Page 1 of 1

Tasks TSS and MP

Posted: Wed Sep 20, 2017 10:31 pm
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?

Re: Tasks TSS and MP

Posted: Wed Sep 20, 2017 11:42 pm
by iansjack

Re: Tasks TSS and MP

Posted: Thu Sep 21, 2017 3:44 am
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

Re: Tasks TSS and MP

Posted: Thu Sep 21, 2017 7:32 am
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?

Re: Tasks TSS and MP

Posted: Thu Sep 21, 2017 7:47 am
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.