OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <limits.h> | 5 #include <limits.h> |
6 #include <stdarg.h> | 6 #include <stdarg.h> |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "src/v8.h" | 10 #include "src/v8.h" |
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 registers_[ra] = bad_ra; | 982 registers_[ra] = bad_ra; |
983 InitializeCoverage(); | 983 InitializeCoverage(); |
984 for (int i = 0; i < kNumExceptions; i++) { | 984 for (int i = 0; i < kNumExceptions; i++) { |
985 exceptions[i] = 0; | 985 exceptions[i] = 0; |
986 } | 986 } |
987 | 987 |
988 last_debugger_input_ = NULL; | 988 last_debugger_input_ = NULL; |
989 } | 989 } |
990 | 990 |
991 | 991 |
992 Simulator::~Simulator() { | 992 Simulator::~Simulator() { free(stack_); } |
993 } | |
994 | 993 |
995 | 994 |
996 // When the generated code calls an external reference we need to catch that in | 995 // When the generated code calls an external reference we need to catch that in |
997 // the simulator. The external reference will be a function compiled for the | 996 // the simulator. The external reference will be a function compiled for the |
998 // host architecture. We need to call that function instead of trying to | 997 // host architecture. We need to call that function instead of trying to |
999 // execute it with the simulator. We do that by redirecting the external | 998 // execute it with the simulator. We do that by redirecting the external |
1000 // reference to a swi (software-interrupt) instruction that is handled by | 999 // reference to a swi (software-interrupt) instruction that is handled by |
1001 // the simulator. We write the original destination of the jump just at a known | 1000 // the simulator. We write the original destination of the jump just at a known |
1002 // offset from the swi instruction so the simulator knows what to call. | 1001 // offset from the swi instruction so the simulator knows what to call. |
1003 class Redirection { | 1002 class Redirection { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1039 addr_of_swi - OFFSET_OF(Redirection, swi_instruction_); | 1038 addr_of_swi - OFFSET_OF(Redirection, swi_instruction_); |
1040 return reinterpret_cast<Redirection*>(addr_of_redirection); | 1039 return reinterpret_cast<Redirection*>(addr_of_redirection); |
1041 } | 1040 } |
1042 | 1041 |
1043 static void* ReverseRedirection(int32_t reg) { | 1042 static void* ReverseRedirection(int32_t reg) { |
1044 Redirection* redirection = FromSwiInstruction( | 1043 Redirection* redirection = FromSwiInstruction( |
1045 reinterpret_cast<Instruction*>(reinterpret_cast<void*>(reg))); | 1044 reinterpret_cast<Instruction*>(reinterpret_cast<void*>(reg))); |
1046 return redirection->external_function(); | 1045 return redirection->external_function(); |
1047 } | 1046 } |
1048 | 1047 |
| 1048 static void DeleteChain(Redirection* redirection) { |
| 1049 while (redirection != nullptr) { |
| 1050 Redirection* next = redirection->next_; |
| 1051 delete redirection; |
| 1052 redirection = next; |
| 1053 } |
| 1054 } |
| 1055 |
1049 private: | 1056 private: |
1050 void* external_function_; | 1057 void* external_function_; |
1051 uint32_t swi_instruction_; | 1058 uint32_t swi_instruction_; |
1052 ExternalReference::Type type_; | 1059 ExternalReference::Type type_; |
1053 Redirection* next_; | 1060 Redirection* next_; |
1054 }; | 1061 }; |
1055 | 1062 |
1056 | 1063 |
| 1064 // static |
| 1065 void Simulator::TearDown(HashMap* i_cache, Redirection* first) { |
| 1066 Redirection::DeleteChain(first); |
| 1067 if (i_cache != nullptr) { |
| 1068 for (HashMap::Entry* entry = i_cache->Start(); entry != nullptr; |
| 1069 entry = i_cache->Next(entry)) { |
| 1070 delete static_cast<CachePage*>(entry->value); |
| 1071 } |
| 1072 delete i_cache; |
| 1073 } |
| 1074 } |
| 1075 |
| 1076 |
1057 void* Simulator::RedirectExternalReference(void* external_function, | 1077 void* Simulator::RedirectExternalReference(void* external_function, |
1058 ExternalReference::Type type) { | 1078 ExternalReference::Type type) { |
1059 Redirection* redirection = Redirection::Get(external_function, type); | 1079 Redirection* redirection = Redirection::Get(external_function, type); |
1060 return redirection->address_of_swi_instruction(); | 1080 return redirection->address_of_swi_instruction(); |
1061 } | 1081 } |
1062 | 1082 |
1063 | 1083 |
1064 // Get the active Simulator for the current thread. | 1084 // Get the active Simulator for the current thread. |
1065 Simulator* Simulator::current(Isolate* isolate) { | 1085 Simulator* Simulator::current(Isolate* isolate) { |
1066 v8::internal::Isolate::PerIsolateThreadData* isolate_data = | 1086 v8::internal::Isolate::PerIsolateThreadData* isolate_data = |
(...skipping 2467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3534 } | 3554 } |
3535 | 3555 |
3536 | 3556 |
3537 #undef UNSUPPORTED | 3557 #undef UNSUPPORTED |
3538 | 3558 |
3539 } } // namespace v8::internal | 3559 } } // namespace v8::internal |
3540 | 3560 |
3541 #endif // USE_SIMULATOR | 3561 #endif // USE_SIMULATOR |
3542 | 3562 |
3543 #endif // V8_TARGET_ARCH_MIPS | 3563 #endif // V8_TARGET_ARCH_MIPS |
OLD | NEW |