Add batch 2 (lnis-uofu_OpenFPGA, splinedrive_kianRiscV, Wren6991_Hazard3, odriverobotics_ODriveHardware, mntmn_amiga2000-gfxcard)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +41 -0
- Wren6991_Hazard3/.gitignore +2 -0
- Wren6991_Hazard3/.gitmodules +18 -0
- Wren6991_Hazard3/.vscode/settings.json +24 -0
- Wren6991_Hazard3/Contributing.md +103 -0
- Wren6991_Hazard3/LICENSE +201 -0
- Wren6991_Hazard3/Readme.md +475 -0
- Wren6991_Hazard3/doc/.gitignore +3 -0
- Wren6991_Hazard3/doc/Makefile +36 -0
- Wren6991_Hazard3/doc/Readme.md +19 -0
- Wren6991_Hazard3/doc/diagrams/debug_topology.drawio +1 -0
- Wren6991_Hazard3/doc/diagrams/hazard3_backend.drawio +1 -0
- Wren6991_Hazard3/doc/diagrams/hazard3_logo_riscv_colors.svg +43 -0
- Wren6991_Hazard3/doc/hazard3-theme.yml +11 -0
- Wren6991_Hazard3/doc/hazard3.adoc +40 -0
- Wren6991_Hazard3/doc/sections/bus_behaviour.adoc +77 -0
- Wren6991_Hazard3/doc/sections/configuration_and_integration.adoc +805 -0
- Wren6991_Hazard3/doc/sections/csr.adoc +1009 -0
- Wren6991_Hazard3/doc/sections/custom_extensions.adoc +228 -0
- Wren6991_Hazard3/doc/sections/debug.adoc +179 -0
- Wren6991_Hazard3/doc/sections/instruction_pseudocode.adoc +1219 -0
- Wren6991_Hazard3/doc/sections/instruction_timings.adoc +220 -0
- Wren6991_Hazard3/doc/sections/introduction.adoc +139 -0
- Wren6991_Hazard3/doc/sections/release_notes.adoc +106 -0
- Wren6991_Hazard3/example_soc/arty7-openocd.cfg +34 -0
- Wren6991_Hazard3/example_soc/fpga/fpga_arty_a7.f +9 -0
- Wren6991_Hazard3/example_soc/fpga/fpga_arty_a7.v +158 -0
- Wren6991_Hazard3/example_soc/fpga/fpga_icebreaker.f +6 -0
- Wren6991_Hazard3/example_soc/fpga/fpga_icebreaker.v +104 -0
- Wren6991_Hazard3/example_soc/fpga/fpga_orangecrab_25f.f +10 -0
- Wren6991_Hazard3/example_soc/fpga/fpga_orangecrab_25f.v +98 -0
- Wren6991_Hazard3/example_soc/fpga/fpga_ulx3s.f +12 -0
- Wren6991_Hazard3/example_soc/fpga/fpga_ulx3s.v +75 -0
- Wren6991_Hazard3/example_soc/fpga/pll_25_40.v +46 -0
- Wren6991_Hazard3/example_soc/fpga/pll_25_50.v +46 -0
- Wren6991_Hazard3/example_soc/icebreaker-openocd.cfg +30 -0
- Wren6991_Hazard3/example_soc/project_paths.mk +2 -0
- Wren6991_Hazard3/example_soc/soc/example_soc.v +613 -0
- Wren6991_Hazard3/example_soc/soc/peri/hazard3_riscv_timer.f +2 -0
- Wren6991_Hazard3/example_soc/soc/peri/hazard3_riscv_timer.v +142 -0
- Wren6991_Hazard3/example_soc/soc/soc.f +27 -0
- Wren6991_Hazard3/example_soc/synth/.gitignore +10 -0
- Wren6991_Hazard3/example_soc/synth/Icebreaker.mk +14 -0
- Wren6991_Hazard3/example_soc/synth/Makefile +1 -0
- Wren6991_Hazard3/example_soc/synth/ULX3S.mk +20 -0
- Wren6991_Hazard3/example_soc/synth/fpga_icebreaker.pcf +43 -0
- Wren6991_Hazard3/example_soc/synth/fpga_orangecrab_25f.lpf +44 -0
- Wren6991_Hazard3/example_soc/synth/fpga_ulx3s.lpf +32 -0
- Wren6991_Hazard3/example_soc/synth/orangecrab-25f.mk +23 -0
- Wren6991_Hazard3/example_soc/synth_vivado/.gitignore +8 -0
.gitattributes
CHANGED
|
@@ -389,3 +389,44 @@ tiny-tpu-v2_tiny-tpu/mnist_demo/artifacts/sim/modelsim_mnist_serial_classifier_f
|
|
| 389 |
tiny-tpu-v2_tiny-tpu/mnist_demo/artifacts/sim/modelsim_mnist_serial_classifier_full/work/_lib1_0.qtl filter=lfs diff=lfs merge=lfs -text
|
| 390 |
tiny-tpu-v2_tiny-tpu/mnist_demo/artifacts/sim/modelsim_mnist_tpu_tiled_classifier/work/_lib1_0.qpg filter=lfs diff=lfs merge=lfs -text
|
| 391 |
tiny-tpu-v2_tiny-tpu/mnist_demo/artifacts/sim/modelsim_mnist_tpu_tiled_classifier/work/_lib1_0.qtl filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 389 |
tiny-tpu-v2_tiny-tpu/mnist_demo/artifacts/sim/modelsim_mnist_serial_classifier_full/work/_lib1_0.qtl filter=lfs diff=lfs merge=lfs -text
|
| 390 |
tiny-tpu-v2_tiny-tpu/mnist_demo/artifacts/sim/modelsim_mnist_tpu_tiled_classifier/work/_lib1_0.qpg filter=lfs diff=lfs merge=lfs -text
|
| 391 |
tiny-tpu-v2_tiny-tpu/mnist_demo/artifacts/sim/modelsim_mnist_tpu_tiled_classifier/work/_lib1_0.qtl filter=lfs diff=lfs merge=lfs -text
|
| 392 |
+
lnis-uofu_OpenFPGA/openfpga_flow/tasks/basic_tests/custom_rrgraph/custom_rrgraph_group_routing/SRC/and2_autocheck_top_tb.v filter=lfs diff=lfs merge=lfs -text
|
| 393 |
+
mntmn_amiga2000-gfxcard/va2000-spartan6/simulation/sram.test filter=lfs diff=lfs merge=lfs -text
|
| 394 |
+
odriverobotics_ODriveHardware/Altium_libs/CustomComponents.SchLib filter=lfs diff=lfs merge=lfs -text
|
| 395 |
+
odriverobotics_ODriveHardware/Altium_libs/CustomFootprints.PcbLib filter=lfs diff=lfs merge=lfs -text
|
| 396 |
+
odriverobotics_ODriveHardware/v2/Analouge.SchDoc filter=lfs diff=lfs merge=lfs -text
|
| 397 |
+
odriverobotics_ODriveHardware/v2/CapsDisambiguationTop.PNG filter=lfs diff=lfs merge=lfs -text
|
| 398 |
+
odriverobotics_ODriveHardware/v2/Config.SchDoc filter=lfs diff=lfs merge=lfs -text
|
| 399 |
+
odriverobotics_ODriveHardware/v2/FPGA.SchDoc filter=lfs diff=lfs merge=lfs -text
|
| 400 |
+
odriverobotics_ODriveHardware/v2/HalfHRoutingTopology.PNG filter=lfs diff=lfs merge=lfs -text
|
| 401 |
+
odriverobotics_ODriveHardware/v2/Inverter.PDF filter=lfs diff=lfs merge=lfs -text
|
| 402 |
+
odriverobotics_ODriveHardware/v2/Inverter.PcbDoc filter=lfs diff=lfs merge=lfs -text
|
| 403 |
+
odriverobotics_ODriveHardware/v2/Inverter45attempt.PcbDoc filter=lfs diff=lfs merge=lfs -text
|
| 404 |
+
odriverobotics_ODriveHardware/v2/InverterLayoutBot.PNG filter=lfs diff=lfs merge=lfs -text
|
| 405 |
+
odriverobotics_ODriveHardware/v2/InverterLayoutTop.PNG filter=lfs diff=lfs merge=lfs -text
|
| 406 |
+
odriverobotics_ODriveHardware/v2/M0.SchDoc filter=lfs diff=lfs merge=lfs -text
|
| 407 |
+
odriverobotics_ODriveHardware/v2/Power.SchDoc filter=lfs diff=lfs merge=lfs -text
|
| 408 |
+
odriverobotics_ODriveHardware/v3/AuxHalfH.SchDoc filter=lfs diff=lfs merge=lfs -text
|
| 409 |
+
odriverobotics_ODriveHardware/v3/MotorCell.SchDoc filter=lfs diff=lfs merge=lfs -text
|
| 410 |
+
odriverobotics_ODriveHardware/v3/MotorCell_noPow.SchDoc filter=lfs diff=lfs merge=lfs -text
|
| 411 |
+
odriverobotics_ODriveHardware/v3/PCB.PcbDoc filter=lfs diff=lfs merge=lfs -text
|
| 412 |
+
odriverobotics_ODriveHardware/v3/STMicroelectronics[[:space:]]STM32[[:space:]]F4/STMicroelectronics[[:space:]]STM32[[:space:]]F4.PcbLib filter=lfs diff=lfs merge=lfs -text
|
| 413 |
+
odriverobotics_ODriveHardware/v3/STMicroelectronics[[:space:]]STM32[[:space:]]F4/STMicroelectronics[[:space:]]STM32[[:space:]]F4.SchLib filter=lfs diff=lfs merge=lfs -text
|
| 414 |
+
odriverobotics_ODriveHardware/v3/STMicroelectronics[[:space:]]STM32[[:space:]]F4.IntLib filter=lfs diff=lfs merge=lfs -text
|
| 415 |
+
odriverobotics_ODriveHardware/v3/Top.SchDoc filter=lfs diff=lfs merge=lfs -text
|
| 416 |
+
odriverobotics_ODriveHardware/v3/layoutexample.PNG filter=lfs diff=lfs merge=lfs -text
|
| 417 |
+
odriverobotics_ODriveHardware/v3/v3.2docs/v3.2_bottom.PNG filter=lfs diff=lfs merge=lfs -text
|
| 418 |
+
odriverobotics_ODriveHardware/v3/v3.2docs/v3.2_top.PNG filter=lfs diff=lfs merge=lfs -text
|
| 419 |
+
odriverobotics_ODriveHardware/v3/v3.3docs/mech_dimensions.PNG filter=lfs diff=lfs merge=lfs -text
|
| 420 |
+
odriverobotics_ODriveHardware/v3/v3.3docs/v3.3_bottom.PNG filter=lfs diff=lfs merge=lfs -text
|
| 421 |
+
odriverobotics_ODriveHardware/v3/v3.3docs/v3.3_top.PNG filter=lfs diff=lfs merge=lfs -text
|
| 422 |
+
odriverobotics_ODriveHardware/v3/v3.4docs/mech_dimensions.PNG filter=lfs diff=lfs merge=lfs -text
|
| 423 |
+
odriverobotics_ODriveHardware/v3/v3.4docs/v3.4_bottom.PNG filter=lfs diff=lfs merge=lfs -text
|
| 424 |
+
odriverobotics_ODriveHardware/v3/v3.4docs/v3.4_top.PNG filter=lfs diff=lfs merge=lfs -text
|
| 425 |
+
odriverobotics_ODriveHardware/v3/v3.5docs/mech_dimensions.PNG filter=lfs diff=lfs merge=lfs -text
|
| 426 |
+
odriverobotics_ODriveHardware/v3/v3.5docs/v3.5_bottom.PNG filter=lfs diff=lfs merge=lfs -text
|
| 427 |
+
odriverobotics_ODriveHardware/v3/v3.5docs/v3.5_top.PNG filter=lfs diff=lfs merge=lfs -text
|
| 428 |
+
splinedrive_kianRiscV/linux_socs/kianv_harris_mcycle_edition/demo/kernel filter=lfs diff=lfs merge=lfs -text
|
| 429 |
+
splinedrive_kianRiscV/linux_socs/kianv_mc_rv32ima_sv32/os/linux/buildroot-kianv-soc/bldroot/rootfs-overlay/root/TinyPrograms/metaballs filter=lfs diff=lfs merge=lfs -text
|
| 430 |
+
splinedrive_kianRiscV/linux_socs/kianv_mc_rv32ima_sv32/os/linux/buildroot-kianv-soc/bldroot/rootfs-overlay/root/TinyPrograms/race filter=lfs diff=lfs merge=lfs -text
|
| 431 |
+
splinedrive_kianRiscV/linux_socs/kianv_mc_rv32ima_sv32/os/linux/buildroot-kianv-soc/bldroot/rootfs-overlay/root/TinyPrograms/render filter=lfs diff=lfs merge=lfs -text
|
| 432 |
+
splinedrive_kianRiscV/linux_socs/kianv_mc_rv32ima_sv32/os/linux/buildroot-kianv-soc/bldroot/rootfs-overlay/root/TinyPrograms/tinyraytracer filter=lfs diff=lfs merge=lfs -text
|
Wren6991_Hazard3/.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.DS_Store
|
| 2 |
+
*.todo
|
Wren6991_Hazard3/.gitmodules
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[submodule "test/sim/riscv-compliance/riscv-arch-test"]
|
| 2 |
+
path = test/sim/riscv-compliance/riscv-arch-test
|
| 3 |
+
url = https://github.com/wren6991/riscv-arch-test.git
|
| 4 |
+
[submodule "scripts"]
|
| 5 |
+
path = scripts
|
| 6 |
+
url = https://github.com/Wren6991/fpgascripts
|
| 7 |
+
[submodule "test/formal/riscv-formal"]
|
| 8 |
+
path = test/formal/riscv-formal/riscv-formal
|
| 9 |
+
url = https://github.com/Wren6991/riscv-formal.git
|
| 10 |
+
[submodule "example_soc/libfpga"]
|
| 11 |
+
path = example_soc/libfpga
|
| 12 |
+
url = https://github.com/Wren6991/libfpga.git
|
| 13 |
+
[submodule "test/sim/riscv-tests/riscv-tests"]
|
| 14 |
+
path = test/sim/riscv-tests/riscv-tests
|
| 15 |
+
url = https://github.com/Wren6991/riscv-tests.git
|
| 16 |
+
[submodule "test/sim/embench/embench-iot"]
|
| 17 |
+
path = test/sim/embench/embench-iot
|
| 18 |
+
url = https://github.com/Wren6991/embench-iot.git
|
Wren6991_Hazard3/.vscode/settings.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"rtlDebugger.command": [
|
| 3 |
+
"${workspaceFolder}/test/sim/tb_cxxrtl/tb",
|
| 4 |
+
"--bin",
|
| 5 |
+
"${workspaceFolder}/test/sim/hellow/tmp/hellow.bin",
|
| 6 |
+
"--debug"
|
| 7 |
+
],
|
| 8 |
+
"rtlDebugger.variableOptions": {
|
| 9 |
+
"cpu i_haddr": {
|
| 10 |
+
"radix": 16
|
| 11 |
+
}
|
| 12 |
+
},
|
| 13 |
+
"rtlDebugger.watchList": [
|
| 14 |
+
{
|
| 15 |
+
"id": "cpu clk"
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
"id": "cpu i_haddr"
|
| 19 |
+
},
|
| 20 |
+
{
|
| 21 |
+
"id": "d_haddr"
|
| 22 |
+
}
|
| 23 |
+
]
|
| 24 |
+
}
|
Wren6991_Hazard3/Contributing.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Contributing
|
| 2 |
+
|
| 3 |
+
There are two main ways you can contribute to Hazard3: _pull requests_ and _issues_.
|
| 4 |
+
|
| 5 |
+
## Pull Requests
|
| 6 |
+
|
| 7 |
+
I am grateful for any of the following pull requests:
|
| 8 |
+
|
| 9 |
+
* New documentation, or fixes for existing documentation
|
| 10 |
+
* New tests, or syncing new versions of upstream tests
|
| 11 |
+
* For upstream tests with downstream patches, please first raise a PR on the submodule for those upstream tests (just merging down is fine)
|
| 12 |
+
* Improvements and expansion to the example SoC
|
| 13 |
+
* Bug fixes for the example SoC
|
| 14 |
+
* Porting the example SoC to new FPGA platforms
|
| 15 |
+
* Preferably ones supported by Yosys + nextpnr, with an inexpensive commercially-available development board that I can order for testing
|
| 16 |
+
* Improvements to automation and scripting
|
| 17 |
+
* Improvements to RTL in project dependencies like `example_soc/libfpga/`
|
| 18 |
+
* General project maintenance (such as fixing accidental use of SSH URLs for submodules)
|
| 19 |
+
|
| 20 |
+
Please do not raise pull requests for the following:
|
| 21 |
+
|
| 22 |
+
* Changes to RTL sources in the top-level `hdl/` directory
|
| 23 |
+
* Cosmetic changes (except for comment-only changes)
|
| 24 |
+
|
| 25 |
+
Raise pull requests against the [develop](https://github.com/Wren6991/Hazard3/tree/develop) branch. Do not raise pull requests directly against [stable](https://github.com/Wren6991/Hazard3/tree/stable).
|
| 26 |
+
|
| 27 |
+
### Changes to Core RTL
|
| 28 |
+
|
| 29 |
+
I do not merge pull requests which modify hardware sources in the `hdl/` directory. I close these pull requests without reading the patch.
|
| 30 |
+
|
| 31 |
+
The contents of the `hdl/` directory have a single author. I will not expose people taping out Hazard3 to the possibility of your employer chasing you for your contribution by harassing them legally. A contribution agreement does not solve this, because you may sign it without the legal capability to do so, and **what is taped out cannot be taped back in.**
|
| 32 |
+
|
| 33 |
+
If you are reading this as a software engineer, please understand that the ASIC industry is more hostile to open-source projects than the software industry is, and I am trying my hardest to build a core that other people can safely use.
|
| 34 |
+
|
| 35 |
+
(I am not trying to be obstructive; if a community fork of Hazard3 gets traction I am happy to contribute and help out with issues and questions. However, the core RTL in this repository will remain single-author.)
|
| 36 |
+
|
| 37 |
+
Do not raise issues with suggested code changes to core RTL. This is the same thing as a pull request, and I will close the issue without reading the patch. Please clearly identify the issue and I will fix it.
|
| 38 |
+
|
| 39 |
+
## Issues
|
| 40 |
+
|
| 41 |
+
There are three main categories of issues which are helpful to the project: _bug reports_, _feature requests_ and _questions_.
|
| 42 |
+
|
| 43 |
+
### Bug Reports
|
| 44 |
+
|
| 45 |
+
If you find a bug in the Hazard3 repository, please report it. This includes:
|
| 46 |
+
|
| 47 |
+
1. A functional bug in Hazard3 such as mis-execution, or ISA non-compliance
|
| 48 |
+
2. A compatibility issue with your tools
|
| 49 |
+
* Please do not raise cosmetic lint issues: the intersection of clean Verilog across all lint tools is the empty set. Hazard3 is lint-clean with Verilator lint.
|
| 50 |
+
* A lint issue relating to simulation/synthesis mismatch is important though, and falls under point **1** above.
|
| 51 |
+
3. An incorrect or incomplete statement in documentation
|
| 52 |
+
4. A test which fails when it should pass, or vice versa
|
| 53 |
+
|
| 54 |
+
#### Reproducibility
|
| 55 |
+
|
| 56 |
+
Before I fix a bug I must reproduce it on my own machine. I cannot fix issues on faith as this is unlikely to result in a reliable or complete fix. Please include the following in a bug report to ensure I can reproduce the issue:
|
| 57 |
+
|
| 58 |
+
* A description of expected behaviour
|
| 59 |
+
* A description of actual, observed behaviour (which differs from expected)
|
| 60 |
+
* A description of the platform where you observed the issue
|
| 61 |
+
* Preferred platforms are the CXXRTL simulator, and the iCEBreaker and ULX3S FPGA SoCs
|
| 62 |
+
* You can attach a patch for a preferred platform if it is necessary to reproduce the issue
|
| 63 |
+
* All files necessary to reproduce the issue
|
| 64 |
+
* For software the minimum is an ELF and disassembly file for your binary
|
| 65 |
+
* Do not strip symbols from ELF files
|
| 66 |
+
* Please attach source code if possible (but the ELF is more important as I may not be able to reproduce your build exactly)
|
| 67 |
+
* A sequence of bash commands which can be invoked on the above files to reproduce the faulty behaviour
|
| 68 |
+
|
| 69 |
+
I develop Hazard3 on the latest Ubuntu LTS release (currently 24.04) and testing your reproduction on this platform is much appreciated.
|
| 70 |
+
|
| 71 |
+
### Feature Requests
|
| 72 |
+
|
| 73 |
+
I am happy to field feature requests. Please be aware the answer may be "no" for any of the following reasons:
|
| 74 |
+
|
| 75 |
+
* Future maintenance burden which I feel is excessive
|
| 76 |
+
* Impact on performance or functionality of existing features
|
| 77 |
+
* I don't like the feature, for reasons of aesthetics or toolchain compatibility
|
| 78 |
+
* I don't expect to have time to implement the feature in a reasonable timeframe
|
| 79 |
+
|
| 80 |
+
Please describe **why** the requested feature is useful. This helps me prioritise the request, and I might realise I also want this feature!
|
| 81 |
+
|
| 82 |
+
I am overwhelmingly more likely to implement requests for standard RISC-V ISA features than custom ones. As a rule, I don't implement standard RISC-V features that are not at least in the Frozen state. Please also consider the availability of toolchain support and upstream tests.
|
| 83 |
+
|
| 84 |
+
### Questions
|
| 85 |
+
|
| 86 |
+
The following questions are relevant to this repository and I am happy to answer them:
|
| 87 |
+
|
| 88 |
+
* Questions about Hazard3's implementation-defined behaviour in relation to the RISC-V standards
|
| 89 |
+
* Questions about tools used to build the Hazard3 simulator or tests (which are not covered by [Readme.md](Readme.md))
|
| 90 |
+
|
| 91 |
+
The following questions are not relevant and I am likely to either ignore or close them:
|
| 92 |
+
|
| 93 |
+
* Questions about Verilog
|
| 94 |
+
* The IEEE 1364-2005 PDF can be found online
|
| 95 |
+
* The best way to learn is to just do it ([instructional video](https://www.youtube.com/watch?v=ZXsQAXx_ao0))
|
| 96 |
+
* Get an FPGA board like an iCEBreaker and get hacking
|
| 97 |
+
* Yosys and nextpnr are great if you are already familiar with software tooling
|
| 98 |
+
* Start with blinking an LED, then PWM the LED, then implement UART TX, then UART RX
|
| 99 |
+
* Questions about the RISC-V ISA
|
| 100 |
+
* Get the latest ISA manual [here](https://github.com/riscv/riscv-isa-manual/releases/latest) (you want the _unprivileged_ manual first -- I find the HTML version more readable these days)
|
| 101 |
+
* There are some excellent books on the topic. I recommend the RISC-V edition of _Computer Organization and Design_ by Patterson & Hennessy for a gentle introduction to computer architecture as well as the RISC-V ISA.
|
| 102 |
+
* Questions which are not questions, i.e. telling me how clever you are
|
| 103 |
+
* I have ChatGPT for this purpose
|
Wren6991_Hazard3/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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enses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
+
the copyright owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
+
other entities that control, are controlled by, or are under common
|
| 17 |
+
control with that entity. For the purposes of this definition,
|
| 18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
+
direction or management of such entity, whether by contract or
|
| 20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
+
|
| 23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
+
exercising permissions granted by this License.
|
| 25 |
+
|
| 26 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
+
including but not limited to software source code, documentation
|
| 28 |
+
source, and configuration files.
|
| 29 |
+
|
| 30 |
+
"Object" form shall mean any form resulting from mechanical
|
| 31 |
+
transformation or translation of a Source form, including but
|
| 32 |
+
not limited to compiled object code, generated documentation,
|
| 33 |
+
and conversions to other media types.
|
| 34 |
+
|
| 35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
+
Object form, made available under the License, as indicated by a
|
| 37 |
+
copyright notice that is included in or attached to the work
|
| 38 |
+
(an example is provided in the Appendix below).
|
| 39 |
+
|
| 40 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 41 |
+
form, that is based on (or derived from) the Work and for which the
|
| 42 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 43 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 44 |
+
of this License, Derivative Works shall not include works that remain
|
| 45 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 46 |
+
the Work and Derivative Works thereof.
|
| 47 |
+
|
| 48 |
+
"Contribution" shall mean any work of authorship, including
|
| 49 |
+
the original version of the Work and any modifications or additions
|
| 50 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 51 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 52 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 53 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 54 |
+
means any form of electronic, verbal, or written communication sent
|
| 55 |
+
to the Licensor or its representatives, including but not limited to
|
| 56 |
+
communication on electronic mailing lists, source code control systems,
|
| 57 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 58 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 59 |
+
excluding communication that is conspicuously marked or otherwise
|
| 60 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 61 |
+
|
| 62 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 63 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 64 |
+
subsequently incorporated within the Work.
|
| 65 |
+
|
| 66 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 67 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 68 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 69 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 70 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 71 |
+
Work and such Derivative Works in Source or Object form.
|
| 72 |
+
|
| 73 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 74 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 75 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 76 |
+
(except as stated in this section) patent license to make, have made,
|
| 77 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 78 |
+
where such license applies only to those patent claims licensable
|
| 79 |
+
by such Contributor that are necessarily infringed by their
|
| 80 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 81 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 82 |
+
institute patent litigation against any entity (including a
|
| 83 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 84 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 85 |
+
or contributory patent infringement, then any patent licenses
|
| 86 |
+
granted to You under this License for that Work shall terminate
|
| 87 |
+
as of the date such litigation is filed.
|
| 88 |
+
|
| 89 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 90 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 91 |
+
modifications, and in Source or Object form, provided that You
|
| 92 |
+
meet the following conditions:
|
| 93 |
+
|
| 94 |
+
(a) You must give any other recipients of the Work or
|
| 95 |
+
Derivative Works a copy of this License; and
|
| 96 |
+
|
| 97 |
+
(b) You must cause any modified files to carry prominent notices
|
| 98 |
+
stating that You changed the files; and
|
| 99 |
+
|
| 100 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 101 |
+
that You distribute, all copyright, patent, trademark, and
|
| 102 |
+
attribution notices from the Source form of the Work,
|
| 103 |
+
excluding those notices that do not pertain to any part of
|
| 104 |
+
the Derivative Works; and
|
| 105 |
+
|
| 106 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 107 |
+
distribution, then any Derivative Works that You distribute must
|
| 108 |
+
include a readable copy of the attribution notices contained
|
| 109 |
+
within such NOTICE file, excluding those notices that do not
|
| 110 |
+
pertain to any part of the Derivative Works, in at least one
|
| 111 |
+
of the following places: within a NOTICE text file distributed
|
| 112 |
+
as part of the Derivative Works; within the Source form or
|
| 113 |
+
documentation, if provided along with the Derivative Works; or,
|
| 114 |
+
within a display generated by the Derivative Works, if and
|
| 115 |
+
wherever such third-party notices normally appear. The contents
|
| 116 |
+
of the NOTICE file are for informational purposes only and
|
| 117 |
+
do not modify the License. You may add Your own attribution
|
| 118 |
+
notices within Derivative Works that You distribute, alongside
|
| 119 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 120 |
+
that such additional attribution notices cannot be construed
|
| 121 |
+
as modifying the License.
|
| 122 |
+
|
| 123 |
+
You may add Your own copyright statement to Your modifications and
|
| 124 |
+
may provide additional or different license terms and conditions
|
| 125 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 126 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 127 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 128 |
+
the conditions stated in this License.
|
| 129 |
+
|
| 130 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 131 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 132 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 133 |
+
this License, without any additional terms or conditions.
|
| 134 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 135 |
+
the terms of any separate license agreement you may have executed
|
| 136 |
+
with Licensor regarding such Contributions.
|
| 137 |
+
|
| 138 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 139 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 140 |
+
except as required for reasonable and customary use in describing the
|
| 141 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 142 |
+
|
| 143 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 144 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 145 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 146 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 147 |
+
implied, including, without limitation, any warranties or conditions
|
| 148 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 149 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 150 |
+
appropriateness of using or redistributing the Work and assume any
|
| 151 |
+
risks associated with Your exercise of permissions under this License.
|
| 152 |
+
|
| 153 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 154 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 155 |
+
unless required by applicable law (such as deliberate and grossly
|
| 156 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 157 |
+
liable to You for damages, including any direct, indirect, special,
|
| 158 |
+
incidental, or consequential damages of any character arising as a
|
| 159 |
+
result of this License or out of the use or inability to use the
|
| 160 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 161 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 162 |
+
other commercial damages or losses), even if such Contributor
|
| 163 |
+
has been advised of the possibility of such damages.
|
| 164 |
+
|
| 165 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 166 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 167 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 168 |
+
or other liability obligations and/or rights consistent with this
|
| 169 |
+
License. However, in accepting such obligations, You may act only
|
| 170 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 171 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 172 |
+
defend, and hold each Contributor harmless for any liability
|
| 173 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 174 |
+
of your accepting any such warranty or additional liability.
|
| 175 |
+
|
| 176 |
+
END OF TERMS AND CONDITIONS
|
| 177 |
+
|
| 178 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 179 |
+
|
| 180 |
+
To apply the Apache License to your work, attach the following
|
| 181 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 182 |
+
replaced with your own identifying information. (Don't include
|
| 183 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 184 |
+
comment syntax for the file format. We also recommend that a
|
| 185 |
+
file or class name and description of purpose be included on the
|
| 186 |
+
same "printed page" as the copyright notice for easier
|
| 187 |
+
identification within third-party archives.
|
| 188 |
+
|
| 189 |
+
Copyright [yyyy] [name of copyright owner]
|
| 190 |
+
|
| 191 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 192 |
+
you may not use this file except in compliance with the License.
|
| 193 |
+
You may obtain a copy of the License at
|
| 194 |
+
|
| 195 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 196 |
+
|
| 197 |
+
Unless required by applicable law or agreed to in writing, software
|
| 198 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 199 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 200 |
+
See the License for the specific language governing permissions and
|
| 201 |
+
limitations under the License.
|
Wren6991_Hazard3/Readme.md
ADDED
|
@@ -0,0 +1,475 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
+
# Hazard3
|
| 2 |
+
|
| 3 |
+
Hazard3 is a 3-stage RISC-V processor, implementing the `RV32I` or `RV32E` instruction set and the following optional extensions:
|
| 4 |
+
|
| 5 |
+
* `M`: integer multiply/divide/modulo
|
| 6 |
+
* `A` : atomic memory operations, with AHB5 global exclusives
|
| 7 |
+
* `C`: compressed instructions
|
| 8 |
+
* `Zicsr`: CSR access
|
| 9 |
+
* `Zilsd`: load/store pair instructions
|
| 10 |
+
* `Zba`: address generation
|
| 11 |
+
* `Zbb`: basic bit manipulation
|
| 12 |
+
* `Zbc`: carry-less multiplication
|
| 13 |
+
* `Zbs`: single-bit manipulation
|
| 14 |
+
* `Zbkb`: basic bit manipulation for scalar cryptography
|
| 15 |
+
* `Zbkx`: crossbar permutation instructions
|
| 16 |
+
* `Zcb`: basic additional compressed instructions
|
| 17 |
+
* `Zclsd`: compressed load/store pair instructions
|
| 18 |
+
* `Zcmp`: push/pop instructions
|
| 19 |
+
* Debug, Machine and User privilege/execution modes
|
| 20 |
+
* Privileged instructions `ecall`, `ebreak`, `mret` and `wfi`
|
| 21 |
+
* Physical memory protection (PMP) with up to 16 regions (configurable support for NAPOT and/or TOR matching)
|
| 22 |
+
* External debug support (JTAG or APB)
|
| 23 |
+
* Instruction address trigger unit (hardware breakpoints)
|
| 24 |
+
|
| 25 |
+
Download the Hazard3 reference manual [here (PDF)](https://github.com/Wren6991/Hazard3/releases/download/v1.1/hazard3.pdf). You can also [read the documentation online](https://wren.wtf/hazard3/doc).
|
| 26 |
+
|
| 27 |
+
This repository contains the source for the Hazard3 core and its associated debug components. The [example SoC integration](example_soc/soc/example_soc.v) shows how you can assemble these components to create a minimal system with a JTAG-enabled RISC-V processor, some RAM, a serial port and a platform timer.
|
| 28 |
+
|
| 29 |
+
Please read [Contributing.md](Contributing.md) before raising an issue or pull request.
|
| 30 |
+
|
| 31 |
+
# Cloning This Repository
|
| 32 |
+
|
| 33 |
+
For the purpose of using Hazard3 in your design, this repository is self-contained. However, you need the submodules for simulation scripts, tests and example SoC components. In the latter case you should do a recursive clone:
|
| 34 |
+
|
| 35 |
+
```bash
|
| 36 |
+
git clone --recursive https://github.com/Wren6991/Hazard3.git hazard3
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
To initialise submodules in an already-cloned repository:
|
| 40 |
+
|
| 41 |
+
```bash
|
| 42 |
+
git submodule update --init --recursive
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
The default branch for clones is [stable](https://github.com/Wren6991/Hazard3/tree/stable). I strongly recommend this branch for ASIC tapeouts. The head of stable is always the latest non-development release under [releases](https://github.com/Wren6991/Hazard3/releases).
|
| 46 |
+
|
| 47 |
+
See the [develop](https://github.com/Wren6991/Hazard3/tree/develop) branch to try the latest features and optimisations.
|
| 48 |
+
|
| 49 |
+
# Running Hello World
|
| 50 |
+
|
| 51 |
+
These instructions walk through:
|
| 52 |
+
|
| 53 |
+
* Setting up the tools for building the Hazard3 simulator from Verilog source
|
| 54 |
+
* Setting up the tools for building RISC-V binaries to run on the simulator
|
| 55 |
+
* Building a "Hello, world!" binary and running it on the simulator
|
| 56 |
+
|
| 57 |
+
These instructions are for Ubuntu 24.04. If you are running on Windows you may have some success with Ubuntu under WSL.
|
| 58 |
+
|
| 59 |
+
You will need:
|
| 60 |
+
|
| 61 |
+
* A recent Yosys build to process the Verilog (these instructions were last tested with `a0e94e506`)
|
| 62 |
+
* A `riscv32-unknown-elf-` toolchain to build software for the core
|
| 63 |
+
* A native `clang-16` to build the simulator
|
| 64 |
+
|
| 65 |
+
`clang-17` is also known to work fine. `clang-18` does work, but has a serious compile time regression with CXXRTL output, which is why the `tb_cxxrtl` Makefile explicitly selects `clang-16`.
|
| 66 |
+
|
| 67 |
+
## Yosys
|
| 68 |
+
|
| 69 |
+
The [Yosys GitHub repo](https://github.com/YosysHQ/yosys) has instructions for building Yosys from source.
|
| 70 |
+
|
| 71 |
+
The following steps work for me on Ubuntu 24.04 using version `a0e94e506` mentioned above.
|
| 72 |
+
|
| 73 |
+
```bash
|
| 74 |
+
sudo apt install build-essential clang lld bison flex libreadline-dev gawk tcl-dev libffi-dev git graphviz xdot pkg-config python3 libboost-system-dev libboost-python-dev libboost-filesystem-dev zlib1g-dev
|
| 75 |
+
|
| 76 |
+
git clone https://github.com/YosysHQ/yosys.git
|
| 77 |
+
cd yosys
|
| 78 |
+
git submodule update --init
|
| 79 |
+
make -j$(nproc)
|
| 80 |
+
sudo make install
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
On MacOS the dependencies can be installed with:
|
| 84 |
+
|
| 85 |
+
```bash
|
| 86 |
+
brew install graphviz python3 boost zlib bison flex xdot pkg-config gawk lld
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
## RISC-V Toolchain
|
| 90 |
+
|
| 91 |
+
I recommend _building_ a toolchain to get libraries with the correct ISA support. Follow the below instructions to build a 32-bit version of the [RISC-V GNU toolchain](https://github.com/riscv/riscv-gnu-toolchain) with a multilib setup suitable for Hazard3 development.
|
| 92 |
+
|
| 93 |
+
```bash
|
| 94 |
+
# Prerequisites for Ubuntu 24.04
|
| 95 |
+
sudo apt install autoconf automake autotools-dev curl python3 python3-pip libmpc-dev libmpfr-dev libgmp-dev gawk build-essential bison flex texinfo gperf libtool patchutils bc zlib1g-dev libexpat-dev ninja-build git cmake libglib2.0-dev libslirp-dev
|
| 96 |
+
|
| 97 |
+
cd /tmp
|
| 98 |
+
git clone https://github.com/riscv/riscv-gnu-toolchain
|
| 99 |
+
cd riscv-gnu-toolchain
|
| 100 |
+
|
| 101 |
+
./configure --prefix=/opt/riscv/gcc15 --with-arch=rv32ia_zicsr_zifencei --with-abi=ilp32 --with-multilib-generator="rv32i_zicsr_zifencei-ilp32--;rv32im_zicsr_zifencei-ilp32--;rv32ia_zicsr_zifencei-ilp32--;rv32ima_zicsr_zifencei-ilp32--;rv32ic_zicsr_zifencei-ilp32--;rv32imc_zicsr_zifencei-ilp32--;rv32iac_zicsr_zifencei-ilp32--;rv32imac_zicsr_zifencei-ilp32--;rv32im_zba_zbb_zbs_zicsr_zifencei-ilp32--;rv32ima_zba_zbb_zbs_zicsr_zifencei-ilp32--;rv32imc_zba_zbb_zbs_zicsr_zifencei-ilp32--;rv32imac_zba_zbb_zbs_zicsr_zifencei-ilp32--;rv32im_zba_zbb_zbs_zbkb_zicsr_zifencei-ilp32--;rv32ima_zba_zbb_zbs_zbkb_zicsr_zifencei-ilp32--;rv32imc_zba_zbb_zbs_zbkb_zicsr_zifencei-ilp32--;rv32imac_zba_zbb_zbs_zbkb_zicsr_zifencei-ilp32--;rv32im_zba_zbb_zbc_zbs_zbkb_zicsr_zifencei-ilp32--;rv32ima_zba_zbb_zbc_zbs_zbkb_zicsr_zifencei-ilp32--;rv32imc_zba_zbb_zbc_zbs_zbkb_zicsr_zifencei-ilp32--;rv32imac_zba_zbb_zbc_zbs_zbkb_zicsr_zifencei-ilp32--;rv32im_zba_zbb_zbs_zbkb_zbkx_zicsr_zifencei-ilp32--;rv32ima_zba_zbb_zbs_zbkb_zbkx_zicsr_zifencei-ilp32--;rv32imc_zba_zbb_zbs_zbkb_zbkx_zicsr_zifencei-ilp32--;rv32imac_zba_zbb_zbs_zbkb_zbkx_zicsr_zifencei-ilp32--;rv32im_zba_zbb_zbc_zbs_zbkb_zbkx_zicsr_zifencei-ilp32--;rv32ima_zba_zbb_zbc_zbs_zbkb_zbkx_zicsr_zifencei-ilp32--;rv32imc_zba_zbb_zbc_zbs_zbkb_zbkx_zicsr_zifencei-ilp32--;rv32imac_zba_zbb_zbc_zbs_zbkb_zbkx_zicsr_zifencei-ilp32--;rv32i_zca_zicsr_zifencei-ilp32--;rv32im_zca_zicsr_zifencei-ilp32--;rv32ia_zca_zicsr_zifencei-ilp32--;rv32ima_zca_zicsr_zifencei-ilp32--;rv32im_zba_zbb_zbs_zca_zicsr_zifencei-ilp32--;rv32ima_zba_zbb_zbs_zca_zicsr_zifencei-ilp32--;rv32im_zba_zbb_zbs_zbkb_zca_zicsr_zifencei-ilp32--;rv32ima_zba_zbb_zbs_zbkb_zca_zicsr_zifencei-ilp32--;rv32im_zba_zbb_zbc_zbs_zbkb_zca_zicsr_zifencei-ilp32--;rv32ima_zba_zbb_zbc_zbs_zbkb_zca_zicsr_zifencei-ilp32--;rv32im_zba_zbb_zbs_zbkb_zbkx_zca_zicsr_zifencei-ilp32--;rv32ima_zba_zbb_zbs_zbkb_zbkx_zca_zicsr_zifencei-ilp32--;rv32im_zba_zbb_zbc_zbs_zbkb_zbkx_zca_zicsr_zifencei-ilp32--;rv32ima_zba_zbb_zbc_zbs_zbkb_zbkx_zca_zicsr_zifencei-ilp32--;rv32i_zca_zcb_zicsr_zifencei-ilp32--;rv32im_zca_zcb_zicsr_zifencei-ilp32--;rv32ia_zca_zcb_zicsr_zifencei-ilp32--;rv32ima_zca_zcb_zicsr_zifencei-ilp32--;rv32im_zba_zbb_zbs_zca_zcb_zicsr_zifencei-ilp32--;rv32ima_zba_zbb_zbs_zca_zcb_zicsr_zifencei-ilp32--;rv32im_zba_zbb_zbs_zbkb_zca_zcb_zicsr_zifencei-ilp32--;rv32ima_zba_zbb_zbs_zbkb_zca_zcb_zicsr_zifencei-ilp32--;rv32im_zba_zbb_zbc_zbs_zbkb_zca_zcb_zicsr_zifencei-ilp32--;rv32ima_zba_zbb_zbc_zbs_zbkb_zca_zcb_zicsr_zifencei-ilp32--;rv32im_zba_zbb_zbs_zbkb_zbkx_zca_zcb_zicsr_zifencei-ilp32--;rv32ima_zba_zbb_zbs_zbkb_zbkx_zca_zcb_zicsr_zifencei-ilp32--;rv32im_zba_zbb_zbc_zbs_zbkb_zbkx_zca_zcb_zicsr_zifencei-ilp32--;rv32ima_zba_zbb_zbc_zbs_zbkb_zbkx_zca_zcb_zicsr_zifencei-ilp32--;rv32i_zca_zcb_zcmp_zicsr_zifencei-ilp32--;rv32im_zca_zcb_zcmp_zicsr_zifencei-ilp32--;rv32ia_zca_zcb_zcmp_zicsr_zifencei-ilp32--;rv32ima_zca_zcb_zcmp_zicsr_zifencei-ilp32--;rv32im_zba_zbb_zbs_zca_zcb_zcmp_zicsr_zifencei-ilp32--;rv32ima_zba_zbb_zbs_zca_zcb_zcmp_zicsr_zifencei-ilp32--;rv32im_zba_zbb_zbs_zbkb_zca_zcb_zcmp_zicsr_zifencei-ilp32--;rv32ima_zba_zbb_zbs_zbkb_zca_zcb_zcmp_zicsr_zifencei-ilp32--;rv32im_zba_zbb_zbc_zbs_zbkb_zca_zcb_zcmp_zicsr_zifencei-ilp32--;rv32ima_zba_zbb_zbc_zbs_zbkb_zca_zcb_zcmp_zicsr_zifencei-ilp32--;rv32im_zba_zbb_zbs_zbkb_zbkx_zca_zcb_zcmp_zicsr_zifencei-ilp32--;rv32ima_zba_zbb_zbs_zbkb_zbkx_zca_zcb_zcmp_zicsr_zifencei-ilp32--;rv32im_zba_zbb_zbc_zbs_zbkb_zbkx_zca_zcb_zcmp_zicsr_zifencei-ilp32--;rv32ima_zba_zbb_zbc_zbs_zbkb_zbkx_zca_zcb_zcmp_zicsr_zifencei-ilp32--;rv32i_zmmul_zicsr_zifencei-ilp32--;rv32ia_zmmul_zicsr_zifencei-ilp32--;rv32ic_zmmul_zicsr_zifencei-ilp32--;rv32iac_zmmul_zicsr_zifencei-ilp32--;rv32i_zca_zmmul_zicsr_zifencei-ilp32--;rv32ia_zca_zmmul_zicsr_zifencei-ilp32--;rv32i_zca_zcb_zmmul_zicsr_zifencei-ilp32--;rv32ia_zca_zcb_zmmul_zicsr_zifencei-ilp32--;rv32i_zca_zcb_zcmp_zmmul_zicsr_zifencei-ilp32--;rv32ia_zca_zcb_zcmp_zmmul_zicsr_zifencei-ilp32--;rv32e_zicsr_zifencei-ilp32e--;rv32ema_zicsr_zifencei-ilp32e--;rv32emac_zicsr_zifencei-ilp32e--;rv32ema_zicsr_zifencei_zba_zbb_zbc_zbkb_zbkx_zbs_zca_zcb_zcmp-ilp32e--"
|
| 102 |
+
sudo mkdir -p /opt/riscv/gcc15
|
| 103 |
+
sudo chown $(whoami) /opt/riscv/gcc15
|
| 104 |
+
make -j $(nproc)
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
The `--with-multilib-generator=` flag builds multiple versions of the standard library, to match possible `-march` flags provided at link time. The multilib-generator command line above was generated using [multilib-gen-gen.py](test/sim/common/multilib-gen-gen.py)
|
| 108 |
+
|
| 109 |
+
Make sure this toolchain can be found on your `PATH` (as `riscv32-unknown-elf-*`):
|
| 110 |
+
|
| 111 |
+
```bash
|
| 112 |
+
export PATH="$PATH:/opt/riscv/gcc15/bin"
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
### Non-multilib (Smaller Install Size)
|
| 116 |
+
|
| 117 |
+
For a faster build and a smaller install size, use this `./configure` line instead:
|
| 118 |
+
|
| 119 |
+
```bash
|
| 120 |
+
./configure --prefix=/opt/riscv/gcc15 --with-arch=rv32imac_zicsr_zifencei_zba_zbb_zbkb_zbs --with-abi=ilp32
|
| 121 |
+
```
|
| 122 |
+
|
| 123 |
+
Adjust the `--with-arch` line as necessary for your Hazard3 configuration. You may need to adjust architectures used in software Makefiles in this repository to fit your chosen architecture variant.
|
| 124 |
+
|
| 125 |
+
### Building Toolchain on MacOS
|
| 126 |
+
|
| 127 |
+
These are my hacks to build the latest `riscv-gnu-toolchain` on MacOS Sequoia on M4 (Arm).
|
| 128 |
+
|
| 129 |
+
```bash
|
| 130 |
+
brew install python3 gawk gnu-sed make gmp mpfr libmpc isl zlib expat texinfo flock libslirp
|
| 131 |
+
git clone https://github.com/riscv/riscv-gnu-toolchain
|
| 132 |
+
cd riscv-gnu-toolchain
|
| 133 |
+
git submodule update --init -- binutils gdb
|
| 134 |
+
# HACK for a macro definition which conflicts with a system header:
|
| 135 |
+
gsed -i 's,# define fdopen,//#define fdopen,' binutils/zlib/zutil.h gdb/zlib/zutil.h
|
| 136 |
+
|
| 137 |
+
export PATH="/opt/homebrew/bin:$PATH"
|
| 138 |
+
export LDFLAGS="-L/opt/homebrew/lib"
|
| 139 |
+
export CPPFLAGS="-I/opt/homebrew/include"
|
| 140 |
+
./configure --prefix=/opt/riscv/gcc15 --with-arch=rv32imac_zicsr_zifencei_zba_zbb_zbkb_zbs --with-abi=ilp32
|
| 141 |
+
gmake -j10
|
| 142 |
+
```
|
| 143 |
+
|
| 144 |
+
## Actually Running Hello World
|
| 145 |
+
|
| 146 |
+
Make sure you have done a _recursive_ clone of the Hazard3 repository. Build the CXXRTL-based simulator:
|
| 147 |
+
|
| 148 |
+
```bash
|
| 149 |
+
cd hazard3
|
| 150 |
+
cd test/sim/tb_cxxrtl
|
| 151 |
+
make
|
| 152 |
+
```
|
| 153 |
+
|
| 154 |
+
Build and run the hello world binary:
|
| 155 |
+
|
| 156 |
+
```bash
|
| 157 |
+
cd ../hellow
|
| 158 |
+
make
|
| 159 |
+
```
|
| 160 |
+
|
| 161 |
+
All going well you should see something like:
|
| 162 |
+
|
| 163 |
+
```
|
| 164 |
+
$ make
|
| 165 |
+
mkdir -p tmp/
|
| 166 |
+
riscv32-unknown-elf-gcc -march=rv32imac_zicsr_zifencei_zba_zbb_zbkb_zbs -Os -Wl,--no-warn-rwx-segments ../common/init.S main.c -T ../common/memmap.ld -I../common -o tmp/hellow.elf
|
| 167 |
+
riscv32-unknown-elf-objcopy -O binary tmp/hellow.elf tmp/hellow.bin
|
| 168 |
+
riscv32-unknown-elf-objdump -h tmp/hellow.elf > tmp/hellow.dis
|
| 169 |
+
riscv32-unknown-elf-objdump -d tmp/hellow.elf >> tmp/hellow.dis
|
| 170 |
+
../tb_cxxrtl/tb --bin tmp/hellow.bin --vcd tmp/hellow_run.vcd --cycles 100000
|
| 171 |
+
Hello world from Hazard3 + CXXRTL!
|
| 172 |
+
CPU requested halt. Exit code 123
|
| 173 |
+
Ran for 897 cycles
|
| 174 |
+
```
|
| 175 |
+
|
| 176 |
+
This will have created a waveform dump called `tmp/hellow_run.vcd` which you can view with GTKWave:
|
| 177 |
+
|
| 178 |
+
```bash
|
| 179 |
+
gtkwave tmp/hellow_run.vcd
|
| 180 |
+
```
|
| 181 |
+
|
| 182 |
+
Installing GTKWave on Ubuntu 24.04 is just `sudo apt install gtkwave`.
|
| 183 |
+
|
| 184 |
+
# Loading Hello World with the Debugger
|
| 185 |
+
|
| 186 |
+
Invoking the simulator built in the previous step, with no arguments, shows the following usage message:
|
| 187 |
+
|
| 188 |
+
```
|
| 189 |
+
$ ./tb
|
| 190 |
+
At least one of --bin or --port must be specified.
|
| 191 |
+
Usage: tb [--bin x.bin] [--vcd x.vcd] [--dump start end] [--cycles n] [--port n]
|
| 192 |
+
--bin x.bin : Flat binary file loaded to address 0x0 in RAM
|
| 193 |
+
--vcd x.vcd : Path to dump waveforms to
|
| 194 |
+
--dump start end : Print out memory contents from start to end (exclusive)
|
| 195 |
+
after execution finishes. Can be passed multiple times.
|
| 196 |
+
--cycles n : Maximum number of cycles to run before exiting.
|
| 197 |
+
Default is 0 (no maximum).
|
| 198 |
+
--port n : Port number to listen for openocd remote bitbang. Sim
|
| 199 |
+
runs in lockstep with JTAG bitbang, not free-running.
|
| 200 |
+
```
|
| 201 |
+
|
| 202 |
+
This simulator contains:
|
| 203 |
+
|
| 204 |
+
- Hardware:
|
| 205 |
+
- The processor
|
| 206 |
+
- A Debug Module (DM)
|
| 207 |
+
- A JTAG Debug Transport Module (DTM)
|
| 208 |
+
- Software:
|
| 209 |
+
- RAM model
|
| 210 |
+
- Routines for loading binary files, dumping VCDs
|
| 211 |
+
- Routines for bitbanging the JTAG DTM through a TCP socket
|
| 212 |
+
|
| 213 |
+
Running hello world in the previous section used the `--bin` argument to load the linked hello world executable directly into the testbench's RAM. If we invoke the simulator with the `--port` argument, it will instead wait for a connection on that port, and then accept JTAG bitbang commands in OpenOCD's `remote-bitbang` format. The simulation runs in lockstep with the JTAG bitbanging, for more predictable results.
|
| 214 |
+
|
| 215 |
+
We need to build a copy of `riscv-openocd` before going any further. OpenOCD's role is to translate the abstract debug commands issued by gdb, e.g. "set the program counter to address `x`", to more concrete operations, e.g. "shift this JTAG DR".
|
| 216 |
+
|
| 217 |
+
## Building riscv-openocd
|
| 218 |
+
|
| 219 |
+
We need a recent build of [riscv-openocd](https://github.com/riscv/riscv-openocd) with the `remote-bitbang` protocol enabled.
|
| 220 |
+
|
| 221 |
+
On Ubuntu:
|
| 222 |
+
|
| 223 |
+
```bash
|
| 224 |
+
cd /tmp
|
| 225 |
+
git clone https://github.com/riscv/riscv-openocd.git
|
| 226 |
+
cd riscv-openocd
|
| 227 |
+
./bootstrap
|
| 228 |
+
# Prefix is optional
|
| 229 |
+
./configure --enable-remote-bitbang --enable-ftdi --program-prefix=riscv-
|
| 230 |
+
make -j $(nproc)
|
| 231 |
+
sudo make install
|
| 232 |
+
```
|
| 233 |
+
|
| 234 |
+
On MacOS:
|
| 235 |
+
|
| 236 |
+
```bash
|
| 237 |
+
brew install autoconf automake libusb jimtcl
|
| 238 |
+
cd /tmp
|
| 239 |
+
git clone https://github.com/riscv/riscv-openocd.git
|
| 240 |
+
cd riscv-openocd
|
| 241 |
+
./bootstrap
|
| 242 |
+
# Workarounds:
|
| 243 |
+
# - System clang has a warning for the GCC constant VLA thing, and OpenOCD is -Werror by default
|
| 244 |
+
# - amtjtagaccel driver tries to pull in a Linux header
|
| 245 |
+
CFLAGS=-Wno-gnu-folding-constant ./configure --enable-remote-bitbang --enable-ftdi --enable-amtjtagaccel=no --program-prefix=riscv-
|
| 246 |
+
```
|
| 247 |
+
## Loading and Running
|
| 248 |
+
|
| 249 |
+
You're going to want three terminal tabs in the `tb_cxxrtl` directory.
|
| 250 |
+
|
| 251 |
+
```bash
|
| 252 |
+
cd hazard3/test/sim/tb_cxxrtl
|
| 253 |
+
```
|
| 254 |
+
|
| 255 |
+
In the first of them type:
|
| 256 |
+
|
| 257 |
+
```bash
|
| 258 |
+
./tb --port 9824
|
| 259 |
+
```
|
| 260 |
+
|
| 261 |
+
You should see something like
|
| 262 |
+
|
| 263 |
+
```
|
| 264 |
+
Waiting for connection on port 9824
|
| 265 |
+
```
|
| 266 |
+
|
| 267 |
+
The simulation will start once OpenOCD connects. In your second terminal in the same directory, start riscv-openocd:
|
| 268 |
+
|
| 269 |
+
```bash
|
| 270 |
+
riscv-openocd -f openocd.cfg
|
| 271 |
+
```
|
| 272 |
+
|
| 273 |
+
If you see something like:
|
| 274 |
+
|
| 275 |
+
```
|
| 276 |
+
Info : Initializing remote_bitbang driver
|
| 277 |
+
Info : Connecting to localhost:9824
|
| 278 |
+
Info : remote_bitbang driver initialized
|
| 279 |
+
Info : Note: The adapter "remote_bitbang" doesn't support configurable speed
|
| 280 |
+
Info : JTAG tap: hazard3.cpu tap/device found: 0xdeadbeef (mfg: 0x777 (Fabric of Truth Inc), part: 0xeadb, ver: 0xd)
|
| 281 |
+
Info : [hazard3.cpu] datacount=1 progbufsize=2
|
| 282 |
+
Info : [hazard3.cpu] Examined RISC-V core
|
| 283 |
+
Info : [hazard3.cpu] XLEN=32, misa=0x40901107
|
| 284 |
+
[hazard3.cpu] Target successfully examined.
|
| 285 |
+
Info : [hazard3.cpu] Examination succeed
|
| 286 |
+
Info : [hazard3.cpu] starting gdb server on 3333
|
| 287 |
+
Info : Listening on port 3333 for gdb connections
|
| 288 |
+
hazard3.cpu halted due to debug-request.
|
| 289 |
+
Info : Listening on port 6666 for tcl connections
|
| 290 |
+
Info : Listening on port 4444 for telnet connections
|
| 291 |
+
```
|
| 292 |
+
|
| 293 |
+
Then openocd is successfully connected to the processor's debug hardware. We're going to use riscv-gdb to load and run the hello world executable, which is what the third terminal is for:
|
| 294 |
+
|
| 295 |
+
```bash
|
| 296 |
+
riscv32-unknown-elf-gdb
|
| 297 |
+
# Remaining commands are typed into the gdb prompt. This one tells gdb to shut up:
|
| 298 |
+
set confirm off
|
| 299 |
+
# Connect to openocd on its default port:
|
| 300 |
+
target extended-remote localhost:3333
|
| 301 |
+
# Load hello world, and check that it loaded correctly
|
| 302 |
+
file ../hellow/tmp/hellow.elf
|
| 303 |
+
load
|
| 304 |
+
compare-sections
|
| 305 |
+
# The processor will quit the simulation when after returning from main(), by
|
| 306 |
+
# writing to a magic MMIO register. openocd will be quite unhappy that the
|
| 307 |
+
# other end of its socket disappeared, so to avoid the resulting error
|
| 308 |
+
# messages, add a breakpoint before _exit.
|
| 309 |
+
break _exit
|
| 310 |
+
run
|
| 311 |
+
# Should break at _exit. Check the terminal with the simulator, you should see
|
| 312 |
+
# the hello world message. The exit code is in register a0, it should be 123:
|
| 313 |
+
info reg a0
|
| 314 |
+
```
|
| 315 |
+
|
| 316 |
+
# Simulating with Verilator
|
| 317 |
+
|
| 318 |
+
There is a Verilator harness with the same features and interface as the CXXRTL harness, except it does not support VCD dumping. First build Verilator:
|
| 319 |
+
|
| 320 |
+
```
|
| 321 |
+
git clone https://github.com/verilator/verilator.git
|
| 322 |
+
cd verilator
|
| 323 |
+
mkdir build
|
| 324 |
+
cd build
|
| 325 |
+
cmake ..
|
| 326 |
+
make -j$(nproc)
|
| 327 |
+
sudo make install
|
| 328 |
+
```
|
| 329 |
+
|
| 330 |
+
Then go to the Hazard3 repository and build the simulator. You should be able to run the hello world binary you compiled earlier:
|
| 331 |
+
|
| 332 |
+
```bash
|
| 333 |
+
cd test/sim/tb_verilator
|
| 334 |
+
make tb
|
| 335 |
+
./tb --bin ../hellow/tmp/hellow.bin
|
| 336 |
+
```
|
| 337 |
+
|
| 338 |
+
# Building an Example SoC
|
| 339 |
+
|
| 340 |
+
There is a tiny [example SoC](example_soc/soc/example_soc.v) which builds on iCEBreaker, ULX3S and Arty A7-100T boards. The SoC contains:
|
| 341 |
+
|
| 342 |
+
- A Hazard3 processor, in a single-ported RV32IMA configuration, with debug support
|
| 343 |
+
- A Debug Transport Module and Debug Module to access Hazard3's debug interface
|
| 344 |
+
- 128 kB of RAM (fits in UP5k SPRAMs)
|
| 345 |
+
- A UART
|
| 346 |
+
- A standard RISC-V platform timer
|
| 347 |
+
|
| 348 |
+
Note there is no software tree for this SoC. For now you'll have to read the source and hack on the test software build. At least you can attach to the processor, poke registers/memory, and convince yourself you really are debugging a RISC-V core.
|
| 349 |
+
|
| 350 |
+
## Comparison of Supported Boards
|
| 351 |
+
|
| 352 |
+
On [iCEBreaker](https://1bitsquared.com/products/icebreaker) (a iCE40 UP5k development board), the processor can be debugged using the onboard FT2232H bridge, through a standard RISCV-V JTAG-DTM exposed on four IO pins. Connecting JTAG requires two solder jumpers to be bridged on the back to connect the JTAG -- see the comments in the [pin constraints file](example_soc/synth/fpga_icebreaker.pcf). FT2232H is a dual-channel FTDI device, so the UART and JTAG can be accessed simultaneously for a very civilised debug experience, with JTAG running at the full 30 MHz supported by the FTDI.
|
| 353 |
+
|
| 354 |
+
[ULX3S](https://radiona.org/ulx3s/) is based on a much larger ECP5 FPGA. Thanks to [this ECP5 JTAG adapter](hdl/debug/dtm/hazard3_ecp5_jtag_dtm.v), it is possible to attach the guts of a RISC-V JTAG-DTM to the custom DR hooks in ECP5's chip TAP. With the right config file you can then convince OpenOCD that the FPGA's own TAP *is* a JTAG-DTM. You can debug Hazard3 on ULX3S using the same micro USB cable you use to load the bitstream, no soldering required. The downside is that the FT231X device on the ULX3S is actually a UART bridge which supports JTAG by bitbanging the auxiliary UART signals, which is incredibly slow. The UART cannot be used simultaneously with JTAG access. The debugging experience is worse than iCEBreaker because of this.
|
| 355 |
+
|
| 356 |
+
Arty A7-100T uses an Artix-7 FPGA. This is the fastest and most capacious of the boards supported by this example SoC integration, but it's also the most expensive. The board has an FT2232H debug probe, similar to iCEBreaker. The probe is intended for programming the FPGA, or for Xilinx debug functionality like ILA. Using the probe, you can tunnel RISC-V debug traffic through the Artix-7 chip TAP [in a similar way](hdl/debug/dtm/hazard3_xilinx7_jtag_dtm.v) to ECP5, using the `BSCANE2` primitive. There is no performance cost to this tunnelling as the DTM registers are exposed directly as DRs on the FPGA chip TAP, so this is an excellent combination of a fast FPGA and a fast debug interface.
|
| 357 |
+
|
| 358 |
+
## Building for iCEBreaker
|
| 359 |
+
|
| 360 |
+
You must have `nextpnr-ice40`, `yosys`, and `iceprog` (from icestorm) on your PATH.
|
| 361 |
+
|
| 362 |
+
```bash
|
| 363 |
+
cd hazard3
|
| 364 |
+
cd example_soc/synth
|
| 365 |
+
make -f Icebreaker.mk prog
|
| 366 |
+
# Should be able to attach to the processor
|
| 367 |
+
riscv-openocd -f ../icebreaker-openocd.cfg
|
| 368 |
+
```
|
| 369 |
+
|
| 370 |
+
## Building for ULX3S
|
| 371 |
+
|
| 372 |
+
You must have `nextpnr-ecp5`, `yosys` and [ujprog](https://github.com/f32c/tools/blob/master/ujprog/README.md) on your PATH.
|
| 373 |
+
|
| 374 |
+
```bash
|
| 375 |
+
cd hazard3
|
| 376 |
+
cd example_soc/synth
|
| 377 |
+
make -f ULX3S.mk flash
|
| 378 |
+
# Should be able to attach to the processor
|
| 379 |
+
riscv-openocd -f ../ulx3s-openocd.cfg
|
| 380 |
+
```
|
| 381 |
+
|
| 382 |
+
## Building for Arty A7-100T
|
| 383 |
+
|
| 384 |
+
These scripts use Vivado to build and load the bitstream. You must have `vivado` on your `PATH`; I used version 2025.1. The free version of Vivado supports the A7-100T, so just type some swear words into AMD's export compliance form and away you go.
|
| 385 |
+
|
| 386 |
+
```bash
|
| 387 |
+
cd hazard3
|
| 388 |
+
cd example_soc/synth_vivado
|
| 389 |
+
make prog
|
| 390 |
+
# Should be able to attach to the processor
|
| 391 |
+
riscv-openocd -f ../arty7-openocd.cfg
|
| 392 |
+
```
|
| 393 |
+
|
| 394 |
+
Vivado and OpenOCD cannot simultaneously connect to the FTDI. If OpenOCD is connected then Vivado will fail to reprogram the FPGA.
|
| 395 |
+
|
| 396 |
+
# Performance
|
| 397 |
+
|
| 398 |
+
## RP2350
|
| 399 |
+
|
| 400 |
+
The RP2350 configuration of Hazard3 achieves 4.15 CoreMark/MHz.
|
| 401 |
+
|
| 402 |
+
```
|
| 403 |
+
2K performance run parameters for coremark.
|
| 404 |
+
CoreMark Size : 666
|
| 405 |
+
Total ticks : 14440822
|
| 406 |
+
Total time (secs): 14.440822
|
| 407 |
+
Iterations/Sec : 4.154888
|
| 408 |
+
Iterations : 60
|
| 409 |
+
Compiler version : GCC15.1.0
|
| 410 |
+
Compiler flags : -O3 -g -march=rv32ima_zicsr_zifencei_zba_zbb_zbkb_zbs -mbranch-cost=1 -funroll-all-loops --param max-inline-insns-auto=200 -finline-limit=10000 -fno-code-hoisting -fno-if-conversion2 -DPERFORMANCE_RUN=1
|
| 411 |
+
Memory location : STACK
|
| 412 |
+
seedcrc : 0xe9f5
|
| 413 |
+
[0]crclist : 0xe714
|
| 414 |
+
[0]crcmatrix : 0x1fd7
|
| 415 |
+
[0]crcstate : 0x8e3a
|
| 416 |
+
[0]crcfinal : 0xa14c
|
| 417 |
+
Correct operation validated. See README.md for run and reporting rules.
|
| 418 |
+
CoreMark 1.0 : 4.154888 / GCC15.1.0 -O3 -g -march=rv32ima_zicsr_zifencei_zba_zbb_zbkb_zbs -mbranch-cost=1 -funroll-all-loops --param max-inline-insns-auto=200 -finline-limit=10000 -fno-code-hoisting -fno-if-conversion2 -DPERFORMANCE_RUN=1 / STACK
|
| 419 |
+
```
|
| 420 |
+
|
| 421 |
+
To reproduce this in the RTL simulator, use the top-level Makefile in [test/sim/coremark](test/sim/coremark) after you have followed all the steps to get set up for running a "Hello, world!" binary above. Expect the simulation to take a couple of minutes.
|
| 422 |
+
|
| 423 |
+
```bash
|
| 424 |
+
cd test/sim/coremark
|
| 425 |
+
make
|
| 426 |
+
```
|
| 427 |
+
|
| 428 |
+
The default flags are appropriate for the non-multilib toolchain build, and achieve 4.10 CoreMark/MHz. To achieve the full 4.15 CoreMark/MHz, change the ISA variant in `core_portme.mak` to `rv32ima_zicsr_zifencei_zba_zbb_zbkb_zbs`. See the comments in that file for an explanation of why this makes a difference.
|
| 429 |
+
|
| 430 |
+
See the RP2350 datasheet for details of the Hazard3 configuration used by that chip. The default `tb_cxxrtl` build uses the same configuration as RP2350, except that it also enables the Zbc extension (which is not emitted by GCC 14 as it is not useful for general-purpose code).
|
| 431 |
+
|
| 432 |
+
## Maximum
|
| 433 |
+
|
| 434 |
+
As of GCC 15, GCC can infer `clmul` and `clmulh` instructions in the CoreMark CRC function. The Zbc extension was dropped from the RP2350 configuration as compilers were not able to exploit it at the time. Enabling Zbc increases the score to 4.25 CoreMark/MHz.
|
| 435 |
+
|
| 436 |
+
```
|
| 437 |
+
CoreMark Size : 666
|
| 438 |
+
Total ticks : 14121622
|
| 439 |
+
Total time (secs): 14.121622
|
| 440 |
+
Iterations/Sec : 4.248804
|
| 441 |
+
Iterations : 60
|
| 442 |
+
Compiler version : GCC15.1.0
|
| 443 |
+
Compiler flags : -O3 -g -march=rv32ima_zicsr_zifencei_zba_zbb_zbkb_zbs_zbc -mbranch-cost=1 -funroll-all-loops --param max-inline-insns-auto=200 -finline-limit=10000 -fno-code-hoisting -fno-if-conversion2 -falign-functions=4 -falign-jumps=4 -falign-loops=4 -DPERFORMANCE_RUN=1
|
| 444 |
+
Memory location : STACK
|
| 445 |
+
seedcrc : 0xe9f5
|
| 446 |
+
[0]crclist : 0xe714
|
| 447 |
+
[0]crcmatrix : 0x1fd7
|
| 448 |
+
[0]crcstate : 0x8e3a
|
| 449 |
+
[0]crcfinal : 0xa14c
|
| 450 |
+
Correct operation validated. See README.md for run and reporting rules.
|
| 451 |
+
CoreMark 1.0 : 4.248804 / GCC15.1.0 -O3 -g -march=rv32ima_zicsr_zifencei_zba_zbb_zbkb_zbs_zbc -mbranch-cost=1 -funroll-all-loops --param max-inline-insns-auto=200 -finline-limit=10000 -fno-code-hoisting -fno-if-conversion2 -falign-functions=4 -falign-jumps=4 -falign-loops=4 -DPERFORMANCE_RUN=1 / STACK
|
| 452 |
+
```
|
| 453 |
+
|
| 454 |
+
## RV32E
|
| 455 |
+
|
| 456 |
+
Reducing the number of GPRs from 31 to 15 carries around a 5% penalty, at 4.02 CoreMark/MHz.
|
| 457 |
+
|
| 458 |
+
```
|
| 459 |
+
2K performance run parameters for coremark.
|
| 460 |
+
CoreMark Size : 666
|
| 461 |
+
Total ticks : 14908801
|
| 462 |
+
Total time (secs): 14.908801
|
| 463 |
+
Iterations/Sec : 4.024469
|
| 464 |
+
Iterations : 60
|
| 465 |
+
Compiler version : GCC15.1.0
|
| 466 |
+
Compiler flags : -O3 -g -march=rv32ema_zba_zbb_zbc_zbkb_zbkx_zbs_zicsr_zifencei -mabi=ilp32e -mbranch-cost=1 -funroll-all-loops --param max-inline-insns-auto=200 -finline-limit=10000 -fno-code-hoisting -fno-if-conversion2 -falign-functions=4 -falign-jumps=4 -falign-loops=4 -DPERFORMANCE_RUN=1
|
| 467 |
+
Memory location : STACK
|
| 468 |
+
seedcrc : 0xe9f5
|
| 469 |
+
[0]crclist : 0xe714
|
| 470 |
+
[0]crcmatrix : 0x1fd7
|
| 471 |
+
[0]crcstate : 0x8e3a
|
| 472 |
+
[0]crcfinal : 0xa14c
|
| 473 |
+
Correct operation validated. See README.md for run and reporting rules.
|
| 474 |
+
CoreMark 1.0 : 4.024469 / GCC15.1.0 -O3 -g -march=rv32ema_zba_zbb_zbc_zbkb_zbkx_zbs_zicsr_zifencei -mabi=ilp32e -mbranch-cost=1 -funroll-all-loops --param max-inline-insns-auto=200 -finline-limit=10000 -fno-code-hoisting -fno-if-conversion2 -falign-functions=4 -falign-jumps=4 -falign-loops=4 -DPERFORMANCE_RUN=1 / STACK
|
| 475 |
+
```
|
Wren6991_Hazard3/doc/.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
rev.adoc
|
| 2 |
+
*.pdf
|
| 3 |
+
*.html
|
Wren6991_Hazard3/doc/Makefile
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
TOP=hazard3
|
| 2 |
+
DEPS=$(shell find -name "*.adoc" | grep -v rev.adoc) diagrams/* *.yml
|
| 3 |
+
|
| 4 |
+
.PHONY: all clean view spell rev
|
| 5 |
+
|
| 6 |
+
all: spell $(TOP).pdf $(TOP).html
|
| 7 |
+
|
| 8 |
+
# `xdg-open` for Ubuntu and friends; `open` for MacOS
|
| 9 |
+
view: all
|
| 10 |
+
ifneq (,$(shell which xdg-open))
|
| 11 |
+
xdg-open $(TOP).pdf
|
| 12 |
+
else
|
| 13 |
+
open $(TOP).pdf
|
| 14 |
+
endif
|
| 15 |
+
|
| 16 |
+
clean:
|
| 17 |
+
rm -f $(TOP).pdf
|
| 18 |
+
|
| 19 |
+
spell:
|
| 20 |
+
ifeq (,$(shell which codespell))
|
| 21 |
+
@echo "Install codespell to check spelling"
|
| 22 |
+
else
|
| 23 |
+
@find -name "*.adoc" | xargs codespell -L hart
|
| 24 |
+
@echo "No spelling errors found"
|
| 25 |
+
endif
|
| 26 |
+
|
| 27 |
+
rev:
|
| 28 |
+
@echo ":revdate: Updated: `date +%Y-%b-%d`" > rev.adoc
|
| 29 |
+
|
| 30 |
+
$(TOP).pdf: $(DEPS) rev
|
| 31 |
+
asciidoctor-pdf -a compress $(TOP).adoc
|
| 32 |
+
|
| 33 |
+
# data-uri attribute: embed images etc in the HTML as base64. Fine as they are
|
| 34 |
+
# small, means the whole doc is one file.
|
| 35 |
+
$(TOP).html: $(DEPS) rev
|
| 36 |
+
asciidoctor --section-numbers -a HTMLBUILD $(TOP).adoc
|
Wren6991_Hazard3/doc/Readme.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Building
|
| 2 |
+
--------
|
| 3 |
+
|
| 4 |
+
## Ubuntu
|
| 5 |
+
|
| 6 |
+
```bash
|
| 7 |
+
# Get tools
|
| 8 |
+
sudo apt install ruby-asciidoctor-pdf codespell
|
| 9 |
+
# Build
|
| 10 |
+
make
|
| 11 |
+
```
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
## MacOS
|
| 15 |
+
|
| 16 |
+
```bash
|
| 17 |
+
brew install asciidoctor codespell
|
| 18 |
+
make
|
| 19 |
+
```
|
Wren6991_Hazard3/doc/diagrams/debug_topology.drawio
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
<mxfile host="app.diagrams.net" modified="2021-11-28T05:22:40.327Z" agent="5.0 (X11)" etag="nTSUjZuznzFSxSvFVrET" version="15.8.6" type="device"><diagram id="9fEN5FmfpFAiGjkGDVgf" name="Page-1">7Vpdc9o6EP01PKbjDzDkEUza9E47kymdSfOo2outW2ExsgjQX98VljG2HOqOcXBmkgcirVayfPborCQYuP5q90mQdfyVh8AGjhXuBu584Dhjb4yfyrDPDKOxNkSChpnJLgwL+hu00dLWDQ0hLTlKzpmk67Ix4EkCgSzZiBB8W3ZbclZ+6ppEYBgWAWGm9ZGGMs6sE2dc2O+BRnH+ZNu7zVpWJHfWb5LGJOTbE5N7N3B9wbnMSqudD0xhl+OS9fv4QutxYgIS2aRD8mMRfBPjL7PHe5lMp58f2dPkxtazfSZso99Yz1bucwgE3yQhqFGsgTvbxlTCYk0C1brFmKMtliuGNRuLIUnjg6+q6LFBSNi9OGv7iAVyCPgKpNijS95houHT/HFudX1bRMPNIY5PIuHmDCKaAdFx7AIkLGic/gUz741hZjfFzLa6wmxsQDZ9mBmoQYhrT1e5kDGPeELYXWGdlXEtfL5wvtYA/g9S7rWQkI3kZaxhR+UP1f3DSNeeTlrmOz3yobLPKwlCcNJJVZ9O24puh1reL5VEyKkSITQEjKQpDXLzR8pYKeLq3c/HG6HiGxHAOWpqhSQiAnnGz6nnjwBGJH0uz+PiXJgYXPjv+/RTf8hgnSXDlYLaIli66wOn+OSjSLjDirBW135GIt2rEvLjNFqoaI2IekwqOaTPWIxUcQ4/NxF6fRckSdcYYSzjFmOD4dfO+OwT/5ohctNPUbVUu7aR8AuotlPNdENTte061fa6Eu26PGfg63MBN+kaArrEhdA0KkgqEEuFZrNgvGeGliLiNMwMw7McvbE+eKOxfua/CRC+LdmfOKyVsKTN9Wk4rGxvK/5D56w/FrIZVHrn0+HLZQrdCJ3z9+3iK9C7v5Sz2ya4ViJXFx1Dru7JbyJCt7G85XnrfK7qWcJxr55w8iNbH4T//C7w7Qi/2074X2kRDo1V+Bmr0/sr7wSc5luBhpGFJMydEp5AZtHtVgeRv/i5wXERFuvkb1QSkVFVHDo+RjgjgznzPjBnfHHm9J8Zt71ihttFYlenncHhqNzPlG5VNsHetVO6Yx4i35W97fptm6tfOHH1a/065p3xu7JfhxnDUa+YYW4WL6fs9pu5L3S9vmm9bd7pLvaphBXavsHhesXyOZ6HOGMgrg5g9cao7vzrvSp+JrH9uX91nIyL6UlDojmdAVWTGvSNi8948Av/z/mK0MTADlGQ1XsxwX+BzxkXReZeojhXTITRKFEyDurqGg0KUxoQNtUNKxqGh1xTF5FyzC7+he9tJUL5qegvTHY72/VZRoAeBA8gTRHS9yBl4NvN5Ka7IJlfxB7lerZJr687lcPMqCbBHbWope5gtfglTrZPKX7O5N79AQ==</diagram></mxfile>
|
Wren6991_Hazard3/doc/diagrams/hazard3_backend.drawio
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
<mxfile modified="2021-11-04T15:44:57.753Z" host="app.diagrams.net" agent="5.0 (X11)" etag="1fTGXkcA6LinXzucZQNY" version="15.4.0" type="device"><diagram name="Page-1" id="7e0a89b8-554c-2b80-1dc8-d5c74ca68de4">7V1tc5s4EP41/liPxDsfEye5600zl0nmru19I0a2aW3jA9w49+tPYMSLJBtsgwTEnmljZJDxPvtIq93VMlInq91vgbNZPPouWo4U4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XpUrXH3wyd8NjkZQ4USGjiV1SsthUzj5B/vUj2fkuKP+Z37QxV+k1yjQ2b3smZPtGf27RWG3H+l0mQ+O3h3Ms7J4cNCe0ObgYAnw52wWoiGDwDpC2amFV9oJqm2BwNnRxRtvBgwBZ3ZvC4Lj2dXFB8w9jPIUwCc8fTc6AQjaFm0pdFKtykuyEeqq4WbV9tdSpZYBmlxL1ajz3O/eCNewy8LVzZaEiw8DP07Rzv1DWBqLR99F8Rn/Aw==</diagram></mxfile>
|
Wren6991_Hazard3/doc/diagrams/hazard3_logo_riscv_colors.svg
ADDED
|
|
Wren6991_Hazard3/doc/hazard3-theme.yml
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
extends: default-sans
|
| 2 |
+
title-page:
|
| 3 |
+
title:
|
| 4 |
+
top: 90%
|
| 5 |
+
logo:
|
| 6 |
+
image: image:diagrams/hazard3_logo_riscv_colors.svg[pdfwidth=80%]
|
| 7 |
+
align: center
|
| 8 |
+
top: 25%
|
| 9 |
+
|
| 10 |
+
codespan:
|
| 11 |
+
font-color: "#00509E"
|
Wren6991_Hazard3/doc/hazard3.adoc
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
:sectnums:
|
| 2 |
+
:toc:
|
| 3 |
+
:toclevels: 3
|
| 4 |
+
:doctype: book
|
| 5 |
+
:pdf-fontsdir: fonts
|
| 6 |
+
:pdf-theme: hazard3-theme.yml
|
| 7 |
+
ifdef::HTMLBUILD[]
|
| 8 |
+
:data-uri:
|
| 9 |
+
:toc: left
|
| 10 |
+
endif::[]
|
| 11 |
+
:times: ×
|
| 12 |
+
|
| 13 |
+
include::rev.adoc[]
|
| 14 |
+
|
| 15 |
+
ifdef::HTMLBUILD[]
|
| 16 |
+
= Hazard3: Design Guide and Reference Manual
|
| 17 |
+
endif::[]
|
| 18 |
+
|
| 19 |
+
ifndef::HTMLBUILD[]
|
| 20 |
+
= Design Guide and Reference Manual
|
| 21 |
+
endif::[]
|
| 22 |
+
|
| 23 |
+
include::sections/introduction.adoc[]
|
| 24 |
+
|
| 25 |
+
include::sections/configuration_and_integration.adoc[]
|
| 26 |
+
|
| 27 |
+
include::sections/bus_behaviour.adoc[]
|
| 28 |
+
|
| 29 |
+
include::sections/csr.adoc[]
|
| 30 |
+
|
| 31 |
+
include::sections/custom_extensions.adoc[]
|
| 32 |
+
|
| 33 |
+
[[debug-chapter]]
|
| 34 |
+
include::sections/debug.adoc[]
|
| 35 |
+
|
| 36 |
+
[appendix]
|
| 37 |
+
include::sections/instruction_timings.adoc[]
|
| 38 |
+
|
| 39 |
+
[appendix]
|
| 40 |
+
include::sections/release_notes.adoc[]
|
Wren6991_Hazard3/doc/sections/bus_behaviour.adoc
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
== Bus Behaviour
|
| 3 |
+
|
| 4 |
+
Hazard3 implements one or two AHB5 bus manager ports. <<port-descriptions-1port>> describes the signal-level implementation for a single-ported processor, and <<port-descriptions-2port>> for dual-ported. This section describes their behaviour at a higher level, and the requirements Hazard3 imposes on your bus subsystem.
|
| 5 |
+
|
| 6 |
+
=== Protocol
|
| 7 |
+
|
| 8 |
+
Hazard3 implements the AHB5 protocol, as described in the https://documentation-service.arm.com/static/5f91607cf86e16515cdc3b4b[AMBA 5 AHB protocol specification].
|
| 9 |
+
|
| 10 |
+
=== Single and Dual-port
|
| 11 |
+
|
| 12 |
+
In a dual-ported processor, loads and stores issue to the D port and instruction fetch issues to the I port. In a single-ported processor, all accesses issue to the single available port.
|
| 13 |
+
|
| 14 |
+
When the processor experiences internal contention, loads and stores take priority over instruction fetch. The rationale for this behaviour is that stalling a load or store will always increase the number of cycles required to execute a program, but stalling an instruction fetch has no cycle cost if the prefetch buffer is able to cover the gap.
|
| 15 |
+
|
| 16 |
+
For single-ported implementations it's highly recommended to enable compressed instruction support (<<param-EXTENSION_C>> = `1`). This reduces contention between instruction fetch and load/store, increasing performance.
|
| 17 |
+
|
| 18 |
+
=== Bursts
|
| 19 |
+
|
| 20 |
+
Hazard3 never generates bursts. `HTRANS` is always `IDLE` or `NSEQ`; `HBURST` is always `SINGLE`.
|
| 21 |
+
|
| 22 |
+
=== Alignment
|
| 23 |
+
|
| 24 |
+
All Hazard3 bus accesses are naturally aligned. That is, address modulo access size is always zero; `HADDR % (1 << HSIZE) == 0` (if `HTRANS` is not `IDLE`). Additionally, instruction fetch is always word-aligned and word-sized.
|
| 25 |
+
|
| 26 |
+
The Zilsd instructions `ld` and `sd` notionally perform 64-bit accesses, but Hazard3 issues these as pairs of 32-bit accesses over its 32-bit AHB bus. The alignment of each access is still four bytes.
|
| 27 |
+
|
| 28 |
+
[[section-memory-ordering]]
|
| 29 |
+
=== Memory Ordering for Loads and Stores
|
| 30 |
+
|
| 31 |
+
Hazard3 is sequentially consistent for loads and stores when it is connected to a sequentially consistent memory subsystem. Equivalently, if a load/store A is before another load/store B in program order, then A issues before B on the core's AHB5 load/store interface. Architecturally this is a (stronger) subset of the RVTSO memory model.
|
| 32 |
+
|
| 33 |
+
When executing a `fence` instruction, the core waits for all earlier loads and stores to complete before raising the `fence_d_vld` signal, then waits for `fence_rdy` before issuing more loads or stores. This has no effect on the order the core issues loads and stores to the bus, as they already unconditionally issue in program order. See <<memory-ordering-signals>> for more information about the core's external fence signals.
|
| 34 |
+
|
| 35 |
+
If a core A executes a `fence` and core B also executes a `fence` at a later time, the memory subsystem must perform any necessary synchronisation to ensure A's load/store accesses issued before A's fence are observed by B's load/store accesses issued after B's fence. Hazard3 does not distinguish different types of data fences: all fences should be treated as `fence rwio, rwio`.
|
| 36 |
+
|
| 37 |
+
The core is guaranteed not to issue any load or store accesses while `fence_d_vld` is asserted. For a two-ported implementation this is a good opportunity for system hardware to manipulate any logic such as cache controllers attached to the core's load/store port. No such guarantee is made for instruction fetch, so in a single-ported implementation you cannot assume based on `fence_d_vld` that the AHB5 port is idle.
|
| 38 |
+
|
| 39 |
+
=== Memory Ordering for Instruction Fetch
|
| 40 |
+
|
| 41 |
+
Hazard3 does not order stores before instruction fetch except with an explicit `fence.i` instruction. This instruction waits for in-progress stores to complete, asserts `fence_i_vld`, waits for `fence_rdy`, and then flushes the prefetch buffer to ensure the next instruction data to be executed is fetched after the instruction fence was observed by the system. It is up to the system designer to ensure that the instruction fetch AHB5 port observes earlier writes from the load/store AHB5 port; this may require flushing of external caches.
|
| 42 |
+
|
| 43 |
+
In system implementations which lack core-local caches it is usually sufficient to ignore the `fence_i_vld` and `fence_d_vld` signals, and tie `fence_rdy` high.
|
| 44 |
+
|
| 45 |
+
=== Cacheable and Bufferable Attributes
|
| 46 |
+
|
| 47 |
+
Hazard3 marks all transfers as non-cacheable and non-bufferable using `HPROT[3:2]`. These signals are tied off to constants and are not controllable by software.
|
| 48 |
+
|
| 49 |
+
All loads are issued to the external bus, even if they alias with a prior store; there is no store-to-load forwarding. All stores are issued to the external bus, even if they alias with a later store; there is no dead store elimination or write merging. Stores are issued immediately to the bus without buffering inside the core.
|
| 50 |
+
|
| 51 |
+
It is possible to use Hazard3 in systems with caches, but an alternative mechanism must be implemented to control cacheability of accesses. For example, implement multiple mirrors of the cached memory with attributes decoded from the address.
|
| 52 |
+
|
| 53 |
+
=== Idempotency
|
| 54 |
+
|
| 55 |
+
Hazard3 expects that all memory used for instruction fetch is read-idempotent. This limitation comes about because PMP execute permissions are checked at the point an instruction is _executed_, not the point it is fetched. This is a deliberate design decision that reduces the logic depth of fetch address generation logic. As a consequence it is possible to trigger reads from arbitrary addresses by jumping to them (though the data returned by that read is discarded if it lacks execute permissions).
|
| 56 |
+
|
| 57 |
+
You must not permit instruction fetch from IO regions if <<param-U_MODE>> is configured, because this would allow U-mode software to cause IO read side effects on privileged registers by (fatally) jumping to an IO address. This can be enforced in one of two ways:
|
| 58 |
+
|
| 59 |
+
* For a 2-port processor, do not connect instruction fetch to IO regions. This is already desirable to improve routing and logic complexity.
|
| 60 |
+
|
| 61 |
+
* For a 1-port processor, filter instruction fetch from IO regions by rejecting transfers if `HPROT[0]` is `0`.
|
| 62 |
+
|
| 63 |
+
This limitation does not apply to load/store; Hazard3 checks load/store addresses for PMP read/write permissions before issuing the transfer to the bus. However, idempotency is still a concern for instructions which generate multiple bus accesses, namely:
|
| 64 |
+
|
| 65 |
+
* Zcmp: `cm.push`, `cm.pop`, `cm.popret`, `cm.popretz`
|
| 66 |
+
* Zilsd: `ld`, `sd`
|
| 67 |
+
* Zclsd: `c.ld`, `c.ldsp`, `c.sd`, `c.sdsp`
|
| 68 |
+
|
| 69 |
+
An interrupt occurring mid-instruction terminates its execution immediately. When returning from the interrupt, the instruction restarts from the beginning, as there is no provision in RISC-V for saving and restoring the execution progress. Therefore each individual read or write may execute multiple times before the instruction eventually completes uninterrupted. This can cause lost or duplicated data when accessing IO regions. For this reason these instructions should be avoided when accessing non-idempotent memory.
|
| 70 |
+
|
| 71 |
+
=== 64-bit Accesses
|
| 72 |
+
|
| 73 |
+
Hazard3 implements the Zilsd and Zclsd extensions, which perform 64-bit loads and stores to and from pairs of registers. The register pair is always an even register plus the consecutively next higher-numbered register.
|
| 74 |
+
|
| 75 |
+
64-bit loads and stores are implemented as pairs of 32-bit AHB5 transfers. Since these accesses only require 4-byte alignment, the load/store address can also be 4-byte-aligned, even though it is notionally an 8-byte transfer.
|
| 76 |
+
|
| 77 |
+
The RISC-V specification does not guarantee the order in which these two writes are issued, and Hazard3 takes advantage of this to simplify fault handling. When the base address register `rs1` is an even-numbered register, the odd-numbered register in the `rd` or `rs2` pair is transferred first. Conversely, when `rs1` is an odd-numbered register, the even register in the pair is transferred first. This ensures that a fault occurring on the second half of an `ld` instruction does not modify `rs1`. It also means that a consecutively-addressed sequence of 64-bit load/stores is not necessarily consecutively addressed on the AHB5 port. When using `ld` and `sd` instructions for IO, ensure that the peripheral is not sensitive to the order of transfers.
|
Wren6991_Hazard3/doc/sections/configuration_and_integration.adoc
ADDED
|
@@ -0,0 +1,805 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
== Configuration and Integration
|
| 2 |
+
|
| 3 |
+
Hazard3 is a soft processor design distributed as HDL source files. To use it in your project you must:
|
| 4 |
+
|
| 5 |
+
* Download the source files from the public git repository.
|
| 6 |
+
* Configure your synthesis and simulation flows to read Hazard3 source files.
|
| 7 |
+
* Select the appropriate top-level module for your bus architecture (`hazard3_cpu_1port` or `hazard3_cpu_2port`).
|
| 8 |
+
* Select the appropriate configuration parameters for your use case.
|
| 9 |
+
* Instantiate the top-level module, and connect or tie-off _all_ ports.
|
| 10 |
+
* Instantiate any optional external components such as the Debug Module (`hazard3_dm`) and JTAG Debug Transport Module (`hazard3_jtag_dtm`).
|
| 11 |
+
|
| 12 |
+
The choice of configuration depends on your requirements for performance, code density, area, maximum frequency, level of memory protection, and number of system interrupts and interrupt priority levels. <<config-parameters-section>> documents the available configuration parameters.
|
| 13 |
+
|
| 14 |
+
The minimal https://github.com/Wren6991/Hazard3/blob/stable/example_soc/soc/example_soc.v[example SoC] shows a complete example of a single-ported Hazard3 core connected to SRAM, a UART, a RISC-V platform timer and external debug components.
|
| 15 |
+
|
| 16 |
+
=== Hazard3 Source Files
|
| 17 |
+
|
| 18 |
+
Hazard3's source is written in Verilog 2005, and is self-contained. It can be found here: https://github.com/Wren6991/Hazard3/tree/stable/hdl[github.com/Wren6991/Hazard3/blob/stable/hdl]. The file https://github.com/Wren6991/Hazard3/blob/stable/hdl/hazard3.f[hdl/hazard3.f] is a list of all the source files required to instantiate Hazard3. Hazard3 is distributed under the permissive Apache 2.0 licence; a full copy of the licence text is available in the git repository.
|
| 19 |
+
|
| 20 |
+
For more information on the Verilog 2005 language, refer to standard IEEE 1364-2005.
|
| 21 |
+
|
| 22 |
+
Files ending with `.vh` are preprocessor include files used by the Hazard3 source. The following two are particularly noteworthy:
|
| 23 |
+
|
| 24 |
+
* https://github.com/Wren6991/Hazard3/blob/stable/hdl/hazard3_config.vh[hazard3_config.vh]: the main Hazard3 configuration header. Lists and describes Hazard3's global configuration parameters, such as ISA extension support
|
| 25 |
+
* https://github.com/Wren6991/Hazard3/blob/stable/hdl/hazard3_config_inst.vh[hazard3_config_inst.vh]: a file which propagates configuration parameters through module instantiations, all the way down from Hazard3's top-level modules through the internals
|
| 26 |
+
|
| 27 |
+
There are two ways to configure Hazard3 using these two files:
|
| 28 |
+
|
| 29 |
+
* Directly edit the parameter defaults in `hazard3_config.vh` in your local Hazard3 checkout (and then let the top-level parameters default when instantiating Hazard3)
|
| 30 |
+
* Set all configuration parameters in your Hazard3 instantiation, and let the parameters propagate down through the hierarchy
|
| 31 |
+
|
| 32 |
+
The latter method is recommended for mature projects because it supports multiple distinct configurations of Hazard3 in the same system (for instance, a high-performance applications core and a low-area control-plane core). You may find the former method more convenient for quick hacking on the configuration.
|
| 33 |
+
|
| 34 |
+
[[top-level-modules]]
|
| 35 |
+
=== Top-level Modules
|
| 36 |
+
|
| 37 |
+
Hazard3 has two top-level modules:
|
| 38 |
+
|
| 39 |
+
* https://github.com/Wren6991/Hazard3/blob/stable/hdl/hazard3_cpu_1port.v[hazard3_cpu_1port]
|
| 40 |
+
* https://github.com/Wren6991/Hazard3/blob/stable/hdl/hazard3_cpu_2port.v[hazard3_cpu_2port]
|
| 41 |
+
|
| 42 |
+
These are both thin wrappers around the https://github.com/Wren6991/Hazard3/blob/stable/hdl/hazard3_core.v[hazard3_core] module. `hazard3_cpu_1port` has a single AHB5 bus port which is shared for instruction fetch, loads, stores and AMOs. `hazard3_cpu_2port` has two AHB5 bus ports, one for instruction fetch, and the other for loads, stores and AMOs. The 2-port wrapper has higher potential for performance, but the 1-port wrapper may be simpler to integrate, since there is no need to arbitrate multiple bus managers externally.
|
| 43 |
+
|
| 44 |
+
The core module `hazard3_core` can also be instantiated directly, which may be more efficient if support for some other bus standard is desired. However, the interface of `hazard3_core` will not be documented and is not guaranteed to be stable. By instantiating this module directly you are taking on the risk that future Hazard3 releases may be incompatible with your integration.
|
| 45 |
+
|
| 46 |
+
=== FPGA Synthesis
|
| 47 |
+
|
| 48 |
+
Hazard3 supports FPGA synthesis using tools such as Yosys and Vivado. You should set <<param-RESET_REGFILE>> to zero, as FPGA block RAMs and LUT RAMs often do not support reset, or are limited in the types of reset they support. Setting <<param-RESET_REGFILE>> to one is likely to result in the register file being implemented with logic fabric flops, which has a significant area and frequency impact.
|
| 49 |
+
|
| 50 |
+
You should synchronise the `rst_n` reset input externally. An example reset synchroniser is included in the example SoC file, but the details depend on your FPGA synthesis flow and your platform-level reset requirements.
|
| 51 |
+
|
| 52 |
+
It's recommended to tie `clk` and `clk_always_on` to the exact same clock net to conserve global buffer resources. Clock gating _is_ supported on FPGA, but you must consult your toolchain documentation for the correct primitives or inference techniques.
|
| 53 |
+
|
| 54 |
+
=== ASIC Synthesis
|
| 55 |
+
|
| 56 |
+
Hazard3 supports ASIC synthesis using common commercial tool flows. There are no particular requirements for configuration parameters, but your choice of configuration has an impact on area and frequency. Please raise an issue https://github.com/Wren6991/Hazard3/issues[here] if you find a compatibility issue with your tools.
|
| 57 |
+
|
| 58 |
+
When applying the `clk_en` clock enable signal to the `clk` input in conjunction with the Xh3power extension, you must instantiate an external clock gate cell appropriate to your platform (such as an AND-and-latch type). Do not use a behavioural AND gate to gate the clock.
|
| 59 |
+
|
| 60 |
+
You must synchronise resets externally according to your STA constraints and your system-level reset strategy. Hazard3 uses an asynchronous active-low reset internally, but this can be adapted to other types by inserting an appropriate synchroniser in your core integration.
|
| 61 |
+
|
| 62 |
+
==== Register File Macros
|
| 63 |
+
|
| 64 |
+
Generally the register file should be synthesised. Synthesised register files offer the best portability and the most flexibility during layout. However there may be an area advantage to implementing the register file using a hard layout macro.
|
| 65 |
+
|
| 66 |
+
Hazard3 supports the use of register file or SRAM macros, by modifying `hazard3_regfile_1w2r.v` to instantiate the appropriate macros. The configuration should be one of the following:
|
| 67 |
+
|
| 68 |
+
* One instance: two read ports, one write port
|
| 69 |
+
* Two instances: one read port, one write port, with the write ports tied together
|
| 70 |
+
|
| 71 |
+
The memory dimensions are:
|
| 72 |
+
|
| 73 |
+
* 32 bits wide
|
| 74 |
+
* 32 rows deep (RV32I) or 16 rows deep (RV32E) -- depends on configuration of <<param-EXTENSION_E>>
|
| 75 |
+
* No requirement for bit write enable
|
| 76 |
+
|
| 77 |
+
When a write and a read simultaneously occur at the same address, the write must succeed. The read data in this case is don't-care.
|
| 78 |
+
|
| 79 |
+
The read data from address 0 is don't-care, because the special case for register `x0` is handled in the register bypass logic. This means a full 32-row or 16-row RAM can be used.
|
| 80 |
+
|
| 81 |
+
[[port-descriptions]]
|
| 82 |
+
=== Interfaces (Top-level Ports)
|
| 83 |
+
|
| 84 |
+
Most ports are common to the two top-level wrappers, `hazard3_cpu_1port` and `hazard3_cpu_2port`. The only difference is the number of AHB5 manager ports used to access the bus: `hazard3_cpu_1port` has a single port used for all accesses, whereas `hazard3_cpu_2port` adds a separate, dedicated port for instruction fetch.
|
| 85 |
+
|
| 86 |
+
NOTE: Hazard3 adopts the convention that all signals are active-high, with the exception of the reset input `rst_n`.
|
| 87 |
+
|
| 88 |
+
[[interfaces-clock-and-reset]]
|
| 89 |
+
==== Clock and Reset Inputs
|
| 90 |
+
|
| 91 |
+
[options="header",cols="1,1,3,4"]
|
| 92 |
+
|===
|
| 93 |
+
| Width | In/Out | Name | Description
|
| 94 |
+
| 1 | In | `clk` | Clock for all processor logic not driven by `clk_always_on`. Must be the same as the AHB5 bus clock (`HCLK`). If the Xh3power extension is configured, you should instantiate an external clock gate on this clock, controlled by the `clk_en` output.
|
| 95 |
+
| 1 | In | `clk_always_on` | Clock for logic required to wake from a low-power state. Connect to the same clock as `clk`, but do not insert an external clock gate.
|
| 96 |
+
| 1 | In | `rst_n` | Active-low asynchronous reset for all processor logic. There is no internal synchroniser, so you must arrange externally for reset assertion/removal times to be met. For example, add an external reset synchroniser.
|
| 97 |
+
|
| 98 |
+
When <<param-RESET_REGFILE>> is one, this input also resets the register file. You should avoid resetting the register file on FPGA, as this can prevent the register file being implemented with block RAM or LUT RAM primitives.
|
| 99 |
+
|===
|
| 100 |
+
|
| 101 |
+
==== Power Control Signals
|
| 102 |
+
|
| 103 |
+
These signals are used in the implementation of internal sleep states as configured by the <<reg-h3.msleep>> csr. They are used only when the Xh3power extension is enabled.
|
| 104 |
+
|
| 105 |
+
[options="header",cols="1,1,3,4"]
|
| 106 |
+
|===
|
| 107 |
+
| Width | In/Out | Name | Description
|
| 108 |
+
| 1 | Out | `pwrup_req` | Power-up request. Disconnect if Xh3power is not configured. Part of a four-phase (Gray code) req/ack handshake for negotiating power or clocks with your system power controller. The processor releases `pwrup_req` on entering a sufficiently deep `wfi` or `h3.block` state, as configured by the `h3.msleep` CSR. It then waits for deassertion of `pwrup_ack` before taking further action.
|
| 109 |
+
|
| 110 |
+
The processor asserts `pwrup_req` when it intends to wake from its low-power state. It then waits for `pwrup_ack` before fetching the first instruction from the bus.
|
| 111 |
+
| 1 | In | `pwrup_ack` | Power-up acknowledged. Tie back to `pwrup_req` if Xh3power is not configured, or if there is no external system power controller. The processor does not access the bus when either `pwrup_req` or `pwrup_ack` is low.
|
| 112 |
+
| 1 | Out | `clk_en` | Control output for an external top-level clock gate on `clk`. Active-high enable. Hazard3 tolerates up to one cycle of delay between the assertion of `clk_en` and the resulting clock pulse on `clk`.
|
| 113 |
+
| 1 | Out | `unblock_out` | Pulses high when an `h3.unblock` instruction executes. Disconnect if Xh3power is not configured.
|
| 114 |
+
| 1 | In | `unblock_in` | A high input pulse will release a blocked `h3.block` instruction, or cause the next `h3.block` instruction to immediately fall through. Tie low if Xh3power is not configured.
|
| 115 |
+
|===
|
| 116 |
+
|
| 117 |
+
[[memory-ordering-signals]]
|
| 118 |
+
==== Memory Ordering Signals
|
| 119 |
+
|
| 120 |
+
Also see <<section-memory-ordering>> for more information on Hazard3's memory model.
|
| 121 |
+
|
| 122 |
+
[options="header",cols="1,1,3,4"]
|
| 123 |
+
|===
|
| 124 |
+
| Width | In/Out | Name | Description
|
| 125 |
+
| 1 | Out | `fence_i_vld` | Indicates the core is executing a `fence.i` instruction. Remains asserted until `fence_rdy` goes high. Never asserted at the same time as `fence_d_vld`.
|
| 126 |
+
|
| 127 |
+
The core waits for all in-progress bus accesses (load/store and instruction fetch) to complete before asserting this signal, and does not issue further instruction fetches for as long as this signal is asserted.
|
| 128 |
+
|
| 129 |
+
Once `fetch_rdy` is seen high, the core flushes its prefetch buffer to order the fetch of younger instructions against the fence. It then resumes normal execution.
|
| 130 |
+
|
| 131 |
+
| 1 | Out | `fence_d_vld` | Indicates the core is executing a non-instruction fence, such as `fence rw, rw`. Remains asserted until `fence_rdy` goes high. Never asserted at the same time as `fence_i_vld`.
|
| 132 |
+
|
| 133 |
+
The core waits for any in-progress load/store bus accesses to complete before asserting this signal, and does not issue further loads/stores for as long as this signal is asserted.
|
| 134 |
+
| 1 | In | `fence_rdy` | Signal to the core that the memory subsystem has finished processing the fence requested by `fence_i_vld` or `fence_d_vld`.
|
| 135 |
+
|
| 136 |
+
If no special handling of fences is required, tie this signal high.
|
| 137 |
+
|===
|
| 138 |
+
|
| 139 |
+
==== Debug Module Controls
|
| 140 |
+
|
| 141 |
+
All Debug Module signals should be connected to the signal with the matching name on the Hazard3 Debug Module implementation (https://github.com/Wren6991/Hazard3/blob/stable/hdl/debug/dm/hazard3_dm.v[hazard3_dm]).
|
| 142 |
+
|
| 143 |
+
[options="header",cols="1,1,3,4"]
|
| 144 |
+
|===
|
| 145 |
+
| Width | In/Out | Name | Description
|
| 146 |
+
| 1 | In | `dbg_req_halt` | Debugger halt request. Tie low if debug support is not configured.
|
| 147 |
+
| 1 | In | `dbg_req_halt_on_reset` | Debugger halt-on-reset request. Tie low if debug support is not configured.
|
| 148 |
+
| 1 | In | `dbg_req_resume` | Debugger resume request. Tie low if debug support is not configured.
|
| 149 |
+
| 1 | Out | `dbg_halted` | Debug halted status. Asserts when the processor is halted in Debug mode. Disconnect if debug support is not configured.
|
| 150 |
+
| 1 | Out | `dbg_running` | Debug halted status. Asserts when the processor is not halted and not transitioning between halted/running states. Disconnect if debug support is not configured.
|
| 151 |
+
| 32 | In | `dbg_data0_rdata` | Read data bus for mapping Debug Module `dmdata0` register as a CSR. Tie to zeroes if debug support is not configured.
|
| 152 |
+
| 32 | Out | `dbg_data0_wdata` | Write data bus for mapping Debug Module `dmdata0` register as a CSR. Disconnect if debug support is not configured.
|
| 153 |
+
| 1 | Out | `dbg_data0_wen` | Write data strobe for mapping Debug Module `dmdata0` register as a CSR. Disconnect if debug support is not configured.
|
| 154 |
+
| 32 | In | `dbg_instr_data` | Instruction injection interface. Tie to zeroes if debug support is not configured.
|
| 155 |
+
| 1 | In | `dbg_instr_data_vld` | Instruction injection interface. Tie low if debug support is not configured.
|
| 156 |
+
| 1 | Out | `dbg_instr_data_rdy` | Instruction injection interface. Disconnect if debug support is not configured.
|
| 157 |
+
| 1 | Out | `dbg_instr_caught_exception` | Exception caught during Program Buffer execution. Disconnect if debug support is not configured.
|
| 158 |
+
| 1 | Out | `dbg_instr_caught_ebreak` | Breakpoint instruction caught during Program Buffer execution. Disconnect if debug support is not configured.
|
| 159 |
+
|===
|
| 160 |
+
|
| 161 |
+
==== Shared System Bus Access
|
| 162 |
+
|
| 163 |
+
This subordinate bus port allows the standard System Bus Access (SBA) feature of the Debug Module to share bus access with the core. Alternatively, use the standalone https://github.com/Wren6991/Hazard3/blob/stable/hdl/debug/dm/hazard3_sbus_to_ahb.v[hazard3_sbus_to_ahb] adapter to provide dedicated SBA access from the Debug Module to the system bus.
|
| 164 |
+
|
| 165 |
+
[options="header",cols="1,1,3,4"]
|
| 166 |
+
|===
|
| 167 |
+
| Width | In/Out | Name | Description
|
| 168 |
+
| 32 | In | `dbg_sbus_addr` | Address for SBA arbitrated with this core's load/store access. Tie to zeroes if this feature is not used.
|
| 169 |
+
| 1 | In | `dbg_sbus_write` | Write/not-Read flag for SBA arbitrated with this core's load/store access. Tie low if this feature is not used.
|
| 170 |
+
| 2 | In | `dbg_sbus_size` | Transfer size (`0`/`1`/`2` = byte/halfword/word) for SBA arbitrated with this core's load/store access. Tie low if this feature is not used.
|
| 171 |
+
| 1 | In | `dbg_sbus_vld` | Transfer enable signal for SBA arbitrated with this core's load/store access. Tie low if this feature is not used.
|
| 172 |
+
| 1 | Out | `dbg_sbus_rdy` | Transfer stall signal for SBA arbitrated with this core's load/store access. Disconnect if this feature is not used.
|
| 173 |
+
| 1 | Out | `dbg_sbus_err` | Bus fault signal for SBA arbitrated with this core's load/store access. Disconnect if this feature is not used.
|
| 174 |
+
| 32 | In | `dbg_sbus_wdata` | Write data bus for SBA arbitrated with this core's load/store access. Tie to zeroes if this feature is not used.
|
| 175 |
+
| 32 | Out | `dbg_sbus_rdata` | Read data bus for SBA arbitrated with this core's load/store access. Disconnect if this feature is not used.
|
| 176 |
+
|===
|
| 177 |
+
|
| 178 |
+
==== Interrupt Requests
|
| 179 |
+
|
| 180 |
+
All interrupts are level-sensitive and synchronous to `clk`. Asynchronous interrupts must be synchronised externally before entering the processor. You must use the ungated version of `clk` (`clk_always_on`) for synchronisation if you use the interrupt to wake from sleep states.
|
| 181 |
+
|
| 182 |
+
Briefly asserting then deasserting an interrupt signal is not guaranteed to cause the processor to enter the relevant handler; the processor ignores interrupts it is not able to take at that time, for example when interrupts are disabled via `mstatus.mie`. There is also no guarantee that the processor will _not_ take such an interrupt. Peripherals and software should follow these guidelines for reliable interrupt handling:
|
| 183 |
+
|
| 184 |
+
* When an interrupt is asserted, it should remain asserted until the condition which caused the interrupt is cleared. For example, an RX FIFO valid interrupt should remain asserted until the processor pops data from the FIFO.
|
| 185 |
+
* Interrupt handlers should check the peripheral status at the top of the handler to see if it still requires servicing. If an interrupt is synchronised externally, it may still briefly be observed as asserted after returning from the handler, causing re-entry.
|
| 186 |
+
* To avoid the previous issue, interrupt handlers should acknowledge (clear) the peripheral interrupt as soon as possible in the handler, to ensure the interrupt is seen deasserted before the processor returns from the interrupt handler.
|
| 187 |
+
|
| 188 |
+
[options="header",cols="1,1,3,4"]
|
| 189 |
+
|===
|
| 190 |
+
| Width | In/Out | Name | Description
|
| 191 |
+
| `NUM_IRQS` | In | `irq` | If Xh3irq is not configured, this is the RISC-V external interrupt line (`mip.meip`) which you should connect to an external interrupt controller such as a standard RISC-V PLIC.
|
| 192 |
+
|
| 193 |
+
If Xh3irq is configured, this is a vector of level-sensitive active-high system interrupt requests, which the core's internal interrupt controller can route through the `mip.meip` vector. Tie low if unused.
|
| 194 |
+
| 1 | In | `soft_irq` | This is the standard RISC-V software interrupt signal, `mip.msip`. It should be connected to a register accessible to M-mode software on your system bus. Tie low if unused.
|
| 195 |
+
| 1 | In | `timer_irq` | This is the standard RISC-V timer interrupt signal, `mip.mtip`. It should be connected to a standard RISC-V platform timer peripheral (`mtime`/`mtimecmp`) accessible to M-mode software on your system bus. Tie low if unused.
|
| 196 |
+
|===
|
| 197 |
+
|
| 198 |
+
[[identification-signals]]
|
| 199 |
+
==== Identification Signals
|
| 200 |
+
|
| 201 |
+
[options="header",cols="1,1,3,4"]
|
| 202 |
+
|===
|
| 203 |
+
| Width | In/Out | Name | Description
|
| 204 |
+
| 32 | In | `mhartid_val` | Set the value of the <<reg-mhartid>> CSR, which software uses to determine on which hart it is running. Hazard3 implements one hart per core, so this is effectively a per-core identification value.
|
| 205 |
+
|
| 206 |
+
At least one hart must have the value of all-zeroes.
|
| 207 |
+
|
| 208 |
+
Generally you should tie this off to a unique constant value per core. Dynamic <<reg-mhartid>> is useful in scenarios such as dual-core lockstep: cores must execute identically when lockstep is engaged so their `mhartid_val` should be driven to the same value.
|
| 209 |
+
| 4 | In | `eco_version` | Set the value of the `eco` version number in <<reg-mimpid>>.
|
| 210 |
+
|
| 211 |
+
On ASIC this should be connected to metal-programmable tie cells so that it can be incremented with metal changes. The initial value should be all-zeroes. On FPGA this should be tied to all-zeroes.
|
| 212 |
+
|
| 213 |
+
|===
|
| 214 |
+
|
| 215 |
+
[[port-descriptions-1port]]
|
| 216 |
+
==== AHB5 Signals for 1-port CPU
|
| 217 |
+
|
| 218 |
+
This wrapper (`hazard3_cpu_1port`) adds a single standard AHB5 manager port. See the AMBA 5 AHB specification from Arm for definitions of these signals in the context of the bus protocol.
|
| 219 |
+
|
| 220 |
+
[options="header",cols="1,1,2,5"]
|
| 221 |
+
|===
|
| 222 |
+
| Width | In/Out | Name | Description
|
| 223 |
+
| 32 | Out | `haddr` | Address output. AHB is always byte-addressed. Hazard3 always issues naturally-aligned accesses.
|
| 224 |
+
| 1 | Out | `hwrite` | Driven high for a write transfer, low for a read transfer.
|
| 225 |
+
| 2 | Out | `htrans` | Driven to `0` (`IDLE`) to indicate no transfer in the current address phase, and `2` (`NSEQ`) to indicate there is a transfer. Other types are not used.
|
| 226 |
+
| 3 | Out | `hsize` | Driven to `0`, `1` or `2` to indicate byte, halfword or word sized transfers respectively. Other sizes are not used.
|
| 227 |
+
| 3 | Out | `hburst` | Tied off to `0` (`SINGLE`). Hazard3 does not issue bursts.
|
| 228 |
+
| 4 | Out | `hprot` | Bits `3:2` are always `0` to indicate nonbufferable and noncacheable access.
|
| 229 |
+
|
| 230 |
+
Bit `1` (privileged) is `0` for U-mode access, and `1` for M-mode and Debug-mode access.
|
| 231 |
+
|
| 232 |
+
Bit `0` is `0` for instruction fetch and `1` for data access (load/store or SBA).
|
| 233 |
+
| 1 | Out | `hmastlock` | Hazard3 does not use legacy bus locking, so this bit is tied to 0.
|
| 234 |
+
| 8 | Out | `hmaster` | 8-bit manager ID. A value of `0x00` indicates access from the core (including Debug mode access via the Program Buffer), and `0x01` indicates an SBA access.
|
| 235 |
+
|
| 236 |
+
Non-SBA Debug-mode load/store access can be detected by checking the `dbg_halted` status.
|
| 237 |
+
| 1 | Out | `hexcl` | Asserts high to indicate the current transfer is an Exclusive read/write as part of a read-modify-write sequence. This can be disconnected if you have not configured the A extension, or if you do not require global exclusive monitoring (for example in a single-core deployment).
|
| 238 |
+
| 1 | In | `hready` | Negative stall signal. Assert low to indicate the current data phase continues on the next cycle.
|
| 239 |
+
| 1 | In | `hresp` | Bus error signal. You _must_ generate the complete two-phase AHB `ERROR` response as per the AHB5 specification.
|
| 240 |
+
| 1 | In | `hexokay` | Exclusive transfer success. Hazard3 always queries the global monitor, so tie this input *high* if you do not implement global exclusive monitoring (for example in a single-core deployment). Similarly, ensure your global monitor returns a successful status for non-shared memory regions such as tightly-coupled memories.
|
| 241 |
+
| 32 | Out | `hwdata` | Write data bus. The LSB of the bus is always aligned to a 4-byte boundary. Hazard3 drives the correct byte lanes depending on the transfer size and bits `1:0` of the address. Remaining byte lanes have undefined contents.
|
| 242 |
+
| 32 | In | `hrdata` | Read data bus. The LSB of the bus is always aligned to a 4-byte boundary, so ensure you drive the correct byte lanes for narrow transfers.
|
| 243 |
+
|===
|
| 244 |
+
|
| 245 |
+
[[port-descriptions-2port]]
|
| 246 |
+
==== AHB5 Signals for 2-port CPU
|
| 247 |
+
|
| 248 |
+
This wrapper (`hazard3_cpu_2port`) adds two standard AHB5 manager ports, with signals prefixed `i_` for instruction and `d_` for data. See the AMBA 5 AHB specification from Arm for definitions of these signals in the context of the bus protocol.
|
| 249 |
+
|
| 250 |
+
The I port only generates word-aligned word-sized read accesses. It does not use AHB5 exclusives.
|
| 251 |
+
|
| 252 |
+
When shared System Bus Access (SBA) is used, the SBA bus accesses are routed through the D port.
|
| 253 |
+
|
| 254 |
+
[options="header",cols="1,1,2,5"]
|
| 255 |
+
|===
|
| 256 |
+
4+| **Port I (Instruction)**
|
| 257 |
+
| Width | In/Out | Name | Description
|
| 258 |
+
| 32 | Out | `i_haddr` | Address output. AHB is always byte-addressed. This port always issues word-aligned accesses (address bits `1:0` are zero).
|
| 259 |
+
| 1 | Out | `i_hwrite` | Always driven low to indicate a read transfer.
|
| 260 |
+
| 2 | Out | `i_htrans` | Driven to `0` (`IDLE`) to indicate no transfer in the current address phase, and `2` (`NSEQ`) to indicate there is a transfer. Other types are not used.
|
| 261 |
+
| 3 | Out | `i_hsize` | Always driven to `2` to indicate a word-sized transfer. Other sizes are not used.
|
| 262 |
+
| 3 | Out | `i_hburst` | Tied off to `0` (`SINGLE`). Hazard3 does not issue bursts.
|
| 263 |
+
| 4 | Out | `i_hprot` | Bits `3:2` are always `0` to indicate nonbufferable and noncacheable access.
|
| 264 |
+
|
| 265 |
+
Bit `1` (privileged) is `0` for U-mode access, and `1` for M-mode and Debug-mode access.
|
| 266 |
+
|
| 267 |
+
Bit `0` is tied to `0` to indicate instruction fetch.
|
| 268 |
+
| 1 | Out | `i_hmastlock` | Hazard3 does not use legacy bus locking, so this bit is tied to 0.
|
| 269 |
+
| 8 | Out | `i_hmaster` | 8-bit manager ID. Tied to `0x00`.
|
| 270 |
+
| 1 | In | `i_hready` | Negative stall signal. Assert low to indicate the current data phase continues on the next cycle.
|
| 271 |
+
| 1 | In | `i_hresp` | Bus error signal. You _must_ generate the complete two-phase AHB `ERROR` response as per the AHB5 specification.
|
| 272 |
+
| 32 | Out | `i_hwdata` | Write data bus. Tied to all-zeroes as this port is read-only.
|
| 273 |
+
| 32 | In | `i_hrdata` | Read data bus. Valid on cycles where `i_hready` is high during non-`IDLE` data phases.
|
| 274 |
+
4+| **Port D (Data)**
|
| 275 |
+
| 32 | Out | `d_haddr` | Address output. AHB is always byte-addressed. Hazard3 always issues naturally-aligned accesses.
|
| 276 |
+
| 1 | Out | `d_hwrite` | Driven high for a write transfer, low for a read transfer.
|
| 277 |
+
| 2 | Out | `d_htrans` | Driven to `0` (`IDLE`) to indicate no transfer in the current address phase, and `2` (`NSEQ`) to indicate there is a transfer. Other types are not used.
|
| 278 |
+
| 3 | Out | `d_hsize` | Driven to `0`, `1` or `2` to indicate byte, halfword or word sized transfers respectively. Other sizes are not used.
|
| 279 |
+
| 3 | Out | `d_hburst` | Tied off to `0` (`SINGLE`). Hazard3 does not issue bursts.
|
| 280 |
+
| 4 | Out | `d_hprot` | Bits `3:2` are always `0` to indicate nonbufferable and noncacheable access.
|
| 281 |
+
|
| 282 |
+
Bit `1` (privileged) is `0` for U-mode access, and `1` for M-mode access.
|
| 283 |
+
|
| 284 |
+
Bit `0` is tied to `1` to indicate data access (load/store or SBA).
|
| 285 |
+
| 1 | Out | `d_hmastlock` | Hazard3 does not use legacy bus locking, so this bit is tied to 0.
|
| 286 |
+
| 8 | Out | `d_hmaster` | 8-bit manager ID. A value of `0x00` indicates access from the core (including Debug-mode access via the Program Buffer), and `0x01` indicates an SBA access.
|
| 287 |
+
|
| 288 |
+
Non-SBA Debug-mode load/store access can be detected by checking the `dbg_halted` status.
|
| 289 |
+
| 1 | Out | `d_hexcl` | Asserts high to indicate the current transfer is an Exclusive read/write as part of a read-modify-write sequence. This can be disconnected if you have not configured the A extension, or if you do not require global exclusive monitoring (for example in a single-core deployment).
|
| 290 |
+
| 1 | In | `d_hready` | Negative stall signal. Assert low to indicate the current data phase continues on the next cycle.
|
| 291 |
+
| 1 | In | `d_hresp` | Bus error signal. You _must_ generate the complete two-phase AHB `ERROR` response as per the AHB5 specification.
|
| 292 |
+
| 1 | In | `d_hexokay` | Exclusive transfer success. Hazard3 always queries the global monitor, so tie this input _high_ if you do not implement global exclusive monitoring (for example in a single-core deployment). Similarly, ensure your global monitor returns a successful status for non-shared memory regions such as tightly-coupled memories.
|
| 293 |
+
| 32 | Out | `d_hwdata` | Write data bus. The LSB of the bus is always aligned to a 4-byte boundary. Hazard3 drives the correct byte lanes depending on the transfer size and bits `1:0` of the address. Remaining byte lanes have undefined contents.
|
| 294 |
+
| 32 | In | `d_hrdata` | Read data bus. The LSB of the bus is always aligned to a 4-byte boundary, so ensure you drive the correct byte lanes for narrow transfers.
|
| 295 |
+
|===
|
| 296 |
+
|
| 297 |
+
[[config-parameters-section]]
|
| 298 |
+
=== Configuration Parameters
|
| 299 |
+
|
| 300 |
+
==== Reset state configuration
|
| 301 |
+
|
| 302 |
+
[[param-RESET_VECTOR]]
|
| 303 |
+
===== RESET_VECTOR
|
| 304 |
+
|
| 305 |
+
Address of the first instruction executed after Hazard3 comes out of reset.
|
| 306 |
+
|
| 307 |
+
Default value: all-zeroes.
|
| 308 |
+
|
| 309 |
+
[[param-MTVEC_INIT]]
|
| 310 |
+
===== MTVEC_INIT
|
| 311 |
+
|
| 312 |
+
Initial value of the machine trap vector base CSR (<<reg-mtvec>>).
|
| 313 |
+
|
| 314 |
+
Bits clear in <<param-MTVEC_WMASK>> will never change from this initial value.
|
| 315 |
+
Bits set in <<param-MTVEC_WMASK>> can be written/set/cleared as normal.
|
| 316 |
+
|
| 317 |
+
Default value: all-zeroes.
|
| 318 |
+
|
| 319 |
+
==== Standard RISC-V ISA support
|
| 320 |
+
|
| 321 |
+
[[param-EXTENSION_A]]
|
| 322 |
+
===== EXTENSION_A
|
| 323 |
+
|
| 324 |
+
Support for the A extension: atomic read/modify/write. `0` for disable, `1` for enable.
|
| 325 |
+
|
| 326 |
+
Default value: `1`
|
| 327 |
+
|
| 328 |
+
[[param-EXTENSION_C]]
|
| 329 |
+
===== EXTENSION_C
|
| 330 |
+
|
| 331 |
+
Support for the C extension: compressed (variable-width). `0` for disable, `1` for enable.
|
| 332 |
+
|
| 333 |
+
C is equivalent here to the Zca extension, because Hazard3 does not implement F or D.
|
| 334 |
+
|
| 335 |
+
Hazard3 supports some other extensions which use 16-bit instructions: Zcmp (<<param-EXTENSION_ZCMP>>), Zcb (<<param-EXTENSION_ZCB>>) and Zclsd (<<param-EXTENSION_ZCLSD>>). You must set <<param-EXTENSION_C>> to enable basic compressed instruction support before enabling any of these other extensions.
|
| 336 |
+
|
| 337 |
+
Default value: `1`
|
| 338 |
+
|
| 339 |
+
[[param-EXTENSION_E]]
|
| 340 |
+
===== EXTENSION_E
|
| 341 |
+
|
| 342 |
+
Implement the RV32E base extension rather than RV32I. RV32E reduces the number of integer registers from 31 to 15. Set `1` to select RV32E, `0` to select RV32I.
|
| 343 |
+
|
| 344 |
+
Default value: `0`
|
| 345 |
+
|
| 346 |
+
[[param-EXTENSION_M]]
|
| 347 |
+
===== EXTENSION_M
|
| 348 |
+
|
| 349 |
+
Support for the M extension: hardware multiply/divide/modulo. `0` for disable, `1` for enable.
|
| 350 |
+
|
| 351 |
+
The exact circuit used to implement these instructions, and the resulting area and performance, depends on the following parameters: <<param-MULDIV_UNROLL>>, <<param-MUL_FAST>>, <<param-MUL_FASTER>>, and <<param-MULH_FAST>>.
|
| 352 |
+
|
| 353 |
+
Default value: `1`
|
| 354 |
+
|
| 355 |
+
[[param-EXTENSION_ZBA]]
|
| 356 |
+
===== EXTENSION_ZBA
|
| 357 |
+
|
| 358 |
+
Support for Zba address generation instructions. `0` for disable, `1` for enable.
|
| 359 |
+
|
| 360 |
+
Default value: `0`
|
| 361 |
+
|
| 362 |
+
[[param-EXTENSION_ZBB]]
|
| 363 |
+
===== EXTENSION_ZBB
|
| 364 |
+
|
| 365 |
+
Support for Zbb basic bit manipulation instructions. `0` for disable, `1` for enable.
|
| 366 |
+
|
| 367 |
+
Default value: `0`
|
| 368 |
+
|
| 369 |
+
[[param-EXTENSION_ZBC]]
|
| 370 |
+
===== EXTENSION_ZBC
|
| 371 |
+
|
| 372 |
+
Support for Zbc carry-less multiplication instructions. `0` for disable, `1` for enable.
|
| 373 |
+
|
| 374 |
+
Default value: `0`
|
| 375 |
+
|
| 376 |
+
[[param-EXTENSION_ZBKB]]
|
| 377 |
+
===== EXTENSION_ZBKB
|
| 378 |
+
|
| 379 |
+
Support for Zbkb basic bit manipulation for cryptography.
|
| 380 |
+
|
| 381 |
+
Requires: <<param-EXTENSION_ZBB>> = `1`.
|
| 382 |
+
|
| 383 |
+
NOTE: Since Zbb and Zbkb have a large overlap, this flag enables only those instructions which are in Zbkb but aren't in Zbb. Therefore both flags must be set for full Zbkb support.
|
| 384 |
+
|
| 385 |
+
Default value: `0`
|
| 386 |
+
|
| 387 |
+
[[param-EXTENSION_ZBKX]]
|
| 388 |
+
===== EXTENSION_ZBKX
|
| 389 |
+
|
| 390 |
+
Support for Zbkx crossbar permutation instructions. `0` for disable, `1` for enable.
|
| 391 |
+
|
| 392 |
+
Default value: `0`
|
| 393 |
+
|
| 394 |
+
|
| 395 |
+
[[param-EXTENSION_ZBS]]
|
| 396 |
+
===== EXTENSION_ZBS
|
| 397 |
+
|
| 398 |
+
Support for Zbs single-bit manipulation instructions. `0` for disable, `1` for enable.
|
| 399 |
+
|
| 400 |
+
Default value: `0`
|
| 401 |
+
|
| 402 |
+
[[param-EXTENSION_ZCB]]
|
| 403 |
+
===== EXTENSION_ZCB
|
| 404 |
+
|
| 405 |
+
Support for Zcb basic additional compressed instructions.
|
| 406 |
+
|
| 407 |
+
Requires: <<param-EXTENSION_C>> = `1`, <<param-EXTENSION_M>> = `1` and <<param-EXTENSION_ZBB>> = `1`.
|
| 408 |
+
|
| 409 |
+
NOTE: The RISC-V specifications state that Zcb depends on Zca; on Hazard3, Zca is synonymous with C, as the F and D extensions are not supported.
|
| 410 |
+
|
| 411 |
+
NOTE: Some of the 16-bit opcodes from Zcb are compressed aliases for 32-bit opcodes from M and Zbb, which is why those extensions must also be enabled.
|
| 412 |
+
|
| 413 |
+
Default value: `0`
|
| 414 |
+
|
| 415 |
+
|
| 416 |
+
[[param-EXTENSION_ZCLSD]]
|
| 417 |
+
===== EXTENSION_ZCLSD
|
| 418 |
+
|
| 419 |
+
Support for Zclsd compressed load/store pair instructions.
|
| 420 |
+
|
| 421 |
+
Requires: <<param-EXTENSION_ZILSD>> = `1` and <<param-EXTENSION_C>> = `1`.
|
| 422 |
+
|
| 423 |
+
Default value: `0`
|
| 424 |
+
|
| 425 |
+
[[param-EXTENSION_ZCMP]]
|
| 426 |
+
===== EXTENSION_ZCMP
|
| 427 |
+
Support for Zcmp push/pop and double-move instructions.
|
| 428 |
+
|
| 429 |
+
Requires: <<param-EXTENSION_C>> = `1`.
|
| 430 |
+
|
| 431 |
+
NOTE: The RISC-V specifications state that Zcmp depends on Zca; on Hazard3, Zca is synonymous with C, as the F and D extensions are not supported.
|
| 432 |
+
|
| 433 |
+
Default value: `0`
|
| 434 |
+
|
| 435 |
+
[[param-EXTENSION_ZIFENCEI]]
|
| 436 |
+
===== EXTENSION_ZIFENCEI
|
| 437 |
+
|
| 438 |
+
Support for the `fence.i` instruction. When the branch predictor is not present,
|
| 439 |
+
this instruction is optional, since a plain branch/jump is sufficient to
|
| 440 |
+
flush the instruction prefetch queue. When the branch predictor is enabled
|
| 441 |
+
(<<param-BRANCH_PREDICTOR>> = 1), this instruction must be implemented.
|
| 442 |
+
|
| 443 |
+
Default value: `0`
|
| 444 |
+
|
| 445 |
+
[[param-EXTENSION_ZILSD]]
|
| 446 |
+
===== EXTENSION_ZILSD
|
| 447 |
+
|
| 448 |
+
Support for Zilsd load/store pair instructions.
|
| 449 |
+
|
| 450 |
+
Hazard3 issues a 64-bit load or store instruction as two 32-bit memory accesses. Therefore this extension improves code density but does not directly improve performance.
|
| 451 |
+
|
| 452 |
+
Default value: `0`
|
| 453 |
+
|
| 454 |
+
[[cfg-custom-extensions]]
|
| 455 |
+
==== Custom Hazard3 Extensions
|
| 456 |
+
|
| 457 |
+
[[param-EXTENSION_XH3BEXTM]]
|
| 458 |
+
===== EXTENSION_XH3BEXTM
|
| 459 |
+
|
| 460 |
+
Custom bit manipulation instructions for Hazard3: `h3.bextm` and `h3.bextmi`. See <<extension-xh3bextm-section>>.
|
| 461 |
+
|
| 462 |
+
Default value: `0`
|
| 463 |
+
|
| 464 |
+
[[param-EXTENSION_XH3IRQ]]
|
| 465 |
+
===== EXTENSION_XH3IRQ
|
| 466 |
+
|
| 467 |
+
Custom preemptive, prioritised interrupt support. Can be disabled if an
|
| 468 |
+
external interrupt controller (e.g. PLIC) is used. If disabled, and
|
| 469 |
+
<<param-NUM_IRQS>> > `1`, the external interrupts are simply OR'd into
|
| 470 |
+
`mip.meip`. See <<extension-xh3irq-section>>.
|
| 471 |
+
|
| 472 |
+
Default value: `0`
|
| 473 |
+
|
| 474 |
+
[[param-EXTENSION_XH3PMPM]]
|
| 475 |
+
===== EXTENSION_XH3PMPM
|
| 476 |
+
|
| 477 |
+
Enable the custom PMPCFGMx CSRs, which can enforce PMP regions in M-mode
|
| 478 |
+
without locking the regions. See <<extension-xh3pmpm-section>>.
|
| 479 |
+
|
| 480 |
+
Default value: `0`
|
| 481 |
+
|
| 482 |
+
[[param-EXTENSION_XH3POWER]]
|
| 483 |
+
===== EXTENSION_XH3POWER
|
| 484 |
+
|
| 485 |
+
Custom power management controls for Hazard3. This adds the <<reg-h3.msleep>> CSR, and the `h3.block` and `h3.unblock` hint instructions. See <<extension-xh3power-section>>
|
| 486 |
+
|
| 487 |
+
Default value: `0`
|
| 488 |
+
|
| 489 |
+
==== CSR support
|
| 490 |
+
|
| 491 |
+
NOTE: the Zicsr extension is implied by any of <<param-CSR_M_MANDATORY>>, <<param-CSR_M_TRAP>>,
|
| 492 |
+
<<param-CSR_COUNTER>>.
|
| 493 |
+
|
| 494 |
+
[[param-CSR_M_MANDATORY]]
|
| 495 |
+
===== CSR_M_MANDATORY
|
| 496 |
+
|
| 497 |
+
Bare minimum CSR support e.g. <<reg-misa>>. This flag is an absolute
|
| 498 |
+
requirement for compliance with the RISC-V privileged specification. However,
|
| 499 |
+
the privileged specification itself is an optional extension. Hazard3 allows
|
| 500 |
+
the mandatory CSRs to be disabled to save a small amount of area in
|
| 501 |
+
deeply-embedded implementations.
|
| 502 |
+
|
| 503 |
+
Default value: `1`
|
| 504 |
+
|
| 505 |
+
[[param-CSR_M_TRAP]]
|
| 506 |
+
===== CSR_M_TRAP
|
| 507 |
+
|
| 508 |
+
Include M-mode trap-handling CSRs, and enable trap support.
|
| 509 |
+
|
| 510 |
+
Setting this parameter to `0` makes the core incapable of handling exceptions and interrupts. Instructions which would raise exceptions, such as illegal opcodes or unaligned load/store addresses, instead execute as NOPs.
|
| 511 |
+
|
| 512 |
+
Default value: `1`
|
| 513 |
+
|
| 514 |
+
[[param-CSR_COUNTER]]
|
| 515 |
+
===== CSR_COUNTER
|
| 516 |
+
|
| 517 |
+
Include the basic performance counters (`cycle`/`instret`) and relevant CSRs. Note that these performance counters are now in their own separate extension (Zicntr) and are no longer mandatory.
|
| 518 |
+
|
| 519 |
+
Default value: `0`
|
| 520 |
+
|
| 521 |
+
[[param-U_MODE]]
|
| 522 |
+
===== U_MODE
|
| 523 |
+
|
| 524 |
+
Support the U (user) privilege level. In U-mode, the core performs unprivileged
|
| 525 |
+
bus accesses, and software's access to CSRs is restricted. Additionally, if
|
| 526 |
+
the PMP is included, the core may restrict U-mode software's access to
|
| 527 |
+
memory.
|
| 528 |
+
|
| 529 |
+
Requires: <<param-CSR_M_TRAP>> = `1`.
|
| 530 |
+
|
| 531 |
+
Default value: `0`
|
| 532 |
+
|
| 533 |
+
[[param-PMP_REGIONS]]
|
| 534 |
+
===== PMP_REGIONS
|
| 535 |
+
|
| 536 |
+
Number of physical memory protection regions, or 0 for no PMP. PMP is more
|
| 537 |
+
useful if U-mode is supported, but this is not a requirement.
|
| 538 |
+
|
| 539 |
+
Hazard3 implements all PMP registers `pmpaddr0` through `pmpaddr15` and `pmpcfg0` through `pmpcfg3` if <<param-PMP_REGIONS>> is greater than zero. They are implemented in the sense that software can read and write them without trapping. However, configuration bits for regions <<param-PMP_REGIONS>> through 15 are hardwired to zero.
|
| 540 |
+
|
| 541 |
+
Requires: <<param-CSR_M_TRAP>> = `1`.
|
| 542 |
+
|
| 543 |
+
Default value: `0`
|
| 544 |
+
|
| 545 |
+
[[param-PMP_GRAIN]]
|
| 546 |
+
===== PMP_GRAIN
|
| 547 |
+
|
| 548 |
+
This is the _G_ parameter in the privileged spec, which defines the
|
| 549 |
+
granularity of PMP regions. Minimum PMP region size is 1 << (_G_ + 2) bytes. For example, _G_ = `3` means 32-byte protection granularity.
|
| 550 |
+
|
| 551 |
+
If _G_ > 0, `pmcfg.a` cannot be set to NA4; attempting to do so will set the region to OFF instead. The _G_ LSBs of each `pmpaddr` register read back as all-zeroes when `pmpcfg.a` is set to TOR or OFF.
|
| 552 |
+
|
| 553 |
+
If _G_ > 1, the _G_ - 1 LSBs of pmpaddr are read-only-1 when `pmpcfg.a` is
|
| 554 |
+
NAPOT.
|
| 555 |
+
|
| 556 |
+
Increasing <<param-PMP_GRAIN>> from its default value reduces the area and
|
| 557 |
+
delay cost associated with the PMP unit.
|
| 558 |
+
|
| 559 |
+
Default value: `0`
|
| 560 |
+
|
| 561 |
+
[[param-PMP_MATCH_NAPOT]]
|
| 562 |
+
===== PMP_MATCH_NAPOT
|
| 563 |
+
|
| 564 |
+
PMP_MATCH_NAPOT: Enable PMP support for the NAPOT (naturally-aligned
|
| 565 |
+
power-of-two) and NA4 (naturally-aligned four-byte) matching modes. When
|
| 566 |
+
disabled, attempting to select these modes will set the PMP region to OFF.
|
| 567 |
+
|
| 568 |
+
Default value: `1`
|
| 569 |
+
|
| 570 |
+
[[param-PMP_MATCH_TOR]]
|
| 571 |
+
===== PMP_MATCH_TOR
|
| 572 |
+
|
| 573 |
+
PMP_MATCH_TOR: Enable PMP support for the TOR (top-of-range) matching mode.
|
| 574 |
+
When disabled, attempting to select this mode will set the region to OFF.
|
| 575 |
+
|
| 576 |
+
Note that NA4 and NAPOT use a separate comparator circuit from TOR
|
| 577 |
+
comparisons. Setting both <<param-PMP_MATCH_NAPOT>> and
|
| 578 |
+
<<param-PMP_MATCH_TOR>> incurs the area cost of both circuits. For best area
|
| 579 |
+
efficiency, select the best single comparator type for your application,
|
| 580 |
+
noting that TOR covers all the possibilities of NAPOT if there are no gaps
|
| 581 |
+
between the regions. Also consider whether <<param-PMP_GRAIN>> can be
|
| 582 |
+
increased from its default value.
|
| 583 |
+
|
| 584 |
+
Default value: `0`
|
| 585 |
+
|
| 586 |
+
[[param-PMP_HARDWIRED]]
|
| 587 |
+
===== PMP_HARDWIRED
|
| 588 |
+
|
| 589 |
+
If a bit is 1, the corresponding region's `pmpaddr` and `pmpcfg` registers are read-only, with their values fixed when the processor is instantiated. PMP_GRAIN is ignored on hardwired regions.
|
| 590 |
+
|
| 591 |
+
Hardwired regions are far cheaper, both in area and comparison delay, than dynamically configurable regions.
|
| 592 |
+
|
| 593 |
+
Hardwired PMP regions are a good option for setting default U-mode permissions on regions which have access controls outside of the processor, such as peripheral regions. For this case it's recommended to make hardwired regions the highest-numbered, so they can be overridden by lower-numbered dynamic
|
| 594 |
+
regions.
|
| 595 |
+
|
| 596 |
+
Default value: all-zeroes.
|
| 597 |
+
|
| 598 |
+
[[param-PMP_HARDWIRED_ADDR]]
|
| 599 |
+
===== PMP_HARDWIRED_ADDR
|
| 600 |
+
|
| 601 |
+
Values of `pmpaddr` registers whose <<param-PMP_HARDWIRED>> bits are set to `1`. Has no effect on PMP regions which are not hardwired.
|
| 602 |
+
|
| 603 |
+
Default value: all-zeroes.
|
| 604 |
+
|
| 605 |
+
[[param-PMP_HARDWIRED_CFG]]
|
| 606 |
+
===== PMP_HARDWIRED_CFG
|
| 607 |
+
|
| 608 |
+
Values of `pmpcfg` registers whose <<param-PMP_HARDWIRED>> bits are set to `1`. Has no effect on PMP regions which are not hardwired.
|
| 609 |
+
|
| 610 |
+
Default value: all-zeroes.
|
| 611 |
+
|
| 612 |
+
[[param-DEBUG_SUPPORT]]
|
| 613 |
+
===== DEBUG_SUPPORT
|
| 614 |
+
|
| 615 |
+
Enable the following hardware functionality:
|
| 616 |
+
|
| 617 |
+
* Support for run/halt and instruction injection from an external Debug Module,
|
| 618 |
+
* Support for Debug Mode
|
| 619 |
+
* Debug Mode CSRs
|
| 620 |
+
* A minimal Trigger Module with an exception trigger, an interrupt trigger and an instruction count trigger (see <<section-trigger-module>>)
|
| 621 |
+
|
| 622 |
+
If the Hazard3 Debug Module is also instantiated and correctly connected to
|
| 623 |
+
the core, this is sufficient for debugging the core from any RISC-V-compliant
|
| 624 |
+
debug host.
|
| 625 |
+
|
| 626 |
+
Consider also enabling hardware breakpoints using
|
| 627 |
+
<<param-BREAKPOINT_TRIGGERS>> if debugging code in read-only memory is an
|
| 628 |
+
anticipated use case.
|
| 629 |
+
|
| 630 |
+
Requires: <<param-CSR_M_MANDATORY>> = `1` and <<param-CSR_M_TRAP>> = `1`.
|
| 631 |
+
|
| 632 |
+
Default value: `0`
|
| 633 |
+
|
| 634 |
+
[[param-BREAKPOINT_TRIGGERS]]
|
| 635 |
+
===== BREAKPOINT_TRIGGERS
|
| 636 |
+
|
| 637 |
+
Number of hardware breakpoints. A breakpoint is implemented as a trigger that
|
| 638 |
+
supports only exact execution address matches, ignoring instruction size.
|
| 639 |
+
That is, a trigger which supports type=2 execute=1 (but not store/load=1,
|
| 640 |
+
i.e. not a watchpoint).
|
| 641 |
+
|
| 642 |
+
Requires: <<param-DEBUG_SUPPORT>> = `1`.
|
| 643 |
+
|
| 644 |
+
Default value: `0`
|
| 645 |
+
|
| 646 |
+
==== External interrupt support
|
| 647 |
+
|
| 648 |
+
[[param-NUM_IRQS]]
|
| 649 |
+
===== NUM_IRQS
|
| 650 |
+
|
| 651 |
+
Number of external IRQs. Minimum 1, maximum 512. Note that if
|
| 652 |
+
<<param-EXTENSION_XH3IRQ>> = `0`, the internal interrupt controller is not
|
| 653 |
+
present. In this case multiple external interrupts are simply OR'd into
|
| 654 |
+
`mip.meip`.
|
| 655 |
+
|
| 656 |
+
Default value: `1`
|
| 657 |
+
|
| 658 |
+
[[param-IRQ_PRIORITY_BITS]]
|
| 659 |
+
===== IRQ_PRIORITY_BITS
|
| 660 |
+
|
| 661 |
+
IRQ_PRIORITY_BITS: Number of priority bits implemented for each interrupt in
|
| 662 |
+
the internal interrupt controller described in <<extension-xh3irq-section>>.
|
| 663 |
+
The <<reg-h3.meipra>> array CSR configures the individual priorities.
|
| 664 |
+
|
| 665 |
+
The number of distinct levels is `(1 << IRQ_PRIORITY_BITS)`. The minimum value
|
| 666 |
+
is `0` (1 level), and the maximum value is `4` (16 levels). Note that
|
| 667 |
+
multiple priority levels with a large number of IRQs will have a severe effect
|
| 668 |
+
on timing.
|
| 669 |
+
|
| 670 |
+
Requires: <<param-EXTENSION_XH3IRQ>> = `1`.
|
| 671 |
+
|
| 672 |
+
Default value: `0`
|
| 673 |
+
|
| 674 |
+
[[param-IRQ_INPUT_BYPASS]]
|
| 675 |
+
===== IRQ_INPUT_BYPASS
|
| 676 |
+
|
| 677 |
+
Disable the input registers on the external interrupts, to reduce latency by one cycle. Can be applied on an IRQ-by-IRQ basis. Use this when the interrupt already comes straight from a register, e.g. when you have synchronised an interrupt to the processor clock from an asynchronous source; the additional register inside the processor is redundant in this case.
|
| 678 |
+
|
| 679 |
+
Ignored if <<param-EXTENSION_XH3IRQ>> = `0`. In this case, when the internal interrupt controller is not present, all external IRQ inputs are OR'd together before being registered in a single flip-flop.
|
| 680 |
+
|
| 681 |
+
Default value: all-zeroes (not bypassed).
|
| 682 |
+
|
| 683 |
+
==== Identification Registers
|
| 684 |
+
|
| 685 |
+
[[param-MVENDORID_VAL]]
|
| 686 |
+
===== MVENDORID_VAL
|
| 687 |
+
|
| 688 |
+
Value of the <<reg-mvendorid>> CSR. Should be either a JEDEC JEP-106-compliant vendor ID, or
|
| 689 |
+
all-zeroes.
|
| 690 |
+
|
| 691 |
+
Bits `31:7` store the continuation code count, and bits `6:0` are the ID. The
|
| 692 |
+
parity bit is not stored.
|
| 693 |
+
|
| 694 |
+
[IMPORTANT]
|
| 695 |
+
====
|
| 696 |
+
The number of continuation codes is _one less than_ the JEP106 bank number.
|
| 697 |
+
|
| 698 |
+
For example, Raspberry Pi has an ID of `0x13` (19 decimal) in bank 10 (decimal). This has a continuation code count of 9, yielding an `mvendorid` of `0x00000493`.
|
| 699 |
+
====
|
| 700 |
+
|
| 701 |
+
Requires: <<param-CSR_M_MANDATORY>> = `1`.
|
| 702 |
+
|
| 703 |
+
Default value: all-zeroes.
|
| 704 |
+
|
| 705 |
+
[[param-MCONFIGPTR_VAL]]
|
| 706 |
+
===== MCONFIGPTR_VAL
|
| 707 |
+
|
| 708 |
+
Value of the <<reg-mconfigptr>> CSR. Pointer to configuration structure blob,
|
| 709 |
+
or all-zeroes. Must be at least 4-byte-aligned.
|
| 710 |
+
|
| 711 |
+
Requires: <<param-CSR_M_MANDATORY>> = `1`.
|
| 712 |
+
|
| 713 |
+
Default value: all-zeroes.
|
| 714 |
+
|
| 715 |
+
==== Performance/size options
|
| 716 |
+
|
| 717 |
+
[[param-REDUCED_BYPASS]]
|
| 718 |
+
===== REDUCED_BYPASS
|
| 719 |
+
|
| 720 |
+
Remove all forwarding paths except X->X (so back-to-back ALU ops can still run
|
| 721 |
+
at 1 CPI), to save area. This has a significant impact on per-clock
|
| 722 |
+
performance, so should only be considered for extremely low-area
|
| 723 |
+
implementations.
|
| 724 |
+
|
| 725 |
+
Default value: `0`
|
| 726 |
+
|
| 727 |
+
[[param-MULDIV_UNROLL]]
|
| 728 |
+
===== MULDIV_UNROLL
|
| 729 |
+
|
| 730 |
+
Configure bits-per-clock for the sequential multiply/divide circuit, if present. Must be a power of 2.
|
| 731 |
+
|
| 732 |
+
Default value: `1`
|
| 733 |
+
|
| 734 |
+
[[param-MUL_FAST]]
|
| 735 |
+
===== MUL_FAST
|
| 736 |
+
|
| 737 |
+
Use a single-cycle multiply circuit for `MUL` instructions, retiring to stage 3 by default (one throughput cycle, two latency cycles).
|
| 738 |
+
|
| 739 |
+
The sequential multiply/divide circuit is still used for `mulh`, `mulhu` and `mulhsu`.
|
| 740 |
+
|
| 741 |
+
Default value: `0`
|
| 742 |
+
|
| 743 |
+
[[param-MUL_FASTER]]
|
| 744 |
+
===== MUL_FASTER
|
| 745 |
+
|
| 746 |
+
Retire fast multiply results to stage 2 instead of stage 3.
|
| 747 |
+
The throughput is the same, but latency is reduced from 2 cycles to 1 cycle.
|
| 748 |
+
|
| 749 |
+
Requires: <<param-MUL_FAST>> = `1`.
|
| 750 |
+
|
| 751 |
+
Default value: `0`
|
| 752 |
+
|
| 753 |
+
[[param-MULH_FAST]]
|
| 754 |
+
===== MULH_FAST
|
| 755 |
+
|
| 756 |
+
Extend the fast multiply circuit to also cover `mulh`, `mulhu` and `mulhsu`. Removethe multiply functionality from the sequential multiply/divide circuit.
|
| 757 |
+
|
| 758 |
+
Requires: <<param-MUL_FAST>> = `1`.
|
| 759 |
+
|
| 760 |
+
Default value: `0`
|
| 761 |
+
|
| 762 |
+
[[param-FAST_BRANCHCMP]]
|
| 763 |
+
===== FAST_BRANCHCMP
|
| 764 |
+
|
| 765 |
+
Instantiate a separate comparator (equal, less-than-signed, less-than-unsigned) for branch comparisons, rather
|
| 766 |
+
than using the ALU. Enabling the separate comparator improves the address-phase timing for instruction fetch, especially if the `Zba`
|
| 767 |
+
extension is enabled (<<param-EXTENSION_ZBA>>). Disabling may save area.
|
| 768 |
+
|
| 769 |
+
Default value: `1`
|
| 770 |
+
|
| 771 |
+
[[param-RESET_REGFILE]]
|
| 772 |
+
===== RESET_REGFILE
|
| 773 |
+
|
| 774 |
+
If `1`, the `rst_n` input resets all general purpose registers to all-zeroes. If `0`, it does not. There are around 1k
|
| 775 |
+
bits in the register file, so the reset can be disabled to permit
|
| 776 |
+
block RAM and LUT RAM inference on FPGA, or to reduce flop area on ASIC.
|
| 777 |
+
|
| 778 |
+
Outside of the register file, all other flops in Hazard3 are always reset by the `rst_n` input, no matter the value of this parameter.
|
| 779 |
+
|
| 780 |
+
Default value: `1`
|
| 781 |
+
|
| 782 |
+
[[param-BRANCH_PREDICTOR]]
|
| 783 |
+
===== BRANCH_PREDICTOR
|
| 784 |
+
|
| 785 |
+
Enable branch prediction. The branch predictor consists of a single BTB entry which is allocated on a taken backward branch, and cleared on a mispredicted non-taken branch, a `fence.i` or a trap.
|
| 786 |
+
|
| 787 |
+
Successful prediction eliminates the 1-cyle fetch bubble on a taken branch, so tight loops execute faster. See <<instruction-timings-branch-predictor>> for more information on this feature.
|
| 788 |
+
|
| 789 |
+
Requires: <<param-EXTENSION_ZIFENCEI>> = `1`.
|
| 790 |
+
|
| 791 |
+
Default value: `0`
|
| 792 |
+
|
| 793 |
+
[[param-MTVEC_WMASK]]
|
| 794 |
+
===== MTVEC_WMASK
|
| 795 |
+
|
| 796 |
+
MTVEC_WMASK: Mask of which bits in mtvec are writable. Full writability (except for bit 1) is
|
| 797 |
+
recommended, because a common idiom in setup code is to set mtvec just
|
| 798 |
+
past code that may trap, as a hardware `try {...} catch` block.
|
| 799 |
+
|
| 800 |
+
|
| 801 |
+
The vectoring mode, in bits `1:0`, can be made fixed by clearing the LSB of `MTVEC_WMASK`.
|
| 802 |
+
|
| 803 |
+
In vectored mode, the vector table must be aligned to its size, rounded up to a power of two. If all four standard M-mode vectors (exception, `msip`, `mtip` and `meip`) are in use, this means 64-byte alignment.
|
| 804 |
+
|
| 805 |
+
Default: All writable except for bit `1`.
|
Wren6991_Hazard3/doc/sections/csr.adoc
ADDED
|
@@ -0,0 +1,1009 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
== CSRs
|
| 2 |
+
|
| 3 |
+
The RISC-V privileged specification affords flexibility as to which CSRs are implemented, and how they behave. This section documents the concrete behaviour of Hazard3's standard and nonstandard M-mode CSRs, as implemented.
|
| 4 |
+
|
| 5 |
+
All CSRs are 32-bit; MXLEN is fixed at 32 bits on Hazard3. All CSR addresses not listed in this section are unimplemented. Accessing an unimplemented CSR will cause an illegal instruction exception (`mcause` = 2). This includes all U-mode and S-mode CSRs.
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
IMPORTANT: The https://github.com/riscv/riscv-isa-manual/releases/download/Priv-v1.12/riscv-privileged-20211203.pdf[RISC-V Privileged Specification] should be your primary reference for writing software to run on Hazard3. This section specifies those details which are left implementation-defined by the RISC-V Privileged Specification, for sake of completeness, but portable RISC-V software should not rely on these details.
|
| 9 |
+
|
| 10 |
+
=== Standard M-mode Identification CSRs
|
| 11 |
+
|
| 12 |
+
[[reg-mvendorid]]
|
| 13 |
+
==== mvendorid
|
| 14 |
+
|
| 15 |
+
Address: `0xf11`
|
| 16 |
+
|
| 17 |
+
Vendor identifier. Read-only, configurable constant. Should contain either all-zeroes, or a valid JEDEC JEP106 vendor ID using the encoding in the RISC-V specification. The <<param-MVENDORID_VAL>> parameter sets the value.
|
| 18 |
+
|
| 19 |
+
[cols="10h,20h,~", options="header"]
|
| 20 |
+
|===
|
| 21 |
+
| Bits | Name | Description
|
| 22 |
+
| 31:7 | `bank` | The number of continuation codes in the vendor JEP106 ID. _One less than the JEP106 bank number._
|
| 23 |
+
| 6:0 | `offset` | Vendor ID within the specified bank. LSB (parity) is not stored.
|
| 24 |
+
|===
|
| 25 |
+
|
| 26 |
+
==== marchid
|
| 27 |
+
|
| 28 |
+
Address: `0xf12`
|
| 29 |
+
|
| 30 |
+
Architecture identifier for Hazard3. Read-only, constant.
|
| 31 |
+
|
| 32 |
+
[cols="10h,20h,~", options="header"]
|
| 33 |
+
|===
|
| 34 |
+
| Bits | Name | Description
|
| 35 |
+
| 31 | - | 0: Open-source implementation
|
| 36 |
+
| 30:0 | - | 0x1b (decimal 27): the https://github.com/riscv/riscv-isa-manual/blob/master/marchid.md[registered] architecture ID for Hazard3
|
| 37 |
+
|===
|
| 38 |
+
|
| 39 |
+
[[reg-mimpid]]
|
| 40 |
+
==== mimpid
|
| 41 |
+
|
| 42 |
+
Address: `0xf13`
|
| 43 |
+
|
| 44 |
+
Implementation identifier. Most of this register is hardwired to indicate the release version of the Hazard3 RTL.
|
| 45 |
+
|
| 46 |
+
[cols="10h,20h,~", options="header"]
|
| 47 |
+
|===
|
| 48 |
+
| Bits | Name | Description
|
| 49 |
+
| 31 | `prerelease` | Value of 1 indicates this Hazard3 instance was synthesised from RTL not yet released to the `stable` branch.
|
| 50 |
+
| 30:28 | - | RES0
|
| 51 |
+
| 27:24 | `major` | Major release version, i.e. the `1` in `v1.2.3`
|
| 52 |
+
| 23:16 | `minor` | Minor release version, i.e. the `2` in `v1.2.3`
|
| 53 |
+
| 15:8 | `patch` | Patch version, i.e. the `3` in `v1.2.3`
|
| 54 |
+
| 7:4 | `eco` | Connected to external signals, initially zero
|
| 55 |
+
| 3:0 | - | RES0
|
| 56 |
+
|===
|
| 57 |
+
|
| 58 |
+
This should match the version of the Github release of the processor's source code. For example, version https://github.com/Wren6991/Hazard3/releases/tag/v1.0.2[1.0.2] would have a `major` of 1, `minor` of 0 and `patch` of 2.
|
| 59 |
+
|
| 60 |
+
`eco` is connected to the `eco_version` input port at Hazard3 top level; the implementer may connect this to metal tie cells in their integration so that they can increment the ECO (engineering change order) number with metal revisions that affect the processor, or may simply tie it to 0. See <<identification-signals>>.
|
| 61 |
+
|
| 62 |
+
NOTE: Versions of Hazard3 older than v1.1 allowed the implementer to set the `mimpid` contents arbitrarily, with a recommendation to set it to the git hash. The hashes of released versions are: `86fc4e3f` (RP2350, v1.0-rc1), `918aaee10` (v1.0), `82729101` (v1.0.1) and `787da131a` (v1.0.2).
|
| 63 |
+
|
| 64 |
+
[[reg-mhartid]]
|
| 65 |
+
==== mhartid
|
| 66 |
+
|
| 67 |
+
Address: `0xf14`
|
| 68 |
+
|
| 69 |
+
Hart identification register. Read-only.
|
| 70 |
+
|
| 71 |
+
The value of this register is configured by the `mhartid_val` input port (see <<identification-signals>>). In a correctly configured system, the value of `mhartid` is unique on each hart, and one hart has an ID of all-zeroes. There is no strict requirement to assign hart IDs consecutively, but there may be performance or memory usage advantages to doing so on certain operating systems.
|
| 72 |
+
|
| 73 |
+
[cols="10h,20h,~", options="header"]
|
| 74 |
+
|===
|
| 75 |
+
| Bits | Name | Description
|
| 76 |
+
| 31:0 | - | Hazard3 cores possess only one hardware thread, so this is a unique per-core identifier.
|
| 77 |
+
|===
|
| 78 |
+
|
| 79 |
+
[[reg-mconfigptr]]
|
| 80 |
+
==== mconfigptr
|
| 81 |
+
|
| 82 |
+
Address: `0xf15`
|
| 83 |
+
|
| 84 |
+
Pointer to configuration data structure. Read-only, configurable constant.
|
| 85 |
+
|
| 86 |
+
[cols="10h,20h,~", options="header"]
|
| 87 |
+
|===
|
| 88 |
+
| Bits | Name | Description
|
| 89 |
+
| 31:0 | - | Either pointer to configuration data structure, containing information about the harts and system, or all-zeroes. At least 4-byte-aligned.
|
| 90 |
+
|===
|
| 91 |
+
|
| 92 |
+
[[reg-misa]]
|
| 93 |
+
==== misa
|
| 94 |
+
|
| 95 |
+
Address: `0x301`
|
| 96 |
+
|
| 97 |
+
Read-only, constant. Value depends on which ISA extensions Hazard3 is configured with. The table below lists the fields which are _not_ always hardwired to 0:
|
| 98 |
+
|
| 99 |
+
[cols="10h,20h,~", options="header"]
|
| 100 |
+
|===
|
| 101 |
+
| Bits | Name | Description
|
| 102 |
+
| 31:30 | `mxl` | Always `0x1`. Indicates this is a 32-bit processor.
|
| 103 |
+
| 23 | `x` | Always 1 to indicate presence of <<extension-xh3misa-section>>, and possibly other custom extensions.
|
| 104 |
+
| 20 | `u` | 1 if User mode is supported, otherwise 0.
|
| 105 |
+
| 12 | `m` | 1 if the M extension is present (<<param-EXTENSION_M>> is `1`)
|
| 106 |
+
| 8 | `i` | 1 if the base ISA is RV32I (<<param-EXTENSION_E>> is `0`)
|
| 107 |
+
| 4 | `e` | 1 if the base ISA is RV32E (<<param-EXTENSION_E>> is `1`)
|
| 108 |
+
| 2 | `c` | 1 if the C extension is present (<<param-EXTENSION_C>> is `1`)
|
| 109 |
+
| 1 | `b` | 1 if Zba, Zbb and Zbs are all present (<<param-EXTENSION_ZBA>>, <<param-EXTENSION_ZBB>> and <<param-EXTENSION_ZBS>> are `1`)
|
| 110 |
+
| 0 | `a` | 1 if the A extension is present (<<param-EXTENSION_A>> is `1`)
|
| 111 |
+
|===
|
| 112 |
+
|
| 113 |
+
=== Standard M-mode Trap Handling CSRs
|
| 114 |
+
|
| 115 |
+
==== mstatus
|
| 116 |
+
|
| 117 |
+
Address: `0x300`
|
| 118 |
+
|
| 119 |
+
The below table lists the fields which are _not_ hardwired to 0:
|
| 120 |
+
|
| 121 |
+
[cols="10h,20h,~", options="header"]
|
| 122 |
+
|===
|
| 123 |
+
| Bits | Name | Description
|
| 124 |
+
| 21 | `tw` | Timeout wait. Only present if U-mode is supported. When 1, attempting to execute a WFI instruction in U-mode will instantly cause an illegal instruction exception.
|
| 125 |
+
| 17 | `mprv` | Modify privilege. Only present if U-mode is supported. If 1, loads and stores behave as though the current privilege level were `mpp`. This includes physical memory protection checks, and the privilege level asserted on the system bus alongside the load/store address.
|
| 126 |
+
| 12:11 | `mpp` | Previous privilege level. If U-mode is supported, this register can store the values 3 (M-mode) or 0 (U-mode). Otherwise, only 3 (M-mode). If another value is written, hardware rounds to the nearest supported mode.
|
| 127 |
+
| 7 | `mpie` | Previous interrupt enable. Readable and writable. Is set to the current value of `mstatus.mie` on trap entry. Is set to 1 on trap return.
|
| 128 |
+
| 3 | `mie` | Interrupt enable. Readable and writable. Is set to 0 on trap entry. Is set to the current value of `mstatus.mpie` on trap return.
|
| 129 |
+
|===
|
| 130 |
+
|
| 131 |
+
==== mstatush
|
| 132 |
+
|
| 133 |
+
Address: `0x310`
|
| 134 |
+
|
| 135 |
+
Hardwired to `0`.
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
==== medeleg
|
| 139 |
+
|
| 140 |
+
Address: `0x302`
|
| 141 |
+
|
| 142 |
+
Unimplemented, as neither U-mode traps nor S-mode are supported. Access will cause an illegal instruction exception.
|
| 143 |
+
|
| 144 |
+
==== mideleg
|
| 145 |
+
|
| 146 |
+
Address: `0x303`
|
| 147 |
+
|
| 148 |
+
Unimplemented, as neither U-mode traps nor S-mode are supported. Access will cause an illegal instruction exception.
|
| 149 |
+
|
| 150 |
+
==== mie
|
| 151 |
+
|
| 152 |
+
Address: `0x304`
|
| 153 |
+
|
| 154 |
+
Interrupt enable register. This is not to be confused with `mstatus.mie`, which is a global enable, and has the final say in whether any interrupt which is both enabled in `mie` and pending in `mip` will actually cause the processor to transfer control to a handler.
|
| 155 |
+
|
| 156 |
+
The table below lists the fields which are _not_ hardwired to 0:
|
| 157 |
+
|
| 158 |
+
[cols="10h,20h,~", options="header"]
|
| 159 |
+
|===
|
| 160 |
+
|Bits | Name | Description
|
| 161 |
+
| 11 | `meie` | External interrupt enable. Hazard3 has internal custom CSRs to further filter external interrupts, see <<reg-h3.meiea>>.
|
| 162 |
+
| 7 | `mtie` | Timer interrupt enable. A timer interrupt is requested when `mie.mtie`, `mip.mtip` and `mstatus.mie` are all 1.
|
| 163 |
+
| 3 | `msie` | Software interrupt enable. A software interrupt is requested when `mie.msie`, `mip.mtip` and `mstatus.mie` are all 1.
|
| 164 |
+
|===
|
| 165 |
+
|
| 166 |
+
NOTE: RISC-V reserves bits 16+ of `mie`/`mip` for platform use, which Hazard3 could use for external interrupt control. On RV32I this could only control 16 external interrupts, so Hazard3 instead adds nonstandard interrupt enable registers starting at <<reg-h3.meiea>>, and keeps the upper half of `mie` reserved.
|
| 167 |
+
|
| 168 |
+
[[reg-mip]]
|
| 169 |
+
==== mip
|
| 170 |
+
|
| 171 |
+
Address: `0x344`
|
| 172 |
+
|
| 173 |
+
Interrupt pending register. Read-only.
|
| 174 |
+
|
| 175 |
+
NOTE: The RISC-V specification lists `mip` as a read-write register, but the bits which are writable correspond to lower privilege modes (S- and U-mode) which are not implemented on Hazard3, so it is documented here as read-only.
|
| 176 |
+
|
| 177 |
+
The table below lists the fields which are _not_ hardwired to 0:
|
| 178 |
+
|
| 179 |
+
[cols="10h,20h,~", options="header"]
|
| 180 |
+
|===
|
| 181 |
+
|Bits | Name | Description
|
| 182 |
+
| 11 | `meip` | External interrupt pending. When 1, indicates there is at least one interrupt which is asserted (hence pending in <<reg-h3.meipa>>) and enabled in <<reg-h3.meiea>>.
|
| 183 |
+
| 7 | `mtip` | Timer interrupt pending. Level-sensitive interrupt signal from outside the core. Connected to a standard, external RISC-V 64-bit timer.
|
| 184 |
+
| 3 | `msip` | Software interrupt pending. In spite of the name, this is not triggered by an instruction on this core, rather it is wired to an external memory-mapped register to provide a cross-hart level-sensitive doorbell interrupt.
|
| 185 |
+
|===
|
| 186 |
+
|
| 187 |
+
[[reg-mtvec]]
|
| 188 |
+
==== mtvec
|
| 189 |
+
|
| 190 |
+
Address: `0x305`
|
| 191 |
+
|
| 192 |
+
Trap vector base address. Read-write. Exactly which bits of `mtvec` can be modified (possibly none) is configurable when instantiating the processor, but by default the entire register is writable. The reset value of `mtvec` is also configurable.
|
| 193 |
+
|
| 194 |
+
[cols="10h,20h,~", options="header"]
|
| 195 |
+
|===
|
| 196 |
+
|Bits | Name | Description
|
| 197 |
+
| 31:2 | `base` | Base address for trap entry. In Vectored mode, this is _OR'd_ with the trap offset to calculate the trap entry address, so the table must be aligned to its total size, rounded up to a power of 2. In Direct mode, `base` is word-aligned.
|
| 198 |
+
| 0 | `mode` | 0 selects Direct mode -- all traps (whether exception or interrupt) jump to `base`. 1 selects Vectored mode -- exceptions go to `base`, interrupts go to `base \| mcause << 2`.
|
| 199 |
+
|===
|
| 200 |
+
|
| 201 |
+
NOTE: In the RISC-V specification, `mode` is a 2-bit write-any read-legal field in bits 1:0. Hazard3 implements this by hardwiring bit 1 to 0.
|
| 202 |
+
|
| 203 |
+
[[reg-mscratch]]
|
| 204 |
+
==== mscratch
|
| 205 |
+
|
| 206 |
+
Address: `0x340`
|
| 207 |
+
|
| 208 |
+
Read-write 32-bit register. No specific hardware function -- available for software to swap with a register when entering a trap handler.
|
| 209 |
+
|
| 210 |
+
[[reg-mepc]]
|
| 211 |
+
==== mepc
|
| 212 |
+
|
| 213 |
+
Address: `0x341`
|
| 214 |
+
|
| 215 |
+
Exception program counter. When entering a trap, the current value of the program counter is recorded here. When executing an `mret`, the processor jumps to `mepc`. Can also be read and written by software.
|
| 216 |
+
|
| 217 |
+
On Hazard3, bits 31:2 of `mepc` are capable of holding all 30-bit values. Bit 1 is writable only if the C extension is implemented, and is otherwise hardwired to 0. Bit 0 is hardwired to 0, as per the specification.
|
| 218 |
+
|
| 219 |
+
All traps on Hazard3 are precise. For example, a load/store bus error will set `mepc` to the exact address of the load/store instruction which encountered the fault.
|
| 220 |
+
|
| 221 |
+
[[reg-mcause]]
|
| 222 |
+
==== mcause
|
| 223 |
+
|
| 224 |
+
Address: `0x342`
|
| 225 |
+
|
| 226 |
+
Exception cause. Set when entering a trap to indicate the reason for the trap. Readable and writable by software.
|
| 227 |
+
|
| 228 |
+
NOTE: On Hazard3, most bits of `mcause` are hardwired to 0. Only bit 31, and enough least-significant bits to index all exception and all interrupt causes (at least four bits), are backed by registers. Only these bits are writable; the RISC-V specification only requires that `mcause` be able to hold all legal cause values.
|
| 229 |
+
|
| 230 |
+
The most significant bit of `mcause` is set to 1 to indicate an interrupt cause, and 0 to indicate an exception cause. The following interrupt causes may be set by Hazard3 hardware:
|
| 231 |
+
|
| 232 |
+
[cols="10h,~", options="header"]
|
| 233 |
+
|===
|
| 234 |
+
| Cause | Description
|
| 235 |
+
| 3 | Software interrupt (`mip.msip`)
|
| 236 |
+
| 7 | Timer interrupt (`mip.mtip`)
|
| 237 |
+
| 11 | External interrupt (`mip.meip`)
|
| 238 |
+
|===
|
| 239 |
+
|
| 240 |
+
The following exception causes may be set by Hazard3 hardware:
|
| 241 |
+
|
| 242 |
+
[cols="10h,~", options="header"]
|
| 243 |
+
|===
|
| 244 |
+
| Cause | Description
|
| 245 |
+
| 0 | Instruction address misaligned
|
| 246 |
+
| 1 | Instruction access fault
|
| 247 |
+
| 2 | Illegal instruction
|
| 248 |
+
| 3 | Breakpoint
|
| 249 |
+
| 4 | Load address misaligned
|
| 250 |
+
| 5 | Load access fault
|
| 251 |
+
| 6 | Store/AMO address misaligned
|
| 252 |
+
| 7 | Store/AMO access fault
|
| 253 |
+
| 8 | Environment call from U-mode
|
| 254 |
+
| 11 | Environment call from M-mode
|
| 255 |
+
|===
|
| 256 |
+
|
| 257 |
+
==== mtval
|
| 258 |
+
|
| 259 |
+
Address: `0x343`
|
| 260 |
+
|
| 261 |
+
Hardwired to 0.
|
| 262 |
+
|
| 263 |
+
==== mcounteren
|
| 264 |
+
|
| 265 |
+
Address: `0x306`
|
| 266 |
+
|
| 267 |
+
Counter enable. Control access to counters from U-mode. Not to be confused with <<reg-mcountinhibit>>.
|
| 268 |
+
|
| 269 |
+
This register only exists if U-mode is supported.
|
| 270 |
+
|
| 271 |
+
[cols="10h,20h,~", options="header"]
|
| 272 |
+
|===
|
| 273 |
+
|Bits | Name | Description
|
| 274 |
+
| 31:3 | - | RES0
|
| 275 |
+
| 2 | `ir` | If 1, U-mode is permitted to access the `instret`/`instreth` instruction retire counter CSRs. Otherwise, U-mode accesses to these CSRs will trap.
|
| 276 |
+
| 1 | `tm` | No hardware effect, as the `time`/`timeh` CSRs are not implemented. However, this field still exists, as M-mode software can use it to track whether it should emulate U-mode attempts to access those CSRs.
|
| 277 |
+
| 0 | `cy` |If 1, U-mode is permitted to access the `cycle`/`cycleh` cycle counter CSRs. Otherwise, U-mode accesses to these CSRs will trap.
|
| 278 |
+
|===
|
| 279 |
+
|
| 280 |
+
=== Standard Memory Protection CSRs
|
| 281 |
+
|
| 282 |
+
==== pmpcfg0...3
|
| 283 |
+
|
| 284 |
+
Address: `0x3a0` through `0x3a3`
|
| 285 |
+
|
| 286 |
+
Configuration registers for up to 16 physical memory protection regions. Only present if PMP support is configured. If so, all 4 registers are present, but some registers may be partially/completely hardwired depending on the number of PMP regions present.
|
| 287 |
+
|
| 288 |
+
By default, M-mode has full permissions (RWX) on all of memory, and U-mode has no permissions. A PMP region can be configured to alter this default within some range of addresses. For every memory location executed, loaded or stored, the processor looks up the _lowest active region_ that overlaps that memory location, and applies its permissions to determine whether this access is allowed. The full description can be found in the RISC-V privileged ISA manual.
|
| 289 |
+
|
| 290 |
+
Each `pmpcfg` register divides into four identical 8-bit chunks, each corresponding to one region, and laid out as below:
|
| 291 |
+
|
| 292 |
+
[cols="10h,20h,~", options="header"]
|
| 293 |
+
|===
|
| 294 |
+
|Bits | Name | Description
|
| 295 |
+
| 7 | `L` | Lock region, and additionally enforce its permissions on M-mode as well as U-mode.
|
| 296 |
+
| 6:5 | - | RES0
|
| 297 |
+
| 4:3 | `A` | Address-matching mode. Values supported are 0 (OFF), 2 (NA4, naturally aligned 4-byte) and 3 (NAPOT, naturally aligned power-of-two). 1 (TOR, top of range) is not supported. Attempting to write an unsupported value will set the region to OFF.
|
| 298 |
+
| 2 | `X` | Execute permission
|
| 299 |
+
| 1 | `W` | Write permission
|
| 300 |
+
| 0 | `R` | Read permission
|
| 301 |
+
|===
|
| 302 |
+
|
| 303 |
+
==== pmpaddr0...15
|
| 304 |
+
|
| 305 |
+
Address: `0x3b0` through `0x3bf`
|
| 306 |
+
|
| 307 |
+
Address registers for up to 16 physical memory protection regions. Only present if PMP support is configured. If so, all 16 registers are present, but some may fully/partially hardwired.
|
| 308 |
+
|
| 309 |
+
`pmpaddr` registers express addresses in units of 4 bytes, so on Hazard3 (a 32-bit processor with no virtual address support) only the lower 30 bits of each address register are implemented.
|
| 310 |
+
|
| 311 |
+
The interpretation of the `pmpaddr` bits depends on the `A` mode configured in the corresponding `pmpcfg` register field:
|
| 312 |
+
|
| 313 |
+
* For NA4, the entire 30-bit PMP address is matched against the 30 MSBs of the checked address.
|
| 314 |
+
* For NAPOT, `pmpaddr` bits up to and including the least-significant zero bit are ignored, and the remaining bits are matched against the MSBs of the checked address.
|
| 315 |
+
|
| 316 |
+
=== Standard M-mode Performance Counters
|
| 317 |
+
|
| 318 |
+
==== mcycle
|
| 319 |
+
|
| 320 |
+
Address: `0xb00`
|
| 321 |
+
|
| 322 |
+
Lower half of the 64-bit cycle counter. Readable and writable by software. Increments every cycle, unless `mcountinhibit.cy` is 1, or the processor is in Debug Mode (as <<reg-dcsr>>.`stopcount` is hardwired to 1).
|
| 323 |
+
|
| 324 |
+
If written with a value `n` and read on the very next cycle, the value read will be exactly `n`. The RISC-V spec says this about `mcycle`: "Any CSR write takes effect after the writing instruction has otherwise completed."
|
| 325 |
+
|
| 326 |
+
==== mcycleh
|
| 327 |
+
|
| 328 |
+
Address: `0xb80`
|
| 329 |
+
|
| 330 |
+
Upper half of the 64-bit cycle counter. Readable and writable by software. Increments on cycles where `mcycle` has the value `0xffffffff`, unless `mcountinhibit.cy` is 1, or the processor is in Debug Mode.
|
| 331 |
+
|
| 332 |
+
This includes when `mcycle` is written on that same cycle, since RISC-V specifies the CSR write takes place _after_ the increment for that cycle.
|
| 333 |
+
|
| 334 |
+
==== minstret
|
| 335 |
+
|
| 336 |
+
Address: `0xb02`
|
| 337 |
+
|
| 338 |
+
Lower half of the 64-bit instruction retire counter. Readable and writable by software. Increments with every instruction executed, unless `mcountinhibit.ir` is 1, or the processor is in Debug Mode (as <<reg-dcsr>>.`stopcount` is hardwired to 1).
|
| 339 |
+
|
| 340 |
+
If some value `n` is written to `minstret`, and it is read back by the very next instruction, the value read will be exactly `n`. This is because the CSR write logically takes place after the instruction has otherwise completed.
|
| 341 |
+
|
| 342 |
+
==== minstreth
|
| 343 |
+
|
| 344 |
+
Address: `0xb82`
|
| 345 |
+
|
| 346 |
+
Upper half of the 64-bit instruction retire counter. Readable and writable by software. Increments when the core retires an instruction and the value of `minstret` is `0xffffffff`, unless `mcountinhibit.ir` is 1, or the processor is in Debug Mode.
|
| 347 |
+
|
| 348 |
+
==== mhpmcounter3...31
|
| 349 |
+
|
| 350 |
+
Address: `0xb03` through `0xb1f`
|
| 351 |
+
|
| 352 |
+
Hardwired to 0.
|
| 353 |
+
|
| 354 |
+
==== mhpmcounter3...31h
|
| 355 |
+
|
| 356 |
+
Address: `0xb83` through `0xb9f`
|
| 357 |
+
|
| 358 |
+
Hardwired to 0.
|
| 359 |
+
|
| 360 |
+
|
| 361 |
+
[[reg-mcountinhibit]]
|
| 362 |
+
==== mcountinhibit
|
| 363 |
+
|
| 364 |
+
Address: `0x320`
|
| 365 |
+
|
| 366 |
+
Counter inhibit. Read-write. The table below lists the fields which are _not_ hardwired to 0:
|
| 367 |
+
|
| 368 |
+
[cols="10h,20h,~", options="header"]
|
| 369 |
+
|===
|
| 370 |
+
| Bits | Name | Description
|
| 371 |
+
| 2 | `ir` | When 1, inhibit counting of `minstret`/`minstreth`. Resets to 1.
|
| 372 |
+
| 0 | `cy` | When 1, inhibit counting of `mcycle`/`mcycleh`. Resets to 1.
|
| 373 |
+
|===
|
| 374 |
+
|
| 375 |
+
==== mhpmevent3...31
|
| 376 |
+
|
| 377 |
+
Address: `0x323` through `0x33f`
|
| 378 |
+
|
| 379 |
+
Hardwired to 0.
|
| 380 |
+
|
| 381 |
+
=== Standard Trigger CSRs
|
| 382 |
+
|
| 383 |
+
Trigger CSRs control Hazard3's trigger module, described in <<section-trigger-module>>. They are implemented if <<param-DEBUG_SUPPORT>> = `1`, and otherwise raise illegal instruction exceptions when accessed.
|
| 384 |
+
|
| 385 |
+
[[reg-tselect]]
|
| 386 |
+
==== tselect
|
| 387 |
+
|
| 388 |
+
Address: `0x7a0`
|
| 389 |
+
|
| 390 |
+
Select a trigger for configuration. The selected trigger is described in <<reg-tinfo>> and can be configured through <<reg-tdata1>> and <<reg-tdata2>>. See <<section-trigger-module>> for an overview of Hazard3's trigger capabilities.
|
| 391 |
+
|
| 392 |
+
This register implements exactly enough bits to index the configured number of triggers. Remaining bits are hardwired to zero.
|
| 393 |
+
|
| 394 |
+
[[reg-tdata1]]
|
| 395 |
+
==== tdata1
|
| 396 |
+
|
| 397 |
+
Address: `0x7a1`
|
| 398 |
+
|
| 399 |
+
Configure the trigger selected by <<reg-tselect>>.
|
| 400 |
+
|
| 401 |
+
[cols="10h,20h,~", options="header"]
|
| 402 |
+
|===
|
| 403 |
+
| Bits | Name | Description
|
| 404 |
+
| 31:28 | `type` a| On Hazard3 this field is hardwired for a given value of <<reg-tselect>>:
|
| 405 |
+
|
| 406 |
+
* `0`: no trigger
|
| 407 |
+
* `2`: address/data match
|
| 408 |
+
* `3`: instruction count
|
| 409 |
+
* `4`: interrupt
|
| 410 |
+
* `5`: exception
|
| 411 |
+
|
| 412 |
+
| 27 | `dmode` | Claim this trigger for Debug Mode use. Only writable by Debug Mode. When set to 1, other modes cannot write to `tdata*` registers for this trigger. This bit must be set to enable Debug Mode entry from a trigger (`action` = `1`).
|
| 413 |
+
|
| 414 |
+
Hazard3 hardwires this field to zero for the instruction count trigger, which only supports breaking to M-mode. It has normal read/write behaviour for other trigger types.
|
| 415 |
+
|===
|
| 416 |
+
|
| 417 |
+
The layout of bits `26:0` of this register depends on the value of `type`.
|
| 418 |
+
|
| 419 |
+
[[reg-mcontrol]]
|
| 420 |
+
===== mcontrol
|
| 421 |
+
|
| 422 |
+
`mcontrol` is the alias for `tdata1` when `type` is `2` (address/data match trigger). Hazard3 implements only exact instruction address match (breakpoints).
|
| 423 |
+
|
| 424 |
+
[cols="10h,20h,~", options="header"]
|
| 425 |
+
|===
|
| 426 |
+
| Bits | Name | Description
|
| 427 |
+
| 26:21 | `maskmax` | Hardwired to zero; only exact matches are supported
|
| 428 |
+
| 20 | `hit` | Hardwired to zero; this feature is not implemented
|
| 429 |
+
| 19 | `select` | Hardwired to zero; only address matching is supported (not data matching)
|
| 430 |
+
| 18 | `timing` | Hardwired to zero; the breakpoint takes place before the matching instruction executes (but after all earlier instructions in program order are observed to have completed)
|
| 431 |
+
| 17:16 | `sizelo` | Hardwired to zero; all instruction sizes are matched
|
| 432 |
+
| 15:12 | `action` | Supports the values `0` (break to M-mode `ebreak` exception handler) and `1` (break to Debug Mode). Bits 15:13 are hardwired to zero.
|
| 433 |
+
|
| 434 |
+
An `action` of `0` is ignored when `tcontrol.mte` is `0`. An `action` of `1` is ignored when `tdata1.dmode` is `0`.
|
| 435 |
+
| 11 | `chain` | Hardwired to zero; chaining is not supported
|
| 436 |
+
| 10:7 | `match` | Hardwired to zero; match is always on the exact address
|
| 437 |
+
| 6 | `m` | Write 1 to enable matching during M-mode execution
|
| 438 |
+
| 3 | `u` | Write 1 to enable matching during U-mode execution. Hardwired to zero if <<param-U_MODE>> = `0`.
|
| 439 |
+
| 2 | `execute` | Write 1 to enable matching on instruction addresses
|
| 440 |
+
| 1 | `store` | Hardwired to zero; store address/data matching is not supported
|
| 441 |
+
| 0 | `load` | Hardwired to zero; load address/data matching is not supported
|
| 442 |
+
|===
|
| 443 |
+
|
| 444 |
+
[[reg-icount]]
|
| 445 |
+
===== icount
|
| 446 |
+
|
| 447 |
+
`icount` is the alias for `tdata1` when `type` is `3` (instruction count trigger).
|
| 448 |
+
|
| 449 |
+
[cols="10h,20h,~", options="header"]
|
| 450 |
+
|===
|
| 451 |
+
| Bits | Name | Description
|
| 452 |
+
| 24 | `hit` | Hardwired to zero; this feature is not implemented
|
| 453 |
+
| 23:10 | `count` | Hardwired to `1`; only single-stepping is supported
|
| 454 |
+
| 9 | `m` | Write 1 to enable matching during M-mode execution, if `tcontrol.mte` is also set. Self-clears when this trigger fires (in any privilege mode).
|
| 455 |
+
| 6 | `u` | Write 1 to enable matching during U-mode execution. Hardwired to zero if <<param-U_MODE>> = `0`. Self-clears when this trigger fires (in any privilege mode).
|
| 456 |
+
| 5:0 | `action` | Hardwired to `0`; this trigger only supports breaking to M-mode with an exception cause of `3` (`ebreak`). The corresponding Debug Mode functionality is already provided by `dcsr.step`.
|
| 457 |
+
|===
|
| 458 |
+
|
| 459 |
+
See <<section-icount-trigger>> for more information about this trigger's behaviour on Hazard3.
|
| 460 |
+
|
| 461 |
+
[[reg-itrigger]]
|
| 462 |
+
===== itrigger
|
| 463 |
+
|
| 464 |
+
`itrigger` is the alias for `tdata1` when `type` is `4` (interrupt trigger).
|
| 465 |
+
|
| 466 |
+
[cols="10h,20h,~", options="header"]
|
| 467 |
+
|===
|
| 468 |
+
| Bits | Name | Description
|
| 469 |
+
| 24 | `hit` | Hardwired to zero; this feature is not implemented
|
| 470 |
+
| 9 | `m` | Write 1 to enable matching during M-mode execution, if `tcontrol.mte` is also set.
|
| 471 |
+
| 6 | `u` | Write 1 to enable matching during U-mode execution. Hardwired to zero if <<param-U_MODE>> = `0`.
|
| 472 |
+
| 5:0 | `action` | Hardwired to `1`; this trigger only supports breaking to Debug Mode (as an M-mode breakpoint exception triggered immediately after M-mode interrupt entry would be unrecoverable).
|
| 473 |
+
|===
|
| 474 |
+
|
| 475 |
+
See <<section-interrupt-trigger>> for more information about this trigger's behaviour on Hazard3.
|
| 476 |
+
|
| 477 |
+
[[reg-etrigger]]
|
| 478 |
+
===== etrigger
|
| 479 |
+
|
| 480 |
+
`etrigger` is the alias for `tdata1` when `type` is `5` (exception trigger).
|
| 481 |
+
|
| 482 |
+
[cols="10h,20h,~", options="header"]
|
| 483 |
+
|===
|
| 484 |
+
| Bits | Name | Description
|
| 485 |
+
| 24 | `hit` | Hardwired to zero; this feature is not implemented
|
| 486 |
+
| 9 | `m` | Write 1 to enable matching during M-mode execution, if `tcontrol.mte` is also set.
|
| 487 |
+
| 6 | `u` | Write 1 to enable matching during U-mode execution. Hardwired to zero if <<param-U_MODE>> = `0`.
|
| 488 |
+
| 5:0 | `action` | Hardwired to `1`; this trigger only supports breaking to Debug Mode (as an M-mode breakpoint exception triggered immediately after M-mode interrupt entry would be unrecoverable).
|
| 489 |
+
|===
|
| 490 |
+
|
| 491 |
+
See <<section-exception-trigger>> for more information about this trigger's behaviour on Hazard3.
|
| 492 |
+
|
| 493 |
+
[[reg-tdata2]]
|
| 494 |
+
==== tdata2
|
| 495 |
+
|
| 496 |
+
Address: `0x7a2`
|
| 497 |
+
|
| 498 |
+
The interpretation of this CSR depends on the `type` field of <<reg-tdata1>>:
|
| 499 |
+
|
| 500 |
+
[horizontal]
|
| 501 |
+
`type` = `2`:: Address/data trigger: `tdata2` contains the address/data to be matched. On Hazard3 this is always an instruction address, and `tdata2` only implemenents enough bits to store any valid program counter (multiple of IALIGN).
|
| 502 |
+
|
| 503 |
+
`type` = `3`:: Instruction count trigger: `tdata2` is hardwired to zero.
|
| 504 |
+
|
| 505 |
+
`type` = `4`:: Interrupt trigger: `tdata2` contains a bitmap of the interrupt `mcause` values upon which this trigger will match. For example, setting bit `11` (value `0x800`) enables triggering on the machine external IRQ vector (`mip.meip`).
|
| 506 |
+
|
| 507 |
+
`type` = `5`:: Exception trigger: `tdata2` contains a bitmap of the non-interrupt `mcause` values upon which this trigger will match. For example, setting bit `2` (value `0x4`) enables triggering on illegal instruction exceptions.
|
| 508 |
+
|
| 509 |
+
[[reg-tdata3]]
|
| 510 |
+
==== tdata3
|
| 511 |
+
|
| 512 |
+
Address: `0x7a3`
|
| 513 |
+
|
| 514 |
+
Hardwired to zero.
|
| 515 |
+
|
| 516 |
+
[[reg-tinfo]]
|
| 517 |
+
==== tinfo
|
| 518 |
+
|
| 519 |
+
Address: `0x7a4`
|
| 520 |
+
|
| 521 |
+
Lists the capabilities of the trigger currently selected by <<reg-tselect>>. This takes the form of a bitmap of values supported by `tdata1.type`. For example, bit `2` being set (a value of `0x4`) indicates the trigger supports `type` = `2`, "address/data match".
|
| 522 |
+
|
| 523 |
+
[cols="10h,~", options="header"]
|
| 524 |
+
|===
|
| 525 |
+
| Bits | Description
|
| 526 |
+
| 5 | Supports `type` = `5`, exception trigger
|
| 527 |
+
| 4 | Supports `type` = `4`, interrupt trigger
|
| 528 |
+
| 3 | Supports `type` = `3`, instruction count trigger
|
| 529 |
+
| 2 | Supports `type` = `2`, address/data match trigger
|
| 530 |
+
| 0 | Supports `type` = `0`, disabled or no trigger
|
| 531 |
+
|===
|
| 532 |
+
|
| 533 |
+
Hazard3 triggers support only a single `type` each. Therefore `tinfo` always has exactly one bit set, and the `tdata1.type` field is read-only.
|
| 534 |
+
|
| 535 |
+
If bit `0` is set, and no other bit is set, there is no trigger corresponding to the current value of `tselect`. There are also no triggers at higher values of `tselect`; trigger enumeration terminates at this point.
|
| 536 |
+
|
| 537 |
+
[[debug-csr-section]]
|
| 538 |
+
=== Standard Debug Mode CSRs
|
| 539 |
+
|
| 540 |
+
This section describes the Debug Mode CSRs, which follow the 0.13.2 RISC-V debug specification. The <<debug-chapter>> section gives more detail on the remainder of Hazard3's debug implementation, including the Debug Module.
|
| 541 |
+
|
| 542 |
+
All Debug Mode CSRs are 32-bit; DXLEN is always 32.
|
| 543 |
+
|
| 544 |
+
[[reg-dcsr]]
|
| 545 |
+
==== dcsr
|
| 546 |
+
|
| 547 |
+
Address: `0x7b0`
|
| 548 |
+
|
| 549 |
+
Debug control and status register. Access outside of Debug Mode will cause an illegal instruction exception. Relevant fields are implemented as follows:
|
| 550 |
+
|
| 551 |
+
[cols="10h,20h,~", options="header"]
|
| 552 |
+
|===
|
| 553 |
+
| Bits | Name | Description
|
| 554 |
+
| 31:28 | `xdebugver` | Hardwired to 4: external debug support as per RISC-V 0.13.2 debug specification.
|
| 555 |
+
| 15 | `ebreakm` | When 1, `ebreak` instructions executed in M-mode will break to Debug Mode instead of trapping
|
| 556 |
+
| 12 | `ebreaku` | When 1, `ebreak` instructions executed in U-mode will break to Debug Mode instead of trapping. Hardwired to 0 if U-mode is not supported.
|
| 557 |
+
| 11 | `stepie` | Hardwired to 0: no interrupts are taken during hardware single-stepping.
|
| 558 |
+
| 10 | `stopcount` | Hardwired to 1: `mcycle`/`mcycleh` and `minstret`/`minstreth` do not increment in Debug Mode.
|
| 559 |
+
| 9 | `stoptime` | Hardwired to 1: core-local timers don't increment in debug mode. This requires cooperation of external hardware based on the halt status to implement correctly.
|
| 560 |
+
| 8:6 | `cause` | Read-only, set by hardware -- see table below.
|
| 561 |
+
| 2 | `step` | When 1, re-enter Debug Mode after each instruction executed in M-mode.
|
| 562 |
+
| 1:0 | `prv` | Read the privilege state the core was in when it entered Debug Mode, and set the privilege state it will be in when it exits Debug Mode. If U-mode is implemented, the values 3 and 0 are supported. Otherwise hardwired to 3.
|
| 563 |
+
|===
|
| 564 |
+
|
| 565 |
+
Fields not mentioned above are hardwired to 0.
|
| 566 |
+
|
| 567 |
+
Hazard3 may set the following `dcsr.cause` values on entry to Debug Mode:
|
| 568 |
+
|
| 569 |
+
[cols="10h,~", options="header"]
|
| 570 |
+
|===
|
| 571 |
+
| Cause | Description
|
| 572 |
+
| `1` | An `ebreak` instruction executed in M-mode when `dcsr.ebreakm` was set, or U-mode when `dcsr.ebreaku` was set.
|
| 573 |
+
| `2` | A trigger fired.
|
| 574 |
+
| `3` | The Debug Module requested a processor halt, or a reset-halt request was present when the core reset was released.
|
| 575 |
+
| `4` | The processor executed one instruction with single-stepping enabled via `dcsr.step`.
|
| 576 |
+
|===
|
| 577 |
+
|
| 578 |
+
Cause `5` (`resethaltreq`) is never set by hardware. This event is reported as a normal halt, cause `3`.
|
| 579 |
+
|
| 580 |
+
==== dpc
|
| 581 |
+
|
| 582 |
+
Address: `0x7b1`
|
| 583 |
+
|
| 584 |
+
Debug program counter. When entering Debug Mode, `dpc` samples the current program counter, e.g. the address of an `ebreak` which caused Debug Mode entry. When leaving debug mode, the processor jumps to `dpc`. The host may read/write this register whilst in Debug Mode.
|
| 585 |
+
|
| 586 |
+
==== dscratch0
|
| 587 |
+
|
| 588 |
+
Address: `0x7b2`
|
| 589 |
+
|
| 590 |
+
Not implemented. Access will cause an illegal instruction exception.
|
| 591 |
+
|
| 592 |
+
To provide data exchange between the Debug Module and the core, the Debug Module's `data0` register is mapped into the core's CSR space at a read/write M-custom address -- see <<reg-dmdata0>>.
|
| 593 |
+
|
| 594 |
+
==== dscratch1
|
| 595 |
+
|
| 596 |
+
Address: `0x7b3`
|
| 597 |
+
|
| 598 |
+
Not implemented. Access will cause an illegal instruction exception.
|
| 599 |
+
|
| 600 |
+
=== Custom Debug Mode CSRs
|
| 601 |
+
|
| 602 |
+
[[reg-h3.dmdata0]]
|
| 603 |
+
==== h3.dmdata0
|
| 604 |
+
|
| 605 |
+
Address: `0xbff`
|
| 606 |
+
|
| 607 |
+
The Debug Module's internal `data0` register is mapped to this CSR address when the core is in debug mode. At any other time, access to this CSR address will cause an illegal instruction exception.
|
| 608 |
+
|
| 609 |
+
NOTE: The 0.13.2 debug specification allows for the Debug Module's abstract data registers to be mapped into the core's CSR address space, but there is no Debug-custom space, so the read/write M-custom space is used instead to avoid conflict with future versions of the debug specification.
|
| 610 |
+
|
| 611 |
+
The Debug Module uses this mapping to exchange data with the core by injecting `csrr`/`csrw` instructions into the prefetch buffer. This in turn is used to implement the Abstract Access Register command. See <<debug-chapter>>.
|
| 612 |
+
|
| 613 |
+
This CSR address is given by the `dataaddress` field of the Debug Module's `hartinfo` register, and `hartinfo.dataaccess` is set to 0 to indicate this is a CSR mapping, not a memory mapping.
|
| 614 |
+
|
| 615 |
+
=== Custom Interrupt Handling CSRs
|
| 616 |
+
|
| 617 |
+
[[reg-h3.meiea]]
|
| 618 |
+
==== h3.meiea
|
| 619 |
+
|
| 620 |
+
Address: `0xbe0`
|
| 621 |
+
|
| 622 |
+
External interrupt enable array. Contains a read-write bit for each external interrupt request: a `1` bit indicates that interrupt is currently enabled. At reset, all external interrupts are disabled.
|
| 623 |
+
|
| 624 |
+
If enabled, an external interrupt can cause assertion of the standard RISC-V machine external interrupt pending flag (`mip.meip`), and therefore cause the processor to enter the external interrupt vector. See <<reg-h3.meipa>>.
|
| 625 |
+
|
| 626 |
+
There are up to 512 external interrupts. The upper half of this register contains a 16-bit window into the full 512-bit vector. The window is indexed by the 5 LSBs of the write data. For example:
|
| 627 |
+
|
| 628 |
+
----
|
| 629 |
+
csrrs a0, meiea, a0 // Read IRQ enables from the window selected by a0
|
| 630 |
+
csrw meiea, a0 // Write a0[31:16] to the window selected by a0[4:0]
|
| 631 |
+
csrr a0, meiea // Read from window 0 (edge case)
|
| 632 |
+
----
|
| 633 |
+
|
| 634 |
+
The purpose of this scheme is to allow software to _index_ an array of interrupt enables (something not usually possible in the CSR space) without introducing a stateful CSR index register which may have to be saved/restored around IRQs.
|
| 635 |
+
|
| 636 |
+
[cols="10h,20h,~", options="header"]
|
| 637 |
+
|===
|
| 638 |
+
| Bits | Name | Description
|
| 639 |
+
| 31:16 | `window` | 16-bit read/write window into the external interrupt enable array
|
| 640 |
+
| 15:5 | - | RES0
|
| 641 |
+
| 4:0 | `index` | Write-only self-clearing field (no value is stored) used to control which window of the array appears in `window`.
|
| 642 |
+
|===
|
| 643 |
+
|
| 644 |
+
[[reg-h3.meipa]]
|
| 645 |
+
==== h3.meipa
|
| 646 |
+
|
| 647 |
+
Address: `0xbe1`
|
| 648 |
+
|
| 649 |
+
External interrupt pending array. Contains a read-only bit for each external interrupt request. Similarly to `h3.meiea`, this register is a window into an array of up to 512 external interrupt flags. The status appears in the upper 16 bits of the value read from `h3.meipa`, and the lower 5 bits of the value _written_ by the same CSR instruction (or 0 if no write takes place) select a 16-bit window of the full interrupt pending array.
|
| 650 |
+
|
| 651 |
+
A `1` bit indicates that interrupt is currently asserted. IRQs are assumed to be level-sensitive, and the relevant `h3.meipa` bit is cleared by servicing the requester so that it deasserts its interrupt request.
|
| 652 |
+
|
| 653 |
+
When any interrupt of sufficient priority is both set in `h3.meipa` and enabled in `h3.meiea`, the standard RISC-V external interrupt pending bit `mip.meip` is asserted. In other words, `h3.meipa` is filtered by `h3.meiea` to generate the standard `mip.meip` flag. So, an external interrupt is taken when _all_ of the following are true:
|
| 654 |
+
|
| 655 |
+
* An interrupt is currently asserted in `h3.meipa`
|
| 656 |
+
* The matching interrupt enable bit is set in `h3.meiea`
|
| 657 |
+
* The interrupt priority is greater than or equal to the preemption priority in `h3.meicontext`
|
| 658 |
+
* The standard M-mode interrupt enable `mstatus.mie` is set
|
| 659 |
+
* The standard M-mode global external interrupt enable `mie.meie` is set
|
| 660 |
+
|
| 661 |
+
In this case, the processor jumps to either:
|
| 662 |
+
|
| 663 |
+
* `mtvec` directly, if vectoring is disabled (`mtvec[0]` is 0)
|
| 664 |
+
* `mtvec + 0x2c`, if vectoring is enabled (`mtvec[0]` is 1)
|
| 665 |
+
|
| 666 |
+
[cols="10h,20h,~", options="header"]
|
| 667 |
+
|===
|
| 668 |
+
| Bits | Name | Description
|
| 669 |
+
| 31:16 | `window` | 16-bit read-only window into the external interrupt pending array
|
| 670 |
+
| 15:5 | - | RES0
|
| 671 |
+
| 4:0 | `index` | Write-only, self-clearing field (no value is stored) used to control which window of the array appears in `window`.
|
| 672 |
+
|===
|
| 673 |
+
|
| 674 |
+
[[reg-h3.meifa]]
|
| 675 |
+
==== h3.meifa
|
| 676 |
+
|
| 677 |
+
Address: `0xbe2`
|
| 678 |
+
|
| 679 |
+
External interrupt force array. Contains a read-write bit for every interrupt request. Writing a 1 to a bit in the interrupt force array causes the corresponding bit to become pending in `h3.meipa`. Software can use this feature to manually trigger a particular interrupt.
|
| 680 |
+
|
| 681 |
+
There are no restrictions on using `h3.meifa` inside of an interrupt. The more useful case here is to schedule some lower-priority handler from within a high-priority interrupt, so that it will execute before the core returns to the foreground code. Implementers may wish to reserve some external IRQs with their external inputs tied to 0 for this purpose.
|
| 682 |
+
|
| 683 |
+
Bits can be cleared by software, and are cleared automatically by hardware upon a read of `h3.meinext` which returns the corresponding IRQ number in `h3.meinext.irq` (no matter whether `h3.meinext.update` is written).
|
| 684 |
+
|
| 685 |
+
`h3.meifa` implements the same array window indexing scheme as `h3.meiea` and `h3.meipa`.
|
| 686 |
+
|
| 687 |
+
[cols="10h,20h,~", options="header"]
|
| 688 |
+
|===
|
| 689 |
+
| Bits | Name | Description
|
| 690 |
+
| 31:16 | `window` | 16-bit read/write window into the external interrupt force array
|
| 691 |
+
| 15:5 | - | RES0
|
| 692 |
+
| 4:0 | `index` | Write-only, self-clearing field (no value is stored) used to control which window of the array appears in `window`.
|
| 693 |
+
|===
|
| 694 |
+
|
| 695 |
+
[[reg-h3.meipra]]
|
| 696 |
+
==== h3.meipra
|
| 697 |
+
|
| 698 |
+
Address: `0xbe3`
|
| 699 |
+
|
| 700 |
+
External interrupt priority array. Each interrupt has an (up to) 4-bit priority value associated with it, and each access to this register reads and/or writes a 16-bit window containing four such priority values. When less than 16 priority levels are available, the LSBs of the priority fields are hardwired to 0.
|
| 701 |
+
|
| 702 |
+
When an interrupt's priority is lower than the current preemption priority `h3.meicontext.preempt`, it is treated as not being pending. The pending bit in `h3.meipa` will still assert, but the machine external interrupt pending bit `mip.meip` will not, so the processor will ignore this interrupt. See <<reg-h3.meicontext>>.
|
| 703 |
+
|
| 704 |
+
[cols="10h,20h,~", options="header"]
|
| 705 |
+
|===
|
| 706 |
+
| Bits | Name | Description
|
| 707 |
+
| 31:16 | `window` | 16-bit read/write window into the external interrupt priority array, containing four 4-bit priority values.
|
| 708 |
+
| 15:7 | - | RES0
|
| 709 |
+
| 6:0 | `index` | Write-only, self-clearing field (no value is stored) used to control which window of the array appears in `window`.
|
| 710 |
+
|===
|
| 711 |
+
|
| 712 |
+
[[reg-h3.meinext]]
|
| 713 |
+
==== h3.meinext
|
| 714 |
+
|
| 715 |
+
Address: `0xbe4`
|
| 716 |
+
|
| 717 |
+
Get next interrupt. Contains the index of the highest-priority external interrupt which is both asserted in `h3.meipa` and enabled in `h3.meiea`, left-shifted by 2 so that it can be used to index an array of 32-bit function pointers. If there is no such interrupt, the MSB is set.
|
| 718 |
+
|
| 719 |
+
When multiple interrupts of the same priority are both pending and enabled, the lowest-numbered wins. Interrupts with priority less than `h3.meicontext.ppreempt` -- the _previous_ preemption priority -- are treated as though they are not pending. This is to ensure that a preempting interrupt frame does not service interrupts which may be in progress in the frame that was preempted.
|
| 720 |
+
|
| 721 |
+
[cols="10h,20h,~", options="header"]
|
| 722 |
+
|===
|
| 723 |
+
| Bits | Name | Description
|
| 724 |
+
| 31 | `noirq` | Set when there is no external interrupt which is enabled, pending, and has sufficient priority. Can be efficiently tested with a `bltz` or `bgez` instruction.
|
| 725 |
+
| 30:11 | - | RES0
|
| 726 |
+
| 10:2 | `irq` | Index of the highest-priority active external interrupt. Zero when no external interrupts with sufficient priority are both pending and enabled.
|
| 727 |
+
| 1 | - | RES0
|
| 728 |
+
| 0 | `update` | Writing 1 (self-clearing) causes hardware to update `h3.meicontext` according to the IRQ number and preemption priority of the interrupt indicated in `noirq`/`irq`. This should be done in a single atomic operation, i.e. `csrrsi a0, meinext, 0x1`.
|
| 729 |
+
|===
|
| 730 |
+
|
| 731 |
+
[[reg-h3.meicontext]]
|
| 732 |
+
==== h3.meicontext
|
| 733 |
+
|
| 734 |
+
Address: `0xbe5`
|
| 735 |
+
|
| 736 |
+
External interrupt context register. Configures the priority level for interrupt preemption, and helps software track which interrupt it is currently in. The latter is useful when a common interrupt service routine handles interrupt requests from multiple instances of the same peripheral.
|
| 737 |
+
|
| 738 |
+
A three-level stack of preemption priorities is maintained in the `preempt`, `ppreempt` and `pppreempt` fields. The priority stack is saved when hardware enters the external interrupt vector, and restored by an `mret` instruction if `h3.meicontext.mreteirq` is set.
|
| 739 |
+
|
| 740 |
+
The top entry of the priority stack, `preempt`, is used by hardware to ensure that only higher-priority interrupts can preempt the current interrupt. The next entry, `ppreempt`, is used to avoid servicing interrupts which may already be in progress in a frame that was preempted. The third entry, `pppreempt`, has no hardware effect, but ensures that `preempt` and `ppreempt` can be correctly saved/restored across arbitrary levels of preemption.
|
| 741 |
+
|
| 742 |
+
[cols="10h,20h,~", options="header"]
|
| 743 |
+
|===
|
| 744 |
+
| Bits | Name | Description
|
| 745 |
+
| 31:28 | `pppreempt` | Previous `ppreempt`. Set to `ppreempt` on priority save, set to zero on priority restore. Has no hardware effect, but ensures that when `h3.meicontext` is saved/restored correctly, `preempt` and `ppreempt` stack correctly through arbitrarily many preemption frames.
|
| 746 |
+
| 27:24 | `ppreempt` | Previous `preempt`. Set to `preempt` on priority save, restored to to `pppreempt` on priority restore.
|
| 747 |
+
|
| 748 |
+
IRQs of lower priority than `ppreempt` are not visible in `h3.meinext`, so that a preemptee is not re-taken in the preempting frame.
|
| 749 |
+
| 23:21 | - | RES0
|
| 750 |
+
| 20:16 | `preempt` | Minimum interrupt priority to preempt the current interrupt. Interrupts with lower priority than `preempt` do not cause the core to transfer to an interrupt handler. Updated by hardware when when `h3.meinext.update` is written, or when hardware enters the external interrupt vector.
|
| 751 |
+
|
| 752 |
+
If an interrupt is present in `h3.meinext`, then `preempt` is set to one level greater than that interrupt's priority. Otherwise, `preempt` is set to one level greater than the maximum interrupt priority, disabling preemption.
|
| 753 |
+
| 15 | `noirq` | Not in interrupt (read/write). Set to 1 at reset. Set to `h3.meinext.noirq` when `h3.meinext.update` is written. No hardware effect.
|
| 754 |
+
| 14:13 | - | RES0
|
| 755 |
+
| 12:4 | `irq` | Current IRQ number (read/write). Set to `h3.meinext.irq` when `h3.meinext.update` is written.
|
| 756 |
+
| 3 | `mtiesave` | Reads as the current value of `mie.mtie`, if `clearts` is set. Otherwise reads as 0. Writes are ORed into `mie.mtie`.
|
| 757 |
+
| 2 | `msiesave` | Reads as the current value of `mie.msie`, if `clearts` is set. Otherwise reads as 0. Writes are ORed into `mie.msie`.
|
| 758 |
+
| 1 | `clearts` | Write-1 self-clearing field. Writing 1 will clear `mie.mtie` and `mie.msie`, and present their prior values in the `mtiesave` and `msiesave` of this register. This makes it safe to re-enable IRQs (via `mstatus.mie`) without the possibility of being preempted by the standard timer and soft interrupt handlers, which may not be aware of Hazard3's interrupt hardware.
|
| 759 |
+
|
| 760 |
+
The clear due to `clearts` takes precedence over the set due to `mtiesave`/`msiesave`, although it would be unusual for software to write both on the same cycle.
|
| 761 |
+
| 0 | `mreteirq` | Enable restore of the preemption priority stack on `mret`. This bit is set on entering the external interrupt vector, cleared by `mret`, and cleared upon taking any trap other than an external interrupt.
|
| 762 |
+
|
| 763 |
+
Provided `h3.meicontext` is saved on entry to the external interrupt vector (before enabling preemption), is restored before exiting, and the standard software/timer IRQs are prevented from preempting (e.g. by using `clearts`), this flag allows the hardware to safely manage the preemption priority stack even when an external interrupt handler may take exceptions.
|
| 764 |
+
|===
|
| 765 |
+
|
| 766 |
+
The following is an example of an external interrupt vector (`mip.meip`) which implements nested, prioritised interrupt dispatch using `h3.meicontext` and `h3.meinext`:
|
| 767 |
+
|
| 768 |
+
----
|
| 769 |
+
isr_external_irq:
|
| 770 |
+
// Save caller saves and exception return state whilst IRQs are disabled.
|
| 771 |
+
// We can't be preempted during this time, but if a higher-priority IRQ
|
| 772 |
+
// arrives ("late arrival"), that will be the one displayed in h3.meinext.
|
| 773 |
+
addi sp, sp, -80
|
| 774 |
+
sw ra, 0(sp)
|
| 775 |
+
... snip
|
| 776 |
+
sw t6, 60(sp)
|
| 777 |
+
|
| 778 |
+
csrr a0, mepc
|
| 779 |
+
sw a0, 64(sp)
|
| 780 |
+
// Set bit 1 when reading to clear+save mie.mtie and mie.msie
|
| 781 |
+
csrrsi a0, h3.meicontext, 0x2
|
| 782 |
+
sw a0, 68(sp)
|
| 783 |
+
csrr a0, mstatus
|
| 784 |
+
sw a0, 72(sp)
|
| 785 |
+
|
| 786 |
+
j get_next_irq
|
| 787 |
+
|
| 788 |
+
dispatch_irq:
|
| 789 |
+
// Preemption priority was configured by h3.meinext update, so enable preemption:
|
| 790 |
+
csrsi mstatus, 0x8
|
| 791 |
+
// h3.meinext is pre-shifted by 2, so only an add is required to index table
|
| 792 |
+
la a1, _external_irq_table
|
| 793 |
+
add a1, a1, a0
|
| 794 |
+
jalr ra, a1
|
| 795 |
+
|
| 796 |
+
// Disable IRQs on returning so we can sample the next IRQ
|
| 797 |
+
csrci mstatus, 0x8
|
| 798 |
+
|
| 799 |
+
get_next_irq:
|
| 800 |
+
// Sample the current highest-priority active IRQ (left-shifted by 2) from
|
| 801 |
+
// h3.meinext, and write 1 to the LSB to tell hardware to tell hw to update
|
| 802 |
+
// h3.meicontext with the preemption priority (and IRQ number) of this IRQ
|
| 803 |
+
csrrsi a0, h3.meinext, 0x1
|
| 804 |
+
// MSB will be set if there is no active IRQ at the current priority level
|
| 805 |
+
bgez a0, dispatch_irq
|
| 806 |
+
|
| 807 |
+
no_more_irqs:
|
| 808 |
+
// Restore saved context and return from handler
|
| 809 |
+
lw a0, 64(sp)
|
| 810 |
+
csrw mepc, a0
|
| 811 |
+
lw a0, 68(sp)
|
| 812 |
+
csrw h3.meicontext, a0
|
| 813 |
+
lw a0, 72(sp)
|
| 814 |
+
csrw mstatus, a0
|
| 815 |
+
|
| 816 |
+
lw ra, 0(sp)
|
| 817 |
+
... snip
|
| 818 |
+
lw t6, 60(sp)
|
| 819 |
+
addi sp, sp, 80
|
| 820 |
+
mret
|
| 821 |
+
----
|
| 822 |
+
|
| 823 |
+
=== Custom Memory Protection CSRs
|
| 824 |
+
|
| 825 |
+
[[reg-h3.pmpcfgm0]]
|
| 826 |
+
==== h3.pmpcfgm0
|
| 827 |
+
|
| 828 |
+
Address: 0xbd0
|
| 829 |
+
|
| 830 |
+
PMP M-mode configuration. One bit per PMP region. Setting a bit makes the corresponding region apply to M-mode (like the `pmpcfg.L` bit) but does not lock the region.
|
| 831 |
+
|
| 832 |
+
PMP is useful for non-security-related purposes, such as stack guarding and peripheral emulation. This extension allows M-mode to freely use any currently unlocked regions for its own purposes, without the inconvenience of having to lock them.
|
| 833 |
+
|
| 834 |
+
Note that this does not grant any new capabilities to M-mode, since in the base standard it is already possible to apply unlocked regions to M-mode by locking them. In general, PMP regions should be locked in ascending region number order so they can't be subsequently overridden by currently unlocked regions.
|
| 835 |
+
|
| 836 |
+
Note also that this is not the same as the "rule locking bypass" bit in the ePMP extension, which does not permit locked and unlocked M-mode regions to coexist.
|
| 837 |
+
|
| 838 |
+
[cols="10h,20h,~", options="header"]
|
| 839 |
+
|===
|
| 840 |
+
| Bits | Name | Description
|
| 841 |
+
| 31:16 | - | RES0
|
| 842 |
+
| 15:0 | `m` | Regions apply to M-mode if this bit _or_ the corresponding `pmpcfg.L` bit is set. Regions are locked if and only if the corresponding `pmpcfg.L` bit is set.
|
| 843 |
+
|===
|
| 844 |
+
|
| 845 |
+
=== Custom Power Control CSRs
|
| 846 |
+
|
| 847 |
+
[[reg-h3.msleep]]
|
| 848 |
+
==== h3.msleep
|
| 849 |
+
|
| 850 |
+
Address: `0xbf0`
|
| 851 |
+
|
| 852 |
+
M-mode sleep control register. Resets to all-zeroes.
|
| 853 |
+
|
| 854 |
+
[cols="10h,20h,~", options="header"]
|
| 855 |
+
|===
|
| 856 |
+
| Bits | Name | Description
|
| 857 |
+
| 31:3 | - | RES0
|
| 858 |
+
| 2 | `sleeponblock` | Enter the deep sleep state on a `h3.block` instruction as well as a standard `wfi`. If this bit is clear, a `h3.block` is always implemented as a simple pipeline stall.
|
| 859 |
+
| 1 | `powerdown` | Release the external power request when going to sleep. The function of this is platform-defined -- it may do nothing, it may do something simple like clock-gating the fabric, or it may be tied to some complex system-level power controller.
|
| 860 |
+
|
| 861 |
+
When waking, the processor reasserts its external power-up request, and will not fetch any instructions until the request is acknowledged. This may add considerable latency to the wakeup.
|
| 862 |
+
| 0 | `deepsleep` | Deassert the processor clock enable when entering the sleep state. If a clock gate is instantiated, this allows most of the processor (everything except the power state machine and the interrupt and halt input registers) to be clock gated whilst asleep, which may reduce the sleep current. This adds one cycle to the wakeup latency.
|
| 863 |
+
|===
|
| 864 |
+
|
| 865 |
+
=== Custom Identification CSRs
|
| 866 |
+
|
| 867 |
+
[[reg-h3.misa]]
|
| 868 |
+
==== h3.misa
|
| 869 |
+
|
| 870 |
+
Address: `0xbf1`
|
| 871 |
+
|
| 872 |
+
M-mode ISA identification register.
|
| 873 |
+
|
| 874 |
+
The `h3.misa` register provides a simple list of which standard RISC-V ISA extensions are supported. It is conceptually similar to the standard <<reg-misa>> register, but stores a larger bit array, sufficient to enumerate all standard extensions. This register comprises the entirety of the Xh3misa extension, as described in <<extension-xh3misa-section>>.
|
| 875 |
+
|
| 876 |
+
The bit assignment is provided by the RISC-V C API documentation here: https://github.com/riscv-non-isa/riscv-c-api-doc/blob/main/src/c-api.adoc#extension-bitmask-definitions[https://github.com/riscv-non-isa/riscv-c-api-doc/blob/main/src/c-api.adoc#extension-bitmask-definitions]. The latest assignment can always be found in the upstream documentation, but at time of writing the following bits are assigned:
|
| 877 |
+
|
| 878 |
+
[%autowidth,options="header"]
|
| 879 |
+
|====
|
| 880 |
+
| Extension | groupid | bit position
|
| 881 |
+
| A | 0 | 0
|
| 882 |
+
| B | 0 | 1
|
| 883 |
+
| C | 0 | 2
|
| 884 |
+
| D | 0 | 3
|
| 885 |
+
| E | 0 | 4
|
| 886 |
+
| F | 0 | 5
|
| 887 |
+
| H | 0 | 7
|
| 888 |
+
| I | 0 | 8
|
| 889 |
+
| M | 0 | 12
|
| 890 |
+
| Q | 0 | 16
|
| 891 |
+
| V | 0 | 21
|
| 892 |
+
| Zacas | 0 | 26
|
| 893 |
+
| Zba | 0 | 27
|
| 894 |
+
| Zbb | 0 | 28
|
| 895 |
+
| Zbc | 0 | 29
|
| 896 |
+
| Zbkb | 0 | 30
|
| 897 |
+
| Zbkc | 0 | 31
|
| 898 |
+
| Zbkx | 0 | 32
|
| 899 |
+
| Zbs | 0 | 33
|
| 900 |
+
| Zfa | 0 | 34
|
| 901 |
+
| Zfh | 0 | 35
|
| 902 |
+
| Zfhmin | 0 | 36
|
| 903 |
+
| Zicboz | 0 | 37
|
| 904 |
+
| Zicond | 0 | 38
|
| 905 |
+
| Zihintntl | 0 | 39
|
| 906 |
+
| Zihintpause | 0 | 40
|
| 907 |
+
| Zknd | 0 | 41
|
| 908 |
+
| Zkne | 0 | 42
|
| 909 |
+
| Zknh | 0 | 43
|
| 910 |
+
| Zksed | 0 | 44
|
| 911 |
+
| Zksh | 0 | 45
|
| 912 |
+
| Zkt | 0 | 46
|
| 913 |
+
| Ztso | 0 | 47
|
| 914 |
+
| Zvbb | 0 | 48
|
| 915 |
+
| Zvbc | 0 | 49
|
| 916 |
+
| Zvfh | 0 | 50
|
| 917 |
+
| Zvfhmin | 0 | 51
|
| 918 |
+
| Zvkb | 0 | 52
|
| 919 |
+
| Zvkg | 0 | 53
|
| 920 |
+
| Zvkned | 0 | 54
|
| 921 |
+
| Zvknha | 0 | 55
|
| 922 |
+
| Zvknhb | 0 | 56
|
| 923 |
+
| Zvksed | 0 | 57
|
| 924 |
+
| Zvksh | 0 | 58
|
| 925 |
+
| Zvkt | 0 | 59
|
| 926 |
+
| Zve32x | 0 | 60
|
| 927 |
+
| Zve32f | 0 | 61
|
| 928 |
+
| Zve64x | 0 | 62
|
| 929 |
+
| Zve64f | 0 | 63
|
| 930 |
+
| Zve64d | 1 | 0
|
| 931 |
+
| Zimop | 1 | 1
|
| 932 |
+
| Zca | 1 | 2
|
| 933 |
+
| Zcb | 1 | 3
|
| 934 |
+
| Zcd | 1 | 4
|
| 935 |
+
| Zcf | 1 | 5
|
| 936 |
+
| Zcmop | 1 | 6
|
| 937 |
+
| Zawrs | 1 | 7
|
| 938 |
+
| Zilsd | 1 | 8
|
| 939 |
+
| Zclsd | 1 | 9
|
| 940 |
+
| Zcmp | 1 | 10
|
| 941 |
+
| Zifencei | 1 | 11
|
| 942 |
+
| Zmmul | 1 | 12
|
| 943 |
+
|====
|
| 944 |
+
|
| 945 |
+
The bit index within the `h3.misa` bitmap can be calculated as `64 * groupid + bit position`. A read from <<reg-h3.misa>> returns a 32-bit slice of the bitmap, indexed by the write data of the same CSR instruction. For example, Zcmp is at bit index 74, which is bit 10 of word 2.
|
| 946 |
+
|
| 947 |
+
----
|
| 948 |
+
// Get bits 95:64 of the ISA bitmap:
|
| 949 |
+
csrrwi a0, h3.misa, 2
|
| 950 |
+
// Get bit 10 of the result:
|
| 951 |
+
bexti a0, a0, 10
|
| 952 |
+
// a0 is 1 if Zcmp is supported.
|
| 953 |
+
----
|
| 954 |
+
|
| 955 |
+
The implementation is not required to decode all bits of the index. The length of the bitmap can be checked by reading from the special index `0x400`. Software should ignore data from bit indices higher than the indicated bitmap length.
|
| 956 |
+
|
| 957 |
+
The following is an example of testing for an extension based on the `groupid` and `bit_position` from the RISC-V C API documentation:
|
| 958 |
+
|
| 959 |
+
----
|
| 960 |
+
uint32_t h3_misa_read(uint32_t index) {
|
| 961 |
+
uint32_t ret;
|
| 962 |
+
asm (
|
| 963 |
+
"csrrw %0, 0xbf1, %1\n"
|
| 964 |
+
: "=r" (ret)
|
| 965 |
+
: "r" (index)
|
| 966 |
+
);
|
| 967 |
+
return ret;
|
| 968 |
+
}
|
| 969 |
+
|
| 970 |
+
bool h3_misa_extension_supported(unsigned int groupid, unsigned int bit_position) {
|
| 971 |
+
unsigned int index = groupid * 64u + bit_position;
|
| 972 |
+
if (index >= h3_misa_read(0x400u)) {
|
| 973 |
+
return false;
|
| 974 |
+
}
|
| 975 |
+
return h3_misa_read(index >> 5) & (1u << (index & 0x1f));
|
| 976 |
+
}
|
| 977 |
+
----
|
| 978 |
+
|
| 979 |
+
Index `0x401` contains the length in _words_ of the custom extension listing, which starts from index `0x500`.
|
| 980 |
+
|
| 981 |
+
Indices `0x500` onward contain versions of custom Hazard3 extensions:
|
| 982 |
+
|
| 983 |
+
[options="header"]
|
| 984 |
+
|===
|
| 985 |
+
| Word index | Extension
|
| 986 |
+
| `0x500` | Xh3misa
|
| 987 |
+
| `0x501` | Xh3irq
|
| 988 |
+
| `0x502` | Xh3pmpm
|
| 989 |
+
| `0x503` | Xh3power
|
| 990 |
+
| `0x504` | Xh3bextm
|
| 991 |
+
|===
|
| 992 |
+
|
| 993 |
+
The custom extension entries have the same `major.minor.patch` format as <<reg-mimpid>>:
|
| 994 |
+
|
| 995 |
+
[cols="10h,20h,~", options="header"]
|
| 996 |
+
|===
|
| 997 |
+
| Bits | Name | Description
|
| 998 |
+
| 31:28 | - | RES0
|
| 999 |
+
| 27:24 | `major` | Major release version, i.e. the `1` in `v1.2.3`
|
| 1000 |
+
| 23:16 | `minor` | Minor release version, i.e. the `2` in `v1.2.3`
|
| 1001 |
+
| 15:8 | `patch` | Patch version, i.e. the `3` in `v1.2.3`
|
| 1002 |
+
| 7:0 | - | RES0
|
| 1003 |
+
|===
|
| 1004 |
+
|
| 1005 |
+
|
| 1006 |
+
A value of all-zeroes indicates the custom extension is not implemented.
|
| 1007 |
+
|
| 1008 |
+
|
| 1009 |
+
|
Wren6991_Hazard3/doc/sections/custom_extensions.adoc
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
== Custom Extensions
|
| 2 |
+
|
| 3 |
+
Hazard3 implements a small number of custom extensions. Xh3misa is always included; the remaining custom extensions are only included if the relevant feature flags are set to `1` when instantiating the processor (<<config-parameters-section>>).
|
| 4 |
+
|
| 5 |
+
The `x` bit in <<reg-misa>> is always set, to indicate (at least) the presence of the Xh3misa extension.
|
| 6 |
+
|
| 7 |
+
[[extension-xh3misa-section]]
|
| 8 |
+
=== Xh3misa: Hazard3 ISA identification register
|
| 9 |
+
|
| 10 |
+
This document describes Xh3misa version: 1.0
|
| 11 |
+
|
| 12 |
+
This extension is enabled by: <<param-CSR_M_MANDATORY>>.
|
| 13 |
+
|
| 14 |
+
This extension adds the <<reg-h3.misa>> CSR. This is an extended version of the standard <<reg-misa>> register, capable of enumerating all standard RISC-V extensions (not just the single-letter ones).
|
| 15 |
+
|
| 16 |
+
It describes presence and absence of extensions using the bitmap format described in the RISC-V C API documentation:
|
| 17 |
+
|
| 18 |
+
https://github.com/riscv-non-isa/riscv-c-api-doc/blob/main/src/c-api.adoc#extension-bitmask-definitions[https://github.com/riscv-non-isa/riscv-c-api-doc/blob/main/src/c-api.adoc#extension-bitmask-definitions]
|
| 19 |
+
|
| 20 |
+
This register also lists the versions of any custom Hazard3 extensions which may be present, including Xh3misa itself. For more details see the description of the <<reg-h3.misa>> register.
|
| 21 |
+
|
| 22 |
+
[[extension-xh3irq-section]]
|
| 23 |
+
=== Xh3irq: Hazard3 interrupt controller
|
| 24 |
+
|
| 25 |
+
This document describes Xh3irq version: 1.0
|
| 26 |
+
|
| 27 |
+
This extension is enabled by: <<param-EXTENSION_XH3IRQ>>
|
| 28 |
+
|
| 29 |
+
This lightweight extension controls up to 512 external interrupts, with up to 16 levels of preemption. It adds no new instructions, but several CSRs:
|
| 30 |
+
|
| 31 |
+
* <<reg-h3.meiea>>
|
| 32 |
+
* <<reg-h3.meipa>>
|
| 33 |
+
* <<reg-h3.meifa>>
|
| 34 |
+
* <<reg-h3.meipra>>
|
| 35 |
+
* <<reg-h3.meinext>>
|
| 36 |
+
* <<reg-h3.meicontext>>
|
| 37 |
+
|
| 38 |
+
If this extension is disabled then Hazard3 supports a single external interrupt input (or multiple inputs that it simply ORs together in an uncontrolled fashion), so an external PLIC can be used for standard interrupt support.
|
| 39 |
+
|
| 40 |
+
Note that, besides the additional CSRs, this extension is effectively a slightly more complicated way of driving the standard `mip.meip` flag (<<reg-mip>>). The RISC-V trap handling CSRs themselves are always completely standard.
|
| 41 |
+
|
| 42 |
+
[[extension-xh3pmpm-section]]
|
| 43 |
+
=== Xh3pmpm: M-mode PMP regions
|
| 44 |
+
|
| 45 |
+
This document describes Xh3pmpm version: 1.0
|
| 46 |
+
|
| 47 |
+
This extension is enabled by: <<param-EXTENSION_XH3PMPM>>
|
| 48 |
+
|
| 49 |
+
This extension adds a new M-mode CSR, <<reg-h3.pmpcfgm0>>, which allows a PMP region to be enforced in M-mode without locking the region.
|
| 50 |
+
|
| 51 |
+
This is useful when the PMP is used for non-security-related purposes such as stack guarding, or trapping and emulation of peripheral accesses.
|
| 52 |
+
|
| 53 |
+
[[extension-xh3power-section]]
|
| 54 |
+
=== Xh3power: Hazard3 power management
|
| 55 |
+
|
| 56 |
+
This document describes Xh3power version: 1.0
|
| 57 |
+
|
| 58 |
+
This extension is enabled by: <<param-EXTENSION_XH3POWER>>
|
| 59 |
+
|
| 60 |
+
This extension adds a new M-mode CSR (<<reg-h3.msleep>>), and two new hint instructions, `h3.block` and `h3.unblock`, in the `slt` nop-compatible custom hint space.
|
| 61 |
+
|
| 62 |
+
The `h3.msleep` CSR controls how deeply the processor sleeps in the WFI sleep state. By default, a WFI is implemented as a normal pipeline stall. By configuring `h3.msleep` appropriately, the processor can gate its own clock when asleep or, with a simple 4-phase req/ack handshake, negotiate with an external power controller for power up/down of external hardware. These options can improve the sleep current at the cost of greater wakeup latency.
|
| 63 |
+
|
| 64 |
+
The hints allow processors to sleep until woken by other processors in a multiprocessor environment. They are implemented on top of the standard WFI state, which means they interact in the same way with external debug, and benefit from the same deep sleep states in `h3.msleep`.
|
| 65 |
+
|
| 66 |
+
==== h3.block
|
| 67 |
+
|
| 68 |
+
Enter a WFI sleep state until either an unblock signal is received, or an interrupt is asserted that would cause a WFI to exit.
|
| 69 |
+
|
| 70 |
+
If `mstatus.tw` is set, attempting to execute this instruction in privilege modes lower than M-mode will generate an illegal instruction exception.
|
| 71 |
+
|
| 72 |
+
If an unblock signal has been received in the time since the last `h3.block`, this instruction executes as a `nop`, and the processor does not enter the sleep state. Conceptually, the sleep state falls through immediately because the corresponding unblock signal has already been received.
|
| 73 |
+
|
| 74 |
+
An unblock signal is received when a neighbouring processor (the exact definition of "neighbouring" being left to the implementer) executes an `h3.unblock` instruction, or for some other platform-defined reason.
|
| 75 |
+
|
| 76 |
+
This instruction is encoded as `slt x0, x0, x0`, which is part of the custom nop-compatible hint encoding space.
|
| 77 |
+
|
| 78 |
+
Example C macro:
|
| 79 |
+
|
| 80 |
+
----
|
| 81 |
+
#define __h3_block() asm ("slt x0, x0, x0")
|
| 82 |
+
----
|
| 83 |
+
|
| 84 |
+
Example assembly macro:
|
| 85 |
+
|
| 86 |
+
----
|
| 87 |
+
.macro h3.block
|
| 88 |
+
slt x0, x0, x0
|
| 89 |
+
.endm
|
| 90 |
+
----
|
| 91 |
+
|
| 92 |
+
==== h3.unblock
|
| 93 |
+
|
| 94 |
+
Post an unblock signal to other processors in the system. For example, to notify another processor that a work queue is now nonempty.
|
| 95 |
+
|
| 96 |
+
If `mstatus.tw` is set, attempting to execute this instruction in privilege modes lower than M-mode will generate an illegal instruction exception.
|
| 97 |
+
|
| 98 |
+
This instruction is encoded as `slt x0, x0, x1`, which is part of the custom nop-compatible hint encoding space.
|
| 99 |
+
|
| 100 |
+
Example C macro:
|
| 101 |
+
|
| 102 |
+
----
|
| 103 |
+
#define __h3_unblock() asm ("slt x0, x0, x1")
|
| 104 |
+
----
|
| 105 |
+
|
| 106 |
+
Example assembly macro:
|
| 107 |
+
|
| 108 |
+
----
|
| 109 |
+
.macro h3.unblock
|
| 110 |
+
slt x0, x0, x1
|
| 111 |
+
.endm
|
| 112 |
+
----
|
| 113 |
+
|
| 114 |
+
[[extension-xh3bextm-section]]
|
| 115 |
+
=== Xh3bextm: Hazard3 bit extract multiple
|
| 116 |
+
|
| 117 |
+
This document describes Xh3bextm version: 1.0
|
| 118 |
+
|
| 119 |
+
This extension is enabled by: <<param-EXTENSION_XH3BEXTM>>
|
| 120 |
+
|
| 121 |
+
This is a small extension with multi-bit versions of the "bit extract" instructions from Zbs, used for extracting small, contiguous bit fields.
|
| 122 |
+
|
| 123 |
+
==== h3.bextm
|
| 124 |
+
|
| 125 |
+
"Bit extract multiple", a multi-bit version of the `bext` instruction from Zbs. Perform a right-shift followed by a mask of 1-8 LSBs.
|
| 126 |
+
|
| 127 |
+
Encoding (R-type):
|
| 128 |
+
|
| 129 |
+
[cols="10h,20h,20h,~", options="header"]
|
| 130 |
+
|===
|
| 131 |
+
| Bits | Name | Value | Description
|
| 132 |
+
| 31:29 | `funct7[6:4]` | `0b000` | RES0
|
| 133 |
+
| 28:26 | `size` | - | Number of ones in mask, values 0->7 encode 1->8 bits.
|
| 134 |
+
| 25 | `funct7[0]` | `0b0` | RES0, because aligns with `shamt[5]` of potential RV64 version of `h3.bextmi`
|
| 135 |
+
| 24:20 | `rs2` | - | Source register 2 (shift amount)
|
| 136 |
+
| 19:15 | `rs1` | - | Source register 1
|
| 137 |
+
| 14:12 | `funct3` | `0b000` | `h3.bextm`
|
| 138 |
+
| 11:7 | `rd` | - | Destination register
|
| 139 |
+
| 6:2 | `opc` | `0b00010`| custom0 opcode
|
| 140 |
+
| 1:0 | `size` | `0b11` | 32-bit instruction
|
| 141 |
+
|===
|
| 142 |
+
|
| 143 |
+
Example C macro (using GCC statement expressions):
|
| 144 |
+
|
| 145 |
+
----
|
| 146 |
+
// nbits must be a constant expression
|
| 147 |
+
#define __h3_bextm(nbits, rs1, rs2) ({\
|
| 148 |
+
uint32_t __h3_bextm_rd; \
|
| 149 |
+
asm (".insn r 0x0b, 0, %3, %0, %1, %2"\
|
| 150 |
+
: "=r" (__h3_bextm_rd) \
|
| 151 |
+
: "r" (rs1), "r" (rs2), "i" ((((nbits) - 1) & 0x7) << 1)\
|
| 152 |
+
); \
|
| 153 |
+
__h3_bextm_rd; \
|
| 154 |
+
})
|
| 155 |
+
----
|
| 156 |
+
|
| 157 |
+
Example assembly macro:
|
| 158 |
+
|
| 159 |
+
----
|
| 160 |
+
// rd = (rs1 >> rs2[4:0]) & ~(-1 << nbits)
|
| 161 |
+
.macro h3.bextm rd rs1 rs2 nbits
|
| 162 |
+
.if (\nbits < 1) || (\nbits > 8)
|
| 163 |
+
.err
|
| 164 |
+
.endif
|
| 165 |
+
#if NO_HAZARD3_CUSTOM
|
| 166 |
+
srl \rd, \rs1, \rs2
|
| 167 |
+
andi \rd, \rd, ((1 << \nbits) - 1)
|
| 168 |
+
#else
|
| 169 |
+
.insn r 0x0b, 0x0, (((\nbits - 1) & 0x7 ) << 1), \rd, \rs1, \rs2
|
| 170 |
+
#endif
|
| 171 |
+
.endm
|
| 172 |
+
----
|
| 173 |
+
|
| 174 |
+
==== h3.bextmi
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
Immediate variant of `h3.bextm`.
|
| 178 |
+
|
| 179 |
+
Encoding (I-type):
|
| 180 |
+
|
| 181 |
+
[cols="10h,20h,20h,~", options="header"]
|
| 182 |
+
|===
|
| 183 |
+
| Bits | Name | Value | Description
|
| 184 |
+
| 31:29 | `imm[11:9]` | `0b000` | RES0
|
| 185 |
+
| 28:26 | `size` | - | Number of ones in mask, values 0->7 encode 1->8 bits.
|
| 186 |
+
| 25 | `imm[5]` | `0b0` | RES0, for potential future RV64 version
|
| 187 |
+
| 24:20 | `shamt` | - | Shift amount, 0 through 31
|
| 188 |
+
| 19:15 | `rs1` | - | Source register 1
|
| 189 |
+
| 14:12 | `funct3` | `0b100` | `h3.bextmi`
|
| 190 |
+
| 11:7 | `rd` | - | Destination register
|
| 191 |
+
| 6:2 | `opc` | `0b00010`| custom0 opcode
|
| 192 |
+
| 1:0 | `size` | `0b11` | 32-bit instruction
|
| 193 |
+
|===
|
| 194 |
+
|
| 195 |
+
Example C macro (using GCC statement expressions):
|
| 196 |
+
|
| 197 |
+
----
|
| 198 |
+
// nbits and shamt must be constant expressions
|
| 199 |
+
#define __h3_bextmi(nbits, rs1, shamt) ({\
|
| 200 |
+
uint32_t __h3_bextmi_rd; \
|
| 201 |
+
asm (".insn i 0x0b, 0x4, %0, %1, %2"\
|
| 202 |
+
: "=r" (__h3_bextmi_rd) \
|
| 203 |
+
: "r" (rs1), "i" ((((nbits) - 1) & 0x7) << 6 | ((shamt) & 0x1f)) \
|
| 204 |
+
); \
|
| 205 |
+
__h3_bextmi_rd; \
|
| 206 |
+
})
|
| 207 |
+
----
|
| 208 |
+
|
| 209 |
+
Example assembly macro:
|
| 210 |
+
|
| 211 |
+
----
|
| 212 |
+
// rd = (rs1 >> shamt) & ~(-1 << nbits)
|
| 213 |
+
.macro h3.bextmi rd rs1 shamt nbits
|
| 214 |
+
.if (\nbits < 1) || (\nbits > 8)
|
| 215 |
+
.err
|
| 216 |
+
.endif
|
| 217 |
+
.if (\shamt < 0) || (\shamt > 31)
|
| 218 |
+
.err
|
| 219 |
+
.endif
|
| 220 |
+
#if NO_HAZARD3_CUSTOM
|
| 221 |
+
srli \rd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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
== Debug
|
| 2 |
+
|
| 3 |
+
Hazard3 implements version 0.13.2 of the RISC-V debug specification, including:
|
| 4 |
+
|
| 5 |
+
* Run/halt/reset control (including halt-on-reset for each hart)
|
| 6 |
+
* Abstract GPR access
|
| 7 |
+
* Program Buffer: 2 words plus `impebreak`
|
| 8 |
+
* Automatic trigger of abstract command (`abstractauto`) on `data0` or Program Buffer access for efficient memory block transfers from the host
|
| 9 |
+
* Support for multiple harts (multiple Hazard3 cores) connected to a single Debug Module (DM)
|
| 10 |
+
* The hart array mask registers, for applying run/halt/reset controls to multiple cores simultaneously
|
| 11 |
+
* (Optional) System Bus Access, either through a dedicated AHB5 manager interface, or multiplexed with a processor load/store port
|
| 12 |
+
* A trigger unit with exception, interrupt and instruction count triggers
|
| 13 |
+
** Exception and interrupt triggers are hardwired with `action` = `1` (break to Debug mode only)
|
| 14 |
+
** Instruction count trigger is hardwired with `action` = `0` and `count` = `1` (provides single-stepping of U-mode or M-mode from an M-mode exception handler)
|
| 15 |
+
** The `tcontrol.mte` and `mpte` bits prevent trigger loops under M-mode trigger usage
|
| 16 |
+
* (Optional) Instruction address match triggers (hardware breakpoints)
|
| 17 |
+
** Usable from both Debug mode and M-mode
|
| 18 |
+
|
| 19 |
+
=== Debug Topologies
|
| 20 |
+
|
| 21 |
+
Hazard3's Debug Module (DM) has the following interfaces:
|
| 22 |
+
|
| 23 |
+
* An upstream AMBA 3 APB port -- the "Debug Module Interface" -- for host access to the Debug Module
|
| 24 |
+
* A downstream Hazard3-specific interface to one or more cores
|
| 25 |
+
* Some reset request/acknowledge signals which require careful handshaking with system-level reset logic
|
| 26 |
+
|
| 27 |
+
This is shown in the example topology below.
|
| 28 |
+
|
| 29 |
+
image::diagrams/debug_topology.png[pdfwidth=50%, width=50%]
|
| 30 |
+
|
| 31 |
+
The DM is implemented by the `hazard3_dm` module, found in https://github.com/Wren6991/Hazard3/blob/stable/hdl/debug/dm/hazard3_dm.v[hdl/debug/dm/hazard3_dm.v]. The DM _must_ be connected directly to the processors without intervening registers. This implies the DM is in the same clock domain as the processors, so multiple processors on the same DM must share a common clock.
|
| 32 |
+
|
| 33 |
+
Upstream of the DM is at least one Debug Transport Module, which bridges some host-facing interface such as JTAG to the APB DM Interface. Hazard3 provides an implementation of a standard RISC-V JTAG-DTM, but any APB manager could be used. The DM requires at least 7 bits of word addressing, i.e. 9 bits of byte address space. The top-level module for Hazard3's JTAG-DTM implementation is `hazard3_jtag_dtm`, found in https://github.com/Wren6991/Hazard3/blob/stable/hdl/debug/dtm/hazard3_jtag_dtm.v[hdl/debug/dtm/hazard3_jtag_dtm.v].
|
| 34 |
+
|
| 35 |
+
An APB arbiter could be inserted here, to allow multiple transports to be used, provided the host(s) avoid using multiple transports concurrently. This also admits simple implementation of self-hosted debug, by mapping the DM to a system-level peripheral address space.
|
| 36 |
+
|
| 37 |
+
The clock domain crossing (if any) occurs on the downstream port of the Debug Transport Module. Hazard3's JTAG-DTM implementation runs entirely in the TCK domain, and instantiates a bus clock-crossing module internally to bridge a TCK-domain internal APB bus to an external bus in the processor clock domain.
|
| 38 |
+
|
| 39 |
+
It is possible to instantiate multiple DMs, one per core, and attach them to a single Debug Transport Module. This is not the preferred topology, but it does allow multiple cores to be independently clocked. In this case, the first DM must be located at address `0x0` in the DMI address space, and you must set the `NEXT_DM_ADDR` parameter on each DM so that the debugger can walk the (null-terminated) linked list and discover all the DMs.
|
| 40 |
+
|
| 41 |
+
[[section-trigger-module]]
|
| 42 |
+
=== Trigger Module
|
| 43 |
+
|
| 44 |
+
Hazard3's Trigger Module generates synchronous traps to either Debug Mode or M-mode when certain pre-programmed conditions are met. It support four types of trigger: instruction address (breakpoint), interrupt, exception, and instruction count. The number of instruction address match triggers is configurable, and the remaining trigger types have one instance each.
|
| 45 |
+
|
| 46 |
+
Use the following CSRs to configure individual triggers:
|
| 47 |
+
|
| 48 |
+
* <<reg-tselect>>: Choose a trigger to configure. Implements exactly enough bits to index all implemented triggers; remaining bits are hardwired to 0
|
| 49 |
+
* <<reg-tinfo>>: List the capabilities of the currently selected trigger (the supported values for `tdata1.type`)
|
| 50 |
+
* <<reg-tdata1>>: Configure the trigger. Layout changes based on the value of `tdata1.type`
|
| 51 |
+
* <<reg-tdata2>>: Further configuration, or address/data to match on
|
| 52 |
+
* <<reg-tdata3>>: Supports filtering of triggers based on context -- not implemented on Hazard3, so hardwired to zero
|
| 53 |
+
|
| 54 |
+
A compliant debugger can enumerate the triggers on a particular Hazard3 implementation using the standard method: incrementing `tselect` from 0, checking `tinfo` for each `tselect` index, and terminating when `tinfo` is 0 or `tselect` wraps.
|
| 55 |
+
|
| 56 |
+
Hazard3 implements only a single trigger type for each `tselect` index. Therefore `tinfo` has only one bit set, and the `tdata1.type` field for each trigger is read-only, matching the bit set in `tinfo`.
|
| 57 |
+
|
| 58 |
+
Most of Hazard3's triggers support a programmable `action` field, which determines whether the trigger targets M-mode (`action` = `0`) or Debug Mode (`action` = `1`).
|
| 59 |
+
|
| 60 |
+
M-mode triggers generate an `ebreak` exception (`mcause` = `3`) with `mepc` pointing to the instruction which generated the trigger condition. This provides hardware support for self-hosted debuggers, such as an M-mode operating system supporting debug of U-mode applications on the same core.
|
| 61 |
+
|
| 62 |
+
Debug Mode triggers enter Debug Mode with `dpc` pointing to the instruction which generated the trigger condition. The core ceases to execute instructions autonomously, and its internals become accessible to the external debug host.
|
| 63 |
+
|
| 64 |
+
An `action` of `1` is ignored when that trigger's `tdata1.dmode` bit is clear. Only Debug Mode can modify this bit, and setting this bit prevents other modes from modifying the trigger's configuration. This effectively claims the trigger for external debugger use, and makes it unavailable to self-hosted debug software.
|
| 65 |
+
|
| 66 |
+
==== Instruction Address Triggers
|
| 67 |
+
|
| 68 |
+
The <<param-BREAKPOINT_TRIGGERS>> parameter configures the trigger unit with 0 or more hardware breakpoint comparators, assigned <<reg-tselect>> indices `0` through `BREAKPOINT_TRIGGERS - 1`. Each comparator continuously monitors the program counter for an exact match for its programmed address. When the comparator matches, the core takes a trap with `dpc` or `mepc` equal to the programmed breakpoint address.
|
| 69 |
+
|
| 70 |
+
In standard RISC-V terms, these are instruction address match triggers, with the following characteristics as described by hardwired fields in `mcontrol` (aka <<reg-tdata1>>):
|
| 71 |
+
|
| 72 |
+
* `tdata1.type` = `2`: address/data match
|
| 73 |
+
* `mcontrol.timing` = `0`: trigger fires before the instruction executes
|
| 74 |
+
* `mcontrol.select` = `0`: match on address (not data)
|
| 75 |
+
* `mcontrol.match` = `0`: match on exact address
|
| 76 |
+
* `mcontrol.store` = `load` = `0`: load/store address comparison not supported
|
| 77 |
+
|
| 78 |
+
The `mcontrol.u` and `mcontrol.m` bits are fully implemented, and determine in which privilege modes the trigger will fire.
|
| 79 |
+
|
| 80 |
+
The `mcontrol.action` field can be programmed with the value `0` or `1`, indicating a break to M-mode or D-mode respectively. D-mode breaks are taken only when `mcontrol.dmode` is set.
|
| 81 |
+
|
| 82 |
+
`tdata2` contains the address to be matched on. The LSB of this register is hardwired to zero, as the RISC-V program counter never contains odd addresses. When compressed instruction support is disabled (<<param-EXTENSION_C>> is `0`), bit `1` is also hardwired to zero.
|
| 83 |
+
|
| 84 |
+
The `mcontrol.execute` flag enables and disables the trigger (1/0).
|
| 85 |
+
|
| 86 |
+
[[section-icount-trigger]]
|
| 87 |
+
==== Instruction Count Trigger
|
| 88 |
+
|
| 89 |
+
Hazard3 implements a single instruction count trigger, assigned <<reg-tselect>> index `BREAKPOINT_TRIGGERS`. For example, if no breakpoint triggers are configured, it is accessed at `tselect` = `0`.
|
| 90 |
+
|
| 91 |
+
This trigger is hardwired with a `count` of `1`, and is intended to be a lightweight feature to support self-hosted M-mode single-stepping. Debug Mode already has this capability in the form of the `dcsr.step` flag, so the instruction count trigger supports `action` = `0` only (break to M-mode).
|
| 92 |
+
|
| 93 |
+
The following configuration bits in <<reg-tdata1>> are _not_ hardwired:
|
| 94 |
+
|
| 95 |
+
* `icount.m`: if `1`, enable the trigger in M-mode
|
| 96 |
+
* `icount.u`: if `1`, enable the trigger in U-mode (only available when the <<param-U_MODE>> parameter is `1`)
|
| 97 |
+
|
| 98 |
+
The trigger fires after one instruction successfully executes. `mepc` points to the next instruction in program order. Since `icount.count` is hardwired to `1`, hardware clears both the `m` and `u` flags after the trigger fires, to avoid repeat fires.
|
| 99 |
+
|
| 100 |
+
IMPORTANT: As a deliberate departure from the 0.13.2 specification, the trigger does not fire on exceptions, because the resulting breakpoint exception would make the original exception unrecoverable and impossible to diagnose. To handle an exception occurring during single-stepping, catch the exception directly.
|
| 101 |
+
|
| 102 |
+
To single-step a U-mode context from M-mode, set `icount.u` before returning to U-mode via `mret.` The U-mode context will trap back out after executing one instruction.
|
| 103 |
+
|
| 104 |
+
To single-step an M-mode target, clear `tcontrol.mte`, then set `tcontrol.mpte` and `icount.m` before returning to an M-mode context via `mret`. The trigger is enabled after the return completes (via `mpte` shifting to `mte`), and the core traps back to the M-mode handler after executing one instruction in the M-mode returnee. The handler executes normally, because `mte` is cleared by the trap, and `icount.m` is cleared by the trigger match.
|
| 105 |
+
|
| 106 |
+
To support the above behaviour, hardware does not clear `icount.m` or `icount.u` while `tcontrol.mte` is clear. See discussion https://github.com/riscv/riscv-debug-spec/pull/829#issuecomment-1492260861[here].
|
| 107 |
+
|
| 108 |
+
[[section-interrupt-trigger]]
|
| 109 |
+
==== Interrupt Trigger
|
| 110 |
+
|
| 111 |
+
Hazard3 implements a single interrupt trigger, assigned <<reg-tselect>> index `BREAKPOINT_TRIGGERS + 1`. For example, if no breakpoint triggers are configured, it is accessed at `tselect` = `1`.
|
| 112 |
+
|
| 113 |
+
This trigger fires on a configurable subset of the interrupt cause values listed in the <<reg-mcause>> register description. `tdata2` contains a bitmap with one bit per cause value. The break is taken after the hardware interrupt entry sequence has taken place (e.g. the setting of `mcause`), but before the first instruction in the interrupt handler executes. `dpc` points to the first instruction in the interrupt handler.
|
| 114 |
+
|
| 115 |
+
`action` is hardwired to `1` (Debug Mode entry), because all interrupts on Hazard3 target M-mode, so a breakpoint exception triggered by interrupt entry would make it impossible to return from the interrupt.
|
| 116 |
+
|
| 117 |
+
The implemented bits are `11`, `7` and `3`, corresponding to `mip.meip`, `mip.mtip` and `mip.msip` respectively.
|
| 118 |
+
|
| 119 |
+
[[section-exception-trigger]]
|
| 120 |
+
==== Exception Trigger
|
| 121 |
+
|
| 122 |
+
Hazard3 implements a single exception trigger, assigned <<reg-tselect>> index `BREAKPOINT_TRIGGERS + 2`. For example, if no breakpoint triggers are configured, it is accessed at `tselect` = `2`.
|
| 123 |
+
|
| 124 |
+
This trigger fires on a configurable subset of the exception cause values listed in the <<reg-mcause>> register description. `tdata2` contains a bitmap with one bit per cause value. The break is taken after the hardware exception entry sequence has taken place (e.g. the setting of `mcause`) but before the first instruction in the exception handler executes. `dpc` points to the first instruction in the exception handler.
|
| 125 |
+
|
| 126 |
+
`action` is hardwired to `1` (Debug Mode entry) because all exceptions on Hazard3 target M-mode, so a breakpoint exception triggered by another exception would always make the original exception unrecoverable.
|
| 127 |
+
|
| 128 |
+
Bits corresponding to causes impossible on a given Hazard3 implementation are hardwired to zero. For example, bit `0` (`mcause` = `0`, fetch alignment exception) is not implemented when <<param-EXTENSION_C>> is `1`, because there are no fetch alignment exceptions if compressed instructions are implemented.
|
| 129 |
+
|
| 130 |
+
Bit `3` (`ebreak`) is also unimplemented. To catch `ebreak` execution from an external debugger, use the `dcsr.ebreakm` and `dcsr.ebreaku` flags.
|
| 131 |
+
|
| 132 |
+
=== Implementation-defined behaviour
|
| 133 |
+
|
| 134 |
+
Features implemented by the Hazard3 Debug Module (beyond the mandatory):
|
| 135 |
+
|
| 136 |
+
* Halt-on-reset, selectable per-hart
|
| 137 |
+
* Program Buffer, size 2 words, `impebreak` = 1.
|
| 138 |
+
* A single data register (`data0`) is implemented as a per-hart CSR accessible by the DM
|
| 139 |
+
* `abstractauto` is supported on the `data0`, `progbuf0` and `progbuf1` registers
|
| 140 |
+
* Up to 32 harts selectable via `hartsel`
|
| 141 |
+
* Hart array mask selection
|
| 142 |
+
* System bus access (optional)
|
| 143 |
+
|
| 144 |
+
Not implemented:
|
| 145 |
+
|
| 146 |
+
* Abstract access memory
|
| 147 |
+
* Abstract access CSR
|
| 148 |
+
* Post-incrementing abstract access GPR
|
| 149 |
+
|
| 150 |
+
The core behaves as follows:
|
| 151 |
+
|
| 152 |
+
* Branch, `jal`, `jalr` and `auipc` are illegal in debug mode, because they observe PC: attempting to execute will halt Program Buffer execution and report an exception in `abstractcs.cmderr`
|
| 153 |
+
* The `dret` instruction is not implemented (a special purpose DM-to-core signal is used to signal resume)
|
| 154 |
+
* The `dscratch` CSRs are not implemented
|
| 155 |
+
* The DM's `data0` register is mapped into the core as a CSR, <<reg-h3.dmdata0>>, address `0xbff`.
|
| 156 |
+
** Raises an illegal instruction exception when accessed outside of Debug Mode
|
| 157 |
+
** The DM ignores attempted core writes to the CSR, unless the DM is currently executing an abstract command on that core
|
| 158 |
+
** Used by the DM to implement abstract GPR access, by injecting CSR read/write instructions
|
| 159 |
+
* `dcsr.stepie` is hardwired to `0` (no interrupts during single stepping)
|
| 160 |
+
* `dcsr.stopcount` and `dcsr.stoptime` are hardwired to `1` (no counter or internal timer increment in debug mode)
|
| 161 |
+
* `dcsr.mprven` is hardwired to `0`
|
| 162 |
+
* `dcsr.prv` supports the values `3` (M-mode) and `0` (U-mode). If U-mode support is not configured, it is hardwired to `3`.
|
| 163 |
+
|
| 164 |
+
See also <<debug-csr-section>> for more details on the core-side Debug Mode registers.
|
| 165 |
+
|
| 166 |
+
The debug host must use the Program Buffer to access CSRs and memory. This carries some overhead for individual accesses, but is efficient for bulk transfers: the `abstractauto` feature allows the DM to trigger the Program Buffer and/or a GPR transfer automatically following every `data0` access, which can be used for e.g. autoincrementing read/write memory bursts. Program Buffer read/writes can also be used as `abstractauto` triggers: this is less useful than the `data0` trigger, but takes little extra effort to implement, and can be used to read/write a large number of CSRs efficiently.
|
| 167 |
+
|
| 168 |
+
Abstract memory access is not implemented because, for bulk transfers, it offers no better throughput than Program Buffer execution with `abstractauto`. Non-bulk transfers, while slower, are still instantaneous from the perspective of the human at the other end of the wire.
|
| 169 |
+
|
| 170 |
+
The Hazard3 DM supports multi-core debug. Each core possesses exactly one hardware thread (hart) which is exposed to the debugger. The RISC-V specification does not mandate what mapping is used between the DM hart index `hartsel` and each core's `mhartid` CSR, but a 1:1 match of these values is the least likely to cause issues.
|
| 171 |
+
|
| 172 |
+
Each core's `mhartid` CSR is configured using the `mhartid_val` input port on that core. In a correctly configured system, each core must have a unique value, and one core has the value of all-zeroes.
|
| 173 |
+
|
| 174 |
+
=== Debug Module to Core Interface
|
| 175 |
+
|
| 176 |
+
The DM can inject instructions directly into the core's instruction prefetch buffer. This mechanism is used to execute the Program Buffer, or used directly by the DM, issuing hardcoded instructions to manipulate core state.
|
| 177 |
+
|
| 178 |
+
The DM's `data0` register is exposed to the core as a debug mode CSR. By issuing instructions to make the core read or write this dummy CSR, the DM can exchange data with the core. To read from a GPR `x` into `data0`, the DM issues a `csrw data0, x` instruction. Similarly `csrr x, data0` will write `data0` to that GPR. The DM always follows the CSR instruction with an `ebreak`, just like the implicit `ebreak` at the end of the Program Buffer, so that it is notified by the core when the GPR read instruction sequence completes.
|
| 179 |
+
|
Wren6991_Hazard3/doc/sections/instruction_pseudocode.adoc
ADDED
|
@@ -0,0 +1,1219 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
== Instruction Pseudocode
|
| 2 |
+
|
| 3 |
+
This section is a quick reference for the operation of the instructions supported by Hazard3, in Verilog syntax. Conventions used in this section:
|
| 4 |
+
|
| 5 |
+
* `rs1`, `rs2` and `rd` are 32-bit unsigned vector variables referring to the two register operands and the destination register
|
| 6 |
+
* `imm` is a 32-bit unsigned vector referring to the instruction's immediate value
|
| 7 |
+
* `pc` is a 32-bit unsigned vector referring to the program counter
|
| 8 |
+
* `mem` is an array of 8-bit unsigned vectors, each corresponding to a byte address in memory.
|
| 9 |
+
|
| 10 |
+
=== RV32I: Register-register
|
| 11 |
+
|
| 12 |
+
With the exception of the shift instructions, all instructions in this section have an immediate range of -2048 to 2047. Negative immediates can be useful for the bitwise operations too: for example `not rd, rs1` is a pseudo-op for `xori rd, rs1, -1`.
|
| 13 |
+
|
| 14 |
+
Shift instructions have an immediate range of 0 to 31.
|
| 15 |
+
|
| 16 |
+
==== add
|
| 17 |
+
|
| 18 |
+
Add register to register.
|
| 19 |
+
|
| 20 |
+
Syntax:
|
| 21 |
+
|
| 22 |
+
add rd, rs1, rs2
|
| 23 |
+
|
| 24 |
+
Operation:
|
| 25 |
+
|
| 26 |
+
rd = rs1 + rs2;
|
| 27 |
+
|
| 28 |
+
==== sub
|
| 29 |
+
|
| 30 |
+
Subtract register from register.
|
| 31 |
+
|
| 32 |
+
Syntax:
|
| 33 |
+
|
| 34 |
+
sub rd, rs1, rs2
|
| 35 |
+
|
| 36 |
+
Operation:
|
| 37 |
+
|
| 38 |
+
rd = rs1 - rs2;
|
| 39 |
+
|
| 40 |
+
==== slt
|
| 41 |
+
|
| 42 |
+
Set if less than (signed).
|
| 43 |
+
|
| 44 |
+
Syntax:
|
| 45 |
+
|
| 46 |
+
slt rd, rs1, rs2
|
| 47 |
+
|
| 48 |
+
Operation:
|
| 49 |
+
|
| 50 |
+
rd = $signed(rs1) < $signed(rs2);
|
| 51 |
+
|
| 52 |
+
==== sltu
|
| 53 |
+
|
| 54 |
+
Set if less than (unsigned).
|
| 55 |
+
|
| 56 |
+
Syntax:
|
| 57 |
+
|
| 58 |
+
sltu rd, rs1, rs
|
| 59 |
+
|
| 60 |
+
Operation:
|
| 61 |
+
|
| 62 |
+
rd = rs1 < rs2;
|
| 63 |
+
|
| 64 |
+
==== and
|
| 65 |
+
|
| 66 |
+
Bitwise AND.
|
| 67 |
+
|
| 68 |
+
Syntax:
|
| 69 |
+
|
| 70 |
+
and rd, rs1, rs2
|
| 71 |
+
|
| 72 |
+
Operation:
|
| 73 |
+
|
| 74 |
+
rd = rs1 & rs2;
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
==== or
|
| 78 |
+
|
| 79 |
+
Bitwise OR.
|
| 80 |
+
|
| 81 |
+
Syntax:
|
| 82 |
+
|
| 83 |
+
or rd, rs1, rs2`
|
| 84 |
+
|
| 85 |
+
Operation:
|
| 86 |
+
|
| 87 |
+
rd = rs1 | rs2;
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
==== xor
|
| 91 |
+
|
| 92 |
+
Bitwise XOR.
|
| 93 |
+
|
| 94 |
+
Syntax:
|
| 95 |
+
|
| 96 |
+
xor rd, rs1, rs2
|
| 97 |
+
|
| 98 |
+
Operation:
|
| 99 |
+
|
| 100 |
+
rd = rs1 ^ rs2;
|
| 101 |
+
|
| 102 |
+
==== sll
|
| 103 |
+
|
| 104 |
+
Shift left, logical.
|
| 105 |
+
|
| 106 |
+
Syntax:
|
| 107 |
+
|
| 108 |
+
sll rd, rs1, rs2
|
| 109 |
+
|
| 110 |
+
Operation:
|
| 111 |
+
|
| 112 |
+
rd = rs1 << rs2;
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
==== srl
|
| 116 |
+
|
| 117 |
+
Shift right, logical.
|
| 118 |
+
|
| 119 |
+
Syntax:
|
| 120 |
+
|
| 121 |
+
srl rd, rs1, rs2
|
| 122 |
+
|
| 123 |
+
Operation:
|
| 124 |
+
|
| 125 |
+
rd = rs1 >> rs2;
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
==== sra
|
| 129 |
+
|
| 130 |
+
Shift right, arithmetic.
|
| 131 |
+
|
| 132 |
+
Syntax:
|
| 133 |
+
|
| 134 |
+
sra rd, rs1, rs2
|
| 135 |
+
|
| 136 |
+
Operation:
|
| 137 |
+
|
| 138 |
+
rd = rs1 >>> rs2;
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
=== RV32I: Register-immediate
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
==== addi
|
| 145 |
+
|
| 146 |
+
Add register to immediate.
|
| 147 |
+
|
| 148 |
+
Syntax:
|
| 149 |
+
|
| 150 |
+
addi rd, rs1, imm
|
| 151 |
+
|
| 152 |
+
Operation:
|
| 153 |
+
|
| 154 |
+
rd = rs1 + imm
|
| 155 |
+
|
| 156 |
+
==== slti
|
| 157 |
+
|
| 158 |
+
Set if less than immediate (signed).
|
| 159 |
+
|
| 160 |
+
Syntax:
|
| 161 |
+
|
| 162 |
+
slti rd, rs1, imm
|
| 163 |
+
|
| 164 |
+
Operation:
|
| 165 |
+
|
| 166 |
+
rd = $signed(rs1) < $signed(imm);
|
| 167 |
+
|
| 168 |
+
==== sltiu
|
| 169 |
+
|
| 170 |
+
Set if less than immediate (unsigned).
|
| 171 |
+
|
| 172 |
+
Syntax:
|
| 173 |
+
|
| 174 |
+
sltiu rd, rs1, imm
|
| 175 |
+
|
| 176 |
+
Operation:
|
| 177 |
+
|
| 178 |
+
rd = rs1 < imm;
|
| 179 |
+
|
| 180 |
+
==== andi
|
| 181 |
+
|
| 182 |
+
Bitwise AND with immediate.
|
| 183 |
+
|
| 184 |
+
Syntax:
|
| 185 |
+
|
| 186 |
+
andi rd, rs1, imm
|
| 187 |
+
|
| 188 |
+
Operation:
|
| 189 |
+
|
| 190 |
+
rd = rs1 & imm;
|
| 191 |
+
|
| 192 |
+
==== ori
|
| 193 |
+
|
| 194 |
+
Bitwise OR with immediate.
|
| 195 |
+
|
| 196 |
+
Syntax:
|
| 197 |
+
|
| 198 |
+
ori rd, rs1, imm
|
| 199 |
+
|
| 200 |
+
Operation:
|
| 201 |
+
|
| 202 |
+
rd = rs1 \| imm;
|
| 203 |
+
|
| 204 |
+
==== xori
|
| 205 |
+
|
| 206 |
+
Bitwise XOR with immediate.
|
| 207 |
+
|
| 208 |
+
Syntax:
|
| 209 |
+
|
| 210 |
+
xori rd, rs1, imm
|
| 211 |
+
|
| 212 |
+
Operation:
|
| 213 |
+
|
| 214 |
+
rd = rs1 ^ imm;
|
| 215 |
+
|
| 216 |
+
==== slli
|
| 217 |
+
|
| 218 |
+
Shift left, logical, immediate.
|
| 219 |
+
|
| 220 |
+
Syntax:
|
| 221 |
+
|
| 222 |
+
slli rd, rs1, imm
|
| 223 |
+
|
| 224 |
+
Operation:
|
| 225 |
+
|
| 226 |
+
rd = rs1 << imm;
|
| 227 |
+
|
| 228 |
+
==== srli
|
| 229 |
+
|
| 230 |
+
Shift right, logical, immediate.
|
| 231 |
+
|
| 232 |
+
Syntax:
|
| 233 |
+
|
| 234 |
+
srli rd, rs1, imm
|
| 235 |
+
|
| 236 |
+
Operation:
|
| 237 |
+
|
| 238 |
+
rd = rs1 >> imm;
|
| 239 |
+
|
| 240 |
+
==== srai
|
| 241 |
+
|
| 242 |
+
Shift right, arithmetic, immediate.
|
| 243 |
+
|
| 244 |
+
Syntax:
|
| 245 |
+
|
| 246 |
+
srai rd, rs1, imm
|
| 247 |
+
|
| 248 |
+
Operation:
|
| 249 |
+
|
| 250 |
+
rd = rs1 >>> imm;
|
| 251 |
+
|
| 252 |
+
=== RV32I: Large immediate
|
| 253 |
+
|
| 254 |
+
==== lui
|
| 255 |
+
|
| 256 |
+
Load upper immediate.
|
| 257 |
+
|
| 258 |
+
Syntax:
|
| 259 |
+
|
| 260 |
+
lui rd, imm
|
| 261 |
+
|
| 262 |
+
Operation:
|
| 263 |
+
|
| 264 |
+
rd = imm;
|
| 265 |
+
|
| 266 |
+
(`imm` is a 20-bit value followed by 12 zeroes)
|
| 267 |
+
|
| 268 |
+
==== auipc
|
| 269 |
+
|
| 270 |
+
Add upper immediate to program counter.
|
| 271 |
+
|
| 272 |
+
Syntax:
|
| 273 |
+
|
| 274 |
+
auipc rd, imm
|
| 275 |
+
|
| 276 |
+
Operation:
|
| 277 |
+
|
| 278 |
+
rd = pc + imm;
|
| 279 |
+
|
| 280 |
+
(`imm` is a 20-bit value followed by 12 zeroes)
|
| 281 |
+
|
| 282 |
+
=== RV32I: Control transfer
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
==== jal
|
| 286 |
+
|
| 287 |
+
Jump and link.
|
| 288 |
+
|
| 289 |
+
Syntax:
|
| 290 |
+
|
| 291 |
+
jal rd, label
|
| 292 |
+
j label // rd is implicitly x0
|
| 293 |
+
|
| 294 |
+
Operation:
|
| 295 |
+
|
| 296 |
+
rd = pc + 4;
|
| 297 |
+
pc = label;
|
| 298 |
+
|
| 299 |
+
NOTE: the 16-bit variant, `c.jal`, writes `pc + 2` to `rd`, rather than `pc + 4`. The `rd` value always points to the sequentially-next instruction.
|
| 300 |
+
|
| 301 |
+
==== jalr
|
| 302 |
+
|
| 303 |
+
Jump and link, target is register.
|
| 304 |
+
|
| 305 |
+
Syntax:
|
| 306 |
+
|
| 307 |
+
jalr rd, rs1, imm // imm is implicitly 0 if omitted.
|
| 308 |
+
jr rs1, imm // rd is implicitly x0. imm is implicitly 0 if omitted.
|
| 309 |
+
ret // pseudo-op for jr ra
|
| 310 |
+
|
| 311 |
+
Operation:
|
| 312 |
+
|
| 313 |
+
rd = pc + 4;
|
| 314 |
+
pc = rs1 + imm;
|
| 315 |
+
|
| 316 |
+
NOTE: the 16-bit variant, `c.jalr`, writes `pc + 2` to `rd`, rather than `pc + 4`. The `rd` value always points to the sequentially-next instruction.
|
| 317 |
+
|
| 318 |
+
==== beq
|
| 319 |
+
|
| 320 |
+
Branch if equal.
|
| 321 |
+
|
| 322 |
+
Syntax:
|
| 323 |
+
|
| 324 |
+
beq rs1, rs2, label
|
| 325 |
+
|
| 326 |
+
Operation:
|
| 327 |
+
|
| 328 |
+
if (rs1 == rs2)
|
| 329 |
+
pc = label;
|
| 330 |
+
|
| 331 |
+
==== bne
|
| 332 |
+
|
| 333 |
+
Branch if not equal.
|
| 334 |
+
|
| 335 |
+
Syntax:
|
| 336 |
+
|
| 337 |
+
bne rs1, rs2, label
|
| 338 |
+
|
| 339 |
+
Operation:
|
| 340 |
+
|
| 341 |
+
if (rs1 != rs2)
|
| 342 |
+
pc = label;
|
| 343 |
+
|
| 344 |
+
==== blt
|
| 345 |
+
|
| 346 |
+
Branch if less than (signed).
|
| 347 |
+
|
| 348 |
+
Syntax:
|
| 349 |
+
|
| 350 |
+
blt rs1, rs2, label
|
| 351 |
+
|
| 352 |
+
Operation:
|
| 353 |
+
|
| 354 |
+
if ($signed(rs1) < $signed(rs2))
|
| 355 |
+
pc = label;
|
| 356 |
+
|
| 357 |
+
==== bge
|
| 358 |
+
|
| 359 |
+
Branch if greater than or equal (signed).
|
| 360 |
+
|
| 361 |
+
Syntax:
|
| 362 |
+
|
| 363 |
+
bge rs1, rs2, label
|
| 364 |
+
|
| 365 |
+
Operation:
|
| 366 |
+
|
| 367 |
+
if ($signed(rs1) >= $signed(rs2))
|
| 368 |
+
pc = label;
|
| 369 |
+
|
| 370 |
+
==== bltu
|
| 371 |
+
|
| 372 |
+
Branch if less than (unsigned).
|
| 373 |
+
|
| 374 |
+
Syntax:
|
| 375 |
+
|
| 376 |
+
bltu rs1, rs2, label
|
| 377 |
+
|
| 378 |
+
Operation:
|
| 379 |
+
|
| 380 |
+
if (rs1 < rs2)
|
| 381 |
+
pc = label;
|
| 382 |
+
|
| 383 |
+
==== bgeu
|
| 384 |
+
|
| 385 |
+
Branch if less than or equal (unsigned).
|
| 386 |
+
|
| 387 |
+
Syntax:
|
| 388 |
+
|
| 389 |
+
bgeu rs1, rs2, label
|
| 390 |
+
|
| 391 |
+
Operation:
|
| 392 |
+
|
| 393 |
+
if (rs1 >= rs2)
|
| 394 |
+
pc = label;
|
| 395 |
+
|
| 396 |
+
=== RV32I: Load and Store
|
| 397 |
+
|
| 398 |
+
==== lw
|
| 399 |
+
|
| 400 |
+
Load word.
|
| 401 |
+
|
| 402 |
+
Syntax:
|
| 403 |
+
|
| 404 |
+
lw rd, imm(rs1)
|
| 405 |
+
lw rd, (rs1) // imm is implicitly 0 if omitted.
|
| 406 |
+
|
| 407 |
+
|
| 408 |
+
Operation:
|
| 409 |
+
|
| 410 |
+
rd = {
|
| 411 |
+
mem[rs1 + imm + 3],
|
| 412 |
+
mem[rs1 + imm + 2],
|
| 413 |
+
mem[rs1 + imm + 1],
|
| 414 |
+
mem[rs1 + imm]
|
| 415 |
+
};
|
| 416 |
+
|
| 417 |
+
==== lh
|
| 418 |
+
|
| 419 |
+
Load halfword (signed).
|
| 420 |
+
|
| 421 |
+
Syntax:
|
| 422 |
+
|
| 423 |
+
lh rd, imm(rs1)
|
| 424 |
+
lh rd, (rs1) // imm is implicitly 0 if omitted.
|
| 425 |
+
|
| 426 |
+
Operation:
|
| 427 |
+
|
| 428 |
+
rd = {
|
| 429 |
+
{16{mem[rs1 + imm + 1][7]}}, // Sign-extend
|
| 430 |
+
mem[rs1 + imm + 1],
|
| 431 |
+
mem[rs1 + imm]
|
| 432 |
+
};
|
| 433 |
+
|
| 434 |
+
==== lhu
|
| 435 |
+
|
| 436 |
+
Load halfword (unsigned).
|
| 437 |
+
|
| 438 |
+
Syntax:
|
| 439 |
+
|
| 440 |
+
lhu rd, imm(rs1)
|
| 441 |
+
lhu rd, (rs1) // imm is implicitly 0 if omitted.
|
| 442 |
+
|
| 443 |
+
Operation:
|
| 444 |
+
|
| 445 |
+
rd = {
|
| 446 |
+
16'h0000, // Zero-extend
|
| 447 |
+
mem[rs1 + imm + 1],
|
| 448 |
+
mem[rs1 + imm]
|
| 449 |
+
};
|
| 450 |
+
|
| 451 |
+
==== lb
|
| 452 |
+
|
| 453 |
+
Load byte (signed).
|
| 454 |
+
|
| 455 |
+
Syntax:
|
| 456 |
+
|
| 457 |
+
lb rd, imm(rs1)
|
| 458 |
+
lb rd, (rs1) // imm is implicitly 0 if omitted.
|
| 459 |
+
|
| 460 |
+
Operation:
|
| 461 |
+
|
| 462 |
+
rd = {
|
| 463 |
+
{24{mem[rs1 + imm][7]}}, // Sign-extend
|
| 464 |
+
mem[rs1 + imm]
|
| 465 |
+
};
|
| 466 |
+
|
| 467 |
+
|
| 468 |
+
|
| 469 |
+
==== lbu
|
| 470 |
+
|
| 471 |
+
Load byte (unsigned).
|
| 472 |
+
|
| 473 |
+
Syntax:
|
| 474 |
+
|
| 475 |
+
lbu rd, imm(rs1)
|
| 476 |
+
lbu rd, (rs1) // imm is implicitly 0 if omitted.
|
| 477 |
+
|
| 478 |
+
Operation:
|
| 479 |
+
|
| 480 |
+
rd = {
|
| 481 |
+
24'h000000, // Zero-extend
|
| 482 |
+
mem[rs1 + imm]
|
| 483 |
+
};
|
| 484 |
+
|
| 485 |
+
==== sw
|
| 486 |
+
|
| 487 |
+
Store word.
|
| 488 |
+
|
| 489 |
+
Syntax:
|
| 490 |
+
|
| 491 |
+
sw rs2, imm(rs1)
|
| 492 |
+
sw rs2, (rs1) // imm is implicitly 0 if omitted.
|
| 493 |
+
|
| 494 |
+
Operation:
|
| 495 |
+
|
| 496 |
+
mem[rs1 + imm] = rs2[7:0];
|
| 497 |
+
mem[rs1 + imm + 1] = rs2[15:8];
|
| 498 |
+
mem[rs1 + imm + 2] = rs2[23:16];
|
| 499 |
+
mem[rs1 + imm + 3] = rs2[31:24];
|
| 500 |
+
|
| 501 |
+
==== sh
|
| 502 |
+
|
| 503 |
+
Store halfword.
|
| 504 |
+
|
| 505 |
+
Syntax:
|
| 506 |
+
|
| 507 |
+
sh rs2, imm(rs1)
|
| 508 |
+
sh rs2, (rs1) // imm is implicitly 0 if omitted.
|
| 509 |
+
|
| 510 |
+
Operation:
|
| 511 |
+
|
| 512 |
+
mem[rs1 + imm] = rs2[7:0];
|
| 513 |
+
mem[rs1 + imm + 1] = rs2[15:8];
|
| 514 |
+
|
| 515 |
+
==== sb
|
| 516 |
+
|
| 517 |
+
Store byte.
|
| 518 |
+
|
| 519 |
+
Syntax:
|
| 520 |
+
|
| 521 |
+
sb rs2, imm(rs1)
|
| 522 |
+
sb rs2, (rs1) // imm is implicitly 0 if omitted.
|
| 523 |
+
|
| 524 |
+
Operation:
|
| 525 |
+
|
| 526 |
+
mem[rs1 + imm] = rs2[7:0];
|
| 527 |
+
|
| 528 |
+
=== M Extension
|
| 529 |
+
|
| 530 |
+
|
| 531 |
+
==== mul
|
| 532 |
+
|
| 533 |
+
Multiply 32 × 32 -> 32.
|
| 534 |
+
|
| 535 |
+
Syntax:
|
| 536 |
+
|
| 537 |
+
mul rd, rs1, rs2
|
| 538 |
+
|
| 539 |
+
|
| 540 |
+
Operation:
|
| 541 |
+
|
| 542 |
+
rd = rs1 * rs2;
|
| 543 |
+
|
| 544 |
+
==== mulh
|
| 545 |
+
|
| 546 |
+
Multiply signed (32) by signed (32), return upper 32 bits of the 64-bit result.
|
| 547 |
+
|
| 548 |
+
Syntax:
|
| 549 |
+
|
| 550 |
+
mulh rd, rs1, rs2
|
| 551 |
+
|
| 552 |
+
Operation:
|
| 553 |
+
|
| 554 |
+
// Both operands are sign-extended to 64 bits:
|
| 555 |
+
wire [63:0] result_full = {{32{rs1[31]}}, rs1} * {{32{rs2[31]}}, rs2};
|
| 556 |
+
rd = result_full[63:32];
|
| 557 |
+
|
| 558 |
+
==== mulhsu
|
| 559 |
+
|
| 560 |
+
Multiply signed (32) by unsigned (32), return upper 32 bits of the 64-bit result.
|
| 561 |
+
|
| 562 |
+
Syntax:
|
| 563 |
+
|
| 564 |
+
mulhsu rd, rs1, rs2
|
| 565 |
+
|
| 566 |
+
Operation:
|
| 567 |
+
|
| 568 |
+
// rs1 is sign-extended, rs2 is zero-extended:
|
| 569 |
+
wire [63:0] result_full = {{32{rs1[31}}, rs1} * {32'h00000000, rs2};
|
| 570 |
+
rd = result_full[63:32];
|
| 571 |
+
|
| 572 |
+
==== mulhu
|
| 573 |
+
|
| 574 |
+
Multiply unsigned (32) by unsigned (32), return upper 32 bits of the 64-bit result.
|
| 575 |
+
|
| 576 |
+
Syntax:
|
| 577 |
+
|
| 578 |
+
mulhu rd, rs1, rs2
|
| 579 |
+
|
| 580 |
+
Operation:
|
| 581 |
+
|
| 582 |
+
wire [63:0] result_full = {32'h00000000, rs1} * {32'h00000000, rs2};
|
| 583 |
+
rd = result_full[63:32];
|
| 584 |
+
|
| 585 |
+
==== div
|
| 586 |
+
|
| 587 |
+
Divide (signed).
|
| 588 |
+
|
| 589 |
+
Syntax:
|
| 590 |
+
|
| 591 |
+
div rd, rs1, rs2
|
| 592 |
+
|
| 593 |
+
Operation:
|
| 594 |
+
|
| 595 |
+
if (rs2 == 32'h0)
|
| 596 |
+
rd = 32'hffffffff;
|
| 597 |
+
else if (rs1 == 32'h80000000 && rs2 == 32'hffffffff) // Signed overflow
|
| 598 |
+
rd = 32'h80000000;
|
| 599 |
+
else
|
| 600 |
+
rd = $signed(rs1) / $signed(rs2);
|
| 601 |
+
|
| 602 |
+
==== divu
|
| 603 |
+
|
| 604 |
+
Divide (unsigned).
|
| 605 |
+
|
| 606 |
+
Syntax:
|
| 607 |
+
|
| 608 |
+
divu rd, rs1, rs2
|
| 609 |
+
|
| 610 |
+
Operation:
|
| 611 |
+
|
| 612 |
+
if (rs2 == 32'h0)
|
| 613 |
+
rd = 32'hffffffff;
|
| 614 |
+
else
|
| 615 |
+
rd = rs1 / rs2;
|
| 616 |
+
|
| 617 |
+
==== rem
|
| 618 |
+
|
| 619 |
+
Remainder (signed).
|
| 620 |
+
|
| 621 |
+
Syntax:
|
| 622 |
+
|
| 623 |
+
rem rd, rs1, rs2
|
| 624 |
+
|
| 625 |
+
Operation:
|
| 626 |
+
|
| 627 |
+
if (rs2 == 32'h0)
|
| 628 |
+
rd = rs1;
|
| 629 |
+
else
|
| 630 |
+
rd = $signed(rs1) % $signed(rs2);
|
| 631 |
+
|
| 632 |
+
==== remu
|
| 633 |
+
|
| 634 |
+
Remainder (unsigned).
|
| 635 |
+
|
| 636 |
+
Syntax:
|
| 637 |
+
|
| 638 |
+
remu rd, rs1, rs2
|
| 639 |
+
|
| 640 |
+
Operation:
|
| 641 |
+
|
| 642 |
+
if (rs2 == 32'h0)
|
| 643 |
+
rd = rs1;
|
| 644 |
+
else
|
| 645 |
+
rd = rs1 % rs2;
|
| 646 |
+
|
| 647 |
+
=== A Extension
|
| 648 |
+
|
| 649 |
+
(TODO)
|
| 650 |
+
|
| 651 |
+
=== C Extension
|
| 652 |
+
|
| 653 |
+
All C extension instructions are 16-bit aliases of 32-bit instructions from other extensions (in the case of Hazard3, entirely from the RV32I base extension). They behave identically to their 32-bit counterparts.
|
| 654 |
+
|
| 655 |
+
=== Zba: Bit manipulation (address generation)
|
| 656 |
+
|
| 657 |
+
==== sh1add
|
| 658 |
+
|
| 659 |
+
Add, with the first addend shifted left by 1.
|
| 660 |
+
|
| 661 |
+
Syntax:
|
| 662 |
+
|
| 663 |
+
sh1add rd, rs1, rs2
|
| 664 |
+
|
| 665 |
+
Operation:
|
| 666 |
+
|
| 667 |
+
rd = (rs1 << 1) + rs2;
|
| 668 |
+
|
| 669 |
+
==== sh2add
|
| 670 |
+
|
| 671 |
+
Add, with the first addend shifted left by 2.
|
| 672 |
+
|
| 673 |
+
Syntax:
|
| 674 |
+
|
| 675 |
+
sh2add rd, rs1, rs2
|
| 676 |
+
|
| 677 |
+
Operation:
|
| 678 |
+
|
| 679 |
+
rd = (rs1 << 2) + rs2;
|
| 680 |
+
|
| 681 |
+
==== sh3add
|
| 682 |
+
|
| 683 |
+
Add, with the first addend shifted left by 3.
|
| 684 |
+
|
| 685 |
+
Syntax:
|
| 686 |
+
|
| 687 |
+
sh3add rd, rs1, rs2
|
| 688 |
+
|
| 689 |
+
Operation:
|
| 690 |
+
|
| 691 |
+
rd = (rs1 << 3) + rs2;
|
| 692 |
+
|
| 693 |
+
=== Zbb: Bit manipulation (basic)
|
| 694 |
+
|
| 695 |
+
==== andn
|
| 696 |
+
|
| 697 |
+
Bitwise AND with inverted operand.
|
| 698 |
+
|
| 699 |
+
Syntax:
|
| 700 |
+
|
| 701 |
+
andn rd, rs1, rs2
|
| 702 |
+
|
| 703 |
+
Operation:
|
| 704 |
+
|
| 705 |
+
rd = rs1 & ~rs2;
|
| 706 |
+
|
| 707 |
+
==== clz
|
| 708 |
+
|
| 709 |
+
Count leading zeroes (starting from MSB, searching LSB-ward).
|
| 710 |
+
|
| 711 |
+
Syntax:
|
| 712 |
+
|
| 713 |
+
clz rd, rs1
|
| 714 |
+
|
| 715 |
+
Operation:
|
| 716 |
+
|
| 717 |
+
----
|
| 718 |
+
rd = 32; // Default = 32 if no set bits
|
| 719 |
+
reg found = 1'b0; // Local variable
|
| 720 |
+
|
| 721 |
+
for (i = 0; i < 32; i = i + 1) begin
|
| 722 |
+
if (rs1[31 - i] && !found) begin
|
| 723 |
+
found = 1'b1;
|
| 724 |
+
rd = i;
|
| 725 |
+
end
|
| 726 |
+
end
|
| 727 |
+
----
|
| 728 |
+
|
| 729 |
+
==== cpop
|
| 730 |
+
|
| 731 |
+
Population count.
|
| 732 |
+
|
| 733 |
+
Syntax:
|
| 734 |
+
|
| 735 |
+
cpop rd, rs1
|
| 736 |
+
|
| 737 |
+
Operation:
|
| 738 |
+
|
| 739 |
+
rd = 0;
|
| 740 |
+
for (i = 0; i < 32; i = i + 1)
|
| 741 |
+
rd = rd + rs1[i];
|
| 742 |
+
|
| 743 |
+
==== ctz
|
| 744 |
+
|
| 745 |
+
Count trailing zeroes (starting from LSB, searching MSB-ward).
|
| 746 |
+
|
| 747 |
+
Syntax:
|
| 748 |
+
|
| 749 |
+
ctz rd, rs1
|
| 750 |
+
|
| 751 |
+
Operation:
|
| 752 |
+
|
| 753 |
+
----
|
| 754 |
+
rd = 32; // Default = 32 if no set bits
|
| 755 |
+
reg found = 1'b0; // Local variable
|
| 756 |
+
|
| 757 |
+
for (i = 0; i < 32; i = i + 1) begin
|
| 758 |
+
if (rs1[i] && !found) begin
|
| 759 |
+
found = 1'b1;
|
| 760 |
+
rd = i;
|
| 761 |
+
end
|
| 762 |
+
end
|
| 763 |
+
----
|
| 764 |
+
|
| 765 |
+
==== max
|
| 766 |
+
|
| 767 |
+
Maximum of two values (signed).
|
| 768 |
+
|
| 769 |
+
Syntax:
|
| 770 |
+
|
| 771 |
+
max rd, rs1, rs2
|
| 772 |
+
|
| 773 |
+
Operation:
|
| 774 |
+
|
| 775 |
+
if ($signed(rs1) < $signed(rs2))
|
| 776 |
+
rd = rs2;
|
| 777 |
+
else
|
| 778 |
+
rd = rs1;
|
| 779 |
+
|
| 780 |
+
==== maxu
|
| 781 |
+
|
| 782 |
+
Maximum of two values (unsigned).
|
| 783 |
+
|
| 784 |
+
Syntax:
|
| 785 |
+
|
| 786 |
+
maxu rd, rs1, rs2
|
| 787 |
+
|
| 788 |
+
Operation:
|
| 789 |
+
|
| 790 |
+
if (rs1 < rs2)
|
| 791 |
+
rd = rs2;
|
| 792 |
+
else
|
| 793 |
+
rd = rs1;
|
| 794 |
+
|
| 795 |
+
==== min
|
| 796 |
+
|
| 797 |
+
Minimum of two values (signed).
|
| 798 |
+
|
| 799 |
+
Syntax:
|
| 800 |
+
|
| 801 |
+
min rd, rs1, rs2
|
| 802 |
+
|
| 803 |
+
Operation:
|
| 804 |
+
|
| 805 |
+
if ($signed(rs1) < $signed(rs2))
|
| 806 |
+
rd = rd1;
|
| 807 |
+
else
|
| 808 |
+
rd = rs2;
|
| 809 |
+
|
| 810 |
+
==== minu
|
| 811 |
+
|
| 812 |
+
Minimum of two values (unsigned).
|
| 813 |
+
|
| 814 |
+
Syntax:
|
| 815 |
+
|
| 816 |
+
minu rd, rs1, rs2
|
| 817 |
+
|
| 818 |
+
Operation:
|
| 819 |
+
|
| 820 |
+
if (rs1 < rs2)
|
| 821 |
+
rd = rs1;
|
| 822 |
+
else
|
| 823 |
+
rd = rs2;
|
| 824 |
+
|
| 825 |
+
==== orc.b
|
| 826 |
+
|
| 827 |
+
Or-combine of bits within each byte.
|
| 828 |
+
|
| 829 |
+
Syntax:
|
| 830 |
+
|
| 831 |
+
orc.b rd, rs1
|
| 832 |
+
|
| 833 |
+
Operation:
|
| 834 |
+
|
| 835 |
+
rd = {
|
| 836 |
+
{8{|rs1[31:24]}},
|
| 837 |
+
{8{|rs1[23:16]}},
|
| 838 |
+
{8{|rs1[15:8]}},
|
| 839 |
+
{8{|rs1[7:0]}}
|
| 840 |
+
};
|
| 841 |
+
|
| 842 |
+
==== orn
|
| 843 |
+
|
| 844 |
+
Bitwise OR with inverted operand.
|
| 845 |
+
|
| 846 |
+
Syntax:
|
| 847 |
+
|
| 848 |
+
orn rd, rs1, rs2
|
| 849 |
+
|
| 850 |
+
Operation:
|
| 851 |
+
|
| 852 |
+
rd = rs1 | ~rs2;
|
| 853 |
+
|
| 854 |
+
==== rev8
|
| 855 |
+
|
| 856 |
+
Reverse bytes within word.
|
| 857 |
+
|
| 858 |
+
Syntax:
|
| 859 |
+
|
| 860 |
+
rev8 rd, rs1
|
| 861 |
+
|
| 862 |
+
Operation:
|
| 863 |
+
|
| 864 |
+
rd = {
|
| 865 |
+
rs1[7:0],
|
| 866 |
+
rs1[15:8],
|
| 867 |
+
rs1[23:16],
|
| 868 |
+
rs1[31:24]
|
| 869 |
+
};
|
| 870 |
+
|
| 871 |
+
==== rol
|
| 872 |
+
|
| 873 |
+
Rotate left.
|
| 874 |
+
|
| 875 |
+
Syntax:
|
| 876 |
+
|
| 877 |
+
rol rd, rs1, rs2
|
| 878 |
+
|
| 879 |
+
Operation:
|
| 880 |
+
|
| 881 |
+
if (rs2[4:0] == 0)
|
| 882 |
+
rd = rs1;
|
| 883 |
+
else
|
| 884 |
+
rd = (rs1 << rs2[4:0]) | (rs1 >> (32 - rs2[4:0]));
|
| 885 |
+
|
| 886 |
+
==== ror
|
| 887 |
+
|
| 888 |
+
Rotate right.
|
| 889 |
+
|
| 890 |
+
Syntax:
|
| 891 |
+
|
| 892 |
+
ror rd, rs1, rs2
|
| 893 |
+
|
| 894 |
+
Operation:
|
| 895 |
+
|
| 896 |
+
if (rs2[4:0] == 0)
|
| 897 |
+
rd = rs1;
|
| 898 |
+
else
|
| 899 |
+
rd = (rs1 >> rs2[4:0]) | (rs1 << (32 - rs2[4:0]));
|
| 900 |
+
|
| 901 |
+
==== rori
|
| 902 |
+
|
| 903 |
+
Rotate right, immediate.
|
| 904 |
+
|
| 905 |
+
Syntax:
|
| 906 |
+
|
| 907 |
+
ror rd, rs1, imm
|
| 908 |
+
|
| 909 |
+
Operation:
|
| 910 |
+
|
| 911 |
+
if (imm[4:0] == 0)
|
| 912 |
+
rd = rs1;
|
| 913 |
+
else
|
| 914 |
+
rd = (rs1 >> imm[4:0]) | (rs1 << (32 - imm[4:0]));
|
| 915 |
+
|
| 916 |
+
==== sext.b
|
| 917 |
+
|
| 918 |
+
Sign-extend from byte.
|
| 919 |
+
|
| 920 |
+
Syntax:
|
| 921 |
+
|
| 922 |
+
sext.b rd, rs1
|
| 923 |
+
|
| 924 |
+
Operation:
|
| 925 |
+
|
| 926 |
+
rd = {
|
| 927 |
+
{24{rs1[7]}},
|
| 928 |
+
rs1[7:0]
|
| 929 |
+
};
|
| 930 |
+
|
| 931 |
+
==== sext.h
|
| 932 |
+
|
| 933 |
+
Sign-extend from halfword.
|
| 934 |
+
|
| 935 |
+
Syntax:
|
| 936 |
+
|
| 937 |
+
sext.h rd, rs1
|
| 938 |
+
|
| 939 |
+
Operation:
|
| 940 |
+
|
| 941 |
+
rd = {
|
| 942 |
+
{16{rs1[15]}},
|
| 943 |
+
rs1[15:0]
|
| 944 |
+
};
|
| 945 |
+
|
| 946 |
+
==== xnor
|
| 947 |
+
|
| 948 |
+
Bitwise XOR with inverted operand.
|
| 949 |
+
|
| 950 |
+
Syntax:
|
| 951 |
+
|
| 952 |
+
xnor rd, rs1, rs2
|
| 953 |
+
|
| 954 |
+
Operation:
|
| 955 |
+
|
| 956 |
+
rd = rs1 ^ ~rs2;
|
| 957 |
+
|
| 958 |
+
==== zext.h
|
| 959 |
+
|
| 960 |
+
Zero-extend from halfword.
|
| 961 |
+
|
| 962 |
+
Syntax:
|
| 963 |
+
|
| 964 |
+
zext.h rd, rs1
|
| 965 |
+
|
| 966 |
+
Operation:
|
| 967 |
+
|
| 968 |
+
rd = {
|
| 969 |
+
16'h0000,
|
| 970 |
+
rs1[15:0]
|
| 971 |
+
};
|
| 972 |
+
|
| 973 |
+
==== zext.b
|
| 974 |
+
|
| 975 |
+
Zero-extend from byte.
|
| 976 |
+
|
| 977 |
+
Syntax:
|
| 978 |
+
|
| 979 |
+
zext.b rd, rs1
|
| 980 |
+
|
| 981 |
+
Operation:
|
| 982 |
+
|
| 983 |
+
// Pseudo-op for RV32I instruction
|
| 984 |
+
andi rd, rs1, 0xff
|
| 985 |
+
|
| 986 |
+
=== Zbc: Bit manipulation (carry-less multiply)
|
| 987 |
+
|
| 988 |
+
Each of these three instructions returns a 32-bit slice of the following 64-bit result:
|
| 989 |
+
|
| 990 |
+
----
|
| 991 |
+
reg [63:0] clmul_result;
|
| 992 |
+
|
| 993 |
+
always @ (*) begin
|
| 994 |
+
clmul_result = 0;
|
| 995 |
+
for (i = 0; i < 32; i = i + 1) begin
|
| 996 |
+
if (rs2[i])) begin
|
| 997 |
+
clmul_result = clmul_result ^ ({32'h0, rs1} << i);
|
| 998 |
+
end
|
| 999 |
+
end
|
| 1000 |
+
end
|
| 1001 |
+
----
|
| 1002 |
+
|
| 1003 |
+
==== clmul
|
| 1004 |
+
|
| 1005 |
+
Carry-less multiply, low half.
|
| 1006 |
+
|
| 1007 |
+
Syntax:
|
| 1008 |
+
|
| 1009 |
+
clmul rd, rs1, rs2
|
| 1010 |
+
|
| 1011 |
+
Operation:
|
| 1012 |
+
|
| 1013 |
+
rd = cmul_result[31:0];
|
| 1014 |
+
|
| 1015 |
+
==== clmulh
|
| 1016 |
+
|
| 1017 |
+
Carry-les multiply, high half.
|
| 1018 |
+
|
| 1019 |
+
Syntax:
|
| 1020 |
+
|
| 1021 |
+
clmulh rd, rs1, rs2
|
| 1022 |
+
|
| 1023 |
+
Operation:
|
| 1024 |
+
|
| 1025 |
+
rd = clmul_result[63:32];
|
| 1026 |
+
|
| 1027 |
+
==== clmulr
|
| 1028 |
+
|
| 1029 |
+
Bit-reverse of carry-less multiply of bit-reverse.
|
| 1030 |
+
|
| 1031 |
+
Syntax:
|
| 1032 |
+
|
| 1033 |
+
clmulr rd, rs1, rs2
|
| 1034 |
+
|
| 1035 |
+
Operation:
|
| 1036 |
+
|
| 1037 |
+
rd = clmul_result[32:1];
|
| 1038 |
+
|
| 1039 |
+
|
| 1040 |
+
=== Zbs: Bit manipulation (single-bit)
|
| 1041 |
+
|
| 1042 |
+
==== bclr
|
| 1043 |
+
|
| 1044 |
+
Clear single bit.
|
| 1045 |
+
|
| 1046 |
+
Syntax:
|
| 1047 |
+
|
| 1048 |
+
bclr rd, rs1, rs2
|
| 1049 |
+
|
| 1050 |
+
Operation:
|
| 1051 |
+
|
| 1052 |
+
rd = rs1 & ~(32'h1 << rs2[4:0]);
|
| 1053 |
+
|
| 1054 |
+
==== bclri
|
| 1055 |
+
|
| 1056 |
+
Clear single bit (immediate).
|
| 1057 |
+
|
| 1058 |
+
Syntax:
|
| 1059 |
+
|
| 1060 |
+
bclri rd, rs1, imm
|
| 1061 |
+
|
| 1062 |
+
Operation:
|
| 1063 |
+
|
| 1064 |
+
rd = rs1 & ~(32'h1 << imm[4:0]);
|
| 1065 |
+
|
| 1066 |
+
|
| 1067 |
+
==== bext
|
| 1068 |
+
|
| 1069 |
+
Extract single bit.
|
| 1070 |
+
|
| 1071 |
+
Syntax:
|
| 1072 |
+
|
| 1073 |
+
bext rd, rs1, rs2
|
| 1074 |
+
|
| 1075 |
+
Operation:
|
| 1076 |
+
|
| 1077 |
+
rd = (rs1 >> rs2[4:0]) & 32'h1;
|
| 1078 |
+
|
| 1079 |
+
==== bexti
|
| 1080 |
+
|
| 1081 |
+
Extract single bit (immediate).
|
| 1082 |
+
|
| 1083 |
+
Syntax:
|
| 1084 |
+
|
| 1085 |
+
bexti rd, rs1, imm
|
| 1086 |
+
|
| 1087 |
+
Operation:
|
| 1088 |
+
|
| 1089 |
+
rd = (rs1 >> imm[4:0]) & 32'h1;
|
| 1090 |
+
|
| 1091 |
+
==== binv
|
| 1092 |
+
|
| 1093 |
+
Invert single bit.
|
| 1094 |
+
|
| 1095 |
+
Syntax:
|
| 1096 |
+
|
| 1097 |
+
binv rd, rs1, rs2
|
| 1098 |
+
|
| 1099 |
+
Operation:
|
| 1100 |
+
|
| 1101 |
+
rd = rs1 ^ (32'h1 << rs2[4:0]);
|
| 1102 |
+
|
| 1103 |
+
==== binvi
|
| 1104 |
+
|
| 1105 |
+
Invert single bit (immediate).
|
| 1106 |
+
|
| 1107 |
+
Syntax:
|
| 1108 |
+
|
| 1109 |
+
binvi rd, rs1, imm
|
| 1110 |
+
|
| 1111 |
+
Operation:
|
| 1112 |
+
|
| 1113 |
+
rd = rs1 ^ (32'h1 << imm[4:0]);
|
| 1114 |
+
|
| 1115 |
+
==== bset
|
| 1116 |
+
|
| 1117 |
+
Set single bit.
|
| 1118 |
+
|
| 1119 |
+
Syntax:
|
| 1120 |
+
|
| 1121 |
+
bset rd, rs1, rs2
|
| 1122 |
+
|
| 1123 |
+
Operation:
|
| 1124 |
+
|
| 1125 |
+
rd = rs1 | (32'h1 << rs2[4:0])
|
| 1126 |
+
|
| 1127 |
+
==== bseti
|
| 1128 |
+
|
| 1129 |
+
Set single bit (immediate).
|
| 1130 |
+
|
| 1131 |
+
Syntax:
|
| 1132 |
+
|
| 1133 |
+
bseti rd, rs1, imm
|
| 1134 |
+
|
| 1135 |
+
Operation:
|
| 1136 |
+
|
| 1137 |
+
rd = rs1 | (32'h1 << imm[4:0]);
|
| 1138 |
+
|
| 1139 |
+
=== Zbkb: Basic bit manipulation for cryptography
|
| 1140 |
+
|
| 1141 |
+
NOTE: Zbkb has a large overlap with Zbb (basic bit manipulation). This section covers only those instruction in Zbkb but not in Zbb.
|
| 1142 |
+
|
| 1143 |
+
==== brev8
|
| 1144 |
+
|
| 1145 |
+
Bit-reverse within each byte.
|
| 1146 |
+
|
| 1147 |
+
Syntax:
|
| 1148 |
+
|
| 1149 |
+
brev8 rd, rs1
|
| 1150 |
+
|
| 1151 |
+
Operation:
|
| 1152 |
+
|
| 1153 |
+
for (i = 0; i < 32; i = i + 8) begin
|
| 1154 |
+
for (j = 0; j < 8; j = j + 1) begin
|
| 1155 |
+
rd[i + j] = rs1[i + (7 - j)];
|
| 1156 |
+
end
|
| 1157 |
+
end
|
| 1158 |
+
|
| 1159 |
+
==== pack
|
| 1160 |
+
|
| 1161 |
+
Pack halfwords into word.
|
| 1162 |
+
|
| 1163 |
+
Syntax:
|
| 1164 |
+
|
| 1165 |
+
pack rd, rs1, rs2
|
| 1166 |
+
|
| 1167 |
+
Operation:
|
| 1168 |
+
|
| 1169 |
+
rd = {
|
| 1170 |
+
rs2[15:0],
|
| 1171 |
+
rs1[15:0]
|
| 1172 |
+
};
|
| 1173 |
+
|
| 1174 |
+
==== packh
|
| 1175 |
+
|
| 1176 |
+
Pack bytes into halfword.
|
| 1177 |
+
|
| 1178 |
+
Syntax:
|
| 1179 |
+
|
| 1180 |
+
packh rd, rs1, rs2
|
| 1181 |
+
|
| 1182 |
+
Operation:
|
| 1183 |
+
|
| 1184 |
+
rd = {
|
| 1185 |
+
16'h0000,
|
| 1186 |
+
rs2[7:0],
|
| 1187 |
+
rs1[7:0]
|
| 1188 |
+
};
|
| 1189 |
+
|
| 1190 |
+
==== zip
|
| 1191 |
+
|
| 1192 |
+
Interleave upper/lower half of register into odd/even bits of result.
|
| 1193 |
+
|
| 1194 |
+
Syntax:
|
| 1195 |
+
|
| 1196 |
+
zip rd, rs1
|
| 1197 |
+
|
| 1198 |
+
Operation:
|
| 1199 |
+
|
| 1200 |
+
for (i = 0; i < 32; i = i + 2) begin
|
| 1201 |
+
rd[i] = rs1[i / 2];
|
| 1202 |
+
rd[i + 1] = rs1[i / 2 + 16];
|
| 1203 |
+
end
|
| 1204 |
+
|
| 1205 |
+
==== unzip
|
| 1206 |
+
|
| 1207 |
+
Deinterleave odd/even bits of register into upper/lower half of result.
|
| 1208 |
+
|
| 1209 |
+
Syntax:
|
| 1210 |
+
|
| 1211 |
+
unzip rd, rs1
|
| 1212 |
+
|
| 1213 |
+
Operation:
|
| 1214 |
+
|
| 1215 |
+
for (i = 0; i < 32; i = i + 2) begin
|
| 1216 |
+
rd[i / 2] = rs1[i];
|
| 1217 |
+
rd[i / 2 + 16] = rs1[i + 1];
|
| 1218 |
+
end
|
| 1219 |
+
|
Wren6991_Hazard3/doc/sections/instruction_timings.adoc
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
== Instruction Cycle Counts
|
| 2 |
+
|
| 3 |
+
All timings are given assuming perfect bus behaviour (no downstream bus stalls), and that the core is configured with `MULDIV_UNROLL = 2` and all other configuration options set for maximum performance.
|
| 4 |
+
|
| 5 |
+
=== Base Instruction Set (RV32I)
|
| 6 |
+
|
| 7 |
+
[%autowidth.stretch, options="header"]
|
| 8 |
+
|===
|
| 9 |
+
| Instruction | Cycles | Note
|
| 10 |
+
3+| Integer Register-register
|
| 11 |
+
| `add rd, rs1, rs2` | 1 |
|
| 12 |
+
| `sub rd, rs1, rs2` | 1 |
|
| 13 |
+
| `slt rd, rs1, rs2` | 1 |
|
| 14 |
+
| `sltu rd, rs1, rs2` | 1 |
|
| 15 |
+
| `and rd, rs1, rs2` | 1 |
|
| 16 |
+
| `or rd, rs1, rs2` | 1 |
|
| 17 |
+
| `xor rd, rs1, rs2` | 1 |
|
| 18 |
+
| `sll rd, rs1, rs2` | 1 |
|
| 19 |
+
| `srl rd, rs1, rs2` | 1 |
|
| 20 |
+
| `sra rd, rs1, rs2` | 1 |
|
| 21 |
+
3+| Integer Register-immediate
|
| 22 |
+
| `addi rd, rs1, imm` | 1 | `nop` is a pseudo-op for `addi x0, x0, 0`
|
| 23 |
+
| `slti rd, rs1, imm` | 1 |
|
| 24 |
+
| `sltiu rd, rs1, imm` | 1 |
|
| 25 |
+
| `andi rd, rs1, imm` | 1 |
|
| 26 |
+
| `ori rd, rs1, imm` | 1 |
|
| 27 |
+
| `xori rd, rs1, imm` | 1 |
|
| 28 |
+
| `slli rd, rs1, imm` | 1 |
|
| 29 |
+
| `srli rd, rs1, imm` | 1 |
|
| 30 |
+
| `srai rd, rs1, imm` | 1 |
|
| 31 |
+
3+| Large Immediate
|
| 32 |
+
| `lui rd, imm` | 1 |
|
| 33 |
+
| `auipc rd, imm` | 1 |
|
| 34 |
+
3+| Control Transfer
|
| 35 |
+
| `jal rd, label` | 2footnote:unaligned_branch[A jump or branch to a 32-bit instruction which is not 32-bit-aligned requires one additional cycle, because two naturally aligned bus cycles are required to fetch the target instruction.]|
|
| 36 |
+
| `jalr rd, rs1, imm` | 2footnote:unaligned_branch[] |
|
| 37 |
+
| `beq rs1, rs2, label`| 1 or 2footnote:unaligned_branch[] | 1 if correctly predicted, 2 if mispredicted.
|
| 38 |
+
| `bne rs1, rs2, label`| 1 or 2footnote:unaligned_branch[] | 1 if correctly predicted, 2 if mispredicted.
|
| 39 |
+
| `blt rs1, rs2, label`| 1 or 2footnote:unaligned_branch[] | 1 if correctly predicted, 2 if mispredicted.
|
| 40 |
+
| `bge rs1, rs2, label`| 1 or 2footnote:unaligned_branch[] | 1 if correctly predicted, 2 if mispredicted.
|
| 41 |
+
| `bltu rs1, rs2, label`| 1 or 2footnote:unaligned_branch[] | 1 if correctly predicted, 2 if mispredicted.
|
| 42 |
+
| `bgeu rs1, rs2, label`| 1 or 2footnote:unaligned_branch[] | 1 if correctly predicted, 2 if mispredicted.
|
| 43 |
+
3+| Load and Store
|
| 44 |
+
| `lw rd, imm(rs1)` | 1 or 2 | 1 if next instruction is independent, 2 if dependent.footnote:data_dependency[If an instruction in stage 2 (e.g. an `add`) uses data from stage 3 (e.g. a `lw` result), a 1-cycle bubble is inserted between the pair. A load data -> store data dependency is _not_ an example of this, because data is produced and consumed in stage 3. However, load data -> load address _would_ qualify, as would e.g. `sc.w` -> `beqz`.]
|
| 45 |
+
| `lh rd, imm(rs1)` | 1 or 2 | 1 if next instruction is independent, 2 if dependent.footnote:data_dependency[]
|
| 46 |
+
| `lhu rd, imm(rs1)` | 1 or 2 | 1 if next instruction is independent, 2 if dependent.footnote:data_dependency[]
|
| 47 |
+
| `lb rd, imm(rs1)` | 1 or 2 | 1 if next instruction is independent, 2 if dependent.footnote:data_dependency[]
|
| 48 |
+
| `lbu rd, imm(rs1)` | 1 or 2 | 1 if next instruction is independent, 2 if dependent.footnote:data_dependency[]
|
| 49 |
+
| `sw rs2, imm(rs1)` | 1 |
|
| 50 |
+
| `sh rs2, imm(rs1)` | 1 |
|
| 51 |
+
| `sb rs2, imm(rs1)` | 1 |
|
| 52 |
+
|===
|
| 53 |
+
|
| 54 |
+
=== Integer Multiply and Divide (M)
|
| 55 |
+
|
| 56 |
+
Timings assume the core is configured with `MULDIV_UNROLL = 2` and `MUL_FAST = 1`. I.e. the sequential multiply/divide circuit processes two bits per cycle, and a separate dedicated multiplier is present for the `mul` instruction.
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
[%autowidth.stretch, options="header"]
|
| 60 |
+
|===
|
| 61 |
+
| Instruction | Cycles | Note
|
| 62 |
+
3+| 32 {times} 32 -> 32 Multiply
|
| 63 |
+
| `mul rd, rs1, rs2` | 1 |
|
| 64 |
+
3+| 32 {times} 32 -> 64 Multiply, Upper Half
|
| 65 |
+
| `mulh rd, rs1, rs2` | 1 |
|
| 66 |
+
| `mulhsu rd, rs1, rs2` | 1 |
|
| 67 |
+
| `mulhu rd, rs1, rs2` | 1 |
|
| 68 |
+
3+| Divide and Remainder
|
| 69 |
+
| `div rd, rs1, rs2` | 18 or 19 | Depending on sign correction
|
| 70 |
+
| `divu rd, rs1, rs2` | 18 |
|
| 71 |
+
| `rem rd, rs1, rs2` | 18 or 19 | Depending on sign correction
|
| 72 |
+
| `remu rd, rs1, rs2` | 18 |
|
| 73 |
+
|===
|
| 74 |
+
|
| 75 |
+
=== Atomics (A)
|
| 76 |
+
|
| 77 |
+
[%autowidth.stretch, options="header"]
|
| 78 |
+
|===
|
| 79 |
+
| Instruction | Cycles | Note
|
| 80 |
+
3+| Load-Reserved/Store-Conditional
|
| 81 |
+
| `lr.w rd, (rs1)` | 1 or 2 | 2 if next instruction is dependentfootnote:data_dependency[], an `lr.w`, `sc.w` or `amo*.w`.footnote:exclusive_pipelining[A pipeline bubble is inserted between `lr.w`/`sc.w` and an immediately-following `lr.w`/`sc.w`/`amo*`, because the AHB5 bus standard does not permit pipelined exclusive accesses. A stall would be inserted between `lr.w` and `sc.w` anyhow, so the local monitor can be updated based on the `lr.w` data phase in time to suppress the `sc.w` address phase.]
|
| 82 |
+
| `sc.w rd, rs2, (rs1)` | 1 or 2 | 2 if next instruction is dependentfootnote:data_dependency[], an `lr.w`, `sc.w` or `amo*.w`.footnote:exclusive_pipelining[]
|
| 83 |
+
3+| Atomic Memory Operations
|
| 84 |
+
|`amoswap.w rd, rs2, (rs1)` | 4+ | 4 per attempt. Multiple attempts if reservation is lost.footnote:amo_timing[AMOs are issued as a paired exclusive read and exclusive write on the bus, at the maximum speed of 2 cycles per access, since the bus does not permit pipelining of exclusive reads/writes. If the write phase fails due to the global monitor reporting a lost reservation, the instruction loops at a rate of 4 cycles per loop, until success. If the read reservation is refused by the global monitor, the instruction generates a Store/AMO Fault exception, to avoid an infinite loop.]
|
| 85 |
+
|`amoadd.w rd, rs2, (rs1)` | 4+ | 4 per attempt. Multiple attempts if reservation is lost.footnote:amo_timing[]
|
| 86 |
+
|`amoxor.w rd, rs2, (rs1)` | 4+ | 4 per attempt. Multiple attempts if reservation is lost.footnote:amo_timing[]
|
| 87 |
+
|`amoand.w rd, rs2, (rs1)` | 4+ | 4 per attempt. Multiple attempts if reservation is lost.footnote:amo_timing[]
|
| 88 |
+
|`amoor.w rd, rs2, (rs1)` | 4+ | 4 per attempt. Multiple attempts if reservation is lost.footnote:amo_timing[]
|
| 89 |
+
|`amomin.w rd, rs2, (rs1)` | 4+ | 4 per attempt. Multiple attempts if reservation is lost.footnote:amo_timing[]
|
| 90 |
+
|`amomax.w rd, rs2, (rs1)` | 4+ | 4 per attempt. Multiple attempts if reservation is lost.footnote:amo_timing[]
|
| 91 |
+
|`amominu.w rd, rs2, (rs1)` | 4+ | 4 per attempt. Multiple attempts if reservation is lost.footnote:amo_timing[]
|
| 92 |
+
|`amomaxu.w rd, rs2, (rs1)` | 4+ | 4 per attempt. Multiple attempts if reservation is lost.footnote:amo_timing[]
|
| 93 |
+
|===
|
| 94 |
+
|
| 95 |
+
=== Compressed Instructions (C or Zca)
|
| 96 |
+
|
| 97 |
+
All C extension 16-bit instructions are aliases of base RV32I instructions. On Hazard3, they perform identically to their 32-bit counterparts.
|
| 98 |
+
|
| 99 |
+
A consequence of the C extension is that 32-bit instructions can be non-naturally-aligned. This has no penalty during sequential execution, but branching to a 32-bit instruction that is not 32-bit-aligned carries a 1 cycle penalty, because the instruction fetch is cracked into two naturally-aligned bus accesses.
|
| 100 |
+
|
| 101 |
+
=== Privileged Instructions (including Zicsr)
|
| 102 |
+
|
| 103 |
+
[%autowidth.stretch, options="header"]
|
| 104 |
+
|===
|
| 105 |
+
| Instruction | Cycles | Note
|
| 106 |
+
3+| CSR Access
|
| 107 |
+
| `csrrw rd, csr, rs1` | 1footnote:csr_fetch_ordering[Writes to the following CSRs take 3 cycles, plus an additional 1 cycle if the following instruction is misaligned 32-bit: `pmpaddr*`, `pmpcfg*`, `tcontrol`, `tdata1`, `tdata2`. These CSRs require an instruction fetch flush to enforce CSR-write-to-fetch ordering.] |
|
| 108 |
+
| `csrrc rd, csr, rs1` | 1footnote:csr_fetch_ordering[] |
|
| 109 |
+
| `csrrs rd, csr, rs1` | 1footnote:csr_fetch_ordering[] |
|
| 110 |
+
| `csrrwi rd, csr, imm` | 1footnote:csr_fetch_ordering[] |
|
| 111 |
+
| `csrrci rd, csr, imm` | 1footnote:csr_fetch_ordering[] |
|
| 112 |
+
| `csrrsi rd, csr, imm` | 1footnote:csr_fetch_ordering[] |
|
| 113 |
+
3+| Trap Request
|
| 114 |
+
| `ecall` | 3 | Time given is for jumping to `mtvec`
|
| 115 |
+
| `ebreak` | 3 | Time given is for jumping to `mtvec`
|
| 116 |
+
|===
|
| 117 |
+
|
| 118 |
+
=== Load/Store Pair (Zilsd)
|
| 119 |
+
|
| 120 |
+
[%autowidth.stretch, options="header"]
|
| 121 |
+
|===
|
| 122 |
+
| Instruction | Cycles | Note
|
| 123 |
+
3+| Load/Store Pair
|
| 124 |
+
| `ld rd, imm(rs1)` | 2 | Issues as two `lw`
|
| 125 |
+
| `sd rs2, imm(rs1)` | 2 | Issues as two `sw`
|
| 126 |
+
|===
|
| 127 |
+
|
| 128 |
+
=== Bit Manipulation (Zba, Zbb, Zbc, Zbs)
|
| 129 |
+
|
| 130 |
+
[%autowidth.stretch, options="header"]
|
| 131 |
+
|===
|
| 132 |
+
| Instruction | Cycles | Note
|
| 133 |
+
3+| Zba (address generation)
|
| 134 |
+
|`sh1add rd, rs1, rs2` | 1 |
|
| 135 |
+
|`sh2add rd, rs1, rs2` | 1 |
|
| 136 |
+
|`sh3add rd, rs1, rs2` | 1 |
|
| 137 |
+
3+| Zbb (basic bit manipulation)
|
| 138 |
+
|`andn rd, rs1, rs2` | 1 |
|
| 139 |
+
|`clz rd, rs1` | 1 |
|
| 140 |
+
|`cpop rd, rs1` | 1 |
|
| 141 |
+
|`ctz rd, rs1` | 1 |
|
| 142 |
+
|`max rd, rs1, rs2` | 1 |
|
| 143 |
+
|`maxu rd, rs1, rs2` | 1 |
|
| 144 |
+
|`min rd, rs1, rs2` | 1 |
|
| 145 |
+
|`minu rd, rs1, rs2` | 1 |
|
| 146 |
+
|`orc.b rd, rs1` | 1 |
|
| 147 |
+
|`orn rd, rs1, rs2` | 1 |
|
| 148 |
+
|`rev8 rd, rs1` | 1 |
|
| 149 |
+
|`rol rd, rs1, rs2` | 1 |
|
| 150 |
+
|`ror rd, rs1, rs2` | 1 |
|
| 151 |
+
|`rori rd, rs1, imm` | 1 |
|
| 152 |
+
|`sext.b rd, rs1` | 1 |
|
| 153 |
+
|`sext.h rd, rs1` | 1 |
|
| 154 |
+
|`xnor rd, rs1, rs2` | 1 |
|
| 155 |
+
|`zext.h rd, rs1` | 1 |
|
| 156 |
+
|`zext.b rd, rs1` | 1 | `zext.b` is a pseudo-op for `andi rd, rs1, 0xff`
|
| 157 |
+
3+| Zbc (carry-less multiply)
|
| 158 |
+
|`clmul rd, rs1, rs2` | 1 |
|
| 159 |
+
|`clmulh rd, rs1, rs2` | 1 |
|
| 160 |
+
|`clmulr rd, rs1, rs2` | 1 |
|
| 161 |
+
3+| Zbs (single-bit manipulation)
|
| 162 |
+
|`bclr rd, rs1, rs2` | 1 |
|
| 163 |
+
|`bclri rd, rs1, imm` | 1 |
|
| 164 |
+
|`bext rd, rs1, rs2` | 1 |
|
| 165 |
+
|`bexti rd, rs1, imm` | 1 |
|
| 166 |
+
|`binv rd, rs1, rs2` | 1 |
|
| 167 |
+
|`binvi rd, rs1, imm` | 1 |
|
| 168 |
+
|`bset rd, rs1, rs2` | 1 |
|
| 169 |
+
|`bseti rd, rs1, imm` | 1 |
|
| 170 |
+
3+| Zbkb (basic bit manipulation for cryptography)
|
| 171 |
+
|`pack rd, rs1, rs2` | 1 |
|
| 172 |
+
|`packh rd, rs1, rs2` | 1 |
|
| 173 |
+
|`brev8 rd, rs1` | 1 |
|
| 174 |
+
|`zip rd, rs1` | 1 |
|
| 175 |
+
|`unzip rd, rs1` | 1 |
|
| 176 |
+
|===
|
| 177 |
+
|
| 178 |
+
=== Additional Basic Compressed Instructions (Zcb)
|
| 179 |
+
|
| 180 |
+
Similarly to the C extension, this extension contains 16-bit variants of common 32-bit instructions:
|
| 181 |
+
|
| 182 |
+
* RV32I base ISA: `lbu`, `lh`, `lhu`, `sb`, `sh`, `zext.b` (alias of `andi`), `not` (alias of `xori`)
|
| 183 |
+
* Zbb extension: `sext.b`, `zext.h`, `sext.h`
|
| 184 |
+
* M extension: `mul`
|
| 185 |
+
|
| 186 |
+
They perform identically to their 32-bit counterparts.
|
| 187 |
+
|
| 188 |
+
=== Compressed Load/Store Pair (Zclsd)
|
| 189 |
+
|
| 190 |
+
These 16-bit instructions behave identically to their 32-bit counterparts, namely:
|
| 191 |
+
|
| 192 |
+
* `c.ld` expands to Zilsd `ld`
|
| 193 |
+
* `c.ldsp` expands to Zilsd `ld`
|
| 194 |
+
* `c.sd` expands to Zilsd `sd`
|
| 195 |
+
* `c.sdsp` expands to Zilsd `sd`
|
| 196 |
+
|
| 197 |
+
=== Push, Pop and Double Move (Zcmp)
|
| 198 |
+
|
| 199 |
+
[%autowidth.stretch, options="header"]
|
| 200 |
+
|===
|
| 201 |
+
| Instruction | Cycles | Note
|
| 202 |
+
|`cm.push {rlist}, -imm` | 1 + _n_ | _n_ is number of registers in rlist
|
| 203 |
+
|`cm.pop {rlist}, imm` | 1 + _n_ | _n_ is number of registers in rlist
|
| 204 |
+
|`cm.popret {rlist}, imm` | 4 (_n_ = 1)footnote:popret_stall[The single-register variant of `cm.popret` takes the same number of cycles as the two-register variant, because of an internal load-use dependency on the loaded return address.] or 2 + _n_ (_n_ >= 2)footnote:unaligned_branch[] | _n_ is number of registers in rlist
|
| 205 |
+
|`cm.popretz {rlist}, imm` | 3 + __n__footnote:unaligned_branch[] | _n_ is number of registers in rlist
|
| 206 |
+
|`cm.mva01s r1s', r2s'` | 2 |
|
| 207 |
+
|`cm.mvsa01 r1s', r2s'` | 2 |
|
| 208 |
+
|===
|
| 209 |
+
|
| 210 |
+
[[instruction-timings-branch-predictor]]
|
| 211 |
+
=== Branch Predictor
|
| 212 |
+
|
| 213 |
+
Hazard3 includes a minimal branch predictor, to accelerate tight loops:
|
| 214 |
+
|
| 215 |
+
* The instruction frontend remembers the last taken, backward branch
|
| 216 |
+
* If the same branch is seen again, it is predicted taken
|
| 217 |
+
* All other branches are predicted nontaken
|
| 218 |
+
* If a predicted-taken branch is not taken, the predictor state is cleared, and it will be predicted nontaken on its next execution.
|
| 219 |
+
|
| 220 |
+
Correctly predicted branches execute in one cycle: the frontend is able to stitch together the two nonsequential fetch paths so that they appear sequential. Mispredicted branches incur a penalty cycle, since a nonsequential fetch address must be issued when the branch is executed.
|
Wren6991_Hazard3/doc/sections/introduction.adoc
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
== Introduction
|
| 2 |
+
|
| 3 |
+
Hazard3 is a configurable 3-stage RISC-V processor, implementing:
|
| 4 |
+
|
| 5 |
+
* `RV32I` or `RV32E`: 32-bit base instruction set
|
| 6 |
+
* `M`: integer multiply/divide/modulo
|
| 7 |
+
* `A`: atomic memory operations, with AHB5 global exclusives
|
| 8 |
+
* `C`: compressed instructions
|
| 9 |
+
* `Zicsr`: CSR access
|
| 10 |
+
* `Zilsd`: load/store pair
|
| 11 |
+
* `Zba`: address generation
|
| 12 |
+
* `Zbb`: basic bit manipulation
|
| 13 |
+
* `Zbc`: carry-less multiplication
|
| 14 |
+
* `Zbs`: single-bit manipulation
|
| 15 |
+
* `Zbkb`: basic bit manipulation for scalar cryptography
|
| 16 |
+
* `Zbkx`: crossbar permutation instructions
|
| 17 |
+
* `Zcb`: basic additional compressed instructions
|
| 18 |
+
* `Zcmp`: push/pop and double-move compressed instructions
|
| 19 |
+
* `Zclsd`: compressed load/store pair instructions
|
| 20 |
+
* Debug, Machine and User privilege/execution modes
|
| 21 |
+
* Privileged instructions `ecall`, `ebreak`, `mret` and `wfi`
|
| 22 |
+
* Physical memory protection (PMP) with up to 16 regions (configurable support for NAPOT and/or TOR matching)
|
| 23 |
+
* External debug support
|
| 24 |
+
* Instruction address trigger unit (hardware breakpoints)
|
| 25 |
+
|
| 26 |
+
This document describes Hazard3 version https://github.com/Wren6991/Hazard3/releases/tag/v1.1.1[v1.1.1]. See <<section-release-notes>> for changes introduced in this and earlier versions.
|
| 27 |
+
|
| 28 |
+
<<<
|
| 29 |
+
|
| 30 |
+
=== Architecture Overview
|
| 31 |
+
|
| 32 |
+
==== Interfaces
|
| 33 |
+
|
| 34 |
+
Hazard3 communicates with system hardware using the following groups of signals:
|
| 35 |
+
|
| 36 |
+
image::diagrams/hazard3_interfaces_both.drawio.png[width=60%, pdfwidth=60%, align="center"]
|
| 37 |
+
|
| 38 |
+
AHB:: The core accesses the bus using either 1 {times} or 2 {times} 32-bit AHB5 bus manager ports, depending on choice of top-level module (see <<top-level-modules>>).
|
| 39 |
+
IRQ:: The core implements standard RISC-V timer and software IRQ inputs, and a choice of a single external IRQ input or an integrated interrupt controller with support for up to 512 external IRQs.
|
| 40 |
+
Debug:: Allows the Hazard3 Debug Module implementation to access core internals, and optionally to access the system bus directly by arbitrating with the core's load/store access.
|
| 41 |
+
Power:: The core can negotiate power up/down of external hardware based on sleep state, and enter/exit sleep states cooperatively with other cores in the same multiprocessor system.
|
| 42 |
+
Fence:: The core can request memory orderings; the system can stall the request (e.g. for a cache flush).
|
| 43 |
+
|
| 44 |
+
See <<port-descriptions>> for a full description of these interfaces.
|
| 45 |
+
|
| 46 |
+
// Hard line break because there is a huge diagram on the next page and it needs to flow with the text
|
| 47 |
+
<<<
|
| 48 |
+
|
| 49 |
+
==== Pipeline Stages
|
| 50 |
+
|
| 51 |
+
The diagram shows how hardware components are distributed through three pipeline stages. A dotted outline means an optional component. Dotted vertical lines are clock boundaries between stages; blocks that straddle these lines are synchronous elements, either registers or bus signals that are notionally registered outside the core. Dependencies (and time) flow from left to right.
|
| 52 |
+
|
| 53 |
+
image::diagrams/hazard3_pipeline.drawio.png[width=90%, align="center", pdfwidth=100%]
|
| 54 |
+
|
| 55 |
+
The three stages are:
|
| 56 |
+
|
| 57 |
+
* `F`: Fetch
|
| 58 |
+
** Contains the data phase for instruction fetch
|
| 59 |
+
** Contains the instruction prefetch buffer
|
| 60 |
+
** Predecodes register numbers `rs1`/`rs2`, for faster register file read and register bypass
|
| 61 |
+
** Contains the address match logic for the optional branch predictor
|
| 62 |
+
** Compares data-phase fetch address with breakpoint addresses
|
| 63 |
+
** Looks up data-phase fetch address against PMP regions
|
| 64 |
+
* `X`: Execute
|
| 65 |
+
** Decodes and execute instructions
|
| 66 |
+
** Looks up load/store/AMO addresses against PMP regions
|
| 67 |
+
** Drives the address phase for load/store/AMO
|
| 68 |
+
** Generates jump/branch addresses
|
| 69 |
+
** Contains the read and write ports for the CSR file
|
| 70 |
+
** Unbypassed register values are available at the beginning of stage `X`
|
| 71 |
+
** The ALU result is valid by the end of stage `X`
|
| 72 |
+
* `M`: Memory
|
| 73 |
+
** Contains the data phase for load/store/AMO
|
| 74 |
+
** Generates exception addresses
|
| 75 |
+
** Register writeback is at the end of stage `M`
|
| 76 |
+
|
| 77 |
+
The instruction fetch address phase is best thought of as residing in stage `X`. The 2-cycle feedback loop between jump/branch decode into address issue in stage `X`, and the fetch data phase in stage `F`, is what defines Hazard3's jump/branch performance.
|
| 78 |
+
|
| 79 |
+
This document often refers to `F`, `X` and `M` as stages 1, 2 and 3 respectively. This numbering is useful when describing dependencies between values held in different pipeline stages, as it makes the direction and distance of the dependency more apparent.
|
| 80 |
+
|
| 81 |
+
==== Bus Interfaces
|
| 82 |
+
|
| 83 |
+
Hazard3 implements either one or two AHB5 bus manager ports. The dual-port configuration adds a dedicated port for instruction fetch. Use the single-port configuration when ease of integration is a priority, since it supports simpler bus topologies. The dual-port configuration supports higher maximum frequency and greater clock-for-clock performance provided you either have a split (Harvard) bus architecture, or can handle multiple AHB5 managers on the same bus.
|
| 84 |
+
|
| 85 |
+
One of the key additions to AHB5 over older AHB versions is *exclusive accesses*, using the `HEXCL` and `HEXOKAY` signals. Exclusive accesses enable an ordered read-modify-write sequence with the guarantee that no other processor has written to the same memory location in between the read and write. Hazard3 uses AHB5 exclusives to implement multiprocessor support for the A (atomics) extension. Single-processor support for the A extension does not require these additional signals.
|
| 86 |
+
|
| 87 |
+
AHB5 is one of the two protocols described in the https://documentation-service.arm.com/static/5f91607cf86e16515cdc3b4b[AMBA 5 AHB protocol specification]. Its full name is (perhaps surprisingly) AMBA 5 AHB5. Refer to the protocol specification for more information about this standard bus protocol.
|
| 88 |
+
|
| 89 |
+
==== Multiply/Divide
|
| 90 |
+
|
| 91 |
+
For minimal M-extension support, as enabled by <<param-EXTENSION_M>>, Hazard3 instantiates a sequential multiply/divide circuit (restoring divide, naive repeated-addition multiply). Instructions stall in stage `X` until the multiply/divide completes. Optionally, the circuit can be unrolled by a small factor to produce multiple bits ber clock. A throughput of one, two or four bits per cycle is achievable in practice, with the internal logic delay becoming quite significant at four.
|
| 92 |
+
|
| 93 |
+
Set <<param-MUL_FAST>> to instantiate the single-cycle multiplier circuit. The fast multiplier returns results either to stage 3 or stage 2, depending on the <<param-MUL_FASTER>> parameter.
|
| 94 |
+
|
| 95 |
+
By default the single-cycle multiplier only supports 32-bit `mul`, which is by far the most common of the four multiply instructions. The remaining instructions still execute on the sequential multiply/divide circuit. Set the <<param-MULH_FAST>> parameter to add single-cycle support for the high-half instructions (`mulh`, `mulhu` and `mulhsu`), at the cost of additional logic delay and area.
|
| 96 |
+
|
| 97 |
+
The single-cycle multiplier is implemented as a simple `*` behavioural multiply, so that your tools can infer the best multiply circuit for your platform. For example, Yosys infers DSP tiles on iCE40 UP5k FPGAs. The multiplier is a self-contained module (in `hdl/arith/hazard3_mul_fast.v`), so you can replace its implementation if you know of a faster or lower-area method for your platform.
|
| 98 |
+
|
| 99 |
+
// ** magic comment to reset sublime text asciidoc lexer
|
| 100 |
+
|
| 101 |
+
==== Constant-time Execution
|
| 102 |
+
|
| 103 |
+
Hazard3 supports `Zkt` constant-time execution in the following configurations:
|
| 104 |
+
|
| 105 |
+
* <<param-EXTENSION_M>> is `0`
|
| 106 |
+
* <<param-EXTENSION_M>> is `1`, <<param-MUL_FAST>> is `1` and <<param-MULH_FAST>> is `1`
|
| 107 |
+
|
| 108 |
+
The source of data-dependent timing is conditional sign correction in the `mulh` and `mulhsu` instructions when executed on the sequential multiply/divide circuit. You can avoid this by configuring these instructions to execute on the single-cycle multiplier instead. The remaining `Zkt` instructions are constant-time for all configurations.
|
| 109 |
+
|
| 110 |
+
Constant-time here refers to **data-independent timing**. Execution time can still be affected by other factors such as instruction alignment and external bus stalls.
|
| 111 |
+
|
| 112 |
+
Software can read the `Zkt` bit in <<reg-h3.misa>> to check whether a given implementation has constant execution time for the `Zkt` instruction list.
|
| 113 |
+
|
| 114 |
+
=== List of RISC-V Specifications
|
| 115 |
+
|
| 116 |
+
These are links to the ratified versions of the base instruction set and extensions implemented by Hazard3.
|
| 117 |
+
|
| 118 |
+
[%autowidth.stretch, options="header"]
|
| 119 |
+
|===
|
| 120 |
+
| Extension | Specification
|
| 121 |
+
| `RV32I` v2.1 | https://github.com/riscv/riscv-isa-manual/releases/download/Ratified-IMAFDQC/riscv-spec-20191213.pdf[Unprivileged ISA 20191213]
|
| 122 |
+
| `M` v2.0 | https://github.com/riscv/riscv-isa-manual/releases/download/Ratified-IMAFDQC/riscv-spec-20191213.pdf[Unprivileged ISA 20191213]
|
| 123 |
+
| `A` v2.1 | https://github.com/riscv/riscv-isa-manual/releases/download/Ratified-IMAFDQC/riscv-spec-20191213.pdf[Unprivileged ISA 20191213]
|
| 124 |
+
| `C` v2.0 | https://github.com/riscv/riscv-isa-manual/releases/download/Ratified-IMAFDQC/riscv-spec-20191213.pdf[Unprivileged ISA 20191213]
|
| 125 |
+
| `Zicsr` v2.0 | https://github.com/riscv/riscv-isa-manual/releases/download/Ratified-IMAFDQC/riscv-spec-20191213.pdf[Unprivileged ISA 20191213]
|
| 126 |
+
| `Zifencei` v2.0 | https://github.com/riscv/riscv-isa-manual/releases/download/Ratified-IMAFDQC/riscv-spec-20191213.pdf[Unprivileged ISA 20191213]
|
| 127 |
+
| `Zilsd` v1.0-rc3 | https://github.com/riscv/riscv-zilsd/releases/download/v1.0-rc3/riscv-zilsd-v1.0-rc3.pdf[Load/Store Pair for RV32 frozen v1.0-rc3]
|
| 128 |
+
| `Zba` v1.0.0 | https://github.com/riscv/riscv-bitmanip/releases/download/1.0.0/bitmanip-1.0.0-38-g865e7a7.pdf[Bit Manipulation ISA extensions 20210628]
|
| 129 |
+
| `Zbb` v1.0.0 | https://github.com/riscv/riscv-bitmanip/releases/download/1.0.0/bitmanip-1.0.0-38-g865e7a7.pdf[Bit Manipulation ISA extensions 20210628]
|
| 130 |
+
| `Zbc` v1.0.0 | https://github.com/riscv/riscv-bitmanip/releases/download/1.0.0/bitmanip-1.0.0-38-g865e7a7.pdf[Bit Manipulation ISA extensions 20210628]
|
| 131 |
+
| `Zbs` v1.0.0 | https://github.com/riscv/riscv-bitmanip/releases/download/1.0.0/bitmanip-1.0.0-38-g865e7a7.pdf[Bit Manipulation ISA extensions 20210628]
|
| 132 |
+
| `Zbkb` v1.0.1 | https://github.com/riscv/riscv-crypto/releases/download/v1.0.1-scalar/riscv-crypto-spec-scalar-v1.0.1.pdf[Scalar Cryptography ISA extensions 20220218]
|
| 133 |
+
| `Zbkx` v1.0.1 | https://github.com/riscv/riscv-crypto/releases/download/v1.0.1-scalar/riscv-crypto-spec-scalar-v1.0.1.pdf[Scalar Cryptography ISA extensions 20220218]
|
| 134 |
+
| `Zcb` v1.0.3-1 | https://github.com/riscv/riscv-code-size-reduction/releases/download/v1.0.3-1/Zc-v1.0.3-1.pdf[Code Size Reduction extensions frozen v1.0.3-1]
|
| 135 |
+
| `Zclsd` v1.0-rc3 | https://github.com/riscv/riscv-zilsd/releases/download/v1.0-rc3/riscv-zilsd-v1.0-rc3.pdf[Load/Store Pair for RV32 frozen v1.0-rc3]
|
| 136 |
+
| `Zcmp` v1.0.3-1 | https://github.com/riscv/riscv-code-size-reduction/releases/download/v1.0.3-1/Zc-v1.0.3-1.pdf[Code Size Reduction extensions frozen v1.0.3-1]
|
| 137 |
+
| Machine ISA v1.12 | https://github.com/riscv/riscv-isa-manual/releases/download/Priv-v1.12/riscv-privileged-20211203.pdf[Privileged Architecture 20211203]
|
| 138 |
+
| Debug v0.13.2 | https://riscv.org/wp-content/uploads/2019/03/riscv-debug-release.pdf[RISC-V External Debug Support 20190322]
|
| 139 |
+
|===
|
Wren6991_Hazard3/doc/sections/release_notes.adoc
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[[section-release-notes]]
|
| 2 |
+
== Release Notes
|
| 3 |
+
:sectnums!:
|
| 4 |
+
|
| 5 |
+
=== Version 1.1.1
|
| 6 |
+
|
| 7 |
+
Fixed errata:
|
| 8 |
+
|
| 9 |
+
* Fix repeated transfer when `hazard3_apb_async_bridge` is connected to a standard APB Requester.
|
| 10 |
+
** This behaviour did not affect instantiation inside of `hazard3_jtag_dtm`.
|
| 11 |
+
* Fix breakpoint trigger on a CSR write not inhibiting the write to the CSR register file.
|
| 12 |
+
* Fix non-synthesisable statement included in RVFI monitor when `HAZARD3_RVFI_STANDALONE` is defined.
|
| 13 |
+
|
| 14 |
+
Other changes:
|
| 15 |
+
|
| 16 |
+
* Improve riscv-formal coverage for AHB5 exclusives and the A extension.
|
| 17 |
+
|
| 18 |
+
See the Github release notes https://github.com/Wren6991/Hazard3/releases/tag/v1.1[here].
|
| 19 |
+
|
| 20 |
+
=== Version 1.1
|
| 21 |
+
|
| 22 |
+
Incompatible changes:
|
| 23 |
+
|
| 24 |
+
* The `MHARTID_VAL` parameter has been removed, and replaced with the `mhartid_val` port.
|
| 25 |
+
* The `MIMPID_VAL` parameter has been removed.
|
| 26 |
+
* The <<reg-mimpid>> CSR has been redefined to contain the hardcoded Hazard3 release version.
|
| 27 |
+
|
| 28 |
+
New signals:
|
| 29 |
+
|
| 30 |
+
* `fence_i_vld`, `fence_d_vld` and `fence_rdy` allow external hardware to enforce memory orderings or trigger cache flushes (see <<memory-ordering-signals,Memory Ordering Signals>>).
|
| 31 |
+
* `mhartid_val` allows a dynamic `mhartid` CSR value.
|
| 32 |
+
* `eco_version` allows modifying part of the processor's reported version number (see <<reg-mimpid>>).
|
| 33 |
+
|
| 34 |
+
New features:
|
| 35 |
+
|
| 36 |
+
* Implement the Zilsd extension (load/store pair), enabled by <<param-EXTENSION_ZILSD>>.
|
| 37 |
+
* Implement the Zclsd extension (compressed load/store pair), enabled by <<param-EXTENSION_ZCLSD>>.
|
| 38 |
+
* Implement the Zbkx extension (crossbar permutation), enabled by <<param-EXTENSION_ZBKX>>.
|
| 39 |
+
* Implement TOR region support for PMP, enabled by <<param-PMP_MATCH_TOR>>.
|
| 40 |
+
** NAPOT/NA4 matching is now optional, enabled by <<param-PMP_MATCH_NAPOT>>.
|
| 41 |
+
* Implement interrupt, exception and instruction count trigger in the <<section-trigger-module>>.
|
| 42 |
+
** These triggers are present whenever debug support is enabled by <<param-DEBUG_SUPPORT>>.
|
| 43 |
+
* Implement the RV32E base extension, enabled by <<param-EXTENSION_E>>.
|
| 44 |
+
* Implement new custom extension: <<extension-xh3misa-section>>, for detecting processor ISA support at finer granularity than the standard `misa` register. Enabled by `CSR_M_MANDATORY`, so it is reliably present.
|
| 45 |
+
* Add `hazard3_xilinx7_jtag_dtm` for tunneling RISC-V debug through Xilinx 7-series FPGA TAPs.
|
| 46 |
+
|
| 47 |
+
Fixed errata:
|
| 48 |
+
|
| 49 |
+
* Fix `fence.i` only ordering against the address phase of a preceding store (a multi-manager AHB fabric may reorder address phases, so order against the data phase instead).
|
| 50 |
+
* Fix local monitor flag being cleared by trap entry as well as trap exit (only `xRET` should clear it).
|
| 51 |
+
** This behaviour continues to not affect entry/exit to Debug Mode, so LR/SC sequences can be single-stepped.
|
| 52 |
+
* Fix the Debug Module PROGBUF1 register being writable when an abstract command is executing, and not setting `abstracts.cmderr` to `busy` when written.
|
| 53 |
+
* Fix spurious dependency of CSR instructions on `rs2`, causing read-after-write stall.
|
| 54 |
+
* Fix processor lockup on AMOs that fail PMP checks.
|
| 55 |
+
* Fix Debug Mode loads and stores during Program Buffer execution being subject to PMP checks on M-mode-enforced (locked) regions.
|
| 56 |
+
* Fix a data-phase fault on the final load of a `cm.popret` which loads at least two registers reporting the return address as the exception PC.
|
| 57 |
+
** The following were not affected: `cm.pop`, `cm.popretz`, 1-register `cm.popret`, PMP traps and alignment traps.
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
PPA optimisations:
|
| 61 |
+
|
| 62 |
+
* Move breakpoint PC comparator from stage 2 to stage 1.
|
| 63 |
+
* Move PMP X permission lookup from stage 2 to stage 1.
|
| 64 |
+
* Simplify PMP X permission lookup by looking up naturally-aligned fetches instead of both halfwords of a potentially unaligned instruction.
|
| 65 |
+
* Move compressed instruction expansion from stage 2 to stage 1.
|
| 66 |
+
* Pre-decode `rs1`/`rs2` bypass controls in stage 1.
|
| 67 |
+
* Restore register on `op_b` input of `hazard3_muldiv_seq` for better routing locality.
|
| 68 |
+
|
| 69 |
+
General improvements:
|
| 70 |
+
|
| 71 |
+
* Relax PMP X permission checking to allow instructions to straddle two PMP regions which both have the necessary permissions.
|
| 72 |
+
* RTL is now lint-clean with Verilator v5.038.
|
| 73 |
+
* Add Verilator testbench, command-line-compatible with existing CXXRTL testbench.
|
| 74 |
+
* Update to latest versions of `riscv-arch-test`, `riscv-test` and `riscv-formal`.
|
| 75 |
+
* Enable `riscv-formal` checks for B extension and other bit manipulation extensions.
|
| 76 |
+
* Update `hazard3_rvfi_monitor` to support running existing `riscv-formal` checks with the A, Zcmp, Zilsd and Zclsd extensions enabled.
|
| 77 |
+
* Allow synthesising the processor with the RVFI trace monitor included by defining the `HAZARD3_RVFI_STANDALONE` macro.
|
| 78 |
+
** This is an intermediate step towards E-trace support, and useful for tracing processor execution on FPGA or in simulation.
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
Other changes:
|
| 82 |
+
|
| 83 |
+
* Writes to CSRs which affect instruction fetch now cost three cycles plus an additional cycle if the following instruction is unaligned 32-bit.
|
| 84 |
+
** Specifically this affects `pmpaddr*`, `pmpcfg*`, `tcontrol`, `tdata1` and `tdata2`.
|
| 85 |
+
** These CSR writes now require an instruction fetch flush to enforce the necessary orderings.
|
| 86 |
+
** All other CSRs remain single-cycle write.
|
| 87 |
+
* Writes to `minstret`/`minstreth` or `mcycle`/`mcycleh` now inhibit the increment of the entire underlying 64-bit counter.
|
| 88 |
+
** The spec wording was recently changed to clarify this issue: see https://github.com/riscv/riscv-isa-manual/issues/1255[here].
|
| 89 |
+
|
| 90 |
+
See the Github release notes https://github.com/Wren6991/Hazard3/releases/tag/v1.1[here].
|
| 91 |
+
|
| 92 |
+
=== Version 1.0.2
|
| 93 |
+
|
| 94 |
+
* Coding style change in `hazard3_frontend` for Verilator compatibility
|
| 95 |
+
|
| 96 |
+
See the Github release notes https://github.com/Wren6991/Hazard3/releases/tag/v1.0.2[here].
|
| 97 |
+
|
| 98 |
+
=== Version 1.0.1
|
| 99 |
+
|
| 100 |
+
* Fix: abstract access commands initiated via `abstractauto` access the wrong core GPR
|
| 101 |
+
|
| 102 |
+
See the Github release notes https://github.com/Wren6991/Hazard3/releases/tag/v1.0.1[here].
|
| 103 |
+
|
| 104 |
+
=== Version 1.0
|
| 105 |
+
|
| 106 |
+
This is the first stable version of Hazard3. See the Github release notes https://github.com/Wren6991/Hazard3/releases/tag/v1.0[here].
|
Wren6991_Hazard3/example_soc/arty7-openocd.cfg
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Notes on Arty A7 FTDI JTAG connectivity
|
| 2 |
+
# (Digilent censored their schematic, lol):
|
| 3 |
+
#
|
| 4 |
+
# TCK (out) is ADBUS0
|
| 5 |
+
# TDI (out) is ADBUS1
|
| 6 |
+
# TDO (in) is ADBUS2
|
| 7 |
+
# TMS (out) is ADBUS3
|
| 8 |
+
#
|
| 9 |
+
# Supply monitoring (in) is on ADBUS4
|
| 10 |
+
#
|
| 11 |
+
# Reset output is ADBUS6
|
| 12 |
+
#
|
| 13 |
+
# LED LD9 is connected to bit 0x0800, active-low
|
| 14 |
+
# LED LD10 is connected to bit 0x1000, active-low
|
| 15 |
+
|
| 16 |
+
adapter driver ftdi
|
| 17 |
+
adapter speed 10000
|
| 18 |
+
ftdi vid_pid 0x0403 0x6010
|
| 19 |
+
ftdi channel 0
|
| 20 |
+
ftdi layout_init 0x00e8 0x60eb
|
| 21 |
+
|
| 22 |
+
transport select jtag
|
| 23 |
+
|
| 24 |
+
set _CHIPNAME artix7
|
| 25 |
+
jtag newtap artix7 hazard3 -expected-id 0x13631093 -irlen 6
|
| 26 |
+
|
| 27 |
+
set _TARGETNAME $_CHIPNAME.hazard3
|
| 28 |
+
target create $_TARGETNAME riscv -chain-position $_TARGETNAME
|
| 29 |
+
riscv set_ir dtmcs 0x22
|
| 30 |
+
riscv set_ir dmi 0x23
|
| 31 |
+
|
| 32 |
+
gdb_report_data_abort enable
|
| 33 |
+
init
|
| 34 |
+
halt
|
Wren6991_Hazard3/example_soc/fpga/fpga_arty_a7.f
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
file fpga_arty_a7.v
|
| 2 |
+
file ../libfpga/common/reset_sync.v
|
| 3 |
+
file ../libfpga/common/fpga_reset.v
|
| 4 |
+
file ../libfpga/common/blinky.v
|
| 5 |
+
|
| 6 |
+
list ../soc/soc.f
|
| 7 |
+
|
| 8 |
+
file ../../hdl/debug/dtm/hazard3_xilinx7_jtag_dtm.v
|
| 9 |
+
|
Wren6991_Hazard3/example_soc/fpga/fpga_arty_a7.v
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*****************************************************************************\
|
| 2 |
+
| Copyright (C) 2021 Luke Wren |
|
| 3 |
+
| SPDX-License-Identifier: Apache-2.0 |
|
| 4 |
+
\*****************************************************************************/
|
| 5 |
+
|
| 6 |
+
`default_nettype none
|
| 7 |
+
|
| 8 |
+
module fpga (
|
| 9 |
+
input wire clk_osc,
|
| 10 |
+
|
| 11 |
+
output wire [3:0] led,
|
| 12 |
+
|
| 13 |
+
output wire uart_tx,
|
| 14 |
+
input wire uart_rx
|
| 15 |
+
);
|
| 16 |
+
|
| 17 |
+
wire clk_sys;
|
| 18 |
+
wire locked;
|
| 19 |
+
wire clkfbout;
|
| 20 |
+
wire clkfbout_buf;
|
| 21 |
+
BUFG bufg_clkfbout (
|
| 22 |
+
.I (clkfbout),
|
| 23 |
+
.O (clkfbout_buf)
|
| 24 |
+
);
|
| 25 |
+
|
| 26 |
+
// Configured for 100 -> 80 MHz
|
| 27 |
+
MMCME2_ADV #(
|
| 28 |
+
.BANDWIDTH ("OPTIMIZED"),
|
| 29 |
+
.CLKOUT4_CASCADE ("FALSE"),
|
| 30 |
+
.COMPENSATION ("ZHOLD"),
|
| 31 |
+
.STARTUP_WAIT ("FALSE"),
|
| 32 |
+
.DIVCLK_DIVIDE (1),
|
| 33 |
+
.CLKFBOUT_MULT_F (10.000),
|
| 34 |
+
.CLKFBOUT_PHASE (0.000),
|
| 35 |
+
.CLKFBOUT_USE_FINE_PS ("FALSE"),
|
| 36 |
+
.CLKOUT0_DIVIDE_F (12.500),
|
| 37 |
+
.CLKOUT0_PHASE (0.000),
|
| 38 |
+
.CLKOUT0_DUTY_CYCLE (0.500),
|
| 39 |
+
.CLKOUT0_USE_FINE_PS ("FALSE"),
|
| 40 |
+
.CLKIN1_PERIOD (10.000)
|
| 41 |
+
) mmcm_adv_inst (
|
| 42 |
+
.CLKFBOUT (clkfbout),
|
| 43 |
+
.CLKFBOUTB (/* unused */),
|
| 44 |
+
.CLKOUT0 (clk_sys),
|
| 45 |
+
.CLKOUT0B (/* unused */),
|
| 46 |
+
.CLKOUT1 (/* unused */),
|
| 47 |
+
.CLKOUT1B (/* unused */),
|
| 48 |
+
.CLKOUT2 (/* unused */),
|
| 49 |
+
.CLKOUT2B (/* unused */),
|
| 50 |
+
.CLKOUT3 (/* unused */),
|
| 51 |
+
.CLKOUT3B (/* unused */),
|
| 52 |
+
.CLKOUT4 (/* unused */),
|
| 53 |
+
.CLKOUT5 (/* unused */),
|
| 54 |
+
.CLKOUT6 (/* unused */),
|
| 55 |
+
// Input clock control
|
| 56 |
+
.CLKFBIN (clkfbout_buf),
|
| 57 |
+
.CLKIN1 (clk_osc),
|
| 58 |
+
.CLKIN2 (1'b0),
|
| 59 |
+
// Tied to always select the primary input clock
|
| 60 |
+
.CLKINSEL (1'b1),
|
| 61 |
+
// Ports for dynamic reconfiguration
|
| 62 |
+
.DADDR (7'h0),
|
| 63 |
+
.DCLK (1'b0),
|
| 64 |
+
.DEN (1'b0),
|
| 65 |
+
.DI (16'h0),
|
| 66 |
+
.DO (/* unused */),
|
| 67 |
+
.DRDY (/* unused */),
|
| 68 |
+
.DWE (1'b0),
|
| 69 |
+
// Ports for dynamic phase shift
|
| 70 |
+
.PSCLK (1'b0),
|
| 71 |
+
.PSEN (1'b0),
|
| 72 |
+
.PSINCDEC (1'b0),
|
| 73 |
+
.PSDONE (/* unused */),
|
| 74 |
+
// Other control and status signals
|
| 75 |
+
.LOCKED (locked),
|
| 76 |
+
.CLKINSTOPPED (/* unused */),
|
| 77 |
+
.CLKFBSTOPPED (/* unused */),
|
| 78 |
+
.PWRDWN (1'b0),
|
| 79 |
+
.RST (1'b0) // TODO???
|
| 80 |
+
);
|
| 81 |
+
|
| 82 |
+
blinky #(
|
| 83 |
+
.CLK_HZ (100_000_000),
|
| 84 |
+
.BLINK_HZ (1)
|
| 85 |
+
) blinky_clk_osc (
|
| 86 |
+
.clk (clk_osc),
|
| 87 |
+
.blink (led[0])
|
| 88 |
+
);
|
| 89 |
+
|
| 90 |
+
blinky #(
|
| 91 |
+
.CLK_HZ (80_000_000),
|
| 92 |
+
.BLINK_HZ (2)
|
| 93 |
+
) blinky_clk_sys (
|
| 94 |
+
.clk (clk_sys),
|
| 95 |
+
.blink (led[1])
|
| 96 |
+
);
|
| 97 |
+
|
| 98 |
+
wire rst_n_sys;
|
| 99 |
+
|
| 100 |
+
fpga_reset #(
|
| 101 |
+
.SHIFT (3)
|
| 102 |
+
) rstgen (
|
| 103 |
+
.clk (clk_sys),
|
| 104 |
+
.force_rst_n (1'b1),
|
| 105 |
+
.rst_n (rst_n_sys)
|
| 106 |
+
);
|
| 107 |
+
|
| 108 |
+
example_soc #(
|
| 109 |
+
.DTM_TYPE ("XILINX7"),
|
| 110 |
+
|
| 111 |
+
.SRAM_DEPTH (1 << 15),
|
| 112 |
+
|
| 113 |
+
.CLK_MHZ (80),
|
| 114 |
+
|
| 115 |
+
.EXTENSION_A (1),
|
| 116 |
+
.EXTENSION_C (0),
|
| 117 |
+
.EXTENSION_M (1),
|
| 118 |
+
.EXTENSION_ZBA (0),
|
| 119 |
+
.EXTENSION_ZBB (0),
|
| 120 |
+
.EXTENSION_ZBC (0),
|
| 121 |
+
.EXTENSION_ZBS (0),
|
| 122 |
+
.EXTENSION_ZBKB (0),
|
| 123 |
+
.EXTENSION_ZCMP (0),
|
| 124 |
+
.EXTENSION_ZCLSD (0),
|
| 125 |
+
.EXTENSION_ZCB (0),
|
| 126 |
+
.EXTENSION_ZILSD (0),
|
| 127 |
+
.EXTENSION_ZIFENCEI (0),
|
| 128 |
+
.EXTENSION_XH3BEXTM (0),
|
| 129 |
+
.EXTENSION_XH3PMPM (0),
|
| 130 |
+
.EXTENSION_XH3POWER (0),
|
| 131 |
+
|
| 132 |
+
.CSR_COUNTER (0),
|
| 133 |
+
.U_MODE (0),
|
| 134 |
+
.PMP_REGIONS (0),
|
| 135 |
+
.BREAKPOINT_TRIGGERS (0),
|
| 136 |
+
.IRQ_PRIORITY_BITS (0),
|
| 137 |
+
.REDUCED_BYPASS (0),
|
| 138 |
+
.MULDIV_UNROLL (1),
|
| 139 |
+
.MUL_FAST (0),
|
| 140 |
+
.MUL_FASTER (0),
|
| 141 |
+
.MULH_FAST (0),
|
| 142 |
+
.FAST_BRANCHCMP (1),
|
| 143 |
+
.BRANCH_PREDICTOR (0)
|
| 144 |
+
) soc_u (
|
| 145 |
+
.clk (clk_sys),
|
| 146 |
+
.rst_n (rst_n_sys),
|
| 147 |
+
|
| 148 |
+
.tck (1'b0),
|
| 149 |
+
.trst_n (1'b0),
|
| 150 |
+
.tms (1'b0),
|
| 151 |
+
.tdi (1'b0),
|
| 152 |
+
.tdo (/* unused */),
|
| 153 |
+
|
| 154 |
+
.uart_tx (uart_tx),
|
| 155 |
+
.uart_rx (uart_rx)
|
| 156 |
+
);
|
| 157 |
+
|
| 158 |
+
endmodule
|
Wren6991_Hazard3/example_soc/fpga/fpga_icebreaker.f
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
file fpga_icebreaker.v
|
| 2 |
+
file ../libfpga/common/reset_sync.v
|
| 3 |
+
file ../libfpga/common/fpga_reset.v
|
| 4 |
+
list ../libfpga/common/activity_led.f
|
| 5 |
+
|
| 6 |
+
list ../soc/soc.f
|
Wren6991_Hazard3/example_soc/fpga/fpga_icebreaker.v
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*****************************************************************************\
|
| 2 |
+
| Copyright (C) 2021 Luke Wren |
|
| 3 |
+
| SPDX-License-Identifier: Apache-2.0 |
|
| 4 |
+
\*****************************************************************************/
|
| 5 |
+
|
| 6 |
+
// FPGA toplevel for ../soc/example_soc.v on an iCEBreaker dev board
|
| 7 |
+
|
| 8 |
+
`default_nettype none
|
| 9 |
+
|
| 10 |
+
module fpga_icebreaker (
|
| 11 |
+
input wire clk_osc,
|
| 12 |
+
|
| 13 |
+
// No external trst_n as iCEBreaker can't easily drive it from FTDI, so we
|
| 14 |
+
// generate a pulse internally from FPGA PoR.
|
| 15 |
+
input wire tck,
|
| 16 |
+
input wire tms,
|
| 17 |
+
input wire tdi,
|
| 18 |
+
output wire tdo,
|
| 19 |
+
|
| 20 |
+
output wire led,
|
| 21 |
+
|
| 22 |
+
output wire mirror_tck,
|
| 23 |
+
output wire mirror_tms,
|
| 24 |
+
output wire mirror_tdi,
|
| 25 |
+
output wire mirror_tdo,
|
| 26 |
+
|
| 27 |
+
output wire uart_tx,
|
| 28 |
+
input wire uart_rx
|
| 29 |
+
);
|
| 30 |
+
|
| 31 |
+
assign mirror_tck = tck;
|
| 32 |
+
assign mirror_tms = tms;
|
| 33 |
+
assign mirror_tdi = tdi;
|
| 34 |
+
assign mirror_tdo = tdo;
|
| 35 |
+
|
| 36 |
+
wire clk_sys = clk_osc;
|
| 37 |
+
wire rst_n_sys;
|
| 38 |
+
wire trst_n;
|
| 39 |
+
|
| 40 |
+
fpga_reset #(
|
| 41 |
+
.SHIFT (3)
|
| 42 |
+
) rstgen (
|
| 43 |
+
.clk (clk_sys),
|
| 44 |
+
.force_rst_n (1'b1),
|
| 45 |
+
.rst_n (rst_n_sys)
|
| 46 |
+
);
|
| 47 |
+
|
| 48 |
+
reset_sync trst_sync_u (
|
| 49 |
+
.clk (tck),
|
| 50 |
+
.rst_n_in (rst_n_sys),
|
| 51 |
+
.rst_n_out (trst_n)
|
| 52 |
+
);
|
| 53 |
+
|
| 54 |
+
activity_led #(
|
| 55 |
+
.WIDTH (1 << 8),
|
| 56 |
+
.ACTIVE_LEVEL (1'b0)
|
| 57 |
+
) tck_led_u (
|
| 58 |
+
.clk (clk_sys),
|
| 59 |
+
.rst_n (rst_n_sys),
|
| 60 |
+
.i (tck),
|
| 61 |
+
.o (led)
|
| 62 |
+
);
|
| 63 |
+
|
| 64 |
+
example_soc #(
|
| 65 |
+
.CLK_MHZ (12),
|
| 66 |
+
.EXTENSION_A (1),
|
| 67 |
+
.EXTENSION_C (0),
|
| 68 |
+
.EXTENSION_M (1),
|
| 69 |
+
.EXTENSION_ZBA (0),
|
| 70 |
+
.EXTENSION_ZBB (0),
|
| 71 |
+
.EXTENSION_ZBC (0),
|
| 72 |
+
.EXTENSION_ZBS (0),
|
| 73 |
+
.EXTENSION_ZBKB (0),
|
| 74 |
+
.EXTENSION_ZIFENCEI (0),
|
| 75 |
+
.EXTENSION_XH3BEXTM (0),
|
| 76 |
+
.EXTENSION_XH3PMPM (0),
|
| 77 |
+
.EXTENSION_XH3POWER (0),
|
| 78 |
+
.CSR_COUNTER (0),
|
| 79 |
+
.U_MODE (0),
|
| 80 |
+
.PMP_REGIONS (0),
|
| 81 |
+
.BREAKPOINT_TRIGGERS (0),
|
| 82 |
+
.IRQ_PRIORITY_BITS (0),
|
| 83 |
+
.REDUCED_BYPASS (0),
|
| 84 |
+
.MULDIV_UNROLL (1),
|
| 85 |
+
.MUL_FAST (0),
|
| 86 |
+
.MUL_FASTER (0),
|
| 87 |
+
.MULH_FAST (0),
|
| 88 |
+
.FAST_BRANCHCMP (1),
|
| 89 |
+
.BRANCH_PREDICTOR (0)
|
| 90 |
+
) soc_u (
|
| 91 |
+
.clk (clk_sys),
|
| 92 |
+
.rst_n (rst_n_sys),
|
| 93 |
+
|
| 94 |
+
.tck (tck),
|
| 95 |
+
.trst_n (trst_n),
|
| 96 |
+
.tms (tms),
|
| 97 |
+
.tdi (tdi),
|
| 98 |
+
.tdo (tdo),
|
| 99 |
+
|
| 100 |
+
.uart_tx (uart_tx),
|
| 101 |
+
.uart_rx (uart_rx)
|
| 102 |
+
);
|
| 103 |
+
|
| 104 |
+
endmodule
|
Wren6991_Hazard3/example_soc/fpga/fpga_orangecrab_25f.f
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
file fpga_orangecrab_25f.v
|
| 2 |
+
file ../libfpga/common/reset_sync.v
|
| 3 |
+
file ../libfpga/common/fpga_reset.v
|
| 4 |
+
|
| 5 |
+
list ../soc/soc.f
|
| 6 |
+
|
| 7 |
+
# ECP5 DTM is not in main SoC list because the JTAGG primitive doesn't exist
|
| 8 |
+
# on most platforms
|
| 9 |
+
list ../../hdl/debug/dtm/hazard3_ecp5_jtag_dtm.f
|
| 10 |
+
|
Wren6991_Hazard3/example_soc/fpga/fpga_orangecrab_25f.v
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*****************************************************************************\
|
| 2 |
+
| Copyright (C) 2021 Luke Wren |
|
| 3 |
+
| SPDX-License-Identifier: Apache-2.0 |
|
| 4 |
+
\*****************************************************************************/
|
| 5 |
+
|
| 6 |
+
`default_nettype none
|
| 7 |
+
|
| 8 |
+
module fpga_orangecrab_25f (
|
| 9 |
+
input wire clk_osc,
|
| 10 |
+
output wire [7:0] dbg,
|
| 11 |
+
|
| 12 |
+
output wire uart_tx,
|
| 13 |
+
input wire uart_rx,
|
| 14 |
+
|
| 15 |
+
output rgb_led0_r,
|
| 16 |
+
output rgb_led0_g,
|
| 17 |
+
output rgb_led0_b,
|
| 18 |
+
|
| 19 |
+
output rst_n,
|
| 20 |
+
input usr_btn
|
| 21 |
+
);
|
| 22 |
+
|
| 23 |
+
wire clk_sys = clk_osc;
|
| 24 |
+
wire rst_n_sys;
|
| 25 |
+
wire trst_n;
|
| 26 |
+
|
| 27 |
+
fpga_reset #(
|
| 28 |
+
.SHIFT (3)
|
| 29 |
+
) rstgen (
|
| 30 |
+
.clk (clk_sys),
|
| 31 |
+
.force_rst_n (1'b1),
|
| 32 |
+
.rst_n (rst_n_sys)
|
| 33 |
+
);
|
| 34 |
+
|
| 35 |
+
example_soc #(
|
| 36 |
+
.DTM_TYPE ("ECP5"),
|
| 37 |
+
.SRAM_DEPTH (1 << 14),
|
| 38 |
+
.CLK_MHZ (48),
|
| 39 |
+
|
| 40 |
+
.EXTENSION_M (1),
|
| 41 |
+
.EXTENSION_A (1),
|
| 42 |
+
.EXTENSION_C (0),
|
| 43 |
+
.EXTENSION_ZBA (0),
|
| 44 |
+
.EXTENSION_ZBB (0),
|
| 45 |
+
.EXTENSION_ZBC (0),
|
| 46 |
+
.EXTENSION_ZBS (0),
|
| 47 |
+
.EXTENSION_ZBKB (0),
|
| 48 |
+
.EXTENSION_ZIFENCEI (1),
|
| 49 |
+
.EXTENSION_XH3BEXTM (0),
|
| 50 |
+
.EXTENSION_XH3PMPM (0),
|
| 51 |
+
.EXTENSION_XH3POWER (0),
|
| 52 |
+
.CSR_COUNTER (1),
|
| 53 |
+
.MUL_FAST (1),
|
| 54 |
+
.MUL_FASTER (0),
|
| 55 |
+
.MULH_FAST (0),
|
| 56 |
+
.MULDIV_UNROLL (1),
|
| 57 |
+
.FAST_BRANCHCMP (1),
|
| 58 |
+
.BRANCH_PREDICTOR (1)
|
| 59 |
+
) soc_u (
|
| 60 |
+
.clk (clk_sys),
|
| 61 |
+
.rst_n (rst_n_sys),
|
| 62 |
+
|
| 63 |
+
// JTAG connections provided internally by ECP5 JTAGG primitive
|
| 64 |
+
.tck (1'b0),
|
| 65 |
+
.trst_n (1'b0),
|
| 66 |
+
.tms (1'b0),
|
| 67 |
+
.tdi (1'b0),
|
| 68 |
+
.tdo (/* unused */),
|
| 69 |
+
|
| 70 |
+
.uart_tx (uart_tx),
|
| 71 |
+
.uart_rx (uart_rx)
|
| 72 |
+
);
|
| 73 |
+
|
| 74 |
+
// Create a 27 bit register
|
| 75 |
+
reg [26:0] counter = 0;
|
| 76 |
+
|
| 77 |
+
// Every positive edge increment register by 1
|
| 78 |
+
always @(posedge clk_sys) begin
|
| 79 |
+
counter <= counter + 1;
|
| 80 |
+
end
|
| 81 |
+
|
| 82 |
+
// Output inverted values of counter onto LEDs
|
| 83 |
+
assign rgb_led0_r = ~counter[24];
|
| 84 |
+
assign rgb_led0_g = ~counter[25];
|
| 85 |
+
assign rgb_led0_b = 0;
|
| 86 |
+
|
| 87 |
+
assign dbg = 8'hff;
|
| 88 |
+
|
| 89 |
+
// Reset logic on button press.
|
| 90 |
+
// this will enter the bootloader
|
| 91 |
+
reg reset_sr = 1'b1;
|
| 92 |
+
always @(posedge clk_sys) begin
|
| 93 |
+
reset_sr <= {usr_btn};
|
| 94 |
+
end
|
| 95 |
+
assign rst_n = reset_sr;
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
endmodule
|
Wren6991_Hazard3/example_soc/fpga/fpga_ulx3s.f
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
file fpga_ulx3s.v
|
| 2 |
+
file pll_25_50.v
|
| 3 |
+
file pll_25_40.v
|
| 4 |
+
file ../libfpga/common/reset_sync.v
|
| 5 |
+
file ../libfpga/common/fpga_reset.v
|
| 6 |
+
|
| 7 |
+
list ../soc/soc.f
|
| 8 |
+
|
| 9 |
+
# ECP5 DTM is not in main SoC list because the JTAGG primitive doesn't exist
|
| 10 |
+
# on most platforms
|
| 11 |
+
list ../../hdl/debug/dtm/hazard3_ecp5_jtag_dtm.f
|
| 12 |
+
|
Wren6991_Hazard3/example_soc/fpga/fpga_ulx3s.v
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*****************************************************************************\
|
| 2 |
+
| Copyright (C) 2021 Luke Wren |
|
| 3 |
+
| SPDX-License-Identifier: Apache-2.0 |
|
| 4 |
+
\*****************************************************************************/
|
| 5 |
+
|
| 6 |
+
`default_nettype none
|
| 7 |
+
|
| 8 |
+
module fpga_ulx3s (
|
| 9 |
+
input wire clk_osc,
|
| 10 |
+
output wire [7:0] dbg,
|
| 11 |
+
|
| 12 |
+
output wire uart_tx,
|
| 13 |
+
input wire uart_rx
|
| 14 |
+
);
|
| 15 |
+
|
| 16 |
+
wire clk_sys;
|
| 17 |
+
wire pll_sys_locked;
|
| 18 |
+
wire rst_n_sys;
|
| 19 |
+
|
| 20 |
+
pll_25_50 pll_sys (
|
| 21 |
+
.clkin (clk_osc),
|
| 22 |
+
.clkout0 (clk_sys),
|
| 23 |
+
.locked (pll_sys_locked)
|
| 24 |
+
);
|
| 25 |
+
|
| 26 |
+
fpga_reset #(
|
| 27 |
+
.SHIFT (3)
|
| 28 |
+
) rstgen (
|
| 29 |
+
.clk (clk_sys),
|
| 30 |
+
.force_rst_n (pll_sys_locked),
|
| 31 |
+
.rst_n (rst_n_sys)
|
| 32 |
+
);
|
| 33 |
+
|
| 34 |
+
example_soc #(
|
| 35 |
+
.DTM_TYPE ("ECP5"),
|
| 36 |
+
.SRAM_DEPTH (1 << 15),
|
| 37 |
+
.CLK_MHZ (50),
|
| 38 |
+
|
| 39 |
+
.EXTENSION_M (1),
|
| 40 |
+
.EXTENSION_A (1),
|
| 41 |
+
.EXTENSION_C (0),
|
| 42 |
+
.EXTENSION_ZBA (0),
|
| 43 |
+
.EXTENSION_ZBB (0),
|
| 44 |
+
.EXTENSION_ZBC (0),
|
| 45 |
+
.EXTENSION_ZBS (0),
|
| 46 |
+
.EXTENSION_ZBKB (0),
|
| 47 |
+
.EXTENSION_ZIFENCEI (1),
|
| 48 |
+
.EXTENSION_XH3BEXTM (0),
|
| 49 |
+
.EXTENSION_XH3PMPM (0),
|
| 50 |
+
.EXTENSION_XH3POWER (0),
|
| 51 |
+
.CSR_COUNTER (1),
|
| 52 |
+
.MUL_FAST (1),
|
| 53 |
+
.MUL_FASTER (0),
|
| 54 |
+
.MULH_FAST (0),
|
| 55 |
+
.MULDIV_UNROLL (1),
|
| 56 |
+
.FAST_BRANCHCMP (1),
|
| 57 |
+
.BRANCH_PREDICTOR (1)
|
| 58 |
+
) soc_u (
|
| 59 |
+
.clk (clk_sys),
|
| 60 |
+
.rst_n (rst_n_sys),
|
| 61 |
+
|
| 62 |
+
// JTAG connections provided internally by ECP5 JTAGG primitive
|
| 63 |
+
.tck (1'b0),
|
| 64 |
+
.trst_n (1'b0),
|
| 65 |
+
.tms (1'b0),
|
| 66 |
+
.tdi (1'b0),
|
| 67 |
+
.tdo (/* unused */),
|
| 68 |
+
|
| 69 |
+
.uart_tx (uart_tx),
|
| 70 |
+
.uart_rx (uart_rx)
|
| 71 |
+
);
|
| 72 |
+
|
| 73 |
+
assign dbg = 8'h00;
|
| 74 |
+
|
| 75 |
+
endmodule
|
Wren6991_Hazard3/example_soc/fpga/pll_25_40.v
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// diamond 3.7 accepts this PLL
|
| 2 |
+
// diamond 3.8-3.9 is untested
|
| 3 |
+
// diamond 3.10 or higher is likely to abort with error about unable to use feedback signal
|
| 4 |
+
// cause of this could be from wrong CPHASE/FPHASE parameters
|
| 5 |
+
module pll_25_40
|
| 6 |
+
(
|
| 7 |
+
input clkin, // 25 MHz, 0 deg
|
| 8 |
+
output clkout0, // 40 MHz, 0 deg
|
| 9 |
+
output locked
|
| 10 |
+
);
|
| 11 |
+
(* FREQUENCY_PIN_CLKI="25" *)
|
| 12 |
+
(* FREQUENCY_PIN_CLKOP="40" *)
|
| 13 |
+
(* ICP_CURRENT="12" *) (* LPF_RESISTOR="8" *) (* MFG_ENABLE_FILTEROPAMP="1" *) (* MFG_GMCREF_SEL="2" *)
|
| 14 |
+
EHXPLLL #(
|
| 15 |
+
.PLLRST_ENA("DISABLED"),
|
| 16 |
+
.INTFB_WAKE("DISABLED"),
|
| 17 |
+
.STDBY_ENABLE("DISABLED"),
|
| 18 |
+
.DPHASE_SOURCE("DISABLED"),
|
| 19 |
+
.OUTDIVIDER_MUXA("DIVA"),
|
| 20 |
+
.OUTDIVIDER_MUXB("DIVB"),
|
| 21 |
+
.OUTDIVIDER_MUXC("DIVC"),
|
| 22 |
+
.OUTDIVIDER_MUXD("DIVD"),
|
| 23 |
+
.CLKI_DIV(5),
|
| 24 |
+
.CLKOP_ENABLE("ENABLED"),
|
| 25 |
+
.CLKOP_DIV(15),
|
| 26 |
+
.CLKOP_CPHASE(7),
|
| 27 |
+
.CLKOP_FPHASE(0),
|
| 28 |
+
.FEEDBK_PATH("CLKOP"),
|
| 29 |
+
.CLKFB_DIV(8)
|
| 30 |
+
) pll_i (
|
| 31 |
+
.RST(1'b0),
|
| 32 |
+
.STDBY(1'b0),
|
| 33 |
+
.CLKI(clkin),
|
| 34 |
+
.CLKOP(clkout0),
|
| 35 |
+
.CLKFB(clkout0),
|
| 36 |
+
.CLKINTFB(),
|
| 37 |
+
.PHASESEL0(1'b0),
|
| 38 |
+
.PHASESEL1(1'b0),
|
| 39 |
+
.PHASEDIR(1'b1),
|
| 40 |
+
.PHASESTEP(1'b1),
|
| 41 |
+
.PHASELOADREG(1'b1),
|
| 42 |
+
.PLLWAKESYNC(1'b0),
|
| 43 |
+
.ENCLKOP(1'b0),
|
| 44 |
+
.LOCK(locked)
|
| 45 |
+
);
|
| 46 |
+
endmodule
|
Wren6991_Hazard3/example_soc/fpga/pll_25_50.v
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// diamond 3.7 accepts this PLL
|
| 2 |
+
// diamond 3.8-3.9 is untested
|
| 3 |
+
// diamond 3.10 or higher is likely to abort with error about unable to use feedback signal
|
| 4 |
+
// cause of this could be from wrong CPHASE/FPHASE parameters
|
| 5 |
+
module pll_25_50
|
| 6 |
+
(
|
| 7 |
+
input clkin, // 25 MHz, 0 deg
|
| 8 |
+
output clkout0, // 50 MHz, 0 deg
|
| 9 |
+
output locked
|
| 10 |
+
);
|
| 11 |
+
(* FREQUENCY_PIN_CLKI="25" *)
|
| 12 |
+
(* FREQUENCY_PIN_CLKOP="50" *)
|
| 13 |
+
(* ICP_CURRENT="12" *) (* LPF_RESISTOR="8" *) (* MFG_ENABLE_FILTEROPAMP="1" *) (* MFG_GMCREF_SEL="2" *)
|
| 14 |
+
EHXPLLL #(
|
| 15 |
+
.PLLRST_ENA("DISABLED"),
|
| 16 |
+
.INTFB_WAKE("DISABLED"),
|
| 17 |
+
.STDBY_ENABLE("DISABLED"),
|
| 18 |
+
.DPHASE_SOURCE("DISABLED"),
|
| 19 |
+
.OUTDIVIDER_MUXA("DIVA"),
|
| 20 |
+
.OUTDIVIDER_MUXB("DIVB"),
|
| 21 |
+
.OUTDIVIDER_MUXC("DIVC"),
|
| 22 |
+
.OUTDIVIDER_MUXD("DIVD"),
|
| 23 |
+
.CLKI_DIV(1),
|
| 24 |
+
.CLKOP_ENABLE("ENABLED"),
|
| 25 |
+
.CLKOP_DIV(12),
|
| 26 |
+
.CLKOP_CPHASE(5),
|
| 27 |
+
.CLKOP_FPHASE(0),
|
| 28 |
+
.FEEDBK_PATH("CLKOP"),
|
| 29 |
+
.CLKFB_DIV(2)
|
| 30 |
+
) pll_i (
|
| 31 |
+
.RST(1'b0),
|
| 32 |
+
.STDBY(1'b0),
|
| 33 |
+
.CLKI(clkin),
|
| 34 |
+
.CLKOP(clkout0),
|
| 35 |
+
.CLKFB(clkout0),
|
| 36 |
+
.CLKINTFB(),
|
| 37 |
+
.PHASESEL0(1'b0),
|
| 38 |
+
.PHASESEL1(1'b0),
|
| 39 |
+
.PHASEDIR(1'b1),
|
| 40 |
+
.PHASESTEP(1'b1),
|
| 41 |
+
.PHASELOADREG(1'b1),
|
| 42 |
+
.PLLWAKESYNC(1'b0),
|
| 43 |
+
.ENCLKOP(1'b0),
|
| 44 |
+
.LOCK(locked)
|
| 45 |
+
);
|
| 46 |
+
endmodule
|
Wren6991_Hazard3/example_soc/icebreaker-openocd.cfg
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
adapter driver ftdi
|
| 2 |
+
|
| 3 |
+
# 30 MHz -- a bit exciting but it seems reliable
|
| 4 |
+
adapter speed 30000
|
| 5 |
+
ftdi_tdo_sample_edge falling
|
| 6 |
+
|
| 7 |
+
# JTAG is on FTDI B channel so it doesn't inadvertently assert flash CS pin
|
| 8 |
+
# (usually UART would be on the B channel).
|
| 9 |
+
|
| 10 |
+
# Note TDO/TMS require two of the solder jumpers on the back of the board to
|
| 11 |
+
# be bridged. On the v1.0e board these are jumpers J3/J4. To find these, look
|
| 12 |
+
# for the box of 5 x 2 jumpers (with a few others hanging off the side) and
|
| 13 |
+
# they are the two in the central column. They line up with the space in
|
| 14 |
+
# between "Jump" and "for" in the silk text "Jump for FTDI FIFO".
|
| 15 |
+
|
| 16 |
+
ftdi_device_desc "Dual RS232-HS"
|
| 17 |
+
ftdi_vid_pid 0x0403 0x6010
|
| 18 |
+
# Use BDBUS0-3 on iCEBreaker to avoid toggling flash chip select
|
| 19 |
+
ftdi_channel 1
|
| 20 |
+
|
| 21 |
+
ftdi_layout_init 0x0000 0xffff
|
| 22 |
+
|
| 23 |
+
set _CHIPNAME hazard3
|
| 24 |
+
jtag newtap $_CHIPNAME cpu -irlen 5
|
| 25 |
+
set _TARGETNAME $_CHIPNAME.cpu
|
| 26 |
+
target create $_TARGETNAME riscv -chain-position $_TARGETNAME
|
| 27 |
+
|
| 28 |
+
gdb_report_data_abort enable
|
| 29 |
+
init
|
| 30 |
+
halt
|
Wren6991_Hazard3/example_soc/project_paths.mk
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Link up to project root
|
| 2 |
+
include $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/../project_paths.mk
|
Wren6991_Hazard3/example_soc/soc/example_soc.v
ADDED
|
@@ -0,0 +1,613 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*****************************************************************************\
|
| 2 |
+
| Copyright (C) 2021-2022 Luke Wren |
|
| 3 |
+
| SPDX-License-Identifier: Apache-2.0 |
|
| 4 |
+
\*****************************************************************************/
|
| 5 |
+
|
| 6 |
+
// Example file integrating a Hazard3 processor, processor JTAG + debug
|
| 7 |
+
// components, some memory and a UART.
|
| 8 |
+
|
| 9 |
+
`default_nettype none
|
| 10 |
+
|
| 11 |
+
module example_soc #(
|
| 12 |
+
parameter DTM_TYPE = "JTAG", // Can be "JTAG", "ECP5" or "XILINX7"
|
| 13 |
+
parameter SRAM_DEPTH = 1 << 15, // Default 32 kwords -> 128 kB
|
| 14 |
+
parameter CLK_MHZ = 12, // For timer timebase
|
| 15 |
+
|
| 16 |
+
`include "hazard3_config.vh"
|
| 17 |
+
) (
|
| 18 |
+
// System clock + reset
|
| 19 |
+
input wire clk,
|
| 20 |
+
input wire rst_n,
|
| 21 |
+
|
| 22 |
+
// JTAG port to RISC-V JTAG-DTM
|
| 23 |
+
input wire tck,
|
| 24 |
+
input wire trst_n,
|
| 25 |
+
input wire tms,
|
| 26 |
+
input wire tdi,
|
| 27 |
+
output wire tdo,
|
| 28 |
+
|
| 29 |
+
// IO
|
| 30 |
+
output wire uart_tx,
|
| 31 |
+
input wire uart_rx
|
| 32 |
+
);
|
| 33 |
+
|
| 34 |
+
// ----------------------------------------------------------------------------
|
| 35 |
+
// Processor debug
|
| 36 |
+
|
| 37 |
+
wire dmi_psel;
|
| 38 |
+
wire dmi_penable;
|
| 39 |
+
wire dmi_pwrite;
|
| 40 |
+
wire [8:0] dmi_paddr;
|
| 41 |
+
wire [31:0] dmi_pwdata;
|
| 42 |
+
wire [31:0] dmi_prdata;
|
| 43 |
+
wire dmi_pready;
|
| 44 |
+
wire dmi_pslverr;
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
// TCK-domain DTM logic can force a hard reset
|
| 48 |
+
wire dmihardreset_req;
|
| 49 |
+
wire assert_dmi_reset = !rst_n || dmihardreset_req;
|
| 50 |
+
wire rst_n_dmi;
|
| 51 |
+
|
| 52 |
+
reset_sync dmi_reset_sync_u (
|
| 53 |
+
.clk (clk),
|
| 54 |
+
.rst_n_in (!assert_dmi_reset),
|
| 55 |
+
.rst_n_out (rst_n_dmi)
|
| 56 |
+
);
|
| 57 |
+
|
| 58 |
+
generate
|
| 59 |
+
if (DTM_TYPE == "JTAG") begin
|
| 60 |
+
|
| 61 |
+
// Standard RISC-V JTAG-DTM connected to external IOs.
|
| 62 |
+
// JTAG-DTM IDCODE should be a JEP106-compliant ID:
|
| 63 |
+
localparam IDCODE = 32'hdeadbeef;
|
| 64 |
+
|
| 65 |
+
hazard3_jtag_dtm #(
|
| 66 |
+
.IDCODE (IDCODE)
|
| 67 |
+
) dtm_u (
|
| 68 |
+
.tck (tck),
|
| 69 |
+
.trst_n (trst_n),
|
| 70 |
+
.tms (tms),
|
| 71 |
+
.tdi (tdi),
|
| 72 |
+
.tdo (tdo),
|
| 73 |
+
|
| 74 |
+
.dmihardreset_req (dmihardreset_req),
|
| 75 |
+
|
| 76 |
+
.clk_dmi (clk),
|
| 77 |
+
.rst_n_dmi (rst_n_dmi),
|
| 78 |
+
|
| 79 |
+
.dmi_psel (dmi_psel),
|
| 80 |
+
.dmi_penable (dmi_penable),
|
| 81 |
+
.dmi_pwrite (dmi_pwrite),
|
| 82 |
+
.dmi_paddr (dmi_paddr),
|
| 83 |
+
.dmi_pwdata (dmi_pwdata),
|
| 84 |
+
.dmi_prdata (dmi_prdata),
|
| 85 |
+
.dmi_pready (dmi_pready),
|
| 86 |
+
.dmi_pslverr (dmi_pslverr)
|
| 87 |
+
);
|
| 88 |
+
|
| 89 |
+
end else if (DTM_TYPE == "ECP5") begin
|
| 90 |
+
|
| 91 |
+
// Attach RISC-V DTM's DTMCS/DMI registers to ECP5 ER1/ER2 registers. This
|
| 92 |
+
// allows the processor to be debugged through the ECP5 chip TAP, using
|
| 93 |
+
// regular upstream OpenOCD.
|
| 94 |
+
|
| 95 |
+
// Connects to ECP5 TAP internally by instantiating a JTAGG primitive.
|
| 96 |
+
assign tdo = 1'b0;
|
| 97 |
+
|
| 98 |
+
hazard3_ecp5_jtag_dtm dtm_u (
|
| 99 |
+
.dmihardreset_req (dmihardreset_req),
|
| 100 |
+
|
| 101 |
+
.clk_dmi (clk),
|
| 102 |
+
.rst_n_dmi (rst_n_dmi),
|
| 103 |
+
|
| 104 |
+
.dmi_psel (dmi_psel),
|
| 105 |
+
.dmi_penable (dmi_penable),
|
| 106 |
+
.dmi_pwrite (dmi_pwrite),
|
| 107 |
+
.dmi_paddr (dmi_paddr),
|
| 108 |
+
.dmi_pwdata (dmi_pwdata),
|
| 109 |
+
.dmi_prdata (dmi_prdata),
|
| 110 |
+
.dmi_pready (dmi_pready),
|
| 111 |
+
.dmi_pslverr (dmi_pslverr)
|
| 112 |
+
);
|
| 113 |
+
|
| 114 |
+
end else if (DTM_TYPE == "XILINX7") begin
|
| 115 |
+
|
| 116 |
+
assign tdo = 1'b0;
|
| 117 |
+
|
| 118 |
+
hazard3_xilinx7_jtag_dtm dtm_u (
|
| 119 |
+
.dmihardreset_req (dmihardreset_req),
|
| 120 |
+
|
| 121 |
+
.clk_dmi (clk),
|
| 122 |
+
.rst_n_dmi (rst_n_dmi),
|
| 123 |
+
|
| 124 |
+
.dmi_psel (dmi_psel),
|
| 125 |
+
.dmi_penable (dmi_penable),
|
| 126 |
+
.dmi_pwrite (dmi_pwrite),
|
| 127 |
+
.dmi_paddr (dmi_paddr),
|
| 128 |
+
.dmi_pwdata (dmi_pwdata),
|
| 129 |
+
.dmi_prdata (dmi_prdata),
|
| 130 |
+
.dmi_pready (dmi_pready),
|
| 131 |
+
.dmi_pslverr (dmi_pslverr)
|
| 132 |
+
);
|
| 133 |
+
|
| 134 |
+
end
|
| 135 |
+
endgenerate
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
localparam N_HARTS = 1;
|
| 139 |
+
localparam XLEN = 32;
|
| 140 |
+
|
| 141 |
+
wire sys_reset_req;
|
| 142 |
+
wire sys_reset_done;
|
| 143 |
+
wire [N_HARTS-1:0] hart_reset_req;
|
| 144 |
+
wire [N_HARTS-1:0] hart_reset_done;
|
| 145 |
+
|
| 146 |
+
wire [N_HARTS-1:0] hart_req_halt;
|
| 147 |
+
wire [N_HARTS-1:0] hart_req_halt_on_reset;
|
| 148 |
+
wire [N_HARTS-1:0] hart_req_resume;
|
| 149 |
+
wire [N_HARTS-1:0] hart_halted;
|
| 150 |
+
wire [N_HARTS-1:0] hart_running;
|
| 151 |
+
|
| 152 |
+
wire [N_HARTS*XLEN-1:0] hart_data0_rdata;
|
| 153 |
+
wire [N_HARTS*XLEN-1:0] hart_data0_wdata;
|
| 154 |
+
wire [N_HARTS-1:0] hart_data0_wen;
|
| 155 |
+
|
| 156 |
+
wire [N_HARTS*XLEN-1:0] hart_instr_data;
|
| 157 |
+
wire [N_HARTS-1:0] hart_instr_data_vld;
|
| 158 |
+
wire [N_HARTS-1:0] hart_instr_data_rdy;
|
| 159 |
+
wire [N_HARTS-1:0] hart_instr_caught_exception;
|
| 160 |
+
wire [N_HARTS-1:0] hart_instr_caught_ebreak;
|
| 161 |
+
|
| 162 |
+
wire [31:0] sbus_addr;
|
| 163 |
+
wire sbus_write;
|
| 164 |
+
wire [1:0] sbus_size;
|
| 165 |
+
wire sbus_vld;
|
| 166 |
+
wire sbus_rdy;
|
| 167 |
+
wire sbus_err;
|
| 168 |
+
wire [31:0] sbus_wdata;
|
| 169 |
+
wire [31:0] sbus_rdata;
|
| 170 |
+
|
| 171 |
+
hazard3_dm #(
|
| 172 |
+
.N_HARTS (N_HARTS),
|
| 173 |
+
.HAVE_SBA (0),
|
| 174 |
+
.NEXT_DM_ADDR (0)
|
| 175 |
+
) dm (
|
| 176 |
+
.clk (clk),
|
| 177 |
+
.rst_n (rst_n),
|
| 178 |
+
|
| 179 |
+
.dmi_psel (dmi_psel),
|
| 180 |
+
.dmi_penable (dmi_penable),
|
| 181 |
+
.dmi_pwrite (dmi_pwrite),
|
| 182 |
+
.dmi_paddr (dmi_paddr),
|
| 183 |
+
.dmi_pwdata (dmi_pwdata),
|
| 184 |
+
.dmi_prdata (dmi_prdata),
|
| 185 |
+
.dmi_pready (dmi_pready),
|
| 186 |
+
.dmi_pslverr (dmi_pslverr),
|
| 187 |
+
|
| 188 |
+
.sys_reset_req (sys_reset_req),
|
| 189 |
+
.sys_reset_done (sys_reset_done),
|
| 190 |
+
.hart_reset_req (hart_reset_req),
|
| 191 |
+
.hart_reset_done (hart_reset_done),
|
| 192 |
+
|
| 193 |
+
.hart_req_halt (hart_req_halt),
|
| 194 |
+
.hart_req_halt_on_reset (hart_req_halt_on_reset),
|
| 195 |
+
.hart_req_resume (hart_req_resume),
|
| 196 |
+
.hart_halted (hart_halted),
|
| 197 |
+
.hart_running (hart_running),
|
| 198 |
+
|
| 199 |
+
.hart_data0_rdata (hart_data0_rdata),
|
| 200 |
+
.hart_data0_wdata (hart_data0_wdata),
|
| 201 |
+
.hart_data0_wen (hart_data0_wen),
|
| 202 |
+
|
| 203 |
+
.hart_instr_data (hart_instr_data),
|
| 204 |
+
.hart_instr_data_vld (hart_instr_data_vld),
|
| 205 |
+
.hart_instr_data_rdy (hart_instr_data_rdy),
|
| 206 |
+
.hart_instr_caught_exception (hart_instr_caught_exception),
|
| 207 |
+
.hart_instr_caught_ebreak (hart_instr_caught_ebreak),
|
| 208 |
+
|
| 209 |
+
.sbus_addr (sbus_addr),
|
| 210 |
+
.sbus_write (sbus_write),
|
| 211 |
+
.sbus_size (sbus_size),
|
| 212 |
+
.sbus_vld (sbus_vld),
|
| 213 |
+
.sbus_rdy (sbus_rdy),
|
| 214 |
+
.sbus_err (sbus_err),
|
| 215 |
+
.sbus_wdata (sbus_wdata),
|
| 216 |
+
.sbus_rdata (sbus_rdata)
|
| 217 |
+
);
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
// Generate resynchronised reset for CPU based on upstream system reset and on
|
| 221 |
+
// system/hart reset requests from DM.
|
| 222 |
+
|
| 223 |
+
wire assert_cpu_reset = !rst_n || sys_reset_req || hart_reset_req[0];
|
| 224 |
+
wire rst_n_cpu;
|
| 225 |
+
|
| 226 |
+
reset_sync cpu_reset_sync (
|
| 227 |
+
.clk (clk),
|
| 228 |
+
.rst_n_in (!assert_cpu_reset),
|
| 229 |
+
.rst_n_out (rst_n_cpu)
|
| 230 |
+
);
|
| 231 |
+
|
| 232 |
+
// Still some work to be done on the reset handshake -- this ought to be
|
| 233 |
+
// resynchronised to DM's reset domain here, and the DM should wait for a
|
| 234 |
+
// rising edge after it has asserted the reset pulse, to make sure the tail
|
| 235 |
+
// of the previous "done" is not passed on.
|
| 236 |
+
assign sys_reset_done = rst_n_cpu;
|
| 237 |
+
assign hart_reset_done = rst_n_cpu;
|
| 238 |
+
|
| 239 |
+
// ----------------------------------------------------------------------------
|
| 240 |
+
// Processor
|
| 241 |
+
|
| 242 |
+
wire [W_ADDR-1:0] proc_haddr;
|
| 243 |
+
wire proc_hwrite;
|
| 244 |
+
wire [1:0] proc_htrans;
|
| 245 |
+
wire [2:0] proc_hsize;
|
| 246 |
+
wire [2:0] proc_hburst;
|
| 247 |
+
wire [3:0] proc_hprot;
|
| 248 |
+
wire proc_hmastlock;
|
| 249 |
+
wire [7:0] proc_hmaster;
|
| 250 |
+
wire proc_hexcl;
|
| 251 |
+
wire proc_hready;
|
| 252 |
+
wire proc_hresp;
|
| 253 |
+
wire proc_hexokay = 1'b1; // No global monitor
|
| 254 |
+
wire [W_DATA-1:0] proc_hwdata;
|
| 255 |
+
wire [W_DATA-1:0] proc_hrdata;
|
| 256 |
+
|
| 257 |
+
wire pwrup_req;
|
| 258 |
+
wire unblock_out;
|
| 259 |
+
|
| 260 |
+
wire uart_irq;
|
| 261 |
+
wire timer_irq;
|
| 262 |
+
|
| 263 |
+
hazard3_cpu_1port #(
|
| 264 |
+
// These must have the values given here for you to end up with a useful SoC:
|
| 265 |
+
.RESET_VECTOR (32'h0000_0040),
|
| 266 |
+
.MTVEC_INIT (32'h0000_0000),
|
| 267 |
+
.CSR_M_MANDATORY (1),
|
| 268 |
+
.CSR_M_TRAP (1),
|
| 269 |
+
.DEBUG_SUPPORT (1),
|
| 270 |
+
.NUM_IRQS (1),
|
| 271 |
+
.RESET_REGFILE (0),
|
| 272 |
+
// Can be overridden from the defaults in hazard3_config.vh during
|
| 273 |
+
// instantiation of example_soc():
|
| 274 |
+
.EXTENSION_A (EXTENSION_A),
|
| 275 |
+
.EXTENSION_C (EXTENSION_C),
|
| 276 |
+
.EXTENSION_E (EXTENSION_E),
|
| 277 |
+
.EXTENSION_M (EXTENSION_M),
|
| 278 |
+
.EXTENSION_ZBA (EXTENSION_ZBA),
|
| 279 |
+
.EXTENSION_ZBB (EXTENSION_ZBB),
|
| 280 |
+
.EXTENSION_ZBC (EXTENSION_ZBC),
|
| 281 |
+
.EXTENSION_ZBKB (EXTENSION_ZBKB),
|
| 282 |
+
.EXTENSION_ZBKX (EXTENSION_ZBKX),
|
| 283 |
+
.EXTENSION_ZBS (EXTENSION_ZBS),
|
| 284 |
+
.EXTENSION_ZCB (EXTENSION_ZCB),
|
| 285 |
+
.EXTENSION_ZCLSD (EXTENSION_ZCLSD),
|
| 286 |
+
.EXTENSION_ZCMP (EXTENSION_ZCMP),
|
| 287 |
+
.EXTENSION_ZIFENCEI (EXTENSION_ZIFENCEI),
|
| 288 |
+
.EXTENSION_ZILSD (EXTENSION_ZILSD),
|
| 289 |
+
.EXTENSION_XH3BEXTM (EXTENSION_XH3BEXTM),
|
| 290 |
+
.EXTENSION_XH3IRQ (EXTENSION_XH3IRQ),
|
| 291 |
+
.EXTENSION_XH3PMPM (EXTENSION_XH3PMPM),
|
| 292 |
+
.EXTENSION_XH3POWER (EXTENSION_XH3POWER),
|
| 293 |
+
.CSR_COUNTER (CSR_COUNTER),
|
| 294 |
+
.U_MODE (U_MODE),
|
| 295 |
+
.PMP_REGIONS (PMP_REGIONS),
|
| 296 |
+
.PMP_GRAIN (PMP_GRAIN),
|
| 297 |
+
.PMP_HARDWIRED (PMP_HARDWIRED),
|
| 298 |
+
.PMP_HARDWIRED_ADDR (PMP_HARDWIRED_ADDR),
|
| 299 |
+
.PMP_HARDWIRED_CFG (PMP_HARDWIRED_CFG),
|
| 300 |
+
.MVENDORID_VAL (MVENDORID_VAL),
|
| 301 |
+
.BREAKPOINT_TRIGGERS (BREAKPOINT_TRIGGERS),
|
| 302 |
+
.IRQ_PRIORITY_BITS (IRQ_PRIORITY_BITS),
|
| 303 |
+
.REDUCED_BYPASS (REDUCED_BYPASS),
|
| 304 |
+
.MULDIV_UNROLL (MULDIV_UNROLL),
|
| 305 |
+
.MUL_FAST (MUL_FAST),
|
| 306 |
+
.MUL_FASTER (MUL_FASTER),
|
| 307 |
+
.MULH_FAST (MULH_FAST),
|
| 308 |
+
.FAST_BRANCHCMP (FAST_BRANCHCMP),
|
| 309 |
+
.BRANCH_PREDICTOR (BRANCH_PREDICTOR),
|
| 310 |
+
.MTVEC_WMASK (MTVEC_WMASK)
|
| 311 |
+
) cpu (
|
| 312 |
+
.clk (clk),
|
| 313 |
+
.clk_always_on (clk),
|
| 314 |
+
.rst_n (rst_n_cpu),
|
| 315 |
+
|
| 316 |
+
.pwrup_req (pwrup_req),
|
| 317 |
+
.pwrup_ack (pwrup_req), // Tied back
|
| 318 |
+
.clk_en (/* unused */),
|
| 319 |
+
.unblock_out (unblock_out),
|
| 320 |
+
.unblock_in (unblock_out), // Tied back
|
| 321 |
+
|
| 322 |
+
.haddr (proc_haddr),
|
| 323 |
+
.hwrite (proc_hwrite),
|
| 324 |
+
.htrans (proc_htrans),
|
| 325 |
+
.hsize (proc_hsize),
|
| 326 |
+
.hburst (proc_hburst),
|
| 327 |
+
.hprot (proc_hprot),
|
| 328 |
+
.hmastlock (proc_hmastlock),
|
| 329 |
+
.hmaster (proc_hmaster),
|
| 330 |
+
.hexcl (proc_hexcl),
|
| 331 |
+
.hready (proc_hready),
|
| 332 |
+
.hresp (proc_hresp),
|
| 333 |
+
.hexokay (proc_hexokay),
|
| 334 |
+
.hwdata (proc_hwdata),
|
| 335 |
+
.hrdata (proc_hrdata),
|
| 336 |
+
|
| 337 |
+
.fence_i_vld (/* unused */),
|
| 338 |
+
.fence_d_vld (/* unused */),
|
| 339 |
+
.fence_rdy (1'b1),
|
| 340 |
+
|
| 341 |
+
.dbg_req_halt (hart_req_halt),
|
| 342 |
+
.dbg_req_halt_on_reset (hart_req_halt_on_reset),
|
| 343 |
+
.dbg_req_resume (hart_req_resume),
|
| 344 |
+
.dbg_halted (hart_halted),
|
| 345 |
+
.dbg_running (hart_running),
|
| 346 |
+
|
| 347 |
+
.dbg_data0_rdata (hart_data0_rdata),
|
| 348 |
+
.dbg_data0_wdata (hart_data0_wdata),
|
| 349 |
+
.dbg_data0_wen (hart_data0_wen),
|
| 350 |
+
|
| 351 |
+
.dbg_instr_data (hart_instr_data),
|
| 352 |
+
.dbg_instr_data_vld (hart_instr_data_vld),
|
| 353 |
+
.dbg_instr_data_rdy (hart_instr_data_rdy),
|
| 354 |
+
.dbg_instr_caught_exception (hart_instr_caught_exception),
|
| 355 |
+
.dbg_instr_caught_ebreak (hart_instr_caught_ebreak),
|
| 356 |
+
|
| 357 |
+
.dbg_sbus_addr (sbus_addr),
|
| 358 |
+
.dbg_sbus_write (sbus_write),
|
| 359 |
+
.dbg_sbus_size (sbus_size),
|
| 360 |
+
.dbg_sbus_vld (sbus_vld),
|
| 361 |
+
.dbg_sbus_rdy (sbus_rdy),
|
| 362 |
+
.dbg_sbus_err (sbus_err),
|
| 363 |
+
.dbg_sbus_wdata (sbus_wdata),
|
| 364 |
+
.dbg_sbus_rdata (sbus_rdata),
|
| 365 |
+
|
| 366 |
+
.mhartid_val (32'd0),
|
| 367 |
+
.eco_version (4'd0),
|
| 368 |
+
|
| 369 |
+
.irq (uart_irq),
|
| 370 |
+
|
| 371 |
+
.soft_irq (1'b0),
|
| 372 |
+
.timer_irq (timer_irq)
|
| 373 |
+
);
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
// ----------------------------------------------------------------------------
|
| 377 |
+
// Bus fabric
|
| 378 |
+
|
| 379 |
+
// - 128 kB SRAM at... 0x0000_0000
|
| 380 |
+
// - System timer at.. 0x4000_0000
|
| 381 |
+
// - UART at.......... 0x4000_4000
|
| 382 |
+
|
| 383 |
+
// AHBL layer
|
| 384 |
+
|
| 385 |
+
wire sram0_hready_resp;
|
| 386 |
+
wire sram0_hready;
|
| 387 |
+
wire sram0_hresp;
|
| 388 |
+
wire [W_ADDR-1:0] sram0_haddr;
|
| 389 |
+
wire sram0_hwrite;
|
| 390 |
+
wire [1:0] sram0_htrans;
|
| 391 |
+
wire [2:0] sram0_hsize;
|
| 392 |
+
wire [2:0] sram0_hburst;
|
| 393 |
+
wire [3:0] sram0_hprot;
|
| 394 |
+
wire sram0_hmastlock;
|
| 395 |
+
wire [W_DATA-1:0] sram0_hwdata;
|
| 396 |
+
wire [W_DATA-1:0] sram0_hrdata;
|
| 397 |
+
|
| 398 |
+
wire bridge_hready_resp;
|
| 399 |
+
wire bridge_hready;
|
| 400 |
+
wire bridge_hresp;
|
| 401 |
+
wire [W_ADDR-1:0] bridge_haddr;
|
| 402 |
+
wire bridge_hwrite;
|
| 403 |
+
wire [1:0] bridge_htrans;
|
| 404 |
+
wire [2:0] bridge_hsize;
|
| 405 |
+
wire [2:0] bridge_hburst;
|
| 406 |
+
wire [3:0] bridge_hprot;
|
| 407 |
+
wire bridge_hmastlock;
|
| 408 |
+
wire [W_DATA-1:0] bridge_hwdata;
|
| 409 |
+
wire [W_DATA-1:0] bridge_hrdata;
|
| 410 |
+
|
| 411 |
+
ahbl_splitter #(
|
| 412 |
+
.N_PORTS (2),
|
| 413 |
+
.ADDR_MAP (64'h40000000_00000000),
|
| 414 |
+
.ADDR_MASK (64'he0000000_e0000000)
|
| 415 |
+
) splitter_u (
|
| 416 |
+
.clk (clk),
|
| 417 |
+
.rst_n (rst_n),
|
| 418 |
+
|
| 419 |
+
.src_hready_resp (proc_hready ),
|
| 420 |
+
.src_hready (proc_hready ),
|
| 421 |
+
.src_hresp (proc_hresp ),
|
| 422 |
+
.src_haddr (proc_haddr ),
|
| 423 |
+
.src_hwrite (proc_hwrite ),
|
| 424 |
+
.src_htrans (proc_htrans ),
|
| 425 |
+
.src_hsize (proc_hsize ),
|
| 426 |
+
.src_hburst (proc_hburst ),
|
| 427 |
+
.src_hprot (proc_hprot ),
|
| 428 |
+
.src_hmastlock (proc_hmastlock),
|
| 429 |
+
.src_hwdata (proc_hwdata ),
|
| 430 |
+
.src_hrdata (proc_hrdata ),
|
| 431 |
+
|
| 432 |
+
.dst_hready_resp ({bridge_hready_resp , sram0_hready_resp}),
|
| 433 |
+
.dst_hready ({bridge_hready , sram0_hready }),
|
| 434 |
+
.dst_hresp ({bridge_hresp , sram0_hresp }),
|
| 435 |
+
.dst_haddr ({bridge_haddr , sram0_haddr }),
|
| 436 |
+
.dst_hwrite ({bridge_hwrite , sram0_hwrite }),
|
| 437 |
+
.dst_htrans ({bridge_htrans , sram0_htrans }),
|
| 438 |
+
.dst_hsize ({bridge_hsize , sram0_hsize }),
|
| 439 |
+
.dst_hburst ({bridge_hburst , sram0_hburst }),
|
| 440 |
+
.dst_hprot ({bridge_hprot , sram0_hprot }),
|
| 441 |
+
.dst_hmastlock ({bridge_hmastlock , sram0_hmastlock }),
|
| 442 |
+
.dst_hwdata ({bridge_hwdata , sram0_hwdata }),
|
| 443 |
+
.dst_hrdata ({bridge_hrdata , sram0_hrdata })
|
| 444 |
+
);
|
| 445 |
+
|
| 446 |
+
// APB layer
|
| 447 |
+
|
| 448 |
+
wire bridge_psel;
|
| 449 |
+
wire bridge_penable;
|
| 450 |
+
wire bridge_pwrite;
|
| 451 |
+
wire [15:0] bridge_paddr;
|
| 452 |
+
wire [31:0] bridge_pwdata;
|
| 453 |
+
wire [31:0] bridge_prdata;
|
| 454 |
+
wire bridge_pready;
|
| 455 |
+
wire bridge_pslverr;
|
| 456 |
+
|
| 457 |
+
wire uart_psel;
|
| 458 |
+
wire uart_penable;
|
| 459 |
+
wire uart_pwrite;
|
| 460 |
+
wire [15:0] uart_paddr;
|
| 461 |
+
wire [31:0] uart_pwdata;
|
| 462 |
+
wire [31:0] uart_prdata;
|
| 463 |
+
wire uart_pready;
|
| 464 |
+
wire uart_pslverr;
|
| 465 |
+
|
| 466 |
+
wire timer_psel;
|
| 467 |
+
wire timer_penable;
|
| 468 |
+
wire timer_pwrite;
|
| 469 |
+
wire [15:0] timer_paddr;
|
| 470 |
+
wire [31:0] timer_pwdata;
|
| 471 |
+
wire [31:0] timer_prdata;
|
| 472 |
+
wire timer_pready;
|
| 473 |
+
wire timer_pslverr;
|
| 474 |
+
|
| 475 |
+
ahbl_to_apb apb_bridge_u (
|
| 476 |
+
.clk (clk),
|
| 477 |
+
.rst_n (rst_n),
|
| 478 |
+
|
| 479 |
+
.ahbls_hready (bridge_hready),
|
| 480 |
+
.ahbls_hready_resp (bridge_hready_resp),
|
| 481 |
+
.ahbls_hresp (bridge_hresp),
|
| 482 |
+
.ahbls_haddr (bridge_haddr),
|
| 483 |
+
.ahbls_hwrite (bridge_hwrite),
|
| 484 |
+
.ahbls_htrans (bridge_htrans),
|
| 485 |
+
.ahbls_hsize (bridge_hsize),
|
| 486 |
+
.ahbls_hburst (bridge_hburst),
|
| 487 |
+
.ahbls_hprot (bridge_hprot),
|
| 488 |
+
.ahbls_hmastlock (bridge_hmastlock),
|
| 489 |
+
.ahbls_hwdata (bridge_hwdata),
|
| 490 |
+
.ahbls_hrdata (bridge_hrdata),
|
| 491 |
+
|
| 492 |
+
.apbm_paddr (bridge_paddr),
|
| 493 |
+
.apbm_psel (bridge_psel),
|
| 494 |
+
.apbm_penable (bridge_penable),
|
| 495 |
+
.apbm_pwrite (bridge_pwrite),
|
| 496 |
+
.apbm_pwdata (bridge_pwdata),
|
| 497 |
+
.apbm_pready (bridge_pready),
|
| 498 |
+
.apbm_prdata (bridge_prdata),
|
| 499 |
+
.apbm_pslverr (bridge_pslverr)
|
| 500 |
+
);
|
| 501 |
+
|
| 502 |
+
apb_splitter #(
|
| 503 |
+
.N_SLAVES (2),
|
| 504 |
+
.ADDR_MAP (32'h4000_0000),
|
| 505 |
+
.ADDR_MASK (32'hc000_c000)
|
| 506 |
+
) inst_apb_splitter (
|
| 507 |
+
.apbs_paddr (bridge_paddr),
|
| 508 |
+
.apbs_psel (bridge_psel),
|
| 509 |
+
.apbs_penable (bridge_penable),
|
| 510 |
+
.apbs_pwrite (bridge_pwrite),
|
| 511 |
+
.apbs_pwdata (bridge_pwdata),
|
| 512 |
+
.apbs_pready (bridge_pready),
|
| 513 |
+
.apbs_prdata (bridge_prdata),
|
| 514 |
+
.apbs_pslverr (bridge_pslverr),
|
| 515 |
+
|
| 516 |
+
.apbm_paddr ({uart_paddr , timer_paddr }),
|
| 517 |
+
.apbm_psel ({uart_psel , timer_psel }),
|
| 518 |
+
.apbm_penable ({uart_penable , timer_penable}),
|
| 519 |
+
.apbm_pwrite ({uart_pwrite , timer_pwrite }),
|
| 520 |
+
.apbm_pwdata ({uart_pwdata , timer_pwdata }),
|
| 521 |
+
.apbm_pready ({uart_pready , timer_pready }),
|
| 522 |
+
.apbm_prdata ({uart_prdata , timer_prdata }),
|
| 523 |
+
.apbm_pslverr ({uart_pslverr , timer_pslverr})
|
| 524 |
+
);
|
| 525 |
+
|
| 526 |
+
// ----------------------------------------------------------------------------
|
| 527 |
+
// Memory and peripherals
|
| 528 |
+
|
| 529 |
+
// No preloaded bootloader -- just use the debugger! (the processor will
|
| 530 |
+
// actually enter an infinite crash loop after reset if memory is
|
| 531 |
+
// zero-initialised so don't leave the little guy hanging too long)
|
| 532 |
+
|
| 533 |
+
ahb_sync_sram #(
|
| 534 |
+
.DEPTH (SRAM_DEPTH)
|
| 535 |
+
) sram0 (
|
| 536 |
+
.clk (clk),
|
| 537 |
+
.rst_n (rst_n),
|
| 538 |
+
|
| 539 |
+
.ahbls_hready_resp (sram0_hready_resp),
|
| 540 |
+
.ahbls_hready (sram0_hready),
|
| 541 |
+
.ahbls_hresp (sram0_hresp),
|
| 542 |
+
.ahbls_haddr (sram0_haddr),
|
| 543 |
+
.ahbls_hwrite (sram0_hwrite),
|
| 544 |
+
.ahbls_htrans (sram0_htrans),
|
| 545 |
+
.ahbls_hsize (sram0_hsize),
|
| 546 |
+
.ahbls_hburst (sram0_hburst),
|
| 547 |
+
.ahbls_hprot (sram0_hprot),
|
| 548 |
+
.ahbls_hmastlock (sram0_hmastlock),
|
| 549 |
+
.ahbls_hwdata (sram0_hwdata),
|
| 550 |
+
.ahbls_hrdata (sram0_hrdata)
|
| 551 |
+
);
|
| 552 |
+
|
| 553 |
+
uart_mini uart_u (
|
| 554 |
+
.clk (clk),
|
| 555 |
+
.rst_n (rst_n),
|
| 556 |
+
|
| 557 |
+
.apbs_psel (uart_psel),
|
| 558 |
+
.apbs_penable (uart_penable),
|
| 559 |
+
.apbs_pwrite (uart_pwrite),
|
| 560 |
+
.apbs_paddr (uart_paddr),
|
| 561 |
+
.apbs_pwdata (uart_pwdata),
|
| 562 |
+
.apbs_prdata (uart_prdata),
|
| 563 |
+
.apbs_pready (uart_pready),
|
| 564 |
+
.apbs_pslverr (uart_pslverr),
|
| 565 |
+
|
| 566 |
+
.rx (uart_rx),
|
| 567 |
+
.tx (uart_tx),
|
| 568 |
+
.cts (1'b0),
|
| 569 |
+
.rts (/* unused */),
|
| 570 |
+
.irq (uart_irq),
|
| 571 |
+
.dreq (/* unused */)
|
| 572 |
+
);
|
| 573 |
+
|
| 574 |
+
// Microsecond timebase for timer
|
| 575 |
+
|
| 576 |
+
reg [$clog2(CLK_MHZ)-1:0] timer_tick_ctr;
|
| 577 |
+
reg timer_tick;
|
| 578 |
+
|
| 579 |
+
always @ (posedge clk or negedge rst_n) begin
|
| 580 |
+
if (!rst_n) begin
|
| 581 |
+
timer_tick_ctr <= {$clog2(CLK_MHZ){1'b0}};
|
| 582 |
+
timer_tick <= 1'b0;
|
| 583 |
+
end else begin
|
| 584 |
+
if (|timer_tick_ctr) begin
|
| 585 |
+
timer_tick_ctr <= timer_tick_ctr - 1'b1;
|
| 586 |
+
end else begin
|
| 587 |
+
timer_tick_ctr <= CLK_MHZ - 1;
|
| 588 |
+
end
|
| 589 |
+
timer_tick <= ~|timer_tick_ctr;
|
| 590 |
+
end
|
| 591 |
+
end
|
| 592 |
+
|
| 593 |
+
hazard3_riscv_timer timer_u (
|
| 594 |
+
.clk (clk),
|
| 595 |
+
.rst_n (rst_n),
|
| 596 |
+
|
| 597 |
+
.psel (timer_psel),
|
| 598 |
+
.penable (timer_penable),
|
| 599 |
+
.pwrite (timer_pwrite),
|
| 600 |
+
.paddr (timer_paddr),
|
| 601 |
+
.pwdata (timer_pwdata),
|
| 602 |
+
.prdata (timer_prdata),
|
| 603 |
+
.pready (timer_pready),
|
| 604 |
+
.pslverr (timer_pslverr),
|
| 605 |
+
|
| 606 |
+
.dbg_halt (&hart_halted),
|
| 607 |
+
|
| 608 |
+
.tick (timer_tick),
|
| 609 |
+
|
| 610 |
+
.timer_irq (timer_irq)
|
| 611 |
+
);
|
| 612 |
+
|
| 613 |
+
endmodule
|
Wren6991_Hazard3/example_soc/soc/peri/hazard3_riscv_timer.f
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
file hazard3_riscv_timer.v
|
| 2 |
+
file ../../../hdl/debug/cdc/hazard3_sync_1bit.v
|
Wren6991_Hazard3/example_soc/soc/peri/hazard3_riscv_timer.v
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*****************************************************************************\
|
| 2 |
+
| Copyright (C) 2022 Luke Wren |
|
| 3 |
+
| SPDX-License-Identifier: Apache-2.0 |
|
| 4 |
+
\*****************************************************************************/
|
| 5 |
+
|
| 6 |
+
`default_nettype none
|
| 7 |
+
|
| 8 |
+
// Basic implementation of standard 64-bit RISC-V timer with 32-bit APB.
|
| 9 |
+
|
| 10 |
+
// TICK_IS_NRZ = 1: tick is an NRZ signal that is asynchronous to clk.
|
| 11 |
+
// TICK_IS_NRZ = 0: tick is a level-sensitive signal that is synchronous to clk.
|
| 12 |
+
|
| 13 |
+
module hazard3_riscv_timer #(
|
| 14 |
+
parameter TICK_IS_NRZ = 0
|
| 15 |
+
) (
|
| 16 |
+
input wire clk,
|
| 17 |
+
input wire rst_n,
|
| 18 |
+
|
| 19 |
+
input wire [15:0] paddr,
|
| 20 |
+
input wire psel,
|
| 21 |
+
input wire penable,
|
| 22 |
+
input wire pwrite,
|
| 23 |
+
input wire [31:0] pwdata,
|
| 24 |
+
output reg [31:0] prdata,
|
| 25 |
+
output wire pready,
|
| 26 |
+
output wire pslverr,
|
| 27 |
+
|
| 28 |
+
input wire dbg_halt,
|
| 29 |
+
input wire tick,
|
| 30 |
+
|
| 31 |
+
output reg timer_irq
|
| 32 |
+
);
|
| 33 |
+
|
| 34 |
+
localparam ADDR_CTRL = 16'h0000;
|
| 35 |
+
localparam ADDR_MTIME = 16'h0008;
|
| 36 |
+
localparam ADDR_MTIMEH = 16'h000c;
|
| 37 |
+
localparam ADDR_MTIMECMP = 16'h0010;
|
| 38 |
+
localparam ADDR_MTIMECMPH = 16'h0014;
|
| 39 |
+
|
| 40 |
+
// ----------------------------------------------------------------------------
|
| 41 |
+
// Timer tick logic
|
| 42 |
+
|
| 43 |
+
wire tick_event;
|
| 44 |
+
|
| 45 |
+
generate
|
| 46 |
+
if (TICK_IS_NRZ) begin: edge_detect
|
| 47 |
+
|
| 48 |
+
wire tick_nrz_sync;
|
| 49 |
+
|
| 50 |
+
hazard3_sync_1bit tick_sync_u (
|
| 51 |
+
.clk (clk),
|
| 52 |
+
.rst_n (rst_n),
|
| 53 |
+
.i (tick),
|
| 54 |
+
.o (tick_nrz_sync)
|
| 55 |
+
);
|
| 56 |
+
|
| 57 |
+
reg tick_nrz_sync_prev;
|
| 58 |
+
always @ (posedge clk or negedge rst_n) begin
|
| 59 |
+
if (!rst_n) begin
|
| 60 |
+
tick_nrz_sync_prev <= 1'b0;
|
| 61 |
+
end else begin
|
| 62 |
+
tick_nrz_sync_prev <= tick_nrz_sync;
|
| 63 |
+
end
|
| 64 |
+
end
|
| 65 |
+
|
| 66 |
+
assign tick_event = tick_nrz_sync ^ tick_nrz_sync_prev;
|
| 67 |
+
|
| 68 |
+
end else begin: no_edge_detect
|
| 69 |
+
|
| 70 |
+
assign tick_event = tick;
|
| 71 |
+
|
| 72 |
+
end
|
| 73 |
+
endgenerate
|
| 74 |
+
|
| 75 |
+
reg ctrl_en;
|
| 76 |
+
wire tick_now = tick_event && ctrl_en && !dbg_halt;
|
| 77 |
+
|
| 78 |
+
// ----------------------------------------------------------------------------
|
| 79 |
+
// Counter registers
|
| 80 |
+
|
| 81 |
+
wire bus_write = pwrite && psel && penable;
|
| 82 |
+
wire bus_read = !pwrite && psel && penable;
|
| 83 |
+
|
| 84 |
+
always @ (posedge clk or negedge rst_n) begin
|
| 85 |
+
if (!rst_n) begin
|
| 86 |
+
ctrl_en <= 1'b1;
|
| 87 |
+
end else if (bus_write && paddr == ADDR_CTRL) begin
|
| 88 |
+
ctrl_en <= pwdata[0];
|
| 89 |
+
end
|
| 90 |
+
end
|
| 91 |
+
|
| 92 |
+
reg [63:0] mtime;
|
| 93 |
+
|
| 94 |
+
always @ (posedge clk or negedge rst_n) begin
|
| 95 |
+
if (!rst_n) begin
|
| 96 |
+
mtime <= 64'h0;
|
| 97 |
+
end else begin
|
| 98 |
+
if (tick_now)
|
| 99 |
+
mtime <= mtime + 1'b1;
|
| 100 |
+
if (bus_write && paddr == ADDR_MTIME)
|
| 101 |
+
mtime[31:0] <= pwdata;
|
| 102 |
+
if (bus_write && paddr == ADDR_MTIMEH)
|
| 103 |
+
mtime[63:32] <= pwdata;
|
| 104 |
+
end
|
| 105 |
+
end
|
| 106 |
+
|
| 107 |
+
// mtimecmp is stored inverted for minor LUT savings on iCE40
|
| 108 |
+
reg [63:0] mtimecmp;
|
| 109 |
+
wire [64:0] cmp_diff = {1'b0, mtime} + {1'b0, mtimecmp} + 65'd1;
|
| 110 |
+
|
| 111 |
+
always @ (posedge clk or negedge rst_n) begin
|
| 112 |
+
if (!rst_n) begin
|
| 113 |
+
mtimecmp <= 64'h0;
|
| 114 |
+
timer_irq <= 1'b0;
|
| 115 |
+
end else begin
|
| 116 |
+
if (bus_write && paddr == ADDR_MTIMECMP)
|
| 117 |
+
mtimecmp[31:0] <= ~pwdata;
|
| 118 |
+
if (bus_write && paddr == ADDR_MTIMECMPH)
|
| 119 |
+
mtimecmp[63:32] <= ~pwdata;
|
| 120 |
+
timer_irq <= cmp_diff[64];
|
| 121 |
+
end
|
| 122 |
+
end
|
| 123 |
+
|
| 124 |
+
always @ (*) begin
|
| 125 |
+
case (paddr)
|
| 126 |
+
ADDR_CTRL: prdata = {31'h0, ctrl_en};
|
| 127 |
+
ADDR_MTIME: prdata = mtime[31:0];
|
| 128 |
+
ADDR_MTIMEH: prdata = mtime[63:32];
|
| 129 |
+
ADDR_MTIMECMP: prdata = ~mtimecmp[31:0];
|
| 130 |
+
ADDR_MTIMECMPH: prdata = ~mtimecmp[63:32];
|
| 131 |
+
default: prdata = 32'h0;
|
| 132 |
+
endcase
|
| 133 |
+
end
|
| 134 |
+
|
| 135 |
+
assign pready = 1'b1;
|
| 136 |
+
assign pslverr = 1'b0;
|
| 137 |
+
|
| 138 |
+
endmodule
|
| 139 |
+
|
| 140 |
+
`ifndef YOSYS
|
| 141 |
+
`default_nettype none
|
| 142 |
+
`endif
|
Wren6991_Hazard3/example_soc/soc/soc.f
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SoC integration file
|
| 2 |
+
|
| 3 |
+
file example_soc.v
|
| 4 |
+
|
| 5 |
+
# CPU + debug components
|
| 6 |
+
|
| 7 |
+
list $HDL/hazard3.f
|
| 8 |
+
list $HDL/debug/dtm/hazard3_jtag_dtm.f
|
| 9 |
+
list $HDL/debug/dm/hazard3_dm.f
|
| 10 |
+
|
| 11 |
+
# RISC-V timer
|
| 12 |
+
|
| 13 |
+
list peri/hazard3_riscv_timer.f
|
| 14 |
+
|
| 15 |
+
# Generic SoC components from libfpga
|
| 16 |
+
|
| 17 |
+
file ../libfpga/common/reset_sync.v
|
| 18 |
+
|
| 19 |
+
list ../libfpga/peris/uart/uart.f
|
| 20 |
+
list ../libfpga/peris/spi_03h_xip/spi_03h_xip.f
|
| 21 |
+
list ../libfpga/mem/ahb_cache.f
|
| 22 |
+
list ../libfpga/mem/ahb_sync_sram.f
|
| 23 |
+
|
| 24 |
+
list ../libfpga/busfabric/ahbl_crossbar.f
|
| 25 |
+
file ../libfpga/busfabric/ahbl_to_apb.v
|
| 26 |
+
file ../libfpga/busfabric/apb_splitter.v
|
| 27 |
+
|
Wren6991_Hazard3/example_soc/synth/.gitignore
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
srcs.mk
|
| 2 |
+
*.blif
|
| 3 |
+
*.asc
|
| 4 |
+
*.hex
|
| 5 |
+
*.bin
|
| 6 |
+
*.json
|
| 7 |
+
*.log
|
| 8 |
+
*.config
|
| 9 |
+
*.svf
|
| 10 |
+
*.bit
|
Wren6991_Hazard3/example_soc/synth/Icebreaker.mk
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
include ../project_paths.mk
|
| 2 |
+
|
| 3 |
+
CHIPNAME=fpga_icebreaker
|
| 4 |
+
DOTF=../fpga/fpga_icebreaker.f
|
| 5 |
+
SYNTH_OPT=-dsp
|
| 6 |
+
PNR_OPT=--timing-allow-fail --detailed-timing-report
|
| 7 |
+
|
| 8 |
+
DEVICE=up5k
|
| 9 |
+
PACKAGE=sg48
|
| 10 |
+
|
| 11 |
+
include $(SCRIPTS)/synth_ice40.mk
|
| 12 |
+
|
| 13 |
+
prog: bit
|
| 14 |
+
iceprog $(CHIPNAME).bin
|
Wren6991_Hazard3/example_soc/synth/Makefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
include Icebreaker.mk
|
Wren6991_Hazard3/example_soc/synth/ULX3S.mk
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
include ../project_paths.mk
|
| 2 |
+
|
| 3 |
+
CHIPNAME=fpga_ulx3s
|
| 4 |
+
TOP=fpga_ulx3s
|
| 5 |
+
DOTF=../fpga/fpga_ulx3s.f
|
| 6 |
+
|
| 7 |
+
SYNTH_OPT=-abc9
|
| 8 |
+
PNR_OPT=--timing-allow-fail
|
| 9 |
+
|
| 10 |
+
DEVICE=um5g-85k
|
| 11 |
+
PACKAGE=CABGA381
|
| 12 |
+
|
| 13 |
+
include $(SCRIPTS)/synth_ecp5.mk
|
| 14 |
+
|
| 15 |
+
# Get ujprog from: git@github.com:emard/tools.git
|
| 16 |
+
prog: bit
|
| 17 |
+
ujprog $(CHIPNAME).bit
|
| 18 |
+
|
| 19 |
+
flash: bit
|
| 20 |
+
ujprog -j flash $(CHIPNAME).bit
|
Wren6991_Hazard3/example_soc/synth/fpga_icebreaker.pcf
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 12 MHz oscillator
|
| 2 |
+
set_io clk_osc 35
|
| 3 |
+
|
| 4 |
+
# JTAG is on FTDI B channel so it doesn't inadvertently assert flash CS pin
|
| 5 |
+
# (usually UART would be on the B channel).
|
| 6 |
+
|
| 7 |
+
# Note TDO/TMS require two of the solder jumpers on the back of the board to
|
| 8 |
+
# be bridged. On the v1.0e board these are jumpers J3/J4. To find these, look
|
| 9 |
+
# for the box of 5 x 2 jumpers (with a few others hanging off the side) and
|
| 10 |
+
# they are the two in the central column. They line up with the space in
|
| 11 |
+
# between "Jump" and "for" in the silk text "Jump for FTDI FIFO".
|
| 12 |
+
|
| 13 |
+
set_io tck 6 # FTDI BDBUS0
|
| 14 |
+
set_io tdi 9 # FTDI BDBUS1
|
| 15 |
+
set_io tdo 18 # FTDI BDBUS2
|
| 16 |
+
set_io tms 19 # FTDI BDBUS3
|
| 17 |
+
|
| 18 |
+
# UART is moved over to FTDI A channel -- this means flash is inaccessible
|
| 19 |
+
# (and stays in a quiescent state since CSn is disconnected and pulled high)
|
| 20 |
+
set_io uart_rx 15 # FTDI ADBUS0, flash SCK, iCE SCK
|
| 21 |
+
set_io uart_tx 14 # FTDI ADBUS1, flash MOSI, iCE SO (if jumper J15 connected)
|
| 22 |
+
|
| 23 |
+
set_io led 37 # Green on main board
|
| 24 |
+
|
| 25 |
+
# # Buttons
|
| 26 |
+
# set_io dpad_u 20 # Snapoff top
|
| 27 |
+
# set_io dpad_d 18 # Snapoff bottom
|
| 28 |
+
# set_io dpad_l 10 # Main board
|
| 29 |
+
# set_io dpad_r 19 # Snapoff middle
|
| 30 |
+
|
| 31 |
+
set_io mirror_tck 27 # Left on snapoff (L2)
|
| 32 |
+
set_io mirror_tms 25 # Right on snapoff (L3)
|
| 33 |
+
set_io mirror_tdi 23 # Top on snapoff (L4)
|
| 34 |
+
set_io mirror_tdo 21 # Bottom on snapoff (L5)
|
| 35 |
+
|
| 36 |
+
# # LEDs
|
| 37 |
+
# set_io led[0] 37 # Green on main board
|
| 38 |
+
# set_io led[1] 11 # Red on main board
|
| 39 |
+
# set_io led[2] 26 # Middle on snapoff (L1)
|
| 40 |
+
# set_io led[3] 27 # Left on snapoff (L2)
|
| 41 |
+
# set_io led[4] 25 # Right on snapoff (L3)
|
| 42 |
+
# set_io led[5] 23 # Top on snapoff (L4)
|
| 43 |
+
# set_io led[6] 21 # Bottom on snapoff (L5)
|
Wren6991_Hazard3/example_soc/synth/fpga_orangecrab_25f.lpf
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Reference: https://github.com/emard/ulx3s/blob/master/doc/constraints/ulx3s_v20.lpf
|
| 2 |
+
|
| 3 |
+
LOCATE COMP "clk_osc" SITE "A9";
|
| 4 |
+
IOBUF PORT "clk_osc" PULLMODE=NONE IO_TYPE=LVCMOS33;
|
| 5 |
+
FREQUENCY PORT "clk_osc" 48 MHZ;
|
| 6 |
+
|
| 7 |
+
# UART TX/RX (from FPGA's point of view, i.e. TX is an output)
|
| 8 |
+
|
| 9 |
+
LOCATE COMP "uart_tx" SITE "N17"; # FPGA transmits to ftdi
|
| 10 |
+
LOCATE COMP "uart_rx" SITE "M18"; # FPGA receives from ftdi
|
| 11 |
+
IOBUF PORT "uart_tx" PULLMODE=UP IO_TYPE=LVCMOS33 DRIVE=4;
|
| 12 |
+
IOBUF PORT "uart_rx" PULLMODE=UP IO_TYPE=LVCMOS33;
|
| 13 |
+
|
| 14 |
+
# 8 pins on an IO header for bringing signals out to a logic analyser
|
| 15 |
+
|
| 16 |
+
LOCATE COMP "dbg[0]" SITE "H2"; # PCLK # "gn[0]"
|
| 17 |
+
LOCATE COMP "dbg[1]" SITE "A8"; # PCLK # "gn[1]"
|
| 18 |
+
LOCATE COMP "dbg[2]" SITE "B8"; # GR_PCLK # "gn[2]"
|
| 19 |
+
LOCATE COMP "dbg[3]" SITE "C8"; # "gn[3]"
|
| 20 |
+
LOCATE COMP "dbg[4]" SITE "B9"; # PCLK # "gp[0]"
|
| 21 |
+
LOCATE COMP "dbg[5]" SITE "B10"; # PCLK # "gp[1]"
|
| 22 |
+
LOCATE COMP "dbg[6]" SITE "L4"; # GR_PCLK # "gp[2]"
|
| 23 |
+
LOCATE COMP "dbg[7]" SITE "N3"; # "gp[3]"
|
| 24 |
+
|
| 25 |
+
IOBUF PORT "dbg[0]" PULLMODE=UP IO_TYPE=LVCMOS33 DRIVE=4;
|
| 26 |
+
IOBUF PORT "dbg[1]" PULLMODE=UP IO_TYPE=LVCMOS33 DRIVE=4;
|
| 27 |
+
IOBUF PORT "dbg[2]" PULLMODE=UP IO_TYPE=LVCMOS33 DRIVE=4;
|
| 28 |
+
IOBUF PORT "dbg[3]" PULLMODE=UP IO_TYPE=LVCMOS33 DRIVE=4;
|
| 29 |
+
IOBUF PORT "dbg[4]" PULLMODE=UP IO_TYPE=LVCMOS33 DRIVE=4;
|
| 30 |
+
IOBUF PORT "dbg[5]" PULLMODE=UP IO_TYPE=LVCMOS33 DRIVE=4;
|
| 31 |
+
IOBUF PORT "dbg[6]" PULLMODE=UP IO_TYPE=LVCMOS33 DRIVE=4;
|
| 32 |
+
IOBUF PORT "dbg[7]" PULLMODE=UP IO_TYPE=LVCMOS33 DRIVE=4;
|
| 33 |
+
|
| 34 |
+
LOCATE COMP "rgb_led0_r" SITE "K4";
|
| 35 |
+
IOBUF PORT "rgb_led0_r" IO_TYPE=LVCMOS33;
|
| 36 |
+
LOCATE COMP "rgb_led0_g" SITE "M3";
|
| 37 |
+
IOBUF PORT "rgb_led0_g" IO_TYPE=LVCMOS33;
|
| 38 |
+
LOCATE COMP "rgb_led0_b" SITE "J3";
|
| 39 |
+
IOBUF PORT "rgb_led0_b" IO_TYPE=LVCMOS33;
|
| 40 |
+
|
| 41 |
+
LOCATE COMP "usr_btn" SITE "J17";
|
| 42 |
+
IOBUF PORT "usr_btn" IO_TYPE=SSTL135_I;
|
| 43 |
+
LOCATE COMP "rst_n" SITE "V17";
|
| 44 |
+
IOBUF PORT "rst_n" IO_TYPE=LVCMOS33;
|
Wren6991_Hazard3/example_soc/synth/fpga_ulx3s.lpf
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Reference: https://github.com/emard/ulx3s/blob/master/doc/constraints/ulx3s_v20.lpf
|
| 2 |
+
|
| 3 |
+
LOCATE COMP "clk_osc" SITE "G2";
|
| 4 |
+
IOBUF PORT "clk_osc" PULLMODE=NONE IO_TYPE=LVCMOS33;
|
| 5 |
+
FREQUENCY PORT "clk_osc" 25 MHZ;
|
| 6 |
+
|
| 7 |
+
# UART TX/RX (from FPGA's point of view, i.e. TX is an output)
|
| 8 |
+
|
| 9 |
+
LOCATE COMP "uart_tx" SITE "L4"; # FPGA transmits to ftdi
|
| 10 |
+
LOCATE COMP "uart_rx" SITE "M1"; # FPGA receives from ftdi
|
| 11 |
+
IOBUF PORT "uart_tx" PULLMODE=UP IO_TYPE=LVCMOS33 DRIVE=4;
|
| 12 |
+
IOBUF PORT "uart_rx" PULLMODE=UP IO_TYPE=LVCMOS33;
|
| 13 |
+
|
| 14 |
+
# 8 pins on an IO header for bringing signals out to a logic analyser
|
| 15 |
+
|
| 16 |
+
LOCATE COMP "dbg[0]" SITE "C11"; # PCLK # "gn[0]"
|
| 17 |
+
LOCATE COMP "dbg[1]" SITE "A11"; # PCLK # "gn[1]"
|
| 18 |
+
LOCATE COMP "dbg[2]" SITE "B10"; # GR_PCLK # "gn[2]"
|
| 19 |
+
LOCATE COMP "dbg[3]" SITE "C10"; # "gn[3]"
|
| 20 |
+
LOCATE COMP "dbg[4]" SITE "B11"; # PCLK # "gp[0]"
|
| 21 |
+
LOCATE COMP "dbg[5]" SITE "A10"; # PCLK # "gp[1]"
|
| 22 |
+
LOCATE COMP "dbg[6]" SITE "A9"; # GR_PCLK # "gp[2]"
|
| 23 |
+
LOCATE COMP "dbg[7]" SITE "B9"; # "gp[3]"
|
| 24 |
+
|
| 25 |
+
IOBUF PORT "dbg[0]" PULLMODE=UP IO_TYPE=LVCMOS33 DRIVE=4;
|
| 26 |
+
IOBUF PORT "dbg[1]" PULLMODE=UP IO_TYPE=LVCMOS33 DRIVE=4;
|
| 27 |
+
IOBUF PORT "dbg[2]" PULLMODE=UP IO_TYPE=LVCMOS33 DRIVE=4;
|
| 28 |
+
IOBUF PORT "dbg[3]" PULLMODE=UP IO_TYPE=LVCMOS33 DRIVE=4;
|
| 29 |
+
IOBUF PORT "dbg[4]" PULLMODE=UP IO_TYPE=LVCMOS33 DRIVE=4;
|
| 30 |
+
IOBUF PORT "dbg[5]" PULLMODE=UP IO_TYPE=LVCMOS33 DRIVE=4;
|
| 31 |
+
IOBUF PORT "dbg[6]" PULLMODE=UP IO_TYPE=LVCMOS33 DRIVE=4;
|
| 32 |
+
IOBUF PORT "dbg[7]" PULLMODE=UP IO_TYPE=LVCMOS33 DRIVE=4;
|
Wren6991_Hazard3/example_soc/synth/orangecrab-25f.mk
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
CHIPNAME=fpga_orangecrab_25f
|
| 2 |
+
TOP=fpga_orangecrab_25f
|
| 3 |
+
DOTF=../fpga/fpga_orangecrab_25f.f
|
| 4 |
+
|
| 5 |
+
SYNTH_OPT=-abc9
|
| 6 |
+
PNR_OPT=--timing-allow-fail
|
| 7 |
+
|
| 8 |
+
DEVICE=25k
|
| 9 |
+
PACKAGE=CSFBGA285
|
| 10 |
+
|
| 11 |
+
DEVICE_IDCODE=0x41111043
|
| 12 |
+
|
| 13 |
+
include $(SCRIPTS)/synth_ecp5.mk
|
| 14 |
+
|
| 15 |
+
$(CHIPNAME).dfu: bit
|
| 16 |
+
cp $(CHIPNAME).bit $@
|
| 17 |
+
dfu-suffix -v 1209 -p 5af0 -a $@
|
| 18 |
+
|
| 19 |
+
prog: bit
|
| 20 |
+
ujprog $(CHIPNAME).bit
|
| 21 |
+
|
| 22 |
+
flash: $(CHIPNAME).dfu
|
| 23 |
+
dfu-util -d 1209:5af0 -D $<
|
Wren6991_Hazard3/example_soc/synth_vivado/.gitignore
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.dcp
|
| 2 |
+
*.log
|
| 3 |
+
*.jou
|
| 4 |
+
*.bit
|
| 5 |
+
*.rpt
|
| 6 |
+
*.txt
|
| 7 |
+
.Xil
|
| 8 |
+
filelist.tcl
|