blob: 29e4827be4301e4373c619baeeeaaf2a125f1044 [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) {
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 // 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
Ben Murdochda12d292016-06-02 14:46:10 +010084 // Push arguments for DebugBreak call.
85 if (mode == SAVE_RESULT_REGISTER) {
86 // Break on return.
87 __ push(r0);
88 } else {
89 // Non-return breaks.
90 __ Push(masm->isolate()->factory()->the_hole_value());
91 }
92 __ mov(r0, Operand(1));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000093 __ mov(r1,
94 Operand(ExternalReference(
95 Runtime::FunctionForId(Runtime::kDebugBreak), masm->isolate())));
96
97 CEntryStub ceb(masm->isolate(), 1);
98 __ CallStub(&ceb);
99
100 if (FLAG_debug_code) {
101 for (int i = 0; i < kNumJSCallerSaved; i++) {
102 Register reg = {JSCallerSavedCode(i)};
Ben Murdochda12d292016-06-02 14:46:10 +0100103 // Do not clobber r0 if mode is SAVE_RESULT_REGISTER. It will
104 // contain return value of the function.
105 if (!(reg.is(r0) && (mode == SAVE_RESULT_REGISTER))) {
106 __ mov(reg, Operand(kDebugZapValue));
107 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000108 }
109 }
110
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000111 // Don't bother removing padding bytes pushed on the stack
112 // as the frame is going to be restored right away.
113
114 // Leave the internal frame.
115 }
116
117 // Now that the break point has been handled, resume normal execution by
118 // jumping to the target address intended by the caller and that was
119 // overwritten by the address of DebugBreakXXX.
120 ExternalReference after_break_target =
121 ExternalReference::debug_after_break_target_address(masm->isolate());
122 __ mov(ip, Operand(after_break_target));
123 __ ldr(ip, MemOperand(ip));
124 __ Jump(ip);
125}
126
127
128void DebugCodegen::GenerateFrameDropperLiveEdit(MacroAssembler* masm) {
129 // Load the function pointer off of our current stack frame.
Ben Murdochda12d292016-06-02 14:46:10 +0100130 __ ldr(r1, MemOperand(fp, FrameDropperFrameConstants::kFunctionOffset));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000131
132 // Pop return address, frame and constant pool pointer (if
133 // FLAG_enable_embedded_constant_pool).
134 __ LeaveFrame(StackFrame::INTERNAL);
135
136 ParameterCount dummy(0);
137 __ FloodFunctionIfStepping(r1, no_reg, dummy, dummy);
138
139 { ConstantPoolUnavailableScope constant_pool_unavailable(masm);
140 // Load context from the function.
141 __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
142
143 // Clear new.target as a safety measure.
144 __ LoadRoot(r3, Heap::kUndefinedValueRootIndex);
145
146 // Get function code.
147 __ ldr(ip, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
148 __ ldr(ip, FieldMemOperand(ip, SharedFunctionInfo::kCodeOffset));
149 __ add(ip, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
150
151 // Re-run JSFunction, r1 is function, cp is context.
152 __ Jump(ip);
153 }
154}
155
156
157const bool LiveEdit::kFrameDropperSupported = true;
158
159#undef __
160
161} // namespace internal
162} // namespace v8
163
164#endif // V8_TARGET_ARCH_ARM