summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--console/module_main.c38
-rw-r--r--include/log.h2
-rw-r--r--include/mmio.h8
-rw-r--r--kernel/log.c9
4 files changed, 55 insertions, 2 deletions
diff --git a/console/module_main.c b/console/module_main.c
index 521aebc..8aeac9f 100644
--- a/console/module_main.c
+++ b/console/module_main.c
@@ -1,10 +1,44 @@
+#include <log.h>
+#include <mmio.h>
+
#ifndef __KERNEL_MODULE__
#define __KERNEL_MODULE__
#endif
-int test_module_init(void) {
+extern console_callback_t callback;
+
+struct console_device_meta {
+ void *register_controller;
+ void *data_start;
+ void *data_end;
+};
+
+const char compatible[] __attribute__((section(".compatible"))) = "unix,soc-tty";
+size_t pos = 0;
+struct console_device_meta dev_meta = { NULL, NULL, NULL };
+
+__attribute__((visibility("hidden"))) void console_put_char(char c) {
+ ((char *)dev_meta.data_start)[pos++] = c;
+
+ if (c == '\n') {
+ *((uint8_t *)dev_meta.register_controller) = 1;
+ pos = 0;
+ }
+ return;
+}
+
+
+int __attribute__((section(".module_init"))) module_init(struct mmio_device_meta *meta) {
+ callback = console_put_char;
+
+ dev_meta.register_controller = meta->start;
+ dev_meta.data_start = (void *)((uint8_t *)meta->start + 1);
+ dev_meta.data_end = (void *)((uint8_t *)meta->start + meta->size);
+
+ printk("Registered console device successfully");
return 0;
}
-void test_module_exit(void) {
+void __attribute__((section(".module_exit"))) module_exit(void) {
+ printk("Unregistered console device (nothing to do)");
}
diff --git a/include/log.h b/include/log.h
index 2b35922..f1e4110 100644
--- a/include/log.h
+++ b/include/log.h
@@ -2,5 +2,7 @@
#define RINGBUF_SIZE 64 * 1024
+typedef void (*console_callback_t)(char);
+
void vprintk(const char *message, __builtin_va_list args);
void printk(const char *message, ...);
diff --git a/include/mmio.h b/include/mmio.h
new file mode 100644
index 0000000..b6531bf
--- /dev/null
+++ b/include/mmio.h
@@ -0,0 +1,8 @@
+#pragma once
+#include <types.h>
+
+struct mmio_device_meta {
+ const char *name;
+ void *start;
+ size_t size;
+};
diff --git a/kernel/log.c b/kernel/log.c
index 3392223..98267e3 100644
--- a/kernel/log.c
+++ b/kernel/log.c
@@ -4,10 +4,19 @@ __attribute__((section(".ringbuf"), aligned(64)))
volatile char log_ring[RINGBUF_SIZE];
static int pos = 0;
+void stub(char c) {
+ (void)c;
+ return;
+}
+
+console_callback_t callback = stub;
+
void put_char(char c) {
log_ring[pos++] = c;
if (pos >= RINGBUF_SIZE)
pos = 0;
+
+ callback(c);
}
void put_string(const char *s) {