1/* SPDX-License-Identifier: GPL-2.0 */ 2 /* SunOS's execv() call only specifies the argv argument, the 3 * environment settings are the same as the calling processes. 4 */ 5sys64_execve: 6 set sys_execve, %g1 7 jmpl %g1, %g0 8 flushw 9 10sys64_execveat: 11 set sys_execveat, %g1 12 jmpl %g1, %g0 13 flushw 14 15#ifdef CONFIG_COMPAT 16sunos_execv: 17 mov %g0, %o2 18sys32_execve: 19 set compat_sys_execve, %g1 20 jmpl %g1, %g0 21 flushw 22 23sys32_execveat: 24 set compat_sys_execveat, %g1 25 jmpl %g1, %g0 26 flushw 27#endif 28 29 .align 32 30sys_nis_syscall: 31 ba,pt %xcc, c_sys_nis_syscall 32 add %sp, PTREGS_OFF, %o0 33sys_memory_ordering: 34 ba,pt %xcc, sparc_memory_ordering 35 add %sp, PTREGS_OFF, %o1 36#ifdef CONFIG_COMPAT 37sys32_sigstack: 38 ba,pt %xcc, do_sys32_sigstack 39 mov %i6, %o2 40#endif 41 .align 32 42#ifdef CONFIG_COMPAT 43sys32_sigreturn: 44 add %sp, PTREGS_OFF, %o0 45 call do_sigreturn32 46 add %o7, 1f-.-4, %o7 47 nop 48#endif 49sys_rt_sigreturn: 50 add %sp, PTREGS_OFF, %o0 51 call do_rt_sigreturn 52 add %o7, 1f-.-4, %o7 53 nop 54#ifdef CONFIG_COMPAT 55sys32_rt_sigreturn: 56 add %sp, PTREGS_OFF, %o0 57 call do_rt_sigreturn32 58 add %o7, 1f-.-4, %o7 59 nop 60#endif 61 .align 32 621: ldx [%g6 + TI_FLAGS], %l5 63 andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0 64 be,pt %icc, rtrap 65 nop 66 call syscall_trace_leave 67 add %sp, PTREGS_OFF, %o0 68 ba,pt %xcc, rtrap 69 nop 70 71 /* This is how fork() was meant to be done, 8 instruction entry. 72 * 73 * I questioned the following code briefly, let me clear things 74 * up so you must not reason on it like I did. 75 * 76 * Know the fork_kpsr etc. we use in the sparc32 port? We don't 77 * need it here because the only piece of window state we copy to 78 * the child is the CWP register. Even if the parent sleeps, 79 * we are safe because we stuck it into pt_regs of the parent 80 * so it will not change. 81 * 82 * XXX This raises the question, whether we can do the same on 83 * XXX sparc32 to get rid of fork_kpsr _and_ fork_kwim. The 84 * XXX answer is yes. We stick fork_kpsr in UREG_G0 and 85 * XXX fork_kwim in UREG_G1 (global registers are considered 86 * XXX volatile across a system call in the sparc ABI I think 87 * XXX if it isn't we can use regs->y instead, anyone who depends 88 * XXX upon the Y register being preserved across a fork deserves 89 * XXX to lose). 90 * 91 * In fact we should take advantage of that fact for other things 92 * during system calls... 93 */ 94 .align 32 95sys_vfork: /* Under Linux, vfork and fork are just special cases of clone. */ 96 sethi %hi(0x4000 | 0x0100 | SIGCHLD), %o0 97 or %o0, %lo(0x4000 | 0x0100 | SIGCHLD), %o0 98 ba,pt %xcc, sys_clone 99sys_fork: 100 clr %o1 101 mov SIGCHLD, %o0 102sys_clone: 103 flushw 104 movrz %o1, %fp, %o1 105 mov 0, %o3 106 ba,pt %xcc, sparc_do_fork 107 add %sp, PTREGS_OFF, %o2 108 109 .globl ret_from_fork 110ret_from_fork: 111 /* Clear current_thread_info()->new_child. */ 112 stb %g0, [%g6 + TI_NEW_CHILD] 113 call schedule_tail 114 mov %g7, %o0 115 ldx [%sp + PTREGS_OFF + PT_V9_I0], %o0 116 brnz,pt %o0, ret_sys_call 117 ldx [%g6 + TI_FLAGS], %l0 118 ldx [%sp + PTREGS_OFF + PT_V9_G1], %l1 119 call %l1 120 ldx [%sp + PTREGS_OFF + PT_V9_G2], %o0 121 ba,pt %xcc, ret_sys_call 122 mov 0, %o0 123 124 .globl sparc_exit_group 125 .type sparc_exit_group,#function 126sparc_exit_group: 127 sethi %hi(sys_exit_group), %g7 128 ba,pt %xcc, 1f 129 or %g7, %lo(sys_exit_group), %g7 130 .size sparc_exit_group,.-sparc_exit_group 131 132 .globl sparc_exit 133 .type sparc_exit,#function 134sparc_exit: 135 sethi %hi(sys_exit), %g7 136 or %g7, %lo(sys_exit), %g7 1371: rdpr %pstate, %g2 138 wrpr %g2, PSTATE_IE, %pstate 139 rdpr %otherwin, %g1 140 rdpr %cansave, %g3 141 add %g3, %g1, %g3 142 wrpr %g3, 0x0, %cansave 143 wrpr %g0, 0x0, %otherwin 144 wrpr %g2, 0x0, %pstate 145 jmpl %g7, %g0 146 stb %g0, [%g6 + TI_WSAVED] 147 .size sparc_exit,.-sparc_exit 148 149linux_sparc_ni_syscall: 150 sethi %hi(sys_ni_syscall), %l7 151 ba,pt %xcc, 4f 152 or %l7, %lo(sys_ni_syscall), %l7 153 154linux_syscall_trace32: 155 call syscall_trace_enter 156 add %sp, PTREGS_OFF, %o0 157 brnz,pn %o0, 3f 158 mov -ENOSYS, %o0 159 160 /* Syscall tracing can modify the registers. */ 161 ldx [%sp + PTREGS_OFF + PT_V9_G1], %g1 162 sethi %hi(sys_call_table32), %l7 163 ldx [%sp + PTREGS_OFF + PT_V9_I0], %i0 164 or %l7, %lo(sys_call_table32), %l7 165 ldx [%sp + PTREGS_OFF + PT_V9_I1], %i1 166 ldx [%sp + PTREGS_OFF + PT_V9_I2], %i2 167 ldx [%sp + PTREGS_OFF + PT_V9_I3], %i3 168 ldx [%sp + PTREGS_OFF + PT_V9_I4], %i4 169 ldx [%sp + PTREGS_OFF + PT_V9_I5], %i5 170 171 cmp %g1, NR_syscalls 172 bgeu,pn %xcc, 3f 173 mov -ENOSYS, %o0 174 175 sll %g1, 2, %l4 176 srl %i0, 0, %o0 177 lduw [%l7 + %l4], %l7 178 srl %i4, 0, %o4 179 srl %i1, 0, %o1 180 srl %i2, 0, %o2 181 ba,pt %xcc, 5f 182 srl %i3, 0, %o3 183 184linux_syscall_trace: 185 call syscall_trace_enter 186 add %sp, PTREGS_OFF, %o0 187 brnz,pn %o0, 3f 188 mov -ENOSYS, %o0 189 190 /* Syscall tracing can modify the registers. */ 191 ldx [%sp + PTREGS_OFF + PT_V9_G1], %g1 192 sethi %hi(sys_call_table64), %l7 193 ldx [%sp + PTREGS_OFF + PT_V9_I0], %i0 194 or %l7, %lo(sys_call_table64), %l7 195 ldx [%sp + PTREGS_OFF + PT_V9_I1], %i1 196 ldx [%sp + PTREGS_OFF + PT_V9_I2], %i2 197 ldx [%sp + PTREGS_OFF + PT_V9_I3], %i3 198 ldx [%sp + PTREGS_OFF + PT_V9_I4], %i4 199 ldx [%sp + PTREGS_OFF + PT_V9_I5], %i5 200 201 cmp %g1, NR_syscalls 202 bgeu,pn %xcc, 3f 203 mov -ENOSYS, %o0 204 205 sll %g1, 2, %l4 206 mov %i0, %o0 207 lduw [%l7 + %l4], %l7 208 mov %i1, %o1 209 mov %i2, %o2 210 mov %i3, %o3 211 b,pt %xcc, 2f 212 mov %i4, %o4 213 214 215 /* Linux 32-bit system calls enter here... */ 216 .align 32 217 .globl linux_sparc_syscall32 218linux_sparc_syscall32: 219 /* Direct access to user regs, much faster. */ 220 cmp %g1, NR_syscalls ! IEU1 Group 221 bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI 222 srl %i0, 0, %o0 ! IEU0 223 sll %g1, 2, %l4 ! IEU0 Group 224 srl %i4, 0, %o4 ! IEU1 225 lduw [%l7 + %l4], %l7 ! Load 226 srl %i1, 0, %o1 ! IEU0 Group 227 ldx [%g6 + TI_FLAGS], %l0 ! Load 228 229 srl %i3, 0, %o3 ! IEU0 230 srl %i2, 0, %o2 ! IEU0 Group 231 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0 232 bne,pn %icc, linux_syscall_trace32 ! CTI 233 mov %i0, %l5 ! IEU1 2345: call %l7 ! CTI Group brk forced 235 srl %i5, 0, %o5 ! IEU1 236 ba,pt %xcc, 3f 237 sra %o0, 0, %o0 238 239 /* Linux native system calls enter here... */ 240 .align 32 241 .globl linux_sparc_syscall 242linux_sparc_syscall: 243 /* Direct access to user regs, much faster. */ 244 cmp %g1, NR_syscalls ! IEU1 Group 245 bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI 246 mov %i0, %o0 ! IEU0 247 sll %g1, 2, %l4 ! IEU0 Group 248 mov %i1, %o1 ! IEU1 249 lduw [%l7 + %l4], %l7 ! Load 2504: mov %i2, %o2 ! IEU0 Group 251 ldx [%g6 + TI_FLAGS], %l0 ! Load 252 253 mov %i3, %o3 ! IEU1 254 mov %i4, %o4 ! IEU0 Group 255 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0 256 bne,pn %icc, linux_syscall_trace ! CTI Group 257 mov %i0, %l5 ! IEU0 2582: call %l7 ! CTI Group brk forced 259 mov %i5, %o5 ! IEU0 260 nop 261 2623: stx %o0, [%sp + PTREGS_OFF + PT_V9_I0] 263ret_sys_call: 264 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %g3 265 mov %ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2 266 sllx %g2, 32, %g2 267 268 cmp %o0, -ERESTART_RESTARTBLOCK 269 bgeu,pn %xcc, 1f 270 andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0 271 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc 272 2732: 274 /* System call success, clear Carry condition code. */ 275 andn %g3, %g2, %g3 2763: 277 stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE] 278 bne,pn %icc, linux_syscall_trace2 279 add %l1, 0x4, %l2 ! npc = npc+4 280 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC] 281 ba,pt %xcc, rtrap 282 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC] 283 2841: 285 /* Check if force_successful_syscall_return() 286 * was invoked. 287 */ 288 ldub [%g6 + TI_SYS_NOERROR], %l2 289 brnz,pn %l2, 2b 290 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc 291 /* System call failure, set Carry condition code. 292 * Also, get abs(errno) to return to the process. 293 */ 294 sub %g0, %o0, %o0 295 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0] 296 ba,pt %xcc, 3b 297 or %g3, %g2, %g3 298 299linux_syscall_trace2: 300 call syscall_trace_leave 301 add %sp, PTREGS_OFF, %o0 302 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC] 303 ba,pt %xcc, rtrap 304 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC] 305