hotspot/src/cpu/x86/vm/assembler_x86_32.inline.hpp
changeset 1111 a98b896e5485
parent 1110 59749505f3e8
parent 1107 5d33babdf375
child 1112 6d909d5803e3
equal deleted inserted replaced
1110:59749505f3e8 1111:a98b896e5485
     1 /*
       
     2  * Copyright 1997-2005 Sun Microsystems, Inc.  All Rights Reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    21  * have any questions.
       
    22  *
       
    23  */
       
    24 
       
    25 inline void MacroAssembler::pd_patch_instruction(address branch, address target) {
       
    26   unsigned char op = branch[0];
       
    27   assert(op == 0xE8 /* call */ ||
       
    28          op == 0xE9 /* jmp */ ||
       
    29          op == 0xEB /* short jmp */ ||
       
    30          (op & 0xF0) == 0x70 /* short jcc */ ||
       
    31          op == 0x0F && (branch[1] & 0xF0) == 0x80 /* jcc */,
       
    32          "Invalid opcode at patch point");
       
    33 
       
    34   if (op == 0xEB || (op & 0xF0) == 0x70) {
       
    35     // short offset operators (jmp and jcc)
       
    36     char* disp = (char*) &branch[1];
       
    37     int imm8 = target - (address) &disp[1];
       
    38     guarantee(this->is8bit(imm8), "Short forward jump exceeds 8-bit offset");
       
    39     *disp = imm8;
       
    40   } else {
       
    41     int* disp = (int*) &branch[(op == 0x0F)? 2: 1];
       
    42     int imm32 = target - (address) &disp[1];
       
    43     *disp = imm32;
       
    44   }
       
    45 }
       
    46 
       
    47 #ifndef PRODUCT
       
    48 inline void MacroAssembler::pd_print_patched_instruction(address branch) {
       
    49   const char* s;
       
    50   unsigned char op = branch[0];
       
    51   if (op == 0xE8) {
       
    52     s = "call";
       
    53   } else if (op == 0xE9 || op == 0xEB) {
       
    54     s = "jmp";
       
    55   } else if ((op & 0xF0) == 0x70) {
       
    56     s = "jcc";
       
    57   } else if (op == 0x0F) {
       
    58     s = "jcc";
       
    59   } else {
       
    60     s = "????";
       
    61   }
       
    62   tty->print("%s (unresolved)", s);
       
    63 }
       
    64 #endif // ndef PRODUCT