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_ARM) | 6 #if defined(TARGET_ARCH_ARM) |
7 | 7 |
| 8 #include "vm/cpu.h" |
8 #include "vm/debugger.h" | 9 #include "vm/debugger.h" |
| 10 #include "vm/instructions.h" |
| 11 #include "vm/stub_code.h" |
9 | 12 |
10 namespace dart { | 13 namespace dart { |
11 | 14 |
| 15 // TODO(hausner): Handle captured variables. |
12 RawInstance* ActivationFrame::GetLocalVarValue(intptr_t slot_index) { | 16 RawInstance* ActivationFrame::GetLocalVarValue(intptr_t slot_index) { |
13 UNIMPLEMENTED(); | 17 uword var_address = fp() + slot_index * kWordSize; |
14 return NULL; | 18 return reinterpret_cast<RawInstance*>( |
| 19 *reinterpret_cast<uword*>(var_address)); |
15 } | 20 } |
16 | 21 |
17 | 22 |
18 RawInstance* ActivationFrame::GetInstanceCallReceiver( | 23 RawInstance* ActivationFrame::GetInstanceCallReceiver( |
19 intptr_t num_actual_args) { | 24 intptr_t num_actual_args) { |
20 UNIMPLEMENTED(); | 25 ASSERT(num_actual_args > 0); // At minimum we have a receiver on the stack. |
21 return NULL; | 26 // Stack pointer points to last argument that was pushed on the stack. |
| 27 uword receiver_addr = sp() + ((num_actual_args - 1) * kWordSize); |
| 28 return reinterpret_cast<RawInstance*>( |
| 29 *reinterpret_cast<uword*>(receiver_addr)); |
22 } | 30 } |
23 | 31 |
24 | 32 |
25 void CodeBreakpoint::PatchFunctionReturn() { | 33 void CodeBreakpoint::PatchFunctionReturn() { |
26 UNIMPLEMENTED(); | 34 uword* code = reinterpret_cast<uword*>(pc_ - 3 * Instr::kInstrSize); |
| 35 ASSERT(code[0] == 0xe8bd4c00); // ldmia sp!, {pp, fp, lr} |
| 36 ASSERT(code[1] == 0xe28dd004); // add sp, sp, #4 |
| 37 ASSERT(code[2] == 0xe12fff1e); // bx lr |
| 38 |
| 39 // Smash code with call instruction and target address. |
| 40 uword stub_addr = StubCode::BreakpointReturnEntryPoint(); |
| 41 uint16_t target_lo = stub_addr & 0xffff; |
| 42 uint16_t target_hi = stub_addr >> 16; |
| 43 uword movw = 0xe300c000 | ((target_lo >> 12) << 16) | (target_lo & 0xfff); |
| 44 uword movt = 0xe340c000 | ((target_hi >> 12) << 16) | (target_hi & 0xfff); |
| 45 uword blx = 0xe12fff3c; |
| 46 code[0] = movw; // movw ip, #target_lo |
| 47 code[1] = movt; // movt ip, #target_hi |
| 48 code[2] = blx; // blx ip |
| 49 CPU::FlushICache(pc_ - 3 * Instr::kInstrSize, 3 * Instr::kInstrSize); |
27 } | 50 } |
28 | 51 |
29 | 52 |
30 void CodeBreakpoint::RestoreFunctionReturn() { | 53 void CodeBreakpoint::RestoreFunctionReturn() { |
31 UNIMPLEMENTED(); | 54 uword* code = reinterpret_cast<uword*>(pc_ - 3 * Instr::kInstrSize); |
| 55 ASSERT((code[0] & 0xfff0f000) == 0xe300c000); |
| 56 code[0] = 0xe8bd4c00; // ldmia sp!, {pp, fp, lr} |
| 57 code[1] = 0xe28dd004; // add sp, sp, #4 |
| 58 code[2] = 0xe12fff1e; // bx lr |
| 59 CPU::FlushICache(pc_ - 3 * Instr::kInstrSize, 3 * Instr::kInstrSize); |
32 } | 60 } |
33 | 61 |
34 } // namespace dart | 62 } // namespace dart |
35 | 63 |
36 #endif // defined TARGET_ARCH_ARM | 64 #endif // defined TARGET_ARCH_ARM |
OLD | NEW |