-
Notifications
You must be signed in to change notification settings - Fork 141
Use regfile YAMLs for F, V; enhance trusim to understand #1813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dhower-qc
wants to merge
9
commits into
riscv:main
Choose a base branch
from
dhower-qc:regfile
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b0ae511
Use regfile YAMLs for F, V; enhance trusim to understand
dhower-qc e6551f6
Merge remote-tracking branch 'origin/main' into regfile
dhower-qc f6da17b
fix ci errors
dhower-qc c77b8f1
address review comments
dhower-qc 5548c71
Merge remote-tracking branch 'origin/main' into regfile
dhower-qc 83c3688
[autofix.ci] apply automated fixes
autofix-ci[bot] aa14319
add missing _value
dhower-qc 86eecd5
Merge remote-tracking branch 'dhower-qc/regfile' into regfile
dhower-qc 8342107
[autofix.ci] apply automated fixes
autofix-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| // Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| // SPDX-License-Identifier: BSD-3-Clause-Clear | ||
|
|
||
| // Tests for register file storage and accessor generation (Layer 4a–4c). | ||
|
|
||
| #include <catch2/catch_test_macros.hpp> | ||
| #include <udb/hart_factory.hxx> | ||
| #include <udb/iss_soc_model.hpp> | ||
| #include <stdexcept> | ||
|
|
||
| // Use the rv64-riscv-tests config (known-working fully-configured rv64 with F extension). | ||
| static const std::string cfg_yaml = R"( | ||
| $schema: https://riscv.org/udb/schemas/config_schema-0.1.0.json | ||
| kind: architecture configuration | ||
| type: fully configured | ||
| name: rv64-riscv-tests | ||
| description: For register file testing | ||
|
|
||
| implemented_extensions: | ||
| - [Sm, "1.11.0"] | ||
| - [Smstateen, "1.0.0"] | ||
| - [I, "2.1"] | ||
| - [C, "2.0"] | ||
| - [M, "2.0"] | ||
| - [Zicsr, "2.0"] | ||
| - [Zicntr, "2.0"] | ||
| - [Smrnmi, "1.0"] | ||
| - [S, "1.11.0"] | ||
| - [U, "1.0.0"] | ||
| - [Zifencei, "2.0.0"] | ||
| - [Sv39, "1.11.0"] | ||
| - [Zca, "1.0.0"] | ||
| - [F, "2.2.0"] | ||
|
|
||
| params: | ||
| MXLEN: 64 | ||
| MARCHID_IMPLEMENTED: true | ||
| ARCH_ID_VALUE: 1 | ||
| MIMPID_IMPLEMENTED: true | ||
| IMP_ID_VALUE: 0 | ||
| VENDOR_ID_BANK: 1 | ||
| VENDOR_ID_OFFSET: 1 | ||
| MISALIGNED_LDST: true | ||
| MISALIGNED_LDST_EXCEPTION_PRIORITY: low | ||
| MISALIGNED_MAX_ATOMICITY_GRANULE_SIZE: 4 | ||
| MISALIGNED_SPLIT_STRATEGY: sequential_bytes | ||
| PRECISE_SYNCHRONOUS_EXCEPTIONS: true | ||
| TRAP_ON_ECALL_FROM_M: true | ||
| TRAP_ON_EBREAK: true | ||
| M_MODE_ENDIANNESS: little | ||
| TRAP_ON_ILLEGAL_WLRL: true | ||
| TRAP_ON_UNIMPLEMENTED_INSTRUCTION: true | ||
| TRAP_ON_RESERVED_INSTRUCTION: true | ||
| TRAP_ON_UNIMPLEMENTED_CSR: true | ||
| REPORT_VA_IN_MTVAL_ON_BREAKPOINT: true | ||
| REPORT_VA_IN_MTVAL_ON_LOAD_MISALIGNED: true | ||
| REPORT_VA_IN_MTVAL_ON_STORE_AMO_MISALIGNED: true | ||
| REPORT_VA_IN_MTVAL_ON_INSTRUCTION_MISALIGNED: true | ||
| REPORT_VA_IN_MTVAL_ON_LOAD_ACCESS_FAULT: true | ||
| REPORT_VA_IN_MTVAL_ON_STORE_AMO_ACCESS_FAULT: true | ||
| REPORT_VA_IN_MTVAL_ON_INSTRUCTION_ACCESS_FAULT: true | ||
| REPORT_ENCODING_IN_MTVAL_ON_ILLEGAL_INSTRUCTION: true | ||
| MTVAL_WIDTH: 32 | ||
| PMA_GRANULARITY: 12 | ||
| PHYS_ADDR_WIDTH: 57 | ||
| MISA_CSR_IMPLEMENTED: true | ||
| MTVEC_ACCESS: rw | ||
| MTVEC_MODES: [0, 1] | ||
| MTVEC_BASE_ALIGNMENT_DIRECT: 4 | ||
| MTVEC_BASE_ALIGNMENT_VECTORED: 4 | ||
| MTVEC_ILLEGAL_WRITE_BEHAVIOR: retain | ||
| MUTABLE_MISA_C: false | ||
| MUTABLE_MISA_M: false | ||
| TIME_CSR_IMPLEMENTED: false | ||
| MUTABLE_MISA_S: false | ||
| ASID_WIDTH: 5 | ||
| S_MODE_ENDIANNESS: little | ||
| SXLEN: [64] | ||
| REPORT_VA_IN_MTVAL_ON_LOAD_PAGE_FAULT: true | ||
| REPORT_VA_IN_MTVAL_ON_STORE_AMO_PAGE_FAULT: true | ||
| REPORT_VA_IN_MTVAL_ON_INSTRUCTION_PAGE_FAULT: true | ||
| REPORT_VA_IN_STVAL_ON_BREAKPOINT: true | ||
| REPORT_VA_IN_STVAL_ON_LOAD_MISALIGNED: true | ||
| REPORT_VA_IN_STVAL_ON_STORE_AMO_MISALIGNED: true | ||
| REPORT_VA_IN_STVAL_ON_INSTRUCTION_MISALIGNED: true | ||
| REPORT_VA_IN_STVAL_ON_LOAD_ACCESS_FAULT: true | ||
| REPORT_VA_IN_STVAL_ON_STORE_AMO_ACCESS_FAULT: true | ||
| REPORT_VA_IN_STVAL_ON_INSTRUCTION_ACCESS_FAULT: true | ||
| REPORT_VA_IN_STVAL_ON_LOAD_PAGE_FAULT: true | ||
| REPORT_VA_IN_STVAL_ON_STORE_AMO_PAGE_FAULT: true | ||
| REPORT_VA_IN_STVAL_ON_INSTRUCTION_PAGE_FAULT: true | ||
| REPORT_ENCODING_IN_STVAL_ON_ILLEGAL_INSTRUCTION: true | ||
| STVAL_WIDTH: 32 | ||
| MCOUNTENABLE_EN: [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false] | ||
| SCOUNTENABLE_EN: [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false] | ||
| COUNTINHIBIT_EN: [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false] | ||
| STVEC_MODE_DIRECT: true | ||
| STVEC_MODE_VECTORED: true | ||
| SATP_MODE_BARE: true | ||
| TRAP_ON_ECALL_FROM_S: true | ||
| TRAP_ON_ECALL_FROM_U: true | ||
| MSTATUS_VS_LEGAL_VALUES: [0] | ||
| MSTATUS_FS_LEGAL_VALUES: [3, 2, 1, 0] | ||
| MSTATUS_TVM_IMPLEMENTED: false | ||
| NUM_PMP_ENTRIES: 16 | ||
| PMP_GRANULARITY: 12 | ||
| MUTABLE_MISA_U: false | ||
| U_MODE_ENDIANNESS: little | ||
| UXLEN: [64] | ||
| MSTATEEN_ENVCFG_TYPE: rw | ||
| HW_MSTATUS_FS_DIRTY_UPDATE: precise | ||
| MUTABLE_MISA_F: false | ||
| HPM_COUNTER_EN: [false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false] | ||
| )"; | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // X register file tests (Layer 4a–4c) | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| TEST_CASE("X register storage has 32 entries", "[regfile]") { | ||
| udb::IssSocModel soc(1024 * 1024, 0); | ||
| auto* hart = udb::HartFactory::create("rv64", 0, cfg_yaml, soc); | ||
| // Write a known value to x31, verify it round-trips; index 32 throws. | ||
| REQUIRE_NOTHROW(hart->set_xreg(31, 42)); | ||
| REQUIRE(hart->xreg(31) == 42); | ||
| REQUIRE_THROWS_AS(hart->xreg(32), std::out_of_range); | ||
| delete hart; | ||
| } | ||
|
|
||
| TEST_CASE("x0 is zero after reset", "[regfile]") { | ||
| udb::IssSocModel soc(1024 * 1024, 0); | ||
| auto* hart = udb::HartFactory::create("rv64", 0, cfg_yaml, soc); | ||
| REQUIRE(hart->xreg(0) == 0); | ||
| delete hart; | ||
| } | ||
|
|
||
| TEST_CASE("writing to x0 leaves it zero (arch_write)", "[regfile]") { | ||
| udb::IssSocModel soc(1024 * 1024, 0); | ||
| auto* hart = udb::HartFactory::create("rv64", 0, cfg_yaml, soc); | ||
| hart->set_xreg(0, 42); | ||
| REQUIRE(hart->xreg(0) == 0); | ||
| delete hart; | ||
| } | ||
|
|
||
| TEST_CASE("xreg throws out_of_range for index >= 32", "[regfile]") { | ||
| udb::IssSocModel soc(1024 * 1024, 0); | ||
| auto* hart = udb::HartFactory::create("rv64", 0, cfg_yaml, soc); | ||
| REQUIRE_THROWS_AS(hart->set_xreg(32, 0), std::out_of_range); | ||
| delete hart; | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // F register file tests (Layer 4d: hart.hpp adds virtual freg() to HartBase) | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| TEST_CASE("F register storage has 32 entries", "[regfile]") { | ||
| udb::IssSocModel soc(1024 * 1024, 0); | ||
| auto* hart = udb::HartFactory::create("rv64", 0, cfg_yaml, soc); | ||
| REQUIRE_NOTHROW(hart->set_freg(31, 0xdeadbeef)); | ||
| REQUIRE(hart->freg(31) == 0xdeadbeef); | ||
| REQUIRE_THROWS_AS(hart->freg(32), std::out_of_range); | ||
| delete hart; | ||
| } | ||
|
|
||
| TEST_CASE("freg round-trips a written value", "[regfile]") { | ||
| udb::IssSocModel soc(1024 * 1024, 0); | ||
| auto* hart = udb::HartFactory::create("rv64", 0, cfg_yaml, soc); | ||
| hart->set_freg(0, 0x3f800000); | ||
| REQUIRE(hart->freg(0) == 0x3f800000); | ||
| delete hart; | ||
| } | ||
|
|
||
| TEST_CASE("freg throws out_of_range for index >= 32", "[regfile]") { | ||
| udb::IssSocModel soc(1024 * 1024, 0); | ||
| auto* hart = udb::HartFactory::create("rv64", 0, cfg_yaml, soc); | ||
| REQUIRE_THROWS_AS(hart->set_freg(32, 0), std::out_of_range); | ||
| delete hart; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.