Merge conflicts
This commit is contained in:
commit
0530d980be
20
src/main.rs
20
src/main.rs
@ -1,21 +1,13 @@
|
|||||||
mod simulator;
|
mod simulator;
|
||||||
|
|
||||||
use simulator::machine::Machine;
|
use simulator::machine::Machine;
|
||||||
use simulator::loader;
|
use simulator::mem_cmp;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let mut m = Machine::_init_machine();
|
||||||
let mut m = loader::load("test_programs/riscv_instructions/simple_arithmerics/unsigned_addition.hex", 4);
|
let path = "test_file_section.txt".to_string();
|
||||||
|
let checker = mem_cmp::Mem_Checker::from(&path);
|
||||||
|
mem_cmp::Mem_Checker::fill_memory_from_Mem_Checker(&checker, &mut m);
|
||||||
Machine::run(m);
|
Machine::run(m);
|
||||||
|
mem_cmp::Mem_Checker::print_Mem_Checker(&checker);
|
||||||
/*let mut m = Machine::_init_machine();
|
|
||||||
m.main_memory[4] = 43;
|
|
||||||
m.main_memory[5] = 150;
|
|
||||||
let a : u8 = 128;
|
|
||||||
let b : i8 = a as i8;
|
|
||||||
let c : u8 = b as u8;
|
|
||||||
println!("aaa {c}");
|
|
||||||
println!("read_memory : {}", Machine::read_memory(&mut m, 2, 4));*/
|
|
||||||
|
|
||||||
}
|
}
|
@ -155,7 +155,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;
|
||||||
loop{
|
for i in 0..MEM_SIZE{
|
||||||
Machine::one_instruction(&mut m);
|
Machine::one_instruction(&mut m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::BufRead;
|
use std::io::BufRead;
|
||||||
|
use std::io::BufReader;
|
||||||
|
use std::io::Lines;
|
||||||
use crate::Machine;
|
use crate::Machine;
|
||||||
|
|
||||||
const MEM_SIZE : usize = 4096;
|
const MEM_SIZE : usize = 4096;
|
||||||
@ -30,14 +32,14 @@ const MEM_SIZE : usize = 4096;
|
|||||||
//content est une suite hexadécimale
|
//content est une suite hexadécimale
|
||||||
|
|
||||||
//Section dans le fichier, champ String car informations proviennent d'un fichier txt
|
//Section dans le fichier, champ String car informations proviennent d'un fichier txt
|
||||||
struct SectionFormat{
|
pub struct SectionFormat{
|
||||||
addr: String,
|
addr: String,
|
||||||
len: String,
|
len: String,
|
||||||
content: String,
|
content: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
//Section dans le programme
|
//Section dans le programme
|
||||||
struct Section{
|
pub struct Section{
|
||||||
addr: usize, // adresse dans la mémoire
|
addr: usize, // adresse dans la mémoire
|
||||||
len: usize, // nombre d'octets de la donnée à addr
|
len: usize, // nombre d'octets de la donnée à addr
|
||||||
content: Vec<u8>, // la donnée en question
|
content: Vec<u8>, // la donnée en question
|
||||||
@ -91,34 +93,36 @@ pub struct Mem_Checker{
|
|||||||
|
|
||||||
impl Mem_Checker{
|
impl Mem_Checker{
|
||||||
|
|
||||||
|
fn vect_from_lines(lines: &mut Lines<BufReader<fs::File>>, pc: &mut usize, sp: &mut usize) -> Vec<String>{
|
||||||
|
let mut vector = Vec::new();
|
||||||
|
for (i,line) in lines.enumerate() {
|
||||||
|
vector.push(line.unwrap());
|
||||||
|
}
|
||||||
|
let size = vector.len();
|
||||||
|
*pc = string_hex_to_usize(vector.get(size - 2).expect("0"));
|
||||||
|
*sp = string_hex_to_usize(vector.get(size - 1).expect("0"));
|
||||||
|
vector
|
||||||
|
}
|
||||||
|
|
||||||
pub fn from(path: &String) -> 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("test_file_section.txt").expect("Wrong filename");
|
||||||
let reader = io::BufReader::new(&file);
|
|
||||||
let reader2 = io::BufReader::new(&file);
|
let reader = io::BufReader::new(file);
|
||||||
let lines = reader.lines();
|
let mut lines = reader.lines();
|
||||||
let length = reader2.lines().count();
|
|
||||||
|
|
||||||
let mut pc: usize = 0;
|
let mut pc: usize = 0;
|
||||||
let mut sp: usize = 0;
|
let mut sp: usize = 0;
|
||||||
let mut sections: Vec<Section> = Vec::new();
|
let vector = Mem_Checker::vect_from_lines(&mut lines, &mut pc, &mut sp);
|
||||||
|
|
||||||
|
let mut sections: Vec<Section> = Vec::new();
|
||||||
let mut tmp_addr_str: String = String::new();
|
let mut tmp_addr_str: String = String::new();
|
||||||
let mut tmp_len_str: String = String::new();
|
let mut tmp_len_str: String = String::new();
|
||||||
|
|
||||||
for (i,line) in lines.enumerate() {
|
let default = String::new();
|
||||||
|
for i in 0..vector.len()-2 {
|
||||||
|
let current_line = vector.get(i).unwrap_or(&default);
|
||||||
|
|
||||||
let current_line = line.unwrap();
|
|
||||||
|
|
||||||
if i == length-2 {
|
|
||||||
//Lecture de PC
|
|
||||||
pc = string_hex_to_usize(¤t_line);
|
|
||||||
}
|
|
||||||
else if i == length-1 {
|
|
||||||
//Lecture SP
|
|
||||||
sp = string_hex_to_usize(¤t_line);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//Lecture des sections
|
//Lecture des sections
|
||||||
if current_line.contains(' ') {
|
if current_line.contains(' ') {
|
||||||
//lecture ligne ADDR LEN
|
//lecture ligne ADDR LEN
|
||||||
@ -131,19 +135,18 @@ impl Mem_Checker{
|
|||||||
let section_f = SectionFormat{
|
let section_f = SectionFormat{
|
||||||
addr: tmp_addr_str.clone(),
|
addr: tmp_addr_str.clone(),
|
||||||
len: tmp_len_str.clone(),
|
len: tmp_len_str.clone(),
|
||||||
content: current_line,
|
content: current_line.clone(),
|
||||||
};
|
};
|
||||||
sections.push(Section::from(§ion_f));
|
sections.push(Section::from(§ion_f));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Mem_Checker{pc:pc, sp:sp, sections:sections}
|
Mem_Checker{pc:pc, sp:sp, sections:sections}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn print_Mem_Checker(m_c: &Mem_Checker){
|
pub fn print_Mem_Checker(m_c: &Mem_Checker){
|
||||||
println!("PC :: {}", m_c.pc);
|
println!("PC :: {}", m_c.pc);
|
||||||
println!("SP :: {}", m_c.sp);
|
println!("SP :: {}", m_c.sp);
|
||||||
|
|
||||||
@ -195,7 +198,11 @@ impl Mem_Checker{
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn string_hex_to_usize(s: &String) -> usize{
|
fn string_hex_to_usize(s: &String) -> usize {
|
||||||
|
|
||||||
|
if s.len() == 0 {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
let max_pow = (s.len()-1) as u32;
|
let max_pow = (s.len()-1) as u32;
|
||||||
let mut ret_value: usize = 0;
|
let mut ret_value: usize = 0;
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
addi sp,sp,-32
|
fe010113
|
||||||
sd s0,24(sp)
|
00813c23
|
||||||
addi s0,sp,32
|
02010413
|
||||||
sw zero,-20(s0)
|
fe042623
|
||||||
li a5,1
|
00100793
|
||||||
sw a5,-24(s0)
|
fef42423
|
||||||
lw a5,-20(s0)
|
fec42783
|
||||||
mv a4,a5
|
00078713
|
||||||
lw a5,-24(s0)
|
fe842783
|
||||||
addw a5,a4,a5
|
00f707bb
|
||||||
sw a5,-20(s0)
|
fef42623
|
||||||
nop
|
00000013
|
||||||
ld s0,24(sp)
|
01813403
|
||||||
addi sp,sp,32
|
02010113
|
||||||
ret
|
00008067
|
||||||
|
0
|
||||||
|
0
|
Loading…
Reference in New Issue
Block a user