context.s 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. RT_CTX_RESTORE ; pop r4 - r11 register
  128. rtosint_exit:
  129. ; restore interrupt
  130. EINT
  131. IRET
  132. .endasmfunc
  133. .asmfunc
  134. _rt_hw_get_st0:
  135. PUSH ST0
  136. POP AL
  137. LRETR
  138. .endasmfunc
  139. .asmfunc
  140. _rt_hw_get_st1:
  141. PUSH ST1
  142. POP AL
  143. LRETR
  144. .endasmfunc
  145. ;
  146. ; * void rt_hw_context_switch_to(rt_uint32 to);
  147. ; * r0 --> to
  148. .asmfunc
  149. _rt_hw_context_switch_to:
  150. MOV AR1, #_rt_interrupt_to_thread
  151. MOV *AR1, AL
  152. ;#if defined (__VFP_FP__) && !defined(__SOFTFP__)
  153. ; CLEAR CONTROL.FPCA
  154. ; MRS r2, CONTROL ; read
  155. ; BIC r2, #0x04 ; modify
  156. ; MSR CONTROL, r2 ; write-back
  157. ;#endif
  158. ; set from thread to 0
  159. MOV AR1, #_rt_interrupt_from_thread
  160. MOV AR0, #0x0
  161. MOV *AR1, AR0
  162. ; set interrupt flag to 1
  163. MOV AR1, #_rt_thread_switch_interrupt_flag
  164. MOV AR0, #1
  165. MOV *AR1, AR0
  166. TRAP #16
  167. ; never reach here!
  168. .endasmfunc
  169. ; compatible with old version
  170. .asmfunc
  171. _rt_hw_interrupt_thread_switch:
  172. LRETR
  173. NOP
  174. .endasmfunc
  175. .end