Bochs 64-Bit Paging

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
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Bochs 64-Bit Paging

Post by thepowersgang »

I'm starting on a 64-bit version of my OS and have succeeded in getting the 64-bit code executed but for some reason, even though all the paging structures are correct and in place, bochs only allows access to a 32-bit virtual address space. I've read through the Intel manuals and I presume that the AMD CPU uses the same structure in 64-bit mode so I am at a loss as to why it doesn't work.

When I execute "info tab" in the bochs debugging console while executing the 64-bit code I only get four entries: (these all point to the same range because I did that for to try and trace this bug/fault)

Code: Select all

0x00000000-0x003fffff -> 0x00000000-0x003fffff
0x40000000-0x403fffff -> 0x00000000-0x003fffff
0x80000000-0x803fffff -> 0x00000000-0x003fffff
0xc0000000-0xc03fffff -> 0x00000000-0x003fffff
Here is the NASM code for my paging structures:

Code: Select all

...
ALIGN 0x1000
_gpInitial_PML4:	; Page Map Level 4
	dq	_gpInitial_PDP + 3	; Identity Map Low 4Mb
	times 510 dq 0
	dq	_gpInitial_PDP + 3	; Also Map to 0xFFFF8000 00000000

_gpInitial_PDP:		; Page Directory Pointer Table
	times 512 dq _gpInitial_PD + 3
;	times 510 dq 0
;	dq _gpInitial_PD + 3

_gpInitial_PD:		; Page Directory
	dq _gpInitial_PT1 + 3
	dq _gpInitial_PT2 + 3
	times 510 dq 0

_gpInitial_PT1:		; Page Table 1
	%assign i 0
	%rep 512
	dq	i*4096+3
	%assign i i+1
	%endrep

_gpInitial_PT2:		; Page Table 2
	%assign i 512
	%rep 512
	dq	i*4096+3
	%assign i i+1
	%endrep
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: Bochs 64-Bit Paging

Post by JohnnyTheDon »

It does work with full 64-bit virtual address space. My kernel loads itself at 0xFFFF800000000000. Info tab is buggy and doesn't show anything above 4GB, but the area is still being mapped.
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: Bochs 64-Bit Paging

Post by JohnnyTheDon »

In addition...

Code: Select all

_gpInitial_PML4:   ; Page Map Level 4
   dq   _gpInitial_PDP + 3   ; Identity Map Low 4Mb
   times 510 dq 0
   dq   _gpInitial_PDP + 3   ; Also Map to 0xFFFF8000 00000000
Doesn't map at 0xFFFF800000000000. Change times 510 dq 0 to times 255 dq 0 and add times 255 dq 0 at the end of the PML4.
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: Bochs 64-Bit Paging

Post by thepowersgang »

Thank you very much!!!!
#-o #-o #-o

I cannot believe I missed that.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Post Reply