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