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