2016-07-12 09:12:56 +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-12 09:12:56 +01:00
|
|
|
*/
|
|
|
|
|
2016-08-17 15:53:36 +01:00
|
|
|
#include <algorithm>
|
|
|
|
#include <array>
|
|
|
|
#include <cstdio>
|
2016-07-12 13:25:33 +01:00
|
|
|
#include <functional>
|
2016-08-17 15:53:36 +01:00
|
|
|
#include <tuple>
|
|
|
|
#include <vector>
|
2016-07-12 09:12:56 +01:00
|
|
|
|
|
|
|
#include <catch.hpp>
|
2018-01-04 21:12:02 +00:00
|
|
|
#include <dynarmic/A32/a32.h>
|
2016-08-25 18:22:08 +01:00
|
|
|
|
2016-07-12 09:12:56 +01:00
|
|
|
#include "common/common_types.h"
|
2019-04-26 12:06:10 +01:00
|
|
|
#include "common/fp/fpcr.h"
|
|
|
|
#include "common/fp/fpsr.h"
|
2018-02-08 02:14:14 +00:00
|
|
|
#include "common/scope_exit.h"
|
2018-01-01 15:23:56 +00:00
|
|
|
#include "frontend/A32/disassembler/disassembler.h"
|
|
|
|
#include "frontend/A32/location_descriptor.h"
|
|
|
|
#include "frontend/A32/translate/translate.h"
|
2018-09-09 01:03:45 +01:00
|
|
|
#include "frontend/A32/types.h"
|
2016-08-17 15:53:36 +01:00
|
|
|
#include "frontend/ir/basic_block.h"
|
2016-09-05 11:54:09 +01:00
|
|
|
#include "frontend/ir/location_descriptor.h"
|
2019-04-26 12:06:10 +01:00
|
|
|
#include "frontend/ir/opcodes.h"
|
|
|
|
#include "fuzz_util.h"
|
2016-07-12 09:12:56 +01:00
|
|
|
#include "rand_int.h"
|
2018-01-27 22:36:55 +00:00
|
|
|
#include "testenv.h"
|
2019-04-13 10:56:55 +01:00
|
|
|
#include "unicorn_emu/a32_unicorn.h"
|
2016-07-12 09:12:56 +01:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
// Must be declared last for all necessary operator<< to be declared prior to this.
|
|
|
|
#include <fmt/format.h>
|
|
|
|
#include <fmt/ostream.h>
|
2016-08-07 19:25:12 +01:00
|
|
|
|
2019-04-13 10:56:55 +01:00
|
|
|
namespace {
|
2019-04-26 12:06:10 +01:00
|
|
|
using namespace Dynarmic;
|
2016-07-12 09:12:56 +01:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
bool ShouldTestInst(u32 instruction, u32 pc, bool is_last_inst) {
|
|
|
|
const A32::LocationDescriptor location{pc, {}, {}};
|
|
|
|
IR::Block block{location};
|
|
|
|
const bool should_continue = A32::TranslateSingleInstruction(block, location, instruction);
|
2016-07-12 09:12:56 +01:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
if (!should_continue && !is_last_inst) {
|
|
|
|
return false;
|
2016-07-12 09:12:56 +01:00
|
|
|
}
|
2016-08-05 01:56:35 +01:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
if (auto terminal = block.GetTerminal(); boost::get<IR::Term::Interpret>(&terminal)) {
|
|
|
|
return false;
|
2016-07-12 09:12:56 +01:00
|
|
|
}
|
2016-08-05 00:35:46 +01:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
for (const auto& ir_inst : block) {
|
|
|
|
switch (ir_inst.GetOpcode()) {
|
|
|
|
case IR::Opcode::A32ExceptionRaised:
|
|
|
|
case IR::Opcode::A32CallSupervisor:
|
|
|
|
case IR::Opcode::A32CoprocInternalOperation:
|
|
|
|
case IR::Opcode::A32CoprocSendOneWord:
|
|
|
|
case IR::Opcode::A32CoprocSendTwoWords:
|
|
|
|
case IR::Opcode::A32CoprocGetOneWord:
|
|
|
|
case IR::Opcode::A32CoprocGetTwoWords:
|
|
|
|
case IR::Opcode::A32CoprocLoadWords:
|
|
|
|
case IR::Opcode::A32CoprocStoreWords:
|
|
|
|
return false;
|
2020-06-20 15:17:08 +01:00
|
|
|
// Currently unimplemented in Unicorn
|
|
|
|
case IR::Opcode::FPVectorRecipEstimate16:
|
|
|
|
case IR::Opcode::FPVectorRSqrtEstimate16:
|
|
|
|
return false;
|
2019-04-26 12:06:10 +01:00
|
|
|
default:
|
|
|
|
continue;
|
2016-07-12 09:12:56 +01:00
|
|
|
}
|
|
|
|
}
|
2016-07-21 21:48:45 +01:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
return true;
|
2016-12-20 20:04:38 +00:00
|
|
|
}
|
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
u32 GenRandomInst(u32 pc, bool is_last_inst) {
|
|
|
|
static const struct InstructionGeneratorInfo {
|
|
|
|
std::vector<InstructionGenerator> generators;
|
|
|
|
std::vector<InstructionGenerator> invalid;
|
|
|
|
} instructions = []{
|
|
|
|
const std::vector<std::tuple<std::string, const char*>> list {
|
|
|
|
#define INST(fn, name, bitstring) {#fn, bitstring},
|
|
|
|
#include "frontend/A32/decoder/arm.inc"
|
2020-05-16 12:30:09 +01:00
|
|
|
#include "frontend/A32/decoder/asimd.inc"
|
2019-05-02 14:38:07 +01:00
|
|
|
#include "frontend/A32/decoder/vfp.inc"
|
2019-04-26 12:06:10 +01:00
|
|
|
#undef INST
|
2017-04-02 12:36:32 +01:00
|
|
|
};
|
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
std::vector<InstructionGenerator> generators;
|
|
|
|
std::vector<InstructionGenerator> invalid;
|
|
|
|
|
|
|
|
// List of instructions not to test
|
|
|
|
static constexpr std::array do_not_test {
|
|
|
|
// Translating load/stores
|
|
|
|
"arm_LDRBT", "arm_LDRBT", "arm_LDRHT", "arm_LDRHT", "arm_LDRSBT", "arm_LDRSBT", "arm_LDRSHT", "arm_LDRSHT", "arm_LDRT", "arm_LDRT",
|
|
|
|
"arm_STRBT", "arm_STRBT", "arm_STRHT", "arm_STRHT", "arm_STRT", "arm_STRT",
|
|
|
|
// Exclusive load/stores
|
2020-05-15 21:07:07 +01:00
|
|
|
"arm_LDREXB", "arm_LDREXD", "arm_LDREXH", "arm_LDREX", "arm_LDAEXB", "arm_LDAEXD", "arm_LDAEXH", "arm_LDAEX",
|
|
|
|
"arm_STREXB", "arm_STREXD", "arm_STREXH", "arm_STREX", "arm_STLEXB", "arm_STLEXD", "arm_STLEXH", "arm_STLEX",
|
2019-04-26 12:06:10 +01:00
|
|
|
"arm_SWP", "arm_SWPB",
|
|
|
|
// Elevated load/store multiple instructions.
|
|
|
|
"arm_LDM_eret", "arm_LDM_usr",
|
|
|
|
"arm_STM_usr",
|
|
|
|
// Hint instructions
|
2019-05-03 01:03:33 +01:00
|
|
|
"arm_NOP", "arm_PLD_imm", "arm_PLD_reg", "arm_SEV",
|
|
|
|
"arm_WFE", "arm_WFI", "arm_YIELD",
|
2019-04-26 12:06:10 +01:00
|
|
|
// E, T, J
|
|
|
|
"arm_BLX_reg", "arm_BLX_imm", "arm_BXJ", "arm_SETEND",
|
|
|
|
// Coprocessor
|
|
|
|
"arm_CDP", "arm_LDC", "arm_MCR", "arm_MCRR", "arm_MRC", "arm_MRRC", "arm_STC",
|
|
|
|
// System
|
|
|
|
"arm_CPS", "arm_RFE", "arm_SRS",
|
|
|
|
// Undefined
|
|
|
|
"arm_UDF",
|
2020-05-10 14:47:21 +01:00
|
|
|
// FPSCR is inaccurate
|
|
|
|
"vfp_VMRS",
|
2020-06-20 13:55:28 +01:00
|
|
|
// Unimplemented in Unicorn
|
2020-06-20 15:17:08 +01:00
|
|
|
"asimd_VPADD_float",
|
2020-06-20 14:45:29 +01:00
|
|
|
// Incorrect Unicorn implementations
|
|
|
|
"asimd_VRECPS", // Unicorn does not fuse the multiply and subtraction, resulting in being off by 1ULP.
|
2020-06-20 15:07:50 +01:00
|
|
|
"asimd_VRSQRTS", // Unicorn does not fuse the multiply and subtraction, resulting in being off by 1ULP.
|
2016-07-12 09:12:56 +01:00
|
|
|
};
|
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
for (const auto& [fn, bitstring] : list) {
|
|
|
|
if (std::find(do_not_test.begin(), do_not_test.end(), fn) != do_not_test.end()) {
|
|
|
|
invalid.emplace_back(InstructionGenerator{bitstring});
|
|
|
|
continue;
|
TranslateArm: Implement CLREX, LDREX, LDREXB, LDREXD, LDREXH, STREX, STREXB, STREXD, STREXH, SWP, SWPB
2016-08-09 22:48:20 +01:00
|
|
|
}
|
2019-04-26 12:06:10 +01:00
|
|
|
generators.emplace_back(InstructionGenerator{bitstring});
|
2016-08-07 21:55:38 +01:00
|
|
|
}
|
2019-04-26 12:06:10 +01:00
|
|
|
return InstructionGeneratorInfo{generators, invalid};
|
|
|
|
}();
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
const size_t index = RandInt<size_t>(0, instructions.generators.size() - 1);
|
|
|
|
const u32 inst = instructions.generators[index].Generate();
|
2019-05-05 18:43:09 +01:00
|
|
|
|
2020-05-10 13:57:39 +01:00
|
|
|
if ((instructions.generators[index].Mask() & 0xF0000000) == 0 && (inst & 0xF0000000) == 0xF0000000) {
|
2019-04-26 12:06:10 +01:00
|
|
|
continue;
|
2016-08-07 21:55:38 +01:00
|
|
|
}
|
2020-05-10 13:57:39 +01:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
if (ShouldTestInst(inst, pc, is_last_inst)) {
|
|
|
|
return inst;
|
2016-08-07 21:55:38 +01:00
|
|
|
}
|
2016-08-05 02:35:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
Dynarmic::A32::UserConfig GetUserConfig(ArmTestEnv& testenv) {
|
|
|
|
Dynarmic::A32::UserConfig user_config;
|
|
|
|
user_config.enable_fast_dispatch = false;
|
|
|
|
user_config.callbacks = &testenv;
|
2019-07-27 19:54:57 +01:00
|
|
|
user_config.always_little_endian = true;
|
2019-04-26 12:06:10 +01:00
|
|
|
return user_config;
|
2016-08-05 02:03:23 +01:00
|
|
|
}
|
2016-08-12 16:53:16 +01:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
static void RunTestInstance(Dynarmic::A32::Jit& jit, A32Unicorn<ArmTestEnv>& uni,
|
|
|
|
ArmTestEnv& jit_env, ArmTestEnv& uni_env,
|
|
|
|
const A32Unicorn<ArmTestEnv>::RegisterArray& regs,
|
|
|
|
const A32Unicorn<ArmTestEnv>::ExtRegArray& vecs,
|
|
|
|
const std::vector<u32>& instructions, const u32 cpsr, const u32 fpscr) {
|
|
|
|
const u32 initial_pc = regs[15];
|
|
|
|
const u32 num_words = initial_pc / sizeof(u32);
|
2019-05-05 18:43:09 +01:00
|
|
|
const u32 code_mem_size = num_words + static_cast<u32>(instructions.size());
|
2019-04-26 12:06:10 +01:00
|
|
|
|
|
|
|
jit_env.code_mem.resize(code_mem_size + 1);
|
|
|
|
uni_env.code_mem.resize(code_mem_size + 1);
|
|
|
|
|
|
|
|
std::copy(instructions.begin(), instructions.end(), jit_env.code_mem.begin() + num_words);
|
|
|
|
std::copy(instructions.begin(), instructions.end(), uni_env.code_mem.begin() + num_words);
|
|
|
|
jit_env.code_mem.back() = 0xEAFFFFFE; // B .
|
|
|
|
uni_env.code_mem.back() = 0xEAFFFFFE; // B .
|
|
|
|
jit_env.modified_memory.clear();
|
|
|
|
uni_env.modified_memory.clear();
|
|
|
|
jit_env.interrupts.clear();
|
|
|
|
uni_env.interrupts.clear();
|
|
|
|
|
|
|
|
jit.Regs() = regs;
|
|
|
|
jit.ExtRegs() = vecs;
|
|
|
|
jit.SetFpscr(fpscr);
|
|
|
|
jit.SetCpsr(cpsr);
|
|
|
|
jit.ClearCache();
|
|
|
|
uni.SetRegisters(regs);
|
|
|
|
uni.SetExtRegs(vecs);
|
|
|
|
uni.SetFpscr(fpscr);
|
|
|
|
uni.EnableFloatingPointAccess();
|
|
|
|
uni.SetCpsr(cpsr);
|
|
|
|
uni.ClearPageCache();
|
|
|
|
|
|
|
|
jit_env.ticks_left = instructions.size();
|
|
|
|
jit.Run();
|
2016-08-12 16:53:16 +01:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
uni_env.ticks_left = instructions.size();
|
|
|
|
uni.Run();
|
2016-11-26 17:24:57 +00:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
SCOPE_FAIL {
|
|
|
|
fmt::print("Instruction Listing:\n");
|
|
|
|
for (u32 instruction : instructions) {
|
|
|
|
fmt::print("{:08x} {}\n", instruction, A32::DisassembleArm(instruction));
|
2017-11-25 17:28:51 +00:00
|
|
|
}
|
2019-04-26 12:06:10 +01:00
|
|
|
fmt::print("\n");
|
2016-11-26 17:24:57 +00:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
fmt::print("Initial register listing:\n");
|
|
|
|
for (size_t i = 0; i < regs.size(); ++i) {
|
|
|
|
fmt::print("{:3s}: {:08x}\n", static_cast<A32::Reg>(i), regs[i]);
|
|
|
|
}
|
|
|
|
for (size_t i = 0; i < vecs.size(); ++i) {
|
|
|
|
fmt::print("{:3s}: {:08x}\n", static_cast<A32::ExtReg>(i), vecs[i]);
|
|
|
|
}
|
|
|
|
fmt::print("cpsr {:08x}\n", cpsr);
|
|
|
|
fmt::print("fpcr {:08x}\n", fpscr);
|
|
|
|
fmt::print("fpcr.AHP {}\n", FP::FPCR{fpscr}.AHP());
|
|
|
|
fmt::print("fpcr.DN {}\n", FP::FPCR{fpscr}.DN());
|
|
|
|
fmt::print("fpcr.FZ {}\n", FP::FPCR{fpscr}.FZ());
|
|
|
|
fmt::print("fpcr.RMode {}\n", static_cast<size_t>(FP::FPCR{fpscr}.RMode()));
|
|
|
|
fmt::print("fpcr.FZ16 {}\n", FP::FPCR{fpscr}.FZ16());
|
|
|
|
fmt::print("\n");
|
|
|
|
|
|
|
|
fmt::print("Final register listing:\n");
|
|
|
|
fmt::print(" unicorn dynarmic\n");
|
|
|
|
const auto uni_regs = uni.GetRegisters();
|
|
|
|
for (size_t i = 0; i < regs.size(); ++i) {
|
|
|
|
fmt::print("{:3s}: {:08x} {:08x} {}\n", static_cast<A32::Reg>(i), uni_regs[i], jit.Regs()[i], uni_regs[i] != jit.Regs()[i] ? "*" : "");
|
|
|
|
}
|
|
|
|
const auto uni_ext_regs = uni.GetExtRegs();
|
|
|
|
for (size_t i = 0; i < vecs.size(); ++i) {
|
|
|
|
fmt::print("s{:2d}: {:08x} {:08x} {}\n", static_cast<size_t>(i), uni_ext_regs[i], jit.ExtRegs()[i], uni_ext_regs[i] != jit.ExtRegs()[i] ? "*" : "");
|
|
|
|
}
|
|
|
|
fmt::print("cpsr {:08x} {:08x} {}\n", uni.GetCpsr(), jit.Cpsr(), uni.GetCpsr() != jit.Cpsr() ? "*" : "");
|
|
|
|
fmt::print("fpsr {:08x} {:08x} {}\n", uni.GetFpscr(), jit.Fpscr(), (uni.GetFpscr() & 0xF0000000) != (jit.Fpscr() & 0xF0000000) ? "*" : "");
|
|
|
|
fmt::print("\n");
|
|
|
|
|
|
|
|
fmt::print("Modified memory:\n");
|
|
|
|
fmt::print(" uni dyn\n");
|
|
|
|
auto uni_iter = uni_env.modified_memory.begin();
|
|
|
|
auto jit_iter = jit_env.modified_memory.begin();
|
|
|
|
while (uni_iter != uni_env.modified_memory.end() || jit_iter != jit_env.modified_memory.end()) {
|
|
|
|
if (uni_iter == uni_env.modified_memory.end() || (jit_iter != jit_env.modified_memory.end() && uni_iter->first > jit_iter->first)) {
|
|
|
|
fmt::print("{:08x}: {:02x} *\n", jit_iter->first, jit_iter->second);
|
|
|
|
jit_iter++;
|
|
|
|
} else if (jit_iter == jit_env.modified_memory.end() || jit_iter->first > uni_iter->first) {
|
|
|
|
fmt::print("{:08x}: {:02x} *\n", uni_iter->first, uni_iter->second);
|
|
|
|
uni_iter++;
|
|
|
|
} else if (uni_iter->first == jit_iter->first) {
|
|
|
|
fmt::print("{:08x}: {:02x} {:02x} {}\n", uni_iter->first, uni_iter->second, jit_iter->second, uni_iter->second != jit_iter->second ? "*" : "");
|
|
|
|
uni_iter++;
|
|
|
|
jit_iter++;
|
2019-04-20 10:00:12 +01:00
|
|
|
}
|
2016-08-13 06:51:55 +01:00
|
|
|
}
|
2019-04-26 12:06:10 +01:00
|
|
|
fmt::print("\n");
|
2016-08-13 06:51:55 +01:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
fmt::print("x86_64:\n");
|
2020-06-12 15:27:42 +01:00
|
|
|
fmt::print("{}\n", jit.Disassemble());
|
2016-08-13 06:51:55 +01:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
fmt::print("Interrupts:\n");
|
|
|
|
for (const auto& i : uni_env.interrupts) {
|
|
|
|
std::puts(i.c_str());
|
2019-04-20 16:11:44 +01:00
|
|
|
}
|
|
|
|
};
|
2016-11-23 18:14:07 +00:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
REQUIRE(uni_env.code_mem_modified_by_guest == jit_env.code_mem_modified_by_guest);
|
|
|
|
if (uni_env.code_mem_modified_by_guest) {
|
|
|
|
return;
|
2017-12-09 15:42:47 +00:00
|
|
|
}
|
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
// Qemu doesn't do Thumb transitions??
|
|
|
|
{
|
|
|
|
const u32 uni_pc = uni.GetPC();
|
|
|
|
const bool is_thumb = (jit.Cpsr() & (1 << 5)) != 0;
|
|
|
|
const u32 new_uni_pc = uni_pc & (is_thumb ? 0xFFFFFFFE : 0xFFFFFFFC);
|
|
|
|
uni.SetPC(new_uni_pc);
|
2017-12-09 15:42:47 +00:00
|
|
|
}
|
2019-04-26 12:06:10 +01:00
|
|
|
|
|
|
|
REQUIRE(uni.GetRegisters() == jit.Regs());
|
|
|
|
REQUIRE(uni.GetExtRegs() == jit.ExtRegs());
|
2020-06-15 23:43:44 +01:00
|
|
|
REQUIRE((uni.GetCpsr() & 0xFFFFFDDF) == (jit.Cpsr() & 0xFFFFFDDF));
|
2019-04-26 12:06:10 +01:00
|
|
|
REQUIRE((uni.GetFpscr() & 0xF0000000) == (jit.Fpscr() & 0xF0000000));
|
|
|
|
REQUIRE(uni_env.modified_memory == jit_env.modified_memory);
|
|
|
|
REQUIRE(uni_env.interrupts.empty());
|
2017-12-09 15:42:47 +00:00
|
|
|
}
|
2019-04-26 12:06:10 +01:00
|
|
|
} // Anonymous namespace
|
2017-12-09 15:42:47 +00:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
TEST_CASE("A32: Single random instruction", "[arm]") {
|
|
|
|
ArmTestEnv jit_env{};
|
|
|
|
ArmTestEnv uni_env{};
|
2016-12-15 22:33:20 +00:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
Dynarmic::A32::Jit jit{GetUserConfig(jit_env)};
|
|
|
|
A32Unicorn<ArmTestEnv> uni{uni_env};
|
2016-12-15 22:33:20 +00:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
A32Unicorn<ArmTestEnv>::RegisterArray regs;
|
|
|
|
A32Unicorn<ArmTestEnv>::ExtRegArray ext_reg;
|
|
|
|
std::vector<u32> instructions(1);
|
2016-12-15 22:33:20 +00:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
for (size_t iteration = 0; iteration < 100000; ++iteration) {
|
|
|
|
std::generate(regs.begin(), regs.end(), [] { return RandInt<u32>(0, ~u32(0)); });
|
|
|
|
std::generate(ext_reg.begin(), ext_reg.end(), [] { return RandInt<u32>(0, ~u32(0)); });
|
2016-12-21 14:15:46 +00:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
instructions[0] = GenRandomInst(0, true);
|
2016-12-21 14:15:46 +00:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
const u32 start_address = 100;
|
2019-07-27 19:54:57 +01:00
|
|
|
const u32 cpsr = (RandInt<u32>(0, 0xF) << 28) | 0x10;
|
2019-04-26 12:06:10 +01:00
|
|
|
const u32 fpcr = RandomFpcr();
|
2016-11-23 21:45:18 +00:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
INFO("Instruction: 0x" << std::hex << instructions[0]);
|
2016-11-23 21:45:18 +00:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
regs[15] = start_address;
|
|
|
|
RunTestInstance(jit, uni, jit_env, uni_env, regs, ext_reg, instructions, cpsr, fpcr);
|
2016-11-23 21:45:18 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-16 18:18:29 +00:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
TEST_CASE("A32: Small random block", "[arm]") {
|
|
|
|
ArmTestEnv jit_env{};
|
|
|
|
ArmTestEnv uni_env{};
|
2017-02-16 18:18:29 +00:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
Dynarmic::A32::Jit jit{GetUserConfig(jit_env)};
|
|
|
|
A32Unicorn<ArmTestEnv> uni{uni_env};
|
2017-02-16 18:18:29 +00:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
A32Unicorn<ArmTestEnv>::RegisterArray regs;
|
|
|
|
A32Unicorn<ArmTestEnv>::ExtRegArray ext_reg;
|
|
|
|
std::vector<u32> instructions(5);
|
2017-02-16 18:18:29 +00:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
for (size_t iteration = 0; iteration < 100000; ++iteration) {
|
|
|
|
std::generate(regs.begin(), regs.end(), [] { return RandInt<u32>(0, ~u32(0)); });
|
|
|
|
std::generate(ext_reg.begin(), ext_reg.end(), [] { return RandInt<u32>(0, ~u32(0)); });
|
2017-02-16 18:18:29 +00:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
instructions[0] = GenRandomInst(0, false);
|
|
|
|
instructions[1] = GenRandomInst(4, false);
|
|
|
|
instructions[2] = GenRandomInst(8, false);
|
|
|
|
instructions[3] = GenRandomInst(12, false);
|
|
|
|
instructions[4] = GenRandomInst(16, true);
|
2017-02-16 18:18:29 +00:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
const u32 start_address = 100;
|
2019-07-27 19:54:57 +01:00
|
|
|
const u32 cpsr = (RandInt<u32>(0, 0xF) << 28) | 0x10;
|
2019-04-26 12:06:10 +01:00
|
|
|
const u32 fpcr = RandomFpcr();
|
2017-02-16 18:18:29 +00:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
INFO("Instruction 1: 0x" << std::hex << instructions[0]);
|
|
|
|
INFO("Instruction 2: 0x" << std::hex << instructions[1]);
|
|
|
|
INFO("Instruction 3: 0x" << std::hex << instructions[2]);
|
|
|
|
INFO("Instruction 4: 0x" << std::hex << instructions[3]);
|
|
|
|
INFO("Instruction 5: 0x" << std::hex << instructions[4]);
|
2017-02-16 18:18:29 +00:00
|
|
|
|
2019-04-26 12:06:10 +01:00
|
|
|
regs[15] = start_address;
|
|
|
|
RunTestInstance(jit, uni, jit_env, uni_env, regs, ext_reg, instructions, cpsr, fpcr);
|
|
|
|
}
|
2017-02-16 18:18:29 +00:00
|
|
|
}
|