blob: a9cc2ef28740f4b91f8331fc503b9cf27f70a5d8 [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2012 the V8 project authors. All rights reserved.
Steve Blocka7e24c12009-10-30 11:49:00 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#ifndef V8_X64_ASSEMBLER_X64_INL_H_
29#define V8_X64_ASSEMBLER_X64_INL_H_
30
Ben Murdoch3ef787d2012-04-12 10:51:47 +010031#include "x64/assembler-x64.h"
32
Steve Blocka7e24c12009-10-30 11:49:00 +000033#include "cpu.h"
Leon Clarkef7060e22010-06-03 12:02:55 +010034#include "debug.h"
Steve Block44f0eee2011-05-26 01:26:41 +010035#include "v8memory.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000036
37namespace v8 {
38namespace internal {
39
Steve Blocka7e24c12009-10-30 11:49:00 +000040
41// -----------------------------------------------------------------------------
42// Implementation of Assembler
43
44
Steve Blocka7e24c12009-10-30 11:49:00 +000045void Assembler::emitl(uint32_t x) {
46 Memory::uint32_at(pc_) = x;
47 pc_ += sizeof(uint32_t);
48}
49
50
51void Assembler::emitq(uint64_t x, RelocInfo::Mode rmode) {
52 Memory::uint64_at(pc_) = x;
53 if (rmode != RelocInfo::NONE) {
54 RecordRelocInfo(rmode, x);
55 }
56 pc_ += sizeof(uint64_t);
57}
58
59
60void Assembler::emitw(uint16_t x) {
61 Memory::uint16_at(pc_) = x;
62 pc_ += sizeof(uint16_t);
63}
64
65
Ben Murdoch257744e2011-11-30 15:57:28 +000066void Assembler::emit_code_target(Handle<Code> target,
67 RelocInfo::Mode rmode,
68 unsigned ast_id) {
Steve Block3ce2e202009-11-05 08:53:23 +000069 ASSERT(RelocInfo::IsCodeTarget(rmode));
Ben Murdoch257744e2011-11-30 15:57:28 +000070 if (rmode == RelocInfo::CODE_TARGET && ast_id != kNoASTId) {
71 RecordRelocInfo(RelocInfo::CODE_TARGET_WITH_ID, ast_id);
72 } else {
73 RecordRelocInfo(rmode);
74 }
Steve Block3ce2e202009-11-05 08:53:23 +000075 int current = code_targets_.length();
76 if (current > 0 && code_targets_.last().is_identical_to(target)) {
77 // Optimization if we keep jumping to the same code target.
78 emitl(current - 1);
79 } else {
80 code_targets_.Add(target);
81 emitl(current);
82 }
83}
84
85
Steve Blocka7e24c12009-10-30 11:49:00 +000086void Assembler::emit_rex_64(Register reg, Register rm_reg) {
87 emit(0x48 | reg.high_bit() << 2 | rm_reg.high_bit());
88}
89
90
91void Assembler::emit_rex_64(XMMRegister reg, Register rm_reg) {
92 emit(0x48 | (reg.code() & 0x8) >> 1 | rm_reg.code() >> 3);
93}
94
95
Steve Block6ded16b2010-05-10 14:33:55 +010096void Assembler::emit_rex_64(Register reg, XMMRegister rm_reg) {
97 emit(0x48 | (reg.code() & 0x8) >> 1 | rm_reg.code() >> 3);
98}
99
100
Steve Blocka7e24c12009-10-30 11:49:00 +0000101void Assembler::emit_rex_64(Register reg, const Operand& op) {
102 emit(0x48 | reg.high_bit() << 2 | op.rex_);
103}
104
105
106void Assembler::emit_rex_64(XMMRegister reg, const Operand& op) {
107 emit(0x48 | (reg.code() & 0x8) >> 1 | op.rex_);
108}
109
110
111void Assembler::emit_rex_64(Register rm_reg) {
112 ASSERT_EQ(rm_reg.code() & 0xf, rm_reg.code());
113 emit(0x48 | rm_reg.high_bit());
114}
115
116
117void Assembler::emit_rex_64(const Operand& op) {
118 emit(0x48 | op.rex_);
119}
120
121
122void Assembler::emit_rex_32(Register reg, Register rm_reg) {
123 emit(0x40 | reg.high_bit() << 2 | rm_reg.high_bit());
124}
125
126
127void Assembler::emit_rex_32(Register reg, const Operand& op) {
128 emit(0x40 | reg.high_bit() << 2 | op.rex_);
129}
130
131
132void Assembler::emit_rex_32(Register rm_reg) {
133 emit(0x40 | rm_reg.high_bit());
134}
135
136
137void Assembler::emit_rex_32(const Operand& op) {
138 emit(0x40 | op.rex_);
139}
140
141
142void Assembler::emit_optional_rex_32(Register reg, Register rm_reg) {
143 byte rex_bits = reg.high_bit() << 2 | rm_reg.high_bit();
144 if (rex_bits != 0) emit(0x40 | rex_bits);
145}
146
147
148void Assembler::emit_optional_rex_32(Register reg, const Operand& op) {
149 byte rex_bits = reg.high_bit() << 2 | op.rex_;
150 if (rex_bits != 0) emit(0x40 | rex_bits);
151}
152
153
154void Assembler::emit_optional_rex_32(XMMRegister reg, const Operand& op) {
155 byte rex_bits = (reg.code() & 0x8) >> 1 | op.rex_;
156 if (rex_bits != 0) emit(0x40 | rex_bits);
157}
158
159
160void Assembler::emit_optional_rex_32(XMMRegister reg, XMMRegister base) {
161 byte rex_bits = (reg.code() & 0x8) >> 1 | (base.code() & 0x8) >> 3;
162 if (rex_bits != 0) emit(0x40 | rex_bits);
163}
164
165
166void Assembler::emit_optional_rex_32(XMMRegister reg, Register base) {
167 byte rex_bits = (reg.code() & 0x8) >> 1 | (base.code() & 0x8) >> 3;
168 if (rex_bits != 0) emit(0x40 | rex_bits);
169}
170
171
Steve Block6ded16b2010-05-10 14:33:55 +0100172void Assembler::emit_optional_rex_32(Register reg, XMMRegister base) {
173 byte rex_bits = (reg.code() & 0x8) >> 1 | (base.code() & 0x8) >> 3;
174 if (rex_bits != 0) emit(0x40 | rex_bits);
175}
176
177
Steve Blocka7e24c12009-10-30 11:49:00 +0000178void Assembler::emit_optional_rex_32(Register rm_reg) {
179 if (rm_reg.high_bit()) emit(0x41);
180}
181
182
183void Assembler::emit_optional_rex_32(const Operand& op) {
184 if (op.rex_ != 0) emit(0x40 | op.rex_);
185}
186
187
188Address Assembler::target_address_at(Address pc) {
Steve Block3ce2e202009-11-05 08:53:23 +0000189 return Memory::int32_at(pc) + pc + 4;
Steve Blocka7e24c12009-10-30 11:49:00 +0000190}
191
192
193void Assembler::set_target_address_at(Address pc, Address target) {
Steve Blockd0582a62009-12-15 09:54:21 +0000194 Memory::int32_at(pc) = static_cast<int32_t>(target - pc - 4);
Steve Block3ce2e202009-11-05 08:53:23 +0000195 CPU::FlushICache(pc, sizeof(int32_t));
Steve Blocka7e24c12009-10-30 11:49:00 +0000196}
197
Steve Block3ce2e202009-11-05 08:53:23 +0000198Handle<Object> Assembler::code_target_object_handle_at(Address pc) {
199 return code_targets_[Memory::int32_at(pc)];
200}
Steve Blocka7e24c12009-10-30 11:49:00 +0000201
202// -----------------------------------------------------------------------------
203// Implementation of RelocInfo
204
205// The modes possibly affected by apply must be in kApplyMask.
206void RelocInfo::apply(intptr_t delta) {
207 if (IsInternalReference(rmode_)) {
208 // absolute code pointer inside code object moves with the code object.
Steve Blockd0582a62009-12-15 09:54:21 +0000209 Memory::Address_at(pc_) += static_cast<int32_t>(delta);
Steve Block1e0659c2011-05-24 12:43:12 +0100210 CPU::FlushICache(pc_, sizeof(Address));
Steve Block3ce2e202009-11-05 08:53:23 +0000211 } else if (IsCodeTarget(rmode_)) {
Steve Blockd0582a62009-12-15 09:54:21 +0000212 Memory::int32_at(pc_) -= static_cast<int32_t>(delta);
Steve Block1e0659c2011-05-24 12:43:12 +0100213 CPU::FlushICache(pc_, sizeof(int32_t));
Steve Blocka7e24c12009-10-30 11:49:00 +0000214 }
215}
216
217
218Address RelocInfo::target_address() {
219 ASSERT(IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY);
Steve Block3ce2e202009-11-05 08:53:23 +0000220 if (IsCodeTarget(rmode_)) {
221 return Assembler::target_address_at(pc_);
222 } else {
223 return Memory::Address_at(pc_);
224 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000225}
226
227
228Address RelocInfo::target_address_address() {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100229 ASSERT(IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY
230 || rmode_ == EMBEDDED_OBJECT
231 || rmode_ == EXTERNAL_REFERENCE);
Steve Blocka7e24c12009-10-30 11:49:00 +0000232 return reinterpret_cast<Address>(pc_);
233}
234
235
Leon Clarkef7060e22010-06-03 12:02:55 +0100236int RelocInfo::target_address_size() {
237 if (IsCodedSpecially()) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100238 return Assembler::kSpecialTargetSize;
Leon Clarkef7060e22010-06-03 12:02:55 +0100239 } else {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100240 return kPointerSize;
Leon Clarkef7060e22010-06-03 12:02:55 +0100241 }
242}
243
244
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100245void RelocInfo::set_target_address(Address target, WriteBarrierMode mode) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000246 ASSERT(IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY);
Steve Block3ce2e202009-11-05 08:53:23 +0000247 if (IsCodeTarget(rmode_)) {
248 Assembler::set_target_address_at(pc_, target);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100249 Object* target_code = Code::GetCodeFromTargetAddress(target);
250 if (mode == UPDATE_WRITE_BARRIER && host() != NULL) {
251 host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(
252 host(), this, HeapObject::cast(target_code));
253 }
Steve Block3ce2e202009-11-05 08:53:23 +0000254 } else {
255 Memory::Address_at(pc_) = target;
Steve Block1e0659c2011-05-24 12:43:12 +0100256 CPU::FlushICache(pc_, sizeof(Address));
Steve Block3ce2e202009-11-05 08:53:23 +0000257 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000258}
259
260
261Object* RelocInfo::target_object() {
262 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
Steve Block3ce2e202009-11-05 08:53:23 +0000263 return Memory::Object_at(pc_);
264}
265
266
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100267Handle<Object> RelocInfo::target_object_handle(Assembler* origin) {
Steve Block3ce2e202009-11-05 08:53:23 +0000268 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
269 if (rmode_ == EMBEDDED_OBJECT) {
270 return Memory::Object_Handle_at(pc_);
271 } else {
272 return origin->code_target_object_handle_at(pc_);
273 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000274}
275
276
277Object** RelocInfo::target_object_address() {
278 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
279 return reinterpret_cast<Object**>(pc_);
280}
281
282
283Address* RelocInfo::target_reference_address() {
284 ASSERT(rmode_ == RelocInfo::EXTERNAL_REFERENCE);
285 return reinterpret_cast<Address*>(pc_);
286}
287
288
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100289void RelocInfo::set_target_object(Object* target, WriteBarrierMode mode) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000290 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100291 Memory::Object_at(pc_) = target;
Steve Block1e0659c2011-05-24 12:43:12 +0100292 CPU::FlushICache(pc_, sizeof(Address));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100293 if (mode == UPDATE_WRITE_BARRIER &&
294 host() != NULL &&
295 target->IsHeapObject()) {
296 host()->GetHeap()->incremental_marking()->RecordWrite(
297 host(), &Memory::Object_at(pc_), HeapObject::cast(target));
298 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000299}
300
301
Ben Murdochb0fe1622011-05-05 13:52:32 +0100302Handle<JSGlobalPropertyCell> RelocInfo::target_cell_handle() {
303 ASSERT(rmode_ == RelocInfo::GLOBAL_PROPERTY_CELL);
304 Address address = Memory::Address_at(pc_);
305 return Handle<JSGlobalPropertyCell>(
306 reinterpret_cast<JSGlobalPropertyCell**>(address));
307}
308
309
310JSGlobalPropertyCell* RelocInfo::target_cell() {
311 ASSERT(rmode_ == RelocInfo::GLOBAL_PROPERTY_CELL);
312 Address address = Memory::Address_at(pc_);
313 Object* object = HeapObject::FromAddress(
314 address - JSGlobalPropertyCell::kValueOffset);
315 return reinterpret_cast<JSGlobalPropertyCell*>(object);
316}
317
318
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100319void RelocInfo::set_target_cell(JSGlobalPropertyCell* cell,
320 WriteBarrierMode mode) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100321 ASSERT(rmode_ == RelocInfo::GLOBAL_PROPERTY_CELL);
322 Address address = cell->address() + JSGlobalPropertyCell::kValueOffset;
323 Memory::Address_at(pc_) = address;
Steve Block1e0659c2011-05-24 12:43:12 +0100324 CPU::FlushICache(pc_, sizeof(Address));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100325 if (mode == UPDATE_WRITE_BARRIER &&
326 host() != NULL) {
327 // TODO(1550) We are passing NULL as a slot because cell can never be on
328 // evacuation candidate.
329 host()->GetHeap()->incremental_marking()->RecordWrite(
330 host(), NULL, cell);
331 }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100332}
333
334
Steve Block3ce2e202009-11-05 08:53:23 +0000335bool RelocInfo::IsPatchedReturnSequence() {
Steve Blocka7e24c12009-10-30 11:49:00 +0000336 // The recognized call sequence is:
337 // movq(kScratchRegister, immediate64); call(kScratchRegister);
338 // It only needs to be distinguished from a return sequence
339 // movq(rsp, rbp); pop(rbp); ret(n); int3 *6
340 // The 11th byte is int3 (0xCC) in the return sequence and
341 // REX.WB (0x48+register bit) for the call sequence.
Steve Block3ce2e202009-11-05 08:53:23 +0000342#ifdef ENABLE_DEBUGGER_SUPPORT
Steve Blocka7e24c12009-10-30 11:49:00 +0000343 return pc_[10] != 0xCC;
Steve Block3ce2e202009-11-05 08:53:23 +0000344#else
345 return false;
346#endif
Steve Blocka7e24c12009-10-30 11:49:00 +0000347}
348
349
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100350bool RelocInfo::IsPatchedDebugBreakSlotSequence() {
351 return !Assembler::IsNop(pc());
352}
353
354
Steve Blocka7e24c12009-10-30 11:49:00 +0000355Address RelocInfo::call_address() {
Ben Murdochbb769b22010-08-11 14:56:33 +0100356 ASSERT((IsJSReturn(rmode()) && IsPatchedReturnSequence()) ||
357 (IsDebugBreakSlot(rmode()) && IsPatchedDebugBreakSlotSequence()));
Steve Block3ce2e202009-11-05 08:53:23 +0000358 return Memory::Address_at(
359 pc_ + Assembler::kRealPatchReturnSequenceAddressOffset);
Steve Blocka7e24c12009-10-30 11:49:00 +0000360}
361
362
363void RelocInfo::set_call_address(Address target) {
Ben Murdochbb769b22010-08-11 14:56:33 +0100364 ASSERT((IsJSReturn(rmode()) && IsPatchedReturnSequence()) ||
365 (IsDebugBreakSlot(rmode()) && IsPatchedDebugBreakSlotSequence()));
Steve Block3ce2e202009-11-05 08:53:23 +0000366 Memory::Address_at(pc_ + Assembler::kRealPatchReturnSequenceAddressOffset) =
367 target;
Steve Block1e0659c2011-05-24 12:43:12 +0100368 CPU::FlushICache(pc_ + Assembler::kRealPatchReturnSequenceAddressOffset,
369 sizeof(Address));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100370 if (host() != NULL) {
371 Object* target_code = Code::GetCodeFromTargetAddress(target);
372 host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(
373 host(), this, HeapObject::cast(target_code));
374 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000375}
376
377
378Object* RelocInfo::call_object() {
Steve Blocka7e24c12009-10-30 11:49:00 +0000379 return *call_object_address();
380}
381
382
383void RelocInfo::set_call_object(Object* target) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000384 *call_object_address() = target;
385}
386
387
388Object** RelocInfo::call_object_address() {
Ben Murdochbb769b22010-08-11 14:56:33 +0100389 ASSERT((IsJSReturn(rmode()) && IsPatchedReturnSequence()) ||
390 (IsDebugBreakSlot(rmode()) && IsPatchedDebugBreakSlotSequence()));
Steve Blocka7e24c12009-10-30 11:49:00 +0000391 return reinterpret_cast<Object**>(
392 pc_ + Assembler::kPatchReturnSequenceAddressOffset);
393}
394
Leon Clarkef7060e22010-06-03 12:02:55 +0100395
396void RelocInfo::Visit(ObjectVisitor* visitor) {
397 RelocInfo::Mode mode = rmode();
398 if (mode == RelocInfo::EMBEDDED_OBJECT) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100399 visitor->VisitEmbeddedPointer(this);
Steve Block1e0659c2011-05-24 12:43:12 +0100400 CPU::FlushICache(pc_, sizeof(Address));
Leon Clarkef7060e22010-06-03 12:02:55 +0100401 } else if (RelocInfo::IsCodeTarget(mode)) {
402 visitor->VisitCodeTarget(this);
Steve Block1e0659c2011-05-24 12:43:12 +0100403 } else if (mode == RelocInfo::GLOBAL_PROPERTY_CELL) {
404 visitor->VisitGlobalPropertyCell(this);
Leon Clarkef7060e22010-06-03 12:02:55 +0100405 } else if (mode == RelocInfo::EXTERNAL_REFERENCE) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100406 visitor->VisitExternalReference(this);
Steve Block1e0659c2011-05-24 12:43:12 +0100407 CPU::FlushICache(pc_, sizeof(Address));
Leon Clarkef7060e22010-06-03 12:02:55 +0100408#ifdef ENABLE_DEBUGGER_SUPPORT
Steve Block44f0eee2011-05-26 01:26:41 +0100409 // TODO(isolates): Get a cached isolate below.
410 } else if (((RelocInfo::IsJSReturn(mode) &&
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100411 IsPatchedReturnSequence()) ||
412 (RelocInfo::IsDebugBreakSlot(mode) &&
Steve Block44f0eee2011-05-26 01:26:41 +0100413 IsPatchedDebugBreakSlotSequence())) &&
414 Isolate::Current()->debug()->has_break_points()) {
Leon Clarkef7060e22010-06-03 12:02:55 +0100415 visitor->VisitDebugTarget(this);
416#endif
417 } else if (mode == RelocInfo::RUNTIME_ENTRY) {
418 visitor->VisitRuntimeEntry(this);
419 }
420}
421
422
Iain Merrick75681382010-08-19 15:07:18 +0100423template<typename StaticVisitor>
Steve Block44f0eee2011-05-26 01:26:41 +0100424void RelocInfo::Visit(Heap* heap) {
Iain Merrick75681382010-08-19 15:07:18 +0100425 RelocInfo::Mode mode = rmode();
426 if (mode == RelocInfo::EMBEDDED_OBJECT) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100427 StaticVisitor::VisitEmbeddedPointer(heap, this);
Steve Block1e0659c2011-05-24 12:43:12 +0100428 CPU::FlushICache(pc_, sizeof(Address));
Iain Merrick75681382010-08-19 15:07:18 +0100429 } else if (RelocInfo::IsCodeTarget(mode)) {
Ben Murdoch8b112d22011-06-08 16:22:53 +0100430 StaticVisitor::VisitCodeTarget(heap, this);
Steve Block1e0659c2011-05-24 12:43:12 +0100431 } else if (mode == RelocInfo::GLOBAL_PROPERTY_CELL) {
Ben Murdoch8b112d22011-06-08 16:22:53 +0100432 StaticVisitor::VisitGlobalPropertyCell(heap, this);
Iain Merrick75681382010-08-19 15:07:18 +0100433 } else if (mode == RelocInfo::EXTERNAL_REFERENCE) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100434 StaticVisitor::VisitExternalReference(this);
Steve Block1e0659c2011-05-24 12:43:12 +0100435 CPU::FlushICache(pc_, sizeof(Address));
Iain Merrick75681382010-08-19 15:07:18 +0100436#ifdef ENABLE_DEBUGGER_SUPPORT
Steve Block44f0eee2011-05-26 01:26:41 +0100437 } else if (heap->isolate()->debug()->has_break_points() &&
Iain Merrick75681382010-08-19 15:07:18 +0100438 ((RelocInfo::IsJSReturn(mode) &&
439 IsPatchedReturnSequence()) ||
440 (RelocInfo::IsDebugBreakSlot(mode) &&
441 IsPatchedDebugBreakSlotSequence()))) {
Ben Murdoch8b112d22011-06-08 16:22:53 +0100442 StaticVisitor::VisitDebugTarget(heap, this);
Iain Merrick75681382010-08-19 15:07:18 +0100443#endif
444 } else if (mode == RelocInfo::RUNTIME_ENTRY) {
445 StaticVisitor::VisitRuntimeEntry(this);
446 }
447}
448
449
Steve Blocka7e24c12009-10-30 11:49:00 +0000450// -----------------------------------------------------------------------------
451// Implementation of Operand
452
453void Operand::set_modrm(int mod, Register rm_reg) {
454 ASSERT(is_uint2(mod));
455 buf_[0] = mod << 6 | rm_reg.low_bits();
456 // Set REX.B to the high bit of rm.code().
457 rex_ |= rm_reg.high_bit();
458}
459
460
461void Operand::set_sib(ScaleFactor scale, Register index, Register base) {
462 ASSERT(len_ == 1);
463 ASSERT(is_uint2(scale));
464 // Use SIB with no index register only for base rsp or r12. Otherwise we
465 // would skip the SIB byte entirely.
466 ASSERT(!index.is(rsp) || base.is(rsp) || base.is(r12));
Steve Block1e0659c2011-05-24 12:43:12 +0100467 buf_[1] = (scale << 6) | (index.low_bits() << 3) | base.low_bits();
Steve Blocka7e24c12009-10-30 11:49:00 +0000468 rex_ |= index.high_bit() << 1 | base.high_bit();
469 len_ = 2;
470}
471
472void Operand::set_disp8(int disp) {
473 ASSERT(is_int8(disp));
474 ASSERT(len_ == 1 || len_ == 2);
475 int8_t* p = reinterpret_cast<int8_t*>(&buf_[len_]);
476 *p = disp;
477 len_ += sizeof(int8_t);
478}
479
480void Operand::set_disp32(int disp) {
481 ASSERT(len_ == 1 || len_ == 2);
482 int32_t* p = reinterpret_cast<int32_t*>(&buf_[len_]);
483 *p = disp;
484 len_ += sizeof(int32_t);
485}
486
487
488} } // namespace v8::internal
489
490#endif // V8_X64_ASSEMBLER_X64_INL_H_