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

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

Issue 12439005: Implement leaf runtime call stub on ARM and corresponding call redirection (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"
9 #include "vm/cpu.h"
8 #include "vm/instructions.h" 10 #include "vm/instructions.h"
9 #include "vm/object.h" 11 #include "vm/object.h"
10 12
11 namespace dart { 13 namespace dart {
12 14
13 uword InstructionPattern::Back(int n) const { 15 CallPattern::CallPattern(uword pc, const Code& code)
16 : end_(reinterpret_cast<uword*>(pc)),
17 pool_index_(DecodePoolIndex()),
18 object_pool_(Array::Handle(code.ObjectPool())) { }
19
20
21 uword CallPattern::Back(int n) const {
14 ASSERT(n > 0); 22 ASSERT(n > 0);
15 return *(end_ - n); 23 return *(end_ - n);
16 } 24 }
17 25
18 26
19 CallPattern::CallPattern(uword pc, const Code& code)
20 : InstructionPattern(pc),
21 pool_index_(DecodePoolIndex()),
22 object_pool_(Array::Handle(code.ObjectPool())) { }
23
24
25 int CallPattern::DecodePoolIndex() { 27 int CallPattern::DecodePoolIndex() {
26 ASSERT(Back(1) == 0xe12fff3e); // Last instruction: blx lr 28 ASSERT(Back(1) == 0xe12fff3e); // Last instruction: blx lr
27 // Decode the second to last instruction. 29 // Decode the second to last instruction.
28 uword instr = Back(2); 30 uword instr = Back(2);
29 int offset = 0; 31 int offset = 0;
30 if ((instr & 0xfffff000) == 0xe59ae000) { // ldr lr, [pp, #+offset] 32 if ((instr & 0xfffff000) == 0xe59ae000) { // ldr lr, [pp, #+offset]
31 offset = instr & 0xfff; 33 offset = instr & 0xfff;
32 } else { 34 } else {
33 ASSERT((instr & 0xfffff000) == 0xe59ee000); // ldr lr, [lr, #+offset] 35 ASSERT((instr & 0xfffff000) == 0xe59ee000); // ldr lr, [lr, #+offset]
34 offset = instr & 0xfff; 36 offset = instr & 0xfff;
(...skipping 28 matching lines...) Expand all
63 // The address is stored in the object array as a RawSmi. 65 // The address is stored in the object array as a RawSmi.
64 return reinterpret_cast<uword>(target_address.raw()); 66 return reinterpret_cast<uword>(target_address.raw());
65 } 67 }
66 68
67 69
68 void CallPattern::SetTargetAddress(uword target_address) const { 70 void CallPattern::SetTargetAddress(uword target_address) const {
69 ASSERT(Utils::IsAligned(target_address, 4)); 71 ASSERT(Utils::IsAligned(target_address, 4));
70 // The address is stored in the object array as a RawSmi. 72 // The address is stored in the object array as a RawSmi.
71 const Smi& smi = Smi::Handle(reinterpret_cast<RawSmi*>(target_address)); 73 const Smi& smi = Smi::Handle(reinterpret_cast<RawSmi*>(target_address));
72 object_pool_.SetAt(pool_index_, smi); 74 object_pool_.SetAt(pool_index_, smi);
75 // No need to flush the instruction cache, since the code is not modified.
73 } 76 }
74 77
75 78
79 JumpPattern::JumpPattern(uword pc) : pc_(pc) { }
80
81
76 bool JumpPattern::IsValid() const { 82 bool JumpPattern::IsValid() const {
77 UNIMPLEMENTED(); 83 Instr* movw = Instr::At(pc_ + (0 * Instr::kInstrSize)); // movw ip, target_lo
78 return false; 84 Instr* movt = Instr::At(pc_ + (1 * Instr::kInstrSize)); // movw ip, target_lo
85 Instr* bxip = Instr::At(pc_ + (2 * Instr::kInstrSize)); // bx ip
86 return (movw->InstructionBits() & 0xfff0f000) == 0xe300c000 &&
87 (movt->InstructionBits() & 0xfff0f000) == 0xe340c000 &&
88 (bxip->InstructionBits() & 0xffffffff) == 0xe12fff1c;
79 } 89 }
80 90
81 91
82 uword JumpPattern::TargetAddress() const { 92 uword JumpPattern::TargetAddress() const {
83 UNIMPLEMENTED(); 93 Instr* movw = Instr::At(pc_ + (0 * Instr::kInstrSize)); // movw ip, target_lo
84 return 0; 94 Instr* movt = Instr::At(pc_ + (1 * Instr::kInstrSize)); // movw ip, target_lo
95 uint16_t target_lo = movw->MovwField();
96 uint16_t target_hi = movt->MovwField();
97 return (target_hi << 16) | target_lo;
85 } 98 }
86 99
87 100
88 void JumpPattern::SetTargetAddress(uword target) const { 101 void JumpPattern::SetTargetAddress(uword target_address) const {
89 UNIMPLEMENTED(); 102 uint16_t target_lo = target_address & 0xffff;
103 uint16_t target_hi = target_address >> 16;
104 uword movw = 0xe300c000 | ((target_lo >> 12) << 16) | (target_lo & 0xfff);
105 uword movt = 0xe340c000 | ((target_hi >> 12) << 16) | (target_hi & 0xfff);
106 *reinterpret_cast<uword*>(pc_ + (0 * Instr::kInstrSize)) = movw;
107 *reinterpret_cast<uword*>(pc_ + (1 * Instr::kInstrSize)) = movt;
108 CPU::FlushICache(pc_, 2 * Instr::kInstrSize);
90 } 109 }
91 110
92 } // namespace dart 111 } // namespace dart
93 112
94 #endif // defined TARGET_ARCH_ARM 113 #endif // defined TARGET_ARCH_ARM
95 114
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