| 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 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 intptr_t end_page = ((start + size) & ~CachePage::kPageMask); | 568 intptr_t end_page = ((start + size) & ~CachePage::kPageMask); |
| 569 return start_page == end_page; | 569 return start_page == end_page; |
| 570 } | 570 } |
| 571 | 571 |
| 572 | 572 |
| 573 void Simulator::set_last_debugger_input(char* input) { | 573 void Simulator::set_last_debugger_input(char* input) { |
| 574 DeleteArray(last_debugger_input_); | 574 DeleteArray(last_debugger_input_); |
| 575 last_debugger_input_ = input; | 575 last_debugger_input_ = input; |
| 576 } | 576 } |
| 577 | 577 |
| 578 void Simulator::FlushICache(base::HashMap* i_cache, void* start_addr, | 578 void Simulator::FlushICache(base::CustomMatcherHashMap* i_cache, |
| 579 size_t size) { | 579 void* start_addr, size_t size) { |
| 580 intptr_t start = reinterpret_cast<intptr_t>(start_addr); | 580 intptr_t start = reinterpret_cast<intptr_t>(start_addr); |
| 581 int intra_line = (start & CachePage::kLineMask); | 581 int intra_line = (start & CachePage::kLineMask); |
| 582 start -= intra_line; | 582 start -= intra_line; |
| 583 size += intra_line; | 583 size += intra_line; |
| 584 size = ((size - 1) | CachePage::kLineMask) + 1; | 584 size = ((size - 1) | CachePage::kLineMask) + 1; |
| 585 int offset = (start & CachePage::kPageMask); | 585 int offset = (start & CachePage::kPageMask); |
| 586 while (!AllOnOnePage(start, size - 1)) { | 586 while (!AllOnOnePage(start, size - 1)) { |
| 587 int bytes_to_flush = CachePage::kPageSize - offset; | 587 int bytes_to_flush = CachePage::kPageSize - offset; |
| 588 FlushOnePage(i_cache, start, bytes_to_flush); | 588 FlushOnePage(i_cache, start, bytes_to_flush); |
| 589 start += bytes_to_flush; | 589 start += bytes_to_flush; |
| 590 size -= bytes_to_flush; | 590 size -= bytes_to_flush; |
| 591 DCHECK_EQ(0, start & CachePage::kPageMask); | 591 DCHECK_EQ(0, start & CachePage::kPageMask); |
| 592 offset = 0; | 592 offset = 0; |
| 593 } | 593 } |
| 594 if (size != 0) { | 594 if (size != 0) { |
| 595 FlushOnePage(i_cache, start, size); | 595 FlushOnePage(i_cache, start, size); |
| 596 } | 596 } |
| 597 } | 597 } |
| 598 | 598 |
| 599 CachePage* Simulator::GetCachePage(base::HashMap* i_cache, void* page) { | 599 CachePage* Simulator::GetCachePage(base::CustomMatcherHashMap* i_cache, |
| 600 void* page) { |
| 600 base::HashMap::Entry* entry = i_cache->LookupOrInsert(page, ICacheHash(page)); | 601 base::HashMap::Entry* entry = i_cache->LookupOrInsert(page, ICacheHash(page)); |
| 601 if (entry->value == NULL) { | 602 if (entry->value == NULL) { |
| 602 CachePage* new_page = new CachePage(); | 603 CachePage* new_page = new CachePage(); |
| 603 entry->value = new_page; | 604 entry->value = new_page; |
| 604 } | 605 } |
| 605 return reinterpret_cast<CachePage*>(entry->value); | 606 return reinterpret_cast<CachePage*>(entry->value); |
| 606 } | 607 } |
| 607 | 608 |
| 608 | 609 |
| 609 // Flush from start up to and not including start + size. | 610 // Flush from start up to and not including start + size. |
| 610 void Simulator::FlushOnePage(base::HashMap* i_cache, intptr_t start, int size) { | 611 void Simulator::FlushOnePage(base::CustomMatcherHashMap* i_cache, |
| 612 intptr_t start, int size) { |
| 611 DCHECK(size <= CachePage::kPageSize); | 613 DCHECK(size <= CachePage::kPageSize); |
| 612 DCHECK(AllOnOnePage(start, size - 1)); | 614 DCHECK(AllOnOnePage(start, size - 1)); |
| 613 DCHECK((start & CachePage::kLineMask) == 0); | 615 DCHECK((start & CachePage::kLineMask) == 0); |
| 614 DCHECK((size & CachePage::kLineMask) == 0); | 616 DCHECK((size & CachePage::kLineMask) == 0); |
| 615 void* page = reinterpret_cast<void*>(start & (~CachePage::kPageMask)); | 617 void* page = reinterpret_cast<void*>(start & (~CachePage::kPageMask)); |
| 616 int offset = (start & CachePage::kPageMask); | 618 int offset = (start & CachePage::kPageMask); |
| 617 CachePage* cache_page = GetCachePage(i_cache, page); | 619 CachePage* cache_page = GetCachePage(i_cache, page); |
| 618 char* valid_bytemap = cache_page->ValidityByte(offset); | 620 char* valid_bytemap = cache_page->ValidityByte(offset); |
| 619 memset(valid_bytemap, CachePage::LINE_INVALID, size >> CachePage::kLineShift); | 621 memset(valid_bytemap, CachePage::LINE_INVALID, size >> CachePage::kLineShift); |
| 620 } | 622 } |
| 621 | 623 |
| 622 void Simulator::CheckICache(base::HashMap* i_cache, Instruction* instr) { | 624 void Simulator::CheckICache(base::CustomMatcherHashMap* i_cache, |
| 625 Instruction* instr) { |
| 623 intptr_t address = reinterpret_cast<intptr_t>(instr); | 626 intptr_t address = reinterpret_cast<intptr_t>(instr); |
| 624 void* page = reinterpret_cast<void*>(address & (~CachePage::kPageMask)); | 627 void* page = reinterpret_cast<void*>(address & (~CachePage::kPageMask)); |
| 625 void* line = reinterpret_cast<void*>(address & (~CachePage::kLineMask)); | 628 void* line = reinterpret_cast<void*>(address & (~CachePage::kLineMask)); |
| 626 int offset = (address & CachePage::kPageMask); | 629 int offset = (address & CachePage::kPageMask); |
| 627 CachePage* cache_page = GetCachePage(i_cache, page); | 630 CachePage* cache_page = GetCachePage(i_cache, page); |
| 628 char* cache_valid_byte = cache_page->ValidityByte(offset); | 631 char* cache_valid_byte = cache_page->ValidityByte(offset); |
| 629 bool cache_hit = (*cache_valid_byte == CachePage::LINE_VALID); | 632 bool cache_hit = (*cache_valid_byte == CachePage::LINE_VALID); |
| 630 char* cached_line = cache_page->CachedData(offset & ~CachePage::kLineMask); | 633 char* cached_line = cache_page->CachedData(offset & ~CachePage::kLineMask); |
| 631 if (cache_hit) { | 634 if (cache_hit) { |
| 632 // Check that the data in memory matches the contents of the I-cache. | 635 // Check that the data in memory matches the contents of the I-cache. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 645 if (isolate->simulator_initialized()) return; | 648 if (isolate->simulator_initialized()) return; |
| 646 isolate->set_simulator_initialized(true); | 649 isolate->set_simulator_initialized(true); |
| 647 ::v8::internal::ExternalReference::set_redirector(isolate, | 650 ::v8::internal::ExternalReference::set_redirector(isolate, |
| 648 &RedirectExternalReference); | 651 &RedirectExternalReference); |
| 649 } | 652 } |
| 650 | 653 |
| 651 | 654 |
| 652 Simulator::Simulator(Isolate* isolate) : isolate_(isolate) { | 655 Simulator::Simulator(Isolate* isolate) : isolate_(isolate) { |
| 653 i_cache_ = isolate_->simulator_i_cache(); | 656 i_cache_ = isolate_->simulator_i_cache(); |
| 654 if (i_cache_ == NULL) { | 657 if (i_cache_ == NULL) { |
| 655 i_cache_ = new base::HashMap(&ICacheMatch); | 658 i_cache_ = new base::CustomMatcherHashMap(&ICacheMatch); |
| 656 isolate_->set_simulator_i_cache(i_cache_); | 659 isolate_->set_simulator_i_cache(i_cache_); |
| 657 } | 660 } |
| 658 Initialize(isolate); | 661 Initialize(isolate); |
| 659 // Set up simulator support first. Some of this information is needed to | 662 // Set up simulator support first. Some of this information is needed to |
| 660 // setup the architecture state. | 663 // setup the architecture state. |
| 661 size_t stack_size = 1 * 1024*1024; // allocate 1MB for stack | 664 size_t stack_size = 1 * 1024*1024; // allocate 1MB for stack |
| 662 stack_ = reinterpret_cast<char*>(malloc(stack_size)); | 665 stack_ = reinterpret_cast<char*>(malloc(stack_size)); |
| 663 pc_modified_ = false; | 666 pc_modified_ = false; |
| 664 icount_ = 0; | 667 icount_ = 0; |
| 665 break_pc_ = NULL; | 668 break_pc_ = NULL; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 | 779 |
| 777 private: | 780 private: |
| 778 void* external_function_; | 781 void* external_function_; |
| 779 uint32_t swi_instruction_; | 782 uint32_t swi_instruction_; |
| 780 ExternalReference::Type type_; | 783 ExternalReference::Type type_; |
| 781 Redirection* next_; | 784 Redirection* next_; |
| 782 }; | 785 }; |
| 783 | 786 |
| 784 | 787 |
| 785 // static | 788 // static |
| 786 void Simulator::TearDown(base::HashMap* i_cache, Redirection* first) { | 789 void Simulator::TearDown(base::CustomMatcherHashMap* i_cache, |
| 790 Redirection* first) { |
| 787 Redirection::DeleteChain(first); | 791 Redirection::DeleteChain(first); |
| 788 if (i_cache != nullptr) { | 792 if (i_cache != nullptr) { |
| 789 for (base::HashMap::Entry* entry = i_cache->Start(); entry != nullptr; | 793 for (base::HashMap::Entry* entry = i_cache->Start(); entry != nullptr; |
| 790 entry = i_cache->Next(entry)) { | 794 entry = i_cache->Next(entry)) { |
| 791 delete static_cast<CachePage*>(entry->value); | 795 delete static_cast<CachePage*>(entry->value); |
| 792 } | 796 } |
| 793 delete i_cache; | 797 delete i_cache; |
| 794 } | 798 } |
| 795 } | 799 } |
| 796 | 800 |
| (...skipping 3514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4311 set_register(sp, current_sp + sizeof(uintptr_t)); | 4315 set_register(sp, current_sp + sizeof(uintptr_t)); |
| 4312 return address; | 4316 return address; |
| 4313 } | 4317 } |
| 4314 | 4318 |
| 4315 } // namespace internal | 4319 } // namespace internal |
| 4316 } // namespace v8 | 4320 } // namespace v8 |
| 4317 | 4321 |
| 4318 #endif // USE_SIMULATOR | 4322 #endif // USE_SIMULATOR |
| 4319 | 4323 |
| 4320 #endif // V8_TARGET_ARCH_ARM | 4324 #endif // V8_TARGET_ARCH_ARM |
| OLD | NEW |