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

IDT

This document describes the Interrupt Descriptor Table (IDT) implementation in the Kyronix kernel. It is the child of x86-64 Architecture.

Source

kernel/arch/x86_64/idt.c, kernel/arch/x86_64/idt_stubs.S

Overview

The IDT provides 256 interrupt vector entries. The Kyronix kernel maps CPU exceptions (vectors 0-31), legacy PIC IRQs (vectors 32-47), the SYSCALL vector (0x80), LAPIC timer (224), and LAPIC spurious (255) through a table of 51 assembly stubs (isr_stub_table).

Vector Allocation

VectorsSourceGate TypeISTHandler
0-31CPU exceptionsINT_GATEisr_dispatch()
3 (#BP)BreakpointTRAP_GATEAllows debugger resume
8 (#DF)Double FaultINT_GATEIST 1Dedicated DF stack
2 (NMI)NMIINT_GATEIST 2Dedicated NMI stack
32-47PIC IRQ 0-15INT_GATEisr_dispatch()
128 (0x80)SYSCALLUSER_GATE (DPL=3)isr_dispatch()
224 (0xE0)LAPIC timerINT_GATEisr_dispatch()
255 (0xFF)LAPIC spuriousINT_GATESilently returns

Gate Types

ConstantValueDescription
IDT_INT_GATE0x8EInterrupt gate: present, DPL=0, clears IF on entry
IDT_TRAP_GATE0x8FTrap gate: present, DPL=0, does NOT clear IF
IDT_USER_GATE0xEEInterrupt gate: present, DPL=3 (user-accessible)

ISR Dispatch (isr_dispatch)

The central C function called from isr_common assembly after register save. It handles:

CPU Exceptions (vectors 0-31)

  • User-mode exceptions: Deliver signal to process via exception_signal(n) (SIGFPE, SIGILL, SIGTRAP, SIGSEGV, SIGBUS, etc.)
  • Page fault (vector 14): handle_user_page_fault() implements demand paging for stack growth and VMA-based anonymous pages
  • Breakpoint/Debug (vectors 1, 3): Check tracer_pid for ptrace support; #BP decrements RIP by 1 past int3
  • Kernel-mode exceptions: Full panic with register dump, exception name, CR2 (for #PF), and kernel backtrace

PIC IRQs (vectors 32-47)

  • IRQ 0 (timer tick): Increments g_ticks, cursor blink, zombie reaping, network polling, timer mask processing (wakeup, alarm, itimer), preemption check
  • IRQs 1-15: Dispatch to registered g_irq_handlers[irq] handlers

Special Vectors

  • LAPIC timer (224): Same preemption logic as PIC IRQ 0
  • LAPIC spurious (255): Silently returns

ISR Stub Assembly

The isr_common routine in idt_stubs.S performs:

  1. swapgs if entering from ring 3 (privilege transition)
  2. Push all 15 GPRs (forming cpu_state_t frame)
  3. Call isr_dispatch(state) in C
  4. Pop all GPRs
  5. swapgs if returning to ring 3
  6. iretq

IRQ Registration

void request_irq(uint8_t irq, irq_handler_fn fn, void *arg);

Registers a handler for PIC IRQ 0-15 and unmasks it via pic_unmask_irq().

Kernel Backtrace

The kernel_backtrace() function scans the kernel stack for return addresses in the range [0xffffffff80000000, 0xffffffff80040000) and prints up to 48 candidates. It is called only during kernel panics.

Last reviewed: 2026-07-22