diff options
| author | Aleksa Vuckovic <aleksa@vuckovic.cc> | 2023-02-25 06:56:01 +0100 |
|---|---|---|
| committer | Aleksa Vuckovic <aleksa@vuckovic.cc> | 2023-02-25 08:45:09 +0100 |
| commit | 239900af293f192931391dc5579afab39a43e6c6 (patch) | |
| tree | 72d7f87ee6adf5aa84b78436197e03e61fba8d97 /kernel/src/boot/multiboot2.c | |
| parent | aaa23fffd02fb49cdbc56a480dbb5a8fa95bff38 (diff) | |
clang-format
Diffstat (limited to 'kernel/src/boot/multiboot2.c')
| -rw-r--r-- | kernel/src/boot/multiboot2.c | 68 |
1 files changed, 37 insertions, 31 deletions
diff --git a/kernel/src/boot/multiboot2.c b/kernel/src/boot/multiboot2.c index dd3ab78..8a7d0d6 100644 --- a/kernel/src/boot/multiboot2.c +++ b/kernel/src/boot/multiboot2.c @@ -1,9 +1,7 @@ #include <types.h> #include <multiboot2.h> - #include <graphics.h> #include <paging.h> - #include <libk/serial_stdio.h> #include <libk/string.h> #include <libk/list.h> @@ -12,11 +10,11 @@ /* https://www.gnu.org/software/grub/manual/multiboot2/html_node/Boot-information-format.html */ -mb2_tag_module* ext2_module; +mb2_tag_module *ext2_module; mmap_t mmap; -void init_fb(mb2_tag_fb* tag_fb) +void init_fb(mb2_tag_fb *tag_fb) { main_fb.addr = tag_fb->framebuffer_addr; main_fb.width = tag_fb->framebuffer_width; @@ -28,62 +26,70 @@ void init_fb(mb2_tag_fb* tag_fb) // identity map framebuffer address map_addr(main_fb.addr, main_fb.addr, FLAG_PRESENT | FLAG_WRITABLE); - map_addr(main_fb.addr + PAGE_SIZE, main_fb.addr + PAGE_SIZE, FLAG_PRESENT | FLAG_WRITABLE); + map_addr(main_fb.addr + PAGE_SIZE, main_fb.addr + PAGE_SIZE, + FLAG_PRESENT | FLAG_WRITABLE); } -void init_mmap(mb2_tag_mmap* tag_mmap) +void init_mmap(mb2_tag_mmap *tag_mmap) { INIT_LIST(mmap.list) // get data and store it into list - for (size_t i = sizeof(mb2_tag_mmap); i < tag_mmap->size; i += sizeof(mb2_tag_mmap_entry)) { - mmap_t* curr_mmap_entry = (mmap_t*)kalloc(sizeof(mmap_t)); - memcpy(&curr_mmap_entry->mmap_entry, (char*)tag_mmap + i, sizeof(mb2_tag_mmap_entry)); + for (size_t i = sizeof(mb2_tag_mmap); i < tag_mmap->size; + i += sizeof(mb2_tag_mmap_entry)) { + mmap_t *curr_mmap_entry = (mmap_t *)kalloc(sizeof(mmap_t)); + memcpy(&curr_mmap_entry->mmap_entry, (char *)tag_mmap + i, + sizeof(mb2_tag_mmap_entry)); add_to_list(&curr_mmap_entry->list, &mmap.list, mmap.list.next); } } -void init_module(mb2_tag_module* tag_module) +void init_module(mb2_tag_module *tag_module) { // name is utf-8 encoded string! - uint32_t name_size = tag_module->size - sizeof(tag_module) + sizeof(char*); - tag_module->name = (char*)kalloc(name_size); - memcpy(tag_module->name, tag_module + tag_module->size - name_size, name_size); + uint32_t name_size = + tag_module->size - sizeof(tag_module) + sizeof(char *); + tag_module->name = (char *)kalloc(name_size); + memcpy(tag_module->name, tag_module + tag_module->size - name_size, + name_size); kfree(tag_module->name); } -void read_mb2(mb2_tag_header* multiboot_bootinfo, uint32_t multiboot_magic) +void read_mb2(mb2_tag_header *multiboot_bootinfo, uint32_t multiboot_magic) { if (multiboot_magic != MB2_MAGIC) { // not loaded by multiboot2 bootloader - __asm__ __volatile__ ("hlt;"); + __asm__ __volatile__("hlt;"); } // we will store framebuffer information here - static mb2_tag_fb* tag_fb; - static mb2_tag_mmap* tag_mmap; + static mb2_tag_fb *tag_fb; + static mb2_tag_mmap *tag_mmap; // skip first 8 bytes (total_size + reserved) - mb2_tag_header* tag_header = (mb2_tag_header*)((uint64_t)multiboot_bootinfo + 8 + KERNEL_VMA); + mb2_tag_header *tag_header = + (mb2_tag_header *)((uint64_t)multiboot_bootinfo + 8 + + KERNEL_VMA); while (tag_header->type != MB2_TAG_END) { // process tag_type - switch(tag_header->type) { - case MB2_TAG_FB: - tag_fb = (mb2_tag_fb*)tag_header; - break; - case MB2_TAG_MMAP: - tag_mmap = (mb2_tag_mmap*)tag_header; - break; - case MB2_TAG_MODULE: - ext2_module = (mb2_tag_module*)tag_header; - break; - default: - break; + switch (tag_header->type) { + case MB2_TAG_FB: + tag_fb = (mb2_tag_fb *)tag_header; + break; + case MB2_TAG_MMAP: + tag_mmap = (mb2_tag_mmap *)tag_header; + break; + case MB2_TAG_MODULE: + ext2_module = (mb2_tag_module *)tag_header; + break; + default: + break; } // next mb2_tag - tag_header += tag_header->size / 8 + ((tag_header->size % 8) > 0); + tag_header += + tag_header->size / 8 + ((tag_header->size % 8) > 0); } init_fb(tag_fb); |
