nativeInstruction.hpp

Go to the documentation of this file.
00001 /* Copyright 1994 - 1996, LongView Technologies, L.L.C. $Revision: 1.4 $ */
00002 /* Copyright (c) 2006, Sun Microsystems, Inc.
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 
00006 following conditions are met:
00007 
00008     * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following 
00010           disclaimer in the documentation and/or other materials provided with the distribution.
00011     * Neither the name of Sun Microsystems nor the names of its contributors may be used to endorse or promote products derived 
00012           from this software without specific prior written permission.
00013 
00014 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT 
00015 NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
00016 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
00017 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00018 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
00019 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
00020 
00021 
00022 */
00023 
00024 
00025 // The base class for differnt kinds of native instruction abstractions.
00026 // Provides the primitive operations to manipulate code relative to this.
00027 
00028 class NativeInstruction: ValueObj {
00029  protected:
00030   char* addr_at(int offset) const               { return (char*)this + offset; }
00031 
00032   char  char_at(int offset) const               { return *addr_at(offset); }
00033   int   long_at(int offset) const               { return *(int*)addr_at(offset); }
00034   oop   oop_at (int offset) const               { return *(oop*)addr_at(offset); }
00035 
00036   void  set_char_at(int offset, char c)         { *addr_at(offset) = c; }
00037   void  set_long_at(int offset, int  i)         { *(int*)addr_at(offset) = i; }
00038   void  set_oop_at (int offset, oop  o)         { *(oop*)addr_at(offset) = o; }
00039 };
00040 
00041 
00042 // An abstraction for accessing/manipulating native call imm32 instructions.
00043 // (used to manipulate inline caches, primitive & dll calls, etc.)
00044 
00045 class NativeCall: public NativeInstruction {
00046  public:
00047   enum Intel_specific_constants {
00048     instruction_code            = 0xE8,
00049     instruction_size            =    5,
00050     instruction_offset          =   -5,
00051     displacement_offset         =   -4,
00052     return_address_offset       =    0,
00053   };
00054 
00055   char* instruction_address() const             { return addr_at(instruction_offset); }
00056   char* next_instruction_address() const        { return addr_at(return_address_offset); }
00057   int   displacement() const                    { return long_at(displacement_offset); }
00058   char* return_address() const                  { return addr_at(return_address_offset); }
00059   char* destination() const                     { return return_address() + displacement(); }
00060   void  set_destination(char* dest)             { set_long_at(displacement_offset, dest - return_address()); }
00061 
00062   void  verify();
00063   void  print();
00064   
00065   // Creation
00066   friend NativeCall* nativeCall_at(char* address);
00067   friend NativeCall* nativeCall_from_return_address(char* return_address);
00068   friend NativeCall* nativeCall_from_relocInfo(char* displacement_address);
00069 };
00070 
00071 
00072 // An abstraction for accessing/manipulating native mov reg, imm32 instructions.
00073 // (used to manipulate inlined 32bit data dll calls, etc.)
00074 
00075 class NativeMov: public NativeInstruction {
00076  public:
00077   enum Intel_specific_constants {
00078     instruction_code            = 0xB8,
00079     instruction_size            =    5,
00080     instruction_offset          =    0,
00081     data_offset                 =    1,
00082     next_instruction_offset     =    5,
00083     register_mask               = 0x07,
00084   };
00085 
00086   char* instruction_address() const             { return addr_at(instruction_offset); }
00087   char* next_instruction_address() const        { return addr_at(next_instruction_offset); }
00088   int   data() const                            { return long_at(data_offset); }
00089   void  set_data(int x)                         { set_long_at(data_offset, x); }
00090 
00091   void  verify();
00092   void  print();
00093   
00094   // Creation
00095   friend NativeMov* nativeMov_at(char* address);
00096 };
00097 
00098 
00099 
00100 // An abstraction for accessing/manipulating native test eax, imm32 instructions.
00101 // (used to manipulate inlined 32bit data for NLRs, dll calls, etc.)
00102 
00103 class NativeTest: public NativeInstruction {
00104  public:
00105   enum Intel_specific_constants {
00106     instruction_code            = 0xA9,
00107     instruction_size            =    5,
00108     instruction_offset          =    0,
00109     data_offset                 =    1,
00110     next_instruction_offset     =    5,
00111   };
00112 
00113   char* instruction_address() const             { return addr_at(instruction_offset); }
00114   char* next_instruction_address() const        { return addr_at(next_instruction_offset); }
00115   int   data() const                            { return long_at(data_offset); }
00116   void  set_data(int x)                         { set_long_at(data_offset, x); }
00117 
00118   void  verify();
00119   void  print();
00120   
00121   // Creation
00122   friend NativeTest* nativeTest_at(char* address);
00123 
00124 };
00125 
00126 
00127 // An abstraction for accessing/manipulating native test eax, imm32 instructions that serve as IC info.
00128 
00129 class IC_Info: public NativeTest {
00130  public:
00131   enum IC_Info_specific_constants {
00132     info_offset         = data_offset,
00133     number_of_flags     = 8,
00134     flags_mask          = (1 << number_of_flags) - 1,
00135   };
00136 
00137   char* NLR_target() const                      { return instruction_address() + (data() >> number_of_flags); }
00138   int   flags() const                           { return data() & flags_mask; }
00139   void  set_flags(int flags)                    { set_data((data() & ~flags_mask) | (flags & flags_mask)); }
00140 
00141   // Creation
00142   friend IC_Info* ic_info_at(char* address);
00143 };
00144 
00145 

Generated on Mon Oct 9 13:37:16 2006 for Strongtalk VM by  doxygen 1.4.7