syscalls.S 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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), %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, and
  109. * check performance counter stuff too.
  110. */
  111. stb %g0, [%g6 + TI_NEW_CHILD]
  112. ldx [%g6 + TI_FLAGS], %l0
  113. call schedule_tail
  114. mov %g7, %o0
  115. andcc %l0, _TIF_PERFCTR, %g0
  116. be,pt %icc, 1f
  117. nop
  118. ldx [%g6 + TI_PCR], %o7
  119. wr %g0, %o7, %pcr
  120. /* Blackbird errata workaround. See commentary in
  121. * smp.c:smp_percpu_timer_interrupt() for more
  122. * information.
  123. */
  124. ba,pt %xcc, 99f
  125. nop
  126. .align 64
  127. 99: wr %g0, %g0, %pic
  128. rd %pic, %g0
  129. 1: ba,pt %xcc, ret_sys_call
  130. ldx [%sp + PTREGS_OFF + PT_V9_I0], %o0
  131. .globl sparc_exit
  132. .type sparc_exit,#function
  133. sparc_exit:
  134. rdpr %pstate, %g2
  135. wrpr %g2, PSTATE_IE, %pstate
  136. rdpr %otherwin, %g1
  137. rdpr %cansave, %g3
  138. add %g3, %g1, %g3
  139. wrpr %g3, 0x0, %cansave
  140. wrpr %g0, 0x0, %otherwin
  141. wrpr %g2, 0x0, %pstate
  142. ba,pt %xcc, sys_exit
  143. stb %g0, [%g6 + TI_WSAVED]
  144. .size sparc_exit,.-sparc_exit
  145. linux_sparc_ni_syscall:
  146. sethi %hi(sys_ni_syscall), %l7
  147. ba,pt %xcc, 4f
  148. or %l7, %lo(sys_ni_syscall), %l7
  149. linux_syscall_trace32:
  150. call syscall_trace_enter
  151. add %sp, PTREGS_OFF, %o0
  152. brnz,pn %o0, 3f
  153. mov -ENOSYS, %o0
  154. srl %i0, 0, %o0
  155. srl %i4, 0, %o4
  156. srl %i1, 0, %o1
  157. srl %i2, 0, %o2
  158. ba,pt %xcc, 2f
  159. srl %i3, 0, %o3
  160. linux_syscall_trace:
  161. call syscall_trace_enter
  162. add %sp, PTREGS_OFF, %o0
  163. brnz,pn %o0, 3f
  164. mov -ENOSYS, %o0
  165. mov %i0, %o0
  166. mov %i1, %o1
  167. mov %i2, %o2
  168. mov %i3, %o3
  169. b,pt %xcc, 2f
  170. mov %i4, %o4
  171. /* Linux 32-bit system calls enter here... */
  172. .align 32
  173. .globl linux_sparc_syscall32
  174. linux_sparc_syscall32:
  175. /* Direct access to user regs, much faster. */
  176. cmp %g1, NR_SYSCALLS ! IEU1 Group
  177. bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
  178. srl %i0, 0, %o0 ! IEU0
  179. sll %g1, 2, %l4 ! IEU0 Group
  180. srl %i4, 0, %o4 ! IEU1
  181. lduw [%l7 + %l4], %l7 ! Load
  182. srl %i1, 0, %o1 ! IEU0 Group
  183. ldx [%g6 + TI_FLAGS], %l0 ! Load
  184. srl %i5, 0, %o5 ! IEU1
  185. srl %i2, 0, %o2 ! IEU0 Group
  186. andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
  187. bne,pn %icc, linux_syscall_trace32 ! CTI
  188. mov %i0, %l5 ! IEU1
  189. call %l7 ! CTI Group brk forced
  190. srl %i3, 0, %o3 ! IEU0
  191. ba,a,pt %xcc, 3f
  192. /* Linux native system calls enter here... */
  193. .align 32
  194. .globl linux_sparc_syscall
  195. linux_sparc_syscall:
  196. /* Direct access to user regs, much faster. */
  197. cmp %g1, NR_SYSCALLS ! IEU1 Group
  198. bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
  199. mov %i0, %o0 ! IEU0
  200. sll %g1, 2, %l4 ! IEU0 Group
  201. mov %i1, %o1 ! IEU1
  202. lduw [%l7 + %l4], %l7 ! Load
  203. 4: mov %i2, %o2 ! IEU0 Group
  204. ldx [%g6 + TI_FLAGS], %l0 ! Load
  205. mov %i3, %o3 ! IEU1
  206. mov %i4, %o4 ! IEU0 Group
  207. andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
  208. bne,pn %icc, linux_syscall_trace ! CTI Group
  209. mov %i0, %l5 ! IEU0
  210. 2: call %l7 ! CTI Group brk forced
  211. mov %i5, %o5 ! IEU0
  212. nop
  213. 3: stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
  214. ret_sys_call:
  215. ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %g3
  216. ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
  217. sra %o0, 0, %o0
  218. mov %ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2
  219. sllx %g2, 32, %g2
  220. /* Check if force_successful_syscall_return()
  221. * was invoked.
  222. */
  223. ldub [%g6 + TI_SYS_NOERROR], %l2
  224. brnz,a,pn %l2, 80f
  225. stb %g0, [%g6 + TI_SYS_NOERROR]
  226. cmp %o0, -ERESTART_RESTARTBLOCK
  227. bgeu,pn %xcc, 1f
  228. andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %l6
  229. 80:
  230. /* System call success, clear Carry condition code. */
  231. andn %g3, %g2, %g3
  232. stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
  233. bne,pn %icc, linux_syscall_trace2
  234. add %l1, 0x4, %l2 ! npc = npc+4
  235. stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
  236. ba,pt %xcc, rtrap
  237. stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
  238. 1:
  239. /* System call failure, set Carry condition code.
  240. * Also, get abs(errno) to return to the process.
  241. */
  242. andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %l6
  243. sub %g0, %o0, %o0
  244. or %g3, %g2, %g3
  245. stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
  246. stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
  247. bne,pn %icc, linux_syscall_trace2
  248. add %l1, 0x4, %l2 ! npc = npc+4
  249. stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
  250. b,pt %xcc, rtrap
  251. stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
  252. linux_syscall_trace2:
  253. call syscall_trace_leave
  254. add %sp, PTREGS_OFF, %o0
  255. stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
  256. ba,pt %xcc, rtrap
  257. stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]