Save point for Sim02

+- simulator.c
This commit is contained in:
Charles Descamps 2024-02-20 11:47:12 -07:00
parent 2d412e233d
commit 3e4d6ec479
2 changed files with 57 additions and 13 deletions

Binary file not shown.

View file

@ -100,6 +100,8 @@ ProcessControlBlock *fillProcessList(OpCodeType *metadataPtr)
// 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;
ProcessControlBlock currentPCB;
// need a pointer to save the location of first metadata opcode // need a pointer to save the location of first metadata opcode
OpCodeType metaAddress; 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
@ -108,34 +110,77 @@ ProcessControlBlock *fillProcessList(OpCodeType *metadataPtr)
int cpuCycleCount; int cpuCycleCount;
// 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;
// temp variables? // need a variable that fills PIDs, starting at 0
char *tempStrOne; int processId = 0;
char *tempStrTwo; // process variables?
char *command;
char *commandInt;
char *argument;
char *argumentInt;
// 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;
// //
// grab the first command and argument
command = wkgMetaPtr->command;
argument = wkgMetaPtr->strArg1;
// loop through the process list, until you hit a sys end. // 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 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 // 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 // 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 // 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 // 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 ioCycles from variable
// set the cpuCycles from variable // set the cpuCycles from variable
// set totalCycles from adding both IO/CPU // set totalCycles from adding both IO/CPU
// 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.
// increment the PID counter
processId = processId + 1;
} }
wkgMetaPtr = wkgMetaPtr->nextNode;
command = wkgMetaPtr->command;
argument = wkgMetaPtr->strArg1;
} }
// return null (temp) // return null (temp)
return (ProcessControlBlock *)NULL; return (ProcessControlBlock *)NULL;
@ -166,6 +211,8 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
char *nextCode; char *nextCode;
// 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
pcbList->headPtr = fillProcessList(metaDataMstrPtr);
// create temp strings // create temp strings
char *command; char *command;
char *argument; char *argument;
@ -186,9 +233,6 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
// checkForIO will need the FILE * passed, will need timer access, and ??? // 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 // 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 ??? // 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 // move the wkgPtrMaster to the next metadata block
wkgPtrMaster = wkgPtrMaster->nextNode; wkgPtrMaster = wkgPtrMaster->nextNode;
// set the command and argument to the current cmd and arg // set the command and argument to the current cmd and arg