christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1 | // Copyright (c) 1994-2006 Sun Microsystems Inc. |
| 2 | // All Rights Reserved. |
| 3 | // |
| 4 | // Redistribution and use in source and binary forms, with or without |
| 5 | // modification, are permitted provided that the following conditions are |
| 6 | // met: |
| 7 | // |
| 8 | // - Redistributions of source code must retain the above copyright notice, |
| 9 | // this list of conditions and the following disclaimer. |
| 10 | // |
| 11 | // - Redistribution in binary form must reproduce the above copyright |
| 12 | // notice, this list of conditions and the following disclaimer in the |
| 13 | // documentation and/or other materials provided with the distribution. |
| 14 | // |
| 15 | // - Neither the name of Sun Microsystems or the names of contributors may |
| 16 | // be used to endorse or promote products derived from this software without |
| 17 | // specific prior written permission. |
| 18 | // |
| 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 20 | // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 21 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 22 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 23 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 24 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 25 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 26 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 27 | // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 28 | // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 29 | // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | |
| 31 | // The original source code covered by the above license above has been |
| 32 | // modified significantly by Google Inc. |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 33 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 34 | |
| 35 | // A light-weight IA32 Assembler. |
| 36 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 37 | #ifndef V8_IA32_ASSEMBLER_IA32_INL_H_ |
| 38 | #define V8_IA32_ASSEMBLER_IA32_INL_H_ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 39 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 40 | #include "ia32/assembler-ia32.h" |
| 41 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 42 | #include "cpu.h" |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 43 | #include "debug.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 44 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 45 | namespace v8 { |
| 46 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 47 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 48 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 49 | static const byte kCallOpcode = 0xE8; |
| 50 | |
| 51 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 52 | // The modes possibly affected by apply must be in kApplyMask. |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 53 | void RelocInfo::apply(intptr_t delta) { |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 54 | if (IsRuntimeEntry(rmode_) || IsCodeTarget(rmode_)) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 55 | int32_t* p = reinterpret_cast<int32_t*>(pc_); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 56 | *p -= delta; // Relocate entry. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 57 | CPU::FlushICache(p, sizeof(uint32_t)); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 58 | } else if (rmode_ == CODE_AGE_SEQUENCE) { |
| 59 | if (*pc_ == kCallOpcode) { |
| 60 | int32_t* p = reinterpret_cast<int32_t*>(pc_ + 1); |
| 61 | *p -= delta; // Relocate entry. |
| 62 | CPU::FlushICache(p, sizeof(uint32_t)); |
| 63 | } |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 64 | } else if (rmode_ == JS_RETURN && IsPatchedReturnSequence()) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 65 | // Special handling of js_return when a break point is set (call |
| 66 | // instruction has been inserted). |
| 67 | int32_t* p = reinterpret_cast<int32_t*>(pc_ + 1); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 68 | *p -= delta; // Relocate entry. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 69 | CPU::FlushICache(p, sizeof(uint32_t)); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 70 | } else if (rmode_ == DEBUG_BREAK_SLOT && IsPatchedDebugBreakSlotSequence()) { |
| 71 | // Special handling of a debug break slot when a break point is set (call |
| 72 | // instruction has been inserted). |
| 73 | int32_t* p = reinterpret_cast<int32_t*>(pc_ + 1); |
| 74 | *p -= delta; // Relocate entry. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 75 | CPU::FlushICache(p, sizeof(uint32_t)); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 76 | } else if (IsInternalReference(rmode_)) { |
| 77 | // absolute code pointer inside code object moves with the code object. |
| 78 | int32_t* p = reinterpret_cast<int32_t*>(pc_); |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 79 | *p += delta; // Relocate entry. |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 80 | CPU::FlushICache(p, sizeof(uint32_t)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 81 | } |
| 82 | } |
| 83 | |
| 84 | |
| 85 | Address RelocInfo::target_address() { |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 86 | ASSERT(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 87 | return Assembler::target_address_at(pc_); |
| 88 | } |
| 89 | |
| 90 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 91 | Address RelocInfo::target_address_address() { |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 92 | ASSERT(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_) |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 93 | || rmode_ == EMBEDDED_OBJECT |
| 94 | || rmode_ == EXTERNAL_REFERENCE); |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 95 | return reinterpret_cast<Address>(pc_); |
| 96 | } |
| 97 | |
| 98 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 99 | int RelocInfo::target_address_size() { |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 100 | return Assembler::kSpecialTargetSize; |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 104 | void RelocInfo::set_target_address(Address target, WriteBarrierMode mode) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 105 | Assembler::set_target_address_at(pc_, target); |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 106 | ASSERT(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 107 | if (mode == UPDATE_WRITE_BARRIER && host() != NULL && IsCodeTarget(rmode_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 108 | Object* target_code = Code::GetCodeFromTargetAddress(target); |
| 109 | host()->GetHeap()->incremental_marking()->RecordWriteIntoCode( |
| 110 | host(), this, HeapObject::cast(target_code)); |
| 111 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | |
| 115 | Object* RelocInfo::target_object() { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 116 | ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 117 | return Memory::Object_at(pc_); |
| 118 | } |
| 119 | |
| 120 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 121 | Handle<Object> RelocInfo::target_object_handle(Assembler* origin) { |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 122 | ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); |
| 123 | return Memory::Object_Handle_at(pc_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | |
| 127 | Object** RelocInfo::target_object_address() { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 128 | ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 129 | return &Memory::Object_at(pc_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 133 | void RelocInfo::set_target_object(Object* target, WriteBarrierMode mode) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 134 | ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 135 | Memory::Object_at(pc_) = target; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 136 | CPU::FlushICache(pc_, sizeof(Address)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 137 | if (mode == UPDATE_WRITE_BARRIER && |
| 138 | host() != NULL && |
| 139 | target->IsHeapObject()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 140 | host()->GetHeap()->incremental_marking()->RecordWrite( |
| 141 | host(), &Memory::Object_at(pc_), HeapObject::cast(target)); |
| 142 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | |
| 146 | Address* RelocInfo::target_reference_address() { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 147 | ASSERT(rmode_ == RelocInfo::EXTERNAL_REFERENCE); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 148 | return reinterpret_cast<Address*>(pc_); |
| 149 | } |
| 150 | |
| 151 | |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 152 | Address RelocInfo::target_runtime_entry(Assembler* origin) { |
| 153 | ASSERT(IsRuntimeEntry(rmode_)); |
| 154 | return reinterpret_cast<Address>(*reinterpret_cast<int32_t*>(pc_)); |
| 155 | } |
| 156 | |
| 157 | |
| 158 | void RelocInfo::set_target_runtime_entry(Address target, |
| 159 | WriteBarrierMode mode) { |
| 160 | ASSERT(IsRuntimeEntry(rmode_)); |
| 161 | if (target_address() != target) set_target_address(target, mode); |
| 162 | } |
| 163 | |
| 164 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 165 | Handle<JSGlobalPropertyCell> RelocInfo::target_cell_handle() { |
| 166 | ASSERT(rmode_ == RelocInfo::GLOBAL_PROPERTY_CELL); |
| 167 | Address address = Memory::Address_at(pc_); |
| 168 | return Handle<JSGlobalPropertyCell>( |
| 169 | reinterpret_cast<JSGlobalPropertyCell**>(address)); |
| 170 | } |
| 171 | |
| 172 | |
| 173 | JSGlobalPropertyCell* RelocInfo::target_cell() { |
| 174 | ASSERT(rmode_ == RelocInfo::GLOBAL_PROPERTY_CELL); |
jkummerow@chromium.org | 000f7fb | 2012-08-01 11:14:42 +0000 | [diff] [blame] | 175 | return JSGlobalPropertyCell::FromValueAddress(Memory::Address_at(pc_)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 179 | void RelocInfo::set_target_cell(JSGlobalPropertyCell* cell, |
| 180 | WriteBarrierMode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 181 | ASSERT(rmode_ == RelocInfo::GLOBAL_PROPERTY_CELL); |
| 182 | Address address = cell->address() + JSGlobalPropertyCell::kValueOffset; |
| 183 | Memory::Address_at(pc_) = address; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 184 | CPU::FlushICache(pc_, sizeof(Address)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 185 | if (mode == UPDATE_WRITE_BARRIER && host() != NULL) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 186 | // TODO(1550) We are passing NULL as a slot because cell can never be on |
| 187 | // evacuation candidate. |
| 188 | host()->GetHeap()->incremental_marking()->RecordWrite( |
| 189 | host(), NULL, cell); |
| 190 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 194 | Code* RelocInfo::code_age_stub() { |
| 195 | ASSERT(rmode_ == RelocInfo::CODE_AGE_SEQUENCE); |
| 196 | ASSERT(*pc_ == kCallOpcode); |
| 197 | return Code::GetCodeFromTargetAddress( |
| 198 | Assembler::target_address_at(pc_ + 1)); |
| 199 | } |
| 200 | |
| 201 | |
| 202 | void RelocInfo::set_code_age_stub(Code* stub) { |
| 203 | ASSERT(*pc_ == kCallOpcode); |
| 204 | ASSERT(rmode_ == RelocInfo::CODE_AGE_SEQUENCE); |
| 205 | Assembler::set_target_address_at(pc_ + 1, stub->instruction_start()); |
| 206 | } |
| 207 | |
| 208 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 209 | Address RelocInfo::call_address() { |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 210 | ASSERT((IsJSReturn(rmode()) && IsPatchedReturnSequence()) || |
| 211 | (IsDebugBreakSlot(rmode()) && IsPatchedDebugBreakSlotSequence())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 212 | return Assembler::target_address_at(pc_ + 1); |
| 213 | } |
| 214 | |
| 215 | |
| 216 | void RelocInfo::set_call_address(Address target) { |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 217 | ASSERT((IsJSReturn(rmode()) && IsPatchedReturnSequence()) || |
| 218 | (IsDebugBreakSlot(rmode()) && IsPatchedDebugBreakSlotSequence())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 219 | Assembler::set_target_address_at(pc_ + 1, target); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 220 | if (host() != NULL) { |
| 221 | Object* target_code = Code::GetCodeFromTargetAddress(target); |
| 222 | host()->GetHeap()->incremental_marking()->RecordWriteIntoCode( |
| 223 | host(), this, HeapObject::cast(target_code)); |
| 224 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | |
| 228 | Object* RelocInfo::call_object() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 229 | return *call_object_address(); |
| 230 | } |
| 231 | |
| 232 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 233 | void RelocInfo::set_call_object(Object* target) { |
| 234 | *call_object_address() = target; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 238 | Object** RelocInfo::call_object_address() { |
| 239 | ASSERT((IsJSReturn(rmode()) && IsPatchedReturnSequence()) || |
| 240 | (IsDebugBreakSlot(rmode()) && IsPatchedDebugBreakSlotSequence())); |
| 241 | return reinterpret_cast<Object**>(pc_ + 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 245 | bool RelocInfo::IsPatchedReturnSequence() { |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 246 | return *pc_ == kCallOpcode; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 250 | bool RelocInfo::IsPatchedDebugBreakSlotSequence() { |
| 251 | return !Assembler::IsNop(pc()); |
| 252 | } |
| 253 | |
| 254 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 255 | void RelocInfo::Visit(ObjectVisitor* visitor) { |
| 256 | RelocInfo::Mode mode = rmode(); |
| 257 | if (mode == RelocInfo::EMBEDDED_OBJECT) { |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 258 | visitor->VisitEmbeddedPointer(this); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 259 | CPU::FlushICache(pc_, sizeof(Address)); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 260 | } else if (RelocInfo::IsCodeTarget(mode)) { |
| 261 | visitor->VisitCodeTarget(this); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 262 | } else if (mode == RelocInfo::GLOBAL_PROPERTY_CELL) { |
| 263 | visitor->VisitGlobalPropertyCell(this); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 264 | } else if (mode == RelocInfo::EXTERNAL_REFERENCE) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 265 | visitor->VisitExternalReference(this); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 266 | CPU::FlushICache(pc_, sizeof(Address)); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 267 | } else if (RelocInfo::IsCodeAgeSequence(mode)) { |
| 268 | visitor->VisitCodeAgeSequence(this); |
| 269 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 270 | // TODO(isolates): Get a cached isolate below. |
| 271 | } else if (((RelocInfo::IsJSReturn(mode) && |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 272 | IsPatchedReturnSequence()) || |
| 273 | (RelocInfo::IsDebugBreakSlot(mode) && |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 274 | IsPatchedDebugBreakSlotSequence())) && |
| 275 | Isolate::Current()->debug()->has_break_points()) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 276 | visitor->VisitDebugTarget(this); |
| 277 | #endif |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 278 | } else if (IsRuntimeEntry(mode)) { |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 279 | visitor->VisitRuntimeEntry(this); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 284 | template<typename StaticVisitor> |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 285 | void RelocInfo::Visit(Heap* heap) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 286 | RelocInfo::Mode mode = rmode(); |
| 287 | if (mode == RelocInfo::EMBEDDED_OBJECT) { |
rossberg@chromium.org | b4b2aa6 | 2011-10-13 09:49:59 +0000 | [diff] [blame] | 288 | StaticVisitor::VisitEmbeddedPointer(heap, this); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 289 | CPU::FlushICache(pc_, sizeof(Address)); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 290 | } else if (RelocInfo::IsCodeTarget(mode)) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 291 | StaticVisitor::VisitCodeTarget(heap, this); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 292 | } else if (mode == RelocInfo::GLOBAL_PROPERTY_CELL) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 293 | StaticVisitor::VisitGlobalPropertyCell(heap, this); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 294 | } else if (mode == RelocInfo::EXTERNAL_REFERENCE) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 295 | StaticVisitor::VisitExternalReference(this); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 296 | CPU::FlushICache(pc_, sizeof(Address)); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 297 | } else if (RelocInfo::IsCodeAgeSequence(mode)) { |
| 298 | StaticVisitor::VisitCodeAgeSequence(heap, this); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 299 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 300 | } else if (heap->isolate()->debug()->has_break_points() && |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 301 | ((RelocInfo::IsJSReturn(mode) && |
| 302 | IsPatchedReturnSequence()) || |
| 303 | (RelocInfo::IsDebugBreakSlot(mode) && |
| 304 | IsPatchedDebugBreakSlotSequence()))) { |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 305 | StaticVisitor::VisitDebugTarget(heap, this); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 306 | #endif |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 307 | } else if (IsRuntimeEntry(mode)) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 308 | StaticVisitor::VisitRuntimeEntry(this); |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | |
| 313 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 314 | Immediate::Immediate(int x) { |
| 315 | x_ = x; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 316 | rmode_ = RelocInfo::NONE32; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | |
| 320 | Immediate::Immediate(const ExternalReference& ext) { |
| 321 | x_ = reinterpret_cast<int32_t>(ext.address()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 322 | rmode_ = RelocInfo::EXTERNAL_REFERENCE; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 323 | } |
| 324 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 325 | |
kasperl@chromium.org | b3284ad | 2009-05-18 06:12:45 +0000 | [diff] [blame] | 326 | Immediate::Immediate(Label* internal_offset) { |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 327 | x_ = reinterpret_cast<int32_t>(internal_offset); |
| 328 | rmode_ = RelocInfo::INTERNAL_REFERENCE; |
| 329 | } |
| 330 | |
| 331 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 332 | Immediate::Immediate(Handle<Object> handle) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 333 | #ifdef DEBUG |
| 334 | Isolate* isolate = Isolate::Current(); |
| 335 | #endif |
| 336 | ALLOW_HANDLE_DEREF(isolate, |
| 337 | "using and embedding raw address, heap object check"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 338 | // Verify all Objects referred by code are NOT in new space. |
| 339 | Object* obj = *handle; |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 340 | ASSERT(!isolate->heap()->InNewSpace(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 341 | if (obj->IsHeapObject()) { |
| 342 | x_ = reinterpret_cast<intptr_t>(handle.location()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 343 | rmode_ = RelocInfo::EMBEDDED_OBJECT; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 344 | } else { |
| 345 | // no relocation needed |
| 346 | x_ = reinterpret_cast<intptr_t>(obj); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 347 | rmode_ = RelocInfo::NONE32; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 348 | } |
| 349 | } |
| 350 | |
| 351 | |
| 352 | Immediate::Immediate(Smi* value) { |
| 353 | x_ = reinterpret_cast<intptr_t>(value); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 354 | rmode_ = RelocInfo::NONE32; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 358 | Immediate::Immediate(Address addr) { |
| 359 | x_ = reinterpret_cast<int32_t>(addr); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 360 | rmode_ = RelocInfo::NONE32; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 364 | void Assembler::emit(uint32_t x) { |
| 365 | *reinterpret_cast<uint32_t*>(pc_) = x; |
| 366 | pc_ += sizeof(uint32_t); |
| 367 | } |
| 368 | |
| 369 | |
| 370 | void Assembler::emit(Handle<Object> handle) { |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 371 | ALLOW_HANDLE_DEREF(isolate(), "heap object check"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 372 | // Verify all Objects referred by code are NOT in new space. |
| 373 | Object* obj = *handle; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 374 | ASSERT(!isolate()->heap()->InNewSpace(obj)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 375 | if (obj->IsHeapObject()) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 376 | emit(reinterpret_cast<intptr_t>(handle.location()), |
| 377 | RelocInfo::EMBEDDED_OBJECT); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 378 | } else { |
| 379 | // no relocation needed |
| 380 | emit(reinterpret_cast<intptr_t>(obj)); |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 385 | void Assembler::emit(uint32_t x, RelocInfo::Mode rmode, TypeFeedbackId id) { |
| 386 | if (rmode == RelocInfo::CODE_TARGET && !id.IsNone()) { |
| 387 | RecordRelocInfo(RelocInfo::CODE_TARGET_WITH_ID, id.ToInt()); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 388 | } else if (!RelocInfo::IsNone(rmode)) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 389 | RecordRelocInfo(rmode); |
| 390 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 391 | emit(x); |
| 392 | } |
| 393 | |
| 394 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 395 | void Assembler::emit(Handle<Code> code, |
| 396 | RelocInfo::Mode rmode, |
| 397 | TypeFeedbackId id) { |
| 398 | ALLOW_HANDLE_DEREF(isolate(), "embedding raw address"); |
| 399 | emit(reinterpret_cast<intptr_t>(code.location()), rmode, id); |
| 400 | } |
| 401 | |
| 402 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 403 | void Assembler::emit(const Immediate& x) { |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 404 | if (x.rmode_ == RelocInfo::INTERNAL_REFERENCE) { |
| 405 | Label* label = reinterpret_cast<Label*>(x.x_); |
| 406 | emit_code_relative_offset(label); |
| 407 | return; |
| 408 | } |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 409 | if (!RelocInfo::IsNone(x.rmode_)) RecordRelocInfo(x.rmode_); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 410 | emit(x.x_); |
| 411 | } |
| 412 | |
| 413 | |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 414 | void Assembler::emit_code_relative_offset(Label* label) { |
| 415 | if (label->is_bound()) { |
| 416 | int32_t pos; |
| 417 | pos = label->pos() + Code::kHeaderSize - kHeapObjectTag; |
| 418 | emit(pos); |
| 419 | } else { |
| 420 | emit_disp(label, Displacement::CODE_RELATIVE); |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 425 | void Assembler::emit_w(const Immediate& x) { |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 426 | ASSERT(RelocInfo::IsNone(x.rmode_)); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 427 | uint16_t value = static_cast<uint16_t>(x.x_); |
| 428 | reinterpret_cast<uint16_t*>(pc_)[0] = value; |
| 429 | pc_ += sizeof(uint16_t); |
| 430 | } |
| 431 | |
| 432 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 433 | Address Assembler::target_address_at(Address pc) { |
| 434 | return pc + sizeof(int32_t) + *reinterpret_cast<int32_t*>(pc); |
| 435 | } |
| 436 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 437 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 438 | void Assembler::set_target_address_at(Address pc, Address target) { |
| 439 | int32_t* p = reinterpret_cast<int32_t*>(pc); |
| 440 | *p = target - (pc + sizeof(int32_t)); |
| 441 | CPU::FlushICache(p, sizeof(int32_t)); |
| 442 | } |
| 443 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 444 | |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 445 | Address Assembler::target_address_from_return_address(Address pc) { |
| 446 | return pc - kCallTargetAddressOffset; |
| 447 | } |
| 448 | |
| 449 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 450 | Displacement Assembler::disp_at(Label* L) { |
| 451 | return Displacement(long_at(L->pos())); |
| 452 | } |
| 453 | |
| 454 | |
| 455 | void Assembler::disp_at_put(Label* L, Displacement disp) { |
| 456 | long_at_put(L->pos(), disp.data()); |
| 457 | } |
| 458 | |
| 459 | |
| 460 | void Assembler::emit_disp(Label* L, Displacement::Type type) { |
| 461 | Displacement disp(L, type); |
| 462 | L->link_to(pc_offset()); |
| 463 | emit(static_cast<int>(disp.data())); |
| 464 | } |
| 465 | |
| 466 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 467 | void Assembler::emit_near_disp(Label* L) { |
| 468 | byte disp = 0x00; |
| 469 | if (L->is_near_linked()) { |
| 470 | int offset = L->near_link_pos() - pc_offset(); |
| 471 | ASSERT(is_int8(offset)); |
| 472 | disp = static_cast<byte>(offset & 0xFF); |
| 473 | } |
| 474 | L->link_to(pc_offset(), Label::kNear); |
| 475 | *pc_++ = disp; |
| 476 | } |
| 477 | |
| 478 | |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 479 | void Operand::set_modrm(int mod, Register rm) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 480 | ASSERT((mod & -4) == 0); |
| 481 | buf_[0] = mod << 6 | rm.code(); |
| 482 | len_ = 1; |
| 483 | } |
| 484 | |
| 485 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 486 | void Operand::set_sib(ScaleFactor scale, Register index, Register base) { |
| 487 | ASSERT(len_ == 1); |
| 488 | ASSERT((scale & -4) == 0); |
| 489 | // Use SIB with no index register only for base esp. |
| 490 | ASSERT(!index.is(esp) || base.is(esp)); |
| 491 | buf_[1] = scale << 6 | index.code() << 3 | base.code(); |
| 492 | len_ = 2; |
| 493 | } |
| 494 | |
| 495 | |
| 496 | void Operand::set_disp8(int8_t disp) { |
| 497 | ASSERT(len_ == 1 || len_ == 2); |
| 498 | *reinterpret_cast<int8_t*>(&buf_[len_++]) = disp; |
| 499 | } |
| 500 | |
| 501 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 502 | void Operand::set_dispr(int32_t disp, RelocInfo::Mode rmode) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 503 | ASSERT(len_ == 1 || len_ == 2); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 504 | int32_t* p = reinterpret_cast<int32_t*>(&buf_[len_]); |
| 505 | *p = disp; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 506 | len_ += sizeof(int32_t); |
| 507 | rmode_ = rmode; |
| 508 | } |
| 509 | |
| 510 | Operand::Operand(Register reg) { |
| 511 | // reg |
| 512 | set_modrm(3, reg); |
| 513 | } |
| 514 | |
| 515 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 516 | Operand::Operand(XMMRegister xmm_reg) { |
| 517 | Register reg = { xmm_reg.code() }; |
| 518 | set_modrm(3, reg); |
| 519 | } |
| 520 | |
| 521 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 522 | Operand::Operand(int32_t disp, RelocInfo::Mode rmode) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 523 | // [disp/r] |
| 524 | set_modrm(0, ebp); |
| 525 | set_dispr(disp, rmode); |
| 526 | } |
| 527 | |
| 528 | } } // namespace v8::internal |
| 529 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 530 | #endif // V8_IA32_ASSEMBLER_IA32_INL_H_ |