compare mem_checker and machine
This commit is contained in:
@ -177,9 +177,7 @@ impl Machine {
|
||||
/// - **machine** which contains a table of instructions
|
||||
pub fn run(machine : Machine){
|
||||
let mut m = machine;
|
||||
for i in 0..MEM_SIZE{
|
||||
Machine::one_instruction(&mut m);
|
||||
}
|
||||
while Machine::one_instruction(&mut m) == 0 {}
|
||||
}
|
||||
|
||||
/// execute the current instruction
|
||||
@ -187,7 +185,7 @@ impl Machine {
|
||||
/// ### Parameters
|
||||
///
|
||||
/// - **machine** which contains a table of instructions and a pc to the actual instruction
|
||||
pub fn one_instruction(machine :&mut Machine) {
|
||||
pub fn one_instruction(machine :&mut Machine) -> i32 {
|
||||
|
||||
let unsigned_reg1 : u64;
|
||||
let unsigned_reg2 : u64;
|
||||
@ -210,10 +208,11 @@ impl Machine {
|
||||
}
|
||||
|
||||
let val = u32::from_be_bytes(val) as u64;
|
||||
let inst : Instruction = decode(val);
|
||||
Self::print_machine_status(machine);
|
||||
println!("executing instruction : {:016x} at pc {:x}", val, machine.pc);
|
||||
println!("{}", print::print(decode(val), machine.pc as i32));
|
||||
let inst : Instruction = decode(val);
|
||||
|
||||
|
||||
|
||||
match inst.opcode {
|
||||
@ -626,10 +625,16 @@ impl Machine {
|
||||
}
|
||||
}
|
||||
}
|
||||
RISCV_SYSTEM => {
|
||||
// temporary return value to stop the loop of run
|
||||
// before we can use system call
|
||||
return 1;
|
||||
}
|
||||
_ => { panic!("{:x} opcode non géré pc : {:x}", inst.opcode, machine.pc)},
|
||||
}
|
||||
|
||||
machine.pc += 4; // Possible bug avec jump
|
||||
machine.pc += 4;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user