1
0

context_gcc.S 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * File : context.S
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2010, 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. * 2010-03-27 Kyle First version
  13. */
  14. #define AVR32_SR 0
  15. #define AVR32_SR_GM_OFFSET 16
  16. .text
  17. /*
  18. * rt_base_t rt_hw_interrupt_disable()
  19. */
  20. .globl rt_hw_interrupt_disable
  21. .type rt_hw_interrupt_disable, %function
  22. rt_hw_interrupt_disable:
  23. ssrf AVR32_SR_GM_OFFSET
  24. mov pc, lr
  25. /*
  26. * void rt_hw_interrupt_enable(rt_base_t level)
  27. */
  28. .globl rt_hw_interrupt_enable
  29. .type rt_hw_interrupt_enable, %function
  30. rt_hw_interrupt_enable:
  31. csrf AVR32_SR_GM_OFFSET
  32. mov pc, lr
  33. /*
  34. * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to)/*
  35. * r8 --> from
  36. * r9 --> to
  37. */
  38. .globl rt_hw_context_switch
  39. .type rt_hw_context_switch, %function
  40. rt_hw_context_switch:
  41. ssrf AVR32_SR_GM_OFFSET /* Disable global interrupt */
  42. stm --sp, r8-r12, lr /* Push R8-R12, LR */
  43. st.w --sp, lr /* Push LR (instead of PC) */
  44. mfsr r8, AVR32_SR /* Read Status Register */
  45. cbr r8, AVR32_SR_GM_OFFSET /* Clear GM bit */
  46. st.w --sp, r8 /* Push SR */
  47. stm --sp, r0-r7 /* Push R0-R7 */
  48. /* Stack layout: R8-R12, LR, PC, SR, R0-R7 */
  49. st.w r12[0], sp /* Store SP in preempted tasks TCB */
  50. ld.w sp, r11[0] /* Get new task stack pointer */
  51. ldm sp++, r0-r7 /* pop R0-R7 */
  52. ld.w r8, sp++ /* pop SR */
  53. mtsr AVR32_SR, r8 /* Restore SR */
  54. ldm sp++, r8-r12, lr, pc/* Pop R8-R12, LR, PC and resume to thread */
  55. /*
  56. * void rt_hw_context_switch_to(rt_uint32 to)/*
  57. * r0 --> to
  58. */
  59. .globl rt_hw_context_switch_to
  60. .type rt_hw_context_switch_to, %function
  61. rt_hw_context_switch_to:
  62. ld.w sp, r12[0] /* Get new task stack pointer */
  63. ldm sp++, r0-r7 /* pop R0-R7 */
  64. ld.w r8, sp++ /* pop SR */
  65. mtsr AVR32_SR, r8 /* Restore SR */
  66. ldm sp++, r8-r12, lr, pc/* Pop R8-R12, LR, PC and resume execution */
  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. .type rt_hw_context_switch_interrupt, %function
  75. rt_hw_context_switch_interrupt:
  76. lda.w r8, rt_thread_switch_interrupt_flag
  77. ld.w r9, r8[0]
  78. cp.w r9, 1
  79. breq _reswitch
  80. mov r9, 1
  81. st.w r8[0], r9
  82. lda.w r8, rt_interrupt_from_thread
  83. st.w r8[0], r12
  84. _reswitch:
  85. lda.w r8, rt_interrupt_to_thread
  86. st.w r8[0], r11
  87. mov pc, lr