sysdep.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* Assembler macros for x86.
  2. Copyright (C) 2017-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef _X86_SYSDEP_H
  16. #define _X86_SYSDEP_H 1
  17. #include <sysdeps/generic/sysdep.h>
  18. /* __CET__ is defined by GCC with Control-Flow Protection values:
  19. enum cf_protection_level
  20. {
  21. CF_NONE = 0,
  22. CF_BRANCH = 1 << 0,
  23. CF_RETURN = 1 << 1,
  24. CF_FULL = CF_BRANCH | CF_RETURN,
  25. CF_SET = 1 << 2
  26. };
  27. */
  28. /* Set if CF_BRANCH (IBT) is enabled. */
  29. #define X86_FEATURE_1_IBT (1U << 0)
  30. /* Set if CF_RETURN (SHSTK) is enabled. */
  31. #define X86_FEATURE_1_SHSTK (1U << 1)
  32. #ifdef __CET__
  33. # define CET_ENABLED 1
  34. # define IBT_ENABLED (__CET__ & X86_FEATURE_1_IBT)
  35. # define SHSTK_ENABLED (__CET__ & X86_FEATURE_1_SHSTK)
  36. #else
  37. # define CET_ENABLED 0
  38. # define IBT_ENABLED 0
  39. # define SHSTK_ENABLED 0
  40. #endif
  41. /* Offset for fxsave/xsave area used by _dl_runtime_resolve. Also need
  42. space to preserve RCX, RDX, RSI, RDI, R8, R9 and RAX. It must be
  43. aligned to 16 bytes for fxsave and 64 bytes for xsave. */
  44. #define STATE_SAVE_OFFSET (8 * 7 + 8)
  45. /* Save SSE, AVX, AVX512, mask and bound registers. */
  46. #define STATE_SAVE_MASK \
  47. ((1 << 1) | (1 << 2) | (1 << 3) | (1 << 5) | (1 << 6) | (1 << 7))
  48. #ifdef __ASSEMBLER__
  49. /* Syntactic details of assembler. */
  50. #ifdef _CET_ENDBR
  51. # define _CET_NOTRACK notrack
  52. #else
  53. # define _CET_ENDBR
  54. # define _CET_NOTRACK
  55. #endif
  56. /* ELF uses byte-counts for .align, most others use log2 of count of bytes. */
  57. #define ALIGNARG(log2) 1<<log2
  58. #define ASM_SIZE_DIRECTIVE(name) .size name,.-name;
  59. /* Define an entry point visible from C. */
  60. #define ENTRY(name) \
  61. .globl C_SYMBOL_NAME(name); \
  62. .type C_SYMBOL_NAME(name),@function; \
  63. .align ALIGNARG(4); \
  64. C_LABEL(name) \
  65. cfi_startproc; \
  66. _CET_ENDBR; \
  67. CALL_MCOUNT
  68. #undef END
  69. #define END(name) \
  70. cfi_endproc; \
  71. ASM_SIZE_DIRECTIVE(name)
  72. #define ENTRY_CHK(name) ENTRY (name)
  73. #define END_CHK(name) END (name)
  74. /* Since C identifiers are not normally prefixed with an underscore
  75. on this system, the asm identifier `syscall_error' intrudes on the
  76. C name space. Make sure we use an innocuous name. */
  77. #define syscall_error __syscall_error
  78. #define mcount _mcount
  79. #undef PSEUDO_END
  80. #define PSEUDO_END(name) \
  81. END (name)
  82. /* Local label name for asm code. */
  83. #ifndef L
  84. /* ELF-like local names start with `.L'. */
  85. # define L(name) .L##name
  86. #endif
  87. #define atom_text_section .section ".text.atom", "ax"
  88. #endif /* __ASSEMBLER__ */
  89. #endif /* _X86_SYSDEP_H */