blob: 8106853134922f73efeb7ca6526396299246c416 [file] [log] [blame]
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001// 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#include "src/v8.h"
6
7#if V8_TARGET_ARCH_PPC
8
9#include "src/codegen.h"
10#include "src/debug.h"
11
12namespace v8 {
13namespace internal {
14
15bool BreakLocationIterator::IsDebugBreakAtReturn() {
16 return Debug::IsDebugBreakAtReturn(rinfo());
17}
18
19
20void BreakLocationIterator::SetDebugBreakAtReturn() {
21 // Patch the code changing the return from JS function sequence from
22 //
23 // LeaveFrame
24 // blr
25 //
26 // to a call to the debug break return code.
27 // this uses a FIXED_SEQUENCE to load an address constant
28 //
29 // mov r0, <address>
30 // mtlr r0
31 // blrl
32 // bkpt
33 //
34 CodePatcher patcher(rinfo()->pc(), Assembler::kJSReturnSequenceInstructions);
35 Assembler::BlockTrampolinePoolScope block_trampoline_pool(patcher.masm());
36 patcher.masm()->mov(
37 v8::internal::r0,
38 Operand(reinterpret_cast<intptr_t>(debug_info_->GetIsolate()
39 ->builtins()
40 ->Return_DebugBreak()
41 ->entry())));
42 patcher.masm()->mtctr(v8::internal::r0);
43 patcher.masm()->bctrl();
44 patcher.masm()->bkpt(0);
45}
46
47
48// Restore the JS frame exit code.
49void BreakLocationIterator::ClearDebugBreakAtReturn() {
50 rinfo()->PatchCode(original_rinfo()->pc(),
51 Assembler::kJSReturnSequenceInstructions);
52}
53
54
55// A debug break in the frame exit code is identified by the JS frame exit code
56// having been patched with a call instruction.
57bool Debug::IsDebugBreakAtReturn(RelocInfo* rinfo) {
58 DCHECK(RelocInfo::IsJSReturn(rinfo->rmode()));
59 return rinfo->IsPatchedReturnSequence();
60}
61
62
63bool BreakLocationIterator::IsDebugBreakAtSlot() {
64 DCHECK(IsDebugBreakSlot());
65 // Check whether the debug break slot instructions have been patched.
66 return rinfo()->IsPatchedDebugBreakSlotSequence();
67}
68
69
70void BreakLocationIterator::SetDebugBreakAtSlot() {
71 DCHECK(IsDebugBreakSlot());
72 // Patch the code changing the debug break slot code from
73 //
74 // ori r3, r3, 0
75 // ori r3, r3, 0
76 // ori r3, r3, 0
77 // ori r3, r3, 0
78 // ori r3, r3, 0
79 //
80 // to a call to the debug break code, using a FIXED_SEQUENCE.
81 //
82 // mov r0, <address>
83 // mtlr r0
84 // blrl
85 //
86 CodePatcher patcher(rinfo()->pc(), Assembler::kDebugBreakSlotInstructions);
87 Assembler::BlockTrampolinePoolScope block_trampoline_pool(patcher.masm());
88 patcher.masm()->mov(
89 v8::internal::r0,
90 Operand(reinterpret_cast<intptr_t>(
91 debug_info_->GetIsolate()->builtins()->Slot_DebugBreak()->entry())));
92 patcher.masm()->mtctr(v8::internal::r0);
93 patcher.masm()->bctrl();
94}
95
96
97void BreakLocationIterator::ClearDebugBreakAtSlot() {
98 DCHECK(IsDebugBreakSlot());
99 rinfo()->PatchCode(original_rinfo()->pc(),
100 Assembler::kDebugBreakSlotInstructions);
101}
102
103
104#define __ ACCESS_MASM(masm)
105
106
107static void Generate_DebugBreakCallHelper(MacroAssembler* masm,
108 RegList object_regs,
109 RegList non_object_regs) {
110 {
111 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
112
113 // Load padding words on stack.
114 __ LoadSmiLiteral(ip, Smi::FromInt(LiveEdit::kFramePaddingValue));
115 for (int i = 0; i < LiveEdit::kFramePaddingInitialSize; i++) {
116 __ push(ip);
117 }
118 __ LoadSmiLiteral(ip, Smi::FromInt(LiveEdit::kFramePaddingInitialSize));
119 __ push(ip);
120
121 // Store the registers containing live values on the expression stack to
122 // make sure that these are correctly updated during GC. Non object values
123 // are stored as a smi causing it to be untouched by GC.
124 DCHECK((object_regs & ~kJSCallerSaved) == 0);
125 DCHECK((non_object_regs & ~kJSCallerSaved) == 0);
126 DCHECK((object_regs & non_object_regs) == 0);
127 if ((object_regs | non_object_regs) != 0) {
128 for (int i = 0; i < kNumJSCallerSaved; i++) {
129 int r = JSCallerSavedCode(i);
130 Register reg = {r};
131 if ((non_object_regs & (1 << r)) != 0) {
132 if (FLAG_debug_code) {
133 __ TestUnsignedSmiCandidate(reg, r0);
134 __ Assert(eq, kUnableToEncodeValueAsSmi, cr0);
135 }
136 __ SmiTag(reg);
137 }
138 }
139 __ MultiPush(object_regs | non_object_regs);
140 }
141
142#ifdef DEBUG
143 __ RecordComment("// Calling from debug break to runtime - come in - over");
144#endif
145 __ mov(r3, Operand::Zero()); // no arguments
146 __ mov(r4, Operand(ExternalReference::debug_break(masm->isolate())));
147
148 CEntryStub ceb(masm->isolate(), 1);
149 __ CallStub(&ceb);
150
151 // Restore the register values from the expression stack.
152 if ((object_regs | non_object_regs) != 0) {
153 __ MultiPop(object_regs | non_object_regs);
154 for (int i = 0; i < kNumJSCallerSaved; i++) {
155 int r = JSCallerSavedCode(i);
156 Register reg = {r};
157 if ((non_object_regs & (1 << r)) != 0) {
158 __ SmiUntag(reg);
159 }
160 if (FLAG_debug_code &&
161 (((object_regs | non_object_regs) & (1 << r)) == 0)) {
162 __ mov(reg, Operand(kDebugZapValue));
163 }
164 }
165 }
166
167 // Don't bother removing padding bytes pushed on the stack
168 // as the frame is going to be restored right away.
169
170 // Leave the internal frame.
171 }
172
173 // Now that the break point has been handled, resume normal execution by
174 // jumping to the target address intended by the caller and that was
175 // overwritten by the address of DebugBreakXXX.
176 ExternalReference after_break_target =
177 ExternalReference::debug_after_break_target_address(masm->isolate());
178 __ mov(ip, Operand(after_break_target));
179 __ LoadP(ip, MemOperand(ip));
180 __ JumpToJSEntry(ip);
181}
182
183
184void DebugCodegen::GenerateCallICStubDebugBreak(MacroAssembler* masm) {
185 // Register state for CallICStub
186 // ----------- S t a t e -------------
187 // -- r4 : function
188 // -- r6 : slot in feedback array (smi)
189 // -----------------------------------
190 Generate_DebugBreakCallHelper(masm, r4.bit() | r6.bit(), 0);
191}
192
193
194void DebugCodegen::GenerateLoadICDebugBreak(MacroAssembler* masm) {
195 // Calling convention for IC load (from ic-ppc.cc).
196 Register receiver = LoadDescriptor::ReceiverRegister();
197 Register name = LoadDescriptor::NameRegister();
198 RegList regs = receiver.bit() | name.bit();
199 if (FLAG_vector_ics) {
200 regs |= VectorLoadICTrampolineDescriptor::SlotRegister().bit();
201 }
202 Generate_DebugBreakCallHelper(masm, regs, 0);
203}
204
205
206void DebugCodegen::GenerateStoreICDebugBreak(MacroAssembler* masm) {
207 // Calling convention for IC store (from ic-ppc.cc).
208 Register receiver = StoreDescriptor::ReceiverRegister();
209 Register name = StoreDescriptor::NameRegister();
210 Register value = StoreDescriptor::ValueRegister();
211 Generate_DebugBreakCallHelper(masm, receiver.bit() | name.bit() | value.bit(),
212 0);
213}
214
215
216void DebugCodegen::GenerateKeyedLoadICDebugBreak(MacroAssembler* masm) {
217 // Calling convention for keyed IC load (from ic-ppc.cc).
218 GenerateLoadICDebugBreak(masm);
219}
220
221
222void DebugCodegen::GenerateKeyedStoreICDebugBreak(MacroAssembler* masm) {
223 // Calling convention for IC keyed store call (from ic-ppc.cc).
224 Register receiver = StoreDescriptor::ReceiverRegister();
225 Register name = StoreDescriptor::NameRegister();
226 Register value = StoreDescriptor::ValueRegister();
227 Generate_DebugBreakCallHelper(masm, receiver.bit() | name.bit() | value.bit(),
228 0);
229}
230
231
232void DebugCodegen::GenerateCompareNilICDebugBreak(MacroAssembler* masm) {
233 // Register state for CompareNil IC
234 // ----------- S t a t e -------------
235 // -- r3 : value
236 // -----------------------------------
237 Generate_DebugBreakCallHelper(masm, r3.bit(), 0);
238}
239
240
241void DebugCodegen::GenerateReturnDebugBreak(MacroAssembler* masm) {
242 // In places other than IC call sites it is expected that r3 is TOS which
243 // is an object - this is not generally the case so this should be used with
244 // care.
245 Generate_DebugBreakCallHelper(masm, r3.bit(), 0);
246}
247
248
249void DebugCodegen::GenerateCallFunctionStubDebugBreak(MacroAssembler* masm) {
250 // Register state for CallFunctionStub (from code-stubs-ppc.cc).
251 // ----------- S t a t e -------------
252 // -- r4 : function
253 // -----------------------------------
254 Generate_DebugBreakCallHelper(masm, r4.bit(), 0);
255}
256
257
258void DebugCodegen::GenerateCallConstructStubDebugBreak(MacroAssembler* masm) {
259 // Calling convention for CallConstructStub (from code-stubs-ppc.cc)
260 // ----------- S t a t e -------------
261 // -- r3 : number of arguments (not smi)
262 // -- r4 : constructor function
263 // -----------------------------------
264 Generate_DebugBreakCallHelper(masm, r4.bit(), r3.bit());
265}
266
267
268void DebugCodegen::GenerateCallConstructStubRecordDebugBreak(
269 MacroAssembler* masm) {
270 // Calling convention for CallConstructStub (from code-stubs-ppc.cc)
271 // ----------- S t a t e -------------
272 // -- r3 : number of arguments (not smi)
273 // -- r4 : constructor function
274 // -- r5 : feedback array
275 // -- r6 : feedback slot (smi)
276 // -----------------------------------
277 Generate_DebugBreakCallHelper(masm, r4.bit() | r5.bit() | r6.bit(), r3.bit());
278}
279
280
281void DebugCodegen::GenerateSlot(MacroAssembler* masm) {
282 // Generate enough nop's to make space for a call instruction. Avoid emitting
283 // the trampoline pool in the debug break slot code.
284 Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm);
285 Label check_codesize;
286 __ bind(&check_codesize);
287 __ RecordDebugBreakSlot();
288 for (int i = 0; i < Assembler::kDebugBreakSlotInstructions; i++) {
289 __ nop(MacroAssembler::DEBUG_BREAK_NOP);
290 }
291 DCHECK_EQ(Assembler::kDebugBreakSlotInstructions,
292 masm->InstructionsGeneratedSince(&check_codesize));
293}
294
295
296void DebugCodegen::GenerateSlotDebugBreak(MacroAssembler* masm) {
297 // In the places where a debug break slot is inserted no registers can contain
298 // object pointers.
299 Generate_DebugBreakCallHelper(masm, 0, 0);
300}
301
302
303void DebugCodegen::GeneratePlainReturnLiveEdit(MacroAssembler* masm) {
304 __ Ret();
305}
306
307
308void DebugCodegen::GenerateFrameDropperLiveEdit(MacroAssembler* masm) {
309 ExternalReference restarter_frame_function_slot =
310 ExternalReference::debug_restarter_frame_function_pointer_address(
311 masm->isolate());
312 __ mov(ip, Operand(restarter_frame_function_slot));
313 __ li(r4, Operand::Zero());
314 __ StoreP(r4, MemOperand(ip, 0));
315
316 // Load the function pointer off of our current stack frame.
317 __ LoadP(r4, MemOperand(fp, StandardFrameConstants::kConstantPoolOffset -
318 kPointerSize));
319
320 // Pop return address, frame and constant pool pointer (if
321 // FLAG_enable_ool_constant_pool).
322 __ LeaveFrame(StackFrame::INTERNAL);
323
324 // Load context from the function.
325 __ LoadP(cp, FieldMemOperand(r4, JSFunction::kContextOffset));
326
327 // Get function code.
328 __ LoadP(ip, FieldMemOperand(r4, JSFunction::kSharedFunctionInfoOffset));
329 __ LoadP(ip, FieldMemOperand(ip, SharedFunctionInfo::kCodeOffset));
330 __ addi(ip, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
331
332 // Re-run JSFunction, r4 is function, cp is context.
333 __ Jump(ip);
334}
335
336
337const bool LiveEdit::kFrameDropperSupported = true;
338
339#undef __
340}
341} // namespace v8::internal
342
343#endif // V8_TARGET_ARCH_PPC