Started Memory operations on simulator

+- simulator.c
This commit is contained in:
Charles Descamps 2024-03-17 14:09:20 -07:00
parent ee95d19bfe
commit d5705e42a4
4 changed files with 97 additions and 1 deletions

View file

@ -1,4 +1,4 @@
0.000001, OS: Simulator start 0.000000, OS: Simulator start
READY state from NEW state READY state from NEW state
ate ate

Binary file not shown.

View file

@ -1,5 +1,20 @@
#include "simulator.h" #include "simulator.h"
/*
Name: accessMemory
Process: checks offset from the PCB
Function Input/Parameters: source PCB (ProcessControlBlock *), offset (int), size (int)
Function Output/Parameters: none
Function Output/Returned: none?
Device Input/Device: none
Device Output/Device: none
Dependencies: ???
*/
void accessMemory(ProcessControlBlock *singlePCB, int offset, int size)
{
// no return, void (temp)
}
/* /*
Name: addProcess Name: addProcess
Process: allocates the memory for the pcb, grabs the data from the created PCB, Process: allocates the memory for the pcb, grabs the data from the created PCB,
@ -31,6 +46,21 @@ ProcessControlBlock *addProcess(const ProcessControlBlock source)
return workingNode; return workingNode;
} }
/*
Name: allocMemory
Process: 'allocates' memory within the PCB, stores offset and size within it's PCB
Function Input/Parameters: source PCB (ProcessControlBlock *), offset (int), size (int)
Function Output/Parameters: none
Function Output/Returned: none?
Device Input/Device: none
Device Output/Device: none
Dependencies: ???
*/
void allocMemory(ProcessControlBlock *singlePCB, int offset, int size)
{
// no return, void (temp)
}
/* /*
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
@ -52,6 +82,21 @@ ProcessControlBlockLL *createProcessList()
return headBlock; return headBlock;
} }
/*
Name: deallocMemory
Process: 'deallocates' memory within the PCB, removes offset and size within it's PCB
Function Input/Parameters: source PCB (ProcessControlBlock *), offset (int), size (int)
Function Output/Parameters: none
Function Output/Returned: none?
Device Input/Device: none
Device Output/Device: none
Dependencies: ???
*/
void deallocMemory(ProcessControlBlock *singlePCB, int offset, int size)
{
// no return, void (temp)
}
/* /*
Name: destroyProcessList Name: destroyProcessList
Process: deallocates memory used for the linked list struct Process: deallocates memory used for the linked list struct
@ -304,6 +349,46 @@ void logOutput(ConfigDataType *configPtr, char *logStr, bool isEnd)
} }
} }
/*
Name: memManager
Process: checks to make sure an allocate will be successful,
makes sure that an access will not segfault (or return segfault if it does),
and initializes memory and deallocates memory
Function Input/Parameters: PCBList (ProcessControlBlockLL *), memory code (MEMORY_SIGNALS),
offset (int), size (int), configuration data (ConfigDataType *)
Function Output/Parameters: none
Function Output/Returned: none?
Device Input/Device: none
Device Output/Device: none
Dependencies: ???
*/
void memManager(ProcessControlBlockLL *pcbList, MEMORY_SIGNALS memCode, int offset, int size, ConfigDataType *configPtr)
{
// switch case for each memory code
switch (memCode)
{
case MEMORY_INITIALIZE:
/* code */
break;
case MEMORY_ALLOCATE:
/* code */
break;
case MEMORY_ACCESS:
/* code */
break;
case MEMORY_DEALLOCATE:
/* code */
break;
default:
break;
}
// no return, void (temp)
}
/* /*
Name: runCPU Name: runCPU
Process: runs the CPU operations for however long it takes Process: runs the CPU operations for however long it takes

View file

@ -17,6 +17,13 @@ typedef enum{
PROCESS_STATE_TERMINATED PROCESS_STATE_TERMINATED
} PROCESS_STATES; } PROCESS_STATES;
typedef enum{
MEMORY_INITIALIZE = 0,
MEMORY_ACCESS,
MEMORY_ALLOCATE,
MEMORY_DEALLOCATE
} MEMORY_SIGNALS;
typedef struct ProcessControlBlockStruct typedef struct ProcessControlBlockStruct
{ {
int uniquePid; int uniquePid;
@ -37,6 +44,10 @@ typedef struct ProcessControlBlockStruct
// see how many are left. // see how many are left.
// also need a time left state here? // also need a time left state here?
double timeLeft; double timeLeft;
// allocated memory array (stores the offsets)
int *allocatedMemOffsets;
// allocated memory array sizes (stores the sizes for each offset)
int *allocatedMemSizes;
// connect to the next process control block here // connect to the next process control block here
struct ProcessControlBlockStruct *nextPtr; struct ProcessControlBlockStruct *nextPtr;
} ProcessControlBlock; } ProcessControlBlock;