context_gcc.s 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * File : context.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-01-13 weety copy from mini2440
  23. */
  24. #define NOINT 0xc0
  25. .globl __delay
  26. __delay:
  27. subs r0, r0, #1
  28. #if 1
  29. movls pc, lr
  30. subs r0, r0, #1
  31. movls pc, lr
  32. subs r0, r0, #1
  33. movls pc, lr
  34. subs r0, r0, #1
  35. movls pc, lr
  36. subs r0, r0, #1
  37. movls pc, lr
  38. subs r0, r0, #1
  39. movls pc, lr
  40. subs r0, r0, #1
  41. movls pc, lr
  42. subs r0, r0, #1
  43. #endif
  44. bhi __delay
  45. mov pc, lr
  46. /*
  47. * rt_base_t rt_hw_interrupt_disable();
  48. */
  49. .globl rt_hw_interrupt_disable
  50. rt_hw_interrupt_disable:
  51. mrs r0, cpsr
  52. orr r1, r0, #NOINT
  53. msr cpsr_c, r1
  54. mov pc, lr
  55. /*
  56. * void rt_hw_interrupt_enable(rt_base_t level);
  57. */
  58. .globl rt_hw_interrupt_enable
  59. rt_hw_interrupt_enable:
  60. msr cpsr, r0
  61. mov pc, lr
  62. .globl restore_context
  63. @.func restore_context
  64. .globl save_context
  65. @.func save_context
  66. save_context:
  67. stmfd sp!, {lr} @ push pc (lr should be pushed in place of PC)
  68. stmfd sp!, {r0-r12, lr} @ push lr & register file
  69. mrs r4, cpsr
  70. stmfd sp!, {r4} @ push cpsr
  71. mrs r4, spsr
  72. stmfd sp!, {r4} @ push spsr
  73. str sp, [r0] @ store sp in preempted tasks TCB
  74. mov pc, lr
  75. bx lr @ branch back to caller
  76. restore_context:
  77. ldr sp, [r0] @ get new task stack pointer
  78. ldmfd sp!, {r4} @ pop new task spsr
  79. msr spsr_cxsf, r4
  80. ldmfd sp!, {r4} @ pop new task cpsr
  81. msr spsr_cxsf, r4
  82. ldmfd sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc
  83. /*
  84. * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
  85. * r0 --> from
  86. * r1 --> to
  87. */
  88. .globl rt_hw_context_switch
  89. rt_hw_context_switch:
  90. stmfd sp!, {lr} @ push pc (lr should be pushed in place of PC)
  91. stmfd sp!, {r0-r12, lr} @ push lr & register file
  92. mrs r4, cpsr
  93. stmfd sp!, {r4} @ push cpsr
  94. mrs r4, spsr
  95. stmfd sp!, {r4} @ push spsr
  96. str sp, [r0] @ store sp in preempted tasks TCB
  97. ldr sp, [r1] @ get new task stack pointer
  98. ldmfd sp!, {r4} @ pop new task spsr
  99. msr spsr_cxsf, r4
  100. ldmfd sp!, {r4} @ pop new task cpsr
  101. msr spsr_cxsf, r4
  102. ldmfd sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc
  103. /*
  104. * void rt_hw_context_switch_to(rt_uint32 to);
  105. * r0 --> to
  106. */
  107. .globl rt_hw_context_switch_to
  108. rt_hw_context_switch_to:
  109. ldr sp, [r0] @ get new task stack pointer
  110. ldmfd sp!, {r4} @ pop new task spsr
  111. msr spsr_cxsf, r4
  112. ldmfd sp!, {r4} @ pop new task cpsr
  113. msr cpsr_cxsf, r4
  114. ldmfd sp!, {r0-r12, lr, pc} @ pop new task r0-r12, lr & pc
  115. /*
  116. * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
  117. */
  118. .globl rt_thread_switch_interrupt_flag
  119. .globl rt_interrupt_from_thread
  120. .globl rt_interrupt_to_thread
  121. .globl rt_hw_context_switch_interrupt
  122. rt_hw_context_switch_interrupt:
  123. ldr r2, =rt_thread_switch_interrupt_flag
  124. ldr r3, [r2]
  125. cmp r3, #1
  126. beq _reswitch
  127. mov r3, #1 @ set rt_thread_switch_interrupt_flag to 1
  128. str r3, [r2]
  129. ldr r2, =rt_interrupt_from_thread @ set rt_interrupt_from_thread
  130. str r0, [r2]
  131. _reswitch:
  132. ldr r2, =rt_interrupt_to_thread @ set rt_interrupt_to_thread
  133. str r1, [r2]
  134. mov pc, lr