runSim partially working
+- simulator.c
This commit is contained in:
parent
c828913809
commit
2d412e233d
2 changed files with 71 additions and 6 deletions
BIN
Sim02/sim02
Executable file
BIN
Sim02/sim02
Executable file
Binary file not shown.
|
|
@ -3,6 +3,22 @@
|
||||||
#include "StandardConstants.h"
|
#include "StandardConstants.h"
|
||||||
#include "simulator.h"
|
#include "simulator.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
Name: addProcess
|
||||||
|
Process: adds a process to the
|
||||||
|
Function Input/Parameters: none
|
||||||
|
Function Output/Parameters: none
|
||||||
|
Function Output/Returned: head pointer to the PCBs
|
||||||
|
Device Input/Device: none
|
||||||
|
Device Output/Device: none
|
||||||
|
Dependencies: malloc, sizeof, fillProcessList
|
||||||
|
*/
|
||||||
|
// ProcessControlBlock *addProcess()
|
||||||
|
// {
|
||||||
|
// // return NULL (temp)
|
||||||
|
// return NULL;
|
||||||
|
// }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Name: createProcessList
|
Name: createProcessList
|
||||||
Process: reads through the opcode struct to fill out the linked list of PCBs
|
Process: reads through the opcode struct to fill out the linked list of PCBs
|
||||||
|
|
@ -56,8 +72,8 @@ Dependencies: free, destroyProcessListHelper(recursively), ???
|
||||||
*/
|
*/
|
||||||
ProcessControlBlock *destroyProcessListHelper(ProcessControlBlock *nodePtr)
|
ProcessControlBlock *destroyProcessListHelper(ProcessControlBlock *nodePtr)
|
||||||
{
|
{
|
||||||
// check to see if the next pointer is NOT null
|
// check to see if the pointer is NOT null
|
||||||
if(nodePtr->nextPtr != NULL)
|
if(nodePtr != NULL)
|
||||||
{
|
{
|
||||||
// if not null, move to the next pointer (recurse)
|
// if not null, move to the next pointer (recurse)
|
||||||
nodePtr->nextPtr = destroyProcessListHelper(nodePtr->nextPtr);
|
nodePtr->nextPtr = destroyProcessListHelper(nodePtr->nextPtr);
|
||||||
|
|
@ -83,13 +99,31 @@ 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;
|
||||||
// need a pointer to save the location of first metadata opcode
|
// 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
|
// need a variable to count how many IO cycles are in the process
|
||||||
|
int ioCycleCount;
|
||||||
// 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;
|
||||||
// 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;
|
||||||
// temp variables?
|
// temp variables?
|
||||||
|
char *tempStrOne;
|
||||||
|
char *tempStrTwo;
|
||||||
|
|
||||||
|
// set the working pointer to the first part of the metadata pointer
|
||||||
|
wkgMetaPtr = metadataPtr;
|
||||||
|
//
|
||||||
|
|
||||||
// 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)
|
||||||
|
{
|
||||||
|
tempStrOne = wkgMetaPtr->command;
|
||||||
|
tempStrTwo = wkgMetaPtr->inOutArg;
|
||||||
// if app start,
|
// if app start,
|
||||||
|
if(compareString(tempStrOne, "app") && compareString(tempStrTwo, "start"))
|
||||||
|
{
|
||||||
// set the unique ID
|
// set the unique ID
|
||||||
// set the process state to PROCESS_STATE_NEW
|
// set the process state to 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
|
||||||
|
|
@ -101,6 +135,8 @@ ProcessControlBlock *fillProcessList(OpCodeType *metadataPtr)
|
||||||
// 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.
|
||||||
|
}
|
||||||
|
}
|
||||||
// return null (temp)
|
// return null (temp)
|
||||||
return (ProcessControlBlock *)NULL;
|
return (ProcessControlBlock *)NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -120,10 +156,29 @@ void runSim(ConfigDataType *configPtr, OpCodeType *metaDataMstrPtr)
|
||||||
{
|
{
|
||||||
// initialize function/variables
|
// initialize function/variables
|
||||||
// need a FILE * for file operations
|
// need a FILE * for file operations
|
||||||
|
FILE *fileWritePtr;
|
||||||
// need two working pointers, one for master loop, one for internal loop
|
// need two working pointers, one for master loop, one for internal loop
|
||||||
// currentTime variable that stores the time.
|
OpCodeType *wkgPtrMaster;
|
||||||
// create the process list with createProcessList
|
// currentTime variable that stores the time. [now unsure if needed]
|
||||||
// function holds master loop, loops until sys end opcode found OR PCB List != NULL
|
// need a variable for headPointer to point
|
||||||
|
ProcessControlBlockLL *pcbList;
|
||||||
|
// string variable for nextCode
|
||||||
|
char *nextCode;
|
||||||
|
// create the process list with createProcessList, store the pointed to address
|
||||||
|
pcbList = createProcessList();
|
||||||
|
// create temp strings
|
||||||
|
char *command;
|
||||||
|
char *argument;
|
||||||
|
|
||||||
|
// get the first data out of the metadata
|
||||||
|
command = metaDataMstrPtr->command;
|
||||||
|
argument = metaDataMstrPtr->strArg1;
|
||||||
|
|
||||||
|
// set the master working pointer to the first metadata block
|
||||||
|
wkgPtrMaster = metaDataMstrPtr;
|
||||||
|
// function holds master loop, loops until sys end opcode found OR wkgPtrMaster nextNode != NULL
|
||||||
|
while( wkgPtrMaster->nextNode != NULL || (compareString(argument, "end") && compareString(command, "sys")))
|
||||||
|
{
|
||||||
// will have a loop that goes from app start to app end for a PCB
|
// will have a loop that goes from app start to app end for a PCB
|
||||||
// (checks to see if the next instruction is NOT app end), using getNextProcess?
|
// (checks to see if the next instruction is NOT app end), using getNextProcess?
|
||||||
// this will getNextOpCode
|
// this will getNextOpCode
|
||||||
|
|
@ -131,9 +186,19 @@ 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
|
||||||
|
wkgPtrMaster = wkgPtrMaster->nextNode;
|
||||||
|
// set the command and argument to the current cmd and arg
|
||||||
|
command = wkgPtrMaster->command;
|
||||||
|
argument = wkgPtrMaster->strArg1;
|
||||||
|
}
|
||||||
//
|
//
|
||||||
// deallocate the process list with destroyProcessList
|
// deallocate the process list with destroyProcessList
|
||||||
printf("runSim called here");
|
destroyProcessList(pcbList);
|
||||||
|
//printf("runSim called here");
|
||||||
// void function, no return.
|
// void function, no return.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue