Finished? fillProcessList function for Sim02

+- simulator.c
This commit is contained in:
Charles Descamps 2024-02-21 00:12:05 -07:00
parent 3e4d6ec479
commit a946ea2c1c
3 changed files with 41 additions and 24 deletions

Binary file not shown.

View file

@ -95,21 +95,20 @@ Device Input/Device: none
Device Output/Device: none Device Output/Device: none
Dependencies: ??? Dependencies: ???
*/ */
ProcessControlBlock *fillProcessList(OpCodeType *metadataPtr) ProcessControlBlockLL *fillProcessList(OpCodeType *metadataPtr, ProcessControlBlockLL *headPointer)
{ {
// initialize function/variables // initialize function/variables
// need a working pointer for the metadata // need a working pointer for the metadata
OpCodeType *wkgMetaPtr; OpCodeType *wkgMetaPtr;
OpCodeType *wkgInternalPtr; OpCodeType *wkgInternalPtr;
ProcessControlBlock currentPCB; ProcessControlBlock currentPCB;
// need a pointer to save the location of first metadata opcode ProcessControlBlock *wkgPCBPtr;
OpCodeType metaAddress;
// need a variable to count how many IO cycles are in the process // 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 // 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 // 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 // need a variable that fills PIDs, starting at 0
int processId = 0; int processId = 0;
// process variables? // process variables?
@ -117,10 +116,15 @@ ProcessControlBlock *fillProcessList(OpCodeType *metadataPtr)
char *commandInt; char *commandInt;
char *argument; char *argument;
char *argumentInt; char *argumentInt;
char *inOutArg;
int integerArgumentOne;
// unused as of current
//int integerArgumentTwo;
// set the working pointer to the first part of the metadata pointer // set the working pointer to the first part of the metadata pointer
wkgMetaPtr = metadataPtr; wkgMetaPtr = metadataPtr;
// // set another working pointer to the first part of the PCB list
wkgPCBPtr = headPointer->headPtr;
// grab the first command and argument // grab the first command and argument
command = wkgMetaPtr->command; command = wkgMetaPtr->command;
@ -139,51 +143,64 @@ ProcessControlBlock *fillProcessList(OpCodeType *metadataPtr)
currentPCB.process_state = PROCESS_STATE_NEW; currentPCB.process_state = PROCESS_STATE_NEW;
// set the nextOpCode as a pointer to the first place metadataPtr started // set the nextOpCode as a pointer to the first place metadataPtr started
currentPCB.nextOpCode = wkgMetaPtr; currentPCB.nextOpCode = wkgMetaPtr;
// set the internal pointer to the location that wkgPtr is at // set the internal pointer to the location that wkgPtr is at
wkgInternalPtr = wkgMetaPtr; wkgInternalPtr = wkgMetaPtr;
// set the internal command and argument // set the internal command and argument
commandInt = wkgInternalPtr->command; commandInt = wkgInternalPtr->command;
argumentInt = wkgInternalPtr->strArg1; 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?) // loop while no longer have io or cpu instructions? (aka not at app end?)
while(wkgInternalPtr->nextNode != NULL || (compareString(argumentInt, "end") && compareString(commandInt, "app"))) while(wkgInternalPtr->nextNode != NULL || (compareString(argumentInt, "end") && compareString(commandInt, "app")))
{ {
printf("%s command, %s argument:\n", commandInt, argumentInt);
// count number of io cycles // count number of io cycles
if((compareString(argumentInt, "in") || compareString(commandInt, "dev"))) if((compareString(commandInt, "dev") == 0 && compareString(inOutArg, "in") == 0))
{ {
// ioCycleCount = ioCycleCount + integerArgumentOne;
printf("IO CYCLE %s\n", argumentInt);
} }
else if((compareString(argumentInt, "out") || compareString(commandInt, "dev"))) if((compareString(commandInt, "dev") == 0 && compareString(inOutArg, "out") == 0))
{ {
// ioCycleCount = ioCycleCount + integerArgumentOne;
printf("IO CYCLE %s\n", argumentInt);
} }
// count number of cpu cycles // count number of cpu cycles
// if((compareString(argumentInt, "process") || compareString(commandInt, "cpu"))) if((compareString(argumentInt, "process") == 0 && compareString(commandInt, "cpu") == 0))
// { {
// // cpuCycleCount = cpuCycleCount + integerArgumentOne;
// printf("CPU CYCLE\n"); }
// }
// move to next node, set relevant args // move to next node, set relevant args
wkgInternalPtr = wkgInternalPtr->nextNode; wkgInternalPtr = wkgInternalPtr->nextNode;
commandInt = wkgInternalPtr->command; commandInt = wkgInternalPtr->command;
argumentInt = wkgInternalPtr->strArg1; argumentInt = wkgInternalPtr->strArg1;
inOutArg = wkgInternalPtr->inOutArg;
} }
// set the ioCycles from variable // set the ioCycles from variable
currentPCB.ioCycles = ioCycleCount;
// set the cpuCycles from variable // set the cpuCycles from variable
currentPCB.cpuCycles = cpuCycleCount;
// set totalCycles from adding both IO/CPU // set totalCycles from adding both IO/CPU
currentPCB.totalCycles = ioCycleCount + cpuCycleCount;
// set the time left from (ioCycles * ioCycleRate) + (cpuCycles * procCyclesRate) // set the time left from (ioCycles * ioCycleRate) + (cpuCycles * procCyclesRate)
// this gets the number of ms in the process. // this gets the number of ms in the process.
currentPCB.timeLeft = timeLeftCount;
// increment the PID counter // increment the PID counter
processId = processId + 1; processId = processId + 1;
} }
// move to the next bit of data
wkgMetaPtr = wkgMetaPtr->nextNode; wkgMetaPtr = wkgMetaPtr->nextNode;
command = wkgMetaPtr->command; command = wkgMetaPtr->command;
argument = wkgMetaPtr->strArg1; argument = wkgMetaPtr->strArg1;
// needs to add nodes to the end and all data once parsed
// do both the metadata and PCBs
wkgPCBPtr = &currentPCB;
wkgPCBPtr->nextPtr = NULL;
} }
// return null (temp) // return null (temp) (should return the headpointer)
return (ProcessControlBlock *)NULL; return headPointer;
} }
/* /*
@ -212,7 +229,7 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
// create the process list with createProcessList, store the pointed to address // create the process list with createProcessList, store the pointed to address
pcbList = createProcessList(); pcbList = createProcessList();
// fill the process list given the metadata // fill the process list given the metadata
pcbList->headPtr = fillProcessList(metaDataMstrPtr); pcbList = fillProcessList(metaDataMstrPtr, pcbList);
// create temp strings // create temp strings
char *command; char *command;
char *argument; char *argument;

View file

@ -24,7 +24,7 @@ typedef struct ProcessControlBlockStruct
// this will be a mini loop within the master loop that goes until it // this will be a mini loop within the master loop that goes until it
// hits the app end command. // hits the app end command.
// it may hold the next opcode, since you don't need to traverse backward // it may hold the next opcode, since you don't need to traverse backward
char *nextOpCode; OpCodeType *nextOpCode;
// have an IO cycle count here // have an IO cycle count here
int ioCycles; int ioCycles;
// have a CPU cycle count here // have a CPU cycle count here
@ -140,7 +140,7 @@ Device Input/Device: none
Device Output/Device: none Device Output/Device: none
Dependencies: ??? Dependencies: ???
*/ */
ProcessControlBlock *fillProcessList(OpCodeType *metadataPtr); ProcessControlBlockLL *fillProcessList(OpCodeType *metadataPtr, ProcessControlBlockLL *headPointer);
/* /*
Name: runSim Name: runSim