2016-07-01 15:01:06 +02: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <set>
|
2016-07-04 15:37:50 +02:00
|
|
|
#include <unordered_map>
|
2016-07-01 15:01:06 +02:00
|
|
|
|
|
|
|
#include "backend_x64/reg_alloc.h"
|
|
|
|
#include "backend_x64/routines.h"
|
|
|
|
#include "common/x64/emitter.h"
|
2016-07-04 11:22:11 +02:00
|
|
|
#include "frontend/ir/ir.h"
|
2016-07-01 15:01:06 +02:00
|
|
|
#include "interface/interface.h"
|
|
|
|
|
|
|
|
namespace Dynarmic {
|
|
|
|
namespace BackendX64 {
|
|
|
|
|
|
|
|
class EmitX64 final {
|
|
|
|
public:
|
2016-07-07 11:53:09 +02:00
|
|
|
EmitX64(Gen::XEmitter* code, Routines* routines, UserCallbacks cb, Jit* jit_interface)
|
|
|
|
: reg_alloc(code), code(code), routines(routines), cb(cb), jit_interface(jit_interface) {}
|
2016-07-01 15:01:06 +02:00
|
|
|
|
2016-07-12 11:58:14 +02:00
|
|
|
CodePtr Emit(const Arm::LocationDescriptor descriptor, IR::Block ir);
|
2016-07-04 15:37:50 +02:00
|
|
|
|
|
|
|
CodePtr GetBasicBlock(Arm::LocationDescriptor descriptor) {
|
|
|
|
auto iter = basic_blocks.find(descriptor);
|
|
|
|
return iter != basic_blocks.end() ? iter->second : nullptr;
|
|
|
|
}
|
2016-07-01 15:01:06 +02:00
|
|
|
|
2016-07-14 13:52:53 +02:00
|
|
|
void ClearCache();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Microinstruction emitters
|
2016-07-01 15:01:06 +02:00
|
|
|
void EmitImmU1(IR::Value* value);
|
|
|
|
void EmitImmU8(IR::Value* value);
|
|
|
|
void EmitImmU32(IR::Value* value);
|
|
|
|
void EmitImmRegRef(IR::Value* value);
|
|
|
|
void EmitGetRegister(IR::Value* value);
|
|
|
|
void EmitSetRegister(IR::Value* value);
|
|
|
|
void EmitGetNFlag(IR::Value* value);
|
|
|
|
void EmitSetNFlag(IR::Value* value);
|
|
|
|
void EmitGetZFlag(IR::Value* value);
|
|
|
|
void EmitSetZFlag(IR::Value* value);
|
|
|
|
void EmitGetCFlag(IR::Value* value);
|
|
|
|
void EmitSetCFlag(IR::Value* value);
|
|
|
|
void EmitGetVFlag(IR::Value* value);
|
|
|
|
void EmitSetVFlag(IR::Value* value);
|
2016-07-12 11:58:14 +02:00
|
|
|
void EmitBXWritePC(IR::Value* value);
|
2016-07-14 15:04:43 +02:00
|
|
|
void EmitCallSupervisor(IR::Value* value);
|
2016-07-01 15:01:06 +02:00
|
|
|
void EmitGetCarryFromOp(IR::Value* value);
|
2016-07-08 11:09:18 +02:00
|
|
|
void EmitGetOverflowFromOp(IR::Value* value);
|
2016-07-12 00:06:35 +02:00
|
|
|
void EmitLeastSignificantHalf(IR::Value* value);
|
2016-07-01 15:01:06 +02:00
|
|
|
void EmitLeastSignificantByte(IR::Value* value);
|
|
|
|
void EmitMostSignificantBit(IR::Value* value);
|
|
|
|
void EmitIsZero(IR::Value* value);
|
|
|
|
void EmitLogicalShiftLeft(IR::Value* value);
|
|
|
|
void EmitLogicalShiftRight(IR::Value* value);
|
2016-07-04 11:22:11 +02:00
|
|
|
void EmitArithmeticShiftRight(IR::Value* value);
|
2016-07-10 02:18:17 +02:00
|
|
|
void EmitRotateRight(IR::Value* value);
|
2016-07-08 11:09:18 +02:00
|
|
|
void EmitAddWithCarry(IR::Value* value);
|
2016-07-08 12:49:30 +02:00
|
|
|
void EmitSubWithCarry(IR::Value* value);
|
2016-07-08 11:43:28 +02:00
|
|
|
void EmitAnd(IR::Value* value);
|
2016-07-08 12:14:50 +02:00
|
|
|
void EmitEor(IR::Value* value);
|
2016-07-10 03:06:38 +02:00
|
|
|
void EmitOr(IR::Value* value);
|
2016-07-10 04:44:45 +02:00
|
|
|
void EmitNot(IR::Value* value);
|
2016-07-16 20:23:42 +02:00
|
|
|
void EmitSignExtendHalfToWord(IR::Value* value);
|
|
|
|
void EmitSignExtendByteToWord(IR::Value* value);
|
|
|
|
void EmitZeroExtendHalfToWord(IR::Value* value);
|
|
|
|
void EmitZeroExtendByteToWord(IR::Value* value);
|
|
|
|
void EmitByteReverseWord(IR::Value* value);
|
|
|
|
void EmitByteReverseHalf(IR::Value* value);
|
2016-07-11 23:43:53 +02:00
|
|
|
void EmitReadMemory8(IR::Value* value);
|
|
|
|
void EmitReadMemory16(IR::Value* value);
|
|
|
|
void EmitReadMemory32(IR::Value* value);
|
|
|
|
void EmitReadMemory64(IR::Value* value);
|
|
|
|
void EmitWriteMemory8(IR::Value* value);
|
|
|
|
void EmitWriteMemory16(IR::Value* value);
|
|
|
|
void EmitWriteMemory32(IR::Value* value);
|
|
|
|
void EmitWriteMemory64(IR::Value* value);
|
2016-07-01 15:01:06 +02:00
|
|
|
|
2016-07-14 13:52:53 +02:00
|
|
|
// Helpers
|
2016-07-04 15:37:50 +02:00
|
|
|
void EmitAddCycles(size_t cycles);
|
2016-07-14 13:52:53 +02:00
|
|
|
void EmitCondPrelude(Arm::Cond cond,
|
|
|
|
boost::optional<Arm::LocationDescriptor> cond_failed,
|
|
|
|
Arm::LocationDescriptor current_location);
|
2016-07-07 11:53:09 +02:00
|
|
|
|
2016-07-14 13:52:53 +02:00
|
|
|
// Terminal instruction emitters
|
2016-07-07 11:53:09 +02:00
|
|
|
void EmitTerminal(IR::Terminal terminal, Arm::LocationDescriptor initial_location);
|
|
|
|
void EmitTerminalInterpret(IR::Term::Interpret terminal, Arm::LocationDescriptor initial_location);
|
|
|
|
void EmitTerminalReturnToDispatch(IR::Term::ReturnToDispatch terminal, Arm::LocationDescriptor initial_location);
|
|
|
|
void EmitTerminalLinkBlock(IR::Term::LinkBlock terminal, Arm::LocationDescriptor initial_location);
|
|
|
|
void EmitTerminalLinkBlockFast(IR::Term::LinkBlockFast terminal, Arm::LocationDescriptor initial_location);
|
|
|
|
void EmitTerminalPopRSBHint(IR::Term::PopRSBHint terminal, Arm::LocationDescriptor initial_location);
|
|
|
|
void EmitTerminalIf(IR::Term::If terminal, Arm::LocationDescriptor initial_location);
|
2016-07-01 15:01:06 +02:00
|
|
|
|
2016-07-14 13:52:53 +02:00
|
|
|
// Per-block state
|
2016-07-01 15:01:06 +02:00
|
|
|
std::set<IR::Value*> inhibit_emission;
|
|
|
|
RegAlloc reg_alloc;
|
2016-07-04 15:37:50 +02:00
|
|
|
|
2016-07-14 13:52:53 +02:00
|
|
|
// State
|
2016-07-04 15:37:50 +02:00
|
|
|
Gen::XEmitter* code;
|
2016-07-01 15:01:06 +02:00
|
|
|
Routines* routines;
|
|
|
|
UserCallbacks cb;
|
2016-07-07 11:53:09 +02:00
|
|
|
Jit* jit_interface;
|
2016-07-04 15:37:50 +02:00
|
|
|
std::unordered_map<Arm::LocationDescriptor, CodePtr, Arm::LocationDescriptorHash> basic_blocks;
|
2016-07-01 15:01:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace BackendX64
|
|
|
|
} // namespace Dynarmic
|