blob: 2e967d7b8e09f8b66a244b1eea342eb2a54edae6 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// 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
10namespace v8 {
11namespace internal {
12
13#define __ ACCESS_MASM(masm)
14
15void 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
26void 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
35void DebugCodegen::ClearDebugBreakSlot(Isolate* isolate, Address pc) {
36 CodePatcher patcher(isolate, pc, Assembler::kDebugBreakSlotInstructions);
37 EmitDebugBreakSlot(patcher.masm());
38}
39
40
41void DebugCodegen::PatchDebugBreakSlot(Isolate* isolate, Address pc,
42 Handle<Code> code) {
Ben Murdoch61f157c2016-09-16 13:49:30 +010043 DCHECK(code->is_debug_stub());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000044 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 Murdoch097c5b22016-05-18 11:27:45 +010061bool DebugCodegen::DebugBreakSlotIsPatched(Address pc) {
62 Instr current_instr = Assembler::instr_at(pc);
63 return !Assembler::IsNop(current_instr, Assembler::DEBUG_BREAK_NOP);
64}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000065
66void 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 Murdochda12d292016-06-02 14:46:10 +010082 // 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 Murdoch4a90d5f2016-03-22 12:00:34 +000091 __ 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 Murdochda12d292016-06-02 14:46:10 +0100100 // 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 Murdoch4a90d5f2016-03-22 12:00:34 +0000105 }
106 }
107
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000108 // 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
125void DebugCodegen::GenerateFrameDropperLiveEdit(MacroAssembler* masm) {
126 // We do not know our frame height, but set sp based on fp.
Ben Murdochda12d292016-06-02 14:46:10 +0100127 __ ld(a1, MemOperand(fp, FrameDropperFrameConstants::kFunctionOffset));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000128
Ben Murdochda12d292016-06-02 14:46:10 +0100129 // Pop return address and frame.
130 __ LeaveFrame(StackFrame::INTERNAL);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000131
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
151const bool LiveEdit::kFrameDropperSupported = true;
152
153#undef __
154
155} // namespace internal
156} // namespace v8
157
158#endif // V8_TARGET_ARCH_MIPS64