1 #ifdef USE_PRAGMA_IDENT_SRC 2 #pragma ident "@(#)relocInfo_sparc.cpp 1.31 07/05/05 17:04:31 JVM" 3 #endif 4 /* 5 * Copyright 1998-2005 Sun Microsystems, Inc. All Rights Reserved. 6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7 * 8 * This code is free software; you can redistribute it and/or modify it 9 * under the terms of the GNU General Public License version 2 only, as 10 * published by the Free Software Foundation. 11 * 12 * This code is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * version 2 for more details (a copy is included in the LICENSE file that 16 * accompanied this code). 17 * 18 * You should have received a copy of the GNU General Public License version 19 * 2 along with this work; if not, write to the Free Software Foundation, 20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21 * 22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 23 * CA 95054 USA or visit www.sun.com if you need additional information or 24 * have any questions. 25 * 26 */ 27 28 # include "incls/_precompiled.incl" 29 # include "incls/_relocInfo_sparc.cpp.incl" 30 31 void Relocation::pd_set_data_value(address x, intptr_t o) { 32 NativeInstruction* ip = nativeInstruction_at(addr()); 33 jint inst = ip->long_at(0); 34 assert(inst != NativeInstruction::illegal_instruction(), "no breakpoint"); 35 switch (Assembler::inv_op(inst)) { 36 37 case Assembler::ldst_op: 38 #ifdef ASSERT 39 switch (Assembler::inv_op3(inst)) { 40 case Assembler::lduw_op3: 41 case Assembler::ldub_op3: 42 case Assembler::lduh_op3: 43 case Assembler::ldd_op3: 44 case Assembler::ldsw_op3: 45 case Assembler::ldsb_op3: 46 case Assembler::ldsh_op3: 47 case Assembler::ldx_op3: 48 case Assembler::ldf_op3: 49 case Assembler::lddf_op3: 50 case Assembler::stw_op3: 51 case Assembler::stb_op3: 52 case Assembler::sth_op3: 53 case Assembler::std_op3: 54 case Assembler::stx_op3: 55 case Assembler::stf_op3: 56 case Assembler::stdf_op3: 57 case Assembler::casa_op3: 58 case Assembler::casxa_op3: 59 break; 60 default: 61 ShouldNotReachHere(); 62 } 63 goto do_non_sethi; 64 #endif 65 66 case Assembler::arith_op: 67 #ifdef ASSERT 68 switch (Assembler::inv_op3(inst)) { 69 case Assembler::or_op3: 70 case Assembler::add_op3: 71 case Assembler::jmpl_op3: 72 break; 73 default: 74 ShouldNotReachHere(); 75 } 76 do_non_sethi:; 77 #endif 78 { 79 guarantee(Assembler::inv_immed(inst), "must have a simm13 field"); 80 int simm13 = Assembler::low10((intptr_t)x) + o; 81 guarantee(Assembler::is_simm13(simm13), "offset can't overflow simm13"); 82 inst &= ~Assembler::simm( -1, 13); 83 inst |= Assembler::simm(simm13, 13); 84 ip->set_long_at(0, inst); 85 } 86 break; 87 88 case Assembler::branch_op: 89 { 90 #ifdef _LP64 91 jint inst2; 92 guarantee(Assembler::inv_op2(inst)==Assembler::sethi_op2, "must be sethi"); 93 ip->set_data64_sethi( ip->addr_at(0), (intptr_t)x ); 94 #ifdef COMPILER2 95 // [RGV] Someone must have missed putting in a reloc entry for the 96 // add in compiler2. 97 inst2 = ip->long_at( NativeMovConstReg::add_offset ); 98 guarantee(Assembler::inv_op(inst2)==Assembler::arith_op, "arith op"); 99 ip->set_long_at(NativeMovConstReg::add_offset,ip->set_data32_simm13( inst2, (intptr_t)x+o)); 100 #endif 101 #else 102 guarantee(Assembler::inv_op2(inst)==Assembler::sethi_op2, "must be sethi"); 103 inst &= ~Assembler::hi22( -1); 104 inst |= Assembler::hi22((intptr_t)x); 105 // (ignore offset; it doesn't play into the sethi) 106 ip->set_long_at(0, inst); 107 #endif 108 } 109 break; 110 111 default: 112 guarantee(false, "instruction must perform arithmetic or memory access"); 113 } 114 } 115 116 117 address Relocation::pd_call_destination(address orig_addr) { 118 intptr_t adj = 0; 119 if (orig_addr != NULL) { 120 // We just moved this call instruction from orig_addr to addr(). 121 // This means its target will appear to have grown by addr() - orig_addr. 122 adj = -( addr() - orig_addr ); 123 } 124 if (NativeCall::is_call_at(addr())) { 125 NativeCall* call = nativeCall_at(addr()); 126 return call->destination() + adj; 127 } 128 if (NativeFarCall::is_call_at(addr())) { 129 NativeFarCall* call = nativeFarCall_at(addr()); 130 return call->destination() + adj; 131 } 132 // Special case: Patchable branch local to the code cache. 133 // This will break badly if the code cache grows larger than a few Mb. 134 NativeGeneralJump* br = nativeGeneralJump_at(addr()); 135 return br->jump_destination() + adj; 136 } 137 138 139 void Relocation::pd_set_call_destination(address x) { 140 if (NativeCall::is_call_at(addr())) { 141 NativeCall* call = nativeCall_at(addr()); 142 call->set_destination(x); 143 return; 144 } 145 if (NativeFarCall::is_call_at(addr())) { 146 NativeFarCall* call = nativeFarCall_at(addr()); 147 call->set_destination(x); 148 return; 149 } 150 // Special case: Patchable branch local to the code cache. 151 // This will break badly if the code cache grows larger than a few Mb. 152 NativeGeneralJump* br = nativeGeneralJump_at(addr()); 153 br->set_jump_destination(x); 154 } 155 156 157 address* Relocation::pd_address_in_code() { 158 // SPARC never embeds addresses in code, at present. 159 //assert(type() == relocInfo::oop_type, "only oops are inlined at present"); 160 return (address*)addr(); 161 } 162 163 164 address Relocation::pd_get_address_from_code() { 165 // SPARC never embeds addresses in code, at present. 166 //assert(type() == relocInfo::oop_type, "only oops are inlined at present"); 167 return *(address*)addr(); 168 } 169 170 171 int Relocation::pd_breakpoint_size() { 172 // minimum breakpoint size, in short words 173 return NativeIllegalInstruction::instruction_size / sizeof(short); 174 } 175 176 void Relocation::pd_swap_in_breakpoint(address x, short* instrs, int instrlen) { 177 Untested("pd_swap_in_breakpoint"); 178 // %%% probably do not need a general instrlen; just use the trap size 179 if (instrs != NULL) { 180 assert(instrlen * sizeof(short) == NativeIllegalInstruction::instruction_size, "enough instrlen in reloc. data"); 181 for (int i = 0; i < instrlen; i++) { 182 instrs[i] = ((short*)x)[i]; 183 } 184 } 185 NativeIllegalInstruction::insert(x); 186 } 187 188 189 void Relocation::pd_swap_out_breakpoint(address x, short* instrs, int instrlen) { 190 Untested("pd_swap_out_breakpoint"); 191 assert(instrlen * sizeof(short) == sizeof(int), "enough buf"); 192 union { int l; short s[1]; } u; 193 for (int i = 0; i < instrlen; i++) { 194 u.s[i] = instrs[i]; 195 } 196 NativeInstruction* ni = nativeInstruction_at(x); 197 ni->set_long_at(0, u.l); 198 }