My TSS can't relax at all

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
Js2xxx
Member
Member
Posts: 48
Joined: Sat Dec 31, 2016 1:43 am
Libera.chat IRC: wrgq
Location: China

My TSS can't relax at all

Post by Js2xxx »

Well I think it's a very simple question, but how to clear x64 TSS busy bit? I tried to reset the attribute direct to the descriptor, and to load another empty TSS, but the original TSS is still busy.
(By the way, could anybody tell me more about context switching in long mode?)

Code: Select all

TssDesc->AttrLow = TSS | DESC_P; //During context switching
DumpTss();
Attachments
The display of DumpTss()
The display of DumpTss()
捕获.PNG (888 Bytes) Viewed 2934 times
Doing steadfastly, or doing nil.
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: My TSS can't relax at all

Post by Korona »

x86_64 does not support hardware task switching. The 64-bit TSS does not contain a register image (it's figure 7-11 in my copy of the Intel SDM). Use software task switching instead (i.e. save/restore all general-purpse registers and use iret to restore RIP and RFLAGS). AFAICT there is no need to bother with the busy bit (or more than one TSS per processor) in 64-bit mode.
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
User avatar
Js2xxx
Member
Member
Posts: 48
Joined: Sat Dec 31, 2016 1:43 am
Libera.chat IRC: wrgq
Location: China

Re: My TSS can't relax at all

Post by Js2xxx »

Korona wrote: AFAICT there is no need to bother with the busy bit (or more than one TSS per processor) in 64-bit mode.
Yes of course you're right. So I've already made this. However, I created a process queue based on an array, and the enqueue and dequeue operation changes the position of each process, so I've got to change my TSS.RSP0 so it'll point to correct position. (I use stack to save GPR and so on, so the image will be stored in the process structure.)

So how to clear busy bits? Thanks for any advice.
Doing steadfastly, or doing nil.
davidv1992
Member
Member
Posts: 223
Joined: Thu Jul 05, 2007 8:58 am

Re: My TSS can't relax at all

Post by davidv1992 »

The busy flag is used in 32 bit mode to prevent things like recursively entering a task through a task gate when you use hardware task switching.

Although the manual isn't particularly clear on this, the 64 bit busy flag seems to be a leftover from hardware task switching. It seems to serve no particular function anymore. In particular (and this also holds in 32 bit mode), one can allways edit the elements of a TSS, even when it is loaded into the TR.

Do note however that simply changing TSS.RSP0 will not change your current stack pointer, it will only change the value that the processor will load when switching from ring 1, 2 or 3 to ring 0.
Post Reply