diff options
Diffstat (limited to 'src/core/core.cpp')
| -rw-r--r-- | src/core/core.cpp | 132 |
1 files changed, 103 insertions, 29 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp index 6efa18159..ee5237096 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp | |||
| @@ -3,6 +3,8 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <memory> | 5 | #include <memory> |
| 6 | |||
| 7 | #include "audio_core/audio_core.h" | ||
| 6 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| 7 | #include "core/arm/arm_interface.h" | 9 | #include "core/arm/arm_interface.h" |
| 8 | #include "core/arm/dynarmic/arm_dynarmic.h" | 10 | #include "core/arm/dynarmic/arm_dynarmic.h" |
| @@ -10,18 +12,24 @@ | |||
| 10 | #include "core/core.h" | 12 | #include "core/core.h" |
| 11 | #include "core/core_timing.h" | 13 | #include "core/core_timing.h" |
| 12 | #include "core/gdbstub/gdbstub.h" | 14 | #include "core/gdbstub/gdbstub.h" |
| 13 | #include "core/hle/hle.h" | 15 | #include "core/hle/kernel/kernel.h" |
| 16 | #include "core/hle/kernel/memory.h" | ||
| 14 | #include "core/hle/kernel/thread.h" | 17 | #include "core/hle/kernel/thread.h" |
| 18 | #include "core/hle/service/service.h" | ||
| 15 | #include "core/hw/hw.h" | 19 | #include "core/hw/hw.h" |
| 20 | #include "core/loader/loader.h" | ||
| 16 | #include "core/settings.h" | 21 | #include "core/settings.h" |
| 22 | #include "video_core/video_core.h" | ||
| 17 | 23 | ||
| 18 | namespace Core { | 24 | namespace Core { |
| 19 | 25 | ||
| 20 | std::unique_ptr<ARM_Interface> g_app_core; ///< ARM11 application core | 26 | /*static*/ System System::s_instance; |
| 21 | std::unique_ptr<ARM_Interface> g_sys_core; ///< ARM11 system (OS) core | 27 | |
| 28 | System::ResultStatus System::RunLoop(int tight_loop) { | ||
| 29 | if (!cpu_core) { | ||
| 30 | return ResultStatus::ErrorNotInitialized; | ||
| 31 | } | ||
| 22 | 32 | ||
| 23 | /// Run the core CPU loop | ||
| 24 | void RunLoop(int tight_loop) { | ||
| 25 | if (GDBStub::IsServerEnabled()) { | 33 | if (GDBStub::IsServerEnabled()) { |
| 26 | GDBStub::HandlePacket(); | 34 | GDBStub::HandlePacket(); |
| 27 | 35 | ||
| @@ -32,7 +40,7 @@ void RunLoop(int tight_loop) { | |||
| 32 | GDBStub::SetCpuStepFlag(false); | 40 | GDBStub::SetCpuStepFlag(false); |
| 33 | tight_loop = 1; | 41 | tight_loop = 1; |
| 34 | } else { | 42 | } else { |
| 35 | return; | 43 | return ResultStatus::Success; |
| 36 | } | 44 | } |
| 37 | } | 45 | } |
| 38 | } | 46 | } |
| @@ -43,48 +51,114 @@ void RunLoop(int tight_loop) { | |||
| 43 | LOG_TRACE(Core_ARM11, "Idling"); | 51 | LOG_TRACE(Core_ARM11, "Idling"); |
| 44 | CoreTiming::Idle(); | 52 | CoreTiming::Idle(); |
| 45 | CoreTiming::Advance(); | 53 | CoreTiming::Advance(); |
| 46 | HLE::Reschedule(__func__); | 54 | PrepareReschedule(); |
| 47 | } else { | 55 | } else { |
| 48 | g_app_core->Run(tight_loop); | 56 | cpu_core->Run(tight_loop); |
| 49 | } | 57 | } |
| 50 | 58 | ||
| 51 | HW::Update(); | 59 | HW::Update(); |
| 52 | if (HLE::IsReschedulePending()) { | 60 | Reschedule(); |
| 53 | Kernel::Reschedule(); | 61 | |
| 54 | } | 62 | return ResultStatus::Success; |
| 63 | } | ||
| 64 | |||
| 65 | System::ResultStatus System::SingleStep() { | ||
| 66 | return RunLoop(1); | ||
| 55 | } | 67 | } |
| 56 | 68 | ||
| 57 | /// Step the CPU one instruction | 69 | System::ResultStatus System::Load(EmuWindow* emu_window, const std::string& filepath) { |
| 58 | void SingleStep() { | 70 | if (app_loader) { |
| 59 | RunLoop(1); | 71 | app_loader.reset(); |
| 72 | } | ||
| 73 | |||
| 74 | app_loader = Loader::GetLoader(filepath); | ||
| 75 | |||
| 76 | if (!app_loader) { | ||
| 77 | LOG_CRITICAL(Core, "Failed to obtain loader for %s!", filepath.c_str()); | ||
| 78 | return ResultStatus::ErrorGetLoader; | ||
| 79 | } | ||
| 80 | |||
| 81 | boost::optional<u32> system_mode{app_loader->LoadKernelSystemMode()}; | ||
| 82 | if (!system_mode) { | ||
| 83 | LOG_CRITICAL(Core, "Failed to determine system mode!"); | ||
| 84 | return ResultStatus::ErrorSystemMode; | ||
| 85 | } | ||
| 86 | |||
| 87 | ResultStatus init_result{Init(emu_window, system_mode.get())}; | ||
| 88 | if (init_result != ResultStatus::Success) { | ||
| 89 | LOG_CRITICAL(Core, "Failed to initialize system (Error %i)!", init_result); | ||
| 90 | System::Shutdown(); | ||
| 91 | return init_result; | ||
| 92 | } | ||
| 93 | |||
| 94 | const Loader::ResultStatus load_result{app_loader->Load()}; | ||
| 95 | if (Loader::ResultStatus::Success != load_result) { | ||
| 96 | LOG_CRITICAL(Core, "Failed to load ROM (Error %i)!", load_result); | ||
| 97 | System::Shutdown(); | ||
| 98 | |||
| 99 | switch (load_result) { | ||
| 100 | case Loader::ResultStatus::ErrorEncrypted: | ||
| 101 | return ResultStatus::ErrorLoader_ErrorEncrypted; | ||
| 102 | case Loader::ResultStatus::ErrorInvalidFormat: | ||
| 103 | return ResultStatus::ErrorLoader_ErrorInvalidFormat; | ||
| 104 | default: | ||
| 105 | return ResultStatus::ErrorLoader; | ||
| 106 | } | ||
| 107 | } | ||
| 108 | return ResultStatus::Success; | ||
| 60 | } | 109 | } |
| 61 | 110 | ||
| 62 | /// Halt the core | 111 | void System::PrepareReschedule() { |
| 63 | void Halt(const char* msg) { | 112 | cpu_core->PrepareReschedule(); |
| 64 | // TODO(ShizZy): ImplementMe | 113 | reschedule_pending = true; |
| 65 | } | 114 | } |
| 66 | 115 | ||
| 67 | /// Kill the core | 116 | void System::Reschedule() { |
| 68 | void Stop() { | 117 | if (!reschedule_pending) { |
| 69 | // TODO(ShizZy): ImplementMe | 118 | return; |
| 119 | } | ||
| 120 | |||
| 121 | reschedule_pending = false; | ||
| 122 | Kernel::Reschedule(); | ||
| 70 | } | 123 | } |
| 71 | 124 | ||
| 72 | /// Initialize the core | 125 | System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) { |
| 73 | void Init() { | 126 | if (cpu_core) { |
| 127 | cpu_core.reset(); | ||
| 128 | } | ||
| 129 | |||
| 130 | Memory::Init(); | ||
| 131 | |||
| 74 | if (Settings::values.use_cpu_jit) { | 132 | if (Settings::values.use_cpu_jit) { |
| 75 | g_sys_core = std::make_unique<ARM_Dynarmic>(USER32MODE); | 133 | cpu_core = std::make_unique<ARM_Dynarmic>(USER32MODE); |
| 76 | g_app_core = std::make_unique<ARM_Dynarmic>(USER32MODE); | ||
| 77 | } else { | 134 | } else { |
| 78 | g_sys_core = std::make_unique<ARM_DynCom>(USER32MODE); | 135 | cpu_core = std::make_unique<ARM_DynCom>(USER32MODE); |
| 79 | g_app_core = std::make_unique<ARM_DynCom>(USER32MODE); | 136 | } |
| 137 | |||
| 138 | CoreTiming::Init(); | ||
| 139 | HW::Init(); | ||
| 140 | Kernel::Init(system_mode); | ||
| 141 | Service::Init(); | ||
| 142 | AudioCore::Init(); | ||
| 143 | GDBStub::Init(); | ||
| 144 | |||
| 145 | if (!VideoCore::Init(emu_window)) { | ||
| 146 | return ResultStatus::ErrorVideoCore; | ||
| 80 | } | 147 | } |
| 81 | 148 | ||
| 82 | LOG_DEBUG(Core, "Initialized OK"); | 149 | LOG_DEBUG(Core, "Initialized OK"); |
| 150 | |||
| 151 | return ResultStatus::Success; | ||
| 83 | } | 152 | } |
| 84 | 153 | ||
| 85 | void Shutdown() { | 154 | void System::Shutdown() { |
| 86 | g_app_core.reset(); | 155 | GDBStub::Shutdown(); |
| 87 | g_sys_core.reset(); | 156 | AudioCore::Shutdown(); |
| 157 | VideoCore::Shutdown(); | ||
| 158 | Service::Shutdown(); | ||
| 159 | Kernel::Shutdown(); | ||
| 160 | HW::Shutdown(); | ||
| 161 | CoreTiming::Shutdown(); | ||
| 88 | 162 | ||
| 89 | LOG_DEBUG(Core, "Shutdown OK"); | 163 | LOG_DEBUG(Core, "Shutdown OK"); |
| 90 | } | 164 | } |