From 2ccf148fbaaf9ea15233d7ef09e31ca0fa6ee3be Mon Sep 17 00:00:00 2001 From: Jason W Kim Date: Fri, 3 Dec 2010 19:40:23 +0000 Subject: [PATCH] fix ARM::fixup_arm_branch, cleanup, and share more code between ELF and Darwin git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120832 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/ARM/ARMAsmBackend.cpp | 35 ++++++++++---------------------- 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/lib/Target/ARM/ARMAsmBackend.cpp b/lib/Target/ARM/ARMAsmBackend.cpp index eb03a24b026..8c5cab72750 100644 --- a/lib/Target/ARM/ARMAsmBackend.cpp +++ b/lib/Target/ARM/ARMAsmBackend.cpp @@ -65,9 +65,16 @@ static unsigned adjustFixupValue(unsigned Kind, uint64_t Value) { default: llvm_unreachable("Unknown fixup kind!"); case FK_Data_4: - case ARM::fixup_arm_movt_hi16: - case ARM::fixup_arm_movw_lo16: return Value; + case ARM::fixup_arm_movt_hi16: + case ARM::fixup_arm_movw_lo16: { + unsigned Hi4 = (Value & 0xF000) >> 12; + unsigned Lo12 = Value & 0x0FFF; + // inst{19-16} = Hi4; + // inst{11-0} = Lo12; + Value = (Hi4 << 16) | (Lo12); + return Value; + } case ARM::fixup_arm_ldst_pcrel_12: { bool isAdd = true; // ARM PC-relative values are offset by 8. @@ -96,7 +103,7 @@ static unsigned adjustFixupValue(unsigned Kind, uint64_t Value) { case ARM::fixup_arm_branch: // These values don't encode the low two bits since they're always zero. // Offset by 8 just as above. - return (Value - 8) >> 2; + return 0xFFFFFF & ((Value - 8) >> 2); case ARM::fixup_arm_pcrel_10: { // Offset by 8 just as above. Value = Value - 8; @@ -142,7 +149,7 @@ public: } }; -// Fixme: can we raise this to share code between Darwin and ELF? +// Fixme: Raise this to share code between Darwin and ELF. void ELFARMAsmBackend::ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF, uint64_t Value) const { uint32_t Mask = 0; @@ -150,32 +157,12 @@ void ELFARMAsmBackend::ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF, unsigned NumBytes = 4; Value = adjustFixupValue(Fixup.getKind(), Value); - switch (Fixup.getKind()) { - default: assert(0 && "Unsupported Fixup kind"); break; - case ARM::fixup_arm_branch: { - unsigned Lo24 = Value & 0xFFFFFF; - Mask = ~(0xFFFFFF); - Value = Lo24; - }; break; - case ARM::fixup_arm_movt_hi16: - case ARM::fixup_arm_movw_lo16: { - unsigned Hi4 = (Value & 0xF000) >> 12; - unsigned Lo12 = Value & 0x0FFF; - // inst{19-16} = Hi4; - // inst{11-0} = Lo12; - Value = (Hi4 << 16) | (Lo12); - Mask = ~(0xF0FFF); - }; break; - } - assert((Fixup.getOffset() % NumBytes == 0) && "Offset mod NumBytes is nonzero!"); // For each byte of the fragment that the fixup touches, mask in the // bits from the fixup value. // The Value has been "split up" into the appropriate bitfields above. - // Fixme: how to share code with the .td generated code? for (unsigned i = 0; i != NumBytes; ++i) { - DF.getContents()[Fixup.getOffset() + i] &= uint8_t(Mask >> (i * 8)); DF.getContents()[Fixup.getOffset() + i] |= uint8_t(Value >> (i * 8)); } }