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
This commit is contained in:
Jason W Kim 2010-12-03 19:40:23 +00:00
parent 0b951ceb02
commit 2ccf148fba

View File

@ -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));
}
}