Task Switching - Linux 0.01

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
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Task Switching - Linux 0.01

Post by thepowersgang »

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.

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])); \
}
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?
cyr1x
Member
Member
Posts: 207
Joined: Tue Aug 21, 2007 1:41 am
Location: Germany

Post by cyr1x »

No,
in the Gnu(AT&T) syntax the format is like this

Code: Select all

mnemonic	source, destination
that means that the value from dx is copied into the var.
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Post by thepowersgang »

Actually I noticed that part about 5 mins later, but I still don't understand why it would copy %dx to %1 (__tmp.b) and then long jump to %0 (__tmp.a)
cyr1x
Member
Member
Posts: 207
Joined: Tue Aug 21, 2007 1:41 am
Location: Germany

Post by cyr1x »

I'm not sure on this, but I think it is in the reverse order(e.g %0 = task, %1 = TSS, ...)
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Post by thepowersgang »

Then why not use %ecx

the 'm' code (i think) means that the data is placed in a temporary memory address instead of a register. the 'd' and 'c' before the tss and task mean to put the value passed into %edx and %ecx respectively.
Post Reply