| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VM_ASSEMBLER_X64_H_ | 5 #ifndef VM_ASSEMBLER_X64_H_ |
| 6 #define VM_ASSEMBLER_X64_H_ | 6 #define VM_ASSEMBLER_X64_H_ |
| 7 | 7 |
| 8 #ifndef VM_ASSEMBLER_H_ | 8 #ifndef VM_ASSEMBLER_H_ |
| 9 #error Do not include assembler_x64.h directly; use assembler.h instead. | 9 #error Do not include assembler_x64.h directly; use assembler.h instead. |
| 10 #endif | 10 #endif |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 SetDisp32(disp); | 205 SetDisp32(disp); |
| 206 } | 206 } |
| 207 } | 207 } |
| 208 | 208 |
| 209 Address(const Address& other) : Operand(other) { } | 209 Address(const Address& other) : Operand(other) { } |
| 210 | 210 |
| 211 Address& operator=(const Address& other) { | 211 Address& operator=(const Address& other) { |
| 212 Operand::operator=(other); | 212 Operand::operator=(other); |
| 213 return *this; | 213 return *this; |
| 214 } | 214 } |
| 215 |
| 216 static Address AddressBaseImm32(Register base, int32_t disp) { |
| 217 return Address(base, disp, true); |
| 218 } |
| 219 |
| 220 private: |
| 221 Address(Register base, int32_t disp, bool fixed) { |
| 222 ASSERT(fixed); |
| 223 SetModRM(2, base); |
| 224 if ((base & 7) == RSP) { |
| 225 SetSIB(TIMES_1, RSP, base); |
| 226 } |
| 227 SetDisp32(disp); |
| 228 } |
| 215 }; | 229 }; |
| 216 | 230 |
| 217 | 231 |
| 218 class FieldAddress : public Address { | 232 class FieldAddress : public Address { |
| 219 public: | 233 public: |
| 220 FieldAddress(Register base, int32_t disp) | 234 FieldAddress(Register base, int32_t disp) |
| 221 : Address(base, disp - kHeapObjectTag) { } | 235 : Address(base, disp - kHeapObjectTag) { } |
| 222 | 236 |
| 223 FieldAddress(Register base, Register index, ScaleFactor scale, int32_t disp) | 237 FieldAddress(Register base, Register index, ScaleFactor scale, int32_t disp) |
| 224 : Address(base, index, scale, disp - kHeapObjectTag) { } | 238 : Address(base, index, scale, disp - kHeapObjectTag) { } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 | 328 |
| 315 static bool sse4_1_supported_; | 329 static bool sse4_1_supported_; |
| 316 #ifdef DEBUG | 330 #ifdef DEBUG |
| 317 static bool initialized_; | 331 static bool initialized_; |
| 318 #endif | 332 #endif |
| 319 }; | 333 }; |
| 320 | 334 |
| 321 | 335 |
| 322 class Assembler : public ValueObject { | 336 class Assembler : public ValueObject { |
| 323 public: | 337 public: |
| 324 explicit Assembler(bool use_far_branches = false) | 338 explicit Assembler(bool use_far_branches = false); |
| 325 : buffer_(), | 339 |
| 326 object_pool_(GrowableObjectArray::Handle()), | |
| 327 prologue_offset_(-1), | |
| 328 comments_() { | |
| 329 // This mode is only needed and implemented for MIPS and ARM. | |
| 330 ASSERT(!use_far_branches); | |
| 331 } | |
| 332 ~Assembler() { } | 340 ~Assembler() { } |
| 333 | 341 |
| 334 static const bool kNearJump = true; | 342 static const bool kNearJump = true; |
| 335 static const bool kFarJump = false; | 343 static const bool kFarJump = false; |
| 336 | 344 |
| 337 /* | 345 /* |
| 338 * Emit Machine Instructions. | 346 * Emit Machine Instructions. |
| 339 */ | 347 */ |
| 340 void call(Register reg); | 348 void call(Register reg); |
| 341 void call(const Address& address); | 349 void call(const Address& address); |
| 342 void call(Label* label); | 350 void call(Label* label); |
| 343 void call(const ExternalLabel* label); | 351 void call(const ExternalLabel* label); |
| 344 | 352 |
| 345 static const intptr_t kCallExternalLabelSize = 13; | 353 static const intptr_t kCallExternalLabelSize = 10; |
| 346 | 354 |
| 347 void pushq(Register reg); | 355 void pushq(Register reg); |
| 348 void pushq(const Address& address); | 356 void pushq(const Address& address); |
| 349 void pushq(const Immediate& imm); | 357 void pushq(const Immediate& imm); |
| 350 | 358 |
| 351 void popq(Register reg); | 359 void popq(Register reg); |
| 352 void popq(const Address& address); | 360 void popq(const Address& address); |
| 353 | 361 |
| 354 void setcc(Condition condition, ByteRegister dst); | 362 void setcc(Condition condition, ByteRegister dst); |
| 355 | 363 |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 void CompareRegisters(Register a, Register b); | 653 void CompareRegisters(Register a, Register b); |
| 646 | 654 |
| 647 // Issues a move instruction if 'to' is not the same as 'from'. | 655 // Issues a move instruction if 'to' is not the same as 'from'. |
| 648 void MoveRegister(Register to, Register from); | 656 void MoveRegister(Register to, Register from); |
| 649 void PopRegister(Register r); | 657 void PopRegister(Register r); |
| 650 | 658 |
| 651 void AddImmediate(Register reg, const Immediate& imm); | 659 void AddImmediate(Register reg, const Immediate& imm); |
| 652 | 660 |
| 653 void Drop(intptr_t stack_elements); | 661 void Drop(intptr_t stack_elements); |
| 654 | 662 |
| 655 void LoadObject(Register dst, const Object& object); | 663 enum Patchability { |
| 664 kPatchable, |
| 665 kNotPatchable, |
| 666 }; |
| 667 |
| 668 void LoadObject(Register dst, const Object& obj, Register pp); |
| 669 void JmpPatchable(const ExternalLabel* label, Register pp); |
| 670 void Jmp(const ExternalLabel* label, Register pp); |
| 671 void J(Condition condition, const ExternalLabel* label, Register pp); |
| 672 void CallPatchable(const ExternalLabel* label); |
| 673 void Call(const ExternalLabel* label, Register pp); |
| 656 void StoreObject(const Address& dst, const Object& obj); | 674 void StoreObject(const Address& dst, const Object& obj); |
| 657 void PushObject(const Object& object); | 675 void PushObject(const Object& object); |
| 658 void CompareObject(Register reg, const Object& object); | 676 void CompareObject(Register reg, const Object& object); |
| 659 void LoadDoubleConstant(XmmRegister dst, double value); | 677 void LoadDoubleConstant(XmmRegister dst, double value); |
| 660 | 678 |
| 661 // Destroys value. | 679 // Destroys value. |
| 662 void StoreIntoObject(Register object, // Object we are storing into. | 680 void StoreIntoObject(Register object, // Object we are storing into. |
| 663 const Address& dest, // Where we are storing into. | 681 const Address& dest, // Where we are storing into. |
| 664 Register value, // Value we are storing. | 682 Register value, // Value we are storing. |
| 665 bool can_value_be_smi = true); | 683 bool can_value_be_smi = true); |
| 666 | 684 |
| 667 void StoreIntoObjectNoBarrier(Register object, | 685 void StoreIntoObjectNoBarrier(Register object, |
| 668 const Address& dest, | 686 const Address& dest, |
| 669 Register value); | 687 Register value); |
| 670 | 688 |
| 671 void DoubleNegate(XmmRegister d); | 689 void DoubleNegate(XmmRegister d); |
| 672 void FloatNegate(XmmRegister f); | 690 void FloatNegate(XmmRegister f); |
| 673 | 691 |
| 674 void DoubleAbs(XmmRegister reg); | 692 void DoubleAbs(XmmRegister reg); |
| 675 | 693 |
| 676 void LockCmpxchgl(const Address& address, Register reg) { | 694 void LockCmpxchgl(const Address& address, Register reg) { |
| 677 lock(); | 695 lock(); |
| 678 cmpxchgl(address, reg); | 696 cmpxchgl(address, reg); |
| 679 } | 697 } |
| 680 | 698 |
| 681 void EnterFrame(intptr_t frame_space); | 699 void EnterFrame(intptr_t frame_space); |
| 682 void LeaveFrame(); | 700 void LeaveFrame(); |
| 701 void LeaveFrameWithPP(); |
| 702 void ReturnPatchable(); |
| 683 void ReserveAlignedFrameSpace(intptr_t frame_space); | 703 void ReserveAlignedFrameSpace(intptr_t frame_space); |
| 684 | 704 |
| 685 // Create a frame for calling into runtime that preserves all volatile | 705 // Create a frame for calling into runtime that preserves all volatile |
| 686 // registers. Frame's RSP is guaranteed to be correctly aligned and | 706 // registers. Frame's RSP is guaranteed to be correctly aligned and |
| 687 // frame_space bytes are reserved under it. | 707 // frame_space bytes are reserved under it. |
| 688 void EnterCallRuntimeFrame(intptr_t frame_space); | 708 void EnterCallRuntimeFrame(intptr_t frame_space); |
| 689 void LeaveCallRuntimeFrame(); | 709 void LeaveCallRuntimeFrame(); |
| 690 | 710 |
| 691 | 711 |
| 692 void CallRuntime(const RuntimeEntry& entry, intptr_t argument_count); | 712 void CallRuntime(const RuntimeEntry& entry, intptr_t argument_count); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 int prologue_offset() const { return prologue_offset_; } | 744 int prologue_offset() const { return prologue_offset_; } |
| 725 const ZoneGrowableArray<int>& GetPointerOffsets() const { | 745 const ZoneGrowableArray<int>& GetPointerOffsets() const { |
| 726 return buffer_.pointer_offsets(); | 746 return buffer_.pointer_offsets(); |
| 727 } | 747 } |
| 728 const GrowableObjectArray& object_pool() const { return object_pool_; } | 748 const GrowableObjectArray& object_pool() const { return object_pool_; } |
| 729 | 749 |
| 730 void FinalizeInstructions(const MemoryRegion& region) { | 750 void FinalizeInstructions(const MemoryRegion& region) { |
| 731 buffer_.FinalizeInstructions(region); | 751 buffer_.FinalizeInstructions(region); |
| 732 } | 752 } |
| 733 | 753 |
| 754 void LoadPoolPointer(Register pp); |
| 755 |
| 734 // Set up a Dart frame on entry with a frame pointer and PC information to | 756 // Set up a Dart frame on entry with a frame pointer and PC information to |
| 735 // enable easy access to the RawInstruction object of code corresponding | 757 // enable easy access to the RawInstruction object of code corresponding |
| 736 // to this frame. | 758 // to this frame. |
| 737 // The dart frame layout is as follows: | 759 // The dart frame layout is as follows: |
| 738 // .... | 760 // .... |
| 739 // ret PC | 761 // ret PC |
| 740 // saved RBP <=== RBP | 762 // saved RBP <=== RBP |
| 741 // pc (used to derive the RawInstruction Object of the dart code) | 763 // pc (used to derive the RawInstruction Object of the dart code) |
| 764 // saved PP |
| 742 // locals space <=== RSP | 765 // locals space <=== RSP |
| 743 // ..... | 766 // ..... |
| 744 // This code sets this up with the sequence: | 767 // This code sets this up with the sequence: |
| 745 // pushq rbp | 768 // pushq rbp |
| 746 // movq rbp, rsp | 769 // movq rbp, rsp |
| 747 // call L | 770 // call L |
| 748 // L: <code to adjust saved pc if there is any intrinsification code> | 771 // L: <code to adjust saved pc if there is any intrinsification code> |
| 772 // ... |
| 773 // pushq r15 |
| 749 // ..... | 774 // ..... |
| 750 void EnterDartFrame(intptr_t frame_size); | 775 void EnterDartFrame(intptr_t frame_size); |
| 776 void EnterDartFrameWithInfo(intptr_t frame_size, |
| 777 Register new_pp, Register new_pc); |
| 751 | 778 |
| 752 // Set up a Dart frame for a function compiled for on-stack replacement. | 779 // Set up a Dart frame for a function compiled for on-stack replacement. |
| 753 // The frame layout is a normal Dart frame, but the frame is partially set | 780 // The frame layout is a normal Dart frame, but the frame is partially set |
| 754 // up on entry (it is the frame of the unoptimized code). | 781 // up on entry (it is the frame of the unoptimized code). |
| 755 void EnterOsrFrame(intptr_t extra_size); | 782 void EnterOsrFrame(intptr_t extra_size, Register new_pp, Register new_pc); |
| 756 | 783 |
| 757 // Set up a stub frame so that the stack traversal code can easily identify | 784 // Set up a stub frame so that the stack traversal code can easily identify |
| 758 // a stub frame. | 785 // a stub frame. |
| 759 // The stub frame layout is as follows: | 786 // The stub frame layout is as follows: |
| 760 // .... | 787 // .... |
| 761 // ret PC | 788 // ret PC |
| 762 // saved RBP | 789 // saved RBP |
| 763 // pc (used to derive the RawInstruction Object of the stub) | 790 // pc (used to derive the RawInstruction Object of the stub) |
| 764 // ..... | 791 // ..... |
| 765 // This code sets this up with the sequence: | 792 // This code sets this up with the sequence: |
| 766 // pushq rbp | 793 // pushq rbp |
| 767 // movq rbp, rsp | 794 // movq rbp, rsp |
| 768 // pushq immediate(0) | 795 // pushq immediate(0) |
| 769 // ..... | 796 // ..... |
| 770 void EnterStubFrame(); | 797 void EnterStubFrame(); |
| 798 void EnterStubFrameWithPP(); |
| 771 | 799 |
| 772 // Instruction pattern from entrypoint is used in dart frame prologs | 800 // Instruction pattern from entrypoint is used in dart frame prologues |
| 773 // to set up the frame and save a PC which can be used to figure out the | 801 // to set up the frame and save a PC which can be used to figure out the |
| 774 // RawInstruction object corresponding to the code running in the frame. | 802 // RawInstruction object corresponding to the code running in the frame. |
| 775 // entrypoint: | 803 // entrypoint: |
| 776 // pushq rbp (size is 1 byte) | 804 // pushq rbp (size is 1 byte) |
| 777 // movq rbp, rsp (size is 3 bytes) | 805 // movq rbp, rsp (size is 3 bytes) |
| 778 // call L (size is 5 bytes) | 806 // call L (size is 5 bytes) |
| 779 // L: | 807 // L: |
| 780 static const intptr_t kEntryPointToPcMarkerOffset = 9; | 808 static const intptr_t kEntryPointToPcMarkerOffset = 9; |
| 781 | 809 |
| 782 // Inlined allocation of an instance of class 'cls', code has no runtime | 810 // Inlined allocation of an instance of class 'cls', code has no runtime |
| (...skipping 12 matching lines...) Expand all Loading... |
| 795 void Unreachable(const char* message); | 823 void Unreachable(const char* message); |
| 796 | 824 |
| 797 static void InitializeMemoryWithBreakpoints(uword data, int length); | 825 static void InitializeMemoryWithBreakpoints(uword data, int length); |
| 798 | 826 |
| 799 static const char* RegisterName(Register reg); | 827 static const char* RegisterName(Register reg); |
| 800 | 828 |
| 801 static const char* FpuRegisterName(FpuRegister reg); | 829 static const char* FpuRegisterName(FpuRegister reg); |
| 802 | 830 |
| 803 private: | 831 private: |
| 804 AssemblerBuffer buffer_; | 832 AssemblerBuffer buffer_; |
| 805 GrowableObjectArray& object_pool_; // Object pool is not used on x64. | 833 |
| 834 // Objects and jump targets. |
| 835 GrowableObjectArray& object_pool_; |
| 836 |
| 837 // Patchability of pool entries. |
| 838 GrowableArray<Patchability> patchable_pool_entries_; |
| 839 |
| 806 int prologue_offset_; | 840 int prologue_offset_; |
| 807 | 841 |
| 808 class CodeComment : public ZoneAllocated { | 842 class CodeComment : public ZoneAllocated { |
| 809 public: | 843 public: |
| 810 CodeComment(intptr_t pc_offset, const String& comment) | 844 CodeComment(intptr_t pc_offset, const String& comment) |
| 811 : pc_offset_(pc_offset), comment_(comment) { } | 845 : pc_offset_(pc_offset), comment_(comment) { } |
| 812 | 846 |
| 813 intptr_t pc_offset() const { return pc_offset_; } | 847 intptr_t pc_offset() const { return pc_offset_; } |
| 814 const String& comment() const { return comment_; } | 848 const String& comment() const { return comment_; } |
| 815 | 849 |
| 816 private: | 850 private: |
| 817 intptr_t pc_offset_; | 851 intptr_t pc_offset_; |
| 818 const String& comment_; | 852 const String& comment_; |
| 819 | 853 |
| 820 DISALLOW_COPY_AND_ASSIGN(CodeComment); | 854 DISALLOW_COPY_AND_ASSIGN(CodeComment); |
| 821 }; | 855 }; |
| 822 | 856 |
| 823 GrowableArray<CodeComment*> comments_; | 857 GrowableArray<CodeComment*> comments_; |
| 824 | 858 |
| 859 intptr_t FindObject(const Object& obj, Patchability patchable); |
| 860 intptr_t FindExternalLabel(const ExternalLabel* label, |
| 861 Patchability patchable); |
| 862 void LoadExternalLabel(Register dst, |
| 863 const ExternalLabel* label, |
| 864 Patchability patchable, |
| 865 Register pp); |
| 866 bool CanLoadFromObjectPool(const Object& object); |
| 867 void LoadWordFromPoolOffset(Register dst, Register pp, int32_t offset); |
| 868 |
| 825 inline void EmitUint8(uint8_t value); | 869 inline void EmitUint8(uint8_t value); |
| 826 inline void EmitInt32(int32_t value); | 870 inline void EmitInt32(int32_t value); |
| 827 inline void EmitInt64(int64_t value); | 871 inline void EmitInt64(int64_t value); |
| 828 | 872 |
| 829 inline void EmitRegisterREX(Register reg, uint8_t rex); | 873 inline void EmitRegisterREX(Register reg, uint8_t rex); |
| 830 inline void EmitRegisterOperand(int rm, int reg); | 874 inline void EmitRegisterOperand(int rm, int reg); |
| 831 inline void EmitOperandREX(int rm, const Operand& operand, uint8_t rex); | 875 inline void EmitOperandREX(int rm, const Operand& operand, uint8_t rex); |
| 832 inline void EmitXmmRegisterOperand(int rm, XmmRegister reg); | 876 inline void EmitXmmRegisterOperand(int rm, XmmRegister reg); |
| 833 inline void EmitFixup(AssemblerFixup* fixup); | 877 inline void EmitFixup(AssemblerFixup* fixup); |
| 834 inline void EmitOperandSizeOverride(); | 878 inline void EmitOperandSizeOverride(); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 } | 981 } |
| 938 | 982 |
| 939 | 983 |
| 940 inline void Assembler::EmitOperandSizeOverride() { | 984 inline void Assembler::EmitOperandSizeOverride() { |
| 941 EmitUint8(0x66); | 985 EmitUint8(0x66); |
| 942 } | 986 } |
| 943 | 987 |
| 944 } // namespace dart | 988 } // namespace dart |
| 945 | 989 |
| 946 #endif // VM_ASSEMBLER_X64_H_ | 990 #endif // VM_ASSEMBLER_X64_H_ |
| OLD | NEW |