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()
Example #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
}
void Kernel(tf_t *tf_p) // kernel begins its control upon/after interrupt
{
   int pid, sid;

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

   switch(tf_p->intr_id)
   {
      case TIMER_INTR:
         TimerISR(); // service the simulated timer interrupt
         break;
      case GETPID_INTR:
         tf_p->eax = cur_pid;
         break;
      case SLEEP_INTR:
         SleepISR();
         break;
      case SPAWN_INTR:
         if(EmptyQ(&avail_q)) {
            cons_printf("No more processes\n");
            tf_p->eax = -1;
         }
         else {
            pid = DeQ(&avail_q);
            pcbs[pid].state = READY;
            SpawnISR(pid, (func_ptr_t) tf_p->eax);
            tf_p->eax = pid;
         }
         break;
      case SEMINIT_INTR:
         sid = SemInitISR(tf_p->eax);
         tf_p->eax = sid;
         break;   
      case SEMWAIT_INTR:
         SemWaitISR();
         break;
      case SEMPOST_INTR:
         SemPostISR();
         break;      
   }

   
   Scheduler();                // find same/new process to run
   Loader(pcbs[cur_pid].tf_p); // load it to run
} // Kernel()
Example #4
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 SLEEP_INTR:
            SleepISR(tf_p->eax);
            break;
       case GETPID_INTR:
            tf_p->eax = cur_pid;
            break;
   }

   // still handles other keyboard-generated simulated events
   if(cons_kbhit()) // check if a key was pressed (returns non zero)
   {
      char key = cons_getchar(); // get the pressed key

      switch(key) // see if it's one of the following for service
      {
         case 'n':
            if(EmptyQ(&avail_q))
               cons_printf("No more available PIDs!\n");
            else
            {
               SpawnISR(DeQ(&avail_q), SimpleProc);
            }
            break;
         case 'k': KillISR(); break; // non-functional in phase 2
         case 's': ShowStatusISR(); break;
         case 'b': breakpoint(); break; // this stops when run in GDB mode
         case 'q': exit(0);
      } // switch(key)
   } // if(cons_kbhit())

   Scheduler();                // select a process to run
   Loader(pcbs[cur_pid].tf_p); // run the process selected
}
Example #5
0
File: main.c Project: mios16/CPE159
void KernelMain(TF_t *TF_ptr) 
{
	int new_pid, i, pid, len;
	char key;

	pcb[running_pid].TF_ptr = TF_ptr;	//save TF_ptr to PCB of running process
	
	switch(TF_ptr->intr_id)			//switch on TF_ptr->intr_id
	{
		case TIMER_INTR:
				TimerISR();	//call TimerISR()
				outportb(0x20, 0x60);	//dismiss timer event: send PIC with a code
				OS_clock++;
				len = sleep_q.len;

				for(i = 0; i < len; i++)
				{
					pid = DeQ(&sleep_q);
					if(OS_clock == pcb[pid].wake_time)
					{
						EnQ(pid, &ready_q);
						pcb[pid].state = READY;
					}
					else
					{
						EnQ(pid, &sleep_q);
					}	
				}
				break;
		case GETPID_INTR:
				GetPidISR();
				break;
		case SLEEP_INTR:
				SleepISR();
				break;
		default:
				cons_printf("Panic: unknown intr ID (%d)!\n", TF_ptr->intr_id);
				breakpoint();		//fallback to GDB
	}

	//same as simulated, handle keystroke simulated events (s/e/b/x, but no 't' key)
	if(cons_kbhit())
	{
		key = cons_getchar();
		switch(key)
		{
			case 's':
				new_pid = DeQ(&free_q);	//dequeue free_q for a new pid
				if (new_pid == -1)	//if the new pid (is -1) indicates no ID left
				{				
					cons_printf("Panic: no more available process ID left!\n");	//show msg on target PC			
				}
				else
				{
					StartProcISR(new_pid);	//call StartProcISR(new pid) to create new proc
				}
				break;
			case 'e':
				EndProcISR();	//call EndProcISR() to handle this event
				break;
			case 'b':
				breakpoint();	//call breakpoint(); to go into GDB
				break;
			case 'x':
				exit(0);	//just call exit(0) to quit MyOS.dli
				break;
			default :		// no keys were pressed
				break;
		}
	}
	Scheduler();				//call scheduler() to process to load/run if needed
	LoadRun(pcb[running_pid].TF_ptr);	//call LoadRun(pcb[running_pid].TF_ptr) to load/run selected proc
}
Example #6
0
File: main.c Project: mios16/CPE159
void KernelMain(TF_t *TF_ptr) 
{
	int new_pid, i, pid, len;	

	pcb[running_pid].TF_ptr = TF_ptr;	//save TF_ptr to PCB of running process
	
	switch(TF_ptr->intr_id)			//switch on TF_ptr->intr_id
	{
		case TIMER_INTR:
				TimerISR();	//call TimerISR()
				outportb(0x20, 0x60);	//dismiss timer event: send PIC with a code
				OS_clock++;
				len = sleep_q.len;

				for(i = 0; i < len; i++)
				{
					pid = DeQ(&sleep_q);
					if(OS_clock == pcb[pid].wake_time)
					{
						EnQ(pid, &ready_q);
						pcb[pid].state = READY;
					}
					else
					{
						EnQ(pid, &sleep_q);
					}	
				}
				break;
		case GETPID_INTR:
				GetPidISR();
				break;
		case SLEEP_INTR:
				SleepISR();
				break;
		//phase 3 new switch() cases		
		case STARTPROC_INTR:
				new_pid = DeQ(&free_q);	//dequeue free_q for a new pid
				if (new_pid == -1)	//indicates no ID left
				{				
					cons_printf("Panic: no more available process ID left!\n");	//show msg on target PC			
				}
				else
				{
					StartProcISR(new_pid, TF_ptr->eax);//create new proc
				}
				break;
		case SEMGET_INTR:
				SemGetISR(TF_ptr->eax);
				break;
		case SEMWAIT_INTR:
				SemWaitISR(TF_ptr->eax);
				break;
		case SEMPOST_INTR:
				SemPostISR(TF_ptr->eax);
				break;
		//phase 4
		case MSGSND_INTR:
				MsgSndISR(TF_ptr->eax);	//Check if parameter needed*********
				break;
		case MSGRCV_INTR:
				MsgRcvISR(TF_ptr->eax);
				break;
		default:
				cons_printf("Panic: unknown intr ID (%d)!\n", TF_ptr->intr_id);
				breakpoint();		//fallback to GDB
	}

	Scheduler();				//call scheduler() to process to load/run if needed
	LoadRun(pcb[running_pid].TF_ptr);	//call LoadRun(pcb[running_pid].TF_ptr) to load/run selected proc
}