Repository navigation
Conversation
…irmware boundary Under the UEFI target rustc forces `is-like-windows` (os = "uefi"), so plain `extern "C"` means the Microsoft x64 ABI: first argument in RCX, args in RCX/RDX/R8/R9. That is correct where firmware is the other side, but it leaked into purely internal boundaries, so assembly calling into Rust had to use Microsoft registers while every reference and external doc assumes SysV. Convert the internal boundaries to `extern "sysv64"`: - `interrupts/handlers.rs::irq_dispatch_common` — called from `irq_stub_common`. The stub now pops the vector into RDI instead of RCX. This retires the Microsoft-ABI workaround added in PR #29 ("correct calling convention (RCX not RDI)"); the stub uses the register the SysV documentation assumes. - `interrupts/mod.rs::noop_for_test` - `monitor/commands/control.rs` — the monitor's `call` trampoline Deliberately left `extern "C"`, each annotated with why: - `lib.rs::kernel_entry` — called by the bootloader as `extern "C" fn(u64)` and `entry-abi: win64` in the target spec. - `environment.rs::after_high_half_entry` / `continue_after_stack_switch` and the matching `memory.rs` extern block — reached by a raw jump, so the declaration must pair with the definition, not with a Rust caller. - `handlers.rs` stub symbol declarations and `IRQ_STUB_TABLE` — addresses only, never called through Rust; the ABI string is declarative. Verification (theseus-qemu --headless, serial relay attached before boot): - 0 page/GP faults, no panic. - `LAPIC timer interrupt received successfully` — the timer ISR dispatched through the converted `irq_dispatch_common`, which is the path this change actually exercises. - `xHCI MSI handler invoked (first delivery)` — MSI vector path intact. - 1429 bytes on COM1; boot reaches monitor and idle loop. Docs: - New axiom A1.1 recording both conventions, the permitted-`extern "C"` set, the asm-register rule, and the red-zone requirement (`disable-redzone: true` stays). - interrupts-and-platform plan: implemented invariant for the SysV dispatch path. - AGENTS.md: new "Calling conventions" gotcha block, so a fresh dev session sees it without inferring from a compiler error. No behaviour change intended beyond ABI selection; the retained Win64 boundary is unchanged and was re-verified by the boot.
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
Uses the System V AMD64 ABI for internal calls and keeps the Microsoft x64 ABI only where firmware or raw assembly is the other side. Branched from
main(76b9021) so it merges independently of #31 / #32 / #33.Why the kernel was using MS ABI
The kernel builds under the UEFI target, where rustc forces
is-like-windowsbecauseosis"uefi". So plainextern "C"means:That is correct at the firmware boundary, but it had leaked into purely internal boundaries — so assembly calling into Rust had to use Microsoft registers, while every reference document and external snippet assumes SysV. PR #29 had to be fixed for exactly this ("Correct calling convention (RCX not RDI)").
The target spec cannot be edited to opt out: rustc rejects
is_like_windowsunlessosis windows/uefi/cygwin, and rejectslinker_flavorunless it matchesis_like_msvc. Per-function ABI is the available mechanism.Changes
Converted to
extern "sysv64":interrupts/handlers.rs::irq_dispatch_common— called fromirq_stub_common; the stub now pops the vector into RDI instead of RCX. This retires the Microsoft-ABI workaround from PR feat: Per-vector interrupt stubs (global_asm!, replaces ISR scanning) #29.interrupts/mod.rs::noop_for_testmonitor/commands/control.rs— the monitor'scalltrampolineDeliberately left
extern "C", each annotated in-code with the reason:kernel_entry— called by the bootloader asextern "C" fn(u64);entry-abi: win64in the target specafter_high_half_entry/continue_after_stack_switch+ thememory.rsextern block — reached by a raw jump, so declarations must pair with definitionsIRQ_STUB_TABLE— addresses only, never called through RustVerification
theseus-qemu --headless, serial relay attached before boot:LAPIC timer interrupt received successfully— the timer ISR dispatched through the convertedirq_dispatch_common. This is the path the change actually exercises; a wrong ABI here faults immediately.xHCI MSI handler invoked (first delivery)— MSI vector path intactDocs
extern "C"set, the asm-register rule (irq_stub_common→ RDI), and whydisable-redzone: truemust stay (SysV's 128-byte red zone is clobberable by an interrupt).plans/interrupts-and-platform.md— implemented invariant for the SysV dispatch path.AGENTS.md— new "Calling conventions" block under Gotchas so a fresh session learns this before hitting a compiler error.Not done here (deliberately)
This does not split the bootloader and kernel. A real split (kernel as its own ELF on
x86_64-unknown-none) is still worth doing eventually — but its motivating benefit is the ELF loader, which is the same work Phase 6 needs for user processes. Because internal boundaries are now explicitlysysv64, that future split becomes a spec-and-loader change with no ABI rewrite; with plainextern "C"it would silently change meaning the day the target changed.