context_gcc.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. * 2024-03-25 Shell Trimming unecessary ops and
  9. * improve the performance of ctx switch
  10. */
  11. #ifndef __ARM64_CONTEXT_H__
  12. #define __ARM64_CONTEXT_H__
  13. #include "../include/context_gcc.h"
  14. #include <rtconfig.h>
  15. #include <asm-generic.h>
  16. #include <asm-fpu.h>
  17. #include <armv8.h>
  18. .macro RESTORE_CONTEXT_SWITCH
  19. /* Set the SP to point to the stack of the task being restored. */
  20. mov sp, x0
  21. #ifdef RT_USING_SMART
  22. bl rt_thread_self
  23. mov x19, x0
  24. bl lwp_aspace_switch
  25. mov x0, x19
  26. bl lwp_user_setting_restore
  27. #endif /* RT_USING_SMART */
  28. _RESTORE_CONTEXT_SWITCH
  29. .endm
  30. .macro RESTORE_IRQ_CONTEXT
  31. /* Set the SP to point to the stack of the task being restored. */
  32. MOV SP, X0
  33. #ifdef RT_USING_SMART
  34. BL rt_thread_self
  35. MOV X19, X0
  36. BL lwp_aspace_switch
  37. MOV X0, X19
  38. BL lwp_user_setting_restore
  39. #endif
  40. LDP X2, X3, [SP], #0x10 /* SPSR and ELR. */
  41. TST X3, #0x1f
  42. MSR SPSR_EL1, X3
  43. MSR ELR_EL1, X2
  44. LDP X29, X30, [SP], #0x10
  45. MSR SP_EL0, X29
  46. LDP X28, X29, [SP], #0x10
  47. MSR FPCR, X28
  48. MSR FPSR, X29
  49. LDP X28, X29, [SP], #0x10
  50. LDP X26, X27, [SP], #0x10
  51. LDP X24, X25, [SP], #0x10
  52. LDP X22, X23, [SP], #0x10
  53. LDP X20, X21, [SP], #0x10
  54. LDP X18, X19, [SP], #0x10
  55. LDP X16, X17, [SP], #0x10
  56. LDP X14, X15, [SP], #0x10
  57. LDP X12, X13, [SP], #0x10
  58. LDP X10, X11, [SP], #0x10
  59. LDP X8, X9, [SP], #0x10
  60. LDP X6, X7, [SP], #0x10
  61. LDP X4, X5, [SP], #0x10
  62. LDP X2, X3, [SP], #0x10
  63. LDP X0, X1, [SP], #0x10
  64. RESTORE_FPU SP
  65. #ifdef RT_USING_SMART
  66. BEQ arch_ret_to_user
  67. #endif
  68. ERET
  69. .endm
  70. #endif /* __ARM64_CONTEXT_H__ */