From 7a87b008510aab3957aaaee346455291b4ef9619 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Fri, 3 Aug 2018 04:51:23 +0200 Subject: [PATCH] Get the userland kernel closer to working again --- src/arch/i386/kernel.S | 4 ++++ src/drivers/console/stdio.c | 6 ++++++ src/kernel/boot.c | 2 ++ src/kernel/config.h | 14 ++++++++++++- src/kernel/multiboot.c | 40 +++++++++---------------------------- tools/boot.c | 3 +++ tools/init.c | 1 - 7 files changed, 37 insertions(+), 33 deletions(-) diff --git a/src/arch/i386/kernel.S b/src/arch/i386/kernel.S index ad71ca6..02a8211 100644 --- a/src/arch/i386/kernel.S +++ b/src/arch/i386/kernel.S @@ -95,6 +95,10 @@ _start: push $0x0 push $0x0 + push boot + call boot_init + add $0x4, %esp + 2: /* initialize the platform */ push boot diff --git a/src/drivers/console/stdio.c b/src/drivers/console/stdio.c index 6e95d6c..4ba7992 100644 --- a/src/drivers/console/stdio.c +++ b/src/drivers/console/stdio.c @@ -5,6 +5,7 @@ #include +#include #include "drivers/console.h" #include "stdio.h" @@ -53,6 +54,11 @@ static STDIOConsoleDriver * _stdio_console_init(ukBus * bus, va_list ap) STDIOConsole stdio; (void) ap; + if(bus == NULL) + { + errno = ENODEV; + return NULL; + } _stdio_console_driver.bus = bus; stdio.interface = &stdio_console; stdio.driver = &_stdio_console_driver; diff --git a/src/kernel/boot.c b/src/kernel/boot.c index 04b84ab..073bd42 100644 --- a/src/kernel/boot.c +++ b/src/kernel/boot.c @@ -51,6 +51,8 @@ void boot_init(ukBoot * boot, char const * name, char const * args, { boot->name = name; boot->args = args; + boot->console = CONFIG_DEFAULT_CONSOLE; + boot->console_bus = CONFIG_DEFAULT_CONSOLE_BUS; boot_set_physmem(boot, physmem_low, physmem_high); } diff --git a/src/kernel/config.h b/src/kernel/config.h index 61df4e5..f51cd2f 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -10,7 +10,19 @@ /* constants */ # ifndef CONFIG_BOOT_MODULES -# define CONFIG_BOOT_MODULES 32 +# define CONFIG_BOOT_MODULES 32 +# endif +# ifndef CONFIG_DEFAULT_CONSOLE +# define CONFIG_DEFAULT_CONSOLE "uart" +# endif +# ifndef CONFIG_DEFAULT_CONSOLE_BUS +# define CONFIG_DEFAULT_CONSOLE_BUS "ioport" +# endif +# ifndef CONFIG_DEFAULT_DISPLAY +# define CONFIG_DEFAULT_DISPLAY "vga" +# endif +# ifndef CONFIG_DEFAULT_DISPLAY_BUS +# define CONFIG_DEFAULT_DISPLAY_BUS "vga" # endif #endif /* !UKERNEL_KERNEL_CONFIG_H */ diff --git a/src/kernel/multiboot.c b/src/kernel/multiboot.c index 95ca12d..bfd92e0 100644 --- a/src/kernel/multiboot.c +++ b/src/kernel/multiboot.c @@ -7,19 +7,7 @@ #if defined(__amd64__) || defined(__i386__) # include # include "drivers/boot/multiboot.h" - -# ifndef KERNEL_CONSOLE -# define KERNEL_CONSOLE "uart" -# endif -# ifndef KERNEL_CONSOLE_BUS -# define KERNEL_CONSOLE_BUS "ioport" -# endif -# ifndef KERNEL_DISPLAY -# define KERNEL_DISPLAY "vga" -# endif -# ifndef KERNEL_DISPLAY_BUS -# define KERNEL_DISPLAY_BUS "vga" -# endif +# include "config.h" /* public */ @@ -27,34 +15,24 @@ /* multiboot */ int multiboot(ukMultibootInfo * mi) { - char const * console = KERNEL_CONSOLE; - char const * display = KERNEL_DISPLAY; + char const * display = CONFIG_DEFAULT_DISPLAY; + char const * bus; size_t i; ukMultibootMod * mod; boot_init(boot, mi->loader_name, mi->cmdline, mi->mem_lower * 1024, mi->mem_upper * 1024); - boot_set_console(boot, console, KERNEL_CONSOLE_BUS); - -#ifdef notyet /* detect the video driver to use */ + bus = CONFIG_DEFAULT_DISPLAY_BUS; +#ifdef notyet if(mi->flags & BOOT_MULTIBOOT_INFO_HAS_VBE) + { display = "vesa"; + bus = "vga"; + } #endif - boot_set_display(boot, display, KERNEL_DISPLAY_BUS); - -#if 0 - /* report information on the boot process */ - puts("DeforaOS Multiboot"); - if(mi->loader_name != NULL) - printf("Loader: %s\n", mi->loader_name); - if(mi->cmdline != NULL) - printf("Command line: %s\n", mi->cmdline); - printf("%u MB memory available\n", - (mi->mem_upper - mi->mem_lower) / 1024); - printf("Booted from %#x\n", mi->boot_device_drive); -#endif + boot_set_display(boot, display, bus); /* register the modules */ if(mi->flags & BOOT_MULTIBOOT_INFO_HAS_MODS) diff --git a/tools/boot.c b/tools/boot.c index 954904c..d166bd1 100644 --- a/tools/boot.c +++ b/tools/boot.c @@ -2,4 +2,7 @@ /* Copyright (c) 2018 Pierre Pronchery */ /* This file is part of DeforaOS uKernel */ +#define CONFIG_DEFAULT_CONSOLE "stdio" +#define CONFIG_DEFAULT_CONSOLE_BUS "tty" + #include "kernel/boot.c" diff --git a/tools/init.c b/tools/init.c index 4d4a884..94ca145 100644 --- a/tools/init.c +++ b/tools/init.c @@ -14,7 +14,6 @@ int _init(void) { boot_init(boot, "user", NULL, 0, 0); - boot_set_console(boot, "tty", "stdio"); platform_init(platform, boot); platform_start(platform); return 0;