Strange page fault

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
solarius
Posts: 20
Joined: Mon Sep 27, 2010 4:45 am

Strange page fault

Post by solarius »

Hello everybody,

We (me and a friend) are trying to setup virtual memory into our kernel. We already have a VESA drivers which provides us a framebuffer to manage the screen. The VESA configuration functions give us the address 0xe0000000 to write to the screen so we mapped it to 0xe0000000 in linear adresses.

If I try to access this address with a simple pointer, like this :

Code: Select all

char *framebuffer = (char*)0xe0000000;
for (int i = 0; i < 100000; i++) {
*framebuffer++ = 0xFF;
}
it writes white pixels on the screen. But if I use a memcpy to copy come datas here, it does a page fault. Besides, before our work, we already had a simple paging system (just a identity mapping) where we mapped VESA memory like this and worked well.
Bochs just tell me that the Page Table Entry is not present, but I don't understand why, because I write in the VESA buffer before the memcpy ...

Here is the Bochs trace,
Here I write with the pointer, everything is okay :

Code: Select all

00199747348d[CPU0 ] page walk for address 0x00000000c0540a38
00199747360d[CPU0 ] page walk for address 0x00000000e0000000
00199763744d[CPU0 ] page walk for address 0x00000000e0001000
00199780128d[CPU0 ] page walk for address 0x00000000e0002000
00199796512d[CPU0 ] page walk for address 0x00000000e0003000
00199812896d[CPU0 ] page walk for address 0x00000000e0004000
00199829280d[CPU0 ] page walk for address 0x00000000e0005000
00199845664d[CPU0 ] page walk for address 0x00000000e0006000
Just after I use a memcpy and ... :

Code: Select all

00201158883d[CPU0 ] page walk for address 0x00000000e0000000
00201158883d[CPU0 ] PTE: entry not present
00201158883d[CPU0 ] page fault for address 00000000e0000000 @ 00000000c011f8ce
00201158883d[CPU0 ] exception(0x0e): error_code=0002
00201158883d[CPU0 ] interrupt(): vector = 0e, TYPE = 3, EXT = 1
00201158883d[CPU0 ] page walk for address 0x00000000c05518f0
00201158883e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x0e)
00201158883d[CPU0 ] exception(0x0d): error_code=0072
00201158883d[CPU0 ] exception(0x08): error_code=0000
00201158883d[CPU0 ] interrupt(): vector = 08, TYPE = 3, EXT = 1
00201158883e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x08)
00201158883d[CPU0 ] exception(0x0d): error_code=0042
00201158883i[CPU0 ] CPU is in protected mode (active)
00201158883i[CPU0 ] CS.d_b = 32 bit
00201158883i[CPU0 ] SS.d_b = 32 bit
00201158883i[CPU0 ] EFER   = 0x00000000
00201158883i[CPU0 ] | RAX=00000000e0000000  RBX=0000000000000000
00201158883i[CPU0 ] | RCX=0000000000003c00  RDX=00000000c0552310
00201158883i[CPU0 ] | RSP=00000000c05409bc  RBP=00000000c05409d8
00201158883i[CPU0 ] | RSI=00000000c0552310  RDI=00000000e0000000
00201158883i[CPU0 ] |  R8=0000000000000000   R9=0000000000000000
00201158883i[CPU0 ] | R10=0000000000000000  R11=0000000000000000
00201158883i[CPU0 ] | R12=0000000000000000  R13=0000000000000000
00201158883i[CPU0 ] | R14=0000000000000000  R15=0000000000000000
00201158883i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf sf ZF af PF cf
00201158883i[CPU0 ] | SEG selector     base    limit G D
00201158883i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00201158883i[CPU0 ] |  CS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00201158883i[CPU0 ] |  DS:0018( 0003| 0|  0) 00000000 ffffffff 1 1
00201158883i[CPU0 ] |  SS:0018( 0003| 0|  0) 00000000 ffffffff 1 1
00201158883i[CPU0 ] |  ES:0018( 0003| 0|  0) 00000000 ffffffff 1 1
00201158883i[CPU0 ] |  FS:0000( 0000| 0|  0) 00000000 00000000 0 0
00201158883i[CPU0 ] |  GS:0000( 0000| 0|  0) 00000000 00000000 0 0
00201158883i[CPU0 ] |  MSR_FS_BASE:0000000000000000
00201158883i[CPU0 ] |  MSR_GS_BASE:0000000000000000
00201158883i[CPU0 ] | RIP=00000000c011f8cc (00000000c011f8cc)
00201158883i[CPU0 ] | CR0=0xe0000011 CR2=0x00000000e0000000
00201158883i[CPU0 ] | CR3=0x00101000 CR4=0x00000000
(0).[201158883] [0x000000000011f8cc] 0010:00000000c011f8cc (unk. ctxt): rep movsd dword ptr es:[edi], dword ptr ds:[esi] ; f3a5
00201158883e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
So if you have any idea on what I miss ... Thank you ^^"

Edit: I correct the mistake ~~
Last edited by solarius on Fri Dec 17, 2010 5:51 am, edited 2 times in total.
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: Strange page fault

Post by Combuster »

Now, what's the purpose of

Code: Select all

char *framebuffer = (char*)framebuffer;
:?
"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 ]
solarius
Posts: 20
Joined: Mon Sep 27, 2010 4:45 am

Re: Strange page fault

Post by solarius »

Combuster wrote:Now, what's the purpose of

Code: Select all

char *framebuffer = (char*)framebuffer;
:?
Sorry, it's correct now !
solarius
Posts: 20
Joined: Mon Sep 27, 2010 4:45 am

Re: Strange page fault

Post by solarius »

You didn't map enough memory or overwrote your pagetables.
Apparently not. I mean, I'm able write 0xFF at the beginning of 0xe0000000 on 100000 bytes without any exception and a successfull "pagewalk" and with the memcpy, the CPU is not able to resolve 0xe0000000. Plus info "tab gave" me the good mapping:
0xe0000000-0xe03C0000 -> 0xe0000000-0xe03C0000
solarius
Posts: 20
Joined: Mon Sep 27, 2010 4:45 am

Re: Strange page fault

Post by solarius »

solarius wrote:
You didn't map enough memory or overwrote your pagetables.
Apparently not. I mean, I'm able write 0xFF at the beginning of 0xe0000000 on 100000 bytes without any exception and a successfull "pagewalk" and with the memcpy, the CPU is not able to resolve 0xe0000000. Plus info "tab gave" me the good mapping:
0xe0000000-0xe03C0000 -> 0xe0000000-0xe03C0000
[Up] Nobody can help me ? If someone wants more details I can put some code or some traces.
solarius
Posts: 20
Joined: Mon Sep 27, 2010 4:45 am

Re: Strange page fault

Post by solarius »

Ok, I found the problem. Just for information I have a memory allocator which use a piece of memory that my new paging system is using too. So it creates mistakes in the paging functions ... I'll just need to correct the allocator.
Post Reply