Is not having a tss a mistake ?

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
JulienDarc
Member
Member
Posts: 97
Joined: Tue Mar 10, 2015 10:08 am

Is not having a tss a mistake ?

Post by JulienDarc »

Hello,

My current goal is to reduce the code size of my os.

In ring0, is the IOPL always checked too in the TSS?

Which would incur that I cannot do without a TSS, even almost empty, and even if its location in memory causes cache misses (I can locate it elsewhere but..).

Thanks

Julien
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: Is not having a tss a mistake ?

Post by Kevin »

IOPL is part of eflags, so no, it's obviously not checked in the TSS. The I/O bitmap is in the TSS and it's probably not accessed if IOPL already gives sufficient privileges.

However, the Intel manual states cleary that "when operating in protected mode, a TSS and TSS descriptor must be created for at least one task, and the segment selector for the TSS must be loaded into the task register (using the LTR instruction).". So yes, not having a TSS is a mistake.
Developer of tyndur - community OS of Lowlevel (German)
LtG
Member
Member
Posts: 384
Joined: Thu Aug 13, 2015 4:57 pm

Re: Is not having a tss a mistake ?

Post by LtG »

If you plan on using multiple rings you will need at least a single TSS.

If you're currently executing in ring3 and you get an interrupt causing ring3->ring0 transition then the TSS is used to set ring0 SS:ESP. Other than that I'm not sure if you need one. I was thinking of it myself as well, but because of ring3 and interrupts I'm going to need one anyway I decided to just accept it.

I think some time ago I did not set TR to point to a valid TSS and everything worked just fine in ring0, so in that sense it wasn't needed, but I'm not sure if GRUB (or QEMU -kernel) had set it for me, can't remember if I even checked.

Kevin, from which version is that from? Couldn't find the same quote after quickly checking the 1986 version, or anything similar.. Might not have looked hard enough though..
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: Is not having a tss a mistake ?

Post by Kevin »

LtG wrote:I think some time ago I did not set TR to point to a valid TSS and everything worked just fine in ring0, so in that sense it wasn't needed, but I'm not sure if GRUB (or QEMU -kernel) had set it for me, can't remember if I even checked.
I guess it works in practice, but if something in newer processors changes to require a valid TSS in additional places, and you code breaks, you get to keep both pieces and can't blame Intel.
Kevin, from which version is that from? Couldn't find the same quote after quickly checking the 1986 version, or anything similar.. Might not have looked hard enough though..
The copy in which I looked it up is from June 2009. If you don't target specifically a 80386 CPU, but also newer ones, you're probably better off not using ancient documentation.
Developer of tyndur - community OS of Lowlevel (German)
LtG
Member
Member
Posts: 384
Joined: Thu Aug 13, 2015 4:57 pm

Re: Is not having a tss a mistake ?

Post by LtG »

I'm not suggesting not using a TSS since it's practically required (the mentioned interrupts and ring3 for example), was just curios myself if I could avoid it so thought I'd comment..

Btw, isn't all 32-bit x86 supposed to be backwards compatible with 80386, so Intel should not be making any changes that would break code not using TSS..

Also the osdev wiki doesn't mention anything about TSS in the protected mode:
http://wiki.osdev.org/Protected_Mode
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: Is not having a tss a mistake ?

Post by Combuster »

Going without a TSS in ring 0 is safe, as long as you don't explicitly use one.
"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 ]
JulienDarc
Member
Member
Posts: 97
Joined: Tue Mar 10, 2015 10:08 am

Re: Is not having a tss a mistake ?

Post by JulienDarc »

Nice,

Thanks :)
Post Reply