ETISS 0.11.2
ExtendableTranslatingInstructionSetSimulator(version0.11.2)
Loading...
Searching...
No Matches
VirtualStructMemory.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
9
10namespace etiss
11{
12namespace plugin
13{
14
16 const etiss::VirtualStruct &str, std::function<uint64_t(etiss::VirtualStruct::Field *, bool &dontMount)> mountPoint,
17 bool littleendian)
18 : mem_(str)
19{
20
21 startaddr_ = std::numeric_limits<uint64_t>::max();
22 endaddr_ = 0;
23
24 ((etiss::VirtualStruct *)&str)
25 ->foreachField(
26 [&](std::shared_ptr<VirtualStruct::Field> field)
27 {
28 references.push_back(field);
29 etiss::VirtualStruct::Field *f = (field).get();
30
31 bool dontMount = false;
32 uint64_t addr = mountPoint(f, dontMount);
33
34 if (dontMount)
35 return;
36
37 if (addr < startaddr_)
38 startaddr_ = addr;
39
40 if (endaddr_ < (addr + f->width_))
41 endaddr_ = addr + f->width_;
42
43 for (size_t i = 0; i < f->width_; ++i)
44 {
45 // auto m =
46 memmap_.insert(
47 std::make_pair(addr + i, std::make_pair(f, (littleendian ? i : (f->width_ - 1 - i)))));
48 // etiss::log(etiss::VERBOSE,"mapped:
49 // ",m.first->first,m.first->second.second,m.first->second.first->name_);
50 }
51 });
52}
53
58
59bool VirtualStructMemory::read(bool debug, ETISS_CPU *cpu, etiss::uint64 addr, etiss::uint8 *buf, etiss::uint32 len)
60{
61
62 for (unsigned i = 0; i < len; ++i)
63 {
64 auto find = memmap_.find(addr + i);
65 if (find != memmap_.end())
66 {
67 etiss::VirtualStruct::Field *f = find->second.first;
68 size_t off = find->second.second << 3;
69 uint64_t fval = f->read();
70 fval = fval >> off;
71 buf[i] = (uint8_t)(fval & 0xFF);
72 }
73 else
74 {
75 buf[i] = 0;
76 }
77 }
78
79 return true;
80}
81bool VirtualStructMemory::write(bool debug, ETISS_CPU *cpu, etiss::uint64 addr, etiss::uint8 *buf, etiss::uint32 len)
82{
83
84 for (unsigned i = 0; i < len; ++i)
85 {
86 auto find = memmap_.find(addr + i);
87 if (find != memmap_.end())
88 {
89 etiss::VirtualStruct::Field *f = find->second.first;
90 size_t off = find->second.second << 3;
91 uint64_t fval = f->read();
92 uint64_t mask = 0xFF;
93 mask = mask << off;
94 fval = fval & ~mask;
95 // uint64_t fvaltest = (((uint64_t)(uint8_t)buf[i]) << off); // DNM DEBUG
96 fval = fval | (((uint64_t)(uint8_t)buf[i]) << off);
97 f->write(fval);
98 {
99 std::stringstream ss;
100 ss << "write to field " << f->name_ << "{" << f->prettyname_ << "}: 0x" << std::hex << f->read()
101 << " (offset: 0x" << std::hex << find->second.second << ")" << std::endl;
102 // DEBUG DNM
103 // std::cout << "VirtualStructMemory::write: " << " write to field " << f->name_ << "{" <<
104 // f->prettyname_ << "}: 0x" << std::hex << f->read() << " val=0x"<< fvaltest << "(offset: 0x" <<
105 // std::hex << find->second.second << ")" << std::endl; etiss::log(etiss::VERBOSE,ss.str());
106 }
107 }
108 else
109 {
110 // ignore
111 }
112 }
113
114 return true;
115}
116std::set<etiss::VirtualStruct::Field *> VirtualStructMemory::getMappedFields()
117{
118
119 std::set<etiss::VirtualStruct::Field *> ret;
120
121 for (auto iter = memmap_.begin(); iter != memmap_.end(); ++iter)
122 {
123 ret.insert(iter->second.first);
124 }
125
126 return ret;
127}
128
129} // namespace plugin
130} // 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()
forwards: include/jit/*
Definition Benchmark.h:17
basic cpu state structure needed for execution of any cpu architecture.
Definition CPU.h:51