Jason W Kim | b321245 | 2010-09-30 02:17:26 +0000 | [diff] [blame] | 1 | //===-- ARMAsmBackend.cpp - ARM Assembler Backend -------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Jim Grosbach | 45e50d8 | 2011-08-16 17:06:20 +0000 | [diff] [blame] | 10 | #include "MCTargetDesc/ARMMCTargetDesc.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 11 | #include "MCTargetDesc/ARMAddressingModes.h" |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 12 | #include "MCTargetDesc/ARMAsmBackend.h" |
| 13 | #include "MCTargetDesc/ARMAsmBackendDarwin.h" |
| 14 | #include "MCTargetDesc/ARMAsmBackendELF.h" |
| 15 | #include "MCTargetDesc/ARMAsmBackendWinCOFF.h" |
Evan Cheng | ad5f485 | 2011-07-23 00:00:19 +0000 | [diff] [blame] | 16 | #include "MCTargetDesc/ARMBaseInfo.h" |
| 17 | #include "MCTargetDesc/ARMFixupKinds.h" |
Quentin Colombet | 77ca8b8 | 2013-01-14 21:34:09 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/StringSwitch.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCAsmBackend.h" |
Jason W Kim | b321245 | 2010-09-30 02:17:26 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCAssembler.h" |
Jim Grosbach | e78031a | 2012-04-30 22:30:43 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCContext.h" |
Jim Grosbach | 87055ed | 2010-12-08 01:16:55 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCDirectives.h" |
Rafael Espindola | f0e24d4 | 2010-12-17 16:59:53 +0000 | [diff] [blame] | 23 | #include "llvm/MC/MCELFObjectWriter.h" |
Jason W Kim | b321245 | 2010-09-30 02:17:26 +0000 | [diff] [blame] | 24 | #include "llvm/MC/MCExpr.h" |
Craig Topper | 6e80c28 | 2012-03-26 06:58:25 +0000 | [diff] [blame] | 25 | #include "llvm/MC/MCFixupKindInfo.h" |
Daniel Dunbar | 73b8713 | 2010-12-16 16:08:33 +0000 | [diff] [blame] | 26 | #include "llvm/MC/MCMachObjectWriter.h" |
Jason W Kim | b321245 | 2010-09-30 02:17:26 +0000 | [diff] [blame] | 27 | #include "llvm/MC/MCObjectWriter.h" |
Jason W Kim | b321245 | 2010-09-30 02:17:26 +0000 | [diff] [blame] | 28 | #include "llvm/MC/MCSectionELF.h" |
| 29 | #include "llvm/MC/MCSectionMachO.h" |
Jim Grosbach | 45e50d8 | 2011-08-16 17:06:20 +0000 | [diff] [blame] | 30 | #include "llvm/MC/MCSubtargetInfo.h" |
Jim Grosbach | 3b50c9e | 2012-01-18 00:23:57 +0000 | [diff] [blame] | 31 | #include "llvm/MC/MCValue.h" |
Wesley Peck | 1851090 | 2010-10-22 15:52:49 +0000 | [diff] [blame] | 32 | #include "llvm/Support/ELF.h" |
Jason W Kim | b321245 | 2010-09-30 02:17:26 +0000 | [diff] [blame] | 33 | #include "llvm/Support/ErrorHandling.h" |
Charles Davis | 8bdfafd | 2013-09-01 04:28:48 +0000 | [diff] [blame] | 34 | #include "llvm/Support/MachO.h" |
Jason W Kim | b321245 | 2010-09-30 02:17:26 +0000 | [diff] [blame] | 35 | #include "llvm/Support/raw_ostream.h" |
Jason W Kim | b321245 | 2010-09-30 02:17:26 +0000 | [diff] [blame] | 36 | using namespace llvm; |
| 37 | |
| 38 | namespace { |
Rafael Espindola | 6b5e56c | 2010-12-17 17:45:22 +0000 | [diff] [blame] | 39 | class ARMELFObjectWriter : public MCELFObjectTargetWriter { |
| 40 | public: |
Rafael Espindola | 1ad4095 | 2011-12-21 17:00:36 +0000 | [diff] [blame] | 41 | ARMELFObjectWriter(uint8_t OSABI) |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 42 | : MCELFObjectTargetWriter(/*Is64Bit*/ false, OSABI, ELF::EM_ARM, |
| 43 | /*HasRelocationAddend*/ false) {} |
Rafael Espindola | 6b5e56c | 2010-12-17 17:45:22 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 46 | const MCFixupKindInfo &ARMAsmBackend::getFixupKindInfo(MCFixupKind Kind) const { |
| 47 | const static MCFixupKindInfo InfosLE[ARM::NumTargetFixupKinds] = { |
| 48 | // This table *must* be in the order that the fixup_* kinds are defined in |
| 49 | // ARMFixupKinds.h. |
| 50 | // |
| 51 | // Name Offset (bits) Size (bits) Flags |
| 52 | {"fixup_arm_ldst_pcrel_12", 0, 32, MCFixupKindInfo::FKF_IsPCRel}, |
| 53 | {"fixup_t2_ldst_pcrel_12", 0, 32, |
| 54 | MCFixupKindInfo::FKF_IsPCRel | |
| 55 | MCFixupKindInfo::FKF_IsAlignedDownTo32Bits}, |
| 56 | {"fixup_arm_pcrel_10_unscaled", 0, 32, MCFixupKindInfo::FKF_IsPCRel}, |
| 57 | {"fixup_arm_pcrel_10", 0, 32, MCFixupKindInfo::FKF_IsPCRel}, |
| 58 | {"fixup_t2_pcrel_10", 0, 32, |
| 59 | MCFixupKindInfo::FKF_IsPCRel | |
| 60 | MCFixupKindInfo::FKF_IsAlignedDownTo32Bits}, |
| 61 | {"fixup_thumb_adr_pcrel_10", 0, 8, |
| 62 | MCFixupKindInfo::FKF_IsPCRel | |
| 63 | MCFixupKindInfo::FKF_IsAlignedDownTo32Bits}, |
| 64 | {"fixup_arm_adr_pcrel_12", 0, 32, MCFixupKindInfo::FKF_IsPCRel}, |
| 65 | {"fixup_t2_adr_pcrel_12", 0, 32, |
| 66 | MCFixupKindInfo::FKF_IsPCRel | |
| 67 | MCFixupKindInfo::FKF_IsAlignedDownTo32Bits}, |
| 68 | {"fixup_arm_condbranch", 0, 24, MCFixupKindInfo::FKF_IsPCRel}, |
| 69 | {"fixup_arm_uncondbranch", 0, 24, MCFixupKindInfo::FKF_IsPCRel}, |
| 70 | {"fixup_t2_condbranch", 0, 32, MCFixupKindInfo::FKF_IsPCRel}, |
| 71 | {"fixup_t2_uncondbranch", 0, 32, MCFixupKindInfo::FKF_IsPCRel}, |
| 72 | {"fixup_arm_thumb_br", 0, 16, MCFixupKindInfo::FKF_IsPCRel}, |
| 73 | {"fixup_arm_uncondbl", 0, 24, MCFixupKindInfo::FKF_IsPCRel}, |
| 74 | {"fixup_arm_condbl", 0, 24, MCFixupKindInfo::FKF_IsPCRel}, |
| 75 | {"fixup_arm_blx", 0, 24, MCFixupKindInfo::FKF_IsPCRel}, |
| 76 | {"fixup_arm_thumb_bl", 0, 32, MCFixupKindInfo::FKF_IsPCRel}, |
| 77 | {"fixup_arm_thumb_blx", 0, 32, MCFixupKindInfo::FKF_IsPCRel}, |
| 78 | {"fixup_arm_thumb_cb", 0, 16, MCFixupKindInfo::FKF_IsPCRel}, |
| 79 | {"fixup_arm_thumb_cp", 0, 8, |
| 80 | MCFixupKindInfo::FKF_IsPCRel | |
| 81 | MCFixupKindInfo::FKF_IsAlignedDownTo32Bits}, |
| 82 | {"fixup_arm_thumb_bcc", 0, 8, MCFixupKindInfo::FKF_IsPCRel}, |
| 83 | // movw / movt: 16-bits immediate but scattered into two chunks 0 - 12, 16 |
| 84 | // - 19. |
| 85 | {"fixup_arm_movt_hi16", 0, 20, 0}, |
| 86 | {"fixup_arm_movw_lo16", 0, 20, 0}, |
| 87 | {"fixup_t2_movt_hi16", 0, 20, 0}, |
| 88 | {"fixup_t2_movw_lo16", 0, 20, 0}, |
| 89 | }; |
| 90 | const static MCFixupKindInfo InfosBE[ARM::NumTargetFixupKinds] = { |
| 91 | // This table *must* be in the order that the fixup_* kinds are defined in |
| 92 | // ARMFixupKinds.h. |
| 93 | // |
| 94 | // Name Offset (bits) Size (bits) Flags |
| 95 | {"fixup_arm_ldst_pcrel_12", 0, 32, MCFixupKindInfo::FKF_IsPCRel}, |
| 96 | {"fixup_t2_ldst_pcrel_12", 0, 32, |
| 97 | MCFixupKindInfo::FKF_IsPCRel | |
| 98 | MCFixupKindInfo::FKF_IsAlignedDownTo32Bits}, |
| 99 | {"fixup_arm_pcrel_10_unscaled", 0, 32, MCFixupKindInfo::FKF_IsPCRel}, |
| 100 | {"fixup_arm_pcrel_10", 0, 32, MCFixupKindInfo::FKF_IsPCRel}, |
| 101 | {"fixup_t2_pcrel_10", 0, 32, |
| 102 | MCFixupKindInfo::FKF_IsPCRel | |
| 103 | MCFixupKindInfo::FKF_IsAlignedDownTo32Bits}, |
| 104 | {"fixup_thumb_adr_pcrel_10", 8, 8, |
| 105 | MCFixupKindInfo::FKF_IsPCRel | |
| 106 | MCFixupKindInfo::FKF_IsAlignedDownTo32Bits}, |
| 107 | {"fixup_arm_adr_pcrel_12", 0, 32, MCFixupKindInfo::FKF_IsPCRel}, |
| 108 | {"fixup_t2_adr_pcrel_12", 0, 32, |
| 109 | MCFixupKindInfo::FKF_IsPCRel | |
| 110 | MCFixupKindInfo::FKF_IsAlignedDownTo32Bits}, |
| 111 | {"fixup_arm_condbranch", 8, 24, MCFixupKindInfo::FKF_IsPCRel}, |
| 112 | {"fixup_arm_uncondbranch", 8, 24, MCFixupKindInfo::FKF_IsPCRel}, |
| 113 | {"fixup_t2_condbranch", 0, 32, MCFixupKindInfo::FKF_IsPCRel}, |
| 114 | {"fixup_t2_uncondbranch", 0, 32, MCFixupKindInfo::FKF_IsPCRel}, |
| 115 | {"fixup_arm_thumb_br", 0, 16, MCFixupKindInfo::FKF_IsPCRel}, |
| 116 | {"fixup_arm_uncondbl", 8, 24, MCFixupKindInfo::FKF_IsPCRel}, |
| 117 | {"fixup_arm_condbl", 8, 24, MCFixupKindInfo::FKF_IsPCRel}, |
| 118 | {"fixup_arm_blx", 8, 24, MCFixupKindInfo::FKF_IsPCRel}, |
| 119 | {"fixup_arm_thumb_bl", 0, 32, MCFixupKindInfo::FKF_IsPCRel}, |
| 120 | {"fixup_arm_thumb_blx", 0, 32, MCFixupKindInfo::FKF_IsPCRel}, |
| 121 | {"fixup_arm_thumb_cb", 0, 16, MCFixupKindInfo::FKF_IsPCRel}, |
| 122 | {"fixup_arm_thumb_cp", 8, 8, |
| 123 | MCFixupKindInfo::FKF_IsPCRel | |
| 124 | MCFixupKindInfo::FKF_IsAlignedDownTo32Bits}, |
| 125 | {"fixup_arm_thumb_bcc", 8, 8, MCFixupKindInfo::FKF_IsPCRel}, |
| 126 | // movw / movt: 16-bits immediate but scattered into two chunks 0 - 12, 16 |
| 127 | // - 19. |
| 128 | {"fixup_arm_movt_hi16", 12, 20, 0}, |
| 129 | {"fixup_arm_movw_lo16", 12, 20, 0}, |
| 130 | {"fixup_t2_movt_hi16", 12, 20, 0}, |
| 131 | {"fixup_t2_movw_lo16", 12, 20, 0}, |
| 132 | }; |
Jim Grosbach | 45e50d8 | 2011-08-16 17:06:20 +0000 | [diff] [blame] | 133 | |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 134 | if (Kind < FirstTargetFixupKind) |
| 135 | return MCAsmBackend::getFixupKindInfo(Kind); |
| 136 | |
| 137 | assert(unsigned(Kind - FirstTargetFixupKind) < getNumFixupKinds() && |
| 138 | "Invalid kind!"); |
| 139 | return (IsLittleEndian ? InfosLE : InfosBE)[Kind - FirstTargetFixupKind]; |
| 140 | } |
| 141 | |
| 142 | void ARMAsmBackend::handleAssemblerFlag(MCAssemblerFlag Flag) { |
| 143 | switch (Flag) { |
| 144 | default: |
| 145 | break; |
| 146 | case MCAF_Code16: |
| 147 | setIsThumb(true); |
| 148 | break; |
| 149 | case MCAF_Code32: |
| 150 | setIsThumb(false); |
| 151 | break; |
Jim Grosbach | 45e50d8 | 2011-08-16 17:06:20 +0000 | [diff] [blame] | 152 | } |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 153 | } |
Chris Lattner | 9fdd10d | 2010-11-17 05:41:32 +0000 | [diff] [blame] | 154 | } // end anonymous namespace |
Jason W Kim | b321245 | 2010-09-30 02:17:26 +0000 | [diff] [blame] | 155 | |
Jim Grosbach | 34a7c6d | 2011-12-05 23:45:46 +0000 | [diff] [blame] | 156 | static unsigned getRelaxedOpcode(unsigned Op) { |
| 157 | switch (Op) { |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 158 | default: |
| 159 | return Op; |
| 160 | case ARM::tBcc: |
| 161 | return ARM::t2Bcc; |
| 162 | case ARM::tLDRpci: |
| 163 | return ARM::t2LDRpci; |
| 164 | case ARM::tADR: |
| 165 | return ARM::t2ADR; |
| 166 | case ARM::tB: |
| 167 | return ARM::t2B; |
| 168 | case ARM::tCBZ: |
| 169 | return ARM::tHINT; |
| 170 | case ARM::tCBNZ: |
| 171 | return ARM::tHINT; |
Jim Grosbach | 34a7c6d | 2011-12-05 23:45:46 +0000 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | |
Jim Grosbach | aba3de9 | 2012-01-18 18:52:16 +0000 | [diff] [blame] | 175 | bool ARMAsmBackend::mayNeedRelaxation(const MCInst &Inst) const { |
Jim Grosbach | 34a7c6d | 2011-12-05 23:45:46 +0000 | [diff] [blame] | 176 | if (getRelaxedOpcode(Inst.getOpcode()) != Inst.getOpcode()) |
| 177 | return true; |
Jason W Kim | b321245 | 2010-09-30 02:17:26 +0000 | [diff] [blame] | 178 | return false; |
| 179 | } |
| 180 | |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 181 | bool ARMAsmBackend::fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value, |
Eli Bendersky | 4d9ada0 | 2013-01-08 00:22:56 +0000 | [diff] [blame] | 182 | const MCRelaxableFragment *DF, |
Jim Grosbach | 25b63fa | 2011-12-06 00:47:03 +0000 | [diff] [blame] | 183 | const MCAsmLayout &Layout) const { |
Benjamin Kramer | 116e99a | 2012-01-19 21:11:13 +0000 | [diff] [blame] | 184 | switch ((unsigned)Fixup.getKind()) { |
Jim Grosbach | c4aa60f | 2012-03-19 21:32:32 +0000 | [diff] [blame] | 185 | case ARM::fixup_arm_thumb_br: { |
| 186 | // Relaxing tB to t2B. tB has a signed 12-bit displacement with the |
| 187 | // low bit being an implied zero. There's an implied +4 offset for the |
| 188 | // branch, so we adjust the other way here to determine what's |
| 189 | // encodable. |
| 190 | // |
| 191 | // Relax if the value is too big for a (signed) i8. |
| 192 | int64_t Offset = int64_t(Value) - 4; |
| 193 | return Offset > 2046 || Offset < -2048; |
| 194 | } |
Jim Grosbach | cb80eb2 | 2012-01-18 21:54:16 +0000 | [diff] [blame] | 195 | case ARM::fixup_arm_thumb_bcc: { |
| 196 | // Relaxing tBcc to t2Bcc. tBcc has a signed 9-bit displacement with the |
| 197 | // low bit being an implied zero. There's an implied +4 offset for the |
| 198 | // branch, so we adjust the other way here to determine what's |
| 199 | // encodable. |
| 200 | // |
| 201 | // Relax if the value is too big for a (signed) i8. |
| 202 | int64_t Offset = int64_t(Value) - 4; |
| 203 | return Offset > 254 || Offset < -256; |
| 204 | } |
Jim Grosbach | 44e5c39 | 2012-01-19 02:09:38 +0000 | [diff] [blame] | 205 | case ARM::fixup_thumb_adr_pcrel_10: |
Jim Grosbach | cb80eb2 | 2012-01-18 21:54:16 +0000 | [diff] [blame] | 206 | case ARM::fixup_arm_thumb_cp: { |
Jim Grosbach | b008df4 | 2012-01-19 01:50:30 +0000 | [diff] [blame] | 207 | // If the immediate is negative, greater than 1020, or not a multiple |
| 208 | // of four, the wide version of the instruction must be used. |
Jim Grosbach | cb80eb2 | 2012-01-18 21:54:16 +0000 | [diff] [blame] | 209 | int64_t Offset = int64_t(Value) - 4; |
Jim Grosbach | b008df4 | 2012-01-19 01:50:30 +0000 | [diff] [blame] | 210 | return Offset > 1020 || Offset < 0 || Offset & 3; |
Jim Grosbach | cb80eb2 | 2012-01-18 21:54:16 +0000 | [diff] [blame] | 211 | } |
Kevin Enderby | 9bd296a | 2014-01-10 00:43:32 +0000 | [diff] [blame] | 212 | case ARM::fixup_arm_thumb_cb: |
| 213 | // If we have a Thumb CBZ or CBNZ instruction and its target is the next |
| 214 | // instruction it is is actually out of range for the instruction. |
| 215 | // It will be changed to a NOP. |
| 216 | int64_t Offset = (Value & ~1); |
| 217 | return Offset == 2; |
Jim Grosbach | cb80eb2 | 2012-01-18 21:54:16 +0000 | [diff] [blame] | 218 | } |
Benjamin Kramer | 116e99a | 2012-01-19 21:11:13 +0000 | [diff] [blame] | 219 | llvm_unreachable("Unexpected fixup kind in fixupNeedsRelaxation()!"); |
Jim Grosbach | 25b63fa | 2011-12-06 00:47:03 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Jim Grosbach | aba3de9 | 2012-01-18 18:52:16 +0000 | [diff] [blame] | 222 | void ARMAsmBackend::relaxInstruction(const MCInst &Inst, MCInst &Res) const { |
Jim Grosbach | 34a7c6d | 2011-12-05 23:45:46 +0000 | [diff] [blame] | 223 | unsigned RelaxedOp = getRelaxedOpcode(Inst.getOpcode()); |
| 224 | |
| 225 | // Sanity check w/ diagnostic if we get here w/ a bogus instruction. |
| 226 | if (RelaxedOp == Inst.getOpcode()) { |
| 227 | SmallString<256> Tmp; |
| 228 | raw_svector_ostream OS(Tmp); |
| 229 | Inst.dump_pretty(OS); |
| 230 | OS << "\n"; |
| 231 | report_fatal_error("unexpected instruction to relax: " + OS.str()); |
| 232 | } |
| 233 | |
Kevin Enderby | 9bd296a | 2014-01-10 00:43:32 +0000 | [diff] [blame] | 234 | // If we are changing Thumb CBZ or CBNZ instruction to a NOP, aka tHINT, we |
| 235 | // have to change the operands too. |
| 236 | if ((Inst.getOpcode() == ARM::tCBZ || Inst.getOpcode() == ARM::tCBNZ) && |
| 237 | RelaxedOp == ARM::tHINT) { |
| 238 | Res.setOpcode(RelaxedOp); |
| 239 | Res.addOperand(MCOperand::CreateImm(0)); |
| 240 | Res.addOperand(MCOperand::CreateImm(14)); |
| 241 | Res.addOperand(MCOperand::CreateReg(0)); |
| 242 | return; |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 243 | } |
Kevin Enderby | 9bd296a | 2014-01-10 00:43:32 +0000 | [diff] [blame] | 244 | |
| 245 | // The rest of instructions we're relaxing have the same operands. |
Jim Grosbach | 34a7c6d | 2011-12-05 23:45:46 +0000 | [diff] [blame] | 246 | // We just need to update to the proper opcode. |
| 247 | Res = Inst; |
| 248 | Res.setOpcode(RelaxedOp); |
Jason W Kim | b321245 | 2010-09-30 02:17:26 +0000 | [diff] [blame] | 249 | } |
| 250 | |
Jim Grosbach | aba3de9 | 2012-01-18 18:52:16 +0000 | [diff] [blame] | 251 | bool ARMAsmBackend::writeNopData(uint64_t Count, MCObjectWriter *OW) const { |
Jim Grosbach | 45e50d8 | 2011-08-16 17:06:20 +0000 | [diff] [blame] | 252 | const uint16_t Thumb1_16bitNopEncoding = 0x46c0; // using MOV r8,r8 |
| 253 | const uint16_t Thumb2_16bitNopEncoding = 0xbf00; // NOP |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 254 | const uint32_t ARMv4_NopEncoding = 0xe1a00000; // using MOV r0,r0 |
Jim Grosbach | 7ccdb7c | 2011-11-16 22:40:25 +0000 | [diff] [blame] | 255 | const uint32_t ARMv6T2_NopEncoding = 0xe320f000; // NOP |
Jim Grosbach | 87055ed | 2010-12-08 01:16:55 +0000 | [diff] [blame] | 256 | if (isThumb()) { |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 257 | const uint16_t nopEncoding = |
| 258 | hasNOP() ? Thumb2_16bitNopEncoding : Thumb1_16bitNopEncoding; |
Jim Grosbach | 97f1de7 | 2010-12-17 19:03:02 +0000 | [diff] [blame] | 259 | uint64_t NumNops = Count / 2; |
| 260 | for (uint64_t i = 0; i != NumNops; ++i) |
Jim Grosbach | 45e50d8 | 2011-08-16 17:06:20 +0000 | [diff] [blame] | 261 | OW->Write16(nopEncoding); |
Jim Grosbach | 97f1de7 | 2010-12-17 19:03:02 +0000 | [diff] [blame] | 262 | if (Count & 1) |
| 263 | OW->Write8(0); |
Jim Grosbach | 87055ed | 2010-12-08 01:16:55 +0000 | [diff] [blame] | 264 | return true; |
| 265 | } |
| 266 | // ARM mode |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 267 | const uint32_t nopEncoding = |
| 268 | hasNOP() ? ARMv6T2_NopEncoding : ARMv4_NopEncoding; |
Jim Grosbach | 97f1de7 | 2010-12-17 19:03:02 +0000 | [diff] [blame] | 269 | uint64_t NumNops = Count / 4; |
| 270 | for (uint64_t i = 0; i != NumNops; ++i) |
Jim Grosbach | 45e50d8 | 2011-08-16 17:06:20 +0000 | [diff] [blame] | 271 | OW->Write32(nopEncoding); |
| 272 | // FIXME: should this function return false when unable to write exactly |
| 273 | // 'Count' bytes with NOP encodings? |
Jim Grosbach | 97f1de7 | 2010-12-17 19:03:02 +0000 | [diff] [blame] | 274 | switch (Count % 4) { |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 275 | default: |
| 276 | break; // No leftover bytes to write |
| 277 | case 1: |
| 278 | OW->Write8(0); |
| 279 | break; |
| 280 | case 2: |
| 281 | OW->Write16(0); |
| 282 | break; |
| 283 | case 3: |
| 284 | OW->Write16(0); |
| 285 | OW->Write8(0xa0); |
| 286 | break; |
Jim Grosbach | 97f1de7 | 2010-12-17 19:03:02 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Rafael Espindola | 0ed1543 | 2010-10-25 17:50:35 +0000 | [diff] [blame] | 289 | return true; |
Jim Grosbach | 58bce99 | 2010-09-30 03:20:34 +0000 | [diff] [blame] | 290 | } |
Jason W Kim | b321245 | 2010-09-30 02:17:26 +0000 | [diff] [blame] | 291 | |
Christian Pirker | fdce7ce | 2014-05-06 10:05:11 +0000 | [diff] [blame] | 292 | static uint32_t swapHalfWords(uint32_t Value, bool IsLittleEndian) { |
| 293 | if (IsLittleEndian) { |
| 294 | // Note that the halfwords are stored high first and low second in thumb; |
| 295 | // so we need to swap the fixup value here to map properly. |
| 296 | uint32_t Swapped = (Value & 0xFFFF0000) >> 16; |
| 297 | Swapped |= (Value & 0x0000FFFF) << 16; |
| 298 | return Swapped; |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 299 | } else |
Christian Pirker | fdce7ce | 2014-05-06 10:05:11 +0000 | [diff] [blame] | 300 | return Value; |
| 301 | } |
| 302 | |
| 303 | static uint32_t joinHalfWords(uint32_t FirstHalf, uint32_t SecondHalf, |
| 304 | bool IsLittleEndian) { |
| 305 | uint32_t Value; |
| 306 | |
| 307 | if (IsLittleEndian) { |
| 308 | Value = (SecondHalf & 0xFFFF) << 16; |
| 309 | Value |= (FirstHalf & 0xFFFF); |
| 310 | } else { |
| 311 | Value = (SecondHalf & 0xFFFF); |
| 312 | Value |= (FirstHalf & 0xFFFF) << 16; |
| 313 | } |
| 314 | |
| 315 | return Value; |
| 316 | } |
| 317 | |
Jim Grosbach | e78031a | 2012-04-30 22:30:43 +0000 | [diff] [blame] | 318 | static unsigned adjustFixupValue(const MCFixup &Fixup, uint64_t Value, |
Christian Pirker | fdce7ce | 2014-05-06 10:05:11 +0000 | [diff] [blame] | 319 | bool IsPCRel, MCContext *Ctx, |
| 320 | bool IsLittleEndian) { |
Jim Grosbach | e78031a | 2012-04-30 22:30:43 +0000 | [diff] [blame] | 321 | unsigned Kind = Fixup.getKind(); |
Jason W Kim | fc5c522 | 2010-12-01 22:46:50 +0000 | [diff] [blame] | 322 | switch (Kind) { |
| 323 | default: |
| 324 | llvm_unreachable("Unknown fixup kind!"); |
Jim Grosbach | 4416dfa | 2010-12-17 18:39:10 +0000 | [diff] [blame] | 325 | case FK_Data_1: |
| 326 | case FK_Data_2: |
Jason W Kim | fc5c522 | 2010-12-01 22:46:50 +0000 | [diff] [blame] | 327 | case FK_Data_4: |
Jason W Kim | fc5c522 | 2010-12-01 22:46:50 +0000 | [diff] [blame] | 328 | return Value; |
Saleem Abdulrasool | fc6b85b | 2014-05-08 01:35:57 +0000 | [diff] [blame] | 329 | case FK_SecRel_2: |
| 330 | return Value; |
Saleem Abdulrasool | 729c7a0 | 2014-05-04 23:13:15 +0000 | [diff] [blame] | 331 | case FK_SecRel_4: |
| 332 | return Value; |
Jason W Kim | d5e6e54 | 2010-12-03 19:40:23 +0000 | [diff] [blame] | 333 | case ARM::fixup_arm_movt_hi16: |
Rafael Espindola | 5904e12 | 2014-03-29 06:26:49 +0000 | [diff] [blame] | 334 | if (!IsPCRel) |
| 335 | Value >>= 16; |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 336 | // Fallthrough |
Rafael Espindola | 5904e12 | 2014-03-29 06:26:49 +0000 | [diff] [blame] | 337 | case ARM::fixup_arm_movw_lo16: { |
Jason W Kim | d5e6e54 | 2010-12-03 19:40:23 +0000 | [diff] [blame] | 338 | unsigned Hi4 = (Value & 0xF000) >> 12; |
| 339 | unsigned Lo12 = Value & 0x0FFF; |
| 340 | // inst{19-16} = Hi4; |
| 341 | // inst{11-0} = Lo12; |
| 342 | Value = (Hi4 << 16) | (Lo12); |
| 343 | return Value; |
| 344 | } |
Evan Cheng | d4a5c05 | 2011-01-14 02:38:49 +0000 | [diff] [blame] | 345 | case ARM::fixup_t2_movt_hi16: |
Rafael Espindola | 5904e12 | 2014-03-29 06:26:49 +0000 | [diff] [blame] | 346 | if (!IsPCRel) |
| 347 | Value >>= 16; |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 348 | // Fallthrough |
Rafael Espindola | 5904e12 | 2014-03-29 06:26:49 +0000 | [diff] [blame] | 349 | case ARM::fixup_t2_movw_lo16: { |
Evan Cheng | d4a5c05 | 2011-01-14 02:38:49 +0000 | [diff] [blame] | 350 | unsigned Hi4 = (Value & 0xF000) >> 12; |
| 351 | unsigned i = (Value & 0x800) >> 11; |
| 352 | unsigned Mid3 = (Value & 0x700) >> 8; |
| 353 | unsigned Lo8 = Value & 0x0FF; |
| 354 | // inst{19-16} = Hi4; |
| 355 | // inst{26} = i; |
| 356 | // inst{14-12} = Mid3; |
| 357 | // inst{7-0} = Lo8; |
Jim Grosbach | d76f43e | 2011-09-30 22:02:45 +0000 | [diff] [blame] | 358 | Value = (Hi4 << 16) | (i << 26) | (Mid3 << 12) | (Lo8); |
Christian Pirker | fdce7ce | 2014-05-06 10:05:11 +0000 | [diff] [blame] | 359 | return swapHalfWords(Value, IsLittleEndian); |
Evan Cheng | d4a5c05 | 2011-01-14 02:38:49 +0000 | [diff] [blame] | 360 | } |
Owen Anderson | 3e6ee1d | 2010-12-09 01:51:07 +0000 | [diff] [blame] | 361 | case ARM::fixup_arm_ldst_pcrel_12: |
Jason W Kim | fc5c522 | 2010-12-01 22:46:50 +0000 | [diff] [blame] | 362 | // ARM PC-relative values are offset by 8. |
Owen Anderson | 3ef19d9 | 2010-12-09 20:27:52 +0000 | [diff] [blame] | 363 | Value -= 4; |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 364 | // FALLTHROUGH |
Owen Anderson | 3e6ee1d | 2010-12-09 01:51:07 +0000 | [diff] [blame] | 365 | case ARM::fixup_t2_ldst_pcrel_12: { |
| 366 | // Offset by 4, adjusted by two due to the half-word ordering of thumb. |
Owen Anderson | 3ef19d9 | 2010-12-09 20:27:52 +0000 | [diff] [blame] | 367 | Value -= 4; |
Owen Anderson | 3e6ee1d | 2010-12-09 01:51:07 +0000 | [diff] [blame] | 368 | bool isAdd = true; |
Jason W Kim | fc5c522 | 2010-12-01 22:46:50 +0000 | [diff] [blame] | 369 | if ((int64_t)Value < 0) { |
| 370 | Value = -Value; |
| 371 | isAdd = false; |
| 372 | } |
Jim Grosbach | e78031a | 2012-04-30 22:30:43 +0000 | [diff] [blame] | 373 | if (Ctx && Value >= 4096) |
| 374 | Ctx->FatalError(Fixup.getLoc(), "out of range pc-relative fixup value"); |
Jason W Kim | fc5c522 | 2010-12-01 22:46:50 +0000 | [diff] [blame] | 375 | Value |= isAdd << 23; |
Jim Grosbach | 3aeb867 | 2010-12-13 19:18:13 +0000 | [diff] [blame] | 376 | |
Owen Anderson | 3e6ee1d | 2010-12-09 01:51:07 +0000 | [diff] [blame] | 377 | // Same addressing mode as fixup_arm_pcrel_10, |
| 378 | // but with 16-bit halfwords swapped. |
Christian Pirker | fdce7ce | 2014-05-06 10:05:11 +0000 | [diff] [blame] | 379 | if (Kind == ARM::fixup_t2_ldst_pcrel_12) |
| 380 | return swapHalfWords(Value, IsLittleEndian); |
Jim Grosbach | 3aeb867 | 2010-12-13 19:18:13 +0000 | [diff] [blame] | 381 | |
Jason W Kim | fc5c522 | 2010-12-01 22:46:50 +0000 | [diff] [blame] | 382 | return Value; |
| 383 | } |
Jim Grosbach | 509dc2a | 2010-12-14 22:28:03 +0000 | [diff] [blame] | 384 | case ARM::fixup_thumb_adr_pcrel_10: |
| 385 | return ((Value - 4) >> 2) & 0xff; |
Jim Grosbach | ce2bd8d | 2010-12-02 00:28:45 +0000 | [diff] [blame] | 386 | case ARM::fixup_arm_adr_pcrel_12: { |
| 387 | // ARM PC-relative values are offset by 8. |
| 388 | Value -= 8; |
| 389 | unsigned opc = 4; // bits {24-21}. Default to add: 0b0100 |
| 390 | if ((int64_t)Value < 0) { |
| 391 | Value = -Value; |
| 392 | opc = 2; // 0b0010 |
| 393 | } |
Jim Grosbach | e78031a | 2012-04-30 22:30:43 +0000 | [diff] [blame] | 394 | if (Ctx && ARM_AM::getSOImmVal(Value) == -1) |
| 395 | Ctx->FatalError(Fixup.getLoc(), "out of range pc-relative fixup value"); |
Jim Grosbach | ce2bd8d | 2010-12-02 00:28:45 +0000 | [diff] [blame] | 396 | // Encode the immediate and shift the opcode into place. |
| 397 | return ARM_AM::getSOImmVal(Value) | (opc << 21); |
| 398 | } |
Jim Grosbach | e34793e | 2010-12-14 16:25:15 +0000 | [diff] [blame] | 399 | |
Owen Anderson | 6d375e5 | 2010-12-14 00:36:49 +0000 | [diff] [blame] | 400 | case ARM::fixup_t2_adr_pcrel_12: { |
| 401 | Value -= 4; |
| 402 | unsigned opc = 0; |
| 403 | if ((int64_t)Value < 0) { |
| 404 | Value = -Value; |
| 405 | opc = 5; |
| 406 | } |
| 407 | |
| 408 | uint32_t out = (opc << 21); |
Owen Anderson | 8543d4f | 2011-03-23 22:03:44 +0000 | [diff] [blame] | 409 | out |= (Value & 0x800) << 15; |
Owen Anderson | 6d375e5 | 2010-12-14 00:36:49 +0000 | [diff] [blame] | 410 | out |= (Value & 0x700) << 4; |
| 411 | out |= (Value & 0x0FF); |
Jim Grosbach | e34793e | 2010-12-14 16:25:15 +0000 | [diff] [blame] | 412 | |
Christian Pirker | fdce7ce | 2014-05-06 10:05:11 +0000 | [diff] [blame] | 413 | return swapHalfWords(out, IsLittleEndian); |
Owen Anderson | 6d375e5 | 2010-12-14 00:36:49 +0000 | [diff] [blame] | 414 | } |
Jim Grosbach | e34793e | 2010-12-14 16:25:15 +0000 | [diff] [blame] | 415 | |
Jason W Kim | d2e2f56 | 2011-02-04 19:47:15 +0000 | [diff] [blame] | 416 | case ARM::fixup_arm_condbranch: |
| 417 | case ARM::fixup_arm_uncondbranch: |
James Molloy | fb5cd60 | 2012-03-30 09:15:32 +0000 | [diff] [blame] | 418 | case ARM::fixup_arm_uncondbl: |
| 419 | case ARM::fixup_arm_condbl: |
Jim Grosbach | 7b811d3 | 2012-02-27 21:36:23 +0000 | [diff] [blame] | 420 | case ARM::fixup_arm_blx: |
Jason W Kim | fc5c522 | 2010-12-01 22:46:50 +0000 | [diff] [blame] | 421 | // These values don't encode the low two bits since they're always zero. |
| 422 | // Offset by 8 just as above. |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 423 | if (const MCSymbolRefExpr *SRE = |
| 424 | dyn_cast<MCSymbolRefExpr>(Fixup.getValue())) |
Saleem Abdulrasool | 6e00ca8 | 2014-01-30 04:02:31 +0000 | [diff] [blame] | 425 | if (SRE->getKind() == MCSymbolRefExpr::VK_ARM_TLSCALL) |
| 426 | return 0; |
Jim Grosbach | 9e19946 | 2010-12-06 23:57:07 +0000 | [diff] [blame] | 427 | return 0xffffff & ((Value - 8) >> 2); |
Owen Anderson | 578074b | 2010-12-13 19:31:11 +0000 | [diff] [blame] | 428 | case ARM::fixup_t2_uncondbranch: { |
Owen Anderson | 235c276 | 2010-12-10 23:02:28 +0000 | [diff] [blame] | 429 | Value = Value - 4; |
Owen Anderson | 302d5fd | 2010-12-09 00:27:41 +0000 | [diff] [blame] | 430 | Value >>= 1; // Low bit is not encoded. |
Jim Grosbach | 3aeb867 | 2010-12-13 19:18:13 +0000 | [diff] [blame] | 431 | |
Jim Grosbach | f588c51 | 2010-12-13 19:25:46 +0000 | [diff] [blame] | 432 | uint32_t out = 0; |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 433 | bool I = Value & 0x800000; |
Owen Anderson | 578074b | 2010-12-13 19:31:11 +0000 | [diff] [blame] | 434 | bool J1 = Value & 0x400000; |
| 435 | bool J2 = Value & 0x200000; |
| 436 | J1 ^= I; |
| 437 | J2 ^= I; |
Jim Grosbach | e34793e | 2010-12-14 16:25:15 +0000 | [diff] [blame] | 438 | |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 439 | out |= I << 26; // S bit |
| 440 | out |= !J1 << 13; // J1 bit |
| 441 | out |= !J2 << 11; // J2 bit |
| 442 | out |= (Value & 0x1FF800) << 5; // imm6 field |
| 443 | out |= (Value & 0x0007FF); // imm11 field |
Jim Grosbach | e34793e | 2010-12-14 16:25:15 +0000 | [diff] [blame] | 444 | |
Christian Pirker | fdce7ce | 2014-05-06 10:05:11 +0000 | [diff] [blame] | 445 | return swapHalfWords(out, IsLittleEndian); |
Owen Anderson | 578074b | 2010-12-13 19:31:11 +0000 | [diff] [blame] | 446 | } |
| 447 | case ARM::fixup_t2_condbranch: { |
| 448 | Value = Value - 4; |
| 449 | Value >>= 1; // Low bit is not encoded. |
Jim Grosbach | e34793e | 2010-12-14 16:25:15 +0000 | [diff] [blame] | 450 | |
Owen Anderson | 578074b | 2010-12-13 19:31:11 +0000 | [diff] [blame] | 451 | uint64_t out = 0; |
Owen Anderson | 14e4127 | 2010-12-09 01:02:09 +0000 | [diff] [blame] | 452 | out |= (Value & 0x80000) << 7; // S bit |
| 453 | out |= (Value & 0x40000) >> 7; // J2 bit |
| 454 | out |= (Value & 0x20000) >> 4; // J1 bit |
| 455 | out |= (Value & 0x1F800) << 5; // imm6 field |
| 456 | out |= (Value & 0x007FF); // imm11 field |
Jim Grosbach | 3aeb867 | 2010-12-13 19:18:13 +0000 | [diff] [blame] | 457 | |
Christian Pirker | fdce7ce | 2014-05-06 10:05:11 +0000 | [diff] [blame] | 458 | return swapHalfWords(out, IsLittleEndian); |
Owen Anderson | 302d5fd | 2010-12-09 00:27:41 +0000 | [diff] [blame] | 459 | } |
Jim Grosbach | 9e19946 | 2010-12-06 23:57:07 +0000 | [diff] [blame] | 460 | case ARM::fixup_arm_thumb_bl: { |
Saleem Abdulrasool | 077fd25 | 2014-01-26 22:29:36 +0000 | [diff] [blame] | 461 | // The value doesn't encode the low bit (always zero) and is offset by |
| 462 | // four. The 32-bit immediate value is encoded as |
| 463 | // imm32 = SignExtend(S:I1:I2:imm10:imm11:0) |
| 464 | // where I1 = NOT(J1 ^ S) and I2 = NOT(J2 ^ S). |
| 465 | // The value is encoded into disjoint bit positions in the destination |
| 466 | // opcode. x = unchanged, I = immediate value bit, S = sign extension bit, |
| 467 | // J = either J1 or J2 bit |
| 468 | // |
| 469 | // BL: xxxxxSIIIIIIIIII xxJxJIIIIIIIIIII |
| 470 | // |
| 471 | // Note that the halfwords are stored high first, low second; so we need |
| 472 | // to transpose the fixup value here to map properly. |
| 473 | uint32_t offset = (Value - 4) >> 1; |
| 474 | uint32_t signBit = (offset & 0x800000) >> 23; |
| 475 | uint32_t I1Bit = (offset & 0x400000) >> 22; |
| 476 | uint32_t J1Bit = (I1Bit ^ 0x1) ^ signBit; |
| 477 | uint32_t I2Bit = (offset & 0x200000) >> 21; |
| 478 | uint32_t J2Bit = (I2Bit ^ 0x1) ^ signBit; |
| 479 | uint32_t imm10Bits = (offset & 0x1FF800) >> 11; |
| 480 | uint32_t imm11Bits = (offset & 0x000007FF); |
NAKAMURA Takumi | 8018a29 | 2013-06-11 06:52:36 +0000 | [diff] [blame] | 481 | |
Christian Pirker | fdce7ce | 2014-05-06 10:05:11 +0000 | [diff] [blame] | 482 | uint32_t FirstHalf = (((uint16_t)signBit << 10) | (uint16_t)imm10Bits); |
| 483 | uint32_t SecondHalf = (((uint16_t)J1Bit << 13) | ((uint16_t)J2Bit << 11) | |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 484 | (uint16_t)imm11Bits); |
Christian Pirker | fdce7ce | 2014-05-06 10:05:11 +0000 | [diff] [blame] | 485 | return joinHalfWords(FirstHalf, SecondHalf, IsLittleEndian); |
Bill Wendling | 3392bfc | 2010-12-09 00:39:08 +0000 | [diff] [blame] | 486 | } |
| 487 | case ARM::fixup_arm_thumb_blx: { |
Saleem Abdulrasool | 077fd25 | 2014-01-26 22:29:36 +0000 | [diff] [blame] | 488 | // The value doesn't encode the low two bits (always zero) and is offset by |
| 489 | // four (see fixup_arm_thumb_cp). The 32-bit immediate value is encoded as |
| 490 | // imm32 = SignExtend(S:I1:I2:imm10H:imm10L:00) |
| 491 | // where I1 = NOT(J1 ^ S) and I2 = NOT(J2 ^ S). |
| 492 | // The value is encoded into disjoint bit positions in the destination |
| 493 | // opcode. x = unchanged, I = immediate value bit, S = sign extension bit, |
| 494 | // J = either J1 or J2 bit, 0 = zero. |
| 495 | // |
| 496 | // BLX: xxxxxSIIIIIIIIII xxJxJIIIIIIIIII0 |
| 497 | // |
| 498 | // Note that the halfwords are stored high first, low second; so we need |
| 499 | // to transpose the fixup value here to map properly. |
| 500 | uint32_t offset = (Value - 2) >> 2; |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 501 | if (const MCSymbolRefExpr *SRE = |
| 502 | dyn_cast<MCSymbolRefExpr>(Fixup.getValue())) |
Saleem Abdulrasool | 6e00ca8 | 2014-01-30 04:02:31 +0000 | [diff] [blame] | 503 | if (SRE->getKind() == MCSymbolRefExpr::VK_ARM_TLSCALL) |
| 504 | offset = 0; |
Saleem Abdulrasool | 077fd25 | 2014-01-26 22:29:36 +0000 | [diff] [blame] | 505 | uint32_t signBit = (offset & 0x400000) >> 22; |
| 506 | uint32_t I1Bit = (offset & 0x200000) >> 21; |
| 507 | uint32_t J1Bit = (I1Bit ^ 0x1) ^ signBit; |
| 508 | uint32_t I2Bit = (offset & 0x100000) >> 20; |
| 509 | uint32_t J2Bit = (I2Bit ^ 0x1) ^ signBit; |
| 510 | uint32_t imm10HBits = (offset & 0xFFC00) >> 10; |
| 511 | uint32_t imm10LBits = (offset & 0x3FF); |
NAKAMURA Takumi | 8018a29 | 2013-06-11 06:52:36 +0000 | [diff] [blame] | 512 | |
Christian Pirker | fdce7ce | 2014-05-06 10:05:11 +0000 | [diff] [blame] | 513 | uint32_t FirstHalf = (((uint16_t)signBit << 10) | (uint16_t)imm10HBits); |
| 514 | uint32_t SecondHalf = (((uint16_t)J1Bit << 13) | ((uint16_t)J2Bit << 11) | |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 515 | ((uint16_t)imm10LBits) << 1); |
Christian Pirker | fdce7ce | 2014-05-06 10:05:11 +0000 | [diff] [blame] | 516 | return joinHalfWords(FirstHalf, SecondHalf, IsLittleEndian); |
Jim Grosbach | 9e19946 | 2010-12-06 23:57:07 +0000 | [diff] [blame] | 517 | } |
Bill Wendling | 8a6449c | 2010-12-08 01:57:09 +0000 | [diff] [blame] | 518 | case ARM::fixup_arm_thumb_cp: |
Jim Grosbach | 3c68561 | 2010-12-08 20:32:07 +0000 | [diff] [blame] | 519 | // Offset by 4, and don't encode the low two bits. Two bytes of that |
| 520 | // 'off by 4' is implicitly handled by the half-word ordering of the |
| 521 | // Thumb encoding, so we only need to adjust by 2 here. |
| 522 | return ((Value - 2) >> 2) & 0xff; |
Jim Grosbach | 68b27eb | 2010-12-09 19:50:12 +0000 | [diff] [blame] | 523 | case ARM::fixup_arm_thumb_cb: { |
Bill Wendling | a7d6aa9 | 2010-12-08 23:01:43 +0000 | [diff] [blame] | 524 | // Offset by 4 and don't encode the lower bit, which is always 0. |
| 525 | uint32_t Binary = (Value - 4) >> 1; |
Owen Anderson | f636a64 | 2010-12-14 19:42:53 +0000 | [diff] [blame] | 526 | return ((Binary & 0x20) << 4) | ((Binary & 0x1f) << 3); |
Bill Wendling | a7d6aa9 | 2010-12-08 23:01:43 +0000 | [diff] [blame] | 527 | } |
Jim Grosbach | e119da1 | 2010-12-10 18:21:33 +0000 | [diff] [blame] | 528 | case ARM::fixup_arm_thumb_br: |
| 529 | // Offset by 4 and don't encode the lower bit, which is always 0. |
| 530 | return ((Value - 4) >> 1) & 0x7ff; |
Jim Grosbach | 78485ad | 2010-12-10 17:13:40 +0000 | [diff] [blame] | 531 | case ARM::fixup_arm_thumb_bcc: |
| 532 | // Offset by 4 and don't encode the lower bit, which is always 0. |
| 533 | return ((Value - 4) >> 1) & 0xff; |
Jim Grosbach | 8648c10 | 2011-12-19 23:06:24 +0000 | [diff] [blame] | 534 | case ARM::fixup_arm_pcrel_10_unscaled: { |
| 535 | Value = Value - 8; // ARM fixups offset by an additional word and don't |
| 536 | // need to adjust for the half-word ordering. |
| 537 | bool isAdd = true; |
| 538 | if ((int64_t)Value < 0) { |
| 539 | Value = -Value; |
| 540 | isAdd = false; |
| 541 | } |
Jim Grosbach | 913cc30 | 2012-03-30 21:54:22 +0000 | [diff] [blame] | 542 | // The value has the low 4 bits encoded in [3:0] and the high 4 in [11:8]. |
Jim Grosbach | e78031a | 2012-04-30 22:30:43 +0000 | [diff] [blame] | 543 | if (Ctx && Value >= 256) |
| 544 | Ctx->FatalError(Fixup.getLoc(), "out of range pc-relative fixup value"); |
Jim Grosbach | 913cc30 | 2012-03-30 21:54:22 +0000 | [diff] [blame] | 545 | Value = (Value & 0xf) | ((Value & 0xf0) << 4); |
Jim Grosbach | 8648c10 | 2011-12-19 23:06:24 +0000 | [diff] [blame] | 546 | return Value | (isAdd << 23); |
| 547 | } |
Jim Grosbach | 3c68561 | 2010-12-08 20:32:07 +0000 | [diff] [blame] | 548 | case ARM::fixup_arm_pcrel_10: |
Owen Anderson | 4743d75 | 2010-12-10 22:46:47 +0000 | [diff] [blame] | 549 | Value = Value - 4; // ARM fixups offset by an additional word and don't |
Jim Grosbach | 3c68561 | 2010-12-08 20:32:07 +0000 | [diff] [blame] | 550 | // need to adjust for the half-word ordering. |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 551 | // Fall through. |
Jim Grosbach | 3c68561 | 2010-12-08 20:32:07 +0000 | [diff] [blame] | 552 | case ARM::fixup_t2_pcrel_10: { |
| 553 | // Offset by 4, adjusted by two due to the half-word ordering of thumb. |
Owen Anderson | 4743d75 | 2010-12-10 22:46:47 +0000 | [diff] [blame] | 554 | Value = Value - 4; |
Jason W Kim | fc5c522 | 2010-12-01 22:46:50 +0000 | [diff] [blame] | 555 | bool isAdd = true; |
| 556 | if ((int64_t)Value < 0) { |
| 557 | Value = -Value; |
| 558 | isAdd = false; |
| 559 | } |
| 560 | // These values don't encode the low two bits since they're always zero. |
| 561 | Value >>= 2; |
Jim Grosbach | e78031a | 2012-04-30 22:30:43 +0000 | [diff] [blame] | 562 | if (Ctx && Value >= 256) |
| 563 | Ctx->FatalError(Fixup.getLoc(), "out of range pc-relative fixup value"); |
Jason W Kim | fc5c522 | 2010-12-01 22:46:50 +0000 | [diff] [blame] | 564 | Value |= isAdd << 23; |
Jim Grosbach | 3c68561 | 2010-12-08 20:32:07 +0000 | [diff] [blame] | 565 | |
Jim Grosbach | 8648c10 | 2011-12-19 23:06:24 +0000 | [diff] [blame] | 566 | // Same addressing mode as fixup_arm_pcrel_10, but with 16-bit halfwords |
| 567 | // swapped. |
Christian Pirker | fdce7ce | 2014-05-06 10:05:11 +0000 | [diff] [blame] | 568 | if (Kind == ARM::fixup_t2_pcrel_10) |
| 569 | return swapHalfWords(Value, IsLittleEndian); |
Jim Grosbach | 3c68561 | 2010-12-08 20:32:07 +0000 | [diff] [blame] | 570 | |
Jason W Kim | fc5c522 | 2010-12-01 22:46:50 +0000 | [diff] [blame] | 571 | return Value; |
| 572 | } |
| 573 | } |
| 574 | } |
| 575 | |
Jim Grosbach | e78031a | 2012-04-30 22:30:43 +0000 | [diff] [blame] | 576 | void ARMAsmBackend::processFixupValue(const MCAssembler &Asm, |
| 577 | const MCAsmLayout &Layout, |
| 578 | const MCFixup &Fixup, |
| 579 | const MCFragment *DF, |
Rafael Espindola | 3e3de5e | 2014-03-28 16:06:09 +0000 | [diff] [blame] | 580 | const MCValue &Target, uint64_t &Value, |
Jim Grosbach | e78031a | 2012-04-30 22:30:43 +0000 | [diff] [blame] | 581 | bool &IsResolved) { |
| 582 | const MCSymbolRefExpr *A = Target.getSymA(); |
| 583 | // Some fixups to thumb function symbols need the low bit (thumb bit) |
| 584 | // twiddled. |
| 585 | if ((unsigned)Fixup.getKind() != ARM::fixup_arm_ldst_pcrel_12 && |
| 586 | (unsigned)Fixup.getKind() != ARM::fixup_t2_ldst_pcrel_12 && |
| 587 | (unsigned)Fixup.getKind() != ARM::fixup_arm_adr_pcrel_12 && |
| 588 | (unsigned)Fixup.getKind() != ARM::fixup_thumb_adr_pcrel_10 && |
| 589 | (unsigned)Fixup.getKind() != ARM::fixup_t2_adr_pcrel_12 && |
| 590 | (unsigned)Fixup.getKind() != ARM::fixup_arm_thumb_cp) { |
| 591 | if (A) { |
| 592 | const MCSymbol &Sym = A->getSymbol().AliasedSymbol(); |
| 593 | if (Asm.isThumbFunc(&Sym)) |
| 594 | Value |= 1; |
| 595 | } |
| 596 | } |
Logan Chien | d5c48aa | 2014-02-05 14:15:16 +0000 | [diff] [blame] | 597 | // For Thumb1 BL instruction, it is possible to be a long jump between |
| 598 | // the basic blocks of the same function. Thus, we would like to resolve |
| 599 | // the offset when the destination has the same MCFragment. |
| 600 | if (A && (unsigned)Fixup.getKind() == ARM::fixup_arm_thumb_bl) { |
| 601 | const MCSymbol &Sym = A->getSymbol().AliasedSymbol(); |
David Blaikie | 908f4d4 | 2014-04-24 16:59:40 +0000 | [diff] [blame] | 602 | const MCSymbolData &SymData = Asm.getSymbolData(Sym); |
Logan Chien | d5c48aa | 2014-02-05 14:15:16 +0000 | [diff] [blame] | 603 | IsResolved = (SymData.getFragment() == DF); |
| 604 | } |
Jim Grosbach | e78031a | 2012-04-30 22:30:43 +0000 | [diff] [blame] | 605 | // We must always generate a relocation for BL/BLX instructions if we have |
| 606 | // a symbol to reference, as the linker relies on knowing the destination |
| 607 | // symbol's thumb-ness to get interworking right. |
| 608 | if (A && ((unsigned)Fixup.getKind() == ARM::fixup_arm_thumb_blx || |
Jim Grosbach | e78031a | 2012-04-30 22:30:43 +0000 | [diff] [blame] | 609 | (unsigned)Fixup.getKind() == ARM::fixup_arm_blx || |
| 610 | (unsigned)Fixup.getKind() == ARM::fixup_arm_uncondbl || |
| 611 | (unsigned)Fixup.getKind() == ARM::fixup_arm_condbl)) |
| 612 | IsResolved = false; |
| 613 | |
| 614 | // Try to get the encoded value for the fixup as-if we're mapping it into |
| 615 | // the instruction. This allows adjustFixupValue() to issue a diagnostic |
| 616 | // if the value aren't invalid. |
Christian Pirker | fdce7ce | 2014-05-06 10:05:11 +0000 | [diff] [blame] | 617 | (void)adjustFixupValue(Fixup, Value, false, &Asm.getContext(), |
| 618 | IsLittleEndian); |
Jim Grosbach | e78031a | 2012-04-30 22:30:43 +0000 | [diff] [blame] | 619 | } |
| 620 | |
Bill Wendling | f09c44c | 2010-12-07 23:11:00 +0000 | [diff] [blame] | 621 | /// getFixupKindNumBytes - The number of bytes the fixup may change. |
Jim Grosbach | 9d6d77a | 2010-11-11 18:04:49 +0000 | [diff] [blame] | 622 | static unsigned getFixupKindNumBytes(unsigned Kind) { |
Jim Grosbach | 9098714 | 2010-11-09 01:37:15 +0000 | [diff] [blame] | 623 | switch (Kind) { |
Jim Grosbach | 9e19946 | 2010-12-06 23:57:07 +0000 | [diff] [blame] | 624 | default: |
| 625 | llvm_unreachable("Unknown fixup kind!"); |
Bill Wendling | 8a6449c | 2010-12-08 01:57:09 +0000 | [diff] [blame] | 626 | |
Jim Grosbach | 4416dfa | 2010-12-17 18:39:10 +0000 | [diff] [blame] | 627 | case FK_Data_1: |
Jim Grosbach | 78485ad | 2010-12-10 17:13:40 +0000 | [diff] [blame] | 628 | case ARM::fixup_arm_thumb_bcc: |
Bill Wendling | 8a6449c | 2010-12-08 01:57:09 +0000 | [diff] [blame] | 629 | case ARM::fixup_arm_thumb_cp: |
Jim Grosbach | 509dc2a | 2010-12-14 22:28:03 +0000 | [diff] [blame] | 630 | case ARM::fixup_thumb_adr_pcrel_10: |
Bill Wendling | 8a6449c | 2010-12-08 01:57:09 +0000 | [diff] [blame] | 631 | return 1; |
| 632 | |
Jim Grosbach | 4416dfa | 2010-12-17 18:39:10 +0000 | [diff] [blame] | 633 | case FK_Data_2: |
Jim Grosbach | e119da1 | 2010-12-10 18:21:33 +0000 | [diff] [blame] | 634 | case ARM::fixup_arm_thumb_br: |
Jim Grosbach | 68b27eb | 2010-12-09 19:50:12 +0000 | [diff] [blame] | 635 | case ARM::fixup_arm_thumb_cb: |
Bill Wendling | a7d6aa9 | 2010-12-08 23:01:43 +0000 | [diff] [blame] | 636 | return 2; |
| 637 | |
Jim Grosbach | 8648c10 | 2011-12-19 23:06:24 +0000 | [diff] [blame] | 638 | case ARM::fixup_arm_pcrel_10_unscaled: |
Jim Grosbach | 9e19946 | 2010-12-06 23:57:07 +0000 | [diff] [blame] | 639 | case ARM::fixup_arm_ldst_pcrel_12: |
| 640 | case ARM::fixup_arm_pcrel_10: |
| 641 | case ARM::fixup_arm_adr_pcrel_12: |
James Molloy | fb5cd60 | 2012-03-30 09:15:32 +0000 | [diff] [blame] | 642 | case ARM::fixup_arm_uncondbl: |
| 643 | case ARM::fixup_arm_condbl: |
Jim Grosbach | 7b811d3 | 2012-02-27 21:36:23 +0000 | [diff] [blame] | 644 | case ARM::fixup_arm_blx: |
Jason W Kim | d2e2f56 | 2011-02-04 19:47:15 +0000 | [diff] [blame] | 645 | case ARM::fixup_arm_condbranch: |
| 646 | case ARM::fixup_arm_uncondbranch: |
Jim Grosbach | 9e19946 | 2010-12-06 23:57:07 +0000 | [diff] [blame] | 647 | return 3; |
Bill Wendling | 8a6449c | 2010-12-08 01:57:09 +0000 | [diff] [blame] | 648 | |
| 649 | case FK_Data_4: |
Owen Anderson | 3e6ee1d | 2010-12-09 01:51:07 +0000 | [diff] [blame] | 650 | case ARM::fixup_t2_ldst_pcrel_12: |
Owen Anderson | 578074b | 2010-12-13 19:31:11 +0000 | [diff] [blame] | 651 | case ARM::fixup_t2_condbranch: |
| 652 | case ARM::fixup_t2_uncondbranch: |
Owen Anderson | 0f7142d | 2010-12-08 00:18:36 +0000 | [diff] [blame] | 653 | case ARM::fixup_t2_pcrel_10: |
Owen Anderson | 6d375e5 | 2010-12-14 00:36:49 +0000 | [diff] [blame] | 654 | case ARM::fixup_t2_adr_pcrel_12: |
Jim Grosbach | 9e19946 | 2010-12-06 23:57:07 +0000 | [diff] [blame] | 655 | case ARM::fixup_arm_thumb_bl: |
Bill Wendling | 3392bfc | 2010-12-09 00:39:08 +0000 | [diff] [blame] | 656 | case ARM::fixup_arm_thumb_blx: |
Evan Cheng | d4a5c05 | 2011-01-14 02:38:49 +0000 | [diff] [blame] | 657 | case ARM::fixup_arm_movt_hi16: |
| 658 | case ARM::fixup_arm_movw_lo16: |
Evan Cheng | d4a5c05 | 2011-01-14 02:38:49 +0000 | [diff] [blame] | 659 | case ARM::fixup_t2_movt_hi16: |
| 660 | case ARM::fixup_t2_movw_lo16: |
Jim Grosbach | 9e19946 | 2010-12-06 23:57:07 +0000 | [diff] [blame] | 661 | return 4; |
Saleem Abdulrasool | 729c7a0 | 2014-05-04 23:13:15 +0000 | [diff] [blame] | 662 | |
Saleem Abdulrasool | fc6b85b | 2014-05-08 01:35:57 +0000 | [diff] [blame] | 663 | case FK_SecRel_2: |
| 664 | return 2; |
Saleem Abdulrasool | 729c7a0 | 2014-05-04 23:13:15 +0000 | [diff] [blame] | 665 | case FK_SecRel_4: |
| 666 | return 4; |
Jim Grosbach | 9098714 | 2010-11-09 01:37:15 +0000 | [diff] [blame] | 667 | } |
| 668 | } |
| 669 | |
Christian Pirker | 2a11160 | 2014-03-28 14:35:30 +0000 | [diff] [blame] | 670 | /// getFixupKindContainerSizeBytes - The number of bytes of the |
| 671 | /// container involved in big endian. |
| 672 | static unsigned getFixupKindContainerSizeBytes(unsigned Kind) { |
| 673 | switch (Kind) { |
| 674 | default: |
| 675 | llvm_unreachable("Unknown fixup kind!"); |
| 676 | |
| 677 | case FK_Data_1: |
| 678 | return 1; |
| 679 | case FK_Data_2: |
| 680 | return 2; |
| 681 | case FK_Data_4: |
| 682 | return 4; |
| 683 | |
| 684 | case ARM::fixup_arm_thumb_bcc: |
| 685 | case ARM::fixup_arm_thumb_cp: |
| 686 | case ARM::fixup_thumb_adr_pcrel_10: |
| 687 | case ARM::fixup_arm_thumb_br: |
| 688 | case ARM::fixup_arm_thumb_cb: |
| 689 | // Instruction size is 2 bytes. |
| 690 | return 2; |
| 691 | |
| 692 | case ARM::fixup_arm_pcrel_10_unscaled: |
| 693 | case ARM::fixup_arm_ldst_pcrel_12: |
| 694 | case ARM::fixup_arm_pcrel_10: |
| 695 | case ARM::fixup_arm_adr_pcrel_12: |
| 696 | case ARM::fixup_arm_uncondbl: |
| 697 | case ARM::fixup_arm_condbl: |
| 698 | case ARM::fixup_arm_blx: |
| 699 | case ARM::fixup_arm_condbranch: |
| 700 | case ARM::fixup_arm_uncondbranch: |
| 701 | case ARM::fixup_t2_ldst_pcrel_12: |
| 702 | case ARM::fixup_t2_condbranch: |
| 703 | case ARM::fixup_t2_uncondbranch: |
| 704 | case ARM::fixup_t2_pcrel_10: |
| 705 | case ARM::fixup_t2_adr_pcrel_12: |
| 706 | case ARM::fixup_arm_thumb_bl: |
| 707 | case ARM::fixup_arm_thumb_blx: |
| 708 | case ARM::fixup_arm_movt_hi16: |
| 709 | case ARM::fixup_arm_movw_lo16: |
Christian Pirker | 2a11160 | 2014-03-28 14:35:30 +0000 | [diff] [blame] | 710 | case ARM::fixup_t2_movt_hi16: |
| 711 | case ARM::fixup_t2_movw_lo16: |
Christian Pirker | 2a11160 | 2014-03-28 14:35:30 +0000 | [diff] [blame] | 712 | // Instruction size is 4 bytes. |
| 713 | return 4; |
| 714 | } |
| 715 | } |
| 716 | |
Benjamin Kramer | 07ea85a | 2012-11-24 14:36:43 +0000 | [diff] [blame] | 717 | void ARMAsmBackend::applyFixup(const MCFixup &Fixup, char *Data, |
Rafael Espindola | 5904e12 | 2014-03-29 06:26:49 +0000 | [diff] [blame] | 718 | unsigned DataSize, uint64_t Value, |
| 719 | bool IsPCRel) const { |
Jim Grosbach | 9d6d77a | 2010-11-11 18:04:49 +0000 | [diff] [blame] | 720 | unsigned NumBytes = getFixupKindNumBytes(Fixup.getKind()); |
Christian Pirker | fdce7ce | 2014-05-06 10:05:11 +0000 | [diff] [blame] | 721 | Value = adjustFixupValue(Fixup, Value, IsPCRel, nullptr, IsLittleEndian); |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 722 | if (!Value) |
| 723 | return; // Doesn't change encoding. |
Jim Grosbach | 9098714 | 2010-11-09 01:37:15 +0000 | [diff] [blame] | 724 | |
Bill Wendling | f09c44c | 2010-12-07 23:11:00 +0000 | [diff] [blame] | 725 | unsigned Offset = Fixup.getOffset(); |
| 726 | assert(Offset + NumBytes <= DataSize && "Invalid fixup offset!"); |
| 727 | |
Christian Pirker | 2a11160 | 2014-03-28 14:35:30 +0000 | [diff] [blame] | 728 | // Used to point to big endian bytes. |
| 729 | unsigned FullSizeBytes; |
Christian Pirker | 875629f | 2014-05-20 09:24:37 +0000 | [diff] [blame] | 730 | if (!IsLittleEndian) { |
Christian Pirker | 2a11160 | 2014-03-28 14:35:30 +0000 | [diff] [blame] | 731 | FullSizeBytes = getFixupKindContainerSizeBytes(Fixup.getKind()); |
Christian Pirker | 875629f | 2014-05-20 09:24:37 +0000 | [diff] [blame] | 732 | assert((Offset + FullSizeBytes) <= DataSize && "Invalid fixup size!"); |
| 733 | assert(NumBytes <= FullSizeBytes && "Invalid fixup size!"); |
| 734 | } |
Christian Pirker | 2a11160 | 2014-03-28 14:35:30 +0000 | [diff] [blame] | 735 | |
Benjamin Kramer | 07ea85a | 2012-11-24 14:36:43 +0000 | [diff] [blame] | 736 | // For each byte of the fragment that the fixup touches, mask in the bits from |
| 737 | // the fixup value. The Value has been "split up" into the appropriate |
| 738 | // bitfields above. |
Christian Pirker | 2a11160 | 2014-03-28 14:35:30 +0000 | [diff] [blame] | 739 | for (unsigned i = 0; i != NumBytes; ++i) { |
| 740 | unsigned Idx = IsLittleEndian ? i : (FullSizeBytes - 1 - i); |
| 741 | Data[Offset + Idx] |= uint8_t((Value >> (i * 8)) & 0xff); |
| 742 | } |
Jason W Kim | b321245 | 2010-09-30 02:17:26 +0000 | [diff] [blame] | 743 | } |
Bill Wendling | 721724e | 2010-12-07 23:05:20 +0000 | [diff] [blame] | 744 | |
Bill Wendling | 58e2d3d | 2013-09-09 02:37:14 +0000 | [diff] [blame] | 745 | MCAsmBackend *llvm::createARMAsmBackend(const Target &T, |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 746 | const MCRegisterInfo &MRI, StringRef TT, |
| 747 | StringRef CPU, bool isLittle) { |
Owen Anderson | 975ddf8 | 2011-04-01 21:07:39 +0000 | [diff] [blame] | 748 | Triple TheTriple(TT); |
Daniel Dunbar | 2b9b0e3 | 2011-04-19 21:14:45 +0000 | [diff] [blame] | 749 | |
Saleem Abdulrasool | 84b952b | 2014-04-27 03:48:22 +0000 | [diff] [blame] | 750 | switch (TheTriple.getObjectFormat()) { |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 751 | default: |
| 752 | llvm_unreachable("unsupported object format"); |
Saleem Abdulrasool | 84b952b | 2014-04-27 03:48:22 +0000 | [diff] [blame] | 753 | case Triple::MachO: { |
Charles Davis | 8bdfafd | 2013-09-01 04:28:48 +0000 | [diff] [blame] | 754 | MachO::CPUSubTypeARM CS = |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 755 | StringSwitch<MachO::CPUSubTypeARM>(TheTriple.getArchName()) |
| 756 | .Cases("armv4t", "thumbv4t", MachO::CPU_SUBTYPE_ARM_V4T) |
| 757 | .Cases("armv5e", "thumbv5e", MachO::CPU_SUBTYPE_ARM_V5TEJ) |
| 758 | .Cases("armv6", "thumbv6", MachO::CPU_SUBTYPE_ARM_V6) |
| 759 | .Cases("armv6m", "thumbv6m", MachO::CPU_SUBTYPE_ARM_V6M) |
| 760 | .Cases("armv7em", "thumbv7em", MachO::CPU_SUBTYPE_ARM_V7EM) |
| 761 | .Cases("armv7k", "thumbv7k", MachO::CPU_SUBTYPE_ARM_V7K) |
| 762 | .Cases("armv7m", "thumbv7m", MachO::CPU_SUBTYPE_ARM_V7M) |
| 763 | .Cases("armv7s", "thumbv7s", MachO::CPU_SUBTYPE_ARM_V7S) |
| 764 | .Default(MachO::CPU_SUBTYPE_ARM_V7); |
Quentin Colombet | 77ca8b8 | 2013-01-14 21:34:09 +0000 | [diff] [blame] | 765 | |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 766 | return new ARMAsmBackendDarwin(T, TT, CS); |
Owen Anderson | 975ddf8 | 2011-04-01 21:07:39 +0000 | [diff] [blame] | 767 | } |
Saleem Abdulrasool | 84b952b | 2014-04-27 03:48:22 +0000 | [diff] [blame] | 768 | case Triple::COFF: |
| 769 | assert(TheTriple.isOSWindows() && "non-Windows ARM COFF is not supported"); |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 770 | return new ARMAsmBackendWinCOFF(T, TT); |
Saleem Abdulrasool | 84b952b | 2014-04-27 03:48:22 +0000 | [diff] [blame] | 771 | case Triple::ELF: |
| 772 | assert(TheTriple.isOSBinFormatELF() && "using ELF for non-ELF target"); |
| 773 | uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(Triple(TT).getOS()); |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 774 | return new ARMAsmBackendELF(T, TT, OSABI, isLittle); |
Saleem Abdulrasool | 84b952b | 2014-04-27 03:48:22 +0000 | [diff] [blame] | 775 | } |
Jason W Kim | b321245 | 2010-09-30 02:17:26 +0000 | [diff] [blame] | 776 | } |
Christian Pirker | 2a11160 | 2014-03-28 14:35:30 +0000 | [diff] [blame] | 777 | |
Christian Pirker | dc9ff75 | 2014-04-01 15:19:30 +0000 | [diff] [blame] | 778 | MCAsmBackend *llvm::createARMLEAsmBackend(const Target &T, |
Christian Pirker | 2a11160 | 2014-03-28 14:35:30 +0000 | [diff] [blame] | 779 | const MCRegisterInfo &MRI, |
| 780 | StringRef TT, StringRef CPU) { |
| 781 | return createARMAsmBackend(T, MRI, TT, CPU, true); |
| 782 | } |
| 783 | |
Christian Pirker | dc9ff75 | 2014-04-01 15:19:30 +0000 | [diff] [blame] | 784 | MCAsmBackend *llvm::createARMBEAsmBackend(const Target &T, |
Christian Pirker | 2a11160 | 2014-03-28 14:35:30 +0000 | [diff] [blame] | 785 | const MCRegisterInfo &MRI, |
| 786 | StringRef TT, StringRef CPU) { |
| 787 | return createARMAsmBackend(T, MRI, TT, CPU, false); |
| 788 | } |
| 789 | |
Christian Pirker | dc9ff75 | 2014-04-01 15:19:30 +0000 | [diff] [blame] | 790 | MCAsmBackend *llvm::createThumbLEAsmBackend(const Target &T, |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 791 | const MCRegisterInfo &MRI, |
| 792 | StringRef TT, StringRef CPU) { |
Christian Pirker | 2a11160 | 2014-03-28 14:35:30 +0000 | [diff] [blame] | 793 | return createARMAsmBackend(T, MRI, TT, CPU, true); |
| 794 | } |
| 795 | |
Christian Pirker | dc9ff75 | 2014-04-01 15:19:30 +0000 | [diff] [blame] | 796 | MCAsmBackend *llvm::createThumbBEAsmBackend(const Target &T, |
Joe Abbey | 8e72eb7 | 2014-09-16 09:18:23 +0000 | [diff] [blame] | 797 | const MCRegisterInfo &MRI, |
| 798 | StringRef TT, StringRef CPU) { |
Christian Pirker | 2a11160 | 2014-03-28 14:35:30 +0000 | [diff] [blame] | 799 | return createARMAsmBackend(T, MRI, TT, CPU, false); |
| 800 | } |