OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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_ARM64. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM64. |
6 #if defined(TARGET_ARCH_ARM64) | 6 #if defined(TARGET_ARCH_ARM64) |
7 | 7 |
8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
9 #include "vm/constants_arm64.h" | 9 #include "vm/constants_arm64.h" |
10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
11 #include "vm/instructions.h" | 11 #include "vm/instructions.h" |
12 #include "vm/object.h" | 12 #include "vm/object.h" |
13 | 13 |
14 namespace dart { | 14 namespace dart { |
15 | 15 |
16 CallPattern::CallPattern(uword pc, const Code& code) | 16 CallPattern::CallPattern(uword pc, const Code& code) |
17 : object_pool_(ObjectPool::Handle(code.GetObjectPool())), | 17 : object_pool_(ObjectPool::Handle(code.GetObjectPool())), |
18 end_(pc), | 18 end_(pc), |
19 ic_data_load_end_(0), | 19 ic_data_load_end_(0), |
20 target_address_pool_index_(-1), | 20 target_code_pool_index_(-1), |
21 ic_data_(ICData::Handle()) { | 21 ic_data_(ICData::Handle()) { |
22 ASSERT(code.ContainsInstructionAt(pc)); | 22 ASSERT(code.ContainsInstructionAt(pc)); |
23 // Last instruction: blr ip0. | 23 // Last instruction: blr ip0. |
24 ASSERT(*(reinterpret_cast<uint32_t*>(end_) - 1) == 0xd63f0200); | 24 ASSERT(*(reinterpret_cast<uint32_t*>(end_) - 1) == 0xd63f0200); |
25 | 25 |
26 Register reg; | 26 Register reg; |
27 ic_data_load_end_ = | 27 ic_data_load_end_ = |
28 InstructionPattern::DecodeLoadWordFromPool(end_ - Instr::kInstrSize, | 28 InstructionPattern::DecodeLoadWordFromPool(end_ - 2 * Instr::kInstrSize, |
29 ®, | 29 ®, |
30 &target_address_pool_index_); | 30 &target_code_pool_index_); |
31 ASSERT(reg == IP0); | 31 ASSERT(reg == CODE_REG); |
32 } | 32 } |
33 | 33 |
34 | 34 |
35 NativeCallPattern::NativeCallPattern(uword pc, const Code& code) | 35 NativeCallPattern::NativeCallPattern(uword pc, const Code& code) |
36 : object_pool_(ObjectPool::Handle(code.GetObjectPool())), | 36 : object_pool_(ObjectPool::Handle(code.GetObjectPool())), |
37 end_(pc), | 37 end_(pc), |
38 native_function_pool_index_(-1), | 38 native_function_pool_index_(-1), |
39 target_address_pool_index_(-1) { | 39 target_code_pool_index_(-1) { |
40 ASSERT(code.ContainsInstructionAt(pc)); | 40 ASSERT(code.ContainsInstructionAt(pc)); |
41 // Last instruction: blr ip0. | 41 // Last instruction: blr ip0. |
42 ASSERT(*(reinterpret_cast<uint32_t*>(end_) - 1) == 0xd63f0200); | 42 ASSERT(*(reinterpret_cast<uint32_t*>(end_) - 1) == 0xd63f0200); |
43 | 43 |
44 Register reg; | 44 Register reg; |
45 uword native_function_load_end = | 45 uword native_function_load_end = |
46 InstructionPattern::DecodeLoadWordFromPool(end_ - Instr::kInstrSize, | 46 InstructionPattern::DecodeLoadWordFromPool(end_ - 2 * Instr::kInstrSize, |
47 ®, | 47 ®, |
48 &target_address_pool_index_); | 48 &target_code_pool_index_); |
49 ASSERT(reg == IP0); | 49 ASSERT(reg == CODE_REG); |
50 InstructionPattern::DecodeLoadWordFromPool(native_function_load_end, | 50 InstructionPattern::DecodeLoadWordFromPool(native_function_load_end, |
51 ®, | 51 ®, |
52 &native_function_pool_index_); | 52 &native_function_pool_index_); |
53 ASSERT(reg == R5); | 53 ASSERT(reg == R5); |
54 } | 54 } |
55 | 55 |
56 | 56 |
57 uword NativeCallPattern::target() const { | 57 RawCode* NativeCallPattern::target() const { |
58 return object_pool_.RawValueAt(target_address_pool_index_); | 58 return reinterpret_cast<RawCode*>( |
| 59 object_pool_.ObjectAt(target_code_pool_index_)); |
59 } | 60 } |
60 | 61 |
61 | 62 |
62 void NativeCallPattern::set_target(uword target_address) const { | 63 void NativeCallPattern::set_target(const Code& target) const { |
63 object_pool_.SetRawValueAt(target_address_pool_index_, target_address); | 64 object_pool_.SetObjectAt(target_code_pool_index_, target); |
64 // No need to flush the instruction cache, since the code is not modified. | 65 // No need to flush the instruction cache, since the code is not modified. |
65 } | 66 } |
66 | 67 |
67 | 68 |
68 NativeFunction NativeCallPattern::native_function() const { | 69 NativeFunction NativeCallPattern::native_function() const { |
69 return reinterpret_cast<NativeFunction>( | 70 return reinterpret_cast<NativeFunction>( |
70 object_pool_.RawValueAt(native_function_pool_index_)); | 71 object_pool_.RawValueAt(native_function_pool_index_)); |
71 } | 72 } |
72 | 73 |
73 | 74 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 InstructionPattern::DecodeLoadObject(ic_data_load_end_, | 286 InstructionPattern::DecodeLoadObject(ic_data_load_end_, |
286 object_pool_, | 287 object_pool_, |
287 ®, | 288 ®, |
288 &ic_data_); | 289 &ic_data_); |
289 ASSERT(reg == R5); | 290 ASSERT(reg == R5); |
290 } | 291 } |
291 return ic_data_.raw(); | 292 return ic_data_.raw(); |
292 } | 293 } |
293 | 294 |
294 | 295 |
295 uword CallPattern::TargetAddress() const { | 296 RawCode* CallPattern::TargetCode() const { |
296 return object_pool_.RawValueAt(target_address_pool_index_); | 297 return reinterpret_cast<RawCode*>( |
| 298 object_pool_.ObjectAt(target_code_pool_index_)); |
297 } | 299 } |
298 | 300 |
299 | 301 |
300 void CallPattern::SetTargetAddress(uword target_address) const { | 302 void CallPattern::SetTargetCode(const Code& target) const { |
301 object_pool_.SetRawValueAt(target_address_pool_index_, target_address); | 303 object_pool_.SetObjectAt(target_code_pool_index_, target); |
302 // No need to flush the instruction cache, since the code is not modified. | 304 // No need to flush the instruction cache, since the code is not modified. |
303 } | 305 } |
304 | 306 |
305 | 307 |
306 void CallPattern::InsertAt(uword pc, uword target_address) { | 308 void CallPattern::InsertDeoptCallAt(uword pc, uword target_address) { |
307 Instr* movz0 = Instr::At(pc + (0 * Instr::kInstrSize)); | 309 Instr* movz0 = Instr::At(pc + (0 * Instr::kInstrSize)); |
308 Instr* movk1 = Instr::At(pc + (1 * Instr::kInstrSize)); | 310 Instr* movk1 = Instr::At(pc + (1 * Instr::kInstrSize)); |
309 Instr* movk2 = Instr::At(pc + (2 * Instr::kInstrSize)); | 311 Instr* movk2 = Instr::At(pc + (2 * Instr::kInstrSize)); |
310 Instr* movk3 = Instr::At(pc + (3 * Instr::kInstrSize)); | 312 Instr* movk3 = Instr::At(pc + (3 * Instr::kInstrSize)); |
311 Instr* blr = Instr::At(pc + (4 * Instr::kInstrSize)); | 313 Instr* blr = Instr::At(pc + (4 * Instr::kInstrSize)); |
312 const uint32_t w0 = Utils::Low32Bits(target_address); | 314 const uint32_t w0 = Utils::Low32Bits(target_address); |
313 const uint32_t w1 = Utils::High32Bits(target_address); | 315 const uint32_t w1 = Utils::High32Bits(target_address); |
314 const uint16_t h0 = Utils::Low16Bits(w0); | 316 const uint16_t h0 = Utils::Low16Bits(w0); |
315 const uint16_t h1 = Utils::High16Bits(w0); | 317 const uint16_t h1 = Utils::High16Bits(w0); |
316 const uint16_t h2 = Utils::Low16Bits(w1); | 318 const uint16_t h2 = Utils::Low16Bits(w1); |
317 const uint16_t h3 = Utils::High16Bits(w1); | 319 const uint16_t h3 = Utils::High16Bits(w1); |
318 | 320 |
319 movz0->SetMoveWideBits(MOVZ, IP0, h0, 0, kDoubleWord); | 321 movz0->SetMoveWideBits(MOVZ, IP0, h0, 0, kDoubleWord); |
320 movk1->SetMoveWideBits(MOVK, IP0, h1, 1, kDoubleWord); | 322 movk1->SetMoveWideBits(MOVK, IP0, h1, 1, kDoubleWord); |
321 movk2->SetMoveWideBits(MOVK, IP0, h2, 2, kDoubleWord); | 323 movk2->SetMoveWideBits(MOVK, IP0, h2, 2, kDoubleWord); |
322 movk3->SetMoveWideBits(MOVK, IP0, h3, 3, kDoubleWord); | 324 movk3->SetMoveWideBits(MOVK, IP0, h3, 3, kDoubleWord); |
323 blr->SetUnconditionalBranchRegBits(BLR, IP0); | 325 blr->SetUnconditionalBranchRegBits(BLR, IP0); |
324 | 326 |
325 ASSERT(kLengthInBytes == 5 * Instr::kInstrSize); | 327 ASSERT(kDeoptCallLengthInBytes == 5 * Instr::kInstrSize); |
326 CPU::FlushICache(pc, kLengthInBytes); | 328 CPU::FlushICache(pc, kDeoptCallLengthInBytes); |
327 } | 329 } |
328 | 330 |
329 | 331 |
330 JumpPattern::JumpPattern(uword pc, const Code& code) : pc_(pc) { } | |
331 | |
332 | |
333 bool JumpPattern::IsValid() const { | |
334 Instr* movz0 = Instr::At(pc_ + (0 * Instr::kInstrSize)); | |
335 Instr* movk1 = Instr::At(pc_ + (1 * Instr::kInstrSize)); | |
336 Instr* movk2 = Instr::At(pc_ + (2 * Instr::kInstrSize)); | |
337 Instr* movk3 = Instr::At(pc_ + (3 * Instr::kInstrSize)); | |
338 Instr* br = Instr::At(pc_ + (4 * Instr::kInstrSize)); | |
339 return (movz0->IsMoveWideOp()) && (movz0->Bits(29, 2) == 2) && | |
340 (movk1->IsMoveWideOp()) && (movk1->Bits(29, 2) == 3) && | |
341 (movk2->IsMoveWideOp()) && (movk2->Bits(29, 2) == 3) && | |
342 (movk3->IsMoveWideOp()) && (movk3->Bits(29, 2) == 3) && | |
343 (br->IsUnconditionalBranchRegOp()) && (br->Bits(16, 5) == 31); | |
344 } | |
345 | |
346 | |
347 uword JumpPattern::TargetAddress() const { | |
348 Instr* movz0 = Instr::At(pc_ + (0 * Instr::kInstrSize)); | |
349 Instr* movk1 = Instr::At(pc_ + (1 * Instr::kInstrSize)); | |
350 Instr* movk2 = Instr::At(pc_ + (2 * Instr::kInstrSize)); | |
351 Instr* movk3 = Instr::At(pc_ + (3 * Instr::kInstrSize)); | |
352 const uint16_t imm0 = movz0->Imm16Field(); | |
353 const uint16_t imm1 = movk1->Imm16Field(); | |
354 const uint16_t imm2 = movk2->Imm16Field(); | |
355 const uint16_t imm3 = movk3->Imm16Field(); | |
356 const int64_t target = | |
357 (static_cast<int64_t>(imm0)) | | |
358 (static_cast<int64_t>(imm1) << 16) | | |
359 (static_cast<int64_t>(imm2) << 32) | | |
360 (static_cast<int64_t>(imm3) << 48); | |
361 return target; | |
362 } | |
363 | |
364 | |
365 void JumpPattern::SetTargetAddress(uword target_address) const { | |
366 Instr* movz0 = Instr::At(pc_ + (0 * Instr::kInstrSize)); | |
367 Instr* movk1 = Instr::At(pc_ + (1 * Instr::kInstrSize)); | |
368 Instr* movk2 = Instr::At(pc_ + (2 * Instr::kInstrSize)); | |
369 Instr* movk3 = Instr::At(pc_ + (3 * Instr::kInstrSize)); | |
370 const int32_t movz0_bits = movz0->InstructionBits(); | |
371 const int32_t movk1_bits = movk1->InstructionBits(); | |
372 const int32_t movk2_bits = movk2->InstructionBits(); | |
373 const int32_t movk3_bits = movk3->InstructionBits(); | |
374 | |
375 const uint32_t w0 = Utils::Low32Bits(target_address); | |
376 const uint32_t w1 = Utils::High32Bits(target_address); | |
377 const uint16_t h0 = Utils::Low16Bits(w0); | |
378 const uint16_t h1 = Utils::High16Bits(w0); | |
379 const uint16_t h2 = Utils::Low16Bits(w1); | |
380 const uint16_t h3 = Utils::High16Bits(w1); | |
381 | |
382 movz0->SetInstructionBits((movz0_bits & ~kImm16Mask) | (h0 << kImm16Shift)); | |
383 movk1->SetInstructionBits((movk1_bits & ~kImm16Mask) | (h1 << kImm16Shift)); | |
384 movk2->SetInstructionBits((movk2_bits & ~kImm16Mask) | (h2 << kImm16Shift)); | |
385 movk3->SetInstructionBits((movk3_bits & ~kImm16Mask) | (h3 << kImm16Shift)); | |
386 CPU::FlushICache(pc_, 4 * Instr::kInstrSize); | |
387 } | |
388 | |
389 | |
390 ReturnPattern::ReturnPattern(uword pc) | 332 ReturnPattern::ReturnPattern(uword pc) |
391 : pc_(pc) { | 333 : pc_(pc) { |
392 } | 334 } |
393 | 335 |
394 | 336 |
395 bool ReturnPattern::IsValid() const { | 337 bool ReturnPattern::IsValid() const { |
396 Instr* bx_lr = Instr::At(pc_); | 338 Instr* bx_lr = Instr::At(pc_); |
397 const Register crn = ConcreteRegister(LR); | 339 const Register crn = ConcreteRegister(LR); |
398 const int32_t instruction = RET | (static_cast<int32_t>(crn) << kRnShift); | 340 const int32_t instruction = RET | (static_cast<int32_t>(crn) << kRnShift); |
399 return bx_lr->InstructionBits() == instruction; | 341 return bx_lr->InstructionBits() == instruction; |
400 } | 342 } |
401 | 343 |
402 } // namespace dart | 344 } // namespace dart |
403 | 345 |
404 #endif // defined TARGET_ARCH_ARM64 | 346 #endif // defined TARGET_ARCH_ARM64 |
OLD | NEW |