summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-08-19 19:39:47 +0200
committerMiguel <m.i@gmx.at>2018-08-19 19:39:47 +0200
commit5055dc85c8a74fcd2ec24fbc51eba2a2da68debe (patch)
tree6b9589c5c89c8bc5c90771ff9d630c15e670f024 /driver
parent575c725f998b166f1d286a2664aa3d6061d337fe (diff)
cleaning up asm stuff and improving docs
Diffstat (limited to 'driver')
-rw-r--r--driver/keyboard.c2
-rw-r--r--driver/mouse.c2
-rw-r--r--driver/pci.c2
-rw-r--r--driver/serial.c20
-rw-r--r--driver/serial.h32
5 files changed, 42 insertions, 16 deletions
diff --git a/driver/keyboard.c b/driver/keyboard.c
index 55e3c41..d35ef6d 100644
--- a/driver/keyboard.c
+++ b/driver/keyboard.c
@@ -3,7 +3,7 @@
#define FOOLOS_MODULE_NAME "keyboard"
#include <stdbool.h>
-#include "kernel/x86.h"
+#include "asm/x86.h"
#include "lib/logger/log.h"
static bool ctrl_l=false;
diff --git a/driver/mouse.c b/driver/mouse.c
index d4dbb56..23619a4 100644
--- a/driver/mouse.c
+++ b/driver/mouse.c
@@ -7,7 +7,7 @@
#include "lib/logger/log.h"
#include <stdint.h>
-#include "kernel/x86.h"
+#include "asm/x86.h"
static volatile uint8_t mouse_cycle;
static volatile uint8_t mouse_byte[3];
diff --git a/driver/pci.c b/driver/pci.c
index 677f445..a8cd68b 100644
--- a/driver/pci.c
+++ b/driver/pci.c
@@ -1,7 +1,7 @@
#define FOOLOS_MODULE_NAME "pci"
#include "kernel/kernel.h"
-#include "kernel/x86.h"
+#include "asm/x86.h"
#include "e1000.h"
#include "lib/logger/log.h" // logger facilities
diff --git a/driver/serial.c b/driver/serial.c
index 1a36bf5..6e6a4bb 100644
--- a/driver/serial.c
+++ b/driver/serial.c
@@ -1,10 +1,13 @@
#define FOOLOS_MODULE_NAME "serial"
#include "serial.h"
-#define PORT 0x3f8 /* COM1 */
+#include "asm/x86.h" // provides x86_inb() and x86_outb()
-void serial_init() {
+/** COM1 Port */
+static const PORT=0x3f8;
+void serial_init()
+{
x86_outb(PORT + 1, 0x00); // Disable all interrupts
x86_outb(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor)
x86_outb(PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud
@@ -13,23 +16,26 @@ void serial_init() {
x86_outb(PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold
x86_outb(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set
-// log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"COM 1 - initialized");
}
-int serial_received() {
+static uint32_t serial_received()
+{
return x86_inb(PORT + 5) & 1;
}
-char serial_read() {
+uint8_t serial_read()
+{
while (serial_received() == 0);
return x86_inb(PORT);
}
-int is_transmit_empty() {
+static uint32_t is_transmit_empty()
+{
return x86_inb(PORT + 5) & 0x20;
}
-void serial_write(char a) {
+void serial_write(uint8_t a)
+{
while (is_transmit_empty() == 0);
x86_outb(PORT,a);
}
diff --git a/driver/serial.h b/driver/serial.h
index 2e10af8..c6841f2 100644
--- a/driver/serial.h
+++ b/driver/serial.h
@@ -1,18 +1,38 @@
+#ifndef FOOLOS_SERIAL_H
+#define FOOLOS_SERIAL_H
/**
* @file
- * Serial Port Driver for COM1
+ * MINIMALISTIC SERIAL PORT DRIVER for COM1
+ * ========================================
+ * Call serial_init() **once** before _reading_ or _writing_ with
+ * serial_read() or serial_write().
*
- * https://wiki.osdev.org/Serial_Ports
+ * Blocking
+ * --------
+ * Please note that the calls will block if the buffers
+ * are full (and not read on the other end) _or_ no data is available
+ * for reading.
*
- * Call serial_init() once before reading and writing with serial_read()
- * and serial_write(). Note that reading and writing might block.
+ * Dependencies
+ * ------------
+ * The implmentation relies on x86_inb() and x86_outb()
+ * to be defined in _asm/x86.h_.
+ *
+ * Reference
+ * ---------
+ * The implementation was ruthlessly copied from here: https://wiki.osdev.org/Serial_Ports
*/
+// We need uint8_t and uint_32t //
+#include <stdint.h>
+
/** Initialize COM1 **/
void serial_init();
/** read one byte from COM1 (blocking) **/
-char serial_read();
+uint8_t serial_read();
/** write one byte from COM1 (blocking) **/
-void serial_write(char a);
+void serial_write(uint8_t a);
+
+#endif