50 lines
1.4 KiB
Rust
Raw Normal View History

use crate::simulator::translationtable::*;
use crate::simulator::machine::*;
use super::machine::ExceptionType;
pub struct MMU <'a>{
/* Un MMU possède une seule référence vers une table des pages à un instant donné
* 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>
}
impl <'a>MMU <'_>{
fn create() -> MMU <'a>{
MMU{
translationTable : None
}
}
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;
match &mmu.translationTable {
None => {
println!("Error from translate : MMU refers to None (No page Table)");
return ExceptionType::ADDRESSERROR_EXCEPTION;
}
Some(table_ref) => {
//On verifie que notre index est valide
if virtual_page_index >= table_ref.get_max_num_pages(){
}
//is the page correctyl mapped ?
//if table_ref.pageTable.get
}
}
ExceptionType::NO_EXCEPTION
}
}