entry-common.S 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. /*
  2. * Copyright (C) 1999, 2000, 2002 Niibe Yutaka
  3. * Copyright (C) 2003 - 2008 Paul Mundt
  4. *
  5. * This file is subject to the terms and conditions of the GNU General Public
  6. * License. See the file "COPYING" in the main directory of this archive
  7. * for more details.
  8. *
  9. */
  10. ! NOTE:
  11. ! GNU as (as of 2.9.1) changes bf/s into bt/s and bra, when the address
  12. ! to be jumped is too far, but it causes illegal slot exception.
  13. /*
  14. * entry.S contains the system-call and fault low-level handling routines.
  15. * This also contains the timer-interrupt handler, as well as all interrupts
  16. * and faults that can result in a task-switch.
  17. *
  18. * NOTE: This code handles signal-recognition, which happens every time
  19. * after a timer-interrupt and after each system call.
  20. *
  21. * NOTE: This code uses a convention that instructions in the delay slot
  22. * of a transfer-control instruction are indented by an extra space, thus:
  23. *
  24. * jmp @k0 ! control-transfer instruction
  25. * ldc k1, ssr ! delay slot
  26. *
  27. * Stack layout in 'ret_from_syscall':
  28. * ptrace needs to have all regs on the stack.
  29. * if the order here is changed, it needs to be
  30. * updated in ptrace.c and ptrace.h
  31. *
  32. * r0
  33. * ...
  34. * r15 = stack pointer
  35. * spc
  36. * pr
  37. * ssr
  38. * gbr
  39. * mach
  40. * macl
  41. * syscall #
  42. *
  43. */
  44. #if defined(CONFIG_PREEMPT)
  45. # define preempt_stop() cli
  46. #else
  47. # define preempt_stop()
  48. # define resume_kernel __restore_all
  49. #endif
  50. .align 2
  51. ENTRY(exception_error)
  52. !
  53. #ifdef CONFIG_TRACE_IRQFLAGS
  54. mov.l 2f, r0
  55. jsr @r0
  56. nop
  57. #endif
  58. sti
  59. mov.l 1f, r0
  60. jmp @r0
  61. nop
  62. .align 2
  63. 1: .long do_exception_error
  64. #ifdef CONFIG_TRACE_IRQFLAGS
  65. 2: .long trace_hardirqs_on
  66. #endif
  67. .align 2
  68. ret_from_exception:
  69. preempt_stop()
  70. #ifdef CONFIG_TRACE_IRQFLAGS
  71. mov.l 4f, r0
  72. jsr @r0
  73. nop
  74. #endif
  75. ENTRY(ret_from_irq)
  76. !
  77. mov #OFF_SR, r0
  78. mov.l @(r0,r15), r0 ! get status register
  79. shll r0
  80. shll r0 ! kernel space?
  81. get_current_thread_info r8, r0
  82. bt resume_kernel ! Yes, it's from kernel, go back soon
  83. #ifdef CONFIG_PREEMPT
  84. bra resume_userspace
  85. nop
  86. ENTRY(resume_kernel)
  87. cli
  88. mov.l @(TI_PRE_COUNT,r8), r0 ! current_thread_info->preempt_count
  89. tst r0, r0
  90. bf noresched
  91. need_resched:
  92. mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
  93. tst #_TIF_NEED_RESCHED, r0 ! need_resched set?
  94. bt noresched
  95. mov #OFF_SR, r0
  96. mov.l @(r0,r15), r0 ! get status register
  97. and #0xf0, r0 ! interrupts off (exception path)?
  98. cmp/eq #0xf0, r0
  99. bt noresched
  100. mov.l 3f, r0
  101. jsr @r0 ! call preempt_schedule_irq
  102. nop
  103. bra need_resched
  104. nop
  105. noresched:
  106. bra __restore_all
  107. nop
  108. .align 2
  109. 1: .long PREEMPT_ACTIVE
  110. 2: .long schedule
  111. 3: .long preempt_schedule_irq
  112. #endif
  113. ENTRY(resume_userspace)
  114. ! r8: current_thread_info
  115. cli
  116. #ifdef CONFIG_TRACE_IRQFLAGS
  117. mov.l 5f, r0
  118. jsr @r0
  119. nop
  120. #endif
  121. mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
  122. tst #_TIF_WORK_MASK, r0
  123. bt/s __restore_all
  124. tst #_TIF_NEED_RESCHED, r0
  125. .align 2
  126. work_pending:
  127. ! r0: current_thread_info->flags
  128. ! r8: current_thread_info
  129. ! t: result of "tst #_TIF_NEED_RESCHED, r0"
  130. bf/s work_resched
  131. tst #(_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK), r0
  132. work_notifysig:
  133. bt/s __restore_all
  134. mov r15, r4
  135. mov r12, r5 ! set arg1(save_r0)
  136. mov r0, r6
  137. mov.l 2f, r1
  138. mov.l 3f, r0
  139. jmp @r1
  140. lds r0, pr
  141. work_resched:
  142. mov.l 1f, r1
  143. jsr @r1 ! schedule
  144. nop
  145. cli
  146. #ifdef CONFIG_TRACE_IRQFLAGS
  147. mov.l 5f, r0
  148. jsr @r0
  149. nop
  150. #endif
  151. !
  152. mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
  153. tst #_TIF_WORK_MASK, r0
  154. bt __restore_all
  155. bra work_pending
  156. tst #_TIF_NEED_RESCHED, r0
  157. .align 2
  158. 1: .long schedule
  159. 2: .long do_notify_resume
  160. 3: .long resume_userspace
  161. #ifdef CONFIG_TRACE_IRQFLAGS
  162. 4: .long trace_hardirqs_on
  163. 5: .long trace_hardirqs_off
  164. #endif
  165. .align 2
  166. syscall_exit_work:
  167. ! r0: current_thread_info->flags
  168. ! r8: current_thread_info
  169. tst #_TIF_WORK_SYSCALL_MASK, r0
  170. bt/s work_pending
  171. tst #_TIF_NEED_RESCHED, r0
  172. #ifdef CONFIG_TRACE_IRQFLAGS
  173. mov.l 5f, r0
  174. jsr @r0
  175. nop
  176. #endif
  177. sti
  178. mov r15, r4
  179. mov.l 8f, r0 ! do_syscall_trace_leave
  180. jsr @r0
  181. nop
  182. bra resume_userspace
  183. nop
  184. .align 2
  185. syscall_trace_entry:
  186. ! Yes it is traced.
  187. mov r15, r4
  188. mov.l 7f, r11 ! Call do_syscall_trace_enter which notifies
  189. jsr @r11 ! superior (will chomp R[0-7])
  190. nop
  191. mov.l r0, @(OFF_R0,r15) ! Save return value
  192. ! Reload R0-R4 from kernel stack, where the
  193. ! parent may have modified them using
  194. ! ptrace(POKEUSR). (Note that R0-R2 are
  195. ! used by the system call handler directly
  196. ! from the kernel stack anyway, so don't need
  197. ! to be reloaded here.) This allows the parent
  198. ! to rewrite system calls and args on the fly.
  199. mov.l @(OFF_R4,r15), r4 ! arg0
  200. mov.l @(OFF_R5,r15), r5
  201. mov.l @(OFF_R6,r15), r6
  202. mov.l @(OFF_R7,r15), r7 ! arg3
  203. mov.l @(OFF_R3,r15), r3 ! syscall_nr
  204. !
  205. mov.l 2f, r10 ! Number of syscalls
  206. cmp/hs r10, r3
  207. bf syscall_call
  208. mov #-ENOSYS, r0
  209. bra syscall_exit
  210. mov.l r0, @(OFF_R0,r15) ! Return value
  211. __restore_all:
  212. mov.l 1f, r0
  213. jmp @r0
  214. nop
  215. .align 2
  216. 1: .long restore_all
  217. .align 2
  218. syscall_badsys: ! Bad syscall number
  219. get_current_thread_info r8, r0
  220. mov #-ENOSYS, r0
  221. bra resume_userspace
  222. mov.l r0, @(OFF_R0,r15) ! Return value
  223. /*
  224. * The main debug trap handler.
  225. *
  226. * r8=TRA (not the trap number!)
  227. *
  228. * Note: This assumes that the trapa value is left in its original
  229. * form (without the shlr2 shift) so the calculation for the jump
  230. * call table offset remains a simple in place mask.
  231. */
  232. debug_trap:
  233. mov r8, r0
  234. and #(0xf << 2), r0
  235. mov.l 1f, r8
  236. add r0, r8
  237. mov.l @r8, r8
  238. jsr @r8
  239. nop
  240. bra __restore_all
  241. nop
  242. .align 2
  243. 1: .long debug_trap_table
  244. /*
  245. * Syscall interface:
  246. *
  247. * Syscall #: R3
  248. * Arguments #0 to #3: R4--R7
  249. * Arguments #4 to #6: R0, R1, R2
  250. * TRA: (number of arguments + ABI revision) x 4
  251. *
  252. * This code also handles delegating other traps to the BIOS/gdb stub
  253. * according to:
  254. *
  255. * Trap number
  256. * (TRA>>2) Purpose
  257. * -------- -------
  258. * 0x00-0x0f original SH-3/4 syscall ABI (not in general use).
  259. * 0x10-0x1f general SH-3/4 syscall ABI.
  260. * 0x20-0x2f syscall ABI for SH-2 parts.
  261. * 0x30-0x3f debug traps used by the kernel.
  262. * 0x40-0xff Not supported by all parts, so left unhandled.
  263. *
  264. * Note: When we're first called, the TRA value must be shifted
  265. * right 2 bits in order to get the value that was used as the "trapa"
  266. * argument.
  267. */
  268. .align 2
  269. .globl ret_from_fork
  270. ret_from_fork:
  271. mov.l 1f, r8
  272. jsr @r8
  273. mov r0, r4
  274. bra syscall_exit
  275. nop
  276. .align 2
  277. 1: .long schedule_tail
  278. /*
  279. * The poorly named main trapa decode and dispatch routine, for
  280. * system calls and debug traps through their respective jump tables.
  281. */
  282. ENTRY(system_call)
  283. #if !defined(CONFIG_CPU_SH2)
  284. mov.l 1f, r9
  285. mov.l @r9, r8 ! Read from TRA (Trap Address) Register
  286. #endif
  287. mov #OFF_TRA, r10
  288. add r15, r10
  289. mov.l r8, @r10 ! set TRA value to tra
  290. /*
  291. * Check the trap type
  292. */
  293. mov #((0x20 << 2) - 1), r9
  294. cmp/hi r9, r8
  295. bt/s debug_trap ! it's a debug trap..
  296. nop
  297. #ifdef CONFIG_TRACE_IRQFLAGS
  298. mov.l 5f, r10
  299. jsr @r10
  300. nop
  301. #endif
  302. sti
  303. !
  304. get_current_thread_info r8, r10
  305. mov.l @(TI_FLAGS,r8), r8
  306. mov #_TIF_WORK_SYSCALL_MASK, r10
  307. tst r10, r8
  308. bf syscall_trace_entry
  309. !
  310. mov.l 2f, r8 ! Number of syscalls
  311. cmp/hs r8, r3
  312. bt syscall_badsys
  313. !
  314. syscall_call:
  315. shll2 r3 ! x4
  316. mov.l 3f, r8 ! Load the address of sys_call_table
  317. add r8, r3
  318. mov.l @r3, r8
  319. jsr @r8 ! jump to specific syscall handler
  320. nop
  321. mov.l @(OFF_R0,r15), r12 ! save r0
  322. mov.l r0, @(OFF_R0,r15) ! save the return value
  323. !
  324. syscall_exit:
  325. cli
  326. #ifdef CONFIG_TRACE_IRQFLAGS
  327. mov.l 6f, r0
  328. jsr @r0
  329. nop
  330. #endif
  331. !
  332. get_current_thread_info r8, r0
  333. mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
  334. tst #_TIF_ALLWORK_MASK, r0
  335. bf syscall_exit_work
  336. bra __restore_all
  337. nop
  338. .align 2
  339. #if !defined(CONFIG_CPU_SH2)
  340. 1: .long TRA
  341. #endif
  342. 2: .long NR_syscalls
  343. 3: .long sys_call_table
  344. #ifdef CONFIG_TRACE_IRQFLAGS
  345. 5: .long trace_hardirqs_on
  346. 6: .long trace_hardirqs_off
  347. #endif
  348. 7: .long do_syscall_trace_enter
  349. 8: .long do_syscall_trace_leave