syscalls.S 7.8 KB

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