Boom Template Github
Boom Template Github
Boom Template Github
com/freechipsproject/rocket-chip
freechipsproject / rocket-chip
Dismiss
Join GitHub today
GitHub is home to over 20 million developers working together to host and
review code, manage projects, and build software together.
Sign up
terpstra Merge pull request #1439 from freechipsproject/wcorrupt … Latest commit cf68d49 5 hours ago
bootrom bootrom: also setup SBI a0+a1 for when we hang (#617) a year ago
firrtl @ 997fb0a Bump firrtl to get bug fixes (#1336) 2 months ago
hardfloat @ 45f5ae1 bump hardfloat for scala 2.11.12 (#1216) 4 months ago
macros/src/main/scala ValName: 'lazy val' now also counts for providing a name 6 months ago
regression Export JTAG_DTM_ENABLE_SBA so env var is visible to RocketSim.py when… a month ago
.gitmodules rocketchip: bump all submodules (and remove cde) 2 years ago
.travis.yml Travis: rebalance some jobs. Schedule long jobs first and short jobs … 12 days ago
LICENSE.Berkeley scripts: two scripts to determine copyright holder of files 2 years ago
README.md Documenting emulator debugging process with GDB (#1415) 13 days ago
README.md
1 of 11 29/05/18, 8:11 PM
GitHub - freechipsproject/rocket-chip: Rocket C... https://github.com/freechipsproject/rocket-chip
This repository contains the Rocket chip generator necessary to instantiate the RISC-V Rocket Core. For more information on
Rocket Chip, please consult our technical report.
Table of Contents
Quick instructions for those who want to dive directly into the details without knowing exactly what's in the repository.
What's in the Rocket chip generator repository?
How should I use the Rocket chip generator?
Using the cycle-accurate Verilator simulation
Mapping a Rocket core down to an FPGA
Pushing a Rocket core through the VLSI tools
How can I parameterize my Rocket chip?
Debugging with GDB
Contributors
Quick Instructions
$ export RISCV=/path/to/riscv/toolchain/installation
The riscv-tools repository is already included in rocket-chip as a Git submodule. You must build this version of riscv-tools:
$ cd rocket-chip/riscv-tools
$ git submodule update --init --recursive
$ export RISCV=/path/to/install/riscv/toolchain
$ export MAKEFLAGS="$MAKEFLAGS -jN" # Assuming you have N cores on your host system
$ ./build.sh
$ ./build-rv32ima.sh (if you are using RV32).
For more information (or if you run into any issues), please consult the riscv-tools/README.
$ cd emulator
$ make
$ cd vsim
$ make
2 of 11 29/05/18, 8:11 PM
GitHub - freechipsproject/rocket-chip: Rocket C... https://github.com/freechipsproject/rocket-chip
In either case, you can run a set of assembly tests or simple benchmarks (Assuming you have N cores on your host system):
$ cd emulator
$ make debug
And to run the assembly tests on the C simulator and generate waveforms:
$ cd vsim
$ make verilog
If riscv-tools version changes, you should recompile and install riscv-tools according to the directions in the riscv-
tools/README.
$ cd riscv-tools
$ ./build.sh
$ ./build-rv32ima.sh (if you are using RV32)
The rocket-chip repository is a meta-repository that points to several sub-repositories using Git submodules. Those
repositories contain tools needed to generate and test SoC designs. This respository also contains code that is used to
generate RTL. Hardware generation is done using Chisel, a hardware construction language embedded in Scala. The rocket-
chip generator is a Scala program that invokes the Chisel compiler in order to emit RTL describing a complete SoC. The
following sections describe the components of this repository.
Git Submodules
Git submodules allow you to keep a Git repository as a subdirectory of another Git repository. For projects being co-
developed with the Rocket Chip Generator, we have often found it expedient to track them as submodules, allowing for rapid
exploitation of new features while keeping commit histories separate. As submoduled projects adopt stable public APIs, we
transition them to external dependencies. Here are the submodules that are currently being tracked in the rocket-chip
repository:
chisel3 (https://github.com/ucb-bar/chisel3): The Rocket Chip Generator uses Chisel to generate RTL.
firrtl (https://github.com/ucb-bar/firrtl): Firrtl (Flexible Internal Representation for RTL) is the intermediate representation
of RTL constructions used by Chisel3. The Chisel3 compiler generates a Firrtl representation, from which the final
product (Verilog code, C code, etc) is generated.
hardfloat (https://github.com/ucb-bar/berkeley-hardfloat): Hardfloat holds Chisel code that generates parameterized
IEEE 754-2008 compliant floating-point units used for fused multiply-add operations, conversions between integer and
floating-point numbers, and conversions between floating-point conversions with different precision.
3 of 11 29/05/18, 8:11 PM
GitHub - freechipsproject/rocket-chip: Rocket C... https://github.com/freechipsproject/rocket-chip
riscv-tools (https://github.com/riscv/riscv-tools): We tag a version of the RISC-V software ecosystem that works with the
RTL committed in this repository.
torture (https://github.com/ucb-bar/riscv-torture): This module is used to generate and execute constrained random
instruction streams that can be used to stress-test both the core and uncore portions of the design.
Scala Packages
In addition to submodules that track independent Git repositories, the rocket-chip code base is itself factored into a number of
Scala packages. These packages are all found within the src/main/scala directory. Some of these packages provide Scala
utilities for generator configuration, while other contain the actual Chisel RTL generators themselves. Here is a brief
description of what can be found in each package:
amba This RTL package uses diplomacy to generate bus implementations of AMBA protocols, including AXI4, AHB-lite,
and APB.
config This utility package provides Scala interfaces for configuring a generator via a dynamically-scoped
parameterization library.
coreplex This RTL package generates a complete coreplex by gluing together a variety of components from other
packages, including: tiled Rocket cores, a system bus network, coherence agents, debug devices, interrupt handlers,
externally-facing peripherals, clock-crossers and converters from TileLink to external bus protocols (e.g. AXI or AHB).
devices This RTL package contains implementations for peripheral devices, including the Debug module and various TL
slaves.
diplomacy This utility package extends Chisel by allowing for two-phase hardware elaboration, in which certain
parameters are dynamically negotiated between modules. For more information about diplomacy, see this paper.
groundtest This RTL package generates synthesizable hardware testers that emit randomized memory access streams
in order to stress-tests the uncore memory hierarchy.
jtag This RTL package provides definitions for generating JTAG bus interfaces.
regmapper This utility package generates slave devices with a standardized interface for accessing their memory-
mapped registers.
rocket This RTL package generates the Rocket in-order pipelined core, as well as the L1 instruction and data caches.
This library is intended to be used by a chip generator that instantiates the core within a memory system and connects it
to the outside world.
tile This RTL package contains components that can be combined with cores to construct tiles, such as FPUs and
accelerators.
tilelink This RTL package uses diplomacy to generate bus implementations of the TileLink protocol. It also contains a
variety of adapters and protocol converters.
system This top-level utility package invokes Chisel to elaborate a particular configuration of a coreplex, along with the
appropriate testing collateral.
unittest This utility package contains a framework for generateing synthesizable hardware testers of individual modules.
util This utility package provides a variety of common Scala and Chisel constructs that are re-used across multiple other
packages,
Other Resources
Outside of Scala, we also provide a variety of resources to create a complete SoC implementation and test the generated
designs.
4 of 11 29/05/18, 8:11 PM
GitHub - freechipsproject/rocket-chip: Rocket C... https://github.com/freechipsproject/rocket-chip
Chisel can generate code for three targets: a high-performance cycle-accurate Verilator, Verilog optimized for FPGAs, and
Verilog for VLSI. The rocket-chip generator can target all three backends. You will need a Java runtime installed on your
machine, since Chisel is overlaid on top of Scala. Chisel RTL (i.e. rocket-chip source code) is a Scala program executing on
top of your Java runtime. To begin, ensure that the ROCKETCHIP environment variable points to the rocket-chip repository.
Before going any further, you must point the RISCV environment variable to your riscv-tools installation directory. If you do not
yet have riscv-tools installed, follow the directions in the riscv-tools/README.
export RISCV=/path/to/install/riscv/toolchain
Otherwise, you will see the following error message while executing any command in the rocket-chip generator:
*** Please set environment variable RISCV. Please take a look at README.
$ cd $ROCKETCHIP/emulator
$ make -jN run
By doing so, the build system will generate C++ code for the cycle-accurate emulator, compile the emulator, compile all
RISC-V assembly tests and benchmarks, and run both tests and benchmarks on the emulator. If Make finished without any
errors, it means that the generated Rocket chip has passed all assembly tests and benchmarks!
To generate vcd waveforms, you can run one of the following commands:
$ make output/rv64ui-p-add.out
$ make output/rv64ui-p-add.vcd
Now take a look in the emulator/generated-src directory. You will find Chisel generated Verilog code and its associated C++
code generated by Verilator.
$ ls $ROCKETCHIP/emulator/generated-src
DefaultConfig.dts
DefaultConfig.graphml
DefaultConfig.json
DefaultConfig.memmap.json
freechips.rocketchip.system.DefaultConfig
freechips.rocketchip.system.DefaultConfig.d
freechips.rocketchip.system.DefaultConfig.fir
5 of 11 29/05/18, 8:11 PM
GitHub - freechipsproject/rocket-chip: Rocket C... https://github.com/freechipsproject/rocket-chip
freechips.rocketchip.system.DefaultConfig.v
$ ls $ROCKETCHIP/emulator/generated-src/freechips.rocketchip.system.DefaultConfig
VTestHarness__1.cpp
VTestHarness__2.cpp
VTestHarness__3.cpp
...
Also, output of the executed assembly tests and benchmarks can be found at emulator/output/*.out. Each file has a cycle-by-
cycle dump of write-back stage of the pipeline. Here's an excerpt of emulator/output/rv64ui-p-add.out:
C0: 483 [1] pc=[00000002138] W[r 3=000000007fff7fff][1] R[r 1=000000007fffffff] R[r 2=ffffffffffff8000]
inst=[002081b3] add s1, ra, s0
C0: 484 [1] pc=[0000000213c] W[r29=000000007fff8000][1] R[r31=ffffffff80007ffe] R[r31=0000000000000005]
inst=[7fff8eb7] lui t3, 0x7fff8
C0: 485 [0] pc=[00000002140] W[r 0=0000000000000000][0] R[r 0=0000000000000000] R[r 0=0000000000000000]
inst=[00000000] unknown
The first [1] at cycle 483, core 0, shows that there's a valid instruction at PC 0x2138 in the writeback stage, which is
0x002081b3 (add s1, ra, s0). The second [1] tells us that the register file is writing r3 with the corresponding value 0x7fff7fff.
When the add instruction was in the decode stage, the pipeline had read r1 and r2 with the corresponding values next to it.
Similarly at cycle 484, there's a valid instruction (lui instruction) at PC 0x213c in the writeback stage. At cycle 485, there isn't
a valid instruction in the writeback stage, perhaps, because of a instruction cache miss at PC 0x2140.
$ cd $ROCKETCHIP/vsim
$ make verilog CONFIG=DefaultFPGAConfig
The Verilog used for the FPGA tools will be generated in vsim/generated-src. Please proceed further with the directions
shown in the README of the fpga-zynq repository.
If you have access to VCS, you will be able to run assembly tests and benchmarks in simulation with the following commands
(again assuming you have N cores on your host machine):
$ cd $ROCKETCHIP/vsim
$ make -jN run CONFIG=DefaultFPGAConfig
The generated output looks similar to those generated from the emulator. Look into vsim/output/*.out for the output of the
executed assembly tests and benchmarks.
$ cd $ROCKETCHIP/vsim
$ make verilog
Now take a look at vsim/generated-src, and the contents of the Top.DefaultConfig.conf file:
$ cd $ROCKETCHIP/vsim/generated-src
DefaultConfig.dts
DefaultConfig.graphml
DefaultConfig.json
DefaultConfig.memmap.json
freechips.rocketchip.system.DefaultConfig.behav_srams.v
freechips.rocketchip.system.DefaultConfig.conf
freechips.rocketchip.system.DefaultConfig.d
freechips.rocketchip.system.DefaultConfig.fir
freechips.rocketchip.system.DefaultConfig.v
$ cat $ROCKETCHIP/vsim/generated-src/*.conf
name data_arrays_0_ext depth 512 width 256 ports mrw mask_gran 8
name tag_array_ext depth 64 width 88 ports mrw mask_gran 22
name tag_array_0_ext depth 64 width 84 ports mrw mask_gran 21
6 of 11 29/05/18, 8:11 PM
GitHub - freechipsproject/rocket-chip: Rocket C... https://github.com/freechipsproject/rocket-chip
The conf file contains information for all SRAMs instantiated in the flow. If you take a close look at the
$ROCKETCHIP/Makefrag, you will see that during Verilog generation, the build system calls a $(mem_gen) script with the
generated configuration file as an argument, which will fill in the Verilog for the SRAMs. Currently, the $(mem_gen) script
points to vsim/vlsi_mem_gen, which simply instantiates behavioral SRAMs. You will see those SRAMs being appended at the
end of vsim/generated-src/Top.DefaultConfig.v. To target vendor-specific SRAMs, you will need to make necessary changes
to vsim/vlsi_mem_gen.
Similarly, if you have access to VCS, you can run assembly tests and benchmarks with the following commands (again
assuming you have N cores on your host machine):
$ cd $ROCKETCHIP/vsim
$ make -jN run
The generated output looks similar to those generated from the emulator. Look into vsim/output/*.out for the output of the
executed assembly tests and benchmarks.
By now, you probably figured out that all generated files have a configuration name attached, e.g. DefaultConfig. Take a look
at src/main/scala/rocketchip/Configs.scala. Search for NSets and NWays defined in BaseConfig. You can change those
numbers to get a Rocket core with different cache parameters. For example, by changing L1I, NWays to 4, you will get a
32KB 4-way set-associative L1 instruction cache rather than a 16KB 2-way set-associative L1 instruction cache.
Further down, you will be able to see two FPGA configurations: DefaultFPGAConfig and DefaultFPGASmallConfig.
DefaultFPGAConfig inherits from BaseConfig, but overrides the low-performance memory port (i.e., backup memory port) to
be turned off. This is because the high-performance memory port is directly connected to the high-performance AXI interface
on the ZYNQ FPGA. DefaultFPGASmallConfig inherits from DefaultFPGAConfig, but changes the cache sizes, disables the
FPU, turns off the fast early-out multiplier and divider, and reduces the number of TLB entries (all defined in SmallConfig).
This small configuration is used for the Zybo FPGA board, which has the smallest ZYNQ part.
Towards the end, you can also find that DefaultSmallConfig inherits all parameters from BaseConfig but overrides the same
parameters of WithNSmallCores.
Now take a look at vsim/Makefile. Search for the CONFIG variable. By default, it is set to DefaultConfig. You can also change
the CONFIG variable on the make command line:
$ cd $ROCKETCHIP/vsim
$ make -jN CONFIG=DefaultSmallConfig run-asm-tests
$ export CONFIG=DefaultSmallConfig
$ make -jN run-asm-tests
This parameterization is one of the many strengths of processor generators written in Chisel, and will be more detailed in a
future blog post, so please stay tuned.
To override specific configuration items, such as the number of external interrupts, you can create your own Configuration(s)
and compose them with Config's ++ operator
7 of 11 29/05/18, 8:11 PM
GitHub - freechipsproject/rocket-chip: Rocket C... https://github.com/freechipsproject/rocket-chip
For that we need to add a Remote Bit-Bang client to the emulator. We can do so by extending our Config with
JtagDTMSystem, which will add a DebugTransportModuleJTAG to the DUT and connect a SimJTAG module in the Test
Harness. This will allow OpenOCD to interface with the emulator, and GDB can interface with OpenOCD. In the following
example we added this Config extension to the DefaultConfig:
rocket-chip$ cd emulator
emulator$ CONFIG=DefaultConfigRBB make
We can also build a debug version capable of generating VCD waveforms using the command:
int main()
{
while (wait)
;
while (!wait)
;
}
First we can test if your program executes well in the simple version of emulator before moving to debugging in step 3 :
$ ./emulator-freechips.rocketchip.system-DefaultConfig helloworld
8 of 11 29/05/18, 8:11 PM
GitHub - freechipsproject/rocket-chip: Rocket C... https://github.com/freechipsproject/rocket-chip
Additional verbose information (clock cycle, pc, instruction being executed) can be printed using the following command:
VCD output files can be obtained using the -debug version of the emulator and are specified using -v or --vcd=FILE
arguments. A detailed log file of all executed instructions can also be obtained from the emulator, this is an example:
Please note that generated VCD waveforms and execution log files can be very voluminous depending on the size of the .elf
file (i.e. code size + debugging symbols).
Please note also that the time it takes the emulator to load your program depends on executable size. Stripping the .elf
executable will unsurprisingly make it run faster. For this you can use $RISCV/bin/riscv64-unknown-elf-strip tool to
reduce the size. This is good for accelerating your simulation but not for debugging. Keep in mind that the HTIF
communication interface between our system and the emulator relies on tohost and fromhost symbols to communicate.
This is why you may get the following error when you try to run a totally stripped executable on the emulator:
$ ./emulator-freechips.rocketchip.system-DefaultConfig totally-stripped-helloworld
This emulator compiled with JTAG Remote Bitbang client. To enable, use +jtag_rbb_enable=1.
Listening on port 46529
warning: tohost and fromhost symbols not in ELF; can't communicate with target
To resolve this, we need to strip all the .elf executable but keep tohost and fromhost symbols using the following
command:
The interest of this step is to make sure your program executes well. To perform debugging you need the original unstripped
version, as explained in step 3.
You can also use the emulator-freechips.rocketchip.system-DefaultConfigRBB-debug version instead if you would like
to generate VCD waveforms.
Please note that if the argument --rbb-port is not passed, a default free TCP port on your computer will be chosen
randomly.
Please note also that when debugging with GDB, the .elf file is not actually loaded by the FESVR. In contrast with Spike, it
must be loaded from GDB as explained in step 5. So the helloworld argument may be replaced by any dummy name.
4) Launch OpenOCD
You will need a RISC-V Enabled OpenOCD binary. This is installed with riscv-tools in $(RISCV)/bin/openocd , or can be
compiled manually from riscv-openocd. OpenOCD requires a configuration file, in which we define the RBB port we will use,
which is in our case 9823 .
$ cat cemulator.cfg
interface remote_bitbang
9 of 11 29/05/18, 8:11 PM
GitHub - freechipsproject/rocket-chip: Rocket C... https://github.com/freechipsproject/rocket-chip
remote_bitbang_host localhost
remote_bitbang_port 9823
gdb_report_data_abort enable
init
halt
$(RISCV)/bin/openocd -f ./cemulator.cfg
Open On-Chip Debugger 0.10.0+dev-00112-g3c1c6e0 (2018-04-12-10:40)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
Warn : Adapter driver 'remote_bitbang' did not declare which transports it allows; assuming legacy JTAG-
only
Info : only one transport option; autoselect 'jtag'
Info : Initializing remote_bitbang driver
Info : Connecting to localhost:9823
Info : remote_bitbang driver initialized
Info : This adapter doesn't support configurable speed
Info : JTAG tap: riscv.cpu tap/device found: 0x00000001 (mfg: 0x000 (<invalid>), part: 0x0000, ver: 0x0)
Info : datacount=2 progbufsize=16
Info : Disabling abstract command reads from CSRs.
Info : Disabling abstract command writes to CSRs.
Info : [0] Found 1 triggers
Info : Examined RISC-V core; found 1 harts
Info : hart 0: XLEN=64, 1 triggers
Info : Listening on port 3333 for gdb connections
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
5) Launch GDB
In another terminal launch GDB and point to the elf file you would like to load then run it with the debugger (in this example,
helloworld ):
$ riscv64-unknown-elf-gdb helloworld
GNU gdb (GDB) 8.0.50.20170724-git
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-pc-linux-gnu --target=riscv64-unknown-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./proj1.out...done.
(gdb)
Compared to Spike, the C Emulator is very slow, so several problems may be encountered due to timeouts between issuing
commands and response from the emulator. To solve this problem, we increase the timeout with the GDB set
remotetimeout command.
After that we load our program by performing a load command. This automatically sets the $PC to the _start symbol in
our .elf file.
10 of 11 29/05/18, 8:11 PM
GitHub - freechipsproject/rocket-chip: Rocket C... https://github.com/freechipsproject/rocket-chip
^C
Program received signal SIGINT, Interrupt.
main (argc=0, argv=<optimized out>) at src/main.c:33
33 while (!wait)
(gdb) print wait
$4 = 0
(gdb) print text
$5 = "Instruction sets want to be free!"
(gdb)
Contributors
Attribution
If used for research, please cite Rocket Chip by the technical report:
Krste Asanović, Rimas Avižienis, Jonathan Bachrach, Scott Beamer, David Biancolin, Christopher Celio, Henry Cook, Palmer
Dabbelt, John Hauser, Adam Izraelevitz, Sagar Karandikar, Benjamin Keller, Donggyu Kim, John Koenig, Yunsup Lee, Eric
Love, Martin Maas, Albert Magyar, Howard Mao, Miquel Moreto, Albert Ou, David Patterson, Brian Richards, Colin Schmidt,
Stephen Twigg, Huy Vo, and Andrew Waterman, The Rocket Chip Generator, Technical Report UCB/EECS-2016-17, EECS
Department, University of California, Berkeley, April 2016
11 of 11 29/05/18, 8:11 PM