diff --git a/Sim02/sim02 b/Sim02/sim02 index 92d9f02..00abee1 100755 Binary files a/Sim02/sim02 and b/Sim02/sim02 differ diff --git a/Sim02/simulator.c b/Sim02/simulator.c index a63708f..fcf0cdb 100644 --- a/Sim02/simulator.c +++ b/Sim02/simulator.c @@ -100,6 +100,8 @@ ProcessControlBlock *fillProcessList(OpCodeType *metadataPtr) // 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; // need a variable to count how many IO cycles are in the process @@ -108,34 +110,77 @@ ProcessControlBlock *fillProcessList(OpCodeType *metadataPtr) int cpuCycleCount; // need a variable to calculate the time left in ms for a process int timeLeftCount; - // temp variables? - char *tempStrOne; - char *tempStrTwo; + // need a variable that fills PIDs, starting at 0 + int processId = 0; + // process variables? + char *command; + char *commandInt; + char *argument; + char *argumentInt; // set the working pointer to the first part of the metadata pointer wkgMetaPtr = metadataPtr; - // + // + + // grab the first command and argument + command = wkgMetaPtr->command; + argument = wkgMetaPtr->strArg1; // loop through the process list, until you hit a sys end. - while(wkgMetaPtr->nextNode != NULL) + while(wkgMetaPtr->nextNode != NULL || (compareString(argument, "end") && compareString(command, "sys"))) { - tempStrOne = wkgMetaPtr->command; - tempStrTwo = wkgMetaPtr->inOutArg; // if app start, - if(compareString(tempStrOne, "app") && compareString(tempStrTwo, "start")) + if (compareString(command, "app") && compareString(argument, "start")) { - // set the unique ID + // set the unique ID for both PCB and Metadata + wkgMetaPtr->pid = processId; + currentPCB.uniquePid = processId; // set the process state to PROCESS_STATE_NEW + currentPCB.process_state = PROCESS_STATE_NEW; // set the nextOpCode as a pointer to the first place metadataPtr started - // loop while no longer have io or cpu instructions? + 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; + // 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"))) + { + // + printf("IO CYCLE %s\n", argumentInt); + } + else if((compareString(argumentInt, "out") || compareString(commandInt, "dev"))) + { + // + printf("IO CYCLE %s\n", argumentInt); + } // count number of cpu cycles + // if((compareString(argumentInt, "process") || compareString(commandInt, "cpu"))) + // { + // // + // printf("CPU CYCLE\n"); + // } + // move to next node, set relevant args + wkgInternalPtr = wkgInternalPtr->nextNode; + commandInt = wkgInternalPtr->command; + argumentInt = wkgInternalPtr->strArg1; + } // set the ioCycles from variable // set the cpuCycles from variable // set totalCycles from adding both IO/CPU // set the time left from (ioCycles * ioCycleRate) + (cpuCycles * procCyclesRate) // this gets the number of ms in the process. + // increment the PID counter + processId = processId + 1; } + wkgMetaPtr = wkgMetaPtr->nextNode; + command = wkgMetaPtr->command; + argument = wkgMetaPtr->strArg1; } // return null (temp) return (ProcessControlBlock *)NULL; @@ -166,6 +211,8 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr) char *nextCode; // create the process list with createProcessList, store the pointed to address pcbList = createProcessList(); + // fill the process list given the metadata + pcbList->headPtr = fillProcessList(metaDataMstrPtr); // create temp strings char *command; char *argument; @@ -186,9 +233,6 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr) // checkForIO will need the FILE * passed, will need timer access, and ??? // this will checkForCPU and run the CPU operations, outputting to FILE * and/or monitor // checkForCPU will need the FILE * passed, will need timer access, and ??? - // TEMP - printf("%s is command, %s is argument\n", command, argument); - // TEMP END // move the wkgPtrMaster to the next metadata block wkgPtrMaster = wkgPtrMaster->nextNode; // set the command and argument to the current cmd and arg