blob: aab5399fee177d248fea1638ff66e7cc75b48f21 [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) {
44 DCHECK_EQ(Code::BUILTIN, code->kind());
45 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
86 if (mode == SAVE_RESULT_REGISTER) __ push(r3);
87
88 __ mov(r3, Operand::Zero()); // no arguments
89 __ mov(r4,
90 Operand(ExternalReference(
91 Runtime::FunctionForId(Runtime::kDebugBreak), masm->isolate())));
92
93 CEntryStub ceb(masm->isolate(), 1);
94 __ CallStub(&ceb);
95
96 if (FLAG_debug_code) {
97 for (int i = 0; i < kNumJSCallerSaved; i++) {
98 Register reg = {JSCallerSavedCode(i)};
99 __ mov(reg, Operand(kDebugZapValue));
100 }
101 }
102
103 if (mode == SAVE_RESULT_REGISTER) __ pop(r3);
104
105 // Don't bother removing padding bytes pushed on the stack
106 // as the frame is going to be restored right away.
107
108 // Leave the internal frame.
109 }
110
111 // Now that the break point has been handled, resume normal execution by
112 // jumping to the target address intended by the caller and that was
113 // overwritten by the address of DebugBreakXXX.
114 ExternalReference after_break_target =
115 ExternalReference::debug_after_break_target_address(masm->isolate());
116 __ mov(ip, Operand(after_break_target));
117 __ LoadP(ip, MemOperand(ip));
118 __ JumpToJSEntry(ip);
119}
120
121
122void DebugCodegen::GenerateFrameDropperLiveEdit(MacroAssembler* masm) {
123 // Load the function pointer off of our current stack frame.
124 __ LoadP(r4, MemOperand(fp, StandardFrameConstants::kConstantPoolOffset -
125 kPointerSize));
126
127 // Pop return address and frame
128 __ LeaveFrame(StackFrame::INTERNAL);
129
130 ParameterCount dummy(0);
131 __ FloodFunctionIfStepping(r4, no_reg, dummy, dummy);
132
133 // Load context from the function.
134 __ LoadP(cp, FieldMemOperand(r4, JSFunction::kContextOffset));
135
136 // Clear new.target as a safety measure.
137 __ LoadRoot(r6, Heap::kUndefinedValueRootIndex);
138
139 // Get function code.
140 __ LoadP(ip, FieldMemOperand(r4, JSFunction::kSharedFunctionInfoOffset));
141 __ LoadP(ip, FieldMemOperand(ip, SharedFunctionInfo::kCodeOffset));
142 __ addi(ip, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
143
144 // Re-run JSFunction, r4 is function, cp is context.
145 __ Jump(ip);
146}
147
148
149const bool LiveEdit::kFrameDropperSupported = true;
150
151#undef __
152} // namespace internal
153} // namespace v8
154
155#endif // V8_TARGET_ARCH_PPC