00001 // Copyright (c) 1994-2006 Sun Microsystems Inc. 00002 // All Rights Reserved. 00003 // 00004 // Redistribution and use in source and binary forms, with or without 00005 // modification, are permitted provided that the following conditions 00006 // are met: 00007 // 00008 // - Redistributions of source code must retain the above copyright notice, 00009 // this list of conditions and the following disclaimer. 00010 // 00011 // - Redistribution in binary form must reproduce the above copyright 00012 // notice, this list of conditions and the following disclaimer in the 00013 // documentation and/or other materials provided with the 00014 // distribution. 00015 // 00016 // - Neither the name of Sun Microsystems or the names of contributors may 00017 // be used to endorse or promote products derived from this software without 00018 // specific prior written permission. 00019 // 00020 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00021 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00022 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00023 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00024 // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00025 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00026 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00027 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00028 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 00029 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00030 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 00031 // OF THE POSSIBILITY OF SUCH DAMAGE. 00032 00033 // The original source code covered by the above license above has been modified 00034 // significantly by Google Inc. 00035 // Copyright 2006-2008 the V8 project authors. All rights reserved. 00036 00037 #ifndef V8_ASSEMBLER_ARM_INL_H_ 00038 #define V8_ASSEMBLER_ARM_INL_H_ 00039 00040 #include "assembler-arm.h" 00041 #include "cpu.h" 00042 00043 00044 namespace v8 { namespace internal { 00045 00046 Condition NegateCondition(Condition cc) { 00047 ASSERT(cc != al); 00048 return static_cast<Condition>(cc ^ ne); 00049 } 00050 00051 00052 void RelocInfo::apply(int delta) { 00053 if (RelocInfo::IsInternalReference(rmode_)) { 00054 // absolute code pointer inside code object moves with the code object. 00055 int32_t* p = reinterpret_cast<int32_t*>(pc_); 00056 *p += delta; // relocate entry 00057 } 00058 // We do not use pc relative addressing on ARM, so there is 00059 // nothing else to do. 00060 } 00061 00062 00063 Address RelocInfo::target_address() { 00064 ASSERT(IsCodeTarget(rmode_)); 00065 return Assembler::target_address_at(pc_); 00066 } 00067 00068 00069 void RelocInfo::set_target_address(Address target) { 00070 ASSERT(IsCodeTarget(rmode_)); 00071 Assembler::set_target_address_at(pc_, target); 00072 } 00073 00074 00075 Object* RelocInfo::target_object() { 00076 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); 00077 return reinterpret_cast<Object*>(Assembler::target_address_at(pc_)); 00078 } 00079 00080 00081 Object** RelocInfo::target_object_address() { 00082 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); 00083 return reinterpret_cast<Object**>(Assembler::target_address_address_at(pc_)); 00084 } 00085 00086 00087 void RelocInfo::set_target_object(Object* target) { 00088 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); 00089 Assembler::set_target_address_at(pc_, reinterpret_cast<Address>(target)); 00090 } 00091 00092 00093 Address* RelocInfo::target_reference_address() { 00094 ASSERT(rmode_ == EXTERNAL_REFERENCE); 00095 return reinterpret_cast<Address*>(pc_); 00096 } 00097 00098 00099 Address RelocInfo::call_address() { 00100 ASSERT(is_call_instruction()); 00101 UNIMPLEMENTED(); 00102 return NULL; 00103 } 00104 00105 00106 void RelocInfo::set_call_address(Address target) { 00107 ASSERT(is_call_instruction()); 00108 UNIMPLEMENTED(); 00109 } 00110 00111 00112 Object* RelocInfo::call_object() { 00113 ASSERT(is_call_instruction()); 00114 UNIMPLEMENTED(); 00115 return NULL; 00116 } 00117 00118 00119 Object** RelocInfo::call_object_address() { 00120 ASSERT(is_call_instruction()); 00121 UNIMPLEMENTED(); 00122 return NULL; 00123 } 00124 00125 00126 void RelocInfo::set_call_object(Object* target) { 00127 ASSERT(is_call_instruction()); 00128 UNIMPLEMENTED(); 00129 } 00130 00131 00132 bool RelocInfo::is_call_instruction() { 00133 UNIMPLEMENTED(); 00134 return false; 00135 } 00136 00137 00138 Operand::Operand(int32_t immediate, RelocInfo::Mode rmode) { 00139 rm_ = no_reg; 00140 imm32_ = immediate; 00141 rmode_ = rmode; 00142 } 00143 00144 00145 Operand::Operand(const char* s) { 00146 rm_ = no_reg; 00147 imm32_ = reinterpret_cast<int32_t>(s); 00148 rmode_ = RelocInfo::EMBEDDED_STRING; 00149 } 00150 00151 00152 Operand::Operand(const ExternalReference& f) { 00153 rm_ = no_reg; 00154 imm32_ = reinterpret_cast<int32_t>(f.address()); 00155 rmode_ = RelocInfo::EXTERNAL_REFERENCE; 00156 } 00157 00158 00159 Operand::Operand(Object** opp) { 00160 rm_ = no_reg; 00161 imm32_ = reinterpret_cast<int32_t>(opp); 00162 rmode_ = RelocInfo::NONE; 00163 } 00164 00165 00166 Operand::Operand(Context** cpp) { 00167 rm_ = no_reg; 00168 imm32_ = reinterpret_cast<int32_t>(cpp); 00169 rmode_ = RelocInfo::NONE; 00170 } 00171 00172 00173 Operand::Operand(Smi* value) { 00174 rm_ = no_reg; 00175 imm32_ = reinterpret_cast<intptr_t>(value); 00176 rmode_ = RelocInfo::NONE; 00177 } 00178 00179 00180 Operand::Operand(Register rm) { 00181 rm_ = rm; 00182 rs_ = no_reg; 00183 shift_op_ = LSL; 00184 shift_imm_ = 0; 00185 } 00186 00187 00188 bool Operand::is_reg() const { 00189 return rm_.is_valid() && 00190 rs_.is(no_reg) && 00191 shift_op_ == LSL && 00192 shift_imm_ == 0; 00193 } 00194 00195 00196 void Assembler::CheckBuffer() { 00197 if (buffer_space() <= kGap) { 00198 GrowBuffer(); 00199 } 00200 if (pc_offset() > next_buffer_check_) { 00201 CheckConstPool(false, true); 00202 } 00203 } 00204 00205 00206 void Assembler::emit(Instr x) { 00207 CheckBuffer(); 00208 *reinterpret_cast<Instr*>(pc_) = x; 00209 pc_ += kInstrSize; 00210 } 00211 00212 00213 Address Assembler::target_address_address_at(Address pc) { 00214 Instr instr = Memory::int32_at(pc); 00215 // Verify that the instruction at pc is a ldr<cond> <Rd>, [pc +/- offset_12]. 00216 ASSERT((instr & 0x0f7f0000) == 0x051f0000); 00217 int offset = instr & 0xfff; // offset_12 is unsigned 00218 if ((instr & (1 << 23)) == 0) offset = -offset; // U bit defines offset sign 00219 // Verify that the constant pool comes after the instruction referencing it. 00220 ASSERT(offset >= -4); 00221 return pc + offset + 8; 00222 } 00223 00224 00225 Address Assembler::target_address_at(Address pc) { 00226 return Memory::Address_at(target_address_address_at(pc)); 00227 } 00228 00229 00230 void Assembler::set_target_address_at(Address pc, Address target) { 00231 Memory::Address_at(target_address_address_at(pc)) = target; 00232 // Intuitively, we would think it is necessary to flush the instruction cache 00233 // after patching a target address in the code as follows: 00234 // CPU::FlushICache(pc, sizeof(target)); 00235 // However, on ARM, no instruction was actually patched by the assignment 00236 // above; the target address is not part of an instruction, it is patched in 00237 // the constant pool and is read via a data access; the instruction accessing 00238 // this address in the constant pool remains unchanged. 00239 } 00240 00241 } } // namespace v8::internal 00242 00243 #endif // V8_ASSEMBLER_ARM_INL_H_