SPU channels: rdch, wrch, rchcnt and the channel logic.
0/1 a fixed bit, name a field, a bit the decoder ignores
the channel number sits in the ra 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 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | rb | ra | rt | ||||||||||||||||||
(defspu rdch :rr #x00d (rt (ch ra))
(if (= (spu-chcnt cpu ra) 0)
(spu-stall cpu ra)
(setf (gpr rt) (pref32 (spu-rdch cpu ra)))))
| 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 | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | rb | ra | rt | ||||||||||||||||||
(defspu wrch :rr #x10d ((ch ra) rt)
(if (= (spu-chcnt cpu ra) 0)
(spu-stall cpu ra)
(spu-wrch cpu ra (slot32 rt))))
| 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 | 0 | 0 | 1 | 1 | 1 | 1 | rb | ra | rt | ||||||||||||||||||
(defspu rchcnt :rr #x00f (rt (ch ra))
(setf (gpr rt) (pref32 (spu-chcnt cpu ra))))
(defconstant +spu-rdeventstat+) source(defconstant +spu-rdeventstat+ 0)(defconstant +spu-wreventmask+) source(defconstant +spu-wreventmask+ 1)(defconstant +spu-wreventack+) source(defconstant +spu-wreventack+ 2)(defconstant +spu-rdsignotify1+) source(defconstant +spu-rdsignotify1+ 3)(defconstant +spu-rdsignotify2+) source(defconstant +spu-rdsignotify2+ 4)(defconstant +spu-wrdec+) source(defconstant +spu-wrdec+ 7)(defconstant +spu-rddec+) source(defconstant +spu-rddec+ 8)(defconstant +mfc-wrmssyncreq+) source(defconstant +mfc-wrmssyncreq+ 9)(defconstant +spu-rdeventmask+) source(defconstant +spu-rdeventmask+ 11)(defconstant +mfc-rdtagmask+) source(defconstant +mfc-rdtagmask+ 12)(defconstant +spu-rdmachstat+) source(defconstant +spu-rdmachstat+ 13)(defconstant +spu-wrsrr0+) source(defconstant +spu-wrsrr0+ 14)(defconstant +spu-rdsrr0+) source(defconstant +spu-rdsrr0+ 15)(defconstant +mfc-lsa+) source(defconstant +mfc-lsa+ 16)(defconstant +mfc-eah+) source(defconstant +mfc-eah+ 17)(defconstant +mfc-eal+) source(defconstant +mfc-eal+ 18)(defconstant +mfc-size+) source(defconstant +mfc-size+ 19)(defconstant +mfc-tagid+) source(defconstant +mfc-tagid+ 20)(defconstant +mfc-cmd+) source(defconstant +mfc-cmd+ 21)(defconstant +mfc-wrtagmask+) source(defconstant +mfc-wrtagmask+ 22)(defconstant +mfc-wrtagupdate+) source(defconstant +mfc-wrtagupdate+ 23)(defconstant +mfc-rdtagstat+) source(defconstant +mfc-rdtagstat+ 24)(defconstant +mfc-rdliststallstat+) source(defconstant +mfc-rdliststallstat+ 25)(defconstant +mfc-wrliststallack+) source(defconstant +mfc-wrliststallack+ 26)(defconstant +mfc-rdatomicstat+) source(defconstant +mfc-rdatomicstat+ 27)(defconstant +spu-wroutmbox+) source(defconstant +spu-wroutmbox+ 28)(defconstant +spu-rdinmbox+) source(defconstant +spu-rdinmbox+ 29)(defconstant +spu-wroutintrmbox+) source(defconstant +spu-wroutintrmbox+ 30)(defun spu-tag-stat-ready) source(defun spu-tag-stat-ready (cpu)
"a pending tag status update request is satisfied"
(let* ((mask (spu-mfc-tag-mask cpu))
(done (logand mask (lognot (spu-mfc-tag-busy cpu)))))
(and (= (spu-mfc-tag-req cpu) 1)
(case (spu-mfc-tag-update cpu)
(1 (or (/= done 0) (= mask 0))) ; any
(2 (= done mask)) ; all
(t t)))))(defun spu-chcnt) source(defun spu-chcnt (cpu ch)
"the count of channel CH"
(declare (type spu cpu) (type (unsigned-byte 7) ch))
(cond ((= ch +spu-rdeventstat+)
(b2i (/= (logand (spu-event-stat cpu) (spu-event-mask cpu)) 0)))
((= ch +spu-rdsignotify1+) (spu-sig1-count cpu))
((= ch +spu-rdsignotify2+) (spu-sig2-count cpu))
((= ch +mfc-cmd+) (- 16 (spu-mfc-qcount cpu)))
((= ch +mfc-rdtagstat+) (b2i (spu-tag-stat-ready cpu)))
((= ch +mfc-rdliststallstat+) (b2i (/= (spu-mfc-stall-stat cpu) 0)))
((= ch +mfc-rdatomicstat+) (spu-mfc-atomic-count cpu))
((= ch +spu-wroutmbox+) (- 1 (spu-out-mbox-count cpu)))
((= ch +spu-rdinmbox+) (spu-in-mbox-count cpu))
((= ch +spu-wroutintrmbox+) (- 1 (spu-out-intr-mbox-count cpu)))
(t 1)))(defun spu-rdch) source(defun spu-rdch (cpu ch)
"read channel CH (its count is nonzero)"
(declare (type spu cpu) (type (unsigned-byte 7) ch))
(cond ((= ch +spu-rdeventstat+) (logand (spu-event-stat cpu) (spu-event-mask cpu)))
((= ch +spu-rdsignotify1+)
(prog1 (spu-sig1 cpu) (setf (spu-sig1 cpu) 0 (spu-sig1-count cpu) 0)))
((= ch +spu-rdsignotify2+)
(prog1 (spu-sig2 cpu) (setf (spu-sig2 cpu) 0 (spu-sig2-count cpu) 0)))
((= ch +spu-rddec+) (spu-dec cpu))
((= ch +spu-rdeventmask+) (spu-event-mask cpu))
((= ch +mfc-rdtagmask+) (spu-mfc-tag-mask cpu))
((= ch +spu-rdsrr0+) (spu-srr0 cpu))
((= ch +mfc-rdtagstat+)
(setf (spu-mfc-tag-req cpu) 0)
(logand (spu-mfc-tag-mask cpu) (lognot (spu-mfc-tag-busy cpu))))
((= ch +mfc-rdliststallstat+)
(prog1 (spu-mfc-stall-stat cpu) (setf (spu-mfc-stall-stat cpu) 0)))
((= ch +mfc-rdatomicstat+)
(setf (spu-mfc-atomic-count cpu) 0)
(spu-mfc-atomic-stat cpu))
((= ch +spu-rdinmbox+)
(let ((v (aref (spu-in-mbox cpu) 0)) (box (spu-in-mbox cpu)))
(setf (aref box 0) (aref box 1) (aref box 1) (aref box 2) (aref box 2) (aref box 3)
(aref box 3) 0
(spu-in-mbox-count cpu) (1- (spu-in-mbox-count cpu)))
v))
(t 0)))(defun spu-wrch) source(defun spu-wrch (cpu ch v)
"write V to channel CH (its count is nonzero)"
(declare (type spu cpu) (type (unsigned-byte 7) ch) (type (unsigned-byte 32) v))
(cond ((= ch +spu-wreventmask+) (setf (spu-event-mask cpu) v))
((= ch +spu-wreventack+) (setf (spu-event-stat cpu) (logand (spu-event-stat cpu) (lognot v))))
((= ch +spu-wrdec+) (setf (spu-dec cpu) v))
((= ch +spu-wrsrr0+) (setf (spu-srr0 cpu) (logand v +spu-bmask+)))
((= ch +mfc-lsa+) (setf (spu-mfc-lsa cpu) v))
((= ch +mfc-eah+) (setf (spu-mfc-eah cpu) v))
((= ch +mfc-eal+) (setf (spu-mfc-eal cpu) v))
((= ch +mfc-size+) (setf (spu-mfc-size cpu) (bit-field v 0 16)))
((= ch +mfc-tagid+) (setf (spu-mfc-tag cpu) (bit-field v 0 5)))
((= ch +mfc-cmd+) (mfc-enqueue cpu v) (mfc-drain cpu))
((= ch +mfc-wrtagmask+) (setf (spu-mfc-tag-mask cpu) v))
((= ch +mfc-wrtagupdate+) (setf (spu-mfc-tag-update cpu) (bit-field v 0 2) (spu-mfc-tag-req cpu) 1))
((= ch +mfc-wrliststallack+) ; TODO: resume the stalled list
(setf (spu-mfc-stall-stat cpu) (logand (spu-mfc-stall-stat cpu) (lognot (ash 1 (bit-field v 0 5))))))
((= ch +spu-wroutmbox+) (setf (spu-out-mbox cpu) v (spu-out-mbox-count cpu) 1))
((= ch +spu-wroutintrmbox+) (setf (spu-out-intr-mbox cpu) v (spu-out-intr-mbox-count cpu) 1)))
nil)(defun spu-stall) source(defun spu-stall (cpu ch)
"block on channel CH: the instruction is retried when the SPU resumes"
(declare (type spu cpu) (type (unsigned-byte 7) ch))
(setf (spu-npc cpu) (spu-pc cpu)
(spu-wait-ch cpu) ch
(spu-status cpu) (logior (logandc2 (spu-status cpu) +spu-running+) +spu-waiting+))
nil)(defun spu-write-in-mbox) source(defun spu-write-in-mbox (cpu v)
"push V into the inbound mailbox; T if there was room"
(declare (type spu cpu) (type (unsigned-byte 32) v))
(let ((n (spu-in-mbox-count cpu)))
(when (< n 4)
(setf (aref (spu-in-mbox cpu) n) v
(spu-in-mbox-count cpu) (1+ n)
(spu-event-stat cpu) (logior (spu-event-stat cpu) +spu-event-mb+))
t)))(defun spu-read-out-mbox) source(defun spu-read-out-mbox (cpu)
"pop the outbound mailbox (its count must be 1)"
(declare (type spu cpu))
(setf (spu-out-mbox-count cpu) 0
(spu-event-stat cpu) (logior (spu-event-stat cpu) +spu-event-le+))
(spu-out-mbox cpu))(defun spu-write-signal) source(defun spu-write-signal (cpu which v)
"signal notification register WHICH (1 or 2), overwrite mode"
(declare (type spu cpu) (type (unsigned-byte 2) which) (type (unsigned-byte 32) v))
(if (= which 1)
(setf (spu-sig1 cpu) v (spu-sig1-count cpu) 1
(spu-event-stat cpu) (logior (spu-event-stat cpu) +spu-event-s1+))
(setf (spu-sig2 cpu) v (spu-sig2-count cpu) 1
(spu-event-stat cpu) (logior (spu-event-stat cpu) +spu-event-s2+)))
nil)Made from xspe at b2fac33349db by tools/gen-xspe.py. xspe is GPL-3.0-or-later.