blob: 6d7d6b8ace54d9e027b720160ba79bccdbf68e40 [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +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.
Steve Blocka7e24c12009-10-30 11:49:00 +00004
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005#include "src/v8.h"
Steve Blocka7e24c12009-10-30 11:49:00 +00006
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007#if V8_TARGET_ARCH_ARM
Leon Clarkef7060e22010-06-03 12:02:55 +01008
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009#include "src/codegen.h"
10#include "src/debug.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000011
12namespace v8 {
13namespace internal {
14
Steve Blocka7e24c12009-10-30 11:49:00 +000015bool BreakLocationIterator::IsDebugBreakAtReturn() {
16 return Debug::IsDebugBreakAtReturn(rinfo());
17}
18
19
20void BreakLocationIterator::SetDebugBreakAtReturn() {
21 // Patch the code changing the return from JS function sequence from
22 // mov sp, fp
23 // ldmia sp!, {fp, lr}
24 // add sp, sp, #4
25 // bx lr
26 // to a call to the debug break return code.
Steve Block6ded16b2010-05-10 14:33:55 +010027 // ldr ip, [pc, #0]
28 // blx ip
Steve Blocka7e24c12009-10-30 11:49:00 +000029 // <debug break return code entry point address>
Ben Murdochb8a8cc12014-11-26 15:28:44 +000030 // bkpt 0
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +010031 CodePatcher patcher(rinfo()->pc(), Assembler::kJSReturnSequenceInstructions);
Steve Block6ded16b2010-05-10 14:33:55 +010032 patcher.masm()->ldr(v8::internal::ip, MemOperand(v8::internal::pc, 0));
33 patcher.masm()->blx(v8::internal::ip);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000034 patcher.Emit(
35 debug_info_->GetIsolate()->builtins()->Return_DebugBreak()->entry());
Steve Blocka7e24c12009-10-30 11:49:00 +000036 patcher.masm()->bkpt(0);
37}
38
39
40// Restore the JS frame exit code.
41void BreakLocationIterator::ClearDebugBreakAtReturn() {
42 rinfo()->PatchCode(original_rinfo()->pc(),
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +010043 Assembler::kJSReturnSequenceInstructions);
Steve Blocka7e24c12009-10-30 11:49:00 +000044}
45
46
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +010047// A debug break in the frame exit code is identified by the JS frame exit code
48// having been patched with a call instruction.
Steve Blocka7e24c12009-10-30 11:49:00 +000049bool Debug::IsDebugBreakAtReturn(RelocInfo* rinfo) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000050 DCHECK(RelocInfo::IsJSReturn(rinfo->rmode()));
Steve Block3ce2e202009-11-05 08:53:23 +000051 return rinfo->IsPatchedReturnSequence();
Steve Blocka7e24c12009-10-30 11:49:00 +000052}
53
54
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +010055bool BreakLocationIterator::IsDebugBreakAtSlot() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000056 DCHECK(IsDebugBreakSlot());
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +010057 // Check whether the debug break slot instructions have been patched.
58 return rinfo()->IsPatchedDebugBreakSlotSequence();
59}
60
61
62void BreakLocationIterator::SetDebugBreakAtSlot() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000063 DCHECK(IsDebugBreakSlot());
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +010064 // Patch the code changing the debug break slot code from
65 // mov r2, r2
66 // mov r2, r2
67 // mov r2, r2
68 // to a call to the debug break slot code.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +010069 // ldr ip, [pc, #0]
70 // blx ip
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +010071 // <debug break slot code entry point address>
72 CodePatcher patcher(rinfo()->pc(), Assembler::kDebugBreakSlotInstructions);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +010073 patcher.masm()->ldr(v8::internal::ip, MemOperand(v8::internal::pc, 0));
74 patcher.masm()->blx(v8::internal::ip);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000075 patcher.Emit(
76 debug_info_->GetIsolate()->builtins()->Slot_DebugBreak()->entry());
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +010077}
78
79
80void BreakLocationIterator::ClearDebugBreakAtSlot() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000081 DCHECK(IsDebugBreakSlot());
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +010082 rinfo()->PatchCode(original_rinfo()->pc(),
83 Assembler::kDebugBreakSlotInstructions);
84}
85
86
Steve Blocka7e24c12009-10-30 11:49:00 +000087#define __ ACCESS_MASM(masm)
88
89
90static void Generate_DebugBreakCallHelper(MacroAssembler* masm,
Kristian Monsen80d68ea2010-09-08 11:05:35 +010091 RegList object_regs,
92 RegList non_object_regs) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +010093 {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000094 FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
95
96 // Load padding words on stack.
97 __ mov(ip, Operand(Smi::FromInt(LiveEdit::kFramePaddingValue)));
98 for (int i = 0; i < LiveEdit::kFramePaddingInitialSize; i++) {
99 __ push(ip);
100 }
101 __ mov(ip, Operand(Smi::FromInt(LiveEdit::kFramePaddingInitialSize)));
102 __ push(ip);
Steve Blocka7e24c12009-10-30 11:49:00 +0000103
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100104 // Store the registers containing live values on the expression stack to
105 // make sure that these are correctly updated during GC. Non object values
106 // are stored as a smi causing it to be untouched by GC.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000107 DCHECK((object_regs & ~kJSCallerSaved) == 0);
108 DCHECK((non_object_regs & ~kJSCallerSaved) == 0);
109 DCHECK((object_regs & non_object_regs) == 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100110 if ((object_regs | non_object_regs) != 0) {
111 for (int i = 0; i < kNumJSCallerSaved; i++) {
112 int r = JSCallerSavedCode(i);
113 Register reg = { r };
114 if ((non_object_regs & (1 << r)) != 0) {
115 if (FLAG_debug_code) {
116 __ tst(reg, Operand(0xc0000000));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000117 __ Assert(eq, kUnableToEncodeValueAsSmi);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100118 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000119 __ SmiTag(reg);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100120 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100121 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100122 __ stm(db_w, sp, object_regs | non_object_regs);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100123 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000124
125#ifdef DEBUG
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100126 __ RecordComment("// Calling from debug break to runtime - come in - over");
Steve Blocka7e24c12009-10-30 11:49:00 +0000127#endif
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000128 __ mov(r0, Operand::Zero()); // no arguments
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100129 __ mov(r1, Operand(ExternalReference::debug_break(masm->isolate())));
Steve Blocka7e24c12009-10-30 11:49:00 +0000130
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000131 CEntryStub ceb(masm->isolate(), 1);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100132 __ CallStub(&ceb);
Steve Blocka7e24c12009-10-30 11:49:00 +0000133
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100134 // Restore the register values from the expression stack.
135 if ((object_regs | non_object_regs) != 0) {
136 __ ldm(ia_w, sp, object_regs | non_object_regs);
137 for (int i = 0; i < kNumJSCallerSaved; i++) {
138 int r = JSCallerSavedCode(i);
139 Register reg = { r };
140 if ((non_object_regs & (1 << r)) != 0) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000141 __ SmiUntag(reg);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100142 }
143 if (FLAG_debug_code &&
144 (((object_regs |non_object_regs) & (1 << r)) == 0)) {
145 __ mov(reg, Operand(kDebugZapValue));
146 }
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100147 }
148 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000149
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000150 // Don't bother removing padding bytes pushed on the stack
151 // as the frame is going to be restored right away.
152
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100153 // Leave the internal frame.
154 }
Ben Murdoch85b71792012-04-11 18:30:58 +0100155
Steve Blocka7e24c12009-10-30 11:49:00 +0000156 // Now that the break point has been handled, resume normal execution by
157 // jumping to the target address intended by the caller and that was
158 // overwritten by the address of DebugBreakXXX.
Steve Block44f0eee2011-05-26 01:26:41 +0100159 ExternalReference after_break_target =
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000160 ExternalReference::debug_after_break_target_address(masm->isolate());
Steve Block44f0eee2011-05-26 01:26:41 +0100161 __ mov(ip, Operand(after_break_target));
Steve Blocka7e24c12009-10-30 11:49:00 +0000162 __ ldr(ip, MemOperand(ip));
163 __ Jump(ip);
164}
165
166
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000167void DebugCodegen::GenerateCallICStubDebugBreak(MacroAssembler* masm) {
168 // Register state for CallICStub
Steve Blocka7e24c12009-10-30 11:49:00 +0000169 // ----------- S t a t e -------------
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000170 // -- r1 : function
171 // -- r3 : slot in feedback array (smi)
Steve Blocka7e24c12009-10-30 11:49:00 +0000172 // -----------------------------------
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000173 Generate_DebugBreakCallHelper(masm, r1.bit() | r3.bit(), 0);
Steve Blocka7e24c12009-10-30 11:49:00 +0000174}
175
176
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000177void DebugCodegen::GenerateLoadICDebugBreak(MacroAssembler* masm) {
178 // Calling convention for IC load (from ic-arm.cc).
179 Register receiver = LoadDescriptor::ReceiverRegister();
180 Register name = LoadDescriptor::NameRegister();
181 Generate_DebugBreakCallHelper(masm, receiver.bit() | name.bit(), 0);
182}
183
184
185void DebugCodegen::GenerateStoreICDebugBreak(MacroAssembler* masm) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000186 // Calling convention for IC store (from ic-arm.cc).
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000187 Register receiver = StoreDescriptor::ReceiverRegister();
188 Register name = StoreDescriptor::NameRegister();
189 Register value = StoreDescriptor::ValueRegister();
190 Generate_DebugBreakCallHelper(
191 masm, receiver.bit() | name.bit() | value.bit(), 0);
192}
193
194
195void DebugCodegen::GenerateKeyedLoadICDebugBreak(MacroAssembler* masm) {
196 // Calling convention for keyed IC load (from ic-arm.cc).
197 GenerateLoadICDebugBreak(masm);
198}
199
200
201void DebugCodegen::GenerateKeyedStoreICDebugBreak(MacroAssembler* masm) {
202 // Calling convention for IC keyed store call (from ic-arm.cc).
203 Register receiver = StoreDescriptor::ReceiverRegister();
204 Register name = StoreDescriptor::NameRegister();
205 Register value = StoreDescriptor::ValueRegister();
206 Generate_DebugBreakCallHelper(
207 masm, receiver.bit() | name.bit() | value.bit(), 0);
208}
209
210
211void DebugCodegen::GenerateCompareNilICDebugBreak(MacroAssembler* masm) {
212 // Register state for CompareNil IC
Steve Blocka7e24c12009-10-30 11:49:00 +0000213 // ----------- S t a t e -------------
Andrei Popescu402d9372010-02-26 13:31:12 +0000214 // -- r0 : value
Steve Blocka7e24c12009-10-30 11:49:00 +0000215 // -----------------------------------
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000216 Generate_DebugBreakCallHelper(masm, r0.bit(), 0);
Steve Blocka7e24c12009-10-30 11:49:00 +0000217}
218
219
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000220void DebugCodegen::GenerateReturnDebugBreak(MacroAssembler* masm) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000221 // In places other than IC call sites it is expected that r0 is TOS which
222 // is an object - this is not generally the case so this should be used with
223 // care.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100224 Generate_DebugBreakCallHelper(masm, r0.bit(), 0);
Steve Blocka7e24c12009-10-30 11:49:00 +0000225}
226
227
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000228void DebugCodegen::GenerateCallFunctionStubDebugBreak(MacroAssembler* masm) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100229 // Register state for CallFunctionStub (from code-stubs-arm.cc).
Steve Blocka7e24c12009-10-30 11:49:00 +0000230 // ----------- S t a t e -------------
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100231 // -- r1 : function
Steve Blocka7e24c12009-10-30 11:49:00 +0000232 // -----------------------------------
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100233 Generate_DebugBreakCallHelper(masm, r1.bit(), 0);
234}
235
236
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000237void DebugCodegen::GenerateCallConstructStubDebugBreak(MacroAssembler* masm) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100238 // Calling convention for CallConstructStub (from code-stubs-arm.cc)
239 // ----------- S t a t e -------------
240 // -- r0 : number of arguments (not smi)
241 // -- r1 : constructor function
242 // -----------------------------------
243 Generate_DebugBreakCallHelper(masm, r1.bit(), r0.bit());
244}
245
246
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000247void DebugCodegen::GenerateCallConstructStubRecordDebugBreak(
248 MacroAssembler* masm) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100249 // Calling convention for CallConstructStub (from code-stubs-arm.cc)
250 // ----------- S t a t e -------------
251 // -- r0 : number of arguments (not smi)
252 // -- r1 : constructor function
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000253 // -- r2 : feedback array
254 // -- r3 : feedback slot (smi)
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100255 // -----------------------------------
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000256 Generate_DebugBreakCallHelper(masm, r1.bit() | r2.bit() | r3.bit(), r0.bit());
Ben Murdoch5d4cdbf2012-04-11 10:23:59 +0100257}
258
259
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000260void DebugCodegen::GenerateSlot(MacroAssembler* masm) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100261 // Generate enough nop's to make space for a call instruction. Avoid emitting
262 // the constant pool in the debug break slot code.
263 Assembler::BlockConstPoolScope block_const_pool(masm);
264 Label check_codesize;
265 __ bind(&check_codesize);
266 __ RecordDebugBreakSlot();
267 for (int i = 0; i < Assembler::kDebugBreakSlotInstructions; i++) {
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800268 __ nop(MacroAssembler::DEBUG_BREAK_NOP);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100269 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000270 DCHECK_EQ(Assembler::kDebugBreakSlotInstructions,
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100271 masm->InstructionsGeneratedSince(&check_codesize));
272}
273
274
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000275void DebugCodegen::GenerateSlotDebugBreak(MacroAssembler* masm) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100276 // In the places where a debug break slot is inserted no registers can contain
277 // object pointers.
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100278 Generate_DebugBreakCallHelper(masm, 0, 0);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100279}
280
281
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000282void DebugCodegen::GeneratePlainReturnLiveEdit(MacroAssembler* masm) {
283 __ Ret();
Steve Block6ded16b2010-05-10 14:33:55 +0100284}
285
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100286
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000287void DebugCodegen::GenerateFrameDropperLiveEdit(MacroAssembler* masm) {
288 ExternalReference restarter_frame_function_slot =
289 ExternalReference::debug_restarter_frame_function_pointer_address(
290 masm->isolate());
291 __ mov(ip, Operand(restarter_frame_function_slot));
292 __ mov(r1, Operand::Zero());
293 __ str(r1, MemOperand(ip, 0));
294
295 // Load the function pointer off of our current stack frame.
296 __ ldr(r1, MemOperand(fp,
297 StandardFrameConstants::kConstantPoolOffset - kPointerSize));
298
299 // Pop return address, frame and constant pool pointer (if
300 // FLAG_enable_ool_constant_pool).
301 __ LeaveFrame(StackFrame::INTERNAL);
302
303 { ConstantPoolUnavailableScope constant_pool_unavailable(masm);
304 // Load context from the function.
305 __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
306
307 // Get function code.
308 __ ldr(ip, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
309 __ ldr(ip, FieldMemOperand(ip, SharedFunctionInfo::kCodeOffset));
310 __ add(ip, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
311
312 // Re-run JSFunction, r1 is function, cp is context.
313 __ Jump(ip);
314 }
Steve Block6ded16b2010-05-10 14:33:55 +0100315}
316
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000317
318const bool LiveEdit::kFrameDropperSupported = true;
Iain Merrick75681382010-08-19 15:07:18 +0100319
Steve Blocka7e24c12009-10-30 11:49:00 +0000320#undef __
321
Steve Blocka7e24c12009-10-30 11:49:00 +0000322} } // namespace v8::internal
Leon Clarkef7060e22010-06-03 12:02:55 +0100323
324#endif // V8_TARGET_ARCH_ARM