kernel: implement SetExceptionHandler routine

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2021-08-06 10:03:29 +08:00
parent 76953985fe
commit 5b2ac0df68

View file

@ -672,8 +672,8 @@ pub fn handle_inner(pid: PID, tid: TID, in_irq: bool, call: SysCall) -> SysCallR
}; };
// println!("Done zeroing out"); // println!("Done zeroing out");
} }
for offset in for offset in (range.as_ptr() as usize..(range.as_ptr() as usize + range.len()))
(range.as_ptr() as usize..(range.as_ptr() as usize + range.len())).step_by(PAGE_SIZE) .step_by(PAGE_SIZE)
{ {
// println!("Handing page to user"); // println!("Handing page to user");
crate::arch::mem::hand_page_to_user(offset as *mut u8) crate::arch::mem::hand_page_to_user(offset as *mut u8)
@ -688,10 +688,8 @@ pub fn handle_inner(pid: PID, tid: TID, in_irq: bool, call: SysCall) -> SysCallR
let mut result = Ok(xous_kernel::Result::Ok); let mut result = Ok(xous_kernel::Result::Ok);
let virt = range.as_ptr() as usize; let virt = range.as_ptr() as usize;
let size = range.len(); let size = range.len();
if cfg!(baremetal) { if cfg!(baremetal) && virt & 0xfff != 0 {
if virt & 0xfff != 0 { return Err(xous_kernel::Error::BadAlignment);
return Err(xous_kernel::Error::BadAlignment);
}
} }
for addr in (virt..(virt + size)).step_by(PAGE_SIZE) { for addr in (virt..(virt + size)).step_by(PAGE_SIZE) {
if let Err(e) = mm.unmap_page(addr as *mut usize) { if let Err(e) = mm.unmap_page(addr as *mut usize) {
@ -757,11 +755,8 @@ pub fn handle_inner(pid: PID, tid: TID, in_irq: bool, call: SysCall) -> SysCallR
// "Activating process thread {} in pid {} coming from pid {} thread {}", // "Activating process thread {} in pid {} coming from pid {} thread {}",
// new_context, new_pid, pid, tid // new_context, new_pid, pid, tid
// ); // );
let result = ss ss.activate_process_thread(tid, new_pid, new_context, true)
.activate_process_thread(tid, new_pid, new_context, true) .map(|_ctx| xous_kernel::Result::ResumeProcess)
.map(|_ctx| xous_kernel::Result::ResumeProcess);
// println!("Done activating process thread: {:?}", result);
result
}), }),
SysCall::ClaimInterrupt(no, callback, arg) => { SysCall::ClaimInterrupt(no, callback, arg) => {
interrupt_claim(no, pid as definitions::PID, callback, arg) interrupt_claim(no, pid as definitions::PID, callback, arg)
@ -770,9 +765,9 @@ pub fn handle_inner(pid: PID, tid: TID, in_irq: bool, call: SysCall) -> SysCallR
SysCall::Yield => do_yield(pid, tid), SysCall::Yield => do_yield(pid, tid),
SysCall::ReturnToParent(_pid, _cpuid) => { SysCall::ReturnToParent(_pid, _cpuid) => {
unsafe { unsafe {
SWITCHTO_CALLER.take().map(|(parent_pid, parent_ctx)| { if let Some((parent_pid, parent_ctx)) = SWITCHTO_CALLER.take() {
crate::arch::irq::set_isr_return_pair(parent_pid, parent_ctx) crate::arch::irq::set_isr_return_pair(parent_pid, parent_ctx)
}); }
}; };
Ok(xous_kernel::Result::ResumeProcess) Ok(xous_kernel::Result::ResumeProcess)
} }
@ -814,10 +809,9 @@ pub fn handle_inner(pid: PID, tid: TID, in_irq: bool, call: SysCall) -> SysCallR
ss.create_server(pid) ss.create_server(pid)
.map(|(sid, cid)| xous_kernel::Result::NewServerID(sid, cid)) .map(|(sid, cid)| xous_kernel::Result::NewServerID(sid, cid))
}), }),
SysCall::CreateServerId => SystemServices::with_mut(|ss| { SysCall::CreateServerId => {
ss.create_server_id() SystemServices::with_mut(|ss| ss.create_server_id().map(xous_kernel::Result::ServerID))
.map(|sid| xous_kernel::Result::ServerID(sid)) }
}),
SysCall::TryConnect(sid) => SystemServices::with_mut(|ss| { SysCall::TryConnect(sid) => SystemServices::with_mut(|ss| {
ss.connect_to_server(sid) ss.connect_to_server(sid)
.map(xous_kernel::Result::ConnectionID) .map(xous_kernel::Result::ConnectionID)
@ -886,6 +880,10 @@ pub fn handle_inner(pid: PID, tid: TID, in_irq: bool, call: SysCall) -> SysCallR
ret ret
}) })
} }
SysCall::SetExceptionHandler(pc, sp) => SystemServices::with_mut(|ss| {
ss.set_exception_handler(pid, pc, sp)
.and(Ok(xous_kernel::Result::Ok))
}),
_ => Err(xous_kernel::Error::UnhandledSyscall), _ => Err(xous_kernel::Error::UnhandledSyscall),
} }
} }