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_pipe:
  21. ba,pt %xcc, sparc_pipe
  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. add %sp, PTREGS_OFF, %o0
  66. call syscall_trace
  67. mov 1, %o1
  68. ba,pt %xcc, rtrap
  69. nop
  70. /* This is how fork() was meant to be done, 8 instruction entry.
  71. *
  72. * I questioned the following code briefly, let me clear things
  73. * up so you must not reason on it like I did.
  74. *
  75. * Know the fork_kpsr etc. we use in the sparc32 port? We don't
  76. * need it here because the only piece of window state we copy to
  77. * the child is the CWP register. Even if the parent sleeps,
  78. * we are safe because we stuck it into pt_regs of the parent
  79. * so it will not change.
  80. *
  81. * XXX This raises the question, whether we can do the same on
  82. * XXX sparc32 to get rid of fork_kpsr _and_ fork_kwim. The
  83. * XXX answer is yes. We stick fork_kpsr in UREG_G0 and
  84. * XXX fork_kwim in UREG_G1 (global registers are considered
  85. * XXX volatile across a system call in the sparc ABI I think
  86. * XXX if it isn't we can use regs->y instead, anyone who depends
  87. * XXX upon the Y register being preserved across a fork deserves
  88. * XXX to lose).
  89. *
  90. * In fact we should take advantage of that fact for other things
  91. * during system calls...
  92. */
  93. .align 32
  94. sys_vfork: /* Under Linux, vfork and fork are just special cases of clone. */
  95. sethi %hi(0x4000 | 0x0100 | SIGCHLD), %o0
  96. or %o0, %lo(0x4000 | 0x0100 | SIGCHLD), %o0
  97. ba,pt %xcc, sys_clone
  98. sys_fork:
  99. clr %o1
  100. mov SIGCHLD, %o0
  101. sys_clone:
  102. flushw
  103. movrz %o1, %fp, %o1
  104. mov 0, %o3
  105. ba,pt %xcc, sparc_do_fork
  106. add %sp, PTREGS_OFF, %o2
  107. .globl ret_from_syscall
  108. ret_from_syscall:
  109. /* Clear current_thread_info()->new_child, and
  110. * check performance counter stuff too.
  111. */
  112. stb %g0, [%g6 + TI_NEW_CHILD]
  113. ldx [%g6 + TI_FLAGS], %l0
  114. call schedule_tail
  115. mov %g7, %o0
  116. andcc %l0, _TIF_PERFCTR, %g0
  117. be,pt %icc, 1f
  118. nop
  119. ldx [%g6 + TI_PCR], %o7
  120. wr %g0, %o7, %pcr
  121. /* Blackbird errata workaround. See commentary in
  122. * smp.c:smp_percpu_timer_interrupt() for more
  123. * information.
  124. */
  125. ba,pt %xcc, 99f
  126. nop
  127. .align 64
  128. 99: wr %g0, %g0, %pic
  129. rd %pic, %g0
  130. 1: ba,pt %xcc, ret_sys_call
  131. ldx [%sp + PTREGS_OFF + PT_V9_I0], %o0
  132. .globl sparc_exit
  133. .type sparc_exit,#function
  134. sparc_exit:
  135. rdpr %pstate, %g2
  136. wrpr %g2, PSTATE_IE, %pstate
  137. rdpr %otherwin, %g1
  138. rdpr %cansave, %g3
  139. add %g3, %g1, %g3
  140. wrpr %g3, 0x0, %cansave
  141. wrpr %g0, 0x0, %otherwin
  142. wrpr %g2, 0x0, %pstate
  143. ba,pt %xcc, sys_exit
  144. stb %g0, [%g6 + TI_WSAVED]
  145. .size sparc_exit,.-sparc_exit
  146. linux_sparc_ni_syscall:
  147. sethi %hi(sys_ni_syscall), %l7
  148. ba,pt %xcc, 4f
  149. or %l7, %lo(sys_ni_syscall), %l7
  150. linux_syscall_trace32:
  151. add %sp, PTREGS_OFF, %o0
  152. call syscall_trace
  153. clr %o1
  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. add %sp, PTREGS_OFF, %o0
  162. call syscall_trace
  163. clr %o1
  164. mov %i0, %o0
  165. mov %i1, %o1
  166. mov %i2, %o2
  167. mov %i3, %o3
  168. b,pt %xcc, 2f
  169. mov %i4, %o4
  170. /* Linux 32-bit system calls enter here... */
  171. .align 32
  172. .globl linux_sparc_syscall32
  173. linux_sparc_syscall32:
  174. /* Direct access to user regs, much faster. */
  175. cmp %g1, NR_SYSCALLS ! IEU1 Group
  176. bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
  177. srl %i0, 0, %o0 ! IEU0
  178. sll %g1, 2, %l4 ! IEU0 Group
  179. srl %i4, 0, %o4 ! IEU1
  180. lduw [%l7 + %l4], %l7 ! Load
  181. srl %i1, 0, %o1 ! IEU0 Group
  182. ldx [%g6 + TI_FLAGS], %l0 ! Load
  183. srl %i5, 0, %o5 ! IEU1
  184. srl %i2, 0, %o2 ! IEU0 Group
  185. andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
  186. bne,pn %icc, linux_syscall_trace32 ! CTI
  187. mov %i0, %l5 ! IEU1
  188. call %l7 ! CTI Group brk forced
  189. srl %i3, 0, %o3 ! IEU0
  190. ba,a,pt %xcc, 3f
  191. /* Linux native system calls enter here... */
  192. .align 32
  193. .globl linux_sparc_syscall
  194. linux_sparc_syscall:
  195. /* Direct access to user regs, much faster. */
  196. cmp %g1, NR_SYSCALLS ! IEU1 Group
  197. bgeu,pn %xcc, linux_sparc_ni_syscall ! CTI
  198. mov %i0, %o0 ! IEU0
  199. sll %g1, 2, %l4 ! IEU0 Group
  200. mov %i1, %o1 ! IEU1
  201. lduw [%l7 + %l4], %l7 ! Load
  202. 4: mov %i2, %o2 ! IEU0 Group
  203. ldx [%g6 + TI_FLAGS], %l0 ! Load
  204. mov %i3, %o3 ! IEU1
  205. mov %i4, %o4 ! IEU0 Group
  206. andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
  207. bne,pn %icc, linux_syscall_trace ! CTI Group
  208. mov %i0, %l5 ! IEU0
  209. 2: call %l7 ! CTI Group brk forced
  210. mov %i5, %o5 ! IEU0
  211. nop
  212. 3: stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
  213. ret_sys_call:
  214. ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %g3
  215. ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
  216. sra %o0, 0, %o0
  217. mov %ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2
  218. sllx %g2, 32, %g2
  219. /* Check if force_successful_syscall_return()
  220. * was invoked.
  221. */
  222. ldub [%g6 + TI_SYS_NOERROR], %l2
  223. brnz,a,pn %l2, 80f
  224. stb %g0, [%g6 + TI_SYS_NOERROR]
  225. cmp %o0, -ERESTART_RESTARTBLOCK
  226. bgeu,pn %xcc, 1f
  227. andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %l6
  228. 80:
  229. /* System call success, clear Carry condition code. */
  230. andn %g3, %g2, %g3
  231. stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
  232. bne,pn %icc, linux_syscall_trace2
  233. add %l1, 0x4, %l2 ! npc = npc+4
  234. stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
  235. ba,pt %xcc, rtrap
  236. stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
  237. 1:
  238. /* System call failure, set Carry condition code.
  239. * Also, get abs(errno) to return to the process.
  240. */
  241. andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %l6
  242. sub %g0, %o0, %o0
  243. or %g3, %g2, %g3
  244. stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
  245. stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
  246. bne,pn %icc, linux_syscall_trace2
  247. add %l1, 0x4, %l2 ! npc = npc+4
  248. stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
  249. b,pt %xcc, rtrap
  250. stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
  251. linux_syscall_trace2:
  252. add %sp, PTREGS_OFF, %o0
  253. call syscall_trace
  254. mov 1, %o1
  255. stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
  256. ba,pt %xcc, rtrap
  257. stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]