Skip to content

feat: Enable x2APIC mode if CPU supports it#30

Open
emilf wants to merge 1 commit intomainfrom
feat/x2apic-enable
Open

feat: Enable x2APIC mode if CPU supports it#30
emilf wants to merge 1 commit intomainfrom
feat/x2apic-enable

Conversation

@emilf
Copy link
Copy Markdown
Owner

@emilf emilf commented Mar 28, 2026

What

Adds try_enable_x2apic() which enables x2APIC mode at boot if CPUID reports support.

Called before init_apic_mode() so the mode cache sees x2APIC, not xAPIC.

How it works

  1. Checks CpuFeatures::get().x2apic — early-return with log if unsupported
  2. Reads IA32_APIC_BASE (MSR 0x1B) — early-return if already enabled (idempotent)
  3. Sets bits 10 (x2APIC enable) + 11 (global enable), writes back
  4. Reads back to verify hardware accepted it; logs success or failure
  5. init_apic_mode() then caches ApicAccessMode::X2Apic

The dispatch layer (local_apic_read/write/eoi/id) already handled x2APIC via MSR paths — this activates that path.

Verified in QEMU

[INFO  interrupts::apic] x2APIC enabled
[INFO  interrupts::apic] APIC mode: x2apic
[INFO  environment] LAPIC timer interrupt received successfully

Full boot completes including ACPI, PCI scan, USB/xHCI keyboard enumeration.

Docs

docs/plans/x2apic-prep.md updated — all four phases now marked complete.

Changes

  • kernel/src/interrupts/apic.rs: try_enable_x2apic() + log_error! import
  • kernel/src/interrupts/mod.rs: re-export try_enable_x2apic
  • kernel/src/environment.rs: call try_enable_x2apic() before init_apic_mode()
  • docs/plans/x2apic-prep.md: all phases marked IMPLEMENTED

Add try_enable_x2apic() which reads IA32_APIC_BASE, sets bits 10+11
(x2APIC enable + global enable), writes back, and verifies via readback.
Must be called before init_apic_mode() so the mode cache sees x2APIC.

The dispatch layer (local_apic_read/write/eoi/id) already handled x2APIC
via x2apic_read/x2apic_write MSR helpers — this activates that path.

Verified in QEMU (-cpu max): x2APIC enabled, APIC mode: x2apic,
LAPIC timer interrupt received successfully, full boot completes.

Also update x2apic-prep.md: all four phases now complete.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant