entry_gcc.S 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * File : context_gcc.S
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2018, RT-Thread Development Team
  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 as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2018-05-29 tanek first implementation
  23. */
  24. .section .text.entry
  25. .align 2
  26. .global trap_entry
  27. trap_entry:
  28. // save all from thread context
  29. addi sp, sp, -32 * 4
  30. sw x1, 1 * 4(sp)
  31. li t0, 0x80
  32. sw t0, 2 * 4(sp)
  33. sw x4, 4 * 4(sp)
  34. sw x5, 5 * 4(sp)
  35. sw x6, 6 * 4(sp)
  36. sw x7, 7 * 4(sp)
  37. sw x8, 8 * 4(sp)
  38. sw x9, 9 * 4(sp)
  39. sw x10, 10 * 4(sp)
  40. sw x11, 11 * 4(sp)
  41. sw x12, 12 * 4(sp)
  42. sw x13, 13 * 4(sp)
  43. sw x14, 14 * 4(sp)
  44. sw x15, 15 * 4(sp)
  45. sw x16, 16 * 4(sp)
  46. sw x17, 17 * 4(sp)
  47. sw x18, 18 * 4(sp)
  48. sw x19, 19 * 4(sp)
  49. sw x20, 20 * 4(sp)
  50. sw x21, 21 * 4(sp)
  51. sw x22, 22 * 4(sp)
  52. sw x23, 23 * 4(sp)
  53. sw x24, 24 * 4(sp)
  54. sw x25, 25 * 4(sp)
  55. sw x26, 26 * 4(sp)
  56. sw x27, 27 * 4(sp)
  57. sw x28, 28 * 4(sp)
  58. sw x29, 29 * 4(sp)
  59. sw x30, 30 * 4(sp)
  60. sw x31, 31 * 4(sp)
  61. // switch to interrupt stack
  62. move s0, sp
  63. la sp, _sp
  64. // interrupt handle
  65. call rt_interrupt_enter
  66. csrr a0, mcause
  67. csrr a1, mepc
  68. mv a2, sp
  69. call handle_trap
  70. call rt_interrupt_leave
  71. // switch to from thread stack
  72. move sp, s0
  73. // need to switch new thread
  74. la s0, rt_thread_switch_interrupt_flag
  75. lw s2, 0(s0)
  76. beqz s2, spurious_interrupt
  77. sw zero, 0(s0)
  78. csrr a0, mepc
  79. sw a0, 0 * 4(sp)
  80. la s0, rt_interrupt_from_thread
  81. lw s1, 0(s0)
  82. sw sp, 0(s1)
  83. la s0, rt_interrupt_to_thread
  84. lw s1, 0(s0)
  85. lw sp, 0(s1)
  86. lw a0, 0 * 4(sp)
  87. csrw mepc, a0
  88. spurious_interrupt:
  89. lw x1, 1 * 4(sp)
  90. // Remain in M-mode after mret
  91. li t0, 0x00001800
  92. csrs mstatus, t0
  93. lw t0, 2 * 4(sp)
  94. csrs mstatus, t0
  95. lw x4, 4 * 4(sp)
  96. lw x5, 5 * 4(sp)
  97. lw x6, 6 * 4(sp)
  98. lw x7, 7 * 4(sp)
  99. lw x8, 8 * 4(sp)
  100. lw x9, 9 * 4(sp)
  101. lw x10, 10 * 4(sp)
  102. lw x11, 11 * 4(sp)
  103. lw x12, 12 * 4(sp)
  104. lw x13, 13 * 4(sp)
  105. lw x14, 14 * 4(sp)
  106. lw x15, 15 * 4(sp)
  107. lw x16, 16 * 4(sp)
  108. lw x17, 17 * 4(sp)
  109. lw x18, 18 * 4(sp)
  110. lw x19, 19 * 4(sp)
  111. lw x20, 20 * 4(sp)
  112. lw x21, 21 * 4(sp)
  113. lw x22, 22 * 4(sp)
  114. lw x23, 23 * 4(sp)
  115. lw x24, 24 * 4(sp)
  116. lw x25, 25 * 4(sp)
  117. lw x26, 26 * 4(sp)
  118. lw x27, 27 * 4(sp)
  119. lw x28, 28 * 4(sp)
  120. lw x29, 29 * 4(sp)
  121. lw x30, 30 * 4(sp)
  122. lw x31, 31 * 4(sp)
  123. addi sp, sp, 32 * 4
  124. mret
  125. .weak handle_trap
  126. handle_trap:
  127. 1:
  128. j 1b