kernel: reflow multiple files' comments

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2020-03-25 14:07:46 +08:00
parent a05258654c
commit a723fb6a02
3 changed files with 54 additions and 35 deletions

View file

@ -83,7 +83,7 @@ impl Uart {
} }
#[cfg(all(not(test), feature = "debug-print"))] #[cfg(all(not(test), feature = "debug-print"))]
pub fn irq(_irq_number: usize, _arg: usize) { pub fn irq(_irq_number: usize, _arg: *mut usize) {
println!( println!(
"Interrupt {}: Key pressed: {}", "Interrupt {}: Key pressed: {}",
_irq_number, _irq_number,

View file

@ -17,9 +17,9 @@ mod args;
mod irq; mod irq;
mod macros; mod macros;
mod mem; mod mem;
mod server;
mod services; mod services;
mod syscall; mod syscall;
mod server;
use mem::MemoryManagerHandle; use mem::MemoryManagerHandle;
use services::SystemServicesHandle; use services::SystemServicesHandle;
@ -110,11 +110,7 @@ pub extern "C" fn main() {
println!("KMAIN: Supervisor mode started..."); println!("KMAIN: Supervisor mode started...");
debug::SUPERVISOR_UART.enable_rx(); debug::SUPERVISOR_UART.enable_rx();
println!("Claiming IRQ 3 via syscall..."); println!("Claiming IRQ 3 via syscall...");
xous::rsyscall(xous::SysCall::ClaimInterrupt( xous::claim_interrupt(3, debug::irq, 0 as *mut usize)
3,
debug::irq as *mut usize,
0 as *mut usize,
))
.expect("Couldn't claim interrupt 3"); .expect("Couldn't claim interrupt 3");
print!("}} "); print!("}} ");
} }
@ -128,6 +124,26 @@ pub extern "C" fn main() {
} }
} }
let child_pids = {
let system_services = SystemServicesHandle::get();
let mut child_count = 0;
for process in system_services.processes {
if process.ppid == 1 {
child_count += 1;
}
}
let mut child_pids = [0; child_count];
let mut idx = 0;
for (process_idx, process) in system_services.processes.enumerate() {
if process.ppid == 1 {
child_pids[idx] = process_idx;
idx += 1;
}
}
child_pids
};
let mut pid = None; let mut pid = None;
loop { loop {
arch::irq::disable_all_irqs(); arch::irq::disable_all_irqs();
@ -137,8 +153,7 @@ pub extern "C" fn main() {
match pid { match pid {
Some(pid) => { Some(pid) => {
println!("Attempting to switch to PID {}", pid); println!("Attempting to switch to PID {}", pid);
xous::rsyscall(xous::SysCall::SwitchTo(pid, 0)) xous::rsyscall(xous::SysCall::SwitchTo(pid, 0)).expect("couldn't switch to pid");
.expect("couldn't switch to pid");
() ()
} }
None => { None => {

View file

@ -169,7 +169,9 @@ static mut SYSTEM_SERVICES: SystemServices = SystemServices {
ppid: 0, ppid: 0,
mapping: arch::mem::DEFAULT_MEMORY_MAPPING, mapping: arch::mem::DEFAULT_MEMORY_MAPPING,
}; MAX_PROCESS_COUNT], }; MAX_PROCESS_COUNT],
servers: filled_array![None; 32], // Note we can't use MAX_SERVER_COUNT here because of how Rust's tokenization works // Note we can't use MAX_SERVER_COUNT here because of how Rust's
// macro tokenization works
servers: filled_array![None; 32],
syscall_stack: [(0, 0), (0, 0), (0, 0)], syscall_stack: [(0, 0), (0, 0), (0, 0)],
syscall_depth: 0, syscall_depth: 0,
}; };
@ -185,9 +187,9 @@ impl core::fmt::Debug for Process {
} }
impl SystemServices { impl SystemServices {
/// Create a new "System Services" object based on the arguments from the kernel. /// Create a new "System Services" object based on the arguments from the
/// These arguments decide where the memory spaces are located, as well as where /// kernel. These arguments decide where the memory spaces are located, as
/// the stack and program counter should initially go. /// well as where the stack and program counter should initially go.
pub fn init(&mut self, base: *const u32, args: &KernelArguments) { pub fn init(&mut self, base: *const u32, args: &KernelArguments) {
// Look through the kernel arguments and create a new process for each. // Look through the kernel arguments and create a new process for each.
let init_offsets = { let init_offsets = {
@ -200,9 +202,9 @@ impl SystemServices {
unsafe { slice::from_raw_parts(base as *const InitialProcess, init_count) } unsafe { slice::from_raw_parts(base as *const InitialProcess, init_count) }
}; };
// Copy over the initial process list. The pid is encoded in the SATP value // Copy over the initial process list. The pid is encoded in the SATP
// from the bootloader. For each process, translate it from a raw KernelArguments // value from the bootloader. For each process, translate it from a raw
// value to a SystemServices Process value. // KernelArguments value to a SystemServices Process value.
for init in init_offsets.iter() { for init in init_offsets.iter() {
let pid = (init.satp >> 22) & ((1 << 9) - 1); let pid = (init.satp >> 22) & ((1 << 9) - 1);
let ref mut process = self.processes[(pid - 1) as usize]; let ref mut process = self.processes[(pid - 1) as usize];
@ -293,8 +295,8 @@ impl SystemServices {
irq_no: usize, irq_no: usize,
arg: *mut usize, arg: *mut usize,
) -> Result<(), xous::Error> { ) -> Result<(), xous::Error> {
// Get the current process (which was just interrupted) and mark // Get the current process (which was just interrupted) and mark it as
// it as "ready to run". // "ready to run".
{ {
let current_pid = self.current_pid(); let current_pid = self.current_pid();
let mut current = self let mut current = self
@ -308,7 +310,8 @@ impl SystemServices {
current.state = ProcessState::Ready; current.state = ProcessState::Ready;
} }
// Get the new process, and ensure that it is in a state where it's fit to run. // Get the new process, and ensure that it is in a state where it's fit
// to run.
let mut process = self.get_process_mut(pid)?; let mut process = self.get_process_mut(pid)?;
match process.state { match process.state {
ProcessState::Ready | ProcessState::Running | ProcessState::Sleeping => (), ProcessState::Ready | ProcessState::Running | ProcessState::Sleeping => (),
@ -336,8 +339,8 @@ impl SystemServices {
Ok(()) Ok(())
} }
/// Resume the given process, picking up exactly where it left off. /// Resume the given process, picking up exactly where it left off. If the
/// If the process is in the Setup state, set it up and then resume. /// process is in the Setup state, set it up and then resume.
pub fn resume_pid( pub fn resume_pid(
&mut self, &mut self,
pid: PID, pid: PID,
@ -383,7 +386,8 @@ impl SystemServices {
} }
new.state = ProcessState::Running; new.state = ProcessState::Running;
// Mark the previous process as ready to run, since we just switched away // Mark the previous process as ready to run, since we just switched
// away
{ {
// println!( // println!(
// "Marking previous process {} as {:?}", // "Marking previous process {} as {:?}",
@ -405,8 +409,8 @@ impl SystemServices {
Ok(()) Ok(())
} }
/// Allocate a new server ID for this process and return the address. /// Allocate a new server ID for this process and return the address. If the
/// If the server table is full, return an error. /// server table is full, return an error.
pub fn create_server(&mut self, name: usize) -> Result<SID, xous::Error> { pub fn create_server(&mut self, name: usize) -> Result<SID, xous::Error> {
println!("Looking through server list for free server"); println!("Looking through server list for free server");
println!("Server entries are {} bytes long", mem::size_of::<Server>()); println!("Server entries are {} bytes long", mem::size_of::<Server>());
@ -431,8 +435,8 @@ impl SystemServices {
Err(xous::Error::OutOfMemory) Err(xous::Error::OutOfMemory)
} }
/// Allocate a new server ID for this process and return the address. /// Allocate a new server ID for this process and return the address. If the
/// If the server table is full, return an error. /// server table is full, return an error.
pub fn connect_to_server(&mut self, sid: SID) -> Result<CID, xous::Error> { pub fn connect_to_server(&mut self, sid: SID) -> Result<CID, xous::Error> {
// Check to see if we've already connected to this server. // Check to see if we've already connected to this server.
// While doing this, find a free slot in case we haven't // While doing this, find a free slot in case we haven't
@ -440,7 +444,8 @@ impl SystemServices {
let mut slot_idx = None; let mut slot_idx = None;
let mut process = ProcessHandle::get(); let mut process = ProcessHandle::get();
// Look through the connection map for (1) a free slot, and (2) an existing connection // Look through the connection map for (1) a free slot, and (2) an
// existing connection
for (idx, server_idx) in process.inner.connection_map.iter().enumerate() { for (idx, server_idx) in process.inner.connection_map.iter().enumerate() {
// If we find an empty slot, use it // If we find an empty slot, use it
if *server_idx == 0 { if *server_idx == 0 {
@ -502,19 +507,18 @@ impl SystemServices {
} }
} }
/// How many people have checked out the handle object. /// How many people have checked out the handle object. This should be replaced
/// This should be replaced by an AtomicUsize when we get /// by an AtomicUsize when we get multicore support. For now, we can get away
/// multicore support. /// with this since the memory manager should only be accessed in an IRQ
/// For now, we can get away with this since the memory manager /// context.
/// should only be accessed in an IRQ context.
static mut SS_HANDLE_COUNT: usize = 0; static mut SS_HANDLE_COUNT: usize = 0;
pub struct SystemServicesHandle<'a> { pub struct SystemServicesHandle<'a> {
manager: &'a mut SystemServices, manager: &'a mut SystemServices,
} }
/// Wraps the MemoryManager in a safe mutex. Because of this, accesses /// Wraps the MemoryManager in a safe mutex. Because of this, accesses to the
/// to the Memory Manager should only be made during interrupt contexts. /// Memory Manager should only be made during interrupt contexts.
impl<'a> SystemServicesHandle<'a> { impl<'a> SystemServicesHandle<'a> {
/// Get the singleton memory manager. /// Get the singleton memory manager.
pub fn get() -> SystemServicesHandle<'a> { pub fn get() -> SystemServicesHandle<'a> {