VERY experimental Nintendo Switch 2 emulator
C++
Move ThreadContext to core/core.h and deal with the fallout
Yuri Kunde Schlesner7b3452c7303c
diff --git a/src/citra_qt/debugger/disassembler.cpp b/src/citra_qt/debugger/disassembler.cppindex 8db73752f7..da084ab241 100644--- a/src/citra_qt/debugger/disassembler.cpp+++ b/src/citra_qt/debugger/disassembler.cpp@@ -13,6 +13,7 @@#include "core/core.h"#include "common/break_points.h"#include "common/symbols.h"+#include "core/arm/arm_interface.h"#include "core/arm/skyeye_common/armdefs.h"#include "core/arm/disassembler/arm_disasm.h"diff --git a/src/core/arm/arm_interface.h b/src/core/arm/arm_interface.hindex d3bd4a9a36..e612f7439a 100644--- a/src/core/arm/arm_interface.h+++ b/src/core/arm/arm_interface.h@@ -7,7 +7,9 @@#include "common/common.h"#include "common/common_types.h"-#include "core/hle/svc.h"+namespace Core {+ struct ThreadContext;+}/// Generic ARM11 CPU interfaceclass ARM_Interface : NonCopyable {@@ -87,13 +89,13 @@ public:* Saves the current CPU context* @param ctx Thread context to save*/- virtual void SaveContext(ThreadContext& ctx) = 0;+ virtual void SaveContext(Core::ThreadContext& ctx) = 0;/*** Loads a CPU context* @param ctx Thread context to load*/- virtual void LoadContext(const ThreadContext& ctx) = 0;+ virtual void LoadContext(const Core::ThreadContext& ctx) = 0;/// Prepare core for thread reschedule (if needed to correctly handle state)virtual void PrepareReschedule() = 0;diff --git a/src/core/arm/dyncom/arm_dyncom.cpp b/src/core/arm/dyncom/arm_dyncom.cppindex 31eb879a27..9c4cc90f23 100644--- a/src/core/arm/dyncom/arm_dyncom.cpp+++ b/src/core/arm/dyncom/arm_dyncom.cpp@@ -9,6 +9,7 @@#include "core/arm/dyncom/arm_dyncom.h"#include "core/arm/dyncom/arm_dyncom_interpreter.h"+#include "core/core.h"#include "core/core_timing.h"const static cpu_config_t s_arm11_cpu_info = {@@ -94,7 +95,7 @@ void ARM_DynCom::ExecuteInstructions(int num_instructions) {AddTicks(ticks_executed);}-void ARM_DynCom::SaveContext(ThreadContext& ctx) {+void ARM_DynCom::SaveContext(Core::ThreadContext& ctx) {memcpy(ctx.cpu_registers, state->Reg, sizeof(ctx.cpu_registers));memcpy(ctx.fpu_registers, state->ExtReg, sizeof(ctx.fpu_registers));@@ -110,7 +111,7 @@ void ARM_DynCom::SaveContext(ThreadContext& ctx) {ctx.mode = state->NextInstr;}-void ARM_DynCom::LoadContext(const ThreadContext& ctx) {+void ARM_DynCom::LoadContext(const Core::ThreadContext& ctx) {memcpy(state->Reg, ctx.cpu_registers, sizeof(ctx.cpu_registers));memcpy(state->ExtReg, ctx.fpu_registers, sizeof(ctx.fpu_registers));diff --git a/src/core/arm/dyncom/arm_dyncom.h b/src/core/arm/dyncom/arm_dyncom.hindex 9e102a46e5..f16fb070cc 100644--- a/src/core/arm/dyncom/arm_dyncom.h+++ b/src/core/arm/dyncom/arm_dyncom.h@@ -71,13 +71,13 @@ public:* Saves the current CPU context* @param ctx Thread context to save*/- void SaveContext(ThreadContext& ctx) override;+ void SaveContext(Core::ThreadContext& ctx) override;/*** Loads a CPU context* @param ctx Thread context to load*/- void LoadContext(const ThreadContext& ctx) override;+ void LoadContext(const Core::ThreadContext& ctx) override;/// Prepare core for thread reschedule (if needed to correctly handle state)void PrepareReschedule() override;diff --git a/src/core/arm/interpreter/arm_interpreter.cpp b/src/core/arm/interpreter/arm_interpreter.cppindex 80ebc359e9..c76d371a23 100644--- a/src/core/arm/interpreter/arm_interpreter.cpp+++ b/src/core/arm/interpreter/arm_interpreter.cpp@@ -4,6 +4,8 @@#include "core/arm/interpreter/arm_interpreter.h"+#include "core/core.h"+const static cpu_config_t arm11_cpu_info = {"armv6", "arm11", 0x0007b000, 0x0007f000, NONCACHE};@@ -75,7 +77,7 @@ void ARM_Interpreter::ExecuteInstructions(int num_instructions) {ARMul_Emulate32(state);}-void ARM_Interpreter::SaveContext(ThreadContext& ctx) {+void ARM_Interpreter::SaveContext(Core::ThreadContext& ctx) {memcpy(ctx.cpu_registers, state->Reg, sizeof(ctx.cpu_registers));memcpy(ctx.fpu_registers, state->ExtReg, sizeof(ctx.fpu_registers));@@ -91,7 +93,7 @@ void ARM_Interpreter::SaveContext(ThreadContext& ctx) {ctx.mode = state->NextInstr;}-void ARM_Interpreter::LoadContext(const ThreadContext& ctx) {+void ARM_Interpreter::LoadContext(const Core::ThreadContext& ctx) {memcpy(state->Reg, ctx.cpu_registers, sizeof(ctx.cpu_registers));memcpy(state->ExtReg, ctx.fpu_registers, sizeof(ctx.fpu_registers));diff --git a/src/core/arm/interpreter/arm_interpreter.h b/src/core/arm/interpreter/arm_interpreter.hindex 019dad5df8..e5ecc69c2f 100644--- a/src/core/arm/interpreter/arm_interpreter.h+++ b/src/core/arm/interpreter/arm_interpreter.h@@ -70,13 +70,13 @@ public:* Saves the current CPU context* @param ctx Thread context to save*/- void SaveContext(ThreadContext& ctx) override;+ void SaveContext(Core::ThreadContext& ctx) override;/*** Loads a CPU context* @param ctx Thread context to load*/- void LoadContext(const ThreadContext& ctx) override;+ void LoadContext(const Core::ThreadContext& ctx) override;/// Prepare core for thread reschedule (if needed to correctly handle state)void PrepareReschedule() override;diff --git a/src/core/core.cpp b/src/core/core.cppindex ff506d67df..cf25f87ca2 100644--- a/src/core/core.cpp+++ b/src/core/core.cpp@@ -8,6 +8,7 @@#include "core/core_timing.h"#include "core/settings.h"+#include "core/arm/arm_interface.h"#include "core/arm/disassembler/arm_disasm.h"#include "core/arm/interpreter/arm_interpreter.h"#include "core/arm/dyncom/arm_dyncom.h"diff --git a/src/core/core.h b/src/core/core.hindex ecd58a73a3..2f5e8bc6be 100644--- a/src/core/core.h+++ b/src/core/core.h@@ -4,8 +4,9 @@#pragma once-#include "core/arm/arm_interface.h"-#include "core/arm/skyeye_common/armdefs.h"+#include "common/common_types.h"++class ARM_Interface;////////////////////////////////////////////////////////////////////////////////////////////////////@@ -16,6 +17,21 @@ enum CPUCore {CPU_OldInterpreter,};+struct ThreadContext {+ u32 cpu_registers[13];+ u32 sp;+ u32 lr;+ u32 pc;+ u32 cpsr;+ u32 fpu_registers[32];+ u32 fpscr;+ u32 fpexc;++ // These are not part of native ThreadContext, but needed by emu+ u32 reg_15;+ u32 mode;+};+extern ARM_Interface* g_app_core; ///< ARM11 application coreextern ARM_Interface* g_sys_core; ///< ARM11 system (OS) corediff --git a/src/core/core_timing.cpp b/src/core/core_timing.cppindex 8331996801..ec9d52a086 100644--- a/src/core/core_timing.cpp+++ b/src/core/core_timing.cpp@@ -9,6 +9,8 @@#include "common/chunk_file.h"#include "common/log.h"++#include "core/arm/arm_interface.h"#include "core/core.h"#include "core/core_timing.h"diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/function_wrappers.hindex 8eb4f252b8..a2f51b41b3 100644--- a/src/core/hle/function_wrappers.h+++ b/src/core/hle/function_wrappers.h@@ -5,6 +5,8 @@#pragma once#include "common/common_types.h"++#include "core/arm/arm_interface.h"#include "core/mem_map.h"#include "core/hle/hle.h"diff --git a/src/core/hle/hle.cpp b/src/core/hle/hle.cppindex 33ac12507f..5d77a14588 100644--- a/src/core/hle/hle.cpp+++ b/src/core/hle/hle.cpp@@ -4,6 +4,7 @@#include <vector>+#include "core/arm/arm_interface.h"#include "core/mem_map.h"#include "core/hle/hle.h"#include "core/hle/kernel/thread.h"diff --git a/src/core/hle/hle.h b/src/core/hle/hle.hindex 59b770f021..3f6f9a4b50 100644--- a/src/core/hle/hle.h+++ b/src/core/hle/hle.h@@ -4,6 +4,8 @@#pragma once+#include <string>+#include "common/common_types.h"#include "core/core.h"diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cppindex 391e833c01..1537702cf5 100644--- a/src/core/hle/kernel/kernel.cpp+++ b/src/core/hle/kernel/kernel.cpp@@ -6,6 +6,7 @@#include "common/common.h"+#include "core/arm/arm_interface.h"#include "core/core.h"#include "core/hle/kernel/kernel.h"#include "core/hle/kernel/thread.h"diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cppindex 954bd09a09..3e9ea464df 100644--- a/src/core/hle/kernel/thread.cpp+++ b/src/core/hle/kernel/thread.cpp@@ -10,6 +10,7 @@#include "common/common.h"#include "common/thread_queue_list.h"+#include "core/arm/arm_interface.h"#include "core/core.h"#include "core/core_timing.h"#include "core/hle/hle.h"@@ -50,7 +51,7 @@ public:return MakeResult<bool>(wait);}- ThreadContext context;+ Core::ThreadContext context;u32 thread_id;@@ -104,18 +105,18 @@ inline void SetCurrentThread(Thread* t) {}/// Saves the current CPU context-void SaveContext(ThreadContext& ctx) {+void SaveContext(Core::ThreadContext& ctx) {Core::g_app_core->SaveContext(ctx);}/// Loads a CPU context-void LoadContext(ThreadContext& ctx) {+void LoadContext(Core::ThreadContext& ctx) {Core::g_app_core->LoadContext(ctx);}/// Resets a threadvoid ResetThread(Thread* t, u32 arg, s32 lowest_priority) {- memset(&t->context, 0, sizeof(ThreadContext));+ memset(&t->context, 0, sizeof(Core::ThreadContext));t->context.cpu_registers[0] = arg;t->context.pc = t->context.reg_15 = t->entry_point;diff --git a/src/core/hle/service/hid_user.cpp b/src/core/hle/service/hid_user.cppindex 99b0ea5a07..8ef9af9d20 100644--- a/src/core/hle/service/hid_user.cpp+++ b/src/core/hle/service/hid_user.cpp@@ -4,6 +4,7 @@#include "common/log.h"+#include "core/arm/arm_interface.h"#include "core/hle/hle.h"#include "core/hle/kernel/event.h"#include "core/hle/kernel/shared_memory.h"diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cppindex cdcdea36d1..92de442e8d 100644--- a/src/core/hle/svc.cpp+++ b/src/core/hle/svc.cpp@@ -7,6 +7,7 @@#include "common/string_util.h"#include "common/symbols.h"+#include "core/arm/arm_interface.h"#include "core/mem_map.h"#include "core/hle/kernel/address_arbiter.h"diff --git a/src/core/hle/svc.h b/src/core/hle/svc.hindex ad780818e8..5d020a5ba5 100644--- a/src/core/hle/svc.h+++ b/src/core/hle/svc.h@@ -20,21 +20,6 @@ struct PageInfo {u32 flags;};-struct ThreadContext {- u32 cpu_registers[13];- u32 sp;- u32 lr;- u32 pc;- u32 cpsr;- u32 fpu_registers[32];- u32 fpscr;- u32 fpexc;-- // These are not part of native ThreadContext, but needed by emu- u32 reg_15;- u32 mode;-};-enum ResetType {RESETTYPE_ONESHOT,RESETTYPE_STICKY,diff --git a/src/core/hw/gpu.cpp b/src/core/hw/gpu.cppindex e346e0ad6f..3b730a0de4 100644--- a/src/core/hw/gpu.cpp+++ b/src/core/hw/gpu.cpp@@ -4,6 +4,8 @@#include "common/common_types.h"+#include "core/arm/arm_interface.h"+#include "core/settings.h"#include "core/core.h"#include "core/mem_map.h"