| 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" |
| 11 | 11 |
| 12 namespace v8 { | 12 namespace v8 { |
| 13 namespace internal { | 13 namespace internal { |
| 14 | 14 |
| 15 | 15 |
| 16 #define __ ACCESS_MASM(masm) | 16 #define __ ACCESS_MASM(masm) |
| 17 | 17 |
| 18 | 18 |
| 19 void Builtins::Generate_Adaptor(MacroAssembler* masm, | 19 void Builtins::Generate_Adaptor(MacroAssembler* masm, |
| 20 CFunctionId id, | 20 CFunctionId id, |
| 21 BuiltinExtraArguments extra_args) { | 21 BuiltinExtraArguments extra_args) { |
| 22 // ----------- S t a t e ------------- | 22 // ----------- S t a t e ------------- |
| 23 // -- rax : number of arguments excluding receiver | 23 // -- rax : number of arguments excluding receiver |
| 24 // -- rdi : called function (only guaranteed when | 24 // (only guaranteed when the called function |
| 25 // extra_args requires it) | 25 // is not marked as DontAdaptArguments) |
| 26 // -- rdi : called function |
| 26 // -- rsp[0] : return address | 27 // -- rsp[0] : return address |
| 27 // -- rsp[8] : last argument | 28 // -- rsp[8] : last argument |
| 28 // -- ... | 29 // -- ... |
| 29 // -- rsp[8 * argc] : first argument (argc == rax) | 30 // -- rsp[8 * argc] : first argument |
| 30 // -- rsp[8 * (argc + 1)] : receiver | 31 // -- rsp[8 * (argc + 1)] : receiver |
| 31 // ----------------------------------- | 32 // ----------------------------------- |
| 32 __ AssertFunction(rdi); | 33 __ AssertFunction(rdi); |
| 33 | 34 |
| 34 // Make sure we operate in the context of the called function (for example | 35 // Make sure we operate in the context of the called function (for example |
| 35 // ConstructStubs implemented in C++ will be run in the context of the caller | 36 // ConstructStubs implemented in C++ will be run in the context of the caller |
| 36 // instead of the callee, due to the way that [[Construct]] is defined for | 37 // instead of the callee, due to the way that [[Construct]] is defined for |
| 37 // ordinary functions). | 38 // ordinary functions). |
| 38 // TODO(bmeurer): Can we make this more robust? | 39 // TODO(bmeurer): Can we make this more robust? |
| 39 __ movp(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); | 40 __ movp(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); |
| 40 | 41 |
| 41 // Insert extra arguments. | 42 // Insert extra arguments. |
| 42 int num_extra_args = 0; | 43 int num_extra_args = 0; |
| 43 if (extra_args == NEEDS_CALLED_FUNCTION) { | 44 if (extra_args == NEEDS_CALLED_FUNCTION) { |
| 44 num_extra_args = 1; | 45 num_extra_args = 1; |
| 45 __ PopReturnAddressTo(kScratchRegister); | 46 __ PopReturnAddressTo(kScratchRegister); |
| 46 __ Push(rdi); | 47 __ Push(rdi); |
| 47 __ PushReturnAddressFrom(kScratchRegister); | 48 __ PushReturnAddressFrom(kScratchRegister); |
| 48 } else { | 49 } else { |
| 49 DCHECK(extra_args == NO_EXTRA_ARGUMENTS); | 50 DCHECK(extra_args == NO_EXTRA_ARGUMENTS); |
| 50 } | 51 } |
| 51 | 52 |
| 52 // JumpToExternalReference expects rax to contain the number of arguments | 53 // JumpToExternalReference expects rax to contain the number of arguments |
| 53 // including the receiver and the extra arguments. | 54 // including the receiver and the extra arguments. But rax is only valid |
| 55 // if the called function is marked as DontAdaptArguments, otherwise we |
| 56 // need to load the argument count from the SharedFunctionInfo. |
| 57 Label argc, done_argc; |
| 58 __ movp(rdx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); |
| 59 __ LoadSharedFunctionInfoSpecialField( |
| 60 rbx, rdx, SharedFunctionInfo::kFormalParameterCountOffset); |
| 61 __ cmpp(rbx, Immediate(SharedFunctionInfo::kDontAdaptArgumentsSentinel)); |
| 62 __ j(equal, &argc, Label::kNear); |
| 63 __ leap(rax, Operand(rbx, num_extra_args + 1)); |
| 64 __ jmp(&done_argc, Label::kNear); |
| 65 __ bind(&argc); |
| 54 __ addp(rax, Immediate(num_extra_args + 1)); | 66 __ addp(rax, Immediate(num_extra_args + 1)); |
| 67 __ bind(&done_argc); |
| 68 |
| 55 __ JumpToExternalReference(ExternalReference(id, masm->isolate()), 1); | 69 __ JumpToExternalReference(ExternalReference(id, masm->isolate()), 1); |
| 56 } | 70 } |
| 57 | 71 |
| 58 | 72 |
| 59 static void CallRuntimePassFunction( | 73 static void CallRuntimePassFunction( |
| 60 MacroAssembler* masm, Runtime::FunctionId function_id) { | 74 MacroAssembler* masm, Runtime::FunctionId function_id) { |
| 61 FrameScope scope(masm, StackFrame::INTERNAL); | 75 FrameScope scope(masm, StackFrame::INTERNAL); |
| 62 // Push a copy of the function onto the stack. | 76 // Push a copy of the function onto the stack. |
| 63 __ Push(rdi); | 77 __ Push(rdi); |
| 64 // Function is also the parameter to the runtime call. | 78 // Function is also the parameter to the runtime call. |
| (...skipping 1854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1919 __ ret(0); | 1933 __ ret(0); |
| 1920 } | 1934 } |
| 1921 | 1935 |
| 1922 | 1936 |
| 1923 #undef __ | 1937 #undef __ |
| 1924 | 1938 |
| 1925 } // namespace internal | 1939 } // namespace internal |
| 1926 } // namespace v8 | 1940 } // namespace v8 |
| 1927 | 1941 |
| 1928 #endif // V8_TARGET_ARCH_X64 | 1942 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |