Task Switching - Linux 0.01
Posted: Sun Jan 13, 2008 3:33 am
I have been trying to get task switching implemented in my OS for quite a while now, despite the immense amount of tutorials I have read.
To try to solve my problem I started to look through the Linux 0.01 source code to see how it was done. I came across a macro called switch_to() that did the actual task switching and noticed that it seemed to copy an undefined value to %dx and then jump to another undefined value.
The macro defines __tmp and then proceeds to use the values undefined, is there some other place in the code that these magically get a useful value inserted into them?
To try to solve my problem I started to look through the Linux 0.01 source code to see how it was done. I came across a macro called switch_to() that did the actual task switching and noticed that it seemed to copy an undefined value to %dx and then jump to another undefined value.
Code: Select all
#define switch_to(n) {\
struct {long a,b;} __tmp; \
__asm__("cmpl %%ecx,_current\n\t" \
"je 1f\n\t" \
"xchgl %%ecx,_current\n\t" \
"movw %%dx,%1\n\t" \
"ljmp %0\n\t" \
"cmpl %%ecx,%2\n\t" \
"jne 1f\n\t" \
"clts\n" \
"1:" \
::"m" (*&__tmp.a),"m" (*&__tmp.b), \
"m" (last_task_used_math),"d" _TSS(n),"c" ((long) task[n])); \
}