Need help on how to task switch with TSS
-
- Member
- Posts: 70
- Joined: Tue Jul 14, 2020 4:01 am
- Libera.chat IRC: clementttttttttt
Need help on how to task switch with TSS
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
Hi Clementt..t, did you read my thread about struggling with the TSS?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.
viewtopic.php?f=1&t=37265
I describe a very simple software task switch mechanism in this thread.
Last edited by bloodline on Mon Oct 12, 2020 10:42 am, edited 1 time in total.
CuriOS: A single address space GUI based operating system built upon a fairly pure Microkernel/Nanokernel. Download latest bootable x86 Disk Image: https://github.com/h5n1xp/CuriOS/blob/main/disk.img.zip
Discord:https://discord.gg/zn2vV2Su
Discord:https://discord.gg/zn2vV2Su
Re: Need help on how to task switch with TSS
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
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.
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
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.