memory context load
This commit is contained in:
parent
8b84dee271
commit
297a4d1d0a
@ -1,6 +1,7 @@
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::io::BufRead;
|
||||
use crate::Machine;
|
||||
|
||||
const MEM_SIZE : usize = 4096;
|
||||
|
||||
@ -156,35 +157,43 @@ impl Mem_Checker{
|
||||
|
||||
}
|
||||
|
||||
fn Mem_Checker_check(m_c: &Mem_Checker, memory: [u8 ; MEM_SIZE]){
|
||||
/*
|
||||
* Check pc, sp
|
||||
*/
|
||||
fn fill_memory_from_Mem_Checker(m_c: &Mem_Checker, machine: &mut Machine){
|
||||
|
||||
machine.sp = m_c.sp;
|
||||
machine.pc = m_c.pc as u64;
|
||||
|
||||
|
||||
/*
|
||||
* Check sections
|
||||
*/
|
||||
for section in m_c.sections.iter() {
|
||||
|
||||
for(i, s) in m_c.sections.iter().enumerate() {
|
||||
let addr = s.addr;
|
||||
let len = s.len;
|
||||
let segment = &s.content;
|
||||
|
||||
/*
|
||||
regarder dans mem[addr]
|
||||
a cette adresse verifier len octets
|
||||
*/
|
||||
|
||||
for j in 0..(len-1){
|
||||
if segment[j] != memory[addr + j] {
|
||||
println!("missmatch");
|
||||
}
|
||||
for (i,b) in section.content.iter().enumerate() {
|
||||
machine.main_memory[section.addr + i] = *b;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* FOR DEBUG
|
||||
*/
|
||||
fn compare_print_m_c_machine(m_c: &Mem_Checker, machine: &mut Machine){
|
||||
|
||||
Mem_Checker::print_Mem_Checker(m_c);
|
||||
|
||||
for section in m_c.sections.iter() {
|
||||
|
||||
print!("\n\n");
|
||||
|
||||
println!("Content addr : {}", section.addr);
|
||||
println!("Content len (number of bytes) : {}", section.len);
|
||||
|
||||
for i in 0..section.len {
|
||||
println!("mem[{}] = {}", section.addr + i, machine.main_memory[section.addr + i]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -261,7 +270,31 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_create_Mem_Chercker(){
|
||||
fn test_fill_memory(){
|
||||
let path = "osef".to_string();
|
||||
let m_c = Mem_Checker::from(&path);
|
||||
let mut machine = Machine::_init_machine();
|
||||
|
||||
Mem_Checker::fill_memory_from_Mem_Checker(&m_c, &mut machine);
|
||||
|
||||
print!("\n Comparing memory from loaded context\n\n");
|
||||
|
||||
Mem_Checker::compare_print_m_c_machine(&m_c, &mut machine);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_enum_start_at_zero(){
|
||||
let v = vec![1,2,3];
|
||||
|
||||
for (i,val) in v.iter().enumerate() {
|
||||
println!("i = {} :: v[i] = {}", i, val);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_create_Mem_Checker(){
|
||||
let path: String = "osef".to_string();
|
||||
let m_c = Mem_Checker::from(&path);
|
||||
Mem_Checker::print_Mem_Checker(&m_c);
|
||||
|
Loading…
Reference in New Issue
Block a user