context_gcc.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. _RESTORE_CONTEXT_SWITCH
  22. .endm
  23. .macro RESTORE_IRQ_CONTEXT
  24. /* Set the SP to point to the stack of the task being restored. */
  25. mov sp, x0
  26. ldp x2, x3, [sp], #0x10 /* SPSR and ELR. */
  27. tst x3, #0x1f
  28. msr spsr_el1, x3
  29. msr elr_el1, x2
  30. ldp x29, x30, [sp], #0x10
  31. msr sp_el0, x29
  32. ldp x28, x29, [sp], #0x10
  33. msr fpcr, x28
  34. msr fpsr, x29
  35. ldp x28, x29, [sp], #0x10
  36. ldp x26, x27, [sp], #0x10
  37. ldp x24, x25, [sp], #0x10
  38. ldp x22, x23, [sp], #0x10
  39. ldp x20, x21, [sp], #0x10
  40. ldp x18, x19, [sp], #0x10
  41. ldp x16, x17, [sp], #0x10
  42. ldp x14, x15, [sp], #0x10
  43. ldp x12, x13, [sp], #0x10
  44. ldp x10, x11, [sp], #0x10
  45. ldp x8, x9, [sp], #0x10
  46. ldp x6, x7, [sp], #0x10
  47. ldp x4, x5, [sp], #0x10
  48. ldp x2, x3, [sp], #0x10
  49. ldp x0, x1, [sp], #0x10
  50. RESTORE_FPU sp
  51. #ifdef RT_USING_SMART
  52. beq arch_ret_to_user
  53. #endif
  54. eret
  55. .endm
  56. #endif /* __ARM64_CONTEXT_H__ */