1
0

context_gcc.S 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. * 2011-02-20 aozima fix context&switch bug.
  14. */
  15. /**
  16. * @addtogroup NIOS_II
  17. */
  18. /*@{*/
  19. .text
  20. .set noat
  21. /*
  22. * rt_base_t rt_hw_interrupt_disable();
  23. */
  24. .global rt_hw_interrupt_disable
  25. .type rt_hw_interrupt_disable, %function
  26. rt_hw_interrupt_disable:
  27. rdctl r2, status /* return status */
  28. wrctl status, zero /* disable interrupt */
  29. ret
  30. /*
  31. * void rt_hw_interrupt_enable(rt_base_t level);
  32. */
  33. .global rt_hw_interrupt_enable
  34. .type rt_hw_interrupt_enable, %function
  35. rt_hw_interrupt_enable:
  36. wrctl status, r4 /* enable interrupt by argument */
  37. ret
  38. /* void rt_hw_context_switch_interrupt_do(void) */
  39. .global rt_hw_context_switch_interrupt_do
  40. .type rt_hw_context_switch_interrupt_do, %function
  41. rt_hw_context_switch_interrupt_do:
  42. /* save from thread */
  43. addi sp,sp,-72
  44. /* frist save r2,so that save status */
  45. stw r2, 4(sp)
  46. /* save status */
  47. /* when the interrupt happen,the interrupt is enable */
  48. movi r2, 1
  49. stw r2, 68(sp) /* status */
  50. stw r3, 8(sp)
  51. stw r4, 12(sp)
  52. /* get & save from thread pc */
  53. ldw r4,%gprel(rt_current_thread_entry)(gp)
  54. stw r4, 0(sp) /* thread pc */
  55. stw r5, 16(sp)
  56. stw r6, 20(sp)
  57. stw r7, 24(sp)
  58. stw r16, 28(sp)
  59. stw r17, 32(sp)
  60. stw r18, 36(sp)
  61. stw r19, 40(sp)
  62. stw r20, 44(sp)
  63. stw r21, 48(sp)
  64. stw r22, 52(sp)
  65. stw r23, 56(sp)
  66. stw fp, 60(sp)
  67. stw ra, 64(sp)
  68. /* save from thread sp */
  69. /* rt_interrupt_from_thread = &from_thread->sp */
  70. ldw r4, %gprel(rt_interrupt_from_thread)(gp)
  71. /* *r4(from_thread->sp) = sp */
  72. stw sp, (r4)
  73. /* clear rt_thread_switch_interrupt_flag */
  74. /* rt_thread_switch_interrupt_flag = 0 */
  75. stw zero,%gprel(rt_thread_switch_interrupt_flag)(gp)
  76. /* load to thread sp */
  77. /* r4 = rt_interrupt_to_thread(&to_thread->sp) */
  78. ldw r4, %gprel(rt_interrupt_to_thread)(gp)
  79. /* sp = to_thread->sp */
  80. ldw sp, (r4)
  81. ldw r2, 68(sp) /* status */
  82. wrctl estatus, r2
  83. ldw ea, 0(sp) /* thread pc */
  84. ldw r2, 4(sp)
  85. ldw r3, 8(sp)
  86. ldw r4, 12(sp)
  87. ldw r5, 16(sp)
  88. ldw r6, 20(sp)
  89. ldw r7, 24(sp)
  90. ldw r16, 28(sp)
  91. ldw r17, 32(sp)
  92. ldw r18, 36(sp)
  93. ldw r19, 40(sp)
  94. ldw r20, 44(sp)
  95. ldw r21, 48(sp)
  96. ldw r22, 52(sp)
  97. ldw r23, 56(sp)
  98. ldw fp, 60(sp)
  99. ldw ra, 64(sp)
  100. addi sp, sp, 72
  101. /* estatus --> status,ea --> pc */
  102. eret
  103. /*
  104. * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
  105. * r4: from
  106. * r5: to
  107. */
  108. .global rt_hw_context_switch
  109. .type rt_hw_context_switch, %function
  110. rt_hw_context_switch:
  111. /* save from thread */
  112. addi sp,sp,-72
  113. /* frist save r2,so that save status */
  114. stw r2, 4(sp)
  115. /* save status */
  116. rdctl r2, status
  117. stw r2, 68(sp) /* status */
  118. stw ra, 0(sp) /* return from rt_hw_context_switch */
  119. stw r3, 8(sp)
  120. stw r4, 12(sp)
  121. stw r5, 16(sp)
  122. stw r6, 20(sp)
  123. stw r7, 24(sp)
  124. stw r16, 28(sp)
  125. stw r17, 32(sp)
  126. stw r18, 36(sp)
  127. stw r19, 40(sp)
  128. stw r20, 44(sp)
  129. stw r21, 48(sp)
  130. stw r22, 52(sp)
  131. stw r23, 56(sp)
  132. stw fp, 60(sp)
  133. stw ra, 64(sp)
  134. /* save form thread sp */
  135. /* from_thread->sp(r4) = sp */
  136. stw sp, (r4)
  137. /* update rt_interrupt_from_thread */
  138. /* rt_interrupt_from_thread = r4(from_thread->sp) */
  139. stw r4,%gprel(rt_interrupt_from_thread)(gp)
  140. /* update rt_interrupt_to_thread */
  141. /* rt_interrupt_to_thread = r5 */
  142. stw r5,%gprel(rt_interrupt_to_thread)(gp)
  143. /* get to thread sp */
  144. /* sp = rt_interrupt_to_thread(r5:to_thread->sp) */
  145. ldw sp, (r5)
  146. ldw r2, 68(sp) /* status */
  147. wrctl estatus, r2
  148. ldw ea, 0(sp) /* thread pc */
  149. ldw r2, 4(sp)
  150. ldw r3, 8(sp)
  151. ldw r4, 12(sp)
  152. ldw r5, 16(sp)
  153. ldw r6, 20(sp)
  154. ldw r7, 24(sp)
  155. ldw r16, 28(sp)
  156. ldw r17, 32(sp)
  157. ldw r18, 36(sp)
  158. ldw r19, 40(sp)
  159. ldw r20, 44(sp)
  160. ldw r21, 48(sp)
  161. ldw r22, 52(sp)
  162. ldw r23, 56(sp)
  163. ldw fp, 60(sp)
  164. ldw ra, 64(sp)
  165. addi sp, sp, 72
  166. /* estatus --> status,ea --> pc */
  167. eret
  168. /*
  169. * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
  170. * r4: from
  171. * r5: to
  172. */
  173. .global rt_hw_context_switch_interrupt
  174. .type rt_hw_context_switch_interrupt, %function
  175. rt_hw_context_switch_interrupt:
  176. /* if( rt_thread_switch_interrupt_flag != 0 ) _from_thread_not_change */
  177. ldw r2,%gprel(rt_thread_switch_interrupt_flag)(gp)
  178. bne r2,zero,_from_thread_not_change
  179. _from_thread_change:
  180. /* save ea -> rt_current_thread_entry */
  181. addi ea,ea,-4
  182. stw ea,%gprel(rt_current_thread_entry)(gp)
  183. /* set rt_thread_switch_interrupt_flag to 1 */
  184. movi r2, 1
  185. stw r2,%gprel(rt_thread_switch_interrupt_flag)(gp)
  186. /* update rt_interrupt_from_thread */
  187. stw r4,%gprel(rt_interrupt_from_thread)(gp)
  188. _from_thread_not_change:
  189. /* update rt_interrupt_to_thread */
  190. stw r5,%gprel(rt_interrupt_to_thread)(gp)
  191. ret
  192. /*
  193. * void rt_hw_context_switch_to(rt_uint32 to);
  194. * r4: to
  195. */
  196. .global rt_hw_context_switch_to
  197. .type rt_hw_context_switch_to, %function
  198. rt_hw_context_switch_to:
  199. /* save to thread */
  200. stw r4,%gprel(rt_interrupt_to_thread)(gp)
  201. /* get sp */
  202. ldw sp, (r4) // sp = *r4
  203. ldw r2, 68(sp) /* status */
  204. wrctl estatus, r2
  205. ldw ea, 0(sp) /* thread entry */
  206. ldw r2, 4(sp)
  207. ldw r3, 8(sp)
  208. ldw r4, 12(sp)
  209. ldw r5, 16(sp)
  210. ldw r6, 20(sp)
  211. ldw r7, 24(sp)
  212. ldw r16, 28(sp)
  213. ldw r17, 32(sp)
  214. ldw r18, 36(sp)
  215. ldw r19, 40(sp)
  216. ldw r20, 44(sp)
  217. ldw r21, 48(sp)
  218. ldw r22, 52(sp)
  219. ldw r23, 56(sp)
  220. ldw fp, 60(sp)
  221. ldw ra, 64(sp)
  222. addi sp, sp, 72
  223. /* estatus --> status,ea --> pc */
  224. eret
  225. /*@}*/