Skip to content

Commit

Permalink
[t1rocket] fix wrong payload logic in axi_load_store
Browse files Browse the repository at this point in the history
  • Loading branch information
Clo91eaf committed Aug 22, 2024
1 parent b93bd41 commit 9fd2537
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions t1rocketemu/online_dpi/src/dpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,27 @@ unsafe fn fill_axi_read_payload(dst: *mut SvBitVecVal, dlen: u32, payload: &AxiR
unsafe fn load_from_payload(
payload: &*const SvBitVecVal,
data_width: usize,
dlen: usize,
size: usize,
) -> (Vec<bool>, &[u8]) {
let src = *payload as *mut u8;
let data_width_in_byte = dlen / 8;
let strb_width_in_byte = dlen / data_width;
let data_width_in_byte = size;
let strb_width_per_byte = if data_width < 64 { 4 } else { 8 };
let strb_width_in_byte = size.div_ceil(strb_width_per_byte);

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 = data_width / 8;
let masks: Vec<bool> = strobe
.into_iter()
.flat_map(|strb| {
let mask: Vec<bool> = (0..strb_width_in_bit).map(|i| (strb & (1 << i)) != 0).collect();
let mask: Vec<bool> = (0..strb_width_per_byte).map(|i| (strb & (1 << i)) != 0).collect();
mask
})
.collect();
assert!(
masks.len() == data.len(),
assert_eq!(
masks.len(), data.len(),
"strobe bit width is not aligned with data byte width"
);

Expand Down Expand Up @@ -99,8 +100,7 @@ unsafe extern "C" fn axi_write_highBandwidthAXI(
);
let mut driver = DPI_TARGET.lock().unwrap();
let driver = driver.as_mut().unwrap();
let data_width = 32; // TODO: get from driver
let (strobe, data) = load_from_payload(&payload, 32, driver.dlen as usize);
let (strobe, data) = load_from_payload(&payload, driver.dlen as usize, (1 << awsize) as usize);
driver.axi_write_high_bandwidth(awaddr as u32, awsize as u64, &strobe, data);
}

Expand Down Expand Up @@ -156,8 +156,7 @@ unsafe extern "C" fn axi_write_highOutstandingAXI(
);
let mut driver = DPI_TARGET.lock().unwrap();
let driver = driver.as_mut().unwrap();
let data_width = 32; // TODO: get from driver
let (strobe, data) = load_from_payload(&payload, data_width, 32);
let (strobe, data) = load_from_payload(&payload, 32, (1 << awsize) as usize);
driver.axi_write_high_outstanding(awaddr as u32, awsize as u64, &strobe, data);
}

Expand Down Expand Up @@ -211,8 +210,8 @@ unsafe extern "C" fn axi_write_loadStoreAXI(
);
let mut driver = DPI_TARGET.lock().unwrap();
let driver = driver.as_mut().unwrap();
let data_width = 32; // TODO: get from sim
let (strobe, data) = load_from_payload(&payload, data_width, driver.dlen as usize);
let data_width = if awsize <= 2 { 32 } else { 8 * (1 << awsize) } as usize;
let (strobe, data) = load_from_payload(&payload, data_width, (driver.dlen / 8) as usize);
driver.axi_write_load_store(awaddr as u32, awsize as u64, &strobe, data);
}

Expand Down

0 comments on commit 9fd2537

Please sign in to comment.