summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/core/core.cpp6
-rw-r--r--src/core/loader/3dsx.cpp15
-rw-r--r--src/core/loader/3dsx.h2
-rw-r--r--src/core/loader/elf.cpp15
-rw-r--r--src/core/loader/elf.h2
-rw-r--r--src/core/loader/loader.h13
-rw-r--r--src/core/loader/ncch.cpp19
-rw-r--r--src/core/loader/ncch.h5
8 files changed, 40 insertions, 37 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp
index 59b8768e7..0c7a72987 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -13,6 +13,7 @@
13#include "core/core_timing.h" 13#include "core/core_timing.h"
14#include "core/gdbstub/gdbstub.h" 14#include "core/gdbstub/gdbstub.h"
15#include "core/hle/kernel/kernel.h" 15#include "core/hle/kernel/kernel.h"
16#include "core/hle/kernel/process.h"
16#include "core/hle/kernel/thread.h" 17#include "core/hle/kernel/thread.h"
17#include "core/hle/service/service.h" 18#include "core/hle/service/service.h"
18#include "core/hw/hw.h" 19#include "core/hw/hw.h"
@@ -100,7 +101,7 @@ System::ResultStatus System::Load(EmuWindow* emu_window, const std::string& file
100 return init_result; 101 return init_result;
101 } 102 }
102 103
103 const Loader::ResultStatus load_result{app_loader->Load()}; 104 const Loader::ResultStatus load_result{app_loader->Load(Kernel::g_current_process)};
104 if (Loader::ResultStatus::Success != load_result) { 105 if (Loader::ResultStatus::Success != load_result) {
105 LOG_CRITICAL(Core, "Failed to load ROM (Error %i)!", load_result); 106 LOG_CRITICAL(Core, "Failed to load ROM (Error %i)!", load_result);
106 System::Shutdown(); 107 System::Shutdown();
@@ -114,6 +115,7 @@ System::ResultStatus System::Load(EmuWindow* emu_window, const std::string& file
114 return ResultStatus::ErrorLoader; 115 return ResultStatus::ErrorLoader;
115 } 116 }
116 } 117 }
118 Memory::SetCurrentPageTable(&Kernel::g_current_process->vm_manager.page_table);
117 status = ResultStatus::Success; 119 status = ResultStatus::Success;
118 return status; 120 return status;
119} 121}
@@ -196,4 +198,4 @@ void System::Shutdown() {
196 LOG_DEBUG(Core, "Shutdown OK"); 198 LOG_DEBUG(Core, "Shutdown OK");
197} 199}
198 200
199} // namespace 201} // namespace Core
diff --git a/src/core/loader/3dsx.cpp b/src/core/loader/3dsx.cpp
index 5ad5c5287..918038f1e 100644
--- a/src/core/loader/3dsx.cpp
+++ b/src/core/loader/3dsx.cpp
@@ -91,8 +91,8 @@ static u32 TranslateAddr(u32 addr, const THREEloadinfo* loadinfo, u32* offsets)
91 return loadinfo->seg_addrs[2] + addr - offsets[1]; 91 return loadinfo->seg_addrs[2] + addr - offsets[1];
92} 92}
93 93
94using Kernel::SharedPtr;
95using Kernel::CodeSet; 94using Kernel::CodeSet;
95using Kernel::SharedPtr;
96 96
97static THREEDSX_Error Load3DSXFile(FileUtil::IOFile& file, u32 base_addr, 97static THREEDSX_Error Load3DSXFile(FileUtil::IOFile& file, u32 base_addr,
98 SharedPtr<CodeSet>* out_codeset) { 98 SharedPtr<CodeSet>* out_codeset) {
@@ -255,7 +255,7 @@ FileType AppLoader_THREEDSX::IdentifyType(FileUtil::IOFile& file) {
255 return FileType::Error; 255 return FileType::Error;
256} 256}
257 257
258ResultStatus AppLoader_THREEDSX::Load() { 258ResultStatus AppLoader_THREEDSX::Load(Kernel::SharedPtr<Kernel::Process>& process) {
259 if (is_loaded) 259 if (is_loaded)
260 return ResultStatus::ErrorAlreadyLoaded; 260 return ResultStatus::ErrorAlreadyLoaded;
261 261
@@ -267,16 +267,15 @@ ResultStatus AppLoader_THREEDSX::Load() {
267 return ResultStatus::Error; 267 return ResultStatus::Error;
268 codeset->name = filename; 268 codeset->name = filename;
269 269
270 Kernel::g_current_process = Kernel::Process::Create(std::move(codeset)); 270 process = Kernel::Process::Create(std::move(codeset));
271 Kernel::g_current_process->svc_access_mask.set(); 271 process->svc_access_mask.set();
272 Kernel::g_current_process->address_mappings = default_address_mappings; 272 process->address_mappings = default_address_mappings;
273 Memory::SetCurrentPageTable(&Kernel::g_current_process->vm_manager.page_table);
274 273
275 // Attach the default resource limit (APPLICATION) to the process 274 // Attach the default resource limit (APPLICATION) to the process
276 Kernel::g_current_process->resource_limit = 275 process->resource_limit =
277 Kernel::ResourceLimit::GetForCategory(Kernel::ResourceLimitCategory::APPLICATION); 276 Kernel::ResourceLimit::GetForCategory(Kernel::ResourceLimitCategory::APPLICATION);
278 277
279 Kernel::g_current_process->Run(48, Kernel::DEFAULT_STACK_SIZE); 278 process->Run(48, Kernel::DEFAULT_STACK_SIZE);
280 279
281 Service::FS::RegisterSelfNCCH(*this); 280 Service::FS::RegisterSelfNCCH(*this);
282 281
diff --git a/src/core/loader/3dsx.h b/src/core/loader/3dsx.h
index 3f376778a..1e59bbb9d 100644
--- a/src/core/loader/3dsx.h
+++ b/src/core/loader/3dsx.h
@@ -31,7 +31,7 @@ public:
31 return IdentifyType(file); 31 return IdentifyType(file);
32 } 32 }
33 33
34 ResultStatus Load() override; 34 ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override;
35 35
36 ResultStatus ReadIcon(std::vector<u8>& buffer) override; 36 ResultStatus ReadIcon(std::vector<u8>& buffer) override;
37 37
diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp
index 2de1f4e81..e36e42120 100644
--- a/src/core/loader/elf.cpp
+++ b/src/core/loader/elf.cpp
@@ -13,8 +13,8 @@
13#include "core/loader/elf.h" 13#include "core/loader/elf.h"
14#include "core/memory.h" 14#include "core/memory.h"
15 15
16using Kernel::SharedPtr;
17using Kernel::CodeSet; 16using Kernel::CodeSet;
17using Kernel::SharedPtr;
18 18
19//////////////////////////////////////////////////////////////////////////////////////////////////// 19////////////////////////////////////////////////////////////////////////////////////////////////////
20// ELF Header Constants 20// ELF Header Constants
@@ -375,7 +375,7 @@ FileType AppLoader_ELF::IdentifyType(FileUtil::IOFile& file) {
375 return FileType::Error; 375 return FileType::Error;
376} 376}
377 377
378ResultStatus AppLoader_ELF::Load() { 378ResultStatus AppLoader_ELF::Load(Kernel::SharedPtr<Kernel::Process>& process) {
379 if (is_loaded) 379 if (is_loaded)
380 return ResultStatus::ErrorAlreadyLoaded; 380 return ResultStatus::ErrorAlreadyLoaded;
381 381
@@ -394,16 +394,15 @@ ResultStatus AppLoader_ELF::Load() {
394 SharedPtr<CodeSet> codeset = elf_reader.LoadInto(Memory::PROCESS_IMAGE_VADDR); 394 SharedPtr<CodeSet> codeset = elf_reader.LoadInto(Memory::PROCESS_IMAGE_VADDR);
395 codeset->name = filename; 395 codeset->name = filename;
396 396
397 Kernel::g_current_process = Kernel::Process::Create(std::move(codeset)); 397 process = Kernel::Process::Create(std::move(codeset));
398 Kernel::g_current_process->svc_access_mask.set(); 398 process->svc_access_mask.set();
399 Kernel::g_current_process->address_mappings = default_address_mappings; 399 process->address_mappings = default_address_mappings;
400 Memory::SetCurrentPageTable(&Kernel::g_current_process->vm_manager.page_table);
401 400
402 // Attach the default resource limit (APPLICATION) to the process 401 // Attach the default resource limit (APPLICATION) to the process
403 Kernel::g_current_process->resource_limit = 402 process->resource_limit =
404 Kernel::ResourceLimit::GetForCategory(Kernel::ResourceLimitCategory::APPLICATION); 403 Kernel::ResourceLimit::GetForCategory(Kernel::ResourceLimitCategory::APPLICATION);
405 404
406 Kernel::g_current_process->Run(48, Kernel::DEFAULT_STACK_SIZE); 405 process->Run(48, Kernel::DEFAULT_STACK_SIZE);
407 406
408 is_loaded = true; 407 is_loaded = true;
409 return ResultStatus::Success; 408 return ResultStatus::Success;
diff --git a/src/core/loader/elf.h b/src/core/loader/elf.h
index 862aa90d8..113da5917 100644
--- a/src/core/loader/elf.h
+++ b/src/core/loader/elf.h
@@ -30,7 +30,7 @@ public:
30 return IdentifyType(file); 30 return IdentifyType(file);
31 } 31 }
32 32
33 ResultStatus Load() override; 33 ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override;
34 34
35private: 35private:
36 std::string filename; 36 std::string filename;
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h
index 3160fd2fd..82b2be6a3 100644
--- a/src/core/loader/loader.h
+++ b/src/core/loader/loader.h
@@ -13,10 +13,12 @@
13#include <boost/optional.hpp> 13#include <boost/optional.hpp>
14#include "common/common_types.h" 14#include "common/common_types.h"
15#include "common/file_util.h" 15#include "common/file_util.h"
16#include "core/hle/kernel/kernel.h"
16 17
17namespace Kernel { 18namespace Kernel {
18struct AddressMapping; 19struct AddressMapping;
19} 20class Process;
21} // namespace Kernel
20 22
21//////////////////////////////////////////////////////////////////////////////////////////////////// 23////////////////////////////////////////////////////////////////////////////////////////////////////
22// Loader namespace 24// Loader namespace
@@ -92,10 +94,11 @@ public:
92 virtual FileType GetFileType() = 0; 94 virtual FileType GetFileType() = 0;
93 95
94 /** 96 /**
95 * Load the application 97 * Load the application and return the created Process instance
96 * @return ResultStatus result of function 98 * @param process The newly created process.
99 * @return The status result of the operation.
97 */ 100 */
98 virtual ResultStatus Load() = 0; 101 virtual ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) = 0;
99 102
100 /** 103 /**
101 * Loads the system mode that this application needs. 104 * Loads the system mode that this application needs.
@@ -206,4 +209,4 @@ extern const std::initializer_list<Kernel::AddressMapping> default_address_mappi
206 */ 209 */
207std::unique_ptr<AppLoader> GetLoader(const std::string& filename); 210std::unique_ptr<AppLoader> GetLoader(const std::string& filename);
208 211
209} // namespace 212} // namespace Loader
diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp
index 5107135f9..66bc5823d 100644
--- a/src/core/loader/ncch.cpp
+++ b/src/core/loader/ncch.cpp
@@ -67,9 +67,9 @@ std::pair<boost::optional<u32>, ResultStatus> AppLoader_NCCH::LoadKernelSystemMo
67 ResultStatus::Success); 67 ResultStatus::Success);
68} 68}
69 69
70ResultStatus AppLoader_NCCH::LoadExec() { 70ResultStatus AppLoader_NCCH::LoadExec(Kernel::SharedPtr<Kernel::Process>& process) {
71 using Kernel::SharedPtr;
72 using Kernel::CodeSet; 71 using Kernel::CodeSet;
72 using Kernel::SharedPtr;
73 73
74 if (!is_loaded) 74 if (!is_loaded)
75 return ResultStatus::ErrorNotLoaded; 75 return ResultStatus::ErrorNotLoaded;
@@ -107,16 +107,15 @@ ResultStatus AppLoader_NCCH::LoadExec() {
107 codeset->entrypoint = codeset->code.addr; 107 codeset->entrypoint = codeset->code.addr;
108 codeset->memory = std::make_shared<std::vector<u8>>(std::move(code)); 108 codeset->memory = std::make_shared<std::vector<u8>>(std::move(code));
109 109
110 Kernel::g_current_process = Kernel::Process::Create(std::move(codeset)); 110 process = Kernel::Process::Create(std::move(codeset));
111 Memory::SetCurrentPageTable(&Kernel::g_current_process->vm_manager.page_table);
112 111
113 // Attach a resource limit to the process based on the resource limit category 112 // Attach a resource limit to the process based on the resource limit category
114 Kernel::g_current_process->resource_limit = 113 process->resource_limit =
115 Kernel::ResourceLimit::GetForCategory(static_cast<Kernel::ResourceLimitCategory>( 114 Kernel::ResourceLimit::GetForCategory(static_cast<Kernel::ResourceLimitCategory>(
116 overlay_ncch->exheader_header.arm11_system_local_caps.resource_limit_category)); 115 overlay_ncch->exheader_header.arm11_system_local_caps.resource_limit_category));
117 116
118 // Set the default CPU core for this process 117 // Set the default CPU core for this process
119 Kernel::g_current_process->ideal_processor = 118 process->ideal_processor =
120 overlay_ncch->exheader_header.arm11_system_local_caps.ideal_processor; 119 overlay_ncch->exheader_header.arm11_system_local_caps.ideal_processor;
121 120
122 // Copy data while converting endianness 121 // Copy data while converting endianness
@@ -124,11 +123,11 @@ ResultStatus AppLoader_NCCH::LoadExec() {
124 kernel_caps; 123 kernel_caps;
125 std::copy_n(overlay_ncch->exheader_header.arm11_kernel_caps.descriptors, kernel_caps.size(), 124 std::copy_n(overlay_ncch->exheader_header.arm11_kernel_caps.descriptors, kernel_caps.size(),
126 begin(kernel_caps)); 125 begin(kernel_caps));
127 Kernel::g_current_process->ParseKernelCaps(kernel_caps.data(), kernel_caps.size()); 126 process->ParseKernelCaps(kernel_caps.data(), kernel_caps.size());
128 127
129 s32 priority = overlay_ncch->exheader_header.arm11_system_local_caps.priority; 128 s32 priority = overlay_ncch->exheader_header.arm11_system_local_caps.priority;
130 u32 stack_size = overlay_ncch->exheader_header.codeset_info.stack_size; 129 u32 stack_size = overlay_ncch->exheader_header.codeset_info.stack_size;
131 Kernel::g_current_process->Run(priority, stack_size); 130 process->Run(priority, stack_size);
132 return ResultStatus::Success; 131 return ResultStatus::Success;
133 } 132 }
134 return ResultStatus::Error; 133 return ResultStatus::Error;
@@ -151,7 +150,7 @@ void AppLoader_NCCH::ParseRegionLockoutInfo() {
151 } 150 }
152} 151}
153 152
154ResultStatus AppLoader_NCCH::Load() { 153ResultStatus AppLoader_NCCH::Load(Kernel::SharedPtr<Kernel::Process>& process) {
155 u64_le ncch_program_id; 154 u64_le ncch_program_id;
156 155
157 if (is_loaded) 156 if (is_loaded)
@@ -183,7 +182,7 @@ ResultStatus AppLoader_NCCH::Load() {
183 182
184 is_loaded = true; // Set state to loaded 183 is_loaded = true; // Set state to loaded
185 184
186 result = LoadExec(); // Load the executable into memory for booting 185 result = LoadExec(process); // Load the executable into memory for booting
187 if (ResultStatus::Success != result) 186 if (ResultStatus::Success != result)
188 return result; 187 return result;
189 188
diff --git a/src/core/loader/ncch.h b/src/core/loader/ncch.h
index 9b56465cb..09230ae33 100644
--- a/src/core/loader/ncch.h
+++ b/src/core/loader/ncch.h
@@ -33,7 +33,7 @@ public:
33 return IdentifyType(file); 33 return IdentifyType(file);
34 } 34 }
35 35
36 ResultStatus Load() override; 36 ResultStatus Load(Kernel::SharedPtr<Kernel::Process>& process) override;
37 37
38 /** 38 /**
39 * Loads the Exheader and returns the system mode for this application. 39 * Loads the Exheader and returns the system mode for this application.
@@ -62,9 +62,10 @@ public:
62private: 62private:
63 /** 63 /**
64 * Loads .code section into memory for booting 64 * Loads .code section into memory for booting
65 * @param process The newly created process
65 * @return ResultStatus result of function 66 * @return ResultStatus result of function
66 */ 67 */
67 ResultStatus LoadExec(); 68 ResultStatus LoadExec(Kernel::SharedPtr<Kernel::Process>& process);
68 69
69 /// Reads the region lockout info in the SMDH and send it to CFG service 70 /// Reads the region lockout info in the SMDH and send it to CFG service
70 void ParseRegionLockoutInfo(); 71 void ParseRegionLockoutInfo();