entry-common.S 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  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 restore_all
  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_SYSCALL_TRACE | _TIF_SINGLESTEP | _TIF_SYSCALL_AUDIT, 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. ! XXX setup arguments...
  197. mov r15, r4
  198. mov #1, r5
  199. mov.l 4f, r0 ! do_syscall_trace
  200. jsr @r0
  201. nop
  202. bra resume_userspace
  203. nop
  204. .align 2
  205. syscall_trace_entry:
  206. ! Yes it is traced.
  207. ! XXX setup arguments...
  208. mov r15, r4
  209. mov #0, r5
  210. mov.l 4f, r11 ! Call do_syscall_trace which notifies
  211. jsr @r11 ! superior (will chomp R[0-7])
  212. nop
  213. ! Reload R0-R4 from kernel stack, where the
  214. ! parent may have modified them using
  215. ! ptrace(POKEUSR). (Note that R0-R2 are
  216. ! used by the system call handler directly
  217. ! from the kernel stack anyway, so don't need
  218. ! to be reloaded here.) This allows the parent
  219. ! to rewrite system calls and args on the fly.
  220. mov.l @(OFF_R4,r15), r4 ! arg0
  221. mov.l @(OFF_R5,r15), r5
  222. mov.l @(OFF_R6,r15), r6
  223. mov.l @(OFF_R7,r15), r7 ! arg3
  224. mov.l @(OFF_R3,r15), r3 ! syscall_nr
  225. !
  226. mov.l 2f, r10 ! Number of syscalls
  227. cmp/hs r10, r3
  228. bf syscall_call
  229. mov #-ENOSYS, r0
  230. bra syscall_exit
  231. mov.l r0, @(OFF_R0,r15) ! Return value
  232. __restore_all:
  233. mov.l 1f, r0
  234. jmp @r0
  235. nop
  236. .align 2
  237. 1: .long restore_all
  238. .align 2
  239. syscall_badsys: ! Bad syscall number
  240. get_current_thread_info r8, r0
  241. mov #-ENOSYS, r0
  242. bra resume_userspace
  243. mov.l r0, @(OFF_R0,r15) ! Return value
  244. /*
  245. * The main debug trap handler.
  246. *
  247. * r8=TRA (not the trap number!)
  248. *
  249. * Note: This assumes that the trapa value is left in its original
  250. * form (without the shlr2 shift) so the calculation for the jump
  251. * call table offset remains a simple in place mask.
  252. */
  253. debug_trap:
  254. mov r8, r0
  255. and #(0xf << 2), r0
  256. mov.l 1f, r8
  257. add r0, r8
  258. mov.l @r8, r8
  259. jsr @r8
  260. nop
  261. bra __restore_all
  262. nop
  263. .align 2
  264. 1: .long debug_trap_table
  265. /*
  266. * Syscall interface:
  267. *
  268. * Syscall #: R3
  269. * Arguments #0 to #3: R4--R7
  270. * Arguments #4 to #6: R0, R1, R2
  271. * TRA: (number of arguments + ABI revision) x 4
  272. *
  273. * This code also handles delegating other traps to the BIOS/gdb stub
  274. * according to:
  275. *
  276. * Trap number
  277. * (TRA>>2) Purpose
  278. * -------- -------
  279. * 0x00-0x0f original SH-3/4 syscall ABI (not in general use).
  280. * 0x10-0x1f general SH-3/4 syscall ABI.
  281. * 0x20-0x2f syscall ABI for SH-2 parts.
  282. * 0x30-0x3f debug traps used by the kernel.
  283. * 0x40-0xff Not supported by all parts, so left unhandled.
  284. *
  285. * Note: When we're first called, the TRA value must be shifted
  286. * right 2 bits in order to get the value that was used as the "trapa"
  287. * argument.
  288. */
  289. .align 2
  290. .globl ret_from_fork
  291. ret_from_fork:
  292. mov.l 1f, r8
  293. jsr @r8
  294. mov r0, r4
  295. bra syscall_exit
  296. nop
  297. .align 2
  298. 1: .long schedule_tail
  299. /*
  300. * The poorly named main trapa decode and dispatch routine, for
  301. * system calls and debug traps through their respective jump tables.
  302. */
  303. ENTRY(system_call)
  304. #if !defined(CONFIG_CPU_SH2)
  305. mov.l 1f, r9
  306. mov.l @r9, r8 ! Read from TRA (Trap Address) Register
  307. #endif
  308. /*
  309. * Check the trap type
  310. */
  311. mov #((0x20 << 2) - 1), r9
  312. cmp/hi r9, r8
  313. bt/s debug_trap ! it's a debug trap..
  314. mov #OFF_TRA, r9
  315. add r15, r9
  316. mov.l r8, @r9 ! set TRA value to tra
  317. #ifdef CONFIG_TRACE_IRQFLAGS
  318. mov.l 5f, r10
  319. jsr @r10
  320. nop
  321. #endif
  322. sti
  323. !
  324. get_current_thread_info r8, r10
  325. mov.l @(TI_FLAGS,r8), r8
  326. mov #(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT), r10
  327. tst r10, r8
  328. bf syscall_trace_entry
  329. !
  330. mov.l 2f, r8 ! Number of syscalls
  331. cmp/hs r8, r3
  332. bt syscall_badsys
  333. !
  334. syscall_call:
  335. shll2 r3 ! x4
  336. mov.l 3f, r8 ! Load the address of sys_call_table
  337. add r8, r3
  338. mov.l @r3, r8
  339. jsr @r8 ! jump to specific syscall handler
  340. nop
  341. mov.l @(OFF_R0,r15), r12 ! save r0
  342. mov.l r0, @(OFF_R0,r15) ! save the return value
  343. !
  344. syscall_exit:
  345. cli
  346. #ifdef CONFIG_TRACE_IRQFLAGS
  347. mov.l 6f, r0
  348. jsr @r0
  349. nop
  350. #endif
  351. !
  352. get_current_thread_info r8, r0
  353. mov.l @(TI_FLAGS,r8), r0 ! current_thread_info->flags
  354. tst #_TIF_ALLWORK_MASK, r0
  355. bf syscall_exit_work
  356. bra __restore_all
  357. nop
  358. .align 2
  359. #if !defined(CONFIG_CPU_SH2)
  360. 1: .long TRA
  361. #endif
  362. 2: .long NR_syscalls
  363. 3: .long sys_call_table
  364. 4: .long do_syscall_trace
  365. #ifdef CONFIG_TRACE_IRQFLAGS
  366. 5: .long trace_hardirqs_on
  367. 6: .long trace_hardirqs_off
  368. #endif