| 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/baseline_classes.h" | 7 #include "native_client/src/trusted/validator_arm/baseline_classes.h" |
| 8 | 8 |
| 9 #include <assert.h> | 9 #include <assert.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 // Note: We would restrict out PC as well for Rd in NaCl, but no need | 182 // Note: We would restrict out PC as well for Rd in NaCl, but no need |
| 183 // since the ARM restriction doesn't allow it anyway. | 183 // since the ARM restriction doesn't allow it anyway. |
| 184 return MAY_BE_SAFE; | 184 return MAY_BE_SAFE; |
| 185 } | 185 } |
| 186 | 186 |
| 187 RegisterList Binary4RegisterDualResult::defs(const Instruction i) const { | 187 RegisterList Binary4RegisterDualResult::defs(const Instruction i) const { |
| 188 return RegisterList(d_hi.reg(i)).Add(d_lo.reg(i)). | 188 return RegisterList(d_hi.reg(i)).Add(d_lo.reg(i)). |
| 189 Add(conditions.conds_if_updated(i)); | 189 Add(conditions.conds_if_updated(i)); |
| 190 } | 190 } |
| 191 | 191 |
| 192 // LoadStore2RegisterImmediateOp | 192 // LoadStore2RegisterImm8Op |
| 193 SafetyLevel LoadStore2RegisterImmediateOp::safety(const Instruction i) const { | 193 SafetyLevel LoadStore2RegisterImm8Op::safety(const Instruction i) const { |
| 194 // Arm restrictions for this instruction. | 194 // Arm restrictions for this instruction. |
| 195 if (t.reg(i).Equals(kRegisterPc)) { | 195 if (t.reg(i).Equals(kRegisterPc)) { |
| 196 return UNPREDICTABLE; | 196 return UNPREDICTABLE; |
| 197 } | 197 } |
| 198 | 198 |
| 199 if (HasWriteBack(i) && | 199 if (HasWriteBack(i) && |
| 200 (n.reg(i).Equals(kRegisterPc) || n.reg(i).Equals(t.reg(i)))) { | 200 (n.reg(i).Equals(kRegisterPc) || |
| 201 // NOTE: The manual states that that it is also unpredictable |
| 202 // when HasWriteBack(i) and Rn=Rt. However, the compilers |
| 203 // may not check for this. For the moment, we are changing |
| 204 // the code to ignore this case for stores. |
| 205 // TODO(karl): Should we not allow this? |
| 206 (is_load_ && n.reg(i).Equals(t.reg(i))))) { |
| 201 return UNPREDICTABLE; | 207 return UNPREDICTABLE; |
| 202 } | 208 } |
| 203 | 209 |
| 204 // Don't allow modification of PC (NaCl constraint). | 210 // Don't allow modification of PC (NaCl constraint). |
| 205 if (defs(i).Contains(kRegisterPc)) return FORBIDDEN_OPERANDS; | 211 if (defs(i).Contains(kRegisterPc)) return FORBIDDEN_OPERANDS; |
| 206 | 212 |
| 207 return MAY_BE_SAFE; | 213 return MAY_BE_SAFE; |
| 208 } | 214 } |
| 209 | 215 |
| 210 RegisterList LoadStore2RegisterImmediateOp::immediate_addressing_defs( | 216 RegisterList LoadStore2RegisterImm8Op::immediate_addressing_defs( |
| 211 const Instruction i) const { | 217 const Instruction i) const { |
| 212 return RegisterList(HasWriteBack(i) ? n.reg(i) : kRegisterNone); | 218 return RegisterList(HasWriteBack(i) ? n.reg(i) : kRegisterNone); |
| 213 } | 219 } |
| 214 | 220 |
| 215 Register LoadStore2RegisterImmediateOp::base_address_register( | 221 Register LoadStore2RegisterImm8Op::base_address_register( |
| 216 const Instruction i) const { | 222 const Instruction i) const { |
| 217 return n.reg(i); | 223 return n.reg(i); |
| 218 } | 224 } |
| 219 | 225 |
| 220 // Load2RegisterImmediateOp | 226 // Load2RegisterImm8Op |
| 221 RegisterList Load2RegisterImmediateOp::defs(Instruction i) const { | 227 RegisterList Load2RegisterImm8Op::defs(Instruction i) const { |
| 222 return immediate_addressing_defs(i).Add(t.reg(i)); | 228 return immediate_addressing_defs(i).Add(t.reg(i)); |
| 223 } | 229 } |
| 224 | 230 |
| 225 bool Load2RegisterImmediateOp::offset_is_immediate(Instruction i) const { | 231 bool Load2RegisterImm8Op::offset_is_immediate(Instruction i) const { |
| 226 UNREFERENCED_PARAMETER(i); | 232 UNREFERENCED_PARAMETER(i); |
| 227 return true; | 233 return true; |
| 228 } | 234 } |
| 229 | 235 |
| 230 // Store2RegisterImmediateOp | 236 // Store2RegisterImm8Op |
| 231 RegisterList Store2RegisterImmediateOp::defs(Instruction i) const { | 237 RegisterList Store2RegisterImm8Op::defs(Instruction i) const { |
| 232 return immediate_addressing_defs(i); | 238 return immediate_addressing_defs(i); |
| 233 } | 239 } |
| 234 | 240 |
| 235 // LoadStore2RegisterImmediateDoubleOp | 241 // LoadStore2RegisterImm8DoubleOp |
| 236 SafetyLevel LoadStore2RegisterImmediateDoubleOp:: | 242 SafetyLevel LoadStore2RegisterImm8DoubleOp:: |
| 237 safety(const Instruction i) const { | 243 safety(const Instruction i) const { |
| 238 // Arm restrictions for this instruction, based on double width. | 244 // Arm restrictions for this instruction, based on double width. |
| 239 if (!t.IsEven(i)) { | 245 if (!t.IsEven(i)) { |
| 240 return UNDEFINED; | 246 return UNDEFINED; |
| 241 } | 247 } |
| 242 | 248 |
| 243 if (t2.reg(i).Equals(kRegisterPc)) { | 249 if (t2.reg(i).Equals(kRegisterPc)) { |
| 244 return UNPREDICTABLE; | 250 return UNPREDICTABLE; |
| 245 } | 251 } |
| 246 | 252 |
| 247 if (HasWriteBack(i) && n.reg(i).Equals(t2.reg(i))) { | 253 // NOTE: The manual states that that it is also unpredictable |
| 254 // when HasWriteBack(i) and Rn=Rt2. However, the compilers |
| 255 // may not check for this. For the moment, we are changing |
| 256 // the code to ignore this case for stores. |
| 257 // TODO(karl): Should we not allow this? |
| 258 if (is_load_ && HasWriteBack(i) && n.reg(i).Equals(t2.reg(i))) { |
| 248 return UNPREDICTABLE; | 259 return UNPREDICTABLE; |
| 249 } | 260 } |
| 250 | 261 |
| 251 // Now apply non-double width restrictions for this instruction. | 262 // Now apply non-double width restrictions for this instruction. |
| 252 return LoadStore2RegisterImmediateOp::safety(i); | 263 return LoadStore2RegisterImm8Op::safety(i); |
| 253 } | 264 } |
| 254 | 265 |
| 255 // Load2RegisterImmediateDoubleOp | 266 // Load2RegisterImm8DoubleOp |
| 256 RegisterList Load2RegisterImmediateDoubleOp::defs(Instruction i) const { | 267 RegisterList Load2RegisterImm8DoubleOp::defs(Instruction i) const { |
| 257 return immediate_addressing_defs(i).Add(t.reg(i)).Add(t2.reg(i)); | 268 return immediate_addressing_defs(i).Add(t.reg(i)).Add(t2.reg(i)); |
| 258 } | 269 } |
| 259 | 270 |
| 260 bool Load2RegisterImmediateDoubleOp::offset_is_immediate(Instruction i) const { | 271 bool Load2RegisterImm8DoubleOp::offset_is_immediate(Instruction i) const { |
| 261 UNREFERENCED_PARAMETER(i); | 272 UNREFERENCED_PARAMETER(i); |
| 262 return true; | 273 return true; |
| 263 } | 274 } |
| 264 | 275 |
| 265 // Store2RegisterImmediateDoubleOp | 276 // Store2RegisterImm8DoubleOp |
| 266 RegisterList Store2RegisterImmediateDoubleOp::defs(Instruction i) const { | 277 RegisterList Store2RegisterImm8DoubleOp::defs(Instruction i) const { |
| 278 return immediate_addressing_defs(i); |
| 279 } |
| 280 |
| 281 // LoadStore2RegisterImm12Op |
| 282 SafetyLevel LoadStore2RegisterImm12Op::safety(const Instruction i) const { |
| 283 // Arm restrictions for this instruction. |
| 284 if (HasWriteBack(i) && |
| 285 (n.reg(i).Equals(kRegisterPc) || |
| 286 // NOTE: The manual states that that it is also unpredictable |
| 287 // when HasWriteBack(i) and Rn=Rt. However, the compilers |
| 288 // may not check for this. For the moment, we are changing |
| 289 // the code to ignore this case for stores. |
| 290 // TODO(karl): Should we not allow this? |
| 291 (is_load_ && n.reg(i).Equals(t.reg(i))))) { |
| 292 return UNPREDICTABLE; |
| 293 } |
| 294 |
| 295 // Don't allow modification of PC (NaCl constraint). |
| 296 if (defs(i).Contains(kRegisterPc)) return FORBIDDEN_OPERANDS; |
| 297 |
| 298 // NaCl special restriction to make all load/store immediates behave |
| 299 // the same. |
| 300 if (t.reg(i).Equals(kRegisterPc)) { |
| 301 return FORBIDDEN_OPERANDS; |
| 302 } |
| 303 |
| 304 return MAY_BE_SAFE; |
| 305 } |
| 306 |
| 307 RegisterList LoadStore2RegisterImm12Op::immediate_addressing_defs( |
| 308 const Instruction i) const { |
| 309 return RegisterList(HasWriteBack(i) ? n.reg(i) : kRegisterNone); |
| 310 } |
| 311 |
| 312 Register LoadStore2RegisterImm12Op::base_address_register( |
| 313 const Instruction i) const { |
| 314 return n.reg(i); |
| 315 } |
| 316 |
| 317 // Load2RegisterImm12Op |
| 318 RegisterList Load2RegisterImm12Op::defs(Instruction i) const { |
| 319 return immediate_addressing_defs(i).Add(t.reg(i)); |
| 320 } |
| 321 |
| 322 bool Load2RegisterImm12Op::offset_is_immediate(Instruction i) const { |
| 323 UNREFERENCED_PARAMETER(i); |
| 324 return true; |
| 325 } |
| 326 |
| 327 // Store2RegisterImm12Op |
| 328 RegisterList Store2RegisterImm12Op::defs(Instruction i) const { |
| 267 return immediate_addressing_defs(i); | 329 return immediate_addressing_defs(i); |
| 268 } | 330 } |
| 269 | 331 |
| 270 // LoadStore3RegisterOp | 332 // LoadStore3RegisterOp |
| 271 SafetyLevel LoadStore3RegisterOp::safety(const Instruction i) const { | 333 SafetyLevel LoadStore3RegisterOp::safety(const Instruction i) const { |
| 272 if (indexing.IsPreIndexing(i)) { | 334 if (indexing.IsPreIndexing(i)) { |
| 273 // If pre-indexing is set, the address of the load is computed as the sum | 335 // If pre-indexing is set, the address of the load is computed as the sum |
| 274 // of the two register parameters. We have checked that the first register | 336 // of the two register parameters. We have checked that the first register |
| 275 // is within the sandbox, but this would allow adding an arbitrary value | 337 // is within the sandbox, but this would allow adding an arbitrary value |
| 276 // to it, so it is not safe. (NaCl constraint). | 338 // to it, so it is not safe. (NaCl constraint). |
| 277 return FORBIDDEN; | 339 return FORBIDDEN; |
| 278 } | 340 } |
| 279 | 341 |
| 280 // Arm restrictions for this instruction. | 342 // Arm restrictions for this instruction. |
| 281 if (RegisterList(t.reg(i)).Add(m.reg(i)).Contains(kRegisterPc)) { | 343 if (RegisterList(t.reg(i)).Add(m.reg(i)).Contains(kRegisterPc)) { |
| 282 return UNPREDICTABLE; | 344 return UNPREDICTABLE; |
| 283 } | 345 } |
| 284 | 346 |
| 285 if (HasWriteBack(i) && | 347 if (HasWriteBack(i) && |
| 286 (n.reg(i).Equals(kRegisterPc) || n.reg(i).Equals(t.reg(i)))) { | 348 (n.reg(i).Equals(kRegisterPc) || |
| 349 // NOTE: The manual states that that it is also unpredictable |
| 350 // when HasWriteBack(i) and Rn=Rt. However, the compilers |
| 351 // may not check for this. For the moment, we are changing |
| 352 // the code to ignore this case for stores. |
| 353 // TODO(karl): Should we not allow this? |
| 354 (is_load_ && n.reg(i).Equals(t.reg(i))))) { |
| 287 return UNPREDICTABLE; | 355 return UNPREDICTABLE; |
| 288 } | 356 } |
| 289 | 357 |
| 290 // Don't let addressing writeback alter PC (NaCl constraint). | 358 // Don't let addressing writeback alter PC (NaCl constraint). |
| 291 if (defs(i).Contains(kRegisterPc)) return FORBIDDEN_OPERANDS; | 359 if (defs(i).Contains(kRegisterPc)) return FORBIDDEN_OPERANDS; |
| 292 | 360 |
| 293 return MAY_BE_SAFE; | 361 return MAY_BE_SAFE; |
| 294 } | 362 } |
| 295 | 363 |
| 296 Register LoadStore3RegisterOp::base_address_register( | 364 Register LoadStore3RegisterOp::base_address_register( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 320 SafetyLevel LoadStore3RegisterDoubleOp::safety(const Instruction i) const { | 388 SafetyLevel LoadStore3RegisterDoubleOp::safety(const Instruction i) const { |
| 321 // Arm restrictions for this instruction, based on double width. | 389 // Arm restrictions for this instruction, based on double width. |
| 322 if (!t.IsEven(i)) { | 390 if (!t.IsEven(i)) { |
| 323 return UNDEFINED; | 391 return UNDEFINED; |
| 324 } | 392 } |
| 325 | 393 |
| 326 if (RegisterList(t2.reg(i)).Add(m.reg(i)).Contains(kRegisterPc)) { | 394 if (RegisterList(t2.reg(i)).Add(m.reg(i)).Contains(kRegisterPc)) { |
| 327 return UNPREDICTABLE; | 395 return UNPREDICTABLE; |
| 328 } | 396 } |
| 329 | 397 |
| 330 if (HasWriteBack(i) && n.reg(i).Equals(t2.reg(i))) { | 398 // NOTE: The manual states that that it is also unpredictable |
| 399 // when HasWriteBack(i) and Rn=Rt2. However, the compilers |
| 400 // may not check for this. For the moment, we are changing |
| 401 // the code to ignore this case for stores. |
| 402 // TODO(karl): Should we not allow this? |
| 403 if (is_load_ && HasWriteBack(i) && n.reg(i).Equals(t2.reg(i))) { |
| 331 return UNPREDICTABLE; | 404 return UNPREDICTABLE; |
| 332 } | 405 } |
| 333 | 406 |
| 334 // Now apply non-double width restrictions for this instruction. | 407 // Now apply non-double width restrictions for this instruction. |
| 335 return LoadStore3RegisterOp::safety(i); | 408 return LoadStore3RegisterOp::safety(i); |
| 336 } | 409 } |
| 337 | 410 |
| 338 // Load3RegisterDoubleOp | 411 // Load3RegisterDoubleOp |
| 339 RegisterList Load3RegisterDoubleOp::defs(const Instruction i) const { | 412 RegisterList Load3RegisterDoubleOp::defs(const Instruction i) const { |
| 340 RegisterList defines; | 413 RegisterList defines; |
| 341 defines.Add(t.reg(i)).Add(t2.reg(i)); | 414 defines.Add(t.reg(i)).Add(t2.reg(i)); |
| 342 if (HasWriteBack(i)) { | 415 if (HasWriteBack(i)) { |
| 343 defines.Add(n.reg(i)); | 416 defines.Add(n.reg(i)); |
| 344 } | 417 } |
| 345 return defines; | 418 return defines; |
| 346 } | 419 } |
| 347 | 420 |
| 348 // Store3RegisterDoubleOp | 421 // Store3RegisterDoubleOp |
| 349 RegisterList Store3RegisterDoubleOp::defs(Instruction i) const { | 422 RegisterList Store3RegisterDoubleOp::defs(Instruction i) const { |
| 350 RegisterList defines; | 423 RegisterList defines; |
| 351 if (HasWriteBack(i)) { | 424 if (HasWriteBack(i)) { |
| 352 defines.Add(n.reg(i)); | 425 defines.Add(n.reg(i)); |
| 353 } | 426 } |
| 354 return defines; | 427 return defines; |
| 355 } | 428 } |
| 356 | 429 |
| 430 // LoadStore3RegisterImm5Op |
| 431 SafetyLevel LoadStore3RegisterImm5Op::safety(const Instruction i) const { |
| 432 if (indexing.IsPreIndexing(i)) { |
| 433 // If pre-indexing is set, the address of the load is computed as the sum |
| 434 // of the two register parameters. We have checked that the first register |
| 435 // is within the sandbox, but this would allow adding an arbitrary value |
| 436 // to it, so it is not safe. (NaCl constraint). |
| 437 return FORBIDDEN; |
| 438 } |
| 439 |
| 440 // Arm restrictions for this instruction. |
| 441 if (m.reg(i).Equals(kRegisterPc)) { |
| 442 return UNPREDICTABLE; |
| 443 } |
| 444 |
| 445 if (HasWriteBack(i) && |
| 446 (n.reg(i).Equals(kRegisterPc) || |
| 447 // NOTE: The manual states that that it is also unpredictable |
| 448 // when HasWriteBack(i) and Rn=Rt2. However, the compilers |
| 449 // may not check for this. For the moment, we are changing |
| 450 // the code to ignore this case for stores. |
| 451 // TODO(karl): Should we not allow this? |
| 452 (is_load_ && n.reg(i).Equals(t.reg(i))))) { |
| 453 return UNPREDICTABLE; |
| 454 } |
| 455 |
| 456 // Don't let Rt be Pc (NaCl constraint -- See header file for special |
| 457 // note). |
| 458 if (t.reg(i).Equals(kRegisterPc)) { |
| 459 return FORBIDDEN_OPERANDS; |
| 460 } |
| 461 |
| 462 // Don't let addressing writeback alter PC (NaCl constraint). |
| 463 if (defs(i).Contains(kRegisterPc)) return FORBIDDEN_OPERANDS; |
| 464 |
| 465 return MAY_BE_SAFE; |
| 466 } |
| 467 |
| 468 Register LoadStore3RegisterImm5Op::base_address_register( |
| 469 const Instruction i) const { |
| 470 return n.reg(i); |
| 471 } |
| 472 |
| 473 // Load3RegisterImm5Op |
| 474 RegisterList Load3RegisterImm5Op::defs(const Instruction i) const { |
| 475 RegisterList defines(t.reg(i)); |
| 476 if (HasWriteBack(i)) { |
| 477 defines.Add(n.reg(i)); |
| 478 } |
| 479 return defines; |
| 480 } |
| 481 |
| 482 // Store3RegisterImm5Op |
| 483 RegisterList Store3RegisterImm5Op::defs(Instruction i) const { |
| 484 RegisterList defines; |
| 485 if (HasWriteBack(i)) { |
| 486 defines.Add(n.reg(i)); |
| 487 } |
| 488 return defines; |
| 489 } |
| 490 |
| 357 // Unary2RegisterImmedShiftedOp | 491 // Unary2RegisterImmedShiftedOp |
| 358 SafetyLevel Unary2RegisterImmedShiftedOp::safety(const Instruction i) const { | 492 SafetyLevel Unary2RegisterImmedShiftedOp::safety(const Instruction i) const { |
| 359 // NaCl Constraint. | 493 // NaCl Constraint. |
| 360 if (d.reg(i).Equals(kRegisterPc)) return FORBIDDEN_OPERANDS; | 494 if (d.reg(i).Equals(kRegisterPc)) return FORBIDDEN_OPERANDS; |
| 361 return MAY_BE_SAFE; | 495 return MAY_BE_SAFE; |
| 362 } | 496 } |
| 363 | 497 |
| 364 RegisterList Unary2RegisterImmedShiftedOp::defs(const Instruction i) const { | 498 RegisterList Unary2RegisterImmedShiftedOp::defs(const Instruction i) const { |
| 365 return RegisterList(d.reg(i)).Add(conditions.conds_if_updated(i)); | 499 return RegisterList(d.reg(i)).Add(conditions.conds_if_updated(i)); |
| 366 } | 500 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 if (RegisterList(n.reg(i)).Add(s.reg(i)).Add(m.reg(i)).Contains(kRegisterPc)) | 558 if (RegisterList(n.reg(i)).Add(s.reg(i)).Add(m.reg(i)).Contains(kRegisterPc)) |
| 425 return UNPREDICTABLE; | 559 return UNPREDICTABLE; |
| 426 return MAY_BE_SAFE; | 560 return MAY_BE_SAFE; |
| 427 } | 561 } |
| 428 | 562 |
| 429 RegisterList Binary3RegisterShiftedTest::defs(const Instruction i) const { | 563 RegisterList Binary3RegisterShiftedTest::defs(const Instruction i) const { |
| 430 return RegisterList(conditions.conds_if_updated(i)); | 564 return RegisterList(conditions.conds_if_updated(i)); |
| 431 } | 565 } |
| 432 | 566 |
| 433 } // namespace | 567 } // namespace |
| OLD | NEW |