ETISS 0.11.2
ExtendableTranslatingInstructionSetSimulator(version0.11.2)
Loading...
Searching...
No Matches
PTE.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2//
3// This file is part of ETISS. It is licensed under the BSD 3-Clause License; you may not use this file except in
4// compliance with the License. You should have received a copy of the license along with this project. If not, see the
5// LICENSE file.
6
17#include "etiss/mm/PTE.h"
18
19namespace etiss
20{
21namespace mm
22{
23
24void PTE::Update(uint64_t new_pte)
25{
26
27 if (PTEFormat::Instance().GetFormatMap().find(std::string("PPN")) == PTEFormat::Instance().GetFormatMap().end())
28 {
31 etiss::log(etiss::FATALERROR, "PPN not defined in PTE format");
32 }
33
34 std::pair<uint32_t, uint32_t> bit_field = PTEFormat::Instance().GetFormatMap().find(std::string("PPN"))->second;
35 if (new_pte & (~GenerateMask(PTEFormat::Instance().GetPTELength())))
36 {
37 std::stringstream msg;
38 msg << "PTE value: [0x" << std::hex << new_pte << "] exceed the format length " << std::dec
39 << PTEFormat::Instance().GetPTELength() << "." << std::endl;
41 etiss::log(etiss::FATALERROR, msg.str());
42 }
43
44 ppn_val_ = new_pte >> bit_field.second;
45 pte_val_ = new_pte;
46}
47
48uint64_t PTE::GetByName(std::string const name) const
49{
50 PTEFormatMap::const_iterator itr = PTEFormat::Instance().GetFormatMap().find(name);
51 if (itr == PTEFormat::Instance().GetFormatMap().end())
52 {
53 std::stringstream msg;
54 msg << "Trying to get value of non-existed Flag in PTE: " << name << std::endl;
56 etiss::log(etiss::FATALERROR, msg.str());
57 }
58 std::pair<uint32_t, uint32_t> bit_field = itr->second;
59 uint32_t msb_pos = bit_field.first;
60 uint32_t lsb_pos = bit_field.second;
61 uint32_t len = msb_pos - lsb_pos + 1;
62 return (pte_val_ >> lsb_pos) & GenerateMask(len);
63}
64
65void PTE::SetFlagByName(std::string name, uint64_t val)
66{
67 PTEFormatMap::const_iterator itr = PTEFormat::Instance().GetFormatMap().find(name);
68 if (itr == PTEFormat::Instance().GetFormatMap().end())
69 {
70 std::stringstream msg;
71 msg << "Trying to set value of non-existed Flag in PTE: " << name << std::endl;
73 etiss::log(etiss::FATALERROR, msg.str());
74 }
75 std::pair<uint32_t, uint32_t> bit_field = itr->second;
76 uint32_t i = 0;
77 do
78 {
79 if (val & (static_cast<uint64_t>(1) << i))
80 SetBit(i + bit_field.second);
81 ++i;
82 } while (i <= bit_field.first);
83}
84
85void PTE::ClearFlagByName(std::string name)
86{
87 PTEFormatMap::const_iterator itr = PTEFormat::Instance().GetFormatMap().find(name);
88 if (itr == PTEFormat::Instance().GetFormatMap().end())
89 {
90 std::stringstream msg;
91 msg << "Trying to clear value of non-existed Flag in PTE: " << name << std::endl;
93 etiss::log(etiss::FATALERROR, msg.str());
94 }
95 std::pair<uint32_t, uint32_t> bit_field = itr->second;
96 uint32_t i = 0;
97 do
98 {
99 ClearBit(i + bit_field.second);
100 ++i;
101 } while (i <= bit_field.first);
102}
103
105{
106 std::cout << "PTE length : " << PTEFormat::Instance().GetPTELength() << std::endl;
107 std::cout << "PTE entry value: 0x" << std::hex << pte_val_ << std::endl;
108 std::cout << "Bit field details: " << std::endl;
109 PTEFormatMap::const_iterator itr = PTEFormat::Instance().GetFormatMap().begin();
110 for (; itr != PTEFormat::Instance().GetFormatMap().end(); ++itr)
111 {
112 std::string name = itr->first;
114 std::cout << "Value of " << name << " : 0x" << std::hex << GetByName(name) << std::endl;
115 }
116 return;
117}
118
119} // namespace mm
120} // namespace etiss
static __inline__ uint32_t
Definition arm_cde.h:25
static __inline__ uint64_t
Definition arm_cde.h:31
static PTEFormat & Instance()
Get the singleton instance.
Definition PTEFormat.h:34
uint32_t GetPTELength() const
Definition PTEFormat.h:57
void DumpBitFild(std::string name)
Dump the details of the bit field according to given name.
Definition PTEFormat.cpp:28
PTEFormatMap & GetFormatMap()
Definition PTEFormat.h:59
void Dump()
Dump the details of the whole PTE format.
Definition PTEFormat.cpp:43
uint64_t ppn_val_
Definition PTE.h:100
void ClearFlagByName(std::string name)
Clear the bit field value with its name.
Definition PTE.cpp:85
uint64_t GetByName(std::string const name) const
Get the bit field value with its name.
Definition PTE.cpp:48
void Dump()
Dump the details of the PTE entry.
Definition PTE.cpp:104
void ClearBit(uint32_t pos)
Definition PTE.h:96
void SetBit(uint32_t pos)
Definition PTE.h:94
uint64_t pte_val_
Definition PTE.h:101
void SetFlagByName(std::string name, uint64_t val)
Set the bit field value with its name.
Definition PTE.cpp:65
void Update(uint64_t new_pte)
Update the PTE with a new value.
Definition PTE.cpp:24
uint64_t GenerateMask(uint64_t len) const
Definition PTE.h:84
forwards: include/jit/*
Definition Benchmark.h:17
@ FATALERROR
Definition Misc.h:84
void log(Verbosity level, std::string msg)
write log message at the given level.
Definition Misc.cpp:94