From 198c05c4b8411222502a20fb2ea9d9a88837d11a Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Tue, 7 May 2024 00:09:14 -0400 Subject: kernel/amd64: trap: Temporarily disable interrupts Signed-off-by: Ian Moffett --- sys/arch/amd64/amd64/trap.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'sys') diff --git a/sys/arch/amd64/amd64/trap.c b/sys/arch/amd64/amd64/trap.c index be0493f..ddada75 100644 --- a/sys/arch/amd64/amd64/trap.c +++ b/sys/arch/amd64/amd64/trap.c @@ -35,6 +35,9 @@ #include #include #include +#include +#include +#include #include static const char *trap_type[] = { @@ -146,8 +149,32 @@ void trap_handler(struct trapframe *tf) { struct proc *curtd = this_td(); + struct timer sched_tmr; + tmrr_status_t tmrr_s; int s; + /* + * Mask interrupts so we don't get put in a funky + * state as we are dealing with this trap. Then the next + * thing we want to do is fetch the sched timer so we can + * ensure it is running after we unmask the interrupts. + */ + intr_mask(); + tmrr_s = req_timer(TIMER_SCHED, &sched_tmr); + if (__unlikely(tmrr_s != TMRR_SUCCESS)) { + trap_print(tf); + panic("Could not fetch TIMER_SCHED (tmrr_s=0x%x)\n", tmrr_s); + } + + /* + * We should be able to perform a usec oneshot but + * make sure just in case. + */ + if (__unlikely(sched_tmr.oneshot_us == NULL)) { + trap_print(tf); + panic("Timer oneshot_us is NULL!\n"); + } + /* * XXX: Handle NMIs better. For now we just * panic. @@ -177,4 +204,8 @@ trap_handler(struct trapframe *tf) signal_raise(curtd, SIGSEGV); break; } + + /* All good, unmask and start sched timer */ + intr_unmask(); + sched_tmr.oneshot_us(DEFAULT_TIMESLICE_USEC); } -- cgit v1.2.3