diff options
| author | Aleksa Vuckovic <aleksav013@gmail.com> | 2022-09-05 04:19:56 +0200 |
|---|---|---|
| committer | Aleksa Vuckovic <aleksav013@gmail.com> | 2022-09-05 04:19:56 +0200 |
| commit | 59f86fe8dd237e50c7fea03b506125e3abff0157 (patch) | |
| tree | 83c04c305ebfb3d5f55f600ea48082b42efe1a7e /kernel/src/devices/serial.c | |
| parent | 6e9b3275d75e0cdbae1e8f7e4dda8880bb6346bc (diff) | |
serial output
Diffstat (limited to 'kernel/src/devices/serial.c')
| -rw-r--r-- | kernel/src/devices/serial.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/kernel/src/devices/serial.c b/kernel/src/devices/serial.c new file mode 100644 index 0000000..76bc71a --- /dev/null +++ b/kernel/src/devices/serial.c @@ -0,0 +1,37 @@ +#include <io.h> +#include <serial.h> + +void init_serial() +{ + outb(PORT + 1, 0x00); // Disable all interrupts + outb(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor) + outb(PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud + outb(PORT + 1, 0x00); // (hi byte) + outb(PORT + 3, 0x03); // 8 bits, no parity, one stop bit + outb(PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold + outb(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set +} + +uint8_t serial_received() +{ + return inb(PORT + 5) & 1; +} + +char read_serial() +{ + while (serial_received() == 0); + + return (char)inb(PORT); +} + +uint8_t is_transmit_empty() +{ + return inb(PORT + 5) & 0x20; +} + +void write_serial(char c) +{ + while (is_transmit_empty() == 0); + + outb(PORT, (uint8_t)c); +} |
