src/cpu/sparc/vm/relocInfo_sparc.cpp

changeset 435
a61af66fc99e
child 599
c436414a719e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/cpu/sparc/vm/relocInfo_sparc.cpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,195 @@
     1.4 +/*
     1.5 + * Copyright 1998-2005 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +# include "incls/_precompiled.incl"
    1.29 +# include "incls/_relocInfo_sparc.cpp.incl"
    1.30 +
    1.31 +void Relocation::pd_set_data_value(address x, intptr_t o) {
    1.32 +  NativeInstruction* ip = nativeInstruction_at(addr());
    1.33 +  jint inst = ip->long_at(0);
    1.34 +  assert(inst != NativeInstruction::illegal_instruction(), "no breakpoint");
    1.35 +  switch (Assembler::inv_op(inst)) {
    1.36 +
    1.37 +  case Assembler::ldst_op:
    1.38 +    #ifdef ASSERT
    1.39 +      switch (Assembler::inv_op3(inst)) {
    1.40 +        case Assembler::lduw_op3:
    1.41 +        case Assembler::ldub_op3:
    1.42 +        case Assembler::lduh_op3:
    1.43 +        case Assembler::ldd_op3:
    1.44 +        case Assembler::ldsw_op3:
    1.45 +        case Assembler::ldsb_op3:
    1.46 +        case Assembler::ldsh_op3:
    1.47 +        case Assembler::ldx_op3:
    1.48 +        case Assembler::ldf_op3:
    1.49 +        case Assembler::lddf_op3:
    1.50 +        case Assembler::stw_op3:
    1.51 +        case Assembler::stb_op3:
    1.52 +        case Assembler::sth_op3:
    1.53 +        case Assembler::std_op3:
    1.54 +        case Assembler::stx_op3:
    1.55 +        case Assembler::stf_op3:
    1.56 +        case Assembler::stdf_op3:
    1.57 +        case Assembler::casa_op3:
    1.58 +        case Assembler::casxa_op3:
    1.59 +          break;
    1.60 +        default:
    1.61 +          ShouldNotReachHere();
    1.62 +      }
    1.63 +      goto do_non_sethi;
    1.64 +    #endif
    1.65 +
    1.66 +  case Assembler::arith_op:
    1.67 +    #ifdef ASSERT
    1.68 +      switch (Assembler::inv_op3(inst)) {
    1.69 +        case Assembler::or_op3:
    1.70 +        case Assembler::add_op3:
    1.71 +        case Assembler::jmpl_op3:
    1.72 +          break;
    1.73 +        default:
    1.74 +          ShouldNotReachHere();
    1.75 +      }
    1.76 +    do_non_sethi:;
    1.77 +    #endif
    1.78 +    {
    1.79 +    guarantee(Assembler::inv_immed(inst), "must have a simm13 field");
    1.80 +    int simm13 = Assembler::low10((intptr_t)x) + o;
    1.81 +    guarantee(Assembler::is_simm13(simm13), "offset can't overflow simm13");
    1.82 +    inst &= ~Assembler::simm(    -1, 13);
    1.83 +    inst |=  Assembler::simm(simm13, 13);
    1.84 +    ip->set_long_at(0, inst);
    1.85 +    }
    1.86 +    break;
    1.87 +
    1.88 +  case Assembler::branch_op:
    1.89 +    {
    1.90 +#ifdef _LP64
    1.91 +    jint inst2;
    1.92 +    guarantee(Assembler::inv_op2(inst)==Assembler::sethi_op2, "must be sethi");
    1.93 +    ip->set_data64_sethi( ip->addr_at(0), (intptr_t)x );
    1.94 +#ifdef COMPILER2
    1.95 +    // [RGV] Someone must have missed putting in a reloc entry for the
    1.96 +    // add in compiler2.
    1.97 +    inst2 = ip->long_at( NativeMovConstReg::add_offset );
    1.98 +    guarantee(Assembler::inv_op(inst2)==Assembler::arith_op, "arith op");
    1.99 +    ip->set_long_at(NativeMovConstReg::add_offset,ip->set_data32_simm13( inst2, (intptr_t)x+o));
   1.100 +#endif
   1.101 +#else
   1.102 +    guarantee(Assembler::inv_op2(inst)==Assembler::sethi_op2, "must be sethi");
   1.103 +    inst &= ~Assembler::hi22(     -1);
   1.104 +    inst |=  Assembler::hi22((intptr_t)x);
   1.105 +    // (ignore offset; it doesn't play into the sethi)
   1.106 +    ip->set_long_at(0, inst);
   1.107 +#endif
   1.108 +    }
   1.109 +    break;
   1.110 +
   1.111 +  default:
   1.112 +    guarantee(false, "instruction must perform arithmetic or memory access");
   1.113 +  }
   1.114 +}
   1.115 +
   1.116 +
   1.117 +address Relocation::pd_call_destination(address orig_addr) {
   1.118 +  intptr_t adj = 0;
   1.119 +  if (orig_addr != NULL) {
   1.120 +    // We just moved this call instruction from orig_addr to addr().
   1.121 +    // This means its target will appear to have grown by addr() - orig_addr.
   1.122 +    adj = -( addr() - orig_addr );
   1.123 +  }
   1.124 +  if (NativeCall::is_call_at(addr())) {
   1.125 +    NativeCall* call = nativeCall_at(addr());
   1.126 +    return call->destination() + adj;
   1.127 +  }
   1.128 +  if (NativeFarCall::is_call_at(addr())) {
   1.129 +    NativeFarCall* call = nativeFarCall_at(addr());
   1.130 +    return call->destination() + adj;
   1.131 +  }
   1.132 +  // Special case:  Patchable branch local to the code cache.
   1.133 +  // This will break badly if the code cache grows larger than a few Mb.
   1.134 +  NativeGeneralJump* br = nativeGeneralJump_at(addr());
   1.135 +  return br->jump_destination() + adj;
   1.136 +}
   1.137 +
   1.138 +
   1.139 +void Relocation::pd_set_call_destination(address x) {
   1.140 +  if (NativeCall::is_call_at(addr())) {
   1.141 +    NativeCall* call = nativeCall_at(addr());
   1.142 +    call->set_destination(x);
   1.143 +    return;
   1.144 +  }
   1.145 +  if (NativeFarCall::is_call_at(addr())) {
   1.146 +    NativeFarCall* call = nativeFarCall_at(addr());
   1.147 +    call->set_destination(x);
   1.148 +    return;
   1.149 +  }
   1.150 +  // Special case:  Patchable branch local to the code cache.
   1.151 +  // This will break badly if the code cache grows larger than a few Mb.
   1.152 +  NativeGeneralJump* br = nativeGeneralJump_at(addr());
   1.153 +  br->set_jump_destination(x);
   1.154 +}
   1.155 +
   1.156 +
   1.157 +address* Relocation::pd_address_in_code() {
   1.158 +  // SPARC never embeds addresses in code, at present.
   1.159 +  //assert(type() == relocInfo::oop_type, "only oops are inlined at present");
   1.160 +  return (address*)addr();
   1.161 +}
   1.162 +
   1.163 +
   1.164 +address Relocation::pd_get_address_from_code() {
   1.165 +  // SPARC never embeds addresses in code, at present.
   1.166 +  //assert(type() == relocInfo::oop_type, "only oops are inlined at present");
   1.167 +  return *(address*)addr();
   1.168 +}
   1.169 +
   1.170 +
   1.171 +int Relocation::pd_breakpoint_size() {
   1.172 +  // minimum breakpoint size, in short words
   1.173 +  return NativeIllegalInstruction::instruction_size / sizeof(short);
   1.174 +}
   1.175 +
   1.176 +void Relocation::pd_swap_in_breakpoint(address x, short* instrs, int instrlen) {
   1.177 +  Untested("pd_swap_in_breakpoint");
   1.178 +  // %%% probably do not need a general instrlen; just use the trap size
   1.179 +  if (instrs != NULL) {
   1.180 +    assert(instrlen * sizeof(short) == NativeIllegalInstruction::instruction_size, "enough instrlen in reloc. data");
   1.181 +    for (int i = 0; i < instrlen; i++) {
   1.182 +      instrs[i] = ((short*)x)[i];
   1.183 +    }
   1.184 +  }
   1.185 +  NativeIllegalInstruction::insert(x);
   1.186 +}
   1.187 +
   1.188 +
   1.189 +void Relocation::pd_swap_out_breakpoint(address x, short* instrs, int instrlen) {
   1.190 +  Untested("pd_swap_out_breakpoint");
   1.191 +  assert(instrlen * sizeof(short) == sizeof(int), "enough buf");
   1.192 +  union { int l; short s[1]; } u;
   1.193 +  for (int i = 0; i < instrlen; i++) {
   1.194 +    u.s[i] = instrs[i];
   1.195 +  }
   1.196 +  NativeInstruction* ni = nativeInstruction_at(x);
   1.197 +  ni->set_long_at(0, u.l);
   1.198 +}

mercurial