entry-arcv2.S 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 stext ; Restart Vector (jump to entry point)
  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) ICI (inter core interrupt)
  42. VECTOR handle_interrupt
  43. VECTOR handle_interrupt
  44. VECTOR handle_interrupt
  45. VECTOR handle_interrupt ; (23) End of fixed IRQs
  46. .rept CONFIG_ARC_NUMBER_OF_INTERRUPTS - 8
  47. VECTOR handle_interrupt
  48. .endr
  49. .section .text, "ax",@progbits
  50. reserved:
  51. flag 1 ; Unexpected event, halt
  52. ;##################### Interrupt Handling ##############################
  53. ENTRY(handle_interrupt)
  54. INTERRUPT_PROLOGUE irq
  55. clri ; To make status32.IE agree with CPU internal state
  56. lr r0, [ICAUSE]
  57. mov blink, ret_from_exception
  58. b.d arch_do_IRQ
  59. mov r1, sp
  60. END(handle_interrupt)
  61. ;################### Non TLB Exception Handling #############################
  62. ENTRY(EV_SWI)
  63. flag 1
  64. END(EV_SWI)
  65. ENTRY(EV_DivZero)
  66. flag 1
  67. END(EV_DivZero)
  68. ENTRY(EV_DCError)
  69. flag 1
  70. END(EV_DCError)
  71. ENTRY(EV_Misaligned)
  72. EXCEPTION_PROLOGUE
  73. lr r0, [efa] ; Faulting Data address
  74. mov r1, sp
  75. FAKE_RET_FROM_EXCPN
  76. SAVE_CALLEE_SAVED_USER
  77. mov r2, sp ; callee_regs
  78. bl do_misaligned_access
  79. ; TBD: optimize - do this only if a callee reg was involved
  80. ; either a dst of emulated LD/ST or src with address-writeback
  81. RESTORE_CALLEE_SAVED_USER
  82. b ret_from_exception
  83. END(EV_Misaligned)
  84. ; ---------------------------------------------
  85. ; Protection Violation Exception Handler
  86. ; ---------------------------------------------
  87. ENTRY(EV_TLBProtV)
  88. EXCEPTION_PROLOGUE
  89. lr r0, [efa] ; Faulting Data address
  90. mov r1, sp ; pt_regs
  91. FAKE_RET_FROM_EXCPN
  92. mov blink, ret_from_exception
  93. b do_page_fault
  94. END(EV_TLBProtV)
  95. ; From Linux standpoint Slow Path I/D TLB Miss is same a ProtV as they
  96. ; need to call do_page_fault().
  97. ; ECR in pt_regs provides whether access was R/W/X
  98. .global call_do_page_fault
  99. .set call_do_page_fault, EV_TLBProtV
  100. ;############# Common Handlers for ARCompact and ARCv2 ##############
  101. #include "entry.S"
  102. ;############# Return from Intr/Excp/Trap (ARCv2 ISA Specifics) ##############
  103. ;
  104. ; Restore the saved sys context (common exit-path for EXCPN/IRQ/Trap)
  105. ; IRQ shd definitely not happen between now and rtie
  106. ; All 2 entry points to here already disable interrupts
  107. .Lrestore_regs:
  108. ld r0, [sp, PT_status32] ; U/K mode at time of entry
  109. lr r10, [AUX_IRQ_ACT]
  110. bmsk r11, r10, 15 ; AUX_IRQ_ACT.ACTIVE
  111. breq r11, 0, .Lexcept_ret ; No intr active, ret from Exception
  112. ;####### Return from Intr #######
  113. debug_marker_l1:
  114. bbit1.nt r0, STATUS_DE_BIT, .Lintr_ret_to_delay_slot
  115. .Lisr_ret_fast_path:
  116. ; Handle special case #1: (Entry via Exception, Return via IRQ)
  117. ;
  118. ; Exception in U mode, preempted in kernel, Intr taken (K mode), orig
  119. ; task now returning to U mode (riding the Intr)
  120. ; AUX_IRQ_ACTIVE won't have U bit set (since intr in K mode), hence SP
  121. ; won't be switched to correct U mode value (from AUX_SP)
  122. ; So force AUX_IRQ_ACT.U for such a case
  123. btst r0, STATUS_U_BIT ; Z flag set if K (Z clear for U)
  124. bset.nz r11, r11, AUX_IRQ_ACT_BIT_U ; NZ means U
  125. sr r11, [AUX_IRQ_ACT]
  126. INTERRUPT_EPILOGUE irq
  127. rtie
  128. ;####### Return from Exception / pure kernel mode #######
  129. .Lexcept_ret: ; Expects r0 has PT_status32
  130. debug_marker_syscall:
  131. EXCEPTION_EPILOGUE
  132. rtie
  133. ;####### Return from Intr to insn in delay slot #######
  134. ; Handle special case #2: (Entry via Exception in Delay Slot, Return via IRQ)
  135. ;
  136. ; Intr returning to a Delay Slot (DS) insn
  137. ; (since IRQ NOT allowed in DS in ARCv2, this can only happen if orig
  138. ; entry was via Exception in DS which got preempted in kernel).
  139. ;
  140. ; IRQ RTIE won't reliably restore DE bit and/or BTA, needs handling
  141. .Lintr_ret_to_delay_slot:
  142. debug_marker_ds:
  143. ld r2, [@intr_to_DE_cnt]
  144. add r2, r2, 1
  145. st r2, [@intr_to_DE_cnt]
  146. ld r2, [sp, PT_ret]
  147. ld r3, [sp, PT_status32]
  148. bic r0, r3, STATUS_U_MASK|STATUS_DE_MASK|STATUS_IE_MASK|STATUS_L_MASK
  149. st r0, [sp, PT_status32]
  150. mov r1, .Lintr_ret_to_delay_slot_2
  151. st r1, [sp, PT_ret]
  152. st r2, [sp, 0]
  153. st r3, [sp, 4]
  154. b .Lisr_ret_fast_path
  155. .Lintr_ret_to_delay_slot_2:
  156. sub sp, sp, SZ_PT_REGS
  157. st r9, [sp, -4]
  158. ld r9, [sp, 0]
  159. sr r9, [eret]
  160. ld r9, [sp, 4]
  161. sr r9, [erstatus]
  162. ld r9, [sp, 8]
  163. sr r9, [erbta]
  164. ld r9, [sp, -4]
  165. add sp, sp, SZ_PT_REGS
  166. rtie
  167. END(ret_from_exception)