Page 1 of 1

Bochs showing only 32-bit linear addresses for PML4

Posted: Sun May 27, 2018 5:01 pm
by CRoemheld
I'm currently trying to jump into the 64-bit kernel using a separate loader.
Though I think I set everything up correctly, the page table inspection in bochs tells me, that I am mapping 32-bit linear addresses to 64-bit physical addresses (I assume so, since the output shows 16 hexadecimal chars for the physical addresses).

However, my kernel is linked at 0xffffffff80200000 (In the linker file from the kernel):

Code: Select all

ENTRY(_entry)

KERNEL_BASE_ADDR = 0xffffffff80200000;

SECTIONS
{
	. = KERNEL_BASE_ADDR;
...
And the elf64 header I parse from the article using a separate loader also says that

Code: Select all

elf64_phdr->p_vaddr
matches the address in the linker file. Everything seems to work, except either the mapping I do for the kernel results in some troubles or bochs seems to show wrong entries in the page table: https://imageshack.com/a/img921/8867/Dlwe8L.png
The result of the far jump to the kernel results in an grayish screen, which seems to be the effect of an interrupt. As this interrupt is most likely resulting from a page fault, the paging mechanism seems to have a bug.

With your help I want to check if my build up is correct the way I did it so far:

Boot -> Grub:
  • - The entry in the grub bootloader starts the separate loader of mine, which is very similar to the one in the tutorial.
    - I'm setting up the GDT (32-bit), IDT(64-bit) and the Paging (with PML4, 4-level paging). -> Setup in this exact order (GDT, IDT, Paging).
    - I'm parsing the elf64 header from the multiboot struct, just as in the tutorial, and retrieve the kernel entry point address, which is 0xffffffff80200000.
    - I enable paging.
    - I setup the GDT for 64-bit and far jump into the kernel entry point (0xffffffff80200000).
After that, the screen becomes grey and the system comes to a halt.
If this build up is correct, then the mistake might be on my side, most likely in the paging mechanism. However, the bochs page table output irritates me a little, since it only shows 32-bit linear addresses, even though I am mapping 64-bit linear addresses (48-bit, since the last 16 bits are a copy of bit 47).

I hope you can give me a hint or tell me if my build up is wrong.

Re: Bochs showing only 32-bit linear addresses for PML4

Posted: Sun May 27, 2018 8:54 pm
by MichaelPetch
There is a user patch a few years ago for BOCHS for the full 64-bit addresses. I tried it previously and it did work although I'm not sure if it works for current releases. https://sourceforge.net/p/bochs/patches/497/#d315

Re: Bochs showing only 32-bit linear addresses for PML4

Posted: Mon May 28, 2018 3:14 am
by CRoemheld
I am using Bochs 2.6.9 and I was building it myself. According to the forum, 2.6.9 should be a fine version number, as the patch was applied there (as far as I understand).

EDIT: Seems like i was wrong, I just checked the source code of my compiled bochs and the patches aren't applied to it. I'm going to check if the patches work.