Passing multiboot_info_t into kernel and using it

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
smolloy
Posts: 11
Joined: Sat Jun 02, 2012 3:42 pm

Passing multiboot_info_t into kernel and using it

Post 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?
User avatar
iansjack
Member
Member
Posts: 4779
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Passing multiboot_info_t into kernel and using it

Post 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.
smolloy
Posts: 11
Joined: Sat Jun 02, 2012 3:42 pm

Re: Passing multiboot_info_t into kernel and using it

Post by smolloy »

Thank you. That proved it. It is indeed a paging problem. I will fix that now.
smolloy
Posts: 11
Joined: Sat Jun 02, 2012 3:42 pm

Re: Passing multiboot_info_t into kernel and using it

Post 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.
AnotherIdiot
Posts: 21
Joined: Sat Sep 28, 2024 8:00 pm
GitHub: https://github.com/ThatOSDeveloper

Re: Passing multiboot_info_t into kernel and using it

Post 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.
You know the drill what people put in here https://github.com/SlugOS/SlugOS
Post Reply