2007-07-06 05:15:40 +08:00
|
|
|
//===-- ARMJITInfo.cpp - Implement the JIT interfaces for the ARM target --===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-07-06 05:15:40 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the JIT interfaces for the ARM target.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "jit"
|
|
|
|
#include "ARMJITInfo.h"
|
2008-11-12 09:02:24 +08:00
|
|
|
#include "ARMInstrInfo.h"
|
2008-11-04 08:50:32 +08:00
|
|
|
#include "ARMConstantPoolValue.h"
|
2007-07-06 05:15:40 +08:00
|
|
|
#include "ARMRelocations.h"
|
|
|
|
#include "ARMSubtarget.h"
|
2008-04-17 04:46:05 +08:00
|
|
|
#include "llvm/Function.h"
|
2009-05-31 04:51:52 +08:00
|
|
|
#include "llvm/CodeGen/JITCodeEmitter.h"
|
2008-11-11 07:14:47 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-09 02:01:40 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-07-25 08:23:56 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2010-11-30 02:47:54 +08:00
|
|
|
#include "llvm/Support/Memory.h"
|
2007-07-06 05:15:40 +08:00
|
|
|
#include <cstdlib>
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
void ARMJITInfo::replaceMachineCodeForFunction(void *Old, void *New) {
|
2010-04-08 06:58:41 +08:00
|
|
|
report_fatal_error("ARMJITInfo::replaceMachineCodeForFunction");
|
2007-07-06 05:15:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// JITCompilerFunction - This contains the address of the JIT function used to
|
|
|
|
/// compile a function lazily.
|
|
|
|
static TargetJITInfo::JITCompilerFn JITCompilerFunction;
|
|
|
|
|
2008-09-02 15:49:03 +08:00
|
|
|
// Get the ASMPREFIX for the current host. This is often '_'.
|
|
|
|
#ifndef __USER_LABEL_PREFIX__
|
|
|
|
#define __USER_LABEL_PREFIX__
|
|
|
|
#endif
|
|
|
|
#define GETASMPREFIX2(X) #X
|
|
|
|
#define GETASMPREFIX(X) GETASMPREFIX2(X)
|
|
|
|
#define ASMPREFIX GETASMPREFIX(__USER_LABEL_PREFIX__)
|
|
|
|
|
2007-07-06 05:15:40 +08:00
|
|
|
// CompilationCallback stub - We can't use a C function with inline assembly in
|
2011-02-02 06:30:51 +08:00
|
|
|
// it, because the prolog/epilog inserted by GCC won't work for us. (We need
|
2008-10-21 05:39:23 +08:00
|
|
|
// to preserve more context and manipulate the stack directly). Instead,
|
2009-08-11 23:33:49 +08:00
|
|
|
// write our own wrapper, which does things our way, so we have complete
|
2008-10-21 05:39:23 +08:00
|
|
|
// control over register saving and restoring.
|
2007-07-06 05:15:40 +08:00
|
|
|
extern "C" {
|
|
|
|
#if defined(__arm__)
|
2009-08-13 06:10:57 +08:00
|
|
|
void ARMCompilationCallback();
|
2007-07-06 05:15:40 +08:00
|
|
|
asm(
|
|
|
|
".text\n"
|
|
|
|
".align 2\n"
|
2008-09-02 15:49:03 +08:00
|
|
|
".globl " ASMPREFIX "ARMCompilationCallback\n"
|
|
|
|
ASMPREFIX "ARMCompilationCallback:\n"
|
2008-10-21 05:39:23 +08:00
|
|
|
// Save caller saved registers since they may contain stuff
|
|
|
|
// for the real target function right now. We have to act as if this
|
|
|
|
// whole compilation callback doesn't exist as far as the caller is
|
|
|
|
// concerned, so we can't just preserve the callee saved regs.
|
2008-10-22 00:54:12 +08:00
|
|
|
"stmdb sp!, {r0, r1, r2, r3, lr}\n"
|
2010-03-02 21:42:03 +08:00
|
|
|
#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
|
2008-11-14 07:28:54 +08:00
|
|
|
"fstmfdd sp!, {d0, d1, d2, d3, d4, d5, d6, d7}\n"
|
|
|
|
#endif
|
2008-10-21 05:39:23 +08:00
|
|
|
// The LR contains the address of the stub function on entry.
|
|
|
|
// pass it as the argument to the C part of the callback
|
|
|
|
"mov r0, lr\n"
|
|
|
|
"sub sp, sp, #4\n"
|
|
|
|
// Call the C portion of the callback
|
|
|
|
"bl " ASMPREFIX "ARMCompilationCallbackC\n"
|
|
|
|
"add sp, sp, #4\n"
|
|
|
|
// Restoring the LR to the return address of the function that invoked
|
|
|
|
// the stub and de-allocating the stack space for it requires us to
|
|
|
|
// swap the two saved LR values on the stack, as they're backwards
|
|
|
|
// for what we need since the pop instruction has a pre-determined
|
|
|
|
// order for the registers.
|
|
|
|
// +--------+
|
|
|
|
// 0 | LR | Original return address
|
2009-08-11 23:33:49 +08:00
|
|
|
// +--------+
|
2008-10-21 05:39:23 +08:00
|
|
|
// 1 | LR | Stub address (start of stub)
|
|
|
|
// 2-5 | R3..R0 | Saved registers (we need to preserve all regs)
|
2008-11-14 07:28:54 +08:00
|
|
|
// 6-20 | D0..D7 | Saved VFP registers
|
2009-08-11 23:33:49 +08:00
|
|
|
// +--------+
|
2008-10-21 05:39:23 +08:00
|
|
|
//
|
2010-03-02 21:42:03 +08:00
|
|
|
#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
|
2008-11-14 07:28:54 +08:00
|
|
|
// Restore VFP caller-saved registers.
|
|
|
|
"fldmfdd sp!, {d0, d1, d2, d3, d4, d5, d6, d7}\n"
|
|
|
|
#endif
|
|
|
|
//
|
2008-10-21 05:39:23 +08:00
|
|
|
// We need to exchange the values in slots 0 and 1 so we can
|
|
|
|
// return to the address in slot 1 with the address in slot 0
|
|
|
|
// restored to the LR.
|
|
|
|
"ldr r0, [sp,#20]\n"
|
|
|
|
"ldr r1, [sp,#16]\n"
|
|
|
|
"str r1, [sp,#20]\n"
|
|
|
|
"str r0, [sp,#16]\n"
|
|
|
|
// Return to the (newly modified) stub to invoke the real function.
|
|
|
|
// The above twiddling of the saved return addresses allows us to
|
2011-02-03 01:29:40 +08:00
|
|
|
// deallocate everything, including the LR the stub saved, with two
|
|
|
|
// updating load instructions.
|
2011-02-02 06:30:51 +08:00
|
|
|
"ldmia sp!, {r0, r1, r2, r3, lr}\n"
|
|
|
|
"ldr pc, [sp], #4\n"
|
2008-09-02 15:49:03 +08:00
|
|
|
);
|
|
|
|
#else // Not an ARM host
|
2007-07-06 05:15:40 +08:00
|
|
|
void ARMCompilationCallback() {
|
2009-07-15 00:55:14 +08:00
|
|
|
llvm_unreachable("Cannot call ARMCompilationCallback() on a non-ARM arch!");
|
2007-07-06 05:15:40 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-08-11 23:33:49 +08:00
|
|
|
/// ARMCompilationCallbackC - This is the target-specific function invoked
|
|
|
|
/// by the function stub when we did not know the real target of a call.
|
|
|
|
/// This function must locate the start of the stub or call site and pass
|
2008-10-21 05:39:23 +08:00
|
|
|
/// it into the JIT compiler function.
|
|
|
|
extern "C" void ARMCompilationCallbackC(intptr_t StubAddr) {
|
|
|
|
// Get the address of the compiled code for this function.
|
|
|
|
intptr_t NewVal = (intptr_t)JITCompilerFunction((void*)StubAddr);
|
2007-07-06 05:15:40 +08:00
|
|
|
|
|
|
|
// Rewrite the call target... so that we don't end up here every time we
|
2008-10-21 05:39:23 +08:00
|
|
|
// execute the call. We're replacing the first two instructions of the
|
|
|
|
// stub with:
|
|
|
|
// ldr pc, [pc,#-4]
|
|
|
|
// <addr>
|
2008-11-08 16:16:49 +08:00
|
|
|
if (!sys::Memory::setRangeWritable((void*)StubAddr, 8)) {
|
2009-07-15 00:55:14 +08:00
|
|
|
llvm_unreachable("ERROR: Unable to mark stub writable");
|
2008-11-08 16:16:49 +08:00
|
|
|
}
|
|
|
|
*(intptr_t *)StubAddr = 0xe51ff004; // ldr pc, [pc, #-4]
|
2008-10-21 05:39:23 +08:00
|
|
|
*(intptr_t *)(StubAddr+4) = NewVal;
|
2008-11-08 16:16:49 +08:00
|
|
|
if (!sys::Memory::setRangeExecutable((void*)StubAddr, 8)) {
|
2009-07-15 00:55:14 +08:00
|
|
|
llvm_unreachable("ERROR: Unable to mark stub executable");
|
2008-11-08 16:16:49 +08:00
|
|
|
}
|
2007-07-06 05:15:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TargetJITInfo::LazyResolverFn
|
|
|
|
ARMJITInfo::getLazyResolverFunction(JITCompilerFn F) {
|
|
|
|
JITCompilerFunction = F;
|
|
|
|
return ARMCompilationCallback;
|
|
|
|
}
|
|
|
|
|
2008-11-10 09:08:07 +08:00
|
|
|
void *ARMJITInfo::emitGlobalValueIndirectSym(const GlobalValue *GV, void *Ptr,
|
2009-05-31 04:51:52 +08:00
|
|
|
JITCodeEmitter &JCE) {
|
2009-12-16 06:42:46 +08:00
|
|
|
uint8_t Buffer[4];
|
|
|
|
uint8_t *Cur = Buffer;
|
|
|
|
MachineCodeEmitter::emitWordLEInto(Cur, (intptr_t)Ptr);
|
|
|
|
void *PtrAddr = JCE.allocIndirectGV(
|
|
|
|
GV, Buffer, sizeof(Buffer), /*Alignment=*/4);
|
2008-11-11 07:14:47 +08:00
|
|
|
addIndirectSymAddr(Ptr, (intptr_t)PtrAddr);
|
|
|
|
return PtrAddr;
|
2008-11-08 09:31:27 +08:00
|
|
|
}
|
|
|
|
|
2009-11-24 07:35:19 +08:00
|
|
|
TargetJITInfo::StubLayout ARMJITInfo::getStubLayout() {
|
|
|
|
// The stub contains up to 3 4-byte instructions, aligned at 4 bytes, and a
|
|
|
|
// 4-byte address. See emitFunctionStub for details.
|
|
|
|
StubLayout Result = {16, 4};
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2008-04-17 04:46:05 +08:00
|
|
|
void *ARMJITInfo::emitFunctionStub(const Function* F, void *Fn,
|
2009-05-31 04:51:52 +08:00
|
|
|
JITCodeEmitter &JCE) {
|
2009-11-24 07:35:19 +08:00
|
|
|
void *Addr;
|
2007-07-06 05:15:40 +08:00
|
|
|
// If this is just a call to an external function, emit a branch instead of a
|
|
|
|
// call. The code is the same except for one bit of the last instruction.
|
|
|
|
if (Fn != (void*)(intptr_t)ARMCompilationCallback) {
|
2008-11-08 09:31:27 +08:00
|
|
|
// Branch to the corresponding function addr.
|
2008-11-11 07:14:47 +08:00
|
|
|
if (IsPIC) {
|
2009-11-24 07:35:19 +08:00
|
|
|
// The stub is 16-byte size and 4-aligned.
|
2008-11-11 07:14:47 +08:00
|
|
|
intptr_t LazyPtr = getIndirectSymAddr(Fn);
|
|
|
|
if (!LazyPtr) {
|
|
|
|
// In PIC mode, the function stub is loading a lazy-ptr.
|
2009-05-31 04:51:52 +08:00
|
|
|
LazyPtr= (intptr_t)emitGlobalValueIndirectSym((GlobalValue*)F, Fn, JCE);
|
2009-07-25 08:23:56 +08:00
|
|
|
DEBUG(if (F)
|
2009-08-11 23:33:49 +08:00
|
|
|
errs() << "JIT: Indirect symbol emitted at [" << LazyPtr
|
2009-07-25 08:23:56 +08:00
|
|
|
<< "] for GV '" << F->getName() << "'\n";
|
|
|
|
else
|
|
|
|
errs() << "JIT: Stub emitted at [" << LazyPtr
|
|
|
|
<< "] for external function at '" << Fn << "'\n");
|
2008-11-11 07:14:47 +08:00
|
|
|
}
|
2009-11-24 07:35:19 +08:00
|
|
|
JCE.emitAlignment(4);
|
|
|
|
Addr = (void*)JCE.getCurrentPCValue();
|
|
|
|
if (!sys::Memory::setRangeWritable(Addr, 16)) {
|
2009-09-09 09:56:29 +08:00
|
|
|
llvm_unreachable("ERROR: Unable to mark stub writable");
|
|
|
|
}
|
2009-11-20 08:21:55 +08:00
|
|
|
JCE.emitWordLE(0xe59fc004); // ldr ip, [pc, #+4]
|
2009-05-31 04:51:52 +08:00
|
|
|
JCE.emitWordLE(0xe08fc00c); // L_func$scv: add ip, pc, ip
|
|
|
|
JCE.emitWordLE(0xe59cf000); // ldr pc, [ip]
|
2009-11-24 07:35:19 +08:00
|
|
|
JCE.emitWordLE(LazyPtr - (intptr_t(Addr)+4+8)); // func - (L_func$scv+8)
|
|
|
|
sys::Memory::InvalidateInstructionCache(Addr, 16);
|
|
|
|
if (!sys::Memory::setRangeExecutable(Addr, 16)) {
|
2009-09-09 09:56:29 +08:00
|
|
|
llvm_unreachable("ERROR: Unable to mark stub executable");
|
|
|
|
}
|
2008-11-11 07:14:47 +08:00
|
|
|
} else {
|
|
|
|
// The stub is 8-byte size and 4-aligned.
|
2009-11-24 07:35:19 +08:00
|
|
|
JCE.emitAlignment(4);
|
|
|
|
Addr = (void*)JCE.getCurrentPCValue();
|
|
|
|
if (!sys::Memory::setRangeWritable(Addr, 8)) {
|
2009-09-09 09:56:29 +08:00
|
|
|
llvm_unreachable("ERROR: Unable to mark stub writable");
|
|
|
|
}
|
2009-05-31 04:51:52 +08:00
|
|
|
JCE.emitWordLE(0xe51ff004); // ldr pc, [pc, #-4]
|
|
|
|
JCE.emitWordLE((intptr_t)Fn); // addr of function
|
2009-11-24 07:35:19 +08:00
|
|
|
sys::Memory::InvalidateInstructionCache(Addr, 8);
|
|
|
|
if (!sys::Memory::setRangeExecutable(Addr, 8)) {
|
2009-09-09 09:56:29 +08:00
|
|
|
llvm_unreachable("ERROR: Unable to mark stub executable");
|
|
|
|
}
|
2008-11-11 07:14:47 +08:00
|
|
|
}
|
2007-07-06 05:15:40 +08:00
|
|
|
} else {
|
2008-10-21 05:39:23 +08:00
|
|
|
// The compilation callback will overwrite the first two words of this
|
2009-08-11 23:33:49 +08:00
|
|
|
// stub with indirect branch instructions targeting the compiled code.
|
2008-10-21 05:39:23 +08:00
|
|
|
// This stub sets the return address to restart the stub, so that
|
|
|
|
// the new branch will be invoked when we come back.
|
|
|
|
//
|
2008-11-08 09:31:27 +08:00
|
|
|
// Branch and link to the compilation callback.
|
|
|
|
// The stub is 16-byte size and 4-byte aligned.
|
2009-11-24 07:35:19 +08:00
|
|
|
JCE.emitAlignment(4);
|
|
|
|
Addr = (void*)JCE.getCurrentPCValue();
|
|
|
|
if (!sys::Memory::setRangeWritable(Addr, 16)) {
|
2009-09-09 09:56:29 +08:00
|
|
|
llvm_unreachable("ERROR: Unable to mark stub writable");
|
|
|
|
}
|
2008-10-21 05:39:23 +08:00
|
|
|
// Save LR so the callback can determine which stub called it.
|
|
|
|
// The compilation callback is responsible for popping this prior
|
|
|
|
// to returning.
|
2009-05-31 04:51:52 +08:00
|
|
|
JCE.emitWordLE(0xe92d4000); // push {lr}
|
2008-11-08 16:16:49 +08:00
|
|
|
// Set the return address to go back to the start of this stub.
|
2009-05-31 04:51:52 +08:00
|
|
|
JCE.emitWordLE(0xe24fe00c); // sub lr, pc, #12
|
2008-11-08 16:16:49 +08:00
|
|
|
// Invoke the compilation callback.
|
2009-05-31 04:51:52 +08:00
|
|
|
JCE.emitWordLE(0xe51ff004); // ldr pc, [pc, #-4]
|
2008-11-08 16:16:49 +08:00
|
|
|
// The address of the compilation callback.
|
2009-05-31 04:51:52 +08:00
|
|
|
JCE.emitWordLE((intptr_t)ARMCompilationCallback);
|
2009-11-24 07:35:19 +08:00
|
|
|
sys::Memory::InvalidateInstructionCache(Addr, 16);
|
|
|
|
if (!sys::Memory::setRangeExecutable(Addr, 16)) {
|
2009-09-09 09:56:29 +08:00
|
|
|
llvm_unreachable("ERROR: Unable to mark stub executable");
|
|
|
|
}
|
2007-07-06 05:15:40 +08:00
|
|
|
}
|
|
|
|
|
2009-11-24 07:35:19 +08:00
|
|
|
return Addr;
|
2007-07-06 05:15:40 +08:00
|
|
|
}
|
|
|
|
|
2008-11-07 17:06:08 +08:00
|
|
|
intptr_t ARMJITInfo::resolveRelocDestAddr(MachineRelocation *MR) const {
|
2008-11-04 08:50:32 +08:00
|
|
|
ARM::RelocationType RT = (ARM::RelocationType)MR->getRelocationType();
|
2008-11-12 09:02:24 +08:00
|
|
|
switch (RT) {
|
|
|
|
default:
|
|
|
|
return (intptr_t)(MR->getResultPointer());
|
|
|
|
case ARM::reloc_arm_pic_jt:
|
2008-11-08 06:30:53 +08:00
|
|
|
// Destination address - jump table base.
|
|
|
|
return (intptr_t)(MR->getResultPointer()) - MR->getConstantVal();
|
2008-11-12 09:02:24 +08:00
|
|
|
case ARM::reloc_arm_jt_base:
|
2008-11-08 06:30:53 +08:00
|
|
|
// Jump table base address.
|
2008-11-07 17:06:08 +08:00
|
|
|
return getJumpTableBaseAddr(MR->getJumpTableIndex());
|
2008-11-12 09:02:24 +08:00
|
|
|
case ARM::reloc_arm_cp_entry:
|
|
|
|
case ARM::reloc_arm_vfp_cp_entry:
|
2008-11-08 06:30:53 +08:00
|
|
|
// Constant pool entry address.
|
2008-11-04 08:50:32 +08:00
|
|
|
return getConstantPoolEntryAddr(MR->getConstantPoolIndex());
|
2008-11-12 09:02:24 +08:00
|
|
|
case ARM::reloc_arm_machine_cp_entry: {
|
2008-11-08 06:57:53 +08:00
|
|
|
ARMConstantPoolValue *ACPV = (ARMConstantPoolValue*)MR->getConstantVal();
|
2008-11-04 08:50:32 +08:00
|
|
|
assert((!ACPV->hasModifier() && !ACPV->mustAddCurrentAddress()) &&
|
|
|
|
"Can't handle this machine constant pool entry yet!");
|
|
|
|
intptr_t Addr = (intptr_t)(MR->getResultPointer());
|
|
|
|
Addr -= getPCLabelAddr(ACPV->getLabelId()) + ACPV->getPCAdjustment();
|
|
|
|
return Addr;
|
|
|
|
}
|
2008-11-12 09:02:24 +08:00
|
|
|
}
|
2008-11-04 08:50:32 +08:00
|
|
|
}
|
|
|
|
|
2007-07-06 05:15:40 +08:00
|
|
|
/// relocate - Before the JIT can run a block of code that has been emitted,
|
|
|
|
/// it must rewrite the code to contain the actual addresses of any
|
|
|
|
/// referenced global symbols.
|
|
|
|
void ARMJITInfo::relocate(void *Function, MachineRelocation *MR,
|
|
|
|
unsigned NumRelocs, unsigned char* GOTBase) {
|
2007-08-07 09:37:15 +08:00
|
|
|
for (unsigned i = 0; i != NumRelocs; ++i, ++MR) {
|
|
|
|
void *RelocPos = (char*)Function + MR->getMachineCodeOffset();
|
2008-11-07 17:06:08 +08:00
|
|
|
intptr_t ResultPtr = resolveRelocDestAddr(MR);
|
2007-08-07 09:37:15 +08:00
|
|
|
switch ((ARM::RelocationType)MR->getRelocationType()) {
|
2008-10-30 07:55:43 +08:00
|
|
|
case ARM::reloc_arm_cp_entry:
|
2008-11-12 09:02:24 +08:00
|
|
|
case ARM::reloc_arm_vfp_cp_entry:
|
2007-08-07 09:37:15 +08:00
|
|
|
case ARM::reloc_arm_relative: {
|
2007-08-31 07:21:27 +08:00
|
|
|
// It is necessary to calculate the correct PC relative value. We
|
|
|
|
// subtract the base addr from the target addr to form a byte offset.
|
2008-11-12 09:02:24 +08:00
|
|
|
ResultPtr = ResultPtr - (intptr_t)RelocPos - 8;
|
2007-08-31 07:21:27 +08:00
|
|
|
// If the result is positive, set bit U(23) to 1.
|
|
|
|
if (ResultPtr >= 0)
|
2008-11-12 09:02:24 +08:00
|
|
|
*((intptr_t*)RelocPos) |= 1 << ARMII::U_BitShift;
|
2007-08-31 07:21:27 +08:00
|
|
|
else {
|
2008-11-12 09:02:24 +08:00
|
|
|
// Otherwise, obtain the absolute value and set bit U(23) to 0.
|
2008-11-13 05:37:59 +08:00
|
|
|
*((intptr_t*)RelocPos) &= ~(1 << ARMII::U_BitShift);
|
2008-11-12 09:02:24 +08:00
|
|
|
ResultPtr = - ResultPtr;
|
2007-08-31 07:21:27 +08:00
|
|
|
}
|
2008-11-04 08:50:32 +08:00
|
|
|
// Set the immed value calculated.
|
2008-11-12 09:02:24 +08:00
|
|
|
// VFP immediate offset is multiplied by 4.
|
|
|
|
if (MR->getRelocationType() == ARM::reloc_arm_vfp_cp_entry)
|
|
|
|
ResultPtr = ResultPtr >> 2;
|
|
|
|
*((intptr_t*)RelocPos) |= ResultPtr;
|
2008-11-04 08:50:32 +08:00
|
|
|
// Set register Rn to PC.
|
2008-11-12 09:02:24 +08:00
|
|
|
*((intptr_t*)RelocPos) |=
|
2010-09-16 04:26:25 +08:00
|
|
|
getARMRegisterNumbering(ARM::PC) << ARMII::RegRnShift;
|
2007-08-07 09:37:15 +08:00
|
|
|
break;
|
|
|
|
}
|
2008-11-08 06:30:53 +08:00
|
|
|
case ARM::reloc_arm_pic_jt:
|
2008-11-04 08:50:32 +08:00
|
|
|
case ARM::reloc_arm_machine_cp_entry:
|
2008-10-30 07:55:43 +08:00
|
|
|
case ARM::reloc_arm_absolute: {
|
2008-11-04 08:50:32 +08:00
|
|
|
// These addresses have already been resolved.
|
2008-11-12 09:02:24 +08:00
|
|
|
*((intptr_t*)RelocPos) |= (intptr_t)ResultPtr;
|
2008-10-30 07:55:43 +08:00
|
|
|
break;
|
|
|
|
}
|
2007-08-07 09:37:15 +08:00
|
|
|
case ARM::reloc_arm_branch: {
|
2007-08-31 07:21:27 +08:00
|
|
|
// It is necessary to calculate the correct value of signed_immed_24
|
|
|
|
// field. We subtract the base addr from the target addr to form a
|
|
|
|
// byte offset, which must be inside the range -33554432 and +33554428.
|
|
|
|
// Then, we set the signed_immed_24 field of the instruction to bits
|
|
|
|
// [25:2] of the byte offset. More details ARM-ARM p. A4-11.
|
2008-11-07 17:06:08 +08:00
|
|
|
ResultPtr = ResultPtr - (intptr_t)RelocPos - 8;
|
2007-08-31 07:21:27 +08:00
|
|
|
ResultPtr = (ResultPtr & 0x03FFFFFC) >> 2;
|
|
|
|
assert(ResultPtr >= -33554432 && ResultPtr <= 33554428);
|
2008-11-12 09:02:24 +08:00
|
|
|
*((intptr_t*)RelocPos) |= ResultPtr;
|
2007-08-07 09:37:15 +08:00
|
|
|
break;
|
|
|
|
}
|
2008-11-07 17:06:08 +08:00
|
|
|
case ARM::reloc_arm_jt_base: {
|
|
|
|
// JT base - (instruction addr + 8)
|
|
|
|
ResultPtr = ResultPtr - (intptr_t)RelocPos - 8;
|
2008-11-12 09:02:24 +08:00
|
|
|
*((intptr_t*)RelocPos) |= ResultPtr;
|
2008-11-07 17:06:08 +08:00
|
|
|
break;
|
|
|
|
}
|
2010-05-25 16:42:45 +08:00
|
|
|
case ARM::reloc_arm_movw: {
|
|
|
|
ResultPtr = ResultPtr & 0xFFFF;
|
|
|
|
*((intptr_t*)RelocPos) |= ResultPtr & 0xFFF;
|
|
|
|
*((intptr_t*)RelocPos) |= ((ResultPtr >> 12) & 0xF) << 16;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ARM::reloc_arm_movt: {
|
|
|
|
ResultPtr = (ResultPtr >> 16) & 0xFFFF;
|
|
|
|
*((intptr_t*)RelocPos) |= ResultPtr & 0xFFF;
|
|
|
|
*((intptr_t*)RelocPos) |= ((ResultPtr >> 12) & 0xF) << 16;
|
|
|
|
break;
|
|
|
|
}
|
2007-08-07 09:37:15 +08:00
|
|
|
}
|
|
|
|
}
|
2007-07-06 05:15:40 +08:00
|
|
|
}
|