forked from jaskaran1312/dstn-assignment1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframetable.c
46 lines (40 loc) · 1.57 KB
/
frametable.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "hardware.h"
#include "frametable.h"
#include "lru.h"
#include <stdio.h>
#include <stdlib.h>
//returns 1 if frame belongs to process, 0 otherwise
int64_t checkFrameTable(int64_t pa, struct Process *process, struct Hardware *hardware) {
if(pa==-1) return 0;
printf("Frame table pid %ld, process pid %ld\n", hardware->frametable->pid[pa], process->pid);
fflush(stdout);
if (hardware->frametable->pid[pa] == process->pid) {
return 1;
}
return 0;
}
int64_t allocateNewFrame(struct Process *process, struct Hardware *hardware) {
/*
basically, because there is no "freeing" of frames, each frame will only be empty once.
This means I only have to allocate each new frame once, which I'm doing linearly.
This also means we dont need free frameframecount, so I removed it.
*/
int64_t temp;
if (hardware->frametable->initialFrameAlloc < 65536) //there are free frames
{
temp = hardware->frametable->initialFrameAlloc; // allocate next free frame
printf("Allocating %ld from frame table\n", temp);
hardware->mainMemory->frames[temp] = (struct PageTable *) malloc(sizeof(struct PageTable));
for(int i=0; i<256; i++){
hardware->mainMemory->frames[temp]->entries[i] = -1;
}
hardware->frametable->initialFrameAlloc++;
} else {
temp = getMMLRU(hardware); //allocate LRU
}
hardware->frametable->pid[temp] = process->pid;
//allocated/replaced frame, have not cleaned it though
updateMMLRU(hardware, temp);
return temp;
}
// fetchSegmentTableEntry()