feat(exceptions): implement basic exception handlers (Phase 1.2.4)#63
Merged
feat(exceptions): implement basic exception handlers (Phase 1.2.4)#63
Conversation
Upgrade Phase-1 exception stubs from minimal vector-name stubs to full diagnostic handlers that report all available fault context over serial. Assembly changes (boot/src/main.rs global_asm!): - Add isr_stub_ec macro for vectors that receive a CPU-pushed error code. Pops the error code into RSI before capturing RSP → ExceptionFrame. - isr_stub updated: RSI=0, RDX=RSP (→ ExceptionFrame). - __exception_common now calls exception_handler(vector, error_code, frame). - Vectors 8,10-14,17,21,29,30 switched to isr_stub_ec per Intel SDM §6.13. exception_handler() (was exception_halt): - arg1 RDI: vector number - arg2 RSI: error code (0 for non-error-code vectors) - arg3 RDX: pointer to ExceptionFrame [RIP, CS, RFLAGS, old_RSP, SS] - Prints: vector name, error code (for applicable vectors), faulting RIP, RFLAGS, old RSP, and CR2 (faulting virtual address) for #PF (vector 14). Adds ExceptionFrame struct documenting the 5-quadword CPU-pushed layout. Closes #9. QEMU boot verification passes.
tests/boot_tests.rs — 35 tests covering: - GDT: bit-pattern correctness for null/code/data descriptors (P, DPL, S, L, D/B, G, executable, writable bits per Intel SDM Vol 3A §3.4.5) - GDT: selector alignment (index × 8, TI=0, RPL=0) - IDT: 64-bit gate attribute bytes (0x8E interrupt, 0x8F trap) - IDT: handler address splitting into offset_low/mid/high fields; round-trip reconstruction; edge cases (0, u64::MAX) - IDT: 256 entries × 16 bytes = 4096 bytes - Exception vectors: which 10 push CPU error codes (Intel SDM Vol 3A §6.13); no-error-code vectors; hardware IRQs (32-255) never push one - ExceptionFrame: 5 quadwords, sequential 8-byte field offsets - Stack constants: 64 KiB total, 4 KiB guard, 60 KiB usable, 16 KiB bootstrap — all page-aligned lib/boot-info/src/lib.rs — 22 tests covering: - BOOT_INFO_MAGIC and BOOT_INFO_VERSION constant stability (ABI contract) - KernelBootInfo::is_valid(): passes for new(), fails for corrupt magic/version - Default field values: acpi_rsdp=0, has_framebuffer=false, empty map - Bootloader name null-termination - KernelMemoryDescriptor::size_bytes() arithmetic - KernelMemoryDescriptor::is_usable() for all usable and reserved types - KernelMemoryMap::entries() slice length matches count field - KernelFramebuffer::zeroed() pixel format and field values - Pixel format constants are distinct - Struct sizes: KernelMemoryDescriptor=32B, KernelFramebuffer=32B
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements Phase 1.2.4: Basic Exception Handlers, closing issue #9.
Upgrades the Phase-1 exception stubs from one-liner vector-name printers to full diagnostic handlers that surface all CPU-provided fault context over serial.
Assembly stub redesign
Two
global_asm!macro variants replace the previous singleisr_stub:isr_stub v[RIP, CS, RFLAGS, old_RSP, SS]isr_stub_ec v[error_code, RIP, CS, RFLAGS, old_RSP, SS]Both stubs pass three arguments to
__exception_common:pop rsi)ExceptionFrame(RSP after error code is consumed)exception_handler() output
For any CPU exception, the handler now prints:
ExceptionFrame struct
Documents the 5-quadword layout the CPU always pushes in 64-bit mode:
[RIP, CS, RFLAGS, old_RSP, SS]Test plan
cargo build— clean, no errorscargo fmt— no formatting changesbash scripts/verify-boot.sh—[PASS] Boot verification PASSED[OK] IDT loaded (32 exception handlers with error codes + RIP + CR2, interrupts disabled)Serial output (QEMU)
Closes #9