summaryrefslogtreecommitdiffhomepage
path: root/src/loader/dev.c
diff options
context:
space:
mode:
authorMarvin Borner2021-07-05 13:38:33 +0200
committerMarvin Borner2021-07-05 13:38:33 +0200
commit981342ef807ebcefba8eeba74511cdcedf9c36bd (patch)
tree2f641c75edd21f7fb064a163c997f23f9dc68978 /src/loader/dev.c
parenta6858f40888338608fede867d279831e98ec0766 (diff)
Device manager, panic and IDE read
Diffstat (limited to 'src/loader/dev.c')
-rw-r--r--src/loader/dev.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/loader/dev.c b/src/loader/dev.c
new file mode 100644
index 0000000..441aaed
--- /dev/null
+++ b/src/loader/dev.c
@@ -0,0 +1,50 @@
+// MIT License, Copyright (c) 2021 Marvin Borner
+// Device manager
+
+#include <dev.h>
+#include <lib.h>
+#include <pnc.h>
+
+static struct dev devices[32] = { 0 };
+
+static const char *dev_resolve_type(enum dev_type type)
+{
+ switch (type) {
+ case DEV_DISK:
+ return "Disk";
+ case DEV_FB:
+ return "Framebuffer";
+ default:
+ return "Unknown";
+ }
+}
+
+u32 dev_register(enum dev_type type, char *name, u32 data,
+ s32 (*read)(void *, u32, u32, struct dev *),
+ s32 (*write)(const void *, u32, u32, struct dev *))
+{
+ static u8 id = 0;
+
+ struct dev *dev = &devices[id];
+ dev->id = id;
+ dev->type = type;
+ dev->read = read;
+ dev->write = write;
+ dev->data = data;
+ dev->exists = 1;
+
+ assert(strlen(name) < sizeof(dev->name));
+ memcpy(dev->name, name, sizeof(dev->name));
+
+ return id++;
+}
+
+void dev_print(void)
+{
+ for (u8 i = 0; i < COUNT(devices); i++) {
+ struct dev *dev = &devices[i];
+ if (!dev->exists)
+ continue;
+ log("%d: %s device: %s\n", dev->id, dev_resolve_type(dev->type), dev->name);
+ }
+}