| 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" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 142 |
| 143 void CallPattern::SetTargetAddress(uword target_address) const { | 143 void CallPattern::SetTargetAddress(uword target_address) const { |
| 144 ASSERT(Utils::IsAligned(target_address, 4)); | 144 ASSERT(Utils::IsAligned(target_address, 4)); |
| 145 // The address is stored in the object array as a RawSmi. | 145 // The address is stored in the object array as a RawSmi. |
| 146 const Smi& smi = Smi::Handle(reinterpret_cast<RawSmi*>(target_address)); | 146 const Smi& smi = Smi::Handle(reinterpret_cast<RawSmi*>(target_address)); |
| 147 object_pool_.SetAt(target_address_pool_index_, smi); | 147 object_pool_.SetAt(target_address_pool_index_, smi); |
| 148 // No need to flush the instruction cache, since the code is not modified. | 148 // No need to flush the instruction cache, since the code is not modified. |
| 149 } | 149 } |
| 150 | 150 |
| 151 | 151 |
| 152 void CallPattern::InsertAt(uword pc, uword target_address) { |
| 153 uint16_t target_lo = target_address & 0xffff; |
| 154 uint16_t target_hi = target_address >> 16; |
| 155 uword movw_ip = 0xe300c000 | ((target_lo >> 12) << 16) | (target_lo & 0xfff); |
| 156 uword movt_ip = 0xe340c000 | ((target_hi >> 12) << 16) | (target_hi & 0xfff); |
| 157 uword blx_ip = 0xe12fff3c; |
| 158 *reinterpret_cast<uword*>(pc + (0 * Instr::kInstrSize)) = movw_ip; |
| 159 *reinterpret_cast<uword*>(pc + (1 * Instr::kInstrSize)) = movt_ip; |
| 160 *reinterpret_cast<uword*>(pc + (2 * Instr::kInstrSize)) = blx_ip; |
| 161 ASSERT(kFixedLengthInBytes == 3 * Instr::kInstrSize); |
| 162 CPU::FlushICache(pc, kFixedLengthInBytes); |
| 163 } |
| 164 |
| 165 |
| 152 JumpPattern::JumpPattern(uword pc) : pc_(pc) { } | 166 JumpPattern::JumpPattern(uword pc) : pc_(pc) { } |
| 153 | 167 |
| 154 | 168 |
| 155 bool JumpPattern::IsValid() const { | 169 bool JumpPattern::IsValid() const { |
| 156 Instr* movw = Instr::At(pc_ + (0 * Instr::kInstrSize)); // movw ip, target_lo | 170 Instr* movw_ip = Instr::At(pc_ + (0 * Instr::kInstrSize)); // target_lo |
| 157 Instr* movt = Instr::At(pc_ + (1 * Instr::kInstrSize)); // movw ip, target_lo | 171 Instr* movt_ip = Instr::At(pc_ + (1 * Instr::kInstrSize)); // target_hi |
| 158 Instr* bxip = Instr::At(pc_ + (2 * Instr::kInstrSize)); // bx ip | 172 Instr* bx_ip = Instr::At(pc_ + (2 * Instr::kInstrSize)); |
| 159 return (movw->InstructionBits() & 0xfff0f000) == 0xe300c000 && | 173 return (movw_ip->InstructionBits() & 0xfff0f000) == 0xe300c000 && |
| 160 (movt->InstructionBits() & 0xfff0f000) == 0xe340c000 && | 174 (movt_ip->InstructionBits() & 0xfff0f000) == 0xe340c000 && |
| 161 (bxip->InstructionBits() & 0xffffffff) == 0xe12fff1c; | 175 (bx_ip->InstructionBits() & 0xffffffff) == 0xe12fff1c; |
| 162 } | 176 } |
| 163 | 177 |
| 164 | 178 |
| 165 uword JumpPattern::TargetAddress() const { | 179 uword JumpPattern::TargetAddress() const { |
| 166 Instr* movw = Instr::At(pc_ + (0 * Instr::kInstrSize)); // movw ip, target_lo | 180 Instr* movw_ip = Instr::At(pc_ + (0 * Instr::kInstrSize)); // target_lo |
| 167 Instr* movt = Instr::At(pc_ + (1 * Instr::kInstrSize)); // movw ip, target_lo | 181 Instr* movt_ip = Instr::At(pc_ + (1 * Instr::kInstrSize)); // target_hi |
| 168 uint16_t target_lo = movw->MovwField(); | 182 uint16_t target_lo = movw_ip->MovwField(); |
| 169 uint16_t target_hi = movt->MovwField(); | 183 uint16_t target_hi = movt_ip->MovwField(); |
| 170 return (target_hi << 16) | target_lo; | 184 return (target_hi << 16) | target_lo; |
| 171 } | 185 } |
| 172 | 186 |
| 173 | 187 |
| 174 void JumpPattern::SetTargetAddress(uword target_address) const { | 188 void JumpPattern::SetTargetAddress(uword target_address) const { |
| 175 uint16_t target_lo = target_address & 0xffff; | 189 uint16_t target_lo = target_address & 0xffff; |
| 176 uint16_t target_hi = target_address >> 16; | 190 uint16_t target_hi = target_address >> 16; |
| 177 uword movw = 0xe300c000 | ((target_lo >> 12) << 16) | (target_lo & 0xfff); | 191 uword movw_ip = 0xe300c000 | ((target_lo >> 12) << 16) | (target_lo & 0xfff); |
| 178 uword movt = 0xe340c000 | ((target_hi >> 12) << 16) | (target_hi & 0xfff); | 192 uword movt_ip = 0xe340c000 | ((target_hi >> 12) << 16) | (target_hi & 0xfff); |
| 179 *reinterpret_cast<uword*>(pc_ + (0 * Instr::kInstrSize)) = movw; | 193 *reinterpret_cast<uword*>(pc_ + (0 * Instr::kInstrSize)) = movw_ip; |
| 180 *reinterpret_cast<uword*>(pc_ + (1 * Instr::kInstrSize)) = movt; | 194 *reinterpret_cast<uword*>(pc_ + (1 * Instr::kInstrSize)) = movt_ip; |
| 181 CPU::FlushICache(pc_, 2 * Instr::kInstrSize); | 195 CPU::FlushICache(pc_, 2 * Instr::kInstrSize); |
| 182 } | 196 } |
| 183 | 197 |
| 184 } // namespace dart | 198 } // namespace dart |
| 185 | 199 |
| 186 #endif // defined TARGET_ARCH_ARM | 200 #endif // defined TARGET_ARCH_ARM |
| 187 | 201 |
| OLD | NEW |