context_rvds.S 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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-08-14 weety copy from mini2440
  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. 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!, {r0-r12, lr, pc}^ ; pop new task r0-r12, lr & pc
  49. endp
  50. ;/*
  51. ; * void rt_hw_context_switch_to(rt_uint32 to);
  52. ; * r0 --> to
  53. ; */
  54. rt_hw_context_switch_to proc
  55. export 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. ldmfd sp!, {r0-r12, lr, pc}^ ; pop new task r0-r12, lr & pc
  60. endp
  61. ;/*
  62. ; * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
  63. ; */
  64. import rt_thread_switch_interrupt_flag
  65. import rt_interrupt_from_thread
  66. import rt_interrupt_to_thread
  67. rt_hw_context_switch_interrupt proc
  68. export rt_hw_context_switch_interrupt
  69. ldr r2, =rt_thread_switch_interrupt_flag
  70. ldr r3, [r2]
  71. cmp r3, #1
  72. beq _reswitch
  73. mov r3, #1 ; set flag to 1
  74. str r3, [r2]
  75. ldr r2, =rt_interrupt_from_thread ; set rt_interrupt_from_thread
  76. str r0, [r2]
  77. _reswitch
  78. ldr r2, =rt_interrupt_to_thread ; set rt_interrupt_to_thread
  79. str r1, [r2]
  80. bx lr
  81. endp
  82. end