Merge pull request #2343 from bunnei/core-cleanup

Core: Top-level consolidate & misc cleanup
This commit is contained in:
bunnei 2016-12-22 11:47:44 -05:00 • committed by GitHub
commit 37e91013ec
45 changed files with 435 additions and 591 deletions

View file

@ -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) {
@ -64,7 +63,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 +96,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 +114,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,32 +126,25 @@ int main(int argc, char** argv) {
Settings::values.use_gdbstub = use_gdbstub;
Settings::Apply();
std::unique_ptr<EmuWindow_SDL2> emu_window = std::make_unique<EmuWindow_SDL2>();
std::unique_ptr<EmuWindow_SDL2> emu_window{std::make_unique<EmuWindow_SDL2>()};
std::unique_ptr<Loader::AppLoader> 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<u32> 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;
}
while (emu_window->IsOpen()) {
Core::RunLoop();
system.RunLoop();
}
return 0;

View file

@ -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();
@ -60,7 +58,7 @@ void EmuThread::run() {
}
// Shutdown the core emulation
System::Shutdown();
Core::System::GetInstance().Shutdown();
#if MICROPROFILE_ENABLED
MicroProfileOnThreadExit();

View file

@ -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)
@ -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() {}

View file

@ -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)
@ -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() {}

View file

@ -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<int, 12> days_in_month = {{
@ -24,7 +23,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();

View file

@ -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::CPU().GetReg(13);
Clear();

View file

@ -185,13 +185,13 @@ DisassemblerWidget::DisassemblerWidget(QWidget* parent, EmuThread* emu_thread)
}
void DisassemblerWidget::Init() {
model->ParseFromAddress(Core::g_app_core->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::g_app_core->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);
@ -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::CPU().GetPC());
}
}
@ -224,7 +224,7 @@ void DisassemblerWidget::OnToggleStartStop() {
}
void DisassemblerWidget::OnDebugModeEntered() {
u32 next_instr = Core::g_app_core->GetPC();
u32 next_instr = Core::CPU().GetPC();
if (model->GetBreakPoints().IsAddressBreakPoint(next_instr))
emu_thread->SetRunning(false);

View file

@ -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::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::g_app_core->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::g_app_core->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::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::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')));

View file

@ -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);

View file

@ -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"
@ -274,7 +273,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();
@ -290,54 +289,25 @@ bool GMainWindow::InitializeSystem(u32 system_mode) {
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<Loader::AppLoader> 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<u32> 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);
@ -352,11 +322,10 @@ bool GMainWindow::LoadROM(const std::string& filename) {
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."));
break;
case Loader::ResultStatus::Error:
default:
QMessageBox::critical(this, tr("Error while loading ROM!"), tr("Unknown error!"));

View file

@ -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"

View file

@ -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;
}
}

View file

@ -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
};

View file

@ -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
@ -155,7 +154,6 @@ set(SRCS
tracer/recorder.cpp
memory.cpp
settings.cpp
system.cpp
)
set(HEADERS
@ -196,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
@ -325,7 +322,6 @@ set(HEADERS
memory_setup.h
mmio.h
settings.h
system.h
)
include_directories(../../externals/dynarmic/include)

View file

@ -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;

View file

@ -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));

View file

@ -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;

View file

@ -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));

View file

@ -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;

View file

@ -3,6 +3,8 @@
// Refer to the license.txt file included.
#include <memory>
#include "audio_core/audio_core.h"
#include "common/logging/log.h"
#include "core/arm/arm_interface.h"
#include "core/arm/dynarmic/arm_dynarmic.h"
@ -10,18 +12,24 @@
#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"
#include "video_core/video_core.h"
namespace Core {
std::unique_ptr<ARM_Interface> g_app_core; ///< ARM11 application core
std::unique_ptr<ARM_Interface> g_sys_core; ///< ARM11 system (OS) core
/*static*/ System System::s_instance;
System::ResultStatus System::RunLoop(int tight_loop) {
if (!cpu_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;
}
}
}
@ -43,48 +51,114 @@ void RunLoop(int tight_loop) {
LOG_TRACE(Core_ARM11, "Idling");
CoreTiming::Idle();
CoreTiming::Advance();
HLE::Reschedule(__func__);
PrepareReschedule();
} else {
g_app_core->Run(tight_loop);
cpu_core->Run(tight_loop);
}
HW::Update();
if (HLE::IsReschedulePending()) {
Kernel::Reschedule();
Reschedule();
return ResultStatus::Success;
}
System::ResultStatus System::SingleStep() {
return RunLoop(1);
}
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<u32> 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;
}
/// Step the CPU one instruction
void SingleStep() {
RunLoop(1);
void System::PrepareReschedule() {
cpu_core->PrepareReschedule();
reschedule_pending = true;
}
/// Halt the core
void Halt(const char* msg) {
// TODO(ShizZy): ImplementMe
void System::Reschedule() {
if (!reschedule_pending) {
return;
}
reschedule_pending = false;
Kernel::Reschedule();
}
/// Kill the core
void Stop() {
// TODO(ShizZy): ImplementMe
}
System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) {
if (cpu_core) {
cpu_core.reset();
}
Memory::Init();
/// Initialize the core
void Init() {
if (Settings::values.use_cpu_jit) {
g_sys_core = std::make_unique<ARM_Dynarmic>(USER32MODE);
g_app_core = std::make_unique<ARM_Dynarmic>(USER32MODE);
cpu_core = std::make_unique<ARM_Dynarmic>(USER32MODE);
} else {
g_sys_core = std::make_unique<ARM_DynCom>(USER32MODE);
g_app_core = std::make_unique<ARM_DynCom>(USER32MODE);
cpu_core = std::make_unique<ARM_DynCom>(USER32MODE);
}
CoreTiming::Init();
HW::Init();
Kernel::Init(system_mode);
Service::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();
Service::Shutdown();
Kernel::Shutdown();
HW::Shutdown();
CoreTiming::Shutdown();
LOG_DEBUG(Core, "Shutdown OK");
}

Some files were not shown because too many files have changed in this diff Show more