コード例 #1
0
ファイル: tp1test.c プロジェクト: gnuvince/ift2245
int test_removeBlocked(void) {
    int success = 1;
    semd_t *s1, *s2;
    pcb_t *p1, *p2, *p3;


    initASL();
    initProc();

    s1 = getSema(0); initSemD(&s1, 1);
    s2 = getSema(1); initSemD(&s2, 2);

    p1 = allocPcb();
    p2 = allocPcb();
    p3 = allocPcb();


    insertBlocked(s1, p1);
    insertBlocked(s2, p2);
    insertBlocked(s1, p3);

    success &= removeBlocked(NULL) == NULL;

    success &= getSNext(s1) == s2;
    success &= removeBlocked(s2) == p2;
    success &= getSemdFree() == s2;
    success &= getSNext(s1) == NULL;

    success &= removeBlocked(s1) == p1;
    success &= removeBlocked(s1) == p3;
    success &= getSemdFree() == s1;
    success &= getASL() == NULL;

    return success;
}
コード例 #2
0
ファイル: tp1test.c プロジェクト: gnuvince/ift2245
int test_allocFreeNull(void) {
    int success = 1;
    int i;

    initProc();

    /* Make sure freeing NULL is invalid. */
    freePcb(NULL);
    success &= getFreeProcessCount() == MAXPROCESS;

    /* Make sure you cannot allocate more than MAXPROCESS */
    for (i = 0; i < MAXPROCESS; i++) {
        allocPcb();
    }
    success &= allocPcb() == NULL;
    success &= allocPcb() == NULL;

    initProc();

    /* Make sure an invalid freePcb doesn't alter the state of free
     * processes. */
    allocPcb();
    success &= getFreeProcessCount() == MAXPROCESS - 1;
    freePcb(NULL);
    success &= getFreeProcessCount() == MAXPROCESS - 1;


    return success;
}
コード例 #3
0
ファイル: tp1test.c プロジェクト: gnuvince/ift2245
int test_headBlocked(void) {
    int success = 1;
    semd_t *s1, *s2;
    pcb_t *p1, *p2, *p3;


    initASL();
    initProc();

    s1 = getSema(0); initSemD(&s1, 1);
    s2 = getSema(1); initSemD(&s2, 2);

    p1 = allocPcb();
    p2 = allocPcb();
    p3 = allocPcb();


    success &= headBlocked(NULL) == NULL;
    success &= headBlocked(s1) == NULL;
    success &= headBlocked(s2) == NULL;

    insertBlocked(s1, p1);
    insertBlocked(s2, p2);
    insertBlocked(s1, p3);

    success &= headBlocked(s1) == p1;
    success &= headBlocked(s2) == p2;
    outBlocked(p1);
    success &= headBlocked(s1) == p3;

    return success;
}
コード例 #4
0
ファイル: tp1test.c プロジェクト: gnuvince/ift2245
int test_outChild(void) {
    int success = 1;
    pcb_t *p1, *p2, *p3, *p4, *p5;

    initProc();
    p1 = allocPcb();
    p2 = allocPcb();
    p3 = allocPcb();
    p4 = allocPcb();
    p5 = allocPcb();

    success &= outChild(NULL) == NULL;
    success &= outChild(p1) == NULL;

    insertChild(p1, p2);
    insertChild(p1, p3);
    insertChild(p3, p4);
    insertChild(p1, p5);

    success &= outChild(p3) == p3;
    success &= emptyChild(p3);
    success &= getPSib(p5) == p2;
    success &= getPSib(p2) == NULL;

    success &= outChild(p5) == p5;
    success &= getPChild(p1) == p2;
    success &= getPSib(p2) == NULL;

    return success;
}
コード例 #5
0
ファイル: tp1test.c プロジェクト: gnuvince/ift2245
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;
}
コード例 #6
0
ファイル: tp1test.c プロジェクト: gnuvince/ift2245
int test_allocFreeCount(void) {
    int success = 1;
    pcb_t *procs[MAXPROCESS];
    int i;

    initProc();

    for (i = 1; i <= MAXPROCESS; ++i) {
        int j = 0;

        while (j < i && j < MAXPROCESS) {
            procs[j++] = allocPcb();
        }

        success &= getFreeProcessCount() == MAXPROCESS - i;

        while (j > 0) {
            freePcb(procs[--j]);
        }

        success &= getFreeProcessCount() == MAXPROCESS;
    }

    return success;
}
コード例 #7
0
ファイル: initial.c プロジェクト: neta-kedem/OS-Project
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;
}
コード例 #8
0
ファイル: tp1test.c プロジェクト: gnuvince/ift2245
int test_emptyChild(void) {
    int success = 1;
    pcb_t *p1, *p2;

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

    success &= !emptyChild(NULL);
    success &= emptyChild(p1);
    success &= emptyChild(p2);

    insertChild(p1, p2);
    success &= !emptyChild(p1);
    removeChild(p1);
    success &= emptyChild(p1);

    return success;
}
コード例 #9
0
ファイル: tp1test.c プロジェクト: gnuvince/ift2245
int test_insertBlocked(void) {
    int success = 1;
    semd_t *s1, *s2, *s3;
    pcb_t *p1, *p2, *p3;
    pcbq_t *q;

    initASL();
    initProc();

    s1 = getSema(0); initSemD(&s1, 1);
    s2 = getSema(1); initSemD(&s2, 2);
    s3 = getSema(12); initSemD(&s3, 3);

    p1 = allocPcb();
    p2 = allocPcb();
    p3 = allocPcb();

    success &= getASL() == NULL;
    insertBlocked(NULL, p1);
    success &= getASL() == NULL;
    insertBlocked(s1, NULL);
    success &= getASL() == NULL;

    insertBlocked(s2, p2);
    q = getSProcQ(s2);
    success &= !emptyProcQ(q);
    success &= getASL() == s2;

    insertBlocked(s3, p3);
    q = getSProcQ(s3);
    success &= !emptyProcQ(q);
    success &= getASL() == s2;
    success &= getSNext(s2) == s3;

    insertBlocked(s1, p1);
    q = getSProcQ(s1);
    success &= !emptyProcQ(q);
    success &= getASL() == s1;
    success &= getSNext(s1) == s2;

    return success;
}
コード例 #10
0
ファイル: tp1test.c プロジェクト: gnuvince/ift2245
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;
}
コード例 #11
0
ファイル: initial.c プロジェクト: Maldus512/uARM_kaya
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();
}
コード例 #12
0
ファイル: tp1test.c プロジェクト: gnuvince/ift2245
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;
}
コード例 #13
0
ファイル: nucleus.c プロジェクト: GiulioZhou/uArm_GAOS
pcb_t *makeInit() {
	// Init the first process
	pcb_t *pcb = allocPcb();
	pcb->p_pid = 1;
	// Processor Status Register
	pcb->p_s.cpsr = STATUS_SYS_MODE;
	pcb->p_s.cpsr = STATUS_ALL_INT_ENABLE(pcb->p_s.cpsr);
	pcb->p_s.cpsr = STATUS_ENABLE_TIMER(pcb->p_s.cpsr);
	// System Control Register
	pcb->p_s.CP15_Control = CP15_CONTROL_NULL;
	// Other registers
	pcb->p_s.pc = (memaddr) init;
	pcb->p_s.sp = RAM_TOP-FRAMESIZE;
	return pcb;
}
コード例 #14
0
/**
@brief (SYS1) Creates a new process.
@param state Processor state from which create a new process.
@return -1 in case of failure; 0 in case of success.
*/
EXTERN int createProcess(state_t *state)
{
	pcb_t *process;

	/* Allocate a new PCB */
	if (!(process = allocPcb())) return -1; /* Failure */

	/* Load processor state into process state */
	saveCurrentState(state, &(process->p_s));

	/* Update process counter, process tree and process queue */
	ProcessCount++;
	insertChild(CurrentProcess, process);
	insertProcQ(&ReadyQueue, process);

	return 0; /* Success */
}
コード例 #15
0
ファイル: tp1test.c プロジェクト: gnuvince/ift2245
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;
}
コード例 #16
0
ファイル: tp1test.c プロジェクト: gnuvince/ift2245
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;
}
コード例 #17
0
ファイル: ex1.c プロジェクト: gonghao/tmp_program
int main(int argc, char *argv[])
{
	int i, nProc, nSchedule;
	GQueues *gq;
	int ret;

	int tServing, tArriving;

	int pid;

	int nTime = 0;

	int RRflag;


	for (i = 0; i < 0; i++)
		pid = 1;


	gq = (GQueues *)malloc(sizeof(GQueues));
    if (gq == NULL)
		return 1;
    
	ret = InitGQueues(gq);
	if (ret != 0)
		return 2;
 
	
	/* 录入数据 */
Retry0:
	printf("Please input the number of processes: "); 
	scanf("%d",&nProc);
	if (nProc < 0 || nProc > MAX_PCB_NUM) {
		printf("Error! the number must be less than %d", MAX_PCB_NUM);
		goto Retry0;
	}

	for (i = 0; i < nProc; ++i) {
		
		printf("No. %d\n", i);
		printf("\t Serving time: ");
		scanf("%d", &tServing);
		printf("\t Arriving time: ");
		scanf("%d", &tArriving);

		allocPcb(gq, i, tServing, tArriving);
	}


Retry1:
	printf("Please input the choice of scheduling[0(RR)/1(SPF)]: ");
	scanf("%d", &nSchedule);
	if (nSchedule < 0 || nSchedule > 1) {
		printf("Error, please retry\n");
		goto Retry1;
	}

	/* 实验测试 */
	RRflag = 0;
	do {
		/* 调度就绪队列 */
		switch (nSchedule)
		{
		case RR:
			invokeRR(&(gq->qReady), RRflag);
			break;
		case SPF:
			invokeSpf(&(gq->qReady));
			break;
		default:
			break;
		}

		/* 运行 */
		printf("nTime = %d,\t", nTime++);
		pid = running(gq->qReady.head);
		printf("pid = %d\n", pid);

		/* 就绪队列的队头是否运行完毕?*/
		RRflag = finishReadyHead(gq);

		/* 是否全部运行完毕?*/
		if (gq->qReady.head == NULL)
			break;
	} while (1);

	/* 结束实验,清理内存 */
	DestroyGQueues(gq);

	//getch();

	return 0;

}
コード例 #18
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;

}
コード例 #19
0
ファイル: main.c プロジェクト: lambdacomplete/PKayaOS
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;
}
コード例 #20
0
ファイル: initial.c プロジェクト: OS-StudentGroup/Kaya-2010
/**
  * @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;
}
コード例 #21
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;

}
コード例 #22
0
ファイル: main.c プロジェクト: windr00/OSExp1
int main(int argc, char ** argv) {
    int nSchedule = SPF;
    int RRflag = 0;
    int pid;
    printf("this is done by 冉惟之, std. id : 2013060105023\n");
    if (argc == 2) {
        if (!strcmp(argv[1], "RR")) {
            nSchedule = RR;
        }
        else if (!strcmp(argv[1], "SPF")) {
            nSchedule = SPF;
        }
        else {
            printf("invalid argument : %s\n", argv[1]);
            return -2;
        }
    }
    else {
        printf("too few arguments\n");
        return -1;
    }
    GQueues *gq = (GQueues *) malloc(sizeof(GQueues));
    InitGQueues(gq);

/* 根据录入进程数据,分配PCB */
    allocPcb(gq, 0, 3, 0);
    allocPcb(gq, 1, 6, 2);
    allocPcb(gq, 2, 4, 4);
    allocPcb(gq, 3, 5, 6);
    allocPcb(gq, 4, 2, 8);

/* 输入进程调度方式 */

    do {
        /* 调度就绪队列 */
        switch (nSchedule)
        {
            case RR:
                invokeRR(&(gq->qReady), RRflag);
                break;
            case SPF:
                invokeSpf(&(gq->qReady));
                break;
            default:
                break;
        }

        /* 就绪队列的队头是否运行完毕?*/
        RRflag = finishReadyHead(gq);
        /* 是否全部运行完毕?*/
        if (gq->qReady.head == NULL)
            break;

        /* 运行 */
        pid = running(gq->qReady.head);
        printf("now running %d\n", pid);
    } while (1);

    /* 结束实验,清理内存 */
    DestroyGQueues(gq);
}