-
Notifications
You must be signed in to change notification settings - Fork 3
/
tlb.h
96 lines (65 loc) · 2.36 KB
/
tlb.h
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Author: Akhil
* Date: 13/3/20
*
* Contains the ADT of the TLB.
*/
//#include "dataTypes.h"
//#include "configuration.h"
typedef struct
{
unsigned int validInvalidBit: 1;
unsigned int pageNum: PAGE_NUM_ADDR_SIZE;
unsigned int frameNum: FRAME_NUM_ADDR_SIZE;
unsigned int lruCount: 4;
}
TLBL1Entry;
typedef struct
{
unsigned int validInvalidBit: 1;
unsigned int pageNum: PAGE_NUM_ADDR_SIZE;
unsigned int frameNum: FRAME_NUM_ADDR_SIZE;
unsigned int lruCount: 5;
}
TLBL2Entry;
typedef struct
{
TLBL1Entry entries[NUM_ENTRIES_IN_L1_TLB];
}
TLBL1;
typedef struct
{
TLBL2Entry entries[NUM_ENTRIES_IN_L2_TLB];
}
TLBL2;
// Functions
// L1
// Invalidates all entries.
void TLBL1Flush();
// Prints the current state of the entire TLB table.
void TLBL1Print();
// Searches for particular page number's in TLB. If hit the physical address is returned else returns -1, second paramenter - error = ERROR_PAGE_NUM_NOT_FOUND. Also updates the corresponding lru
unsigned int TLBL1Search(unsigned int pageNum, unsigned int *error);
// Replaces a block in tlb with the new block - with new pageNum and frameNum mapping. Returns the index where the new entry was put.
int TLBL1Update(unsigned int pageNum, unsigned int frameNum);
// Mimics the entry of index being used and hence updates the LRU corresponding to the index.
int TLBL1UpdateLru(int index);
// Returns the index of the lru entry in the TLB.
int TLBL1GetLruIndex();
// Returns the first invalid entry in the TLB.
int TLBL1GetFirstInvalidEntry();
// L2
// Invalidates all entries.
void TLBL2Flush();
// Prints the current state of the entire TLB table.
void TLBL2Print();
// Searches for particular page number's in TLB. If hit the physical address is returned else returns -1, second paramenter - error = ERROR_PAGE_NUM_NOT_FOUND. Also updates the corresponding lru
unsigned int TLBL2Search(unsigned int pageNum, unsigned int *error);
// Replaces a block in tlb with the new block - with new pageNum and frameNum mapping. Returns the index where the new entry was put.
int TLBL2Update (unsigned int pageNum, unsigned int frameNum);
// Mimics the entry of index being used and hence updates the LRU corresponding to the index.
int TLBL2UpdateLru(int index);
// Returns the index of the lru entry in the TLB.
int TLBL2GetLruIndex();
// Returns the first invalid entry in the TLB.
int TLBL2GetFirstInvalidEntry();