I was wondering about making the most simplest(without any algos) process switching codes and thought of this.
1) Put interrupt(switcher) which will handle the registers into timer (08h) of bios.
2) Store all registers of a new process in memory before loading the program.
3) While switching store the current state of registers and then passing control to the next process.
Now, the problem is, how to get cs:ip before the interrupt(switcher)?
Is this the right way of solving the problem or is there are better ways(I guess there are many, but simple ones)?
Process switching
- nitinjavakid
- Member
- Posts: 65
- Joined: Sat Oct 21, 2006 11:28 am
- Location: Exams over!
- Contact:
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
pretty close:
hook up some timer (or syscall for cooperative multitasking)
then upon switch:
1: store all registers to memory
2: pick the stack of the new task
3: load all registers from memory
4: resume execution
as for cs:ip (and eflags), these are pushed last before the interrupt handler is called - check the intel docs for the exact order. Just check ss:sp+0, ss:sp+2 and ss:sp+4, they should be in there.
As for simplicity, my old task switcher only counts 28 lines of assembly to do just that. (the current one has a few extra lines for debugging and timer purposes - source is on my site if you want a reference. its 32 bit though)
hook up some timer (or syscall for cooperative multitasking)
then upon switch:
1: store all registers to memory
2: pick the stack of the new task
3: load all registers from memory
4: resume execution
as for cs:ip (and eflags), these are pushed last before the interrupt handler is called - check the intel docs for the exact order. Just check ss:sp+0, ss:sp+2 and ss:sp+4, they should be in there.
As for simplicity, my old task switcher only counts 28 lines of assembly to do just that. (the current one has a few extra lines for debugging and timer purposes - source is on my site if you want a reference. its 32 bit though)
- nitinjavakid
- Member
- Posts: 65
- Joined: Sat Oct 21, 2006 11:28 am
- Location: Exams over!
- Contact: