blob: 57aea3898c86da2a269740c6cf512c6adf993f52 [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
Andrei Popescu31002712010-02-23 13:46:05 +0000105Address RelocInfo::target_address_address() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000106 DCHECK(IsCodeTarget(rmode_) ||
107 IsRuntimeEntry(rmode_) ||
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100108 rmode_ == EMBEDDED_OBJECT ||
109 rmode_ == EXTERNAL_REFERENCE);
110 // Read the address of the word containing the target_address in an
111 // instruction stream.
112 // The only architecture-independent user of this function is the serializer.
113 // The serializer uses it to find out how many raw bytes of instruction to
114 // output before the next target.
115 // For an instruction like LUI/ORI where the target bits are mixed into the
116 // instruction bits, the size of the target will be zero, indicating that the
117 // serializer should not step forward in memory after a target is resolved
118 // and written. In this case the target_address_address function should
119 // return the end of the instructions to be patched, allowing the
120 // deserializer to deserialize the instructions as raw bytes and put them in
121 // place, ready to be patched with the target. After jump optimization,
122 // that is the address of the instruction that follows J/JAL/JR/JALR
123 // instruction.
124 return reinterpret_cast<Address>(
125 pc_ + Assembler::kInstructionsFor32BitConstant * Assembler::kInstrSize);
Steve Block44f0eee2011-05-26 01:26:41 +0100126}
127
128
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000129Address RelocInfo::constant_pool_entry_address() {
130 UNREACHABLE();
131 return NULL;
132}
133
134
Steve Block44f0eee2011-05-26 01:26:41 +0100135int RelocInfo::target_address_size() {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100136 return Assembler::kSpecialTargetSize;
Andrei Popescu31002712010-02-23 13:46:05 +0000137}
138
139
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000140void RelocInfo::set_target_address(Address target,
141 WriteBarrierMode write_barrier_mode,
142 ICacheFlushMode icache_flush_mode) {
143 DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000144 Assembler::set_target_address_at(isolate_, pc_, host_, target,
145 icache_flush_mode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000146 if (write_barrier_mode == UPDATE_WRITE_BARRIER &&
147 host() != NULL && IsCodeTarget(rmode_)) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100148 Object* target_code = Code::GetCodeFromTargetAddress(target);
149 host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(
150 host(), this, HeapObject::cast(target_code));
151 }
Andrei Popescu31002712010-02-23 13:46:05 +0000152}
153
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000154Address Assembler::target_address_from_return_address(Address pc) {
155 return pc - kCallTargetAddressOffset;
156}
157
158
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000159void Assembler::set_target_internal_reference_encoded_at(Address pc,
160 Address target) {
Ben Murdochda12d292016-06-02 14:46:10 +0100161 Instr instr1 = Assembler::instr_at(pc + 0 * Assembler::kInstrSize);
162 Instr instr2 = Assembler::instr_at(pc + 1 * Assembler::kInstrSize);
163 DCHECK(Assembler::IsLui(instr1));
164 DCHECK(Assembler::IsOri(instr2) || Assembler::IsJicOrJialc(instr2));
165 instr1 &= ~kImm16Mask;
166 instr2 &= ~kImm16Mask;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000167 int32_t imm = reinterpret_cast<int32_t>(target);
168 DCHECK((imm & 3) == 0);
Ben Murdochda12d292016-06-02 14:46:10 +0100169 if (Assembler::IsJicOrJialc(instr2)) {
170 // Encoded internal references are lui/jic load of 32-bit absolute address.
171 uint32_t lui_offset_u, jic_offset_u;
172 Assembler::UnpackTargetAddressUnsigned(imm, lui_offset_u, jic_offset_u);
173
174 Assembler::instr_at_put(pc + 0 * Assembler::kInstrSize,
175 instr1 | lui_offset_u);
176 Assembler::instr_at_put(pc + 1 * Assembler::kInstrSize,
177 instr2 | jic_offset_u);
178 } else {
179 // Encoded internal references are lui/ori load of 32-bit absolute address.
180 Assembler::instr_at_put(pc + 0 * Assembler::kInstrSize,
181 instr1 | ((imm >> kLuiShift) & kImm16Mask));
182 Assembler::instr_at_put(pc + 1 * Assembler::kInstrSize,
183 instr2 | (imm & kImm16Mask));
184 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000185
186 // Currently used only by deserializer, and all code will be flushed
187 // after complete deserialization, no need to flush on each reference.
188}
189
190
191void Assembler::deserialization_set_target_internal_reference_at(
192 Isolate* isolate, Address pc, Address target, RelocInfo::Mode mode) {
193 if (mode == RelocInfo::INTERNAL_REFERENCE_ENCODED) {
194 DCHECK(IsLui(instr_at(pc)));
195 set_target_internal_reference_encoded_at(pc, target);
196 } else {
197 DCHECK(mode == RelocInfo::INTERNAL_REFERENCE);
198 Memory::Address_at(pc) = target;
199 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000200}
201
202
Andrei Popescu31002712010-02-23 13:46:05 +0000203Object* RelocInfo::target_object() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000204 DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
205 return reinterpret_cast<Object*>(Assembler::target_address_at(pc_, host_));
Andrei Popescu31002712010-02-23 13:46:05 +0000206}
207
208
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100209Handle<Object> RelocInfo::target_object_handle(Assembler* origin) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000210 DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
Andrei Popescu31002712010-02-23 13:46:05 +0000211 return Handle<Object>(reinterpret_cast<Object**>(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000212 Assembler::target_address_at(pc_, host_)));
Andrei Popescu31002712010-02-23 13:46:05 +0000213}
214
215
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000216void RelocInfo::set_target_object(Object* target,
217 WriteBarrierMode write_barrier_mode,
218 ICacheFlushMode icache_flush_mode) {
219 DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000220 Assembler::set_target_address_at(isolate_, pc_, host_,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000221 reinterpret_cast<Address>(target),
222 icache_flush_mode);
223 if (write_barrier_mode == UPDATE_WRITE_BARRIER &&
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100224 host() != NULL &&
225 target->IsHeapObject()) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100226 host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(
227 host(), this, HeapObject::cast(target));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100228 }
Andrei Popescu31002712010-02-23 13:46:05 +0000229}
230
231
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000232Address RelocInfo::target_external_reference() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000233 DCHECK(rmode_ == EXTERNAL_REFERENCE);
234 return Assembler::target_address_at(pc_, host_);
Steve Block44f0eee2011-05-26 01:26:41 +0100235}
236
237
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000238Address RelocInfo::target_internal_reference() {
239 if (rmode_ == INTERNAL_REFERENCE) {
240 return Memory::Address_at(pc_);
241 } else {
Ben Murdochda12d292016-06-02 14:46:10 +0100242 // Encoded internal references are lui/ori or lui/jic load of 32-bit
243 // absolute address.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000244 DCHECK(rmode_ == INTERNAL_REFERENCE_ENCODED);
Ben Murdochda12d292016-06-02 14:46:10 +0100245 Instr instr1 = Assembler::instr_at(pc_ + 0 * Assembler::kInstrSize);
246 Instr instr2 = Assembler::instr_at(pc_ + 1 * Assembler::kInstrSize);
247 DCHECK(Assembler::IsLui(instr1));
248 DCHECK(Assembler::IsOri(instr2) || Assembler::IsJicOrJialc(instr2));
249 if (Assembler::IsJicOrJialc(instr2)) {
250 return reinterpret_cast<Address>(
251 Assembler::CreateTargetAddress(instr1, instr2));
252 }
253 int32_t imm = (instr1 & static_cast<int32_t>(kImm16Mask)) << kLuiShift;
254 imm |= (instr2 & static_cast<int32_t>(kImm16Mask));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000255 return reinterpret_cast<Address>(imm);
256 }
257}
258
259
260Address RelocInfo::target_internal_reference_address() {
261 DCHECK(rmode_ == INTERNAL_REFERENCE || rmode_ == INTERNAL_REFERENCE_ENCODED);
262 return reinterpret_cast<Address>(pc_);
263}
264
265
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000266Address RelocInfo::target_runtime_entry(Assembler* origin) {
267 DCHECK(IsRuntimeEntry(rmode_));
268 return target_address();
269}
270
271
272void RelocInfo::set_target_runtime_entry(Address target,
273 WriteBarrierMode write_barrier_mode,
274 ICacheFlushMode icache_flush_mode) {
275 DCHECK(IsRuntimeEntry(rmode_));
276 if (target_address() != target)
277 set_target_address(target, write_barrier_mode, icache_flush_mode);
278}
279
280
281Handle<Cell> RelocInfo::target_cell_handle() {
282 DCHECK(rmode_ == RelocInfo::CELL);
Steve Block44f0eee2011-05-26 01:26:41 +0100283 Address address = Memory::Address_at(pc_);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000284 return Handle<Cell>(reinterpret_cast<Cell**>(address));
Steve Block44f0eee2011-05-26 01:26:41 +0100285}
286
287
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000288Cell* RelocInfo::target_cell() {
289 DCHECK(rmode_ == RelocInfo::CELL);
290 return Cell::FromValueAddress(Memory::Address_at(pc_));
Steve Block44f0eee2011-05-26 01:26:41 +0100291}
292
293
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000294void RelocInfo::set_target_cell(Cell* cell,
295 WriteBarrierMode write_barrier_mode,
296 ICacheFlushMode icache_flush_mode) {
297 DCHECK(rmode_ == RelocInfo::CELL);
298 Address address = cell->address() + Cell::kValueOffset;
Steve Block44f0eee2011-05-26 01:26:41 +0100299 Memory::Address_at(pc_) = address;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000300 if (write_barrier_mode == UPDATE_WRITE_BARRIER && host() != NULL) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100301 host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(host(), this,
302 cell);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100303 }
Andrei Popescu31002712010-02-23 13:46:05 +0000304}
305
306
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000307static const int kNoCodeAgeSequenceLength = 7 * Assembler::kInstrSize;
308
309
310Handle<Object> RelocInfo::code_age_stub_handle(Assembler* origin) {
311 UNREACHABLE(); // This should never be reached on Arm.
312 return Handle<Object>();
313}
314
315
316Code* RelocInfo::code_age_stub() {
317 DCHECK(rmode_ == RelocInfo::CODE_AGE_SEQUENCE);
318 return Code::GetCodeFromTargetAddress(
319 Assembler::target_address_at(pc_ + Assembler::kInstrSize, host_));
320}
321
322
323void RelocInfo::set_code_age_stub(Code* stub,
324 ICacheFlushMode icache_flush_mode) {
325 DCHECK(rmode_ == RelocInfo::CODE_AGE_SEQUENCE);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000326 Assembler::set_target_address_at(isolate_, pc_ + Assembler::kInstrSize, host_,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000327 stub->instruction_start());
328}
329
330
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000331Address RelocInfo::debug_call_address() {
332 // The pc_ offset of 0 assumes patched debug break slot or return
333 // sequence.
334 DCHECK(IsDebugBreakSlot(rmode()) && IsPatchedDebugBreakSlotSequence());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000335 return Assembler::target_address_at(pc_, host_);
Andrei Popescu31002712010-02-23 13:46:05 +0000336}
337
338
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000339void RelocInfo::set_debug_call_address(Address target) {
340 DCHECK(IsDebugBreakSlot(rmode()) && IsPatchedDebugBreakSlotSequence());
341 // The pc_ offset of 0 assumes patched debug break slot or return
342 // sequence.
343 Assembler::set_target_address_at(isolate_, pc_, host_, target);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100344 if (host() != NULL) {
345 Object* target_code = Code::GetCodeFromTargetAddress(target);
346 host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(
347 host(), this, HeapObject::cast(target_code));
348 }
Andrei Popescu31002712010-02-23 13:46:05 +0000349}
350
351
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000352void RelocInfo::WipeOut() {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000353 DCHECK(IsEmbeddedObject(rmode_) || IsCodeTarget(rmode_) ||
354 IsRuntimeEntry(rmode_) || IsExternalReference(rmode_) ||
355 IsInternalReference(rmode_) || IsInternalReferenceEncoded(rmode_));
356 if (IsInternalReference(rmode_)) {
357 Memory::Address_at(pc_) = NULL;
358 } else if (IsInternalReferenceEncoded(rmode_)) {
359 Assembler::set_target_internal_reference_encoded_at(pc_, nullptr);
360 } else {
361 Assembler::set_target_address_at(isolate_, pc_, host_, NULL);
362 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000363}
364
Ben Murdochc5610432016-08-08 18:44:38 +0100365template <typename ObjectVisitor>
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000366void RelocInfo::Visit(Isolate* isolate, ObjectVisitor* visitor) {
Steve Block44f0eee2011-05-26 01:26:41 +0100367 RelocInfo::Mode mode = rmode();
368 if (mode == RelocInfo::EMBEDDED_OBJECT) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100369 visitor->VisitEmbeddedPointer(this);
Steve Block44f0eee2011-05-26 01:26:41 +0100370 } else if (RelocInfo::IsCodeTarget(mode)) {
371 visitor->VisitCodeTarget(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000372 } else if (mode == RelocInfo::CELL) {
373 visitor->VisitCell(this);
Steve Block44f0eee2011-05-26 01:26:41 +0100374 } else if (mode == RelocInfo::EXTERNAL_REFERENCE) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100375 visitor->VisitExternalReference(this);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000376 } else if (mode == RelocInfo::INTERNAL_REFERENCE ||
377 mode == RelocInfo::INTERNAL_REFERENCE_ENCODED) {
378 visitor->VisitInternalReference(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000379 } else if (RelocInfo::IsCodeAgeSequence(mode)) {
380 visitor->VisitCodeAgeSequence(this);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000381 } else if (RelocInfo::IsDebugBreakSlot(mode) &&
382 IsPatchedDebugBreakSlotSequence()) {
Steve Block44f0eee2011-05-26 01:26:41 +0100383 visitor->VisitDebugTarget(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000384 } else if (RelocInfo::IsRuntimeEntry(mode)) {
Steve Block44f0eee2011-05-26 01:26:41 +0100385 visitor->VisitRuntimeEntry(this);
386 }
387}
388
389
390template<typename StaticVisitor>
391void RelocInfo::Visit(Heap* heap) {
392 RelocInfo::Mode mode = rmode();
393 if (mode == RelocInfo::EMBEDDED_OBJECT) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100394 StaticVisitor::VisitEmbeddedPointer(heap, this);
Steve Block44f0eee2011-05-26 01:26:41 +0100395 } else if (RelocInfo::IsCodeTarget(mode)) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000396 StaticVisitor::VisitCodeTarget(heap, this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000397 } else if (mode == RelocInfo::CELL) {
398 StaticVisitor::VisitCell(heap, this);
Steve Block44f0eee2011-05-26 01:26:41 +0100399 } else if (mode == RelocInfo::EXTERNAL_REFERENCE) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100400 StaticVisitor::VisitExternalReference(this);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000401 } else if (mode == RelocInfo::INTERNAL_REFERENCE ||
402 mode == RelocInfo::INTERNAL_REFERENCE_ENCODED) {
403 StaticVisitor::VisitInternalReference(this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000404 } else if (RelocInfo::IsCodeAgeSequence(mode)) {
405 StaticVisitor::VisitCodeAgeSequence(heap, this);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000406 } else if (RelocInfo::IsDebugBreakSlot(mode) &&
407 IsPatchedDebugBreakSlotSequence()) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000408 StaticVisitor::VisitDebugTarget(heap, this);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000409 } else if (RelocInfo::IsRuntimeEntry(mode)) {
Steve Block44f0eee2011-05-26 01:26:41 +0100410 StaticVisitor::VisitRuntimeEntry(this);
411 }
Andrei Popescu31002712010-02-23 13:46:05 +0000412}
413
414
415// -----------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000416// Assembler.
Andrei Popescu31002712010-02-23 13:46:05 +0000417
418
419void Assembler::CheckBuffer() {
420 if (buffer_space() <= kGap) {
421 GrowBuffer();
422 }
423}
424
425
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000426void Assembler::CheckTrampolinePoolQuick(int extra_instructions) {
427 if (pc_offset() >= next_buffer_check_ - extra_instructions * kInstrSize) {
Steve Block44f0eee2011-05-26 01:26:41 +0100428 CheckTrampolinePool();
429 }
430}
431
432
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000433void Assembler::CheckForEmitInForbiddenSlot() {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000434 if (!is_buffer_growth_blocked()) {
435 CheckBuffer();
436 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000437 if (IsPrevInstrCompactBranch()) {
438 // Nop instruction to preceed a CTI in forbidden slot:
439 Instr nop = SPECIAL | SLL;
440 *reinterpret_cast<Instr*>(pc_) = nop;
441 pc_ += kInstrSize;
442
443 ClearCompactBranchState();
444 }
445}
446
447
448void Assembler::EmitHelper(Instr x, CompactBranchType is_compact_branch) {
449 if (IsPrevInstrCompactBranch()) {
450 if (Instruction::IsForbiddenAfterBranchInstr(x)) {
451 // Nop instruction to preceed a CTI in forbidden slot:
452 Instr nop = SPECIAL | SLL;
453 *reinterpret_cast<Instr*>(pc_) = nop;
454 pc_ += kInstrSize;
455 }
456 ClearCompactBranchState();
457 }
Andrei Popescu31002712010-02-23 13:46:05 +0000458 *reinterpret_cast<Instr*>(pc_) = x;
459 pc_ += kInstrSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000460 if (is_compact_branch == CompactBranchType::COMPACT_BRANCH) {
461 EmittedCompactBranchInstruction();
462 }
Steve Block44f0eee2011-05-26 01:26:41 +0100463 CheckTrampolinePoolQuick();
Andrei Popescu31002712010-02-23 13:46:05 +0000464}
465
Ben Murdoch61f157c2016-09-16 13:49:30 +0100466template <>
467inline void Assembler::EmitHelper(uint8_t x);
Andrei Popescu31002712010-02-23 13:46:05 +0000468
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000469template <typename T>
470void Assembler::EmitHelper(T x) {
471 *reinterpret_cast<T*>(pc_) = x;
472 pc_ += sizeof(x);
473 CheckTrampolinePoolQuick();
474}
475
Ben Murdoch61f157c2016-09-16 13:49:30 +0100476template <>
477void Assembler::EmitHelper(uint8_t x) {
478 *reinterpret_cast<uint8_t*>(pc_) = x;
479 pc_ += sizeof(x);
480 if (reinterpret_cast<intptr_t>(pc_) % kInstrSize == 0) {
481 CheckTrampolinePoolQuick();
482 }
483}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000484
485void Assembler::emit(Instr x, CompactBranchType is_compact_branch) {
486 if (!is_buffer_growth_blocked()) {
487 CheckBuffer();
488 }
489 EmitHelper(x, is_compact_branch);
490}
491
492
493} // namespace internal
494} // namespace v8
Andrei Popescu31002712010-02-23 13:46:05 +0000495
496#endif // V8_MIPS_ASSEMBLER_MIPS_INL_H_