diff options
| author | 2018-12-27 20:28:15 -0500 | |
|---|---|---|
| committer | 2018-12-27 20:32:30 -0500 | |
| commit | 771431f62539a991cc4d8cf5dc4908bb5b366da2 (patch) | |
| tree | db724de34e5e8a8326ce1a061553520cbd157944 /src/core | |
| parent | Merge pull request #1951 from Tinob/master (diff) | |
| download | yuzu-771431f62539a991cc4d8cf5dc4908bb5b366da2.tar.gz yuzu-771431f62539a991cc4d8cf5dc4908bb5b366da2.tar.xz yuzu-771431f62539a991cc4d8cf5dc4908bb5b366da2.zip | |
kernel/thread: Move process thread initialization into process.cpp
This function isn't a general purpose function that should be exposed to
everything, given it's specific to initializing the main thread for a
Process instance.
Given that, it's a tad bit more sensible to place this within
process.cpp, which keeps it visible only to the code that actually needs
it.
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/hle/kernel/process.cpp | 31 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.cpp | 24 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.h | 11 |
3 files changed, 30 insertions, 36 deletions
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 4f209a979..81a23dfbf 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp | |||
| @@ -20,6 +20,35 @@ | |||
| 20 | #include "core/settings.h" | 20 | #include "core/settings.h" |
| 21 | 21 | ||
| 22 | namespace Kernel { | 22 | namespace Kernel { |
| 23 | namespace { | ||
| 24 | /** | ||
| 25 | * Sets up the primary application thread | ||
| 26 | * | ||
| 27 | * @param owner_process The parent process for the main thread | ||
| 28 | * @param kernel The kernel instance to create the main thread under. | ||
| 29 | * @param entry_point The address at which the thread should start execution | ||
| 30 | * @param priority The priority to give the main thread | ||
| 31 | */ | ||
| 32 | void SetupMainThread(Process& owner_process, KernelCore& kernel, VAddr entry_point, u32 priority) { | ||
| 33 | // Setup page table so we can write to memory | ||
| 34 | SetCurrentPageTable(&owner_process.VMManager().page_table); | ||
| 35 | |||
| 36 | // Initialize new "main" thread | ||
| 37 | const VAddr stack_top = owner_process.VMManager().GetTLSIORegionEndAddress(); | ||
| 38 | auto thread_res = Thread::Create(kernel, "main", entry_point, priority, 0, THREADPROCESSORID_0, | ||
| 39 | stack_top, owner_process); | ||
| 40 | |||
| 41 | SharedPtr<Thread> thread = std::move(thread_res).Unwrap(); | ||
| 42 | |||
| 43 | // Register 1 must be a handle to the main thread | ||
| 44 | const Handle guest_handle = owner_process.GetHandleTable().Create(thread).Unwrap(); | ||
| 45 | thread->SetGuestHandle(guest_handle); | ||
| 46 | thread->GetContext().cpu_registers[1] = guest_handle; | ||
| 47 | |||
| 48 | // Threads by default are dormant, wake up the main thread so it runs when the scheduler fires | ||
| 49 | thread->ResumeFromWait(); | ||
| 50 | } | ||
| 51 | } // Anonymous namespace | ||
| 23 | 52 | ||
| 24 | CodeSet::CodeSet() = default; | 53 | CodeSet::CodeSet() = default; |
| 25 | CodeSet::~CodeSet() = default; | 54 | CodeSet::~CodeSet() = default; |
| @@ -86,7 +115,7 @@ void Process::Run(VAddr entry_point, s32 main_thread_priority, u32 stack_size) { | |||
| 86 | vm_manager.LogLayout(); | 115 | vm_manager.LogLayout(); |
| 87 | ChangeStatus(ProcessStatus::Running); | 116 | ChangeStatus(ProcessStatus::Running); |
| 88 | 117 | ||
| 89 | Kernel::SetupMainThread(kernel, entry_point, main_thread_priority, *this); | 118 | SetupMainThread(*this, kernel, entry_point, main_thread_priority); |
| 90 | } | 119 | } |
| 91 | 120 | ||
| 92 | void Process::PrepareForTermination() { | 121 | void Process::PrepareForTermination() { |
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 434655638..d3984dfc4 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -12,7 +12,6 @@ | |||
| 12 | #include "common/assert.h" | 12 | #include "common/assert.h" |
| 13 | #include "common/common_types.h" | 13 | #include "common/common_types.h" |
| 14 | #include "common/logging/log.h" | 14 | #include "common/logging/log.h" |
| 15 | #include "common/math_util.h" | ||
| 16 | #include "common/thread_queue_list.h" | 15 | #include "common/thread_queue_list.h" |
| 17 | #include "core/arm/arm_interface.h" | 16 | #include "core/arm/arm_interface.h" |
| 18 | #include "core/core.h" | 17 | #include "core/core.h" |
| @@ -232,29 +231,6 @@ void Thread::BoostPriority(u32 priority) { | |||
| 232 | current_priority = priority; | 231 | current_priority = priority; |
| 233 | } | 232 | } |
| 234 | 233 | ||
| 235 | SharedPtr<Thread> SetupMainThread(KernelCore& kernel, VAddr entry_point, u32 priority, | ||
| 236 | Process& owner_process) { | ||
| 237 | // Setup page table so we can write to memory | ||
| 238 | SetCurrentPageTable(&owner_process.VMManager().page_table); | ||
| 239 | |||
| 240 | // Initialize new "main" thread | ||
| 241 | const VAddr stack_top = owner_process.VMManager().GetTLSIORegionEndAddress(); | ||
| 242 | auto thread_res = Thread::Create(kernel, "main", entry_point, priority, 0, THREADPROCESSORID_0, | ||
| 243 | stack_top, owner_process); | ||
| 244 | |||
| 245 | SharedPtr<Thread> thread = std::move(thread_res).Unwrap(); | ||
| 246 | |||
| 247 | // Register 1 must be a handle to the main thread | ||
| 248 | const Handle guest_handle = owner_process.GetHandleTable().Create(thread).Unwrap(); | ||
| 249 | thread->SetGuestHandle(guest_handle); | ||
| 250 | thread->GetContext().cpu_registers[1] = guest_handle; | ||
| 251 | |||
| 252 | // Threads by default are dormant, wake up the main thread so it runs when the scheduler fires | ||
| 253 | thread->ResumeFromWait(); | ||
| 254 | |||
| 255 | return thread; | ||
| 256 | } | ||
| 257 | |||
| 258 | void Thread::SetWaitSynchronizationResult(ResultCode result) { | 234 | void Thread::SetWaitSynchronizationResult(ResultCode result) { |
| 259 | context.cpu_registers[0] = result.raw; | 235 | context.cpu_registers[0] = result.raw; |
| 260 | } | 236 | } |
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index fe5398d56..cc68eed2f 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h | |||
| @@ -456,17 +456,6 @@ private: | |||
| 456 | }; | 456 | }; |
| 457 | 457 | ||
| 458 | /** | 458 | /** |
| 459 | * Sets up the primary application thread | ||
| 460 | * @param kernel The kernel instance to create the main thread under. | ||
| 461 | * @param entry_point The address at which the thread should start execution | ||
| 462 | * @param priority The priority to give the main thread | ||
| 463 | * @param owner_process The parent process for the main thread | ||
| 464 | * @return A shared pointer to the main thread | ||
| 465 | */ | ||
| 466 | SharedPtr<Thread> SetupMainThread(KernelCore& kernel, VAddr entry_point, u32 priority, | ||
| 467 | Process& owner_process); | ||
| 468 | |||
| 469 | /** | ||
| 470 | * Gets the current thread | 459 | * Gets the current thread |
| 471 | */ | 460 | */ |
| 472 | Thread* GetCurrentThread(); | 461 | Thread* GetCurrentThread(); |