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 // (only guaranteed when the called function | |
25 // is not marked as DontAdaptArguments) | |
26 // -- rdi : called function | 24 // -- rdi : called function |
27 // -- rsp[0] : return address | 25 // -- rsp[0] : return address |
28 // -- rsp[8] : last argument | 26 // -- rsp[8] : last argument |
29 // -- ... | 27 // -- ... |
30 // -- rsp[8 * argc] : first argument | 28 // -- rsp[8 * argc] : first argument |
31 // -- rsp[8 * (argc + 1)] : receiver | 29 // -- rsp[8 * (argc + 1)] : receiver |
32 // ----------------------------------- | 30 // ----------------------------------- |
33 __ AssertFunction(rdi); | 31 __ AssertFunction(rdi); |
34 | 32 |
35 // Make sure we operate in the context of the called function (for example | |
36 // ConstructStubs implemented in C++ will be run in the context of the caller | |
37 // instead of the callee, due to the way that [[Construct]] is defined for | |
38 // ordinary functions). | |
39 // TODO(bmeurer): Can we make this more robust? | |
40 __ movp(rsi, FieldOperand(rdi, JSFunction::kContextOffset)); | |
41 | |
42 // Insert extra arguments. | 33 // Insert extra arguments. |
43 int num_extra_args = 0; | 34 int num_extra_args = 0; |
44 if (extra_args == NEEDS_CALLED_FUNCTION) { | 35 if (extra_args == NEEDS_CALLED_FUNCTION) { |
45 num_extra_args = 1; | 36 num_extra_args = 1; |
46 __ PopReturnAddressTo(kScratchRegister); | 37 __ PopReturnAddressTo(kScratchRegister); |
47 __ Push(rdi); | 38 __ Push(rdi); |
48 __ PushReturnAddressFrom(kScratchRegister); | 39 __ PushReturnAddressFrom(kScratchRegister); |
49 } else { | 40 } else { |
50 DCHECK(extra_args == NO_EXTRA_ARGUMENTS); | 41 DCHECK(extra_args == NO_EXTRA_ARGUMENTS); |
51 } | 42 } |
52 | 43 |
53 // JumpToExternalReference expects rax to contain the number of arguments | 44 // JumpToExternalReference expects rax to contain the number of arguments |
54 // including the receiver and the extra arguments. But rax is only valid | 45 // including the receiver and the extra arguments. |
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); | |
66 __ addp(rax, Immediate(num_extra_args + 1)); | 46 __ addp(rax, Immediate(num_extra_args + 1)); |
67 __ bind(&done_argc); | |
68 | 47 |
69 __ JumpToExternalReference(ExternalReference(id, masm->isolate()), 1); | 48 __ JumpToExternalReference(ExternalReference(id, masm->isolate()), 1); |
70 } | 49 } |
71 | 50 |
72 | 51 |
73 static void CallRuntimePassFunction( | 52 static void CallRuntimePassFunction( |
74 MacroAssembler* masm, Runtime::FunctionId function_id) { | 53 MacroAssembler* masm, Runtime::FunctionId function_id) { |
75 // ----------- S t a t e ------------- | 54 // ----------- S t a t e ------------- |
76 // -- rdx : new target (preserved for callee) | 55 // -- rdx : new target (preserved for callee) |
77 // -- rdi : target function (preserved for callee) | 56 // -- rdi : target function (preserved for callee) |
(...skipping 1983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2061 __ ret(0); | 2040 __ ret(0); |
2062 } | 2041 } |
2063 | 2042 |
2064 | 2043 |
2065 #undef __ | 2044 #undef __ |
2066 | 2045 |
2067 } // namespace internal | 2046 } // namespace internal |
2068 } // namespace v8 | 2047 } // namespace v8 |
2069 | 2048 |
2070 #endif // V8_TARGET_ARCH_X64 | 2049 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |