00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "v8.h"
00029
00030 #include "codegen-inl.h"
00031 #include "debug.h"
00032 #include "runtime.h"
00033
00034 namespace v8 { namespace internal {
00035
00036
00037 #define __ masm->
00038
00039
00040 void Builtins::Generate_Adaptor(MacroAssembler* masm, CFunctionId id) {
00041
00042 __ mov(ip, Operand(ExternalReference::builtin_passed_function()));
00043 __ str(r1, MemOperand(ip, 0));
00044
00045
00046
00047
00048 __ add(r0, r0, Operand(1));
00049 __ JumpToBuiltin(ExternalReference(id));
00050 }
00051
00052
00053 void Builtins::Generate_JSConstructCall(MacroAssembler* masm) {
00054
00055
00056
00057
00058
00059
00060
00061
00062 __ EnterConstructFrame();
00063
00064
00065 __ mov(r0, Operand(r0, LSL, kSmiTagSize));
00066 __ push(r0);
00067 __ push(r1);
00068
00069
00070 __ push(r1);
00071 __ CallRuntime(Runtime::kNewObject, 1);
00072 __ push(r0);
00073
00074
00075
00076
00077
00078 __ ldr(r1, MemOperand(sp, kPointerSize));
00079 __ push(r1);
00080 __ push(r0);
00081
00082
00083
00084
00085
00086
00087
00088
00089 __ ldr(r3, MemOperand(sp, 4 * kPointerSize));
00090
00091
00092 __ add(r2, fp, Operand(StandardFrameConstants::kCallerSPOffset));
00093
00094
00095 __ mov(r0, Operand(r3, LSR, kSmiTagSize));
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 Label loop, entry;
00108 __ b(&entry);
00109 __ bind(&loop);
00110 __ ldr(ip, MemOperand(r2, r3, LSL, kPointerSizeLog2 - 1));
00111 __ push(ip);
00112 __ bind(&entry);
00113 __ sub(r3, r3, Operand(2), SetCC);
00114 __ b(ge, &loop);
00115
00116
00117
00118
00119 ParameterCount actual(r0);
00120 __ InvokeFunction(r1, actual, CALL_FUNCTION);
00121
00122
00123
00124
00125
00126
00127 __ pop();
00128
00129
00130
00131
00132
00133
00134 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
00135
00136
00137
00138
00139 Label use_receiver, exit;
00140
00141
00142
00143
00144
00145
00146 __ tst(r0, Operand(kSmiTagMask));
00147 __ b(eq, &use_receiver);
00148
00149
00150
00151 __ ldr(r3, FieldMemOperand(r0, HeapObject::kMapOffset));
00152 __ ldrb(r3, FieldMemOperand(r3, Map::kInstanceTypeOffset));
00153 __ cmp(r3, Operand(FIRST_JS_OBJECT_TYPE));
00154 __ b(ge, &exit);
00155
00156
00157
00158 __ bind(&use_receiver);
00159 __ ldr(r0, MemOperand(sp));
00160
00161
00162
00163 __ bind(&exit);
00164
00165
00166
00167
00168 __ ldr(r1, MemOperand(sp, 2 * kPointerSize));
00169 __ LeaveConstructFrame();
00170 __ add(sp, sp, Operand(r1, LSL, kPointerSizeLog2 - 1));
00171 __ add(sp, sp, Operand(kPointerSize));
00172 __ mov(pc, Operand(lr));
00173 }
00174
00175
00176 static void Generate_JSEntryTrampolineHelper(MacroAssembler* masm,
00177 bool is_construct) {
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187 __ mov(cp, Operand(0));
00188
00189
00190 __ EnterInternalFrame();
00191
00192
00193 __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
00194
00195
00196 __ push(r1);
00197 __ push(r2);
00198
00199
00200
00201
00202
00203 Label loop, entry;
00204 __ add(r2, r4, Operand(r3, LSL, kPointerSizeLog2));
00205
00206 __ b(&entry);
00207 __ bind(&loop);
00208 __ ldr(r0, MemOperand(r4, kPointerSize, PostIndex));
00209 __ ldr(r0, MemOperand(r0));
00210 __ push(r0);
00211 __ bind(&entry);
00212 __ cmp(r4, Operand(r2));
00213 __ b(ne, &loop);
00214
00215
00216
00217 __ mov(r4, Operand(Factory::undefined_value()));
00218 __ mov(r5, Operand(r4));
00219 __ mov(r6, Operand(r4));
00220 __ mov(r7, Operand(r4));
00221 if (kR9Available == 1)
00222 __ mov(r9, Operand(r4));
00223
00224
00225 __ mov(r0, Operand(r3));
00226 if (is_construct) {
00227 __ Call(Handle<Code>(Builtins::builtin(Builtins::JSConstructCall)),
00228 RelocInfo::CODE_TARGET);
00229 } else {
00230 ParameterCount actual(r0);
00231 __ InvokeFunction(r1, actual, CALL_FUNCTION);
00232 }
00233
00234
00235
00236 __ LeaveInternalFrame();
00237 __ mov(pc, lr);
00238
00239
00240 }
00241
00242
00243 void Builtins::Generate_JSEntryTrampoline(MacroAssembler* masm) {
00244 Generate_JSEntryTrampolineHelper(masm, false);
00245 }
00246
00247
00248 void Builtins::Generate_JSConstructEntryTrampoline(MacroAssembler* masm) {
00249 Generate_JSEntryTrampolineHelper(masm, true);
00250 }
00251
00252
00253 void Builtins::Generate_FunctionCall(MacroAssembler* masm) {
00254
00255
00256 { Label done;
00257 __ tst(r0, Operand(r0));
00258 __ b(ne, &done);
00259 __ mov(r2, Operand(Factory::undefined_value()));
00260 __ push(r2);
00261 __ add(r0, r0, Operand(1));
00262 __ bind(&done);
00263 }
00264
00265
00266
00267 { Label done, non_function, function;
00268 __ ldr(r1, MemOperand(sp, r0, LSL, kPointerSizeLog2));
00269 __ tst(r1, Operand(kSmiTagMask));
00270 __ b(eq, &non_function);
00271 __ ldr(r2, FieldMemOperand(r1, HeapObject::kMapOffset));
00272 __ ldrb(r2, FieldMemOperand(r2, Map::kInstanceTypeOffset));
00273 __ cmp(r2, Operand(JS_FUNCTION_TYPE));
00274 __ b(eq, &function);
00275
00276
00277 __ bind(&non_function);
00278 __ mov(r1, Operand(0));
00279 __ b(&done);
00280
00281
00282
00283 __ bind(&function);
00284 __ ldr(cp, FieldMemOperand(r1, JSFunction::kContextOffset));
00285
00286 __ bind(&done);
00287 }
00288
00289
00290
00291
00292 { Label call_to_object, use_global_receiver, patch_receiver, done;
00293 __ add(r2, sp, Operand(r0, LSL, kPointerSizeLog2));
00294 __ ldr(r2, MemOperand(r2, -kPointerSize));
00295
00296
00297
00298
00299 __ tst(r2, Operand(kSmiTagMask));
00300 __ b(eq, &call_to_object);
00301
00302 __ mov(r3, Operand(Factory::null_value()));
00303 __ cmp(r2, r3);
00304 __ b(eq, &use_global_receiver);
00305 __ mov(r3, Operand(Factory::undefined_value()));
00306 __ cmp(r2, r3);
00307 __ b(eq, &use_global_receiver);
00308
00309 __ ldr(r3, FieldMemOperand(r2, HeapObject::kMapOffset));
00310 __ ldrb(r3, FieldMemOperand(r3, Map::kInstanceTypeOffset));
00311 __ cmp(r3, Operand(FIRST_JS_OBJECT_TYPE));
00312 __ b(lt, &call_to_object);
00313 __ cmp(r3, Operand(LAST_JS_OBJECT_TYPE));
00314 __ b(le, &done);
00315
00316 __ bind(&call_to_object);
00317 __ EnterInternalFrame();
00318
00319
00320 __ mov(r0, Operand(r0, LSL, kSmiTagSize));
00321 __ push(r0);
00322 __ push(r1);
00323
00324 __ push(r2);
00325 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_JS);
00326 __ mov(r2, r0);
00327
00328
00329 __ pop(r1);
00330 __ pop(r0);
00331 __ mov(r0, Operand(r0, ASR, kSmiTagSize));
00332
00333 __ LeaveInternalFrame();
00334 __ b(&patch_receiver);
00335
00336
00337 __ bind(&use_global_receiver);
00338 const int kGlobalIndex =
00339 Context::kHeaderSize + Context::GLOBAL_INDEX * kPointerSize;
00340 __ ldr(r2, FieldMemOperand(cp, kGlobalIndex));
00341 __ ldr(r2, FieldMemOperand(r2, GlobalObject::kGlobalReceiverOffset));
00342
00343 __ bind(&patch_receiver);
00344 __ add(r3, sp, Operand(r0, LSL, kPointerSizeLog2));
00345 __ str(r2, MemOperand(r3, -kPointerSize));
00346
00347 __ bind(&done);
00348 }
00349
00350
00351
00352
00353 { Label loop;
00354
00355 __ add(r2, sp, Operand(r0, LSL, kPointerSizeLog2));
00356 __ add(r2, r2, Operand(kPointerSize));
00357
00358 __ bind(&loop);
00359 __ ldr(ip, MemOperand(r2, -kPointerSize));
00360 __ str(ip, MemOperand(r2));
00361 __ sub(r2, r2, Operand(kPointerSize));
00362 __ cmp(r2, sp);
00363 __ b(ne, &loop);
00364 }
00365
00366
00367
00368
00369 __ sub(r0, r0, Operand(1));
00370 __ add(sp, sp, Operand(kPointerSize));
00371
00372
00373
00374
00375
00376
00377 { Label invoke;
00378 __ tst(r1, r1);
00379 __ b(ne, &invoke);
00380 __ mov(r2, Operand(0));
00381 __ GetBuiltinEntry(r3, Builtins::CALL_NON_FUNCTION);
00382 __ Jump(Handle<Code>(builtin(ArgumentsAdaptorTrampoline)),
00383 RelocInfo::CODE_TARGET);
00384
00385 __ bind(&invoke);
00386 __ ldr(r3, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
00387 __ ldr(r2,
00388 FieldMemOperand(r3,
00389 SharedFunctionInfo::kFormalParameterCountOffset));
00390 __ ldr(r3,
00391 MemOperand(r3, SharedFunctionInfo::kCodeOffset - kHeapObjectTag));
00392 __ add(r3, r3, Operand(Code::kHeaderSize - kHeapObjectTag));
00393 __ cmp(r2, r0);
00394 __ Jump(Handle<Code>(builtin(ArgumentsAdaptorTrampoline)),
00395 RelocInfo::CODE_TARGET, ne);
00396
00397
00398 ParameterCount expected(0);
00399 __ InvokeCode(r3, expected, expected, JUMP_FUNCTION);
00400 }
00401 }
00402
00403
00404 void Builtins::Generate_FunctionApply(MacroAssembler* masm) {
00405 const int kIndexOffset = -5 * kPointerSize;
00406 const int kLimitOffset = -4 * kPointerSize;
00407 const int kArgsOffset = 2 * kPointerSize;
00408 const int kRecvOffset = 3 * kPointerSize;
00409 const int kFunctionOffset = 4 * kPointerSize;
00410
00411 __ EnterInternalFrame();
00412
00413 __ ldr(r0, MemOperand(fp, kFunctionOffset));
00414 __ push(r0);
00415 __ ldr(r0, MemOperand(fp, kArgsOffset));
00416 __ push(r0);
00417 __ InvokeBuiltin(Builtins::APPLY_PREPARE, CALL_JS);
00418
00419
00420
00421 Label okay;
00422 ExternalReference stack_guard_limit_address =
00423 ExternalReference::address_of_stack_guard_limit();
00424 __ mov(r2, Operand(stack_guard_limit_address));
00425 __ ldr(r2, MemOperand(r2));
00426 __ sub(r2, sp, r2);
00427 __ sub(r2, r2, Operand(3 * kPointerSize));
00428
00429 __ cmp(r2, Operand(r0, LSL, kPointerSizeLog2 - kSmiTagSize));
00430 __ b(hi, &okay);
00431
00432
00433 __ ldr(r1, MemOperand(fp, kFunctionOffset));
00434 __ push(r1);
00435 __ push(r0);
00436 __ InvokeBuiltin(Builtins::APPLY_OVERFLOW, CALL_JS);
00437
00438
00439 __ bind(&okay);
00440 __ push(r0);
00441 __ mov(r1, Operand(0));
00442 __ push(r1);
00443
00444
00445 __ ldr(r0, MemOperand(fp, kFunctionOffset));
00446 __ ldr(cp, FieldMemOperand(r0, JSFunction::kContextOffset));
00447
00448
00449 Label call_to_object, use_global_receiver, push_receiver;
00450 __ ldr(r0, MemOperand(fp, kRecvOffset));
00451 __ tst(r0, Operand(kSmiTagMask));
00452 __ b(eq, &call_to_object);
00453 __ mov(r1, Operand(Factory::null_value()));
00454 __ cmp(r0, r1);
00455 __ b(eq, &use_global_receiver);
00456 __ mov(r1, Operand(Factory::undefined_value()));
00457 __ cmp(r0, r1);
00458 __ b(eq, &use_global_receiver);
00459
00460
00461
00462 __ ldr(r1, FieldMemOperand(r0, HeapObject::kMapOffset));
00463 __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset));
00464 __ cmp(r1, Operand(FIRST_JS_OBJECT_TYPE));
00465 __ b(lt, &call_to_object);
00466 __ cmp(r1, Operand(LAST_JS_OBJECT_TYPE));
00467 __ b(le, &push_receiver);
00468
00469
00470
00471 __ bind(&call_to_object);
00472 __ push(r0);
00473 __ InvokeBuiltin(Builtins::TO_OBJECT, CALL_JS);
00474 __ b(&push_receiver);
00475
00476
00477 __ bind(&use_global_receiver);
00478 const int kGlobalOffset =
00479 Context::kHeaderSize + Context::GLOBAL_INDEX * kPointerSize;
00480 __ ldr(r0, FieldMemOperand(cp, kGlobalOffset));
00481 __ ldr(r0, FieldMemOperand(r0, GlobalObject::kGlobalReceiverOffset));
00482
00483
00484
00485 __ bind(&push_receiver);
00486 __ push(r0);
00487
00488
00489 Label entry, loop;
00490 __ ldr(r0, MemOperand(fp, kIndexOffset));
00491 __ b(&entry);
00492
00493
00494
00495
00496 __ bind(&loop);
00497 __ ldr(r1, MemOperand(fp, kArgsOffset));
00498 __ push(r1);
00499 __ push(r0);
00500
00501
00502 __ CallRuntime(Runtime::kGetProperty, 2);
00503 __ push(r0);
00504
00505
00506 __ ldr(r0, MemOperand(fp, kIndexOffset));
00507 __ add(r0, r0, Operand(1 << kSmiTagSize));
00508 __ str(r0, MemOperand(fp, kIndexOffset));
00509
00510
00511
00512 __ bind(&entry);
00513 __ ldr(r1, MemOperand(fp, kLimitOffset));
00514 __ cmp(r0, r1);
00515 __ b(ne, &loop);
00516
00517
00518 ParameterCount actual(r0);
00519 __ mov(r0, Operand(r0, ASR, kSmiTagSize));
00520 __ ldr(r1, MemOperand(fp, kFunctionOffset));
00521 __ InvokeFunction(r1, actual, CALL_FUNCTION);
00522
00523
00524 __ LeaveInternalFrame();
00525 __ add(sp, sp, Operand(3 * kPointerSize));
00526 __ mov(pc, lr);
00527 }
00528
00529
00530 static void EnterArgumentsAdaptorFrame(MacroAssembler* masm) {
00531 __ mov(r0, Operand(r0, LSL, kSmiTagSize));
00532 __ mov(r4, Operand(ArgumentsAdaptorFrame::SENTINEL));
00533 __ stm(db_w, sp, r0.bit() | r1.bit() | r4.bit() | fp.bit() | lr.bit());
00534 __ add(fp, sp, Operand(3 * kPointerSize));
00535 }
00536
00537
00538 static void LeaveArgumentsAdaptorFrame(MacroAssembler* masm) {
00539
00540
00541
00542
00543
00544 __ ldr(r1, MemOperand(fp, -3 * kPointerSize));
00545 __ mov(sp, fp);
00546 __ ldm(ia_w, sp, fp.bit() | lr.bit());
00547 __ add(sp, sp, Operand(r1, LSL, kPointerSizeLog2 - kSmiTagSize));
00548 __ add(sp, sp, Operand(kPointerSize));
00549 }
00550
00551
00552 void Builtins::Generate_ArgumentsAdaptorTrampoline(MacroAssembler* masm) {
00553
00554
00555
00556
00557
00558
00559
00560 Label invoke, dont_adapt_arguments;
00561
00562 Label enough, too_few;
00563 __ cmp(r0, Operand(r2));
00564 __ b(lt, &too_few);
00565 __ cmp(r2, Operand(SharedFunctionInfo::kDontAdaptArgumentsSentinel));
00566 __ b(eq, &dont_adapt_arguments);
00567
00568 {
00569 __ bind(&enough);
00570 EnterArgumentsAdaptorFrame(masm);
00571
00572
00573
00574
00575
00576
00577 __ add(r0, fp, Operand(r0, LSL, kPointerSizeLog2 - kSmiTagSize));
00578
00579 __ add(r0, r0, Operand(2 * kPointerSize));
00580 __ sub(r2, r0, Operand(r2, LSL, kPointerSizeLog2));
00581
00582
00583
00584
00585
00586
00587
00588 Label copy;
00589 __ bind(©);
00590 __ ldr(ip, MemOperand(r0, 0));
00591 __ push(ip);
00592 __ cmp(r0, r2);
00593 __ sub(r0, r0, Operand(kPointerSize));
00594 __ b(ne, ©);
00595
00596 __ b(&invoke);
00597 }
00598
00599 {
00600 __ bind(&too_few);
00601 EnterArgumentsAdaptorFrame(masm);
00602
00603
00604
00605
00606
00607
00608 __ add(r0, fp, Operand(r0, LSL, kPointerSizeLog2 - kSmiTagSize));
00609
00610
00611
00612
00613
00614
00615 Label copy;
00616 __ bind(©);
00617
00618 __ ldr(ip, MemOperand(r0, 2 * kPointerSize));
00619 __ push(ip);
00620 __ cmp(r0, fp);
00621 __ sub(r0, r0, Operand(kPointerSize));
00622 __ b(ne, ©);
00623
00624
00625
00626
00627
00628 __ mov(ip, Operand(Factory::undefined_value()));
00629 __ sub(r2, fp, Operand(r2, LSL, kPointerSizeLog2));
00630 __ sub(r2, r2, Operand(4 * kPointerSize));
00631
00632 Label fill;
00633 __ bind(&fill);
00634 __ push(ip);
00635 __ cmp(sp, r2);
00636 __ b(ne, &fill);
00637 }
00638
00639
00640 __ bind(&invoke);
00641 __ Call(r3);
00642
00643
00644 LeaveArgumentsAdaptorFrame(masm);
00645 __ mov(pc, lr);
00646
00647
00648
00649
00650
00651 __ bind(&dont_adapt_arguments);
00652 __ mov(pc, r3);
00653 }
00654
00655
00656 static void Generate_DebugBreakCallHelper(MacroAssembler* masm,
00657 RegList pointer_regs) {
00658
00659
00660
00661
00662
00663
00664 __ SaveRegistersToMemory(kJSCallerSaved);
00665
00666
00667
00668
00669 __ mov(ip, Operand(ExternalReference::the_hole_value_location()));
00670 __ ldr(r3, MemOperand(ip));
00671 __ mov(r0, Operand(0));
00672 __ stm(db_w, sp, r0.bit() | r3.bit());
00673
00674
00675
00676
00677
00678
00679
00680 __ add(ip, sp, Operand(kPointerSize));
00681
00682 __ mov(r3, Operand(0));
00683 __ mov(r2, Operand(cp));
00684
00685
00686
00687 __ stm(db_w, sp, r2.bit() | r3.bit() | pp.bit() | fp.bit() |
00688 ip.bit() | lr.bit());
00689
00690 __ add(fp, sp, Operand(-StandardFrameConstants::kContextOffset));
00691 __ mov(pp, Operand(ip));
00692
00693 __ push(r0);
00694
00695
00696
00697
00698
00699
00700 __ CopyRegistersFromMemoryToStack(sp, pointer_regs);
00701
00702 #ifdef DEBUG
00703 __ RecordComment("// Calling from debug break to runtime - come in - over");
00704 #endif
00705
00706 __ mov(r1, Operand(ExternalReference::debug_break()));
00707
00708 CEntryDebugBreakStub ceb;
00709 __ CallStub(&ceb);
00710
00711
00712
00713
00714 __ CopyRegistersFromStackToMemory(sp, r3, pointer_regs);
00715
00716
00717
00718
00719
00720
00721 __ mov(sp, Operand(fp));
00722 __ ldm(ia, sp, pp.bit() | fp.bit() | sp.bit() | lr.bit());
00723 __ pop();
00724
00725
00726
00727
00728 __ RestoreRegistersFromMemory(kJSCallerSaved);
00729
00730
00731
00732
00733 __ mov(ip, Operand(ExternalReference(Debug_Address::AfterBreakTarget())));
00734 __ ldr(ip, MemOperand(ip));
00735 __ Jump(ip);
00736 }
00737
00738
00739 void Builtins::Generate_LoadIC_DebugBreak(MacroAssembler* masm) {
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749 Generate_DebugBreakCallHelper(masm, r0.bit() | r2.bit());
00750 }
00751
00752
00753 void Builtins::Generate_StoreIC_DebugBreak(MacroAssembler* masm) {
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763 Generate_DebugBreakCallHelper(masm, r0.bit() | r2.bit());
00764 }
00765
00766
00767 void Builtins::Generate_KeyedLoadIC_DebugBreak(MacroAssembler* masm) {
00768
00769 }
00770
00771
00772 void Builtins::Generate_KeyedStoreIC_DebugBreak(MacroAssembler* masm) {
00773
00774 }
00775
00776
00777 void Builtins::Generate_CallIC_DebugBreak(MacroAssembler* masm) {
00778
00779
00780
00781
00782
00783
00784
00785
00786
00787
00788
00789 Generate_DebugBreakCallHelper(masm, r1.bit());
00790 }
00791
00792
00793 void Builtins::Generate_ConstructCall_DebugBreak(MacroAssembler* masm) {
00794
00795
00796
00797 Generate_DebugBreakCallHelper(masm, r0.bit());
00798 }
00799
00800
00801 void Builtins::Generate_Return_DebugBreak(MacroAssembler* masm) {
00802
00803
00804
00805 Generate_DebugBreakCallHelper(masm, r0.bit());
00806 }
00807
00808
00809 void Builtins::Generate_Return_DebugBreakEntry(MacroAssembler* masm) {
00810
00811
00812 }
00813
00814 void Builtins::Generate_StubNoRegisters_DebugBreak(MacroAssembler* masm) {
00815
00816 }
00817
00818
00819 #undef __
00820
00821 } }