blob: 668481e9ba20382d6682832ee034b3dbddd21fad [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2012 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Andrei Popescu31002712010-02-23 13:46:05 +00004
5#ifndef V8_MIPS_CONSTANTS_H_
6#define V8_MIPS_CONSTANTS_H_
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007#include "src/globals.h"
Andrei Popescu31002712010-02-23 13:46:05 +00008// UNIMPLEMENTED_ macro for MIPS.
Steve Block44f0eee2011-05-26 01:26:41 +01009#ifdef DEBUG
Andrei Popescu31002712010-02-23 13:46:05 +000010#define UNIMPLEMENTED_MIPS() \
11 v8::internal::PrintF("%s, \tline %d: \tfunction %s not implemented. \n", \
12 __FILE__, __LINE__, __func__)
Steve Block44f0eee2011-05-26 01:26:41 +010013#else
14#define UNIMPLEMENTED_MIPS()
15#endif
16
Andrei Popescu31002712010-02-23 13:46:05 +000017#define UNSUPPORTED_MIPS() v8::internal::PrintF("Unsupported instruction.\n")
18
Ben Murdoch3ef787d2012-04-12 10:51:47 +010019enum ArchVariants {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000020 kMips32r1 = v8::internal::MIPSr1,
21 kMips32r2 = v8::internal::MIPSr2,
22 kMips32r6 = v8::internal::MIPSr6,
Ben Murdoch3ef787d2012-04-12 10:51:47 +010023 kLoongson
24};
Andrei Popescu31002712010-02-23 13:46:05 +000025
Steve Block44f0eee2011-05-26 01:26:41 +010026#ifdef _MIPS_ARCH_MIPS32R2
Ben Murdoch3ef787d2012-04-12 10:51:47 +010027 static const ArchVariants kArchVariant = kMips32r2;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000028#elif _MIPS_ARCH_MIPS32R6
29 static const ArchVariants kArchVariant = kMips32r6;
Ben Murdoch3ef787d2012-04-12 10:51:47 +010030#elif _MIPS_ARCH_LOONGSON
31// The loongson flag refers to the LOONGSON architectures based on MIPS-III,
32// which predates (and is a subset of) the mips32r2 and r1 architectures.
33 static const ArchVariants kArchVariant = kLoongson;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000034#elif _MIPS_ARCH_MIPS32RX
35// This flags referred to compatibility mode that creates universal code that
36// can run on any MIPS32 architecture revision. The dynamically generated code
37// by v8 is specialized for the MIPS host detected in runtime probing.
38 static const ArchVariants kArchVariant = kMips32r1;
Steve Block44f0eee2011-05-26 01:26:41 +010039#else
Ben Murdoch3ef787d2012-04-12 10:51:47 +010040 static const ArchVariants kArchVariant = kMips32r1;
Steve Block44f0eee2011-05-26 01:26:41 +010041#endif
42
Ben Murdochb8a8cc12014-11-26 15:28:44 +000043enum Endianness {
44 kLittle,
45 kBig
46};
47
48#if defined(V8_TARGET_LITTLE_ENDIAN)
49 static const Endianness kArchEndian = kLittle;
50#elif defined(V8_TARGET_BIG_ENDIAN)
51 static const Endianness kArchEndian = kBig;
52#else
53#error Unknown endianness
54#endif
55
56enum FpuMode {
57 kFP32,
58 kFP64,
59 kFPXX
60};
61
62#if defined(FPU_MODE_FP32)
63 static const FpuMode kFpuMode = kFP32;
64#elif defined(FPU_MODE_FP64)
65 static const FpuMode kFpuMode = kFP64;
66#elif defined(FPU_MODE_FPXX)
67 static const FpuMode kFpuMode = kFPXX;
68#else
69 static const FpuMode kFpuMode = kFP32;
70#endif
Steve Block44f0eee2011-05-26 01:26:41 +010071
Ben Murdoch257744e2011-11-30 15:57:28 +000072#if(defined(__mips_hard_float) && __mips_hard_float != 0)
73// Use floating-point coprocessor instructions. This flag is raised when
74// -mhard-float is passed to the compiler.
Ben Murdoch3ef787d2012-04-12 10:51:47 +010075const bool IsMipsSoftFloatABI = false;
Ben Murdoch257744e2011-11-30 15:57:28 +000076#elif(defined(__mips_soft_float) && __mips_soft_float != 0)
Ben Murdochb8a8cc12014-11-26 15:28:44 +000077// This flag is raised when -msoft-float is passed to the compiler.
78// Although FPU is a base requirement for v8, soft-float ABI is used
79// on soft-float systems with FPU kernel emulation.
Ben Murdoch3ef787d2012-04-12 10:51:47 +010080const bool IsMipsSoftFloatABI = true;
Ben Murdoch257744e2011-11-30 15:57:28 +000081#else
Ben Murdoch3ef787d2012-04-12 10:51:47 +010082const bool IsMipsSoftFloatABI = true;
Ben Murdoch257744e2011-11-30 15:57:28 +000083#endif
84
Ben Murdochb8a8cc12014-11-26 15:28:44 +000085#if defined(V8_TARGET_LITTLE_ENDIAN)
86const uint32_t kHoleNanUpper32Offset = 4;
87const uint32_t kHoleNanLower32Offset = 0;
88#elif defined(V8_TARGET_BIG_ENDIAN)
89const uint32_t kHoleNanUpper32Offset = 0;
90const uint32_t kHoleNanLower32Offset = 4;
91#else
92#error Unknown endianness
93#endif
94
95#ifndef FPU_MODE_FPXX
96#define IsFp64Mode() \
97 (kFpuMode == kFP64)
98#else
99#define IsFp64Mode() \
100 (CpuFeatures::IsSupported(FP64FPU))
101#endif
102
103#ifndef _MIPS_ARCH_MIPS32RX
104#define IsMipsArchVariant(check) \
105 (kArchVariant == check)
106#else
107#define IsMipsArchVariant(check) \
Paul Lind18a7ebb2014-12-17 22:29:32 -0800108 (CpuFeatures::IsSupported(static_cast<CpuFeature>(check)))
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000109#endif
110
111
112#define __STDC_FORMAT_MACROS
113#include <inttypes.h>
Ben Murdoch257744e2011-11-30 15:57:28 +0000114
Andrei Popescu31002712010-02-23 13:46:05 +0000115// Defines constants and accessor classes to assemble, disassemble and
116// simulate MIPS32 instructions.
117//
118// See: MIPS32 Architecture For Programmers
119// Volume II: The MIPS32 Instruction Set
120// Try www.cs.cornell.edu/courses/cs3410/2008fa/MIPS_Vol2.pdf.
121
Steve Block44f0eee2011-05-26 01:26:41 +0100122namespace v8 {
123namespace internal {
Andrei Popescu31002712010-02-23 13:46:05 +0000124
125// -----------------------------------------------------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000126// Registers and FPURegisters.
Andrei Popescu31002712010-02-23 13:46:05 +0000127
128// Number of general purpose registers.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100129const int kNumRegisters = 32;
130const int kInvalidRegister = -1;
Andrei Popescu31002712010-02-23 13:46:05 +0000131
132// Number of registers with HI, LO, and pc.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100133const int kNumSimuRegisters = 35;
Andrei Popescu31002712010-02-23 13:46:05 +0000134
135// In the simulator, the PC register is simulated as the 34th register.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100136const int kPCRegister = 34;
Andrei Popescu31002712010-02-23 13:46:05 +0000137
138// Number coprocessor registers.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100139const int kNumFPURegisters = 32;
140const int kInvalidFPURegister = -1;
Andrei Popescu31002712010-02-23 13:46:05 +0000141
Steve Block44f0eee2011-05-26 01:26:41 +0100142// FPU (coprocessor 1) control registers. Currently only FCSR is implemented.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100143const int kFCSRRegister = 31;
144const int kInvalidFPUControlRegister = -1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000145const uint32_t kFPUInvalidResult = static_cast<uint32_t>(1 << 31) - 1;
146const uint64_t kFPU64InvalidResult =
147 static_cast<uint64_t>(static_cast<uint64_t>(1) << 63) - 1;
Steve Block44f0eee2011-05-26 01:26:41 +0100148
149// FCSR constants.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100150const uint32_t kFCSRInexactFlagBit = 2;
151const uint32_t kFCSRUnderflowFlagBit = 3;
152const uint32_t kFCSROverflowFlagBit = 4;
153const uint32_t kFCSRDivideByZeroFlagBit = 5;
154const uint32_t kFCSRInvalidOpFlagBit = 6;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000155
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100156const uint32_t kFCSRInexactFlagMask = 1 << kFCSRInexactFlagBit;
157const uint32_t kFCSRUnderflowFlagMask = 1 << kFCSRUnderflowFlagBit;
158const uint32_t kFCSROverflowFlagMask = 1 << kFCSROverflowFlagBit;
159const uint32_t kFCSRDivideByZeroFlagMask = 1 << kFCSRDivideByZeroFlagBit;
160const uint32_t kFCSRInvalidOpFlagMask = 1 << kFCSRInvalidOpFlagBit;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000161
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100162const uint32_t kFCSRFlagMask =
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000163 kFCSRInexactFlagMask |
164 kFCSRUnderflowFlagMask |
165 kFCSROverflowFlagMask |
166 kFCSRDivideByZeroFlagMask |
167 kFCSRInvalidOpFlagMask;
168
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100169const uint32_t kFCSRExceptionFlagMask = kFCSRFlagMask ^ kFCSRInexactFlagMask;
Steve Block44f0eee2011-05-26 01:26:41 +0100170
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000171// 'pref' instruction hints
172const int32_t kPrefHintLoad = 0;
173const int32_t kPrefHintStore = 1;
174const int32_t kPrefHintLoadStreamed = 4;
175const int32_t kPrefHintStoreStreamed = 5;
176const int32_t kPrefHintLoadRetained = 6;
177const int32_t kPrefHintStoreRetained = 7;
178const int32_t kPrefHintWritebackInvalidate = 25;
179const int32_t kPrefHintPrepareForStore = 30;
180
Andrei Popescu31002712010-02-23 13:46:05 +0000181// Helper functions for converting between register numbers and names.
182class Registers {
183 public:
184 // Return the name of the register.
185 static const char* Name(int reg);
186
187 // Lookup the register number for the name provided.
188 static int Number(const char* name);
189
190 struct RegisterAlias {
191 int reg;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100192 const char* name;
Andrei Popescu31002712010-02-23 13:46:05 +0000193 };
194
195 static const int32_t kMaxValue = 0x7fffffff;
196 static const int32_t kMinValue = 0x80000000;
197
198 private:
Andrei Popescu31002712010-02-23 13:46:05 +0000199 static const char* names_[kNumSimuRegisters];
200 static const RegisterAlias aliases_[];
201};
202
203// Helper functions for converting between register numbers and names.
Steve Block44f0eee2011-05-26 01:26:41 +0100204class FPURegisters {
Andrei Popescu31002712010-02-23 13:46:05 +0000205 public:
206 // Return the name of the register.
207 static const char* Name(int reg);
208
209 // Lookup the register number for the name provided.
210 static int Number(const char* name);
211
212 struct RegisterAlias {
213 int creg;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100214 const char* name;
Andrei Popescu31002712010-02-23 13:46:05 +0000215 };
216
217 private:
Steve Block44f0eee2011-05-26 01:26:41 +0100218 static const char* names_[kNumFPURegisters];
Andrei Popescu31002712010-02-23 13:46:05 +0000219 static const RegisterAlias aliases_[];
220};
221
222
223// -----------------------------------------------------------------------------
224// Instructions encoding constants.
225
226// On MIPS all instructions are 32 bits.
227typedef int32_t Instr;
228
Andrei Popescu31002712010-02-23 13:46:05 +0000229// Special Software Interrupt codes when used in the presence of the MIPS
230// simulator.
231enum SoftwareInterruptCodes {
232 // Transition to C code.
233 call_rt_redirected = 0xfffff
234};
235
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000236// On MIPS Simulator breakpoints can have different codes:
237// - Breaks between 0 and kMaxWatchpointCode are treated as simple watchpoints,
238// the simulator will run through them and print the registers.
239// - Breaks between kMaxWatchpointCode and kMaxStopCode are treated as stop()
240// instructions (see Assembler::stop()).
241// - Breaks larger than kMaxStopCode are simple breaks, dropping you into the
242// debugger.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100243const uint32_t kMaxWatchpointCode = 31;
244const uint32_t kMaxStopCode = 127;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000245STATIC_ASSERT(kMaxWatchpointCode < kMaxStopCode);
246
247
Andrei Popescu31002712010-02-23 13:46:05 +0000248// ----- Fields offset and length.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100249const int kOpcodeShift = 26;
250const int kOpcodeBits = 6;
251const int kRsShift = 21;
252const int kRsBits = 5;
253const int kRtShift = 16;
254const int kRtBits = 5;
255const int kRdShift = 11;
256const int kRdBits = 5;
257const int kSaShift = 6;
258const int kSaBits = 5;
259const int kFunctionShift = 0;
260const int kFunctionBits = 6;
261const int kLuiShift = 16;
Andrei Popescu31002712010-02-23 13:46:05 +0000262
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100263const int kImm16Shift = 0;
264const int kImm16Bits = 16;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000265const int kImm21Shift = 0;
266const int kImm21Bits = 21;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100267const int kImm26Shift = 0;
268const int kImm26Bits = 26;
269const int kImm28Shift = 0;
270const int kImm28Bits = 28;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000271const int kImm32Shift = 0;
272const int kImm32Bits = 32;
Andrei Popescu31002712010-02-23 13:46:05 +0000273
Ben Murdoch589d6972011-11-30 16:04:58 +0000274// In branches and jumps immediate fields point to words, not bytes,
275// and are therefore shifted by 2.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100276const int kImmFieldShift = 2;
Ben Murdoch589d6972011-11-30 16:04:58 +0000277
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000278const int kFrBits = 5;
279const int kFrShift = 21;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100280const int kFsShift = 11;
281const int kFsBits = 5;
282const int kFtShift = 16;
283const int kFtBits = 5;
284const int kFdShift = 6;
285const int kFdBits = 5;
286const int kFCccShift = 8;
287const int kFCccBits = 3;
288const int kFBccShift = 18;
289const int kFBccBits = 3;
290const int kFBtrueShift = 16;
291const int kFBtrueBits = 1;
Andrei Popescu31002712010-02-23 13:46:05 +0000292
Ben Murdoch257744e2011-11-30 15:57:28 +0000293// ----- Miscellaneous useful masks.
Andrei Popescu31002712010-02-23 13:46:05 +0000294// Instruction bit masks.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100295const int kOpcodeMask = ((1 << kOpcodeBits) - 1) << kOpcodeShift;
296const int kImm16Mask = ((1 << kImm16Bits) - 1) << kImm16Shift;
297const int kImm26Mask = ((1 << kImm26Bits) - 1) << kImm26Shift;
298const int kImm28Mask = ((1 << kImm28Bits) - 1) << kImm28Shift;
299const int kRsFieldMask = ((1 << kRsBits) - 1) << kRsShift;
300const int kRtFieldMask = ((1 << kRtBits) - 1) << kRtShift;
301const int kRdFieldMask = ((1 << kRdBits) - 1) << kRdShift;
302const int kSaFieldMask = ((1 << kSaBits) - 1) << kSaShift;
303const int kFunctionFieldMask = ((1 << kFunctionBits) - 1) << kFunctionShift;
Andrei Popescu31002712010-02-23 13:46:05 +0000304// Misc masks.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100305const int kHiMask = 0xffff << 16;
306const int kLoMask = 0xffff;
307const int kSignMask = 0x80000000;
308const int kJumpAddrMask = (1 << (kImm26Bits + kImmFieldShift)) - 1;
Andrei Popescu31002712010-02-23 13:46:05 +0000309
310// ----- MIPS Opcodes and Function Fields.
311// We use this presentation to stay close to the table representation in
312// MIPS32 Architecture For Programmers, Volume II: The MIPS32 Instruction Set.
313enum Opcode {
314 SPECIAL = 0 << kOpcodeShift,
315 REGIMM = 1 << kOpcodeShift,
316
317 J = ((0 << 3) + 2) << kOpcodeShift,
318 JAL = ((0 << 3) + 3) << kOpcodeShift,
319 BEQ = ((0 << 3) + 4) << kOpcodeShift,
320 BNE = ((0 << 3) + 5) << kOpcodeShift,
321 BLEZ = ((0 << 3) + 6) << kOpcodeShift,
322 BGTZ = ((0 << 3) + 7) << kOpcodeShift,
323
324 ADDI = ((1 << 3) + 0) << kOpcodeShift,
325 ADDIU = ((1 << 3) + 1) << kOpcodeShift,
326 SLTI = ((1 << 3) + 2) << kOpcodeShift,
327 SLTIU = ((1 << 3) + 3) << kOpcodeShift,
328 ANDI = ((1 << 3) + 4) << kOpcodeShift,
329 ORI = ((1 << 3) + 5) << kOpcodeShift,
330 XORI = ((1 << 3) + 6) << kOpcodeShift,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000331 LUI = ((1 << 3) + 7) << kOpcodeShift, // LUI/AUI family.
Andrei Popescu31002712010-02-23 13:46:05 +0000332
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000333 BEQC = ((2 << 3) + 0) << kOpcodeShift,
Ben Murdoch257744e2011-11-30 15:57:28 +0000334 COP1 = ((2 << 3) + 1) << kOpcodeShift, // Coprocessor 1 class.
Andrei Popescu31002712010-02-23 13:46:05 +0000335 BEQL = ((2 << 3) + 4) << kOpcodeShift,
336 BNEL = ((2 << 3) + 5) << kOpcodeShift,
337 BLEZL = ((2 << 3) + 6) << kOpcodeShift,
338 BGTZL = ((2 << 3) + 7) << kOpcodeShift,
339
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000340 DADDI = ((3 << 3) + 0) << kOpcodeShift, // This is also BNEC.
Andrei Popescu31002712010-02-23 13:46:05 +0000341 SPECIAL2 = ((3 << 3) + 4) << kOpcodeShift,
Steve Block44f0eee2011-05-26 01:26:41 +0100342 SPECIAL3 = ((3 << 3) + 7) << kOpcodeShift,
Andrei Popescu31002712010-02-23 13:46:05 +0000343
344 LB = ((4 << 3) + 0) << kOpcodeShift,
Steve Block44f0eee2011-05-26 01:26:41 +0100345 LH = ((4 << 3) + 1) << kOpcodeShift,
346 LWL = ((4 << 3) + 2) << kOpcodeShift,
Andrei Popescu31002712010-02-23 13:46:05 +0000347 LW = ((4 << 3) + 3) << kOpcodeShift,
348 LBU = ((4 << 3) + 4) << kOpcodeShift,
Steve Block44f0eee2011-05-26 01:26:41 +0100349 LHU = ((4 << 3) + 5) << kOpcodeShift,
350 LWR = ((4 << 3) + 6) << kOpcodeShift,
Andrei Popescu31002712010-02-23 13:46:05 +0000351 SB = ((5 << 3) + 0) << kOpcodeShift,
Steve Block44f0eee2011-05-26 01:26:41 +0100352 SH = ((5 << 3) + 1) << kOpcodeShift,
353 SWL = ((5 << 3) + 2) << kOpcodeShift,
Andrei Popescu31002712010-02-23 13:46:05 +0000354 SW = ((5 << 3) + 3) << kOpcodeShift,
Steve Block44f0eee2011-05-26 01:26:41 +0100355 SWR = ((5 << 3) + 6) << kOpcodeShift,
Andrei Popescu31002712010-02-23 13:46:05 +0000356
357 LWC1 = ((6 << 3) + 1) << kOpcodeShift,
358 LDC1 = ((6 << 3) + 5) << kOpcodeShift,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000359 BEQZC = ((6 << 3) + 6) << kOpcodeShift,
360
361 PREF = ((6 << 3) + 3) << kOpcodeShift,
Andrei Popescu31002712010-02-23 13:46:05 +0000362
363 SWC1 = ((7 << 3) + 1) << kOpcodeShift,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000364 SDC1 = ((7 << 3) + 5) << kOpcodeShift,
365 BNEZC = ((7 << 3) + 6) << kOpcodeShift,
366
367 COP1X = ((1 << 4) + 3) << kOpcodeShift
Andrei Popescu31002712010-02-23 13:46:05 +0000368};
369
370enum SecondaryField {
371 // SPECIAL Encoding of Function Field.
372 SLL = ((0 << 3) + 0),
Ben Murdoch589d6972011-11-30 16:04:58 +0000373 MOVCI = ((0 << 3) + 1),
Andrei Popescu31002712010-02-23 13:46:05 +0000374 SRL = ((0 << 3) + 2),
375 SRA = ((0 << 3) + 3),
376 SLLV = ((0 << 3) + 4),
377 SRLV = ((0 << 3) + 6),
378 SRAV = ((0 << 3) + 7),
379
380 JR = ((1 << 3) + 0),
381 JALR = ((1 << 3) + 1),
Steve Block44f0eee2011-05-26 01:26:41 +0100382 MOVZ = ((1 << 3) + 2),
383 MOVN = ((1 << 3) + 3),
Andrei Popescu31002712010-02-23 13:46:05 +0000384 BREAK = ((1 << 3) + 5),
385
386 MFHI = ((2 << 3) + 0),
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000387 CLZ_R6 = ((2 << 3) + 0),
388 CLO_R6 = ((2 << 3) + 1),
Andrei Popescu31002712010-02-23 13:46:05 +0000389 MFLO = ((2 << 3) + 2),
390
391 MULT = ((3 << 3) + 0),
392 MULTU = ((3 << 3) + 1),
393 DIV = ((3 << 3) + 2),
394 DIVU = ((3 << 3) + 3),
395
396 ADD = ((4 << 3) + 0),
397 ADDU = ((4 << 3) + 1),
398 SUB = ((4 << 3) + 2),
399 SUBU = ((4 << 3) + 3),
400 AND = ((4 << 3) + 4),
401 OR = ((4 << 3) + 5),
402 XOR = ((4 << 3) + 6),
403 NOR = ((4 << 3) + 7),
404
405 SLT = ((5 << 3) + 2),
406 SLTU = ((5 << 3) + 3),
407
408 TGE = ((6 << 3) + 0),
409 TGEU = ((6 << 3) + 1),
410 TLT = ((6 << 3) + 2),
411 TLTU = ((6 << 3) + 3),
412 TEQ = ((6 << 3) + 4),
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000413 SELEQZ_S = ((6 << 3) + 5),
Andrei Popescu31002712010-02-23 13:46:05 +0000414 TNE = ((6 << 3) + 6),
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000415 SELNEZ_S = ((6 << 3) + 7),
416
417 // Multiply integers in r6.
418 MUL_MUH = ((3 << 3) + 0), // MUL, MUH.
419 MUL_MUH_U = ((3 << 3) + 1), // MUL_U, MUH_U.
420
421 MUL_OP = ((0 << 3) + 2),
422 MUH_OP = ((0 << 3) + 3),
423 DIV_OP = ((0 << 3) + 2),
424 MOD_OP = ((0 << 3) + 3),
425
426 DIV_MOD = ((3 << 3) + 2),
427 DIV_MOD_U = ((3 << 3) + 3),
Andrei Popescu31002712010-02-23 13:46:05 +0000428
429 // SPECIAL2 Encoding of Function Field.
430 MUL = ((0 << 3) + 2),
Steve Block44f0eee2011-05-26 01:26:41 +0100431 CLZ = ((4 << 3) + 0),
432 CLO = ((4 << 3) + 1),
433
434 // SPECIAL3 Encoding of Function Field.
435 EXT = ((0 << 3) + 0),
436 INS = ((0 << 3) + 4),
Andrei Popescu31002712010-02-23 13:46:05 +0000437
438 // REGIMM encoding of rt Field.
439 BLTZ = ((0 << 3) + 0) << 16,
440 BGEZ = ((0 << 3) + 1) << 16,
441 BLTZAL = ((2 << 3) + 0) << 16,
442 BGEZAL = ((2 << 3) + 1) << 16,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000443 BGEZALL = ((2 << 3) + 3) << 16,
Andrei Popescu31002712010-02-23 13:46:05 +0000444
445 // COP1 Encoding of rs Field.
446 MFC1 = ((0 << 3) + 0) << 21,
Steve Block44f0eee2011-05-26 01:26:41 +0100447 CFC1 = ((0 << 3) + 2) << 21,
Andrei Popescu31002712010-02-23 13:46:05 +0000448 MFHC1 = ((0 << 3) + 3) << 21,
449 MTC1 = ((0 << 3) + 4) << 21,
Steve Block44f0eee2011-05-26 01:26:41 +0100450 CTC1 = ((0 << 3) + 6) << 21,
Andrei Popescu31002712010-02-23 13:46:05 +0000451 MTHC1 = ((0 << 3) + 7) << 21,
452 BC1 = ((1 << 3) + 0) << 21,
453 S = ((2 << 3) + 0) << 21,
454 D = ((2 << 3) + 1) << 21,
455 W = ((2 << 3) + 4) << 21,
456 L = ((2 << 3) + 5) << 21,
457 PS = ((2 << 3) + 6) << 21,
458 // COP1 Encoding of Function Field When rs=S.
Steve Block44f0eee2011-05-26 01:26:41 +0100459 ROUND_L_S = ((1 << 3) + 0),
460 TRUNC_L_S = ((1 << 3) + 1),
461 CEIL_L_S = ((1 << 3) + 2),
462 FLOOR_L_S = ((1 << 3) + 3),
463 ROUND_W_S = ((1 << 3) + 4),
464 TRUNC_W_S = ((1 << 3) + 5),
465 CEIL_W_S = ((1 << 3) + 6),
466 FLOOR_W_S = ((1 << 3) + 7),
Andrei Popescu31002712010-02-23 13:46:05 +0000467 CVT_D_S = ((4 << 3) + 1),
468 CVT_W_S = ((4 << 3) + 4),
469 CVT_L_S = ((4 << 3) + 5),
470 CVT_PS_S = ((4 << 3) + 6),
471 // COP1 Encoding of Function Field When rs=D.
Steve Block44f0eee2011-05-26 01:26:41 +0100472 ADD_D = ((0 << 3) + 0),
473 SUB_D = ((0 << 3) + 1),
474 MUL_D = ((0 << 3) + 2),
475 DIV_D = ((0 << 3) + 3),
476 SQRT_D = ((0 << 3) + 4),
477 ABS_D = ((0 << 3) + 5),
478 MOV_D = ((0 << 3) + 6),
479 NEG_D = ((0 << 3) + 7),
480 ROUND_L_D = ((1 << 3) + 0),
481 TRUNC_L_D = ((1 << 3) + 1),
482 CEIL_L_D = ((1 << 3) + 2),
483 FLOOR_L_D = ((1 << 3) + 3),
484 ROUND_W_D = ((1 << 3) + 4),
485 TRUNC_W_D = ((1 << 3) + 5),
486 CEIL_W_D = ((1 << 3) + 6),
487 FLOOR_W_D = ((1 << 3) + 7),
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000488 MIN = ((3 << 3) + 4),
489 MINA = ((3 << 3) + 5),
490 MAX = ((3 << 3) + 6),
491 MAXA = ((3 << 3) + 7),
Andrei Popescu31002712010-02-23 13:46:05 +0000492 CVT_S_D = ((4 << 3) + 0),
493 CVT_W_D = ((4 << 3) + 4),
494 CVT_L_D = ((4 << 3) + 5),
Steve Block44f0eee2011-05-26 01:26:41 +0100495 C_F_D = ((6 << 3) + 0),
496 C_UN_D = ((6 << 3) + 1),
497 C_EQ_D = ((6 << 3) + 2),
498 C_UEQ_D = ((6 << 3) + 3),
499 C_OLT_D = ((6 << 3) + 4),
500 C_ULT_D = ((6 << 3) + 5),
501 C_OLE_D = ((6 << 3) + 6),
502 C_ULE_D = ((6 << 3) + 7),
Andrei Popescu31002712010-02-23 13:46:05 +0000503 // COP1 Encoding of Function Field When rs=W or L.
504 CVT_S_W = ((4 << 3) + 0),
505 CVT_D_W = ((4 << 3) + 1),
506 CVT_S_L = ((4 << 3) + 0),
507 CVT_D_L = ((4 << 3) + 1),
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000508 BC1EQZ = ((2 << 2) + 1) << 21,
509 BC1NEZ = ((3 << 2) + 1) << 21,
510 // COP1 CMP positive predicates Bit 5..4 = 00.
511 CMP_AF = ((0 << 3) + 0),
512 CMP_UN = ((0 << 3) + 1),
513 CMP_EQ = ((0 << 3) + 2),
514 CMP_UEQ = ((0 << 3) + 3),
515 CMP_LT = ((0 << 3) + 4),
516 CMP_ULT = ((0 << 3) + 5),
517 CMP_LE = ((0 << 3) + 6),
518 CMP_ULE = ((0 << 3) + 7),
519 CMP_SAF = ((1 << 3) + 0),
520 CMP_SUN = ((1 << 3) + 1),
521 CMP_SEQ = ((1 << 3) + 2),
522 CMP_SUEQ = ((1 << 3) + 3),
523 CMP_SSLT = ((1 << 3) + 4),
524 CMP_SSULT = ((1 << 3) + 5),
525 CMP_SLE = ((1 << 3) + 6),
526 CMP_SULE = ((1 << 3) + 7),
527 // COP1 CMP negative predicates Bit 5..4 = 01.
528 CMP_AT = ((2 << 3) + 0), // Reserved, not implemented.
529 CMP_OR = ((2 << 3) + 1),
530 CMP_UNE = ((2 << 3) + 2),
531 CMP_NE = ((2 << 3) + 3),
532 CMP_UGE = ((2 << 3) + 4), // Reserved, not implemented.
533 CMP_OGE = ((2 << 3) + 5), // Reserved, not implemented.
534 CMP_UGT = ((2 << 3) + 6), // Reserved, not implemented.
535 CMP_OGT = ((2 << 3) + 7), // Reserved, not implemented.
536 CMP_SAT = ((3 << 3) + 0), // Reserved, not implemented.
537 CMP_SOR = ((3 << 3) + 1),
538 CMP_SUNE = ((3 << 3) + 2),
539 CMP_SNE = ((3 << 3) + 3),
540 CMP_SUGE = ((3 << 3) + 4), // Reserved, not implemented.
541 CMP_SOGE = ((3 << 3) + 5), // Reserved, not implemented.
542 CMP_SUGT = ((3 << 3) + 6), // Reserved, not implemented.
543 CMP_SOGT = ((3 << 3) + 7), // Reserved, not implemented.
544
545 SEL = ((2 << 3) + 0),
546 SELEQZ_C = ((2 << 3) + 4), // COP1 on FPR registers.
547 SELNEZ_C = ((2 << 3) + 7), // COP1 on FPR registers.
Andrei Popescu31002712010-02-23 13:46:05 +0000548 // COP1 Encoding of Function Field When rs=PS.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000549 // COP1X Encoding of Function Field.
550 MADD_D = ((4 << 3) + 1),
Andrei Popescu31002712010-02-23 13:46:05 +0000551
552 NULLSF = 0
553};
554
555
556// ----- Emulated conditions.
557// On MIPS we use this enum to abstract from conditionnal branch instructions.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000558// The 'U' prefix is used to specify unsigned comparisons.
559// Oppposite conditions must be paired as odd/even numbers
560// because 'NegateCondition' function flips LSB to negate condition.
Andrei Popescu31002712010-02-23 13:46:05 +0000561enum Condition {
562 // Any value < 0 is considered no_condition.
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400563 kNoCondition = -1,
564 overflow = 0,
565 no_overflow = 1,
566 Uless = 2,
567 Ugreater_equal = 3,
568 equal = 4,
569 not_equal = 5,
570 Uless_equal = 6,
571 Ugreater = 7,
572 negative = 8,
573 positive = 9,
574 parity_even = 10,
575 parity_odd = 11,
576 less = 12,
Andrei Popescu31002712010-02-23 13:46:05 +0000577 greater_equal = 13,
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400578 less_equal = 14,
579 greater = 15,
580 ueq = 16, // Unordered or Equal.
581 nue = 17, // Not (Unordered or Equal).
582 cc_always = 18,
Andrei Popescu31002712010-02-23 13:46:05 +0000583
Ben Murdoch257744e2011-11-30 15:57:28 +0000584 // Aliases.
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400585 carry = Uless,
586 not_carry = Ugreater_equal,
587 zero = equal,
588 eq = equal,
589 not_zero = not_equal,
590 ne = not_equal,
591 nz = not_equal,
592 sign = negative,
593 not_sign = positive,
594 mi = negative,
595 pl = positive,
596 hi = Ugreater,
597 ls = Uless_equal,
598 ge = greater_equal,
599 lt = less,
600 gt = greater,
601 le = less_equal,
602 hs = Ugreater_equal,
603 lo = Uless,
604 al = cc_always,
605 cc_default = kNoCondition
Andrei Popescu31002712010-02-23 13:46:05 +0000606};
607
Steve Block44f0eee2011-05-26 01:26:41 +0100608
609// Returns the equivalent of !cc.
610// Negation of the default kNoCondition (-1) results in a non-default
611// no_condition value (-2). As long as tests for no_condition check
612// for condition < 0, this will work as expected.
613inline Condition NegateCondition(Condition cc) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000614 DCHECK(cc != cc_always);
Steve Block44f0eee2011-05-26 01:26:41 +0100615 return static_cast<Condition>(cc ^ 1);
616}
617
618
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000619// Commute a condition such that {a cond b == b cond' a}.
620inline Condition CommuteCondition(Condition cc) {
Steve Block44f0eee2011-05-26 01:26:41 +0100621 switch (cc) {
622 case Uless:
623 return Ugreater;
624 case Ugreater:
625 return Uless;
626 case Ugreater_equal:
627 return Uless_equal;
628 case Uless_equal:
629 return Ugreater_equal;
630 case less:
631 return greater;
632 case greater:
633 return less;
634 case greater_equal:
635 return less_equal;
636 case less_equal:
637 return greater_equal;
638 default:
639 return cc;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000640 }
Steve Block44f0eee2011-05-26 01:26:41 +0100641}
642
643
Andrei Popescu31002712010-02-23 13:46:05 +0000644// ----- Coprocessor conditions.
645enum FPUCondition {
Ben Murdoch589d6972011-11-30 16:04:58 +0000646 kNoFPUCondition = -1,
647
648 F = 0, // False.
649 UN = 1, // Unordered.
650 EQ = 2, // Equal.
651 UEQ = 3, // Unordered or Equal.
652 OLT = 4, // Ordered or Less Than.
653 ULT = 5, // Unordered or Less Than.
654 OLE = 6, // Ordered or Less Than or Equal.
655 ULE = 7 // Unordered or Less Than or Equal.
656};
657
658
659// FPU rounding modes.
660enum FPURoundingMode {
661 RN = 0 << 0, // Round to Nearest.
662 RZ = 1 << 0, // Round towards zero.
663 RP = 2 << 0, // Round towards Plus Infinity.
664 RM = 3 << 0, // Round towards Minus Infinity.
665
666 // Aliases.
667 kRoundToNearest = RN,
668 kRoundToZero = RZ,
669 kRoundToPlusInf = RP,
670 kRoundToMinusInf = RM
671};
672
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100673const uint32_t kFPURoundingModeMask = 3 << 0;
Ben Murdoch589d6972011-11-30 16:04:58 +0000674
675enum CheckForInexactConversion {
676 kCheckForInexactConversion,
677 kDontCheckForInexactConversion
Andrei Popescu31002712010-02-23 13:46:05 +0000678};
679
680
Steve Block44f0eee2011-05-26 01:26:41 +0100681// -----------------------------------------------------------------------------
682// Hints.
683
684// Branch hints are not used on the MIPS. They are defined so that they can
685// appear in shared function signatures, but will be ignored in MIPS
686// implementations.
687enum Hint {
688 no_hint = 0
689};
690
691
692inline Hint NegateHint(Hint hint) {
693 return no_hint;
694}
695
696
697// -----------------------------------------------------------------------------
698// Specific instructions, constants, and masks.
699// These constants are declared in assembler-mips.cc, as they use named
700// registers and other constants.
701
702// addiu(sp, sp, 4) aka Pop() operation or part of Pop(r)
703// operations as post-increment of sp.
704extern const Instr kPopInstruction;
705// addiu(sp, sp, -4) part of Push(r) operation as pre-decrement of sp.
706extern const Instr kPushInstruction;
707// sw(r, MemOperand(sp, 0))
708extern const Instr kPushRegPattern;
Ben Murdoch257744e2011-11-30 15:57:28 +0000709// lw(r, MemOperand(sp, 0))
Steve Block44f0eee2011-05-26 01:26:41 +0100710extern const Instr kPopRegPattern;
711extern const Instr kLwRegFpOffsetPattern;
712extern const Instr kSwRegFpOffsetPattern;
713extern const Instr kLwRegFpNegOffsetPattern;
714extern const Instr kSwRegFpNegOffsetPattern;
715// A mask for the Rt register for push, pop, lw, sw instructions.
716extern const Instr kRtMask;
717extern const Instr kLwSwInstrTypeMask;
718extern const Instr kLwSwInstrArgumentMask;
719extern const Instr kLwSwOffsetMask;
720
Andrei Popescu31002712010-02-23 13:46:05 +0000721// Break 0xfffff, reserved for redirected real time call.
722const Instr rtCallRedirInstr = SPECIAL | BREAK | call_rt_redirected << 6;
723// A nop instruction. (Encoding of sll 0 0 0).
724const Instr nopInstr = 0;
725
726class Instruction {
727 public:
728 enum {
Steve Block44f0eee2011-05-26 01:26:41 +0100729 kInstrSize = 4,
730 kInstrSizeLog2 = 2,
Andrei Popescu31002712010-02-23 13:46:05 +0000731 // On MIPS PC cannot actually be directly accessed. We behave as if PC was
Steve Block44f0eee2011-05-26 01:26:41 +0100732 // always the value of the current instruction being executed.
Andrei Popescu31002712010-02-23 13:46:05 +0000733 kPCReadOffset = 0
734 };
735
736 // Get the raw instruction bits.
737 inline Instr InstructionBits() const {
738 return *reinterpret_cast<const Instr*>(this);
739 }
740
741 // Set the raw instruction bits to value.
742 inline void SetInstructionBits(Instr value) {
743 *reinterpret_cast<Instr*>(this) = value;
744 }
745
746 // Read one particular bit out of the instruction bits.
747 inline int Bit(int nr) const {
748 return (InstructionBits() >> nr) & 1;
749 }
750
751 // Read a bit field out of the instruction bits.
752 inline int Bits(int hi, int lo) const {
753 return (InstructionBits() >> lo) & ((2 << (hi - lo)) - 1);
754 }
755
756 // Instruction type.
757 enum Type {
758 kRegisterType,
759 kImmediateType,
760 kJumpType,
761 kUnsupported = -1
762 };
763
764 // Get the encoding type of the instruction.
765 Type InstructionType() const;
766
767
768 // Accessors for the different named fields used in the MIPS encoding.
Steve Block44f0eee2011-05-26 01:26:41 +0100769 inline Opcode OpcodeValue() const {
Andrei Popescu31002712010-02-23 13:46:05 +0000770 return static_cast<Opcode>(
771 Bits(kOpcodeShift + kOpcodeBits - 1, kOpcodeShift));
772 }
773
Steve Block44f0eee2011-05-26 01:26:41 +0100774 inline int RsValue() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000775 DCHECK(InstructionType() == kRegisterType ||
Andrei Popescu31002712010-02-23 13:46:05 +0000776 InstructionType() == kImmediateType);
777 return Bits(kRsShift + kRsBits - 1, kRsShift);
778 }
779
Steve Block44f0eee2011-05-26 01:26:41 +0100780 inline int RtValue() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000781 DCHECK(InstructionType() == kRegisterType ||
Andrei Popescu31002712010-02-23 13:46:05 +0000782 InstructionType() == kImmediateType);
783 return Bits(kRtShift + kRtBits - 1, kRtShift);
784 }
785
Steve Block44f0eee2011-05-26 01:26:41 +0100786 inline int RdValue() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000787 DCHECK(InstructionType() == kRegisterType);
Andrei Popescu31002712010-02-23 13:46:05 +0000788 return Bits(kRdShift + kRdBits - 1, kRdShift);
789 }
790
Steve Block44f0eee2011-05-26 01:26:41 +0100791 inline int SaValue() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000792 DCHECK(InstructionType() == kRegisterType);
Andrei Popescu31002712010-02-23 13:46:05 +0000793 return Bits(kSaShift + kSaBits - 1, kSaShift);
794 }
795
Steve Block44f0eee2011-05-26 01:26:41 +0100796 inline int FunctionValue() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000797 DCHECK(InstructionType() == kRegisterType ||
Andrei Popescu31002712010-02-23 13:46:05 +0000798 InstructionType() == kImmediateType);
799 return Bits(kFunctionShift + kFunctionBits - 1, kFunctionShift);
800 }
801
Steve Block44f0eee2011-05-26 01:26:41 +0100802 inline int FdValue() const {
803 return Bits(kFdShift + kFdBits - 1, kFdShift);
Andrei Popescu31002712010-02-23 13:46:05 +0000804 }
805
Steve Block44f0eee2011-05-26 01:26:41 +0100806 inline int FsValue() const {
807 return Bits(kFsShift + kFsBits - 1, kFsShift);
808 }
809
810 inline int FtValue() const {
811 return Bits(kFtShift + kFtBits - 1, kFtShift);
812 }
813
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000814 inline int FrValue() const {
815 return Bits(kFrShift + kFrBits -1, kFrShift);
816 }
817
Steve Block44f0eee2011-05-26 01:26:41 +0100818 // Float Compare condition code instruction bits.
819 inline int FCccValue() const {
820 return Bits(kFCccShift + kFCccBits - 1, kFCccShift);
821 }
822
823 // Float Branch condition code instruction bits.
824 inline int FBccValue() const {
825 return Bits(kFBccShift + kFBccBits - 1, kFBccShift);
826 }
827
828 // Float Branch true/false instruction bit.
829 inline int FBtrueValue() const {
830 return Bits(kFBtrueShift + kFBtrueBits - 1, kFBtrueShift);
Andrei Popescu31002712010-02-23 13:46:05 +0000831 }
832
833 // Return the fields at their original place in the instruction encoding.
834 inline Opcode OpcodeFieldRaw() const {
835 return static_cast<Opcode>(InstructionBits() & kOpcodeMask);
836 }
837
838 inline int RsFieldRaw() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000839 DCHECK(InstructionType() == kRegisterType ||
Andrei Popescu31002712010-02-23 13:46:05 +0000840 InstructionType() == kImmediateType);
841 return InstructionBits() & kRsFieldMask;
842 }
843
Steve Block44f0eee2011-05-26 01:26:41 +0100844 // Same as above function, but safe to call within InstructionType().
845 inline int RsFieldRawNoAssert() const {
846 return InstructionBits() & kRsFieldMask;
847 }
848
Andrei Popescu31002712010-02-23 13:46:05 +0000849 inline int RtFieldRaw() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000850 DCHECK(InstructionType() == kRegisterType ||
Andrei Popescu31002712010-02-23 13:46:05 +0000851 InstructionType() == kImmediateType);
852 return InstructionBits() & kRtFieldMask;
853 }
854
855 inline int RdFieldRaw() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000856 DCHECK(InstructionType() == kRegisterType);
Andrei Popescu31002712010-02-23 13:46:05 +0000857 return InstructionBits() & kRdFieldMask;
858 }
859
860 inline int SaFieldRaw() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000861 DCHECK(InstructionType() == kRegisterType);
Andrei Popescu31002712010-02-23 13:46:05 +0000862 return InstructionBits() & kSaFieldMask;
863 }
864
865 inline int FunctionFieldRaw() const {
866 return InstructionBits() & kFunctionFieldMask;
867 }
868
869 // Get the secondary field according to the opcode.
Steve Block44f0eee2011-05-26 01:26:41 +0100870 inline int SecondaryValue() const {
Andrei Popescu31002712010-02-23 13:46:05 +0000871 Opcode op = OpcodeFieldRaw();
872 switch (op) {
873 case SPECIAL:
874 case SPECIAL2:
Steve Block44f0eee2011-05-26 01:26:41 +0100875 return FunctionValue();
Andrei Popescu31002712010-02-23 13:46:05 +0000876 case COP1:
Steve Block44f0eee2011-05-26 01:26:41 +0100877 return RsValue();
Andrei Popescu31002712010-02-23 13:46:05 +0000878 case REGIMM:
Steve Block44f0eee2011-05-26 01:26:41 +0100879 return RtValue();
Andrei Popescu31002712010-02-23 13:46:05 +0000880 default:
881 return NULLSF;
882 }
883 }
884
Steve Block44f0eee2011-05-26 01:26:41 +0100885 inline int32_t Imm16Value() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000886 DCHECK(InstructionType() == kImmediateType);
Andrei Popescu31002712010-02-23 13:46:05 +0000887 return Bits(kImm16Shift + kImm16Bits - 1, kImm16Shift);
888 }
889
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000890 inline int32_t Imm21Value() const {
891 DCHECK(InstructionType() == kImmediateType);
892 return Bits(kImm21Shift + kImm21Bits - 1, kImm21Shift);
893 }
894
Steve Block44f0eee2011-05-26 01:26:41 +0100895 inline int32_t Imm26Value() const {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000896 DCHECK(InstructionType() == kJumpType);
Ben Murdoch589d6972011-11-30 16:04:58 +0000897 return Bits(kImm26Shift + kImm26Bits - 1, kImm26Shift);
Andrei Popescu31002712010-02-23 13:46:05 +0000898 }
899
900 // Say if the instruction should not be used in a branch delay slot.
Steve Block44f0eee2011-05-26 01:26:41 +0100901 bool IsForbiddenInBranchDelay() const;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100902 // Say if the instruction 'links'. e.g. jal, bal.
Steve Block44f0eee2011-05-26 01:26:41 +0100903 bool IsLinkingInstruction() const;
Andrei Popescu31002712010-02-23 13:46:05 +0000904 // Say if the instruction is a break or a trap.
Steve Block44f0eee2011-05-26 01:26:41 +0100905 bool IsTrap() const;
Andrei Popescu31002712010-02-23 13:46:05 +0000906
907 // Instructions are read of out a code stream. The only way to get a
908 // reference to an instruction is to convert a pointer. There is no way
909 // to allocate or create instances of class Instruction.
910 // Use the At(pc) function to create references to Instruction.
Ben Murdoch257744e2011-11-30 15:57:28 +0000911 static Instruction* At(byte* pc) {
Andrei Popescu31002712010-02-23 13:46:05 +0000912 return reinterpret_cast<Instruction*>(pc);
913 }
914
915 private:
916 // We need to prevent the creation of instances of class Instruction.
917 DISALLOW_IMPLICIT_CONSTRUCTORS(Instruction);
918};
919
920
921// -----------------------------------------------------------------------------
922// MIPS assembly various constants.
923
Steve Block44f0eee2011-05-26 01:26:41 +0100924// C/C++ argument slots size.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100925const int kCArgSlotCount = 4;
926const int kCArgsSlotsSize = kCArgSlotCount * Instruction::kInstrSize;
Steve Block44f0eee2011-05-26 01:26:41 +0100927// JS argument slots size.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100928const int kJSArgsSlotsSize = 0 * Instruction::kInstrSize;
Steve Block44f0eee2011-05-26 01:26:41 +0100929// Assembly builtins argument slots size.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100930const int kBArgsSlotsSize = 0 * Instruction::kInstrSize;
Andrei Popescu31002712010-02-23 13:46:05 +0000931
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100932const int kBranchReturnOffset = 2 * Instruction::kInstrSize;
Andrei Popescu31002712010-02-23 13:46:05 +0000933
Steve Block44f0eee2011-05-26 01:26:41 +0100934} } // namespace v8::internal
Andrei Popescu31002712010-02-23 13:46:05 +0000935
936#endif // #ifndef V8_MIPS_CONSTANTS_H_