1 # New tutorial for setting up Microwatt chroot and running simulations
5 * Libre-SOC page covering our workflow: [[HDL_workflow]]
6 * Devscripts Libre-SOC page: [[devscripts]]
7 * Original Microwatt Libre-SOC page: [[microwatt]]
8 * [Libre-SOC Microwatt repo branch](https://git.libre-soc.org/?p=microwatt.git;a=tree;hb=refs/heads/verilator_trace)
9 * [Libre-SOC devscripts repo](https://git.libre-soc.org/?p=dev-env-setup.git;a=tree)
10 * [Verilator docs, commands](https://verilator.org/guide/latest/exe_verilator.html)
11 * [Verilator runtime command documentation](https://verilator.org/guide/latest/exe_sim.html)
12 * First steps for working with PowerISA instructions Libre-SOC page:
15 ## Development environment scripts
17 If you haven't already, clone Libre-SOC's development environment setup scripts.
18 These are bash scripts, and greatly simplify the time it takes to create a:
21 - With all software and libraries at specific versions
22 (which are known to work).
24 These attributes are absolutely critical, and no support will be
25 provided, unless you use these scripts to setup a development environment. This
26 helps us fix any bugs in the scripts, and make sure everyone runs on the same
29 $ git clone https://git.libre-soc.org/git/dev-env-setup.git
32 [code](https://git.libre-soc.org/?p=dev-env-setup.git;a=tree) before running
33 any of those scripts. They may be confusing, however after reading a few you'll
34 start to become more familiar with them.
36 It is expected for you to use Debian, we mostly use 11 (Bullseye) for the host
37 OS, while all the chroots run Debian 10 (Buster).
42 Commands to run in terminal to setup a new chroot environment for microwatt
47 # ./mk-deb-chroot microwatt
48 # ./cp-scripts-to-chroot microwatt
51 (microwatt):$ cd dev-env-setup
52 (microwatt):$ sudo bash
53 (microwatt):# ./install-hdl-apt-reqs
54 (microwatt):# ./verilator-install
55 (microwatt):# ./hdl-tools-yosys
56 (microwatt):# apt install gtkwave -y
58 (microwatt):$ cd ~/src/
59 (microwatt):$ git clone https://git.libre-soc.org/git/microwatt.git
60 (microwatt):$ cd microwatt
61 (microwatt):$ git checkout verilator_trace
63 Make sure verilator binaries in $PATH:
65 (microwatt):$ export PATH=/usr/local/verilator/bin:$PATH
66 (microwatt):$ export GHDLSYNTH=ghdl
68 (GHDLSYNTH needs to be redefined because the Makefile has default `ghdl.so`,
69 but somewhere else '.so' gets appended. You may see the following error if you
71 `ERROR: Can't load module
72 ./ghdl.so':/usr/local/bin/../share/yosys/plugins/**ghdl.so.so**`)
73 [IRC](https://libre-soc.org/irclog/%23libre-soc.2023-01-25.log.html#t2023-01-25T11:10:47)
75 ## Compiling the verilator sim for Microwatt
77 * [Libre-SOC Microwatt repo branch, Makefile](https://git.libre-soc.org/?p=microwatt.git;a=blob;f=Makefile;h=b764793fcdf5409be33a01f2440cea3717cb2a32;hb=refs/heads/verilator_trace)
79 Verilator creates a fairly fast simulation by converting the HDL design to C++,
80 and then compiling a binary which the user runs.
82 To compile the verilator simulation, first set verilator as the target for the
85 (microwatt):$ export FPGA_TARGET=verilator
87 Before compiling, you can change the `THREADS` variable in the makefile, which
88 will allow the compiled verilator simulation binary to use more than 1 thread
89 (*make sure to check how many CPU threads you have before changing this!*)
91 To compile the verilator simulation binary, call make with the
92 `microwatt-verilator` rule.
94 (microwatt):$ make microwatt-verilator
98 ## Compiling hello world code
100 We need some to actually run on the core, so...?
101 Instructions assume you're still in the microwatt directory.
103 (microwatt):$ cd hello_world
106 A `hello_world.bin` should be generated (the final binary to be loaded), as
107 well as an [.elf file](https://en.wikipedia.org/wiki/Executable_and_Linkable_Format),
108 and .hex (representing the binary data as hex text strings).
110 To view the symbol table (useful to see where various sections of the binary
113 (microwatt):$ powerpc64le-linux-gnu-objdump -h hello_world.elf
114 (microwatt):$ powerpc64le-linux-gnu-objdump -x hello_world.elf
116 `-h` shows just the section headers, `-x` shows all headers.
118 And to view the disassembly (great for learning about the PowerISA instructions,
119 and for associating the binary hex with actual instructions):
121 (microwatt):$ powerpc64le-linux-gnu-objdump -d hello_world.elf
123 For more information about `objdump` (common utility, not just for PowerISA),
124 see the manual pages.
126 (microwatt):$ man powerpc64le-linux-gnu-objdump
128 The binary is ready to go, now it can be loaded into the simulation.
130 ## Running the simulation
132 Run the `microwatt-verilator` binary, with `hello_world/hello_world.bin` as an
135 (microwatt):$ time ./microwatt-verilator hello_world/hello_world.bin
137 `time` is a utility you can use to measure how long it takes to run the sim.
139 A pretty ASCII art of a lightbulb should be printed, and then the user can type any characters, which will be echoed back. To end the simulation press Ctrl+c.
141 If no characters are appearing after about 20 seconds, stop the simulation,
142 as there might be other issues.
144 Single-threaded verilator sim binary, on a 2nd gen intel i5 (sandybridge)
145 takes 53 seconds to print the ASCII lightbulb.
147 ## Analysing results after simulation
149 The following files will be generated during the sim:
151 - `bram.dump` - Shows the PC address and instruction being executed. If the sim
152 hangs without any printing, view this file, as the processor may have hit an
153 exception etc. Grows in size as the sim runs.
155 - `bram.snapshot.[NUMBER]` - Snapshot files of the contents of bram, can be
156 used to resume the simulation. The number on the end corresponds to the tick
157 time (i.e. 'bram.snapshot.1999990'). Pass the tick number on the end of the
158 filename with the '-s' flag:
160 (microwatt):$ time ./microwatt-verilator hello_world/hello_world.bin -s 1999990
162 You'll get a message like this:
164 loading hello_world/hello_world.bin at 0x0 size 0x1888
165 loading bram.snapshot.1999990 at 0x0 size 0x10000000
168 These snapshots are generated at intervals of every 2,000,000 ticks.
170 - `verilator.save.[NUMBER]` - (TODO: Need to check) - Verilator model snapshot
173 - `microwatt-verilator.vcd` - (TODO: Need to check) - GTKWave waveform file,
174 allowing you to look at processor signals and transitions during simulation.
175 *Needs to be converted to fst file first*:
177 (microwatt):$ vcd2fst --vcdname=microwatt-verilator.vcd --fstname=microwatt-verilator.fst
178 (microwatt):$ gtkwave microwatt-verilator.fst
181 ## Verilator runtime commands
184 # Show the version of verilator being used
185 (microwatt):$ ./microwatt-verilator +verilator+version