| 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 | 5 // modification, are permitted provided that the following conditions |
| 6 // are met: | 6 // are 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 Address RelocInfo::target_address() { | 97 Address RelocInfo::target_address() { |
| 98 ASSERT(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)); | 98 ASSERT(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)); |
| 99 return Assembler::target_address_at(pc_); | 99 return Assembler::target_address_at(pc_); |
| 100 } | 100 } |
| 101 | 101 |
| 102 | 102 |
| 103 Address RelocInfo::target_address_address() { | 103 Address RelocInfo::target_address_address() { |
| 104 ASSERT(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_) | 104 ASSERT(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_) |
| 105 || rmode_ == EMBEDDED_OBJECT | 105 || rmode_ == EMBEDDED_OBJECT |
| 106 || rmode_ == EXTERNAL_REFERENCE); | 106 || rmode_ == EXTERNAL_REFERENCE); |
| 107 return reinterpret_cast<Address>(Assembler::target_pointer_address_at(pc_)); | 107 return Assembler::target_pointer_address_at(pc_); |
| 108 } | 108 } |
| 109 | 109 |
| 110 | 110 |
| 111 int RelocInfo::target_address_size() { | 111 int RelocInfo::target_address_size() { |
| 112 return kPointerSize; | 112 return kPointerSize; |
| 113 } | 113 } |
| 114 | 114 |
| 115 | 115 |
| 116 void RelocInfo::set_target_address(Address target, WriteBarrierMode mode) { | 116 void RelocInfo::set_target_address(Address target, WriteBarrierMode mode) { |
| 117 ASSERT(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)); | 117 ASSERT(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)); |
| 118 Assembler::set_target_address_at(pc_, target); | 118 Assembler::set_target_address_at(pc_, target); |
| 119 if (mode == UPDATE_WRITE_BARRIER && host() != NULL && IsCodeTarget(rmode_)) { | 119 if (mode == UPDATE_WRITE_BARRIER && host() != NULL && IsCodeTarget(rmode_)) { |
| 120 Object* target_code = Code::GetCodeFromTargetAddress(target); | 120 Object* target_code = Code::GetCodeFromTargetAddress(target); |
| 121 host()->GetHeap()->incremental_marking()->RecordWriteIntoCode( | 121 host()->GetHeap()->incremental_marking()->RecordWriteIntoCode( |
| 122 host(), this, HeapObject::cast(target_code)); | 122 host(), this, HeapObject::cast(target_code)); |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 | 125 |
| 126 | 126 |
| 127 Object* RelocInfo::target_object() { | 127 Object* RelocInfo::target_object() { |
| 128 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); | 128 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); |
| 129 return reinterpret_cast<Object*>(Assembler::target_pointer_at(pc_)); | 129 return reinterpret_cast<Object*>(Assembler::target_address_at(pc_)); |
| 130 } | 130 } |
| 131 | 131 |
| 132 | 132 |
| 133 Handle<Object> RelocInfo::target_object_handle(Assembler* origin) { | 133 Handle<Object> RelocInfo::target_object_handle(Assembler* origin) { |
| 134 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); | 134 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); |
| 135 return Handle<Object>(reinterpret_cast<Object**>( | 135 return Handle<Object>(reinterpret_cast<Object**>( |
| 136 Assembler::target_pointer_at(pc_))); | 136 Assembler::target_address_at(pc_))); |
| 137 } | |
| 138 | |
| 139 | |
| 140 Object** RelocInfo::target_object_address() { | |
| 141 // Provide a "natural pointer" to the embedded object, | |
| 142 // which can be de-referenced during heap iteration. | |
| 143 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); | |
| 144 reconstructed_obj_ptr_ = | |
| 145 reinterpret_cast<Object*>(Assembler::target_pointer_at(pc_)); | |
| 146 return &reconstructed_obj_ptr_; | |
| 147 } | 137 } |
| 148 | 138 |
| 149 | 139 |
| 150 void RelocInfo::set_target_object(Object* target, WriteBarrierMode mode) { | 140 void RelocInfo::set_target_object(Object* target, WriteBarrierMode mode) { |
| 151 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); | 141 ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT); |
| 152 ASSERT(!target->IsConsString()); | 142 ASSERT(!target->IsConsString()); |
| 153 Assembler::set_target_pointer_at(pc_, reinterpret_cast<Address>(target)); | 143 Assembler::set_target_address_at(pc_, reinterpret_cast<Address>(target)); |
| 154 if (mode == UPDATE_WRITE_BARRIER && | 144 if (mode == UPDATE_WRITE_BARRIER && |
| 155 host() != NULL && | 145 host() != NULL && |
| 156 target->IsHeapObject()) { | 146 target->IsHeapObject()) { |
| 157 host()->GetHeap()->incremental_marking()->RecordWrite( | 147 host()->GetHeap()->incremental_marking()->RecordWrite( |
| 158 host(), &Memory::Object_at(pc_), HeapObject::cast(target)); | 148 host(), &Memory::Object_at(pc_), HeapObject::cast(target)); |
| 159 } | 149 } |
| 160 } | 150 } |
| 161 | 151 |
| 162 | 152 |
| 163 Address* RelocInfo::target_reference_address() { | 153 Address RelocInfo::target_reference() { |
| 164 ASSERT(rmode_ == EXTERNAL_REFERENCE); | 154 ASSERT(rmode_ == EXTERNAL_REFERENCE); |
| 165 reconstructed_adr_ptr_ = Assembler::target_address_at(pc_); | 155 return Assembler::target_address_at(pc_); |
| 166 return &reconstructed_adr_ptr_; | |
| 167 } | 156 } |
| 168 | 157 |
| 169 | 158 |
| 170 Address RelocInfo::target_runtime_entry(Assembler* origin) { | 159 Address RelocInfo::target_runtime_entry(Assembler* origin) { |
| 171 ASSERT(IsRuntimeEntry(rmode_)); | 160 ASSERT(IsRuntimeEntry(rmode_)); |
| 172 return target_address(); | 161 return target_address(); |
| 173 } | 162 } |
| 174 | 163 |
| 175 | 164 |
| 176 void RelocInfo::set_target_runtime_entry(Address target, | 165 void RelocInfo::set_target_runtime_entry(Address target, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 } | 251 } |
| 263 | 252 |
| 264 | 253 |
| 265 Object** RelocInfo::call_object_address() { | 254 Object** RelocInfo::call_object_address() { |
| 266 ASSERT((IsJSReturn(rmode()) && IsPatchedReturnSequence()) || | 255 ASSERT((IsJSReturn(rmode()) && IsPatchedReturnSequence()) || |
| 267 (IsDebugBreakSlot(rmode()) && IsPatchedDebugBreakSlotSequence())); | 256 (IsDebugBreakSlot(rmode()) && IsPatchedDebugBreakSlotSequence())); |
| 268 return reinterpret_cast<Object**>(pc_ + 2 * Assembler::kInstrSize); | 257 return reinterpret_cast<Object**>(pc_ + 2 * Assembler::kInstrSize); |
| 269 } | 258 } |
| 270 | 259 |
| 271 | 260 |
| 261 void RelocInfo::WipeOut() { |
| 262 ASSERT(IsEmbeddedObject(rmode_) || |
| 263 IsCodeTarget(rmode_) || |
| 264 IsRuntimeEntry(rmode_) || |
| 265 IsExternalReference(rmode_)); |
| 266 Assembler::set_target_address_at(pc_, NULL); |
| 267 } |
| 268 |
| 269 |
| 272 bool RelocInfo::IsPatchedReturnSequence() { | 270 bool RelocInfo::IsPatchedReturnSequence() { |
| 273 Instr current_instr = Assembler::instr_at(pc_); | 271 Instr current_instr = Assembler::instr_at(pc_); |
| 274 Instr next_instr = Assembler::instr_at(pc_ + Assembler::kInstrSize); | 272 Instr next_instr = Assembler::instr_at(pc_ + Assembler::kInstrSize); |
| 275 // A patched return sequence is: | 273 // A patched return sequence is: |
| 276 // ldr ip, [pc, #0] | 274 // ldr ip, [pc, #0] |
| 277 // blx ip | 275 // blx ip |
| 278 return ((current_instr & kLdrPCMask) == kLdrPCPattern) | 276 return ((current_instr & kLdrPCMask) == kLdrPCPattern) |
| 279 && ((next_instr & kBlxRegMask) == kBlxRegPattern); | 277 && ((next_instr & kBlxRegMask) == kBlxRegPattern); |
| 280 } | 278 } |
| 281 | 279 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 | 385 |
| 388 | 386 |
| 389 void Assembler::emit(Instr x) { | 387 void Assembler::emit(Instr x) { |
| 390 CheckBuffer(); | 388 CheckBuffer(); |
| 391 *reinterpret_cast<Instr*>(pc_) = x; | 389 *reinterpret_cast<Instr*>(pc_) = x; |
| 392 pc_ += kInstrSize; | 390 pc_ += kInstrSize; |
| 393 } | 391 } |
| 394 | 392 |
| 395 | 393 |
| 396 Address Assembler::target_pointer_address_at(Address pc) { | 394 Address Assembler::target_pointer_address_at(Address pc) { |
| 397 Address target_pc = pc; | 395 Instr instr = Memory::int32_at(pc); |
| 398 Instr instr = Memory::int32_at(target_pc); | 396 return pc + GetLdrRegisterImmediateOffset(instr) + kPcLoadDelta; |
| 399 // If we have a bx instruction, the instruction before the bx is | |
| 400 // what we need to patch. | |
| 401 static const int32_t kBxInstMask = 0x0ffffff0; | |
| 402 static const int32_t kBxInstPattern = 0x012fff10; | |
| 403 if ((instr & kBxInstMask) == kBxInstPattern) { | |
| 404 target_pc -= kInstrSize; | |
| 405 instr = Memory::int32_at(target_pc); | |
| 406 } | |
| 407 | |
| 408 // With a blx instruction, the instruction before is what needs to be patched. | |
| 409 if ((instr & kBlxRegMask) == kBlxRegPattern) { | |
| 410 target_pc -= kInstrSize; | |
| 411 instr = Memory::int32_at(target_pc); | |
| 412 } | |
| 413 | |
| 414 ASSERT(IsLdrPcImmediateOffset(instr)); | |
| 415 int offset = instr & 0xfff; // offset_12 is unsigned | |
| 416 if ((instr & (1 << 23)) == 0) offset = -offset; // U bit defines offset sign | |
| 417 // Verify that the constant pool comes after the instruction referencing it. | |
| 418 ASSERT(offset >= -4); | |
| 419 return target_pc + offset + 8; | |
| 420 } | 397 } |
| 421 | 398 |
| 422 | 399 |
| 423 Address Assembler::target_pointer_at(Address pc) { | 400 Address Assembler::target_address_at(Address pc) { |
| 424 if (IsMovW(Memory::int32_at(pc))) { | 401 if (IsMovW(Memory::int32_at(pc))) { |
| 425 ASSERT(IsMovT(Memory::int32_at(pc + kInstrSize))); | 402 ASSERT(IsMovT(Memory::int32_at(pc + kInstrSize))); |
| 426 Instruction* instr = Instruction::At(pc); | 403 Instruction* instr = Instruction::At(pc); |
| 427 Instruction* next_instr = Instruction::At(pc + kInstrSize); | 404 Instruction* next_instr = Instruction::At(pc + kInstrSize); |
| 428 return reinterpret_cast<Address>( | 405 return reinterpret_cast<Address>( |
| 429 (next_instr->ImmedMovwMovtValue() << 16) | | 406 (next_instr->ImmedMovwMovtValue() << 16) | |
| 430 instr->ImmedMovwMovtValue()); | 407 instr->ImmedMovwMovtValue()); |
| 431 } | 408 } |
| 409 ASSERT(IsLdrPcImmediateOffset(Memory::int32_at(pc))); |
| 432 return Memory::Address_at(target_pointer_address_at(pc)); | 410 return Memory::Address_at(target_pointer_address_at(pc)); |
| 433 } | 411 } |
| 434 | 412 |
| 435 | 413 |
| 436 Address Assembler::target_address_from_return_address(Address pc) { | 414 Address Assembler::target_address_from_return_address(Address pc) { |
| 437 // Returns the address of the call target from the return address that will | 415 // Returns the address of the call target from the return address that will |
| 438 // be returned to after a call. | 416 // be returned to after a call. |
| 439 // Call sequence on V7 or later is : | 417 // Call sequence on V7 or later is : |
| 440 // movw ip, #... @ call address low 16 | 418 // movw ip, #... @ call address low 16 |
| 441 // movt ip, #... @ call address high 16 | 419 // movt ip, #... @ call address high 16 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 Memory::Address_at(constant_pool_entry) = target; | 457 Memory::Address_at(constant_pool_entry) = target; |
| 480 } | 458 } |
| 481 | 459 |
| 482 | 460 |
| 483 static Instr EncodeMovwImmediate(uint32_t immediate) { | 461 static Instr EncodeMovwImmediate(uint32_t immediate) { |
| 484 ASSERT(immediate < 0x10000); | 462 ASSERT(immediate < 0x10000); |
| 485 return ((immediate & 0xf000) << 4) | (immediate & 0xfff); | 463 return ((immediate & 0xf000) << 4) | (immediate & 0xfff); |
| 486 } | 464 } |
| 487 | 465 |
| 488 | 466 |
| 489 void Assembler::set_target_pointer_at(Address pc, Address target) { | 467 void Assembler::set_target_address_at(Address pc, Address target) { |
| 490 if (IsMovW(Memory::int32_at(pc))) { | 468 if (IsMovW(Memory::int32_at(pc))) { |
| 491 ASSERT(IsMovT(Memory::int32_at(pc + kInstrSize))); | 469 ASSERT(IsMovT(Memory::int32_at(pc + kInstrSize))); |
| 492 uint32_t* instr_ptr = reinterpret_cast<uint32_t*>(pc); | 470 uint32_t* instr_ptr = reinterpret_cast<uint32_t*>(pc); |
| 493 uint32_t immediate = reinterpret_cast<uint32_t>(target); | 471 uint32_t immediate = reinterpret_cast<uint32_t>(target); |
| 494 uint32_t intermediate = instr_ptr[0]; | 472 uint32_t intermediate = instr_ptr[0]; |
| 495 intermediate &= ~EncodeMovwImmediate(0xFFFF); | 473 intermediate &= ~EncodeMovwImmediate(0xFFFF); |
| 496 intermediate |= EncodeMovwImmediate(immediate & 0xFFFF); | 474 intermediate |= EncodeMovwImmediate(immediate & 0xFFFF); |
| 497 instr_ptr[0] = intermediate; | 475 instr_ptr[0] = intermediate; |
| 498 intermediate = instr_ptr[1]; | 476 intermediate = instr_ptr[1]; |
| 499 intermediate &= ~EncodeMovwImmediate(0xFFFF); | 477 intermediate &= ~EncodeMovwImmediate(0xFFFF); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 510 // CPU::FlushICache(pc, sizeof(target)); | 488 // CPU::FlushICache(pc, sizeof(target)); |
| 511 // However, on ARM, no instruction is actually patched in the case | 489 // However, on ARM, no instruction is actually patched in the case |
| 512 // of embedded constants of the form: | 490 // of embedded constants of the form: |
| 513 // ldr ip, [pc, #...] | 491 // ldr ip, [pc, #...] |
| 514 // since the instruction accessing this address in the constant pool remains | 492 // since the instruction accessing this address in the constant pool remains |
| 515 // unchanged. | 493 // unchanged. |
| 516 } | 494 } |
| 517 } | 495 } |
| 518 | 496 |
| 519 | 497 |
| 520 Address Assembler::target_address_at(Address pc) { | |
| 521 return target_pointer_at(pc); | |
| 522 } | |
| 523 | |
| 524 | |
| 525 void Assembler::set_target_address_at(Address pc, Address target) { | |
| 526 set_target_pointer_at(pc, target); | |
| 527 } | |
| 528 | |
| 529 | |
| 530 } } // namespace v8::internal | 498 } } // namespace v8::internal |
| 531 | 499 |
| 532 #endif // V8_ARM_ASSEMBLER_ARM_INL_H_ | 500 #endif // V8_ARM_ASSEMBLER_ARM_INL_H_ |
| OLD | NEW |