Page 1 of 1

Need help on how to task switch with TSS

Posted: Mon Oct 12, 2020 4:15 am
by clementttttttttt
So I'm trying to implement multitasking in my os with TSS, but I can't understand how to use it. There is almost no tutorial on how to switch tasks with it. Also, I understand it's a piece of junk, and it's very slow.

Re: Need help on how to task switch with TSS

Posted: Mon Oct 12, 2020 4:27 am
by bloodline
clementttttttttt wrote:So I'm trying to implement multitasking in my os with TSS, but I can't understand how to use it. There is almost no tutorial on how to switch tasks with it. Also, I understand it's a piece of junk, and it's very slow.
Hi Clementt..t, did you read my thread about struggling with the TSS?

viewtopic.php?f=1&t=37265

I describe a very simple software task switch mechanism in this thread.

Re: Need help on how to task switch with TSS

Posted: Mon Oct 12, 2020 6:32 am
by nexos
Skip TSS based multitasking. The TSS is a pain. On 32 bit, you can look at Brokenthorn for minimal TSS usage examples. 64 bit doesn't even allow you to use it for multitasking You should use software multitasking instead.

Re: Need help on how to task switch with TSS

Posted: Mon Oct 12, 2020 7:11 am
by rdos
TSS task switching is still useful for some exception handlers (double fault), and as the main method if you don't plan to use multiple cores, but otherwise it's not so good.

Switching tasks with TSS is pretty simple. You just do a far jmp with the TSS as the destination selector. The problem is the TSS busy bit that needs to be modified in some contexts.

As for speed, I don't know. The advantage of the TSS method is that it will null invalid selectors when they are loaded from a TSS, but when software task switching is used, loading them will result in exceptions in the scheduler, and handling this properly will increase complexity in exception handlers.

Re: Need help on how to task switch with TSS

Posted: Mon Oct 12, 2020 7:16 am
by nexos
With software multitasking, one could only load registers that had been changed. This would make it faster. Of course one would need to detect this, which could take longer then loading all the registers. I don't use the TSS mainly for portability. x86_64 doesn't provide a full TSS that can do task switches. So it is best to do a software approach.