entry.S 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /*
  2. * Common Low Level Interrupts/Traps/Exceptions(non-TLB) Handling for ARC
  3. * (included from entry-<isa>.S
  4. *
  5. * Copyright (C) 2014-15 Synopsys, Inc. (www.synopsys.com)
  6. * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. /*------------------------------------------------------------------
  13. * Function ABI
  14. *------------------------------------------------------------------
  15. *
  16. * Arguments r0 - r7
  17. * Caller Saved Registers r0 - r12
  18. * Callee Saved Registers r13- r25
  19. * Global Pointer (gp) r26
  20. * Frame Pointer (fp) r27
  21. * Stack Pointer (sp) r28
  22. * Branch link register (blink) r31
  23. *------------------------------------------------------------------
  24. */
  25. ;################### Special Sys Call Wrappers ##########################
  26. ENTRY(sys_clone_wrapper)
  27. SAVE_CALLEE_SAVED_USER
  28. bl @sys_clone
  29. DISCARD_CALLEE_SAVED_USER
  30. GET_CURR_THR_INFO_FLAGS r10
  31. btst r10, TIF_SYSCALL_TRACE
  32. bnz tracesys_exit
  33. b .Lret_from_system_call
  34. END(sys_clone_wrapper)
  35. ENTRY(ret_from_fork)
  36. ; when the forked child comes here from the __switch_to function
  37. ; r0 has the last task pointer.
  38. ; put last task in scheduler queue
  39. jl @schedule_tail
  40. ld r9, [sp, PT_status32]
  41. brne r9, 0, 1f
  42. jl.d [r14] ; kernel thread entry point
  43. mov r0, r13 ; (see PF_KTHREAD block in copy_thread)
  44. 1:
  45. ; Return to user space
  46. ; 1. Any forked task (Reach here via BRne above)
  47. ; 2. First ever init task (Reach here via return from JL above)
  48. ; This is the historic "kernel_execve" use-case, to return to init
  49. ; user mode, in a round about way since that is always done from
  50. ; a kernel thread which is executed via JL above but always returns
  51. ; out whenever kernel_execve (now inline do_fork()) is involved
  52. b ret_from_exception
  53. END(ret_from_fork)
  54. ;################### Non TLB Exception Handling #############################
  55. ; ---------------------------------------------
  56. ; Instruction Error Exception Handler
  57. ; ---------------------------------------------
  58. ENTRY(instr_service)
  59. EXCEPTION_PROLOGUE
  60. lr r0, [efa]
  61. mov r1, sp
  62. FAKE_RET_FROM_EXCPN
  63. bl do_insterror_or_kprobe
  64. b ret_from_exception
  65. END(instr_service)
  66. ; ---------------------------------------------
  67. ; Machine Check Exception Handler
  68. ; ---------------------------------------------
  69. ENTRY(EV_MachineCheck)
  70. EXCEPTION_PROLOGUE
  71. lr r2, [ecr]
  72. lr r0, [efa]
  73. mov r1, sp
  74. ; hardware auto-disables MMU, re-enable it to allow kernel vaddr
  75. ; access for say stack unwinding of modules for crash dumps
  76. lr r3, [ARC_REG_PID]
  77. or r3, r3, MMU_ENABLE
  78. sr r3, [ARC_REG_PID]
  79. lsr r3, r2, 8
  80. bmsk r3, r3, 7
  81. brne r3, ECR_C_MCHK_DUP_TLB, 1f
  82. bl do_tlb_overlap_fault
  83. b ret_from_exception
  84. 1:
  85. ; DEAD END: can't do much, display Regs and HALT
  86. SAVE_CALLEE_SAVED_USER
  87. GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
  88. st sp, [r10, THREAD_CALLEE_REG]
  89. j do_machine_check_fault
  90. END(EV_MachineCheck)
  91. ; ---------------------------------------------
  92. ; Privilege Violation Exception Handler
  93. ; ---------------------------------------------
  94. ENTRY(EV_PrivilegeV)
  95. EXCEPTION_PROLOGUE
  96. lr r0, [efa]
  97. mov r1, sp
  98. FAKE_RET_FROM_EXCPN
  99. bl do_privilege_fault
  100. b ret_from_exception
  101. END(EV_PrivilegeV)
  102. ; ---------------------------------------------
  103. ; Extension Instruction Exception Handler
  104. ; ---------------------------------------------
  105. ENTRY(EV_Extension)
  106. EXCEPTION_PROLOGUE
  107. lr r0, [efa]
  108. mov r1, sp
  109. FAKE_RET_FROM_EXCPN
  110. bl do_extension_fault
  111. b ret_from_exception
  112. END(EV_Extension)
  113. ;################ Trap Handling (Syscall, Breakpoint) ##################
  114. ; ---------------------------------------------
  115. ; syscall Tracing
  116. ; ---------------------------------------------
  117. tracesys:
  118. ; save EFA in case tracer wants the PC of traced task
  119. ; using ERET won't work since next-PC has already committed
  120. lr r12, [efa]
  121. GET_CURR_TASK_FIELD_PTR TASK_THREAD, r11
  122. st r12, [r11, THREAD_FAULT_ADDR] ; thread.fault_address
  123. ; PRE Sys Call Ptrace hook
  124. mov r0, sp ; pt_regs needed
  125. bl @syscall_trace_entry
  126. ; Tracing code now returns the syscall num (orig or modif)
  127. mov r8, r0
  128. ; Do the Sys Call as we normally would.
  129. ; Validate the Sys Call number
  130. cmp r8, NR_syscalls
  131. mov.hi r0, -ENOSYS
  132. bhi tracesys_exit
  133. ; Restore the sys-call args. Mere invocation of the hook abv could have
  134. ; clobbered them (since they are in scratch regs). The tracer could also
  135. ; have deliberately changed the syscall args: r0-r7
  136. ld r0, [sp, PT_r0]
  137. ld r1, [sp, PT_r1]
  138. ld r2, [sp, PT_r2]
  139. ld r3, [sp, PT_r3]
  140. ld r4, [sp, PT_r4]
  141. ld r5, [sp, PT_r5]
  142. ld r6, [sp, PT_r6]
  143. ld r7, [sp, PT_r7]
  144. ld.as r9, [sys_call_table, r8]
  145. jl [r9] ; Entry into Sys Call Handler
  146. tracesys_exit:
  147. st r0, [sp, PT_r0] ; sys call return value in pt_regs
  148. ;POST Sys Call Ptrace Hook
  149. bl @syscall_trace_exit
  150. b ret_from_exception ; NOT ret_from_system_call at is saves r0 which
  151. ; we'd done before calling post hook above
  152. ; ---------------------------------------------
  153. ; Breakpoint TRAP
  154. ; ---------------------------------------------
  155. trap_with_param:
  156. ; stop_pc info by gdb needs this info
  157. lr r0, [efa]
  158. mov r1, sp
  159. ; Now that we have read EFA, it is safe to do "fake" rtie
  160. ; and get out of CPU exception mode
  161. FAKE_RET_FROM_EXCPN
  162. ; Save callee regs in case gdb wants to have a look
  163. ; SP will grow up by size of CALLEE Reg-File
  164. ; NOTE: clobbers r12
  165. SAVE_CALLEE_SAVED_USER
  166. ; save location of saved Callee Regs @ thread_struct->pc
  167. GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
  168. st sp, [r10, THREAD_CALLEE_REG]
  169. ; Call the trap handler
  170. bl do_non_swi_trap
  171. ; unwind stack to discard Callee saved Regs
  172. DISCARD_CALLEE_SAVED_USER
  173. b ret_from_exception
  174. ; ---------------------------------------------
  175. ; syscall TRAP
  176. ; ABI: (r0-r7) upto 8 args, (r8) syscall number
  177. ; ---------------------------------------------
  178. ENTRY(EV_Trap)
  179. EXCEPTION_PROLOGUE
  180. ;============ TRAP 1 :breakpoints
  181. ; Check ECR for trap with arg (PROLOGUE ensures r9 has ECR)
  182. bmsk.f 0, r9, 7
  183. bnz trap_with_param
  184. ;============ TRAP (no param): syscall top level
  185. ; First return from Exception to pure K mode (Exception/IRQs renabled)
  186. FAKE_RET_FROM_EXCPN
  187. ; If syscall tracing ongoing, invoke pre-post-hooks
  188. GET_CURR_THR_INFO_FLAGS r10
  189. btst r10, TIF_SYSCALL_TRACE
  190. bnz tracesys ; this never comes back
  191. ;============ Normal syscall case
  192. ; syscall num shd not exceed the total system calls avail
  193. cmp r8, NR_syscalls
  194. mov.hi r0, -ENOSYS
  195. bhi .Lret_from_system_call
  196. ; Offset into the syscall_table and call handler
  197. ld.as r9,[sys_call_table, r8]
  198. jl [r9] ; Entry into Sys Call Handler
  199. .Lret_from_system_call:
  200. st r0, [sp, PT_r0] ; sys call return value in pt_regs
  201. ; fall through to ret_from_exception
  202. END(EV_Trap)
  203. ;############# Return from Intr/Excp/Trap (Linux Specifics) ##############
  204. ;
  205. ; If ret to user mode do we need to handle signals, schedule() et al.
  206. ENTRY(ret_from_exception)
  207. ; Pre-{IRQ,Trap,Exception} K/U mode from pt_regs->status32
  208. ld r8, [sp, PT_status32] ; returning to User/Kernel Mode
  209. bbit0 r8, STATUS_U_BIT, resume_kernel_mode
  210. ; Before returning to User mode check-for-and-complete any pending work
  211. ; such as rescheduling/signal-delivery etc.
  212. resume_user_mode_begin:
  213. ; Disable IRQs to ensures that chk for pending work itself is atomic
  214. ; (and we don't end up missing a NEED_RESCHED/SIGPENDING due to an
  215. ; interim IRQ).
  216. IRQ_DISABLE r10
  217. ; Fast Path return to user mode if no pending work
  218. GET_CURR_THR_INFO_FLAGS r9
  219. and.f 0, r9, _TIF_WORK_MASK
  220. bz .Lrestore_regs
  221. ; --- (Slow Path #1) task preemption ---
  222. bbit0 r9, TIF_NEED_RESCHED, .Lchk_pend_signals
  223. mov blink, resume_user_mode_begin ; tail-call to U mode ret chks
  224. j @schedule ; BTST+Bnz causes relo error in link
  225. .Lchk_pend_signals:
  226. IRQ_ENABLE r10
  227. ; --- (Slow Path #2) pending signal ---
  228. mov r0, sp ; pt_regs for arg to do_signal()/do_notify_resume()
  229. GET_CURR_THR_INFO_FLAGS r9
  230. bbit0 r9, TIF_SIGPENDING, .Lchk_notify_resume
  231. ; Normal Trap/IRQ entry only saves Scratch (caller-saved) regs
  232. ; in pt_reg since the "C" ABI (kernel code) will automatically
  233. ; save/restore callee-saved regs.
  234. ;
  235. ; However, here we need to explicitly save callee regs because
  236. ; (i) If this signal causes coredump - full regfile needed
  237. ; (ii) If signal is SIGTRAP/SIGSTOP, task is being traced thus
  238. ; tracer might call PEEKUSR(CALLEE reg)
  239. ;
  240. ; NOTE: SP will grow up by size of CALLEE Reg-File
  241. SAVE_CALLEE_SAVED_USER ; clobbers r12
  242. ; save location of saved Callee Regs @ thread_struct->callee
  243. GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
  244. st sp, [r10, THREAD_CALLEE_REG]
  245. bl @do_signal
  246. ; Ideally we want to discard the Callee reg above, however if this was
  247. ; a tracing signal, tracer could have done a POKEUSR(CALLEE reg)
  248. RESTORE_CALLEE_SAVED_USER
  249. b resume_user_mode_begin ; loop back to start of U mode ret
  250. ; --- (Slow Path #3) notify_resume ---
  251. .Lchk_notify_resume:
  252. btst r9, TIF_NOTIFY_RESUME
  253. blnz @do_notify_resume
  254. b resume_user_mode_begin ; unconditionally back to U mode ret chks
  255. ; for single exit point from this block
  256. resume_kernel_mode:
  257. ; Disable Interrupts from this point on
  258. ; CONFIG_PREEMPT: This is a must for preempt_schedule_irq()
  259. ; !CONFIG_PREEMPT: To ensure restore_regs is intr safe
  260. IRQ_DISABLE r9
  261. #ifdef CONFIG_PREEMPT
  262. ; Can't preempt if preemption disabled
  263. GET_CURR_THR_INFO_FROM_SP r10
  264. ld r8, [r10, THREAD_INFO_PREEMPT_COUNT]
  265. brne r8, 0, .Lrestore_regs
  266. ; check if this task's NEED_RESCHED flag set
  267. ld r9, [r10, THREAD_INFO_FLAGS]
  268. bbit0 r9, TIF_NEED_RESCHED, .Lrestore_regs
  269. ; Invoke PREEMPTION
  270. jl preempt_schedule_irq
  271. ; preempt_schedule_irq() always returns with IRQ disabled
  272. #endif
  273. b .Lrestore_regs
  274. ##### DONT ADD CODE HERE - .Lrestore_regs actually follows in entry-<isa>.S