Ejemplo n.º 1
0
void scheduler() {

  // Init no longer has children. Needs to close.
  if (jrb_empty(init->children)) {
    SYSHalt();
  }

  if(dll_empty(readyQ)) {
    noop_flag = 1;
    noop();
  } else {
    PCB *process;
    Dllist node;
    Jval registers;
    
    noop_flag = 0;
    process = (PCB *) malloc(sizeof(PCB));
    node = dll_first(readyQ);       // Get next node in queue
    dll_delete_node(node);          // Node in memory. Delete off readyQ
    
    // Get registers from node
    registers = dll_val(node);
    process = (PCB *)jval_v(registers);
    
    // Update current process
    currentProcess = process;
    User_Base = process->base;
    User_Limit = process->limit;
    
    run_user_code(process->registers);
  }
}
Ejemplo n.º 2
0
void
exceptionHandler(ExceptionType which)
{
  int             type, r5, r6, r7, newPC;
  int             buf[NumTotalRegs];

  examine_registers(buf);
  type = buf[4];
  r5 = buf[5];
  r6 = buf[6];
  r7 = buf[7];
  newPC = buf[NextPCReg];
  
  /*
   * for system calls type is in r4, arg1 is in r5, arg2 is in r6, and
   * arg3 is in r7 put result in r2 and don't forget to increment the
   * pc before returning!
   */

  //set current register to buf. 
  setReg(current, buf);

   
  switch (which) {
  case SyscallException:
    /* the numbers for system calls is in <sys/syscall.h> */
    switch (type) {
    case 0:
      /* 0 is our halt system call number */
      DEBUG('e', "Halt initiated by user program\n");
      SYSHalt();
    case SYS_exit:
      /* this is the _exit() system call */
      DEBUG('e', "SYS Exit\n");      
      kt_fork(do_exit,current);
      
      break;
    case SYS_read:
      DEBUG('e', "SYS Read\n");
      kt_fork(do_read,current);
      break;
    case SYS_write:
      DEBUG('e', "SYS Write\n");
      kt_fork(do_write,current); 
      break;
    case SYS_ioctl:
      DEBUG('e',"Sys ioctl\n");
      kt_fork(do_ioctl,current);
      break;
    case SYS_fstat:
      DEBUG('e',"Sys fstat\n");
      kt_fork(do_fstat,current);
      break;
    case SYS_getpagesize:
      DEBUG('e', "Sys getpagesize\n");
      kt_fork(do_getpagesize,current);
      break;
    case SYS_sbrk:
      DEBUG('e',"Sys_sbrk\n");
      kt_fork(do_sbrk,current);
      break;
    case SYS_execve:
      DEBUG('e',"Sys execve\n");
      kt_fork(do_execve,current);
      break;
    case SYS_getpid:
      DEBUG('e',"SYS_getpid\n");
      kt_fork(do_getpid,current);
      break;
    case SYS_fork:
      DEBUG('e', "SYS_fork\n");
      kt_fork(do_fork,current);
      break;
    case SYS_getppid:
      DEBUG('e', "SYS_getppid\n");
      kt_fork(do_getppid,current);
      //SYSHalt();//STUB
      break;
    case SYS_wait:
      DEBUG('e', "SYS_wait\n");
      //SYSHalt();//STUB
      kt_fork(do_wait,current);
      break;
    case SYS_getdtablesize:
      DEBUG('e', "SYS_getdtablesize\n");
      kt_fork(do_getdtablesize,current);
      break;
    case SYS_close:
      DEBUG('e', "SYS_close\n");
      kt_fork(do_close,current);
      break;
    case SYS_pipe:
      DEBUG('e', "SYS_pipe\n");
      kt_fork(do_pipe,current);
      break;
    case SYS_dup:
      DEBUG('e', "SYS_dup\n");
      kt_fork(do_dup,current);
      break;
    case SYS_dup2:
      DEBUG('e', "SYS_dup2\n");
      kt_fork(do_dup2,current);
      break;
    default:
      DEBUG('e', "Unknown system call\n");
      SYSHalt();
      break;
    }
    break;
  case PageFaultException:
    DEBUG('e', "Exception PageFaultException\n");
    break;
  case BusErrorException:
    DEBUG('e', "Exception BusErrorException\n");
    break;
  case AddressErrorException:
    DEBUG('e', "Exception AddressErrorException\n");
    break;
  case OverflowException:
    DEBUG('e', "Exception OverflowException\n");
    break;
  case IllegalInstrException:
    DEBUG('e', "Exception IllegalInstrException\n");
    break;
  default:
    printf("Unexpected user mode exception %d %d\n", which, type);
    exit(1);
  }

  scheduler();
}