//----------------------------------------------------------------------------------------------------// // @func - sched_prio //! @desc //! Pre-emptive strict priority scheduler //! @return //! - Nothing //! @note //! - None //----------------------------------------------------------------------------------------------------// void sched_prio () { int i; signed char ready = -1; // Enqueue only currently running processes. Else, // If PROC_DEAD, no need to enqueue // If PROC_WAIT or PROC_TIMED_WAIT, already enqueued in appropriate wait queue // If PROC_DELAY, is in one of the timer queues // If idle_task, then does not need to enter the queue if (current_process->state == PROC_RUN) { ptable[current_pid].state = PROC_READY; if (current_pid != idle_task_pid) penq (&ready_q[ptable[current_pid].priority], current_pid, 0); } SET_CURRENT_PROCESS (-1); for (i=0; i <= PRIO_LOWEST; i++) { while (ready_q[i].item_count != 0) { pdeq (&ready_q[i], &ready, 0); if (ptable[ready].state == PROC_DEAD) { // Flush out dead processes ready = -1; continue; } else break; } if (ready != -1) break; } if (ready == -1) ready = idle_task_pid; #if 0 DBG_PRINT ("XMK: Scheduler: scheduled pid: "); putnum (ready); DBG_PRINT ("\r\n"); #endif ptable[ready].state = PROC_RUN; SET_CURRENT_PROCESS (ready); }
void init_idle_task (void) { idle_task_pid = proc_create (PRIO_LOWEST); // Idle task (PID 0). ptable[idle_task_pid].state = PROC_RUN; // Idle task assumed to be running as soon as the kernel starts #ifndef PPC_CPU_440 ptable[idle_task_pid].pcontext.regs[CTX_INDEX_MSR] = mfmsr () | XIL_EXCEPTION_NON_CRITICAL; #else // We set MSR[DS] = 1 here, because that is the TLB scheme we use to // separate instruction and data space on the 440. ptable[idle_task_pid].pcontext.regs[CTX_INDEX_MSR] = mfmsr () | XIL_EXCEPTION_NON_CRITICAL | XREG_MSR_TLB_DATA_TS; #endif ptable[idle_task_pid].pcontext.regs[CTX_INDEX_PC] = (unsigned int)idle_task; ptable[idle_task_pid].pcontext.regs[CTX_INDEX_GPR(1)] = mfgpr (1); ptable[idle_task_pid].pcontext.regs[CTX_INDEX_GPR(2)] = mfgpr (2); ptable[idle_task_pid].pcontext.regs[CTX_INDEX_GPR(13)]= mfgpr (13); SET_CURRENT_PROCESS (idle_task_pid); }