context_gcc.S 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * COPYRIGHT (C) 2013-2014, Shanghai Real-Thread Technology Co., Ltd
  3. *
  4. * All rights reserved.
  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. #define NOINT 0xc0
  21. /*
  22. * rt_base_t rt_hw_interrupt_disable();
  23. */
  24. .globl rt_hw_interrupt_disable
  25. rt_hw_interrupt_disable:
  26. mrs r0, cpsr
  27. orr r1, r0, #NOINT
  28. msr cpsr_c, r1
  29. bx lr
  30. /*
  31. * void rt_hw_interrupt_enable(rt_base_t level);
  32. */
  33. .globl rt_hw_interrupt_enable
  34. rt_hw_interrupt_enable:
  35. msr cpsr, r0
  36. bx lr
  37. /*
  38. * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
  39. * r0 --> from
  40. * r1 --> to
  41. */
  42. .globl rt_hw_context_switch
  43. rt_hw_context_switch:
  44. stmfd sp!, {lr} @ push pc (lr should be pushed in place of PC)
  45. stmfd sp!, {r0-r12, lr} @ push lr & register file
  46. mrs r4, cpsr
  47. tst lr, #0x01
  48. beq _ARM_MODE
  49. orr r4, r4, #0x20 @ it's thumb code
  50. _ARM_MODE:
  51. stmfd sp!, {r4} @ push cpsr
  52. str sp, [r0] @ store sp in preempted tasks TCB
  53. ldr sp, [r1] @ get new task stack pointer
  54. ldmfd sp!, {r4} @ pop new task cpsr to spsr
  55. msr spsr_cxsf, r4
  56. ldmfd sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc, copy spsr to cpsr
  57. /*
  58. * void rt_hw_context_switch_to(rt_uint32 to);
  59. * r0 --> to
  60. */
  61. .globl rt_hw_context_switch_to
  62. rt_hw_context_switch_to:
  63. ldr sp, [r0] @ get new task stack pointer
  64. ldmfd sp!, {r4} @ pop new task spsr
  65. msr spsr_cxsf, r4
  66. bic r4, r4, #0x20 @ must be ARM mode
  67. msr cpsr_cxsf, r4
  68. ldmfd sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc
  69. /*
  70. * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
  71. */
  72. .globl rt_thread_switch_interrupt_flag
  73. .globl rt_interrupt_from_thread
  74. .globl rt_interrupt_to_thread
  75. .globl rt_hw_context_switch_interrupt
  76. rt_hw_context_switch_interrupt:
  77. ldr r2, =rt_thread_switch_interrupt_flag
  78. ldr r3, [r2]
  79. cmp r3, #1
  80. beq _reswitch
  81. mov r3, #1 @ set rt_thread_switch_interrupt_flag to 1
  82. str r3, [r2]
  83. ldr r2, =rt_interrupt_from_thread @ set rt_interrupt_from_thread
  84. str r0, [r2]
  85. _reswitch:
  86. ldr r2, =rt_interrupt_to_thread @ set rt_interrupt_to_thread
  87. str r1, [r2]
  88. bx lr