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