Compare commits
1 Commits
main
...
clippy_fix
Author | SHA1 | Date | |
---|---|---|---|
|
9b87a0cd83 |
@ -3,7 +3,7 @@ use std::{cell::RefCell, rc::Rc};
|
|||||||
use crate::{simulator::{machine::{ExceptionType, Machine}, error::{MachineOk, MachineError}}};
|
use crate::{simulator::{machine::{ExceptionType, Machine}, error::{MachineOk, MachineError}}};
|
||||||
use crate::kernel::synch::{Lock, Semaphore};
|
use crate::kernel::synch::{Lock, Semaphore};
|
||||||
|
|
||||||
use super::{system::{System, self}, thread::Thread};
|
use super::{system::{System}, thread::Thread};
|
||||||
|
|
||||||
/// The halt system call. Stops Burritos.
|
/// The halt system call. Stops Burritos.
|
||||||
pub const SC_SHUTDOWN: u8 = 0;
|
pub const SC_SHUTDOWN: u8 = 0;
|
||||||
@ -239,7 +239,7 @@ fn sc_sem_create(machine: &mut Machine, system: &mut System) -> Result<MachineOk
|
|||||||
let size = get_length_param(addr_name, machine);
|
let size = get_length_param(addr_name, machine);
|
||||||
let _name = get_string_param(addr_name, size, machine);
|
let _name = get_string_param(addr_name, size, machine);
|
||||||
match initial_count < 0 {
|
match initial_count < 0 {
|
||||||
true => Err(format!("Initial_count < 0"))?,
|
true => Err("Initial_count < 0".to_string())?,
|
||||||
false => {
|
false => {
|
||||||
let id = system.get_thread_manager().get_obj_addrs().add_semaphore(Semaphore::new(initial_count));
|
let id = system.get_thread_manager().get_obj_addrs().add_semaphore(Semaphore::new(initial_count));
|
||||||
machine.write_int_register(10, id as i64);
|
machine.write_int_register(10, id as i64);
|
||||||
@ -278,12 +278,12 @@ fn sc_new_thread(machine: &mut Machine, system: &mut System) -> Result<MachineOk
|
|||||||
};
|
};
|
||||||
let current_thread = current_thread.borrow_mut();
|
let current_thread = current_thread.borrow_mut();
|
||||||
if let Some(process) = current_thread.get_process_owner() {
|
if let Some(process) = current_thread.get_process_owner() {
|
||||||
system.get_thread_manager().start_thread(n_thread, Rc::clone(&process), func as u64, current_thread.thread_context.int_registers[2] as u64 + machine.page_size, args);
|
system.get_thread_manager().start_thread(n_thread, Rc::clone(process), func as u64, current_thread.thread_context.int_registers[2] as u64 + machine.page_size, args);
|
||||||
// TODO changé la valeur de sp quand on supportera les addresses virtuels
|
// TODO changé la valeur de sp quand on supportera les addresses virtuels
|
||||||
machine.write_int_register(10, tid as i64);
|
machine.write_int_register(10, tid as i64);
|
||||||
Ok(MachineOk::Ok)
|
Ok(MachineOk::Ok)
|
||||||
} else {
|
} else {
|
||||||
return Err("Process owner of current thread is none")?;
|
Err("Process owner of current thread is none")?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -350,8 +350,8 @@ mod test {
|
|||||||
machine.write_int_register(17, SC_SHUTDOWN as i64); // Set type to shutdown
|
machine.write_int_register(17, SC_SHUTDOWN as i64); // Set type to shutdown
|
||||||
// let ecall = Instruction::new(0b000000000000_00000_000_00000_1110011);
|
// let ecall = Instruction::new(0b000000000000_00000_000_00000_1110011);
|
||||||
|
|
||||||
machine.write_memory(4, 0, 0b000000000000_00000_000_00000_1110011); // ecall
|
machine.write_memory(4, 0, 0b0000_0000_0000_0000_0000_0000_0111_0011); // ecall
|
||||||
machine.write_memory(4, 4, 0b000000001010_00000_000_00001_0010011); // r1 <- 10
|
machine.write_memory(4, 4, 0b0000_0000_1010_0000_0000_0000_1001_0011); // r1 <- 10
|
||||||
let mut system = System::new(true);
|
let mut system = System::new(true);
|
||||||
machine.run(&mut system);
|
machine.run(&mut system);
|
||||||
// If the machine was stopped with no error, the shutdown worked
|
// If the machine was stopped with no error, the shutdown worked
|
||||||
@ -377,11 +377,11 @@ mod test {
|
|||||||
machine.write_int_register(11, 5); // String size
|
machine.write_int_register(11, 5); // String size
|
||||||
machine.write_int_register(12, 1); // Console output
|
machine.write_int_register(12, 1); // Console output
|
||||||
|
|
||||||
machine.write_memory(4, 0, 0b000000000000_00000_000_00000_1110011); // ecall
|
machine.write_memory(4, 0, 0b0000_0000_0000_0000_0000_0000_0111_0011); // ecall
|
||||||
machine.write_int_register(17, SC_WRITE as i64); // Set type to write
|
machine.write_int_register(17, SC_WRITE as i64); // Set type to write
|
||||||
|
|
||||||
machine.write_memory(4, 4, 0b000000000000_00000_000_10001_0010011); // r17 <- SC_SHUTDOWN
|
machine.write_memory(4, 4, 0b0000_0000_0000_0000_0000_1000_1001_0011); // r17 <- SC_SHUTDOWN
|
||||||
machine.write_memory(4, 8, 0b000000000000_00000_000_00000_1110011); // ecall
|
machine.write_memory(4, 8, 0b0000_0000_0000_0000_0000_0000_0111_0011); // ecall
|
||||||
|
|
||||||
let mut system = System::new(true);
|
let mut system = System::new(true);
|
||||||
machine.run(&mut system);
|
machine.run(&mut system);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Eq, Debug)]
|
||||||
pub struct Process {
|
pub struct Process {
|
||||||
pub num_thread: usize,
|
pub num_thread: usize,
|
||||||
}
|
}
|
@ -74,14 +74,14 @@ impl Lock {
|
|||||||
self.free = false;
|
self.free = false;
|
||||||
self.owner = Option::Some(match thread_manager.get_g_current_thread() {
|
self.owner = Option::Some(match thread_manager.get_g_current_thread() {
|
||||||
Some(th) => {
|
Some(th) => {
|
||||||
Rc::clone(&th)
|
Rc::clone(th)
|
||||||
},
|
},
|
||||||
None => unreachable!()
|
None => unreachable!()
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
match thread_manager.get_g_current_thread() {
|
match thread_manager.get_g_current_thread() {
|
||||||
Some(x) => {
|
Some(x) => {
|
||||||
let x = Rc::clone(&x);
|
let x = Rc::clone(x);
|
||||||
self.waiting_queue.push(Rc::clone(&x));
|
self.waiting_queue.push(Rc::clone(&x));
|
||||||
thread_manager.thread_sleep(machine, Rc::clone(&x));
|
thread_manager.thread_sleep(machine, Rc::clone(&x));
|
||||||
},
|
},
|
||||||
@ -111,7 +111,7 @@ impl Lock {
|
|||||||
Some(thread) => {
|
Some(thread) => {
|
||||||
self.owner = Some(thread);
|
self.owner = Some(thread);
|
||||||
match &self.owner {
|
match &self.owner {
|
||||||
Some(x) => thread_manager.ready_to_run(Rc::clone(&x)),
|
Some(x) => thread_manager.ready_to_run(Rc::clone(x)),
|
||||||
None => ()
|
None => ()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -252,7 +252,7 @@ impl ThreadManager {
|
|||||||
self.debug(format!("Finishing thread {}", thread.borrow().get_name()));
|
self.debug(format!("Finishing thread {}", thread.borrow().get_name()));
|
||||||
// g_objets_addrs->removeObject(self.thread) // a ajouté plus tard
|
// g_objets_addrs->removeObject(self.thread) // a ajouté plus tard
|
||||||
for (_, el) in thread.borrow().join_thread.iter().enumerate() {
|
for (_, el) in thread.borrow().join_thread.iter().enumerate() {
|
||||||
self.ready_to_run(Rc::clone(&el));
|
self.ready_to_run(Rc::clone(el));
|
||||||
}
|
}
|
||||||
self.thread_sleep(machine, Rc::clone(&thread));
|
self.thread_sleep(machine, Rc::clone(&thread));
|
||||||
machine.interrupt.set_status(old_status);
|
machine.interrupt.set_status(old_status);
|
||||||
@ -512,7 +512,7 @@ mod test {
|
|||||||
thread_manager.lock_acquire(lock_id, &mut machine).expect("lock acquire return an error at second iteration: ");
|
thread_manager.lock_acquire(lock_id, &mut machine).expect("lock acquire return an error at second iteration: ");
|
||||||
{
|
{
|
||||||
let lock = thread_manager.get_obj_addrs().search_lock(lock_id).unwrap();
|
let lock = thread_manager.get_obj_addrs().search_lock(lock_id).unwrap();
|
||||||
assert_eq!(lock.owner,Some(thread_1.clone()));
|
assert_eq!(lock.owner,Some(thread_1));
|
||||||
assert!(!lock.free);
|
assert!(!lock.free);
|
||||||
assert_eq!(lock.waiting_queue.iter().count(),1);
|
assert_eq!(lock.waiting_queue.iter().count(),1);
|
||||||
}
|
}
|
||||||
@ -525,7 +525,7 @@ mod test {
|
|||||||
assert!(lock.waiting_queue.is_empty());
|
assert!(lock.waiting_queue.is_empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_manager.set_g_current_thread(Some(thread_2.clone()));
|
thread_manager.set_g_current_thread(Some(thread_2));
|
||||||
thread_manager.lock_release(lock_id, &mut machine).expect("lock release return an error at second iteration: ");
|
thread_manager.lock_release(lock_id, &mut machine).expect("lock release return an error at second iteration: ");
|
||||||
{
|
{
|
||||||
let lock = thread_manager.get_obj_addrs().search_lock(lock_id).unwrap();
|
let lock = thread_manager.get_obj_addrs().search_lock(lock_id).unwrap();
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq, Eq)]
|
||||||
pub struct Interrupt {
|
pub struct Interrupt {
|
||||||
level: InterruptStatus
|
level: InterruptStatus
|
||||||
}
|
}
|
||||||
@ -21,7 +21,7 @@ impl Interrupt {
|
|||||||
old
|
old
|
||||||
}
|
}
|
||||||
|
|
||||||
fn one_tick(&self, nb_cycle: i32) {
|
fn one_tick(&self, _nb_cycle: i32) {
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ impl Interrupt {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Clone, Copy, Debug)]
|
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
||||||
pub enum InterruptStatus {
|
pub enum InterruptStatus {
|
||||||
InterruptOff,
|
InterruptOff,
|
||||||
InterruptOn
|
InterruptOn
|
||||||
|
@ -619,7 +619,7 @@ mod test {
|
|||||||
assert_eq!(loader.sections[1].virt_addr, 0x4000);
|
assert_eq!(loader.sections[1].virt_addr, 0x4000);
|
||||||
assert_eq!(loader.sections[1].image_offset, 0x1000);
|
assert_eq!(loader.sections[1].image_offset, 0x1000);
|
||||||
assert!(loader.sections[1].does_flag_contains_key(crate::simulator::loader::FlagValue::ShfAlloc));
|
assert!(loader.sections[1].does_flag_contains_key(crate::simulator::loader::FlagValue::ShfAlloc));
|
||||||
assert_eq!(loader.sections[2].virt_addr, 0x400_000);
|
assert_eq!(loader.sections[2].virt_addr, 0x0040_0000);
|
||||||
assert_eq!(loader.sections[2].image_offset, 0x2000);
|
assert_eq!(loader.sections[2].image_offset, 0x2000);
|
||||||
assert!(loader.sections[2].does_flag_contains_key(crate::simulator::loader::FlagValue::ShfAlloc));
|
assert!(loader.sections[2].does_flag_contains_key(crate::simulator::loader::FlagValue::ShfAlloc));
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,7 @@ impl Machine {
|
|||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn raise_exception(&mut self, exception: ExceptionType, address : u64, system: &mut System) -> Result<MachineOk, MachineError>{
|
pub fn raise_exception(&mut self, exception: ExceptionType, _address : u64, system: &mut System) -> Result<MachineOk, MachineError>{
|
||||||
self.set_status(MachineStatus::SystemMode);
|
self.set_status(MachineStatus::SystemMode);
|
||||||
// Handle the interruption
|
// Handle the interruption
|
||||||
match exception::call(&exception, self, system) {
|
match exception::call(&exception, self, system) {
|
||||||
|
@ -21,7 +21,7 @@ impl RegisterNum for i64 {}
|
|||||||
impl RegisterNum for f32 {}
|
impl RegisterNum for f32 {}
|
||||||
|
|
||||||
/// Machine register array
|
/// Machine register array
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq, Eq)]
|
||||||
pub struct Register<U: RegisterNum> {
|
pub struct Register<U: RegisterNum> {
|
||||||
/// 32 available registers of type U
|
/// 32 available registers of type U
|
||||||
register: [U; 32]
|
register: [U; 32]
|
||||||
|
@ -22,7 +22,7 @@ impl TranslationTable {
|
|||||||
|
|
||||||
let mut tmp_vec : Vec<PageTableEntry> = Vec::new();
|
let mut tmp_vec : Vec<PageTableEntry> = Vec::new();
|
||||||
|
|
||||||
for i in 0..MaxVirtPages {
|
for _i in 0..MaxVirtPages {
|
||||||
tmp_vec.push(PageTableEntry::create());
|
tmp_vec.push(PageTableEntry::create());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ impl TranslationTable {
|
|||||||
//Assert a mettre dans chacune des fonctions suivantes
|
//Assert a mettre dans chacune des fonctions suivantes
|
||||||
|
|
||||||
pub fn get_max_num_pages(&self) -> u64{
|
pub fn get_max_num_pages(&self) -> u64{
|
||||||
return self.maxNumPages;
|
self.maxNumPages
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_physical_page(&mut self, vpn : u64, physical_page : i32){
|
pub fn set_physical_page(&mut self, vpn : u64, physical_page : i32){
|
||||||
|
@ -9,7 +9,7 @@ use std::ptr;
|
|||||||
/// These methods wrap unsafe instructions because it doesn't respect borrow rules per example
|
/// These methods wrap unsafe instructions because it doesn't respect borrow rules per example
|
||||||
/// but everything has been tested with miri to assure there's no Undefined Behaviour (use-after-free, double free, etc.)
|
/// but everything has been tested with miri to assure there's no Undefined Behaviour (use-after-free, double free, etc.)
|
||||||
/// or memory leak
|
/// or memory leak
|
||||||
#[derive(PartialEq, Clone, Debug)]
|
#[derive(PartialEq, Eq, Clone, Debug)]
|
||||||
pub struct List<T: PartialEq> {
|
pub struct List<T: PartialEq> {
|
||||||
head: Link<T>,
|
head: Link<T>,
|
||||||
tail: Link<T>,
|
tail: Link<T>,
|
||||||
|
Loading…
Reference in New Issue
Block a user