| 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 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 intptr_t end_page = ((start + size) & ~CachePage::kPageMask); | 734 intptr_t end_page = ((start + size) & ~CachePage::kPageMask); |
| 735 return start_page == end_page; | 735 return start_page == end_page; |
| 736 } | 736 } |
| 737 | 737 |
| 738 | 738 |
| 739 void Simulator::set_last_debugger_input(char* input) { | 739 void Simulator::set_last_debugger_input(char* input) { |
| 740 DeleteArray(last_debugger_input_); | 740 DeleteArray(last_debugger_input_); |
| 741 last_debugger_input_ = input; | 741 last_debugger_input_ = input; |
| 742 } | 742 } |
| 743 | 743 |
| 744 void Simulator::FlushICache(base::HashMap* i_cache, void* start_addr, | 744 void Simulator::FlushICache(base::CustomMatcherHashMap* i_cache, |
| 745 size_t size) { | 745 void* start_addr, size_t size) { |
| 746 int64_t start = reinterpret_cast<int64_t>(start_addr); | 746 int64_t start = reinterpret_cast<int64_t>(start_addr); |
| 747 int64_t intra_line = (start & CachePage::kLineMask); | 747 int64_t intra_line = (start & CachePage::kLineMask); |
| 748 start -= intra_line; | 748 start -= intra_line; |
| 749 size += intra_line; | 749 size += intra_line; |
| 750 size = ((size - 1) | CachePage::kLineMask) + 1; | 750 size = ((size - 1) | CachePage::kLineMask) + 1; |
| 751 int offset = (start & CachePage::kPageMask); | 751 int offset = (start & CachePage::kPageMask); |
| 752 while (!AllOnOnePage(start, size - 1)) { | 752 while (!AllOnOnePage(start, size - 1)) { |
| 753 int bytes_to_flush = CachePage::kPageSize - offset; | 753 int bytes_to_flush = CachePage::kPageSize - offset; |
| 754 FlushOnePage(i_cache, start, bytes_to_flush); | 754 FlushOnePage(i_cache, start, bytes_to_flush); |
| 755 start += bytes_to_flush; | 755 start += bytes_to_flush; |
| 756 size -= bytes_to_flush; | 756 size -= bytes_to_flush; |
| 757 DCHECK_EQ((int64_t)0, start & CachePage::kPageMask); | 757 DCHECK_EQ((int64_t)0, start & CachePage::kPageMask); |
| 758 offset = 0; | 758 offset = 0; |
| 759 } | 759 } |
| 760 if (size != 0) { | 760 if (size != 0) { |
| 761 FlushOnePage(i_cache, start, size); | 761 FlushOnePage(i_cache, start, size); |
| 762 } | 762 } |
| 763 } | 763 } |
| 764 | 764 |
| 765 CachePage* Simulator::GetCachePage(base::HashMap* i_cache, void* page) { | 765 CachePage* Simulator::GetCachePage(base::CustomMatcherHashMap* i_cache, |
| 766 void* page) { |
| 766 base::HashMap::Entry* entry = i_cache->LookupOrInsert(page, ICacheHash(page)); | 767 base::HashMap::Entry* entry = i_cache->LookupOrInsert(page, ICacheHash(page)); |
| 767 if (entry->value == NULL) { | 768 if (entry->value == NULL) { |
| 768 CachePage* new_page = new CachePage(); | 769 CachePage* new_page = new CachePage(); |
| 769 entry->value = new_page; | 770 entry->value = new_page; |
| 770 } | 771 } |
| 771 return reinterpret_cast<CachePage*>(entry->value); | 772 return reinterpret_cast<CachePage*>(entry->value); |
| 772 } | 773 } |
| 773 | 774 |
| 774 | 775 |
| 775 // Flush from start up to and not including start + size. | 776 // Flush from start up to and not including start + size. |
| 776 void Simulator::FlushOnePage(base::HashMap* i_cache, intptr_t start, | 777 void Simulator::FlushOnePage(base::CustomMatcherHashMap* i_cache, |
| 777 size_t size) { | 778 intptr_t start, size_t size) { |
| 778 DCHECK(size <= CachePage::kPageSize); | 779 DCHECK(size <= CachePage::kPageSize); |
| 779 DCHECK(AllOnOnePage(start, size - 1)); | 780 DCHECK(AllOnOnePage(start, size - 1)); |
| 780 DCHECK((start & CachePage::kLineMask) == 0); | 781 DCHECK((start & CachePage::kLineMask) == 0); |
| 781 DCHECK((size & CachePage::kLineMask) == 0); | 782 DCHECK((size & CachePage::kLineMask) == 0); |
| 782 void* page = reinterpret_cast<void*>(start & (~CachePage::kPageMask)); | 783 void* page = reinterpret_cast<void*>(start & (~CachePage::kPageMask)); |
| 783 int offset = (start & CachePage::kPageMask); | 784 int offset = (start & CachePage::kPageMask); |
| 784 CachePage* cache_page = GetCachePage(i_cache, page); | 785 CachePage* cache_page = GetCachePage(i_cache, page); |
| 785 char* valid_bytemap = cache_page->ValidityByte(offset); | 786 char* valid_bytemap = cache_page->ValidityByte(offset); |
| 786 memset(valid_bytemap, CachePage::LINE_INVALID, size >> CachePage::kLineShift); | 787 memset(valid_bytemap, CachePage::LINE_INVALID, size >> CachePage::kLineShift); |
| 787 } | 788 } |
| 788 | 789 |
| 789 void Simulator::CheckICache(base::HashMap* i_cache, Instruction* instr) { | 790 void Simulator::CheckICache(base::CustomMatcherHashMap* i_cache, |
| 791 Instruction* instr) { |
| 790 int64_t address = reinterpret_cast<int64_t>(instr); | 792 int64_t address = reinterpret_cast<int64_t>(instr); |
| 791 void* page = reinterpret_cast<void*>(address & (~CachePage::kPageMask)); | 793 void* page = reinterpret_cast<void*>(address & (~CachePage::kPageMask)); |
| 792 void* line = reinterpret_cast<void*>(address & (~CachePage::kLineMask)); | 794 void* line = reinterpret_cast<void*>(address & (~CachePage::kLineMask)); |
| 793 int offset = (address & CachePage::kPageMask); | 795 int offset = (address & CachePage::kPageMask); |
| 794 CachePage* cache_page = GetCachePage(i_cache, page); | 796 CachePage* cache_page = GetCachePage(i_cache, page); |
| 795 char* cache_valid_byte = cache_page->ValidityByte(offset); | 797 char* cache_valid_byte = cache_page->ValidityByte(offset); |
| 796 bool cache_hit = (*cache_valid_byte == CachePage::LINE_VALID); | 798 bool cache_hit = (*cache_valid_byte == CachePage::LINE_VALID); |
| 797 char* cached_line = cache_page->CachedData(offset & ~CachePage::kLineMask); | 799 char* cached_line = cache_page->CachedData(offset & ~CachePage::kLineMask); |
| 798 if (cache_hit) { | 800 if (cache_hit) { |
| 799 // Check that the data in memory matches the contents of the I-cache. | 801 // Check that the data in memory matches the contents of the I-cache. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 812 if (isolate->simulator_initialized()) return; | 814 if (isolate->simulator_initialized()) return; |
| 813 isolate->set_simulator_initialized(true); | 815 isolate->set_simulator_initialized(true); |
| 814 ::v8::internal::ExternalReference::set_redirector(isolate, | 816 ::v8::internal::ExternalReference::set_redirector(isolate, |
| 815 &RedirectExternalReference); | 817 &RedirectExternalReference); |
| 816 } | 818 } |
| 817 | 819 |
| 818 | 820 |
| 819 Simulator::Simulator(Isolate* isolate) : isolate_(isolate) { | 821 Simulator::Simulator(Isolate* isolate) : isolate_(isolate) { |
| 820 i_cache_ = isolate_->simulator_i_cache(); | 822 i_cache_ = isolate_->simulator_i_cache(); |
| 821 if (i_cache_ == NULL) { | 823 if (i_cache_ == NULL) { |
| 822 i_cache_ = new base::HashMap(&ICacheMatch); | 824 i_cache_ = new base::CustomMatcherHashMap(&ICacheMatch); |
| 823 isolate_->set_simulator_i_cache(i_cache_); | 825 isolate_->set_simulator_i_cache(i_cache_); |
| 824 } | 826 } |
| 825 Initialize(isolate); | 827 Initialize(isolate); |
| 826 // Set up simulator support first. Some of this information is needed to | 828 // Set up simulator support first. Some of this information is needed to |
| 827 // setup the architecture state. | 829 // setup the architecture state. |
| 828 stack_size_ = FLAG_sim_stack_size * KB; | 830 stack_size_ = FLAG_sim_stack_size * KB; |
| 829 stack_ = reinterpret_cast<char*>(malloc(stack_size_)); | 831 stack_ = reinterpret_cast<char*>(malloc(stack_size_)); |
| 830 pc_modified_ = false; | 832 pc_modified_ = false; |
| 831 icount_ = 0; | 833 icount_ = 0; |
| 832 break_count_ = 0; | 834 break_count_ = 0; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 | 928 |
| 927 private: | 929 private: |
| 928 void* external_function_; | 930 void* external_function_; |
| 929 uint32_t swi_instruction_; | 931 uint32_t swi_instruction_; |
| 930 ExternalReference::Type type_; | 932 ExternalReference::Type type_; |
| 931 Redirection* next_; | 933 Redirection* next_; |
| 932 }; | 934 }; |
| 933 | 935 |
| 934 | 936 |
| 935 // static | 937 // static |
| 936 void Simulator::TearDown(base::HashMap* i_cache, Redirection* first) { | 938 void Simulator::TearDown(base::CustomMatcherHashMap* i_cache, |
| 939 Redirection* first) { |
| 937 Redirection::DeleteChain(first); | 940 Redirection::DeleteChain(first); |
| 938 if (i_cache != nullptr) { | 941 if (i_cache != nullptr) { |
| 939 for (base::HashMap::Entry* entry = i_cache->Start(); entry != nullptr; | 942 for (base::HashMap::Entry* entry = i_cache->Start(); entry != nullptr; |
| 940 entry = i_cache->Next(entry)) { | 943 entry = i_cache->Next(entry)) { |
| 941 delete static_cast<CachePage*>(entry->value); | 944 delete static_cast<CachePage*>(entry->value); |
| 942 } | 945 } |
| 943 delete i_cache; | 946 delete i_cache; |
| 944 } | 947 } |
| 945 } | 948 } |
| 946 | 949 |
| (...skipping 4102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5049 } | 5052 } |
| 5050 | 5053 |
| 5051 | 5054 |
| 5052 #undef UNSUPPORTED | 5055 #undef UNSUPPORTED |
| 5053 } // namespace internal | 5056 } // namespace internal |
| 5054 } // namespace v8 | 5057 } // namespace v8 |
| 5055 | 5058 |
| 5056 #endif // USE_SIMULATOR | 5059 #endif // USE_SIMULATOR |
| 5057 | 5060 |
| 5058 #endif // V8_TARGET_ARCH_MIPS64 | 5061 #endif // V8_TARGET_ARCH_MIPS64 |
| OLD | NEW |