| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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_MIPS) | 6 #if defined(TARGET_ARCH_MIPS) |
| 7 | 7 |
| 8 #include "vm/cpu.h" | 8 #include "vm/cpu.h" |
| 9 #include "vm/debugger.h" | 9 #include "vm/debugger.h" |
| 10 #include "vm/instructions.h" | 10 #include "vm/instructions.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 RawObject* ActivationFrame::GetClosureObject(intptr_t num_actual_args) { | 25 RawObject* ActivationFrame::GetClosureObject(intptr_t num_actual_args) { |
| 26 // At a minimum we have the closure object on the stack. | 26 // At a minimum we have the closure object on the stack. |
| 27 ASSERT(num_actual_args > 0); | 27 ASSERT(num_actual_args > 0); |
| 28 // Stack pointer points to last argument that was pushed on the stack. | 28 // Stack pointer points to last argument that was pushed on the stack. |
| 29 uword closure_addr = sp() + ((num_actual_args - 1) * kWordSize); | 29 uword closure_addr = sp() + ((num_actual_args - 1) * kWordSize); |
| 30 return reinterpret_cast<RawObject*>( | 30 return reinterpret_cast<RawObject*>( |
| 31 *reinterpret_cast<uword*>(closure_addr)); | 31 *reinterpret_cast<uword*>(closure_addr)); |
| 32 } | 32 } |
| 33 | 33 |
| 34 | |
| 35 void CodeBreakpoint::PatchFunctionReturn() { | |
| 36 Instr* instr1 = Instr::At(pc_ - 5 * Instr::kInstrSize); | |
| 37 Instr* instr2 = Instr::At(pc_ - 4 * Instr::kInstrSize); | |
| 38 Instr* instr3 = Instr::At(pc_ - 3 * Instr::kInstrSize); | |
| 39 Instr* instr4 = Instr::At(pc_ - 2 * Instr::kInstrSize); | |
| 40 Instr* instr5 = Instr::At(pc_ - 1 * Instr::kInstrSize); | |
| 41 | |
| 42 #if defined(DEBUG) | |
| 43 instr1->AssertIsImmInstr(LW, SP, RA, 2 * kWordSize); | |
| 44 instr2->AssertIsImmInstr(LW, SP, FP, 1 * kWordSize); | |
| 45 instr3->AssertIsImmInstr(LW, SP, PP, 0 * kWordSize); | |
| 46 instr4->AssertIsSpecialInstr(JR, RA, ZR, ZR); | |
| 47 instr5->AssertIsImmInstr(ADDIU, SP, SP, 4 * kWordSize); | |
| 48 #endif // defined(DEBUG) | |
| 49 | |
| 50 // Smash code with call instruction and target address. | |
| 51 uword stub_addr = StubCode::BreakpointReturnEntryPoint(); | |
| 52 uint16_t target_lo = stub_addr & 0xffff; | |
| 53 uint16_t target_hi = stub_addr >> 16; | |
| 54 | |
| 55 // Unlike other architectures, the sequence we are patching in is shorter | |
| 56 // than the sequence we are replacing. We pad at the top with nops so that | |
| 57 // the end of the new sequence is lined up with the code descriptor. | |
| 58 instr1->SetInstructionBits(Instr::kNopInstruction); | |
| 59 instr2->SetImmInstrBits(LUI, ZR, TMP, target_hi); | |
| 60 instr3->SetImmInstrBits(ORI, TMP, TMP, target_lo); | |
| 61 instr4->SetSpecialInstrBits(JALR, TMP, ZR, RA); | |
| 62 instr5->SetInstructionBits(Instr::kNopInstruction); | |
| 63 | |
| 64 CPU::FlushICache(pc_ - 5 * Instr::kInstrSize, 5 * Instr::kInstrSize); | |
| 65 } | |
| 66 | |
| 67 | |
| 68 void CodeBreakpoint::RestoreFunctionReturn() { | |
| 69 Instr* instr1 = Instr::At(pc_ - 5 * Instr::kInstrSize); | |
| 70 Instr* instr2 = Instr::At(pc_ - 4 * Instr::kInstrSize); | |
| 71 Instr* instr3 = Instr::At(pc_ - 3 * Instr::kInstrSize); | |
| 72 Instr* instr4 = Instr::At(pc_ - 2 * Instr::kInstrSize); | |
| 73 Instr* instr5 = Instr::At(pc_ - 1 * Instr::kInstrSize); | |
| 74 | |
| 75 ASSERT(instr2->OpcodeField() == LUI && instr2->RtField() == TMP); | |
| 76 | |
| 77 instr1->SetImmInstrBits(LW, SP, RA, 2 * kWordSize); | |
| 78 instr2->SetImmInstrBits(LW, SP, FP, 1 * kWordSize); | |
| 79 instr3->SetImmInstrBits(LW, SP, PP, 0 * kWordSize); | |
| 80 instr4->SetSpecialInstrBits(JR, RA, ZR, ZR); | |
| 81 instr5->SetImmInstrBits(ADDIU, SP, SP, 4 * kWordSize); | |
| 82 | |
| 83 CPU::FlushICache(pc_ - 5 * Instr::kInstrSize, 5 * Instr::kInstrSize); | |
| 84 } | |
| 85 | |
| 86 } // namespace dart | 34 } // namespace dart |
| 87 | 35 |
| 88 #endif // defined TARGET_ARCH_MIPS | 36 #endif // defined TARGET_ARCH_MIPS |
| OLD | NEW |