[][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

IndexFound inMaps toPurpose
GdtIndex::Nullnowhere (hopefully)__
GdtIndex::KCodecs, while in kernel codeflat: 0x00000000..0xffffffffkernel's code segment
GdtIndex::KDatads, es, while in kernel codeflat: 0x00000000..0xffffffffkernel's data segment
GdtIndex::KTlsgs, while in kernel codekernel's cpu-localskernel sets-up cpu-locals at this address
GdtIndex::KStackss, while in kernel codeflat: 0x00000000..0xffffffffkernel's stack segment
GdtIndex::UCodecs, while in user codeflat: 0x00000000..0xffffffffuser's code segment
GdtIndex::UDatads, es, while in user codeflat: 0x00000000..0xffffffffuser's data segment
GdtIndex::UTlsRegionfs, while in user code&TLS..&TLS+0x200user can get the address of its TLS from this selector
GdtIndex::UTlsElfgs, while in user codeUser-defineduser can set-up elf TLS at this address
GdtIndex::UStackss, while in user codeflat: 0x00000000..0xffffffff
GdtIndex::LDT_Points to the GLOBAL_LDT
GdtIndex::TSSIDT Double fault vectorPoints to the MAIN_TASKDouble fault exception backups registers to this TSS
GdtIndex::FTSSIDT Double fault vectorDouble 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:

IndexFound inMaps toPurpose
MSRfs, while in kernel codekernel's cpu-localskernel sets-up cpu-locals at this address
MSRgs, while in user code&TLS..&TLS+0x200user can get the address of its TLS from this selector
MSRfs, while in user codeUser-defineduser 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.