Index: src/trusted/service_runtime/arch/mips/nacl_switch.S |
diff --git a/src/trusted/service_runtime/arch/mips/nacl_switch.S b/src/trusted/service_runtime/arch/mips/nacl_switch.S |
new file mode 100644 |
index 0000000000000000000000000000000000000000..324984cecc71faa4634bff8e1e8a35fefcb56ba4 |
--- /dev/null |
+++ b/src/trusted/service_runtime/arch/mips/nacl_switch.S |
@@ -0,0 +1,75 @@ |
+/* |
+ * Copyright 2012 The Native Client Authors. All rights reserved. |
+ * Use of this source code is governed by a BSD-style license that can |
+ * be found in the LICENSE file. |
+ */ |
+ |
+#include "native_client/src/trusted/service_runtime/arch/mips/sel_rt.h" |
+#include "native_client/src/trusted/service_runtime/nacl_config.h" |
+ |
+.text |
+ |
+/* |
+ * This trusted code is linked into the service_runtime and |
+ * executed when switching from the service runtime to a nacl |
+ * module. This happens when a main nacl thread is created and starting to |
+ * execute the nacl code, or when nacl module is returning from a system |
+ * call. This piece of code lives in a service runtime part of address space. |
+ * The one and only argument is in register a0 |
+ * |
+ * a0 -- address of thread context (struct NaClThreadContext) |
+ */ |
+ |
+DEFINE_GLOBAL_HIDDEN_IDENTIFIER(NaClSwitch): |
+ |
+ .set noreorder |
+ |
+/* |
+ * We clear registers a1, a2, a3, t0, t1, t2, t3, t4, t5 and ra to avoid |
+ * information leaks. The remaining registers are overwritten by the code that |
+ * follows after. |
+ */ |
+ |
+ addu $a1, $zero, $zero |
+ addu $a2, $zero, $zero |
+ addu $a3, $zero, $zero |
+ addu $t0, $zero, $zero |
+ addu $t1, $zero, $zero |
+ addu $t2, $zero, $zero |
+ addu $t3, $zero, $zero |
+ addu $t4, $zero, $zero |
+ addu $t5, $zero, $zero |
+ addu $ra, $zero, $zero |
+ |
+ /* NACL_CALLEE_SAVE_LIST BEGIN */ |
+ |
+ lw $t6, NACL_THREAD_CONTEXT_OFFSET_T6($a0) |
+ lw $t7, NACL_THREAD_CONTEXT_OFFSET_T7($a0) |
+ lw $s0, NACL_THREAD_CONTEXT_OFFSET_S0($a0) |
+ lw $s1, NACL_THREAD_CONTEXT_OFFSET_S1($a0) |
+ lw $s2, NACL_THREAD_CONTEXT_OFFSET_S2($a0) |
+ lw $s3, NACL_THREAD_CONTEXT_OFFSET_S3($a0) |
+ lw $s4, NACL_THREAD_CONTEXT_OFFSET_S4($a0) |
+ lw $s5, NACL_THREAD_CONTEXT_OFFSET_S5($a0) |
+ lw $s6, NACL_THREAD_CONTEXT_OFFSET_S6($a0) |
+ lw $s7, NACL_THREAD_CONTEXT_OFFSET_S7($a0) |
+ lw $t8, NACL_THREAD_CONTEXT_OFFSET_T8($a0) |
+ lw $gp, NACL_THREAD_CONTEXT_OFFSET_GLOBAL_PTR($a0) |
+ lw $sp, NACL_THREAD_CONTEXT_OFFSET_STACK_PTR($a0) |
+ lw $fp, NACL_THREAD_CONTEXT_OFFSET_FRAME_PTR($a0) |
+ |
+ /* NACL_CALLEE_SAVE_LIST END*/ |
+ |
+ lw $v0, 60($a0) /* context->sysret */ |
Mark Seaborn
2012/09/18 03:24:34
Can you use NACL_THREAD_CONTEXT_OFFSET_SYSRET here
petarj
2012/09/19 17:27:51
Done.
|
+ lw $v1, 64($a0) /* context->new_prog_ctr */ |
Mark Seaborn
2012/09/18 03:24:34
Same here: use a #defined constant.
petarj
2012/09/19 17:27:51
Done.
|
+ |
+ /* At startup, context->sysret contains not the the return value, but the |
+ first argument. Put it in a0. */ |
+ addu $a0, $v0, $zero |
+ |
+ /* Transfer control to untrusted code */ |
+ jr $v1 |
+ nop |
+ |
+ .set reorder |
+ |