| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 uword call_address() const { | 135 uword call_address() const { |
| 136 return start_ + 1 * kInstructionSize; | 136 return start_ + 1 * kInstructionSize; |
| 137 } | 137 } |
| 138 | 138 |
| 139 uword start_; | 139 uword start_; |
| 140 | 140 |
| 141 DISALLOW_IMPLICIT_CONSTRUCTORS(StaticCall); | 141 DISALLOW_IMPLICIT_CONSTRUCTORS(StaticCall); |
| 142 }; | 142 }; |
| 143 | 143 |
| 144 | 144 |
| 145 uword CodePatcher::GetStaticCallTargetAt(uword return_address) { | 145 uword CodePatcher::GetStaticCallTargetAt(uword return_address, |
| 146 const Code& code) { |
| 147 ASSERT(code.ContainsInstructionAt(return_address)); |
| 146 StaticCall call(return_address); | 148 StaticCall call(return_address); |
| 147 return call.target(); | 149 return call.target(); |
| 148 } | 150 } |
| 149 | 151 |
| 150 | 152 |
| 151 void CodePatcher::PatchStaticCallAt(uword return_address, uword new_target) { | 153 void CodePatcher::PatchStaticCallAt(uword return_address, |
| 154 const Code& code, |
| 155 uword new_target) { |
| 156 ASSERT(code.ContainsInstructionAt(return_address)); |
| 152 StaticCall call(return_address); | 157 StaticCall call(return_address); |
| 153 call.set_target(new_target); | 158 call.set_target(new_target); |
| 154 } | 159 } |
| 155 | 160 |
| 156 | 161 |
| 157 void CodePatcher::PatchInstanceCallAt(uword return_address, uword new_target) { | 162 void CodePatcher::PatchInstanceCallAt(uword return_address, |
| 163 const Code& code, |
| 164 uword new_target) { |
| 165 ASSERT(code.ContainsInstructionAt(return_address)); |
| 158 InstanceCall call(return_address); | 166 InstanceCall call(return_address); |
| 159 call.set_target(new_target); | 167 call.set_target(new_target); |
| 160 } | 168 } |
| 161 | 169 |
| 162 | 170 |
| 163 | 171 |
| 164 void CodePatcher::InsertCallAt(uword start, uword target) { | 172 void CodePatcher::InsertCallAt(uword start, uword target) { |
| 165 *reinterpret_cast<uint8_t*>(start) = 0xE8; | 173 *reinterpret_cast<uint8_t*>(start) = 0xE8; |
| 166 CallPattern call(start); | 174 CallPattern call(start); |
| 167 call.SetTargetAddress(target); | 175 call.SetTargetAddress(target); |
| 168 CPU::FlushICache(start, CallPattern::InstructionLength()); | 176 CPU::FlushICache(start, CallPattern::InstructionLength()); |
| 169 } | 177 } |
| 170 | 178 |
| 171 | 179 |
| 172 bool CodePatcher::IsDartCall(uword return_address) { | |
| 173 return DartCallPattern::IsValid(return_address); | |
| 174 } | |
| 175 | |
| 176 | |
| 177 uword CodePatcher::GetInstanceCallAt(uword return_address, | 180 uword CodePatcher::GetInstanceCallAt(uword return_address, |
| 181 const Code& code, |
| 178 ICData* ic_data, | 182 ICData* ic_data, |
| 179 Array* arguments_descriptor) { | 183 Array* arguments_descriptor) { |
| 184 ASSERT(code.ContainsInstructionAt(return_address)); |
| 180 InstanceCall call(return_address); | 185 InstanceCall call(return_address); |
| 181 if (ic_data != NULL) { | 186 if (ic_data != NULL) { |
| 182 *ic_data ^= call.ic_data(); | 187 *ic_data ^= call.ic_data(); |
| 183 } | 188 } |
| 184 if (arguments_descriptor != NULL) { | 189 if (arguments_descriptor != NULL) { |
| 185 *arguments_descriptor ^= call.arguments_descriptor(); | 190 *arguments_descriptor ^= call.arguments_descriptor(); |
| 186 } | 191 } |
| 187 return call.target(); | 192 return call.target(); |
| 188 } | 193 } |
| 189 | 194 |
| 190 | 195 |
| 191 intptr_t CodePatcher::InstanceCallSizeInBytes() { | 196 intptr_t CodePatcher::InstanceCallSizeInBytes() { |
| 192 return DartCallPattern::kNumInstructions * DartCallPattern::kInstructionSize; | 197 return DartCallPattern::kNumInstructions * DartCallPattern::kInstructionSize; |
| 193 } | 198 } |
| 194 | 199 |
| 195 } // namespace dart | 200 } // namespace dart |
| 196 | 201 |
| 197 #endif // defined TARGET_ARCH_IA32 | 202 #endif // defined TARGET_ARCH_IA32 |
| OLD | NEW |