TSS based task 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
proxy

TSS based task switching

Post by proxy »

ok, i've been using the setjmp/longjmp technique for task switching and it works great. I would like to switch to TSS as this offers more protection checks upon switch and all those goodies.

my "plan" is to have 2 TSS in the GDT (last and current). also each thread object will have a TSS to store it's individual state.

As far as i understand, when i want to switch, i should copy the contents of the next threads, TSS into current and do a ljmp to that TSS's selector, this will automatically switch tasks and put the last tasks state into last TSS entry.

first of all, is this correct so far? also when should i copy the last TSS to the last Thread's TSS? should it be in the code directly following the ljmp (i realize this will be running in the context of a different task), is that the best time, or is there a less error prone time?

thanks

proxy
Ozguxxx

Re:TSS based task switching

Post by Ozguxxx »

well, I think there is a little mistake, I mean intel manual says:
The 80386 switches execution to another task in any of four cases:
1) The current task executes a JMP or CALL that refers to a TSS descriptor.
2) The current task executes a JMP or CALL that refers to a task gate.
3) An interrupt or exception vectors to a task gate in the IDT.
4) The current task executes an IRET when the NT flag is set.
So in fact you have to make a jump to tss descriptor so tss does not have to be in gdt, you can put it anywhere in memory, but it should not cross a page boundary... Well, I think 2 tss approach should work, but I say give it a try and check its performance. Good luck.
mystran

Re:TSS based task switching

Post by mystran »

Ozgunh82 wrote: So in fact you have to make a jump to tss descriptor so tss does not have to be in gdt, you can put it anywhere in memory, but it should not cross a page boundary... Well, I think 2 tss approach should work, but I say give it a try and check its performance. Good luck.
Well, you put TSS descriptor into GDT, and you put the actual TSS somewhere in the memory, and make sure your descriptor points to the TSS structure (among other this ofcourse).

I think you could just modify the descriptor to point to some other TSS on the fly if you wanted. Probably not a good idea to use a 2 TSS, but 2 TSS descriptors maybe. No idea if it actually works though.

From reading the Intel manuals, it's pretty easy to get the impression that Intel itself now thinks that software task-switching is better suited for modern general-purpose multi-tasking. The whole TSS model is kinda weirdly structured anyway, if you just want to do two protection levels.
Ozguxxx

Re:TSS based task switching

Post by Ozguxxx »

Well, in fact a tss per task and one descriptor per all tasks in one priviledge is enough, currently I am doing in that way.
Post Reply