Page 1 of 1
My TSS can't relax at all
Posted: Sat Apr 22, 2017 2:40 am
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();
Re: My TSS can't relax at all
Posted: Sat Apr 22, 2017 3:21 am
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.
Re: My TSS can't relax at all
Posted: Sat Apr 22, 2017 4:44 am
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.
Re: My TSS can't relax at all
Posted: Sat Apr 22, 2017 8:55 am
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.