feat: owloysius - dynamic init function invocator
[lunaix-os.git] / lunaix-os / kernel / tty / lxconsole.c
index 67961b52def89799344dcf4b689e1307d4a7f65b..cf2d43c4e15d195b428fa97e7cedc859e882e0ec 100644 (file)
@@ -146,20 +146,6 @@ __tty_read_pg(struct device* dev, void* buf, size_t offset)
     return __tty_read(dev, buf, offset, PG_SIZE);
 }
 
-void
-lxconsole_spawn_ttydev()
-{
-    struct device* tty_dev = device_addseq(NULL, &lx_console, "tty");
-    tty_dev->write = __tty_write;
-    tty_dev->write_page = __tty_write_pg;
-    tty_dev->read = __tty_read;
-    tty_dev->read_page = __tty_read_pg;
-    tty_dev->exec_cmd = __tty_exec_cmd;
-
-    waitq_init(&lx_reader);
-    input_add_listener(__lxconsole_listener);
-}
-
 int
 __tty_write(struct device* dev, void* buf, size_t offset, size_t len)
 {
@@ -352,4 +338,30 @@ console_start_flushing()
     struct lx_timer* timer =
       timer_run_ms(20, console_flush, NULL, TIMER_MODE_PERIODIC);
     lx_console.flush_timer = timer;
-}
\ No newline at end of file
+}
+
+static int
+lxconsole_spawn_ttydev(struct device_def* devdef)
+{
+    struct device* tty_dev = device_allocseq(NULL, &lx_console);
+    tty_dev->ops.write = __tty_write;
+    tty_dev->ops.write_page = __tty_write_pg;
+    tty_dev->ops.read = __tty_read;
+    tty_dev->ops.read_page = __tty_read_pg;
+    tty_dev->ops.exec_cmd = __tty_exec_cmd;
+
+    waitq_init(&lx_reader);
+    input_add_listener(__lxconsole_listener);
+
+    register_device(tty_dev, &devdef->class, "vcon");
+
+    return 0;
+}
+
+static struct device_def lxconsole_def = {
+    .name = "Lunaix Virtual Console",
+    .class = DEVCLASSV(DEVIF_NON, DEVFN_TTY, DEV_BUILTIN, 12),
+    .init = lxconsole_spawn_ttydev
+};
+// FIXME
+EXPORT_DEVICE(lxconsole, &lxconsole_def, load_onboot);
\ No newline at end of file