context_gcc.S 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * File : context.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://openlab.rt-thread.com/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2011-01-13 weety copy from mini2440
  13. */
  14. /*!
  15. * \addtogroup AT91SAM926X
  16. */
  17. /*@{*/
  18. #define NOINT 0xc0
  19. /*
  20. * rt_base_t rt_hw_interrupt_disable();
  21. */
  22. .globl rt_hw_interrupt_disable
  23. rt_hw_interrupt_disable:
  24. mrs r0, cpsr
  25. orr r1, r0, #NOINT
  26. msr cpsr_c, r1
  27. mov pc, lr
  28. /*
  29. * void rt_hw_interrupt_enable(rt_base_t level);
  30. */
  31. .globl rt_hw_interrupt_enable
  32. rt_hw_interrupt_enable:
  33. msr cpsr, r0
  34. mov pc, lr
  35. /*
  36. * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
  37. * r0 --> from
  38. * r1 --> to
  39. */
  40. .globl rt_hw_context_switch
  41. rt_hw_context_switch:
  42. stmfd sp!, {lr} @ push pc (lr should be pushed in place of PC)
  43. stmfd sp!, {r0-r12, lr} @ push lr & register file
  44. mrs r4, cpsr
  45. stmfd sp!, {r4} @ push cpsr
  46. mrs r4, spsr
  47. stmfd sp!, {r4} @ push spsr
  48. str sp, [r0] @ store sp in preempted tasks TCB
  49. ldr sp, [r1] @ get new task stack pointer
  50. ldmfd sp!, {r4} @ pop new task spsr
  51. msr spsr_cxsf, r4
  52. ldmfd sp!, {r4} @ pop new task cpsr
  53. msr cpsr_cxsf, r4
  54. ldmfd sp!, {r0-r12, lr, pc} @ pop new task r0-r12, lr & pc
  55. /*
  56. * void rt_hw_context_switch_to(rt_uint32 to);
  57. * r0 --> to
  58. */
  59. .globl rt_hw_context_switch_to
  60. rt_hw_context_switch_to:
  61. ldr sp, [r0] @ get new task stack pointer
  62. ldmfd sp!, {r4} @ pop new task spsr
  63. msr spsr_cxsf, r4
  64. ldmfd sp!, {r4} @ pop new task cpsr
  65. msr cpsr_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_interrput_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_interrput_flag
  76. ldr r3, [r2]
  77. cmp r3, #1
  78. beq _reswitch
  79. mov r3, #1 @ set rt_thread_switch_interrput_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. mov pc, lr