context.s 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. ;
  2. ; Copyright (c) 2006-2018, RT-Thread Development Team
  3. ;
  4. ; SPDX-License-Identifier: Apache-2.0
  5. ;
  6. ; Change Logs:
  7. ; Date Author Notes
  8. ; 2018-09-01 xuzhuoyi the first version.
  9. ;
  10. .ref _rt_interrupt_to_thread
  11. .ref _rt_interrupt_from_thread
  12. .ref _rt_thread_switch_interrupt_flag
  13. .def _RTOSINT_Handler
  14. .def _rt_hw_get_st0
  15. .def _rt_hw_get_st1
  16. .def _rt_hw_context_switch_interrupt
  17. .def _rt_hw_context_switch
  18. .def _rt_hw_context_switch_to
  19. .def _rt_hw_interrupt_thread_switch
  20. .def _rt_hw_interrupt_disable
  21. .def _rt_hw_interrupt_enable
  22. RT_CTX_SAVE .macro
  23. PUSH AR1H:AR0H
  24. PUSH XAR2
  25. PUSH XAR3
  26. PUSH XAR4
  27. PUSH XAR5
  28. PUSH XAR6
  29. PUSH XAR7
  30. PUSH XT
  31. PUSH RPC
  32. .endm
  33. RT_CTX_RESTORE .macro
  34. POP RPC
  35. POP XT
  36. POP XAR7
  37. POP XAR6
  38. POP XAR5
  39. POP XAR4
  40. POP XAR3
  41. POP XAR2
  42. MOVZ AR0 , @SP
  43. SUBB XAR0, #6
  44. MOVL ACC , *XAR0
  45. AND ACC, #0xFFFF << 16
  46. MOV AL, IER
  47. MOVL *XAR0, ACC
  48. POP AR1H:AR0H
  49. .endm
  50. .text
  51. .newblock
  52. ;
  53. ; rt_base_t rt_hw_interrupt_disable();
  54. ;
  55. .asmfunc
  56. _rt_hw_interrupt_disable:
  57. DINT
  58. LRETR
  59. .endasmfunc
  60. ;
  61. ; void rt_hw_interrupt_enable(rt_base_t level);
  62. ;
  63. .asmfunc
  64. _rt_hw_interrupt_enable:
  65. EINT
  66. LRETR
  67. .endasmfunc
  68. ;
  69. ; void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
  70. ; r0 --> from
  71. ; r4 --> to
  72. .asmfunc
  73. _rt_hw_context_switch_interrupt:
  74. _rt_hw_context_switch:
  75. MOVL XAR0, #0
  76. MOV AR0, AL
  77. MOVL XAR4, *-SP[4]
  78. ; set rt_thread_switch_interrupt_flag to 1
  79. MOVL XAR5, #_rt_thread_switch_interrupt_flag
  80. MOVL XAR6, *XAR5
  81. MOVL ACC, XAR6
  82. CMPB AL, #1
  83. B _reswitch, EQ
  84. MOVL XAR6, #1
  85. MOVL *XAR5, XAR6
  86. MOVL XAR5, #_rt_interrupt_from_thread ; set rt_interrupt_from_thread
  87. MOVL *XAR5, XAR0
  88. _reswitch:
  89. MOVL XAR5, #_rt_interrupt_to_thread ; set rt_interrupt_to_thread
  90. MOVL *XAR5, XAR4
  91. TRAP #16
  92. LRETR
  93. .endasmfunc
  94. .asmfunc
  95. _RTOSINT_Handler:
  96. ; disable interrupt to protect context switch
  97. DINT
  98. ; get rt_thread_switch_interrupt_flag
  99. MOV AR0, #_rt_thread_switch_interrupt_flag
  100. MOV AL, *AR0
  101. MOV AR1, AL
  102. CMP AR1, #0
  103. B rtosint_exit, EQ ; pendsv already handled
  104. ; clear rt_thread_switch_interrupt_flag to 0
  105. MOV AR1, #0x00
  106. MOV *AR0, AR1
  107. MOV AR0, #_rt_interrupt_from_thread
  108. MOV AL, *AR0
  109. MOV AR1, AL
  110. CMP AR1, #0
  111. B switch_to_thread, EQ ; skip register save at the first time
  112. ;MOVZ AR1, @SP ; get from thread stack pointer
  113. ;#if defined (__VFP_FP__) && !defined(__SOFTFP__)
  114. ; TST lr, #0x10 ; if(!EXC_RETURN[4])
  115. ; VSTMDBEQ r1!, {d8 - d15} ; push FPU register s16~s31
  116. ;#endif
  117. RT_CTX_SAVE ; push r4 - r11 register
  118. ;#if defined (__VFP_FP__) && !defined(__SOFTFP__)
  119. ; MOV r4, #0x00 ; flag = 0
  120. ; TST lr, #0x10 ; if(!EXC_RETURN[4])
  121. ; MOVEQ r4, #0x01 ; flag = 1
  122. ; STMFD r1!, {r4} ; push flag
  123. ;#endif
  124. MOV AL, *AR0
  125. MOV AR1, AL
  126. MOVZ AR1, @SP ; get from thread stack pointer
  127. MOV *AR0, AR1 ; update from thread stack pointer
  128. switch_to_thread:
  129. MOV AR1, #_rt_interrupt_to_thread
  130. MOV AL, *AR1
  131. MOV AR1, AL
  132. MOV AL, *AR1
  133. MOV AR1, AL ; load thread stack pointer
  134. ;#if defined (__VFP_FP__) && !defined(__SOFTFP__)
  135. ; LDMFD r1!, {r3} ; pop flag
  136. ;#endif
  137. MOV @SP, AR1
  138. INC SP
  139. RT_CTX_RESTORE ; pop r4 - r11 register
  140. rtosint_exit:
  141. ; restore interrupt
  142. EINT
  143. IRET
  144. .endasmfunc
  145. .asmfunc
  146. _rt_hw_get_st0:
  147. PUSH ST0
  148. POP AL
  149. LRETR
  150. .endasmfunc
  151. .asmfunc
  152. _rt_hw_get_st1:
  153. PUSH ST1
  154. POP AL
  155. LRETR
  156. .endasmfunc
  157. ;
  158. ; * void rt_hw_context_switch_to(rt_uint32 to);
  159. ; * r0 --> to
  160. .asmfunc
  161. _rt_hw_context_switch_to:
  162. MOV AR1, #_rt_interrupt_to_thread
  163. MOV *AR1, AL
  164. ;#if defined (__VFP_FP__) && !defined(__SOFTFP__)
  165. ; CLEAR CONTROL.FPCA
  166. ; MRS r2, CONTROL ; read
  167. ; BIC r2, #0x04 ; modify
  168. ; MSR CONTROL, r2 ; write-back
  169. ;#endif
  170. ; set from thread to 0
  171. MOV AR1, #_rt_interrupt_from_thread
  172. MOV AR0, #0x0
  173. MOV *AR1, AR0
  174. ; set interrupt flag to 1
  175. MOV AR1, #_rt_thread_switch_interrupt_flag
  176. MOV AR0, #1
  177. MOV *AR1, AR0
  178. TRAP #16
  179. ; never reach here!
  180. .endasmfunc
  181. ; compatible with old version
  182. .asmfunc
  183. _rt_hw_interrupt_thread_switch:
  184. LRETR
  185. NOP
  186. .endasmfunc
  187. .end