context_gcc.S 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 AT91SAM926X
  26. */
  27. /*@{*/
  28. #define NOINT 0xc0
  29. /*
  30. * rt_base_t rt_hw_interrupt_disable();
  31. */
  32. .globl rt_hw_interrupt_disable
  33. rt_hw_interrupt_disable:
  34. mrs r0, cpsr
  35. orr r1, r0, #NOINT
  36. msr cpsr_c, r1
  37. mov pc, lr
  38. /*
  39. * void rt_hw_interrupt_enable(rt_base_t level);
  40. */
  41. .globl rt_hw_interrupt_enable
  42. rt_hw_interrupt_enable:
  43. msr cpsr, r0
  44. mov pc, lr
  45. /*
  46. * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
  47. * r0 --> from
  48. * r1 --> to
  49. */
  50. .globl rt_hw_context_switch
  51. rt_hw_context_switch:
  52. stmfd sp!, {lr} @ push pc (lr should be pushed in place of PC)
  53. stmfd sp!, {r0-r12, lr} @ push lr & register file
  54. mrs r4, cpsr
  55. stmfd sp!, {r4} @ push cpsr
  56. mrs r4, spsr
  57. stmfd sp!, {r4} @ push spsr
  58. str sp, [r0] @ store sp in preempted tasks TCB
  59. ldr sp, [r1] @ get new task stack pointer
  60. ldmfd sp!, {r4} @ pop new task spsr
  61. msr spsr_cxsf, r4
  62. ldmfd sp!, {r4} @ pop new task cpsr
  63. msr spsr_cxsf, r4
  64. ldmfd sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc
  65. /*
  66. * void rt_hw_context_switch_to(rt_uint32 to);
  67. * r0 --> to
  68. */
  69. .globl rt_hw_context_switch_to
  70. rt_hw_context_switch_to:
  71. ldr sp, [r0] @ get new task stack pointer
  72. ldmfd sp!, {r4} @ pop new task spsr
  73. msr spsr_cxsf, r4
  74. ldmfd sp!, {r4} @ pop new task cpsr
  75. msr cpsr_cxsf, r4
  76. ldmfd sp!, {r0-r12, lr, pc} @ pop new task r0-r12, lr & pc
  77. /*
  78. * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
  79. */
  80. .globl rt_thread_switch_interrupt_flag
  81. .globl rt_interrupt_from_thread
  82. .globl rt_interrupt_to_thread
  83. .globl rt_hw_context_switch_interrupt
  84. rt_hw_context_switch_interrupt:
  85. ldr r2, =rt_thread_switch_interrupt_flag
  86. ldr r3, [r2]
  87. cmp r3, #1
  88. beq _reswitch
  89. mov r3, #1 @ set rt_thread_switch_interrupt_flag to 1
  90. str r3, [r2]
  91. ldr r2, =rt_interrupt_from_thread @ set rt_interrupt_from_thread
  92. str r0, [r2]
  93. _reswitch:
  94. ldr r2, =rt_interrupt_to_thread @ set rt_interrupt_to_thread
  95. str r1, [r2]
  96. mov pc, lr