The hand-written parts of the manual still described how the retired xenia-rs interpreter behaved: its snapshots, Rust casts and helpers. Each of those 490 statements is now either restated as what Canary's emitters and x64 backend actually do (at the pinned canary_experimental commit), or dropped where it only made sense for xenia-rs. Checking them turned up claims that were wrong, not just outdated: - VSCR[SAT] is never modelled in Canary (DID_SATURATE is a stub and mfvscr cannot see it); the pages said saturating ops set it stickily. - Canary does not implement lswi/lswx/stswi/stswx, dcbi, mtfsb0/mtfsb1, vmsum*, vmhaddshs, vupkhpx/vupklpx, and most SPRs; pages described them as working. - Traps evaluate TO in Canary; stvebx/stvehx/stvewx store one element, not 16 bytes; mtmsrd writes only EE; fres/frsqrte/vrsqrtefp precision claims and the stfs "rounds under RN / sets FPSCR" claim contradicted the spec. - Reservations are a 64 KiB block bitmap plus a value compare, not per-address tracking. Claims that neither Canary's source nor a public spec settles are marked unverified (NI at boot, vmaddcfp128 operand order, estimate bit-exactness). Generated regions are untouched; re-running the generator changes nothing. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
6.0 KiB
6.0 KiB
sc — System Call
Category: Branch & System · Form: SC · Opcode:
0x44000002· sync
Assembler Mnemonics
| Mnemonic | XML entry | Flags | Description |
|---|---|---|---|
sc |
sc |
— | System Call |
Syntax
sc [LEV]
Encoding
sc — form SC
- Opcode word:
0x44000002 - Primary opcode (bits 0–5):
17 - Extended opcode: —
- Synchronising: yes
| Bits | Field | Meaning |
|---|---|---|
| 0–5 | OPCD |
primary opcode (17) |
| 6–19 | — |
reserved |
| 20–26 | LEV |
exception level |
| 27–29 | — |
reserved |
| 30 | 1 |
fixed 1 |
| 31 | — |
reserved |
Operands
| Field | Role | Description |
|---|---|---|
LEV |
sc: read | System-call exception level (for sc). |
Register Effects
sc
- Reads (always):
LEV - Reads (conditional): none
- Writes (always): none
- Writes (conditional): none
Status-Register Effects
No condition-register or status-register effects.
Operation (pseudocode)
system_call_exception(LEV)
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
sc
- Canary XML:
tools/ppc-instructions.xml— search formnem="sc" - Canary emitter:
src/xenia/cpu/ppc/ppc_emit_control.cc:457 - Sylpheed opcode:
crates/sylpheed-ppc/src/opcode.rs:214 - Sylpheed decoder:
crates/sylpheed-ppc/src/decoder.rs:456
Canary emitter (frozen snapshot @ f21ebd49e9)
int InstrEmit_sc(PPCHIRBuilder& f, const InstrData& i) {
// Game code should only ever use LEV=0.
// LEV=2 is to signify 'call import' from Xenia.
// TODO(gibbed): syscalls!
if (i.SC.LEV == 0) {
f.CallExtern(f.builtins()->syscall_handler);
return 0;
}
if (i.SC.LEV == 2) {
f.CallExtern(f.function());
return 0;
}
XEINSTRNOTIMPLEMENTED();
return 1;
}
Special Cases & Edge Conditions
LEVfield — kernel vs hypervisor. The 7-bitLEVoperand selects the privilege level of the syscall:LEV = 0— supervisor (kernel) syscall. Standard application → kernel transition; targets the0xC00system-call vector.LEV = 1— reserved.LEV = 2— hypervisor syscall (HVcall). On the Xenon,sc 2traps to the Xbox 360 hypervisor; this is how the kernel itself talks to the supervisor below it (e.g., for security operations, encrypted-memory accesses, page table updates).
scas written by titles. Almost all guest game code usesLEV = 0to callXboxKrnl.exe. Game disassembly will show large jump tables of small thunks each ending inli r0, syscall_no; sc; blr.- No condition or status side effects.
scupdates no general-purpose register on entry — neither LR nor CR. The kernel sees the GPR/FPR snapshot as-is and reads the syscall number out ofr0(Xbox 360 ABI convention, not architectural). - Return path. Hardware returns from
scviarfid-class instructions in the kernel handler; from the application's perspective execution resumes atCIA + 4. Canary emitsscas a host call (CallExternof its syscall handler), after which the translated code simply continues atCIA + 4. - Canary divergence vs hardware. Canary does not model the
0xC00exception vector or save SRR0/SRR1.LEV=0calls its syscall handler,LEV=2is Canary's own marker for an import call, and any otherLEVis unimplemented. This is sufficient because Xbox 360 titles don't observe SRR registers and Canary implements the kernel natively. - Synchronisation. Marked
syncin Canary'stools/ppc-instructions.xml—scis context-synchronising (hardware completes all prior instructions before raising the exception). JITs must flush pending state before emitting the host call. - Reserved bits. Bit 30 is fixed
1; bits 6–19 and 27–29 are reserved (must be 0). The 1-bit field at position 30 distinguishes thescencoding fromscv(later PowerISA addition, not present on the Xenon).
Related Instructions
bx,bcx,bclrx,bcctrx— ordinary control flow alternatives.tw,twi,td,tdi— synchronous trap exceptions; another way to enter the kernel.mtmsr,mtmsrd— machine-state changes used by the kernel'sschandler on return (rfid/hrfidchain not separately documented in this manual).isync— context-synchronising sibling;scitself implies an isync-like fence.
IBM Reference
- AIX 7.3 —
sc(System Call) - PowerISA v2.07B, Book III §7 — System Linkage interrupt definitions and
LEVfield semantics.