Skip to main content

Module gdt

Module gdt 

Source
Expand description

Global Descriptor Table (GDT) for Strat9-OS

Sets up the GDT with kernel code/data segments, user segments for SYSRET, and a TSS descriptor. The TSS must be initialized before this module.

§Segment layout (SYSRET-compatible)

Index 0: Null
Index 1: Kernel Code 64-bit  (CS=0x08)     ← SYSCALL loads CS from STAR[47:32]
Index 2: Kernel Data          (SS=0x10)     ← SYSCALL loads SS
Index 3: User Code 32-bit    (dummy, 0x18)  ← STAR[63:48] base
Index 4: User Data            (0x20)        ← SYSRETQ: SS = base+8 | RPL3 = 0x23
Index 5: User Code 64-bit    (0x28)        ← SYSRETQ: CS = base+16 | RPL3 = 0x2B
Index 6-7: TSS (16-byte descriptor)

STAR MSR: [47:32]=0x08 (kernel CS), [63:48]=0x18 (index 3). SYSRETQ: CS = 0x18+16 = 0x28 | RPL3 = 0x2B, SS = 0x18+8 = 0x20 | RPL3 = 0x23.

Functions§

init
Initialize the GDT with kernel segments, user segments, and TSS.
init_cpu
Initialize the GDT for a given CPU index.
kernel_code_selector
Get the kernel code segment selector
kernel_data_selector
Get the kernel data segment selector
star_msr_value
Get the raw STAR MSR value for SYSCALL/SYSRET.
user_code_selector
Get the user code 64-bit segment selector (with RPL=3)
user_data_selector
Get the user data segment selector (with RPL=3)