# The instruction set: ARMv5TE as the ARM946E-S implements it The architecture is ARMv5TE (Main ID 41059461h: implementor 41h ARM, architecture 5 = v5TE, part 946h, revision 1; DDI 0201D table 2-3 and GBATEK "ARM CP15 ID Codes", which gives the same value read on an NDS9). The semantics reference is the ARM Architecture Reference Manual (DDI 0100E, the v5TE-era edition; DDI 0100I where it clarifies a v5TE rule): its pseudo-code is the handler specification, cited by section. GBATEK's ARM chapters are a second, DS-specific reading (no$gba's author tested on a DS). Everything below is **DOC** unless tagged otherwise; nothing has a hardware-tier judge yet except where a test ROM is named. The ARMv4T base (data processing, the barrel shifter, PSR transfer, LDR/STR and the halfword forms, LDM/STM, SWP, SWI, coprocessor transfers, the whole Thumb set) is the same architecture arm7tdmi-python specifies; this core writes it again from the ARM ARM (core-choice.md) and checks its own corners rather than inheriting them. ## New instructions (v5T and the E extension) | Instruction | Encoding (ARM) | What it does | Flags | Timing (DDI 0165B table 8-2) | | --- | --- | --- | --- | --- | | CLZ Rd, Rm | `cond 0001 0110 1111 Rd 1111 0001 Rm` | count leading zeros, 0-32 | none | 1 | | QADD / QSUB Rd, Rm, Rn | `cond 0001 0op0 Rn Rd 0000 0101 Rm` | signed saturating add / subtract | Q set on saturation (sticky), NZCV unchanged | 1, +1 if the next instruction uses Rd | | QDADD / QDSUB | same, op with bit 22 set | Rm +/- sat(2 x Rn): the doubling saturates first and sets Q itself | Q | as QADD | | SMULxy, SMLAxy | `cond 0001 0110 / 0000 ... 1yx0` | 16 x 16 signed, x/y choose halves; SMLA adds Ra | SMLA sets Q on accumulate overflow (no saturation) | 1, +1 interlock | | SMULWy, SMLAWy | `cond 0001 0010 ... 1y10 / 1y00` | 32 x 16 signed, top 32 of the 48-bit product | SMLAW sets Q on accumulate overflow | 1, +1 interlock | | SMLALxy | `cond 0001 0100 ...` | 16 x 16 signed into a 64-bit accumulator | none | 2, +1 interlock | | LDRD / STRD | halfword-transfer space, bits 7:4 = 1101 / 1111 with L=0 | two words into Rd (even), Rd+1 | | LDRD 2 (+1), STRD 2 | | PLD | `1111 01x1 x101 Rn 1111 ...` | preload hint | | 1 (DnSPEC asserted) | | MCRR / MRRC | `cond 1100 010L ...` | two registers to / from a coprocessor | | b+2 | | BLX label | `1111 101H imm24` | branch with link to Thumb, H gives bit 1 | | 3 | | BLX Rm | `cond 0001 0010 1111 1111 1111 0011 Rm` | branch with link and exchange | | 3 | | BKPT | `1110 0001 0010 imm12 0111 imm4` | prefetch abort (debug disabled) | | | | CDP2, LDC2, STC2, MCR2, MRC2 | the cond=1111 forms | coprocessor operations without a condition | | as the conditional forms | | Thumb BLX (both), BKPT | `0100 0111 1 Rm 000`; the BL suffix with bit 12 clear | | | | The DS has no coprocessor but CP15, so MCRR/MRRC and every CP0-CP14 operation reach an absent coprocessor and take the undefined-instruction trap (DDI 0165B "Coprocessor absent", b+4 cycles). CP15 accepts only MCR/MRC with opcode_1 = 0 (and the BIST and cache debug registers with other opcode_1 values); CDP, LDC and STC to CP15 are undefined (GBATEK "ARM CP15 Overview"). U4 asks what MCR2/MRC2 to CP15 do. ## Rules that change for ARMv4 instructions | Behaviour | ARM7TDMI (v4T) | ARM946E-S (v5TE) | Source | | --- | --- | --- | --- | | LDR, LDM, Thumb POP into R15 | T unchanged (bit 0 ignored) | T = bit 0 of the loaded value, unless CP15 control bit 15 ("disable loading TBIT") is set | DDI 0201D 2.3.5 bit 15; GBATEK; rockwrestler's ARMv5 group (TEST ROM) | | MUL / MLA / long multiplies with S | C flag "meaningless" | C unchanged | GBATEK "ARM CPU Versions"; ARM ARM | | Multiply timing | early termination on the multiplier's top bytes | fixed (table above); MULS 4 cycles, xMULLS 5 | DDI 0165B table 8-2; GBATEK "DS Memory Timings" | | LDM with Rn in the list and writeback | no writeback | writeback if Rn is the only register or not the last | GBATEK "Block Data Transfer"; rockwrestler LDM/STM edge cases (TEST ROM) | | STM with Rn in the list and writeback | old base only if Rn is first, else the new base | always the old base | same | | Empty register list | R15 transferred, base +/- 40h | nothing transferred, base +/- 40h | GBATEK (U2: whether any bus cycle happens) | | LDRH at an odd address | aligned halfword rotated by 8 | address forced even | GBATEK "ARM CPU Memory Alignments" | | LDRSH at an odd address | sign-extended **byte** | address forced even, halfword sign-extended | same | | Data abort | base updated | base restored | DDI 0165B 2.9.7, DDI 0201D 2.2.1 (the DS's PU raises data aborts; the DS bus never asserts an external abort: U3) | | cond = 1111 | "never" / unpredictable | the unconditional space (BLX, PLD, the `*2` coprocessor forms); others undefined | ARM ARM | | Thumb BL suffix with bit 12 clear | (ARMv4T: undefined) | BLX to ARM | ARM ARM | | Thumb `ADD/MOV/CMP Hi` with both registers low | unpredictable | unpredictable (not defined by v5TE either: U5) | ARM ARM | ## The DS-specific corners already known - **R15 reads**: address + 8 (ARM) / + 4 (Thumb), as on every ARM; the five-stage pipeline does not show through (DDI 0165B 2.7). - **Unaligned LDR and SWP rotate**, as on the ARM7 (GBATEK). LDRD/STRD: GBATEK says the DS accepts a 4-aligned address ("align-4 seems to be okay"); the ARM ARM calls an address not 8-aligned unpredictable. C2 below. - **Wait for interrupt** is a CP15 write (c7,c0,4; the second encoding is c15,c8,2 by DDI 0201D, c7,c8,2 by GBATEK: cp15-tcm-pu-caches.md C2), not an instruction; the DS BIOS's Halt uses it (GBATEK "BIOS Halt Functions", and the board's HALTCNT is ARM7-only). - **Exception vectors** at FFFF0000h when CP15 control bit 13 is set; the DS BIOS sets it (OBSERVED: MAME's run of the DS BIOS writes 00002078h to the control register first, mame-oracle.md), and the reset vector is FFFF0000h, so the VINITHI pin is high at reset (OBSERVED in the same trace, its first line). ## Unknowns (U) and contradictions (C) - U1 What an LDRD/STRD with an odd Rd, or Rd = R14, does on this core (ARM ARM: unpredictable). Test: a probe ROM (probe batching). - U2 Empty-list LDM/STM: whether any data-bus cycle happens, and what the cycle count is. - U3 Whether anything on the DS asserts the ARM9's external abort (GBATEK says nothing). Default: no; only the PU's permission faults abort. - U4 MCR2/MRC2 with CP15 as target: undefined, or treated as MCR/MRC? - U5 Thumb hi-register operations with two low registers on the ARM9. - U6 SMLAxy and SMLAWy saturation: the ARM ARM says Q is set and the result wraps; check with rockwrestler's DSP-multiply group, which prints per-case verdicts. - U7 What the CP15 control register reads at reset on a DS before the BIOS writes it (INITRAM and VINITHI pin states; the ITCM-enable bit takes INITRAM's value, DDI 0201D bit 18). - C1 GBATEK's generic CP15 control-register list names bit 1 "alignment fault check" and bit 15 "pre-ARMv5 mode"; DDI 0201D table 2-9 has bit 1 reserved (SBZ) and bit 15 "disable loading TBIT". GBATEK's NDS-specific line (bits 0, 2, 7, 12-19 R/W; 3-6 set) agrees with the TRM. Judge: a read-back probe; follow the TRM meanwhile. - C2 LDRD/STRD alignment: the ARM ARM (8-byte, else unpredictable) against GBATEK (4 is fine on the NDS). Follow GBATEK (a DS observation) and tag it DOC.