summaryrefslogtreecommitdiff
path: root/src/core/core.h
diff options
context:
space:
mode:
authorGravatar bunnei2016-12-22 11:47:44 -0500
committerGravatar GitHub2016-12-22 11:47:44 -0500
commitaa47af7fb6efd0bda54cca2373ed978e538f6d61 (patch)
tree93d96872603f64925cd632f27bb5c7046cadeedf /src/core/core.h
parentMerge pull request #2285 from mailwl/csnd-format (diff)
parentThreadContext: Move from "core" to "arm_interface". (diff)
downloadyuzu-aa47af7fb6efd0bda54cca2373ed978e538f6d61.tar.gz
yuzu-aa47af7fb6efd0bda54cca2373ed978e538f6d61.tar.xz
yuzu-aa47af7fb6efd0bda54cca2373ed978e538f6d61.zip
Merge pull request #2343 from bunnei/core-cleanup
Core: Top-level consolidate & misc cleanup
Diffstat (limited to 'src/core/core.h')
-rw-r--r--src/core/core.h148
1 files changed, 105 insertions, 43 deletions
diff --git a/src/core/core.h b/src/core/core.h
index ffbfa91c3..1015e8847 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -5,56 +5,118 @@
5#pragma once 5#pragma once
6 6
7#include <memory> 7#include <memory>
8#include <string>
9
8#include "common/common_types.h" 10#include "common/common_types.h"
11#include "core/memory.h"
9 12
13class EmuWindow;
10class ARM_Interface; 14class ARM_Interface;
11 15
12//////////////////////////////////////////////////////////////////////////////////////////////////// 16namespace Loader {
17class AppLoader;
18}
13 19
14namespace Core { 20namespace Core {
15 21
16struct ThreadContext { 22class System {
17 u32 cpu_registers[13]; 23public:
18 u32 sp; 24 /**
19 u32 lr; 25 * Gets the instance of the System singleton class.
20 u32 pc; 26 * @returns Reference to the instance of the System singleton class.
21 u32 cpsr; 27 */
22 u32 fpu_registers[64]; 28 static System& GetInstance() {
23 u32 fpscr; 29 return s_instance;
24 u32 fpexc; 30 }
31
32 /// Enumeration representing the return values of the System Initialize and Load process.
33 enum class ResultStatus : u32 {
34 Success, ///< Succeeded
35 ErrorNotInitialized, ///< Error trying to use core prior to initialization
36 ErrorGetLoader, ///< Error finding the correct application loader
37 ErrorSystemMode, ///< Error determining the system mode
38 ErrorLoader, ///< Error loading the specified application
39 ErrorLoader_ErrorEncrypted, ///< Error loading the specified application due to encryption
40 ErrorLoader_ErrorInvalidFormat, ///< Error loading the specified application due to an
41 /// invalid format
42 ErrorVideoCore, ///< Error in the video core
43 };
44
45 /**
46 * Run the core CPU loop
47 * This function runs the core for the specified number of CPU instructions before trying to
48 * update hardware. This is much faster than SingleStep (and should be equivalent), as the CPU
49 * is not required to do a full dispatch with each instruction. NOTE: the number of instructions
50 * requested is not guaranteed to run, as this will be interrupted preemptively if a hardware
51 * update is requested (e.g. on a thread switch).
52 * @param tight_loop Number of instructions to execute.
53 * @return Result status, indicating whethor or not the operation succeeded.
54 */
55 ResultStatus RunLoop(int tight_loop = 1000);
56
57 /**
58 * Step the CPU one instruction
59 * @return Result status, indicating whethor or not the operation succeeded.
60 */
61 ResultStatus SingleStep();
62
63 /// Shutdown the emulated system.
64 void Shutdown();
65
66 /**
67 * Load an executable application.
68 * @param emu_window Pointer to the host-system window used for video output and keyboard input.
69 * @param filepath String path to the executable application to load on the host file system.
70 * @returns ResultStatus code, indicating if the operation succeeded.
71 */
72 ResultStatus Load(EmuWindow* emu_window, const std::string& filepath);
73
74 /**
75 * Indicates if the emulated system is powered on (all subsystems initialized and able to run an
76 * application).
77 * @returns True if the emulated system is powered on, otherwise false.
78 */
79 bool IsPoweredOn() const {
80 return cpu_core != nullptr;
81 }
82
83 /// Prepare the core emulation for a reschedule
84 void PrepareReschedule();
85
86 /**
87 * Gets a reference to the emulated CPU.
88 * @returns A reference to the emulated CPU.
89 */
90 ARM_Interface& CPU() {
91 return *cpu_core;
92 }
93
94private:
95 /**
96 * Initialize the emulated system.
97 * @param emu_window Pointer to the host-system window used for video output and keyboard input.
98 * @param system_mode The system mode.
99 * @return ResultStatus code, indicating if the operation succeeded.
100 */
101 ResultStatus Init(EmuWindow* emu_window, u32 system_mode);
102
103 /// Reschedule the core emulation
104 void Reschedule();
105
106 /// AppLoader used to load the current executing application
107 std::unique_ptr<Loader::AppLoader> app_loader;
108
109 ///< ARM11 CPU core
110 std::unique_ptr<ARM_Interface> cpu_core;
111
112 /// When true, signals that a reschedule should happen
113 bool reschedule_pending{};
114
115 static System s_instance;
25}; 116};
26 117
27extern std::unique_ptr<ARM_Interface> g_app_core; ///< ARM11 application core 118static ARM_Interface& CPU() {
28extern std::unique_ptr<ARM_Interface> g_sys_core; ///< ARM11 system (OS) core 119 return System::GetInstance().CPU();
29 120}
30////////////////////////////////////////////////////////////////////////////////////////////////////
31
32/// Start the core
33void Start();
34
35/**
36 * Run the core CPU loop
37 * This function runs the core for the specified number of CPU instructions before trying to update
38 * hardware. This is much faster than SingleStep (and should be equivalent), as the CPU is not
39 * required to do a full dispatch with each instruction. NOTE: the number of instructions requested
40 * is not guaranteed to run, as this will be interrupted preemptively if a hardware update is
41 * requested (e.g. on a thread switch).
42 */
43void RunLoop(int tight_loop = 1000);
44
45/// Step the CPU one instruction
46void SingleStep();
47
48/// Halt the core
49void Halt(const char* msg);
50
51/// Kill the core
52void Stop();
53
54/// Initialize the core
55void Init();
56
57/// Shutdown the core
58void Shutdown();
59 121
60} // namespace 122} // namespace Core