duke@435: /* trims@1907: * Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: duke@435: # include "incls/_precompiled.incl" duke@435: # include "incls/_relocInfo_sparc.cpp.incl" duke@435: duke@435: void Relocation::pd_set_data_value(address x, intptr_t o) { duke@435: NativeInstruction* ip = nativeInstruction_at(addr()); duke@435: jint inst = ip->long_at(0); duke@435: assert(inst != NativeInstruction::illegal_instruction(), "no breakpoint"); duke@435: switch (Assembler::inv_op(inst)) { duke@435: duke@435: case Assembler::ldst_op: duke@435: #ifdef ASSERT duke@435: switch (Assembler::inv_op3(inst)) { duke@435: case Assembler::lduw_op3: duke@435: case Assembler::ldub_op3: duke@435: case Assembler::lduh_op3: duke@435: case Assembler::ldd_op3: duke@435: case Assembler::ldsw_op3: duke@435: case Assembler::ldsb_op3: duke@435: case Assembler::ldsh_op3: duke@435: case Assembler::ldx_op3: duke@435: case Assembler::ldf_op3: duke@435: case Assembler::lddf_op3: duke@435: case Assembler::stw_op3: duke@435: case Assembler::stb_op3: duke@435: case Assembler::sth_op3: duke@435: case Assembler::std_op3: duke@435: case Assembler::stx_op3: duke@435: case Assembler::stf_op3: duke@435: case Assembler::stdf_op3: duke@435: case Assembler::casa_op3: duke@435: case Assembler::casxa_op3: duke@435: break; duke@435: default: duke@435: ShouldNotReachHere(); duke@435: } duke@435: goto do_non_sethi; duke@435: #endif duke@435: duke@435: case Assembler::arith_op: duke@435: #ifdef ASSERT duke@435: switch (Assembler::inv_op3(inst)) { duke@435: case Assembler::or_op3: duke@435: case Assembler::add_op3: duke@435: case Assembler::jmpl_op3: duke@435: break; duke@435: default: duke@435: ShouldNotReachHere(); duke@435: } duke@435: do_non_sethi:; duke@435: #endif duke@435: { duke@435: guarantee(Assembler::inv_immed(inst), "must have a simm13 field"); duke@435: int simm13 = Assembler::low10((intptr_t)x) + o; duke@435: guarantee(Assembler::is_simm13(simm13), "offset can't overflow simm13"); duke@435: inst &= ~Assembler::simm( -1, 13); duke@435: inst |= Assembler::simm(simm13, 13); duke@435: ip->set_long_at(0, inst); duke@435: } duke@435: break; duke@435: duke@435: case Assembler::branch_op: duke@435: { duke@435: #ifdef _LP64 duke@435: jint inst2; duke@435: guarantee(Assembler::inv_op2(inst)==Assembler::sethi_op2, "must be sethi"); kvn@599: if (format() != 0) { kvn@599: assert(type() == relocInfo::oop_type, "only narrow oops case"); kvn@599: jint np = oopDesc::encode_heap_oop((oop)x); kvn@599: inst &= ~Assembler::hi22(-1); kvn@599: inst |= Assembler::hi22((intptr_t)np); kvn@599: ip->set_long_at(0, inst); kvn@599: inst2 = ip->long_at( NativeInstruction::nop_instruction_size ); kvn@599: guarantee(Assembler::inv_op(inst2)==Assembler::arith_op, "arith op"); kvn@599: ip->set_long_at(NativeInstruction::nop_instruction_size, ip->set_data32_simm13( inst2, (intptr_t)np)); kvn@599: break; kvn@599: } duke@435: ip->set_data64_sethi( ip->addr_at(0), (intptr_t)x ); duke@435: #else duke@435: guarantee(Assembler::inv_op2(inst)==Assembler::sethi_op2, "must be sethi"); duke@435: inst &= ~Assembler::hi22( -1); duke@435: inst |= Assembler::hi22((intptr_t)x); duke@435: // (ignore offset; it doesn't play into the sethi) duke@435: ip->set_long_at(0, inst); duke@435: #endif duke@435: } duke@435: break; duke@435: duke@435: default: duke@435: guarantee(false, "instruction must perform arithmetic or memory access"); duke@435: } duke@435: } duke@435: duke@435: duke@435: address Relocation::pd_call_destination(address orig_addr) { duke@435: intptr_t adj = 0; duke@435: if (orig_addr != NULL) { duke@435: // We just moved this call instruction from orig_addr to addr(). duke@435: // This means its target will appear to have grown by addr() - orig_addr. duke@435: adj = -( addr() - orig_addr ); duke@435: } duke@435: if (NativeCall::is_call_at(addr())) { duke@435: NativeCall* call = nativeCall_at(addr()); duke@435: return call->destination() + adj; duke@435: } duke@435: if (NativeFarCall::is_call_at(addr())) { duke@435: NativeFarCall* call = nativeFarCall_at(addr()); duke@435: return call->destination() + adj; duke@435: } duke@435: // Special case: Patchable branch local to the code cache. duke@435: // This will break badly if the code cache grows larger than a few Mb. duke@435: NativeGeneralJump* br = nativeGeneralJump_at(addr()); duke@435: return br->jump_destination() + adj; duke@435: } duke@435: duke@435: duke@435: void Relocation::pd_set_call_destination(address x) { duke@435: if (NativeCall::is_call_at(addr())) { duke@435: NativeCall* call = nativeCall_at(addr()); duke@435: call->set_destination(x); duke@435: return; duke@435: } duke@435: if (NativeFarCall::is_call_at(addr())) { duke@435: NativeFarCall* call = nativeFarCall_at(addr()); duke@435: call->set_destination(x); duke@435: return; duke@435: } duke@435: // Special case: Patchable branch local to the code cache. duke@435: // This will break badly if the code cache grows larger than a few Mb. duke@435: NativeGeneralJump* br = nativeGeneralJump_at(addr()); duke@435: br->set_jump_destination(x); duke@435: } duke@435: duke@435: duke@435: address* Relocation::pd_address_in_code() { duke@435: // SPARC never embeds addresses in code, at present. duke@435: //assert(type() == relocInfo::oop_type, "only oops are inlined at present"); duke@435: return (address*)addr(); duke@435: } duke@435: duke@435: duke@435: address Relocation::pd_get_address_from_code() { duke@435: // SPARC never embeds addresses in code, at present. duke@435: //assert(type() == relocInfo::oop_type, "only oops are inlined at present"); duke@435: return *(address*)addr(); duke@435: } duke@435: duke@435: duke@435: int Relocation::pd_breakpoint_size() { duke@435: // minimum breakpoint size, in short words duke@435: return NativeIllegalInstruction::instruction_size / sizeof(short); duke@435: } duke@435: duke@435: void Relocation::pd_swap_in_breakpoint(address x, short* instrs, int instrlen) { duke@435: Untested("pd_swap_in_breakpoint"); duke@435: // %%% probably do not need a general instrlen; just use the trap size duke@435: if (instrs != NULL) { duke@435: assert(instrlen * sizeof(short) == NativeIllegalInstruction::instruction_size, "enough instrlen in reloc. data"); duke@435: for (int i = 0; i < instrlen; i++) { duke@435: instrs[i] = ((short*)x)[i]; duke@435: } duke@435: } duke@435: NativeIllegalInstruction::insert(x); duke@435: } duke@435: duke@435: duke@435: void Relocation::pd_swap_out_breakpoint(address x, short* instrs, int instrlen) { duke@435: Untested("pd_swap_out_breakpoint"); duke@435: assert(instrlen * sizeof(short) == sizeof(int), "enough buf"); duke@435: union { int l; short s[1]; } u; duke@435: for (int i = 0; i < instrlen; i++) { duke@435: u.s[i] = instrs[i]; duke@435: } duke@435: NativeInstruction* ni = nativeInstruction_at(x); duke@435: ni->set_long_at(0, u.l); duke@435: } never@739: never@739: void poll_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) { never@739: } never@739: never@739: void poll_return_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) { never@739: }