-
Notifications
You must be signed in to change notification settings - Fork 3
/
testMM.c
80 lines (65 loc) · 1.96 KB
/
testMM.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include<stdio.h>
#include<stdlib.h>
#include "dataTypes.h"
#include "pageTable.h"
#include "segmentTable.h"
#include "pcb.h"
#include "frameTable.h"
#include "configuration.h"
FrameTable frameTable;
segmentTable* GDTptr;
PCB pcbArr[1];
int main()
{
printf("Starting execution of simulator\n");
long addr[100];
int n=20,i;
printf("Enter input\n");
for(i=0;i<n;i++)
{
scanf("%lx",&addr[i]);
}
printf("Initializing frame table\n");
initFrameTable();
printf("Initialized frame table\n");
printf("Initializing GDT\n");
GDTptr=initSegTable();
printf("Initilized GDT\n");
printf("Initializing PCB\n");
initPCB(&pcbArr[0]);
printf("Initialized PCB\n");
// Set up done. Start simulation
// allocateFrame(1,level1PageTable,0,1);
// allocateFrame(1,level1PageTable,1,1); //need to enter in page tables too
//allocateFrame(1,1);
i = 0;
unsigned int* pageNo = calloc(1, sizeof(unsigned int));
unsigned int* level = calloc(1,sizeof(unsigned int));
pageTable** ptrToPageFaultPageTable = malloc(sizeof(pageTable *));
pageTable* pagetable;
int26 address;
while(i < n)
{
address.value = addr[i]>>10;
pagetable = searchSegmentTable(0, address);
printf("Calling searchPageTable\n");
//if(searchPageTable(pcbArr[0].LDTPointer->entries[0].level3PageTableptr, ptrToPageFaultPageTable, addr[i]&0xFFFFFFFF,pageNo,level) == -1){
if(searchPageTable(pagetable, ptrToPageFaultPageTable, addr[i]&0xFFFFFFFF,0,pageNo,level) == -1){
printf("After returing to testMM searchPageTable: level = %d, pageFaultPageNumber = %d\n",*level,*pageNo);
allocateFrame(0,addr[i]>>32,*ptrToPageFaultPageTable, *pageNo, *level);
// We need to retry for this address
printf("Retrying for same page after page fault\n");
printf("------------------------------------\n");
continue;
}
else{
printf("Search in page table was successful\n");
i++;
}
printf("------------------------------------\n");
}
deleteProcess(0);
free(pageNo);
free(level);
return 0;
}