blob: 09f4d59e356c0b8fe83fadc09f8de16b9b8e4e94 [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2012 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Andrei Popescu31002712010-02-23 13:46:05 +00004
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005#if V8_TARGET_ARCH_MIPS
Leon Clarkef7060e22010-06-03 12:02:55 +01006
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007#include "src/codegen.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008#include "src/debug/debug.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009#include "src/deoptimizer.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010#include "src/full-codegen/full-codegen.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040011#include "src/runtime/runtime.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000012
Andrei Popescu31002712010-02-23 13:46:05 +000013
14namespace v8 {
15namespace internal {
16
17
18#define __ ACCESS_MASM(masm)
19
20
21void Builtins::Generate_Adaptor(MacroAssembler* masm,
22 CFunctionId id,
23 BuiltinExtraArguments extra_args) {
Ben Murdoch257744e2011-11-30 15:57:28 +000024 // ----------- S t a t e -------------
25 // -- a0 : number of arguments excluding receiver
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000026 // -- a1 : target
27 // -- a3 : new.target
Ben Murdoch257744e2011-11-30 15:57:28 +000028 // -- sp[0] : last argument
29 // -- ...
30 // -- sp[4 * (argc - 1)] : first argument
31 // -- sp[4 * agrc] : receiver
32 // -----------------------------------
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000033 __ AssertFunction(a1);
34
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 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +000040
41 // Insert extra arguments.
42 int num_extra_args = 0;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000043 switch (extra_args) {
44 case BuiltinExtraArguments::kTarget:
45 __ Push(a1);
46 ++num_extra_args;
47 break;
48 case BuiltinExtraArguments::kNewTarget:
49 __ Push(a3);
50 ++num_extra_args;
51 break;
52 case BuiltinExtraArguments::kTargetAndNewTarget:
53 __ Push(a1, a3);
54 num_extra_args += 2;
55 break;
56 case BuiltinExtraArguments::kNone:
57 break;
Ben Murdoch257744e2011-11-30 15:57:28 +000058 }
59
Emily Bernierd0a1eb72015-03-24 16:35:39 -040060 // JumpToExternalReference expects a0 to contain the number of arguments
Ben Murdoch257744e2011-11-30 15:57:28 +000061 // including the receiver and the extra arguments.
Emily Bernierd0a1eb72015-03-24 16:35:39 -040062 __ Addu(a0, a0, num_extra_args + 1);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000063
Ben Murdoch257744e2011-11-30 15:57:28 +000064 __ JumpToExternalReference(ExternalReference(id, masm->isolate()));
65}
66
67
Ben Murdoch3ef787d2012-04-12 10:51:47 +010068// Load the built-in InternalArray function from the current context.
69static void GenerateLoadInternalArrayFunction(MacroAssembler* masm,
70 Register result) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000071 // Load the InternalArray function from the native context.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000072 __ LoadNativeContextSlot(Context::INTERNAL_ARRAY_FUNCTION_INDEX, result);
Ben Murdoch3ef787d2012-04-12 10:51:47 +010073}
74
75
Ben Murdoch257744e2011-11-30 15:57:28 +000076// Load the built-in Array function from the current context.
77static void GenerateLoadArrayFunction(MacroAssembler* masm, Register result) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000078 // Load the Array function from the native context.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000079 __ LoadNativeContextSlot(Context::ARRAY_FUNCTION_INDEX, result);
Ben Murdoch257744e2011-11-30 15:57:28 +000080}
81
82
Ben Murdoch3ef787d2012-04-12 10:51:47 +010083void Builtins::Generate_InternalArrayCode(MacroAssembler* masm) {
84 // ----------- S t a t e -------------
85 // -- a0 : number of arguments
86 // -- ra : return address
87 // -- sp[...]: constructor arguments
88 // -----------------------------------
89 Label generic_array_code, one_or_more_arguments, two_or_more_arguments;
90
91 // Get the InternalArray function.
92 GenerateLoadInternalArrayFunction(masm, a1);
93
94 if (FLAG_debug_code) {
95 // Initial map for the builtin InternalArray functions should be maps.
96 __ lw(a2, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +000097 __ SmiTst(a2, t0);
98 __ Assert(ne, kUnexpectedInitialMapForInternalArrayFunction,
Ben Murdoch3ef787d2012-04-12 10:51:47 +010099 t0, Operand(zero_reg));
100 __ GetObjectType(a2, a3, t0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000101 __ Assert(eq, kUnexpectedInitialMapForInternalArrayFunction,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100102 t0, Operand(MAP_TYPE));
103 }
104
105 // Run the native code for the InternalArray function called as a normal
106 // function.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000107 // Tail call a stub.
108 InternalArrayConstructorStub stub(masm->isolate());
109 __ TailCallStub(&stub);
Andrei Popescu31002712010-02-23 13:46:05 +0000110}
111
112
113void Builtins::Generate_ArrayCode(MacroAssembler* masm) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000114 // ----------- S t a t e -------------
115 // -- a0 : number of arguments
116 // -- ra : return address
117 // -- sp[...]: constructor arguments
118 // -----------------------------------
119 Label generic_array_code;
120
121 // Get the Array function.
122 GenerateLoadArrayFunction(masm, a1);
123
124 if (FLAG_debug_code) {
125 // Initial map for the builtin Array functions should be maps.
126 __ lw(a2, FieldMemOperand(a1, JSFunction::kPrototypeOrInitialMapOffset));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000127 __ SmiTst(a2, t0);
128 __ Assert(ne, kUnexpectedInitialMapForArrayFunction1,
Ben Murdoch257744e2011-11-30 15:57:28 +0000129 t0, Operand(zero_reg));
130 __ GetObjectType(a2, a3, t0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000131 __ Assert(eq, kUnexpectedInitialMapForArrayFunction2,
Ben Murdoch257744e2011-11-30 15:57:28 +0000132 t0, Operand(MAP_TYPE));
133 }
134
135 // Run the native code for the Array function called as a normal function.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000136 // Tail call a stub.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000137 __ mov(a3, a1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000138 __ LoadRoot(a2, Heap::kUndefinedValueRootIndex);
139 ArrayConstructorStub stub(masm->isolate());
140 __ TailCallStub(&stub);
Andrei Popescu31002712010-02-23 13:46:05 +0000141}
142
143
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000144// static
Ben Murdoch097c5b22016-05-18 11:27:45 +0100145void Builtins::Generate_MathMaxMin(MacroAssembler* masm, MathMaxMinKind kind) {
146 // ----------- S t a t e -------------
147 // -- a0 : number of arguments
148 // -- ra : return address
149 // -- sp[(argc - n) * 8] : arg[n] (zero-based)
150 // -- sp[(argc + 1) * 8] : receiver
151 // -----------------------------------
152 Condition const cc = (kind == MathMaxMinKind::kMin) ? ge : le;
153 Heap::RootListIndex const root_index =
154 (kind == MathMaxMinKind::kMin) ? Heap::kInfinityValueRootIndex
155 : Heap::kMinusInfinityValueRootIndex;
156 DoubleRegister const reg = (kind == MathMaxMinKind::kMin) ? f2 : f0;
157
158 // Load the accumulator with the default return value (either -Infinity or
159 // +Infinity), with the tagged value in a1 and the double value in f0.
160 __ LoadRoot(a1, root_index);
161 __ ldc1(f0, FieldMemOperand(a1, HeapNumber::kValueOffset));
162 __ mov(a3, a0);
163
164 Label done_loop, loop;
165 __ bind(&loop);
166 {
167 // Check if all parameters done.
168 __ Subu(a0, a0, Operand(1));
169 __ Branch(&done_loop, lt, a0, Operand(zero_reg));
170
171 // Load the next parameter tagged value into a2.
172 __ Lsa(at, sp, a0, kPointerSizeLog2);
173 __ lw(a2, MemOperand(at));
174
175 // Load the double value of the parameter into f2, maybe converting the
176 // parameter to a number first using the ToNumberStub if necessary.
177 Label convert, convert_smi, convert_number, done_convert;
178 __ bind(&convert);
179 __ JumpIfSmi(a2, &convert_smi);
180 __ lw(t0, FieldMemOperand(a2, HeapObject::kMapOffset));
181 __ JumpIfRoot(t0, Heap::kHeapNumberMapRootIndex, &convert_number);
182 {
183 // Parameter is not a Number, use the ToNumberStub to convert it.
184 FrameScope scope(masm, StackFrame::INTERNAL);
185 __ SmiTag(a0);
186 __ SmiTag(a3);
187 __ Push(a0, a1, a3);
188 __ mov(a0, a2);
189 ToNumberStub stub(masm->isolate());
190 __ CallStub(&stub);
191 __ mov(a2, v0);
192 __ Pop(a0, a1, a3);
193 {
194 // Restore the double accumulator value (f0).
195 Label restore_smi, done_restore;
196 __ JumpIfSmi(a1, &restore_smi);
197 __ ldc1(f0, FieldMemOperand(a1, HeapNumber::kValueOffset));
198 __ jmp(&done_restore);
199 __ bind(&restore_smi);
200 __ SmiToDoubleFPURegister(a1, f0, t0);
201 __ bind(&done_restore);
202 }
203 __ SmiUntag(a3);
204 __ SmiUntag(a0);
205 }
206 __ jmp(&convert);
207 __ bind(&convert_number);
208 __ ldc1(f2, FieldMemOperand(a2, HeapNumber::kValueOffset));
209 __ jmp(&done_convert);
210 __ bind(&convert_smi);
211 __ SmiToDoubleFPURegister(a2, f2, t0);
212 __ bind(&done_convert);
213
214 // Perform the actual comparison with the accumulator value on the left hand
215 // side (f0) and the next parameter value on the right hand side (f2).
216 Label compare_equal, compare_nan, compare_swap;
217 __ BranchF(&compare_equal, &compare_nan, eq, f0, f2);
218 __ BranchF(&compare_swap, nullptr, cc, f0, f2);
219 __ Branch(&loop);
220
221 // Left and right hand side are equal, check for -0 vs. +0.
222 __ bind(&compare_equal);
223 __ FmoveHigh(t0, reg);
224 __ Branch(&loop, ne, t0, Operand(0x80000000));
225
226 // Result is on the right hand side.
227 __ bind(&compare_swap);
228 __ mov_d(f0, f2);
229 __ mov(a1, a2);
230 __ jmp(&loop);
231
232 // At least one side is NaN, which means that the result will be NaN too.
233 __ bind(&compare_nan);
234 __ LoadRoot(a1, Heap::kNanValueRootIndex);
235 __ ldc1(f0, FieldMemOperand(a1, HeapNumber::kValueOffset));
236 __ jmp(&loop);
237 }
238
239 __ bind(&done_loop);
240 __ Lsa(sp, sp, a3, kPointerSizeLog2);
241 __ mov(v0, a1);
242 __ DropAndRet(1);
243}
244
245// static
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000246void Builtins::Generate_NumberConstructor(MacroAssembler* masm) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000247 // ----------- S t a t e -------------
248 // -- a0 : number of arguments
249 // -- a1 : constructor function
250 // -- ra : return address
251 // -- sp[(argc - n - 1) * 4] : arg[n] (zero based)
252 // -- sp[argc * 4] : receiver
253 // -----------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +0000254
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000255 // 1. Load the first argument into a0 and get rid of the rest (including the
256 // receiver).
257 Label no_arguments;
258 {
259 __ Branch(USE_DELAY_SLOT, &no_arguments, eq, a0, Operand(zero_reg));
260 __ Subu(a0, a0, Operand(1));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100261 __ Lsa(sp, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000262 __ lw(a0, MemOperand(sp));
263 __ Drop(2);
Ben Murdoch257744e2011-11-30 15:57:28 +0000264 }
265
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000266 // 2a. Convert first argument to number.
267 ToNumberStub stub(masm->isolate());
268 __ TailCallStub(&stub);
Ben Murdoch257744e2011-11-30 15:57:28 +0000269
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000270 // 2b. No arguments, return +0.
271 __ bind(&no_arguments);
272 __ Move(v0, Smi::FromInt(0));
273 __ DropAndRet(1);
274}
Ben Murdoch257744e2011-11-30 15:57:28 +0000275
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000276
277// static
278void Builtins::Generate_NumberConstructor_ConstructStub(MacroAssembler* masm) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000279 // ----------- S t a t e -------------
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000280 // -- a0 : number of arguments
281 // -- a1 : constructor function
282 // -- a3 : new target
283 // -- ra : return address
284 // -- sp[(argc - n - 1) * 4] : arg[n] (zero based)
285 // -- sp[argc * 4] : receiver
Ben Murdoch257744e2011-11-30 15:57:28 +0000286 // -----------------------------------
287
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000288 // 1. Make sure we operate in the context of the called function.
289 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +0000290
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000291 // 2. Load the first argument into a0 and get rid of the rest (including the
292 // receiver).
293 {
294 Label no_arguments, done;
295 __ Branch(USE_DELAY_SLOT, &no_arguments, eq, a0, Operand(zero_reg));
296 __ Subu(a0, a0, Operand(1));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100297 __ Lsa(sp, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000298 __ lw(a0, MemOperand(sp));
299 __ Drop(2);
300 __ jmp(&done);
301 __ bind(&no_arguments);
302 __ Move(a0, Smi::FromInt(0));
303 __ Drop(1);
304 __ bind(&done);
Ben Murdoch257744e2011-11-30 15:57:28 +0000305 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000306
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000307 // 3. Make sure a0 is a number.
308 {
309 Label done_convert;
310 __ JumpIfSmi(a0, &done_convert);
311 __ GetObjectType(a0, a2, a2);
312 __ Branch(&done_convert, eq, a2, Operand(HEAP_NUMBER_TYPE));
313 {
314 FrameScope scope(masm, StackFrame::INTERNAL);
315 __ Push(a1, a3);
316 ToNumberStub stub(masm->isolate());
317 __ CallStub(&stub);
318 __ Move(a0, v0);
319 __ Pop(a1, a3);
320 }
321 __ bind(&done_convert);
322 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000323
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000324 // 4. Check if new target and constructor differ.
325 Label new_object;
326 __ Branch(&new_object, ne, a1, Operand(a3));
Ben Murdoch257744e2011-11-30 15:57:28 +0000327
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000328 // 5. Allocate a JSValue wrapper for the number.
329 __ AllocateJSValue(v0, a1, a0, a2, t0, &new_object);
Ben Murdoch257744e2011-11-30 15:57:28 +0000330 __ Ret();
331
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000332 // 6. Fallback to the runtime to create new object.
333 __ bind(&new_object);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100334 {
335 FrameScope scope(masm, StackFrame::INTERNAL);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100336 __ Push(a0); // first argument
337 FastNewObjectStub stub(masm->isolate());
338 __ CallStub(&stub);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000339 __ Pop(a0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100340 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000341 __ Ret(USE_DELAY_SLOT);
342 __ sw(a0, FieldMemOperand(v0, JSValue::kValueOffset)); // In delay slot
343}
Ben Murdoch257744e2011-11-30 15:57:28 +0000344
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000345
346// static
347void Builtins::Generate_StringConstructor(MacroAssembler* masm) {
348 // ----------- S t a t e -------------
349 // -- a0 : number of arguments
350 // -- a1 : constructor function
351 // -- ra : return address
352 // -- sp[(argc - n - 1) * 4] : arg[n] (zero based)
353 // -- sp[argc * 4] : receiver
354 // -----------------------------------
355
356 // 1. Load the first argument into a0 and get rid of the rest (including the
357 // receiver).
358 Label no_arguments;
359 {
360 __ Branch(USE_DELAY_SLOT, &no_arguments, eq, a0, Operand(zero_reg));
361 __ Subu(a0, a0, Operand(1));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100362 __ Lsa(sp, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000363 __ lw(a0, MemOperand(sp));
364 __ Drop(2);
365 }
366
367 // 2a. At least one argument, return a0 if it's a string, otherwise
368 // dispatch to appropriate conversion.
369 Label to_string, symbol_descriptive_string;
370 {
371 __ JumpIfSmi(a0, &to_string);
372 __ GetObjectType(a0, a1, a1);
373 STATIC_ASSERT(FIRST_NONSTRING_TYPE == SYMBOL_TYPE);
374 __ Subu(a1, a1, Operand(FIRST_NONSTRING_TYPE));
375 __ Branch(&symbol_descriptive_string, eq, a1, Operand(zero_reg));
376 __ Branch(&to_string, gt, a1, Operand(zero_reg));
377 __ Ret(USE_DELAY_SLOT);
378 __ mov(v0, a0);
379 }
380
381 // 2b. No arguments, return the empty string (and pop the receiver).
Ben Murdoch257744e2011-11-30 15:57:28 +0000382 __ bind(&no_arguments);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000383 {
384 __ LoadRoot(v0, Heap::kempty_stringRootIndex);
385 __ DropAndRet(1);
386 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000387
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000388 // 3a. Convert a0 to a string.
389 __ bind(&to_string);
390 {
391 ToStringStub stub(masm->isolate());
392 __ TailCallStub(&stub);
393 }
394
395 // 3b. Convert symbol in a0 to a string.
396 __ bind(&symbol_descriptive_string);
397 {
398 __ Push(a0);
399 __ TailCallRuntime(Runtime::kSymbolDescriptiveString);
400 }
401}
402
403
404// static
405void Builtins::Generate_StringConstructor_ConstructStub(MacroAssembler* masm) {
406 // ----------- S t a t e -------------
407 // -- a0 : number of arguments
408 // -- a1 : constructor function
409 // -- a3 : new target
410 // -- ra : return address
411 // -- sp[(argc - n - 1) * 4] : arg[n] (zero based)
412 // -- sp[argc * 4] : receiver
413 // -----------------------------------
414
415 // 1. Make sure we operate in the context of the called function.
416 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
417
418 // 2. Load the first argument into a0 and get rid of the rest (including the
419 // receiver).
420 {
421 Label no_arguments, done;
422 __ Branch(USE_DELAY_SLOT, &no_arguments, eq, a0, Operand(zero_reg));
423 __ Subu(a0, a0, Operand(1));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100424 __ Lsa(sp, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000425 __ lw(a0, MemOperand(sp));
426 __ Drop(2);
427 __ jmp(&done);
428 __ bind(&no_arguments);
429 __ LoadRoot(a0, Heap::kempty_stringRootIndex);
430 __ Drop(1);
431 __ bind(&done);
432 }
433
434 // 3. Make sure a0 is a string.
435 {
436 Label convert, done_convert;
437 __ JumpIfSmi(a0, &convert);
438 __ GetObjectType(a0, a2, a2);
439 __ And(t0, a2, Operand(kIsNotStringMask));
440 __ Branch(&done_convert, eq, t0, Operand(zero_reg));
441 __ bind(&convert);
442 {
443 FrameScope scope(masm, StackFrame::INTERNAL);
444 ToStringStub stub(masm->isolate());
445 __ Push(a1, a3);
446 __ CallStub(&stub);
447 __ Move(a0, v0);
448 __ Pop(a1, a3);
449 }
450 __ bind(&done_convert);
451 }
452
453 // 4. Check if new target and constructor differ.
454 Label new_object;
455 __ Branch(&new_object, ne, a1, Operand(a3));
456
457 // 5. Allocate a JSValue wrapper for the string.
458 __ AllocateJSValue(v0, a1, a0, a2, t0, &new_object);
459 __ Ret();
460
461 // 6. Fallback to the runtime to create new object.
462 __ bind(&new_object);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100463 {
464 FrameScope scope(masm, StackFrame::INTERNAL);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100465 __ Push(a0); // first argument
466 FastNewObjectStub stub(masm->isolate());
467 __ CallStub(&stub);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000468 __ Pop(a0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100469 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000470 __ Ret(USE_DELAY_SLOT);
471 __ sw(a0, FieldMemOperand(v0, JSValue::kValueOffset)); // In delay slot
Steve Block44f0eee2011-05-26 01:26:41 +0100472}
473
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000474static void GenerateTailCallToSharedCode(MacroAssembler* masm) {
475 __ lw(a2, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
476 __ lw(a2, FieldMemOperand(a2, SharedFunctionInfo::kCodeOffset));
477 __ Addu(at, a2, Operand(Code::kHeaderSize - kHeapObjectTag));
478 __ Jump(at);
479}
480
Ben Murdoch097c5b22016-05-18 11:27:45 +0100481static void GenerateTailCallToReturnedCode(MacroAssembler* masm,
482 Runtime::FunctionId function_id) {
483 // ----------- S t a t e -------------
484 // -- a0 : argument count (preserved for callee)
485 // -- a1 : target function (preserved for callee)
486 // -- a3 : new target (preserved for callee)
487 // -----------------------------------
488 {
489 FrameScope scope(masm, StackFrame::INTERNAL);
490 // Push a copy of the target function and the new target.
491 // Push function as parameter to the runtime call.
492 __ SmiTag(a0);
493 __ Push(a0, a1, a3, a1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000494
Ben Murdoch097c5b22016-05-18 11:27:45 +0100495 __ CallRuntime(function_id, 1);
496
497 // Restore target function and new target.
498 __ Pop(a0, a1, a3);
499 __ SmiUntag(a0);
500 }
501
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000502 __ Addu(at, v0, Operand(Code::kHeaderSize - kHeapObjectTag));
503 __ Jump(at);
504}
505
506
507void Builtins::Generate_InOptimizationQueue(MacroAssembler* masm) {
508 // Checking whether the queued function is ready for install is optional,
509 // since we come across interrupts and stack checks elsewhere. However,
510 // not checking may delay installing ready functions, and always checking
511 // would be quite expensive. A good compromise is to first check against
512 // stack limit as a cue for an interrupt signal.
513 Label ok;
514 __ LoadRoot(t0, Heap::kStackLimitRootIndex);
515 __ Branch(&ok, hs, sp, Operand(t0));
516
Ben Murdoch097c5b22016-05-18 11:27:45 +0100517 GenerateTailCallToReturnedCode(masm, Runtime::kTryInstallOptimizedCode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000518
519 __ bind(&ok);
520 GenerateTailCallToSharedCode(masm);
521}
522
523
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100524static void Generate_JSConstructStubHelper(MacroAssembler* masm,
525 bool is_api_function,
Ben Murdoch097c5b22016-05-18 11:27:45 +0100526 bool create_implicit_receiver,
527 bool check_derived_construct) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000528 // ----------- S t a t e -------------
529 // -- a0 : number of arguments
530 // -- a1 : constructor function
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000531 // -- a2 : allocation site or undefined
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000532 // -- a3 : new target
Ben Murdoch257744e2011-11-30 15:57:28 +0000533 // -- ra : return address
534 // -- sp[...]: constructor arguments
535 // -----------------------------------
536
Ben Murdoch257744e2011-11-30 15:57:28 +0000537 Isolate* isolate = masm->isolate();
538
Ben Murdoch257744e2011-11-30 15:57:28 +0000539 // Enter a construct frame.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100540 {
541 FrameScope scope(masm, StackFrame::CONSTRUCT);
Ben Murdoch257744e2011-11-30 15:57:28 +0000542
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000543 // Preserve the incoming parameters on the stack.
544 __ AssertUndefinedOrAllocationSite(a2, t0);
545 __ SmiTag(a0);
546 __ Push(a2, a0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000547
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000548 if (create_implicit_receiver) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100549 // Allocate the new receiver object.
550 __ Push(a1, a3);
551 FastNewObjectStub stub(masm->isolate());
552 __ CallStub(&stub);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000553 __ mov(t4, v0);
554 __ Pop(a1, a3);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100555
Ben Murdoch097c5b22016-05-18 11:27:45 +0100556 // ----------- S t a t e -------------
557 // -- a1: constructor function
558 // -- a3: new target
559 // -- t0: newly allocated object
560 // -----------------------------------
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100561
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000562 // Retrieve smi-tagged arguments count from the stack.
563 __ lw(a0, MemOperand(sp));
Ben Murdoch257744e2011-11-30 15:57:28 +0000564 }
565
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000566 __ SmiUntag(a0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000567
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000568 if (create_implicit_receiver) {
569 // Push the allocated receiver to the stack. We need two copies
570 // because we may have to return the original one and the calling
571 // conventions dictate that the called function pops the receiver.
572 __ Push(t4, t4);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000573 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000574 __ PushRoot(Heap::kTheHoleValueRootIndex);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000575 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000576
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100577 // Set up pointer to last argument.
578 __ Addu(a2, fp, Operand(StandardFrameConstants::kCallerSPOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +0000579
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100580 // Copy arguments and receiver to the expression stack.
581 // a0: number of arguments
582 // a1: constructor function
583 // a2: address of last argument (caller sp)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000584 // a3: new target
585 // t4: number of arguments (smi-tagged)
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100586 // sp[0]: receiver
587 // sp[1]: receiver
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000588 // sp[2]: number of arguments (smi-tagged)
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100589 Label loop, entry;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000590 __ SmiTag(t4, a0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100591 __ jmp(&entry);
592 __ bind(&loop);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100593 __ Lsa(t0, a2, t4, kPointerSizeLog2 - kSmiTagSize);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100594 __ lw(t1, MemOperand(t0));
595 __ push(t1);
596 __ bind(&entry);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000597 __ Addu(t4, t4, Operand(-2));
598 __ Branch(&loop, greater_equal, t4, Operand(zero_reg));
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000599
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100600 // Call the function.
601 // a0: number of arguments
602 // a1: constructor function
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000603 // a3: new target
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100604 if (is_api_function) {
605 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
606 Handle<Code> code =
607 masm->isolate()->builtins()->HandleApiCallConstruct();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000608 __ Call(code, RelocInfo::CODE_TARGET);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100609 } else {
610 ParameterCount actual(a0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000611 __ InvokeFunction(a1, a3, actual, CALL_FUNCTION,
612 CheckDebugStepCallWrapper());
Ben Murdoch257744e2011-11-30 15:57:28 +0000613 }
614
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100615 // Store offset of return address for deoptimizer.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000616 if (create_implicit_receiver && !is_api_function) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100617 masm->isolate()->heap()->SetConstructStubDeoptPCOffset(masm->pc_offset());
618 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000619
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100620 // Restore context from the frame.
621 __ lw(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
Ben Murdoch257744e2011-11-30 15:57:28 +0000622
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000623 if (create_implicit_receiver) {
624 // If the result is an object (in the ECMA sense), we should get rid
625 // of the receiver and use the result; see ECMA-262 section 13.2.2-7
626 // on page 74.
627 Label use_receiver, exit;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100628
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000629 // If the result is a smi, it is *not* an object in the ECMA sense.
630 // v0: result
631 // sp[0]: receiver (newly allocated object)
632 // sp[1]: number of arguments (smi-tagged)
633 __ JumpIfSmi(v0, &use_receiver);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100634
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000635 // If the type of the result (stored in its map) is less than
636 // FIRST_JS_RECEIVER_TYPE, it is not an object in the ECMA sense.
637 __ GetObjectType(v0, a1, a3);
638 __ Branch(&exit, greater_equal, a3, Operand(FIRST_JS_RECEIVER_TYPE));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100639
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000640 // Throw away the result of the constructor invocation and use the
641 // on-stack receiver as the result.
642 __ bind(&use_receiver);
643 __ lw(v0, MemOperand(sp));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100644
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000645 // Remove receiver from the stack, remove caller arguments, and
646 // return.
647 __ bind(&exit);
648 // v0: result
649 // sp[0]: receiver (newly allocated object)
650 // sp[1]: number of arguments (smi-tagged)
651 __ lw(a1, MemOperand(sp, 1 * kPointerSize));
652 } else {
653 __ lw(a1, MemOperand(sp));
654 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100655
656 // Leave construct frame.
Ben Murdoch257744e2011-11-30 15:57:28 +0000657 }
658
Ben Murdoch097c5b22016-05-18 11:27:45 +0100659 // ES6 9.2.2. Step 13+
660 // Check that the result is not a Smi, indicating that the constructor result
661 // from a derived class is neither undefined nor an Object.
662 if (check_derived_construct) {
663 Label dont_throw;
664 __ JumpIfNotSmi(v0, &dont_throw);
665 {
666 FrameScope scope(masm, StackFrame::INTERNAL);
667 __ CallRuntime(Runtime::kThrowDerivedConstructorReturnedNonObject);
668 }
669 __ bind(&dont_throw);
670 }
671
672 __ Lsa(sp, sp, a1, kPointerSizeLog2 - 1);
Ben Murdoch257744e2011-11-30 15:57:28 +0000673 __ Addu(sp, sp, kPointerSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000674 if (create_implicit_receiver) {
675 __ IncrementCounter(isolate->counters()->constructed_objects(), 1, a1, a2);
676 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000677 __ Ret();
Andrei Popescu31002712010-02-23 13:46:05 +0000678}
679
680
681void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100682 Generate_JSConstructStubHelper(masm, false, true, false);
Andrei Popescu31002712010-02-23 13:46:05 +0000683}
684
685
686void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100687 Generate_JSConstructStubHelper(masm, true, false, false);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000688}
689
690
691void Builtins::Generate_JSBuiltinsConstructStub(MacroAssembler* masm) {
Ben Murdoch097c5b22016-05-18 11:27:45 +0100692 Generate_JSConstructStubHelper(masm, false, false, false);
693}
694
695
696void Builtins::Generate_JSBuiltinsConstructStubForDerived(
697 MacroAssembler* masm) {
698 Generate_JSConstructStubHelper(masm, false, false, true);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000699}
700
701
702void Builtins::Generate_ConstructedNonConstructable(MacroAssembler* masm) {
703 FrameScope scope(masm, StackFrame::INTERNAL);
704 __ Push(a1);
705 __ CallRuntime(Runtime::kThrowConstructedNonConstructable);
706}
707
708
709enum IsTagged { kArgcIsSmiTagged, kArgcIsUntaggedInt };
710
711
712// Clobbers a2; preserves all other registers.
713static void Generate_CheckStackOverflow(MacroAssembler* masm, Register argc,
714 IsTagged argc_is_tagged) {
715 // Check the stack for overflow. We are not trying to catch
716 // interruptions (e.g. debug break and preemption) here, so the "real stack
717 // limit" is checked.
718 Label okay;
719 __ LoadRoot(a2, Heap::kRealStackLimitRootIndex);
720 // Make a2 the space we have left. The stack might already be overflowed
721 // here which will cause a2 to become negative.
722 __ Subu(a2, sp, a2);
723 // Check if the arguments will overflow the stack.
724 if (argc_is_tagged == kArgcIsSmiTagged) {
725 __ sll(t3, argc, kPointerSizeLog2 - kSmiTagSize);
726 } else {
727 DCHECK(argc_is_tagged == kArgcIsUntaggedInt);
728 __ sll(t3, argc, kPointerSizeLog2);
729 }
730 // Signed comparison.
731 __ Branch(&okay, gt, a2, Operand(t3));
732
733 // Out of stack space.
734 __ CallRuntime(Runtime::kThrowStackOverflow);
735
736 __ bind(&okay);
Ben Murdoch257744e2011-11-30 15:57:28 +0000737}
738
739
740static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm,
741 bool is_construct) {
742 // Called from JSEntryStub::GenerateBody
743
744 // ----------- S t a t e -------------
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000745 // -- a0: new.target
Ben Murdoch257744e2011-11-30 15:57:28 +0000746 // -- a1: function
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100747 // -- a2: receiver_pointer
Ben Murdoch257744e2011-11-30 15:57:28 +0000748 // -- a3: argc
749 // -- s0: argv
750 // -----------------------------------
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000751 ProfileEntryHookStub::MaybeCallEntryHook(masm);
Ben Murdoch257744e2011-11-30 15:57:28 +0000752
753 // Clear the context before we push it when entering the JS frame.
754 __ mov(cp, zero_reg);
755
756 // Enter an internal frame.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100757 {
758 FrameScope scope(masm, StackFrame::INTERNAL);
Ben Murdoch257744e2011-11-30 15:57:28 +0000759
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000760 // Setup the context (we need to use the caller context from the isolate).
761 ExternalReference context_address(Isolate::kContextAddress,
762 masm->isolate());
763 __ li(cp, Operand(context_address));
764 __ lw(cp, MemOperand(cp));
Ben Murdoch257744e2011-11-30 15:57:28 +0000765
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100766 // Push the function and the receiver onto the stack.
767 __ Push(a1, a2);
Ben Murdoch257744e2011-11-30 15:57:28 +0000768
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000769 // Check if we have enough stack space to push all arguments.
770 // Clobbers a2.
771 Generate_CheckStackOverflow(masm, a3, kArgcIsUntaggedInt);
772
773 // Remember new.target.
774 __ mov(t1, a0);
775
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100776 // Copy arguments to the stack in a loop.
777 // a3: argc
778 // s0: argv, i.e. points to first arg
779 Label loop, entry;
Ben Murdoch097c5b22016-05-18 11:27:45 +0100780 __ Lsa(t2, s0, a3, kPointerSizeLog2);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100781 __ b(&entry);
782 __ nop(); // Branch delay slot nop.
783 // t2 points past last arg.
784 __ bind(&loop);
785 __ lw(t0, MemOperand(s0)); // Read next parameter.
786 __ addiu(s0, s0, kPointerSize);
787 __ lw(t0, MemOperand(t0)); // Dereference handle.
788 __ push(t0); // Push parameter.
789 __ bind(&entry);
790 __ Branch(&loop, ne, s0, Operand(t2));
Ben Murdoch257744e2011-11-30 15:57:28 +0000791
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000792 // Setup new.target and argc.
793 __ mov(a0, a3);
794 __ mov(a3, t1);
795
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100796 // Initialize all JavaScript callee-saved registers, since they will be seen
797 // by the garbage collector as part of handlers.
798 __ LoadRoot(t0, Heap::kUndefinedValueRootIndex);
799 __ mov(s1, t0);
800 __ mov(s2, t0);
801 __ mov(s3, t0);
802 __ mov(s4, t0);
803 __ mov(s5, t0);
804 // s6 holds the root address. Do not clobber.
805 // s7 is cp. Do not init.
Ben Murdoch257744e2011-11-30 15:57:28 +0000806
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000807 // Invoke the code.
808 Handle<Code> builtin = is_construct
809 ? masm->isolate()->builtins()->Construct()
810 : masm->isolate()->builtins()->Call();
811 __ Call(builtin, RelocInfo::CODE_TARGET);
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000812
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100813 // Leave internal frame.
Ben Murdoch257744e2011-11-30 15:57:28 +0000814 }
815
Ben Murdoch257744e2011-11-30 15:57:28 +0000816 __ Jump(ra);
Andrei Popescu31002712010-02-23 13:46:05 +0000817}
818
819
Andrei Popescu31002712010-02-23 13:46:05 +0000820void Builtins::Generate_JSEntryTrampoline(MacroAssembler* masm) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000821 Generate_JSEntryTrampolineHelper(masm, false);
Andrei Popescu31002712010-02-23 13:46:05 +0000822}
823
824
825void Builtins::Generate_JSConstructEntryTrampoline(MacroAssembler* masm) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000826 Generate_JSEntryTrampolineHelper(masm, true);
Steve Block44f0eee2011-05-26 01:26:41 +0100827}
828
829
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000830// Generate code for entering a JS function with the interpreter.
831// On entry to the function the receiver and arguments have been pushed on the
832// stack left to right. The actual argument count matches the formal parameter
833// count expected by the function.
834//
835// The live registers are:
836// o a1: the JS function object being called.
837// o a3: the new target
838// o cp: our context
839// o fp: the caller's frame pointer
840// o sp: stack pointer
841// o ra: return address
842//
Ben Murdoch097c5b22016-05-18 11:27:45 +0100843// The function builds an interpreter frame. See InterpreterFrameConstants in
844// frames.h for its layout.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000845void Builtins::Generate_InterpreterEntryTrampoline(MacroAssembler* masm) {
846 // Open a frame scope to indicate that there is a frame on the stack. The
847 // MANUAL indicates that the scope shouldn't actually generate code to set up
848 // the frame (that is done below).
849 FrameScope frame_scope(masm, StackFrame::MANUAL);
850
851 __ Push(ra, fp, cp, a1);
852 __ Addu(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000853
854 // Get the bytecode array from the function object and load the pointer to the
855 // first entry into kInterpreterBytecodeRegister.
856 __ lw(a0, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100857 Label load_debug_bytecode_array, bytecode_array_loaded;
858 Register debug_info = kInterpreterBytecodeArrayRegister;
859 DCHECK(!debug_info.is(a0));
860 __ lw(debug_info, FieldMemOperand(a0, SharedFunctionInfo::kDebugInfoOffset));
861 __ Branch(&load_debug_bytecode_array, ne, debug_info,
862 Operand(DebugInfo::uninitialized()));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000863 __ lw(kInterpreterBytecodeArrayRegister,
864 FieldMemOperand(a0, SharedFunctionInfo::kFunctionDataOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100865 __ bind(&bytecode_array_loaded);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000866
867 if (FLAG_debug_code) {
868 // Check function data field is actually a BytecodeArray object.
869 __ SmiTst(kInterpreterBytecodeArrayRegister, t0);
870 __ Assert(ne, kFunctionDataShouldBeBytecodeArrayOnInterpreterEntry, t0,
871 Operand(zero_reg));
872 __ GetObjectType(kInterpreterBytecodeArrayRegister, t0, t0);
873 __ Assert(eq, kFunctionDataShouldBeBytecodeArrayOnInterpreterEntry, t0,
874 Operand(BYTECODE_ARRAY_TYPE));
875 }
876
Ben Murdoch097c5b22016-05-18 11:27:45 +0100877 // Push new.target, bytecode array and zero for bytecode array offset.
878 __ Push(a3, kInterpreterBytecodeArrayRegister, zero_reg);
879
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000880 // Allocate the local and temporary register file on the stack.
881 {
882 // Load frame size from the BytecodeArray object.
883 __ lw(t0, FieldMemOperand(kInterpreterBytecodeArrayRegister,
884 BytecodeArray::kFrameSizeOffset));
885
886 // Do a stack check to ensure we don't go over the limit.
887 Label ok;
888 __ Subu(t1, sp, Operand(t0));
889 __ LoadRoot(a2, Heap::kRealStackLimitRootIndex);
890 __ Branch(&ok, hs, t1, Operand(a2));
891 __ CallRuntime(Runtime::kThrowStackOverflow);
892 __ bind(&ok);
893
894 // If ok, push undefined as the initial value for all register file entries.
895 Label loop_header;
896 Label loop_check;
897 __ LoadRoot(t1, Heap::kUndefinedValueRootIndex);
898 __ Branch(&loop_check);
899 __ bind(&loop_header);
900 // TODO(rmcilroy): Consider doing more than one push per loop iteration.
901 __ push(t1);
902 // Continue loop if not done.
903 __ bind(&loop_check);
904 __ Subu(t0, t0, Operand(kPointerSize));
905 __ Branch(&loop_header, ge, t0, Operand(zero_reg));
906 }
907
908 // TODO(rmcilroy): List of things not currently dealt with here but done in
909 // fullcodegen's prologue:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000910 // - Call ProfileEntryHookStub when isolate has a function_entry_hook.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000911 // - Code aging of the BytecodeArray object.
912
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000913 // Load bytecode offset and dispatch table into registers.
914 __ LoadRoot(kInterpreterAccumulatorRegister, Heap::kUndefinedValueRootIndex);
915 __ Addu(kInterpreterRegisterFileRegister, fp,
916 Operand(InterpreterFrameConstants::kRegisterFilePointerFromFp));
917 __ li(kInterpreterBytecodeOffsetRegister,
918 Operand(BytecodeArray::kHeaderSize - kHeapObjectTag));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100919 __ li(kInterpreterDispatchTableRegister,
920 Operand(ExternalReference::interpreter_dispatch_table_address(
921 masm->isolate())));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000922
923 // Dispatch to the first bytecode handler for the function.
924 __ Addu(a0, kInterpreterBytecodeArrayRegister,
925 kInterpreterBytecodeOffsetRegister);
926 __ lbu(a0, MemOperand(a0));
Ben Murdoch097c5b22016-05-18 11:27:45 +0100927 __ Lsa(at, kInterpreterDispatchTableRegister, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000928 __ lw(at, MemOperand(at));
929 // TODO(rmcilroy): Make dispatch table point to code entrys to avoid untagging
930 // and header removal.
931 __ Addu(at, at, Operand(Code::kHeaderSize - kHeapObjectTag));
932 __ Call(at);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100933
934 // Even though the first bytecode handler was called, we will never return.
935 __ Abort(kUnexpectedReturnFromBytecodeHandler);
936
937 // Load debug copy of the bytecode array.
938 __ bind(&load_debug_bytecode_array);
939 __ lw(kInterpreterBytecodeArrayRegister,
940 FieldMemOperand(debug_info, DebugInfo::kAbstractCodeIndex));
941 __ Branch(&bytecode_array_loaded);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000942}
943
944
945void Builtins::Generate_InterpreterExitTrampoline(MacroAssembler* masm) {
946 // TODO(rmcilroy): List of things not currently dealt with here but done in
947 // fullcodegen's EmitReturnSequence.
948 // - Supporting FLAG_trace for Runtime::TraceExit.
949 // - Support profiler (specifically decrementing profiling_counter
950 // appropriately and calling out to HandleInterrupts if necessary).
951
952 // The return value is in accumulator, which is already in v0.
953
954 // Leave the frame (also dropping the register file).
955 __ LeaveFrame(StackFrame::JAVA_SCRIPT);
956
957 // Drop receiver + arguments and return.
958 __ lw(at, FieldMemOperand(kInterpreterBytecodeArrayRegister,
959 BytecodeArray::kParameterSizeOffset));
960 __ Addu(sp, sp, at);
961 __ Jump(ra);
962}
963
964
965// static
Ben Murdoch097c5b22016-05-18 11:27:45 +0100966void Builtins::Generate_InterpreterPushArgsAndCallImpl(
967 MacroAssembler* masm, TailCallMode tail_call_mode) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000968 // ----------- S t a t e -------------
969 // -- a0 : the number of arguments (not including the receiver)
970 // -- a2 : the address of the first argument to be pushed. Subsequent
971 // arguments should be consecutive above this, in the same order as
972 // they are to be pushed onto the stack.
973 // -- a1 : the target to call (can be any Object).
974 // -----------------------------------
975
976 // Find the address of the last argument.
977 __ Addu(a3, a0, Operand(1)); // Add one for receiver.
978 __ sll(a3, a3, kPointerSizeLog2);
979 __ Subu(a3, a2, Operand(a3));
980
981 // Push the arguments.
982 Label loop_header, loop_check;
983 __ Branch(&loop_check);
984 __ bind(&loop_header);
985 __ lw(t0, MemOperand(a2));
986 __ Addu(a2, a2, Operand(-kPointerSize));
987 __ push(t0);
988 __ bind(&loop_check);
989 __ Branch(&loop_header, gt, a2, Operand(a3));
990
991 // Call the target.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100992 __ Jump(masm->isolate()->builtins()->Call(ConvertReceiverMode::kAny,
993 tail_call_mode),
994 RelocInfo::CODE_TARGET);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000995}
996
997
998// static
999void Builtins::Generate_InterpreterPushArgsAndConstruct(MacroAssembler* masm) {
1000 // ----------- S t a t e -------------
1001 // -- a0 : argument count (not including receiver)
1002 // -- a3 : new target
1003 // -- a1 : constructor to call
1004 // -- a2 : address of the first argument
1005 // -----------------------------------
1006
1007 // Find the address of the last argument.
1008 __ sll(t0, a0, kPointerSizeLog2);
1009 __ Subu(t0, a2, Operand(t0));
1010
1011 // Push a slot for the receiver.
1012 __ push(zero_reg);
1013
1014 // Push the arguments.
1015 Label loop_header, loop_check;
1016 __ Branch(&loop_check);
1017 __ bind(&loop_header);
1018 __ lw(t1, MemOperand(a2));
1019 __ Addu(a2, a2, Operand(-kPointerSize));
1020 __ push(t1);
1021 __ bind(&loop_check);
1022 __ Branch(&loop_header, gt, a2, Operand(t0));
1023
1024 // Call the constructor with a0, a1, and a3 unmodified.
1025 __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET);
1026}
1027
1028
Ben Murdoch097c5b22016-05-18 11:27:45 +01001029static void Generate_EnterBytecodeDispatch(MacroAssembler* masm) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001030 // Initialize register file register and dispatch table register.
1031 __ Addu(kInterpreterRegisterFileRegister, fp,
1032 Operand(InterpreterFrameConstants::kRegisterFilePointerFromFp));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001033 __ li(kInterpreterDispatchTableRegister,
1034 Operand(ExternalReference::interpreter_dispatch_table_address(
1035 masm->isolate())));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001036
1037 // Get the context from the frame.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001038 __ lw(kContextRegister,
1039 MemOperand(kInterpreterRegisterFileRegister,
1040 InterpreterFrameConstants::kContextFromRegisterPointer));
1041
1042 // Get the bytecode array pointer from the frame.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001043 __ lw(
1044 kInterpreterBytecodeArrayRegister,
1045 MemOperand(kInterpreterRegisterFileRegister,
1046 InterpreterFrameConstants::kBytecodeArrayFromRegisterPointer));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001047
1048 if (FLAG_debug_code) {
1049 // Check function data field is actually a BytecodeArray object.
1050 __ SmiTst(kInterpreterBytecodeArrayRegister, at);
1051 __ Assert(ne, kFunctionDataShouldBeBytecodeArrayOnInterpreterEntry, at,
1052 Operand(zero_reg));
1053 __ GetObjectType(kInterpreterBytecodeArrayRegister, a1, a1);
1054 __ Assert(eq, kFunctionDataShouldBeBytecodeArrayOnInterpreterEntry, a1,
1055 Operand(BYTECODE_ARRAY_TYPE));
1056 }
1057
1058 // Get the target bytecode offset from the frame.
1059 __ lw(kInterpreterBytecodeOffsetRegister,
1060 MemOperand(
1061 kInterpreterRegisterFileRegister,
1062 InterpreterFrameConstants::kBytecodeOffsetFromRegisterPointer));
1063 __ SmiUntag(kInterpreterBytecodeOffsetRegister);
1064
1065 // Dispatch to the target bytecode.
1066 __ Addu(a1, kInterpreterBytecodeArrayRegister,
1067 kInterpreterBytecodeOffsetRegister);
1068 __ lbu(a1, MemOperand(a1));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001069 __ Lsa(a1, kInterpreterDispatchTableRegister, a1, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001070 __ lw(a1, MemOperand(a1));
1071 __ Addu(a1, a1, Operand(Code::kHeaderSize - kHeapObjectTag));
1072 __ Jump(a1);
1073}
1074
1075
Ben Murdoch097c5b22016-05-18 11:27:45 +01001076static void Generate_InterpreterNotifyDeoptimizedHelper(
1077 MacroAssembler* masm, Deoptimizer::BailoutType type) {
1078 // Enter an internal frame.
1079 {
1080 FrameScope scope(masm, StackFrame::INTERNAL);
1081
1082 // Pass the deoptimization type to the runtime system.
1083 __ li(a1, Operand(Smi::FromInt(static_cast<int>(type))));
1084 __ push(a1);
1085 __ CallRuntime(Runtime::kNotifyDeoptimized);
1086 // Tear down internal frame.
1087 }
1088
1089 // Drop state (we don't use these for interpreter deopts) and and pop the
1090 // accumulator value into the accumulator register.
1091 __ Drop(1);
1092 __ Pop(kInterpreterAccumulatorRegister);
1093
1094 // Enter the bytecode dispatch.
1095 Generate_EnterBytecodeDispatch(masm);
1096}
1097
1098
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001099void Builtins::Generate_InterpreterNotifyDeoptimized(MacroAssembler* masm) {
1100 Generate_InterpreterNotifyDeoptimizedHelper(masm, Deoptimizer::EAGER);
1101}
1102
1103
1104void Builtins::Generate_InterpreterNotifySoftDeoptimized(MacroAssembler* masm) {
1105 Generate_InterpreterNotifyDeoptimizedHelper(masm, Deoptimizer::SOFT);
1106}
1107
1108
1109void Builtins::Generate_InterpreterNotifyLazyDeoptimized(MacroAssembler* masm) {
1110 Generate_InterpreterNotifyDeoptimizedHelper(masm, Deoptimizer::LAZY);
1111}
1112
Ben Murdoch097c5b22016-05-18 11:27:45 +01001113void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) {
1114 // Set the address of the interpreter entry trampoline as a return address.
1115 // This simulates the initial call to bytecode handlers in interpreter entry
1116 // trampoline. The return will never actually be taken, but our stack walker
1117 // uses this address to determine whether a frame is interpreted.
1118 __ li(ra, Operand(masm->isolate()->builtins()->InterpreterEntryTrampoline()));
1119
1120 Generate_EnterBytecodeDispatch(masm);
1121}
1122
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001123
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001124void Builtins::Generate_CompileLazy(MacroAssembler* masm) {
Ben Murdoch097c5b22016-05-18 11:27:45 +01001125 GenerateTailCallToReturnedCode(masm, Runtime::kCompileLazy);
Steve Block44f0eee2011-05-26 01:26:41 +01001126}
1127
1128
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001129void Builtins::Generate_CompileOptimized(MacroAssembler* masm) {
Ben Murdoch097c5b22016-05-18 11:27:45 +01001130 GenerateTailCallToReturnedCode(masm,
1131 Runtime::kCompileOptimized_NotConcurrent);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001132}
1133
1134
1135void Builtins::Generate_CompileOptimizedConcurrent(MacroAssembler* masm) {
Ben Murdoch097c5b22016-05-18 11:27:45 +01001136 GenerateTailCallToReturnedCode(masm, Runtime::kCompileOptimized_Concurrent);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001137}
1138
1139
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001140static void GenerateMakeCodeYoungAgainCommon(MacroAssembler* masm) {
1141 // For now, we are relying on the fact that make_code_young doesn't do any
1142 // garbage collection which allows us to save/restore the registers without
1143 // worrying about which of them contain pointers. We also don't build an
1144 // internal frame to make the code faster, since we shouldn't have to do stack
1145 // crawls in MakeCodeYoung. This seems a bit fragile.
1146
1147 // Set a0 to point to the head of the PlatformCodeAge sequence.
1148 __ Subu(a0, a0,
1149 Operand(kNoCodeAgeSequenceLength - Assembler::kInstrSize));
1150
1151 // The following registers must be saved and restored when calling through to
1152 // the runtime:
1153 // a0 - contains return address (beginning of patch sequence)
1154 // a1 - isolate
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001155 // a3 - new target
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001156 RegList saved_regs =
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001157 (a0.bit() | a1.bit() | a3.bit() | ra.bit() | fp.bit()) & ~sp.bit();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001158 FrameScope scope(masm, StackFrame::MANUAL);
1159 __ MultiPush(saved_regs);
1160 __ PrepareCallCFunction(2, 0, a2);
1161 __ li(a1, Operand(ExternalReference::isolate_address(masm->isolate())));
1162 __ CallCFunction(
1163 ExternalReference::get_make_code_young_function(masm->isolate()), 2);
1164 __ MultiPop(saved_regs);
1165 __ Jump(a0);
1166}
1167
1168#define DEFINE_CODE_AGE_BUILTIN_GENERATOR(C) \
1169void Builtins::Generate_Make##C##CodeYoungAgainEvenMarking( \
1170 MacroAssembler* masm) { \
1171 GenerateMakeCodeYoungAgainCommon(masm); \
1172} \
1173void Builtins::Generate_Make##C##CodeYoungAgainOddMarking( \
1174 MacroAssembler* masm) { \
1175 GenerateMakeCodeYoungAgainCommon(masm); \
1176}
1177CODE_AGE_LIST(DEFINE_CODE_AGE_BUILTIN_GENERATOR)
1178#undef DEFINE_CODE_AGE_BUILTIN_GENERATOR
1179
1180
1181void Builtins::Generate_MarkCodeAsExecutedOnce(MacroAssembler* masm) {
1182 // For now, as in GenerateMakeCodeYoungAgainCommon, we are relying on the fact
1183 // that make_code_young doesn't do any garbage collection which allows us to
1184 // save/restore the registers without worrying about which of them contain
1185 // pointers.
1186
1187 // Set a0 to point to the head of the PlatformCodeAge sequence.
1188 __ Subu(a0, a0,
1189 Operand(kNoCodeAgeSequenceLength - Assembler::kInstrSize));
1190
1191 // The following registers must be saved and restored when calling through to
1192 // the runtime:
1193 // a0 - contains return address (beginning of patch sequence)
1194 // a1 - isolate
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001195 // a3 - new target
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001196 RegList saved_regs =
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001197 (a0.bit() | a1.bit() | a3.bit() | ra.bit() | fp.bit()) & ~sp.bit();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001198 FrameScope scope(masm, StackFrame::MANUAL);
1199 __ MultiPush(saved_regs);
1200 __ PrepareCallCFunction(2, 0, a2);
1201 __ li(a1, Operand(ExternalReference::isolate_address(masm->isolate())));
1202 __ CallCFunction(
1203 ExternalReference::get_mark_code_as_executed_function(masm->isolate()),
1204 2);
1205 __ MultiPop(saved_regs);
1206
1207 // Perform prologue operations usually performed by the young code stub.
1208 __ Push(ra, fp, cp, a1);
1209 __ Addu(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp));
1210
1211 // Jump to point after the code-age stub.
1212 __ Addu(a0, a0, Operand(kNoCodeAgeSequenceLength));
1213 __ Jump(a0);
1214}
1215
1216
1217void Builtins::Generate_MarkCodeAsExecutedTwice(MacroAssembler* masm) {
1218 GenerateMakeCodeYoungAgainCommon(masm);
1219}
1220
1221
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001222void Builtins::Generate_MarkCodeAsToBeExecutedOnce(MacroAssembler* masm) {
1223 Generate_MarkCodeAsExecutedOnce(masm);
1224}
1225
1226
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001227static void Generate_NotifyStubFailureHelper(MacroAssembler* masm,
1228 SaveFPRegsMode save_doubles) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001229 {
1230 FrameScope scope(masm, StackFrame::INTERNAL);
Ben Murdoch257744e2011-11-30 15:57:28 +00001231
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001232 // Preserve registers across notification, this is important for compiled
1233 // stubs that tail call the runtime on deopts passing their parameters in
1234 // registers.
1235 __ MultiPush(kJSCallerSaved | kCalleeSaved);
1236 // Pass the function and deoptimization type to the runtime system.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001237 __ CallRuntime(Runtime::kNotifyStubFailure, save_doubles);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001238 __ MultiPop(kJSCallerSaved | kCalleeSaved);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001239 }
Ben Murdoch257744e2011-11-30 15:57:28 +00001240
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001241 __ Addu(sp, sp, Operand(kPointerSize)); // Ignore state
1242 __ Jump(ra); // Jump to miss handler
1243}
1244
1245
1246void Builtins::Generate_NotifyStubFailure(MacroAssembler* masm) {
1247 Generate_NotifyStubFailureHelper(masm, kDontSaveFPRegs);
1248}
1249
1250
1251void Builtins::Generate_NotifyStubFailureSaveDoubles(MacroAssembler* masm) {
1252 Generate_NotifyStubFailureHelper(masm, kSaveFPRegs);
Steve Block44f0eee2011-05-26 01:26:41 +01001253}
1254
1255
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001256static void Generate_NotifyDeoptimizedHelper(MacroAssembler* masm,
1257 Deoptimizer::BailoutType type) {
1258 {
1259 FrameScope scope(masm, StackFrame::INTERNAL);
1260 // Pass the function and deoptimization type to the runtime system.
1261 __ li(a0, Operand(Smi::FromInt(static_cast<int>(type))));
1262 __ push(a0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001263 __ CallRuntime(Runtime::kNotifyDeoptimized);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001264 }
1265
1266 // Get the full codegen state from the stack and untag it -> t2.
1267 __ lw(t2, MemOperand(sp, 0 * kPointerSize));
1268 __ SmiUntag(t2);
1269 // Switch on the state.
1270 Label with_tos_register, unknown_state;
1271 __ Branch(&with_tos_register,
1272 ne, t2, Operand(FullCodeGenerator::NO_REGISTERS));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001273 __ Ret(USE_DELAY_SLOT);
1274 // Safe to fill delay slot Addu will emit one instruction.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001275 __ Addu(sp, sp, Operand(1 * kPointerSize)); // Remove state.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001276
1277 __ bind(&with_tos_register);
1278 __ lw(v0, MemOperand(sp, 1 * kPointerSize));
1279 __ Branch(&unknown_state, ne, t2, Operand(FullCodeGenerator::TOS_REG));
1280
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001281 __ Ret(USE_DELAY_SLOT);
1282 // Safe to fill delay slot Addu will emit one instruction.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001283 __ Addu(sp, sp, Operand(2 * kPointerSize)); // Remove state.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001284
1285 __ bind(&unknown_state);
1286 __ stop("no cases left");
1287}
1288
1289
Steve Block44f0eee2011-05-26 01:26:41 +01001290void Builtins::Generate_NotifyDeoptimized(MacroAssembler* masm) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001291 Generate_NotifyDeoptimizedHelper(masm, Deoptimizer::EAGER);
Steve Block44f0eee2011-05-26 01:26:41 +01001292}
1293
1294
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001295void Builtins::Generate_NotifySoftDeoptimized(MacroAssembler* masm) {
1296 Generate_NotifyDeoptimizedHelper(masm, Deoptimizer::SOFT);
1297}
1298
1299
Steve Block44f0eee2011-05-26 01:26:41 +01001300void Builtins::Generate_NotifyLazyDeoptimized(MacroAssembler* masm) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001301 Generate_NotifyDeoptimizedHelper(masm, Deoptimizer::LAZY);
Steve Block44f0eee2011-05-26 01:26:41 +01001302}
1303
1304
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001305// Clobbers {t2, t3, t4, t5}.
1306static void CompatibleReceiverCheck(MacroAssembler* masm, Register receiver,
1307 Register function_template_info,
1308 Label* receiver_check_failed) {
1309 Register signature = t2;
1310 Register map = t3;
1311 Register constructor = t4;
1312 Register scratch = t5;
1313
1314 // If there is no signature, return the holder.
1315 __ lw(signature, FieldMemOperand(function_template_info,
1316 FunctionTemplateInfo::kSignatureOffset));
1317 Label receiver_check_passed;
1318 __ JumpIfRoot(signature, Heap::kUndefinedValueRootIndex,
1319 &receiver_check_passed);
1320
1321 // Walk the prototype chain.
1322 __ lw(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
1323 Label prototype_loop_start;
1324 __ bind(&prototype_loop_start);
1325
1326 // Get the constructor, if any.
1327 __ GetMapConstructor(constructor, map, scratch, scratch);
1328 Label next_prototype;
1329 __ Branch(&next_prototype, ne, scratch, Operand(JS_FUNCTION_TYPE));
1330 Register type = constructor;
1331 __ lw(type,
1332 FieldMemOperand(constructor, JSFunction::kSharedFunctionInfoOffset));
1333 __ lw(type, FieldMemOperand(type, SharedFunctionInfo::kFunctionDataOffset));
1334
1335 // Loop through the chain of inheriting function templates.
1336 Label function_template_loop;
1337 __ bind(&function_template_loop);
1338
1339 // If the signatures match, we have a compatible receiver.
1340 __ Branch(&receiver_check_passed, eq, signature, Operand(type),
1341 USE_DELAY_SLOT);
1342
1343 // If the current type is not a FunctionTemplateInfo, load the next prototype
1344 // in the chain.
1345 __ JumpIfSmi(type, &next_prototype);
1346 __ GetObjectType(type, scratch, scratch);
1347 __ Branch(&next_prototype, ne, scratch, Operand(FUNCTION_TEMPLATE_INFO_TYPE));
1348
1349 // Otherwise load the parent function template and iterate.
1350 __ lw(type,
1351 FieldMemOperand(type, FunctionTemplateInfo::kParentTemplateOffset));
1352 __ Branch(&function_template_loop);
1353
1354 // Load the next prototype and iterate.
1355 __ bind(&next_prototype);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001356 __ lw(scratch, FieldMemOperand(map, Map::kBitField3Offset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001357 __ DecodeField<Map::HasHiddenPrototype>(scratch);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001358 __ Branch(receiver_check_failed, eq, scratch, Operand(zero_reg));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001359 __ lw(receiver, FieldMemOperand(map, Map::kPrototypeOffset));
1360 __ lw(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001361
1362 __ Branch(&prototype_loop_start);
1363
1364 __ bind(&receiver_check_passed);
1365}
1366
1367
1368void Builtins::Generate_HandleFastApiCall(MacroAssembler* masm) {
1369 // ----------- S t a t e -------------
1370 // -- a0 : number of arguments excluding receiver
1371 // -- a1 : callee
1372 // -- ra : return address
1373 // -- sp[0] : last argument
1374 // -- ...
1375 // -- sp[4 * (argc - 1)] : first argument
1376 // -- sp[4 * argc] : receiver
1377 // -----------------------------------
1378
1379 // Load the FunctionTemplateInfo.
1380 __ lw(t1, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
1381 __ lw(t1, FieldMemOperand(t1, SharedFunctionInfo::kFunctionDataOffset));
1382
1383 // Do the compatible receiver check.
1384 Label receiver_check_failed;
Ben Murdoch097c5b22016-05-18 11:27:45 +01001385 __ Lsa(t8, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001386 __ lw(t0, MemOperand(t8));
1387 CompatibleReceiverCheck(masm, t0, t1, &receiver_check_failed);
1388
1389 // Get the callback offset from the FunctionTemplateInfo, and jump to the
1390 // beginning of the code.
1391 __ lw(t2, FieldMemOperand(t1, FunctionTemplateInfo::kCallCodeOffset));
1392 __ lw(t2, FieldMemOperand(t2, CallHandlerInfo::kFastHandlerOffset));
1393 __ Addu(t2, t2, Operand(Code::kHeaderSize - kHeapObjectTag));
1394 __ Jump(t2);
1395
1396 // Compatible receiver check failed: throw an Illegal Invocation exception.
1397 __ bind(&receiver_check_failed);
1398 // Drop the arguments (including the receiver);
1399 __ Addu(t8, t8, Operand(kPointerSize));
1400 __ addu(sp, t8, zero_reg);
1401 __ TailCallRuntime(Runtime::kThrowIllegalInvocation);
1402}
1403
1404
Steve Block44f0eee2011-05-26 01:26:41 +01001405void Builtins::Generate_OnStackReplacement(MacroAssembler* masm) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001406 // Lookup the function in the JavaScript frame.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001407 __ lw(a0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
1408 {
1409 FrameScope scope(masm, StackFrame::INTERNAL);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001410 // Pass function as argument.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001411 __ push(a0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001412 __ CallRuntime(Runtime::kCompileForOnStackReplacement);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001413 }
1414
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001415 // If the code object is null, just return to the unoptimized code.
1416 __ Ret(eq, v0, Operand(Smi::FromInt(0)));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001417
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001418 // Load deoptimization data from the code object.
1419 // <deopt_data> = <code>[#deoptimization_data_offset]
1420 __ lw(a1, MemOperand(v0, Code::kDeoptimizationDataOffset - kHeapObjectTag));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001421
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001422 // Load the OSR entrypoint offset from the deoptimization data.
1423 // <osr_offset> = <deopt_data>[#header_size + #osr_pc_offset]
1424 __ lw(a1, MemOperand(a1, FixedArray::OffsetOfElementAt(
1425 DeoptimizationInputData::kOsrPcOffsetIndex) - kHeapObjectTag));
1426 __ SmiUntag(a1);
1427
1428 // Compute the target address = code_obj + header_size + osr_offset
1429 // <entry_addr> = <code_obj> + #header_size + <osr_offset>
1430 __ addu(v0, v0, a1);
1431 __ addiu(ra, v0, Code::kHeaderSize - kHeapObjectTag);
1432
1433 // And "return" to the OSR entry point of the function.
1434 __ Ret();
1435}
1436
1437
1438void Builtins::Generate_OsrAfterStackCheck(MacroAssembler* masm) {
1439 // We check the stack limit as indicator that recompilation might be done.
1440 Label ok;
1441 __ LoadRoot(at, Heap::kStackLimitRootIndex);
1442 __ Branch(&ok, hs, sp, Operand(at));
1443 {
1444 FrameScope scope(masm, StackFrame::INTERNAL);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001445 __ CallRuntime(Runtime::kStackGuard);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001446 }
1447 __ Jump(masm->isolate()->builtins()->OnStackReplacement(),
1448 RelocInfo::CODE_TARGET);
1449
1450 __ bind(&ok);
1451 __ Ret();
Andrei Popescu31002712010-02-23 13:46:05 +00001452}
1453
1454
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001455// static
1456void Builtins::Generate_DatePrototype_GetField(MacroAssembler* masm,
1457 int field_index) {
1458 // ----------- S t a t e -------------
1459 // -- sp[0] : receiver
1460 // -----------------------------------
1461
1462 // 1. Pop receiver into a0 and check that it's actually a JSDate object.
1463 Label receiver_not_date;
1464 {
1465 __ Pop(a0);
1466 __ JumpIfSmi(a0, &receiver_not_date);
1467 __ GetObjectType(a0, t0, t0);
1468 __ Branch(&receiver_not_date, ne, t0, Operand(JS_DATE_TYPE));
1469 }
1470
1471 // 2. Load the specified date field, falling back to the runtime as necessary.
1472 if (field_index == JSDate::kDateValue) {
1473 __ Ret(USE_DELAY_SLOT);
1474 __ lw(v0, FieldMemOperand(a0, JSDate::kValueOffset)); // In delay slot.
1475 } else {
1476 if (field_index < JSDate::kFirstUncachedField) {
1477 Label stamp_mismatch;
1478 __ li(a1, Operand(ExternalReference::date_cache_stamp(masm->isolate())));
1479 __ lw(a1, MemOperand(a1));
1480 __ lw(t0, FieldMemOperand(a0, JSDate::kCacheStampOffset));
1481 __ Branch(&stamp_mismatch, ne, t0, Operand(a1));
1482 __ Ret(USE_DELAY_SLOT);
1483 __ lw(v0, FieldMemOperand(
1484 a0, JSDate::kValueOffset +
1485 field_index * kPointerSize)); // In delay slot.
1486 __ bind(&stamp_mismatch);
1487 }
1488 FrameScope scope(masm, StackFrame::INTERNAL);
1489 __ PrepareCallCFunction(2, t0);
1490 __ li(a1, Operand(Smi::FromInt(field_index)));
1491 __ CallCFunction(
1492 ExternalReference::get_date_field_function(masm->isolate()), 2);
1493 }
1494 __ Ret();
1495
1496 // 3. Raise a TypeError if the receiver is not a date.
1497 __ bind(&receiver_not_date);
1498 __ TailCallRuntime(Runtime::kThrowNotDateError);
1499}
1500
1501
1502// static
1503void Builtins::Generate_FunctionPrototypeApply(MacroAssembler* masm) {
1504 // ----------- S t a t e -------------
1505 // -- a0 : argc
1506 // -- sp[0] : argArray
1507 // -- sp[4] : thisArg
1508 // -- sp[8] : receiver
1509 // -----------------------------------
1510
1511 // 1. Load receiver into a1, argArray into a0 (if present), remove all
1512 // arguments from the stack (including the receiver), and push thisArg (if
1513 // present) instead.
1514 {
1515 Label no_arg;
1516 Register scratch = t0;
1517 __ LoadRoot(a2, Heap::kUndefinedValueRootIndex);
1518 __ mov(a3, a2);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001519 // Lsa() cannot be used hare as scratch value used later.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001520 __ sll(scratch, a0, kPointerSizeLog2);
1521 __ Addu(a0, sp, Operand(scratch));
1522 __ lw(a1, MemOperand(a0)); // receiver
1523 __ Subu(a0, a0, Operand(kPointerSize));
1524 __ Branch(&no_arg, lt, a0, Operand(sp));
1525 __ lw(a2, MemOperand(a0)); // thisArg
1526 __ Subu(a0, a0, Operand(kPointerSize));
1527 __ Branch(&no_arg, lt, a0, Operand(sp));
1528 __ lw(a3, MemOperand(a0)); // argArray
1529 __ bind(&no_arg);
1530 __ Addu(sp, sp, Operand(scratch));
1531 __ sw(a2, MemOperand(sp));
1532 __ mov(a0, a3);
1533 }
1534
1535 // ----------- S t a t e -------------
1536 // -- a0 : argArray
1537 // -- a1 : receiver
1538 // -- sp[0] : thisArg
1539 // -----------------------------------
1540
1541 // 2. Make sure the receiver is actually callable.
1542 Label receiver_not_callable;
1543 __ JumpIfSmi(a1, &receiver_not_callable);
1544 __ lw(t0, FieldMemOperand(a1, HeapObject::kMapOffset));
1545 __ lbu(t0, FieldMemOperand(t0, Map::kBitFieldOffset));
1546 __ And(t0, t0, Operand(1 << Map::kIsCallable));
1547 __ Branch(&receiver_not_callable, eq, t0, Operand(zero_reg));
1548
1549 // 3. Tail call with no arguments if argArray is null or undefined.
1550 Label no_arguments;
1551 __ JumpIfRoot(a0, Heap::kNullValueRootIndex, &no_arguments);
1552 __ JumpIfRoot(a0, Heap::kUndefinedValueRootIndex, &no_arguments);
1553
1554 // 4a. Apply the receiver to the given argArray (passing undefined for
1555 // new.target).
1556 __ LoadRoot(a3, Heap::kUndefinedValueRootIndex);
1557 __ Jump(masm->isolate()->builtins()->Apply(), RelocInfo::CODE_TARGET);
1558
1559 // 4b. The argArray is either null or undefined, so we tail call without any
1560 // arguments to the receiver.
1561 __ bind(&no_arguments);
1562 {
1563 __ mov(a0, zero_reg);
1564 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
1565 }
1566
1567 // 4c. The receiver is not callable, throw an appropriate TypeError.
1568 __ bind(&receiver_not_callable);
1569 {
1570 __ sw(a1, MemOperand(sp));
1571 __ TailCallRuntime(Runtime::kThrowApplyNonFunction);
1572 }
1573}
1574
1575
1576// static
1577void Builtins::Generate_FunctionPrototypeCall(MacroAssembler* masm) {
Ben Murdoch257744e2011-11-30 15:57:28 +00001578 // 1. Make sure we have at least one argument.
1579 // a0: actual number of arguments
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001580 {
1581 Label done;
Ben Murdoch257744e2011-11-30 15:57:28 +00001582 __ Branch(&done, ne, a0, Operand(zero_reg));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001583 __ PushRoot(Heap::kUndefinedValueRootIndex);
Ben Murdoch257744e2011-11-30 15:57:28 +00001584 __ Addu(a0, a0, Operand(1));
1585 __ bind(&done);
1586 }
1587
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001588 // 2. Get the function to call (passed as receiver) from the stack.
Ben Murdoch257744e2011-11-30 15:57:28 +00001589 // a0: actual number of arguments
Ben Murdoch097c5b22016-05-18 11:27:45 +01001590 __ Lsa(at, sp, a0, kPointerSizeLog2);
Ben Murdoch257744e2011-11-30 15:57:28 +00001591 __ lw(a1, MemOperand(at));
Ben Murdoch257744e2011-11-30 15:57:28 +00001592
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001593 // 3. Shift arguments and return address one slot down on the stack
Ben Murdoch257744e2011-11-30 15:57:28 +00001594 // (overwriting the original receiver). Adjust argument count to make
1595 // the original first argument the new receiver.
1596 // a0: actual number of arguments
1597 // a1: function
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001598 {
1599 Label loop;
Ben Murdoch257744e2011-11-30 15:57:28 +00001600 // Calculate the copy start address (destination). Copy end address is sp.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001601 __ Lsa(a2, sp, a0, kPointerSizeLog2);
Ben Murdoch257744e2011-11-30 15:57:28 +00001602
1603 __ bind(&loop);
1604 __ lw(at, MemOperand(a2, -kPointerSize));
1605 __ sw(at, MemOperand(a2));
1606 __ Subu(a2, a2, Operand(kPointerSize));
1607 __ Branch(&loop, ne, a2, Operand(sp));
1608 // Adjust the actual number of arguments and remove the top element
1609 // (which is a copy of the last argument).
1610 __ Subu(a0, a0, Operand(1));
1611 __ Pop();
1612 }
1613
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001614 // 4. Call the callable.
1615 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
Andrei Popescu31002712010-02-23 13:46:05 +00001616}
1617
1618
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001619void Builtins::Generate_ReflectApply(MacroAssembler* masm) {
1620 // ----------- S t a t e -------------
1621 // -- a0 : argc
1622 // -- sp[0] : argumentsList
1623 // -- sp[4] : thisArgument
1624 // -- sp[8] : target
1625 // -- sp[12] : receiver
1626 // -----------------------------------
Ben Murdoch257744e2011-11-30 15:57:28 +00001627
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001628 // 1. Load target into a1 (if present), argumentsList into a0 (if present),
1629 // remove all arguments from the stack (including the receiver), and push
1630 // thisArgument (if present) instead.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001631 {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001632 Label no_arg;
1633 Register scratch = t0;
1634 __ LoadRoot(a1, Heap::kUndefinedValueRootIndex);
1635 __ mov(a2, a1);
1636 __ mov(a3, a1);
1637 __ sll(scratch, a0, kPointerSizeLog2);
1638 __ mov(a0, scratch);
1639 __ Subu(a0, a0, Operand(kPointerSize));
1640 __ Branch(&no_arg, lt, a0, Operand(zero_reg));
1641 __ Addu(a0, sp, Operand(a0));
1642 __ lw(a1, MemOperand(a0)); // target
1643 __ Subu(a0, a0, Operand(kPointerSize));
1644 __ Branch(&no_arg, lt, a0, Operand(sp));
1645 __ lw(a2, MemOperand(a0)); // thisArgument
1646 __ Subu(a0, a0, Operand(kPointerSize));
1647 __ Branch(&no_arg, lt, a0, Operand(sp));
1648 __ lw(a3, MemOperand(a0)); // argumentsList
1649 __ bind(&no_arg);
1650 __ Addu(sp, sp, Operand(scratch));
1651 __ sw(a2, MemOperand(sp));
1652 __ mov(a0, a3);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001653 }
1654
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001655 // ----------- S t a t e -------------
1656 // -- a0 : argumentsList
1657 // -- a1 : target
1658 // -- sp[0] : thisArgument
1659 // -----------------------------------
1660
1661 // 2. Make sure the target is actually callable.
1662 Label target_not_callable;
1663 __ JumpIfSmi(a1, &target_not_callable);
1664 __ lw(t0, FieldMemOperand(a1, HeapObject::kMapOffset));
1665 __ lbu(t0, FieldMemOperand(t0, Map::kBitFieldOffset));
1666 __ And(t0, t0, Operand(1 << Map::kIsCallable));
1667 __ Branch(&target_not_callable, eq, t0, Operand(zero_reg));
1668
1669 // 3a. Apply the target to the given argumentsList (passing undefined for
1670 // new.target).
1671 __ LoadRoot(a3, Heap::kUndefinedValueRootIndex);
1672 __ Jump(masm->isolate()->builtins()->Apply(), RelocInfo::CODE_TARGET);
1673
1674 // 3b. The target is not callable, throw an appropriate TypeError.
1675 __ bind(&target_not_callable);
1676 {
1677 __ sw(a1, MemOperand(sp));
1678 __ TailCallRuntime(Runtime::kThrowApplyNonFunction);
1679 }
1680}
1681
1682
1683void Builtins::Generate_ReflectConstruct(MacroAssembler* masm) {
1684 // ----------- S t a t e -------------
1685 // -- a0 : argc
1686 // -- sp[0] : new.target (optional)
1687 // -- sp[4] : argumentsList
1688 // -- sp[8] : target
1689 // -- sp[12] : receiver
1690 // -----------------------------------
1691
1692 // 1. Load target into a1 (if present), argumentsList into a0 (if present),
1693 // new.target into a3 (if present, otherwise use target), remove all
1694 // arguments from the stack (including the receiver), and push thisArgument
1695 // (if present) instead.
1696 {
1697 Label no_arg;
1698 Register scratch = t0;
1699 __ LoadRoot(a1, Heap::kUndefinedValueRootIndex);
1700 __ mov(a2, a1);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001701 // Lsa() cannot be used hare as scratch value used later.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001702 __ sll(scratch, a0, kPointerSizeLog2);
1703 __ Addu(a0, sp, Operand(scratch));
1704 __ sw(a2, MemOperand(a0)); // receiver
1705 __ Subu(a0, a0, Operand(kPointerSize));
1706 __ Branch(&no_arg, lt, a0, Operand(sp));
1707 __ lw(a1, MemOperand(a0)); // target
1708 __ mov(a3, a1); // new.target defaults to target
1709 __ Subu(a0, a0, Operand(kPointerSize));
1710 __ Branch(&no_arg, lt, a0, Operand(sp));
1711 __ lw(a2, MemOperand(a0)); // argumentsList
1712 __ Subu(a0, a0, Operand(kPointerSize));
1713 __ Branch(&no_arg, lt, a0, Operand(sp));
1714 __ lw(a3, MemOperand(a0)); // new.target
1715 __ bind(&no_arg);
1716 __ Addu(sp, sp, Operand(scratch));
1717 __ mov(a0, a2);
1718 }
1719
1720 // ----------- S t a t e -------------
1721 // -- a0 : argumentsList
1722 // -- a3 : new.target
1723 // -- a1 : target
1724 // -- sp[0] : receiver (undefined)
1725 // -----------------------------------
1726
1727 // 2. Make sure the target is actually a constructor.
1728 Label target_not_constructor;
1729 __ JumpIfSmi(a1, &target_not_constructor);
1730 __ lw(t0, FieldMemOperand(a1, HeapObject::kMapOffset));
1731 __ lbu(t0, FieldMemOperand(t0, Map::kBitFieldOffset));
1732 __ And(t0, t0, Operand(1 << Map::kIsConstructor));
1733 __ Branch(&target_not_constructor, eq, t0, Operand(zero_reg));
1734
1735 // 3. Make sure the target is actually a constructor.
1736 Label new_target_not_constructor;
1737 __ JumpIfSmi(a3, &new_target_not_constructor);
1738 __ lw(t0, FieldMemOperand(a3, HeapObject::kMapOffset));
1739 __ lbu(t0, FieldMemOperand(t0, Map::kBitFieldOffset));
1740 __ And(t0, t0, Operand(1 << Map::kIsConstructor));
1741 __ Branch(&new_target_not_constructor, eq, t0, Operand(zero_reg));
1742
1743 // 4a. Construct the target with the given new.target and argumentsList.
1744 __ Jump(masm->isolate()->builtins()->Apply(), RelocInfo::CODE_TARGET);
1745
1746 // 4b. The target is not a constructor, throw an appropriate TypeError.
1747 __ bind(&target_not_constructor);
1748 {
1749 __ sw(a1, MemOperand(sp));
1750 __ TailCallRuntime(Runtime::kThrowCalledNonCallable);
1751 }
1752
1753 // 4c. The new.target is not a constructor, throw an appropriate TypeError.
1754 __ bind(&new_target_not_constructor);
1755 {
1756 __ sw(a3, MemOperand(sp));
1757 __ TailCallRuntime(Runtime::kThrowCalledNonCallable);
1758 }
Ben Murdoch257744e2011-11-30 15:57:28 +00001759}
1760
1761
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001762static void ArgumentAdaptorStackCheck(MacroAssembler* masm,
1763 Label* stack_overflow) {
1764 // ----------- S t a t e -------------
1765 // -- a0 : actual number of arguments
1766 // -- a1 : function (passed through to callee)
1767 // -- a2 : expected number of arguments
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001768 // -- a3 : new target (passed through to callee)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001769 // -----------------------------------
1770 // Check the stack for overflow. We are not trying to catch
1771 // interruptions (e.g. debug break and preemption) here, so the "real stack
1772 // limit" is checked.
1773 __ LoadRoot(t1, Heap::kRealStackLimitRootIndex);
1774 // Make t1 the space we have left. The stack might already be overflowed
1775 // here which will cause t1 to become negative.
1776 __ subu(t1, sp, t1);
1777 // Check if the arguments will overflow the stack.
1778 __ sll(at, a2, kPointerSizeLog2);
1779 // Signed comparison.
1780 __ Branch(stack_overflow, le, t1, Operand(at));
1781}
1782
1783
Ben Murdoch257744e2011-11-30 15:57:28 +00001784static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) {
1785 __ sll(a0, a0, kSmiTagSize);
1786 __ li(t0, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1787 __ MultiPush(a0.bit() | a1.bit() | t0.bit() | fp.bit() | ra.bit());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001788 __ Addu(fp, sp,
1789 Operand(StandardFrameConstants::kFixedFrameSizeFromFp + kPointerSize));
Ben Murdoch257744e2011-11-30 15:57:28 +00001790}
1791
1792
1793static void LeaveArgumentsAdaptorFrame(MacroAssembler* masm) {
1794 // ----------- S t a t e -------------
1795 // -- v0 : result being passed through
1796 // -----------------------------------
1797 // Get the number of arguments passed (as a smi), tear down the frame and
1798 // then tear down the parameters.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001799 __ lw(a1, MemOperand(fp, -(StandardFrameConstants::kFixedFrameSizeFromFp +
1800 kPointerSize)));
Ben Murdoch257744e2011-11-30 15:57:28 +00001801 __ mov(sp, fp);
1802 __ MultiPop(fp.bit() | ra.bit());
Ben Murdoch097c5b22016-05-18 11:27:45 +01001803 __ Lsa(sp, sp, a1, kPointerSizeLog2 - kSmiTagSize);
Ben Murdoch257744e2011-11-30 15:57:28 +00001804 // Adjust for the receiver.
1805 __ Addu(sp, sp, Operand(kPointerSize));
Andrei Popescu31002712010-02-23 13:46:05 +00001806}
1807
1808
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001809// static
1810void Builtins::Generate_Apply(MacroAssembler* masm) {
1811 // ----------- S t a t e -------------
1812 // -- a0 : argumentsList
1813 // -- a1 : target
1814 // -- a3 : new.target (checked to be constructor or undefined)
1815 // -- sp[0] : thisArgument
1816 // -----------------------------------
1817
1818 // Create the list of arguments from the array-like argumentsList.
1819 {
1820 Label create_arguments, create_array, create_runtime, done_create;
1821 __ JumpIfSmi(a0, &create_runtime);
1822
1823 // Load the map of argumentsList into a2.
1824 __ lw(a2, FieldMemOperand(a0, HeapObject::kMapOffset));
1825
1826 // Load native context into t0.
1827 __ lw(t0, NativeContextMemOperand());
1828
1829 // Check if argumentsList is an (unmodified) arguments object.
1830 __ lw(at, ContextMemOperand(t0, Context::SLOPPY_ARGUMENTS_MAP_INDEX));
1831 __ Branch(&create_arguments, eq, a2, Operand(at));
1832 __ lw(at, ContextMemOperand(t0, Context::STRICT_ARGUMENTS_MAP_INDEX));
1833 __ Branch(&create_arguments, eq, a2, Operand(at));
1834
1835 // Check if argumentsList is a fast JSArray.
1836 __ lw(v0, FieldMemOperand(a2, HeapObject::kMapOffset));
1837 __ lbu(v0, FieldMemOperand(v0, Map::kInstanceTypeOffset));
1838 __ Branch(&create_array, eq, v0, Operand(JS_ARRAY_TYPE));
1839
1840 // Ask the runtime to create the list (actually a FixedArray).
1841 __ bind(&create_runtime);
1842 {
1843 FrameScope scope(masm, StackFrame::INTERNAL);
1844 __ Push(a1, a3, a0);
1845 __ CallRuntime(Runtime::kCreateListFromArrayLike);
1846 __ mov(a0, v0);
1847 __ Pop(a1, a3);
1848 __ lw(a2, FieldMemOperand(v0, FixedArray::kLengthOffset));
1849 __ SmiUntag(a2);
1850 }
1851 __ Branch(&done_create);
1852
1853 // Try to create the list from an arguments object.
1854 __ bind(&create_arguments);
Ben Murdoch097c5b22016-05-18 11:27:45 +01001855 __ lw(a2, FieldMemOperand(a0, JSArgumentsObject::kLengthOffset));
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001856 __ lw(t0, FieldMemOperand(a0, JSObject::kElementsOffset));
1857 __ lw(at, FieldMemOperand(t0, FixedArray::kLengthOffset));
1858 __ Branch(&create_runtime, ne, a2, Operand(at));
1859 __ SmiUntag(a2);
1860 __ mov(a0, t0);
1861 __ Branch(&done_create);
1862
1863 // Try to create the list from a JSArray object.
1864 __ bind(&create_array);
1865 __ lw(a2, FieldMemOperand(a2, Map::kBitField2Offset));
1866 __ DecodeField<Map::ElementsKindBits>(a2);
1867 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
1868 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
1869 STATIC_ASSERT(FAST_ELEMENTS == 2);
1870 __ Branch(&create_runtime, hi, a2, Operand(FAST_ELEMENTS));
1871 __ Branch(&create_runtime, eq, a2, Operand(FAST_HOLEY_SMI_ELEMENTS));
1872 __ lw(a2, FieldMemOperand(a0, JSArray::kLengthOffset));
1873 __ lw(a0, FieldMemOperand(a0, JSArray::kElementsOffset));
1874 __ SmiUntag(a2);
1875
1876 __ bind(&done_create);
1877 }
1878
1879 // Check for stack overflow.
1880 {
1881 // Check the stack for overflow. We are not trying to catch interruptions
1882 // (i.e. debug break and preemption) here, so check the "real stack limit".
1883 Label done;
1884 __ LoadRoot(t0, Heap::kRealStackLimitRootIndex);
1885 // Make ip the space we have left. The stack might already be overflowed
1886 // here which will cause ip to become negative.
1887 __ Subu(t0, sp, t0);
1888 // Check if the arguments will overflow the stack.
1889 __ sll(at, a2, kPointerSizeLog2);
1890 __ Branch(&done, gt, t0, Operand(at)); // Signed comparison.
1891 __ TailCallRuntime(Runtime::kThrowStackOverflow);
1892 __ bind(&done);
1893 }
1894
1895 // ----------- S t a t e -------------
1896 // -- a1 : target
1897 // -- a0 : args (a FixedArray built from argumentsList)
1898 // -- a2 : len (number of elements to push from args)
1899 // -- a3 : new.target (checked to be constructor or undefined)
1900 // -- sp[0] : thisArgument
1901 // -----------------------------------
1902
1903 // Push arguments onto the stack (thisArgument is already on the stack).
1904 {
1905 __ mov(t0, zero_reg);
1906 Label done, loop;
1907 __ bind(&loop);
1908 __ Branch(&done, eq, t0, Operand(a2));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001909 __ Lsa(at, a0, t0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001910 __ lw(at, FieldMemOperand(at, FixedArray::kHeaderSize));
1911 __ Push(at);
1912 __ Addu(t0, t0, Operand(1));
1913 __ Branch(&loop);
1914 __ bind(&done);
1915 __ Move(a0, t0);
1916 }
1917
1918 // Dispatch to Call or Construct depending on whether new.target is undefined.
1919 {
1920 Label construct;
1921 __ LoadRoot(at, Heap::kUndefinedValueRootIndex);
1922 __ Branch(&construct, ne, a3, Operand(at));
1923 __ Jump(masm->isolate()->builtins()->Call(), RelocInfo::CODE_TARGET);
1924 __ bind(&construct);
1925 __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET);
1926 }
1927}
1928
Ben Murdoch097c5b22016-05-18 11:27:45 +01001929namespace {
1930
1931// Drops top JavaScript frame and an arguments adaptor frame below it (if
1932// present) preserving all the arguments prepared for current call.
1933// Does nothing if debugger is currently active.
1934// ES6 14.6.3. PrepareForTailCall
1935//
1936// Stack structure for the function g() tail calling f():
1937//
1938// ------- Caller frame: -------
1939// | ...
1940// | g()'s arg M
1941// | ...
1942// | g()'s arg 1
1943// | g()'s receiver arg
1944// | g()'s caller pc
1945// ------- g()'s frame: -------
1946// | g()'s caller fp <- fp
1947// | g()'s context
1948// | function pointer: g
1949// | -------------------------
1950// | ...
1951// | ...
1952// | f()'s arg N
1953// | ...
1954// | f()'s arg 1
1955// | f()'s receiver arg <- sp (f()'s caller pc is not on the stack yet!)
1956// ----------------------
1957//
1958void PrepareForTailCall(MacroAssembler* masm, Register args_reg,
1959 Register scratch1, Register scratch2,
1960 Register scratch3) {
1961 DCHECK(!AreAliased(args_reg, scratch1, scratch2, scratch3));
1962 Comment cmnt(masm, "[ PrepareForTailCall");
1963
1964 // Prepare for tail call only if the debugger is not active.
1965 Label done;
1966 ExternalReference debug_is_active =
1967 ExternalReference::debug_is_active_address(masm->isolate());
1968 __ li(at, Operand(debug_is_active));
1969 __ lb(scratch1, MemOperand(at));
1970 __ Branch(&done, ne, scratch1, Operand(zero_reg));
1971
1972 // Drop possible interpreter handler/stub frame.
1973 {
1974 Label no_interpreter_frame;
1975 __ lw(scratch3, MemOperand(fp, StandardFrameConstants::kMarkerOffset));
1976 __ Branch(&no_interpreter_frame, ne, scratch3,
1977 Operand(Smi::FromInt(StackFrame::STUB)));
1978 __ lw(fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1979 __ bind(&no_interpreter_frame);
1980 }
1981
1982 // Check if next frame is an arguments adaptor frame.
1983 Label no_arguments_adaptor, formal_parameter_count_loaded;
1984 __ lw(scratch2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
1985 __ lw(scratch3, MemOperand(scratch2, StandardFrameConstants::kContextOffset));
1986 __ Branch(&no_arguments_adaptor, ne, scratch3,
1987 Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR)));
1988
1989 // Drop arguments adaptor frame and load arguments count.
1990 __ mov(fp, scratch2);
1991 __ lw(scratch1,
1992 MemOperand(fp, ArgumentsAdaptorFrameConstants::kLengthOffset));
1993 __ SmiUntag(scratch1);
1994 __ Branch(&formal_parameter_count_loaded);
1995
1996 __ bind(&no_arguments_adaptor);
1997 // Load caller's formal parameter count
1998 __ lw(scratch1, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
1999 __ lw(scratch1,
2000 FieldMemOperand(scratch1, JSFunction::kSharedFunctionInfoOffset));
2001 __ lw(scratch1,
2002 FieldMemOperand(scratch1,
2003 SharedFunctionInfo::kFormalParameterCountOffset));
2004 __ SmiUntag(scratch1);
2005
2006 __ bind(&formal_parameter_count_loaded);
2007
2008 // Calculate the end of destination area where we will put the arguments
2009 // after we drop current frame. We add kPointerSize to count the receiver
2010 // argument which is not included into formal parameters count.
2011 Register dst_reg = scratch2;
2012 __ Lsa(dst_reg, fp, scratch1, kPointerSizeLog2);
2013 __ Addu(dst_reg, dst_reg,
2014 Operand(StandardFrameConstants::kCallerSPOffset + kPointerSize));
2015
2016 Register src_reg = scratch1;
2017 __ Lsa(src_reg, sp, args_reg, kPointerSizeLog2);
2018 // Count receiver argument as well (not included in args_reg).
2019 __ Addu(src_reg, src_reg, Operand(kPointerSize));
2020
2021 if (FLAG_debug_code) {
2022 __ Check(lo, kStackAccessBelowStackPointer, src_reg, Operand(dst_reg));
2023 }
2024
2025 // Restore caller's frame pointer and return address now as they will be
2026 // overwritten by the copying loop.
2027 __ lw(ra, MemOperand(fp, StandardFrameConstants::kCallerPCOffset));
2028 __ lw(fp, MemOperand(fp, StandardFrameConstants::kCallerFPOffset));
2029
2030 // Now copy callee arguments to the caller frame going backwards to avoid
2031 // callee arguments corruption (source and destination areas could overlap).
2032
2033 // Both src_reg and dst_reg are pointing to the word after the one to copy,
2034 // so they must be pre-decremented in the loop.
2035 Register tmp_reg = scratch3;
2036 Label loop, entry;
2037 __ Branch(&entry);
2038 __ bind(&loop);
2039 __ Subu(src_reg, src_reg, Operand(kPointerSize));
2040 __ Subu(dst_reg, dst_reg, Operand(kPointerSize));
2041 __ lw(tmp_reg, MemOperand(src_reg));
2042 __ sw(tmp_reg, MemOperand(dst_reg));
2043 __ bind(&entry);
2044 __ Branch(&loop, ne, sp, Operand(src_reg));
2045
2046 // Leave current frame.
2047 __ mov(sp, dst_reg);
2048
2049 __ bind(&done);
2050}
2051} // namespace
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002052
2053// static
2054void Builtins::Generate_CallFunction(MacroAssembler* masm,
Ben Murdoch097c5b22016-05-18 11:27:45 +01002055 ConvertReceiverMode mode,
2056 TailCallMode tail_call_mode) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002057 // ----------- S t a t e -------------
2058 // -- a0 : the number of arguments (not including the receiver)
2059 // -- a1 : the function to call (checked to be a JSFunction)
2060 // -----------------------------------
2061 __ AssertFunction(a1);
2062
2063 // See ES6 section 9.2.1 [[Call]] ( thisArgument, argumentsList)
2064 // Check that the function is not a "classConstructor".
2065 Label class_constructor;
2066 __ lw(a2, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2067 __ lbu(a3, FieldMemOperand(a2, SharedFunctionInfo::kFunctionKindByteOffset));
2068 __ And(at, a3, Operand(SharedFunctionInfo::kClassConstructorBitsWithinByte));
2069 __ Branch(&class_constructor, ne, at, Operand(zero_reg));
2070
2071 // Enter the context of the function; ToObject has to run in the function
2072 // context, and we also need to take the global proxy from the function
2073 // context in case of conversion.
2074 STATIC_ASSERT(SharedFunctionInfo::kNativeByteOffset ==
2075 SharedFunctionInfo::kStrictModeByteOffset);
2076 __ lw(cp, FieldMemOperand(a1, JSFunction::kContextOffset));
2077 // We need to convert the receiver for non-native sloppy mode functions.
2078 Label done_convert;
2079 __ lbu(a3, FieldMemOperand(a2, SharedFunctionInfo::kNativeByteOffset));
2080 __ And(at, a3, Operand((1 << SharedFunctionInfo::kNativeBitWithinByte) |
2081 (1 << SharedFunctionInfo::kStrictModeBitWithinByte)));
2082 __ Branch(&done_convert, ne, at, Operand(zero_reg));
2083 {
2084 // ----------- S t a t e -------------
2085 // -- a0 : the number of arguments (not including the receiver)
2086 // -- a1 : the function to call (checked to be a JSFunction)
2087 // -- a2 : the shared function info.
2088 // -- cp : the function context.
2089 // -----------------------------------
2090
2091 if (mode == ConvertReceiverMode::kNullOrUndefined) {
2092 // Patch receiver to global proxy.
2093 __ LoadGlobalProxy(a3);
2094 } else {
2095 Label convert_to_object, convert_receiver;
Ben Murdoch097c5b22016-05-18 11:27:45 +01002096 __ Lsa(at, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002097 __ lw(a3, MemOperand(at));
2098 __ JumpIfSmi(a3, &convert_to_object);
2099 STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE);
2100 __ GetObjectType(a3, t0, t0);
2101 __ Branch(&done_convert, hs, t0, Operand(FIRST_JS_RECEIVER_TYPE));
2102 if (mode != ConvertReceiverMode::kNotNullOrUndefined) {
2103 Label convert_global_proxy;
2104 __ JumpIfRoot(a3, Heap::kUndefinedValueRootIndex,
2105 &convert_global_proxy);
2106 __ JumpIfNotRoot(a3, Heap::kNullValueRootIndex, &convert_to_object);
2107 __ bind(&convert_global_proxy);
2108 {
2109 // Patch receiver to global proxy.
2110 __ LoadGlobalProxy(a3);
2111 }
2112 __ Branch(&convert_receiver);
2113 }
2114 __ bind(&convert_to_object);
2115 {
2116 // Convert receiver using ToObject.
2117 // TODO(bmeurer): Inline the allocation here to avoid building the frame
2118 // in the fast case? (fall back to AllocateInNewSpace?)
2119 FrameScope scope(masm, StackFrame::INTERNAL);
2120 __ sll(a0, a0, kSmiTagSize); // Smi tagged.
2121 __ Push(a0, a1);
2122 __ mov(a0, a3);
2123 ToObjectStub stub(masm->isolate());
2124 __ CallStub(&stub);
2125 __ mov(a3, v0);
2126 __ Pop(a0, a1);
2127 __ sra(a0, a0, kSmiTagSize); // Un-tag.
2128 }
2129 __ lw(a2, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2130 __ bind(&convert_receiver);
2131 }
Ben Murdoch097c5b22016-05-18 11:27:45 +01002132 __ Lsa(at, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002133 __ sw(a3, MemOperand(at));
2134 }
2135 __ bind(&done_convert);
2136
2137 // ----------- S t a t e -------------
2138 // -- a0 : the number of arguments (not including the receiver)
2139 // -- a1 : the function to call (checked to be a JSFunction)
2140 // -- a2 : the shared function info.
2141 // -- cp : the function context.
2142 // -----------------------------------
2143
Ben Murdoch097c5b22016-05-18 11:27:45 +01002144 if (tail_call_mode == TailCallMode::kAllow) {
2145 PrepareForTailCall(masm, a0, t0, t1, t2);
2146 }
2147
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002148 __ lw(a2,
2149 FieldMemOperand(a2, SharedFunctionInfo::kFormalParameterCountOffset));
2150 __ sra(a2, a2, kSmiTagSize); // Un-tag.
2151 ParameterCount actual(a0);
2152 ParameterCount expected(a2);
2153 __ InvokeFunctionCode(a1, no_reg, expected, actual, JUMP_FUNCTION,
2154 CheckDebugStepCallWrapper());
2155
2156 // The function is a "classConstructor", need to raise an exception.
2157 __ bind(&class_constructor);
2158 {
2159 FrameScope frame(masm, StackFrame::INTERNAL);
2160 __ Push(a1);
2161 __ CallRuntime(Runtime::kThrowConstructorNonCallableError);
2162 }
2163}
2164
2165
2166// static
Ben Murdoch097c5b22016-05-18 11:27:45 +01002167void Builtins::Generate_CallBoundFunctionImpl(MacroAssembler* masm,
2168 TailCallMode tail_call_mode) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002169 // ----------- S t a t e -------------
2170 // -- a0 : the number of arguments (not including the receiver)
2171 // -- a1 : the function to call (checked to be a JSBoundFunction)
2172 // -----------------------------------
2173 __ AssertBoundFunction(a1);
2174
Ben Murdoch097c5b22016-05-18 11:27:45 +01002175 if (tail_call_mode == TailCallMode::kAllow) {
2176 PrepareForTailCall(masm, a0, t0, t1, t2);
2177 }
2178
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002179 // Patch the receiver to [[BoundThis]].
2180 {
2181 __ lw(at, FieldMemOperand(a1, JSBoundFunction::kBoundThisOffset));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002182 __ Lsa(t0, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002183 __ sw(at, MemOperand(t0));
2184 }
2185
2186 // Load [[BoundArguments]] into a2 and length of that into t0.
2187 __ lw(a2, FieldMemOperand(a1, JSBoundFunction::kBoundArgumentsOffset));
2188 __ lw(t0, FieldMemOperand(a2, FixedArray::kLengthOffset));
2189 __ SmiUntag(t0);
2190
2191 // ----------- S t a t e -------------
2192 // -- a0 : the number of arguments (not including the receiver)
2193 // -- a1 : the function to call (checked to be a JSBoundFunction)
2194 // -- a2 : the [[BoundArguments]] (implemented as FixedArray)
2195 // -- t0 : the number of [[BoundArguments]]
2196 // -----------------------------------
2197
2198 // Reserve stack space for the [[BoundArguments]].
2199 {
2200 Label done;
2201 __ sll(t1, t0, kPointerSizeLog2);
2202 __ Subu(sp, sp, Operand(t1));
2203 // Check the stack for overflow. We are not trying to catch interruptions
2204 // (i.e. debug break and preemption) here, so check the "real stack limit".
2205 __ LoadRoot(at, Heap::kRealStackLimitRootIndex);
2206 __ Branch(&done, gt, sp, Operand(at)); // Signed comparison.
2207 // Restore the stack pointer.
2208 __ Addu(sp, sp, Operand(t1));
2209 {
2210 FrameScope scope(masm, StackFrame::MANUAL);
2211 __ EnterFrame(StackFrame::INTERNAL);
2212 __ CallRuntime(Runtime::kThrowStackOverflow);
2213 }
2214 __ bind(&done);
2215 }
2216
2217 // Relocate arguments down the stack.
2218 {
2219 Label loop, done_loop;
2220 __ mov(t1, zero_reg);
2221 __ bind(&loop);
2222 __ Branch(&done_loop, gt, t1, Operand(a0));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002223 __ Lsa(t2, sp, t0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002224 __ lw(at, MemOperand(t2));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002225 __ Lsa(t2, sp, t1, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002226 __ sw(at, MemOperand(t2));
2227 __ Addu(t0, t0, Operand(1));
2228 __ Addu(t1, t1, Operand(1));
2229 __ Branch(&loop);
2230 __ bind(&done_loop);
2231 }
2232
2233 // Copy [[BoundArguments]] to the stack (below the arguments).
2234 {
2235 Label loop, done_loop;
2236 __ lw(t0, FieldMemOperand(a2, FixedArray::kLengthOffset));
2237 __ SmiUntag(t0);
2238 __ Addu(a2, a2, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
2239 __ bind(&loop);
2240 __ Subu(t0, t0, Operand(1));
2241 __ Branch(&done_loop, lt, t0, Operand(zero_reg));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002242 __ Lsa(t1, a2, t0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002243 __ lw(at, MemOperand(t1));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002244 __ Lsa(t1, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002245 __ sw(at, MemOperand(t1));
2246 __ Addu(a0, a0, Operand(1));
2247 __ Branch(&loop);
2248 __ bind(&done_loop);
2249 }
2250
2251 // Call the [[BoundTargetFunction]] via the Call builtin.
2252 __ lw(a1, FieldMemOperand(a1, JSBoundFunction::kBoundTargetFunctionOffset));
2253 __ li(at, Operand(ExternalReference(Builtins::kCall_ReceiverIsAny,
2254 masm->isolate())));
2255 __ lw(at, MemOperand(at));
2256 __ Addu(at, at, Operand(Code::kHeaderSize - kHeapObjectTag));
2257 __ Jump(at);
2258}
2259
2260
2261// static
Ben Murdoch097c5b22016-05-18 11:27:45 +01002262void Builtins::Generate_Call(MacroAssembler* masm, ConvertReceiverMode mode,
2263 TailCallMode tail_call_mode) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002264 // ----------- S t a t e -------------
2265 // -- a0 : the number of arguments (not including the receiver)
2266 // -- a1 : the target to call (can be any Object).
2267 // -----------------------------------
2268
2269 Label non_callable, non_function, non_smi;
2270 __ JumpIfSmi(a1, &non_callable);
2271 __ bind(&non_smi);
2272 __ GetObjectType(a1, t1, t2);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002273 __ Jump(masm->isolate()->builtins()->CallFunction(mode, tail_call_mode),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002274 RelocInfo::CODE_TARGET, eq, t2, Operand(JS_FUNCTION_TYPE));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002275 __ Jump(masm->isolate()->builtins()->CallBoundFunction(tail_call_mode),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002276 RelocInfo::CODE_TARGET, eq, t2, Operand(JS_BOUND_FUNCTION_TYPE));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002277
2278 // Check if target has a [[Call]] internal method.
2279 __ lbu(t1, FieldMemOperand(t1, Map::kBitFieldOffset));
2280 __ And(t1, t1, Operand(1 << Map::kIsCallable));
2281 __ Branch(&non_callable, eq, t1, Operand(zero_reg));
2282
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002283 __ Branch(&non_function, ne, t2, Operand(JS_PROXY_TYPE));
2284
Ben Murdoch097c5b22016-05-18 11:27:45 +01002285 // 0. Prepare for tail call if necessary.
2286 if (tail_call_mode == TailCallMode::kAllow) {
2287 PrepareForTailCall(masm, a0, t0, t1, t2);
2288 }
2289
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002290 // 1. Runtime fallback for Proxy [[Call]].
2291 __ Push(a1);
2292 // Increase the arguments size to include the pushed function and the
2293 // existing receiver on the stack.
2294 __ Addu(a0, a0, 2);
2295 // Tail-call to the runtime.
2296 __ JumpToExternalReference(
2297 ExternalReference(Runtime::kJSProxyCall, masm->isolate()));
2298
2299 // 2. Call to something else, which might have a [[Call]] internal method (if
2300 // not we raise an exception).
2301 __ bind(&non_function);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002302 // Overwrite the original receiver with the (original) target.
Ben Murdoch097c5b22016-05-18 11:27:45 +01002303 __ Lsa(at, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002304 __ sw(a1, MemOperand(at));
2305 // Let the "call_as_function_delegate" take care of the rest.
2306 __ LoadNativeContextSlot(Context::CALL_AS_FUNCTION_DELEGATE_INDEX, a1);
2307 __ Jump(masm->isolate()->builtins()->CallFunction(
Ben Murdoch097c5b22016-05-18 11:27:45 +01002308 ConvertReceiverMode::kNotNullOrUndefined, tail_call_mode),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002309 RelocInfo::CODE_TARGET);
2310
2311 // 3. Call to something that is not callable.
2312 __ bind(&non_callable);
2313 {
2314 FrameScope scope(masm, StackFrame::INTERNAL);
2315 __ Push(a1);
2316 __ CallRuntime(Runtime::kThrowCalledNonCallable);
2317 }
2318}
2319
2320
2321// static
2322void Builtins::Generate_ConstructFunction(MacroAssembler* masm) {
2323 // ----------- S t a t e -------------
2324 // -- a0 : the number of arguments (not including the receiver)
2325 // -- a1 : the constructor to call (checked to be a JSFunction)
2326 // -- a3 : the new target (checked to be a constructor)
2327 // -----------------------------------
2328 __ AssertFunction(a1);
2329
2330 // Calling convention for function specific ConstructStubs require
2331 // a2 to contain either an AllocationSite or undefined.
2332 __ LoadRoot(a2, Heap::kUndefinedValueRootIndex);
2333
2334 // Tail call to the function-specific construct stub (still in the caller
2335 // context at this point).
2336 __ lw(t0, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2337 __ lw(t0, FieldMemOperand(t0, SharedFunctionInfo::kConstructStubOffset));
2338 __ Addu(at, t0, Operand(Code::kHeaderSize - kHeapObjectTag));
2339 __ Jump(at);
2340}
2341
2342
2343// static
2344void Builtins::Generate_ConstructBoundFunction(MacroAssembler* masm) {
2345 // ----------- S t a t e -------------
2346 // -- a0 : the number of arguments (not including the receiver)
2347 // -- a1 : the function to call (checked to be a JSBoundFunction)
2348 // -- a3 : the new target (checked to be a constructor)
2349 // -----------------------------------
2350 __ AssertBoundFunction(a1);
2351
2352 // Load [[BoundArguments]] into a2 and length of that into t0.
2353 __ lw(a2, FieldMemOperand(a1, JSBoundFunction::kBoundArgumentsOffset));
2354 __ lw(t0, FieldMemOperand(a2, FixedArray::kLengthOffset));
2355 __ SmiUntag(t0);
2356
2357 // ----------- S t a t e -------------
2358 // -- a0 : the number of arguments (not including the receiver)
2359 // -- a1 : the function to call (checked to be a JSBoundFunction)
2360 // -- a2 : the [[BoundArguments]] (implemented as FixedArray)
2361 // -- a3 : the new target (checked to be a constructor)
2362 // -- t0 : the number of [[BoundArguments]]
2363 // -----------------------------------
2364
2365 // Reserve stack space for the [[BoundArguments]].
2366 {
2367 Label done;
2368 __ sll(t1, t0, kPointerSizeLog2);
2369 __ Subu(sp, sp, Operand(t1));
2370 // Check the stack for overflow. We are not trying to catch interruptions
2371 // (i.e. debug break and preemption) here, so check the "real stack limit".
2372 __ LoadRoot(at, Heap::kRealStackLimitRootIndex);
2373 __ Branch(&done, gt, sp, Operand(at)); // Signed comparison.
2374 // Restore the stack pointer.
2375 __ Addu(sp, sp, Operand(t1));
2376 {
2377 FrameScope scope(masm, StackFrame::MANUAL);
2378 __ EnterFrame(StackFrame::INTERNAL);
2379 __ CallRuntime(Runtime::kThrowStackOverflow);
2380 }
2381 __ bind(&done);
2382 }
2383
2384 // Relocate arguments down the stack.
2385 {
2386 Label loop, done_loop;
2387 __ mov(t1, zero_reg);
2388 __ bind(&loop);
2389 __ Branch(&done_loop, ge, t1, Operand(a0));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002390 __ Lsa(t2, sp, t0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002391 __ lw(at, MemOperand(t2));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002392 __ Lsa(t2, sp, t1, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002393 __ sw(at, MemOperand(t2));
2394 __ Addu(t0, t0, Operand(1));
2395 __ Addu(t1, t1, Operand(1));
2396 __ Branch(&loop);
2397 __ bind(&done_loop);
2398 }
2399
2400 // Copy [[BoundArguments]] to the stack (below the arguments).
2401 {
2402 Label loop, done_loop;
2403 __ lw(t0, FieldMemOperand(a2, FixedArray::kLengthOffset));
2404 __ SmiUntag(t0);
2405 __ Addu(a2, a2, Operand(FixedArray::kHeaderSize - kHeapObjectTag));
2406 __ bind(&loop);
2407 __ Subu(t0, t0, Operand(1));
2408 __ Branch(&done_loop, lt, t0, Operand(zero_reg));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002409 __ Lsa(t1, a2, t0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002410 __ lw(at, MemOperand(t1));
Ben Murdoch097c5b22016-05-18 11:27:45 +01002411 __ Lsa(t1, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002412 __ sw(at, MemOperand(t1));
2413 __ Addu(a0, a0, Operand(1));
2414 __ Branch(&loop);
2415 __ bind(&done_loop);
2416 }
2417
2418 // Patch new.target to [[BoundTargetFunction]] if new.target equals target.
2419 {
2420 Label skip_load;
2421 __ Branch(&skip_load, ne, a1, Operand(a3));
2422 __ lw(a3, FieldMemOperand(a1, JSBoundFunction::kBoundTargetFunctionOffset));
2423 __ bind(&skip_load);
2424 }
2425
2426 // Construct the [[BoundTargetFunction]] via the Construct builtin.
2427 __ lw(a1, FieldMemOperand(a1, JSBoundFunction::kBoundTargetFunctionOffset));
2428 __ li(at, Operand(ExternalReference(Builtins::kConstruct, masm->isolate())));
2429 __ lw(at, MemOperand(at));
2430 __ Addu(at, at, Operand(Code::kHeaderSize - kHeapObjectTag));
2431 __ Jump(at);
2432}
2433
2434
2435// static
2436void Builtins::Generate_ConstructProxy(MacroAssembler* masm) {
2437 // ----------- S t a t e -------------
2438 // -- a0 : the number of arguments (not including the receiver)
2439 // -- a1 : the constructor to call (checked to be a JSProxy)
2440 // -- a3 : the new target (either the same as the constructor or
2441 // the JSFunction on which new was invoked initially)
2442 // -----------------------------------
2443
2444 // Call into the Runtime for Proxy [[Construct]].
2445 __ Push(a1, a3);
2446 // Include the pushed new_target, constructor and the receiver.
2447 __ Addu(a0, a0, Operand(3));
2448 // Tail-call to the runtime.
2449 __ JumpToExternalReference(
2450 ExternalReference(Runtime::kJSProxyConstruct, masm->isolate()));
2451}
2452
2453
2454// static
2455void Builtins::Generate_Construct(MacroAssembler* masm) {
2456 // ----------- S t a t e -------------
2457 // -- a0 : the number of arguments (not including the receiver)
2458 // -- a1 : the constructor to call (can be any Object)
2459 // -- a3 : the new target (either the same as the constructor or
2460 // the JSFunction on which new was invoked initially)
2461 // -----------------------------------
2462
2463 // Check if target is a Smi.
2464 Label non_constructor;
2465 __ JumpIfSmi(a1, &non_constructor);
2466
2467 // Dispatch based on instance type.
2468 __ lw(t1, FieldMemOperand(a1, HeapObject::kMapOffset));
2469 __ lbu(t2, FieldMemOperand(t1, Map::kInstanceTypeOffset));
2470 __ Jump(masm->isolate()->builtins()->ConstructFunction(),
2471 RelocInfo::CODE_TARGET, eq, t2, Operand(JS_FUNCTION_TYPE));
2472
2473 // Check if target has a [[Construct]] internal method.
2474 __ lbu(t3, FieldMemOperand(t1, Map::kBitFieldOffset));
2475 __ And(t3, t3, Operand(1 << Map::kIsConstructor));
2476 __ Branch(&non_constructor, eq, t3, Operand(zero_reg));
2477
2478 // Only dispatch to bound functions after checking whether they are
2479 // constructors.
2480 __ Jump(masm->isolate()->builtins()->ConstructBoundFunction(),
2481 RelocInfo::CODE_TARGET, eq, t2, Operand(JS_BOUND_FUNCTION_TYPE));
2482
2483 // Only dispatch to proxies after checking whether they are constructors.
2484 __ Jump(masm->isolate()->builtins()->ConstructProxy(), RelocInfo::CODE_TARGET,
2485 eq, t2, Operand(JS_PROXY_TYPE));
2486
2487 // Called Construct on an exotic Object with a [[Construct]] internal method.
2488 {
2489 // Overwrite the original receiver with the (original) target.
Ben Murdoch097c5b22016-05-18 11:27:45 +01002490 __ Lsa(at, sp, a0, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002491 __ sw(a1, MemOperand(at));
2492 // Let the "call_as_constructor_delegate" take care of the rest.
2493 __ LoadNativeContextSlot(Context::CALL_AS_CONSTRUCTOR_DELEGATE_INDEX, a1);
2494 __ Jump(masm->isolate()->builtins()->CallFunction(),
2495 RelocInfo::CODE_TARGET);
2496 }
2497
2498 // Called Construct on an Object that doesn't have a [[Construct]] internal
2499 // method.
2500 __ bind(&non_constructor);
2501 __ Jump(masm->isolate()->builtins()->ConstructedNonConstructable(),
2502 RelocInfo::CODE_TARGET);
2503}
2504
2505
Andrei Popescu31002712010-02-23 13:46:05 +00002506void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
Ben Murdoch257744e2011-11-30 15:57:28 +00002507 // State setup as expected by MacroAssembler::InvokePrologue.
2508 // ----------- S t a t e -------------
2509 // -- a0: actual arguments count
2510 // -- a1: function (passed through to callee)
2511 // -- a2: expected arguments count
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002512 // -- a3: new target (passed through to callee)
Ben Murdoch257744e2011-11-30 15:57:28 +00002513 // -----------------------------------
2514
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002515 Label invoke, dont_adapt_arguments, stack_overflow;
Ben Murdoch257744e2011-11-30 15:57:28 +00002516
2517 Label enough, too_few;
2518 __ Branch(&dont_adapt_arguments, eq,
2519 a2, Operand(SharedFunctionInfo::kDontAdaptArgumentsSentinel));
2520 // We use Uless as the number of argument should always be greater than 0.
2521 __ Branch(&too_few, Uless, a0, Operand(a2));
2522
2523 { // Enough parameters: actual >= expected.
2524 // a0: actual number of arguments as a smi
2525 // a1: function
2526 // a2: expected number of arguments
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002527 // a3: new target (passed through to callee)
Ben Murdoch257744e2011-11-30 15:57:28 +00002528 __ bind(&enough);
2529 EnterArgumentsAdaptorFrame(masm);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002530 ArgumentAdaptorStackCheck(masm, &stack_overflow);
Ben Murdoch257744e2011-11-30 15:57:28 +00002531
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002532 // Calculate copy start address into a0 and copy end address into t1.
Ben Murdoch097c5b22016-05-18 11:27:45 +01002533 __ Lsa(a0, fp, a0, kPointerSizeLog2 - kSmiTagSize);
Ben Murdoch257744e2011-11-30 15:57:28 +00002534 // Adjust for return address and receiver.
2535 __ Addu(a0, a0, Operand(2 * kPointerSize));
2536 // Compute copy end address.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002537 __ sll(t1, a2, kPointerSizeLog2);
2538 __ subu(t1, a0, t1);
Ben Murdoch257744e2011-11-30 15:57:28 +00002539
2540 // Copy the arguments (including the receiver) to the new stack frame.
2541 // a0: copy start address
2542 // a1: function
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002543 // a2: expected number of arguments
2544 // a3: new target (passed through to callee)
2545 // t1: copy end address
Ben Murdoch257744e2011-11-30 15:57:28 +00002546
2547 Label copy;
2548 __ bind(&copy);
2549 __ lw(t0, MemOperand(a0));
2550 __ push(t0);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002551 __ Branch(USE_DELAY_SLOT, &copy, ne, a0, Operand(t1));
Ben Murdoch257744e2011-11-30 15:57:28 +00002552 __ addiu(a0, a0, -kPointerSize); // In delay slot.
2553
2554 __ jmp(&invoke);
2555 }
2556
2557 { // Too few parameters: Actual < expected.
2558 __ bind(&too_few);
Ben Murdoch257744e2011-11-30 15:57:28 +00002559
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002560 // If the function is strong we need to throw an error.
2561 Label no_strong_error;
2562 __ lw(t1, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
2563 __ lw(t2, FieldMemOperand(t1, SharedFunctionInfo::kCompilerHintsOffset));
2564 __ And(t3, t2, Operand(1 << (SharedFunctionInfo::kStrongModeFunction +
2565 kSmiTagSize)));
2566 __ Branch(&no_strong_error, eq, t3, Operand(zero_reg));
2567
2568 // What we really care about is the required number of arguments.
2569 __ lw(t2, FieldMemOperand(t1, SharedFunctionInfo::kLengthOffset));
2570 __ SmiUntag(t2);
2571 __ Branch(&no_strong_error, ge, a0, Operand(t2));
2572
2573 {
2574 FrameScope frame(masm, StackFrame::MANUAL);
2575 EnterArgumentsAdaptorFrame(masm);
2576 __ CallRuntime(Runtime::kThrowStrongModeTooFewArguments);
2577 }
2578
2579 __ bind(&no_strong_error);
2580 EnterArgumentsAdaptorFrame(masm);
2581 ArgumentAdaptorStackCheck(masm, &stack_overflow);
2582
2583 // Calculate copy start address into a0 and copy end address into t3.
Ben Murdoch257744e2011-11-30 15:57:28 +00002584 // a0: actual number of arguments as a smi
2585 // a1: function
2586 // a2: expected number of arguments
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002587 // a3: new target (passed through to callee)
Ben Murdoch097c5b22016-05-18 11:27:45 +01002588 __ Lsa(a0, fp, a0, kPointerSizeLog2 - kSmiTagSize);
Ben Murdoch257744e2011-11-30 15:57:28 +00002589 // Adjust for return address and receiver.
2590 __ Addu(a0, a0, Operand(2 * kPointerSize));
2591 // Compute copy end address. Also adjust for return address.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002592 __ Addu(t3, fp, kPointerSize);
Ben Murdoch257744e2011-11-30 15:57:28 +00002593
2594 // Copy the arguments (including the receiver) to the new stack frame.
2595 // a0: copy start address
2596 // a1: function
2597 // a2: expected number of arguments
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002598 // a3: new target (passed through to callee)
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002599 // t3: copy end address
Ben Murdoch257744e2011-11-30 15:57:28 +00002600 Label copy;
2601 __ bind(&copy);
2602 __ lw(t0, MemOperand(a0)); // Adjusted above for return addr and receiver.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002603 __ Subu(sp, sp, kPointerSize);
Ben Murdoch257744e2011-11-30 15:57:28 +00002604 __ Subu(a0, a0, kPointerSize);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002605 __ Branch(USE_DELAY_SLOT, &copy, ne, a0, Operand(t3));
2606 __ sw(t0, MemOperand(sp)); // In the delay slot.
Ben Murdoch257744e2011-11-30 15:57:28 +00002607
2608 // Fill the remaining expected arguments with undefined.
2609 // a1: function
2610 // a2: expected number of arguments
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002611 // a3: new target (passed through to callee)
Ben Murdoch257744e2011-11-30 15:57:28 +00002612 __ LoadRoot(t0, Heap::kUndefinedValueRootIndex);
2613 __ sll(t2, a2, kPointerSizeLog2);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002614 __ Subu(t1, fp, Operand(t2));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002615 // Adjust for frame.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002616 __ Subu(t1, t1, Operand(StandardFrameConstants::kFixedFrameSizeFromFp +
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002617 2 * kPointerSize));
Ben Murdoch257744e2011-11-30 15:57:28 +00002618
2619 Label fill;
2620 __ bind(&fill);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002621 __ Subu(sp, sp, kPointerSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002622 __ Branch(USE_DELAY_SLOT, &fill, ne, sp, Operand(t1));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002623 __ sw(t0, MemOperand(sp));
Ben Murdoch257744e2011-11-30 15:57:28 +00002624 }
2625
2626 // Call the entry point.
2627 __ bind(&invoke);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002628 __ mov(a0, a2);
2629 // a0 : expected number of arguments
2630 // a1 : function (passed through to callee)
2631 // a3 : new target (passed through to callee)
2632 __ lw(t0, FieldMemOperand(a1, JSFunction::kCodeEntryOffset));
2633 __ Call(t0);
Ben Murdoch257744e2011-11-30 15:57:28 +00002634
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002635 // Store offset of return address for deoptimizer.
2636 masm->isolate()->heap()->SetArgumentsAdaptorDeoptPCOffset(masm->pc_offset());
2637
Ben Murdoch257744e2011-11-30 15:57:28 +00002638 // Exit frame and return.
2639 LeaveArgumentsAdaptorFrame(masm);
2640 __ Ret();
2641
2642
2643 // -------------------------------------------
2644 // Don't adapt arguments.
2645 // -------------------------------------------
2646 __ bind(&dont_adapt_arguments);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002647 __ lw(t0, FieldMemOperand(a1, JSFunction::kCodeEntryOffset));
2648 __ Jump(t0);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002649
2650 __ bind(&stack_overflow);
2651 {
2652 FrameScope frame(masm, StackFrame::MANUAL);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002653 __ CallRuntime(Runtime::kThrowStackOverflow);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002654 __ break_(0xCC);
2655 }
Andrei Popescu31002712010-02-23 13:46:05 +00002656}
2657
2658
2659#undef __
2660
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002661} // namespace internal
2662} // namespace v8
Andrei Popescu31002712010-02-23 13:46:05 +00002663
Leon Clarkef7060e22010-06-03 12:02:55 +01002664#endif // V8_TARGET_ARCH_MIPS