Skip to content

[top,dv] Init TB top#213

Merged
marnovandermaas merged 18 commits into
mainfrom
init_tb_top
Feb 13, 2026
Merged

[top,dv] Init TB top#213
marnovandermaas merged 18 commits into
mainfrom
init_tb_top

Conversation

@martin-velay
Copy link
Copy Markdown
Contributor

@martin-velay martin-velay commented Dec 23, 2025

Linked to issue #31, but doesn't cover it all.

Instructions to get the C code running on the top level TB in UVM style:

  1. Build the SW with: https://github.com/lowRISC/mocha?tab=readme-ov-file#build
  2. Run the simulation with:
    dvsim hw/top_chip/dv/top_chip_sim_cfg.hjson -i uart_smoke -t xcelium
    Result:
UVM_INFO @             20414030: (sw_test_status_if.sv:61) [tb.u_sim_sram.u_sim_sram_if.u_sw_test_status_if] SW test transitioned to SwTestStatusInTest.
...
UVM_INFO @            349734030: (sw_test_status_if.sv:61) [tb.u_sim_sram.u_sim_sram_if.u_sw_test_status_if] SW test transitioned to SwTestStatusPassed.
UVM_INFO @            349734030: (sw_test_status_if.sv:82) [tb.u_sim_sram.u_sim_sram_if.u_sw_test_status_if] ==== SW TEST PASSED ====
...
TEST PASSED CHECKS
 _____         _                                  _ _ 
|_   _|__  ___| |_   _ __   __ _ ___ ___  ___  __| | |
  | |/ _ \/ __| __| | '_ \ / _` / __/ __|/ _ \/ _` | |
  | |  __/\__ \ |_  | |_) | (_| \__ \__ \  __/ (_| |_|
  |_|\___||___/\__| | .__/ \__,_|___/___/\___|\__,_(_)
                    |_|                               

Instructions to get the C code running on the top level TB in Verilator style:

  1. Build the SW with: https://github.com/lowRISC/mocha?tab=readme-ov-file#build
  2. Build Verilator:
    fusesoc --cores-root=. run --target=sim --tool=verilator --setup --build lowrisc:mocha:top_chip_verilator
  3. Run C tests with Verilator:
    ctest --test-dir build/sw -R sim_verilator

Which should give:

Test project /scratch/mvelay/mocha/build/sw
      Start  1: test_framework_test_sim_verilator
 1/14 Test  #1: test_framework_test_sim_verilator ...................   Passed    0.57 sec
      Start  2: test_framework_test_cheri_sim_verilator
 2/14 Test  #2: test_framework_test_cheri_sim_verilator .............   Passed    0.59 sec
      Start  3: test_framework_exception_test_sim_verilator
 3/14 Test  #3: test_framework_exception_test_sim_verilator .........   Passed    0.75 sec
      Start  4: test_framework_exception_test_cheri_sim_verilator
 4/14 Test  #4: test_framework_exception_test_cheri_sim_verilator ...   Passed    0.80 sec
      Start  5: plic_smoketest_sim_verilator
 5/14 Test  #5: plic_smoketest_sim_verilator ........................   Passed    0.47 sec
      Start  6: plic_smoketest_cheri_sim_verilator
 6/14 Test  #6: plic_smoketest_cheri_sim_verilator ..................   Passed    0.53 sec
      Start  7: spi_device_smoketest_sim_verilator
 7/14 Test  #7: spi_device_smoketest_sim_verilator ..................   Passed    1.11 sec
      Start  8: spi_device_smoketest_cheri_sim_verilator
 8/14 Test  #8: spi_device_smoketest_cheri_sim_verilator ............   Passed    1.23 sec
      Start  9: timer_smoketest_sim_verilator
 9/14 Test  #9: timer_smoketest_sim_verilator .......................   Passed    0.48 sec
      Start 10: timer_smoketest_cheri_sim_verilator
10/14 Test #10: timer_smoketest_cheri_sim_verilator .................   Passed    0.54 sec
      Start 11: timer_interrupt_test_sim_verilator
11/14 Test #11: timer_interrupt_test_sim_verilator ..................   Passed    1.19 sec
      Start 12: timer_interrupt_test_cheri_sim_verilator
12/14 Test #12: timer_interrupt_test_cheri_sim_verilator ............   Passed    1.28 sec
      Start 13: uart_smoketest_sim_verilator
13/14 Test #13: uart_smoketest_sim_verilator ........................   Passed    0.46 sec
      Start 14: uart_smoketest_cheri_sim_verilator
14/14 Test #14: uart_smoketest_cheri_sim_verilator ..................   Passed    0.53 sec

100% tests passed, 0 tests failed out of 14

@martin-velay
Copy link
Copy Markdown
Contributor Author

@ziuziakowska, I've just pushed all what I had related to the SW-DV topic mentioned in this issue.

Comment thread hw/top_chip/dv/top_chip_sim_cfg.hjson Outdated
Copy link
Copy Markdown
Collaborator

@marnovandermaas marnovandermaas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is some great work! Thanks for learning from Sunburst chip. I've done a code review and left some initial comments.

Comment thread hw/top_chip/dv/env/seq_lib/top_chip_dv_base_vseq.sv Outdated
Comment thread hw/top_chip/dv/env/seq_lib/top_chip_dv_base_vseq.sv
Comment thread hw/top_chip/dv/env/seq_lib/top_chip_dv_base_vseq.sv Outdated
Comment thread hw/top_chip/dv/env/seq_lib/top_chip_dv_base_vseq.sv Outdated
Comment thread hw/top_chip/dv/env/seq_lib/top_chip_dv_base_vseq.sv
Comment thread hw/vendor/patches/cva6_cheri/0007_tag_data_sram_wmask.patch
Comment thread hw/top_chip/rtl/top_pkg.sv Outdated
Comment thread hw/top_chip/dv/tb/sim_sram_axi_sink.sv Outdated
Comment thread hw/top_chip/dv/tb/sim_sram_axi_sink.sv Outdated
Comment thread hw/top_chip/dv/tb/sim_sram_axi_sink.sv Outdated
@martin-velay martin-velay force-pushed the init_tb_top branch 5 times, most recently from 708aab1 to 12c93fa Compare January 30, 2026 16:23
@martin-velay
Copy link
Copy Markdown
Contributor Author

@marnovandermaas, thanks a lot for your good review. I have now taken into account all the comment which required changes. There is only one remaining item: #213 (comment)

Please let me know what you think I should do. If needed we can have a call next week

- This solves a cache illegal state caused by an out of range array
  index in the decode logic in the id_stage.sv file.

Signed-off-by: martin-velay <mvelay@lowrisc.org>
- Remove useless dependencies: crypto_dpi_prince, digestpp_dpi and
  kmac_pkg

Signed-off-by: martin-velay <mvelay@lowrisc.org>
- The module instr_tracer is only used for non-Verilator simulations. It
  is a behavioral module that traces instructions executed by the core
  and logs them to a file. This is useful for debugging and performance
  analysis.

Signed-off-by: martin-velay <mvelay@lowrisc.org>
- Required to get .log.txt and rodata.txt files needed by
  sw_logger_if.

Signed-off-by: martin-velay <mvelay@lowrisc.org>
- This follows the pattern established in OpenTitan to create a dedicated
  simulation SRAM region that can be used by software running on the CPU to
  communicate directly with the DV environment. This is useful for logging
  and test status reporting from SW to DV.
- See: https://opentitan.org/book/hw/dv/sv/sim_sram/index.html
- This commit will close #249

Signed-off-by: martin-velay <mvelay@lowrisc.org>
- Include top_chip_sim_cfg.hjson into mocha_sim_cfg.hjson so that
  the top level regression is run when running the global regression.
  This is needed for the nightly/weekly CI regressions.

Signed-off-by: martin-velay <mvelay@lowrisc.org>
- For the moment, only the signals are added to match the DUT, but they
  are not connected to any SPI agent. This will be done in a future PR.

Signed-off-by: martin-velay <mvelay@lowrisc.org>
Signed-off-by: martin-velay <mvelay@lowrisc.org>
- Declare Verilator separatly from top_chip_system core into its own
  core file. This is needed to avoid circular dependencies after
  introducing the sim_sram_axi_sink for Verilator simulations.

Signed-off-by: martin-velay <mvelay@lowrisc.org>
ziuziakowska and others added 2 commits February 13, 2026 14:14
Signed-off-by: Alice Ziuziakowska <a.ziuziakowska@lowrisc.org>
Signed-off-by: martin-velay <mvelay@lowrisc.org>
@martin-velay
Copy link
Copy Markdown
Contributor Author

@engdoreis, I have applied the suggested patch. It fixes the UART issue, thanks!

Now, it remains one issue, the CI will fail I believe while running Verilator tests. To fix this I need to change the address below into something else:

localparam bit [31:0] VERILATOR_SW_DV_START_ADDR = 'h2001_0000;

My suspicion is that this below will trigger a simulation termination:
always @(posedge clk_i) begin
if (u_sw_test_status_if.sw_test_done) begin
$display("Verilator sim termination requested");
$display("Your simulation wrote to 0x%h", u_sw_test_status_if.sw_test_status_addr);
dv_test_status_pkg::dv_test_status(u_sw_test_status_if.sw_test_passed);
$finish;
end
end

Anybody knows how to debug this with Verilator? @ziuziakowska or @engdoreis ?

@ziuziakowska
Copy link
Copy Markdown
Contributor

Locally, I use a script like this called run_verilator.sh that I run with a compiled binary to test:

#!/bin/sh
nix develop --command bash -c "build/lowrisc_mocha_top_chip_system_0/sim-verilator/Vtop_chip_verilator -t -E $1"

So for example, run_verilator.sh build/sw/device/tests/uart_smoketest to run the UART smoketest on Verilator. The -t flag makes the Verilator simulation write out a trace of all the instructions executed to trace_hart_0.dasm in the Mocha directory. The software build also outputs a disassembly of all the compiled binaries, which you can find in build/sw/device/tests/uart_smoketest.dump for that example. Using that disassembly you can find the address of the function that might be causing the issue and following the execution trace. If the tests are failing fast, it is likely that the binaries are running as expected, and the memory write to the unmapped DV status region is trying to proceed as any other write, causing a fault.

You may be able to apply #289 on top of your branch temporarily and try running it with that, as that PR adds printing a register dump on an unhandled exception, so you'll get a view of the registers when the exception occurred printed to the UART (captured in uart0.log).

- This change is required as the SW now performs special writes for the
  DV to know when the simulation should be terminated. In Verilator
  this was handled by a "magic word" write on the UART.

Signed-off-by: martin-velay <mvelay@lowrisc.org>
@martin-velay
Copy link
Copy Markdown
Contributor Author

Copy link
Copy Markdown
Collaborator

@engdoreis engdoreis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with the results produced by this PR.

Copy link
Copy Markdown
Contributor

@ziuziakowska ziuziakowska left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM on the SW side 👍.

@engdoreis
Copy link
Copy Markdown
Collaborator

The fpga runner error in CI is likely related to my experiments in the runner.

Copy link
Copy Markdown
Collaborator

@marnovandermaas marnovandermaas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR and making CI pass. I've tested the command and it passes.

dvsim hw/top_chip/dv/top_chip_sim_cfg.hjson -i uart_smoke -t xcelium

Let's get this PR merged and we can then build upon it with refinements.

@marnovandermaas
Copy link
Copy Markdown
Collaborator

fpga-test is failing, but the bitstream is building and it's failing on the flashing. This flashing is ok to fail for now as we are still building this CI step.

@marnovandermaas marnovandermaas merged commit 9911567 into main Feb 13, 2026
6 of 8 checks passed
@martin-velay
Copy link
Copy Markdown
Contributor Author

Excellent! I am really happy, thanks all for your support and feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants