Update copyright notices with scripts/update-copyrights
[jlayton/glibc.git] / sysdeps / x86_64 / sysdep.h
1 /* Assembler macros for x86-64.
2    Copyright (C) 2001-2014 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4
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.
9
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.
14
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    <http://www.gnu.org/licenses/>.  */
18
19 #ifndef _X86_64_SYSDEP_H
20 #define _X86_64_SYSDEP_H 1
21
22 #include <sysdeps/generic/sysdep.h>
23
24 #ifdef  __ASSEMBLER__
25
26 /* Syntactic details of assembler.  */
27
28 /* ELF uses byte-counts for .align, most others use log2 of count of bytes.  */
29 #define ALIGNARG(log2) 1<<log2
30 #define ASM_SIZE_DIRECTIVE(name) .size name,.-name;
31
32
33 /* Define an entry point visible from C.  */
34 #define ENTRY(name)                                                           \
35   .globl C_SYMBOL_NAME(name);                                                 \
36   .type C_SYMBOL_NAME(name),@function;                                        \
37   .align ALIGNARG(4);                                                         \
38   C_LABEL(name)                                                               \
39   cfi_startproc;                                                              \
40   CALL_MCOUNT
41
42 #undef  END
43 #define END(name)                                                             \
44   cfi_endproc;                                                                \
45   ASM_SIZE_DIRECTIVE(name)
46
47 #define ENTRY_CHK(name) ENTRY (name)
48 #define END_CHK(name) END (name)
49
50 /* If compiled for profiling, call `mcount' at the start of each function.  */
51 #ifdef  PROF
52 /* The mcount code relies on a normal frame pointer being on the stack
53    to locate our caller, so push one just for its benefit.  */
54 #define CALL_MCOUNT                                                          \
55   pushq %rbp;                                                                \
56   cfi_adjust_cfa_offset(8);                                                  \
57   movq %rsp, %rbp;                                                           \
58   cfi_def_cfa_register(%rbp);                                                \
59   call JUMPTARGET(mcount);                                                   \
60   popq %rbp;                                                                 \
61   cfi_def_cfa(rsp,8);
62 #else
63 #define CALL_MCOUNT             /* Do nothing.  */
64 #endif
65
66 /* Since C identifiers are not normally prefixed with an underscore
67    on this system, the asm identifier `syscall_error' intrudes on the
68    C name space.  Make sure we use an innocuous name.  */
69 #define syscall_error   __syscall_error
70 #define mcount          _mcount
71
72 #define PSEUDO(name, syscall_name, args)                                      \
73 lose:                                                                         \
74   jmp JUMPTARGET(syscall_error)                                               \
75   .globl syscall_error;                                                       \
76   ENTRY (name)                                                                \
77   DO_CALL (syscall_name, args);                                               \
78   jb lose
79
80 #undef  PSEUDO_END
81 #define PSEUDO_END(name)                                                      \
82   END (name)
83
84 #undef JUMPTARGET
85 #ifdef PIC
86 #define JUMPTARGET(name)        name##@PLT
87 #else
88 #define JUMPTARGET(name)        name
89 #endif
90
91 /* Local label name for asm code. */
92 #ifndef L
93 /* ELF-like local names start with `.L'.  */
94 # define L(name)        .L##name
95 #endif
96
97 #define atom_text_section .section ".text.atom", "ax"
98
99 /* Long and pointer size in bytes.  */
100 #define LP_SIZE 8
101
102 /* Instruction to operate on long and pointer.  */
103 #define LP_OP(insn) insn##q
104
105 /* Assembler address directive. */
106 #define ASM_ADDR .quad
107
108 /* Registers to hold long and pointer.  */
109 #define RAX_LP  rax
110 #define RBP_LP  rbp
111 #define RBX_LP  rbx
112 #define RCX_LP  rcx
113 #define RDI_LP  rdi
114 #define RDX_LP  rdx
115 #define RSI_LP  rsi
116 #define RSP_LP  rsp
117 #define R8_LP   r8
118 #define R9_LP   r9
119 #define R10_LP  r10
120 #define R11_LP  r11
121 #define R12_LP  r12
122 #define R13_LP  r13
123 #define R14_LP  r14
124 #define R15_LP  r15
125
126 #else   /* __ASSEMBLER__ */
127
128 /* Long and pointer size in bytes.  */
129 #define LP_SIZE "8"
130
131 /* Instruction to operate on long and pointer.  */
132 #define LP_OP(insn) #insn "q"
133
134 /* Assembler address directive. */
135 #define ASM_ADDR ".quad"
136
137 /* Registers to hold long and pointer.  */
138 #define RAX_LP  "rax"
139 #define RBP_LP  "rbp"
140 #define RBX_LP  "rbx"
141 #define RCX_LP  "rcx"
142 #define RDI_LP  "rdi"
143 #define RDX_LP  "rdx"
144 #define RSI_LP  "rsi"
145 #define RSP_LP  "rsp"
146 #define R8_LP   "r8"
147 #define R9_LP   "r9"
148 #define R10_LP  "r10"
149 #define R11_LP  "r11"
150 #define R12_LP  "r12"
151 #define R13_LP  "r13"
152 #define R14_LP  "r14"
153 #define R15_LP  "r15"
154
155 #endif  /* __ASSEMBLER__ */
156
157 #endif  /* _X86_64_SYSDEP_H */