blob: 3e4b67c93881d62a5ce68f41e387c385d9f4d0a0 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// Copyright 2013 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_ARM64
6
7#include "src/arm64/frames-arm64.h"
8#include "src/codegen.h"
9#include "src/debug/debug.h"
10
11namespace v8 {
12namespace internal {
13
14#define __ ACCESS_MASM(masm)
15
16
17void EmitDebugBreakSlot(Assembler* masm) {
18 Label check_size;
19 __ bind(&check_size);
20 for (int i = 0; i < Assembler::kDebugBreakSlotInstructions; i++) {
21 __ nop(Assembler::DEBUG_BREAK_NOP);
22 }
23 DCHECK_EQ(Assembler::kDebugBreakSlotInstructions,
24 static_cast<int>(masm->InstructionsGeneratedSince(&check_size)));
25}
26
27
28void DebugCodegen::GenerateSlot(MacroAssembler* masm, RelocInfo::Mode mode) {
29 // Generate enough nop's to make space for a call instruction. Avoid emitting
30 // the constant pool in the debug break slot code.
31 InstructionAccurateScope scope(masm, Assembler::kDebugBreakSlotInstructions);
32 masm->RecordDebugBreakSlot(mode);
33 EmitDebugBreakSlot(masm);
34}
35
36
37void DebugCodegen::ClearDebugBreakSlot(Isolate* isolate, Address pc) {
38 PatchingAssembler patcher(isolate, reinterpret_cast<Instruction*>(pc),
39 Assembler::kDebugBreakSlotInstructions);
40 EmitDebugBreakSlot(&patcher);
41}
42
43
44void DebugCodegen::PatchDebugBreakSlot(Isolate* isolate, Address pc,
45 Handle<Code> code) {
46 DCHECK_EQ(Code::BUILTIN, code->kind());
47 PatchingAssembler patcher(isolate, reinterpret_cast<Instruction*>(pc),
48 Assembler::kDebugBreakSlotInstructions);
49 // Patch the code emitted by DebugCodegen::GenerateSlots, changing the debug
50 // break slot code from
51 // mov x0, x0 @ nop DEBUG_BREAK_NOP
52 // mov x0, x0 @ nop DEBUG_BREAK_NOP
53 // mov x0, x0 @ nop DEBUG_BREAK_NOP
54 // mov x0, x0 @ nop DEBUG_BREAK_NOP
55 // mov x0, x0 @ nop DEBUG_BREAK_NOP
56 // to a call to the debug slot code.
57 // ldr ip0, [pc, #(2 * kInstructionSize)]
58 // blr ip0
59 // b skip
60 // <debug break slot code entry point address (64 bits)>
61 // skip:
62
63 Label skip_constant;
64 // The first instruction of a patched debug break slot must be a load literal
65 // loading the address of the debug break slot code.
66 patcher.ldr_pcrel(ip0, (2 * kInstructionSize) >> kLoadLiteralScaleLog2);
67 patcher.b(&skip_constant);
68 patcher.dc64(reinterpret_cast<int64_t>(code->entry()));
69 patcher.bind(&skip_constant);
70 // TODO(all): check the following is correct.
71 // The debug break slot code will push a frame and call statically compiled
72 // code. By using blr, this call site will be registered in the frame.
73 // The debugger can now iterate on the frames to find this call.
74 patcher.blr(ip0);
75}
76
Ben Murdoch097c5b22016-05-18 11:27:45 +010077bool DebugCodegen::DebugBreakSlotIsPatched(Address pc) {
78 Instruction* current_instr = reinterpret_cast<Instruction*>(pc);
79 return !current_instr->IsNop(Assembler::DEBUG_BREAK_NOP);
80}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000081
82void DebugCodegen::GenerateDebugBreakStub(MacroAssembler* masm,
83 DebugBreakCallHelperMode mode) {
84 __ RecordComment("Debug break");
85 Register scratch = x10;
86 {
87 FrameScope scope(masm, StackFrame::INTERNAL);
88
89 // Load padding words on stack.
90 __ Mov(scratch, Smi::FromInt(LiveEdit::kFramePaddingValue));
91 __ PushMultipleTimes(scratch, LiveEdit::kFramePaddingInitialSize);
92 __ Mov(scratch, Smi::FromInt(LiveEdit::kFramePaddingInitialSize));
93 __ Push(scratch);
94
95 if (mode == SAVE_RESULT_REGISTER) __ Push(x0);
96
97 __ Mov(x0, 0); // No arguments.
98 __ Mov(x1, ExternalReference(Runtime::FunctionForId(Runtime::kDebugBreak),
99 masm->isolate()));
100
101 CEntryStub stub(masm->isolate(), 1);
102 __ CallStub(&stub);
103
104 if (FLAG_debug_code) {
105 for (int i = 0; i < kNumJSCallerSaved; i++) {
106 Register reg = Register::XRegFromCode(JSCallerSavedCode(i));
107 __ Mov(reg, Operand(kDebugZapValue));
108 }
109 }
110
111 // Restore the register values from the expression stack.
112 if (mode == SAVE_RESULT_REGISTER) __ Pop(x0);
113
114 // Don't bother removing padding bytes pushed on the stack
115 // as the frame is going to be restored right away.
116
117 // Leave the internal frame.
118 }
119
120 // Now that the break point has been handled, resume normal execution by
121 // jumping to the target address intended by the caller and that was
122 // overwritten by the address of DebugBreakXXX.
123 ExternalReference after_break_target =
124 ExternalReference::debug_after_break_target_address(masm->isolate());
125 __ Mov(scratch, after_break_target);
126 __ Ldr(scratch, MemOperand(scratch));
127 __ Br(scratch);
128}
129
130
131void DebugCodegen::GenerateFrameDropperLiveEdit(MacroAssembler* masm) {
132 // We do not know our frame height, but set sp based on fp.
133 __ Sub(masm->StackPointer(), fp, kPointerSize);
134 __ AssertStackConsistency();
135
136 __ Pop(x1, fp, lr); // Function, Frame, Return address.
137
138 ParameterCount dummy(0);
139 __ FloodFunctionIfStepping(x1, no_reg, dummy, dummy);
140
141 UseScratchRegisterScope temps(masm);
142 Register scratch = temps.AcquireX();
143
144 // Load context from the function.
145 __ Ldr(cp, FieldMemOperand(x1, JSFunction::kContextOffset));
146
147 // Clear new.target as a safety measure.
148 __ LoadRoot(x3, Heap::kUndefinedValueRootIndex);
149
150 // Get function code.
151 __ Ldr(scratch, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset));
152 __ Ldr(scratch, FieldMemOperand(scratch, SharedFunctionInfo::kCodeOffset));
153 __ Add(scratch, scratch, Code::kHeaderSize - kHeapObjectTag);
154
155 // Re-run JSFunction, x1 is function, cp is context.
156 __ Br(scratch);
157}
158
159
160const bool LiveEdit::kFrameDropperSupported = true;
161
162} // namespace internal
163} // namespace v8
164
165#endif // V8_TARGET_ARCH_ARM64