diff --git a/Sim02/sim02 b/Sim02/sim02 index 00abee1..5403898 100755 Binary files a/Sim02/sim02 and b/Sim02/sim02 differ diff --git a/Sim02/simulator.c b/Sim02/simulator.c index fcf0cdb..2193094 100644 --- a/Sim02/simulator.c +++ b/Sim02/simulator.c @@ -95,21 +95,20 @@ Device Input/Device: none Device Output/Device: none Dependencies: ??? */ -ProcessControlBlock *fillProcessList(OpCodeType *metadataPtr) +ProcessControlBlockLL *fillProcessList(OpCodeType *metadataPtr, ProcessControlBlockLL *headPointer) { // initialize function/variables // need a working pointer for the metadata OpCodeType *wkgMetaPtr; OpCodeType *wkgInternalPtr; ProcessControlBlock currentPCB; - // need a pointer to save the location of first metadata opcode - OpCodeType metaAddress; + ProcessControlBlock *wkgPCBPtr; // need a variable to count how many IO cycles are in the process - int ioCycleCount; + int ioCycleCount = 0; // need a variable to count how many CPU cycles are in the process - int cpuCycleCount; + int cpuCycleCount = 0; // need a variable to calculate the time left in ms for a process - int timeLeftCount; + int timeLeftCount = 0; // need a variable that fills PIDs, starting at 0 int processId = 0; // process variables? @@ -117,10 +116,15 @@ ProcessControlBlock *fillProcessList(OpCodeType *metadataPtr) char *commandInt; char *argument; char *argumentInt; + char *inOutArg; + int integerArgumentOne; + // unused as of current + //int integerArgumentTwo; // set the working pointer to the first part of the metadata pointer wkgMetaPtr = metadataPtr; - // + // set another working pointer to the first part of the PCB list + wkgPCBPtr = headPointer->headPtr; // grab the first command and argument command = wkgMetaPtr->command; @@ -139,51 +143,64 @@ ProcessControlBlock *fillProcessList(OpCodeType *metadataPtr) currentPCB.process_state = PROCESS_STATE_NEW; // set the nextOpCode as a pointer to the first place metadataPtr started currentPCB.nextOpCode = wkgMetaPtr; + // set the internal pointer to the location that wkgPtr is at wkgInternalPtr = wkgMetaPtr; // set the internal command and argument commandInt = wkgInternalPtr->command; argumentInt = wkgInternalPtr->strArg1; + inOutArg = wkgInternalPtr->inOutArg; + integerArgumentOne = wkgInternalPtr->intArg2; + // integer argument two is unused atm + //integerArgumentTwo = wkgInternalPtr->intArg3; // loop while no longer have io or cpu instructions? (aka not at app end?) while(wkgInternalPtr->nextNode != NULL || (compareString(argumentInt, "end") && compareString(commandInt, "app"))) { - printf("%s command, %s argument:\n", commandInt, argumentInt); // count number of io cycles - if((compareString(argumentInt, "in") || compareString(commandInt, "dev"))) + if((compareString(commandInt, "dev") == 0 && compareString(inOutArg, "in") == 0)) { - // - printf("IO CYCLE %s\n", argumentInt); + ioCycleCount = ioCycleCount + integerArgumentOne; } - else if((compareString(argumentInt, "out") || compareString(commandInt, "dev"))) + if((compareString(commandInt, "dev") == 0 && compareString(inOutArg, "out") == 0)) { - // - printf("IO CYCLE %s\n", argumentInt); + ioCycleCount = ioCycleCount + integerArgumentOne; } // count number of cpu cycles - // if((compareString(argumentInt, "process") || compareString(commandInt, "cpu"))) - // { - // // - // printf("CPU CYCLE\n"); - // } + if((compareString(argumentInt, "process") == 0 && compareString(commandInt, "cpu") == 0)) + { + cpuCycleCount = cpuCycleCount + integerArgumentOne; + } // move to next node, set relevant args wkgInternalPtr = wkgInternalPtr->nextNode; commandInt = wkgInternalPtr->command; argumentInt = wkgInternalPtr->strArg1; + inOutArg = wkgInternalPtr->inOutArg; } + // set the ioCycles from variable + currentPCB.ioCycles = ioCycleCount; // set the cpuCycles from variable + currentPCB.cpuCycles = cpuCycleCount; // set totalCycles from adding both IO/CPU + currentPCB.totalCycles = ioCycleCount + cpuCycleCount; // set the time left from (ioCycles * ioCycleRate) + (cpuCycles * procCyclesRate) // this gets the number of ms in the process. + currentPCB.timeLeft = timeLeftCount; // increment the PID counter processId = processId + 1; } + // move to the next bit of data wkgMetaPtr = wkgMetaPtr->nextNode; command = wkgMetaPtr->command; argument = wkgMetaPtr->strArg1; + + // needs to add nodes to the end and all data once parsed + // do both the metadata and PCBs + wkgPCBPtr = ¤tPCB; + wkgPCBPtr->nextPtr = NULL; } - // return null (temp) - return (ProcessControlBlock *)NULL; + // return null (temp) (should return the headpointer) + return headPointer; } /* @@ -212,7 +229,7 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr) // create the process list with createProcessList, store the pointed to address pcbList = createProcessList(); // fill the process list given the metadata - pcbList->headPtr = fillProcessList(metaDataMstrPtr); + pcbList = fillProcessList(metaDataMstrPtr, pcbList); // create temp strings char *command; char *argument; diff --git a/Sim02/simulator.h b/Sim02/simulator.h index ffafb2a..4b3dd8e 100644 --- a/Sim02/simulator.h +++ b/Sim02/simulator.h @@ -24,7 +24,7 @@ typedef struct ProcessControlBlockStruct // this will be a mini loop within the master loop that goes until it // hits the app end command. // it may hold the next opcode, since you don't need to traverse backward - char *nextOpCode; + OpCodeType *nextOpCode; // have an IO cycle count here int ioCycles; // have a CPU cycle count here @@ -140,7 +140,7 @@ Device Input/Device: none Device Output/Device: none Dependencies: ??? */ -ProcessControlBlock *fillProcessList(OpCodeType *metadataPtr); +ProcessControlBlockLL *fillProcessList(OpCodeType *metadataPtr, ProcessControlBlockLL *headPointer); /* Name: runSim