blob: 1d9f7d603705700adc7821a44d14c93471b497db [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) {
44 DCHECK_EQ(Code::BUILTIN, code->kind());
45 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
80 if (mode == SAVE_RESULT_REGISTER) __ push(v0);
81
82 __ PrepareCEntryArgs(0); // No arguments.
83 __ PrepareCEntryFunction(ExternalReference(
84 Runtime::FunctionForId(Runtime::kDebugBreak), masm->isolate()));
85
86 CEntryStub ceb(masm->isolate(), 1);
87 __ CallStub(&ceb);
88
89 if (FLAG_debug_code) {
90 for (int i = 0; i < kNumJSCallerSaved; i++) {
91 Register reg = {JSCallerSavedCode(i)};
92 __ li(reg, kDebugZapValue);
93 }
94 }
95
96 if (mode == SAVE_RESULT_REGISTER) __ pop(v0);
97
98 // Don't bother removing padding bytes pushed on the stack
99 // as the frame is going to be restored right away.
100
101 // Leave the internal frame.
102 }
103
104 // Now that the break point has been handled, resume normal execution by
105 // jumping to the target address intended by the caller and that was
106 // overwritten by the address of DebugBreakXXX.
107 ExternalReference after_break_target =
108 ExternalReference::debug_after_break_target_address(masm->isolate());
109 __ li(t9, Operand(after_break_target));
110 __ lw(t9, MemOperand(t9));
111 __ Jump(t9);
112}
113
114
115void DebugCodegen::GenerateFrameDropperLiveEdit(MacroAssembler* masm) {
116 // We do not know our frame height, but set sp based on fp.
117 __ Subu(sp, fp, Operand(kPointerSize));
118
119 __ Pop(ra, fp, a1); // Return address, Frame, Function.
120
121 ParameterCount dummy(0);
122 __ FloodFunctionIfStepping(a1, no_reg, dummy, dummy);
123
124 // Load context from the function.
125 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
126
127 // Clear new.target as a safety measure.
128 __ LoadRoot(a3, Heap::kUndefinedValueRootIndex);
129
130 // Get function code.
131 __ lw(at, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
132 __ lw(at, FieldMemOperand(at, SharedFunctionInfo::kCodeOffset));
133 __ Addu(t9, at, Operand(Code::kHeaderSize - kHeapObjectTag));
134
135 // Re-run JSFunction, a1 is function, cp is context.
136 __ Jump(t9);
137}
138
139
140const bool LiveEdit::kFrameDropperSupported = true;
141
142#undef __
143
144} // namespace internal
145} // namespace v8
146
147#endif // V8_TARGET_ARCH_MIPS