context_iar.S 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. ;/*
  2. ; * File : context_iar.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. ; * 2015-04-15 ArdaFu convert from context_gcc.s
  24. ; */
  25. #define NOINT 0xc0
  26. SECTION .text:CODE(6)
  27. /*
  28. * rt_base_t rt_hw_interrupt_disable();
  29. */
  30. PUBLIC rt_hw_interrupt_disable
  31. rt_hw_interrupt_disable:
  32. MRS R0, CPSR
  33. ORR R1, R0, #NOINT
  34. MSR CPSR_C, R1
  35. MOV PC, LR
  36. /*
  37. * void rt_hw_interrupt_enable(rt_base_t level);
  38. */
  39. PUBLIC rt_hw_interrupt_enable
  40. rt_hw_interrupt_enable:
  41. MSR CPSR_CXSF, R0
  42. MOV PC, LR
  43. /*
  44. * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
  45. * r0 --> from
  46. * r1 --> to
  47. */
  48. PUBLIC rt_hw_context_switch
  49. rt_hw_context_switch:
  50. STMFD SP!, {LR} ; push pc (lr should be pushed in place of PC)
  51. STMFD SP!, {R0-R12, LR} ; push lr & register file
  52. MRS R4, CPSR
  53. STMFD SP!, {R4} ; push cpsr
  54. STR SP, [R0] ; store sp in preempted tasks TCB
  55. LDR SP, [R1] ; get new task stack pointer
  56. LDMFD SP!, {R4} ; pop new task spsr
  57. MSR SPSR_cxsf, R4
  58. LDMFD SP!, {R0-R12, LR, PC}^ ; pop new task r0-r12, lr & pc
  59. /*
  60. * void rt_hw_context_switch_to(rt_uint32 to);
  61. * r0 --> to
  62. */
  63. PUBLIC rt_hw_context_switch_to
  64. rt_hw_context_switch_to:
  65. LDR SP, [R0] ; get new task stack pointer
  66. LDMFD SP!, {R4} ; pop new task spsr
  67. MSR SPSR_cxsf, R4
  68. LDMFD SP!, {R0-R12, LR, PC}^ ; pop new task r0-r12, lr & pc
  69. /*
  70. * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
  71. */
  72. IMPORT rt_thread_switch_interrupt_flag
  73. IMPORT rt_interrupt_from_thread
  74. IMPORT rt_interrupt_to_thread
  75. PUBLIC rt_hw_context_switch_interrupt
  76. rt_hw_context_switch_interrupt:
  77. LDR R2, =rt_thread_switch_interrupt_flag
  78. LDR R3, [R2]
  79. CMP R3, #1
  80. BEQ _reswitch
  81. MOV R3, #1 ; set flag to 1
  82. STR R3, [R2]
  83. LDR R2, =rt_interrupt_from_thread ; set rt_interrupt_from_thread
  84. STR R0, [R2]
  85. _reswitch:
  86. LDR R2, =rt_interrupt_to_thread ; set rt_interrupt_to_thread
  87. STR R1, [R2]
  88. MOV PC, LR
  89. END