Page 1 of 1

Multiboot/GRUB Question

Posted: Sun Jul 14, 2013 6:12 am
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

Re: Multiboot/GRUB Question

Posted: Sun Jul 14, 2013 6:57 am
by sortie
You will want a copy of multiboot.h. Consult the documentation you got along with GRUB.

Re: Multiboot/GRUB Question

Posted: Sun Jul 14, 2013 9:17 am
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.

Re: Multiboot/GRUB Question

Posted: Sun Jul 14, 2013 10:20 am
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.

Re: Multiboot/GRUB Question

Posted: Sun Jul 14, 2013 10:32 am
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

Re: Multiboot/GRUB Question

Posted: Sun Jul 14, 2013 11:17 am
by Archangel
I tried it, and it worked like a charm. Thaks a lot!

Archangel

Re: Multiboot/GRUB Question

Posted: Sun Jul 14, 2013 12:20 pm
by heathCliff
Glad to hear it!