mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
baremetal: just one more build error for this phase
Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
e7a4927943
commit
30fef020f2
2 changed files with 96 additions and 59 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
use core::mem;
|
|
||||||
use core::cell::RefCell;
|
use core::cell::RefCell;
|
||||||
|
use core::mem;
|
||||||
static mut PROCESS: *mut ProcessImpl = 0xff80_1000 as *mut ProcessImpl;
|
static mut PROCESS: *mut ProcessImpl = 0xff80_1000 as *mut ProcessImpl;
|
||||||
pub const MAX_THREAD: TID = 31;
|
pub const MAX_THREAD: TID = 31;
|
||||||
pub const INITIAL_TID: TID = 1;
|
pub const INITIAL_TID: TID = 1;
|
||||||
|
|
@ -93,7 +93,9 @@ pub struct Thread {
|
||||||
|
|
||||||
impl Process {
|
impl Process {
|
||||||
pub fn current() -> Process {
|
pub fn current() -> Process {
|
||||||
Process { pid: unsafe { PROCESS_TABLE.borrow().current } }
|
Process {
|
||||||
|
pid: unsafe { PROCESS_TABLE.borrow().current },
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mark this process as running on the current core
|
/// Mark this process as running on the current core
|
||||||
|
|
@ -171,7 +173,7 @@ impl Process {
|
||||||
&mut process.threads[thread - 1]
|
&mut process.threads[thread - 1]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_free_thread_nr(&self) -> Option<TID> {
|
pub fn find_free_thread(&self) -> Option<TID> {
|
||||||
let mut process = unsafe { &mut *PROCESS };
|
let mut process = unsafe { &mut *PROCESS };
|
||||||
for (index, thread) in process.threads.iter().enumerate() {
|
for (index, thread) in process.threads.iter().enumerate() {
|
||||||
if index != 0 && thread.sepc == 0 {
|
if index != 0 && thread.sepc == 0 {
|
||||||
|
|
@ -224,6 +226,27 @@ impl Process {
|
||||||
|
|
||||||
process.inner = Default::default();
|
process.inner = Default::default();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn setup_thread(&mut self, thread: TID, _setup: ThreadInit) -> Result<(), xous::Error> {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn create(pid: PID, init_data: ProcessInit) -> PID {
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn destroy(pid: PID) -> Result<(), xous::Error> {
|
||||||
|
todo!();
|
||||||
|
// let mut process_table = unsafe { &mut *PROCESS };
|
||||||
|
// let pid_idx = pid.get() as usize - 1;
|
||||||
|
// if pid_idx >= process_table.table.len() {
|
||||||
|
// panic!("attempted to destroy PID that exceeds table index: {}", pid);
|
||||||
|
// }
|
||||||
|
// let process = process_table.table[pid_idx].as_mut().unwrap();
|
||||||
|
// process_table.table[pid_idx] = None;
|
||||||
|
// process_table.total -= 1;
|
||||||
|
// Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Thread {
|
impl Thread {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ 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 xous::MemoryRange;
|
||||||
|
use crate::mem::MemoryManager;
|
||||||
|
|
||||||
use core::cell::RefCell;
|
use core::cell::RefCell;
|
||||||
|
|
||||||
|
|
@ -287,7 +288,12 @@ impl SystemServices {
|
||||||
init_count += 1;
|
init_count += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unsafe { core::slice::from_raw_parts(base as *const crate::arch::process::InitialProcess, init_count) }
|
unsafe {
|
||||||
|
core::slice::from_raw_parts(
|
||||||
|
base as *const crate::arch::process::InitialProcess,
|
||||||
|
init_count,
|
||||||
|
)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Copy over the initial process list. The pid is encoded in the SATP
|
// Copy over the initial process list. The pid is encoded in the SATP
|
||||||
|
|
@ -312,7 +318,11 @@ impl SystemServices {
|
||||||
if pid == 1 {
|
if pid == 1 {
|
||||||
process.state = ProcessState::Running(0);
|
process.state = ProcessState::Running(0);
|
||||||
} else {
|
} else {
|
||||||
process.state = ProcessState::Setup(init.entrypoint, init.sp, crate::arch::process::DEFAULT_STACK_SIZE);
|
process.state = ProcessState::Setup(
|
||||||
|
init.entrypoint,
|
||||||
|
init.sp,
|
||||||
|
crate::arch::process::DEFAULT_STACK_SIZE,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -987,7 +997,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;
|
||||||
crate::mem::MemoryManager::with_mut(|mm| {
|
crate::mem::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
|
||||||
|
|
@ -1003,8 +1012,8 @@ impl SystemServices {
|
||||||
let mut error = None;
|
let mut error = None;
|
||||||
|
|
||||||
// Lend each subsequent page.
|
// Lend each subsequent page.
|
||||||
for offset in
|
for offset in (0..(len / core::mem::size_of::<usize>()))
|
||||||
(0..(len / core::mem::size_of::<usize>())).step_by(crate::mem::PAGE_SIZE / core::mem::size_of::<usize>())
|
.step_by(crate::mem::PAGE_SIZE / core::mem::size_of::<usize>())
|
||||||
{
|
{
|
||||||
mm.move_page(
|
mm.move_page(
|
||||||
&src_mapping,
|
&src_mapping,
|
||||||
|
|
@ -1080,38 +1089,39 @@ impl SystemServices {
|
||||||
let current_pid = self.current_pid();
|
let current_pid = self.current_pid();
|
||||||
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;
|
||||||
let mut mm = MemoryManagerHandle::get();
|
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
|
||||||
.find_virtual_address(dest_virt, len, xous::MemoryType::Messages)
|
.find_virtual_address(dest_virt, len, xous::MemoryType::Messages)
|
||||||
.or_else(|e| {
|
.or_else(|e| {
|
||||||
src_mapping.activate();
|
src_mapping.activate();
|
||||||
Err(e)
|
Err(e)
|
||||||
})?;
|
})?;
|
||||||
src_mapping.activate();
|
src_mapping.activate();
|
||||||
|
|
||||||
let mut error = None;
|
let mut error = None;
|
||||||
|
|
||||||
// Lend each subsequent page.
|
// Lend each subsequent page.
|
||||||
for offset in
|
for offset in (0..(len / core::mem::size_of::<usize>()))
|
||||||
(0..(len / core::mem::size_of::<usize>())).step_by(crate::mem::PAGE_SIZE / core::mem::size_of::<usize>())
|
.step_by(crate::mem::PAGE_SIZE / core::mem::size_of::<usize>())
|
||||||
{
|
{
|
||||||
mm.lend_page(
|
mm.lend_page(
|
||||||
&src_mapping,
|
&src_mapping,
|
||||||
src_virt.wrapping_add(offset),
|
src_virt.wrapping_add(offset),
|
||||||
dest_pid,
|
dest_pid,
|
||||||
&dest_mapping,
|
&dest_mapping,
|
||||||
dest_virt.wrapping_add(offset),
|
dest_virt.wrapping_add(offset),
|
||||||
mutable,
|
mutable,
|
||||||
)
|
)
|
||||||
.unwrap_or_else(|e| {
|
.unwrap_or_else(|e| {
|
||||||
error = Some(e);
|
error = Some(e);
|
||||||
0
|
0
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
error.map_or_else(|| Ok(dest_virt), |e| panic!("unable to lend: {:?}", e))
|
error.map_or_else(|| Ok(dest_virt), |e| panic!("unable to lend: {:?}", e))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(baremetal))]
|
#[cfg(not(baremetal))]
|
||||||
|
|
@ -1161,26 +1171,27 @@ impl SystemServices {
|
||||||
let current_pid = self.current_pid();
|
let current_pid = self.current_pid();
|
||||||
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;
|
||||||
let mut mm = MemoryManagerHandle::get();
|
MemoryManager::with_mut(|mm| {
|
||||||
let mut error = None;
|
let mut error = None;
|
||||||
|
|
||||||
// Lend each subsequent page.
|
// Lend each subsequent page.
|
||||||
for offset in
|
for offset in (0..(len / core::mem::size_of::<usize>()))
|
||||||
(0..(len / core::mem::size_of::<usize>())).step_by(crate::mem::PAGE_SIZE / core::mem::size_of::<usize>())
|
.step_by(crate::mem::PAGE_SIZE / core::mem::size_of::<usize>())
|
||||||
{
|
{
|
||||||
mm.unlend_page(
|
mm.unlend_page(
|
||||||
&src_mapping,
|
&src_mapping,
|
||||||
src_virt.wrapping_add(offset),
|
src_virt.wrapping_add(offset),
|
||||||
dest_pid,
|
dest_pid,
|
||||||
&dest_mapping,
|
&dest_mapping,
|
||||||
dest_virt.wrapping_add(offset),
|
dest_virt.wrapping_add(offset),
|
||||||
)
|
)
|
||||||
.unwrap_or_else(|e| {
|
.unwrap_or_else(|e| {
|
||||||
error = Some(e);
|
error = Some(e);
|
||||||
0
|
0
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
error.map_or_else(|| Ok(dest_virt), |e| Err(e))
|
error.map_or_else(|| Ok(dest_virt), |e| Err(e))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(baremetal))]
|
#[cfg(not(baremetal))]
|
||||||
|
|
@ -1281,8 +1292,12 @@ impl SystemServices {
|
||||||
if entry == &None {
|
if entry == &None {
|
||||||
#[cfg(baremetal)]
|
#[cfg(baremetal)]
|
||||||
// Allocate a single page for the server queue
|
// Allocate a single page for the server queue
|
||||||
let backing = crate::mem::MemoryManager::with_mut(|mm|
|
let backing = crate::mem::MemoryManager::with_mut(|mm| {
|
||||||
MemoryRange::new(mm.map_zeroed_page(pid, false)? as _, crate::arch::mem::PAGE_SIZE))?;
|
MemoryRange::new(
|
||||||
|
mm.map_zeroed_page(pid, false)? as _,
|
||||||
|
crate::arch::mem::PAGE_SIZE,
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
#[cfg(not(baremetal))]
|
#[cfg(not(baremetal))]
|
||||||
let backing = MemoryRange::new(4096, 4096).unwrap();
|
let backing = MemoryRange::new(4096, 4096).unwrap();
|
||||||
|
|
@ -1291,7 +1306,6 @@ impl SystemServices {
|
||||||
// self.pid.get()
|
// self.pid.get()
|
||||||
// );
|
// );
|
||||||
|
|
||||||
|
|
||||||
// Initialize the server with the given memory page.
|
// Initialize the server with the given memory page.
|
||||||
Server::init(entry, pid, sid, backing).map_err(|x| x)?;
|
Server::init(entry, pid, sid, backing).map_err(|x| x)?;
|
||||||
return Ok(sid);
|
return Ok(sid);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue