1
0

context_gcc.S 2.2 KB

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