OLD | NEW |
1 // Copyright (c) 1994-2006 Sun Microsystems Inc. | 1 // Copyright (c) 1994-2006 Sun Microsystems Inc. |
2 // All Rights Reserved. | 2 // All Rights Reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // - Redistributions of source code must retain the above copyright notice, | 8 // - Redistributions of source code must retain the above copyright notice, |
9 // this list of conditions and the following disclaimer. | 9 // this list of conditions and the following disclaimer. |
10 // | 10 // |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 namespace v8 { namespace internal { | 42 namespace v8 { namespace internal { |
43 | 43 |
44 Condition NegateCondition(Condition cc) { | 44 Condition NegateCondition(Condition cc) { |
45 return static_cast<Condition>(cc ^ 1); | 45 return static_cast<Condition>(cc ^ 1); |
46 } | 46 } |
47 | 47 |
48 | 48 |
49 // The modes possibly affected by apply must be in kApplyMask. | 49 // The modes possibly affected by apply must be in kApplyMask. |
50 void RelocInfo::apply(int delta) { | 50 void RelocInfo::apply(int delta) { |
51 if (rmode_ == runtime_entry || is_code_target(rmode_)) { | 51 if (rmode_ == RUNTIME_ENTRY || IsCodeTarget(rmode_)) { |
52 int32_t* p = reinterpret_cast<int32_t*>(pc_); | 52 int32_t* p = reinterpret_cast<int32_t*>(pc_); |
53 *p -= delta; // relocate entry | 53 *p -= delta; // relocate entry |
54 } else if (rmode_ == js_return && is_call_instruction()) { | 54 } else if (rmode_ == JS_RETURN && is_call_instruction()) { |
55 // Special handling of js_return when a break point is set (call | 55 // Special handling of js_return when a break point is set (call |
56 // instruction has been inserted). | 56 // instruction has been inserted). |
57 int32_t* p = reinterpret_cast<int32_t*>(pc_ + 1); | 57 int32_t* p = reinterpret_cast<int32_t*>(pc_ + 1); |
58 *p -= delta; // relocate entry | 58 *p -= delta; // relocate entry |
59 } else if (is_internal_reference(rmode_)) { | 59 } else if (IsInternalReference(rmode_)) { |
60 // absolute code pointer inside code object moves with the code object. | 60 // absolute code pointer inside code object moves with the code object. |
61 int32_t* p = reinterpret_cast<int32_t*>(pc_); | 61 int32_t* p = reinterpret_cast<int32_t*>(pc_); |
62 *p += delta; // relocate entry | 62 *p += delta; // relocate entry |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 | 66 |
67 Address RelocInfo::target_address() { | 67 Address RelocInfo::target_address() { |
68 ASSERT(is_code_target(rmode_) || rmode_ == runtime_entry); | 68 ASSERT(IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY); |
69 return Assembler::target_address_at(pc_); | 69 return Assembler::target_address_at(pc_); |
70 } | 70 } |
71 | 71 |
72 | 72 |
73 void RelocInfo::set_target_address(Address target) { | 73 void RelocInfo::set_target_address(Address target) { |
74 ASSERT(is_code_target(rmode_) || rmode_ == runtime_entry); | 74 ASSERT(IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY); |
75 Assembler::set_target_address_at(pc_, target); | 75 Assembler::set_target_address_at(pc_, target); |
76 } | 76 } |
77 | 77 |
78 | 78 |
79 Object* RelocInfo::target_object() { | 79 Object* RelocInfo::target_object() { |
80 ASSERT(is_code_target(rmode_) || rmode_ == embedded_object); | 80 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); |
81 return *reinterpret_cast<Object**>(pc_); | 81 return *reinterpret_cast<Object**>(pc_); |
82 } | 82 } |
83 | 83 |
84 | 84 |
85 Object** RelocInfo::target_object_address() { | 85 Object** RelocInfo::target_object_address() { |
86 ASSERT(is_code_target(rmode_) || rmode_ == embedded_object); | 86 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); |
87 return reinterpret_cast<Object**>(pc_); | 87 return reinterpret_cast<Object**>(pc_); |
88 } | 88 } |
89 | 89 |
90 | 90 |
91 void RelocInfo::set_target_object(Object* target) { | 91 void RelocInfo::set_target_object(Object* target) { |
92 ASSERT(is_code_target(rmode_) || rmode_ == embedded_object); | 92 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); |
93 *reinterpret_cast<Object**>(pc_) = target; | 93 *reinterpret_cast<Object**>(pc_) = target; |
94 } | 94 } |
95 | 95 |
96 | 96 |
97 Address* RelocInfo::target_reference_address() { | 97 Address* RelocInfo::target_reference_address() { |
98 ASSERT(rmode_ == external_reference); | 98 ASSERT(rmode_ == RelocInfo::EXTERNAL_REFERENCE); |
99 return reinterpret_cast<Address*>(pc_); | 99 return reinterpret_cast<Address*>(pc_); |
100 } | 100 } |
101 | 101 |
102 | 102 |
103 Address RelocInfo::call_address() { | 103 Address RelocInfo::call_address() { |
104 ASSERT(is_call_instruction()); | 104 ASSERT(is_call_instruction()); |
105 return Assembler::target_address_at(pc_ + 1); | 105 return Assembler::target_address_at(pc_ + 1); |
106 } | 106 } |
107 | 107 |
108 | 108 |
(...skipping 21 matching lines...) Expand all Loading... |
130 } | 130 } |
131 | 131 |
132 | 132 |
133 bool RelocInfo::is_call_instruction() { | 133 bool RelocInfo::is_call_instruction() { |
134 return *pc_ == 0xE8; | 134 return *pc_ == 0xE8; |
135 } | 135 } |
136 | 136 |
137 | 137 |
138 Immediate::Immediate(int x) { | 138 Immediate::Immediate(int x) { |
139 x_ = x; | 139 x_ = x; |
140 rmode_ = no_reloc; | 140 rmode_ = RelocInfo::NONE; |
141 } | 141 } |
142 | 142 |
143 | 143 |
144 Immediate::Immediate(const ExternalReference& ext) { | 144 Immediate::Immediate(const ExternalReference& ext) { |
145 x_ = reinterpret_cast<int32_t>(ext.address()); | 145 x_ = reinterpret_cast<int32_t>(ext.address()); |
146 rmode_ = external_reference; | 146 rmode_ = RelocInfo::EXTERNAL_REFERENCE; |
147 } | 147 } |
148 | 148 |
149 Immediate::Immediate(const char* s) { | 149 Immediate::Immediate(const char* s) { |
150 x_ = reinterpret_cast<int32_t>(s); | 150 x_ = reinterpret_cast<int32_t>(s); |
151 rmode_ = embedded_string; | 151 rmode_ = RelocInfo::EMBEDDED_STRING; |
152 } | 152 } |
153 | 153 |
154 | 154 |
155 Immediate::Immediate(Handle<Object> handle) { | 155 Immediate::Immediate(Handle<Object> handle) { |
156 // Verify all Objects referred by code are NOT in new space. | 156 // Verify all Objects referred by code are NOT in new space. |
157 Object* obj = *handle; | 157 Object* obj = *handle; |
158 ASSERT(!Heap::InNewSpace(obj)); | 158 ASSERT(!Heap::InNewSpace(obj)); |
159 if (obj->IsHeapObject()) { | 159 if (obj->IsHeapObject()) { |
160 x_ = reinterpret_cast<intptr_t>(handle.location()); | 160 x_ = reinterpret_cast<intptr_t>(handle.location()); |
161 rmode_ = embedded_object; | 161 rmode_ = RelocInfo::EMBEDDED_OBJECT; |
162 } else { | 162 } else { |
163 // no relocation needed | 163 // no relocation needed |
164 x_ = reinterpret_cast<intptr_t>(obj); | 164 x_ = reinterpret_cast<intptr_t>(obj); |
165 rmode_ = no_reloc; | 165 rmode_ = RelocInfo::NONE; |
166 } | 166 } |
167 } | 167 } |
168 | 168 |
169 | 169 |
170 Immediate::Immediate(Smi* value) { | 170 Immediate::Immediate(Smi* value) { |
171 x_ = reinterpret_cast<intptr_t>(value); | 171 x_ = reinterpret_cast<intptr_t>(value); |
172 rmode_ = no_reloc; | 172 rmode_ = RelocInfo::NONE; |
173 } | 173 } |
174 | 174 |
175 | 175 |
176 void Assembler::emit(uint32_t x) { | 176 void Assembler::emit(uint32_t x) { |
177 *reinterpret_cast<uint32_t*>(pc_) = x; | 177 *reinterpret_cast<uint32_t*>(pc_) = x; |
178 pc_ += sizeof(uint32_t); | 178 pc_ += sizeof(uint32_t); |
179 } | 179 } |
180 | 180 |
181 | 181 |
182 void Assembler::emit(Handle<Object> handle) { | 182 void Assembler::emit(Handle<Object> handle) { |
183 // Verify all Objects referred by code are NOT in new space. | 183 // Verify all Objects referred by code are NOT in new space. |
184 Object* obj = *handle; | 184 Object* obj = *handle; |
185 ASSERT(!Heap::InNewSpace(obj)); | 185 ASSERT(!Heap::InNewSpace(obj)); |
186 if (obj->IsHeapObject()) { | 186 if (obj->IsHeapObject()) { |
187 emit(reinterpret_cast<intptr_t>(handle.location()), embedded_object); | 187 emit(reinterpret_cast<intptr_t>(handle.location()), |
| 188 RelocInfo::EMBEDDED_OBJECT); |
188 } else { | 189 } else { |
189 // no relocation needed | 190 // no relocation needed |
190 emit(reinterpret_cast<intptr_t>(obj)); | 191 emit(reinterpret_cast<intptr_t>(obj)); |
191 } | 192 } |
192 } | 193 } |
193 | 194 |
194 | 195 |
195 void Assembler::emit(uint32_t x, RelocMode rmode) { | 196 void Assembler::emit(uint32_t x, RelocInfo::Mode rmode) { |
196 if (rmode != no_reloc) RecordRelocInfo(rmode); | 197 if (rmode != RelocInfo::NONE) RecordRelocInfo(rmode); |
197 emit(x); | 198 emit(x); |
198 } | 199 } |
199 | 200 |
200 | 201 |
201 void Assembler::emit(const Immediate& x) { | 202 void Assembler::emit(const Immediate& x) { |
202 if (x.rmode_ != no_reloc) RecordRelocInfo(x.rmode_); | 203 if (x.rmode_ != RelocInfo::NONE) RecordRelocInfo(x.rmode_); |
203 emit(x.x_); | 204 emit(x.x_); |
204 } | 205 } |
205 | 206 |
206 | 207 |
207 Address Assembler::target_address_at(Address pc) { | 208 Address Assembler::target_address_at(Address pc) { |
208 return pc + sizeof(int32_t) + *reinterpret_cast<int32_t*>(pc); | 209 return pc + sizeof(int32_t) + *reinterpret_cast<int32_t*>(pc); |
209 } | 210 } |
210 | 211 |
211 | 212 |
212 void Assembler::set_target_address_at(Address pc, Address target) { | 213 void Assembler::set_target_address_at(Address pc, Address target) { |
(...skipping 21 matching lines...) Expand all Loading... |
234 | 235 |
235 | 236 |
236 void Operand::set_modrm(int mod, // reg == 0 | 237 void Operand::set_modrm(int mod, // reg == 0 |
237 Register rm) { | 238 Register rm) { |
238 ASSERT((mod & -4) == 0); | 239 ASSERT((mod & -4) == 0); |
239 buf_[0] = mod << 6 | rm.code(); | 240 buf_[0] = mod << 6 | rm.code(); |
240 len_ = 1; | 241 len_ = 1; |
241 } | 242 } |
242 | 243 |
243 | 244 |
244 void Operand::set_dispr(int32_t disp, RelocMode rmode) { | 245 void Operand::set_dispr(int32_t disp, RelocInfo::Mode rmode) { |
245 ASSERT(len_ == 1 || len_ == 2); | 246 ASSERT(len_ == 1 || len_ == 2); |
246 *reinterpret_cast<int32_t*>(&buf_[len_]) = disp; | 247 *reinterpret_cast<int32_t*>(&buf_[len_]) = disp; |
247 len_ += sizeof(int32_t); | 248 len_ += sizeof(int32_t); |
248 rmode_ = rmode; | 249 rmode_ = rmode; |
249 } | 250 } |
250 | 251 |
251 Operand::Operand(Register reg) { | 252 Operand::Operand(Register reg) { |
252 // reg | 253 // reg |
253 set_modrm(3, reg); | 254 set_modrm(3, reg); |
254 } | 255 } |
255 | 256 |
256 | 257 |
257 Operand::Operand(int32_t disp, RelocMode rmode) { | 258 Operand::Operand(int32_t disp, RelocInfo::Mode rmode) { |
258 // [disp/r] | 259 // [disp/r] |
259 set_modrm(0, ebp); | 260 set_modrm(0, ebp); |
260 set_dispr(disp, rmode); | 261 set_dispr(disp, rmode); |
261 } | 262 } |
262 | 263 |
263 } } // namespace v8::internal | 264 } } // namespace v8::internal |
264 | 265 |
265 #endif // V8_ASSEMBLER_IA32_INL_H_ | 266 #endif // V8_ASSEMBLER_IA32_INL_H_ |
OLD | NEW |