The same thing but in C
Find a file
Minecon724 6e9919f3a3
Some checks failed
/ deploy (push) Failing after 1m8s
almost
2024-10-19 18:05:29 +02:00
.forgejo/workflows almost 2024-10-19 18:05:29 +02:00
include fix 2024-10-19 16:48:00 +02:00
programs ELF support and other stuff 2024-10-19 11:50:02 +02:00
src asd 2024-10-19 17:16:36 +02:00
.gitignore initial commit 2024-10-14 19:48:56 +02:00
Makefile iaa 2024-10-19 17:40:11 +02:00
README.md Fix README 2024-10-19 11:53:32 +02:00
remake.sh It now runs a program 2024-10-16 15:34:06 +02:00

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: 0. Requirements: libelf

  1. make # should display no warnings
    
  2. Executable is build/criscv

Compile programs: 0. Get the toolchain obviously

  1. riscv32-unknown-elf-gcc -ffreestanding -nostdlib -Ttext=0x0 -e main -O0 -o program.elf program.c
    
  2. program.bin is 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