OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #if V8_TARGET_ARCH_X64 | 7 #if V8_TARGET_ARCH_X64 |
8 | 8 |
9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 4799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4810 __ movp(rax, prev_limit_reg); | 4810 __ movp(rax, prev_limit_reg); |
4811 __ jmp(&leave_exit_frame); | 4811 __ jmp(&leave_exit_frame); |
4812 } | 4812 } |
4813 | 4813 |
4814 | 4814 |
4815 static void CallApiFunctionStubHelper(MacroAssembler* masm, | 4815 static void CallApiFunctionStubHelper(MacroAssembler* masm, |
4816 const ParameterCount& argc, | 4816 const ParameterCount& argc, |
4817 bool return_first_arg, | 4817 bool return_first_arg, |
4818 bool call_data_undefined) { | 4818 bool call_data_undefined) { |
4819 // ----------- S t a t e ------------- | 4819 // ----------- S t a t e ------------- |
4820 // -- rax : callee | 4820 // -- rdi : callee |
4821 // -- rbx : call_data | 4821 // -- rbx : call_data |
4822 // -- rcx : holder | 4822 // -- rcx : holder |
4823 // -- rdx : api_function_address | 4823 // -- rdx : api_function_address |
4824 // -- rsi : context | 4824 // -- rsi : context |
4825 // -- rdi : number of arguments if argc is a register | 4825 // -- rax : number of arguments if argc is a register |
4826 // -- rsp[0] : return address | 4826 // -- rsp[0] : return address |
4827 // -- rsp[8] : last argument | 4827 // -- rsp[8] : last argument |
4828 // -- ... | 4828 // -- ... |
4829 // -- rsp[argc * 8] : first argument | 4829 // -- rsp[argc * 8] : first argument |
4830 // -- rsp[(argc + 1) * 8] : receiver | 4830 // -- rsp[(argc + 1) * 8] : receiver |
4831 // ----------------------------------- | 4831 // ----------------------------------- |
4832 | 4832 |
4833 Register callee = rax; | 4833 Register callee = rdi; |
4834 Register call_data = rbx; | 4834 Register call_data = rbx; |
4835 Register holder = rcx; | 4835 Register holder = rcx; |
4836 Register api_function_address = rdx; | 4836 Register api_function_address = rdx; |
4837 Register context = rsi; | 4837 Register context = rsi; |
| 4838 Register return_address = r8; |
4838 | 4839 |
4839 typedef FunctionCallbackArguments FCA; | 4840 typedef FunctionCallbackArguments FCA; |
4840 | 4841 |
4841 STATIC_ASSERT(FCA::kContextSaveIndex == 6); | 4842 STATIC_ASSERT(FCA::kContextSaveIndex == 6); |
4842 STATIC_ASSERT(FCA::kCalleeIndex == 5); | 4843 STATIC_ASSERT(FCA::kCalleeIndex == 5); |
4843 STATIC_ASSERT(FCA::kDataIndex == 4); | 4844 STATIC_ASSERT(FCA::kDataIndex == 4); |
4844 STATIC_ASSERT(FCA::kReturnValueOffset == 3); | 4845 STATIC_ASSERT(FCA::kReturnValueOffset == 3); |
4845 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2); | 4846 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2); |
4846 STATIC_ASSERT(FCA::kIsolateIndex == 1); | 4847 STATIC_ASSERT(FCA::kIsolateIndex == 1); |
4847 STATIC_ASSERT(FCA::kHolderIndex == 0); | 4848 STATIC_ASSERT(FCA::kHolderIndex == 0); |
4848 STATIC_ASSERT(FCA::kArgsLength == 7); | 4849 STATIC_ASSERT(FCA::kArgsLength == 7); |
4849 | 4850 |
4850 DCHECK(argc.is_immediate() || rdi.is(argc.reg())); | 4851 DCHECK(argc.is_immediate() || rax.is(argc.reg())); |
4851 | 4852 |
4852 if (kPointerSize == kInt64Size) { | 4853 __ PopReturnAddressTo(return_address); |
4853 // pop return address and save context | 4854 |
4854 __ xchgq(context, Operand(rsp, 0)); | 4855 // context save |
4855 } else { | 4856 __ Push(context); |
4856 // x32 handling. | |
4857 __ PopReturnAddressTo(kScratchRegister); | |
4858 __ Push(context); | |
4859 __ movq(context, kScratchRegister); | |
4860 } | |
4861 | 4857 |
4862 // callee | 4858 // callee |
4863 __ Push(callee); | 4859 __ Push(callee); |
4864 | 4860 |
4865 // call data | 4861 // call data |
4866 __ Push(call_data); | 4862 __ Push(call_data); |
4867 Register scratch = call_data; | 4863 Register scratch = call_data; |
4868 if (!call_data_undefined) { | 4864 if (!call_data_undefined) { |
4869 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); | 4865 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); |
4870 } | 4866 } |
4871 // return value | 4867 // return value |
4872 __ Push(scratch); | 4868 __ Push(scratch); |
4873 // return value default | 4869 // return value default |
4874 __ Push(scratch); | 4870 __ Push(scratch); |
4875 // isolate | 4871 // isolate |
4876 __ Move(scratch, ExternalReference::isolate_address(masm->isolate())); | 4872 __ Move(scratch, ExternalReference::isolate_address(masm->isolate())); |
4877 __ Push(scratch); | 4873 __ Push(scratch); |
4878 // holder | 4874 // holder |
4879 __ Push(holder); | 4875 __ Push(holder); |
4880 | 4876 |
4881 __ movp(scratch, rsp); | 4877 __ movp(scratch, rsp); |
4882 // Push return address back on stack. | 4878 // Push return address back on stack. |
4883 __ PushReturnAddressFrom(context); | 4879 __ PushReturnAddressFrom(return_address); |
4884 | 4880 |
4885 // load context from callee | 4881 // load context from callee |
4886 __ movp(context, FieldOperand(callee, JSFunction::kContextOffset)); | 4882 __ movp(context, FieldOperand(callee, JSFunction::kContextOffset)); |
4887 | 4883 |
4888 // Allocate the v8::Arguments structure in the arguments' space since | 4884 // Allocate the v8::Arguments structure in the arguments' space since |
4889 // it's not controlled by GC. | 4885 // it's not controlled by GC. |
4890 const int kApiStackSpace = 4; | 4886 const int kApiStackSpace = 4; |
4891 | 4887 |
4892 PrepareCallApiFunction(masm, kApiStackSpace); | 4888 PrepareCallApiFunction(masm, kApiStackSpace); |
4893 | 4889 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4947 stack_space = argc.immediate() + FCA::kArgsLength + 1; | 4943 stack_space = argc.immediate() + FCA::kArgsLength + 1; |
4948 stack_space_operand = nullptr; | 4944 stack_space_operand = nullptr; |
4949 } | 4945 } |
4950 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, callback_arg, | 4946 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, callback_arg, |
4951 stack_space, stack_space_operand, | 4947 stack_space, stack_space_operand, |
4952 return_value_operand, &context_restore_operand); | 4948 return_value_operand, &context_restore_operand); |
4953 } | 4949 } |
4954 | 4950 |
4955 | 4951 |
4956 void CallApiFunctionStub::Generate(MacroAssembler* masm) { | 4952 void CallApiFunctionStub::Generate(MacroAssembler* masm) { |
4957 // TODO(dcarney): make rax contain the function address. | |
4958 bool call_data_undefined = this->call_data_undefined(); | 4953 bool call_data_undefined = this->call_data_undefined(); |
4959 CallApiFunctionStubHelper(masm, ParameterCount(rdi), false, | 4954 CallApiFunctionStubHelper(masm, ParameterCount(rax), false, |
4960 call_data_undefined); | 4955 call_data_undefined); |
4961 } | 4956 } |
4962 | 4957 |
4963 | 4958 |
4964 void CallApiAccessorStub::Generate(MacroAssembler* masm) { | 4959 void CallApiAccessorStub::Generate(MacroAssembler* masm) { |
4965 bool is_store = this->is_store(); | 4960 bool is_store = this->is_store(); |
4966 int argc = this->argc(); | 4961 int argc = this->argc(); |
4967 bool call_data_undefined = this->call_data_undefined(); | 4962 bool call_data_undefined = this->call_data_undefined(); |
4968 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store, | 4963 CallApiFunctionStubHelper(masm, ParameterCount(argc), is_store, |
4969 call_data_undefined); | 4964 call_data_undefined); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5026 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, getter_arg, | 5021 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, getter_arg, |
5027 kStackSpace, nullptr, return_value_operand, NULL); | 5022 kStackSpace, nullptr, return_value_operand, NULL); |
5028 } | 5023 } |
5029 | 5024 |
5030 | 5025 |
5031 #undef __ | 5026 #undef __ |
5032 | 5027 |
5033 } } // namespace v8::internal | 5028 } } // namespace v8::internal |
5034 | 5029 |
5035 #endif // V8_TARGET_ARCH_X64 | 5030 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |