| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 <stdarg.h> | 5 #include <stdarg.h> |
| 6 #include <stdlib.h> | 6 #include <stdlib.h> |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #if V8_TARGET_ARCH_PPC | 9 #if V8_TARGET_ARCH_PPC |
| 10 | 10 |
| (...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 return start_page == end_page; | 700 return start_page == end_page; |
| 701 } | 701 } |
| 702 | 702 |
| 703 | 703 |
| 704 void Simulator::set_last_debugger_input(char* input) { | 704 void Simulator::set_last_debugger_input(char* input) { |
| 705 DeleteArray(last_debugger_input_); | 705 DeleteArray(last_debugger_input_); |
| 706 last_debugger_input_ = input; | 706 last_debugger_input_ = input; |
| 707 } | 707 } |
| 708 | 708 |
| 709 | 709 |
| 710 void Simulator::FlushICache(v8::internal::HashMap* i_cache, void* start_addr, | 710 void Simulator::FlushICache(base::HashMap* i_cache, void* start_addr, |
| 711 size_t size) { | 711 size_t size) { |
| 712 intptr_t start = reinterpret_cast<intptr_t>(start_addr); | 712 intptr_t start = reinterpret_cast<intptr_t>(start_addr); |
| 713 int intra_line = (start & CachePage::kLineMask); | 713 int intra_line = (start & CachePage::kLineMask); |
| 714 start -= intra_line; | 714 start -= intra_line; |
| 715 size += intra_line; | 715 size += intra_line; |
| 716 size = ((size - 1) | CachePage::kLineMask) + 1; | 716 size = ((size - 1) | CachePage::kLineMask) + 1; |
| 717 int offset = (start & CachePage::kPageMask); | 717 int offset = (start & CachePage::kPageMask); |
| 718 while (!AllOnOnePage(start, size - 1)) { | 718 while (!AllOnOnePage(start, size - 1)) { |
| 719 int bytes_to_flush = CachePage::kPageSize - offset; | 719 int bytes_to_flush = CachePage::kPageSize - offset; |
| 720 FlushOnePage(i_cache, start, bytes_to_flush); | 720 FlushOnePage(i_cache, start, bytes_to_flush); |
| 721 start += bytes_to_flush; | 721 start += bytes_to_flush; |
| 722 size -= bytes_to_flush; | 722 size -= bytes_to_flush; |
| 723 DCHECK_EQ(0, static_cast<int>(start & CachePage::kPageMask)); | 723 DCHECK_EQ(0, static_cast<int>(start & CachePage::kPageMask)); |
| 724 offset = 0; | 724 offset = 0; |
| 725 } | 725 } |
| 726 if (size != 0) { | 726 if (size != 0) { |
| 727 FlushOnePage(i_cache, start, size); | 727 FlushOnePage(i_cache, start, size); |
| 728 } | 728 } |
| 729 } | 729 } |
| 730 | 730 |
| 731 | 731 |
| 732 CachePage* Simulator::GetCachePage(v8::internal::HashMap* i_cache, void* page) { | 732 CachePage* Simulator::GetCachePage(base::HashMap* i_cache, void* page) { |
| 733 v8::internal::HashMap::Entry* entry = | 733 base::HashMap::Entry* entry = i_cache->LookupOrInsert(page, ICacheHash(page)); |
| 734 i_cache->LookupOrInsert(page, ICacheHash(page)); | |
| 735 if (entry->value == NULL) { | 734 if (entry->value == NULL) { |
| 736 CachePage* new_page = new CachePage(); | 735 CachePage* new_page = new CachePage(); |
| 737 entry->value = new_page; | 736 entry->value = new_page; |
| 738 } | 737 } |
| 739 return reinterpret_cast<CachePage*>(entry->value); | 738 return reinterpret_cast<CachePage*>(entry->value); |
| 740 } | 739 } |
| 741 | 740 |
| 742 | 741 |
| 743 // Flush from start up to and not including start + size. | 742 // Flush from start up to and not including start + size. |
| 744 void Simulator::FlushOnePage(v8::internal::HashMap* i_cache, intptr_t start, | 743 void Simulator::FlushOnePage(base::HashMap* i_cache, intptr_t start, int size) { |
| 745 int size) { | |
| 746 DCHECK(size <= CachePage::kPageSize); | 744 DCHECK(size <= CachePage::kPageSize); |
| 747 DCHECK(AllOnOnePage(start, size - 1)); | 745 DCHECK(AllOnOnePage(start, size - 1)); |
| 748 DCHECK((start & CachePage::kLineMask) == 0); | 746 DCHECK((start & CachePage::kLineMask) == 0); |
| 749 DCHECK((size & CachePage::kLineMask) == 0); | 747 DCHECK((size & CachePage::kLineMask) == 0); |
| 750 void* page = reinterpret_cast<void*>(start & (~CachePage::kPageMask)); | 748 void* page = reinterpret_cast<void*>(start & (~CachePage::kPageMask)); |
| 751 int offset = (start & CachePage::kPageMask); | 749 int offset = (start & CachePage::kPageMask); |
| 752 CachePage* cache_page = GetCachePage(i_cache, page); | 750 CachePage* cache_page = GetCachePage(i_cache, page); |
| 753 char* valid_bytemap = cache_page->ValidityByte(offset); | 751 char* valid_bytemap = cache_page->ValidityByte(offset); |
| 754 memset(valid_bytemap, CachePage::LINE_INVALID, size >> CachePage::kLineShift); | 752 memset(valid_bytemap, CachePage::LINE_INVALID, size >> CachePage::kLineShift); |
| 755 } | 753 } |
| 756 | 754 |
| 757 | 755 void Simulator::CheckICache(base::HashMap* i_cache, Instruction* instr) { |
| 758 void Simulator::CheckICache(v8::internal::HashMap* i_cache, | |
| 759 Instruction* instr) { | |
| 760 intptr_t address = reinterpret_cast<intptr_t>(instr); | 756 intptr_t address = reinterpret_cast<intptr_t>(instr); |
| 761 void* page = reinterpret_cast<void*>(address & (~CachePage::kPageMask)); | 757 void* page = reinterpret_cast<void*>(address & (~CachePage::kPageMask)); |
| 762 void* line = reinterpret_cast<void*>(address & (~CachePage::kLineMask)); | 758 void* line = reinterpret_cast<void*>(address & (~CachePage::kLineMask)); |
| 763 int offset = (address & CachePage::kPageMask); | 759 int offset = (address & CachePage::kPageMask); |
| 764 CachePage* cache_page = GetCachePage(i_cache, page); | 760 CachePage* cache_page = GetCachePage(i_cache, page); |
| 765 char* cache_valid_byte = cache_page->ValidityByte(offset); | 761 char* cache_valid_byte = cache_page->ValidityByte(offset); |
| 766 bool cache_hit = (*cache_valid_byte == CachePage::LINE_VALID); | 762 bool cache_hit = (*cache_valid_byte == CachePage::LINE_VALID); |
| 767 char* cached_line = cache_page->CachedData(offset & ~CachePage::kLineMask); | 763 char* cached_line = cache_page->CachedData(offset & ~CachePage::kLineMask); |
| 768 if (cache_hit) { | 764 if (cache_hit) { |
| 769 // Check that the data in memory matches the contents of the I-cache. | 765 // Check that the data in memory matches the contents of the I-cache. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 782 if (isolate->simulator_initialized()) return; | 778 if (isolate->simulator_initialized()) return; |
| 783 isolate->set_simulator_initialized(true); | 779 isolate->set_simulator_initialized(true); |
| 784 ::v8::internal::ExternalReference::set_redirector(isolate, | 780 ::v8::internal::ExternalReference::set_redirector(isolate, |
| 785 &RedirectExternalReference); | 781 &RedirectExternalReference); |
| 786 } | 782 } |
| 787 | 783 |
| 788 | 784 |
| 789 Simulator::Simulator(Isolate* isolate) : isolate_(isolate) { | 785 Simulator::Simulator(Isolate* isolate) : isolate_(isolate) { |
| 790 i_cache_ = isolate_->simulator_i_cache(); | 786 i_cache_ = isolate_->simulator_i_cache(); |
| 791 if (i_cache_ == NULL) { | 787 if (i_cache_ == NULL) { |
| 792 i_cache_ = new v8::internal::HashMap(&ICacheMatch); | 788 i_cache_ = new base::HashMap(&ICacheMatch); |
| 793 isolate_->set_simulator_i_cache(i_cache_); | 789 isolate_->set_simulator_i_cache(i_cache_); |
| 794 } | 790 } |
| 795 Initialize(isolate); | 791 Initialize(isolate); |
| 796 // Set up simulator support first. Some of this information is needed to | 792 // Set up simulator support first. Some of this information is needed to |
| 797 // setup the architecture state. | 793 // setup the architecture state. |
| 798 #if V8_TARGET_ARCH_PPC64 | 794 #if V8_TARGET_ARCH_PPC64 |
| 799 size_t stack_size = FLAG_sim_stack_size * KB; | 795 size_t stack_size = FLAG_sim_stack_size * KB; |
| 800 #else | 796 #else |
| 801 size_t stack_size = MB; // allocate 1MB for stack | 797 size_t stack_size = MB; // allocate 1MB for stack |
| 802 #endif | 798 #endif |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 private: | 914 private: |
| 919 void* external_function_; | 915 void* external_function_; |
| 920 uint32_t swi_instruction_; | 916 uint32_t swi_instruction_; |
| 921 ExternalReference::Type type_; | 917 ExternalReference::Type type_; |
| 922 Redirection* next_; | 918 Redirection* next_; |
| 923 intptr_t function_descriptor_[3]; | 919 intptr_t function_descriptor_[3]; |
| 924 }; | 920 }; |
| 925 | 921 |
| 926 | 922 |
| 927 // static | 923 // static |
| 928 void Simulator::TearDown(HashMap* i_cache, Redirection* first) { | 924 void Simulator::TearDown(base::HashMap* i_cache, Redirection* first) { |
| 929 Redirection::DeleteChain(first); | 925 Redirection::DeleteChain(first); |
| 930 if (i_cache != nullptr) { | 926 if (i_cache != nullptr) { |
| 931 for (HashMap::Entry* entry = i_cache->Start(); entry != nullptr; | 927 for (base::HashMap::Entry* entry = i_cache->Start(); entry != nullptr; |
| 932 entry = i_cache->Next(entry)) { | 928 entry = i_cache->Next(entry)) { |
| 933 delete static_cast<CachePage*>(entry->value); | 929 delete static_cast<CachePage*>(entry->value); |
| 934 } | 930 } |
| 935 delete i_cache; | 931 delete i_cache; |
| 936 } | 932 } |
| 937 } | 933 } |
| 938 | 934 |
| 939 | 935 |
| 940 void* Simulator::RedirectExternalReference(Isolate* isolate, | 936 void* Simulator::RedirectExternalReference(Isolate* isolate, |
| 941 void* external_function, | 937 void* external_function, |
| (...skipping 3190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4132 uintptr_t* stack_slot = reinterpret_cast<uintptr_t*>(current_sp); | 4128 uintptr_t* stack_slot = reinterpret_cast<uintptr_t*>(current_sp); |
| 4133 uintptr_t address = *stack_slot; | 4129 uintptr_t address = *stack_slot; |
| 4134 set_register(sp, current_sp + sizeof(uintptr_t)); | 4130 set_register(sp, current_sp + sizeof(uintptr_t)); |
| 4135 return address; | 4131 return address; |
| 4136 } | 4132 } |
| 4137 } // namespace internal | 4133 } // namespace internal |
| 4138 } // namespace v8 | 4134 } // namespace v8 |
| 4139 | 4135 |
| 4140 #endif // USE_SIMULATOR | 4136 #endif // USE_SIMULATOR |
| 4141 #endif // V8_TARGET_ARCH_PPC | 4137 #endif // V8_TARGET_ARCH_PPC |
| OLD | NEW |