summaryrefslogtreecommitdiff
path: root/src/core/hle
diff options
context:
space:
mode:
authorGravatar Lioncash2019-11-26 16:29:34 -0500
committerGravatar Lioncash2019-11-26 21:55:39 -0500
commitb05bfc603689419dc515a656b9fc711d79994f13 (patch)
treebc0937d11bbe31458785a69478edbf11a720b0ae /src/core/hle
parentcore/memory: Migrate over ZeroBlock() and CopyBlock() to the Memory class (diff)
downloadyuzu-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')
-rw-r--r--src/core/hle/kernel/address_arbiter.cpp28
-rw-r--r--src/core/hle/kernel/hle_ipc.cpp12
-rw-r--r--src/core/hle/kernel/mutex.cpp2
-rw-r--r--src/core/hle/kernel/svc.cpp16
-rw-r--r--src/core/hle/service/audio/audout_u.cpp6
-rw-r--r--src/core/hle/service/ldr/ldr.cpp5
-rw-r--r--src/core/hle/service/lm/lm.cpp10
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp4
8 files changed, 50 insertions, 33 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
68ResultCode AddressArbiter::IncrementAndSignalToAddressIfEqual(VAddr address, s32 value, 68ResultCode 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
83ResultCode AddressArbiter::ModifyByWaitingCountAndSignalToAddressIfEqual(VAddr address, s32 value, 85ResultCode 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
135ResultCode AddressArbiter::WaitForAddressIfLessThan(VAddr address, s32 value, s64 timeout, 139ResultCode 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
159ResultCode AddressArbiter::WaitForAddressIfEqual(VAddr address, s32 value, s64 timeout) { 165ResultCode 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
214ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(Thread& thread) { 214ResultCode 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) {
282std::vector<u8> HLERequestContext::ReadBuffer(int buffer_index) const { 283std::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;
diff --git a/src/core/hle/service/audio/audout_u.cpp b/src/core/hle/service/audio/audout_u.cpp
index 6a29377e3..4fb2cbc4b 100644
--- a/src/core/hle/service/audio/audout_u.cpp
+++ b/src/core/hle/service/audio/audout_u.cpp
@@ -43,7 +43,8 @@ public:
43 IAudioOut(Core::System& system, AudoutParams audio_params, AudioCore::AudioOut& audio_core, 43 IAudioOut(Core::System& system, AudoutParams audio_params, AudioCore::AudioOut& audio_core,
44 std::string&& device_name, std::string&& unique_name) 44 std::string&& device_name, std::string&& unique_name)
45 : ServiceFramework("IAudioOut"), audio_core(audio_core), 45 : ServiceFramework("IAudioOut"), audio_core(audio_core),
46 device_name(std::move(device_name)), audio_params(audio_params) { 46 device_name(std::move(device_name)),
47 audio_params(audio_params), main_memory{system.Memory()} {
47 // clang-format off 48 // clang-format off
48 static const FunctionInfo functions[] = { 49 static const FunctionInfo functions[] = {
49 {0, &IAudioOut::GetAudioOutState, "GetAudioOutState"}, 50 {0, &IAudioOut::GetAudioOutState, "GetAudioOutState"},
@@ -137,7 +138,7 @@ private:
137 const u64 tag{rp.Pop<u64>()}; 138 const u64 tag{rp.Pop<u64>()};
138 139
139 std::vector<s16> samples(audio_buffer.buffer_size / sizeof(s16)); 140 std::vector<s16> samples(audio_buffer.buffer_size / sizeof(s16));
140 Memory::ReadBlock(audio_buffer.buffer, samples.data(), audio_buffer.buffer_size); 141 main_memory.ReadBlock(audio_buffer.buffer, samples.data(), audio_buffer.buffer_size);
141 142
142 if (!audio_core.QueueBuffer(stream, tag, std::move(samples))) { 143 if (!audio_core.QueueBuffer(stream, tag, std::move(samples))) {
143 IPC::ResponseBuilder rb{ctx, 2}; 144 IPC::ResponseBuilder rb{ctx, 2};
@@ -209,6 +210,7 @@ private:
209 210
210 /// This is the event handle used to check if the audio buffer was released 211 /// This is the event handle used to check if the audio buffer was released
211 Kernel::EventPair buffer_event; 212 Kernel::EventPair buffer_event;
213 Memory::Memory& main_memory;
212}; 214};
213 215
214AudOutU::AudOutU(Core::System& system_) : ServiceFramework("audout:u"), system{system_} { 216AudOutU::AudOutU(Core::System& system_) : ServiceFramework("audout:u"), system{system_} {
diff --git a/src/core/hle/service/ldr/ldr.cpp b/src/core/hle/service/ldr/ldr.cpp
index 88f903bfd..157aeec88 100644
--- a/src/core/hle/service/ldr/ldr.cpp
+++ b/src/core/hle/service/ldr/ldr.cpp
@@ -140,9 +140,10 @@ public:
140 rb.Push(ERROR_INVALID_SIZE); 140 rb.Push(ERROR_INVALID_SIZE);
141 return; 141 return;
142 } 142 }
143
143 // Read NRR data from memory 144 // Read NRR data from memory
144 std::vector<u8> nrr_data(nrr_size); 145 std::vector<u8> nrr_data(nrr_size);
145 Memory::ReadBlock(nrr_address, nrr_data.data(), nrr_size); 146 system.Memory().ReadBlock(nrr_address, nrr_data.data(), nrr_size);
146 NRRHeader header; 147 NRRHeader header;
147 std::memcpy(&header, nrr_data.data(), sizeof(NRRHeader)); 148 std::memcpy(&header, nrr_data.data(), sizeof(NRRHeader));
148 149
@@ -291,7 +292,7 @@ public:
291 292
292 // Read NRO data from memory 293 // Read NRO data from memory
293 std::vector<u8> nro_data(nro_size); 294 std::vector<u8> nro_data(nro_size);
294 Memory::ReadBlock(nro_address, nro_data.data(), nro_size); 295 system.Memory().ReadBlock(nro_address, nro_data.data(), nro_size);
295 296
296 SHA256Hash hash{}; 297 SHA256Hash hash{};
297 mbedtls_sha256_ret(nro_data.data(), nro_data.size(), hash.data(), 0); 298 mbedtls_sha256_ret(nro_data.data(), nro_data.size(), hash.data(), 0);
diff --git a/src/core/hle/service/lm/lm.cpp b/src/core/hle/service/lm/lm.cpp
index 74ecaef1b..346c8f899 100644
--- a/src/core/hle/service/lm/lm.cpp
+++ b/src/core/hle/service/lm/lm.cpp
@@ -36,15 +36,15 @@ private:
36 MessageHeader header{}; 36 MessageHeader header{};
37 VAddr addr{ctx.BufferDescriptorX()[0].Address()}; 37 VAddr addr{ctx.BufferDescriptorX()[0].Address()};
38 const VAddr end_addr{addr + ctx.BufferDescriptorX()[0].size}; 38 const VAddr end_addr{addr + ctx.BufferDescriptorX()[0].size};
39 Memory::ReadBlock(addr, &header, sizeof(MessageHeader)); 39 memory.ReadBlock(addr, &header, sizeof(MessageHeader));
40 addr += sizeof(MessageHeader); 40 addr += sizeof(MessageHeader);
41 41
42 FieldMap fields; 42 FieldMap fields;
43 while (addr < end_addr) { 43 while (addr < end_addr) {
44 const auto field = static_cast<Field>(Memory::Read8(addr++)); 44 const auto field = static_cast<Field>(memory.Read8(addr++));
45 const auto length = Memory::Read8(addr++); 45 const auto length = memory.Read8(addr++);
46 46
47 if (static_cast<Field>(Memory::Read8(addr)) == Field::Skip) { 47 if (static_cast<Field>(memory.Read8(addr)) == Field::Skip) {
48 ++addr; 48 ++addr;
49 } 49 }
50 50
@@ -55,7 +55,7 @@ private:
55 } 55 }
56 56
57 std::vector<u8> data(length); 57 std::vector<u8> data(length);
58 Memory::ReadBlock(addr, data.data(), length); 58 memory.ReadBlock(addr, data.data(), length);
59 fields.emplace(field, std::move(data)); 59 fields.emplace(field, std::move(data));
60 } 60 }
61 61
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp
index 9de0ace22..6d8bca8bb 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp
@@ -191,8 +191,8 @@ u32 nvhost_gpu::KickoffPB(const std::vector<u8>& input, std::vector<u8>& output,
191 std::memcpy(entries.data(), input2.data(), 191 std::memcpy(entries.data(), input2.data(),
192 params.num_entries * sizeof(Tegra::CommandListHeader)); 192 params.num_entries * sizeof(Tegra::CommandListHeader));
193 } else { 193 } else {
194 Memory::ReadBlock(params.address, entries.data(), 194 system.Memory().ReadBlock(params.address, entries.data(),
195 params.num_entries * sizeof(Tegra::CommandListHeader)); 195 params.num_entries * sizeof(Tegra::CommandListHeader));
196 } 196 }
197 UNIMPLEMENTED_IF(params.flags.add_wait.Value() != 0); 197 UNIMPLEMENTED_IF(params.flags.add_wait.Value() != 0);
198 UNIMPLEMENTED_IF(params.flags.add_increment.Value() != 0); 198 UNIMPLEMENTED_IF(params.flags.add_increment.Value() != 0);