: :
: : Hello everyone,
: :
: : As some of you may know Im developing a 32bit OS. Im currently
: : developing a way to trap kernel errors, and output debug information.
: :
: : The problem: I cant, of course, access EIP.
: :
: : I know there is a way of getting EIPs value, but what?
: :
: : Thanks for any help!
: :
: :
: There are two ways to do it, on is with an interrupt and the other is with a bogus function call. When an interrupt happens the stack looks like the following:
:
: ESP: error code - sometimes on certain cpu exceptions like a page fault
: ESP + 4: eip
: ESP + 8: cs
: ESP + A: eflags
:
: so you could get EIP like this, in an interupt handler of course:
:
: mov eax, [esp] ; or esp + 4 if the processor pushed an error code
:
:
: The other way is with a bogus function call, when a function is called its stack looks like this
:
: ESP: eip
: ESP + 4: parameters to the function, if passed on stack
:
: so you could get eip like this
:
: get_eip:
: mov eax, [esp]
: ret
:
:
I tried the interrupt version, and it seems to work.
Thanks alot!