2001-09-19 10:37:31 +00:00
|
|
|
/* Assembler macros for x86-64.
|
2024-01-01 18:12:26 +00:00
|
|
|
Copyright (C) 2001-2024 Free Software Foundation, Inc.
|
2001-09-19 10:37:31 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
License along with the GNU C Library; if not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2001-09-19 10:37:31 +00:00
|
|
|
|
2012-05-15 19:49:42 +00:00
|
|
|
#ifndef _X86_64_SYSDEP_H
|
|
|
|
#define _X86_64_SYSDEP_H 1
|
|
|
|
|
2017-11-01 12:37:10 +00:00
|
|
|
#include <sysdeps/x86/sysdep.h>
|
2022-10-18 15:00:07 +00:00
|
|
|
#include <x86-lp_size.h>
|
2001-09-19 10:37:31 +00:00
|
|
|
|
2024-01-05 13:36:40 +00:00
|
|
|
/* __CET__ is defined by GCC with Control-Flow Protection values:
|
|
|
|
|
|
|
|
enum cf_protection_level
|
|
|
|
{
|
|
|
|
CF_NONE = 0,
|
|
|
|
CF_BRANCH = 1 << 0,
|
|
|
|
CF_RETURN = 1 << 1,
|
|
|
|
CF_FULL = CF_BRANCH | CF_RETURN,
|
|
|
|
CF_SET = 1 << 2
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Set if CF_BRANCH (IBT) is enabled. */
|
|
|
|
#define X86_FEATURE_1_IBT (1U << 0)
|
|
|
|
/* Set if CF_RETURN (SHSTK) is enabled. */
|
|
|
|
#define X86_FEATURE_1_SHSTK (1U << 1)
|
|
|
|
|
|
|
|
#ifdef __CET__
|
|
|
|
# define CET_ENABLED 1
|
|
|
|
# define SHSTK_ENABLED (__CET__ & X86_FEATURE_1_SHSTK)
|
|
|
|
#else
|
|
|
|
# define CET_ENABLED 0
|
|
|
|
# define SHSTK_ENABLED 0
|
|
|
|
#endif
|
|
|
|
|
2001-09-19 10:37:31 +00:00
|
|
|
#ifdef __ASSEMBLER__
|
|
|
|
|
|
|
|
/* Syntactic details of assembler. */
|
|
|
|
|
2024-01-05 13:36:40 +00:00
|
|
|
#ifdef _CET_ENDBR
|
|
|
|
# define _CET_NOTRACK notrack
|
|
|
|
#else
|
|
|
|
# define _CET_ENDBR
|
|
|
|
# define _CET_NOTRACK
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Define an entry point visible from C. */
|
|
|
|
#define ENTRY_P2ALIGN(name, alignment) \
|
|
|
|
.globl C_SYMBOL_NAME(name); \
|
|
|
|
.type C_SYMBOL_NAME(name),@function; \
|
|
|
|
.align ALIGNARG(alignment); \
|
|
|
|
C_LABEL(name) \
|
|
|
|
cfi_startproc; \
|
|
|
|
_CET_ENDBR; \
|
|
|
|
CALL_MCOUNT
|
|
|
|
|
2015-06-09 11:25:49 +00:00
|
|
|
/* This macro is for setting proper CFI with DW_CFA_expression describing
|
|
|
|
the register as saved relative to %rsp instead of relative to the CFA.
|
|
|
|
Expression is DW_OP_drop, DW_OP_breg7 (%rsp is register 7), sleb128 offset
|
|
|
|
from %rsp. */
|
|
|
|
#define cfi_offset_rel_rsp(regn, off) .cfi_escape 0x10, regn, 0x4, 0x13, \
|
|
|
|
0x77, off & 0x7F | 0x80, off >> 7
|
|
|
|
|
2001-09-19 10:37:31 +00:00
|
|
|
/* If compiled for profiling, call `mcount' at the start of each function. */
|
|
|
|
#ifdef PROF
|
|
|
|
/* The mcount code relies on a normal frame pointer being on the stack
|
|
|
|
to locate our caller, so push one just for its benefit. */
|
* sysdeps/generic/sysdep.h (cfi_offset, cfi_startproc,
cfi_endproc, cfi_def_cfa, cfi_def_ccfa_register,
cfi_def_cfa_offset, cfi_adjust_cfa_offset, cfi_offset): Define.
* sysdeps/x86_64/sysdep.h (CALL_MCOUNT): Add cfi directives.
(ENTRY): Likewise.
(END): Likewise.
* configure.in: Test for asm cfi directives.
* config.h.in: Add HAVE_ASM_CFI_DIRECTIVES.
2003-05-21 Andreas Jaeger <aj@suse.de>
* sysdeps/generic/sysdep.h (cfi_offset, cfi_startproc,
cfi_endproc, cfi_def_cfa, cfi_def_ccfa_register,
cfi_def_cfa_offset, cfi_adjust_cfa_offset, cfi_offset): Define.
* sysdeps/x86_64/sysdep.h (CALL_MCOUNT): Add cfi directives.
(ENTRY): Likewise.
(END): Likewise.
* configure.in: Test for asm cfi directives.
* config.h.in: Add HAVE_ASM_CFI_DIRECTIVES.
2003-05-21 09:25:53 +00:00
|
|
|
#define CALL_MCOUNT \
|
|
|
|
pushq %rbp; \
|
|
|
|
cfi_adjust_cfa_offset(8); \
|
|
|
|
movq %rsp, %rbp; \
|
|
|
|
cfi_def_cfa_register(%rbp); \
|
|
|
|
call JUMPTARGET(mcount); \
|
|
|
|
popq %rbp; \
|
|
|
|
cfi_def_cfa(rsp,8);
|
2001-09-19 10:37:31 +00:00
|
|
|
#else
|
|
|
|
#define CALL_MCOUNT /* Do nothing. */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define PSEUDO(name, syscall_name, args) \
|
|
|
|
lose: \
|
|
|
|
jmp JUMPTARGET(syscall_error) \
|
|
|
|
.globl syscall_error; \
|
|
|
|
ENTRY (name) \
|
|
|
|
DO_CALL (syscall_name, args); \
|
|
|
|
jb lose
|
|
|
|
|
2003-01-09 20:30:21 +00:00
|
|
|
#undef JUMPTARGET
|
2016-11-28 17:44:49 +00:00
|
|
|
#ifdef SHARED
|
2016-05-24 15:44:10 +00:00
|
|
|
# ifdef BIND_NOW
|
|
|
|
# define JUMPTARGET(name) *name##@GOTPCREL(%rip)
|
|
|
|
# else
|
|
|
|
# define JUMPTARGET(name) name##@PLT
|
|
|
|
# endif
|
2001-09-19 10:37:31 +00:00
|
|
|
#else
|
2016-11-28 17:44:49 +00:00
|
|
|
/* For static archives, branch to target directly. */
|
2016-05-24 15:44:10 +00:00
|
|
|
# define JUMPTARGET(name) name
|
2001-09-19 10:37:31 +00:00
|
|
|
#endif
|
|
|
|
|
2012-05-14 21:56:07 +00:00
|
|
|
/* Instruction to operate on long and pointer. */
|
|
|
|
#define LP_OP(insn) insn##q
|
|
|
|
|
|
|
|
/* Assembler address directive. */
|
|
|
|
#define ASM_ADDR .quad
|
|
|
|
|
|
|
|
/* Registers to hold long and pointer. */
|
|
|
|
#define RAX_LP rax
|
|
|
|
#define RBP_LP rbp
|
|
|
|
#define RBX_LP rbx
|
|
|
|
#define RCX_LP rcx
|
|
|
|
#define RDI_LP rdi
|
|
|
|
#define RDX_LP rdx
|
|
|
|
#define RSI_LP rsi
|
|
|
|
#define RSP_LP rsp
|
|
|
|
#define R8_LP r8
|
|
|
|
#define R9_LP r9
|
|
|
|
#define R10_LP r10
|
|
|
|
#define R11_LP r11
|
|
|
|
#define R12_LP r12
|
|
|
|
#define R13_LP r13
|
|
|
|
#define R14_LP r14
|
|
|
|
#define R15_LP r15
|
|
|
|
|
2021-03-05 15:26:42 +00:00
|
|
|
/* Zero upper vector registers and return with xtest. NB: Use VZEROALL
|
|
|
|
to avoid RTM abort triggered by VZEROUPPER inside transactionally. */
|
|
|
|
#define ZERO_UPPER_VEC_REGISTERS_RETURN_XTEST \
|
|
|
|
xtest; \
|
2022-06-03 23:52:37 +00:00
|
|
|
jnz 1f; \
|
|
|
|
vzeroupper; \
|
2021-03-05 15:26:42 +00:00
|
|
|
ret; \
|
|
|
|
1: \
|
2022-06-03 23:52:37 +00:00
|
|
|
vzeroall; \
|
2021-03-05 15:26:42 +00:00
|
|
|
ret
|
|
|
|
|
2022-06-07 04:11:28 +00:00
|
|
|
/* Can be used to replace vzeroupper that is not directly before a
|
|
|
|
return. This is useful when hoisting a vzeroupper from multiple
|
|
|
|
return paths to decrease the total number of vzerouppers and code
|
|
|
|
size. */
|
|
|
|
#define COND_VZEROUPPER_XTEST \
|
|
|
|
xtest; \
|
|
|
|
jz 1f; \
|
|
|
|
vzeroall; \
|
|
|
|
jmp 2f; \
|
|
|
|
1: \
|
|
|
|
vzeroupper; \
|
|
|
|
2:
|
|
|
|
|
|
|
|
/* In RTM define this as COND_VZEROUPPER_XTEST. */
|
|
|
|
#ifndef COND_VZEROUPPER
|
|
|
|
# define COND_VZEROUPPER vzeroupper
|
|
|
|
#endif
|
|
|
|
|
2021-03-05 15:26:42 +00:00
|
|
|
/* Zero upper vector registers and return. */
|
|
|
|
#ifndef ZERO_UPPER_VEC_REGISTERS_RETURN
|
|
|
|
# define ZERO_UPPER_VEC_REGISTERS_RETURN \
|
|
|
|
VZEROUPPER; \
|
|
|
|
ret
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef VZEROUPPER_RETURN
|
|
|
|
# define VZEROUPPER_RETURN VZEROUPPER; ret
|
|
|
|
#endif
|
|
|
|
|
2012-05-14 21:56:07 +00:00
|
|
|
#else /* __ASSEMBLER__ */
|
|
|
|
|
|
|
|
/* Instruction to operate on long and pointer. */
|
|
|
|
#define LP_OP(insn) #insn "q"
|
|
|
|
|
|
|
|
/* Assembler address directive. */
|
|
|
|
#define ASM_ADDR ".quad"
|
|
|
|
|
|
|
|
/* Registers to hold long and pointer. */
|
|
|
|
#define RAX_LP "rax"
|
|
|
|
#define RBP_LP "rbp"
|
|
|
|
#define RBX_LP "rbx"
|
|
|
|
#define RCX_LP "rcx"
|
|
|
|
#define RDI_LP "rdi"
|
|
|
|
#define RDX_LP "rdx"
|
|
|
|
#define RSI_LP "rsi"
|
|
|
|
#define RSP_LP "rsp"
|
|
|
|
#define R8_LP "r8"
|
|
|
|
#define R9_LP "r9"
|
|
|
|
#define R10_LP "r10"
|
|
|
|
#define R11_LP "r11"
|
|
|
|
#define R12_LP "r12"
|
|
|
|
#define R13_LP "r13"
|
|
|
|
#define R14_LP "r14"
|
|
|
|
#define R15_LP "r15"
|
|
|
|
|
2001-09-19 10:37:31 +00:00
|
|
|
#endif /* __ASSEMBLER__ */
|
2012-05-15 19:49:42 +00:00
|
|
|
|
|
|
|
#endif /* _X86_64_SYSDEP_H */
|