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..118a96357d2243d1a31a149843251532cbad10ec |
--- /dev/null |
+++ b/src/trusted/service_runtime/arch/mips/nacl_switch.S |
@@ -0,0 +1,72 @@ |
+/* |
+ * 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/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, 0($a0) |
+ lw $t7, 4($a0) |
+ lw $s0, 8($a0) |
+ lw $s1, 12($a0) |
+ lw $s2, 16($a0) |
+ lw $s3, 20($a0) |
+ lw $s4, 24($a0) |
+ lw $s5, 28($a0) |
+ lw $s6, 32($a0) |
+ lw $s7, 36($a0) |
+ lw $t8, 40($a0) |
+ lw $gp, 44($a0) |
+ lw $sp, 48($a0) |
+ lw $fp, 52($a0) |
+ /* NACL_CALLEE_SAVE_LIST END*/ |
+ |
+ lw $v0, 60($a0) /* context->sysret */ |
+ lw $v1, 64($a0) /* context->new_prog_ctr */ |
+ |
+ /* 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 |
+ |