예제 #1
0
int main()
{
	pcb_t *init;
	int i;

	/* Populate the processor state areas into the ROM Reserved Frame */
	populateArea(SYSBK_NEWAREA,		(memaddr) sysBpHandler);	/* SYS/BP Exception Handling */
	populateArea(PGMTRAP_NEWAREA,	(memaddr) pgmTrapHandler);	/* PgmTrap Exception Handling */
	populateArea(INT_NEWAREA,		(memaddr) intHandler);		/* Interrupt Exception Handling */
	populateArea(TLB_NEWAREA,		(memaddr) tlbHandler);		/* TLB Exception Handling */

	/* Initialize data structures */
	initPcbs();
	initASL();
	
	/* Initialize global variables */
	ReadyQueue = mkEmptyProcQ();
	CurrentProcess = NULL;
	ProcessCount = SoftBlockCount = TimerTick = PseudoClock = 0;
	
	/* Initialize device semaphores */
	for (i = 0; i < DEV_PER_INT; i++)
		Semaphore.disk[i] =
		Semaphore.tape[i] =
		Semaphore.network[i] =
		Semaphore.printer[i] =
		Semaphore.terminalR[i] =
		Semaphore.terminalT[i] = 0;

	/* Initialize init method */
	if (!(init = allocPcb()))
		PANIC(); /* Anomaly */
	
	/* Enable interrupts; enable Kernel-Mode; disable Virtual Memory */
	init->p_s.CP15_Control &= ~(0x1);
	init->p_s.cpsr =  STATUS_SYS_MODE | STATUS_ALL_INT_ENABLE(init->p_s.cpsr);
	
	/* Initialize Stack Pointer */
	init->p_s.sp = RAM_TOP - BUS_REG_RAM_SIZE;
	
	/* Initialize Program Counter with the test process */
	init->p_s.pc = (memaddr) test;

	/* Insert init in ProcQ */
	insertProcQ(&ReadyQueue, init);
	
	/* Initialize Process Id */
	ProcessCount++;

	/* Start the timer tick */
	StartTimerTick = getTODLO();
	/* Call the scheduler */
	scheduler();

	/* Anomaly */
	PANIC();
	return 0;
}
예제 #2
0
파일: main.c 프로젝트: gorghino/so1213
/*Entry point del sistema. Main() inizializza e popola le NewOldArea della ROM e le NewOldArea delle CPU > 0
	Inizializza le strutture dati di fase1, i semafori dei device e chiama lo scheduler*/
