Add Exit Exception
This commit is contained in:
@ -15,13 +15,13 @@ use std::{
|
||||
io::Write,
|
||||
fs::File
|
||||
};
|
||||
use crate::simulator::{
|
||||
use crate::{simulator::{
|
||||
error::MachineError,
|
||||
instruction::{*, self},
|
||||
interrupt::Interrupt,
|
||||
global::*,
|
||||
register::*
|
||||
};
|
||||
}, kernel::system::System};
|
||||
|
||||
use crate::kernel::{
|
||||
exception
|
||||
@ -226,11 +226,11 @@ impl Machine {
|
||||
s
|
||||
}
|
||||
|
||||
pub fn raise_exception(&mut self, exception: ExceptionType, address : u64) -> Result<MachineOk, MachineError>{
|
||||
pub fn raise_exception(&mut self, exception: ExceptionType, address : u64, system: &mut System) -> Result<MachineOk, MachineError>{
|
||||
|
||||
self.set_status(MachineStatus::SystemMode);
|
||||
// Handle the interruption
|
||||
match exception::call(exception, self) {
|
||||
match exception::call(exception, self, system) {
|
||||
Ok(MachineOk::Shutdown) => {
|
||||
self.set_status(MachineStatus::UserMode);
|
||||
return Ok(MachineOk::Shutdown);
|
||||
@ -246,9 +246,9 @@ impl Machine {
|
||||
/// ### Parameters
|
||||
///
|
||||
/// - **machine** which contains a table of instructions
|
||||
pub fn run(&mut self) {
|
||||
pub fn run(&mut self, system: &mut System) {
|
||||
loop {
|
||||
match self.one_instruction() {
|
||||
match self.one_instruction(system) {
|
||||
Ok(MachineOk::Ok) => println!("hello"),
|
||||
Ok(MachineOk::Shutdown) => break,
|
||||
Err(e) => { if e.to_string().contains("System") { break; } panic!("FATAL at pc {} -> {}", self.pc, e) }
|
||||
@ -262,7 +262,7 @@ impl Machine {
|
||||
/// ### Parameters
|
||||
///
|
||||
/// - **machine** which contains a table of instructions and a pc to the actual instruction
|
||||
pub fn one_instruction(&mut self) -> Result<MachineOk, MachineError> {
|
||||
pub fn one_instruction(&mut self, system: &mut System) -> Result<MachineOk, MachineError> {
|
||||
|
||||
if self.main_memory.len() <= self.pc as usize {
|
||||
panic!("ERROR : number max of instructions rushed");
|
||||
@ -335,7 +335,7 @@ impl Machine {
|
||||
RISCV_FP => self.fp_instruction(inst),
|
||||
|
||||
// Treatment for: SYSTEM CALLS
|
||||
RISCV_SYSTEM => self.raise_exception(ExceptionType::SyscallException, self.pc),
|
||||
RISCV_SYSTEM => self.raise_exception(ExceptionType::SyscallException, self.pc, system),
|
||||
|
||||
// Default case
|
||||
_ => Err(format!("{:x}: Unknown opcode\npc: {:x}", inst.opcode, self.pc))?
|
||||
@ -710,7 +710,8 @@ mod test {
|
||||
let memory_before = mem_cmp::MemChecker::from(get_full_path!("memory", $a)).unwrap();
|
||||
let memory_after = mem_cmp::MemChecker::from(get_full_path!("memory", &end_file_name)).unwrap();
|
||||
mem_cmp::MemChecker::fill_memory_from_mem_checker(&memory_before, &mut m);
|
||||
m.run();
|
||||
let mut system = crate::kernel::system::System::default();
|
||||
m.run(&mut system);
|
||||
let expected_trace = fs::read_to_string(get_full_path!("reg_trace", $a)).unwrap();
|
||||
assert!(mem_cmp::MemChecker::compare_machine_memory(&memory_after, &m));
|
||||
assert!(expected_trace.contains(m.registers_trace.as_str()));
|
||||
|
Reference in New Issue
Block a user