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" |
11 | 11 |
12 namespace dart { | 12 namespace dart { |
13 | 13 |
14 intptr_t InstructionPattern::IndexFromPPLoad(uword start) { | 14 intptr_t IndexFromPPLoad(uword start) { |
15 int32_t offset = *reinterpret_cast<int32_t*>(start); | 15 int32_t offset = *reinterpret_cast<int32_t*>(start); |
16 return ObjectPool::IndexFromOffset(offset); | 16 return ObjectPool::IndexFromOffset(offset); |
17 } | 17 } |
18 | 18 |
19 | 19 |
20 intptr_t InstructionPattern::OffsetFromPPIndex(intptr_t index) { | |
21 intptr_t offset = ObjectPool::element_offset(index); | |
22 return offset - kHeapObjectTag; | |
23 } | |
24 | |
25 | |
26 bool InstructionPattern::TestBytesWith(const int* data, int num_bytes) const { | |
27 ASSERT(data != NULL); | |
28 const uint8_t* byte_array = reinterpret_cast<const uint8_t*>(start_); | |
29 for (int i = 0; i < num_bytes; i++) { | |
30 // Skip comparison for data[i] < 0. | |
31 if ((data[i] >= 0) && (byte_array[i] != (0xFF & data[i]))) { | |
32 return false; | |
33 } | |
34 } | |
35 return true; | |
36 } | |
37 | |
38 | |
39 uword JumpPattern::TargetAddress() const { | 20 uword JumpPattern::TargetAddress() const { |
40 ASSERT(IsValid()); | 21 ASSERT(IsValid()); |
41 int index = InstructionPattern::IndexFromPPLoad(start() + 3); | 22 int index = IndexFromPPLoad(start() + 3); |
42 return object_pool_.RawValueAt(index); | 23 return object_pool_.RawValueAt(index); |
43 } | 24 } |
44 | 25 |
45 | 26 |
46 void JumpPattern::SetTargetAddress(uword target) const { | 27 void JumpPattern::SetTargetAddress(uword target) const { |
47 ASSERT(IsValid()); | 28 ASSERT(IsValid()); |
48 int index = InstructionPattern::IndexFromPPLoad(start() + 3); | 29 int index = IndexFromPPLoad(start() + 3); |
49 object_pool_.SetRawValueAt(index, target); | 30 object_pool_.SetRawValueAt(index, target); |
50 // No need to flush the instruction cache, since the code is not modified. | 31 // No need to flush the instruction cache, since the code is not modified. |
51 } | 32 } |
52 | 33 |
53 | 34 |
54 const int* JumpPattern::pattern() const { | |
55 // 07: 41 ff a7 imm32 jmpq [reg + off] | |
56 static const int kJumpPattern[kLengthInBytes] = | |
57 {0x41, 0xFF, -1, -1, -1, -1, -1}; | |
58 return kJumpPattern; | |
59 } | |
60 | |
61 | |
62 void ShortCallPattern::SetTargetAddress(uword target) const { | 35 void ShortCallPattern::SetTargetAddress(uword target) const { |
63 ASSERT(IsValid()); | 36 ASSERT(IsValid()); |
64 *reinterpret_cast<uint32_t*>(start() + 1) = target - start() - kLengthInBytes; | 37 *reinterpret_cast<uint32_t*>(start() + 1) = target - start() - kLengthInBytes; |
65 CPU::FlushICache(start() + 1, kWordSize); | 38 CPU::FlushICache(start() + 1, kWordSize); |
66 } | 39 } |
67 | 40 |
68 | 41 |
69 const int* ShortCallPattern::pattern() const { | |
70 static const int kCallPattern[kLengthInBytes] = {0xE8, -1, -1, -1, -1}; | |
71 return kCallPattern; | |
72 } | |
73 | |
74 | |
75 const int* ReturnPattern::pattern() const { | |
76 static const int kReturnPattern[kLengthInBytes] = { 0xC3 }; | |
77 return kReturnPattern; | |
78 } | |
79 | |
80 | |
81 const int* ProloguePattern::pattern() const { | |
82 static const int kProloguePattern[kLengthInBytes] = | |
83 { 0x55, 0x48, 0x89, 0xe5 }; | |
84 return kProloguePattern; | |
85 } | |
86 | |
87 | |
88 const int* SetFramePointerPattern::pattern() const { | |
89 static const int kFramePointerPattern[kLengthInBytes] = { 0x48, 0x89, 0xe5 }; | |
90 return kFramePointerPattern; | |
91 } | |
92 | |
93 } // namespace dart | 42 } // namespace dart |
94 | 43 |
95 #endif // defined TARGET_ARCH_X64 | 44 #endif // defined TARGET_ARCH_X64 |
OLD | NEW |