page fault when executing "rep insw"

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
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

page fault when executing "rep insw"

Post 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
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: page fault when executing "rep insw"

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: page fault when executing "rep insw"

Post 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.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Re: page fault when executing "rep insw"

Post 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.
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: page fault when executing "rep insw"

Post 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)
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Re: page fault when executing "rep insw"

Post by blackoil »

Problem solved, it's due to my pageallocator double xor the page bitmap record.
Post Reply