Paging (This is a real problem this time...)

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
elderK

Paging (This is a real problem this time...)

Post by elderK »

Heyyyyy people.

First things first.
My Second Stage bootloader is now coded entirely in C.
It sets up all kinds of things, probes ram to get memory size, etc.
Sets up Paging.

Identity maps 0-1MiB.
Then it aliases 3GiB to 1MiB. (maps up to 5MiB up from 3GiB).

Anywho, Kernel works happily and ive implemented a nice set of handy debugging things, like a little box on the screen that shows you the value of the registers at any time.

Anywho, the problem is - I dont like having to rely on a ... 'early' Page Directory (at 0x9000).

So, I am trying to reinitialize Paging, to use structures from Kernel space. (New PAge dir is at 0xC0006000).

Everything seems to go ok,
Cr3 is loaded with the new Address for the PDIR, All the entries are filled with the correct data, and all the Page descriptors have the right addresses and permissions.

However, After paging has 'reanabled', it just dies.
its like paging stops working altogether, because Bochs tells me its a Physical RAM read error.

(Its trying to read from 3GiB Kernelspace... physical in the VMachine, rather than it being virtual and translated).

Im not sure why, but I remember someone mentioning you having to 'invalidate' the Page Directory cache? or something like that?

Any help would be super, ultra MEGA appreciated.
Thanks!

~zeii.
User avatar
Kevin McGuire
Member
Member
Posts: 843
Joined: Tue Nov 09, 2004 12:00 am
Location: United States
Contact:

Re:Paging (This is a real problem this time...)

Post by Kevin McGuire »

Did you try dumping the thirty-two bit value stored for the address of the EIP just after setting cr0 or cr3 in the appropriate page table to ensure you are not trying to map non-existant memory.

If I am not mistaken running the debugger and stepping through the cr0 or cr3 change should give you the error _and_ allow you to display the current value of EIP -- thus using the debugging commands tranverse the page directory and table by hand using the display memory commands to double check the mapped address.

There should be a command in bochs to display a location in physical RAM or virtual RAM?

...<I googled>.. "bochs debugging commands"
...<I found>.. http://www.cs.umd.edu/~hollings/cs412/s02/debugger.html
x /nuf addr Examine memory at linear address addr
xp /nuf addr Examine memory at physical address addr
elderK

Re:Paging (This is a real problem this time...)

Post by elderK »

Alright, this maybe the problem.

The Page Dir has 1024 PDEs.
I have PDEs 0 and 768 plugged and present.

(0-4MiB, 3GiB - +4MiB)

The problem is, The addresses for the 'PDE' Entries themselves are in
virtual addressing.

The PDIR is being filled with Virtual Addresses for its PDEs, the PDEs contain the Mappings. THe mapping are fine, when you look through the
PDEs on Bochs.

However, we can do that because I know where they are being stored in
real phsyical memory.

So basically, before I Set the PDIR , etc, I need to get the *real* Address of the Structures, the Physical Address.

Seem to make sense?
Thats why its giving me a Read RAM error - because its trying to read the PDEs FROM 3GiB, but the PDE Addresses themselve arent meant to be virtual.
Yeah?

~Z
elderK

Re:Paging (This is a real problem this time...)

Post by elderK »

Fixed the bug :)
New paging structures now work.

Kernel Paging is cool now.
:D You can like, just create a page directory and swap straight to it :).

Its neat!

Itll automatically detect if you are running in Virtualized space and translate the Virtual addresses into Physical ones, so the PDE addresses are all physical, and the CR3 has the physical address of the PD :).

Woohooo!

:D Man, Lately ive been doing a lot of rewriting of components, and im getting excited :D Im hitting a little milestone soon! Whooohooo!
Post Reply