entry-common.S 8.5 KB

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