duke@435: /* xdono@631: * Copyright 1997-2008 Sun Microsystems, Inc. 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: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: // We have interface for the following instructions: duke@435: // - NativeInstruction duke@435: // - - NativeCall duke@435: // - - NativeFarCall duke@435: // - - NativeMovConstReg duke@435: // - - NativeMovConstRegPatching duke@435: // - - NativeMovRegMem duke@435: // - - NativeMovRegMemPatching duke@435: // - - NativeJump duke@435: // - - NativeGeneralJump duke@435: // - - NativeIllegalInstruction duke@435: // The base class for different kinds of native instruction abstractions. duke@435: // Provides the primitive operations to manipulate code relative to this. duke@435: class NativeInstruction VALUE_OBJ_CLASS_SPEC { duke@435: friend class Relocation; duke@435: duke@435: public: duke@435: enum Sparc_specific_constants { duke@435: nop_instruction_size = 4 duke@435: }; duke@435: kamg@551: bool is_dtrace_trap(); duke@435: bool is_nop() { return long_at(0) == nop_instruction(); } duke@435: bool is_call() { return is_op(long_at(0), Assembler::call_op); } duke@435: bool is_sethi() { return (is_op2(long_at(0), Assembler::sethi_op2) duke@435: && inv_rd(long_at(0)) != G0); } duke@435: duke@435: bool sets_cc() { duke@435: // conservative (returns true for some instructions that do not set the duke@435: // the condition code, such as, "save". duke@435: // Does not return true for the deprecated tagged instructions, such as, TADDcc duke@435: int x = long_at(0); duke@435: return (is_op(x, Assembler::arith_op) && duke@435: (inv_op3(x) & Assembler::cc_bit_op3) == Assembler::cc_bit_op3); duke@435: } duke@435: bool is_illegal(); duke@435: bool is_zombie() { duke@435: int x = long_at(0); duke@435: return is_op3(x, duke@435: VM_Version::v9_instructions_work() ? duke@435: Assembler::ldsw_op3 : Assembler::lduw_op3, duke@435: Assembler::ldst_op) duke@435: && Assembler::inv_rs1(x) == G0 duke@435: && Assembler::inv_rd(x) == O7; duke@435: } duke@435: bool is_ic_miss_trap(); // Inline-cache uses a trap to detect a miss duke@435: bool is_return() { duke@435: // is it the output of MacroAssembler::ret or MacroAssembler::retl? duke@435: int x = long_at(0); duke@435: const int pc_return_offset = 8; // see frame_sparc.hpp duke@435: return is_op3(x, Assembler::jmpl_op3, Assembler::arith_op) duke@435: && (inv_rs1(x) == I7 || inv_rs1(x) == O7) duke@435: && inv_immed(x) && inv_simm(x, 13) == pc_return_offset duke@435: && inv_rd(x) == G0; duke@435: } duke@435: bool is_int_jump() { duke@435: // is it the output of MacroAssembler::b? duke@435: int x = long_at(0); duke@435: return is_op2(x, Assembler::bp_op2) || is_op2(x, Assembler::br_op2); duke@435: } duke@435: bool is_float_jump() { duke@435: // is it the output of MacroAssembler::fb? duke@435: int x = long_at(0); duke@435: return is_op2(x, Assembler::fbp_op2) || is_op2(x, Assembler::fb_op2); duke@435: } duke@435: bool is_jump() { duke@435: return is_int_jump() || is_float_jump(); duke@435: } duke@435: bool is_cond_jump() { duke@435: int x = long_at(0); duke@435: return (is_int_jump() && Assembler::inv_cond(x) != Assembler::always) || duke@435: (is_float_jump() && Assembler::inv_cond(x) != Assembler::f_always); duke@435: } duke@435: duke@435: bool is_stack_bang() { duke@435: int x = long_at(0); duke@435: return is_op3(x, Assembler::stw_op3, Assembler::ldst_op) && duke@435: (inv_rd(x) == G0) && (inv_rs1(x) == SP) && (inv_rs2(x) == G3_scratch); duke@435: } duke@435: duke@435: bool is_prefetch() { duke@435: int x = long_at(0); duke@435: return is_op3(x, Assembler::prefetch_op3, Assembler::ldst_op); duke@435: } duke@435: duke@435: bool is_membar() { duke@435: int x = long_at(0); duke@435: return is_op3(x, Assembler::membar_op3, Assembler::arith_op) && duke@435: (inv_rd(x) == G0) && (inv_rs1(x) == O7); duke@435: } duke@435: duke@435: bool is_safepoint_poll() { duke@435: int x = long_at(0); duke@435: #ifdef _LP64 duke@435: return is_op3(x, Assembler::ldx_op3, Assembler::ldst_op) && duke@435: #else duke@435: return is_op3(x, Assembler::lduw_op3, Assembler::ldst_op) && duke@435: #endif duke@435: (inv_rd(x) == G0) && (inv_immed(x) ? Assembler::inv_simm13(x) == 0 : inv_rs2(x) == G0); duke@435: } duke@435: duke@435: bool is_zero_test(Register ®); duke@435: bool is_load_store_with_small_offset(Register reg); duke@435: duke@435: public: duke@435: #ifdef ASSERT duke@435: static int rdpc_instruction() { return Assembler::op(Assembler::arith_op ) | Assembler::op3(Assembler::rdreg_op3) | Assembler::u_field(5, 18, 14) | Assembler::rd(O7); } duke@435: #else duke@435: // Temporary fix: in optimized mode, u_field is a macro for efficiency reasons (see Assembler::u_field) - needs to be fixed duke@435: static int rdpc_instruction() { return Assembler::op(Assembler::arith_op ) | Assembler::op3(Assembler::rdreg_op3) | u_field(5, 18, 14) | Assembler::rd(O7); } duke@435: #endif duke@435: static int nop_instruction() { return Assembler::op(Assembler::branch_op) | Assembler::op2(Assembler::sethi_op2); } duke@435: static int illegal_instruction(); // the output of __ breakpoint_trap() duke@435: static int call_instruction(address destination, address pc) { return Assembler::op(Assembler::call_op) | Assembler::wdisp((intptr_t)destination, (intptr_t)pc, 30); } duke@435: duke@435: static int branch_instruction(Assembler::op2s op2val, Assembler::Condition c, bool a) { duke@435: return Assembler::op(Assembler::branch_op) | Assembler::op2(op2val) | Assembler::annul(a) | Assembler::cond(c); duke@435: } duke@435: duke@435: static int op3_instruction(Assembler::ops opval, Register rd, Assembler::op3s op3val, Register rs1, int simm13a) { duke@435: return Assembler::op(opval) | Assembler::rd(rd) | Assembler::op3(op3val) | Assembler::rs1(rs1) | Assembler::immed(true) | Assembler::simm(simm13a, 13); duke@435: } duke@435: duke@435: static int sethi_instruction(Register rd, int imm22a) { duke@435: return Assembler::op(Assembler::branch_op) | Assembler::rd(rd) | Assembler::op2(Assembler::sethi_op2) | Assembler::hi22(imm22a); duke@435: } duke@435: duke@435: protected: duke@435: address addr_at(int offset) const { return address(this) + offset; } duke@435: int long_at(int offset) const { return *(int*)addr_at(offset); } duke@435: void set_long_at(int offset, int i); /* deals with I-cache */ duke@435: void set_jlong_at(int offset, jlong i); /* deals with I-cache */ duke@435: void set_addr_at(int offset, address x); /* deals with I-cache */ duke@435: duke@435: address instruction_address() const { return addr_at(0); } duke@435: address next_instruction_address() const { return addr_at(BytesPerInstWord); } duke@435: duke@435: static bool is_op( int x, Assembler::ops opval) { duke@435: return Assembler::inv_op(x) == opval; duke@435: } duke@435: static bool is_op2(int x, Assembler::op2s op2val) { duke@435: return Assembler::inv_op(x) == Assembler::branch_op && Assembler::inv_op2(x) == op2val; duke@435: } duke@435: static bool is_op3(int x, Assembler::op3s op3val, Assembler::ops opval) { duke@435: return Assembler::inv_op(x) == opval && Assembler::inv_op3(x) == op3val; duke@435: } duke@435: duke@435: // utilities to help subclasses decode: duke@435: static Register inv_rd( int x ) { return Assembler::inv_rd( x); } duke@435: static Register inv_rs1( int x ) { return Assembler::inv_rs1(x); } duke@435: static Register inv_rs2( int x ) { return Assembler::inv_rs2(x); } duke@435: duke@435: static bool inv_immed( int x ) { return Assembler::inv_immed(x); } duke@435: static bool inv_annul( int x ) { return (Assembler::annul(true) & x) != 0; } duke@435: static int inv_cond( int x ) { return Assembler::inv_cond(x); } duke@435: duke@435: static int inv_op( int x ) { return Assembler::inv_op( x); } duke@435: static int inv_op2( int x ) { return Assembler::inv_op2(x); } duke@435: static int inv_op3( int x ) { return Assembler::inv_op3(x); } duke@435: duke@435: static int inv_simm( int x, int nbits ) { return Assembler::inv_simm(x, nbits); } duke@435: static intptr_t inv_wdisp( int x, int nbits ) { return Assembler::inv_wdisp( x, 0, nbits); } duke@435: static intptr_t inv_wdisp16( int x ) { return Assembler::inv_wdisp16(x, 0); } duke@435: static int branch_destination_offset(int x) { return Assembler::branch_destination(x, 0); } duke@435: static int patch_branch_destination_offset(int dest_offset, int x) { duke@435: return Assembler::patched_branch(dest_offset, x, 0); duke@435: } duke@435: void set_annul_bit() { set_long_at(0, long_at(0) | Assembler::annul(true)); } duke@435: duke@435: // utility for checking if x is either of 2 small constants duke@435: static bool is_either(int x, int k1, int k2) { duke@435: // return x == k1 || x == k2; duke@435: return (1 << x) & (1 << k1 | 1 << k2); duke@435: } duke@435: duke@435: // utility for checking overflow of signed instruction fields duke@435: static bool fits_in_simm(int x, int nbits) { duke@435: // cf. Assembler::assert_signed_range() duke@435: // return -(1 << nbits-1) <= x && x < ( 1 << nbits-1), duke@435: return (unsigned)(x + (1 << nbits-1)) < (unsigned)(1 << nbits); duke@435: } duke@435: duke@435: // set a signed immediate field duke@435: static int set_simm(int insn, int imm, int nbits) { duke@435: return (insn &~ Assembler::simm(-1, nbits)) | Assembler::simm(imm, nbits); duke@435: } duke@435: duke@435: // set a wdisp field (disp should be the difference of two addresses) duke@435: static int set_wdisp(int insn, intptr_t disp, int nbits) { duke@435: return (insn &~ Assembler::wdisp((intptr_t)-4, (intptr_t)0, nbits)) | Assembler::wdisp(disp, 0, nbits); duke@435: } duke@435: duke@435: static int set_wdisp16(int insn, intptr_t disp) { duke@435: return (insn &~ Assembler::wdisp16((intptr_t)-4, 0)) | Assembler::wdisp16(disp, 0); duke@435: } duke@435: duke@435: // get a simm13 field from an arithmetic or memory instruction duke@435: static int get_simm13(int insn) { duke@435: assert(is_either(Assembler::inv_op(insn), duke@435: Assembler::arith_op, Assembler::ldst_op) && duke@435: (insn & Assembler::immed(true)), "must have a simm13 field"); duke@435: return Assembler::inv_simm(insn, 13); duke@435: } duke@435: duke@435: // set the simm13 field of an arithmetic or memory instruction duke@435: static bool set_simm13(int insn, int imm) { duke@435: get_simm13(insn); // tickle the assertion check duke@435: return set_simm(insn, imm, 13); duke@435: } duke@435: duke@435: // combine the fields of a sethi stream (7 instructions ) and an add, jmp or ld/st duke@435: static intptr_t data64( address pc, int arith_insn ) { duke@435: assert(is_op2(*(unsigned int *)pc, Assembler::sethi_op2), "must be sethi"); duke@435: intptr_t hi = (intptr_t)gethi( (unsigned int *)pc ); duke@435: intptr_t lo = (intptr_t)get_simm13(arith_insn); duke@435: assert((unsigned)lo < (1 << 10), "offset field of set_oop must be 10 bits"); duke@435: return hi | lo; duke@435: } duke@435: duke@435: // Regenerate the instruction sequence that performs the 64 bit duke@435: // sethi. This only does the sethi. The disp field (bottom 10 bits) twisti@1040: // must be handled separately. duke@435: static void set_data64_sethi(address instaddr, intptr_t x); duke@435: duke@435: // combine the fields of a sethi/simm13 pair (simm13 = or, add, jmpl, ld/st) duke@435: static int data32(int sethi_insn, int arith_insn) { duke@435: assert(is_op2(sethi_insn, Assembler::sethi_op2), "must be sethi"); duke@435: int hi = Assembler::inv_hi22(sethi_insn); duke@435: int lo = get_simm13(arith_insn); duke@435: assert((unsigned)lo < (1 << 10), "offset field of set_oop must be 10 bits"); duke@435: return hi | lo; duke@435: } duke@435: duke@435: static int set_data32_sethi(int sethi_insn, int imm) { duke@435: // note that Assembler::hi22 clips the low 10 bits for us duke@435: assert(is_op2(sethi_insn, Assembler::sethi_op2), "must be sethi"); duke@435: return (sethi_insn &~ Assembler::hi22(-1)) | Assembler::hi22(imm); duke@435: } duke@435: duke@435: static int set_data32_simm13(int arith_insn, int imm) { duke@435: get_simm13(arith_insn); // tickle the assertion check duke@435: int imm10 = Assembler::low10(imm); duke@435: return (arith_insn &~ Assembler::simm(-1, 13)) | Assembler::simm(imm10, 13); duke@435: } duke@435: duke@435: static int low10(int imm) { duke@435: return Assembler::low10(imm); duke@435: } duke@435: duke@435: // Perform the inverse of the LP64 Macroassembler::sethi duke@435: // routine. Extracts the 54 bits of address from the instruction duke@435: // stream. This routine must agree with the sethi routine in duke@435: // assembler_inline_sparc.hpp duke@435: static address gethi( unsigned int *pc ) { duke@435: int i = 0; duke@435: uintptr_t adr; duke@435: // We first start out with the real sethi instruction duke@435: assert(is_op2(*pc, Assembler::sethi_op2), "in gethi - must be sethi"); duke@435: adr = (unsigned int)Assembler::inv_hi22( *(pc++) ); duke@435: i++; duke@435: while ( i < 7 ) { duke@435: // We're done if we hit a nop duke@435: if ( (int)*pc == nop_instruction() ) break; duke@435: assert ( Assembler::inv_op(*pc) == Assembler::arith_op, "in gethi - must be arith_op" ); duke@435: switch ( Assembler::inv_op3(*pc) ) { duke@435: case Assembler::xor_op3: duke@435: adr ^= (intptr_t)get_simm13( *pc ); duke@435: return ( (address)adr ); duke@435: break; duke@435: case Assembler::sll_op3: duke@435: adr <<= ( *pc & 0x3f ); duke@435: break; duke@435: case Assembler::or_op3: duke@435: adr |= (intptr_t)get_simm13( *pc ); duke@435: break; duke@435: default: duke@435: assert ( 0, "in gethi - Should not reach here" ); duke@435: break; duke@435: } duke@435: pc++; duke@435: i++; duke@435: } duke@435: return ( (address)adr ); duke@435: } duke@435: duke@435: public: duke@435: void verify(); duke@435: void print(); duke@435: duke@435: // unit test stuff duke@435: static void test() {} // override for testing duke@435: duke@435: inline friend NativeInstruction* nativeInstruction_at(address address); duke@435: }; duke@435: duke@435: inline NativeInstruction* nativeInstruction_at(address address) { duke@435: NativeInstruction* inst = (NativeInstruction*)address; duke@435: #ifdef ASSERT duke@435: inst->verify(); duke@435: #endif duke@435: return inst; duke@435: } duke@435: duke@435: duke@435: duke@435: //----------------------------------------------------------------------------- duke@435: duke@435: // The NativeCall is an abstraction for accessing/manipulating native call imm32 instructions. duke@435: // (used to manipulate inline caches, primitive & dll calls, etc.) duke@435: inline NativeCall* nativeCall_at(address instr); duke@435: inline NativeCall* nativeCall_overwriting_at(address instr, duke@435: address destination); duke@435: inline NativeCall* nativeCall_before(address return_address); duke@435: class NativeCall: public NativeInstruction { duke@435: public: duke@435: enum Sparc_specific_constants { duke@435: instruction_size = 8, duke@435: return_address_offset = 8, duke@435: call_displacement_width = 30, duke@435: displacement_offset = 0, duke@435: instruction_offset = 0 duke@435: }; duke@435: address instruction_address() const { return addr_at(0); } duke@435: address next_instruction_address() const { return addr_at(instruction_size); } duke@435: address return_address() const { return addr_at(return_address_offset); } duke@435: duke@435: address destination() const { return inv_wdisp(long_at(0), call_displacement_width) + instruction_address(); } duke@435: address displacement_address() const { return addr_at(displacement_offset); } duke@435: void set_destination(address dest) { set_long_at(0, set_wdisp(long_at(0), dest - instruction_address(), call_displacement_width)); } duke@435: void set_destination_mt_safe(address dest); duke@435: duke@435: void verify_alignment() {} // do nothing on sparc duke@435: void verify(); duke@435: void print(); duke@435: duke@435: // unit test stuff duke@435: static void test(); duke@435: duke@435: // Creation duke@435: friend inline NativeCall* nativeCall_at(address instr); duke@435: friend NativeCall* nativeCall_overwriting_at(address instr, address destination = NULL) { duke@435: // insert a "blank" call: duke@435: NativeCall* call = (NativeCall*)instr; duke@435: call->set_long_at(0 * BytesPerInstWord, call_instruction(destination, instr)); duke@435: call->set_long_at(1 * BytesPerInstWord, nop_instruction()); duke@435: assert(call->addr_at(2 * BytesPerInstWord) - instr == instruction_size, "instruction size"); duke@435: // check its structure now: duke@435: assert(nativeCall_at(instr)->destination() == destination, "correct call destination"); duke@435: return call; duke@435: } duke@435: duke@435: friend inline NativeCall* nativeCall_before(address return_address) { duke@435: NativeCall* call = (NativeCall*)(return_address - return_address_offset); duke@435: #ifdef ASSERT duke@435: call->verify(); duke@435: #endif duke@435: return call; duke@435: } duke@435: duke@435: static bool is_call_at(address instr) { duke@435: return nativeInstruction_at(instr)->is_call(); duke@435: } duke@435: duke@435: static bool is_call_before(address instr) { duke@435: return nativeInstruction_at(instr - return_address_offset)->is_call(); duke@435: } duke@435: duke@435: static bool is_call_to(address instr, address target) { duke@435: return nativeInstruction_at(instr)->is_call() && duke@435: nativeCall_at(instr)->destination() == target; duke@435: } duke@435: duke@435: // MT-safe patching of a call instruction. duke@435: static void insert(address code_pos, address entry) { duke@435: (void)nativeCall_overwriting_at(code_pos, entry); duke@435: } duke@435: duke@435: static void replace_mt_safe(address instr_addr, address code_buffer); duke@435: }; duke@435: inline NativeCall* nativeCall_at(address instr) { duke@435: NativeCall* call = (NativeCall*)instr; duke@435: #ifdef ASSERT duke@435: call->verify(); duke@435: #endif duke@435: return call; duke@435: } duke@435: duke@435: // The NativeFarCall is an abstraction for accessing/manipulating native call-anywhere duke@435: // instructions in the sparcv9 vm. Used to call native methods which may be loaded duke@435: // anywhere in the address space, possibly out of reach of a call instruction. duke@435: duke@435: #ifndef _LP64 duke@435: duke@435: // On 32-bit systems, a far call is the same as a near one. duke@435: class NativeFarCall; duke@435: inline NativeFarCall* nativeFarCall_at(address instr); duke@435: class NativeFarCall : public NativeCall { duke@435: public: duke@435: friend inline NativeFarCall* nativeFarCall_at(address instr) { return (NativeFarCall*)nativeCall_at(instr); } duke@435: friend NativeFarCall* nativeFarCall_overwriting_at(address instr, address destination = NULL) duke@435: { return (NativeFarCall*)nativeCall_overwriting_at(instr, destination); } duke@435: friend NativeFarCall* nativeFarCall_before(address return_address) duke@435: { return (NativeFarCall*)nativeCall_before(return_address); } duke@435: }; duke@435: duke@435: #else duke@435: duke@435: // The format of this extended-range call is: duke@435: // jumpl_to addr, lreg duke@435: // == sethi %hi54(addr), O7 ; jumpl O7, %lo10(addr), O7 ; duke@435: // That is, it is essentially the same as a NativeJump. duke@435: class NativeFarCall; duke@435: inline NativeFarCall* nativeFarCall_overwriting_at(address instr, address destination); duke@435: inline NativeFarCall* nativeFarCall_at(address instr); duke@435: class NativeFarCall: public NativeInstruction { duke@435: public: duke@435: enum Sparc_specific_constants { duke@435: // instruction_size includes the delay slot instruction. duke@435: instruction_size = 9 * BytesPerInstWord, duke@435: return_address_offset = 9 * BytesPerInstWord, duke@435: jmpl_offset = 7 * BytesPerInstWord, duke@435: displacement_offset = 0, duke@435: instruction_offset = 0 duke@435: }; duke@435: address instruction_address() const { return addr_at(0); } duke@435: address next_instruction_address() const { return addr_at(instruction_size); } duke@435: address return_address() const { return addr_at(return_address_offset); } duke@435: duke@435: address destination() const { duke@435: return (address) data64(addr_at(0), long_at(jmpl_offset)); duke@435: } duke@435: address displacement_address() const { return addr_at(displacement_offset); } duke@435: void set_destination(address dest); duke@435: duke@435: bool destination_is_compiled_verified_entry_point(); duke@435: duke@435: void verify(); duke@435: void print(); duke@435: duke@435: // unit test stuff duke@435: static void test(); duke@435: duke@435: // Creation duke@435: friend inline NativeFarCall* nativeFarCall_at(address instr) { duke@435: NativeFarCall* call = (NativeFarCall*)instr; duke@435: #ifdef ASSERT duke@435: call->verify(); duke@435: #endif duke@435: return call; duke@435: } duke@435: duke@435: friend inline NativeFarCall* nativeFarCall_overwriting_at(address instr, address destination = NULL) { duke@435: Unimplemented(); duke@435: NativeFarCall* call = (NativeFarCall*)instr; duke@435: return call; duke@435: } duke@435: duke@435: friend NativeFarCall* nativeFarCall_before(address return_address) { duke@435: NativeFarCall* call = (NativeFarCall*)(return_address - return_address_offset); duke@435: #ifdef ASSERT duke@435: call->verify(); duke@435: #endif duke@435: return call; duke@435: } duke@435: duke@435: static bool is_call_at(address instr); duke@435: duke@435: // MT-safe patching of a call instruction. duke@435: static void insert(address code_pos, address entry) { duke@435: (void)nativeFarCall_overwriting_at(code_pos, entry); duke@435: } duke@435: static void replace_mt_safe(address instr_addr, address code_buffer); duke@435: }; duke@435: duke@435: #endif // _LP64 duke@435: duke@435: // An interface for accessing/manipulating native set_oop imm, reg instructions. duke@435: // (used to manipulate inlined data references, etc.) duke@435: // set_oop imm, reg duke@435: // == sethi %hi22(imm), reg ; add reg, %lo10(imm), reg duke@435: class NativeMovConstReg; duke@435: inline NativeMovConstReg* nativeMovConstReg_at(address address); duke@435: class NativeMovConstReg: public NativeInstruction { duke@435: public: duke@435: enum Sparc_specific_constants { duke@435: sethi_offset = 0, duke@435: #ifdef _LP64 duke@435: add_offset = 7 * BytesPerInstWord, duke@435: instruction_size = 8 * BytesPerInstWord duke@435: #else duke@435: add_offset = 4, duke@435: instruction_size = 8 duke@435: #endif duke@435: }; duke@435: duke@435: address instruction_address() const { return addr_at(0); } duke@435: address next_instruction_address() const { return addr_at(instruction_size); } duke@435: duke@435: // (The [set_]data accessor respects oop_type relocs also.) duke@435: intptr_t data() const; duke@435: void set_data(intptr_t x); duke@435: duke@435: // report the destination register duke@435: Register destination() { return inv_rd(long_at(sethi_offset)); } duke@435: duke@435: void verify(); duke@435: void print(); duke@435: duke@435: // unit test stuff duke@435: static void test(); duke@435: duke@435: // Creation duke@435: friend inline NativeMovConstReg* nativeMovConstReg_at(address address) { duke@435: NativeMovConstReg* test = (NativeMovConstReg*)address; duke@435: #ifdef ASSERT duke@435: test->verify(); duke@435: #endif duke@435: return test; duke@435: } duke@435: duke@435: duke@435: friend NativeMovConstReg* nativeMovConstReg_before(address address) { duke@435: NativeMovConstReg* test = (NativeMovConstReg*)(address - instruction_size); duke@435: #ifdef ASSERT duke@435: test->verify(); duke@435: #endif duke@435: return test; duke@435: } duke@435: duke@435: }; duke@435: duke@435: duke@435: // An interface for accessing/manipulating native set_oop imm, reg instructions. duke@435: // (used to manipulate inlined data references, etc.) duke@435: // set_oop imm, reg duke@435: // == sethi %hi22(imm), reg; nop; add reg, %lo10(imm), reg duke@435: // duke@435: // Note that it is identical to NativeMovConstReg with the exception of a nop between the duke@435: // sethi and the add. The nop is required to be in the delay slot of the call instruction duke@435: // which overwrites the sethi during patching. duke@435: class NativeMovConstRegPatching; duke@435: inline NativeMovConstRegPatching* nativeMovConstRegPatching_at(address address);class NativeMovConstRegPatching: public NativeInstruction { duke@435: public: duke@435: enum Sparc_specific_constants { duke@435: sethi_offset = 0, duke@435: #ifdef _LP64 duke@435: nop_offset = 7 * BytesPerInstWord, duke@435: #else duke@435: nop_offset = sethi_offset + BytesPerInstWord, duke@435: #endif duke@435: add_offset = nop_offset + BytesPerInstWord, duke@435: instruction_size = add_offset + BytesPerInstWord duke@435: }; duke@435: duke@435: address instruction_address() const { return addr_at(0); } duke@435: address next_instruction_address() const { return addr_at(instruction_size); } duke@435: duke@435: // (The [set_]data accessor respects oop_type relocs also.) duke@435: int data() const; duke@435: void set_data(int x); duke@435: duke@435: // report the destination register duke@435: Register destination() { return inv_rd(long_at(sethi_offset)); } duke@435: duke@435: void verify(); duke@435: void print(); duke@435: duke@435: // unit test stuff duke@435: static void test(); duke@435: duke@435: // Creation duke@435: friend inline NativeMovConstRegPatching* nativeMovConstRegPatching_at(address address) { duke@435: NativeMovConstRegPatching* test = (NativeMovConstRegPatching*)address; duke@435: #ifdef ASSERT duke@435: test->verify(); duke@435: #endif duke@435: return test; duke@435: } duke@435: duke@435: duke@435: friend NativeMovConstRegPatching* nativeMovConstRegPatching_before(address address) { duke@435: NativeMovConstRegPatching* test = (NativeMovConstRegPatching*)(address - instruction_size); duke@435: #ifdef ASSERT duke@435: test->verify(); duke@435: #endif duke@435: return test; duke@435: } duke@435: duke@435: }; duke@435: duke@435: duke@435: // An interface for accessing/manipulating native memory ops duke@435: // ld* [reg + offset], reg duke@435: // st* reg, [reg + offset] duke@435: // sethi %hi(imm), reg; add reg, %lo(imm), reg; ld* [reg1 + reg], reg2 duke@435: // sethi %hi(imm), reg; add reg, %lo(imm), reg; st* reg2, [reg1 + reg] duke@435: // Ops covered: {lds,ldu,st}{w,b,h}, {ld,st}{d,x} duke@435: // duke@435: class NativeMovRegMem; duke@435: inline NativeMovRegMem* nativeMovRegMem_at (address address); duke@435: class NativeMovRegMem: public NativeInstruction { duke@435: public: duke@435: enum Sparc_specific_constants { duke@435: op3_mask_ld = 1 << Assembler::lduw_op3 | duke@435: 1 << Assembler::ldub_op3 | duke@435: 1 << Assembler::lduh_op3 | duke@435: 1 << Assembler::ldd_op3 | duke@435: 1 << Assembler::ldsw_op3 | duke@435: 1 << Assembler::ldsb_op3 | duke@435: 1 << Assembler::ldsh_op3 | duke@435: 1 << Assembler::ldx_op3, duke@435: op3_mask_st = 1 << Assembler::stw_op3 | duke@435: 1 << Assembler::stb_op3 | duke@435: 1 << Assembler::sth_op3 | duke@435: 1 << Assembler::std_op3 | duke@435: 1 << Assembler::stx_op3, duke@435: op3_ldst_int_limit = Assembler::ldf_op3, duke@435: op3_mask_ldf = 1 << (Assembler::ldf_op3 - op3_ldst_int_limit) | duke@435: 1 << (Assembler::lddf_op3 - op3_ldst_int_limit), duke@435: op3_mask_stf = 1 << (Assembler::stf_op3 - op3_ldst_int_limit) | duke@435: 1 << (Assembler::stdf_op3 - op3_ldst_int_limit), duke@435: duke@435: offset_width = 13, duke@435: sethi_offset = 0, duke@435: #ifdef _LP64 duke@435: add_offset = 7 * BytesPerInstWord, duke@435: #else duke@435: add_offset = 4, duke@435: #endif duke@435: ldst_offset = add_offset + BytesPerInstWord duke@435: }; duke@435: bool is_immediate() const { duke@435: // check if instruction is ld* [reg + offset], reg or st* reg, [reg + offset] duke@435: int i0 = long_at(0); duke@435: return (is_op(i0, Assembler::ldst_op)); duke@435: } duke@435: duke@435: address instruction_address() const { return addr_at(0); } duke@435: address next_instruction_address() const { duke@435: #ifdef _LP64 duke@435: return addr_at(is_immediate() ? 4 : (7 * BytesPerInstWord)); duke@435: #else duke@435: return addr_at(is_immediate() ? 4 : 12); duke@435: #endif duke@435: } duke@435: intptr_t offset() const { duke@435: return is_immediate()? inv_simm(long_at(0), offset_width) : duke@435: nativeMovConstReg_at(addr_at(0))->data(); duke@435: } duke@435: void set_offset(intptr_t x) { duke@435: if (is_immediate()) { duke@435: guarantee(fits_in_simm(x, offset_width), "data block offset overflow"); duke@435: set_long_at(0, set_simm(long_at(0), x, offset_width)); duke@435: } else duke@435: nativeMovConstReg_at(addr_at(0))->set_data(x); duke@435: } duke@435: duke@435: void add_offset_in_bytes(intptr_t radd_offset) { duke@435: set_offset (offset() + radd_offset); duke@435: } duke@435: duke@435: void copy_instruction_to(address new_instruction_address); duke@435: duke@435: void verify(); duke@435: void print (); duke@435: duke@435: // unit test stuff duke@435: static void test(); duke@435: duke@435: private: duke@435: friend inline NativeMovRegMem* nativeMovRegMem_at (address address) { duke@435: NativeMovRegMem* test = (NativeMovRegMem*)address; duke@435: #ifdef ASSERT duke@435: test->verify(); duke@435: #endif duke@435: return test; duke@435: } duke@435: }; duke@435: duke@435: duke@435: // An interface for accessing/manipulating native memory ops duke@435: // ld* [reg + offset], reg duke@435: // st* reg, [reg + offset] duke@435: // sethi %hi(imm), reg; nop; add reg, %lo(imm), reg; ld* [reg1 + reg], reg2 duke@435: // sethi %hi(imm), reg; nop; add reg, %lo(imm), reg; st* reg2, [reg1 + reg] duke@435: // Ops covered: {lds,ldu,st}{w,b,h}, {ld,st}{d,x} duke@435: // duke@435: // Note that it is identical to NativeMovRegMem with the exception of a nop between the duke@435: // sethi and the add. The nop is required to be in the delay slot of the call instruction duke@435: // which overwrites the sethi during patching. duke@435: class NativeMovRegMemPatching; duke@435: inline NativeMovRegMemPatching* nativeMovRegMemPatching_at (address address); duke@435: class NativeMovRegMemPatching: public NativeInstruction { duke@435: public: duke@435: enum Sparc_specific_constants { duke@435: op3_mask_ld = 1 << Assembler::lduw_op3 | duke@435: 1 << Assembler::ldub_op3 | duke@435: 1 << Assembler::lduh_op3 | duke@435: 1 << Assembler::ldd_op3 | duke@435: 1 << Assembler::ldsw_op3 | duke@435: 1 << Assembler::ldsb_op3 | duke@435: 1 << Assembler::ldsh_op3 | duke@435: 1 << Assembler::ldx_op3, duke@435: op3_mask_st = 1 << Assembler::stw_op3 | duke@435: 1 << Assembler::stb_op3 | duke@435: 1 << Assembler::sth_op3 | duke@435: 1 << Assembler::std_op3 | duke@435: 1 << Assembler::stx_op3, duke@435: op3_ldst_int_limit = Assembler::ldf_op3, duke@435: op3_mask_ldf = 1 << (Assembler::ldf_op3 - op3_ldst_int_limit) | duke@435: 1 << (Assembler::lddf_op3 - op3_ldst_int_limit), duke@435: op3_mask_stf = 1 << (Assembler::stf_op3 - op3_ldst_int_limit) | duke@435: 1 << (Assembler::stdf_op3 - op3_ldst_int_limit), duke@435: duke@435: offset_width = 13, duke@435: sethi_offset = 0, duke@435: #ifdef _LP64 duke@435: nop_offset = 7 * BytesPerInstWord, duke@435: #else duke@435: nop_offset = 4, duke@435: #endif duke@435: add_offset = nop_offset + BytesPerInstWord, duke@435: ldst_offset = add_offset + BytesPerInstWord duke@435: }; duke@435: bool is_immediate() const { duke@435: // check if instruction is ld* [reg + offset], reg or st* reg, [reg + offset] duke@435: int i0 = long_at(0); duke@435: return (is_op(i0, Assembler::ldst_op)); duke@435: } duke@435: duke@435: address instruction_address() const { return addr_at(0); } duke@435: address next_instruction_address() const { duke@435: return addr_at(is_immediate()? 4 : 16); duke@435: } duke@435: int offset() const { duke@435: return is_immediate()? inv_simm(long_at(0), offset_width) : duke@435: nativeMovConstRegPatching_at(addr_at(0))->data(); duke@435: } duke@435: void set_offset(int x) { duke@435: if (is_immediate()) { duke@435: guarantee(fits_in_simm(x, offset_width), "data block offset overflow"); duke@435: set_long_at(0, set_simm(long_at(0), x, offset_width)); duke@435: } duke@435: else duke@435: nativeMovConstRegPatching_at(addr_at(0))->set_data(x); duke@435: } duke@435: duke@435: void add_offset_in_bytes(intptr_t radd_offset) { duke@435: set_offset (offset() + radd_offset); duke@435: } duke@435: duke@435: void copy_instruction_to(address new_instruction_address); duke@435: duke@435: void verify(); duke@435: void print (); duke@435: duke@435: // unit test stuff duke@435: static void test(); duke@435: duke@435: private: duke@435: friend inline NativeMovRegMemPatching* nativeMovRegMemPatching_at (address address) { duke@435: NativeMovRegMemPatching* test = (NativeMovRegMemPatching*)address; duke@435: #ifdef ASSERT duke@435: test->verify(); duke@435: #endif duke@435: return test; duke@435: } duke@435: }; duke@435: duke@435: duke@435: // An interface for accessing/manipulating native jumps duke@435: // jump_to addr duke@435: // == sethi %hi22(addr), temp ; jumpl reg, %lo10(addr), G0 ; duke@435: // jumpl_to addr, lreg duke@435: // == sethi %hi22(addr), temp ; jumpl reg, %lo10(addr), lreg ; duke@435: class NativeJump; duke@435: inline NativeJump* nativeJump_at(address address); duke@435: class NativeJump: public NativeInstruction { duke@435: private: duke@435: void guarantee_displacement(int disp, int width) { duke@435: guarantee(fits_in_simm(disp, width + 2), "branch displacement overflow"); duke@435: } duke@435: duke@435: public: duke@435: enum Sparc_specific_constants { duke@435: sethi_offset = 0, duke@435: #ifdef _LP64 duke@435: jmpl_offset = 7 * BytesPerInstWord, duke@435: instruction_size = 9 * BytesPerInstWord // includes delay slot duke@435: #else duke@435: jmpl_offset = 1 * BytesPerInstWord, duke@435: instruction_size = 3 * BytesPerInstWord // includes delay slot duke@435: #endif duke@435: }; duke@435: duke@435: address instruction_address() const { return addr_at(0); } duke@435: address next_instruction_address() const { return addr_at(instruction_size); } duke@435: duke@435: #ifdef _LP64 duke@435: address jump_destination() const { duke@435: return (address) data64(instruction_address(), long_at(jmpl_offset)); duke@435: } duke@435: void set_jump_destination(address dest) { duke@435: set_data64_sethi( instruction_address(), (intptr_t)dest); duke@435: set_long_at(jmpl_offset, set_data32_simm13( long_at(jmpl_offset), (intptr_t)dest)); duke@435: } duke@435: #else duke@435: address jump_destination() const { duke@435: return (address) data32(long_at(sethi_offset), long_at(jmpl_offset)); duke@435: } duke@435: void set_jump_destination(address dest) { duke@435: set_long_at(sethi_offset, set_data32_sethi( long_at(sethi_offset), (intptr_t)dest)); duke@435: set_long_at(jmpl_offset, set_data32_simm13( long_at(jmpl_offset), (intptr_t)dest)); duke@435: } duke@435: #endif duke@435: duke@435: // Creation duke@435: friend inline NativeJump* nativeJump_at(address address) { duke@435: NativeJump* jump = (NativeJump*)address; duke@435: #ifdef ASSERT duke@435: jump->verify(); duke@435: #endif duke@435: return jump; duke@435: } duke@435: duke@435: void verify(); duke@435: void print(); duke@435: duke@435: // Unit testing stuff duke@435: static void test(); duke@435: duke@435: // Insertion of native jump instruction duke@435: static void insert(address code_pos, address entry); duke@435: // MT-safe insertion of native jump at verified method entry duke@435: static void check_verified_entry_alignment(address entry, address verified_entry) { duke@435: // nothing to do for sparc. duke@435: } duke@435: static void patch_verified_entry(address entry, address verified_entry, address dest); duke@435: }; duke@435: duke@435: duke@435: duke@435: // Despite the name, handles only simple branches. duke@435: class NativeGeneralJump; duke@435: inline NativeGeneralJump* nativeGeneralJump_at(address address); duke@435: class NativeGeneralJump: public NativeInstruction { duke@435: public: duke@435: enum Sparc_specific_constants { duke@435: instruction_size = 8 duke@435: }; duke@435: duke@435: address instruction_address() const { return addr_at(0); } duke@435: address jump_destination() const { return addr_at(0) + branch_destination_offset(long_at(0)); } duke@435: void set_jump_destination(address dest) { duke@435: int patched_instr = patch_branch_destination_offset(dest - addr_at(0), long_at(0)); duke@435: set_long_at(0, patched_instr); duke@435: } duke@435: void set_annul() { set_annul_bit(); } duke@435: NativeInstruction *delay_slot_instr() { return nativeInstruction_at(addr_at(4));} duke@435: void fill_delay_slot(int instr) { set_long_at(4, instr);} duke@435: Assembler::Condition condition() { duke@435: int x = long_at(0); duke@435: return (Assembler::Condition) Assembler::inv_cond(x); duke@435: } duke@435: duke@435: // Creation duke@435: friend inline NativeGeneralJump* nativeGeneralJump_at(address address) { duke@435: NativeGeneralJump* jump = (NativeGeneralJump*)(address); duke@435: #ifdef ASSERT duke@435: jump->verify(); duke@435: #endif duke@435: return jump; duke@435: } duke@435: duke@435: // Insertion of native general jump instruction duke@435: static void insert_unconditional(address code_pos, address entry); duke@435: static void replace_mt_safe(address instr_addr, address code_buffer); duke@435: duke@435: void verify(); duke@435: }; duke@435: duke@435: duke@435: class NativeIllegalInstruction: public NativeInstruction { duke@435: public: duke@435: enum Sparc_specific_constants { duke@435: instruction_size = 4 duke@435: }; duke@435: duke@435: // Insert illegal opcode as specific address duke@435: static void insert(address code_pos); duke@435: };