• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/debug/debug.h"
8 
9 #include "src/codegen.h"
10 #include "src/debug/liveedit.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 #define __ ACCESS_MASM(masm)
16 
17 
EmitDebugBreakSlot(MacroAssembler * masm)18 void EmitDebugBreakSlot(MacroAssembler* masm) {
19   Label check_size;
20   __ bind(&check_size);
21   for (int i = 0; i < Assembler::kDebugBreakSlotInstructions; i++) {
22     __ nop(MacroAssembler::DEBUG_BREAK_NOP);
23   }
24   DCHECK_EQ(Assembler::kDebugBreakSlotInstructions,
25             masm->InstructionsGeneratedSince(&check_size));
26 }
27 
28 
GenerateSlot(MacroAssembler * masm,RelocInfo::Mode mode)29 void DebugCodegen::GenerateSlot(MacroAssembler* masm, RelocInfo::Mode mode) {
30   // Generate enough nop's to make space for a call instruction. Avoid emitting
31   // the trampoline pool in the debug break slot code.
32   Assembler::BlockTrampolinePoolScope block_pool(masm);
33   masm->RecordDebugBreakSlot(mode);
34   EmitDebugBreakSlot(masm);
35 }
36 
37 
ClearDebugBreakSlot(Isolate * isolate,Address pc)38 void DebugCodegen::ClearDebugBreakSlot(Isolate* isolate, Address pc) {
39   CodePatcher patcher(isolate, pc, Assembler::kDebugBreakSlotInstructions);
40   EmitDebugBreakSlot(patcher.masm());
41 }
42 
43 
PatchDebugBreakSlot(Isolate * isolate,Address pc,Handle<Code> code)44 void DebugCodegen::PatchDebugBreakSlot(Isolate* isolate, Address pc,
45                                        Handle<Code> code) {
46   DCHECK(code->is_debug_stub());
47   CodePatcher patcher(isolate, pc, Assembler::kDebugBreakSlotInstructions);
48   // Patch the code changing the debug break slot code from:
49   //   nop(DEBUG_BREAK_NOP) - nop(1) is sll(zero_reg, zero_reg, 1)
50   //   nop(DEBUG_BREAK_NOP)
51   //   nop(DEBUG_BREAK_NOP)
52   //   nop(DEBUG_BREAK_NOP)
53   // to a call to the debug break slot code.
54   //   li t9, address   (lui t9 / ori t9 instruction pair)
55   //   call t9          (jalr t9 / nop instruction pair)
56   patcher.masm()->li(v8::internal::t9,
57                      Operand(reinterpret_cast<int32_t>(code->entry())));
58   patcher.masm()->Call(v8::internal::t9);
59 }
60 
DebugBreakSlotIsPatched(Address pc)61 bool DebugCodegen::DebugBreakSlotIsPatched(Address pc) {
62   Instr current_instr = Assembler::instr_at(pc);
63   return !Assembler::IsNop(current_instr, Assembler::DEBUG_BREAK_NOP);
64 }
65 
GenerateDebugBreakStub(MacroAssembler * masm,DebugBreakCallHelperMode mode)66 void DebugCodegen::GenerateDebugBreakStub(MacroAssembler* masm,
67                                           DebugBreakCallHelperMode mode) {
68   __ RecordComment("Debug break");
69   {
70     FrameScope scope(masm, StackFrame::INTERNAL);
71 
72     // Push arguments for DebugBreak call.
73     if (mode == SAVE_RESULT_REGISTER) {
74       // Break on return.
75       __ push(v0);
76     } else {
77       // Non-return breaks.
78       __ Push(masm->isolate()->factory()->the_hole_value());
79     }
80     __ PrepareCEntryArgs(1);
81     __ PrepareCEntryFunction(ExternalReference(
82         Runtime::FunctionForId(Runtime::kDebugBreak), masm->isolate()));
83 
84     CEntryStub ceb(masm->isolate(), 1);
85     __ CallStub(&ceb);
86 
87     if (FLAG_debug_code) {
88       for (int i = 0; i < kNumJSCallerSaved; i++) {
89         Register reg = {JSCallerSavedCode(i)};
90         // Do not clobber v0 if mode is SAVE_RESULT_REGISTER. It will
91         // contain return value of the function returned by DebugBreak.
92         if (!(reg.is(v0) && (mode == SAVE_RESULT_REGISTER))) {
93           __ li(reg, kDebugZapValue);
94         }
95       }
96     }
97     // Leave the internal frame.
98   }
99 
100   __ MaybeDropFrames();
101 
102   // Return to caller.
103   __ Ret();
104 }
105 
GenerateHandleDebuggerStatement(MacroAssembler * masm)106 void DebugCodegen::GenerateHandleDebuggerStatement(MacroAssembler* masm) {
107   {
108     FrameScope scope(masm, StackFrame::INTERNAL);
109     __ CallRuntime(Runtime::kHandleDebuggerStatement, 0);
110   }
111   __ MaybeDropFrames();
112 
113   // Return to caller.
114   __ Ret();
115 }
116 
GenerateFrameDropperTrampoline(MacroAssembler * masm)117 void DebugCodegen::GenerateFrameDropperTrampoline(MacroAssembler* masm) {
118   // Frame is being dropped:
119   // - Drop to the target frame specified by a1.
120   // - Look up current function on the frame.
121   // - Leave the frame.
122   // - Restart the frame by calling the function.
123   __ mov(fp, a1);
124   __ lw(a1, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
125 
126   // Pop return address and frame.
127   __ LeaveFrame(StackFrame::INTERNAL);
128 
129   __ lw(a0, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
130   __ lw(a0,
131         FieldMemOperand(a0, SharedFunctionInfo::kFormalParameterCountOffset));
132   __ mov(a2, a0);
133 
134   ParameterCount dummy1(a2);
135   ParameterCount dummy2(a0);
136   __ InvokeFunction(a1, dummy1, dummy2, JUMP_FUNCTION,
137                     CheckDebugStepCallWrapper());
138 }
139 
140 
141 const bool LiveEdit::kFrameDropperSupported = true;
142 
143 #undef __
144 
145 }  // namespace internal
146 }  // namespace v8
147 
148 #endif  // V8_TARGET_ARCH_MIPS
149