rv64

10 definitions in 8 files, 10 with an encoding diagram. src/isa/rv64

Files

FileDefinitionsOtherWhat
package.lisp00the ISA.RV64 package: RISC-V RV64 (a skeleton: docs/isa.md); exports its state contract.
state.lisp012RV64's architected state and the accessors every semantics body uses.
defrv.lisp02RISC-V encodings (generated, gen/opcodes.lisp) and DEFRV, an instruction's semantics on its encoding.
gen/opcodes.lisp00the encodings table, shown with each instruction
rv64i.lisp100RV64I semantics (a few instructions so far: the skeleton of docs/isa.md).
exec.lisp06RV64 as a guest: the executor, decoder, step and run loop.
enc.lisp02RV64 as a host: run-time encoders made from the DEFRV encodings, and the emitter.
asm.lisp00a compile-time RV64 assembler built from the DEFRV records.

README

src/isa/rv64: RISC-V RV64 (a skeleton)

Package ISA.RV64. This is the worked example of docs/isa.md, "Adding an ISA". It is small and real. It is not a complete RISC-V.

FileWhat
package.lispISA.RV64 and its exports
state.lispdefisa rv64 (32-bit words, little-endian), the rv64 struct (x, pc, npc, exc), (gpr n), (set-gpr n v) (writes to x0 dropped), rv-load/rv-store (little-endian over the core's big-endian memory, addresses modulo 2^32), i-imm, s-imm, b-imm, branch-to
defrv.lispdefrvenc (the generated table), (defrv name ...): definsn with the generated encoding
gen/opcodes.lispthe encodings (generated, do not edit)
rv64i.lispthe semantics, each quoting the manual
exec.lisprv64-execute, rv64-decode, rv64-fetch, rv64-step, rv64-run
enc.lisp(rv64-enc/<name> field...) (fields MSB first), rv64-emit32
asm.lisprv64-assemble, rv64-load-program (compile time)

Fields keep riscv-opcodes' names (rd rs1 rs2 imm12 imm12hi imm12lo bimm12hi bimm12lo ...).

Adding instructions

  1. Check that the encoding is in gen/opcodes.lisp. If its extension is missing, add it to XSPE_RVGEN_ARGS in tools/rvgen/CMakeLists.txt and regenerate (below).
  2. Write (defrv name (:asm "mnemonic" operand...) (:doc "...") body) in the extension's file (rv64i.lisp, rv64m.lisp ...), quoting [RVUNPRIV]. Load the file in files.cmake before exec.lisp.
  3. Add sample values to tests/isa/rv64/sem.lisp and an LLVM word to tests/isa/rv64/enc.lisp. If the instruction writes one register, or memory and nothing else, isel_rv64 covers and verifies it without further changes.

Regenerating

CPM_SOURCE_CACHE=$HOME/.cache/cpm cmake -S . -B build -DXSPE_REGEN=ON
cmake --build build --target rv64-regen && git diff src/isa/rv64/gen

The test rv64_regen (REGEN mode only) requires the committed file to match a fresh run.


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