Scheme utility procedures for the RISC-V instruction set architecture
git clone https://git.8pit.net/riscv-utils.git
1# riscv-utils 2 3Scheme utility procedures for the [RISC-V][riscv website] instruction set architecture. 4 5## Features 6 7The feature set of provided procedures is centered around easing the 8development of utilities for RISC-V (especially instruction set 9simulators). Currently the following features are provided:1011* `decode.scm`: Decoding of RISC-V instructions.12* `encode.scm`: Encoding of RISC-V instructions.13* `convert.scm`: Conversion from/to different representations.14* `opcodes.scm`: Constants for instruction opcodes (currently rv32i only).1516## Usage1718The code is supposed to be used from a Scheme REPL, no binaries are19provided. The Scheme files in the `riscv/` directory are mostly(?)20[R7RS][r7rs small] compatible. It should be possible to use them with any21standard compliant Scheme implementation which provides an22[SRFI-151][srfi-151] module. Just load the files you want to use23using `(load "riscv/<file>.scm")` from your Scheme REPL.2425If your favorite Scheme implementation is [CHICKEN][call-cc], read on.2627### Example2829The API is intentionally very low-level. Nonetheless, many fun things30can be done with it. The following example takes an existing `JAL`31instruction (e.g. as extracted from a `riscv32-unknown-elf-objdump -d`32output) and modifies it to jump somewhere else.3334 $ csi35 > (import riscv)36 > (set! jal #x0100056f)37 > (instr-j-imm jal)38 1639 > (j-type (instr-opcode jal) (instr-rd jal) 32)40 335558234142The value `33555823` (`0x200056f`) is RISC-V machine code for a JAL43instruction holing the value `32` (instead of `16`) as a J-immediate.44This can be easily verified using:4546 > (set! jal-new 33555823)47 > (instr->hex jal-new)48 "#x200056f"49 > (instr-j-imm jal-new)50 325152## Installation5354In addition to standard compliant(?) Scheme source code, this repository55also contains the required files for using the code as a CHICKEN Scheme56[egg][call-cc eggs]. However, since the code is still in very early57stages of development I haven't published it as an egg yet. Nonetheless,58an egg can be built locally using:5960 $ chicken-install -test6162### Building without installing6364If installation is not desired, build as follows:6566 $ export CHICKEN_REPOSITORY_PATH="$(pwd):${CHICKEN_REPOSITORY_PATH}"67 $ chicken-install -n -test6869Afterwards simply run `(import riscv)` in `csi(1)` as usual.7071## License7273This program is free software: you can redistribute it and/or modify it74under the terms of the GNU General Public License as published by the75Free Software Foundation, either version 3 of the License, or (at your76option) any later version.7778This program is distributed in the hope that it will be useful, but79WITHOUT ANY WARRANTY; without even the implied warranty of80MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General81Public License for more details.8283You should have received a copy of the GNU General Public License along84with this program. If not, see <http://www.gnu.org/licenses/>.8586[riscv website]: https://riscv.org/87[srfi-151]: https://srfi.schemers.org/srfi-151/srfi-151.html88[r7rs small]: https://small.r7rs.org/89[call-cc]: https://call-cc.org90[call-cc eggs]: https://eggs.call-cc.org/