Skip to content

Commit

Permalink
Test write to ROM (#433)
Browse files Browse the repository at this point in the history
  • Loading branch information
rusty1968 authored Jul 14, 2023
1 parent 54e926b commit 26fb699
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions hw-model/test-fw/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,8 @@ required-features = ["riscv"]
name = "test_invalid_instruction"
path = "test_invalid_instruction.rs"
required-features = ["riscv"]

[[bin]]
name = "test_write_to_rom"
path = "test_write_to_rom.rs"
required-features = ["riscv"]
25 changes: 25 additions & 0 deletions hw-model/test-fw/test_write_to_rom.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed under the Apache-2.0 license

//! A very simple program to test the behavior of the CPU when trying to write to ROM.

#![no_main]
#![no_std]

// Needed to bring in startup code
#[allow(unused)]
use caliptra_test_harness::println;

#[panic_handler]
pub fn panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
}

#[no_mangle]
extern "C" fn main() {
unsafe {
let rom_address = 0x00_u32;
let rom_address_ptr = rom_address as *mut u32;
*rom_address_ptr = 0xdeadbeef;
}
loop {}
}
16 changes: 16 additions & 0 deletions hw-model/tests/model_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,19 @@ fn test_invalid_instruction_exception_failure() {
harness::NMI_CAUSE_ILLEGAL_INSTRUCTION_ERROR
);
}

#[test]
fn test_write_to_rom() {
let elf = caliptra_builder::build_firmware_elf(&FwId {
bin_name: "test_write_to_rom",
..BASE_FWID
})
.unwrap();
let mut model = run_fw_elf(&elf);
model.step_until_exit_success().unwrap_err();
let soc_ifc: caliptra_registers::soc_ifc::RegisterBlock<_> = model.soc_ifc();
assert_eq!(
soc_ifc.cptra_fw_error_non_fatal().read(),
harness::ERROR_EXCEPTION
);
}

0 comments on commit 26fb699

Please sign in to comment.