compare mem_checker and machine
This commit is contained in:
parent
d352f5dcd2
commit
1e2e537ec9
@ -10,5 +10,5 @@ fn main() {
|
|||||||
mem_cmp::Mem_Checker::fill_memory_from_Mem_Checker(&checker, &mut m);
|
mem_cmp::Mem_Checker::fill_memory_from_Mem_Checker(&checker, &mut m);
|
||||||
//mem_cmp::Mem_Checker::print_Mem_Checker(&checker);
|
//mem_cmp::Mem_Checker::print_Mem_Checker(&checker);
|
||||||
//Machine::print_memory(&mut m, 0x400000, 0x405000);
|
//Machine::print_memory(&mut m, 0x400000, 0x405000);
|
||||||
Machine::run(m);
|
//Machine::run(m);
|
||||||
}
|
}
|
||||||
|
@ -177,9 +177,7 @@ impl Machine {
|
|||||||
/// - **machine** which contains a table of instructions
|
/// - **machine** which contains a table of instructions
|
||||||
pub fn run(machine : Machine){
|
pub fn run(machine : Machine){
|
||||||
let mut m = machine;
|
let mut m = machine;
|
||||||
for i in 0..MEM_SIZE{
|
while Machine::one_instruction(&mut m) == 0 {}
|
||||||
Machine::one_instruction(&mut m);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// execute the current instruction
|
/// execute the current instruction
|
||||||
@ -187,7 +185,7 @@ impl Machine {
|
|||||||
/// ### Parameters
|
/// ### Parameters
|
||||||
///
|
///
|
||||||
/// - **machine** which contains a table of instructions and a pc to the actual instruction
|
/// - **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_reg1 : u64;
|
||||||
let unsigned_reg2 : u64;
|
let unsigned_reg2 : u64;
|
||||||
@ -210,10 +208,11 @@ impl Machine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let val = u32::from_be_bytes(val) as u64;
|
let val = u32::from_be_bytes(val) as u64;
|
||||||
|
let inst : Instruction = decode(val);
|
||||||
Self::print_machine_status(machine);
|
Self::print_machine_status(machine);
|
||||||
println!("executing instruction : {:016x} at pc {:x}", val, machine.pc);
|
println!("executing instruction : {:016x} at pc {:x}", val, machine.pc);
|
||||||
println!("{}", print::print(decode(val), machine.pc as i32));
|
println!("{}", print::print(decode(val), machine.pc as i32));
|
||||||
let inst : Instruction = decode(val);
|
|
||||||
|
|
||||||
|
|
||||||
match inst.opcode {
|
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)},
|
_ => { panic!("{:x} opcode non géré pc : {:x}", inst.opcode, machine.pc)},
|
||||||
}
|
}
|
||||||
|
|
||||||
machine.pc += 4; // Possible bug avec jump
|
machine.pc += 4;
|
||||||
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,6 +194,19 @@ impl Mem_Checker{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn compare_machine_memory(m_c: &Mem_Checker, machine: &Machine) -> bool {
|
||||||
|
|
||||||
|
for section in m_c.sections.iter() {
|
||||||
|
for i in 0..section.len {
|
||||||
|
if machine.main_memory[section.addr + i] != section.content[i] {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user