From e33ec11d9287ba4ad5cb59a26c5c87d487410d73 Mon Sep 17 00:00:00 2001 From: Will Sowerbutts Date: Tue, 13 Jan 2015 20:28:19 +0000 Subject: [PATCH] Kernel: getproc() should not enable interrupts if it is called from within an interrupt handler because we cannot handle any interrupts that arrive as a result. Enable interrupts only when no process is ready, which is obviously never the case when we're preempting a process from within a timer interrupt. The kernel will also panic if we're about to enable interrupts in getproc() when we're already handling one. --- Kernel/process.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Kernel/process.c b/Kernel/process.c index 46aa3127..dab50471 100644 --- a/Kernel/process.c +++ b/Kernel/process.c @@ -109,8 +109,6 @@ ptptr __fastcall__ getproc(void) pp->p_page); #endif #endif - /* yes please, interrupts on. */ - ei(); haltafter = getproc_nextp; @@ -133,6 +131,11 @@ ptptr __fastcall__ getproc(void) /* Take a nap: not that it makes much difference to power on most Z80 type devices */ if (getproc_nextp == haltafter) { + /* we have only one interrupt stack so we can't take interrupts */ + if(udata.u_ininterrupt) + panic("getproc: cannot ei"); + /* yes please, interrupts on (WRS: they probably are already on?) */ + ei(); platform_idle(); } } @@ -150,9 +153,6 @@ ptptr __fastcall__ getproc(void) { ptptr p = udata.u_ptab; - /* yes please, interrupts on. */ - ei(); - #ifdef DEBUGREALLYHARD kputs("getproc("); if (udata.u_ininterrupt) @@ -179,6 +179,7 @@ ptptr __fastcall__ getproc(void) default: /* Wait for an I/O operation to let us run, don't run other tasks */ + ei(); platform_idle(); } } -- 2.34.1