| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #if V8_TARGET_ARCH_X64 | 7 #if V8_TARGET_ARCH_X64 |
| 8 | 8 |
| 9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
| 10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
| (...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 // MANUAL indicates that the scope shouldn't actually generate code to set up | 689 // MANUAL indicates that the scope shouldn't actually generate code to set up |
| 690 // the frame (that is done below). | 690 // the frame (that is done below). |
| 691 FrameScope frame_scope(masm, StackFrame::MANUAL); | 691 FrameScope frame_scope(masm, StackFrame::MANUAL); |
| 692 __ pushq(rbp); // Caller's frame pointer. | 692 __ pushq(rbp); // Caller's frame pointer. |
| 693 __ movp(rbp, rsp); | 693 __ movp(rbp, rsp); |
| 694 __ Push(rsi); // Callee's context. | 694 __ Push(rsi); // Callee's context. |
| 695 __ Push(rdi); // Callee's JS function. | 695 __ Push(rdi); // Callee's JS function. |
| 696 | 696 |
| 697 // Get the bytecode array from the function object and load the pointer to the | 697 // Get the bytecode array from the function object and load the pointer to the |
| 698 // first entry into edi (InterpreterBytecodeRegister). | 698 // first entry into edi (InterpreterBytecodeRegister). |
| 699 __ movp(r14, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); | 699 __ movp(rax, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); |
| 700 __ movp(r14, FieldOperand(r14, SharedFunctionInfo::kFunctionDataOffset)); | 700 __ movp(kInterpreterBytecodeArrayRegister, |
| 701 FieldOperand(rax, SharedFunctionInfo::kFunctionDataOffset)); |
| 701 | 702 |
| 702 if (FLAG_debug_code) { | 703 if (FLAG_debug_code) { |
| 703 // Check function data field is actually a BytecodeArray object. | 704 // Check function data field is actually a BytecodeArray object. |
| 704 __ AssertNotSmi(r14); | 705 __ AssertNotSmi(kInterpreterBytecodeArrayRegister); |
| 705 __ CmpObjectType(r14, BYTECODE_ARRAY_TYPE, rax); | 706 __ CmpObjectType(kInterpreterBytecodeArrayRegister, BYTECODE_ARRAY_TYPE, |
| 707 rax); |
| 706 __ Assert(equal, kFunctionDataShouldBeBytecodeArrayOnInterpreterEntry); | 708 __ Assert(equal, kFunctionDataShouldBeBytecodeArrayOnInterpreterEntry); |
| 707 } | 709 } |
| 708 | 710 |
| 709 // Allocate the local and temporary register file on the stack. | 711 // Allocate the local and temporary register file on the stack. |
| 710 { | 712 { |
| 711 // Load frame size from the BytecodeArray object. | 713 // Load frame size from the BytecodeArray object. |
| 712 __ movl(rcx, FieldOperand(r14, BytecodeArray::kFrameSizeOffset)); | 714 __ movl(rcx, FieldOperand(kInterpreterBytecodeArrayRegister, |
| 715 BytecodeArray::kFrameSizeOffset)); |
| 713 | 716 |
| 714 // Do a stack check to ensure we don't go over the limit. | 717 // Do a stack check to ensure we don't go over the limit. |
| 715 Label ok; | 718 Label ok; |
| 716 __ movp(rdx, rsp); | 719 __ movp(rdx, rsp); |
| 717 __ subp(rdx, rcx); | 720 __ subp(rdx, rcx); |
| 718 __ CompareRoot(rdx, Heap::kRealStackLimitRootIndex); | 721 __ CompareRoot(rdx, Heap::kRealStackLimitRootIndex); |
| 719 __ j(above_equal, &ok, Label::kNear); | 722 __ j(above_equal, &ok, Label::kNear); |
| 720 __ InvokeBuiltin(Builtins::STACK_OVERFLOW, CALL_FUNCTION); | 723 __ InvokeBuiltin(Builtins::STACK_OVERFLOW, CALL_FUNCTION); |
| 721 __ bind(&ok); | 724 __ bind(&ok); |
| 722 | 725 |
| 723 // If ok, push undefined as the initial value for all register file entries. | 726 // If ok, push undefined as the initial value for all register file entries. |
| 724 // Note: there should always be at least one stack slot for the return | |
| 725 // register in the register file. | |
| 726 Label loop_header; | 727 Label loop_header; |
| 728 Label loop_check; |
| 727 __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex); | 729 __ LoadRoot(rdx, Heap::kUndefinedValueRootIndex); |
| 730 __ j(always, &loop_check); |
| 728 __ bind(&loop_header); | 731 __ bind(&loop_header); |
| 729 // TODO(rmcilroy): Consider doing more than one push per loop iteration. | 732 // TODO(rmcilroy): Consider doing more than one push per loop iteration. |
| 730 __ Push(rdx); | 733 __ Push(rdx); |
| 731 // Continue loop if not done. | 734 // Continue loop if not done. |
| 735 __ bind(&loop_check); |
| 732 __ subp(rcx, Immediate(kPointerSize)); | 736 __ subp(rcx, Immediate(kPointerSize)); |
| 733 __ j(not_equal, &loop_header, Label::kNear); | 737 __ j(greater_equal, &loop_header, Label::kNear); |
| 734 } | 738 } |
| 735 | 739 |
| 736 // TODO(rmcilroy): List of things not currently dealt with here but done in | 740 // TODO(rmcilroy): List of things not currently dealt with here but done in |
| 737 // fullcodegen's prologue: | 741 // fullcodegen's prologue: |
| 738 // - Support profiler (specifically profiling_counter). | 742 // - Support profiler (specifically profiling_counter). |
| 739 // - Call ProfileEntryHookStub when isolate has a function_entry_hook. | 743 // - Call ProfileEntryHookStub when isolate has a function_entry_hook. |
| 740 // - Allow simulator stop operations if FLAG_stop_at is set. | 744 // - Allow simulator stop operations if FLAG_stop_at is set. |
| 741 // - Deal with sloppy mode functions which need to replace the | 745 // - Deal with sloppy mode functions which need to replace the |
| 742 // receiver with the global proxy when called as functions (without an | 746 // receiver with the global proxy when called as functions (without an |
| 743 // explicit receiver object). | 747 // explicit receiver object). |
| (...skipping 12 matching lines...) Expand all Loading... |
| 756 | 760 |
| 757 // Perform stack guard check. | 761 // Perform stack guard check. |
| 758 { | 762 { |
| 759 Label ok; | 763 Label ok; |
| 760 __ CompareRoot(rsp, Heap::kStackLimitRootIndex); | 764 __ CompareRoot(rsp, Heap::kStackLimitRootIndex); |
| 761 __ j(above_equal, &ok, Label::kNear); | 765 __ j(above_equal, &ok, Label::kNear); |
| 762 __ CallRuntime(Runtime::kStackGuard, 0); | 766 __ CallRuntime(Runtime::kStackGuard, 0); |
| 763 __ bind(&ok); | 767 __ bind(&ok); |
| 764 } | 768 } |
| 765 | 769 |
| 766 // Load bytecode offset and dispatch table into registers. | 770 // Load accumulator, register file, bytecode offset, dispatch table into |
| 767 __ movp(r12, Immediate(BytecodeArray::kHeaderSize - kHeapObjectTag)); | 771 // registers. |
| 768 __ LoadRoot(r15, Heap::kInterpreterTableRootIndex); | 772 __ LoadRoot(kInterpreterAccumulatorRegister, Heap::kUndefinedValueRootIndex); |
| 769 __ addp(r15, Immediate(FixedArray::kHeaderSize - kHeapObjectTag)); | 773 __ movp(kInterpreterRegisterFileRegister, rbp); |
| 774 __ subp( |
| 775 kInterpreterRegisterFileRegister, |
| 776 Immediate(kPointerSize + StandardFrameConstants::kFixedFrameSizeFromFp)); |
| 777 __ movp(kInterpreterBytecodeOffsetRegister, |
| 778 Immediate(BytecodeArray::kHeaderSize - kHeapObjectTag)); |
| 779 __ LoadRoot(kInterpreterDispatchTableRegister, |
| 780 Heap::kInterpreterTableRootIndex); |
| 781 __ addp(kInterpreterDispatchTableRegister, |
| 782 Immediate(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 770 | 783 |
| 771 // Dispatch to the first bytecode handler for the function. | 784 // Dispatch to the first bytecode handler for the function. |
| 772 __ movzxbp(rax, Operand(r14, r12, times_1, 0)); | 785 __ movzxbp(rbx, Operand(kInterpreterBytecodeArrayRegister, |
| 773 __ movp(rax, Operand(r15, rax, times_pointer_size, 0)); | 786 kInterpreterBytecodeOffsetRegister, times_1, 0)); |
| 787 __ movp(rbx, Operand(kInterpreterDispatchTableRegister, rbx, |
| 788 times_pointer_size, 0)); |
| 774 // TODO(rmcilroy): Make dispatch table point to code entrys to avoid untagging | 789 // TODO(rmcilroy): Make dispatch table point to code entrys to avoid untagging |
| 775 // and header removal. | 790 // and header removal. |
| 776 __ addp(rax, Immediate(Code::kHeaderSize - kHeapObjectTag)); | 791 __ addp(rbx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 777 __ jmp(rax); | 792 __ call(rbx); |
| 778 } | 793 } |
| 779 | 794 |
| 780 | 795 |
| 781 void Builtins::Generate_InterpreterExitTrampoline(MacroAssembler* masm) { | 796 void Builtins::Generate_InterpreterExitTrampoline(MacroAssembler* masm) { |
| 782 // TODO(rmcilroy): List of things not currently dealt with here but done in | 797 // TODO(rmcilroy): List of things not currently dealt with here but done in |
| 783 // fullcodegen's EmitReturnSequence. | 798 // fullcodegen's EmitReturnSequence. |
| 784 // - Supporting FLAG_trace for Runtime::TraceExit. | 799 // - Supporting FLAG_trace for Runtime::TraceExit. |
| 785 // - Support profiler (specifically decrementing profiling_counter | 800 // - Support profiler (specifically decrementing profiling_counter |
| 786 // appropriately and calling out to HandleInterrupts if necessary). | 801 // appropriately and calling out to HandleInterrupts if necessary). |
| 787 | 802 |
| 788 // Load return value into r0. | 803 // The return value is in accumulator, which is already in rax. |
| 789 __ movp(rax, Operand(rbp, -kPointerSize - | 804 |
| 790 StandardFrameConstants::kFixedFrameSizeFromFp)); | |
| 791 // Leave the frame (also dropping the register file). | 805 // Leave the frame (also dropping the register file). |
| 792 __ leave(); | 806 __ leave(); |
| 793 // Return droping receiver + arguments. | 807 // Return droping receiver + arguments. |
| 794 // TODO(rmcilroy): Get number of arguments from BytecodeArray. | 808 // TODO(rmcilroy): Get number of arguments from BytecodeArray. |
| 795 __ Ret(1 * kPointerSize, rcx); | 809 __ Ret(1 * kPointerSize, rcx); |
| 796 } | 810 } |
| 797 | 811 |
| 798 | 812 |
| 799 void Builtins::Generate_CompileLazy(MacroAssembler* masm) { | 813 void Builtins::Generate_CompileLazy(MacroAssembler* masm) { |
| 800 CallRuntimePassFunction(masm, Runtime::kCompileLazy); | 814 CallRuntimePassFunction(masm, Runtime::kCompileLazy); |
| (...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1838 __ ret(0); | 1852 __ ret(0); |
| 1839 } | 1853 } |
| 1840 | 1854 |
| 1841 | 1855 |
| 1842 #undef __ | 1856 #undef __ |
| 1843 | 1857 |
| 1844 } // namespace internal | 1858 } // namespace internal |
| 1845 } // namespace v8 | 1859 } // namespace v8 |
| 1846 | 1860 |
| 1847 #endif // V8_TARGET_ARCH_X64 | 1861 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |