Need help on how to task switch with TSS

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
clementttttttttt
Member
Member
Posts: 70
Joined: Tue Jul 14, 2020 4:01 am
Libera.chat IRC: clementttttttttt

Need help on how to task switch with TSS

Post 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.
User avatar
bloodline
Member
Member
Posts: 264
Joined: Tue Sep 15, 2020 8:07 am
Location: London, UK

Re: Need help on how to task switch with TSS

Post 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.
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
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: Need help on how to task switch with TSS

Post 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.
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
rdos
Member
Member
Posts: 3297
Joined: Wed Oct 01, 2008 1:55 pm

Re: Need help on how to task switch with TSS

Post 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.
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: Need help on how to task switch with TSS

Post 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.
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
Post Reply