mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
kernel: more warning fixes
Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
ba30b4919d
commit
bef0168c20
2 changed files with 80 additions and 71 deletions
|
|
@ -1,6 +1,4 @@
|
||||||
use crate::args::KernelArguments;
|
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use core::mem;
|
|
||||||
use core::slice;
|
use core::slice;
|
||||||
use core::str;
|
use core::str;
|
||||||
|
|
||||||
|
|
@ -114,7 +112,7 @@ impl MemoryManager {
|
||||||
pub fn init_from_memory(
|
pub fn init_from_memory(
|
||||||
&mut self,
|
&mut self,
|
||||||
base: *mut u32,
|
base: *mut u32,
|
||||||
args: &KernelArguments,
|
args: &crate::args::KernelArguments,
|
||||||
) -> Result<(), xous::Error> {
|
) -> Result<(), xous::Error> {
|
||||||
let mut args_iter = args.iter();
|
let mut args_iter = args.iter();
|
||||||
let xarg_def = args_iter.next().expect("mm: no kernel arguments found");
|
let xarg_def = args_iter.next().expect("mm: no kernel arguments found");
|
||||||
|
|
@ -146,7 +144,7 @@ impl MemoryManager {
|
||||||
let ptr = tag.data.as_ptr() as *mut MemoryRangeExtra;
|
let ptr = tag.data.as_ptr() as *mut MemoryRangeExtra;
|
||||||
EXTRA_REGIONS = slice::from_raw_parts_mut(
|
EXTRA_REGIONS = slice::from_raw_parts_mut(
|
||||||
ptr,
|
ptr,
|
||||||
tag.data.len() * 4 / mem::size_of::<MemoryRangeExtra>(),
|
tag.data.len() * 4 / core::mem::size_of::<MemoryRangeExtra>(),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -389,7 +387,7 @@ impl MemoryManager {
|
||||||
let virt = virt as *mut usize;
|
let virt = virt as *mut usize;
|
||||||
|
|
||||||
// Zero-out the page
|
// Zero-out the page
|
||||||
unsafe { virt.write_bytes(0, PAGE_SIZE / mem::size_of::<usize>()) };
|
unsafe { virt.write_bytes(0, PAGE_SIZE / core::mem::size_of::<usize>()) };
|
||||||
if is_user {
|
if is_user {
|
||||||
crate::arch::mem::hand_page_to_user(virt as _)?;
|
crate::arch::mem::hand_page_to_user(virt as _)?;
|
||||||
}
|
}
|
||||||
|
|
@ -608,7 +606,7 @@ impl MemoryManager {
|
||||||
&& addr < (region.mem_start + region.mem_size) as usize
|
&& addr < (region.mem_start + region.mem_size) as usize
|
||||||
{
|
{
|
||||||
offset += (addr - (region.mem_start as usize)) / PAGE_SIZE;
|
offset += (addr - (region.mem_start as usize)) / PAGE_SIZE;
|
||||||
return unsafe { action_inner(&mut MEMORY_ALLOCATIONS[offset], pid, action) };
|
return action_inner(&mut MEMORY_ALLOCATIONS[offset], pid, action);
|
||||||
}
|
}
|
||||||
offset += region.mem_size as usize / PAGE_SIZE;
|
offset += region.mem_size as usize / PAGE_SIZE;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,12 +80,12 @@ pub struct Process {
|
||||||
/// manipulate this process.
|
/// manipulate this process.
|
||||||
pub ppid: PID,
|
pub ppid: PID,
|
||||||
|
|
||||||
/// The current context (i.e. thread)
|
/// The current thread ID
|
||||||
// current_thread: u8,
|
current_thread: TID,
|
||||||
|
|
||||||
/// The context number that was active before this process was switched
|
/// The context number that was active before this process was switched
|
||||||
/// away.
|
/// away.
|
||||||
previous_context: u8,
|
previous_thread: TID,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Process {
|
impl Default for Process {
|
||||||
|
|
@ -198,8 +198,8 @@ std::thread_local!(static SYSTEM_SERVICES: core::cell::RefCell<SystemServices> =
|
||||||
ppid: unsafe { PID::new_unchecked(1) },
|
ppid: unsafe { PID::new_unchecked(1) },
|
||||||
pid: unsafe { PID::new_unchecked(1) },
|
pid: unsafe { PID::new_unchecked(1) },
|
||||||
mapping: arch::mem::DEFAULT_MEMORY_MAPPING,
|
mapping: arch::mem::DEFAULT_MEMORY_MAPPING,
|
||||||
// current_thread: 0,
|
current_thread: 0 as TID,
|
||||||
previous_context: INITIAL_TID as u8,
|
previous_thread: INITIAL_TID as TID,
|
||||||
}; MAX_PROCESS_COUNT],
|
}; MAX_PROCESS_COUNT],
|
||||||
// Note we can't use MAX_SERVER_COUNT here because of how Rust's
|
// Note we can't use MAX_SERVER_COUNT here because of how Rust's
|
||||||
// macro tokenization works
|
// macro tokenization works
|
||||||
|
|
@ -215,8 +215,8 @@ static mut SYSTEM_SERVICES: SystemServices = SystemServices {
|
||||||
ppid: unsafe { PID::new_unchecked(1) },
|
ppid: unsafe { PID::new_unchecked(1) },
|
||||||
pid: unsafe { PID::new_unchecked(1) },
|
pid: unsafe { PID::new_unchecked(1) },
|
||||||
mapping: arch::mem::DEFAULT_MEMORY_MAPPING,
|
mapping: arch::mem::DEFAULT_MEMORY_MAPPING,
|
||||||
// current_thread: 0,
|
current_thread: 0 as TID,
|
||||||
previous_context: INITIAL_TID as u8,
|
previous_thread: INITIAL_TID as TID,
|
||||||
}; MAX_PROCESS_COUNT],
|
}; MAX_PROCESS_COUNT],
|
||||||
// Note we can't use MAX_SERVER_COUNT here because of how Rust's
|
// Note we can't use MAX_SERVER_COUNT here because of how Rust's
|
||||||
// macro tokenization works
|
// macro tokenization works
|
||||||
|
|
@ -438,10 +438,7 @@ impl SystemServices {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a stack frame in the specified process and jump to it.
|
#[cfg(not(baremetal))]
|
||||||
/// 1. Pause the current process and switch to the new one
|
|
||||||
/// 2. Save the process state, if it hasn't already been saved
|
|
||||||
/// 3. Run the new process, returning to an illegal instruction
|
|
||||||
pub fn make_callback_to(
|
pub fn make_callback_to(
|
||||||
&mut self,
|
&mut self,
|
||||||
_pid: PID,
|
_pid: PID,
|
||||||
|
|
@ -449,64 +446,78 @@ impl SystemServices {
|
||||||
_irq_no: usize,
|
_irq_no: usize,
|
||||||
_arg: *mut usize,
|
_arg: *mut usize,
|
||||||
) -> Result<(), xous::Error> {
|
) -> Result<(), xous::Error> {
|
||||||
todo!();
|
|
||||||
Err(xous::Error::UnhandledSyscall)
|
Err(xous::Error::UnhandledSyscall)
|
||||||
// // Get the current process (which was just interrupted) and mark it as
|
}
|
||||||
// // "ready to run". If this function is called when the current process
|
|
||||||
// // isn't running, that means the system has gotten into an invalid
|
|
||||||
// // state.
|
|
||||||
// {
|
|
||||||
// let current_pid = self.current_pid();
|
|
||||||
// let mut current = self
|
|
||||||
// .get_process_mut(current_pid)
|
|
||||||
// .expect("couldn't get current PID");
|
|
||||||
// current.state = match current.state {
|
|
||||||
// ProcessState::Running(x) => ProcessState::Ready(x | (1 << current.current_context)),
|
|
||||||
// y => panic!("current process was {:?}, not 'Running(_)'", y),
|
|
||||||
// };
|
|
||||||
// println!("Making PID {} state {:?}", current_pid, current.state);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Get the new process, and ensure that it is in a state where it's fit
|
/// Create a stack frame in the specified process and jump to it.
|
||||||
// // to run. Again, if the new process isn't fit to run, then the system
|
/// 1. Pause the current process and switch to the new one
|
||||||
// // is in a very bad state.
|
/// 2. Save the process state, if it hasn't already been saved
|
||||||
// {
|
/// 3. Run the new process, returning to an illegal instruction
|
||||||
// let mut process = self.get_process_mut(pid)?;
|
#[cfg(baremetal)]
|
||||||
// let available_threads = match process.state {
|
pub fn make_callback_to(
|
||||||
// ProcessState::Ready(x) | ProcessState::Running(x) => x,
|
&mut self,
|
||||||
// ProcessState::Sleeping => 0,
|
pid: PID,
|
||||||
// ProcessState::Free => panic!("process was not allocated"),
|
pc: *const usize,
|
||||||
// ProcessState::Setup(_, _, _) => panic!("process hasn't been set up yet"),
|
irq_no: usize,
|
||||||
// };
|
arg: *mut usize,
|
||||||
// process.state = ProcessState::Running(available_threads);
|
) -> Result<(), xous::Error> {
|
||||||
// process.previous_context = process.current_context;
|
// Get the current process (which was just interrupted) and mark it as
|
||||||
// process.current_context = IRQ_CONTEXT as u8;
|
// "ready to run". If this function is called when the current process
|
||||||
// process.mapping.activate();
|
// isn't running, that means the system has gotten into an invalid
|
||||||
// }
|
// state.
|
||||||
|
{
|
||||||
|
let current_pid = self.current_pid();
|
||||||
|
let mut current = self
|
||||||
|
.get_process_mut(current_pid)
|
||||||
|
.expect("couldn't get current PID");
|
||||||
|
current.state = match current.state {
|
||||||
|
ProcessState::Running(x) => ProcessState::Ready(x | (1 << current.current_thread)),
|
||||||
|
y => panic!("current process was {:?}, not 'Running(_)'", y),
|
||||||
|
};
|
||||||
|
println!("Making PID {} state {:?}", current_pid, current.state);
|
||||||
|
}
|
||||||
|
|
||||||
// // Switch to new process memory space, allowing us to save the context
|
// Get the new process, and ensure that it is in a state where it's fit
|
||||||
// // if necessary.
|
// to run. Again, if the new process isn't fit to run, then the system
|
||||||
|
// is in a very bad state.
|
||||||
|
{
|
||||||
|
let mut process = self.get_process_mut(pid)?;
|
||||||
|
let available_threads = match process.state {
|
||||||
|
ProcessState::Ready(x) | ProcessState::Running(x) => x,
|
||||||
|
ProcessState::Sleeping => 0,
|
||||||
|
ProcessState::Free => panic!("process was not allocated"),
|
||||||
|
ProcessState::Setup(_) | ProcessState::Allocated => panic!("process hasn't been set up yet"),
|
||||||
|
};
|
||||||
|
process.state = ProcessState::Running(available_threads);
|
||||||
|
process.previous_thread = process.current_thread;
|
||||||
|
process.current_thread = arch::process::IRQ_CONTEXT as TID;
|
||||||
|
process.mapping.activate()?;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Switch to new process memory space, allowing us to save the context
|
||||||
|
// if necessary.
|
||||||
// self.pid = pid;
|
// self.pid = pid;
|
||||||
|
|
||||||
// // Invoke the syscall, but use the current stack pointer. When this
|
// Invoke the syscall, but use the current stack pointer. When this
|
||||||
// // function returns, it will jump to the RETURN_FROM_ISR address,
|
// function returns, it will jump to the RETURN_FROM_ISR address,
|
||||||
// // causing an instruction fault and exiting the interrupt.
|
// causing an instruction fault and exiting the interrupt.
|
||||||
// let mut arch_process = ProcessHandle::get();
|
ArchProcess::with_current_mut(|arch_process| {
|
||||||
// let sp = arch_process.current_context().stack_pointer();
|
let sp = arch_process.current_thread().stack_pointer();
|
||||||
|
|
||||||
// // Activate the current context
|
// Activate the current context
|
||||||
// arch_process.set_context(IRQ_CONTEXT);
|
arch_process.set_thread(arch::process::IRQ_CONTEXT).unwrap();
|
||||||
|
|
||||||
// // Construct the new frame
|
// Construct the new frame
|
||||||
// arch::syscall::invoke(
|
arch::syscall::invoke(
|
||||||
// arch_process.current_context(),
|
arch_process.current_thread(),
|
||||||
// pid == 1,
|
pid.get() == 1,
|
||||||
// pc as usize,
|
pc as usize,
|
||||||
// sp,
|
sp,
|
||||||
// RETURN_FROM_ISR,
|
arch::process::RETURN_FROM_ISR,
|
||||||
// &[irq_no, arg as usize],
|
&[irq_no, arg as usize],
|
||||||
// );
|
);
|
||||||
// Ok(())
|
});
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mark the specified context as ready to run. If the thread is Sleeping, mark
|
/// Mark the specified context as ready to run. If the thread is Sleeping, mark
|
||||||
|
|
@ -1081,14 +1092,14 @@ impl SystemServices {
|
||||||
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
|
||||||
.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().unwrap();
|
||||||
Err(e)
|
Err(e)
|
||||||
})?;
|
})?;
|
||||||
src_mapping.activate();
|
src_mapping.activate().unwrap();
|
||||||
|
|
||||||
let mut error = None;
|
let mut error = None;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue