native_fault first asks hle_fault: for a block with an HLE mark, a fault
at an offset before the mark's prefix end, from an x86 exception that is
a guest access's as native_fault judges one (a #PF with a plain
read/write error code, or a #GP/#SS of a non-canonical address), settles
the run as native_fault does at the block's first instruction with none
of it retired: pinned::settle over a copy of the state, the chain's
retired instructions added, the PC at the entry, a link's BTYPE applied.
The fast path writes no guest register or frame field before its commit
point, so that is the state the call entered with. It then sets the
bypass and counts it. The scheduler's step takes the bypass beside PACM
(always evaluated, so a stale one is cleared) and fetches the entry as a
single-instruction block: the original runs from its first word and
takes the fault itself, with ESR, FAR, ELR and state as without HLE. A
fault in the bail's code keeps its moved recovery row; any other trap in
a fast path still stops the PE.
The plan bypassed #PF only; accepting the non-canonical #GP/#SS too keeps
a fast path exact where the placement's limit lies past the host's
canonical range (the test host's five-level limit on a four-level host),
the faults native_fault already accepts at a guest access.
Tests: Touch with X0 unreadable equals the original in full and bypasses
once; three such calls on one machine bypass three times and stay exact;
every readable/unreadable/read-only combination of X0 and X1 agrees;
4000 random Touch cases bypass exactly when X0's page is unreadable;
pointers at or past the limit, tagged or in the upper half bail without
a fault, an unmapped one in range bypasses; software step never matches;
a reused session runs as a fresh machine with Touch on as well, and no
call with every page mapped bypasses. Mutations caught: no hook, no
prefix bound, no bypass taken.
Translator id unchanged: engine glue and tests only.
hle_compile now installs what it accepts (install_hle, after
install_device_stub): a copy of the entry's first word is admitted and
prepared alone in the compile's variant; anything but one instruction's
block counts the bail refusal, a refused layout the compose refusal, and
either is translated as before. The composite's emission holds that word
as its input and installs through Machine::install as a block of one
instruction at the entry's PC and frame, so the board indexes it, links
into and out of it and retires it as any block (an IC IVAU of any word of
the function retires its page's blocks), and nothing stores, offers or
rebases it. Its Block holds hle::Mark, one byte with a niche (the fast
path's length in 64-byte units), set from State::installing as a device
stub's flag is; Block stays within its 72-byte bound. The mark is read by
the fault bypass that follows (expect(dead_code) until then). The plan's
mark held the routine too; nothing reads it, so it is left out.
Tests: a Bail composite at every stand-in, entered directly and through
blr x16 on a guarded page, ends every call exactly as the original
(4000 cases each, a sixteenth through blr), installs and never bypasses;
a composite is installed once and reused; Touch with X1 unreadable takes
the original's fault through the bail's moved recovery row. A match
whose routine has no fast path yet (memmove) is refused as compose and
translated with the same blocks as off.
Translator id unchanged: engine glue and tests only.
stela_compiler::x86_64::hle::compose lays out a Request (routine, entry
PC, exit ret, max_bytes) in front of the bail, the entry's first word
compiled alone as the engine compiles a block: bytes [0, prefix_end) are
the fast path, built pinned with the block's link slots and padded with
INT3 to a multiple of 64; each bail is a jmp rel32 to prefix_end; from
prefix_end the bail's code follows unchanged, its direct exits, fault
recovery rows and cold code moved by prefix_end, which keeps their patch
points' residues mod 8, and align_exits runs over the whole. The
composite is one instruction: source_bytes 4, relocations None, no
self-loop or region.
emit.rs: Bails, checked() (xor edx; rax = lower_limit - base, bail on
BE; cmp rax, n, bail on B; after each branch a CMOV of the same flags
makes the dereferenced register and n 0, no LFENCE) and success() (a
Direct exit with its forward link slot). Bail's fast path is one jump to
the bail; Touch's checks X0 for one byte, loads it into EAX and bails,
followed by a success exit no path takes, for its layout's tests. The
production routines are refused (NoNative) until their fast paths land.
Two deviations from the plan, both forced by the engine: the source map
is [(pc, 0)] alone, since place() requires one entry per source word and
a second (pc, prefix_end) entry would make the one word two instructions;
and of the three const assertions only the pinned map (X0 in R15, X1 in
RBP) and the frame's X array at offset 0 are const, as link_slot and
offset are not const fns (chain.rs and x86_64.rs stay untouched): tests
pin the forward link slot and X2 at frame byte 16. compose also refuses
a fast path past 255 * 64 bytes (PrefixTooLong), the most the engine's
one-byte mark names.
Translator id CHANGES (crates/stela-compiler/src): together with the
previous commit's move, one refill of the translation store.
stela_compiler::x86_64::hle::Routine is the enum that was
stela_engine::hle's routine module, unchanged: the five production
routines and, under test or test-support, Bail and Touch. The engine
re-exports it as hle::Id, and its test-support feature now enables the
compiler's so the test routines exist wherever the engine's do. The
names test moves with it.
Translator id CHANGES: crates/stela-compiler/src is fingerprinted
(STELA_COMPILER_SOURCE_SHA256), so a pack made before this commit is
stale. The composite's emitters land in this same compiler module next,
so an image built from the finished branch refills the translation store
once, as the plan's section C expects.
Machine::set_hle takes a Config and hle_statistics reports what it did
(hle::Statistics: matched, the signatures that matched, installed,
bypassed and refusals by reason). compile_window calls hle_compile after
it reads the source and before it looks for a stored, shared or rebased
block. With no routine enabled it returns at once, so a boot without
--hle compiles exactly the blocks it did before (pinned by
hle_off_compiles_the_same_blocks_as_without_it, also for --hle with the
empty generated table). Only an EL0 compile of an ordinary variant
looks: not single-step, translated, DIT-timed or streaming, with FP on and
no alignment checks. A candidate's prefix hash is checked at its own
length, then its digest over the bytes of the window or, for a function
longer than it, of RAM. Only the first window of a compile looks, so the
whole-window compile that may follow does not count the same match twice.
Nothing is installed yet: a match is translated as before.
Beyond the plan's five refusals there is a sixth, admitted: a function
holding a word the chip lacks (Chip::admit makes it UDF or a NOP) is
refused, as the original would not run the bytes its signature was made
from.
The harness's Session::new and run take an Option<Config>, run returns
the run's Statistics, and a reused session runs as a fresh machine with
HLE on (Bail for every stand-in, Touch for touch's) as well as off.
Translator id unchanged: src/hle and the engine glue are not translation
inputs.
An Outcome now holds PSTATE, and an abort ESR, FAR, ELR and SPSR_EL1.
StandIn::through_blr appends a `blr x16` after the function and guards
the code mapping (store_host's NativeHost::guard sets GP, bit 50, in its
stage-1 descriptors): memset's `bti c` admits the call's BTYPE 0b10 and
runs as the model says, every other stand-in takes a Branch Target
exception at its entry with BTYPE in ESR and SPSR. A session's call clears
BTYPE, which the abort's ERET brought back from SPSR, and ESR, FAR, ELR
and SPSR, which a Branch Target exception leaves partly as they were, so
a reused session still runs as a fresh machine, now also through blr.
agree() requires PSTATE equal and X0 as the model gives it.
Translator id unchanged: tests only.
The digest now follows each masked word with a byte that says whether
it has a masked field, so a candidate whose word is a branch out of the
function no longer matches a signed function holding `b .` there; the
prefix hash stays a filter. Eligibility refuses a last word other than
`ret` or an inside `b` (FallsThrough), every word with bits 31:25 clear
(Reserved: UDF, AMX's 0x00201000 | op << 5 | Rt, GXF and the SPTM's
maintenance words), and as Exclusive the RCpc forms with an offset or
writeback (LDAPUR, STLUR, their SIMD&FP forms, RCpc3), LSE128 and the MTE
tag accesses of that class. The stand-ins pad with NOPs before their last
`ret` instead of after it.
Translator id unchanged: only crates/stela-engine/src/hle (not a
translation input) and tests change.
The install build is the RTL8852CE Wi-Fi branch (wifi/rtw8852c-m3, 999c0d361)
with upstream's GPT slot, TRIM and 32 MiB log fixes.
One conflict, in crates/stela-boot/src/engine/network.rs (HostNetwork::open):
the Wi-Fi adapter's address wait still runs through network_link::address,
so its connection keeper's failures are retried until the cut, and upstream's
DHCP and DNS notes (Stack::take_notes) are logged after that wait, before the
keeper's retry line. This matches wifi/rtw8852c-m3-test, without its
host-check-only `pub(crate) mod security`.