aboutsummaryrefslogtreecommitdiff
path: root/kernel.cc
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2021-02-02 22:27:27 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2021-02-02 22:27:27 +0200
commit36e8ee0cdaa904ee00710b1d2df16691729cc93d (patch)
tree16e3836af7ef9efa6da1bbde4248ae5ad956bf58 /kernel.cc
parentlibk: add its own makefile (diff)
downloadkernel.cpp-36e8ee0cdaa904ee00710b1d2df16691729cc93d.tar.xz
Print some multiboot2 information
Diffstat (limited to 'kernel.cc')
-rw-r--r--kernel.cc76
1 files changed, 69 insertions, 7 deletions
diff --git a/kernel.cc b/kernel.cc
index 3df1903..ffc7180 100644
--- a/kernel.cc
+++ b/kernel.cc
@@ -1,6 +1,3 @@
-#include <stdlib.h>
-#include <types.h>
-
/* Check if the compiler thinks you are targeting the wrong operating system. */
#if defined(__linux__)
#error "You are not using a cross-compiler"
@@ -11,16 +8,81 @@
#error "This tutorial needs to be compiled with a ix86-elf compiler"
#endif
+#include "multiboot2.h"
#include "vga.h"
+#include <stdlib.h>
+#include <types.h>
-extern "C" void kernel_main(void) {
+extern "C" void kernel_main(uint32_t mb_magic, uint32_t mb_addr) {
VGA terminal;
- console_set(&terminal);
+ Console::set(&terminal);
terminal.set_color(VGA::VGA_COLOR_CYAN, VGA::VGA_COLOR_BROWN);
- terminal.write("Hello, kernel World! xxx--\n", "--xyxyxz\n", 10);
+ printk("Hello, kernel World!\n");
+
+ printk("multiboot magic: 0x", mb_magic,
+ mb_magic == MULTIBOOT2_BOOTLOADER_MAGIC ? " is valid" : " is invalid",
+ '\n');
+ printk("multiboot addr: 0x", mb_addr, '\n');
+
+ if (mb_addr & 7) {
+ printk("unaligned mbi\n");
+ }
+
+ struct multiboot_tag *tag;
+ const uint32_t size = *(unsigned *)mb_addr;
+ printk("Announced mbi size 0x", size, '\n');
+
+ for (tag = (struct multiboot_tag *)(mb_addr + 8);
+ tag->type != MULTIBOOT_TAG_TYPE_END;
+ tag = (struct multiboot_tag *)((multiboot_uint8_t *)tag +
+ ((tag->size + 7) & ~7))) {
+
+ switch (tag->type) {
+ case MULTIBOOT_TAG_TYPE_CMDLINE:
+ printk("Command line = [", ((struct multiboot_tag_string *)tag)->string,
+ "]\n");
+ break;
+ case MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME:
+ printk("Boot loader name = [",
+ ((struct multiboot_tag_string *)tag)->string, "]\n");
+ break;
+ case MULTIBOOT_TAG_TYPE_BASIC_MEMINFO:
+ printk("mem_lower = ",
+ ((struct multiboot_tag_basic_meminfo *)tag)->mem_lower, "KB\n",
+ "mem_upper = ",
+ ((struct multiboot_tag_basic_meminfo *)tag)->mem_upper, "KB\n");
+ break;
+ case MULTIBOOT_TAG_TYPE_BOOTDEV:
+ printk("Boot device 0x", ((struct multiboot_tag_bootdev *)tag)->biosdev,
+ " slice ", ((struct multiboot_tag_bootdev *)tag)->slice, " part ",
+ ((struct multiboot_tag_bootdev *)tag)->part, '\n');
+ break;
+ case MULTIBOOT_TAG_TYPE_MMAP: {
+ multiboot_memory_map_t *mmap;
+
+ printk("mmap\n");
+
+ for (mmap = ((struct multiboot_tag_mmap *)tag)->entries;
+ (multiboot_uint8_t *)mmap < (multiboot_uint8_t *)tag + tag->size;
+ mmap = (multiboot_memory_map_t *)((unsigned long)mmap +
+ ((struct multiboot_tag_mmap *)tag)
+ ->entry_size))
+ printk(" base_addr = 0x", (unsigned)(mmap->addr >> 32), ' ',
+ (unsigned)(mmap->addr & 0xffffffff), " length = 0x",
+ (unsigned)(mmap->len >> 32), ' ',
+ (unsigned)(mmap->len & 0xffffffff), " type = 0x",
+ (unsigned)mmap->type, '\n');
+ } break;
+ default:
+ printk("Tag 0x", tag->type, ", Size 0x", tag->size, '\n');
+ break;
+ } // switch(tag->type)
+ } // for(each tag)
- printk("This is printk\n");
+ tag = (struct multiboot_tag *)((multiboot_uint8_t *)tag +
+ ((tag->size + 7) & ~7));
+ printk("Total mbi size 0x", (unsigned)tag - mb_addr, '\n');
abort();
}