entry-common.S 8.2 KB

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