entry-arcv2.S 8.0 KB

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