2016-07-01 14:01:06 +01:00
|
|
|
/* This file is part of the dynarmic project.
|
|
|
|
* Copyright (c) 2016 MerryMage
|
|
|
|
* This software may be used and distributed according to the terms of the GNU
|
|
|
|
* General Public License version 2 or any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <catch.hpp>
|
|
|
|
|
|
|
|
#include "common/common_types.h"
|
2016-07-04 14:37:50 +01:00
|
|
|
#include "interface/interface.h"
|
2016-07-07 10:53:09 +01:00
|
|
|
#include "skyeye_interpreter/dyncom/arm_dyncom_interpreter.h"
|
|
|
|
#include "skyeye_interpreter/skyeye_common/armstate.h"
|
2016-07-01 14:01:06 +01:00
|
|
|
|
2016-07-07 12:01:47 +01:00
|
|
|
static std::array<u16, 1024> code_mem{};
|
2016-07-07 10:53:09 +01:00
|
|
|
|
2016-07-07 12:01:47 +01:00
|
|
|
static u32 MemoryRead32(u32 vaddr);
|
|
|
|
static void InterpreterFallback(u32 pc, Dynarmic::Jit* jit);
|
|
|
|
static Dynarmic::UserCallbacks GetUserCallbacks();
|
2016-07-01 14:01:06 +01:00
|
|
|
|
2016-07-07 12:01:47 +01:00
|
|
|
static u32 MemoryRead32(u32 vaddr) {
|
2016-07-07 10:53:09 +01:00
|
|
|
if (vaddr < code_mem.size() * sizeof(u16)) {
|
|
|
|
size_t index = vaddr / sizeof(u16);
|
|
|
|
return code_mem[index] | (code_mem[index+1] << 16);
|
2016-07-04 14:37:50 +01:00
|
|
|
}
|
|
|
|
return vaddr;
|
|
|
|
}
|
2016-07-01 14:01:06 +01:00
|
|
|
|
2016-07-07 12:01:47 +01:00
|
|
|
static void InterpreterFallback(u32 pc, Dynarmic::Jit* jit) {
|
2016-07-07 10:53:09 +01:00
|
|
|
ARMul_State interp_state{USER32MODE};
|
|
|
|
interp_state.user_callbacks = GetUserCallbacks();
|
|
|
|
interp_state.NumInstrsToExecute = 1;
|
|
|
|
|
|
|
|
interp_state.Reg = jit->Regs();
|
|
|
|
interp_state.Cpsr = jit->Cpsr();
|
|
|
|
interp_state.Reg[15] = pc;
|
|
|
|
|
|
|
|
InterpreterClearCache();
|
|
|
|
InterpreterMainLoop(&interp_state);
|
|
|
|
|
|
|
|
jit->Regs() = interp_state.Reg;
|
|
|
|
jit->Cpsr() = interp_state.Cpsr;
|
|
|
|
}
|
|
|
|
|
2016-07-07 12:01:47 +01:00
|
|
|
static Dynarmic::UserCallbacks GetUserCallbacks() {
|
2016-07-04 14:37:50 +01:00
|
|
|
Dynarmic::UserCallbacks user_callbacks{};
|
|
|
|
user_callbacks.MemoryRead32 = &MemoryRead32;
|
2016-07-07 10:53:09 +01:00
|
|
|
user_callbacks.InterpreterFallback = &InterpreterFallback;
|
2016-07-04 14:37:50 +01:00
|
|
|
return user_callbacks;
|
2016-07-01 14:01:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE( "thumb: lsls r0, r1, #2", "[thumb]" ) {
|
2016-07-04 14:37:50 +01:00
|
|
|
Dynarmic::Jit jit{GetUserCallbacks()};
|
|
|
|
code_mem.fill({});
|
|
|
|
code_mem[0] = 0x0088; // lsls r0, r1, #2
|
2016-07-07 10:53:09 +01:00
|
|
|
code_mem[1] = 0xE7FE; // b +#0
|
2016-07-04 14:37:50 +01:00
|
|
|
|
|
|
|
jit.Regs()[0] = 1;
|
|
|
|
jit.Regs()[1] = 2;
|
|
|
|
jit.Regs()[15] = 0; // PC = 0
|
|
|
|
jit.Cpsr() = 0x00000030; // Thumb, User-mode
|
2016-07-01 14:01:06 +01:00
|
|
|
|
2016-07-04 14:37:50 +01:00
|
|
|
jit.Run(1);
|
2016-07-01 14:01:06 +01:00
|
|
|
|
2016-07-04 14:37:50 +01:00
|
|
|
REQUIRE( jit.Regs()[0] == 8 );
|
|
|
|
REQUIRE( jit.Regs()[1] == 2 );
|
2016-07-07 10:53:09 +01:00
|
|
|
REQUIRE( jit.Regs()[15] == 2 );
|
2016-07-04 14:37:50 +01:00
|
|
|
REQUIRE( jit.Cpsr() == 0x00000030 );
|
2016-07-01 14:01:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE( "thumb: lsls r0, r1, #31", "[thumb]" ) {
|
2016-07-04 14:37:50 +01:00
|
|
|
Dynarmic::Jit jit{GetUserCallbacks()};
|
|
|
|
code_mem.fill({});
|
|
|
|
code_mem[0] = 0x07C8; // lsls r0, r1, #31
|
2016-07-07 10:53:09 +01:00
|
|
|
code_mem[1] = 0xE7FE; // b +#0
|
2016-07-04 14:37:50 +01:00
|
|
|
|
|
|
|
jit.Regs()[0] = 1;
|
|
|
|
jit.Regs()[1] = 0xFFFFFFFF;
|
|
|
|
jit.Regs()[15] = 0; // PC = 0
|
|
|
|
jit.Cpsr() = 0x00000030; // Thumb, User-mode
|
2016-07-01 14:01:06 +01:00
|
|
|
|
2016-07-04 14:37:50 +01:00
|
|
|
jit.Run(1);
|
2016-07-01 14:01:06 +01:00
|
|
|
|
2016-07-04 14:37:50 +01:00
|
|
|
REQUIRE( jit.Regs()[0] == 0x80000000 );
|
|
|
|
REQUIRE( jit.Regs()[1] == 0xffffffff );
|
2016-07-07 10:53:09 +01:00
|
|
|
REQUIRE( jit.Regs()[15] == 2 );
|
2016-07-07 14:51:47 +01:00
|
|
|
REQUIRE( jit.Cpsr() == 0xA0000030 ); // N, C flags, Thumb, User-mode
|
2016-07-01 14:01:06 +01:00
|
|
|
}
|