Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

x86-64 Architecture

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.

Files

FilePurpose
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

GDT Layout

SelectorEntryDescription
0x00NullNull descriptor
0x08Kernel code64-bit ring 0 executable
0x10Kernel data64-bit ring 0 writable
0x18User data64-bit ring 3 writable
0x20User code64-bit ring 3 executable
0x28 + n*0x10TSS for CPU nTask State Segment

IDT Vector Layout

VectorsSourceGate TypeDescription
0-31CPU exceptionsINT_GATE#DE through #SX
32-47PIC IRQ 0-15INT_GATELegacy PIC interrupts
0x80 (128)SYSCALLUSER_GATE (DPL=3)System call entry
224 (0xE0)LAPIC timerINT_GATEPer-CPU timer tick
255 (0xFF)LAPIC spuriousINT_GATESpurious interrupt

IST Usage

IST IndexStackAssigned To
116 KiB dedicatedDouble Fault (#8)
216 KiB dedicatedNMI (vector 2)

Per-CPU Data

Per-CPU data is accessed via the GS segment register. MSR_GS_BASE points to cpu_local_t for the current CPU. Key offsets:

OffsetFieldDescription
0kernel_rspKernel stack pointer (for SYSCALL entry)
8user_rspUser stack pointer (saved on SYSCALL)
16cpu_idCPU identifier
32currentCurrent proc_t pointer
40idleIdle process pointer

The swapgs instruction swaps between user and kernel GS bases on privilege transitions.

Last reviewed: 2026-07-22