forked from chipsalliance/VeeR-ISS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tlb.cpp
55 lines (47 loc) · 1.09 KB
/
Tlb.cpp
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
#include <cmath>
#include "VirtMem.hpp"
using namespace WdRiscv;
Tlb::Tlb(unsigned size)
: entries_(size)
{
}
void
Tlb::insertEntry(uint64_t virtPageNum, uint64_t physPageNum, uint32_t asid,
bool global, bool isUser, bool read, bool write, bool exec)
{
TlbEntry* best = nullptr;
for (size_t i = 0; i < entries_.size(); ++i)
{
auto& entry = entries_[i];
if (not entry.valid_ or (best and entry.time_ < best->time_))
best = &entry;
}
best->valid_ = true;
best->virtPageNum_ = virtPageNum;
best->physPageNum_ = physPageNum;
best->time_ = time_++;
best->asid_ = asid;
best->global_ = global;
best->user_ = isUser;
best->read_ = read;
best->write_ = write;
best->exec_ = exec;
}
void
Tlb::insertEntry(const TlbEntry& te)
{
TlbEntry* best = nullptr;
for (size_t i = 0; i < entries_.size(); ++i)
{
auto& entry = entries_[i];
if (not entry.valid_)
{
best = &entry;
break;
}
if (not best or entry.time_ < best->time_)
best = &entry;
}
*best = te;
best->time_ = time_++;
}