initgraph, whole lot of refactor
This commit is contained in:
+31
-32
@@ -1,45 +1,44 @@
|
||||
#include <zinnia/cmdline.h>
|
||||
#include <zinnia/console.h>
|
||||
#include <zinnia/init.h>
|
||||
#include <zinnia/print.h>
|
||||
#include <zinnia/string.h>
|
||||
#include <zinnia/spin.h>
|
||||
|
||||
extern struct console* const __ld_console_start[];
|
||||
extern struct console* const __ld_console_end[];
|
||||
|
||||
struct console* active = nullptr;
|
||||
static struct console* registered = nullptr;
|
||||
static struct spinlock console_lock;
|
||||
|
||||
void console_write(const char* buf, size_t len) {
|
||||
if (__likely(active))
|
||||
active->write(active, buf, len);
|
||||
spin_lock(&console_lock);
|
||||
for (struct console* con = registered; con; con = con->next)
|
||||
con->write(con, buf, len);
|
||||
spin_unlock(&console_lock);
|
||||
}
|
||||
|
||||
static void console_setup(const char* value) {
|
||||
if (!value)
|
||||
return;
|
||||
bool console_register(struct console* con) {
|
||||
if (!con->init(con))
|
||||
return false;
|
||||
|
||||
// Find a suitable boot console.
|
||||
struct console* const* cur = __ld_console_start;
|
||||
while (cur < __ld_console_end) {
|
||||
if (!strcmp(value, (*cur)->name)) {
|
||||
active = *cur;
|
||||
spin_lock(&console_lock);
|
||||
con->next = registered;
|
||||
registered = con;
|
||||
spin_unlock(&console_lock);
|
||||
|
||||
log("console: Registered console \"%s\"\n", con->name);
|
||||
return true;
|
||||
}
|
||||
|
||||
void console_unregister(struct console* con) {
|
||||
spin_lock(&console_lock);
|
||||
for (struct console** link = ®istered; *link; link = &(*link)->next) {
|
||||
if (*link == con) {
|
||||
*link = con->next;
|
||||
break;
|
||||
}
|
||||
cur++;
|
||||
}
|
||||
spin_unlock(&console_lock);
|
||||
}
|
||||
|
||||
CMDLINE_OPTION("console", "Set a default console", console_setup);
|
||||
|
||||
void console_init() {
|
||||
// If we have no console set and at least one set, use that as a default.
|
||||
if (!active && &__ld_console_start[0] != &__ld_console_end[0])
|
||||
active = __ld_console_start[0];
|
||||
|
||||
if (active) {
|
||||
if (active->init(active) == false) {
|
||||
active = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
log("console: Logging on console \"%s\"\n", active->name);
|
||||
}
|
||||
[[__init]]
|
||||
static void console_stage_init(struct boot_info*) {
|
||||
kprintf("\ec");
|
||||
}
|
||||
INIT_TASK(console_stage, "core.console", console_stage_init);
|
||||
|
||||
Reference in New Issue
Block a user