context_gcc.S 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2010-03-27 Kyle First version
  9. */
  10. #define AVR32_SR 0
  11. #define AVR32_SR_GM_OFFSET 16
  12. .text
  13. /*
  14. * rt_base_t rt_hw_interrupt_disable()
  15. */
  16. .globl rt_hw_interrupt_disable
  17. .type rt_hw_interrupt_disable, %function
  18. rt_hw_interrupt_disable:
  19. ssrf AVR32_SR_GM_OFFSET
  20. mov pc, lr
  21. /*
  22. * void rt_hw_interrupt_enable(rt_base_t level)
  23. */
  24. .globl rt_hw_interrupt_enable
  25. .type rt_hw_interrupt_enable, %function
  26. rt_hw_interrupt_enable:
  27. csrf AVR32_SR_GM_OFFSET
  28. mov pc, lr
  29. /*
  30. * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to)/*
  31. * r8 --> from
  32. * r9 --> to
  33. */
  34. .globl rt_hw_context_switch
  35. .type rt_hw_context_switch, %function
  36. rt_hw_context_switch:
  37. ssrf AVR32_SR_GM_OFFSET /* Disable global interrupt */
  38. stm --sp, r8-r12, lr /* Push R8-R12, LR */
  39. st.w --sp, lr /* Push LR (instead of PC) */
  40. mfsr r8, AVR32_SR /* Read Status Register */
  41. cbr r8, AVR32_SR_GM_OFFSET /* Clear GM bit */
  42. st.w --sp, r8 /* Push SR */
  43. stm --sp, r0-r7 /* Push R0-R7 */
  44. /* Stack layout: R8-R12, LR, PC, SR, R0-R7 */
  45. st.w r12[0], sp /* Store SP in preempted tasks TCB */
  46. ld.w sp, r11[0] /* Get new task stack pointer */
  47. ldm sp++, r0-r7 /* pop R0-R7 */
  48. ld.w r8, sp++ /* pop SR */
  49. mtsr AVR32_SR, r8 /* Restore SR */
  50. ldm sp++, r8-r12, lr, pc/* Pop R8-R12, LR, PC and resume to thread */
  51. /*
  52. * void rt_hw_context_switch_to(rt_uint32 to)/*
  53. * r0 --> to
  54. */
  55. .globl rt_hw_context_switch_to
  56. .type rt_hw_context_switch_to, %function
  57. rt_hw_context_switch_to:
  58. ld.w sp, r12[0] /* Get new task stack pointer */
  59. ldm sp++, r0-r7 /* pop R0-R7 */
  60. ld.w r8, sp++ /* pop SR */
  61. mtsr AVR32_SR, r8 /* Restore SR */
  62. ldm sp++, r8-r12, lr, pc/* Pop R8-R12, LR, PC and resume execution */
  63. /*
  64. * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to)/*
  65. */
  66. .globl rt_thread_switch_interrupt_flag
  67. .globl rt_interrupt_from_thread
  68. .globl rt_interrupt_to_thread
  69. .globl rt_hw_context_switch_interrupt
  70. .type rt_hw_context_switch_interrupt, %function
  71. rt_hw_context_switch_interrupt:
  72. lda.w r8, rt_thread_switch_interrupt_flag
  73. ld.w r9, r8[0]
  74. cp.w r9, 1
  75. breq _reswitch
  76. mov r9, 1
  77. st.w r8[0], r9
  78. lda.w r8, rt_interrupt_from_thread
  79. st.w r8[0], r12
  80. _reswitch:
  81. lda.w r8, rt_interrupt_to_thread
  82. st.w r8[0], r11
  83. mov pc, lr