syscalls.S 7.8 KB

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