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

Subversion Repositories riscv_vhdl

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

Details | Compare with Previous | View Log

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