Пример #1
0
/**
 * @biref: initialize all processes in the system
 * NOTE: We assume there are only two user processes in the system in this example.
 */
void process_init() 
{
	int i;
	U32 *sp;
  
        /* fill out the initialization table */
	set_test_procs();
	for ( i = 0; i < NUM_TEST_PROCS; i++ ) {
		g_proc_table[i].m_pid = g_test_procs[i].m_pid;
		g_proc_table[i].m_stack_size = g_test_procs[i].m_stack_size;
		g_proc_table[i].mpf_start_pc = g_test_procs[i].mpf_start_pc;
	}
  
	/* initilize exception stack frame (i.e. initial context) for each process */
	for ( i = 0; i < NUM_TEST_PROCS; i++ ) {
		int j;
		(gp_pcbs[i])->m_pid = (g_proc_table[i]).m_pid;
		(gp_pcbs[i])->m_state = NEW;
		
		sp = alloc_stack((g_proc_table[i]).m_stack_size);
		*(--sp)  = INITIAL_xPSR;      // user process initial xPSR  
		*(--sp)  = (U32)((g_proc_table[i]).mpf_start_pc); // PC contains the entry point of the process
		for ( j = 0; j < 6; j++ ) { // R0-R3, R12 are cleared with 0
			*(--sp) = 0x0;
		}
		(gp_pcbs[i])->mp_sp = sp;
	}
}
Пример #2
0
void process_init() {
	int i;
	U32 *sp;

	// Add null process to process table
	g_proc_table[PID_NULL].m_pid = 0;
	g_proc_table[PID_NULL].m_priority = 4;
	g_proc_table[PID_NULL].m_stack_size = USR_SZ_STACK;
	g_proc_table[PID_NULL].mpf_start_pc = &null_process;
  
  // Initialize test process table    
	set_test_procs();

	/* fill out the initialization table */
	for ( i = 0; i < NUM_TEST_PROCS; i++ ) {
		g_proc_table[i+1].m_pid = g_test_procs[i].m_pid;
		g_proc_table[i+1].m_priority = g_test_procs[i].m_priority;
		g_proc_table[i+1].m_stack_size = g_test_procs[i].m_stack_size;
		g_proc_table[i+1].mpf_start_pc = g_test_procs[i].mpf_start_pc;
	}

	/* configure the timer i-process */
	g_proc_table[PID_TIMER_IPROC].m_pid = PID_TIMER_IPROC;
	g_proc_table[PID_TIMER_IPROC].m_priority = HIGH;
	g_proc_table[PID_TIMER_IPROC].m_stack_size = USR_SZ_STACK;
	g_proc_table[PID_TIMER_IPROC].mpf_start_pc = &timer_i_process;

	/* configure the UART i-process */
	g_proc_table[PID_UART_IPROC].m_pid = PID_UART_IPROC;
	g_proc_table[PID_UART_IPROC].m_priority = HIGH;
	g_proc_table[PID_UART_IPROC].m_stack_size = USR_SZ_STACK;
	g_proc_table[PID_UART_IPROC].mpf_start_pc = &uart_i_process;

	/* configure the KCD process */
	g_proc_table[PID_KCD].m_pid = PID_KCD;
	g_proc_table[PID_KCD].m_priority = HIGH;
	g_proc_table[PID_KCD].m_stack_size = USR_SZ_STACK;
	g_proc_table[PID_KCD].mpf_start_pc = &kcd_proc;

	/* configure the CRT process */
	g_proc_table[PID_CRT].m_pid = PID_CRT;
	g_proc_table[PID_CRT].m_priority = HIGH;
	g_proc_table[PID_CRT].m_stack_size = USR_SZ_STACK;
	g_proc_table[PID_CRT].mpf_start_pc = &crt_proc;

	/* configure the Wall Clock process */
	g_proc_table[PID_CLOCK].m_pid = PID_CLOCK;
	g_proc_table[PID_CLOCK].m_priority = HIGH;
	g_proc_table[PID_CLOCK].m_stack_size = USR_SZ_STACK;
	g_proc_table[PID_CLOCK].mpf_start_pc = &wall_clock_proc;
  
	/* initilize exception stack frame (i.e. initial context) for each process */
	for ( i = 0; i < NUM_PROCS; i++ ) {
		int j;
		(gp_pcbs[i])->m_pid = (g_proc_table[i]).m_pid;
		(gp_pcbs[i])->m_state = NEW;
		(gp_pcbs[i])->m_priority = (g_proc_table[i]).m_priority;
		
		init_queue(&(gp_pcbs[i])->msg_queue);
		
		sp = alloc_stack((g_proc_table[i]).m_stack_size); // from memory.c
		*(--sp)  = INITIAL_xPSR;      // user process initial xPSR  
		*(--sp)  = (U32)((g_proc_table[i]).mpf_start_pc); // PC contains the entry point of the process
		for ( j = 0; j < 6; j++ ) { // R0-R3, R12 are cleared with 0
			*(--sp) = 0x0;
		}
		(gp_pcbs[i])->mp_sp = sp;

// #ifdef DEBUG_0  
// 	printf("gp_pcbs[i]->m_pid = 0x%x \n\r", gp_pcbs[i]->m_pid);
// 	printf("gp_pcbs[i]->m_priority = 0x%x \n\r", gp_pcbs[i]->m_priority);
// 	printf("gp_pcbs[i]->m_state = 0x%x \n\r", gp_pcbs[i]->m_state);
// 	printf("gp_pcbs[i]->mp_sp = 0x%x \n\r", gp_pcbs[i]->mp_sp);
// #endif		
	}

	/* Proc Table has been set and PCBs have been initialized, so enqueue the required processes into the ready queue*/
	ready_queue_enqueue(gp_pcbs[PID_NULL]);
	
	/* Enqueue into ready queue after ensuring that these methods are properly defined
		We do this before the test processes so that we can initialize the stack frame for these processes*/
	ready_queue_enqueue(gp_pcbs[PID_KCD]);
	ready_queue_enqueue(gp_pcbs[PID_CRT]);
	ready_queue_enqueue(gp_pcbs[PID_CLOCK]);


	for (i = 0; i<NUM_TEST_PROCS; i++) {
		ready_queue_enqueue(gp_pcbs[i+1]);	// i+1 since process id 0 is the null process
	}


	/*
#ifdef DEBUG_0
	printf("Ready Queue after process init:\n\r");

	for (i = 0; i < NUM_PRIORITIES; i++) {
	    Queue *p_cur_queue = &g_ready_queues[i];
	    PCB *p_cur_pcb = (PCB *)p_cur_queue->first;
	    
	    printf("Priority %d:\n\r", i);
	    
	    while (p_cur_pcb != NULL) {
	        printf("\tPID %d\n\r", p_cur_pcb->m_pid);
	        p_cur_pcb = p_cur_pcb->next;
	    }
	}	
#endif
	*/
}
Пример #3
0
/**
 * @biref: initialize all processes in the system
 * NOTE: We assume there are only two user processes in the system in this example.
 */
