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_MIPS. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_MIPS. |
6 #if defined(TARGET_ARCH_MIPS) | 6 #if defined(TARGET_ARCH_MIPS) |
7 | 7 |
8 #include "vm/constants_mips.h" | 8 #include "vm/constants_mips.h" |
| 9 #include "vm/cpu.h" |
9 #include "vm/instructions.h" | 10 #include "vm/instructions.h" |
10 #include "vm/object.h" | 11 #include "vm/object.h" |
11 | 12 |
12 namespace dart { | 13 namespace dart { |
13 | 14 |
14 CallPattern::CallPattern(uword pc, const Code& code) | 15 CallPattern::CallPattern(uword pc, const Code& code) |
15 : end_(reinterpret_cast<uword*>(pc)), | 16 : end_(reinterpret_cast<uword*>(pc)), |
16 target_address_pool_index_(-1), | 17 target_address_pool_index_(-1), |
17 args_desc_load_end_(-1), | 18 args_desc_load_end_(-1), |
18 args_desc_(Array::Handle()), | 19 args_desc_(Array::Handle()), |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 | 152 |
152 void CallPattern::SetTargetAddress(uword target_address) const { | 153 void CallPattern::SetTargetAddress(uword target_address) const { |
153 ASSERT(Utils::IsAligned(target_address, 4)); | 154 ASSERT(Utils::IsAligned(target_address, 4)); |
154 // The address is stored in the object array as a RawSmi. | 155 // The address is stored in the object array as a RawSmi. |
155 const Smi& smi = Smi::Handle(reinterpret_cast<RawSmi*>(target_address)); | 156 const Smi& smi = Smi::Handle(reinterpret_cast<RawSmi*>(target_address)); |
156 object_pool_.SetAt(target_address_pool_index_, smi); | 157 object_pool_.SetAt(target_address_pool_index_, smi); |
157 // No need to flush the instruction cache, since the code is not modified. | 158 // No need to flush the instruction cache, since the code is not modified. |
158 } | 159 } |
159 | 160 |
160 | 161 |
| 162 void CallPattern::InsertAt(uword pc, uword target_address) { |
| 163 Instr* lui = Instr::At(pc + (0 * Instr::kInstrSize)); |
| 164 Instr* ori = Instr::At(pc + (1 * Instr::kInstrSize)); |
| 165 Instr* jr = Instr::At(pc + (2 * Instr::kInstrSize)); |
| 166 Instr* nop = Instr::At(pc + (3 * Instr::kInstrSize)); |
| 167 uint16_t target_lo = target_address & 0xffff; |
| 168 uint16_t target_hi = target_address >> 16; |
| 169 |
| 170 lui->SetImmInstrBits(LUI, ZR, TMP1, target_hi); |
| 171 ori->SetImmInstrBits(ORI, TMP1, TMP1, target_lo); |
| 172 jr->SetSpecialInstrBits(JALR, TMP1, ZR, RA); |
| 173 nop->SetInstructionBits(Instr::kNopInstruction); |
| 174 |
| 175 ASSERT(kFixedLengthInBytes == 4 * Instr::kInstrSize); |
| 176 CPU::FlushICache(pc, kFixedLengthInBytes); |
| 177 } |
| 178 |
| 179 |
161 JumpPattern::JumpPattern(uword pc) : pc_(pc) { } | 180 JumpPattern::JumpPattern(uword pc) : pc_(pc) { } |
162 | 181 |
163 | 182 |
164 bool JumpPattern::IsValid() const { | 183 bool JumpPattern::IsValid() const { |
165 Instr* lui = Instr::At(pc_ + (0 * Instr::kInstrSize)); | 184 Instr* lui = Instr::At(pc_ + (0 * Instr::kInstrSize)); |
166 Instr* ori = Instr::At(pc_ + (1 * Instr::kInstrSize)); | 185 Instr* ori = Instr::At(pc_ + (1 * Instr::kInstrSize)); |
167 Instr* jr = Instr::At(pc_ + (2 * Instr::kInstrSize)); | 186 Instr* jr = Instr::At(pc_ + (2 * Instr::kInstrSize)); |
168 Instr* nop = Instr::At(pc_ + (3 * Instr::kInstrSize)); | 187 Instr* nop = Instr::At(pc_ + (3 * Instr::kInstrSize)); |
169 return (lui->OpcodeField() == LUI) && | 188 return (lui->OpcodeField() == LUI) && |
170 (ori->OpcodeField() == ORI) && | 189 (ori->OpcodeField() == ORI) && |
(...skipping 21 matching lines...) Expand all Loading... |
192 const uint16_t target_hi = target_address >> 16; | 211 const uint16_t target_hi = target_address >> 16; |
193 | 212 |
194 lui->SetInstructionBits((lui_bits & 0xffff0000) | target_hi); | 213 lui->SetInstructionBits((lui_bits & 0xffff0000) | target_hi); |
195 ori->SetInstructionBits((ori_bits & 0xffff0000) | target_lo); | 214 ori->SetInstructionBits((ori_bits & 0xffff0000) | target_lo); |
196 } | 215 } |
197 | 216 |
198 } // namespace dart | 217 } // namespace dart |
199 | 218 |
200 #endif // defined TARGET_ARCH_MIPS | 219 #endif // defined TARGET_ARCH_MIPS |
201 | 220 |
OLD | NEW |