context_gcc.S 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2006-03-13 Bernard first version
  13. */
  14. #define NOINT 0xc0
  15. /*
  16. * rt_base_t rt_hw_interrupt_disable()/*
  17. */
  18. .globl rt_hw_interrupt_disable
  19. rt_hw_interrupt_disable:
  20. mrs r0, cpsr
  21. orr r1, r0, #NOINT
  22. msr cpsr_c, r1
  23. mov pc, lr
  24. /*
  25. * void rt_hw_interrupt_enable(rt_base_t level)/*
  26. */
  27. .globl rt_hw_interrupt_enable
  28. rt_hw_interrupt_enable:
  29. msr cpsr, r0
  30. mov pc, lr
  31. /*
  32. * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to)/*
  33. * r0 --> from
  34. * r1 --> to
  35. */
  36. .globl rt_hw_context_switch
  37. rt_hw_context_switch:
  38. stmfd sp!, {lr} /* push pc (lr should be pushed in place of PC) */
  39. stmfd sp!, {r0-r12, lr} /* push lr & register file */
  40. mrs r4, cpsr
  41. stmfd sp!, {r4} /* push cpsr */
  42. mrs r4, spsr
  43. stmfd sp!, {r4} /* push spsr */
  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!, {r4} /* pop new task cpsr */
  49. msr cpsr_cxsf, r4
  50. ldmfd sp!, {r0-r12, lr, pc} /* pop new task r0-r12, lr & pc */
  51. /*
  52. * void rt_hw_context_switch_to(rt_uint32 to)/*
  53. * r0 --> to
  54. */
  55. .globl rt_hw_context_switch_to
  56. rt_hw_context_switch_to:
  57. ldr sp, [r0] /* get new task stack pointer */
  58. ldmfd sp!, {r4} /* pop new task spsr */
  59. msr spsr_cxsf, r4
  60. ldmfd sp!, {r4} /* pop new task cpsr */
  61. msr cpsr_cxsf, r4
  62. ldmfd sp!, {r0-r12, lr, pc} /* pop new task r0-r12, lr & pc */
  63. /*
  64. * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to)/*
  65. */
  66. .globl rt_thread_switch_interrput_flag
  67. .globl rt_interrupt_from_thread
  68. .globl rt_interrupt_to_thread
  69. .globl rt_hw_context_switch_interrupt
  70. rt_hw_context_switch_interrupt:
  71. ldr r2, =rt_thread_switch_interrput_flag
  72. ldr r3, [r2]
  73. cmp r3, #1
  74. beq _reswitch
  75. mov r3, #1 /* set rt_thread_switch_interrput_flag to 1 */
  76. str r3, [r2]
  77. ldr r2, =rt_interrupt_from_thread /* set rt_interrupt_from_thread */
  78. str r0, [r2]
  79. _reswitch:
  80. ldr r2, =rt_interrupt_to_thread /* set rt_interrupt_to_thread */
  81. str r1, [r2]
  82. mov pc, lr