5 #ifndef V8_SIMULATOR_BASE_H_ 6 #define V8_SIMULATOR_BASE_H_ 10 #include "src/globals.h" 11 #include "src/isolate.h" 13 #if defined(USE_SIMULATOR) 24 static void InitializeOncePerProcess();
25 static void GlobalTearDown();
27 static base::Mutex* redirection_mutex() {
return redirection_mutex_; }
28 static Redirection* redirection() {
return redirection_; }
29 static void set_redirection(Redirection* r) { redirection_ = r; }
31 static base::Mutex* i_cache_mutex() {
return i_cache_mutex_; }
32 static base::CustomMatcherHashMap* i_cache() {
return i_cache_; }
35 static Address RedirectExternalReference(Address external_function,
36 ExternalReference::Type type);
39 template <
typename Return,
typename SimT,
typename CallImpl,
typename... Args>
40 static Return VariadicCall(SimT* sim, CallImpl call, Address entry,
44 std::array<intptr_t,
sizeof...(args)> args_arr{{ConvertArg(args)...}};
45 intptr_t ret = (sim->*call)(entry, args_arr.size(), args_arr.data());
46 return ConvertReturn<Return>(ret);
51 static typename std::enable_if<std::is_integral<T>::value, T>::type
52 ConvertReturn(intptr_t ret) {
53 static_assert(
sizeof(T) <=
sizeof(intptr_t),
"type bigger than ptrsize");
54 return static_cast<T
>(ret);
59 static typename std::enable_if<std::is_pointer<T>::value, T>::type
60 ConvertReturn(intptr_t ret) {
61 return reinterpret_cast<T
>(ret);
66 static typename std::enable_if<std::is_void<T>::value, T>::type ConvertReturn(
70 static base::Mutex* redirection_mutex_;
71 static Redirection* redirection_;
73 static base::Mutex* i_cache_mutex_;
74 static base::CustomMatcherHashMap* i_cache_;
81 static typename std::enable_if<std::is_integral<T>::value, intptr_t>::type
83 static_assert(
sizeof(T) <=
sizeof(intptr_t),
"type bigger than ptrsize");
84 #if V8_TARGET_ARCH_MIPS64 87 using signed_t =
typename std::make_signed<T>::type;
88 return static_cast<intptr_t
>(
static_cast<signed_t
>(arg));
92 return static_cast<intptr_t
>(arg);
98 static typename std::enable_if<std::is_pointer<T>::value, intptr_t>::type
100 return reinterpret_cast<intptr_t
>(arg);
121 Redirection(Address external_function, ExternalReference::Type type);
123 Address address_of_instruction() {
124 #if ABI_USES_FUNCTION_DESCRIPTORS 125 return reinterpret_cast<Address
>(function_descriptor_);
127 return reinterpret_cast<Address
>(&instruction_);
131 void* external_function() {
132 return reinterpret_cast<void*
>(external_function_);
134 ExternalReference::Type type() {
return type_; }
136 static Redirection* Get(Address external_function,
137 ExternalReference::Type type);
139 static Redirection* FromInstruction(Instruction* instruction) {
140 Address addr_of_instruction =
reinterpret_cast<Address
>(instruction);
141 Address addr_of_redirection =
142 addr_of_instruction - offsetof(Redirection, instruction_);
143 return reinterpret_cast<Redirection*
>(addr_of_redirection);
146 static void* ReverseRedirection(intptr_t reg) {
147 Redirection* redirection = FromInstruction(
148 reinterpret_cast<Instruction*>(reinterpret_cast<void*>(reg)));
149 return redirection->external_function();
152 static void DeleteChain(Redirection* redirection) {
153 while (redirection !=
nullptr) {
154 Redirection* next = redirection->next_;
161 Address external_function_;
163 ExternalReference::Type type_;
165 #if ABI_USES_FUNCTION_DESCRIPTORS 166 intptr_t function_descriptor_[3];
173 #endif // defined(USE_SIMULATOR) 174 #endif // V8_SIMULATOR_BASE_H_