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.
|
|
|
|
*/
|
|
|
|
|
2016-07-07 11:53:09 +02:00
|
|
|
#include "common/assert.h"
|
2016-07-14 15:39:43 +02:00
|
|
|
#include "ir_emitter.h"
|
2016-07-01 15:01:06 +02:00
|
|
|
|
|
|
|
namespace Dynarmic {
|
|
|
|
namespace Arm {
|
|
|
|
|
|
|
|
void IREmitter::Unimplemented() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-07-11 23:43:53 +02:00
|
|
|
u32 IREmitter::PC() {
|
2016-08-01 21:03:13 +02:00
|
|
|
u32 offset = current_location.TFlag() ? 4 : 8;
|
|
|
|
return current_location.PC() + offset;
|
2016-07-11 23:43:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 IREmitter::AlignPC(size_t alignment) {
|
|
|
|
u32 pc = PC();
|
|
|
|
return static_cast<u32>(pc - pc % alignment);
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::Imm1(bool imm1) {
|
|
|
|
return IR::Value(imm1);
|
2016-07-08 11:09:18 +02:00
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::Imm8(u8 imm8) {
|
|
|
|
return IR::Value(imm8);
|
2016-07-01 15:01:06 +02:00
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::Imm32(u32 imm32) {
|
|
|
|
return IR::Value(imm32);
|
2016-07-08 11:09:18 +02:00
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::GetRegister(Reg reg) {
|
2016-07-08 11:09:18 +02:00
|
|
|
if (reg == Reg::PC) {
|
2016-07-11 23:43:53 +02:00
|
|
|
return Imm32(PC());
|
2016-07-08 11:09:18 +02:00
|
|
|
}
|
2016-07-23 00:55:00 +02:00
|
|
|
return Inst(IR::Opcode::GetRegister, { IR::Value(reg) });
|
2016-07-01 15:01:06 +02:00
|
|
|
}
|
|
|
|
|
2016-08-05 19:54:19 +02:00
|
|
|
IR::Value IREmitter::GetExtendedRegister(ExtReg reg) {
|
|
|
|
if (reg >= Arm::ExtReg::S0 && reg <= Arm::ExtReg::S31) {
|
|
|
|
return Inst(IR::Opcode::GetExtendedRegister32, {IR::Value(reg)});
|
|
|
|
} else if (reg >= Arm::ExtReg::D0 && reg <= Arm::ExtReg::D31) {
|
|
|
|
return Inst(IR::Opcode::GetExtendedRegister64, {IR::Value(reg)});
|
|
|
|
} else {
|
|
|
|
ASSERT_MSG(false, "Invalid reg.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
void IREmitter::SetRegister(const Reg reg, const IR::Value& value) {
|
2016-07-11 23:43:53 +02:00
|
|
|
ASSERT(reg != Reg::PC);
|
2016-07-23 00:55:00 +02:00
|
|
|
Inst(IR::Opcode::SetRegister, { IR::Value(reg), value });
|
2016-07-01 15:01:06 +02:00
|
|
|
}
|
|
|
|
|
2016-08-05 19:54:19 +02:00
|
|
|
void IREmitter::SetExtendedRegister(const ExtReg reg, const IR::Value& value) {
|
|
|
|
if (reg >= Arm::ExtReg::S0 && reg <= Arm::ExtReg::S31) {
|
|
|
|
Inst(IR::Opcode::SetExtendedRegister32, {IR::Value(reg), value});
|
|
|
|
} else if (reg >= Arm::ExtReg::D0 && reg <= Arm::ExtReg::D31) {
|
|
|
|
Inst(IR::Opcode::SetExtendedRegister64, {IR::Value(reg), value});
|
|
|
|
} else {
|
|
|
|
ASSERT_MSG(false, "Invalid reg.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
void IREmitter::ALUWritePC(const IR::Value& value) {
|
2016-07-08 11:09:18 +02:00
|
|
|
// This behaviour is ARM version-dependent.
|
2016-07-12 11:58:14 +02:00
|
|
|
// The below implementation is for ARMv6k
|
2016-07-18 22:04:39 +02:00
|
|
|
BranchWritePC(value);
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
void IREmitter::BranchWritePC(const IR::Value& value) {
|
2016-08-01 21:03:13 +02:00
|
|
|
if (!current_location.TFlag()) {
|
2016-07-12 11:58:14 +02:00
|
|
|
auto new_pc = And(value, Imm32(0xFFFFFFFC));
|
2016-07-23 00:55:00 +02:00
|
|
|
Inst(IR::Opcode::SetRegister, { IR::Value(Reg::PC), new_pc });
|
2016-07-12 11:58:14 +02:00
|
|
|
} else {
|
|
|
|
auto new_pc = And(value, Imm32(0xFFFFFFFE));
|
2016-07-23 00:55:00 +02:00
|
|
|
Inst(IR::Opcode::SetRegister, { IR::Value(Reg::PC), new_pc });
|
2016-07-12 11:58:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
void IREmitter::BXWritePC(const IR::Value& value) {
|
2016-07-18 22:04:39 +02:00
|
|
|
Inst(IR::Opcode::BXWritePC, {value});
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
void IREmitter::LoadWritePC(const IR::Value& value) {
|
2016-07-12 11:58:14 +02:00
|
|
|
// This behaviour is ARM version-dependent.
|
|
|
|
// The below implementation is for ARMv6k
|
2016-07-18 22:04:39 +02:00
|
|
|
BXWritePC(value);
|
2016-07-08 11:09:18 +02:00
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
void IREmitter::CallSupervisor(const IR::Value& value) {
|
2016-07-14 15:04:43 +02:00
|
|
|
Inst(IR::Opcode::CallSupervisor, {value});
|
|
|
|
}
|
|
|
|
|
2016-08-13 01:10:23 +02:00
|
|
|
void IREmitter::PushRSB(const LocationDescriptor& return_location) {
|
|
|
|
Inst(IR::Opcode::PushRSB, {IR::Value(return_location.UniqueHash())});
|
|
|
|
}
|
|
|
|
|
2016-08-14 20:39:16 +02:00
|
|
|
IR::Value IREmitter::GetCpsr() {
|
|
|
|
return Inst(IR::Opcode::GetCpsr, {});
|
|
|
|
}
|
|
|
|
|
|
|
|
void IREmitter::SetCpsr(const IR::Value& value) {
|
|
|
|
Inst(IR::Opcode::SetCpsr, {value});
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::GetCFlag() {
|
2016-07-01 15:01:06 +02:00
|
|
|
return Inst(IR::Opcode::GetCFlag, {});
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
void IREmitter::SetNFlag(const IR::Value& value) {
|
2016-07-01 15:01:06 +02:00
|
|
|
Inst(IR::Opcode::SetNFlag, {value});
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
void IREmitter::SetZFlag(const IR::Value& value) {
|
2016-07-01 15:01:06 +02:00
|
|
|
Inst(IR::Opcode::SetZFlag, {value});
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
void IREmitter::SetCFlag(const IR::Value& value) {
|
2016-07-01 15:01:06 +02:00
|
|
|
Inst(IR::Opcode::SetCFlag, {value});
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
void IREmitter::SetVFlag(const IR::Value& value) {
|
2016-07-08 11:09:18 +02:00
|
|
|
Inst(IR::Opcode::SetVFlag, {value});
|
|
|
|
}
|
|
|
|
|
2016-08-06 23:04:52 +02:00
|
|
|
void IREmitter::OrQFlag(const IR::Value& value) {
|
|
|
|
Inst(IR::Opcode::OrQFlag, {value});
|
|
|
|
}
|
|
|
|
|
2016-08-04 23:04:42 +02:00
|
|
|
IR::Value IREmitter::Pack2x32To1x64(const IR::Value& lo, const IR::Value& hi)
|
|
|
|
{
|
|
|
|
return Inst(IR::Opcode::Pack2x32To1x64, {lo, hi});
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::LeastSignificantWord(const IR::Value& value) {
|
|
|
|
return Inst(IR::Opcode::LeastSignificantWord, {value});
|
|
|
|
}
|
|
|
|
|
2016-08-06 22:03:57 +02:00
|
|
|
IREmitter::ResultAndCarry IREmitter::MostSignificantWord(const IR::Value& value) {
|
|
|
|
auto result = Inst(IR::Opcode::MostSignificantWord, {value});
|
|
|
|
auto carry_out = Inst(IR::Opcode::GetCarryFromOp, {result});
|
|
|
|
return {result, carry_out};
|
2016-08-04 23:04:42 +02:00
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::LeastSignificantHalf(const IR::Value& value) {
|
2016-07-12 00:06:35 +02:00
|
|
|
return Inst(IR::Opcode::LeastSignificantHalf, {value});
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::LeastSignificantByte(const IR::Value& value) {
|
2016-07-01 15:01:06 +02:00
|
|
|
return Inst(IR::Opcode::LeastSignificantByte, {value});
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::MostSignificantBit(const IR::Value& value) {
|
2016-07-01 15:01:06 +02:00
|
|
|
return Inst(IR::Opcode::MostSignificantBit, {value});
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::IsZero(const IR::Value& value) {
|
2016-07-01 15:01:06 +02:00
|
|
|
return Inst(IR::Opcode::IsZero, {value});
|
|
|
|
}
|
|
|
|
|
2016-08-04 23:04:42 +02:00
|
|
|
IR::Value IREmitter::IsZero64(const IR::Value& value) {
|
|
|
|
return Inst(IR::Opcode::IsZero64, {value});
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IREmitter::ResultAndCarry IREmitter::LogicalShiftLeft(const IR::Value& value_in, const IR::Value& shift_amount, const IR::Value& carry_in) {
|
2016-07-01 15:01:06 +02:00
|
|
|
auto result = Inst(IR::Opcode::LogicalShiftLeft, {value_in, shift_amount, carry_in});
|
|
|
|
auto carry_out = Inst(IR::Opcode::GetCarryFromOp, {result});
|
|
|
|
return {result, carry_out};
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IREmitter::ResultAndCarry IREmitter::LogicalShiftRight(const IR::Value& value_in, const IR::Value& shift_amount, const IR::Value& carry_in) {
|
2016-07-01 15:01:06 +02:00
|
|
|
auto result = Inst(IR::Opcode::LogicalShiftRight, {value_in, shift_amount, carry_in});
|
|
|
|
auto carry_out = Inst(IR::Opcode::GetCarryFromOp, {result});
|
|
|
|
return {result, carry_out};
|
|
|
|
}
|
|
|
|
|
2016-08-07 15:23:33 +02:00
|
|
|
IR::Value IREmitter::LogicalShiftRight64(const IR::Value& value_in, const IR::Value& shift_amount) {
|
|
|
|
return Inst(IR::Opcode::LogicalShiftRight64, {value_in, shift_amount});
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IREmitter::ResultAndCarry IREmitter::ArithmeticShiftRight(const IR::Value& value_in, const IR::Value& shift_amount, const IR::Value& carry_in) {
|
2016-07-04 11:22:11 +02:00
|
|
|
auto result = Inst(IR::Opcode::ArithmeticShiftRight, {value_in, shift_amount, carry_in});
|
|
|
|
auto carry_out = Inst(IR::Opcode::GetCarryFromOp, {result});
|
|
|
|
return {result, carry_out};
|
|
|
|
}
|
2016-07-01 15:01:06 +02:00
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IREmitter::ResultAndCarry IREmitter::RotateRight(const IR::Value& value_in, const IR::Value& shift_amount, const IR::Value& carry_in) {
|
2016-07-10 02:18:17 +02:00
|
|
|
auto result = Inst(IR::Opcode::RotateRight, {value_in, shift_amount, carry_in});
|
|
|
|
auto carry_out = Inst(IR::Opcode::GetCarryFromOp, {result});
|
|
|
|
return {result, carry_out};
|
|
|
|
}
|
|
|
|
|
2016-07-31 20:07:35 +02:00
|
|
|
IREmitter::ResultAndCarry IREmitter::RotateRightExtended(const IR::Value& value_in, const IR::Value& carry_in) {
|
|
|
|
auto result = Inst(IR::Opcode::RotateRightExtended, {value_in, carry_in});
|
|
|
|
auto carry_out = Inst(IR::Opcode::GetCarryFromOp, {result});
|
|
|
|
return {result, carry_out};
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IREmitter::ResultAndCarryAndOverflow IREmitter::AddWithCarry(const IR::Value& a, const IR::Value& b, const IR::Value& carry_in) {
|
2016-07-08 11:09:18 +02:00
|
|
|
auto result = Inst(IR::Opcode::AddWithCarry, {a, b, carry_in});
|
|
|
|
auto carry_out = Inst(IR::Opcode::GetCarryFromOp, {result});
|
|
|
|
auto overflow = Inst(IR::Opcode::GetOverflowFromOp, {result});
|
|
|
|
return {result, carry_out, overflow};
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::Add(const IR::Value& a, const IR::Value& b) {
|
2016-07-11 23:43:53 +02:00
|
|
|
return Inst(IR::Opcode::AddWithCarry, {a, b, Imm1(0)});
|
|
|
|
}
|
|
|
|
|
2016-08-04 23:04:42 +02:00
|
|
|
IR::Value IREmitter::Add64(const IR::Value& a, const IR::Value& b) {
|
|
|
|
return Inst(IR::Opcode::Add64, {a, b});
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IREmitter::ResultAndCarryAndOverflow IREmitter::SubWithCarry(const IR::Value& a, const IR::Value& b, const IR::Value& carry_in) {
|
2016-07-08 12:49:30 +02:00
|
|
|
// This is equivalent to AddWithCarry(a, Not(b), carry_in).
|
|
|
|
auto result = Inst(IR::Opcode::SubWithCarry, {a, b, carry_in});
|
|
|
|
auto carry_out = Inst(IR::Opcode::GetCarryFromOp, {result});
|
|
|
|
auto overflow = Inst(IR::Opcode::GetOverflowFromOp, {result});
|
|
|
|
return {result, carry_out, overflow};
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::Sub(const IR::Value& a, const IR::Value& b) {
|
2016-07-18 16:11:16 +02:00
|
|
|
return Inst(IR::Opcode::SubWithCarry, {a, b, Imm1(1)});
|
|
|
|
}
|
|
|
|
|
2016-08-06 07:09:47 +02:00
|
|
|
IR::Value IREmitter::Sub64(const IR::Value& a, const IR::Value& b) {
|
|
|
|
return Inst(IR::Opcode::Sub64, {a, b});
|
|
|
|
}
|
|
|
|
|
2016-08-04 23:04:42 +02:00
|
|
|
IR::Value IREmitter::Mul(const IR::Value& a, const IR::Value& b) {
|
|
|
|
return Inst(IR::Opcode::Mul, {a, b});
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::Mul64(const IR::Value& a, const IR::Value& b) {
|
|
|
|
return Inst(IR::Opcode::Mul64, {a, b});
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::And(const IR::Value& a, const IR::Value& b) {
|
2016-07-08 11:43:28 +02:00
|
|
|
return Inst(IR::Opcode::And, {a, b});
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::Eor(const IR::Value& a, const IR::Value& b) {
|
2016-07-08 12:14:50 +02:00
|
|
|
return Inst(IR::Opcode::Eor, {a, b});
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::Or(const IR::Value& a, const IR::Value& b) {
|
2016-07-10 03:06:38 +02:00
|
|
|
return Inst(IR::Opcode::Or, {a, b});
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::Not(const IR::Value& a) {
|
2016-07-10 04:44:45 +02:00
|
|
|
return Inst(IR::Opcode::Not, {a});
|
|
|
|
}
|
|
|
|
|
2016-08-04 23:04:42 +02:00
|
|
|
IR::Value IREmitter::SignExtendWordToLong(const IR::Value& a) {
|
|
|
|
return Inst(IR::Opcode::SignExtendWordToLong, {a});
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::SignExtendHalfToWord(const IR::Value& a) {
|
2016-07-16 20:23:42 +02:00
|
|
|
return Inst(IR::Opcode::SignExtendHalfToWord, {a});
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::SignExtendByteToWord(const IR::Value& a) {
|
2016-07-16 20:23:42 +02:00
|
|
|
return Inst(IR::Opcode::SignExtendByteToWord, {a});
|
|
|
|
}
|
|
|
|
|
2016-08-04 23:04:42 +02:00
|
|
|
IR::Value IREmitter::ZeroExtendWordToLong(const IR::Value& a) {
|
|
|
|
return Inst(IR::Opcode::ZeroExtendWordToLong, {a});
|
2016-07-16 20:23:42 +02:00
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::ZeroExtendHalfToWord(const IR::Value& a) {
|
2016-07-16 20:23:42 +02:00
|
|
|
return Inst(IR::Opcode::ZeroExtendHalfToWord, {a});
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::ZeroExtendByteToWord(const IR::Value& a) {
|
2016-07-16 20:23:42 +02:00
|
|
|
return Inst(IR::Opcode::ZeroExtendByteToWord, {a});
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::ByteReverseWord(const IR::Value& a) {
|
2016-07-16 20:23:42 +02:00
|
|
|
return Inst(IR::Opcode::ByteReverseWord, {a});
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::ByteReverseHalf(const IR::Value& a) {
|
2016-07-16 20:23:42 +02:00
|
|
|
return Inst(IR::Opcode::ByteReverseHalf, {a});
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::ByteReverseDual(const IR::Value& a) {
|
2016-07-20 16:34:17 +02:00
|
|
|
return Inst(IR::Opcode::ByteReverseDual, {a});
|
|
|
|
}
|
2016-07-16 20:23:42 +02:00
|
|
|
|
2016-08-12 19:26:14 +02:00
|
|
|
IR::Value IREmitter::PackedSaturatedAddU8(const IR::Value& a, const IR::Value& b) {
|
|
|
|
return Inst(IR::Opcode::PackedSaturatedAddU8, {a, b});
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::PackedSaturatedAddS8(const IR::Value& a, const IR::Value& b) {
|
|
|
|
return Inst(IR::Opcode::PackedSaturatedAddS8, {a, b});
|
|
|
|
}
|
|
|
|
|
2016-08-12 17:53:16 +02:00
|
|
|
IR::Value IREmitter::PackedSaturatedSubU8(const IR::Value& a, const IR::Value& b) {
|
|
|
|
return Inst(IR::Opcode::PackedSaturatedSubU8, {a, b});
|
|
|
|
}
|
|
|
|
|
2016-08-12 19:18:38 +02:00
|
|
|
IR::Value IREmitter::PackedSaturatedSubS8(const IR::Value& a, const IR::Value& b) {
|
|
|
|
return Inst(IR::Opcode::PackedSaturatedSubS8, {a, b});
|
|
|
|
}
|
|
|
|
|
2016-08-12 19:42:16 +02:00
|
|
|
IR::Value IREmitter::PackedSaturatedAddU16(const IR::Value& a, const IR::Value& b) {
|
|
|
|
return Inst(IR::Opcode::PackedSaturatedAddU16, {a, b});
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::PackedSaturatedAddS16(const IR::Value& a, const IR::Value& b) {
|
|
|
|
return Inst(IR::Opcode::PackedSaturatedAddS16, {a, b});
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::PackedSaturatedSubU16(const IR::Value& a, const IR::Value& b) {
|
|
|
|
return Inst(IR::Opcode::PackedSaturatedSubU16, {a, b});
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::PackedSaturatedSubS16(const IR::Value& a, const IR::Value& b) {
|
|
|
|
return Inst(IR::Opcode::PackedSaturatedSubS16, {a, b});
|
|
|
|
}
|
|
|
|
|
2016-08-07 20:25:12 +02:00
|
|
|
IR::Value IREmitter::TransferToFP32(const IR::Value& a) {
|
|
|
|
return Inst(IR::Opcode::TransferToFP32, {a});
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::TransferToFP64(const IR::Value& a) {
|
|
|
|
return Inst(IR::Opcode::TransferToFP64, {a});
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::TransferFromFP32(const IR::Value& a) {
|
|
|
|
return Inst(IR::Opcode::TransferFromFP32, {a});
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::TransferFromFP64(const IR::Value& a) {
|
|
|
|
return Inst(IR::Opcode::TransferFromFP64, {a});
|
|
|
|
}
|
|
|
|
|
2016-08-07 02:27:18 +02:00
|
|
|
IR::Value IREmitter::FPAbs32(const IR::Value& a) {
|
|
|
|
return Inst(IR::Opcode::FPAbs32, {a});
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::FPAbs64(const IR::Value& a) {
|
|
|
|
return Inst(IR::Opcode::FPAbs64, {a});
|
|
|
|
}
|
|
|
|
|
2016-08-06 18:21:29 +02:00
|
|
|
IR::Value IREmitter::FPAdd32(const IR::Value& a, const IR::Value& b, bool fpscr_controlled) {
|
|
|
|
ASSERT(fpscr_controlled);
|
|
|
|
return Inst(IR::Opcode::FPAdd32, {a, b});
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::FPAdd64(const IR::Value& a, const IR::Value& b, bool fpscr_controlled) {
|
|
|
|
ASSERT(fpscr_controlled);
|
|
|
|
return Inst(IR::Opcode::FPAdd64, {a, b});
|
|
|
|
}
|
|
|
|
|
2016-08-07 11:56:12 +02:00
|
|
|
IR::Value IREmitter::FPDiv32(const IR::Value& a, const IR::Value& b, bool fpscr_controlled) {
|
|
|
|
ASSERT(fpscr_controlled);
|
|
|
|
return Inst(IR::Opcode::FPDiv32, {a, b});
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::FPDiv64(const IR::Value& a, const IR::Value& b, bool fpscr_controlled) {
|
|
|
|
ASSERT(fpscr_controlled);
|
|
|
|
return Inst(IR::Opcode::FPDiv64, {a, b});
|
|
|
|
}
|
|
|
|
|
2016-08-07 11:21:14 +02:00
|
|
|
IR::Value IREmitter::FPMul32(const IR::Value& a, const IR::Value& b, bool fpscr_controlled) {
|
|
|
|
ASSERT(fpscr_controlled);
|
|
|
|
return Inst(IR::Opcode::FPMul32, {a, b});
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::FPMul64(const IR::Value& a, const IR::Value& b, bool fpscr_controlled) {
|
|
|
|
ASSERT(fpscr_controlled);
|
|
|
|
return Inst(IR::Opcode::FPMul64, {a, b});
|
|
|
|
}
|
|
|
|
|
2016-08-07 11:56:12 +02:00
|
|
|
IR::Value IREmitter::FPNeg32(const IR::Value& a) {
|
|
|
|
return Inst(IR::Opcode::FPNeg32, {a});
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::FPNeg64(const IR::Value& a) {
|
|
|
|
return Inst(IR::Opcode::FPNeg64, {a});
|
|
|
|
}
|
|
|
|
|
2016-08-07 13:19:07 +02:00
|
|
|
IR::Value IREmitter::FPSqrt32(const IR::Value& a) {
|
|
|
|
return Inst(IR::Opcode::FPSqrt32, {a});
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::FPSqrt64(const IR::Value& a) {
|
|
|
|
return Inst(IR::Opcode::FPSqrt64, {a});
|
|
|
|
}
|
2016-08-07 11:56:12 +02:00
|
|
|
|
2016-08-07 02:41:25 +02:00
|
|
|
IR::Value IREmitter::FPSub32(const IR::Value& a, const IR::Value& b, bool fpscr_controlled) {
|
|
|
|
ASSERT(fpscr_controlled);
|
|
|
|
return Inst(IR::Opcode::FPSub32, {a, b});
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::FPSub64(const IR::Value& a, const IR::Value& b, bool fpscr_controlled) {
|
|
|
|
ASSERT(fpscr_controlled);
|
|
|
|
return Inst(IR::Opcode::FPSub64, {a, b});
|
|
|
|
}
|
|
|
|
|
2016-08-23 23:04:46 +02:00
|
|
|
IR::Value IREmitter::FPDoubleToSingle(const IR::Value& a, bool fpscr_controlled) {
|
|
|
|
ASSERT(fpscr_controlled);
|
|
|
|
return Inst(IR::Opcode::FPDoubleToSingle, {a});
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::FPSingleToDouble(const IR::Value& a, bool fpscr_controlled) {
|
|
|
|
ASSERT(fpscr_controlled);
|
|
|
|
return Inst(IR::Opcode::FPSingleToDouble, {a});
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::FPSingleToS32(const IR::Value& a, bool round_towards_zero, bool fpscr_controlled) {
|
|
|
|
ASSERT(fpscr_controlled);
|
|
|
|
return Inst(IR::Opcode::FPSingleToS32, {a, Imm1(round_towards_zero)});
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::FPSingleToU32(const IR::Value& a, bool round_towards_zero, bool fpscr_controlled) {
|
|
|
|
ASSERT(fpscr_controlled);
|
|
|
|
return Inst(IR::Opcode::FPSingleToU32, {a, Imm1(round_towards_zero)});
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::FPDoubleToS32(const IR::Value& a, bool round_towards_zero, bool fpscr_controlled) {
|
|
|
|
ASSERT(fpscr_controlled);
|
|
|
|
return Inst(IR::Opcode::FPDoubleToS32, {a, Imm1(round_towards_zero)});
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::FPDoubleToU32(const IR::Value& a, bool round_towards_zero, bool fpscr_controlled) {
|
|
|
|
ASSERT(fpscr_controlled);
|
|
|
|
return Inst(IR::Opcode::FPDoubleToU32, {a, Imm1(round_towards_zero)});
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::FPS32ToSingle(const IR::Value& a, bool round_to_nearest, bool fpscr_controlled) {
|
|
|
|
ASSERT(fpscr_controlled);
|
|
|
|
return Inst(IR::Opcode::FPS32ToSingle, {a, Imm1(round_to_nearest)});
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::FPU32ToSingle(const IR::Value& a, bool round_to_nearest, bool fpscr_controlled) {
|
|
|
|
ASSERT(fpscr_controlled);
|
|
|
|
return Inst(IR::Opcode::FPU32ToSingle, {a, Imm1(round_to_nearest)});
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::FPS32ToDouble(const IR::Value& a, bool round_to_nearest, bool fpscr_controlled) {
|
|
|
|
ASSERT(fpscr_controlled);
|
|
|
|
return Inst(IR::Opcode::FPS32ToDouble, {a, Imm1(round_to_nearest)});
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::FPU32ToDouble(const IR::Value& a, bool round_to_nearest, bool fpscr_controlled) {
|
|
|
|
ASSERT(fpscr_controlled);
|
|
|
|
return Inst(IR::Opcode::FPU32ToDouble, {a, Imm1(round_to_nearest)});
|
|
|
|
}
|
|
|
|
|
TranslateArm: Implement CLREX, LDREX, LDREXB, LDREXD, LDREXH, STREX, STREXB, STREXD, STREXH, SWP, SWPB
2016-08-09 23:48:20 +02:00
|
|
|
void IREmitter::ClearExlcusive() {
|
|
|
|
Inst(IR::Opcode::ClearExclusive, {});
|
|
|
|
}
|
|
|
|
|
|
|
|
void IREmitter::SetExclusive(const IR::Value& vaddr, size_t byte_size) {
|
|
|
|
ASSERT(byte_size == 1 || byte_size == 2 || byte_size == 4 || byte_size == 8 || byte_size == 16);
|
|
|
|
Inst(IR::Opcode::SetExclusive, {vaddr, Imm8(u8(byte_size))});
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::ReadMemory8(const IR::Value& vaddr) {
|
2016-07-11 23:43:53 +02:00
|
|
|
return Inst(IR::Opcode::ReadMemory8, {vaddr});
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::ReadMemory16(const IR::Value& vaddr) {
|
2016-07-20 16:34:17 +02:00
|
|
|
auto value = Inst(IR::Opcode::ReadMemory16, {vaddr});
|
2016-08-01 21:03:13 +02:00
|
|
|
return current_location.EFlag() ? ByteReverseHalf(value) : value;
|
2016-07-11 23:43:53 +02:00
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::ReadMemory32(const IR::Value& vaddr) {
|
2016-07-20 16:34:17 +02:00
|
|
|
auto value = Inst(IR::Opcode::ReadMemory32, {vaddr});
|
2016-08-01 21:03:13 +02:00
|
|
|
return current_location.EFlag() ? ByteReverseWord(value) : value;
|
2016-07-11 23:43:53 +02:00
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::ReadMemory64(const IR::Value& vaddr) {
|
2016-07-20 16:34:17 +02:00
|
|
|
auto value = Inst(IR::Opcode::ReadMemory64, {vaddr});
|
2016-08-01 21:03:13 +02:00
|
|
|
return current_location.EFlag() ? ByteReverseDual(value) : value;
|
2016-07-11 23:43:53 +02:00
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
void IREmitter::WriteMemory8(const IR::Value& vaddr, const IR::Value& value) {
|
2016-07-11 23:43:53 +02:00
|
|
|
Inst(IR::Opcode::WriteMemory8, {vaddr, value});
|
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
void IREmitter::WriteMemory16(const IR::Value& vaddr, const IR::Value& value) {
|
2016-08-01 21:03:13 +02:00
|
|
|
if (current_location.EFlag()) {
|
2016-07-23 00:55:00 +02:00
|
|
|
auto v = ByteReverseHalf(value);
|
|
|
|
Inst(IR::Opcode::WriteMemory16, {vaddr, v});
|
|
|
|
} else {
|
|
|
|
Inst(IR::Opcode::WriteMemory16, {vaddr, value});
|
2016-07-20 16:34:17 +02:00
|
|
|
}
|
2016-07-11 23:43:53 +02:00
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
void IREmitter::WriteMemory32(const IR::Value& vaddr, const IR::Value& value) {
|
2016-08-01 21:03:13 +02:00
|
|
|
if (current_location.EFlag()) {
|
2016-07-23 00:55:00 +02:00
|
|
|
auto v = ByteReverseWord(value);
|
|
|
|
Inst(IR::Opcode::WriteMemory32, {vaddr, v});
|
|
|
|
} else {
|
|
|
|
Inst(IR::Opcode::WriteMemory32, {vaddr, value});
|
2016-07-20 16:34:17 +02:00
|
|
|
}
|
2016-07-11 23:43:53 +02:00
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
void IREmitter::WriteMemory64(const IR::Value& vaddr, const IR::Value& value) {
|
2016-08-01 21:03:13 +02:00
|
|
|
if (current_location.EFlag()) {
|
2016-07-23 00:55:00 +02:00
|
|
|
auto v = ByteReverseDual(value);
|
|
|
|
Inst(IR::Opcode::WriteMemory64, {vaddr, v});
|
|
|
|
} else {
|
|
|
|
Inst(IR::Opcode::WriteMemory64, {vaddr, value});
|
2016-07-20 16:34:17 +02:00
|
|
|
}
|
2016-07-11 23:43:53 +02:00
|
|
|
}
|
|
|
|
|
TranslateArm: Implement CLREX, LDREX, LDREXB, LDREXD, LDREXH, STREX, STREXB, STREXD, STREXH, SWP, SWPB
2016-08-09 23:48:20 +02:00
|
|
|
IR::Value IREmitter::ExclusiveWriteMemory8(const IR::Value& vaddr, const IR::Value& value) {
|
|
|
|
return Inst(IR::Opcode::ExclusiveWriteMemory8, {vaddr, value});
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::ExclusiveWriteMemory16(const IR::Value& vaddr, const IR::Value& value) {
|
|
|
|
if (current_location.EFlag()) {
|
|
|
|
auto v = ByteReverseHalf(value);
|
|
|
|
return Inst(IR::Opcode::ExclusiveWriteMemory16, {vaddr, v});
|
|
|
|
} else {
|
|
|
|
return Inst(IR::Opcode::ExclusiveWriteMemory16, {vaddr, value});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::ExclusiveWriteMemory32(const IR::Value& vaddr, const IR::Value& value) {
|
|
|
|
if (current_location.EFlag()) {
|
|
|
|
auto v = ByteReverseWord(value);
|
|
|
|
return Inst(IR::Opcode::ExclusiveWriteMemory32, {vaddr, v});
|
|
|
|
} else {
|
|
|
|
return Inst(IR::Opcode::ExclusiveWriteMemory32, {vaddr, value});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IR::Value IREmitter::ExclusiveWriteMemory64(const IR::Value& vaddr, const IR::Value& value_lo, const IR::Value& value_hi) {
|
|
|
|
if (current_location.EFlag()) {
|
|
|
|
auto vlo = ByteReverseWord(value_lo);
|
|
|
|
auto vhi = ByteReverseWord(value_hi);
|
|
|
|
return Inst(IR::Opcode::ExclusiveWriteMemory64, {vaddr, vlo, vhi});
|
|
|
|
} else {
|
|
|
|
return Inst(IR::Opcode::ExclusiveWriteMemory64, {vaddr, value_lo, value_hi});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-05 15:07:27 +02:00
|
|
|
void IREmitter::Breakpoint() {
|
|
|
|
Inst(IR::Opcode::Breakpoint, {});
|
|
|
|
}
|
|
|
|
|
2016-07-07 11:53:09 +02:00
|
|
|
void IREmitter::SetTerm(const IR::Terminal& terminal) {
|
2016-08-25 16:35:50 +02:00
|
|
|
block.SetTerminal(terminal);
|
2016-07-07 11:53:09 +02:00
|
|
|
}
|
|
|
|
|
2016-07-23 00:55:00 +02:00
|
|
|
IR::Value IREmitter::Inst(IR::Opcode op, std::initializer_list<IR::Value> args) {
|
2016-08-25 16:35:50 +02:00
|
|
|
block.AppendNewInst(op, args);
|
|
|
|
return IR::Value(&block.back());
|
2016-07-01 15:01:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Arm
|
|
|
|
} // namespace Dynarmic
|
|
|
|
|