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.
I used GRUB as a bootloader for my kernel. I follow the specs on grub
website, I used exactly the same boot.s and multiboot.h but I have a
problem.
After grub load my kernel I do this test:
I think that in that same tutorial, you push the values of eax and ebx to pass them to main().
Just checking - have you definitely pushed them in the right order? If not, you would be getting a pointer to the multiboot info structure rather than the magic number.
int cmain(unsigned long magic, unsigned long addr)
{
...
}
I tried to display the value of addr and it seems to be the real grub
multiboot structure so I think that the value is pushed in a right order.
However I tried to debug it with bochs setting a logical break at the entry
point. The value of %eax was 0x2BADB002 (The good magic). Next, I step
into but I do not arrive to interpret the result.
That is odd...you could try breaking at the entry point and then using si to step one instruction at a time, to see what goes wrong. Have you changed boot.s at all?
The result should be something like: <Address of cmain> <Magic value> <Pointer to multiboot structure>. Also try "info regs" to see if the value of ESP is expected.
The stack grows downwards, doesn't it? So Bochs is displaying [esp], [esp+4] and [esp+8], when you want to see [esp-12], [esp-8] and [esp-4]. What does x/3wx esp-12 show?...
After the entry point there is the prolog and the test (002017af:), this
is what I'm doing in main. In the assembly we see that the value of
magic is located to "ss:[ebp+0x8]". So, I put a breakpoint to 0x002017af
and I did this :
cacao wrote:Hmm...yes the stack grows downward but if I set a breakpoint at the
entry point, Where is the parameters of main located ? On the stack ?
Um. Yes, of course, you're right. I was getting confused...
I just noticed, though: why is ESP so low? According to boot.s, the stack is after the end of the kernel, which (according to Bochs) is loaded at 2MB or so. How did you link the kernel? Perhaps you should inspect the kernel with a hex editor to see if the multiboot header looks right...
EDIT: also, try setting a breakpoint at multiboot_entry and stepping from there.
cacao wrote:YES !!!! The linker script. I check it and I saw that my "ENTRY" value was
"cmain" instead of "_start" (defined in boot.s). The problem is solved.