OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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_X64. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. |
6 #if defined(TARGET_ARCH_X64) | 6 #if defined(TARGET_ARCH_X64) |
7 | 7 |
8 #include "vm/cpu.h" | 8 #include "vm/cpu.h" |
9 #include "vm/instructions.h" | 9 #include "vm/instructions.h" |
10 #include "vm/object.h" | 10 #include "vm/object.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 for (int i = 0; i < num_bytes; i++) { | 30 for (int i = 0; i < num_bytes; i++) { |
31 // Skip comparison for data[i] < 0. | 31 // Skip comparison for data[i] < 0. |
32 if ((data[i] >= 0) && (byte_array[i] != (0xFF & data[i]))) { | 32 if ((data[i] >= 0) && (byte_array[i] != (0xFF & data[i]))) { |
33 return false; | 33 return false; |
34 } | 34 } |
35 } | 35 } |
36 return true; | 36 return true; |
37 } | 37 } |
38 | 38 |
39 | 39 |
40 uword CallPattern::TargetAddress() const { | |
41 ASSERT(IsValid()); | |
42 return *reinterpret_cast<uword*>(start() + 2); | |
43 } | |
44 | |
45 | |
46 void CallPattern::SetTargetAddress(uword target) const { | |
47 ASSERT(IsValid()); | |
48 *reinterpret_cast<uword*>(start() + 2) = target; | |
49 CPU::FlushICache(start() + 2, kWordSize); | |
50 } | |
51 | |
52 | |
53 const int* CallPattern::pattern() const { | |
54 // movq $target, TMP | |
55 // callq *TMP | |
56 static const int kCallPattern[kLengthInBytes] = | |
57 {0x49, 0xBB, -1, -1, -1, -1, -1, -1, -1, -1, 0x41, 0xFF, 0xD3}; | |
58 return kCallPattern; | |
59 } | |
60 | |
61 | |
62 uword JumpPattern::TargetAddress() const { | 40 uword JumpPattern::TargetAddress() const { |
63 ASSERT(IsValid()); | 41 ASSERT(IsValid()); |
64 int index = InstructionPattern::IndexFromPPLoad(start() + 3); | 42 int index = InstructionPattern::IndexFromPPLoad(start() + 3); |
65 return reinterpret_cast<uword>(object_pool_.At(index)); | 43 return reinterpret_cast<uword>(object_pool_.At(index)); |
66 } | 44 } |
67 | 45 |
68 | 46 |
69 void JumpPattern::SetTargetAddress(uword target) const { | 47 void JumpPattern::SetTargetAddress(uword target) const { |
70 ASSERT(IsValid()); | 48 ASSERT(IsValid()); |
71 int index = InstructionPattern::IndexFromPPLoad(start() + 3); | 49 int index = InstructionPattern::IndexFromPPLoad(start() + 3); |
72 const Smi& smi = Smi::Handle(reinterpret_cast<RawSmi*>(target)); | 50 const Smi& smi = Smi::Handle(reinterpret_cast<RawSmi*>(target)); |
73 object_pool_.SetAt(index, smi); | 51 object_pool_.SetAt(index, smi); |
74 // No need to flush the instruction cache, since the code is not modified. | 52 // No need to flush the instruction cache, since the code is not modified. |
75 } | 53 } |
76 | 54 |
77 | 55 |
78 const int* JumpPattern::pattern() const { | 56 const int* JumpPattern::pattern() const { |
79 // 00: 4d 8b 9d imm32 mov R11, [R13 + off] | 57 // 07: 41 ff a7 imm32 jmpq [reg + off] |
80 // 07: 41 ff e3 jmpq R11 | |
81 static const int kJumpPattern[kLengthInBytes] = | 58 static const int kJumpPattern[kLengthInBytes] = |
82 {0x4D, 0x8B, -1, -1, -1, -1, -1, 0x41, 0xFF, 0xE3}; | 59 {0x41, 0xFF, -1, -1, -1, -1, -1}; |
83 return kJumpPattern; | 60 return kJumpPattern; |
84 } | 61 } |
85 | 62 |
86 | 63 |
87 void ShortCallPattern::SetTargetAddress(uword target) const { | 64 void ShortCallPattern::SetTargetAddress(uword target) const { |
88 ASSERT(IsValid()); | 65 ASSERT(IsValid()); |
89 *reinterpret_cast<uint32_t*>(start() + 1) = target - start() - kLengthInBytes; | 66 *reinterpret_cast<uint32_t*>(start() + 1) = target - start() - kLengthInBytes; |
90 CPU::FlushICache(start() + 1, kWordSize); | 67 CPU::FlushICache(start() + 1, kWordSize); |
91 } | 68 } |
92 | 69 |
93 | 70 |
94 const int* ShortCallPattern::pattern() const { | 71 const int* ShortCallPattern::pattern() const { |
95 static const int kCallPattern[kLengthInBytes] = {0xE8, -1, -1, -1, -1}; | 72 static const int kCallPattern[kLengthInBytes] = {0xE8, -1, -1, -1, -1}; |
96 return kCallPattern; | 73 return kCallPattern; |
97 } | 74 } |
98 | 75 |
99 } // namespace dart | 76 } // namespace dart |
100 | 77 |
101 #endif // defined TARGET_ARCH_X64 | 78 #endif // defined TARGET_ARCH_X64 |
OLD | NEW |