Back to index

glibc  2.9
sysdep.h
Go to the documentation of this file.
00001 /* Assembly macros for 64-bit PowerPC.
00002    Copyright (C) 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA
00018    02110-1301 USA.  */
00019 
00020 #include <sysdeps/powerpc/sysdep.h>
00021 
00022 #ifdef __ELF__
00023 
00024 #ifdef __ASSEMBLER__
00025 
00026 /* Support macros for CALL_MCOUNT.  */
00027        .macro SAVE_ARG NARG
00028        .if \NARG
00029        SAVE_ARG \NARG-1
00030        std    2+\NARG,-72+8*(\NARG)(1)
00031        .endif
00032        .endm
00033 
00034        .macro REST_ARG NARG
00035        .if \NARG
00036        REST_ARG \NARG-1
00037        ld     2+\NARG,40+8*(\NARG)(1)
00038        .endif
00039        .endm
00040 
00041 /* If compiled for profiling, call `_mcount' at the start of each function.
00042    see ppc-mcount.S for more details.  */
00043        .macro CALL_MCOUNT NARG
00044 #ifdef PROF
00045        mflr   r0
00046        SAVE_ARG \NARG
00047        std    r0,16(r1)
00048        stdu   r1,-112(r1)
00049        bl     JUMPTARGET (_mcount)
00050        ld     r0,128(r1)
00051        REST_ARG \NARG
00052        addi   r1,r1,112
00053        mtlr   r0
00054 #endif
00055        .endm
00056 
00057 #ifdef USE_PPC64_OVERLAPPING_OPD
00058 # define OPD_ENT(name)      .quad BODY_LABEL (name), .TOC.@tocbase
00059 #else
00060 # define OPD_ENT(name)      .quad BODY_LABEL (name), .TOC.@tocbase, 0
00061 #endif
00062 
00063 #define ENTRY_1(name)       \
00064        .section      ".text";             \
00065        .type BODY_LABEL(name),@function;  \
00066        .globl name;                       \
00067        .section ".opd","aw";                     \
00068        .align 3;                          \
00069 name##: OPD_ENT (name);                          \
00070        .previous;
00071 
00072 #ifdef HAVE_ASM_GLOBAL_DOT_NAME
00073 # define DOT_LABEL(X) .##X
00074 # define BODY_LABEL(X) .##X
00075 # define ENTRY_2(name)      \
00076        .globl BODY_LABEL(name);           \
00077        ENTRY_1(name)                      \
00078        .size name, 24;
00079 # define END_2(name) \
00080        .size BODY_LABEL(name),.-BODY_LABEL(name);
00081 #else
00082 # define DOT_LABEL(X) X
00083 # define BODY_LABEL(X) .LY##X
00084 # define ENTRY_2(name)      \
00085        .type name,@function;                     \
00086        ENTRY_1(name)
00087 # define END_2(name) \
00088        .size name,.-BODY_LABEL(name);            \
00089        .size BODY_LABEL(name),.-BODY_LABEL(name);
00090 #endif
00091 
00092 #define ENTRY(name)  \
00093        ENTRY_2(name)                      \
00094        .align ALIGNARG(2);                \
00095 BODY_LABEL(name):                         \
00096        cfi_startproc;
00097 
00098 #define EALIGN_W_0  /* No words to insert.  */
00099 #define EALIGN_W_1  nop
00100 #define EALIGN_W_2  nop;nop
00101 #define EALIGN_W_3  nop;nop;nop
00102 #define EALIGN_W_4  EALIGN_W_3;nop
00103 #define EALIGN_W_5  EALIGN_W_4;nop
00104 #define EALIGN_W_6  EALIGN_W_5;nop
00105 #define EALIGN_W_7  EALIGN_W_6;nop
00106 
00107 /* EALIGN is like ENTRY, but does alignment to 'words'*4 bytes
00108    past a 2^alignt boundary.  */
00109 #define EALIGN(name, alignt, words) \
00110        ENTRY_2(name)                      \
00111        .align ALIGNARG(alignt);           \
00112        EALIGN_W_##words;                  \
00113 BODY_LABEL(name):                         \
00114        cfi_startproc;
00115 
00116 /* Local labels stripped out by the linker.  */
00117 #undef L
00118 #define L(x) .L##x
00119 
00120 #define tostring(s) #s
00121 #define stringify(s) tostring(s)
00122 #define XGLUE(a,b) a##b
00123 #define GLUE(a,b) XGLUE(a,b)
00124 #define LT_LABEL(name) GLUE(.LT,name)
00125 #define LT_LABELSUFFIX(name,suffix) GLUE(GLUE(.LT,name),suffix)
00126 
00127 /* Support Traceback tables */
00128 #define TB_ASM                     0x000c000000000000
00129 #define TB_GLOBALLINK              0x0000800000000000
00130 #define TB_IS_EPROL         0x0000400000000000
00131 #define TB_HAS_TBOFF        0x0000200000000000
00132 #define TB_INT_PROC         0x0000100000000000
00133 #define TB_HAS_CTL          0x0000080000000000
00134 #define TB_TOCLESS          0x0000040000000000
00135 #define TB_FP_PRESENT              0x0000020000000000
00136 #define TB_LOG_ABORT        0x0000010000000000
00137 #define TB_INT_HANDL        0x0000008000000000
00138 #define TB_NAME_PRESENT            0x0000004000000000
00139 #define TB_USES_ALLOCA             0x0000002000000000
00140 #define TB_SAVES_CR         0x0000000200000000
00141 #define TB_SAVES_LR         0x0000000100000000
00142 #define TB_STORES_BC        0x0000000080000000
00143 #define TB_FIXUP            0x0000000040000000
00144 #define TB_FP_SAVED(fprs)   (((fprs) & 0x3f) << 24)
00145 #define TB_GPR_SAVED(gprs)  (((fprs) & 0x3f) << 16)
00146 #define TB_FIXEDPARMS(parms)       (((parms) & 0xff) << 8)
00147 #define TB_FLOATPARMS(parms)       (((parms) & 0x7f) << 1)
00148 #define TB_PARMSONSTK              0x0000000000000001
00149 
00150 #define PPC_HIGHER(v)              (((v) >> 32) & 0xffff)
00151 #define TB_DEFAULT          TB_ASM | TB_HAS_TBOFF | TB_NAME_PRESENT
00152 
00153 #define TRACEBACK(name) \
00154 LT_LABEL(name): ; \
00155        .long  0 ; \
00156        .quad  TB_DEFAULT ; \
00157        .long  LT_LABEL(name)-BODY_LABEL(name) ; \
00158        .short LT_LABELSUFFIX(name,_name_end)-LT_LABELSUFFIX(name,_name_start) ; \
00159 LT_LABELSUFFIX(name,_name_start): ;\
00160        .ascii stringify(name) ; \
00161 LT_LABELSUFFIX(name,_name_end): ; \
00162        .align 2 ;
00163 
00164 #define TRACEBACK_MASK(name,mask) \
00165 LT_LABEL(name): ; \
00166        .long  0 ; \
00167        .quad  TB_DEFAULT | mask ; \
00168        .long  LT_LABEL(name)-BODY_LABEL(name) ; \
00169        .short LT_LABELSUFFIX(name,_name_end)-LT_LABELSUFFIX(name,_name_start) ; \
00170 LT_LABELSUFFIX(name,_name_start): ;\
00171        .ascii stringify(name) ; \
00172 LT_LABELSUFFIX(name,_name_end): ; \
00173        .align 2 ;
00174 
00175 /* END generates Traceback tables */
00176 #undef END
00177 #define END(name) \
00178   cfi_endproc;                     \
00179   TRACEBACK(name)           \
00180   END_2(name)
00181 
00182 /* This form supports more informative traceback tables */
00183 #define END_GEN_TB(name,mask)      \
00184   cfi_endproc;                     \
00185   TRACEBACK_MASK(name,mask) \
00186   END_2(name)
00187 
00188 #define DO_CALL(syscall) \
00189     li 0,syscall; \
00190     sc
00191 
00192 /* ppc64 is always PIC */
00193 #undef JUMPTARGET
00194 #define JUMPTARGET(name) DOT_LABEL(name)
00195 
00196 #define PSEUDO(name, syscall_name, args) \
00197   .section ".text";  \
00198   ENTRY (name) \
00199   DO_CALL (SYS_ify (syscall_name));
00200 
00201 #define PSEUDO_RET \
00202     bnslr+; \
00203     b JUMPTARGET(__syscall_error)
00204 
00205 #define ret PSEUDO_RET
00206 
00207 #undef PSEUDO_END
00208 #define       PSEUDO_END(name) \
00209   END (name)
00210 
00211 #define PSEUDO_NOERRNO(name, syscall_name, args) \
00212   .section ".text";  \
00213   ENTRY (name) \
00214   DO_CALL (SYS_ify (syscall_name));
00215 
00216 #define PSEUDO_RET_NOERRNO \
00217     blr
00218 
00219 #define ret_NOERRNO PSEUDO_RET_NOERRNO
00220 
00221 #undef PSEUDO_END_NOERRNO
00222 #define       PSEUDO_END_NOERRNO(name) \
00223   END (name)
00224 
00225 #define PSEUDO_ERRVAL(name, syscall_name, args) \
00226   .section ".text";  \
00227   ENTRY (name) \
00228   DO_CALL (SYS_ify (syscall_name));
00229 
00230 #define PSEUDO_RET_ERRVAL \
00231     blr
00232 
00233 #define ret_ERRVAL PSEUDO_RET_ERRVAL
00234 
00235 #undef PSEUDO_END_ERRVAL
00236 #define       PSEUDO_END_ERRVAL(name) \
00237   END (name)
00238 
00239 #else /* !__ASSEMBLER__ */
00240 
00241 #ifdef USE_PPC64_OVERLAPPING_OPD
00242 # define OPD_ENT(name)      ".quad " BODY_PREFIX #name ", .TOC.@tocbase;"
00243 #else
00244 # define OPD_ENT(name)      ".quad " BODY_PREFIX #name ", .TOC.@tocbase, 0;"
00245 #endif
00246 
00247 #ifdef HAVE_ASM_GLOBAL_DOT_NAME
00248 # define DOT_PREFIX "."
00249 # define BODY_PREFIX "."
00250 # define ENTRY_2(name)      \
00251        ".globl " BODY_PREFIX #name ";\n"                       \
00252        ".size  " #name ", 24;"
00253 # define END_2(name) \
00254        ".size " BODY_PREFIX #name ",.-" BODY_PREFIX #name ";"
00255 #else
00256 # define DOT_PREFIX ""
00257 # define BODY_PREFIX ".LY"
00258 # define ENTRY_2(name) ".type " #name ",@function;"
00259 # define END_2(name) \
00260        ".size " #name ",.-" BODY_PREFIX #name ";\n"                   \
00261        ".size " BODY_PREFIX #name ",.-" BODY_PREFIX #name ";"
00262 #endif
00263 
00264 #endif /* __ASSEMBLER__ */
00265 
00266 #endif /* __ELF__ */