This document describes the x86-64 architecture support in the Kyronix kernel. It is the child of Architecture and parent of x86-64-specific documents.
File Purpose
cpu.hCPU primitives, I/O ports, MSRs, control registers, data structures
gdt.cGDT creation, TSS initialization, per-CPU segments
idt.cIDT setup, PIC remapping, ISR dispatch
idt_stubs.SAssembly ISR entry/exit stubs, isr_stub_table
lapic.cLocal APIC initialization, IPI, timer calibration
pit.cPIT channel 0 programming, RTC epoch reading
syscall_setup.cSYSCALL/SYSRET configuration, SSE enable, per-CPU local data
syscall_entry.SSYSCALL entry point, enter_userspace trampolines
Selector Entry Description
0x00Null Null descriptor
0x08Kernel code 64-bit ring 0 executable
0x10Kernel data 64-bit ring 0 writable
0x18User data 64-bit ring 3 writable
0x20User code 64-bit ring 3 executable
0x28 + n*0x10TSS for CPU n Task State Segment
Vectors Source Gate Type Description
0-31 CPU exceptions INT_GATE #DE through #SX
32-47 PIC IRQ 0-15 INT_GATE Legacy PIC interrupts
0x80 (128) SYSCALL USER_GATE (DPL=3) System call entry
224 (0xE0) LAPIC timer INT_GATE Per-CPU timer tick
255 (0xFF) LAPIC spurious INT_GATE Spurious interrupt
IST Index Stack Assigned To
1 16 KiB dedicated Double Fault (#8)
2 16 KiB dedicated NMI (vector 2)
Per-CPU data is accessed via the GS segment register. MSR_GS_BASE points to cpu_local_t for the current CPU. Key offsets:
Offset Field Description
0 kernel_rspKernel stack pointer (for SYSCALL entry)
8 user_rspUser stack pointer (saved on SYSCALL)
16 cpu_idCPU identifier
32 currentCurrent proc_t pointer
40 idleIdle process pointer
The swapgs instruction swaps between user and kernel GS bases on privilege transitions.
Last reviewed: 2026-07-22