A port of mini-rv32ima to VScript (Squirrel 3)
Click below for the YouTube video showing off this project.
riscv-vscript is a port of mini-rv32ima to VScript (Squirrel3) that:
By default when you execute the script, it will boot into a Linux environment. The device tree (dtb) + system image is stored inside of riscv_data.nut inside of an array of hex bytes values.
It is functional in that it can run Linux, sha256sum, coremark etc and give accurate results.
It is pretty slow, but that's primarily due to the Think rate being limited to 0.1s.
If you don't use Think and let it run and block the main thread, it runs pretty fast and is quite responsive/interactive -- but obviously that isn't desirable as it would hang the server :P
please disregard the blatant lack of support for color codes
This is basically just a raw port of mini-rv32ima to Squirrel3.
Rather annoying as Squirrel has no fixed/small size or unsigned types... only >>>
for unsigned shift. (ie. non-sign-extend)
So we have to emulate all of that and all the logic for it is 'fun'.
We map the player_say game event to map player text to the UART interface.
It supports basically everything you could ever want, but do
not consider it in any way conformant.
It can boot the Linux kernel, run coremark, run sha256sum and get
a correct results, etc.
It can even shutdown with halt -f
and it actually shuts down
the risc-v computer and cleans up the entity responsible for
the Think function.
I was very close to giving up many times writing this code. Luckily mini-rv32ima has a single-step register dump mode. All of the debugging was done via enabling single-step, and a fixed elapsed_us and diff-ing the single-step outputs to see where we diverge.
Special thanks to cnlohr for nerdsniping me with this tiny rv32 implementation I was very surprised how understandable it was, and how little it takes to have a rv32 implementation capable of actually being usable!
This code was all made in a tea-infused 6 hour coding session.
Due to Squirrel having no 64-bit or unsigned types...
unsigned less than is implemented by splitting the number into two signed 16-bit components and doing the comparison that way.
mulh is emulated by treating it as a 64-bit mul in 16-bit parts.
divu is emulated in an interesting way...
modu is treated the same as normal mod for now. So far nothing has relied on the signed-ness semantics of this yet.