summaryrefslogtreecommitdiff
path: root/src/core/core.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/core.h')
-rw-r--r--src/core/core.h56
1 files changed, 34 insertions, 22 deletions
diff --git a/src/core/core.h b/src/core/core.h
index f81cbfb3c..f90f085ad 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -4,9 +4,12 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <array>
7#include <memory> 8#include <memory>
8#include <string> 9#include <string>
10#include <thread>
9#include "common/common_types.h" 11#include "common/common_types.h"
12#include "core/core_cpu.h"
10#include "core/hle/kernel/kernel.h" 13#include "core/hle/kernel/kernel.h"
11#include "core/hle/kernel/scheduler.h" 14#include "core/hle/kernel/scheduler.h"
12#include "core/loader/loader.h" 15#include "core/loader/loader.h"
@@ -89,7 +92,7 @@ public:
89 * @returns True if the emulated system is powered on, otherwise false. 92 * @returns True if the emulated system is powered on, otherwise false.
90 */ 93 */
91 bool IsPoweredOn() const { 94 bool IsPoweredOn() const {
92 return cpu_core != nullptr; 95 return cpu_barrier && cpu_barrier->IsAlive();
93 } 96 }
94 97
95 /** 98 /**
@@ -103,24 +106,34 @@ public:
103 /// Prepare the core emulation for a reschedule 106 /// Prepare the core emulation for a reschedule
104 void PrepareReschedule(); 107 void PrepareReschedule();
105 108
109 /// Gets and resets core performance statistics
106 PerfStats::Results GetAndResetPerfStats(); 110 PerfStats::Results GetAndResetPerfStats();
107 111
108 /** 112 /// Gets an ARM interface to the CPU core that is currently running
109 * Gets a reference to the emulated CPU. 113 ARM_Interface& CurrentArmInterface() {
110 * @returns A reference to the emulated CPU. 114 return CurrentCpuCore().ArmInterface();
111 */
112 ARM_Interface& CPU() {
113 return *cpu_core;
114 } 115 }
115 116
117 /// Gets an ARM interface to the CPU core with the specified index
118 ARM_Interface& ArmInterface(size_t core_index);
119
120 /// Gets a CPU interface to the CPU core with the specified index
121 Cpu& CpuCore(size_t core_index);
122
123 /// Gets the GPU interface
116 Tegra::GPU& GPU() { 124 Tegra::GPU& GPU() {
117 return *gpu_core; 125 return *gpu_core;
118 } 126 }
119 127
120 Kernel::Scheduler& Scheduler() { 128 /// Gets the scheduler for the CPU core that is currently running
121 return *scheduler; 129 Kernel::Scheduler& CurrentScheduler() {
130 return *CurrentCpuCore().Scheduler();
122 } 131 }
123 132
133 /// Gets the scheduler for the CPU core with the specified index
134 const std::shared_ptr<Kernel::Scheduler>& Scheduler(size_t core_index);
135
136 /// Gets the current process
124 Kernel::SharedPtr<Kernel::Process>& CurrentProcess() { 137 Kernel::SharedPtr<Kernel::Process>& CurrentProcess() {
125 return current_process; 138 return current_process;
126 } 139 }
@@ -155,6 +168,9 @@ public:
155 } 168 }
156 169
157private: 170private:
171 /// Returns the currently running CPU core
172 Cpu& CurrentCpuCore();
173
158 /** 174 /**
159 * Initialize the emulated system. 175 * Initialize the emulated system.
160 * @param emu_window Pointer to the host-system window used for video output and keyboard input. 176 * @param emu_window Pointer to the host-system window used for video output and keyboard input.
@@ -163,22 +179,15 @@ private:
163 */ 179 */
164 ResultStatus Init(EmuWindow* emu_window, u32 system_mode); 180 ResultStatus Init(EmuWindow* emu_window, u32 system_mode);
165 181
166 /// Reschedule the core emulation
167 void Reschedule();
168
169 /// AppLoader used to load the current executing application 182 /// AppLoader used to load the current executing application
170 std::unique_ptr<Loader::AppLoader> app_loader; 183 std::unique_ptr<Loader::AppLoader> app_loader;
171
172 std::shared_ptr<ARM_Interface> cpu_core;
173 std::unique_ptr<Kernel::Scheduler> scheduler;
174 std::unique_ptr<Tegra::GPU> gpu_core; 184 std::unique_ptr<Tegra::GPU> gpu_core;
175
176 std::shared_ptr<Tegra::DebugContext> debug_context; 185 std::shared_ptr<Tegra::DebugContext> debug_context;
177
178 Kernel::SharedPtr<Kernel::Process> current_process; 186 Kernel::SharedPtr<Kernel::Process> current_process;
179 187 std::shared_ptr<CpuBarrier> cpu_barrier;
180 /// When true, signals that a reschedule should happen 188 std::array<std::shared_ptr<Cpu>, NUM_CPU_CORES> cpu_cores;
181 bool reschedule_pending{}; 189 std::array<std::unique_ptr<std::thread>, NUM_CPU_CORES - 1> cpu_core_threads;
190 size_t active_core{}; ///< Active core, only used in single thread mode
182 191
183 /// Service manager 192 /// Service manager
184 std::shared_ptr<Service::SM::ServiceManager> service_manager; 193 std::shared_ptr<Service::SM::ServiceManager> service_manager;
@@ -190,10 +199,13 @@ private:
190 199
191 ResultStatus status = ResultStatus::Success; 200 ResultStatus status = ResultStatus::Success;
192 std::string status_details = ""; 201 std::string status_details = "";
202
203 /// Map of guest threads to CPU cores
204 std::map<std::thread::id, std::shared_ptr<Cpu>> thread_to_cpu;
193}; 205};
194 206
195inline ARM_Interface& CPU() { 207inline ARM_Interface& CurrentArmInterface() {
196 return System::GetInstance().CPU(); 208 return System::GetInstance().CurrentArmInterface();
197} 209}
198 210
199inline TelemetrySession& Telemetry() { 211inline TelemetrySession& Telemetry() {