Multiboot/GRUB Question

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
User avatar
Archangel
Posts: 6
Joined: Thu Jun 06, 2013 2:17 pm

Multiboot/GRUB Question

Post by Archangel »

Hi,

I've just started writing my kernel, and actually put effort into it. I decided to use GRUB2 as a bootloader as it is far easier to do that than to write a bootloader too. The problem, or rather the challenge is that I need to get the multiboot info passed by GRUB.

The multiboot specification says that GRUB passes the address of this structure in the ebx register. I got the value in the register, but now I need to access this structure. I need to copy it to the c representation of the same structure.

I am newish to c and asm, and very new to gcc, how would I create a copy of that structure so I can use the various things in it. What is the best/easies way to do it. This really seems like a simple problem, but I just can't get it to work.

I don't even know if the address I get is correct, when ii boot my kernel using GRUB on real hardware, the value in the register is returned as 0x10000. Is this correct? It does seem to be exactly the same every time I boot so it ssems right.

Thanks.
Archangel
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: Multiboot/GRUB Question

Post by sortie »

You will want a copy of multiboot.h. Consult the documentation you got along with GRUB.
User avatar
Archangel
Posts: 6
Joined: Thu Jun 06, 2013 2:17 pm

Re: Multiboot/GRUB Question

Post by Archangel »

Hi,

I do have multiboot.h and the multiboot info structure defined, it's just that I'm not sure how to copy the in-memory structure pointed to by the ebx register into my structure so I can use it.
heathCliff
Posts: 2
Joined: Sat Dec 12, 2009 12:05 pm

Re: Multiboot/GRUB Question

Post by heathCliff »

Assuming you're working in C, provide it as an argument to your kernel's C code. Upon entry in assembly, set up your stack, push your arguments (EBX) in reverse order onto the stack, and then call your kernel's function (e.g. kmain).

You would do well to review the C calling convention.
User avatar
Archangel
Posts: 6
Joined: Thu Jun 06, 2013 2:17 pm

Re: Multiboot/GRUB Question

Post by Archangel »

Hi,

Looking at JamesM's and Brans kernel development tutorials I noticed they pass the multiboot header that way, makes sense. Ill try it. Thank you

Regards
Archangel
User avatar
Archangel
Posts: 6
Joined: Thu Jun 06, 2013 2:17 pm

Re: Multiboot/GRUB Question

Post by Archangel »

I tried it, and it worked like a charm. Thaks a lot!

Archangel
heathCliff
Posts: 2
Joined: Sat Dec 12, 2009 12:05 pm

Re: Multiboot/GRUB Question

Post by heathCliff »

Glad to hear it!
Post Reply