From 21159d3d98f58dcaaea54c9252508aaaa09d0934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Autin?= Date: Thu, 23 Mar 2023 20:54:05 +0100 Subject: [PATCH] Renamed exceptions to follow CamlCase convention --- src/simulator/machine.rs | 20 +++++++++----------- src/simulator/mmu.rs | 22 +++++++++++----------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/simulator/machine.rs b/src/simulator/machine.rs index b785d6b..d90c950 100644 --- a/src/simulator/machine.rs +++ b/src/simulator/machine.rs @@ -11,16 +11,17 @@ use std::fs::File; * Decommenter la variant si il est utilisé quelque part */ pub enum ExceptionType { - NO_EXCEPTION,//Everything ok! + //Everything ok! + NoException, //SYSCALL_EXCEPTION,//A program executed a system call. - PAGEFAULT_EXCEPTION,//Page fault exception - READONLY_EXCEPTION,//Write attempted to a page marked "read-only" */ - BUSERROR_EXCEPTION, + PagefaultException,//Page fault exception + ReadOnlyException,//Write attempted to a page marked "read-only" */ + BusErrorException, /* translation resulted in an invalid physical address (mis-aligned or out-of-bounds) */ - ADDRESSERROR_EXCEPTION, /* Reference that was + AddressErrorException, /* Reference that was not mapped in the address space */ //OVERFLOW_EXCEPTION, //Integer overflow in add or sub. @@ -30,18 +31,15 @@ pub enum ExceptionType { pub const STACK_REG: usize = 2; - pub const NUM_INT_REGS: usize = 32; pub const NUM_FP_REGS: usize = 32; - -//max number of physical page +/// max number of physical pages pub const NUM_PHY_PAGE : u64 = 400; -//doit etre une puissance de deux +/// Must be 2^x pub const PAGE_SIZE : u64 = 128; -//doit etre un multiple de PAGE_SIZE +/// Must be a multiple of PAGE_SIZE pub const MEM_SIZE : usize = (PAGE_SIZE*NUM_PHY_PAGE*100) as usize; - pub trait RegisterNum: Add + Sub + PartialEq + Copy {} impl RegisterNum for i64 {} diff --git a/src/simulator/mmu.rs b/src/simulator/mmu.rs index 780e49f..f91dcb0 100644 --- a/src/simulator/mmu.rs +++ b/src/simulator/mmu.rs @@ -29,7 +29,7 @@ impl <'a>MMU <'_>{ MMU::translate(mmu, virt_addr, &mut phy_addr_double_check, false); match exc { - ExceptionType::NO_EXCEPTION => { + ExceptionType::NoException => { if phy_addr != phy_addr_double_check { //Besoin ici d'une impl pour gestion d'exeption //dans nachos : g-machine->RaiseException(exc, virt_addr); @@ -44,7 +44,7 @@ impl <'a>MMU <'_>{ _ => { //Besoin ici d'une impl pour gestion d'exeption //dans nachos : g-machine->RaiseException(exc, virt_addr); - println!("Error from mmu_read_mem :: Exception different from NO_EXCEPTION"); + println!("Error from mmu_read_mem :: Exception different from NoException"); return false; } } @@ -63,7 +63,7 @@ impl <'a>MMU <'_>{ MMU::translate(mmu, virt_addr, &mut phy_addr_double_check, true); match exc { - ExceptionType::NO_EXCEPTION => { + ExceptionType::NoException => { if phy_addr != phy_addr_double_check { //Besoin ici d'une impl pour gestion d'exeption //dans nachos : g-machine->RaiseException(exc, virt_addr); @@ -78,7 +78,7 @@ impl <'a>MMU <'_>{ _ => { //Besoin ici d'une impl pour gestion d'exeption //dans nachos : g-machine->RaiseException(exc, virt_addr); - println!("Error from mmu_write_mem :: Exception different from NO_EXCEPTION"); + println!("Error from mmu_write_mem :: Exception different from NoException"); return false; } } @@ -96,7 +96,7 @@ impl <'a>MMU <'_>{ match &mut mmu.translationTable { None => { println!("Error from translate : MMU refers to None (No page Table)"); - return ExceptionType::ADDRESSERROR_EXCEPTION; + return ExceptionType::AddressErrorException; } Some(table_ref) => { @@ -104,7 +104,7 @@ impl <'a>MMU <'_>{ //On verifie que notre index est valide if vpn >= table_ref.get_max_num_pages(){ println!("Error from translate :: index is out of bound"); - return ExceptionType::ADDRESSERROR_EXCEPTION; + return ExceptionType::AddressErrorException; } /*Doc nachos dit que ce test sert a savoir si la page est mappée @@ -113,13 +113,13 @@ impl <'a>MMU <'_>{ */ 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; + return ExceptionType::AddressErrorException; } //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; + return ExceptionType::AddressErrorException; } //if the page is not yet in main memory, run the page fault manager @@ -129,13 +129,13 @@ impl <'a>MMU <'_>{ 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; + return ExceptionType::AddressErrorException; } //Make sure that the physical adress is correct 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; + return ExceptionType::BusErrorException; } //Set U/M bits to 1 @@ -151,6 +151,6 @@ impl <'a>MMU <'_>{ } } - ExceptionType::NO_EXCEPTION + ExceptionType::NoException } } \ No newline at end of file