| 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_IA32. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32. |
| 6 #if defined(TARGET_ARCH_IA32) | 6 #if defined(TARGET_ARCH_IA32) |
| 7 | 7 |
| 8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
| 9 #include "vm/code_patcher.h" | 9 #include "vm/code_patcher.h" |
| 10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 86 |
| 87 RawObject* ic_data() const { return immediate_one(); } | 87 RawObject* ic_data() const { return immediate_one(); } |
| 88 RawObject* arguments_descriptor() const { return immediate_two(); } | 88 RawObject* arguments_descriptor() const { return immediate_two(); } |
| 89 | 89 |
| 90 private: | 90 private: |
| 91 DISALLOW_IMPLICIT_CONSTRUCTORS(InstanceCall); | 91 DISALLOW_IMPLICIT_CONSTRUCTORS(InstanceCall); |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 | 94 |
| 95 // The expected pattern of a dart static call: | 95 // The expected pattern of a dart static call: |
| 96 // mov EDX, arguments_descriptor_array | 96 // mov EDX, arguments_descriptor_array (optional in polymorphic calls) |
| 97 // call target_address | 97 // call target_address |
| 98 // <- return address | 98 // <- return address |
| 99 class StaticCall : public ValueObject { | 99 class StaticCall : public ValueObject { |
| 100 public: | 100 public: |
| 101 explicit StaticCall(uword return_address) | 101 explicit StaticCall(uword return_address) |
| 102 : start_(return_address - (kNumInstructions * kInstructionSize)) { | 102 : start_(return_address - (kNumInstructions * kInstructionSize)) { |
| 103 ASSERT(IsValid(return_address)); | 103 ASSERT(IsValid(return_address)); |
| 104 ASSERT(kInstructionSize == Assembler::kCallExternalLabelSize); | 104 ASSERT(kInstructionSize == Assembler::kCallExternalLabelSize); |
| 105 } | 105 } |
| 106 | 106 |
| 107 static bool IsValid(uword return_address) { | 107 static bool IsValid(uword return_address) { |
| 108 uint8_t* code_bytes = | 108 uint8_t* code_bytes = |
| 109 reinterpret_cast<uint8_t*>( | 109 reinterpret_cast<uint8_t*>( |
| 110 return_address - (kNumInstructions * kInstructionSize)); | 110 return_address - (kNumInstructions * kInstructionSize)); |
| 111 return (code_bytes[0] == 0xBA) && | 111 return (code_bytes[0] == 0xE8); |
| 112 (code_bytes[1 * kInstructionSize] == 0xE8); | |
| 113 } | 112 } |
| 114 | 113 |
| 115 uword target() const { | 114 uword target() const { |
| 116 const uword offset = *reinterpret_cast<uword*>(call_address() + 1); | 115 const uword offset = *reinterpret_cast<uword*>(call_address() + 1); |
| 117 return return_address() + offset; | 116 return return_address() + offset; |
| 118 } | 117 } |
| 119 | 118 |
| 120 void set_target(uword target) const { | 119 void set_target(uword target) const { |
| 121 uword* target_addr = reinterpret_cast<uword*>(call_address() + 1); | 120 uword* target_addr = reinterpret_cast<uword*>(call_address() + 1); |
| 122 uword offset = target - return_address(); | 121 uword offset = target - return_address(); |
| 123 *target_addr = offset; | 122 *target_addr = offset; |
| 124 CPU::FlushICache(call_address(), kInstructionSize); | 123 CPU::FlushICache(call_address(), kInstructionSize); |
| 125 } | 124 } |
| 126 | 125 |
| 127 static const int kNumInstructions = 2; | 126 static const int kNumInstructions = 1; |
| 128 static const int kInstructionSize = 5; // All instructions have same length. | 127 static const int kInstructionSize = 5; // All instructions have same length. |
| 129 | 128 |
| 130 private: | 129 private: |
| 131 uword return_address() const { | 130 uword return_address() const { |
| 132 return start_ + kNumInstructions * kInstructionSize; | 131 return start_ + kNumInstructions * kInstructionSize; |
| 133 } | 132 } |
| 134 | 133 |
| 135 uword call_address() const { | 134 uword call_address() const { |
| 136 return start_ + 1 * kInstructionSize; | 135 return start_; |
| 137 } | 136 } |
| 138 | 137 |
| 139 uword start_; | 138 uword start_; |
| 140 | 139 |
| 141 DISALLOW_IMPLICIT_CONSTRUCTORS(StaticCall); | 140 DISALLOW_IMPLICIT_CONSTRUCTORS(StaticCall); |
| 142 }; | 141 }; |
| 143 | 142 |
| 144 | 143 |
| 145 uword CodePatcher::GetStaticCallTargetAt(uword return_address, | 144 uword CodePatcher::GetStaticCallTargetAt(uword return_address, |
| 146 const Code& code) { | 145 const Code& code) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 } | 192 } |
| 194 | 193 |
| 195 | 194 |
| 196 intptr_t CodePatcher::InstanceCallSizeInBytes() { | 195 intptr_t CodePatcher::InstanceCallSizeInBytes() { |
| 197 return DartCallPattern::kNumInstructions * DartCallPattern::kInstructionSize; | 196 return DartCallPattern::kNumInstructions * DartCallPattern::kInstructionSize; |
| 198 } | 197 } |
| 199 | 198 |
| 200 } // namespace dart | 199 } // namespace dart |
| 201 | 200 |
| 202 #endif // defined TARGET_ARCH_IA32 | 201 #endif // defined TARGET_ARCH_IA32 |
| OLD | NEW |