Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | // Copyright (c) 1994-2006 Sun Microsystems Inc. |
| 2 | // All Rights Reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are |
| 6 | // 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 distribution. |
| 14 | // |
| 15 | // - Neither the name of Sun Microsystems or the names of contributors may |
| 16 | // be used to endorse or promote products derived from this software without |
| 17 | // specific prior written permission. |
| 18 | // |
| 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 20 | // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 21 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 22 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 23 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 24 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 25 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 26 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 27 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 28 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | |
| 31 | // The original source code covered by the above license above has been |
| 32 | // modified significantly by Google Inc. |
| 33 | // Copyright 2012 the V8 project authors. All rights reserved. |
| 34 | |
| 35 | // A light-weight IA32 Assembler. |
| 36 | |
| 37 | #ifndef V8_X87_ASSEMBLER_X87_INL_H_ |
| 38 | #define V8_X87_ASSEMBLER_X87_INL_H_ |
| 39 | |
| 40 | #include "src/x87/assembler-x87.h" |
| 41 | |
| 42 | #include "src/assembler.h" |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 43 | #include "src/debug/debug.h" |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 44 | |
| 45 | namespace v8 { |
| 46 | namespace internal { |
| 47 | |
| 48 | bool CpuFeatures::SupportsCrankshaft() { return true; } |
| 49 | |
| 50 | |
| 51 | static const byte kCallOpcode = 0xE8; |
| 52 | static const int kNoCodeAgeSequenceLength = 5; |
| 53 | |
| 54 | |
| 55 | // The modes possibly affected by apply must be in kApplyMask. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 56 | void RelocInfo::apply(intptr_t delta) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 57 | if (IsRuntimeEntry(rmode_) || IsCodeTarget(rmode_)) { |
| 58 | int32_t* p = reinterpret_cast<int32_t*>(pc_); |
| 59 | *p -= delta; // Relocate entry. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 60 | } else if (IsCodeAgeSequence(rmode_)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 61 | if (*pc_ == kCallOpcode) { |
| 62 | int32_t* p = reinterpret_cast<int32_t*>(pc_ + 1); |
| 63 | *p -= delta; // Relocate entry. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 64 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 65 | } else if (IsDebugBreakSlot(rmode_) && IsPatchedDebugBreakSlotSequence()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 66 | // Special handling of a debug break slot when a break point is set (call |
| 67 | // instruction has been inserted). |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 68 | int32_t* p = reinterpret_cast<int32_t*>( |
| 69 | pc_ + Assembler::kPatchDebugBreakSlotAddressOffset); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 70 | *p -= delta; // Relocate entry. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 71 | } else if (IsInternalReference(rmode_)) { |
| 72 | // absolute code pointer inside code object moves with the code object. |
| 73 | int32_t* p = reinterpret_cast<int32_t*>(pc_); |
| 74 | *p += delta; // Relocate entry. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
| 78 | |
| 79 | Address RelocInfo::target_address() { |
| 80 | DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)); |
| 81 | return Assembler::target_address_at(pc_, host_); |
| 82 | } |
| 83 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 84 | Address RelocInfo::target_address_address() { |
| 85 | DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_) |
| 86 | || rmode_ == EMBEDDED_OBJECT |
| 87 | || rmode_ == EXTERNAL_REFERENCE); |
| 88 | return reinterpret_cast<Address>(pc_); |
| 89 | } |
| 90 | |
| 91 | |
| 92 | Address RelocInfo::constant_pool_entry_address() { |
| 93 | UNREACHABLE(); |
| 94 | return NULL; |
| 95 | } |
| 96 | |
| 97 | |
| 98 | int RelocInfo::target_address_size() { |
| 99 | return Assembler::kSpecialTargetSize; |
| 100 | } |
| 101 | |
| 102 | |
| 103 | void RelocInfo::set_target_address(Address target, |
| 104 | WriteBarrierMode write_barrier_mode, |
| 105 | ICacheFlushMode icache_flush_mode) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 106 | Assembler::set_target_address_at(isolate_, pc_, host_, target, |
| 107 | icache_flush_mode); |
| 108 | Assembler::set_target_address_at(isolate_, pc_, host_, target); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 109 | DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)); |
| 110 | if (write_barrier_mode == UPDATE_WRITE_BARRIER && host() != NULL && |
| 111 | IsCodeTarget(rmode_)) { |
| 112 | Object* target_code = Code::GetCodeFromTargetAddress(target); |
| 113 | host()->GetHeap()->incremental_marking()->RecordWriteIntoCode( |
| 114 | host(), this, HeapObject::cast(target_code)); |
| 115 | } |
| 116 | } |
| 117 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 118 | Object* RelocInfo::target_object() { |
| 119 | DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); |
| 120 | return Memory::Object_at(pc_); |
| 121 | } |
| 122 | |
| 123 | |
| 124 | Handle<Object> RelocInfo::target_object_handle(Assembler* origin) { |
| 125 | DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); |
| 126 | return Memory::Object_Handle_at(pc_); |
| 127 | } |
| 128 | |
| 129 | |
| 130 | void RelocInfo::set_target_object(Object* target, |
| 131 | WriteBarrierMode write_barrier_mode, |
| 132 | ICacheFlushMode icache_flush_mode) { |
| 133 | DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); |
| 134 | Memory::Object_at(pc_) = target; |
| 135 | if (icache_flush_mode != SKIP_ICACHE_FLUSH) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 136 | Assembler::FlushICache(isolate_, pc_, sizeof(Address)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 137 | } |
| 138 | if (write_barrier_mode == UPDATE_WRITE_BARRIER && |
| 139 | host() != NULL && |
| 140 | target->IsHeapObject()) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 141 | host()->GetHeap()->incremental_marking()->RecordWriteIntoCode( |
| 142 | host(), this, HeapObject::cast(target)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | |
| 146 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 147 | Address RelocInfo::target_external_reference() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 148 | DCHECK(rmode_ == RelocInfo::EXTERNAL_REFERENCE); |
| 149 | return Memory::Address_at(pc_); |
| 150 | } |
| 151 | |
| 152 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 153 | Address RelocInfo::target_internal_reference() { |
| 154 | DCHECK(rmode_ == INTERNAL_REFERENCE); |
| 155 | return Memory::Address_at(pc_); |
| 156 | } |
| 157 | |
| 158 | |
| 159 | Address RelocInfo::target_internal_reference_address() { |
| 160 | DCHECK(rmode_ == INTERNAL_REFERENCE); |
| 161 | return reinterpret_cast<Address>(pc_); |
| 162 | } |
| 163 | |
| 164 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 165 | Address RelocInfo::target_runtime_entry(Assembler* origin) { |
| 166 | DCHECK(IsRuntimeEntry(rmode_)); |
| 167 | return reinterpret_cast<Address>(*reinterpret_cast<int32_t*>(pc_)); |
| 168 | } |
| 169 | |
| 170 | |
| 171 | void RelocInfo::set_target_runtime_entry(Address target, |
| 172 | WriteBarrierMode write_barrier_mode, |
| 173 | ICacheFlushMode icache_flush_mode) { |
| 174 | DCHECK(IsRuntimeEntry(rmode_)); |
| 175 | if (target_address() != target) { |
| 176 | set_target_address(target, write_barrier_mode, icache_flush_mode); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | |
| 181 | Handle<Cell> RelocInfo::target_cell_handle() { |
| 182 | DCHECK(rmode_ == RelocInfo::CELL); |
| 183 | Address address = Memory::Address_at(pc_); |
| 184 | return Handle<Cell>(reinterpret_cast<Cell**>(address)); |
| 185 | } |
| 186 | |
| 187 | |
| 188 | Cell* RelocInfo::target_cell() { |
| 189 | DCHECK(rmode_ == RelocInfo::CELL); |
| 190 | return Cell::FromValueAddress(Memory::Address_at(pc_)); |
| 191 | } |
| 192 | |
| 193 | |
| 194 | void RelocInfo::set_target_cell(Cell* cell, |
| 195 | WriteBarrierMode write_barrier_mode, |
| 196 | ICacheFlushMode icache_flush_mode) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 197 | DCHECK(cell->IsCell()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 198 | DCHECK(rmode_ == RelocInfo::CELL); |
| 199 | Address address = cell->address() + Cell::kValueOffset; |
| 200 | Memory::Address_at(pc_) = address; |
| 201 | if (icache_flush_mode != SKIP_ICACHE_FLUSH) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 202 | Assembler::FlushICache(isolate_, pc_, sizeof(Address)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 203 | } |
| 204 | if (write_barrier_mode == UPDATE_WRITE_BARRIER && host() != NULL) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 205 | host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(host(), this, |
| 206 | cell); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 207 | } |
| 208 | } |
| 209 | |
| 210 | |
| 211 | Handle<Object> RelocInfo::code_age_stub_handle(Assembler* origin) { |
| 212 | DCHECK(rmode_ == RelocInfo::CODE_AGE_SEQUENCE); |
| 213 | DCHECK(*pc_ == kCallOpcode); |
| 214 | return Memory::Object_Handle_at(pc_ + 1); |
| 215 | } |
| 216 | |
| 217 | |
| 218 | Code* RelocInfo::code_age_stub() { |
| 219 | DCHECK(rmode_ == RelocInfo::CODE_AGE_SEQUENCE); |
| 220 | DCHECK(*pc_ == kCallOpcode); |
| 221 | return Code::GetCodeFromTargetAddress( |
| 222 | Assembler::target_address_at(pc_ + 1, host_)); |
| 223 | } |
| 224 | |
| 225 | |
| 226 | void RelocInfo::set_code_age_stub(Code* stub, |
| 227 | ICacheFlushMode icache_flush_mode) { |
| 228 | DCHECK(*pc_ == kCallOpcode); |
| 229 | DCHECK(rmode_ == RelocInfo::CODE_AGE_SEQUENCE); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 230 | Assembler::set_target_address_at( |
| 231 | isolate_, pc_ + 1, host_, stub->instruction_start(), icache_flush_mode); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 235 | Address RelocInfo::debug_call_address() { |
| 236 | DCHECK(IsDebugBreakSlot(rmode()) && IsPatchedDebugBreakSlotSequence()); |
| 237 | Address location = pc_ + Assembler::kPatchDebugBreakSlotAddressOffset; |
| 238 | return Assembler::target_address_at(location, host_); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 242 | void RelocInfo::set_debug_call_address(Address target) { |
| 243 | DCHECK(IsDebugBreakSlot(rmode()) && IsPatchedDebugBreakSlotSequence()); |
| 244 | Address location = pc_ + Assembler::kPatchDebugBreakSlotAddressOffset; |
| 245 | Assembler::set_target_address_at(isolate_, location, host_, target); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 246 | if (host() != NULL) { |
| 247 | Object* target_code = Code::GetCodeFromTargetAddress(target); |
| 248 | host()->GetHeap()->incremental_marking()->RecordWriteIntoCode( |
| 249 | host(), this, HeapObject::cast(target_code)); |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 254 | void RelocInfo::WipeOut() { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 255 | if (IsEmbeddedObject(rmode_) || IsExternalReference(rmode_) || |
| 256 | IsInternalReference(rmode_)) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 257 | Memory::Address_at(pc_) = NULL; |
| 258 | } else if (IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)) { |
| 259 | // Effectively write zero into the relocation. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 260 | Assembler::set_target_address_at(isolate_, pc_, host_, |
| 261 | pc_ + sizeof(int32_t)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 262 | } else { |
| 263 | UNREACHABLE(); |
| 264 | } |
| 265 | } |
| 266 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 267 | template <typename ObjectVisitor> |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 268 | void RelocInfo::Visit(Isolate* isolate, ObjectVisitor* visitor) { |
| 269 | RelocInfo::Mode mode = rmode(); |
| 270 | if (mode == RelocInfo::EMBEDDED_OBJECT) { |
| 271 | visitor->VisitEmbeddedPointer(this); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 272 | Assembler::FlushICache(isolate, pc_, sizeof(Address)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 273 | } else if (RelocInfo::IsCodeTarget(mode)) { |
| 274 | visitor->VisitCodeTarget(this); |
| 275 | } else if (mode == RelocInfo::CELL) { |
| 276 | visitor->VisitCell(this); |
| 277 | } else if (mode == RelocInfo::EXTERNAL_REFERENCE) { |
| 278 | visitor->VisitExternalReference(this); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 279 | } else if (mode == RelocInfo::INTERNAL_REFERENCE) { |
| 280 | visitor->VisitInternalReference(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 281 | } else if (RelocInfo::IsCodeAgeSequence(mode)) { |
| 282 | visitor->VisitCodeAgeSequence(this); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 283 | } else if (RelocInfo::IsDebugBreakSlot(mode) && |
| 284 | IsPatchedDebugBreakSlotSequence()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 285 | visitor->VisitDebugTarget(this); |
| 286 | } else if (IsRuntimeEntry(mode)) { |
| 287 | visitor->VisitRuntimeEntry(this); |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | |
| 292 | template<typename StaticVisitor> |
| 293 | void RelocInfo::Visit(Heap* heap) { |
| 294 | RelocInfo::Mode mode = rmode(); |
| 295 | if (mode == RelocInfo::EMBEDDED_OBJECT) { |
| 296 | StaticVisitor::VisitEmbeddedPointer(heap, this); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 297 | Assembler::FlushICache(heap->isolate(), pc_, sizeof(Address)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 298 | } else if (RelocInfo::IsCodeTarget(mode)) { |
| 299 | StaticVisitor::VisitCodeTarget(heap, this); |
| 300 | } else if (mode == RelocInfo::CELL) { |
| 301 | StaticVisitor::VisitCell(heap, this); |
| 302 | } else if (mode == RelocInfo::EXTERNAL_REFERENCE) { |
| 303 | StaticVisitor::VisitExternalReference(this); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 304 | } else if (mode == RelocInfo::INTERNAL_REFERENCE) { |
| 305 | StaticVisitor::VisitInternalReference(this); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 306 | } else if (RelocInfo::IsCodeAgeSequence(mode)) { |
| 307 | StaticVisitor::VisitCodeAgeSequence(heap, this); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 308 | } else if (RelocInfo::IsDebugBreakSlot(mode) && |
| 309 | IsPatchedDebugBreakSlotSequence()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 310 | StaticVisitor::VisitDebugTarget(heap, this); |
| 311 | } else if (IsRuntimeEntry(mode)) { |
| 312 | StaticVisitor::VisitRuntimeEntry(this); |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | |
| 317 | |
| 318 | Immediate::Immediate(int x) { |
| 319 | x_ = x; |
| 320 | rmode_ = RelocInfo::NONE32; |
| 321 | } |
| 322 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 323 | Immediate::Immediate(Address x, RelocInfo::Mode rmode) { |
| 324 | x_ = reinterpret_cast<int32_t>(x); |
| 325 | rmode_ = rmode; |
| 326 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 327 | |
| 328 | Immediate::Immediate(const ExternalReference& ext) { |
| 329 | x_ = reinterpret_cast<int32_t>(ext.address()); |
| 330 | rmode_ = RelocInfo::EXTERNAL_REFERENCE; |
| 331 | } |
| 332 | |
| 333 | |
| 334 | Immediate::Immediate(Label* internal_offset) { |
| 335 | x_ = reinterpret_cast<int32_t>(internal_offset); |
| 336 | rmode_ = RelocInfo::INTERNAL_REFERENCE; |
| 337 | } |
| 338 | |
| 339 | |
| 340 | Immediate::Immediate(Handle<Object> handle) { |
| 341 | AllowDeferredHandleDereference using_raw_address; |
| 342 | // Verify all Objects referred by code are NOT in new space. |
| 343 | Object* obj = *handle; |
| 344 | if (obj->IsHeapObject()) { |
| 345 | DCHECK(!HeapObject::cast(obj)->GetHeap()->InNewSpace(obj)); |
| 346 | x_ = reinterpret_cast<intptr_t>(handle.location()); |
| 347 | rmode_ = RelocInfo::EMBEDDED_OBJECT; |
| 348 | } else { |
| 349 | // no relocation needed |
| 350 | x_ = reinterpret_cast<intptr_t>(obj); |
| 351 | rmode_ = RelocInfo::NONE32; |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | |
| 356 | Immediate::Immediate(Smi* value) { |
| 357 | x_ = reinterpret_cast<intptr_t>(value); |
| 358 | rmode_ = RelocInfo::NONE32; |
| 359 | } |
| 360 | |
| 361 | |
| 362 | Immediate::Immediate(Address addr) { |
| 363 | x_ = reinterpret_cast<int32_t>(addr); |
| 364 | rmode_ = RelocInfo::NONE32; |
| 365 | } |
| 366 | |
| 367 | |
| 368 | void Assembler::emit(uint32_t x) { |
| 369 | *reinterpret_cast<uint32_t*>(pc_) = x; |
| 370 | pc_ += sizeof(uint32_t); |
| 371 | } |
| 372 | |
| 373 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 374 | void Assembler::emit_q(uint64_t x) { |
| 375 | *reinterpret_cast<uint64_t*>(pc_) = x; |
| 376 | pc_ += sizeof(uint64_t); |
| 377 | } |
| 378 | |
| 379 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 380 | void Assembler::emit(Handle<Object> handle) { |
| 381 | AllowDeferredHandleDereference heap_object_check; |
| 382 | // Verify all Objects referred by code are NOT in new space. |
| 383 | Object* obj = *handle; |
| 384 | DCHECK(!isolate()->heap()->InNewSpace(obj)); |
| 385 | if (obj->IsHeapObject()) { |
| 386 | emit(reinterpret_cast<intptr_t>(handle.location()), |
| 387 | RelocInfo::EMBEDDED_OBJECT); |
| 388 | } else { |
| 389 | // no relocation needed |
| 390 | emit(reinterpret_cast<intptr_t>(obj)); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | |
| 395 | void Assembler::emit(uint32_t x, RelocInfo::Mode rmode, TypeFeedbackId id) { |
| 396 | if (rmode == RelocInfo::CODE_TARGET && !id.IsNone()) { |
| 397 | RecordRelocInfo(RelocInfo::CODE_TARGET_WITH_ID, id.ToInt()); |
| 398 | } else if (!RelocInfo::IsNone(rmode) |
| 399 | && rmode != RelocInfo::CODE_AGE_SEQUENCE) { |
| 400 | RecordRelocInfo(rmode); |
| 401 | } |
| 402 | emit(x); |
| 403 | } |
| 404 | |
| 405 | |
| 406 | void Assembler::emit(Handle<Code> code, |
| 407 | RelocInfo::Mode rmode, |
| 408 | TypeFeedbackId id) { |
| 409 | AllowDeferredHandleDereference embedding_raw_address; |
| 410 | emit(reinterpret_cast<intptr_t>(code.location()), rmode, id); |
| 411 | } |
| 412 | |
| 413 | |
| 414 | void Assembler::emit(const Immediate& x) { |
| 415 | if (x.rmode_ == RelocInfo::INTERNAL_REFERENCE) { |
| 416 | Label* label = reinterpret_cast<Label*>(x.x_); |
| 417 | emit_code_relative_offset(label); |
| 418 | return; |
| 419 | } |
| 420 | if (!RelocInfo::IsNone(x.rmode_)) RecordRelocInfo(x.rmode_); |
| 421 | emit(x.x_); |
| 422 | } |
| 423 | |
| 424 | |
| 425 | void Assembler::emit_code_relative_offset(Label* label) { |
| 426 | if (label->is_bound()) { |
| 427 | int32_t pos; |
| 428 | pos = label->pos() + Code::kHeaderSize - kHeapObjectTag; |
| 429 | emit(pos); |
| 430 | } else { |
| 431 | emit_disp(label, Displacement::CODE_RELATIVE); |
| 432 | } |
| 433 | } |
| 434 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 435 | void Assembler::emit_b(Immediate x) { |
| 436 | DCHECK(x.is_int8() || x.is_uint8()); |
| 437 | uint8_t value = static_cast<uint8_t>(x.x_); |
| 438 | *pc_++ = value; |
| 439 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 440 | |
| 441 | void Assembler::emit_w(const Immediate& x) { |
| 442 | DCHECK(RelocInfo::IsNone(x.rmode_)); |
| 443 | uint16_t value = static_cast<uint16_t>(x.x_); |
| 444 | reinterpret_cast<uint16_t*>(pc_)[0] = value; |
| 445 | pc_ += sizeof(uint16_t); |
| 446 | } |
| 447 | |
| 448 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 449 | Address Assembler::target_address_at(Address pc, Address constant_pool) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 450 | return pc + sizeof(int32_t) + *reinterpret_cast<int32_t*>(pc); |
| 451 | } |
| 452 | |
| 453 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 454 | void Assembler::set_target_address_at(Isolate* isolate, Address pc, |
| 455 | Address constant_pool, Address target, |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 456 | ICacheFlushMode icache_flush_mode) { |
| 457 | int32_t* p = reinterpret_cast<int32_t*>(pc); |
| 458 | *p = target - (pc + sizeof(int32_t)); |
| 459 | if (icache_flush_mode != SKIP_ICACHE_FLUSH) { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 460 | Assembler::FlushICache(isolate, p, sizeof(int32_t)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 461 | } |
| 462 | } |
| 463 | |
| 464 | |
| 465 | Address Assembler::target_address_from_return_address(Address pc) { |
| 466 | return pc - kCallTargetAddressOffset; |
| 467 | } |
| 468 | |
| 469 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 470 | Displacement Assembler::disp_at(Label* L) { |
| 471 | return Displacement(long_at(L->pos())); |
| 472 | } |
| 473 | |
| 474 | |
| 475 | void Assembler::disp_at_put(Label* L, Displacement disp) { |
| 476 | long_at_put(L->pos(), disp.data()); |
| 477 | } |
| 478 | |
| 479 | |
| 480 | void Assembler::emit_disp(Label* L, Displacement::Type type) { |
| 481 | Displacement disp(L, type); |
| 482 | L->link_to(pc_offset()); |
| 483 | emit(static_cast<int>(disp.data())); |
| 484 | } |
| 485 | |
| 486 | |
| 487 | void Assembler::emit_near_disp(Label* L) { |
| 488 | byte disp = 0x00; |
| 489 | if (L->is_near_linked()) { |
| 490 | int offset = L->near_link_pos() - pc_offset(); |
| 491 | DCHECK(is_int8(offset)); |
| 492 | disp = static_cast<byte>(offset & 0xFF); |
| 493 | } |
| 494 | L->link_to(pc_offset(), Label::kNear); |
| 495 | *pc_++ = disp; |
| 496 | } |
| 497 | |
| 498 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 499 | void Assembler::deserialization_set_target_internal_reference_at( |
| 500 | Isolate* isolate, Address pc, Address target, RelocInfo::Mode mode) { |
| 501 | Memory::Address_at(pc) = target; |
| 502 | } |
| 503 | |
| 504 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 505 | void Operand::set_modrm(int mod, Register rm) { |
| 506 | DCHECK((mod & -4) == 0); |
| 507 | buf_[0] = mod << 6 | rm.code(); |
| 508 | len_ = 1; |
| 509 | } |
| 510 | |
| 511 | |
| 512 | void Operand::set_sib(ScaleFactor scale, Register index, Register base) { |
| 513 | DCHECK(len_ == 1); |
| 514 | DCHECK((scale & -4) == 0); |
| 515 | // Use SIB with no index register only for base esp. |
| 516 | DCHECK(!index.is(esp) || base.is(esp)); |
| 517 | buf_[1] = scale << 6 | index.code() << 3 | base.code(); |
| 518 | len_ = 2; |
| 519 | } |
| 520 | |
| 521 | |
| 522 | void Operand::set_disp8(int8_t disp) { |
| 523 | DCHECK(len_ == 1 || len_ == 2); |
| 524 | *reinterpret_cast<int8_t*>(&buf_[len_++]) = disp; |
| 525 | } |
| 526 | |
| 527 | |
| 528 | void Operand::set_dispr(int32_t disp, RelocInfo::Mode rmode) { |
| 529 | DCHECK(len_ == 1 || len_ == 2); |
| 530 | int32_t* p = reinterpret_cast<int32_t*>(&buf_[len_]); |
| 531 | *p = disp; |
| 532 | len_ += sizeof(int32_t); |
| 533 | rmode_ = rmode; |
| 534 | } |
| 535 | |
| 536 | Operand::Operand(Register reg) { |
| 537 | // reg |
| 538 | set_modrm(3, reg); |
| 539 | } |
| 540 | |
| 541 | |
| 542 | Operand::Operand(int32_t disp, RelocInfo::Mode rmode) { |
| 543 | // [disp/r] |
| 544 | set_modrm(0, ebp); |
| 545 | set_dispr(disp, rmode); |
| 546 | } |
| 547 | |
| 548 | |
| 549 | Operand::Operand(Immediate imm) { |
| 550 | // [disp/r] |
| 551 | set_modrm(0, ebp); |
| 552 | set_dispr(imm.x_, imm.rmode_); |
| 553 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 554 | } // namespace internal |
| 555 | } // namespace v8 |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 556 | |
| 557 | #endif // V8_X87_ASSEMBLER_X87_INL_H_ |