Lint: remove some warnings
This commit is contained in:
parent
9cc57e7f03
commit
66d6daf0b9
@ -1,5 +1,3 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::simulator::{machine::{ExceptionType, Machine}, error::{MachineOk, MachineError}};
|
||||
|
||||
use super::system::System;
|
||||
@ -174,9 +172,9 @@ fn syscall(machine: &mut Machine, system: &mut System) -> Result<MachineOk, Mach
|
||||
SC_V => todo!(),
|
||||
SC_SEM_CREATE => {
|
||||
let addr_name = machine.read_int_register(10);
|
||||
let initial_count = machine.read_int_register((11));
|
||||
let initial_count = machine.read_int_register(11);
|
||||
let size = get_length_param(addr_name as usize, machine);
|
||||
let name = get_string_param(addr_name, size, machine);
|
||||
let _name = get_string_param(addr_name, size, machine);
|
||||
|
||||
if initial_count <0{
|
||||
|
||||
@ -240,14 +238,13 @@ fn get_string_param(addr: i64, maxlen: usize, machine: &Machine) -> Vec<char>{
|
||||
mod test {
|
||||
use crate::kernel::exception::{SC_SHUTDOWN, SC_WRITE};
|
||||
use crate::kernel::system::System;
|
||||
use crate::simulator::instruction::Instruction;
|
||||
use crate::simulator::machine::Machine;
|
||||
|
||||
#[test]
|
||||
fn test_sc_shutdown() {
|
||||
let mut machine = Machine::new(true);
|
||||
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, 4, 0b000000001010_00000_000_00001_0010011); // r1 <- 10
|
||||
@ -263,7 +260,7 @@ mod test {
|
||||
fn test_sc_print() {
|
||||
let mut machine = Machine::new(true);
|
||||
|
||||
let address = machine.read_int_register(10);
|
||||
let _address = machine.read_int_register(10);
|
||||
// Write string 'HELLO' in memory
|
||||
machine.write_memory(1, 4000, 72);
|
||||
machine.write_memory(1, 4001, 69);
|
||||
|
@ -3,8 +3,7 @@
|
||||
//! Module containing structs and methods pertaining to the state of the operating system
|
||||
|
||||
use super::{thread_manager::ThreadManager};
|
||||
use crate::utility;
|
||||
use crate::utility::objaddr::{ObjAddr, SynchObj};
|
||||
use crate::utility::objaddr::ObjAddr;
|
||||
|
||||
/// # System
|
||||
///
|
||||
|
@ -1,4 +1,4 @@
|
||||
use super::{process::Process, system::ObjectType, thread_manager::SIMULATORSTACKSIZE};
|
||||
use super::{process::Process, system::ObjectType};
|
||||
use crate::{simulator::machine::{NUM_INT_REGS, NUM_FP_REGS, STACK_REG}};
|
||||
|
||||
const STACK_FENCEPOST: u32 = 0xdeadbeef;
|
||||
@ -23,7 +23,6 @@ pub struct ThreadContext {
|
||||
pub struct Thread {
|
||||
name: String,
|
||||
pub process: Option<Process>,
|
||||
// simulation_context: UContextT,
|
||||
pub thread_context: ThreadContext,
|
||||
pub stack_pointer: i32,
|
||||
object_type: ObjectType
|
||||
@ -53,21 +52,6 @@ impl Thread {
|
||||
self.thread_context.int_registers[STACK_REG] = initial_sp as i64;
|
||||
}
|
||||
|
||||
pub fn init_simulator_context(&self, base_stack_addr: [i8; SIMULATORSTACKSIZE]) {
|
||||
// let res = self.simulation_context.get_context();
|
||||
// if res != 0 {
|
||||
// panic!("getcontext returns non-zero value {}", res);
|
||||
// }
|
||||
// self.simulation_context.buf.uc_stack.ss_sp = base_stack_addr;
|
||||
// self.simulation_context.buf.uc_stack.ss_size = base_stack_addr.len();
|
||||
// self.simulation_context.buf.uc_stack.ss_flags = 0;
|
||||
// self.simulation_context.buf.uc_link = UContextT::new().buf;
|
||||
// self.simulation_context.make_context(start_thread_execution, 0);
|
||||
|
||||
// self.simulation_context.stackBottom = base_stack_addr.to_vec();
|
||||
// self.simulation_context.stackBottom[0] = STACK_FENCEPOST;
|
||||
}
|
||||
|
||||
/// Check if a thread has overflowed its stack
|
||||
///
|
||||
/// This assertion doesn't catch all stack overflow conditions and your program may still crash because of an overflow.
|
||||
@ -78,14 +62,6 @@ impl Thread {
|
||||
// }
|
||||
}
|
||||
|
||||
pub fn save_simulator_state(&self) {
|
||||
// todo!(); // simulator state will maybe be removed so panic call is remove. See ucontext.rs
|
||||
}
|
||||
|
||||
pub fn restore_simulator_state(&self) {
|
||||
// todo!(); // simulator state will maybe be removed so panic call is remove. See ucontext.rs
|
||||
}
|
||||
|
||||
pub fn get_name(&self) -> String {
|
||||
self.name.clone()
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ use std::{rc::Rc, cell::{RefCell, Ref}};
|
||||
|
||||
use crate::{utility::list::List, simulator::{machine::{NUM_INT_REGS, NUM_FP_REGS, Machine}, interrupt::InterruptStatus}};
|
||||
|
||||
use super::{thread::Thread, mgerror::ErrorCode, process::Process};
|
||||
use super::{thread::Thread, process::Process};
|
||||
|
||||
pub const SIMULATORSTACKSIZE: usize = 32 * 1024;
|
||||
|
||||
@ -92,8 +92,6 @@ impl ThreadManager {
|
||||
thread_m.process = Option::Some(owner);
|
||||
let ptr = sp_loc; // todo addrspace
|
||||
thread_m.init_thread_context(func_pc, ptr, argument);
|
||||
let base_stack_addr: [i8; SIMULATORSTACKSIZE] = [0; SIMULATORSTACKSIZE]; // todo AllocBoundedArray
|
||||
thread_m.init_simulator_context(base_stack_addr);
|
||||
thread_m.process.as_mut().unwrap().num_thread += 1;
|
||||
self.get_g_alive().push(Rc::clone(&thread));
|
||||
self.ready_to_run(Rc::clone(&thread));
|
||||
@ -202,7 +200,7 @@ impl ThreadManager {
|
||||
mod test {
|
||||
use std::{rc::Rc, cell::RefCell};
|
||||
|
||||
use crate::{simulator::{machine::Machine, loader}, kernel::{system::System, thread::{Thread, self}, process::Process}};
|
||||
use crate::{simulator::{machine::Machine, loader}, kernel::{system::System, thread::Thread, process::Process}};
|
||||
|
||||
#[test]
|
||||
fn test_thread_context() {
|
||||
|
@ -2,35 +2,6 @@ use crate::Machine;
|
||||
use std::fs;
|
||||
use std::io::Read;
|
||||
|
||||
/// load a 32-bits binary file into the machine
|
||||
///
|
||||
/// ### Parameters
|
||||
///
|
||||
/// - **path** path of the file to load
|
||||
/// - **machine** the machine where the bin file will be loaded
|
||||
/// - **start_index** at which index of machine memory you want to start to load the program
|
||||
///
|
||||
/// Returns in a Result any io error
|
||||
pub fn load(path: &str, machine: &mut Machine, start_index: usize) -> Result<(), std::io::Error> {
|
||||
let mut file = fs::File::open(path)?;
|
||||
let mut instructions: Vec<u32> = Default::default();
|
||||
loop {
|
||||
let mut buf: [u8; 4] = [0; 4];
|
||||
let res = file.read(&mut buf)?;
|
||||
if res == 0 {
|
||||
break; // eof
|
||||
} else {
|
||||
instructions.push(u32::from_le_bytes(buf));
|
||||
}
|
||||
}
|
||||
for (i, inst) in instructions.iter().enumerate() {
|
||||
machine.write_memory(4, 4 * i + start_index, inst.to_owned() as u64);
|
||||
}
|
||||
// #[cfg(debug_assertions)]
|
||||
// println!("{:04x?}", instructions); // only print loaded program in debug build
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The elf header defines principes aspects of the binary files, it's place at the start of the file
|
||||
/// see <https://en.wikipedia.org/wiki/Executable_and_Linkable_Format#File_header> for more informations
|
||||
pub struct ElfHeader {
|
||||
|
@ -2,6 +2,13 @@
|
||||
|
||||
use std::ptr;
|
||||
|
||||
/// Definition of the generic single-linked FIFO list
|
||||
///
|
||||
/// Each elements points to a single item of the list and the following one
|
||||
///
|
||||
/// 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.)
|
||||
/// or memory leak
|
||||
#[derive(PartialEq)]
|
||||
pub struct List<T: PartialEq> {
|
||||
head: Link<T>,
|
||||
|
Loading…
Reference in New Issue
Block a user