Merge conflicts
This commit is contained in:
commit
0530d980be
20
src/main.rs
20
src/main.rs
@ -1,21 +1,13 @@
|
||||
mod simulator;
|
||||
|
||||
use simulator::machine::Machine;
|
||||
use simulator::loader;
|
||||
use simulator::mem_cmp;
|
||||
|
||||
fn main() {
|
||||
|
||||
let mut m = loader::load("test_programs/riscv_instructions/simple_arithmerics/unsigned_addition.hex", 4);
|
||||
|
||||
let mut m = Machine::_init_machine();
|
||||
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);
|
||||
|
||||
/*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));*/
|
||||
|
||||
mem_cmp::Mem_Checker::print_Mem_Checker(&checker);
|
||||
}
|
@ -155,7 +155,7 @@ impl Machine {
|
||||
/// - **machine** which contains a table of instructions
|
||||
pub fn run(machine : Machine){
|
||||
let mut m = machine;
|
||||
loop{
|
||||
for i in 0..MEM_SIZE{
|
||||
Machine::one_instruction(&mut m);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::io::BufRead;
|
||||
use std::io::BufReader;
|
||||
use std::io::Lines;
|
||||
use crate::Machine;
|
||||
|
||||
const MEM_SIZE : usize = 4096;
|
||||
@ -30,14 +32,14 @@ const MEM_SIZE : usize = 4096;
|
||||
//content est une suite hexadécimale
|
||||
|
||||
//Section dans le fichier, champ String car informations proviennent d'un fichier txt
|
||||
struct SectionFormat{
|
||||
pub struct SectionFormat{
|
||||
addr: String,
|
||||
len: String,
|
||||
content: String,
|
||||
}
|
||||
|
||||
//Section dans le programme
|
||||
struct Section{
|
||||
pub struct Section{
|
||||
addr: usize, // adresse dans la mémoire
|
||||
len: usize, // nombre d'octets de la donnée à addr
|
||||
content: Vec<u8>, // la donnée en question
|
||||
@ -91,34 +93,36 @@ pub struct 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 {
|
||||
|
||||
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 lines = reader.lines();
|
||||
let length = reader2.lines().count();
|
||||
|
||||
let reader = io::BufReader::new(file);
|
||||
let mut lines = reader.lines();
|
||||
|
||||
let mut pc: 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_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
|
||||
if current_line.contains(' ') {
|
||||
//lecture ligne ADDR LEN
|
||||
@ -131,19 +135,18 @@ impl Mem_Checker{
|
||||
let section_f = SectionFormat{
|
||||
addr: tmp_addr_str.clone(),
|
||||
len: tmp_len_str.clone(),
|
||||
content: current_line,
|
||||
content: current_line.clone(),
|
||||
};
|
||||
sections.push(Section::from(§ion_f));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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!("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 mut ret_value: usize = 0;
|
||||
|
@ -1,15 +1,17 @@
|
||||
addi sp,sp,-32
|
||||
sd s0,24(sp)
|
||||
addi s0,sp,32
|
||||
sw zero,-20(s0)
|
||||
li a5,1
|
||||
sw a5,-24(s0)
|
||||
lw a5,-20(s0)
|
||||
mv a4,a5
|
||||
lw a5,-24(s0)
|
||||
addw a5,a4,a5
|
||||
sw a5,-20(s0)
|
||||
nop
|
||||
ld s0,24(sp)
|
||||
addi sp,sp,32
|
||||
ret
|
||||
fe010113
|
||||
00813c23
|
||||
02010413
|
||||
fe042623
|
||||
00100793
|
||||
fef42423
|
||||
fec42783
|
||||
00078713
|
||||
fe842783
|
||||
00f707bb
|
||||
fef42623
|
||||
00000013
|
||||
01813403
|
||||
02010113
|
||||
00008067
|
||||
0
|
||||
0
|
Loading…
Reference in New Issue
Block a user