context_rvds.S 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. ; * this program is free software; you can redistribute it and/or modify
  7. ; * it under the terms of the gnu general public license as published by
  8. ; * the free software foundation; either version 2 of the license, or
  9. ; * (at your option) any later version.
  10. ; *
  11. ; * this program is distributed in the hope that it will be useful,
  12. ; * but without any warranty; without even the implied warranty of
  13. ; * merchantability or fitness for a particular purpose. see the
  14. ; * gnu general public license for more details.
  15. ; *
  16. ; * you should have received a copy of the gnu general public license along
  17. ; * with this program; if not, write to the free software foundation, inc.,
  18. ; * 51 franklin street, fifth floor, boston, ma 02110-1301 usa.
  19. ; *
  20. ; * change logs:
  21. ; * date author notes
  22. ; * 2011-08-14 weety copy from mini2440
  23. ; */
  24. NOINT EQU 0XC0 ; disable interrupt in psr
  25. AREA |.TEXT|, CODE, READONLY, ALIGN=2
  26. ARM
  27. REQUIRE8
  28. PRESERVE8
  29. ;/*
  30. ; * rt_base_t rt_hw_interrupt_disable();
  31. ; */
  32. rt_hw_interrupt_disable PROC
  33. EXPORT rt_hw_interrupt_disable
  34. MRS R0, CPSR
  35. ORR R1, R0, #NOINT
  36. MSR CPSR_C, R1
  37. BX LR
  38. ENDP
  39. ;/*
  40. ; * void rt_hw_interrupt_enable(rt_base_t level);
  41. ; */
  42. rt_hw_interrupt_enable proc
  43. export rt_hw_interrupt_enable
  44. msr cpsr_c, r0
  45. bx lr
  46. endp
  47. ;/*
  48. ; * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
  49. ; * r0 --> from
  50. ; * r1 --> to
  51. ; */
  52. rt_hw_context_switch proc
  53. export rt_hw_context_switch
  54. stmfd sp!, {lr} ; push pc (lr should be pushed in place of pc)
  55. stmfd sp!, {r0-r12, lr} ; push lr & register file
  56. mrs r4, cpsr
  57. stmfd sp!, {r4} ; push cpsr
  58. str sp, [r0] ; store sp in preempted tasks tcb
  59. ldr sp, [r1] ; get new task stack pointer
  60. ldmfd sp!, {r4} ; pop new task spsr
  61. msr spsr_cxsf, r4
  62. ldmfd sp!, {r0-r12, lr, pc}^ ; pop new task r0-r12, lr & pc
  63. endp
  64. ;/*
  65. ; * void rt_hw_context_switch_to(rt_uint32 to);
  66. ; * r0 --> to
  67. ; */
  68. rt_hw_context_switch_to proc
  69. export rt_hw_context_switch_to
  70. ldr sp, [r0] ; get new task stack pointer
  71. ldmfd sp!, {r4} ; pop new task spsr
  72. msr spsr_cxsf, r4
  73. ldmfd sp!, {r0-r12, lr, pc}^ ; pop new task r0-r12, lr & pc
  74. endp
  75. ;/*
  76. ; * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
  77. ; */
  78. import rt_thread_switch_interrupt_flag
  79. import rt_interrupt_from_thread
  80. import rt_interrupt_to_thread
  81. rt_hw_context_switch_interrupt proc
  82. export rt_hw_context_switch_interrupt
  83. ldr r2, =rt_thread_switch_interrupt_flag
  84. ldr r3, [r2]
  85. cmp r3, #1
  86. beq _reswitch
  87. mov r3, #1 ; set flag to 1
  88. str r3, [r2]
  89. ldr r2, =rt_interrupt_from_thread ; set rt_interrupt_from_thread
  90. str r0, [r2]
  91. _reswitch
  92. ldr r2, =rt_interrupt_to_thread ; set rt_interrupt_to_thread
  93. str r1, [r2]
  94. bx lr
  95. endp
  96. end