mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1 | // Copyright (c) 1994-2006 Sun Microsystems Inc. |
| 2 | // All Rights Reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3 | // |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions |
| 6 | // are met: |
| 7 | // |
| 8 | // - Redistributions of source code must retain the above copyright notice, |
| 9 | // this list of conditions and the following disclaimer. |
| 10 | // |
| 11 | // - Redistribution in binary form must reproduce the above copyright |
| 12 | // notice, this list of conditions and the following disclaimer in the |
| 13 | // documentation and/or other materials provided with the |
| 14 | // distribution. |
| 15 | // |
| 16 | // - Neither the name of Sun Microsystems or the names of contributors may |
| 17 | // be used to endorse or promote products derived from this software without |
| 18 | // specific prior written permission. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 19 | // |
| 20 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 22 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 23 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 24 | // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 25 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 26 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 27 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 28 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 29 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 30 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 31 | // OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | |
| 33 | // The original source code covered by the above license above has been modified |
| 34 | // significantly by Google Inc. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 35 | // Copyright 2006-2008 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 36 | |
| 37 | #ifndef V8_ASSEMBLER_ARM_INL_H_ |
| 38 | #define V8_ASSEMBLER_ARM_INL_H_ |
| 39 | |
| 40 | #include "assembler-arm.h" |
| 41 | #include "cpu.h" |
| 42 | |
| 43 | |
| 44 | namespace v8 { namespace internal { |
| 45 | |
| 46 | Condition NegateCondition(Condition cc) { |
| 47 | ASSERT(cc != al); |
| 48 | return static_cast<Condition>(cc ^ ne); |
| 49 | } |
| 50 | |
| 51 | |
| 52 | void RelocInfo::apply(int delta) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 53 | if (RelocInfo::IsInternalReference(rmode_)) { |
| 54 | // absolute code pointer inside code object moves with the code object. |
| 55 | int32_t* p = reinterpret_cast<int32_t*>(pc_); |
| 56 | *p += delta; // relocate entry |
| 57 | } |
| 58 | // We do not use pc relative addressing on ARM, so there is |
| 59 | // nothing else to do. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | |
| 63 | Address RelocInfo::target_address() { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 64 | ASSERT(IsCodeTarget(rmode_)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 65 | return Assembler::target_address_at(pc_); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | void RelocInfo::set_target_address(Address target) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 70 | ASSERT(IsCodeTarget(rmode_)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 71 | Assembler::set_target_address_at(pc_, target); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | Object* RelocInfo::target_object() { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 76 | ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 77 | return reinterpret_cast<Object*>(Assembler::target_address_at(pc_)); |
| 78 | } |
| 79 | |
| 80 | |
| 81 | Object** RelocInfo::target_object_address() { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 82 | ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 83 | return reinterpret_cast<Object**>(Assembler::target_address_address_at(pc_)); |
| 84 | } |
| 85 | |
| 86 | |
| 87 | void RelocInfo::set_target_object(Object* target) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 88 | ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 89 | Assembler::set_target_address_at(pc_, reinterpret_cast<Address>(target)); |
| 90 | } |
| 91 | |
| 92 | |
| 93 | Address* RelocInfo::target_reference_address() { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 94 | ASSERT(rmode_ == EXTERNAL_REFERENCE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 95 | return reinterpret_cast<Address*>(pc_); |
| 96 | } |
| 97 | |
| 98 | |
| 99 | Address RelocInfo::call_address() { |
| 100 | ASSERT(is_call_instruction()); |
| 101 | UNIMPLEMENTED(); |
| 102 | return NULL; |
| 103 | } |
| 104 | |
| 105 | |
| 106 | void RelocInfo::set_call_address(Address target) { |
| 107 | ASSERT(is_call_instruction()); |
| 108 | UNIMPLEMENTED(); |
| 109 | } |
| 110 | |
| 111 | |
| 112 | Object* RelocInfo::call_object() { |
| 113 | ASSERT(is_call_instruction()); |
| 114 | UNIMPLEMENTED(); |
| 115 | return NULL; |
| 116 | } |
| 117 | |
| 118 | |
| 119 | Object** RelocInfo::call_object_address() { |
| 120 | ASSERT(is_call_instruction()); |
| 121 | UNIMPLEMENTED(); |
| 122 | return NULL; |
| 123 | } |
| 124 | |
| 125 | |
| 126 | void RelocInfo::set_call_object(Object* target) { |
| 127 | ASSERT(is_call_instruction()); |
| 128 | UNIMPLEMENTED(); |
| 129 | } |
| 130 | |
| 131 | |
| 132 | bool RelocInfo::is_call_instruction() { |
| 133 | UNIMPLEMENTED(); |
| 134 | return false; |
| 135 | } |
| 136 | |
| 137 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 138 | Operand::Operand(int32_t immediate, RelocInfo::Mode rmode) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 139 | rm_ = no_reg; |
| 140 | imm32_ = immediate; |
| 141 | rmode_ = rmode; |
| 142 | } |
| 143 | |
| 144 | |
| 145 | Operand::Operand(const char* s) { |
| 146 | rm_ = no_reg; |
| 147 | imm32_ = reinterpret_cast<int32_t>(s); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 148 | rmode_ = RelocInfo::EMBEDDED_STRING; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | |
| 152 | Operand::Operand(const ExternalReference& f) { |
| 153 | rm_ = no_reg; |
| 154 | imm32_ = reinterpret_cast<int32_t>(f.address()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 155 | rmode_ = RelocInfo::EXTERNAL_REFERENCE; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | |
| 159 | Operand::Operand(Object** opp) { |
| 160 | rm_ = no_reg; |
| 161 | imm32_ = reinterpret_cast<int32_t>(opp); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 162 | rmode_ = RelocInfo::NONE; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | |
| 166 | Operand::Operand(Context** cpp) { |
| 167 | rm_ = no_reg; |
| 168 | imm32_ = reinterpret_cast<int32_t>(cpp); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 169 | rmode_ = RelocInfo::NONE; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | |
| 173 | Operand::Operand(Smi* value) { |
| 174 | rm_ = no_reg; |
| 175 | imm32_ = reinterpret_cast<intptr_t>(value); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 176 | rmode_ = RelocInfo::NONE; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | |
| 180 | Operand::Operand(Register rm) { |
| 181 | rm_ = rm; |
| 182 | rs_ = no_reg; |
| 183 | shift_op_ = LSL; |
| 184 | shift_imm_ = 0; |
| 185 | } |
| 186 | |
| 187 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 188 | bool Operand::is_reg() const { |
| 189 | return rm_.is_valid() && |
| 190 | rs_.is(no_reg) && |
| 191 | shift_op_ == LSL && |
| 192 | shift_imm_ == 0; |
| 193 | } |
| 194 | |
| 195 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 196 | void Assembler::CheckBuffer() { |
| 197 | if (buffer_space() <= kGap) { |
| 198 | GrowBuffer(); |
| 199 | } |
| 200 | if (pc_offset() > next_buffer_check_) { |
| 201 | CheckConstPool(false, true); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | |
| 206 | void Assembler::emit(Instr x) { |
| 207 | CheckBuffer(); |
| 208 | *reinterpret_cast<Instr*>(pc_) = x; |
| 209 | pc_ += kInstrSize; |
| 210 | } |
| 211 | |
| 212 | |
| 213 | Address Assembler::target_address_address_at(Address pc) { |
| 214 | Instr instr = Memory::int32_at(pc); |
| 215 | // Verify that the instruction at pc is a ldr<cond> <Rd>, [pc +/- offset_12]. |
| 216 | ASSERT((instr & 0x0f7f0000) == 0x051f0000); |
| 217 | int offset = instr & 0xfff; // offset_12 is unsigned |
| 218 | if ((instr & (1 << 23)) == 0) offset = -offset; // U bit defines offset sign |
| 219 | // Verify that the constant pool comes after the instruction referencing it. |
| 220 | ASSERT(offset >= -4); |
| 221 | return pc + offset + 8; |
| 222 | } |
| 223 | |
| 224 | |
| 225 | Address Assembler::target_address_at(Address pc) { |
| 226 | return Memory::Address_at(target_address_address_at(pc)); |
| 227 | } |
| 228 | |
| 229 | |
| 230 | void Assembler::set_target_address_at(Address pc, Address target) { |
| 231 | Memory::Address_at(target_address_address_at(pc)) = target; |
| 232 | // Intuitively, we would think it is necessary to flush the instruction cache |
| 233 | // after patching a target address in the code as follows: |
| 234 | // CPU::FlushICache(pc, sizeof(target)); |
| 235 | // However, on ARM, no instruction was actually patched by the assignment |
| 236 | // above; the target address is not part of an instruction, it is patched in |
| 237 | // the constant pool and is read via a data access; the instruction accessing |
| 238 | // this address in the constant pool remains unchanged. |
| 239 | } |
| 240 | |
| 241 | } } // namespace v8::internal |
| 242 | |
| 243 | #endif // V8_ASSEMBLER_ARM_INL_H_ |