context_gcc.S 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. /*!
  25. * \addtogroup ARMv6
  26. */
  27. /*@{*/
  28. #include <rtconfig.h>
  29. #define NOINT 0xc0
  30. #define FPEXC_EN (1 << 30) /* VFP enable bit */
  31. /*
  32. * rt_base_t rt_hw_interrupt_disable();
  33. */
  34. .globl rt_hw_interrupt_disable
  35. rt_hw_interrupt_disable:
  36. mrs r0, cpsr
  37. cpsid if
  38. bx lr
  39. /*
  40. * void rt_hw_interrupt_enable(rt_base_t level);
  41. */
  42. .globl rt_hw_interrupt_enable
  43. rt_hw_interrupt_enable:
  44. msr cpsr_c, r0
  45. bx lr
  46. /*
  47. * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
  48. * r0 --> from
  49. * r1 --> to
  50. */
  51. .globl rt_hw_context_switch
  52. rt_hw_context_switch:
  53. stmfd sp!, {lr} @ push pc (lr should be pushed in place of PC)
  54. stmfd sp!, {r0-r12, lr} @ push lr & register file
  55. mrs r4, cpsr
  56. tst lr, #0x01
  57. orrne r4, r4, #0x20 @ it's thumb code
  58. stmfd sp!, {r4} @ push cpsr
  59. str sp, [r0] @ store sp in preempted tasks TCB
  60. ldr sp, [r1] @ get new task stack pointer
  61. ldmfd sp!, {r4} @ pop new task cpsr to spsr
  62. msr spsr_cxsf, r4
  63. #ifdef RT_USING_VFP
  64. vmrs r0, fpexc
  65. bic r0, r0, #FPEXC_EN @ always disable VFP so we can
  66. @ lazily save/restore the old state.
  67. vmsr fpexc, r0
  68. #endif
  69. _do_switch:
  70. ldmfd sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc, copy spsr to cpsr
  71. /*
  72. * void rt_hw_context_switch_to(rt_uint32 to);
  73. * r0 --> to
  74. */
  75. .globl rt_hw_context_switch_to
  76. rt_hw_context_switch_to:
  77. ldr sp, [r0] @ get new task stack pointer
  78. ldmfd sp!, {r4} @ pop new task spsr
  79. msr spsr_cxsf, r4
  80. bic r4, r4, #0x20 @ must be ARM mode
  81. msr cpsr_cxsf, r4
  82. #ifdef RT_USING_VFP
  83. vmrs r0, fpexc
  84. bic r0, r0, #FPEXC_EN @ always disable VFP so we can
  85. @ lazily save/restore the old state.
  86. vmsr fpexc, r0
  87. #endif
  88. ldmfd sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc
  89. /*
  90. * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
  91. */
  92. .globl rt_thread_switch_interrupt_flag
  93. .globl rt_interrupt_from_thread
  94. .globl rt_interrupt_to_thread
  95. .globl rt_hw_context_switch_interrupt
  96. rt_hw_context_switch_interrupt:
  97. ldr r2, =rt_thread_switch_interrupt_flag
  98. ldr r3, [r2]
  99. cmp r3, #1
  100. beq _reswitch
  101. mov r3, #1 @ set rt_thread_switch_interrupt_flag to 1
  102. str r3, [r2]
  103. ldr r2, =rt_interrupt_from_thread @ set rt_interrupt_from_thread
  104. str r0, [r2]
  105. _reswitch:
  106. ldr r2, =rt_interrupt_to_thread @ set rt_interrupt_to_thread
  107. str r1, [r2]
  108. bx lr