Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #if V8_TARGET_ARCH_MIPS64 |
| 6 | |
| 7 | #include "src/codegen.h" |
| 8 | #include "src/debug/debug.h" |
| 9 | |
| 10 | namespace v8 { |
| 11 | namespace internal { |
| 12 | |
| 13 | #define __ ACCESS_MASM(masm) |
| 14 | |
| 15 | void EmitDebugBreakSlot(MacroAssembler* masm) { |
| 16 | Label check_size; |
| 17 | __ bind(&check_size); |
| 18 | for (int i = 0; i < Assembler::kDebugBreakSlotInstructions; i++) { |
| 19 | __ nop(MacroAssembler::DEBUG_BREAK_NOP); |
| 20 | } |
| 21 | DCHECK_EQ(Assembler::kDebugBreakSlotInstructions, |
| 22 | masm->InstructionsGeneratedSince(&check_size)); |
| 23 | } |
| 24 | |
| 25 | |
| 26 | void DebugCodegen::GenerateSlot(MacroAssembler* masm, RelocInfo::Mode mode) { |
| 27 | // Generate enough nop's to make space for a call instruction. Avoid emitting |
| 28 | // the trampoline pool in the debug break slot code. |
| 29 | Assembler::BlockTrampolinePoolScope block_pool(masm); |
| 30 | masm->RecordDebugBreakSlot(mode); |
| 31 | EmitDebugBreakSlot(masm); |
| 32 | } |
| 33 | |
| 34 | |
| 35 | void DebugCodegen::ClearDebugBreakSlot(Isolate* isolate, Address pc) { |
| 36 | CodePatcher patcher(isolate, pc, Assembler::kDebugBreakSlotInstructions); |
| 37 | EmitDebugBreakSlot(patcher.masm()); |
| 38 | } |
| 39 | |
| 40 | |
| 41 | void DebugCodegen::PatchDebugBreakSlot(Isolate* isolate, Address pc, |
| 42 | Handle<Code> code) { |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 43 | DCHECK(code->is_debug_stub()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 44 | CodePatcher patcher(isolate, pc, Assembler::kDebugBreakSlotInstructions); |
| 45 | // Patch the code changing the debug break slot code from: |
| 46 | // nop(DEBUG_BREAK_NOP) - nop(1) is sll(zero_reg, zero_reg, 1) |
| 47 | // nop(DEBUG_BREAK_NOP) |
| 48 | // nop(DEBUG_BREAK_NOP) |
| 49 | // nop(DEBUG_BREAK_NOP) |
| 50 | // nop(DEBUG_BREAK_NOP) |
| 51 | // nop(DEBUG_BREAK_NOP) |
| 52 | // to a call to the debug break slot code. |
| 53 | // li t9, address (4-instruction sequence on mips64) |
| 54 | // call t9 (jalr t9 / nop instruction pair) |
| 55 | patcher.masm()->li(v8::internal::t9, |
| 56 | Operand(reinterpret_cast<int64_t>(code->entry())), |
| 57 | ADDRESS_LOAD); |
| 58 | patcher.masm()->Call(v8::internal::t9); |
| 59 | } |
| 60 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 61 | bool DebugCodegen::DebugBreakSlotIsPatched(Address pc) { |
| 62 | Instr current_instr = Assembler::instr_at(pc); |
| 63 | return !Assembler::IsNop(current_instr, Assembler::DEBUG_BREAK_NOP); |
| 64 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 65 | |
| 66 | void DebugCodegen::GenerateDebugBreakStub(MacroAssembler* masm, |
| 67 | DebugBreakCallHelperMode mode) { |
| 68 | __ RecordComment("Debug break"); |
| 69 | { |
| 70 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 71 | |
| 72 | // Load padding words on stack. |
| 73 | __ li(at, Operand(Smi::FromInt(LiveEdit::kFramePaddingValue))); |
| 74 | __ Dsubu(sp, sp, |
| 75 | Operand(kPointerSize * LiveEdit::kFramePaddingInitialSize)); |
| 76 | for (int i = LiveEdit::kFramePaddingInitialSize - 1; i >= 0; i--) { |
| 77 | __ sd(at, MemOperand(sp, kPointerSize * i)); |
| 78 | } |
| 79 | __ li(at, Operand(Smi::FromInt(LiveEdit::kFramePaddingInitialSize))); |
| 80 | __ push(at); |
| 81 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 82 | // Push arguments for DebugBreak call. |
| 83 | if (mode == SAVE_RESULT_REGISTER) { |
| 84 | // Break on return. |
| 85 | __ push(v0); |
| 86 | } else { |
| 87 | // Non-return breaks. |
| 88 | __ Push(masm->isolate()->factory()->the_hole_value()); |
| 89 | } |
| 90 | __ PrepareCEntryArgs(1); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 91 | __ PrepareCEntryFunction(ExternalReference( |
| 92 | Runtime::FunctionForId(Runtime::kDebugBreak), masm->isolate())); |
| 93 | |
| 94 | CEntryStub ceb(masm->isolate(), 1); |
| 95 | __ CallStub(&ceb); |
| 96 | |
| 97 | if (FLAG_debug_code) { |
| 98 | for (int i = 0; i < kNumJSCallerSaved; i++) { |
| 99 | Register reg = {JSCallerSavedCode(i)}; |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 100 | // Do not clobber v0 if mode is SAVE_RESULT_REGISTER. It will |
| 101 | // contain return value of the function returned by DebugBreak. |
| 102 | if (!(reg.is(v0) && (mode == SAVE_RESULT_REGISTER))) { |
| 103 | __ li(reg, kDebugZapValue); |
| 104 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 105 | } |
| 106 | } |
| 107 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 108 | // Don't bother removing padding bytes pushed on the stack |
| 109 | // as the frame is going to be restored right away. |
| 110 | |
| 111 | // Leave the internal frame. |
| 112 | } |
| 113 | |
| 114 | // Now that the break point has been handled, resume normal execution by |
| 115 | // jumping to the target address intended by the caller and that was |
| 116 | // overwritten by the address of DebugBreakXXX. |
| 117 | ExternalReference after_break_target = |
| 118 | ExternalReference::debug_after_break_target_address(masm->isolate()); |
| 119 | __ li(t9, Operand(after_break_target)); |
| 120 | __ ld(t9, MemOperand(t9)); |
| 121 | __ Jump(t9); |
| 122 | } |
| 123 | |
| 124 | |
| 125 | void DebugCodegen::GenerateFrameDropperLiveEdit(MacroAssembler* masm) { |
| 126 | // We do not know our frame height, but set sp based on fp. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 127 | __ ld(a1, MemOperand(fp, FrameDropperFrameConstants::kFunctionOffset)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 128 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 129 | // Pop return address and frame. |
| 130 | __ LeaveFrame(StackFrame::INTERNAL); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 131 | |
| 132 | ParameterCount dummy(0); |
| 133 | __ FloodFunctionIfStepping(a1, no_reg, dummy, dummy); |
| 134 | |
| 135 | // Load context from the function. |
| 136 | __ ld(cp, FieldMemOperand(a1, JSFunction::kContextOffset)); |
| 137 | |
| 138 | // Clear new.target as a safety measure. |
| 139 | __ LoadRoot(a3, Heap::kUndefinedValueRootIndex); |
| 140 | |
| 141 | // Get function code. |
| 142 | __ ld(at, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); |
| 143 | __ ld(at, FieldMemOperand(at, SharedFunctionInfo::kCodeOffset)); |
| 144 | __ Daddu(t9, at, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 145 | |
| 146 | // Re-run JSFunction, a1 is function, cp is context. |
| 147 | __ Jump(t9); |
| 148 | } |
| 149 | |
| 150 | |
| 151 | const bool LiveEdit::kFrameDropperSupported = true; |
| 152 | |
| 153 | #undef __ |
| 154 | |
| 155 | } // namespace internal |
| 156 | } // namespace v8 |
| 157 | |
| 158 | #endif // V8_TARGET_ARCH_MIPS64 |