xref: /haiku/src/system/libroot/posix/glibc/include/arch/x86/sysdep.h (revision 8bdd63fe5d3a5048b2a81eb8f545b1c47528e320)
1*5af32e75SAxel Dörfler /* Assembler macros for i386.
2*5af32e75SAxel Dörfler    Copyright (C) 1991, 92, 93, 95, 96, 98 Free Software Foundation, Inc.
3*5af32e75SAxel Dörfler    This file is part of the GNU C Library.
4*5af32e75SAxel Dörfler 
5*5af32e75SAxel Dörfler    The GNU C Library is free software; you can redistribute it and/or
6*5af32e75SAxel Dörfler    modify it under the terms of the GNU Lesser General Public
7*5af32e75SAxel Dörfler    License as published by the Free Software Foundation; either
8*5af32e75SAxel Dörfler    version 2.1 of the License, or (at your option) any later version.
9*5af32e75SAxel Dörfler 
10*5af32e75SAxel Dörfler    The GNU C Library is distributed in the hope that it will be useful,
11*5af32e75SAxel Dörfler    but WITHOUT ANY WARRANTY; without even the implied warranty of
12*5af32e75SAxel Dörfler    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13*5af32e75SAxel Dörfler    Lesser General Public License for more details.
14*5af32e75SAxel Dörfler 
15*5af32e75SAxel Dörfler    You should have received a copy of the GNU Lesser General Public
16*5af32e75SAxel Dörfler    License along with the GNU C Library; if not, write to the Free
17*5af32e75SAxel Dörfler    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18*5af32e75SAxel Dörfler    02111-1307 USA.  */
19*5af32e75SAxel Dörfler 
20*5af32e75SAxel Dörfler #include_next <sysdep.h>
21*5af32e75SAxel Dörfler 
22*5af32e75SAxel Dörfler #ifdef	__ASSEMBLER__
23*5af32e75SAxel Dörfler 
24*5af32e75SAxel Dörfler /* Syntactic details of assembler.  */
25*5af32e75SAxel Dörfler 
26*5af32e75SAxel Dörfler #ifdef HAVE_ELF
27*5af32e75SAxel Dörfler 
28*5af32e75SAxel Dörfler /* ELF uses byte-counts for .align, most others use log2 of count of bytes.  */
29*5af32e75SAxel Dörfler #define ALIGNARG(log2) 1<<log2
30*5af32e75SAxel Dörfler /* For ELF we need the `.type' directive to make shared libs work right.  */
31*5af32e75SAxel Dörfler #define ASM_TYPE_DIRECTIVE(name,typearg) .type name,typearg;
32*5af32e75SAxel Dörfler #define ASM_SIZE_DIRECTIVE(name) .size name,.-name;
33*5af32e75SAxel Dörfler 
34*5af32e75SAxel Dörfler #else
35*5af32e75SAxel Dörfler 
36*5af32e75SAxel Dörfler #define ALIGNARG(log2) log2
37*5af32e75SAxel Dörfler #define ASM_TYPE_DIRECTIVE(name,type)	/* Nothing is specified.  */
38*5af32e75SAxel Dörfler #define ASM_SIZE_DIRECTIVE(name)	/* Nothing is specified.  */
39*5af32e75SAxel Dörfler 
40*5af32e75SAxel Dörfler #endif
41*5af32e75SAxel Dörfler 
42*5af32e75SAxel Dörfler 
43*5af32e75SAxel Dörfler /* Define an entry point visible from C.
44*5af32e75SAxel Dörfler 
45*5af32e75SAxel Dörfler    There is currently a bug in gdb which prevents us from specifying
46*5af32e75SAxel Dörfler    incomplete stabs information.  Fake some entries here which specify
47*5af32e75SAxel Dörfler    the current source file.  */
48*5af32e75SAxel Dörfler #define	ENTRY(name)							      \
49*5af32e75SAxel Dörfler   STABS_CURRENT_FILE1("")						      \
50*5af32e75SAxel Dörfler   STABS_CURRENT_FILE(name)						      \
51*5af32e75SAxel Dörfler   ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name);				      \
52*5af32e75SAxel Dörfler   ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),@function)			      \
53*5af32e75SAxel Dörfler   .align ALIGNARG(4);							      \
54*5af32e75SAxel Dörfler   STABS_FUN(name)							      \
55*5af32e75SAxel Dörfler   C_LABEL(name)								      \
56*5af32e75SAxel Dörfler   CALL_MCOUNT
57*5af32e75SAxel Dörfler 
58*5af32e75SAxel Dörfler #undef	END
59*5af32e75SAxel Dörfler #define END(name)							      \
60*5af32e75SAxel Dörfler   ASM_SIZE_DIRECTIVE(name)						      \
61*5af32e75SAxel Dörfler   STABS_FUN_END(name)
62*5af32e75SAxel Dörfler 
63*5af32e75SAxel Dörfler /* Remove the following two lines once the gdb bug is fixed.  */
64*5af32e75SAxel Dörfler #define STABS_CURRENT_FILE(name)					      \
65*5af32e75SAxel Dörfler   STABS_CURRENT_FILE1 (#name)
66*5af32e75SAxel Dörfler #define STABS_CURRENT_FILE1(name)					      \
67*5af32e75SAxel Dörfler   1: .stabs name,100,0,0,1b;
68*5af32e75SAxel Dörfler /* Emit stabs definition lines.  We use F(0,1) and define t(0,1) as `int',
69*5af32e75SAxel Dörfler    the same way gcc does it.  */
70*5af32e75SAxel Dörfler #define STABS_FUN(name) STABS_FUN2(name, name##:F(0,1))
71*5af32e75SAxel Dörfler #define STABS_FUN2(name, namestr)					      \
72*5af32e75SAxel Dörfler   .stabs "int:t(0,1)=r(0,1);-2147483648;2147483647;",128,0,0,0;		      \
73*5af32e75SAxel Dörfler   .stabs #namestr,36,0,0,name;
74*5af32e75SAxel Dörfler #define STABS_FUN_END(name)						      \
75*5af32e75SAxel Dörfler   1: .stabs "",36,0,0,1b-name;
76*5af32e75SAxel Dörfler 
77*5af32e75SAxel Dörfler /* If compiled for profiling, call `mcount' at the start of each function.  */
78*5af32e75SAxel Dörfler #ifdef	PROF
79*5af32e75SAxel Dörfler /* The mcount code relies on a normal frame pointer being on the stack
80*5af32e75SAxel Dörfler    to locate our caller, so push one just for its benefit.  */
81*5af32e75SAxel Dörfler #define CALL_MCOUNT \
82*5af32e75SAxel Dörfler   pushl %ebp; movl %esp, %ebp; call JUMPTARGET(mcount); popl %ebp;
83*5af32e75SAxel Dörfler #else
84*5af32e75SAxel Dörfler #define CALL_MCOUNT		/* Do nothing.  */
85*5af32e75SAxel Dörfler #endif
86*5af32e75SAxel Dörfler 
87*5af32e75SAxel Dörfler /* Since C identifiers are not normally prefixed with an underscore
88*5af32e75SAxel Dörfler    on this system, the asm identifier `syscall_error' intrudes on the
89*5af32e75SAxel Dörfler    C name space.  Make sure we use an innocuous name.  */
90*5af32e75SAxel Dörfler #define	syscall_error	__syscall_error
91*5af32e75SAxel Dörfler #define mcount		_mcount
92*5af32e75SAxel Dörfler 
93*5af32e75SAxel Dörfler #define	PSEUDO(name, syscall_name, args)				      \
94*5af32e75SAxel Dörfler lose: SYSCALL_PIC_SETUP							      \
95*5af32e75SAxel Dörfler   jmp JUMPTARGET(syscall_error)						      \
96*5af32e75SAxel Dörfler   .globl syscall_error;							      \
97*5af32e75SAxel Dörfler   ENTRY (name)								      \
98*5af32e75SAxel Dörfler   DO_CALL (syscall_name, args);						      \
99*5af32e75SAxel Dörfler   jb lose
100*5af32e75SAxel Dörfler 
101*5af32e75SAxel Dörfler #undef	PSEUDO_END
102*5af32e75SAxel Dörfler #define	PSEUDO_END(name)						      \
103*5af32e75SAxel Dörfler   END (name)
104*5af32e75SAxel Dörfler 
105*5af32e75SAxel Dörfler #ifdef PIC
106*5af32e75SAxel Dörfler #define JUMPTARGET(name)	name##@PLT
107*5af32e75SAxel Dörfler #define SYSCALL_PIC_SETUP \
108*5af32e75SAxel Dörfler     pushl %ebx;								      \
109*5af32e75SAxel Dörfler     call 0f;								      \
110*5af32e75SAxel Dörfler 0:  popl %ebx;								      \
111*5af32e75SAxel Dörfler     addl $_GLOBAL_OFFSET_TABLE+[.-0b], %ebx;
112*5af32e75SAxel Dörfler #else
113*5af32e75SAxel Dörfler #define JUMPTARGET(name)	name
114*5af32e75SAxel Dörfler #define SYSCALL_PIC_SETUP	/* Nothing.  */
115*5af32e75SAxel Dörfler #endif
116*5af32e75SAxel Dörfler 
117*5af32e75SAxel Dörfler /* Local label name for asm code. */
118*5af32e75SAxel Dörfler #ifndef L
119*5af32e75SAxel Dörfler #define L(name)		name
120*5af32e75SAxel Dörfler #endif
121*5af32e75SAxel Dörfler 
122*5af32e75SAxel Dörfler #endif	/* __ASSEMBLER__ */
123