entry-arcv2.S 7.5 KB

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