hotspot/src/cpu/sparc/vm/nativeInst_sparc.hpp
author trims
Tue, 05 Apr 2011 14:12:31 -0700
changeset 8921 14bfe81f2a9d
parent 8724 693c6b883b54
child 13728 882756847a04
permissions -rw-r--r--
7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass Summary: Update the copyright to be 2010 on all changed files in OpenJDK Reviewed-by: ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
8921
14bfe81f2a9d 7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents: 8724
diff changeset
     2
 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2131
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2131
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 2131
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#ifndef CPU_SPARC_VM_NATIVEINST_SPARC_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define CPU_SPARC_VM_NATIVEINST_SPARC_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "asm/assembler.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "runtime/icache.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "runtime/os.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
#include "utilities/top.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// We have interface for the following instructions:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// - NativeInstruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// - - NativeCall
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// - - NativeFarCall
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// - - NativeMovConstReg
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// - - NativeMovConstRegPatching
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// - - NativeMovRegMem
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// - - NativeMovRegMemPatching
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// - - NativeJump
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
// - - NativeGeneralJump
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// - - NativeIllegalInstruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// The base class for different kinds of native instruction abstractions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// Provides the primitive operations to manipulate code relative to this.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
class NativeInstruction VALUE_OBJ_CLASS_SPEC {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  friend class Relocation;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  enum Sparc_specific_constants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    nop_instruction_size        =    4
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
363
99d43e8a76ad 6537506: Provide a mechanism for specifying Java-level USDT-like dtrace probes
kamg
parents: 1
diff changeset
    55
  bool is_dtrace_trap();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  bool is_nop()                        { return long_at(0) == nop_instruction(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  bool is_call()                       { return is_op(long_at(0), Assembler::call_op); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  bool is_sethi()                      { return (is_op2(long_at(0), Assembler::sethi_op2)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
                                          && inv_rd(long_at(0)) != G0); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  bool sets_cc() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    // conservative (returns true for some instructions that do not set the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    // the condition code, such as, "save".
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    // Does not return true for the deprecated tagged instructions, such as, TADDcc
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    int x = long_at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    return (is_op(x, Assembler::arith_op) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
            (inv_op3(x) & Assembler::cc_bit_op3) == Assembler::cc_bit_op3);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  bool is_illegal();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  bool is_zombie() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    int x = long_at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    return is_op3(x,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
                  VM_Version::v9_instructions_work() ?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
                    Assembler::ldsw_op3 : Assembler::lduw_op3,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
                  Assembler::ldst_op)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
        && Assembler::inv_rs1(x) == G0
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
        && Assembler::inv_rd(x) == O7;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  bool is_ic_miss_trap();       // Inline-cache uses a trap to detect a miss
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  bool is_return() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    // is it the output of MacroAssembler::ret or MacroAssembler::retl?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    int x = long_at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    const int pc_return_offset = 8; // see frame_sparc.hpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    return is_op3(x, Assembler::jmpl_op3, Assembler::arith_op)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
        && (inv_rs1(x) == I7 || inv_rs1(x) == O7)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
        && inv_immed(x) && inv_simm(x, 13) == pc_return_offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
        && inv_rd(x) == G0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  bool is_int_jump() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    // is it the output of MacroAssembler::b?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    int x = long_at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    return is_op2(x, Assembler::bp_op2) || is_op2(x, Assembler::br_op2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  bool is_float_jump() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    // is it the output of MacroAssembler::fb?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    int x = long_at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    return is_op2(x, Assembler::fbp_op2) || is_op2(x, Assembler::fb_op2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  bool is_jump() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    return is_int_jump() || is_float_jump();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  bool is_cond_jump() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    int x = long_at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    return (is_int_jump() && Assembler::inv_cond(x) != Assembler::always) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
           (is_float_jump() && Assembler::inv_cond(x) != Assembler::f_always);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  bool is_stack_bang() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    int x = long_at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    return is_op3(x, Assembler::stw_op3, Assembler::ldst_op) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
      (inv_rd(x) == G0) && (inv_rs1(x) == SP) && (inv_rs2(x) == G3_scratch);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  bool is_prefetch() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    int x = long_at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    return is_op3(x, Assembler::prefetch_op3, Assembler::ldst_op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  bool is_membar() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    int x = long_at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    return is_op3(x, Assembler::membar_op3, Assembler::arith_op) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
      (inv_rd(x) == G0) && (inv_rs1(x) == O7);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  bool is_safepoint_poll() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    int x = long_at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    return is_op3(x, Assembler::ldx_op3,  Assembler::ldst_op) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    return is_op3(x, Assembler::lduw_op3, Assembler::ldst_op) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      (inv_rd(x) == G0) && (inv_immed(x) ? Assembler::inv_simm13(x) == 0 : inv_rs2(x) == G0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  bool is_zero_test(Register &reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  bool is_load_store_with_small_offset(Register reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  static int rdpc_instruction()        { return Assembler::op(Assembler::arith_op ) | Assembler::op3(Assembler::rdreg_op3) | Assembler::u_field(5, 18, 14) | Assembler::rd(O7); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  // Temporary fix: in optimized mode, u_field is a macro for efficiency reasons (see Assembler::u_field) - needs to be fixed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  static int rdpc_instruction()        { return Assembler::op(Assembler::arith_op ) | Assembler::op3(Assembler::rdreg_op3) |            u_field(5, 18, 14) | Assembler::rd(O7); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  static int nop_instruction()         { return Assembler::op(Assembler::branch_op) | Assembler::op2(Assembler::sethi_op2); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  static int illegal_instruction();    // the output of __ breakpoint_trap()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  static int call_instruction(address destination, address pc) { return Assembler::op(Assembler::call_op) | Assembler::wdisp((intptr_t)destination, (intptr_t)pc, 30); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  static int branch_instruction(Assembler::op2s op2val, Assembler::Condition c, bool a) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    return Assembler::op(Assembler::branch_op) | Assembler::op2(op2val) | Assembler::annul(a) | Assembler::cond(c);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  static int op3_instruction(Assembler::ops opval, Register rd, Assembler::op3s op3val, Register rs1, int simm13a) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    return Assembler::op(opval) | Assembler::rd(rd) | Assembler::op3(op3val) | Assembler::rs1(rs1) | Assembler::immed(true) | Assembler::simm(simm13a, 13);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  static int sethi_instruction(Register rd, int imm22a) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    return Assembler::op(Assembler::branch_op) | Assembler::rd(rd) | Assembler::op2(Assembler::sethi_op2) | Assembler::hi22(imm22a);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  address  addr_at(int offset) const    { return address(this) + offset; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  int      long_at(int offset) const    { return *(int*)addr_at(offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  void set_long_at(int offset, int i);      /* deals with I-cache */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  void set_jlong_at(int offset, jlong i);   /* deals with I-cache */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  void set_addr_at(int offset, address x);  /* deals with I-cache */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  address instruction_address() const       { return addr_at(0); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  address next_instruction_address() const  { return addr_at(BytesPerInstWord); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  static bool is_op( int x, Assembler::ops opval)  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    return Assembler::inv_op(x) == opval;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  static bool is_op2(int x, Assembler::op2s op2val) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    return Assembler::inv_op(x) == Assembler::branch_op && Assembler::inv_op2(x) == op2val;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  static bool is_op3(int x, Assembler::op3s op3val, Assembler::ops opval) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    return Assembler::inv_op(x) == opval && Assembler::inv_op3(x) == op3val;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  // utilities to help subclasses decode:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  static Register inv_rd(  int x ) { return Assembler::inv_rd( x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  static Register inv_rs1( int x ) { return Assembler::inv_rs1(x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  static Register inv_rs2( int x ) { return Assembler::inv_rs2(x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  static bool inv_immed( int x ) { return Assembler::inv_immed(x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  static bool inv_annul( int x ) { return (Assembler::annul(true) & x) != 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  static int  inv_cond(  int x ) { return Assembler::inv_cond(x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  static int inv_op(  int x ) { return Assembler::inv_op( x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  static int inv_op2( int x ) { return Assembler::inv_op2(x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  static int inv_op3( int x ) { return Assembler::inv_op3(x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  static int inv_simm(    int x, int nbits ) { return Assembler::inv_simm(x, nbits); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  static intptr_t inv_wdisp(   int x, int nbits ) { return Assembler::inv_wdisp(  x, 0, nbits); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  static intptr_t inv_wdisp16( int x )            { return Assembler::inv_wdisp16(x, 0); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  static int branch_destination_offset(int x) { return Assembler::branch_destination(x, 0); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  static int patch_branch_destination_offset(int dest_offset, int x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    return Assembler::patched_branch(dest_offset, x, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  void set_annul_bit() { set_long_at(0, long_at(0) | Assembler::annul(true)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  // utility for checking if x is either of 2 small constants
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  static bool is_either(int x, int k1, int k2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    // return x == k1 || x == k2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    return (1 << x) & (1 << k1 | 1 << k2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  // utility for checking overflow of signed instruction fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  static bool fits_in_simm(int x, int nbits) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    // cf. Assembler::assert_signed_range()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    // return -(1 << nbits-1) <= x  &&  x < ( 1 << nbits-1),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    return (unsigned)(x + (1 << nbits-1)) < (unsigned)(1 << nbits);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  // set a signed immediate field
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  static int set_simm(int insn, int imm, int nbits) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    return (insn &~ Assembler::simm(-1, nbits)) | Assembler::simm(imm, nbits);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  // set a wdisp field (disp should be the difference of two addresses)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  static int set_wdisp(int insn, intptr_t disp, int nbits) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    return (insn &~ Assembler::wdisp((intptr_t)-4, (intptr_t)0, nbits)) | Assembler::wdisp(disp, 0, nbits);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  static int set_wdisp16(int insn, intptr_t disp) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    return (insn &~ Assembler::wdisp16((intptr_t)-4, 0)) | Assembler::wdisp16(disp, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  // get a simm13 field from an arithmetic or memory instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  static int get_simm13(int insn) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    assert(is_either(Assembler::inv_op(insn),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
                     Assembler::arith_op, Assembler::ldst_op) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
            (insn & Assembler::immed(true)), "must have a simm13 field");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    return Assembler::inv_simm(insn, 13);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  // set the simm13 field of an arithmetic or memory instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  static bool set_simm13(int insn, int imm) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    get_simm13(insn);           // tickle the assertion check
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    return set_simm(insn, imm, 13);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  // combine the fields of a sethi stream (7 instructions ) and an add, jmp or ld/st
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  static intptr_t data64( address pc, int arith_insn ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    assert(is_op2(*(unsigned int *)pc, Assembler::sethi_op2), "must be sethi");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    intptr_t hi = (intptr_t)gethi( (unsigned int *)pc );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
    intptr_t lo = (intptr_t)get_simm13(arith_insn);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
    assert((unsigned)lo < (1 << 10), "offset field of set_oop must be 10 bits");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    return hi | lo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  // Regenerate the instruction sequence that performs the 64 bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  // sethi.  This only does the sethi.  The disp field (bottom 10 bits)
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 670
diff changeset
   255
  // must be handled separately.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  static void set_data64_sethi(address instaddr, intptr_t x);
8724
693c6b883b54 7028374: race in fix_oop_relocations for scavengeable nmethods
never
parents: 7397
diff changeset
   257
  static void verify_data64_sethi(address instaddr, intptr_t x);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  // combine the fields of a sethi/simm13 pair (simm13 = or, add, jmpl, ld/st)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  static int data32(int sethi_insn, int arith_insn) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    assert(is_op2(sethi_insn, Assembler::sethi_op2), "must be sethi");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    int hi = Assembler::inv_hi22(sethi_insn);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    int lo = get_simm13(arith_insn);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    assert((unsigned)lo < (1 << 10), "offset field of set_oop must be 10 bits");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    return hi | lo;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  static int set_data32_sethi(int sethi_insn, int imm) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    // note that Assembler::hi22 clips the low 10 bits for us
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    assert(is_op2(sethi_insn, Assembler::sethi_op2), "must be sethi");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    return (sethi_insn &~ Assembler::hi22(-1)) | Assembler::hi22(imm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  static int set_data32_simm13(int arith_insn, int imm) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    get_simm13(arith_insn);             // tickle the assertion check
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    int imm10 = Assembler::low10(imm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    return (arith_insn &~ Assembler::simm(-1, 13)) | Assembler::simm(imm10, 13);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  static int low10(int imm) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    return Assembler::low10(imm);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  // Perform the inverse of the LP64 Macroassembler::sethi
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  // routine.  Extracts the 54 bits of address from the instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  // stream. This routine must agree with the sethi routine in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  // assembler_inline_sparc.hpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  static address gethi( unsigned int *pc ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    int i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    uintptr_t adr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
    // We first start out with the real sethi instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    assert(is_op2(*pc, Assembler::sethi_op2), "in gethi - must be sethi");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    adr = (unsigned int)Assembler::inv_hi22( *(pc++) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
    i++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    while ( i < 7 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
       // We're done if we hit a nop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
       if ( (int)*pc == nop_instruction() ) break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
       assert ( Assembler::inv_op(*pc) == Assembler::arith_op, "in gethi - must be arith_op" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
       switch  ( Assembler::inv_op3(*pc) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
         case Assembler::xor_op3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
           adr ^= (intptr_t)get_simm13( *pc );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
           return ( (address)adr );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
         case Assembler::sll_op3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
           adr <<= ( *pc & 0x3f );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
         case Assembler::or_op3:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
           adr |= (intptr_t)get_simm13( *pc );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
         default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
           assert ( 0, "in gethi - Should not reach here" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
       }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
       pc++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
       i++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
    return ( (address)adr );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  void  verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  void  print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  // unit test stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  static void test() {}                 // override for testing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  inline friend NativeInstruction* nativeInstruction_at(address address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
inline NativeInstruction* nativeInstruction_at(address address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
    NativeInstruction* inst = (NativeInstruction*)address;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
      inst->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    return inst;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
//-----------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
// The NativeCall is an abstraction for accessing/manipulating native call imm32 instructions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
// (used to manipulate inline caches, primitive & dll calls, etc.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
inline NativeCall* nativeCall_at(address instr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
inline NativeCall* nativeCall_overwriting_at(address instr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
                                             address destination);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
inline NativeCall* nativeCall_before(address return_address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
class NativeCall: public NativeInstruction {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  enum Sparc_specific_constants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
    instruction_size                   = 8,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
    return_address_offset              = 8,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
    call_displacement_width            = 30,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
    displacement_offset                = 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
    instruction_offset                 = 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  address instruction_address() const       { return addr_at(0); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  address next_instruction_address() const  { return addr_at(instruction_size); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  address return_address() const            { return addr_at(return_address_offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  address destination() const               { return inv_wdisp(long_at(0), call_displacement_width) + instruction_address(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  address displacement_address() const      { return addr_at(displacement_offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  void  set_destination(address dest)       { set_long_at(0, set_wdisp(long_at(0), dest - instruction_address(), call_displacement_width)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  void  set_destination_mt_safe(address dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  void  verify_alignment() {} // do nothing on sparc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  void  verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
  void  print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  // unit test stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  static void  test();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  friend inline NativeCall* nativeCall_at(address instr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  friend NativeCall* nativeCall_overwriting_at(address instr, address destination = NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
    // insert a "blank" call:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    NativeCall* call = (NativeCall*)instr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
    call->set_long_at(0 * BytesPerInstWord, call_instruction(destination, instr));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    call->set_long_at(1 * BytesPerInstWord, nop_instruction());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
    assert(call->addr_at(2 * BytesPerInstWord) - instr == instruction_size, "instruction size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
    // check its structure now:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    assert(nativeCall_at(instr)->destination() == destination, "correct call destination");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
    return call;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  friend inline NativeCall* nativeCall_before(address return_address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
    NativeCall* call = (NativeCall*)(return_address - return_address_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
    #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
      call->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
    #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
    return call;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  static bool is_call_at(address instr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
    return nativeInstruction_at(instr)->is_call();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  static bool is_call_before(address instr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
    return nativeInstruction_at(instr - return_address_offset)->is_call();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  static bool is_call_to(address instr, address target) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
    return nativeInstruction_at(instr)->is_call() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
      nativeCall_at(instr)->destination() == target;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  // MT-safe patching of a call instruction.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  static void insert(address code_pos, address entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
    (void)nativeCall_overwriting_at(code_pos, entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  static void replace_mt_safe(address instr_addr, address code_buffer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
inline NativeCall* nativeCall_at(address instr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  NativeCall* call = (NativeCall*)instr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  call->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  return call;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
// The NativeFarCall is an abstraction for accessing/manipulating native call-anywhere
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
// instructions in the sparcv9 vm.  Used to call native methods which may be loaded
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
// anywhere in the address space, possibly out of reach of a call instruction.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
#ifndef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
// On 32-bit systems, a far call is the same as a near one.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
class NativeFarCall;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
inline NativeFarCall* nativeFarCall_at(address instr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
class NativeFarCall : public NativeCall {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  friend inline NativeFarCall* nativeFarCall_at(address instr) { return (NativeFarCall*)nativeCall_at(instr); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  friend NativeFarCall* nativeFarCall_overwriting_at(address instr, address destination = NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
                                                        { return (NativeFarCall*)nativeCall_overwriting_at(instr, destination); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
  friend NativeFarCall* nativeFarCall_before(address return_address)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
                                                        { return (NativeFarCall*)nativeCall_before(return_address); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
// The format of this extended-range call is:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
//      jumpl_to addr, lreg
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
//      == sethi %hi54(addr), O7 ;  jumpl O7, %lo10(addr), O7 ;  <delay>
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
// That is, it is essentially the same as a NativeJump.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
class NativeFarCall;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
inline NativeFarCall* nativeFarCall_overwriting_at(address instr, address destination);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
inline NativeFarCall* nativeFarCall_at(address instr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
class NativeFarCall: public NativeInstruction {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  enum Sparc_specific_constants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
    // instruction_size includes the delay slot instruction.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
    instruction_size                   = 9 * BytesPerInstWord,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
    return_address_offset              = 9 * BytesPerInstWord,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
    jmpl_offset                        = 7 * BytesPerInstWord,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
    displacement_offset                = 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
    instruction_offset                 = 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
  address instruction_address() const       { return addr_at(0); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  address next_instruction_address() const  { return addr_at(instruction_size); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  address return_address() const            { return addr_at(return_address_offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  address destination() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
    return (address) data64(addr_at(0), long_at(jmpl_offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
  address displacement_address() const      { return addr_at(displacement_offset); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
  void set_destination(address dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
  bool destination_is_compiled_verified_entry_point();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  void  verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  void  print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
  // unit test stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  static void  test();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
  friend inline NativeFarCall* nativeFarCall_at(address instr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
    NativeFarCall* call = (NativeFarCall*)instr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
      call->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
    #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
    return call;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  friend inline NativeFarCall* nativeFarCall_overwriting_at(address instr, address destination = NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    Unimplemented();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
    NativeFarCall* call = (NativeFarCall*)instr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
    return call;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  friend NativeFarCall* nativeFarCall_before(address return_address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
    NativeFarCall* call = (NativeFarCall*)(return_address - return_address_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
    #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
      call->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
    #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
    return call;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  static bool is_call_at(address instr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  // MT-safe patching of a call instruction.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  static void insert(address code_pos, address entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
    (void)nativeFarCall_overwriting_at(code_pos, entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  static void replace_mt_safe(address instr_addr, address code_buffer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
#endif // _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
// An interface for accessing/manipulating native set_oop imm, reg instructions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
// (used to manipulate inlined data references, etc.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
//      set_oop imm, reg
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
//      == sethi %hi22(imm), reg ;  add reg, %lo10(imm), reg
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
class NativeMovConstReg;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
inline NativeMovConstReg* nativeMovConstReg_at(address address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
class NativeMovConstReg: public NativeInstruction {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  enum Sparc_specific_constants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
    sethi_offset           = 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
    add_offset             = 7 * BytesPerInstWord,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
    instruction_size       = 8 * BytesPerInstWord
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
    add_offset             = 4,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
    instruction_size       = 8
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
  address instruction_address() const       { return addr_at(0); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
  address next_instruction_address() const  { return addr_at(instruction_size); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
  // (The [set_]data accessor respects oop_type relocs also.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
  intptr_t data() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
  void set_data(intptr_t x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
  // report the destination register
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
  Register destination() { return inv_rd(long_at(sethi_offset)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
  void  verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
  void  print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
  // unit test stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  static void test();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
  friend inline NativeMovConstReg* nativeMovConstReg_at(address address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
    NativeMovConstReg* test = (NativeMovConstReg*)address;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
    #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
      test->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
    #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
    return test;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
  friend NativeMovConstReg* nativeMovConstReg_before(address address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
    NativeMovConstReg* test = (NativeMovConstReg*)(address - instruction_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
    #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
      test->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
    #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
    return test;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
// An interface for accessing/manipulating native set_oop imm, reg instructions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
// (used to manipulate inlined data references, etc.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
//      set_oop imm, reg
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
//      == sethi %hi22(imm), reg; nop; add reg, %lo10(imm), reg
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
// Note that it is identical to NativeMovConstReg with the exception of a nop between the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
// sethi and the add.  The nop is required to be in the delay slot of the call instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
// which overwrites the sethi during patching.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
class NativeMovConstRegPatching;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
inline NativeMovConstRegPatching* nativeMovConstRegPatching_at(address address);class NativeMovConstRegPatching: public NativeInstruction {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  enum Sparc_specific_constants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
    sethi_offset           = 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
    nop_offset             = 7 * BytesPerInstWord,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
    nop_offset             = sethi_offset + BytesPerInstWord,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
    add_offset             = nop_offset   + BytesPerInstWord,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
    instruction_size       = add_offset   + BytesPerInstWord
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
  address instruction_address() const       { return addr_at(0); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
  address next_instruction_address() const  { return addr_at(instruction_size); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  // (The [set_]data accessor respects oop_type relocs also.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
  int data() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
  void  set_data(int x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
  // report the destination register
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
  Register destination() { return inv_rd(long_at(sethi_offset)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
  void  verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
  void  print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
  // unit test stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
  static void test();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
  friend inline NativeMovConstRegPatching* nativeMovConstRegPatching_at(address address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
    NativeMovConstRegPatching* test = (NativeMovConstRegPatching*)address;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
    #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
      test->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
    #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
    return test;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
  friend NativeMovConstRegPatching* nativeMovConstRegPatching_before(address address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
    NativeMovConstRegPatching* test = (NativeMovConstRegPatching*)(address - instruction_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
    #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
      test->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
    #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
    return test;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
// An interface for accessing/manipulating native memory ops
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
//      ld* [reg + offset], reg
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
//      st* reg, [reg + offset]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
//      sethi %hi(imm), reg; add reg, %lo(imm), reg; ld* [reg1 + reg], reg2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
//      sethi %hi(imm), reg; add reg, %lo(imm), reg; st* reg2, [reg1 + reg]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
// Ops covered: {lds,ldu,st}{w,b,h}, {ld,st}{d,x}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
class NativeMovRegMem;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
inline NativeMovRegMem* nativeMovRegMem_at (address address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
class NativeMovRegMem: public NativeInstruction {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
  enum Sparc_specific_constants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
    op3_mask_ld = 1 << Assembler::lduw_op3 |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
                  1 << Assembler::ldub_op3 |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
                  1 << Assembler::lduh_op3 |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
                  1 << Assembler::ldd_op3 |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
                  1 << Assembler::ldsw_op3 |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
                  1 << Assembler::ldsb_op3 |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
                  1 << Assembler::ldsh_op3 |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
                  1 << Assembler::ldx_op3,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
    op3_mask_st = 1 << Assembler::stw_op3 |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
                  1 << Assembler::stb_op3 |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
                  1 << Assembler::sth_op3 |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
                  1 << Assembler::std_op3 |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
                  1 << Assembler::stx_op3,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
    op3_ldst_int_limit = Assembler::ldf_op3,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
    op3_mask_ldf = 1 << (Assembler::ldf_op3  - op3_ldst_int_limit) |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
                   1 << (Assembler::lddf_op3 - op3_ldst_int_limit),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
    op3_mask_stf = 1 << (Assembler::stf_op3  - op3_ldst_int_limit) |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
                   1 << (Assembler::stdf_op3 - op3_ldst_int_limit),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
    offset_width    = 13,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
    sethi_offset    = 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
    add_offset      = 7 * BytesPerInstWord,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
    add_offset      = 4,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
    ldst_offset     = add_offset + BytesPerInstWord
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
  bool is_immediate() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
    // check if instruction is ld* [reg + offset], reg or st* reg, [reg + offset]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
    int i0 = long_at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
    return (is_op(i0, Assembler::ldst_op));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
  address instruction_address() const           { return addr_at(0); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
  address next_instruction_address() const      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
    return addr_at(is_immediate() ? 4 : (7 * BytesPerInstWord));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
    return addr_at(is_immediate() ? 4 : 12);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
  intptr_t   offset() const                             {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
     return is_immediate()? inv_simm(long_at(0), offset_width) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
                            nativeMovConstReg_at(addr_at(0))->data();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
  void  set_offset(intptr_t x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
    if (is_immediate()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
      guarantee(fits_in_simm(x, offset_width), "data block offset overflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
      set_long_at(0, set_simm(long_at(0), x, offset_width));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
    } else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
      nativeMovConstReg_at(addr_at(0))->set_data(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
  void  add_offset_in_bytes(intptr_t radd_offset)     {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
      set_offset (offset() + radd_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
  void  copy_instruction_to(address new_instruction_address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
  void verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
  void print ();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
  // unit test stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
  static void test();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
  friend inline NativeMovRegMem* nativeMovRegMem_at (address address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
    NativeMovRegMem* test = (NativeMovRegMem*)address;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
    #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
      test->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
    #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
    return test;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
// An interface for accessing/manipulating native memory ops
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
//      ld* [reg + offset], reg
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
//      st* reg, [reg + offset]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
//      sethi %hi(imm), reg; nop; add reg, %lo(imm), reg; ld* [reg1 + reg], reg2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
//      sethi %hi(imm), reg; nop; add reg, %lo(imm), reg; st* reg2, [reg1 + reg]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
// Ops covered: {lds,ldu,st}{w,b,h}, {ld,st}{d,x}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
// Note that it is identical to NativeMovRegMem with the exception of a nop between the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
// sethi and the add.  The nop is required to be in the delay slot of the call instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
// which overwrites the sethi during patching.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
class NativeMovRegMemPatching;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
inline NativeMovRegMemPatching* nativeMovRegMemPatching_at (address address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
class NativeMovRegMemPatching: public NativeInstruction {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
  enum Sparc_specific_constants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
    op3_mask_ld = 1 << Assembler::lduw_op3 |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
                  1 << Assembler::ldub_op3 |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
                  1 << Assembler::lduh_op3 |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
                  1 << Assembler::ldd_op3 |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
                  1 << Assembler::ldsw_op3 |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
                  1 << Assembler::ldsb_op3 |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
                  1 << Assembler::ldsh_op3 |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
                  1 << Assembler::ldx_op3,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
    op3_mask_st = 1 << Assembler::stw_op3 |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
                  1 << Assembler::stb_op3 |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
                  1 << Assembler::sth_op3 |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
                  1 << Assembler::std_op3 |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
                  1 << Assembler::stx_op3,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
    op3_ldst_int_limit = Assembler::ldf_op3,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
    op3_mask_ldf = 1 << (Assembler::ldf_op3  - op3_ldst_int_limit) |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
                   1 << (Assembler::lddf_op3 - op3_ldst_int_limit),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
    op3_mask_stf = 1 << (Assembler::stf_op3  - op3_ldst_int_limit) |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
                   1 << (Assembler::stdf_op3 - op3_ldst_int_limit),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
    offset_width    = 13,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
    sethi_offset    = 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
    nop_offset      = 7 * BytesPerInstWord,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
    nop_offset      = 4,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
    add_offset      = nop_offset + BytesPerInstWord,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
    ldst_offset     = add_offset + BytesPerInstWord
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
  bool is_immediate() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
    // check if instruction is ld* [reg + offset], reg or st* reg, [reg + offset]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
    int i0 = long_at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
    return (is_op(i0, Assembler::ldst_op));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
  address instruction_address() const           { return addr_at(0); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
  address next_instruction_address() const      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
    return addr_at(is_immediate()? 4 : 16);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
  int   offset() const                          {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
     return is_immediate()? inv_simm(long_at(0), offset_width) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
                            nativeMovConstRegPatching_at(addr_at(0))->data();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
  void  set_offset(int x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
    if (is_immediate()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
      guarantee(fits_in_simm(x, offset_width), "data block offset overflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
      set_long_at(0, set_simm(long_at(0), x, offset_width));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
    else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
      nativeMovConstRegPatching_at(addr_at(0))->set_data(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
  void  add_offset_in_bytes(intptr_t radd_offset)     {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
      set_offset (offset() + radd_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
  void  copy_instruction_to(address new_instruction_address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
  void verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
  void print ();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
  // unit test stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
  static void test();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   795
  friend inline NativeMovRegMemPatching* nativeMovRegMemPatching_at (address address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
    NativeMovRegMemPatching* test = (NativeMovRegMemPatching*)address;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   797
    #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   798
      test->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   799
    #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
    return test;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   801
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   802
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
// An interface for accessing/manipulating native jumps
489c9b5090e2 Initial load
duke
parents:
diff changeset
   806
//      jump_to addr
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
//      == sethi %hi22(addr), temp ;  jumpl reg, %lo10(addr), G0 ;  <delay>
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
//      jumpl_to addr, lreg
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
//      == sethi %hi22(addr), temp ;  jumpl reg, %lo10(addr), lreg ;  <delay>
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
class NativeJump;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
inline NativeJump* nativeJump_at(address address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
class NativeJump: public NativeInstruction {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
  void guarantee_displacement(int disp, int width) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
    guarantee(fits_in_simm(disp, width + 2), "branch displacement overflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
  enum Sparc_specific_constants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
    sethi_offset           = 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
    jmpl_offset            = 7 * BytesPerInstWord,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
    instruction_size       = 9 * BytesPerInstWord  // includes delay slot
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
    jmpl_offset            = 1 * BytesPerInstWord,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
    instruction_size       = 3 * BytesPerInstWord  // includes delay slot
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
  address instruction_address() const       { return addr_at(0); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
  address next_instruction_address() const  { return addr_at(instruction_size); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
  address jump_destination() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
    return (address) data64(instruction_address(), long_at(jmpl_offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
  void set_jump_destination(address dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
    set_data64_sethi( instruction_address(), (intptr_t)dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
    set_long_at(jmpl_offset,  set_data32_simm13( long_at(jmpl_offset),  (intptr_t)dest));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
  address jump_destination() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
    return (address) data32(long_at(sethi_offset), long_at(jmpl_offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
  void set_jump_destination(address dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
    set_long_at(sethi_offset, set_data32_sethi(  long_at(sethi_offset), (intptr_t)dest));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
    set_long_at(jmpl_offset,  set_data32_simm13( long_at(jmpl_offset),  (intptr_t)dest));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
  friend inline NativeJump* nativeJump_at(address address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
    NativeJump* jump = (NativeJump*)address;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
    #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
      jump->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
    #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
    return jump;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
  void verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
  void print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
  // Unit testing stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
  static void test();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
  // Insertion of native jump instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
  static void insert(address code_pos, address entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
  // MT-safe insertion of native jump at verified method entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
  static void check_verified_entry_alignment(address entry, address verified_entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
    // nothing to do for sparc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
  static void patch_verified_entry(address entry, address verified_entry, address dest);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
// Despite the name, handles only simple branches.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
class NativeGeneralJump;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
inline NativeGeneralJump* nativeGeneralJump_at(address address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
class NativeGeneralJump: public NativeInstruction {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
  enum Sparc_specific_constants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
    instruction_size                   = 8
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
  address instruction_address() const       { return addr_at(0); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
  address jump_destination()    const       { return addr_at(0) + branch_destination_offset(long_at(0)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
  void set_jump_destination(address dest) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
    int patched_instr = patch_branch_destination_offset(dest - addr_at(0), long_at(0));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
    set_long_at(0, patched_instr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
  void set_annul() { set_annul_bit(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
  NativeInstruction *delay_slot_instr() { return nativeInstruction_at(addr_at(4));}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
  void fill_delay_slot(int instr) { set_long_at(4, instr);}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
  Assembler::Condition condition() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
    int x = long_at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
    return (Assembler::Condition) Assembler::inv_cond(x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
  // Creation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
  friend inline NativeGeneralJump* nativeGeneralJump_at(address address) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
    NativeGeneralJump* jump = (NativeGeneralJump*)(address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
      jump->verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
    return jump;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
  // Insertion of native general jump instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
  static void insert_unconditional(address code_pos, address entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
  static void replace_mt_safe(address instr_addr, address code_buffer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
  void verify();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
class NativeIllegalInstruction: public NativeInstruction {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
  enum Sparc_specific_constants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
    instruction_size            =    4
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
  // Insert illegal opcode as specific address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
  static void insert(address code_pos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   926
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   927
#endif // CPU_SPARC_VM_NATIVEINST_SPARC_HPP