diff options
Diffstat (limited to 'src/serial.c')
-rw-r--r-- | src/serial.c | 57 |
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; +} |