1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  23  */
  24 /*
  25  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  26  * Use is subject to license terms.
  27  */
  28 
  29 #ifndef _LIBM_H
  30 #define         _LIBM_H
  31 
  32 #include <sys/isa_defs.h>
  33 
  34 #ifdef _ASM
  35 /* BEGIN CSTYLED */
  36 
  37 /*
  38  * Disable amd64 assembly code profiling for now.
  39  */
  40 #if defined(__amd64)
  41 #undef PROF
  42 #endif
  43 
  44 #include <sys/asm_linkage.h>
  45 
  46 #define         NAME(x) x
  47 #define         TEXT    .section        ".text"
  48 #define         DATA    .section        ".data"
  49 #define         RO_DATA .section        ".rodata"
  50 #define         IDENT(x)        .ident  x
  51 
  52 #if defined(__sparc)
  53 #define         LIBM_ANSI_PRAGMA_WEAK(sym,stype) \
  54         .weak __/**/sym;                 \
  55         .type __/**/sym,#stype;          \
  56 __/**/sym       = sym
  57 
  58 #ifndef SET_FILE
  59 #define         SET_FILE(x) \
  60         .file   x
  61 #endif  /* !defined(SET_FILE) */
  62 
  63 #ifdef PIC
  64 /*
  65  * One should *never* pass o7 to PIC_SETUP.
  66  */
  67 #define         PIC_SETUP(via) \
  68 9:      call    8f; \
  69         sethi   %hi(NAME(_GLOBAL_OFFSET_TABLE_)-(9b-.)),%via; \
  70 8:      or      %via,%lo(NAME(_GLOBAL_OFFSET_TABLE_)-(9b-.)),%via; \
  71         add     %via,%o7,%via
  72 /*
  73  * Must save/restore %o7 in leaf routines; may *not* use jmpl!
  74  */
  75 #define         PIC_LEAF_SETUP(via) \
  76         or      %g0,%o7,%g1; \
  77 9:      call    8f; \
  78         sethi   %hi(NAME(_GLOBAL_OFFSET_TABLE_)-(9b-.)),%via; \
  79 8:      or      %via,%lo(NAME(_GLOBAL_OFFSET_TABLE_)-(9b-.)),%via; \
  80         add     %via,%o7,%via; \
  81         or      %g0,%g1,%o7
  82 #ifdef __sparcv9
  83 #define         PIC_SET(via,sym,dst)    ldx     [%via+sym],%dst
  84 #else   /* defined(__sparcv9) */
  85 #define         PIC_SET(via,sym,dst)    ld      [%via+sym],%dst
  86 #endif  /* defined(__sparcv9) */
  87 #else   /* defined(PIC) */
  88 #define         PIC_SETUP(via)
  89 #define         PIC_LEAF_SETUP(via)
  90 #ifdef __sparcv9
  91 /*
  92  * g1 is used as scratch register in V9 mode
  93  */
  94 #define         PIC_SET(via,sym,dst)    setx    sym,%g1,%dst
  95 #else   /* defined(__sparcv9) */
  96 #define         PIC_SET(via,sym,dst)    set     sym,%dst
  97 #endif  /* defined(__sparcv9) */
  98 #endif  /* defined(PIC) */
  99 
 100 /*
 101  * Workaround for 4337025: MCOUNT in asm_linkage.h does not support __sparcv9
 102  */
 103 #if defined(PROF) && defined(__sparcv9)
 104 #undef MCOUNT_SIZE
 105 #undef MCOUNT
 106 
 107 #if !defined(PIC)
 108 #define         MCOUNT_SIZE     (9*4)   /* 9 instructions */
 109 #define         MCOUNT(x) \
 110         save    %sp, -SA(MINFRAME), %sp; \
 111         sethi   %hh(.L_/**/x/**/1), %o0; \
 112         sethi   %lm(.L_/**/x/**/1), %o1; \
 113         or      %o0, %hm(.L_/**/x/**/1), %o0; \
 114         or      %o1, %lo(.L_/**/x/**/1), %o1; \
 115         sllx    %o0, 32, %o0; \
 116         call    _mcount; \
 117         or      %o0, %o1, %o0; \
 118         restore; \
 119         .common .L_/**/x/**/1, 8, 8
 120 #elif defined(PIC32)
 121 #define         MCOUNT_SIZE     (10*4)  /* 10 instructions */
 122 #define         MCOUNT(x) \
 123         save    %sp,-SA(MINFRAME),%sp; \
 124 1:      call    .+8; \
 125         sethi   %hi(_GLOBAL_OFFSET_TABLE_-(1b-.)),%o0; \
 126         sethi   %hi(.L_/**/x/**/1),%o1; \
 127         add     %o0,%lo(_GLOBAL_OFFSET_TABLE_-(1b-.)),%o0; \
 128         add     %o1,%lo(.L_/**/x/**/1),%o1; \
 129         add     %o0,%o7,%o0; \
 130         call    _mcount; \
 131         ldx     [%o0+%o1],%o0; \
 132         restore; \
 133         .common .L_/**/x/**/1,8,8
 134 #else   /* PIC13 */
 135 #define         MCOUNT_SIZE     (8*4)   /* 8 instructions */
 136 #define         MCOUNT(x) \
 137         save    %sp,-SA(MINFRAME),%sp; \
 138 1:      call    .+8; \
 139         sethi   %hi(_GLOBAL_OFFSET_TABLE_-(1b-.)),%o0; \
 140         add     %o0,%lo(_GLOBAL_OFFSET_TABLE_-(1b-.)),%o0; \
 141         add     %o0,%o7,%o0; \
 142         call    _mcount; \
 143         ldx     [%o0+%lo(.L_/**/x/**/1)],%o0; \
 144         restore; \
 145         .common .L_/**/x/**/1,8,8
 146 #endif  /* !defined(PIC) */
 147 #endif /* defined(PROF) && defined(__sparcv9) */
 148 #elif defined(__x86)
 149 #define         LIBM_ANSI_PRAGMA_WEAK(sym,stype) \
 150         .weak __/**/sym;                 \
 151         .type __/**/sym,@stype;          \
 152 __/**/sym       = sym
 153 
 154 #ifdef PIC
 155 #if defined(__amd64)
 156 #define         PIC_SETUP(x)
 157 #define         PIC_WRAPUP
 158 #define         PIC_F(x)        x@PLT
 159 #define         PIC_G(x)        x@GOTPCREL(%rip)
 160 #define         PIC_L(x)        x(%rip)
 161 #define         PIC_G_LOAD(insn,sym,dst) \
 162         movq    PIC_G(sym),%dst; \
 163         insn    (%dst),%dst
 164 #else
 165 #define         PIC_SETUP(label) \
 166         pushl   %ebx; \
 167         call    .label; \
 168 .label: popl    %ebx; \
 169         addl    $_GLOBAL_OFFSET_TABLE_+[.-.label],%ebx
 170 #define         PIC_WRAPUP      popl    %ebx
 171 #define         PIC_F(x)        x@PLT
 172 #define         PIC_G(x)        x@GOT(%ebx)
 173 #define         PIC_L(x)        x@GOTOFF(%ebx)
 174 #define         PIC_G_LOAD(insn,sym,dst) \
 175         mov     PIC_G(sym),%dst; \
 176         insn    (%dst),%dst
 177 #endif
 178 #else   /* defined(PIC) */
 179 #define         PIC_SETUP(x)
 180 #define         PIC_WRAPUP
 181 #define         PIC_F(x)        x
 182 #define         PIC_G(x)        x
 183 #define         PIC_L(x)        x
 184 #define         PIC_G_LOAD(insn,sym,dst)        insn    sym,%dst
 185 #endif  /* defined(PIC) */
 186 #else
 187 #error Unknown architecture
 188 #endif
 189 
 190 /* END CSTYLED */
 191 #else   /* defined(_ASM) */
 192 #include "libm_macros.h"
 193 #include "libm_protos.h"
 194 #include "libm_inlines.h"
 195 #include <math.h>
 196 #if defined(__SUNPRO_C)
 197 #include <sunmath.h>
 198 #endif
 199 #endif  /* defined(_ASM) */
 200 #endif  /* _LIBM_H */