diff --git a/kernel/Makefile b/kernel/Makefile index 6a414c3..05fc4b3 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -58,7 +58,6 @@ SRCFILES += $(call GRABSRC, \ path \ rbuf \ ipc/pipe \ - drivers/serial \ dev \ ) diff --git a/kernel/dev/serialdev.c b/kernel/dev/serialdev.c index ed0dd91..3b14636 100644 --- a/kernel/dev/serialdev.c +++ b/kernel/dev/serialdev.c @@ -6,8 +6,47 @@ #include "util/util.h" #include "hshtb.h" #include "sysdefs/devctl.h" -#include "drivers/serial/serial.h" #include "kprintf.h" +#include "hal/hal.h" + +// https://wiki.osdev.org/Serial_Ports + +#define PORT 0x3f8 + +void serial_init(void) { + io_out8(PORT+1, 0x00); + io_out8(PORT+3, 0x80); + io_out8(PORT+0, 0x03); + io_out8(PORT+1, 0x00); + io_out8(PORT+3, 0x03); + io_out8(PORT+2, 0xC7); + io_out8(PORT+4, 0x0B); + io_out8(PORT+4, 0x1E); + io_out8(PORT+0, 0xAE); + + if (io_in8(PORT+0) != 0xAE) { + ERR("serial", "serial is faulty!\n"); + return; + } + + io_out8(PORT+4, 0x0F); +} + +int serial_recvready(void) { + return io_in8(PORT+5) & 1; +} + +uint8_t serial_recvb(void) { + return io_in8(PORT); +} + +int serial_sendready(void) { + return io_in8(PORT+5) & 0x20; +} + +void serial_sendb(uint8_t b) { + io_out8(PORT, b); +} int32_t serialdev_sendb(uint8_t *buffer, size_t len, void *extra) { (void)len; (void)extra; diff --git a/kernel/drivers/serial/serial.c b/kernel/drivers/serial/serial.c deleted file mode 100644 index 811ae80..0000000 --- a/kernel/drivers/serial/serial.c +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include "hal/hal.h" -#include "kprintf.h" - -// https://wiki.osdev.org/Serial_Ports - -#define PORT 0x3f8 - -void serial_init(void) { - io_out8(PORT+1, 0x00); - io_out8(PORT+3, 0x80); - io_out8(PORT+0, 0x03); - io_out8(PORT+1, 0x00); - io_out8(PORT+3, 0x03); - io_out8(PORT+2, 0xC7); - io_out8(PORT+4, 0x0B); - io_out8(PORT+4, 0x1E); - io_out8(PORT+0, 0xAE); - - if (io_in8(PORT+0) != 0xAE) { - ERR("serial", "serial is faulty!\n"); - return; - } - - io_out8(PORT+4, 0x0F); -} - -int serial_recvready(void) { - return io_in8(PORT+5) & 1; -} - -uint8_t serial_recvb(void) { - return io_in8(PORT); -} - -int serial_sendready(void) { - return io_in8(PORT+5) & 0x20; -} - -void serial_sendb(uint8_t b) { - io_out8(PORT, b); -} diff --git a/kernel/drivers/serial/serial.h b/kernel/drivers/serial/serial.h deleted file mode 100644 index c2538e2..0000000 --- a/kernel/drivers/serial/serial.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef DRIVERS_SERIAL_SERIAL_H_ -#define DRIVERS_SERIAL_SERIAL_H_ - -#include - -void serial_init(void); -int serial_recvready(void); -uint8_t serial_recvb(void); -int serial_sendready(void); -void serial_sendb(uint8_t b); - -#endif // DRIVERS_SERIAL_SERIAL_H_