mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +00:00
kernel: on to lifetime issues now!
Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
30fef020f2
commit
8925964754
2 changed files with 45 additions and 29 deletions
|
|
@ -2,8 +2,8 @@ use crate::arch;
|
||||||
use crate::arch::mem::MemoryMapping;
|
use crate::arch::mem::MemoryMapping;
|
||||||
pub use crate::arch::process::Process as ArchProcess;
|
pub use crate::arch::process::Process as ArchProcess;
|
||||||
pub use crate::arch::process::Thread;
|
pub use crate::arch::process::Thread;
|
||||||
use xous::MemoryRange;
|
|
||||||
use crate::mem::MemoryManager;
|
use crate::mem::MemoryManager;
|
||||||
|
use xous::MemoryRange;
|
||||||
|
|
||||||
use core::cell::RefCell;
|
use core::cell::RefCell;
|
||||||
|
|
||||||
|
|
@ -69,7 +69,7 @@ pub enum ProcessState {
|
||||||
|
|
||||||
/// This is a brand-new process that hasn't been run yet, and needs its
|
/// This is a brand-new process that hasn't been run yet, and needs its
|
||||||
/// initial context set up.
|
/// initial context set up.
|
||||||
// Setup(ThreadInit),
|
Setup(ThreadInit),
|
||||||
|
|
||||||
/// This process is able to be run. The context bitmask describes contexts
|
/// This process is able to be run. The context bitmask describes contexts
|
||||||
/// that are ready.
|
/// that are ready.
|
||||||
|
|
@ -318,11 +318,12 @@ impl SystemServices {
|
||||||
if pid == 1 {
|
if pid == 1 {
|
||||||
process.state = ProcessState::Running(0);
|
process.state = ProcessState::Running(0);
|
||||||
} else {
|
} else {
|
||||||
process.state = ProcessState::Setup(
|
process.state = ProcessState::Setup(ThreadInit::new(
|
||||||
init.entrypoint,
|
unsafe { core::mem::transmute::<usize, _>(init.entrypoint) },
|
||||||
init.sp,
|
MemoryRange::new(init.sp, crate::arch::process::DEFAULT_STACK_SIZE).unwrap(),
|
||||||
crate::arch::process::DEFAULT_STACK_SIZE,
|
None,
|
||||||
);
|
[0u8; 16],
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -560,27 +561,27 @@ impl SystemServices {
|
||||||
process.state = match process.state {
|
process.state = match process.state {
|
||||||
ProcessState::Free => return Err(xous::Error::ProcessNotFound),
|
ProcessState::Free => return Err(xous::Error::ProcessNotFound),
|
||||||
ProcessState::Sleeping => return Err(xous::Error::ProcessNotFound),
|
ProcessState::Sleeping => return Err(xous::Error::ProcessNotFound),
|
||||||
ProcessState::Allocated => return Err(xous::Error::ProcessNotFound), /*
|
ProcessState::Allocated => return Err(xous::Error::ProcessNotFound),
|
||||||
ProcessState::Setup(setup) => {
|
ProcessState::Setup(setup) => {
|
||||||
// Activate the process, which enables its memory mapping
|
// Activate the process, which enables its memory mapping
|
||||||
process.activate()?;
|
process.activate()?;
|
||||||
|
|
||||||
// If a context is specified for a Setup task to switch to,
|
// If a context is specified for a Setup task to switch to,
|
||||||
// ensure it's the INITIAL_TID. Otherwise it's not valid.
|
// ensure it's the INITIAL_TID. Otherwise it's not valid.
|
||||||
if let Some(ctx) = tid {
|
if let Some(tid) = tid {
|
||||||
if ctx != INITIAL_TID {
|
if tid != INITIAL_TID {
|
||||||
return Err(xous::Error::InvalidThread);
|
return Err(xous::Error::InvalidThread);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut p = crate::arch::process::Process::current();
|
||||||
|
p.setup_thread(INITIAL_TID, setup)?;
|
||||||
|
p.set_thread(INITIAL_TID)?;
|
||||||
|
// process.current_thread = INITIAL_TID as u8;
|
||||||
|
|
||||||
|
// Mark the current proces state as "running, and no waiting contexts"
|
||||||
|
ProcessState::Running(0)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let mut p = crate::arch::process::Process::current();
|
|
||||||
p.setup_thread(INITIAL_TID, setup)?;
|
|
||||||
p.set_thread(INITIAL_TID)?;
|
|
||||||
// process.current_thread = INITIAL_TID as u8;
|
|
||||||
|
|
||||||
// Mark the current proces state as "running, and no waiting contexts"
|
|
||||||
ProcessState::Running(0)
|
|
||||||
}*/
|
|
||||||
ProcessState::Ready(0) => {
|
ProcessState::Ready(0) => {
|
||||||
panic!("ProcessState was `Ready(0)`, which is invalid!");
|
panic!("ProcessState was `Ready(0)`, which is invalid!");
|
||||||
}
|
}
|
||||||
|
|
@ -1090,7 +1091,6 @@ impl SystemServices {
|
||||||
let src_mapping = self.get_process(current_pid)?.mapping;
|
let src_mapping = self.get_process(current_pid)?.mapping;
|
||||||
let dest_mapping = self.get_process(dest_pid)?.mapping;
|
let dest_mapping = self.get_process(dest_pid)?.mapping;
|
||||||
MemoryManager::with_mut(|mm| {
|
MemoryManager::with_mut(|mm| {
|
||||||
|
|
||||||
// Locate an address to fit the new memory.
|
// Locate an address to fit the new memory.
|
||||||
dest_mapping.activate();
|
dest_mapping.activate();
|
||||||
let dest_virt = mm
|
let dest_virt = mm
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{MemoryAddress, PID, TID};
|
use crate::{MemoryAddress, MemoryRange, PID, TID};
|
||||||
use core::convert::TryInto;
|
use core::convert::TryInto;
|
||||||
|
|
||||||
mod mem;
|
mod mem;
|
||||||
|
|
@ -12,11 +12,27 @@ pub struct ProcessArgs {
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct ThreadInit {
|
pub struct ThreadInit {
|
||||||
call: fn(data: *const usize) -> usize,
|
call: fn(data: *const usize) -> usize,
|
||||||
stack: MemoryAddress,
|
stack: MemoryRange,
|
||||||
arg: Option<MemoryAddress>,
|
arg: Option<MemoryAddress>,
|
||||||
name: [u8; 16],
|
name: [u8; 16],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ThreadInit {
|
||||||
|
pub fn new(
|
||||||
|
call: fn(data: *const usize) -> usize,
|
||||||
|
stack: MemoryRange,
|
||||||
|
arg: Option<MemoryAddress>,
|
||||||
|
name: [u8; 16],
|
||||||
|
) -> Self {
|
||||||
|
ThreadInit {
|
||||||
|
call,
|
||||||
|
stack,
|
||||||
|
arg,
|
||||||
|
name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||||
pub struct ProcessKey([u8; 16]);
|
pub struct ProcessKey([u8; 16]);
|
||||||
impl ProcessKey {
|
impl ProcessKey {
|
||||||
|
|
@ -37,7 +53,7 @@ pub fn thread_to_args(call: usize, init: &ThreadInit) -> [usize; 8] {
|
||||||
[
|
[
|
||||||
call as usize,
|
call as usize,
|
||||||
init.call as usize,
|
init.call as usize,
|
||||||
init.stack.get(),
|
init.stack.as_ptr() as _,
|
||||||
init.arg.map(|x| x.get()).unwrap_or_default(),
|
init.arg.map(|x| x.get()).unwrap_or_default(),
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue