Page 1 of 1

Passing multiboot_info_t into kernel and using it

Posted: Fri May 02, 2025 8:31 am
by smolloy
I am moving on from the x86 higher-half barebones,,and I'm trying to pass the multiboot magic and header into the kernel:

Code: Select all

pushl %ebx # Push the pointer to the multiboot info struct
pushl %eax # Push the magic to be checked by the kernel
call kernel_main

Code: Select all

void kernel_main(uint32_t magic, uint32_t physaddr)
I get the expected magic number, but as soon as I dereference addr->flags I get a crash, and it is this that I am trying to understand.

The value of physaddr is 65536 (0x10000), and since I'm working with a higher-half kernel, I convert physaddr to a virtual address as follows:

Code: Select all

multiboot_info_t *addr = (multiboot_info_t*)(physaddr + 0xC0000000);
My guess is that the crash is due to this memory location not being properly mapped in the page tables, but before I try to start fixing that (I am a novice) I wanted to check with you good people to make sure it is not something more obvious than that.

Is it a paging problem? How could I confirm that? Is there something else I should check?

Re: Passing multiboot_info_t into kernel and using it

Posted: Fri May 02, 2025 8:40 am
by iansjack
Have you mapped that physical address to the corresponding virtual address? If not, the program will triple-fault.

You can check page mappings by running under qemu and using the “info mem” command. It would probably help if you used gdb to debug the program. That way you can insert breakpoints, inspect variables and memory content, and pinpoint the exact point of failure. Used in conjunction with the qemu monitor it becomes very easy to track down the cause of this sort of problem.

Re: Passing multiboot_info_t into kernel and using it

Posted: Fri May 02, 2025 8:49 am
by smolloy
Thank you. That proved it. It is indeed a paging problem. I will fix that now.

Re: Passing multiboot_info_t into kernel and using it

Posted: Fri May 02, 2025 2:23 pm
by smolloy
Just to confirm -- I fixed boot.s so that the value in ebx (that's where multiboot puts the struct pointer) is properly mapped. This fixes my problem.

Re: Passing multiboot_info_t into kernel and using it

Posted: Fri May 23, 2025 6:20 am
by AnotherIdiot
You should define a virtual memory layout that maps all available physical memory addresses according to your system’s requirements. Additionally, implement assembly-level routines to translate between physical and virtual addresses as needed.