impl translate
This commit is contained in:
parent
ea309ab124
commit
77f28d029d
@ -15,7 +15,7 @@ pub enum ExceptionType {
|
|||||||
//SYSCALL_EXCEPTION,//A program executed a system call.
|
//SYSCALL_EXCEPTION,//A program executed a system call.
|
||||||
PAGEFAULT_EXCEPTION,//Page fault exception
|
PAGEFAULT_EXCEPTION,//Page fault exception
|
||||||
READONLY_EXCEPTION,//Write attempted to a page marked "read-only" */
|
READONLY_EXCEPTION,//Write attempted to a page marked "read-only" */
|
||||||
//BUSERROR_EXCEPTION,
|
BUSERROR_EXCEPTION,
|
||||||
/* translation resulted
|
/* translation resulted
|
||||||
in an invalid physical
|
in an invalid physical
|
||||||
address (mis-aligned or
|
address (mis-aligned or
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
use crate::simulator::translationtable::*;
|
use crate::simulator::translationtable::*;
|
||||||
use crate::simulator::machine::*;
|
use crate::simulator::machine::*;
|
||||||
|
|
||||||
use super::machine::ExceptionType;
|
|
||||||
|
|
||||||
pub struct MMU <'a>{
|
pub struct MMU <'a>{
|
||||||
/* Un MMU possède une seule référence vers une table des pages à un instant donné
|
/* 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 table est associée au processus courant
|
||||||
@ -20,14 +18,35 @@ impl <'a>MMU <'_>{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn translate(mmu : &mut MMU, virtAddr : u64, physAddr : &mut u64, size : usize, writing : bool) -> ExceptionType {
|
pub fn mmu_read_mem(mmu : &mut MMU, machine : &Machine, virt_addr : u64, value : &mut u64) -> bool {
|
||||||
|
//Pour plus tard eventuellement considerer le boutisme de notre mémoire
|
||||||
|
//Peut etre pas si on fixe cela en BIG ENDIAN (octects poids fort au debut)
|
||||||
|
let mut phy_addr : u64 = 0;
|
||||||
|
let mut phy_addr_double_check : u64 = 0;
|
||||||
|
let exc = MMU::translate(mmu, virt_addr, &mut phy_addr, false);
|
||||||
|
MMU::translate(mmu, virt_addr, &mut phy_addr_double_check, false);
|
||||||
|
|
||||||
|
//PB ICI car double appel a translate et on doit a chaque appel passer mmu en param
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn mmu_write_mem(&mut self, machine : &mut Machine, virt_addr : u64, value : &mut u64) -> bool {
|
||||||
|
//Pour plus tard eventuellement considerer le boutisme de notre mémoire
|
||||||
|
//Peut etre pas si on fixe cela en BIG ENDIAN (octects poids fort au debut)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn translate(mmu : &mut MMU, virtAddr : u64, physAddr : &mut u64, writing : bool) -> ExceptionType {
|
||||||
|
|
||||||
let vpn : u64 = virtAddr/PAGE_SIZE; //virtual page index
|
let vpn : u64 = virtAddr/PAGE_SIZE; //virtual page index
|
||||||
let offset : u64 = virtAddr%PAGE_SIZE; //adresse intra page
|
let offset : u64 = virtAddr%PAGE_SIZE; //adresse intra page
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
match &mmu.translationTable {
|
match &mut mmu.translationTable {
|
||||||
None => {
|
None => {
|
||||||
println!("Error from translate : MMU refers to None (No page Table)");
|
println!("Error from translate : MMU refers to None (No page Table)");
|
||||||
return ExceptionType::ADDRESSERROR_EXCEPTION;
|
return ExceptionType::ADDRESSERROR_EXCEPTION;
|
||||||
@ -67,7 +86,21 @@ impl <'a>MMU <'_>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Make sure that the physical adress is correct
|
//Make sure that the physical adress is correct
|
||||||
let num_phy_page = (MEM_SIZE as u64)/PAGE_SIZE;
|
if table_ref.get_physical_page(vpn) < 0 || table_ref.get_physical_page(vpn) >= (NUM_PHY_PAGE as i32) {
|
||||||
|
println!("Error from translate :: no valid correspondance");
|
||||||
|
return ExceptionType::BUSERROR_EXCEPTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Set U/M bits to 1
|
||||||
|
if writing {
|
||||||
|
table_ref.set_bit_M(vpn);
|
||||||
|
}
|
||||||
|
|
||||||
|
table_ref.set_bit_U(vpn);
|
||||||
|
|
||||||
|
//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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user