linkage.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ASM_LINKAGE_H
  3. #define __ASM_LINKAGE_H
  4. #define __ALIGN .align 2
  5. #define __ALIGN_STR __stringify(__ALIGN)
  6. #define SYM_FUNC_START(name) \
  7. SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN) \
  8. .cfi_startproc;
  9. #define SYM_FUNC_START_NOALIGN(name) \
  10. SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE) \
  11. .cfi_startproc;
  12. #define SYM_FUNC_START_LOCAL(name) \
  13. SYM_START(name, SYM_L_LOCAL, SYM_A_ALIGN) \
  14. .cfi_startproc;
  15. #define SYM_FUNC_START_LOCAL_NOALIGN(name) \
  16. SYM_START(name, SYM_L_LOCAL, SYM_A_NONE) \
  17. .cfi_startproc;
  18. #define SYM_FUNC_START_WEAK(name) \
  19. SYM_START(name, SYM_L_WEAK, SYM_A_ALIGN) \
  20. .cfi_startproc;
  21. #define SYM_FUNC_START_WEAK_NOALIGN(name) \
  22. SYM_START(name, SYM_L_WEAK, SYM_A_NONE) \
  23. .cfi_startproc;
  24. #define SYM_FUNC_END(name) \
  25. .cfi_endproc; \
  26. SYM_END(name, SYM_T_FUNC)
  27. #define SYM_CODE_START(name) \
  28. SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN) \
  29. .cfi_startproc;
  30. #define SYM_CODE_END(name) \
  31. .cfi_endproc; \
  32. SYM_END(name, SYM_T_NONE)
  33. /*
  34. * This is for the signal handler trampoline, which is used as the return
  35. * address of the signal handlers in userspace instead of called normally.
  36. * The long standing libgcc bug https://gcc.gnu.org/PR124050 requires a
  37. * nop between .cfi_startproc and the actual address of the trampoline, so
  38. * we cannot simply use SYM_FUNC_START.
  39. *
  40. * This wrapper also contains all the .cfi_* directives for recovering
  41. * the content of the GPRs and the "return address" (where the rt_sigreturn
  42. * syscall will jump to), assuming there is a struct rt_sigframe (where
  43. * a struct sigcontext containing those information we need to recover) at
  44. * $sp. The "DWARF for the LoongArch(TM) Architecture" manual states
  45. * column 0 is for $zero, but it does not make too much sense to
  46. * save/restore the hardware zero register. Repurpose this column here
  47. * for the return address (here it's not the content of $ra we cannot use
  48. * the default column 3).
  49. */
  50. #define SYM_SIGFUNC_START(name) \
  51. .cfi_startproc; \
  52. .cfi_signal_frame; \
  53. .cfi_def_cfa 3, RT_SIGFRAME_SC; \
  54. .cfi_return_column 0; \
  55. .cfi_offset 0, SC_PC; \
  56. \
  57. .irp num, 1, 2, 3, 4, 5, 6, 7, 8, \
  58. 9, 10, 11, 12, 13, 14, 15, 16, \
  59. 17, 18, 19, 20, 21, 22, 23, 24, \
  60. 25, 26, 27, 28, 29, 30, 31; \
  61. .cfi_offset \num, SC_REGS + \num * SZREG; \
  62. .endr; \
  63. \
  64. nop; \
  65. SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN)
  66. #define SYM_SIGFUNC_END(name) SYM_FUNC_END(name)
  67. #endif