2018-01-17 20:00:42 +00:00
|
|
|
/* This file is part of the dynarmic project.
|
|
|
|
* Copyright (c) 2018 MerryMage
|
2020-04-23 15:25:11 +01:00
|
|
|
* SPDX-License-Identifier: 0BSD
|
2018-01-17 20:00:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
|
2022-12-31 16:26:55 +00:00
|
|
|
#include <catch2/catch_test_macros.hpp>
|
2018-01-17 20:00:42 +00:00
|
|
|
|
2021-05-19 17:28:35 +01:00
|
|
|
#include "../rand_int.h"
|
|
|
|
#include "../unicorn_emu/a64_unicorn.h"
|
|
|
|
#include "./testenv.h"
|
2018-01-17 20:00:42 +00:00
|
|
|
|
|
|
|
using namespace Dynarmic;
|
|
|
|
|
|
|
|
TEST_CASE("Unicorn: Sanity test", "[a64]") {
|
2018-08-11 11:39:53 +01:00
|
|
|
A64TestEnv env;
|
2018-08-01 15:25:40 +01:00
|
|
|
|
2021-05-22 14:51:20 +01:00
|
|
|
env.code_mem.emplace_back(0x8b020020); // ADD X0, X1, X2
|
|
|
|
env.code_mem.emplace_back(0x14000000); // B .
|
2018-01-17 20:00:42 +00:00
|
|
|
|
2018-08-11 11:39:53 +01:00
|
|
|
constexpr A64Unicorn::RegisterArray regs{
|
2018-01-17 20:00:42 +00:00
|
|
|
0, 1, 2, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
2021-05-22 14:51:20 +01:00
|
|
|
0, 0, 0, 0, 0, 0, 0};
|
2018-01-17 20:00:42 +00:00
|
|
|
|
2018-08-11 11:39:53 +01:00
|
|
|
A64Unicorn unicorn{env};
|
2018-01-17 20:00:42 +00:00
|
|
|
|
|
|
|
unicorn.SetRegisters(regs);
|
|
|
|
unicorn.SetPC(0);
|
|
|
|
|
|
|
|
env.ticks_left = 2;
|
|
|
|
unicorn.Run();
|
|
|
|
|
|
|
|
REQUIRE(unicorn.GetRegisters()[0] == 3);
|
|
|
|
REQUIRE(unicorn.GetRegisters()[1] == 1);
|
|
|
|
REQUIRE(unicorn.GetRegisters()[2] == 2);
|
|
|
|
REQUIRE(unicorn.GetPC() == 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("Unicorn: Ensure 0xFFFF'FFFF'FFFF'FFFF is readable", "[a64]") {
|
2018-08-11 11:39:53 +01:00
|
|
|
A64TestEnv env;
|
2018-01-17 20:00:42 +00:00
|
|
|
|
2021-05-22 14:51:20 +01:00
|
|
|
env.code_mem.emplace_back(0x385fed99); // LDRB W25, [X12, #0xfffffffffffffffe]!
|
|
|
|
env.code_mem.emplace_back(0x14000000); // B .
|
2018-01-17 20:00:42 +00:00
|
|
|
|
2018-08-11 11:39:53 +01:00
|
|
|
A64Unicorn::RegisterArray regs{};
|
2018-01-17 20:00:42 +00:00
|
|
|
regs[12] = 1;
|
|
|
|
|
2018-08-11 11:39:53 +01:00
|
|
|
A64Unicorn unicorn{env};
|
2018-01-17 20:00:42 +00:00
|
|
|
|
|
|
|
unicorn.SetRegisters(regs);
|
|
|
|
unicorn.SetPC(0);
|
|
|
|
|
|
|
|
env.ticks_left = 2;
|
|
|
|
unicorn.Run();
|
|
|
|
|
|
|
|
REQUIRE(unicorn.GetPC() == 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("Unicorn: Ensure is able to read across page boundaries", "[a64]") {
|
2018-08-11 11:39:53 +01:00
|
|
|
A64TestEnv env;
|
2018-01-17 20:00:42 +00:00
|
|
|
|
2021-05-22 14:51:20 +01:00
|
|
|
env.code_mem.emplace_back(0xb85f93d9); // LDUR W25, [X30, #0xfffffffffffffff9]
|
|
|
|
env.code_mem.emplace_back(0x14000000); // B .
|
2018-01-17 20:00:42 +00:00
|
|
|
|
2018-08-11 11:39:53 +01:00
|
|
|
A64Unicorn::RegisterArray regs{};
|
2018-01-17 20:00:42 +00:00
|
|
|
regs[30] = 4;
|
|
|
|
|
2018-08-11 11:39:53 +01:00
|
|
|
A64Unicorn unicorn{env};
|
2018-01-17 20:00:42 +00:00
|
|
|
|
|
|
|
unicorn.SetRegisters(regs);
|
|
|
|
unicorn.SetPC(0);
|
|
|
|
|
|
|
|
env.ticks_left = 2;
|
|
|
|
unicorn.Run();
|
|
|
|
|
|
|
|
REQUIRE(unicorn.GetPC() == 4);
|
|
|
|
}
|