void Kernel(tf_t *tf_p) // kernel begins its control upon/after interrupt
{
   int pid;

   pcbs[ cur_pid ].tf_p = tf_p; // save for cur_pid which may change

   switch( tf_p->intr_id )
   {
      case TIMER_INTR:
         TimerISR();
         break;
      case IRQ7_INTR:
         IRQ7ISR(); // service parallel printer port event
         break;
      case GETPID_INTR:
         tf_p->eax = cur_pid;
         break;
      case SLEEP_INTR:
         SleepISR();
         break;
      case SPAWN_INTR:
         pid = DeQ( &avail_q ); // get pid and put in ebx can be in Kernel()
         pcbs[ cur_pid ].tf_p->ebx = pid; // child PID, could be -1
         if( pid == -1 ) break; // no more process
         SpawnISR(pid, (func_ptr_t) pcbs[ cur_pid ].tf_p->eax);
         break;
      case SEMINIT_INTR:
         SemInitISR();
         break;
      case SEMWAIT_INTR:
         SemWaitISR(tf_p->eax);
         break;
      case SEMPOST_INTR:
         SemPostISR(tf_p->eax);
         break;
      case MSGSND_INTR:
         MsgSndISR();
         break;
      case MSGRCV_INTR:
         MsgRcvISR();
         break;
      case IRQ3_INTR:	
      case IRQ4_INTR:
         IRQ34ISR();	
         break;
      case FORK_INTR:
         pid = DeQ( &avail_q );
         ForkISR(pid);
         pcbs[ cur_pid ].tf_p->ebx = pid;
         break;
      case WAIT_INTR: //cons_printf("Wait Intr\n");
         WaitISR(); 
         break;
      case EXIT_INTR: //cons_printf("Exit Intr\n");
         ExitISR();
         break;
   }
   Scheduler();                  // find same/new process to run
   Loader(pcbs[ cur_pid ].tf_p); // load it to run
} // Kernel()
Пример #2
0
void Kernel(tf_t *tf_p) // kernel directly enters here when interrupt occurs
{
	// Save "tf_p" to pcbs[cur_pid].tf_p for future resume of process runtime
	pcbs[cur_pid].tf_p = tf_p;

	// tf_p->intr_id tells what intr made CPU get here, pushed in entry.S
	switch(tf_p->intr_id)
	{
		case TIMER_INTR:
			TimerISR(); // this must include dismissal of timer interrupt
			break;
		case IRQ7_INTR:
			IRQ7ISR();
			break;
		case SLEEP_INTR:
			SleepISR(tf_p->eax);
			break;
		case GETPID_INTR:
			tf_p->eax = cur_pid;
			break;
		case SPAWN_INTR:
			if (EmptyQ(&avail_q)) {
				cons_printf("No more available PIDs!\n");
				tf_p->ebx = -1;
			}
			else {
				tf_p->ebx = DeQ(&avail_q);
				SpawnISR((int) tf_p->ebx, (func_ptr_t) tf_p->eax);
			}
			break;
		case SEMINIT_INTR:
			tf_p->ebx = SemInitISR(tf_p->eax);
			break;
		case SEMWAIT_INTR:
			SemWaitISR(tf_p->eax);
			break;
		case SEMPOST_INTR:
			SemPostISR(tf_p->eax);
			break;
		case MSGSND_INTR:
			MsgSndISR();
			break;
		case MSGRCV_INTR:
			MsgRcvISR();
			break;
	}

	Scheduler();                // select a process to run
	Loader(pcbs[cur_pid].tf_p); // run the process selected
}