summaryrefslogtreecommitdiff
path: root/src/serial.c
diff options
context:
space:
mode:
authorOlivier Gayot <duskcoder@gmail.com>2015-10-29 14:25:57 +0100
committerOlivier Gayot <duskcoder@gmail.com>2015-10-29 14:25:57 +0100
commit74eb20d8c4810b7757d85f7066359a566621a661 (patch)
treef511c21ad6d4f2b45ad2c42f689758ea294f2541 /src/serial.c
parente7edce9f232e1359097793b2610e04b16dab7f7e (diff)
kfs: added the serial print
* 38400 bauds * 1 stop bit * no parity check * 8 bits words Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
Diffstat (limited to 'src/serial.c')
-rw-r--r--src/serial.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/serial.c b/src/serial.c
new file mode 100644
index 0000000..720d454
--- /dev/null
+++ b/src/serial.c
@@ -0,0 +1,57 @@
+#define COM1_BASE 0x3f8
+#define COM2_BASE 0x2f8
+#define COM3_BASE 0x3e8
+#define COM4_BASE 0x2e8
+
+#include "uart_16550.h"
+
+static inline void outb(unsigned char value, unsigned short port)
+{
+ asm volatile("outb %0,%1" : : "a" (value), "dN" (port));
+}
+
+static inline unsigned char inb(unsigned short port)
+{
+ unsigned char value;
+
+ asm volatile("inb %1,%0" : "=a" (value) : "dN" (port));
+
+ return value;
+}
+
+int serial_putchar(unsigned char c)
+{
+ outb(c, COM1_BASE);
+
+ return 1;
+}
+
+int serial_init(void)
+{
+ /* set the communication parameters */
+ unsigned char lcr_value = 0x0;
+
+ lcr_value = DATA_WORD_LEN_8
+ | STOP_BIT_1
+ | PARITY_NONE
+ | BREAK_SIGNAL_DISABLED
+ | DLAB_ACCESSIBLE_DLL_DLM;
+
+ outb(lcr_value, COM1_BASE + 3);
+
+ unsigned char dll_value = 0x03;
+ unsigned char dlm_value = 0x00;
+
+ outb(dll_value, COM1_BASE + 0);
+ outb(dlm_value, COM1_BASE + 1);
+
+ lcr_value = DATA_WORD_LEN_8
+ | STOP_BIT_1
+ | PARITY_NONE
+ | BREAK_SIGNAL_DISABLED
+ | DLAB_ACCESSIBLE_RBR_THR_IER;
+
+ outb(lcr_value, COM1_BASE + 3);
+
+ return 0;
+}