entry.S 11 KB

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