OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #if V8_TARGET_ARCH_X64 | 5 #if V8_TARGET_ARCH_X64 |
6 | 6 |
7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
8 #include "src/codegen.h" | 8 #include "src/codegen.h" |
9 #include "src/deoptimizer.h" | 9 #include "src/deoptimizer.h" |
10 #include "src/full-codegen/full-codegen.h" | 10 #include "src/full-codegen/full-codegen.h" |
(...skipping 2066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2077 { | 2077 { |
2078 Label no_interpreter_frame; | 2078 Label no_interpreter_frame; |
2079 __ Cmp(Operand(rbp, StandardFrameConstants::kMarkerOffset), | 2079 __ Cmp(Operand(rbp, StandardFrameConstants::kMarkerOffset), |
2080 Smi::FromInt(StackFrame::STUB)); | 2080 Smi::FromInt(StackFrame::STUB)); |
2081 __ j(not_equal, &no_interpreter_frame, Label::kNear); | 2081 __ j(not_equal, &no_interpreter_frame, Label::kNear); |
2082 __ movp(rbp, Operand(rbp, StandardFrameConstants::kCallerFPOffset)); | 2082 __ movp(rbp, Operand(rbp, StandardFrameConstants::kCallerFPOffset)); |
2083 __ bind(&no_interpreter_frame); | 2083 __ bind(&no_interpreter_frame); |
2084 } | 2084 } |
2085 | 2085 |
2086 // Check if next frame is an arguments adaptor frame. | 2086 // Check if next frame is an arguments adaptor frame. |
| 2087 Register caller_args_count_reg = scratch1; |
2087 Label no_arguments_adaptor, formal_parameter_count_loaded; | 2088 Label no_arguments_adaptor, formal_parameter_count_loaded; |
2088 __ movp(scratch2, Operand(rbp, StandardFrameConstants::kCallerFPOffset)); | 2089 __ movp(scratch2, Operand(rbp, StandardFrameConstants::kCallerFPOffset)); |
2089 __ Cmp(Operand(scratch2, StandardFrameConstants::kContextOffset), | 2090 __ Cmp(Operand(scratch2, StandardFrameConstants::kContextOffset), |
2090 Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); | 2091 Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)); |
2091 __ j(not_equal, &no_arguments_adaptor, Label::kNear); | 2092 __ j(not_equal, &no_arguments_adaptor, Label::kNear); |
2092 | 2093 |
2093 // Drop arguments adaptor frame and load arguments count. | 2094 // Drop current frame and load arguments count from arguments adaptor frame. |
2094 __ movp(rbp, scratch2); | 2095 __ movp(rbp, scratch2); |
2095 __ SmiToInteger32( | 2096 __ SmiToInteger32( |
2096 scratch1, Operand(rbp, ArgumentsAdaptorFrameConstants::kLengthOffset)); | 2097 caller_args_count_reg, |
| 2098 Operand(rbp, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
2097 __ jmp(&formal_parameter_count_loaded, Label::kNear); | 2099 __ jmp(&formal_parameter_count_loaded, Label::kNear); |
2098 | 2100 |
2099 __ bind(&no_arguments_adaptor); | 2101 __ bind(&no_arguments_adaptor); |
2100 // Load caller's formal parameter count | 2102 // Load caller's formal parameter count |
2101 __ movp(scratch1, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); | 2103 __ movp(scratch1, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset)); |
2102 __ movp(scratch1, | 2104 __ movp(scratch1, |
2103 FieldOperand(scratch1, JSFunction::kSharedFunctionInfoOffset)); | 2105 FieldOperand(scratch1, JSFunction::kSharedFunctionInfoOffset)); |
2104 __ LoadSharedFunctionInfoSpecialField( | 2106 __ LoadSharedFunctionInfoSpecialField( |
2105 scratch1, scratch1, SharedFunctionInfo::kFormalParameterCountOffset); | 2107 caller_args_count_reg, scratch1, |
| 2108 SharedFunctionInfo::kFormalParameterCountOffset); |
2106 | 2109 |
2107 __ bind(&formal_parameter_count_loaded); | 2110 __ bind(&formal_parameter_count_loaded); |
2108 | 2111 |
2109 // Calculate the destination address where we will put the return address | 2112 ParameterCount callee_args_count(args_reg); |
2110 // after we drop current frame. | 2113 __ PrepareForTailCall(callee_args_count, caller_args_count_reg, scratch2, |
2111 Register new_sp_reg = scratch2; | 2114 scratch3, ReturnAddressState::kOnStack); |
2112 __ subp(scratch1, args_reg); | |
2113 __ leap(new_sp_reg, Operand(rbp, scratch1, times_pointer_size, | |
2114 StandardFrameConstants::kCallerPCOffset)); | |
2115 | |
2116 if (FLAG_debug_code) { | |
2117 __ cmpp(rsp, new_sp_reg); | |
2118 __ Check(below, kStackAccessBelowStackPointer); | |
2119 } | |
2120 | |
2121 // Copy receiver and return address as well. | |
2122 Register count_reg = scratch1; | |
2123 __ leap(count_reg, Operand(args_reg, 2)); | |
2124 | |
2125 // Copy return address from caller's frame to current frame's return address | |
2126 // to avoid its trashing and let the following loop copy it to the right | |
2127 // place. | |
2128 Register tmp_reg = scratch3; | |
2129 __ movp(tmp_reg, Operand(rbp, StandardFrameConstants::kCallerPCOffset)); | |
2130 __ movp(Operand(rsp, 0), tmp_reg); | |
2131 | |
2132 // Restore caller's frame pointer now as it could be overwritten by | |
2133 // the copying loop. | |
2134 __ movp(rbp, Operand(rbp, StandardFrameConstants::kCallerFPOffset)); | |
2135 | |
2136 Operand src(rsp, count_reg, times_pointer_size, 0); | |
2137 Operand dst(new_sp_reg, count_reg, times_pointer_size, 0); | |
2138 | |
2139 // Now copy callee arguments to the caller frame going backwards to avoid | |
2140 // callee arguments corruption (source and destination areas could overlap). | |
2141 Label loop, entry; | |
2142 __ jmp(&entry, Label::kNear); | |
2143 __ bind(&loop); | |
2144 __ decp(count_reg); | |
2145 __ movp(tmp_reg, src); | |
2146 __ movp(dst, tmp_reg); | |
2147 __ bind(&entry); | |
2148 __ cmpp(count_reg, Immediate(0)); | |
2149 __ j(not_equal, &loop, Label::kNear); | |
2150 | |
2151 // Leave current frame. | |
2152 __ movp(rsp, new_sp_reg); | |
2153 | |
2154 __ bind(&done); | 2115 __ bind(&done); |
2155 } | 2116 } |
2156 } // namespace | 2117 } // namespace |
2157 | 2118 |
2158 // static | 2119 // static |
2159 void Builtins::Generate_CallFunction(MacroAssembler* masm, | 2120 void Builtins::Generate_CallFunction(MacroAssembler* masm, |
2160 ConvertReceiverMode mode, | 2121 ConvertReceiverMode mode, |
2161 TailCallMode tail_call_mode) { | 2122 TailCallMode tail_call_mode) { |
2162 // ----------- S t a t e ------------- | 2123 // ----------- S t a t e ------------- |
2163 // -- rax : the number of arguments (not including the receiver) | 2124 // -- rax : the number of arguments (not including the receiver) |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2743 __ ret(0); | 2704 __ ret(0); |
2744 } | 2705 } |
2745 | 2706 |
2746 | 2707 |
2747 #undef __ | 2708 #undef __ |
2748 | 2709 |
2749 } // namespace internal | 2710 } // namespace internal |
2750 } // namespace v8 | 2711 } // namespace v8 |
2751 | 2712 |
2752 #endif // V8_TARGET_ARCH_X64 | 2713 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |