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/cpu.h" |
10 #include "vm/instructions.h" | 10 #include "vm/instructions.h" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 return object_pool_.RawValueAt(target_address_pool_index_); | 157 return object_pool_.RawValueAt(target_address_pool_index_); |
158 } | 158 } |
159 | 159 |
160 | 160 |
161 void CallPattern::SetTargetAddress(uword target_address) const { | 161 void CallPattern::SetTargetAddress(uword target_address) const { |
162 object_pool_.SetRawValueAt(target_address_pool_index_, target_address); | 162 object_pool_.SetRawValueAt(target_address_pool_index_, target_address); |
163 // No need to flush the instruction cache, since the code is not modified. | 163 // No need to flush the instruction cache, since the code is not modified. |
164 } | 164 } |
165 | 165 |
166 | 166 |
| 167 NativeCallPattern::NativeCallPattern(uword pc, const Code& code) |
| 168 : object_pool_(ObjectPool::Handle(code.GetObjectPool())), |
| 169 end_(pc), |
| 170 native_function_pool_index_(-1), |
| 171 target_address_pool_index_(-1) { |
| 172 ASSERT(code.ContainsInstructionAt(pc)); |
| 173 // Last instruction: jalr RA, T9(=R25). |
| 174 ASSERT(*(reinterpret_cast<uword*>(end_) - 2) == 0x0320f809); |
| 175 |
| 176 Register reg; |
| 177 uword native_function_load_end = |
| 178 InstructionPattern::DecodeLoadWordFromPool(end_ - 2 * Instr::kInstrSize, |
| 179 ®, |
| 180 &target_address_pool_index_); |
| 181 ASSERT(reg == T9); |
| 182 InstructionPattern::DecodeLoadWordFromPool(native_function_load_end, |
| 183 ®, |
| 184 &native_function_pool_index_); |
| 185 ASSERT(reg == T5); |
| 186 } |
| 187 |
| 188 |
| 189 uword NativeCallPattern::target() const { |
| 190 return object_pool_.RawValueAt(target_address_pool_index_); |
| 191 } |
| 192 |
| 193 |
| 194 void NativeCallPattern::set_target(uword target_address) const { |
| 195 object_pool_.SetRawValueAt(target_address_pool_index_, target_address); |
| 196 // No need to flush the instruction cache, since the code is not modified. |
| 197 } |
| 198 |
| 199 |
| 200 NativeFunction NativeCallPattern::native_function() const { |
| 201 return reinterpret_cast<NativeFunction>( |
| 202 object_pool_.RawValueAt(native_function_pool_index_)); |
| 203 } |
| 204 |
| 205 |
| 206 void NativeCallPattern::set_native_function(NativeFunction func) const { |
| 207 object_pool_.SetRawValueAt(native_function_pool_index_, |
| 208 reinterpret_cast<uword>(func)); |
| 209 } |
| 210 |
| 211 |
167 void CallPattern::InsertAt(uword pc, uword target_address) { | 212 void CallPattern::InsertAt(uword pc, uword target_address) { |
168 Instr* lui = Instr::At(pc + (0 * Instr::kInstrSize)); | 213 Instr* lui = Instr::At(pc + (0 * Instr::kInstrSize)); |
169 Instr* ori = Instr::At(pc + (1 * Instr::kInstrSize)); | 214 Instr* ori = Instr::At(pc + (1 * Instr::kInstrSize)); |
170 Instr* jr = Instr::At(pc + (2 * Instr::kInstrSize)); | 215 Instr* jr = Instr::At(pc + (2 * Instr::kInstrSize)); |
171 Instr* nop = Instr::At(pc + (3 * Instr::kInstrSize)); | 216 Instr* nop = Instr::At(pc + (3 * Instr::kInstrSize)); |
172 uint16_t target_lo = target_address & 0xffff; | 217 uint16_t target_lo = target_address & 0xffff; |
173 uint16_t target_hi = target_address >> 16; | 218 uint16_t target_hi = target_address >> 16; |
174 | 219 |
175 lui->SetImmInstrBits(LUI, ZR, T9, target_hi); | 220 lui->SetImmInstrBits(LUI, ZR, T9, target_hi); |
176 ori->SetImmInstrBits(ORI, T9, T9, target_lo); | 221 ori->SetImmInstrBits(ORI, T9, T9, target_lo); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 bool ReturnPattern::IsValid() const { | 273 bool ReturnPattern::IsValid() const { |
229 Instr* jr = Instr::At(pc_); | 274 Instr* jr = Instr::At(pc_); |
230 return (jr->OpcodeField() == SPECIAL) && | 275 return (jr->OpcodeField() == SPECIAL) && |
231 (jr->FunctionField() == JR) && | 276 (jr->FunctionField() == JR) && |
232 (jr->RsField() == RA); | 277 (jr->RsField() == RA); |
233 } | 278 } |
234 | 279 |
235 } // namespace dart | 280 } // namespace dart |
236 | 281 |
237 #endif // defined TARGET_ARCH_MIPS | 282 #endif // defined TARGET_ARCH_MIPS |
OLD | NEW |