v8  3.14.5(node0.10.28)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
constants-arm.h
Go to the documentation of this file.
1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef V8_ARM_CONSTANTS_ARM_H_
29 #define V8_ARM_CONSTANTS_ARM_H_
30 
31 // ARM EABI is required.
32 #if defined(__arm__) && !defined(__ARM_EABI__)
33 #error ARM EABI support is required.
34 #endif
35 
36 // This means that interwork-compatible jump instructions are generated. We
37 // want to generate them on the simulator too so it makes snapshots that can
38 // be used on real hardware.
39 #if defined(__THUMB_INTERWORK__) || !defined(__arm__)
40 # define USE_THUMB_INTERWORK 1
41 #endif
42 
43 #if defined(__ARM_ARCH_7A__) || \
44  defined(__ARM_ARCH_7R__) || \
45  defined(__ARM_ARCH_7__)
46 # define CAN_USE_ARMV7_INSTRUCTIONS 1
47 #endif
48 
49 #if defined(__ARM_ARCH_6__) || \
50  defined(__ARM_ARCH_6J__) || \
51  defined(__ARM_ARCH_6K__) || \
52  defined(__ARM_ARCH_6Z__) || \
53  defined(__ARM_ARCH_6ZK__) || \
54  defined(__ARM_ARCH_6T2__) || \
55  defined(CAN_USE_ARMV7_INSTRUCTIONS)
56 # define CAN_USE_ARMV6_INSTRUCTIONS 1
57 #endif
58 
59 #if defined(__ARM_ARCH_5T__) || \
60  defined(__ARM_ARCH_5TE__) || \
61  defined(__ARM_ARCH_5TEJ__) || \
62  defined(CAN_USE_ARMV6_INSTRUCTIONS)
63 # define CAN_USE_ARMV5_INSTRUCTIONS 1
64 # define CAN_USE_THUMB_INSTRUCTIONS 1
65 #endif
66 
67 // Simulator should support ARM5 instructions and unaligned access by default.
68 #if !defined(__arm__)
69 # define CAN_USE_ARMV5_INSTRUCTIONS 1
70 # define CAN_USE_THUMB_INSTRUCTIONS 1
71 
72 # ifndef CAN_USE_UNALIGNED_ACCESSES
73 # define CAN_USE_UNALIGNED_ACCESSES 1
74 # endif
75 
76 #endif
77 
78 // Using blx may yield better code, so use it when required or when available
79 #if defined(USE_THUMB_INTERWORK) || defined(CAN_USE_ARMV5_INSTRUCTIONS)
80 #define USE_BLX 1
81 #endif
82 
83 namespace v8 {
84 namespace internal {
85 
86 // Constant pool marker.
87 const int kConstantPoolMarkerMask = 0xffe00000;
88 const int kConstantPoolMarker = 0x0c000000;
89 const int kConstantPoolLengthMask = 0x001ffff;
90 
91 // Number of registers in normal ARM mode.
92 const int kNumRegisters = 16;
93 
94 // VFP support.
95 const int kNumVFPSingleRegisters = 32;
96 const int kNumVFPDoubleRegisters = 16;
98 
99 // PC is register 15.
100 const int kPCRegister = 15;
101 const int kNoRegister = -1;
102 
103 // -----------------------------------------------------------------------------
104 // Conditions.
105 
106 // Defines constants and accessor classes to assemble, disassemble and
107 // simulate ARM instructions.
108 //
109 // Section references in the code refer to the "ARM Architecture Reference
110 // Manual" from July 2005 (available at http://www.arm.com/miscPDFs/14128.pdf)
111 //
112 // Constants for specific fields are defined in their respective named enums.
113 // General constants are in an anonymous enum in class Instr.
114 
115 // Values for the condition field as defined in section A3.2
116 enum Condition {
118 
119  eq = 0 << 28, // Z set Equal.
120  ne = 1 << 28, // Z clear Not equal.
121  cs = 2 << 28, // C set Unsigned higher or same.
122  cc = 3 << 28, // C clear Unsigned lower.
123  mi = 4 << 28, // N set Negative.
124  pl = 5 << 28, // N clear Positive or zero.
125  vs = 6 << 28, // V set Overflow.
126  vc = 7 << 28, // V clear No overflow.
127  hi = 8 << 28, // C set, Z clear Unsigned higher.
128  ls = 9 << 28, // C clear or Z set Unsigned lower or same.
129  ge = 10 << 28, // N == V Greater or equal.
130  lt = 11 << 28, // N != V Less than.
131  gt = 12 << 28, // Z clear, N == V Greater than.
132  le = 13 << 28, // Z set or N != V Less then or equal
133  al = 14 << 28, // Always.
134 
135  kSpecialCondition = 15 << 28, // Special condition (refer to section A3.2.1).
137 
138  // Aliases.
139  hs = cs, // C set Unsigned higher or same.
140  lo = cc // C clear Unsigned lower.
141 };
142 
143 
145  ASSERT(cond != al);
146  return static_cast<Condition>(cond ^ ne);
147 }
148 
149 
150 // Corresponds to transposing the operands of a comparison.
152  switch (cond) {
153  case lo:
154  return hi;
155  case hi:
156  return lo;
157  case hs:
158  return ls;
159  case ls:
160  return hs;
161  case lt:
162  return gt;
163  case gt:
164  return lt;
165  case ge:
166  return le;
167  case le:
168  return ge;
169  default:
170  return cond;
171  };
172 }
173 
174 
175 // -----------------------------------------------------------------------------
176 // Instructions encoding.
177 
178 // Instr is merely used by the Assembler to distinguish 32bit integers
179 // representing instructions from usual 32 bit values.
180 // Instruction objects are pointers to 32bit values, and provide methods to
181 // access the various ISA fields.
182 typedef int32_t Instr;
183 
184 
185 // Opcodes for Data-processing instructions (instructions with a type 0 and 1)
186 // as defined in section A3.4
187 enum Opcode {
188  AND = 0 << 21, // Logical AND.
189  EOR = 1 << 21, // Logical Exclusive OR.
190  SUB = 2 << 21, // Subtract.
191  RSB = 3 << 21, // Reverse Subtract.
192  ADD = 4 << 21, // Add.
193  ADC = 5 << 21, // Add with Carry.
194  SBC = 6 << 21, // Subtract with Carry.
195  RSC = 7 << 21, // Reverse Subtract with Carry.
196  TST = 8 << 21, // Test.
197  TEQ = 9 << 21, // Test Equivalence.
198  CMP = 10 << 21, // Compare.
199  CMN = 11 << 21, // Compare Negated.
200  ORR = 12 << 21, // Logical (inclusive) OR.
201  MOV = 13 << 21, // Move.
202  BIC = 14 << 21, // Bit Clear.
203  MVN = 15 << 21 // Move Not.
204 };
205 
206 
207 // The bits for bit 7-4 for some type 0 miscellaneous instructions.
209  // With bits 22-21 01.
210  BX = 1 << 4,
211  BXJ = 2 << 4,
212  BLX = 3 << 4,
213  BKPT = 7 << 4,
214 
215  // With bits 22-21 11.
216  CLZ = 1 << 4
217 };
218 
219 
220 // Instruction encoding bits and masks.
221 enum {
222  H = 1 << 5, // Halfword (or byte).
223  S6 = 1 << 6, // Signed (or unsigned).
224  L = 1 << 20, // Load (or store).
225  S = 1 << 20, // Set condition code (or leave unchanged).
226  W = 1 << 21, // Writeback base register (or leave unchanged).
227  A = 1 << 21, // Accumulate in multiply instruction (or not).
228  B = 1 << 22, // Unsigned byte (or word).
229  N = 1 << 22, // Long (or short).
230  U = 1 << 23, // Positive (or negative) offset/index.
231  P = 1 << 24, // Offset/pre-indexed addressing (or post-indexed addressing).
232  I = 1 << 25, // Immediate shifter operand (or not).
233 
234  B4 = 1 << 4,
235  B5 = 1 << 5,
236  B6 = 1 << 6,
237  B7 = 1 << 7,
238  B8 = 1 << 8,
239  B9 = 1 << 9,
240  B12 = 1 << 12,
241  B16 = 1 << 16,
242  B18 = 1 << 18,
243  B19 = 1 << 19,
244  B20 = 1 << 20,
245  B21 = 1 << 21,
246  B22 = 1 << 22,
247  B23 = 1 << 23,
248  B24 = 1 << 24,
249  B25 = 1 << 25,
250  B26 = 1 << 26,
251  B27 = 1 << 27,
252  B28 = 1 << 28,
253 
254  // Instruction bit masks.
255  kCondMask = 15 << 28,
256  kALUMask = 0x6f << 21,
257  kRdMask = 15 << 12, // In str instruction.
258  kCoprocessorMask = 15 << 8,
259  kOpCodeMask = 15 << 21, // In data-processing instructions.
260  kImm24Mask = (1 << 24) - 1,
261  kOff12Mask = (1 << 12) - 1
262 };
263 
264 
265 // -----------------------------------------------------------------------------
266 // Addressing modes and instruction variants.
267 
268 // Condition code updating mode.
269 enum SBit {
270  SetCC = 1 << 20, // Set condition code.
271  LeaveCC = 0 << 20 // Leave condition code unchanged.
272 };
273 
274 
275 // Status register selection.
276 enum SRegister {
277  CPSR = 0 << 22,
278  SPSR = 1 << 22
279 };
280 
281 
282 // Shifter types for Data-processing operands as defined in section A5.1.2.
283 enum ShiftOp {
284  LSL = 0 << 5, // Logical shift left.
285  LSR = 1 << 5, // Logical shift right.
286  ASR = 2 << 5, // Arithmetic shift right.
287  ROR = 3 << 5, // Rotate right.
288 
289  // RRX is encoded as ROR with shift_imm == 0.
290  // Use a special code to make the distinction. The RRX ShiftOp is only used
291  // as an argument, and will never actually be encoded. The Assembler will
292  // detect it and emit the correct ROR shift operand with shift_imm == 0.
293  RRX = -1,
295 };
296 
297 
298 // Status register fields.
300  CPSR_c = CPSR | 1 << 16,
301  CPSR_x = CPSR | 1 << 17,
302  CPSR_s = CPSR | 1 << 18,
303  CPSR_f = CPSR | 1 << 19,
304  SPSR_c = SPSR | 1 << 16,
305  SPSR_x = SPSR | 1 << 17,
306  SPSR_s = SPSR | 1 << 18,
307  SPSR_f = SPSR | 1 << 19
308 };
309 
310 // Status register field mask (or'ed SRegisterField enum values).
311 typedef uint32_t SRegisterFieldMask;
312 
313 
314 // Memory operand addressing mode.
315 enum AddrMode {
316  // Bit encoding P U W.
317  Offset = (8|4|0) << 21, // Offset (without writeback to base).
318  PreIndex = (8|4|1) << 21, // Pre-indexed addressing with writeback.
319  PostIndex = (0|4|0) << 21, // Post-indexed addressing with writeback.
320  NegOffset = (8|0|0) << 21, // Negative offset (without writeback to base).
321  NegPreIndex = (8|0|1) << 21, // Negative pre-indexed with writeback.
322  NegPostIndex = (0|0|0) << 21 // Negative post-indexed with writeback.
323 };
324 
325 
326 // Load/store multiple addressing mode.
328  // Bit encoding P U W .
329  da = (0|0|0) << 21, // Decrement after.
330  ia = (0|4|0) << 21, // Increment after.
331  db = (8|0|0) << 21, // Decrement before.
332  ib = (8|4|0) << 21, // Increment before.
333  da_w = (0|0|1) << 21, // Decrement after with writeback to base.
334  ia_w = (0|4|1) << 21, // Increment after with writeback to base.
335  db_w = (8|0|1) << 21, // Decrement before with writeback to base.
336  ib_w = (8|4|1) << 21, // Increment before with writeback to base.
337 
338  // Alias modes for comparison when writeback does not matter.
339  da_x = (0|0|0) << 21, // Decrement after.
340  ia_x = (0|4|0) << 21, // Increment after.
341  db_x = (8|0|0) << 21, // Decrement before.
342  ib_x = (8|4|0) << 21, // Increment before.
343 
344  kBlockAddrModeMask = (8|4|1) << 21
345 };
346 
347 
348 // Coprocessor load/store operand size.
349 enum LFlag {
350  Long = 1 << 22, // Long load/store coprocessor.
351  Short = 0 << 22 // Short load/store coprocessor.
352 };
353 
354 
355 // -----------------------------------------------------------------------------
356 // Supervisor Call (svc) specific support.
357 
358 // Special Software Interrupt codes when used in the presence of the ARM
359 // simulator.
360 // svc (formerly swi) provides a 24bit immediate value. Use bits 22:0 for
361 // standard SoftwareInterrupCode. Bit 23 is reserved for the stop feature.
363  // transition to C code
365  // break point
366  kBreakpoint= 0x20,
367  // stop
368  kStopCode = 1 << 23
369 };
370 const uint32_t kStopCodeMask = kStopCode - 1;
371 const uint32_t kMaxStopCode = kStopCode - 1;
373 
374 
375 // Type of VFP register. Determines register encoding.
379 };
380 
381 
382 // VFP FPSCR constants.
386 };
387 
388 // This mask does not include the "inexact" or "input denormal" cumulative
389 // exceptions flags, because we usually don't want to check for it.
390 const uint32_t kVFPExceptionMask = 0xf;
391 const uint32_t kVFPInvalidOpExceptionBit = 1 << 0;
392 const uint32_t kVFPOverflowExceptionBit = 1 << 2;
393 const uint32_t kVFPUnderflowExceptionBit = 1 << 3;
394 const uint32_t kVFPInexactExceptionBit = 1 << 4;
395 const uint32_t kVFPFlushToZeroMask = 1 << 24;
396 
397 const uint32_t kVFPNConditionFlagBit = 1 << 31;
398 const uint32_t kVFPZConditionFlagBit = 1 << 30;
399 const uint32_t kVFPCConditionFlagBit = 1 << 29;
400 const uint32_t kVFPVConditionFlagBit = 1 << 28;
401 
402 
403 // VFP rounding modes. See ARM DDI 0406B Page A2-29.
405  RN = 0 << 22, // Round to Nearest.
406  RP = 1 << 22, // Round towards Plus Infinity.
407  RM = 2 << 22, // Round towards Minus Infinity.
408  RZ = 3 << 22, // Round towards zero.
409 
410  // Aliases.
415 };
416 
417 const uint32_t kVFPRoundingModeMask = 3 << 22;
418 
422 };
423 
424 // -----------------------------------------------------------------------------
425 // Hints.
426 
427 // Branch hints are not used on the ARM. They are defined so that they can
428 // appear in shared function signatures, but will be ignored in ARM
429 // implementations.
430 enum Hint { no_hint };
431 
432 // Hints are not used on the arm. Negating is trivial.
433 inline Hint NegateHint(Hint ignored) { return no_hint; }
434 
435 
436 // -----------------------------------------------------------------------------
437 // Specific instructions, constants, and masks.
438 // These constants are declared in assembler-arm.cc, as they use named registers
439 // and other constants.
440 
441 
442 // add(sp, sp, 4) instruction (aka Pop())
443 extern const Instr kPopInstruction;
444 
445 // str(r, MemOperand(sp, 4, NegPreIndex), al) instruction (aka push(r))
446 // register r is not encoded.
447 extern const Instr kPushRegPattern;
448 
449 // ldr(r, MemOperand(sp, 4, PostIndex), al) instruction (aka pop(r))
450 // register r is not encoded.
451 extern const Instr kPopRegPattern;
452 
453 // mov lr, pc
454 extern const Instr kMovLrPc;
455 // ldr rd, [pc, #offset]
456 extern const Instr kLdrPCMask;
457 extern const Instr kLdrPCPattern;
458 // blxcc rm
459 extern const Instr kBlxRegMask;
460 
461 extern const Instr kBlxRegPattern;
462 
463 extern const Instr kMovMvnMask;
464 extern const Instr kMovMvnPattern;
465 extern const Instr kMovMvnFlip;
466 extern const Instr kMovLeaveCCMask;
468 extern const Instr kMovwMask;
469 extern const Instr kMovwPattern;
470 extern const Instr kMovwLeaveCCFlip;
471 extern const Instr kCmpCmnMask;
472 extern const Instr kCmpCmnPattern;
473 extern const Instr kCmpCmnFlip;
474 extern const Instr kAddSubFlip;
475 extern const Instr kAndBicFlip;
476 
477 // A mask for the Rd register for push, pop, ldr, str instructions.
478 extern const Instr kLdrRegFpOffsetPattern;
479 
480 extern const Instr kStrRegFpOffsetPattern;
481 
482 extern const Instr kLdrRegFpNegOffsetPattern;
483 
484 extern const Instr kStrRegFpNegOffsetPattern;
485 
486 extern const Instr kLdrStrInstrTypeMask;
487 extern const Instr kLdrStrInstrArgumentMask;
488 extern const Instr kLdrStrOffsetMask;
489 
490 
491 // -----------------------------------------------------------------------------
492 // Instruction abstraction.
493 
494 // The class Instruction enables access to individual fields defined in the ARM
495 // architecture instruction set encoding as described in figure A3-1.
496 // Note that the Assembler uses typedef int32_t Instr.
497 //
498 // Example: Test whether the instruction at ptr does set the condition code
499 // bits.
500 //
501 // bool InstructionSetsConditionCodes(byte* ptr) {
502 // Instruction* instr = Instruction::At(ptr);
503 // int type = instr->TypeValue();
504 // return ((type == 0) || (type == 1)) && instr->HasS();
505 // }
506 //
507 class Instruction {
508  public:
509  enum {
513  };
514 
515  // Helper macro to define static accessors.
516  // We use the cast to char* trick to bypass the strict anti-aliasing rules.
517  #define DECLARE_STATIC_TYPED_ACCESSOR(return_type, Name) \
518  static inline return_type Name(Instr instr) { \
519  char* temp = reinterpret_cast<char*>(&instr); \
520  return reinterpret_cast<Instruction*>(temp)->Name(); \
521  }
522 
523  #define DECLARE_STATIC_ACCESSOR(Name) DECLARE_STATIC_TYPED_ACCESSOR(int, Name)
524 
525  // Get the raw instruction bits.
526  inline Instr InstructionBits() const {
527  return *reinterpret_cast<const Instr*>(this);
528  }
529 
530  // Set the raw instruction bits to value.
531  inline void SetInstructionBits(Instr value) {
532  *reinterpret_cast<Instr*>(this) = value;
533  }
534 
535  // Read one particular bit out of the instruction bits.
536  inline int Bit(int nr) const {
537  return (InstructionBits() >> nr) & 1;
538  }
539 
540  // Read a bit field's value out of the instruction bits.
541  inline int Bits(int hi, int lo) const {
542  return (InstructionBits() >> lo) & ((2 << (hi - lo)) - 1);
543  }
544 
545  // Read a bit field out of the instruction bits.
546  inline int BitField(int hi, int lo) const {
547  return InstructionBits() & (((2 << (hi - lo)) - 1) << lo);
548  }
549 
550  // Static support.
551 
552  // Read one particular bit out of the instruction bits.
553  static inline int Bit(Instr instr, int nr) {
554  return (instr >> nr) & 1;
555  }
556 
557  // Read the value of a bit field out of the instruction bits.
558  static inline int Bits(Instr instr, int hi, int lo) {
559  return (instr >> lo) & ((2 << (hi - lo)) - 1);
560  }
561 
562 
563  // Read a bit field out of the instruction bits.
564  static inline int BitField(Instr instr, int hi, int lo) {
565  return instr & (((2 << (hi - lo)) - 1) << lo);
566  }
567 
568 
569  // Accessors for the different named fields used in the ARM encoding.
570  // The naming of these accessor corresponds to figure A3-1.
571  //
572  // Two kind of accessors are declared:
573  // - <Name>Field() will return the raw field, i.e. the field's bits at their
574  // original place in the instruction encoding.
575  // e.g. if instr is the 'addgt r0, r1, r2' instruction, encoded as
576  // 0xC0810002 ConditionField(instr) will return 0xC0000000.
577  // - <Name>Value() will return the field value, shifted back to bit 0.
578  // e.g. if instr is the 'addgt r0, r1, r2' instruction, encoded as
579  // 0xC0810002 ConditionField(instr) will return 0xC.
580 
581 
582  // Generally applicable fields
583  inline Condition ConditionValue() const {
584  return static_cast<Condition>(Bits(31, 28));
585  }
586  inline Condition ConditionField() const {
587  return static_cast<Condition>(BitField(31, 28));
588  }
591 
592  inline int TypeValue() const { return Bits(27, 25); }
593 
594  inline int RnValue() const { return Bits(19, 16); }
596  inline int RdValue() const { return Bits(15, 12); }
598 
599  inline int CoprocessorValue() const { return Bits(11, 8); }
600  // Support for VFP.
601  // Vn(19-16) | Vd(15-12) | Vm(3-0)
602  inline int VnValue() const { return Bits(19, 16); }
603  inline int VmValue() const { return Bits(3, 0); }
604  inline int VdValue() const { return Bits(15, 12); }
605  inline int NValue() const { return Bit(7); }
606  inline int MValue() const { return Bit(5); }
607  inline int DValue() const { return Bit(22); }
608  inline int RtValue() const { return Bits(15, 12); }
609  inline int PValue() const { return Bit(24); }
610  inline int UValue() const { return Bit(23); }
611  inline int Opc1Value() const { return (Bit(23) << 2) | Bits(21, 20); }
612  inline int Opc2Value() const { return Bits(19, 16); }
613  inline int Opc3Value() const { return Bits(7, 6); }
614  inline int SzValue() const { return Bit(8); }
615  inline int VLValue() const { return Bit(20); }
616  inline int VCValue() const { return Bit(8); }
617  inline int VAValue() const { return Bits(23, 21); }
618  inline int VBValue() const { return Bits(6, 5); }
619  inline int VFPNRegValue(VFPRegPrecision pre) {
620  return VFPGlueRegValue(pre, 16, 7);
621  }
622  inline int VFPMRegValue(VFPRegPrecision pre) {
623  return VFPGlueRegValue(pre, 0, 5);
624  }
625  inline int VFPDRegValue(VFPRegPrecision pre) {
626  return VFPGlueRegValue(pre, 12, 22);
627  }
628 
629  // Fields used in Data processing instructions
630  inline int OpcodeValue() const {
631  return static_cast<Opcode>(Bits(24, 21));
632  }
633  inline Opcode OpcodeField() const {
634  return static_cast<Opcode>(BitField(24, 21));
635  }
636  inline int SValue() const { return Bit(20); }
637  // with register
638  inline int RmValue() const { return Bits(3, 0); }
640  inline int ShiftValue() const { return static_cast<ShiftOp>(Bits(6, 5)); }
641  inline ShiftOp ShiftField() const {
642  return static_cast<ShiftOp>(BitField(6, 5));
643  }
644  inline int RegShiftValue() const { return Bit(4); }
645  inline int RsValue() const { return Bits(11, 8); }
646  inline int ShiftAmountValue() const { return Bits(11, 7); }
647  // with immediate
648  inline int RotateValue() const { return Bits(11, 8); }
649  inline int Immed8Value() const { return Bits(7, 0); }
650  inline int Immed4Value() const { return Bits(19, 16); }
651  inline int ImmedMovwMovtValue() const {
652  return Immed4Value() << 12 | Offset12Value(); }
653 
654  // Fields used in Load/Store instructions
655  inline int PUValue() const { return Bits(24, 23); }
656  inline int PUField() const { return BitField(24, 23); }
657  inline int BValue() const { return Bit(22); }
658  inline int WValue() const { return Bit(21); }
659  inline int LValue() const { return Bit(20); }
660  // with register uses same fields as Data processing instructions above
661  // with immediate
662  inline int Offset12Value() const { return Bits(11, 0); }
663  // multiple
664  inline int RlistValue() const { return Bits(15, 0); }
665  // extra loads and stores
666  inline int SignValue() const { return Bit(6); }
667  inline int HValue() const { return Bit(5); }
668  inline int ImmedHValue() const { return Bits(11, 8); }
669  inline int ImmedLValue() const { return Bits(3, 0); }
670 
671  // Fields used in Branch instructions
672  inline int LinkValue() const { return Bit(24); }
673  inline int SImmed24Value() const { return ((InstructionBits() << 8) >> 8); }
674 
675  // Fields used in Software interrupt instructions
677  return static_cast<SoftwareInterruptCodes>(Bits(23, 0));
678  }
679 
680  // Test for special encodings of type 0 instructions (extra loads and stores,
681  // as well as multiplications).
682  inline bool IsSpecialType0() const { return (Bit(7) == 1) && (Bit(4) == 1); }
683 
684  // Test for miscellaneous instructions encodings of type 0 instructions.
685  inline bool IsMiscType0() const { return (Bit(24) == 1)
686  && (Bit(23) == 0)
687  && (Bit(20) == 0)
688  && ((Bit(7) == 0)); }
689 
690  // Test for a nop instruction, which falls under type 1.
691  inline bool IsNopType1() const { return Bits(24, 0) == 0x0120F000; }
692 
693  // Test for a stop instruction.
694  inline bool IsStop() const {
695  return (TypeValue() == 7) && (Bit(24) == 1) && (SvcValue() >= kStopCode);
696  }
697 
698  // Special accessors that test for existence of a value.
699  inline bool HasS() const { return SValue() == 1; }
700  inline bool HasB() const { return BValue() == 1; }
701  inline bool HasW() const { return WValue() == 1; }
702  inline bool HasL() const { return LValue() == 1; }
703  inline bool HasU() const { return UValue() == 1; }
704  inline bool HasSign() const { return SignValue() == 1; }
705  inline bool HasH() const { return HValue() == 1; }
706  inline bool HasLink() const { return LinkValue() == 1; }
707 
708  // Decoding the double immediate in the vmov instruction.
709  double DoubleImmedVmov() const;
710 
711  // Instructions are read of out a code stream. The only way to get a
712  // reference to an instruction is to convert a pointer. There is no way
713  // to allocate or create instances of class Instruction.
714  // Use the At(pc) function to create references to Instruction.
715  static Instruction* At(byte* pc) {
716  return reinterpret_cast<Instruction*>(pc);
717  }
718 
719 
720  private:
721  // Join split register codes, depending on single or double precision.
722  // four_bit is the position of the least-significant bit of the four
723  // bit specifier. one_bit is the position of the additional single bit
724  // specifier.
725  inline int VFPGlueRegValue(VFPRegPrecision pre, int four_bit, int one_bit) {
726  if (pre == kSinglePrecision) {
727  return (Bits(four_bit + 3, four_bit) << 1) | Bit(one_bit);
728  }
729  return (Bit(one_bit) << 4) | Bits(four_bit + 3, four_bit);
730  }
731 
732  // We need to prevent the creation of instances of class Instruction.
733  DISALLOW_IMPLICIT_CONSTRUCTORS(Instruction);
734 };
735 
736 
737 // Helper functions for converting between register numbers and names.
738 class Registers {
739  public:
740  // Return the name of the register.
741  static const char* Name(int reg);
742 
743  // Lookup the register number for the name provided.
744  static int Number(const char* name);
745 
746  struct RegisterAlias {
747  int reg;
748  const char* name;
749  };
750 
751  private:
752  static const char* names_[kNumRegisters];
753  static const RegisterAlias aliases_[];
754 };
755 
756 // Helper functions for converting between VFP register numbers and names.
758  public:
759  // Return the name of the register.
760  static const char* Name(int reg, bool is_double);
761 
762  // Lookup the register number for the name provided.
763  // Set flag pointed by is_double to true if register
764  // is double-precision.
765  static int Number(const char* name, bool* is_double);
766 
767  private:
768  static const char* names_[kNumVFPRegisters];
769 };
770 
771 
772 } } // namespace v8::internal
773 
774 #endif // V8_ARM_CONSTANTS_ARM_H_
static int BitField(Instr instr, int hi, int lo)
const Instr kCmpCmnMask
const uint32_t kVFPZConditionFlagBit
const Instr kMovwMask
const int kNumVFPRegisters
Definition: constants-arm.h:97
const Instr kLdrPCMask
const Instr kLdrRegFpOffsetPattern
const Instr kMovwLeaveCCFlip
const Instr kLdrPCPattern
const Instr kMovMvnPattern
const uint32_t kVFPNConditionFlagBit
const uint32_t kVFPInvalidOpExceptionBit
const int kNumRegisters
Definition: constants-arm.h:92
const Instr kMovLrPc
static int Bit(Instr instr, int nr)
const int kPCRegister
const uint32_t kVFPOverflowExceptionBit
int VFPDRegValue(VFPRegPrecision pre)
bool IsSpecialType0() const
const uint32_t kVFPUnderflowExceptionBit
SoftwareInterruptCodes SvcValue() const
static const char * Name(int reg, bool is_double)
int int32_t
Definition: unicode.cc:47
DECLARE_STATIC_TYPED_ACCESSOR(Condition, ConditionValue)
const Instr kAddSubFlip
const Instr kLdrStrOffsetMask
Instr InstructionBits() const
static int Number(const char *name, bool *is_double)
const uint32_t kMaxStopCode
#define ASSERT(condition)
Definition: checks.h:270
const Instr kBlxRegMask
const uint32_t kStopCodeMask
const Instr kCmpCmnPattern
int Bit(int nr) const
const Instr kPopRegPattern
static const char * Name(int reg)
const int kNumVFPSingleRegisters
Definition: constants-arm.h:95
uint8_t byte
Definition: globals.h:156
const Instr kPushRegPattern
const uint32_t kVFPFlushToZeroMask
Condition ReverseCondition(Condition cond)
static Instruction * At(byte *pc)
int ImmedMovwMovtValue() const
const Instr kLdrStrInstrArgumentMask
const int32_t kDefaultStopCode
static int Number(const char *name)
void SetInstructionBits(Instr value)
Hint NegateHint(Hint ignored)
const Instr kLdrRegFpNegOffsetPattern
double DoubleImmedVmov() const
static int Bits(Instr instr, int hi, int lo)
const Instr kAndBicFlip
const Instr kMovLeaveCCMask
const Register pc
int BitField(int hi, int lo) const
const Instr kPopInstruction
const Instr kStrRegFpOffsetPattern
const uint32_t kVFPExceptionMask
Opcode OpcodeField() const
const int kConstantPoolMarker
Definition: constants-arm.h:88
int Bits(int hi, int lo) const
const Instr kMovLeaveCCPattern
const Instr kLdrStrInstrTypeMask
int VFPNRegValue(VFPRegPrecision pre)
const Instr kBlxRegPattern
const uint32_t kVFPVConditionFlagBit
const Instr kMovMvnMask
const uint32_t kVFPInexactExceptionBit
Condition NegateCondition(Condition cond)
const Instr kMovwPattern
uint32_t SRegisterFieldMask
Condition ConditionField() const
ShiftOp ShiftField() const
const int kConstantPoolMarkerMask
Definition: constants-arm.h:87
const Instr kMovMvnFlip
Condition ConditionValue() const
const uint32_t kVFPRoundingModeMask
const int kConstantPoolLengthMask
Definition: constants-arm.h:89
const Instr kStrRegFpNegOffsetPattern
int VFPMRegValue(VFPRegPrecision pre)
const uint32_t kVFPCConditionFlagBit
const int kNumVFPDoubleRegisters
Definition: constants-arm.h:96
const Instr kCmpCmnFlip
const int kNoRegister