context.s 4.7 KB

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