context_gcc.S 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2006-09-06 XuXinming first version
  9. */
  10. /*!
  11. * \addtogroup S3C44B0
  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. mov pc, 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. mov pc, 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. stmfd sp!, {r4} @ push cpsr
  42. mrs r4, spsr
  43. stmfd sp!, {r4} @ push spsr
  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 spsr
  47. msr spsr_cxsf, r4
  48. ldmfd sp!, {r4} @ pop new task cpsr
  49. msr cpsr_cxsf, r4
  50. ldmfd sp!, {r0-r12, lr, pc} @ pop new task r0-r12, lr & pc
  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. ldmfd sp!, {r4} @ pop new task cpsr
  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. mov pc, lr