From cd2bee17f20d8ec1df09f458c0f75114b65ed470 Mon Sep 17 00:00:00 2001 From: Merry Date: Thu, 29 Dec 2022 20:19:56 +0000 Subject: [PATCH] tests/A32: Add a SVC call test --- tests/A32/test_svc.cpp | 39 +++++++++++++++++++++++++++++++++++++++ tests/A32/testenv.h | 2 +- tests/CMakeLists.txt | 1 + 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tests/A32/test_svc.cpp diff --git a/tests/A32/test_svc.cpp b/tests/A32/test_svc.cpp new file mode 100644 index 00000000..367b89b3 --- /dev/null +++ b/tests/A32/test_svc.cpp @@ -0,0 +1,39 @@ +/* This file is part of the dynarmic project. + * Copyright (c) 2022 MerryMage + * SPDX-License-Identifier: 0BSD + */ + +#include + +#include + +#include "./testenv.h" + +using namespace Dynarmic; + +class ArmSvcTestEnv : public ArmTestEnv { +public: + std::optional svc_called = std::nullopt; + void CallSVC(u32 swi) override { + svc_called = swi; + } +}; + +TEST_CASE("arm: svc", "[arm][A32]") { + ArmSvcTestEnv test_env; + A32::Jit jit{A32::UserConfig{&test_env}}; + test_env.code_mem = { + 0xef0001ee, // svc #0x1ee + 0xe30a0071, // mov r0, #41073 + 0xeafffffe, // b +#0 + }; + + jit.SetCpsr(0x000001d0); // User-mode + + test_env.ticks_left = 3; + jit.Run(); + + REQUIRE(test_env.svc_called == 0x1ee); + REQUIRE(jit.Regs()[15] == 0x00000008); + REQUIRE(jit.Regs()[0] == 41073); +} diff --git a/tests/A32/testenv.h b/tests/A32/testenv.h index bc6775ac..4345663b 100644 --- a/tests/A32/testenv.h +++ b/tests/A32/testenv.h @@ -17,7 +17,7 @@ #include "dynarmic/interface/A32/a32.h" template -class A32TestEnv final : public Dynarmic::A32::UserCallbacks { +class A32TestEnv : public Dynarmic::A32::UserCallbacks { public: using InstructionType = InstructionType_; using RegisterArray = std::array; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 849f8e18..ce898c87 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,6 +12,7 @@ if ("A32" IN_LIST DYNARMIC_FRONTENDS) A32/test_arm_disassembler.cpp A32/test_arm_instructions.cpp A32/test_coprocessor.cpp + A32/test_svc.cpp A32/test_thumb_instructions.cpp A32/testenv.h decoder_tests.cpp