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