syscalls.S 7.5 KB

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