syscalls.S 6.8 KB

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