#[repr(C)]
pub struct EvalResultRaw {
pub outcome: u32,
pub reschedule: [u8; 32],
}
fn completed() -> EvalResultRaw {
EvalResultRaw {
outcome: 0, reschedule: [0u8; 32],
}
}
#[repr(C)]
pub struct SimTimeRaw {
pub sim_units: i64,
pub delta: u32,
}
#[repr(C)]
pub struct WideViewRaw {
pub aval: *mut u64,
pub bval: *mut u64,
pub word_count: u32,
}
static mut CELL: u128 = 0;
static mut IN_CELL: u128 = 0;
static mut OUT_CELL: u128 = 0;
static mut REQUEST_CELL: u128 = 0;
static mut NBA_STAGE: u128 = 0;
static mut NBA_PENDING: bool = false;
static mut CURRENT_TIME: i64 = 0;
const DELAY_DUE_TIME: i64 = 10;
static mut DELAY_CELL: u128 = 0;
static mut DELAY_RAN: bool = false;
static mut FINAL_CELL: u128 = 0;
static mut FINAL_RAN: bool = false;
#[unsafe(no_mangle)]
pub extern "C" fn sim_abi_version() -> u32 {
__ABI_VERSION__
}
#[unsafe(no_mangle)]
pub extern "C" fn sim_init(_design_id: u32) -> *mut core::ffi::c_void {
__ABORT__
unsafe {
CELL = 0;
IN_CELL = 0;
OUT_CELL = 0;
REQUEST_CELL = 0;
NBA_STAGE = 0;
NBA_PENDING = false;
CURRENT_TIME = 0;
DELAY_CELL = 0;
DELAY_RAN = false;
FINAL_CELL = 0;
FINAL_RAN = false;
}
core::ptr::NonNull::<u8>::dangling().as_ptr().cast()
}
#[unsafe(no_mangle)]
pub extern "C" fn sim_settle(_h: *mut core::ffi::c_void) -> EvalResultRaw {
__ABORT__
unsafe {
OUT_CELL = IN_CELL;
}
completed()
}
#[unsafe(no_mangle)]
pub extern "C" fn sim_eval_region(
_h: *mut core::ffi::c_void,
_region: u32,
_t: SimTimeRaw,
) -> EvalResultRaw {
__ABORT__
match _region {
0 => {
let request = unsafe { REQUEST_CELL };
if request != 0 {
return VJ_PROCESS_TABLE[0](_h, core::ptr::null_mut(), 0);
}
unsafe {
if CURRENT_TIME >= DELAY_DUE_TIME && !DELAY_RAN {
DELAY_CELL = DELAY_CELL.wrapping_add(1);
DELAY_RAN = true;
}
}
}
1 => {
}
2 => {
unsafe {
NBA_STAGE = IN_CELL;
NBA_PENDING = true;
}
}
3 => {
}
4 => {
}
other => panic!("test_kernel: sim_eval_region called with unknown region {other}"),
}
completed()
}
#[unsafe(no_mangle)]
pub extern "C" fn sim_commit_nba(_h: *mut core::ffi::c_void, _t: SimTimeRaw) -> EvalResultRaw {
__ABORT__
unsafe {
if NBA_PENDING {
OUT_CELL = NBA_STAGE;
NBA_PENDING = false;
}
}
completed()
}
#[unsafe(no_mangle)]
pub extern "C" fn sim_step_time(_h: *mut core::ffi::c_void, _t: SimTimeRaw) -> EvalResultRaw {
__ABORT__
unsafe {
CURRENT_TIME = _t.sim_units;
}
completed()
}
#[unsafe(no_mangle)]
pub extern "C" fn sim_save(_h: *mut core::ffi::c_void) -> *mut core::ffi::c_void {
__ABORT__
core::ptr::null_mut()
}
#[unsafe(no_mangle)]
pub extern "C" fn sim_restore(_h: *mut core::ffi::c_void, _checkpoint: *mut core::ffi::c_void) {
__ABORT__
}
#[unsafe(no_mangle)]
pub extern "C" fn sim_final(_h: *mut core::ffi::c_void) {
__ABORT__
unsafe {
if !FINAL_RAN {
FINAL_CELL = FINAL_CELL.wrapping_add(1);
FINAL_RAN = true;
}
}
}
#[unsafe(no_mangle)]
pub extern "C" fn sim_process_count(_h: *mut core::ffi::c_void) -> u32 {
__ABORT__
VJ_PROCESS_TABLE.len() as u32
}
#[unsafe(no_mangle)]
pub extern "C" fn sv_get_scalar(_h: *mut core::ffi::c_void, _slot: u32) -> u128 {
__ABORT__
unsafe {
match _slot {
0 => CELL,
1 => IN_CELL,
2 => OUT_CELL,
3 => REQUEST_CELL,
4 => DELAY_CELL,
5 => FINAL_CELL,
other => panic!("test_kernel: sv_get_scalar called with unknown slot {other}"),
}
}
}
#[unsafe(no_mangle)]
pub extern "C" fn sv_set_scalar(_h: *mut core::ffi::c_void, _slot: u32, v: u128) {
__ABORT__
unsafe {
match _slot {
0 => CELL = v,
1 => IN_CELL = v,
2 => OUT_CELL = v,
3 => REQUEST_CELL = v,
other => panic!("test_kernel: sv_set_scalar called with unknown slot {other}"),
}
}
}
#[unsafe(no_mangle)]
pub extern "C" fn sv_get_wide(_h: *mut core::ffi::c_void, _slot: u32) -> WideViewRaw {
unreachable!("sv_get_wide is a trivial, never-called stub in this fixture")
}
#[unsafe(no_mangle)]
pub extern "C" fn sv_set_wide(_h: *mut core::ffi::c_void, _slot: u32, _v: WideViewRaw) {
unreachable!("sv_set_wide is a trivial, never-called stub in this fixture")
}
#[unsafe(no_mangle)]
pub extern "C" fn sv_get_mem_word(
_h: *mut core::ffi::c_void,
_slot: u32,
_row: u64,
) -> WideViewRaw {
unreachable!("sv_get_mem_word is a trivial, never-called stub in this fixture")
}
#[unsafe(no_mangle)]
pub extern "C" fn sv_set_mem_word(
_h: *mut core::ffi::c_void,
_slot: u32,
_row: u64,
_v: WideViewRaw,
) {
unreachable!("sv_set_mem_word is a trivial, never-called stub in this fixture")
}
extern "C" fn test_kernel_process(
_h: *mut core::ffi::c_void,
_local: *mut u8,
_resume_pc: u32,
) -> EvalResultRaw {
unsafe {
CELL = CELL.wrapping_add(1);
}
completed()
}
#[unsafe(no_mangle)]
pub static VJ_PROCESS_TABLE: [extern "C" fn(*mut core::ffi::c_void, *mut u8, u32) -> EvalResultRaw; 1] =
[test_kernel_process];
#[unsafe(no_mangle)]
pub extern "C" fn __test_process_table_len() -> u32 {
VJ_PROCESS_TABLE.len() as u32
}