kernel::arch
The seam between the kernel’s logic and the machine underneath it.
On the target this is a thin re-export of arch-xtensa. On a host it is a
set of stand-ins — and those stand-ins are the only reason cargo test can
build this crate at all. arch-xtensa carries
#![feature(asm_experimental_arch)], which is E0554 on the stable
toolchain CI uses, so a kernel that names it unconditionally cannot be
compiled for the host. Its unit tests then run nowhere, which is precisely
where they ran before this module existed.
The stand-ins are instrumented rather than inert. A cs_with that only
called its closure would accept an unbalanced critical section without
complaint; this one tracks nesting so a test can assert on it. A tick you
can set is what makes a rollover test possible at all: at one millisecond
the real counter needs longer than the age of the universe to wrap, so
lying about the clock is the only way to reach the arithmetic.
What this does not do is pretend to be a machine. The host cs_with
masks nothing, because on a host there is nothing to mask. The concurrency
this kernel actually has — a timer ISR preempting a task in the middle of a
critical section, a register window spilled across a trap — has no host
equivalent, and no fake here will find a bug in it. That is what the
on-target suite is for (make test-target). This seam buys coverage of
logic: state machines, bounds, exhaustion, arithmetic. Read a green host
run as “the logic is consistent”, never as “the kernel works”.
Modules
Section titled “Modules”host— Host stand-ins for the Xtensa primitives the kernel’s logic touches.
Functions
Section titled “Functions”cs_try_with
Section titled “cs_try_with”fn cs_try_with<R, impl FnOnce() -> R>(f: impl FnOnce) -> Option<R>wait_for_interrupt
Section titled “wait_for_interrupt”fn wait_for_interrupt()Park until an interrupt, through the selected architecture.
wait_masked
Section titled “wait_masked”fn wait_masked()Terminal halt through the selected architecture.
Type Aliases
Section titled “Type Aliases”Context
Section titled “Context”type Context = SelectedArch::Context;Saved frame selected with the architecture in exactly one place.
References: SelectedArch