summaryrefslogtreecommitdiff
path: root/src/kernel/arch
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
parent9900cc737988f25db30b5876f066a78e73389205 (diff)
kernel: each driver registers its own mounts
Diffstat (limited to 'src/kernel/arch')
-rw-r--r--src/kernel/arch/i386/boot.c40
-rw-r--r--src/kernel/arch/i386/driver/ps2.c21
-rw-r--r--src/kernel/arch/i386/driver/ps2.h11
-rw-r--r--src/kernel/arch/i386/driver/serial.c25
-rw-r--r--src/kernel/arch/i386/driver/serial.h13
-rw-r--r--src/kernel/arch/i386/tty/tty.c2
6 files changed, 68 insertions, 44 deletions
diff --git a/src/kernel/arch/i386/boot.c b/src/kernel/arch/i386/boot.c
index a3716ee..be80f73 100644
--- a/src/kernel/arch/i386/boot.c
+++ b/src/kernel/arch/i386/boot.c
@@ -1,19 +1,34 @@
#include <kernel/arch/generic.h>
#include <kernel/arch/i386/ata.h>
#include <kernel/arch/i386/boot.h>
+#include <kernel/arch/i386/driver/ps2.h>
+#include <kernel/arch/i386/driver/serial.h>
#include <kernel/arch/i386/gdt.h>
#include <kernel/arch/i386/interrupts/idt.h>
#include <kernel/arch/i386/interrupts/irq.h>
#include <kernel/arch/i386/multiboot.h>
#include <kernel/main.h>
+#include <kernel/mem/alloc.h>
#include <kernel/panic.h>
+#include <kernel/vfs/root.h>
void tty_init(void); // TODO put this in a header file
+static void find_init(struct multiboot_info *multiboot, struct kmain_info *info)
+{
+ struct multiboot_mod *module = &multiboot->mods[0];
+ if (multiboot->mods_count < 1) {
+ kprintf("can't find init! ");
+ panic_invalid_state();
+ }
+ info->init.at = module->start;
+ info->init.size = module->end - module->start;
+
+}
+
void kmain_early(struct multiboot_info *multiboot) {
struct kmain_info info;
- // setup some basic stuff
tty_init();
kprintf("gdt...");
gdt_init();
@@ -21,20 +36,19 @@ void kmain_early(struct multiboot_info *multiboot) {
idt_init();
kprintf("irq...");
irq_init();
- kprintf("ata...");
- ata_init();
-
- { // find the init module
- struct multiboot_mod *module = &multiboot->mods[0];
- if (multiboot->mods_count < 1) {
- kprintf("can't find init! ");
- panic_invalid_state(); // no init
- }
- info.init.at = module->start;
- info.init.size = module->end - module->start;
- }
info.memtop = (void*) (multiboot->mem_upper * 1024);
+ find_init(multiboot, &info);
+ kprintf("mem...\n");
+ mem_init(&info);
+
+ kprintf("rootfs...");
+ vfs_root_init();
+ ps2_init();
+ serial_init();
+
+ kprintf("ata...");
+ ata_init();
kmain(info);
}
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);
diff --git a/src/kernel/arch/i386/tty/tty.c b/src/kernel/arch/i386/tty/tty.c
index d4a97fb..a1964f9 100644
--- a/src/kernel/arch/i386/tty/tty.c
+++ b/src/kernel/arch/i386/tty/tty.c
@@ -5,7 +5,7 @@
void tty_init(void) {
vga_clear();
- serial_init();
+ serial_preinit();
vga_write("\x03 ", 2); // cp437 heart
serial_write("<3 ", 3);