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_MIPS
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
EmitDebugBreakSlot(MacroAssembler * masm)16 void 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
GenerateSlot(MacroAssembler * masm,RelocInfo::Mode mode)27 void 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
ClearDebugBreakSlot(Isolate * isolate,Address pc)36 void DebugCodegen::ClearDebugBreakSlot(Isolate* isolate, Address pc) {
37 CodePatcher patcher(isolate, pc, Assembler::kDebugBreakSlotInstructions);
38 EmitDebugBreakSlot(patcher.masm());
39 }
40
41
PatchDebugBreakSlot(Isolate * isolate,Address pc,Handle<Code> code)42 void 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
59
GenerateDebugBreakStub(MacroAssembler * masm,DebugBreakCallHelperMode mode)60 void DebugCodegen::GenerateDebugBreakStub(MacroAssembler* masm,
61 DebugBreakCallHelperMode mode) {
62 __ RecordComment("Debug break");
63 {
64 FrameScope scope(masm, StackFrame::INTERNAL);
65
66 // Load padding words on stack.
67 __ li(at, Operand(Smi::FromInt(LiveEdit::kFramePaddingValue)));
68 __ Subu(sp, sp,
69 Operand(kPointerSize * LiveEdit::kFramePaddingInitialSize));
70 for (int i = LiveEdit::kFramePaddingInitialSize - 1; i >= 0; i--) {
71 __ sw(at, MemOperand(sp, kPointerSize * i));
72 }
73 __ li(at, Operand(Smi::FromInt(LiveEdit::kFramePaddingInitialSize)));
74 __ push(at);
75
76 if (mode == SAVE_RESULT_REGISTER) __ push(v0);
77
78 __ PrepareCEntryArgs(0); // No arguments.
79 __ PrepareCEntryFunction(ExternalReference(
80 Runtime::FunctionForId(Runtime::kDebugBreak), masm->isolate()));
81
82 CEntryStub ceb(masm->isolate(), 1);
83 __ CallStub(&ceb);
84
85 if (FLAG_debug_code) {
86 for (int i = 0; i < kNumJSCallerSaved; i++) {
87 Register reg = {JSCallerSavedCode(i)};
88 __ li(reg, kDebugZapValue);
89 }
90 }
91
92 if (mode == SAVE_RESULT_REGISTER) __ pop(v0);
93
94 // Don't bother removing padding bytes pushed on the stack
95 // as the frame is going to be restored right away.
96
97 // Leave the internal frame.
98 }
99
100 // Now that the break point has been handled, resume normal execution by
101 // jumping to the target address intended by the caller and that was
102 // overwritten by the address of DebugBreakXXX.
103 ExternalReference after_break_target =
104 ExternalReference::debug_after_break_target_address(masm->isolate());
105 __ li(t9, Operand(after_break_target));
106 __ lw(t9, MemOperand(t9));
107 __ Jump(t9);
108 }
109
110
GenerateFrameDropperLiveEdit(MacroAssembler * masm)111 void DebugCodegen::GenerateFrameDropperLiveEdit(MacroAssembler* masm) {
112 // We do not know our frame height, but set sp based on fp.
113 __ Subu(sp, fp, Operand(kPointerSize));
114
115 __ Pop(ra, fp, a1); // Return address, Frame, Function.
116
117 ParameterCount dummy(0);
118 __ FloodFunctionIfStepping(a1, no_reg, dummy, dummy);
119
120 // Load context from the function.
121 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
122
123 // Clear new.target as a safety measure.
124 __ LoadRoot(a3, Heap::kUndefinedValueRootIndex);
125
126 // Get function code.
127 __ lw(at, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
128 __ lw(at, FieldMemOperand(at, SharedFunctionInfo::kCodeOffset));
129 __ Addu(t9, at, Operand(Code::kHeaderSize - kHeapObjectTag));
130
131 // Re-run JSFunction, a1 is function, cp is context.
132 __ Jump(t9);
133 }
134
135
136 const bool LiveEdit::kFrameDropperSupported = true;
137
138 #undef __
139
140 } // namespace internal
141 } // namespace v8
142
143 #endif // V8_TARGET_ARCH_MIPS
144