the SPU decoder, executor and run loop.
(defconstant +spu-invalid+) source(defconstant +spu-invalid+ #x40)(defun spu-illegal) source(defun spu-illegal (cpu insn)
(declare (type spu cpu) (ignore insn))
(setf (spu-status cpu) (logior (logandc2 (spu-status cpu) +spu-running+)
+spu-halted+ +spu-invalid+))
nil)(define-executor spu-execute) source(define-executor spu-execute spu :illegal spu-illegal)(define-decoder spu-decode) source(define-decoder spu-decode spu)(defun spu-step) source(defun spu-step (cpu)
"fetch the instruction at pc from the local store and run it"
(declare (type spu cpu))
(let* ((pc (spu-pc cpu))
(insn (ls-read 32 pc)))
(setf (spu-npc cpu) (logand (+ pc 4) +spu-lslr+))
(spu-execute cpu insn)
(setf (spu-pc cpu) (spu-npc cpu)
(spu-insn-count cpu) (wrap 64 (1+ (spu-insn-count cpu))))
nil))(defun spu-start) source(defun spu-start (cpu pc)
"start (or restart) the SPU at LS address PC"
(declare (type spu cpu) (type (unsigned-byte 32) pc))
(setf (spu-pc cpu) (logand pc +spu-bmask+)
(spu-status cpu) +spu-running+)
nil)(defun spu-run) source(defun spu-run (cpu limit)
"run until the SPU stops, halts or blocks, or LIMIT instructions ran; a
SPU blocked on a channel that became ready resumes first. Returns the
number of instructions run."
(declare (type spu cpu) (type (unsigned-byte 64) limit))
(when (and (= (spu-status cpu) +spu-waiting+)
(/= (spu-chcnt cpu (spu-wait-ch cpu)) 0))
(setf (spu-status cpu) +spu-running+))
(let ((n 0))
(loop while (and (logtest (spu-status cpu) +spu-running+) (< n limit))
do (spu-step cpu) (setq n (1+ n)))
n))Made from xspe at b2fac33349db by tools/gen-xspe.py. xspe is GPL-3.0-or-later.