diff options
author | dzwdz | 2023-08-06 01:16:14 +0200 |
---|---|---|
committer | dzwdz | 2023-08-06 01:16:14 +0200 |
commit | 0ddd4d1dab8dc2ba092c7351cfb2e054fce1f429 (patch) | |
tree | dfa378e88be27c189c739190dc3ec7beb8e26aba /src/kernel | |
parent | a71120adf590f699c4b8d6249a340976575ea530 (diff) |
kernel: put every driver in /kdev/
there's no real reason for bootstrap to be doing that, and this brings it closer
to only doing the elf loading
Diffstat (limited to 'src/kernel')
-rw-r--r-- | src/kernel/arch/amd64/driver/fsroot.c | 36 | ||||
-rw-r--r-- | src/kernel/arch/amd64/driver/pata.c | 2 | ||||
-rw-r--r-- | src/kernel/arch/amd64/driver/ps2.c | 2 | ||||
-rw-r--r-- | src/kernel/arch/amd64/driver/rtl8139.c | 2 | ||||
-rw-r--r-- | src/kernel/arch/amd64/driver/serial.c | 2 | ||||
-rw-r--r-- | src/kernel/arch/amd64/driver/video.c | 2 | ||||
-rw-r--r-- | src/kernel/arch/amd64/interrupts/isr.c | 1 |
7 files changed, 35 insertions, 12 deletions
diff --git a/src/kernel/arch/amd64/driver/fsroot.c b/src/kernel/arch/amd64/driver/fsroot.c index 0b0e2ef..d59edf3 100644 --- a/src/kernel/arch/amd64/driver/fsroot.c +++ b/src/kernel/arch/amd64/driver/fsroot.c @@ -8,26 +8,48 @@ #include <kernel/vfs/request.h> #include <shared/mem.h> -static int handle(VfsReq *req) { +static long handle(VfsReq *req) { // TODO document directory read format // TODO don't hardcode - const char dir[] = + static const char base[] = "kdev/"; + static const char dir[] = "com1\0" "ps2/\0" "ata/\0" "eth/\0" "video/"; + const char *id; + int len; + if (!req->caller) return -1; + if (req->type != VFSOP_OPEN) { + /* otherwise, uninitialized, to cause compiler warnings if used */ + /* this operates under the assumption that base and dir never change + * but even if they do, that will just result in a crash. */ + id = (void *__force)req->id; + if (id == base) { + len = sizeof base; + } else if (id == dir) { + len = sizeof dir; + } else { + kprintf("%p %p %p\n", base, dir, id); + assert(false); + } + } + switch (req->type) { case VFSOP_OPEN: - return req->input.len == 1 ? 0 : -1; + if (reqpathcmp(req, "/")) return (long)base; + if (reqpathcmp(req, "/kdev/")) return (long)dir; + return -ENOENT; case VFSOP_READ: - return req_readcopy(req, dir, sizeof dir); - + return req_readcopy(req, id, len); // TODO getsize for the other kernel provided directories - case VFSOP_GETSIZE: return sizeof dir; - default: return -ENOSYS; + case VFSOP_GETSIZE: + return len; + default: + return -ENOSYS; } } diff --git a/src/kernel/arch/amd64/driver/pata.c b/src/kernel/arch/amd64/driver/pata.c index 99c3102..b0058f8 100644 --- a/src/kernel/arch/amd64/driver/pata.c +++ b/src/kernel/arch/amd64/driver/pata.c @@ -13,7 +13,7 @@ static const int root_id = 100; static void accept(VfsReq *req); void pata_init(void) { ata_init(); - vfs_root_register("/ata", accept); + vfs_root_register("/kdev/ata", accept); } static void accept(VfsReq *req) { diff --git a/src/kernel/arch/amd64/driver/ps2.c b/src/kernel/arch/amd64/driver/ps2.c index 06825d6..e314477 100644 --- a/src/kernel/arch/amd64/driver/ps2.c +++ b/src/kernel/arch/amd64/driver/ps2.c @@ -58,7 +58,7 @@ void ps2_init(void) { irq_fn[IRQ_PS2KB] = ps2_irq; irq_fn[IRQ_PS2MOUSE] = ps2_irq; - vfs_root_register("/ps2", accept); + vfs_root_register("/kdev/ps2", accept); } static void ps2_irq(void) { diff --git a/src/kernel/arch/amd64/driver/rtl8139.c b/src/kernel/arch/amd64/driver/rtl8139.c index 09b0ca5..737053e 100644 --- a/src/kernel/arch/amd64/driver/rtl8139.c +++ b/src/kernel/arch/amd64/driver/rtl8139.c @@ -83,7 +83,7 @@ void rtl8139_init(uint32_t bdf) { uint64_t mac = (((uint64_t)port_in32(iobase + MAC + 4) & 0xFFFF) << 32) + port_in32(iobase + MAC); kprintf("rtl8139 mac %012x\n", mac); - vfs_root_register("/eth", accept); + vfs_root_register("/kdev/eth", accept); } static void rtl8139_irq(void) { diff --git a/src/kernel/arch/amd64/driver/serial.c b/src/kernel/arch/amd64/driver/serial.c index 5b42d8d..36b7cfa 100644 --- a/src/kernel/arch/amd64/driver/serial.c +++ b/src/kernel/arch/amd64/driver/serial.c @@ -15,7 +15,7 @@ static const int COM1 = 0x3f8; static void accept(VfsReq *req); static void serial_irq(void); static VfsReq *hung_reads = NULL; -void serial_init(void) { vfs_root_register("/com1", accept); } +void serial_init(void) { vfs_root_register("/kdev/com1", accept); } static void serial_selftest(void) { diff --git a/src/kernel/arch/amd64/driver/video.c b/src/kernel/arch/amd64/driver/video.c index cb70931..5a7fc8f 100644 --- a/src/kernel/arch/amd64/driver/video.c +++ b/src/kernel/arch/amd64/driver/video.c @@ -65,5 +65,5 @@ void video_init(GfxInfo fb_) { fb = fb_; snprintf(namebuf, sizeof namebuf, "%ux%ux%u", fb.width, fb.height, fb.bpp); namelen = strlen(namebuf); - vfs_root_register("/video", accept); + vfs_root_register("/kdev/video", accept); } diff --git a/src/kernel/arch/amd64/interrupts/isr.c b/src/kernel/arch/amd64/interrupts/isr.c index ff00f2f..4ea80c6 100644 --- a/src/kernel/arch/amd64/interrupts/isr.c +++ b/src/kernel/arch/amd64/interrupts/isr.c @@ -40,6 +40,7 @@ void isr_stage3(uint8_t interrupt, uint64_t *stackframe) { log_interrupt(interrupt, stackframe); cpu_halt(); } else { /* in user */ + log_interrupt(interrupt, stackframe); proc_kill(proc_cur, interrupt); proc_switch_any(); } |