]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re-core/uclibc/lib/contrib/uclibc/libc/sysdeps/linux/powerpc/powerpc64/sysdep.h
Update
[l4.git] / l4 / pkg / l4re-core / uclibc / lib / contrib / uclibc / libc / sysdeps / linux / powerpc / powerpc64 / sysdep.h
1 /* Assembly macros for 64-bit PowerPC.
2    Copyright (C) 2002, 2003, 2004, 2006 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 #ifdef __ELF__
20
21 #ifdef __ASSEMBLER__
22
23 /* Support macros for CALL_MCOUNT.  */
24         .macro SAVE_ARG NARG
25         .if \NARG
26         SAVE_ARG \NARG-1
27         std     2+\NARG,-72+8*(\NARG)(1)
28         .endif
29         .endm
30
31         .macro REST_ARG NARG
32         .if \NARG
33         REST_ARG \NARG-1
34         ld      2+\NARG,40+8*(\NARG)(1)
35         .endif
36         .endm
37
38 /* If compiled for profiling, call `_mcount' at the start of each function.
39    see ppc-mcount.S for more details.  */
40         .macro CALL_MCOUNT NARG
41 #ifdef  PROF
42         mflr    r0
43         SAVE_ARG \NARG
44         std     r0,16(r1)
45         stdu    r1,-112(r1)
46         bl      JUMPTARGET (_mcount)
47         ld      r0,128(r1)
48         REST_ARG \NARG
49         addi    r1,r1,112
50         mtlr    r0
51 #endif
52         .endm
53
54 #ifdef USE_PPC64_OVERLAPPING_OPD
55 # define OPD_ENT(name)  .quad BODY_LABEL (name), .TOC.@tocbase
56 #else
57 # define OPD_ENT(name)  .quad BODY_LABEL (name), .TOC.@tocbase, 0
58 #endif
59
60 #define ENTRY_1(name)   \
61         .section        ".text";                \
62         .type BODY_LABEL(name),@function;       \
63         .globl name;                            \
64         .section ".opd","aw";                   \
65         .align 3;                               \
66 name##: OPD_ENT (name);                         \
67         .previous;
68
69 #ifdef HAVE_ASM_GLOBAL_DOT_NAME
70 # define DOT_LABEL(X) .##X
71 # define BODY_LABEL(X) .##X
72 # define ENTRY_2(name)  \
73         .globl BODY_LABEL(name);                \
74         ENTRY_1(name)                           \
75         .size name, 24;
76 # define END_2(name)    \
77         .size BODY_LABEL(name),.-BODY_LABEL(name);
78 #else
79 # define DOT_LABEL(X) X
80 # define BODY_LABEL(X) .LY##X
81 # define ENTRY_2(name)  \
82         .type name,@function;                   \
83         ENTRY_1(name)
84 # define END_2(name)    \
85         .size name,.-BODY_LABEL(name);          \
86         .size BODY_LABEL(name),.-BODY_LABEL(name);
87 #endif
88
89 #define ENTRY(name)     \
90         ENTRY_2(name)                           \
91         .align ALIGNARG(2);                     \
92 BODY_LABEL(name):                               \
93         cfi_startproc;
94
95 #define EALIGN_W_0  /* No words to insert.  */
96 #define EALIGN_W_1  nop
97 #define EALIGN_W_2  nop;nop
98 #define EALIGN_W_3  nop;nop;nop
99 #define EALIGN_W_4  EALIGN_W_3;nop
100 #define EALIGN_W_5  EALIGN_W_4;nop
101 #define EALIGN_W_6  EALIGN_W_5;nop
102 #define EALIGN_W_7  EALIGN_W_6;nop
103
104 /* EALIGN is like ENTRY, but does alignment to 'words'*4 bytes
105    past a 2^alignt boundary.  */
106 #define EALIGN(name, alignt, words) \
107         ENTRY_2(name)                           \
108         .align ALIGNARG(alignt);                \
109         EALIGN_W_##words;                       \
110 BODY_LABEL(name):                               \
111         cfi_startproc;
112
113 /* Local labels stripped out by the linker.  */
114 #undef L
115 #define L(x) .L##x
116
117 #define tostring(s) #s
118 #define stringify(s) tostring(s)
119 #define XGLUE(a,b) a##b
120 #define GLUE(a,b) XGLUE(a,b)
121 #define LT_LABEL(name) GLUE(.LT,name)
122 #define LT_LABELSUFFIX(name,suffix) GLUE(GLUE(.LT,name),suffix)
123
124 /* Support Traceback tables */
125 #define TB_ASM                  0x000c000000000000
126 #define TB_GLOBALLINK           0x0000800000000000
127 #define TB_IS_EPROL             0x0000400000000000
128 #define TB_HAS_TBOFF            0x0000200000000000
129 #define TB_INT_PROC             0x0000100000000000
130 #define TB_HAS_CTL              0x0000080000000000
131 #define TB_TOCLESS              0x0000040000000000
132 #define TB_FP_PRESENT           0x0000020000000000
133 #define TB_LOG_ABORT            0x0000010000000000
134 #define TB_INT_HANDL            0x0000008000000000
135 #define TB_NAME_PRESENT         0x0000004000000000
136 #define TB_USES_ALLOCA          0x0000002000000000
137 #define TB_SAVES_CR             0x0000000200000000
138 #define TB_SAVES_LR             0x0000000100000000
139 #define TB_STORES_BC            0x0000000080000000
140 #define TB_FIXUP                0x0000000040000000
141 #define TB_FP_SAVED(fprs)       (((fprs) & 0x3f) << 24)
142 #define TB_GPR_SAVED(gprs)      (((fprs) & 0x3f) << 16)
143 #define TB_FIXEDPARMS(parms)    (((parms) & 0xff) << 8)
144 #define TB_FLOATPARMS(parms)    (((parms) & 0x7f) << 1)
145 #define TB_PARMSONSTK           0x0000000000000001
146
147 #define PPC_HIGHER(v)           (((v) >> 32) & 0xffff)
148 #define TB_DEFAULT              TB_ASM | TB_HAS_TBOFF | TB_NAME_PRESENT
149
150 #define TRACEBACK(name) \
151 LT_LABEL(name): ; \
152         .long   0 ; \
153         .quad   TB_DEFAULT ; \
154         .long   LT_LABEL(name)-BODY_LABEL(name) ; \
155         .short  LT_LABELSUFFIX(name,_name_end)-LT_LABELSUFFIX(name,_name_start) ; \
156 LT_LABELSUFFIX(name,_name_start): ;\
157         .ascii  stringify(name) ; \
158 LT_LABELSUFFIX(name,_name_end): ; \
159         .align  2 ;
160
161 #define TRACEBACK_MASK(name,mask) \
162 LT_LABEL(name): ; \
163         .long   0 ; \
164         .quad   TB_DEFAULT | mask ; \
165         .long   LT_LABEL(name)-BODY_LABEL(name) ; \
166         .short  LT_LABELSUFFIX(name,_name_end)-LT_LABELSUFFIX(name,_name_start) ; \
167 LT_LABELSUFFIX(name,_name_start): ;\
168         .ascii  stringify(name) ; \
169 LT_LABELSUFFIX(name,_name_end): ; \
170         .align  2 ;
171
172 /* END generates Traceback tables */
173 #undef  END
174 #define END(name) \
175   cfi_endproc;                  \
176   TRACEBACK(name)               \
177   END_2(name)
178
179 /* This form supports more informative traceback tables */
180 #define END_GEN_TB(name,mask)   \
181   cfi_endproc;                  \
182   TRACEBACK_MASK(name,mask)     \
183   END_2(name)
184
185 #define DO_CALL(syscall) \
186     li 0,syscall; \
187     sc
188
189 /* ppc64 is always PIC */
190 #undef JUMPTARGET
191 #define JUMPTARGET(name) DOT_LABEL(name)
192
193 #define PSEUDO(name, syscall_name, args) \
194   .section ".text";     \
195   ENTRY (name) \
196   DO_CALL (SYS_ify (syscall_name));
197
198 #define PSEUDO_RET \
199     bnslr+; \
200     b JUMPTARGET(__syscall_error)
201
202 #define ret PSEUDO_RET
203
204 #undef  PSEUDO_END
205 #define PSEUDO_END(name) \
206   END (name)
207
208 #define PSEUDO_NOERRNO(name, syscall_name, args) \
209   .section ".text";     \
210   ENTRY (name) \
211   DO_CALL (SYS_ify (syscall_name));
212
213 #define PSEUDO_RET_NOERRNO \
214     blr
215
216 #define ret_NOERRNO PSEUDO_RET_NOERRNO
217
218 #undef  PSEUDO_END_NOERRNO
219 #define PSEUDO_END_NOERRNO(name) \
220   END (name)
221
222 #define PSEUDO_ERRVAL(name, syscall_name, args) \
223   .section ".text";     \
224   ENTRY (name) \
225   DO_CALL (SYS_ify (syscall_name));
226
227 #define PSEUDO_RET_ERRVAL \
228     blr
229
230 #undef ret_ERRVAL
231 #define ret_ERRVAL PSEUDO_RET_ERRVAL
232
233 #undef  PSEUDO_END_ERRVAL
234 #define PSEUDO_END_ERRVAL(name) \
235   END (name)
236
237 #else /* !__ASSEMBLER__ */
238
239 #ifdef USE_PPC64_OVERLAPPING_OPD
240 # define OPD_ENT(name)  ".quad " BODY_PREFIX #name ", .TOC.@tocbase;"
241 #else
242 # define OPD_ENT(name)  ".quad " BODY_PREFIX #name ", .TOC.@tocbase, 0;"
243 #endif
244
245 #ifdef HAVE_ASM_GLOBAL_DOT_NAME
246 # define DOT_PREFIX "."
247 # define BODY_PREFIX "."
248 # define ENTRY_2(name)  \
249         ".globl " BODY_PREFIX #name ";\n"                               \
250         ".size  " #name ", 24;"
251 # define END_2(name)    \
252         ".size " BODY_PREFIX #name ",.-" BODY_PREFIX #name ";"
253 #else
254 # define DOT_PREFIX ""
255 # define BODY_PREFIX ".LY"
256 # define ENTRY_2(name) ".type " #name ",@function;"
257 # define END_2(name)    \
258         ".size " #name ",.-" BODY_PREFIX #name ";\n"                    \
259         ".size " BODY_PREFIX #name ",.-" BODY_PREFIX #name ";"
260 #endif
261
262 #endif  /* __ASSEMBLER__ */
263
264 #endif /* __ELF__ */