1
0
rocket-chip/README.md

473 lines
20 KiB
Markdown
Raw Normal View History

2015-08-26 23:34:22 +02:00
Rocket Chip Generator [![Build Status](https://travis-ci.org/ucb-bar/rocket-chip.svg?branch=master)](https://travis-ci.org/ucb-bar/rocket-chip)
2014-09-12 19:15:04 +02:00
=====================
This repository contains the Rocket chip generator necessary to instantiate
2016-04-20 00:24:13 +02:00
the RISC-V Rocket Core. For more information on Rocket Chip, please consult our [technical report](http://www.eecs.berkeley.edu/Pubs/TechRpts/2016/EECS-2016-17.html).
2014-09-12 19:15:04 +02:00
2014-10-07 11:07:39 +02:00
## Table of Contents
2014-09-12 19:22:00 +02:00
2014-10-07 11:07:39 +02:00
+ [Quick instructions](#quick) 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?](#what)
+ [How should I use the Rocket chip generator?](#how)
2014-10-07 12:54:30 +02:00
+ [Using the high-performance cycle-accurate C++ emulator](#emulator)
+ [Mapping a Rocket core down to an FPGA](#fpga)
+ [Pushing a Rocket core through the VLSI tools](#vlsi)
2014-10-07 11:07:39 +02:00
+ [How can I parameterize my Rocket chip?](#param)
+ [Contributors](#contributors)
2014-09-12 19:15:04 +02:00
2014-10-07 11:07:39 +02:00
## <a name="quick"></a> Quick Instructions
2014-08-07 23:50:31 +02:00
2014-10-07 11:07:39 +02:00
### Checkout The Code
2014-08-07 23:50:31 +02:00
2014-10-07 11:05:20 +02:00
$ git clone https://github.com/ucb-bar/rocket-chip.git
$ cd rocket-chip
2014-10-07 11:07:39 +02:00
$ git submodule update --init
2014-08-07 23:50:31 +02:00
2014-10-07 11:07:39 +02:00
### Setting up the RISCV environment variable
2014-08-07 23:50:31 +02:00
2014-10-07 11:07:39 +02:00
To build the rocket-chip repository, you must point the RISCV
environment variable to your riscv-tools installation directory.
2014-08-07 23:50:31 +02:00
$ 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
$ ./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](https://github.com/riscv/riscv-tools/blob/master/README.md).
2014-08-07 23:50:31 +02:00
2014-10-07 11:07:39 +02:00
### Building The Project
2014-08-07 23:50:31 +02:00
2015-07-16 01:25:04 +02:00
First, to build the C simulator:
2014-08-07 23:50:31 +02:00
$ cd emulator
$ make
2015-07-16 01:25:04 +02:00
Or to build the VCS simulator:
2014-08-07 23:50:31 +02:00
2014-09-01 05:57:16 +02:00
$ cd vsim
2014-08-07 23:50:31 +02:00
$ make
2014-10-07 11:07:39 +02:00
In either case, you can run a set of assembly tests or simple benchmarks
(Assuming you have N cores on your host system):
2014-08-07 23:50:31 +02:00
2014-10-07 11:07:39 +02:00
$ make -jN run-asm-tests
2015-07-16 01:25:04 +02:00
$ make -jN run-bmark-tests
2014-08-07 23:50:31 +02:00
To build a C simulator that is capable of VCD waveform generation:
$ cd emulator
2014-09-12 09:19:29 +02:00
$ make debug
2014-08-07 23:50:31 +02:00
And to run the assembly tests on the C simulator and generate waveforms:
2014-10-07 11:07:39 +02:00
$ make -jN run-asm-tests-debug
2015-07-16 01:25:04 +02:00
$ make -jN run-bmark-tests-debug
2014-08-07 23:50:31 +02:00
To generate FPGA- or VLSI-synthesizable verilog (output will be in `vsim/generated-src`):
2014-08-07 23:50:31 +02:00
2014-10-07 11:07:39 +02:00
$ cd vsim
$ make verilog
2014-08-07 23:50:31 +02:00
### Keeping Your Repo Up-to-Date
2014-08-07 23:50:31 +02:00
If you are trying to keep your repo up to date with this github repo,
you also need to keep the submodules and tools up to date.
$ # Get the newest versions of the files in this repo
2014-08-07 23:50:31 +02:00
$ git pull origin master
$ # Make sure the submodules have the correct versions
$ git submodule update --init --recursive
If riscv-tools version changes, you should recompile and install riscv-tools according to the directions in the [riscv-tools/README](https://github.com/riscv/riscv-tools/blob/master/README.md).
$ cd riscv-tools
$ ./build.sh
$ ./build-rv32ima.sh (if you are using RV32)
2014-10-07 11:07:39 +02:00
## <a name="what"></a> What's in the Rocket chip generator repository?
The rocket-chip repository is the head git repository that points to
many sub-repositories (e.g. the riscv-tools repository) using [git
submodules](http://git-scm.com/book/en/Git-Tools-Submodules). While
we're aware of the ongoing debate as to how meta-projects should be
managed (i.e. a big monolithic repository vs. smaller repositories
tracked as submodules), we've found that for our chip-building projects
at Berkeley, the ability to compose a subset of private and public
sub-repositories on a per-chip basis is a killer feature of git
submodule.
### <a name="what_submodules"></a>The Submodules
2014-10-07 11:07:39 +02:00
Here's a look at all the git submodules that are currently tracked in
the rocket-chip repository:
* **chisel3**
([https://github.com/ucb-bar/chisel3](https://github.com/ucb-bar/chisel3)):
At Berkeley, we write RTL in Chisel. For those who are not familiar
2014-10-07 11:07:39 +02:00
with Chisel, please go take a look at
[http://chisel.eecs.berkeley.edu](http://chisel.eecs.berkeley.edu). We
have submoduled a specific git commit tag of the Chisel compiler rather
than pointing to a versioned Chisel release as an external dependency;
so far we were developing Chisel and the rocket core at the same time,
and hence it was easiest to use submodule to track bleeding edge commits
to Chisel, which contained a bunch of new features and bug fixes. As
Chisel gets more stable, we will likely replace this submodule with an
external dependency.
* **firrtl**
([https://github.com/ucb-bar/firrtl](https://github.com/ucb-bar/firrtl)):
FIRRTL (Flexible Internal Representation for RTL) is the intermediate format
which Chisel3 is based upon. The Chisel3 compiler generates a FIRRTL representation,
from which the final product (Verilog code, C code, etc) is generated.
2014-10-07 11:07:39 +02:00
* **hardfloat**
([https://github.com/ucb-bar/berkeley-hardfloat](https://github.com/ucb-bar/berkeley-hardfloat)):
This repository holds the parameterized IEEE 754-2008 compliant
floating-point units for fused multiply-add operations, conversions
between integer and floating-point numbers, and conversions between
floating-point conversions with different precision. The floating-point
units in this repository work on an internal recoded format (exponent
has an additional bit) to handle subnormal numbers more efficiently in
the processor. Please take a look at the
[README](https://github.com/ucb-bar/berkeley-hardfloat/blob/master/README.md)
in the repository for more information.
* **riscv-tools**
2015-02-17 23:43:11 +01:00
([https://github.com/riscv/riscv-tools](https://github.com/riscv/riscv-tools)):
2014-10-07 11:07:39 +02:00
We tag a version of riscv-tools that works with the RTL committed in the
rocket-chip repository. Once the software toolchain stabilizes, we
might turn this submodule into an external dependency.
* **torture**
([https://github.com/ucb-bar/torture](https://github.com/ucb-bar/torture)):
The torture test code is used to generate randomized instruction streams which
are then run as code on the rocket core(s). These are constrained random tests
to stress-test both the core and uncore portions of the design.
### <a name="what_submodules"></a>The Sub Packages
In addition to submodules, which are tracked as different git repositories,
the rocket-chip Chisel code base is factored into a number of Scala packages.
2016-08-19 20:39:30 +02:00
Here is a brief description of what can be found in each package:
* **rocket**
2016-08-19 20:39:30 +02:00
The rocket package holds the actual source code of the Rocket core.
Note that the L1 blocking I$ and the L1 non-blocking D$ are considered
part of the core, and hence we keep the L1 cache source code in this
repository. This repository is not meant to stand alone; it needs to be
included in a chip repository (e.g. rocket-chip) that instantiates the
core within a memory system and connects it to the outside world.
* **uncore**
2016-08-19 20:39:30 +02:00
This package implements the uncore logic, such as the L2 coherence hub
(the agent that keeps multiple L1 D$ coherent). The definition of the
coherent interfaces between tiles ("tilelink") and the debug interface
also live in this repository.
* **junctions**
2016-08-19 20:39:30 +02:00
This package contains code and
converters for various bus protocols and interfaces.
* **groundtest**
2016-08-19 20:39:30 +02:00
This package contains code which can test the uncore by generating randomized
instruction streams. It replaces the rocket processor with an instruction
stream generator to stress-test the uncore portions of the design.
2016-08-19 20:39:30 +02:00
* **coreplex**
This package pieces together the parts of a working coreplex, including
the rocket tiles, L1-to-L2 network, L2 coherence agents, and internal devices
like the debug unit and boot ROM.
* **rocketchip**
The top-level package instantiates the coreplex and drops in any
external-facing devices. It also includes clock-crossers and converters
from TileLink to external bus protocols (like AXI or AHB).
### <a name="what_toplevel"></a>The Top Level Module
2016-08-19 20:39:30 +02:00
Take a look at the src/main/scala/rocketchip directory.
This directory has the Chisel source files including the top level
2016-08-19 20:39:30 +02:00
RocketChip.scala.
2014-10-07 11:07:39 +02:00
Take a look at the top-level I/O pins. Open up
2016-08-19 20:39:30 +02:00
src/main/scala/rocketchip/RocketChip.scala, and search for TopIO.
You will read the following:
/** Top-level io for the chip */
class BasicTopIO(implicit val p: Parameters) extends ParameterizedBundle()(p)
with HasTopLevelParameters
class TopIO(implicit p: Parameters) extends BasicTopIO()(p) {
val mem_axi = Vec(nMemAXIChannels, new NastiIO)
val mem_ahb = Vec(nMemAHBChannels, new HastiMasterIO)
val interrupts = Vec(p(NExtInterrupts), Bool()).asInput
val mmio_axi = Vec(p(NExtMMIOAXIChannels), new NastiIO)
val mmio_ahb = Vec(p(NExtMMIOAHBChannels), new HastiMasterIO)
val debug = new DebugBusIO()(p).flip
2014-10-07 11:07:39 +02:00
}
2016-06-29 00:23:32 +02:00
There are 4 major I/O ports coming out of the top-level module:
2014-10-07 11:07:39 +02:00
* **Debug interface (debug)**:
The debug interface can be used to both debug the processor as
it is executing, and to read and write memory.
* **High-performance memory interface (mem_\*)**:
Memory requests from the processor comes out the mem_\* ports.
Depending on the configuration of the design, these may be visible as
AXI or AHB protocol. The mem_\* port(s) uses the same uncore clock, and
2014-10-07 11:07:39 +02:00
is intended to be connected to something on the same chip.
* **Memory mapped I/O interface (mmio_\*)**:
The optional mmio_\* interfaces can be used to communicate with devices
on the chip but outside of the rocket-chip boundary. Depending on the
configuration of the design, these may be visible as AXI or AHB.
* **Interrupts interface (interrupts)**: This interface is used to
deliver external interrupts to the processor core.
2014-10-07 11:07:39 +02:00
## <a name="how"></a> How should I use the Rocket chip generator?
Chisel can generate code for three targets: a high-performance
cycle-accurate C++ emulator, Verilog optimized for FPGAs, and Verilog
for VLSI. The rocket-chip generator can target all three backends. You
2014-10-07 11:07:39 +02:00
will need a Java runtime installed on your machine, since Chisel is
overlaid on top of [Scala](http://www.scala-lang.org/). 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.
$ git clone https://github.com/ucb-bar/rocket-chip.git
$ cd rocket-chip
$ export ROCKETCHIP=`pwd`
2014-10-07 11:05:20 +02:00
$ git submodule update --init
$ cd riscv-tools
$ git submodule update --init --recursive riscv-tests
2014-10-07 11:07:39 +02:00
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
2015-02-17 23:43:11 +01:00
[riscv-tools/README](https://github.com/riscv/riscv-tools/blob/master/README.md).
2014-10-07 11:07:39 +02:00
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.
### <a name="emulator"></a> 1) Using the high-performance cycle-accurate C++ emulator
Your next step is to get the C++ emulator working. Assuming you have N
cores on your host system, do the following:
$ 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!
2014-10-07 11:05:20 +02:00
You can also run assembly tests and benchmarks separately:
$ make -jN run-asm-tests
$ make -jN run-bmark-tests
2014-10-07 11:05:20 +02:00
2014-10-07 11:09:17 +02:00
To generate vcd waveforms, you can run one of the following commands:
2014-10-07 11:05:20 +02:00
$ make -jN run-debug
$ make -jN run-asm-tests-debug
$ make -jN run-bmark-tests-debug
2014-10-07 11:05:20 +02:00
Or call out individual assembly tests or benchmarks:
$ make output/rv64ui-p-add.out
$ make output/rv64ui-p-add.vcd
2014-10-07 11:07:39 +02:00
Now take a look in the emulator/generated-src directory. You will find
Chisel generated C++ code.
$ ls $ROCKETCHIP/emulator/generated-src
2016-05-25 20:08:11 +02:00
Top.DefaultConfig-0.cpp
Top.DefaultConfig-0.o
Top.DefaultConfig-1.cpp
Top.DefaultConfig-1.o
Top.DefaultConfig-2.cpp
Top.DefaultConfig-2.o
Top.DefaultConfig-3.cpp
Top.DefaultConfig-3.o
Top.DefaultConfig-4.cpp
Top.DefaultConfig-4.o
Top.DefaultConfig-5.cpp
Top.DefaultConfig-5.o
Top.DefaultConfig.cpp
Top.DefaultConfig.h
2014-10-07 11:07:39 +02:00
emulator.h
emulator_api.h
emulator_mod.h
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
2014-10-07 11:07:39 +02:00
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.
### <a name="fpga"></a> 2) Mapping a Rocket core to an FPGA
2014-10-07 11:07:39 +02:00
We use Synopsys VCS for Verilog simulation. We acknowledge that using a
proprietary Verilog simulation tool for an open-source project is not
ideal; we ask the community to help us move DirectC routines (VCS's way
of gluing Verilog testbenches to arbitrary C/C++ code) into DPI/VPI
2014-10-08 01:46:48 +02:00
routines so that we can make Verilog simulation work with an open-source
2014-10-07 11:07:39 +02:00
Verilog simulator. In the meantime, you can use the C++ emulator to
generate vcd waveforms, which you can view with an open-source waveform
viewer such as GTKWave.
You can generate synthesizable Verilog with the following commands:
2014-10-07 11:07:39 +02:00
$ cd $ROCKETCHIP/vsim
$ make verilog CONFIG=DefaultFPGAConfig
2014-10-07 11:07:39 +02:00
The Verilog used for the FPGA tools will be generated in
vsim/generated-src. Please proceed further with the directions shown in
2014-10-07 11:07:39 +02:00
the [README](https://github.com/ucb-bar/fpga-zynq/blob/master/README.md)
of the fpga-zynq repository.
However, if you have access to VCS, you will be able to 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 CONFIG=DefaultFPGAConfig
2014-10-07 11:07:39 +02:00
The generated output looks similar to those generated from the emulator.
Look into vsim/output/\*.out for the output of the executed assembly
2014-10-07 11:07:39 +02:00
tests and benchmarks.
### <a name="vlsi"></a> 3) Pushing a Rocket core through the VLSI tools
You can generate Verilog for your VLSI flow with the following commands:
$ cd $ROCKETCHIP/vsim
$ make verilog
Now take a look at vsim/generated-src, and the contents of the
2016-05-25 20:08:11 +02:00
Top.DefaultConfig.conf file:
2014-10-07 11:07:39 +02:00
$ cd $ROCKETCHIP/vsim/generated-src
2016-05-25 20:08:11 +02:00
Top.DefaultConfig.conf
Top.DefaultConfig.prm
Top.DefaultConfig.v
consts.DefaultConfig.vh
2014-10-07 11:07:39 +02:00
$ cat $ROCKETCHIP/vsim/generated-src/*.conf
name MetadataArray_tag_arr depth 128 width 84 ports mwrite,read mask_gran 21
name ICache_tag_array depth 128 width 38 ports mrw mask_gran 19
name DataArray_T6 depth 512 width 128 ports mwrite,read mask_gran 64
name HellaFlowQueue_ram depth 32 width 133 ports write,read
name ICache_T157 depth 512 width 128 ports rw
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
2016-05-25 20:08:11 +02:00
vsim/generated-src/Top.DefaultConfig.v. To target vendor-specific
2014-10-07 11:07:39 +02:00
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.
## <a name="param"></a> How can I parameterize my Rocket chip?
2016-05-25 20:08:11 +02:00
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
2016-05-25 20:08:11 +02:00
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.
2014-10-07 11:07:39 +02:00
Further down, you will be able to see two FPGA configurations:
2014-10-07 11:05:20 +02:00
DefaultFPGAConfig and DefaultFPGASmallConfig. DefaultFPGAConfig inherits from
2016-05-25 20:08:11 +02:00
BaseConfig, but overrides the low-performance memory port (i.e., backup
2014-10-07 11:05:20 +02:00
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 ExampleSmallConfig inherits all
2016-05-25 20:08:11 +02:00
parameters from BaseConfig but overrides the same parameters of
2014-10-07 11:05:20 +02:00
SmallConfig.
2014-10-07 11:07:39 +02:00
Now take a look at vsim/Makefile. Search for the CONFIG variable.
By default, it is set to DefaultConfig. You can also change the
2014-10-07 11:07:39 +02:00
CONFIG variable on the make command line:
$ cd $ROCKETCHIP/vsim
2014-10-07 11:05:20 +02:00
$ make -jN CONFIG=ExampleSmallConfig run-asm-tests
2014-10-07 11:07:39 +02:00
Or, even by defining CONFIG as an environment variable:
2014-10-07 11:05:20 +02:00
$ export CONFIG=ExampleSmallConfig
$ make -jN run-asm-tests
2014-10-07 11:07:39 +02:00
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
class WithNExtInterrupts extends Config (nExt: Int) {
(pname, site, here) => pname match {
case (NExtInterrupts => nExt)
}
}
class MyConfig extends Config (new WithNExtInterrupts(16) ++ new DefaultSmallConfig)
Then you can build as usual with CONFIG=MyConfig.
2014-10-07 11:07:39 +02:00
## <a name="contributors"></a> Contributors
- Scott Beamer
- Henry Cook
- Yunsup Lee
- Stephen Twigg
- Huy Vo
- Andrew Waterman
2016-04-20 00:24:13 +02:00
## <a name="attribution"></a> 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](http://www.eecs.berkeley.edu/Pubs/TechRpts/2016/EECS-2016-17.html)_, Technical Report UCB/EECS-2016-17, EECS Department, University of California, Berkeley, April 2016