diff options
| author | 2019-11-26 16:29:34 -0500 | |
|---|---|---|
| committer | 2019-11-26 21:55:39 -0500 | |
| commit | b05bfc603689419dc515a656b9fc711d79994f13 (patch) | |
| tree | bc0937d11bbe31458785a69478edbf11a720b0ae /src/core/hle/kernel | |
| parent | core/memory: Migrate over ZeroBlock() and CopyBlock() to the Memory class (diff) | |
| download | yuzu-b05bfc603689419dc515a656b9fc711d79994f13.tar.gz yuzu-b05bfc603689419dc515a656b9fc711d79994f13.tar.xz yuzu-b05bfc603689419dc515a656b9fc711d79994f13.zip | |
core/memory: Migrate over Read{8, 16, 32, 64, Block} to the Memory class
With all of the trivial parts of the memory interface moved over, we can
get right into moving over the bits that are used.
Note that this does require the use of GetInstance from the global
system instance to be used within hle_ipc.cpp and the gdbstub. This is
fine for the time being, as they both already rely on the global system
instance in other functions. These will be removed in a change directed
at both of these respectively.
For now, it's sufficient, as it still accomplishes the goal of
de-globalizing the memory code.
Diffstat (limited to 'src/core/hle/kernel')
| -rw-r--r-- | src/core/hle/kernel/address_arbiter.cpp | 28 | ||||
| -rw-r--r-- | src/core/hle/kernel/hle_ipc.cpp | 12 | ||||
| -rw-r--r-- | src/core/hle/kernel/mutex.cpp | 2 | ||||
| -rw-r--r-- | src/core/hle/kernel/svc.cpp | 16 |
4 files changed, 36 insertions, 22 deletions
diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cpp index 7f9a559d2..07f0dac67 100644 --- a/src/core/hle/kernel/address_arbiter.cpp +++ b/src/core/hle/kernel/address_arbiter.cpp | |||
| @@ -67,12 +67,14 @@ ResultCode AddressArbiter::SignalToAddressOnly(VAddr address, s32 num_to_wake) { | |||
| 67 | 67 | ||
| 68 | ResultCode AddressArbiter::IncrementAndSignalToAddressIfEqual(VAddr address, s32 value, | 68 | ResultCode AddressArbiter::IncrementAndSignalToAddressIfEqual(VAddr address, s32 value, |
| 69 | s32 num_to_wake) { | 69 | s32 num_to_wake) { |
| 70 | auto& memory = system.Memory(); | ||
| 71 | |||
| 70 | // Ensure that we can write to the address. | 72 | // Ensure that we can write to the address. |
| 71 | if (!system.Memory().IsValidVirtualAddress(address)) { | 73 | if (!memory.IsValidVirtualAddress(address)) { |
| 72 | return ERR_INVALID_ADDRESS_STATE; | 74 | return ERR_INVALID_ADDRESS_STATE; |
| 73 | } | 75 | } |
| 74 | 76 | ||
| 75 | if (static_cast<s32>(Memory::Read32(address)) != value) { | 77 | if (static_cast<s32>(memory.Read32(address)) != value) { |
| 76 | return ERR_INVALID_STATE; | 78 | return ERR_INVALID_STATE; |
| 77 | } | 79 | } |
| 78 | 80 | ||
| @@ -82,8 +84,10 @@ ResultCode AddressArbiter::IncrementAndSignalToAddressIfEqual(VAddr address, s32 | |||
| 82 | 84 | ||
| 83 | ResultCode AddressArbiter::ModifyByWaitingCountAndSignalToAddressIfEqual(VAddr address, s32 value, | 85 | ResultCode AddressArbiter::ModifyByWaitingCountAndSignalToAddressIfEqual(VAddr address, s32 value, |
| 84 | s32 num_to_wake) { | 86 | s32 num_to_wake) { |
| 87 | auto& memory = system.Memory(); | ||
| 88 | |||
| 85 | // Ensure that we can write to the address. | 89 | // Ensure that we can write to the address. |
| 86 | if (!system.Memory().IsValidVirtualAddress(address)) { | 90 | if (!memory.IsValidVirtualAddress(address)) { |
| 87 | return ERR_INVALID_ADDRESS_STATE; | 91 | return ERR_INVALID_ADDRESS_STATE; |
| 88 | } | 92 | } |
| 89 | 93 | ||
| @@ -109,7 +113,7 @@ ResultCode AddressArbiter::ModifyByWaitingCountAndSignalToAddressIfEqual(VAddr a | |||
| 109 | } | 113 | } |
| 110 | } | 114 | } |
| 111 | 115 | ||
| 112 | if (static_cast<s32>(Memory::Read32(address)) != value) { | 116 | if (static_cast<s32>(memory.Read32(address)) != value) { |
| 113 | return ERR_INVALID_STATE; | 117 | return ERR_INVALID_STATE; |
| 114 | } | 118 | } |
| 115 | 119 | ||
| @@ -134,12 +138,14 @@ ResultCode AddressArbiter::WaitForAddress(VAddr address, ArbitrationType type, s | |||
| 134 | 138 | ||
| 135 | ResultCode AddressArbiter::WaitForAddressIfLessThan(VAddr address, s32 value, s64 timeout, | 139 | ResultCode AddressArbiter::WaitForAddressIfLessThan(VAddr address, s32 value, s64 timeout, |
| 136 | bool should_decrement) { | 140 | bool should_decrement) { |
| 141 | auto& memory = system.Memory(); | ||
| 142 | |||
| 137 | // Ensure that we can read the address. | 143 | // Ensure that we can read the address. |
| 138 | if (!system.Memory().IsValidVirtualAddress(address)) { | 144 | if (!memory.IsValidVirtualAddress(address)) { |
| 139 | return ERR_INVALID_ADDRESS_STATE; | 145 | return ERR_INVALID_ADDRESS_STATE; |
| 140 | } | 146 | } |
| 141 | 147 | ||
| 142 | const s32 cur_value = static_cast<s32>(Memory::Read32(address)); | 148 | const s32 cur_value = static_cast<s32>(memory.Read32(address)); |
| 143 | if (cur_value >= value) { | 149 | if (cur_value >= value) { |
| 144 | return ERR_INVALID_STATE; | 150 | return ERR_INVALID_STATE; |
| 145 | } | 151 | } |
| @@ -157,15 +163,19 @@ ResultCode AddressArbiter::WaitForAddressIfLessThan(VAddr address, s32 value, s6 | |||
| 157 | } | 163 | } |
| 158 | 164 | ||
| 159 | ResultCode AddressArbiter::WaitForAddressIfEqual(VAddr address, s32 value, s64 timeout) { | 165 | ResultCode AddressArbiter::WaitForAddressIfEqual(VAddr address, s32 value, s64 timeout) { |
| 166 | auto& memory = system.Memory(); | ||
| 167 | |||
| 160 | // Ensure that we can read the address. | 168 | // Ensure that we can read the address. |
| 161 | if (!system.Memory().IsValidVirtualAddress(address)) { | 169 | if (!memory.IsValidVirtualAddress(address)) { |
| 162 | return ERR_INVALID_ADDRESS_STATE; | 170 | return ERR_INVALID_ADDRESS_STATE; |
| 163 | } | 171 | } |
| 172 | |||
| 164 | // Only wait for the address if equal. | 173 | // Only wait for the address if equal. |
| 165 | if (static_cast<s32>(Memory::Read32(address)) != value) { | 174 | if (static_cast<s32>(memory.Read32(address)) != value) { |
| 166 | return ERR_INVALID_STATE; | 175 | return ERR_INVALID_STATE; |
| 167 | } | 176 | } |
| 168 | // Short-circuit without rescheduling, if timeout is zero. | 177 | |
| 178 | // Short-circuit without rescheduling if timeout is zero. | ||
| 169 | if (timeout == 0) { | 179 | if (timeout == 0) { |
| 170 | return RESULT_TIMEOUT; | 180 | return RESULT_TIMEOUT; |
| 171 | } | 181 | } |
diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp index be24cef06..03745c449 100644 --- a/src/core/hle/kernel/hle_ipc.cpp +++ b/src/core/hle/kernel/hle_ipc.cpp | |||
| @@ -214,10 +214,11 @@ ResultCode HLERequestContext::PopulateFromIncomingCommandBuffer(const HandleTabl | |||
| 214 | ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(Thread& thread) { | 214 | ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(Thread& thread) { |
| 215 | auto& owner_process = *thread.GetOwnerProcess(); | 215 | auto& owner_process = *thread.GetOwnerProcess(); |
| 216 | auto& handle_table = owner_process.GetHandleTable(); | 216 | auto& handle_table = owner_process.GetHandleTable(); |
| 217 | auto& memory = Core::System::GetInstance().Memory(); | ||
| 217 | 218 | ||
| 218 | std::array<u32, IPC::COMMAND_BUFFER_LENGTH> dst_cmdbuf; | 219 | std::array<u32, IPC::COMMAND_BUFFER_LENGTH> dst_cmdbuf; |
| 219 | Memory::ReadBlock(owner_process, thread.GetTLSAddress(), dst_cmdbuf.data(), | 220 | memory.ReadBlock(owner_process, thread.GetTLSAddress(), dst_cmdbuf.data(), |
| 220 | dst_cmdbuf.size() * sizeof(u32)); | 221 | dst_cmdbuf.size() * sizeof(u32)); |
| 221 | 222 | ||
| 222 | // The header was already built in the internal command buffer. Attempt to parse it to verify | 223 | // The header was already built in the internal command buffer. Attempt to parse it to verify |
| 223 | // the integrity and then copy it over to the target command buffer. | 224 | // the integrity and then copy it over to the target command buffer. |
| @@ -282,15 +283,14 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(Thread& thread) { | |||
| 282 | std::vector<u8> HLERequestContext::ReadBuffer(int buffer_index) const { | 283 | std::vector<u8> HLERequestContext::ReadBuffer(int buffer_index) const { |
| 283 | std::vector<u8> buffer; | 284 | std::vector<u8> buffer; |
| 284 | const bool is_buffer_a{BufferDescriptorA().size() && BufferDescriptorA()[buffer_index].Size()}; | 285 | const bool is_buffer_a{BufferDescriptorA().size() && BufferDescriptorA()[buffer_index].Size()}; |
| 286 | auto& memory = Core::System::GetInstance().Memory(); | ||
| 285 | 287 | ||
| 286 | if (is_buffer_a) { | 288 | if (is_buffer_a) { |
| 287 | buffer.resize(BufferDescriptorA()[buffer_index].Size()); | 289 | buffer.resize(BufferDescriptorA()[buffer_index].Size()); |
| 288 | Memory::ReadBlock(BufferDescriptorA()[buffer_index].Address(), buffer.data(), | 290 | memory.ReadBlock(BufferDescriptorA()[buffer_index].Address(), buffer.data(), buffer.size()); |
| 289 | buffer.size()); | ||
| 290 | } else { | 291 | } else { |
| 291 | buffer.resize(BufferDescriptorX()[buffer_index].Size()); | 292 | buffer.resize(BufferDescriptorX()[buffer_index].Size()); |
| 292 | Memory::ReadBlock(BufferDescriptorX()[buffer_index].Address(), buffer.data(), | 293 | memory.ReadBlock(BufferDescriptorX()[buffer_index].Address(), buffer.data(), buffer.size()); |
| 293 | buffer.size()); | ||
| 294 | } | 294 | } |
| 295 | 295 | ||
| 296 | return buffer; | 296 | return buffer; |
diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp index 8493d0f78..88eede436 100644 --- a/src/core/hle/kernel/mutex.cpp +++ b/src/core/hle/kernel/mutex.cpp | |||
| @@ -79,7 +79,7 @@ ResultCode Mutex::TryAcquire(VAddr address, Handle holding_thread_handle, | |||
| 79 | // thread. | 79 | // thread. |
| 80 | ASSERT(requesting_thread == current_thread); | 80 | ASSERT(requesting_thread == current_thread); |
| 81 | 81 | ||
| 82 | const u32 addr_value = Memory::Read32(address); | 82 | const u32 addr_value = system.Memory().Read32(address); |
| 83 | 83 | ||
| 84 | // If the mutex isn't being held, just return success. | 84 | // If the mutex isn't being held, just return success. |
| 85 | if (addr_value != (holding_thread_handle | Mutex::MutexHasWaitersFlag)) { | 85 | if (addr_value != (holding_thread_handle | Mutex::MutexHasWaitersFlag)) { |
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 738db528d..a6c377cfc 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp | |||
| @@ -454,7 +454,8 @@ static ResultCode WaitSynchronization(Core::System& system, Handle* index, VAddr | |||
| 454 | LOG_TRACE(Kernel_SVC, "called handles_address=0x{:X}, handle_count={}, nano_seconds={}", | 454 | LOG_TRACE(Kernel_SVC, "called handles_address=0x{:X}, handle_count={}, nano_seconds={}", |
| 455 | handles_address, handle_count, nano_seconds); | 455 | handles_address, handle_count, nano_seconds); |
| 456 | 456 | ||
| 457 | if (!system.Memory().IsValidVirtualAddress(handles_address)) { | 457 | auto& memory = system.Memory(); |
| 458 | if (!memory.IsValidVirtualAddress(handles_address)) { | ||
| 458 | LOG_ERROR(Kernel_SVC, | 459 | LOG_ERROR(Kernel_SVC, |
| 459 | "Handle address is not a valid virtual address, handle_address=0x{:016X}", | 460 | "Handle address is not a valid virtual address, handle_address=0x{:016X}", |
| 460 | handles_address); | 461 | handles_address); |
| @@ -476,7 +477,7 @@ static ResultCode WaitSynchronization(Core::System& system, Handle* index, VAddr | |||
| 476 | const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); | 477 | const auto& handle_table = system.Kernel().CurrentProcess()->GetHandleTable(); |
| 477 | 478 | ||
| 478 | for (u64 i = 0; i < handle_count; ++i) { | 479 | for (u64 i = 0; i < handle_count; ++i) { |
| 479 | const Handle handle = Memory::Read32(handles_address + i * sizeof(Handle)); | 480 | const Handle handle = memory.Read32(handles_address + i * sizeof(Handle)); |
| 480 | const auto object = handle_table.Get<WaitObject>(handle); | 481 | const auto object = handle_table.Get<WaitObject>(handle); |
| 481 | 482 | ||
| 482 | if (object == nullptr) { | 483 | if (object == nullptr) { |
| @@ -618,13 +619,15 @@ static void Break(Core::System& system, u32 reason, u64 info1, u64 info2) { | |||
| 618 | return; | 619 | return; |
| 619 | } | 620 | } |
| 620 | 621 | ||
| 622 | auto& memory = system.Memory(); | ||
| 623 | |||
| 621 | // This typically is an error code so we're going to assume this is the case | 624 | // This typically is an error code so we're going to assume this is the case |
| 622 | if (sz == sizeof(u32)) { | 625 | if (sz == sizeof(u32)) { |
| 623 | LOG_CRITICAL(Debug_Emulated, "debug_buffer_err_code={:X}", Memory::Read32(addr)); | 626 | LOG_CRITICAL(Debug_Emulated, "debug_buffer_err_code={:X}", memory.Read32(addr)); |
| 624 | } else { | 627 | } else { |
| 625 | // We don't know what's in here so we'll hexdump it | 628 | // We don't know what's in here so we'll hexdump it |
| 626 | debug_buffer.resize(sz); | 629 | debug_buffer.resize(sz); |
| 627 | Memory::ReadBlock(addr, debug_buffer.data(), sz); | 630 | memory.ReadBlock(addr, debug_buffer.data(), sz); |
| 628 | std::string hexdump; | 631 | std::string hexdump; |
| 629 | for (std::size_t i = 0; i < debug_buffer.size(); i++) { | 632 | for (std::size_t i = 0; i < debug_buffer.size(); i++) { |
| 630 | hexdump += fmt::format("{:02X} ", debug_buffer[i]); | 633 | hexdump += fmt::format("{:02X} ", debug_buffer[i]); |
| @@ -714,7 +717,7 @@ static void OutputDebugString([[maybe_unused]] Core::System& system, VAddr addre | |||
| 714 | } | 717 | } |
| 715 | 718 | ||
| 716 | std::string str(len, '\0'); | 719 | std::string str(len, '\0'); |
| 717 | Memory::ReadBlock(address, str.data(), str.size()); | 720 | system.Memory().ReadBlock(address, str.data(), str.size()); |
| 718 | LOG_DEBUG(Debug_Emulated, "{}", str); | 721 | LOG_DEBUG(Debug_Emulated, "{}", str); |
| 719 | } | 722 | } |
| 720 | 723 | ||
| @@ -1674,6 +1677,7 @@ static ResultCode SignalProcessWideKey(Core::System& system, VAddr condition_var | |||
| 1674 | 1677 | ||
| 1675 | const std::size_t current_core = system.CurrentCoreIndex(); | 1678 | const std::size_t current_core = system.CurrentCoreIndex(); |
| 1676 | auto& monitor = system.Monitor(); | 1679 | auto& monitor = system.Monitor(); |
| 1680 | auto& memory = system.Memory(); | ||
| 1677 | 1681 | ||
| 1678 | // Atomically read the value of the mutex. | 1682 | // Atomically read the value of the mutex. |
| 1679 | u32 mutex_val = 0; | 1683 | u32 mutex_val = 0; |
| @@ -1683,7 +1687,7 @@ static ResultCode SignalProcessWideKey(Core::System& system, VAddr condition_var | |||
| 1683 | monitor.SetExclusive(current_core, mutex_address); | 1687 | monitor.SetExclusive(current_core, mutex_address); |
| 1684 | 1688 | ||
| 1685 | // If the mutex is not yet acquired, acquire it. | 1689 | // If the mutex is not yet acquired, acquire it. |
| 1686 | mutex_val = Memory::Read32(mutex_address); | 1690 | mutex_val = memory.Read32(mutex_address); |
| 1687 | 1691 | ||
| 1688 | if (mutex_val != 0) { | 1692 | if (mutex_val != 0) { |
| 1689 | update_val = mutex_val | Mutex::MutexHasWaitersFlag; | 1693 | update_val = mutex_val | Mutex::MutexHasWaitersFlag; |