OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 5674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5685 | 5685 |
5686 Label fast_elements_case; | 5686 Label fast_elements_case; |
5687 __ Branch(&fast_elements_case, eq, a3, Operand(FAST_ELEMENTS)); | 5687 __ Branch(&fast_elements_case, eq, a3, Operand(FAST_ELEMENTS)); |
5688 GenerateCase(masm, FAST_HOLEY_ELEMENTS); | 5688 GenerateCase(masm, FAST_HOLEY_ELEMENTS); |
5689 | 5689 |
5690 __ bind(&fast_elements_case); | 5690 __ bind(&fast_elements_case); |
5691 GenerateCase(masm, FAST_ELEMENTS); | 5691 GenerateCase(masm, FAST_ELEMENTS); |
5692 } | 5692 } |
5693 | 5693 |
5694 | 5694 |
| 5695 void CallApiFunctionStub::Generate(MacroAssembler* masm) { |
| 5696 // ----------- S t a t e ------------- |
| 5697 // -- a0 : callee |
| 5698 // -- t0 : call_data |
| 5699 // -- a2 : holder |
| 5700 // -- a3 : api_function_address |
| 5701 // -- a1 : thunk_arg |
| 5702 // -- cp : context |
| 5703 // -- |
| 5704 // -- sp[0] : last argument |
| 5705 // -- ... |
| 5706 // -- sp[(argc - 1)* 4] : first argument |
| 5707 // -- sp[argc * 4] : receiver |
| 5708 // ----------------------------------- |
| 5709 |
| 5710 Register callee = a0; |
| 5711 Register call_data = t0; |
| 5712 Register holder = a2; |
| 5713 Register api_function_address = a3; |
| 5714 Register thunk_arg = a1; |
| 5715 Register context = cp; |
| 5716 |
| 5717 int argc = ArgumentBits::decode(bit_field_); |
| 5718 bool restore_context = RestoreContextBits::decode(bit_field_); |
| 5719 bool call_data_undefined = CallDataUndefinedBits::decode(bit_field_); |
| 5720 |
| 5721 typedef FunctionCallbackArguments FCA; |
| 5722 |
| 5723 STATIC_ASSERT(FCA::kContextSaveIndex == 6); |
| 5724 STATIC_ASSERT(FCA::kCalleeIndex == 5); |
| 5725 STATIC_ASSERT(FCA::kDataIndex == 4); |
| 5726 STATIC_ASSERT(FCA::kReturnValueOffset == 3); |
| 5727 STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2); |
| 5728 STATIC_ASSERT(FCA::kIsolateIndex == 1); |
| 5729 STATIC_ASSERT(FCA::kHolderIndex == 0); |
| 5730 STATIC_ASSERT(FCA::kArgsLength == 7); |
| 5731 |
| 5732 Isolate* isolate = masm->isolate(); |
| 5733 |
| 5734 // Save context, callee and call data. |
| 5735 __ Push(context, callee, call_data); |
| 5736 // Load context from callee. |
| 5737 __ lw(context, FieldMemOperand(callee, JSFunction::kContextOffset)); |
| 5738 |
| 5739 Register scratch = call_data; |
| 5740 if (!call_data_undefined) { |
| 5741 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); |
| 5742 } |
| 5743 // Push return value and default return value. |
| 5744 __ Push(scratch, scratch); |
| 5745 __ li(scratch, |
| 5746 Operand(ExternalReference::isolate_address(isolate))); |
| 5747 // Push isolate and holder. |
| 5748 __ Push(scratch, holder); |
| 5749 |
| 5750 // Prepare arguments. |
| 5751 __ mov(scratch, sp); |
| 5752 |
| 5753 // Allocate the v8::Arguments structure in the arguments' space since |
| 5754 // it's not controlled by GC. |
| 5755 const int kApiStackSpace = 4; |
| 5756 |
| 5757 FrameScope frame_scope(masm, StackFrame::MANUAL); |
| 5758 __ EnterExitFrame(false, kApiStackSpace); |
| 5759 |
| 5760 ASSERT(!thunk_arg.is(a0) && !api_function_address.is(a0) && !scratch.is(a0)); |
| 5761 // a0 = FunctionCallbackInfo& |
| 5762 // Arguments is after the return address. |
| 5763 __ Addu(a0, sp, Operand(1 * kPointerSize)); |
| 5764 // FunctionCallbackInfo::implicit_args_ |
| 5765 __ sw(scratch, MemOperand(a0, 0 * kPointerSize)); |
| 5766 // FunctionCallbackInfo::values_ |
| 5767 __ Addu(at, scratch, Operand((FCA::kArgsLength - 1 + argc) * kPointerSize)); |
| 5768 __ sw(at, MemOperand(a0, 1 * kPointerSize)); |
| 5769 // FunctionCallbackInfo::length_ = argc |
| 5770 __ li(at, Operand(argc)); |
| 5771 __ sw(at, MemOperand(a0, 2 * kPointerSize)); |
| 5772 // FunctionCallbackInfo::is_construct_call = 0 |
| 5773 __ sw(zero_reg, MemOperand(a0, 3 * kPointerSize)); |
| 5774 |
| 5775 const int kStackUnwindSpace = argc + FCA::kArgsLength + 1; |
| 5776 Address thunk_address = FUNCTION_ADDR(&InvokeFunctionCallback); |
| 5777 ExternalReference::Type thunk_type = ExternalReference::PROFILING_API_CALL; |
| 5778 ApiFunction thunk_fun(thunk_address); |
| 5779 ExternalReference thunk_ref = ExternalReference(&thunk_fun, thunk_type, |
| 5780 masm->isolate()); |
| 5781 |
| 5782 AllowExternalCallThatCantCauseGC scope(masm); |
| 5783 MemOperand context_restore_operand( |
| 5784 fp, (2 + FCA::kContextSaveIndex) * kPointerSize); |
| 5785 MemOperand return_value_operand(fp, |
| 5786 (2 + FCA::kReturnValueOffset) * kPointerSize); |
| 5787 |
| 5788 __ CallApiFunctionAndReturn(api_function_address, |
| 5789 thunk_ref, |
| 5790 thunk_arg, |
| 5791 kStackUnwindSpace, |
| 5792 return_value_operand, |
| 5793 restore_context ? |
| 5794 &context_restore_operand : NULL); |
| 5795 } |
| 5796 |
| 5797 |
5695 #undef __ | 5798 #undef __ |
5696 | 5799 |
5697 } } // namespace v8::internal | 5800 } } // namespace v8::internal |
5698 | 5801 |
5699 #endif // V8_TARGET_ARCH_MIPS | 5802 #endif // V8_TARGET_ARCH_MIPS |
OLD | NEW |