blob: ba2a86405e1d963fc029a229e5e0e0689ebf0bf2 [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 Murdochb8a8cc12014-11-26 15:28:44 +000084Address 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
92Address RelocInfo::constant_pool_entry_address() {
93 UNREACHABLE();
94 return NULL;
95}
96
97
98int RelocInfo::target_address_size() {
99 return Assembler::kSpecialTargetSize;
100}
101
102
103void RelocInfo::set_target_address(Address target,
104 WriteBarrierMode write_barrier_mode,
105 ICacheFlushMode icache_flush_mode) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000106 Assembler::set_target_address_at(isolate_, pc_, host_, target,
107 icache_flush_mode);
108 Assembler::set_target_address_at(isolate_, pc_, host_, target);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000109 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 Murdochb8a8cc12014-11-26 15:28:44 +0000118Object* RelocInfo::target_object() {
119 DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
120 return Memory::Object_at(pc_);
121}
122
123
124Handle<Object> RelocInfo::target_object_handle(Assembler* origin) {
125 DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
126 return Memory::Object_Handle_at(pc_);
127}
128
129
130void 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 Murdoch4a90d5f2016-03-22 12:00:34 +0000136 Assembler::FlushICache(isolate_, pc_, sizeof(Address));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000137 }
138 if (write_barrier_mode == UPDATE_WRITE_BARRIER &&
139 host() != NULL &&
140 target->IsHeapObject()) {
Ben Murdochda12d292016-06-02 14:46:10 +0100141 host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(
142 host(), this, HeapObject::cast(target));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000143 }
144}
145
146
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000147Address RelocInfo::target_external_reference() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000148 DCHECK(rmode_ == RelocInfo::EXTERNAL_REFERENCE);
149 return Memory::Address_at(pc_);
150}
151
152
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000153Address RelocInfo::target_internal_reference() {
154 DCHECK(rmode_ == INTERNAL_REFERENCE);
155 return Memory::Address_at(pc_);
156}
157
158
159Address RelocInfo::target_internal_reference_address() {
160 DCHECK(rmode_ == INTERNAL_REFERENCE);
161 return reinterpret_cast<Address>(pc_);
162}
163
164
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000165Address RelocInfo::target_runtime_entry(Assembler* origin) {
166 DCHECK(IsRuntimeEntry(rmode_));
167 return reinterpret_cast<Address>(*reinterpret_cast<int32_t*>(pc_));
168}
169
170
171void 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
181Handle<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
188Cell* RelocInfo::target_cell() {
189 DCHECK(rmode_ == RelocInfo::CELL);
190 return Cell::FromValueAddress(Memory::Address_at(pc_));
191}
192
193
194void RelocInfo::set_target_cell(Cell* cell,
195 WriteBarrierMode write_barrier_mode,
196 ICacheFlushMode icache_flush_mode) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000197 DCHECK(cell->IsCell());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000198 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 Murdoch4a90d5f2016-03-22 12:00:34 +0000202 Assembler::FlushICache(isolate_, pc_, sizeof(Address));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000203 }
204 if (write_barrier_mode == UPDATE_WRITE_BARRIER && host() != NULL) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100205 host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(host(), this,
206 cell);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000207 }
208}
209
210
211Handle<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
218Code* 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
226void RelocInfo::set_code_age_stub(Code* stub,
227 ICacheFlushMode icache_flush_mode) {
228 DCHECK(*pc_ == kCallOpcode);
229 DCHECK(rmode_ == RelocInfo::CODE_AGE_SEQUENCE);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000230 Assembler::set_target_address_at(
231 isolate_, pc_ + 1, host_, stub->instruction_start(), icache_flush_mode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000232}
233
234
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000235Address RelocInfo::debug_call_address() {
236 DCHECK(IsDebugBreakSlot(rmode()) && IsPatchedDebugBreakSlotSequence());
237 Address location = pc_ + Assembler::kPatchDebugBreakSlotAddressOffset;
238 return Assembler::target_address_at(location, host_);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000239}
240
241
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000242void 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 Murdochb8a8cc12014-11-26 15:28:44 +0000246 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 Murdochb8a8cc12014-11-26 15:28:44 +0000254void RelocInfo::WipeOut() {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000255 if (IsEmbeddedObject(rmode_) || IsExternalReference(rmode_) ||
256 IsInternalReference(rmode_)) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000257 Memory::Address_at(pc_) = NULL;
258 } else if (IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)) {
259 // Effectively write zero into the relocation.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000260 Assembler::set_target_address_at(isolate_, pc_, host_,
261 pc_ + sizeof(int32_t));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000262 } else {
263 UNREACHABLE();
264 }
265}
266
Ben Murdochc5610432016-08-08 18:44:38 +0100267template <typename ObjectVisitor>
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000268void RelocInfo::Visit(Isolate* isolate, ObjectVisitor* visitor) {
269 RelocInfo::Mode mode = rmode();
270 if (mode == RelocInfo::EMBEDDED_OBJECT) {
271 visitor->VisitEmbeddedPointer(this);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000272 Assembler::FlushICache(isolate, pc_, sizeof(Address));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000273 } 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 Murdoch4a90d5f2016-03-22 12:00:34 +0000279 } else if (mode == RelocInfo::INTERNAL_REFERENCE) {
280 visitor->VisitInternalReference(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000281 } else if (RelocInfo::IsCodeAgeSequence(mode)) {
282 visitor->VisitCodeAgeSequence(this);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000283 } else if (RelocInfo::IsDebugBreakSlot(mode) &&
284 IsPatchedDebugBreakSlotSequence()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000285 visitor->VisitDebugTarget(this);
286 } else if (IsRuntimeEntry(mode)) {
287 visitor->VisitRuntimeEntry(this);
288 }
289}
290
291
292template<typename StaticVisitor>
293void RelocInfo::Visit(Heap* heap) {
294 RelocInfo::Mode mode = rmode();
295 if (mode == RelocInfo::EMBEDDED_OBJECT) {
296 StaticVisitor::VisitEmbeddedPointer(heap, this);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000297 Assembler::FlushICache(heap->isolate(), pc_, sizeof(Address));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000298 } 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 Murdoch4a90d5f2016-03-22 12:00:34 +0000304 } else if (mode == RelocInfo::INTERNAL_REFERENCE) {
305 StaticVisitor::VisitInternalReference(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000306 } else if (RelocInfo::IsCodeAgeSequence(mode)) {
307 StaticVisitor::VisitCodeAgeSequence(heap, this);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000308 } else if (RelocInfo::IsDebugBreakSlot(mode) &&
309 IsPatchedDebugBreakSlotSequence()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000310 StaticVisitor::VisitDebugTarget(heap, this);
311 } else if (IsRuntimeEntry(mode)) {
312 StaticVisitor::VisitRuntimeEntry(this);
313 }
314}
315
316
317
318Immediate::Immediate(int x) {
319 x_ = x;
320 rmode_ = RelocInfo::NONE32;
321}
322
Ben Murdochda12d292016-06-02 14:46:10 +0100323Immediate::Immediate(Address x, RelocInfo::Mode rmode) {
324 x_ = reinterpret_cast<int32_t>(x);
325 rmode_ = rmode;
326}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000327
328Immediate::Immediate(const ExternalReference& ext) {
329 x_ = reinterpret_cast<int32_t>(ext.address());
330 rmode_ = RelocInfo::EXTERNAL_REFERENCE;
331}
332
333
334Immediate::Immediate(Label* internal_offset) {
335 x_ = reinterpret_cast<int32_t>(internal_offset);
336 rmode_ = RelocInfo::INTERNAL_REFERENCE;
337}
338
339
340Immediate::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
356Immediate::Immediate(Smi* value) {
357 x_ = reinterpret_cast<intptr_t>(value);
358 rmode_ = RelocInfo::NONE32;
359}
360
361
362Immediate::Immediate(Address addr) {
363 x_ = reinterpret_cast<int32_t>(addr);
364 rmode_ = RelocInfo::NONE32;
365}
366
367
368void Assembler::emit(uint32_t x) {
369 *reinterpret_cast<uint32_t*>(pc_) = x;
370 pc_ += sizeof(uint32_t);
371}
372
373
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000374void Assembler::emit_q(uint64_t x) {
375 *reinterpret_cast<uint64_t*>(pc_) = x;
376 pc_ += sizeof(uint64_t);
377}
378
379
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000380void 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
395void 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
406void 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
414void 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
425void 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 Murdochda12d292016-06-02 14:46:10 +0100435void 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 Murdochb8a8cc12014-11-26 15:28:44 +0000440
441void 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 Murdoch4a90d5f2016-03-22 12:00:34 +0000449Address Assembler::target_address_at(Address pc, Address constant_pool) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000450 return pc + sizeof(int32_t) + *reinterpret_cast<int32_t*>(pc);
451}
452
453
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000454void Assembler::set_target_address_at(Isolate* isolate, Address pc,
455 Address constant_pool, Address target,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000456 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 Murdoch4a90d5f2016-03-22 12:00:34 +0000460 Assembler::FlushICache(isolate, p, sizeof(int32_t));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000461 }
462}
463
464
465Address Assembler::target_address_from_return_address(Address pc) {
466 return pc - kCallTargetAddressOffset;
467}
468
469
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000470Displacement Assembler::disp_at(Label* L) {
471 return Displacement(long_at(L->pos()));
472}
473
474
475void Assembler::disp_at_put(Label* L, Displacement disp) {
476 long_at_put(L->pos(), disp.data());
477}
478
479
480void 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
487void 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 Murdoch4a90d5f2016-03-22 12:00:34 +0000499void 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 Murdochb8a8cc12014-11-26 15:28:44 +0000505void 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
512void 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
522void Operand::set_disp8(int8_t disp) {
523 DCHECK(len_ == 1 || len_ == 2);
524 *reinterpret_cast<int8_t*>(&buf_[len_++]) = disp;
525}
526
527
528void 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
536Operand::Operand(Register reg) {
537 // reg
538 set_modrm(3, reg);
539}
540
541
542Operand::Operand(int32_t disp, RelocInfo::Mode rmode) {
543 // [disp/r]
544 set_modrm(0, ebp);
545 set_dispr(disp, rmode);
546}
547
548
549Operand::Operand(Immediate imm) {
550 // [disp/r]
551 set_modrm(0, ebp);
552 set_dispr(imm.x_, imm.rmode_);
553}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000554} // namespace internal
555} // namespace v8
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000556
557#endif // V8_X87_ASSEMBLER_X87_INL_H_