TSS Question

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
System123
Member
Member
Posts: 196
Joined: Mon Jul 07, 2008 1:25 am

TSS Question

Post by System123 »

I have looked through old posts on the forum and have checked the Intel manuals but I can't find the answer to my question. I am setting up my TSS in my GDT but I don't know what the Ganularity and Accessiblity values must be. so far I have this in my GDT

Code: Select all

SetGDTGate(0,0,0,0,0); // nil descriptor
  SetGDTGate(1,0,$FFFFFFFF,$9A,$CF); // Kernel space code
  SetGDTGate(2,0,$FFFFFFFF,$92,$CF); // Kernel space data
  SetGDTGate(3,0,$FFFFFFFF,$FA,$CF); // User space code
  SetGDTGate(4,0,$FFFFFFFF,$F2,$CF); // User space data
  SetGDTGate(5,PtrUInt(TSS),SizeOf(TSS)-1, Access??, Gran??);
Gizmic OS
Currently - Busy with FAT12 driver and VFS
quirck
Member
Member
Posts: 42
Joined: Sun Nov 23, 2008 5:56 am
Location: Russia, Saint-Petersburg

Re: TSS Question

Post by quirck »

Granularity bit stands for multiplying limit by 4K. Here this is not necessary => we have gran = $40 (32-bit, upper bits of limit are zero).
Access byte must include: P = 1 (present), DPL = 0, S = 0 (system), Type = 9 (32-bit available TSS). Thus, access = $89.
System123
Member
Member
Posts: 196
Joined: Mon Jul 07, 2008 1:25 am

Re: TSS Question

Post by System123 »

Thanks.
Gizmic OS
Currently - Busy with FAT12 driver and VFS
System123
Member
Member
Posts: 196
Joined: Mon Jul 07, 2008 1:25 am

Re: TSS Question

Post by System123 »

I now have my tss installed in the gdt. But when i try call ltr the cpu tripple faults. What value should be used with ltr? Like lgdt you use the gdt pointer which contains a limit and a base what does ltr use?
Gizmic OS
Currently - Busy with FAT12 driver and VFS
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: TSS Question

Post by Brendan »

Hi,
System123 wrote:I now have my tss installed in the gdt. But when i try call ltr the cpu tripple faults. What value should be used with ltr? Like lgdt you use the gdt pointer which contains a limit and a base what does ltr use?
LTR is like LLDT - you use an offset in the GDT to refer to the corresponding GDT entry. For example, if the GDT has a NULL entry then the TSS entry (then other entries) you'd do "mov eax,0x0008; ltr ax".


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: TSS Question

Post by Love4Boobies »

Note however that the use of hardware-based task switching is ill advised - it's slower than software and support for TSS's is dropped for 64-bit modes altogether.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
System123
Member
Member
Posts: 196
Joined: Mon Jul 07, 2008 1:25 am

Re: TSS Question

Post by System123 »

Don't you still need 1 TSS for Software based switching? Because that is what I am trying to implement however all the docs I have read say you need a TSS.
Gizmic OS
Currently - Busy with FAT12 driver and VFS
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: TSS Question

Post by pcmattman »

Correct, if you plan to be switching to and from user-mode code.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: TSS Question

Post by Combuster »

Basically, the TSS is used when entering ring 0 from ring 3. If its broken (or absent) when the processor needs it, it will reset instead. During this jump the CPU will grab two entries: SS0 and ESP0, so that's the only part you need to do.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
System123
Member
Member
Posts: 196
Joined: Mon Jul 07, 2008 1:25 am

Re: TSS Question

Post by System123 »

I initialized my TSS with SS0 = 0x10 and Esp0 = the start of the kernel stack. But when i ltr 0x0028 (the gdt segment with it in) i get a general protection fault? Any common reasons?
I think it is due to my access byte being 0x89? As this makes the dpl = 2?
Gizmic OS
Currently - Busy with FAT12 driver and VFS
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: TSS Question

Post by Combuster »

Could you tell us what bochs has to say/complain about it?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
System123
Member
Member
Posts: 196
Joined: Mon Jul 07, 2008 1:25 am

Re: TSS Question

Post by System123 »

Don't worry I found the problem. I had my granularity and access byte mixed up. It works fine now.
Gizmic OS
Currently - Busy with FAT12 driver and VFS
Post Reply