entry-arcv2.S 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * ARCv2 ISA based core Low Level Intr/Traps/Exceptions(non-TLB) Handling
  4. *
  5. * Copyright (C) 2013 Synopsys, Inc. (www.synopsys.com)
  6. */
  7. #include <linux/linkage.h> /* ARC_{EXTRY,EXIT} */
  8. #include <asm/entry.h> /* SAVE_ALL_{INT1,INT2,TRAP...} */
  9. #include <asm/errno.h>
  10. #include <asm/arcregs.h>
  11. #include <asm/irqflags.h>
  12. #include <asm/mmu.h>
  13. ; A maximum number of supported interrupts in the core interrupt controller.
  14. ; This number is not equal to the maximum interrupt number (256) because
  15. ; first 16 lines are reserved for exceptions and are not configurable.
  16. #define NR_CPU_IRQS 240
  17. .cpu HS
  18. #define VECTOR .word
  19. ;############################ Vector Table #################################
  20. .section .vector,"a",@progbits
  21. .align 4
  22. # Initial 16 slots are Exception Vectors
  23. VECTOR res_service ; Reset Vector
  24. VECTOR mem_service ; Mem exception
  25. VECTOR instr_service ; Instrn Error
  26. VECTOR EV_MachineCheck ; Fatal Machine check
  27. VECTOR EV_TLBMissI ; Intruction TLB miss
  28. VECTOR EV_TLBMissD ; Data TLB miss
  29. VECTOR EV_TLBProtV ; Protection Violation
  30. VECTOR EV_PrivilegeV ; Privilege Violation
  31. VECTOR EV_SWI ; Software Breakpoint
  32. VECTOR EV_Trap ; Trap exception
  33. VECTOR EV_Extension ; Extn Instruction Exception
  34. VECTOR EV_DivZero ; Divide by Zero
  35. VECTOR EV_DCError ; Data Cache Error
  36. VECTOR EV_Misaligned ; Misaligned Data Access
  37. VECTOR reserved ; Reserved slots
  38. VECTOR reserved ; Reserved slots
  39. # Begin Interrupt Vectors
  40. VECTOR handle_interrupt ; (16) Timer0
  41. VECTOR handle_interrupt ; unused (Timer1)
  42. VECTOR handle_interrupt ; unused (WDT)
  43. VECTOR handle_interrupt ; (19) Inter core Interrupt (IPI)
  44. VECTOR handle_interrupt ; (20) perf Interrupt
  45. VECTOR handle_interrupt ; (21) Software Triggered Intr (Self IPI)
  46. VECTOR handle_interrupt ; unused
  47. VECTOR handle_interrupt ; (23) unused
  48. # End of fixed IRQs
  49. .rept NR_CPU_IRQS - 8
  50. VECTOR handle_interrupt
  51. .endr
  52. .section .text, "ax",@progbits
  53. reserved:
  54. flag 1 ; Unexpected event, halt
  55. ;##################### Interrupt Handling ##############################
  56. ENTRY(handle_interrupt)
  57. INTERRUPT_PROLOGUE
  58. # irq control APIs local_irq_save/restore/disable/enable fiddle with
  59. # global interrupt enable bits in STATUS32 (.IE for 1 prio, .E[] for 2 prio)
  60. # However a taken interrupt doesn't clear these bits. Thus irqs_disabled()
  61. # query in hard ISR path would return false (since .IE is set) which would
  62. # trips genirq interrupt handling asserts.
  63. #
  64. # So do a "soft" disable of interrutps here.
  65. #
  66. # Note this disable is only for consistent book-keeping as further interrupts
  67. # will be disabled anyways even w/o this. Hardware tracks active interrupts
  68. # seperately in AUX_IRQ_ACT.active and will not take new interrupts
  69. # unless this one returns (or higher prio becomes pending in 2-prio scheme)
  70. IRQ_DISABLE
  71. ; icause is banked: one per priority level
  72. ; so a higher prio interrupt taken here won't clobber prev prio icause
  73. lr r0, [ICAUSE]
  74. mov blink, ret_from_exception
  75. b.d arch_do_IRQ
  76. mov r1, sp
  77. END(handle_interrupt)
  78. ;################### Non TLB Exception Handling #############################
  79. ENTRY(EV_SWI)
  80. ; TODO: implement this
  81. EXCEPTION_PROLOGUE
  82. b ret_from_exception
  83. END(EV_SWI)
  84. ENTRY(EV_DivZero)
  85. ; TODO: implement this
  86. EXCEPTION_PROLOGUE
  87. b ret_from_exception
  88. END(EV_DivZero)
  89. ENTRY(EV_DCError)
  90. ; TODO: implement this
  91. EXCEPTION_PROLOGUE
  92. b ret_from_exception
  93. END(EV_DCError)
  94. ; ---------------------------------------------
  95. ; Memory Error Exception Handler
  96. ; - Unlike ARCompact, handles Bus errors for both User/Kernel mode,
  97. ; Instruction fetch or Data access, under a single Exception Vector
  98. ; ---------------------------------------------
  99. ENTRY(mem_service)
  100. EXCEPTION_PROLOGUE
  101. lr r0, [efa]
  102. mov r1, sp
  103. FAKE_RET_FROM_EXCPN
  104. bl do_memory_error
  105. b ret_from_exception
  106. END(mem_service)
  107. ENTRY(EV_Misaligned)
  108. EXCEPTION_PROLOGUE
  109. lr r0, [efa] ; Faulting Data address
  110. mov r1, sp
  111. FAKE_RET_FROM_EXCPN
  112. SAVE_CALLEE_SAVED_USER
  113. mov r2, sp ; callee_regs
  114. bl do_misaligned_access
  115. ; TBD: optimize - do this only if a callee reg was involved
  116. ; either a dst of emulated LD/ST or src with address-writeback
  117. RESTORE_CALLEE_SAVED_USER
  118. b ret_from_exception
  119. END(EV_Misaligned)
  120. ; ---------------------------------------------
  121. ; Protection Violation Exception Handler
  122. ; ---------------------------------------------
  123. ENTRY(EV_TLBProtV)
  124. EXCEPTION_PROLOGUE
  125. lr r0, [efa] ; Faulting Data address
  126. mov r1, sp ; pt_regs
  127. FAKE_RET_FROM_EXCPN
  128. mov blink, ret_from_exception
  129. b do_page_fault
  130. END(EV_TLBProtV)
  131. ; From Linux standpoint Slow Path I/D TLB Miss is same a ProtV as they
  132. ; need to call do_page_fault().
  133. ; ECR in pt_regs provides whether access was R/W/X
  134. .global call_do_page_fault
  135. .set call_do_page_fault, EV_TLBProtV
  136. ;############# Common Handlers for ARCompact and ARCv2 ##############
  137. #include "entry.S"
  138. ;############# Return from Intr/Excp/Trap (ARCv2 ISA Specifics) ##############
  139. ;
  140. ; Restore the saved sys context (common exit-path for EXCPN/IRQ/Trap)
  141. ; IRQ shd definitely not happen between now and rtie
  142. ; All 2 entry points to here already disable interrupts
  143. .Lrestore_regs:
  144. restore_regs:
  145. # Interrpts are actually disabled from this point on, but will get
  146. # reenabled after we return from interrupt/exception.
  147. # But irq tracer needs to be told now...
  148. TRACE_ASM_IRQ_ENABLE
  149. ld r0, [sp, PT_status32] ; U/K mode at time of entry
  150. lr r10, [AUX_IRQ_ACT]
  151. bmsk r11, r10, 15 ; extract AUX_IRQ_ACT.active
  152. breq r11, 0, .Lexcept_ret ; No intr active, ret from Exception
  153. ;####### Return from Intr #######
  154. .Lisr_ret:
  155. debug_marker_l1:
  156. ; bbit1.nt r0, STATUS_DE_BIT, .Lintr_ret_to_delay_slot
  157. btst r0, STATUS_DE_BIT ; Z flag set if bit clear
  158. bnz .Lintr_ret_to_delay_slot ; branch if STATUS_DE_BIT set
  159. ; Handle special case #1: (Entry via Exception, Return via IRQ)
  160. ;
  161. ; Exception in U mode, preempted in kernel, Intr taken (K mode), orig
  162. ; task now returning to U mode (riding the Intr)
  163. ; AUX_IRQ_ACTIVE won't have U bit set (since intr in K mode), hence SP
  164. ; won't be switched to correct U mode value (from AUX_SP)
  165. ; So force AUX_IRQ_ACT.U for such a case
  166. btst r0, STATUS_U_BIT ; Z flag set if K (Z clear for U)
  167. bset.nz r11, r11, AUX_IRQ_ACT_BIT_U ; NZ means U
  168. sr r11, [AUX_IRQ_ACT]
  169. INTERRUPT_EPILOGUE
  170. rtie
  171. ;####### Return from Exception / pure kernel mode #######
  172. .Lexcept_ret: ; Expects r0 has PT_status32
  173. debug_marker_syscall:
  174. EXCEPTION_EPILOGUE
  175. rtie
  176. ;####### Return from Intr to insn in delay slot #######
  177. ; Handle special case #2: (Entry via Exception in Delay Slot, Return via IRQ)
  178. ;
  179. ; Intr returning to a Delay Slot (DS) insn
  180. ; (since IRQ NOT allowed in DS in ARCv2, this can only happen if orig
  181. ; entry was via Exception in DS which got preempted in kernel).
  182. ;
  183. ; IRQ RTIE won't reliably restore DE bit and/or BTA, needs workaround
  184. ;
  185. ; Solution is to drop out of interrupt context into pure kernel mode
  186. ; and return from pure kernel mode which does right things for delay slot
  187. .Lintr_ret_to_delay_slot:
  188. debug_marker_ds:
  189. ld r2, [@intr_to_DE_cnt]
  190. add r2, r2, 1
  191. st r2, [@intr_to_DE_cnt]
  192. ; drop out of interrupt context (clear AUX_IRQ_ACT.active)
  193. bmskn r11, r10, 15
  194. sr r11, [AUX_IRQ_ACT]
  195. b .Lexcept_ret
  196. END(ret_from_exception)