| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 #include "native_client/src/trusted/validator_arm/inst_classes.h" | 7 #include "native_client/src/trusted/validator_arm/inst_classes.h" |
| 8 | 8 |
| 9 #include <assert.h> | |
| 10 #include <string.h> | 9 #include <string.h> |
| 11 | 10 |
| 12 // Implementations of instruction classes, for those not completely defined in | 11 // Implementations of instruction classes, for those not completely defined in |
| 13 | 12 |
| 14 namespace nacl_arm_dec { | 13 namespace nacl_arm_dec { |
| 15 | 14 |
| 16 const char* ClassDecoder::name() const { | |
| 17 // This should never be called! | |
| 18 assert(0); | |
| 19 return "???"; | |
| 20 } | |
| 21 | |
| 22 // A utility function: given a modified-immediate-form instruction, extracts | 15 // A utility function: given a modified-immediate-form instruction, extracts |
| 23 // the immediate value. This is used to analyze BIC and TST. | 16 // the immediate value. This is used to analyze BIC and TST. |
| 24 // | 17 // |
| 25 // This encoding is described in Section A5.2.4. | 18 // This encoding is described in Section A5.2.4. |
| 26 static uint32_t get_modified_immediate(Instruction i) { | 19 static uint32_t get_modified_immediate(Instruction i) { |
| 27 int rotation = i.bits(11, 8) * 2; | 20 int rotation = i.bits(11, 8) * 2; |
| 28 uint32_t value = i.bits(7, 0); | 21 uint32_t value = i.bits(7, 0); |
| 29 | 22 |
| 30 if (rotation == 0) return value; | 23 if (rotation == 0) return value; |
| 31 | 24 |
| 32 return (value >> rotation) | (value << (32 - rotation)); | 25 return (value >> rotation) | (value << (32 - rotation)); |
| 33 } | 26 } |
| 34 | 27 |
| 35 // Breakpoint | 28 // Breakpoint |
| 36 | 29 |
| 37 bool Breakpoint::is_literal_pool_head(const Instruction i) const { | 30 bool Breakpoint::is_literal_pool_head(const Instruction i) const { |
| 38 return i.condition() == Instruction::AL | 31 return i.condition() == Instruction::AL |
| 39 && i.bits(19, 8) == 0x777 | 32 && i.bits(19, 8) == 0x777 |
| 40 && i.bits(3, 0) == 0x7; | 33 && i.bits(3, 0) == 0x7; |
| 41 } | 34 } |
| 42 | 35 |
| 43 // Binary4RegisterShiftedOp | 36 // Binary4RegisterShiftedOp |
| 44 SafetyLevel Binary4RegisterShiftedOp::safety(Instruction i) const { | 37 SafetyLevel Binary4RegisterShiftedOp::safety(Instruction i) const { |
| 45 // Unsafe if any register contains PC (ARM restriction). | 38 // Unsafe if any register contains PC (ARM restriction). |
| 46 if ((d_.reg(i) + n_.reg(i) + s_.reg(i) + m_.reg(i))[kRegisterPc]) | 39 if ((d_.reg(i) + n_.reg(i) + s_.reg(i) + m_.reg(i))[kRegisterPc]) |
| 47 return UNPREDICTABLE; | 40 return UNPREDICTABLE; |
| 41 |
| 48 // Note: We would restrict out PC as well for Rd in NaCl, but no need | 42 // Note: We would restrict out PC as well for Rd in NaCl, but no need |
| 49 // since the ARM restriction doesn't allow it anyway. | 43 // since the ARM restriction doesn't allow it anyway. |
| 50 return MAY_BE_SAFE; | 44 return MAY_BE_SAFE; |
| 51 } | 45 } |
| 52 | 46 |
| 53 RegisterList Binary4RegisterShiftedOp::defs(const Instruction i) const { | 47 RegisterList Binary4RegisterShiftedOp::defs(const Instruction i) const { |
| 54 return d_.reg(i) + flags_.reg_if_updated(i); | 48 return d_.reg(i) + flags_.reg_if_updated(i); |
| 55 } | 49 } |
| 56 | 50 |
| 57 // Unary3RegisterShiftedOp | 51 // Unary3RegisterShiftedOp |
| 58 SafetyLevel Unary3RegisterShiftedOp::safety(Instruction i) const { | 52 SafetyLevel Unary3RegisterShiftedOp::safety(Instruction i) const { |
| 59 // Unsafe if any register contains PC (ARM restriction). | 53 // Unsafe if any register contains PC (ARM restriction). |
| 60 if ((d_.reg(i) + s_.reg(i) + m_.reg(i))[kRegisterPc]) return UNPREDICTABLE; | 54 if ((d_.reg(i) + s_.reg(i) + m_.reg(i))[kRegisterPc]) return UNPREDICTABLE; |
| 55 |
| 61 // Note: We would restrict out PC as well for Rd in NaCl, but no need | 56 // Note: We would restrict out PC as well for Rd in NaCl, but no need |
| 62 // since the ARM restriction doesn't allow it anyway. | 57 // since the ARM restriction doesn't allow it anyway. |
| 63 return MAY_BE_SAFE; | 58 return MAY_BE_SAFE; |
| 64 } | 59 } |
| 65 | 60 |
| 66 RegisterList Unary3RegisterShiftedOp::defs(const Instruction i) const { | 61 RegisterList Unary3RegisterShiftedOp::defs(const Instruction i) const { |
| 67 return d_.reg(i) + flags_.reg_if_updated(i); | 62 return d_.reg(i) + flags_.reg_if_updated(i); |
| 68 } | 63 } |
| 69 | 64 |
| 70 // Data processing and arithmetic | 65 // Data processing and arithmetic |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 return kRegisterPc + (PreindexingFlag(i) ? kRegisterLink : kRegisterNone); | 483 return kRegisterPc + (PreindexingFlag(i) ? kRegisterLink : kRegisterNone); |
| 489 } | 484 } |
| 490 | 485 |
| 491 int32_t Branch::branch_target_offset(const Instruction i) const { | 486 int32_t Branch::branch_target_offset(const Instruction i) const { |
| 492 // Sign extend and shift left 2: | 487 // Sign extend and shift left 2: |
| 493 int32_t offset = (int32_t)(i.bits(23, 0) << 8) >> 6; | 488 int32_t offset = (int32_t)(i.bits(23, 0) << 8) >> 6; |
| 494 return offset + 8; // because r15 reads as 8 bytes ahead | 489 return offset + 8; // because r15 reads as 8 bytes ahead |
| 495 } | 490 } |
| 496 | 491 |
| 497 } // namespace | 492 } // namespace |
| OLD | NEW |