| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 // Simulator should support ARM5 instructions. | 69 // Simulator should support ARM5 instructions. |
| 70 #if !defined(__arm__) | 70 #if !defined(__arm__) |
| 71 # define CAN_USE_ARMV5_INSTRUCTIONS 1 | 71 # define CAN_USE_ARMV5_INSTRUCTIONS 1 |
| 72 # define CAN_USE_THUMB_INSTRUCTIONS 1 | 72 # define CAN_USE_THUMB_INSTRUCTIONS 1 |
| 73 #endif | 73 #endif |
| 74 | 74 |
| 75 namespace assembler { | 75 namespace assembler { |
| 76 namespace arm { | 76 namespace arm { |
| 77 | 77 |
| 78 // The following enum declarations are identical to declarations in |
| 79 // assembler-thumb2.h, but in a different namespace. Please keep the order and |
| 80 // values consistent, so we can merge the files later easily. |
| 81 |
| 82 // Opcodes for Data-processing instructions (instructions with a type 0 and 1) |
| 83 // as defined in section A3.4 |
| 84 enum Opcode { |
| 85 no_operand = -1, |
| 86 AND = 0, // Logical AND |
| 87 EOR = 1, // Logical Exclusive OR |
| 88 SUB = 2, // Subtract |
| 89 RSB = 3, // Reverse Subtract |
| 90 ADD = 4, // Add |
| 91 ADC = 5, // Add with Carry |
| 92 SBC = 6, // Subtract with Carry |
| 93 RSC = 7, // Reverse Subtract with Carry |
| 94 TST = 8, // Test |
| 95 TEQ = 9, // Test Equivalence |
| 96 CMP = 10, // Compare |
| 97 CMN = 11, // Compare Negated |
| 98 ORR = 12, // Logical (inclusive) OR |
| 99 MOV = 13, // Move |
| 100 BIC = 14, // Bit Clear |
| 101 MVN = 15, // Move Not |
| 102 max_operand = 16 |
| 103 }; |
| 104 |
| 105 enum BitPositions { |
| 106 B0 = 1 << 0, |
| 107 B1 = 1 << 1, |
| 108 B2 = 1 << 2, |
| 109 B3 = 1 << 3, |
| 110 B4 = 1 << 4, |
| 111 B5 = 1 << 5, |
| 112 B6 = 1 << 6, |
| 113 B7 = 1 << 7, |
| 114 B8 = 1 << 8, |
| 115 B9 = 1 << 9, |
| 116 B10 = 1 << 10, |
| 117 B11 = 1 << 11, |
| 118 B12 = 1 << 12, |
| 119 B13 = 1 << 13, |
| 120 B14 = 1 << 14, |
| 121 B15 = 1 << 15, |
| 122 B16 = 1 << 16, |
| 123 B18 = 1 << 18, |
| 124 B19 = 1 << 19, |
| 125 B20 = 1 << 20, |
| 126 B21 = 1 << 21, |
| 127 B22 = 1 << 22, |
| 128 B23 = 1 << 23, |
| 129 B24 = 1 << 24, |
| 130 B25 = 1 << 25, |
| 131 B26 = 1 << 26, |
| 132 B27 = 1 << 27 |
| 133 }; |
| 134 |
| 78 // Number of registers in normal ARM mode. | 135 // Number of registers in normal ARM mode. |
| 79 static const int kNumRegisters = 16; | 136 static const int kNumRegisters = 16; |
| 80 | 137 |
| 81 // VFP support. | 138 // VFP support. |
| 82 static const int kNumVFPRegisters = 48; | 139 static const int kNumVFPRegisters = 48; |
| 83 | 140 |
| 84 // PC is register 15. | 141 // PC is register 15. |
| 85 static const int kPCRegister = 15; | 142 static const int kPCRegister = 15; |
| 86 static const int kNoRegister = -1; | 143 static const int kNoRegister = -1; |
| 87 | 144 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 112 GE = 10, // signed greater than or equal | 169 GE = 10, // signed greater than or equal |
| 113 LT = 11, // signed less than | 170 LT = 11, // signed less than |
| 114 GT = 12, // signed greater than | 171 GT = 12, // signed greater than |
| 115 LE = 13, // signed less than or equal | 172 LE = 13, // signed less than or equal |
| 116 AL = 14, // always (unconditional) | 173 AL = 14, // always (unconditional) |
| 117 special_condition = 15, // special condition (refer to section A3.2.1) | 174 special_condition = 15, // special condition (refer to section A3.2.1) |
| 118 max_condition = 16 | 175 max_condition = 16 |
| 119 }; | 176 }; |
| 120 | 177 |
| 121 | 178 |
| 122 // Opcodes for Data-processing instructions (instructions with a type 0 and 1) | |
| 123 // as defined in section A3.4 | |
| 124 enum Opcode { | |
| 125 no_operand = -1, | |
| 126 AND = 0, // Logical AND | |
| 127 EOR = 1, // Logical Exclusive OR | |
| 128 SUB = 2, // Subtract | |
| 129 RSB = 3, // Reverse Subtract | |
| 130 ADD = 4, // Add | |
| 131 ADC = 5, // Add with Carry | |
| 132 SBC = 6, // Subtract with Carry | |
| 133 RSC = 7, // Reverse Subtract with Carry | |
| 134 TST = 8, // Test | |
| 135 TEQ = 9, // Test Equivalence | |
| 136 CMP = 10, // Compare | |
| 137 CMN = 11, // Compare Negated | |
| 138 ORR = 12, // Logical (inclusive) OR | |
| 139 MOV = 13, // Move | |
| 140 BIC = 14, // Bit Clear | |
| 141 MVN = 15, // Move Not | |
| 142 max_operand = 16 | |
| 143 }; | |
| 144 | |
| 145 | |
| 146 // Some special instructions encoded as a TEQ with S=0 (bit 20). | 179 // Some special instructions encoded as a TEQ with S=0 (bit 20). |
| 147 enum Opcode9Bits { | 180 enum Opcode9Bits { |
| 148 BX = 1, | 181 BX = 1, |
| 149 BXJ = 2, | 182 BXJ = 2, |
| 150 BLX = 3, | 183 BLX = 3, |
| 151 BKPT = 7 | 184 BKPT = 7 |
| 152 }; | 185 }; |
| 153 | 186 |
| 154 | 187 |
| 155 // Some special instructions encoded as a CMN with S=0 (bit 20). | 188 // Some special instructions encoded as a CMN with S=0 (bit 20). |
| 156 enum Opcode11Bits { | 189 enum Opcode11Bits { |
| 157 CLZ = 1 | 190 CLZ = 1 |
| 158 }; | 191 }; |
| 159 | 192 |
| 160 | 193 |
| 161 // S | 194 // S |
| 162 | 195 |
| 163 | 196 |
| 164 // Shifter types for Data-processing operands as defined in section A5.1.2. | 197 // Shifter types for Data-processing operands as defined in section A5.1.2. |
| 165 enum Shift { | 198 enum Shift { |
| 166 no_shift = -1, | 199 no_shift = -1, |
| 200 RRX = -2, |
| 167 LSL = 0, // Logical shift left | 201 LSL = 0, // Logical shift left |
| 168 LSR = 1, // Logical shift right | 202 LSR = 1, // Logical shift right |
| 169 ASR = 2, // Arithmetic shift right | 203 ASR = 2, // Arithmetic shift right |
| 170 ROR = 3, // Rotate right | 204 ROR = 3, // Rotate right |
| 171 max_shift = 4 | 205 max_shift = 4 |
| 172 }; | 206 }; |
| 173 | 207 |
| 174 | 208 |
| 175 // Special Software Interrupt codes when used in the presence of the ARM | 209 // Special Software Interrupt codes when used in the presence of the ARM |
| 176 // simulator. | 210 // simulator. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 195 // Instr* instr = Instr::At(ptr); | 229 // Instr* instr = Instr::At(ptr); |
| 196 // int type = instr->TypeField(); | 230 // int type = instr->TypeField(); |
| 197 // return ((type == 0) || (type == 1)) && instr->HasS(); | 231 // return ((type == 0) || (type == 1)) && instr->HasS(); |
| 198 // } | 232 // } |
| 199 // | 233 // |
| 200 class Instr { | 234 class Instr { |
| 201 public: | 235 public: |
| 202 enum { | 236 enum { |
| 203 kInstrSize = 4, | 237 kInstrSize = 4, |
| 204 kInstrSizeLog2 = 2, | 238 kInstrSizeLog2 = 2, |
| 205 kPCReadOffset = 8 | 239 kPCReadOffset = 8, |
| 240 kPCReadOffsetThumb = 4 |
| 206 }; | 241 }; |
| 207 | 242 |
| 208 // Get the raw instruction bits. | 243 // Get the raw instruction bits. |
| 209 inline instr_t InstructionBits() const { | 244 inline instr_t InstructionBits() const { |
| 210 return *reinterpret_cast<const instr_t*>(this); | 245 return *reinterpret_cast<const instr_t*>(this); |
| 211 } | 246 } |
| 212 | 247 |
| 213 // Set the raw instruction bits to value. | 248 // Set the raw instruction bits to value. |
| 214 inline void SetInstructionBits(instr_t value) { | 249 inline void SetInstructionBits(instr_t value) { |
| 215 *reinterpret_cast<instr_t*>(this) = value; | 250 *reinterpret_cast<instr_t*>(this) = value; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 // Helper functions for converting between VFP register numbers and names. | 373 // Helper functions for converting between VFP register numbers and names. |
| 339 class VFPRegisters { | 374 class VFPRegisters { |
| 340 public: | 375 public: |
| 341 // Return the name of the register. | 376 // Return the name of the register. |
| 342 static const char* Name(int reg); | 377 static const char* Name(int reg); |
| 343 | 378 |
| 344 private: | 379 private: |
| 345 static const char* names_[kNumVFPRegisters]; | 380 static const char* names_[kNumVFPRegisters]; |
| 346 }; | 381 }; |
| 347 | 382 |
| 383 // Thumb2 sepcific stuff starts here |
| 384 enum SetFlags { |
| 385 FALSE = 0, |
| 386 TRUE = 1, |
| 387 AUTO = 2 |
| 388 }; |
| 389 |
| 390 |
| 391 enum Operation { |
| 392 OP_UNSUPPORTED, |
| 393 |
| 394 OP_ADC, OP_ADD, OP_ADR, OP_AND, OP_ASR, |
| 395 |
| 396 OP_B, OP_BFC, OP_BFI, OP_BIC, OP_BKPT, OP_BL, OP_BLX, OP_BX, OP_BXJ, |
| 397 |
| 398 OP_CBNZ, OP_CBZ, OP_CDP, OP_CDP2, OP_CHKA, OP_CLREX, OP_CLZ, OP_CNN, |
| 399 OP_CMN_IMM, OP_CMP, OP_CMP_IMM, OP_CPS, |
| 400 |
| 401 OP_DBG, OP_DMB, OP_DSB, |
| 402 |
| 403 OP_EOR, |
| 404 |
| 405 OP_ISB, OP_IT, |
| 406 |
| 407 OP_LDC, OP_LDC2, OP_LDM, OP_LDMIA, OP_LDMFD, OP_LDMDA, OP_LDMDB, OP_LDMEA, |
| 408 OP_LDMIB, OP_LDMED, OP_LDR, OP_LDR_LITERAL, OP_LDRB, OP_LDRBT, OP_LDRD, |
| 409 OP_LDREX, OP_LDREXB, OP_LDREXD, OP_LDREXH, OP_LDRH, OP_LDRHT, OP_LDRSB, |
| 410 OP_LDRSBT, OP_LDRSH, OP_LDRSHT, OP_LDRT, OP_LSL, OP_LSR, OP_MCR, OP_MCR2, |
| 411 OP_MCRR, OP_MCRR2, OP_MLA, OP_MLS, OP_MOV, OP_MOVT, OP_MRC, OP_MRC2, |
| 412 OP_MRRC, OP_MRRC2, OP_MRS, OP_MSR, OP_MUL, OP_MVN, |
| 413 |
| 414 OP_NEG, OP_NOP, |
| 415 |
| 416 OP_ORN, OP_ORR, OP_PKH, OP_PLD, OP_PLDW, OP_PLI, OP_POP, OP_PUSH, |
| 417 |
| 418 OP_QADD, OP_QADD16, OP_QADD8, OP_QASX, OP_QDADD, OP_QDSUB, OP_QSAX, OP_QSUB, |
| 419 OP_QSUB16, OP_QSUB8, |
| 420 |
| 421 OP_RBIT, OP_REV, OP_REV16, OP_REVSH, OP_RFE, OP_ROR, OP_RRX, OP_RSB, |
| 422 OP_RSC, |
| 423 |
| 424 OP_SADD16, OP_SADD8, OP_SASX, OP_SBC, OP_SBFX, OP_SDIV, OP_SEL, OP_SETEND, |
| 425 OP_SEV, OP_SHADD16, OP_SHADD8, OP_SHASX, OP_SHSAX, OP_SHSUB16, OP_SHSUB8, |
| 426 OP_SMC, OP_SMLABB, OP_SMLABT, OP_SMLATB, OP_SMLATT, OP_SMLAD, OP_SMLAL, |
| 427 OP_SMLALBB, OP_SMLALBT, OP_SMLALTB, OP_SMLALTT, OP_SMLALD, OP_SMLAWB, |
| 428 OP_SMLAWT, OP_SMLSD, OP_SMLSLD, OP_SMMLA, OP_SMMLS, OP_SMMUL, OP_SMUAD, |
| 429 OP_SMULBB, OP_SMULBT, OP_SMULTB, OP_SMULTT, OP_SMULL, OP_SMULWB, OP_SMULWT, |
| 430 OP_SMUSD, OP_SRS, OP_SSAT, OP_SSAT16, OP_SSAX, OP_SSUB16, OP_SSUB8, |
| 431 OP_STC, OP_STC2, OP_STM, OP_STMIA, OP_STMEA, OP_STMDA, OP_STMED, |
| 432 OP_STMDB, OP_STMFD, OP_STMIB, OP_STMFA, OP_STR, OP_STRB, OP_STRBT, OP_STRD, |
| 433 OP_STREX, OP_STREXB, OP_STREXD, OP_STREXH, OP_STRH, OP_STRHT, OP_STRT, OP_SUB, |
| 434 OP_SVC, OP_SWC, OP_SWPB, OP_SXTAB, OP_SXTAB16, OP_SXTAH, OP_SXTB, OP_SXTB16, |
| 435 OP_SXTH, |
| 436 |
| 437 OP_TBB, OP_TBH, OP_TEQ, OP_TST, |
| 438 |
| 439 OP_UADD16, OP_UADD8, OP_UASX, OP_UBFX, OP_UDIV, OP_UHADD16, OP_UHADD8, |
| 440 OP_UHASX, OP_UHSAX, OP_UHSUB16, OP_UHSUB8, OP_UMAAL, OP_UMLAL, OP_UMULL, |
| 441 OP_UQADD16, OP_UQADD8, OP_UQASX, OP_UQSAX, OP_UQSUB16, OP_UQSUB8, |
| 442 OP_USADD8, OP_USADA8, OP_USAT, OP_USAT16, OP_USAX, OP_USUB16, OP_USUB8, |
| 443 OP_UXTAB, OP_UXTAB16, OP_UXTAH, OP_UXTB, OP_UXTB16, OP_UXTH, |
| 444 |
| 445 OP_VABA, OP_VABAL, OP_VABD_INT, OP_VABDL, OP_VABD_FP, OP_VABS, OP_VACGE, |
| 446 OP_VACGT, OP_VACLE, OP_VACLT, OP_VADD_INT, OP_VADD_FP, OP_VADDHN, |
| 447 OP_VADDL, OP_VADDW, OP_VAND, OP_VBIC, OP_VBIF, OP_VBIT, OP_VBSL, |
| 448 OP_VCEQ, OP_VCGE, OP_VCGT, OP_VCLE, OP_VCLS, OP_VCLT, OP_VCLZ, OP_VCMP, |
| 449 OP_VCMPE, OP_VCNT, OP_VCVT, OP_VCVTR, OP_VDIV, OP_VDUP, OP_VEOR, OP_VEXT, |
| 450 OP_VHADD, OP_VHSUB, OP_VLD1, OP_VLD2, OP_VLD3, OP_VLD4, OP_VLDM, |
| 451 OP_VLDR, OP_VMAX, OP_VMIN, OP_VMLA, OP_VMLAL, OP_VMLS, OP_VMLSL, |
| 452 OP_VMOV, OP_VMOVL, OP_VMOVN, OP_VMRS, OP_VMSR, OP_VMUL, OP_VMULL, OP_VMVN, |
| 453 OP_VMVN_IMM, OP_VNEG, OP_VNMLA, OP_VNMLS, OP_VNMUL, OP_VORN, OP_VORR, |
| 454 OP_VPADAL, OP_VPADD, OP_VPADDL, OP_VPMAX, OP_VPMIN, OP_VPOP, OP_VPUSH, |
| 455 OP_VQABS, OP_VQADD, OP_VQDMLAL, OP_VQDMLSL, OP_VQDMULH, OP_VQDMULL, OP_VQMOVN, |
| 456 OP_VQMOVUN, OP_VQNEG, OP_VQRDMULH, OP_VQRSHL, OP_VQRSHRN, OP_VQRSHRUN, |
| 457 OP_VQSHL, OP_VQSHLU, OP_VQSHRN, OP_VQSHRUN, OP_VQSUB, OP_VRADDHN, OP_VRECPE, |
| 458 OP_VRECPS, OP_VREV15, OP_VREV32, OP_VREV64, OP_VRHADD, OP_VRSHL, OP_VRSHR, |
| 459 OP_VRSHRN, OP_VRSQRTE, OP_VRSQRTS, OP_VRSRA, OP_VRSUBHN, OP_VSHL, OP_VSHLL, |
| 460 OP_VSHR, OP_VSHRN, OP_VSLI, OP_VSQRT, OP_VSRA, OP_VSRI, OP_VST1, OP_VST2, |
| 461 OP_VST3, OP_VST4, OP_VSTM, OP_VSTR, OP_VSUB, OP_VSUBHN, OP_VSUBL, OP_VSUBW, |
| 462 OP_VSWP, OP_VTBL, OP_VTBX, OP_VTRN, OP_VTST, OP_VUZP, OP_VZIP, |
| 463 |
| 464 OP_WFE, OP_WFI, |
| 465 |
| 466 OP_YIELD |
| 467 }; |
| 468 |
| 469 enum OpVariant { |
| 470 VARIANT_NONE, |
| 471 VARIANT_REGISTER, |
| 472 VARIANT_IMMEDIATE, |
| 473 VARIANT_REGISTER_SHIFTED_REGISTER, |
| 474 VARIANT_SP_PLUS_IMMEDIATE |
| 475 }; |
| 476 |
| 477 // Thumb 2 Instruction |
| 478 |
| 479 const uint16_t kMax16BitThumbOpcode = 0xe7ff; |
| 480 |
| 481 class InstrThumb2 { |
| 482 public: |
| 483 explicit InstrThumb2(byte* pc); |
| 484 |
| 485 |
| 486 // Get the pc |
| 487 inline byte* Pc() const { |
| 488 return pc_; |
| 489 } |
| 490 |
| 491 inline byte* Address() const { |
| 492 return reinterpret_cast<byte*>(reinterpret_cast<uint32_t>(pc_) & ~1); |
| 493 } |
| 494 |
| 495 // Read one particular bit out of the instruction bits (16 bit or hi). |
| 496 inline int Bit0(int nr) const { |
| 497 return (instr0_ >> nr) & 1; |
| 498 } |
| 499 |
| 500 // Read a bit field out of the instruction bits (16 bit or hi). |
| 501 inline int Bits0(int hi, int lo) const { |
| 502 return (instr0_ >> lo) & ((2 << (hi - lo)) - 1); |
| 503 } |
| 504 |
| 505 // Read one particular bit out of the instruction bits (16 bit or hi). |
| 506 inline int Bit1(int nr) const { |
| 507 return (instr1_ >> nr) & 1; |
| 508 } |
| 509 |
| 510 // Read a bit field out of the instruction bits (16 bit or hi). |
| 511 inline int Bits1(int hi, int lo) const { |
| 512 return (instr1_ >> lo) & ((2 << (hi - lo)) - 1); |
| 513 } |
| 514 |
| 515 inline int Type() const { |
| 516 return type_; |
| 517 } |
| 518 |
| 519 inline int Variant() const { |
| 520 return variant_; |
| 521 } |
| 522 |
| 523 inline bool HasS() const { |
| 524 return s_; |
| 525 } |
| 526 |
| 527 inline int Rd() const { |
| 528 return rd_; |
| 529 } |
| 530 |
| 531 inline int Rm() const { |
| 532 return rm_; |
| 533 } |
| 534 |
| 535 inline int Rn() const { |
| 536 return rn_; |
| 537 } |
| 538 |
| 539 inline int Rs() const { |
| 540 return rs_; |
| 541 } |
| 542 |
| 543 inline int Rt() const { |
| 544 return rt_; |
| 545 } |
| 546 |
| 547 inline int Imm() const { |
| 548 return imm_; |
| 549 } |
| 550 |
| 551 inline int Size() const { |
| 552 return size_; |
| 553 } |
| 554 |
| 555 inline Operation Op() const { |
| 556 return op_; |
| 557 } |
| 558 |
| 559 private: |
| 560 byte* pc_; |
| 561 uint16_t instr0_; |
| 562 uint16_t instr1_; |
| 563 int size_; |
| 564 |
| 565 Operation op_; |
| 566 OpVariant variant_; |
| 567 bool s_; |
| 568 int type_; |
| 569 int rd_; |
| 570 int rm_; |
| 571 int rn_; |
| 572 int rs_; |
| 573 int rt_; |
| 574 int cond_; |
| 575 int imm_; |
| 576 |
| 577 void Decode16(); |
| 578 void Decode32(); |
| 579 |
| 580 void Decode16_Imm11(Operation op, OpVariant variant); |
| 581 void Decode16_Rdn3Imm8(Operation op, OpVariant variant); |
| 582 |
| 583 void Decode32_SRn4XImm3Rd4Imm2Type2Rm4(Operation op, OpVariant variant); |
| 584 void Decode32_ImmX5SRn4XImm3Rd4Imm8(Operation op, OpVariant variant); |
| 585 |
| 586 void DecodeImmShift(); |
| 587 void ThumbExpandImm(); |
| 588 |
| 589 void UnsupportedInstruction(); |
| 590 |
| 591 // We need to prevent the creation of instances of class Instr. |
| 592 DISALLOW_IMPLICIT_CONSTRUCTORS(InstrThumb2); |
| 593 }; |
| 348 | 594 |
| 349 } } // namespace assembler::arm | 595 } } // namespace assembler::arm |
| 350 | 596 |
| 351 #endif // V8_ARM_CONSTANTS_ARM_H_ | 597 #endif // V8_ARM_CONSTANTS_ARM_H_ |
| OLD | NEW |