summaryrefslogtreecommitdiff
path: root/src/core/core.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2016-12-15 19:01:48 -0500
committerGravatar bunnei2016-12-21 23:29:13 -0500
commit232ef55c1a13552e5ba8b72d61d1d072f5851598 (patch)
tree729ee82ded58202888a2c27bdc3beec6ab926768 /src/core/core.cpp
parentfile_util: Remove unused paths. (diff)
downloadyuzu-232ef55c1a13552e5ba8b72d61d1d072f5851598.tar.gz
yuzu-232ef55c1a13552e5ba8b72d61d1d072f5851598.tar.xz
yuzu-232ef55c1a13552e5ba8b72d61d1d072f5851598.zip
core: Consolidate core and system state, remove system module & cleanups.
Diffstat (limited to 'src/core/core.cpp')
-rw-r--r--src/core/core.cpp112
1 files changed, 87 insertions, 25 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp
index 6efa18159..b4df90efd 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"
@@ -11,17 +13,23 @@
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/hle.h"
16#include "core/hle/kernel/kernel.h"
17#include "core/hle/kernel/memory.h"
14#include "core/hle/kernel/thread.h" 18#include "core/hle/kernel/thread.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
18namespace Core { 24namespace Core {
19 25
20std::unique_ptr<ARM_Interface> g_app_core; ///< ARM11 application core 26/*static*/ System System::s_instance;
21std::unique_ptr<ARM_Interface> g_sys_core; ///< ARM11 system (OS) core 27
28System::ResultStatus System::RunLoop(int tight_loop) {
29 if (!app_core) {
30 return ResultStatus::ErrorNotInitialized;
31 }
22 32
23/// Run the core CPU loop
24void 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 }
@@ -45,46 +53,100 @@ void RunLoop(int tight_loop) {
45 CoreTiming::Advance(); 53 CoreTiming::Advance();
46 HLE::Reschedule(__func__); 54 HLE::Reschedule(__func__);
47 } else { 55 } else {
48 g_app_core->Run(tight_loop); 56 app_core->Run(tight_loop);
49 } 57 }
50 58
51 HW::Update(); 59 HW::Update();
52 if (HLE::IsReschedulePending()) { 60 if (HLE::IsReschedulePending()) {
53 Kernel::Reschedule(); 61 Kernel::Reschedule();
54 } 62 }
55}
56 63
57/// Step the CPU one instruction 64 return ResultStatus::Success;
58void SingleStep() {
59 RunLoop(1);
60} 65}
61 66
62/// Halt the core 67System::ResultStatus System::SingleStep() {
63void Halt(const char* msg) { 68 return RunLoop(1);
64 // TODO(ShizZy): ImplementMe
65} 69}
66 70
67/// Kill the core 71System::ResultStatus System::Load(EmuWindow* emu_window, const std::string& filepath) {
68void Stop() { 72 if (app_loader) {
69 // TODO(ShizZy): ImplementMe 73 app_loader.reset();
74 }
75
76 app_loader = Loader::GetLoader(filepath);
77
78 if (!app_loader) {
79 LOG_CRITICAL(Core, "Failed to obtain loader for %s!", filepath.c_str());
80 return ResultStatus::ErrorGetLoader;
81 }
82
83 boost::optional<u32> system_mode{ app_loader->LoadKernelSystemMode() };
84 if (!system_mode) {
85 LOG_CRITICAL(Core, "Failed to determine system mode!");
86 return ResultStatus::ErrorSystemMode;
87 }
88
89 ResultStatus init_result{ Init(emu_window, system_mode.get()) };
90 if (init_result != ResultStatus::Success) {
91 LOG_CRITICAL(Core, "Failed to initialize system (Error %i)!", init_result);
92 System::Shutdown();
93 return init_result;
94 }
95
96 const Loader::ResultStatus load_result{ app_loader->Load() };
97 if (Loader::ResultStatus::Success != load_result) {
98 LOG_CRITICAL(Core, "Failed to load ROM (Error %i)!", load_result);
99 System::Shutdown();
100
101 switch (load_result) {
102 case Loader::ResultStatus::ErrorEncrypted:
103 return ResultStatus::ErrorLoader_ErrorEncrypted;
104 case Loader::ResultStatus::ErrorInvalidFormat:
105 return ResultStatus::ErrorLoader_ErrorInvalidFormat;
106 default:
107 return ResultStatus::ErrorLoader;
108 }
109 }
110 return ResultStatus::Success;
70} 111}
71 112
72/// Initialize the core 113System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) {
73void Init() { 114 if (app_core) {
115 app_core.reset();
116 }
117
118 Memory::Init();
119
74 if (Settings::values.use_cpu_jit) { 120 if (Settings::values.use_cpu_jit) {
75 g_sys_core = std::make_unique<ARM_Dynarmic>(USER32MODE); 121 app_core = std::make_unique<ARM_Dynarmic>(USER32MODE);
76 g_app_core = std::make_unique<ARM_Dynarmic>(USER32MODE);
77 } else { 122 } else {
78 g_sys_core = std::make_unique<ARM_DynCom>(USER32MODE); 123 app_core = std::make_unique<ARM_DynCom>(USER32MODE);
79 g_app_core = std::make_unique<ARM_DynCom>(USER32MODE); 124 }
125
126 CoreTiming::Init();
127 HW::Init();
128 Kernel::Init(system_mode);
129 HLE::Init();
130 AudioCore::Init();
131 GDBStub::Init();
132
133 if (!VideoCore::Init(emu_window)) {
134 return ResultStatus::ErrorVideoCore;
80 } 135 }
81 136
82 LOG_DEBUG(Core, "Initialized OK"); 137 LOG_DEBUG(Core, "Initialized OK");
138
139 return ResultStatus::Success;
83} 140}
84 141
85void Shutdown() { 142void System::Shutdown() {
86 g_app_core.reset(); 143 GDBStub::Shutdown();
87 g_sys_core.reset(); 144 AudioCore::Shutdown();
145 VideoCore::Shutdown();
146 HLE::Shutdown();
147 Kernel::Shutdown();
148 HW::Shutdown();
149 CoreTiming::Shutdown();
88 150
89 LOG_DEBUG(Core, "Shutdown OK"); 151 LOG_DEBUG(Core, "Shutdown OK");
90} 152}