Page 1 of 1

Paging problem.

Posted: Wed Jul 30, 2008 7:38 am
by huxuelei
hi, i am writting the code to enable the paging in my small kernel.
i use the follow code:

Code: Select all

		asm volatile("movl %0, %%cr3\n\t"
					 "movl %%cr0, %%eax\n\t"
					 "or $0x80000000, %%eax\n\t"
					 "movl %%eax, %%cr0\n\t"
					 ::"r"(pageDirectory));
After executed these codes, some kind of exception happend.I got some information from bochs's log file:
00066367781i[CPU0 ] | RAX=00000000 80000011 RBX=0000000000100000
00066367781i[CPU0 ] | RCX=00000000000b8000 RDX=00000000746f6fd6
00066367781i[CPU0 ] | RSP=0000000000067e38 RBP=0000000000067e38
00066367781i[CPU0 ] | RSI=0000000000000000 RDI=0000000000000001
00066367781i[CPU0 ] | R8=0000000000000000 R9=0000000000000000
00066367781i[CPU0 ] | R10=0000000000000000 R11=0000000000000000
00066367781i[CPU0 ] | R12=0000000000000000 R13=0000000000000000
00066367781i[CPU0 ] | R14=0000000000000000 R15=0000000000000000
00066367781i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf SF zf af PF cf
00066367781i[CPU0 ] | SEG selector base limit G D
00066367781i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00066367781i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 000fffff 1 1
00066367781i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00066367781i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00066367781i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 000fffff 1 1
00066367781i[CPU0 ] | FS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00066367781i[CPU0 ] | GS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00066367781i[CPU0 ] | MSR_FS_BASE:0000000000000000
00066367781i[CPU0 ] | MSR_GS_BASE:0000000000000000
00066367781i[CPU0 ] | RIP=00000000001042c0 (00000000001042c0)
00066367781i[CPU0 ] | CR0=0x80000011 CR1=0x0 CR2=0x0000000080000011
00066367781i[CPU0 ] | CR3=0x00200000 CR4=0x00000000
00066367781i[CPU0 ] >> add byte ptr ds:[eax], al : 0000
00066367781e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting

I do not know how to solve this problem.Please give me little help.

Re: Paging problem.

Posted: Wed Jul 30, 2008 8:19 am
by Korona
1.) Your inline assembly statement is not correct as you don't tell gcc that your code trashes eax. Add eax to the clobbered registers list of the assembly statement.
2.) It seems that the page that contains your assembly statement is not identity-mapped. I guess that another physical page that contains zeros is mapped to this location. 0x00 0x00 is the opcode for the add byte [eax], al instruction. Your eax register contains the value 0x80000011. Bochs tries to execute that instruction and tries to read from memory address 0x80000011. Because there is no paged mapped to this address the instruction causes a page fault. Bochs tries to invoke the page fault handler but there is no IDT or the page fault handler is not setup correctly so a general protection fault & a triple fault is generated. Make sure that you identity map the page that contains your inline assembly code.

Re: Paging problem.

Posted: Wed Jul 30, 2008 8:40 am
by JamesM
Korona wrote:1.) Your inline assembly statement is not correct as you don't tell gcc that your code trashes eax. Add eax to the clobbered registers list of the assembly statement.
AIUI gcc is intelligent enough to know that any registers explicitly mentioned in the inline assembly statement are clobbered - the clobber list is for "side-effect" registers that don't get mentioned by name in the asm but are still killed.

Re: Paging problem.

Posted: Wed Jul 30, 2008 10:11 pm
by huxuelei
00066367781e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
Can anyone tell me what's this mean?

Re: Paging problem.

Posted: Thu Jul 31, 2008 2:31 am
by blackoil
hi, make sure your kernel pages cover all current kernel memory, including the page fault exception itself, RTC, keyboard.

Re: Paging problem.

Posted: Thu Jul 31, 2008 2:46 am
by Korona
huxuelei wrote:
00066367781e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
Can anyone tell me what's this mean?
That means that the processor tried to process two exceptions but there were no interrupts handlers for the exceptions. A third exception is fired which makes the processor reboot.

Re: Paging problem.

Posted: Thu Jul 31, 2008 2:51 am
by Combuster
you get a pagefault when enabling paging. Given the code, you sent execution into uninitialized memory (00 00 00 00 00 00 00 00 etc)

Make sure as said that your kernel is mapped fully and that the executing code is identity mapped.