开发者

How get process information?

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


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.


You probably need to use assembly code to do the context save/restore, unless you have library routines like getcontext/setcontext already implemented.


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());
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