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
huxuelei
Member
Member
Posts: 35
Joined: Tue May 27, 2008 8:32 am

Paging problem.

Post 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.
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: Paging problem.

Post 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.
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Paging problem.

Post 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.
huxuelei
Member
Member
Posts: 35
Joined: Tue May 27, 2008 8:32 am

Re: Paging problem.

Post by huxuelei »

00066367781e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
Can anyone tell me what's this mean?
blackoil
Member
Member
Posts: 148
Joined: Mon Feb 12, 2007 4:45 am

Re: Paging problem.

Post by blackoil »

hi, make sure your kernel pages cover all current kernel memory, including the page fault exception itself, RTC, keyboard.
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: Paging problem.

Post 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.
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
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: Paging problem.

Post 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.
"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 ]
Post Reply