The idea is to debug a simple program on an emulated Rocket. The procedure is well defined on the officiel Rocket repository. This post basically summarizes the needed steps.
Generating the emulator
Let’s say you have a default rocket-chip
repository. You need to add a Remote Bit-Bang client in the emulator by modifying src/main/scala/system/Configs.scala
:
@@ -86,3 +86,4 @@ class MMIOPortOnlyConfig extends Config(
class BaseFPGAConfig extends Config(new BaseConfig ++ new WithCoherentBusTopology)
class DefaultFPGAConfig extends Config(new WithNSmallCores(1) ++ new BaseFPGAConfig)
+class DefaultConfigRBB extends Config(new WithJtagDTMSystem ++ new WithNBigCores(1) ++ new WithCoherentBusTopology ++ new BaseConfig)
Building the emulator
rocket-chip$ cd emulator
emulator$ CONFIG=freechips.rocketchip.system.DefaultConfigRBB make
Compiling a test program
char text[] = "Vafgehpgvba frgf jnag gb or serr!";
// Don't use the stack, because sp isn't set up.
volatile int wait = 1;
int main()
{
while (wait)
;
// Doesn't actually go on the stack, because there are lots of GPRs.
int i = 0;
while (text[i]) {
char lower = text[i] | 32;
if (lower >= 'a' && lower <= 'm')
text[i] += 13;
else if (lower > 'm' && lower <= 'z')
text[i] -= 13;
i++;
}
while (!wait)
;
}
This C code (which performs a ROT13 transformation) can be saved in a hello_world.c
file. In order to compile it, it is assumed to the same settings as for riscv-tests
. In this case, it is assumed we modified this C code and that debug symbols were added in the Makefile.