criscv/README.md
Minecon724 16975eced0
All checks were successful
/ deploy (push) Successful in 1m18s
Not a thing
2024-10-21 19:43:12 +02:00

34 lines
No EOL
1.5 KiB
Markdown

RISC-V (rv32i) emulator in C \
This is just for me to understand how all this works, and to learn something new. \
So don't use it.
Example programs:
- `return.bin` returns -1094647826 (puts it to register 10)
- `return2.elf` returns a different value with more steps. if it returns DADD, something's wrong
Emulator exit codes:
- `-1` - reached end of address space
- `0` - never happens
- `1` - invalid opcode
- `2` - illegal instruction argument (like funct3)
Compile:
1. Dependencies: `libelf`
2. ```
make # should display no warnings
```
3. Executable is `build/criscv`
Note: Prebuilts for **x86_64 & aarch64 Linux** are available [here](https://git.m724.eu/Minecon724/criscv/actions), pick the top one, download the artifact, and keep the one for your architecture. \
Those are **dynamic**, meaning you still need the dependencies! See compile step 1 above.
Compile programs:
1. Get the toolchain obviously
2. ```
riscv32-unknown-elf-gcc -ffreestanding -nostdlib -Ttext=0x0 -e main -O0 -o program.elf program.c
```
3. `program.bin` is the binary file with the program, pass it as an argument
rv32i, ilp32 compatible toolchain for 64bit Linux: [download](https://lfs.m724.eu/toolchain.tar.zst) `adaa74f263dcba430da588b1109bc3b90bd90a84c67b06213bd03a7bbacd1a2a` \
Or just the stuff necessary to make a binary file: [download](https://lfs.m724.eu/toolchainlite.tar.zst) `55e79dff7ba4093dedb8151461508fc157525ad89615d49d737845af03d1643f` \
Those were compiled with `./configure --prefix=$(pwd)/../toolchain --with-arch=rv32i --with-abi=ilp32` and `make`