OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 // r1: preserved | 625 // r1: preserved |
626 // r2: preserved | 626 // r2: preserved |
627 | 627 |
628 // Drop the execution stack down to the frame pointer and restore | 628 // Drop the execution stack down to the frame pointer and restore |
629 // the caller frame pointer and return address. | 629 // the caller frame pointer and return address. |
630 mov(sp, fp); | 630 mov(sp, fp); |
631 ldm(ia_w, sp, fp.bit() | lr.bit()); | 631 ldm(ia_w, sp, fp.bit() | lr.bit()); |
632 } | 632 } |
633 | 633 |
634 | 634 |
635 void MacroAssembler::EnterExitFrame(bool save_doubles) { | 635 void MacroAssembler::EnterExitFrame(bool save_doubles, int stack_space) { |
636 // Compute the argv pointer in a callee-saved register. | |
637 add(r6, sp, Operand(r0, LSL, kPointerSizeLog2)); | |
638 sub(r6, r6, Operand(kPointerSize)); | |
639 | |
640 // Setup the frame structure on the stack. | 636 // Setup the frame structure on the stack. |
641 ASSERT_EQ(2 * kPointerSize, ExitFrameConstants::kCallerSPDisplacement); | 637 ASSERT_EQ(2 * kPointerSize, ExitFrameConstants::kCallerSPDisplacement); |
642 ASSERT_EQ(1 * kPointerSize, ExitFrameConstants::kCallerPCOffset); | 638 ASSERT_EQ(1 * kPointerSize, ExitFrameConstants::kCallerPCOffset); |
643 ASSERT_EQ(0 * kPointerSize, ExitFrameConstants::kCallerFPOffset); | 639 ASSERT_EQ(0 * kPointerSize, ExitFrameConstants::kCallerFPOffset); |
644 Push(lr, fp); | 640 Push(lr, fp); |
645 mov(fp, Operand(sp)); // Setup new frame pointer. | 641 mov(fp, Operand(sp)); // Setup new frame pointer. |
646 // Reserve room for saved entry sp and code object. | 642 // Reserve room for saved entry sp and code object. |
647 sub(sp, sp, Operand(2 * kPointerSize)); | 643 sub(sp, sp, Operand(2 * kPointerSize)); |
648 if (FLAG_debug_code) { | 644 if (FLAG_debug_code) { |
649 mov(ip, Operand(0)); | 645 mov(ip, Operand(0)); |
650 str(ip, MemOperand(fp, ExitFrameConstants::kSPOffset)); | 646 str(ip, MemOperand(fp, ExitFrameConstants::kSPOffset)); |
651 } | 647 } |
652 mov(ip, Operand(CodeObject())); | 648 mov(ip, Operand(CodeObject())); |
653 str(ip, MemOperand(fp, ExitFrameConstants::kCodeOffset)); | 649 str(ip, MemOperand(fp, ExitFrameConstants::kCodeOffset)); |
654 | 650 |
655 // Save the frame pointer and the context in top. | 651 // Save the frame pointer and the context in top. |
656 mov(ip, Operand(ExternalReference(Top::k_c_entry_fp_address))); | 652 mov(ip, Operand(ExternalReference(Top::k_c_entry_fp_address))); |
657 str(fp, MemOperand(ip)); | 653 str(fp, MemOperand(ip)); |
658 mov(ip, Operand(ExternalReference(Top::k_context_address))); | 654 mov(ip, Operand(ExternalReference(Top::k_context_address))); |
659 str(cp, MemOperand(ip)); | 655 str(cp, MemOperand(ip)); |
660 | 656 |
661 // Setup argc and the builtin function in callee-saved registers. | |
662 mov(r4, Operand(r0)); | |
663 mov(r5, Operand(r1)); | |
664 | |
665 // Optionally save all double registers. | 657 // Optionally save all double registers. |
666 if (save_doubles) { | 658 if (save_doubles) { |
667 sub(sp, sp, Operand(DwVfpRegister::kNumRegisters * kDoubleSize)); | 659 sub(sp, sp, Operand(DwVfpRegister::kNumRegisters * kDoubleSize)); |
668 const int offset = -2 * kPointerSize; | 660 const int offset = -2 * kPointerSize; |
669 for (int i = 0; i < DwVfpRegister::kNumRegisters; i++) { | 661 for (int i = 0; i < DwVfpRegister::kNumRegisters; i++) { |
670 DwVfpRegister reg = DwVfpRegister::from_code(i); | 662 DwVfpRegister reg = DwVfpRegister::from_code(i); |
671 vstr(reg, fp, offset - ((i + 1) * kDoubleSize)); | 663 vstr(reg, fp, offset - ((i + 1) * kDoubleSize)); |
672 } | 664 } |
673 // Note that d0 will be accessible at | 665 // Note that d0 will be accessible at |
674 // fp - 2 * kPointerSize - DwVfpRegister::kNumRegisters * kDoubleSize, | 666 // fp - 2 * kPointerSize - DwVfpRegister::kNumRegisters * kDoubleSize, |
675 // since the sp slot and code slot were pushed after the fp. | 667 // since the sp slot and code slot were pushed after the fp. |
676 } | 668 } |
677 | 669 |
678 // Reserve place for the return address and align the frame preparing for | 670 // Reserve place for the return address and stack space and align the frame |
679 // calling the runtime function. | 671 // preparing for calling the runtime function. |
680 const int frame_alignment = MacroAssembler::ActivationFrameAlignment(); | 672 const int frame_alignment = MacroAssembler::ActivationFrameAlignment(); |
681 sub(sp, sp, Operand(kPointerSize)); | 673 sub(sp, sp, Operand((stack_space + 1) * kPointerSize)); |
682 if (frame_alignment > 0) { | 674 if (frame_alignment > 0) { |
683 ASSERT(IsPowerOf2(frame_alignment)); | 675 ASSERT(IsPowerOf2(frame_alignment)); |
684 and_(sp, sp, Operand(-frame_alignment)); | 676 and_(sp, sp, Operand(-frame_alignment)); |
685 } | 677 } |
686 | 678 |
687 // Set the exit frame sp value to point just before the return address | 679 // Set the exit frame sp value to point just before the return address |
688 // location. | 680 // location. |
689 add(ip, sp, Operand(kPointerSize)); | 681 add(ip, sp, Operand(kPointerSize)); |
690 str(ip, MemOperand(fp, ExitFrameConstants::kSPOffset)); | 682 str(ip, MemOperand(fp, ExitFrameConstants::kSPOffset)); |
691 } | 683 } |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1468 // in initial map. | 1460 // in initial map. |
1469 bind(&non_instance); | 1461 bind(&non_instance); |
1470 ldr(result, FieldMemOperand(result, Map::kConstructorOffset)); | 1462 ldr(result, FieldMemOperand(result, Map::kConstructorOffset)); |
1471 | 1463 |
1472 // All done. | 1464 // All done. |
1473 bind(&done); | 1465 bind(&done); |
1474 } | 1466 } |
1475 | 1467 |
1476 | 1468 |
1477 void MacroAssembler::CallStub(CodeStub* stub, Condition cond) { | 1469 void MacroAssembler::CallStub(CodeStub* stub, Condition cond) { |
1478 ASSERT(allow_stub_calls()); // stub calls are not allowed in some stubs | 1470 ASSERT(allow_stub_calls()); // Stub calls are not allowed in some stubs. |
1479 Call(stub->GetCode(), RelocInfo::CODE_TARGET, cond); | 1471 Call(stub->GetCode(), RelocInfo::CODE_TARGET, cond); |
1480 } | 1472 } |
1481 | 1473 |
1482 | 1474 |
1483 void MacroAssembler::TailCallStub(CodeStub* stub, Condition cond) { | 1475 void MacroAssembler::TailCallStub(CodeStub* stub, Condition cond) { |
1484 ASSERT(allow_stub_calls()); // stub calls are not allowed in some stubs | 1476 ASSERT(allow_stub_calls()); // Stub calls are not allowed in some stubs. |
1485 Jump(stub->GetCode(), RelocInfo::CODE_TARGET, cond); | 1477 Jump(stub->GetCode(), RelocInfo::CODE_TARGET, cond); |
1486 } | 1478 } |
1487 | 1479 |
1488 | 1480 |
| 1481 MaybeObject* MacroAssembler::TryTailCallStub(CodeStub* stub, Condition cond) { |
| 1482 ASSERT(allow_stub_calls()); // Stub calls are not allowed in some stubs. |
| 1483 Object* result; |
| 1484 { MaybeObject* maybe_result = stub->TryGetCode(); |
| 1485 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 1486 } |
| 1487 Jump(stub->GetCode(), RelocInfo::CODE_TARGET, cond); |
| 1488 return result; |
| 1489 } |
| 1490 |
| 1491 |
| 1492 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) { |
| 1493 return ref0.address() - ref1.address(); |
| 1494 } |
| 1495 |
| 1496 |
| 1497 MaybeObject* MacroAssembler::TryCallApiFunctionAndReturn( |
| 1498 ApiFunction* function, int stack_space) { |
| 1499 ExternalReference next_address = |
| 1500 ExternalReference::handle_scope_next_address(); |
| 1501 const int kNextOffset = 0; |
| 1502 const int kLimitOffset = AddressOffset( |
| 1503 ExternalReference::handle_scope_limit_address(), |
| 1504 next_address); |
| 1505 const int kLevelOffset = AddressOffset( |
| 1506 ExternalReference::handle_scope_level_address(), |
| 1507 next_address); |
| 1508 |
| 1509 // Allocate HandleScope in callee-save registers. |
| 1510 mov(r7, Operand(next_address)); |
| 1511 ldr(r4, MemOperand(r7, kNextOffset)); |
| 1512 ldr(r5, MemOperand(r7, kLimitOffset)); |
| 1513 ldr(r6, MemOperand(r7, kLevelOffset)); |
| 1514 add(r6, r6, Operand(1)); |
| 1515 str(r6, MemOperand(r7, kLevelOffset)); |
| 1516 |
| 1517 // Native call returns to the DirectCEntry stub which redirects to the |
| 1518 // return address pushed on stack (could have moved after GC). |
| 1519 // DirectCEntry stub itself is generated early and never moves. |
| 1520 DirectCEntryStub stub; |
| 1521 stub.GenerateCall(this, function); |
| 1522 |
| 1523 Label promote_scheduled_exception; |
| 1524 Label delete_allocated_handles; |
| 1525 Label leave_exit_frame; |
| 1526 |
| 1527 // If result is non-zero, dereference to get the result value |
| 1528 // otherwise set it to undefined. |
| 1529 cmp(r0, Operand(0)); |
| 1530 LoadRoot(r0, Heap::kUndefinedValueRootIndex, eq); |
| 1531 ldr(r0, MemOperand(r0), ne); |
| 1532 |
| 1533 // No more valid handles (the result handle was the last one). Restore |
| 1534 // previous handle scope. |
| 1535 str(r4, MemOperand(r7, kNextOffset)); |
| 1536 if (FLAG_debug_code) { |
| 1537 ldr(r1, MemOperand(r7, kLevelOffset)); |
| 1538 cmp(r1, r6); |
| 1539 Check(eq, "Unexpected level after return from api call"); |
| 1540 } |
| 1541 sub(r6, r6, Operand(1)); |
| 1542 str(r6, MemOperand(r7, kLevelOffset)); |
| 1543 ldr(ip, MemOperand(r7, kLimitOffset)); |
| 1544 cmp(r5, ip); |
| 1545 b(ne, &delete_allocated_handles); |
| 1546 |
| 1547 // Check if the function scheduled an exception. |
| 1548 bind(&leave_exit_frame); |
| 1549 LoadRoot(r4, Heap::kTheHoleValueRootIndex); |
| 1550 mov(ip, Operand(ExternalReference::scheduled_exception_address())); |
| 1551 ldr(r5, MemOperand(ip)); |
| 1552 cmp(r4, r5); |
| 1553 b(ne, &promote_scheduled_exception); |
| 1554 |
| 1555 // LeaveExitFrame expects unwind space to be in r4. |
| 1556 mov(r4, Operand(stack_space)); |
| 1557 LeaveExitFrame(false); |
| 1558 |
| 1559 bind(&promote_scheduled_exception); |
| 1560 MaybeObject* result = TryTailCallExternalReference( |
| 1561 ExternalReference(Runtime::kPromoteScheduledException), 0, 1); |
| 1562 if (result->IsFailure()) { |
| 1563 return result; |
| 1564 } |
| 1565 |
| 1566 // HandleScope limit has changed. Delete allocated extensions. |
| 1567 bind(&delete_allocated_handles); |
| 1568 str(r5, MemOperand(r7, kLimitOffset)); |
| 1569 mov(r4, r0); |
| 1570 PrepareCallCFunction(0, r5); |
| 1571 CallCFunction(ExternalReference::delete_handle_scope_extensions(), 0); |
| 1572 mov(r0, r4); |
| 1573 jmp(&leave_exit_frame); |
| 1574 |
| 1575 return result; |
| 1576 } |
| 1577 |
| 1578 |
1489 void MacroAssembler::IllegalOperation(int num_arguments) { | 1579 void MacroAssembler::IllegalOperation(int num_arguments) { |
1490 if (num_arguments > 0) { | 1580 if (num_arguments > 0) { |
1491 add(sp, sp, Operand(num_arguments * kPointerSize)); | 1581 add(sp, sp, Operand(num_arguments * kPointerSize)); |
1492 } | 1582 } |
1493 LoadRoot(r0, Heap::kUndefinedValueRootIndex); | 1583 LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
1494 } | 1584 } |
1495 | 1585 |
1496 | 1586 |
1497 void MacroAssembler::IndexFromHash(Register hash, Register index) { | 1587 void MacroAssembler::IndexFromHash(Register hash, Register index) { |
1498 // If the hash field contains an array index pick it out. The assert checks | 1588 // If the hash field contains an array index pick it out. The assert checks |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1733 int result_size) { | 1823 int result_size) { |
1734 // TODO(1236192): Most runtime routines don't need the number of | 1824 // TODO(1236192): Most runtime routines don't need the number of |
1735 // arguments passed in because it is constant. At some point we | 1825 // arguments passed in because it is constant. At some point we |
1736 // should remove this need and make the runtime routine entry code | 1826 // should remove this need and make the runtime routine entry code |
1737 // smarter. | 1827 // smarter. |
1738 mov(r0, Operand(num_arguments)); | 1828 mov(r0, Operand(num_arguments)); |
1739 JumpToExternalReference(ext); | 1829 JumpToExternalReference(ext); |
1740 } | 1830 } |
1741 | 1831 |
1742 | 1832 |
| 1833 MaybeObject* MacroAssembler::TryTailCallExternalReference( |
| 1834 const ExternalReference& ext, int num_arguments, int result_size) { |
| 1835 // TODO(1236192): Most runtime routines don't need the number of |
| 1836 // arguments passed in because it is constant. At some point we |
| 1837 // should remove this need and make the runtime routine entry code |
| 1838 // smarter. |
| 1839 mov(r0, Operand(num_arguments)); |
| 1840 return TryJumpToExternalReference(ext); |
| 1841 } |
| 1842 |
| 1843 |
1743 void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, | 1844 void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, |
1744 int num_arguments, | 1845 int num_arguments, |
1745 int result_size) { | 1846 int result_size) { |
1746 TailCallExternalReference(ExternalReference(fid), num_arguments, result_size); | 1847 TailCallExternalReference(ExternalReference(fid), num_arguments, result_size); |
1747 } | 1848 } |
1748 | 1849 |
1749 | 1850 |
1750 void MacroAssembler::JumpToExternalReference(const ExternalReference& builtin) { | 1851 void MacroAssembler::JumpToExternalReference(const ExternalReference& builtin) { |
1751 #if defined(__thumb__) | 1852 #if defined(__thumb__) |
1752 // Thumb mode builtin. | 1853 // Thumb mode builtin. |
1753 ASSERT((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1); | 1854 ASSERT((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1); |
1754 #endif | 1855 #endif |
1755 mov(r1, Operand(builtin)); | 1856 mov(r1, Operand(builtin)); |
1756 CEntryStub stub(1); | 1857 CEntryStub stub(1); |
1757 Jump(stub.GetCode(), RelocInfo::CODE_TARGET); | 1858 Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
1758 } | 1859 } |
1759 | 1860 |
1760 | 1861 |
| 1862 MaybeObject* MacroAssembler::TryJumpToExternalReference( |
| 1863 const ExternalReference& builtin) { |
| 1864 #if defined(__thumb__) |
| 1865 // Thumb mode builtin. |
| 1866 ASSERT((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1); |
| 1867 #endif |
| 1868 mov(r1, Operand(builtin)); |
| 1869 CEntryStub stub(1); |
| 1870 return TryTailCallStub(&stub); |
| 1871 } |
| 1872 |
| 1873 |
1761 void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, | 1874 void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, |
1762 InvokeJSFlags flags, | 1875 InvokeJSFlags flags, |
1763 PostCallGenerator* post_call_generator) { | 1876 PostCallGenerator* post_call_generator) { |
1764 GetBuiltinEntry(r2, id); | 1877 GetBuiltinEntry(r2, id); |
1765 if (flags == CALL_JS) { | 1878 if (flags == CALL_JS) { |
1766 Call(r2); | 1879 Call(r2); |
1767 if (post_call_generator != NULL) post_call_generator->Generate(); | 1880 if (post_call_generator != NULL) post_call_generator->Generate(); |
1768 } else { | 1881 } else { |
1769 ASSERT(flags == JUMP_JS); | 1882 ASSERT(flags == JUMP_JS); |
1770 Jump(r2); | 1883 Jump(r2); |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2296 | 2409 |
2297 void CodePatcher::Emit(Address addr) { | 2410 void CodePatcher::Emit(Address addr) { |
2298 masm()->emit(reinterpret_cast<Instr>(addr)); | 2411 masm()->emit(reinterpret_cast<Instr>(addr)); |
2299 } | 2412 } |
2300 #endif // ENABLE_DEBUGGER_SUPPORT | 2413 #endif // ENABLE_DEBUGGER_SUPPORT |
2301 | 2414 |
2302 | 2415 |
2303 } } // namespace v8::internal | 2416 } } // namespace v8::internal |
2304 | 2417 |
2305 #endif // V8_TARGET_ARCH_ARM | 2418 #endif // V8_TARGET_ARCH_ARM |
OLD | NEW |