Reputation: 89
In my Operating System class we are programming in C and we overrode the Timer Interrupt, after that from the timer interrupt we wrote we have to handle 4 processes, but we need to get the context of the process, like the instruction pointer, data segment, etc. How can we get that information from c? if not, do we need to use also ASM inside the C code? thanks :D
I'm using virtual box with Windows XP 32 bits, and using the DOS 16 bit virtual machine
Upvotes: 1
Views: 1116
Reputation: 93468
I believe this technique won't work for EIP and EFLAGS since they can only be accessed through special instructions.
I don't know the equivalent of movl for DOS 16 bit, but I think you get the idea.
unsigned long get_ebp()
{
__asm__("movl %ebp, %eax");
}
int main()
{
printf("ebp: 0x%p\n", get_ebp());
}
Upvotes: 0
Reputation: 490348
Yes, you pretty much need at least a little bit of assembly language. A typical starting point is pusha
. That preserves the main general purpose registers so you have someplace to work without destroying anything critical. If you're supporting the FPU, you'll probably want to look at fsave
. You restore those with popa
and frestore
respectively.
Upvotes: 2
Reputation: 30989
You probably need to use assembly code to do the context save/restore, unless you have library routines like getcontext
/setcontext
already implemented.
Upvotes: 0