From fa4ff5facf837f280d15400ff44f102dc6d31d3a Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 22 Oct 2020 22:03:43 -0400 Subject: [PATCH] load some multiboot2 info after the framebuffer is initialized --- src/hos_main.c | 6 +++++- src/mbinfo.c | 51 ++++++++++++++++++++++++++++++++++++++++++++---- src/mbinfo.h | 4 +++- src/mem.h | 2 ++ src/multiboot2.h | 7 ++++++- 5 files changed, 63 insertions(+), 7 deletions(-) diff --git a/src/hos_main.c b/src/hos_main.c index bf1cd0d..d002f47 100644 --- a/src/hos_main.c +++ b/src/hos_main.c @@ -5,11 +5,15 @@ void hos_main(uint32_t mbinfo_addr) { - mbinfo_init(mbinfo_addr); + if (!mbinfo_init(mbinfo_addr)) + { + return; + } if (!fb_ready()) { return; } klog_init(); klog_printf("Welcome to HOS!\n"); + mbinfo_load(); } diff --git a/src/mbinfo.c b/src/mbinfo.c index 8af9d0d..48712f6 100644 --- a/src/mbinfo.c +++ b/src/mbinfo.c @@ -1,10 +1,31 @@ #include "multiboot2.h" #include "fb.h" +#include "mem.h" +#include +#include "klog.h" -static void mbinfo_process_tag(multiboot2_info_tag_t * tag) +static uint32_t mbinfo[2048]; + +static void mbinfo_process_tag(const multiboot2_info_tag_t * tag) { switch (tag->type) { + case MULTIBOOT2_INFO_BOOT_COMMAND_LINE: + { + multiboot2_info_boot_command_line_t * cl = + (multiboot2_info_boot_command_line_t *)tag; + klog_printf("Kernel boot command line: '%s'\n", cl->string); + } + break; + + case MULTIBOOT2_INFO_BOOT_LOADER_NAME: + { + multiboot2_info_boot_loader_name_t * bln = + (multiboot2_info_boot_loader_name_t *)tag; + klog_printf("Boot loader: '%s'\n", bln->string); + } + break; + case MULTIBOOT2_INFO_FRAMEBUFFER_INFO: { multiboot2_info_framebuffer_info_t * fbinfo = @@ -18,12 +39,34 @@ static void mbinfo_process_tag(multiboot2_info_tag_t * tag) } } -void mbinfo_init(uint32_t mbinfo_addr) +static void process_tags(const multiboot2_info_tag_t * tag, bool init) { - multiboot2_info_tag_t * tag = (multiboot2_info_tag_t *)(mbinfo_addr + sizeof(multiboot2_info_header_t)); while (tag->type != 0u) { - mbinfo_process_tag(tag); + if ((init && (tag->type == MULTIBOOT2_INFO_FRAMEBUFFER_INFO)) || + (!init && (tag->type != MULTIBOOT2_INFO_FRAMEBUFFER_INFO))) + { + mbinfo_process_tag(tag); + } tag = multiboot2_info_next_tag(tag); } } + +bool mbinfo_init(uint32_t mbinfo_addr) +{ + multiboot2_info_header_t * mbinfo_header = (multiboot2_info_header_t *)mbinfo_addr; + if (mbinfo_header->total_size <= sizeof(mbinfo)) + { + memcpy32(mbinfo, mbinfo_header, mbinfo_header->total_size / 4u); + multiboot2_info_tag_t * tag = (multiboot2_info_tag_t *)(mbinfo + sizeof(multiboot2_info_header_t) / 4u); + process_tags(tag, true); + return true; + } + return false; +} + +void mbinfo_load(void) +{ + multiboot2_info_tag_t * tag = (multiboot2_info_tag_t *)(mbinfo + sizeof(multiboot2_info_header_t) / 4u); + process_tags(tag, false); +} diff --git a/src/mbinfo.h b/src/mbinfo.h index 314f675..bd95bdf 100644 --- a/src/mbinfo.h +++ b/src/mbinfo.h @@ -2,7 +2,9 @@ #define MBINFO_H #include +#include -void mbinfo_init(uint32_t mbinfo_addr); +bool mbinfo_init(uint32_t mbinfo_addr); +void mbinfo_load(void); #endif diff --git a/src/mem.h b/src/mem.h index e5ead99..fd843a2 100644 --- a/src/mem.h +++ b/src/mem.h @@ -1,6 +1,8 @@ #ifndef MEM_H #define MEM_H +#include + static inline void memcpy(void * dest, const void * src, size_t n) { uint32_t r0, r1, r2; diff --git a/src/multiboot2.h b/src/multiboot2.h index f5603a5..3881bb9 100644 --- a/src/multiboot2.h +++ b/src/multiboot2.h @@ -70,7 +70,12 @@ typedef struct { typedef struct { multiboot2_info_tag_t header; - uint8_t string[]; + char string[]; +} multiboot2_info_boot_command_line_t; + +typedef struct { + multiboot2_info_tag_t header; + char string[]; } multiboot2_info_boot_loader_name_t; typedef struct {