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 #if V8_TARGET_ARCH_MIPS | 10 #if V8_TARGET_ARCH_MIPS |
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 return start_page == end_page; | 858 return start_page == end_page; |
859 } | 859 } |
860 | 860 |
861 | 861 |
862 void Simulator::set_last_debugger_input(char* input) { | 862 void Simulator::set_last_debugger_input(char* input) { |
863 DeleteArray(last_debugger_input_); | 863 DeleteArray(last_debugger_input_); |
864 last_debugger_input_ = input; | 864 last_debugger_input_ = input; |
865 } | 865 } |
866 | 866 |
867 | 867 |
868 void Simulator::FlushICache(v8::internal::HashMap* i_cache, | 868 void Simulator::FlushICache(base::HashMap* i_cache, |
869 void* start_addr, | 869 void* start_addr, |
870 size_t size) { | 870 size_t size) { |
871 intptr_t start = reinterpret_cast<intptr_t>(start_addr); | 871 intptr_t start = reinterpret_cast<intptr_t>(start_addr); |
872 int intra_line = (start & CachePage::kLineMask); | 872 int intra_line = (start & CachePage::kLineMask); |
873 start -= intra_line; | 873 start -= intra_line; |
874 size += intra_line; | 874 size += intra_line; |
875 size = ((size - 1) | CachePage::kLineMask) + 1; | 875 size = ((size - 1) | CachePage::kLineMask) + 1; |
876 int offset = (start & CachePage::kPageMask); | 876 int offset = (start & CachePage::kPageMask); |
877 while (!AllOnOnePage(start, size - 1)) { | 877 while (!AllOnOnePage(start, size - 1)) { |
878 int bytes_to_flush = CachePage::kPageSize - offset; | 878 int bytes_to_flush = CachePage::kPageSize - offset; |
879 FlushOnePage(i_cache, start, bytes_to_flush); | 879 FlushOnePage(i_cache, start, bytes_to_flush); |
880 start += bytes_to_flush; | 880 start += bytes_to_flush; |
881 size -= bytes_to_flush; | 881 size -= bytes_to_flush; |
882 DCHECK_EQ(0, start & CachePage::kPageMask); | 882 DCHECK_EQ(0, start & CachePage::kPageMask); |
883 offset = 0; | 883 offset = 0; |
884 } | 884 } |
885 if (size != 0) { | 885 if (size != 0) { |
886 FlushOnePage(i_cache, start, size); | 886 FlushOnePage(i_cache, start, size); |
887 } | 887 } |
888 } | 888 } |
889 | 889 |
890 | 890 |
891 CachePage* Simulator::GetCachePage(v8::internal::HashMap* i_cache, void* page) { | 891 CachePage* Simulator::GetCachePage(base::HashMap* i_cache, void* page) { |
892 v8::internal::HashMap::Entry* entry = | 892 base::HashMap::Entry* entry = |
893 i_cache->LookupOrInsert(page, ICacheHash(page)); | 893 i_cache->LookupOrInsert(page, ICacheHash(page)); |
894 if (entry->value == NULL) { | 894 if (entry->value == NULL) { |
895 CachePage* new_page = new CachePage(); | 895 CachePage* new_page = new CachePage(); |
896 entry->value = new_page; | 896 entry->value = new_page; |
897 } | 897 } |
898 return reinterpret_cast<CachePage*>(entry->value); | 898 return reinterpret_cast<CachePage*>(entry->value); |
899 } | 899 } |
900 | 900 |
901 | 901 |
902 // Flush from start up to and not including start + size. | 902 // Flush from start up to and not including start + size. |
903 void Simulator::FlushOnePage(v8::internal::HashMap* i_cache, | 903 void Simulator::FlushOnePage(base::HashMap* i_cache, |
904 intptr_t start, | 904 intptr_t start, |
905 int size) { | 905 int size) { |
906 DCHECK(size <= CachePage::kPageSize); | 906 DCHECK(size <= CachePage::kPageSize); |
907 DCHECK(AllOnOnePage(start, size - 1)); | 907 DCHECK(AllOnOnePage(start, size - 1)); |
908 DCHECK((start & CachePage::kLineMask) == 0); | 908 DCHECK((start & CachePage::kLineMask) == 0); |
909 DCHECK((size & CachePage::kLineMask) == 0); | 909 DCHECK((size & CachePage::kLineMask) == 0); |
910 void* page = reinterpret_cast<void*>(start & (~CachePage::kPageMask)); | 910 void* page = reinterpret_cast<void*>(start & (~CachePage::kPageMask)); |
911 int offset = (start & CachePage::kPageMask); | 911 int offset = (start & CachePage::kPageMask); |
912 CachePage* cache_page = GetCachePage(i_cache, page); | 912 CachePage* cache_page = GetCachePage(i_cache, page); |
913 char* valid_bytemap = cache_page->ValidityByte(offset); | 913 char* valid_bytemap = cache_page->ValidityByte(offset); |
914 memset(valid_bytemap, CachePage::LINE_INVALID, size >> CachePage::kLineShift); | 914 memset(valid_bytemap, CachePage::LINE_INVALID, size >> CachePage::kLineShift); |
915 } | 915 } |
916 | 916 |
917 | 917 |
918 void Simulator::CheckICache(v8::internal::HashMap* i_cache, | 918 void Simulator::CheckICache(base::HashMap* i_cache, |
919 Instruction* instr) { | 919 Instruction* instr) { |
920 intptr_t address = reinterpret_cast<intptr_t>(instr); | 920 intptr_t address = reinterpret_cast<intptr_t>(instr); |
921 void* page = reinterpret_cast<void*>(address & (~CachePage::kPageMask)); | 921 void* page = reinterpret_cast<void*>(address & (~CachePage::kPageMask)); |
922 void* line = reinterpret_cast<void*>(address & (~CachePage::kLineMask)); | 922 void* line = reinterpret_cast<void*>(address & (~CachePage::kLineMask)); |
923 int offset = (address & CachePage::kPageMask); | 923 int offset = (address & CachePage::kPageMask); |
924 CachePage* cache_page = GetCachePage(i_cache, page); | 924 CachePage* cache_page = GetCachePage(i_cache, page); |
925 char* cache_valid_byte = cache_page->ValidityByte(offset); | 925 char* cache_valid_byte = cache_page->ValidityByte(offset); |
926 bool cache_hit = (*cache_valid_byte == CachePage::LINE_VALID); | 926 bool cache_hit = (*cache_valid_byte == CachePage::LINE_VALID); |
927 char* cached_line = cache_page->CachedData(offset & ~CachePage::kLineMask); | 927 char* cached_line = cache_page->CachedData(offset & ~CachePage::kLineMask); |
928 if (cache_hit) { | 928 if (cache_hit) { |
(...skipping 13 matching lines...) Expand all Loading... |
942 if (isolate->simulator_initialized()) return; | 942 if (isolate->simulator_initialized()) return; |
943 isolate->set_simulator_initialized(true); | 943 isolate->set_simulator_initialized(true); |
944 ::v8::internal::ExternalReference::set_redirector(isolate, | 944 ::v8::internal::ExternalReference::set_redirector(isolate, |
945 &RedirectExternalReference); | 945 &RedirectExternalReference); |
946 } | 946 } |
947 | 947 |
948 | 948 |
949 Simulator::Simulator(Isolate* isolate) : isolate_(isolate) { | 949 Simulator::Simulator(Isolate* isolate) : isolate_(isolate) { |
950 i_cache_ = isolate_->simulator_i_cache(); | 950 i_cache_ = isolate_->simulator_i_cache(); |
951 if (i_cache_ == NULL) { | 951 if (i_cache_ == NULL) { |
952 i_cache_ = new v8::internal::HashMap(&ICacheMatch); | 952 i_cache_ = new base::HashMap(&ICacheMatch); |
953 isolate_->set_simulator_i_cache(i_cache_); | 953 isolate_->set_simulator_i_cache(i_cache_); |
954 } | 954 } |
955 Initialize(isolate); | 955 Initialize(isolate); |
956 // Set up simulator support first. Some of this information is needed to | 956 // Set up simulator support first. Some of this information is needed to |
957 // setup the architecture state. | 957 // setup the architecture state. |
958 stack_ = reinterpret_cast<char*>(malloc(stack_size_)); | 958 stack_ = reinterpret_cast<char*>(malloc(stack_size_)); |
959 pc_modified_ = false; | 959 pc_modified_ = false; |
960 icount_ = 0; | 960 icount_ = 0; |
961 break_count_ = 0; | 961 break_count_ = 0; |
962 break_pc_ = NULL; | 962 break_pc_ = NULL; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1055 | 1055 |
1056 private: | 1056 private: |
1057 void* external_function_; | 1057 void* external_function_; |
1058 uint32_t swi_instruction_; | 1058 uint32_t swi_instruction_; |
1059 ExternalReference::Type type_; | 1059 ExternalReference::Type type_; |
1060 Redirection* next_; | 1060 Redirection* next_; |
1061 }; | 1061 }; |
1062 | 1062 |
1063 | 1063 |
1064 // static | 1064 // static |
1065 void Simulator::TearDown(HashMap* i_cache, Redirection* first) { | 1065 void Simulator::TearDown(base::HashMap* i_cache, Redirection* first) { |
1066 Redirection::DeleteChain(first); | 1066 Redirection::DeleteChain(first); |
1067 if (i_cache != nullptr) { | 1067 if (i_cache != nullptr) { |
1068 for (HashMap::Entry* entry = i_cache->Start(); entry != nullptr; | 1068 for (base::HashMap::Entry* entry = i_cache->Start(); entry != nullptr; |
1069 entry = i_cache->Next(entry)) { | 1069 entry = i_cache->Next(entry)) { |
1070 delete static_cast<CachePage*>(entry->value); | 1070 delete static_cast<CachePage*>(entry->value); |
1071 } | 1071 } |
1072 delete i_cache; | 1072 delete i_cache; |
1073 } | 1073 } |
1074 } | 1074 } |
1075 | 1075 |
1076 | 1076 |
1077 void* Simulator::RedirectExternalReference(Isolate* isolate, | 1077 void* Simulator::RedirectExternalReference(Isolate* isolate, |
1078 void* external_function, | 1078 void* external_function, |
(...skipping 3528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4607 | 4607 |
4608 | 4608 |
4609 #undef UNSUPPORTED | 4609 #undef UNSUPPORTED |
4610 | 4610 |
4611 } // namespace internal | 4611 } // namespace internal |
4612 } // namespace v8 | 4612 } // namespace v8 |
4613 | 4613 |
4614 #endif // USE_SIMULATOR | 4614 #endif // USE_SIMULATOR |
4615 | 4615 |
4616 #endif // V8_TARGET_ARCH_MIPS | 4616 #endif // V8_TARGET_ARCH_MIPS |
OLD | NEW |