Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 // describes the bits which are not modifiable. | 152 // describes the bits which are not modifiable. |
| 153 SimSystemRegister(uint32_t value, uint32_t write_ignore_mask) | 153 SimSystemRegister(uint32_t value, uint32_t write_ignore_mask) |
| 154 : value_(value), write_ignore_mask_(write_ignore_mask) { } | 154 : value_(value), write_ignore_mask_(write_ignore_mask) { } |
| 155 | 155 |
| 156 uint32_t value_; | 156 uint32_t value_; |
| 157 uint32_t write_ignore_mask_; | 157 uint32_t write_ignore_mask_; |
| 158 }; | 158 }; |
| 159 | 159 |
| 160 | 160 |
| 161 // Represent a register (r0-r31, v0-v31). | 161 // Represent a register (r0-r31, v0-v31). |
| 162 template<int kSizeInBytes> | |
| 163 class SimRegisterBase { | 162 class SimRegisterBase { |
| 164 public: | 163 public: |
| 165 template<typename T> | 164 void Set(int64_t new_value, unsigned size) { |
| 166 void Set(T new_value, unsigned size = sizeof(T)) { | 165 ASSERT((size == kXRegSizeInBits) || (size == kWRegSizeInBits)); |
| 167 ASSERT(size <= kSizeInBytes); | |
| 168 ASSERT(size <= sizeof(new_value)); | |
| 169 // All AArch64 registers are zero-extending; Writing a W register clears the | 166 // All AArch64 registers are zero-extending; Writing a W register clears the |
| 170 // top bits of the corresponding X register. | 167 // top bits of the corresponding X register. |
| 171 memset(value_, 0, kSizeInBytes); | 168 value_ = new_value; |
| 172 memcpy(value_, &new_value, size); | 169 STATIC_ASSERT(kWRegSizeInBits == kSRegSizeInBits); |
| 170 if (size == kWRegSizeInBits) { | |
| 171 value_ &= kWRegMask; | |
| 172 } | |
| 173 } | |
| 174 | |
| 175 template<typename T> | |
| 176 void Set(T new_value) { | |
| 177 union SetUnion { | |
| 178 int64_t value; | |
| 179 T new_value; | |
| 180 } reg = { 0 }; | |
| 181 STATIC_ASSERT(sizeof(union SetUnion) == sizeof(value_)); | |
| 182 | |
| 183 reg.new_value = new_value; | |
| 184 | |
| 185 value_ = reg.value; | |
|
Sven Panne
2014/03/28 07:57:55
I am slightly worried about using the union trick
| |
| 173 } | 186 } |
| 174 | 187 |
| 175 // Copy 'size' bytes of the register to the result, and zero-extend to fill | 188 // Copy 'size' bytes of the register to the result, and zero-extend to fill |
| 176 // the result. | 189 // the result. |
| 177 template<typename T> | 190 int64_t Get(unsigned size) const { |
| 178 T Get(unsigned size = sizeof(T)) const { | 191 ASSERT(size/8 <= kXRegSize); |
| 179 ASSERT(size <= kSizeInBytes); | 192 int64_t result = value_; |
| 180 T result; | 193 if (size == kSRegSizeInBits) { |
| 181 memset(&result, 0, sizeof(result)); | 194 result &= kSRegMask; |
| 182 memcpy(&result, value_, size); | 195 } |
| 183 return result; | 196 return result; |
| 184 } | 197 } |
| 185 | 198 |
| 199 template<typename T> | |
| 200 T Get() const { | |
| 201 union GetUnion { | |
| 202 int64_t value; | |
| 203 T result; | |
| 204 } reg = { value_ }; | |
| 205 STATIC_ASSERT(sizeof(union GetUnion) == sizeof(value_)); | |
| 206 | |
| 207 return reg.result; | |
|
Sven Panne
2014/03/28 07:57:55
Same concern here as above: The compiler is free t
| |
| 208 } | |
| 209 | |
| 186 protected: | 210 protected: |
| 187 uint8_t value_[kSizeInBytes]; | 211 int64_t value_; |
| 188 }; | 212 }; |
| 189 typedef SimRegisterBase<kXRegSize> SimRegister; // r0-r31 | 213 |
| 190 typedef SimRegisterBase<kDRegSize> SimFPRegister; // v0-v31 | 214 STATIC_ASSERT(kXRegSize == kDRegSize); |
| 215 typedef SimRegisterBase SimRegister; // r0-r31 | |
| 216 typedef SimRegisterBase SimFPRegister; // v0-v31 | |
| 191 | 217 |
| 192 | 218 |
| 193 class Simulator : public DecoderVisitor { | 219 class Simulator : public DecoderVisitor { |
| 194 public: | 220 public: |
| 195 explicit Simulator(Decoder<DispatchingDecoderVisitor>* decoder, | 221 explicit Simulator(Decoder<DispatchingDecoderVisitor>* decoder, |
| 196 Isolate* isolate = NULL, | 222 Isolate* isolate = NULL, |
| 197 FILE* stream = stderr); | 223 FILE* stream = stderr); |
| 198 Simulator(); | 224 Simulator(); |
| 199 ~Simulator(); | 225 ~Simulator(); |
| 200 | 226 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 347 LogProcessorState(); | 373 LogProcessorState(); |
| 348 increment_pc(); | 374 increment_pc(); |
| 349 CheckBreakpoints(); | 375 CheckBreakpoints(); |
| 350 } | 376 } |
| 351 | 377 |
| 352 // Declare all Visitor functions. | 378 // Declare all Visitor functions. |
| 353 #define DECLARE(A) void Visit##A(Instruction* instr); | 379 #define DECLARE(A) void Visit##A(Instruction* instr); |
| 354 VISITOR_LIST(DECLARE) | 380 VISITOR_LIST(DECLARE) |
| 355 #undef DECLARE | 381 #undef DECLARE |
| 356 | 382 |
| 383 bool Reg31ZeroMode(unsigned code, Reg31Mode r31mode) const { | |
| 384 return ((code == 31) && (r31mode == Reg31IsZeroRegister)); | |
| 385 } | |
| 386 | |
| 357 // Register accessors. | 387 // Register accessors. |
| 358 | |
| 359 // Return 'size' bits of the value of an integer register, as the specified | 388 // Return 'size' bits of the value of an integer register, as the specified |
| 360 // type. The value is zero-extended to fill the result. | 389 // type. The value is zero-extended to fill the result. |
| 361 // | 390 // |
| 362 // The only supported values of 'size' are kXRegSizeInBits and | 391 // The only supported values of 'size' are kXRegSizeInBits and |
| 363 // kWRegSizeInBits. | 392 // kWRegSizeInBits. |
| 364 template<typename T> | 393 int64_t reg(unsigned size, unsigned code, |
| 365 T reg(unsigned size, unsigned code, | |
| 366 Reg31Mode r31mode = Reg31IsZeroRegister) const { | 394 Reg31Mode r31mode = Reg31IsZeroRegister) const { |
| 367 unsigned size_in_bytes = size / 8; | |
| 368 ASSERT(size_in_bytes <= sizeof(T)); | |
| 369 ASSERT((size == kXRegSizeInBits) || (size == kWRegSizeInBits)); | 395 ASSERT((size == kXRegSizeInBits) || (size == kWRegSizeInBits)); |
| 370 ASSERT(code < kNumberOfRegisters); | 396 ASSERT(code < kNumberOfRegisters); |
| 371 | 397 |
| 372 if ((code == 31) && (r31mode == Reg31IsZeroRegister)) { | 398 if (Reg31ZeroMode(code, r31mode)) { |
| 373 T result; | 399 return 0; |
| 374 memset(&result, 0, sizeof(result)); | |
| 375 return result; | |
| 376 } | 400 } |
| 377 return registers_[code].Get<T>(size_in_bytes); | 401 return registers_[code].Get(size); |
| 378 } | 402 } |
| 379 | 403 |
| 380 // Like reg(), but infer the access size from the template type. | 404 // Like reg(), but infer the access size from the template type. |
| 381 template<typename T> | 405 template<typename T> |
| 382 T reg(unsigned code, Reg31Mode r31mode = Reg31IsZeroRegister) const { | 406 T reg(unsigned code, Reg31Mode r31mode = Reg31IsZeroRegister) const { |
| 383 return reg<T>(sizeof(T) * 8, code, r31mode); | 407 ASSERT(code < kNumberOfRegisters); |
| 408 if (Reg31ZeroMode(code, r31mode)) { | |
| 409 return 0; | |
| 410 } | |
| 411 return registers_[code].Get<T>(); | |
| 384 } | 412 } |
| 385 | 413 |
| 386 // Common specialized accessors for the reg() template. | 414 // Common specialized accessors for the reg() template. |
| 387 int32_t wreg(unsigned code, | 415 int32_t wreg(unsigned code, |
| 388 Reg31Mode r31mode = Reg31IsZeroRegister) const { | 416 Reg31Mode r31mode = Reg31IsZeroRegister) const { |
| 389 return reg<int32_t>(code, r31mode); | 417 return reg<int32_t>(code, r31mode); |
| 390 } | 418 } |
| 391 | 419 |
| 392 int64_t xreg(unsigned code, | 420 int64_t xreg(unsigned code, |
| 393 Reg31Mode r31mode = Reg31IsZeroRegister) const { | 421 Reg31Mode r31mode = Reg31IsZeroRegister) const { |
| 394 return reg<int64_t>(code, r31mode); | 422 return reg<int64_t>(code, r31mode); |
| 395 } | 423 } |
| 396 | 424 |
| 397 int64_t reg(unsigned size, unsigned code, | |
| 398 Reg31Mode r31mode = Reg31IsZeroRegister) const { | |
| 399 return reg<int64_t>(size, code, r31mode); | |
| 400 } | |
| 401 | |
| 402 // Write 'size' bits of 'value' into an integer register. The value is | 425 // Write 'size' bits of 'value' into an integer register. The value is |
| 403 // zero-extended. This behaviour matches AArch64 register writes. | 426 // zero-extended. This behaviour matches AArch64 register writes. |
| 404 // | 427 // |
| 405 // The only supported values of 'size' are kXRegSizeInBits and | 428 // The only supported values of 'size' are kXRegSizeInBits and |
| 406 // kWRegSizeInBits. | 429 // kWRegSizeInBits. |
| 407 template<typename T> | 430 template<typename T> |
| 408 void set_reg(unsigned size, unsigned code, T value, | 431 void set_reg(unsigned size, unsigned code, T value, |
| 409 Reg31Mode r31mode = Reg31IsZeroRegister) { | 432 Reg31Mode r31mode = Reg31IsZeroRegister) { |
| 410 unsigned size_in_bytes = size / 8; | |
| 411 ASSERT(size_in_bytes <= sizeof(T)); | |
| 412 ASSERT((size == kXRegSizeInBits) || (size == kWRegSizeInBits)); | 433 ASSERT((size == kXRegSizeInBits) || (size == kWRegSizeInBits)); |
| 413 ASSERT(code < kNumberOfRegisters); | 434 ASSERT(code < kNumberOfRegisters); |
| 414 | 435 |
| 415 if ((code == 31) && (r31mode == Reg31IsZeroRegister)) { | 436 if (!Reg31ZeroMode(code, r31mode)) |
| 416 return; | 437 registers_[code].Set(value, size); |
| 417 } | |
| 418 return registers_[code].Set(value, size_in_bytes); | |
| 419 } | 438 } |
| 420 | 439 |
| 421 // Like set_reg(), but infer the access size from the template type. | 440 // Like set_reg(), but infer the access size from the template type. |
| 422 template<typename T> | 441 template<typename T> |
| 423 void set_reg(unsigned code, T value, | 442 void set_reg(unsigned code, T value, |
| 424 Reg31Mode r31mode = Reg31IsZeroRegister) { | 443 Reg31Mode r31mode = Reg31IsZeroRegister) { |
| 425 set_reg(sizeof(value) * 8, code, value, r31mode); | 444 ASSERT(code < kNumberOfRegisters); |
| 445 if (!Reg31ZeroMode(code, r31mode)) | |
| 446 registers_[code].Set(value); | |
| 426 } | 447 } |
| 427 | 448 |
| 428 // Common specialized accessors for the set_reg() template. | 449 // Common specialized accessors for the set_reg() template. |
| 429 void set_wreg(unsigned code, int32_t value, | 450 void set_wreg(unsigned code, int32_t value, |
| 430 Reg31Mode r31mode = Reg31IsZeroRegister) { | 451 Reg31Mode r31mode = Reg31IsZeroRegister) { |
| 431 set_reg(kWRegSizeInBits, code, value, r31mode); | 452 set_reg(code, value, r31mode); |
| 432 } | 453 } |
| 433 | 454 |
| 434 void set_xreg(unsigned code, int64_t value, | 455 void set_xreg(unsigned code, int64_t value, |
| 435 Reg31Mode r31mode = Reg31IsZeroRegister) { | 456 Reg31Mode r31mode = Reg31IsZeroRegister) { |
| 436 set_reg(kXRegSizeInBits, code, value, r31mode); | 457 set_reg(code, value, r31mode); |
| 437 } | 458 } |
| 438 | 459 |
| 439 // Commonly-used special cases. | 460 // Commonly-used special cases. |
| 440 template<typename T> | 461 template<typename T> |
| 441 void set_lr(T value) { | 462 void set_lr(T value) { |
| 442 ASSERT(sizeof(T) == kPointerSize); | 463 ASSERT(sizeof(T) == kPointerSize); |
| 443 set_reg(kLinkRegCode, value); | 464 set_reg(kLinkRegCode, value); |
| 444 } | 465 } |
| 445 | 466 |
| 446 template<typename T> | 467 template<typename T> |
| 447 void set_sp(T value) { | 468 void set_sp(T value) { |
| 448 ASSERT(sizeof(T) == kPointerSize); | 469 ASSERT(sizeof(T) == kPointerSize); |
| 449 set_reg(31, value, Reg31IsStackPointer); | 470 set_reg(31, value, Reg31IsStackPointer); |
| 450 } | 471 } |
| 451 | 472 |
| 452 int64_t sp() { return xreg(31, Reg31IsStackPointer); } | 473 int64_t sp() { return xreg(31, Reg31IsStackPointer); } |
| 453 int64_t jssp() { return xreg(kJSSPCode, Reg31IsStackPointer); } | 474 int64_t jssp() { return xreg(kJSSPCode, Reg31IsStackPointer); } |
| 454 int64_t fp() { | 475 int64_t fp() { |
| 455 return xreg(kFramePointerRegCode, Reg31IsStackPointer); | 476 return xreg(kFramePointerRegCode, Reg31IsStackPointer); |
| 456 } | 477 } |
| 457 Instruction* lr() { return reg<Instruction*>(kLinkRegCode); } | 478 Instruction* lr() { return reg<Instruction*>(kLinkRegCode); } |
| 458 | 479 |
| 459 Address get_sp() { return reg<Address>(31, Reg31IsStackPointer); } | 480 Address get_sp() { return reg<Address>(31, Reg31IsStackPointer); } |
| 460 | 481 |
| 461 // Return 'size' bits of the value of a floating-point register, as the | |
| 462 // specified type. The value is zero-extended to fill the result. | |
| 463 // | |
| 464 // The only supported values of 'size' are kDRegSizeInBits and | |
| 465 // kSRegSizeInBits. | |
| 466 template<typename T> | |
| 467 T fpreg(unsigned size, unsigned code) const { | |
| 468 unsigned size_in_bytes = size / 8; | |
| 469 ASSERT(size_in_bytes <= sizeof(T)); | |
| 470 ASSERT((size == kDRegSizeInBits) || (size == kSRegSizeInBits)); | |
| 471 ASSERT(code < kNumberOfFPRegisters); | |
| 472 return fpregisters_[code].Get<T>(size_in_bytes); | |
| 473 } | |
| 474 | |
| 475 // Like fpreg(), but infer the access size from the template type. | |
| 476 template<typename T> | 482 template<typename T> |
| 477 T fpreg(unsigned code) const { | 483 T fpreg(unsigned code) const { |
| 478 return fpreg<T>(sizeof(T) * 8, code); | 484 ASSERT(code < kNumberOfRegisters); |
| 485 return fpregisters_[code].Get<T>(); | |
| 479 } | 486 } |
| 480 | 487 |
| 481 // Common specialized accessors for the fpreg() template. | 488 // Common specialized accessors for the fpreg() template. |
| 482 float sreg(unsigned code) const { | 489 float sreg(unsigned code) const { |
| 483 return fpreg<float>(code); | 490 return fpreg<float>(code); |
| 484 } | 491 } |
| 485 | 492 |
| 486 uint32_t sreg_bits(unsigned code) const { | 493 uint32_t sreg_bits(unsigned code) const { |
| 487 return fpreg<uint32_t>(code); | 494 return fpreg<uint32_t>(code); |
| 488 } | 495 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 504 return 0.0; | 511 return 0.0; |
| 505 } | 512 } |
| 506 } | 513 } |
| 507 | 514 |
| 508 // Write 'value' into a floating-point register. The value is zero-extended. | 515 // Write 'value' into a floating-point register. The value is zero-extended. |
| 509 // This behaviour matches AArch64 register writes. | 516 // This behaviour matches AArch64 register writes. |
| 510 template<typename T> | 517 template<typename T> |
| 511 void set_fpreg(unsigned code, T value) { | 518 void set_fpreg(unsigned code, T value) { |
| 512 ASSERT((sizeof(value) == kDRegSize) || (sizeof(value) == kSRegSize)); | 519 ASSERT((sizeof(value) == kDRegSize) || (sizeof(value) == kSRegSize)); |
| 513 ASSERT(code < kNumberOfFPRegisters); | 520 ASSERT(code < kNumberOfFPRegisters); |
| 514 fpregisters_[code].Set(value, sizeof(value)); | 521 fpregisters_[code].Set(value); |
| 515 } | 522 } |
| 516 | 523 |
| 517 // Common specialized accessors for the set_fpreg() template. | 524 // Common specialized accessors for the set_fpreg() template. |
| 518 void set_sreg(unsigned code, float value) { | 525 void set_sreg(unsigned code, float value) { |
| 519 set_fpreg(code, value); | 526 set_fpreg(code, value); |
| 520 } | 527 } |
| 521 | 528 |
| 522 void set_sreg_bits(unsigned code, uint32_t value) { | 529 void set_sreg_bits(unsigned code, uint32_t value) { |
| 523 set_fpreg(code, value); | 530 set_fpreg(code, value); |
| 524 } | 531 } |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 899 static void UnregisterCTryCatch() { | 906 static void UnregisterCTryCatch() { |
| 900 Simulator::current(Isolate::Current())->PopAddress(); | 907 Simulator::current(Isolate::Current())->PopAddress(); |
| 901 } | 908 } |
| 902 }; | 909 }; |
| 903 | 910 |
| 904 #endif // !defined(USE_SIMULATOR) | 911 #endif // !defined(USE_SIMULATOR) |
| 905 | 912 |
| 906 } } // namespace v8::internal | 913 } } // namespace v8::internal |
| 907 | 914 |
| 908 #endif // V8_ARM64_SIMULATOR_ARM64_H_ | 915 #endif // V8_ARM64_SIMULATOR_ARM64_H_ |
| OLD | NEW |