mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +00:00
kernel: remove more warnings
Still haven't run it on real hardware, but this removes more warnings from the system. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
0006d4d99c
commit
ba30b4919d
8 changed files with 61 additions and 84 deletions
7
kernel/.vscode/settings.json
vendored
7
kernel/.vscode/settings.json
vendored
|
|
@ -37,5 +37,10 @@
|
||||||
"vmim",
|
"vmim",
|
||||||
"vmip",
|
"vmip",
|
||||||
"xous"
|
"xous"
|
||||||
|
],
|
||||||
|
"rust-analyzer.checkOnSave.allTargets": false,
|
||||||
|
"rust-analyzer.checkOnSave.extraArgs": [
|
||||||
|
"--target",
|
||||||
|
"riscv32imac-unknown-none-elf"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -436,14 +436,14 @@ pub fn move_page_inner(
|
||||||
*entry = 0;
|
*entry = 0;
|
||||||
unsafe { flush_mmu() };
|
unsafe { flush_mmu() };
|
||||||
|
|
||||||
dest_space.activate();
|
dest_space.activate()?;
|
||||||
let phys = previous_entry >> 10 << 12;
|
let phys = previous_entry >> 10 << 12;
|
||||||
let flags = untranslate_flags(previous_entry);
|
let flags = untranslate_flags(previous_entry);
|
||||||
|
|
||||||
let result = map_page_inner(mm, dest_pid, phys, dest_addr as usize, flags, dest_pid.get() != 1);
|
let result = map_page_inner(mm, dest_pid, phys, dest_addr as usize, flags, dest_pid.get() != 1);
|
||||||
|
|
||||||
// Switch back to the original address space and return
|
// Switch back to the original address space and return
|
||||||
src_space.activate();
|
src_space.activate().unwrap();
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -487,7 +487,7 @@ pub fn lend_page_inner(
|
||||||
*entry = (*entry & !MMUFlags::VALID.bits()) | MMUFlags::S.bits();
|
*entry = (*entry & !MMUFlags::VALID.bits()) | MMUFlags::S.bits();
|
||||||
unsafe { flush_mmu() };
|
unsafe { flush_mmu() };
|
||||||
|
|
||||||
dest_space.activate();
|
dest_space.activate()?;
|
||||||
map_page_inner(
|
map_page_inner(
|
||||||
mm,
|
mm,
|
||||||
dest_pid,
|
dest_pid,
|
||||||
|
|
@ -514,7 +514,7 @@ pub fn lend_page_inner(
|
||||||
);
|
);
|
||||||
unsafe { flush_mmu() };
|
unsafe { flush_mmu() };
|
||||||
|
|
||||||
dest_space.activate();
|
dest_space.activate()?;
|
||||||
map_page_inner(
|
map_page_inner(
|
||||||
mm,
|
mm,
|
||||||
dest_pid,
|
dest_pid,
|
||||||
|
|
@ -526,7 +526,7 @@ pub fn lend_page_inner(
|
||||||
};
|
};
|
||||||
unsafe { flush_mmu() };
|
unsafe { flush_mmu() };
|
||||||
|
|
||||||
src_space.activate();
|
src_space.activate().unwrap();
|
||||||
result.map(|_| phys)
|
result.map(|_| phys)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -549,7 +549,7 @@ pub fn return_page_inner(
|
||||||
*src_entry = 0;
|
*src_entry = 0;
|
||||||
unsafe { flush_mmu() };
|
unsafe { flush_mmu() };
|
||||||
|
|
||||||
dest_space.activate();
|
dest_space.activate()?;
|
||||||
let dest_entry =
|
let dest_entry =
|
||||||
pagetable_entry(dest_addr as usize).expect("page wasn't lent in destination space");
|
pagetable_entry(dest_addr as usize).expect("page wasn't lent in destination space");
|
||||||
if *dest_entry & MMUFlags::S.bits() == 0 {
|
if *dest_entry & MMUFlags::S.bits() == 0 {
|
||||||
|
|
@ -571,7 +571,7 @@ pub fn return_page_inner(
|
||||||
}
|
}
|
||||||
unsafe { flush_mmu() };
|
unsafe { flush_mmu() };
|
||||||
|
|
||||||
src_space.activate();
|
src_space.activate().unwrap();
|
||||||
Ok(phys)
|
Ok(phys)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use crate::arch::mem::PAGE_SIZE;
|
||||||
use crate::services::ProcessInner;
|
use crate::services::ProcessInner;
|
||||||
use xous::{ProcessInit, ThreadInit, PID, TID};
|
use xous::{ProcessInit, ThreadInit, PID, TID};
|
||||||
|
|
||||||
use crate::args::KernelArguments;
|
// use crate::args::KernelArguments;
|
||||||
pub const DEFAULT_STACK_SIZE: usize = 131072;
|
pub const DEFAULT_STACK_SIZE: usize = 131072;
|
||||||
pub const MAX_PROCESS_COUNT: usize = 32;
|
pub const MAX_PROCESS_COUNT: usize = 32;
|
||||||
// pub use crate::arch::mem::DEFAULT_STACK_TOP;
|
// pub use crate::arch::mem::DEFAULT_STACK_TOP;
|
||||||
|
|
@ -15,7 +15,7 @@ pub const MAX_PROCESS_COUNT: usize = 32;
|
||||||
pub const RETURN_FROM_ISR: usize = 0xff80_2000;
|
pub const RETURN_FROM_ISR: usize = 0xff80_2000;
|
||||||
|
|
||||||
/// This is the address a thread will return to when it exits.
|
/// This is the address a thread will return to when it exits.
|
||||||
pub const EXIT_THREAD: usize = 0xff80_3000;
|
const EXIT_THREAD: usize = 0xff80_3000;
|
||||||
pub const IRQ_CONTEXT: usize = 1;
|
pub const IRQ_CONTEXT: usize = 1;
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
|
@ -117,14 +117,14 @@ impl Process {
|
||||||
// })
|
// })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calls the provided function with the current inner process state.
|
// /// Calls the provided function with the current inner process state.
|
||||||
pub fn with_current<F, R>(f: F) -> R
|
// pub fn with_current<F, R>(f: F) -> R
|
||||||
where
|
// where
|
||||||
F: FnOnce(&Process) -> R,
|
// F: FnOnce(&Process) -> R,
|
||||||
{
|
// {
|
||||||
let process = Self::current();
|
// let process = Self::current();
|
||||||
f(&process)
|
// f(&process)
|
||||||
}
|
// }
|
||||||
|
|
||||||
/// Calls the provided function with the current inner process state.
|
/// Calls the provided function with the current inner process state.
|
||||||
pub fn with_current_mut<F, R>(f: F) -> R
|
pub fn with_current_mut<F, R>(f: F) -> R
|
||||||
|
|
@ -235,8 +235,20 @@ impl Process {
|
||||||
process.inner = Default::default();
|
process.inner = Default::default();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setup_thread(&mut self, thread: TID, _setup: ThreadInit) -> Result<(), xous::Error> {
|
pub fn setup_thread(&mut self, new_tid: TID, setup: ThreadInit) -> Result<(), xous::Error> {
|
||||||
todo!();
|
let entrypoint = unsafe { core::mem::transmute::<_, usize>(setup.call) };
|
||||||
|
// Create the new context and set it to run in the new address space.
|
||||||
|
let pid = self.pid.get();
|
||||||
|
let thread = self.thread(new_tid);
|
||||||
|
crate::arch::syscall::invoke(
|
||||||
|
thread,
|
||||||
|
pid == 1,
|
||||||
|
entrypoint,
|
||||||
|
setup.stack.as_ptr() as usize,
|
||||||
|
EXIT_THREAD,
|
||||||
|
&[setup.arg.map(|x| x.get() as usize).unwrap_or_default()],
|
||||||
|
);
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create(pid: PID, init_data: ProcessInit) -> PID {
|
pub fn create(pid: PID, init_data: ProcessInit) -> PID {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ extern "C" {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn invoke(
|
pub fn invoke(
|
||||||
Thread: &mut Thread,
|
thread: &mut Thread,
|
||||||
supervisor: bool,
|
supervisor: bool,
|
||||||
pc: usize,
|
pc: usize,
|
||||||
sp: usize,
|
sp: usize,
|
||||||
|
|
@ -14,13 +14,13 @@ pub fn invoke(
|
||||||
args: &[usize],
|
args: &[usize],
|
||||||
) {
|
) {
|
||||||
set_supervisor(supervisor);
|
set_supervisor(supervisor);
|
||||||
Thread.registers[0] = ret_addr;
|
thread.registers[0] = ret_addr;
|
||||||
Thread.registers[1] = sp;
|
thread.registers[1] = sp;
|
||||||
assert!(args.len() <= 8, "too many arguments to invoke()");
|
assert!(args.len() <= 8, "too many arguments to invoke()");
|
||||||
for (idx, arg) in args.iter().enumerate() {
|
for (idx, arg) in args.iter().enumerate() {
|
||||||
Thread.registers[9 + idx] = *arg;
|
thread.registers[9 + idx] = *arg;
|
||||||
}
|
}
|
||||||
Thread.sepc = pc;
|
thread.sepc = pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_supervisor(supervisor: bool) {
|
fn set_supervisor(supervisor: bool) {
|
||||||
|
|
@ -31,8 +31,8 @@ fn set_supervisor(supervisor: bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resume(supervisor: bool, Thread: &Thread) -> ! {
|
pub fn resume(supervisor: bool, thread: &Thread) -> ! {
|
||||||
sepc::write(Thread.sepc);
|
sepc::write(thread.sepc);
|
||||||
|
|
||||||
// Return to the appropriate CPU mode
|
// Return to the appropriate CPU mode
|
||||||
set_supervisor(supervisor);
|
set_supervisor(supervisor);
|
||||||
|
|
@ -43,5 +43,5 @@ pub fn resume(supervisor: bool, Thread: &Thread) -> ! {
|
||||||
// Thread.registers[1],
|
// Thread.registers[1],
|
||||||
// Thread.sepc,
|
// Thread.sepc,
|
||||||
// );
|
// );
|
||||||
unsafe { _xous_resume_context(Thread.registers.as_ptr()) };
|
unsafe { _xous_resume_context(thread.registers.as_ptr()) };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::args::KernelArguments;
|
use crate::args::KernelArguments;
|
||||||
use core::cell::RefCell;
|
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use core::mem;
|
use core::mem;
|
||||||
use core::slice;
|
use core::slice;
|
||||||
|
|
@ -10,9 +9,6 @@ use crate::arch::process::Process;
|
||||||
|
|
||||||
use xous::{MemoryFlags, MemoryRange, PID};
|
use xous::{MemoryFlags, MemoryRange, PID};
|
||||||
|
|
||||||
#[cfg(not(baremetal))]
|
|
||||||
use std::thread_local;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum ClaimOrRelease {
|
enum ClaimOrRelease {
|
||||||
Claim,
|
Claim,
|
||||||
|
|
@ -63,7 +59,7 @@ impl Default for MemoryManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(baremetal))]
|
#[cfg(not(baremetal))]
|
||||||
thread_local!(static MEMORY_MANAGER: RefCell<MemoryManager> = RefCell::new(MemoryManager::default()));
|
std::thread_local!(static MEMORY_MANAGER: core::cell::RefCell<MemoryManager> = core::cell::RefCell::new(MemoryManager::default()));
|
||||||
|
|
||||||
#[cfg(baremetal)]
|
#[cfg(baremetal)]
|
||||||
static mut MEMORY_MANAGER: MemoryManager = MemoryManager::default_hack();
|
static mut MEMORY_MANAGER: MemoryManager = MemoryManager::default_hack();
|
||||||
|
|
@ -189,11 +185,11 @@ impl MemoryManager {
|
||||||
};
|
};
|
||||||
for o in 0..self.ram_size / PAGE_SIZE {
|
for o in 0..self.ram_size / PAGE_SIZE {
|
||||||
unsafe {
|
unsafe {
|
||||||
if let Some(allocation) = MEMORY_ALLOCATIONS[offset + o] {
|
if let Some(_allocation) = MEMORY_ALLOCATIONS[offset + o] {
|
||||||
println!(
|
println!(
|
||||||
" {:08x} => {}",
|
" {:08x} => {}",
|
||||||
self.ram_size + o * PAGE_SIZE,
|
self.ram_size + o * PAGE_SIZE,
|
||||||
allocation.get()
|
_allocation.get()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -207,14 +203,12 @@ impl MemoryManager {
|
||||||
for region in EXTRA_REGIONS {
|
for region in EXTRA_REGIONS {
|
||||||
println!(" Region {}:", region);
|
println!(" Region {}:", region);
|
||||||
for o in 0..(region.mem_size as usize) / PAGE_SIZE {
|
for o in 0..(region.mem_size as usize) / PAGE_SIZE {
|
||||||
unsafe {
|
if let Some(_allocation) = MEMORY_ALLOCATIONS[offset + o] {
|
||||||
if let Some(allocation) = MEMORY_ALLOCATIONS[offset + o] {
|
println!(
|
||||||
println!(
|
" {:08x} => {}",
|
||||||
" {:08x} => {}",
|
(region.mem_start as usize) + o * PAGE_SIZE,
|
||||||
(region.mem_start as usize) + o * PAGE_SIZE,
|
_allocation.get()
|
||||||
allocation.get()
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
offset += region.mem_size as usize / PAGE_SIZE;
|
offset += region.mem_size as usize / PAGE_SIZE;
|
||||||
|
|
|
||||||
|
|
@ -175,7 +175,7 @@ impl Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(baremetal)]
|
#[cfg(baremetal)]
|
||||||
let mut queue = unsafe {
|
let queue = unsafe {
|
||||||
core::slice::from_raw_parts_mut(
|
core::slice::from_raw_parts_mut(
|
||||||
_backing.as_mut_ptr() as *mut QueuedMessage,
|
_backing.as_mut_ptr() as *mut QueuedMessage,
|
||||||
_backing.len() / mem::size_of::<QueuedMessage>(),
|
_backing.len() / mem::size_of::<QueuedMessage>(),
|
||||||
|
|
|
||||||
|
|
@ -5,30 +5,6 @@ pub use crate::arch::process::Thread;
|
||||||
use crate::mem::MemoryManager;
|
use crate::mem::MemoryManager;
|
||||||
use xous::MemoryRange;
|
use xous::MemoryRange;
|
||||||
|
|
||||||
use core::cell::RefCell;
|
|
||||||
|
|
||||||
// Fake macro to implement "thread local" on baremetal as a simple static variable.
|
|
||||||
// The kernel is single-threaded so it's really just one thread.
|
|
||||||
#[cfg(baremetal)]
|
|
||||||
macro_rules! thread_local {
|
|
||||||
// empty (base case for the recursion)
|
|
||||||
() => {};
|
|
||||||
|
|
||||||
// process multiple declarations
|
|
||||||
($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = $init:expr; $($rest:tt)*) => (
|
|
||||||
$(#[$attr])* $vis static $name: $t = $init;
|
|
||||||
$crate::services::thread_local!($($rest)*);
|
|
||||||
);
|
|
||||||
|
|
||||||
// handle a single declaration
|
|
||||||
($(#[$attr:meta])* $vis:vis static $name:ident: $t:ty = $init:expr) => (
|
|
||||||
$(#[$attr])* $vis static $name: $t = $init;
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(baremetal))]
|
|
||||||
use std::thread_local;
|
|
||||||
|
|
||||||
use crate::filled_array;
|
use crate::filled_array;
|
||||||
use crate::server::Server;
|
use crate::server::Server;
|
||||||
// use core::mem;
|
// use core::mem;
|
||||||
|
|
@ -216,7 +192,7 @@ impl Process {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(baremetal))]
|
#[cfg(not(baremetal))]
|
||||||
thread_local!(static SYSTEM_SERVICES: RefCell<SystemServices> = RefCell::new(SystemServices {
|
std::thread_local!(static SYSTEM_SERVICES: core::cell::RefCell<SystemServices> = core::cell::RefCell::new(SystemServices {
|
||||||
processes: [Process {
|
processes: [Process {
|
||||||
state: ProcessState::Free,
|
state: ProcessState::Free,
|
||||||
ppid: unsafe { PID::new_unchecked(1) },
|
ppid: unsafe { PID::new_unchecked(1) },
|
||||||
|
|
@ -473,6 +449,7 @@ 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
|
// // Get the current process (which was just interrupted) and mark it as
|
||||||
// // "ready to run". If this function is called when the current process
|
// // "ready to run". If this function is called when the current process
|
||||||
|
|
@ -1249,17 +1226,6 @@ impl SystemServices {
|
||||||
|
|
||||||
arch_process.setup_thread(new_tid, thread_init)?;
|
arch_process.setup_thread(new_tid, thread_init)?;
|
||||||
|
|
||||||
// // Create the new context and set it to run in the new address space.
|
|
||||||
// let context = process.context(new_context_nr);
|
|
||||||
// arch::syscall::invoke(
|
|
||||||
// context,
|
|
||||||
// self.pid == 1,
|
|
||||||
// entrypoint.get() as usize,
|
|
||||||
// stack_pointer.get() as usize,
|
|
||||||
// EXIT_THREAD,
|
|
||||||
// &[arg.map(|x| x.get()).unwrap_or_default() as usize],
|
|
||||||
// );
|
|
||||||
|
|
||||||
// println!("KERNEL({}): Created new context {}", pid, new_context_nr);
|
// println!("KERNEL({}): Created new context {}", pid, new_context_nr);
|
||||||
|
|
||||||
// Queue the thread to run
|
// Queue the thread to run
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,10 @@ 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,
|
pub call: fn(data: *const usize) -> usize,
|
||||||
stack: MemoryRange,
|
pub stack: MemoryRange,
|
||||||
arg: Option<MemoryAddress>,
|
pub arg: Option<MemoryAddress>,
|
||||||
name: [u8; 16],
|
pub name: [u8; 16],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ThreadInit {
|
impl ThreadInit {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue