context_rvds.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ;/*
  2. ; * File : context_rvds.S
  3. ; * This file is part of RT-Thread RTOS
  4. ; * COPYRIGHT (C) 2006, RT-Thread Development Team
  5. ; *
  6. ; * The license and distribution terms for this file may be
  7. ; * found in the file LICENSE in this distribution or at
  8. ; * http://www.rt-thread.org/license/LICENSE
  9. ; *
  10. ; * Change Logs:
  11. ; * Date Author Notes
  12. ; * 2009-01-20 Bernard first version
  13. ; */
  14. NOINT EQU 0xc0 ; disable interrupt in psr
  15. AREA |.text|, CODE, READONLY, ALIGN=2
  16. ARM
  17. REQUIRE8
  18. PRESERVE8
  19. ;/*
  20. ; * rt_base_t rt_hw_interrupt_disable();
  21. ; */
  22. rt_hw_interrupt_disable PROC
  23. EXPORT rt_hw_interrupt_disable
  24. MRS r0, cpsr
  25. ORR r1, r0, #NOINT
  26. MSR cpsr_c, r1
  27. BX lr
  28. ENDP
  29. ;/*
  30. ; * void rt_hw_interrupt_enable(rt_base_t level);
  31. ; */
  32. rt_hw_interrupt_enable PROC
  33. EXPORT rt_hw_interrupt_enable
  34. MSR cpsr_c, r0
  35. BX lr
  36. ENDP
  37. ;/*
  38. ; * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
  39. ; * r0 --> from
  40. ; * r1 --> to
  41. ; */
  42. rt_hw_context_switch PROC
  43. EXPORT rt_hw_context_switch
  44. STMFD sp!, {lr} ; push pc (lr should be pushed in place of PC)
  45. STMFD sp!, {r0-r12, lr} ; push lr & register file
  46. MRS r4, cpsr
  47. STMFD sp!, {r4} ; push cpsr
  48. MRS r4, spsr
  49. STMFD sp!, {r4} ; push spsr
  50. STR sp, [r0] ; store sp in preempted tasks TCB
  51. LDR sp, [r1] ; get new task stack pointer
  52. LDMFD sp!, {r4} ; pop new task spsr
  53. MSR spsr_cxsf, r4
  54. LDMFD sp!, {r4} ; pop new task cpsr
  55. MSR cpsr_cxsf, r4
  56. LDMFD sp!, {r0-r12, lr, pc} ; pop new task r0-r12, lr & pc
  57. ENDP
  58. ;/*
  59. ; * void rt_hw_context_switch_to(rt_uint32 to);
  60. ; * r0 --> to
  61. ; */
  62. rt_hw_context_switch_to PROC
  63. EXPORT rt_hw_context_switch_to
  64. LDR sp, [r0] ; get new task stack pointer
  65. LDMFD sp!, {r4} ; pop new task spsr
  66. MSR spsr_cxsf, r4
  67. LDMFD sp!, {r4} ; pop new task cpsr
  68. MSR cpsr_cxsf, r4
  69. LDMFD sp!, {r0-r12, lr, pc} ; pop new task r0-r12, lr & pc
  70. ENDP
  71. ;/*
  72. ; * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
  73. ; */
  74. IMPORT rt_thread_switch_interrput_flag
  75. IMPORT rt_interrupt_from_thread
  76. IMPORT rt_interrupt_to_thread
  77. rt_hw_context_switch_interrupt PROC
  78. EXPORT rt_hw_context_switch_interrupt
  79. LDR r2, =rt_thread_switch_interrput_flag
  80. LDR r3, [r2]
  81. CMP r3, #1
  82. BEQ _reswitch
  83. MOV r3, #1 ; set rt_thread_switch_interrput_flag to 1
  84. STR r3, [r2]
  85. LDR r2, =rt_interrupt_from_thread ; set rt_interrupt_from_thread
  86. STR r0, [r2]
  87. _reswitch
  88. LDR r2, =rt_interrupt_to_thread ; set rt_interrupt_to_thread
  89. STR r1, [r2]
  90. BX lr
  91. ENDP
  92. END