• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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_PPC
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_trampoline_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   //
50   //   ori r3, r3, 0
51   //   ori r3, r3, 0
52   //   ori r3, r3, 0
53   //   ori r3, r3, 0
54   //   ori r3, r3, 0
55   //
56   // to a call to the debug break code, using a FIXED_SEQUENCE.
57   //
58   //   mov r0, <address>
59   //   mtlr r0
60   //   blrl
61   //
62   Assembler::BlockTrampolinePoolScope block_trampoline_pool(patcher.masm());
63   patcher.masm()->mov(v8::internal::r0,
64                       Operand(reinterpret_cast<intptr_t>(code->entry())));
65   patcher.masm()->mtctr(v8::internal::r0);
66   patcher.masm()->bctrl();
67 }
68 
DebugBreakSlotIsPatched(Address pc)69 bool DebugCodegen::DebugBreakSlotIsPatched(Address pc) {
70   Instr current_instr = Assembler::instr_at(pc);
71   return !Assembler::IsNop(current_instr, Assembler::DEBUG_BREAK_NOP);
72 }
73 
GenerateDebugBreakStub(MacroAssembler * masm,DebugBreakCallHelperMode mode)74 void DebugCodegen::GenerateDebugBreakStub(MacroAssembler* masm,
75                                           DebugBreakCallHelperMode mode) {
76   __ RecordComment("Debug break");
77   {
78     FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
79 
80     // Load padding words on stack.
81     __ LoadSmiLiteral(ip, Smi::FromInt(LiveEdit::kFramePaddingValue));
82     for (int i = 0; i < LiveEdit::kFramePaddingInitialSize; i++) {
83       __ push(ip);
84     }
85     __ LoadSmiLiteral(ip, Smi::FromInt(LiveEdit::kFramePaddingInitialSize));
86     __ push(ip);
87 
88     // Push arguments for DebugBreak call.
89     if (mode == SAVE_RESULT_REGISTER) {
90       // Break on return.
91       __ push(r3);
92     } else {
93       // Non-return breaks.
94       __ Push(masm->isolate()->factory()->the_hole_value());
95     }
96     __ mov(r3, Operand(1));
97     __ mov(r4,
98            Operand(ExternalReference(
99                Runtime::FunctionForId(Runtime::kDebugBreak), masm->isolate())));
100 
101     CEntryStub ceb(masm->isolate(), 1);
102     __ CallStub(&ceb);
103 
104     if (FLAG_debug_code) {
105       for (int i = 0; i < kNumJSCallerSaved; i++) {
106         Register reg = {JSCallerSavedCode(i)};
107         // Do not clobber r3 if mode is SAVE_RESULT_REGISTER. It will
108         // contain return value of the function.
109         if (!(reg.is(r3) && (mode == SAVE_RESULT_REGISTER))) {
110           __ mov(reg, Operand(kDebugZapValue));
111         }
112       }
113     }
114 
115     // Don't bother removing padding bytes pushed on the stack
116     // as the frame is going to be restored right away.
117 
118     // Leave the internal frame.
119   }
120 
121   // Now that the break point has been handled, resume normal execution by
122   // jumping to the target address intended by the caller and that was
123   // overwritten by the address of DebugBreakXXX.
124   ExternalReference after_break_target =
125       ExternalReference::debug_after_break_target_address(masm->isolate());
126   __ mov(ip, Operand(after_break_target));
127   __ LoadP(ip, MemOperand(ip));
128   __ JumpToJSEntry(ip);
129 }
130 
131 
GenerateFrameDropperLiveEdit(MacroAssembler * masm)132 void DebugCodegen::GenerateFrameDropperLiveEdit(MacroAssembler* masm) {
133   // Load the function pointer off of our current stack frame.
134   __ LoadP(r4, MemOperand(fp, FrameDropperFrameConstants::kFunctionOffset));
135 
136   // Pop return address and frame
137   __ LeaveFrame(StackFrame::INTERNAL);
138 
139   ParameterCount dummy(0);
140   __ FloodFunctionIfStepping(r4, no_reg, dummy, dummy);
141 
142   // Load context from the function.
143   __ LoadP(cp, FieldMemOperand(r4, JSFunction::kContextOffset));
144 
145   // Clear new.target as a safety measure.
146   __ LoadRoot(r6, Heap::kUndefinedValueRootIndex);
147 
148   // Get function code.
149   __ LoadP(ip, FieldMemOperand(r4, JSFunction::kSharedFunctionInfoOffset));
150   __ LoadP(ip, FieldMemOperand(ip, SharedFunctionInfo::kCodeOffset));
151   __ addi(ip, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
152 
153   // Re-run JSFunction, r4 is function, cp is context.
154   __ Jump(ip);
155 }
156 
157 
158 const bool LiveEdit::kFrameDropperSupported = true;
159 
160 #undef __
161 }  // namespace internal
162 }  // namespace v8
163 
164 #endif  // V8_TARGET_ARCH_PPC
165