Multiboot: display mmap and mod informations

sample code from https://www.gnu.org/software/grub/manual/multiboot/html_node/kernel_002ec.html#kernel_002ec
have issue (c.f. https://forum.osdev.org/viewtopic.php?t=30318)
This commit is contained in:
Mathieu Maret 2019-05-16 23:12:46 +02:00
parent 3bca737990
commit 13f1dc7878

View File

@ -26,6 +26,7 @@ void cpuid(int code, uint32_t *a, uint32_t *d)
// Multiboot information available here : // Multiboot information available here :
// https://www.gnu.org/software/grub/manual/multiboot/multiboot.html#kernel_002ec // https://www.gnu.org/software/grub/manual/multiboot/multiboot.html#kernel_002ec
// https://www.gnu.org/software/grub/manual/multiboot/html_node/Boot-information-format.html#Boot%20information%20format
void kmain(unsigned long magic, unsigned long addr) void kmain(unsigned long magic, unsigned long addr)
{ {
unsigned long upper_mem = 0; unsigned long upper_mem = 0;
@ -42,7 +43,7 @@ void kmain(unsigned long magic, unsigned long addr)
multiboot_info_t *mbi = (multiboot_info_t *)addr; multiboot_info_t *mbi = (multiboot_info_t *)addr;
/* Are mem_* valid? */ /* Are mem_* valid? */
if (CHECK_FLAG(mbi->flags, 0)) { if (CHECK_FLAG(mbi->flags, 0)) {
printf("mem_lower = %dKB mem_upper %dKB\n", mbi->mem_lower, mbi->mem_upper); printf("mem_lower = %dKiB mem_upper %dKiB\n", mbi->mem_lower, mbi->mem_upper);
upper_mem = mbi->mem_upper; upper_mem = mbi->mem_upper;
} }
@ -55,6 +56,33 @@ void kmain(unsigned long magic, unsigned long addr)
if (CHECK_FLAG(mbi->flags, 2)) { if (CHECK_FLAG(mbi->flags, 2)) {
printf("cmdline = %s\n", (char *)mbi->cmdline); printf("cmdline = %s\n", (char *)mbi->cmdline);
} }
if (CHECK_FLAG(mbi->flags, 3)) {
multiboot_module_t *mod;
uint32_t i;
printf("mods_count = %d, mods_addr = 0x%x\n", (int)mbi->mods_count,
(int)mbi->mods_addr);
for (i = 0, mod = (multiboot_module_t *)mbi->mods_addr; i < mbi->mods_count;
i++, mod++)
printf(" mod_start = 0x%x, mod_end = 0x%x, cmdline = %s\n",
(unsigned)mod->mod_start, (unsigned)mod->mod_end, (char *)mod->cmdline);
}
if (CHECK_FLAG(mbi->flags, 6)) {
struct multiboot_mmap_entry *mmap = (struct multiboot_mmap_entry*)mbi->mmap_addr;
uint size = mbi->mmap_length / sizeof(struct multiboot_mmap_entry);
printf("mmap buffer at %d size %d %d\n", mbi->mmap_addr, mbi->mmap_length, sizeof(multiboot_memory_map_t) );
for (uint i = 0; i < size; i++){
printf("base_addr_high = 0x%x, base_addr_low = 0x%x, "
"length_high = 0x%x, length_low = 0x%x, type = 0x%x\n",
(unsigned) (mmap[i].addr >> 32),
(unsigned) (mmap[i].addr & 0xffffffff),
(unsigned) (mmap[i].len >> 32),
(unsigned) (mmap[i].len & 0xffffffff),
(uint32_t)mmap[i].type);
}
}
} }
if (upper_mem == 0) { if (upper_mem == 0) {