Skip to content

Latest commit

 

History

History
135 lines (101 loc) · 5.68 KB

appendix_a.adoc

File metadata and controls

135 lines (101 loc) · 5.68 KB

Appendix A: Venus

Venus is the simulator that is used by UC Berkeley’s CS 61C course. It’s nowhere near as nice nor as full featured as RARS and currently seems poorly documented and maintained.

UC Berkeley is the designer of RISC-V and so was one of the first colleges to start teaching RISC-V, years before RARS existed. Given that they’ve built up a curriculum around Venus and invested at least a little in their own fork it makes sense that they’d be hesitant to switch.

In any case, this appendix will go over the most important differences between Venus and RARS.

Versions and History

Unlike RARS which seems to have one primary and fairly well maintained stable version, and a few even more updated forks, Venus is less clear. As far as I can tell it was started by kvakil 5 years ago, was forked by ThaumicMekanism, and finally was forked by Berkeley for their cs61c course. While the latter has the most recent commit none of them are what I would call well maintained, with the former 2 seeming to stall in 2018 and 2020 respectively. Venus (all versions) has a web based interface but I don’t know why anyone would prefer that to the standalone JAR version.

As of the end of 2022 you can get Venus jar files from ThaumicMekanism’s github here or from Berkeley’s course website here.

I don’t know what the minor differences are between them but you should use whatever is provided by the course if you’re taking it.

Data section

The documentation is sorely lacking and out of date but the most relevant differences from RARS are that it uses .asciiz instead of .asciz and while .float and .double are reserved, Venus doesn’t actually support floating point instructions so you can’t actually do anything with them.

The only documentation I can find is from ThaumicMekanism’s wiki and it doesn’t mention .space even though Venus seems to allow it.[1] CS61C’s documentation doesn’t mention data directives at all.[2]

Environment Calls

Venus only supports a handful of ecalls and they work differently than they do in RARS. Again, the only documentation I can find is ThaumicMekanism’s.[3]

There is one that I know of that is not listed in that table. Ecall 5 is basically the C function atoi which converts a string to an integer. It takes the address of the string in a1 and returns the number in a0. If there is any leading or trailing whitespace or the string isn’t a valid number it returns 0.

One thing you might have noticed is that Venus doesn’t support any of the input ecalls. This is extremely limiting since you can’t write any interactive programs and to test a function you have to actually change the program (usually a variable in the data section) and re-run it. The only way to even get variable program behavior is to use the file input capability to read data and do something different based on that input.

But aside from the lack of some basic ecalls, there’s also a behavioral difference in how they work. In RARS, you use a7 to select the ecall leaving the lower a registers for arguments which matches how you would pass arguments to a function. Venus uses a0 to select the ecall which means your argument(s) start in a1. This is probably why they provide wrapper functions for the ecalls to students for their projects, though it took until recently to get them right.

So, what does this look like in practice? Let’s take the simple command line argument program from chapter 7 and convert it for Venus. So the following program:

link:code/args.s[role=include]

becomes

link:code/args_venus.s[role=include]

Note that we had to save argv beacuse a1 is now used in our ecalls. In addition the behavior is different than RARS:

$ java -jar ~/venus-jvm-latest.jar args_venus.s
There are 0 command line arguments:
$ java -jar ~/venus-jvm-latest.jar args_venus.s hello
There are 2 command line arguments:
args_venus.s
hello

RARS may have decided not to include the program name/"executable" in its arguments but at least it is consistent in its behavior. In addition, the section on passing arguments in CS 61C’s documentation is inaccurate as of December 2022. Just like with C and RARS, argc comes first in a0 then argv in a1, not the other way around as described.[4]

Constants

Another minor difference from RARS is how you declare constants. In Venus you use the same syntax as C, so the constants example from chapter 7:

link:code/constants_rars.s[role=include]

becomes

link:code/constants_venus.s[role=include]

Conclusion

While most of this book applies equally well to both programs (other than chapter 6 of course) and to RISC-V in general, this appendix should clear up any difficulties you might have run into trying to convert the examples to run in Venus. Hopefully Berkeley will decide to switch to RARS eventually.


3. Funny enough the Wiki link on cs61c’s Venus is empty and their own documentation, entirely focused on the web version, links to ThaumicMekanism’s wiki