entry.S 10 KB

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