int main(){
	int i = 0;

	/*Init NewOldArea della ROM*/
	initNewOldArea((state_t *)INT_NEWAREA, (memaddr) interruptHandler, 0);
	initNewOldArea((state_t *)TLB_NEWAREA, (memaddr)tlbHandler, 0);
	initNewOldArea((state_t *)PGMTRAP_NEWAREA, (memaddr) trapHandler, 0);
	initNewOldArea((state_t *)SYSBK_NEWAREA, (memaddr) syscallHandler, 0);
	
	/*Init NewOldArea delle CPU > 0.*/
    for (i=1; i<GET_NCPU;i++){
    	initNewOldArea(&new_old_areas[i][INT_NEWAREA_INDEX], (memaddr) interruptHandler, i);
    	initNewOldArea(&new_old_areas[i][TLB_NEWAREA_INDEX], (memaddr) tlbHandler, i);
    	initNewOldArea(&new_old_areas[i][PGMTRAP_NEWAREA_INDEX], (memaddr) trapHandler, i);
    	initNewOldArea(&new_old_areas[i][SYSBK_NEWAREA_INDEX], (memaddr) syscallHandler, i);
    }

    /*Inizializzo le strutture dati di fase1*/
    initPcbs();
    initASL();

    /*Inizializzo tutte le variabili del nucleo: Process Count, Soft-block Count, Ready Queues, and Current Process.*/
	for (i=0; i<GET_NCPU; i++){
		process_count[i] = 0; /*Counter processi attivi*/  	
    	ready_queue[i] = NULL; /*Coda dei processi in stato ready*/
    	current_process[i] = NULL; /*Puntatore al processo in esecuzione*/
    }
    softBlock_count = 0; /*Contatore processi in stato wait*/

    /*Inizializzo i semafori mantenuti dal nucleo
    	Vengono impostati a 0 i semafori dei device (uno per device), due per ogni terminal (scrittura/lettura) e
    	il semaforo dello pseudoClock.*/
	for(i=0;i<DEV_PER_INT;i++){
		sem_disk[i] = 0;
		sem_tape[i] = 0;
		sem_ethernet[i] = 0;
		sem_printer[i] = 0;
		sem_terminal_read[i] = 0;
		sem_terminal_write[i] = 0;
	}
	pseudo_clock = 0; 

	/*Inizializzo i semafori delle CAS:
		0-MAX_CPUS: Scheduler
		MAX_CPUS+1: PV
		MAX_CPUS+2: PseudoClock*/

	for (i=0;i<NUM_SEM_CUSTOM; i++)
		semArray[i] = 1;

	/*Inizializzo lo scheduler*/
	init();

	/*Error: Non uscirò mai dallo scheduler*/
	PANIC();
	return -1;
}
예제 #3
0
int main() {
	initExceptionHandlers();
	initPcbs();
	initASL();
	// Initialize device semaphores
	memset(&semaphores, 0, sizeof(semaphores));
	// Create init and start the scheduler
	pcb_t *init;
	init = makeInit();
	init->p_pid = 1;
	boot_start=getTODLO();
	schedStart(init);
	return 0;
}
예제 #4
0
파일: main.c 프로젝트: MarcoDN/ProgPK
int main() {

	int i,j;

	/* Setting up CPU0 new areas in ROM. */
	populateArea((state_t *)INT_NEWAREA,(memaddr)intHandler,0);
	populateArea((state_t *)TLB_NEWAREA,(memaddr)tlbHandler,0);
	populateArea((state_t *)PGMTRAP_NEWAREA,(memaddr)trapHandler,0);
	populateArea((state_t *)SYSBK_NEWAREA,(memaddr)sysHandler,0);

	/* Setting up CPU-n (with n >= 1) new areas in RAM, in a defined array of state_t pointers. */
	for (i = 1; i < NUM_CPU; i++)
		for (j = 0; j < 4; j++)

			switch (j) {

			case 0: populateArea(&new_old_areas[i][1],(memaddr)intHandler,i); break;
			case 1: populateArea(&new_old_areas[i][3],(memaddr)tlbHandler,i); break;
			case 2: populateArea(&new_old_areas[i][5],(memaddr)trapHandler,i); break;
			case 3: populateArea(&new_old_areas[i][7],(memaddr)sysHandler,i); break;

			}

	/* Initialization of underlaying data structures. */
	initPcbs();
	initASL();

	/* Inizialization of device semaphores. TODO */

	if ((psClock_timer = getSemd(0)) != NULL)
		psClock_timer -> s_value = 0;

	if ((terminalWrite = getSemd(1)) != NULL)
		terminalWrite -> s_value = 0;

	if ((terminalRead = getSemd(2)) != NULL)
		terminalRead -> s_value = 0;

	/* Scheduler initialization process. */
	initScheduler(i);

	return 1;
}
예제 #5
0
int main(){
	int i, j;
	state_t *statep;
	//popolo le aree della ROM
	init_area(INT_NEWAREA, (memaddr) int_handler);
	init_area(TLB_NEWAREA, (memaddr) tlb_handler);
	init_area(PGMTRAP_NEWAREA, (memaddr) trap_handler);
	init_area(SYSBK_NEWAREA, (memaddr) sys_handler);
	//inizializzo le strutture di phase1
	initPcbs();
	initASL();
	//inizializzo le variabili di sistema
	process_count = 0;
	softblock_count = 0;
	//mappa dei process id liberi
	for( i = 0; i < MAXPROC ; i++ ) pid_map[i] = 0;
	//array di puntatori ai processi attivi
	for( i = 0; i < MAXPROC ; i++ ) activeProcesses[i] = NULL;
	//semafori dei device
	for(i = 0; i < MAX_DEVICES; i++) devSem[i] = 0;
    	//registri di stato da conservare dei device
	for(i = 0; i < MAX_DEVICES; i++) devStatus[i] = 0;
	//tempo di gestione degli interrupt
	for(i = 0; i < MAX_DEVICES; i++) interruptTime[i] = 0;

	if( !((first = allocPcb()) && (twiddle = allocPcb()))){
		PANIC();
	}

	processSet( twiddle, (memaddr) idle, PRIO_IDLE);	//il processo idle ha id 1
	
	processSet( first, (memaddr) test, PRIO_NORM );

	current_process = NULL;
	process_count++;
	scheduler();
}
예제 #6
0
int main() {
	int i;

	initPcbs();
	addokbuf("Initialized process control blocks   \n");

	/* Check allocPcb */
	for (i = 0; i < MAXPROC; i++) {
		if ((procp[i] = allocPcb()) == NULL)
			adderrbuf("allocPcb(): unexpected NULL   ");
	}
	if (allocPcb() != NULL) {
		adderrbuf("allocPcb(): allocated more than MAXPROC entries   ");
	}
	addokbuf("allocPcb ok   \n");

	/* return the last 10 entries back to free list */
	for (i = 10; i < MAXPROC; i++)
		freePcb(procp[i]);
	addokbuf("freed 10 entries   \n");

	/* create a 10-element process queue */
	qa = mkEmptyProcQ();
	if (!emptyProcQ(qa)) adderrbuf("emptyProcQ(qa): unexpected FALSE   ");
	addokbuf("Inserting...   \n");
	for (i = 0; i < 10; i++) {
		if ((q = allocPcb()) == NULL)
			adderrbuf("allocPcb(): unexpected NULL while insert   ");
		switch (i) {
			case 0:
				firstproc = q;
				break;
			case 5:
				midproc = q;
				break;
			case 9:
				lastproc = q;
				break;
			default:
				break;
		}
		insertProcQ(&qa, q);
	}
	addokbuf("inserted 10 elements   \n");

	if (emptyProcQ(qa)) adderrbuf("emptyProcQ(qa): unexpected TRUE"   );

	/* Check outProcQ and headProcQ */
	if (headProcQ(qa) != firstproc)
		adderrbuf("headProcQ(qa) failed   ");

	q = outProcQ(&qa, firstproc);
	if ((q == NULL) || (q != firstproc))
		adderrbuf("outProcQ(&qa, firstproc) failed on first entry   ");		
	freePcb(q);

	q = outProcQ(&qa, midproc);
	if (q == NULL || q != midproc)
		adderrbuf("outProcQ(&qa, midproc) failed on middle entry   ");
	freePcb(q);

	if (outProcQ(&qa, procp[0]) != NULL)
		adderrbuf("outProcQ(&qa, procp[0]) failed on nonexistent entry   ");
	addokbuf("outProcQ() ok   \n");

	/* Check if removeProc and insertProc remove in the correct order */
	addokbuf("Removing...   \n");
	for (i = 0; i < 8; i++) {
		if ((q = removeProcQ(&qa)) == NULL)
			adderrbuf("removeProcQ(&qa): unexpected NULL   ");
		freePcb(q);
	}

	if (q != lastproc)
		adderrbuf("removeProcQ(): failed on last entry   ");

	if (removeProcQ(&qa) != NULL)
		adderrbuf("removeProcQ(&qa): removes too many entries   ");

	if (!emptyProcQ(qa))
		adderrbuf("emptyProcQ(qa): unexpected FALSE   ");

	addokbuf("insertProcQ(), removeProcQ() and emptyProcQ() ok   \n");
	addokbuf("process queues module ok      \n");

	addokbuf("checking process trees...\n");

	if (!emptyChild(procp[2]))
		adderrbuf("emptyChild: unexpected FALSE   ");

	/* make procp[1] through procp[9] children of procp[0] */
	addokbuf("Inserting...   \n");
	for (i = 1; i < 10; i++) {
		insertChild(procp[0], procp[i]);
	}
	addokbuf("Inserted 9 children   \n");

	if (emptyChild(procp[0]))
		adderrbuf("emptyChild(procp[0]): unexpected TRUE   ");

	/* Check outChild */
	q = outChild(procp[1]);
	if (q == NULL || q != procp[1])
		adderrbuf("outChild(procp[1]) failed on first child   ");
	q = outChild(procp[4]);
	if (q == NULL || q != procp[4])
		adderrbuf("outChild(procp[4]) failed on middle child   ");
	if (outChild(procp[0]) != NULL)
		adderrbuf("outChild(procp[0]) failed on nonexistent child   ");
	addokbuf("outChild ok   \n");

	/* Check removeChild */
	addokbuf("Removing...   \n");
	for (i = 0; i < 7; i++) {
		if ((q = removeChild(procp[0])) == NULL)
			adderrbuf("removeChild(procp[0]): unexpected NULL   ");
	}

	if (removeChild(procp[0]) != NULL)
		adderrbuf("removeChild(): removes too many children   ");

	if (!emptyChild(procp[0]))
		adderrbuf("emptyChild(procp[0]): unexpected FALSE   ");

	addokbuf("insertChild(), removeChild() and emptyChild() ok   \n");
	addokbuf("process tree module ok      \n");

	for (i = 0; i < 10; i++) 
		freePcb(procp[i]);


	/* check ASL */
	initASL();
	addokbuf("Initialized active semaphore list   \n");

	/* check removeBlocked and insertBlocked */
	addokbuf("insertBlocked() test #1 started  \n");
	for (i = 10; i < MAXPROC; i++) {
		procp[i] = allocPcb();
		if (insertBlocked(&sem[i], procp[i]))
			adderrbuf("insertBlocked() test#1: unexpected TRUE   ");
	}
	addokbuf("insertBlocked() test #2 started  \n");
	for (i = 0; i < 10; i++) {
		procp[i] = allocPcb();
		if (insertBlocked(&sem[i], procp[i]))
			adderrbuf("insertBlocked() test #2: unexpected TRUE   ");
	}

	/* check if semaphore descriptors are returned to free list */
	p = removeBlocked(&sem[11]);
	if (insertBlocked(&sem[11],p))
		adderrbuf("removeBlocked(): fails to return to free list   ");

	if (insertBlocked(&onesem, procp[9]) == FALSE)
		adderrbuf("insertBlocked(): inserted more than MAXPROC   ");

	addokbuf("removeBlocked() test started   \n");
	for (i = 10; i< MAXPROC; i++) {
		q = removeBlocked(&sem[i]);
		if (q == NULL)
			adderrbuf("removeBlocked(): wouldn't remove   ");
		if (q != procp[i])
			adderrbuf("removeBlocked(): removed wrong element   ");
		if (insertBlocked(&sem[i-10], q))
			adderrbuf("insertBlocked(3): unexpected TRUE   ");
	}
	if (removeBlocked(&sem[11]) != NULL)
		adderrbuf("removeBlocked(): removed nonexistent blocked proc   ");
	addokbuf("insertBlocked() and removeBlocked() ok   \n");

	if (headBlocked(&sem[11]) != NULL)
		adderrbuf("headBlocked(): nonNULL for a nonexistent queue   ");
	if ((q = headBlocked(&sem[9])) == NULL)
		adderrbuf("headBlocked(1): NULL for an existent queue   ");
	if (q != procp[9])
		adderrbuf("headBlocked(1): wrong process returned   ");
	p = outBlocked(q);
	if (p != q)
		adderrbuf("outBlocked(1): couldn't remove from valid queue   ");
	q = headBlocked(&sem[9]);
	if (q == NULL)
		adderrbuf("headBlocked(2): NULL for an existent queue   ");
	if (q != procp[19])
		adderrbuf("headBlocked(2): wrong process returned   ");
	p = outBlocked(q);
	if (p != q)
		adderrbuf("outBlocked(2): couldn't remove from valid queue   ");
	p = outBlocked(q);
	if(c = p)
		addokbuf("saaaaaas \n");
	if (p != NULL)
		adderrbuf("outBlocked(): removed same process twice.");
	if (headBlocked(&sem[9]) != NULL)
		adderrbuf("out/headBlocked: unexpected nonempty queue   ");
	addokbuf("headBlocked() and outBlocked() ok   \n");
	addokbuf("ASL module ok   \n");
	addokbuf("So Long and Thanks for All the Fish\n");

	return 0;

}
예제 #7
0
int main(void)
{
	/************* INIZIALIZZAZIONE DEL SISTEMA */
	/* Inizializzazione del vettore dei lock a PASS */
	initLock();
	/* Inizializzo le new (e old) area di tutte le CPU */
	initAreas(pnew_old_areas, NUM_CPU);
	/* Inizializzo le strutture dati di Phase1 */
	initPcbs();
	initASL();
	/* Inizializzo le strutture dello scheduler */
	initReadyQueues();
	
	
	/************* CARICAMENTO DEI PROCESSI NELLE READY QUEUE */
	
		/* Test phase2 */
		//pcb_t *phase2 = allocPcb();
		//STST(&(phase2->p_s));
		//phase2->p_s.status = getSTATUS();
		//phase2->p_s.pc_epc = phase2->p_s.reg_t9 = (memaddr)p2test;
		//phase2->p_s.reg_sp = PFRAMES_START;
		//addReady(phase2);
		
		/* Test di alcuni processi di prova */
		pcb_t *test1 = allocPcb();
		STST(&(test1->p_s));
		test1->p_s.status = getSTATUS();
		(test1->p_s).pc_epc = (test1->p_s).reg_t9 = (memaddr)print1;
		test1->p_s.reg_sp = PFRAMES_START;
		addReady(test1);
		
		/* Test di alcuni processi di prova */
		pcb_t *test2 = allocPcb();
		STST(&(test2->p_s));
		test2->p_s.status = getSTATUS();
		test2->p_s.pc_epc = test2->p_s.reg_t9 = (memaddr)print2;
		test2->p_s.reg_sp = test1->p_s.reg_sp-FRAME_SIZE;
		addReady(test2);
		
		pcb_t *test3 = allocPcb();
		STST(&(test3->p_s));
		test3->p_s.status = getSTATUS();
		test3->p_s.pc_epc = test3->p_s.reg_t9 = (memaddr)print3;
		test3->p_s.reg_sp = test2->p_s.reg_sp-FRAME_SIZE;
		addReady(test3);

		pcb_t *test4 = allocPcb();
		STST(&(test4->p_s));
		test4->p_s.status = getSTATUS();
		test4->p_s.pc_epc = test4->p_s.reg_t9 = (memaddr)print4;
		test4->p_s.reg_sp = test3->p_s.reg_sp-FRAME_SIZE;
		addReady(test4);
	
	/************* ESECUZIONE DEI PROCESSI */
	/* Inizializzo la Interrupt Routing Table dinamica */
	/* initIRT(); */
	/* Inizializzo le altre CPU e faccio partire lo scheduler */
	initCpus();
	return 0;
}
예제 #8
0
/**
  * @brief Inizializzazione del nucleo.
  * @return void.
 */ 
