Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 1379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1390 Call(stub->GetCode(), RelocInfo::CODE_TARGET, cond); | 1390 Call(stub->GetCode(), RelocInfo::CODE_TARGET, cond); |
| 1391 } | 1391 } |
| 1392 | 1392 |
| 1393 | 1393 |
| 1394 void MacroAssembler::TailCallStub(CodeStub* stub, Condition cond) { | 1394 void MacroAssembler::TailCallStub(CodeStub* stub, Condition cond) { |
| 1395 ASSERT(allow_stub_calls()); // stub calls are not allowed in some stubs | 1395 ASSERT(allow_stub_calls()); // stub calls are not allowed in some stubs |
| 1396 Jump(stub->GetCode(), RelocInfo::CODE_TARGET, cond); | 1396 Jump(stub->GetCode(), RelocInfo::CODE_TARGET, cond); |
| 1397 } | 1397 } |
| 1398 | 1398 |
| 1399 | 1399 |
| 1400 MaybeObject* MacroAssembler::TryTailCallStub(CodeStub* stub, Condition cond) { | |
| 1401 ASSERT(allow_stub_calls()); // stub calls are not allowed in some stubs | |
| 1402 Object* result; | |
| 1403 { MaybeObject* maybe_result = stub->TryGetCode(); | |
| 1404 if (!maybe_result->ToObject(&result)) return maybe_result; | |
| 1405 } | |
| 1406 Jump(stub->GetCode(), RelocInfo::CODE_TARGET, cond); | |
| 1407 return result; | |
| 1408 } | |
| 1409 | |
| 1410 void MacroAssembler::EnterExitFramePrologue(int unwind_space) { | |
|
antonm
2011/01/13 12:47:08
Thanks a lot for introducing this macros. But you
Zaheer
2011/01/13 14:17:09
EnterExitFrame satisfies the builtin (argc/argv) i
| |
| 1411 add(ip, sp, Operand(unwind_space * kPointerSize)); | |
| 1412 stm(db_w, sp, fp.bit() | ip.bit() | lr.bit()); | |
|
antonm
2011/01/13 12:47:08
Please, retain the original comment which describe
Zaheer
2011/01/13 14:17:09
Done.
| |
| 1413 mov(fp, Operand(sp)); | |
| 1414 | |
| 1415 mov(ip, Operand(CodeObject())); | |
| 1416 push(ip); | |
| 1417 push(ip); // Exit Frame pc patched before call | |
| 1418 | |
| 1419 mov(ip, Operand(ExternalReference(Top::k_c_entry_fp_address))); | |
| 1420 str(fp, MemOperand(ip)); | |
| 1421 mov(ip, Operand(ExternalReference(Top::k_context_address))); | |
| 1422 str(cp, MemOperand(ip)); | |
| 1423 } | |
| 1424 | |
| 1425 void MacroAssembler::EnterExitFrameEpilogue(int arg_stack_space) { | |
| 1426 // Create space for the args | |
|
antonm
2011/01/13 12:47:08
nit: period at the end of the comment, please
Zaheer
2011/01/13 14:17:09
Done.
| |
| 1427 sub(sp, sp, Operand(arg_stack_space * kPointerSize)); | |
| 1428 | |
| 1429 int frame_alignment = ActivationFrameAlignment(); | |
| 1430 int frame_alignment_mask = frame_alignment - 1; | |
| 1431 if (frame_alignment > kPointerSize) { | |
| 1432 ASSERT(frame_alignment == 2 * kPointerSize); | |
| 1433 tst(sp, Operand(frame_alignment_mask)); | |
|
antonm
2011/01/13 12:47:08
please, keep the comment
Zaheer
2011/01/13 14:17:09
Done.
| |
| 1434 push(ip, nz); | |
| 1435 } | |
| 1436 } | |
| 1437 | |
| 1438 void MacroAssembler::PrepareCallApiFunction(int arg_stack_space, | |
| 1439 int unwind_space) { | |
| 1440 EnterExitFramePrologue(unwind_space); | |
| 1441 EnterExitFrameEpilogue(arg_stack_space); | |
| 1442 } | |
| 1443 | |
| 1444 static int AddressOffset(ExternalReference ref0, ExternalReference ref1) { | |
| 1445 int64_t offset = (ref0.address() - ref1.address()); | |
| 1446 // Check that fits into int. | |
| 1447 ASSERT(static_cast<int>(offset) == offset); | |
| 1448 return static_cast<int>(offset); | |
| 1449 } | |
| 1450 | |
| 1451 MaybeObject* MacroAssembler::TryCallApiFunctionAndReturn( | |
| 1452 ApiFunction* function) { | |
| 1453 ExternalReference next_address = | |
| 1454 ExternalReference::handle_scope_next_address(); | |
| 1455 const int kNextOffset = 0; | |
| 1456 const int kLimitOffset = AddressOffset( | |
| 1457 ExternalReference::handle_scope_limit_address(), | |
| 1458 next_address); | |
| 1459 const int kLevelOffset = AddressOffset( | |
| 1460 ExternalReference::handle_scope_level_address(), | |
| 1461 next_address); | |
| 1462 | |
| 1463 // Allocate HandleScope in callee-save registers. | |
| 1464 mov(r7, Operand(next_address)); | |
| 1465 ldr(r4, MemOperand(r7, kNextOffset)); | |
| 1466 ldr(r5, MemOperand(r7, kLimitOffset)); | |
| 1467 ldr(r6, MemOperand(r7, kLevelOffset)); | |
| 1468 add(r6, r6, Operand(1)); | |
| 1469 str(r6, MemOperand(r7, kLevelOffset)); | |
| 1470 | |
| 1471 // patch the exit frame pc and Call the api function! | |
|
antonm
2011/01/13 12:47:08
nit: [P]atch and [c]all
Zaheer
2011/01/13 14:17:09
Done.
| |
| 1472 add(ip, pc, Operand(8)); | |
| 1473 str(ip, MemOperand(fp, -2 * kPointerSize)); | |
| 1474 Call(function->address(), RelocInfo::RUNTIME_ENTRY); | |
| 1475 | |
| 1476 Label promote_scheduled_exception; | |
| 1477 Label delete_allocated_handles; | |
| 1478 Label leave_exit_frame; | |
| 1479 | |
| 1480 // If result is non-zero, dereference to get the result value | |
| 1481 // otherwise set it to undefined | |
|
antonm
2011/01/13 12:47:08
nit: period at the end of the comment.
Zaheer
2011/01/13 14:17:09
Done.
| |
| 1482 LoadRoot(r0, Heap::kUndefinedValueRootIndex, eq); | |
|
antonm
2011/01/13 12:47:08
it looks like you forgot cmp(r0, Operand(0))
Zaheer
2011/01/13 14:17:09
sorry, i realized that in my tests. fixed.
| |
| 1483 ldr(r0, MemOperand(r0), ne); | |
| 1484 | |
| 1485 // No more valid handles (the result handle was the last one). Restore | |
| 1486 // previous handle scope. | |
| 1487 str(r4, MemOperand(r7, kNextOffset)); | |
| 1488 if (FLAG_debug_code) { | |
| 1489 ldr(r1, MemOperand(r7, kLevelOffset)); | |
| 1490 cmp(r1, r6); | |
| 1491 Check(eq, "Unexpected level after return from api call"); | |
| 1492 } | |
| 1493 sub(r6, r6, Operand(1)); | |
| 1494 str(r6, MemOperand(r7, kLevelOffset)); | |
| 1495 ldr(ip, MemOperand(r7, kLimitOffset)); | |
| 1496 cmp(r5, ip); | |
| 1497 b(ne, &delete_allocated_handles); | |
| 1498 | |
| 1499 // Check if the function scheduled an exception. | |
| 1500 bind(&leave_exit_frame); | |
| 1501 mov(ip, Operand(ExternalReference::the_hole_value_location())); | |
|
antonm
2011/01/13 12:47:08
please, use LoadRoot.
Zaheer
2011/01/13 14:17:09
Done.
| |
| 1502 ldr(r4, MemOperand(ip)); | |
| 1503 mov(ip, Operand(ExternalReference(Top::k_pending_exception_address))); | |
| 1504 ldr(r5, MemOperand(ip)); | |
| 1505 cmp(r4, r5); | |
| 1506 b(ne, &promote_scheduled_exception); | |
| 1507 LeaveExitFrame(false); | |
| 1508 | |
| 1509 bind(&promote_scheduled_exception); | |
| 1510 MaybeObject* result = TryTailCallExternalReference( | |
| 1511 ExternalReference(Runtime::kPromoteScheduledException), 0, 1); | |
| 1512 if (result->IsFailure()) { | |
| 1513 return result; | |
| 1514 } | |
| 1515 | |
| 1516 // HandleScope limit has changed. Delete allocated extensions. | |
| 1517 bind(&delete_allocated_handles); | |
| 1518 str(r5, MemOperand(r7, kLimitOffset)); | |
| 1519 mov(r4, r0); | |
| 1520 PrepareCallCFunction(0, r5); | |
| 1521 CallCFunction(ExternalReference::delete_handle_scope_extensions(), 0); | |
| 1522 mov(r0, r4); | |
| 1523 jmp(&leave_exit_frame); | |
| 1524 | |
| 1525 return result; | |
| 1526 } | |
| 1527 | |
| 1528 | |
| 1400 void MacroAssembler::IllegalOperation(int num_arguments) { | 1529 void MacroAssembler::IllegalOperation(int num_arguments) { |
| 1401 if (num_arguments > 0) { | 1530 if (num_arguments > 0) { |
| 1402 add(sp, sp, Operand(num_arguments * kPointerSize)); | 1531 add(sp, sp, Operand(num_arguments * kPointerSize)); |
| 1403 } | 1532 } |
| 1404 LoadRoot(r0, Heap::kUndefinedValueRootIndex); | 1533 LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
| 1405 } | 1534 } |
| 1406 | 1535 |
| 1407 | 1536 |
| 1408 void MacroAssembler::IndexFromHash(Register hash, Register index) { | 1537 void MacroAssembler::IndexFromHash(Register hash, Register index) { |
| 1409 // If the hash field contains an array index pick it out. The assert checks | 1538 // If the hash field contains an array index pick it out. The assert checks |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1642 int num_arguments, | 1771 int num_arguments, |
| 1643 int result_size) { | 1772 int result_size) { |
| 1644 // TODO(1236192): Most runtime routines don't need the number of | 1773 // TODO(1236192): Most runtime routines don't need the number of |
| 1645 // arguments passed in because it is constant. At some point we | 1774 // arguments passed in because it is constant. At some point we |
| 1646 // should remove this need and make the runtime routine entry code | 1775 // should remove this need and make the runtime routine entry code |
| 1647 // smarter. | 1776 // smarter. |
| 1648 mov(r0, Operand(num_arguments)); | 1777 mov(r0, Operand(num_arguments)); |
| 1649 JumpToExternalReference(ext); | 1778 JumpToExternalReference(ext); |
| 1650 } | 1779 } |
| 1651 | 1780 |
| 1781 MaybeObject* MacroAssembler::TryTailCallExternalReference( | |
| 1782 const ExternalReference& ext, int num_arguments, int result_size) { | |
| 1783 // TODO(1236192): Most runtime routines don't need the number of | |
| 1784 // arguments passed in because it is constant. At some point we | |
| 1785 // should remove this need and make the runtime routine entry code | |
| 1786 // smarter. | |
| 1787 mov(r0, Operand(num_arguments)); | |
| 1788 return TryJumpToExternalReference(ext); | |
| 1789 } | |
| 1652 | 1790 |
| 1653 void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, | 1791 void MacroAssembler::TailCallRuntime(Runtime::FunctionId fid, |
| 1654 int num_arguments, | 1792 int num_arguments, |
| 1655 int result_size) { | 1793 int result_size) { |
| 1656 TailCallExternalReference(ExternalReference(fid), num_arguments, result_size); | 1794 TailCallExternalReference(ExternalReference(fid), num_arguments, result_size); |
| 1657 } | 1795 } |
| 1658 | 1796 |
| 1659 | 1797 |
| 1660 void MacroAssembler::JumpToExternalReference(const ExternalReference& builtin) { | 1798 void MacroAssembler::JumpToExternalReference(const ExternalReference& builtin) { |
| 1661 #if defined(__thumb__) | 1799 #if defined(__thumb__) |
| 1662 // Thumb mode builtin. | 1800 // Thumb mode builtin. |
| 1663 ASSERT((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1); | 1801 ASSERT((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1); |
| 1664 #endif | 1802 #endif |
| 1665 mov(r1, Operand(builtin)); | 1803 mov(r1, Operand(builtin)); |
| 1666 CEntryStub stub(1); | 1804 CEntryStub stub(1); |
| 1667 Jump(stub.GetCode(), RelocInfo::CODE_TARGET); | 1805 Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 1668 } | 1806 } |
| 1669 | 1807 |
| 1808 MaybeObject* MacroAssembler::TryJumpToExternalReference( | |
| 1809 const ExternalReference& builtin) { | |
| 1810 #if defined(__thumb__) | |
| 1811 // Thumb mode builtin. | |
| 1812 ASSERT((reinterpret_cast<intptr_t>(builtin.address()) & 1) == 1); | |
| 1813 #endif | |
| 1814 mov(r1, Operand(builtin)); | |
| 1815 CEntryStub stub(1); | |
| 1816 return TryTailCallStub(&stub); | |
| 1817 } | |
| 1670 | 1818 |
| 1671 void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, | 1819 void MacroAssembler::InvokeBuiltin(Builtins::JavaScript id, |
| 1672 InvokeJSFlags flags) { | 1820 InvokeJSFlags flags) { |
| 1673 GetBuiltinEntry(r2, id); | 1821 GetBuiltinEntry(r2, id); |
| 1674 if (flags == CALL_JS) { | 1822 if (flags == CALL_JS) { |
| 1675 Call(r2); | 1823 Call(r2); |
| 1676 } else { | 1824 } else { |
| 1677 ASSERT(flags == JUMP_JS); | 1825 ASSERT(flags == JUMP_JS); |
| 1678 Jump(r2); | 1826 Jump(r2); |
| 1679 } | 1827 } |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2145 | 2293 |
| 2146 void CodePatcher::Emit(Address addr) { | 2294 void CodePatcher::Emit(Address addr) { |
| 2147 masm()->emit(reinterpret_cast<Instr>(addr)); | 2295 masm()->emit(reinterpret_cast<Instr>(addr)); |
| 2148 } | 2296 } |
| 2149 #endif // ENABLE_DEBUGGER_SUPPORT | 2297 #endif // ENABLE_DEBUGGER_SUPPORT |
| 2150 | 2298 |
| 2151 | 2299 |
| 2152 } } // namespace v8::internal | 2300 } } // namespace v8::internal |
| 2153 | 2301 |
| 2154 #endif // V8_TARGET_ARCH_ARM | 2302 #endif // V8_TARGET_ARCH_ARM |
| OLD | NEW |