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:
2023-12-30 09:09:18 +00:00
parent fc56f906d3
commit b0c021d4e9
6 changed files with 91 additions and 18 deletions

View File

@@ -13,9 +13,9 @@
#include <socks/memblock.h>
#include <socks/vm.h>
#include <socks/printk.h>
#include <socks/console.h>
#include <socks/machine/cpu.h>
#include <socks/libc/stdio.h>
#include <arch/vgacon.h>
#ifdef KEXT_NET_DOORSTUCK_SOCKS_ACPI
#include <arch/acpi.h>
@@ -25,6 +25,10 @@
#include <socks/fbcon.h>
#endif
#ifdef KEXT_NET_DOORSTUCK_SOCKS_SERIALCON
#include <socks/serialcon.h>
#endif
#define PTR32(x) ((void *)((uintptr_t)(x)))
static ml_cpu_block g_bootstrap_cpu = {0};
@@ -54,6 +58,28 @@ static void early_vm_init(void)
printk("memblock: reserved bios+kernel at [0x%016llx-0x%016llx]", 0, (uintptr_t)__pend);
}
void early_console_init(void)
{
const char *dest = arg_value("kernel.early-console");
if (!dest) {
return;
}
#ifdef KEXT_NET_DOORSTUCK_SOCKS_FBCON
if (!strcmp(dest, "tty0")) {
early_vgacon_init();
}
#endif
#ifdef KEXT_NET_DOORSTUCK_SOCKS_SERIALCON
if (!strncmp(dest, "ttyS0", 5)) {
/* TODO allow specifying baud rate from command line */
unsigned int baud = 115200;
early_serialcon_init(baud);
}
#endif
}
static void init_bootfb(multiboot_info_t *mb)
{
__bootfb_varinfo.fb_xres = mb->framebuffer_width;
@@ -109,11 +135,10 @@ int ml_init(uintptr_t arg)
init_bootfb(mb);
bootstrap_cpu_init();
#ifdef KEXT_NET_DOORSTUCK_SOCKS_FBCON
early_vgacon_init();
#endif
clock_calibrate(500);
early_console_init();
print_kernel_banner();
early_vm_init();