From 81e22ae8c75d7e1fb674258833a473d448b856b5 Mon Sep 17 00:00:00 2001 From: bunnei Date: Tue, 11 Oct 2016 17:26:25 -0400 Subject: [PATCH 1/8] loader: Remove duplicate docstrings. --- src/core/loader/3dsx.h | 20 -------------------- src/core/loader/elf.h | 8 -------- src/core/loader/ncch.h | 28 ---------------------------- 3 files changed, 56 deletions(-) diff --git a/src/core/loader/3dsx.h b/src/core/loader/3dsx.h index cfcc21cc43..3f376778a3 100644 --- a/src/core/loader/3dsx.h +++ b/src/core/loader/3dsx.h @@ -27,34 +27,14 @@ public: */ static FileType IdentifyType(FileUtil::IOFile& file); - /** - * Returns the type of this file - * @return FileType corresponding to the loaded file - */ FileType GetFileType() override { return IdentifyType(file); } - /** - * Load the bootable file - * @return ResultStatus result of function - */ ResultStatus Load() override; - /** - * Get the icon (typically icon section) of the application - * @param buffer Reference to buffer to store data - * @return ResultStatus result of function - */ ResultStatus ReadIcon(std::vector& buffer) override; - /** - * Get the RomFS of the application - * @param romfs_file Reference to buffer to store data - * @param offset Offset in the file to the RomFS - * @param size Size of the RomFS in bytes - * @return ResultStatus result of function - */ ResultStatus ReadRomFS(std::shared_ptr& romfs_file, u64& offset, u64& size) override; diff --git a/src/core/loader/elf.h b/src/core/loader/elf.h index 584bf6e27d..862aa90d87 100644 --- a/src/core/loader/elf.h +++ b/src/core/loader/elf.h @@ -26,18 +26,10 @@ public: */ static FileType IdentifyType(FileUtil::IOFile& file); - /** - * Returns the type of this file - * @return FileType corresponding to the loaded file - */ FileType GetFileType() override { return IdentifyType(file); } - /** - * Load the bootable file - * @return ResultStatus result of function - */ ResultStatus Load() override; private: diff --git a/src/core/loader/ncch.h b/src/core/loader/ncch.h index 6c93d46d8f..6afc171a50 100644 --- a/src/core/loader/ncch.h +++ b/src/core/loader/ncch.h @@ -171,18 +171,10 @@ public: */ static FileType IdentifyType(FileUtil::IOFile& file); - /** - * Returns the type of this file - * @return FileType corresponding to the loaded file - */ FileType GetFileType() override { return IdentifyType(file); } - /** - * Load the application - * @return ResultStatus result of function - */ ResultStatus Load() override; /** @@ -191,32 +183,12 @@ public: */ boost::optional LoadKernelSystemMode(); - /** - * Get the code (typically .code section) of the application - * @param buffer Reference to buffer to store data - * @return ResultStatus result of function - */ ResultStatus ReadCode(std::vector& buffer) override; - /** - * Get the icon (typically icon section) of the application - * @param buffer Reference to buffer to store data - * @return ResultStatus result of function - */ ResultStatus ReadIcon(std::vector& buffer) override; - /** - * Get the banner (typically banner section) of the application - * @param buffer Reference to buffer to store data - * @return ResultStatus result of function - */ ResultStatus ReadBanner(std::vector& buffer) override; - /** - * Get the logo (typically logo section) of the application - * @param buffer Reference to buffer to store data - * @return ResultStatus result of function - */ ResultStatus ReadLogo(std::vector& buffer) override; /** From 198b6c9bdd58d76303f75a8577303907967a143e Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 4 Nov 2016 23:14:38 -0400 Subject: [PATCH 2/8] core: Consolidate top-level system state into a singleton. --- src/citra/citra.cpp | 39 ++++++-------- src/citra_qt/bootmanager.cpp | 2 +- src/citra_qt/configure_general.cpp | 2 +- src/citra_qt/configure_graphics.cpp | 2 +- src/citra_qt/configure_system.cpp | 2 +- src/citra_qt/main.cpp | 83 ++++++++++------------------- src/core/system.cpp | 61 ++++++++++++++++----- src/core/system.h | 82 ++++++++++++++++++++++++---- 8 files changed, 167 insertions(+), 106 deletions(-) diff --git a/src/citra/citra.cpp b/src/citra/citra.cpp index 3114a71db3..5e2829b54b 100644 --- a/src/citra/citra.cpp +++ b/src/citra/citra.cpp @@ -64,7 +64,7 @@ int main(int argc, char** argv) { return -1; } #endif - std::string boot_filename; + std::string filepath; static struct option long_options[] = { {"gdbport", required_argument, 0, 'g'}, @@ -97,9 +97,9 @@ int main(int argc, char** argv) { } } else { #ifdef _WIN32 - boot_filename = Common::UTF16ToUTF8(argv_w[optind]); + filepath = Common::UTF16ToUTF8(argv_w[optind]); #else - boot_filename = argv[optind]; + filepath = argv[optind]; #endif optind++; } @@ -115,7 +115,7 @@ int main(int argc, char** argv) { MicroProfileOnThreadCreate("EmuThread"); SCOPE_EXIT({ MicroProfileShutdown(); }); - if (boot_filename.empty()) { + if (filepath.empty()) { LOG_CRITICAL(Frontend, "Failed to load ROM: No ROM specified"); return -1; } @@ -127,27 +127,20 @@ int main(int argc, char** argv) { Settings::values.use_gdbstub = use_gdbstub; Settings::Apply(); - std::unique_ptr emu_window = std::make_unique(); + std::unique_ptr emu_window{ std::make_unique() }; - std::unique_ptr loader = Loader::GetLoader(boot_filename); - if (!loader) { - LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", boot_filename.c_str()); + Core::System& system{ Core::System::GetInstance() }; + + SCOPE_EXIT({ system.Shutdown(); }); + + const Core::System::ResultStatus load_result{ system.Load(emu_window.get(), filepath) }; + + switch (load_result) { + case Core::System::ResultStatus::ErrorGetLoader: + LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", filepath.c_str()); return -1; - } - - boost::optional system_mode = loader->LoadKernelSystemMode(); - - if (!system_mode) { - LOG_CRITICAL(Frontend, "Failed to load ROM (Could not determine system mode)!"); - return -1; - } - - System::Init(emu_window.get(), system_mode.get()); - SCOPE_EXIT({ System::Shutdown(); }); - - Loader::ResultStatus load_result = loader->Load(); - if (Loader::ResultStatus::Success != load_result) { - LOG_CRITICAL(Frontend, "Failed to load ROM (Error %i)!", load_result); + case Core::System::ResultStatus::ErrorLoader: + LOG_CRITICAL(Frontend, "Failed to load ROM!"); return -1; } diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index c7eb2aafc8..5e8ae30665 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp @@ -60,7 +60,7 @@ void EmuThread::run() { } // Shutdown the core emulation - System::Shutdown(); + Core::System::GetInstance().Shutdown(); #if MICROPROFILE_ENABLED MicroProfileOnThreadExit(); diff --git a/src/citra_qt/configure_general.cpp b/src/citra_qt/configure_general.cpp index 27139fb303..f576f6f7a9 100644 --- a/src/citra_qt/configure_general.cpp +++ b/src/citra_qt/configure_general.cpp @@ -14,7 +14,7 @@ ConfigureGeneral::ConfigureGeneral(QWidget* parent) ui->setupUi(this); this->setConfiguration(); - ui->toggle_cpu_jit->setEnabled(!System::IsPoweredOn()); + ui->toggle_cpu_jit->setEnabled(!Core::System::GetInstance().IsPoweredOn()); } ConfigureGeneral::~ConfigureGeneral() {} diff --git a/src/citra_qt/configure_graphics.cpp b/src/citra_qt/configure_graphics.cpp index 36f10c8d76..1e6f7f880a 100644 --- a/src/citra_qt/configure_graphics.cpp +++ b/src/citra_qt/configure_graphics.cpp @@ -13,7 +13,7 @@ ConfigureGraphics::ConfigureGraphics(QWidget* parent) ui->setupUi(this); this->setConfiguration(); - ui->toggle_vsync->setEnabled(!System::IsPoweredOn()); + ui->toggle_vsync->setEnabled(!Core::System::GetInstance().IsPoweredOn()); } ConfigureGraphics::~ConfigureGraphics() {} diff --git a/src/citra_qt/configure_system.cpp b/src/citra_qt/configure_system.cpp index 873d314ec1..545261c015 100644 --- a/src/citra_qt/configure_system.cpp +++ b/src/citra_qt/configure_system.cpp @@ -24,7 +24,7 @@ ConfigureSystem::ConfigureSystem(QWidget* parent) : QWidget(parent), ui(new Ui:: ConfigureSystem::~ConfigureSystem() {} void ConfigureSystem::setConfiguration() { - enabled = !System::IsPoweredOn(); + enabled = !Core::System::GetInstance().IsPoweredOn(); if (!enabled) { ReadSystemSettings(); diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index e16d3196c8..0c7723b0af 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -274,7 +274,7 @@ void GMainWindow::OnDisplayTitleBars(bool show) { } } -bool GMainWindow::InitializeSystem(u32 system_mode) { +bool GMainWindow::LoadROM(const std::string& filename) { // Shutdown previous session if the emu thread is still active... if (emu_thread != nullptr) ShutdownGame(); @@ -284,79 +284,50 @@ bool GMainWindow::InitializeSystem(u32 system_mode) { if (!gladLoadGL()) { QMessageBox::critical(this, tr("Error while starting Citra!"), - tr("Failed to initialize the video core!\n\n" - "Please ensure that your GPU supports OpenGL 3.3 and that you " - "have the latest graphics driver.")); + tr("Failed to initialize the video core!\n\n" + "Please ensure that your GPU supports OpenGL 3.3 and that you " + "have the latest graphics driver.")); return false; } - // Initialize the core emulation - System::Result system_result = System::Init(render_window, system_mode); - if (System::Result::Success != system_result) { - switch (system_result) { - case System::Result::ErrorInitVideoCore: - QMessageBox::critical(this, tr("Error while starting Citra!"), - tr("Failed to initialize the video core!\n\n" - "Please ensure that your GPU supports OpenGL 3.3 and that you " - "have the latest graphics driver.")); - break; + Core::System& system{ Core::System::GetInstance() }; - default: - QMessageBox::critical(this, tr("Error while starting Citra!"), - tr("Unknown error (please check the log)!")); - break; - } - return false; - } - return true; -} - -bool GMainWindow::LoadROM(const std::string& filename) { - std::unique_ptr app_loader = Loader::GetLoader(filename); - if (!app_loader) { - LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", filename.c_str()); - QMessageBox::critical(this, tr("Error while loading ROM!"), - tr("The ROM format is not supported.")); - return false; - } - - boost::optional system_mode = app_loader->LoadKernelSystemMode(); - if (!system_mode) { - LOG_CRITICAL(Frontend, "Failed to load ROM!"); - QMessageBox::critical(this, tr("Error while loading ROM!"), - tr("Could not determine the system mode.")); - return false; - } - - if (!InitializeSystem(system_mode.get())) - return false; - - Loader::ResultStatus result = app_loader->Load(); - if (Loader::ResultStatus::Success != result) { - System::Shutdown(); - LOG_CRITICAL(Frontend, "Failed to load ROM!"); + const Core::System::ResultStatus result{ system.Load(render_window, filename) }; + if (result != Core::System::ResultStatus::Success) { switch (result) { - case Loader::ResultStatus::ErrorEncrypted: { + case Core::System::ResultStatus::ErrorGetLoader: + LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", filename.c_str()); + QMessageBox::critical(this, tr("Error while loading ROM!"), + tr("The ROM format is not supported.")); + break; + + case Core::System::ResultStatus::ErrorSystemMode: + LOG_CRITICAL(Frontend, "Failed to load ROM!"); + QMessageBox::critical(this, tr("Error while loading ROM!"), + tr("Could not determine the system mode.")); + break; + + case Core::System::ResultStatus::ErrorLoader_ErrorEncrypted: + { // Build the MessageBox ourselves to have clickable link QMessageBox popup_error; popup_error.setTextFormat(Qt::RichText); popup_error.setWindowTitle(tr("Error while loading ROM!")); popup_error.setText( tr("The game that you are trying to load must be decrypted before being used with " - "Citra.

" - "For more information on dumping and decrypting games, please see: https://" - "citra-emu.org/wiki/Dumping-Game-Cartridges")); + "Citra.

" + "For more information on dumping and decrypting games, please see: https://" + "citra-emu.org/wiki/Dumping-Game-Cartridges")); popup_error.setIcon(QMessageBox::Critical); popup_error.exec(); break; } - case Loader::ResultStatus::ErrorInvalidFormat: + case Core::System::ResultStatus::ErrorLoader_ErrorInvalidFormat: QMessageBox::critical(this, tr("Error while loading ROM!"), - tr("The ROM format is not supported.")); + tr("The ROM format is not supported.")); break; - case Loader::ResultStatus::Error: default: QMessageBox::critical(this, tr("Error while loading ROM!"), tr("Unknown error!")); diff --git a/src/core/system.cpp b/src/core/system.cpp index a5f763805b..fa8bd0317a 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -13,33 +13,30 @@ #include "core/system.h" #include "video_core/video_core.h" -namespace System { +namespace Core { -static bool is_powered_on{false}; +/*static*/ System System::s_instance; -Result Init(EmuWindow* emu_window, u32 system_mode) { +System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) { Core::Init(); CoreTiming::Init(); Memory::Init(); HW::Init(); Kernel::Init(system_mode); HLE::Init(); - if (!VideoCore::Init(emu_window)) { - return Result::ErrorInitVideoCore; - } AudioCore::Init(); GDBStub::Init(); + if (!VideoCore::Init(emu_window)) { + return ResultStatus::ErrorVideoCore; + } + is_powered_on = true; - return Result::Success; + return ResultStatus::Success; } -bool IsPoweredOn() { - return is_powered_on; -} - -void Shutdown() { +void System::Shutdown() { GDBStub::Shutdown(); AudioCore::Shutdown(); VideoCore::Shutdown(); @@ -52,4 +49,42 @@ void Shutdown() { is_powered_on = false; } -} // namespace +System::ResultStatus System::Load(EmuWindow* emu_window, const std::string& filepath) { + state.app_loader = Loader::GetLoader(filepath); + + if (!state.app_loader) { + LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", filepath.c_str()); + return ResultStatus::ErrorGetLoader; + } + + boost::optional system_mode{ state.app_loader->LoadKernelSystemMode() }; + if (!system_mode) { + LOG_CRITICAL(Frontend, "Failed to determine system mode!"); + return ResultStatus::ErrorSystemMode; + } + + ResultStatus init_result{ Init(emu_window, system_mode.get()) }; + if (init_result != ResultStatus::Success) { + LOG_CRITICAL(Frontend, "Failed to initialize system (Error %i)!", init_result); + System::Shutdown(); + return init_result; + } + + const Loader::ResultStatus load_result{ state.app_loader->Load() }; + if (Loader::ResultStatus::Success != load_result) { + LOG_CRITICAL(Frontend, "Failed to load ROM (Error %i)!", load_result); + System::Shutdown(); + + switch (load_result) { + case Loader::ResultStatus::ErrorEncrypted: + return ResultStatus::ErrorLoader_ErrorEncrypted; + case Loader::ResultStatus::ErrorInvalidFormat: + return ResultStatus::ErrorLoader_ErrorInvalidFormat; + default: + return ResultStatus::ErrorLoader; + } + } + return ResultStatus::Success; +} + +} // namespace Core diff --git a/src/core/system.h b/src/core/system.h index b41fc088a8..192a9c4479 100644 --- a/src/core/system.h +++ b/src/core/system.h @@ -4,18 +4,80 @@ #pragma once +#include + +#include "core/loader/loader.h" + class EmuWindow; -namespace System { +namespace Core { -enum class Result { - Success, ///< Everything is fine - Error, ///< Something went wrong (no module specified) - ErrorInitCore, ///< Something went wrong during core init - ErrorInitVideoCore, ///< Something went wrong during video core init +class System { +public: + struct State { + std::unique_ptr app_loader; + }; + + /** + * Gets the instance of the System singleton class. + * @returns Reference to the instance of the System singleton class. + */ + static System& GetInstance() { + return s_instance; + } + + /// Enumeration representing the return values of the System Initialize and Load process. + enum class ResultStatus : u32 { + Success, ///< Succeeded + ErrorGetLoader, ///< Error finding the correct application loader + ErrorSystemMode, ///< Error determining the system mode + ErrorLoader, ///< Error loading the specified application + ErrorLoader_ErrorEncrypted, ///< Error loading the specified application due to encryption + ErrorLoader_ErrorInvalidFormat, ///< Error loading the specified application due to an invalid format + ErrorVideoCore, ///< Error in the video core + }; + + /** + * Initialize the emulated system. + * @param emu_window Pointer to the host-system window used for video output and keyboard input. + * @param system_mode The system mode. + * @returns ResultStatus code, indicating if the operation succeeded. + */ + ResultStatus Init(EmuWindow* emu_window, u32 system_mode); + + /// Shutdown the emulated system. + void Shutdown(); + + /** + * Load an executable application. + * @param emu_window Pointer to the host-system window used for video output and keyboard input. + * @param filepath String path to the executable application to load on the host file system. + * @returns ResultStatus code, indicating if the operation succeeded. + */ + ResultStatus Load(EmuWindow* emu_window, const std::string& filepath); + + /** + * Indicates if the emulated system is powered on (all subsystems initialized and able to run an + * application). + * @returns True if the emulated system is powered on, otherwise false. + */ + bool IsPoweredOn() const { + return is_powered_on; + } + + /** + * Gets the internal state of the emulated system. + * @returns The internal state of the emulated system + */ + State& GetState() { + return state; + } + +private: + bool is_powered_on{}; + State state; + + static System s_instance; }; -Result Init(EmuWindow* emu_window, u32 system_mode); -bool IsPoweredOn(); -void Shutdown(); -} +} // namespace Core From 707cc66362e613925bbdd0c2abed7959a42decad Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 5 Nov 2016 00:23:32 -0400 Subject: [PATCH 3/8] file_util: Remove unused paths. --- src/common/common_paths.h | 18 -------------- src/common/file_util.cpp | 52 +++------------------------------------ src/common/file_util.h | 20 --------------- 3 files changed, 3 insertions(+), 87 deletions(-) diff --git a/src/common/common_paths.h b/src/common/common_paths.h index 37304d2363..b56105306e 100644 --- a/src/common/common_paths.h +++ b/src/common/common_paths.h @@ -32,22 +32,10 @@ // Subdirs in the User dir returned by GetUserPath(D_USER_IDX) #define CONFIG_DIR "config" -#define GAMECONFIG_DIR "game_config" -#define MAPS_DIR "maps" #define CACHE_DIR "cache" #define SDMC_DIR "sdmc" #define NAND_DIR "nand" #define SYSDATA_DIR "sysdata" -#define SHADERCACHE_DIR "shader_cache" -#define STATESAVES_DIR "state_saves" -#define SCREENSHOTS_DIR "screenShots" -#define DUMP_DIR "dump" -#define DUMP_TEXTURES_DIR "textures" -#define DUMP_FRAMES_DIR "frames" -#define DUMP_AUDIO_DIR "audio" -#define LOGS_DIR "logs" -#define SHADERS_DIR "shaders" -#define SYSCONF_DIR "sysconf" // Filenames // Files in the directory returned by GetUserPath(D_CONFIG_IDX) @@ -57,9 +45,3 @@ // Sys files #define SHARED_FONT "shared_font.bin" - -// Files in the directory returned by GetUserPath(D_LOGS_IDX) -#define MAIN_LOG "emu.log" - -// Files in the directory returned by GetUserPath(D_SYSCONF_IDX) -#define SYSCONF "SYSCONF" diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index c618495f72..5ab938a24b 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -697,6 +697,9 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string& new paths[D_CONFIG_IDX] = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP; paths[D_CACHE_IDX] = paths[D_USER_IDX] + CACHE_DIR DIR_SEP; + paths[D_SDMC_IDX] = paths[D_USER_IDX] + SDMC_DIR DIR_SEP; + paths[D_NAND_IDX] = paths[D_USER_IDX] + NAND_DIR DIR_SEP; + paths[D_SYSDATA_IDX] = paths[D_USER_IDX] + SYSDATA_DIR DIR_SEP; #else if (FileUtil::Exists(ROOT_DIR DIR_SEP USERDATA_DIR)) { paths[D_USER_IDX] = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP; @@ -712,24 +715,8 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string& new paths[D_CACHE_IDX] = cache_dir + DIR_SEP EMU_DATA_DIR DIR_SEP; } #endif - - paths[D_GAMECONFIG_IDX] = paths[D_USER_IDX] + GAMECONFIG_DIR DIR_SEP; - paths[D_MAPS_IDX] = paths[D_USER_IDX] + MAPS_DIR DIR_SEP; paths[D_SDMC_IDX] = paths[D_USER_IDX] + SDMC_DIR DIR_SEP; paths[D_NAND_IDX] = paths[D_USER_IDX] + NAND_DIR DIR_SEP; - paths[D_SYSDATA_IDX] = paths[D_USER_IDX] + SYSDATA_DIR DIR_SEP; - paths[D_SHADERCACHE_IDX] = paths[D_USER_IDX] + SHADERCACHE_DIR DIR_SEP; - paths[D_SHADERS_IDX] = paths[D_USER_IDX] + SHADERS_DIR DIR_SEP; - paths[D_STATESAVES_IDX] = paths[D_USER_IDX] + STATESAVES_DIR DIR_SEP; - paths[D_SCREENSHOTS_IDX] = paths[D_USER_IDX] + SCREENSHOTS_DIR DIR_SEP; - paths[D_DUMP_IDX] = paths[D_USER_IDX] + DUMP_DIR DIR_SEP; - paths[D_DUMPFRAMES_IDX] = paths[D_DUMP_IDX] + DUMP_FRAMES_DIR DIR_SEP; - paths[D_DUMPAUDIO_IDX] = paths[D_DUMP_IDX] + DUMP_AUDIO_DIR DIR_SEP; - paths[D_DUMPTEXTURES_IDX] = paths[D_DUMP_IDX] + DUMP_TEXTURES_DIR DIR_SEP; - paths[D_LOGS_IDX] = paths[D_USER_IDX] + LOGS_DIR DIR_SEP; - paths[F_DEBUGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + DEBUGGER_CONFIG; - paths[F_LOGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + LOGGER_CONFIG; - paths[F_MAINLOG_IDX] = paths[D_LOGS_IDX] + MAIN_LOG; } if (!newPath.empty()) { @@ -743,48 +730,15 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string& new switch (DirIDX) { case D_ROOT_IDX: paths[D_USER_IDX] = paths[D_ROOT_IDX] + DIR_SEP; - paths[D_SYSCONF_IDX] = paths[D_USER_IDX] + SYSCONF_DIR + DIR_SEP; - paths[F_SYSCONF_IDX] = paths[D_SYSCONF_IDX] + SYSCONF; break; case D_USER_IDX: paths[D_USER_IDX] = paths[D_ROOT_IDX] + DIR_SEP; paths[D_CONFIG_IDX] = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP; - paths[D_GAMECONFIG_IDX] = paths[D_USER_IDX] + GAMECONFIG_DIR DIR_SEP; - paths[D_MAPS_IDX] = paths[D_USER_IDX] + MAPS_DIR DIR_SEP; paths[D_CACHE_IDX] = paths[D_USER_IDX] + CACHE_DIR DIR_SEP; paths[D_SDMC_IDX] = paths[D_USER_IDX] + SDMC_DIR DIR_SEP; paths[D_NAND_IDX] = paths[D_USER_IDX] + NAND_DIR DIR_SEP; - paths[D_SHADERCACHE_IDX] = paths[D_USER_IDX] + SHADERCACHE_DIR DIR_SEP; - paths[D_SHADERS_IDX] = paths[D_USER_IDX] + SHADERS_DIR DIR_SEP; - paths[D_STATESAVES_IDX] = paths[D_USER_IDX] + STATESAVES_DIR DIR_SEP; - paths[D_SCREENSHOTS_IDX] = paths[D_USER_IDX] + SCREENSHOTS_DIR DIR_SEP; - paths[D_DUMP_IDX] = paths[D_USER_IDX] + DUMP_DIR DIR_SEP; - paths[D_DUMPFRAMES_IDX] = paths[D_DUMP_IDX] + DUMP_FRAMES_DIR DIR_SEP; - paths[D_DUMPAUDIO_IDX] = paths[D_DUMP_IDX] + DUMP_AUDIO_DIR DIR_SEP; - paths[D_DUMPTEXTURES_IDX] = paths[D_DUMP_IDX] + DUMP_TEXTURES_DIR DIR_SEP; - paths[D_LOGS_IDX] = paths[D_USER_IDX] + LOGS_DIR DIR_SEP; - paths[D_SYSCONF_IDX] = paths[D_USER_IDX] + SYSCONF_DIR DIR_SEP; - paths[F_EMUCONFIG_IDX] = paths[D_CONFIG_IDX] + EMU_CONFIG; - paths[F_DEBUGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + DEBUGGER_CONFIG; - paths[F_LOGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + LOGGER_CONFIG; - paths[F_MAINLOG_IDX] = paths[D_LOGS_IDX] + MAIN_LOG; break; - - case D_CONFIG_IDX: - paths[F_EMUCONFIG_IDX] = paths[D_CONFIG_IDX] + EMU_CONFIG; - paths[F_DEBUGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + DEBUGGER_CONFIG; - paths[F_LOGGERCONFIG_IDX] = paths[D_CONFIG_IDX] + LOGGER_CONFIG; - break; - - case D_DUMP_IDX: - paths[D_DUMPFRAMES_IDX] = paths[D_DUMP_IDX] + DUMP_FRAMES_DIR DIR_SEP; - paths[D_DUMPAUDIO_IDX] = paths[D_DUMP_IDX] + DUMP_AUDIO_DIR DIR_SEP; - paths[D_DUMPTEXTURES_IDX] = paths[D_DUMP_IDX] + DUMP_TEXTURES_DIR DIR_SEP; - break; - - case D_LOGS_IDX: - paths[F_MAINLOG_IDX] = paths[D_LOGS_IDX] + MAIN_LOG; } } diff --git a/src/common/file_util.h b/src/common/file_util.h index ac58607c59..94adfcd7ec 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -21,31 +21,11 @@ enum { D_USER_IDX, D_ROOT_IDX, D_CONFIG_IDX, - D_GAMECONFIG_IDX, - D_MAPS_IDX, D_CACHE_IDX, - D_SHADERCACHE_IDX, - D_SHADERS_IDX, - D_STATESAVES_IDX, - D_SCREENSHOTS_IDX, D_SDMC_IDX, D_NAND_IDX, D_SYSDATA_IDX, - D_HIRESTEXTURES_IDX, - D_DUMP_IDX, - D_DUMPFRAMES_IDX, - D_DUMPAUDIO_IDX, - D_DUMPTEXTURES_IDX, - D_DUMPDSP_IDX, D_LOGS_IDX, - D_SYSCONF_IDX, - F_EMUCONFIG_IDX, - F_DEBUGGERCONFIG_IDX, - F_LOGGERCONFIG_IDX, - F_MAINLOG_IDX, - F_RAMDUMP_IDX, - F_ARAMDUMP_IDX, - F_SYSCONF_IDX, NUM_PATH_INDICES }; From 232ef55c1a13552e5ba8b72d61d1d072f5851598 Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 15 Dec 2016 19:01:48 -0500 Subject: [PATCH 4/8] core: Consolidate core and system state, remove system module & cleanups. --- src/citra/citra.cpp | 3 +- src/citra_qt/bootmanager.cpp | 6 +- src/citra_qt/configure_general.cpp | 2 +- src/citra_qt/configure_graphics.cpp | 2 +- src/citra_qt/configure_system.cpp | 1 - src/citra_qt/debugger/callstack.cpp | 2 +- src/citra_qt/debugger/disassembler.cpp | 10 +-- src/citra_qt/debugger/registers.cpp | 16 ++-- src/citra_qt/debugger/wait_tree.cpp | 2 +- src/citra_qt/main.cpp | 1 - src/core/CMakeLists.txt | 2 - src/core/core.cpp | 112 +++++++++++++++++------ src/core/core.h | 120 +++++++++++++++++++------ src/core/core_timing.cpp | 27 +++--- src/core/gdbstub/gdbstub.cpp | 39 ++++---- src/core/hle/function_wrappers.h | 60 ++++++------- src/core/hle/hle.cpp | 4 +- src/core/hle/kernel/thread.cpp | 6 +- src/core/hle/service/ldr_ro/ldr_ro.cpp | 8 +- src/core/hle/svc.cpp | 12 +-- src/core/system.cpp | 90 ------------------- src/core/system.h | 83 ----------------- 22 files changed, 278 insertions(+), 330 deletions(-) delete mode 100644 src/core/system.cpp delete mode 100644 src/core/system.h diff --git a/src/citra/citra.cpp b/src/citra/citra.cpp index 5e2829b54b..febfc5dc8b 100644 --- a/src/citra/citra.cpp +++ b/src/citra/citra.cpp @@ -33,7 +33,6 @@ #include "core/gdbstub/gdbstub.h" #include "core/loader/loader.h" #include "core/settings.h" -#include "core/system.h" #include "video_core/video_core.h" static void PrintHelp(const char* argv0) { @@ -145,7 +144,7 @@ int main(int argc, char** argv) { } while (emu_window->IsOpen()) { - Core::RunLoop(); + system.RunLoop(); } return 0; diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index 5e8ae30665..bb75633b6b 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp @@ -14,8 +14,6 @@ #include "common/scm_rev.h" #include "common/string_util.h" #include "core/core.h" -#include "core/settings.h" -#include "core/system.h" #include "video_core/debug_utils/debug_utils.h" #include "video_core/video_core.h" @@ -38,7 +36,7 @@ void EmuThread::run() { if (!was_active) emit DebugModeLeft(); - Core::RunLoop(); + Core::System::GetInstance().RunLoop(); was_active = running || exec_step; if (!was_active && !stop_run) @@ -48,7 +46,7 @@ void EmuThread::run() { emit DebugModeLeft(); exec_step = false; - Core::SingleStep(); + Core::System::GetInstance().SingleStep(); emit DebugModeEntered(); yieldCurrentThread(); diff --git a/src/citra_qt/configure_general.cpp b/src/citra_qt/configure_general.cpp index f576f6f7a9..03cd8835ba 100644 --- a/src/citra_qt/configure_general.cpp +++ b/src/citra_qt/configure_general.cpp @@ -4,8 +4,8 @@ #include "citra_qt/configure_general.h" #include "citra_qt/ui_settings.h" +#include "core/core.h" #include "core/settings.h" -#include "core/system.h" #include "ui_configure_general.h" ConfigureGeneral::ConfigureGeneral(QWidget* parent) diff --git a/src/citra_qt/configure_graphics.cpp b/src/citra_qt/configure_graphics.cpp index 1e6f7f880a..cea7db388b 100644 --- a/src/citra_qt/configure_graphics.cpp +++ b/src/citra_qt/configure_graphics.cpp @@ -3,8 +3,8 @@ // Refer to the license.txt file included. #include "citra_qt/configure_graphics.h" +#include "core/core.h" #include "core/settings.h" -#include "core/system.h" #include "ui_configure_graphics.h" ConfigureGraphics::ConfigureGraphics(QWidget* parent) diff --git a/src/citra_qt/configure_system.cpp b/src/citra_qt/configure_system.cpp index 545261c015..eb1276ef33 100644 --- a/src/citra_qt/configure_system.cpp +++ b/src/citra_qt/configure_system.cpp @@ -6,7 +6,6 @@ #include "citra_qt/ui_settings.h" #include "core/hle/service/cfg/cfg.h" #include "core/hle/service/fs/archive.h" -#include "core/system.h" #include "ui_configure_system.h" static const std::array days_in_month = {{ diff --git a/src/citra_qt/debugger/callstack.cpp b/src/citra_qt/debugger/callstack.cpp index c66f2b96a1..5e176be48a 100644 --- a/src/citra_qt/debugger/callstack.cpp +++ b/src/citra_qt/debugger/callstack.cpp @@ -25,7 +25,7 @@ CallstackWidget::CallstackWidget(QWidget* parent) : QDockWidget(parent) { void CallstackWidget::OnDebugModeEntered() { // Stack pointer - const u32 sp = Core::g_app_core->GetReg(13); + const u32 sp = Core::AppCore().GetReg(13); Clear(); diff --git a/src/citra_qt/debugger/disassembler.cpp b/src/citra_qt/debugger/disassembler.cpp index 1ee6bbd6aa..712e35f7f3 100644 --- a/src/citra_qt/debugger/disassembler.cpp +++ b/src/citra_qt/debugger/disassembler.cpp @@ -185,13 +185,13 @@ DisassemblerWidget::DisassemblerWidget(QWidget* parent, EmuThread* emu_thread) } void DisassemblerWidget::Init() { - model->ParseFromAddress(Core::g_app_core->GetPC()); + model->ParseFromAddress(Core::AppCore().GetPC()); disasm_ui.treeView->resizeColumnToContents(0); disasm_ui.treeView->resizeColumnToContents(1); disasm_ui.treeView->resizeColumnToContents(2); - QModelIndex model_index = model->IndexFromAbsoluteAddress(Core::g_app_core->GetPC()); + QModelIndex model_index = model->IndexFromAbsoluteAddress(Core::AppCore().GetPC()); disasm_ui.treeView->scrollTo(model_index); disasm_ui.treeView->selectionModel()->setCurrentIndex( model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); @@ -214,8 +214,8 @@ void DisassemblerWidget::OnPause() { emu_thread->SetRunning(false); // TODO: By now, the CPU might not have actually stopped... - if (Core::g_app_core) { - model->SetNextInstruction(Core::g_app_core->GetPC()); + if (Core::System::GetInstance().IsPoweredOn()) { + model->SetNextInstruction(Core::AppCore().GetPC()); } } @@ -224,7 +224,7 @@ void DisassemblerWidget::OnToggleStartStop() { } void DisassemblerWidget::OnDebugModeEntered() { - u32 next_instr = Core::g_app_core->GetPC(); + u32 next_instr = Core::AppCore().GetPC(); if (model->GetBreakPoints().IsAddressBreakPoint(next_instr)) emu_thread->SetRunning(false); diff --git a/src/citra_qt/debugger/registers.cpp b/src/citra_qt/debugger/registers.cpp index 4c529d3c35..d5b6542bd1 100644 --- a/src/citra_qt/debugger/registers.cpp +++ b/src/citra_qt/debugger/registers.cpp @@ -58,16 +58,16 @@ RegistersWidget::RegistersWidget(QWidget* parent) : QDockWidget(parent) { } void RegistersWidget::OnDebugModeEntered() { - if (!Core::g_app_core) + if (!Core::System::GetInstance().IsPoweredOn()) return; for (int i = 0; i < core_registers->childCount(); ++i) core_registers->child(i)->setText( - 1, QString("0x%1").arg(Core::g_app_core->GetReg(i), 8, 16, QLatin1Char('0'))); + 1, QString("0x%1").arg(Core::AppCore().GetReg(i), 8, 16, QLatin1Char('0'))); for (int i = 0; i < vfp_registers->childCount(); ++i) vfp_registers->child(i)->setText( - 1, QString("0x%1").arg(Core::g_app_core->GetVFPReg(i), 8, 16, QLatin1Char('0'))); + 1, QString("0x%1").arg(Core::AppCore().GetVFPReg(i), 8, 16, QLatin1Char('0'))); UpdateCPSRValues(); UpdateVFPSystemRegisterValues(); @@ -127,7 +127,7 @@ void RegistersWidget::CreateCPSRChildren() { } void RegistersWidget::UpdateCPSRValues() { - const u32 cpsr_val = Core::g_app_core->GetCPSR(); + const u32 cpsr_val = Core::AppCore().GetCPSR(); cpsr->setText(1, QString("0x%1").arg(cpsr_val, 8, 16, QLatin1Char('0'))); cpsr->child(0)->setText( @@ -191,10 +191,10 @@ void RegistersWidget::CreateVFPSystemRegisterChildren() { } void RegistersWidget::UpdateVFPSystemRegisterValues() { - const u32 fpscr_val = Core::g_app_core->GetVFPSystemReg(VFP_FPSCR); - const u32 fpexc_val = Core::g_app_core->GetVFPSystemReg(VFP_FPEXC); - const u32 fpinst_val = Core::g_app_core->GetVFPSystemReg(VFP_FPINST); - const u32 fpinst2_val = Core::g_app_core->GetVFPSystemReg(VFP_FPINST2); + const u32 fpscr_val = Core::AppCore().GetVFPSystemReg(VFP_FPSCR); + const u32 fpexc_val = Core::AppCore().GetVFPSystemReg(VFP_FPEXC); + const u32 fpinst_val = Core::AppCore().GetVFPSystemReg(VFP_FPINST); + const u32 fpinst2_val = Core::AppCore().GetVFPSystemReg(VFP_FPINST2); QTreeWidgetItem* const fpscr = vfp_system_registers->child(0); fpscr->setText(1, QString("0x%1").arg(fpscr_val, 8, 16, QLatin1Char('0'))); diff --git a/src/citra_qt/debugger/wait_tree.cpp b/src/citra_qt/debugger/wait_tree.cpp index 5a308bf7fe..1d2de5185f 100644 --- a/src/citra_qt/debugger/wait_tree.cpp +++ b/src/citra_qt/debugger/wait_tree.cpp @@ -391,7 +391,7 @@ WaitTreeWidget::WaitTreeWidget(QWidget* parent) : QDockWidget(tr("Wait Tree"), p } void WaitTreeWidget::OnDebugModeEntered() { - if (!Core::g_app_core) + if (!Core::System::GetInstance().IsPoweredOn()) return; model->InitItems(); view->setModel(model); diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index 0c7723b0af..e27c09b53c 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -46,7 +46,6 @@ #include "core/gdbstub/gdbstub.h" #include "core/loader/loader.h" #include "core/settings.h" -#include "core/system.h" #include "qhexedit.h" #include "video_core/video_core.h" diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index af224166a7..d547b0746e 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -155,7 +155,6 @@ set(SRCS tracer/recorder.cpp memory.cpp settings.cpp - system.cpp ) set(HEADERS @@ -325,7 +324,6 @@ set(HEADERS memory_setup.h mmio.h settings.h - system.h ) include_directories(../../externals/dynarmic/include) diff --git a/src/core/core.cpp b/src/core/core.cpp index 6efa181592..b4df90efd4 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -3,6 +3,8 @@ // Refer to the license.txt file included. #include + +#include "audio_core/audio_core.h" #include "common/logging/log.h" #include "core/arm/arm_interface.h" #include "core/arm/dynarmic/arm_dynarmic.h" @@ -11,17 +13,23 @@ #include "core/core_timing.h" #include "core/gdbstub/gdbstub.h" #include "core/hle/hle.h" +#include "core/hle/kernel/kernel.h" +#include "core/hle/kernel/memory.h" #include "core/hle/kernel/thread.h" #include "core/hw/hw.h" +#include "core/loader/loader.h" #include "core/settings.h" +#include "video_core/video_core.h" namespace Core { -std::unique_ptr g_app_core; ///< ARM11 application core -std::unique_ptr g_sys_core; ///< ARM11 system (OS) core +/*static*/ System System::s_instance; + +System::ResultStatus System::RunLoop(int tight_loop) { + if (!app_core) { + return ResultStatus::ErrorNotInitialized; + } -/// Run the core CPU loop -void RunLoop(int tight_loop) { if (GDBStub::IsServerEnabled()) { GDBStub::HandlePacket(); @@ -32,7 +40,7 @@ void RunLoop(int tight_loop) { GDBStub::SetCpuStepFlag(false); tight_loop = 1; } else { - return; + return ResultStatus::Success; } } } @@ -45,46 +53,100 @@ void RunLoop(int tight_loop) { CoreTiming::Advance(); HLE::Reschedule(__func__); } else { - g_app_core->Run(tight_loop); + app_core->Run(tight_loop); } HW::Update(); if (HLE::IsReschedulePending()) { Kernel::Reschedule(); } + + return ResultStatus::Success; } -/// Step the CPU one instruction -void SingleStep() { - RunLoop(1); +System::ResultStatus System::SingleStep() { + return RunLoop(1); } -/// Halt the core -void Halt(const char* msg) { - // TODO(ShizZy): ImplementMe +System::ResultStatus System::Load(EmuWindow* emu_window, const std::string& filepath) { + if (app_loader) { + app_loader.reset(); + } + + app_loader = Loader::GetLoader(filepath); + + if (!app_loader) { + LOG_CRITICAL(Core, "Failed to obtain loader for %s!", filepath.c_str()); + return ResultStatus::ErrorGetLoader; + } + + boost::optional system_mode{ app_loader->LoadKernelSystemMode() }; + if (!system_mode) { + LOG_CRITICAL(Core, "Failed to determine system mode!"); + return ResultStatus::ErrorSystemMode; + } + + ResultStatus init_result{ Init(emu_window, system_mode.get()) }; + if (init_result != ResultStatus::Success) { + LOG_CRITICAL(Core, "Failed to initialize system (Error %i)!", init_result); + System::Shutdown(); + return init_result; + } + + const Loader::ResultStatus load_result{ app_loader->Load() }; + if (Loader::ResultStatus::Success != load_result) { + LOG_CRITICAL(Core, "Failed to load ROM (Error %i)!", load_result); + System::Shutdown(); + + switch (load_result) { + case Loader::ResultStatus::ErrorEncrypted: + return ResultStatus::ErrorLoader_ErrorEncrypted; + case Loader::ResultStatus::ErrorInvalidFormat: + return ResultStatus::ErrorLoader_ErrorInvalidFormat; + default: + return ResultStatus::ErrorLoader; + } + } + return ResultStatus::Success; } -/// Kill the core -void Stop() { - // TODO(ShizZy): ImplementMe -} +System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) { + if (app_core) { + app_core.reset(); + } + + Memory::Init(); -/// Initialize the core -void Init() { if (Settings::values.use_cpu_jit) { - g_sys_core = std::make_unique(USER32MODE); - g_app_core = std::make_unique(USER32MODE); + app_core = std::make_unique(USER32MODE); } else { - g_sys_core = std::make_unique(USER32MODE); - g_app_core = std::make_unique(USER32MODE); + app_core = std::make_unique(USER32MODE); + } + + CoreTiming::Init(); + HW::Init(); + Kernel::Init(system_mode); + HLE::Init(); + AudioCore::Init(); + GDBStub::Init(); + + if (!VideoCore::Init(emu_window)) { + return ResultStatus::ErrorVideoCore; } LOG_DEBUG(Core, "Initialized OK"); + + return ResultStatus::Success; } -void Shutdown() { - g_app_core.reset(); - g_sys_core.reset(); +void System::Shutdown() { + GDBStub::Shutdown(); + AudioCore::Shutdown(); + VideoCore::Shutdown(); + HLE::Shutdown(); + Kernel::Shutdown(); + HW::Shutdown(); + CoreTiming::Shutdown(); LOG_DEBUG(Core, "Shutdown OK"); } diff --git a/src/core/core.h b/src/core/core.h index ffbfa91c3f..f4326161d7 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -5,11 +5,17 @@ #pragma once #include -#include "common/common_types.h" +#include +#include "common/common_types.h" +#include "core/memory.h" + +class EmuWindow; class ARM_Interface; -//////////////////////////////////////////////////////////////////////////////////////////////////// +namespace Loader { +class AppLoader; +} namespace Core { @@ -24,37 +30,97 @@ struct ThreadContext { u32 fpexc; }; -extern std::unique_ptr g_app_core; ///< ARM11 application core -extern std::unique_ptr g_sys_core; ///< ARM11 system (OS) core +class System { +public: + /** + * Gets the instance of the System singleton class. + * @returns Reference to the instance of the System singleton class. + */ + static System& GetInstance() { + return s_instance; + } -//////////////////////////////////////////////////////////////////////////////////////////////////// + /// Enumeration representing the return values of the System Initialize and Load process. + enum class ResultStatus : u32 { + Success, ///< Succeeded + ErrorNotInitialized, ///< Error trying to use core prior to initialization + ErrorGetLoader, ///< Error finding the correct application loader + ErrorSystemMode, ///< Error determining the system mode + ErrorLoader, ///< Error loading the specified application + ErrorLoader_ErrorEncrypted, ///< Error loading the specified application due to encryption + ErrorLoader_ErrorInvalidFormat, ///< Error loading the specified application due to an invalid format + ErrorVideoCore, ///< Error in the video core + }; -/// Start the core -void Start(); + /** + * Initialize the emulated system. + * @param emu_window Pointer to the host-system window used for video output and keyboard input. + * @param system_mode The system mode. + * @return ResultStatus code, indicating if the operation succeeded. + */ + ResultStatus Init(EmuWindow* emu_window, u32 system_mode); -/** - * Run the core CPU loop - * This function runs the core for the specified number of CPU instructions before trying to update - * hardware. This is much faster than SingleStep (and should be equivalent), as the CPU is not - * required to do a full dispatch with each instruction. NOTE: the number of instructions requested - * is not guaranteed to run, as this will be interrupted preemptively if a hardware update is - * requested (e.g. on a thread switch). - */ -void RunLoop(int tight_loop = 1000); + /// Start the core + void Start(); -/// Step the CPU one instruction -void SingleStep(); + /** + * Run the core CPU loop + * This function runs the core for the specified number of CPU instructions before trying to update + * hardware. This is much faster than SingleStep (and should be equivalent), as the CPU is not + * required to do a full dispatch with each instruction. NOTE: the number of instructions requested + * is not guaranteed to run, as this will be interrupted preemptively if a hardware update is + * requested (e.g. on a thread switch). + * @param tight_loop Number of instructions to execute. + * @return Result status, indicating whethor or not the operation succeeded. + */ + ResultStatus RunLoop(int tight_loop = 1000); -/// Halt the core -void Halt(const char* msg); + /** + * Step the CPU one instruction + * @return Result status, indicating whethor or not the operation succeeded. + */ + ResultStatus SingleStep(); -/// Kill the core -void Stop(); + /// Shutdown the emulated system. + void Shutdown(); -/// Initialize the core -void Init(); + /** + * Load an executable application. + * @param emu_window Pointer to the host-system window used for video output and keyboard input. + * @param filepath String path to the executable application to load on the host file system. + * @returns ResultStatus code, indicating if the operation succeeded. + */ + ResultStatus Load(EmuWindow* emu_window, const std::string& filepath); -/// Shutdown the core -void Shutdown(); + /** + * Indicates if the emulated system is powered on (all subsystems initialized and able to run an + * application). + * @returns True if the emulated system is powered on, otherwise false. + */ + bool IsPoweredOn() const { + return app_core != nullptr; + } -} // namespace + /** + * Gets a reference to the emulated AppCore CPU. + * @returns A reference to the emulated AppCore CPU. + */ + ARM_Interface& AppCore() { + return *app_core; + } + +private: + /// AppLoader used to load the current executing application + std::unique_ptr app_loader; + + ///< ARM11 application core + std::unique_ptr app_core; + + static System s_instance; +}; + +static ARM_Interface& AppCore() { + return System::GetInstance().AppCore(); +} + +} // namespace Core diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp index 5220b55eab..9fe3747952 100644 --- a/src/core/core_timing.cpp +++ b/src/core/core_timing.cpp @@ -130,7 +130,6 @@ int RegisterEvent(const char* name, TimedCallback callback) { static void AntiCrashCallback(u64 userdata, int cycles_late) { LOG_CRITICAL(Core_Timing, "Savestate broken: an unregistered event was called."); - Core::Halt("invalid timing events"); } void RestoreRegisterEvent(int event_type, const char* name, TimedCallback callback) { @@ -147,7 +146,7 @@ void UnregisterAllEvents() { } void Init() { - Core::g_app_core->down_count = INITIAL_SLICE_LENGTH; + Core::AppCore().down_count = INITIAL_SLICE_LENGTH; g_slice_length = INITIAL_SLICE_LENGTH; global_timer = 0; idled_cycles = 0; @@ -187,7 +186,7 @@ void Shutdown() { } u64 GetTicks() { - return (u64)global_timer + g_slice_length - Core::g_app_core->down_count; + return (u64)global_timer + g_slice_length - Core::AppCore().down_count; } u64 GetIdleTicks() { @@ -461,18 +460,18 @@ void MoveEvents() { } void ForceCheck() { - s64 cycles_executed = g_slice_length - Core::g_app_core->down_count; + s64 cycles_executed = g_slice_length - Core::AppCore().down_count; global_timer += cycles_executed; // This will cause us to check for new events immediately. - Core::g_app_core->down_count = 0; + Core::AppCore().down_count = 0; // But let's not eat a bunch more time in Advance() because of this. g_slice_length = 0; } void Advance() { - s64 cycles_executed = g_slice_length - Core::g_app_core->down_count; + s64 cycles_executed = g_slice_length - Core::AppCore().down_count; global_timer += cycles_executed; - Core::g_app_core->down_count = g_slice_length; + Core::AppCore().down_count = g_slice_length; if (has_ts_events) MoveEvents(); @@ -481,7 +480,7 @@ void Advance() { if (!first) { if (g_slice_length < 10000) { g_slice_length += 10000; - Core::g_app_core->down_count += g_slice_length; + Core::AppCore().down_count += g_slice_length; } } else { // Note that events can eat cycles as well. @@ -491,7 +490,7 @@ void Advance() { const int diff = target - g_slice_length; g_slice_length += diff; - Core::g_app_core->down_count += diff; + Core::AppCore().down_count += diff; } if (advance_callback) advance_callback(static_cast(cycles_executed)); @@ -507,12 +506,12 @@ void LogPendingEvents() { } void Idle(int max_idle) { - s64 cycles_down = Core::g_app_core->down_count; + s64 cycles_down = Core::AppCore().down_count; if (max_idle != 0 && cycles_down > max_idle) cycles_down = max_idle; if (first && cycles_down > 0) { - s64 cycles_executed = g_slice_length - Core::g_app_core->down_count; + s64 cycles_executed = g_slice_length - Core::AppCore().down_count; s64 cycles_next_event = first->time - global_timer; if (cycles_next_event < cycles_executed + cycles_down) { @@ -527,9 +526,9 @@ void Idle(int max_idle) { cycles_down / (float)(g_clock_rate_arm11 * 0.001f)); idled_cycles += cycles_down; - Core::g_app_core->down_count -= cycles_down; - if (Core::g_app_core->down_count == 0) - Core::g_app_core->down_count = -1; + Core::AppCore().down_count -= cycles_down; + if (Core::AppCore().down_count == 0) + Core::AppCore().down_count = -1; } std::string GetScheduledEventsSummary() { diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index f96cbde64d..9acdd402b3 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp @@ -30,6 +30,7 @@ #include #endif +#include "core/loader/loader.h" #include "common/logging/log.h" #include "common/string_util.h" #include "core/arm/arm_interface.h" @@ -450,8 +451,8 @@ static void SendSignal(u32 signal) { latest_signal = signal; std::string buffer = Common::StringFromFormat("T%02x%02x:%08x;%02x:%08x;", latest_signal, 15, - htonl(Core::g_app_core->GetPC()), 13, - htonl(Core::g_app_core->GetReg(13))); + htonl(Core::AppCore().GetPC()), 13, + htonl(Core::AppCore().GetReg(13))); LOG_DEBUG(Debug_GDBStub, "Response: %s", buffer.c_str()); SendReply(buffer.c_str()); } @@ -538,15 +539,15 @@ static void ReadRegister() { } if (id <= R15_REGISTER) { - IntToGdbHex(reply, Core::g_app_core->GetReg(id)); + IntToGdbHex(reply, Core::AppCore().GetReg(id)); } else if (id == CPSR_REGISTER) { - IntToGdbHex(reply, Core::g_app_core->GetCPSR()); + IntToGdbHex(reply, Core::AppCore().GetCPSR()); } else if (id > CPSR_REGISTER && id < FPSCR_REGISTER) { - IntToGdbHex(reply, Core::g_app_core->GetVFPReg( + IntToGdbHex(reply, Core::AppCore().GetVFPReg( id - CPSR_REGISTER - 1)); // VFP registers should start at 26, so one after CSPR_REGISTER } else if (id == FPSCR_REGISTER) { - IntToGdbHex(reply, Core::g_app_core->GetVFPSystemReg(VFP_FPSCR)); // Get FPSCR + IntToGdbHex(reply, Core::AppCore().GetVFPSystemReg(VFP_FPSCR)); // Get FPSCR IntToGdbHex(reply + 8, 0); } else { return SendReply("E01"); @@ -563,22 +564,22 @@ static void ReadRegisters() { u8* bufptr = buffer; for (int reg = 0; reg <= R15_REGISTER; reg++) { - IntToGdbHex(bufptr + reg * CHAR_BIT, Core::g_app_core->GetReg(reg)); + IntToGdbHex(bufptr + reg * CHAR_BIT, Core::AppCore().GetReg(reg)); } bufptr += (16 * CHAR_BIT); - IntToGdbHex(bufptr, Core::g_app_core->GetCPSR()); + IntToGdbHex(bufptr, Core::AppCore().GetCPSR()); bufptr += CHAR_BIT; for (int reg = 0; reg <= 31; reg++) { - IntToGdbHex(bufptr + reg * CHAR_BIT, Core::g_app_core->GetVFPReg(reg)); + IntToGdbHex(bufptr + reg * CHAR_BIT, Core::AppCore().GetVFPReg(reg)); } bufptr += (32 * CHAR_BIT); - IntToGdbHex(bufptr, Core::g_app_core->GetVFPSystemReg(VFP_FPSCR)); + IntToGdbHex(bufptr, Core::AppCore().GetVFPSystemReg(VFP_FPSCR)); SendReply(reinterpret_cast(buffer)); } @@ -595,13 +596,13 @@ static void WriteRegister() { } if (id <= R15_REGISTER) { - Core::g_app_core->SetReg(id, GdbHexToInt(buffer_ptr)); + Core::AppCore().SetReg(id, GdbHexToInt(buffer_ptr)); } else if (id == CPSR_REGISTER) { - Core::g_app_core->SetCPSR(GdbHexToInt(buffer_ptr)); + Core::AppCore().SetCPSR(GdbHexToInt(buffer_ptr)); } else if (id > CPSR_REGISTER && id < FPSCR_REGISTER) { - Core::g_app_core->SetVFPReg(id - CPSR_REGISTER - 1, GdbHexToInt(buffer_ptr)); + Core::AppCore().SetVFPReg(id - CPSR_REGISTER - 1, GdbHexToInt(buffer_ptr)); } else if (id == FPSCR_REGISTER) { - Core::g_app_core->SetVFPSystemReg(VFP_FPSCR, GdbHexToInt(buffer_ptr)); + Core::AppCore().SetVFPSystemReg(VFP_FPSCR, GdbHexToInt(buffer_ptr)); } else { return SendReply("E01"); } @@ -618,20 +619,20 @@ static void WriteRegisters() { for (int i = 0, reg = 0; reg <= FPSCR_REGISTER; i++, reg++) { if (reg <= R15_REGISTER) { - Core::g_app_core->SetReg(reg, GdbHexToInt(buffer_ptr + i * CHAR_BIT)); + Core::AppCore().SetReg(reg, GdbHexToInt(buffer_ptr + i * CHAR_BIT)); } else if (reg == CPSR_REGISTER) { - Core::g_app_core->SetCPSR(GdbHexToInt(buffer_ptr + i * CHAR_BIT)); + Core::AppCore().SetCPSR(GdbHexToInt(buffer_ptr + i * CHAR_BIT)); } else if (reg == CPSR_REGISTER - 1) { // Dummy FPA register, ignore } else if (reg < CPSR_REGISTER) { // Dummy FPA registers, ignore i += 2; } else if (reg > CPSR_REGISTER && reg < FPSCR_REGISTER) { - Core::g_app_core->SetVFPReg(reg - CPSR_REGISTER - 1, + Core::AppCore().SetVFPReg(reg - CPSR_REGISTER - 1, GdbHexToInt(buffer_ptr + i * CHAR_BIT)); i++; // Skip padding } else if (reg == FPSCR_REGISTER) { - Core::g_app_core->SetVFPSystemReg(VFP_FPSCR, GdbHexToInt(buffer_ptr + i * CHAR_BIT)); + Core::AppCore().SetVFPSystemReg(VFP_FPSCR, GdbHexToInt(buffer_ptr + i * CHAR_BIT)); } } @@ -908,7 +909,7 @@ void ToggleServer(bool status) { server_enabled = status; // Start server - if (!IsConnected() && Core::g_sys_core != nullptr) { + if (!IsConnected() && Core::System().GetInstance().IsPoweredOn()) { Init(); } } else { diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/function_wrappers.h index 8ce0f6d2b6..0f2a04e30a 100644 --- a/src/core/hle/function_wrappers.h +++ b/src/core/hle/function_wrappers.h @@ -14,7 +14,7 @@ namespace HLE { -#define PARAM(n) Core::g_app_core->GetReg(n) +#define PARAM(n) Core::AppCore().GetReg(n) /// An invalid result code that is meant to be overwritten when a thread resumes from waiting static const ResultCode RESULT_INVALID(0xDEADC0DE); @@ -24,7 +24,7 @@ static const ResultCode RESULT_INVALID(0xDEADC0DE); * @param res Result to return */ static inline void FuncReturn(u32 res) { - Core::g_app_core->SetReg(0, res); + Core::AppCore().SetReg(0, res); } /** @@ -33,8 +33,8 @@ static inline void FuncReturn(u32 res) { * @todo Verify that this function is correct */ static inline void FuncReturn64(u64 res) { - Core::g_app_core->SetReg(0, (u32)(res & 0xFFFFFFFF)); - Core::g_app_core->SetReg(1, (u32)((res >> 32) & 0xFFFFFFFF)); + Core::AppCore().SetReg(0, (u32)(res & 0xFFFFFFFF)); + Core::AppCore().SetReg(1, (u32)((res >> 32) & 0xFFFFFFFF)); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -49,7 +49,7 @@ template void Wrap() { u32 param_1 = 0; u32 retval = func(¶m_1, PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)).raw; - Core::g_app_core->SetReg(1, param_1); + Core::AppCore().SetReg(1, param_1); FuncReturn(retval); } @@ -57,7 +57,7 @@ template void Wrap() { u32 param_1 = 0; u32 retval = func(¶m_1, PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)).raw; - Core::g_app_core->SetReg(1, param_1); + Core::AppCore().SetReg(1, param_1); FuncReturn(retval); } @@ -69,7 +69,7 @@ void Wrap() { .raw; if (retval != RESULT_INVALID.raw) { - Core::g_app_core->SetReg(1, (u32)param_1); + Core::AppCore().SetReg(1, (u32)param_1); FuncReturn(retval); } } @@ -84,7 +84,7 @@ template void Wrap() { u32 param_1 = 0; u32 retval = func(¶m_1).raw; - Core::g_app_core->SetReg(1, param_1); + Core::AppCore().SetReg(1, param_1); FuncReturn(retval); } @@ -102,11 +102,11 @@ void Wrap() { MemoryInfo memory_info = {}; PageInfo page_info = {}; u32 retval = func(&memory_info, &page_info, PARAM(2)).raw; - Core::g_app_core->SetReg(1, memory_info.base_address); - Core::g_app_core->SetReg(2, memory_info.size); - Core::g_app_core->SetReg(3, memory_info.permission); - Core::g_app_core->SetReg(4, memory_info.state); - Core::g_app_core->SetReg(5, page_info.flags); + Core::AppCore().SetReg(1, memory_info.base_address); + Core::AppCore().SetReg(2, memory_info.size); + Core::AppCore().SetReg(3, memory_info.permission); + Core::AppCore().SetReg(4, memory_info.state); + Core::AppCore().SetReg(5, page_info.flags); FuncReturn(retval); } @@ -115,11 +115,11 @@ void Wrap() { MemoryInfo memory_info = {}; PageInfo page_info = {}; u32 retval = func(&memory_info, &page_info, PARAM(2), PARAM(3)).raw; - Core::g_app_core->SetReg(1, memory_info.base_address); - Core::g_app_core->SetReg(2, memory_info.size); - Core::g_app_core->SetReg(3, memory_info.permission); - Core::g_app_core->SetReg(4, memory_info.state); - Core::g_app_core->SetReg(5, page_info.flags); + Core::AppCore().SetReg(1, memory_info.base_address); + Core::AppCore().SetReg(2, memory_info.size); + Core::AppCore().SetReg(3, memory_info.permission); + Core::AppCore().SetReg(4, memory_info.state); + Core::AppCore().SetReg(5, page_info.flags); FuncReturn(retval); } @@ -127,7 +127,7 @@ template void Wrap() { s32 param_1 = 0; u32 retval = func(¶m_1, PARAM(1)).raw; - Core::g_app_core->SetReg(1, param_1); + Core::AppCore().SetReg(1, param_1); FuncReturn(retval); } @@ -140,7 +140,7 @@ template void Wrap() { u32 param_1 = 0; u32 retval = func(¶m_1, PARAM(1)).raw; - Core::g_app_core->SetReg(1, param_1); + Core::AppCore().SetReg(1, param_1); FuncReturn(retval); } @@ -160,7 +160,7 @@ template void Wrap() { u32 param_1 = 0; u32 retval = func(¶m_1, (char*)Memory::GetPointer(PARAM(1))).raw; - Core::g_app_core->SetReg(1, param_1); + Core::AppCore().SetReg(1, param_1); FuncReturn(retval); } @@ -168,7 +168,7 @@ template void Wrap() { u32 param_1 = 0; u32 retval = func(¶m_1, PARAM(1), PARAM(2)).raw; - Core::g_app_core->SetReg(1, param_1); + Core::AppCore().SetReg(1, param_1); FuncReturn(retval); } @@ -176,7 +176,7 @@ template void Wrap() { s32 param_1 = 0; u32 retval = func(¶m_1, PARAM(1), PARAM(2)).raw; - Core::g_app_core->SetReg(1, param_1); + Core::AppCore().SetReg(1, param_1); FuncReturn(retval); } @@ -184,8 +184,8 @@ template void Wrap() { s64 param_1 = 0; u32 retval = func(¶m_1, PARAM(1), PARAM(2)).raw; - Core::g_app_core->SetReg(1, (u32)param_1); - Core::g_app_core->SetReg(2, (u32)(param_1 >> 32)); + Core::AppCore().SetReg(1, (u32)param_1); + Core::AppCore().SetReg(2, (u32)(param_1 >> 32)); FuncReturn(retval); } @@ -194,7 +194,7 @@ void Wrap() { u32 param_1 = 0; // The last parameter is passed in R0 instead of R4 u32 retval = func(¶m_1, PARAM(1), PARAM(2), PARAM(3), PARAM(0)).raw; - Core::g_app_core->SetReg(1, param_1); + Core::AppCore().SetReg(1, param_1); FuncReturn(retval); } @@ -209,8 +209,8 @@ template void Wrap() { s64 param_1 = 0; u32 retval = func(¶m_1, PARAM(1), PARAM(2)).raw; - Core::g_app_core->SetReg(1, (u32)param_1); - Core::g_app_core->SetReg(2, (u32)(param_1 >> 32)); + Core::AppCore().SetReg(1, (u32)param_1); + Core::AppCore().SetReg(2, (u32)(param_1 >> 32)); FuncReturn(retval); } @@ -227,8 +227,8 @@ void Wrap() { reinterpret_cast(Memory::GetPointer(PARAM(2))), PARAM(3)) .raw; // The first out parameter is moved into R2 and the second is moved into R1. - Core::g_app_core->SetReg(1, param_2); - Core::g_app_core->SetReg(2, param_1); + Core::AppCore().SetReg(1, param_2); + Core::AppCore().SetReg(2, param_1); FuncReturn(retval); } diff --git a/src/core/hle/hle.cpp b/src/core/hle/hle.cpp index 41b7721636..d73d98a701 100644 --- a/src/core/hle/hle.cpp +++ b/src/core/hle/hle.cpp @@ -26,9 +26,9 @@ void Reschedule(const char* reason) { // routines. This simulates that time by artificially advancing the number of CPU "ticks". // The value was chosen empirically, it seems to work well enough for everything tested, but // is likely not ideal. We should find a more accurate way to simulate timing with HLE. - Core::g_app_core->AddTicks(4000); + Core::AppCore().AddTicks(4000); - Core::g_app_core->PrepareReschedule(); + Core::AppCore().PrepareReschedule(); reschedule = true; } diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 18b696f72a..91c05fc424 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -188,7 +188,7 @@ static void SwitchContext(Thread* new_thread) { // Save context for previous thread if (previous_thread) { previous_thread->last_running_ticks = CoreTiming::GetTicks(); - Core::g_app_core->SaveContext(previous_thread->context); + Core::AppCore().SaveContext(previous_thread->context); if (previous_thread->status == THREADSTATUS_RUNNING) { // This is only the case when a reschedule is triggered without the current thread @@ -214,8 +214,8 @@ static void SwitchContext(Thread* new_thread) { // Restores thread to its nominal priority if it has been temporarily changed new_thread->current_priority = new_thread->nominal_priority; - Core::g_app_core->LoadContext(new_thread->context); - Core::g_app_core->SetCP15Register(CP15_THREAD_URO, new_thread->GetTLSAddress()); + Core::AppCore().LoadContext(new_thread->context); + Core::AppCore().SetCP15Register(CP15_THREAD_URO, new_thread->GetTLSAddress()); } else { current_thread = nullptr; } diff --git a/src/core/hle/service/ldr_ro/ldr_ro.cpp b/src/core/hle/service/ldr_ro/ldr_ro.cpp index 9e5d6a3187..614f16d448 100644 --- a/src/core/hle/service/ldr_ro/ldr_ro.cpp +++ b/src/core/hle/service/ldr_ro/ldr_ro.cpp @@ -457,7 +457,7 @@ static void LoadCRO(Interface* self, bool link_on_load_bug_fix) { } } - Core::g_app_core->ClearInstructionCache(); + Core::AppCore().ClearInstructionCache(); LOG_INFO(Service_LDR, "CRO \"%s\" loaded at 0x%08X, fixed_end=0x%08X", cro.ModuleName().data(), cro_address, cro_address + fix_size); @@ -562,7 +562,7 @@ static void UnloadCRO(Interface* self) { memory_synchronizer.RemoveMemoryBlock(cro_address, cro_buffer_ptr); } - Core::g_app_core->ClearInstructionCache(); + Core::AppCore().ClearInstructionCache(); cmd_buff[1] = result.raw; } @@ -624,7 +624,7 @@ static void LinkCRO(Interface* self) { } memory_synchronizer.SynchronizeOriginalMemory(); - Core::g_app_core->ClearInstructionCache(); + Core::AppCore().ClearInstructionCache(); cmd_buff[1] = result.raw; } @@ -686,7 +686,7 @@ static void UnlinkCRO(Interface* self) { } memory_synchronizer.SynchronizeOriginalMemory(); - Core::g_app_core->ClearInstructionCache(); + Core::AppCore().ClearInstructionCache(); cmd_buff[1] = result.raw; } diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 5839d72304..b20f2aaa47 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -582,7 +582,7 @@ static ResultCode CreateThread(Handle* out_handle, s32 priority, u32 entry_point /// Called when a thread exits static void ExitThread() { - LOG_TRACE(Kernel_SVC, "called, pc=0x%08X", Core::g_app_core->GetPC()); + LOG_TRACE(Kernel_SVC, "called, pc=0x%08X", Core::AppCore().GetPC()); Kernel::ExitCurrentThread(); } @@ -612,7 +612,7 @@ static ResultCode CreateMutex(Handle* out_handle, u32 initial_locked) { using Kernel::Mutex; SharedPtr mutex = Mutex::Create(initial_locked != 0); - mutex->name = Common::StringFromFormat("mutex-%08x", Core::g_app_core->GetReg(14)); + mutex->name = Common::StringFromFormat("mutex-%08x", Core::AppCore().GetReg(14)); CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(mutex))); LOG_TRACE(Kernel_SVC, "called initial_locked=%s : created handle=0x%08X", @@ -683,7 +683,7 @@ static ResultCode CreateSemaphore(Handle* out_handle, s32 initial_count, s32 max using Kernel::Semaphore; CASCADE_RESULT(SharedPtr semaphore, Semaphore::Create(initial_count, max_count)); - semaphore->name = Common::StringFromFormat("semaphore-%08x", Core::g_app_core->GetReg(14)); + semaphore->name = Common::StringFromFormat("semaphore-%08x", Core::AppCore().GetReg(14)); CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(semaphore))); LOG_TRACE(Kernel_SVC, "called initial_count=%d, max_count=%d, created handle=0x%08X", @@ -740,7 +740,7 @@ static ResultCode CreateEvent(Handle* out_handle, u32 reset_type) { using Kernel::Event; SharedPtr evt = Event::Create(static_cast(reset_type)); - evt->name = Common::StringFromFormat("event-%08x", Core::g_app_core->GetReg(14)); + evt->name = Common::StringFromFormat("event-%08x", Core::AppCore().GetReg(14)); CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(evt))); LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", reset_type, @@ -787,7 +787,7 @@ static ResultCode CreateTimer(Handle* out_handle, u32 reset_type) { using Kernel::Timer; SharedPtr timer = Timer::Create(static_cast(reset_type)); - timer->name = Common::StringFromFormat("timer-%08x", Core::g_app_core->GetReg(14)); + timer->name = Common::StringFromFormat("timer-%08x", Core::AppCore().GetReg(14)); CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(timer))); LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", reset_type, @@ -854,7 +854,7 @@ static void SleepThread(s64 nanoseconds) { static s64 GetSystemTick() { s64 result = CoreTiming::GetTicks(); // Advance time to defeat dumb games (like Cubic Ninja) that busy-wait for the frame to end. - Core::g_app_core->AddTicks( + Core::AppCore().AddTicks( 150); // Measured time between two calls on a 9.2 o3DS with Ninjhax 1.1b return result; } diff --git a/src/core/system.cpp b/src/core/system.cpp deleted file mode 100644 index fa8bd0317a..0000000000 --- a/src/core/system.cpp +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2014 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#include "audio_core/audio_core.h" -#include "core/core.h" -#include "core/core_timing.h" -#include "core/gdbstub/gdbstub.h" -#include "core/hle/hle.h" -#include "core/hle/kernel/kernel.h" -#include "core/hle/kernel/memory.h" -#include "core/hw/hw.h" -#include "core/system.h" -#include "video_core/video_core.h" - -namespace Core { - -/*static*/ System System::s_instance; - -System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) { - Core::Init(); - CoreTiming::Init(); - Memory::Init(); - HW::Init(); - Kernel::Init(system_mode); - HLE::Init(); - AudioCore::Init(); - GDBStub::Init(); - - if (!VideoCore::Init(emu_window)) { - return ResultStatus::ErrorVideoCore; - } - - is_powered_on = true; - - return ResultStatus::Success; -} - -void System::Shutdown() { - GDBStub::Shutdown(); - AudioCore::Shutdown(); - VideoCore::Shutdown(); - HLE::Shutdown(); - Kernel::Shutdown(); - HW::Shutdown(); - CoreTiming::Shutdown(); - Core::Shutdown(); - - is_powered_on = false; -} - -System::ResultStatus System::Load(EmuWindow* emu_window, const std::string& filepath) { - state.app_loader = Loader::GetLoader(filepath); - - if (!state.app_loader) { - LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", filepath.c_str()); - return ResultStatus::ErrorGetLoader; - } - - boost::optional system_mode{ state.app_loader->LoadKernelSystemMode() }; - if (!system_mode) { - LOG_CRITICAL(Frontend, "Failed to determine system mode!"); - return ResultStatus::ErrorSystemMode; - } - - ResultStatus init_result{ Init(emu_window, system_mode.get()) }; - if (init_result != ResultStatus::Success) { - LOG_CRITICAL(Frontend, "Failed to initialize system (Error %i)!", init_result); - System::Shutdown(); - return init_result; - } - - const Loader::ResultStatus load_result{ state.app_loader->Load() }; - if (Loader::ResultStatus::Success != load_result) { - LOG_CRITICAL(Frontend, "Failed to load ROM (Error %i)!", load_result); - System::Shutdown(); - - switch (load_result) { - case Loader::ResultStatus::ErrorEncrypted: - return ResultStatus::ErrorLoader_ErrorEncrypted; - case Loader::ResultStatus::ErrorInvalidFormat: - return ResultStatus::ErrorLoader_ErrorInvalidFormat; - default: - return ResultStatus::ErrorLoader; - } - } - return ResultStatus::Success; -} - -} // namespace Core diff --git a/src/core/system.h b/src/core/system.h deleted file mode 100644 index 192a9c4479..0000000000 --- a/src/core/system.h +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 2014 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -#include - -#include "core/loader/loader.h" - -class EmuWindow; - -namespace Core { - -class System { -public: - struct State { - std::unique_ptr app_loader; - }; - - /** - * Gets the instance of the System singleton class. - * @returns Reference to the instance of the System singleton class. - */ - static System& GetInstance() { - return s_instance; - } - - /// Enumeration representing the return values of the System Initialize and Load process. - enum class ResultStatus : u32 { - Success, ///< Succeeded - ErrorGetLoader, ///< Error finding the correct application loader - ErrorSystemMode, ///< Error determining the system mode - ErrorLoader, ///< Error loading the specified application - ErrorLoader_ErrorEncrypted, ///< Error loading the specified application due to encryption - ErrorLoader_ErrorInvalidFormat, ///< Error loading the specified application due to an invalid format - ErrorVideoCore, ///< Error in the video core - }; - - /** - * Initialize the emulated system. - * @param emu_window Pointer to the host-system window used for video output and keyboard input. - * @param system_mode The system mode. - * @returns ResultStatus code, indicating if the operation succeeded. - */ - ResultStatus Init(EmuWindow* emu_window, u32 system_mode); - - /// Shutdown the emulated system. - void Shutdown(); - - /** - * Load an executable application. - * @param emu_window Pointer to the host-system window used for video output and keyboard input. - * @param filepath String path to the executable application to load on the host file system. - * @returns ResultStatus code, indicating if the operation succeeded. - */ - ResultStatus Load(EmuWindow* emu_window, const std::string& filepath); - - /** - * Indicates if the emulated system is powered on (all subsystems initialized and able to run an - * application). - * @returns True if the emulated system is powered on, otherwise false. - */ - bool IsPoweredOn() const { - return is_powered_on; - } - - /** - * Gets the internal state of the emulated system. - * @returns The internal state of the emulated system - */ - State& GetState() { - return state; - } - -private: - bool is_powered_on{}; - State state; - - static System s_instance; -}; - -} // namespace Core From 4fc8b8229ed1d9ea9d20faee7059c898265db6cf Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 16 Dec 2016 00:37:38 -0500 Subject: [PATCH 5/8] core: Remove HLE module, consolidate code & various cleanups. --- src/core/CMakeLists.txt | 2 - src/core/core.cpp | 26 +++++-- src/core/core.h | 28 +++++--- src/core/file_sys/archive_extsavedata.cpp | 4 +- src/core/file_sys/archive_ncch.cpp | 2 +- .../file_sys/archive_source_sd_savedata.cpp | 2 +- src/core/file_sys/archive_systemsavedata.cpp | 2 +- src/core/hle/function_wrappers.h | 16 ++--- src/core/hle/hle.h | 23 ------ src/core/hle/kernel/address_arbiter.cpp | 1 - src/core/hle/kernel/kernel.h | 3 +- src/core/hle/kernel/thread.cpp | 5 +- src/core/hle/kernel/thread.h | 1 - src/core/hle/service/csnd_snd.cpp | 1 - src/core/hle/service/fs/archive.cpp | 5 +- src/core/hle/service/fs/archive.h | 4 +- src/core/hle/service/ir/ir.cpp | 3 +- src/core/hle/service/mic_u.cpp | 3 +- src/core/hle/svc.cpp | 70 +++++++++---------- 19 files changed, 94 insertions(+), 107 deletions(-) delete mode 100644 src/core/hle/hle.h diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index d547b0746e..5d74e45468 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -31,7 +31,6 @@ set(SRCS file_sys/savedata_archive.cpp gdbstub/gdbstub.cpp hle/config_mem.cpp - hle/hle.cpp hle/applets/applet.cpp hle/applets/erreula.cpp hle/applets/mii_selector.cpp @@ -195,7 +194,6 @@ set(HEADERS gdbstub/gdbstub.h hle/config_mem.h hle/function_wrappers.h - hle/hle.h hle/ipc.h hle/applets/applet.h hle/applets/erreula.h diff --git a/src/core/core.cpp b/src/core/core.cpp index b4df90efd4..67d7cf7b26 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -12,10 +12,10 @@ #include "core/core.h" #include "core/core_timing.h" #include "core/gdbstub/gdbstub.h" -#include "core/hle/hle.h" #include "core/hle/kernel/kernel.h" #include "core/hle/kernel/memory.h" #include "core/hle/kernel/thread.h" +#include "core/hle/service/service.h" #include "core/hw/hw.h" #include "core/loader/loader.h" #include "core/settings.h" @@ -51,15 +51,13 @@ System::ResultStatus System::RunLoop(int tight_loop) { LOG_TRACE(Core_ARM11, "Idling"); CoreTiming::Idle(); CoreTiming::Advance(); - HLE::Reschedule(__func__); + PrepareReschedule(); } else { app_core->Run(tight_loop); } HW::Update(); - if (HLE::IsReschedulePending()) { - Kernel::Reschedule(); - } + Reschedule(); return ResultStatus::Success; } @@ -110,6 +108,20 @@ System::ResultStatus System::Load(EmuWindow* emu_window, const std::string& file return ResultStatus::Success; } +void System::PrepareReschedule() { + app_core->PrepareReschedule(); + reschedule_pending = true; +} + +void System::Reschedule() { + if (!reschedule_pending) { + return; + } + + reschedule_pending = false; + Kernel::Reschedule(); +} + System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) { if (app_core) { app_core.reset(); @@ -126,7 +138,7 @@ System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) { CoreTiming::Init(); HW::Init(); Kernel::Init(system_mode); - HLE::Init(); + Service::Init(); AudioCore::Init(); GDBStub::Init(); @@ -143,7 +155,7 @@ void System::Shutdown() { GDBStub::Shutdown(); AudioCore::Shutdown(); VideoCore::Shutdown(); - HLE::Shutdown(); + Service::Shutdown(); Kernel::Shutdown(); HW::Shutdown(); CoreTiming::Shutdown(); diff --git a/src/core/core.h b/src/core/core.h index f4326161d7..8194db6a2c 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -52,17 +52,6 @@ public: ErrorVideoCore, ///< Error in the video core }; - /** - * Initialize the emulated system. - * @param emu_window Pointer to the host-system window used for video output and keyboard input. - * @param system_mode The system mode. - * @return ResultStatus code, indicating if the operation succeeded. - */ - ResultStatus Init(EmuWindow* emu_window, u32 system_mode); - - /// Start the core - void Start(); - /** * Run the core CPU loop * This function runs the core for the specified number of CPU instructions before trying to update @@ -101,6 +90,9 @@ public: return app_core != nullptr; } + /// Prepare the core emulation for a reschedule + void PrepareReschedule(); + /** * Gets a reference to the emulated AppCore CPU. * @returns A reference to the emulated AppCore CPU. @@ -110,12 +102,26 @@ public: } private: + /** + * Initialize the emulated system. + * @param emu_window Pointer to the host-system window used for video output and keyboard input. + * @param system_mode The system mode. + * @return ResultStatus code, indicating if the operation succeeded. + */ + ResultStatus Init(EmuWindow* emu_window, u32 system_mode); + + /// Reschedule the core emulation + void Reschedule(); + /// AppLoader used to load the current executing application std::unique_ptr app_loader; ///< ARM11 application core std::unique_ptr app_core; + /// When true, signals that a reschedule should happen + bool reschedule_pending{}; + static System s_instance; }; diff --git a/src/core/file_sys/archive_extsavedata.cpp b/src/core/file_sys/archive_extsavedata.cpp index 5b172df4a2..b9fc77e34f 100644 --- a/src/core/file_sys/archive_extsavedata.cpp +++ b/src/core/file_sys/archive_extsavedata.cpp @@ -142,10 +142,10 @@ std::string GetExtSaveDataPath(const std::string& mount_point, const Path& path) std::string GetExtDataContainerPath(const std::string& mount_point, bool shared) { if (shared) return Common::StringFromFormat("%sdata/%s/extdata/", mount_point.c_str(), - SYSTEM_ID.c_str()); + SYSTEM_ID); return Common::StringFromFormat("%sNintendo 3DS/%s/%s/extdata/", mount_point.c_str(), - SYSTEM_ID.c_str(), SDCARD_ID.c_str()); + SYSTEM_ID, SDCARD_ID); } Path ConstructExtDataBinaryPath(u32 media_type, u32 high, u32 low) { diff --git a/src/core/file_sys/archive_ncch.cpp b/src/core/file_sys/archive_ncch.cpp index 6f1aadfc3d..89455e39c2 100644 --- a/src/core/file_sys/archive_ncch.cpp +++ b/src/core/file_sys/archive_ncch.cpp @@ -19,7 +19,7 @@ namespace FileSys { static std::string GetNCCHContainerPath(const std::string& nand_directory) { - return Common::StringFromFormat("%s%s/title/", nand_directory.c_str(), SYSTEM_ID.c_str()); + return Common::StringFromFormat("%s%s/title/", nand_directory.c_str(), SYSTEM_ID); } static std::string GetNCCHPath(const std::string& mount_point, u32 high, u32 low) { diff --git a/src/core/file_sys/archive_source_sd_savedata.cpp b/src/core/file_sys/archive_source_sd_savedata.cpp index 287322d3e1..e01357891a 100644 --- a/src/core/file_sys/archive_source_sd_savedata.cpp +++ b/src/core/file_sys/archive_source_sd_savedata.cpp @@ -18,7 +18,7 @@ namespace { std::string GetSaveDataContainerPath(const std::string& sdmc_directory) { return Common::StringFromFormat("%sNintendo 3DS/%s/%s/title/", sdmc_directory.c_str(), - SYSTEM_ID.c_str(), SDCARD_ID.c_str()); + SYSTEM_ID, SDCARD_ID); } std::string GetSaveDataPath(const std::string& mount_location, u64 program_id) { diff --git a/src/core/file_sys/archive_systemsavedata.cpp b/src/core/file_sys/archive_systemsavedata.cpp index 54e7793e09..8986b5c0e7 100644 --- a/src/core/file_sys/archive_systemsavedata.cpp +++ b/src/core/file_sys/archive_systemsavedata.cpp @@ -26,7 +26,7 @@ std::string GetSystemSaveDataPath(const std::string& mount_point, const Path& pa } std::string GetSystemSaveDataContainerPath(const std::string& mount_point) { - return Common::StringFromFormat("%sdata/%s/sysdata/", mount_point.c_str(), SYSTEM_ID.c_str()); + return Common::StringFromFormat("%sdata/%s/sysdata/", mount_point.c_str(), SYSTEM_ID); } Path ConstructSystemSaveDataBinaryPath(u32 high, u32 low) { diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/function_wrappers.h index 0f2a04e30a..cafc7fe62a 100644 --- a/src/core/hle/function_wrappers.h +++ b/src/core/hle/function_wrappers.h @@ -7,7 +7,7 @@ #include "common/common_types.h" #include "core/arm/arm_interface.h" #include "core/core.h" -#include "core/hle/hle.h" +#include "core/hle/kernel/kernel.h" #include "core/hle/result.h" #include "core/hle/svc.h" #include "core/memory.h" @@ -64,7 +64,7 @@ void Wrap() { template void Wrap() { s32 param_1 = 0; - s32 retval = func(¶m_1, (Handle*)Memory::GetPointer(PARAM(1)), (s32)PARAM(2), + s32 retval = func(¶m_1, (Kernel::Handle*)Memory::GetPointer(PARAM(1)), (s32)PARAM(2), (PARAM(3) != 0), (((s64)PARAM(4) << 32) | PARAM(0))) .raw; @@ -110,7 +110,7 @@ void Wrap() { FuncReturn(retval); } -template +template void Wrap() { MemoryInfo memory_info = {}; PageInfo page_info = {}; @@ -205,7 +205,7 @@ void Wrap() { FuncReturn(func(PARAM(0), param1, param2).raw); } -template +template void Wrap() { s64 param_1 = 0; u32 retval = func(¶m_1, PARAM(1), PARAM(2)).raw; @@ -214,15 +214,15 @@ void Wrap() { FuncReturn(retval); } -template +template void Wrap() { FuncReturn(func(PARAM(0), PARAM(1)).raw); } -template +template void Wrap() { - Handle param_1 = 0; - Handle param_2 = 0; + Kernel::Handle param_1 = 0; + Kernel::Handle param_2 = 0; u32 retval = func(¶m_1, ¶m_2, reinterpret_cast(Memory::GetPointer(PARAM(2))), PARAM(3)) .raw; diff --git a/src/core/hle/hle.h b/src/core/hle/hle.h deleted file mode 100644 index 23859e1296..0000000000 --- a/src/core/hle/hle.h +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2014 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -#include "common/common_types.h" - -typedef u32 Handle; -typedef s32 Result; - -const Handle INVALID_HANDLE = 0; - -namespace HLE { - -void Reschedule(const char* reason); -bool IsReschedulePending(); -void DoneRescheduling(); - -void Init(); -void Shutdown(); - -} // namespace diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cpp index b5a0cc3a39..01fab123eb 100644 --- a/src/core/hle/kernel/address_arbiter.cpp +++ b/src/core/hle/kernel/address_arbiter.cpp @@ -4,7 +4,6 @@ #include "common/common_types.h" #include "common/logging/log.h" -#include "core/hle/hle.h" #include "core/hle/kernel/address_arbiter.h" #include "core/hle/kernel/thread.h" #include "core/memory.h" diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index 1adcf6c712..9503e7d044 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h @@ -11,11 +11,12 @@ #include #include #include "common/common_types.h" -#include "core/hle/hle.h" #include "core/hle/result.h" namespace Kernel { +using Handle = u32; + class Thread; // TODO: Verify code diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 91c05fc424..c964b35d4d 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -14,7 +14,6 @@ #include "core/arm/skyeye_common/armstate.h" #include "core/core.h" #include "core/core_timing.h" -#include "core/hle/hle.h" #include "core/hle/kernel/kernel.h" #include "core/hle/kernel/memory.h" #include "core/hle/kernel/mutex.h" @@ -330,7 +329,7 @@ void Thread::ResumeFromWait() { ready_queue.push_back(current_priority, this); status = THREADSTATUS_READY; - HLE::Reschedule(__func__); + Core::System::GetInstance().PrepareReschedule(); } /** @@ -545,8 +544,6 @@ void Reschedule() { Thread* cur = GetCurrentThread(); Thread* next = PopNextReadyThread(); - HLE::DoneRescheduling(); - if (cur && next) { LOG_TRACE(Kernel, "context switch %u -> %u", cur->GetObjectId(), next->GetObjectId()); } else if (cur) { diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index d4fefc5730..89acc12c1b 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -11,7 +11,6 @@ #include #include "common/common_types.h" #include "core/core.h" -#include "core/hle/hle.h" #include "core/hle/kernel/kernel.h" #include "core/hle/result.h" diff --git a/src/core/hle/service/csnd_snd.cpp b/src/core/hle/service/csnd_snd.cpp index 6544e89a22..25392f3cf8 100644 --- a/src/core/hle/service/csnd_snd.cpp +++ b/src/core/hle/service/csnd_snd.cpp @@ -4,7 +4,6 @@ #include #include "common/alignment.h" -#include "core/hle/hle.h" #include "core/hle/kernel/mutex.h" #include "core/hle/kernel/shared_memory.h" #include "core/hle/service/csnd_snd.h" diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index 09205e4b29..6cddc1fdb2 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp @@ -23,7 +23,6 @@ #include "core/file_sys/archive_systemsavedata.h" #include "core/file_sys/directory_backend.h" #include "core/file_sys/file_backend.h" -#include "core/hle/hle.h" #include "core/hle/kernel/client_session.h" #include "core/hle/result.h" #include "core/hle/service/fs/archive.h" @@ -46,9 +45,7 @@ struct hash { }; } -/// TODO(Subv): Confirm length of these strings -const std::string SYSTEM_ID = "00000000000000000000000000000000"; -const std::string SDCARD_ID = "00000000000000000000000000000000"; +static constexpr Kernel::Handle INVALID_HANDLE{}; namespace Service { namespace FS { diff --git a/src/core/hle/service/fs/archive.h b/src/core/hle/service/fs/archive.h index 7ba62ede09..0aa373f401 100644 --- a/src/core/hle/service/fs/archive.h +++ b/src/core/hle/service/fs/archive.h @@ -17,9 +17,9 @@ class FileBackend; } /// The unique system identifier hash, also known as ID0 -extern const std::string SYSTEM_ID; +static constexpr char SYSTEM_ID[]{ "00000000000000000000000000000000" }; /// The scrambled SD card CID, also known as ID1 -extern const std::string SDCARD_ID; +static constexpr char SDCARD_ID[]{ "00000000000000000000000000000000" }; namespace Service { namespace FS { diff --git a/src/core/hle/service/ir/ir.cpp b/src/core/hle/service/ir/ir.cpp index 4d6639dedb..7f1731a50f 100644 --- a/src/core/hle/service/ir/ir.cpp +++ b/src/core/hle/service/ir/ir.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include "core/hle/kernel/event.h" +#include "core/hle/kernel/kernel.h" #include "core/hle/kernel/shared_memory.h" #include "core/hle/service/ir/ir.h" #include "core/hle/service/ir/ir_rst.h" @@ -36,7 +37,7 @@ void InitializeIrNopShared(Interface* self) { u32 send_buff_size = cmd_buff[4]; u32 unk2 = cmd_buff[5]; u8 baud_rate = cmd_buff[6] & 0xFF; - Handle handle = cmd_buff[8]; + Kernel::Handle handle = cmd_buff[8]; if (Kernel::g_handle_table.IsValid(handle)) { transfer_shared_memory = Kernel::g_handle_table.Get(handle); diff --git a/src/core/hle/service/mic_u.cpp b/src/core/hle/service/mic_u.cpp index 7ced36439e..4f1dd2fce8 100644 --- a/src/core/hle/service/mic_u.cpp +++ b/src/core/hle/service/mic_u.cpp @@ -4,6 +4,7 @@ #include "common/logging/log.h" #include "core/hle/kernel/event.h" +#include "core/hle/kernel/kernel.h" #include "core/hle/kernel/shared_memory.h" #include "core/hle/service/mic_u.h" @@ -50,7 +51,7 @@ static bool audio_buffer_loop; static void MapSharedMem(Interface* self) { u32* cmd_buff = Kernel::GetCommandBuffer(); u32 size = cmd_buff[1]; - Handle mem_handle = cmd_buff[3]; + Kernel::Handle mem_handle = cmd_buff[3]; shared_memory = Kernel::g_handle_table.Get(mem_handle); if (shared_memory) { shared_memory->name = "MIC_U:shared_memory"; diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index b20f2aaa47..5a52525c6e 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -166,7 +166,7 @@ static ResultCode ControlMemory(u32* out_addr, u32 operation, u32 addr0, u32 add } /// Maps a memory block to specified address -static ResultCode MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 other_permissions) { +static ResultCode MapMemoryBlock(Kernel::Handle handle, u32 addr, u32 permissions, u32 other_permissions) { using Kernel::SharedMemory; using Kernel::MemoryPermission; @@ -198,7 +198,7 @@ static ResultCode MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 o ErrorSummary::InvalidArgument, ErrorLevel::Usage); } -static ResultCode UnmapMemoryBlock(Handle handle, u32 addr) { +static ResultCode UnmapMemoryBlock(Kernel::Handle handle, u32 addr) { using Kernel::SharedMemory; LOG_TRACE(Kernel_SVC, "called memblock=0x%08X, addr=0x%08X", handle, addr); @@ -213,7 +213,7 @@ static ResultCode UnmapMemoryBlock(Handle handle, u32 addr) { } /// Connect to an OS service given the port name, returns the handle to the port to out -static ResultCode ConnectToPort(Handle* out_handle, const char* port_name) { +static ResultCode ConnectToPort(Kernel::Handle* out_handle, const char* port_name) { if (port_name == nullptr) return ERR_NOT_FOUND; if (std::strlen(port_name) > 11) @@ -238,7 +238,7 @@ static ResultCode ConnectToPort(Handle* out_handle, const char* port_name) { } /// Makes a blocking IPC call to an OS service. -static ResultCode SendSyncRequest(Handle handle) { +static ResultCode SendSyncRequest(Kernel::Handle handle) { SharedPtr session = Kernel::g_handle_table.Get(handle); if (session == nullptr) { @@ -253,13 +253,13 @@ static ResultCode SendSyncRequest(Handle handle) { } /// Close a handle -static ResultCode CloseHandle(Handle handle) { +static ResultCode CloseHandle(Kernel::Handle handle) { LOG_TRACE(Kernel_SVC, "Closing handle 0x%08X", handle); return Kernel::g_handle_table.Close(handle); } /// Wait for a handle to synchronize, timeout after the specified nanoseconds -static ResultCode WaitSynchronization1(Handle handle, s64 nano_seconds) { +static ResultCode WaitSynchronization1(Kernel::Handle handle, s64 nano_seconds) { auto object = Kernel::g_handle_table.GetWaitObject(handle); Kernel::Thread* thread = Kernel::GetCurrentThread(); @@ -295,7 +295,7 @@ static ResultCode WaitSynchronization1(Handle handle, s64 nano_seconds) { } /// Wait for the given handles to synchronize, timeout after the specified nanoseconds -static ResultCode WaitSynchronizationN(s32* out, Handle* handles, s32 handle_count, bool wait_all, +static ResultCode WaitSynchronizationN(s32* out, Kernel::Handle* handles, s32 handle_count, bool wait_all, s64 nano_seconds) { Kernel::Thread* thread = Kernel::GetCurrentThread(); @@ -423,7 +423,7 @@ static ResultCode WaitSynchronizationN(s32* out, Handle* handles, s32 handle_cou } /// Create an address arbiter (to allocate access to shared resources) -static ResultCode CreateAddressArbiter(Handle* out_handle) { +static ResultCode CreateAddressArbiter(Kernel::Handle* out_handle) { using Kernel::AddressArbiter; SharedPtr arbiter = AddressArbiter::Create(); @@ -433,7 +433,7 @@ static ResultCode CreateAddressArbiter(Handle* out_handle) { } /// Arbitrate address -static ResultCode ArbitrateAddress(Handle handle, u32 address, u32 type, u32 value, +static ResultCode ArbitrateAddress(Kernel::Handle handle, u32 address, u32 type, u32 value, s64 nanoseconds) { using Kernel::AddressArbiter; @@ -476,7 +476,7 @@ static void OutputDebugString(const char* string) { } /// Get resource limit -static ResultCode GetResourceLimit(Handle* resource_limit, Handle process_handle) { +static ResultCode GetResourceLimit(Kernel::Handle* resource_limit, Kernel::Handle process_handle) { LOG_TRACE(Kernel_SVC, "called process=0x%08X", process_handle); SharedPtr process = @@ -490,7 +490,7 @@ static ResultCode GetResourceLimit(Handle* resource_limit, Handle process_handle } /// Get resource limit current values -static ResultCode GetResourceLimitCurrentValues(s64* values, Handle resource_limit_handle, +static ResultCode GetResourceLimitCurrentValues(s64* values, Kernel::Handle resource_limit_handle, u32* names, u32 name_count) { LOG_TRACE(Kernel_SVC, "called resource_limit=%08X, names=%p, name_count=%d", resource_limit_handle, names, name_count); @@ -507,7 +507,7 @@ static ResultCode GetResourceLimitCurrentValues(s64* values, Handle resource_lim } /// Get resource limit max values -static ResultCode GetResourceLimitLimitValues(s64* values, Handle resource_limit_handle, u32* names, +static ResultCode GetResourceLimitLimitValues(s64* values, Kernel::Handle resource_limit_handle, u32* names, u32 name_count) { LOG_TRACE(Kernel_SVC, "called resource_limit=%08X, names=%p, name_count=%d", resource_limit_handle, names, name_count); @@ -524,7 +524,7 @@ static ResultCode GetResourceLimitLimitValues(s64* values, Handle resource_limit } /// Creates a new thread -static ResultCode CreateThread(Handle* out_handle, s32 priority, u32 entry_point, u32 arg, +static ResultCode CreateThread(Kernel::Handle* out_handle, s32 priority, u32 entry_point, u32 arg, u32 stack_top, s32 processor_id) { using Kernel::Thread; @@ -588,7 +588,7 @@ static void ExitThread() { } /// Gets the priority for the specified thread -static ResultCode GetThreadPriority(s32* priority, Handle handle) { +static ResultCode GetThreadPriority(s32* priority, Kernel::Handle handle) { const SharedPtr thread = Kernel::g_handle_table.Get(handle); if (thread == nullptr) return ERR_INVALID_HANDLE; @@ -598,7 +598,7 @@ static ResultCode GetThreadPriority(s32* priority, Handle handle) { } /// Sets the priority for the specified thread -static ResultCode SetThreadPriority(Handle handle, s32 priority) { +static ResultCode SetThreadPriority(Kernel::Handle handle, s32 priority) { SharedPtr thread = Kernel::g_handle_table.Get(handle); if (thread == nullptr) return ERR_INVALID_HANDLE; @@ -608,7 +608,7 @@ static ResultCode SetThreadPriority(Handle handle, s32 priority) { } /// Create a mutex -static ResultCode CreateMutex(Handle* out_handle, u32 initial_locked) { +static ResultCode CreateMutex(Kernel::Handle* out_handle, u32 initial_locked) { using Kernel::Mutex; SharedPtr mutex = Mutex::Create(initial_locked != 0); @@ -622,7 +622,7 @@ static ResultCode CreateMutex(Handle* out_handle, u32 initial_locked) { } /// Release a mutex -static ResultCode ReleaseMutex(Handle handle) { +static ResultCode ReleaseMutex(Kernel::Handle handle) { using Kernel::Mutex; LOG_TRACE(Kernel_SVC, "called handle=0x%08X", handle); @@ -637,7 +637,7 @@ static ResultCode ReleaseMutex(Handle handle) { } /// Get the ID of the specified process -static ResultCode GetProcessId(u32* process_id, Handle process_handle) { +static ResultCode GetProcessId(u32* process_id, Kernel::Handle process_handle) { LOG_TRACE(Kernel_SVC, "called process=0x%08X", process_handle); const SharedPtr process = @@ -650,7 +650,7 @@ static ResultCode GetProcessId(u32* process_id, Handle process_handle) { } /// Get the ID of the process that owns the specified thread -static ResultCode GetProcessIdOfThread(u32* process_id, Handle thread_handle) { +static ResultCode GetProcessIdOfThread(u32* process_id, Kernel::Handle thread_handle) { LOG_TRACE(Kernel_SVC, "called thread=0x%08X", thread_handle); const SharedPtr thread = @@ -667,7 +667,7 @@ static ResultCode GetProcessIdOfThread(u32* process_id, Handle thread_handle) { } /// Get the ID for the specified thread. -static ResultCode GetThreadId(u32* thread_id, Handle handle) { +static ResultCode GetThreadId(u32* thread_id, Kernel::Handle handle) { LOG_TRACE(Kernel_SVC, "called thread=0x%08X", handle); const SharedPtr thread = Kernel::g_handle_table.Get(handle); @@ -679,7 +679,7 @@ static ResultCode GetThreadId(u32* thread_id, Handle handle) { } /// Creates a semaphore -static ResultCode CreateSemaphore(Handle* out_handle, s32 initial_count, s32 max_count) { +static ResultCode CreateSemaphore(Kernel::Handle* out_handle, s32 initial_count, s32 max_count) { using Kernel::Semaphore; CASCADE_RESULT(SharedPtr semaphore, Semaphore::Create(initial_count, max_count)); @@ -692,7 +692,7 @@ static ResultCode CreateSemaphore(Handle* out_handle, s32 initial_count, s32 max } /// Releases a certain number of slots in a semaphore -static ResultCode ReleaseSemaphore(s32* count, Handle handle, s32 release_count) { +static ResultCode ReleaseSemaphore(s32* count, Kernel::Handle handle, s32 release_count) { using Kernel::Semaphore; LOG_TRACE(Kernel_SVC, "called release_count=%d, handle=0x%08X", release_count, handle); @@ -708,7 +708,7 @@ static ResultCode ReleaseSemaphore(s32* count, Handle handle, s32 release_count) /// Query process memory static ResultCode QueryProcessMemory(MemoryInfo* memory_info, PageInfo* page_info, - Handle process_handle, u32 addr) { + Kernel::Handle process_handle, u32 addr) { using Kernel::Process; Kernel::SharedPtr process = Kernel::g_handle_table.Get(process_handle); if (process == nullptr) @@ -736,7 +736,7 @@ static ResultCode QueryMemory(MemoryInfo* memory_info, PageInfo* page_info, u32 } /// Create an event -static ResultCode CreateEvent(Handle* out_handle, u32 reset_type) { +static ResultCode CreateEvent(Kernel::Handle* out_handle, u32 reset_type) { using Kernel::Event; SharedPtr evt = Event::Create(static_cast(reset_type)); @@ -749,14 +749,14 @@ static ResultCode CreateEvent(Handle* out_handle, u32 reset_type) { } /// Duplicates a kernel handle -static ResultCode DuplicateHandle(Handle* out, Handle handle) { +static ResultCode DuplicateHandle(Kernel::Handle* out, Kernel::Handle handle) { CASCADE_RESULT(*out, Kernel::g_handle_table.Duplicate(handle)); LOG_TRACE(Kernel_SVC, "duplicated 0x%08X to 0x%08X", handle, *out); return RESULT_SUCCESS; } /// Signals an event -static ResultCode SignalEvent(Handle handle) { +static ResultCode SignalEvent(Kernel::Handle handle) { using Kernel::Event; LOG_TRACE(Kernel_SVC, "called event=0x%08X", handle); @@ -770,7 +770,7 @@ static ResultCode SignalEvent(Handle handle) { } /// Clears an event -static ResultCode ClearEvent(Handle handle) { +static ResultCode ClearEvent(Kernel::Handle handle) { using Kernel::Event; LOG_TRACE(Kernel_SVC, "called event=0x%08X", handle); @@ -783,7 +783,7 @@ static ResultCode ClearEvent(Handle handle) { } /// Creates a timer -static ResultCode CreateTimer(Handle* out_handle, u32 reset_type) { +static ResultCode CreateTimer(Kernel::Handle* out_handle, u32 reset_type) { using Kernel::Timer; SharedPtr timer = Timer::Create(static_cast(reset_type)); @@ -796,7 +796,7 @@ static ResultCode CreateTimer(Handle* out_handle, u32 reset_type) { } /// Clears a timer -static ResultCode ClearTimer(Handle handle) { +static ResultCode ClearTimer(Kernel::Handle handle) { using Kernel::Timer; LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle); @@ -810,7 +810,7 @@ static ResultCode ClearTimer(Handle handle) { } /// Starts a timer -static ResultCode SetTimer(Handle handle, s64 initial, s64 interval) { +static ResultCode SetTimer(Kernel::Handle handle, s64 initial, s64 interval) { using Kernel::Timer; LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle); @@ -825,7 +825,7 @@ static ResultCode SetTimer(Handle handle, s64 initial, s64 interval) { } /// Cancels a timer -static ResultCode CancelTimer(Handle handle) { +static ResultCode CancelTimer(Kernel::Handle handle) { using Kernel::Timer; LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle); @@ -860,7 +860,7 @@ static s64 GetSystemTick() { } /// Creates a memory block at the specified address with the specified permissions and size -static ResultCode CreateMemoryBlock(Handle* out_handle, u32 addr, u32 size, u32 my_permission, +static ResultCode CreateMemoryBlock(Kernel::Handle* out_handle, u32 addr, u32 size, u32 my_permission, u32 other_permission) { using Kernel::SharedMemory; @@ -912,7 +912,7 @@ static ResultCode CreateMemoryBlock(Handle* out_handle, u32 addr, u32 size, u32 return RESULT_SUCCESS; } -static ResultCode CreatePort(Handle* server_port, Handle* client_port, const char* name, +static ResultCode CreatePort(Kernel::Handle* server_port, Kernel::Handle* client_port, const char* name, u32 max_sessions) { // TODO(Subv): Implement named ports. ASSERT_MSG(name == nullptr, "Named ports are currently unimplemented"); @@ -978,7 +978,7 @@ static ResultCode GetSystemInfo(s64* out, u32 type, s32 param) { return RESULT_SUCCESS; } -static ResultCode GetProcessInfo(s64* out, Handle process_handle, u32 type) { +static ResultCode GetProcessInfo(s64* out, Kernel::Handle process_handle, u32 type) { LOG_TRACE(Kernel_SVC, "called process=0x%08X type=%u", process_handle, type); using Kernel::Process; @@ -1185,7 +1185,7 @@ void CallSVC(u32 immediate) { if (info->func) { info->func(); // TODO(Subv): Not all service functions should cause a reschedule in all cases. - HLE::Reschedule(__func__); + Core::System::GetInstance().PrepareReschedule(); } else { LOG_ERROR(Kernel_SVC, "unimplemented SVC function %s(..)", info->name); } From 5ac5cbeab7387b2eabd4618291e223fd7189bb8b Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 17 Dec 2016 01:20:47 -0500 Subject: [PATCH 6/8] Address clang-format issues. --- src/citra/citra.cpp | 6 ++--- src/citra_qt/main.cpp | 27 +++++++++++------------ src/core/core.cpp | 6 ++--- src/core/core.h | 25 +++++++++++---------- src/core/file_sys/archive_extsavedata.cpp | 7 +++--- src/core/gdbstub/gdbstub.cpp | 4 ++-- src/core/hle/service/fs/archive.h | 4 ++-- src/core/hle/svc.cpp | 19 ++++++++-------- 8 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/citra/citra.cpp b/src/citra/citra.cpp index febfc5dc8b..99c096ac7a 100644 --- a/src/citra/citra.cpp +++ b/src/citra/citra.cpp @@ -126,13 +126,13 @@ int main(int argc, char** argv) { Settings::values.use_gdbstub = use_gdbstub; Settings::Apply(); - std::unique_ptr emu_window{ std::make_unique() }; + std::unique_ptr emu_window{std::make_unique()}; - Core::System& system{ Core::System::GetInstance() }; + Core::System& system{Core::System::GetInstance()}; SCOPE_EXIT({ system.Shutdown(); }); - const Core::System::ResultStatus load_result{ system.Load(emu_window.get(), filepath) }; + const Core::System::ResultStatus load_result{system.Load(emu_window.get(), filepath)}; switch (load_result) { case Core::System::ResultStatus::ErrorGetLoader: diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index e27c09b53c..6d59cf6408 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -283,49 +283,48 @@ bool GMainWindow::LoadROM(const std::string& filename) { if (!gladLoadGL()) { QMessageBox::critical(this, tr("Error while starting Citra!"), - tr("Failed to initialize the video core!\n\n" - "Please ensure that your GPU supports OpenGL 3.3 and that you " - "have the latest graphics driver.")); + tr("Failed to initialize the video core!\n\n" + "Please ensure that your GPU supports OpenGL 3.3 and that you " + "have the latest graphics driver.")); return false; } - Core::System& system{ Core::System::GetInstance() }; + Core::System& system{Core::System::GetInstance()}; - const Core::System::ResultStatus result{ system.Load(render_window, filename) }; + const Core::System::ResultStatus result{system.Load(render_window, filename)}; if (result != Core::System::ResultStatus::Success) { switch (result) { case Core::System::ResultStatus::ErrorGetLoader: LOG_CRITICAL(Frontend, "Failed to obtain loader for %s!", filename.c_str()); QMessageBox::critical(this, tr("Error while loading ROM!"), - tr("The ROM format is not supported.")); + tr("The ROM format is not supported.")); break; case Core::System::ResultStatus::ErrorSystemMode: LOG_CRITICAL(Frontend, "Failed to load ROM!"); QMessageBox::critical(this, tr("Error while loading ROM!"), - tr("Could not determine the system mode.")); + tr("Could not determine the system mode.")); break; - case Core::System::ResultStatus::ErrorLoader_ErrorEncrypted: - { + case Core::System::ResultStatus::ErrorLoader_ErrorEncrypted: { // Build the MessageBox ourselves to have clickable link QMessageBox popup_error; popup_error.setTextFormat(Qt::RichText); popup_error.setWindowTitle(tr("Error while loading ROM!")); popup_error.setText( tr("The game that you are trying to load must be decrypted before being used with " - "Citra.

" - "For more information on dumping and decrypting games, please see: https://" - "citra-emu.org/wiki/Dumping-Game-Cartridges")); + "Citra.

" + "For more information on dumping and decrypting games, please see: https://" + "citra-emu.org/wiki/Dumping-Game-Cartridges")); popup_error.setIcon(QMessageBox::Critical); popup_error.exec(); break; } case Core::System::ResultStatus::ErrorLoader_ErrorInvalidFormat: QMessageBox::critical(this, tr("Error while loading ROM!"), - tr("The ROM format is not supported.")); + tr("The ROM format is not supported.")); break; default: diff --git a/src/core/core.cpp b/src/core/core.cpp index 67d7cf7b26..fabd3f42a4 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -78,20 +78,20 @@ System::ResultStatus System::Load(EmuWindow* emu_window, const std::string& file return ResultStatus::ErrorGetLoader; } - boost::optional system_mode{ app_loader->LoadKernelSystemMode() }; + boost::optional system_mode{app_loader->LoadKernelSystemMode()}; if (!system_mode) { LOG_CRITICAL(Core, "Failed to determine system mode!"); return ResultStatus::ErrorSystemMode; } - ResultStatus init_result{ Init(emu_window, system_mode.get()) }; + ResultStatus init_result{Init(emu_window, system_mode.get())}; if (init_result != ResultStatus::Success) { LOG_CRITICAL(Core, "Failed to initialize system (Error %i)!", init_result); System::Shutdown(); return init_result; } - const Loader::ResultStatus load_result{ app_loader->Load() }; + const Loader::ResultStatus load_result{app_loader->Load()}; if (Loader::ResultStatus::Success != load_result) { LOG_CRITICAL(Core, "Failed to load ROM (Error %i)!", load_result); System::Shutdown(); diff --git a/src/core/core.h b/src/core/core.h index 8194db6a2c..728c24c1c5 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -42,23 +42,24 @@ public: /// Enumeration representing the return values of the System Initialize and Load process. enum class ResultStatus : u32 { - Success, ///< Succeeded - ErrorNotInitialized, ///< Error trying to use core prior to initialization - ErrorGetLoader, ///< Error finding the correct application loader - ErrorSystemMode, ///< Error determining the system mode - ErrorLoader, ///< Error loading the specified application + Success, ///< Succeeded + ErrorNotInitialized, ///< Error trying to use core prior to initialization + ErrorGetLoader, ///< Error finding the correct application loader + ErrorSystemMode, ///< Error determining the system mode + ErrorLoader, ///< Error loading the specified application ErrorLoader_ErrorEncrypted, ///< Error loading the specified application due to encryption - ErrorLoader_ErrorInvalidFormat, ///< Error loading the specified application due to an invalid format - ErrorVideoCore, ///< Error in the video core + ErrorLoader_ErrorInvalidFormat, ///< Error loading the specified application due to an + /// invalid format + ErrorVideoCore, ///< Error in the video core }; /** * Run the core CPU loop - * This function runs the core for the specified number of CPU instructions before trying to update - * hardware. This is much faster than SingleStep (and should be equivalent), as the CPU is not - * required to do a full dispatch with each instruction. NOTE: the number of instructions requested - * is not guaranteed to run, as this will be interrupted preemptively if a hardware update is - * requested (e.g. on a thread switch). + * This function runs the core for the specified number of CPU instructions before trying to + * update hardware. This is much faster than SingleStep (and should be equivalent), as the CPU + * is not required to do a full dispatch with each instruction. NOTE: the number of instructions + * requested is not guaranteed to run, as this will be interrupted preemptively if a hardware + * update is requested (e.g. on a thread switch). * @param tight_loop Number of instructions to execute. * @return Result status, indicating whethor or not the operation succeeded. */ diff --git a/src/core/file_sys/archive_extsavedata.cpp b/src/core/file_sys/archive_extsavedata.cpp index b9fc77e34f..51ce78435d 100644 --- a/src/core/file_sys/archive_extsavedata.cpp +++ b/src/core/file_sys/archive_extsavedata.cpp @@ -141,11 +141,10 @@ std::string GetExtSaveDataPath(const std::string& mount_point, const Path& path) std::string GetExtDataContainerPath(const std::string& mount_point, bool shared) { if (shared) - return Common::StringFromFormat("%sdata/%s/extdata/", mount_point.c_str(), - SYSTEM_ID); + return Common::StringFromFormat("%sdata/%s/extdata/", mount_point.c_str(), SYSTEM_ID); - return Common::StringFromFormat("%sNintendo 3DS/%s/%s/extdata/", mount_point.c_str(), - SYSTEM_ID, SDCARD_ID); + return Common::StringFromFormat("%sNintendo 3DS/%s/%s/extdata/", mount_point.c_str(), SYSTEM_ID, + SDCARD_ID); } Path ConstructExtDataBinaryPath(u32 media_type, u32 high, u32 low) { diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index 9acdd402b3..c75d5fc5e2 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp @@ -30,12 +30,12 @@ #include #endif -#include "core/loader/loader.h" #include "common/logging/log.h" #include "common/string_util.h" #include "core/arm/arm_interface.h" #include "core/core.h" #include "core/gdbstub/gdbstub.h" +#include "core/loader/loader.h" #include "core/memory.h" const int GDB_BUFFER_SIZE = 10000; @@ -629,7 +629,7 @@ static void WriteRegisters() { i += 2; } else if (reg > CPSR_REGISTER && reg < FPSCR_REGISTER) { Core::AppCore().SetVFPReg(reg - CPSR_REGISTER - 1, - GdbHexToInt(buffer_ptr + i * CHAR_BIT)); + GdbHexToInt(buffer_ptr + i * CHAR_BIT)); i++; // Skip padding } else if (reg == FPSCR_REGISTER) { Core::AppCore().SetVFPSystemReg(VFP_FPSCR, GdbHexToInt(buffer_ptr + i * CHAR_BIT)); diff --git a/src/core/hle/service/fs/archive.h b/src/core/hle/service/fs/archive.h index 0aa373f401..519c1f3a94 100644 --- a/src/core/hle/service/fs/archive.h +++ b/src/core/hle/service/fs/archive.h @@ -17,9 +17,9 @@ class FileBackend; } /// The unique system identifier hash, also known as ID0 -static constexpr char SYSTEM_ID[]{ "00000000000000000000000000000000" }; +static constexpr char SYSTEM_ID[]{"00000000000000000000000000000000"}; /// The scrambled SD card CID, also known as ID1 -static constexpr char SDCARD_ID[]{ "00000000000000000000000000000000" }; +static constexpr char SDCARD_ID[]{"00000000000000000000000000000000"}; namespace Service { namespace FS { diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 5a52525c6e..1f89ccfd54 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -166,7 +166,8 @@ static ResultCode ControlMemory(u32* out_addr, u32 operation, u32 addr0, u32 add } /// Maps a memory block to specified address -static ResultCode MapMemoryBlock(Kernel::Handle handle, u32 addr, u32 permissions, u32 other_permissions) { +static ResultCode MapMemoryBlock(Kernel::Handle handle, u32 addr, u32 permissions, + u32 other_permissions) { using Kernel::SharedMemory; using Kernel::MemoryPermission; @@ -295,8 +296,8 @@ static ResultCode WaitSynchronization1(Kernel::Handle handle, s64 nano_seconds) } /// Wait for the given handles to synchronize, timeout after the specified nanoseconds -static ResultCode WaitSynchronizationN(s32* out, Kernel::Handle* handles, s32 handle_count, bool wait_all, - s64 nano_seconds) { +static ResultCode WaitSynchronizationN(s32* out, Kernel::Handle* handles, s32 handle_count, + bool wait_all, s64 nano_seconds) { Kernel::Thread* thread = Kernel::GetCurrentThread(); // Check if 'handles' is invalid @@ -507,8 +508,8 @@ static ResultCode GetResourceLimitCurrentValues(s64* values, Kernel::Handle reso } /// Get resource limit max values -static ResultCode GetResourceLimitLimitValues(s64* values, Kernel::Handle resource_limit_handle, u32* names, - u32 name_count) { +static ResultCode GetResourceLimitLimitValues(s64* values, Kernel::Handle resource_limit_handle, + u32* names, u32 name_count) { LOG_TRACE(Kernel_SVC, "called resource_limit=%08X, names=%p, name_count=%d", resource_limit_handle, names, name_count); @@ -860,8 +861,8 @@ static s64 GetSystemTick() { } /// Creates a memory block at the specified address with the specified permissions and size -static ResultCode CreateMemoryBlock(Kernel::Handle* out_handle, u32 addr, u32 size, u32 my_permission, - u32 other_permission) { +static ResultCode CreateMemoryBlock(Kernel::Handle* out_handle, u32 addr, u32 size, + u32 my_permission, u32 other_permission) { using Kernel::SharedMemory; if (size % Memory::PAGE_SIZE != 0) @@ -912,8 +913,8 @@ static ResultCode CreateMemoryBlock(Kernel::Handle* out_handle, u32 addr, u32 si return RESULT_SUCCESS; } -static ResultCode CreatePort(Kernel::Handle* server_port, Kernel::Handle* client_port, const char* name, - u32 max_sessions) { +static ResultCode CreatePort(Kernel::Handle* server_port, Kernel::Handle* client_port, + const char* name, u32 max_sessions) { // TODO(Subv): Implement named ports. ASSERT_MSG(name == nullptr, "Named ports are currently unimplemented"); From e26fbfd1d72c026d0f25c09595e7123459b1734f Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 22 Dec 2016 00:00:01 -0500 Subject: [PATCH 7/8] core: Replace "AppCore" nomenclature with just "CPU". --- src/citra_qt/debugger/callstack.cpp | 2 +- src/citra_qt/debugger/disassembler.cpp | 8 ++-- src/citra_qt/debugger/registers.cpp | 14 +++--- src/core/core.cpp | 14 +++--- src/core/core.h | 18 ++++---- src/core/core_timing.cpp | 26 +++++------ src/core/gdbstub/gdbstub.cpp | 39 ++++++++--------- src/core/hle/function_wrappers.h | 60 +++++++++++++------------- src/core/hle/kernel/thread.cpp | 6 +-- src/core/hle/service/ldr_ro/ldr_ro.cpp | 8 ++-- src/core/hle/svc.cpp | 13 +++--- 11 files changed, 103 insertions(+), 105 deletions(-) diff --git a/src/citra_qt/debugger/callstack.cpp b/src/citra_qt/debugger/callstack.cpp index 5e176be48a..c1db935836 100644 --- a/src/citra_qt/debugger/callstack.cpp +++ b/src/citra_qt/debugger/callstack.cpp @@ -25,7 +25,7 @@ CallstackWidget::CallstackWidget(QWidget* parent) : QDockWidget(parent) { void CallstackWidget::OnDebugModeEntered() { // Stack pointer - const u32 sp = Core::AppCore().GetReg(13); + const u32 sp = Core::CPU().GetReg(13); Clear(); diff --git a/src/citra_qt/debugger/disassembler.cpp b/src/citra_qt/debugger/disassembler.cpp index 712e35f7f3..e9c8ad8581 100644 --- a/src/citra_qt/debugger/disassembler.cpp +++ b/src/citra_qt/debugger/disassembler.cpp @@ -185,13 +185,13 @@ DisassemblerWidget::DisassemblerWidget(QWidget* parent, EmuThread* emu_thread) } void DisassemblerWidget::Init() { - model->ParseFromAddress(Core::AppCore().GetPC()); + model->ParseFromAddress(Core::CPU().GetPC()); disasm_ui.treeView->resizeColumnToContents(0); disasm_ui.treeView->resizeColumnToContents(1); disasm_ui.treeView->resizeColumnToContents(2); - QModelIndex model_index = model->IndexFromAbsoluteAddress(Core::AppCore().GetPC()); + QModelIndex model_index = model->IndexFromAbsoluteAddress(Core::CPU().GetPC()); disasm_ui.treeView->scrollTo(model_index); disasm_ui.treeView->selectionModel()->setCurrentIndex( model_index, QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows); @@ -215,7 +215,7 @@ void DisassemblerWidget::OnPause() { // TODO: By now, the CPU might not have actually stopped... if (Core::System::GetInstance().IsPoweredOn()) { - model->SetNextInstruction(Core::AppCore().GetPC()); + model->SetNextInstruction(Core::CPU().GetPC()); } } @@ -224,7 +224,7 @@ void DisassemblerWidget::OnToggleStartStop() { } void DisassemblerWidget::OnDebugModeEntered() { - u32 next_instr = Core::AppCore().GetPC(); + u32 next_instr = Core::CPU().GetPC(); if (model->GetBreakPoints().IsAddressBreakPoint(next_instr)) emu_thread->SetRunning(false); diff --git a/src/citra_qt/debugger/registers.cpp b/src/citra_qt/debugger/registers.cpp index d5b6542bd1..b982bc58b8 100644 --- a/src/citra_qt/debugger/registers.cpp +++ b/src/citra_qt/debugger/registers.cpp @@ -63,11 +63,11 @@ void RegistersWidget::OnDebugModeEntered() { for (int i = 0; i < core_registers->childCount(); ++i) core_registers->child(i)->setText( - 1, QString("0x%1").arg(Core::AppCore().GetReg(i), 8, 16, QLatin1Char('0'))); + 1, QString("0x%1").arg(Core::CPU().GetReg(i), 8, 16, QLatin1Char('0'))); for (int i = 0; i < vfp_registers->childCount(); ++i) vfp_registers->child(i)->setText( - 1, QString("0x%1").arg(Core::AppCore().GetVFPReg(i), 8, 16, QLatin1Char('0'))); + 1, QString("0x%1").arg(Core::CPU().GetVFPReg(i), 8, 16, QLatin1Char('0'))); UpdateCPSRValues(); UpdateVFPSystemRegisterValues(); @@ -127,7 +127,7 @@ void RegistersWidget::CreateCPSRChildren() { } void RegistersWidget::UpdateCPSRValues() { - const u32 cpsr_val = Core::AppCore().GetCPSR(); + const u32 cpsr_val = Core::CPU().GetCPSR(); cpsr->setText(1, QString("0x%1").arg(cpsr_val, 8, 16, QLatin1Char('0'))); cpsr->child(0)->setText( @@ -191,10 +191,10 @@ void RegistersWidget::CreateVFPSystemRegisterChildren() { } void RegistersWidget::UpdateVFPSystemRegisterValues() { - const u32 fpscr_val = Core::AppCore().GetVFPSystemReg(VFP_FPSCR); - const u32 fpexc_val = Core::AppCore().GetVFPSystemReg(VFP_FPEXC); - const u32 fpinst_val = Core::AppCore().GetVFPSystemReg(VFP_FPINST); - const u32 fpinst2_val = Core::AppCore().GetVFPSystemReg(VFP_FPINST2); + const u32 fpscr_val = Core::CPU().GetVFPSystemReg(VFP_FPSCR); + const u32 fpexc_val = Core::CPU().GetVFPSystemReg(VFP_FPEXC); + const u32 fpinst_val = Core::CPU().GetVFPSystemReg(VFP_FPINST); + const u32 fpinst2_val = Core::CPU().GetVFPSystemReg(VFP_FPINST2); QTreeWidgetItem* const fpscr = vfp_system_registers->child(0); fpscr->setText(1, QString("0x%1").arg(fpscr_val, 8, 16, QLatin1Char('0'))); diff --git a/src/core/core.cpp b/src/core/core.cpp index fabd3f42a4..ee52370961 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -26,7 +26,7 @@ namespace Core { /*static*/ System System::s_instance; System::ResultStatus System::RunLoop(int tight_loop) { - if (!app_core) { + if (!cpu_core) { return ResultStatus::ErrorNotInitialized; } @@ -53,7 +53,7 @@ System::ResultStatus System::RunLoop(int tight_loop) { CoreTiming::Advance(); PrepareReschedule(); } else { - app_core->Run(tight_loop); + cpu_core->Run(tight_loop); } HW::Update(); @@ -109,7 +109,7 @@ System::ResultStatus System::Load(EmuWindow* emu_window, const std::string& file } void System::PrepareReschedule() { - app_core->PrepareReschedule(); + cpu_core->PrepareReschedule(); reschedule_pending = true; } @@ -123,16 +123,16 @@ void System::Reschedule() { } System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) { - if (app_core) { - app_core.reset(); + if (cpu_core) { + cpu_core.reset(); } Memory::Init(); if (Settings::values.use_cpu_jit) { - app_core = std::make_unique(USER32MODE); + cpu_core = std::make_unique(USER32MODE); } else { - app_core = std::make_unique(USER32MODE); + cpu_core = std::make_unique(USER32MODE); } CoreTiming::Init(); diff --git a/src/core/core.h b/src/core/core.h index 728c24c1c5..b0f8df4418 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -88,18 +88,18 @@ public: * @returns True if the emulated system is powered on, otherwise false. */ bool IsPoweredOn() const { - return app_core != nullptr; + return cpu_core != nullptr; } /// Prepare the core emulation for a reschedule void PrepareReschedule(); /** - * Gets a reference to the emulated AppCore CPU. - * @returns A reference to the emulated AppCore CPU. + * Gets a reference to the emulated CPU. + * @returns A reference to the emulated CPU. */ - ARM_Interface& AppCore() { - return *app_core; + ARM_Interface& CPU() { + return *cpu_core; } private: @@ -117,8 +117,8 @@ private: /// AppLoader used to load the current executing application std::unique_ptr app_loader; - ///< ARM11 application core - std::unique_ptr app_core; + ///< ARM11 CPU core + std::unique_ptr cpu_core; /// When true, signals that a reschedule should happen bool reschedule_pending{}; @@ -126,8 +126,8 @@ private: static System s_instance; }; -static ARM_Interface& AppCore() { - return System::GetInstance().AppCore(); +static ARM_Interface& CPU() { + return System::GetInstance().CPU(); } } // namespace Core diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp index 9fe3747952..a437d08233 100644 --- a/src/core/core_timing.cpp +++ b/src/core/core_timing.cpp @@ -146,7 +146,7 @@ void UnregisterAllEvents() { } void Init() { - Core::AppCore().down_count = INITIAL_SLICE_LENGTH; + Core::CPU().down_count = INITIAL_SLICE_LENGTH; g_slice_length = INITIAL_SLICE_LENGTH; global_timer = 0; idled_cycles = 0; @@ -186,7 +186,7 @@ void Shutdown() { } u64 GetTicks() { - return (u64)global_timer + g_slice_length - Core::AppCore().down_count; + return (u64)global_timer + g_slice_length - Core::CPU().down_count; } u64 GetIdleTicks() { @@ -460,18 +460,18 @@ void MoveEvents() { } void ForceCheck() { - s64 cycles_executed = g_slice_length - Core::AppCore().down_count; + s64 cycles_executed = g_slice_length - Core::CPU().down_count; global_timer += cycles_executed; // This will cause us to check for new events immediately. - Core::AppCore().down_count = 0; + Core::CPU().down_count = 0; // But let's not eat a bunch more time in Advance() because of this. g_slice_length = 0; } void Advance() { - s64 cycles_executed = g_slice_length - Core::AppCore().down_count; + s64 cycles_executed = g_slice_length - Core::CPU().down_count; global_timer += cycles_executed; - Core::AppCore().down_count = g_slice_length; + Core::CPU().down_count = g_slice_length; if (has_ts_events) MoveEvents(); @@ -480,7 +480,7 @@ void Advance() { if (!first) { if (g_slice_length < 10000) { g_slice_length += 10000; - Core::AppCore().down_count += g_slice_length; + Core::CPU().down_count += g_slice_length; } } else { // Note that events can eat cycles as well. @@ -490,7 +490,7 @@ void Advance() { const int diff = target - g_slice_length; g_slice_length += diff; - Core::AppCore().down_count += diff; + Core::CPU().down_count += diff; } if (advance_callback) advance_callback(static_cast(cycles_executed)); @@ -506,12 +506,12 @@ void LogPendingEvents() { } void Idle(int max_idle) { - s64 cycles_down = Core::AppCore().down_count; + s64 cycles_down = Core::CPU().down_count; if (max_idle != 0 && cycles_down > max_idle) cycles_down = max_idle; if (first && cycles_down > 0) { - s64 cycles_executed = g_slice_length - Core::AppCore().down_count; + s64 cycles_executed = g_slice_length - Core::CPU().down_count; s64 cycles_next_event = first->time - global_timer; if (cycles_next_event < cycles_executed + cycles_down) { @@ -526,9 +526,9 @@ void Idle(int max_idle) { cycles_down / (float)(g_clock_rate_arm11 * 0.001f)); idled_cycles += cycles_down; - Core::AppCore().down_count -= cycles_down; - if (Core::AppCore().down_count == 0) - Core::AppCore().down_count = -1; + Core::CPU().down_count -= cycles_down; + if (Core::CPU().down_count == 0) + Core::CPU().down_count = -1; } std::string GetScheduledEventsSummary() { diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index c75d5fc5e2..d88e25073a 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp @@ -450,9 +450,9 @@ static void SendSignal(u32 signal) { latest_signal = signal; - std::string buffer = Common::StringFromFormat("T%02x%02x:%08x;%02x:%08x;", latest_signal, 15, - htonl(Core::AppCore().GetPC()), 13, - htonl(Core::AppCore().GetReg(13))); + std::string buffer = + Common::StringFromFormat("T%02x%02x:%08x;%02x:%08x;", latest_signal, 15, + htonl(Core::CPU().GetPC()), 13, htonl(Core::CPU().GetReg(13))); LOG_DEBUG(Debug_GDBStub, "Response: %s", buffer.c_str()); SendReply(buffer.c_str()); } @@ -539,15 +539,15 @@ static void ReadRegister() { } if (id <= R15_REGISTER) { - IntToGdbHex(reply, Core::AppCore().GetReg(id)); + IntToGdbHex(reply, Core::CPU().GetReg(id)); } else if (id == CPSR_REGISTER) { - IntToGdbHex(reply, Core::AppCore().GetCPSR()); + IntToGdbHex(reply, Core::CPU().GetCPSR()); } else if (id > CPSR_REGISTER && id < FPSCR_REGISTER) { - IntToGdbHex(reply, Core::AppCore().GetVFPReg( + IntToGdbHex(reply, Core::CPU().GetVFPReg( id - CPSR_REGISTER - 1)); // VFP registers should start at 26, so one after CSPR_REGISTER } else if (id == FPSCR_REGISTER) { - IntToGdbHex(reply, Core::AppCore().GetVFPSystemReg(VFP_FPSCR)); // Get FPSCR + IntToGdbHex(reply, Core::CPU().GetVFPSystemReg(VFP_FPSCR)); // Get FPSCR IntToGdbHex(reply + 8, 0); } else { return SendReply("E01"); @@ -564,22 +564,22 @@ static void ReadRegisters() { u8* bufptr = buffer; for (int reg = 0; reg <= R15_REGISTER; reg++) { - IntToGdbHex(bufptr + reg * CHAR_BIT, Core::AppCore().GetReg(reg)); + IntToGdbHex(bufptr + reg * CHAR_BIT, Core::CPU().GetReg(reg)); } bufptr += (16 * CHAR_BIT); - IntToGdbHex(bufptr, Core::AppCore().GetCPSR()); + IntToGdbHex(bufptr, Core::CPU().GetCPSR()); bufptr += CHAR_BIT; for (int reg = 0; reg <= 31; reg++) { - IntToGdbHex(bufptr + reg * CHAR_BIT, Core::AppCore().GetVFPReg(reg)); + IntToGdbHex(bufptr + reg * CHAR_BIT, Core::CPU().GetVFPReg(reg)); } bufptr += (32 * CHAR_BIT); - IntToGdbHex(bufptr, Core::AppCore().GetVFPSystemReg(VFP_FPSCR)); + IntToGdbHex(bufptr, Core::CPU().GetVFPSystemReg(VFP_FPSCR)); SendReply(reinterpret_cast(buffer)); } @@ -596,13 +596,13 @@ static void WriteRegister() { } if (id <= R15_REGISTER) { - Core::AppCore().SetReg(id, GdbHexToInt(buffer_ptr)); + Core::CPU().SetReg(id, GdbHexToInt(buffer_ptr)); } else if (id == CPSR_REGISTER) { - Core::AppCore().SetCPSR(GdbHexToInt(buffer_ptr)); + Core::CPU().SetCPSR(GdbHexToInt(buffer_ptr)); } else if (id > CPSR_REGISTER && id < FPSCR_REGISTER) { - Core::AppCore().SetVFPReg(id - CPSR_REGISTER - 1, GdbHexToInt(buffer_ptr)); + Core::CPU().SetVFPReg(id - CPSR_REGISTER - 1, GdbHexToInt(buffer_ptr)); } else if (id == FPSCR_REGISTER) { - Core::AppCore().SetVFPSystemReg(VFP_FPSCR, GdbHexToInt(buffer_ptr)); + Core::CPU().SetVFPSystemReg(VFP_FPSCR, GdbHexToInt(buffer_ptr)); } else { return SendReply("E01"); } @@ -619,20 +619,19 @@ static void WriteRegisters() { for (int i = 0, reg = 0; reg <= FPSCR_REGISTER; i++, reg++) { if (reg <= R15_REGISTER) { - Core::AppCore().SetReg(reg, GdbHexToInt(buffer_ptr + i * CHAR_BIT)); + Core::CPU().SetReg(reg, GdbHexToInt(buffer_ptr + i * CHAR_BIT)); } else if (reg == CPSR_REGISTER) { - Core::AppCore().SetCPSR(GdbHexToInt(buffer_ptr + i * CHAR_BIT)); + Core::CPU().SetCPSR(GdbHexToInt(buffer_ptr + i * CHAR_BIT)); } else if (reg == CPSR_REGISTER - 1) { // Dummy FPA register, ignore } else if (reg < CPSR_REGISTER) { // Dummy FPA registers, ignore i += 2; } else if (reg > CPSR_REGISTER && reg < FPSCR_REGISTER) { - Core::AppCore().SetVFPReg(reg - CPSR_REGISTER - 1, - GdbHexToInt(buffer_ptr + i * CHAR_BIT)); + Core::CPU().SetVFPReg(reg - CPSR_REGISTER - 1, GdbHexToInt(buffer_ptr + i * CHAR_BIT)); i++; // Skip padding } else if (reg == FPSCR_REGISTER) { - Core::AppCore().SetVFPSystemReg(VFP_FPSCR, GdbHexToInt(buffer_ptr + i * CHAR_BIT)); + Core::CPU().SetVFPSystemReg(VFP_FPSCR, GdbHexToInt(buffer_ptr + i * CHAR_BIT)); } } diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/function_wrappers.h index cafc7fe62a..7875971ce3 100644 --- a/src/core/hle/function_wrappers.h +++ b/src/core/hle/function_wrappers.h @@ -14,7 +14,7 @@ namespace HLE { -#define PARAM(n) Core::AppCore().GetReg(n) +#define PARAM(n) Core::CPU().GetReg(n) /// An invalid result code that is meant to be overwritten when a thread resumes from waiting static const ResultCode RESULT_INVALID(0xDEADC0DE); @@ -24,7 +24,7 @@ static const ResultCode RESULT_INVALID(0xDEADC0DE); * @param res Result to return */ static inline void FuncReturn(u32 res) { - Core::AppCore().SetReg(0, res); + Core::CPU().SetReg(0, res); } /** @@ -33,8 +33,8 @@ static inline void FuncReturn(u32 res) { * @todo Verify that this function is correct */ static inline void FuncReturn64(u64 res) { - Core::AppCore().SetReg(0, (u32)(res & 0xFFFFFFFF)); - Core::AppCore().SetReg(1, (u32)((res >> 32) & 0xFFFFFFFF)); + Core::CPU().SetReg(0, (u32)(res & 0xFFFFFFFF)); + Core::CPU().SetReg(1, (u32)((res >> 32) & 0xFFFFFFFF)); } //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -49,7 +49,7 @@ template void Wrap() { u32 param_1 = 0; u32 retval = func(¶m_1, PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)).raw; - Core::AppCore().SetReg(1, param_1); + Core::CPU().SetReg(1, param_1); FuncReturn(retval); } @@ -57,7 +57,7 @@ template void Wrap() { u32 param_1 = 0; u32 retval = func(¶m_1, PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)).raw; - Core::AppCore().SetReg(1, param_1); + Core::CPU().SetReg(1, param_1); FuncReturn(retval); } @@ -69,7 +69,7 @@ void Wrap() { .raw; if (retval != RESULT_INVALID.raw) { - Core::AppCore().SetReg(1, (u32)param_1); + Core::CPU().SetReg(1, (u32)param_1); FuncReturn(retval); } } @@ -84,7 +84,7 @@ template void Wrap() { u32 param_1 = 0; u32 retval = func(¶m_1).raw; - Core::AppCore().SetReg(1, param_1); + Core::CPU().SetReg(1, param_1); FuncReturn(retval); } @@ -102,11 +102,11 @@ void Wrap() { MemoryInfo memory_info = {}; PageInfo page_info = {}; u32 retval = func(&memory_info, &page_info, PARAM(2)).raw; - Core::AppCore().SetReg(1, memory_info.base_address); - Core::AppCore().SetReg(2, memory_info.size); - Core::AppCore().SetReg(3, memory_info.permission); - Core::AppCore().SetReg(4, memory_info.state); - Core::AppCore().SetReg(5, page_info.flags); + Core::CPU().SetReg(1, memory_info.base_address); + Core::CPU().SetReg(2, memory_info.size); + Core::CPU().SetReg(3, memory_info.permission); + Core::CPU().SetReg(4, memory_info.state); + Core::CPU().SetReg(5, page_info.flags); FuncReturn(retval); } @@ -115,11 +115,11 @@ void Wrap() { MemoryInfo memory_info = {}; PageInfo page_info = {}; u32 retval = func(&memory_info, &page_info, PARAM(2), PARAM(3)).raw; - Core::AppCore().SetReg(1, memory_info.base_address); - Core::AppCore().SetReg(2, memory_info.size); - Core::AppCore().SetReg(3, memory_info.permission); - Core::AppCore().SetReg(4, memory_info.state); - Core::AppCore().SetReg(5, page_info.flags); + Core::CPU().SetReg(1, memory_info.base_address); + Core::CPU().SetReg(2, memory_info.size); + Core::CPU().SetReg(3, memory_info.permission); + Core::CPU().SetReg(4, memory_info.state); + Core::CPU().SetReg(5, page_info.flags); FuncReturn(retval); } @@ -127,7 +127,7 @@ template void Wrap() { s32 param_1 = 0; u32 retval = func(¶m_1, PARAM(1)).raw; - Core::AppCore().SetReg(1, param_1); + Core::CPU().SetReg(1, param_1); FuncReturn(retval); } @@ -140,7 +140,7 @@ template void Wrap() { u32 param_1 = 0; u32 retval = func(¶m_1, PARAM(1)).raw; - Core::AppCore().SetReg(1, param_1); + Core::CPU().SetReg(1, param_1); FuncReturn(retval); } @@ -160,7 +160,7 @@ template void Wrap() { u32 param_1 = 0; u32 retval = func(¶m_1, (char*)Memory::GetPointer(PARAM(1))).raw; - Core::AppCore().SetReg(1, param_1); + Core::CPU().SetReg(1, param_1); FuncReturn(retval); } @@ -168,7 +168,7 @@ template void Wrap() { u32 param_1 = 0; u32 retval = func(¶m_1, PARAM(1), PARAM(2)).raw; - Core::AppCore().SetReg(1, param_1); + Core::CPU().SetReg(1, param_1); FuncReturn(retval); } @@ -176,7 +176,7 @@ template void Wrap() { s32 param_1 = 0; u32 retval = func(¶m_1, PARAM(1), PARAM(2)).raw; - Core::AppCore().SetReg(1, param_1); + Core::CPU().SetReg(1, param_1); FuncReturn(retval); } @@ -184,8 +184,8 @@ template void Wrap() { s64 param_1 = 0; u32 retval = func(¶m_1, PARAM(1), PARAM(2)).raw; - Core::AppCore().SetReg(1, (u32)param_1); - Core::AppCore().SetReg(2, (u32)(param_1 >> 32)); + Core::CPU().SetReg(1, (u32)param_1); + Core::CPU().SetReg(2, (u32)(param_1 >> 32)); FuncReturn(retval); } @@ -194,7 +194,7 @@ void Wrap() { u32 param_1 = 0; // The last parameter is passed in R0 instead of R4 u32 retval = func(¶m_1, PARAM(1), PARAM(2), PARAM(3), PARAM(0)).raw; - Core::AppCore().SetReg(1, param_1); + Core::CPU().SetReg(1, param_1); FuncReturn(retval); } @@ -209,8 +209,8 @@ template void Wrap() { s64 param_1 = 0; u32 retval = func(¶m_1, PARAM(1), PARAM(2)).raw; - Core::AppCore().SetReg(1, (u32)param_1); - Core::AppCore().SetReg(2, (u32)(param_1 >> 32)); + Core::CPU().SetReg(1, (u32)param_1); + Core::CPU().SetReg(2, (u32)(param_1 >> 32)); FuncReturn(retval); } @@ -227,8 +227,8 @@ void Wrap() { reinterpret_cast(Memory::GetPointer(PARAM(2))), PARAM(3)) .raw; // The first out parameter is moved into R2 and the second is moved into R1. - Core::AppCore().SetReg(1, param_2); - Core::AppCore().SetReg(2, param_1); + Core::CPU().SetReg(1, param_2); + Core::CPU().SetReg(2, param_1); FuncReturn(retval); } diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index c964b35d4d..60b7bea702 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -187,7 +187,7 @@ static void SwitchContext(Thread* new_thread) { // Save context for previous thread if (previous_thread) { previous_thread->last_running_ticks = CoreTiming::GetTicks(); - Core::AppCore().SaveContext(previous_thread->context); + Core::CPU().SaveContext(previous_thread->context); if (previous_thread->status == THREADSTATUS_RUNNING) { // This is only the case when a reschedule is triggered without the current thread @@ -213,8 +213,8 @@ static void SwitchContext(Thread* new_thread) { // Restores thread to its nominal priority if it has been temporarily changed new_thread->current_priority = new_thread->nominal_priority; - Core::AppCore().LoadContext(new_thread->context); - Core::AppCore().SetCP15Register(CP15_THREAD_URO, new_thread->GetTLSAddress()); + Core::CPU().LoadContext(new_thread->context); + Core::CPU().SetCP15Register(CP15_THREAD_URO, new_thread->GetTLSAddress()); } else { current_thread = nullptr; } diff --git a/src/core/hle/service/ldr_ro/ldr_ro.cpp b/src/core/hle/service/ldr_ro/ldr_ro.cpp index 614f16d448..8d00a75778 100644 --- a/src/core/hle/service/ldr_ro/ldr_ro.cpp +++ b/src/core/hle/service/ldr_ro/ldr_ro.cpp @@ -457,7 +457,7 @@ static void LoadCRO(Interface* self, bool link_on_load_bug_fix) { } } - Core::AppCore().ClearInstructionCache(); + Core::CPU().ClearInstructionCache(); LOG_INFO(Service_LDR, "CRO \"%s\" loaded at 0x%08X, fixed_end=0x%08X", cro.ModuleName().data(), cro_address, cro_address + fix_size); @@ -562,7 +562,7 @@ static void UnloadCRO(Interface* self) { memory_synchronizer.RemoveMemoryBlock(cro_address, cro_buffer_ptr); } - Core::AppCore().ClearInstructionCache(); + Core::CPU().ClearInstructionCache(); cmd_buff[1] = result.raw; } @@ -624,7 +624,7 @@ static void LinkCRO(Interface* self) { } memory_synchronizer.SynchronizeOriginalMemory(); - Core::AppCore().ClearInstructionCache(); + Core::CPU().ClearInstructionCache(); cmd_buff[1] = result.raw; } @@ -686,7 +686,7 @@ static void UnlinkCRO(Interface* self) { } memory_synchronizer.SynchronizeOriginalMemory(); - Core::AppCore().ClearInstructionCache(); + Core::CPU().ClearInstructionCache(); cmd_buff[1] = result.raw; } diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 1f89ccfd54..2ca270de3d 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -583,7 +583,7 @@ static ResultCode CreateThread(Kernel::Handle* out_handle, s32 priority, u32 ent /// Called when a thread exits static void ExitThread() { - LOG_TRACE(Kernel_SVC, "called, pc=0x%08X", Core::AppCore().GetPC()); + LOG_TRACE(Kernel_SVC, "called, pc=0x%08X", Core::CPU().GetPC()); Kernel::ExitCurrentThread(); } @@ -613,7 +613,7 @@ static ResultCode CreateMutex(Kernel::Handle* out_handle, u32 initial_locked) { using Kernel::Mutex; SharedPtr mutex = Mutex::Create(initial_locked != 0); - mutex->name = Common::StringFromFormat("mutex-%08x", Core::AppCore().GetReg(14)); + mutex->name = Common::StringFromFormat("mutex-%08x", Core::CPU().GetReg(14)); CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(mutex))); LOG_TRACE(Kernel_SVC, "called initial_locked=%s : created handle=0x%08X", @@ -684,7 +684,7 @@ static ResultCode CreateSemaphore(Kernel::Handle* out_handle, s32 initial_count, using Kernel::Semaphore; CASCADE_RESULT(SharedPtr semaphore, Semaphore::Create(initial_count, max_count)); - semaphore->name = Common::StringFromFormat("semaphore-%08x", Core::AppCore().GetReg(14)); + semaphore->name = Common::StringFromFormat("semaphore-%08x", Core::CPU().GetReg(14)); CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(semaphore))); LOG_TRACE(Kernel_SVC, "called initial_count=%d, max_count=%d, created handle=0x%08X", @@ -741,7 +741,7 @@ static ResultCode CreateEvent(Kernel::Handle* out_handle, u32 reset_type) { using Kernel::Event; SharedPtr evt = Event::Create(static_cast(reset_type)); - evt->name = Common::StringFromFormat("event-%08x", Core::AppCore().GetReg(14)); + evt->name = Common::StringFromFormat("event-%08x", Core::CPU().GetReg(14)); CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(evt))); LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", reset_type, @@ -788,7 +788,7 @@ static ResultCode CreateTimer(Kernel::Handle* out_handle, u32 reset_type) { using Kernel::Timer; SharedPtr timer = Timer::Create(static_cast(reset_type)); - timer->name = Common::StringFromFormat("timer-%08x", Core::AppCore().GetReg(14)); + timer->name = Common::StringFromFormat("timer-%08x", Core::CPU().GetReg(14)); CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(timer))); LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", reset_type, @@ -855,8 +855,7 @@ static void SleepThread(s64 nanoseconds) { static s64 GetSystemTick() { s64 result = CoreTiming::GetTicks(); // Advance time to defeat dumb games (like Cubic Ninja) that busy-wait for the frame to end. - Core::AppCore().AddTicks( - 150); // Measured time between two calls on a 9.2 o3DS with Ninjhax 1.1b + Core::CPU().AddTicks(150); // Measured time between two calls on a 9.2 o3DS with Ninjhax 1.1b return result; } From 8b1e269e5898ad0b6aadabee41fea777f0e62fdc Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 22 Dec 2016 00:08:09 -0500 Subject: [PATCH 8/8] ThreadContext: Move from "core" to "arm_interface". --- src/core/arm/arm_interface.h | 19 +++++++++++++------ src/core/arm/dynarmic/arm_dynarmic.cpp | 4 ++-- src/core/arm/dynarmic/arm_dynarmic.h | 8 ++------ src/core/arm/dyncom/arm_dyncom.cpp | 4 ++-- src/core/arm/dyncom/arm_dyncom.h | 8 ++------ src/core/core.h | 11 ----------- src/core/hle/kernel/thread.cpp | 6 +++--- src/core/hle/kernel/thread.h | 3 ++- 8 files changed, 26 insertions(+), 37 deletions(-) diff --git a/src/core/arm/arm_interface.h b/src/core/arm/arm_interface.h index e466b21b2d..ccd43f4314 100644 --- a/src/core/arm/arm_interface.h +++ b/src/core/arm/arm_interface.h @@ -8,15 +8,22 @@ #include "core/arm/skyeye_common/arm_regformat.h" #include "core/arm/skyeye_common/vfp/asm_vfp.h" -namespace Core { -struct ThreadContext; -} - /// Generic ARM11 CPU interface class ARM_Interface : NonCopyable { public: virtual ~ARM_Interface() {} + struct ThreadContext { + u32 cpu_registers[13]; + u32 sp; + u32 lr; + u32 pc; + u32 cpsr; + u32 fpu_registers[64]; + u32 fpscr; + u32 fpexc; + }; + /** * Runs the CPU for the given number of instructions * @param num_instructions Number of instructions to run @@ -124,13 +131,13 @@ public: * Saves the current CPU context * @param ctx Thread context to save */ - virtual void SaveContext(Core::ThreadContext& ctx) = 0; + virtual void SaveContext(ThreadContext& ctx) = 0; /** * Loads a CPU context * @param ctx Thread context to load */ - virtual void LoadContext(const Core::ThreadContext& ctx) = 0; + virtual void LoadContext(const ThreadContext& ctx) = 0; /// Prepare core for thread reschedule (if needed to correctly handle state) virtual void PrepareReschedule() = 0; diff --git a/src/core/arm/dynarmic/arm_dynarmic.cpp b/src/core/arm/dynarmic/arm_dynarmic.cpp index fc4254670e..5290382ff4 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic.cpp @@ -137,7 +137,7 @@ void ARM_Dynarmic::ExecuteInstructions(int num_instructions) { AddTicks(ticks_executed); } -void ARM_Dynarmic::SaveContext(Core::ThreadContext& ctx) { +void ARM_Dynarmic::SaveContext(ARM_Interface::ThreadContext& ctx) { memcpy(ctx.cpu_registers, jit->Regs().data(), sizeof(ctx.cpu_registers)); memcpy(ctx.fpu_registers, jit->ExtRegs().data(), sizeof(ctx.fpu_registers)); @@ -150,7 +150,7 @@ void ARM_Dynarmic::SaveContext(Core::ThreadContext& ctx) { ctx.fpexc = interpreter_state->VFP[VFP_FPEXC]; } -void ARM_Dynarmic::LoadContext(const Core::ThreadContext& ctx) { +void ARM_Dynarmic::LoadContext(const ARM_Interface::ThreadContext& ctx) { memcpy(jit->Regs().data(), ctx.cpu_registers, sizeof(ctx.cpu_registers)); memcpy(jit->ExtRegs().data(), ctx.fpu_registers, sizeof(ctx.fpu_registers)); diff --git a/src/core/arm/dynarmic/arm_dynarmic.h b/src/core/arm/dynarmic/arm_dynarmic.h index ced86d29b0..87ab53d81c 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.h +++ b/src/core/arm/dynarmic/arm_dynarmic.h @@ -10,10 +10,6 @@ #include "core/arm/arm_interface.h" #include "core/arm/skyeye_common/armstate.h" -namespace Core { -struct ThreadContext; -} - class ARM_Dynarmic final : public ARM_Interface { public: ARM_Dynarmic(PrivilegeMode initial_mode); @@ -33,8 +29,8 @@ public: void AddTicks(u64 ticks) override; - void SaveContext(Core::ThreadContext& ctx) override; - void LoadContext(const Core::ThreadContext& ctx) override; + void SaveContext(ThreadContext& ctx) override; + void LoadContext(const ThreadContext& ctx) override; void PrepareReschedule() override; void ExecuteInstructions(int num_instructions) override; diff --git a/src/core/arm/dyncom/arm_dyncom.cpp b/src/core/arm/dyncom/arm_dyncom.cpp index 34c7f945ec..81f9bf99e0 100644 --- a/src/core/arm/dyncom/arm_dyncom.cpp +++ b/src/core/arm/dyncom/arm_dyncom.cpp @@ -89,7 +89,7 @@ void ARM_DynCom::ExecuteInstructions(int num_instructions) { AddTicks(ticks_executed); } -void ARM_DynCom::SaveContext(Core::ThreadContext& ctx) { +void ARM_DynCom::SaveContext(ThreadContext& ctx) { memcpy(ctx.cpu_registers, state->Reg.data(), sizeof(ctx.cpu_registers)); memcpy(ctx.fpu_registers, state->ExtReg.data(), sizeof(ctx.fpu_registers)); @@ -102,7 +102,7 @@ void ARM_DynCom::SaveContext(Core::ThreadContext& ctx) { ctx.fpexc = state->VFP[VFP_FPEXC]; } -void ARM_DynCom::LoadContext(const Core::ThreadContext& ctx) { +void ARM_DynCom::LoadContext(const ThreadContext& ctx) { memcpy(state->Reg.data(), ctx.cpu_registers, sizeof(ctx.cpu_registers)); memcpy(state->ExtReg.data(), ctx.fpu_registers, sizeof(ctx.fpu_registers)); diff --git a/src/core/arm/dyncom/arm_dyncom.h b/src/core/arm/dyncom/arm_dyncom.h index 65db1f0f9b..62c174f3ce 100644 --- a/src/core/arm/dyncom/arm_dyncom.h +++ b/src/core/arm/dyncom/arm_dyncom.h @@ -10,10 +10,6 @@ #include "core/arm/skyeye_common/arm_regformat.h" #include "core/arm/skyeye_common/armstate.h" -namespace Core { -struct ThreadContext; -} - class ARM_DynCom final : public ARM_Interface { public: ARM_DynCom(PrivilegeMode initial_mode); @@ -36,8 +32,8 @@ public: void AddTicks(u64 ticks) override; - void SaveContext(Core::ThreadContext& ctx) override; - void LoadContext(const Core::ThreadContext& ctx) override; + void SaveContext(ThreadContext& ctx) override; + void LoadContext(const ThreadContext& ctx) override; void PrepareReschedule() override; void ExecuteInstructions(int num_instructions) override; diff --git a/src/core/core.h b/src/core/core.h index b0f8df4418..1015e8847f 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -19,17 +19,6 @@ class AppLoader; namespace Core { -struct ThreadContext { - u32 cpu_registers[13]; - u32 sp; - u32 lr; - u32 pc; - u32 cpsr; - u32 fpu_registers[64]; - u32 fpscr; - u32 fpexc; -}; - class System { public: /** diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 60b7bea702..5fb95dadaa 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -384,9 +384,9 @@ std::tuple GetFreeThreadLocalSlot(std::vector>& t * @param entry_point Address of entry point for execution * @param arg User argument for thread */ -static void ResetThreadContext(Core::ThreadContext& context, u32 stack_top, u32 entry_point, - u32 arg) { - memset(&context, 0, sizeof(Core::ThreadContext)); +static void ResetThreadContext(ARM_Interface::ThreadContext& context, u32 stack_top, + u32 entry_point, u32 arg) { + memset(&context, 0, sizeof(ARM_Interface::ThreadContext)); context.cpu_registers[0] = arg; context.pc = entry_point; diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index 89acc12c1b..c77ac644d5 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -10,6 +10,7 @@ #include #include #include "common/common_types.h" +#include "core/arm/arm_interface.h" #include "core/core.h" #include "core/hle/kernel/kernel.h" #include "core/hle/result.h" @@ -157,7 +158,7 @@ public: return !wait_objects.empty(); } - Core::ThreadContext context; + ARM_Interface::ThreadContext context; u32 thread_id;