RV64 as a guest: the executor, decoder, step and run loop.
(defun rv64-illegal) source(defun rv64-illegal (cpu insn)
(declare (type rv64 cpu) (type (unsigned-byte 32) insn) (ignore insn))
(setf (rv64-exc cpu) +exc-illegal+))(define-executor rv64-execute) source(define-executor rv64-execute rv64 :illegal rv64-illegal)(define-decoder rv64-decode) source(define-decoder rv64-decode rv64)(defun rv64-fetch) source(defun rv64-fetch (addr)
"the instruction word at ADDR: 32 bits, little-endian"
(declare (type (unsigned-byte 64) addr))
(rv-load 32 addr))(defun rv64-step) source(defun rv64-step (cpu)
(declare (type rv64 cpu))
(let ((insn (rv64-fetch (rv64-pc cpu))))
(setf (rv64-npc cpu) (wrap 64 (+ (rv64-pc cpu) 4)))
(rv64-execute cpu insn)
(when (= (rv64-exc cpu) 0)
(setf (rv64-pc cpu) (rv64-npc cpu)))))(defun rv64-run) source(defun rv64-run (cpu stop max)
(declare (type rv64 cpu) (type (unsigned-byte 64) stop) (type (unsigned-byte 32) max))
(let ((n 0))
(declare (type (unsigned-byte 32) n))
(loop
(when (or (= (rv64-pc cpu) stop) (/= (rv64-exc cpu) 0) (>= n max)) (return n))
(rv64-step cpu)
(setq n (+ n 1)))))Made from xspe at b2fac33349db by tools/gen-xspe.py. xspe is GPL-3.0-or-later.