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.h189
1 files changed, 96 insertions, 93 deletions
diff --git a/src/core/core.h b/src/core/core.h
index 83ded63a5..579a774e4 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -5,6 +5,7 @@
5#pragma once 5#pragma once
6 6
7#include <cstddef> 7#include <cstddef>
8#include <functional>
8#include <memory> 9#include <memory>
9#include <string> 10#include <string>
10#include <vector> 11#include <vector>
@@ -25,11 +26,11 @@ class VfsFilesystem;
25} // namespace FileSys 26} // namespace FileSys
26 27
27namespace Kernel { 28namespace Kernel {
28class GlobalScheduler; 29class GlobalSchedulerContext;
29class KernelCore; 30class KernelCore;
30class PhysicalCore; 31class PhysicalCore;
31class Process; 32class Process;
32class Scheduler; 33class KScheduler;
33} // namespace Kernel 34} // namespace Kernel
34 35
35namespace Loader { 36namespace Loader {
@@ -69,6 +70,10 @@ namespace SM {
69class ServiceManager; 70class ServiceManager;
70} // namespace SM 71} // namespace SM
71 72
73namespace Time {
74class TimeManager;
75} // namespace Time
76
72} // namespace Service 77} // namespace Service
73 78
74namespace Tegra { 79namespace Tegra {
@@ -120,7 +125,7 @@ public:
120 * Gets the instance of the System singleton class. 125 * Gets the instance of the System singleton class.
121 * @returns Reference to the instance of the System singleton class. 126 * @returns Reference to the instance of the System singleton class.
122 */ 127 */
123 static System& GetInstance() { 128 [[deprecated("Use of the global system instance is deprecated")]] static System& GetInstance() {
124 return s_instance; 129 return s_instance;
125 } 130 }
126 131
@@ -140,19 +145,19 @@ public:
140 * Run the OS and Application 145 * Run the OS and Application
141 * This function will start emulation and run the relevant devices 146 * This function will start emulation and run the relevant devices
142 */ 147 */
143 ResultStatus Run(); 148 [[nodiscard]] ResultStatus Run();
144 149
145 /** 150 /**
146 * Pause the OS and Application 151 * Pause the OS and Application
147 * This function will pause emulation and stop the relevant devices 152 * This function will pause emulation and stop the relevant devices
148 */ 153 */
149 ResultStatus Pause(); 154 [[nodiscard]] ResultStatus Pause();
150 155
151 /** 156 /**
152 * Step the CPU one instruction 157 * Step the CPU one instruction
153 * @return Result status, indicating whether or not the operation succeeded. 158 * @return Result status, indicating whether or not the operation succeeded.
154 */ 159 */
155 ResultStatus SingleStep(); 160 [[nodiscard]] ResultStatus SingleStep();
156 161
157 /** 162 /**
158 * Invalidate the CPU instruction caches 163 * Invalidate the CPU instruction caches
@@ -161,6 +166,8 @@ public:
161 */ 166 */
162 void InvalidateCpuInstructionCaches(); 167 void InvalidateCpuInstructionCaches();
163 168
169 void InvalidateCpuInstructionCacheRange(VAddr addr, std::size_t size);
170
164 /// Shutdown the emulated system. 171 /// Shutdown the emulated system.
165 void Shutdown(); 172 void Shutdown();
166 173
@@ -169,22 +176,24 @@ public:
169 * @param emu_window Reference to the host-system window used for video output and keyboard 176 * @param emu_window Reference to the host-system window used for video output and keyboard
170 * input. 177 * input.
171 * @param filepath String path to the executable application to load on the host file system. 178 * @param filepath String path to the executable application to load on the host file system.
179 * @param program_index Specifies the index within the container of the program to launch.
172 * @returns ResultStatus code, indicating if the operation succeeded. 180 * @returns ResultStatus code, indicating if the operation succeeded.
173 */ 181 */
174 ResultStatus Load(Frontend::EmuWindow& emu_window, const std::string& filepath); 182 [[nodiscard]] ResultStatus Load(Frontend::EmuWindow& emu_window, const std::string& filepath,
183 std::size_t program_index = 0);
175 184
176 /** 185 /**
177 * Indicates if the emulated system is powered on (all subsystems initialized and able to run an 186 * Indicates if the emulated system is powered on (all subsystems initialized and able to run an
178 * application). 187 * application).
179 * @returns True if the emulated system is powered on, otherwise false. 188 * @returns True if the emulated system is powered on, otherwise false.
180 */ 189 */
181 bool IsPoweredOn() const; 190 [[nodiscard]] bool IsPoweredOn() const;
182 191
183 /// Gets a reference to the telemetry session for this emulation session. 192 /// Gets a reference to the telemetry session for this emulation session.
184 Core::TelemetrySession& TelemetrySession(); 193 [[nodiscard]] Core::TelemetrySession& TelemetrySession();
185 194
186 /// Gets a reference to the telemetry session for this emulation session. 195 /// Gets a reference to the telemetry session for this emulation session.
187 const Core::TelemetrySession& TelemetrySession() const; 196 [[nodiscard]] const Core::TelemetrySession& TelemetrySession() const;
188 197
189 /// Prepare the core emulation for a reschedule 198 /// Prepare the core emulation for a reschedule
190 void PrepareReschedule(); 199 void PrepareReschedule();
@@ -193,181 +202,166 @@ public:
193 void PrepareReschedule(u32 core_index); 202 void PrepareReschedule(u32 core_index);
194 203
195 /// Gets and resets core performance statistics 204 /// Gets and resets core performance statistics
196 PerfStatsResults GetAndResetPerfStats(); 205 [[nodiscard]] PerfStatsResults GetAndResetPerfStats();
197 206
198 /// Gets an ARM interface to the CPU core that is currently running 207 /// Gets an ARM interface to the CPU core that is currently running
199 ARM_Interface& CurrentArmInterface(); 208 [[nodiscard]] ARM_Interface& CurrentArmInterface();
200 209
201 /// Gets an ARM interface to the CPU core that is currently running 210 /// Gets an ARM interface to the CPU core that is currently running
202 const ARM_Interface& CurrentArmInterface() const; 211 [[nodiscard]] const ARM_Interface& CurrentArmInterface() const;
203 212
204 /// Gets the index of the currently running CPU core 213 /// Gets the index of the currently running CPU core
205 std::size_t CurrentCoreIndex() const; 214 [[nodiscard]] std::size_t CurrentCoreIndex() const;
206
207 /// Gets the scheduler for the CPU core that is currently running
208 Kernel::Scheduler& CurrentScheduler();
209
210 /// Gets the scheduler for the CPU core that is currently running
211 const Kernel::Scheduler& CurrentScheduler() const;
212 215
213 /// Gets the physical core for the CPU core that is currently running 216 /// Gets the physical core for the CPU core that is currently running
214 Kernel::PhysicalCore& CurrentPhysicalCore(); 217 [[nodiscard]] Kernel::PhysicalCore& CurrentPhysicalCore();
215 218
216 /// Gets the physical core for the CPU core that is currently running 219 /// Gets the physical core for the CPU core that is currently running
217 const Kernel::PhysicalCore& CurrentPhysicalCore() const; 220 [[nodiscard]] const Kernel::PhysicalCore& CurrentPhysicalCore() const;
218 221
219 /// Gets a reference to an ARM interface for the CPU core with the specified index 222 /// Gets a reference to an ARM interface for the CPU core with the specified index
220 ARM_Interface& ArmInterface(std::size_t core_index); 223 [[nodiscard]] ARM_Interface& ArmInterface(std::size_t core_index);
221 224
222 /// Gets a const reference to an ARM interface from the CPU core with the specified index 225 /// Gets a const reference to an ARM interface from the CPU core with the specified index
223 const ARM_Interface& ArmInterface(std::size_t core_index) const; 226 [[nodiscard]] const ARM_Interface& ArmInterface(std::size_t core_index) const;
224 227
225 CpuManager& GetCpuManager(); 228 /// Gets a reference to the underlying CPU manager.
229 [[nodiscard]] CpuManager& GetCpuManager();
226 230
227 const CpuManager& GetCpuManager() const; 231 /// Gets a const reference to the underlying CPU manager
232 [[nodiscard]] const CpuManager& GetCpuManager() const;
228 233
229 /// Gets a reference to the exclusive monitor 234 /// Gets a reference to the exclusive monitor
230 ExclusiveMonitor& Monitor(); 235 [[nodiscard]] ExclusiveMonitor& Monitor();
231 236
232 /// Gets a constant reference to the exclusive monitor 237 /// Gets a constant reference to the exclusive monitor
233 const ExclusiveMonitor& Monitor() const; 238 [[nodiscard]] const ExclusiveMonitor& Monitor() const;
234 239
235 /// Gets a mutable reference to the system memory instance. 240 /// Gets a mutable reference to the system memory instance.
236 Core::Memory::Memory& Memory(); 241 [[nodiscard]] Core::Memory::Memory& Memory();
237 242
238 /// Gets a constant reference to the system memory instance. 243 /// Gets a constant reference to the system memory instance.
239 const Core::Memory::Memory& Memory() const; 244 [[nodiscard]] const Core::Memory::Memory& Memory() const;
240 245
241 /// Gets a mutable reference to the GPU interface 246 /// Gets a mutable reference to the GPU interface
242 Tegra::GPU& GPU(); 247 [[nodiscard]] Tegra::GPU& GPU();
243 248
244 /// Gets an immutable reference to the GPU interface. 249 /// Gets an immutable reference to the GPU interface.
245 const Tegra::GPU& GPU() const; 250 [[nodiscard]] const Tegra::GPU& GPU() const;
246 251
247 /// Gets a mutable reference to the renderer. 252 /// Gets a mutable reference to the renderer.
248 VideoCore::RendererBase& Renderer(); 253 [[nodiscard]] VideoCore::RendererBase& Renderer();
249 254
250 /// Gets an immutable reference to the renderer. 255 /// Gets an immutable reference to the renderer.
251 const VideoCore::RendererBase& Renderer() const; 256 [[nodiscard]] const VideoCore::RendererBase& Renderer() const;
252
253 /// Gets the scheduler for the CPU core with the specified index
254 Kernel::Scheduler& Scheduler(std::size_t core_index);
255
256 /// Gets the scheduler for the CPU core with the specified index
257 const Kernel::Scheduler& Scheduler(std::size_t core_index) const;
258 257
259 /// Gets the global scheduler 258 /// Gets the global scheduler
260 Kernel::GlobalScheduler& GlobalScheduler(); 259 [[nodiscard]] Kernel::GlobalSchedulerContext& GlobalSchedulerContext();
261 260
262 /// Gets the global scheduler 261 /// Gets the global scheduler
263 const Kernel::GlobalScheduler& GlobalScheduler() const; 262 [[nodiscard]] const Kernel::GlobalSchedulerContext& GlobalSchedulerContext() const;
264 263
265 /// Gets the manager for the guest device memory 264 /// Gets the manager for the guest device memory
266 Core::DeviceMemory& DeviceMemory(); 265 [[nodiscard]] Core::DeviceMemory& DeviceMemory();
267 266
268 /// Gets the manager for the guest device memory 267 /// Gets the manager for the guest device memory
269 const Core::DeviceMemory& DeviceMemory() const; 268 [[nodiscard]] const Core::DeviceMemory& DeviceMemory() const;
270 269
271 /// Provides a pointer to the current process 270 /// Provides a pointer to the current process
272 Kernel::Process* CurrentProcess(); 271 [[nodiscard]] Kernel::Process* CurrentProcess();
273 272
274 /// Provides a constant pointer to the current process. 273 /// Provides a constant pointer to the current process.
275 const Kernel::Process* CurrentProcess() const; 274 [[nodiscard]] const Kernel::Process* CurrentProcess() const;
276 275
277 /// Provides a reference to the core timing instance. 276 /// Provides a reference to the core timing instance.
278 Timing::CoreTiming& CoreTiming(); 277 [[nodiscard]] Timing::CoreTiming& CoreTiming();
279 278
280 /// Provides a constant reference to the core timing instance. 279 /// Provides a constant reference to the core timing instance.
281 const Timing::CoreTiming& CoreTiming() const; 280 [[nodiscard]] const Timing::CoreTiming& CoreTiming() const;
282 281
283 /// Provides a reference to the interrupt manager instance. 282 /// Provides a reference to the interrupt manager instance.
284 Core::Hardware::InterruptManager& InterruptManager(); 283 [[nodiscard]] Core::Hardware::InterruptManager& InterruptManager();
285 284
286 /// Provides a constant reference to the interrupt manager instance. 285 /// Provides a constant reference to the interrupt manager instance.
287 const Core::Hardware::InterruptManager& InterruptManager() const; 286 [[nodiscard]] const Core::Hardware::InterruptManager& InterruptManager() const;
288 287
289 /// Provides a reference to the kernel instance. 288 /// Provides a reference to the kernel instance.
290 Kernel::KernelCore& Kernel(); 289 [[nodiscard]] Kernel::KernelCore& Kernel();
291 290
292 /// Provides a constant reference to the kernel instance. 291 /// Provides a constant reference to the kernel instance.
293 const Kernel::KernelCore& Kernel() const; 292 [[nodiscard]] const Kernel::KernelCore& Kernel() const;
294 293
295 /// Provides a reference to the internal PerfStats instance. 294 /// Provides a reference to the internal PerfStats instance.
296 Core::PerfStats& GetPerfStats(); 295 [[nodiscard]] Core::PerfStats& GetPerfStats();
297 296
298 /// Provides a constant reference to the internal PerfStats instance. 297 /// Provides a constant reference to the internal PerfStats instance.
299 const Core::PerfStats& GetPerfStats() const; 298 [[nodiscard]] const Core::PerfStats& GetPerfStats() const;
300 299
301 /// Provides a reference to the frame limiter; 300 /// Provides a reference to the frame limiter;
302 Core::FrameLimiter& FrameLimiter(); 301 [[nodiscard]] Core::FrameLimiter& FrameLimiter();
303 302
304 /// Provides a constant referent to the frame limiter 303 /// Provides a constant referent to the frame limiter
305 const Core::FrameLimiter& FrameLimiter() const; 304 [[nodiscard]] const Core::FrameLimiter& FrameLimiter() const;
306 305
307 /// Gets the name of the current game 306 /// Gets the name of the current game
308 Loader::ResultStatus GetGameName(std::string& out) const; 307 [[nodiscard]] Loader::ResultStatus GetGameName(std::string& out) const;
309 308
310 void SetStatus(ResultStatus new_status, const char* details); 309 void SetStatus(ResultStatus new_status, const char* details);
311 310
312 const std::string& GetStatusDetails() const; 311 [[nodiscard]] const std::string& GetStatusDetails() const;
313 312
314 Loader::AppLoader& GetAppLoader() const; 313 [[nodiscard]] Loader::AppLoader& GetAppLoader();
314 [[nodiscard]] const Loader::AppLoader& GetAppLoader() const;
315 315
316 Service::SM::ServiceManager& ServiceManager(); 316 [[nodiscard]] Service::SM::ServiceManager& ServiceManager();
317 const Service::SM::ServiceManager& ServiceManager() const; 317 [[nodiscard]] const Service::SM::ServiceManager& ServiceManager() const;
318 318
319 void SetFilesystem(FileSys::VirtualFilesystem vfs); 319 void SetFilesystem(FileSys::VirtualFilesystem vfs);
320 320
321 FileSys::VirtualFilesystem GetFilesystem() const; 321 [[nodiscard]] FileSys::VirtualFilesystem GetFilesystem() const;
322 322
323 void RegisterCheatList(const std::vector<Memory::CheatEntry>& list, 323 void RegisterCheatList(const std::vector<Memory::CheatEntry>& list,
324 const std::array<u8, 0x20>& build_id, VAddr main_region_begin, 324 const std::array<u8, 0x20>& build_id, VAddr main_region_begin,
325 u64 main_region_size); 325 u64 main_region_size);
326 326
327 void SetAppletFrontendSet(Service::AM::Applets::AppletFrontendSet&& set); 327 void SetAppletFrontendSet(Service::AM::Applets::AppletFrontendSet&& set);
328
329 void SetDefaultAppletFrontendSet(); 328 void SetDefaultAppletFrontendSet();
330 329
331 Service::AM::Applets::AppletManager& GetAppletManager(); 330 [[nodiscard]] Service::AM::Applets::AppletManager& GetAppletManager();
332 331 [[nodiscard]] const Service::AM::Applets::AppletManager& GetAppletManager() const;
333 const Service::AM::Applets::AppletManager& GetAppletManager() const;
334 332
335 void SetContentProvider(std::unique_ptr<FileSys::ContentProviderUnion> provider); 333 void SetContentProvider(std::unique_ptr<FileSys::ContentProviderUnion> provider);
336 334
337 FileSys::ContentProvider& GetContentProvider(); 335 [[nodiscard]] FileSys::ContentProvider& GetContentProvider();
338 336 [[nodiscard]] const FileSys::ContentProvider& GetContentProvider() const;
339 const FileSys::ContentProvider& GetContentProvider() const;
340 337
341 Service::FileSystem::FileSystemController& GetFileSystemController(); 338 [[nodiscard]] Service::FileSystem::FileSystemController& GetFileSystemController();
342 339 [[nodiscard]] const Service::FileSystem::FileSystemController& GetFileSystemController() const;
343 const Service::FileSystem::FileSystemController& GetFileSystemController() const;
344 340
345 void RegisterContentProvider(FileSys::ContentProviderUnionSlot slot, 341 void RegisterContentProvider(FileSys::ContentProviderUnionSlot slot,
346 FileSys::ContentProvider* provider); 342 FileSys::ContentProvider* provider);
347 343
348 void ClearContentProvider(FileSys::ContentProviderUnionSlot slot); 344 void ClearContentProvider(FileSys::ContentProviderUnionSlot slot);
349 345
350 const Reporter& GetReporter() const; 346 [[nodiscard]] const Reporter& GetReporter() const;
351
352 Service::Glue::ARPManager& GetARPManager();
353
354 const Service::Glue::ARPManager& GetARPManager() const;
355 347
356 Service::APM::Controller& GetAPMController(); 348 [[nodiscard]] Service::Glue::ARPManager& GetARPManager();
349 [[nodiscard]] const Service::Glue::ARPManager& GetARPManager() const;
357 350
358 const Service::APM::Controller& GetAPMController() const; 351 [[nodiscard]] Service::APM::Controller& GetAPMController();
352 [[nodiscard]] const Service::APM::Controller& GetAPMController() const;
359 353
360 Service::LM::Manager& GetLogManager(); 354 [[nodiscard]] Service::LM::Manager& GetLogManager();
355 [[nodiscard]] const Service::LM::Manager& GetLogManager() const;
361 356
362 const Service::LM::Manager& GetLogManager() const; 357 [[nodiscard]] Service::Time::TimeManager& GetTimeManager();
358 [[nodiscard]] const Service::Time::TimeManager& GetTimeManager() const;
363 359
364 void SetExitLock(bool locked); 360 void SetExitLock(bool locked);
365 361 [[nodiscard]] bool GetExitLock() const;
366 bool GetExitLock() const;
367 362
368 void SetCurrentProcessBuildID(const CurrentBuildProcessID& id); 363 void SetCurrentProcessBuildID(const CurrentBuildProcessID& id);
369 364 [[nodiscard]] const CurrentBuildProcessID& GetCurrentProcessBuildID() const;
370 const CurrentBuildProcessID& GetCurrentProcessBuildID() const;
371 365
372 /// Register a host thread as an emulated CPU Core. 366 /// Register a host thread as an emulated CPU Core.
373 void RegisterCoreThread(std::size_t id); 367 void RegisterCoreThread(std::size_t id);
@@ -382,18 +376,27 @@ public:
382 void ExitDynarmicProfile(); 376 void ExitDynarmicProfile();
383 377
384 /// Tells if system is running on multicore. 378 /// Tells if system is running on multicore.
385 bool IsMulticore() const; 379 [[nodiscard]] bool IsMulticore() const;
386 380
387private: 381 /// Type used for the frontend to designate a callback for System to re-launch the application
388 System(); 382 /// using a specified program index.
383 using ExecuteProgramCallback = std::function<void(std::size_t)>;
389 384
390 /** 385 /**
391 * Initialize the emulated system. 386 * Registers a callback from the frontend for System to re-launch the application using a
392 * @param emu_window Reference to the host-system window used for video output and keyboard 387 * specified program index.
393 * input. 388 * @param callback Callback from the frontend to relaunch the application.
394 * @return ResultStatus code, indicating if the operation succeeded.
395 */ 389 */
396 ResultStatus Init(Frontend::EmuWindow& emu_window); 390 void RegisterExecuteProgramCallback(ExecuteProgramCallback&& callback);
391
392 /**
393 * Instructs the frontend to re-launch the application using the specified program_index.
394 * @param program_index Specifies the index within the application of the program to launch.
395 */
396 void ExecuteProgram(std::size_t program_index);
397
398private:
399 System();
397 400
398 struct Impl; 401 struct Impl;
399 std::unique_ptr<Impl> impl; 402 std::unique_ptr<Impl> impl;