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