diff options
Diffstat (limited to 'kernel/src/boot/tag.c')
-rw-r--r-- | kernel/src/boot/tag.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/kernel/src/boot/tag.c b/kernel/src/boot/tag.c new file mode 100644 index 0000000..22ea758 --- /dev/null +++ b/kernel/src/boot/tag.c @@ -0,0 +1,91 @@ +#include <panic.h> +#include <string.h> + +#include "print.h" +#include "tag.h" +#include "acpi/acpi.h" +#include "graphics/framebuffer.h" +#include "memory/memory.h" + +static struct BootInfo info; + +static void read_cmdline(struct BootTag *tag, char *data, uint8_t len) { + debugk("Found cmdline"); + if (len >= CMDLINE_MAX) + panic("multiboot2 cmd line to long\nmax is %d but was provided %d\n", + CMDLINE_MAX, len); + memcpy(tag->data.cmdline, data, len); + info.tags[ID_CMDLINE] = *tag; +} + +static void read_framebuffer(struct BootTag *tag, uint32_t *data) { + debugk("Found framebuffer"); + tag->data.framebuffer = (struct Framebuffer *) data; + info.tags[ID_FRAMEBUFFER] = *tag;; +} + +static void read_memorymap(struct BootTag *tag, uint32_t *data) { + debugk("Found memorymap"); + tag->data.memory_map = (struct MemoryMap *) data; + info.tags[iD_MEMORYMAP] = *tag; +} + +static void read_rsdp(struct BootTag *tag, char *data) { + debugk("Found RSDP"); + tag->data.rsdp = (struct RootSystemDescriptionPointer *) data; + info.tags[ID_RSDP] = *tag; +} + +static uint32_t *read_tag(uint32_t *data) { + struct BootTag tag; + tag.type = ((uint16_t*)data)[0]; + tag.size = data[1]; + tag.valid = 1; + + uint8_t data_len = tag.size - 2 * sizeof(uint32_t); + + switch (tag.type) { + case ID_CMDLINE: + read_cmdline(&tag, (char *)(data + 2), data_len); + break; + case ID_FRAMEBUFFER: + read_framebuffer(&tag, data + 2); + break; + case iD_MEMORYMAP: + read_memorymap(&tag, data + 2); + break; + case ID_RSDP: + read_rsdp(&tag, (char *) (data + 2)); + break; + default: + break; + } + + if(tag.size % 8 != 0) { + tag.size += 8 - (tag.size % 8); + } + + return data + tag.size / sizeof(uint32_t); +} + +void load_boot_info(void* boot_info) { + + debugk("Reading multiboot info"); + + memset(&info, 0, sizeof(boot_info)); + + uint32_t* data = (uint32_t*) boot_info; + info.total_size = *data++; + info.reserved = *data++; + + while((uint8_t*) data < (uint8_t*) boot_info + info.total_size) { + data = read_tag(data); + } + + succek("Loaded multiboot info"); +} + +bool get_boot_tag(enum BootTagID id, struct BootTag **tag) { + *tag = &info.tags[id]; + return (*tag)->valid; +} |