# Undocumented, unpredictable and contested behaviour Two lists. **U-items** are behaviours ARM's documents leave out, call "unpredictable" or say "must not be used", that real code or the test ROMs reach anyway; each says what the core does and on what evidence. **C-items** are places where two sources disagree; each says which wins and why, or that the user decided (handoff-brief.md "Decided by the user"). Evidence tags as in the family methodology: **DOC** (ARM's data sheet DS and TRM, GBATEK), **TEST ROM** (a test ROM whose author ran it on a GBA or Game Boy Player and says so; evidence only for the cases it tests), **OBSERVED** (another implementation run as a closed box: the SingleStepTests ARM7TDMI corpus, MIT, generated by its author from a NanoBoyAdvance fork and used here as data; NanoBoyAdvance 1.8.3 and mGBA `fd9dc5c` run through the drivers in `referees/`), **HYPOTHESIS** (a reasoned default, with what would settle it). No emulator's source was read to write these rules (docs/provenance.md, "Wave 2"); where a rule rests only on OBSERVED evidence it says so, because the GBA's hardware may differ. ## U-items **U1. Misaligned word loads rotate.** `LDR` from an address with bits 1:0 set drives that address with width 32; the memory returns the aligned word; the core rotates it right by `8 × (address & 3)`. `SWP` does the same for its read and writes Rm unrotated. (DOC: DS 4.9.3; GBATEK "ARM CPU Memory Alignments". OBSERVED: the corpus's 8,972 + 8,884 misaligned single transfers and 17,382 in `arm_swp` agree.) **U2. Misaligned halfword loads.** `LDRH` from an odd address reads the aligned halfword and rotates the 32-bit result right by 8 (bits 7:0 land in 31:24). `LDRSH` from an odd address returns the **sign-extended byte** at that address (DOC: GBATEK; TEST ROM: jsmolka `halfword_transfer`, tests 400–449; DS 4.10.4 calls it unpredictable). The corpus agrees on the value; its bus width is C4. **U3. Misaligned stores and block transfers drive the address as computed.** `STR`, `STRH`, `STM`, `LDM` with unaligned addresses: the core puts the unaligned address on the bus; the GBA's memory ignores the low bits (DOC: GBATEK "forced align"). The core never aligns a data address; the corpus records the unaligned addresses (140,198 in `arm_ldm_stm`, 169,064 in `thumb_push_pop`). For LDM/STM the address increments by 4 from the unaligned start. **U4. Empty register list.** `LDM`/`STM` with list 0 transfer R15 only, and the base moves as if 16 registers were transferred (±0x40); for decrementing modes the single transfer happens at the lowest address the 16-register form would use (base − 0x40 for DB, base − 0x3C for DA). Thumb `LDMIA`/`STMIA`/`PUSH`/`POP` with an empty list behave the same (R15, ±0x40). (DOC: GBATEK "Strange Effects on Invalid Rlist's"; TEST ROM: jsmolka `block_transfer`, alyosha-tas `thumb/Push_no_regs`; OBSERVED: corpus. The DS says nothing.) alyosha-tas `thumb/Pop_no_regs` also checks the instruction's time with a timer, which the minimal harness cannot run (rung 5). **U5. STM with the base in the list and write-back.** If the base is the **first** (lowest) register in the list, the old base is stored; otherwise the new (written-back) base is stored: write-back happens after the first transfer (DOC: DS 4.11.6, GBATEK "Writeback with Rb included in Rlist"). **U6. Loads and write-back to the same register.** `LDM` with the base in the list and write-back: the loaded value wins (DOC: GBATEK, "no writeback (LDM/ARMv4)"). `LDR`/`LDRH`/... with Rn = Rd and write-back (or post-indexed): the loaded value wins. `STR` with Rn = Rd and write-back stores the old value. (TEST ROM: jsmolka `single_transfer`; the DS says "must not".) **U7. LDM/STM with the S bit (`^`).** Without PC in an LDM list, or for any STM, the transfer uses the User-bank registers (DOC: DS 4.11.4). With PC in an LDM list, it is a normal load plus CPSR ← SPSR after the transfer. Write-back with `^` is "should not be used" (GBATEK); the core writes the base back to the **User bank's** Rn, as the corpus does in every such case (OBSERVED). **The LDM^ glitch.** alyosha-tas's `LDM/ReadMe.txt` (TEST ROM, "personally tested on GBP"; "may not work on all models"): "When LDM to user mode registers, the next register access uses the OR'd value of the user mode and banked register if it exists." GBATEK's caution says the same in weaker words. The core's rule, fitted to the eight `LDM_*` ROMs (all pass in the minimal harness, `tests/test_roms.py`): in the instruction after a User-bank LDM, the register reads the instruction makes **in its first cycle** return a banked register OR'd with the User bank's copy; reads in later cycles, and all writes, see only the current mode's register. Which reads fall in the first cycle is the ROMs' evidence, consistent with the TRM's cycle tables: Rn and Rm of a data-processing or single-transfer instruction (Rs alone for a register-specified shift, whose Rn and Rm come a cycle later), the base of LDM/STM and SWP, BX's Rm, MUL's Rm and Rs, MLA's Rn, and RdHi:RdLo of UMLAL/SMLAL (their Rm and Rs come a cycle later). Store data (STR's Rd, STM's registers, SWP's Rm) is read after the first cycle. The ROMs test FIQ mode; the core applies the rule to every mode with banked registers (HYPOTHESIS for the others). The window does not survive a save state (not in `CPUState`). **U8. Storing R15.** `STR PC` and `STM` with PC in the list store the instruction's address plus 12 (ARM) (DOC: DS 4.9.4, 4.11.1). **U9. R15 as an operand with a register-specified shift** reads the instruction's address plus 12 (DOC: DS 4.5.5): the extra cycle has advanced the PC. Rs = R15 is "must not"; there it reads **plus 8**, because Rs is read in the first cycle, before the PC advances (OBSERVED: the corpus's 1,591 executed `arm_data_proc_register_shift` cases with Rs = R15 agree only with plus 8). **U10. Shifter edge cases** (DOC: DS 4.5.2): immediate `LSR #0` and `ASR #0` mean 32; `ROR #0` means RRX. Register amounts use Rs's low byte: 0 leaves the value and C unchanged; LSL/LSR by 32 give 0 with C = bit 0 / bit 31; by more than 32 give 0 with C = 0; ASR by 32 or more fills with bit 31 and C = bit 31; ROR by a non-zero multiple of 32 leaves the value and sets C = bit 31. Logical operations set C from the shifter only when the shift amount is non-zero (GBATEK). TEST ROM: jsmolka `shifts`, mGBA suite `shifter` (hardware-captured); OBSERVED: the corpus's 150,000 data-processing cases. **U11. Multiply flags and early termination.** MULS/MLAS/…S set N and Z; V is unaffected; **C is "meaningless" per ARM but deterministic**: zayd's Booth-multiplier model (bmchtech post 2024-10-22, `multiplication-algorithm`, zlib) derives it from the multiplier array's last carry and was fuzzed against a GBA. The core's `booth_multiply` is that model transcribed (with its zlib notice, NOTICE), and rung 4 judges the core against the model's own C code (7,000,000 cases). `scripts/multiply_model.py` runs the model on every executed multiply in the corpus (53,446): results agree in all 47,382 whose destination is not R15 or doubled, and the C flag in all 28,508 S forms. The cycle count `m` is the TRM's rule (timing.md), and the model's iteration count equals it in all 53,446. TEST ROM: mGBA suite `multiply-long` (hardware-captured). **U12. Multiply register restrictions.** Rd = Rm and R15 as any operand are "must not" (DS 4.7.1). The core computes with the values as read. **R15 as an operand reads the instruction's address + 12** (MLA's Rn too, although it is read in the first cycle): OBSERVED only, the corpus's cases with R15 operands agree with nothing else (752 MLA cases fail with + 8 for Rn). A write to R15 refills (OBSERVED, corpus). No hardware evidence. **U13. Data processing with S and Rd = R15.** CPSR ← SPSR of the current mode (DOC: DS 4.5.4). In User or System mode there is no SPSR: the core reads the CPSR there, so the CPSR is unchanged (HYPOTHESIS; OBSERVED, the corpus agrees). `TST`/`TEQ`/`CMP`/`CMN` with Rd = 15 (the ARMv2 "P" forms) are test operations whose result is not written, and they also restore the CPSR (OBSERVED, corpus). No hardware evidence. **U14. Setting I or F acts one instruction late; clearing it acts at once.** The core samples the interrupt lines at the end of each instruction (DOC: TRM 2.8.4–2.8.5, "checks for a LOW level on the output of the FIQ synchronizer at the end of each instruction" when the flag is clear). A line is masked only if its bit was set both when that instruction **started** and when it **ended**. So `MSR CPSR_c, #0x92` that sets I still lets an IRQ asserted during it be taken after it (TEST ROM: alyosha-tas `psr`, "timing of disabling interrupts when disabling via S bit set", run on a GBA Player; judged on gba-python's board, it fails with masks sampled only at the end), and an instruction that clears I (`MSR`, or `SUBS PC, LR, #4` restoring a CPSR with I clear) lets a pending IRQ in right after it (TEST ROM: alyosha-tas `irq/IRQ_sub` and `irq/IRQ_sub_slow` with Nintendo's BIOS, whose IRQ return at 0x138 ends in `SUBS PC, LR, #4` with the next IRQ pending: both pass with this rule and fail, r12 = 251 and 244, when clearing also acts one instruction late; gba-python 2026-11-23). The reset core of 2026-11-19 had clearing act late too; that cost the mGBA suite's "Timer count-up" table 224 of its 936 cases (not hardware-calibrated, owner's ruling; recorded, not used as the judge). F follows I by analogy (HYPOTHESIS: the GBA has no FIQ source to test it). **U15. Mode bits.** Bit 4 of the mode field reads 1 after any MSR that writes the control field (TEST ROM: alyosha-tas `psr` ReadMe, "upper bit of mode value is always set"; the corpus agrees, OBSERVED). A mode value that names none of the seven modes (DS 3.7: "unpredictable state") has no SPSR and banks R8–R14 as User mode does (HYPOTHESIS; OBSERVED, every corpus case in such a mode passes with it). **U16. PSR transfers.** MSR writes the fields named by its four mask bits (`c` = 7–0, `x` = 15–8, `s` = 23–16, `f` = 31–24); in User mode only `f` (DOC: DS 4.6 names the control and flag fields; OBSERVED: the corpus writes `s` and `x` too). MSR to SPSR in User or System mode is ignored, and MRS of SPSR there returns the CPSR (TEST ROM: alyosha-tas `psr`, "reading / writing spsr in modes without an spsr"; OBSERVED: corpus). MSR can set T, and the next fetch is then a halfword at PC (OBSERVED: 2,386 corpus cases change T through `arm_msr_reg`; "must never" per the DS). Reserved bits 27–8 keep what MSR writes (OBSERVED: corpus); the silicon is untested here. *Still open: what executes after an MSR that sets T.* MSR does not refill, so the pipeline still holds the two ARM words prefetched at the MSR's address + 4 and + 8, and the next two Thumb steps decode them. ARM's documents only forbid it: "the software must never change the state of the T bit in the CPSR. If this happens, the processor will enter an unpredictable state" (DS 3.8, again in DS 4.6), "Never use an MSR instruction to force a change to the state of the T bit in the CPSR" (TRM 2.7.2, Caution). The corpus judges only the MSR itself, one instruction per case. Until 2026-11-25 the core raised `IndexError` on the next step (a 32-bit word indexing the Thumb table; found by arm7tdmi-rust's rung 5). **Build (HYPOTHESIS):** the Thumb decoder takes bits 15:0 of each held word, the halfword a Thumb fetch at that word's address would have taken from the bus: ARM fetches are at A[1:0] = 00, and a halfword read there takes D[15:0] with BIGEND = 0 (TRM 3.6.4, table 3-7; the GBA is little-endian). So after `MSR` at *a*: the low halfwords of the words at *a* + 4 and *a* + 8, then halfword fetches from R15 = *a* + 12 on, as the corpus shows (`tests/test_msr_thumb.py`). Other readings that would also not crash: the high halfword, or a refill at the MSR's PC + 4. A GBA test ROM that sets T with MSR in front of distinguishable halfwords and reports which ran (on hardware) would settle it. **U17. CP14 exists.** The ARM7TDMI has an internal coprocessor 14 for the debug communications channel (DOC: TRM 4.6, "The internal coprocessor, CP14, can still be used"). On the GBA, `MRC p14` and `MCR p14` **do not trap** (TEST ROM: alyosha-tas `arm/Coprocessor_14`): MRC returns the value on the data bus, which is the opcode the instruction's own cycle-1 fetch brought in (`pc+8`); `MRC p14, …, R15` sets N, Z, C, V from bits 31–28 of that value (DS 4.16; the test checks N); MCR has no visible effect; the instruction's time matches a timer value the test checks (0x75). CDP/LDC/STC to CP14 still trap (HYPOTHESIS; the test's comment says "all others besides MRC / MCR are undef"; OBSERVED: corpus). **U18. Thumb BL halves are two instructions.** The first half writes LR ← PC + 4 + (offset_hi << 12) and is an ordinary one-cycle instruction (an interrupt can come between the halves). The second writes PC ← LR + (offset_lo << 1) and LR ← (address of the second half + 2) | 1. A second half without a first uses whatever LR holds; a first half alone leaves LR changed. (DOC: DS 5.19.1; OBSERVED: the corpus tests the halves separately, `thumb_bl_blx_prefix`, `thumb_bl_suffix`.) **U19. Reserved encodings that execute.** ARM condition `1111` ("reserved, must not be used", DS 4.2; ARMv4's "never"): the core never executes it, so it costs one S cycle (OBSERVED: corpus). ARMv5 reused the space for BLX/PLD, so no GBA software uses it. Thumb format 5 with H1 = H2 = 0 (`ADD/CMP/MOV` of two low registers through the hi-register encoding, "undefined" in DS 5.5.1) runs as the operation on the low registers (TEST ROM: alyosha-tas `thumb/cpy`, `0x460A` moves R1 to R2; OBSERVED: 12,548 corpus cases in `thumb_add_cmp_mov_hi`). Thumb `BX` with H1 = 1 (`0x4780`, ARMv5's `BLX Rm`; "undefined" in DS 5.5.3) is a plain BX, LR unchanged (TEST ROM: alyosha-tas `thumb/blx`; OBSERVED: 25,102 corpus cases in `thumb_bx`). **U20. The low bits of R15 after a write.** A write of a value with its low bits set into R15 (a data-processing or load write, BX to ARM with bit 1 set, Thumb POP of an empty list) keeps those bits in R15 (final R15 = value + 2L) while the refill fetches drop them (C3); the next Thumb instruction clears bit 0, and Thumb `POP {PC}` clears it at once (OBSERVED only: every such corpus case; GBATEK says R15 is "forcibly aligned", C9). Which value a following `ADD Rx, PC, #0` sees is untested. **U21. The ARMv5 LDRD/STRD encodings** (halfword space, L = 0, SH = 10 or 11). Unpredictable on ARMv4T; no ARM document gives a cycle table, GBATEK says only "ARMv5TE and up", and the corpus has no such case. OBSERVED only, by running NanoBoyAdvance 1.8.3 closed box on 98 cases made from the corpus's STRH cases with bits 6:5 patched (2026-11-19): no bus access; two internal cycles for LDRD, one for STRD; registers as STRH leaves them (the base written back), less the store. The core does the same, its internal cycles at pc+12. No hardware evidence; a test ROM would settle it. ## C-items **C1. Merged IS: the fetch after an I cycle.** TRM: S (3.3.4, every table with an I cycle followed by a fetch). OBSERVED: NanoBoyAdvance, mGBA and the corpus time it as N (the corpus records `access` = N|code as the next-fetch type after every load, multiply, register shift and swap). Both are right about different things: the core drives SEQ high, the GBA's memory controller starts a new access anyway; emulators that time it as N pass the mGBA suite's hardware-captured `timing` tests. *Resolution:* the core reports S (the pin), the board converts with `gba_access` (user decision 1). **C2. Write-back to R15.** `LDR`/`STR`/`LDRH`/`STRH`/`LDM`/`STM` with Rn = R15 and write-back ("must not", DS 4.9, 4.11). The corpus treats the written-back R15 as a branch and refills (two extra code fetches); NanoBoyAdvance run closed box writes R15 without refilling (OBSERVED, `scripts/referee_sst.py`). 5,112 corpus cases (2,186 stores, 2,926 loads). The corpus README lists this as its known issue ("may not have perfectly correct behavior"). No hardware evidence; no GBA software does it. *Resolution:* neither side wins. The core refills (every other write to R15 does), and the cases are **excluded from the rung-1 gate** as unverified until a hardware test exists. **C3. Refill fetch addresses after a misaligned PC write.** After `BX` to an ARM address with bit 1 set, or a data-processing/load write of an ARM PC with bits 1:0 set, or a Thumb PC with bit 0 set through paths that do not use it as the state bit: the corpus fetches at the address with the low bits cleared; NanoBoyAdvance run closed box fetches at the raw address (OBSERVED; the GBA bus aligns it, so its GBA timing is unaffected). 33,087 corpus cases, the largest class. *Resolution:* follow the corpus: drive fetch addresses with the bits cleared. It is the only source with an opinion about the pins, and the GBA cannot tell the two apart. **C4. LDRSH from an odd address: bus width.** Same value everywhere (U2). The corpus reads with width 16 at the odd address and sign-extends bits 15:8 of the halfword; NanoBoyAdvance run closed box reads with width 8 (OBSERVED). 17,145 corpus cases (6,132 ARM, 11,013 Thumb). On the GBA the width matters only to 8-bit-bus SRAM, whose reads of any width return one byte. *Resolution:* width 16, as the instruction's MAS encodes (TRM table 6-9: "s represents the size of the data transfer"), which is the corpus's. **C5. The undefined-instruction trap's I cycle.** TRM table 6-21: S, I, N, S (2S+N+I). OBSERVED: NanoBoyAdvance and the corpus: S, N, S. The corpus cannot show I cycles, so this is a closed-box emulator against the TRM. *Resolution:* the TRM (user decision 5); a board-level timing test can settle it. **C6. CP14 MRC/MCR.** Corpus: undefined trap (1,500 executed corpus cases with coprocessor number 14 in `arm_mcr_mrc`, out of 25,094 executed MCR/MRC cases). TEST ROM (alyosha-tas `Coprocessor_14`): no trap (U17). The test exercises four encodings: `MRC p14,0,Rd,c0,c0,0`, `MRC p14,0,Rd,c1,c0,0`, `MRC p14,0,R15,c1,c0,0` (flags), and `MCR p14,0,R1,c1,c0,0` ("shouldn't crash"). *Resolution:* hardware for corpus cases with those encodings (expected values from the test's observed behaviour); every other CP14 case is **excluded as unverified**. Generating expected values for all 1,500 by the core's own rule would test the core against itself (user decision 3). **C7. Thumb conditional branch with condition `1110`** (`0xDE00`–`0xDEFF`). DS 5.16 and GBATEK: "undefined, should not be used". OBSERVED: the corpus (`thumb_undefined_bcc`, 50,000 cases) and NanoBoyAdvance 1.8.3 run closed box branch (always taken, no trap); mGBA `fd9dc5c` run closed box takes the undefined trap (`tests/hw/thumb_undefined/README.md`, "What the referees showed"); ares (ISC) takes it too. A **dispute between emulators**, and the corpus is one side of it. No hardware evidence. *Resolution:* the undefined trap, provisionally; the corpus file is excluded until the hardware test ROM in `tests/hw/thumb_undefined/` is run on a GBA (user decision 4). **C8. Thumb `0xE800`–`0xEFFF`** (ARMv5's BLX suffix). Not an ARMv4T encoding; ARM's rule for undefined Thumb encodings is the undefined trap. OBSERVED: NanoBoyAdvance and mGBA run closed box differ from each other and from the trap on parts of the range (the same README); ares traps all of it. Not in the corpus. *Resolution:* the undefined trap for both ranges, provisionally, until the hardware test ROM decides (user decision 4). **C9. Is R15 aligned after a misaligned write?** GBATEK: yes ("R15 will be always forcibly aligned"). Corpus: no (U20). Single-instruction tests cannot show which value the next instruction reads. *Resolution:* follow the corpus for rung 1; write a harness test that reads PC after such a write once a hardware result exists. **C10. LOCK on SWP's read.** TRM table 6-14: LOCK high in both the read and the write cycle. OBSERVED: the corpus and NanoBoyAdvance mark only the write. The GBA does not use LOCK as far as is known (its DMA arbitration is the board's). *Resolution:* the TRM; the rung-1 comparison ignores LOCK on the read. **C11. Thumb POP and LDMIA with an empty list: an I cycle before the refill?** Both load R15 alone (U4). TRM table 6-12 (every LDM that loads R15): S, N, I, then the refill; the core follows it. OBSERVED: NanoBoyAdvance run closed box makes that I cycle for the ARM form and not for the Thumb forms (`scripts/referee_icycles.py`, 156 cases). The corpus cannot see I cycles. *Resolution:* the TRM, as for the ARM form; alyosha-tas `thumb/Pop_no_regs` checks the instruction's time on a Game Boy Player (timer 0x16) and decides it at rung 5. ## Open items - No die-level or netlist model of the ARM7TDMI exists in public (searched 2026-10-21: one die photo listing, no netlist, no Verilog traced from silicon). The open ARMv4T HDL cores are reimplementations, not traces. Hardware-captured evidence is therefore test ROMs run on GBAs, and ARM's own documents. - There is no GBA hardware on hand. Behaviours resting only on closed-box emulator measurements (OBSERVED, no TEST ROM or DOC): U7's write-back to the User bank, U9's Rs = R15, U12, U13's P forms and User-mode SPSR, U15's invalid modes, U16's `s`/`x` fields, T and reserved bits, U17's CDP/LDC/STC to CP14, U19's NV, U20, U21, C2–C4, C9, C10. - Resting on a HYPOTHESIS alone (no evidence of any tier): U16's decode of the ARM words an MSR that sets T leaves in the pipeline (bits 15:0, 2026-11-25). - The corpus stores every bank whatever the mode (validation.md "The corpus's state layout"), so mode switches are fully judged; but each case is one instruction, so nothing that spans instructions (U7's glitch, U14, U18 across an interrupt, C9) is in it.