summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel
diff options
context:
space:
mode:
authorGravatar Lioncash2019-11-26 17:39:57 -0500
committerGravatar Lioncash2019-11-26 21:55:39 -0500
commite4c381b8850db96f162cfcf2cbe28b0e7c1f76f1 (patch)
tree14b95ea207543f3884558ebdf8673a511bf64dc3 /src/core/hle/kernel
parentcore/memory: Migrate over Read{8, 16, 32, 64, Block} to the Memory class (diff)
downloadyuzu-e4c381b8850db96f162cfcf2cbe28b0e7c1f76f1.tar.gz
yuzu-e4c381b8850db96f162cfcf2cbe28b0e7c1f76f1.tar.xz
yuzu-e4c381b8850db96f162cfcf2cbe28b0e7c1f76f1.zip
core/memory: Migrate over Write{8, 16, 32, 64, Block} to the Memory class
The Write functions are used slightly less than the Read functions, which make these a bit nicer to move over. The only adjustments we really need to make here are to Dynarmic's exclusive monitor instance. We need to keep a reference to the currently active memory instance to perform exclusive read/write operations.
Diffstat (limited to 'src/core/hle/kernel')
-rw-r--r--src/core/hle/kernel/address_arbiter.cpp6
-rw-r--r--src/core/hle/kernel/hle_ipc.cpp9
-rw-r--r--src/core/hle/kernel/mutex.cpp4
-rw-r--r--src/core/hle/kernel/svc.cpp27
4 files changed, 25 insertions, 21 deletions
diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cpp
index 07f0dac67..98d07fa5b 100644
--- a/src/core/hle/kernel/address_arbiter.cpp
+++ b/src/core/hle/kernel/address_arbiter.cpp
@@ -78,7 +78,7 @@ ResultCode AddressArbiter::IncrementAndSignalToAddressIfEqual(VAddr address, s32
78 return ERR_INVALID_STATE; 78 return ERR_INVALID_STATE;
79 } 79 }
80 80
81 Memory::Write32(address, static_cast<u32>(value + 1)); 81 memory.Write32(address, static_cast<u32>(value + 1));
82 return SignalToAddressOnly(address, num_to_wake); 82 return SignalToAddressOnly(address, num_to_wake);
83} 83}
84 84
@@ -117,7 +117,7 @@ ResultCode AddressArbiter::ModifyByWaitingCountAndSignalToAddressIfEqual(VAddr a
117 return ERR_INVALID_STATE; 117 return ERR_INVALID_STATE;
118 } 118 }
119 119
120 Memory::Write32(address, static_cast<u32>(updated_value)); 120 memory.Write32(address, static_cast<u32>(updated_value));
121 WakeThreads(waiting_threads, num_to_wake); 121 WakeThreads(waiting_threads, num_to_wake);
122 return RESULT_SUCCESS; 122 return RESULT_SUCCESS;
123} 123}
@@ -151,7 +151,7 @@ ResultCode AddressArbiter::WaitForAddressIfLessThan(VAddr address, s32 value, s6
151 } 151 }
152 152
153 if (should_decrement) { 153 if (should_decrement) {
154 Memory::Write32(address, static_cast<u32>(cur_value - 1)); 154 memory.Write32(address, static_cast<u32>(cur_value - 1));
155 } 155 }
156 156
157 // Short-circuit without rescheduling, if timeout is zero. 157 // Short-circuit without rescheduling, if timeout is zero.
diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp
index 03745c449..8b01567a8 100644
--- a/src/core/hle/kernel/hle_ipc.cpp
+++ b/src/core/hle/kernel/hle_ipc.cpp
@@ -274,8 +274,8 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(Thread& thread) {
274 } 274 }
275 275
276 // Copy the translated command buffer back into the thread's command buffer area. 276 // Copy the translated command buffer back into the thread's command buffer area.
277 Memory::WriteBlock(owner_process, thread.GetTLSAddress(), dst_cmdbuf.data(), 277 memory.WriteBlock(owner_process, thread.GetTLSAddress(), dst_cmdbuf.data(),
278 dst_cmdbuf.size() * sizeof(u32)); 278 dst_cmdbuf.size() * sizeof(u32));
279 279
280 return RESULT_SUCCESS; 280 return RESULT_SUCCESS;
281} 281}
@@ -311,10 +311,11 @@ std::size_t HLERequestContext::WriteBuffer(const void* buffer, std::size_t size,
311 size = buffer_size; // TODO(bunnei): This needs to be HW tested 311 size = buffer_size; // TODO(bunnei): This needs to be HW tested
312 } 312 }
313 313
314 auto& memory = Core::System::GetInstance().Memory();
314 if (is_buffer_b) { 315 if (is_buffer_b) {
315 Memory::WriteBlock(BufferDescriptorB()[buffer_index].Address(), buffer, size); 316 memory.WriteBlock(BufferDescriptorB()[buffer_index].Address(), buffer, size);
316 } else { 317 } else {
317 Memory::WriteBlock(BufferDescriptorC()[buffer_index].Address(), buffer, size); 318 memory.WriteBlock(BufferDescriptorC()[buffer_index].Address(), buffer, size);
318 } 319 }
319 320
320 return size; 321 return size;
diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp
index 88eede436..061e9bcb0 100644
--- a/src/core/hle/kernel/mutex.cpp
+++ b/src/core/hle/kernel/mutex.cpp
@@ -117,7 +117,7 @@ ResultCode Mutex::Release(VAddr address) {
117 117
118 // There are no more threads waiting for the mutex, release it completely. 118 // There are no more threads waiting for the mutex, release it completely.
119 if (thread == nullptr) { 119 if (thread == nullptr) {
120 Memory::Write32(address, 0); 120 system.Memory().Write32(address, 0);
121 return RESULT_SUCCESS; 121 return RESULT_SUCCESS;
122 } 122 }
123 123
@@ -132,7 +132,7 @@ ResultCode Mutex::Release(VAddr address) {
132 } 132 }
133 133
134 // Grant the mutex to the next waiting thread and resume it. 134 // Grant the mutex to the next waiting thread and resume it.
135 Memory::Write32(address, mutex_value); 135 system.Memory().Write32(address, mutex_value);
136 136
137 ASSERT(thread->GetStatus() == ThreadStatus::WaitMutex); 137 ASSERT(thread->GetStatus() == ThreadStatus::WaitMutex);
138 thread->ResumeFromWait(); 138 thread->ResumeFromWait();
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index a6c377cfc..db3ae3eb8 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -1120,7 +1120,7 @@ static ResultCode GetThreadContext(Core::System& system, VAddr thread_context, H
1120 std::fill(ctx.vector_registers.begin() + 16, ctx.vector_registers.end(), u128{}); 1120 std::fill(ctx.vector_registers.begin() + 16, ctx.vector_registers.end(), u128{});
1121 } 1121 }
1122 1122
1123 Memory::WriteBlock(thread_context, &ctx, sizeof(ctx)); 1123 system.Memory().WriteBlock(thread_context, &ctx, sizeof(ctx));
1124 return RESULT_SUCCESS; 1124 return RESULT_SUCCESS;
1125} 1125}
1126 1126
@@ -1280,20 +1280,21 @@ static ResultCode QueryProcessMemory(Core::System& system, VAddr memory_info_add
1280 return ERR_INVALID_HANDLE; 1280 return ERR_INVALID_HANDLE;
1281 } 1281 }
1282 1282
1283 auto& memory = system.Memory();
1283 const auto& vm_manager = process->VMManager(); 1284 const auto& vm_manager = process->VMManager();
1284 const MemoryInfo memory_info = vm_manager.QueryMemory(address); 1285 const MemoryInfo memory_info = vm_manager.QueryMemory(address);
1285 1286
1286 Memory::Write64(memory_info_address, memory_info.base_address); 1287 memory.Write64(memory_info_address, memory_info.base_address);
1287 Memory::Write64(memory_info_address + 8, memory_info.size); 1288 memory.Write64(memory_info_address + 8, memory_info.size);
1288 Memory::Write32(memory_info_address + 16, memory_info.state); 1289 memory.Write32(memory_info_address + 16, memory_info.state);
1289 Memory::Write32(memory_info_address + 20, memory_info.attributes); 1290 memory.Write32(memory_info_address + 20, memory_info.attributes);
1290 Memory::Write32(memory_info_address + 24, memory_info.permission); 1291 memory.Write32(memory_info_address + 24, memory_info.permission);
1291 Memory::Write32(memory_info_address + 32, memory_info.ipc_ref_count); 1292 memory.Write32(memory_info_address + 32, memory_info.ipc_ref_count);
1292 Memory::Write32(memory_info_address + 28, memory_info.device_ref_count); 1293 memory.Write32(memory_info_address + 28, memory_info.device_ref_count);
1293 Memory::Write32(memory_info_address + 36, 0); 1294 memory.Write32(memory_info_address + 36, 0);
1294 1295
1295 // Page info appears to be currently unused by the kernel and is always set to zero. 1296 // Page info appears to be currently unused by the kernel and is always set to zero.
1296 Memory::Write32(page_info_address, 0); 1297 memory.Write32(page_info_address, 0);
1297 1298
1298 return RESULT_SUCCESS; 1299 return RESULT_SUCCESS;
1299} 1300}
@@ -2290,12 +2291,13 @@ static ResultCode GetProcessList(Core::System& system, u32* out_num_processes,
2290 return ERR_INVALID_ADDRESS_STATE; 2291 return ERR_INVALID_ADDRESS_STATE;
2291 } 2292 }
2292 2293
2294 auto& memory = system.Memory();
2293 const auto& process_list = kernel.GetProcessList(); 2295 const auto& process_list = kernel.GetProcessList();
2294 const auto num_processes = process_list.size(); 2296 const auto num_processes = process_list.size();
2295 const auto copy_amount = std::min(std::size_t{out_process_ids_size}, num_processes); 2297 const auto copy_amount = std::min(std::size_t{out_process_ids_size}, num_processes);
2296 2298
2297 for (std::size_t i = 0; i < copy_amount; ++i) { 2299 for (std::size_t i = 0; i < copy_amount; ++i) {
2298 Memory::Write64(out_process_ids, process_list[i]->GetProcessID()); 2300 memory.Write64(out_process_ids, process_list[i]->GetProcessID());
2299 out_process_ids += sizeof(u64); 2301 out_process_ids += sizeof(u64);
2300 } 2302 }
2301 2303
@@ -2329,13 +2331,14 @@ static ResultCode GetThreadList(Core::System& system, u32* out_num_threads, VAdd
2329 return ERR_INVALID_ADDRESS_STATE; 2331 return ERR_INVALID_ADDRESS_STATE;
2330 } 2332 }
2331 2333
2334 auto& memory = system.Memory();
2332 const auto& thread_list = current_process->GetThreadList(); 2335 const auto& thread_list = current_process->GetThreadList();
2333 const auto num_threads = thread_list.size(); 2336 const auto num_threads = thread_list.size();
2334 const auto copy_amount = std::min(std::size_t{out_thread_ids_size}, num_threads); 2337 const auto copy_amount = std::min(std::size_t{out_thread_ids_size}, num_threads);
2335 2338
2336 auto list_iter = thread_list.cbegin(); 2339 auto list_iter = thread_list.cbegin();
2337 for (std::size_t i = 0; i < copy_amount; ++i, ++list_iter) { 2340 for (std::size_t i = 0; i < copy_amount; ++i, ++list_iter) {
2338 Memory::Write64(out_thread_ids, (*list_iter)->GetThreadID()); 2341 memory.Write64(out_thread_ids, (*list_iter)->GetThreadID());
2339 out_thread_ids += sizeof(u64); 2342 out_thread_ids += sizeof(u64);
2340 } 2343 }
2341 2344