exceptions.S 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
  4. * Scott McNutt <smcnutt@psyent.com>
  5. */
  6. #include <config.h>
  7. #include <asm/opcodes.h>
  8. .text
  9. .align 4
  10. .global _exception
  11. .set noat
  12. .set nobreak
  13. _exception:
  14. /* SAVE ALL REGS -- this allows trap and unimplemented
  15. * instruction handlers to be coded conveniently in C
  16. */
  17. addi sp, sp, -(33*4)
  18. stw r0, 0(sp)
  19. stw r1, 4(sp)
  20. stw r2, 8(sp)
  21. stw r3, 12(sp)
  22. stw r4, 16(sp)
  23. stw r5, 20(sp)
  24. stw r6, 24(sp)
  25. stw r7, 28(sp)
  26. stw r8, 32(sp)
  27. stw r9, 36(sp)
  28. stw r10, 40(sp)
  29. stw r11, 44(sp)
  30. stw r12, 48(sp)
  31. stw r13, 52(sp)
  32. stw r14, 56(sp)
  33. stw r15, 60(sp)
  34. stw r16, 64(sp)
  35. stw r17, 68(sp)
  36. stw r19, 72(sp)
  37. stw r19, 76(sp)
  38. stw r20, 80(sp)
  39. stw r21, 84(sp)
  40. stw r22, 88(sp)
  41. stw r23, 92(sp)
  42. stw r24, 96(sp)
  43. stw r25, 100(sp)
  44. stw r26, 104(sp)
  45. stw r27, 108(sp)
  46. stw r28, 112(sp)
  47. stw r29, 116(sp)
  48. stw r30, 120(sp)
  49. stw r31, 124(sp)
  50. rdctl et, estatus
  51. stw et, 128(sp)
  52. /* If interrupts are disabled -- software interrupt */
  53. rdctl et, estatus
  54. andi et, et, 1
  55. beq et, r0, 0f
  56. /* If no interrupts are pending -- software interrupt */
  57. rdctl et, ipending
  58. beq et, r0, 0f
  59. /* HARDWARE INTERRUPT: Call interrupt handler */
  60. movhi r3, %hi(external_interrupt)
  61. ori r3, r3, %lo(external_interrupt)
  62. mov r4, sp /* ptr to regs */
  63. callr r3
  64. /* Return address fixup: execution resumes by re-issue of
  65. * interrupted instruction at ea-4 (ea == r29). Here we do
  66. * simple fixup to allow common exception return.
  67. */
  68. ldw r3, 116(sp)
  69. addi r3, r3, -4
  70. stw r3, 116(sp)
  71. br _exception_return
  72. 0:
  73. /* TRAP EXCEPTION */
  74. movhi r3, %hi(OPC_TRAP)
  75. ori r3, r3, %lo(OPC_TRAP)
  76. addi r1, ea, -4
  77. ldw r1, 0(r1)
  78. bne r1, r3, 1f
  79. movhi r3, %hi(trap_handler)
  80. ori r3, r3, %lo(trap_handler)
  81. mov r4, sp /* ptr to regs */
  82. callr r3
  83. br _exception_return
  84. 1:
  85. /* UNIMPLEMENTED INSTRUCTION EXCEPTION */
  86. movhi r3, %hi(soft_emulation)
  87. ori r3, r3, %lo(soft_emulation)
  88. mov r4, sp /* ptr to regs */
  89. callr r3
  90. /* Restore regsisters and return from exception*/
  91. _exception_return:
  92. ldw r1, 4(sp)
  93. ldw r2, 8(sp)
  94. ldw r3, 12(sp)
  95. ldw r4, 16(sp)
  96. ldw r5, 20(sp)
  97. ldw r6, 24(sp)
  98. ldw r7, 28(sp)
  99. ldw r8, 32(sp)
  100. ldw r9, 36(sp)
  101. ldw r10, 40(sp)
  102. ldw r11, 44(sp)
  103. ldw r12, 48(sp)
  104. ldw r13, 52(sp)
  105. ldw r14, 56(sp)
  106. ldw r15, 60(sp)
  107. ldw r16, 64(sp)
  108. ldw r17, 68(sp)
  109. ldw r19, 72(sp)
  110. ldw r19, 76(sp)
  111. ldw r20, 80(sp)
  112. ldw r21, 84(sp)
  113. ldw r22, 88(sp)
  114. ldw r23, 92(sp)
  115. ldw r24, 96(sp)
  116. ldw r25, 100(sp)
  117. ldw r26, 104(sp)
  118. ldw r27, 108(sp)
  119. ldw r28, 112(sp)
  120. ldw r29, 116(sp)
  121. ldw r30, 120(sp)
  122. ldw r31, 124(sp)
  123. addi sp, sp, (33*4)
  124. eret
  125. /*-------------------------------------------------------------*/