| 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_MIPS64 | 10 #if V8_TARGET_ARCH_MIPS64 |
| (...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 intptr_t end_page = ((start + size) & ~CachePage::kPageMask); | 794 intptr_t end_page = ((start + size) & ~CachePage::kPageMask); |
| 795 return start_page == end_page; | 795 return start_page == end_page; |
| 796 } | 796 } |
| 797 | 797 |
| 798 | 798 |
| 799 void Simulator::set_last_debugger_input(char* input) { | 799 void Simulator::set_last_debugger_input(char* input) { |
| 800 DeleteArray(last_debugger_input_); | 800 DeleteArray(last_debugger_input_); |
| 801 last_debugger_input_ = input; | 801 last_debugger_input_ = input; |
| 802 } | 802 } |
| 803 | 803 |
| 804 | 804 void Simulator::FlushICache(base::HashMap* i_cache, void* start_addr, |
| 805 void Simulator::FlushICache(v8::internal::HashMap* i_cache, | |
| 806 void* start_addr, | |
| 807 size_t size) { | 805 size_t size) { |
| 808 int64_t start = reinterpret_cast<int64_t>(start_addr); | 806 int64_t start = reinterpret_cast<int64_t>(start_addr); |
| 809 int64_t intra_line = (start & CachePage::kLineMask); | 807 int64_t intra_line = (start & CachePage::kLineMask); |
| 810 start -= intra_line; | 808 start -= intra_line; |
| 811 size += intra_line; | 809 size += intra_line; |
| 812 size = ((size - 1) | CachePage::kLineMask) + 1; | 810 size = ((size - 1) | CachePage::kLineMask) + 1; |
| 813 int offset = (start & CachePage::kPageMask); | 811 int offset = (start & CachePage::kPageMask); |
| 814 while (!AllOnOnePage(start, size - 1)) { | 812 while (!AllOnOnePage(start, size - 1)) { |
| 815 int bytes_to_flush = CachePage::kPageSize - offset; | 813 int bytes_to_flush = CachePage::kPageSize - offset; |
| 816 FlushOnePage(i_cache, start, bytes_to_flush); | 814 FlushOnePage(i_cache, start, bytes_to_flush); |
| 817 start += bytes_to_flush; | 815 start += bytes_to_flush; |
| 818 size -= bytes_to_flush; | 816 size -= bytes_to_flush; |
| 819 DCHECK_EQ((int64_t)0, start & CachePage::kPageMask); | 817 DCHECK_EQ((int64_t)0, start & CachePage::kPageMask); |
| 820 offset = 0; | 818 offset = 0; |
| 821 } | 819 } |
| 822 if (size != 0) { | 820 if (size != 0) { |
| 823 FlushOnePage(i_cache, start, size); | 821 FlushOnePage(i_cache, start, size); |
| 824 } | 822 } |
| 825 } | 823 } |
| 826 | 824 |
| 827 | 825 CachePage* Simulator::GetCachePage(base::HashMap* i_cache, void* page) { |
| 828 CachePage* Simulator::GetCachePage(v8::internal::HashMap* i_cache, void* page) { | 826 base::HashMap::Entry* entry = i_cache->LookupOrInsert(page, ICacheHash(page)); |
| 829 v8::internal::HashMap::Entry* entry = | |
| 830 i_cache->LookupOrInsert(page, ICacheHash(page)); | |
| 831 if (entry->value == NULL) { | 827 if (entry->value == NULL) { |
| 832 CachePage* new_page = new CachePage(); | 828 CachePage* new_page = new CachePage(); |
| 833 entry->value = new_page; | 829 entry->value = new_page; |
| 834 } | 830 } |
| 835 return reinterpret_cast<CachePage*>(entry->value); | 831 return reinterpret_cast<CachePage*>(entry->value); |
| 836 } | 832 } |
| 837 | 833 |
| 838 | 834 |
| 839 // Flush from start up to and not including start + size. | 835 // Flush from start up to and not including start + size. |
| 840 void Simulator::FlushOnePage(v8::internal::HashMap* i_cache, intptr_t start, | 836 void Simulator::FlushOnePage(base::HashMap* i_cache, intptr_t start, |
| 841 size_t size) { | 837 size_t size) { |
| 842 DCHECK(size <= CachePage::kPageSize); | 838 DCHECK(size <= CachePage::kPageSize); |
| 843 DCHECK(AllOnOnePage(start, size - 1)); | 839 DCHECK(AllOnOnePage(start, size - 1)); |
| 844 DCHECK((start & CachePage::kLineMask) == 0); | 840 DCHECK((start & CachePage::kLineMask) == 0); |
| 845 DCHECK((size & CachePage::kLineMask) == 0); | 841 DCHECK((size & CachePage::kLineMask) == 0); |
| 846 void* page = reinterpret_cast<void*>(start & (~CachePage::kPageMask)); | 842 void* page = reinterpret_cast<void*>(start & (~CachePage::kPageMask)); |
| 847 int offset = (start & CachePage::kPageMask); | 843 int offset = (start & CachePage::kPageMask); |
| 848 CachePage* cache_page = GetCachePage(i_cache, page); | 844 CachePage* cache_page = GetCachePage(i_cache, page); |
| 849 char* valid_bytemap = cache_page->ValidityByte(offset); | 845 char* valid_bytemap = cache_page->ValidityByte(offset); |
| 850 memset(valid_bytemap, CachePage::LINE_INVALID, size >> CachePage::kLineShift); | 846 memset(valid_bytemap, CachePage::LINE_INVALID, size >> CachePage::kLineShift); |
| 851 } | 847 } |
| 852 | 848 |
| 853 | 849 void Simulator::CheckICache(base::HashMap* i_cache, Instruction* instr) { |
| 854 void Simulator::CheckICache(v8::internal::HashMap* i_cache, | |
| 855 Instruction* instr) { | |
| 856 int64_t address = reinterpret_cast<int64_t>(instr); | 850 int64_t address = reinterpret_cast<int64_t>(instr); |
| 857 void* page = reinterpret_cast<void*>(address & (~CachePage::kPageMask)); | 851 void* page = reinterpret_cast<void*>(address & (~CachePage::kPageMask)); |
| 858 void* line = reinterpret_cast<void*>(address & (~CachePage::kLineMask)); | 852 void* line = reinterpret_cast<void*>(address & (~CachePage::kLineMask)); |
| 859 int offset = (address & CachePage::kPageMask); | 853 int offset = (address & CachePage::kPageMask); |
| 860 CachePage* cache_page = GetCachePage(i_cache, page); | 854 CachePage* cache_page = GetCachePage(i_cache, page); |
| 861 char* cache_valid_byte = cache_page->ValidityByte(offset); | 855 char* cache_valid_byte = cache_page->ValidityByte(offset); |
| 862 bool cache_hit = (*cache_valid_byte == CachePage::LINE_VALID); | 856 bool cache_hit = (*cache_valid_byte == CachePage::LINE_VALID); |
| 863 char* cached_line = cache_page->CachedData(offset & ~CachePage::kLineMask); | 857 char* cached_line = cache_page->CachedData(offset & ~CachePage::kLineMask); |
| 864 if (cache_hit) { | 858 if (cache_hit) { |
| 865 // Check that the data in memory matches the contents of the I-cache. | 859 // Check that the data in memory matches the contents of the I-cache. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 878 if (isolate->simulator_initialized()) return; | 872 if (isolate->simulator_initialized()) return; |
| 879 isolate->set_simulator_initialized(true); | 873 isolate->set_simulator_initialized(true); |
| 880 ::v8::internal::ExternalReference::set_redirector(isolate, | 874 ::v8::internal::ExternalReference::set_redirector(isolate, |
| 881 &RedirectExternalReference); | 875 &RedirectExternalReference); |
| 882 } | 876 } |
| 883 | 877 |
| 884 | 878 |
| 885 Simulator::Simulator(Isolate* isolate) : isolate_(isolate) { | 879 Simulator::Simulator(Isolate* isolate) : isolate_(isolate) { |
| 886 i_cache_ = isolate_->simulator_i_cache(); | 880 i_cache_ = isolate_->simulator_i_cache(); |
| 887 if (i_cache_ == NULL) { | 881 if (i_cache_ == NULL) { |
| 888 i_cache_ = new v8::internal::HashMap(&ICacheMatch); | 882 i_cache_ = new base::HashMap(&ICacheMatch); |
| 889 isolate_->set_simulator_i_cache(i_cache_); | 883 isolate_->set_simulator_i_cache(i_cache_); |
| 890 } | 884 } |
| 891 Initialize(isolate); | 885 Initialize(isolate); |
| 892 // Set up simulator support first. Some of this information is needed to | 886 // Set up simulator support first. Some of this information is needed to |
| 893 // setup the architecture state. | 887 // setup the architecture state. |
| 894 stack_size_ = FLAG_sim_stack_size * KB; | 888 stack_size_ = FLAG_sim_stack_size * KB; |
| 895 stack_ = reinterpret_cast<char*>(malloc(stack_size_)); | 889 stack_ = reinterpret_cast<char*>(malloc(stack_size_)); |
| 896 pc_modified_ = false; | 890 pc_modified_ = false; |
| 897 icount_ = 0; | 891 icount_ = 0; |
| 898 break_count_ = 0; | 892 break_count_ = 0; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 | 987 |
| 994 private: | 988 private: |
| 995 void* external_function_; | 989 void* external_function_; |
| 996 uint32_t swi_instruction_; | 990 uint32_t swi_instruction_; |
| 997 ExternalReference::Type type_; | 991 ExternalReference::Type type_; |
| 998 Redirection* next_; | 992 Redirection* next_; |
| 999 }; | 993 }; |
| 1000 | 994 |
| 1001 | 995 |
| 1002 // static | 996 // static |
| 1003 void Simulator::TearDown(HashMap* i_cache, Redirection* first) { | 997 void Simulator::TearDown(base::HashMap* i_cache, Redirection* first) { |
| 1004 Redirection::DeleteChain(first); | 998 Redirection::DeleteChain(first); |
| 1005 if (i_cache != nullptr) { | 999 if (i_cache != nullptr) { |
| 1006 for (HashMap::Entry* entry = i_cache->Start(); entry != nullptr; | 1000 for (base::HashMap::Entry* entry = i_cache->Start(); entry != nullptr; |
| 1007 entry = i_cache->Next(entry)) { | 1001 entry = i_cache->Next(entry)) { |
| 1008 delete static_cast<CachePage*>(entry->value); | 1002 delete static_cast<CachePage*>(entry->value); |
| 1009 } | 1003 } |
| 1010 delete i_cache; | 1004 delete i_cache; |
| 1011 } | 1005 } |
| 1012 } | 1006 } |
| 1013 | 1007 |
| 1014 | 1008 |
| 1015 void* Simulator::RedirectExternalReference(Isolate* isolate, | 1009 void* Simulator::RedirectExternalReference(Isolate* isolate, |
| 1016 void* external_function, | 1010 void* external_function, |
| (...skipping 3926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4943 } | 4937 } |
| 4944 | 4938 |
| 4945 | 4939 |
| 4946 #undef UNSUPPORTED | 4940 #undef UNSUPPORTED |
| 4947 } // namespace internal | 4941 } // namespace internal |
| 4948 } // namespace v8 | 4942 } // namespace v8 |
| 4949 | 4943 |
| 4950 #endif // USE_SIMULATOR | 4944 #endif // USE_SIMULATOR |
| 4951 | 4945 |
| 4952 #endif // V8_TARGET_ARCH_MIPS64 | 4946 #endif // V8_TARGET_ARCH_MIPS64 |
| OLD | NEW |