| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 2779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2790 movq(dst, FieldOperand(dst, JSFunction::kContextOffset)); | 2790 movq(dst, FieldOperand(dst, JSFunction::kContextOffset)); |
| 2791 } | 2791 } |
| 2792 // The context may be an intermediate context, not a function context. | 2792 // The context may be an intermediate context, not a function context. |
| 2793 movq(dst, Operand(dst, Context::SlotOffset(Context::FCONTEXT_INDEX))); | 2793 movq(dst, Operand(dst, Context::SlotOffset(Context::FCONTEXT_INDEX))); |
| 2794 } else { // context is the current function context. | 2794 } else { // context is the current function context. |
| 2795 // The context may be an intermediate context, not a function context. | 2795 // The context may be an intermediate context, not a function context. |
| 2796 movq(dst, Operand(rsi, Context::SlotOffset(Context::FCONTEXT_INDEX))); | 2796 movq(dst, Operand(rsi, Context::SlotOffset(Context::FCONTEXT_INDEX))); |
| 2797 } | 2797 } |
| 2798 } | 2798 } |
| 2799 | 2799 |
| 2800 #ifdef _WIN64 |
| 2801 static const int kRegisterPassedArguments = 4; |
| 2802 #else |
| 2803 static const int kRegisterPassedArguments = 6; |
| 2804 #endif |
| 2800 | 2805 |
| 2801 int MacroAssembler::ArgumentStackSlotsForCFunctionCall(int num_arguments) { | 2806 int MacroAssembler::ArgumentStackSlotsForCFunctionCall(int num_arguments) { |
| 2802 // On Windows 64 stack slots are reserved by the caller for all arguments | 2807 // On Windows 64 stack slots are reserved by the caller for all arguments |
| 2803 // including the ones passed in registers, and space is always allocated for | 2808 // including the ones passed in registers, and space is always allocated for |
| 2804 // the four register arguments even if the function takes fewer than four | 2809 // the four register arguments even if the function takes fewer than four |
| 2805 // arguments. | 2810 // arguments. |
| 2806 // On AMD64 ABI (Linux/Mac) the first six arguments are passed in registers | 2811 // On AMD64 ABI (Linux/Mac) the first six arguments are passed in registers |
| 2807 // and the caller does not reserve stack slots for them. | 2812 // and the caller does not reserve stack slots for them. |
| 2808 ASSERT(num_arguments >= 0); | 2813 ASSERT(num_arguments >= 0); |
| 2809 #ifdef _WIN64 | 2814 #ifdef _WIN64 |
| 2810 static const int kMinimumStackSlots = 4; | 2815 const int kMinimumStackSlots = kRegisterPassedArguments; |
| 2811 if (num_arguments < kMinimumStackSlots) return kMinimumStackSlots; | 2816 if (num_arguments < kMinimumStackSlots) return kMinimumStackSlots; |
| 2812 return num_arguments; | 2817 return num_arguments; |
| 2813 #else | 2818 #else |
| 2814 static const int kRegisterPassedArguments = 6; | |
| 2815 if (num_arguments < kRegisterPassedArguments) return 0; | 2819 if (num_arguments < kRegisterPassedArguments) return 0; |
| 2816 return num_arguments - kRegisterPassedArguments; | 2820 return num_arguments - kRegisterPassedArguments; |
| 2817 #endif | 2821 #endif |
| 2818 } | 2822 } |
| 2819 | 2823 |
| 2820 | 2824 |
| 2821 void MacroAssembler::PrepareCallCFunction(int num_arguments) { | 2825 void MacroAssembler::PrepareCallCFunction(int num_arguments) { |
| 2822 int frame_alignment = OS::ActivationFrameAlignment(); | 2826 int frame_alignment = OS::ActivationFrameAlignment(); |
| 2823 ASSERT(frame_alignment != 0); | 2827 ASSERT(frame_alignment != 0); |
| 2824 ASSERT(num_arguments >= 0); | 2828 ASSERT(num_arguments >= 0); |
| 2829 |
| 2830 // Reserve space for Isolate address which is always passed as last parameter |
| 2831 num_arguments += 1; |
| 2832 |
| 2825 // Make stack end at alignment and allocate space for arguments and old rsp. | 2833 // Make stack end at alignment and allocate space for arguments and old rsp. |
| 2826 movq(kScratchRegister, rsp); | 2834 movq(kScratchRegister, rsp); |
| 2827 ASSERT(IsPowerOf2(frame_alignment)); | 2835 ASSERT(IsPowerOf2(frame_alignment)); |
| 2828 int argument_slots_on_stack = | 2836 int argument_slots_on_stack = |
| 2829 ArgumentStackSlotsForCFunctionCall(num_arguments); | 2837 ArgumentStackSlotsForCFunctionCall(num_arguments); |
| 2830 subq(rsp, Immediate((argument_slots_on_stack + 1) * kPointerSize)); | 2838 subq(rsp, Immediate((argument_slots_on_stack + 1) * kPointerSize)); |
| 2831 and_(rsp, Immediate(-frame_alignment)); | 2839 and_(rsp, Immediate(-frame_alignment)); |
| 2832 movq(Operand(rsp, argument_slots_on_stack * kPointerSize), kScratchRegister); | 2840 movq(Operand(rsp, argument_slots_on_stack * kPointerSize), kScratchRegister); |
| 2833 } | 2841 } |
| 2834 | 2842 |
| 2835 | 2843 |
| 2836 void MacroAssembler::CallCFunction(ExternalReference function, | 2844 void MacroAssembler::CallCFunction(ExternalReference function, |
| 2837 int num_arguments) { | 2845 int num_arguments) { |
| 2838 movq(rax, function); | 2846 movq(rax, function); |
| 2839 CallCFunction(rax, num_arguments); | 2847 CallCFunction(rax, num_arguments); |
| 2840 } | 2848 } |
| 2841 | 2849 |
| 2842 | 2850 |
| 2843 void MacroAssembler::CallCFunction(Register function, int num_arguments) { | 2851 void MacroAssembler::CallCFunction(Register function, int num_arguments) { |
| 2852 // Pass current isolate address as additional parameter. |
| 2853 if (num_arguments < kRegisterPassedArguments) { |
| 2854 #ifdef _WIN64 |
| 2855 // First four arguments are passed in registers on Windows. |
| 2856 Register arg_to_reg[] = {rcx, rdx, r8, r9}; |
| 2857 #else |
| 2858 // First six arguments are passed in registers on other platforms. |
| 2859 Register arg_to_reg[] = {rdi, rsi, rdx, rcx, r8, r9}; |
| 2860 #endif |
| 2861 Register reg = arg_to_reg[num_arguments]; |
| 2862 movq(reg, ExternalReference::isolate_address()); |
| 2863 } else { |
| 2864 // Push Isolate pointer after all parameters. |
| 2865 int argument_slots_on_stack = |
| 2866 ArgumentStackSlotsForCFunctionCall(num_arguments); |
| 2867 movq(kScratchRegister, ExternalReference::isolate_address()); |
| 2868 movq(Operand(rsp, argument_slots_on_stack * kPointerSize), |
| 2869 kScratchRegister); |
| 2870 } |
| 2871 |
| 2844 // Check stack alignment. | 2872 // Check stack alignment. |
| 2845 if (FLAG_debug_code) { | 2873 if (FLAG_debug_code) { |
| 2846 CheckStackAlignment(); | 2874 CheckStackAlignment(); |
| 2847 } | 2875 } |
| 2848 | 2876 |
| 2849 call(function); | 2877 call(function); |
| 2850 ASSERT(OS::ActivationFrameAlignment() != 0); | 2878 ASSERT(OS::ActivationFrameAlignment() != 0); |
| 2851 ASSERT(num_arguments >= 0); | 2879 ASSERT(num_arguments >= 0); |
| 2880 num_arguments += 1; |
| 2852 int argument_slots_on_stack = | 2881 int argument_slots_on_stack = |
| 2853 ArgumentStackSlotsForCFunctionCall(num_arguments); | 2882 ArgumentStackSlotsForCFunctionCall(num_arguments); |
| 2854 movq(rsp, Operand(rsp, argument_slots_on_stack * kPointerSize)); | 2883 movq(rsp, Operand(rsp, argument_slots_on_stack * kPointerSize)); |
| 2855 } | 2884 } |
| 2856 | 2885 |
| 2857 | 2886 |
| 2858 CodePatcher::CodePatcher(byte* address, int size) | 2887 CodePatcher::CodePatcher(byte* address, int size) |
| 2859 : address_(address), size_(size), masm_(address, size + Assembler::kGap) { | 2888 : address_(address), size_(size), masm_(address, size + Assembler::kGap) { |
| 2860 // Create a new macro assembler pointing to the address of the code to patch. | 2889 // Create a new macro assembler pointing to the address of the code to patch. |
| 2861 // The size is adjusted with kGap on order for the assembler to generate size | 2890 // The size is adjusted with kGap on order for the assembler to generate size |
| 2862 // bytes of instructions without failing with buffer size constraints. | 2891 // bytes of instructions without failing with buffer size constraints. |
| 2863 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); | 2892 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 2864 } | 2893 } |
| 2865 | 2894 |
| 2866 | 2895 |
| 2867 CodePatcher::~CodePatcher() { | 2896 CodePatcher::~CodePatcher() { |
| 2868 // Indicate that code has changed. | 2897 // Indicate that code has changed. |
| 2869 CPU::FlushICache(address_, size_); | 2898 CPU::FlushICache(address_, size_); |
| 2870 | 2899 |
| 2871 // Check that the code was patched as expected. | 2900 // Check that the code was patched as expected. |
| 2872 ASSERT(masm_.pc_ == address_ + size_); | 2901 ASSERT(masm_.pc_ == address_ + size_); |
| 2873 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); | 2902 ASSERT(masm_.reloc_info_writer.pos() == address_ + size_ + Assembler::kGap); |
| 2874 } | 2903 } |
| 2875 | 2904 |
| 2876 } } // namespace v8::internal | 2905 } } // namespace v8::internal |
| 2877 | 2906 |
| 2878 #endif // V8_TARGET_ARCH_X64 | 2907 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |