1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #if V8_TARGET_ARCH_MIPS
40 #ifdef ENABLE_DEBUGGER_SUPPORT
42 bool BreakLocationIterator::IsDebugBreakAtReturn() {
43 return Debug::IsDebugBreakAtReturn(rinfo());
47 void BreakLocationIterator::SetDebugBreakAtReturn() {
48 // Mips return sequence:
55 // nop (in branch delay slot)
57 // Make sure this constant matches the number if instrucntions we emit.
58 ASSERT(Assembler::kJSReturnSequenceInstructions == 7);
59 CodePatcher patcher(rinfo()->pc(), Assembler::kJSReturnSequenceInstructions);
60 // li and Call pseudo-instructions emit two instructions each.
61 patcher.masm()->li(v8::internal::t9,
62 Operand(reinterpret_cast<int32_t>(
63 debug_info_->GetIsolate()->debug()->debug_break_return()->entry())));
64 patcher.masm()->Call(v8::internal::t9);
65 patcher.masm()->nop();
66 patcher.masm()->nop();
67 patcher.masm()->nop();
69 // TODO(mips): Open issue about using breakpoint instruction instead of nops.
70 // patcher.masm()->bkpt(0);
74 // Restore the JS frame exit code.
75 void BreakLocationIterator::ClearDebugBreakAtReturn() {
76 rinfo()->PatchCode(original_rinfo()->pc(),
77 Assembler::kJSReturnSequenceInstructions);
81 // A debug break in the exit code is identified by the JS frame exit code
82 // having been patched with li/call psuedo-instrunction (liu/ori/jalr).
83 bool Debug::IsDebugBreakAtReturn(RelocInfo* rinfo) {
84 ASSERT(RelocInfo::IsJSReturn(rinfo->rmode()));
85 return rinfo->IsPatchedReturnSequence();
89 bool BreakLocationIterator::IsDebugBreakAtSlot() {
90 ASSERT(IsDebugBreakSlot());
91 // Check whether the debug break slot instructions have been patched.
92 return rinfo()->IsPatchedDebugBreakSlotSequence();
96 void BreakLocationIterator::SetDebugBreakAtSlot() {
97 ASSERT(IsDebugBreakSlot());
98 // Patch the code changing the debug break slot code from:
99 // nop(DEBUG_BREAK_NOP) - nop(1) is sll(zero_reg, zero_reg, 1)
100 // nop(DEBUG_BREAK_NOP)
101 // nop(DEBUG_BREAK_NOP)
102 // nop(DEBUG_BREAK_NOP)
103 // to a call to the debug break slot code.
104 // li t9, address (lui t9 / ori t9 instruction pair)
105 // call t9 (jalr t9 / nop instruction pair)
106 CodePatcher patcher(rinfo()->pc(), Assembler::kDebugBreakSlotInstructions);
107 patcher.masm()->li(v8::internal::t9, Operand(reinterpret_cast<int32_t>(
108 debug_info_->GetIsolate()->debug()->debug_break_slot()->entry())));
109 patcher.masm()->Call(v8::internal::t9);
113 void BreakLocationIterator::ClearDebugBreakAtSlot() {
114 ASSERT(IsDebugBreakSlot());
115 rinfo()->PatchCode(original_rinfo()->pc(),
116 Assembler::kDebugBreakSlotInstructions);
119 const bool Debug::FramePaddingLayout::kIsSupported = false;
122 #define __ ACCESS_MASM(masm)
126 static void Generate_DebugBreakCallHelper(MacroAssembler* masm,
128 RegList non_object_regs) {
130 FrameScope scope(masm, StackFrame::INTERNAL);
132 // Store the registers containing live values on the expression stack to
133 // make sure that these are correctly updated during GC. Non object values
134 // are stored as a smi causing it to be untouched by GC.
135 ASSERT((object_regs & ~kJSCallerSaved) == 0);
136 ASSERT((non_object_regs & ~kJSCallerSaved) == 0);
137 ASSERT((object_regs & non_object_regs) == 0);
138 if ((object_regs | non_object_regs) != 0) {
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 if (FLAG_debug_code) {
144 __ And(at, reg, 0xc0000000);
145 __ Assert(eq, kUnableToEncodeValueAsSmi, at, Operand(zero_reg));
147 __ sll(reg, reg, kSmiTagSize);
150 __ MultiPush(object_regs | non_object_regs);
154 __ RecordComment("// Calling from debug break to runtime - come in - over");
156 __ PrepareCEntryArgs(0); // No arguments.
157 __ PrepareCEntryFunction(ExternalReference::debug_break(masm->isolate()));
162 // Restore the register values from the expression stack.
163 if ((object_regs | non_object_regs) != 0) {
164 __ MultiPop(object_regs | non_object_regs);
165 for (int i = 0; i < kNumJSCallerSaved; i++) {
166 int r = JSCallerSavedCode(i);
167 Register reg = { r };
168 if ((non_object_regs & (1 << r)) != 0) {
169 __ srl(reg, reg, kSmiTagSize);
171 if (FLAG_debug_code &&
172 (((object_regs |non_object_regs) & (1 << r)) == 0)) {
173 __ li(reg, kDebugZapValue);
178 // Leave the internal frame.
181 // Now that the break point has been handled, resume normal execution by
182 // jumping to the target address intended by the caller and that was
183 // overwritten by the address of DebugBreakXXX.
185 ExternalReference(Debug_Address::AfterBreakTarget(), masm->isolate())));
186 __ lw(t9, MemOperand(t9));
191 void Debug::GenerateLoadICDebugBreak(MacroAssembler* masm) {
192 // Calling convention for IC load (from ic-mips.cc).
193 // ----------- S t a t e -------------
195 // -- ra : return address
197 // -- [sp] : receiver
198 // -----------------------------------
199 // Registers a0 and a2 contain objects that need to be pushed on the
200 // expression stack of the fake JS frame.
201 Generate_DebugBreakCallHelper(masm, a0.bit() | a2.bit(), 0);
205 void Debug::GenerateStoreICDebugBreak(MacroAssembler* masm) {
206 // Calling convention for IC store (from ic-mips.cc).
207 // ----------- S t a t e -------------
211 // -- ra : return address
212 // -----------------------------------
213 // Registers a0, a1, and a2 contain objects that need to be pushed on the
214 // expression stack of the fake JS frame.
215 Generate_DebugBreakCallHelper(masm, a0.bit() | a1.bit() | a2.bit(), 0);
219 void Debug::GenerateKeyedLoadICDebugBreak(MacroAssembler* masm) {
220 // ---------- S t a t e --------------
221 // -- ra : return address
224 Generate_DebugBreakCallHelper(masm, a0.bit() | a1.bit(), 0);
228 void Debug::GenerateKeyedStoreICDebugBreak(MacroAssembler* masm) {
229 // ---------- S t a t e --------------
233 // -- ra : return address
234 Generate_DebugBreakCallHelper(masm, a0.bit() | a1.bit() | a2.bit(), 0);
238 void Debug::GenerateCompareNilICDebugBreak(MacroAssembler* masm) {
239 // Register state for CompareNil IC
240 // ----------- S t a t e -------------
242 // -----------------------------------
243 Generate_DebugBreakCallHelper(masm, a0.bit(), 0);
247 void Debug::GenerateCallICDebugBreak(MacroAssembler* masm) {
248 // Calling convention for IC call (from ic-mips.cc).
249 // ----------- S t a t e -------------
251 // -----------------------------------
252 Generate_DebugBreakCallHelper(masm, a2.bit(), 0);
256 void Debug::GenerateReturnDebugBreak(MacroAssembler* masm) {
257 // In places other than IC call sites it is expected that v0 is TOS which
258 // is an object - this is not generally the case so this should be used with
260 Generate_DebugBreakCallHelper(masm, v0.bit(), 0);
264 void Debug::GenerateCallFunctionStubDebugBreak(MacroAssembler* masm) {
265 // Register state for CallFunctionStub (from code-stubs-mips.cc).
266 // ----------- S t a t e -------------
268 // -----------------------------------
269 Generate_DebugBreakCallHelper(masm, a1.bit(), 0);
273 void Debug::GenerateCallFunctionStubRecordDebugBreak(MacroAssembler* masm) {
274 // Register state for CallFunctionStub (from code-stubs-mips.cc).
275 // ----------- S t a t e -------------
277 // -- a2 : cache cell for call target
278 // -----------------------------------
279 Generate_DebugBreakCallHelper(masm, a1.bit() | a2.bit(), 0);
283 void Debug::GenerateCallConstructStubDebugBreak(MacroAssembler* masm) {
284 // Calling convention for CallConstructStub (from code-stubs-mips.cc).
285 // ----------- S t a t e -------------
286 // -- a0 : number of arguments (not smi)
287 // -- a1 : constructor function
288 // -----------------------------------
289 Generate_DebugBreakCallHelper(masm, a1.bit() , a0.bit());
293 void Debug::GenerateCallConstructStubRecordDebugBreak(MacroAssembler* masm) {
294 // Calling convention for CallConstructStub (from code-stubs-mips.cc).
295 // ----------- S t a t e -------------
296 // -- a0 : number of arguments (not smi)
297 // -- a1 : constructor function
298 // -- a2 : cache cell for call target
299 // -----------------------------------
300 Generate_DebugBreakCallHelper(masm, a1.bit() | a2.bit(), a0.bit());
304 void Debug::GenerateSlot(MacroAssembler* masm) {
305 // Generate enough nop's to make space for a call instruction. Avoid emitting
306 // the trampoline pool in the debug break slot code.
307 Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm);
308 Label check_codesize;
309 __ bind(&check_codesize);
310 __ RecordDebugBreakSlot();
311 for (int i = 0; i < Assembler::kDebugBreakSlotInstructions; i++) {
312 __ nop(MacroAssembler::DEBUG_BREAK_NOP);
314 ASSERT_EQ(Assembler::kDebugBreakSlotInstructions,
315 masm->InstructionsGeneratedSince(&check_codesize));
319 void Debug::GenerateSlotDebugBreak(MacroAssembler* masm) {
320 // In the places where a debug break slot is inserted no registers can contain
322 Generate_DebugBreakCallHelper(masm, 0, 0);
326 void Debug::GeneratePlainReturnLiveEdit(MacroAssembler* masm) {
327 masm->Abort(kLiveEditFrameDroppingIsNotSupportedOnMips);
331 void Debug::GenerateFrameDropperLiveEdit(MacroAssembler* masm) {
332 masm->Abort(kLiveEditFrameDroppingIsNotSupportedOnMips);
336 const bool Debug::kFrameDropperSupported = false;
341 #endif // ENABLE_DEBUGGER_SUPPORT
343 } } // namespace v8::internal
345 #endif // V8_TARGET_ARCH_MIPS