rsx: fifo.lisp

the command processor: GET chases PUT through the command buffer.

Other definitions

(defun rsx-fail) source
(defun rsx-fail (rsx)
  (declare (type rsx rsx))
  (setf (rsx-status rsx) +rsx-error+)
  nil)
(defun rsx-command) source
(defun rsx-command (rsx get put)
  "run the command at GET (an IO offset, PUT the end of the commands) -> the next GET"
  (declare (type rsx rsx) (type u32 get put))
  (let ((cmd (mem-read 32 (rsx-io rsx get))))
    (cond
      ((or (= (logand cmd #xE0000003) #x20000000) (= (logand cmd #xE0000003) 1))
       (let ((target (if (= (logand cmd 3) 1) (logand cmd #xFFFFFFFC) (logand cmd #x1FFFFFFC))))
         (when (= target get)
           (setf (rsx-status rsx) +rsx-spin+))
         target))
      ((= (logand cmd 3) 2)
       (if (= (rsx-call-return rsx) 3)
           (progn (setf (rsx-call-return rsx) (wrap 32 (+ get 4)))
                  (logand cmd #x1FFFFFFC))
           (progn (rsx-fail rsx) get)))
      ((= (logand cmd #xFFFF0003) #x00020000)
       (if (= (rsx-call-return rsx) 3)
           (progn (rsx-fail rsx) get)
           (let ((target (rsx-call-return rsx)))
             (setf (rsx-call-return rsx) 3)
             target)))
      ((/= (logand cmd #xA0030003) 0)
       (rsx-fail rsx)
       get)
      (t
       (let ((count (ldb (byte 11 18) cmd))
             (method (logand cmd #xFFFC))
             (step (if (logbitp 30 cmd) 0 4)))
         (cond
           ((and (>= put get) (> (+ get 4 (* 4 count)) put))
            (setf (rsx-status rsx) +rsx-idle+)       ; the arguments are not all there yet
            get)
           (t
            (dotimes (i count)
              (rsx-method rsx (ldb (byte 16 0) (+ method (* step i))) (mem-read 32 (rsx-io rsx (+ get 4 (* 4 i)))))
              (unless (= (rsx-status rsx) +rsx-running+)
                (return-from rsx-command get)))
            (wrap 32 (+ get 4 (* 4 count))))))))))
(defun rsx-run) source
(defun rsx-run (rsx limit)
  "process commands until GET reaches PUT, the FIFO stalls, or LIMIT commands ran -> the count;
   RSX-STATUS tells why it stopped"
  (declare (type rsx rsx) (type u32 limit))
  (let ((n 0) (control (rsx-control rsx)))
    (setf (rsx-status rsx) +rsx-running+)
    (loop
      (let ((get (mem-read 32 (+ control 4)))
            (put (logand (mem-read 32 control) #xFFFFFFFC)))
        (when (= get put)
          (setf (rsx-status rsx) +rsx-idle+)
          (return))
        (when (>= n limit)
          (setf (rsx-status rsx) +rsx-limit+)
          (return))
        (let ((next (rsx-command rsx get put)))
          (unless (= (rsx-status rsx) +rsx-running+)
            (return))
          (mem-write 32 (+ control 4) next)
          (setq n (+ n 1))
          (setf (rsx-commands rsx) (wrap 32 (+ (rsx-commands rsx) 1))))))
    n))

Made from xspe at b2fac33349db by tools/gen-xspe.py. xspe is GPL-3.0-or-later.