context_gcc.S 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (c) 2006-2024, 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. .section .text
  23. .globl rt_hw_context_switch_to
  24. /*
  25. * void rt_hw_context_switch_to(rt_uint3 to, struct rt_thread *to_thread);
  26. * X0 --> to (thread stack)
  27. * X1 --> to_thread
  28. */
  29. rt_hw_context_switch_to:
  30. ldr x0, [x0]
  31. mov sp, x0
  32. mov x0, x1
  33. bl rt_cpus_lock_status_restore
  34. #ifdef RT_USING_SMART
  35. bl rt_thread_self
  36. bl lwp_user_setting_restore
  37. #endif
  38. b rt_hw_context_switch_exit
  39. .globl rt_hw_context_switch
  40. /*
  41. * void rt_hw_context_switch(rt_uint32 from, rt_uint32
  42. to, struct rt_thread *to_thread);
  43. * X0 --> from (from_thread stack)
  44. * X1 --> to (to_thread stack)
  45. * X2 --> to_thread
  46. */
  47. rt_hw_context_switch:
  48. SAVE_CONTEXT_SWITCH
  49. mov x3, sp
  50. str x3, [x0] // store sp in preempted tasks TCB
  51. ldr x0, [x1] // get new task stack pointer
  52. mov sp, x0
  53. /* backup thread self */
  54. mov x19, x2
  55. mov x0, x19
  56. bl rt_cpus_lock_status_restore
  57. #ifdef RT_USING_SMART
  58. mov x0, x19
  59. bl lwp_user_setting_restore
  60. #endif
  61. b rt_hw_context_switch_exit
  62. .globl rt_hw_context_switch_interrupt
  63. /*
  64. * void rt_hw_context_switch_interrupt(context, from sp, to sp, tp tcb)
  65. * X0 :interrupt context
  66. * X1 :addr of from_thread's sp
  67. * X2 :addr of to_thread's sp
  68. * X3 :to_thread's tcb
  69. */
  70. rt_hw_context_switch_interrupt:
  71. stp x0, x1, [sp, #-0x10]!
  72. stp x2, x3, [sp, #-0x10]!
  73. stp x29, x30, [sp, #-0x10]!
  74. #ifdef RT_USING_SMART
  75. bl rt_thread_self
  76. bl lwp_user_setting_save
  77. #endif
  78. ldp x29, x30, [sp], #0x10
  79. ldp x2, x3, [sp], #0x10
  80. ldp x0, x1, [sp], #0x10
  81. str x0, [x1]
  82. ldr x0, [x2]
  83. mov sp, x0
  84. mov x0, x3
  85. mov x19, x0
  86. bl rt_cpus_lock_status_restore
  87. mov x0, x19
  88. #ifdef RT_USING_SMART
  89. bl lwp_user_setting_restore
  90. #endif
  91. b rt_hw_context_switch_exit
  92. .global rt_hw_context_switch_exit
  93. rt_hw_context_switch_exit:
  94. clrex
  95. mov x0, sp
  96. RESTORE_CONTEXT_SWITCH