#include "system.h"

/* This procedure is called when a timer interrupt occurs. */
void TimerInterruptHandler(void) {

  struct SaveArea *savearea;

  if (current_process > 0) {	/* was there a running process */
    /* Save the processor state of the system caller. The
       dispatcher will later use this to restart the processes. */
    savearea = &(pd[current_process].sa);
    asm {
      /* processes ia and psw are saved in iia and ipsw */
      store iia, savearea+0;
      store ipsw, savearea+4;
      /* save the base and bound registers */
      store base, savearea+8;
      store base, savearea+12;
      /* save all the general registers */
      storeall savearea+16;
      /* set up the system stack */
      load SystemStack + SYSTEM_STACK_SIZE, r30;
    }
    pd[current_process].timeLeft = 0;
    pd[current_process].state = READY;

  } 
  /* the processor was idle waiting for an interrupt and
     so there is no current process to save the state of */

  /* pick another process to run (it could be the same one) */
  Dispatcher();
}
    
    

