Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(953)

Side by Side Diff: src/x64/builtins-x64.cc

Issue 114085: X64: Implement CEntryStub and JSEntryTrampoline. (Closed)
Patch Set: Addressed review comments Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include "v8.h" 28 #include "v8.h"
29 #include "codegen-inl.h" 29 #include "codegen-inl.h"
30 #include "macro-assembler.h"
30 31
31 namespace v8 { 32 namespace v8 {
32 namespace internal { 33 namespace internal {
33 34
35 #define __ ACCESS_MASM(masm)
36
34 void Builtins::Generate_Adaptor(MacroAssembler* masm, 37 void Builtins::Generate_Adaptor(MacroAssembler* masm,
35 Builtins::CFunctionId id) { 38 Builtins::CFunctionId id) {
36 masm->int3(); // UNIMPLEMENTED. 39 masm->int3(); // UNIMPLEMENTED.
37 } 40 }
38 41
39 void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) { 42 void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
40 masm->int3(); // UNIMPLEMENTED. 43 masm->int3(); // UNIMPLEMENTED.
41 } 44 }
42 45
43 void Builtins::Generate_FunctionApply(MacroAssembler* masm) { 46 void Builtins::Generate_FunctionApply(MacroAssembler* masm) {
44 masm->int3(); // UNIMPLEMENTED. 47 masm->int3(); // UNIMPLEMENTED.
45 } 48 }
46 49
47 void Builtins::Generate_FunctionCall(MacroAssembler* masm) { 50 void Builtins::Generate_FunctionCall(MacroAssembler* masm) {
48 masm->int3(); // UNIMPLEMENTED. 51 masm->int3(); // UNIMPLEMENTED.
49 } 52 }
50 53
51 void Builtins::Generate_JSConstructCall(MacroAssembler* masm) { 54 void Builtins::Generate_JSConstructCall(MacroAssembler* masm) {
52 masm->int3(); // UNIMPLEMENTED. 55 masm->int3(); // UNIMPLEMENTED.
53 } 56 }
54 57
55 void Builtins::Generate_JSConstructEntryTrampoline(MacroAssembler* masm) { 58 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm,
56 masm->int3(); // UNIMPLEMENTED. 59 bool is_construct) {
60 // Expects five C++ function parameters.
61 // - Address entry (ignored)
62 // - JSFunction* function (
63 // - Object* receiver
64 // - int argc
65 // - Object*** argv
66 // (see Handle::Invoke in execution.cc).
67
68 // Platform specific argument handling. After this, the stack contains
69 // an internal frame and the pushed function and receiver, and
70 // register rax and rbx holds the argument count and argument array,
71 // while rdi holds the function pointer and rsi the context.
72 #ifdef __MSVC__
73 // MSVC parameters in:
74 // rcx : entry (ignored)
75 // rdx : function
76 // r8 : receiver
77 // r9 : argc
78 // [rsp+0x20] : argv
79
80 // Clear the context before we push it when entering the JS frame.
81 __ xor_(rsi, rsi);
82 // Enter an internal frame.
83 __ EnterInternalFrame();
84
85 // Load the previous frame pointer to access C argument on stack
86 __ movq(kScratchRegister, Operand(rbp, 0));
87
88 // Load the function context into rsi.
89 __ movq(rsi, FieldOperand(rdx, JSFunction::kContextOffset));
90
91 // Push the function and the receiver onto the stack.
92 __ push(rdx);
93 __ push(r8);
94
95 // Load the number of arguments and setup pointer to the arguments.
96 __ movq(rax, r9);
97 __ movq(rbx, Operand(kScratchRegister, EntryFrameConstants::kArgvOffset));
98 // Load the function pointer into rdi.
99 __ movq(rdi, rdx);
100 #else // !defined(__MSVC__)
101 // GCC parameters in:
102 // rdi : entry (ignored)
103 // rsi : function
104 // rdx : receiver
105 // rcx : argc
106 // r8 : argv
107
108 __ movq(rdi, rsi);
109 // rdi : function
110
111 // Clear the context before we push it when entering the JS frame.
112 __ xor_(rsi, rsi);
113 // Enter an internal frame.
114 __ EnterInternalFrame();
115
116 // Push the function and receiver and setup the context.
117 __ push(rdi);
118 __ push(rdx);
119 __ movq(rsi, FieldOperand(rdi, JSFunction::kContextOffset));
120
121 // Load the number of arguments and setup pointer to the arguments.
122 __ movq(rax, rcx);
123 __ movq(rbx, r8);
124 #endif // __MSVC__
125 // Current stack contents:
126 // [rsp + 2 * kPointerSize ... ]: Internal frame
127 // [rsp + kPointerSize] : function
128 // [rsp] : receiver
129 // Current register contents:
130 // rax : argc
131 // rbx : argv
132 // rsi : context
133 // rdi : function
134
135 // Copy arguments to the stack in a loop.
136 // Register rbx points to array of pointers to handle locations.
137 // Push the values of these handles.
138 Label loop, entry;
139 __ xor_(rcx, rcx); // Set loop variable to 0.
140 __ jmp(&entry);
141 __ bind(&loop);
142 __ movq(kScratchRegister, Operand(rbx, rcx, kTimesPointerSize, 0));
143 __ push(Operand(kScratchRegister, 0)); // dereference handle
144 __ add(rcx, Immediate(1));
145 __ bind(&entry);
146 __ cmp(rcx, rax);
147 __ j(not_equal, &loop);
148
149 // Invoke the code.
150 if (is_construct) {
151 // Expects rdi to hold function pointer.
152 __ movq(kScratchRegister,
153 Handle<Code>(Builtins::builtin(Builtins::JSConstructCall)),
154 RelocInfo::CODE_TARGET);
155 __ call(kScratchRegister);
156 } else {
157 ParameterCount actual(rax);
158 __ InvokeFunction(rdi, actual, CALL_FUNCTION);
159 }
160
161 // Exit the JS frame. Notice that this also removes the empty
162 // context and the function left on the stack by the code
163 // invocation.
164 __ LeaveInternalFrame();
165 // TODO(X64): Is argument correct? Is there a receiver to remove?
166 __ ret(1 * kPointerSize); // remove receiver
57 } 167 }
58 168
169
59 void Builtins::Generate_JSEntryTrampoline(MacroAssembler* masm) { 170 void Builtins::Generate_JSEntryTrampoline(MacroAssembler* masm) {
60 masm->int3(); // UNIMPLEMENTED. 171 Generate_JSEntryTrampolineHelper(masm, false);
172 }
173
174
175 void Builtins::Generate_JSConstructEntryTrampoline(MacroAssembler* masm) {
176 Generate_JSEntryTrampolineHelper(masm, true);
61 } 177 }
62 178
63 } } // namespace v8::internal 179 } } // namespace v8::internal
64 180
65 181
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698