1 /*
   2  * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright 2012, 2015 SAP AG. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #include "precompiled.hpp"
  27 #include "asm/assembler.inline.hpp"
  28 #include "code/relocInfo.hpp"
  29 #include "nativeInst_ppc.hpp"
  30 #include "oops/klass.inline.hpp"
  31 #include "oops/oop.inline.hpp"
  32 #include "runtime/safepoint.hpp"
  33 
  34 void Relocation::pd_set_data_value(address x, intptr_t o, bool verify_only) {
  35   // The following comment is from the declaration of DataRelocation:
  36   //
  37   //  "The "o" (displacement) argument is relevant only to split relocations
  38   //   on RISC machines.  In some CPUs (SPARC), the set-hi and set-lo ins'ns
  39   //   can encode more than 32 bits between them.  This allows compilers to
  40   //   share set-hi instructions between addresses that differ by a small
  41   //   offset (e.g., different static variables in the same class).
  42   //   On such machines, the "x" argument to set_value on all set-lo
  43   //   instructions must be the same as the "x" argument for the
  44   //   corresponding set-hi instructions.  The "o" arguments for the
  45   //   set-hi instructions are ignored, and must not affect the high-half
  46   //   immediate constant.  The "o" arguments for the set-lo instructions are
  47   //   added into the low-half immediate constant, and must not overflow it."
  48   //
  49   // Currently we don't support splitting of relocations, so o must be
  50   // zero:
  51   assert(o == 0, "tried to split relocations");
  52 
  53   if (!verify_only) {
  54     if (format() != 1) {
  55       nativeMovConstReg_at(addr())->set_data_plain(((intptr_t)x), code());
  56     } else {
  57       assert(type() == relocInfo::oop_type || type() == relocInfo::metadata_type,
  58              "how to encode else?");
  59       narrowOop no = (type() == relocInfo::oop_type) ?
  60         oopDesc::encode_heap_oop((oop)x) : Klass::encode_klass((Klass*)x);
  61       nativeMovConstReg_at(addr())->set_narrow_oop(no, code());
  62     }
  63   } else {
  64     guarantee((address) (nativeMovConstReg_at(addr())->data()) == x, "data must match");
  65   }
  66 }
  67 
  68 address Relocation::pd_call_destination(address orig_addr) {
  69   intptr_t adj = 0;
  70   address inst_loc = addr();
  71 
  72   if (orig_addr != NULL) {
  73     // We just moved this call instruction from orig_addr to addr().
  74     // This means its target will appear to have grown by addr() - orig_addr.
  75     adj = -(inst_loc - orig_addr);
  76   }
  77   if (NativeFarCall::is_far_call_at(inst_loc)) {
  78     NativeFarCall* call = nativeFarCall_at(inst_loc);
  79     return call->destination() + (intptr_t)(call->is_pcrelative() ? adj : 0);
  80   } else if (NativeJump::is_jump_at(inst_loc)) {
  81     NativeJump* jump = nativeJump_at(inst_loc);
  82     return jump->jump_destination() + (intptr_t)(jump->is_pcrelative() ? adj : 0);
  83   } else if (NativeConditionalFarBranch::is_conditional_far_branch_at(inst_loc)) {
  84     NativeConditionalFarBranch* branch = NativeConditionalFarBranch_at(inst_loc);
  85     return branch->branch_destination();
  86   } else {
  87     orig_addr = nativeCall_at(inst_loc)->get_trampoline();
  88     if (orig_addr == NULL) {
  89       return (address) -1;
  90     } else {
  91       return ((NativeCallTrampolineStub*)orig_addr)->destination();
  92     }
  93   }
  94 }
  95 
  96 void Relocation::pd_set_call_destination(address x) {
  97   address inst_loc = addr();
  98 
  99   if (NativeFarCall::is_far_call_at(inst_loc)) {
 100     NativeFarCall* call = nativeFarCall_at(inst_loc);
 101     call->set_destination(x);
 102   } else if (NativeJump::is_jump_at(inst_loc)) {
 103     NativeJump* jump= nativeJump_at(inst_loc);
 104     jump->set_jump_destination(x);
 105   } else if (NativeConditionalFarBranch::is_conditional_far_branch_at(inst_loc)) {
 106     NativeConditionalFarBranch* branch = NativeConditionalFarBranch_at(inst_loc);
 107     branch->set_branch_destination(x);
 108   } else {
 109     NativeCall* call = nativeCall_at(inst_loc);
 110     call->set_destination_mt_safe(x, false);
 111   }
 112 }
 113 
 114 address* Relocation::pd_address_in_code() {
 115   ShouldNotReachHere();
 116   return 0;
 117 }
 118 
 119 address Relocation::pd_get_address_from_code() {
 120   return (address)(nativeMovConstReg_at(addr())->data());
 121 }
 122 
 123 void poll_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
 124 }
 125 
 126 void metadata_Relocation::pd_fix_value(address x) {
 127 }