Yet another paging problem

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
sparky
Posts: 19
Joined: Sun Apr 29, 2007 5:48 pm

Yet another paging problem

Post by sparky »

Hi,

I'm having problems when enabling paging in my virtual memory manager.
Below is the contents of the cr and eip registers. my kernel is loaded at 1mb (phys 0x00100000). Is there any way I can find out which instruction was being executed when it tried to access the page at 0x001070a0 that caused the page fault?

Also the following from a tutorial also confuses me:
The current page table needs to identity map the current EIP: when we set the paging bit in CR0, the CPU will still be executing from the same address, so it had better have some valid instructions at wherever it’s executing. This is why it’s good to locate the kernel at whatever address it’s going to end up once paging is enabled.


01130591098i[CPU ] | EIP=001002a0 (001002a0)
01130591098i[CPU ] | CR0=0x80000011 CR1=0 CR2=0x001070a0
01130591098i[CPU ] | CR3=0x0010a000 CR4=0x00000000
01130591098i[CPU ] (instruction unavailable) page not present
01130591098e[CPU ] exception(): 3rd (14) exception with no resolution, shutdown status is 00h, resetting
01130591098i[SYS ] bx_pc_system_c::Reset(SOFTWARE) called
01130591098e[CPU ] CPU_LOOP bx_guard.interrupt_requested=1
01130591098i[CTRL ] asking for next debug command


Any suggestions guys ?
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Post by jnc100 »

Several:

- Bochs debugger
- Disassember
- Break (while(1)) after each line one at a time to see which causes the fault
- As CR2 is not the same as EIP it looks like a data read/write, which might be a statically allocated structure. Consult your linker map.

Regards,
John.
sparky
Posts: 19
Joined: Sun Apr 29, 2007 5:48 pm

Post by sparky »

I've tried using bochs debugger, im kinda new to it tho but using the manual and printing out contents of memory and the like i aint finding anything useful.


I've even disabled my memory manager and replaced it with the basic paging on http://www.osdever.net/tutorials/paging.php but that also page faults as soon as i enable the paging bit.

Anyone else got any ideas or steps to follow to try and work out whats going wrong?
User avatar
Kevin McGuire
Member
Member
Posts: 843
Joined: Tue Nov 09, 2004 12:00 am
Location: United States
Contact:

Post by Kevin McGuire »

Goto you're source code and where you move the value into CR0 to enable paging...

You need to insert the following assembler instructions before the that:
hlt
nop
nop

Then run bochs in debug mode until it appears to stop or gives a message the processor was halted. Once you reach this point press control+c on the keyboard. Then use the command s to single step through the instructions that modify the CR0 register which enables paging.

What you want to see is if: Right when you enable paging BOCHS throws a exception about a page fault on the next instruction.

Also make sure you have mapped the kernel into virtual memory before turning paging on.
Post Reply