entry-common.S 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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. mov.l @(TI_PRE_COUNT,r8), r0 ! current_thread_info->preempt_count
  88. tst r0, r0
  89. bf noresched
  90. need_resched:
  91. mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
  92. tst #_TIF_NEED_RESCHED, r0 ! need_resched set?
  93. bt noresched
  94. mov #OFF_SR, r0
  95. mov.l @(r0,r15), r0 ! get status register
  96. and #0xf0, r0 ! interrupts off (exception path)?
  97. cmp/eq #0xf0, r0
  98. bt noresched
  99. mov.l 1f, r0
  100. mov.l r0, @(TI_PRE_COUNT,r8)
  101. #ifdef CONFIG_TRACE_IRQFLAGS
  102. mov.l 3f, r0
  103. jsr @r0
  104. nop
  105. #endif
  106. sti
  107. mov.l 2f, r0
  108. jsr @r0
  109. nop
  110. mov #0, r0
  111. mov.l r0, @(TI_PRE_COUNT,r8)
  112. cli
  113. #ifdef CONFIG_TRACE_IRQFLAGS
  114. mov.l 4f, r0
  115. jsr @r0
  116. nop
  117. #endif
  118. bra need_resched
  119. nop
  120. noresched:
  121. bra __restore_all
  122. nop
  123. .align 2
  124. 1: .long PREEMPT_ACTIVE
  125. 2: .long schedule
  126. #ifdef CONFIG_TRACE_IRQFLAGS
  127. 3: .long trace_hardirqs_on
  128. 4: .long trace_hardirqs_off
  129. #endif
  130. #endif
  131. ENTRY(resume_userspace)
  132. ! r8: current_thread_info
  133. cli
  134. #ifdef CONFIG_TRACE_IRQFLAGS
  135. mov.l 5f, r0
  136. jsr @r0
  137. nop
  138. #endif
  139. mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
  140. tst #_TIF_WORK_MASK, r0
  141. bt/s __restore_all
  142. tst #_TIF_NEED_RESCHED, r0
  143. .align 2
  144. work_pending:
  145. ! r0: current_thread_info->flags
  146. ! r8: current_thread_info
  147. ! t: result of "tst #_TIF_NEED_RESCHED, r0"
  148. bf/s work_resched
  149. tst #(_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK), r0
  150. work_notifysig:
  151. bt/s __restore_all
  152. mov r15, r4
  153. mov r12, r5 ! set arg1(save_r0)
  154. mov r0, r6
  155. mov.l 2f, r1
  156. mov.l 3f, r0
  157. jmp @r1
  158. lds r0, pr
  159. work_resched:
  160. mov.l 1f, r1
  161. jsr @r1 ! schedule
  162. nop
  163. cli
  164. #ifdef CONFIG_TRACE_IRQFLAGS
  165. mov.l 5f, r0
  166. jsr @r0
  167. nop
  168. #endif
  169. !
  170. mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
  171. tst #_TIF_WORK_MASK, r0
  172. bt __restore_all
  173. bra work_pending
  174. tst #_TIF_NEED_RESCHED, r0
  175. .align 2
  176. 1: .long schedule
  177. 2: .long do_notify_resume
  178. 3: .long resume_userspace
  179. #ifdef CONFIG_TRACE_IRQFLAGS
  180. 4: .long trace_hardirqs_on
  181. 5: .long trace_hardirqs_off
  182. #endif
  183. .align 2
  184. syscall_exit_work:
  185. ! r0: current_thread_info->flags
  186. ! r8: current_thread_info
  187. tst #_TIF_WORK_SYSCALL_MASK, r0
  188. bt/s work_pending
  189. tst #_TIF_NEED_RESCHED, r0
  190. #ifdef CONFIG_TRACE_IRQFLAGS
  191. mov.l 5f, r0
  192. jsr @r0
  193. nop
  194. #endif
  195. sti
  196. mov r15, r4
  197. mov.l 8f, r0 ! do_syscall_trace_leave
  198. jsr @r0
  199. nop
  200. bra resume_userspace
  201. nop
  202. .align 2
  203. syscall_trace_entry:
  204. ! Yes it is traced.
  205. mov r15, r4
  206. mov.l 7f, r11 ! Call do_syscall_trace_enter which notifies
  207. jsr @r11 ! superior (will chomp R[0-7])
  208. nop
  209. mov.l r0, @(OFF_R0,r15) ! Save return value
  210. ! Reload R0-R4 from kernel stack, where the
  211. ! parent may have modified them using
  212. ! ptrace(POKEUSR). (Note that R0-R2 are
  213. ! used by the system call handler directly
  214. ! from the kernel stack anyway, so don't need
  215. ! to be reloaded here.) This allows the parent
  216. ! to rewrite system calls and args on the fly.
  217. mov.l @(OFF_R4,r15), r4 ! arg0
  218. mov.l @(OFF_R5,r15), r5
  219. mov.l @(OFF_R6,r15), r6
  220. mov.l @(OFF_R7,r15), r7 ! arg3
  221. mov.l @(OFF_R3,r15), r3 ! syscall_nr
  222. !
  223. mov.l 2f, r10 ! Number of syscalls
  224. cmp/hs r10, r3
  225. bf syscall_call
  226. mov #-ENOSYS, r0
  227. bra syscall_exit
  228. mov.l r0, @(OFF_R0,r15) ! Return value
  229. __restore_all:
  230. mov.l 1f, r0
  231. jmp @r0
  232. nop
  233. .align 2
  234. 1: .long restore_all
  235. .align 2
  236. syscall_badsys: ! Bad syscall number
  237. get_current_thread_info r8, r0
  238. mov #-ENOSYS, r0
  239. bra resume_userspace
  240. mov.l r0, @(OFF_R0,r15) ! Return value
  241. /*
  242. * The main debug trap handler.
  243. *
  244. * r8=TRA (not the trap number!)
  245. *
  246. * Note: This assumes that the trapa value is left in its original
  247. * form (without the shlr2 shift) so the calculation for the jump
  248. * call table offset remains a simple in place mask.
  249. */
  250. debug_trap:
  251. mov r8, r0
  252. and #(0xf << 2), r0
  253. mov.l 1f, r8
  254. add r0, r8
  255. mov.l @r8, r8
  256. jsr @r8
  257. nop
  258. bra __restore_all
  259. nop
  260. .align 2
  261. 1: .long debug_trap_table
  262. /*
  263. * Syscall interface:
  264. *
  265. * Syscall #: R3
  266. * Arguments #0 to #3: R4--R7
  267. * Arguments #4 to #6: R0, R1, R2
  268. * TRA: (number of arguments + ABI revision) x 4
  269. *
  270. * This code also handles delegating other traps to the BIOS/gdb stub
  271. * according to:
  272. *
  273. * Trap number
  274. * (TRA>>2) Purpose
  275. * -------- -------
  276. * 0x00-0x0f original SH-3/4 syscall ABI (not in general use).
  277. * 0x10-0x1f general SH-3/4 syscall ABI.
  278. * 0x20-0x2f syscall ABI for SH-2 parts.
  279. * 0x30-0x3f debug traps used by the kernel.
  280. * 0x40-0xff Not supported by all parts, so left unhandled.
  281. *
  282. * Note: When we're first called, the TRA value must be shifted
  283. * right 2 bits in order to get the value that was used as the "trapa"
  284. * argument.
  285. */
  286. .align 2
  287. .globl ret_from_fork
  288. ret_from_fork:
  289. mov.l 1f, r8
  290. jsr @r8
  291. mov r0, r4
  292. bra syscall_exit
  293. nop
  294. .align 2
  295. 1: .long schedule_tail
  296. /*
  297. * The poorly named main trapa decode and dispatch routine, for
  298. * system calls and debug traps through their respective jump tables.
  299. */
  300. ENTRY(system_call)
  301. #if !defined(CONFIG_CPU_SH2)
  302. mov.l 1f, r9
  303. mov.l @r9, r8 ! Read from TRA (Trap Address) Register
  304. #endif
  305. /*
  306. * Check the trap type
  307. */
  308. mov #((0x20 << 2) - 1), r9
  309. cmp/hi r9, r8
  310. bt/s debug_trap ! it's a debug trap..
  311. mov #OFF_TRA, r9
  312. add r15, r9
  313. mov.l r8, @r9 ! set TRA value to tra
  314. #ifdef CONFIG_TRACE_IRQFLAGS
  315. mov.l 5f, r10
  316. jsr @r10
  317. nop
  318. #endif
  319. sti
  320. !
  321. get_current_thread_info r8, r10
  322. mov.l @(TI_FLAGS,r8), r8
  323. mov #_TIF_WORK_SYSCALL_MASK, r10
  324. tst r10, r8
  325. bf syscall_trace_entry
  326. !
  327. mov.l 2f, r8 ! Number of syscalls
  328. cmp/hs r8, r3
  329. bt syscall_badsys
  330. !
  331. syscall_call:
  332. shll2 r3 ! x4
  333. mov.l 3f, r8 ! Load the address of sys_call_table
  334. add r8, r3
  335. mov.l @r3, r8
  336. jsr @r8 ! jump to specific syscall handler
  337. nop
  338. mov.l @(OFF_R0,r15), r12 ! save r0
  339. mov.l r0, @(OFF_R0,r15) ! save the return value
  340. !
  341. syscall_exit:
  342. cli
  343. #ifdef CONFIG_TRACE_IRQFLAGS
  344. mov.l 6f, r0
  345. jsr @r0
  346. nop
  347. #endif
  348. !
  349. get_current_thread_info r8, r0
  350. mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
  351. tst #_TIF_ALLWORK_MASK, r0
  352. bf syscall_exit_work
  353. bra __restore_all
  354. nop
  355. .align 2
  356. #if !defined(CONFIG_CPU_SH2)
  357. 1: .long TRA
  358. #endif
  359. 2: .long NR_syscalls
  360. 3: .long sys_call_table
  361. #ifdef CONFIG_TRACE_IRQFLAGS
  362. 5: .long trace_hardirqs_on
  363. 6: .long trace_hardirqs_off
  364. #endif
  365. 7: .long do_syscall_trace_enter
  366. 8: .long do_syscall_trace_leave