Try some filesystems
This commit is contained in:
@@ -3,7 +3,7 @@ use core::{arch::riscv64::wfi, time::Duration};
|
||||
use alloc::{format, string::String};
|
||||
|
||||
use crate::{
|
||||
scheduler::{ACTIVE_PID, PROCESSUS_COUNT, PROCESS_TABLE},
|
||||
scheduler::{ACTIVE_PID, PROCESS_COUNT, PROCESS_TABLE},
|
||||
time::elapsed_time_since_startup,
|
||||
};
|
||||
|
||||
@@ -35,6 +35,7 @@ pub struct Process {
|
||||
pub pid: i64,
|
||||
pub name: String,
|
||||
pub state: ProcessState,
|
||||
pub entry: Option<fn()>,
|
||||
pub wake_time: Duration,
|
||||
pub ctx: ExecutionContext,
|
||||
pub stack: [u64; STACK_SIZE],
|
||||
@@ -53,15 +54,14 @@ impl core::fmt::Debug for Process {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_processus<T: Into<String>>(code: extern "C" fn(), name: T) -> i64 {
|
||||
pub fn create_process<T: Into<String>>(code: fn(), name: T) -> i64 {
|
||||
let mut next_pid = 0;
|
||||
while next_pid < PROCESSUS_COUNT
|
||||
&& unsafe { PROCESS_TABLE[next_pid].state != ProcessState::Dead }
|
||||
while next_pid < PROCESS_COUNT && unsafe { PROCESS_TABLE[next_pid].state != ProcessState::Dead }
|
||||
{
|
||||
next_pid += 1;
|
||||
}
|
||||
|
||||
if next_pid >= PROCESSUS_COUNT {
|
||||
if next_pid >= PROCESS_COUNT {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -69,8 +69,10 @@ pub fn create_processus<T: Into<String>>(code: extern "C" fn(), name: T) -> i64
|
||||
PROCESS_TABLE[next_pid].pid = next_pid as i64;
|
||||
PROCESS_TABLE[next_pid].name = name.into();
|
||||
PROCESS_TABLE[next_pid].state = ProcessState::Activable;
|
||||
PROCESS_TABLE[next_pid].ctx.a[0] = code as usize as u64;
|
||||
PROCESS_TABLE[next_pid].ctx.mepc = processus_launcher as *const _;
|
||||
PROCESS_TABLE[next_pid].entry = Some(code);
|
||||
PROCESS_TABLE[next_pid].ctx.a[0] =
|
||||
PROCESS_TABLE[next_pid].entry.as_ref().unwrap_unchecked() as *const fn() as u64;
|
||||
PROCESS_TABLE[next_pid].ctx.mepc = process_launcher as *const _;
|
||||
PROCESS_TABLE[next_pid].ctx.mstatus = 1 << 1 | 1 << 5;
|
||||
PROCESS_TABLE[next_pid].ctx.sp = &raw const PROCESS_TABLE[next_pid].stack[STACK_SIZE - 1];
|
||||
}
|
||||
@@ -78,12 +80,12 @@ pub fn create_processus<T: Into<String>>(code: extern "C" fn(), name: T) -> i64
|
||||
next_pid as i64
|
||||
}
|
||||
|
||||
extern "C" fn processus_launcher(code: extern "C" fn()) {
|
||||
code();
|
||||
terminate_processus();
|
||||
extern "C" fn process_launcher(code: *const fn()) {
|
||||
unsafe { (*code)() };
|
||||
terminate_process();
|
||||
}
|
||||
|
||||
fn terminate_processus() {
|
||||
fn terminate_process() {
|
||||
unsafe {
|
||||
PROCESS_TABLE[ACTIVE_PID].state = ProcessState::Dead;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user