BurritOS now read configuration file

This commit is contained in:
François Autin
2023-04-19 18:09:08 +02:00
parent 1c4c51b0ba
commit 73ac8d3083
9 changed files with 57 additions and 42 deletions

View File

@ -584,12 +584,12 @@ fn get_address_point(instructions: &[u8], address: usize, is_32bits: bool) -> Op
/// It may not pass in the future if future gcc version modify order of the binary or something else
#[cfg(test)]
mod test {
use crate::simulator::{loader::{Loader, SectionHeader}, machine::Machine};
use crate::{simulator::{loader::{Loader, SectionHeader}, machine::Machine}, utility::cfg::get_debug_configuration};
#[test]
fn test_parse_elf() {
let mut machine = Machine::new(true);
let mut machine = Machine::new(true, get_debug_configuration());
let loader = Loader::load_and_parse("./target/guac/unsigned_addition.guac").expect("IO Error");
loader.load_into_machine(&mut machine, 0).expect("Parsing error");
assert!(!loader.elf_header.is_32bits);
@ -610,7 +610,7 @@ mod test {
#[test]
fn test_parse_section() {
let mut machine = Machine::new(true);
let mut machine = Machine::new(true, get_debug_configuration());
let loader = Loader::load_and_parse("./target/guac/unsigned_addition.guac").expect("IO Error");
loader.load_into_machine(&mut machine, 0).expect("Parsing error");
assert_eq!(9, loader.sections.len());

View File

@ -21,7 +21,7 @@ use crate::{simulator::{
interrupt::Interrupt,
global::*,
register::*
}, kernel::system::System};
}, kernel::system::System, utility::cfg::{Settings, MachineSettingKey}};
use crate::kernel::{
exception
@ -71,12 +71,6 @@ pub const STACK_REG: usize = 2;
pub const NUM_INT_REGS: usize = 32;
/// Number of available Floating Point registers
pub const NUM_FP_REGS: usize = 32;
/// max number of physical pages
pub const NUM_PHY_PAGE : u64 = 400;
/// Must be 2^x
pub const PAGE_SIZE : u64 = 128;
/// Must be a multiple of PAGE_SIZE
pub const MEM_SIZE : usize = (PAGE_SIZE*NUM_PHY_PAGE*100_000) as usize;
/// RISC-V Simulator
pub struct Machine {
@ -100,7 +94,8 @@ pub struct Machine {
pub interrupt: Interrupt,
// 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
num_phy_page: u64,
page_size: u64,
/// Current machine status
pub status: MachineStatus
}
@ -109,27 +104,32 @@ pub struct Machine {
impl Machine {
/// Machine constructor
pub fn new(debug: bool) -> Self {
pub fn new(debug: bool, settings: Settings) -> Self {
let mut shiftmask : [u64 ; 64] = [0 ; 64];
let mut value : u64 = 0xffffffff;
value = (value << 32) + value;
for item in &mut shiftmask {
*item = value;
value >>= 1;
}
let num_phy_page = *settings.get(&MachineSettingKey::NumPhysPages).unwrap();
let page_size = *settings.get(&MachineSettingKey::PageSize).unwrap();
let mem_size = (page_size*num_phy_page*100_000) as usize;
Machine {
debug,
pc : 0,
sp: 0,
int_reg : { let mut r = Register::<i64>::init(); r.set_reg(10, -1); r },
fp_reg : Register::<f32>::init(),
main_memory : vec![0_u8; MEM_SIZE],
main_memory : vec![0_u8; mem_size],
shiftmask,
interrupt: Interrupt::new(),
registers_trace : String::from(""),
status: MachineStatus::SystemMode
status: MachineStatus::SystemMode,
num_phy_page,
page_size
}
}
@ -707,6 +707,7 @@ mod test {
use std::fs;
use crate::simulator::{machine::Machine, mem_cmp};
use crate::utility::cfg::get_debug_configuration;
macro_rules! get_full_path {
($prefix: expr, $test_name:expr) => {{
@ -720,7 +721,7 @@ mod test {
macro_rules! init_test {
($a:expr) => {{
let mut m = Machine::new(true);
let mut m = Machine::new(true, get_debug_configuration());
let end_file_name = { let mut s = String::from($a); s.push_str("End"); s };
let memory_before = mem_cmp::MemChecker::from(get_full_path!("memory", $a)).unwrap();
let memory_after = mem_cmp::MemChecker::from(get_full_path!("memory", &end_file_name)).unwrap();
@ -735,12 +736,12 @@ mod test {
#[test]
fn test_init_machine() {
let _ = Machine::new(true);
let _ = Machine::new(true, get_debug_configuration());
}
#[test]
fn test_read_memory() {
let mut m = Machine::new(true);
let mut m = Machine::new(true, get_debug_configuration());
m.main_memory[4] = 43;
m.main_memory[5] = 150;
assert_eq!((43 << 8) + 150, m.read_memory(2, 4));
@ -748,7 +749,7 @@ mod test {
#[test]
fn test_write_memory() {
let mut m = Machine::new(true);
let mut m = Machine::new(true, get_debug_configuration());
m.write_memory(2, 6, (43 << 8) + 150);
assert_eq!(43, m.main_memory[6]);
assert_eq!(150, m.main_memory[7]);

View File

@ -206,12 +206,14 @@ impl MemChecker{
#[cfg(test)]
mod tests {
use crate::utility::cfg::get_debug_configuration;
use super::*;
#[test]
fn test_fill_memory(){
let m_c = MemChecker::from("test/machine/memoryAdd.txt").unwrap();
let mut machine = Machine::new(true);
let mut machine = Machine::new(true, get_debug_configuration());
MemChecker::fill_memory_from_mem_checker(&m_c, &mut machine);
MemChecker::compare_print_m_c_machine(&m_c, &mut machine);
}

View File

@ -6,15 +6,18 @@ pub struct MMU <'a>{
* Cette table est associée au processus courant
* Cette référence peut etre mise a jour par exemple lors d'un switchTo
*/
translationTable : Option<&'a mut TranslationTable>
translationTable : Option<&'a mut TranslationTable>,
numPhyPages : u64,
pageSize : u64
}
impl <'a>MMU <'_>{
fn create() -> MMU <'a>{
MMU{
translationTable : None
fn create(numPhyPages: u64, pageSize: u64) -> MMU <'a>{
MMU {
translationTable : None,
numPhyPages,
pageSize
}
}
@ -88,8 +91,8 @@ impl <'a>MMU <'_>{
pub fn translate(mmu : &mut MMU, virtAddr : u64, physAddr : &mut u64, writing : bool) -> ExceptionType {
let vpn : u64 = virtAddr/PAGE_SIZE; //virtual page index
let offset : u64 = virtAddr%PAGE_SIZE; //adresse intra page
let vpn : u64 = virtAddr/(mmu.pageSize); //virtual page index
let offset : u64 = virtAddr%(mmu.pageSize); //adresse intra page
@ -133,7 +136,7 @@ impl <'a>MMU <'_>{
}
//Make sure that the physical adress is correct
if table_ref.get_physical_page(vpn) < 0 || table_ref.get_physical_page(vpn) >= (NUM_PHY_PAGE as i32) {
if table_ref.get_physical_page(vpn) < 0 || table_ref.get_physical_page(vpn) >= (mmu.numPhyPages as i32) {
println!("Error from translate :: no valid correspondance");
return ExceptionType::BusErrorException;
}
@ -147,7 +150,7 @@ impl <'a>MMU <'_>{
//on se permet ici la conversion du champs physical_page de i32 vers u64
//si cette valeur avait été signée, cela aurait été detecté juste au dessus, renvoyant une BUSERROR_EXCEPTION
*physAddr = (table_ref.get_physical_page(vpn) as u64)*PAGE_SIZE + offset;
*physAddr = (table_ref.get_physical_page(vpn) as u64)*(mmu.pageSize) + offset;
}
}