syscalls.S 6.8 KB

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