context_gcc.S 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (c) 2006-2020, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-05-18 Jesven the first version
  9. * 2023-06-24 Shell Support backtrace for user thread
  10. * 2024-01-06 Shell Fix barrier on irq_disable/enable
  11. * 2024-03-28 Shell Move vector handling codes from context_gcc.S
  12. */
  13. #ifndef __ASSEMBLY__
  14. #define __ASSEMBLY__
  15. #endif
  16. #include "context_gcc.h"
  17. #include "../include/vector_gcc.h"
  18. #include <rtconfig.h>
  19. #include <asm-generic.h>
  20. #include <asm-fpu.h>
  21. #include <armv8.h>
  22. /**
  23. * Context switch status
  24. */
  25. .section .bss
  26. rt_interrupt_from_thread:
  27. .quad 0
  28. rt_interrupt_to_thread:
  29. .quad 0
  30. rt_thread_switch_interrupt_flag:
  31. .quad 0
  32. .section .text
  33. /*
  34. * void rt_hw_context_switch_to(rt_ubase_t to);
  35. * X0 --> to sp
  36. */
  37. .globl rt_hw_context_switch_to
  38. rt_hw_context_switch_to:
  39. clrex
  40. ldr x0, [x0]
  41. RESTORE_CONTEXT_SWITCH
  42. /*
  43. * void rt_hw_context_switch(rt_ubase_t from, rt_ubase_t to);
  44. * X0 --> from sp
  45. * X1 --> to sp
  46. * X2 --> to thread
  47. */
  48. .globl rt_hw_context_switch
  49. rt_hw_context_switch:
  50. clrex
  51. SAVE_CONTEXT_SWITCH
  52. mov x2, sp
  53. str x2, [x0] // store sp in preempted tasks TCB
  54. ldr x0, [x1] // get new task stack pointer
  55. RESTORE_CONTEXT_SWITCH
  56. /*
  57. * void rt_hw_context_switch_interrupt(rt_ubase_t from, rt_ubase_t to, rt_thread_t from_thread, rt_thread_t to_thread);
  58. */
  59. .globl rt_thread_switch_interrupt_flag
  60. .globl rt_interrupt_from_thread
  61. .globl rt_interrupt_to_thread
  62. .globl rt_hw_context_switch_interrupt
  63. rt_hw_context_switch_interrupt:
  64. clrex
  65. ldr x6, =rt_thread_switch_interrupt_flag
  66. ldr x7, [x6]
  67. cmp x7, #1
  68. b.eq _reswitch
  69. /* set rt_interrupt_from_thread */
  70. ldr x4, =rt_interrupt_from_thread
  71. str x0, [x4]
  72. /* set rt_thread_switch_interrupt_flag to 1 */
  73. mov x7, #1
  74. str x7, [x6]
  75. stp x1, x30, [sp, #-0x10]!
  76. #ifdef RT_USING_SMART
  77. mov x0, x2
  78. bl lwp_user_setting_save
  79. #endif
  80. ldp x1, x30, [sp], #0x10
  81. _reswitch:
  82. ldr x6, =rt_interrupt_to_thread // set rt_interrupt_to_thread
  83. str x1, [x6]
  84. ret