Finished? fillProcessList function for Sim02
+- simulator.c
This commit is contained in:
parent
3e4d6ec479
commit
a946ea2c1c
3 changed files with 41 additions and 24 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue