Long mode initialisation problem
Long mode initialisation problem
Hello!
I'm trying to port my little kernel over to 64-bit. Just from beginning I've got problems. Code assembles just fine, but it doesn't run properly. I'm testing it under VBox, which triple faults and QEMU, which just hangs. Bochs reboots all the time so isn't very helpful. I've got a small request, can somebody check my code? Here it is.
Regards,
Mark
I'm trying to port my little kernel over to 64-bit. Just from beginning I've got problems. Code assembles just fine, but it doesn't run properly. I'm testing it under VBox, which triple faults and QEMU, which just hangs. Bochs reboots all the time so isn't very helpful. I've got a small request, can somebody check my code? Here it is.
Regards,
Mark
Please correct my English. If you'll find mistake please tell me about it so I can improve my English.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Long mode initialisation problem
Bochs (unlike other emus) will print messages to the console when it resets - I suggest you start reading those instead of claiming it doesn't help.
Re: Long mode initialisation problem
Bochs reboots just after GRUB shows, but I can't do anything and it doesn't print anything to console.
Regards,
Mark
Regards,
Mark
Please correct my English. If you'll find mistake please tell me about it so I can improve my English.
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Re: Long mode initialisation problem
But it does write a wealth of information to the bochsout file, which you can look at to see where and why it reset.
Re: Long mode initialisation problem
I can see two problems. The upper part of page table entries aren't being initialized, and the selector you use in the far jump is wrong (being the address of the Code descriptor rather than it's offset in the GDT which is .
Re: Long mode initialisation problem
Hi,
If you specify a log file, output will go there, otherwise, it will be sent to the console.
Cheers,
Adam
neonek wrote:Bochs reboots just after GRUB shows, but I can't do anything and it doesn't print anything to console.
Code: Select all
cpu: [...], reset_on_triple_fault=0
Cheers,
Adam
Re: Long mode initialisation problem
OK. Now I know that bochs reboots due to #PF followed by #GP. I know what's wrong but I can't figure out where bug is. Please, can somebody check my code?
Regards,
Mark
Regards,
Mark
Please correct my English. If you'll find mistake please tell me about it so I can improve my English.
Re: Long mode initialisation problem
Your PML4, PDPT, PD and PT aren't aligned. Either put them at a fixed 4K aligned address outside the kernel, or make sure that the BSS section has 4K alignment, and move the MBOOT and MBOOT_Magic variables to the end. You should also fix the two other issues I mentioned if you haven't already.
Re: Long mode initialisation problem
I've aligned my paging tables and moved MBOOT variables after paging tables in .bss. GDT.Code has valid value (0x08). Still I can't figure out how to set up those paging tables. What did you mean by "The upper part of page table entries aren't being initialized" ? And bochs gives me a weird RIP values after jump to long mode code (00000000802000df). Thanks for help.
Regards,
Mark
Regards,
Mark
Please correct my English. If you'll find mistake please tell me about it so I can improve my English.
Re: Long mode initialisation problem
Chances are that your kernel is linked at 0x200000 instead of 0xffffffff80000000. It should be linked at 0xffffffff80000000. And in the V2P macro, you also need to add the physical address of the kernel (since it's probably not loaded at 0).
In this code, you're only initializing the first half of the page table entries. You should have a and dword [edi+4], byte 0 in there.
Code: Select all
.IdentityMap:
mov [edi], ebx
add ebx, 0x1000
add edi, 0x08
loop .IdentityMap
Re: Long mode initialisation problem
My startup section is linked at 0x100000. Other sections are linked at 0xFFFFFFFF80000000. I've changed a bit KERNEL_BASE to 0xFFFFFFFF7FF00000, so V2P gives proper values. I've also added code for clearing upper part of page tables but with no luck. Bochs still page faults at 0x0000000080200***. I don't have any ideas what can be wrong here. Anyway, thank you for your help.
Regards,
Mark
Regards,
Mark
Please correct my English. If you'll find mistake please tell me about it so I can improve my English.