1 // Copyright 2015 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 #include "src/v8.h"
6
7 #if V8_TARGET_ARCH_S390
8
9 #include "src/debug/debug.h"
10
11 #include "src/codegen.h"
12 #include "src/debug/liveedit.h"
13
14 namespace v8 {
15 namespace internal {
16
17 #define __ ACCESS_MASM(masm)
18
EmitDebugBreakSlot(MacroAssembler * masm)19 void EmitDebugBreakSlot(MacroAssembler* masm) {
20 Label check_size;
21 __ bind(&check_size);
22 // oill r3, 0
23 // oill r3, 0
24 __ nop(Assembler::DEBUG_BREAK_NOP);
25 __ nop(Assembler::DEBUG_BREAK_NOP);
26
27 // lr r0, r0 64-bit only
28 // lr r0, r0 64-bit only
29 // lr r0, r0 64-bit only
30 for (int i = 8; i < Assembler::kDebugBreakSlotLength; i += 2) {
31 __ nop();
32 }
33 DCHECK_EQ(Assembler::kDebugBreakSlotLength,
34 masm->SizeOfCodeGeneratedSince(&check_size));
35 }
36
GenerateSlot(MacroAssembler * masm,RelocInfo::Mode mode)37 void DebugCodegen::GenerateSlot(MacroAssembler* masm, RelocInfo::Mode mode) {
38 // Generate enough nop's to make space for a call instruction.
39 masm->RecordDebugBreakSlot(mode);
40 EmitDebugBreakSlot(masm);
41 }
42
ClearDebugBreakSlot(Isolate * isolate,Address pc)43 void DebugCodegen::ClearDebugBreakSlot(Isolate* isolate, Address pc) {
44 CodePatcher patcher(isolate, pc, Assembler::kDebugBreakSlotLength);
45 EmitDebugBreakSlot(patcher.masm());
46 }
47
PatchDebugBreakSlot(Isolate * isolate,Address pc,Handle<Code> code)48 void DebugCodegen::PatchDebugBreakSlot(Isolate* isolate, Address pc,
49 Handle<Code> code) {
50 DCHECK(code->is_debug_stub());
51 CodePatcher patcher(isolate, pc, Assembler::kDebugBreakSlotLength);
52 // Patch the code changing the debug break slot code from
53 //
54 // oill r3, 0
55 // oill r3, 0
56 // oill r3, 0 64-bit only
57 // lr r0, r0 64-bit only
58 //
59 // to a call to the debug break code, using a FIXED_SEQUENCE.
60 //
61 // iilf r14, <address> 6-bytes
62 // basr r14, r14A 2-bytes
63 //
64 // The 64bit sequence has an extra iihf.
65 //
66 // iihf r14, <high 32-bits address> 6-bytes
67 // iilf r14, <lower 32-bits address> 6-bytes
68 // basr r14, r14 2-bytes
69 patcher.masm()->mov(v8::internal::r14,
70 Operand(reinterpret_cast<intptr_t>(code->entry())));
71 patcher.masm()->basr(v8::internal::r14, v8::internal::r14);
72 }
73
DebugBreakSlotIsPatched(Address pc)74 bool DebugCodegen::DebugBreakSlotIsPatched(Address pc) {
75 Instr current_instr = Assembler::instr_at(pc);
76 return !Assembler::IsNop(current_instr, Assembler::DEBUG_BREAK_NOP);
77 }
78
GenerateDebugBreakStub(MacroAssembler * masm,DebugBreakCallHelperMode mode)79 void DebugCodegen::GenerateDebugBreakStub(MacroAssembler* masm,
80 DebugBreakCallHelperMode mode) {
81 __ RecordComment("Debug break");
82 {
83 FrameScope scope(masm, StackFrame::INTERNAL);
84
85 // Load padding words on stack.
86 __ LoadSmiLiteral(ip, Smi::FromInt(LiveEdit::kFramePaddingValue));
87 for (int i = 0; i < LiveEdit::kFramePaddingInitialSize; i++) {
88 __ push(ip);
89 }
90 __ LoadSmiLiteral(ip, Smi::FromInt(LiveEdit::kFramePaddingInitialSize));
91 __ push(ip);
92
93 // Push arguments for DebugBreak call.
94 if (mode == SAVE_RESULT_REGISTER) {
95 // Break on return.
96 __ push(r2);
97 } else {
98 // Non-return breaks.
99 __ Push(masm->isolate()->factory()->the_hole_value());
100 }
101 __ mov(r2, Operand(1));
102 __ mov(r3,
103 Operand(ExternalReference(
104 Runtime::FunctionForId(Runtime::kDebugBreak), masm->isolate())));
105
106 CEntryStub ceb(masm->isolate(), 1);
107 __ CallStub(&ceb);
108
109 if (FLAG_debug_code) {
110 for (int i = 0; i < kNumJSCallerSaved; i++) {
111 Register reg = {JSCallerSavedCode(i)};
112 // Do not clobber r2 if mode is SAVE_RESULT_REGISTER. It will
113 // contain return value of the function.
114 if (!(reg.is(r2) && (mode == SAVE_RESULT_REGISTER))) {
115 __ mov(reg, Operand(kDebugZapValue));
116 }
117 }
118 }
119
120 // Don't bother removing padding bytes pushed on the stack
121 // as the frame is going to be restored right away.
122
123 // Leave the internal frame.
124 }
125
126 // Now that the break point has been handled, resume normal execution by
127 // jumping to the target address intended by the caller and that was
128 // overwritten by the address of DebugBreakXXX.
129 ExternalReference after_break_target =
130 ExternalReference::debug_after_break_target_address(masm->isolate());
131 __ mov(ip, Operand(after_break_target));
132 __ LoadP(ip, MemOperand(ip));
133 __ JumpToJSEntry(ip);
134 }
135
GenerateFrameDropperLiveEdit(MacroAssembler * masm)136 void DebugCodegen::GenerateFrameDropperLiveEdit(MacroAssembler* masm) {
137 // Load the function pointer off of our current stack frame.
138 __ LoadP(r3, MemOperand(fp, FrameDropperFrameConstants::kFunctionOffset));
139
140 // Pop return address and frame
141 __ LeaveFrame(StackFrame::INTERNAL);
142
143 ParameterCount dummy(0);
144 __ FloodFunctionIfStepping(r3, no_reg, dummy, dummy);
145
146 // Load context from the function.
147 __ LoadP(cp, FieldMemOperand(r3, JSFunction::kContextOffset));
148
149 // Clear new.target as a safety measure.
150 __ LoadRoot(r5, Heap::kUndefinedValueRootIndex);
151
152 // Get function code.
153 __ LoadP(ip, FieldMemOperand(r3, JSFunction::kSharedFunctionInfoOffset));
154 __ LoadP(ip, FieldMemOperand(ip, SharedFunctionInfo::kCodeOffset));
155 __ AddP(ip, Operand(Code::kHeaderSize - kHeapObjectTag));
156
157 // Re-run JSFunction, r3 is function, cp is context.
158 __ Jump(ip);
159 }
160
161 const bool LiveEdit::kFrameDropperSupported = true;
162
163 #undef __
164 } // namespace internal
165 } // namespace v8
166
167 #endif // V8_TARGET_ARCH_S390
168