| 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 902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 registers_[ra] = bad_ra; | 913 registers_[ra] = bad_ra; |
| 914 InitializeCoverage(); | 914 InitializeCoverage(); |
| 915 for (int i = 0; i < kNumExceptions; i++) { | 915 for (int i = 0; i < kNumExceptions; i++) { |
| 916 exceptions[i] = 0; | 916 exceptions[i] = 0; |
| 917 } | 917 } |
| 918 | 918 |
| 919 last_debugger_input_ = NULL; | 919 last_debugger_input_ = NULL; |
| 920 } | 920 } |
| 921 | 921 |
| 922 | 922 |
| 923 Simulator::~Simulator() { | 923 Simulator::~Simulator() { free(stack_); } |
| 924 } | |
| 925 | 924 |
| 926 | 925 |
| 927 // When the generated code calls an external reference we need to catch that in | 926 // When the generated code calls an external reference we need to catch that in |
| 928 // the simulator. The external reference will be a function compiled for the | 927 // the simulator. The external reference will be a function compiled for the |
| 929 // host architecture. We need to call that function instead of trying to | 928 // host architecture. We need to call that function instead of trying to |
| 930 // execute it with the simulator. We do that by redirecting the external | 929 // execute it with the simulator. We do that by redirecting the external |
| 931 // reference to a swi (software-interrupt) instruction that is handled by | 930 // reference to a swi (software-interrupt) instruction that is handled by |
| 932 // the simulator. We write the original destination of the jump just at a known | 931 // the simulator. We write the original destination of the jump just at a known |
| 933 // offset from the swi instruction so the simulator knows what to call. | 932 // offset from the swi instruction so the simulator knows what to call. |
| 934 class Redirection { | 933 class Redirection { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 addr_of_swi - OFFSET_OF(Redirection, swi_instruction_); | 969 addr_of_swi - OFFSET_OF(Redirection, swi_instruction_); |
| 971 return reinterpret_cast<Redirection*>(addr_of_redirection); | 970 return reinterpret_cast<Redirection*>(addr_of_redirection); |
| 972 } | 971 } |
| 973 | 972 |
| 974 static void* ReverseRedirection(int64_t reg) { | 973 static void* ReverseRedirection(int64_t reg) { |
| 975 Redirection* redirection = FromSwiInstruction( | 974 Redirection* redirection = FromSwiInstruction( |
| 976 reinterpret_cast<Instruction*>(reinterpret_cast<void*>(reg))); | 975 reinterpret_cast<Instruction*>(reinterpret_cast<void*>(reg))); |
| 977 return redirection->external_function(); | 976 return redirection->external_function(); |
| 978 } | 977 } |
| 979 | 978 |
| 979 static void DeleteChain(Redirection* redirection) { |
| 980 while (redirection != nullptr) { |
| 981 Redirection* next = redirection->next_; |
| 982 delete redirection; |
| 983 redirection = next; |
| 984 } |
| 985 } |
| 986 |
| 980 private: | 987 private: |
| 981 void* external_function_; | 988 void* external_function_; |
| 982 uint32_t swi_instruction_; | 989 uint32_t swi_instruction_; |
| 983 ExternalReference::Type type_; | 990 ExternalReference::Type type_; |
| 984 Redirection* next_; | 991 Redirection* next_; |
| 985 }; | 992 }; |
| 986 | 993 |
| 987 | 994 |
| 995 // static |
| 996 void Simulator::TearDown(HashMap* i_cache, Redirection* first) { |
| 997 Redirection::DeleteChain(first); |
| 998 if (i_cache != nullptr) { |
| 999 for (HashMap::Entry* entry = i_cache->Start(); entry != nullptr; |
| 1000 entry = i_cache->Next(entry)) { |
| 1001 delete static_cast<CachePage*>(entry->value); |
| 1002 } |
| 1003 delete i_cache; |
| 1004 } |
| 1005 } |
| 1006 |
| 1007 |
| 988 void* Simulator::RedirectExternalReference(void* external_function, | 1008 void* Simulator::RedirectExternalReference(void* external_function, |
| 989 ExternalReference::Type type) { | 1009 ExternalReference::Type type) { |
| 990 Redirection* redirection = Redirection::Get(external_function, type); | 1010 Redirection* redirection = Redirection::Get(external_function, type); |
| 991 return redirection->address_of_swi_instruction(); | 1011 return redirection->address_of_swi_instruction(); |
| 992 } | 1012 } |
| 993 | 1013 |
| 994 | 1014 |
| 995 // Get the active Simulator for the current thread. | 1015 // Get the active Simulator for the current thread. |
| 996 Simulator* Simulator::current(Isolate* isolate) { | 1016 Simulator* Simulator::current(Isolate* isolate) { |
| 997 v8::internal::Isolate::PerIsolateThreadData* isolate_data = | 1017 v8::internal::Isolate::PerIsolateThreadData* isolate_data = |
| (...skipping 2753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3751 return address; | 3771 return address; |
| 3752 } | 3772 } |
| 3753 | 3773 |
| 3754 | 3774 |
| 3755 #undef UNSUPPORTED | 3775 #undef UNSUPPORTED |
| 3756 } } // namespace v8::internal | 3776 } } // namespace v8::internal |
| 3757 | 3777 |
| 3758 #endif // USE_SIMULATOR | 3778 #endif // USE_SIMULATOR |
| 3759 | 3779 |
| 3760 #endif // V8_TARGET_ARCH_MIPS64 | 3780 #endif // V8_TARGET_ARCH_MIPS64 |
| OLD | NEW |