2023-06-24 17:16:14 -05:00
|
|
|
use hbvm::vm::{
|
|
|
|
mem::{Memory, MemoryAccessReason, PageSize},
|
|
|
|
trap::HandleTrap,
|
|
|
|
value::Value,
|
|
|
|
};
|
|
|
|
|
2023-06-20 19:07:48 -05:00
|
|
|
use {
|
|
|
|
hbvm::{validate::validate, vm::Vm},
|
|
|
|
std::io::{stdin, Read},
|
2023-04-22 13:00:19 -05:00
|
|
|
};
|
2023-04-18 18:08:30 -05:00
|
|
|
|
2023-06-20 19:07:48 -05:00
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
let mut prog = vec![];
|
|
|
|
stdin().read_to_end(&mut prog)?;
|
2023-06-24 17:16:14 -05:00
|
|
|
|
2023-06-20 19:07:48 -05:00
|
|
|
if let Err(e) = validate(&prog) {
|
|
|
|
eprintln!("Program validation error: {e:?}");
|
|
|
|
return Ok(());
|
|
|
|
} else {
|
|
|
|
unsafe {
|
2023-07-11 03:29:23 -05:00
|
|
|
let mut vm = Vm::<_, 0>::new_unchecked(&prog, TestTrapHandler);
|
2023-06-20 19:07:48 -05:00
|
|
|
vm.memory.insert_test_page();
|
|
|
|
println!("Program interrupt: {:?}", vm.run());
|
|
|
|
println!("{:?}", vm.registers);
|
|
|
|
}
|
|
|
|
}
|
2023-04-22 16:06:33 -05:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn time() -> u32 {
|
|
|
|
9
|
|
|
|
}
|
2023-06-24 17:16:14 -05:00
|
|
|
|
|
|
|
struct TestTrapHandler;
|
|
|
|
impl HandleTrap for TestTrapHandler {
|
|
|
|
fn page_fault(
|
|
|
|
&mut self,
|
|
|
|
_: MemoryAccessReason,
|
|
|
|
_: &mut Memory,
|
|
|
|
_: u64,
|
|
|
|
_: PageSize,
|
|
|
|
_: *mut u8,
|
|
|
|
) -> bool {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
fn invalid_op(&mut self, _: &mut [Value; 256], _: &mut usize, _: &mut Memory, _: u8) -> bool
|
|
|
|
where
|
|
|
|
Self: Sized,
|
|
|
|
{
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
fn ecall(&mut self, _: &mut [Value; 256], _: &mut usize, _: &mut Memory)
|
|
|
|
where
|
|
|
|
Self: Sized,
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|