context_gcc.S 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. ; */
  24. #define NOINT 0xC0
  25. ;/*
  26. ; * rt_base_t rt_hw_interrupt_disable();
  27. ; */
  28. .globl rt_hw_interrupt_disable
  29. rt_hw_interrupt_disable:
  30. MRS R0, CPSR
  31. ORR R1, R0, #NOINT
  32. MSR CPSR_c, R1
  33. BX LR
  34. /*
  35. * void rt_hw_interrupt_enable(rt_base_t level);
  36. */
  37. .globl rt_hw_interrupt_enable
  38. rt_hw_interrupt_enable:
  39. MSR CPSR, R0
  40. BX LR
  41. /*
  42. * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
  43. * r0 --> from
  44. * r1 --> to
  45. */
  46. .globl rt_hw_context_switch
  47. rt_hw_context_switch:
  48. stmfd sp!, {lr} @; push pc (lr should be pushed in place of pc)
  49. stmfd sp!, {r0-r12, lr} @; push lr & register file
  50. mrs r4, cpsr
  51. stmfd sp!, {r4} @; push cpsr
  52. str sp, [r0] @; store sp in preempted tasks tcb
  53. ldr sp, [r1] @; get new task stack pointer
  54. ldmfd sp!, {r4} @; pop new task spsr
  55. msr spsr_cxsf, r4
  56. ldmfd sp!, {r0-r12, lr, pc}^ @; pop new task r0-r12, lr & pc
  57. /*
  58. * void rt_hw_context_switch_to(rt_uint32 to);
  59. * r0 --> to
  60. */
  61. .globl rt_hw_context_switch_to
  62. rt_hw_context_switch_to:
  63. ldr sp, [r0] @; get new task stack pointer
  64. ldmfd sp!, {r4} @; pop new task cpsr
  65. msr spsr_cxsf, r4
  66. ldmfd sp!, {r0-r12, lr, pc}^ @; pop new task r0-r12, lr & pc
  67. /*
  68. * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
  69. */
  70. .globl rt_thread_switch_interrupt_flag
  71. .globl rt_interrupt_from_thread
  72. .globl rt_interrupt_to_thread
  73. .globl rt_hw_context_switch_interrupt
  74. 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 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