diff options
author | dzwdz | 2022-04-07 21:13:00 +0200 |
---|---|---|
committer | dzwdz | 2022-04-07 21:13:00 +0200 |
commit | da2bbef4e4f586ecf13cd5ffe9a62df3114a3483 (patch) | |
tree | c65b48e250f803938c82239a0919b8a92ee0b826 /src/kernel/arch | |
parent | df2c9dbc694fb4718fc4905b9af3331dbf73bfb2 (diff) |
kernel: add a /com1 device
Diffstat (limited to 'src/kernel/arch')
-rw-r--r-- | src/kernel/arch/i386/driver/serial.c (renamed from src/kernel/arch/i386/tty/serial.c) | 15 | ||||
-rw-r--r-- | src/kernel/arch/i386/driver/serial.h | 9 | ||||
-rw-r--r-- | src/kernel/arch/i386/tty/serial.h | 7 | ||||
-rw-r--r-- | src/kernel/arch/i386/tty/tty.c | 12 |
4 files changed, 25 insertions, 18 deletions
diff --git a/src/kernel/arch/i386/tty/serial.c b/src/kernel/arch/i386/driver/serial.c index 054f956..d2c34e7 100644 --- a/src/kernel/arch/i386/tty/serial.c +++ b/src/kernel/arch/i386/driver/serial.c @@ -1,5 +1,6 @@ +#include <kernel/arch/i386/driver/serial.h> +#include <kernel/arch/i386/interrupts/irq.h> #include <kernel/arch/i386/port_io.h> -#include <kernel/arch/i386/tty/serial.h> #include <kernel/panic.h> #include <stdint.h> @@ -40,6 +41,18 @@ bool serial_poll_read(char *c) { return true; } +size_t serial_read(char *buf, size_t len) { + irq_interrupt_flag(true); + for (size_t i = 0; i < len; i++) { + for (;;) { + if (serial_poll_read(&buf[i])) break; + asm("hlt" ::: "memory"); + } + } + irq_interrupt_flag(false); + return len; +} + void serial_write(const char *buf, size_t len) { for (size_t i = 0; i < len; i++) serial_putchar(buf[i]); diff --git a/src/kernel/arch/i386/driver/serial.h b/src/kernel/arch/i386/driver/serial.h new file mode 100644 index 0000000..be738d1 --- /dev/null +++ b/src/kernel/arch/i386/driver/serial.h @@ -0,0 +1,9 @@ +#pragma once +#include <stdbool.h> +#include <stddef.h> + +void serial_init(void); +size_t serial_read(char *buf, size_t len); +void serial_write(const char *buf, size_t len); + +bool serial_poll_read(char *c); diff --git a/src/kernel/arch/i386/tty/serial.h b/src/kernel/arch/i386/tty/serial.h deleted file mode 100644 index 808f1aa..0000000 --- a/src/kernel/arch/i386/tty/serial.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once -#include <stdbool.h> -#include <stddef.h> - -bool serial_poll_read(char *c); -void serial_write(const char *buf, size_t len); -void serial_init(void); diff --git a/src/kernel/arch/i386/tty/tty.c b/src/kernel/arch/i386/tty/tty.c index ebe0fd3..ab15aba 100644 --- a/src/kernel/arch/i386/tty/tty.c +++ b/src/kernel/arch/i386/tty/tty.c @@ -1,5 +1,4 @@ -#include <kernel/arch/i386/interrupts/irq.h> -#include <kernel/arch/i386/tty/serial.h> +#include <kernel/arch/i386/driver/serial.h> #include <kernel/arch/i386/tty/vga.h> #include <kernel/arch/io.h> @@ -13,14 +12,7 @@ void tty_init(void) { } void tty_read(char *buf, size_t len) { - irq_interrupt_flag(true); - for (size_t i = 0; i < len; i++) { - for (;;) { - if (serial_poll_read(&buf[i])) break; - asm("hlt" ::: "memory"); - } - } - irq_interrupt_flag(false); + serial_read(buf, len); } void tty_write(const char *buf, size_t len) { |