Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Unified Diff: runtime/vm/stub_code_mips.cc

Issue 13473010: Adds native/leaf runtime call stub and redirection on MIPS. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/vm/stub_code_mips.cc
===================================================================
--- runtime/vm/stub_code_mips.cc (revision 20794)
+++ runtime/vm/stub_code_mips.cc (working copy)
@@ -100,8 +100,91 @@
}
+// 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::GenerateCallNativeCFunctionStub(Assembler* assembler) {
- __ Unimplemented("CallNativeCFunction stub");
+ 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();
+
+ __ 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);
+
+ // Reserve space for the native arguments structure passed on the stack (the
+ // outgoing pointer parameter to the native arguments structure is passed in
+ // R0) and align frame before entering the C++ world.
+ __ ReserveAlignedFrameSpace(sizeof(NativeArguments));
+
+ // 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: T1 already contains argc.
+
+ ASSERT(argv_offset == 2 * kWordSize);
+ // Set argv in NativeArguments: T2 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.
+
+ // Call native function or redirection via simulator.
+ __ jalr(T5);
+
+ // Reset exit frame information in Isolate structure.
+ __ LoadImmediate(A2, 0);
+ __ sw(A2, Address(CTX, Isolate::top_exit_frame_info_offset()));
+
+ // Load Context pointer from Isolate structure into R2.
+ __ lw(A2, Address(CTX, Isolate::top_context_offset()));
+
+ // Reset Context pointer in Isolate structure.
+ __ LoadImmediate(A3, reinterpret_cast<intptr_t>(Object::null()));
+ __ sw(A3, 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));
+ __ addiu(SP, SP, Immediate(2 * kWordSize));
+ __ Ret();
}

Powered by Google App Engine
This is Rietveld 408576698