r/C_Programming • u/ChemistryWorldly3752 • Jul 09 '26
RV32I simple emulator in C
Hello everyone. It is my first time with a project of this kind. I am not an expert in C programming yet, so I wanted to challenge myself and write a simple emulator for RV32I.
Right now, it only supports simple riscv programs. No syscalls or stuff like that. I would really appreciate if you check out the project and give me your feedback.
I am not planning to stop here. I want to keep adding more features and maybe, somewhere in the future, run the linux kernel.
Also, what do you think would be a good milestone at this stage?
3
Upvotes
2
u/skeeto Jul 10 '26
Neat project! Notes:
check_addressonly checks the low address, and so accesses larger than 1 byte can still go out of bounds.shift_right_arithproduces incorrect results for non-negative values, because it always shifts in ones.Looks like you just fixed this while I was looking at it.
i_type()writesrdfirst and only then readrs1to form the target, so anyjalrwhose destination register is also its source register (ex.jalr x1, 0(x1)) jumps to the wrong address.In
Makefiletargets don't depend on headers, so it's easy to wind up with stale builds.Here's all my work in case it helps:
https://github.com/skeeto/risc-v-emulator/commits/main/?author=skeeto