Re: page fault processing
Posted: Fri Jul 03, 2020 3:51 pm
This combination of stack operations seems wrong to me.mrjbom wrote:Code: Select all
pushad push eax popad
The Place to Start for Operating System Developers
https://forum.osdev.org/
This combination of stack operations seems wrong to me.mrjbom wrote:Code: Select all
pushad push eax popad
I don't quite understand it either.PeterX wrote:This combination of stack operations seems wrong to me.mrjbom wrote:Code: Select all
pushad push eax popad
But the error code is not at ESP+4 here.mrjbom wrote:Code: Select all
pushad ;save error code from stack to eax mov eax, [esp + 4]
Your C function must have parameters if you want to pass values to it. The compiler will clobber EAX because it doesn't know you're trying to pass a value that way.mrjbom wrote:But my С function doesn't have any parameters...
Code: Select all
For example:
pushad
push eax
... (place the call here)
pop eax (or "ADD esp, 4" will do the work, too)
popadOK, now I pass error code through the function parameters. Here is my code, as advised.PeterX wrote:You need a counterpart for every stackoperation.And what nexos is trying to tell you is a so-called "stackframe". It is used for C function calls (and every function using C functions, be it assembler, Pascal or what else).Code: Select all
For example: pushad push eax ... (place the call here) pop eax (or "ADD esp, 4" will do the work, too) popad
Code: Select all
page_fault:
cli
;save all 32bit registers
pushad
;pass error code in function argument
push eax
call page_fault_handler
pop eax
;return all 32bit registers
popad
;delete error code from stack
add esp, 4
sti
iretd
Now I pass the error code as you said.Octocontrabass wrote:Do you update the page tables so the faulting instruction will not cause another page fault? If you make no changes to the page tables, it will just fault again and again.
You are still not passing the error code to your C function. Try "push [esp+32]" instead of "push eax".
Code: Select all
page_fault:
;save all 32bit registers
pushad
;pass error code in function argument
push dword [esp + 32]
call page_fault_handler
pop dword [esp + 32]
;return all 32bit registers
popad
;delete error code from stack
add esp, 4
iretd