The generator had not been able to run correctly since the manual moved into
`tools/ppc-manual/`: it computed the repository root as `HERE.parent.parent`,
which now names `tools/`, so the XML, Canary's emitters and xenia-rs all stopped
resolving — silently, because both scrapers skipped what they could not find.
Every page's references had been pointing at paths that exist nowhere.
What each source contributed, measured on the 350 pages before this change:
Operation (pseudocode) 251 pages: fixed boilerplate "derives from the xenia-rs
interpreter"; 99 carry real hand-written seeds
C translation 337 pages: the same kind of boilerplate
xenia-rs snapshot 336 pages: the interpreter arm, pasted in — the only
per-instruction semantics on unseeded pages
links xenia-rs opcode/decoder/interpreter + Canary emitter
Now:
* semantics come from **Xenia Canary**, the reference emulator, read through
`git show` at a pinned upstream commit (`origin/canary_experimental`,
f21ebd49e9). Not our checkout: it carries instrumentation and lacked
upstream's `mcrf` fix, so it would have published probes and a wrong `mcrf`.
Each page embeds the emitter (`InstrEmit_<mnem>`), and for the 128 pure
one-line delegations also the helper that holds the semantics.
* decode references point at `crates/sylpheed-ppc` — the decoder that
produces `sylpheed.db` — as in-repo relative links.
* the boilerplate now says what is true, and the C translation guide maps
Canary's actual HIR calls, checked against `ppc_hir_builder.h` (including
that `UpdateCR(n, v)` truncates to 32 bits).
* `rust_scraper.py` -> `decoder_scraper.py` (interpreter half dropped);
missing sources are now errors, not empty results.
Verified:
consistency checks 455 XML entries, 350 families, 598 index keys
hand-written tails 386/386 byte-identical after regeneration
xenia-rs in generated 0
pages with a snapshot 349/350 (was 336) — `dcbi` has no Canary emitter at all
in-repo decoder links 910/910 resolve to a line holding the identifier
emitter boundaries brace counter == column-0 `}` rule on 521/521;
preprocessor model unit-tested (#if 0/#else/#elif)
idempotency re-run: 0 pages updated, 0 working-tree changes
Hand-written notes (outside the generated regions) are not rewritten here:
* 110 links into `../../xenia-rs/...` were dead; they now point at the file in
the archived repository (git.mc02.dev/fabi/xenia-rs @ 8401d4d). Line anchors
were dropped because the notes predate that commit — 0 of 441 old line
ranges match it — and a precise-looking wrong anchor is worse than none. The
link text, which carries the author's line numbers, is unchanged.
* 140 prose claims about xenia-rs's behaviour remain. 23 are verified to hold
for Canary too (the 32-bit CR0 truncation, OE left unimplemented); the other
114 need checking one by one, and some invert — e.g. `divdx` notes a correct
64-bit CR0 update in xenia-rs where Canary's `UpdateCR` truncates. Left for
a deliberate pass rather than a blind substitution.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
6.3 KiB
mtspr — Move to Special-Purpose Register
Category: Control / CR / SPR · Form: XFX · Opcode:
0x7c0003a6
Assembler Mnemonics
| Mnemonic | XML entry | Flags | Description |
|---|---|---|---|
mtspr |
mtspr |
— | Move to Special-Purpose Register |
Syntax
mtspr [SPR], [RS]
Encoding
mtspr — form XFX
- Opcode word:
0x7c0003a6 - Primary opcode (bits 0–5):
31 - Extended opcode:
467 - Synchronising: no
| Bits | Field | Meaning |
|---|---|---|
| 0–5 | OPCD |
primary opcode (31) |
| 6–10 | RT |
destination / source GPR |
| 11–20 | spr/tbr/FXM |
SPR/TBR number (byte-swapped halves) or CR field mask |
| 21–30 | XO |
extended opcode |
| 31 | — |
reserved |
Operands
| Field | Role | Description |
|---|---|---|
RS |
mtspr: read | Source GPR (alias for RD in some stores). |
SPR |
mtspr: write | Special-Purpose-Register number. Encoded with the two 5-bit halves swapped (bits 11-15 become the high half, bits 16-20 the low half). |
Register Effects
mtspr
- Reads (always):
RS - Reads (conditional): none
- Writes (always):
SPR - Writes (conditional): none
Status-Register Effects
No condition-register or status-register effects.
Operation (pseudocode)
n <- spr_number(SPR)
SPR(n) <- (RS)
C Translation Example
/* No hand-written C yet. Translate the Canary emitter snapshot */
/* under Implementation References; its HIR maps directly: */
/* f.LoadGPR(n) / f.StoreGPR(n, v) -> r[n] / r[n] = v */
/* f.LoadFPR / StoreFPR, f.LoadVR / StoreVR -> f[n], v[n] */
/* f.Load(ea, T), f.Store(ea, v) -> raw read / write; emitters */
/* wrap them in f.ByteSwap for the big-endian guest value */
/* f.UpdateCR(n, v) -> CR field n from v's LOW 32 BITS vs 0 */
/* f.LoadCA / f.StoreCA -> xer.CA; f.StoreSAT -> vscr.SAT */
/* i.XO.RA, i.D.DS, ... -> the bit-fields listed under Operands */
/* The Register Effects and Status-Register Effects tables above */
/* enumerate every side effect a faithful translation must emit. */
Implementation References
mtspr
- Canary XML:
tools/ppc-instructions.xml— search formnem="mtspr" - Canary emitter:
src/xenia/cpu/ppc/ppc_emit_control.cc:773 - Sylpheed opcode:
crates/sylpheed-ppc/src/opcode.rs:185 - Sylpheed decoder:
crates/sylpheed-ppc/src/decoder.rs:925
Canary emitter (frozen snapshot @ f21ebd49e9)
int InstrEmit_mtspr(PPCHIRBuilder& f, const InstrData& i) {
// n <- spr[5:9] || spr[0:4]
// if length(SPR(n)) = 64 then
// SPR(n) <- (RS)
// else
// SPR(n) <- (RS)[32:63]
Value* rt = f.LoadGPR(i.XFX.RT);
const uint32_t n = ((i.XFX.spr & 0x1F) << 5) | ((i.XFX.spr >> 5) & 0x1F);
switch (n) {
case 1:
// XER
f.StoreXER(rt);
break;
case 8:
// LR
f.StoreLR(rt);
break;
case 9:
// CTR
f.StoreCTR(rt);
break;
case 256:
f.StoreContext(offsetof(PPCContext, vrsave), f.Truncate(rt, INT32_TYPE));
// VRSAVE
break;
default:
XEINSTRNOTIMPLEMENTED();
return 1;
}
return 0;
}
Special Cases & Edge Conditions
-
SPR halves are swapped in the encoding. As with
mfspr, the 10-bitsprfield stores the two 5-bit halves transposed. Software always names the logical SPR number; assemblers handle the swap. Decoded numbern = ((field & 0x1F) << 5) | ((field >> 5) & 0x1F). -
SPRs writable from userspace (Xenon, modelled by xenia).
Decoded # Name Effect 1 XER unpacked into ctx.xer_so/xer_ov/xer_caand length field8 LR ctx.lr ← RS9 CTR ctx.ctr ← RS256 VRSAVE ctx.vrsave ← RS & 0xFFFFFFFF -
SPRs xenia silently swallows (no observable effect). SPRG0..3, HID0, HID1, DAR, DSISR — these are kernel/diagnostic registers; xenia accepts the write to avoid spurious "unimplemented SPR" warnings, but the value is discarded.
-
Privileged SPRs. On real hardware, writes to MSR-visible kernel SPRs (SPRG0..3, HID0/1, DSISR, DAR, PIR, etc.) require supervisor mode and trap from problem state. xenia does not enforce privilege.
-
Time-base writes are privileged.
mtspr 268/269(TBL/TBU) only works in supervisor mode on real hardware. xenia will warnmtspr: unimplemented SPRfor these — do not assume the time base can be guest-written. -
Simplified mnemonics.
mtxer RS≡mtspr 1, RS,mtlr RS≡mtspr 8, RS,mtctr RS≡mtspr 9, RS. These dominate Xbox 360 disassembly. -
No CR / XER side effects.
mtspritself doesn't record (the target SPR may itself be XER, in which case XER is being directly overwritten). -
Not synchronising. xenia's XML omits the
syncflag; PowerISA does require somemtsprcases (e.g. SDR1, MMU regs) to be context-synchronising — none of them appear in title binaries.
Related Instructions
mfspr— inverse: read an SPR into a GPR.mftb— read time-base (preferred overmfspr TBL/TBU).mtmsr,mtmsrd— write MSR (separate opcode).mcrxr— sample-and-clear XER's overflow/carry bits.
Simplified Mnemonics
| Simplified | Expansion |
|---|---|
mtxer RS |
mtspr 1, RS |
mtlr RS |
mtspr 8, RS |
mtctr RS |
mtspr 9, RS |
IBM Reference
- AIX 7.3 —
mtspr(Move to Special Purpose Register) - PowerISA v2.07B, Book III §4 — SPR number table and privilege rules.