OpenCores
URL https://opencores.org/ocsvn/riscv_vhdl/riscv_vhdl/trunk

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [README.md] - Blame information for rev 3

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sergeykhbr
System-On-Chip template based on Rocket-chip (RISC-V ISA). VHDL implementation.
2
=====================
3
 
4
This repository provides open source System-on-Chip implementation based on
5
64-bits CPU "Rocket-chip" distributed under BSD license. SOC source files
6
either include general set of peripheries, FPGA CADs projects files, own
7
implementation of the Windows/Linux debugger and several examples that help
8
to run your firmware on almost any FPGA boards.
9
Satellite Navigation (GPS/GLONASS/Galileo) modules were stubbed in this
10
repository and can be requested on
11
[gnss-sensor.com](http://www.gnss-sensor.com).
12
 
13
 
14
## What is Rocket-chip and [RISC-V ISA](http://www.riscv.org)?
15
 
16
RISC-V (pronounced "risk-five") is a new instruction set architecture (ISA)
17
that was originally designed to support computer architecture research and
18
education and is now set become a standard open architecture for industry
19
implementations under the governance of the RISC-V Foundation. RISC-V was
20
originally developed in the Computer Science Division of the EECS Department
21
at the University of California, Berkeley.
22
 
23
Parameterized generator of the Rocket-chip can be found here:
24
[https://github.com/ucb-bar](https://github.com/ucb-bar)
25
 
26
## System-on-Chip structure and performance
27
 
28
SoC documentation in [.pdf](rocket_soc/docs/riscv_soc_descr.pdf) and
29
[.html](http://sergeykhbr.github.io/riscv_vhdl/) formats.
30
 
31
![SOC top](rocket_soc/docs/pics/soc_top_v5.png)
32
 
33
Performance analysis is based on
34
[**Dhrystone v2.1. benchmark**](http://fossies.org/linux/privat/old/dhrystone-2.1.tar.gz/)
35
that is very compact and entirely ported into Zephyr shell example.
36
You can run it yourself and verify results (see below).
37
 
38
**RISC-V Instruction simulator** - always one instruction per clock.
39
**FPGA SOC based on "Rocket" CPU** - single core/single issue 64-bits CPU
40
with disabled L1toL2 interconnect (Verilog generated from Scala sources).
41
**FPGA SOC based on "River" CPU** - single core/single issue 64-bits CPU is my own
42
implementation of RISC-V ISA (VHDL with SystemC as reference).
43
 
44
 
45
Target | usec per
1 dhry | Dhrystone
per sec | MHz,
max | FPU | OS | Optim.
46
-------|:-------------------:|:---------------------:|:------------:|:---:|----|----
47
RISC-V simulator v3.1       | 12.0 | **77257.0** | -   | No  | Zephyr 1.3 | -O2
48
FPGA SoC with "Rocket" v3.1 | 28.0 | **34964.0** | 60  | No  | Zephyr 1.3 | -O2
49
FPGA SoC with "Rocket" v4.0 | 40.7 | **24038.0** | 601  | Yes | Zephyr 1.5 | -O2
50
FPGA SoC with "River " v4.0 | 28.0 | **35259.0** | 601  | No | Zephyr 1.5 | -O2
51
RISC-V simulator v5.1       | 12.0 | **65652.0** | -   | No  | Zephyr 1.6 | -O0
52
RISC-V simulator v5.1       | 12.0 | **76719.0** | -   | No  | Zephyr 1.6 | -O2
53
FPGA SoC with "Rocket" v5.1 | 41.0 | **23999.0** | 601  | Yes | Zephyr 1.6 | -O2
54
FPGA SoC with "River" v5.1  | 28.0 | **35121.0** | 601  | No | Zephyr 1.6 | -O2
55
FPGA SoC with "LEON3" SPARC | 20.0 | **48229.0** | 60  | No | Bare metal | -O0
56
FPGA SoC with "LEON3" SPARC | 8.0 | **119515.0** | 60  | No | Bare metal | -O2
57
 
58
1 - Actual SoC frequency is 40 MHz (to meet FPU constrains) but
59
Dhrystone benchmark uses constant 60 MHz and high precision counter (in clock cycles)
60
to compute results in msec. Timer value doesn't depend of clock frequency.
61
You can find FPGA bit-files with Rocket and River CPUs in the repository. I am
62
also ready to share my framework for Leon3 SPARC V8 processor (SoC and FW) by request.
63
 
64
Access to all memory banks and peripheries in the same clock domain is always
65
one clock in this SOC (without wait-states). So, this benchmark
66
result (**Dhrystone per seconds**) shows performance of the CPU with integer
67
instructions and degradation of the CPI relative ideal (simulation) case.
68
 
69
   **In my opinion compiler affects on benchmark results much more than hardware
70
   architecture and there's a lot of work for RISC-V compiler developers.
71
   So, use as new compiler as possible.**
72
 
73
## Repository structure
74
 
75
This repository consists of three sub-projects each in own subfolder:
76
 
77
- **rocket_soc** is the folder with VHDL/Verilog sources of the SOC
78
  including synthesizable processors *"Rocket"* and *"River"* and peripheries.
79
  Source code is portable on almost any FPGA is due to the fact that
80
  technology dependant modules (like *PLL*, *IO-buffers*
81
  etc) instantiated inside of "virtual" components
82
  in a similar to Gailser's *[GRLIB](www.gailser.com)* way.
83
  Full SOC design without FPU occupies less than 5 % of FPGA resources (Virtex6).
84
  *"Rocket-chip"* CPU itself is the modern **64-bits processor
85
  with L1-cache, branch-predictor, MMU and virtualization support**.
86
  This sub-project also contains:
87
    * *fw*: directory with the bootloader and FW examples.
88
    * *fw_images*: directory with the ROM images in HEX-format.
89
    * *prj*: project files for different CADs (Xilinx ISE, ModelSim).
90
    * *tb*: VHDL testbech of the full system and utilities.
91
    * *bit_files*: Pre-built FPGA images for ML605 and KC705 boards.
92
- **zephyr** is the ported on RISC-V 64-bits operation system.
93
  Information about this Real-Time Operation System for Internet of
94
  Things Devices provided by [Zephyr Project](https://www.zephyrproject.org/).
95
  Early support for the Zephyr Project includes Intel Corporation,
96
  NXP Semiconductors N.V., Synopsys, Inc. and UbiquiOS Technology Limited.
97
- **debugger**. The last piece of the ready-to-use open HW/SW system is
98
  [Software Debugger (C++)](http://sergeykhbr.github.io/riscv_vhdl/sw_debugger_api_link.html)
99
  with the full system simulator available as a plug-in.
100
  Debugger interacts with the target (FPGA or Software Simulator)
101
  via [Ethernet](http://sergeykhbr.github.io/riscv_vhdl/eth_link.html)
102
  using EDCL protocol over UDP. To provide this functionality SOC includes
103
  [**10/100 Ethernet MAC with EDCL**](http://sergeykhbr.github.io/riscv_vhdl/eth_link.html)
104
  and [**Debug Support Unit (DSU)**](http://sergeykhbr.github.io/riscv_vhdl/periphery_page_1.html)
105
  devices on AMBA AXI4 bus.
106
- **RISC-V "River" core**. It's my own implementation of RISC-V ISA that is ideal
107
  for embedded application with active usage of 64-bits computations
108
  (DSP for Satellite Navigation). I've specified the following principles for myself:
109
    1. Unified Verification Methodology (UVM)
110
        - */debugger/cpu_fnc_plugin*  - Functional RISC-V CPU model.
111
        - */debugger/cpu_sysc_plugin* - Precise SystemC RIVER CPU model.
112
        - */rocket_soc/riverlib*      - RIVER VHDL sources with VCD-stimulus from SystemC.
113
    2. Advanced debugging features: bus tracing, pipeline statistic (like CPI) in real-time on HW level etc.
114
    3. Integration with GUI from the very beginning.
115
  I hope to develop the most friendly synthesizable processor for HW and SW developers
116
  and provide debugging tools of professional quality.
117
 
118
 
119
# Step I: Simple FPGA test.
120
 
121
You can use the pre-built FPGA image (for Xilinx ML605 or KC705 board) and any serial
122
console application (*putty*, *screen* or other).
123
 
124
1. Unpack and load file image *riscv_soc.bit* from */rocket_soc/bit_files/* into FPGA board.
125
2. Connect to serial port. I use standard console utility *screen* on Ubuntu.
126
 
127
        $ sudo apt-get install screen
128
        $ sudo screen /dev/ttyUSB0 115200
129
 
130
3. Use button "*Center*" to reset FPGA system and reprint initial messages:
131
 
132
```
133
    Boot . . .OK
134
    Zephyr version 1.5.0
135
    shell>
136
```
137
 
138
Our system is ready to use. Shell command **pnp** prints SOC HW information,
139
command **dhry** runs Dhrystone 2.1 benchmark.
140
To end the session, use Ctrl-A, Shift-K
141
 
142
![Zephyr demo](rocket_soc/docs/pics/zephyr_demo.gif)
143
 
144
Zephyr kernel v1.6 supports shell commands from different kernel modules, to switch
145
one module to another use command **set_module**:
146
 
147
```
148
    shell> set_module kernel
149
    shell> version
150
    shell> set_module soc
151
    shell> dhry
152
    shell> pnp
153
    ...
154
```
155
 
156
# Step II: Build and run Software models with GUI.
157
 
158
At this step we're going to build: functional models of CPU and peripheries,
159
precise SystemC model of 'River' CPU and RISC-V Debugger with GUI
160
(MS Visual Studio project for Windows is also available).
161
This step **doesn't require any Hardware** and the final result will look as on
162
the following animated picture:
163
 
164
![Debugger demo](rocket_soc/docs/pics/debugger_demo.gif)
165
 
166
There's dependency of two others open source projects:
167
 
168
* **[Qt-libraries](https://www.qt.io/download/)**
169
* **[SystemC library](http://accellera.org/downloads/standards/systemc)**
170
 
171
1. Download and install Qt-package (checked with version 5.7).
172
2. Specify environment variable QT_PATH:
173
 
174
        $ export QT_PATH=/home/install_dir/Qt5.7.0/5.7/gcc_64
175
 
176
3. If you would like to run SystemC models download the systemc archive.
177
4. Unpack and build sources:
178
 
179
        $ tar -xvzf systemc-2.3.1a.tar.gz
180
        $ cd systemc-2.3.1a
181
        $ mkdir tmp
182
        $ cd tmp
183
        $ ./../configure --prefix=/home/user/systemc-2.3.1a/build
184
        $ make
185
        $ make install
186
 
187
5. Specify environment variable SYSTEMC_PATH:
188
 
189
        $ export SYSTEMC_PATH=/home/user/systemc-2.3.1a/build")
190
 
191
   **Note: System Simulator supports blocking and non-blocking accesses to the simulated
192
   devices. You can request additional information of how to connect your
193
   SystemC device to this SoC.**
194
 
195
6. Build project:
196
 
197
        $ cd debugger/makefiles
198
        $ make
199
 
200
7. In a case of successful build start desired configuration:
201
 
202
        $ cd ../linuxbuild/bin
203
 
204
Start Configuration        | Description
205
---------------------------|-----------------
206
$ ./_run_functional_sim.sh | Functional RISC-V Full System Model
207
$ ./_run_systemc_sim.sh    | Use SystemC Precise Model of RIVER CPU
208
$ ./_run_fpga_gui.sh       | FPGA board. Default port 'COM3', TAP IP = 192.168.0.51
209
 
210
**Note:** Specify correct serial port in the file *debugger/targets/fpga_gui.json*
211
(COM3 -> ttyUSB0) if you run debugger on linux.
212
 
213
**Note:** Instruction of how to connect FPGA board via
214
Ethernet your can find [here](http://sergeykhbr.github.io/riscv_vhdl/eth_link.html).
215
Simulation and Hardware targets use identical EDCL over UDP interface so that
216
[Debugger](http://sergeykhbr.github.io/riscv_vhdl/sw_debugger_api_link.html) can work
217
with any target using the same set of commands.
218
 
219
**Debugger doesn't implement any specific interface for the simulation.
220
Debugger uses only architectural access via TAP (EDCL over UDP) for all targets.**
221
 
222
 
223
# Step III: Build FPGA image
224
 
225
Default VHDL configuration enables River CPU with full debug support.
226
 
227
![River top](rocket_soc/docs/pics/river_top.png)
228
 
229
You can enable usage of "Rocket-chip" CPU instead of "River" disabling the
230
configuration parameter in */rocket_soc/work/config_common.vhd*
231
CFG_COMMON_RIVER_CPU_ENABLE.
232
 
233
1. Open ML605 project file for Xilinx ISE14.7 *prj/ml605/riscv_soc.xise*
234
   or KC705 project file for Xilinx Vivado *prj/kc705/riscv_soc.xpr*.
235
2. Edit configuration constants in file **work/config_common.vhd** if needed.
236
   (Skip this step by default).
237
3. Use *rocket_soc/work/tb/riscv_soc_tb.vhd"* testbench file to verify
238
   full system including *CPU*, *UART*, *Timers*, *Ethernet*, *GPIO* etc.
239
4. Generate bit-file and load it into FPGA.
240
 
241
 
242
# Step IV: How to build 64-bits Zephyr v1.6.0 for RISC-V or other custom firmware
243
 
244
As an example we're going to build two programs:
245
 
246
* Zephyr OS kernel with ROM-image generation.
247
* 'Hello world' example. Then load it into the target using Debugger's command.
248
 
249
## 1. Setup GCC toolchain
250
 
251
  You can find step-by-step instruction of how to build your own
252
toolchain on [riscv.org](http://riscv.org/software-tools/). If you would like
253
to use pre-build GCC binary files and libraries you can download it here:
254
 
255
   [Ubuntu GNU GCC 6.1.0 toolchain RV64D (207MB)](http://www.gnss-sensor.com/index.php?LinkID=1018)
256
   [Ubuntu GNU GCC 6.1.0 toolchain RV64IMA (204MB)](http://www.gnss-sensor.com/index.php?LinkID=1017)
257
 
258
   [(obsolete) Ubuntu GNU GCC 5.1.0 toolchain RV64IMA (256MB)](http://www.gnss-sensor.com/index.php?LinkID=1013)
259
 
260
  GCC 5.1.0 is the legacy version for *riscv_vhdl* with tag **v3.1** or older.
261
**RV64IMA** build doesn't use hardware FPU (*--soft-float*). **RV64D** build
262
requires FPU co-processor (*--hard-float*).
263
 
264
  Just after you download the toolchain unpack it and set environment variable
265
as follows:
266
 
267
    $ tar -xzvf gnu-toolchain-rv64ima.tar.gz gnu-toolchain-rv64ima
268
    $ export PATH=/home/your_path/gnu-toolchain-rv64ima/bin:$PATH
269
 
270
If you would like to generate hex-file and use it for ROM initialization you can use
271
*'elf2hex'* and *'libfesvr.so'* library from the GNU toolchain but I suggest to use my version
272
of such tool *'elf2raw64'*. I've put this binary into pre-built GCC archive 'gnu_toolchain-rv64/bin'.
273
If *elf2raw64* conflicts with installed LIBC version re-build it from *fw/elf2raw64/makefiles*
274
directory.
275
 
276
## 2. Patch and build Zephyr OS v1.6.0 binary
277
 
278
    $ mkdir zephyr_160
279
    $ cd zephyr_160
280
    $ git clone https://gerrit.zephyrproject.org/r/zephyr
281
    $ cd zephyr
282
    $ git checkout tags/v1.6.0
283
    $ cp ../../riscv_vhdl/zephyr/v1.6.0-riscv64-base.diff .
284
    $ cp ../../riscv_vhdl/zephyr/v1.6.0-riscv64-exten.diff .
285
    $ git apply v1.6.0-riscv64-base.diff
286
    $ git apply v1.6.0-riscv64-exten.diff
287
 
288
The first patch adds base functionality for RISC-V 64-bits architecture.
289
The second one extends it by adding Dhrystone 2.1. benchmark and
290
MS Visual Studio target and maybe something else.
291
 
292
Build elf-file:
293
 
294
    $ export ZEPHYR_BASE=/home/zephyr_160/zephyr
295
    $ cd zephyr/samples/shell
296
    $ make ARCH=riscv64 CROSS_COMPILE=/home/your_path/gnu-toolchain-rv64ima/bin/riscv64-unknown-elf- BOARD=riscv_gnss 2>&1 | tee _err.log
297
 
298
Create HEX-image for ROM initialization. I use own analog of the *elf2raw*
299
utility named as *elf2raw64*. You can find it in GNU tools archive.
300
 
301
    $ elf2raw64 outdir/riscv_gnss/zephyr.elf -h -f 262144 -l 8 -o fwimage.hex
302
 
303
Flags:
304
 
305
    -h        -- specify HEX format of the output file.
306
    -f 262144 -- specify total ROM size in bytes.
307
    -l 8      -- specify number of bytes in one line (AXI databus width). Default is 16.
308
 
309
Copy *fwimage.hex* to rocket_soc subdirectory
310
 
311
    $ cp fwimage.hex ../../../rocket_soc/fw_images
312
 
313
## 3. Debug Zephyr kernel with debug symbols.
314
 
315
Our debugger allows to use debug information from the elf-file as on the
316
picture bellow:
317
 
318
![GUI debug](rocket_soc/docs/pics/dbg_gui_symb.png)
319
 
320
To achieve such results just use the console command *'loadelf'*:
321
 
322
    riscv# loadelf zephyr.elf
323
    riscv# loadelf zephyr.elf nocode
324
 
325
The second command loads debug information without target reprogramming.
326
 
327
## 4. Build and run custom FW like 'Hello World' example.
328
 
329
Build example:
330
 
331
    $ cd /your_git_path/rocket_soc/fw/helloworld/makefiles
332
    $ make
333
 
334
Run Risc-V Debugger application:
335
 
336
    $ ./your_git_path/debugger/linuxbuild/bin/_run_functional_sim.sh
337
 
338
Load elf-file using debugger's console:
339
 
340
    #riscv loadelf bin/helloworld
341
 
342
You should see something like:
343
 
344
```
345
    riscv# loadelf e:/helloworld
346
    [loader0]: Loading '.text' section
347
    [loader0]: Loading '.eh_frame' section
348
    [loader0]: Loading '.rodata.str1.8' section
349
    [loader0]: Loading '.rodata' section
350
    [loader0]: Loading '.data' section
351
    [loader0]: Loading '.sdata' section
352
    [loader0]: Loading '.sbss' section
353
    [loader0]: Loading '.bss' section
354
    [loader0]: Loaded: 42912 B
355
```
356
 
357
Just after image loading has been finished debugger clears reset CPU signal.
358
Start the simulation manually (F5) if the processor was in 'halt' state.
359
This example prints only once UART message *'Hello World - 1'*,
360
so if you'd like to repeat test reload image using **loadelf** command.
361
 
362
Now we can also generate HEX-file for ROM initialization to do that
363
see other example with **bootrom** implementation
364
 
365
    $ cd rocket_soc/fw/boot/makefiles
366
    $ make
367
    $ cd ../linuxbuild/bin
368
 
369
Opened directory contains the following files:
370
- _bootimage_       - elf-file (not used by SOC).
371
- _bootimage.dump_  - disassembled file for the verification.
372
- *_bootimage.hex_* - HEX-file for the Boot ROM intialization.
373
 
374
You can also check *bootimage.hex* and memory dump for consistence:
375
 
376
    #riscv dump 0 8192 dump.hex hex
377
 
378
I hope your also have run firmware on RISC-V system successfully.
379
 
380
My usual FPGA setup is ML605 board and debugger that is running on Windows 7
381
from Visual Studio project, so other target configurations (linux + KC705)
382
could contain errors that are fixing with a small delay. Let me know if see one.
383
 
384
 
385
## Versions History
386
 
387
### Implemented functionality (v5.1)
388
 
389
- "RIVER" critical bugs fixed:Not decoded  SRAI instrucion, missed exception generation.
390
- Zephyr v1.6.0 ported with *unikernel* instead of the obsolete *nanokernel*.
391
 
392
### Implemented functionality (v5.0)
393
 
394
- New CPU implemented ("RIVER").
395
- "Rocket-chip" CPU updated to date 18 Jan 2017. TileLink interface was totally redesigned.
396
- SystemC support was added with the precise CPU model and VCD-stimulus generator.
397
- Debugger functionality is now oriented only on RIVER implementation
398
  and includes a lot of new features: breakpoints, disassembler,
399
  CPI meter and others.
400
- AXI bus controller significantly improved
401
 
402
### Implemented functionality (v4.0)
403
 
404
- Support new revision of User-Level ISA Spec. 2.1 and Privileged spec. 1.9.
405
- FW will be binary incompatible with the previous Rocket-chip CPU (changed CSR's
406
indexes, instruction ERET removed, new set of instructions xRET was added etc).
407
- GCC versions (5.x) becomes obsolete.
408
- FPU enabled by default and pre-built GCC 6.x with --hard-float provided.
409
- HostIO bus removed.
410
- HW Debug capability significantly affetcted by new DebugUnit, but Simulation
411
significantly improved.
412
- Updated bootloader and FW will become available soon.
413
 
414
### Implemented functionality (v3.1)
415
 
416
To get branch *v3.1* use the following git command:
417
 
418
    $ git clone -b v3.1 https://github.com/sergeykhbr/riscv_vhdl.git
419
 
420
This is the last revision of the RISC-V SOC based on ISA version 1.9.
421
All afterwards updates will be **binary incompatible** with this tag.
422
Tag v3.1 adds:
423
 
424
- New Zephyr Kernel with the shell autocompletion.
425
- Significantly updated GUI of the debugger.
426
 
427
**Use tag v3.1 and GCC 5.1.0 instead of latest revision while release v4.0
428
won't ready. GCC 6.1.0 and 5.1.0 are binary incompatible either as SoC itself!**
429
 
430
 
431
### Implemented functionality (v3.0)
432
 
433
To get branch *v3.0* use the following git command:
434
 
435
    $ git clone -b v3.0 https://github.com/sergeykhbr/riscv_vhdl.git
436
 
437
- Ported open source Real-Time Operation System for Internet of Things
438
  Devices provided by [Zephyr Project](https://www.zephyrproject.org/).
439
- Benchmark *Dhrystone v2.1* run on FPGA and Simulator with published results.
440
- Testmode removed. *'gnsslib'* fully disabled.
441
- Graphical User Interface (GUI) for the debugger based on QT-libraries
442
  with significantly increasing of the debugger functionality.
443
 
444
### Implemented functionality (v2.0)
445
 
446
To get branch *v2.0* use the following git command:
447
 
448
    $ git clone -b v2.0 https://github.com/sergeykhbr/riscv_vhdl.git
449
 
450
This release add to following features to *v1.0*:
451
 
452
- *Debug Support Unit* (DSU) for the access to all CPU registers (CSRs).
453
- *10/100 Ethernet MAC with EDCL* that allows to debug processor from the
454
  reset vector redirecting UDP requests directly on system bus.
455
- GNSS engine and RF-mezzanine card support.
456
- **Test Mode** (DIP[0]=1) that allows to use SOC with or without
457
  *RF-mezzanine card*.
458
- Master/Slave AMBA AXI4 interface refactoring.
459
- *Debugger Software (C++)* for Windows and Linux with built-in simulator
460
  and plugins support.
461
- Portable asynchronous FIFO implementation allowing to connect modules to the
462
  System BUS from a separate clock domains (ADC clock domain):
463
- A lot of system optimizations.
464
 
465
 
466
### Implemented functionality (v1.0)
467
 
468
The initial *v1.0* release provides base SOC functionality with minimal
469
set of peripheries. To get this version use:
470
 
471
    $ git clone -b v1.0 https://github.com/sergeykhbr/riscv_vhdl.git
472
 
473
- Proof-of-concept VHDL SOC based on Verilog generated core *"Rocket-chip"*.
474
- Peripheries with AMBA AXI4 interfaces: GPIO, LEDs, UART, IRQ controller etc.
475
- Plug'n-Play support.
476
- Configuration and constraint files for ML605 (Virtex6) and KC705 (Kintex7)
477
  FPGA boards.
478
- Bit-files for ML605 and KC705 boards.
479
- Pre-built ROM images with the BootLoader and FW-image. FW-image is copied
480
  into internal SRAM during boot-stage.
481
- *"Hello World"* example.
482
 
483
 
484
## Doxygen project documentation
485
 
486
[http://sergeykhbr.github.io/riscv_vhdl/](http://sergeykhbr.github.io/riscv_vhdl/)

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.