OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // Classes that describe assembly patterns as used by inline caches. | 4 // Classes that describe assembly patterns as used by inline caches. |
5 | 5 |
6 #ifndef RUNTIME_VM_INSTRUCTIONS_IA32_H_ | 6 #ifndef RUNTIME_VM_INSTRUCTIONS_IA32_H_ |
7 #define RUNTIME_VM_INSTRUCTIONS_IA32_H_ | 7 #define RUNTIME_VM_INSTRUCTIONS_IA32_H_ |
8 | 8 |
9 #ifndef RUNTIME_VM_INSTRUCTIONS_H_ | 9 #ifndef RUNTIME_VM_INSTRUCTIONS_H_ |
10 #error Do not include instructions_ia32.h directly; use instructions.h instead. | 10 #error Do not include instructions_ia32.h directly; use instructions.h instead. |
11 #endif | 11 #endif |
12 | 12 |
13 #include "vm/allocation.h" | 13 #include "vm/allocation.h" |
14 #include "vm/cpu.h" | 14 #include "vm/cpu.h" |
15 #include "vm/object.h" | 15 #include "vm/object.h" |
16 | 16 |
17 namespace dart { | 17 namespace dart { |
18 | 18 |
19 // Forward declarations. | 19 // Forward declarations. |
20 class RawClass; | 20 class RawClass; |
21 class Immediate; | 21 class Immediate; |
22 class RawObject; | 22 class RawObject; |
23 | 23 |
24 // Template class for all instruction pattern classes. | 24 // Template class for all instruction pattern classes. |
25 // P has to specify a static pattern and a pattern length method. | 25 // P has to specify a static pattern and a pattern length method. |
26 template<class P> class InstructionPattern : public ValueObject { | 26 template <class P> |
| 27 class InstructionPattern : public ValueObject { |
27 public: | 28 public: |
28 explicit InstructionPattern(uword pc) : start_(pc) { | 29 explicit InstructionPattern(uword pc) : start_(pc) { ASSERT(pc != 0); } |
29 ASSERT(pc != 0); | |
30 } | |
31 | 30 |
32 // Call to check if the instruction pattern at 'pc' match the instruction. | 31 // Call to check if the instruction pattern at 'pc' match the instruction. |
33 // 'P::pattern()' returns the expected byte pattern in form of an integer | 32 // 'P::pattern()' returns the expected byte pattern in form of an integer |
34 // array with length of 'P::pattern_length_in_bytes()'. A '-1' element means | 33 // array with length of 'P::pattern_length_in_bytes()'. A '-1' element means |
35 // 'any byte'. | 34 // 'any byte'. |
36 bool IsValid() const { | 35 bool IsValid() const { |
37 return TestBytesWith(P::pattern(), P::pattern_length_in_bytes()); | 36 return TestBytesWith(P::pattern(), P::pattern_length_in_bytes()); |
38 } | 37 } |
39 | 38 |
40 protected: | 39 protected: |
(...skipping 19 matching lines...) Expand all Loading... |
60 | 59 |
61 DISALLOW_COPY_AND_ASSIGN(InstructionPattern); | 60 DISALLOW_COPY_AND_ASSIGN(InstructionPattern); |
62 }; | 61 }; |
63 | 62 |
64 | 63 |
65 class CallPattern : public InstructionPattern<CallPattern> { | 64 class CallPattern : public InstructionPattern<CallPattern> { |
66 public: | 65 public: |
67 explicit CallPattern(uword pc) : InstructionPattern(pc) {} | 66 explicit CallPattern(uword pc) : InstructionPattern(pc) {} |
68 uword TargetAddress() const { | 67 uword TargetAddress() const { |
69 ASSERT(this->IsValid()); | 68 ASSERT(this->IsValid()); |
70 return this->start() + | 69 return this->start() + CallPattern::pattern_length_in_bytes() + |
71 CallPattern::pattern_length_in_bytes() + | 70 *reinterpret_cast<uword*>(this->start() + 1); |
72 *reinterpret_cast<uword*>(this->start() + 1); | |
73 } | 71 } |
74 | 72 |
75 void SetTargetAddress(uword new_target) const { | 73 void SetTargetAddress(uword new_target) const { |
76 ASSERT(this->IsValid()); | 74 ASSERT(this->IsValid()); |
77 *reinterpret_cast<uword*>(this->start() + 1) = | 75 *reinterpret_cast<uword*>(this->start() + 1) = |
78 new_target - this->start() - CallPattern::pattern_length_in_bytes(); | 76 new_target - this->start() - CallPattern::pattern_length_in_bytes(); |
79 CPU::FlushICache(this->start() + 1, kWordSize); | 77 CPU::FlushICache(this->start() + 1, kWordSize); |
80 } | 78 } |
81 | 79 |
82 static int pattern_length_in_bytes() { return kLengthInBytes; } | 80 static int pattern_length_in_bytes() { return kLengthInBytes; } |
83 static const int* pattern() { | 81 static const int* pattern() { |
84 static const int kCallPattern[kLengthInBytes] = {0xE8, -1, -1, -1, -1}; | 82 static const int kCallPattern[kLengthInBytes] = {0xE8, -1, -1, -1, -1}; |
85 return kCallPattern; | 83 return kCallPattern; |
86 } | 84 } |
87 | 85 |
88 | 86 |
89 private: | 87 private: |
90 static const int kLengthInBytes = 5; | 88 static const int kLengthInBytes = 5; |
91 DISALLOW_COPY_AND_ASSIGN(CallPattern); | 89 DISALLOW_COPY_AND_ASSIGN(CallPattern); |
92 }; | 90 }; |
93 | 91 |
94 | 92 |
95 class ReturnPattern : public InstructionPattern<ReturnPattern> { | 93 class ReturnPattern : public InstructionPattern<ReturnPattern> { |
96 public: | 94 public: |
97 explicit ReturnPattern(uword pc) : InstructionPattern(pc) {} | 95 explicit ReturnPattern(uword pc) : InstructionPattern(pc) {} |
98 | 96 |
99 static const int* pattern() { | 97 static const int* pattern() { |
100 static const int kReturnPattern[kLengthInBytes] = { 0xC3 }; | 98 static const int kReturnPattern[kLengthInBytes] = {0xC3}; |
101 return kReturnPattern; | 99 return kReturnPattern; |
102 } | 100 } |
103 static int pattern_length_in_bytes() { return kLengthInBytes; } | 101 static int pattern_length_in_bytes() { return kLengthInBytes; } |
104 | 102 |
105 private: | 103 private: |
106 static const int kLengthInBytes = 1; | 104 static const int kLengthInBytes = 1; |
107 }; | 105 }; |
108 | 106 |
109 | 107 |
110 // push ebp | 108 // push ebp |
111 // mov ebp, esp | 109 // mov ebp, esp |
112 class ProloguePattern : public InstructionPattern<ProloguePattern> { | 110 class ProloguePattern : public InstructionPattern<ProloguePattern> { |
113 public: | 111 public: |
114 explicit ProloguePattern(uword pc) : InstructionPattern(pc) {} | 112 explicit ProloguePattern(uword pc) : InstructionPattern(pc) {} |
115 | 113 |
116 static const int* pattern() { | 114 static const int* pattern() { |
117 static const int kProloguePattern[kLengthInBytes] = { 0x55, 0x89, 0xe5 }; | 115 static const int kProloguePattern[kLengthInBytes] = {0x55, 0x89, 0xe5}; |
118 return kProloguePattern; | 116 return kProloguePattern; |
119 } | 117 } |
120 | 118 |
121 static int pattern_length_in_bytes() { return kLengthInBytes; } | 119 static int pattern_length_in_bytes() { return kLengthInBytes; } |
122 | 120 |
123 private: | 121 private: |
124 static const int kLengthInBytes = 3; | 122 static const int kLengthInBytes = 3; |
125 }; | 123 }; |
126 | 124 |
127 | 125 |
128 // mov ebp, esp | 126 // mov ebp, esp |
129 class SetFramePointerPattern : | 127 class SetFramePointerPattern |
130 public InstructionPattern<SetFramePointerPattern> { | 128 : public InstructionPattern<SetFramePointerPattern> { |
131 public: | 129 public: |
132 explicit SetFramePointerPattern(uword pc) : InstructionPattern(pc) {} | 130 explicit SetFramePointerPattern(uword pc) : InstructionPattern(pc) {} |
133 | 131 |
134 static const int* pattern() { | 132 static const int* pattern() { |
135 static const int kFramePointerPattern[kLengthInBytes] = { 0x89, 0xe5 }; | 133 static const int kFramePointerPattern[kLengthInBytes] = {0x89, 0xe5}; |
136 return kFramePointerPattern; | 134 return kFramePointerPattern; |
137 } | 135 } |
138 | 136 |
139 static int pattern_length_in_bytes() { return kLengthInBytes; } | 137 static int pattern_length_in_bytes() { return kLengthInBytes; } |
140 | 138 |
141 private: | 139 private: |
142 static const int kLengthInBytes = 2; | 140 static const int kLengthInBytes = 2; |
143 }; | 141 }; |
144 | 142 |
145 } // namespace dart | 143 } // namespace dart |
146 | 144 |
147 #endif // RUNTIME_VM_INSTRUCTIONS_IA32_H_ | 145 #endif // RUNTIME_VM_INSTRUCTIONS_IA32_H_ |
OLD | NEW |