1
0

context_rvds.S 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. ; * 2009-01-20 Bernard first version
  9. ; */
  10. NOINT EQU 0xc0 ; disable interrupt in psr
  11. AREA |.text|, CODE, READONLY, ALIGN=2
  12. ARM
  13. REQUIRE8
  14. PRESERVE8
  15. ;/*
  16. ; * rt_base_t rt_hw_interrupt_disable();
  17. ; */
  18. rt_hw_interrupt_disable PROC
  19. EXPORT rt_hw_interrupt_disable
  20. MRS r0, cpsr
  21. ORR r1, r0, #NOINT
  22. MSR cpsr_c, r1
  23. BX lr
  24. ENDP
  25. ;/*
  26. ; * void rt_hw_interrupt_enable(rt_base_t level);
  27. ; */
  28. rt_hw_interrupt_enable PROC
  29. EXPORT rt_hw_interrupt_enable
  30. MSR cpsr_c, r0
  31. BX lr
  32. ENDP
  33. ;/*
  34. ; * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
  35. ; * r0 --> from
  36. ; * r1 --> to
  37. ; */
  38. rt_hw_context_switch PROC
  39. EXPORT rt_hw_context_switch
  40. STMFD sp!, {lr} ; push pc (lr should be pushed in place of PC)
  41. STMFD sp!, {r0-r12, lr} ; push lr & register file
  42. MRS r4, cpsr
  43. STMFD sp!, {r4} ; push cpsr
  44. MRS r4, spsr
  45. STMFD sp!, {r4} ; push spsr
  46. STR sp, [r0] ; store sp in preempted tasks TCB
  47. LDR sp, [r1] ; get new task stack pointer
  48. LDMFD sp!, {r4} ; pop new task spsr
  49. MSR spsr_cxsf, r4
  50. LDMFD sp!, {r4} ; pop new task cpsr
  51. MSR cpsr_cxsf, r4
  52. LDMFD sp!, {r0-r12, lr, pc} ; pop new task r0-r12, lr & pc
  53. ENDP
  54. ;/*
  55. ; * void rt_hw_context_switch_to(rt_uint32 to);
  56. ; * r0 --> to
  57. ; */
  58. rt_hw_context_switch_to PROC
  59. EXPORT rt_hw_context_switch_to
  60. LDR sp, [r0] ; get new task stack pointer
  61. LDMFD sp!, {r4} ; pop new task spsr
  62. MSR spsr_cxsf, r4
  63. LDMFD sp!, {r4} ; pop new task cpsr
  64. MSR cpsr_cxsf, r4
  65. LDMFD sp!, {r0-r12, lr, pc} ; pop new task r0-r12, lr & pc
  66. ENDP
  67. ;/*
  68. ; * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
  69. ; */
  70. IMPORT rt_thread_switch_interrupt_flag
  71. IMPORT rt_interrupt_from_thread
  72. IMPORT rt_interrupt_to_thread
  73. rt_hw_context_switch_interrupt PROC
  74. EXPORT rt_hw_context_switch_interrupt
  75. LDR r2, =rt_thread_switch_interrupt_flag
  76. LDR r3, [r2]
  77. CMP r3, #1
  78. BEQ _reswitch
  79. MOV r3, #1 ; set rt_thread_switch_interrupt_flag to 1
  80. STR r3, [r2]
  81. LDR r2, =rt_interrupt_from_thread ; set rt_interrupt_from_thread
  82. STR r0, [r2]
  83. _reswitch
  84. LDR r2, =rt_interrupt_to_thread ; set rt_interrupt_to_thread
  85. STR r1, [r2]
  86. BX lr
  87. ENDP
  88. END