context.s 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. ; r1 --> to
  63. .asmfunc
  64. _rt_hw_context_switch_interrupt:
  65. _rt_hw_context_switch:
  66. MOV AR0, AL
  67. ; set rt_thread_switch_interrupt_flag to 1
  68. MOVL XAR2, #_rt_thread_switch_interrupt_flag
  69. MOVL XAR3, *XAR2
  70. MOVL ACC, XAR3
  71. CMPB AL, #1
  72. B _reswitch, EQ
  73. MOVL XAR3, #1
  74. MOVL *XAR2, XAR3
  75. MOVL XAR2, #_rt_interrupt_from_thread ; set rt_interrupt_from_thread
  76. MOVL *XAR2, XAR0
  77. _reswitch:
  78. MOVL XAR2, #_rt_interrupt_to_thread ; set rt_interrupt_to_thread
  79. MOVL *XAR2, XAR1
  80. TRAP #16
  81. LRETR
  82. .endasmfunc
  83. .asmfunc
  84. _RTOSINT_Handler:
  85. ; disable interrupt to protect context switch
  86. DINT
  87. ; get rt_thread_switch_interrupt_flag
  88. MOV AR0, #_rt_thread_switch_interrupt_flag
  89. MOV AL, *AR0
  90. MOV AR1, AL
  91. CMP AR1, #0
  92. B rtosint_exit, EQ ; pendsv already handled
  93. ; clear rt_thread_switch_interrupt_flag to 0
  94. MOV AR1, #0x00
  95. MOV *AR0, AR1
  96. MOV AR0, #_rt_interrupt_from_thread
  97. MOV AL, *AR0
  98. MOV AR1, AL
  99. CMP AR1, #0
  100. B switch_to_thread, EQ ; skip register save at the first time
  101. ;MOVZ AR1, @SP ; get from thread stack pointer
  102. ;#if defined (__VFP_FP__) && !defined(__SOFTFP__)
  103. ; TST lr, #0x10 ; if(!EXC_RETURN[4])
  104. ; VSTMDBEQ r1!, {d8 - d15} ; push FPU register s16~s31
  105. ;#endif
  106. RT_CTX_SAVE ; push r4 - r11 register
  107. ;#if defined (__VFP_FP__) && !defined(__SOFTFP__)
  108. ; MOV r4, #0x00 ; flag = 0
  109. ; TST lr, #0x10 ; if(!EXC_RETURN[4])
  110. ; MOVEQ r4, #0x01 ; flag = 1
  111. ; STMFD r1!, {r4} ; push flag
  112. ;#endif
  113. MOV AL, *AR0
  114. MOV AR1, AL
  115. MOVZ AR1, @SP ; get from thread stack pointer
  116. MOV *AR0, AR1 ; update from thread stack pointer
  117. switch_to_thread:
  118. MOV AR1, #_rt_interrupt_to_thread
  119. MOV AL, *AR1
  120. MOV AR1, AL
  121. MOV AL, *AR1
  122. MOV AR1, AL ; load thread stack pointer
  123. ;#if defined (__VFP_FP__) && !defined(__SOFTFP__)
  124. ; LDMFD r1!, {r3} ; pop flag
  125. ;#endif
  126. MOV @SP, AR1
  127. INC SP
  128. RT_CTX_RESTORE ; pop r4 - r11 register
  129. rtosint_exit:
  130. ; restore interrupt
  131. EINT
  132. IRET
  133. .endasmfunc
  134. .asmfunc
  135. _rt_hw_get_st0:
  136. PUSH ST0
  137. POP AL
  138. LRETR
  139. .endasmfunc
  140. .asmfunc
  141. _rt_hw_get_st1:
  142. PUSH ST1
  143. POP AL
  144. LRETR
  145. .endasmfunc
  146. ;
  147. ; * void rt_hw_context_switch_to(rt_uint32 to);
  148. ; * r0 --> to
  149. .asmfunc
  150. _rt_hw_context_switch_to:
  151. MOV AR1, #_rt_interrupt_to_thread
  152. MOV *AR1, AL
  153. ;#if defined (__VFP_FP__) && !defined(__SOFTFP__)
  154. ; CLEAR CONTROL.FPCA
  155. ; MRS r2, CONTROL ; read
  156. ; BIC r2, #0x04 ; modify
  157. ; MSR CONTROL, r2 ; write-back
  158. ;#endif
  159. ; set from thread to 0
  160. MOV AR1, #_rt_interrupt_from_thread
  161. MOV AR0, #0x0
  162. MOV *AR1, AR0
  163. ; set interrupt flag to 1
  164. MOV AR1, #_rt_thread_switch_interrupt_flag
  165. MOV AR0, #1
  166. MOV *AR1, AR0
  167. TRAP #16
  168. ; never reach here!
  169. .endasmfunc
  170. ; compatible with old version
  171. .asmfunc
  172. _rt_hw_interrupt_thread_switch:
  173. LRETR
  174. NOP
  175. .endasmfunc
  176. .end