ETISS 0.11.2
ExtendableTranslatingInstructionSetSimulator(version0.11.2)
Loading...
Searching...
No Matches
Translation.h
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
7#ifndef ETISS_INCLUDE_TRANSLATION_H
8#define ETISS_INCLUDE_TRANSLATION_H
9
10#include "etiss/Misc.h"
11
12#include <memory>
13#include <unordered_map>
14
15namespace etiss
16{
17
18typedef etiss::int32 (*ExecBlockCall)(ETISS_CPU *cpu, ETISS_System *system, void **plugin_pointers);
19
24{
25 public:
26 const etiss::uint64 start;
27 const etiss::uint64 end;
30 unsigned refcount;
32 bool valid;
33 const std::shared_ptr<void> jitlib;
34 BlockLink(etiss::uint64 start, etiss::uint64 end, ExecBlockCall execBlock, std::shared_ptr<void> lib);
35 ~BlockLink();
40 static inline void incrRef(BlockLink *link) { link->refcount++; }
45 static inline void decrRef(BlockLink *&link)
46 {
47 link->refcount--;
48 if (unlikely(link->refcount == 0))
49 {
50 delete link;
51 }
52 link = 0;
53 }
60 static inline void updateRef(BlockLink *&link, BlockLink *newValue)
61 {
62 if (link == newValue)
63 {
64 return;
65 }
66 if (likely(link != 0))
67 {
68 link->refcount--;
69 if (unlikely(link->refcount == 0))
70 {
71 delete link;
72 }
73 }
74 if (likely(newValue != 0))
75 {
76 incrRef(newValue);
77 }
78 link = newValue;
79 }
80};
81
83{
84 private:
85 std::shared_ptr<etiss::CPUArch> &archptr_;
86 std::shared_ptr<etiss::JIT> &jitptr_;
89 std::list<std::shared_ptr<etiss::Plugin>> &plugins_;
95
108
110
111 std::unordered_map<etiss::uint64, std::list<BlockLink *>> blockmap_;
112#if ETISS_TRANSLATOR_STAT
113 etiss::uint64 next_count_;
114 etiss::uint64 branch_count_;
115 etiss::uint64 miss_count_;
116#endif
117 public:
118 Translation(std::shared_ptr<etiss::CPUArch> &arch, std::shared_ptr<etiss::JIT> &jit,
119 std::list<std::shared_ptr<etiss::Plugin>> &plugins, ETISS_System &system, ETISS_CPU &cpu);
120 ~Translation();
121 void **init();
126 inline BlockLink *getBlockFast(BlockLink *prev, const etiss::uint64 &instructionindex)
127 {
128 if (prev != 0)
129 {
130 BlockLink *bl = prev->next;
131 if (instructionindex >= prev->end && bl != 0 && bl->end > instructionindex)
132 { // ->next MUST always start immediately after the current block since it is not checked here
133 // check if block is invalid
134 if (bl->valid)
135 {
136#if ETISS_TRANSLATOR_STAT
137 next_count_++;
138#endif
139 return bl;
140 }
141 else
142 {
143 BlockLink::updateRef(prev->next, 0);
144 }
145 }
146 bl = prev->branch;
147 if (bl != 0 && bl->start <= instructionindex && bl->end > instructionindex)
148 {
149 // check if block is invalid
150 if (bl->valid)
151 { // check
152#if ETISS_TRANSLATOR_STAT
153 branch_count_++;
154#endif
155 return bl;
156 }
157 else
158 {
160 }
161 }
162 }
163#if ETISS_TRANSLATOR_STAT
164 miss_count_++;
165#endif
166 return getBlock(prev, instructionindex);
167 }
168
169 BlockLink *getBlock(BlockLink *prev, const etiss::uint64 &instructionindex);
170
171 etiss::int32 translateBlock(CodeBlock &cb);
172
173 void unloadBlocksAll();
174
175 void unloadBlocks(etiss::uint64 startindex = 0, etiss::uint64 endindex = ((etiss::uint64)((etiss::int64)-1)));
176
177 std::string disasm(uint8_t *buf, unsigned len, int &append);
178
179 private:
184};
185
186} // namespace etiss
187
188#endif // ETISS_INCLUDE_TRANSLATION_H
general configuration and logging
static __inline__ uint64_t
Definition arm_cde.h:31
static __inline__ uint8_t
Definition arm_mve.h:323
#define likely(x)
Definition types.h:35
#define unlikely(x)
Definition types.h:36
the interface to translate instructions of and processor architecture
Definition CPUArch.h:116
A list of CodeSets.
Definition CodePart.h:532
compiler interface for just in time compilation of generated C code
Definition JIT.h:29
allows to add code to the translation of instructions
Definition Plugin.h:222
std::string disasm(uint8_t *buf, unsigned len, int &append)
etiss::instr::ModedInstructionSet * mis_
etiss::JIT *const jit_
Definition Translation.h:88
uint64_t tblockcount
countes translated blocks. needed to guarantee unique block function names
std::list< std::shared_ptr< etiss::Plugin > > & plugins_
Definition Translation.h:89
size_t plugins_array_size_
Definition Translation.h:94
etiss::TranslationPlugin ** plugins_array_
Definition Translation.h:92
void unloadBlocks(etiss::uint64 startindex=0, etiss::uint64 endindex=((etiss::uint64)((etiss::int64) -1)))
etiss::CPUArch *const arch_
Definition Translation.h:87
BlockLink * getBlockFast(BlockLink *prev, const etiss::uint64 &instructionindex)
CALL THIS function NOT getBlock(...) since getBlock will not check next/branch references.
void ** plugins_handle_array_
Definition Translation.h:93
std::unordered_map< etiss::uint64, std::list< BlockLink * > > blockmap_
std::shared_ptr< etiss::CPUArch > & archptr_
Definition Translation.h:85
ETISS_CPU & cpu_
Definition Translation.h:91
const uint64_t id
unique id used to generate unique function names across translation instances
etiss::int32 translateBlock(CodeBlock &cb)
void(* plugins_finalizeCodeBlock_)(etiss::TranslationPlugin **, CodeBlock &)
Function pointer, the function is getting defined in Translation::init via template function etiss::c...
BlockLink * getBlock(BlockLink *prev, const etiss::uint64 &instructionindex)
void(* plugins_initCodeBlock_)(etiss::TranslationPlugin **, CodeBlock &)
Function pointer, the function is getting defined in Translation::init via template function etiss::c...
std::shared_ptr< etiss::JIT > & jitptr_
Definition Translation.h:86
ETISS_System & system_
Definition Translation.h:90
holds etiss::instr::VariableInstructionSet instances for different modes.
forwards: include/jit/*
Definition Benchmark.h:17
etiss::int32(* ExecBlockCall)(ETISS_CPU *cpu, ETISS_System *system, void **plugin_pointers)
Definition Translation.h:18
basic cpu state structure needed for execution of any cpu architecture.
Definition CPU.h:51
memory access and time synchronization functions.
Definition System.h:40