mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
kernel: riscv: fix wfi handling for interrupts
Keep interrupts nominally disabled in supervisor mode, and only enable them for a brief period after WFI hits. If an interrupt occurs, then WFI becomes a NOP. The `idle()` function is only called when no more processes are running, which happens when all processes are waiting for an interrupt. Therefore, enable interrupts for a brief period when WFI returns in order to drain all pending interrupts and return to the caller to handle any change in the process table. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
eb4ab4ca35
commit
6e290500db
1 changed files with 15 additions and 1 deletions
|
|
@ -19,7 +19,6 @@ pub fn current_pid() -> PID {
|
|||
|
||||
pub fn init() {
|
||||
unsafe {
|
||||
sstatus::set_sie();
|
||||
sie::set_ssoft();
|
||||
sie::set_sext();
|
||||
}
|
||||
|
|
@ -29,6 +28,21 @@ pub fn init() {
|
|||
/// Put the core to sleep until an interrupt hits. Returns `true`
|
||||
/// to indicate the kernel should not exit.
|
||||
pub fn idle() -> bool {
|
||||
|
||||
// Issue `wfi`. This will return as soon as an external interrupt
|
||||
// is available.
|
||||
unsafe { riscv::asm::wfi() };
|
||||
|
||||
// Enable interrupts temporarily in Supervisor mode, allowing them
|
||||
// to drain. Aside from this brief instance, interrupts are
|
||||
// disabled when running in Supervisor mode.
|
||||
//
|
||||
// These interrupts are handled by userspace, so code execution will
|
||||
// immediately jump to the interrupt handler and return here after
|
||||
// all interrupts have been handled.
|
||||
unsafe {
|
||||
sstatus::set_sie();
|
||||
sstatus::clear_sie();
|
||||
};
|
||||
true
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue