From 74eb20d8c4810b7757d85f7066359a566621a661 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Thu, 29 Oct 2015 14:25:57 +0100 Subject: kfs: added the serial print * 38400 bauds * 1 stop bit * no parity check * 8 bits words Signed-off-by: Olivier Gayot --- src/serial.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/serial.c (limited to 'src/serial.c') 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; +} -- cgit v1.2.3