kernel: add kernel.early-console and kernel.console boot args
kernel.early-console is used to specify which output device the kernel boot log should be written to. the first thing the kernel does on boot after initialising the bootstrap processor is initialise the early console, making it useful for debugging problems that occur early in the boot process. this arg accepts a list of hard-coded values for output devices, such as tty0 for the display or ttyS0 for the serial port. the exact values supported will depend on the platform. once all drivers are loaded, the kernel switches to the device specified by kernel.console for output. unlike kernel.early-console, this arg specifies the name of a tty device in /dev/tty. this means that, not only are more devices supported (any device provided by a tty driver), but the kernel can also get input from the user using this console too (not used by the kernel itself, but will be used by the user to interact with userspace programs, like the shell).
This commit is contained in:
28
init/main.c
28
init/main.c
@@ -1,5 +1,6 @@
|
||||
#include <stdint.h>
|
||||
#include <socks/init.h>
|
||||
#include <socks/arg.h>
|
||||
#include <socks/clock.h>
|
||||
#include <socks/input.h>
|
||||
#include <socks/panic.h>
|
||||
@@ -10,6 +11,7 @@
|
||||
#include <socks/kext.h>
|
||||
#include <socks/object.h>
|
||||
#include <socks/sched.h>
|
||||
#include <socks/libc/stdio.h>
|
||||
#include <socks/machine/init.h>
|
||||
#include <socks/cpu.h>
|
||||
|
||||
@@ -29,7 +31,7 @@ void print_kernel_banner(void)
|
||||
static void hang(void)
|
||||
{
|
||||
while (1) {
|
||||
//printk("tick");
|
||||
printk("%d: tick", this_cpu());
|
||||
milli_sleep(2000);
|
||||
}
|
||||
}
|
||||
@@ -37,10 +39,10 @@ static void hang(void)
|
||||
void background_thread(void)
|
||||
{
|
||||
printk("background_thread() running on processor %u", this_cpu());
|
||||
milli_sleep(500);
|
||||
milli_sleep(1000);
|
||||
|
||||
while (1) {
|
||||
//printk("tock");
|
||||
printk("%d: tock", this_cpu());
|
||||
milli_sleep(2000);
|
||||
}
|
||||
}
|
||||
@@ -99,6 +101,26 @@ void kernel_init(uintptr_t arg)
|
||||
tty_set_foreground(cast_to_device(tty0));
|
||||
}
|
||||
|
||||
const char *console_tty_name = arg_value("kernel.console");
|
||||
if (!console_tty_name) {
|
||||
console_tty_name = "tty0";
|
||||
}
|
||||
|
||||
char console_tty_path[128];
|
||||
snprintf(console_tty_path, sizeof console_tty_path, "/dev/tty/%s", console_tty_name);
|
||||
|
||||
struct object *console_tty = NULL;
|
||||
status = object_get(console_tty_path, &console_tty);
|
||||
|
||||
if (status == KERN_OK) {
|
||||
register_tty_console();
|
||||
struct device *console_tty_device = cast_to_device(console_tty);
|
||||
redirect_printk_to_tty(console_tty_device);
|
||||
object_deref(console_tty);
|
||||
} else {
|
||||
printk("console tty '%s' is unavailable.", console_tty_name);
|
||||
}
|
||||
|
||||
create_kernel_thread(background_thread);
|
||||
|
||||
struct object *kbd;
|
||||
|
||||
Reference in New Issue
Block a user