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_IA32 | 7 #if V8_TARGET_ARCH_IA32 |
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 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 // MANUAL indicates that the scope shouldn't actually generate code to set up | 625 // MANUAL indicates that the scope shouldn't actually generate code to set up |
626 // the frame (that is done below). | 626 // the frame (that is done below). |
627 FrameScope frame_scope(masm, StackFrame::MANUAL); | 627 FrameScope frame_scope(masm, StackFrame::MANUAL); |
628 __ push(ebp); // Caller's frame pointer. | 628 __ push(ebp); // Caller's frame pointer. |
629 __ mov(ebp, esp); | 629 __ mov(ebp, esp); |
630 __ push(esi); // Callee's context. | 630 __ push(esi); // Callee's context. |
631 __ push(edi); // Callee's JS function. | 631 __ push(edi); // Callee's JS function. |
632 | 632 |
633 // Get the bytecode array from the function object and load the pointer to the | 633 // Get the bytecode array from the function object and load the pointer to the |
634 // first entry into edi (InterpreterBytecodeRegister). | 634 // first entry into edi (InterpreterBytecodeRegister). |
635 __ mov(edi, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); | 635 __ mov(eax, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
636 __ mov(edi, FieldOperand(edi, SharedFunctionInfo::kFunctionDataOffset)); | 636 __ mov(kInterpreterBytecodeArrayRegister, |
| 637 FieldOperand(eax, SharedFunctionInfo::kFunctionDataOffset)); |
637 | 638 |
638 if (FLAG_debug_code) { | 639 if (FLAG_debug_code) { |
639 // Check function data field is actually a BytecodeArray object. | 640 // Check function data field is actually a BytecodeArray object. |
640 __ AssertNotSmi(edi); | 641 __ AssertNotSmi(kInterpreterBytecodeArrayRegister); |
641 __ CmpObjectType(edi, BYTECODE_ARRAY_TYPE, eax); | 642 __ CmpObjectType(kInterpreterBytecodeArrayRegister, BYTECODE_ARRAY_TYPE, |
| 643 eax); |
642 __ Assert(equal, kFunctionDataShouldBeBytecodeArrayOnInterpreterEntry); | 644 __ Assert(equal, kFunctionDataShouldBeBytecodeArrayOnInterpreterEntry); |
643 } | 645 } |
644 | 646 |
645 // Allocate the local and temporary register file on the stack. | 647 // Allocate the local and temporary register file on the stack. |
646 { | 648 { |
647 // Load frame size from the BytecodeArray object. | 649 // Load frame size from the BytecodeArray object. |
648 __ mov(ebx, FieldOperand(edi, BytecodeArray::kFrameSizeOffset)); | 650 __ mov(ebx, FieldOperand(kInterpreterBytecodeArrayRegister, |
| 651 BytecodeArray::kFrameSizeOffset)); |
649 | 652 |
650 // Do a stack check to ensure we don't go over the limit. | 653 // Do a stack check to ensure we don't go over the limit. |
651 Label ok; | 654 Label ok; |
652 __ mov(ecx, esp); | 655 __ mov(ecx, esp); |
653 __ sub(ecx, ebx); | 656 __ sub(ecx, ebx); |
654 ExternalReference stack_limit = | 657 ExternalReference stack_limit = |
655 ExternalReference::address_of_real_stack_limit(masm->isolate()); | 658 ExternalReference::address_of_real_stack_limit(masm->isolate()); |
656 __ cmp(ecx, Operand::StaticVariable(stack_limit)); | 659 __ cmp(ecx, Operand::StaticVariable(stack_limit)); |
657 __ j(above_equal, &ok, Label::kNear); | 660 __ j(above_equal, &ok); |
658 __ InvokeBuiltin(Builtins::STACK_OVERFLOW, CALL_FUNCTION); | 661 __ InvokeBuiltin(Builtins::STACK_OVERFLOW, CALL_FUNCTION); |
659 __ bind(&ok); | 662 __ bind(&ok); |
660 | 663 |
661 // If ok, push undefined as the initial value for all register file entries. | 664 // If ok, push undefined as the initial value for all register file entries. |
662 // Note: there should always be at least one stack slot for the return | |
663 // register in the register file. | |
664 Label loop_header; | 665 Label loop_header; |
| 666 Label loop_check; |
665 __ mov(eax, Immediate(masm->isolate()->factory()->undefined_value())); | 667 __ mov(eax, Immediate(masm->isolate()->factory()->undefined_value())); |
| 668 __ jmp(&loop_check); |
666 __ bind(&loop_header); | 669 __ bind(&loop_header); |
667 // TODO(rmcilroy): Consider doing more than one push per loop iteration. | 670 // TODO(rmcilroy): Consider doing more than one push per loop iteration. |
668 __ push(eax); | 671 __ push(eax); |
669 // Continue loop if not done. | 672 // Continue loop if not done. |
| 673 __ bind(&loop_check); |
670 __ sub(ebx, Immediate(kPointerSize)); | 674 __ sub(ebx, Immediate(kPointerSize)); |
671 __ j(not_equal, &loop_header, Label::kNear); | 675 __ j(greater_equal, &loop_header); |
672 } | 676 } |
673 | 677 |
674 // TODO(rmcilroy): List of things not currently dealt with here but done in | 678 // TODO(rmcilroy): List of things not currently dealt with here but done in |
675 // fullcodegen's prologue: | 679 // fullcodegen's prologue: |
676 // - Support profiler (specifically profiling_counter). | 680 // - Support profiler (specifically profiling_counter). |
677 // - Call ProfileEntryHookStub when isolate has a function_entry_hook. | 681 // - Call ProfileEntryHookStub when isolate has a function_entry_hook. |
678 // - Allow simulator stop operations if FLAG_stop_at is set. | 682 // - Allow simulator stop operations if FLAG_stop_at is set. |
679 // - Deal with sloppy mode functions which need to replace the | 683 // - Deal with sloppy mode functions which need to replace the |
680 // receiver with the global proxy when called as functions (without an | 684 // receiver with the global proxy when called as functions (without an |
681 // explicit receiver object). | 685 // explicit receiver object). |
682 // - Code aging of the BytecodeArray object. | 686 // - Code aging of the BytecodeArray object. |
683 // - Supporting FLAG_trace. | 687 // - Supporting FLAG_trace. |
684 // | 688 // |
685 // The following items are also not done here, and will probably be done using | 689 // The following items are also not done here, and will probably be done using |
686 // explicit bytecodes instead: | 690 // explicit bytecodes instead: |
687 // - Allocating a new local context if applicable. | 691 // - Allocating a new local context if applicable. |
688 // - Setting up a local binding to the this function, which is used in | 692 // - Setting up a local binding to the this function, which is used in |
689 // derived constructors with super calls. | 693 // derived constructors with super calls. |
690 // - Setting new.target if required. | 694 // - Setting new.target if required. |
691 // - Dealing with REST parameters (only if | 695 // - Dealing with REST parameters (only if |
692 // https://codereview.chromium.org/1235153006 doesn't land by then). | 696 // https://codereview.chromium.org/1235153006 doesn't land by then). |
693 // - Dealing with argument objects. | 697 // - Dealing with argument objects. |
694 | 698 |
695 // Perform stack guard check. | 699 // Perform stack guard check. |
696 { | 700 { |
697 Label ok; | 701 Label ok; |
698 ExternalReference stack_limit = | 702 ExternalReference stack_limit = |
699 ExternalReference::address_of_stack_limit(masm->isolate()); | 703 ExternalReference::address_of_stack_limit(masm->isolate()); |
700 __ cmp(esp, Operand::StaticVariable(stack_limit)); | 704 __ cmp(esp, Operand::StaticVariable(stack_limit)); |
701 __ j(above_equal, &ok, Label::kNear); | 705 __ j(above_equal, &ok); |
702 __ CallRuntime(Runtime::kStackGuard, 0); | 706 __ CallRuntime(Runtime::kStackGuard, 0); |
703 __ bind(&ok); | 707 __ bind(&ok); |
704 } | 708 } |
705 | 709 |
706 // Load bytecode offset and dispatch table into registers. | 710 // Load accumulator, register file, bytecode offset, dispatch table into |
707 __ mov(ecx, Immediate(BytecodeArray::kHeaderSize - kHeapObjectTag)); | 711 // registers. |
| 712 __ LoadRoot(kInterpreterAccumulatorRegister, Heap::kUndefinedValueRootIndex); |
| 713 __ mov(kInterpreterRegisterFileRegister, ebp); |
| 714 __ sub( |
| 715 kInterpreterRegisterFileRegister, |
| 716 Immediate(kPointerSize + StandardFrameConstants::kFixedFrameSizeFromFp)); |
| 717 __ mov(kInterpreterBytecodeOffsetRegister, |
| 718 Immediate(BytecodeArray::kHeaderSize - kHeapObjectTag)); |
708 // Since the dispatch table root might be set after builtins are generated, | 719 // Since the dispatch table root might be set after builtins are generated, |
709 // load directly from the roots table. | 720 // load directly from the roots table. |
710 __ LoadRoot(ebx, Heap::kInterpreterTableRootIndex); | 721 __ LoadRoot(kInterpreterDispatchTableRegister, |
711 __ add(ebx, Immediate(FixedArray::kHeaderSize - kHeapObjectTag)); | 722 Heap::kInterpreterTableRootIndex); |
| 723 __ add(kInterpreterDispatchTableRegister, |
| 724 Immediate(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 725 |
| 726 // TODO(rmcilroy) Push our context as a stack located parameter of the |
| 727 // bytecode handler. |
712 | 728 |
713 // Dispatch to the first bytecode handler for the function. | 729 // Dispatch to the first bytecode handler for the function. |
714 __ movzx_b(eax, Operand(edi, ecx, times_1, 0)); | 730 __ movzx_b(esi, Operand(kInterpreterBytecodeArrayRegister, |
715 __ mov(eax, Operand(ebx, eax, times_pointer_size, 0)); | 731 kInterpreterBytecodeOffsetRegister, times_1, 0)); |
| 732 __ mov(esi, Operand(kInterpreterDispatchTableRegister, esi, |
| 733 times_pointer_size, 0)); |
716 // TODO(rmcilroy): Make dispatch table point to code entrys to avoid untagging | 734 // TODO(rmcilroy): Make dispatch table point to code entrys to avoid untagging |
717 // and header removal. | 735 // and header removal. |
718 __ add(eax, Immediate(Code::kHeaderSize - kHeapObjectTag)); | 736 __ add(esi, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
719 __ jmp(eax); | 737 __ call(esi); |
720 } | 738 } |
721 | 739 |
722 | 740 |
723 void Builtins::Generate_InterpreterExitTrampoline(MacroAssembler* masm) { | 741 void Builtins::Generate_InterpreterExitTrampoline(MacroAssembler* masm) { |
724 // TODO(rmcilroy): List of things not currently dealt with here but done in | 742 // TODO(rmcilroy): List of things not currently dealt with here but done in |
725 // fullcodegen's EmitReturnSequence. | 743 // fullcodegen's EmitReturnSequence. |
726 // - Supporting FLAG_trace for Runtime::TraceExit. | 744 // - Supporting FLAG_trace for Runtime::TraceExit. |
727 // - Support profiler (specifically decrementing profiling_counter | 745 // - Support profiler (specifically decrementing profiling_counter |
728 // appropriately and calling out to HandleInterrupts if necessary). | 746 // appropriately and calling out to HandleInterrupts if necessary). |
729 | 747 |
730 // Load return value into r0. | 748 // The return value is in accumulator, which is already in rax. |
731 __ mov(eax, Operand(ebp, -kPointerSize - | 749 |
732 StandardFrameConstants::kFixedFrameSizeFromFp)); | |
733 // Leave the frame (also dropping the register file). | 750 // Leave the frame (also dropping the register file). |
734 __ leave(); | 751 __ leave(); |
735 // Return droping receiver + arguments. | 752 // Return droping receiver + arguments. |
736 // TODO(rmcilroy): Get number of arguments from BytecodeArray. | 753 // TODO(rmcilroy): Get number of arguments from BytecodeArray. |
737 __ Ret(1 * kPointerSize, ecx); | 754 __ Ret(1 * kPointerSize, ecx); |
738 } | 755 } |
739 | 756 |
740 | 757 |
741 void Builtins::Generate_CompileLazy(MacroAssembler* masm) { | 758 void Builtins::Generate_CompileLazy(MacroAssembler* masm) { |
742 CallRuntimePassFunction(masm, Runtime::kCompileLazy); | 759 CallRuntimePassFunction(masm, Runtime::kCompileLazy); |
(...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1762 | 1779 |
1763 __ bind(&ok); | 1780 __ bind(&ok); |
1764 __ ret(0); | 1781 __ ret(0); |
1765 } | 1782 } |
1766 | 1783 |
1767 #undef __ | 1784 #undef __ |
1768 } // namespace internal | 1785 } // namespace internal |
1769 } // namespace v8 | 1786 } // namespace v8 |
1770 | 1787 |
1771 #endif // V8_TARGET_ARCH_IA32 | 1788 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |