Skip to content

Commit

Permalink
[t1rocket] add quit to terminate simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
Clo91eaf committed Aug 12, 2024
1 parent e1492ee commit 2e45a61
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
9 changes: 9 additions & 0 deletions t1rocketemu/online_dpi/src/dpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ mod dpi_export {
#[cfg(feature = "trace")]
/// `export "DPI-C" function dump_wave(input string file)`
pub fn dump_wave(path: *const c_char);

/// 'export "DPI-C" function quit()'
pub fn quit();
}
}

Expand All @@ -326,3 +329,9 @@ pub(crate) fn dump_wave(scope: crate::svdpi::SvScope, path: &str) {
dpi_export::dump_wave(path_cstring.as_ptr());
}
}

pub(crate) fn quit() {
unsafe {
dpi_export::quit();
}
}
10 changes: 9 additions & 1 deletion t1rocketemu/online_dpi/src/drive.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::dpi::*;
use crate::get_t;
use crate::{ get_t, EXIT_CODE, EXIT_POS };
use crate::svdpi::SvScope;
use crate::OfflineArgs;

Expand Down Expand Up @@ -335,6 +335,14 @@ impl Driver {
self.shadow_mem.write_mem_axi(addr, size, 32, strobe, data);
let data_hex = hex::encode(data);
self.last_commit_cycle = get_t();

// exit with code
if addr == EXIT_POS && data.len() == 4 && data == &EXIT_CODE.to_le_bytes() {
info!("exit successfully");
quit();
return;
}

trace!(
"[{}] axi_write_load_store (addr={addr:#x}, size={size}, data={data_hex})",
get_t()
Expand Down
4 changes: 4 additions & 0 deletions t1rocketemu/online_dpi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ pub(crate) struct OfflineArgs {
pub timeout: u64,
}

// quit signal
const EXIT_POS: u32 = 0x4000_0000;
const EXIT_CODE: u32 = 0xdead_beef;

// keep in sync with TestBench.ClockGen
pub const CYCLE_PERIOD: u64 = 20;

Expand Down
5 changes: 5 additions & 0 deletions t1rocketemu/src/TestBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class TestBench(generator: SerializableModuleGenerator[T1RocketTile, T1RocketTil
|`endif
| endfunction;
|
| export "DPI-C" function quit;
| function quit();
| $$finish;
| endfunction;
|
| import "DPI-C" context function void t1rocket_cosim_init();
| initial begin
| t1rocket_cosim_init();
Expand Down
4 changes: 3 additions & 1 deletion tests/emurt/emurt.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ int _write(int file, char* ptr, int len) {
}

void _exit(int code) {
__asm__("csrwi 0x7cc, 0");
__asm__("li x1, 0x40000000");
__asm__("li x2, 0xdeadbeef");
__asm__("sw x2, 0(x1)");
__builtin_unreachable();
}

Expand Down
4 changes: 3 additions & 1 deletion tests/t1_main.S
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ _start:
call test

// exit
csrwi 0x7cc, 0
li x1, 0x40000000
li x2, 0xdeadbeef
sw x2, 0(x1)

.p2align 2

0 comments on commit 2e45a61

Please sign in to comment.