context_gcc.S 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*
  2. * File : context_gcc.S
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006-2011, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2011-02-14 aozima first implementation for Nios II.
  13. */
  14. /**
  15. * @addtogroup NIOS_II
  16. */
  17. /*@{*/
  18. .text
  19. .set noat
  20. /*
  21. * rt_base_t rt_hw_interrupt_disable();
  22. */
  23. .global rt_hw_interrupt_disable
  24. .type rt_hw_interrupt_disable, %function
  25. rt_hw_interrupt_disable:
  26. rdctl r2, status /* return status */
  27. wrctl status, zero /* disable interrupt */
  28. ret
  29. /*
  30. * void rt_hw_interrupt_enable(rt_base_t level);
  31. */
  32. .global rt_hw_interrupt_enable
  33. .type rt_hw_interrupt_enable, %function
  34. rt_hw_interrupt_enable:
  35. wrctl status, r4 /* enable interrupt by argument */
  36. ret
  37. /* void rt_hw_context_switch_interrupt_do(void) */
  38. .global rt_hw_context_switch_interrupt_do
  39. .type rt_hw_context_switch_interrupt_do, %function
  40. rt_hw_context_switch_interrupt_do:
  41. /* save from thread */
  42. addi sp,sp,-72
  43. rdctl r2, status
  44. stw r2, 68(sp) /* status */
  45. stw r2, 4(sp)
  46. stw r3, 8(sp)
  47. stw r4, 12(sp)
  48. /* get & save from thread pc */
  49. ldw r4,%gprel(rt_current_thread_entry)(gp)
  50. stw r4, 0(sp) /* thread back */
  51. stw r5, 16(sp)
  52. stw r6, 20(sp)
  53. stw r7, 24(sp)
  54. stw r16, 28(sp)
  55. stw r17, 32(sp)
  56. stw r18, 36(sp)
  57. stw r19, 40(sp)
  58. stw r20, 44(sp)
  59. stw r21, 48(sp)
  60. stw r22, 52(sp)
  61. stw r23, 56(sp)
  62. stw fp, 60(sp)
  63. stw ra, 64(sp)
  64. /* save from thread sp */
  65. ldw r4, %gprel(rt_interrupt_from_thread)(gp)
  66. stw sp, (r4)
  67. /* clear rt_thread_switch_interrput_flag */
  68. stw zero,%gprel(rt_thread_switch_interrput_flag)(gp)
  69. /* load to thread sp */
  70. ldw r4, %gprel(rt_interrupt_to_thread)(gp)
  71. ldw sp, (r4)
  72. ldw r2, 68(sp) /* status */
  73. wrctl status, r2
  74. ldw at, 0(sp) /* thread pc */
  75. ldw r2, 4(sp)
  76. ldw r3, 8(sp)
  77. ldw r4, 12(sp)
  78. ldw r5, 16(sp)
  79. ldw r6, 20(sp)
  80. ldw r7, 24(sp)
  81. ldw r16, 28(sp)
  82. ldw r17, 32(sp)
  83. ldw r18, 36(sp)
  84. ldw r19, 40(sp)
  85. ldw r20, 44(sp)
  86. ldw r21, 48(sp)
  87. ldw r22, 52(sp)
  88. ldw r23, 56(sp)
  89. ldw fp, 60(sp)
  90. ldw ra, 64(sp)
  91. addi sp, sp, 72
  92. jmp at
  93. /*
  94. * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
  95. * r4: from
  96. * r5: to
  97. */
  98. .global rt_hw_context_switch
  99. .type rt_hw_context_switch, %function
  100. rt_hw_context_switch:
  101. /* save from thread */
  102. addi sp,sp,-72
  103. rdctl r2, status
  104. stw r2, 68(sp) /* status */
  105. stw ra, 0(sp) /* thread back */
  106. stw r2, 4(sp)
  107. stw r3, 8(sp)
  108. stw r4, 12(sp)
  109. stw r5, 16(sp)
  110. stw r6, 20(sp)
  111. stw r7, 24(sp)
  112. stw r16, 28(sp)
  113. stw r17, 32(sp)
  114. stw r18, 36(sp)
  115. stw r19, 40(sp)
  116. stw r20, 44(sp)
  117. stw r21, 48(sp)
  118. stw r22, 52(sp)
  119. stw r23, 56(sp)
  120. stw fp, 60(sp)
  121. stw ra, 64(sp)
  122. /* save form thread sp */
  123. stw sp, (r4)
  124. /* update rt_interrupt_from_thread */
  125. stw r4,%gprel(rt_interrupt_from_thread)(gp)
  126. /* update rt_interrupt_to_thread */
  127. stw r5,%gprel(rt_interrupt_to_thread)(gp)
  128. /* get to thread sp */
  129. ldw sp, (r5)
  130. ldw r2, 68(sp) /* status */
  131. wrctl status, r2
  132. ldw at, 0(sp) /* thread pc */
  133. ldw r2, 4(sp)
  134. ldw r3, 8(sp)
  135. ldw r4, 12(sp)
  136. ldw r5, 16(sp)
  137. ldw r6, 20(sp)
  138. ldw r7, 24(sp)
  139. ldw r16, 28(sp)
  140. ldw r17, 32(sp)
  141. ldw r18, 36(sp)
  142. ldw r19, 40(sp)
  143. ldw r20, 44(sp)
  144. ldw r21, 48(sp)
  145. ldw r22, 52(sp)
  146. ldw r23, 56(sp)
  147. ldw fp, 60(sp)
  148. ldw ra, 64(sp)
  149. addi sp, sp, 72
  150. jmp at
  151. /*
  152. * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
  153. * r4: from
  154. * r5: to
  155. */
  156. .global rt_hw_context_switch_interrupt
  157. .type rt_hw_context_switch_interrupt, %function
  158. rt_hw_context_switch_interrupt:
  159. /* save ea -> rt_current_thread_entry */
  160. addi ea,ea,-4
  161. stw ea,%gprel(rt_current_thread_entry)(gp)
  162. /* set rt_thread_switch_interrput_flag to 1 */
  163. movi r2, 1
  164. stw r2,%gprel(rt_thread_switch_interrput_flag)(gp)
  165. /* update rt_interrupt_from_thread */
  166. stw r4,%gprel(rt_interrupt_from_thread)(gp)
  167. /* update rt_interrupt_to_thread */
  168. stw r5,%gprel(rt_interrupt_to_thread)(gp)
  169. ret
  170. /*
  171. * void rt_hw_context_switch_to(rt_uint32 to);
  172. * r4: to
  173. */
  174. .global rt_hw_context_switch_to
  175. .type rt_hw_context_switch_to, %function
  176. rt_hw_context_switch_to:
  177. /* save to thread */
  178. stw r4,%gprel(rt_interrupt_to_thread)(gp)
  179. /* get sp */
  180. ldw sp, (r4) // sp = *r4
  181. ldw r2, 68(sp) /* status */
  182. wrctl status, r2
  183. ldw at, 0(sp) /* thread entry */
  184. ldw r2, 4(sp)
  185. ldw r3, 8(sp)
  186. ldw r4, 12(sp)
  187. ldw r5, 16(sp)
  188. ldw r6, 20(sp)
  189. ldw r7, 24(sp)
  190. ldw r16, 28(sp)
  191. ldw r17, 32(sp)
  192. ldw r18, 36(sp)
  193. ldw r19, 40(sp)
  194. ldw r20, 44(sp)
  195. ldw r21, 48(sp)
  196. ldw r22, 52(sp)
  197. ldw r23, 56(sp)
  198. ldw fp, 60(sp)
  199. ldw ra, 64(sp)
  200. addi sp, sp, 72
  201. jmp at
  202. /*@}*/