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