blob: 5fdda4fedc34144011441d4165f8db5372f78489 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// Copyright 2012 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_ARM
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 constant pool in the debug break slot code.
30 Assembler::BlockConstPoolScope block_const_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 // mov r2, r2
48 // mov r2, r2
49 // mov r2, r2
50 // mov r2, r2
51 // to a call to the debug break slot code.
52 // ldr ip, [pc, #0]
53 // b skip
54 // <debug break slot code entry point address>
55 // skip:
56 // blx ip
57 Label skip_constant;
58 patcher.masm()->ldr(ip, MemOperand(v8::internal::pc, 0));
59 patcher.masm()->b(&skip_constant);
60 patcher.Emit(code->entry());
61 patcher.masm()->bind(&skip_constant);
62 patcher.masm()->blx(ip);
63}
64
Ben Murdoch097c5b22016-05-18 11:27:45 +010065bool DebugCodegen::DebugBreakSlotIsPatched(Address pc) {
66 Instr current_instr = Assembler::instr_at(pc);
67 return !Assembler::IsNop(current_instr, Assembler::DEBUG_BREAK_NOP);
68}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000069
70void DebugCodegen::GenerateDebugBreakStub(MacroAssembler* masm,
71 DebugBreakCallHelperMode mode) {
72 __ RecordComment("Debug break");
73 {
74 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
75
76 // Load padding words on stack.
77 __ mov(ip, Operand(Smi::FromInt(LiveEdit::kFramePaddingValue)));
78 for (int i = 0; i < LiveEdit::kFramePaddingInitialSize; i++) {
79 __ push(ip);
80 }
81 __ mov(ip, Operand(Smi::FromInt(LiveEdit::kFramePaddingInitialSize)));
82 __ push(ip);
83
84 if (mode == SAVE_RESULT_REGISTER) __ push(r0);
85
86 __ mov(r0, Operand::Zero()); // no arguments
87 __ mov(r1,
88 Operand(ExternalReference(
89 Runtime::FunctionForId(Runtime::kDebugBreak), masm->isolate())));
90
91 CEntryStub ceb(masm->isolate(), 1);
92 __ CallStub(&ceb);
93
94 if (FLAG_debug_code) {
95 for (int i = 0; i < kNumJSCallerSaved; i++) {
96 Register reg = {JSCallerSavedCode(i)};
97 __ mov(reg, Operand(kDebugZapValue));
98 }
99 }
100
101 if (mode == SAVE_RESULT_REGISTER) __ pop(r0);
102
103 // Don't bother removing padding bytes pushed on the stack
104 // as the frame is going to be restored right away.
105
106 // Leave the internal frame.
107 }
108
109 // Now that the break point has been handled, resume normal execution by
110 // jumping to the target address intended by the caller and that was
111 // overwritten by the address of DebugBreakXXX.
112 ExternalReference after_break_target =
113 ExternalReference::debug_after_break_target_address(masm->isolate());
114 __ mov(ip, Operand(after_break_target));
115 __ ldr(ip, MemOperand(ip));
116 __ Jump(ip);
117}
118
119
120void DebugCodegen::GenerateFrameDropperLiveEdit(MacroAssembler* masm) {
121 // Load the function pointer off of our current stack frame.
122 __ ldr(r1, MemOperand(fp,
123 StandardFrameConstants::kConstantPoolOffset - kPointerSize));
124
125 // Pop return address, frame and constant pool pointer (if
126 // FLAG_enable_embedded_constant_pool).
127 __ LeaveFrame(StackFrame::INTERNAL);
128
129 ParameterCount dummy(0);
130 __ FloodFunctionIfStepping(r1, no_reg, dummy, dummy);
131
132 { ConstantPoolUnavailableScope constant_pool_unavailable(masm);
133 // Load context from the function.
134 __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
135
136 // Clear new.target as a safety measure.
137 __ LoadRoot(r3, Heap::kUndefinedValueRootIndex);
138
139 // Get function code.
140 __ ldr(ip, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
141 __ ldr(ip, FieldMemOperand(ip, SharedFunctionInfo::kCodeOffset));
142 __ add(ip, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
143
144 // Re-run JSFunction, r1 is function, cp is context.
145 __ Jump(ip);
146 }
147}
148
149
150const bool LiveEdit::kFrameDropperSupported = true;
151
152#undef __
153
154} // namespace internal
155} // namespace v8
156
157#endif // V8_TARGET_ARCH_ARM