20 Commits
Author SHA1 Message Date
atharvranjan 99ed89787e Integrate PR #275 preserving FNINIT and existing shift expectations
Signed-off-by: Arths17 <Atharvranjan8@gmail.com>
2026-11-24 21:49:30 -06:00
atharvranjan 522560d0a2 Integrate PR #271 while preserving BetterXen terminology
Signed-off-by: Arths17 <Atharvranjan8@gmail.com>
2026-11-24 21:48:34 -06:00
atharvranjan bfe0bbfaf7 Rename project and native applications to BetterXen
Update active repository links and coordination settings while retaining upstream history, notices, legacy library names and guest interfaces. Document the independent-copy migration and its limits.

Signed-off-by: Arths17 <Atharvranjan8@gmail.com>
2026-11-24 20:51:08 -06:00
zachdoxsee 501117c4d8 Merge upstream main into task/378-fninit
Signed-off-by: zachdoxsee <zachdoxsee36@gmail.com>
2026-11-25 02:10:46 +01:00
maridogolpeador 67023d292b loader: add SHLD and SHRD, the double-precision shifts (#121)
Both engines refused SHLD and SHRD (0F A4/A5, 0F AC/AD) as illegal
instructions. They are now declared in the x86 registry and run on the
shared semantics for 16-, 32- and 64-bit register and memory
destinations, with the count in an 8-bit immediate or in CL.

- instructions.toml, x86_table.rs (generated), generate_x86.py,
  x86_decode.rs: the two operations and two operand encodings,
  rm_reg_imm and rm_reg_cl (ModRM destination, reg source, count).
- x86_exec.rs: the destination is shifted with the vacated bits filled
  from the source register. The count is masked to five bits (six for
  64-bit operands), a masked count of zero changes nothing, CF takes the
  last bit shifted out, ZF/SF/PF follow the result and OF is set only
  for a count of one. A 16-bit count above 16 is undefined in the SDM;
  the flags are kept and no test relies on the result.
- cpu_known_answers.rs: eight SDM-derived cases move from refused to
  verified.
- tests/x86: 72 assembled SHLD and SHRD instructions, with a
  bit-at-a-time reference in x86_integer.rs. A destination the
  reference marks undefined now skips the memory operand check too.
- docs/cpu/instruction-registry.md, CHANGELOG.md.

Nothing is lowered to ARM64.

Signed-off-by: maridogolpeador <354308468+maridogolpeador@users.noreply.github.com>
2026-11-24 20:47:45 -03:00
Bartosz Szczepański 1c6bd25723 loader: run LAHF and SAHF and report them in CPUID (#387)
LAHF (9F) and SAHF (9E) are declared in the instruction registry and run
through the shared semantics in both engines (Intel SDM Vol. 2A LAHF,
Vol. 2B SAHF): LAHF writes AH = SF:ZF:0:AF:0:PF:1:CF and keeps the rest of
RAX, SAHF loads SF, ZF, AF, PF and CF from AH and leaves OF unchanged.
With both implemented, guest CPUID reports leaf 8000_0001h ECX bit 0.

The four known answers recorded as refused by #155 are verified, with
twelve more cases. Both instructions join the clang-assembled integer
fixtures and the independent bit-level reference, and cpu_features.rs
moves LAHF/SAHF from the refused witnesses to the reported features.

Signed-off-by: Bartosz Szczepański <bartosz.szczepanski@hotmail.com>
2026-11-24 23:32:17 +01:00
zachdoxsee 47a819e05b loader: add FNINIT and the x87 control, status and tag words (#378)
The decoder refused FNINIT (DB E3), which the mingw-w64 C runtime runs
once before main. Guest state gains the x87 control, status and tag
words, and FNINIT sets them to the Intel SDM values 037F, 0 and FFFF.
Both engines run the shared semantics.

The registry gains a form key, rm, that pins a register-only form to one
ModRM byte: the other bytes of DB /4 are different instructions. No other
x87 instruction is added and CPUID still reports no FPU.

Part of Gate A2.

Signed-off-by: zachdoxsee <zachdoxsee36@gmail.com>
2026-11-24 23:01:33 +01:00
zachdoxsee c9505e53e2 Merge upstream main into task/199-fences
Conflicts: CHANGELOG.md, where both entries are kept; the generated
crates/loader/src/x86_table.rs, rebuilt with generate_x86.py from the
merged instructions.toml; and one sentence of
docs/cpu/instruction-registry.md, where the list of rejected
instructions now drops both RCL/RCR (from #351) and the fences.

Signed-off-by: zachdoxsee <zachdoxsee36@gmail.com>
2026-11-24 20:54:40 +01:00
zachdoxsee b1b57cf16a Merge upstream main into task/128-exact-unmasked-overflow
Conflict in CHANGELOG.md only: both new entries are kept.

Signed-off-by: zachdoxsee <zachdoxsee36@gmail.com>
2026-11-24 20:40:31 +01:00
sahib453 94783fa603 docs: take the fences off the rejected-on-purpose list (#199)
The instruction registry document listed fences among the forms
rejected on purpose. This branch accepts them and explains why in the
new memory-ordering section, so the list no longer names them.

Signed-off-by: sahib453 <117431595+sahib453@users.noreply.github.com>
2026-11-25 00:44:40 +05:30
sahib453 c1cea65e17 docs: take RCL and RCR off the rejected-on-purpose list (#121)
The instruction registry document listed RCL and RCR among the forms
rejected on purpose. This branch implements them, so the list no longer
names them. SHLD and SHRD stay on it.

Signed-off-by: sahib453 <117431595+sahib453@users.noreply.github.com>
2026-11-25 00:44:28 +05:30
sahib453 d195978903 loader: accept MFENCE, LFENCE and SFENCE and document guest memory ordering (#199)
Both engines refused the three fences as illegal instructions, and no
document said what ordering guest memory accesses have.

- instructions.toml, x86_table.rs (generated): the register forms of
  0F AE digits 5, 6 and 7. The memory forms stay undeclared.
- x86_exec.rs: a fence changes nothing. Each engine runs one guest
  instruction at a time on one host thread and completes its loads and
  stores before the next, so accesses are already totally ordered.
- docs/cpu/instruction-registry.md: states that ordering, why the
  fences are no-ops under it, and that it holds only while guest
  threads do not run on several host threads.
- Tests: five single-thread known-answer cases, three assembled
  fixtures, two rejected memory forms, and MASKMOVDQU as the refused
  SSE2 instruction in cpu_features.rs now that MFENCE runs.

No multi-thread behaviour is established.

Signed-off-by: sahib453 <117431595+sahib453@users.noreply.github.com>
2026-11-25 00:25:27 +05:30
sahib453 403a67747f loader: set only the overflow flag for an exact unmasked overflow (#128)
With the overflow exception unmasked, an overflow whose result is exact
before the exponent is bounded set the MXCSR precision flag as well as
the overflow flag. The Intel SDM (Vol. 1, D.4.2.3, Table D-16) reports
precision there only if rounding with an unbounded exponent is inexact.

- softfloat.rs: Control reads the overflow mask, and round() reports
  precision on an unmasked overflow only when the result was rounded.
  The masked response is unchanged.
- cpu_known_answers.rs: the five exact-overflow cases are no longer an
  ignored defect, three more cover the other rounding modes, and the
  scalar and conversion sweeps now compare the precision flag here.
- docs/cpu/instruction-registry.md: the behaviour is no longer listed
  as unasserted.

Signed-off-by: sahib453 <117431595+sahib453@users.noreply.github.com>
2026-11-24 23:25:07 +05:30
zachdoxsee 314d1f5874 loader: add MOVS, STOS, REP and the direction flag (#129)
Declare MOVS and STOS for 8- to 64-bit elements through a new string
encoding that accepts REP, and add the direction flag with CLD and STD.

A REP form runs one element per step and stays on the instruction until
RCX is zero. Every element therefore counts against the step budget, a
repeat can stop part-way and resume, and a fault keeps the elements
already done. FS and GS apply to the MOVS source only. Both engines use
the shared semantics; there is no bulk-copy path.

Fourteen SDM-derived cases already in cpu_known_answers.rs move from
refused to verified, and ten more are now refused at their second
instruction because CLD runs. tests/cpu_rep.rs adds a byte-array model
over every form, direction and count.

Signed-off-by: zachdoxsee <zachdoxsee36@gmail.com>
2026-11-24 17:14:46 +01:00
zachdoxsee da16b36499 loader: add CPUID with a truthful guest feature contract (#130)
CPUID returns a fixed table that never reads the host: a synthetic
vendor, and a feature bit only when every instruction of that feature
is implemented. Today that is CMOV, POPCNT, LZCNT and long mode. SSE
and SSE2 stay unreported while parts of them are rejected. Unlisted
leaves return zeros.

tests/cpu_features.rs pins every leaf in both engines, requires each
reported feature's instruction set among the executed fixtures, and
holds a refused witness instruction for each unreported feature, so a
bit cannot be set early or forgotten later.

Signed-off-by: zachdoxsee <zachdoxsee36@gmail.com>
2026-11-24 16:59:50 +01:00
zachdoxsee 3a3f0c52af loader: add XADD, CMPXCHG and LOCK on their memory forms (#198)
Declare XADD and CMPXCHG in the instruction registry for 8- to 64-bit
register and memory destinations. The LOCK prefix is accepted on the
forms the registry marks lockable and only with a memory destination;
every other use stays an illegal instruction.

Both engines run the new forms on the shared semantics. A failed
CMPXCHG still writes its destination, so it faults on memory that
cannot be written, and a fault changes nothing. The registry document
states the ordering, alignment, compare-failure and fault rules a guest
scheduler has to preserve. Nothing is lowered to ARM64 atomics.

Fourteen SDM-derived cases already in cpu_known_answers.rs move from
refused to verified. Adds 62 LLVM-assembled fixtures with reference
arms, generator checks for the lock key and tests/x86_atomic.rs.

Signed-off-by: zachdoxsee <zachdoxsee36@gmail.com>
2026-11-24 16:46:01 +01:00
jelly013 42825b223b Merge upstream main (#280, #281, #282, #283) into CPU/runtime continuation
Keep every upstream test and the new assembler forms. Keep the shared
decoder and lowering, which already cover the merged MOVZX, MOVSX and
segment fixes, and adopt upstream's rule that GS applies when FS and GS
overrides are combined. Add segment regressions for RIP-relative operands,
negative displacements and fault addresses in both engines.

Signed-off-by: jelly013 <22855910+jelly013@users.noreply.github.com>
2026-11-24 13:33:18 +01:00
jelly013 4f4d977807 cpu: add exact SSE and SSE2 floating point
Add the scalar and packed binary32 and binary64 arithmetic, compares and
conversions, computed exactly and rounded once in software. Follow MXCSR
rounding, sticky flags, denormals-are-zero, flush-to-zero, tininess after
rounding and x86 NaN selection. Stop on unmasked exceptions without a
result. Host floating point is not used, and no form is lowered to NEON.

Verify 6,824 vectors computed with exact fractions by an independent Python
reference in both engines, and round-to-nearest results against the host.
List the behaviour that is implemented but left unasserted.

Refs #127, #128

Signed-off-by: jelly013 <22855910+jelly013@users.noreply.github.com>
2026-11-24 13:11:07 +01:00
jelly013 dce37dab18 cpu: add SSE2 state, moves and packed integer forms
Add XMM0-XMM15 and MXCSR to the guest state and extend the registry with
mandatory prefixes, so the shared decoder covers the SSE and SSE2 moves and
packed integer operations. Reject opcodes where 0x66 could be both an
operand size and a mandatory prefix.

Translate operations with identical NEON lane semantics to ARM64; other
forms call the shared semantics and are counted. Raise a distinct
general-protection exit for misaligned 16-byte operands and reserved MXCSR
bits. Floating-point arithmetic is not implemented.

Verify 374 LLVM-assembled instructions against a byte-array reference that
reads only their assembly text, and mixed sequences between the engines.

Refs #124, #125, #126, #128

Signed-off-by: jelly013 <22855910+jelly013@users.noreply.github.com>
2026-11-24 12:53:35 +01:00
jelly013 02f9ad9a34 cpu: share one generated decoder and store guest flags
Add a declarative x86-64 instruction registry with a validating generator,
and decode through its tables in the static probe, the interpreter and the
native DBT. Move integer semantics into shared reviewed primitives and
extend them to 8-, 16-, 32- and 64-bit register and memory operands.

Store all six arithmetic flags in the guest state so they survive helper
calls and block boundaries, and correct unsigned branch conditions. Lower
common forms to ARM64; other forms call the shared semantics and are
counted. Report probe support from the decoder that executes.

Verify 985 LLVM-assembled instructions against a bit-level reference that
reads only their assembly text, and random sequences between the engines.

Refs #64, #65, #66, #68, #70, #71, #73, #118, #119, #120, #121, #122,

Signed-off-by: jelly013 <22855910+jelly013@users.noreply.github.com>
#123, #194, #195, #196
2026-11-24 12:36:52 +01:00