entry-compact.S 12 KB

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