OSDev.org
https://forum.osdev.org/

Tasks TSS and MP
https://forum.osdev.org/viewtopic.php?f=1&t=32433
Page 1 of 1

Author:  Coconut9 [ Wed Sep 20, 2017 10:31 pm ]
Post subject:  Tasks TSS and MP

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?

Author:  iansjack [ Wed Sep 20, 2017 11:42 pm ]
Post subject:  Re: Tasks TSS and MP

http://wiki.osdev.org/Task_State_Segment

Author:  Brendan [ Thu Sep 21, 2017 3:44 am ]
Post subject:  Re: Tasks TSS and MP

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

Author:  Coconut9 [ Thu Sep 21, 2017 7:32 am ]
Post subject:  Re: Tasks TSS and MP

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?

Author:  davidv1992 [ Thu Sep 21, 2017 7:47 am ]
Post subject:  Re: Tasks TSS and MP

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.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/