Esempio n. 1
0
void P1_DumpProcesses(){// Do CPU Time Part
  Check_Your_Privilege();
  USLOSS_Console("Dumping Process\n");
  int i;
    for(i=0;i<P1_MAXPROC;i++){
        if(procTable[i].priority==-1){
          continue;
        }
        int state=procTable[i].state;
        char* statePhrase;
        switch(state){
          case 1:
            statePhrase="Ready";
            break;
          case 2:
            statePhrase="Killed";
            break;
          case 3:
            statePhrase="Quit";
            break;
          case 4:
            statePhrase="Waiting";
            break;
        }
        int cpu;
        if(i==currPid){
          cpu=P1_ReadTime();
        }else{
          cpu=procTable[i].cpuTime;
        }
        USLOSS_Console("Name:%s\t PID:%-5d\tParent:%d\tPriority:%d\tState:%s\tKids:%d\tCPUTime:%d\n",
                procTable[i].name,i,procTable[i].parent,procTable[i].priority,
                statePhrase,procTable[i].numChildren,cpu); 
    }
}
Esempio n. 2
0
void sysHandler(int type,void *arg) {
	if(arg == NULL){
		USLOSS_Console("USLOSS_Sysargs is NULL!\n");
		return;
	}
	USLOSS_Sysargs *sysArgs = (USLOSS_Sysargs *) arg;
	int retVal = 0;
	int retVal2 = 0;
	int sectSize = 0;
	int sectors = 0;
	int tracks = 0;
	interruptsOn();
	switch (sysArgs->number) {
	case SYS_TERMREAD:
		retVal = P2_TermRead((int)sysArgs->arg3, (int)sysArgs->arg2, sysArgs->arg1);
                if(retVal >= 0){
                        sysArgs->arg4 = (void *)0;
                        sysArgs->arg2 = (void *)retVal;
                }else{
                        sysArgs->arg4 = (void *)-1;
                }
                break;
	case SYS_TERMWRITE:
		retVal = P2_TermWrite((int)sysArgs->arg3,(int)sysArgs->arg2,(char *)sysArgs->arg1);
                if(retVal >= 0){
                        sysArgs->arg4 = (void *)0;
                        sysArgs->arg2 = (void *)retVal;
                }else{
                        sysArgs->arg4 = (void *)-1;
                }
		break;
	case SYS_SPAWN: //Part 1
		retVal = P2_Spawn(sysArgs->arg5, sysArgs->arg1, sysArgs->arg2,
				(int) sysArgs->arg3, (int) sysArgs->arg4);
		if (retVal == -3 || retVal == -2) {
			sysArgs->arg4 = (void *) -1;
			sysArgs->arg1 = (void *) -1;
		} else {
			sysArgs->arg1 = (void *) retVal;
			sysArgs->arg4 = (void *) 0;
		}
		break;
	case SYS_WAIT: //Part 1
		retVal = P2_Wait(&retVal2);
		if(retVal == -1){
			sysArgs->arg1 = (void *)-1;
			sysArgs->arg4 = (void *)-1;
			sysArgs->arg2 = (void *)-1;
		}else{
			sysArgs->arg1 = (void *)retVal;
			sysArgs->arg2 = (void *)retVal2;
			sysArgs->arg4 = (void *)0;
		}
		break;
	case SYS_TERMINATE: //Part 1
		P2_Terminate((int)sysArgs->arg1);
		break;
	case SYS_SLEEP: // Part 1
		retVal = P2_Sleep((int)sysArgs->arg1);
		sysArgs->arg4 = (void *) retVal;
		break;
	case SYS_DISKREAD:
		retVal = P2_DiskRead((int)sysArgs->arg5,(int)sysArgs->arg3,(int) sysArgs->arg4,(int)sysArgs->arg2,(void *)sysArgs->arg1);
                if (retVal == -1) {
                        sysArgs->arg1 = (void *)retVal;
                        sysArgs->arg4 = (void *)-1;
                }
                else if (retVal == 0) {
                        sysArgs->arg1 = (void *)0;
                        sysArgs->arg4 = (void *)0;
                }else {
                        sysArgs->arg1 = (void *)retVal; //output is the disk's status register
                        sysArgs->arg4 = (void *)0;
                }
		break;
	case SYS_DISKWRITE:
		retVal = P2_DiskWrite((int)sysArgs->arg5,(int)sysArgs->arg3,(int) sysArgs->arg4,(int)sysArgs->arg2,(void *)sysArgs->arg1);
		if (retVal == -1) {
			sysArgs->arg1 = (void *)retVal;
			sysArgs->arg4 = (void *)-1;
		}
		else if (retVal == 0) {
			sysArgs->arg1 = (void *)0;
			sysArgs->arg4 = (void *)0;
		}else {
			sysArgs->arg1 = (void *)retVal; //output is the disk's status register
			sysArgs->arg4 = (void *)0;
		}
		break;
	case SYS_DISKSIZE:
		retVal = P2_DiskSize((int)sysArgs->arg1,&sectSize,&sectors,&tracks);
		if (retVal == -1) {
			sysArgs->arg4 = (void *)-1;
		}else {
			sysArgs->arg4 = (void *)0;
			sysArgs->arg1 = (void *)sectSize;
			sysArgs->arg2 = (void *)sectors;
			sysArgs->arg3 = (void *)tracks;
		}
		break;
	case SYS_GETTIMEOFDAY: //Part 1
		sysArgs->arg1 = (void *)USLOSS_Clock();
		break;
	case SYS_CPUTIME: //Part 1
		sysArgs->arg1 = (void *)P1_ReadTime();
		break;
	case SYS_DUMPPROCESSES: //Part 1
		P1_DumpProcesses();
		break;
	case SYS_GETPID: //Part 1
		sysArgs->arg1 = (void *) P1_GetPID();
		break;
	case SYS_SEMCREATE: //Part 1
		retVal = (int)sysArgs->arg1;
		if(retVal < 0){
			sysArgs->arg4 = (void *)-1;
		}else{
			sysArgs->arg4 = (void *)0;
			sysArgs->arg1 = (void *) semAdd(P1_SemCreate(retVal));
		}
		break;
	case SYS_SEMP: // Part 1
		if(validSem((int)sysArgs->arg1) == 0){
			sysArgs->arg4 = (void *) -1;
			return;
		}
		retVal = P1_P(userSemList[(int)sysArgs->arg1].sem);
		if(retVal < 0){
			sysArgs->arg4 = (void *) -1;
		}
		else{
			sysArgs->arg4 = (void *) 0;
		}
		break;
	case SYS_SEMV: // Part 1
                if(validSem((int)sysArgs->arg1) == 0){
                        sysArgs->arg4 = (void *) -1;
                        return;
                }
		retVal = P1_V(userSemList[(int)sysArgs->arg1].sem);
		if(retVal < 0){
			sysArgs->arg4 = (void *) -1;
		}
		else{
			sysArgs->arg4 = (void *) 0;
		}
		break;
	case SYS_SEMFREE: // Part 1
                if(validSem((int)sysArgs->arg1) == 0){
                        sysArgs->arg4 = (void *) -1;
                        return;
                }
		
		retVal = semDelete((int)sysArgs->arg1);
		if(retVal < 0){
			sysArgs->arg4 = (void *) -1;
		}
		else{
			sysArgs->arg4 = (void *) 0;
		}
		break;
	case SYS_MBOXCREATE: //Part 1
		retVal = P2_MboxCreate((int)sysArgs->arg1,(int)sysArgs->arg2);
		if(retVal == -2){
			sysArgs->arg1 = (void *) -1;
			sysArgs->arg4 = (void *) -1;
		}else{
			sysArgs->arg1 = (void *) retVal;
			sysArgs->arg4 = (void *) 0;
		}
		break;
	case SYS_MBOXRELEASE: // Part 1
		retVal = P2_MboxRelease((int)sysArgs->arg1);
		if(retVal < 0){
			sysArgs->arg4 = (void *) -1;
		}else{
			sysArgs->arg4 = (void *) 0;
		}
		break;
	case SYS_MBOXSEND: // Part 1
		retVal = P2_MboxSend((int)sysArgs->arg1,sysArgs->arg2,(int *)&sysArgs->arg3);
		if(retVal < 0){
			sysArgs->arg4 = (void *) -1;
		}else{
			sysArgs->arg4 = (void *) 0;
		}
		break;
	case SYS_MBOXRECEIVE: // Part 1
                retVal = P2_MboxReceive((int)sysArgs->arg1,sysArgs->arg2,(int *)&sysArgs->arg3);
                if(retVal < 0){
                        sysArgs->arg4 = (void *) -1;
                }else{
                        sysArgs->arg4 = (void *) 0;
			sysArgs->arg2 = (void *) retVal;
                }
		break;
	case SYS_MBOXCONDSEND: // Part 1
                retVal = P2_MboxCondSend((int)sysArgs->arg1,sysArgs->arg2,(int *)&sysArgs->arg3);
                if(retVal == -1){
                        sysArgs->arg4 = (void *) -1;
                }else if(retVal == -2){
			sysArgs->arg4 = (void *) 1;
		}
		else{
                        sysArgs->arg4 = (void *) 0;
                }
		break;
	case SYS_MBOXCONDRECEIVE: // Part 1
                retVal = P2_MboxCondReceive((int)sysArgs->arg1,sysArgs->arg2,(int *)&sysArgs->arg3);
                if(retVal == -1){
                        sysArgs->arg4 = (void *) -1;
                }else if(retVal == -2){
                        sysArgs->arg4 = (void *) 1;
                }
                else{
                        sysArgs->arg4 = (void *) 0;
			sysArgs->arg2 = (void *) retVal;
                }
		break;
	default:
		P1_Quit(1);
	}
}