entry-compact.S 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Low Level Interrupts/Traps/Exceptions(non-TLB) Handling for ARCompact ISA
  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. * vineetg: May 2011
  9. * -Userspace unaligned access emulation
  10. *
  11. * vineetg: Feb 2011 (ptrace low level code fixes)
  12. * -traced syscall return code (r0) was not saved into pt_regs for restoring
  13. * into user reg-file when traded task rets to user space.
  14. * -syscalls needing arch-wrappers (mainly for passing sp as pt_regs)
  15. * were not invoking post-syscall trace hook (jumping directly into
  16. * ret_from_system_call)
  17. *
  18. * vineetg: Nov 2010:
  19. * -Vector table jumps (@8 bytes) converted into branches (@4 bytes)
  20. * -To maintain the slot size of 8 bytes/vector, added nop, which is
  21. * not executed at runtime.
  22. *
  23. * vineetg: Nov 2009 (Everything needed for TIF_RESTORE_SIGMASK)
  24. * -do_signal()invoked upon TIF_RESTORE_SIGMASK as well
  25. * -Wrappers for sys_{,rt_}sigsuspend() no longer needed as they don't
  26. * need ptregs anymore
  27. *
  28. * Vineetg: Oct 2009
  29. * -In a rare scenario, Process gets a Priv-V exception and gets scheduled
  30. * out. Since we don't do FAKE RTIE for Priv-V, CPU exception state remains
  31. * active (AE bit enabled). This causes a double fault for a subseq valid
  32. * exception. Thus FAKE RTIE needed in low level Priv-Violation handler.
  33. * Instr Error could also cause similar scenario, so same there as well.
  34. *
  35. * Vineetg: March 2009 (Supporting 2 levels of Interrupts)
  36. *
  37. * Vineetg: Aug 28th 2008: Bug #94984
  38. * -Zero Overhead Loop Context shd be cleared when entering IRQ/EXcp/Trap
  39. * Normally CPU does this automatically, however when doing FAKE rtie,
  40. * we need to explicitly do this. The problem in macros
  41. * FAKE_RET_FROM_EXCPN and FAKE_RET_FROM_EXCPN_LOCK_IRQ was that this bit
  42. * was being "CLEARED" rather then "SET". Since it is Loop INHIBIT Bit,
  43. * setting it and not clearing it clears ZOL context
  44. *
  45. * Vineetg: May 16th, 2008
  46. * - r25 now contains the Current Task when in kernel
  47. *
  48. * Vineetg: Dec 22, 2007
  49. * Minor Surgery of Low Level ISR to make it SMP safe
  50. * - MMU_SCRATCH0 Reg used for freeing up r9 in Level 1 ISR
  51. * - _current_task is made an array of NR_CPUS
  52. * - Access of _current_task wrapped inside a macro so that if hardware
  53. * team agrees for a dedicated reg, no other code is touched
  54. *
  55. * Amit Bhor, Rahul Trivedi, Kanika Nema, Sameer Dhavale : Codito Tech 2004
  56. */
  57. #include <linux/errno.h>
  58. #include <linux/linkage.h> /* {ENTRY,EXIT} */
  59. #include <asm/entry.h>
  60. #include <asm/irqflags.h>
  61. .cpu A7
  62. ;############################ Vector Table #################################
  63. .macro VECTOR lbl
  64. #if 1 /* Just in case, build breaks */
  65. j \lbl
  66. #else
  67. b \lbl
  68. nop
  69. #endif
  70. .endm
  71. .section .vector, "ax",@progbits
  72. .align 4
  73. /* Each entry in the vector table must occupy 2 words. Since it is a jump
  74. * across sections (.vector to .text) we are guaranteed that 'j somewhere'
  75. * will use the 'j limm' form of the instruction as long as somewhere is in
  76. * a section other than .vector.
  77. */
  78. ; ********* Critical System Events **********************
  79. VECTOR res_service ; 0x0, Reset Vector (0x0)
  80. VECTOR mem_service ; 0x8, Mem exception (0x1)
  81. VECTOR instr_service ; 0x10, Instrn Error (0x2)
  82. ; ******************** Device ISRs **********************
  83. #ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS
  84. VECTOR handle_interrupt_level2
  85. #else
  86. VECTOR handle_interrupt_level1
  87. #endif
  88. .rept 28
  89. VECTOR handle_interrupt_level1 ; Other devices
  90. .endr
  91. /* FOR ARC600: timer = 0x3, uart = 0x8, emac = 0x10 */
  92. ; ******************** Exceptions **********************
  93. VECTOR EV_MachineCheck ; 0x100, Fatal Machine check (0x20)
  94. VECTOR EV_TLBMissI ; 0x108, Instruction TLB miss (0x21)
  95. VECTOR EV_TLBMissD ; 0x110, Data TLB miss (0x22)
  96. VECTOR EV_TLBProtV ; 0x118, Protection Violation (0x23)
  97. ; or Misaligned Access
  98. VECTOR EV_PrivilegeV ; 0x120, Privilege Violation (0x24)
  99. VECTOR EV_Trap ; 0x128, Trap exception (0x25)
  100. VECTOR EV_Extension ; 0x130, Extn Instruction Excp (0x26)
  101. .rept 24
  102. VECTOR reserved ; Reserved Exceptions
  103. .endr
  104. ;##################### Scratch Mem for IRQ stack switching #############
  105. ARCFP_DATA int1_saved_reg
  106. .align 32
  107. .type int1_saved_reg, @object
  108. .size int1_saved_reg, 4
  109. int1_saved_reg:
  110. .zero 4
  111. /* Each Interrupt level needs its own scratch */
  112. ARCFP_DATA int2_saved_reg
  113. .type int2_saved_reg, @object
  114. .size int2_saved_reg, 4
  115. int2_saved_reg:
  116. .zero 4
  117. ; ---------------------------------------------
  118. .section .text, "ax",@progbits
  119. reserved:
  120. flag 1 ; Unexpected event, halt
  121. ;##################### Interrupt Handling ##############################
  122. #ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS
  123. ; ---------------------------------------------
  124. ; Level 2 ISR: Can interrupt a Level 1 ISR
  125. ; ---------------------------------------------
  126. ENTRY(handle_interrupt_level2)
  127. INTERRUPT_PROLOGUE 2
  128. ;------------------------------------------------------
  129. ; if L2 IRQ interrupted a L1 ISR, disable preemption
  130. ;
  131. ; This is to avoid a potential L1-L2-L1 scenario
  132. ; -L1 IRQ taken
  133. ; -L2 interrupts L1 (before L1 ISR could run)
  134. ; -preemption off IRQ, user task in syscall picked to run
  135. ; -RTIE to userspace
  136. ; Returns from L2 context fine
  137. ; But both L1 and L2 re-enabled, so another L1 can be taken
  138. ; while prev L1 is still unserviced
  139. ;
  140. ;------------------------------------------------------
  141. ; L2 interrupting L1 implies both L2 and L1 active
  142. ; However both A2 and A1 are NOT set in STATUS32, thus
  143. ; need to check STATUS32_L2 to determine if L1 was active
  144. ld r9, [sp, PT_status32] ; get statu32_l2 (saved in pt_regs)
  145. bbit0 r9, STATUS_A1_BIT, 1f ; L1 not active when L2 IRQ, so normal
  146. ; bump thread_info->preempt_count (Disable preemption)
  147. GET_CURR_THR_INFO_FROM_SP r10
  148. ld r9, [r10, THREAD_INFO_PREEMPT_COUNT]
  149. add r9, r9, 1
  150. st r9, [r10, THREAD_INFO_PREEMPT_COUNT]
  151. 1:
  152. ;------------------------------------------------------
  153. ; setup params for Linux common ISR and invoke it
  154. ;------------------------------------------------------
  155. lr r0, [icause2]
  156. and r0, r0, 0x1f
  157. bl.d @arch_do_IRQ
  158. mov r1, sp
  159. mov r8,0x2
  160. sr r8, [AUX_IRQ_LV12] ; clear bit in Sticky Status Reg
  161. b ret_from_exception
  162. END(handle_interrupt_level2)
  163. #endif
  164. ; ---------------------------------------------
  165. ; User Mode Memory Bus Error Interrupt Handler
  166. ; (Kernel mode memory errors handled via separate exception vectors)
  167. ; ---------------------------------------------
  168. ENTRY(mem_service)
  169. INTERRUPT_PROLOGUE 2
  170. mov r0, ilink2
  171. mov r1, sp
  172. ; User process needs to be killed with SIGBUS, but first need to get
  173. ; out of the L2 interrupt context (drop to pure kernel mode) and jump
  174. ; off to "C" code where SIGBUS in enqueued
  175. lr r3, [status32]
  176. bclr r3, r3, STATUS_A2_BIT
  177. or r3, r3, (STATUS_E1_MASK|STATUS_E2_MASK)
  178. sr r3, [status32_l2]
  179. mov ilink2, 1f
  180. rtie
  181. 1:
  182. bl do_memory_error
  183. b ret_from_exception
  184. END(mem_service)
  185. ; ---------------------------------------------
  186. ; Level 1 ISR
  187. ; ---------------------------------------------
  188. ENTRY(handle_interrupt_level1)
  189. INTERRUPT_PROLOGUE 1
  190. lr r0, [icause1]
  191. and r0, r0, 0x1f
  192. #ifdef CONFIG_TRACE_IRQFLAGS
  193. ; icause1 needs to be read early, before calling tracing, which
  194. ; can clobber scratch regs, hence use of stack to stash it
  195. push r0
  196. TRACE_ASM_IRQ_DISABLE
  197. pop r0
  198. #endif
  199. bl.d @arch_do_IRQ
  200. mov r1, sp
  201. mov r8,0x1
  202. sr r8, [AUX_IRQ_LV12] ; clear bit in Sticky Status Reg
  203. b ret_from_exception
  204. END(handle_interrupt_level1)
  205. ;################### Non TLB Exception Handling #############################
  206. ; ---------------------------------------------
  207. ; Protection Violation Exception Handler
  208. ; ---------------------------------------------
  209. ENTRY(EV_TLBProtV)
  210. EXCEPTION_PROLOGUE
  211. mov r2, r10 ; ECR set into r10 already
  212. lr r0, [efa] ; Faulting Data address (not part of pt_regs saved above)
  213. ; Exception auto-disables further Intr/exceptions.
  214. ; Re-enable them by pretending to return from exception
  215. ; (so rest of handler executes in pure K mode)
  216. FAKE_RET_FROM_EXCPN
  217. mov r1, sp ; Handle to pt_regs
  218. ;------ (5) Type of Protection Violation? ----------
  219. ;
  220. ; ProtV Hardware Exception is triggered for Access Faults of 2 types
  221. ; -Access Violation : 00_23_(00|01|02|03)_00
  222. ; x r w r+w
  223. ; -Unaligned Access : 00_23_04_00
  224. ;
  225. bbit1 r2, ECR_C_BIT_PROTV_MISALIG_DATA, 4f
  226. ;========= (6a) Access Violation Processing ========
  227. bl do_page_fault
  228. b ret_from_exception
  229. ;========== (6b) Non aligned access ============
  230. 4:
  231. SAVE_CALLEE_SAVED_USER
  232. mov r2, sp ; callee_regs
  233. bl do_misaligned_access
  234. ; TBD: optimize - do this only if a callee reg was involved
  235. ; either a dst of emulated LD/ST or src with address-writeback
  236. RESTORE_CALLEE_SAVED_USER
  237. b ret_from_exception
  238. END(EV_TLBProtV)
  239. ; Wrapper for Linux page fault handler called from EV_TLBMiss*
  240. ; Very similar to ProtV handler case (6a) above, but avoids the extra checks
  241. ; for Misaligned access
  242. ;
  243. ENTRY(call_do_page_fault)
  244. EXCEPTION_PROLOGUE
  245. lr r0, [efa] ; Faulting Data address
  246. mov r1, sp
  247. FAKE_RET_FROM_EXCPN
  248. mov blink, ret_from_exception
  249. b do_page_fault
  250. END(call_do_page_fault)
  251. ;############# Common Handlers for ARCompact and ARCv2 ##############
  252. #include "entry.S"
  253. ;############# Return from Intr/Excp/Trap (ARC Specifics) ##############
  254. ;
  255. ; Restore the saved sys context (common exit-path for EXCPN/IRQ/Trap)
  256. ; IRQ shd definitely not happen between now and rtie
  257. ; All 2 entry points to here already disable interrupts
  258. .Lrestore_regs:
  259. # Interrupts are actually disabled from this point on, but will get
  260. # reenabled after we return from interrupt/exception.
  261. # But irq tracer needs to be told now...
  262. TRACE_ASM_IRQ_ENABLE
  263. lr r10, [status32]
  264. ; Restore REG File. In case multiple Events outstanding,
  265. ; use the same priority as rtie: EXCPN, L2 IRQ, L1 IRQ, None
  266. ; Note that we use realtime STATUS32 (not pt_regs->status32) to
  267. ; decide that.
  268. and.f 0, r10, (STATUS_A1_MASK|STATUS_A2_MASK)
  269. bz .Lexcep_or_pure_K_ret
  270. ; Returning from Interrupts (Level 1 or 2)
  271. #ifdef CONFIG_ARC_COMPACT_IRQ_LEVELS
  272. ; Level 2 interrupt return Path - from hardware standpoint
  273. bbit0 r10, STATUS_A2_BIT, not_level2_interrupt
  274. ;------------------------------------------------------------------
  275. ; However the context returning might not have taken L2 intr itself
  276. ; e.g. Task'A' user-code -> L2 intr -> schedule -> 'B' user-code ret
  277. ; Special considerations needed for the context which took L2 intr
  278. ld r9, [sp, PT_event] ; Ensure this is L2 intr context
  279. brne r9, event_IRQ2, 149f
  280. ;------------------------------------------------------------------
  281. ; if L2 IRQ interrupted an L1 ISR, we'd disabled preemption earlier
  282. ; so that sched doesn't move to new task, causing L1 to be delayed
  283. ; undeterministically. Now that we've achieved that, let's reset
  284. ; things to what they were, before returning from L2 context
  285. ;----------------------------------------------------------------
  286. ld r9, [sp, PT_status32] ; get statu32_l2 (saved in pt_regs)
  287. bbit0 r9, STATUS_A1_BIT, 149f ; L1 not active when L2 IRQ, so normal
  288. ; decrement thread_info->preempt_count (re-enable preemption)
  289. GET_CURR_THR_INFO_FROM_SP r10
  290. ld r9, [r10, THREAD_INFO_PREEMPT_COUNT]
  291. ; paranoid check, given A1 was active when A2 happened, preempt count
  292. ; must not be 0 because we would have incremented it.
  293. ; If this does happen we simply HALT as it means a BUG !!!
  294. cmp r9, 0
  295. bnz 2f
  296. flag 1
  297. 2:
  298. sub r9, r9, 1
  299. st r9, [r10, THREAD_INFO_PREEMPT_COUNT]
  300. 149:
  301. INTERRUPT_EPILOGUE 2 ; return from level 2 interrupt
  302. debug_marker_l2:
  303. rtie
  304. not_level2_interrupt:
  305. #endif
  306. INTERRUPT_EPILOGUE 1 ; return from level 1 interrupt
  307. debug_marker_l1:
  308. rtie
  309. .Lexcep_or_pure_K_ret:
  310. ;this case is for syscalls or Exceptions or pure kernel mode
  311. EXCEPTION_EPILOGUE
  312. debug_marker_syscall:
  313. rtie
  314. END(ret_from_exception)