ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
PTE.cpp
Go to the documentation of this file.
1 
55 #include "etiss/mm/PTE.h"
56 
57 namespace etiss
58 {
59 namespace mm
60 {
61 
62 void PTE::Update(uint64_t new_pte)
63 {
64 
65  if (PTEFormat::Instance().GetFormatMap().find(std::string("PPN")) == PTEFormat::Instance().GetFormatMap().end())
66  {
69  etiss::log(etiss::FATALERROR, "PPN not defined in PTE format");
70  }
71 
72  std::pair<uint32_t, uint32_t> bit_field = PTEFormat::Instance().GetFormatMap().find(std::string("PPN"))->second;
73  if (new_pte & (~GenerateMask(PTEFormat::Instance().GetPTELength())))
74  {
75  std::stringstream msg;
76  msg << "PTE value: [0x" << std::hex << new_pte << "] exceed the format length " << std::dec
77  << PTEFormat::Instance().GetPTELength() << "." << std::endl;
79  etiss::log(etiss::FATALERROR, msg.str());
80  }
81 
82  ppn_val_ = new_pte >> bit_field.second;
83  ;
84  pte_val_ = new_pte;
85 }
86 
87 uint64_t PTE::GetByName(std::string const name) const
88 {
89  PTEFormatMap::const_iterator itr = PTEFormat::Instance().GetFormatMap().find(name);
90  if (itr == PTEFormat::Instance().GetFormatMap().end())
91  {
92  std::stringstream msg;
93  msg << "Trying to get value of non-existed Flag in PTE: " << name << std::endl;
95  etiss::log(etiss::FATALERROR, msg.str());
96  }
97  std::pair<uint32_t, uint32_t> bit_field = itr->second;
98  uint32_t msb_pos = bit_field.first;
99  uint32_t lsb_pos = bit_field.second;
100  uint32_t len = msb_pos - lsb_pos + 1;
101  return (pte_val_ >> lsb_pos) & GenerateMask(len);
102 }
103 
104 void PTE::SetFlagByName(std::string name, uint64_t val)
105 {
106  PTEFormatMap::const_iterator itr = PTEFormat::Instance().GetFormatMap().find(name);
107  if (itr == PTEFormat::Instance().GetFormatMap().end())
108  {
109  std::stringstream msg;
110  msg << "Trying to set value of non-existed Flag in PTE: " << name << std::endl;
112  etiss::log(etiss::FATALERROR, msg.str());
113  }
114  std::pair<uint32_t, uint32_t> bit_field = itr->second;
115  uint32_t i = 0;
116  do
117  {
118  if (val & (static_cast<uint64_t>(1) << i))
119  SetBit(i + bit_field.second);
120  ++i;
121  } while (i <= bit_field.first);
122 }
123 
124 void PTE::ClearFlagByName(std::string name)
125 {
126  PTEFormatMap::const_iterator itr = PTEFormat::Instance().GetFormatMap().find(name);
127  if (itr == PTEFormat::Instance().GetFormatMap().end())
128  {
129  std::stringstream msg;
130  msg << "Trying to clear value of non-existed Flag in PTE: " << name << std::endl;
132  etiss::log(etiss::FATALERROR, msg.str());
133  }
134  std::pair<uint32_t, uint32_t> bit_field = itr->second;
135  uint32_t i = 0;
136  do
137  {
138  ClearBit(i + bit_field.second);
139  ++i;
140  } while (i <= bit_field.first);
141 }
142 
143 void PTE::Dump()
144 {
145  std::cout << "PTE length : " << PTEFormat::Instance().GetPTELength() << std::endl;
146  std::cout << "PTE entry value: 0x" << std::hex << pte_val_ << std::endl;
147  std::cout << "Bit field details: " << std::endl;
148  PTEFormatMap::const_iterator itr = PTEFormat::Instance().GetFormatMap().begin();
149  for (; itr != PTEFormat::Instance().GetFormatMap().end(); ++itr)
150  {
151  std::string name = itr->first;
153  std::cout << "Value of " << name << " : 0x" << std::hex << GetByName(name) << std::endl;
154  }
155  return;
156 }
157 
158 } // namespace mm
159 } // 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:70
uint32_t GetPTELength() const
Definition: PTEFormat.h:93
void DumpBitFild(std::string name)
Dump the details of the bit field according to given name.
Definition: PTEFormat.cpp:66
void Dump()
Dump the details of the whole PTE format.
Definition: PTEFormat.cpp:81
PTEFormatMap & GetFormatMap()
Definition: PTEFormat.h:95
uint64_t ppn_val_
Definition: PTE.h:138
void ClearFlagByName(std::string name)
Clear the bit field value with its name.
Definition: PTE.cpp:124
uint64_t GetByName(std::string const name) const
Get the bit field value with its name.
Definition: PTE.cpp:87
void Dump()
Dump the details of the PTE entry.
Definition: PTE.cpp:143
void ClearBit(uint32_t pos)
Definition: PTE.h:134
void SetBit(uint32_t pos)
Definition: PTE.h:132
uint64_t pte_val_
Definition: PTE.h:139
void SetFlagByName(std::string name, uint64_t val)
Set the bit field value with its name.
Definition: PTE.cpp:104
void Update(uint64_t new_pte)
Update the PTE with a new value.
Definition: PTE.cpp:62
uint64_t GenerateMask(uint64_t len) const
Definition: PTE.h:122
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
Definition: Benchmark.h:53
@ FATALERROR
Definition: Misc.h:126
void log(Verbosity level, std::string msg)
write log message at the given level.
Definition: Misc.cpp:125