support multiple irq-like contexts with an enum

This commit is contained in:
bunnie 2024-03-08 16:20:20 +08:00
parent 70639214e1
commit 5234127b7b

View file

@ -32,6 +32,13 @@ const MINIELF_FLG_X: u8 = 4;
#[cfg(baremetal)] #[cfg(baremetal)]
const MINIELF_FLG_EHF: u8 = 8; const MINIELF_FLG_EHF: u8 = 8;
#[derive(Debug)]
pub enum CallbackType {
/// args: irq_no, arg
Interrupt(usize, *mut usize),
Swap([usize; 8]),
}
#[derive(Debug, Copy, Clone, PartialEq)] #[derive(Debug, Copy, Clone, PartialEq)]
pub struct ExceptionHandler { pub struct ExceptionHandler {
/// Address (in program space) where the exception handler is /// Address (in program space) where the exception handler is
@ -577,14 +584,14 @@ impl SystemServices {
&mut self, &mut self,
pid: PID, pid: PID,
pc: *const usize, pc: *const usize,
irq_no: usize, cb_type: CallbackType,
arg: *mut usize,
ret_addr: usize,
) -> Result<(), xous_kernel::Error> { ) -> Result<(), xous_kernel::Error> {
// 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
// isn't running, that means the system has gotten into an invalid // isn't running, that means the system has gotten into an invalid
// state. // state.
use core::num::IntErrorKind;
{ {
let current_pid = self.current_pid(); let current_pid = self.current_pid();
let current = self.get_process_mut(current_pid).expect("couldn't get current PID"); let current = self.get_process_mut(current_pid).expect("couldn't get current PID");
@ -620,8 +627,8 @@ impl SystemServices {
#[cfg(feature = "gdb-stub")] #[cfg(feature = "gdb-stub")]
if let ProcessState::Debug(_) = process.state { if let ProcessState::Debug(_) = process.state {
println!( println!(
"Making a callback for IRQ {} to process {:?} which is currently in a debug state!", "Making a callback of type {:?} to process {:?} which is currently in a debug state!",
irq_no, pid cb_type, pid
); );
process.state = ProcessState::DebugIrq(available_threads); process.state = ProcessState::DebugIrq(available_threads);
} else { } else {
@ -661,14 +668,28 @@ impl SystemServices {
arch_process.set_tid(arch::process::IRQ_TID).unwrap(); arch_process.set_tid(arch::process::IRQ_TID).unwrap();
// Construct the new frame // Construct the new frame
arch::syscall::invoke( match cb_type {
arch_process.current_thread_mut(), CallbackType::Interrupt(irq_no, arg) => {
pid.get() == 1, arch::syscall::invoke(
pc as usize, arch_process.current_thread_mut(),
sp, pid.get() == 1,
ret_addr, pc as usize,
&[irq_no, arg as usize], sp,
); arch::process::RETURN_FROM_ISR,
&[irq_no, arg as usize],
);
}
CallbackType::Swap(args) => {
arch::syscall::invoke(
arch_process.current_thread_mut(),
pid.get() == 1,
pc as usize,
sp,
arch::process::RETURN_FROM_SWAPPER,
&args,
);
}
}
}); });
Ok(()) Ok(())
} }