mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-02 07:11:49 +00:00
Implement the major chunk of PR7195: support for 'callw'
in the integrated assembler. Still some discussion to be done. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@107825 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
cc69e13a36
commit
9fc05227a2
@ -23,13 +23,13 @@
|
||||
#include "llvm/Target/TargetAsmBackend.h"
|
||||
using namespace llvm;
|
||||
|
||||
namespace {
|
||||
|
||||
static unsigned getFixupKindLog2Size(unsigned Kind) {
|
||||
switch (Kind) {
|
||||
default: assert(0 && "invalid fixup kind!");
|
||||
case X86::reloc_pcrel_1byte:
|
||||
case FK_Data_1: return 0;
|
||||
case X86::reloc_pcrel_2byte:
|
||||
case FK_Data_2: return 1;
|
||||
case X86::reloc_pcrel_4byte:
|
||||
case X86::reloc_riprel_4byte:
|
||||
@ -39,6 +39,7 @@ static unsigned getFixupKindLog2Size(unsigned Kind) {
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
class X86AsmBackend : public TargetAsmBackend {
|
||||
public:
|
||||
X86AsmBackend(const Target &T)
|
||||
@ -60,6 +61,7 @@ public:
|
||||
|
||||
bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const;
|
||||
};
|
||||
} // end anonymous namespace
|
||||
|
||||
static unsigned getRelaxedOpcode(unsigned Op) {
|
||||
switch (Op) {
|
||||
@ -180,6 +182,7 @@ bool X86AsmBackend::WriteNopData(uint64_t Count, MCObjectWriter *OW) const {
|
||||
|
||||
/* *** */
|
||||
|
||||
namespace {
|
||||
class ELFX86AsmBackend : public X86AsmBackend {
|
||||
public:
|
||||
ELFX86AsmBackend(const Target &T)
|
||||
@ -281,7 +284,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
} // end anonymous namespace
|
||||
|
||||
TargetAsmBackend *llvm::createX86_32AsmBackend(const Target &T,
|
||||
const std::string &TT) {
|
||||
|
@ -17,6 +17,7 @@ namespace X86 {
|
||||
enum Fixups {
|
||||
reloc_pcrel_4byte = FirstTargetFixupKind, // 32-bit pcrel, e.g. a branch.
|
||||
reloc_pcrel_1byte, // 8-bit pcrel, e.g. branch_1
|
||||
reloc_pcrel_2byte, // 16-bit pcrel, e.g. callw
|
||||
reloc_riprel_4byte, // 32-bit rip-relative
|
||||
reloc_riprel_4byte_movq_load // 32-bit rip-relative in movq
|
||||
};
|
||||
|
@ -50,9 +50,10 @@ def NoImm : ImmType<0>;
|
||||
def Imm8 : ImmType<1>;
|
||||
def Imm8PCRel : ImmType<2>;
|
||||
def Imm16 : ImmType<3>;
|
||||
def Imm32 : ImmType<4>;
|
||||
def Imm32PCRel : ImmType<5>;
|
||||
def Imm64 : ImmType<6>;
|
||||
def Imm16PCRel : ImmType<4>;
|
||||
def Imm32 : ImmType<5>;
|
||||
def Imm32PCRel : ImmType<6>;
|
||||
def Imm64 : ImmType<7>;
|
||||
|
||||
// FPFormat - This specifies what form this FP instruction has. This is used by
|
||||
// the Floating-Point stackifier pass.
|
||||
@ -187,6 +188,13 @@ class Ii32<bits<8> o, Format f, dag outs, dag ins, string asm,
|
||||
let CodeSize = 3;
|
||||
}
|
||||
|
||||
class Ii16PCRel<bits<8> o, Format f, dag outs, dag ins, string asm,
|
||||
list<dag> pattern>
|
||||
: X86Inst<o, f, Imm16PCRel, outs, ins, asm> {
|
||||
let Pattern = pattern;
|
||||
let CodeSize = 3;
|
||||
}
|
||||
|
||||
class Ii32PCRel<bits<8> o, Format f, dag outs, dag ins, string asm,
|
||||
list<dag> pattern>
|
||||
: X86Inst<o, f, Imm32PCRel, outs, ins, asm> {
|
||||
|
@ -360,9 +360,10 @@ namespace X86II {
|
||||
Imm8 = 1 << ImmShift,
|
||||
Imm8PCRel = 2 << ImmShift,
|
||||
Imm16 = 3 << ImmShift,
|
||||
Imm32 = 4 << ImmShift,
|
||||
Imm32PCRel = 5 << ImmShift,
|
||||
Imm64 = 6 << ImmShift,
|
||||
Imm16PCRel = 4 << ImmShift,
|
||||
Imm32 = 5 << ImmShift,
|
||||
Imm32PCRel = 6 << ImmShift,
|
||||
Imm64 = 7 << ImmShift,
|
||||
|
||||
//===------------------------------------------------------------------===//
|
||||
// FP Instruction Classification... Zero is non-fp instruction.
|
||||
@ -460,7 +461,8 @@ namespace X86II {
|
||||
default: assert(0 && "Unknown immediate size");
|
||||
case X86II::Imm8:
|
||||
case X86II::Imm8PCRel: return 1;
|
||||
case X86II::Imm16: return 2;
|
||||
case X86II::Imm16:
|
||||
case X86II::Imm16PCRel: return 2;
|
||||
case X86II::Imm32:
|
||||
case X86II::Imm32PCRel: return 4;
|
||||
case X86II::Imm64: return 8;
|
||||
@ -473,6 +475,7 @@ namespace X86II {
|
||||
switch (TSFlags & X86II::ImmMask) {
|
||||
default: assert(0 && "Unknown immediate size");
|
||||
case X86II::Imm8PCRel:
|
||||
case X86II::Imm16PCRel:
|
||||
case X86II::Imm32PCRel:
|
||||
return true;
|
||||
case X86II::Imm8:
|
||||
|
@ -259,6 +259,7 @@ def lea32mem : Operand<i32> {
|
||||
let ParserMatchClass = X86AbsMemAsmOperand,
|
||||
PrintMethod = "print_pcrel_imm" in {
|
||||
def i32imm_pcrel : Operand<i32>;
|
||||
def i16imm_pcrel : Operand<i16>;
|
||||
|
||||
def offset8 : Operand<i64>;
|
||||
def offset16 : Operand<i64>;
|
||||
@ -709,6 +710,12 @@ let isCall = 1 in
|
||||
"lcall{w}\t{*}$dst", []>, OpSize;
|
||||
def FARCALL32m : I<0xFF, MRM3m, (outs), (ins opaque48mem:$dst),
|
||||
"lcall{l}\t{*}$dst", []>;
|
||||
|
||||
// callw for 16 bit code for the assembler.
|
||||
let isAsmParserOnly = 1 in
|
||||
def CALLpcrel16 : Ii16PCRel<0xE8, RawFrm,
|
||||
(outs), (ins i16imm_pcrel:$dst, variable_ops),
|
||||
"callw\t$dst", []>, OpSize;
|
||||
}
|
||||
|
||||
// Constructing a stack frame.
|
||||
|
@ -38,13 +38,14 @@ public:
|
||||
~X86MCCodeEmitter() {}
|
||||
|
||||
unsigned getNumFixupKinds() const {
|
||||
return 4;
|
||||
return 5;
|
||||
}
|
||||
|
||||
const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const {
|
||||
const static MCFixupKindInfo Infos[] = {
|
||||
{ "reloc_pcrel_4byte", 0, 4 * 8, MCFixupKindInfo::FKF_IsPCRel },
|
||||
{ "reloc_pcrel_1byte", 0, 1 * 8, MCFixupKindInfo::FKF_IsPCRel },
|
||||
{ "reloc_pcrel_2byte", 0, 2 * 8, MCFixupKindInfo::FKF_IsPCRel },
|
||||
{ "reloc_riprel_4byte", 0, 4 * 8, MCFixupKindInfo::FKF_IsPCRel },
|
||||
{ "reloc_riprel_4byte_movq_load", 0, 4 * 8, MCFixupKindInfo::FKF_IsPCRel }
|
||||
};
|
||||
@ -170,8 +171,8 @@ static MCFixupKind getImmFixupKind(uint64_t TSFlags) {
|
||||
switch (Size) {
|
||||
default: assert(0 && "Unknown immediate size");
|
||||
case 1: return isPCRel ? MCFixupKind(X86::reloc_pcrel_1byte) : FK_Data_1;
|
||||
case 2: return isPCRel ? MCFixupKind(X86::reloc_pcrel_2byte) : FK_Data_2;
|
||||
case 4: return isPCRel ? MCFixupKind(X86::reloc_pcrel_4byte) : FK_Data_4;
|
||||
case 2: assert(!isPCRel); return FK_Data_2;
|
||||
case 8: assert(!isPCRel); return FK_Data_8;
|
||||
}
|
||||
}
|
||||
@ -199,6 +200,8 @@ EmitImmediate(const MCOperand &DispOp, unsigned Size, MCFixupKind FixupKind,
|
||||
FixupKind == MCFixupKind(X86::reloc_riprel_4byte) ||
|
||||
FixupKind == MCFixupKind(X86::reloc_riprel_4byte_movq_load))
|
||||
ImmOffset -= 4;
|
||||
if (FixupKind == MCFixupKind(X86::reloc_pcrel_2byte))
|
||||
ImmOffset -= 4;// FIXME: This should be 2, but 'as' produces an offset of 4.
|
||||
if (FixupKind == MCFixupKind(X86::reloc_pcrel_1byte))
|
||||
ImmOffset -= 1;
|
||||
|
||||
|
@ -1,5 +1,10 @@
|
||||
// RUN: llvm-mc -triple x86_64-unknown-unknown --show-encoding %s | FileCheck %s
|
||||
|
||||
// PR7195
|
||||
// CHECK: callw 42
|
||||
// CHECK: encoding: [0x66,0xe8,A,A]
|
||||
callw 42
|
||||
|
||||
// CHECK: crc32b %bl, %eax
|
||||
// CHECK: encoding: [0xf2,0x0f,0x38,0xf0,0xc3]
|
||||
crc32b %bl, %eax
|
||||
|
@ -347,6 +347,7 @@ static int X86TypeFromOpName(LiteralConstantEmitter *type,
|
||||
LEA("lea64mem");
|
||||
|
||||
// all I
|
||||
PCR("i16imm_pcrel");
|
||||
PCR("i32imm_pcrel");
|
||||
PCR("i64i32imm_pcrel");
|
||||
PCR("brtarget8");
|
||||
|
@ -836,6 +836,7 @@ OperandType RecognizableInstr::typeFromString(const std::string &s,
|
||||
TYPE("RST", TYPE_ST)
|
||||
TYPE("i128mem", TYPE_M128)
|
||||
TYPE("i64i32imm_pcrel", TYPE_REL64)
|
||||
TYPE("i16imm_pcrel", TYPE_REL16)
|
||||
TYPE("i32imm_pcrel", TYPE_REL32)
|
||||
TYPE("SSECC", TYPE_IMM3)
|
||||
TYPE("brtarget", TYPE_RELv)
|
||||
@ -955,6 +956,7 @@ OperandEncoding RecognizableInstr::relocationEncodingFromString
|
||||
ENCODING("i64i8imm", ENCODING_IB)
|
||||
ENCODING("i8imm", ENCODING_IB)
|
||||
ENCODING("i64i32imm_pcrel", ENCODING_ID)
|
||||
ENCODING("i16imm_pcrel", ENCODING_IW)
|
||||
ENCODING("i32imm_pcrel", ENCODING_ID)
|
||||
ENCODING("brtarget", ENCODING_Iv)
|
||||
ENCODING("brtarget8", ENCODING_IB)
|
||||
|
Loading…
Reference in New Issue
Block a user