entry.S 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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 ret_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. #ifdef CONFIG_ARC_DW2_UNWIND
  55. ; Workaround for bug 94179 (STAR ):
  56. ; Despite -fasynchronous-unwind-tables, linker is not making dwarf2 unwinder
  57. ; section (.debug_frame) as loadable. So we force it here.
  58. ; This also fixes STAR 9000487933 where the prev-workaround (objcopy --setflag)
  59. ; would not work after a clean build due to kernel build system dependencies.
  60. .section .debug_frame, "wa",@progbits
  61. ; Reset to .text as this file is included in entry-<isa>.S
  62. .section .text, "ax",@progbits
  63. #endif
  64. ;################### Non TLB Exception Handling #############################
  65. ; ---------------------------------------------
  66. ; Instruction Error Exception Handler
  67. ; ---------------------------------------------
  68. ENTRY(instr_service)
  69. EXCEPTION_PROLOGUE
  70. lr r0, [efa]
  71. mov r1, sp
  72. FAKE_RET_FROM_EXCPN
  73. bl do_insterror_or_kprobe
  74. b ret_from_exception
  75. END(instr_service)
  76. ; ---------------------------------------------
  77. ; Machine Check Exception Handler
  78. ; ---------------------------------------------
  79. ENTRY(EV_MachineCheck)
  80. EXCEPTION_PROLOGUE
  81. lr r2, [ecr]
  82. lr r0, [efa]
  83. mov r1, sp
  84. ; hardware auto-disables MMU, re-enable it to allow kernel vaddr
  85. ; access for say stack unwinding of modules for crash dumps
  86. lr r3, [ARC_REG_PID]
  87. or r3, r3, MMU_ENABLE
  88. sr r3, [ARC_REG_PID]
  89. lsr r3, r2, 8
  90. bmsk r3, r3, 7
  91. brne r3, ECR_C_MCHK_DUP_TLB, 1f
  92. bl do_tlb_overlap_fault
  93. b ret_from_exception
  94. 1:
  95. ; DEAD END: can't do much, display Regs and HALT
  96. SAVE_CALLEE_SAVED_USER
  97. GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
  98. st sp, [r10, THREAD_CALLEE_REG]
  99. j do_machine_check_fault
  100. END(EV_MachineCheck)
  101. ; ---------------------------------------------
  102. ; Privilege Violation Exception Handler
  103. ; ---------------------------------------------
  104. ENTRY(EV_PrivilegeV)
  105. EXCEPTION_PROLOGUE
  106. lr r0, [efa]
  107. mov r1, sp
  108. FAKE_RET_FROM_EXCPN
  109. bl do_privilege_fault
  110. b ret_from_exception
  111. END(EV_PrivilegeV)
  112. ; ---------------------------------------------
  113. ; Extension Instruction Exception Handler
  114. ; ---------------------------------------------
  115. ENTRY(EV_Extension)
  116. EXCEPTION_PROLOGUE
  117. lr r0, [efa]
  118. mov r1, sp
  119. FAKE_RET_FROM_EXCPN
  120. bl do_extension_fault
  121. b ret_from_exception
  122. END(EV_Extension)
  123. ;################ Trap Handling (Syscall, Breakpoint) ##################
  124. ; ---------------------------------------------
  125. ; syscall Tracing
  126. ; ---------------------------------------------
  127. tracesys:
  128. ; save EFA in case tracer wants the PC of traced task
  129. ; using ERET won't work since next-PC has already committed
  130. lr r12, [efa]
  131. GET_CURR_TASK_FIELD_PTR TASK_THREAD, r11
  132. st r12, [r11, THREAD_FAULT_ADDR] ; thread.fault_address
  133. ; PRE Sys Call Ptrace hook
  134. mov r0, sp ; pt_regs needed
  135. bl @syscall_trace_entry
  136. ; Tracing code now returns the syscall num (orig or modif)
  137. mov r8, r0
  138. ; Do the Sys Call as we normally would.
  139. ; Validate the Sys Call number
  140. cmp r8, NR_syscalls
  141. mov.hi r0, -ENOSYS
  142. bhi tracesys_exit
  143. ; Restore the sys-call args. Mere invocation of the hook abv could have
  144. ; clobbered them (since they are in scratch regs). The tracer could also
  145. ; have deliberately changed the syscall args: r0-r7
  146. ld r0, [sp, PT_r0]
  147. ld r1, [sp, PT_r1]
  148. ld r2, [sp, PT_r2]
  149. ld r3, [sp, PT_r3]
  150. ld r4, [sp, PT_r4]
  151. ld r5, [sp, PT_r5]
  152. ld r6, [sp, PT_r6]
  153. ld r7, [sp, PT_r7]
  154. ld.as r9, [sys_call_table, r8]
  155. jl [r9] ; Entry into Sys Call Handler
  156. tracesys_exit:
  157. st r0, [sp, PT_r0] ; sys call return value in pt_regs
  158. ;POST Sys Call Ptrace Hook
  159. bl @syscall_trace_exit
  160. b ret_from_exception ; NOT ret_from_system_call at is saves r0 which
  161. ; we'd done before calling post hook above
  162. ; ---------------------------------------------
  163. ; Breakpoint TRAP
  164. ; ---------------------------------------------
  165. trap_with_param:
  166. ; stop_pc info by gdb needs this info
  167. lr r0, [efa]
  168. mov r1, sp
  169. ; Now that we have read EFA, it is safe to do "fake" rtie
  170. ; and get out of CPU exception mode
  171. FAKE_RET_FROM_EXCPN
  172. ; Save callee regs in case gdb wants to have a look
  173. ; SP will grow up by size of CALLEE Reg-File
  174. ; NOTE: clobbers r12
  175. SAVE_CALLEE_SAVED_USER
  176. ; save location of saved Callee Regs @ thread_struct->pc
  177. GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
  178. st sp, [r10, THREAD_CALLEE_REG]
  179. ; Call the trap handler
  180. bl do_non_swi_trap
  181. ; unwind stack to discard Callee saved Regs
  182. DISCARD_CALLEE_SAVED_USER
  183. b ret_from_exception
  184. ; ---------------------------------------------
  185. ; syscall TRAP
  186. ; ABI: (r0-r7) upto 8 args, (r8) syscall number
  187. ; ---------------------------------------------
  188. ENTRY(EV_Trap)
  189. EXCEPTION_PROLOGUE
  190. ;============ TRAP 1 :breakpoints
  191. ; Check ECR for trap with arg (PROLOGUE ensures r9 has ECR)
  192. bmsk.f 0, r9, 7
  193. bnz trap_with_param
  194. ;============ TRAP (no param): syscall top level
  195. ; First return from Exception to pure K mode (Exception/IRQs renabled)
  196. FAKE_RET_FROM_EXCPN
  197. ; If syscall tracing ongoing, invoke pre-post-hooks
  198. GET_CURR_THR_INFO_FLAGS r10
  199. btst r10, TIF_SYSCALL_TRACE
  200. bnz tracesys ; this never comes back
  201. ;============ Normal syscall case
  202. ; syscall num shd not exceed the total system calls avail
  203. cmp r8, NR_syscalls
  204. mov.hi r0, -ENOSYS
  205. bhi ret_from_system_call
  206. ; Offset into the syscall_table and call handler
  207. ld.as r9,[sys_call_table, r8]
  208. jl [r9] ; Entry into Sys Call Handler
  209. ; fall through to ret_from_system_call
  210. END(EV_Trap)
  211. ENTRY(ret_from_system_call)
  212. st r0, [sp, PT_r0] ; sys call return value in pt_regs
  213. ; fall through yet again to ret_from_exception
  214. ;############# Return from Intr/Excp/Trap (Linux Specifics) ##############
  215. ;
  216. ; If ret to user mode do we need to handle signals, schedule() et al.
  217. ENTRY(ret_from_exception)
  218. ; Pre-{IRQ,Trap,Exception} K/U mode from pt_regs->status32
  219. ld r8, [sp, PT_status32] ; returning to User/Kernel Mode
  220. bbit0 r8, STATUS_U_BIT, resume_kernel_mode
  221. ; Before returning to User mode check-for-and-complete any pending work
  222. ; such as rescheduling/signal-delivery etc.
  223. resume_user_mode_begin:
  224. ; Disable IRQs to ensures that chk for pending work itself is atomic
  225. ; (and we don't end up missing a NEED_RESCHED/SIGPENDING due to an
  226. ; interim IRQ).
  227. IRQ_DISABLE r10
  228. ; Fast Path return to user mode if no pending work
  229. GET_CURR_THR_INFO_FLAGS r9
  230. and.f 0, r9, _TIF_WORK_MASK
  231. bz .Lrestore_regs
  232. ; --- (Slow Path #1) task preemption ---
  233. bbit0 r9, TIF_NEED_RESCHED, .Lchk_pend_signals
  234. mov blink, resume_user_mode_begin ; tail-call to U mode ret chks
  235. j @schedule ; BTST+Bnz causes relo error in link
  236. .Lchk_pend_signals:
  237. IRQ_ENABLE r10
  238. ; --- (Slow Path #2) pending signal ---
  239. mov r0, sp ; pt_regs for arg to do_signal()/do_notify_resume()
  240. GET_CURR_THR_INFO_FLAGS r9
  241. bbit0 r9, TIF_SIGPENDING, .Lchk_notify_resume
  242. ; Normal Trap/IRQ entry only saves Scratch (caller-saved) regs
  243. ; in pt_reg since the "C" ABI (kernel code) will automatically
  244. ; save/restore callee-saved regs.
  245. ;
  246. ; However, here we need to explicitly save callee regs because
  247. ; (i) If this signal causes coredump - full regfile needed
  248. ; (ii) If signal is SIGTRAP/SIGSTOP, task is being traced thus
  249. ; tracer might call PEEKUSR(CALLEE reg)
  250. ;
  251. ; NOTE: SP will grow up by size of CALLEE Reg-File
  252. SAVE_CALLEE_SAVED_USER ; clobbers r12
  253. ; save location of saved Callee Regs @ thread_struct->callee
  254. GET_CURR_TASK_FIELD_PTR TASK_THREAD, r10
  255. st sp, [r10, THREAD_CALLEE_REG]
  256. bl @do_signal
  257. ; Ideally we want to discard the Callee reg above, however if this was
  258. ; a tracing signal, tracer could have done a POKEUSR(CALLEE reg)
  259. RESTORE_CALLEE_SAVED_USER
  260. b resume_user_mode_begin ; loop back to start of U mode ret
  261. ; --- (Slow Path #3) notify_resume ---
  262. .Lchk_notify_resume:
  263. btst r9, TIF_NOTIFY_RESUME
  264. blnz @do_notify_resume
  265. b resume_user_mode_begin ; unconditionally back to U mode ret chks
  266. ; for single exit point from this block
  267. resume_kernel_mode:
  268. ; Disable Interrupts from this point on
  269. ; CONFIG_PREEMPT: This is a must for preempt_schedule_irq()
  270. ; !CONFIG_PREEMPT: To ensure restore_regs is intr safe
  271. IRQ_DISABLE r9
  272. #ifdef CONFIG_PREEMPT
  273. ; Can't preempt if preemption disabled
  274. GET_CURR_THR_INFO_FROM_SP r10
  275. ld r8, [r10, THREAD_INFO_PREEMPT_COUNT]
  276. brne r8, 0, .Lrestore_regs
  277. ; check if this task's NEED_RESCHED flag set
  278. ld r9, [r10, THREAD_INFO_FLAGS]
  279. bbit0 r9, TIF_NEED_RESCHED, .Lrestore_regs
  280. ; Invoke PREEMPTION
  281. jl preempt_schedule_irq
  282. ; preempt_schedule_irq() always returns with IRQ disabled
  283. #endif
  284. b .Lrestore_regs
  285. ##### DONT ADD CODE HERE - .Lrestore_regs actually follows in entry-<isa>.S