diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/page_table.cpp | 1 | ||||
| -rw-r--r-- | src/common/page_table.h | 6 | ||||
| -rw-r--r-- | src/core/arm/dynarmic/arm_dynarmic_32.cpp | 28 | ||||
| -rw-r--r-- | src/core/arm/dynarmic/arm_dynarmic_64.cpp | 32 | ||||
| -rw-r--r-- | src/core/memory.cpp | 43 |
5 files changed, 77 insertions, 33 deletions
diff --git a/src/common/page_table.cpp b/src/common/page_table.cpp index 8fd8620fd..9fffd816f 100644 --- a/src/common/page_table.cpp +++ b/src/common/page_table.cpp | |||
| @@ -14,6 +14,7 @@ void PageTable::Resize(size_t address_space_width_in_bits, size_t page_size_in_b | |||
| 14 | const size_t num_page_table_entries{1ULL << (address_space_width_in_bits - page_size_in_bits)}; | 14 | const size_t num_page_table_entries{1ULL << (address_space_width_in_bits - page_size_in_bits)}; |
| 15 | pointers.resize(num_page_table_entries); | 15 | pointers.resize(num_page_table_entries); |
| 16 | backing_addr.resize(num_page_table_entries); | 16 | backing_addr.resize(num_page_table_entries); |
| 17 | current_address_space_width_in_bits = address_space_width_in_bits; | ||
| 17 | } | 18 | } |
| 18 | 19 | ||
| 19 | } // namespace Common | 20 | } // namespace Common |
diff --git a/src/common/page_table.h b/src/common/page_table.h index 61c5552e0..e92b66b2b 100644 --- a/src/common/page_table.h +++ b/src/common/page_table.h | |||
| @@ -98,6 +98,10 @@ struct PageTable { | |||
| 98 | */ | 98 | */ |
| 99 | void Resize(size_t address_space_width_in_bits, size_t page_size_in_bits); | 99 | void Resize(size_t address_space_width_in_bits, size_t page_size_in_bits); |
| 100 | 100 | ||
| 101 | size_t GetAddressSpaceBits() const { | ||
| 102 | return current_address_space_width_in_bits; | ||
| 103 | } | ||
| 104 | |||
| 101 | /** | 105 | /** |
| 102 | * Vector of memory pointers backing each page. An entry can only be non-null if the | 106 | * Vector of memory pointers backing each page. An entry can only be non-null if the |
| 103 | * corresponding attribute element is of type `Memory`. | 107 | * corresponding attribute element is of type `Memory`. |
| @@ -105,6 +109,8 @@ struct PageTable { | |||
| 105 | VirtualBuffer<PageInfo> pointers; | 109 | VirtualBuffer<PageInfo> pointers; |
| 106 | 110 | ||
| 107 | VirtualBuffer<u64> backing_addr; | 111 | VirtualBuffer<u64> backing_addr; |
| 112 | |||
| 113 | size_t current_address_space_width_in_bits; | ||
| 108 | }; | 114 | }; |
| 109 | 115 | ||
| 110 | } // namespace Common | 116 | } // namespace Common |
diff --git a/src/core/arm/dynarmic/arm_dynarmic_32.cpp b/src/core/arm/dynarmic/arm_dynarmic_32.cpp index e5b78210a..cea7f0fb1 100644 --- a/src/core/arm/dynarmic/arm_dynarmic_32.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic_32.cpp | |||
| @@ -24,45 +24,46 @@ namespace Core { | |||
| 24 | 24 | ||
| 25 | class DynarmicCallbacks32 : public Dynarmic::A32::UserCallbacks { | 25 | class DynarmicCallbacks32 : public Dynarmic::A32::UserCallbacks { |
| 26 | public: | 26 | public: |
| 27 | explicit DynarmicCallbacks32(ARM_Dynarmic_32& parent_) : parent{parent_} {} | 27 | explicit DynarmicCallbacks32(ARM_Dynarmic_32& parent_) |
| 28 | : parent{parent_}, memory(parent.system.Memory()) {} | ||
| 28 | 29 | ||
| 29 | u8 MemoryRead8(u32 vaddr) override { | 30 | u8 MemoryRead8(u32 vaddr) override { |
| 30 | return parent.system.Memory().Read8(vaddr); | 31 | return memory.Read8(vaddr); |
| 31 | } | 32 | } |
| 32 | u16 MemoryRead16(u32 vaddr) override { | 33 | u16 MemoryRead16(u32 vaddr) override { |
| 33 | return parent.system.Memory().Read16(vaddr); | 34 | return memory.Read16(vaddr); |
| 34 | } | 35 | } |
| 35 | u32 MemoryRead32(u32 vaddr) override { | 36 | u32 MemoryRead32(u32 vaddr) override { |
| 36 | return parent.system.Memory().Read32(vaddr); | 37 | return memory.Read32(vaddr); |
| 37 | } | 38 | } |
| 38 | u64 MemoryRead64(u32 vaddr) override { | 39 | u64 MemoryRead64(u32 vaddr) override { |
| 39 | return parent.system.Memory().Read64(vaddr); | 40 | return memory.Read64(vaddr); |
| 40 | } | 41 | } |
| 41 | 42 | ||
| 42 | void MemoryWrite8(u32 vaddr, u8 value) override { | 43 | void MemoryWrite8(u32 vaddr, u8 value) override { |
| 43 | parent.system.Memory().Write8(vaddr, value); | 44 | memory.Write8(vaddr, value); |
| 44 | } | 45 | } |
| 45 | void MemoryWrite16(u32 vaddr, u16 value) override { | 46 | void MemoryWrite16(u32 vaddr, u16 value) override { |
| 46 | parent.system.Memory().Write16(vaddr, value); | 47 | memory.Write16(vaddr, value); |
| 47 | } | 48 | } |
| 48 | void MemoryWrite32(u32 vaddr, u32 value) override { | 49 | void MemoryWrite32(u32 vaddr, u32 value) override { |
| 49 | parent.system.Memory().Write32(vaddr, value); | 50 | memory.Write32(vaddr, value); |
| 50 | } | 51 | } |
| 51 | void MemoryWrite64(u32 vaddr, u64 value) override { | 52 | void MemoryWrite64(u32 vaddr, u64 value) override { |
| 52 | parent.system.Memory().Write64(vaddr, value); | 53 | memory.Write64(vaddr, value); |
| 53 | } | 54 | } |
| 54 | 55 | ||
| 55 | bool MemoryWriteExclusive8(u32 vaddr, u8 value, u8 expected) override { | 56 | bool MemoryWriteExclusive8(u32 vaddr, u8 value, u8 expected) override { |
| 56 | return parent.system.Memory().WriteExclusive8(vaddr, value, expected); | 57 | return memory.WriteExclusive8(vaddr, value, expected); |
| 57 | } | 58 | } |
| 58 | bool MemoryWriteExclusive16(u32 vaddr, u16 value, u16 expected) override { | 59 | bool MemoryWriteExclusive16(u32 vaddr, u16 value, u16 expected) override { |
| 59 | return parent.system.Memory().WriteExclusive16(vaddr, value, expected); | 60 | return memory.WriteExclusive16(vaddr, value, expected); |
| 60 | } | 61 | } |
| 61 | bool MemoryWriteExclusive32(u32 vaddr, u32 value, u32 expected) override { | 62 | bool MemoryWriteExclusive32(u32 vaddr, u32 value, u32 expected) override { |
| 62 | return parent.system.Memory().WriteExclusive32(vaddr, value, expected); | 63 | return memory.WriteExclusive32(vaddr, value, expected); |
| 63 | } | 64 | } |
| 64 | bool MemoryWriteExclusive64(u32 vaddr, u64 value, u64 expected) override { | 65 | bool MemoryWriteExclusive64(u32 vaddr, u64 value, u64 expected) override { |
| 65 | return parent.system.Memory().WriteExclusive64(vaddr, value, expected); | 66 | return memory.WriteExclusive64(vaddr, value, expected); |
| 66 | } | 67 | } |
| 67 | 68 | ||
| 68 | void InterpreterFallback(u32 pc, std::size_t num_instructions) override { | 69 | void InterpreterFallback(u32 pc, std::size_t num_instructions) override { |
| @@ -112,6 +113,7 @@ public: | |||
| 112 | } | 113 | } |
| 113 | 114 | ||
| 114 | ARM_Dynarmic_32& parent; | 115 | ARM_Dynarmic_32& parent; |
| 116 | Core::Memory::Memory& memory; | ||
| 115 | std::size_t num_interpreted_instructions{}; | 117 | std::size_t num_interpreted_instructions{}; |
| 116 | static constexpr u64 minimum_run_cycles = 1000U; | 118 | static constexpr u64 minimum_run_cycles = 1000U; |
| 117 | }; | 119 | }; |
diff --git a/src/core/arm/dynarmic/arm_dynarmic_64.cpp b/src/core/arm/dynarmic/arm_dynarmic_64.cpp index dd439f55e..63193dcb1 100644 --- a/src/core/arm/dynarmic/arm_dynarmic_64.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic_64.cpp | |||
| @@ -27,57 +27,56 @@ using Vector = Dynarmic::A64::Vector; | |||
| 27 | 27 | ||
| 28 | class DynarmicCallbacks64 : public Dynarmic::A64::UserCallbacks { | 28 | class DynarmicCallbacks64 : public Dynarmic::A64::UserCallbacks { |
| 29 | public: | 29 | public: |
| 30 | explicit DynarmicCallbacks64(ARM_Dynarmic_64& parent_) : parent{parent_} {} | 30 | explicit DynarmicCallbacks64(ARM_Dynarmic_64& parent_) |
| 31 | : parent{parent_}, memory(parent.system.Memory()) {} | ||
| 31 | 32 | ||
| 32 | u8 MemoryRead8(u64 vaddr) override { | 33 | u8 MemoryRead8(u64 vaddr) override { |
| 33 | return parent.system.Memory().Read8(vaddr); | 34 | return memory.Read8(vaddr); |
| 34 | } | 35 | } |
| 35 | u16 MemoryRead16(u64 vaddr) override { | 36 | u16 MemoryRead16(u64 vaddr) override { |
| 36 | return parent.system.Memory().Read16(vaddr); | 37 | return memory.Read16(vaddr); |
| 37 | } | 38 | } |
| 38 | u32 MemoryRead32(u64 vaddr) override { | 39 | u32 MemoryRead32(u64 vaddr) override { |
| 39 | return parent.system.Memory().Read32(vaddr); | 40 | return memory.Read32(vaddr); |
| 40 | } | 41 | } |
| 41 | u64 MemoryRead64(u64 vaddr) override { | 42 | u64 MemoryRead64(u64 vaddr) override { |
| 42 | return parent.system.Memory().Read64(vaddr); | 43 | return memory.Read64(vaddr); |
| 43 | } | 44 | } |
| 44 | Vector MemoryRead128(u64 vaddr) override { | 45 | Vector MemoryRead128(u64 vaddr) override { |
| 45 | auto& memory = parent.system.Memory(); | ||
| 46 | return {memory.Read64(vaddr), memory.Read64(vaddr + 8)}; | 46 | return {memory.Read64(vaddr), memory.Read64(vaddr + 8)}; |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | void MemoryWrite8(u64 vaddr, u8 value) override { | 49 | void MemoryWrite8(u64 vaddr, u8 value) override { |
| 50 | parent.system.Memory().Write8(vaddr, value); | 50 | memory.Write8(vaddr, value); |
| 51 | } | 51 | } |
| 52 | void MemoryWrite16(u64 vaddr, u16 value) override { | 52 | void MemoryWrite16(u64 vaddr, u16 value) override { |
| 53 | parent.system.Memory().Write16(vaddr, value); | 53 | memory.Write16(vaddr, value); |
| 54 | } | 54 | } |
| 55 | void MemoryWrite32(u64 vaddr, u32 value) override { | 55 | void MemoryWrite32(u64 vaddr, u32 value) override { |
| 56 | parent.system.Memory().Write32(vaddr, value); | 56 | memory.Write32(vaddr, value); |
| 57 | } | 57 | } |
| 58 | void MemoryWrite64(u64 vaddr, u64 value) override { | 58 | void MemoryWrite64(u64 vaddr, u64 value) override { |
| 59 | parent.system.Memory().Write64(vaddr, value); | 59 | memory.Write64(vaddr, value); |
| 60 | } | 60 | } |
| 61 | void MemoryWrite128(u64 vaddr, Vector value) override { | 61 | void MemoryWrite128(u64 vaddr, Vector value) override { |
| 62 | auto& memory = parent.system.Memory(); | ||
| 63 | memory.Write64(vaddr, value[0]); | 62 | memory.Write64(vaddr, value[0]); |
| 64 | memory.Write64(vaddr + 8, value[1]); | 63 | memory.Write64(vaddr + 8, value[1]); |
| 65 | } | 64 | } |
| 66 | 65 | ||
| 67 | bool MemoryWriteExclusive8(u64 vaddr, std::uint8_t value, std::uint8_t expected) override { | 66 | bool MemoryWriteExclusive8(u64 vaddr, std::uint8_t value, std::uint8_t expected) override { |
| 68 | return parent.system.Memory().WriteExclusive8(vaddr, value, expected); | 67 | return memory.WriteExclusive8(vaddr, value, expected); |
| 69 | } | 68 | } |
| 70 | bool MemoryWriteExclusive16(u64 vaddr, std::uint16_t value, std::uint16_t expected) override { | 69 | bool MemoryWriteExclusive16(u64 vaddr, std::uint16_t value, std::uint16_t expected) override { |
| 71 | return parent.system.Memory().WriteExclusive16(vaddr, value, expected); | 70 | return memory.WriteExclusive16(vaddr, value, expected); |
| 72 | } | 71 | } |
| 73 | bool MemoryWriteExclusive32(u64 vaddr, std::uint32_t value, std::uint32_t expected) override { | 72 | bool MemoryWriteExclusive32(u64 vaddr, std::uint32_t value, std::uint32_t expected) override { |
| 74 | return parent.system.Memory().WriteExclusive32(vaddr, value, expected); | 73 | return memory.WriteExclusive32(vaddr, value, expected); |
| 75 | } | 74 | } |
| 76 | bool MemoryWriteExclusive64(u64 vaddr, std::uint64_t value, std::uint64_t expected) override { | 75 | bool MemoryWriteExclusive64(u64 vaddr, std::uint64_t value, std::uint64_t expected) override { |
| 77 | return parent.system.Memory().WriteExclusive64(vaddr, value, expected); | 76 | return memory.WriteExclusive64(vaddr, value, expected); |
| 78 | } | 77 | } |
| 79 | bool MemoryWriteExclusive128(u64 vaddr, Vector value, Vector expected) override { | 78 | bool MemoryWriteExclusive128(u64 vaddr, Vector value, Vector expected) override { |
| 80 | return parent.system.Memory().WriteExclusive128(vaddr, value, expected); | 79 | return memory.WriteExclusive128(vaddr, value, expected); |
| 81 | } | 80 | } |
| 82 | 81 | ||
| 83 | void InterpreterFallback(u64 pc, std::size_t num_instructions) override { | 82 | void InterpreterFallback(u64 pc, std::size_t num_instructions) override { |
| @@ -139,6 +138,7 @@ public: | |||
| 139 | } | 138 | } |
| 140 | 139 | ||
| 141 | ARM_Dynarmic_64& parent; | 140 | ARM_Dynarmic_64& parent; |
| 141 | Core::Memory::Memory& memory; | ||
| 142 | u64 tpidrro_el0 = 0; | 142 | u64 tpidrro_el0 = 0; |
| 143 | u64 tpidr_el0 = 0; | 143 | u64 tpidr_el0 = 0; |
| 144 | static constexpr u64 minimum_run_cycles = 1000U; | 144 | static constexpr u64 minimum_run_cycles = 1000U; |
diff --git a/src/core/memory.cpp b/src/core/memory.cpp index bf2ef7816..9857278f6 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp | |||
| @@ -591,7 +591,15 @@ struct Memory::Impl { | |||
| 591 | * @returns The instance of T read from the specified virtual address. | 591 | * @returns The instance of T read from the specified virtual address. |
| 592 | */ | 592 | */ |
| 593 | template <typename T> | 593 | template <typename T> |
| 594 | T Read(const VAddr vaddr) { | 594 | T Read(VAddr vaddr) { |
| 595 | // AARCH64 masks the upper 16 bit of all memory accesses | ||
| 596 | vaddr &= 0xffffffffffffLL; | ||
| 597 | |||
| 598 | if (vaddr >= 1uLL << current_page_table->GetAddressSpaceBits()) { | ||
| 599 | LOG_ERROR(HW_Memory, "Unmapped Read{} @ 0x{:08X}", sizeof(T) * 8, vaddr); | ||
| 600 | return 0; | ||
| 601 | } | ||
| 602 | |||
| 595 | // Avoid adding any extra logic to this fast-path block | 603 | // Avoid adding any extra logic to this fast-path block |
| 596 | const uintptr_t raw_pointer = current_page_table->pointers[vaddr >> PAGE_BITS].Raw(); | 604 | const uintptr_t raw_pointer = current_page_table->pointers[vaddr >> PAGE_BITS].Raw(); |
| 597 | if (const u8* const pointer = Common::PageTable::PageInfo::ExtractPointer(raw_pointer)) { | 605 | if (const u8* const pointer = Common::PageTable::PageInfo::ExtractPointer(raw_pointer)) { |
| @@ -629,7 +637,16 @@ struct Memory::Impl { | |||
| 629 | * is undefined. | 637 | * is undefined. |
| 630 | */ | 638 | */ |
| 631 | template <typename T> | 639 | template <typename T> |
| 632 | void Write(const VAddr vaddr, const T data) { | 640 | void Write(VAddr vaddr, const T data) { |
| 641 | // AARCH64 masks the upper 16 bit of all memory accesses | ||
| 642 | vaddr &= 0xffffffffffffLL; | ||
| 643 | |||
| 644 | if (vaddr >= 1uLL << current_page_table->GetAddressSpaceBits()) { | ||
| 645 | LOG_ERROR(HW_Memory, "Unmapped Write{} 0x{:08X} @ 0x{:016X}", sizeof(data) * 8, | ||
| 646 | static_cast<u32>(data), vaddr); | ||
| 647 | return; | ||
| 648 | } | ||
| 649 | |||
| 633 | // Avoid adding any extra logic to this fast-path block | 650 | // Avoid adding any extra logic to this fast-path block |
| 634 | const uintptr_t raw_pointer = current_page_table->pointers[vaddr >> PAGE_BITS].Raw(); | 651 | const uintptr_t raw_pointer = current_page_table->pointers[vaddr >> PAGE_BITS].Raw(); |
| 635 | if (u8* const pointer = Common::PageTable::PageInfo::ExtractPointer(raw_pointer)) { | 652 | if (u8* const pointer = Common::PageTable::PageInfo::ExtractPointer(raw_pointer)) { |
| @@ -656,7 +673,16 @@ struct Memory::Impl { | |||
| 656 | } | 673 | } |
| 657 | 674 | ||
| 658 | template <typename T> | 675 | template <typename T> |
| 659 | bool WriteExclusive(const VAddr vaddr, const T data, const T expected) { | 676 | bool WriteExclusive(VAddr vaddr, const T data, const T expected) { |
| 677 | // AARCH64 masks the upper 16 bit of all memory accesses | ||
| 678 | vaddr &= 0xffffffffffffLL; | ||
| 679 | |||
| 680 | if (vaddr >= 1uLL << current_page_table->GetAddressSpaceBits()) { | ||
| 681 | LOG_ERROR(HW_Memory, "Unmapped Write{} 0x{:08X} @ 0x{:016X}", sizeof(data) * 8, | ||
| 682 | static_cast<u32>(data), vaddr); | ||
| 683 | return true; | ||
| 684 | } | ||
| 685 | |||
| 660 | const uintptr_t raw_pointer = current_page_table->pointers[vaddr >> PAGE_BITS].Raw(); | 686 | const uintptr_t raw_pointer = current_page_table->pointers[vaddr >> PAGE_BITS].Raw(); |
| 661 | if (u8* const pointer = Common::PageTable::PageInfo::ExtractPointer(raw_pointer)) { | 687 | if (u8* const pointer = Common::PageTable::PageInfo::ExtractPointer(raw_pointer)) { |
| 662 | // NOTE: Avoid adding any extra logic to this fast-path block | 688 | // NOTE: Avoid adding any extra logic to this fast-path block |
| @@ -683,7 +709,16 @@ struct Memory::Impl { | |||
| 683 | return true; | 709 | return true; |
| 684 | } | 710 | } |
| 685 | 711 | ||
| 686 | bool WriteExclusive128(const VAddr vaddr, const u128 data, const u128 expected) { | 712 | bool WriteExclusive128(VAddr vaddr, const u128 data, const u128 expected) { |
| 713 | // AARCH64 masks the upper 16 bit of all memory accesses | ||
| 714 | vaddr &= 0xffffffffffffLL; | ||
| 715 | |||
| 716 | if (vaddr >= 1uLL << current_page_table->GetAddressSpaceBits()) { | ||
| 717 | LOG_ERROR(HW_Memory, "Unmapped Write{} 0x{:08X} @ 0x{:016X}", sizeof(data) * 8, | ||
| 718 | static_cast<u32>(data[0]), vaddr); | ||
| 719 | return true; | ||
| 720 | } | ||
| 721 | |||
| 687 | const uintptr_t raw_pointer = current_page_table->pointers[vaddr >> PAGE_BITS].Raw(); | 722 | const uintptr_t raw_pointer = current_page_table->pointers[vaddr >> PAGE_BITS].Raw(); |
| 688 | if (u8* const pointer = Common::PageTable::PageInfo::ExtractPointer(raw_pointer)) { | 723 | if (u8* const pointer = Common::PageTable::PageInfo::ExtractPointer(raw_pointer)) { |
| 689 | // NOTE: Avoid adding any extra logic to this fast-path block | 724 | // NOTE: Avoid adding any extra logic to this fast-path block |