context_rvds.S 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. ;/*
  2. ; * File : context_rvds.S
  3. ; * This file is part of RT-Thread RTOS
  4. ; * COPYRIGHT (C) 2006, RT-Thread Development Team
  5. ; *
  6. ; * This program is free software; you can redistribute it and/or modify
  7. ; * it under the terms of the GNU General Public License as published by
  8. ; * the Free Software Foundation; either version 2 of the License, or
  9. ; * (at your option) any later version.
  10. ; *
  11. ; * This program is distributed in the hope that it will be useful,
  12. ; * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ; * GNU General Public License for more details.
  15. ; *
  16. ; * You should have received a copy of the GNU General Public License along
  17. ; * with this program; if not, write to the Free Software Foundation, Inc.,
  18. ; * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. ; *
  20. ; * Change Logs:
  21. ; * Date Author Notes
  22. ; * 2011-08-14 weety copy from mini2440
  23. ; */
  24. NOINT EQU 0xc0 ; disable interrupt in psr
  25. AREA |.text|, CODE, READONLY, ALIGN=2
  26. ARM
  27. REQUIRE8
  28. PRESERVE8
  29. ;/*
  30. ; * rt_base_t rt_hw_interrupt_disable();
  31. ; */
  32. rt_hw_interrupt_disable PROC
  33. EXPORT rt_hw_interrupt_disable
  34. MRS r0, cpsr
  35. ORR r1, r0, #NOINT
  36. MSR cpsr_c, r1
  37. BX lr
  38. ENDP
  39. ;/*
  40. ; * void rt_hw_interrupt_enable(rt_base_t level);
  41. ; */
  42. rt_hw_interrupt_enable PROC
  43. EXPORT rt_hw_interrupt_enable
  44. MSR cpsr_c, r0
  45. BX lr
  46. ENDP
  47. ;/*
  48. ; * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
  49. ; * r0 --> from
  50. ; * r1 --> to
  51. ; */
  52. rt_hw_context_switch PROC
  53. EXPORT rt_hw_context_switch
  54. STMFD sp!, {lr} ; push pc (lr should be pushed in place of PC)
  55. STMFD sp!, {r0-r12, lr} ; push lr & register file
  56. MRS r4, cpsr
  57. STMFD sp!, {r4} ; push cpsr
  58. MRS r4, spsr
  59. STMFD sp!, {r4} ; push spsr
  60. STR sp, [r0] ; store sp in preempted tasks TCB
  61. LDR sp, [r1] ; get new task stack pointer
  62. LDMFD sp!, {r4} ; pop new task spsr
  63. MSR spsr_cxsf, r4
  64. LDMFD sp!, {r4} ; pop new task cpsr
  65. MSR spsr_cxsf, r4
  66. LDMFD sp!, {r0-r12, lr, pc}^ ; pop new task r0-r12, lr & pc
  67. ENDP
  68. ;/*
  69. ; * void rt_hw_context_switch_to(rt_uint32 to);
  70. ; * r0 --> to
  71. ; */
  72. rt_hw_context_switch_to PROC
  73. EXPORT rt_hw_context_switch_to
  74. LDR sp, [r0] ; get new task stack pointer
  75. LDMFD sp!, {r4} ; pop new task spsr
  76. MSR spsr_cxsf, r4
  77. LDMFD sp!, {r4} ; pop new task cpsr
  78. MSR cpsr_cxsf, r4
  79. LDMFD sp!, {r0-r12, lr, pc} ; pop new task r0-r12, lr & pc
  80. ENDP
  81. ;/*
  82. ; * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
  83. ; */
  84. IMPORT rt_thread_switch_interrupt_flag
  85. IMPORT rt_interrupt_from_thread
  86. IMPORT rt_interrupt_to_thread
  87. rt_hw_context_switch_interrupt PROC
  88. EXPORT rt_hw_context_switch_interrupt
  89. LDR r2, =rt_thread_switch_interrupt_flag
  90. LDR r3, [r2]
  91. CMP r3, #1
  92. BEQ _reswitch
  93. MOV r3, #1 ; set rt_thread_switch_interrupt_flag to 1
  94. STR r3, [r2]
  95. LDR r2, =rt_interrupt_from_thread ; set rt_interrupt_from_thread
  96. STR r0, [r2]
  97. _reswitch
  98. LDR r2, =rt_interrupt_to_thread ; set rt_interrupt_to_thread
  99. STR r1, [r2]
  100. BX lr
  101. ENDP
  102. END