ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
VirtualStructMemory.cpp
Go to the documentation of this file.
1/*
2
3 @copyright
4
5 <pre>
6
7 Copyright 2018 Infineon Technologies AG
8
9 This file is part of ETISS tool, see <https://github.com/tum-ei-eda/etiss>.
10
11 The initial version of this software has been created with the funding support by the German Federal
12 Ministry of Education and Research (BMBF) in the project EffektiV under grant 01IS13022.
13
14 Redistribution and use in source and binary forms, with or without modification, are permitted
15 provided that the following conditions are met:
16
17 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
18 the following disclaimer.
19
20 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
21 and the following disclaimer in the documentation and/or other materials provided with the distribution.
22
23 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
24 or promote products derived from this software without specific prior written permission.
25
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
27 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
28 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
29 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 POSSIBILITY OF SUCH DAMAGE.
34
35 </pre>
36
37 @author Chair of Electronic Design Automation, TUM
38
39 @version 0.1
40
41*/
42
44
45namespace etiss
46{
47namespace plugin
48{
49
51 const etiss::VirtualStruct &str, std::function<uint64_t(etiss::VirtualStruct::Field *, bool &dontMount)> mountPoint,
52 bool littleendian)
53 : mem_(str)
54{
55
56 startaddr_ = std::numeric_limits<uint64_t>::max();
57 endaddr_ = 0;
58
59 ((etiss::VirtualStruct *)&str)->foreachField([&](std::shared_ptr<VirtualStruct::Field> field) {
60 references.push_back(field);
61 etiss::VirtualStruct::Field *f = (field).get();
62
63 bool dontMount = false;
64 uint64_t addr = mountPoint(f, dontMount);
65
66 if (dontMount)
67 return;
68
69 if (addr < startaddr_)
70 startaddr_ = addr;
71
72 if (endaddr_ < (addr + f->width_))
73 endaddr_ = addr + f->width_;
74
75 for (size_t i = 0; i < f->width_; ++i)
76 {
77 // auto m =
78 memmap_.insert(std::make_pair(addr + i, std::make_pair(f, (littleendian ? i : (f->width_ - 1 - i)))));
79 // etiss::log(etiss::VERBOSE,"mapped: ",m.first->first,m.first->second.second,m.first->second.first->name_);
80 }
81 });
82}
83
88
89bool VirtualStructMemory::read(bool debug, ETISS_CPU *cpu, etiss::uint64 addr, etiss::uint8 *buf, etiss::uint32 len)
90{
91
92 for (unsigned i = 0; i < len; ++i)
93 {
94 auto find = memmap_.find(addr + i);
95 if (find != memmap_.end())
96 {
97 etiss::VirtualStruct::Field *f = find->second.first;
98 size_t off = find->second.second << 3;
99 uint64_t fval = f->read();
100 fval = fval >> off;
101 buf[i] = (uint8_t)(fval & 0xFF);
102 }
103 else
104 {
105 buf[i] = 0;
106 }
107 }
108
109 return true;
110}
111bool VirtualStructMemory::write(bool debug, ETISS_CPU *cpu, etiss::uint64 addr, etiss::uint8 *buf, etiss::uint32 len)
112{
113
114 for (unsigned i = 0; i < len; ++i)
115 {
116 auto find = memmap_.find(addr + i);
117 if (find != memmap_.end())
118 {
119 etiss::VirtualStruct::Field *f = find->second.first;
120 size_t off = find->second.second << 3;
121 uint64_t fval = f->read();
122 uint64_t mask = 0xFF;
123 mask = mask << off;
124 fval = fval & ~mask;
125 // uint64_t fvaltest = (((uint64_t)(uint8_t)buf[i]) << off); // DNM DEBUG
126 fval = fval | (((uint64_t)(uint8_t)buf[i]) << off);
127 f->write(fval);
128 {
129 std::stringstream ss;
130 ss << "write to field " << f->name_ << "{" << f->prettyname_ << "}: 0x" << std::hex << f->read()
131 << " (offset: 0x" << std::hex << find->second.second << ")" << std::endl;
132 // DEBUG DNM
133 // std::cout << "VirtualStructMemory::write: " << " write to field " << f->name_ << "{" <<
134 // f->prettyname_ << "}: 0x" << std::hex << f->read() << " val=0x"<< fvaltest << "(offset: 0x" <<
135 // std::hex << find->second.second << ")" << std::endl; etiss::log(etiss::VERBOSE,ss.str());
136 }
137 }
138 else
139 {
140 // ignore
141 }
142 }
143
144 return true;
145}
146std::set<etiss::VirtualStruct::Field *> VirtualStructMemory::getMappedFields()
147{
148
149 std::set<etiss::VirtualStruct::Field *> ret;
150
151 for (auto iter = memmap_.begin(); iter != memmap_.end(); ++iter)
152 {
153 ret.insert(iter->second.first);
154 }
155
156 return ret;
157}
158
159} // namespace plugin
160} // namespace etiss
static __inline__ uint64_t
Definition arm_cde.h:31
static __inline__ uint8_t
Definition arm_mve.h:323
a Field instance represents e.g.
const std::string name_
name of the field.
const size_t width_
width in bytes (rounded up if neccessary)
void write(uint64_t)
function to write bits/a value to the Field.
uint64_t read() const
function to read bits/a value from the Field.
const std::string prettyname_
alternative/human readable name of the field.
abstract representation of an module of a simulation which could be a embedded device of the cpu of a...
virtual bool read(bool debug, ETISS_CPU *cpu, etiss::uint64 addr, etiss::uint8 *buf, etiss::uint32 len)
virtual bool write(bool debug, ETISS_CPU *cpu, etiss::uint64 addr, etiss::uint8 *buf, etiss::uint32 len)
VirtualStructMemory(const etiss::VirtualStruct &str, std::function< uint64_t(etiss::VirtualStruct::Field *, bool &)> mountPoint, bool littleendian=true)
std::list< std::shared_ptr< VirtualStruct::Field > > references
std::set< etiss::VirtualStruct::Field * > getMappedFields()
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
Definition Benchmark.h:53
basic cpu state structure needed for execution of any cpu architecture.
Definition CPU.h:89