1
0
forked from Rativel/BurritOS

Add thread save and restore processor context

This commit is contained in:
Quentin Legot
2023-03-09 12:08:33 +01:00
parent fe4bbb2fc2
commit d392c69535
5 changed files with 83 additions and 37 deletions

View File

@@ -1,13 +1,12 @@
use super::{process::Process, system::ObjectType};
use super::{process::Process, system::ObjectType, thread_manager::SIMULATORSTACKSIZE};
use crate::{simulator::machine::{NUM_INT_REGS, NUM_FP_REGS, STACK_REG}};
const SIMULATORSTACKSIZE: usize = 32 * 1024;
const STACK_FENCEPOST: u32 = 0xdeadbeef;
#[derive(PartialEq)]
struct ThreadContext {
pub struct ThreadContext {
pub int_registers: [i64; NUM_INT_REGS],
pub float_registers: [i64; NUM_FP_REGS],
pub float_registers: [f32; NUM_FP_REGS],
pc: i64,
}
@@ -16,8 +15,8 @@ pub struct Thread {
name: String,
pub process: Option<Process>,
// simulation_context: UContextT,
thread_context: ThreadContext,
stack_pointer: i32,
pub thread_context: ThreadContext,
pub stack_pointer: i32,
object_type: ObjectType
}
@@ -31,7 +30,7 @@ impl Thread {
// simulation_context: UContextT::new(),
thread_context: ThreadContext {
int_registers: [0; NUM_INT_REGS],
float_registers: [0; NUM_FP_REGS],
float_registers: [0f32; NUM_FP_REGS],
pc: 0
},
stack_pointer: 0,
@@ -59,28 +58,19 @@ impl Thread {
// self.simulation_context.stackBottom = base_stack_addr.to_vec();
// self.simulation_context.stackBottom[0] = STACK_FENCEPOST;
}
/// Put the thread to sleep and relinquish the processor
pub fn sleep(&self) {
todo!();
}
/// Finish the execution of the thread and prepare its deallocation
pub fn finish(&self) {
todo!();
}
/// 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.
///
pub fn check_overflow(&self) {
todo!();
// if self.simulator_context.stackBottom != STACK_FENCEPOST {
// panic!("thread {} has overflowed", self.get_name())
// }
}
pub fn save_processor_state(&self) {
todo!();
}
pub fn restore_processor_state(&self) {
todo!();
pub fn sleep(&self) {
unreachable!("Has been moved to thread manager");
}
pub fn save_simulator_state(&self) {