From da2bbef4e4f586ecf13cd5ffe9a62df3114a3483 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Thu, 7 Apr 2022 21:13:00 +0200 Subject: kernel: add a /com1 device --- src/kernel/vfs/root.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/kernel/vfs') diff --git a/src/kernel/vfs/root.c b/src/kernel/vfs/root.c index 8904c4b..b8b41fc 100644 --- a/src/kernel/vfs/root.c +++ b/src/kernel/vfs/root.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -13,6 +14,7 @@ enum { HANDLE_ROOT, HANDLE_TTY, HANDLE_VGA, + HANDLE_COM1, HANDLE_PS2, HANDLE_ATA_ROOT, HANDLE_ATA, @@ -61,6 +63,7 @@ int vfs_root_handler(struct vfs_request *req) { if (exacteq(req, "/tty")) return HANDLE_TTY; if (exacteq(req, "/vga")) return HANDLE_VGA; + if (exacteq(req, "/com1")) return HANDLE_COM1; if (exacteq(req, "/ps2")) return HANDLE_PS2; if (exacteq(req, "/ata/")) return HANDLE_ATA_ROOT; @@ -79,7 +82,12 @@ int vfs_root_handler(struct vfs_request *req) { switch (req->id) { case HANDLE_ROOT: { // TODO document directory read format - const char src[] = "tty\0vga\0ata/"; + const char src[] = + "tty\0" + "vga\0" + "com1\0" + "ps2\0" + "ata/"; if (req->output.len < 0) return 0; // is this needed? TODO make that a size_t or something int len = min((size_t) req->output.len, sizeof(src)); virt_cpy_to(req->caller->pages, req->output.buf, src, len); @@ -100,6 +108,12 @@ int vfs_root_handler(struct vfs_request *req) { vga + req->offset, req->output.len); return req->output.len; } + case HANDLE_COM1: { + char buf[16]; + size_t len = serial_read(buf, sizeof buf); + virt_cpy_to(req->caller->pages, req->output.buf, buf, len); + return len; + } case HANDLE_PS2: { uint8_t buf[16]; size_t len = ps2_read(buf, sizeof buf); @@ -151,7 +165,16 @@ int vfs_root_handler(struct vfs_request *req) { req->input.buf, req->input.len); return req->input.len; } + case HANDLE_COM1: { + struct virt_iter iter; + virt_iter_new(&iter, req->input.buf, req->input.len, + req->caller->pages, true, false); + while (virt_iter_next(&iter)) + serial_write(iter.frag, iter.frag_len); + return iter.prior; + } case HANDLE_ATA_ROOT: return -1; + // TODO don't panic on ps2 reads default: panic_invalid_state(); } -- cgit v1.2.3