taille de la memoire recalculée

This commit is contained in:
Moysan Gabriel 2023-03-14 22:55:48 +01:00
parent 88a0b31300
commit ea309ab124
2 changed files with 37 additions and 8 deletions

View File

@ -34,10 +34,13 @@ pub const STACK_REG: usize = 2;
pub const NUM_INT_REGS: usize = 32; pub const NUM_INT_REGS: usize = 32;
pub const NUM_FP_REGS: usize = 32; pub const NUM_FP_REGS: usize = 32;
/// doit disparaitre //max number of physical page
const MEM_SIZE : usize = 0x500000; pub const NUM_PHY_PAGE : u64 = 400;
//doit etre une puissance de deux //doit etre une puissance de deux
pub const PAGE_SIZE : u64 = 128; 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<Output=Self> + Sub<Output=Self> + PartialEq + Copy {} pub trait RegisterNum: Add<Output=Self> + Sub<Output=Self> + PartialEq + Copy {}

View File

@ -22,8 +22,8 @@ impl <'a>MMU <'_>{
fn translate(mmu : &mut MMU, virtAddr : u64, physAddr : &mut u64, size : usize, writing : bool) -> ExceptionType { fn translate(mmu : &mut MMU, virtAddr : u64, physAddr : &mut u64, size : usize, writing : bool) -> ExceptionType {
let virtual_page_index : u64 = virtAddr/PAGE_SIZE; let vpn : u64 = virtAddr/PAGE_SIZE; //virtual page index
let offset : u64 = virtAddr%PAGE_SIZE; let offset : u64 = virtAddr%PAGE_SIZE; //adresse intra page
@ -36,12 +36,38 @@ impl <'a>MMU <'_>{
Some(table_ref) => { Some(table_ref) => {
//On verifie que notre index est valide //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 ? /*Doc nachos dit que ce test sert a savoir si la page est mappée
//if table_ref.pageTable.get *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;
} }
} }