1 /* Assembler macros for x86-64.
2 Copyright (C) 2001-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #ifndef _X86_64_SYSDEP_H
20 #define _X86_64_SYSDEP_H 1
22 #include <sysdeps/x86/sysdep.h>
23 #include <x86-lp_size.h>
25 /* __CET__ is defined by GCC with Control-Flow Protection values:
27 enum cf_protection_level
32 CF_FULL = CF_BRANCH | CF_RETURN,
37 /* Set if CF_BRANCH (IBT) is enabled. */
38 #define X86_FEATURE_1_IBT (1U << 0)
39 /* Set if CF_RETURN (SHSTK) is enabled. */
40 #define X86_FEATURE_1_SHSTK (1U << 1)
43 # define CET_ENABLED 1
44 # define SHSTK_ENABLED (__CET__ & X86_FEATURE_1_SHSTK)
46 # define CET_ENABLED 0
47 # define SHSTK_ENABLED 0
52 /* Syntactic details of assembler. */
55 # define _CET_NOTRACK notrack
61 /* Define an entry point visible from C. */
62 #define ENTRY_P2ALIGN(name, alignment) \
63 .globl C_SYMBOL_NAME(name); \
64 .type C_SYMBOL_NAME(name),@function; \
65 .align ALIGNARG(alignment); \
71 /* This macro is for setting proper CFI with DW_CFA_expression describing
72 the register as saved relative to %rsp instead of relative to the CFA.
73 Expression is DW_OP_drop, DW_OP_breg7 (%rsp is register 7), sleb128 offset
75 #define cfi_offset_rel_rsp(regn, off) .cfi_escape 0x10, regn, 0x4, 0x13, \
76 0x77, off & 0x7F | 0x80, off >> 7
78 /* If compiled for profiling, call `mcount' at the start of each function. */
80 /* The mcount code relies on a normal frame pointer being on the stack
81 to locate our caller, so push one just for its benefit. */
84 cfi_adjust_cfa_offset(8); \
86 cfi_def_cfa_register(%rbp); \
87 call JUMPTARGET(mcount); \
91 #define CALL_MCOUNT /* Do nothing. */
94 #define PSEUDO(name, syscall_name, args) \
96 jmp JUMPTARGET(syscall_error) \
97 .globl syscall_error; \
99 DO_CALL (syscall_name, args); \
105 # define JUMPTARGET(name) *name##@GOTPCREL(%rip)
107 # define JUMPTARGET(name) name##@PLT
110 /* For static archives, branch to target directly. */
111 # define JUMPTARGET(name) name
114 /* Instruction to operate on long and pointer. */
115 #define LP_OP(insn) insn##q
117 /* Assembler address directive. */
118 #define ASM_ADDR .quad
120 /* Registers to hold long and pointer. */
138 /* Zero upper vector registers and return with xtest. NB: Use VZEROALL
139 to avoid RTM abort triggered by VZEROUPPER inside transactionally. */
140 #define ZERO_UPPER_VEC_REGISTERS_RETURN_XTEST \
149 /* Can be used to replace vzeroupper that is not directly before a
150 return. This is useful when hoisting a vzeroupper from multiple
151 return paths to decrease the total number of vzerouppers and code
153 #define COND_VZEROUPPER_XTEST \
162 /* In RTM define this as COND_VZEROUPPER_XTEST. */
163 #ifndef COND_VZEROUPPER
164 # define COND_VZEROUPPER vzeroupper
167 /* Zero upper vector registers and return. */
168 #ifndef ZERO_UPPER_VEC_REGISTERS_RETURN
169 # define ZERO_UPPER_VEC_REGISTERS_RETURN \
174 #ifndef VZEROUPPER_RETURN
175 # define VZEROUPPER_RETURN VZEROUPPER; ret
178 #else /* __ASSEMBLER__ */
180 /* Instruction to operate on long and pointer. */
181 #define LP_OP(insn) #insn "q"
183 /* Assembler address directive. */
184 #define ASM_ADDR ".quad"
186 /* Registers to hold long and pointer. */
204 #endif /* __ASSEMBLER__ */
206 #endif /* _X86_64_SYSDEP_H */