Activating paging corrupts stack

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.
User avatar
yemista
Member
Member
Posts: 299
Joined: Fri Dec 26, 2008 12:31 pm
Location: Boston
Contact:

Re: Activating paging corrupts stack

Post by yemista »

show a register dump right before it fails, and right after it fails. Something to note though is, since I do not know how you coded the paging routine, does it fail immediatley after cr0 is loaded, or does it fail at the ret instruction? If it does not fail after cr0 is loaded, then paging should be working right and its probably a stack issue. show a register dump, gdt, and segment and control registers
computafreak
Member
Member
Posts: 76
Joined: Sun Dec 14, 2008 1:53 pm

Re: Activating paging corrupts stack

Post by computafreak »

Code: Select all

Control registers before failure:
CR0: 0x60000011
CR1: Reserved
CR2: can't retrieve
CR3: 0x0
CR4: 0x0

GDT before failure:
Index: 0, Selector: 0x0000, Base address: 0x0, Size: 0x0, DPL: 0x0
Index: 1, Selector: 0x0008, Base address: 0x0, Size: 0xFFFFFFFF, DPL: 0
Index: 2, Selector: 0x0010, Base address: 0x0, Size: 0xFFFFFFFF, DPL: 0
Index: 3, Selector: 0x0018, Base address: 0x0, Size: 0xFFFFFFFF, DPL: 3
Index: 4, Selector: 0x0020, Base address: 0x0, Size: 0xFFFFFFFF, DPL: 3
Index: 5, Selector: 0x0028, Base address: 0x10B020, Size: 0x2F, DPL: 0

Segment registers before failure:
CS: 0x0008
DS: 0x0010
ES: 0x0010
SS: 0x0010
FS: 0x0010
GS: 0x0010

Control registers after failure:
CR0: 0xE0000011
CR1: Reserved
CR2: can't retrieve
CR3: 0x110000
CR4: 0x0

GDT after failure:
Same as before failure

Segment registers after failure
Same as before failure
It fails on the RET of the InitialisePaging routine. It doesn't fail after CR0 is written to. I've uploaded both the linker script and the paging code (which is kind of a mash-up of several I found, I'm rather suspicious of it to be honest)
Attachments
Link.ld
Linker script
(581 Bytes) Downloaded 21 times
Paging.cpp
Paging code
(7.28 KiB) Downloaded 28 times
User avatar
yemista
Member
Member
Posts: 299
Joined: Fri Dec 26, 2008 12:31 pm
Location: Boston
Contact:

Re: Activating paging corrupts stack

Post by yemista »

what about a dump of the regular registers before and after the failure? what is esp before you enter that routine, and what is it right before the ret instruction?
computafreak
Member
Member
Posts: 76
Joined: Sun Dec 14, 2008 1:53 pm

Re: Activating paging corrupts stack

Post by computafreak »

Code: Select all

Registers before failure:
EAX: 0xE0000011
EBX: 0x0
ECX: 0x11244C
EDX: 0x0
ESI: 0x2CEEE
EDI: 0x2CEEF
EBP: 0x10AFC0
ESP: 0x10AFA8
EIP: 0x00104DAD
EFlags: 0x6

Registers after failure:
EAX: 0x0
EBX: 0x2CD80
ECX: 0x11244C
EDX: 0x0
ESI: 0x2CEEE
EDI: 0x2CEEF
EBP: 0x10AFF0
ESP: 0x10AFB0
EIP: 0xC
EFlags: 0x10046
However, I seem to have made a small error when stepping through. The problem does not lie immediately after the ret of the InitialisePaging routine. It seems to occur after returning to the Main routine, but as it tries to call a simple method which prints the text "Done!". The memory access doesn't even occur - just calling the method causes a jump to garbage
User avatar
Combuster
Member
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: Activating paging corrupts stack

Post by Combuster »

tried "info tab" anywhere? Where is your code jumping and what bit of physical memory should be there and what bit is actually there ?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
computafreak
Member
Member
Posts: 76
Joined: Sun Dec 14, 2008 1:53 pm

Re: Activating paging corrupts stack

Post by computafreak »

Sorry for the late reply, I've had quite a lot of non-OSDev related stuff to do. Anyway; my debugging has gone a little awry. My error actually occurs immediately after the leave, but before the ret of the InitialisePaging method, before I return to Main. My page tables stay the same throughout (identity mapping from 0x0 to 0x00113FFF)

Another thing I've noticed is that if I set the stack size to 0x10000 bytes, the opcode exception becomes a page fault exception in Bochs and VPC. The amount of memory allocated becomes 0x7000, and the faulting address becomes 0xA0000011
Post Reply