| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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" | 5 #include "vm/globals.h" |
| 6 #if defined(TARGET_ARCH_X64) | 6 #if defined(TARGET_ARCH_X64) |
| 7 | 7 |
| 8 #include "vm/debugger.h" | 8 #include "vm/debugger.h" |
| 9 | 9 |
| 10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 RawInstance* ActivationFrame::GetInstanceCallReceiver( | 21 RawInstance* ActivationFrame::GetInstanceCallReceiver( |
| 22 intptr_t num_actual_args) { | 22 intptr_t num_actual_args) { |
| 23 ASSERT(num_actual_args > 0); // At minimum we have a receiver on the stack. | 23 ASSERT(num_actual_args > 0); // At minimum we have a receiver on the stack. |
| 24 // Stack pointer points to last argument that was pushed on the stack. | 24 // Stack pointer points to last argument that was pushed on the stack. |
| 25 uword receiver_addr = sp() + ((num_actual_args - 1) * kWordSize); | 25 uword receiver_addr = sp() + ((num_actual_args - 1) * kWordSize); |
| 26 return reinterpret_cast<RawInstance*>( | 26 return reinterpret_cast<RawInstance*>( |
| 27 *reinterpret_cast<uword*>(receiver_addr)); | 27 *reinterpret_cast<uword*>(receiver_addr)); |
| 28 } | 28 } |
| 29 | 29 |
| 30 | 30 |
| 31 void Breakpoint::PatchFunctionReturn() { | 31 void CodeBreakpoint::PatchFunctionReturn() { |
| 32 uint8_t* code = reinterpret_cast<uint8_t*>(pc_ - 13); | 32 uint8_t* code = reinterpret_cast<uint8_t*>(pc_ - 13); |
| 33 // movq %rbp,%rsp | 33 // movq %rbp,%rsp |
| 34 ASSERT((code[0] == 0x48) && (code[1] == 0x8b) && (code[2] == 0xe5)); | 34 ASSERT((code[0] == 0x48) && (code[1] == 0x8b) && (code[2] == 0xe5)); |
| 35 ASSERT(code[3] == 0x5d); // popq %rbp | 35 ASSERT(code[3] == 0x5d); // popq %rbp |
| 36 ASSERT(code[4] == 0xc3); // ret | 36 ASSERT(code[4] == 0xc3); // ret |
| 37 // Next 8 bytes are nop instructions | 37 // Next 8 bytes are nop instructions |
| 38 ASSERT((code[5] == 0x90) && (code[6] == 0x90) && | 38 ASSERT((code[5] == 0x90) && (code[6] == 0x90) && |
| 39 (code[7] == 0x90) && (code[8] == 0x90) && | 39 (code[7] == 0x90) && (code[8] == 0x90) && |
| 40 (code[9] == 0x90) && (code[10] == 0x90) && | 40 (code[9] == 0x90) && (code[10] == 0x90) && |
| 41 (code[11] == 0x90) && (code[12] == 0x90)); | 41 (code[11] == 0x90) && (code[12] == 0x90)); |
| 42 // Smash code with call instruction and relative target address. | 42 // Smash code with call instruction and relative target address. |
| 43 uword stub_addr = StubCode::BreakpointReturnEntryPoint(); | 43 uword stub_addr = StubCode::BreakpointReturnEntryPoint(); |
| 44 code[0] = 0x49; | 44 code[0] = 0x49; |
| 45 code[1] = 0xbb; | 45 code[1] = 0xbb; |
| 46 *reinterpret_cast<uword*>(&code[2]) = stub_addr; | 46 *reinterpret_cast<uword*>(&code[2]) = stub_addr; |
| 47 code[10] = 0x41; | 47 code[10] = 0x41; |
| 48 code[11] = 0xff; | 48 code[11] = 0xff; |
| 49 code[12] = 0xd3; | 49 code[12] = 0xd3; |
| 50 CPU::FlushICache(pc_, 5); | 50 CPU::FlushICache(pc_, 5); |
| 51 } | 51 } |
| 52 | 52 |
| 53 | 53 |
| 54 void Breakpoint::RestoreFunctionReturn() { | 54 void CodeBreakpoint::RestoreFunctionReturn() { |
| 55 uint8_t* code = reinterpret_cast<uint8_t*>(pc_ - 13); | 55 uint8_t* code = reinterpret_cast<uint8_t*>(pc_ - 13); |
| 56 ASSERT((code[0] == 0x49) && (code[1] == 0xbb)); | 56 ASSERT((code[0] == 0x49) && (code[1] == 0xbb)); |
| 57 code[0] = 0x48; // movq %rbp,%rsp | 57 code[0] = 0x48; // movq %rbp,%rsp |
| 58 code[1] = 0x8b; | 58 code[1] = 0x8b; |
| 59 code[2] = 0xe5; | 59 code[2] = 0xe5; |
| 60 code[3] = 0x5d; // popq %rbp | 60 code[3] = 0x5d; // popq %rbp |
| 61 code[4] = 0xc3; // ret | 61 code[4] = 0xc3; // ret |
| 62 code[5] = 0x90; // nop | 62 code[5] = 0x90; // nop |
| 63 code[6] = 0x90; // nop | 63 code[6] = 0x90; // nop |
| 64 code[7] = 0x90; // nop | 64 code[7] = 0x90; // nop |
| 65 code[8] = 0x90; // nop | 65 code[8] = 0x90; // nop |
| 66 code[9] = 0x90; // nop | 66 code[9] = 0x90; // nop |
| 67 code[10] = 0x90; // nop | 67 code[10] = 0x90; // nop |
| 68 code[11] = 0x90; // nop | 68 code[11] = 0x90; // nop |
| 69 code[12] = 0x90; // nop | 69 code[12] = 0x90; // nop |
| 70 CPU::FlushICache(pc_, 5); | 70 CPU::FlushICache(pc_, 5); |
| 71 } | 71 } |
| 72 | 72 |
| 73 } // namespace dart | 73 } // namespace dart |
| 74 | 74 |
| 75 #endif // defined TARGET_ARCH_X64 | 75 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |