Exemplo n.º 1
0
int test_outProcQ(void) {
    int success = 1;
    pcb_t *p1, *p2, *p3;
    pcbq_t *q;

    initProc();
    q = mkEmptyProcQ();
    p1 = allocPcb();
    p2 = allocPcb();
    p3 = allocPcb();

    success &= outProcQ(NULL, p1) == NULL;
    success &= outProcQ(&q, NULL) == NULL;
    success &= outProcQ(&q, p1) == NULL;
    success &= outProcQ(&q, p2) == NULL;
    success &= outProcQ(&q, p3) == NULL;

    insertProcQ(&q, p1);
    insertProcQ(&q, p2);
    success &= outProcQ(&q, p3) == NULL;
    insertProcQ(&q, p3);
    success &= outProcQ(&q, p3) == p3;
    success &= outProcQ(&q, p1) == p1;
    success &= removeProcQ(&q) == p2;

    return success;
}
Exemplo n.º 2
0
/* Insert of the ProcBLk into the semaphore queue  */
int insertBlocked ( int *semAdd, pcb_t *p ) {
  semd_t *tmp = semd_h;

  /* Find the correct element */
  while( tmp->s_next != NULL && ( ( tmp->s_next )->s_semAdd ) < semAdd ){
    tmp = tmp->s_next;
  }
  
  /* Control if we must create a new semaphore */
  if( tmp->s_next == NULL || ( tmp->s_next )->s_semAdd > semAdd ){
    if( semdFree_h == NULL ){
      return TRUE;
    }
    else{	
      semd_t *add = semdFree_h;
      semdFree_h = semdFree_h->s_next;
      add->s_next = tmp->s_next;	
      tmp->s_next = add;	
      add->s_semAdd = semAdd;
      add->s_procQ = mkEmptyProcQ();
      add->s_procQ = p;
      p->p_next = p;
    }
  }	
  else {
    if ( tmp->s_next->s_semAdd == semAdd ){
      insertProcQ( &((tmp->s_next)->s_procQ ), p);	
    }
  }
  p->p_semAdd = semAdd;
  return FALSE;
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
0
Arquivo: pcb.c Projeto: anaptfox/kaya
/*Initializes the pcbs*/
void initPcbs(){
	static pcb_t pcbs[MAXPROC];
	int i = 0;
	freePcb_tp = mkEmptyProcQ();
	while( i < MAXPROC){
		freePcb(&pcbs[i]);
		i++; 
	}
}
Exemplo n.º 5
0
Arquivo: pcb.c Projeto: anaptfox/kaya
/* removeProcQ takes the pointer to the tail pointer and removes the 
ProcBlk associated with it, then reassigns pointers around the removed ProcBlk*/
pcb_t *removeProcQ(pcb_t **tp){
	/* Case 1: ProcQ is empty*/
	if(emptyProcQ(*tp)){
		return(NULL);
		
	}/* Case 2: Only one ProcBlk in ProcQ*/
	else if((*tp)->p_next == *tp){
		pcb_t *old = (*tp);
		*tp = mkEmptyProcQ();
		return(old);
	}/* Case 3: More than 1 ProcBlk in ProcQ*/
	else{
		pcb_t *old = (*tp)->p_next;
		(*tp)->p_next->p_next->p_prev = *tp;
		(*tp)->p_next = (*tp)->p_next->p_next;
		return(old);
	}
}
Exemplo n.º 6
0
/** Rimuove un semaforo da semdFree_h e lo alloca, inserendolo nella ASL.
*   Restituisce TRUE se semdFree è vuota.
*   Restituisce FALSE se ha successo.
*/
HIDDEN int allocFree(int *semAdd, pcb_t *p){
	/* Alloco un nuovo semaforo per metterlo nell'ASL */
	int result = FALSE;
	semd_t *i = NULL;
	if(semdFree_h != NULL){
		semd_t *alloc = findSemd(semAdd);
		if(alloc==NULL && semdFree_h != NULL){
			alloc = semdFree_h;
        	semdFree_h = semdFree_h -> s_next;
       		alloc -> s_next = NULL;
        	alloc -> s_semAdd = semAdd;
        	alloc -> s_procQ = mkEmptyProcQ();
        	/* Coda vuota  */
        	if(semd_h == NULL){
        		semd_h = alloc;
        	} else {
        		if(alloc->s_semAdd < semd_h->s_semAdd){
					/* Inserimento in testa */
					alloc -> s_next = semd_h;
					semd_h = alloc;
				} else {
					/* Scorro la ASL */
					i = semd_h;
					while(i -> s_next != NULL && alloc->s_semAdd > (i -> s_next)->s_semAdd){
						i = i -> s_next;
					}
					if(i -> s_next == NULL){
						/* Inserimento in coda */
						i -> s_next = alloc;
					} else {
						/* Inserimento prima del semAdd maggiore di alloc */
						alloc -> s_next = i -> s_next;
						i -> s_next = alloc;
					}
				}
        	}
		}
        p -> p_semAdd = semAdd;
        insertProcQ(&(alloc -> s_procQ), p);
    } else {
    	result = TRUE;
    }
    return result;
}
Exemplo n.º 7
0
int test_headProcQ(void) {
    int success = 1;
    pcb_t *p1, *p2;
    pcbq_t *q;

    initProc();
    q = mkEmptyProcQ();
    p1 = allocPcb();
    p2 = allocPcb();

    success &= headProcQ(q) == NULL;
    insertProcQ(&q, p1);
    success &= headProcQ(q) == p1;
    insertProcQ(&q, p2);
    success &= headProcQ(q) == p1;
    outProcQ(&q, p1);
    success &= headProcQ(q) == p2;

    return success;
}
Exemplo n.º 8
0
int test_EmptyProcQ(void) {
    int success = 1;
    pcb_t *p;
    pcbq_t *q;

    initProc();

    success &= emptyProcQ(NULL);

    q = mkEmptyProcQ();
    success &= emptyProcQ(q);

    p = allocPcb();
    insertProcQ(&q, p);
    success &= !emptyProcQ(q);
    success &= getPNext(p) == p;
    removeProcQ(&q);
    success &= emptyProcQ(q);

    return success;
}
Exemplo n.º 9
0
Arquivo: pcb.c Projeto: anaptfox/kaya
/* Remove the ProcBlk pointed to by p from the process queue whose
tail-pointer is pointed to by tp. Update the process queue’s tail
pointer if necessary. If the desired entry is not in the indicated queue
(an error condition), return NULL; otherwise, return p. Note that p
can point to any element of the process queue. */
pcb_t *outProcQ(pcb_t **tp, pcb_t *p){
	/* Case 1: ProcQ is empty.*/
	if(emptyProcQ(*tp)){
		return(NULL);
	} /* Case 2: ProcQ has only 1 ProcBlk*/
	else if((*tp)->p_prev == *tp){
		if(*tp == p){
			pcb_t *outproc = *tp;
			*tp = mkEmptyProcQ();
			return(outproc);
		}else{
			return(NULL);
		}
	}/* Case 3: ProcQ has more than one ProcBlk*/
	else{/*Subcase 1: Removing the ProcBlk pointed to by the tail pointer*/
		if(*tp == p){
			pcb_t *outproc = *tp;
			(*tp)->p_prev->p_next = (*tp)->p_next;
			(*tp)->p_next->p_prev = (*tp)->p_prev;
			*tp = (*tp)->p_prev;
			return(outproc);
		}else{
			pcb_t *index = (*tp)->p_next;
			while(index != *tp){/*Subcase 2: Removing the head*/
				if(p == index && index == (*tp)->p_next){
					return removeProcQ(tp);
				}/*Subcas3: Removing a middle ProcBlk*/
				else if(p == index){
					index->p_prev->p_next = index->p_next;
					index->p_next->p_prev = index->p_prev;
					return(index);
				}else{
					index = index->p_next;
				}
			}
			return(NULL);
		}
	}
	
}
Exemplo n.º 10
0
int test_insertProcQ(void) {
    int success = 1;
    int i;
    pcbq_t *q = mkEmptyProcQ();

    initProc();

    success &= emptyProcQ(q);
    insertProcQ(&q, NULL);
    success &= emptyProcQ(q);

    for (i = 0; i < MAXPROCESS; ++i) {
        insertProcQ(&q, allocPcb());
    }

    for (i = 0; i < MAXPROCESS; ++i) {
        success &= removeProcQ(&q) != NULL;
    }
    success &= !removeProcQ(&q);


    return success;
}
Exemplo n.º 11
0
int test_removeProcQ(void) {
    int success = 1;
    pcb_t *p1, *p2;
    pcbq_t *q;

    initProc();
    p1 = allocPcb();
    p2 = allocPcb();
    q = mkEmptyProcQ();

    success &= removeProcQ(NULL) == NULL;

    insertProcQ(&q, p1);
    success &= !emptyProcQ(q);
    success &= removeProcQ(&q) == p1;
    success &= emptyProcQ(q);

    insertProcQ(&q, p1);
    insertProcQ(&q, p2);
    success &= removeProcQ(&q) == p1;
    success &= removeProcQ(&q) == p2;

    return success;
}
Exemplo n.º 12
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;

}
Exemplo n.º 13
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;
}