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.
9 #if V8_TARGET_ARCH_MIPS
17 bool BreakLocationIterator::IsDebugBreakAtReturn() {
18 return Debug::IsDebugBreakAtReturn(rinfo());
22 void BreakLocationIterator::SetDebugBreakAtReturn() {
23 // Mips return sequence:
30 // nop (in branch delay slot)
32 // Make sure this constant matches the number if instrucntions we emit.
33 ASSERT(Assembler::kJSReturnSequenceInstructions == 7);
34 CodePatcher patcher(rinfo()->pc(), Assembler::kJSReturnSequenceInstructions);
35 // li and Call pseudo-instructions emit two instructions each.
36 patcher.masm()->li(v8::internal::t9, Operand(reinterpret_cast<int32_t>(
37 debug_info_->GetIsolate()->builtins()->Return_DebugBreak()->entry())));
38 patcher.masm()->Call(v8::internal::t9);
39 patcher.masm()->nop();
40 patcher.masm()->nop();
41 patcher.masm()->nop();
43 // TODO(mips): Open issue about using breakpoint instruction instead of nops.
44 // patcher.masm()->bkpt(0);
48 // Restore the JS frame exit code.
49 void BreakLocationIterator::ClearDebugBreakAtReturn() {
50 rinfo()->PatchCode(original_rinfo()->pc(),
51 Assembler::kJSReturnSequenceInstructions);
55 // A debug break in the exit code is identified by the JS frame exit code
56 // having been patched with li/call psuedo-instrunction (liu/ori/jalr).
57 bool Debug::IsDebugBreakAtReturn(RelocInfo* rinfo) {
58 ASSERT(RelocInfo::IsJSReturn(rinfo->rmode()));
59 return rinfo->IsPatchedReturnSequence();
63 bool BreakLocationIterator::IsDebugBreakAtSlot() {
64 ASSERT(IsDebugBreakSlot());
65 // Check whether the debug break slot instructions have been patched.
66 return rinfo()->IsPatchedDebugBreakSlotSequence();
70 void BreakLocationIterator::SetDebugBreakAtSlot() {
71 ASSERT(IsDebugBreakSlot());
72 // Patch the code changing the debug break slot code from:
73 // nop(DEBUG_BREAK_NOP) - nop(1) is sll(zero_reg, zero_reg, 1)
74 // nop(DEBUG_BREAK_NOP)
75 // nop(DEBUG_BREAK_NOP)
76 // nop(DEBUG_BREAK_NOP)
77 // to a call to the debug break slot code.
78 // li t9, address (lui t9 / ori t9 instruction pair)
79 // call t9 (jalr t9 / nop instruction pair)
80 CodePatcher patcher(rinfo()->pc(), Assembler::kDebugBreakSlotInstructions);
81 patcher.masm()->li(v8::internal::t9, Operand(reinterpret_cast<int32_t>(
82 debug_info_->GetIsolate()->builtins()->Slot_DebugBreak()->entry())));
83 patcher.masm()->Call(v8::internal::t9);
87 void BreakLocationIterator::ClearDebugBreakAtSlot() {
88 ASSERT(IsDebugBreakSlot());
89 rinfo()->PatchCode(original_rinfo()->pc(),
90 Assembler::kDebugBreakSlotInstructions);
93 const bool Debug::FramePaddingLayout::kIsSupported = false;
96 #define __ ACCESS_MASM(masm)
100 static void Generate_DebugBreakCallHelper(MacroAssembler* masm,
102 RegList non_object_regs) {
104 FrameScope scope(masm, StackFrame::INTERNAL);
106 // Store the registers containing live values on the expression stack to
107 // make sure that these are correctly updated during GC. Non object values
108 // are stored as a smi causing it to be untouched by GC.
109 ASSERT((object_regs & ~kJSCallerSaved) == 0);
110 ASSERT((non_object_regs & ~kJSCallerSaved) == 0);
111 ASSERT((object_regs & non_object_regs) == 0);
112 if ((object_regs | non_object_regs) != 0) {
113 for (int i = 0; i < kNumJSCallerSaved; i++) {
114 int r = JSCallerSavedCode(i);
115 Register reg = { r };
116 if ((non_object_regs & (1 << r)) != 0) {
117 if (FLAG_debug_code) {
118 __ And(at, reg, 0xc0000000);
119 __ Assert(eq, kUnableToEncodeValueAsSmi, at, Operand(zero_reg));
121 __ sll(reg, reg, kSmiTagSize);
124 __ MultiPush(object_regs | non_object_regs);
128 __ RecordComment("// Calling from debug break to runtime - come in - over");
130 __ PrepareCEntryArgs(0); // No arguments.
131 __ PrepareCEntryFunction(ExternalReference::debug_break(masm->isolate()));
133 CEntryStub ceb(masm->isolate(), 1);
136 // Restore the register values from the expression stack.
137 if ((object_regs | non_object_regs) != 0) {
138 __ MultiPop(object_regs | non_object_regs);
139 for (int i = 0; i < kNumJSCallerSaved; i++) {
140 int r = JSCallerSavedCode(i);
141 Register reg = { r };
142 if ((non_object_regs & (1 << r)) != 0) {
143 __ srl(reg, reg, kSmiTagSize);
145 if (FLAG_debug_code &&
146 (((object_regs |non_object_regs) & (1 << r)) == 0)) {
147 __ li(reg, kDebugZapValue);
152 // Leave the internal frame.
155 // Now that the break point has been handled, resume normal execution by
156 // jumping to the target address intended by the caller and that was
157 // overwritten by the address of DebugBreakXXX.
159 ExternalReference(Debug_Address::AfterBreakTarget(), masm->isolate())));
160 __ lw(t9, MemOperand(t9));
165 void Debug::GenerateCallICStubDebugBreak(MacroAssembler* masm) {
166 // Register state for CallICStub
167 // ----------- S t a t e -------------
169 // -- a3 : slot in feedback array (smi)
170 // -----------------------------------
171 Generate_DebugBreakCallHelper(masm, a1.bit() | a3.bit(), 0);
175 void Debug::GenerateLoadICDebugBreak(MacroAssembler* masm) {
176 // Calling convention for IC load (from ic-mips.cc).
177 // ----------- S t a t e -------------
179 // -- ra : return address
181 // -- [sp] : receiver
182 // -----------------------------------
183 // Registers a0 and a2 contain objects that need to be pushed on the
184 // expression stack of the fake JS frame.
185 Generate_DebugBreakCallHelper(masm, a0.bit() | a2.bit(), 0);
189 void Debug::GenerateStoreICDebugBreak(MacroAssembler* masm) {
190 // Calling convention for IC store (from ic-mips.cc).
191 // ----------- S t a t e -------------
195 // -- ra : return address
196 // -----------------------------------
197 // Registers a0, a1, and a2 contain objects that need to be pushed on the
198 // expression stack of the fake JS frame.
199 Generate_DebugBreakCallHelper(masm, a0.bit() | a1.bit() | a2.bit(), 0);
203 void Debug::GenerateKeyedLoadICDebugBreak(MacroAssembler* masm) {
204 // ---------- S t a t e --------------
205 // -- ra : return address
208 Generate_DebugBreakCallHelper(masm, a0.bit() | a1.bit(), 0);
212 void Debug::GenerateKeyedStoreICDebugBreak(MacroAssembler* masm) {
213 // ---------- S t a t e --------------
217 // -- ra : return address
218 Generate_DebugBreakCallHelper(masm, a0.bit() | a1.bit() | a2.bit(), 0);
222 void Debug::GenerateCompareNilICDebugBreak(MacroAssembler* masm) {
223 // Register state for CompareNil IC
224 // ----------- S t a t e -------------
226 // -----------------------------------
227 Generate_DebugBreakCallHelper(masm, a0.bit(), 0);
231 void Debug::GenerateReturnDebugBreak(MacroAssembler* masm) {
232 // In places other than IC call sites it is expected that v0 is TOS which
233 // is an object - this is not generally the case so this should be used with
235 Generate_DebugBreakCallHelper(masm, v0.bit(), 0);
239 void Debug::GenerateCallFunctionStubDebugBreak(MacroAssembler* masm) {
240 // Register state for CallFunctionStub (from code-stubs-mips.cc).
241 // ----------- S t a t e -------------
243 // -----------------------------------
244 Generate_DebugBreakCallHelper(masm, a1.bit(), 0);
248 void Debug::GenerateCallConstructStubDebugBreak(MacroAssembler* masm) {
249 // Calling convention for CallConstructStub (from code-stubs-mips.cc).
250 // ----------- S t a t e -------------
251 // -- a0 : number of arguments (not smi)
252 // -- a1 : constructor function
253 // -----------------------------------
254 Generate_DebugBreakCallHelper(masm, a1.bit() , a0.bit());
258 void Debug::GenerateCallConstructStubRecordDebugBreak(MacroAssembler* masm) {
259 // Calling convention for CallConstructStub (from code-stubs-mips.cc).
260 // ----------- S t a t e -------------
261 // -- a0 : number of arguments (not smi)
262 // -- a1 : constructor function
263 // -- a2 : feedback array
264 // -- a3 : feedback slot (smi)
265 // -----------------------------------
266 Generate_DebugBreakCallHelper(masm, a1.bit() | a2.bit() | a3.bit(), a0.bit());
270 void Debug::GenerateSlot(MacroAssembler* masm) {
271 // Generate enough nop's to make space for a call instruction. Avoid emitting
272 // the trampoline pool in the debug break slot code.
273 Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm);
274 Label check_codesize;
275 __ bind(&check_codesize);
276 __ RecordDebugBreakSlot();
277 for (int i = 0; i < Assembler::kDebugBreakSlotInstructions; i++) {
278 __ nop(MacroAssembler::DEBUG_BREAK_NOP);
280 ASSERT_EQ(Assembler::kDebugBreakSlotInstructions,
281 masm->InstructionsGeneratedSince(&check_codesize));
285 void Debug::GenerateSlotDebugBreak(MacroAssembler* masm) {
286 // In the places where a debug break slot is inserted no registers can contain
288 Generate_DebugBreakCallHelper(masm, 0, 0);
292 void Debug::GeneratePlainReturnLiveEdit(MacroAssembler* masm) {
293 masm->Abort(kLiveEditFrameDroppingIsNotSupportedOnMips);
297 void Debug::GenerateFrameDropperLiveEdit(MacroAssembler* masm) {
298 masm->Abort(kLiveEditFrameDroppingIsNotSupportedOnMips);
302 const bool Debug::kFrameDropperSupported = false;
306 } } // namespace v8::internal
308 #endif // V8_TARGET_ARCH_MIPS