| 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 target_address_pool_index_(-1), | 17 target_address_pool_index_(-1), |
| 18 args_desc_load_end_(-1), | 18 args_desc_load_end_(-1), |
| 19 args_desc_pool_index_(-1), | 19 args_desc_(Array::Handle()), |
| 20 ic_data_load_end_(-1), | 20 ic_data_load_end_(-1), |
| 21 ic_data_pool_index_(-1), | 21 ic_data_(ICData::Handle()), |
| 22 object_pool_(Array::Handle(code.ObjectPool())) { | 22 object_pool_(Array::Handle(code.ObjectPool())) { |
| 23 ASSERT(code.ContainsInstructionAt(pc)); | 23 ASSERT(code.ContainsInstructionAt(pc)); |
| 24 ASSERT(Back(1) == 0xe12fff3e); // Last instruction: blx lr | 24 ASSERT(Back(1) == 0xe12fff3e); // Last instruction: blx lr |
| 25 Register reg; | 25 Register reg; |
| 26 args_desc_load_end_ = | 26 args_desc_load_end_ = |
| 27 DecodeLoadWordFromPool(1, ®, &target_address_pool_index_); | 27 DecodeLoadWordFromPool(1, ®, &target_address_pool_index_); |
| 28 ASSERT(reg == LR); | 28 ASSERT(reg == LR); |
| 29 } | 29 } |
| 30 | 30 |
| 31 | 31 |
| 32 uword CallPattern::Back(int n) const { | 32 uword CallPattern::Back(int n) const { |
| 33 ASSERT(n > 0); | 33 ASSERT(n > 0); |
| 34 return *(end_ - n); | 34 return *(end_ - n); |
| 35 } | 35 } |
| 36 | 36 |
| 37 | 37 |
| 38 // Decodes a load sequence ending at end. Returns the register being loaded and | 38 // Decodes a load sequence ending at end. Returns the register being loaded and |
| 39 // the loaded object. |
| 40 // Returns the location of the load sequence, counting the number of |
| 41 // instructions back from the end of the call pattern. |
| 42 int CallPattern::DecodeLoadObject(int end, Register* reg, Object* obj) { |
| 43 ASSERT(end > 0); |
| 44 uword instr = Back(end + 1); |
| 45 if ((instr & 0xfff00000) == 0xe5900000) { // ldr reg, [reg, #+offset] |
| 46 int index = 0; |
| 47 end = DecodeLoadWordFromPool(end, reg, &index); |
| 48 *obj = object_pool_.At(index); |
| 49 } else { |
| 50 int value = 0; |
| 51 end = DecodeLoadWordImmediate(end, reg, &value); |
| 52 *obj = reinterpret_cast<RawObject*>(value); |
| 53 } |
| 54 return end; |
| 55 } |
| 56 |
| 57 |
| 58 // Decodes a load sequence ending at end. Returns the register being loaded and |
| 59 // the loaded immediate value. |
| 60 // Returns the location of the load sequence, counting the number of |
| 61 // instructions back from the end of the call pattern. |
| 62 int CallPattern::DecodeLoadWordImmediate(int end, Register* reg, int* value) { |
| 63 ASSERT(end > 0); |
| 64 uword instr = Back(++end); |
| 65 int imm = 0; |
| 66 if ((instr & 0xfff00000) == 0xe3400000) { // movt reg, #imm_hi |
| 67 imm |= (instr & 0xf0000) << 12; |
| 68 imm |= (instr & 0xfff) << 16; |
| 69 instr = Back(++end); |
| 70 } |
| 71 ASSERT((instr & 0xfff00000) == 0xe3000000); // movw reg, #imm_lo |
| 72 imm |= (instr & 0xf0000) >> 4; |
| 73 imm |= instr & 0xfff; |
| 74 *reg = static_cast<Register>((instr & 0xf000) >> 12); |
| 75 *value = imm; |
| 76 return end; |
| 77 } |
| 78 |
| 79 |
| 80 // Decodes a load sequence ending at end. Returns the register being loaded and |
| 39 // the index in the pool being read from. | 81 // the index in the pool being read from. |
| 40 // Returns the location of the load sequence, counting the number of | 82 // Returns the location of the load sequence, counting the number of |
| 41 // instructions back from the end of the call pattern. | 83 // instructions back from the end of the call pattern. |
| 42 int CallPattern::DecodeLoadWordFromPool(int end, Register* reg, int* index) { | 84 int CallPattern::DecodeLoadWordFromPool(int end, Register* reg, int* index) { |
| 43 ASSERT(end > 0); | 85 ASSERT(end > 0); |
| 44 uword instr = Back(++end); | 86 uword instr = Back(++end); |
| 45 int offset = 0; | 87 int offset = 0; |
| 46 if ((instr & 0xffff0000) == 0xe59a0000) { // ldr reg, [pp, #+offset] | 88 if ((instr & 0xffff0000) == 0xe59a0000) { // ldr reg, [pp, #+offset] |
| 47 offset = instr & 0xfff; | 89 offset = instr & 0xfff; |
| 48 *reg = static_cast<Register>((instr & 0xf000) >> 12); | 90 *reg = static_cast<Register>((instr & 0xf000) >> 12); |
| 49 } else { | 91 } else { |
| 50 ASSERT((instr & 0xfff00000) == 0xe5900000); // ldr reg, [reg, #+offset] | 92 ASSERT((instr & 0xfff00000) == 0xe5900000); // ldr reg, [reg, #+offset] |
| 51 offset = instr & 0xfff; | 93 offset = instr & 0xfff; |
| 52 instr = Back(++end); | 94 instr = Back(++end); |
| 53 if ((instr & 0xffff0000) == 0xe28a0000) { // add reg, pp, shifter_op | 95 if ((instr & 0xffff0000) == 0xe28a0000) { // add reg, pp, shifter_op |
| 54 const int rot = (instr & 0xf00) * 2; | 96 const int rot = (instr & 0xf00) * 2; |
| 55 const int imm8 = instr & 0xff; | 97 const int imm8 = instr & 0xff; |
| 56 offset |= (imm8 >> rot) | (imm8 << (32 - rot)); | 98 offset |= (imm8 >> rot) | (imm8 << (32 - rot)); |
| 57 *reg = static_cast<Register>((instr & 0xf000) >> 12); | 99 *reg = static_cast<Register>((instr & 0xf000) >> 12); |
| 58 } else { | 100 } else { |
| 59 ASSERT((instr & 0xffff0000) == 0xe08a0000); // add reg, pp, reg | 101 ASSERT((instr & 0xffff0000) == 0xe08a0000); // add reg, pp, reg |
| 60 instr = Back(++end); | 102 end = DecodeLoadWordImmediate(end, reg, &offset); |
| 61 if ((instr & 0xfff00000) == 0xe3400000) { // movt reg, offset_hi | |
| 62 offset |= (instr & 0xf0000) << 12; | |
| 63 offset |= (instr & 0xfff) << 16; | |
| 64 instr = Back(++end); | |
| 65 } | |
| 66 ASSERT((instr & 0xfff00000) == 0xe3000000); // movw reg, offset_lo | |
| 67 ASSERT((offset & 0xffff) == 0); | |
| 68 offset |= (instr & 0xf0000) >> 4; | |
| 69 offset |= instr & 0xfff; | |
| 70 *reg = static_cast<Register>((instr & 0xf000) >> 12); | |
| 71 } | 103 } |
| 72 } | 104 } |
| 73 offset += kHeapObjectTag; | 105 offset += kHeapObjectTag; |
| 74 ASSERT(Utils::IsAligned(offset, 4)); | 106 ASSERT(Utils::IsAligned(offset, 4)); |
| 75 *index = (offset - Array::data_offset())/4; | 107 *index = (offset - Array::data_offset())/4; |
| 76 return end; | 108 return end; |
| 77 } | 109 } |
| 78 | 110 |
| 79 | 111 |
| 80 RawICData* CallPattern::IcData() { | 112 RawICData* CallPattern::IcData() { |
| 81 if (ic_data_pool_index_ < 0) { | 113 if (ic_data_.IsNull()) { |
| 82 Register reg; | 114 Register reg; |
| 83 // Loading of the argument descriptor must be decoded first, if not already. | 115 // Loading of the argument descriptor must be decoded first, if not already. |
| 84 if (args_desc_pool_index_ < 0) { | 116 if (args_desc_.IsNull()) { |
| 85 ic_data_load_end_ = DecodeLoadWordFromPool( | 117 ic_data_load_end_ = DecodeLoadObject( |
| 86 args_desc_load_end_, ®, &args_desc_pool_index_); | 118 args_desc_load_end_, ®, &args_desc_); |
| 87 ASSERT(reg == R4); | 119 ASSERT(reg == R4); |
| 88 } | 120 } |
| 89 DecodeLoadWordFromPool(ic_data_load_end_, ®, &ic_data_pool_index_); | 121 DecodeLoadObject(ic_data_load_end_, ®, &ic_data_); |
| 90 ASSERT(reg == R5); | 122 ASSERT(reg == R5); |
| 91 } | 123 } |
| 92 ICData& ic_data = ICData::Handle(); | 124 return ic_data_.raw(); |
| 93 ic_data ^= object_pool_.At(ic_data_pool_index_); | |
| 94 return ic_data.raw(); | |
| 95 } | 125 } |
| 96 | 126 |
| 97 | 127 |
| 98 RawArray* CallPattern::ArgumentsDescriptor() { | 128 RawArray* CallPattern::ArgumentsDescriptor() { |
| 99 if (args_desc_pool_index_ < 0) { | 129 if (args_desc_.IsNull()) { |
| 100 Register reg; | 130 Register reg; |
| 101 ic_data_load_end_ = DecodeLoadWordFromPool( | 131 ic_data_load_end_ = DecodeLoadObject( |
| 102 args_desc_load_end_, ®, &args_desc_pool_index_); | 132 args_desc_load_end_, ®, &args_desc_); |
| 103 ASSERT(reg == R4); | 133 ASSERT(reg == R4); |
| 104 } | 134 } |
| 105 Array& args_desc = Array::Handle(); | 135 return args_desc_.raw(); |
| 106 args_desc ^= object_pool_.At(args_desc_pool_index_); | |
| 107 return args_desc.raw(); | |
| 108 } | 136 } |
| 109 | 137 |
| 110 | 138 |
| 111 uword CallPattern::TargetAddress() const { | 139 uword CallPattern::TargetAddress() const { |
| 112 ASSERT(target_address_pool_index_ >= 0); | 140 ASSERT(target_address_pool_index_ >= 0); |
| 113 const Object& target_address = | 141 const Object& target_address = |
| 114 Object::Handle(object_pool_.At(target_address_pool_index_)); | 142 Object::Handle(object_pool_.At(target_address_pool_index_)); |
| 115 ASSERT(target_address.IsSmi()); | 143 ASSERT(target_address.IsSmi()); |
| 116 // The address is stored in the object array as a RawSmi. | 144 // The address is stored in the object array as a RawSmi. |
| 117 return reinterpret_cast<uword>(target_address.raw()); | 145 return reinterpret_cast<uword>(target_address.raw()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 uword movt = 0xe340c000 | ((target_hi >> 12) << 16) | (target_hi & 0xfff); | 184 uword movt = 0xe340c000 | ((target_hi >> 12) << 16) | (target_hi & 0xfff); |
| 157 *reinterpret_cast<uword*>(pc_ + (0 * Instr::kInstrSize)) = movw; | 185 *reinterpret_cast<uword*>(pc_ + (0 * Instr::kInstrSize)) = movw; |
| 158 *reinterpret_cast<uword*>(pc_ + (1 * Instr::kInstrSize)) = movt; | 186 *reinterpret_cast<uword*>(pc_ + (1 * Instr::kInstrSize)) = movt; |
| 159 CPU::FlushICache(pc_, 2 * Instr::kInstrSize); | 187 CPU::FlushICache(pc_, 2 * Instr::kInstrSize); |
| 160 } | 188 } |
| 161 | 189 |
| 162 } // namespace dart | 190 } // namespace dart |
| 163 | 191 |
| 164 #endif // defined TARGET_ARCH_ARM | 192 #endif // defined TARGET_ARCH_ARM |
| 165 | 193 |
| OLD | NEW |