blob: 802c80fa716abd5a943e346202f85b11fc7b62b2 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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 Murdoch4a90d5f2016-03-22 12:00:34 +000043#include "src/debug/debug.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000044
45namespace v8 {
46namespace internal {
47
48bool CpuFeatures::SupportsCrankshaft() { return true; }
49
50
51static const byte kCallOpcode = 0xE8;
52static const int kNoCodeAgeSequenceLength = 5;
53
54
55// The modes possibly affected by apply must be in kApplyMask.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000056void RelocInfo::apply(intptr_t delta) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000057 if (IsRuntimeEntry(rmode_) || IsCodeTarget(rmode_)) {
58 int32_t* p = reinterpret_cast<int32_t*>(pc_);
59 *p -= delta; // Relocate entry.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000060 } else if (IsCodeAgeSequence(rmode_)) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000061 if (*pc_ == kCallOpcode) {
62 int32_t* p = reinterpret_cast<int32_t*>(pc_ + 1);
63 *p -= delta; // Relocate entry.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000064 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000065 } else if (IsDebugBreakSlot(rmode_) && IsPatchedDebugBreakSlotSequence()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000066 // Special handling of a debug break slot when a break point is set (call
67 // instruction has been inserted).
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000068 int32_t* p = reinterpret_cast<int32_t*>(
69 pc_ + Assembler::kPatchDebugBreakSlotAddressOffset);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000070 *p -= delta; // Relocate entry.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000071 } 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 Murdochb8a8cc12014-11-26 15:28:44 +000075 }
76}
77
78
79Address RelocInfo::target_address() {
80 DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_));
81 return Assembler::target_address_at(pc_, host_);
82}
83
Ben Murdochda12d292016-06-02 14:46:10 +010084Address RelocInfo::wasm_memory_reference() {
85 DCHECK(IsWasmMemoryReference(rmode_));
86 return Memory::Address_at(pc_);
87}
Ben Murdochb8a8cc12014-11-26 15:28:44 +000088
89Address RelocInfo::target_address_address() {
90 DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)
91 || rmode_ == EMBEDDED_OBJECT
92 || rmode_ == EXTERNAL_REFERENCE);
93 return reinterpret_cast<Address>(pc_);
94}
95
96
97Address RelocInfo::constant_pool_entry_address() {
98 UNREACHABLE();
99 return NULL;
100}
101
102
103int RelocInfo::target_address_size() {
104 return Assembler::kSpecialTargetSize;
105}
106
107
108void RelocInfo::set_target_address(Address target,
109 WriteBarrierMode write_barrier_mode,
110 ICacheFlushMode icache_flush_mode) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000111 Assembler::set_target_address_at(isolate_, pc_, host_, target,
112 icache_flush_mode);
113 Assembler::set_target_address_at(isolate_, pc_, host_, target);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000114 DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_));
115 if (write_barrier_mode == UPDATE_WRITE_BARRIER && host() != NULL &&
116 IsCodeTarget(rmode_)) {
117 Object* target_code = Code::GetCodeFromTargetAddress(target);
118 host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(
119 host(), this, HeapObject::cast(target_code));
120 }
121}
122
Ben Murdochda12d292016-06-02 14:46:10 +0100123void RelocInfo::update_wasm_memory_reference(
124 Address old_base, Address new_base, size_t old_size, size_t new_size,
125 ICacheFlushMode icache_flush_mode) {
126 DCHECK(IsWasmMemoryReference(rmode_));
127 DCHECK(old_base <= wasm_memory_reference() &&
128 wasm_memory_reference() < old_base + old_size);
129 Address updated_reference = new_base + (wasm_memory_reference() - old_base);
130 DCHECK(new_base <= updated_reference &&
131 updated_reference < new_base + new_size);
132 Memory::Address_at(pc_) = updated_reference;
133 if (icache_flush_mode != SKIP_ICACHE_FLUSH) {
134 Assembler::FlushICache(isolate_, pc_, sizeof(int32_t));
135 }
136}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000137
138Object* RelocInfo::target_object() {
139 DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
140 return Memory::Object_at(pc_);
141}
142
143
144Handle<Object> RelocInfo::target_object_handle(Assembler* origin) {
145 DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
146 return Memory::Object_Handle_at(pc_);
147}
148
149
150void RelocInfo::set_target_object(Object* target,
151 WriteBarrierMode write_barrier_mode,
152 ICacheFlushMode icache_flush_mode) {
153 DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
154 Memory::Object_at(pc_) = target;
155 if (icache_flush_mode != SKIP_ICACHE_FLUSH) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000156 Assembler::FlushICache(isolate_, pc_, sizeof(Address));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000157 }
158 if (write_barrier_mode == UPDATE_WRITE_BARRIER &&
159 host() != NULL &&
160 target->IsHeapObject()) {
Ben Murdochda12d292016-06-02 14:46:10 +0100161 host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(
162 host(), this, HeapObject::cast(target));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000163 }
164}
165
166
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000167Address RelocInfo::target_external_reference() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000168 DCHECK(rmode_ == RelocInfo::EXTERNAL_REFERENCE);
169 return Memory::Address_at(pc_);
170}
171
172
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000173Address RelocInfo::target_internal_reference() {
174 DCHECK(rmode_ == INTERNAL_REFERENCE);
175 return Memory::Address_at(pc_);
176}
177
178
179Address RelocInfo::target_internal_reference_address() {
180 DCHECK(rmode_ == INTERNAL_REFERENCE);
181 return reinterpret_cast<Address>(pc_);
182}
183
184
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000185Address RelocInfo::target_runtime_entry(Assembler* origin) {
186 DCHECK(IsRuntimeEntry(rmode_));
187 return reinterpret_cast<Address>(*reinterpret_cast<int32_t*>(pc_));
188}
189
190
191void RelocInfo::set_target_runtime_entry(Address target,
192 WriteBarrierMode write_barrier_mode,
193 ICacheFlushMode icache_flush_mode) {
194 DCHECK(IsRuntimeEntry(rmode_));
195 if (target_address() != target) {
196 set_target_address(target, write_barrier_mode, icache_flush_mode);
197 }
198}
199
200
201Handle<Cell> RelocInfo::target_cell_handle() {
202 DCHECK(rmode_ == RelocInfo::CELL);
203 Address address = Memory::Address_at(pc_);
204 return Handle<Cell>(reinterpret_cast<Cell**>(address));
205}
206
207
208Cell* RelocInfo::target_cell() {
209 DCHECK(rmode_ == RelocInfo::CELL);
210 return Cell::FromValueAddress(Memory::Address_at(pc_));
211}
212
213
214void RelocInfo::set_target_cell(Cell* cell,
215 WriteBarrierMode write_barrier_mode,
216 ICacheFlushMode icache_flush_mode) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000217 DCHECK(cell->IsCell());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000218 DCHECK(rmode_ == RelocInfo::CELL);
219 Address address = cell->address() + Cell::kValueOffset;
220 Memory::Address_at(pc_) = address;
221 if (icache_flush_mode != SKIP_ICACHE_FLUSH) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000222 Assembler::FlushICache(isolate_, pc_, sizeof(Address));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000223 }
224 if (write_barrier_mode == UPDATE_WRITE_BARRIER && host() != NULL) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100225 host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(host(), this,
226 cell);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000227 }
228}
229
230
231Handle<Object> RelocInfo::code_age_stub_handle(Assembler* origin) {
232 DCHECK(rmode_ == RelocInfo::CODE_AGE_SEQUENCE);
233 DCHECK(*pc_ == kCallOpcode);
234 return Memory::Object_Handle_at(pc_ + 1);
235}
236
237
238Code* RelocInfo::code_age_stub() {
239 DCHECK(rmode_ == RelocInfo::CODE_AGE_SEQUENCE);
240 DCHECK(*pc_ == kCallOpcode);
241 return Code::GetCodeFromTargetAddress(
242 Assembler::target_address_at(pc_ + 1, host_));
243}
244
245
246void RelocInfo::set_code_age_stub(Code* stub,
247 ICacheFlushMode icache_flush_mode) {
248 DCHECK(*pc_ == kCallOpcode);
249 DCHECK(rmode_ == RelocInfo::CODE_AGE_SEQUENCE);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000250 Assembler::set_target_address_at(
251 isolate_, pc_ + 1, host_, stub->instruction_start(), icache_flush_mode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000252}
253
254
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000255Address RelocInfo::debug_call_address() {
256 DCHECK(IsDebugBreakSlot(rmode()) && IsPatchedDebugBreakSlotSequence());
257 Address location = pc_ + Assembler::kPatchDebugBreakSlotAddressOffset;
258 return Assembler::target_address_at(location, host_);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000259}
260
261
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000262void RelocInfo::set_debug_call_address(Address target) {
263 DCHECK(IsDebugBreakSlot(rmode()) && IsPatchedDebugBreakSlotSequence());
264 Address location = pc_ + Assembler::kPatchDebugBreakSlotAddressOffset;
265 Assembler::set_target_address_at(isolate_, location, host_, target);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000266 if (host() != NULL) {
267 Object* target_code = Code::GetCodeFromTargetAddress(target);
268 host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(
269 host(), this, HeapObject::cast(target_code));
270 }
271}
272
273
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000274void RelocInfo::WipeOut() {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000275 if (IsEmbeddedObject(rmode_) || IsExternalReference(rmode_) ||
276 IsInternalReference(rmode_)) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000277 Memory::Address_at(pc_) = NULL;
278 } else if (IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)) {
279 // Effectively write zero into the relocation.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000280 Assembler::set_target_address_at(isolate_, pc_, host_,
281 pc_ + sizeof(int32_t));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000282 } else {
283 UNREACHABLE();
284 }
285}
286
287
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000288void RelocInfo::Visit(Isolate* isolate, ObjectVisitor* visitor) {
289 RelocInfo::Mode mode = rmode();
290 if (mode == RelocInfo::EMBEDDED_OBJECT) {
291 visitor->VisitEmbeddedPointer(this);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000292 Assembler::FlushICache(isolate, pc_, sizeof(Address));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000293 } else if (RelocInfo::IsCodeTarget(mode)) {
294 visitor->VisitCodeTarget(this);
295 } else if (mode == RelocInfo::CELL) {
296 visitor->VisitCell(this);
297 } else if (mode == RelocInfo::EXTERNAL_REFERENCE) {
298 visitor->VisitExternalReference(this);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000299 } else if (mode == RelocInfo::INTERNAL_REFERENCE) {
300 visitor->VisitInternalReference(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000301 } else if (RelocInfo::IsCodeAgeSequence(mode)) {
302 visitor->VisitCodeAgeSequence(this);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000303 } else if (RelocInfo::IsDebugBreakSlot(mode) &&
304 IsPatchedDebugBreakSlotSequence()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000305 visitor->VisitDebugTarget(this);
306 } else if (IsRuntimeEntry(mode)) {
307 visitor->VisitRuntimeEntry(this);
308 }
309}
310
311
312template<typename StaticVisitor>
313void RelocInfo::Visit(Heap* heap) {
314 RelocInfo::Mode mode = rmode();
315 if (mode == RelocInfo::EMBEDDED_OBJECT) {
316 StaticVisitor::VisitEmbeddedPointer(heap, this);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000317 Assembler::FlushICache(heap->isolate(), pc_, sizeof(Address));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000318 } else if (RelocInfo::IsCodeTarget(mode)) {
319 StaticVisitor::VisitCodeTarget(heap, this);
320 } else if (mode == RelocInfo::CELL) {
321 StaticVisitor::VisitCell(heap, this);
322 } else if (mode == RelocInfo::EXTERNAL_REFERENCE) {
323 StaticVisitor::VisitExternalReference(this);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000324 } else if (mode == RelocInfo::INTERNAL_REFERENCE) {
325 StaticVisitor::VisitInternalReference(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000326 } else if (RelocInfo::IsCodeAgeSequence(mode)) {
327 StaticVisitor::VisitCodeAgeSequence(heap, this);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000328 } else if (RelocInfo::IsDebugBreakSlot(mode) &&
329 IsPatchedDebugBreakSlotSequence()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000330 StaticVisitor::VisitDebugTarget(heap, this);
331 } else if (IsRuntimeEntry(mode)) {
332 StaticVisitor::VisitRuntimeEntry(this);
333 }
334}
335
336
337
338Immediate::Immediate(int x) {
339 x_ = x;
340 rmode_ = RelocInfo::NONE32;
341}
342
Ben Murdochda12d292016-06-02 14:46:10 +0100343Immediate::Immediate(Address x, RelocInfo::Mode rmode) {
344 x_ = reinterpret_cast<int32_t>(x);
345 rmode_ = rmode;
346}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000347
348Immediate::Immediate(const ExternalReference& ext) {
349 x_ = reinterpret_cast<int32_t>(ext.address());
350 rmode_ = RelocInfo::EXTERNAL_REFERENCE;
351}
352
353
354Immediate::Immediate(Label* internal_offset) {
355 x_ = reinterpret_cast<int32_t>(internal_offset);
356 rmode_ = RelocInfo::INTERNAL_REFERENCE;
357}
358
359
360Immediate::Immediate(Handle<Object> handle) {
361 AllowDeferredHandleDereference using_raw_address;
362 // Verify all Objects referred by code are NOT in new space.
363 Object* obj = *handle;
364 if (obj->IsHeapObject()) {
365 DCHECK(!HeapObject::cast(obj)->GetHeap()->InNewSpace(obj));
366 x_ = reinterpret_cast<intptr_t>(handle.location());
367 rmode_ = RelocInfo::EMBEDDED_OBJECT;
368 } else {
369 // no relocation needed
370 x_ = reinterpret_cast<intptr_t>(obj);
371 rmode_ = RelocInfo::NONE32;
372 }
373}
374
375
376Immediate::Immediate(Smi* value) {
377 x_ = reinterpret_cast<intptr_t>(value);
378 rmode_ = RelocInfo::NONE32;
379}
380
381
382Immediate::Immediate(Address addr) {
383 x_ = reinterpret_cast<int32_t>(addr);
384 rmode_ = RelocInfo::NONE32;
385}
386
387
388void Assembler::emit(uint32_t x) {
389 *reinterpret_cast<uint32_t*>(pc_) = x;
390 pc_ += sizeof(uint32_t);
391}
392
393
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000394void Assembler::emit_q(uint64_t x) {
395 *reinterpret_cast<uint64_t*>(pc_) = x;
396 pc_ += sizeof(uint64_t);
397}
398
399
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000400void Assembler::emit(Handle<Object> handle) {
401 AllowDeferredHandleDereference heap_object_check;
402 // Verify all Objects referred by code are NOT in new space.
403 Object* obj = *handle;
404 DCHECK(!isolate()->heap()->InNewSpace(obj));
405 if (obj->IsHeapObject()) {
406 emit(reinterpret_cast<intptr_t>(handle.location()),
407 RelocInfo::EMBEDDED_OBJECT);
408 } else {
409 // no relocation needed
410 emit(reinterpret_cast<intptr_t>(obj));
411 }
412}
413
414
415void Assembler::emit(uint32_t x, RelocInfo::Mode rmode, TypeFeedbackId id) {
416 if (rmode == RelocInfo::CODE_TARGET && !id.IsNone()) {
417 RecordRelocInfo(RelocInfo::CODE_TARGET_WITH_ID, id.ToInt());
418 } else if (!RelocInfo::IsNone(rmode)
419 && rmode != RelocInfo::CODE_AGE_SEQUENCE) {
420 RecordRelocInfo(rmode);
421 }
422 emit(x);
423}
424
425
426void Assembler::emit(Handle<Code> code,
427 RelocInfo::Mode rmode,
428 TypeFeedbackId id) {
429 AllowDeferredHandleDereference embedding_raw_address;
430 emit(reinterpret_cast<intptr_t>(code.location()), rmode, id);
431}
432
433
434void Assembler::emit(const Immediate& x) {
435 if (x.rmode_ == RelocInfo::INTERNAL_REFERENCE) {
436 Label* label = reinterpret_cast<Label*>(x.x_);
437 emit_code_relative_offset(label);
438 return;
439 }
440 if (!RelocInfo::IsNone(x.rmode_)) RecordRelocInfo(x.rmode_);
441 emit(x.x_);
442}
443
444
445void Assembler::emit_code_relative_offset(Label* label) {
446 if (label->is_bound()) {
447 int32_t pos;
448 pos = label->pos() + Code::kHeaderSize - kHeapObjectTag;
449 emit(pos);
450 } else {
451 emit_disp(label, Displacement::CODE_RELATIVE);
452 }
453}
454
Ben Murdochda12d292016-06-02 14:46:10 +0100455void Assembler::emit_b(Immediate x) {
456 DCHECK(x.is_int8() || x.is_uint8());
457 uint8_t value = static_cast<uint8_t>(x.x_);
458 *pc_++ = value;
459}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000460
461void Assembler::emit_w(const Immediate& x) {
462 DCHECK(RelocInfo::IsNone(x.rmode_));
463 uint16_t value = static_cast<uint16_t>(x.x_);
464 reinterpret_cast<uint16_t*>(pc_)[0] = value;
465 pc_ += sizeof(uint16_t);
466}
467
468
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000469Address Assembler::target_address_at(Address pc, Address constant_pool) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000470 return pc + sizeof(int32_t) + *reinterpret_cast<int32_t*>(pc);
471}
472
473
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000474void Assembler::set_target_address_at(Isolate* isolate, Address pc,
475 Address constant_pool, Address target,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000476 ICacheFlushMode icache_flush_mode) {
477 int32_t* p = reinterpret_cast<int32_t*>(pc);
478 *p = target - (pc + sizeof(int32_t));
479 if (icache_flush_mode != SKIP_ICACHE_FLUSH) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000480 Assembler::FlushICache(isolate, p, sizeof(int32_t));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000481 }
482}
483
484
485Address Assembler::target_address_from_return_address(Address pc) {
486 return pc - kCallTargetAddressOffset;
487}
488
489
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000490Displacement Assembler::disp_at(Label* L) {
491 return Displacement(long_at(L->pos()));
492}
493
494
495void Assembler::disp_at_put(Label* L, Displacement disp) {
496 long_at_put(L->pos(), disp.data());
497}
498
499
500void Assembler::emit_disp(Label* L, Displacement::Type type) {
501 Displacement disp(L, type);
502 L->link_to(pc_offset());
503 emit(static_cast<int>(disp.data()));
504}
505
506
507void Assembler::emit_near_disp(Label* L) {
508 byte disp = 0x00;
509 if (L->is_near_linked()) {
510 int offset = L->near_link_pos() - pc_offset();
511 DCHECK(is_int8(offset));
512 disp = static_cast<byte>(offset & 0xFF);
513 }
514 L->link_to(pc_offset(), Label::kNear);
515 *pc_++ = disp;
516}
517
518
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000519void Assembler::deserialization_set_target_internal_reference_at(
520 Isolate* isolate, Address pc, Address target, RelocInfo::Mode mode) {
521 Memory::Address_at(pc) = target;
522}
523
524
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000525void Operand::set_modrm(int mod, Register rm) {
526 DCHECK((mod & -4) == 0);
527 buf_[0] = mod << 6 | rm.code();
528 len_ = 1;
529}
530
531
532void Operand::set_sib(ScaleFactor scale, Register index, Register base) {
533 DCHECK(len_ == 1);
534 DCHECK((scale & -4) == 0);
535 // Use SIB with no index register only for base esp.
536 DCHECK(!index.is(esp) || base.is(esp));
537 buf_[1] = scale << 6 | index.code() << 3 | base.code();
538 len_ = 2;
539}
540
541
542void Operand::set_disp8(int8_t disp) {
543 DCHECK(len_ == 1 || len_ == 2);
544 *reinterpret_cast<int8_t*>(&buf_[len_++]) = disp;
545}
546
547
548void Operand::set_dispr(int32_t disp, RelocInfo::Mode rmode) {
549 DCHECK(len_ == 1 || len_ == 2);
550 int32_t* p = reinterpret_cast<int32_t*>(&buf_[len_]);
551 *p = disp;
552 len_ += sizeof(int32_t);
553 rmode_ = rmode;
554}
555
556Operand::Operand(Register reg) {
557 // reg
558 set_modrm(3, reg);
559}
560
561
562Operand::Operand(int32_t disp, RelocInfo::Mode rmode) {
563 // [disp/r]
564 set_modrm(0, ebp);
565 set_dispr(disp, rmode);
566}
567
568
569Operand::Operand(Immediate imm) {
570 // [disp/r]
571 set_modrm(0, ebp);
572 set_dispr(imm.x_, imm.rmode_);
573}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000574} // namespace internal
575} // namespace v8
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000576
577#endif // V8_X87_ASSEMBLER_X87_INL_H_