syscalls.S 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /* SunOS's execv() call only specifies the argv argument, the
  2. * environment settings are the same as the calling processes.
  3. */
  4. sys_execve:
  5. sethi %hi(sparc_execve), %g1
  6. ba,pt %xcc, execve_merge
  7. or %g1, %lo(sparc_execve), %g1
  8. #ifdef CONFIG_COMPAT
  9. sunos_execv:
  10. stx %g0, [%sp + PTREGS_OFF + PT_V9_I2]
  11. sys32_execve:
  12. sethi %hi(sparc32_execve), %g1
  13. or %g1, %lo(sparc32_execve), %g1
  14. #endif
  15. execve_merge:
  16. flushw
  17. jmpl %g1, %g0
  18. add %sp, PTREGS_OFF, %o0
  19. .align 32
  20. sys_sparc_pipe:
  21. ba,pt %xcc, sys_sparc_pipe_real
  22. add %sp, PTREGS_OFF, %o0
  23. sys_nis_syscall:
  24. ba,pt %xcc, c_sys_nis_syscall
  25. add %sp, PTREGS_OFF, %o0
  26. sys_memory_ordering:
  27. ba,pt %xcc, sparc_memory_ordering
  28. add %sp, PTREGS_OFF, %o1
  29. sys_sigaltstack:
  30. ba,pt %xcc, do_sigaltstack
  31. add %i6, STACK_BIAS, %o2
  32. #ifdef CONFIG_COMPAT
  33. sys32_sigstack:
  34. ba,pt %xcc, do_sys32_sigstack
  35. mov %i6, %o2
  36. sys32_sigaltstack:
  37. ba,pt %xcc, do_sys32_sigaltstack
  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), %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_syscall
  107. ret_from_syscall:
  108. /* Clear current_thread_info()->new_child. */
  109. stb %g0, [%g6 + TI_NEW_CHILD]
  110. ldx [%g6 + TI_FLAGS], %l0
  111. call schedule_tail
  112. mov %g7, %o0
  113. ba,pt %xcc, ret_sys_call
  114. ldx [%sp + PTREGS_OFF + PT_V9_I0], %o0
  115. .globl sparc_exit
  116. .type sparc_exit,#function
  117. sparc_exit:
  118. rdpr %pstate, %g2
  119. wrpr %g2, PSTATE_IE, %pstate
  120. rdpr %otherwin, %g1
  121. rdpr %cansave, %g3
  122. add %g3, %g1, %g3
  123. wrpr %g3, 0x0, %cansave
  124. wrpr %g0, 0x0, %otherwin
  125. wrpr %g2, 0x0, %pstate
  126. ba,pt %xcc, sys_exit
  127. stb %g0, [%g6 + TI_WSAVED]
  128. .size sparc_exit,.-sparc_exit
  129. linux_sparc_ni_syscall:
  130. sethi %hi(sys_ni_syscall), %l7
  131. ba,pt %xcc, 4f
  132. or %l7, %lo(sys_ni_syscall), %l7
  133. linux_syscall_trace32:
  134. call syscall_trace_enter
  135. add %sp, PTREGS_OFF, %o0
  136. brnz,pn %o0, 3f
  137. mov -ENOSYS, %o0
  138. srl %i0, 0, %o0
  139. srl %i4, 0, %o4
  140. srl %i1, 0, %o1
  141. srl %i2, 0, %o2
  142. ba,pt %xcc, 2f
  143. srl %i3, 0, %o3
  144. linux_syscall_trace:
  145. call syscall_trace_enter
  146. add %sp, PTREGS_OFF, %o0
  147. brnz,pn %o0, 3f
  148. mov -ENOSYS, %o0
  149. mov %i0, %o0
  150. mov %i1, %o1
  151. mov %i2, %o2
  152. mov %i3, %o3
  153. b,pt %xcc, 2f
  154. mov %i4, %o4
  155. /* Linux 32-bit system calls enter here... */
  156. .align 32
  157. .globl linux_sparc_syscall32
  158. linux_sparc_syscall32:
  159. /* Direct access to user regs, much faster. */
  160. cmp %g1, NR_syscalls ! IEU1 Group
  161. bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
  162. srl %i0, 0, %o0 ! IEU0
  163. sll %g1, 2, %l4 ! IEU0 Group
  164. srl %i4, 0, %o4 ! IEU1
  165. lduw [%l7 + %l4], %l7 ! Load
  166. srl %i1, 0, %o1 ! IEU0 Group
  167. ldx [%g6 + TI_FLAGS], %l0 ! Load
  168. srl %i5, 0, %o5 ! IEU1
  169. srl %i2, 0, %o2 ! IEU0 Group
  170. andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
  171. bne,pn %icc, linux_syscall_trace32 ! CTI
  172. mov %i0, %l5 ! IEU1
  173. call %l7 ! CTI Group brk forced
  174. srl %i3, 0, %o3 ! IEU0
  175. ba,a,pt %xcc, 3f
  176. /* Linux native system calls enter here... */
  177. .align 32
  178. .globl linux_sparc_syscall
  179. linux_sparc_syscall:
  180. /* Direct access to user regs, much faster. */
  181. cmp %g1, NR_syscalls ! IEU1 Group
  182. bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
  183. mov %i0, %o0 ! IEU0
  184. sll %g1, 2, %l4 ! IEU0 Group
  185. mov %i1, %o1 ! IEU1
  186. lduw [%l7 + %l4], %l7 ! Load
  187. 4: mov %i2, %o2 ! IEU0 Group
  188. ldx [%g6 + TI_FLAGS], %l0 ! Load
  189. mov %i3, %o3 ! IEU1
  190. mov %i4, %o4 ! IEU0 Group
  191. andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
  192. bne,pn %icc, linux_syscall_trace ! CTI Group
  193. mov %i0, %l5 ! IEU0
  194. 2: call %l7 ! CTI Group brk forced
  195. mov %i5, %o5 ! IEU0
  196. nop
  197. 3: stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
  198. ret_sys_call:
  199. ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %g3
  200. ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
  201. sra %o0, 0, %o0
  202. mov %ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2
  203. sllx %g2, 32, %g2
  204. /* Check if force_successful_syscall_return()
  205. * was invoked.
  206. */
  207. ldub [%g6 + TI_SYS_NOERROR], %l2
  208. brnz,a,pn %l2, 80f
  209. stb %g0, [%g6 + TI_SYS_NOERROR]
  210. cmp %o0, -ERESTART_RESTARTBLOCK
  211. bgeu,pn %xcc, 1f
  212. andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
  213. 80:
  214. /* System call success, clear Carry condition code. */
  215. andn %g3, %g2, %g3
  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. /* System call failure, set Carry condition code.
  224. * Also, get abs(errno) to return to the process.
  225. */
  226. andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
  227. sub %g0, %o0, %o0
  228. or %g3, %g2, %g3
  229. stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
  230. stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
  231. bne,pn %icc, linux_syscall_trace2
  232. add %l1, 0x4, %l2 ! npc = npc+4
  233. stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
  234. b,pt %xcc, rtrap
  235. stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
  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]