Skip to content

feat: build the aarch64 and riscv64 kernel (cross-arch skeleton) - #138

Merged
kernalix7 merged 4 commits into
mainfrom
feat/cross-arch-kernel-build
Jul 10, 2026
Merged

feat: build the aarch64 and riscv64 kernel (cross-arch skeleton)#138
kernalix7 merged 4 commits into
mainfrom
feat/cross-arch-kernel-build

Conversation

@kernalix7

Copy link
Copy Markdown
Owner

Completes the cross-arch kernel build: cargo build -p oncrix-kernel now succeeds on x86_64, aarch64, and riscv64 (previously only x86_64). oncrix-drivers also builds on all three.

What was blocking

  • Generic kernel code hard-coded x86-only arch submodules (crate::arch::x86_64::{clone,init,sched_glue,...}, oncrix_hal::arch::x86_64::uart); the aarch64/riscv64 submodules didn't exist → 24 unresolved-path errors.
  • cachefiles::CacheBackend was ~4.3 GiB by value ([Option;32], each ~134 MiB) → riscv64 codegen aborted with a >2 GiB stack-frame LLVM error.
  • Legacy x86 drivers issued in/out port-I/O asm unconditionally → aarch64/riscv64 invalid register errors.

Changes

  • kernel+hal: arch-neutral facade — arch/mod.rs re-exports the active target's submodules under crate::arch::* / oncrix_hal::arch::* per #[cfg(target_arch)]; generic callers use the neutral paths. New aarch64 + riscv64 arch submodules (clone/context/init/init_embed/sched_glue/syscall_entry) with signature-matching build stubs; aarch64 (PL011) + riscv64 (NS16550) uart shims exposing COM1/Uart16550. x86_64 unchanged.
  • vfs: box cachefiles volume slots → CacheBackend pointer-sized, volumes heap-allocated lazily; capacity/behaviour/private-API unchanged.
  • drivers: cfg-gate x86 port-I/O asm behind #[cfg(target_arch="x86_64")] with type-correct non-x86 fallbacks.

Scope note

Non-x86 runtime bodies are honest stubs (unimplemented!/no-op) pending real context-switch/clone/trap support — this lands a compiling cross-arch skeleton, not a bootable aarch64/riscv64 kernel yet.

Verified

cargo build -p oncrix-kernel on x86_64/aarch64/riscv64 = 0 errors; cargo build --workspace (x86) = 0; cargo fmt --all --check + cargo clippy --workspace -- -D warnings = clean. No x86 regression.

The generic kernel referenced x86-only arch submodules directly
(crate::arch::x86_64::{clone,init,sched_glue,...}, oncrix_hal::arch::
x86_64::uart), so only x86_64 built. Introduce an arch-neutral facade:
kernel and hal arch/mod.rs re-export the active target's submodules
under crate::arch::* / oncrix_hal::arch::* per #[cfg(target_arch)], and
generic callers use those neutral paths. Provide aarch64 and riscv64
arch submodules (clone, context, init, init_embed, sched_glue,
syscall_entry) with signature-matching build stubs, plus aarch64 (PL011)
and riscv64 (NS16550) uart shims exposing COM1/Uart16550. x86_64 is
unchanged. Non-x86 runtime bodies are honest stubs (unimplemented!/no-op)
pending real context-switch/clone support; this lands a compiling
cross-arch skeleton.
cachefiles::CacheBackend inlined [Option<CacheVolume>; 32] where each
CacheVolume is ~134 MiB, making the struct ~4.3 GiB by value. Building it
in CacheBackend::default() needs a >2 GiB stack frame, which the riscv64
backend rejects (signed-32-bit frame-offset limit), aborting codegen.
Box the volume slots ([Option<Box<CacheVolume>>; 32]) so the struct is
pointer-sized and volumes are heap-allocated lazily; capacity, behaviour,
and the private API are unchanged.
Legacy x86 device drivers (PS/2, VGA text, RTL8139/ATA/AC97/SB16 PIO, PC
speaker, CMOS, 8250/16550 port-I/O, uhci, e100, ne2k, ...) issued in/out
and other x86 port-I/O instructions unconditionally, failing to build on
aarch64/riscv64 (invalid register dx/ax/al). Gate the x86 asm behind
#[cfg(target_arch = "x86_64")] with type-correct non-x86 fallbacks
(default read / no-op write) so the crate builds on all three targets;
x86 behaviour is unchanged.
A newer nightly clippy flags the tree-wide 'for slot in &mut self.table
{ *slot = None; }' clear pattern (fixed-capacity inline tables) as
manual_slice_fill. .fill(None) is not always applicable (non-Copy
elements) and the loop is clear, so allow it workspace-wide, matching the
existing large_const_arrays allow. Unblocks workspace clippy CI.
@kernalix7
kernalix7 merged commit 6f9ec65 into main Jul 10, 2026
2 checks passed
@kernalix7
kernalix7 deleted the feat/cross-arch-kernel-build branch July 10, 2026 07:01
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