Page 1 of 1

Process switching

Posted: Mon Nov 06, 2006 2:12 pm
by nitinjavakid
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. :shock:

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)?

Posted: Mon Nov 06, 2006 3:31 pm
by Combuster
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)

Posted: Mon Nov 06, 2006 10:13 pm
by nitinjavakid
Great! Now I am starting to understand the importance of reading Intel manuals. Thanks man!