From 85522602eab0074189e9a0f3721c681e972193f4 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Mon, 16 Mar 2020 19:03:10 +0800 Subject: [PATCH] kernel: silence warnings and remove excess prints These prints were used to debug errors in the new process switching architecture. Signed-off-by: Sean Cross --- kernel/src/arch/riscv/irq.rs | 6 ++---- kernel/src/arch/riscv/process.rs | 20 -------------------- kernel/src/arch/riscv/syscall.rs | 12 ++++++------ kernel/src/mem.rs | 14 +------------- kernel/src/services.rs | 20 +++++--------------- kernel/src/syscall.rs | 8 +++++++- 6 files changed, 21 insertions(+), 59 deletions(-) diff --git a/kernel/src/arch/riscv/irq.rs b/kernel/src/arch/riscv/irq.rs index 1988e0ad5..aa6b125e0 100644 --- a/kernel/src/arch/riscv/irq.rs +++ b/kernel/src/arch/riscv/irq.rs @@ -1,7 +1,7 @@ use crate::arch::current_pid; use crate::arch::mem::MemoryMapping; use crate::arch::process::ProcessHandle; -use crate::mem::{MemoryManagerHandle, PAGE_SIZE}; +use crate::mem::MemoryManagerHandle; use crate::services::{ProcessContext, ProcessState, SystemServicesHandle, RETURN_FROM_ISR}; use riscv::register::{scause, sepc, sie, sstatus, stval, vexriscv::sim, vexriscv::sip}; use xous::{SysCall, PID}; @@ -108,6 +108,7 @@ pub extern "C" fn trap_handler( println!("Result: {:?}", response); let mut process = ProcessHandle::get(); + let ctx = process.current_context(); // If we're resuming a process that was previously sleeping, restore the context. // Otherwise, keep the context the same but pass the return values in 8 return @@ -173,7 +174,6 @@ pub extern "C" fn trap_handler( if let Some(previous_pid) = PREVIOUS_PID.take() { // Switch to the previous process' address space. - println!("<<< Resuming previous pid {}", previous_pid); SystemServicesHandle::get() .resume_pid(previous_pid, ProcessState::Ready) .expect("unable to resume previous PID"); @@ -200,10 +200,8 @@ pub extern "C" fn trap_handler( PREVIOUS_PID = Some(pid); } } - println!(">>> HANDLING IRQ {:08x} (current PID: {})", irqs_pending, pid); crate::irq::handle(irqs_pending).expect("Couldn't handle IRQ"); let mut process = ProcessHandle::get(); - println!(">>> returning to pid {}", current_pid()); crate::arch::syscall::resume(current_pid() == 1, process.trap_context()); } } diff --git a/kernel/src/arch/riscv/process.rs b/kernel/src/arch/riscv/process.rs index fee88407a..7bbb8fc85 100644 --- a/kernel/src/arch/riscv/process.rs +++ b/kernel/src/arch/riscv/process.rs @@ -118,13 +118,6 @@ impl ProcessContext { } } -/// How many people have checked out the handle object. -/// This should be replaced by an AtomicUsize when we get -/// multicore support. -/// For now, we can get away with this since the memory manager -/// should only be accessed in an IRQ context. -static mut PROCESS_HANDLE_COUNT: usize = 0; - pub struct ProcessHandle<'a> { process: &'a mut Process, } @@ -134,25 +127,12 @@ pub struct ProcessHandle<'a> { impl<'a> ProcessHandle<'a> { /// Get the singleton Process. pub fn get() -> ProcessHandle<'a> { - let count = unsafe { - PROCESS_HANDLE_COUNT += 1; - PROCESS_HANDLE_COUNT - 1 - }; - // if count != 0 { - // panic!("Multiple users of ProcessHandle!"); - // } ProcessHandle { process: unsafe { &mut *PROCESS }, } } } -impl Drop for ProcessHandle<'_> { - fn drop(&mut self) { - unsafe { PROCESS_HANDLE_COUNT -= 1 }; - } -} - use core::ops::{Deref, DerefMut}; impl Deref for ProcessHandle<'_> { type Target = Process; diff --git a/kernel/src/arch/riscv/syscall.rs b/kernel/src/arch/riscv/syscall.rs index 4ec5f9b0f..764caeb6b 100644 --- a/kernel/src/arch/riscv/syscall.rs +++ b/kernel/src/arch/riscv/syscall.rs @@ -35,11 +35,11 @@ pub fn resume(supervisor: bool, context: &ProcessContext) -> ! { // Return to the appropriate CPU mode set_supervisor(supervisor); - println!( - "Switching to PID {}, SP: {:08x}, PC: {:08x}", - crate::arch::current_pid(), - context.registers[1], - context.sepc, - ); + // println!( + // "Switching to PID {}, SP: {:08x}, PC: {:08x}", + // crate::arch::current_pid(), + // context.registers[1], + // context.sepc, + // ); unsafe { _xous_resume_context(context.registers.as_ptr()) }; } diff --git a/kernel/src/mem.rs b/kernel/src/mem.rs index 0b40fa940..13d30d445 100644 --- a/kernel/src/mem.rs +++ b/kernel/src/mem.rs @@ -160,6 +160,7 @@ impl MemoryManager { Ok(()) } + #[allow(dead_code)] pub fn print_ownership(&self) { println!("Ownership ({} bytes in all):", self.allocations.len()); @@ -207,19 +208,6 @@ impl MemoryManager { } } - unsafe fn bzero(&self, mut sbss: *mut T, ebss: *mut T) - where - T: Copy, - { - use core::ptr; - println!("ZERO: {:08x} - {:08x}", sbss as usize, ebss as usize); - while sbss < ebss { - // NOTE(volatile) to prevent this from being transformed into `memclr` - ptr::write_volatile(sbss, mem::zeroed()); - sbss = sbss.offset(1); - } - } - /// Allocate a single page to the given process. /// DOES NOT ZERO THE PAGE!!! /// This function CANNOT zero the page, as it hasn't been mapped yet. diff --git a/kernel/src/services.rs b/kernel/src/services.rs index d9bfa45ea..701380e32 100644 --- a/kernel/src/services.rs +++ b/kernel/src/services.rs @@ -304,16 +304,6 @@ impl SystemServices { pid as PID } - pub fn current_process(&self) -> Result<&Process, xous::Error> { - let pid = self.current_pid(); - self.get_process(pid) - } - - pub fn current_process_mut(&mut self) -> Result<&mut Process, xous::Error> { - let pid = self.current_pid(); - self.get_process_mut(pid) - } - /// Create a stack frame in the specified process and jump to it. /// 1. Pause the current process and switch to the new one /// 2. Save the process state, if it hasn't already been saved @@ -414,10 +404,10 @@ impl SystemServices { // Mark the previous process as ready to run, since we just switched away { - println!( - "Marking previous process {} as {:?}", - previous_pid, previous_state - ); + // println!( + // "Marking previous process {} as {:?}", + // previous_pid, previous_state + // ); self.get_process_mut(previous_pid) .expect("couldn't get previous pid") .state = previous_state; @@ -436,7 +426,7 @@ impl SystemServices { /// Allocate a new server ID for this process and return the address. /// If the server table is full, return an error. - pub fn create_server(&mut self) -> Result { + pub fn create_server(&mut self, name: usize) -> Result { for entry in self.servers.iter_mut() { if entry.state == ServerState::Free { let pid = self.pid; diff --git a/kernel/src/syscall.rs b/kernel/src/syscall.rs index 2a18f2b4a..ad2ef5352 100644 --- a/kernel/src/syscall.rs +++ b/kernel/src/syscall.rs @@ -1,8 +1,8 @@ use crate::arch; +use crate::arch::process::ProcessHandle; use crate::irq::interrupt_claim; use crate::mem::{MemoryManagerHandle, PAGE_SIZE}; use crate::services::{ProcessState, SystemServicesHandle}; -use crate::arch::process::ProcessHandle; use xous::*; // extern "Rust" { @@ -227,6 +227,12 @@ pub fn handle(call: SysCall) -> xous::Result { .map(|_| xous::Result::ResumeProcess) .unwrap_or(xous::Result::Error(xous::Error::ProcessNotFound)) } + SysCall::CreateServer(name) => { + let mut ss = SystemServicesHandle::get(); + ss.create_server(name) + .map(|x| xous::Result::ServerID(x)) + .unwrap_or_else(|e| xous::Result::Error(e)) + } _ => xous::Result::Error(xous::Error::UnhandledSyscall), } }