Hello, right now I'm creating software multitasking.
I wonder how can I save IP of process???
Thanks
Software multitasking: IP saving
Re:Software multitasking: IP saving
make a struc of a process descriptor which holds all the registers, including ip, and the address of the stack. on task switch, make the kernel save the contents of the old task load the contents of the new process's descriptor.
Re:Software multitasking: IP saving
You can also code the context switching into your interrupt handler. This way, the ip is already on the stack, and you can push all of the other registers you want to save (all is probably a good idea ), and then switch the stack the that of the proces you want to switch to. Then, when the handler iret's, it automatically jumps into the process at the correct ip. Then to switch back, you do the same thing, but switch back to the other stack (which has the IP of the first process still saved on it), and then the iret returns to the first process.
Re:Software multitasking: IP saving
Yes, that I know,
but when, say, my IRQ0 works on 100Hz, and I put there dispatcher, and say, we have a running process, when the IRQ0 triggers, does it call intstruction?
If yes, then call instruction before jumping to function that refered, according to Help PC, saves IP and CS onto stack. But in what order it saves (where is IP in SS:SP), or IP is first or CS or something else ?
P.S. to unknown user: without using stuct, you can simplier put all regs and other stuff onto process' stack
but when, say, my IRQ0 works on 100Hz, and I put there dispatcher, and say, we have a running process, when the IRQ0 triggers, does it call intstruction?
If yes, then call instruction before jumping to function that refered, according to Help PC, saves IP and CS onto stack. But in what order it saves (where is IP in SS:SP), or IP is first or CS or something else ?
P.S. to unknown user: without using stuct, you can simplier put all regs and other stuff onto process' stack
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Software multitasking: IP saving
the order for the "call" instruction is documented in any good intel manual: IP is always pushed last.
You can get the current IP value with the following code:
Anyway, why even bothering ? just save the stack pointer to your thread structure ! when you'll come back to that thread, you'll restore the stack of that thread and perform a "return" instruction, which will send you back to the point from which you called "stack_switch"
You can get the current IP value with the following code:
Code: Select all
call .here
.here : pop eax