Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 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/codegen.h" |
| 8 | #include "src/debug/debug.h" |
| 9 | |
| 10 | namespace v8 { |
| 11 | namespace internal { |
| 12 | |
| 13 | #define __ ACCESS_MASM(masm) |
| 14 | |
| 15 | |
| 16 | void 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 | |
| 27 | void 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 | |
| 36 | void DebugCodegen::ClearDebugBreakSlot(Isolate* isolate, Address pc) { |
| 37 | CodePatcher patcher(isolate, pc, Assembler::kDebugBreakSlotInstructions); |
| 38 | EmitDebugBreakSlot(patcher.masm()); |
| 39 | } |
| 40 | |
| 41 | |
| 42 | void DebugCodegen::PatchDebugBreakSlot(Isolate* isolate, Address pc, |
| 43 | Handle<Code> code) { |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame^] | 44 | DCHECK(code->is_debug_stub()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 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 Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 67 | bool DebugCodegen::DebugBreakSlotIsPatched(Address pc) { |
| 68 | Instr current_instr = Assembler::instr_at(pc); |
| 69 | return !Assembler::IsNop(current_instr, Assembler::DEBUG_BREAK_NOP); |
| 70 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 71 | |
| 72 | void 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 Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 86 | // 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 Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 95 | __ 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 Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 105 | // 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 Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 110 | } |
| 111 | } |
| 112 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 113 | // 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 | |
| 130 | void DebugCodegen::GenerateFrameDropperLiveEdit(MacroAssembler* masm) { |
| 131 | // Load the function pointer off of our current stack frame. |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 132 | __ LoadP(r4, MemOperand(fp, FrameDropperFrameConstants::kFunctionOffset)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 133 | |
| 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 | |
| 156 | const bool LiveEdit::kFrameDropperSupported = true; |
| 157 | |
| 158 | #undef __ |
| 159 | } // namespace internal |
| 160 | } // namespace v8 |
| 161 | |
| 162 | #endif // V8_TARGET_ARCH_PPC |