xref: /haiku/src/system/libroot/posix/glibc/include/arch/x86_64/sysdep.h (revision 8bdd63fe5d3a5048b2a81eb8f545b1c47528e320)
1 /* Assembler macros for x86-64.
2    Copyright (C) 2001, 2002, 2003 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, write to the Free
17    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
19 
20 #include_next <sysdep.h>
21 
22 #ifdef	__ASSEMBLER__
23 
24 #ifdef HAVE_ELF
25 
26 /* ELF uses byte-counts for .align, most others use log2 of count of bytes.  */
27 #define ALIGNARG(log2) 1<<log2
28 /* For ELF we need the `.type' directive to make shared libs work right.  */
29 #define ASM_TYPE_DIRECTIVE(name,typearg) .type name,typearg;
30 #define ASM_SIZE_DIRECTIVE(name) .size name,.-name;
31 
32 #else
33 
34 #define ALIGNARG(log2) log2
35 #define ASM_TYPE_DIRECTIVE(name,type)	/* Nothing is specified.  */
36 #define ASM_SIZE_DIRECTIVE(name)	/* Nothing is specified.  */
37 
38 #endif
39 
40 
41 /* Define an entry point visible from C.  */
42 #define	ENTRY(name)							      \
43   ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name);				      \
44   ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),@function)			      \
45   .align ALIGNARG(4);							      \
46   C_LABEL(name)								      \
47   cfi_startproc;							      \
48   CALL_MCOUNT
49 
50 #undef	END
51 #define END(name)							      \
52   cfi_endproc;								      \
53   ASM_SIZE_DIRECTIVE(name)
54 
55 /* If compiled for profiling, call `mcount' at the start of each function.  */
56 #ifdef	PROF
57 /* The mcount code relies on a normal frame pointer being on the stack
58    to locate our caller, so push one just for its benefit.  */
59 #define CALL_MCOUNT                                                          \
60   pushq %rbp;                                                                \
61   cfi_adjust_cfa_offset(8);                                                  \
62   movq %rsp, %rbp;                                                           \
63   cfi_def_cfa_register(%rbp);                                                \
64   call JUMPTARGET(mcount);                                                   \
65   popq %rbp;                                                                 \
66   cfi_def_cfa(rsp,8);
67 #else
68 #define CALL_MCOUNT		/* Do nothing.  */
69 #endif
70 
71 /* Since C identifiers are not normally prefixed with an underscore
72    on this system, the asm identifier `syscall_error' intrudes on the
73    C name space.  Make sure we use an innocuous name.  */
74 #define	syscall_error	__syscall_error
75 #define mcount		_mcount
76 
77 #define	PSEUDO(name, syscall_name, args)				      \
78 lose:									      \
79   jmp JUMPTARGET(syscall_error)						      \
80   .globl syscall_error;							      \
81   ENTRY (name)								      \
82   DO_CALL (syscall_name, args);						      \
83   jb lose
84 
85 #undef	PSEUDO_END
86 #define	PSEUDO_END(name)						      \
87   END (name)
88 
89 #undef JUMPTARGET
90 #ifdef PIC
91 #define JUMPTARGET(name)	name##@PLT
92 #else
93 #define JUMPTARGET(name)	name
94 #endif
95 
96 /* Local label name for asm code. */
97 #ifndef L
98 # ifdef HAVE_ELF
99 /* ELF-like local names start with `.L'.  */
100 #  define L(name)	.L##name
101 # else
102 #  define L(name)	name
103 # endif
104 #endif
105 
106 #endif	/* __ASSEMBLER__ */
107