-
Notifications
You must be signed in to change notification settings - Fork 28.2k
/
builtins-s390.cc
3493 lines (2993 loc) Β· 129 KB
/
builtins-s390.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#if V8_TARGET_ARCH_S390
#include "src/api/api-arguments.h"
#include "src/codegen/code-factory.h"
#include "src/codegen/interface-descriptors-inl.h"
// For interpreter_entry_return_pc_offset. TODO(jkummerow): Drop.
#include "src/codegen/macro-assembler-inl.h"
#include "src/codegen/register-configuration.h"
#include "src/debug/debug.h"
#include "src/deoptimizer/deoptimizer.h"
#include "src/execution/frame-constants.h"
#include "src/execution/frames.h"
#include "src/heap/heap-inl.h"
#include "src/logging/counters.h"
#include "src/objects/cell.h"
#include "src/objects/foreign.h"
#include "src/objects/heap-number.h"
#include "src/objects/js-generator.h"
#include "src/objects/smi.h"
#include "src/runtime/runtime.h"
#if V8_ENABLE_WEBASSEMBLY
#include "src/wasm/wasm-linkage.h"
#include "src/wasm/wasm-objects.h"
#endif // V8_ENABLE_WEBASSEMBLY
namespace v8 {
namespace internal {
#define __ ACCESS_MASM(masm)
void Builtins::Generate_Adaptor(MacroAssembler* masm, Address address) {
__ Move(kJavaScriptCallExtraArg1Register, ExternalReference::Create(address));
__ Jump(BUILTIN_CODE(masm->isolate(), AdaptorWithBuiltinExitFrame),
RelocInfo::CODE_TARGET);
}
static void GenerateTailCallToReturnedCode(MacroAssembler* masm,
Runtime::FunctionId function_id) {
// ----------- S t a t e -------------
// -- r2 : actual argument count
// -- r3 : target function (preserved for callee)
// -- r5 : new target (preserved for callee)
// -----------------------------------
{
FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
// Push a copy of the target function, the new target and the actual
// argument count.
// Push function as parameter to the runtime call.
__ SmiTag(kJavaScriptCallArgCountRegister);
__ Push(kJavaScriptCallTargetRegister, kJavaScriptCallNewTargetRegister,
kJavaScriptCallArgCountRegister, kJavaScriptCallTargetRegister);
__ CallRuntime(function_id, 1);
__ mov(r4, r2);
// Restore target function, new target and actual argument count.
__ Pop(kJavaScriptCallTargetRegister, kJavaScriptCallNewTargetRegister,
kJavaScriptCallArgCountRegister);
__ SmiUntag(kJavaScriptCallArgCountRegister);
}
static_assert(kJavaScriptCallCodeStartRegister == r4, "ABI mismatch");
__ JumpCodeObject(r4);
}
namespace {
void Generate_JSBuiltinsConstructStubHelper(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- r2 : number of arguments
// -- r3 : constructor function
// -- r5 : new target
// -- cp : context
// -- lr : return address
// -- sp[...]: constructor arguments
// -----------------------------------
Register scratch = r4;
Label stack_overflow;
__ StackOverflowCheck(r2, scratch, &stack_overflow);
// Enter a construct frame.
{
FrameAndConstantPoolScope scope(masm, StackFrame::CONSTRUCT);
// Preserve the incoming parameters on the stack.
__ SmiTag(r2);
__ Push(cp, r2);
__ SmiUntag(r2);
// TODO(victorgomes): When the arguments adaptor is completely removed, we
// should get the formal parameter count and copy the arguments in its
// correct position (including any undefined), instead of delaying this to
// InvokeFunction.
// Set up pointer to last argument (skip receiver).
__ la(r6, MemOperand(fp, StandardFrameConstants::kCallerSPOffset +
kSystemPointerSize));
// Copy arguments and receiver to the expression stack.
__ PushArray(r6, r2, r1, r0);
// The receiver for the builtin/api call.
__ PushRoot(RootIndex::kTheHoleValue);
// Call the function.
// r2: number of arguments
// r3: constructor function
// r5: new target
__ InvokeFunctionWithNewTarget(r3, r5, r2, InvokeType::kCall);
// Restore context from the frame.
__ LoadU64(cp, MemOperand(fp, ConstructFrameConstants::kContextOffset));
// Restore smi-tagged arguments count from the frame.
__ LoadU64(scratch, MemOperand(fp, ConstructFrameConstants::kLengthOffset));
// Leave construct frame.
}
// Remove caller arguments from the stack and return.
__ DropArguments(scratch, TurboAssembler::kCountIsSmi,
TurboAssembler::kCountExcludesReceiver);
__ Ret();
__ bind(&stack_overflow);
{
FrameScope scope(masm, StackFrame::INTERNAL);
__ CallRuntime(Runtime::kThrowStackOverflow);
__ bkpt(0); // Unreachable code.
}
}
} // namespace
// The construct stub for ES5 constructor functions and ES6 class constructors.
void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- r2: number of arguments (untagged)
// -- r3: constructor function
// -- r5: new target
// -- cp: context
// -- lr: return address
// -- sp[...]: constructor arguments
// -----------------------------------
FrameScope scope(masm, StackFrame::MANUAL);
// Enter a construct frame.
Label post_instantiation_deopt_entry, not_create_implicit_receiver;
__ EnterFrame(StackFrame::CONSTRUCT);
// Preserve the incoming parameters on the stack.
__ SmiTag(r2);
__ Push(cp, r2, r3);
__ PushRoot(RootIndex::kUndefinedValue);
__ Push(r5);
// ----------- S t a t e -------------
// -- sp[0*kSystemPointerSize]: new target
// -- sp[1*kSystemPointerSize]: padding
// -- r3 and sp[2*kSystemPointerSize]: constructor function
// -- sp[3*kSystemPointerSize]: number of arguments (tagged)
// -- sp[4*kSystemPointerSize]: context
// -----------------------------------
__ LoadTaggedPointerField(
r6, FieldMemOperand(r3, JSFunction::kSharedFunctionInfoOffset));
__ LoadU32(r6, FieldMemOperand(r6, SharedFunctionInfo::kFlagsOffset));
__ DecodeField<SharedFunctionInfo::FunctionKindBits>(r6);
__ JumpIfIsInRange(r6, kDefaultDerivedConstructor, kDerivedConstructor,
¬_create_implicit_receiver);
// If not derived class constructor: Allocate the new receiver object.
__ IncrementCounter(masm->isolate()->counters()->constructed_objects(), 1, r6,
r7);
__ Call(BUILTIN_CODE(masm->isolate(), FastNewObject), RelocInfo::CODE_TARGET);
__ b(&post_instantiation_deopt_entry);
// Else: use TheHoleValue as receiver for constructor call
__ bind(¬_create_implicit_receiver);
__ LoadRoot(r2, RootIndex::kTheHoleValue);
// ----------- S t a t e -------------
// -- r2: receiver
// -- Slot 4 / sp[0*kSystemPointerSize]: new target
// -- Slot 3 / sp[1*kSystemPointerSize]: padding
// -- Slot 2 / sp[2*kSystemPointerSize]: constructor function
// -- Slot 1 / sp[3*kSystemPointerSize]: number of arguments (tagged)
// -- Slot 0 / sp[4*kSystemPointerSize]: context
// -----------------------------------
// Deoptimizer enters here.
masm->isolate()->heap()->SetConstructStubCreateDeoptPCOffset(
masm->pc_offset());
__ bind(&post_instantiation_deopt_entry);
// Restore new target.
__ Pop(r5);
// Push the allocated receiver to the stack.
__ Push(r2);
// We need two copies because we may have to return the original one
// and the calling conventions dictate that the called function pops the
// receiver. The second copy is pushed after the arguments, we saved in r6
// since r0 needs to store the number of arguments before
// InvokingFunction.
__ mov(r8, r2);
// Set up pointer to first argument (skip receiver).
__ la(r6, MemOperand(fp, StandardFrameConstants::kCallerSPOffset +
kSystemPointerSize));
// ----------- S t a t e -------------
// -- r5: new target
// -- sp[0*kSystemPointerSize]: implicit receiver
// -- sp[1*kSystemPointerSize]: implicit receiver
// -- sp[2*kSystemPointerSize]: padding
// -- sp[3*kSystemPointerSize]: constructor function
// -- sp[4*kSystemPointerSize]: number of arguments (tagged)
// -- sp[5*kSystemPointerSize]: context
// -----------------------------------
// Restore constructor function and argument count.
__ LoadU64(r3, MemOperand(fp, ConstructFrameConstants::kConstructorOffset));
__ LoadU64(r2, MemOperand(fp, ConstructFrameConstants::kLengthOffset));
__ SmiUntag(r2);
Label stack_overflow;
__ StackOverflowCheck(r2, r7, &stack_overflow);
// Copy arguments and receiver to the expression stack.
__ PushArray(r6, r2, r1, r0);
// Push implicit receiver.
__ Push(r8);
// Call the function.
__ InvokeFunctionWithNewTarget(r3, r5, r2, InvokeType::kCall);
// ----------- S t a t e -------------
// -- r0: constructor result
// -- sp[0*kSystemPointerSize]: implicit receiver
// -- sp[1*kSystemPointerSize]: padding
// -- sp[2*kSystemPointerSize]: constructor function
// -- sp[3*kSystemPointerSize]: number of arguments
// -- sp[4*kSystemPointerSize]: context
// -----------------------------------
// Store offset of return address for deoptimizer.
masm->isolate()->heap()->SetConstructStubInvokeDeoptPCOffset(
masm->pc_offset());
// If the result is an object (in the ECMA sense), we should get rid
// of the receiver and use the result; see ECMA-262 section 13.2.2-7
// on page 74.
Label use_receiver, do_throw, leave_and_return, check_receiver;
// If the result is undefined, we jump out to using the implicit receiver.
__ JumpIfNotRoot(r2, RootIndex::kUndefinedValue, &check_receiver);
// Otherwise we do a smi check and fall through to check if the return value
// is a valid receiver.
// Throw away the result of the constructor invocation and use the
// on-stack receiver as the result.
__ bind(&use_receiver);
__ LoadU64(r2, MemOperand(sp));
__ JumpIfRoot(r2, RootIndex::kTheHoleValue, &do_throw);
__ bind(&leave_and_return);
// Restore smi-tagged arguments count from the frame.
__ LoadU64(r3, MemOperand(fp, ConstructFrameConstants::kLengthOffset));
// Leave construct frame.
__ LeaveFrame(StackFrame::CONSTRUCT);
// Remove caller arguments from the stack and return.
__ DropArguments(r3, TurboAssembler::kCountIsSmi,
TurboAssembler::kCountExcludesReceiver);
__ Ret();
__ bind(&check_receiver);
// If the result is a smi, it is *not* an object in the ECMA sense.
__ JumpIfSmi(r2, &use_receiver);
// If the type of the result (stored in its map) is less than
// FIRST_JS_RECEIVER_TYPE, it is not an object in the ECMA sense.
STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE);
__ CompareObjectType(r2, r6, r6, FIRST_JS_RECEIVER_TYPE);
__ bge(&leave_and_return);
__ b(&use_receiver);
__ bind(&do_throw);
// Restore the context from the frame.
__ LoadU64(cp, MemOperand(fp, ConstructFrameConstants::kContextOffset));
__ CallRuntime(Runtime::kThrowConstructorReturnedNonObject);
__ bkpt(0);
__ bind(&stack_overflow);
// Restore the context from the frame.
__ LoadU64(cp, MemOperand(fp, ConstructFrameConstants::kContextOffset));
__ CallRuntime(Runtime::kThrowStackOverflow);
// Unreachable code.
__ bkpt(0);
}
void Builtins::Generate_JSBuiltinsConstructStub(MacroAssembler* masm) {
Generate_JSBuiltinsConstructStubHelper(masm);
}
static void GetSharedFunctionInfoBytecode(MacroAssembler* masm,
Register sfi_data,
Register scratch1) {
Label done;
__ CompareObjectType(sfi_data, scratch1, scratch1, INTERPRETER_DATA_TYPE);
__ bne(&done, Label::kNear);
__ LoadTaggedPointerField(
sfi_data,
FieldMemOperand(sfi_data, InterpreterData::kBytecodeArrayOffset));
__ bind(&done);
}
// static
void Builtins::Generate_ResumeGeneratorTrampoline(MacroAssembler* masm) {
// ----------- S t a t e -------------
// -- r2 : the value to pass to the generator
// -- r3 : the JSGeneratorObject to resume
// -- lr : return address
// -----------------------------------
// Store input value into generator object.
__ StoreTaggedField(
r2, FieldMemOperand(r3, JSGeneratorObject::kInputOrDebugPosOffset), r0);
__ RecordWriteField(r3, JSGeneratorObject::kInputOrDebugPosOffset, r2, r5,
kLRHasNotBeenSaved, SaveFPRegsMode::kIgnore);
// Check that r3 is still valid, RecordWrite might have clobbered it.
__ AssertGeneratorObject(r3);
// Load suspended function and context.
__ LoadTaggedPointerField(
r6, FieldMemOperand(r3, JSGeneratorObject::kFunctionOffset));
__ LoadTaggedPointerField(cp,
FieldMemOperand(r6, JSFunction::kContextOffset));
// Flood function if we are stepping.
Label prepare_step_in_if_stepping, prepare_step_in_suspended_generator;
Label stepping_prepared;
Register scratch = r7;
ExternalReference debug_hook =
ExternalReference::debug_hook_on_function_call_address(masm->isolate());
__ Move(scratch, debug_hook);
__ LoadS8(scratch, MemOperand(scratch));
__ CmpSmiLiteral(scratch, Smi::zero(), r0);
__ bne(&prepare_step_in_if_stepping);
// Flood function if we need to continue stepping in the suspended generator.
ExternalReference debug_suspended_generator =
ExternalReference::debug_suspended_generator_address(masm->isolate());
__ Move(scratch, debug_suspended_generator);
__ LoadU64(scratch, MemOperand(scratch));
__ CmpS64(scratch, r3);
__ beq(&prepare_step_in_suspended_generator);
__ bind(&stepping_prepared);
// Check the stack for overflow. We are not trying to catch interruptions
// (i.e. debug break and preemption) here, so check the "real stack limit".
Label stack_overflow;
__ LoadU64(scratch,
__ StackLimitAsMemOperand(StackLimitKind::kRealStackLimit));
__ CmpU64(sp, scratch);
__ blt(&stack_overflow);
// ----------- S t a t e -------------
// -- r3 : the JSGeneratorObject to resume
// -- r6 : generator function
// -- cp : generator context
// -- lr : return address
// -----------------------------------
// Copy the function arguments from the generator object's register file.
__ LoadTaggedPointerField(
r5, FieldMemOperand(r6, JSFunction::kSharedFunctionInfoOffset));
__ LoadU16(
r5, FieldMemOperand(r5, SharedFunctionInfo::kFormalParameterCountOffset));
__ LoadTaggedPointerField(
r4,
FieldMemOperand(r3, JSGeneratorObject::kParametersAndRegistersOffset));
{
Label done_loop, loop;
__ bind(&loop);
__ SubS64(r5, r5, Operand(1));
__ blt(&done_loop);
__ ShiftLeftU64(r1, r5, Operand(kTaggedSizeLog2));
__ la(scratch, MemOperand(r4, r1));
__ LoadAnyTaggedField(scratch,
FieldMemOperand(scratch, FixedArray::kHeaderSize));
__ Push(scratch);
__ b(&loop);
__ bind(&done_loop);
// Push receiver.
__ LoadAnyTaggedField(
scratch, FieldMemOperand(r3, JSGeneratorObject::kReceiverOffset));
__ Push(scratch);
}
// Underlying function needs to have bytecode available.
if (FLAG_debug_code) {
__ LoadTaggedPointerField(
r5, FieldMemOperand(r6, JSFunction::kSharedFunctionInfoOffset));
__ LoadTaggedPointerField(
r5, FieldMemOperand(r5, SharedFunctionInfo::kFunctionDataOffset));
GetSharedFunctionInfoBytecode(masm, r5, ip);
__ CompareObjectType(r5, r5, r5, BYTECODE_ARRAY_TYPE);
__ Assert(eq, AbortReason::kMissingBytecodeArray);
}
// Resume (Ignition/TurboFan) generator object.
{
__ LoadTaggedPointerField(
r2, FieldMemOperand(r6, JSFunction::kSharedFunctionInfoOffset));
__ LoadS16(
r2,
FieldMemOperand(r2, SharedFunctionInfo::kFormalParameterCountOffset));
// We abuse new.target both to indicate that this is a resume call and to
// pass in the generator object. In ordinary calls, new.target is always
// undefined because generator functions are non-constructable.
__ mov(r5, r3);
__ mov(r3, r6);
static_assert(kJavaScriptCallCodeStartRegister == r4, "ABI mismatch");
__ LoadTaggedPointerField(r4, FieldMemOperand(r3, JSFunction::kCodeOffset));
__ JumpCodeObject(r4);
}
__ bind(&prepare_step_in_if_stepping);
{
FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
__ Push(r3, r6);
// Push hole as receiver since we do not use it for stepping.
__ PushRoot(RootIndex::kTheHoleValue);
__ CallRuntime(Runtime::kDebugOnFunctionCall);
__ Pop(r3);
__ LoadTaggedPointerField(
r6, FieldMemOperand(r3, JSGeneratorObject::kFunctionOffset));
}
__ b(&stepping_prepared);
__ bind(&prepare_step_in_suspended_generator);
{
FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
__ Push(r3);
__ CallRuntime(Runtime::kDebugPrepareStepInSuspendedGenerator);
__ Pop(r3);
__ LoadTaggedPointerField(
r6, FieldMemOperand(r3, JSGeneratorObject::kFunctionOffset));
}
__ b(&stepping_prepared);
__ bind(&stack_overflow);
{
FrameScope scope(masm, StackFrame::INTERNAL);
__ CallRuntime(Runtime::kThrowStackOverflow);
__ bkpt(0); // This should be unreachable.
}
}
void Builtins::Generate_ConstructedNonConstructable(MacroAssembler* masm) {
FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
__ push(r3);
__ CallRuntime(Runtime::kThrowConstructedNonConstructable);
}
namespace {
constexpr int kPushedStackSpace =
(kNumCalleeSaved + 2) * kSystemPointerSize +
kNumCalleeSavedDoubles * kDoubleSize + 5 * kSystemPointerSize +
EntryFrameConstants::kCallerFPOffset - kSystemPointerSize;
// Called with the native C calling convention. The corresponding function
// signature is either:
//
// using JSEntryFunction = GeneratedCode<Address(
// Address root_register_value, Address new_target, Address target,
// Address receiver, intptr_t argc, Address** args)>;
// or
// using JSEntryFunction = GeneratedCode<Address(
// Address root_register_value, MicrotaskQueue* microtask_queue)>;
void Generate_JSEntryVariant(MacroAssembler* masm, StackFrame::Type type,
Builtin entry_trampoline) {
// The register state is either:
// r2: root register value
// r3: code entry
// r4: function
// r5: receiver
// r6: argc
// [sp + 20 * kSystemPointerSize]: argv
// or
// r2: root_register_value
// r3: microtask_queue
Label invoke, handler_entry, exit;
int pushed_stack_space = 0;
{
NoRootArrayScope no_root_array(masm);
// saving floating point registers
// 64bit ABI requires f8 to f15 be saved
// http://refspecs.linuxbase.org/ELF/zSeries/lzsabi0_zSeries.html
__ lay(sp, MemOperand(sp, -8 * kDoubleSize));
__ std(d8, MemOperand(sp));
__ std(d9, MemOperand(sp, 1 * kDoubleSize));
__ std(d10, MemOperand(sp, 2 * kDoubleSize));
__ std(d11, MemOperand(sp, 3 * kDoubleSize));
__ std(d12, MemOperand(sp, 4 * kDoubleSize));
__ std(d13, MemOperand(sp, 5 * kDoubleSize));
__ std(d14, MemOperand(sp, 6 * kDoubleSize));
__ std(d15, MemOperand(sp, 7 * kDoubleSize));
pushed_stack_space += kNumCalleeSavedDoubles * kDoubleSize;
// zLinux ABI
// Incoming parameters:
// r2: root register value
// r3: code entry
// r4: function
// r5: receiver
// r6: argc
// [sp + 20 * kSystemPointerSize]: argv
// Requires us to save the callee-preserved registers r6-r13
// General convention is to also save r14 (return addr) and
// sp/r15 as well in a single STM/STMG
__ lay(sp, MemOperand(sp, -10 * kSystemPointerSize));
__ StoreMultipleP(r6, sp, MemOperand(sp, 0));
pushed_stack_space += (kNumCalleeSaved + 2) * kSystemPointerSize;
// Initialize the root register.
// C calling convention. The first argument is passed in r2.
__ mov(kRootRegister, r2);
}
// save r6 to r1
__ mov(r0, r6);
// Push a frame with special values setup to mark it as an entry frame.
// Bad FP (-1)
// SMI Marker
// SMI Marker
// kCEntryFPAddress
// Frame type
__ lay(sp, MemOperand(sp, -5 * kSystemPointerSize));
pushed_stack_space += 5 * kSystemPointerSize;
// Push a bad frame pointer to fail if it is used.
__ mov(r9, Operand(-1));
__ mov(r8, Operand(StackFrame::TypeToMarker(type)));
__ mov(r7, Operand(StackFrame::TypeToMarker(type)));
// Save copies of the top frame descriptor on the stack.
__ Move(r1, ExternalReference::Create(IsolateAddressId::kCEntryFPAddress,
masm->isolate()));
__ LoadU64(r6, MemOperand(r1));
__ StoreMultipleP(r6, r9, MemOperand(sp, kSystemPointerSize));
// Clear c_entry_fp, now we've pushed its previous value to the stack.
// If the c_entry_fp is not already zero and we don't clear it, the
// SafeStackFrameIterator will assume we are executing C++ and miss the JS
// frames on top.
__ mov(r6, Operand::Zero());
__ StoreU64(r6, MemOperand(r1));
Register scrach = r8;
// Set up frame pointer for the frame to be pushed.
// Need to add kSystemPointerSize, because sp has one extra
// frame already for the frame type being pushed later.
__ lay(fp, MemOperand(sp, -EntryFrameConstants::kCallerFPOffset +
kSystemPointerSize));
pushed_stack_space +=
EntryFrameConstants::kCallerFPOffset - kSystemPointerSize;
// restore r6
__ mov(r6, r0);
// If this is the outermost JS call, set js_entry_sp value.
Label non_outermost_js;
ExternalReference js_entry_sp =
ExternalReference::Create(IsolateAddressId::kJSEntrySPAddress,
masm->isolate());
__ Move(r7, js_entry_sp);
__ LoadAndTestP(scrach, MemOperand(r7));
__ bne(&non_outermost_js, Label::kNear);
__ StoreU64(fp, MemOperand(r7));
__ mov(scrach, Operand(StackFrame::OUTERMOST_JSENTRY_FRAME));
Label cont;
__ b(&cont, Label::kNear);
__ bind(&non_outermost_js);
__ mov(scrach, Operand(StackFrame::INNER_JSENTRY_FRAME));
__ bind(&cont);
__ StoreU64(scrach, MemOperand(sp)); // frame-type
// Jump to a faked try block that does the invoke, with a faked catch
// block that sets the pending exception.
__ b(&invoke, Label::kNear);
__ bind(&handler_entry);
// Store the current pc as the handler offset. It's used later to create the
// handler table.
masm->isolate()->builtins()->SetJSEntryHandlerOffset(handler_entry.pos());
// Caught exception: Store result (exception) in the pending exception
// field in the JSEnv and return a failure sentinel. Coming in here the
// fp will be invalid because the PushStackHandler below sets it to 0 to
// signal the existence of the JSEntry frame.
__ Move(scrach,
ExternalReference::Create(IsolateAddressId::kPendingExceptionAddress,
masm->isolate()));
__ StoreU64(r2, MemOperand(scrach));
__ LoadRoot(r2, RootIndex::kException);
__ b(&exit, Label::kNear);
// Invoke: Link this frame into the handler chain.
__ bind(&invoke);
// Must preserve r2-r6.
__ PushStackHandler();
// If an exception not caught by another handler occurs, this handler
// returns control to the code after the b(&invoke) above, which
// restores all kCalleeSaved registers (including cp and fp) to their
// saved values before returning a failure to C.
// Invoke the function by calling through JS entry trampoline builtin.
// Notice that we cannot store a reference to the trampoline code directly in
// this stub, because runtime stubs are not traversed when doing GC.
// Invoke the function by calling through JS entry trampoline builtin and
// pop the faked function when we return.
Handle<Code> trampoline_code =
masm->isolate()->builtins()->code_handle(entry_trampoline);
DCHECK_EQ(kPushedStackSpace, pushed_stack_space);
__ Call(trampoline_code, RelocInfo::CODE_TARGET);
// Unlink this frame from the handler chain.
__ PopStackHandler();
__ bind(&exit); // r2 holds result
// Check if the current stack frame is marked as the outermost JS frame.
Label non_outermost_js_2;
__ pop(r7);
__ CmpS64(r7, Operand(StackFrame::OUTERMOST_JSENTRY_FRAME));
__ bne(&non_outermost_js_2, Label::kNear);
__ mov(scrach, Operand::Zero());
__ Move(r7, js_entry_sp);
__ StoreU64(scrach, MemOperand(r7));
__ bind(&non_outermost_js_2);
// Restore the top frame descriptors from the stack.
__ pop(r5);
__ Move(scrach, ExternalReference::Create(IsolateAddressId::kCEntryFPAddress,
masm->isolate()));
__ StoreU64(r5, MemOperand(scrach));
// Reset the stack to the callee saved registers.
__ lay(sp, MemOperand(sp, -EntryFrameConstants::kCallerFPOffset));
// Reload callee-saved preserved regs, return address reg (r14) and sp
__ LoadMultipleP(r6, sp, MemOperand(sp, 0));
__ la(sp, MemOperand(sp, 10 * kSystemPointerSize));
// saving floating point registers
#if V8_TARGET_ARCH_S390X
// 64bit ABI requires f8 to f15 be saved
__ ld(d8, MemOperand(sp));
__ ld(d9, MemOperand(sp, 1 * kDoubleSize));
__ ld(d10, MemOperand(sp, 2 * kDoubleSize));
__ ld(d11, MemOperand(sp, 3 * kDoubleSize));
__ ld(d12, MemOperand(sp, 4 * kDoubleSize));
__ ld(d13, MemOperand(sp, 5 * kDoubleSize));
__ ld(d14, MemOperand(sp, 6 * kDoubleSize));
__ ld(d15, MemOperand(sp, 7 * kDoubleSize));
__ la(sp, MemOperand(sp, 8 * kDoubleSize));
#else
// 31bit ABI requires you to store f4 and f6:
// http://refspecs.linuxbase.org/ELF/zSeries/lzsabi0_s390.html#AEN417
__ ld(d4, MemOperand(sp));
__ ld(d6, MemOperand(sp, kDoubleSize));
__ la(sp, MemOperand(sp, 2 * kDoubleSize));
#endif
__ b(r14);
}
} // namespace
void Builtins::Generate_JSEntry(MacroAssembler* masm) {
Generate_JSEntryVariant(masm, StackFrame::ENTRY, Builtin::kJSEntryTrampoline);
}
void Builtins::Generate_JSConstructEntry(MacroAssembler* masm) {
Generate_JSEntryVariant(masm, StackFrame::CONSTRUCT_ENTRY,
Builtin::kJSConstructEntryTrampoline);
}
void Builtins::Generate_JSRunMicrotasksEntry(MacroAssembler* masm) {
Generate_JSEntryVariant(masm, StackFrame::ENTRY,
Builtin::kRunMicrotasksTrampoline);
}
static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm,
bool is_construct) {
// Called from Generate_JS_Entry
// r3: new.target
// r4: function
// r5: receiver
// r6: argc
// [fp + kPushedStackSpace + 20 * kSystemPointerSize]: argv
// r0,r2,r7-r9, cp may be clobbered
__ mov(r2, r6);
// Load argv from the stack.
__ LoadU64(
r6, MemOperand(fp, kPushedStackSpace + EntryFrameConstants::kArgvOffset));
// r2: argc
// r3: new.target
// r4: function
// r5: receiver
// r6: argv
// Enter an internal frame.
{
// FrameScope ends up calling MacroAssembler::EnterFrame here
FrameScope scope(masm, StackFrame::INTERNAL);
// Setup the context (we need to use the caller context from the isolate).
ExternalReference context_address = ExternalReference::Create(
IsolateAddressId::kContextAddress, masm->isolate());
__ Move(cp, context_address);
__ LoadU64(cp, MemOperand(cp));
// Push the function
__ Push(r4);
// Check if we have enough stack space to push all arguments.
Label enough_stack_space, stack_overflow;
__ AddS64(r7, r2, Operand(1));
__ StackOverflowCheck(r7, r1, &stack_overflow);
__ b(&enough_stack_space);
__ bind(&stack_overflow);
__ CallRuntime(Runtime::kThrowStackOverflow);
// Unreachable code.
__ bkpt(0);
__ bind(&enough_stack_space);
// Copy arguments to the stack in a loop from argv to sp.
// The arguments are actually placed in reverse order on sp
// compared to argv (i.e. arg1 is highest memory in sp).
// r2: argc
// r3: function
// r5: new.target
// r6: argv, i.e. points to first arg
// r7: scratch reg to hold scaled argc
// r8: scratch reg to hold arg handle
// r9: scratch reg to hold index into argv
Label argLoop, argExit;
__ ShiftLeftU64(r9, r2, Operand(kSystemPointerSizeLog2));
__ lay(r9, MemOperand(r6, r9, -kSystemPointerSize)); // point to last arg
__ ltgr(r7, r2);
__ beq(&argExit, Label::kNear);
__ bind(&argLoop);
__ LoadU64(r8, MemOperand(r9)); // read next parameter
__ LoadU64(r0, MemOperand(r8)); // dereference handle
__ Push(r0);
__ lay(r9, MemOperand(r9, -kSystemPointerSize)); // r9++;
__ SubS64(r7, r7, Operand(1));
__ bgt(&argLoop);
__ bind(&argExit);
// Push the receiver.
__ Push(r5);
// Setup new.target, argc and function.
__ mov(r5, r3);
__ mov(r3, r4);
// r2: argc
// r3: function
// r5: new.target
// Initialize all JavaScript callee-saved registers, since they will be seen
// by the garbage collector as part of handlers.
__ LoadRoot(r4, RootIndex::kUndefinedValue);
__ mov(r6, r4);
__ mov(r7, r6);
__ mov(r8, r6);
__ mov(r9, r6);
// Invoke the code.
Handle<Code> builtin = is_construct
? BUILTIN_CODE(masm->isolate(), Construct)
: masm->isolate()->builtins()->Call();
__ Call(builtin, RelocInfo::CODE_TARGET);
// Exit the JS frame and remove the parameters (except function), and
// return.
}
__ b(r14);
// r2: result
}
void Builtins::Generate_JSEntryTrampoline(MacroAssembler* masm) {
Generate_JSEntryTrampolineHelper(masm, false);
}
void Builtins::Generate_JSConstructEntryTrampoline(MacroAssembler* masm) {
Generate_JSEntryTrampolineHelper(masm, true);
}
void Builtins::Generate_RunMicrotasksTrampoline(MacroAssembler* masm) {
// This expects two C++ function parameters passed by Invoke() in
// execution.cc.
// r2: root_register_value
// r3: microtask_queue
__ mov(RunMicrotasksDescriptor::MicrotaskQueueRegister(), r3);
__ Jump(BUILTIN_CODE(masm->isolate(), RunMicrotasks), RelocInfo::CODE_TARGET);
}
static void ReplaceClosureCodeWithOptimizedCode(MacroAssembler* masm,
Register optimized_code,
Register closure,
Register scratch1,
Register slot_address) {
DCHECK(!AreAliased(optimized_code, closure, scratch1, slot_address));
DCHECK_EQ(closure, kJSFunctionRegister);
DCHECK(!AreAliased(optimized_code, closure));
// Store code entry in the closure.
__ StoreTaggedField(optimized_code,
FieldMemOperand(closure, JSFunction::kCodeOffset), r0);
// Write barrier clobbers scratch1 below.
Register value = scratch1;
__ mov(value, optimized_code);
__ RecordWriteField(closure, JSFunction::kCodeOffset, value, slot_address,
kLRHasNotBeenSaved, SaveFPRegsMode::kIgnore,
RememberedSetAction::kOmit, SmiCheck::kOmit);
}
static void LeaveInterpreterFrame(MacroAssembler* masm, Register scratch1,
Register scratch2) {
Register params_size = scratch1;
// Get the size of the formal parameters + receiver (in bytes).
__ LoadU64(params_size,
MemOperand(fp, InterpreterFrameConstants::kBytecodeArrayFromFp));
__ LoadU32(params_size,
FieldMemOperand(params_size, BytecodeArray::kParameterSizeOffset));
Register actual_params_size = scratch2;
// Compute the size of the actual parameters + receiver (in bytes).
__ LoadU64(actual_params_size,
MemOperand(fp, StandardFrameConstants::kArgCOffset));
__ ShiftLeftU64(actual_params_size, actual_params_size,
Operand(kSystemPointerSizeLog2));
__ AddS64(actual_params_size, actual_params_size,
Operand(kSystemPointerSize));
// If actual is bigger than formal, then we should use it to free up the stack
// arguments.
Label corrected_args_count;
__ CmpS64(params_size, actual_params_size);
__ bge(&corrected_args_count);
__ mov(params_size, actual_params_size);
__ bind(&corrected_args_count);
// Leave the frame (also dropping the register file).
__ LeaveFrame(StackFrame::INTERPRETED);
__ DropArguments(params_size, TurboAssembler::kCountIsBytes,
TurboAssembler::kCountIncludesReceiver);
}
// Tail-call |function_id| if |actual_marker| == |expected_marker|
static void TailCallRuntimeIfMarkerEquals(MacroAssembler* masm,
Register actual_marker,
OptimizationMarker expected_marker,
Runtime::FunctionId function_id) {
Label no_match;
__ CmpS64(actual_marker, Operand(expected_marker));
__ bne(&no_match);
GenerateTailCallToReturnedCode(masm, function_id);
__ bind(&no_match);
}
static void TailCallOptimizedCodeSlot(MacroAssembler* masm,
Register optimized_code_entry,
Register scratch) {
// ----------- S t a t e -------------
// -- r2 : actual argument count
// -- r5 : new target (preserved for callee if needed, and caller)
// -- r3 : target function (preserved for callee if needed, and caller)
// -----------------------------------
DCHECK(!AreAliased(r3, r5, optimized_code_entry, scratch));
Register closure = r3;
Label heal_optimized_code_slot;
// If the optimized code is cleared, go to runtime to update the optimization
// marker field.
__ LoadWeakValue(optimized_code_entry, optimized_code_entry,
&heal_optimized_code_slot);
// Check if the optimized code is marked for deopt. If it is, call the
// runtime to clear it.
__ LoadTaggedPointerField(
scratch,
FieldMemOperand(optimized_code_entry, Code::kCodeDataContainerOffset));
__ LoadS32(scratch, FieldMemOperand(
scratch, CodeDataContainer::kKindSpecificFlagsOffset));
__ TestBit(scratch, Code::kMarkedForDeoptimizationBit, r0);
__ bne(&heal_optimized_code_slot);
// Optimized code is good, get it into the closure and link the closure
// into the optimized functions list, then tail call the optimized code.
ReplaceClosureCodeWithOptimizedCode(masm, optimized_code_entry, closure,
scratch, r7);
static_assert(kJavaScriptCallCodeStartRegister == r4, "ABI mismatch");
__ LoadCodeObjectEntry(r4, optimized_code_entry);
__ Jump(r4);
// Optimized code slot contains deoptimized code or code is cleared and
// optimized code marker isn't updated. Evict the code, update the marker
// and re-enter the closure's code.
__ bind(&heal_optimized_code_slot);
GenerateTailCallToReturnedCode(masm, Runtime::kHealOptimizedCodeSlot);
}
static void MaybeOptimizeCode(MacroAssembler* masm, Register feedback_vector,
Register optimization_marker) {
// ----------- S t a t e -------------
// -- r2 : actual argument count
// -- r5 : new target (preserved for callee if needed, and caller)
// -- r3 : target function (preserved for callee if needed, and caller)
// -- feedback vector (preserved for caller if needed)
// -- optimization_marker : a int32 containing a non-zero optimization
// marker.
// -----------------------------------
DCHECK(!AreAliased(feedback_vector, r3, r5, optimization_marker));
// TODO(v8:8394): The logging of first execution will break if
// feedback vectors are not allocated. We need to find a different way of
// logging these events if required.
TailCallRuntimeIfMarkerEquals(masm, optimization_marker,
OptimizationMarker::kLogFirstExecution,
Runtime::kFunctionFirstExecution);
TailCallRuntimeIfMarkerEquals(masm, optimization_marker,
OptimizationMarker::kCompileOptimized,
Runtime::kCompileOptimized_NotConcurrent);
TailCallRuntimeIfMarkerEquals(masm, optimization_marker,
OptimizationMarker::kCompileOptimizedConcurrent,
Runtime::kCompileOptimized_Concurrent);
// Marker should be one of LogFirstExecution / CompileOptimized /
// CompileOptimizedConcurrent. InOptimizationQueue and None shouldn't reach
// here.
if (FLAG_debug_code) {
__ stop();
}
}
// Advance the current bytecode offset. This simulates what all bytecode
// handlers do upon completion of the underlying operation. Will bail out to a
// label if the bytecode (without prefix) is a return bytecode. Will not advance
// the bytecode offset if the current bytecode is a JumpLoop, instead just
// re-executing the JumpLoop to jump to the correct bytecode.
static void AdvanceBytecodeOffsetOrReturn(MacroAssembler* masm,
Register bytecode_array,
Register bytecode_offset,
Register bytecode, Register scratch1,
Register scratch2, Label* if_return) {
Register bytecode_size_table = scratch1;
Register scratch3 = bytecode;
// The bytecode offset value will be increased by one in wide and extra wide
// cases. In the case of having a wide or extra wide JumpLoop bytecode, we
// will restore the original bytecode. In order to simplify the code, we have
// a backup of it.
Register original_bytecode_offset = scratch2;
DCHECK(!AreAliased(bytecode_array, bytecode_offset, bytecode_size_table,
bytecode, original_bytecode_offset));