Kernel: getproc() should not enable interrupts if it is called from
authorWill Sowerbutts <will@sowerbutts.com>
Tue, 13 Jan 2015 20:28:19 +0000 (20:28 +0000)
committerWill Sowerbutts <will@sowerbutts.com>
Tue, 13 Jan 2015 20:49:16 +0000 (20:49 +0000)
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

index 46aa312..dab5047 100644 (file)
@@ -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();
                }
        }