v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
assembler-mips64-inl.h
Go to the documentation of this file.
1// 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#ifndef V8_CODEGEN_MIPS64_ASSEMBLER_MIPS64_INL_H_
36#define V8_CODEGEN_MIPS64_ASSEMBLER_MIPS64_INL_H_
37
39// Include the non-inl header before the rest of the headers.
40
43#include "src/debug/debug.h"
45
46namespace v8 {
47namespace internal {
48
49bool CpuFeatures::SupportsOptimizer() { return IsSupported(FPU); }
50
51// -----------------------------------------------------------------------------
52// Operand and MemOperand.
53
54bool Operand::is_reg() const { return rm_.is_valid(); }
55
56int64_t Operand::immediate() const {
57 DCHECK(!is_reg());
59 return value_.immediate;
60}
61
62// -----------------------------------------------------------------------------
63// RelocInfo.
64
65void WritableRelocInfo::apply(intptr_t delta) {
67 // Absolute code pointer inside code object moves with the code object.
69 }
70}
71
75}
76
79 // Read the address of the word containing the target_address in an
80 // instruction stream.
81 // The only architecture-independent user of this function is the serializer.
82 // The serializer uses it to find out how many raw bytes of instruction to
83 // output before the next target.
84 // For an instruction like LUI/ORI where the target bits are mixed into the
85 // instruction bits, the size of the target will be zero, indicating that the
86 // serializer should not step forward in memory after a target is resolved
87 // and written. In this case the target_address_address function should
88 // return the end of the instructions to be patched, allowing the
89 // deserializer to deserialize the instructions as raw bytes and put them in
90 // place, ready to be patched with the target. After jump optimization,
91 // that is the address of the instruction that follows J/JAL/JR/JALR
92 // instruction.
94}
95
97
99
101 Address instruction_payload) {
102 return kSpecialTargetSize;
103}
104
106 Address pc, Address target, WritableJitAllocation& jit_allocation) {
107 // Encoded internal references are j/jal instructions.
109
110 uint64_t imm28 = target & static_cast<uint64_t>(kImm28Mask);
111
112 instr &= ~kImm26Mask;
113 uint64_t imm26 = imm28 >> 2;
114 DCHECK(is_uint26(imm26));
115
116 instr_at_put(pc, instr | (imm26 & kImm26Mask), &jit_allocation);
117 // Currently used only by deserializer, and all code will be flushed
118 // after complete deserialization, no need to flush on each reference.
119}
120
122 Address pc, Address target, WritableJitAllocation& jit_allocation,
123 RelocInfo::Mode mode) {
126 set_target_internal_reference_encoded_at(pc, target, jit_allocation);
127 } else {
129 jit_allocation.WriteUnalignedValue<Address>(pc, target);
130 }
131}
132
133Tagged<HeapObject> RelocInfo::target_object(PtrComprCageBase cage_base) {
135 return Cast<HeapObject>(
137}
138
139DirectHandle<HeapObject> RelocInfo::target_object_handle(Assembler* origin) {
141 return DirectHandle<HeapObject>::FromSlot(reinterpret_cast<Address*>(
143}
144
146 ICacheFlushMode icache_flush_mode) {
149 &jit_allocation_, icache_flush_mode);
150}
151
155}
156
158 Address target, ICacheFlushMode icache_flush_mode) {
161 &jit_allocation_, icache_flush_mode);
162}
163
164WasmCodePointer RelocInfo::wasm_code_pointer_table_entry() const {
166 return WasmCodePointer{Assembler::uint32_constant_at(pc_, constant_pool_)};
167}
168
170 WasmCodePointer target, ICacheFlushMode icache_flush_mode) {
173 &jit_allocation_, icache_flush_mode);
174}
175
177 if (rmode_ == INTERNAL_REFERENCE) {
178 return Memory<Address>(pc_);
179 } else {
180 // Encoded internal references are j/jal instructions.
183 instr &= kImm26Mask;
184 uint64_t imm28 = instr << 2;
185 uint64_t segment = pc_ & ~static_cast<uint64_t>(kImm28Mask);
186 return static_cast<Address>(segment | imm28);
187 }
188}
189
192 return pc_;
193}
194
197 return ReadUnalignedValue<JSDispatchHandle>(pc_);
198}
199
200Builtin RelocInfo::target_builtin_at(Assembler* origin) { UNREACHABLE(); }
201
205}
206
208 Instr instr0 = instr_at(pc);
209 Instr instr1 = instr_at(pc + 1 * kInstrSize);
210
211 DCHECK((GetOpcodeField(instr0) == LUI) && (GetOpcodeField(instr1) == ORI));
212
213 // Assemble the 32 bit value.
214 uint32_t upper16 = GetImmediate16(instr0) << 16;
215 uint32_t lower16 = GetImmediate16(instr1);
216 uint32_t addr = upper16 | lower16;
217
218 return addr;
219}
220
222 uint32_t new_constant,
223 WritableJitAllocation* jit_allocation,
224 ICacheFlushMode icache_flush_mode) {
225 Instr instr1 = instr_at(pc + kInstrSize);
226 uint32_t rt_code = GetRt(instr1);
227
228#ifdef DEBUG
229 // Check we have the result from a li macro-instruction.
230 Instr instr0 = instr_at(pc);
231 DCHECK((GetOpcodeField(instr0) == LUI) && (GetOpcodeField(instr1) == ORI) &&
232 (GetRt(instr0) == rt_code));
233#endif
234
235 // Must use 2 instructions to insure patchable 32-bit value.
236 // lui rt, upper-16.
237 // ori rt, rt, lower-16.
238 Instr new_instr0 =
239 LUI | (rt_code << kRtShift) | ((new_constant >> 16) & kImm16Mask);
240 Instr new_instr1 = ORI | (rt_code << kRtShift) | (rt_code << kRsShift) |
241 (new_constant & kImm16Mask);
242 instr_at_put(pc, new_instr0, jit_allocation);
243 instr_at_put(pc + kInstrSize, new_instr1, jit_allocation);
244
245 if (icache_flush_mode != SKIP_ICACHE_FLUSH) {
247 }
248}
249
250// -----------------------------------------------------------------------------
251// Assembler.
252
254 if (buffer_space() <= kGap) {
255 GrowBuffer();
256 }
257}
258
261 CheckBuffer();
262 }
264 // Nop instruction to precede a CTI in forbidden slot:
265 Instr nop = SPECIAL | SLL;
266 *reinterpret_cast<Instr*>(pc_) = nop;
267 pc_ += kInstrSize;
268
270 }
271}
272
276 // Nop instruction to precede a CTI in forbidden slot:
277 Instr nop = SPECIAL | SLL;
278 *reinterpret_cast<Instr*>(pc_) = nop;
279 pc_ += kInstrSize;
280 }
282 }
283 *reinterpret_cast<Instr*>(pc_) = x;
284 pc_ += kInstrSize;
285 if (is_compact_branch == CompactBranchType::COMPACT_BRANCH) {
287 }
289}
290
291template <>
292inline void Assembler::EmitHelper(uint8_t x);
293
294template <typename T>
295void Assembler::EmitHelper(T x) {
296 *reinterpret_cast<T*>(pc_) = x;
297 pc_ += sizeof(x);
299}
300
301template <>
303 *reinterpret_cast<uint8_t*>(pc_) = x;
304 pc_ += sizeof(x);
305 if (reinterpret_cast<intptr_t>(pc_) % kInstrSize == 0) {
307 }
308}
309
310void Assembler::emit(Instr x, CompactBranchType is_compact_branch) {
312 CheckBuffer();
313 }
314 EmitHelper(x, is_compact_branch);
315}
316
317void Assembler::emit(uint64_t data) {
319 EmitHelper(data);
320}
321
322EnsureSpace::EnsureSpace(Assembler* assembler) { assembler->CheckBuffer(); }
323
324} // namespace internal
325} // namespace v8
326
327#endif // V8_CODEGEN_MIPS64_ASSEMBLER_MIPS64_INL_H_
static constexpr int kSpecialTargetSize
bool is_buffer_growth_blocked() const
static void deserialization_set_target_internal_reference_at(Address pc, Address target, WritableJitAllocation &jit_allocation, RelocInfo::Mode mode=RelocInfo::INTERNAL_REFERENCE)
static bool IsJ(Instr instr)
static uint32_t GetOpcodeField(Instr instr)
static void set_uint32_constant_at(Address pc, Address constant_pool, uint32_t new_constant, WritableJitAllocation *jit_allocation, ICacheFlushMode icache_flush_mode=FLUSH_ICACHE_IF_NEEDED)
void instr_at_put(int pos, Instr instr)
static uint32_t GetRt(Instr instr)
static void set_target_internal_reference_encoded_at(Address pc, Address target)
static constexpr int kGap
static int RelocateInternalReference(RelocInfo::Mode rmode, Address pc, intptr_t pc_delta, WritableJitAllocation *jit_allocation=nullptr)
static V8_INLINE void set_target_address_at(Address pc, Address constant_pool, Address target, WritableJitAllocation *jit_allocation, ICacheFlushMode icache_flush_mode=FLUSH_ICACHE_IF_NEEDED)
static constexpr int kInstructionsFor64BitConstant
static uint32_t GetImmediate16(Instr instr)
static int deserialization_special_target_size(Address location)
static V8_INLINE Address target_address_at(Address pc, Address constant_pool)
void CheckTrampolinePoolQuick(int extra_instructions=0)
Instruction * pc() const
static uint32_t uint32_constant_at(Address pc, Address constant_pool)
static bool IsSupported(CpuFeature f)
static V8_INLINE DirectHandle FromSlot(Address *slot)
Definition handles.h:687
V8_INLINE EnsureSpace(Assembler *assembler)
union v8::internal::Operand::Value value_
bool IsHeapNumberRequest() const
V8_INLINE bool is_reg() const
int32_t immediate() const
constexpr bool is_valid() const
V8_INLINE Address target_internal_reference()
static constexpr bool IsInternalReference(Mode mode)
Definition reloc-info.h:238
static constexpr bool IsOffHeapTarget(Mode mode)
Definition reloc-info.h:244
V8_INLINE Address target_address()
static constexpr bool IsInternalReferenceEncoded(Mode mode)
Definition reloc-info.h:241
V8_INLINE Address target_internal_reference_address()
static constexpr bool IsCodeTarget(Mode mode)
Definition reloc-info.h:196
static constexpr bool IsWasmCall(Mode mode)
Definition reloc-info.h:213
V8_INLINE int target_address_size()
V8_INLINE Builtin target_builtin_at(Assembler *origin)
V8_INLINE WasmCodePointer wasm_code_pointer_table_entry() const
V8_INLINE Address target_off_heap_target()
static constexpr bool IsWasmStubCall(Mode mode)
Definition reloc-info.h:214
V8_INLINE Address target_external_reference()
V8_INLINE Tagged< HeapObject > target_object(PtrComprCageBase cage_base)
V8_INLINE Address constant_pool_entry_address()
V8_INLINE JSDispatchHandle js_dispatch_handle()
V8_INLINE DirectHandle< HeapObject > target_object_handle(Assembler *origin)
static constexpr bool IsFullEmbeddedObject(Mode mode)
Definition reloc-info.h:203
bool HasTargetAddressAddress() const
V8_INLINE Address target_address_address()
V8_INLINE void WriteUnalignedValue(Address address, T value)
V8_INLINE void set_target_object(Tagged< InstructionStream > host, Tagged< HeapObject > target, WriteBarrierMode write_barrier_mode=UPDATE_WRITE_BARRIER, ICacheFlushMode icache_flush_mode=FLUSH_ICACHE_IF_NEEDED)
WritableJitAllocation & jit_allocation_
Definition reloc-info.h:462
V8_INLINE void set_wasm_code_pointer_table_entry(WasmCodePointer, ICacheFlushMode icache_flush_mode=FLUSH_ICACHE_IF_NEEDED)
V8_INLINE void apply(intptr_t delta)
V8_INLINE void set_target_external_reference(Address, ICacheFlushMode icache_flush_mode=FLUSH_ICACHE_IF_NEEDED)
TNode< Object > target
Instruction * instr
int x
constexpr Opcode SPECIAL
void FlushInstructionCache(void *start, size_t size)
kInterpreterTrampolineOffset Tagged< HeapObject >
base::StrongAlias< JSDispatchHandleAliasTag, uint32_t > JSDispatchHandle
Definition globals.h:557
constexpr int kImm16Mask
constexpr Opcode LUI
constexpr uint8_t kInstrSize
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
#define DCHECK(condition)
Definition logging.h:482