context_gcc.S 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. * 2013-07-05 Bernard the first version
  9. */
  10. /*
  11. * rt_base_t rt_hw_interrupt_disable();
  12. */
  13. .globl rt_hw_interrupt_disable
  14. rt_hw_interrupt_disable:
  15. mrs r0, cpsr
  16. cpsid if
  17. bx lr
  18. /*
  19. * void rt_hw_interrupt_enable(rt_base_t level);
  20. */
  21. .globl rt_hw_interrupt_enable
  22. rt_hw_interrupt_enable:
  23. msr cpsr_c, r0
  24. bx lr
  25. /*
  26. * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
  27. * r0 --> from
  28. * r1 --> to
  29. */
  30. .globl rt_hw_context_switch
  31. rt_hw_context_switch:
  32. stmfd sp!, {lr} @ push pc (lr should be pushed in place of PC)
  33. stmfd sp!, {r0-r12, lr} @ push lr & register file
  34. mrs r4, cpsr
  35. tst lr, #0x01
  36. orrne r4, r4, #0x20 @ it's thumb code
  37. stmfd sp!, {r4} @ push cpsr
  38. str sp, [r0] @ store sp in preempted tasks TCB
  39. ldr sp, [r1] @ get new task stack pointer
  40. ldmfd sp!, {r4} @ pop new task cpsr to spsr
  41. msr spsr_cxsf, r4
  42. _do_switch:
  43. ldmfd sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc, copy spsr to cpsr
  44. /*
  45. * void rt_hw_context_switch_to(rt_uint32 to);
  46. * r0 --> to
  47. */
  48. .globl rt_hw_context_switch_to
  49. rt_hw_context_switch_to:
  50. ldr sp, [r0] @ get new task stack pointer
  51. ldmfd sp!, {r4} @ pop new task spsr
  52. msr spsr_cxsf, r4
  53. bic r4, r4, #0x20 @ must be ARM mode
  54. msr cpsr_cxsf, r4
  55. ldmfd sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc
  56. /*
  57. * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
  58. */
  59. .globl rt_thread_switch_interrupt_flag
  60. .globl rt_interrupt_from_thread
  61. .globl rt_interrupt_to_thread
  62. .globl rt_hw_context_switch_interrupt
  63. rt_hw_context_switch_interrupt:
  64. ldr r2, =rt_thread_switch_interrupt_flag
  65. ldr r3, [r2]
  66. cmp r3, #1
  67. beq _reswitch
  68. mov r3, #1 @ set rt_thread_switch_interrupt_flag to 1
  69. str r3, [r2]
  70. ldr r2, =rt_interrupt_from_thread @ set rt_interrupt_from_thread
  71. str r0, [r2]
  72. _reswitch:
  73. ldr r2, =rt_interrupt_to_thread @ set rt_interrupt_to_thread
  74. str r1, [r2]
  75. bx lr