summaryrefslogtreecommitdiff
path: root/src/kernel/arch/i386/driver/serial.c
diff options
context:
space:
mode:
authordzwdz2022-05-05 22:47:12 +0200
committerdzwdz2022-05-05 22:47:12 +0200
commita40063321e8fbf4d82f46471221062bfa393604a (patch)
treedf4bb43830c0f94f90738d841b5caeb72922cda6 /src/kernel/arch/i386/driver/serial.c
parent9900cc737988f25db30b5876f066a78e73389205 (diff)
kernel: each driver registers its own mounts
Diffstat (limited to 'src/kernel/arch/i386/driver/serial.c')
-rw-r--r--src/kernel/arch/i386/driver/serial.c25
1 files changed, 18 insertions, 7 deletions
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; }