diff --git a/kernel/include/3rd/multiboot2.h b/kernel/include/3rd/multiboot2.h index ce4901f..96180aa 100644 --- a/kernel/include/3rd/multiboot2.h +++ b/kernel/include/3rd/multiboot2.h @@ -42,6 +42,8 @@ /* Flags set in the ’flags’ member of the multiboot header. */ #define MULTIBOOT_TAG_ALIGN 8 +#define MULTIBOOT_TAG_TOTAL 22 + #define MULTIBOOT_TAG_TYPE_END 0 #define MULTIBOOT_TAG_TYPE_CMDLINE 1 #define MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME 2 diff --git a/kernel/include/kreflock.h b/kernel/include/kreflock.h index ed3bcc6..5da4ce0 100644 --- a/kernel/include/kreflock.h +++ b/kernel/include/kreflock.h @@ -34,11 +34,11 @@ typedef struct { } reflock_t; #define NEW_REFLOCK(_on_lock, _on_unlock, _strict, _allow_force) \ - { _on_lock, \ - _on_unlock, \ - _strict, \ - _allow_force, \ - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } } + { \ + _on_lock, _on_unlock, _strict, _allow_force, { \ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 \ + } \ + } void reflock_make(reflock_t *lock); bool reflock_validate_magic(reflock_t *lock); diff --git a/kernel/include/multiboot2.h b/kernel/include/multiboot2.h new file mode 100644 index 0000000..102860b --- /dev/null +++ b/kernel/include/multiboot2.h @@ -0,0 +1,23 @@ +#ifndef __K_MULTIBOOT2 +#define __K_MULTIBOOT2 + +#include "3rd/multiboot2.h" +#include + +// STUB! +typedef int list_head; + +// make it tag-like to fit better with get_multiboot_tag +struct multiboot_module_list_tag { + multiboot_uint16_t type; // will be MULTIBOOT_TAG_MODULE + multiboot_uint16_t flags; // will be 0 + multiboot_uint32_t size; // will be sizeof(struct multiboot_module_list_tag) + + struct multiboot_tag_module *module; + list_head list; +}; + +struct multiboot_tag *get_multiboot_tag(uint8_t tag_id); +int multiboot2_init(uint64_t *addr, uint32_t magic); + +#endif \ No newline at end of file diff --git a/kernel/multiboot2.c b/kernel/multiboot2.c index 48ebf3a..338aeec 100644 --- a/kernel/multiboot2.c +++ b/kernel/multiboot2.c @@ -1,10 +1,23 @@ +#include "multiboot2.h" +#include "3rd/multiboot2.h" #include "khal.h" #include "kstdlib.h" -#include <3rd/multiboot2.h> +#include "kstring.h" +#include "sys/panic.h" #include +static struct multiboot_tag *unary_tags[MULTIBOOT_TAG_TOTAL]; + #define CHECK_FLAG(flags, bit) ((flags) & (1 << (bit))) +struct multiboot_tag *get_multiboot_tag(uint8_t tag_id) { + if (tag_id < 0 || tag_id >= MULTIBOOT_TAG_TOTAL) { + return NULL; + } + + return unary_tags[tag_id]; +} + void handle_cmdline_tag(struct multiboot_tag *tag); void handle_module_tag(struct multiboot_tag *tag); void handle_basic_load_base_addr(struct multiboot_tag *tag); @@ -28,6 +41,10 @@ int multiboot2_init(uint64_t *addr, uint32_t magic) { uint64_t size = *addr; serial_printf("Announced mbi size 0x%x\n", size); + // set all tags to NULL + memset(unary_tags, 0x00, + sizeof(struct multiboot_tag *) * MULTIBOOT_TAG_TOTAL); + tag = (struct multiboot_tag *)(mbi_addr + sizeof(uint64_t)); while (tag->type != MULTIBOOT_TAG_TYPE_END) { @@ -52,6 +69,14 @@ int multiboot2_init(uint64_t *addr, uint32_t magic) { break; } + // In case I'm just stupid + if (unary_tags[tag->type]) + PANIC("Duplicate multiboot tag during initialization"); + + // there can be more than one of those + // module tags will be handled separately after heap init + if (tag->type != MULTIBOOT_TAG_TYPE_MODULE) unary_tags[tag->type] = tag; + // Move to the next tag tag = (struct multiboot_tag *)((uintptr_t)tag) + ((tag->size + 7) & ~7); }