This combination of stack operations seems wrong to me.mrjbom wrote:Code: Select all
pushad push eax popad
page fault processing
Re: page fault processing
Re: page fault processing
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
Most likely, I misunderstood what @nexos meant.
-
- Member
- Posts: 5885
- Joined: Mon Mar 25, 2013 7:01 pm
Re: page fault processing
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...
The System V ABI requires you to pass parameters on the stack, but GCC supports other calling conventions, including ones that pass some parameters in registers.
You should remove CLI/STI. If you want interrupts disabled, change the IDT to use an interrupt gate.
Re: page fault processing
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
Re: page fault processing
OK, 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
The parameter is passed successfully and everything seems fine...
But the problem is that the function loops, as if an exception is constantly triggered, and the processor is not reset, although I clear the stack of the error code.
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
-
- Member
- Posts: 5885
- Joined: Mon Mar 25, 2013 7:01 pm
Re: page fault processing
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".
You are still not passing the error code to your C function. Try "push [esp+32]" instead of "push eax".
Re: page fault processing
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".
Everything really works as it should.
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