diff options
Diffstat (limited to 'src/kernel/arch/i386/driver')
-rw-r--r-- | src/kernel/arch/i386/driver/ps2.c | 21 | ||||
-rw-r--r-- | src/kernel/arch/i386/driver/ps2.h | 11 | ||||
-rw-r--r-- | src/kernel/arch/i386/driver/serial.c | 25 | ||||
-rw-r--r-- | src/kernel/arch/i386/driver/serial.h | 13 |
4 files changed, 40 insertions, 30 deletions
diff --git a/src/kernel/arch/i386/driver/ps2.c b/src/kernel/arch/i386/driver/ps2.c index 8955100..97e2878 100644 --- a/src/kernel/arch/i386/driver/ps2.c +++ b/src/kernel/arch/i386/driver/ps2.c @@ -2,6 +2,7 @@ #include <kernel/arch/i386/interrupts/irq.h> #include <kernel/mem/virt.h> #include <kernel/panic.h> +#include <kernel/vfs/request.h> #include <shared/container/ring.h> #include <shared/mem.h> @@ -12,23 +13,33 @@ static volatile ring_t backlog = {(void*)backlog_buf, BACKLOG_CAPACITY, 0, 0}; static struct vfs_request *blocked_on = NULL; -bool ps2_ready(void) { + +static void accept(struct vfs_request *req); +static bool is_ready(struct vfs_backend *self); + + +static struct vfs_backend backend = BACKEND_KERN(is_ready, accept); +void ps2_init(void) { vfs_mount_root_register("/ps2", &backend); } + + + +static bool ps2_ready(void) { return ring_size((void*)&backlog) > 0; } void ps2_recv(uint8_t s) { ring_put1b((void*)&backlog, s); if (blocked_on) { - vfs_ps2_accept(blocked_on); + accept(blocked_on); blocked_on = NULL; } } -size_t ps2_read(uint8_t *buf, size_t len) { +static size_t ps2_read(uint8_t *buf, size_t len) { return ring_get((void*)&backlog, buf, len); } -void vfs_ps2_accept(struct vfs_request *req) { +static void accept(struct vfs_request *req) { // when you fix something here go also fix it in the COM1 driver static uint8_t buf[32]; // pretty damn stupid int ret; @@ -60,4 +71,4 @@ void vfs_ps2_accept(struct vfs_request *req) { } } -bool vfs_ps2_ready(struct vfs_backend *self) { return blocked_on == NULL; } +static bool is_ready(struct vfs_backend *self) { return blocked_on == NULL; } diff --git a/src/kernel/arch/i386/driver/ps2.h b/src/kernel/arch/i386/driver/ps2.h index c5d0ce1..54e8fb2 100644 --- a/src/kernel/arch/i386/driver/ps2.h +++ b/src/kernel/arch/i386/driver/ps2.h @@ -1,12 +1,5 @@ #pragma once -#include <kernel/vfs/request.h> -#include <stdbool.h> -#include <stddef.h> #include <stdint.h> -bool ps2_ready(void); -void ps2_recv(uint8_t scancode); -size_t ps2_read(uint8_t *buf, size_t max_len); - -void vfs_ps2_accept(struct vfs_request *); -bool vfs_ps2_ready(struct vfs_backend *); +void ps2_recv(uint8_t s); +void ps2_init(void); diff --git a/src/kernel/arch/i386/driver/serial.c b/src/kernel/arch/i386/driver/serial.c index 170cc4d..614d4e0 100644 --- a/src/kernel/arch/i386/driver/serial.c +++ b/src/kernel/arch/i386/driver/serial.c @@ -16,6 +16,17 @@ static const int COM1 = 0x3f8; static struct vfs_request *blocked_on = NULL; +static void accept(struct vfs_request *req); +static bool is_ready(struct vfs_backend *self); + + +static struct vfs_backend backend = BACKEND_KERN(is_ready, accept); +void serial_init(void) { vfs_mount_root_register("/com1", &backend); } + + + + + static void serial_selftest(void) { char b = 0x69; port_out8(COM1 + 4, 0b00011110); // enable loopback mode @@ -23,7 +34,7 @@ static void serial_selftest(void) { assert(port_in8(COM1) == b); } -void serial_init(void) { +void serial_preinit(void) { // see https://www.sci.muni.cz/docs/pc/serport.txt // set baud rate divisor port_out8(COM1 + 3, 0b10000000); // enable DLAB @@ -40,20 +51,20 @@ void serial_init(void) { } -bool serial_ready(void) { +static bool serial_ready(void) { return ring_size((void*)&backlog) > 0; } void serial_irq(void) { ring_put1b((void*)&backlog, port_in8(COM1)); if (blocked_on) { - vfs_com1_accept(blocked_on); + accept(blocked_on); blocked_on = NULL; // TODO vfs_backend_tryaccept } } -size_t serial_read(char *buf, size_t len) { +static size_t serial_read(char *buf, size_t len) { return ring_get((void*)&backlog, buf, len); } @@ -69,8 +80,8 @@ void serial_write(const char *buf, size_t len) { } -void vfs_com1_accept(struct vfs_request *req) { - static uint8_t buf[32]; +static void accept(struct vfs_request *req) { + static char buf[32]; int ret; switch (req->type) { case VFSOP_OPEN: @@ -109,4 +120,4 @@ void vfs_com1_accept(struct vfs_request *req) { } } -bool vfs_com1_ready(struct vfs_backend *self) { return blocked_on == NULL; } +static bool is_ready(struct vfs_backend *self) { return blocked_on == NULL; } diff --git a/src/kernel/arch/i386/driver/serial.h b/src/kernel/arch/i386/driver/serial.h index 6aff142..6a4876e 100644 --- a/src/kernel/arch/i386/driver/serial.h +++ b/src/kernel/arch/i386/driver/serial.h @@ -3,13 +3,8 @@ #include <stdbool.h> #include <stddef.h> -void serial_init(void); +void serial_preinit(void); +void serial_irq(void); +void serial_write(const char *buf, size_t len); -bool serial_ready(void); -void serial_irq(void); -size_t serial_read(char *buf, size_t len); - -void serial_write(const char *buf, size_t len); - -void vfs_com1_accept(struct vfs_request *); -bool vfs_com1_ready(struct vfs_backend *); +void serial_init(void); |