perilus Part Nine2026-11-08
TL;DR: perilus now passes all of the Architecture
Certification Tests in the RV32I base set. The total diff required
to get there turned out to be pretty small, but it took some effort to
find it. Also, I prompted my way to an improved simulator frontend.
So, what were the problems? There were only about half a dozen, and all of their fixes were only a few lines each. It’s probably not that interesting to go through each one, so I’ll just say that one of them was as simple as masking the least-significant bit of the PC when writing it. The smallest RISC-V instructions are in the C extension and are two bytes long. That means that jumping to any memory location whose address is divisible by two could be valid, so we have to accept it. Odd addresses are never valid, though, so we can guarantee that we’ll never jump to one by simply clearing the LSB of the PC every time we change it. This is a good example of the kind of thing that I wouldn’t have thought to check for, and it’s really nice to have a curated test suite to rely on.
It’s worth noting that I still can’t be certain that my implementation is correct in all cases, but it’s certainly much more reliable than before. I wouldn’t use it for anything important, but it probably won’t fall over immediately either.
My next goal for this project is to add some kind of I/O. I think
I’ll try simulating a popular UART chip, map it into memory, and then
write some simulator code to bridge a TTY on the host OS into the
simulated UART. Then I’ll be able to get a prompt on
perilus, which opens up a lot of options. To do this
properly, I’ll need to implement a small amount of the privileged ISA,
which I’m still trying to understand. An unrelated and maybe more fun
short-term goal is to write some no_std Rust code, compile
it for RV32I, and run it on perilus.
The previous perilus simulator used the
ratatui crate to build up a simple TUI frontend. This
design has the advantage that no window abstraction is required, but it
also has limits that I don’t really want. The simulator is outside my
“learning boundary” for this project, by which I mean that I don’t care
to spend a lot of time working on it. I just want it to work so I can
focus on perilus itself. This makes it a good candidate for
a guided implementation with an LLM, so that’s exactly what I did. The
new version keeps roughly the same aesthetic but is a standalone GUI
application written with egui. I don’t think I’m doing
anything that’s strictly impossible with ratatui, but for
now this is just easier. Maybe in the future I’ll change my mind again
and cut it down to something more minimal.1
Anyway, the new simulator has some new features that I figured out I wanted after playing with it for a while. Most are ergonomic, like automatically scrolling to follow the PC or being able to step by instruction instead of only by cycle. I also added the ability to save and load the contents of memory, which I originally had been avoiding for “purity” reasons but have since relented on. My idea was to force myself to pretend like I was building this computer out of real components, but I realized that if I did that then I’d almost certainly have an EEPROM chip that I could use for nonvolatile storage of RAM contents. The only alternative would be to leave the circuit powered on (or the simulator process running) forever, which would make it difficult to change anything. So I’d probably come up with some way to save to EEPROM and load it back again later, and the analagous thing to do in the simulator is to operate on files. It’s all made up anyway, so I guess I don’t need to justify my reasoning to anyone, but I still feel like this is a reasonable compromise between the two extremes (i.e., monkish self-flagellation vs. unrestrained indulgence).
I’m no longer holding to a weekly schedule for projects like I did for most of 2026. It was fun but also kind of stressful, and I think it contributed to me burning out in late August. I’m still pretty stressed in other areas of my life, so I’m not going to set any kind of schedule for my projects anytime soon. Lately I’ve been feeling a bit better, so I’m going to take it slow and try not to overwhelm myself again.
I originally wanted to port the simulator to the web, but it looked like that would be pretty hard because it would mean cross-compiling the generated Verilator model source code. I might still try that in the future.↩︎