ex-entry.S 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (C) 2005-2017 Andes Technology Corporation
  3. #include <linux/linkage.h>
  4. #include <asm/memory.h>
  5. #include <asm/nds32.h>
  6. #include <asm/errno.h>
  7. #include <asm/asm-offsets.h>
  8. #include <asm/page.h>
  9. #ifdef CONFIG_HWZOL
  10. .macro push_zol
  11. mfusr $r14, $LB
  12. mfusr $r15, $LE
  13. mfusr $r16, $LC
  14. .endm
  15. #endif
  16. .macro save_user_regs
  17. smw.adm $sp, [$sp], $sp, #0x1
  18. /* move $SP to the bottom of pt_regs */
  19. addi $sp, $sp, -OSP_OFFSET
  20. /* push $r0 ~ $r25 */
  21. smw.bim $r0, [$sp], $r25
  22. /* push $fp, $gp, $lp */
  23. smw.bim $sp, [$sp], $sp, #0xe
  24. mfsr $r12, $SP_USR
  25. mfsr $r13, $IPC
  26. #ifdef CONFIG_HWZOL
  27. push_zol
  28. #endif
  29. movi $r17, -1
  30. move $r18, $r0
  31. mfsr $r19, $PSW
  32. mfsr $r20, $IPSW
  33. mfsr $r21, $P_IPSW
  34. mfsr $r22, $P_IPC
  35. mfsr $r23, $P_P0
  36. mfsr $r24, $P_P1
  37. smw.bim $r12, [$sp], $r24, #0
  38. addi $sp, $sp, -FUCOP_CTL_OFFSET
  39. /* Initialize kernel space $fp */
  40. andi $p0, $r20, #PSW_mskPOM
  41. movi $p1, #0x0
  42. cmovz $fp, $p1, $p0
  43. andi $r16, $r19, #PSW_mskINTL
  44. slti $r17, $r16, #4
  45. bnez $r17, 1f
  46. addi $r17, $r19, #-2
  47. mtsr $r17, $PSW
  48. isb
  49. 1:
  50. /* If it was superuser mode, we don't need to update $r25 */
  51. bnez $p0, 2f
  52. la $p0, __entry_task
  53. lw $r25, [$p0]
  54. 2:
  55. .endm
  56. .text
  57. /*
  58. * Exception Vector
  59. */
  60. exception_handlers:
  61. .long unhandled_exceptions !Reset/NMI
  62. .long unhandled_exceptions !TLB fill
  63. .long do_page_fault !PTE not present
  64. .long do_dispatch_tlb_misc !TLB misc
  65. .long unhandled_exceptions !TLB VLPT
  66. .long unhandled_exceptions !Machine Error
  67. .long do_debug_trap !Debug related
  68. .long do_dispatch_general !General exception
  69. .long eh_syscall !Syscall
  70. .long asm_do_IRQ !IRQ
  71. common_exception_handler:
  72. save_user_regs
  73. mfsr $p0, $ITYPE
  74. andi $p0, $p0, #ITYPE_mskVECTOR
  75. srli $p0, $p0, #ITYPE_offVECTOR
  76. andi $p1, $p0, #NDS32_VECTOR_mskNONEXCEPTION
  77. bnez $p1, 1f
  78. sethi $lp, hi20(ret_from_exception)
  79. ori $lp, $lp, lo12(ret_from_exception)
  80. sethi $p1, hi20(exception_handlers)
  81. ori $p1, $p1, lo12(exception_handlers)
  82. lw $p1, [$p1+$p0<<2]
  83. move $r0, $p0
  84. mfsr $r1, $EVA
  85. mfsr $r2, $ITYPE
  86. move $r3, $sp
  87. mfsr $r4, $OIPC
  88. /* enable gie if it is enabled in IPSW. */
  89. mfsr $r21, $PSW
  90. andi $r20, $r20, #PSW_mskGIE /* r20 is $IPSW*/
  91. or $r21, $r21, $r20
  92. mtsr $r21, $PSW
  93. dsb
  94. jr $p1
  95. /* syscall */
  96. 1:
  97. addi $p1, $p0, #-NDS32_VECTOR_offEXCEPTION
  98. bnez $p1, 2f
  99. sethi $lp, hi20(ret_from_exception)
  100. ori $lp, $lp, lo12(ret_from_exception)
  101. sethi $p1, hi20(exception_handlers)
  102. ori $p1, $p1, lo12(exception_handlers)
  103. lwi $p1, [$p1+#NDS32_VECTOR_offEXCEPTION<<2]
  104. jr $p1
  105. /* interrupt */
  106. 2:
  107. #ifdef CONFIG_TRACE_IRQFLAGS
  108. jal __trace_hardirqs_off
  109. #endif
  110. move $r0, $sp
  111. sethi $lp, hi20(ret_from_intr)
  112. ori $lp, $lp, lo12(ret_from_intr)
  113. sethi $p0, hi20(exception_handlers)
  114. ori $p0, $p0, lo12(exception_handlers)
  115. lwi $p0, [$p0+#NDS32_VECTOR_offINTERRUPT<<2]
  116. jr $p0
  117. .macro EXCEPTION_VECTOR_DEBUG
  118. .align 4
  119. mfsr $p0, $EDM_CTL
  120. andi $p0, $p0, EDM_CTL_mskV3_EDM_MODE
  121. tnez $p0, SWID_RAISE_INTERRUPT_LEVEL
  122. .endm
  123. .macro EXCEPTION_VECTOR
  124. .align 4
  125. sethi $p0, hi20(common_exception_handler)
  126. ori $p0, $p0, lo12(common_exception_handler)
  127. jral.ton $p0, $p0
  128. .endm
  129. .section ".text.init", #alloc, #execinstr
  130. .global exception_vector
  131. exception_vector:
  132. .rept 6
  133. EXCEPTION_VECTOR
  134. .endr
  135. EXCEPTION_VECTOR_DEBUG
  136. .rept 121
  137. EXCEPTION_VECTOR
  138. .endr
  139. .align 4
  140. .global exception_vector_end
  141. exception_vector_end: