mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
kernel: get PID1 running, now working on PID2
Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
10ecacd136
commit
75449f1deb
4 changed files with 28 additions and 20 deletions
|
|
@ -98,7 +98,7 @@ pub extern "C" fn trap_handler(
|
||||||
let response =
|
let response =
|
||||||
crate::syscall::handle(pid, tid, call).unwrap_or_else(|e| xous::Result::Error(e));
|
crate::syscall::handle(pid, tid, call).unwrap_or_else(|e| xous::Result::Error(e));
|
||||||
|
|
||||||
println!("Syscall Result: {:?}", response);
|
// println!("Syscall Result: {:?}", response);
|
||||||
ArchProcess::with_current_mut(|p| {
|
ArchProcess::with_current_mut(|p| {
|
||||||
let thread = p.current_thread();
|
let thread = p.current_thread();
|
||||||
// If we're resuming a process that was previously sleeping, restore the
|
// If we're resuming a process that was previously sleeping, restore the
|
||||||
|
|
@ -107,7 +107,10 @@ pub extern "C" fn trap_handler(
|
||||||
if response == xous::Result::ResumeProcess {
|
if response == xous::Result::ResumeProcess {
|
||||||
crate::arch::syscall::resume(current_pid().get() == 1, thread);
|
crate::arch::syscall::resume(current_pid().get() == 1, thread);
|
||||||
} else {
|
} else {
|
||||||
// println!("Returning to address {:08x}", tid.sepc);
|
println!(
|
||||||
|
"Returning to address {:08x}",
|
||||||
|
ArchProcess::with_current_mut(|p| p.current_thread().sepc)
|
||||||
|
);
|
||||||
unsafe { _xous_syscall_return_result(&response, thread) };
|
unsafe { _xous_syscall_return_result(&response, thread) };
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use core::mem;
|
use core::mem;
|
||||||
static mut PROCESS: *mut ProcessImpl = 0xff80_1000 as *mut ProcessImpl;
|
static mut PROCESS: *mut ProcessImpl = 0xff80_1000 as *mut ProcessImpl;
|
||||||
pub const MAX_THREAD: TID = 31;
|
pub const MAX_THREAD: TID = 31;
|
||||||
pub const INITIAL_TID: TID = 2;
|
pub const INITIAL_TID: TID = 1;
|
||||||
use crate::arch::mem::PAGE_SIZE;
|
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};
|
||||||
|
|
@ -16,25 +16,29 @@ 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.
|
||||||
const EXIT_THREAD: usize = 0xff80_3000;
|
const EXIT_THREAD: usize = 0xff80_3000;
|
||||||
pub const IRQ_CONTEXT: usize = 1;
|
pub const IRQ_THREAD: usize = 0;
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
#[repr(C)]
|
||||||
struct ProcessImpl {
|
struct ProcessImpl {
|
||||||
/// Used by the interrupt handler to calculate offsets
|
/// Used by the interrupt handler to calculate offsets
|
||||||
scratch: usize,
|
scratch: usize,
|
||||||
|
|
||||||
|
/// The currently-active thread for this process
|
||||||
|
current_thread: usize,
|
||||||
|
|
||||||
/// Global parameters used by the operating system
|
/// Global parameters used by the operating system
|
||||||
pub inner: ProcessInner,
|
pub inner: ProcessInner,
|
||||||
|
|
||||||
|
/// Pad everything to 128 bytes, so the Thread slice starts at
|
||||||
|
/// offset 128.
|
||||||
|
_padding: [u32; 14],
|
||||||
|
|
||||||
/// This enables the kernel to keep track of threads in the
|
/// This enables the kernel to keep track of threads in the
|
||||||
/// target process, and know which threads are ready to
|
/// target process, and know which threads are ready to
|
||||||
/// receive messages.
|
/// receive messages.
|
||||||
threads: [Thread; MAX_THREAD],
|
threads: [Thread; MAX_THREAD],
|
||||||
|
|
||||||
/// The currently-active thread for this process
|
|
||||||
current_thread: TID,
|
|
||||||
|
|
||||||
_padding: [u32; 14],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Singleton process table. Each process in the system gets allocated from this table.
|
/// Singleton process table. Each process in the system gets allocated from this table.
|
||||||
|
|
@ -218,15 +222,17 @@ impl Process {
|
||||||
thread + 1 < process.threads.len(),
|
thread + 1 < process.threads.len(),
|
||||||
"tried to init a thread that's out of range"
|
"tried to init a thread that's out of range"
|
||||||
);
|
);
|
||||||
assert!(thread != 1, "tried to init using the irq thread");
|
assert!(thread != IRQ_THREAD, "tried to init using the irq thread");
|
||||||
assert!(thread != 0, "tried to init using a thread of 0");
|
|
||||||
assert!(
|
assert!(
|
||||||
thread == 2,
|
thread == INITIAL_TID,
|
||||||
"tried to init using a thread that wasn't 2. This probably isn't what you want."
|
"tried to init using a thread {} that wasn't {}. This probably isn't what you want.",
|
||||||
|
thread,
|
||||||
|
INITIAL_TID
|
||||||
);
|
);
|
||||||
// By convention, thread 0 is the trap thread. Therefore, thread 1 is
|
// By convention, thread 1 is the trap thread. Therefore, thread 2 is
|
||||||
// the first default thread.
|
// the first default thread. Thread 0 is unused. There is an offset of
|
||||||
process.current_thread = thread;
|
// 1 due to how the interrupt handler functions.
|
||||||
|
process.current_thread = thread + 1;
|
||||||
for thread in process.threads.iter_mut() {
|
for thread in process.threads.iter_mut() {
|
||||||
*thread = Default::default();
|
*thread = Default::default();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,7 @@ use core::panic::PanicInfo;
|
||||||
#[cfg(baremetal)]
|
#[cfg(baremetal)]
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
fn handle_panic(_arg: &PanicInfo) -> ! {
|
fn handle_panic(_arg: &PanicInfo) -> ! {
|
||||||
println!("PANIC in PID {}!", crate::arch::current_pid());
|
println!("PANIC in PID {}: {}", crate::arch::current_pid(), _arg);
|
||||||
println!("Details: {:?}", _arg);
|
|
||||||
loop {
|
loop {
|
||||||
arch::idle();
|
arch::idle();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -156,7 +156,7 @@ impl Process {
|
||||||
/// This process has at least one context that may be run
|
/// This process has at least one context that may be run
|
||||||
pub fn runnable(&self) -> bool {
|
pub fn runnable(&self) -> bool {
|
||||||
match self.state {
|
match self.state {
|
||||||
/*ProcessState::Setup(_) | */ ProcessState::Ready(_) => true,
|
ProcessState::Setup(_) | ProcessState::Ready(_) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -492,7 +492,7 @@ impl SystemServices {
|
||||||
};
|
};
|
||||||
process.state = ProcessState::Running(available_threads);
|
process.state = ProcessState::Running(available_threads);
|
||||||
process.previous_thread = process.current_thread;
|
process.previous_thread = process.current_thread;
|
||||||
process.current_thread = arch::process::IRQ_CONTEXT as TID;
|
process.current_thread = arch::process::IRQ_THREAD;
|
||||||
process.mapping.activate()?;
|
process.mapping.activate()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -507,7 +507,7 @@ impl SystemServices {
|
||||||
let sp = arch_process.current_thread().stack_pointer();
|
let sp = arch_process.current_thread().stack_pointer();
|
||||||
|
|
||||||
// Activate the current context
|
// Activate the current context
|
||||||
arch_process.set_thread(arch::process::IRQ_CONTEXT).unwrap();
|
arch_process.set_thread(arch::process::IRQ_THREAD).unwrap();
|
||||||
|
|
||||||
// Construct the new frame
|
// Construct the new frame
|
||||||
arch::syscall::invoke(
|
arch::syscall::invoke(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue