OLD | NEW |
| (Empty) |
1 // 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 | |
6 | |
7 #include "src/v8.h" | |
8 | |
9 #if V8_TARGET_ARCH_MIPS64 | |
10 | |
11 #include "src/codegen.h" | |
12 #include "src/debug.h" | |
13 | |
14 namespace v8 { | |
15 namespace internal { | |
16 | |
17 #define __ ACCESS_MASM(masm) | |
18 | |
19 void EmitDebugBreakSlot(MacroAssembler* masm) { | |
20 Label check_size; | |
21 __ bind(&check_size); | |
22 for (int i = 0; i < Assembler::kDebugBreakSlotInstructions; i++) { | |
23 __ nop(MacroAssembler::DEBUG_BREAK_NOP); | |
24 } | |
25 DCHECK_EQ(Assembler::kDebugBreakSlotInstructions, | |
26 masm->InstructionsGeneratedSince(&check_size)); | |
27 } | |
28 | |
29 | |
30 void DebugCodegen::GenerateSlot(MacroAssembler* masm, RelocInfo::Mode mode, | |
31 int call_argc) { | |
32 // Generate enough nop's to make space for a call instruction. Avoid emitting | |
33 // the trampoline pool in the debug break slot code. | |
34 Assembler::BlockTrampolinePoolScope block_pool(masm); | |
35 masm->RecordDebugBreakSlot(mode, call_argc); | |
36 EmitDebugBreakSlot(masm); | |
37 } | |
38 | |
39 | |
40 void DebugCodegen::ClearDebugBreakSlot(Address pc) { | |
41 CodePatcher patcher(pc, Assembler::kDebugBreakSlotInstructions); | |
42 EmitDebugBreakSlot(patcher.masm()); | |
43 } | |
44 | |
45 | |
46 void DebugCodegen::PatchDebugBreakSlot(Address pc, Handle<Code> code) { | |
47 DCHECK_EQ(Code::BUILTIN, code->kind()); | |
48 CodePatcher patcher(pc, Assembler::kDebugBreakSlotInstructions); | |
49 // Patch the code changing the debug break slot code from: | |
50 // nop(DEBUG_BREAK_NOP) - nop(1) is sll(zero_reg, zero_reg, 1) | |
51 // nop(DEBUG_BREAK_NOP) | |
52 // nop(DEBUG_BREAK_NOP) | |
53 // nop(DEBUG_BREAK_NOP) | |
54 // nop(DEBUG_BREAK_NOP) | |
55 // nop(DEBUG_BREAK_NOP) | |
56 // to a call to the debug break slot code. | |
57 // li t9, address (4-instruction sequence on mips64) | |
58 // call t9 (jalr t9 / nop instruction pair) | |
59 patcher.masm()->li(v8::internal::t9, | |
60 Operand(reinterpret_cast<int64_t>(code->entry())), | |
61 ADDRESS_LOAD); | |
62 patcher.masm()->Call(v8::internal::t9); | |
63 } | |
64 | |
65 | |
66 void DebugCodegen::GenerateDebugBreakStub(MacroAssembler* masm, | |
67 DebugBreakCallHelperMode mode) { | |
68 __ RecordComment("Debug break"); | |
69 { | |
70 FrameScope scope(masm, StackFrame::INTERNAL); | |
71 | |
72 // Load padding words on stack. | |
73 __ li(at, Operand(Smi::FromInt(LiveEdit::kFramePaddingValue))); | |
74 __ Dsubu(sp, sp, | |
75 Operand(kPointerSize * LiveEdit::kFramePaddingInitialSize)); | |
76 for (int i = LiveEdit::kFramePaddingInitialSize - 1; i >= 0; i--) { | |
77 __ sd(at, MemOperand(sp, kPointerSize * i)); | |
78 } | |
79 __ li(at, Operand(Smi::FromInt(LiveEdit::kFramePaddingInitialSize))); | |
80 __ push(at); | |
81 | |
82 if (mode == SAVE_RESULT_REGISTER) __ push(v0); | |
83 | |
84 __ PrepareCEntryArgs(0); // No arguments. | |
85 __ PrepareCEntryFunction(ExternalReference( | |
86 Runtime::FunctionForId(Runtime::kDebugBreak), masm->isolate())); | |
87 | |
88 CEntryStub ceb(masm->isolate(), 1); | |
89 __ CallStub(&ceb); | |
90 | |
91 if (FLAG_debug_code) { | |
92 for (int i = 0; i < kNumJSCallerSaved; i++) { | |
93 Register reg = {JSCallerSavedCode(i)}; | |
94 __ li(reg, kDebugZapValue); | |
95 } | |
96 } | |
97 | |
98 if (mode == SAVE_RESULT_REGISTER) __ pop(v0); | |
99 | |
100 // Don't bother removing padding bytes pushed on the stack | |
101 // as the frame is going to be restored right away. | |
102 | |
103 // Leave the internal frame. | |
104 } | |
105 | |
106 // Now that the break point has been handled, resume normal execution by | |
107 // jumping to the target address intended by the caller and that was | |
108 // overwritten by the address of DebugBreakXXX. | |
109 ExternalReference after_break_target = | |
110 ExternalReference::debug_after_break_target_address(masm->isolate()); | |
111 __ li(t9, Operand(after_break_target)); | |
112 __ ld(t9, MemOperand(t9)); | |
113 __ Jump(t9); | |
114 } | |
115 | |
116 | |
117 void DebugCodegen::GeneratePlainReturnLiveEdit(MacroAssembler* masm) { | |
118 __ Ret(); | |
119 } | |
120 | |
121 | |
122 void DebugCodegen::GenerateFrameDropperLiveEdit(MacroAssembler* masm) { | |
123 ExternalReference restarter_frame_function_slot = | |
124 ExternalReference::debug_restarter_frame_function_pointer_address( | |
125 masm->isolate()); | |
126 __ li(at, Operand(restarter_frame_function_slot)); | |
127 __ sw(zero_reg, MemOperand(at, 0)); | |
128 | |
129 // We do not know our frame height, but set sp based on fp. | |
130 __ Dsubu(sp, fp, Operand(kPointerSize)); | |
131 | |
132 __ Pop(ra, fp, a1); // Return address, Frame, Function. | |
133 | |
134 // Load context from the function. | |
135 __ ld(cp, FieldMemOperand(a1, JSFunction::kContextOffset)); | |
136 | |
137 // Get function code. | |
138 __ ld(at, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset)); | |
139 __ ld(at, FieldMemOperand(at, SharedFunctionInfo::kCodeOffset)); | |
140 __ Daddu(t9, at, Operand(Code::kHeaderSize - kHeapObjectTag)); | |
141 | |
142 // Re-run JSFunction, a1 is function, cp is context. | |
143 __ Jump(t9); | |
144 } | |
145 | |
146 | |
147 const bool LiveEdit::kFrameDropperSupported = true; | |
148 | |
149 #undef __ | |
150 | |
151 } // namespace internal | |
152 } // namespace v8 | |
153 | |
154 #endif // V8_TARGET_ARCH_MIPS64 | |
OLD | NEW |