Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, 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 #include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM. |
| 6 #if defined(TARGET_ARCH_ARM) | 6 #if defined(TARGET_ARCH_ARM) |
| 7 | 7 |
| 8 #include "vm/constants_arm.h" | 8 #include "vm/constants_arm.h" |
| 9 #include "vm/cpu.h" | 9 #include "vm/cpu.h" |
| 10 #include "vm/instructions.h" | 10 #include "vm/instructions.h" |
| 11 #include "vm/object.h" | 11 #include "vm/object.h" |
| 12 | 12 |
| 13 namespace dart { | 13 namespace dart { |
| 14 | 14 |
| 15 CallPattern::CallPattern(uword pc, const Code& code) | 15 CallPattern::CallPattern(uword pc, const Code& code) |
| 16 : end_(reinterpret_cast<uword*>(pc)), | 16 : end_(reinterpret_cast<uword*>(pc)), |
| 17 pool_index_(DecodePoolIndex()), | 17 target_address_pool_index_(-1), |
| 18 object_pool_(Array::Handle(code.ObjectPool())) { } | 18 args_desc_load_end_(-1), |
| 19 args_desc_pool_index_(-1), | |
| 20 ic_data_load_end_(-1), | |
| 21 ic_data_pool_index_(-1), | |
| 22 object_pool_(Array::Handle(code.ObjectPool())) { | |
| 23 ASSERT(Back(1) == 0xe12fff3e); // Last instruction: blx lr | |
| 24 Register reg; | |
| 25 args_desc_load_end_ = | |
| 26 DecodeLoadWordFromPool(1, ®, &target_address_pool_index_); | |
| 27 ASSERT(reg == LR); | |
| 28 } | |
| 19 | 29 |
| 20 | 30 |
| 21 uword CallPattern::Back(int n) const { | 31 uword CallPattern::Back(int n) const { |
| 22 ASSERT(n > 0); | 32 ASSERT(n > 0); |
| 23 return *(end_ - n); | 33 return *(end_ - n); |
| 24 } | 34 } |
| 25 | 35 |
| 26 | 36 |
| 27 int CallPattern::DecodePoolIndex() { | 37 // Decodes a load sequence ending at end. Returns the register being loaded and |
| 28 ASSERT(Back(1) == 0xe12fff3e); // Last instruction: blx lr | 38 // the index in the pool being read from. |
| 29 // Decode the second to last instruction. | 39 // Returns the location of the load sequence, counting the number of |
| 30 uword instr = Back(2); | 40 // instructions back from the end of the call pattern. |
| 41 int CallPattern::DecodeLoadWordFromPool(int end, Register* reg, int* index) { | |
| 42 ASSERT(end > 0); | |
| 43 uword instr = Back(++end); | |
| 31 int offset = 0; | 44 int offset = 0; |
| 32 if ((instr & 0xfffff000) == 0xe59ae000) { // ldr lr, [pp, #+offset] | 45 if ((instr & 0xffff0000) == 0xe59a0000) { // ldr reg, [pp, #+offset] |
|
zra
2013/03/11 22:36:08
Would it be too heavyweight here to use the Instr
regis
2013/03/11 23:16:30
I thought of using class Instr and tried, but the
| |
| 33 offset = instr & 0xfff; | 46 offset = instr & 0xfff; |
| 47 *reg = static_cast<Register>((instr & 0xf000) >> 12); | |
| 34 } else { | 48 } else { |
| 35 ASSERT((instr & 0xfffff000) == 0xe59ee000); // ldr lr, [lr, #+offset] | 49 ASSERT((instr & 0xfff00000) == 0xe5900000); // ldr reg, [reg, #+offset] |
| 36 offset = instr & 0xfff; | 50 offset = instr & 0xfff; |
| 37 instr = Back(3); | 51 instr = Back(++end); |
| 38 if ((instr & 0xfffff000) == 0xe28ae000) { // add lr, pp, shifter_op | 52 if ((instr & 0xffff0000) == 0xe28a0000) { // add reg, pp, shifter_op |
| 39 const int rot = (instr & 0xf00) * 2; | 53 const int rot = (instr & 0xf00) * 2; |
| 40 const int imm8 = instr & 0xff; | 54 const int imm8 = instr & 0xff; |
| 41 offset |= (imm8 >> rot) | (imm8 << (32 - rot)); | 55 offset |= (imm8 >> rot) | (imm8 << (32 - rot)); |
| 56 *reg = static_cast<Register>((instr & 0xf000) >> 12); | |
| 42 } else { | 57 } else { |
| 43 ASSERT(instr == 0xe08ae00e); // add lr, pp, lr | 58 ASSERT((instr & 0xffff0000) == 0xe08a0000); // add reg, pp, reg |
| 44 instr = Back(4); | 59 instr = Back(++end); |
| 45 if ((instr & 0xfff0f000) == 0xe340e000) { // movt lr, offset_hi | 60 if ((instr & 0xfff00000) == 0xe3400000) { // movt reg, offset_hi |
| 46 offset |= (instr & 0xf0000) << 12; | 61 offset |= (instr & 0xf0000) << 12; |
| 47 offset |= (instr & 0xfff) << 16; | 62 offset |= (instr & 0xfff) << 16; |
| 48 instr = Back(5); | 63 instr = Back(++end); |
| 49 } | 64 } |
| 50 ASSERT((instr & 0xfff0f000) == 0xe300e000); // movw lr, offset_lo | 65 ASSERT((instr & 0xfff00000) == 0xe3000000); // movw reg, offset_lo |
| 51 ASSERT((offset & 0xffff) == 0); | 66 ASSERT((offset & 0xffff) == 0); |
| 52 offset |= (instr & 0xf0000) >> 4; | 67 offset |= (instr & 0xf0000) >> 4; |
| 53 offset |= instr & 0xfff; | 68 offset |= instr & 0xfff; |
| 69 *reg = static_cast<Register>((instr & 0xf000) >> 12); | |
| 54 } | 70 } |
| 55 } | 71 } |
| 56 offset += kHeapObjectTag; | 72 offset += kHeapObjectTag; |
| 57 ASSERT(Utils::IsAligned(offset, 4)); | 73 ASSERT(Utils::IsAligned(offset, 4)); |
| 58 return (offset - Array::data_offset())/4; | 74 *index = (offset - Array::data_offset())/4; |
| 75 return end; | |
| 76 } | |
| 77 | |
| 78 | |
| 79 RawICData* CallPattern::IcData() { | |
| 80 if (ic_data_pool_index_ < 0) { | |
| 81 Register reg; | |
| 82 // Loading of the argument descriptor must be decoded first, if not already. | |
| 83 if (args_desc_pool_index_ < 0) { | |
| 84 ic_data_load_end_ = DecodeLoadWordFromPool( | |
| 85 args_desc_load_end_, ®, &args_desc_pool_index_); | |
| 86 ASSERT(reg == R4); | |
| 87 } | |
| 88 DecodeLoadWordFromPool(ic_data_load_end_, ®, &ic_data_pool_index_); | |
| 89 ASSERT(reg == R5); | |
| 90 } | |
| 91 ICData& ic_data = ICData::Handle(); | |
| 92 ic_data ^= object_pool_.At(ic_data_pool_index_); | |
| 93 return ic_data.raw(); | |
| 94 } | |
| 95 | |
| 96 | |
| 97 RawArray* CallPattern::ArgumentsDescriptor() { | |
| 98 if (args_desc_pool_index_ < 0) { | |
| 99 Register reg; | |
| 100 ic_data_load_end_ = DecodeLoadWordFromPool( | |
| 101 args_desc_load_end_, ®, &args_desc_pool_index_); | |
| 102 ASSERT(reg == R4); | |
| 103 } | |
| 104 Array& args_desc = Array::Handle(); | |
| 105 args_desc ^= object_pool_.At(args_desc_pool_index_); | |
| 106 return args_desc.raw(); | |
| 59 } | 107 } |
| 60 | 108 |
| 61 | 109 |
| 62 uword CallPattern::TargetAddress() const { | 110 uword CallPattern::TargetAddress() const { |
| 63 const Object& target_address = Object::Handle(object_pool_.At(pool_index_)); | 111 ASSERT(target_address_pool_index_ >= 0); |
| 112 const Object& target_address = | |
| 113 Object::Handle(object_pool_.At(target_address_pool_index_)); | |
| 64 ASSERT(target_address.IsSmi()); | 114 ASSERT(target_address.IsSmi()); |
| 65 // The address is stored in the object array as a RawSmi. | 115 // The address is stored in the object array as a RawSmi. |
| 66 return reinterpret_cast<uword>(target_address.raw()); | 116 return reinterpret_cast<uword>(target_address.raw()); |
| 67 } | 117 } |
| 68 | 118 |
| 69 | 119 |
| 70 void CallPattern::SetTargetAddress(uword target_address) const { | 120 void CallPattern::SetTargetAddress(uword target_address) const { |
| 71 ASSERT(Utils::IsAligned(target_address, 4)); | 121 ASSERT(Utils::IsAligned(target_address, 4)); |
| 72 // The address is stored in the object array as a RawSmi. | 122 // The address is stored in the object array as a RawSmi. |
| 73 const Smi& smi = Smi::Handle(reinterpret_cast<RawSmi*>(target_address)); | 123 const Smi& smi = Smi::Handle(reinterpret_cast<RawSmi*>(target_address)); |
| 74 object_pool_.SetAt(pool_index_, smi); | 124 object_pool_.SetAt(target_address_pool_index_, smi); |
| 75 // No need to flush the instruction cache, since the code is not modified. | 125 // No need to flush the instruction cache, since the code is not modified. |
| 76 } | 126 } |
| 77 | 127 |
| 78 | 128 |
| 79 JumpPattern::JumpPattern(uword pc) : pc_(pc) { } | 129 JumpPattern::JumpPattern(uword pc) : pc_(pc) { } |
| 80 | 130 |
| 81 | 131 |
| 82 bool JumpPattern::IsValid() const { | 132 bool JumpPattern::IsValid() const { |
| 83 Instr* movw = Instr::At(pc_ + (0 * Instr::kInstrSize)); // movw ip, target_lo | 133 Instr* movw = Instr::At(pc_ + (0 * Instr::kInstrSize)); // movw ip, target_lo |
| 84 Instr* movt = Instr::At(pc_ + (1 * Instr::kInstrSize)); // movw ip, target_lo | 134 Instr* movt = Instr::At(pc_ + (1 * Instr::kInstrSize)); // movw ip, target_lo |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 105 uword movt = 0xe340c000 | ((target_hi >> 12) << 16) | (target_hi & 0xfff); | 155 uword movt = 0xe340c000 | ((target_hi >> 12) << 16) | (target_hi & 0xfff); |
| 106 *reinterpret_cast<uword*>(pc_ + (0 * Instr::kInstrSize)) = movw; | 156 *reinterpret_cast<uword*>(pc_ + (0 * Instr::kInstrSize)) = movw; |
| 107 *reinterpret_cast<uword*>(pc_ + (1 * Instr::kInstrSize)) = movt; | 157 *reinterpret_cast<uword*>(pc_ + (1 * Instr::kInstrSize)) = movt; |
| 108 CPU::FlushICache(pc_, 2 * Instr::kInstrSize); | 158 CPU::FlushICache(pc_, 2 * Instr::kInstrSize); |
| 109 } | 159 } |
| 110 | 160 |
| 111 } // namespace dart | 161 } // namespace dart |
| 112 | 162 |
| 113 #endif // defined TARGET_ARCH_ARM | 163 #endif // defined TARGET_ARCH_ARM |
| 114 | 164 |
| OLD | NEW |