Process switching

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
nitinjavakid
Member
Member
Posts: 65
Joined: Sat Oct 21, 2006 11:28 am
Location: Exams over!
Contact:

Process switching

Post 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)?
User avatar
Combuster
Member
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:

Post 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)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
nitinjavakid
Member
Member
Posts: 65
Joined: Sat Oct 21, 2006 11:28 am
Location: Exams over!
Contact:

Post by nitinjavakid »

Great! Now I am starting to understand the importance of reading Intel manuals. Thanks man!
Regards


Nitin
Post Reply