From 9400716f56057d9f2fcd7f7ad033dfcb131105a2 Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Wed, 25 Jul 2018 17:18:18 +1000 Subject: Added missing prototype for puts() in stdio.h. Implemented a basic serial interface using COM0 which can be accessed with the system call sys_puts as well as the library functions rsputs() and rsprintf(). Renamed puts() in con.c to con_puts() and made the function static to avoid interference with the library function puts(). --- kernel/serial.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 kernel/serial.c (limited to 'kernel/serial.c') diff --git a/kernel/serial.c b/kernel/serial.c new file mode 100644 index 0000000..7f23298 --- /dev/null +++ b/kernel/serial.c @@ -0,0 +1,52 @@ +#include +#include + +/* 115200 baud */ +#define DIVISOR 1 + +#define RSBASE 0x3F8 + +#define RSDATA RSBASE +#define RSINTEN (RSBASE + 1) +#define RSFIFOC (RSBASE + 2) +#define RSLINEC (RSBASE + 3) +#define RSMODEMC (RSBASE + 4) +#define RSLINES (RSBASE + 5) +#define RSMODEMS (RSBASE + 6) +#define RSSCRATCH (RSBASE + 7) + +static int rsputs(char *s) { + while(*s) { + while((inb(RSLINES) & 0x20) == 0); + outb(RSDATA, *s++); + } + + return 0; +} + +void serial_init(void) { + outb(RSSCRATCH, 0x00); + outb(RSSCRATCH, 0xAA); + if(inb(RSSCRATCH) != 0xAA) { + printk("[rs] COM0 not detected!\n"); + return; + } + + /* enable access to the divisor */ + outb(RSLINEC, inb(RSLINEC) | 0x80); + /* write the divisor */ + outb(RSBASE, DIVISOR); + outb(RSBASE + 1, DIVISOR >> 8); + /* restore access to the divisor */ + outb(RSLINEC, inb(RSLINEC) & 0x7F); + /* configure port parameters */ + outb(RSLINEC, 0x03); + outb(RSINTEN, 0x00); + + rsputs("[kernel] Serial monitor initialized!\n\r"); + printk("[rs] Serial port COM0 initialized!\n"); +} + +int sys_rsputs(char *s) { + return rsputs(s); +} -- cgit v1.3