[−][src]Module sunrise_kernel::i386::gdt
GDT Handler
The Global Descriptor Table is responsible for segmentation of memory.
Since we manage memory permissions in the paging, we want to set-up our
segments so that we have a flat-memory model, i.e. having segments with
base = 0; limit = 0xffffffff
.
GDT segments
Index | Found in | Maps to | Purpose |
---|---|---|---|
GdtIndex::Null | nowhere (hopefully) | _ | _ |
GdtIndex::KCode | cs , while in kernel code | flat: 0x00000000..0xffffffff | kernel's code segment |
GdtIndex::KData | ds , es , while in kernel code | flat: 0x00000000..0xffffffff | kernel's data segment |
GdtIndex::KTls | gs , while in kernel code | kernel's cpu-locals | kernel sets-up cpu-locals at this address |
GdtIndex::KStack | ss , while in kernel code | flat: 0x00000000..0xffffffff | kernel's stack segment |
GdtIndex::UCode | cs , while in user code | flat: 0x00000000..0xffffffff | user's code segment |
GdtIndex::UData | ds , es , while in user code | flat: 0x00000000..0xffffffff | user's data segment |
GdtIndex::UTlsRegion | fs , while in user code | & TLS ..& TLS +0x200 | user can get the address of its TLS from this selector |
GdtIndex::UTlsElf | gs , while in user code | User-defined | user can set-up elf TLS at this address |
GdtIndex::UStack | ss , while in user code | flat: 0x00000000..0xffffffff | |
GdtIndex::LDT | _ | Points to the GLOBAL_LDT | |
GdtIndex::TSS | IDT Double fault vector | Points to the MAIN_TASK | Double fault exception backups registers to this TSS |
GdtIndex::FTSS | IDT Double fault vector | Double fault exception loads registers from this TSS |
UTlsRegion
The kernel allocates a 0x200-bytes region for every thread, and always makes fs
point to it
when jumping to userspace. See TLS
for more.
This region is thread local, its address is switched at every thread-switch.
UTlsElf:
The segment pointed by gs
is controlled by the user. It can set its address/limit with
svcSetThreadArea
. The segment it chooses to use is local to every thread, and defaults to 0x00000000..0xffffffff
.
Typically, the user will want to make gs
point to its elf TLS.
This segment is thread local, its address and size are switched at every thread-switch.
LDT segments:
None :)
x86_64
Because x86_64 uses fs
for tls instead of gs
, the purpose of gs
and fs
are swapped:
Index | Found in | Maps to | Purpose |
---|---|---|---|
MSR | fs , while in kernel code | kernel's cpu-locals | kernel sets-up cpu-locals at this address |
MSR | gs , while in user code | & TLS ..& TLS +0x200 | user can get the address of its TLS from this selector |
MSR | fs , while in user code | User-defined | user can set-up elf TLS at this address |
Structs
DescriptorTable | A structure containing our GDT. |
DescriptorTableEntry | An entry in the GDT/LDT. |
DoubleFaultTaskStack | The stack used while handling a double fault. |
GdtManager | Safety wrapper that manages the lifetime of GDT tables. |
MainTask | The main TSS. See MAIN_TASK. |
Enums
GdtIndex | Index in the GDT of each segment descriptor. |
SystemDescriptorTypes | Lists the valid values of System Descriptor Types. |
Statics
DOUBLE_FAULT_TASK | Double fault TSS |
DOUBLE_FAULT_TASK_STACK | The stack used while handling a double fault. See DOUBLE_FAULT_TASK. |
GDT | The global GDT. Needs to be initialized with init_gdt. |
GLOBAL_LDT | The global LDT used by all the processes. |
MAIN_TASK | Main TSS |
Functions
init_gdt | Initializes the GDT. |