PatchworkOS
Loading...
Searching...
No Matches
tss_t Struct Reference
Kernel » CPU » TSS

Task State Segment structure. More...

#include <tss.h>

Data Fields

uint32_t reserved1
 
uint64_t rsp0
 Stack pointer to load when switching to ring 0, unused.
 
uint64_t rsp1
 Stack pointer to load when switching to ring 1, unused.
 
uint64_t rsp2
 Stack pointer to load when switching to ring 2, unused.
 
uint64_t reserved2
 
uint64_t ist [7]
 
uint64_t reserved3
 
uint16_t reserved4
 
uint16_t iopb
 Offset to the I/O permission bitmap, we set this to the size of the TSS to disable the bitmap.
 
char todo
 

Detailed Description

Task State Segment structure.

The rsp* members store the stack to use when switching to a higher privilege level, we dont use these.

Instead we have a total of 4 stacks used while in kernel space, 3 per-cpu stacks and 1 per-thread stack. Of course there is also the user stack used while in user space. But that is not relevant to the TSS and instead handled by the system call code.

The per-cpu stacks

The per-cpu stacks are:

  • Exception stack, used while handling exceptions, specified in ist[0].
  • Double fault stack, used while handling double faults, specified in ist[1].
  • Interrupt stack, used while handling all other interrupts, specified in ist[2].

We need three stacks as its possible for an exception to occur during an interrupt, and its possible for a double fault to occur during an exception, therefore we must ensure that in the worst case where each of these occur recursively we have a separate stack for each level.

The per-thread stack

The per-thread stack is called the "kernel stack" and is used while the thread is in kernel space and NOT handling an exception or interrupt. In effect this is used in system calls, boot, inital thread loading and if the thread is a kernel thread it is used all the time. This stack is not handled by the TSS, instead the system call code is responsible for switching to this stack when entering kernel space from user space.

The Interrupt Stack Table

The IST works by having the CPU check the IST index specified in the IDT gate for that interrupt or exception, if it has a non zero IST index it will then load that stack pointer from ist[index - 1] and switch to that stack before calling the interrupt or exception handler. This happens regardless of the current privilege level.

Definition at line 87 of file tss.h.

Field Documentation

◆ iopb

uint16_t tss_t::iopb

Offset to the I/O permission bitmap, we set this to the size of the TSS to disable the bitmap.

Definition at line 97 of file tss.h.

Referenced by tss_init().

◆ ist

uint64_t tss_t::ist[7]

Definition at line 94 of file tss.h.

Referenced by tss_init(), and tss_ist_load().

◆ reserved1

uint32_t tss_t::reserved1

Definition at line 89 of file tss.h.

Referenced by tss_init().

◆ reserved2

uint64_t tss_t::reserved2

Definition at line 93 of file tss.h.

Referenced by tss_init().

◆ reserved3

uint64_t tss_t::reserved3

Definition at line 95 of file tss.h.

Referenced by tss_init().

◆ reserved4

uint16_t tss_t::reserved4

Definition at line 96 of file tss.h.

Referenced by tss_init().

◆ rsp0

uint64_t tss_t::rsp0

Stack pointer to load when switching to ring 0, unused.

Definition at line 90 of file tss.h.

Referenced by tss_init().

◆ rsp1

uint64_t tss_t::rsp1

Stack pointer to load when switching to ring 1, unused.

Definition at line 91 of file tss.h.

Referenced by tss_init().

◆ rsp2

uint64_t tss_t::rsp2

Stack pointer to load when switching to ring 2, unused.

Definition at line 92 of file tss.h.

Referenced by tss_init().

◆ todo

char tss_t::todo

Definition at line 44 of file threads.h.


The documentation for this struct was generated from the following files: