Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, 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_IA32_H_ | 5 #ifndef VM_ASSEMBLER_IA32_H_ |
| 6 #define VM_ASSEMBLER_IA32_H_ | 6 #define VM_ASSEMBLER_IA32_H_ |
| 7 | 7 |
| 8 #ifndef VM_ASSEMBLER_H_ | 8 #ifndef VM_ASSEMBLER_H_ |
| 9 #error Do not include assembler_ia32.h directly; use assembler.h instead. | 9 #error Do not include assembler_ia32.h directly; use assembler.h instead. |
| 10 #endif | 10 #endif |
| 11 | 11 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 23 explicit Immediate(int32_t value) : value_(value) { } | 23 explicit Immediate(int32_t value) : value_(value) { } |
| 24 | 24 |
| 25 int32_t value() const { return value_; } | 25 int32_t value() const { return value_; } |
| 26 | 26 |
| 27 bool is_int8() const { return Utils::IsInt(8, value_); } | 27 bool is_int8() const { return Utils::IsInt(8, value_); } |
| 28 bool is_uint8() const { return Utils::IsUint(8, value_); } | 28 bool is_uint8() const { return Utils::IsUint(8, value_); } |
| 29 bool is_uint16() const { return Utils::IsUint(16, value_); } | 29 bool is_uint16() const { return Utils::IsUint(16, value_); } |
| 30 | 30 |
| 31 private: | 31 private: |
| 32 const int32_t value_; | 32 const int32_t value_; |
| 33 | 33 DISALLOW_COPY_AND_ASSIGN(Immediate); |
|
srdjan
2013/01/16 23:57:56
Need to be fixed as discussed (Mac build complains
regis
2013/01/17 01:02:09
Done.
| |
| 34 // TODO(5411081): Add DISALLOW_COPY_AND_ASSIGN(Immediate) once the mac | |
| 35 // build issue is resolved. | |
| 36 }; | 34 }; |
| 37 | 35 |
| 38 | 36 |
| 39 class Operand : public ValueObject { | 37 class Operand { |
| 40 public: | 38 public: |
| 41 uint8_t mod() const { | 39 uint8_t mod() const { |
| 42 return (encoding_at(0) >> 6) & 3; | 40 return (encoding_at(0) >> 6) & 3; |
| 43 } | 41 } |
| 44 | 42 |
| 45 Register rm() const { | 43 Register rm() const { |
| 46 return static_cast<Register>(encoding_at(0) & 7); | 44 return static_cast<Register>(encoding_at(0) & 7); |
| 47 } | 45 } |
| 48 | 46 |
| 49 ScaleFactor scale() const { | 47 ScaleFactor scale() const { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 61 int8_t disp8() const { | 59 int8_t disp8() const { |
| 62 ASSERT(length_ >= 2); | 60 ASSERT(length_ >= 2); |
| 63 return static_cast<int8_t>(encoding_[length_ - 1]); | 61 return static_cast<int8_t>(encoding_[length_ - 1]); |
| 64 } | 62 } |
| 65 | 63 |
| 66 int32_t disp32() const { | 64 int32_t disp32() const { |
| 67 ASSERT(length_ >= 5); | 65 ASSERT(length_ >= 5); |
| 68 return bit_copy<int32_t>(encoding_[length_ - 4]); | 66 return bit_copy<int32_t>(encoding_[length_ - 4]); |
| 69 } | 67 } |
| 70 | 68 |
| 71 bool IsRegister(Register reg) const { | 69 Operand(const Operand& other) : length_(other.length_) { |
| 72 return ((encoding_[0] & 0xF8) == 0xC0) // Addressing mode is register only. | 70 memmove(&encoding_[0], &other.encoding_[0], other.length_); |
| 73 && ((encoding_[0] & 0x07) == reg); // Register codes match. | 71 } |
| 72 | |
| 73 Operand& operator=(const Operand& other) { | |
| 74 length_ = other.length_; | |
| 75 memmove(&encoding_[0], &other.encoding_[0], other.length_); | |
| 76 return *this; | |
| 74 } | 77 } |
| 75 | 78 |
| 76 protected: | 79 protected: |
| 77 // Operand can be sub classed (e.g: Address). | 80 Operand() : length_(0) { } // Needed by subclass Address. |
| 78 Operand() : length_(0) { } | |
| 79 | 81 |
| 80 void SetModRM(int mod, Register rm) { | 82 void SetModRM(int mod, Register rm) { |
| 81 ASSERT((mod & ~3) == 0); | 83 ASSERT((mod & ~3) == 0); |
| 82 encoding_[0] = (mod << 6) | rm; | 84 encoding_[0] = (mod << 6) | rm; |
| 83 length_ = 1; | 85 length_ = 1; |
| 84 } | 86 } |
| 85 | 87 |
| 86 void SetSIB(ScaleFactor scale, Register index, Register base) { | 88 void SetSIB(ScaleFactor scale, Register index, Register base) { |
| 87 ASSERT(length_ == 1); | 89 ASSERT(length_ == 1); |
| 88 ASSERT((scale & ~3) == 0); | 90 ASSERT((scale & ~3) == 0); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 108 uint8_t padding_; | 110 uint8_t padding_; |
| 109 | 111 |
| 110 explicit Operand(Register reg) { SetModRM(3, reg); } | 112 explicit Operand(Register reg) { SetModRM(3, reg); } |
| 111 | 113 |
| 112 // Get the operand encoding byte at the given index. | 114 // Get the operand encoding byte at the given index. |
| 113 uint8_t encoding_at(int index) const { | 115 uint8_t encoding_at(int index) const { |
| 114 ASSERT(index >= 0 && index < length_); | 116 ASSERT(index >= 0 && index < length_); |
| 115 return encoding_[index]; | 117 return encoding_[index]; |
| 116 } | 118 } |
| 117 | 119 |
| 120 // Returns whether or not this operand is really the given register in | |
| 121 // disguise. Used from the assembler to generate better encodings. | |
| 122 bool IsRegister(Register reg) const { | |
| 123 return ((encoding_[0] & 0xF8) == 0xC0) // Addressing mode is register only. | |
| 124 && ((encoding_[0] & 0x07) == reg); // Register codes match. | |
| 125 } | |
| 126 | |
| 118 friend class Assembler; | 127 friend class Assembler; |
| 119 | |
| 120 // TODO(5411081): Add DISALLOW_COPY_AND_ASSIGN(Operand) once the mac | |
| 121 // build issue is resolved. | |
| 122 }; | 128 }; |
| 123 | 129 |
| 124 | 130 |
| 125 class Address : public Operand { | 131 class Address : public Operand { |
| 126 public: | 132 public: |
| 127 Address(Register base, int32_t disp) { | 133 Address(Register base, int32_t disp) { |
| 128 if (disp == 0 && base != EBP) { | 134 if (disp == 0 && base != EBP) { |
| 129 SetModRM(0, base); | 135 SetModRM(0, base); |
| 130 if (base == ESP) SetSIB(TIMES_1, ESP, base); | 136 if (base == ESP) SetSIB(TIMES_1, ESP, base); |
| 131 } else if (Utils::IsInt(8, disp)) { | 137 } else if (Utils::IsInt(8, disp)) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 155 SetModRM(1, ESP); | 161 SetModRM(1, ESP); |
| 156 SetSIB(scale, index, base); | 162 SetSIB(scale, index, base); |
| 157 SetDisp8(disp); | 163 SetDisp8(disp); |
| 158 } else { | 164 } else { |
| 159 SetModRM(2, ESP); | 165 SetModRM(2, ESP); |
| 160 SetSIB(scale, index, base); | 166 SetSIB(scale, index, base); |
| 161 SetDisp32(disp); | 167 SetDisp32(disp); |
| 162 } | 168 } |
| 163 } | 169 } |
| 164 | 170 |
| 171 Address(const Address& other) : Operand(other) { } | |
| 172 | |
| 173 Address& operator=(const Address& other) { | |
| 174 Operand::operator=(other); | |
| 175 return *this; | |
| 176 } | |
| 177 | |
| 165 static Address Absolute(const uword addr) { | 178 static Address Absolute(const uword addr) { |
| 166 Address result; | 179 Address result; |
| 167 result.SetModRM(0, EBP); | 180 result.SetModRM(0, EBP); |
| 168 result.SetDisp32(addr); | 181 result.SetDisp32(addr); |
| 169 return result; | 182 return result; |
| 170 } | 183 } |
| 171 | 184 |
| 172 private: | 185 private: |
| 173 Address() {} | 186 Address() { } // Needed by Address::Absolute. |
| 174 | |
| 175 // TODO(5411081): Add DISALLOW_COPY_AND_ASSIGN(Address) once the mac | |
| 176 // build issue is resolved. | |
| 177 }; | 187 }; |
| 178 | 188 |
| 179 | 189 |
| 180 class FieldAddress : public Address { | 190 class FieldAddress : public Address { |
| 181 public: | 191 public: |
| 182 FieldAddress(Register base, int32_t disp) | 192 FieldAddress(Register base, int32_t disp) |
| 183 : Address(base, disp - kHeapObjectTag) {} | 193 : Address(base, disp - kHeapObjectTag) { } |
| 194 | |
| 184 FieldAddress(Register base, Register index, ScaleFactor scale, int32_t disp) | 195 FieldAddress(Register base, Register index, ScaleFactor scale, int32_t disp) |
| 185 : Address(base, index, scale, disp - kHeapObjectTag) {} | 196 : Address(base, index, scale, disp - kHeapObjectTag) { } |
| 197 | |
| 198 FieldAddress(const FieldAddress& other) : Address(other) { } | |
| 199 | |
| 200 FieldAddress& operator=(const FieldAddress& other) { | |
| 201 Address::operator=(other); | |
| 202 return *this; | |
| 203 } | |
| 186 }; | 204 }; |
| 187 | 205 |
| 188 | 206 |
| 189 class Label : public ValueObject { | 207 class Label : public ValueObject { |
| 190 public: | 208 public: |
| 191 Label() : position_(0), unresolved_(0) { | 209 Label() : position_(0), unresolved_(0) { |
| 192 #ifdef DEBUG | 210 #ifdef DEBUG |
| 193 for (int i = 0; i < kMaxUnresolvedBranches; i++) { | 211 for (int i = 0; i < kMaxUnresolvedBranches; i++) { |
| 194 unresolved_near_positions_[i] = -1; | 212 unresolved_near_positions_[i] = -1; |
| 195 } | 213 } |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 629 void Unimplemented(const char* message); | 647 void Unimplemented(const char* message); |
| 630 void Untested(const char* message); | 648 void Untested(const char* message); |
| 631 void Unreachable(const char* message); | 649 void Unreachable(const char* message); |
| 632 | 650 |
| 633 static void InitializeMemoryWithBreakpoints(uword data, int length); | 651 static void InitializeMemoryWithBreakpoints(uword data, int length); |
| 634 | 652 |
| 635 void Comment(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); | 653 void Comment(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); |
| 636 const Code::Comments& GetCodeComments() const; | 654 const Code::Comments& GetCodeComments() const; |
| 637 | 655 |
| 638 static const char* RegisterName(Register reg); | 656 static const char* RegisterName(Register reg); |
| 639 static const char* XmmRegisterName(XmmRegister reg); | 657 static const char* FpuRegisterName(FpuRegister reg); |
| 640 | 658 |
| 641 private: | 659 private: |
| 642 AssemblerBuffer buffer_; | 660 AssemblerBuffer buffer_; |
| 643 int prologue_offset_; | 661 int prologue_offset_; |
| 644 | 662 |
| 645 class CodeComment : public ZoneAllocated { | 663 class CodeComment : public ZoneAllocated { |
| 646 public: | 664 public: |
| 647 CodeComment(intptr_t pc_offset, const String& comment) | 665 CodeComment(intptr_t pc_offset, const String& comment) |
| 648 : pc_offset_(pc_offset), comment_(comment) { } | 666 : pc_offset_(pc_offset), comment_(comment) { } |
| 649 | 667 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 709 } | 727 } |
| 710 | 728 |
| 711 | 729 |
| 712 inline void Assembler::EmitOperandSizeOverride() { | 730 inline void Assembler::EmitOperandSizeOverride() { |
| 713 EmitUint8(0x66); | 731 EmitUint8(0x66); |
| 714 } | 732 } |
| 715 | 733 |
| 716 } // namespace dart | 734 } // namespace dart |
| 717 | 735 |
| 718 #endif // VM_ASSEMBLER_IA32_H_ | 736 #endif // VM_ASSEMBLER_IA32_H_ |
| OLD | NEW |