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