Skip to content

Commit

Permalink
[rocketemu] exit with right EXIT_CODE check
Browse files Browse the repository at this point in the history
  • Loading branch information
Clo91eaf authored and sequencer committed Jul 25, 2024
1 parent a879f16 commit 2f13506
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
12 changes: 7 additions & 5 deletions rocketemu/driver/src/dpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ pub type SvBitVecVal = u32;
unsafe fn load_from_payload(
payload: &*const SvBitVecVal,
aw_size: c_longlong,
data_width: u32,
data_width: usize,
dlen: usize,
) -> (Vec<bool>, &[u8]) {
let src = *payload as *mut u8;
let data_width_in_byte = (data_width / 8) as usize;
let strb_width_in_byte = data_width_in_byte.div_ceil(8); // ceil divide by 8 to get byte width
let data_width_in_byte = dlen / 8;
let strb_width_in_byte = dlen / data_width;
let payload_size_in_byte = strb_width_in_byte + data_width_in_byte; // data width in byte
let byte_vec = std::slice::from_raw_parts(src, payload_size_in_byte);
let strobe = &byte_vec[0..strb_width_in_byte];
let data = &byte_vec[strb_width_in_byte..];

let strb_width_in_bit = std::cmp::min(8, data_width_in_byte);
let strb_width_in_bit = data_width / 8;
let masks: Vec<bool> = strobe
.into_iter()
.flat_map(|strb| {
Expand Down Expand Up @@ -97,7 +98,8 @@ unsafe extern "C" fn axi_write_loadStoreAXI_rs(
);

let sim = &mut *(target as *mut Simulator);
let (strobe, data) = load_from_payload(&payload, 1 << awsize, sim.dlen);
let data_width = 32; // TODO: get from sim
let (strobe, data) = load_from_payload(&payload, 1 << awsize, data_width, sim.dlen as usize);
sim.axi_write(awaddr as u32, &strobe, data);
}

Expand Down
19 changes: 10 additions & 9 deletions rocketemu/driver/src/sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub(crate) struct AxiReadPayload {
}

const EXIT_POS: u32 = 0x4000_0000;
const EXIT_CODE: u32 = 0xdead_beef;

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
Expand Down Expand Up @@ -263,15 +264,15 @@ impl Simulator {
get_t()
);
let data_hex = hex::encode(data);
info!(
"[{}] axi_write (addr={addr:#x}, data={data_hex})",
get_t()
);

if addr == EXIT_POS {
info!("exit with code: {:x?}", data);
quit();
return;
info!("[{}] axi_write (addr={addr:#x}, data={data_hex})", get_t());

if addr == EXIT_POS && data.len() >= 4 {
let exit_code = u32::from_le_bytes([data[0], data[1], data[2], data[3]]);
if exit_code == EXIT_CODE {
info!("exit with code: {:x?}", exit_code);
quit();
return;
}
}

self.write_mem(addr, self.dlen / 8, strobe, data);
Expand Down

0 comments on commit 2f13506

Please sign in to comment.