| 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/actual_classes.h" | 7 #include "native_client/src/trusted/validator_arm/actual_classes.h" |
| 8 | 8 |
| 9 #include <assert.h> | 9 #include <assert.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 } | 176 } |
| 177 | 177 |
| 178 | 178 |
| 179 SafetyLevel StrImmediate::safety(const Instruction i) const { | 179 SafetyLevel StrImmediate::safety(const Instruction i) const { |
| 180 // Arm restrictions for this instruction. | 180 // Arm restrictions for this instruction. |
| 181 if (t.reg(i).Equals(kRegisterPc)) { | 181 if (t.reg(i).Equals(kRegisterPc)) { |
| 182 return UNPREDICTABLE; | 182 return UNPREDICTABLE; |
| 183 } | 183 } |
| 184 | 184 |
| 185 if (HasWriteBack(i) && | 185 if (HasWriteBack(i) && |
| 186 (n.reg(i).Equals(kRegisterPc) || n.reg(i).Equals(t.reg(i)))) { | 186 (n.reg(i).Equals(kRegisterPc))) { |
| 187 // NOTE: The manual states that that it is also unpredictable |
| 188 // when HasWriteBack(i) and Rn=Rt. However, the compilers |
| 189 // may not check for this. For the moment, we are changing |
| 190 // the code to ignore this case for stores. |
| 191 // TODO(karl): Should we not allow this? |
| 187 return UNPREDICTABLE; | 192 return UNPREDICTABLE; |
| 188 } | 193 } |
| 189 | 194 |
| 190 // Don't let addressing writeback alter PC (NaCl constraint). | 195 // Don't let addressing writeback alter PC (NaCl constraint). |
| 191 if (defs(i).Contains(kRegisterPc)) return FORBIDDEN_OPERANDS; | 196 if (defs(i).Contains(kRegisterPc)) return FORBIDDEN_OPERANDS; |
| 192 | 197 |
| 193 return MAY_BE_SAFE; | 198 return MAY_BE_SAFE; |
| 194 } | 199 } |
| 195 | 200 |
| 196 SafetyLevel StrImmediateDouble::safety(const Instruction i) const { | 201 SafetyLevel StrImmediateDouble::safety(const Instruction i) const { |
| 197 // Arm double width restrictions for this instruction. | 202 // Arm double width restrictions for this instruction. |
| 198 if (!t.IsEven(i)) { | 203 if (!t.IsEven(i)) { |
| 199 return UNDEFINED; | 204 return UNDEFINED; |
| 200 } | 205 } |
| 201 | 206 |
| 202 if (t2.reg(i).Equals(kRegisterPc)) { | 207 if (t2.reg(i).Equals(kRegisterPc)) { |
| 203 return UNPREDICTABLE; | 208 return UNPREDICTABLE; |
| 204 } | 209 } |
| 205 | 210 |
| 206 if (HasWriteBack(i) && n.reg(i).Equals(t2.reg(i))) { | 211 // NOTE: The manual states that that it is also unpredictable |
| 207 return UNPREDICTABLE; | 212 // when HasWriteBack(i) and Rn=Rt. However, the compilers |
| 208 } | 213 // may not check for this. For the moment, we are changing |
| 214 // the code to ignore this case for stores. |
| 215 // TODO(karl): Should we not allow this? |
| 216 // if (HasWriteBack(i) && n.reg(i).Equals(t2.reg(i))) { |
| 217 // return UNPREDICTABLE; |
| 218 // } |
| 209 | 219 |
| 210 // Now apply non-double width restrictions for this instruction. | 220 // Now apply non-double width restrictions for this instruction. |
| 211 return StrImmediate::safety(i); | 221 return StrImmediate::safety(i); |
| 212 } | 222 } |
| 213 | 223 |
| 214 SafetyLevel StoreRegister::safety(const Instruction i) const { | 224 SafetyLevel StoreRegister::safety(const Instruction i) const { |
| 215 if (PreindexingFlag(i)) { | 225 if (PreindexingFlag(i)) { |
| 216 // Computes base address by adding two registers -- cannot predict! | 226 // Computes base address by adding two registers -- cannot predict! |
| 217 return FORBIDDEN; | 227 return FORBIDDEN; |
| 218 } | 228 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 243 // to it, so it is not safe. (NaCl constraint). | 253 // to it, so it is not safe. (NaCl constraint). |
| 244 return FORBIDDEN; | 254 return FORBIDDEN; |
| 245 } | 255 } |
| 246 | 256 |
| 247 // Arm restrictions for this instruction. | 257 // Arm restrictions for this instruction. |
| 248 if (RegisterList(t.reg(i)).Add(m.reg(i)).Contains(kRegisterPc)) { | 258 if (RegisterList(t.reg(i)).Add(m.reg(i)).Contains(kRegisterPc)) { |
| 249 return UNPREDICTABLE; | 259 return UNPREDICTABLE; |
| 250 } | 260 } |
| 251 | 261 |
| 252 if (HasWriteBack(i) && | 262 if (HasWriteBack(i) && |
| 253 (n.reg(i).Equals(kRegisterPc) || n.reg(i).Equals(t.reg(i)))) { | 263 (n.reg(i).Equals(kRegisterPc))) { |
| 264 // NOTE: The manual states that that it is also unpredictable |
| 265 // when HasWriteBack(i) and Rn=Rt. However, the compilers |
| 266 // may not check for this. For the moment, we are changing |
| 267 // the code to ignore this case for stores. |
| 268 // TODO(karl): Should we not allow this? |
| 254 return UNPREDICTABLE; | 269 return UNPREDICTABLE; |
| 255 } | 270 } |
| 256 | 271 |
| 257 // Don't let addressing writeback alter PC (NaCl constraint). | 272 // Don't let addressing writeback alter PC (NaCl constraint). |
| 258 if (defs(i).Contains(kRegisterPc)) return FORBIDDEN_OPERANDS; | 273 if (defs(i).Contains(kRegisterPc)) return FORBIDDEN_OPERANDS; |
| 259 | 274 |
| 260 return MAY_BE_SAFE; | 275 return MAY_BE_SAFE; |
| 261 } | 276 } |
| 262 | 277 |
| 263 SafetyLevel StoreExclusive::safety(const Instruction i) const { | 278 SafetyLevel StoreExclusive::safety(const Instruction i) const { |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 // Arm double width restrictions for this instruction. | 439 // Arm double width restrictions for this instruction. |
| 425 if (!t.IsEven(i)) { | 440 if (!t.IsEven(i)) { |
| 426 return UNDEFINED; | 441 return UNDEFINED; |
| 427 } | 442 } |
| 428 | 443 |
| 429 if (RegisterList(t2.reg(i)).Add(m.reg(i)).Contains(kRegisterPc)) { | 444 if (RegisterList(t2.reg(i)).Add(m.reg(i)).Contains(kRegisterPc)) { |
| 430 return UNPREDICTABLE; | 445 return UNPREDICTABLE; |
| 431 } | 446 } |
| 432 | 447 |
| 433 if (HasWriteBack(i) && | 448 if (HasWriteBack(i) && |
| 434 (n.reg(i).Equals(kRegisterPc) || n.reg(i).Equals(t.reg(i)) || | 449 (n.reg(i).Equals(kRegisterPc))) { |
| 435 n.reg(i).Equals(t2.reg(i)))) { | 450 // NOTE: The manual states that that it is also unpredictable |
| 451 // when HasWriteBack(i) and Rn=Rt or Rn=Rt2. However, the compilers |
| 452 // may not check for this. For the moment, we are changing |
| 453 // the code to ignore this case for stores. |
| 454 // TODO(karl): Should we not allow this? |
| 436 return UNPREDICTABLE; | 455 return UNPREDICTABLE; |
| 437 } | 456 } |
| 438 | 457 |
| 439 // Now apply non-double width restrictions for this instruction. | 458 // Now apply non-double width restrictions for this instruction. |
| 440 return StrRegister::safety(i); | 459 return StrRegister::safety(i); |
| 441 } | 460 } |
| 442 | 461 |
| 443 Register LoadExclusive::base_address_register(const Instruction i) const { | 462 Register LoadExclusive::base_address_register(const Instruction i) const { |
| 444 return Rn(i); | 463 return Rn(i); |
| 445 } | 464 } |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 Add(PreindexingFlag(i) ? kRegisterLink : kRegisterNone); | 605 Add(PreindexingFlag(i) ? kRegisterLink : kRegisterNone); |
| 587 } | 606 } |
| 588 | 607 |
| 589 int32_t Branch::branch_target_offset(const Instruction i) const { | 608 int32_t Branch::branch_target_offset(const Instruction i) const { |
| 590 // Sign extend and shift left 2: | 609 // Sign extend and shift left 2: |
| 591 int32_t offset = (int32_t)(i.Bits(23, 0) << 8) >> 6; | 610 int32_t offset = (int32_t)(i.Bits(23, 0) << 8) >> 6; |
| 592 return offset + 8; // because r15 reads as 8 bytes ahead | 611 return offset + 8; // because r15 reads as 8 bytes ahead |
| 593 } | 612 } |
| 594 | 613 |
| 595 } // namespace | 614 } // namespace |
| OLD | NEW |