blob: 5e27f4545baf8e7d8118db7b96458ac133b5bb0d [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001
Andrei Popescu31002712010-02-23 13:46:05 +00002// Copyright (c) 1994-2006 Sun Microsystems Inc.
3// All Rights Reserved.
4//
5// Redistribution and use in source and binary forms, with or without
6// modification, are permitted provided that the following conditions are
7// met:
8//
9// - Redistributions of source code must retain the above copyright notice,
10// this list of conditions and the following disclaimer.
11//
12// - Redistribution in binary form must reproduce the above copyright
13// notice, this list of conditions and the following disclaimer in the
14// documentation and/or other materials provided with the 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.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32// The original source code covered by the above license above has been
33// modified significantly by Google Inc.
Ben Murdoch3ef787d2012-04-12 10:51:47 +010034// Copyright 2012 the V8 project authors. All rights reserved.
Andrei Popescu31002712010-02-23 13:46:05 +000035
36
37#ifndef V8_MIPS_ASSEMBLER_MIPS_INL_H_
38#define V8_MIPS_ASSEMBLER_MIPS_INL_H_
39
Ben Murdochb8a8cc12014-11-26 15:28:44 +000040#include "src/mips/assembler-mips.h"
Ben Murdoch3ef787d2012-04-12 10:51:47 +010041
Ben Murdochb8a8cc12014-11-26 15:28:44 +000042#include "src/assembler.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000043#include "src/debug/debug.h"
Andrei Popescu31002712010-02-23 13:46:05 +000044
45
46namespace v8 {
47namespace internal {
48
Ben Murdochb8a8cc12014-11-26 15:28:44 +000049
50bool CpuFeatures::SupportsCrankshaft() { return IsSupported(FPU); }
51
52
Andrei Popescu31002712010-02-23 13:46:05 +000053// -----------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +000054// Operand and MemOperand.
Andrei Popescu31002712010-02-23 13:46:05 +000055
56Operand::Operand(int32_t immediate, RelocInfo::Mode rmode) {
57 rm_ = no_reg;
58 imm32_ = immediate;
59 rmode_ = rmode;
60}
61
Steve Block44f0eee2011-05-26 01:26:41 +010062
Andrei Popescu31002712010-02-23 13:46:05 +000063Operand::Operand(const ExternalReference& f) {
64 rm_ = no_reg;
65 imm32_ = reinterpret_cast<int32_t>(f.address());
66 rmode_ = RelocInfo::EXTERNAL_REFERENCE;
67}
68
Andrei Popescu31002712010-02-23 13:46:05 +000069
70Operand::Operand(Smi* value) {
71 rm_ = no_reg;
72 imm32_ = reinterpret_cast<intptr_t>(value);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000073 rmode_ = RelocInfo::NONE32;
Andrei Popescu31002712010-02-23 13:46:05 +000074}
75
Steve Block44f0eee2011-05-26 01:26:41 +010076
Andrei Popescu31002712010-02-23 13:46:05 +000077Operand::Operand(Register rm) {
78 rm_ = rm;
79}
80
Steve Block44f0eee2011-05-26 01:26:41 +010081
Andrei Popescu31002712010-02-23 13:46:05 +000082bool Operand::is_reg() const {
83 return rm_.is_valid();
84}
85
86
Andrei Popescu31002712010-02-23 13:46:05 +000087// -----------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +000088// RelocInfo.
Andrei Popescu31002712010-02-23 13:46:05 +000089
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000090void RelocInfo::apply(intptr_t delta) {
91 if (IsInternalReference(rmode_) || IsInternalReferenceEncoded(rmode_)) {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000092 // Absolute code pointer inside code object moves with the code object.
93 byte* p = reinterpret_cast<byte*>(pc_);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000094 int count = Assembler::RelocateInternalReference(rmode_, p, delta);
95 Assembler::FlushICache(isolate_, p, count * sizeof(uint32_t));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000096 }
Andrei Popescu31002712010-02-23 13:46:05 +000097}
98
99
100Address RelocInfo::target_address() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000101 DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_));
102 return Assembler::target_address_at(pc_, host_);
Andrei Popescu31002712010-02-23 13:46:05 +0000103}
104
105
106Address RelocInfo::target_address_address() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000107 DCHECK(IsCodeTarget(rmode_) ||
108 IsRuntimeEntry(rmode_) ||
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100109 rmode_ == EMBEDDED_OBJECT ||
110 rmode_ == EXTERNAL_REFERENCE);
111 // Read the address of the word containing the target_address in an
112 // instruction stream.
113 // The only architecture-independent user of this function is the serializer.
114 // The serializer uses it to find out how many raw bytes of instruction to
115 // output before the next target.
116 // For an instruction like LUI/ORI where the target bits are mixed into the
117 // instruction bits, the size of the target will be zero, indicating that the
118 // serializer should not step forward in memory after a target is resolved
119 // and written. In this case the target_address_address function should
120 // return the end of the instructions to be patched, allowing the
121 // deserializer to deserialize the instructions as raw bytes and put them in
122 // place, ready to be patched with the target. After jump optimization,
123 // that is the address of the instruction that follows J/JAL/JR/JALR
124 // instruction.
125 return reinterpret_cast<Address>(
126 pc_ + Assembler::kInstructionsFor32BitConstant * Assembler::kInstrSize);
Steve Block44f0eee2011-05-26 01:26:41 +0100127}
128
129
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000130Address RelocInfo::constant_pool_entry_address() {
131 UNREACHABLE();
132 return NULL;
133}
134
135
Steve Block44f0eee2011-05-26 01:26:41 +0100136int RelocInfo::target_address_size() {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100137 return Assembler::kSpecialTargetSize;
Andrei Popescu31002712010-02-23 13:46:05 +0000138}
139
140
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000141void RelocInfo::set_target_address(Address target,
142 WriteBarrierMode write_barrier_mode,
143 ICacheFlushMode icache_flush_mode) {
144 DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000145 Assembler::set_target_address_at(isolate_, pc_, host_, target,
146 icache_flush_mode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000147 if (write_barrier_mode == UPDATE_WRITE_BARRIER &&
148 host() != NULL && IsCodeTarget(rmode_)) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100149 Object* target_code = Code::GetCodeFromTargetAddress(target);
150 host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(
151 host(), this, HeapObject::cast(target_code));
152 }
Andrei Popescu31002712010-02-23 13:46:05 +0000153}
154
155
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000156Address Assembler::target_address_from_return_address(Address pc) {
157 return pc - kCallTargetAddressOffset;
158}
159
160
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000161void Assembler::set_target_internal_reference_encoded_at(Address pc,
162 Address target) {
163 // Encoded internal references are lui/ori load of 32-bit abolute address.
164 Instr instr_lui = Assembler::instr_at(pc + 0 * Assembler::kInstrSize);
165 Instr instr_ori = Assembler::instr_at(pc + 1 * Assembler::kInstrSize);
166 DCHECK(Assembler::IsLui(instr_lui));
167 DCHECK(Assembler::IsOri(instr_ori));
168 instr_lui &= ~kImm16Mask;
169 instr_ori &= ~kImm16Mask;
170 int32_t imm = reinterpret_cast<int32_t>(target);
171 DCHECK((imm & 3) == 0);
172 Assembler::instr_at_put(pc + 0 * Assembler::kInstrSize,
173 instr_lui | ((imm >> kLuiShift) & kImm16Mask));
174 Assembler::instr_at_put(pc + 1 * Assembler::kInstrSize,
175 instr_ori | (imm & kImm16Mask));
176
177 // Currently used only by deserializer, and all code will be flushed
178 // after complete deserialization, no need to flush on each reference.
179}
180
181
182void Assembler::deserialization_set_target_internal_reference_at(
183 Isolate* isolate, Address pc, Address target, RelocInfo::Mode mode) {
184 if (mode == RelocInfo::INTERNAL_REFERENCE_ENCODED) {
185 DCHECK(IsLui(instr_at(pc)));
186 set_target_internal_reference_encoded_at(pc, target);
187 } else {
188 DCHECK(mode == RelocInfo::INTERNAL_REFERENCE);
189 Memory::Address_at(pc) = target;
190 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000191}
192
193
Andrei Popescu31002712010-02-23 13:46:05 +0000194Object* RelocInfo::target_object() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000195 DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
196 return reinterpret_cast<Object*>(Assembler::target_address_at(pc_, host_));
Andrei Popescu31002712010-02-23 13:46:05 +0000197}
198
199
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100200Handle<Object> RelocInfo::target_object_handle(Assembler* origin) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000201 DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
Andrei Popescu31002712010-02-23 13:46:05 +0000202 return Handle<Object>(reinterpret_cast<Object**>(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000203 Assembler::target_address_at(pc_, host_)));
Andrei Popescu31002712010-02-23 13:46:05 +0000204}
205
206
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000207void RelocInfo::set_target_object(Object* target,
208 WriteBarrierMode write_barrier_mode,
209 ICacheFlushMode icache_flush_mode) {
210 DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000211 Assembler::set_target_address_at(isolate_, pc_, host_,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000212 reinterpret_cast<Address>(target),
213 icache_flush_mode);
214 if (write_barrier_mode == UPDATE_WRITE_BARRIER &&
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100215 host() != NULL &&
216 target->IsHeapObject()) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100217 host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(
218 host(), this, HeapObject::cast(target));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100219 }
Andrei Popescu31002712010-02-23 13:46:05 +0000220}
221
222
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000223Address RelocInfo::target_external_reference() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000224 DCHECK(rmode_ == EXTERNAL_REFERENCE);
225 return Assembler::target_address_at(pc_, host_);
Steve Block44f0eee2011-05-26 01:26:41 +0100226}
227
228
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000229Address RelocInfo::target_internal_reference() {
230 if (rmode_ == INTERNAL_REFERENCE) {
231 return Memory::Address_at(pc_);
232 } else {
233 // Encoded internal references are lui/ori load of 32-bit abolute address.
234 DCHECK(rmode_ == INTERNAL_REFERENCE_ENCODED);
235 Instr instr_lui = Assembler::instr_at(pc_ + 0 * Assembler::kInstrSize);
236 Instr instr_ori = Assembler::instr_at(pc_ + 1 * Assembler::kInstrSize);
237 DCHECK(Assembler::IsLui(instr_lui));
238 DCHECK(Assembler::IsOri(instr_ori));
239 int32_t imm = (instr_lui & static_cast<int32_t>(kImm16Mask)) << kLuiShift;
240 imm |= (instr_ori & static_cast<int32_t>(kImm16Mask));
241 return reinterpret_cast<Address>(imm);
242 }
243}
244
245
246Address RelocInfo::target_internal_reference_address() {
247 DCHECK(rmode_ == INTERNAL_REFERENCE || rmode_ == INTERNAL_REFERENCE_ENCODED);
248 return reinterpret_cast<Address>(pc_);
249}
250
251
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000252Address RelocInfo::target_runtime_entry(Assembler* origin) {
253 DCHECK(IsRuntimeEntry(rmode_));
254 return target_address();
255}
256
257
258void RelocInfo::set_target_runtime_entry(Address target,
259 WriteBarrierMode write_barrier_mode,
260 ICacheFlushMode icache_flush_mode) {
261 DCHECK(IsRuntimeEntry(rmode_));
262 if (target_address() != target)
263 set_target_address(target, write_barrier_mode, icache_flush_mode);
264}
265
266
267Handle<Cell> RelocInfo::target_cell_handle() {
268 DCHECK(rmode_ == RelocInfo::CELL);
Steve Block44f0eee2011-05-26 01:26:41 +0100269 Address address = Memory::Address_at(pc_);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000270 return Handle<Cell>(reinterpret_cast<Cell**>(address));
Steve Block44f0eee2011-05-26 01:26:41 +0100271}
272
273
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000274Cell* RelocInfo::target_cell() {
275 DCHECK(rmode_ == RelocInfo::CELL);
276 return Cell::FromValueAddress(Memory::Address_at(pc_));
Steve Block44f0eee2011-05-26 01:26:41 +0100277}
278
279
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000280void RelocInfo::set_target_cell(Cell* cell,
281 WriteBarrierMode write_barrier_mode,
282 ICacheFlushMode icache_flush_mode) {
283 DCHECK(rmode_ == RelocInfo::CELL);
284 Address address = cell->address() + Cell::kValueOffset;
Steve Block44f0eee2011-05-26 01:26:41 +0100285 Memory::Address_at(pc_) = address;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000286 if (write_barrier_mode == UPDATE_WRITE_BARRIER && host() != NULL) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100287 host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(host(), this,
288 cell);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100289 }
Andrei Popescu31002712010-02-23 13:46:05 +0000290}
291
292
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000293static const int kNoCodeAgeSequenceLength = 7 * Assembler::kInstrSize;
294
295
296Handle<Object> RelocInfo::code_age_stub_handle(Assembler* origin) {
297 UNREACHABLE(); // This should never be reached on Arm.
298 return Handle<Object>();
299}
300
301
302Code* RelocInfo::code_age_stub() {
303 DCHECK(rmode_ == RelocInfo::CODE_AGE_SEQUENCE);
304 return Code::GetCodeFromTargetAddress(
305 Assembler::target_address_at(pc_ + Assembler::kInstrSize, host_));
306}
307
308
309void RelocInfo::set_code_age_stub(Code* stub,
310 ICacheFlushMode icache_flush_mode) {
311 DCHECK(rmode_ == RelocInfo::CODE_AGE_SEQUENCE);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000312 Assembler::set_target_address_at(isolate_, pc_ + Assembler::kInstrSize, host_,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000313 stub->instruction_start());
314}
315
316
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000317Address RelocInfo::debug_call_address() {
318 // The pc_ offset of 0 assumes patched debug break slot or return
319 // sequence.
320 DCHECK(IsDebugBreakSlot(rmode()) && IsPatchedDebugBreakSlotSequence());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000321 return Assembler::target_address_at(pc_, host_);
Andrei Popescu31002712010-02-23 13:46:05 +0000322}
323
324
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000325void RelocInfo::set_debug_call_address(Address target) {
326 DCHECK(IsDebugBreakSlot(rmode()) && IsPatchedDebugBreakSlotSequence());
327 // The pc_ offset of 0 assumes patched debug break slot or return
328 // sequence.
329 Assembler::set_target_address_at(isolate_, pc_, host_, target);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100330 if (host() != NULL) {
331 Object* target_code = Code::GetCodeFromTargetAddress(target);
332 host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(
333 host(), this, HeapObject::cast(target_code));
334 }
Andrei Popescu31002712010-02-23 13:46:05 +0000335}
336
337
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000338void RelocInfo::WipeOut() {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000339 DCHECK(IsEmbeddedObject(rmode_) || IsCodeTarget(rmode_) ||
340 IsRuntimeEntry(rmode_) || IsExternalReference(rmode_) ||
341 IsInternalReference(rmode_) || IsInternalReferenceEncoded(rmode_));
342 if (IsInternalReference(rmode_)) {
343 Memory::Address_at(pc_) = NULL;
344 } else if (IsInternalReferenceEncoded(rmode_)) {
345 Assembler::set_target_internal_reference_encoded_at(pc_, nullptr);
346 } else {
347 Assembler::set_target_address_at(isolate_, pc_, host_, NULL);
348 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000349}
350
351
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000352void RelocInfo::Visit(Isolate* isolate, ObjectVisitor* visitor) {
Steve Block44f0eee2011-05-26 01:26:41 +0100353 RelocInfo::Mode mode = rmode();
354 if (mode == RelocInfo::EMBEDDED_OBJECT) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100355 visitor->VisitEmbeddedPointer(this);
Steve Block44f0eee2011-05-26 01:26:41 +0100356 } else if (RelocInfo::IsCodeTarget(mode)) {
357 visitor->VisitCodeTarget(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000358 } else if (mode == RelocInfo::CELL) {
359 visitor->VisitCell(this);
Steve Block44f0eee2011-05-26 01:26:41 +0100360 } else if (mode == RelocInfo::EXTERNAL_REFERENCE) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100361 visitor->VisitExternalReference(this);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000362 } else if (mode == RelocInfo::INTERNAL_REFERENCE ||
363 mode == RelocInfo::INTERNAL_REFERENCE_ENCODED) {
364 visitor->VisitInternalReference(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000365 } else if (RelocInfo::IsCodeAgeSequence(mode)) {
366 visitor->VisitCodeAgeSequence(this);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000367 } else if (RelocInfo::IsDebugBreakSlot(mode) &&
368 IsPatchedDebugBreakSlotSequence()) {
Steve Block44f0eee2011-05-26 01:26:41 +0100369 visitor->VisitDebugTarget(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000370 } else if (RelocInfo::IsRuntimeEntry(mode)) {
Steve Block44f0eee2011-05-26 01:26:41 +0100371 visitor->VisitRuntimeEntry(this);
372 }
373}
374
375
376template<typename StaticVisitor>
377void RelocInfo::Visit(Heap* heap) {
378 RelocInfo::Mode mode = rmode();
379 if (mode == RelocInfo::EMBEDDED_OBJECT) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100380 StaticVisitor::VisitEmbeddedPointer(heap, this);
Steve Block44f0eee2011-05-26 01:26:41 +0100381 } else if (RelocInfo::IsCodeTarget(mode)) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000382 StaticVisitor::VisitCodeTarget(heap, this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000383 } else if (mode == RelocInfo::CELL) {
384 StaticVisitor::VisitCell(heap, this);
Steve Block44f0eee2011-05-26 01:26:41 +0100385 } else if (mode == RelocInfo::EXTERNAL_REFERENCE) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100386 StaticVisitor::VisitExternalReference(this);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000387 } else if (mode == RelocInfo::INTERNAL_REFERENCE ||
388 mode == RelocInfo::INTERNAL_REFERENCE_ENCODED) {
389 StaticVisitor::VisitInternalReference(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000390 } else if (RelocInfo::IsCodeAgeSequence(mode)) {
391 StaticVisitor::VisitCodeAgeSequence(heap, this);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000392 } else if (RelocInfo::IsDebugBreakSlot(mode) &&
393 IsPatchedDebugBreakSlotSequence()) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000394 StaticVisitor::VisitDebugTarget(heap, this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000395 } else if (RelocInfo::IsRuntimeEntry(mode)) {
Steve Block44f0eee2011-05-26 01:26:41 +0100396 StaticVisitor::VisitRuntimeEntry(this);
397 }
Andrei Popescu31002712010-02-23 13:46:05 +0000398}
399
400
401// -----------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000402// Assembler.
Andrei Popescu31002712010-02-23 13:46:05 +0000403
404
405void Assembler::CheckBuffer() {
406 if (buffer_space() <= kGap) {
407 GrowBuffer();
408 }
409}
410
411
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000412void Assembler::CheckTrampolinePoolQuick(int extra_instructions) {
413 if (pc_offset() >= next_buffer_check_ - extra_instructions * kInstrSize) {
Steve Block44f0eee2011-05-26 01:26:41 +0100414 CheckTrampolinePool();
415 }
416}
417
418
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000419void Assembler::CheckForEmitInForbiddenSlot() {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000420 if (!is_buffer_growth_blocked()) {
421 CheckBuffer();
422 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000423 if (IsPrevInstrCompactBranch()) {
424 // Nop instruction to preceed a CTI in forbidden slot:
425 Instr nop = SPECIAL | SLL;
426 *reinterpret_cast<Instr*>(pc_) = nop;
427 pc_ += kInstrSize;
428
429 ClearCompactBranchState();
430 }
431}
432
433
434void Assembler::EmitHelper(Instr x, CompactBranchType is_compact_branch) {
435 if (IsPrevInstrCompactBranch()) {
436 if (Instruction::IsForbiddenAfterBranchInstr(x)) {
437 // Nop instruction to preceed a CTI in forbidden slot:
438 Instr nop = SPECIAL | SLL;
439 *reinterpret_cast<Instr*>(pc_) = nop;
440 pc_ += kInstrSize;
441 }
442 ClearCompactBranchState();
443 }
Andrei Popescu31002712010-02-23 13:46:05 +0000444 *reinterpret_cast<Instr*>(pc_) = x;
445 pc_ += kInstrSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000446 if (is_compact_branch == CompactBranchType::COMPACT_BRANCH) {
447 EmittedCompactBranchInstruction();
448 }
Steve Block44f0eee2011-05-26 01:26:41 +0100449 CheckTrampolinePoolQuick();
Andrei Popescu31002712010-02-23 13:46:05 +0000450}
451
452
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000453template <typename T>
454void Assembler::EmitHelper(T x) {
455 *reinterpret_cast<T*>(pc_) = x;
456 pc_ += sizeof(x);
457 CheckTrampolinePoolQuick();
458}
459
460
461void Assembler::emit(Instr x, CompactBranchType is_compact_branch) {
462 if (!is_buffer_growth_blocked()) {
463 CheckBuffer();
464 }
465 EmitHelper(x, is_compact_branch);
466}
467
468
469} // namespace internal
470} // namespace v8
Andrei Popescu31002712010-02-23 13:46:05 +0000471
472#endif // V8_MIPS_ASSEMBLER_MIPS_INL_H_