diff --git a/vendor/google_riscv-dv.lock.hjson b/vendor/google_riscv-dv.lock.hjson new file mode 100644 index 00000000..285995ca --- /dev/null +++ b/vendor/google_riscv-dv.lock.hjson @@ -0,0 +1,14 @@ +// Copyright lowRISC contributors. +// Licensed under the Apache License, Version 2.0, see LICENSE for details. +// SPDX-License-Identifier: Apache-2.0 + +// This file is generated by the vendor_hw script. Please do not modify it +// manually. + +{ + upstream: + { + url: https://github.com/google/riscv-dv + rev: 215e0646ae9909aa0e78d6e91f4f33ed77f95e43 + } +} diff --git a/vendor/google_riscv-dv/CONTRIBUTING.md b/vendor/google_riscv-dv/CONTRIBUTING.md new file mode 100644 index 00000000..db177d4a --- /dev/null +++ b/vendor/google_riscv-dv/CONTRIBUTING.md @@ -0,0 +1,28 @@ +# How to Contribute + +We'd love to accept your patches and contributions to this project. There are +just a few small guidelines you need to follow. + +## Contributor License Agreement + +Contributions to this project must be accompanied by a Contributor License +Agreement. You (or your employer) retain the copyright to your contribution; +this simply gives us permission to use and redistribute your contributions as +part of the project. Head over to to see +your current agreements on file or to sign a new one. + +You generally only need to submit a CLA once, so if you've already submitted one +(even if it was for a different project), you probably don't need to do it +again. + +## Code reviews + +All submissions, including submissions by project members, require review. We +use GitHub pull requests for this purpose. Consult +[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more +information on using pull requests. + +## Community Guidelines + +This project follows +[Google's Open Source Community Guidelines](https://opensource.google.com/conduct/). diff --git a/vendor/google_riscv-dv/LICENSE.txt b/vendor/google_riscv-dv/LICENSE.txt new file mode 100644 index 00000000..4c9ad980 --- /dev/null +++ b/vendor/google_riscv-dv/LICENSE.txt @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/google_riscv-dv/README.md b/vendor/google_riscv-dv/README.md new file mode 100644 index 00000000..e1d23417 --- /dev/null +++ b/vendor/google_riscv-dv/README.md @@ -0,0 +1,190 @@ +# RISCV-DV + +RISCV-DV is a SV/UVM based open-source instruction generator for RISC-V +processor verification. It currently supports the following features: + +- Supported instruction set: RV32IMC, RV64IMC +- Supported privileged mode: machine mode, supervisor mode, user mode +- Page table randomization and exception +- Privileged CSR setup randomization +- Trap/interrupt handling +- Test suite to stress test MMU +- Support sub-programs and random program calls +- Support illegal instruction and HINT instruction +- Random forward/backward branch instructions +- Support mix directed instruciton with random instruction stream +- Support co-simulation with multiple ISS : spike, riscv-ovpsim + +## Getting Started + +### Prerequisites + +To be able to run the instruction generator, you need to have an RTL simulator +which supports Systemverilog and UVM 1.2. This generator has been verified with +Synopsys VCS and Cadence Incisive/Xcelium simulator. Please make sure the EDA +tool environment is properly setup before running the generator. + +### Running the generator + +A simple script "run" is provided for you to run a single test or a regression. +Here is the command to run a single test: + +``` +./run -test riscv_instr_base_test +``` +You can specify the simulator by "-tool" option + +``` +./run -test riscv_instr_base_test -tool irun +./run -test riscv_instr_base_test -tool vcs +``` +The complete test list can be found in testlist. To run a full regression, you +can just specify the test name to "all". + +``` +./run -test all +``` +The script will run each test in the test list sequentially with the iteration +count specified in the "testlist". All the generated RISC-V assembly will be +listed when the regression is done. If it is successful, you should see the +following output: + +``` +=========================================================== + Generated RISC-V assembly tests + ---------------------------------------------------------- +./out_2018-11-20/asm_tests/riscv_arithmetic_basic_test.0.S +./out_2018-11-20/asm_tests/riscv_machine_mode_rand_test.0.S +./out_2018-11-20/asm_tests/riscv_mmu_stress_test.0.S +./out_2018-11-20/asm_tests/riscv_mmu_stress_test.1.S +./out_2018-11-20/asm_tests/riscv_no_fence_test.0.S +./out_2018-11-20/asm_tests/riscv_page_table_exception_test.0.S +./out_2018-11-20/asm_tests/riscv_page_table_exception_test.1.S +./out_2018-11-20/asm_tests/riscv_privileged_mode_rand_test.0.S +./out_2018-11-20/asm_tests/riscv_privileged_mode_rand_test.1.S +./out_2018-11-20/asm_tests/riscv_rand_instr_test.0.S +./out_2018-11-20/asm_tests/riscv_rand_instr_test.1.S +./out_2018-11-20/asm_tests/riscv_rand_jump_test.0.S +./out_2018-11-20/asm_tests/riscv_sfence_exception_test.0.S +``` +Here's a few more examples of the run command: +``` +// Run a single test 10 times +./run -test riscv_page_table_exception_test -n 10 + +// Run a test with a specified seed +./run -test riscv_page_table_exception_test -seed 123 + +// Run a test with addtional runtime options, separated with comma +./run -test riscv_rand_instr_test -runo +instr_cnt=10000,+no_fence=1 + +// Two steps compile and simulation (Avoid multiple compilation) +./run -co # compile only +# Generate multiple tests +./run -so -test riscv_rand_instr_test -n 10 +./run -so -test riscv_mmu_stress_test -n 20 +.... +``` + +### Use the generated test in your RTL and ISS simulation + +You need to use the RISC-V gcc/llvm compiler to compile the assembly tests to an ELF +file and feed into your TB. We currently don't provide a reference TB for the +co-simulation as it could be quite different based on the processor and ISS +implementation. A reference script "iss_sim" is provided to compile the program +with the RISC-V gcc compiler and simulate with spike. +``` +./run -test all; ./iss_sim +``` + +To run with ISS simulation for RV32IMC, you can specify ISA and ABI from command +line like this: +``` +./iss_sim -isa rv32imc -abi ilp32 +``` + +The default ISS is spike. Thanks for the great support from Imperas Software Ltd., +we have added the support for [riscv-ovpsim](https://github.com/riscv/riscv-ovpsim). +You can use -iss to run with different ISS. +``` +./iss_sim -iss spike # Use spike as ISS +./iss_sim -iss ovpsim # Use riscv-ovpsim as ISS +``` + +We have added a flow to run ISS simulation with both spike and riscv-ovpsim, +the instruction trace from these runs will be cross compared. This could greatly +speed up your development of new test without the need to simulate against a +real RISC-V processor. +``` +./iss_sim -iss all # Run ISS simulation with spike + riscv-ovpsim +``` + +## Configure the generator to match your processor features + +The default configuration of the instruction generator is for RV64IMC RISC-V +processors with address translation capability. You might want to configure the +generator according the feature of your processor. + +The static setting of the processor src/riscv_core_setting.sv + +``` +// Bit width of RISC-V GPR +parameter int XLEN = 64; + +// Parameter for SATP mode, set to BARE if address translation is not supported +parameter satp_mode_t SATP_MODE = SV39; + +// Supported Privileged mode +privileged_mode_t supported_privileged_mode[] = {USER_MODE, + SUPERVISOR_MODE, + MACHINE_MODE}; + +// Unsupported instructions +riscv_instr_name_t unsupported_instr[] = {}; + +// ISA supported by the processor +riscv_instr_group_t supported_isa[] = {RV32I, RV32M, RV64I, RV64M}; + +... +``` + +## Runtime options of the generator + + + +## Adding new instruction stream and test + +Please refer to src/src/riscv_load_store_instr_lib.sv for an example on how to +add a new instruction stream. +``` +virtual function void apply_directed_instr(); + asm_gen.add_directed_instr_stream("my_new_instr_stream_class_name", 10); +endfunction +``` + After the new instruction stream is created, you +can refer to test/riscv_instr_test_lib.sv to see how an instruction stream can +be mixed with existing random instruction stream. + +## Supporting model + +Please file an issue under this repository for any bug report / integration +issue / feature request. We are looking forward to knowing your experience of +using this flow and how we can make it better together. + +## External contributions + +We definitely welcome external contributions. We hope it could be a +collaborative effort to build a strong open source RISC-V processor +verification platform. Free feel to submit your pull request for review. +Please refer to CONTRIBUTING.md for license related questions. + +## Future release plan + +We have some work in progress which will be part of future releases: + +- Privileged CSR test suite. +- Coverage model. + +## Disclaimer + +This is not an officially supported Google product. diff --git a/vendor/google_riscv-dv/files.f b/vendor/google_riscv-dv/files.f new file mode 100644 index 00000000..bfd9b7aa --- /dev/null +++ b/vendor/google_riscv-dv/files.f @@ -0,0 +1,22 @@ +// Copyright 2018 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// HEADERS ++incdir+./src ++incdir+./test + +// SOURCES +./src/riscv_instr_pkg.sv +./test/riscv_instr_test_pkg.sv +./test/riscv_instr_gen_tb_top.sv diff --git a/vendor/google_riscv-dv/iss_cmp b/vendor/google_riscv-dv/iss_cmp new file mode 100755 index 00000000..74de5b6a --- /dev/null +++ b/vendor/google_riscv-dv/iss_cmp @@ -0,0 +1,50 @@ +#!/bin/bash +# Copyright 2018 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +spike_log="$1" +ovpsim_log="$2" +report_file="$3" + +# ----------------------------------------------------------------------------- +# Convert spike log to standard instruction trace csv +# ----------------------------------------------------------------------------- +# Remove all the init spike boot instructions +# 0xffffffff80000000 is the first user instruction +if [[ "$XLEN" == "32" ]]; then + sed -i '/0xffffffff80000000/,$!d' "$spike_log" +else + sed -i '/core.*0x0000000080000000/,$!d' "$spike_log" +fi +# Remove all instructions after ecall (end of program excecution) +sed -i '/ecall/q' "$spike_log" +# Convert the spike log to riscv_instr_trace.proto format +spike_csv=$(echo "$spike_log" | sed 's/\.log/.csv/g') +python scripts/spike_log_to_trace_csv.py --log $spike_log --csv $spike_csv + +# ----------------------------------------------------------------------------- +# Convert ovpsim log to standard instruction trace csv +# ----------------------------------------------------------------------------- +# Remove the header part of ovpsim log +sed -i '/Info 1:/,$!d' "$ovpsim_log" +# Remove all instructions after ecall (end of program excecution) +sed -i '/ecall/q' "$ovpsim_log" +# Convert the spike log to riscv_instr_trace.proto format +ovpsim_csv=$(echo "$ovpsim_log" | sed 's/\.log/.csv/g') +python scripts/ovpsim_log_to_trace_csv.py --log $ovpsim_log --csv $ovpsim_csv + +# ----------------------------------------------------------------------------- +# Compare the trace log +# ----------------------------------------------------------------------------- +python scripts/instr_trace_compare.py $spike_csv $ovpsim_csv "spike" "ovpsim" >> $report_file diff --git a/vendor/google_riscv-dv/iss_sim b/vendor/google_riscv-dv/iss_sim new file mode 100755 index 00000000..3760f26f --- /dev/null +++ b/vendor/google_riscv-dv/iss_sim @@ -0,0 +1,179 @@ +#!/bin/bash +# Copyright 2018 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Path for RISC-V GCC toolchain +# You can install the toolchain from https://github.com/riscv/riscv-gcc +RISCV_TOOLCHAIN="XXX" + +# GCC compile options +ABI="lp64" +ISA="rv64imc" + +DATE=`date +%Y-%m-%d` + +# Instruction set simulator +ISS="spike" # other options: ovpsim, all + +# riscv-ovpsim options +OVPSIM_VARIANT="RV64GC" +RISCV_OVPSIM="YOUR_PATH_HERE/riscv-ovpsim/bin/Linux64/riscvOVPsim.exe" + +# Directory of assemble tests +SRC_DIR="./out_${DATE}/asm_tests" + +# Assembly test file name +TEST="" + +# Regression report file name +REPORT="$SRC_DIR/regression_report.log" + +# Clean the result of the previous runs +CLEAN=1 + +# Process command line options +while [[ $# -gt 0 ]] +do +key="$1" +case $key in + -iss) + ISS="$2" + shift + ;; + -dir) + SRC_DIR="$2" + shift + ;; + -toolchain) + RISCV_TOOLCHAIN="$2" + shift + ;; + -isa) + ISA="$2" + shift + ;; + -abi) + ABI="$2" + shift + ;; + -test) + TEST="$2" + shift + ;; + -report) + REPORT="$2" + shift + ;; + -noclean) + CLEAN=0 + shift + ;; + *) + echo "unknown option $1" + return + ;; +esac +shift +done + +RISCV_GCC="$RISCV_TOOLCHAIN/bin/riscv64-unknown-elf-gcc" +RISCV_OBJCOPY="$RISCV_TOOLCHAIN/bin/riscv64-unknown-elf-objcopy" +RISCV_SPIKE="$RISCV_TOOLCHAIN/bin/spike" + +mkdir -p "$SRC_DIR" + +# If the test is specified through "-test" option, run a single test rather +# than all tests under SRC_DIR. +if [[ $TEST == "" ]]; then + find "$SRC_DIR" -name "*.S" > "$SRC_DIR/asm_test_list" +else + echo "$TEST" > "$SRC_DIR/asm_test_list" +fi + +if [[ $ISA =~ 32 ]]; then + OVPSIM_VARIANT="RV32GC" +fi + +# Clean up previous running result +if [[ $CLEAN == 1 ]]; then + rm -rf "$REPORT" + if [[ "$ISS" == "spike" ]] || [[ "$ISS" == "all" ]]; then + rm -rf "$SRC_DIR/spike_sim" + fi + if [[ "$ISS" == "ovpsim" ]] || [[ "$ISS" == "all" ]]; then + rm -rf "$SRC_DIR/riscv_ovpsim" + fi +fi + +# GCC compile +while read asm_test; do + # Generate binary for RTL simulation + SRC="$asm_test" + OBJFILE="$asm_test.o" + BINFILE="$asm_test.bin" + GCC_CMD="$RISCV_GCC -march=$ISA -mabi=$ABI -static -mcmodel=medany \ + -fvisibility=hidden -nostdlib \ + -nostartfiles -I$RISCV_TESTS/env/p \ + -Tscripts/link.ld $SRC -o $OBJFILE" + echo "riscv_gcc compiling : $SRC" + $($GCC_CMD) + echo "Convert $OBJFILE to $BINFILE" + # Convert the ELF to plain binary + # You can load this binary to your RTL simulation + "$RISCV_OBJCOPY" -O binary "$OBJFILE" "$BINFILE" +done <"$SRC_DIR/asm_test_list" + +if [[ "$ISS" == "ovpsim" ]] || [[ "$ISS" == "all" ]]; then + mkdir -p "$SRC_DIR/riscv_ovpsim" +fi +if [[ "$ISS" == "spike" ]] || [[ "$ISS" == "all" ]]; then + mkdir -p "$SRC_DIR/spike_sim" +fi + +# Run ISS simulation +while read asm_test; do + ELF="${asm_test}.o" + TEST_NAME=$(echo "$ELF" | sed 's/^.*\///g') + # Spike sim + if [[ "$ISS" == "spike" ]] || [[ "$ISS" == "all" ]]; then + echo "Running spike: $TEST_NAME" + SPIKE_LOG="$SRC_DIR/spike_sim/$TEST_NAME.log" + SPIKE_CMD="timeout 60s $RISCV_SPIKE --isa=$ISA -l $ELF &> $SPIKE_LOG" + $($SPIKE_CMD &> $SPIKE_LOG) + fi + # riscv_ovpsim sim + if [[ "$ISS" == "ovpsim" ]] || [[ "$ISS" == "all" ]]; then + OVPSIM_LOG="$SRC_DIR/riscv_ovpsim/$TEST_NAME.log" + echo "Running ovpsim: $TEST_NAME" + RISCV_OVPSIM_CMD="$RISCV_OVPSIM --variant $OVPSIM_VARIANT \ + --override riscvOVPsim/cpu/PMP_registers=0 \ + --override riscvOVPsim/cpu/simulateexceptions=T \ + --trace --tracechange --traceshowicount --program $ELF \ + --finishafter 500000" + $($RISCV_OVPSIM_CMD &> $OVPSIM_LOG) + fi + if [[ "$ISS" == "all" ]]; then + echo "Rerun command: ./iss_sim -test $asm_test -iss all" >> "$REPORT" + echo "spike : $SPIKE_LOG" >> "$REPORT" + echo "ovpsim : $OVPSIM_LOG" >> "$REPORT" + ./iss_cmp "$SPIKE_LOG" "$OVPSIM_LOG" "$REPORT" + tail -1 "$REPORT" + echo "" >> "$REPORT" + fi +done <"$SRC_DIR/asm_test_list" + +if [[ "$ISS" == "all" ]]; then + echo "Full regression report is saved to $REPORT" + cat "$REPORT" +fi diff --git a/vendor/google_riscv-dv/run b/vendor/google_riscv-dv/run new file mode 100755 index 00000000..93554502 --- /dev/null +++ b/vendor/google_riscv-dv/run @@ -0,0 +1,170 @@ +#!/bin/bash +# Copyright 2018 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# This is simple run script to run a dedicated test or a regression +# +# Usage: +# Run a single test with irun +# ./run -tool irun -test riscv_instr_base_test +# +# Run regression with vcs +# ./run -test all +# +# Change output directory +# ./run -out my_output_dir + +DATE=`date +%Y-%m-%d` + +# RTL simulator, support vcs and irun +SIMULATOR="vcs" + +# random seed +SEED=`date +%s` + +# Test name, "all" means run all tests in the testlist +TEST="riscv_instr_base_test" + +# Number of assembly programs to be generated for this test +# This option only apply to single test mode. For the regression mode, the number is specified in +# the testlist +NUM_TESTS=1 + +# Simulation output directory +OUT="./out_${DATE}" + +# Simulation only +SIM_ONLY=0 + +# Compile only +CMP_ONLY=0 + +# Process command line options +while [[ $# -gt 0 ]] +do +key="$1" +case $key in + -tool) + SIMULATOR="$2" + shift + ;; + -test) + TEST="$2" + shift + ;; + -n) + NUM_TESTS="$2" + shift + ;; + -seed) + SEED="$2" + shift + ;; + -so) + SIM_ONLY=1 + ;; + -co) + CMP_ONLY=1 + ;; + -o) + OUT="$2" + shift + ;; + *) + echo "unknown option $1" + exit 1 + ;; +esac +shift +done + +# Generate compile and simulation commands +if [[ "$SIMULATOR" == "vcs" ]]; then + + COMPILE_CMD="vcs -file ./vcs.compile.option.f \ + -f ./files.f -full64 \ + -l $OUT/compile.log \ + -Mdir=$OUT/vcs_simv.csrc \ + -o $OUT/vcs_simv" + + SIM_CMD="$OUT/vcs_simv +UVM_TESTNAME=" + +elif [[ "$SIMULATOR" == "irun" ]]; then + + COMPILE_CMD="irun -64bit \ + -access +rwc \ + -f ./files.f \ + -q -sv -uvm \ + -vlog_ext +.vh -I. \ + -uvmhome CDNS-1.2 \ + -l ${OUT}/compile.log" + + SIM_CMD="irun -R +UVM_TESTNAME=" + +else + echo "unsupported simulator $SIMULATOR" + exit 1 +fi + +# Clean up previous runs +if [[ $SIM_ONLY == 0 ]]; then + rm -rf ${OUT} +fi + +mkdir -p ${OUT} +mkdir -p ${OUT}/asm_tests + +# Compilation +if [[ $SIM_ONLY == 0 ]]; then + ${COMPILE_CMD} +fi + +# Skip simulation if compilation only flag is set +if [[ $CMP_ONLY == 1 ]]; then + exit 0 +fi + +# Run sim +if [[ ${TEST} == "all" ]]; then + echo "Running regression with testlist:" + cat testlist + while read line; do + if ! [[ $line =~ ^\/\/ ]]; then + if [[ $line =~([a-z0-9_-]*)([[:space:]]*)\:([[:space:]]*)([0-9]*) ]]; then + SEED=`date +%s` + TEST=${BASH_REMATCH[1]} + ITERATION=${BASH_REMATCH[4]} + echo "Running ${TEST}, iteration count: ${ITERATION}" + if ! [[ $ITERATION == "0" ]]; then + ${SIM_CMD}${TEST} +asm_file_name=${OUT}/asm_tests/${TEST} \ + +ntb_random_seed=${SEED} \ + -l ${OUT}/sim_${TEST}.log +num_of_tests=${ITERATION} + fi + fi + fi + done < testlist +else + echo "Running test ${TEST} with $SIMULATOR.." + ${SIM_CMD}${TEST} +asm_file_name=${OUT}/asm_tests/${TEST} \ + +ntb_random_seed=${SEED} \ + -l ${OUT}/sim_${TEST}.log \ + +num_of_tests=${NUM_TESTS} +fi + +# List all generated assembly tests +echo "===========================================================" +echo " Generated RISC-V assembly tests" +echo " ----------------------------------------------------------" +find $OUT/asm_tests -name "*.S" | sort -k11 diff --git a/vendor/google_riscv-dv/scripts/ibex_log_to_trace_csv.py b/vendor/google_riscv-dv/scripts/ibex_log_to_trace_csv.py new file mode 100644 index 00000000..34036bbc --- /dev/null +++ b/vendor/google_riscv-dv/scripts/ibex_log_to_trace_csv.py @@ -0,0 +1,53 @@ +""" +Copyright lowRISC contributors. +Licensed under the Apache License, Version 2.0, see LICENSE for details. +SPDX-License-Identifier: Apache-2.0 + +Convert ibex log to the standard trace CSV format +""" + +import re +import argparse + +from riscv_trace_csv import * + +def process_ibex_sim_log(ibex_log, csv): + """Process ibex simulation log. + + Extract instruction and affected register information from ibex simulation + log and save to a standard CSV format. + """ + print("Processing ibex log : %s" % ibex_log) + instr_cnt = 0 + ibex_instr = "" + + with open(ibex_log, "r") as f, open(csv, "w") as csv_fd: + trace_csv = RiscvInstructiontTraceCsv(csv_fd) + trace_csv.start_new_trace() + for line in f: + # Extract instruction infromation + m = re.search(r"^\s*(?P