Page 1 of 1
page fault when executing "rep insw"
Posted: Wed Jun 03, 2009 8:06 am
by blackoil
HI,
I mapped 19 pages in user space, then call ReadFile -> ReadCluster -> ReadSector,
then I got page fault, when accessing the 2nd page in ReadSector.
Code: Select all
cld
mov ecx,512/2
mov edi,0
mov dx,ATA_Port_Primary_Data
rep insw
Then I use lodsb instead, no page fault though
Code: Select all
cld
mov ecx,4096*19
mov esi,0
rep lodsb
Re: page fault when executing "rep insw"
Posted: Wed Jun 03, 2009 8:10 am
by Brendan
Hi,
blackoil wrote:Then I use lodsb instead, no page fault though
Maybe the page is read-only? The error code from the page fault (pushed on the page fault handler's stack by the CPU) should tell you the cause...
Cheers,
Brendan
Re: page fault when executing "rep insw"
Posted: Wed Jun 03, 2009 8:14 am
by thepowersgang
Ok, first is the code snippet what you are actually using to read the data? Because it seems that you are reading the data to address 0, which is usually not what you want.
Second check the address that the page fault occurs at and check that you have mapped it in.
Afik, the instruction LODSB reads a byte from memory into eax, so it is probebly not what you want to do for port reads.
Re: page fault when executing "rep insw"
Posted: Wed Jun 03, 2009 8:45 am
by blackoil
I am trying to load my app for run test,
kernel runs at 0x80000000+ space,
app runs at 0x00000000-0x7fffffff space,
kernel allocates pages with present|user|writable flag on, then ReadFile read bytes from disk to vaddr 0 (app entry point is 0).
And I use FAT12, 8 sectors per cluster, it is 4096 bytes per cluster.
if some "rep insw" iteratons trashed the pagedir / pagetable, that will be the cause.
Re: page fault when executing "rep insw"
Posted: Wed Jun 03, 2009 9:34 pm
by thepowersgang
I suggest using the Bochs Debugger and breaking the program at the "rep insw" and doing a page table dump (type 'info tab' at the bochs prompt) then stepping through the code ('s') until you reach the page fault. Then check if this address is actually mapped into your address space.
If you can't figure out the error then please give us the address the error occured at, the paging dump, a register dump ('r') and the exact source code that causes the error. (i.e. an unedited snippet)
Re: page fault when executing "rep insw"
Posted: Sat Jun 06, 2009 12:06 am
by blackoil
Problem solved, it's due to my pageallocator double xor the page bitmap record.