2016-09-02 05:07:14 +02:00
|
|
|
// Copyright 2016 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2016-12-11 02:11:16 +01:00
|
|
|
#include <cstring>
|
2016-09-20 17:21:23 +02:00
|
|
|
#include <dynarmic/dynarmic.h>
|
2016-09-02 05:07:14 +02:00
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/microprofile.h"
|
2016-09-21 08:52:38 +02:00
|
|
|
#include "core/arm/dynarmic/arm_dynarmic.h"
|
2016-09-02 05:07:14 +02:00
|
|
|
#include "core/core.h"
|
|
|
|
#include "core/core_timing.h"
|
2018-01-03 04:24:12 +01:00
|
|
|
#include "core/hle/kernel/svc.h"
|
2016-09-02 05:07:14 +02:00
|
|
|
#include "core/memory.h"
|
|
|
|
|
2017-08-29 03:09:42 +02:00
|
|
|
static void InterpreterFallback(u64 pc, Dynarmic::Jit* jit, void* user_arg) {
|
|
|
|
UNIMPLEMENTED_MSG("InterpreterFallback for ARM64 JIT does not exist!");
|
2016-09-02 05:07:14 +02:00
|
|
|
}
|
|
|
|
|
2017-08-29 03:09:42 +02:00
|
|
|
static bool IsReadOnlyMemory(u64 vaddr) {
|
2016-09-02 05:07:14 +02:00
|
|
|
// TODO(bunnei): ImplementMe
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-29 03:09:42 +02:00
|
|
|
u8 MemoryRead8(const u64 addr) {
|
|
|
|
return Memory::Read8(static_cast<VAddr>(addr));
|
|
|
|
}
|
|
|
|
|
|
|
|
u16 MemoryRead16(const u64 addr) {
|
|
|
|
return Memory::Read16(static_cast<VAddr>(addr));
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 MemoryRead32(const u64 addr) {
|
|
|
|
return Memory::Read32(static_cast<VAddr>(addr));
|
|
|
|
}
|
|
|
|
|
|
|
|
u64 MemoryRead64(const u64 addr) {
|
|
|
|
return Memory::Read64(static_cast<VAddr>(addr));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryWrite8(const u64 addr, const u8 data) {
|
|
|
|
Memory::Write8(static_cast<VAddr>(addr), data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryWrite16(const u64 addr, const u16 data) {
|
|
|
|
Memory::Write16(static_cast<VAddr>(addr), data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryWrite32(const u64 addr, const u32 data) {
|
|
|
|
Memory::Write32(static_cast<VAddr>(addr), data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryWrite64(const u64 addr, const u64 data) {
|
|
|
|
Memory::Write64(static_cast<VAddr>(addr), data);
|
|
|
|
}
|
|
|
|
|
2018-01-03 04:24:12 +01:00
|
|
|
static Dynarmic::UserCallbacks GetUserCallbacks(ARM_Interface* interpreter_fallback) {
|
2016-09-02 05:07:14 +02:00
|
|
|
Dynarmic::UserCallbacks user_callbacks{};
|
|
|
|
user_callbacks.InterpreterFallback = &InterpreterFallback;
|
2018-01-03 04:24:12 +01:00
|
|
|
user_callbacks.user_arg = static_cast<void*>(interpreter_fallback);
|
|
|
|
user_callbacks.CallSVC = &Kernel::CallSVC;
|
2017-02-03 00:31:07 +01:00
|
|
|
user_callbacks.memory.IsReadOnlyMemory = &IsReadOnlyMemory;
|
2017-08-29 03:09:42 +02:00
|
|
|
user_callbacks.memory.ReadCode = &MemoryRead32;
|
|
|
|
user_callbacks.memory.Read8 = &MemoryRead8;
|
|
|
|
user_callbacks.memory.Read16 = &MemoryRead16;
|
|
|
|
user_callbacks.memory.Read32 = &MemoryRead32;
|
|
|
|
user_callbacks.memory.Read64 = &MemoryRead64;
|
|
|
|
user_callbacks.memory.Write8 = &MemoryWrite8;
|
|
|
|
user_callbacks.memory.Write16 = &MemoryWrite16;
|
|
|
|
user_callbacks.memory.Write32 = &MemoryWrite32;
|
|
|
|
user_callbacks.memory.Write64 = &MemoryWrite64;
|
|
|
|
//user_callbacks.page_table = Memory::GetCurrentPageTablePointers();
|
2016-09-02 05:07:14 +02:00
|
|
|
return user_callbacks;
|
|
|
|
}
|
|
|
|
|
2018-01-03 04:24:12 +01:00
|
|
|
ARM_Dynarmic::ARM_Dynarmic() {
|
2016-09-02 05:07:14 +02:00
|
|
|
}
|
|
|
|
|
2017-10-10 05:56:20 +02:00
|
|
|
void ARM_Dynarmic::MapBackingMemory(VAddr address, size_t size, u8* memory, Kernel::VMAPermission perms) {
|
2016-09-02 05:07:14 +02:00
|
|
|
}
|
|
|
|
|
2017-08-29 03:09:42 +02:00
|
|
|
void ARM_Dynarmic::SetPC(u64 pc) {
|
|
|
|
jit->Regs64()[32] = pc;
|
2016-09-02 05:07:14 +02:00
|
|
|
}
|
|
|
|
|
2017-08-29 03:09:42 +02:00
|
|
|
u64 ARM_Dynarmic::GetPC() const {
|
|
|
|
return jit->Regs64()[32];
|
2016-09-02 05:07:14 +02:00
|
|
|
}
|
|
|
|
|
2017-08-29 03:09:42 +02:00
|
|
|
u64 ARM_Dynarmic::GetReg(int index) const {
|
|
|
|
return jit->Regs64()[index];
|
2016-09-02 05:07:14 +02:00
|
|
|
}
|
|
|
|
|
2017-08-29 03:09:42 +02:00
|
|
|
void ARM_Dynarmic::SetReg(int index, u64 value) {
|
|
|
|
jit->Regs64()[index] = value;
|
2016-09-02 05:07:14 +02:00
|
|
|
}
|
|
|
|
|
2017-10-10 05:56:20 +02:00
|
|
|
const u128& ARM_Dynarmic::GetExtReg(int index) const {
|
|
|
|
return jit->ExtRegs64()[index];
|
2016-09-02 05:07:14 +02:00
|
|
|
}
|
|
|
|
|
2017-10-10 05:56:20 +02:00
|
|
|
void ARM_Dynarmic::SetExtReg(int index, u128& value) {
|
|
|
|
jit->ExtRegs64()[index] = value;
|
2016-09-02 05:07:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 ARM_Dynarmic::GetVFPReg(int index) const {
|
2017-10-10 05:56:20 +02:00
|
|
|
return {};
|
2016-09-02 05:07:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM_Dynarmic::SetVFPReg(int index, u32 value) {
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 ARM_Dynarmic::GetCPSR() const {
|
|
|
|
return jit->Cpsr();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM_Dynarmic::SetCPSR(u32 cpsr) {
|
|
|
|
jit->Cpsr() = cpsr;
|
|
|
|
}
|
|
|
|
|
2017-09-30 20:16:39 +02:00
|
|
|
VAddr ARM_Dynarmic::GetTlsAddress() const {
|
|
|
|
return jit->TlsAddr();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM_Dynarmic::SetTlsAddress(VAddr address) {
|
|
|
|
jit->TlsAddr() = address;
|
|
|
|
}
|
|
|
|
|
2016-09-02 05:07:14 +02:00
|
|
|
MICROPROFILE_DEFINE(ARM_Jit, "ARM JIT", "ARM JIT", MP_RGB(255, 64, 64));
|
|
|
|
|
|
|
|
void ARM_Dynarmic::ExecuteInstructions(int num_instructions) {
|
2017-09-24 23:44:13 +02:00
|
|
|
ASSERT(Memory::GetCurrentPageTable() == current_page_table);
|
2016-09-02 05:07:14 +02:00
|
|
|
MICROPROFILE_SCOPE(ARM_Jit);
|
|
|
|
|
2017-08-19 18:33:01 +02:00
|
|
|
std::size_t ticks_executed = jit->Run(static_cast<unsigned>(num_instructions));
|
2016-09-02 05:07:14 +02:00
|
|
|
|
2017-09-30 18:25:49 +02:00
|
|
|
CoreTiming::AddTicks(ticks_executed);
|
2016-09-02 05:07:14 +02:00
|
|
|
}
|
|
|
|
|
2016-12-22 06:08:09 +01:00
|
|
|
void ARM_Dynarmic::SaveContext(ARM_Interface::ThreadContext& ctx) {
|
2017-08-29 03:09:42 +02:00
|
|
|
memcpy(ctx.cpu_registers, jit->Regs64().data(), sizeof(ctx.cpu_registers));
|
2017-10-10 05:56:20 +02:00
|
|
|
memcpy(ctx.fpu_registers, jit->ExtRegs64().data(), sizeof(ctx.fpu_registers));
|
2016-09-02 05:07:14 +02:00
|
|
|
|
2017-08-29 03:09:42 +02:00
|
|
|
ctx.lr = jit->Regs64()[30];
|
|
|
|
ctx.sp = jit->Regs64()[31];
|
|
|
|
ctx.pc = jit->Regs64()[32];
|
2016-09-02 05:07:14 +02:00
|
|
|
ctx.cpsr = jit->Cpsr();
|
|
|
|
|
2017-09-30 20:16:39 +02:00
|
|
|
// TODO(bunnei): Fix once we have proper support for tpidrro_el0, etc. in the JIT
|
|
|
|
ctx.tls_address = jit->TlsAddr();
|
2016-09-02 05:07:14 +02:00
|
|
|
}
|
|
|
|
|
2016-12-22 06:08:09 +01:00
|
|
|
void ARM_Dynarmic::LoadContext(const ARM_Interface::ThreadContext& ctx) {
|
2017-08-29 03:09:42 +02:00
|
|
|
memcpy(jit->Regs64().data(), ctx.cpu_registers, sizeof(ctx.cpu_registers));
|
2017-10-10 05:56:20 +02:00
|
|
|
memcpy(jit->ExtRegs64().data(), ctx.fpu_registers, sizeof(ctx.fpu_registers));
|
2016-09-02 05:07:14 +02:00
|
|
|
|
2017-08-29 03:09:42 +02:00
|
|
|
jit->Regs64()[30] = ctx.lr;
|
|
|
|
jit->Regs64()[31] = ctx.sp;
|
|
|
|
jit->Regs64()[32] = ctx.pc;
|
2016-09-02 05:07:14 +02:00
|
|
|
jit->Cpsr() = ctx.cpsr;
|
|
|
|
|
2017-09-30 20:16:39 +02:00
|
|
|
// TODO(bunnei): Fix once we have proper support for tpidrro_el0, etc. in the JIT
|
|
|
|
jit->TlsAddr() = ctx.tls_address;
|
2016-09-02 05:07:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ARM_Dynarmic::PrepareReschedule() {
|
|
|
|
if (jit->IsExecuting()) {
|
|
|
|
jit->HaltExecution();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARM_Dynarmic::ClearInstructionCache() {
|
|
|
|
jit->ClearCache();
|
|
|
|
}
|
2017-09-24 23:44:13 +02:00
|
|
|
|
|
|
|
void ARM_Dynarmic::PageTableChanged() {
|
|
|
|
current_page_table = Memory::GetCurrentPageTable();
|
|
|
|
|
|
|
|
auto iter = jits.find(current_page_table);
|
|
|
|
if (iter != jits.end()) {
|
|
|
|
jit = iter->second.get();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-10 05:56:20 +02:00
|
|
|
jit = new Dynarmic::Jit(GetUserCallbacks(this), Dynarmic::Arch::ARM64);
|
2017-09-24 23:44:13 +02:00
|
|
|
jits.emplace(current_page_table, std::unique_ptr<Dynarmic::Jit>(jit));
|
|
|
|
}
|