aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/dump_multiboot.cc
blob: 219d64f2e0c4c89dec24cd795c75ad62266dff41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <multiboot2.h>
#include <stdlib.h>

extern "C" void dump_multiboot(uint32_t mb_magic, uint32_t mb_addr) {
  printk("multiboot magic: ", uhex{mb_magic}, mb_magic == MULTIBOOT2_BOOTLOADER_MAGIC ? " valid" : " invalid", '\n');
  printk("multiboot  addr: ", uhex{mb_addr}, !(mb_addr & 7) ? " is aligned" : " is not aligned", '\n');

  struct multiboot_tag* tag;
  const uint32_t size = *reinterpret_cast<uint32_t*>(mb_addr);
  printk("Announced mbi size ", size, '\n');

  for (tag = reinterpret_cast<multiboot_tag*>(mb_addr + 8); tag->type != MULTIBOOT_TAG_TYPE_END;
       tag = reinterpret_cast<multiboot_tag*>(reinterpret_cast<uint8_t*>(tag) + ((tag->size + 7u) & ~7u))) {
    switch (tag->type) {
      case MULTIBOOT_TAG_TYPE_CMDLINE: {
        auto* t = reinterpret_cast<multiboot_tag_string*>(tag);
        printk("Command line = [", t->string, "]\n");
      } break;

      case MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME: {
        auto* t = reinterpret_cast<multiboot_tag_string*>(tag);
        printk("Boot loader name = [", t->string, "]\n");
      } break;

      case MULTIBOOT_TAG_TYPE_BOOTDEV: {
        auto* t = reinterpret_cast<multiboot_tag_bootdev*>(tag);
        printk("Boot device ", uhex{t->biosdev}, " slice ", t->slice, " part ", t->part, '\n');
      } break;

      case MULTIBOOT_TAG_TYPE_BASIC_MEMINFO: {
        auto* t = reinterpret_cast<multiboot_tag_basic_meminfo*>(tag);
        printk("mem_lower = ", t->mem_lower, "KB\n", "mem_upper = ", t->mem_upper, "KB\n");
      } break;

      case MULTIBOOT_TAG_TYPE_MMAP: {
        auto* t = reinterpret_cast<multiboot_tag_mmap*>(tag);
        multiboot_memory_map_t* mmap;

        printk("memory map\n");
        for (mmap = t->entries; reinterpret_cast<uint8_t*>(mmap) < reinterpret_cast<uint8_t*>(tag) + tag->size;
             mmap = reinterpret_cast<multiboot_memory_map_t*>(reinterpret_cast<uint32_t>(mmap) +
                                                              reinterpret_cast<multiboot_tag_mmap*>(tag)->entry_size)) {
          printk("  base_addr = ", uhex{static_cast<uint32_t>(mmap->addr >> 32)}, ' ',
                 uhex{static_cast<uint32_t>(mmap->addr & 0xffffffff)});
          printk(" length = ", static_cast<uint32_t>(mmap->len >> 32), ' ',
                 static_cast<uint32_t>(mmap->len & 0xffffffff));
          printk(" type = ", mmap->type, '\n');
        }
      } break;

      default:
        printk("Tag ", tag->type, ", Size ", tag->size, '\n');
        break;
    }  // switch(tag->type)
  }    // for(each tag)

  tag = reinterpret_cast<multiboot_tag*>(reinterpret_cast<uint8_t*>(tag) + ((tag->size + 7u) & ~7u));
  printk("Total mbi size ", reinterpret_cast<uint32_t>(tag) - mb_addr, '\n');
}