PPU branches, CR logical ops, SPR moves, system call, sync.
0/1 a fixed bit, name a field, a bit the decoder ignores
b (rel li)
Branch
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 | 0 | li | aa | lk | |||||||||||||||||||||||
(defppu b ((18 6) "li:24 aa:1 lk:1") (:asm "b" (rel li)) (:doc "Branch")
(let ((off (sext 26 (ash li 2))))
(when (= lk 1) (setf (ppu-lr cpu) (next-pc)))
(branch-to (if (= aa 1) off (+ (ppu-pc cpu) off)))))
bc bo bi (rel bd)
Branch Conditional
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 0 | 0 | 0 | 0 | bo | bi | bd | aa | lk | |||||||||||||||||||||
(defppu bc ((16 6) "bo:5 bi:5 bd:14 aa:1 lk:1") (:asm "bc" bo bi (rel bd))
(:doc "Branch Conditional")
(let ((off (sext 16 (ash bd 2))) (taken (bo-cond bo bi)))
(when (= lk 1) (setf (ppu-lr cpu) (next-pc)))
(when taken (branch-to (if (= aa 1) off (+ (ppu-pc cpu) off))))))
bclr bo bi bh
Branch Conditional to Link Register
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 | 1 | bo | bi | 0 | 0 | 0 | bh | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | lk | |||||||||
(defppu bclr ((19 6) "bo:5 bi:5 000 bh:2" (16 10) "lk:1") (:asm "bclr" bo bi bh)
(:doc "Branch Conditional to Link Register")
(let ((target (logand (ppu-lr cpu) (wrap 64 (lognot 3)))) (taken (bo-cond bo bi)))
(when (= lk 1) (setf (ppu-lr cpu) (next-pc)))
(when taken (branch-to target))))
bcctr bo bi bh
Branch Conditional to Count Register
BO2 = 0 is an invalid form for bcctr: CTR is never decremented here
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 | 1 | bo | bi | 0 | 0 | 0 | bh | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | lk | |||||||||
(defppu bcctr ((19 6) "bo:5 bi:5 000 bh:2" (528 10) "lk:1") (:asm "bcctr" bo bi bh)
(:doc "Branch Conditional to Count Register")
(let ((target (logand (ppu-ctr cpu) (wrap 64 (lognot 3)))))
(when (= lk 1) (setf (ppu-lr cpu) (next-pc)))
(when (or (= (msb-bit 5 bo 0) 1) (= (cr-bit bi) (msb-bit 5 bo 1)))
(branch-to target))))
mcrf bf bfa
Move Condition Register Field
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 | 1 | bf | bfa | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||||||||||||||
(defppu mcrf ((19 6) "bf:3 .. bfa:3 .. ....." (0 10) ".") (:asm "mcrf" bf bfa)
(:doc "Move Condition Register Field")
(set-cr-field bf (cr-field bfa)))
mfocrf rt fxm (const one 1)
Move From (One) Condition Register Field
one = 0: mfcr, the whole CR. one = 1: mfocrf, the one field FXM selects; the other fields read as 0.
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 1 | rt | one | fxm | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | 1 | |||||||||||||
(defppu mfocrf ((31 6) "rt:5 one:1 fxm:8 ." (19 10) ".") (:asm "mfocrf" rt fxm (const one 1))
(:doc "Move From (One) Condition Register Field")
(if (= one 0)
(setf (gpr rt) (ppu-cr cpu))
(let ((m 0))
(dotimes (i 8)
(when (= (msb-bit 8 fxm i) 1)
(setq m (logior m (ones 4 (* 4 (- 7 i)))))))
(setf (gpr rt) (logand (ppu-cr cpu) m)))))
mtocrf fxm rs (const one 1)
Move To (One) Condition Register Field(s)
mtcrf and mtocrf (one = 1, a single FXM bit): the fields FXM selects
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 1 | rs | one | fxm | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | |||||||||||||
(defppu mtocrf ((31 6) "rs:5 one:1 fxm:8 ." (144 10) ".") (:asm "mtocrf" fxm rs (const one 1))
(:doc "Move To (One) Condition Register Field(s)")
(let ((m 0))
(dotimes (i 8)
(when (= (msb-bit 8 fxm i) 1)
(setq m (logior m (ones 4 (* 4 (- 7 i)))))))
(setf (ppu-cr cpu) (logior (logand (wrap 32 (gpr rs)) m)
(logand (ppu-cr cpu) (wrap 32 (lognot m)))))))
mfspr rt (spr spr)
Move From Special Purpose Register
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 1 | rt | spr | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 0 | 1 | 1 | ||||||||||||||
(defppu mfspr ((31 6) "rt:5 spr:10" (339 10) ".") (:asm "mfspr" rt (spr spr))
(:doc "Move From Special Purpose Register")
(let ((n (spr-number spr)))
(cond ((= n +spr-xer+) (setf (gpr rt) (ppu-xer cpu)))
((= n +spr-lr+) (setf (gpr rt) (ppu-lr cpu)))
((= n +spr-ctr+) (setf (gpr rt) (ppu-ctr cpu)))
((= n +spr-vrsave+) (setf (gpr rt) (ppu-vrsave cpu)))
((= n +spr-tb+) (setf (gpr rt) (host-timebase)))
((= n +spr-tbu+) (setf (gpr rt) (ash (host-timebase) -32)))
(t (raise +exc-spr+)))))
mtspr (spr spr) rs
Move To Special Purpose Register
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 1 | rs | spr | 0 | 1 | 1 | 1 | 0 | 1 | 0 | 0 | 1 | 1 | ||||||||||||||
(defppu mtspr ((31 6) "rs:5 spr:10" (467 10) ".") (:asm "mtspr" (spr spr) rs)
(:doc "Move To Special Purpose Register")
(let ((n (spr-number spr)) (v (gpr rs)))
(cond ((= n +spr-xer+) (setf (ppu-xer cpu) (logand v #xE000007F)))
((= n +spr-lr+) (setf (ppu-lr cpu) v))
((= n +spr-ctr+) (setf (ppu-ctr cpu) v))
((= n +spr-vrsave+) (setf (ppu-vrsave cpu) (wrap 32 v)))
(t (raise +exc-spr+)))))
mftb rt (spr tbr)
Move From Time Base
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 1 | rt | tbr | 0 | 1 | 0 | 1 | 1 | 1 | 0 | 0 | 1 | 1 | ||||||||||||||
(defppu mftb ((31 6) "rt:5 tbr:10" (371 10) ".") (:asm "mftb" rt (spr tbr))
(:doc "Move From Time Base")
(let ((n (spr-number tbr)))
(cond ((= n +spr-tb+) (setf (gpr rt) (host-timebase)))
((= n +spr-tbu+) (setf (gpr rt) (ash (host-timebase) -32)))
(t (raise +exc-spr+)))))
sc lev
System Call
lv2-syscall is defined by src/sys/ps3/lv2: syscall number in r11, arguments in r3..r10, result in r3
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 0 | 0 | 0 | 1 | lev | 1 | ||||||||||||||||||||||||
(defppu sc ((17 6) "..... ..... .... lev:7 ... 1 .") (:asm "sc" lev) (:doc "System Call")
(lv2-syscall cpu))
hletrap index
HLE function trap (emulator)
Primary opcode 1 is not a PowerPC instruction. The HLE writes it into the thunks that stand for firmware functions (src/sys/ps3/lv2/abi.lisp): the low 26 bits number the function, and hle-trap, which src/sys/ps3/lv2 defines, runs it.
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 0 | 0 | 0 | 0 | 1 | index | |||||||||||||||||||||||||
(defppu hletrap ((1 6) "index:26") (:asm "hletrap" index) (:doc "HLE function trap (emulator)")
(hle-trap cpu index))
sync
Synchronize
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 1 | 0 |
(defppu sync ((31 6) "..... ..... ....." (598 10) ".") (:asm "sync") (:doc "Synchronize"))
eieio
Enforce In-order Execution of I/O
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 1 | 0 |
(defppu eieio ((31 6) "..... ..... ....." (854 10) ".") (:asm "eieio")
(:doc "Enforce In-order Execution of I/O"))
isync
Instruction Synchronize
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 1 | 1 | 0 |
(defppu isync ((19 6) "..... ..... ....." (150 10) ".") (:asm "isync") (:doc "Instruction Synchronize"))
dcbt ra rb
Data Cache Block Touch
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 1 | ra | rb | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | ||||||||||||||
(defppu dcbt ((31 6) "..... ra:5 rb:5" (278 10) ".") (:asm "dcbt" ra rb) (:doc "Data Cache Block Touch"))
dcbtst ra rb
Data Cache Block Touch for Store
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 1 | ra | rb | 0 | 0 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | ||||||||||||||
(defppu dcbtst ((31 6) "..... ra:5 rb:5" (246 10) ".") (:asm "dcbtst" ra rb)
(:doc "Data Cache Block Touch for Store"))
dcbf ra rb
Data Cache Block Flush
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 1 | ra | rb | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 1 | 0 | ||||||||||||||
(defppu dcbf ((31 6) "..... ra:5 rb:5" (86 10) ".") (:asm "dcbf" ra rb) (:doc "Data Cache Block Flush"))
dcbst ra rb
Data Cache Block Store
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 1 | ra | rb | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 1 | 0 | ||||||||||||||
(defppu dcbst ((31 6) "..... ra:5 rb:5" (54 10) ".") (:asm "dcbst" ra rb) (:doc "Data Cache Block Store"))
icbi ra rb
Instruction Cache Block Invalidate
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 1 | ra | rb | 1 | 1 | 1 | 1 | 0 | 1 | 0 | 1 | 1 | 0 | ||||||||||||||
(defppu icbi ((31 6) "..... ra:5 rb:5" (982 10) ".") (:asm "icbi" ra rb)
(:doc "Instruction Cache Block Invalidate"))
dst
Data Stream Touch
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 | 1 | 0 |
(defppu dst ((31 6) "..... ..... ....." (342 10) ".") (:asm "dst") (:doc "Data Stream Touch"))
dstst
Data Stream Touch for Store
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 1 | 0 | 1 | 0 | 1 | 1 | 1 | 0 | 1 | 1 | 0 |
(defppu dstst ((31 6) "..... ..... ....." (374 10) ".") (:asm "dstst") (:doc "Data Stream Touch for Store"))
dss
Data Stream Stop
| 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | 1 | 0 | 1 | 1 | 0 |
(defppu dss ((31 6) "..... ..... ....." (822 10) ".") (:asm "dss") (:doc "Data Stream Stop"))
(defmacro next-pc) source(defmacro next-pc () `(wrap 64 (+ (ppu-pc cpu) 4)))(defmacro bo-cond) source(defmacro bo-cond (bo bi)
`(progn
(when (= (msb-bit 5 ,bo 2) 0)
(setf (ppu-ctr cpu) (wrap 64 (- (ppu-ctr cpu) 1))))
(and (or (= (msb-bit 5 ,bo 2) 1)
(/= (b2i (/= (ppu-ctr cpu) 0)) (msb-bit 5 ,bo 3)))
(or (= (msb-bit 5 ,bo 0) 1)
(= (cr-bit ,bi) (msb-bit 5 ,bo 1))))))(defmacro defcrop) source(defmacro defcrop (name xo doc expr)
`(defppu ,name ((19 6) "bt:5 ba:5 bb:5" (,xo 10) ".") (:asm ,(string-downcase (symbol-name name)) bt ba bb)
(:doc ,doc)
(let ((a (cr-bit ba)) (b (cr-bit bb)))
(declare (ignorable b))
(set-cr-bit bt ,expr))))(defmacro spr-number) source(defmacro spr-number (f) `(logior (ash (bit-field ,f 0 5) 5) (bit-field ,f 5 5)))(defconstant +spr-xer+) source(defconstant +spr-xer+ 1)(defconstant +spr-lr+) source(defconstant +spr-lr+ 8)(defconstant +spr-ctr+) source(defconstant +spr-ctr+ 9)(defconstant +spr-vrsave+) source(defconstant +spr-vrsave+ 256)(defconstant +spr-tb+) source(defconstant +spr-tb+ 268)(defconstant +spr-tbu+) source(defconstant +spr-tbu+ 269)(defvar *reference-timebase*) source(defvar *reference-timebase* 0)Made from xspe at b2fac33349db by tools/gen-xspe.py. xspe is GPL-3.0-or-later.