kernel: move to allow hosted init

This prepares for new calls to init SystemServices and the MemoryManager
so that they can be initialized with something other than a
KernelArguments struct.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2020-06-03 18:28:22 +08:00
parent 322e2e7804
commit 21c46de60e
11 changed files with 27 additions and 21 deletions

View file

@ -33,9 +33,9 @@ _start:
// have already been set up by the loader.
jal x1, init
// Call the main function. This function diverges, so
// Call the kmain function. This function diverges, so
// shouldn't ever return.
j main
j kmain
/*

View file

@ -43,17 +43,17 @@ fn handle_panic(_arg: &PanicInfo) -> ! {
pub extern "C" fn init(arg_offset: *const u32, init_offset: *const u32, rpt_offset: *mut u32) {
unsafe { args::KernelArguments::init(arg_offset) };
let args = args::KernelArguments::get();
// Everything needs memory, so the first thing we should do is initialize the memory manager.
{
use mem::MemoryManagerHandle;
let mut memory_manager = MemoryManagerHandle::get();
memory_manager
.init(rpt_offset, &args)
.init_from_memory(rpt_offset, &args)
.expect("couldn't initialize memory manager");
}
// Everything needs memory, so the first thing we should do is initialize the memory manager.
{
let mut system_services = SystemServicesHandle::get();
system_services.init(init_offset, &args);
system_services.init_from_memory(init_offset, &args);
}
// Now that the memory manager is set up, perform any arch-specific initializations.
@ -90,9 +90,8 @@ fn next_pid_to_run(last_pid: Option<PID>) -> Option<PID> {
None
}
#[cfg_attr(baremetal, no_mangle)]
fn main() {
println!("Hello, world!");
#[no_mangle]
pub extern "C" fn kmain() {
// Either map memory using a syscall, or if we're debugging the syscall
// handler then directly map it.
#[cfg(all(feature = "debug-print", baremetal))]
@ -148,3 +147,10 @@ fn main() {
}
}
}
/// The main entrypoint when run in hosted mode. When running in embedded mode,
/// this function does not exist.
#[cfg(not(baremetal))]
fn main() {
kmain();
}

View file

@ -116,7 +116,7 @@ impl DerefMut for MemoryManagerHandle<'_> {
/// and place it at the usual offset. The MMU will not be enabled yet,
/// as the process entry has not yet been created.
impl MemoryManager {
pub fn init(&mut self, base: *mut u32, args: &KernelArguments) -> Result<(), xous::Error> {
pub fn init_from_memory(&mut self, base: *mut u32, args: &KernelArguments) -> Result<(), xous::Error> {
let mut args_iter = args.iter();
let xarg_def = args_iter.next().expect("mm: no kernel arguments found");
assert!(

View file

@ -130,15 +130,15 @@ impl Server {
Ok(())
}
pub fn print_queue(&self) {
println!(" Q Queue Head: {}", self.queue_head);
println!(" Q Queue Tail: {}", self.queue_tail);
for (_idx, _entry) in self.queue.iter().enumerate() {
if _entry != &QueuedMessage::Empty {
println!(" Q entry[{}]: {:?}", _idx, _entry);
}
}
}
// pub fn print_queue(&self) {
// println!(" Q Queue Head: {}", self.queue_head);
// println!(" Q Queue Tail: {}", self.queue_tail);
// for (_idx, _entry) in self.queue.iter().enumerate() {
// if _entry != &QueuedMessage::Empty {
// println!(" Q entry[{}]: {:?}", _idx, _entry);
// }
// }
// }
/// Convert a `QueuedMesage::WaitingResponse` into `QueuedMessage::Empty`
/// and return the pair. Advance the tail. Note that the `idx` could be

View file

@ -201,7 +201,7 @@ impl SystemServices {
/// Create a new "System Services" object based on the arguments from the
/// kernel. These arguments decide where the memory spaces are located, as
/// well as where the stack and program counter should initially go.
pub fn init(&mut self, base: *const u32, args: &KernelArguments) {
pub fn init_from_memory(&mut self, base: *const u32, args: &KernelArguments) {
// Look through the kernel arguments and create a new process for each.
let init_offsets = {
let mut init_count = 1;

View file

@ -166,9 +166,9 @@ pub fn handle(call: SysCall) -> core::result::Result<xous::Result, xous::Error>
.unwrap_or(Err(xous::Error::ProcessNotFound))
}
SysCall::ReturnToParentI(_pid, _cpuid) => {
let mut ss = SystemServicesHandle::get();
let _ss = SystemServicesHandle::get();
unsafe {
let (current_pid, current_ctx) = crate::arch::irq::take_isr_return_pair()
let (_current_pid, _current_ctx) = crate::arch::irq::take_isr_return_pair()
.expect("couldn't get the isr return pair");
// ss.ready_context(current_pid, current_ctx).unwrap();
let (parent_pid, parent_ctx) = SWITCHTO_CALLER