Tasks TSS and MP
- Coconut9
- Member
- Posts: 51
- Joined: Sat May 20, 2017 1:25 am
- Location: PCI bus: 3, slot: 9, function: 5
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?
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!
Linux user: Cool, more free stuff!
Mac user: Ooh I have to pay!
Windows user: Ah not again!
Re: Tasks TSS and MP
Hi,
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
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.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?
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.
- Coconut9
- Member
- Posts: 51
- Joined: Sat May 20, 2017 1:25 am
- Location: PCI bus: 3, slot: 9, function: 5
Re: Tasks TSS and MP
Is TSS size fixed or I can use the first 0xC0 bytes only?Brendan wrote:Hi,
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.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?
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
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!
Linux user: Cool, more free stuff!
Mac user: Ooh I have to pay!
Windows user: Ah not again!
-
- Member
- Posts: 223
- Joined: Thu Jul 05, 2007 8:58 am
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.