blob: 7facf9526a8c0e3e28979bb859b6224130c9f89b [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// 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/codegen.h"
8#include "src/debug/debug.h"
9
10namespace v8 {
11namespace internal {
12
13#define __ ACCESS_MASM(masm)
14
15
16void EmitDebugBreakSlot(MacroAssembler* masm) {
17 Label check_size;
18 __ bind(&check_size);
19 for (int i = 0; i < Assembler::kDebugBreakSlotInstructions; i++) {
20 __ nop(MacroAssembler::DEBUG_BREAK_NOP);
21 }
22 DCHECK_EQ(Assembler::kDebugBreakSlotInstructions,
23 masm->InstructionsGeneratedSince(&check_size));
24}
25
26
27void DebugCodegen::GenerateSlot(MacroAssembler* masm, RelocInfo::Mode mode) {
28 // Generate enough nop's to make space for a call instruction. Avoid emitting
29 // the trampoline pool in the debug break slot code.
30 Assembler::BlockTrampolinePoolScope block_trampoline_pool(masm);
31 masm->RecordDebugBreakSlot(mode);
32 EmitDebugBreakSlot(masm);
33}
34
35
36void DebugCodegen::ClearDebugBreakSlot(Isolate* isolate, Address pc) {
37 CodePatcher patcher(isolate, pc, Assembler::kDebugBreakSlotInstructions);
38 EmitDebugBreakSlot(patcher.masm());
39}
40
41
42void DebugCodegen::PatchDebugBreakSlot(Isolate* isolate, Address pc,
43 Handle<Code> code) {
Ben Murdoch61f157c2016-09-16 13:49:30 +010044 DCHECK(code->is_debug_stub());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000045 CodePatcher patcher(isolate, pc, Assembler::kDebugBreakSlotInstructions);
46 // Patch the code changing the debug break slot code from
47 //
48 // ori r3, r3, 0
49 // ori r3, r3, 0
50 // ori r3, r3, 0
51 // ori r3, r3, 0
52 // ori r3, r3, 0
53 //
54 // to a call to the debug break code, using a FIXED_SEQUENCE.
55 //
56 // mov r0, <address>
57 // mtlr r0
58 // blrl
59 //
60 Assembler::BlockTrampolinePoolScope block_trampoline_pool(patcher.masm());
61 patcher.masm()->mov(v8::internal::r0,
62 Operand(reinterpret_cast<intptr_t>(code->entry())));
63 patcher.masm()->mtctr(v8::internal::r0);
64 patcher.masm()->bctrl();
65}
66
Ben Murdoch097c5b22016-05-18 11:27:45 +010067bool DebugCodegen::DebugBreakSlotIsPatched(Address pc) {
68 Instr current_instr = Assembler::instr_at(pc);
69 return !Assembler::IsNop(current_instr, Assembler::DEBUG_BREAK_NOP);
70}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000071
72void DebugCodegen::GenerateDebugBreakStub(MacroAssembler* masm,
73 DebugBreakCallHelperMode mode) {
74 __ RecordComment("Debug break");
75 {
76 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
77
78 // Load padding words on stack.
79 __ LoadSmiLiteral(ip, Smi::FromInt(LiveEdit::kFramePaddingValue));
80 for (int i = 0; i < LiveEdit::kFramePaddingInitialSize; i++) {
81 __ push(ip);
82 }
83 __ LoadSmiLiteral(ip, Smi::FromInt(LiveEdit::kFramePaddingInitialSize));
84 __ push(ip);
85
Ben Murdochda12d292016-06-02 14:46:10 +010086 // Push arguments for DebugBreak call.
87 if (mode == SAVE_RESULT_REGISTER) {
88 // Break on return.
89 __ push(r3);
90 } else {
91 // Non-return breaks.
92 __ Push(masm->isolate()->factory()->the_hole_value());
93 }
94 __ mov(r3, Operand(1));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000095 __ mov(r4,
96 Operand(ExternalReference(
97 Runtime::FunctionForId(Runtime::kDebugBreak), masm->isolate())));
98
99 CEntryStub ceb(masm->isolate(), 1);
100 __ CallStub(&ceb);
101
102 if (FLAG_debug_code) {
103 for (int i = 0; i < kNumJSCallerSaved; i++) {
104 Register reg = {JSCallerSavedCode(i)};
Ben Murdochda12d292016-06-02 14:46:10 +0100105 // Do not clobber r3 if mode is SAVE_RESULT_REGISTER. It will
106 // contain return value of the function.
107 if (!(reg.is(r3) && (mode == SAVE_RESULT_REGISTER))) {
108 __ mov(reg, Operand(kDebugZapValue));
109 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000110 }
111 }
112
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000113 // Don't bother removing padding bytes pushed on the stack
114 // as the frame is going to be restored right away.
115
116 // Leave the internal frame.
117 }
118
119 // Now that the break point has been handled, resume normal execution by
120 // jumping to the target address intended by the caller and that was
121 // overwritten by the address of DebugBreakXXX.
122 ExternalReference after_break_target =
123 ExternalReference::debug_after_break_target_address(masm->isolate());
124 __ mov(ip, Operand(after_break_target));
125 __ LoadP(ip, MemOperand(ip));
126 __ JumpToJSEntry(ip);
127}
128
129
130void DebugCodegen::GenerateFrameDropperLiveEdit(MacroAssembler* masm) {
131 // Load the function pointer off of our current stack frame.
Ben Murdochda12d292016-06-02 14:46:10 +0100132 __ LoadP(r4, MemOperand(fp, FrameDropperFrameConstants::kFunctionOffset));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000133
134 // Pop return address and frame
135 __ LeaveFrame(StackFrame::INTERNAL);
136
137 ParameterCount dummy(0);
138 __ FloodFunctionIfStepping(r4, no_reg, dummy, dummy);
139
140 // Load context from the function.
141 __ LoadP(cp, FieldMemOperand(r4, JSFunction::kContextOffset));
142
143 // Clear new.target as a safety measure.
144 __ LoadRoot(r6, Heap::kUndefinedValueRootIndex);
145
146 // Get function code.
147 __ LoadP(ip, FieldMemOperand(r4, JSFunction::kSharedFunctionInfoOffset));
148 __ LoadP(ip, FieldMemOperand(ip, SharedFunctionInfo::kCodeOffset));
149 __ addi(ip, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
150
151 // Re-run JSFunction, r4 is function, cp is context.
152 __ Jump(ip);
153}
154
155
156const bool LiveEdit::kFrameDropperSupported = true;
157
158#undef __
159} // namespace internal
160} // namespace v8
161
162#endif // V8_TARGET_ARCH_PPC