context_gcc.S 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2011-01-13 weety copy from mini2440
  9. */
  10. /*!
  11. * \addtogroup ARMv6
  12. */
  13. /*@{*/
  14. #include <rtconfig.h>
  15. #define NOINT 0xc0
  16. #define FPEXC_EN (1 << 30) /* VFP enable bit */
  17. /*
  18. * rt_base_t rt_hw_interrupt_disable();
  19. */
  20. .globl rt_hw_interrupt_disable
  21. rt_hw_interrupt_disable:
  22. mrs r0, cpsr
  23. cpsid if
  24. bx lr
  25. /*
  26. * void rt_hw_interrupt_enable(rt_base_t level);
  27. */
  28. .globl rt_hw_interrupt_enable
  29. rt_hw_interrupt_enable:
  30. msr cpsr_c, r0
  31. bx lr
  32. /*
  33. * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
  34. * r0 --> from
  35. * r1 --> to
  36. */
  37. .globl rt_hw_context_switch
  38. rt_hw_context_switch:
  39. stmfd sp!, {lr} @ push pc (lr should be pushed in place of PC)
  40. stmfd sp!, {r0-r12, lr} @ push lr & register file
  41. mrs r4, cpsr
  42. tst lr, #0x01
  43. orrne r4, r4, #0x20 @ it's thumb code
  44. stmfd sp!, {r4} @ push cpsr
  45. str sp, [r0] @ store sp in preempted tasks TCB
  46. ldr sp, [r1] @ get new task stack pointer
  47. ldmfd sp!, {r4} @ pop new task cpsr to spsr
  48. msr spsr_cxsf, r4
  49. _do_switch:
  50. ldmfd sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc, copy spsr to cpsr
  51. /*
  52. * void rt_hw_context_switch_to(rt_uint32 to);
  53. * r0 --> to
  54. */
  55. .globl rt_hw_context_switch_to
  56. rt_hw_context_switch_to:
  57. ldr sp, [r0] @ get new task stack pointer
  58. ldmfd sp!, {r4} @ pop new task spsr
  59. msr spsr_cxsf, r4
  60. bic r4, r4, #0x20 @ must be ARM mode
  61. msr cpsr_cxsf, r4
  62. ldmfd sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc
  63. /*
  64. * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
  65. */
  66. .globl rt_thread_switch_interrupt_flag
  67. .globl rt_interrupt_from_thread
  68. .globl rt_interrupt_to_thread
  69. .globl rt_hw_context_switch_interrupt
  70. rt_hw_context_switch_interrupt:
  71. ldr r2, =rt_thread_switch_interrupt_flag
  72. ldr r3, [r2]
  73. cmp r3, #1
  74. beq _reswitch
  75. mov r3, #1 @ set rt_thread_switch_interrupt_flag to 1
  76. str r3, [r2]
  77. ldr r2, =rt_interrupt_from_thread @ set rt_interrupt_from_thread
  78. str r0, [r2]
  79. _reswitch:
  80. ldr r2, =rt_interrupt_to_thread @ set rt_interrupt_to_thread
  81. str r1, [r2]
  82. bx lr