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
11 #include "src/codegen.h"
12 #include "src/debug.h"
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);
94 #define __ ACCESS_MASM(masm)
98 static void Generate_DebugBreakCallHelper(MacroAssembler* masm,
100 RegList non_object_regs) {
102 FrameScope scope(masm, StackFrame::INTERNAL);
104 // Store the registers containing live values on the expression stack to
105 // make sure that these are correctly updated during GC. Non object values
106 // are stored as a smi causing it to be untouched by GC.
107 ASSERT((object_regs & ~kJSCallerSaved) == 0);
108 ASSERT((non_object_regs & ~kJSCallerSaved) == 0);
109 ASSERT((object_regs & non_object_regs) == 0);
110 if ((object_regs | non_object_regs) != 0) {
111 for (int i = 0; i < kNumJSCallerSaved; i++) {
112 int r = JSCallerSavedCode(i);
113 Register reg = { r };
114 if ((non_object_regs & (1 << r)) != 0) {
115 if (FLAG_debug_code) {
116 __ And(at, reg, 0xc0000000);
117 __ Assert(eq, kUnableToEncodeValueAsSmi, at, Operand(zero_reg));
119 __ sll(reg, reg, kSmiTagSize);
122 __ MultiPush(object_regs | non_object_regs);
126 __ RecordComment("// Calling from debug break to runtime - come in - over");
128 __ PrepareCEntryArgs(0); // No arguments.
129 __ PrepareCEntryFunction(ExternalReference::debug_break(masm->isolate()));
131 CEntryStub ceb(masm->isolate(), 1);
134 // Restore the register values from the expression stack.
135 if ((object_regs | non_object_regs) != 0) {
136 __ MultiPop(object_regs | non_object_regs);
137 for (int i = 0; i < kNumJSCallerSaved; i++) {
138 int r = JSCallerSavedCode(i);
139 Register reg = { r };
140 if ((non_object_regs & (1 << r)) != 0) {
141 __ srl(reg, reg, kSmiTagSize);
143 if (FLAG_debug_code &&
144 (((object_regs |non_object_regs) & (1 << r)) == 0)) {
145 __ li(reg, kDebugZapValue);
150 // Leave the internal frame.
153 // Now that the break point has been handled, resume normal execution by
154 // jumping to the target address intended by the caller and that was
155 // overwritten by the address of DebugBreakXXX.
156 ExternalReference after_break_target =
157 ExternalReference::debug_after_break_target_address(masm->isolate());
158 __ li(t9, Operand(after_break_target));
159 __ lw(t9, MemOperand(t9));
164 void DebugCodegen::GenerateCallICStubDebugBreak(MacroAssembler* masm) {
165 // Register state for CallICStub
166 // ----------- S t a t e -------------
168 // -- a3 : slot in feedback array (smi)
169 // -----------------------------------
170 Generate_DebugBreakCallHelper(masm, a1.bit() | a3.bit(), 0);
174 void DebugCodegen::GenerateLoadICDebugBreak(MacroAssembler* masm) {
175 // Calling convention for IC load (from ic-mips.cc).
176 // ----------- S t a t e -------------
178 // -- ra : return address
180 // -- [sp] : receiver
181 // -----------------------------------
182 // Registers a0 and a2 contain objects that need to be pushed on the
183 // expression stack of the fake JS frame.
184 Generate_DebugBreakCallHelper(masm, a0.bit() | a2.bit(), 0);
188 void DebugCodegen::GenerateStoreICDebugBreak(MacroAssembler* masm) {
189 // Calling convention for IC store (from ic-mips.cc).
190 // ----------- S t a t e -------------
194 // -- ra : return address
195 // -----------------------------------
196 // Registers a0, a1, and a2 contain objects that need to be pushed on the
197 // expression stack of the fake JS frame.
198 Generate_DebugBreakCallHelper(masm, a0.bit() | a1.bit() | a2.bit(), 0);
202 void DebugCodegen::GenerateKeyedLoadICDebugBreak(MacroAssembler* masm) {
203 // ---------- S t a t e --------------
204 // -- ra : return address
207 Generate_DebugBreakCallHelper(masm, a0.bit() | a1.bit(), 0);
211 void DebugCodegen::GenerateKeyedStoreICDebugBreak(MacroAssembler* masm) {
212 // ---------- S t a t e --------------
216 // -- ra : return address
217 Generate_DebugBreakCallHelper(masm, a0.bit() | a1.bit() | a2.bit(), 0);
221 void DebugCodegen::GenerateCompareNilICDebugBreak(MacroAssembler* masm) {
222 // Register state for CompareNil IC
223 // ----------- S t a t e -------------
225 // -----------------------------------
226 Generate_DebugBreakCallHelper(masm, a0.bit(), 0);
230 void DebugCodegen::GenerateReturnDebugBreak(MacroAssembler* masm) {
231 // In places other than IC call sites it is expected that v0 is TOS which
232 // is an object - this is not generally the case so this should be used with
234 Generate_DebugBreakCallHelper(masm, v0.bit(), 0);
238 void DebugCodegen::GenerateCallFunctionStubDebugBreak(MacroAssembler* masm) {
239 // Register state for CallFunctionStub (from code-stubs-mips.cc).
240 // ----------- S t a t e -------------
242 // -----------------------------------
243 Generate_DebugBreakCallHelper(masm, a1.bit(), 0);
247 void DebugCodegen::GenerateCallConstructStubDebugBreak(MacroAssembler* masm) {
248 // Calling convention for CallConstructStub (from code-stubs-mips.cc).
249 // ----------- S t a t e -------------
250 // -- a0 : number of arguments (not smi)
251 // -- a1 : constructor function
252 // -----------------------------------
253 Generate_DebugBreakCallHelper(masm, a1.bit() , a0.bit());
257 void DebugCodegen::GenerateCallConstructStubRecordDebugBreak(
258 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 DebugCodegen::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 DebugCodegen::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 DebugCodegen::GeneratePlainReturnLiveEdit(MacroAssembler* masm) {
293 masm->Abort(kLiveEditFrameDroppingIsNotSupportedOnMips);
297 void DebugCodegen::GenerateFrameDropperLiveEdit(MacroAssembler* masm) {
298 masm->Abort(kLiveEditFrameDroppingIsNotSupportedOnMips);
302 const bool LiveEdit::kFrameDropperSupported = false;
306 } } // namespace v8::internal
308 #endif // V8_TARGET_ARCH_MIPS