OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * be found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #include "native_client/src/trusted/service_runtime/arch/mips/sel_rt.h" | 7 #include "native_client/src/trusted/service_runtime/arch/mips/sel_rt.h" |
8 #include "native_client/src/trusted/service_runtime/nacl_config.h" | 8 #include "native_client/src/trusted/service_runtime/nacl_config.h" |
9 | 9 |
10 .text | 10 .text |
11 | 11 |
12 | 12 |
13 /* | 13 /* |
14 * This trusted code is linked into the service runtime. It is executed when a | 14 * This trusted code is linked into the service runtime. It is executed when a |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 * .......... | 60 * .......... |
61 * sp+X: argN | 61 * sp+X: argN |
62 * | 62 * |
63 * When service runtime serves a system call, it first creates a structure which | 63 * When service runtime serves a system call, it first creates a structure which |
64 * utilizes these arguments. The structure is created by Decoder functions in | 64 * utilizes these arguments. The structure is created by Decoder functions in |
65 * nacl_syscall_handlers.c. (nacl_syscall_handlers.c is an automatically | 65 * nacl_syscall_handlers.c. (nacl_syscall_handlers.c is an automatically |
66 * generated file and placed in | 66 * generated file and placed in |
67 * scons-out//gen/native_client/src/trusted/service_runtime). | 67 * scons-out//gen/native_client/src/trusted/service_runtime). |
68 */ | 68 */ |
69 | 69 |
70 /* Place a0-a3 argument registers in the reserved 16-byte region in caller's | 70 /* |
71 stack frame (o32 ABI), and place return address on top of that. */ | 71 * .cpload will expand into the three instructions function prologue that sets |
72 | 72 * up the $gp register to the trusted value. |
| 73 */ |
73 .cpload $t9 | 74 .cpload $t9 |
74 | 75 |
| 76 /* |
| 77 * Place a0-a3 argument registers in the reserved 16-byte region in caller's |
| 78 * stack frame (o32 ABI), and place return address on top of that. |
| 79 */ |
75 sw $a3, 12($sp) | 80 sw $a3, 12($sp) |
76 sw $a2, 8($sp) | 81 sw $a2, 8($sp) |
77 sw $a1, 4($sp) | 82 sw $a1, 4($sp) |
78 sw $a0, 0($sp) | 83 sw $a0, 0($sp) |
79 /* Save return address for returning to untrusted code. */ | 84 /* Save return address for returning to untrusted code. */ |
80 sw $ra, -4($sp) | 85 sw $ra, -4($sp) |
81 /* Save return address that indicates which trampoline was called. */ | 86 /* Save return address that indicates which trampoline was called. */ |
82 sw $t5, -8($sp) | 87 sw $t5, -8($sp) |
83 | 88 |
84 /* Load the __thread variable's offset into a3. */ | 89 /* Load the __thread variable's offset into a3. */ |
85 lui $a3, %tprel_hi(gNaClThreadIdx) | 90 lui $a3, %tprel_hi(gNaClThreadIdx) |
86 addiu $a3, $a3, %tprel_lo(gNaClThreadIdx) | 91 addiu $a3, $a3, %tprel_lo(gNaClThreadIdx) |
87 | 92 |
88 /* Fetch the thread-local variable holding the thread index. */ | 93 /* Fetch the thread-local variable holding the thread index. */ |
89 rdhwr $v1, $29 | 94 rdhwr $v1, $29 |
90 addu $a3, $v1, $a3 | 95 addu $a3, $v1, $a3 |
91 lw $a0, 0($a3) | 96 lw $a0, 0($a3) |
92 | 97 |
93 /* Load the nacl_user entry of this thread. | 98 /* |
94 * a1 = nacl_user[a0*4] */ | 99 * Load the nacl_user entry of this thread. |
| 100 * a1 = nacl_user[a0*4] |
| 101 */ |
95 lw $a1,%got(nacl_user)($28) | 102 lw $a1,%got(nacl_user)($28) |
96 sll $a0, $a0, 2 | 103 sll $a0, $a0, 2 |
97 addu $a1, $a1, $a0 | 104 addu $a1, $a1, $a0 |
98 lw $a1, 0($a1) | 105 lw $a1, 0($a1) |
99 | 106 |
100 sw $s0, NACL_THREAD_CONTEXT_OFFSET_S0($a1) | 107 sw $s0, NACL_THREAD_CONTEXT_OFFSET_S0($a1) |
101 sw $s1, NACL_THREAD_CONTEXT_OFFSET_S1($a1) | 108 sw $s1, NACL_THREAD_CONTEXT_OFFSET_S1($a1) |
102 sw $s2, NACL_THREAD_CONTEXT_OFFSET_S2($a1) | 109 sw $s2, NACL_THREAD_CONTEXT_OFFSET_S2($a1) |
103 sw $s3, NACL_THREAD_CONTEXT_OFFSET_S3($a1) | 110 sw $s3, NACL_THREAD_CONTEXT_OFFSET_S3($a1) |
104 sw $s4, NACL_THREAD_CONTEXT_OFFSET_S4($a1) | 111 sw $s4, NACL_THREAD_CONTEXT_OFFSET_S4($a1) |
105 sw $s5, NACL_THREAD_CONTEXT_OFFSET_S5($a1) | 112 sw $s5, NACL_THREAD_CONTEXT_OFFSET_S5($a1) |
106 sw $s6, NACL_THREAD_CONTEXT_OFFSET_S6($a1) | 113 sw $s6, NACL_THREAD_CONTEXT_OFFSET_S6($a1) |
107 sw $s7, NACL_THREAD_CONTEXT_OFFSET_S7($a1) | 114 sw $s7, NACL_THREAD_CONTEXT_OFFSET_S7($a1) |
108 sw $t8, NACL_THREAD_CONTEXT_OFFSET_T8($a1) | 115 sw $t8, NACL_THREAD_CONTEXT_OFFSET_T8($a1) |
109 sw $gp, NACL_THREAD_CONTEXT_OFFSET_GLOBAL_PTR($a1) | |
110 sw $sp, NACL_THREAD_CONTEXT_OFFSET_STACK_PTR($a1) | 116 sw $sp, NACL_THREAD_CONTEXT_OFFSET_STACK_PTR($a1) |
111 sw $fp, NACL_THREAD_CONTEXT_OFFSET_FRAME_PTR($a1) | 117 sw $fp, NACL_THREAD_CONTEXT_OFFSET_FRAME_PTR($a1) |
112 | 118 |
113 /* Restore the thread index. */ | 119 /* Restore the thread index. */ |
114 srl $a0, $a0, 2 | 120 srl $a0, $a0, 2 |
115 | 121 |
116 /* Reserve 16-byte for arguments (o32 ABI) */ | 122 /* Restore the trusted stack */ |
117 addiu $sp, $sp, -16 | 123 lw $sp, NACL_THREAD_CONTEXT_OFFSET_TRUSTED_STACK_PTR($a1) |
| 124 |
118 lw $t9,%call16(NaClSyscallCSegHook)($gp) | 125 lw $t9,%call16(NaClSyscallCSegHook)($gp) |
119 jr $t9 | 126 jr $t9 |
120 nop | 127 nop |
121 | 128 |
122 /* NOTREACHED */ | 129 /* NOTREACHED */ |
123 | 130 |
124 /* | 131 /* |
125 * If the thread returns, which must not happen, it will be halted | 132 * If the thread returns, which must not happen, it will be halted |
126 * by the following instruction | 133 * by the following instruction. |
127 */ | 134 */ |
128 | 135 |
129 NACL_HALT | 136 NACL_HALT |
130 | 137 |
OLD | NEW |