You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

201 lines
8.6 KiB

  1. # About the source of this VexRiscv-Simulation
  2. This is a stipped down version of the pqriscv resporitory:
  3. https://github.com/mupq/pqriscv
  4. The original README of this repository starts below and might not fit for all functionality anymore.
  5. You might want to read the README in the root folder of this repo instead.
  6. Modifications: Thorsten Knoll, Oct 2020
  7. # PQVexRiscV
  8. [VexRiscv](https://github.com/SpinalHDL/VexRiscv) based Target platforms
  9. for the [pqriscv](https://github.com/mupq/pqriscv) project
  10. ## Introduction
  11. The goal of this project is to implement a simple test-platform for the
  12. VexRiscv CPU, to be used as a reference platform for benchmarking and
  13. experimenting with PQC scheme implementations.
  14. ## Setup
  15. You'll need the following
  16. * Java JDK **==** 1.8
  17. * [SBT](https://www.scala-sbt.org) >= 1.2.8, the Scala Build Tool
  18. * (For iCE40 based FPGAs) [Icestorm FPGA Toolchain](http://www.clifford.at/icestorm/), including [NextPNR](https://github.com/YosysHQ/nextpnr)
  19. * (For Xilinx based FPGAs) Vivado ~= 2018.3 (probably also works with older and newer versions)
  20. * (For the Simulator) [Verilator](https://www.veripool.org/wiki/verilator)
  21. * (Optionally for Debugging) [OpenOCD for VexRiscv](https://github.com/SpinalHDL/openocd_riscv)
  22. ## Synthesis
  23. This project (and VexRiscv) uses the SpinalHDL language, which is
  24. essentially a DSL for hardware design on top of the Scala language.
  25. The Scala sources will then generate equivalent Verilog (or VHDL) of
  26. circuits described in SpinalHDL.
  27. So to create a bitstream for a FPGA, you'll have to generate the verilog
  28. file first and then run synthesis.
  29. Just run `sbt` in the project root and run any of the main classes to
  30. generate the verilog source for one of the targets.
  31. The `rtl` folder contains a Makefile to generate the bitstream for the
  32. FPGAs (the Makefile will also run `sbt` to generate the Verilog).
  33. For example:
  34. ```sh
  35. make -C rtl TARGETS=PQVexRiscvUP5K
  36. ```
  37. ## Simulation
  38. Simulating a VexRiscv core is also possible.
  39. ```sh
  40. sbt "runMain mupq.PQVexRiscvSim --init initfile.bin --ram 256,128 --uart uartoutput.txt"
  41. ```
  42. Adapt the options to your liking. The `--init` option points to a binary
  43. file which is loaded into the simulated RAM as initialization. Remove
  44. the option to leave the RAM blank, you can also load your binary via
  45. OpenOCD+GDB.
  46. The `--ram` option determines the memory architecture. The
  47. simulator will add a X KiB sized block of RAM to the memory architecture
  48. for each integer. Default is two blocks of ram, one for meant for code,
  49. one for data. The RAM blocks start at address `0x80000000` of the
  50. VexRiscv core and are placed back-to-back.
  51. The `--uart` block may point to a file to which the simulated UART
  52. output of the core is appended. When this option is skipped, UART is
  53. redirected to stdout.
  54. ## OpenOCD for VexRiscv
  55. All boards (including the simulator) support debugging via a JTAG port.
  56. For that you'll need a suitable debugging adapter (anything FT2232
  57. should do) and [OpenOCD port for VexRiscv](https://github.com/SpinalHDL/openocd_riscv).
  58. You can use the following to compile a stripped down version of the
  59. tool, which also adds the suffix `-vexriscv` to the program name, as
  60. well as placing all the data into a different dir, so the installation
  61. won't clash with any other OpenOCD version on your system. Adapt the
  62. prefix/datarootdir to your taste.
  63. ```sh
  64. ./bootstrap
  65. ./configure --prefix=/usr/local --program-suffix=-vexriscv \
  66. --datarootdir=/usr/local/share/vexriscv --enable-maintainer-mode \
  67. --disable-werror --enable-ft232r --enable-ftdi --enable-jtag_vpi \
  68. --disable-aice --disable-amtjtagaccel --disable-armjtagew \
  69. --disable-assert --disable-at91rm9200 --disable-bcm2835gpio \
  70. --disable-buspira --disable-cmsis-dap --disable-doxygen-html \
  71. --disable-doxygen-pdf --disable-dummy --disable-ep93xx \
  72. --disable-gw16012 --disable-imx_gpio --disable-jlink \
  73. --disable-kitprog --disable-minidriver-dummy --disable-oocd_trace \
  74. --disable-opendous --disable-openjtag --disable-osbdm \
  75. --disable-parport --disable-parport-giveio --disable-parport-ppdev \
  76. --disable-presto --disable-remote-bitbang --disable-rlink \
  77. --disable-stlink --disable-sysfsgpio --disable-ti-icdi \
  78. --disable-ulink --disable-usb-blaster --disable-usb-blaster-2 \
  79. --disable-usbprog --disable-verbose-jtag-io \
  80. --disable-verbose-usb-comms --disable-verbose-usb-io \
  81. --disable-vsllink --disable-xds110 --disable-zy1000 \
  82. --disable-zy1000-master
  83. make
  84. # sudo make install
  85. ```
  86. Some templates for connecting OpenOCD and a Debug adapter to the boards
  87. are at the ready in the project root. For example:
  88. ```sh
  89. openocd-vexriscv -f pqvexriscvsim.cfg
  90. ```
  91. Since OpenOCD opens up a gdbserver, you can debug on your target with
  92. GDB. For example:
  93. ```sh
  94. riscv64-unknown-elf-gdb -ex 'set remotetimeout 10' -ex 'target remote :3333' -ex load -ex 'break main' my_awesome_program.elf
  95. ```
  96. ## FPGA Platforms
  97. This project will support multiple FPGA targets in future:
  98. * [iCE40 UltraPlus 5K](https://www.latticesemi.com/en/Products/FPGAandCPLD/iCE40UltraPlus) as, for example, present in the [iCE40 UltraPlus Breakout Board](https://www.latticesemi.com/en/Products/DevelopmentBoardsAndKits/iCE40UltraPlusBreakoutBoard)
  99. * WIP: [Icoboard](http://icoboard.org/), which in turn uses the [iCE40 HX 8K](https://www.latticesemi.com/Products/FPGAandCPLD/iCE40)
  100. * WIP: [Xilinx 7 Series](https://www.xilinx.com/products/silicon-devices/fpga.html), with an example file for the [Digilent Arty A7 board](https://store.digilentinc.com/arty-a7-artix-7-fpga-development-board-for-makers-and-hobbyists/)
  101. ### iCE40 UltraPlus 5k
  102. A basic design with the default VexRiscv plugins should fit on the iCE40
  103. UP5K.
  104. As the UP5K features 8 DSP blocks, a non-blocking multiplier will fit
  105. comfortably.
  106. Furthermore, four 32kb sized SRAM blocks are present on the FPGA, which
  107. are used to implement two separate 64kb large blocks on the memory bus.
  108. You should link your code to the lower half (starting `0x80000000`), and
  109. stack / data to the upper half (starting `0x80010000`).
  110. The `rtl` folder contains a constraint file to place the design on the
  111. UltraPlus Breakout Board (though other boards should work fine, as long
  112. as the use the UP5K, just adapt the PCF as necessary).
  113. It exposes the JTAG and UART pins to IO ports located on header B as
  114. follows:
  115. | Function | Pin |
  116. |------------|---------|
  117. | JTAG `TDO` | iob_23b |
  118. | JTAG `TCK` | iob_25b |
  119. | JTAG `TDI` | iob_24a |
  120. | JTAG `TMS` | iob_29b |
  121. | UART `TXD` | iob_8a |
  122. | UART `RXD` | iob_9b |
  123. You can use any FTDI FT2232H or FT232H based debugger probe together
  124. with `openocd-vexriscv`, just adapt the connection script
  125. `PQVexRiscvUP5K.cfg` accordingly.
  126. Tip: You could use the
  127. [FT_PROG](https://www.ftdichip.com/Support/Utilities.htm#FT_PROG) to
  128. change the serial number of a generic FT232H breakout board [(e,g, the
  129. Adafruit FT232H Breakout board)](https://www.adafruit.com/product/2264).
  130. Add a line `ftdi_serial "XXX"` to the connection script, and `openocd`
  131. will automatically pick the right FTDI.
  132. Another well known FTDI based probe is the [Olimex
  133. ARM-USB-TINY-H](https://www.olimex.com/Products/ARM/JTAG/ARM-USB-TINY-H/)
  134. (see the example `openocd-vexriscv` connection script for the Icoboard
  135. `pqvexriscvicoboard.cfg`).
  136. ### Icoboarda (WIP)
  137. This FPGA target is still a heavy work in progress.
  138. The FPGA itself has more LUTs than the UP5K, however, doesn't feature
  139. any DSPs.
  140. Thus, the design will likely use a smaller multi-cycle multiplier to
  141. implement the multiplication instruction.
  142. The large SRAM blocks of the UP5K are also missing, however, the
  143. Icoboard offers a 8MBit large SRAM chip, which will be used for
  144. code **and** data.
  145. ### Xilinx 7 Series
  146. The Digilent Arty A7 board uses the Xilinx Artix-7 XC7A35T (or XC7A100T
  147. depending on the model), which will comfortably fit even larger variants
  148. of the VexRiscv core).
  149. The Arty board also exists in other variants using the Spartan-7 series
  150. chip, which should also be large enough for the VexRiscv.
  151. Similarly to the UP5K, the default design will use two separate 64kb
  152. blocks for code and data each.
  153. On the Arty Boards, the UART is exposed on the shared FPGA configuration
  154. and UART USB port of the board.
  155. The JTAG (for the VexRiscv core, **not** the JTAG for the FPGA chip) is
  156. exposed on the PMOD JD connector.
  157. | Function | Pin (PMOD JD) |
  158. |----------|---------------|
  159. | `TDO` | 1 |
  160. | `TCK` | 3 |
  161. | `TDI` | 7 |
  162. | `TMS` | 8 |
  163. If you use the Olimex ARM-USB-TINY-H, you'll also need to connect the
  164. VREF.
  165. Note, that the pinout is exactly the same as the [SiFive Freedom E310
  166. Arty FPGA Dev Kit](https://github.com/sifive/freedom), except that
  167. the `nRST`, `nTRST` remain unused.
  168. ## Internals
  169. *TODO*: Write up some infos on the platforms, what features of VexRiscv
  170. are enabled, how the memory architecture works, ...