Merge branch 'thread_scheduler' of gitlab.istic.univ-rennes1.fr:simpleos/burritos into thread_scheduler

This commit is contained in:
François Autin
2023-03-29 16:26:35 +02:00
3 changed files with 100 additions and 4 deletions

View File

@ -23,6 +23,10 @@ use crate::simulator::{
register::*
};
use crate::kernel::{
exception
};
/// # Exceptions
///
/// Textual names of the exceptions that can be generated by user program
@ -48,6 +52,16 @@ pub enum ExceptionType {
NumExceptionTypes
}
/// # Machine Status
///
/// The machine can be running kernel code (SystemMode), user code (UserMode),
/// or there can be no running thread if the ready list is empty (IdleMode).
pub enum MachineStatus {
IdleMode,
SystemMode,
UserMode
}
/// ID of the stack register
pub const STACK_REG: usize = 2;
/// Number of available Integer registers
@ -78,9 +92,12 @@ pub struct Machine {
/// Debug data
pub registers_trace : String, // for tests
/// todo: document Interrupts
pub interrupt: Interrupt
pub interrupt: Interrupt,
// futur taille à calculer int memSize = g_cfg->NumPhysPages * g_cfg->PageSize;
//creer une struct cfg(configuration) qui s'initialise avec valeur dans un fichier cfg
/// Current machine status
pub status: MachineStatus
}
@ -105,7 +122,8 @@ impl Machine {
main_memory : vec![0_u8; MEM_SIZE],
shiftmask,
interrupt: Interrupt::new(),
registers_trace : String::from("")
registers_trace : String::from(""),
status: MachineStatus::SystemMode
}
}
@ -206,6 +224,15 @@ impl Machine {
s
}
pub fn raise_exception(&mut self, exception: ExceptionType, address : u64) -> Result<(), MachineError>{
self.set_status(MachineStatus::SystemMode);
// Handle the interruption
exception::call(exception, self); // todo: return error if the syscall code is invalid
self.set_status(MachineStatus::UserMode);
Ok(())
}
/// Execute the instructions table of a machine putted in param
///
/// ### Parameters
@ -298,7 +325,7 @@ impl Machine {
RISCV_FP => self.fp_instruction(inst),
// Treatment for: SYSTEM CALLS
RISCV_SYSTEM => Err(format!("{:x}: System opcode\npc: {:x}", inst.opcode, self.pc))?,
RISCV_SYSTEM => self.raise_exception(ExceptionType::SyscallException, self.pc),
// Default case
_ => Err(format!("{:x}: Unknown opcode\npc: {:x}", inst.opcode, self.pc))?
@ -640,6 +667,14 @@ impl Machine {
pub fn write_fp_register(&mut self, index: usize, value: f32) {
self.fp_reg.set_reg(index as u8, value);
}
pub fn get_status(&self) -> MachineStatus {
todo!()
}
pub fn set_status(&mut self, new_status: MachineStatus) {
self.status = new_status;
}
}
#[cfg(test)]