Tasks TSS and MP

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
Coconut9
Member
Member
Posts: 51
Joined: Sat May 20, 2017 1:25 am
Location: PCI bus: 3, slot: 9, function: 5

Tasks TSS and MP

Post by Coconut9 »

I have already started all the processors. As I understand I need to load different TSS to every processor. But what exactly the TSS is doing? Should I need to use one for every process/thread?
How people react when a new update of your OS is coming:
Linux user: Cool, more free stuff!
Mac user: Ooh I have to pay!
Windows user: Ah not again!
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Tasks TSS and MP

Post by iansjack »

User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Tasks TSS and MP

Post by Brendan »

Hi,
ARISTOS wrote:I have already started all the processors. As I understand I need to load different TSS to every processor. But what exactly the TSS is doing? Should I need to use one for every process/thread?
When a CPU switches from CPL=3 to CPL=0 (from user-space to kernel space) the CPU normally loads the "hopefully guaranteed safe to use" kernel stack from the TSS to make sure that malicious user-space code can't do something like setting its stack to an address in kernel space and tricking the kernel into trashing itself. Note: The SYSCALL instruction is a special case where the CPU does not switch to a safe stack.

At a minimum, each CPU will need to use different RAM for its kernel stack (otherwise you get problems when 2 or more CPUs are running kernel code at the same time). Beyond that; it depends on other design decisions (if the kernel uses hardware multi-tasking or software multi-tasking, if the kernel uses "one kernel stack per task" or "one kernel stack per CPU", if the kernel uses paging to make some of kernel space contain different things for different CPUs).

The typical case is "software multi-tasking, one kernel stack per task, all of kernel space is the same for all CPUs"; and in this case you'd need one TSS per CPU, where you'd set the "SS0:ESP0" fields in each CPU's TSS during boot/kernel initialisation.


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
Coconut9
Member
Member
Posts: 51
Joined: Sat May 20, 2017 1:25 am
Location: PCI bus: 3, slot: 9, function: 5

Re: Tasks TSS and MP

Post by Coconut9 »

Brendan wrote:Hi,
ARISTOS wrote:I have already started all the processors. As I understand I need to load different TSS to every processor. But what exactly the TSS is doing? Should I need to use one for every process/thread?
When a CPU switches from CPL=3 to CPL=0 (from user-space to kernel space) the CPU normally loads the "hopefully guaranteed safe to use" kernel stack from the TSS to make sure that malicious user-space code can't do something like setting its stack to an address in kernel space and tricking the kernel into trashing itself. Note: The SYSCALL instruction is a special case where the CPU does not switch to a safe stack.

At a minimum, each CPU will need to use different RAM for its kernel stack (otherwise you get problems when 2 or more CPUs are running kernel code at the same time). Beyond that; it depends on other design decisions (if the kernel uses hardware multi-tasking or software multi-tasking, if the kernel uses "one kernel stack per task" or "one kernel stack per CPU", if the kernel uses paging to make some of kernel space contain different things for different CPUs).

The typical case is "software multi-tasking, one kernel stack per task, all of kernel space is the same for all CPUs"; and in this case you'd need one TSS per CPU, where you'd set the "SS0:ESP0" fields in each CPU's TSS during boot/kernel initialisation.


Cheers,

Brendan
Is TSS size fixed or I can use the first 0xC0 bytes only?
How people react when a new update of your OS is coming:
Linux user: Cool, more free stuff!
Mac user: Ooh I have to pay!
Windows user: Ah not again!
davidv1992
Member
Member
Posts: 223
Joined: Thu Jul 05, 2007 8:58 am

Re: Tasks TSS and MP

Post by davidv1992 »

Honestly, those questions are best answered by the intel processor manuals. They can be found here. Beyond that, if you want to get anywhere with making an os, being able to do your own research is critical. Learn to use google, and read and understand what you find (in detail, looking up further details if needed). If you then find that you have a specific question that you cant find an answer to, it is okay to ask. But show in your questions that you made an effort to do your own research.
Post Reply