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