The same thing but in C
|
|
||
|---|---|---|
| .forgejo/workflows | ||
| include | ||
| programs | ||
| src | ||
| .gitignore | ||
| Makefile | ||
| README.md | ||
| remake.sh | ||
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.binreturns -1094647826 (puts it to register 10)return2.elfreturns a different value with more steps. if it returns DADD, something's wrong
Emulator exit codes:
-1- reached end of address space0- never happens1- invalid opcode2- illegal instruction argument (like funct3)
Compile:
0. Requirements: libelf
-
make # should display no warnings - Executable is
build/criscv
Compile programs: 0. Get the toolchain obviously
-
riscv32-unknown-elf-gcc -ffreestanding -nostdlib -Ttext=0x0 -e main -O0 -o program.elf program.c program.binis the binary file with the program, pass it as an argument
rv32i, ilp32 compatible toolchain for 64bit Linux: download adaa74f263dcba430da588b1109bc3b90bd90a84c67b06213bd03a7bbacd1a2a
Or just the stuff necessary to make a binary file: download 55e79dff7ba4093dedb8151461508fc157525ad89615d49d737845af03d1643f
Those were compiled with ./configure --prefix=$(pwd)/../toolchain --with-arch=rv32i --with-abi=ilp32 and make