2016-07-01 14:01:06 +01:00
|
|
|
/* This file is part of the dynarmic project.
|
|
|
|
* Copyright (c) 2016 MerryMage
|
2020-04-23 15:25:11 +01:00
|
|
|
* SPDX-License-Identifier: 0BSD
|
2016-07-01 14:01:06 +01:00
|
|
|
*/
|
|
|
|
|
2021-08-08 12:51:37 +01:00
|
|
|
#include <catch2/catch.hpp>
|
2016-07-01 14:01:06 +01:00
|
|
|
|
2021-05-19 17:28:35 +01:00
|
|
|
#include "./testenv.h"
|
|
|
|
#include "dynarmic/common/common_types.h"
|
|
|
|
#include "dynarmic/interface/A32/a32.h"
|
2016-07-01 14:01:06 +01:00
|
|
|
|
2018-01-27 22:36:55 +00:00
|
|
|
static Dynarmic::A32::UserConfig GetUserConfig(ThumbTestEnv* testenv) {
|
|
|
|
Dynarmic::A32::UserConfig user_config;
|
|
|
|
user_config.callbacks = testenv;
|
|
|
|
return user_config;
|
2016-07-01 14:01:06 +01:00
|
|
|
}
|
|
|
|
|
2019-03-02 21:18:42 +00:00
|
|
|
TEST_CASE("thumb: lsls r0, r1, #2", "[thumb]") {
|
2018-01-27 22:36:55 +00:00
|
|
|
ThumbTestEnv test_env;
|
|
|
|
Dynarmic::A32::Jit jit{GetUserConfig(&test_env)};
|
2019-03-02 21:18:42 +00:00
|
|
|
test_env.code_mem = {
|
2021-05-22 14:51:20 +01:00
|
|
|
0x0088, // lsls r0, r1, #2
|
|
|
|
0xE7FE, // b +#0
|
2019-03-02 21:18:42 +00:00
|
|
|
};
|
2016-07-04 14:37:50 +01:00
|
|
|
|
|
|
|
jit.Regs()[0] = 1;
|
|
|
|
jit.Regs()[1] = 2;
|
2021-05-22 14:51:20 +01:00
|
|
|
jit.Regs()[15] = 0; // PC = 0
|
|
|
|
jit.SetCpsr(0x00000030); // Thumb, User-mode
|
2016-07-01 14:01:06 +01:00
|
|
|
|
2018-01-27 22:36:55 +00:00
|
|
|
test_env.ticks_left = 1;
|
2018-01-04 21:12:02 +00:00
|
|
|
jit.Run();
|
2016-07-01 14:01:06 +01:00
|
|
|
|
2018-11-24 02:48:53 +00:00
|
|
|
REQUIRE(jit.Regs()[0] == 8);
|
|
|
|
REQUIRE(jit.Regs()[1] == 2);
|
|
|
|
REQUIRE(jit.Regs()[15] == 2);
|
|
|
|
REQUIRE(jit.Cpsr() == 0x00000030);
|
2016-07-01 14:01:06 +01:00
|
|
|
}
|
|
|
|
|
2019-03-02 21:18:42 +00:00
|
|
|
TEST_CASE("thumb: lsls r0, r1, #31", "[thumb]") {
|
2018-01-27 22:36:55 +00:00
|
|
|
ThumbTestEnv test_env;
|
|
|
|
Dynarmic::A32::Jit jit{GetUserConfig(&test_env)};
|
2019-03-02 21:18:42 +00:00
|
|
|
test_env.code_mem = {
|
2021-05-22 14:51:20 +01:00
|
|
|
0x07C8, // lsls r0, r1, #31
|
|
|
|
0xE7FE, // b +#0
|
2019-03-02 21:18:42 +00:00
|
|
|
};
|
2016-07-04 14:37:50 +01:00
|
|
|
|
|
|
|
jit.Regs()[0] = 1;
|
|
|
|
jit.Regs()[1] = 0xFFFFFFFF;
|
2021-05-22 14:51:20 +01:00
|
|
|
jit.Regs()[15] = 0; // PC = 0
|
|
|
|
jit.SetCpsr(0x00000030); // Thumb, User-mode
|
2016-07-01 14:01:06 +01:00
|
|
|
|
2018-01-27 22:36:55 +00:00
|
|
|
test_env.ticks_left = 1;
|
2018-01-04 21:12:02 +00:00
|
|
|
jit.Run();
|
2016-07-01 14:01:06 +01:00
|
|
|
|
2018-11-24 02:48:53 +00:00
|
|
|
REQUIRE(jit.Regs()[0] == 0x80000000);
|
|
|
|
REQUIRE(jit.Regs()[1] == 0xffffffff);
|
|
|
|
REQUIRE(jit.Regs()[15] == 2);
|
2021-05-22 14:51:20 +01:00
|
|
|
REQUIRE(jit.Cpsr() == 0xA0000030); // N, C flags, Thumb, User-mode
|
2016-07-01 14:01:06 +01:00
|
|
|
}
|
2016-07-16 19:22:57 +01:00
|
|
|
|
2019-03-02 21:18:42 +00:00
|
|
|
TEST_CASE("thumb: revsh r4, r3", "[thumb]") {
|
2018-01-27 22:36:55 +00:00
|
|
|
ThumbTestEnv test_env;
|
|
|
|
Dynarmic::A32::Jit jit{GetUserConfig(&test_env)};
|
2019-03-02 21:18:42 +00:00
|
|
|
test_env.code_mem = {
|
2021-05-22 14:51:20 +01:00
|
|
|
0xBADC, // revsh r4, r3
|
|
|
|
0xE7FE, // b +#0
|
2019-03-02 21:18:42 +00:00
|
|
|
};
|
2016-07-16 19:22:57 +01:00
|
|
|
|
|
|
|
jit.Regs()[3] = 0x12345678;
|
2021-05-22 14:51:20 +01:00
|
|
|
jit.Regs()[15] = 0; // PC = 0
|
|
|
|
jit.SetCpsr(0x00000030); // Thumb, User-mode
|
2016-07-16 19:22:57 +01:00
|
|
|
|
2018-01-27 22:36:55 +00:00
|
|
|
test_env.ticks_left = 1;
|
2018-01-04 21:12:02 +00:00
|
|
|
jit.Run();
|
2016-07-16 19:22:57 +01:00
|
|
|
|
2018-11-24 02:48:53 +00:00
|
|
|
REQUIRE(jit.Regs()[3] == 0x12345678);
|
|
|
|
REQUIRE(jit.Regs()[4] == 0x00007856);
|
|
|
|
REQUIRE(jit.Regs()[15] == 2);
|
2021-05-22 14:51:20 +01:00
|
|
|
REQUIRE(jit.Cpsr() == 0x00000030); // Thumb, User-mode
|
2016-07-16 19:22:57 +01:00
|
|
|
}
|
2016-07-18 15:11:16 +01:00
|
|
|
|
2019-03-02 21:18:42 +00:00
|
|
|
TEST_CASE("thumb: ldr r3, [r3, #28]", "[thumb]") {
|
2018-01-27 22:36:55 +00:00
|
|
|
ThumbTestEnv test_env;
|
|
|
|
Dynarmic::A32::Jit jit{GetUserConfig(&test_env)};
|
2019-03-02 21:18:42 +00:00
|
|
|
test_env.code_mem = {
|
2021-05-22 14:51:20 +01:00
|
|
|
0x69DB, // ldr r3, [r3, #28]
|
|
|
|
0xE7FE, // b +#0
|
2019-03-02 21:18:42 +00:00
|
|
|
};
|
2016-07-18 15:11:16 +01:00
|
|
|
|
|
|
|
jit.Regs()[3] = 0x12345678;
|
2021-05-22 14:51:20 +01:00
|
|
|
jit.Regs()[15] = 0; // PC = 0
|
|
|
|
jit.SetCpsr(0x00000030); // Thumb, User-mode
|
2016-07-18 15:11:16 +01:00
|
|
|
|
2018-01-27 22:36:55 +00:00
|
|
|
test_env.ticks_left = 1;
|
2018-01-04 21:12:02 +00:00
|
|
|
jit.Run();
|
2016-07-18 15:11:16 +01:00
|
|
|
|
2021-05-22 14:51:20 +01:00
|
|
|
REQUIRE(jit.Regs()[3] == 0x97969594); // Memory location 0x12345694
|
2018-11-24 02:48:53 +00:00
|
|
|
REQUIRE(jit.Regs()[15] == 2);
|
2021-05-22 14:51:20 +01:00
|
|
|
REQUIRE(jit.Cpsr() == 0x00000030); // Thumb, User-mode
|
2016-07-18 15:11:16 +01:00
|
|
|
}
|
2016-07-18 22:18:58 +01:00
|
|
|
|
2019-03-02 21:18:42 +00:00
|
|
|
TEST_CASE("thumb: blx +#67712", "[thumb]") {
|
2018-01-27 22:36:55 +00:00
|
|
|
ThumbTestEnv test_env;
|
|
|
|
Dynarmic::A32::Jit jit{GetUserConfig(&test_env)};
|
2019-03-02 21:18:42 +00:00
|
|
|
test_env.code_mem = {
|
2021-05-22 14:51:20 +01:00
|
|
|
0xF010, 0xEC3E, // blx +#67712
|
|
|
|
0xE7FE // b +#0
|
2019-03-02 21:18:42 +00:00
|
|
|
};
|
2016-07-18 22:18:58 +01:00
|
|
|
|
2021-05-22 14:51:20 +01:00
|
|
|
jit.Regs()[15] = 0; // PC = 0
|
|
|
|
jit.SetCpsr(0x00000030); // Thumb, User-mode
|
2016-07-18 22:18:58 +01:00
|
|
|
|
2018-01-27 22:36:55 +00:00
|
|
|
test_env.ticks_left = 1;
|
2018-01-04 21:12:02 +00:00
|
|
|
jit.Run();
|
2016-07-18 22:18:58 +01:00
|
|
|
|
2018-11-24 02:48:53 +00:00
|
|
|
REQUIRE(jit.Regs()[14] == (0x4 | 1));
|
|
|
|
REQUIRE(jit.Regs()[15] == 0x10880);
|
2021-05-22 14:51:20 +01:00
|
|
|
REQUIRE(jit.Cpsr() == 0x00000010); // User-mode
|
2016-07-18 22:18:58 +01:00
|
|
|
}
|
|
|
|
|
2019-03-02 21:18:42 +00:00
|
|
|
TEST_CASE("thumb: bl +#234584", "[thumb]") {
|
2018-01-27 22:36:55 +00:00
|
|
|
ThumbTestEnv test_env;
|
|
|
|
Dynarmic::A32::Jit jit{GetUserConfig(&test_env)};
|
2019-03-02 21:18:42 +00:00
|
|
|
test_env.code_mem = {
|
2021-05-22 14:51:20 +01:00
|
|
|
0xF039, 0xFA2A, // bl +#234584
|
|
|
|
0xE7FE // b +#0
|
2019-03-02 21:18:42 +00:00
|
|
|
};
|
2016-07-18 22:18:58 +01:00
|
|
|
|
2021-05-22 14:51:20 +01:00
|
|
|
jit.Regs()[15] = 0; // PC = 0
|
|
|
|
jit.SetCpsr(0x00000030); // Thumb, User-mode
|
2016-07-18 22:18:58 +01:00
|
|
|
|
2018-01-27 22:36:55 +00:00
|
|
|
test_env.ticks_left = 1;
|
2018-01-04 21:12:02 +00:00
|
|
|
jit.Run();
|
2016-07-18 22:18:58 +01:00
|
|
|
|
2018-11-24 02:48:53 +00:00
|
|
|
REQUIRE(jit.Regs()[14] == (0x4 | 1));
|
|
|
|
REQUIRE(jit.Regs()[15] == 0x39458);
|
2021-05-22 14:51:20 +01:00
|
|
|
REQUIRE(jit.Cpsr() == 0x00000030); // Thumb, User-mode
|
2016-07-18 22:18:58 +01:00
|
|
|
}
|
2016-07-18 22:48:23 +01:00
|
|
|
|
2019-03-02 21:18:42 +00:00
|
|
|
TEST_CASE("thumb: bl -#42", "[thumb]") {
|
2018-01-27 22:36:55 +00:00
|
|
|
ThumbTestEnv test_env;
|
|
|
|
Dynarmic::A32::Jit jit{GetUserConfig(&test_env)};
|
2019-03-02 21:18:42 +00:00
|
|
|
test_env.code_mem = {
|
2021-05-22 14:51:20 +01:00
|
|
|
0xF7FF, 0xFFE9, // bl -#42
|
|
|
|
0xE7FE // b +#0
|
2019-03-02 21:18:42 +00:00
|
|
|
};
|
2016-07-18 22:48:23 +01:00
|
|
|
|
2021-05-22 14:51:20 +01:00
|
|
|
jit.Regs()[15] = 0; // PC = 0
|
|
|
|
jit.SetCpsr(0x00000030); // Thumb, User-mode
|
2016-07-18 22:48:23 +01:00
|
|
|
|
2018-01-27 22:36:55 +00:00
|
|
|
test_env.ticks_left = 1;
|
2018-01-04 21:12:02 +00:00
|
|
|
jit.Run();
|
2016-07-18 22:48:23 +01:00
|
|
|
|
2018-11-24 02:48:53 +00:00
|
|
|
REQUIRE(jit.Regs()[14] == (0x4 | 1));
|
|
|
|
REQUIRE(jit.Regs()[15] == 0xFFFFFFD6);
|
2021-05-22 14:51:20 +01:00
|
|
|
REQUIRE(jit.Cpsr() == 0x00000030); // Thumb, User-mode
|
2016-07-18 22:48:23 +01:00
|
|
|
}
|