Overview
Thearch module provides x86_64-specific functionality including interrupt descriptor table (IDT) setup, global descriptor table (GDT) configuration, task state segment (TSS) management, CPU exception handlers, and hardware detection.
Module Structure
IDT Initialization
init_idt()
Initializes the interrupt descriptor table, global descriptor table, task state segment, and exception handlers.
Location: kernel/src/arch/idt.rs:91
- Configures IST1 (Interrupt Stack Table entry 1) for double fault handler with dedicated 16KB stack
- Builds TSS descriptor in GDT
- Loads GDT with new TSS entry
- Reloads code segment (CS) to apply GDT changes
- Sets data segment registers (DS, ES, SS) and clears FS/GS
- Loads TSS into TR register
- Installs CPU exception handlers (0x00-0x13)
- Installs IRQ handlers (0x20-0x2F), with dedicated PIT handler at IRQ0
- Loads IDTR
- Unmasks IRQ0 (PIT) in the PIC
- Enables interrupts with
sti
Data Structures
IdtEntry
Represents a single entry in the x86_64 IDT.
Location: kernel/src/arch/idt.rs:6
set_handler(&mut self, h: u64)- Set interrupt handler with no ISTset_handler_ist1(&mut self, h: u64)- Set handler using IST1 (for double fault)
Tss (Task State Segment)
Holds privilege level stacks and interrupt stacks.
Location: kernel/src/arch/idt.rs:42
Gdt (Global Descriptor Table)
Location: kernel/src/arch/idt.rs:63
Exception Handlers
All CPU exceptions are handled by specialized handlers inisr_handlers.rs.
CrashFrame
Captures complete CPU state at time of exception.
Location: kernel/src/arch/isr_handlers.rs:33
Exception Handler Functions
Each exception displays a detailed graphical crash screen with register dumps and diagnostic information.| Vector | Name | Handler Function | Description |
|---|---|---|---|
| 0x00 | #DE | isr_divide_by_zero() | Division by zero or overflow |
| 0x05 | #BR | isr_bound_range() | BOUND instruction range exceeded |
| 0x06 | #UD | isr_ud_handler() | Invalid/undefined opcode |
| 0x08 | #DF | isr_double_fault() | Double fault (uses IST1) |
| 0x0D | #GP | isr_gp_handler() | General protection fault |
| 0x0E | #PF | isr_page_fault() | Page fault |
kernel/src/arch/isr_handlers.rs:471
Panic Handler
Rust panic handler with comprehensive diagnostic screen. Location:kernel/src/arch/isr_handlers.rs:318
Hardware Detection
HardwareInfo
Comprehensive hardware detection using CPUID, ATA IDENTIFY, and E820 memory map.
Location: kernel/src/arch/hardware.rs:532
CpuInfo
CPU detection via CPUID instruction.
Location: kernel/src/arch/hardware.rs:50
DiskInfo
ATA/ATAPI disk detection (supports up to 4 drives).
Location: kernel/src/arch/hardware.rs:263
RamInfo
Memory detection from E820 memory map (written by bootloader).
Location: kernel/src/arch/hardware.rs:470
DisplayInfo
Framebuffer information from VESA (written by bootloader).
Location: kernel/src/arch/hardware.rs:505
Assembly Stubs
Exception entry points are defined in assembly (isr.asm) and call into Rust handlers:
Safety Considerations
- init_idt() must be called exactly once
- Exception handlers never return - they halt the system
- Double fault handler uses IST1 to prevent triple faults from stack overflow
- All port I/O and CPUID operations are unsafe
- Hardware detection may return default values if probing fails