Index: runtime/vm/stub_code_mips.cc |
=================================================================== |
--- runtime/vm/stub_code_mips.cc (revision 25822) |
+++ runtime/vm/stub_code_mips.cc (working copy) |
@@ -189,7 +189,104 @@ |
__ sw(A1, Address(SP, 1 * kWordSize)); |
__ sw(A0, Address(SP, 0 * kWordSize)); |
__ mov(A0, SP); // Pass the pointer to the NativeArguments. |
+ __ mov(A1, T5); // Pass the function entrypoint. |
+ __ ReserveAlignedFrameSpace(2 * kWordSize); // Just passing A0, A1. |
+ |
+ // Call native wrapper function or redirection via simulator. |
+#if defined(USING_SIMULATOR) |
+ uword entry = reinterpret_cast<uword>(NativeEntry::NativeCallWrapper); |
+ entry = Simulator::RedirectExternalReference( |
+ entry, Simulator::kNativeCall, NativeEntry::kNumCallWrapperArguments); |
+ __ LoadImmediate(T5, entry); |
+ __ jalr(T5); |
+#else |
+ __ BranchLink(&NativeEntry::NativeCallWrapperLabel()); |
+#endif |
+ __ TraceSimMsg("CallNativeCFunctionStub return"); |
+ |
+ // Reset exit frame information in Isolate structure. |
+ __ sw(ZR, Address(CTX, Isolate::top_exit_frame_info_offset())); |
+ |
+ // Load Context pointer from Isolate structure into A2. |
+ __ lw(A2, Address(CTX, Isolate::top_context_offset())); |
+ |
+ // Load null. |
+ __ LoadImmediate(TMP, reinterpret_cast<intptr_t>(Object::null())); |
+ |
+ // Reset Context pointer in Isolate structure. |
+ __ sw(TMP, Address(CTX, Isolate::top_context_offset())); |
+ |
+ // Cache Context pointer into CTX while executing Dart code. |
+ __ mov(CTX, A2); |
+ |
+ __ mov(SP, FP); |
+ __ lw(RA, Address(SP, 1 * kWordSize)); |
+ __ lw(FP, Address(SP, 0 * kWordSize)); |
+ __ Ret(); |
+ __ delay_slot()->addiu(SP, SP, Immediate(2 * kWordSize)); |
+} |
+ |
+ |
+// Input parameters: |
+// RA : return address. |
+// SP : address of return value. |
+// T5 : address of the native function to call. |
+// A2 : address of first argument in argument array. |
+// A1 : argc_tag including number of arguments and function kind. |
+void StubCode::GenerateCallBootstrapCFunctionStub(Assembler* assembler) { |
+ const intptr_t isolate_offset = NativeArguments::isolate_offset(); |
+ const intptr_t argc_tag_offset = NativeArguments::argc_tag_offset(); |
+ const intptr_t argv_offset = NativeArguments::argv_offset(); |
+ const intptr_t retval_offset = NativeArguments::retval_offset(); |
+ |
+ __ SetPrologueOffset(); |
+ __ TraceSimMsg("CallNativeCFunctionStub"); |
+ __ addiu(SP, SP, Immediate(-2 * kWordSize)); |
+ __ sw(RA, Address(SP, 1 * kWordSize)); |
+ __ sw(FP, Address(SP, 0 * kWordSize)); |
+ __ mov(FP, SP); |
+ |
+ // Load current Isolate pointer from Context structure into A0. |
+ __ lw(A0, FieldAddress(CTX, Context::isolate_offset())); |
+ |
+ // Save exit frame information to enable stack walking as we are about |
+ // to transition to native code. |
+ __ sw(SP, Address(A0, Isolate::top_exit_frame_info_offset())); |
+ |
+ // Save current Context pointer into Isolate structure. |
+ __ sw(CTX, Address(A0, Isolate::top_context_offset())); |
+ |
+ // Cache Isolate pointer into CTX while executing native code. |
+ __ mov(CTX, A0); |
+ |
+ // Initialize NativeArguments structure and call native function. |
+ // Registers A0, A1, A2, and A3 are used. |
+ |
+ ASSERT(isolate_offset == 0 * kWordSize); |
+ // Set isolate in NativeArgs: A0 already contains CTX. |
+ |
+ // There are no native calls to closures, so we do not need to set the tag |
+ // bits kClosureFunctionBit and kInstanceFunctionBit in argc_tag_. |
+ ASSERT(argc_tag_offset == 1 * kWordSize); |
+ // Set argc in NativeArguments: A1 already contains argc. |
+ |
+ ASSERT(argv_offset == 2 * kWordSize); |
+ // Set argv in NativeArguments: A2 already contains argv. |
+ |
+ ASSERT(retval_offset == 3 * kWordSize); |
+ __ addiu(A3, FP, Immediate(2 * kWordSize)); // Set retval in NativeArgs. |
+ |
+ // TODO(regis): Should we pass the structure by value as in runtime calls? |
+ // It would require changing Dart API for native functions. |
+ // For now, space is reserved on the stack and we pass a pointer to it. |
+ __ addiu(SP, SP, Immediate(-4 * kWordSize)); |
+ __ sw(A3, Address(SP, 3 * kWordSize)); |
+ __ sw(A2, Address(SP, 2 * kWordSize)); |
+ __ sw(A1, Address(SP, 1 * kWordSize)); |
+ __ sw(A0, Address(SP, 0 * kWordSize)); |
+ __ mov(A0, SP); // Pass the pointer to the NativeArguments. |
+ |
__ ReserveAlignedFrameSpace(kWordSize); // Just passing A0. |
// Call native function or redirection via simulator. |