| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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_ARM | 9 #if V8_TARGET_ARCH_ARM |
| 10 | 10 |
| (...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 intptr_t end_page = ((start + size) & ~CachePage::kPageMask); | 626 intptr_t end_page = ((start + size) & ~CachePage::kPageMask); |
| 627 return start_page == end_page; | 627 return start_page == end_page; |
| 628 } | 628 } |
| 629 | 629 |
| 630 | 630 |
| 631 void Simulator::set_last_debugger_input(char* input) { | 631 void Simulator::set_last_debugger_input(char* input) { |
| 632 DeleteArray(last_debugger_input_); | 632 DeleteArray(last_debugger_input_); |
| 633 last_debugger_input_ = input; | 633 last_debugger_input_ = input; |
| 634 } | 634 } |
| 635 | 635 |
| 636 | 636 void Simulator::FlushICache(base::HashMap* i_cache, void* start_addr, |
| 637 void Simulator::FlushICache(v8::internal::HashMap* i_cache, | |
| 638 void* start_addr, | |
| 639 size_t size) { | 637 size_t size) { |
| 640 intptr_t start = reinterpret_cast<intptr_t>(start_addr); | 638 intptr_t start = reinterpret_cast<intptr_t>(start_addr); |
| 641 int intra_line = (start & CachePage::kLineMask); | 639 int intra_line = (start & CachePage::kLineMask); |
| 642 start -= intra_line; | 640 start -= intra_line; |
| 643 size += intra_line; | 641 size += intra_line; |
| 644 size = ((size - 1) | CachePage::kLineMask) + 1; | 642 size = ((size - 1) | CachePage::kLineMask) + 1; |
| 645 int offset = (start & CachePage::kPageMask); | 643 int offset = (start & CachePage::kPageMask); |
| 646 while (!AllOnOnePage(start, size - 1)) { | 644 while (!AllOnOnePage(start, size - 1)) { |
| 647 int bytes_to_flush = CachePage::kPageSize - offset; | 645 int bytes_to_flush = CachePage::kPageSize - offset; |
| 648 FlushOnePage(i_cache, start, bytes_to_flush); | 646 FlushOnePage(i_cache, start, bytes_to_flush); |
| 649 start += bytes_to_flush; | 647 start += bytes_to_flush; |
| 650 size -= bytes_to_flush; | 648 size -= bytes_to_flush; |
| 651 DCHECK_EQ(0, start & CachePage::kPageMask); | 649 DCHECK_EQ(0, start & CachePage::kPageMask); |
| 652 offset = 0; | 650 offset = 0; |
| 653 } | 651 } |
| 654 if (size != 0) { | 652 if (size != 0) { |
| 655 FlushOnePage(i_cache, start, size); | 653 FlushOnePage(i_cache, start, size); |
| 656 } | 654 } |
| 657 } | 655 } |
| 658 | 656 |
| 659 | 657 CachePage* Simulator::GetCachePage(base::HashMap* i_cache, void* page) { |
| 660 CachePage* Simulator::GetCachePage(v8::internal::HashMap* i_cache, void* page) { | 658 base::HashMap::Entry* entry = i_cache->LookupOrInsert(page, ICacheHash(page)); |
| 661 v8::internal::HashMap::Entry* entry = | |
| 662 i_cache->LookupOrInsert(page, ICacheHash(page)); | |
| 663 if (entry->value == NULL) { | 659 if (entry->value == NULL) { |
| 664 CachePage* new_page = new CachePage(); | 660 CachePage* new_page = new CachePage(); |
| 665 entry->value = new_page; | 661 entry->value = new_page; |
| 666 } | 662 } |
| 667 return reinterpret_cast<CachePage*>(entry->value); | 663 return reinterpret_cast<CachePage*>(entry->value); |
| 668 } | 664 } |
| 669 | 665 |
| 670 | 666 |
| 671 // Flush from start up to and not including start + size. | 667 // Flush from start up to and not including start + size. |
| 672 void Simulator::FlushOnePage(v8::internal::HashMap* i_cache, | 668 void Simulator::FlushOnePage(base::HashMap* i_cache, intptr_t start, int size) { |
| 673 intptr_t start, | |
| 674 int size) { | |
| 675 DCHECK(size <= CachePage::kPageSize); | 669 DCHECK(size <= CachePage::kPageSize); |
| 676 DCHECK(AllOnOnePage(start, size - 1)); | 670 DCHECK(AllOnOnePage(start, size - 1)); |
| 677 DCHECK((start & CachePage::kLineMask) == 0); | 671 DCHECK((start & CachePage::kLineMask) == 0); |
| 678 DCHECK((size & CachePage::kLineMask) == 0); | 672 DCHECK((size & CachePage::kLineMask) == 0); |
| 679 void* page = reinterpret_cast<void*>(start & (~CachePage::kPageMask)); | 673 void* page = reinterpret_cast<void*>(start & (~CachePage::kPageMask)); |
| 680 int offset = (start & CachePage::kPageMask); | 674 int offset = (start & CachePage::kPageMask); |
| 681 CachePage* cache_page = GetCachePage(i_cache, page); | 675 CachePage* cache_page = GetCachePage(i_cache, page); |
| 682 char* valid_bytemap = cache_page->ValidityByte(offset); | 676 char* valid_bytemap = cache_page->ValidityByte(offset); |
| 683 memset(valid_bytemap, CachePage::LINE_INVALID, size >> CachePage::kLineShift); | 677 memset(valid_bytemap, CachePage::LINE_INVALID, size >> CachePage::kLineShift); |
| 684 } | 678 } |
| 685 | 679 |
| 686 | 680 void Simulator::CheckICache(base::HashMap* i_cache, Instruction* instr) { |
| 687 void Simulator::CheckICache(v8::internal::HashMap* i_cache, | |
| 688 Instruction* instr) { | |
| 689 intptr_t address = reinterpret_cast<intptr_t>(instr); | 681 intptr_t address = reinterpret_cast<intptr_t>(instr); |
| 690 void* page = reinterpret_cast<void*>(address & (~CachePage::kPageMask)); | 682 void* page = reinterpret_cast<void*>(address & (~CachePage::kPageMask)); |
| 691 void* line = reinterpret_cast<void*>(address & (~CachePage::kLineMask)); | 683 void* line = reinterpret_cast<void*>(address & (~CachePage::kLineMask)); |
| 692 int offset = (address & CachePage::kPageMask); | 684 int offset = (address & CachePage::kPageMask); |
| 693 CachePage* cache_page = GetCachePage(i_cache, page); | 685 CachePage* cache_page = GetCachePage(i_cache, page); |
| 694 char* cache_valid_byte = cache_page->ValidityByte(offset); | 686 char* cache_valid_byte = cache_page->ValidityByte(offset); |
| 695 bool cache_hit = (*cache_valid_byte == CachePage::LINE_VALID); | 687 bool cache_hit = (*cache_valid_byte == CachePage::LINE_VALID); |
| 696 char* cached_line = cache_page->CachedData(offset & ~CachePage::kLineMask); | 688 char* cached_line = cache_page->CachedData(offset & ~CachePage::kLineMask); |
| 697 if (cache_hit) { | 689 if (cache_hit) { |
| 698 // Check that the data in memory matches the contents of the I-cache. | 690 // Check that the data in memory matches the contents of the I-cache. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 711 if (isolate->simulator_initialized()) return; | 703 if (isolate->simulator_initialized()) return; |
| 712 isolate->set_simulator_initialized(true); | 704 isolate->set_simulator_initialized(true); |
| 713 ::v8::internal::ExternalReference::set_redirector(isolate, | 705 ::v8::internal::ExternalReference::set_redirector(isolate, |
| 714 &RedirectExternalReference); | 706 &RedirectExternalReference); |
| 715 } | 707 } |
| 716 | 708 |
| 717 | 709 |
| 718 Simulator::Simulator(Isolate* isolate) : isolate_(isolate) { | 710 Simulator::Simulator(Isolate* isolate) : isolate_(isolate) { |
| 719 i_cache_ = isolate_->simulator_i_cache(); | 711 i_cache_ = isolate_->simulator_i_cache(); |
| 720 if (i_cache_ == NULL) { | 712 if (i_cache_ == NULL) { |
| 721 i_cache_ = new v8::internal::HashMap(&ICacheMatch); | 713 i_cache_ = new base::HashMap(&ICacheMatch); |
| 722 isolate_->set_simulator_i_cache(i_cache_); | 714 isolate_->set_simulator_i_cache(i_cache_); |
| 723 } | 715 } |
| 724 Initialize(isolate); | 716 Initialize(isolate); |
| 725 // Set up simulator support first. Some of this information is needed to | 717 // Set up simulator support first. Some of this information is needed to |
| 726 // setup the architecture state. | 718 // setup the architecture state. |
| 727 size_t stack_size = 1 * 1024*1024; // allocate 1MB for stack | 719 size_t stack_size = 1 * 1024*1024; // allocate 1MB for stack |
| 728 stack_ = reinterpret_cast<char*>(malloc(stack_size)); | 720 stack_ = reinterpret_cast<char*>(malloc(stack_size)); |
| 729 pc_modified_ = false; | 721 pc_modified_ = false; |
| 730 icount_ = 0; | 722 icount_ = 0; |
| 731 break_pc_ = NULL; | 723 break_pc_ = NULL; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 | 835 |
| 844 private: | 836 private: |
| 845 void* external_function_; | 837 void* external_function_; |
| 846 uint32_t swi_instruction_; | 838 uint32_t swi_instruction_; |
| 847 ExternalReference::Type type_; | 839 ExternalReference::Type type_; |
| 848 Redirection* next_; | 840 Redirection* next_; |
| 849 }; | 841 }; |
| 850 | 842 |
| 851 | 843 |
| 852 // static | 844 // static |
| 853 void Simulator::TearDown(HashMap* i_cache, Redirection* first) { | 845 void Simulator::TearDown(base::HashMap* i_cache, Redirection* first) { |
| 854 Redirection::DeleteChain(first); | 846 Redirection::DeleteChain(first); |
| 855 if (i_cache != nullptr) { | 847 if (i_cache != nullptr) { |
| 856 for (HashMap::Entry* entry = i_cache->Start(); entry != nullptr; | 848 for (base::HashMap::Entry* entry = i_cache->Start(); entry != nullptr; |
| 857 entry = i_cache->Next(entry)) { | 849 entry = i_cache->Next(entry)) { |
| 858 delete static_cast<CachePage*>(entry->value); | 850 delete static_cast<CachePage*>(entry->value); |
| 859 } | 851 } |
| 860 delete i_cache; | 852 delete i_cache; |
| 861 } | 853 } |
| 862 } | 854 } |
| 863 | 855 |
| 864 | 856 |
| 865 void* Simulator::RedirectExternalReference(Isolate* isolate, | 857 void* Simulator::RedirectExternalReference(Isolate* isolate, |
| 866 void* external_function, | 858 void* external_function, |
| (...skipping 3447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4314 set_register(sp, current_sp + sizeof(uintptr_t)); | 4306 set_register(sp, current_sp + sizeof(uintptr_t)); |
| 4315 return address; | 4307 return address; |
| 4316 } | 4308 } |
| 4317 | 4309 |
| 4318 } // namespace internal | 4310 } // namespace internal |
| 4319 } // namespace v8 | 4311 } // namespace v8 |
| 4320 | 4312 |
| 4321 #endif // USE_SIMULATOR | 4313 #endif // USE_SIMULATOR |
| 4322 | 4314 |
| 4323 #endif // V8_TARGET_ARCH_ARM | 4315 #endif // V8_TARGET_ARCH_ARM |
| OLD | NEW |