void process_init() 
{
	int i;
	int j;
	U32 *sp;
	timeout_queue = NULL;
        /* fill out the initialization table */
	set_test_procs();
	set_stress_test_procs();
	set_user_procs();
	set_system_procs();
	j = 0;
	// User processes
	for ( i = 0; i < NUM_TEST_PROCS; i++ ) {
		addProcTable(j, g_test_procs[i].m_pid, g_test_procs[i].m_stack_size, 
			g_test_procs[i].m_priority, g_test_procs[i].mpf_start_pc);
		j++;
	}
	
	for ( i = 0; i < NUM_USER_PROCS; i++ ) {
		addProcTable(j, g_user_procs[i].m_pid, g_user_procs[i].m_stack_size, 
			g_user_procs[i].m_priority, g_user_procs[i].mpf_start_pc);
		j++;
	}
	
	// Stress test processes
	for ( i = 0; i < NUM_STRESS_TEST_PROCS; i++ ) {
		addProcTable(j, g_stress_test_procs[i].m_pid, g_stress_test_procs[i].m_stack_size, 
			g_stress_test_procs[i].m_priority, g_stress_test_procs[i].mpf_start_pc);
		j++;
	}
	
	// KCD and CRT processes
	for ( i = 0; i < NUM_SYSTEM_PROCS; i++ ) {
		addProcTable(j, g_system_procs[i].m_pid, g_system_procs[i].m_stack_size, 
			g_system_procs[i].m_priority, g_system_procs[i].mpf_start_pc);
		j++;
	}
	
	// NULL process
	addProcTable(j, 0, SYS_SZ_STACK, LOWEST+1, &nullProc);
	j++;
	
	// UART I Process
	addProcTable(j, PID_UART_IPROC, SYS_SZ_STACK, LOWEST+1, &UART_i_Proc);
	j++;
	
	// Timer I Process
	addProcTable(j, PID_TIMER_IPROC, SYS_SZ_STACK, LOWEST+1, &Timer_i_Proc);
  j++;
	
	/* initilize exception stack frame (i.e. initial context) for each process */
	for ( i = 0; i < TOTAL_PROCS; i++ ) {
		int j;
		(gp_pcbs[i])->m_pid = (g_proc_table[i]).m_pid;
		//printf("pid = %d, start = %d\n", (g_proc_table[i]).m_pid, (g_proc_table[i]).mpf_start_pc);
		(gp_pcbs[i])->m_state = NEW;
		(gp_pcbs[i])->m_priority = (g_proc_table[i]).m_priority;
		
		sp = alloc_stack((g_proc_table[i]).m_stack_size);
		*(--sp)  = INITIAL_xPSR;      // user process initial xPSR  
		*(--sp)  = (U32)((g_proc_table[i]).mpf_start_pc); // PC contains the entry point of the process
		for ( j = 0; j < 6; j++ ) { // R0-R3, R12 are cleared with 0
			*(--sp) = 0x0;
		}
		#ifdef DEBUG_0
		printf("stack = 0x%x\n\r", sp);
		#endif
		
		if (!isIProcess(gp_pcbs[i]->m_pid)) {
			pq_push(ready_queue, gp_pcbs[i]);
		}
		
		(gp_pcbs[i])->mp_sp = sp;
	}
}
Пример #4
0
void process_init() {
	U32 *sp;
	int i;
	int j;

	// Initialization table
	set_test_procs();
	for (i = 1; i <= NUM_TEST_PROCS; i++) {
		g_proc_table[i].pid = g_test_procs[i - 1].pid;
		g_proc_table[i].stack_size = g_test_procs[i - 1].stack_size;
		g_proc_table[i].start_pc = g_test_procs[i - 1].start_pc;
		g_proc_table[i].priority = g_test_procs[i - 1].priority;
	}

	i = NUM_TEST_PROCS;
	// User processes
	set_u_procs();
	for (j = 0; j < 5; j++) {
		i++;
		g_proc_table[i].pid = g_u_procs[j].pid;
		g_proc_table[i].stack_size = g_u_procs[j].stack_size;
		g_proc_table[i].start_pc = g_u_procs[j].start_pc;
		g_proc_table[i].priority = g_u_procs[j].priority;
	}

	// System Processes
	set_s_procs();
	for (j = 0; j < 2; j++) {
		i++;
		g_proc_table[i].pid = g_s_procs[j].pid;
		g_proc_table[i].stack_size = g_s_procs[j].stack_size;
		g_proc_table[i].start_pc = g_s_procs[j].start_pc;
		g_proc_table[i].priority = g_s_procs[j].priority;
	}

	// I-Processes
	set_i_procs();
	for (j = 0; j < 2; j++) {
		i++;
		g_proc_table[i].pid = g_i_procs[j].pid;
		g_proc_table[i].stack_size = g_i_procs[j].stack_size;
		g_proc_table[i].start_pc = g_i_procs[j].start_pc;
		g_proc_table[i].priority = g_i_procs[j].priority;
	}

	// Null process
	set_null_proc();

	// Initialize exception stack frame (initial context) for each process
	for (i = 0; i < NUM_PROCS; i++) {
		int j;
		gp_pcbs[i]->id = g_proc_table[i].pid;
		gp_pcbs[i]->state = NEW;

		sp = alloc_stack(g_proc_table[i].stack_size);
		*(--sp) = INITIAL_xPSR;      // user process initial xPSR  
		*(--sp) = (U32)((g_proc_table[i]).start_pc); // PC contains the entry point of the process
		for (j = 0; j < 6; j++) { // R0-R3, R12 are cleared with 0
			*(--sp) = 0x0;
		}
		gp_pcbs[i]->sp = sp;

		if (gp_pcbs[i]->id == PID_KCD) {
			s_kcd = gp_pcbs[i];
		} else if (gp_pcbs[i]->id == PID_CRT) {
			s_crt = gp_pcbs[i];
		} else if (gp_pcbs[i]->id == PID_TIMER_IPROC) {
			i_timer = gp_pcbs[i];
		} else if (gp_pcbs[i]->id == PID_UART_IPROC) {
			i_uart = gp_pcbs[i];
		}

		if (gp_pcbs[i]->id < PID_TIMER_IPROC) {
			// Add to priority queue
			gp_pcbs[i]->priority = g_proc_table[i].priority;
			process_enqueue(gp_pcb_queue, gp_pcbs[i], gp_pcbs[i]->priority);
		}
	}
}