Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(868)

Side by Side Diff: runtime/vm/instructions_arm.cc

Issue 12518016: Decode ic data and arguments descriptor passed in calls on ARM. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/instructions_arm.h ('k') | runtime/vm/instructions_arm_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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(code.ContainsInstructionAt(pc));
24 ASSERT(Back(1) == 0xe12fff3e); // Last instruction: blx lr
25 Register reg;
26 args_desc_load_end_ =
27 DecodeLoadWordFromPool(1, &reg, &target_address_pool_index_);
28 ASSERT(reg == LR);
29 }
19 30
20 31
21 uword CallPattern::Back(int n) const { 32 uword CallPattern::Back(int n) const {
22 ASSERT(n > 0); 33 ASSERT(n > 0);
23 return *(end_ - n); 34 return *(end_ - n);
24 } 35 }
25 36
26 37
27 int CallPattern::DecodePoolIndex() { 38 // Decodes a load sequence ending at end. Returns the register being loaded and
28 ASSERT(Back(1) == 0xe12fff3e); // Last instruction: blx lr 39 // the index in the pool being read from.
29 // Decode the second to last instruction. 40 // Returns the location of the load sequence, counting the number of
30 uword instr = Back(2); 41 // instructions back from the end of the call pattern.
42 int CallPattern::DecodeLoadWordFromPool(int end, Register* reg, int* index) {
43 ASSERT(end > 0);
44 uword instr = Back(++end);
31 int offset = 0; 45 int offset = 0;
32 if ((instr & 0xfffff000) == 0xe59ae000) { // ldr lr, [pp, #+offset] 46 if ((instr & 0xffff0000) == 0xe59a0000) { // ldr reg, [pp, #+offset]
33 offset = instr & 0xfff; 47 offset = instr & 0xfff;
48 *reg = static_cast<Register>((instr & 0xf000) >> 12);
34 } else { 49 } else {
35 ASSERT((instr & 0xfffff000) == 0xe59ee000); // ldr lr, [lr, #+offset] 50 ASSERT((instr & 0xfff00000) == 0xe5900000); // ldr reg, [reg, #+offset]
36 offset = instr & 0xfff; 51 offset = instr & 0xfff;
37 instr = Back(3); 52 instr = Back(++end);
38 if ((instr & 0xfffff000) == 0xe28ae000) { // add lr, pp, shifter_op 53 if ((instr & 0xffff0000) == 0xe28a0000) { // add reg, pp, shifter_op
39 const int rot = (instr & 0xf00) * 2; 54 const int rot = (instr & 0xf00) * 2;
40 const int imm8 = instr & 0xff; 55 const int imm8 = instr & 0xff;
41 offset |= (imm8 >> rot) | (imm8 << (32 - rot)); 56 offset |= (imm8 >> rot) | (imm8 << (32 - rot));
57 *reg = static_cast<Register>((instr & 0xf000) >> 12);
42 } else { 58 } else {
43 ASSERT(instr == 0xe08ae00e); // add lr, pp, lr 59 ASSERT((instr & 0xffff0000) == 0xe08a0000); // add reg, pp, reg
44 instr = Back(4); 60 instr = Back(++end);
45 if ((instr & 0xfff0f000) == 0xe340e000) { // movt lr, offset_hi 61 if ((instr & 0xfff00000) == 0xe3400000) { // movt reg, offset_hi
46 offset |= (instr & 0xf0000) << 12; 62 offset |= (instr & 0xf0000) << 12;
47 offset |= (instr & 0xfff) << 16; 63 offset |= (instr & 0xfff) << 16;
48 instr = Back(5); 64 instr = Back(++end);
49 } 65 }
50 ASSERT((instr & 0xfff0f000) == 0xe300e000); // movw lr, offset_lo 66 ASSERT((instr & 0xfff00000) == 0xe3000000); // movw reg, offset_lo
51 ASSERT((offset & 0xffff) == 0); 67 ASSERT((offset & 0xffff) == 0);
52 offset |= (instr & 0xf0000) >> 4; 68 offset |= (instr & 0xf0000) >> 4;
53 offset |= instr & 0xfff; 69 offset |= instr & 0xfff;
70 *reg = static_cast<Register>((instr & 0xf000) >> 12);
54 } 71 }
55 } 72 }
56 offset += kHeapObjectTag; 73 offset += kHeapObjectTag;
57 ASSERT(Utils::IsAligned(offset, 4)); 74 ASSERT(Utils::IsAligned(offset, 4));
58 return (offset - Array::data_offset())/4; 75 *index = (offset - Array::data_offset())/4;
76 return end;
77 }
78
79
80 RawICData* CallPattern::IcData() {
81 if (ic_data_pool_index_ < 0) {
82 Register reg;
83 // Loading of the argument descriptor must be decoded first, if not already.
84 if (args_desc_pool_index_ < 0) {
85 ic_data_load_end_ = DecodeLoadWordFromPool(
86 args_desc_load_end_, &reg, &args_desc_pool_index_);
87 ASSERT(reg == R4);
88 }
89 DecodeLoadWordFromPool(ic_data_load_end_, &reg, &ic_data_pool_index_);
90 ASSERT(reg == R5);
91 }
92 ICData& ic_data = ICData::Handle();
93 ic_data ^= object_pool_.At(ic_data_pool_index_);
94 return ic_data.raw();
95 }
96
97
98 RawArray* CallPattern::ArgumentsDescriptor() {
99 if (args_desc_pool_index_ < 0) {
100 Register reg;
101 ic_data_load_end_ = DecodeLoadWordFromPool(
102 args_desc_load_end_, &reg, &args_desc_pool_index_);
103 ASSERT(reg == R4);
104 }
105 Array& args_desc = Array::Handle();
106 args_desc ^= object_pool_.At(args_desc_pool_index_);
107 return args_desc.raw();
59 } 108 }
60 109
61 110
62 uword CallPattern::TargetAddress() const { 111 uword CallPattern::TargetAddress() const {
63 const Object& target_address = Object::Handle(object_pool_.At(pool_index_)); 112 ASSERT(target_address_pool_index_ >= 0);
113 const Object& target_address =
114 Object::Handle(object_pool_.At(target_address_pool_index_));
64 ASSERT(target_address.IsSmi()); 115 ASSERT(target_address.IsSmi());
65 // The address is stored in the object array as a RawSmi. 116 // The address is stored in the object array as a RawSmi.
66 return reinterpret_cast<uword>(target_address.raw()); 117 return reinterpret_cast<uword>(target_address.raw());
67 } 118 }
68 119
69 120
70 void CallPattern::SetTargetAddress(uword target_address) const { 121 void CallPattern::SetTargetAddress(uword target_address) const {
71 ASSERT(Utils::IsAligned(target_address, 4)); 122 ASSERT(Utils::IsAligned(target_address, 4));
72 // The address is stored in the object array as a RawSmi. 123 // The address is stored in the object array as a RawSmi.
73 const Smi& smi = Smi::Handle(reinterpret_cast<RawSmi*>(target_address)); 124 const Smi& smi = Smi::Handle(reinterpret_cast<RawSmi*>(target_address));
74 object_pool_.SetAt(pool_index_, smi); 125 object_pool_.SetAt(target_address_pool_index_, smi);
75 // No need to flush the instruction cache, since the code is not modified. 126 // No need to flush the instruction cache, since the code is not modified.
76 } 127 }
77 128
78 129
79 JumpPattern::JumpPattern(uword pc) : pc_(pc) { } 130 JumpPattern::JumpPattern(uword pc) : pc_(pc) { }
80 131
81 132
82 bool JumpPattern::IsValid() const { 133 bool JumpPattern::IsValid() const {
83 Instr* movw = Instr::At(pc_ + (0 * Instr::kInstrSize)); // movw ip, target_lo 134 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 135 Instr* movt = Instr::At(pc_ + (1 * Instr::kInstrSize)); // movw ip, target_lo
(...skipping 20 matching lines...) Expand all
105 uword movt = 0xe340c000 | ((target_hi >> 12) << 16) | (target_hi & 0xfff); 156 uword movt = 0xe340c000 | ((target_hi >> 12) << 16) | (target_hi & 0xfff);
106 *reinterpret_cast<uword*>(pc_ + (0 * Instr::kInstrSize)) = movw; 157 *reinterpret_cast<uword*>(pc_ + (0 * Instr::kInstrSize)) = movw;
107 *reinterpret_cast<uword*>(pc_ + (1 * Instr::kInstrSize)) = movt; 158 *reinterpret_cast<uword*>(pc_ + (1 * Instr::kInstrSize)) = movt;
108 CPU::FlushICache(pc_, 2 * Instr::kInstrSize); 159 CPU::FlushICache(pc_, 2 * Instr::kInstrSize);
109 } 160 }
110 161
111 } // namespace dart 162 } // namespace dart
112 163
113 #endif // defined TARGET_ARCH_ARM 164 #endif // defined TARGET_ARCH_ARM
114 165
OLDNEW
« no previous file with comments | « runtime/vm/instructions_arm.h ('k') | runtime/vm/instructions_arm_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698