syscalls.S 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. #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), %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: /* Under Linux, vfork and fork are just special cases of clone. */
  85. sethi %hi(0x4000 | 0x0100 | SIGCHLD), %o0
  86. or %o0, %lo(0x4000 | 0x0100 | SIGCHLD), %o0
  87. ba,pt %xcc, sys_clone
  88. sys_fork:
  89. clr %o1
  90. mov SIGCHLD, %o0
  91. sys_clone:
  92. flushw
  93. movrz %o1, %fp, %o1
  94. mov 0, %o3
  95. ba,pt %xcc, sparc_do_fork
  96. add %sp, PTREGS_OFF, %o2
  97. .globl ret_from_syscall
  98. ret_from_syscall:
  99. /* Clear current_thread_info()->new_child. */
  100. stb %g0, [%g6 + TI_NEW_CHILD]
  101. call schedule_tail
  102. mov %g7, %o0
  103. ldx [%sp + PTREGS_OFF + PT_V9_I0], %o0
  104. brnz,pt %o0, ret_sys_call
  105. ldx [%g6 + TI_FLAGS], %l0
  106. ldx [%sp + PTREGS_OFF + PT_V9_G1], %l1
  107. call %l1
  108. ldx [%sp + PTREGS_OFF + PT_V9_G2], %o0
  109. ba,pt %xcc, ret_sys_call
  110. mov 0, %o0
  111. .globl sparc_exit_group
  112. .type sparc_exit_group,#function
  113. sparc_exit_group:
  114. sethi %hi(sys_exit_group), %g7
  115. ba,pt %xcc, 1f
  116. or %g7, %lo(sys_exit_group), %g7
  117. .size sparc_exit_group,.-sparc_exit_group
  118. .globl sparc_exit
  119. .type sparc_exit,#function
  120. sparc_exit:
  121. sethi %hi(sys_exit), %g7
  122. or %g7, %lo(sys_exit), %g7
  123. 1: rdpr %pstate, %g2
  124. wrpr %g2, PSTATE_IE, %pstate
  125. rdpr %otherwin, %g1
  126. rdpr %cansave, %g3
  127. add %g3, %g1, %g3
  128. wrpr %g3, 0x0, %cansave
  129. wrpr %g0, 0x0, %otherwin
  130. wrpr %g2, 0x0, %pstate
  131. jmpl %g7, %g0
  132. stb %g0, [%g6 + TI_WSAVED]
  133. .size sparc_exit,.-sparc_exit
  134. linux_sparc_ni_syscall:
  135. sethi %hi(sys_ni_syscall), %l7
  136. ba,pt %xcc, 4f
  137. or %l7, %lo(sys_ni_syscall), %l7
  138. linux_syscall_trace32:
  139. call syscall_trace_enter
  140. add %sp, PTREGS_OFF, %o0
  141. brnz,pn %o0, 3f
  142. mov -ENOSYS, %o0
  143. srl %i0, 0, %o0
  144. srl %i4, 0, %o4
  145. srl %i1, 0, %o1
  146. srl %i2, 0, %o2
  147. ba,pt %xcc, 2f
  148. srl %i3, 0, %o3
  149. linux_syscall_trace:
  150. call syscall_trace_enter
  151. add %sp, PTREGS_OFF, %o0
  152. brnz,pn %o0, 3f
  153. mov -ENOSYS, %o0
  154. mov %i0, %o0
  155. mov %i1, %o1
  156. mov %i2, %o2
  157. mov %i3, %o3
  158. b,pt %xcc, 2f
  159. mov %i4, %o4
  160. /* Linux 32-bit system calls enter here... */
  161. .align 32
  162. .globl linux_sparc_syscall32
  163. linux_sparc_syscall32:
  164. /* Direct access to user regs, much faster. */
  165. cmp %g1, NR_syscalls ! IEU1 Group
  166. bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
  167. srl %i0, 0, %o0 ! IEU0
  168. sll %g1, 2, %l4 ! IEU0 Group
  169. srl %i4, 0, %o4 ! IEU1
  170. lduw [%l7 + %l4], %l7 ! Load
  171. srl %i1, 0, %o1 ! IEU0 Group
  172. ldx [%g6 + TI_FLAGS], %l0 ! Load
  173. srl %i5, 0, %o5 ! IEU1
  174. srl %i2, 0, %o2 ! IEU0 Group
  175. andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
  176. bne,pn %icc, linux_syscall_trace32 ! CTI
  177. mov %i0, %l5 ! IEU1
  178. call %l7 ! CTI Group brk forced
  179. srl %i3, 0, %o3 ! IEU0
  180. ba,a,pt %xcc, 3f
  181. /* Linux native system calls enter here... */
  182. .align 32
  183. .globl linux_sparc_syscall
  184. linux_sparc_syscall:
  185. /* Direct access to user regs, much faster. */
  186. cmp %g1, NR_syscalls ! IEU1 Group
  187. bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
  188. mov %i0, %o0 ! IEU0
  189. sll %g1, 2, %l4 ! IEU0 Group
  190. mov %i1, %o1 ! IEU1
  191. lduw [%l7 + %l4], %l7 ! Load
  192. 4: mov %i2, %o2 ! IEU0 Group
  193. ldx [%g6 + TI_FLAGS], %l0 ! Load
  194. mov %i3, %o3 ! IEU1
  195. mov %i4, %o4 ! IEU0 Group
  196. andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
  197. bne,pn %icc, linux_syscall_trace ! CTI Group
  198. mov %i0, %l5 ! IEU0
  199. 2: call %l7 ! CTI Group brk forced
  200. mov %i5, %o5 ! IEU0
  201. nop
  202. 3: stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
  203. ret_sys_call:
  204. ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %g3
  205. sra %o0, 0, %o0
  206. mov %ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2
  207. sllx %g2, 32, %g2
  208. cmp %o0, -ERESTART_RESTARTBLOCK
  209. bgeu,pn %xcc, 1f
  210. andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
  211. ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
  212. 2:
  213. /* System call success, clear Carry condition code. */
  214. andn %g3, %g2, %g3
  215. 3:
  216. stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
  217. bne,pn %icc, linux_syscall_trace2
  218. add %l1, 0x4, %l2 ! npc = npc+4
  219. stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
  220. ba,pt %xcc, rtrap
  221. stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
  222. 1:
  223. /* Check if force_successful_syscall_return()
  224. * was invoked.
  225. */
  226. ldub [%g6 + TI_SYS_NOERROR], %l2
  227. brnz,pn %l2, 2b
  228. ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
  229. /* System call failure, set Carry condition code.
  230. * Also, get abs(errno) to return to the process.
  231. */
  232. sub %g0, %o0, %o0
  233. stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
  234. ba,pt %xcc, 3b
  235. or %g3, %g2, %g3
  236. linux_syscall_trace2:
  237. call syscall_trace_leave
  238. add %sp, PTREGS_OFF, %o0
  239. stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
  240. ba,pt %xcc, rtrap
  241. stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]