diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/citra/citra.cpp | 13 | ||||
| -rw-r--r-- | src/citra_qt/main.cpp | 23 | ||||
| -rw-r--r-- | src/citra_qt/main.h | 7 | ||||
| -rw-r--r-- | src/core/hle/kernel/kernel.cpp | 6 | ||||
| -rw-r--r-- | src/core/hle/kernel/kernel.h | 4 | ||||
| -rw-r--r-- | src/core/loader/loader.h | 12 | ||||
| -rw-r--r-- | src/core/loader/ncch.cpp | 10 | ||||
| -rw-r--r-- | src/core/loader/ncch.h | 6 | ||||
| -rw-r--r-- | src/core/system.cpp | 4 | ||||
| -rw-r--r-- | src/core/system.h | 2 |
10 files changed, 66 insertions, 21 deletions
diff --git a/src/citra/citra.cpp b/src/citra/citra.cpp index e47375f88..f9387e61c 100644 --- a/src/citra/citra.cpp +++ b/src/citra/citra.cpp | |||
| @@ -129,15 +129,22 @@ int main(int argc, char** argv) { | |||
| 129 | 129 | ||
| 130 | std::unique_ptr<EmuWindow_SDL2> emu_window = std::make_unique<EmuWindow_SDL2>(); | 130 | std::unique_ptr<EmuWindow_SDL2> emu_window = std::make_unique<EmuWindow_SDL2>(); |
| 131 | 131 | ||
| 132 | System::Init(emu_window.get()); | ||
| 133 | SCOPE_EXIT({ System::Shutdown(); }); | ||
| 134 | |||
| 135 | std::unique_ptr<Loader::AppLoader> loader = Loader::GetLoader(boot_filename); | 132 | std::unique_ptr<Loader::AppLoader> loader = Loader::GetLoader(boot_filename); |
| 136 | if (!loader) { | 133 | if (!loader) { |
| 137 | LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", boot_filename.c_str()); | 134 | LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", boot_filename.c_str()); |
| 138 | return -1; | 135 | return -1; |
| 139 | } | 136 | } |
| 140 | 137 | ||
| 138 | boost::optional<u32> system_mode = loader->LoadKernelSystemMode(); | ||
| 139 | |||
| 140 | if (!system_mode) { | ||
| 141 | LOG_CRITICAL(Frontend, "Failed to load ROM (Could not determine system mode)!"); | ||
| 142 | return -1; | ||
| 143 | } | ||
| 144 | |||
| 145 | System::Init(emu_window.get(), system_mode.get()); | ||
| 146 | SCOPE_EXIT({ System::Shutdown(); }); | ||
| 147 | |||
| 141 | Loader::ResultStatus load_result = loader->Load(); | 148 | Loader::ResultStatus load_result = loader->Load(); |
| 142 | if (Loader::ResultStatus::Success != load_result) { | 149 | if (Loader::ResultStatus::Success != load_result) { |
| 143 | LOG_CRITICAL(Frontend, "Failed to load ROM (Error %i)!", load_result); | 150 | LOG_CRITICAL(Frontend, "Failed to load ROM (Error %i)!", load_result); |
diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 0bf9f48d6..a3887f9ab 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp | |||
| @@ -253,7 +253,7 @@ void GMainWindow::OnDisplayTitleBars(bool show) { | |||
| 253 | } | 253 | } |
| 254 | } | 254 | } |
| 255 | 255 | ||
| 256 | bool GMainWindow::InitializeSystem() { | 256 | bool GMainWindow::InitializeSystem(u32 system_mode) { |
| 257 | // Shutdown previous session if the emu thread is still active... | 257 | // Shutdown previous session if the emu thread is still active... |
| 258 | if (emu_thread != nullptr) | 258 | if (emu_thread != nullptr) |
| 259 | ShutdownGame(); | 259 | ShutdownGame(); |
| @@ -270,7 +270,7 @@ bool GMainWindow::InitializeSystem() { | |||
| 270 | } | 270 | } |
| 271 | 271 | ||
| 272 | // Initialize the core emulation | 272 | // Initialize the core emulation |
| 273 | System::Result system_result = System::Init(render_window); | 273 | System::Result system_result = System::Init(render_window, system_mode); |
| 274 | if (System::Result::Success != system_result) { | 274 | if (System::Result::Success != system_result) { |
| 275 | switch (system_result) { | 275 | switch (system_result) { |
| 276 | case System::Result::ErrorInitVideoCore: | 276 | case System::Result::ErrorInitVideoCore: |
| @@ -299,8 +299,20 @@ bool GMainWindow::LoadROM(const std::string& filename) { | |||
| 299 | return false; | 299 | return false; |
| 300 | } | 300 | } |
| 301 | 301 | ||
| 302 | boost::optional<u32> system_mode = app_loader->LoadKernelSystemMode(); | ||
| 303 | if (!system_mode) { | ||
| 304 | LOG_CRITICAL(Frontend, "Failed to load ROM!"); | ||
| 305 | QMessageBox::critical(this, tr("Error while loading ROM!"), | ||
| 306 | tr("Could not determine the system mode.")); | ||
| 307 | return false; | ||
| 308 | } | ||
| 309 | |||
| 310 | if (!InitializeSystem(system_mode.get())) | ||
| 311 | return false; | ||
| 312 | |||
| 302 | Loader::ResultStatus result = app_loader->Load(); | 313 | Loader::ResultStatus result = app_loader->Load(); |
| 303 | if (Loader::ResultStatus::Success != result) { | 314 | if (Loader::ResultStatus::Success != result) { |
| 315 | System::Shutdown(); | ||
| 304 | LOG_CRITICAL(Frontend, "Failed to load ROM!"); | 316 | LOG_CRITICAL(Frontend, "Failed to load ROM!"); |
| 305 | 317 | ||
| 306 | switch (result) { | 318 | switch (result) { |
| @@ -338,13 +350,8 @@ void GMainWindow::BootGame(const std::string& filename) { | |||
| 338 | LOG_INFO(Frontend, "Citra starting..."); | 350 | LOG_INFO(Frontend, "Citra starting..."); |
| 339 | StoreRecentFile(filename); // Put the filename on top of the list | 351 | StoreRecentFile(filename); // Put the filename on top of the list |
| 340 | 352 | ||
| 341 | if (!InitializeSystem()) | 353 | if (!LoadROM(filename)) |
| 342 | return; | ||
| 343 | |||
| 344 | if (!LoadROM(filename)) { | ||
| 345 | System::Shutdown(); | ||
| 346 | return; | 354 | return; |
| 347 | } | ||
| 348 | 355 | ||
| 349 | // Create and start the emulation thread | 356 | // Create and start the emulation thread |
| 350 | emu_thread = std::make_unique<EmuThread>(render_window); | 357 | emu_thread = std::make_unique<EmuThread>(render_window); |
diff --git a/src/citra_qt/main.h b/src/citra_qt/main.h index 82eb90aae..f87178227 100644 --- a/src/citra_qt/main.h +++ b/src/citra_qt/main.h | |||
| @@ -60,7 +60,12 @@ signals: | |||
| 60 | void EmulationStopping(); | 60 | void EmulationStopping(); |
| 61 | 61 | ||
| 62 | private: | 62 | private: |
| 63 | bool InitializeSystem(); | 63 | /** |
| 64 | * Initializes the emulation system. | ||
| 65 | * @param system_mode The system mode with which to intialize the kernel. | ||
| 66 | * @returns Whether the system was properly initialized. | ||
| 67 | */ | ||
| 68 | bool InitializeSystem(u32 system_mode); | ||
| 64 | bool LoadROM(const std::string& filename); | 69 | bool LoadROM(const std::string& filename); |
| 65 | void BootGame(const std::string& filename); | 70 | void BootGame(const std::string& filename); |
| 66 | void ShutdownGame(); | 71 | void ShutdownGame(); |
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 9e1795927..0c8752670 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -124,13 +124,11 @@ void HandleTable::Clear() { | |||
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | /// Initialize the kernel | 126 | /// Initialize the kernel |
| 127 | void Init() { | 127 | void Init(u32 system_mode) { |
| 128 | ConfigMem::Init(); | 128 | ConfigMem::Init(); |
| 129 | SharedPage::Init(); | 129 | SharedPage::Init(); |
| 130 | 130 | ||
| 131 | // TODO(yuriks): The memory type parameter needs to be determined by the ExHeader field instead | 131 | Kernel::MemoryInit(system_mode); |
| 132 | // For now it defaults to the one with a largest allocation to the app | ||
| 133 | Kernel::MemoryInit(2); // Allocates 96MB to the application | ||
| 134 | 132 | ||
| 135 | Kernel::ResourceLimitsInit(); | 133 | Kernel::ResourceLimitsInit(); |
| 136 | Kernel::ThreadingInit(); | 134 | Kernel::ThreadingInit(); |
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 6b8dbecff..231cf7b75 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h | |||
| @@ -286,8 +286,8 @@ private: | |||
| 286 | 286 | ||
| 287 | extern HandleTable g_handle_table; | 287 | extern HandleTable g_handle_table; |
| 288 | 288 | ||
| 289 | /// Initialize the kernel | 289 | /// Initialize the kernel with the specified system mode. |
| 290 | void Init(); | 290 | void Init(u32 system_mode); |
| 291 | 291 | ||
| 292 | /// Shutdown the kernel | 292 | /// Shutdown the kernel |
| 293 | void Shutdown(); | 293 | void Shutdown(); |
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 9652d7ac5..5e3d46638 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h | |||
| @@ -9,6 +9,7 @@ | |||
| 9 | #include <memory> | 9 | #include <memory> |
| 10 | #include <string> | 10 | #include <string> |
| 11 | #include <vector> | 11 | #include <vector> |
| 12 | #include <boost/optional.hpp> | ||
| 12 | #include "common/common_types.h" | 13 | #include "common/common_types.h" |
| 13 | #include "common/file_util.h" | 14 | #include "common/file_util.h" |
| 14 | 15 | ||
| @@ -96,6 +97,17 @@ public: | |||
| 96 | virtual ResultStatus Load() = 0; | 97 | virtual ResultStatus Load() = 0; |
| 97 | 98 | ||
| 98 | /** | 99 | /** |
| 100 | * Loads the system mode that this application needs. | ||
| 101 | * This function defaults to 2 (96MB allocated to the application) if it can't read the | ||
| 102 | * information. | ||
| 103 | * @returns Optional with the kernel system mode | ||
| 104 | */ | ||
| 105 | virtual boost::optional<u32> LoadKernelSystemMode() { | ||
| 106 | // 96MB allocated to the application. | ||
| 107 | return 2; | ||
| 108 | } | ||
| 109 | |||
| 110 | /** | ||
| 99 | * Get the code (typically .code section) of the application | 111 | * Get the code (typically .code section) of the application |
| 100 | * @param buffer Reference to buffer to store data | 112 | * @param buffer Reference to buffer to store data |
| 101 | * @return ResultStatus result of function | 113 | * @return ResultStatus result of function |
diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp index fadd7b16b..d4be61e0e 100644 --- a/src/core/loader/ncch.cpp +++ b/src/core/loader/ncch.cpp | |||
| @@ -117,6 +117,14 @@ FileType AppLoader_NCCH::IdentifyType(FileUtil::IOFile& file) { | |||
| 117 | return FileType::Error; | 117 | return FileType::Error; |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | boost::optional<u32> AppLoader_NCCH::LoadKernelSystemMode() { | ||
| 121 | if (!is_loaded) { | ||
| 122 | if (LoadExeFS() != ResultStatus::Success) | ||
| 123 | return boost::none; | ||
| 124 | } | ||
| 125 | return exheader_header.arm11_system_local_caps.system_mode.Value(); | ||
| 126 | } | ||
| 127 | |||
| 120 | ResultStatus AppLoader_NCCH::LoadExec() { | 128 | ResultStatus AppLoader_NCCH::LoadExec() { |
| 121 | using Kernel::SharedPtr; | 129 | using Kernel::SharedPtr; |
| 122 | using Kernel::CodeSet; | 130 | using Kernel::CodeSet; |
| @@ -277,6 +285,8 @@ ResultStatus AppLoader_NCCH::LoadExeFS() { | |||
| 277 | LOG_DEBUG(Loader, "Core version: %d", core_version); | 285 | LOG_DEBUG(Loader, "Core version: %d", core_version); |
| 278 | LOG_DEBUG(Loader, "Thread priority: 0x%X", priority); | 286 | LOG_DEBUG(Loader, "Thread priority: 0x%X", priority); |
| 279 | LOG_DEBUG(Loader, "Resource limit category: %d", resource_limit_category); | 287 | LOG_DEBUG(Loader, "Resource limit category: %d", resource_limit_category); |
| 288 | LOG_DEBUG(Loader, "System Mode: %d", | ||
| 289 | exheader_header.arm11_system_local_caps.system_mode); | ||
| 280 | 290 | ||
| 281 | if (exheader_header.arm11_system_local_caps.program_id != ncch_header.program_id) { | 291 | if (exheader_header.arm11_system_local_caps.program_id != ncch_header.program_id) { |
| 282 | LOG_ERROR(Loader, "ExHeader Program ID mismatch: the ROM is probably encrypted."); | 292 | LOG_ERROR(Loader, "ExHeader Program ID mismatch: the ROM is probably encrypted."); |
diff --git a/src/core/loader/ncch.h b/src/core/loader/ncch.h index f8718d063..bcf3ae6e3 100644 --- a/src/core/loader/ncch.h +++ b/src/core/loader/ncch.h | |||
| @@ -186,6 +186,12 @@ public: | |||
| 186 | ResultStatus Load() override; | 186 | ResultStatus Load() override; |
| 187 | 187 | ||
| 188 | /** | 188 | /** |
| 189 | * Loads the Exheader and returns the system mode for this application. | ||
| 190 | * @return Optional with the kernel system mode | ||
| 191 | */ | ||
| 192 | boost::optional<u32> LoadKernelSystemMode(); | ||
| 193 | |||
| 194 | /** | ||
| 189 | * Get the code (typically .code section) of the application | 195 | * Get the code (typically .code section) of the application |
| 190 | * @param buffer Reference to buffer to store data | 196 | * @param buffer Reference to buffer to store data |
| 191 | * @return ResultStatus result of function | 197 | * @return ResultStatus result of function |
diff --git a/src/core/system.cpp b/src/core/system.cpp index 7d54811a0..a5f763805 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp | |||
| @@ -17,12 +17,12 @@ namespace System { | |||
| 17 | 17 | ||
| 18 | static bool is_powered_on{false}; | 18 | static bool is_powered_on{false}; |
| 19 | 19 | ||
| 20 | Result Init(EmuWindow* emu_window) { | 20 | Result Init(EmuWindow* emu_window, u32 system_mode) { |
| 21 | Core::Init(); | 21 | Core::Init(); |
| 22 | CoreTiming::Init(); | 22 | CoreTiming::Init(); |
| 23 | Memory::Init(); | 23 | Memory::Init(); |
| 24 | HW::Init(); | 24 | HW::Init(); |
| 25 | Kernel::Init(); | 25 | Kernel::Init(system_mode); |
| 26 | HLE::Init(); | 26 | HLE::Init(); |
| 27 | if (!VideoCore::Init(emu_window)) { | 27 | if (!VideoCore::Init(emu_window)) { |
| 28 | return Result::ErrorInitVideoCore; | 28 | return Result::ErrorInitVideoCore; |
diff --git a/src/core/system.h b/src/core/system.h index 6d672b1b5..b41fc088a 100644 --- a/src/core/system.h +++ b/src/core/system.h | |||
| @@ -15,7 +15,7 @@ enum class Result { | |||
| 15 | ErrorInitVideoCore, ///< Something went wrong during video core init | 15 | ErrorInitVideoCore, ///< Something went wrong during video core init |
| 16 | }; | 16 | }; |
| 17 | 17 | ||
| 18 | Result Init(EmuWindow* emu_window); | 18 | Result Init(EmuWindow* emu_window, u32 system_mode); |
| 19 | bool IsPoweredOn(); | 19 | bool IsPoweredOn(); |
| 20 | void Shutdown(); | 20 | void Shutdown(); |
| 21 | } | 21 | } |