BurritOS now read configuration file
This commit is contained in:
@ -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]);
|
||||
|
Reference in New Issue
Block a user