change memory to a vector, it can now be fill
This commit is contained in:
parent
e82af4ae67
commit
5a90419ebb
11
src/main.rs
11
src/main.rs
@ -1,11 +1,14 @@
|
||||
mod simulator;
|
||||
|
||||
use simulator::machine::Machine;
|
||||
use simulator::{mem_cmp, loader};
|
||||
use simulator::mem_cmp;
|
||||
|
||||
fn main() {
|
||||
let path = "test_file_section.txt".to_string();
|
||||
let mut m = loader::load(&path, 4);
|
||||
Machine::print_memory(&mut m);
|
||||
let mut m = Machine::_init_machine();
|
||||
let path = "memory.txt".to_string();
|
||||
let checker = mem_cmp::Mem_Checker::from(&path);
|
||||
mem_cmp::Mem_Checker::fill_memory_from_Mem_Checker(&checker, &mut m);
|
||||
mem_cmp::Mem_Checker::print_Mem_Checker(&checker);
|
||||
Machine::print_memory(&mut m, 0x400000, 0x405000);
|
||||
Machine::run(m);
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ use super::global::*;
|
||||
use std::fs::File;
|
||||
|
||||
/// doit disparaitre
|
||||
const MEM_SIZE : usize = 4096;
|
||||
const MEM_SIZE : usize = 0x500000;
|
||||
|
||||
pub trait RegisterNum: Add<Output=Self> + Sub<Output=Self> + PartialEq + Copy {}
|
||||
|
||||
@ -65,7 +65,7 @@ pub struct Machine {
|
||||
pub sp: usize,
|
||||
pub int_reg : Register<i64>,
|
||||
pub fp_reg : Register<f32>,
|
||||
pub main_memory : [u8 ; MEM_SIZE],
|
||||
pub main_memory : Vec<u8>,
|
||||
pub shiftmask : [u64 ; 64]
|
||||
// futur taille à calculer int memSize = g_cfg->NumPhysPages * g_cfg->PageSize;
|
||||
//creer une struct cfg(configuration) qui s'initialise avec valeur dans un fichier cfg
|
||||
@ -89,7 +89,7 @@ impl Machine {
|
||||
sp: 0,
|
||||
int_reg : Register::<i64>::init(),
|
||||
fp_reg : Register::<f32>::init(),
|
||||
main_memory : [0 ; MEM_SIZE],
|
||||
main_memory : vec![0; MEM_SIZE],
|
||||
shiftmask
|
||||
}
|
||||
|
||||
@ -180,17 +180,16 @@ impl Machine {
|
||||
uint64_t value;*/
|
||||
|
||||
if machine.main_memory.len() <= machine.pc as usize {
|
||||
println!("ERROR : number max of instructions rushed");
|
||||
return ;
|
||||
panic!("ERROR : number max of instructions rushed");
|
||||
}
|
||||
let mut val: [u8; 4] = [0; 4];
|
||||
for i in 0..4 {
|
||||
let mut val: [u8; 8] = [0; 8];
|
||||
for i in 0..8 {
|
||||
val[i] = machine.main_memory[machine.pc as usize + i];
|
||||
}
|
||||
|
||||
let val = u32::from_be_bytes(val);
|
||||
let val = u64::from_be_bytes(val);
|
||||
println!("{:x}", val);
|
||||
let inst : Instruction = decode(val as u64);
|
||||
let inst : Instruction = decode(val);
|
||||
|
||||
|
||||
match inst.opcode {
|
||||
@ -610,8 +609,11 @@ impl Machine {
|
||||
|
||||
}
|
||||
|
||||
pub fn print_memory(machine : &mut Machine) {
|
||||
for i in 0..MEM_SIZE {
|
||||
/// print memory FOR DEBUG
|
||||
///
|
||||
/// "@"adresse [16 bytes]
|
||||
pub fn print_memory(machine : &mut Machine, from: usize, to: usize) {
|
||||
for i in from..to {
|
||||
if i%16 == 0 {
|
||||
print!("\n@{:04x} ", i);
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ impl Mem_Checker{
|
||||
|
||||
pub fn from(path: &String) -> Mem_Checker {
|
||||
|
||||
let file = fs::File::open("test_file_section.txt").expect("Wrong filename");
|
||||
let file = fs::File::open(path).expect("Wrong filename");
|
||||
|
||||
let reader = io::BufReader::new(file);
|
||||
let mut lines = reader.lines();
|
||||
@ -124,7 +124,7 @@ impl Mem_Checker{
|
||||
let current_line = vector.get(i).unwrap_or(&default);
|
||||
|
||||
//Lecture des sections
|
||||
if current_line.contains(' ') {
|
||||
if i % 2 == 0 {
|
||||
//lecture ligne ADDR LEN
|
||||
let next_word_index = current_line.find(' ').unwrap();
|
||||
tmp_addr_str = String::from(¤t_line[0..next_word_index]);
|
||||
@ -135,7 +135,7 @@ impl Mem_Checker{
|
||||
let section_f = SectionFormat{
|
||||
addr: tmp_addr_str.clone(),
|
||||
len: tmp_len_str.clone(),
|
||||
content: current_line.clone(),
|
||||
content: current_line.clone().replace(" ", ""),
|
||||
};
|
||||
sections.push(Section::from(§ion_f));
|
||||
}
|
||||
@ -147,8 +147,8 @@ impl Mem_Checker{
|
||||
|
||||
|
||||
pub fn print_Mem_Checker(m_c: &Mem_Checker){
|
||||
println!("PC :: {}", m_c.pc);
|
||||
println!("SP :: {}", m_c.sp);
|
||||
println!("PC :: {:x}", m_c.pc);
|
||||
println!("SP :: {:x}", m_c.sp);
|
||||
|
||||
for(i,s) in m_c.sections.iter().enumerate() {
|
||||
println!("\nSection {}\n", i);
|
||||
|
@ -1,17 +1,2 @@
|
||||
fe010113
|
||||
00813c23
|
||||
02010413
|
||||
fe042623
|
||||
00100793
|
||||
fef42423
|
||||
fec42783
|
||||
00078713
|
||||
fe842783
|
||||
00f707bb
|
||||
fef42623
|
||||
00000013
|
||||
01813403
|
||||
02010113
|
||||
00008067
|
||||
0
|
||||
0
|
||||
130101FE233C8100
|
||||
13040102232604FE
|
||||
|
Loading…
Reference in New Issue
Block a user