rsx: state.lisp

the RSX machine: registers, abstract state, memory windows, the FIFO's own state.

Other definitions

(defconstant +rsx-running+) source
(defconstant +rsx-running+ 0)
(defconstant +rsx-idle+) source
(defconstant +rsx-idle+ 1)
(defconstant +rsx-spin+) source
(defconstant +rsx-spin+ 2)
(defconstant +rsx-blocked+) source
(defconstant +rsx-blocked+ 3)
(defconstant +rsx-limit+) source
(defconstant +rsx-limit+ 4)
(defconstant +rsx-error+) source
(defconstant +rsx-error+ 5)
(defmacro rsx-program-words) source
(defmacro rsx-program-words () 2176)
(defmacro rsx-constant-words) source
(defmacro rsx-constant-words () 1872)
(defstruct rsx) source
(defstruct (rsx (:conc-name rsx-))
  (gfx (make-gfx) :type gfx)
  (regs (make-array 16384 :element-type '(unsigned-byte 32) :initial-element 0)
   :type (simple-array (unsigned-byte 32) (16384)))
  ;; memory windows, set by the HLE (cellGcmSys)
  (io-base 0 :type u32)
  (io-size 0 :type u32)
  (local-base #xC0000000 :type u32)
  (control 0 :type u32)
  (label-base 0 :type u32)
  (driver-info 0 :type u32)             ; the driver's info area (per-head flip flags), 0 none
  ;; the command processor
  (status 0 :type u8)
  (call-return 3 :type u32)             ; 3: no call in progress
  (commands 0 :type u32)                ; commands processed
  ;; the draw being collected between SET_BEGIN_END(primitive) and SET_BEGIN_END(0)
  (draw-open 0 :type u1)
  (draw-kind 0 :type u8)
  (draw-first 0 :type u32)
  (draw-count 0 :type u32)
  ;; the transform (vertex) program engine
  (program (make-array 2176 :element-type '(unsigned-byte 32) :initial-element 0)
   :type (simple-array (unsigned-byte 32) (2176)))
  (program-uploads 0 :type u32)         ; words uploaded so far: part of the program's identity
  (constants (make-array 1872 :element-type '(unsigned-byte 32) :initial-element 0)
   :type (simple-array (unsigned-byte 32) (1872)))
  ;; the IO map: effective 1 MiB page of each IO page, #xFFFF unmapped
  (io-map (make-array 512 :element-type '(unsigned-byte 16) :initial-element #xFFFF)
   :type (simple-array (unsigned-byte 16) (512)))
  (io-mapped 0 :type u1)                ; 1 once a page is mapped: IO-BASE is no longer used
  ;; display buffers (cellGcmSetDisplayBuffer): offsets in local memory
  (display-offset (make-array 8 :element-type '(unsigned-byte 32) :initial-element 0)
   :type (simple-array (unsigned-byte 32) (8)))
  (display-pitch (make-array 8 :element-type '(unsigned-byte 32) :initial-element 0)
   :type (simple-array (unsigned-byte 32) (8)))
  (display-width (make-array 8 :element-type '(unsigned-byte 32) :initial-element 0)
   :type (simple-array (unsigned-byte 32) (8)))
  (display-height (make-array 8 :element-type '(unsigned-byte 32) :initial-element 0)
   :type (simple-array (unsigned-byte 32) (8)))
  (display-count 0 :type u8)
  ;; flips and transfers
  (flips 0 :type u32)
  (flip-buffer 0 :type u32)
  (flip-status 0 :type u8)              ; 0 done, 1 waiting (cellGcmResetFlipStatus)
  (flip-handlers 0 :type u32)           ; flip handler calls owed to the PPU
  (transfers 0 :type u32))
(defmacro rsx-fill) source
(defmacro rsx-fill (array n value)
  (let ((a (gensym "A")))
    `(let ((,a ,array)) (dotimes (i ,n) (setf (aref ,a i) ,value)))))
(defmacro define-rsx-reset) source
(defmacro define-rsx-reset ()
  `(defun rsx-reset (rsx)
     "RSX as it was made: registers, state, windows, FIFO, display"
     (declare (type rsx rsx))
     (let ((gfx (rsx-gfx rsx)))
       ,@(mapcar (lambda (f)
                   (let* ((acc (gfx-sym 'gfx (gff-slot f)))
                          (elt (gfx-lisp-type (gff-type f)))
                          (init (or (gff-default f) (if (eq elt 'single-float) 0.0 0))))
                     (if (and (gff-index f) (not (gff-count f)))
                         `(rsx-fill (,acc gfx) ,(gff-index f) ,init)
                         `(setf (,acc gfx) ,init))))
                 *gfx-fields*))
     (rsx-fill (rsx-regs rsx) 16384 0)
     (rsx-fill (rsx-program rsx) 2176 0)
     (rsx-fill (rsx-constants rsx) 1872 0)
     (rsx-fill (rsx-io-map rsx) 512 #xFFFF)
     (rsx-fill (rsx-display-offset rsx) 8 0)
     (rsx-fill (rsx-display-pitch rsx) 8 0)
     (rsx-fill (rsx-display-width rsx) 8 0)
     (rsx-fill (rsx-display-height rsx) 8 0)
     (setf (rsx-io-base rsx) 0 (rsx-io-size rsx) 0 (rsx-local-base rsx) #xC0000000
           (rsx-control rsx) 0 (rsx-label-base rsx) 0 (rsx-driver-info rsx) 0 (rsx-status rsx) 0 (rsx-call-return rsx) 3
           (rsx-commands rsx) 0 (rsx-draw-open rsx) 0 (rsx-draw-kind rsx) 0 (rsx-draw-first rsx) 0
           (rsx-draw-count rsx) 0 (rsx-program-uploads rsx) 0 (rsx-io-mapped rsx) 0
           (rsx-display-count rsx) 0 (rsx-flips rsx) 0 (rsx-flip-buffer rsx) 0 (rsx-flip-status rsx) 0
           (rsx-flip-handlers rsx) 0 (rsx-transfers rsx) 0)
     nil))
(defconstant +rsx-event-clear+) source
(defconstant +rsx-event-clear+ 1)
(defconstant +rsx-event-draw+) source
(defconstant +rsx-event-draw+ 2)
(defconstant +rsx-event-flip+) source
(defconstant +rsx-event-flip+ 3)
(defun rsx-event) source
(defun rsx-event (rsx kind)
  "the RSX's event sink: called after each clear, draw and flip (KIND
   +RSX-EVENT-...+). Nothing here; a machine defines it again for its presenter."
  (declare (type rsx rsx) (type u8 kind) (ignorable rsx kind))
  nil)
(defun rsx-io) source
(defun rsx-io (rsx offset)
  "the effective address of IO offset OFFSET (0 if it is not mapped)"
  (declare (type rsx rsx) (type u32 offset))
  (if (= (rsx-io-mapped rsx) 0)
      (wrap 32 (+ (rsx-io-base rsx) offset))
      (let ((page (ash offset -20)))
        (if (or (>= page 512) (= (aref (rsx-io-map rsx) page) #xFFFF))
            0
            (logior (ash (aref (rsx-io-map rsx) page) 20) (ldb (byte 20 0) offset))))))
(defun rsx-map-io) source
(defun rsx-map-io (rsx ea io size)
  "map SIZE bytes of main memory at EA to IO offset IO (all multiples of 1 MiB)"
  (declare (type rsx rsx) (type u32 ea io size))
  (setf (rsx-io-mapped rsx) 1)
  (dotimes (i (ash size -20))
    (let ((page (+ (ash io -20) i)))
      (when (< page 512)
        (setf (aref (rsx-io-map rsx) page) (ldb (byte 16 0) (+ (ash ea -20) i))))))
  nil)
(defun rsx-unmap-io) source
(defun rsx-unmap-io (rsx io size)
  "unmap SIZE bytes of IO space at IO (multiples of 1 MiB)"
  (declare (type rsx rsx) (type u32 io size))
  (dotimes (i (ash size -20))
    (let ((page (+ (ash io -20) i)))
      (when (< page 512)
        (setf (aref (rsx-io-map rsx) page) #xFFFF))))
  nil)
(defun rsx-address) source
(defun rsx-address (rsx location offset)
  "the effective address of OFFSET in LOCATION (a CELL_GCM_LOCATION_ or a DMA object), 0 if unknown"
  (declare (type rsx rsx) (type u32 location offset))
  (case location
    ((0 #xFEED0000) (wrap 32 (+ (rsx-local-base rsx) offset)))
    ((1 #xFEED0001) (rsx-io rsx offset))
    ((#x66606660 #x66616661) (wrap 32 (+ (rsx-label-base rsx) offset)))
    (#x66626660 (wrap 32 (+ (rsx-label-base rsx) #x1400 offset)))
    (otherwise 0)))
(defun rsx-bit) source
(defun rsx-bit (value bit)
  "1 when bit BIT of VALUE is set"
  (declare (type u32 value) (type u8 bit))
  (ldb (byte 1 bit) value))
(defun rsx-unorm8) source
(defun rsx-unorm8 (value shift)
  "the byte of VALUE at SHIFT as a float in [0, 1]"
  (declare (type u32 value) (type u8 shift))
  (/ (float (ldb (byte 8 shift) value) 1.0) 255.0))

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