context_gcc.S 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * File : context.S
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2013, 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. * 2013-07-05 Bernard the first version
  23. */
  24. .section .text, "ax"
  25. /*
  26. * rt_base_t rt_hw_interrupt_disable();
  27. */
  28. .globl rt_hw_interrupt_disable
  29. rt_hw_interrupt_disable:
  30. mrs r0, cpsr
  31. cpsid i
  32. bx lr
  33. /*
  34. * void rt_hw_interrupt_enable(rt_base_t level);
  35. */
  36. .globl rt_hw_interrupt_enable
  37. rt_hw_interrupt_enable:
  38. msr cpsr, r0
  39. bx lr
  40. /*
  41. * void rt_hw_context_switch_to(rt_uint32 to);
  42. * r0 --> to
  43. */
  44. .globl rt_hw_context_switch_to
  45. rt_hw_context_switch_to:
  46. ldr sp, [r0] @ get new task stack pointer
  47. ldmfd sp!, {r4} @ pop new task spsr
  48. msr spsr_cxsf, r4
  49. ldmfd sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc
  50. .section .bss.share.isr
  51. _guest_switch_lvl:
  52. .word 0
  53. .section .text.isr, "ax"
  54. /*
  55. * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
  56. * r0 --> from
  57. * r1 --> to
  58. */
  59. .globl rt_hw_context_switch
  60. rt_hw_context_switch:
  61. stmfd sp!, {lr} @ push pc (lr should be pushed in place of PC)
  62. stmfd sp!, {r0-r12, lr} @ push lr & register file
  63. mrs r4, cpsr
  64. tst lr, #0x01
  65. orrne r4, r4, #0x20 @ it's thumb code
  66. stmfd sp!, {r4} @ push cpsr
  67. str sp, [r0] @ store sp in preempted tasks TCB
  68. ldr sp, [r1] @ get new task stack pointer
  69. ldmfd sp!, {r4} @ pop new task cpsr to spsr
  70. msr spsr_cxsf, r4
  71. ldmfd sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc, copy spsr to cpsr
  72. /*
  73. * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
  74. */
  75. .globl rt_thread_switch_interrupt_flag
  76. .globl rt_interrupt_from_thread
  77. .globl rt_interrupt_to_thread
  78. .globl rt_hw_context_switch_interrupt
  79. rt_hw_context_switch_interrupt:
  80. ldr r2, =rt_thread_switch_interrupt_flag
  81. ldr r3, [r2]
  82. cmp r3, #1
  83. beq _reswitch
  84. ldr ip, =rt_interrupt_from_thread @ set rt_interrupt_from_thread
  85. mov r3, #1 @ set rt_thread_switch_interrupt_flag to 1
  86. str r0, [ip]
  87. str r3, [r2]
  88. _reswitch:
  89. ldr r2, =rt_interrupt_to_thread @ set rt_interrupt_to_thread
  90. str r1, [r2]
  91. bx lr