From ea309ab1246c68637bc5e9f31955c94ba8e9cb89 Mon Sep 17 00:00:00 2001 From: Moysan Gabriel Date: Tue, 14 Mar 2023 22:55:48 +0100 Subject: [PATCH] =?UTF-8?q?taille=20de=20la=20memoire=20recalcul=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/simulator/machine.rs | 7 +++++-- src/simulator/mmu.rs | 38 ++++++++++++++++++++++++++++++++------ 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/simulator/machine.rs b/src/simulator/machine.rs index 9177d48..447ce1e 100644 --- a/src/simulator/machine.rs +++ b/src/simulator/machine.rs @@ -34,10 +34,13 @@ pub const STACK_REG: usize = 2; pub const NUM_INT_REGS: usize = 32; pub const NUM_FP_REGS: usize = 32; -/// doit disparaitre -const MEM_SIZE : usize = 0x500000; +//max number of physical page +pub const NUM_PHY_PAGE : u64 = 400; //doit etre une puissance de deux pub const PAGE_SIZE : u64 = 128; +//doit etre un multiple de PAGE_SIZE +pub const MEM_SIZE : usize = (PAGE_SIZE*NUM_PHY_PAGE) as usize; + pub trait RegisterNum: Add + Sub + PartialEq + Copy {} diff --git a/src/simulator/mmu.rs b/src/simulator/mmu.rs index 5ad8d36..40ee0b1 100644 --- a/src/simulator/mmu.rs +++ b/src/simulator/mmu.rs @@ -22,8 +22,8 @@ impl <'a>MMU <'_>{ fn translate(mmu : &mut MMU, virtAddr : u64, physAddr : &mut u64, size : usize, writing : bool) -> ExceptionType { - let virtual_page_index : u64 = virtAddr/PAGE_SIZE; - let offset : u64 = virtAddr%PAGE_SIZE; + let vpn : u64 = virtAddr/PAGE_SIZE; //virtual page index + let offset : u64 = virtAddr%PAGE_SIZE; //adresse intra page @@ -36,12 +36,38 @@ impl <'a>MMU <'_>{ Some(table_ref) => { //On verifie que notre index est valide - if virtual_page_index >= table_ref.get_max_num_pages(){ - + if vpn >= table_ref.get_max_num_pages(){ + println!("Error from translate :: index is out of bound"); + return ExceptionType::ADDRESSERROR_EXCEPTION; } - //is the page correctyl mapped ? - //if table_ref.pageTable.get + /*Doc nachos dit que ce test sert a savoir si la page est mappée + *On teste les droit de lecture ecriture sur cette page + *A confirmer avc isabelle + */ + if !table_ref.get_bit_read(vpn) && !table_ref.get_bit_write(vpn) { + println!("Error from translate :: virtual page # {} not mapped",vpn); + return ExceptionType::ADDRESSERROR_EXCEPTION; + } + + //si on souhaite effectuer un acces lecture, on verifie que l'on dispose du droit d'acces sur cette page + if writing && !table_ref.get_bit_write(vpn) { + println!("Error from translate :: write access on a read only virtual page # {}",vpn); + return ExceptionType::READONLY_EXCEPTION; + } + + //if the page is not yet in main memory, run the page fault manager + //Page manager not implemented yet + if !table_ref.get_bit_valid(vpn){ + println!("Error from translate :: no valid correspondance"); + println!("We need to update the page table by raising an exception -> not implemented"); + + //Ici il faudra reverifier le bit valid apres intervention du page fault manager + return ExceptionType::ADDRESSERROR_EXCEPTION; + } + + //Make sure that the physical adress is correct + let num_phy_page = (MEM_SIZE as u64)/PAGE_SIZE; } }