ETISS 0.11.2
ExtendableTranslatingInstructionSetSimulator(version0.11.2)
Loading...
Searching...
No Matches
SelectiveSysWrapper.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
8#include "etiss/ETISS.h"
9#include "etiss/CPUCore.h"
10#include "etiss/JIT.h"
11
12namespace etiss
13{
14namespace plugin
15{
16
18{
21 std::vector<void *> jitHandles;
22};
23
25{
26 auto ret = new WrapSystem();
27 ret->sys.handle = system->handle;
28 ret->orig = system;
29
30 auto jit = ((CPUCore *)cpu->_etiss_private_handle_)->getJIT();
31 std::set<std::string> headers;
32 headers.insert(etiss::jitFiles());
33 std::string jitErr;
34
35 auto makeWrapper = [&](void *funcPtr, void *handle, bool isDbg, bool isSync, bool isIRead)
36 {
37 std::string funcAddr = std::to_string((uintptr_t)funcPtr);
38 std::string params, cast, call;
39 params += "void *handle";
40 cast += "void*";
41 call += "(void*)" + std::to_string((uintptr_t)handle) + "ull";
42 if (!isDbg)
43 {
44 params += ", ETISS_CPU *cpu";
45 cast += ", ETISS_CPU*";
46 call += ", cpu";
47 }
48 if (!isSync)
49 {
50 params += ", etiss_uint64 addr";
51 cast += ", etiss_uint64";
52 call += ", addr";
53 if (!isIRead)
54 {
55 params += ", etiss_uint8 *buffer";
56 cast += ", etiss_uint8*";
57 call += ", buffer";
58 }
59 params += ", etiss_uint32 length";
60 cast += ", etiss_uint32";
61 call += ", length";
62 }
63
64 std::string code = "#include \"etiss/jit/System.h\"\n";
65 code += "etiss_int32 wrapper(" + params + "){\n";
66 code += " return ((etiss_int32 (*)(" + cast + "))" + funcAddr + ")(" + call + ");\n}\n";
67
68 void *jitHandle = jit->translate(code, headers, {}, {}, jitErr, false);
69 ret->jitHandles.push_back(jitHandle);
70 return jit->getFunction(jitHandle, "wrapper", jitErr);
71 };
72
73 ETISS_System wrapInfo = getWrapInfo(system);
74 ret->sys = *system;
75 if (wrapInfo.iread)
76 {
77 ret->sys.iread =
78 (decltype(ret->sys.iread))makeWrapper((void *)wrapInfo.iread, wrapInfo.handle, false, false, true);
79 }
80 if (wrapInfo.iwrite)
81 {
82 ret->sys.iwrite =
83 (decltype(ret->sys.iwrite))makeWrapper((void *)wrapInfo.iwrite, wrapInfo.handle, false, false, false);
84 }
85 if (wrapInfo.dread)
86 {
87 ret->sys.dread =
88 (decltype(ret->sys.dread))makeWrapper((void *)wrapInfo.dread, wrapInfo.handle, false, false, false);
89 }
90 if (wrapInfo.dwrite)
91 {
92 ret->sys.dwrite =
93 (decltype(ret->sys.dwrite))makeWrapper((void *)wrapInfo.dwrite, wrapInfo.handle, false, false, false);
94 }
95 if (wrapInfo.dbg_read)
96 {
97 ret->sys.dbg_read =
98 (decltype(ret->sys.dbg_read))makeWrapper((void *)wrapInfo.dbg_read, wrapInfo.handle, true, false, false);
99 }
100 if (wrapInfo.dbg_write)
101 {
102 ret->sys.dbg_write =
103 (decltype(ret->sys.dbg_write))makeWrapper((void *)wrapInfo.dbg_write, wrapInfo.handle, true, false, false);
104 }
105 if (wrapInfo.syncTime)
106 {
107 ret->sys.syncTime =
108 (decltype(ret->sys.syncTime))makeWrapper((void *)wrapInfo.syncTime, wrapInfo.handle, false, true, false);
109 }
110
111 return (ETISS_System *)ret;
112}
113
115{
116 auto wrapSys = (WrapSystem *)system;
117 auto jit = ((CPUCore *)cpu->_etiss_private_handle_)->getJIT();
118 for (auto h : wrapSys->jitHandles)
119 {
120 jit->free(h);
121 }
122 ETISS_System *orig = (wrapSys)->orig;
123 delete wrapSys;
124 return orig;
125}
126
127} // namespace plugin
128
129} // namespace etiss
defines main cpu core interface
Header file of the ETISS library.
JIT compiler interface definition.
CPUCore is responsible for the simulation of a CPU core in ETISS.
Definition CPUCore.h:64
ETISS_System * unwrap(ETISS_CPU *cpu, ETISS_System *system) final
undo wrap function call this function will be called AFTER etiss::Plugin::cleanup
virtual ETISS_System getWrapInfo(ETISS_System *origSystem)=0
Defines which System functions to wrap.
ETISS_System * wrap(ETISS_CPU *cpu, ETISS_System *system) final
change/wrap the passed system structure.
forwards: include/jit/*
Definition Benchmark.h:17
std::string jitFiles()
Get ETISS JIT files path.
Definition Misc.cpp:563
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
basic cpu state structure needed for execution of any cpu architecture.
Definition CPU.h:51
void * _etiss_private_handle_
private helper handle for plugins
Definition CPU.h:69
memory access and time synchronization functions.
Definition System.h:40
etiss_int32(* dwrite)(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
write data
Definition System.h:59
etiss_int32(* iread)(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint32 length)
used to simulate an instruction fetch.
Definition System.h:46
void * handle
custom handle that will be passed to the functions of this structure
Definition System.h:78
etiss_int32(* dbg_write)(void *handle, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
direct debug write
Definition System.h:70
etiss_int32(* dbg_read)(void *handle, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
direct debug read
Definition System.h:66
etiss_int32(* dread)(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
read data
Definition System.h:55
void(* syncTime)(void *handle, ETISS_CPU *cpu)
called after a block to synchronize the time
Definition System.h:76
etiss_int32(* iwrite)(void *handle, ETISS_CPU *cpu, etiss_uint64 addr, etiss_uint8 *buffer, etiss_uint32 length)
write instruction data over instruction bus
Definition System.h:50
std::vector< void * > jitHandles