int main(void)
{
	pcb_t *init;
	int i;

	/* Popolazione delle 4 nuove aree nella ROM Reserved Frame */
	
	/*	SYS/BP Exception Handling	*/
	populate(SYSBK_NEWAREA, (memaddr) sysBpHandler);
	
	/*	PgmTrap Exception Handling	*/
	populate(PGMTRAP_NEWAREA, (memaddr) pgmTrapHandler);
	
	/*	TLB Exception Handling		*/
	populate(TLB_NEWAREA, (memaddr) tlbHandler);
	
	/*	Interrupt Exception Handling	*/
	populate(INT_NEWAREA, (memaddr) intHandler);

	/* Inizializzazione delle strutture dati del livello 2 (phase1) */
	initPcbs();
	initSemd();
	
	/* Inizializzazione delle variabili globali */
	mkEmptyProcQ(&readyQueue);
	currentProcess = NULL;
	processCount = softBlockCount = pidCount = 0;
	timerTick = 0;
	
	/* Inizializzazione della tabella dei pcb utilizzati */
	for(i=0; i<MAXPROC; i++)
	{
		pcbused_table[i].pid = 0;
		pcbused_table[i].pcb = NULL;
	}
	
	/* Inizializzazione dei semafori dei device */
	for(i=0; i<DEV_PER_INT; i++)
	{
		sem.disk[i] = 0;
		sem.tape[i] = 0;
		sem.network[i] = 0;
		sem.printer[i] = 0;
		sem.terminalR[i] = 0;
		sem.terminalT[i] = 0;
	}
	
	/* Inizializzazione del semaforo dello pseudo-clock */
	pseudo_clock = 0;
	
	/* Inizializzazione del primo processo (init) */
	/* Se il primo processo (init) non viene creato, PANIC() */
	if((init = allocPcb()) == NULL)
		PANIC();
	
	/* Interrupt attivati e smascherati, Memoria Virtuale spenta, Kernel-Mode attivo */
	init->p_state.status = (init->p_state.status | STATUS_IEp | STATUS_INT_UNMASKED | STATUS_KUc) & ~STATUS_VMp;
	
	/* Il registro SP viene inizializzato a RAMTOP-FRAMESIZE */
	init->p_state.reg_sp = RAMTOP - FRAME_SIZE;
	
	/* PC inizializzato all'indirizzo di test() */
	init->p_state.pc_epc = init->p_state.reg_t9 = (memaddr)test;
	
	/* Il PID impostato per init è 1 */
	pidCount++;
	init->p_pid = pidCount;
	
	/* Aggiorna la tabella dei pcb utilizzati, assegnando il giusto pid e il puntatore al pcb di init */
	pcbused_table[0].pid = init->p_pid;
	pcbused_table[0].pcb = init;

	/* Inserisce init nella coda di processi Ready */
	insertProcQ(&readyQueue, init);
	
	processCount++;
	
	/* Avvio il tempo per il calcolo dello pseudo-clock tick */
	startTimerTick = GET_TODLOW;
	
	scheduler();
	
	return 0;
}
예제 #9
0
int main() {
	int i;

	initPcbs();
	addokbuf("Initialized Process Control Blocks   \n");

	/* Check allocPcb */
	for (i = 0; i < MAXPROC; i++) {
		if ((procp[i] = allocPcb()) == NULL)
			adderrbuf("allocPcb(): unexpected NULL   ");
	}
	
	if (allocPcb() != NULL) {
		adderrbuf(" ERROR: allocPcb(): allocated more than MAXPROC entries   ");
	}
	addokbuf(" allocPcb test OK   \n");

	
	/* Return the last 10 entries back to free list */
	for (i = 10; i < MAXPROC; i++)
          freePcb(procp[i]);
	
	addokbuf(" Added 10 entries to the free PCB list   \n");

	/* Create a 10-element process queue */
	INIT_LIST_HEAD(&qa);
	
	if (!emptyProcQ(&qa)) adderrbuf("ERROR: emptyProcQ(qa): unexpected FALSE   ");
	
	addokbuf("Testing insertProcQ ...   \n");
	
	for (i = 0; i < 10; i++) {
		if ((q = allocPcb()) == NULL)
			adderrbuf("ERROR: allocPcb(): unexpected NULL while insert   ");
		switch (i) {
			case 3:
				q->priority=DEFAULT_PCB_PRIORITY;
				proc = q;
			break;
			case 4:
				q->priority=MAX_PCB_PRIORITY;
				maxproc = q;
				break;	
			case 5:
				q->priority=MIN_PCB_PRIORITY;
				minproc=q;
			break;
			default:
				q->priority=DEFAULT_PCB_PRIORITY;
			break;
		}
		insertProcQ(&qa, q);
	}
	
	addokbuf("Test insertProcQ: OK. Inserted 10 elements \n");
	
	if (emptyProcQ(&qa)) adderrbuf("ERROR: emptyProcQ(qa): unexpected TRUE"   );

	/* Check outProcQ and headProcQ */
	if (headProcQ(&qa) != maxproc)
		adderrbuf("ERROR: headProcQ(qa) failed   ");
	
	/* Removing an element from ProcQ */
	q = outProcQ(&qa, proc);
	if ((q == NULL) || (q != proc))
		adderrbuf("ERROR: outProcQ(&qa, proc) failed to remove the entry   ");		
	freePcb(q);
	
	/* Removing the first element from ProcQ */
	q = removeProcQ(&qa);
	if (q == NULL || q != maxproc)
		adderrbuf("ERROR: removeProcQ(&qa, midproc) failed to remove the elements in the right order   ");
	freePcb(q);

	/* Removing other 7 elements  */
	addokbuf(" Testing removeProcQ ...   \n");
	for (i = 0; i < 7; i++) {
		if ((q = removeProcQ(&qa)) == NULL)
			adderrbuf("removeProcQ(&qa): unexpected NULL   ");
		freePcb(q);
	}
	
	// Removing the last element
	q=removeProcQ(&qa);
	if (q != minproc)
		adderrbuf("ERROR: removeProcQ(): failed on last entry   ");
	freePcb(q);
	
	if (removeProcQ(&qa) != NULL)
		adderrbuf("ERROR: removeProcQ(&qa): removes too many entries   ");

	if (!emptyProcQ(&qa))
		adderrbuf("ERROR: emptyProcQ(qa): unexpected FALSE   ");

	addokbuf(" Test insertProcQ(), removeProcQ() and emptyProcQ(): OK   \n");
	addokbuf(" Test process queues module: OK      \n");

	addokbuf(" Testing process trees...\n");

	if (!emptyChild(procp[2]))
	  adderrbuf("ERROR: emptyChild: unexpected FALSE   ");
	
	/* make procp[1],procp[2],procp[3], procp[7] children of procp[0] */
	addokbuf("Inserting...   \n");
	insertChild(procp[0], procp[1]);
	insertChild(procp[0], procp[2]);
	insertChild(procp[0], procp[3]);
	insertChild(procp[0], procp[7]);
	addokbuf("Inserted 2 children of pcb0  \n");
	
	/* make procp[8],procp[9] children of procp[7] */
	insertChild(procp[7], procp[8]);
	insertChild(procp[7], procp[9]);
	addokbuf("Inserted 2 children of pcb7  \n");
	

	if (emptyChild(procp[0]))
	  adderrbuf("ERROR: emptyChild(procp[0]): unexpected TRUE   ");
	
	if (emptyChild(procp[7]))
		adderrbuf("ERROR: emptyChild(procp[0]): unexpected TRUE   ");

	
	/* Check outChild */
	q = outChild(procp[1]);
	if (q == NULL || q != procp[1])
		adderrbuf("ERROR: outChild(procp[1]) failed ");
	
	q = outChild(procp[8]);
	if (q == NULL || q != procp[8])
		adderrbuf("ERROR: outChild(procp[8]) failed ");
	
	/* Check removeChild */
	q = removeChild(procp[0]);
	if (q == NULL || q != procp[2])
		adderrbuf("ERROR: removeChild(procp[0]) failed ");
	
	q = removeChild(procp[7]);
	if (q == NULL || q != procp[9])
		adderrbuf("ERROR: removeChild(procp[7]) failed ");
	
	q = removeChild(procp[0]);
	if (q == NULL || q != procp[3])
		adderrbuf("ERROR: removeChild(procp[0]) failed ");

	q = removeChild(procp[0]);
	if (q == NULL || q != procp[7])
		adderrbuf("ERROR: removeChild(procp[0]) failed ");
	
	
	if (removeChild(procp[0]) != NULL)
		adderrbuf("ERROR: removeChild(): removes too many children   ");

	if (!emptyChild(procp[0]))
	    adderrbuf("ERROR: emptyChild(procp[0]): unexpected FALSE   ");
	    
	addokbuf("Test: insertChild(), removeChild() and emptyChild() OK   \n");
	addokbuf("Testing process tree module OK      \n");

	 
	freePcb(procp[0]);
	freePcb(procp[1]);
	freePcb(procp[2]);
	freePcb(procp[3]);
	freePcb(procp[4]);
	freePcb(procp[5]);
	freePcb(procp[6]);
	freePcb(procp[7]);
	freePcb(procp[8]);
	freePcb(procp[9]);
	
	
	/* check ASL */
	initASL();
	addokbuf("Initializing active semaphore list   \n");

	/* check removeBlocked and insertBlocked */
	addokbuf(" Test insertBlocked(): test #1 started  \n");
	for (i = 10; i < MAXPROC; i++) {
		procp[i] = allocPcb();
		if (insertBlocked(i, procp[i]))
			adderrbuf("ERROR: insertBlocked() test#1: unexpected TRUE   ");
	}

	addokbuf("Test insertBlocked(): test #2 started  \n");
	for (i = 0; i < 10; i++) {
		procp[i] = allocPcb();
		if (insertBlocked(i, procp[i]))
			adderrbuf("ERROR:insertBlocked() test #2: unexpected TRUE   ");
	}

	/* check if semaphore descriptors are returned to the free list */
	p = removeBlocked(11);
	if (insertBlocked(11,p))
		adderrbuf("ERROR: removeBlocked(): fails to return to free list   ");

	if (insertBlocked(MAXPROC+1, procp[9]) == FALSE)
		adderrbuf("ERROR: insertBlocked(): inserted more than MAXPROC   ");
	
	addokbuf("Test removeBlocked(): test started   \n");
	for (i = 10; i< MAXPROC; i++) {
		q = removeBlocked(i);
		if (q == NULL)
			adderrbuf("ERROR: removeBlocked(): wouldn't remove   ");
		if (q != procp[i])
			adderrbuf("ERROR: removeBlocked(): removed wrong element   ");

	}

	if (removeBlocked(11) != NULL)
		adderrbuf("ERROR: removeBlocked(): removed nonexistent blocked proc   ");
	
	addokbuf("Test: insertBlocked() and removeBlocked() ok   \n");

	if (headBlocked(11) != NULL)
		adderrbuf("ERROR: headBlocked(): nonNULL for a nonexistent queue   ");
	
	if ((q = headBlocked(9)) == NULL)
		adderrbuf("ERROR: headBlocked(1): NULL for an existent queue   ");
	if (q != procp[9])
		adderrbuf("ERROR: headBlocked(1): wrong process returned   ");
	p = outBlocked(q);
	if (p != q)
		adderrbuf("ERROR: outBlocked(1): couldn't remove from valid queue   ");

	/* Creating a 2-layer tree */
	insertChild(procp[0], procp[1]);
	insertChild(procp[0], procp[2]);
	insertChild(procp[0], procp[3]);
	insertChild(procp[3], procp[4]);
	
	/* Testing outChildBlocked */
	outChildBlocked(procp[0]);
	
	if (headBlocked(0) != NULL)
		adderrbuf("ERROR: outChildBlocked(): nonNULL for a nonexistent queue (0)  ");
	if (headBlocked(1) != NULL)
		adderrbuf("ERROR: outChildBlocked(): nonNULL for a nonexistent queue (1)  ");
	if (headBlocked(2) != NULL)
		adderrbuf("ERROR: outChildBlocked(): nonNULL for a nonexistent queue  (2) ");
	if (headBlocked(3) != NULL)
		adderrbuf("ERROR: outChildBlocked(): nonNULL for a nonexistent queue (3)  ");
	if (headBlocked(4) != NULL)
			adderrbuf("ERROR: outChildBlocked(): nonNULL for a nonexistent queue (4)  ");	
	if (headBlocked(5) == NULL)
			adderrbuf("ERROR: outChildBlocked(): NULL for an existent queue  (5) ");	
	
	addokbuf("Test headBlocked() and outBlocked(): OK   \n");
	
	addokbuf("ASL module OK   \n");
	addokbuf("So Long and Thanks for All the Fish\n");
  
	return 0;

}