Bare Bones tutorial on GRUB

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
birie
Posts: 3
Joined: Wed Feb 27, 2008 12:23 am

Bare Bones tutorial on GRUB

Post by birie »

Aloha all,
I was just working with the barebones tutorial on creating a correct multiboot elf kernel. In the tutorial it pushes eax then ebx. In the multiboot spec (0.6.95) the first parameter that is passed is ebx then eax. I was just wondering if this was intentional and there is something I am missing or if it was just based of off an older multiboot spec.
Thanks,
Bryce
User avatar
codemastersnake
Member
Member
Posts: 148
Joined: Sun Nov 07, 2004 12:00 am
Contact:

Post by codemastersnake »

I don't know about the tutorial but you should always stick to the official documentations.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post by Solar »

Hmmmm... I know I got the order wrong once, but I thought I corrected that in my code before I wrote that tutorial. It might well be that bug survived; can you double-check this, i.e. check which way around actually leads to the correct results?
Every good solution is obvious once you've found it.
birie
Posts: 3
Joined: Wed Feb 27, 2008 12:23 am

Post by birie »

Ebx then eax produces correct results for me. I suppose it all depends on how you write your c function. I copied the kernel.c code from the multiboot spec website and needed to swap.
User avatar
os.hacker64
Member
Member
Posts: 149
Joined: Mon Feb 11, 2008 4:43 pm
Location: Limbo City,Afterlife

Re: Bare Bones tutorial on GRUB

Post by os.hacker64 »

birie wrote:Aloha all,
I was just working with the barebones tutorial on creating a correct multiboot elf kernel. In the tutorial it pushes eax then ebx. In the multiboot spec (0.6.95) the first parameter that is passed is ebx then eax. I was just wondering if this was intentional and there is something I am missing or if it was just based of off an older multiboot spec.
Thanks,
Bryce
A brother Hawaiian!
Kanu Operating System
Working on:Paging and Multitasking

BURN /\/\1(40$0|=7
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post by Solar »

birie wrote:I suppose it all depends on how you write your c function. I copied the kernel.c code from the multiboot spec website and needed to swap.
Aaaahhhhh... that explains it, then.

Multiboot: kernel.c

Code: Select all

void cmain (unsigned long magic, unsigned long addr)
BareBones: main.c

Code: Select all

void main( void* mbd, unsigned int magic )
If the C function expects to pop the parameters the other way round, of course you have to push them the other way round, too.

This isn't a mistake either in the BareBones or the Multiboot docs, as there is no "right" way to put the parameters on the stack. You just tried to slice & dice code from two different sources, and got bitten by a difference in interface. ;-)
Every good solution is obvious once you've found it.
birie
Posts: 3
Joined: Wed Feb 27, 2008 12:23 am

re:

Post by birie »

Back to that old think before you post thing. (: I realized it just after I posted. Thanks for the response. And hello to all the hawaiian os devs.
Post Reply