1 /* More subroutines needed by GCC output code on some machines. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 2000, 2001 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
13 In addition to the permissions in the GNU General Public License, the
14 Free Software Foundation gives you unlimited permission to link the
15 compiled version of this file into combinations with other programs,
16 and to distribute those combinations without any restriction coming
17 from the use of this file. (The General Public License restrictions
18 do apply in other respects; for example, they cover modification of
19 the file, and distribution when not linked into a combine
22 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
23 WARRANTY; without even the implied warranty of MERCHANTABILITY or
24 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27 You should have received a copy of the GNU General Public License
28 along with GCC; see the file COPYING. If not, write to the Free
29 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
32 /* It is incorrect to include config.h here, because this file is being
33 compiled for the target, and hence definitions concerning only the host
37 * This file was taken from the GCC v3.1 source - Brian
47 //#include "tconfig.h"
48 //#include "tsystem.h"
50 //#include "machmode.h"
52 /* Don't use `fancy_abort' here even if config.h says to use it. */
59 #if defined (L_negdi2) || defined (L_divdi3) || defined (L_moddi3)
60 #if defined (L_divdi3) || defined (L_moddi3)
72 w
.s
.high
= -uu
.s
.high
- ((UWtype
) w
.s
.low
> 0);
80 __addvsi3 (Wtype a
, Wtype b
)
86 if (b
>= 0 ? w
< a
: w
> a
)
95 __addvdi3 (DWtype a
, DWtype b
)
101 if (b
>= 0 ? w
< a
: w
> a
)
110 __subvsi3 (Wtype a
, Wtype b
)
113 return __addvsi3 (a
, (-b
));
119 if (b
>= 0 ? w
> a
: w
< a
)
129 __subvdi3 (DWtype a
, DWtype b
)
138 if (b
>= 0 ? w
> a
: w
< a
)
148 __mulvsi3 (Wtype a
, Wtype b
)
154 if (((a
>= 0) == (b
>= 0)) ? w
< 0 : w
> 0)
169 if (a
>= 0 ? w
> 0 : w
< 0)
184 if (a
>= 0 ? w
> 0 : w
< 0)
233 __mulvdi3 (DWtype u
, DWtype v
)
239 if (((u
>= 0) == (v
>= 0)) ? w
< 0 : w
> 0)
247 /* Unless shift functions are defined whith full ANSI prototypes,
248 parameter b will be promoted to int if word_type is smaller than an int. */
251 __lshrdi3 (DWtype u
, word_type b
)
262 bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
266 w
.s
.low
= (UWtype
) uu
.s
.high
>> -bm
;
270 UWtype carries
= (UWtype
) uu
.s
.high
<< bm
;
272 w
.s
.high
= (UWtype
) uu
.s
.high
>> b
;
273 w
.s
.low
= ((UWtype
) uu
.s
.low
>> b
) | carries
;
282 __ashldi3 (DWtype u
, word_type b
)
293 bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
297 w
.s
.high
= (UWtype
) uu
.s
.low
<< -bm
;
301 UWtype carries
= (UWtype
) uu
.s
.low
>> bm
;
303 w
.s
.low
= (UWtype
) uu
.s
.low
<< b
;
304 w
.s
.high
= ((UWtype
) uu
.s
.high
<< b
) | carries
;
313 __ashrdi3 (DWtype u
, word_type b
)
324 bm
= (sizeof (Wtype
) * BITS_PER_UNIT
) - b
;
327 /* w.s.high = 1..1 or 0..0 */
328 w
.s
.high
= uu
.s
.high
>> (sizeof (Wtype
) * BITS_PER_UNIT
- 1);
329 w
.s
.low
= uu
.s
.high
>> -bm
;
333 UWtype carries
= (UWtype
) uu
.s
.high
<< bm
;
335 w
.s
.high
= uu
.s
.high
>> b
;
336 w
.s
.low
= ((UWtype
) uu
.s
.low
>> b
) | carries
;
348 UWtype word
, count
, add
;
352 word
= uu
.s
.low
, add
= 0;
353 else if (uu
.s
.high
!= 0)
354 word
= uu
.s
.high
, add
= BITS_PER_UNIT
* sizeof (Wtype
);
358 count_trailing_zeros (count
, word
);
359 return count
+ add
+ 1;
365 __muldi3 (DWtype u
, DWtype v
)
373 w
.ll
= __umulsidi3 (uu
.s
.low
, vv
.s
.low
);
374 w
.s
.high
+= ((UWtype
) uu
.s
.low
* (UWtype
) vv
.s
.high
375 + (UWtype
) uu
.s
.high
* (UWtype
) vv
.s
.low
);
382 #if defined (sdiv_qrnnd)
384 __udiv_w_sdiv (UWtype
*rp
, UWtype a1
, UWtype a0
, UWtype d
)
391 if (a1
< d
- a1
- (a0
>> (W_TYPE_SIZE
- 1)))
393 /* dividend, divisor, and quotient are nonnegative */
394 sdiv_qrnnd (q
, r
, a1
, a0
, d
);
398 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */
399 sub_ddmmss (c1
, c0
, a1
, a0
, d
>> 1, d
<< (W_TYPE_SIZE
- 1));
400 /* Divide (c1*2^32 + c0) by d */
401 sdiv_qrnnd (q
, r
, c1
, c0
, d
);
402 /* Add 2^31 to quotient */
403 q
+= (UWtype
) 1 << (W_TYPE_SIZE
- 1);
408 b1
= d
>> 1; /* d/2, between 2^30 and 2^31 - 1 */
409 c1
= a1
>> 1; /* A/2 */
410 c0
= (a1
<< (W_TYPE_SIZE
- 1)) + (a0
>> 1);
412 if (a1
< b1
) /* A < 2^32*b1, so A/2 < 2^31*b1 */
414 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
416 r
= 2*r
+ (a0
& 1); /* Remainder from A/(2*b1) */
433 else if (c1
< b1
) /* So 2^31 <= (A/2)/b1 < 2^32 */
436 c0
= ~c0
; /* logical NOT */
438 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
440 q
= ~q
; /* (A/2)/b1 */
443 r
= 2*r
+ (a0
& 1); /* A/(2*b1) */
461 else /* Implies c1 = b1 */
462 { /* Hence a1 = d - 1 = 2*b1 - 1 */
480 /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */
482 __udiv_w_sdiv (UWtype
*rp
__attribute__ ((__unused__
)),
483 UWtype a1
__attribute__ ((__unused__
)),
484 UWtype a0
__attribute__ ((__unused__
)),
485 UWtype d
__attribute__ ((__unused__
)))
492 #if (defined (L_udivdi3) || defined (L_divdi3) || \
493 defined (L_umoddi3) || defined (L_moddi3))
498 const UQItype __clz_tab
[] =
500 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
501 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
502 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
503 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
504 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
505 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
506 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
507 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
513 #if (defined (L_udivdi3) || defined (L_divdi3) || \
514 defined (L_umoddi3) || defined (L_moddi3))
518 __udivmoddi4 (UDWtype n
, UDWtype d
, UDWtype
*rp
)
523 UWtype d0
, d1
, n0
, n1
, n2
;
535 #if !UDIV_NEEDS_NORMALIZATION
542 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
545 /* Remainder in n0. */
552 d0
= 1 / d0
; /* Divide intentionally by zero. */
554 udiv_qrnnd (q1
, n1
, 0, n1
, d0
);
555 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
557 /* Remainder in n0. */
568 #else /* UDIV_NEEDS_NORMALIZATION */
576 count_leading_zeros (bm
, d0
);
580 /* Normalize, i.e. make the most significant bit of the
584 n1
= (n1
<< bm
) | (n0
>> (W_TYPE_SIZE
- bm
));
588 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
591 /* Remainder in n0 >> bm. */
598 d0
= 1 / d0
; /* Divide intentionally by zero. */
600 count_leading_zeros (bm
, d0
);
604 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
605 conclude (the most significant bit of n1 is set) /\ (the
606 leading quotient digit q1 = 1).
608 This special case is necessary, not an optimization.
609 (Shifts counts of W_TYPE_SIZE are undefined.) */
618 b
= W_TYPE_SIZE
- bm
;
622 n1
= (n1
<< bm
) | (n0
>> b
);
625 udiv_qrnnd (q1
, n1
, n2
, n1
, d0
);
630 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
632 /* Remainder in n0 >> bm. */
642 #endif /* UDIV_NEEDS_NORMALIZATION */
653 /* Remainder in n1n0. */
665 count_leading_zeros (bm
, d1
);
668 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
669 conclude (the most significant bit of n1 is set) /\ (the
670 quotient digit q0 = 0 or 1).
672 This special case is necessary, not an optimization. */
674 /* The condition on the next line takes advantage of that
675 n1 >= d1 (true due to program flow). */
676 if (n1
> d1
|| n0
>= d0
)
679 sub_ddmmss (n1
, n0
, n1
, n0
, d1
, d0
);
698 b
= W_TYPE_SIZE
- bm
;
700 d1
= (d1
<< bm
) | (d0
>> b
);
703 n1
= (n1
<< bm
) | (n0
>> b
);
706 udiv_qrnnd (q0
, n1
, n2
, n1
, d1
);
707 umul_ppmm (m1
, m0
, q0
, d0
);
709 if (m1
> n1
|| (m1
== n1
&& m0
> n0
))
712 sub_ddmmss (m1
, m0
, m1
, m0
, d1
, d0
);
717 /* Remainder in (n1n0 - m1m0) >> bm. */
720 sub_ddmmss (n1
, n0
, n1
, n0
, m1
, m0
);
721 rr
.s
.low
= (n1
<< b
) | (n0
>> bm
);
722 rr
.s
.high
= n1
>> bm
;
737 __divdi3 (DWtype u
, DWtype v
)
748 uu
.ll
= __negdi2 (uu
.ll
);
751 vv
.ll
= __negdi2 (vv
.ll
);
753 w
= __udivmoddi4 (uu
.ll
, vv
.ll
, (UDWtype
*) 0);
763 __moddi3 (DWtype u
, DWtype v
)
774 uu
.ll
= __negdi2 (uu
.ll
);
776 vv
.ll
= __negdi2 (vv
.ll
);
778 (void) __udivmoddi4 (uu
.ll
, vv
.ll
, &w
);
788 __umoddi3 (UDWtype u
, UDWtype v
)
792 (void) __udivmoddi4 (u
, v
, &w
);
800 __udivdi3 (UDWtype n
, UDWtype d
)
802 return __udivmoddi4 (n
, d
, (UDWtype
*) 0);
808 __cmpdi2 (DWtype a
, DWtype b
)
812 au
.ll
= a
, bu
.ll
= b
;
814 if (au
.s
.high
< bu
.s
.high
)
816 else if (au
.s
.high
> bu
.s
.high
)
818 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
820 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
828 __ucmpdi2 (DWtype a
, DWtype b
)
832 au
.ll
= a
, bu
.ll
= b
;
834 if ((UWtype
) au
.s
.high
< (UWtype
) bu
.s
.high
)
836 else if ((UWtype
) au
.s
.high
> (UWtype
) bu
.s
.high
)
838 if ((UWtype
) au
.s
.low
< (UWtype
) bu
.s
.low
)
840 else if ((UWtype
) au
.s
.low
> (UWtype
) bu
.s
.low
)
846 #if defined(L_fixunstfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
847 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
848 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
851 __fixunstfDI (TFtype a
)
859 /* Compute high word of result, as a flonum. */
860 b
= (a
/ HIGH_WORD_COEFF
);
861 /* Convert that to fixed (but not to DWtype!),
862 and shift it into the high word. */
865 /* Remove high part from the TFtype, leaving the low part as flonum. */
867 /* Convert that to fixed (but not to DWtype!) and add it in.
868 Sometimes A comes out negative. This is significant, since
869 A has more bits than a long int does. */
878 #if defined(L_fixtfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
883 return - __fixunstfDI (-a
);
884 return __fixunstfDI (a
);
888 #if defined(L_fixunsxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
889 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
890 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
893 __fixunsxfDI (XFtype a
)
901 /* Compute high word of result, as a flonum. */
902 b
= (a
/ HIGH_WORD_COEFF
);
903 /* Convert that to fixed (but not to DWtype!),
904 and shift it into the high word. */
907 /* Remove high part from the XFtype, leaving the low part as flonum. */
909 /* Convert that to fixed (but not to DWtype!) and add it in.
910 Sometimes A comes out negative. This is significant, since
911 A has more bits than a long int does. */
920 #if defined(L_fixxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
925 return - __fixunsxfDI (-a
);
926 return __fixunsxfDI (a
);
931 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
932 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
935 __fixunsdfDI (DFtype a
)
943 /* Compute high word of result, as a flonum. */
944 b
= (a
/ HIGH_WORD_COEFF
);
945 /* Convert that to fixed (but not to DWtype!),
946 and shift it into the high word. */
949 /* Remove high part from the DFtype, leaving the low part as flonum. */
951 /* Convert that to fixed (but not to DWtype!) and add it in.
952 Sometimes A comes out negative. This is significant, since
953 A has more bits than a long int does. */
967 return - __fixunsdfDI (-a
);
968 return __fixunsdfDI (a
);
973 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
974 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
977 __fixunssfDI (SFtype original_a
)
979 /* Convert the SFtype to a DFtype, because that is surely not going
980 to lose any bits. Some day someone else can write a faster version
981 that avoids converting to DFtype, and verify it really works right. */
982 DFtype a
= original_a
;
989 /* Compute high word of result, as a flonum. */
990 b
= (a
/ HIGH_WORD_COEFF
);
991 /* Convert that to fixed (but not to DWtype!),
992 and shift it into the high word. */
995 /* Remove high part from the DFtype, leaving the low part as flonum. */
997 /* Convert that to fixed (but not to DWtype!) and add it in.
998 Sometimes A comes out negative. This is significant, since
999 A has more bits than a long int does. */
1001 v
-= (UWtype
) (- a
);
1010 __fixsfdi (SFtype a
)
1013 return - __fixunssfDI (-a
);
1014 return __fixunssfDI (a
);
1018 #if defined(L_floatdixf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1019 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1020 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1021 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1024 __floatdixf (DWtype u
)
1028 d
= (Wtype
) (u
>> WORD_SIZE
);
1029 d
*= HIGH_HALFWORD_COEFF
;
1030 d
*= HIGH_HALFWORD_COEFF
;
1031 d
+= (UWtype
) (u
& (HIGH_WORD_COEFF
- 1));
1037 #if defined(L_floatditf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1038 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1039 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1040 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1043 __floatditf (DWtype u
)
1047 d
= (Wtype
) (u
>> WORD_SIZE
);
1048 d
*= HIGH_HALFWORD_COEFF
;
1049 d
*= HIGH_HALFWORD_COEFF
;
1050 d
+= (UWtype
) (u
& (HIGH_WORD_COEFF
- 1));
1057 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1058 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1059 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1062 __floatdidf (DWtype u
)
1066 d
= (Wtype
) (u
>> WORD_SIZE
);
1067 d
*= HIGH_HALFWORD_COEFF
;
1068 d
*= HIGH_HALFWORD_COEFF
;
1069 d
+= (UWtype
) (u
& (HIGH_WORD_COEFF
- 1));
1076 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1077 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1078 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1079 #define DI_SIZE (sizeof (DWtype) * BITS_PER_UNIT)
1081 /* Define codes for all the float formats that we know of. Note
1082 that this is copied from real.h. */
1084 #define UNKNOWN_FLOAT_FORMAT 0
1085 #define IEEE_FLOAT_FORMAT 1
1086 #define VAX_FLOAT_FORMAT 2
1087 #define IBM_FLOAT_FORMAT 3
1089 /* Default to IEEE float if not specified. Nearly all machines use it. */
1090 #ifndef HOST_FLOAT_FORMAT
1091 #define HOST_FLOAT_FORMAT IEEE_FLOAT_FORMAT
1094 #if HOST_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
1099 #if HOST_FLOAT_FORMAT == IBM_FLOAT_FORMAT
1104 #if HOST_FLOAT_FORMAT == VAX_FLOAT_FORMAT
1110 __floatdisf (DWtype u
)
1112 /* Do the calculation in DFmode
1113 so that we don't lose any of the precision of the high word
1114 while multiplying it. */
1117 /* Protect against double-rounding error.
1118 Represent any low-order bits, that might be truncated in DFmode,
1119 by a bit that won't be lost. The bit can go in anywhere below the
1120 rounding position of the SFmode. A fixed mask and bit position
1121 handles all usual configurations. It doesn't handle the case
1122 of 128-bit DImode, however. */
1123 if (DF_SIZE
< DI_SIZE
1124 && DF_SIZE
> (DI_SIZE
- DF_SIZE
+ SF_SIZE
))
1126 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - DF_SIZE))
1127 if (! (- ((DWtype
) 1 << DF_SIZE
) < u
1128 && u
< ((DWtype
) 1 << DF_SIZE
)))
1130 if ((UDWtype
) u
& (REP_BIT
- 1))
1134 f
= (Wtype
) (u
>> WORD_SIZE
);
1135 f
*= HIGH_HALFWORD_COEFF
;
1136 f
*= HIGH_HALFWORD_COEFF
;
1137 f
+= (UWtype
) (u
& (HIGH_WORD_COEFF
- 1));
1143 #if defined(L_fixunsxfsi) && LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96
1144 /* Reenable the normal types, in case limits.h needs them. */
1157 __fixunsxfSI (XFtype a
)
1159 if (a
>= - (DFtype
) Wtype_MIN
)
1160 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1166 /* Reenable the normal types, in case limits.h needs them. */
1179 __fixunsdfSI (DFtype a
)
1181 if (a
>= - (DFtype
) Wtype_MIN
)
1182 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1188 /* Reenable the normal types, in case limits.h needs them. */
1201 __fixunssfSI (SFtype a
)
1203 if (a
>= - (SFtype
) Wtype_MIN
)
1204 return (Wtype
) (a
+ Wtype_MIN
) - Wtype_MIN
;
1209 /* From here on down, the routines use normal data types. */
1211 #define SItype bogus_type
1212 #define USItype bogus_type
1213 #define DItype bogus_type
1214 #define UDItype bogus_type
1215 #define SFtype bogus_type
1216 #define DFtype bogus_type
1234 /* Like bcmp except the sign is meaningful.
1235 Result is negative if S1 is less than S2,
1236 positive if S1 is greater, 0 if S1 and S2 are equal. */
1239 __gcc_bcmp (const unsigned char *s1
, const unsigned char *s2
, size_t size
)
1243 unsigned char c1
= *s1
++, c2
= *s2
++;
1253 /* __eprintf used to be used by GCC's private version of <assert.h>.
1254 We no longer provide that header, but this routine remains in libgcc.a
1255 for binary backward compatibility. Note that it is not included in
1256 the shared version of libgcc. */
1258 #ifndef inhibit_libc
1260 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1264 __eprintf (const char *string
, const char *expression
,
1265 unsigned int line
, const char *filename
)
1267 fprintf (stderr
, string
, expression
, line
, filename
);
1277 #if LONG_TYPE_SIZE == GCOV_TYPE_SIZE
1278 typedef long gcov_type
;
1280 typedef long long gcov_type
;
1284 /* Structure emitted by -a */
1288 const char *filename
;
1292 const unsigned long *addresses
;
1294 /* Older GCC's did not emit these fields. */
1296 const char **functions
;
1297 const long *line_nums
;
1298 const char **filenames
;
1302 #ifdef BLOCK_PROFILER_CODE
1305 #ifndef inhibit_libc
1307 /* Simple minded basic block profiling output dumper for
1308 systems that don't provide tcov support. At present,
1309 it requires atexit and stdio. */
1311 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1314 #include "gbl-ctors.h"
1315 #include "gcov-io.h"
1317 #ifdef TARGET_HAS_F_SETLKW
1322 static struct bb
*bb_head
;
1325 __bb_exit_func (void)
1334 i
= strlen (bb_head
->filename
) - 3;
1337 for (ptr
= bb_head
; ptr
!= (struct bb
*) 0; ptr
= ptr
->next
)
1341 /* Make sure the output file exists -
1342 but don't clobber exiting data. */
1343 if ((da_file
= fopen (ptr
->filename
, "a")) != 0)
1346 /* Need to re-open in order to be able to write from the start. */
1347 da_file
= fopen (ptr
->filename
, "r+b");
1348 /* Some old systems might not allow the 'b' mode modifier.
1349 Therefore, try to open without it. This can lead to a race
1350 condition so that when you delete and re-create the file, the
1351 file might be opened in text mode, but then, you shouldn't
1352 delete the file in the first place. */
1354 da_file
= fopen (ptr
->filename
, "r+");
1357 fprintf (stderr
, "arc profiling: Can't open output file %s.\n",
1362 /* After a fork, another process might try to read and/or write
1363 the same file simultanously. So if we can, lock the file to
1364 avoid race conditions. */
1365 #if defined (TARGET_HAS_F_SETLKW)
1367 struct flock s_flock
;
1369 s_flock
.l_type
= F_WRLCK
;
1370 s_flock
.l_whence
= SEEK_SET
;
1371 s_flock
.l_start
= 0;
1373 s_flock
.l_pid
= getpid ();
1375 while (fcntl (fileno (da_file
), F_SETLKW
, &s_flock
)
1380 /* If the file is not empty, and the number of counts in it is the
1381 same, then merge them in. */
1382 firstchar
= fgetc (da_file
);
1383 if (firstchar
== EOF
)
1385 if (ferror (da_file
))
1387 fprintf (stderr
, "arc profiling: Can't read output file ");
1388 perror (ptr
->filename
);
1395 if (ungetc (firstchar
, da_file
) == EOF
)
1397 if (__read_long (&n_counts
, da_file
, 8) != 0)
1399 fprintf (stderr
, "arc profiling: Can't read output file %s.\n",
1404 if (n_counts
== ptr
->ncounts
)
1408 for (i
= 0; i
< n_counts
; i
++)
1412 if (__read_gcov_type (&v
, da_file
, 8) != 0)
1415 "arc profiling: Can't read output file %s.\n",
1419 ptr
->counts
[i
] += v
;
1427 /* ??? Should first write a header to the file. Preferably, a 4 byte
1428 magic number, 4 bytes containing the time the program was
1429 compiled, 4 bytes containing the last modification time of the
1430 source file, and 4 bytes indicating the compiler options used.
1432 That way we can easily verify that the proper source/executable/
1433 data file combination is being used from gcov. */
1435 if (__write_gcov_type (ptr
->ncounts
, da_file
, 8) != 0)
1438 fprintf (stderr
, "arc profiling: Error writing output file %s.\n",
1444 gcov_type
*count_ptr
= ptr
->counts
;
1446 for (j
= ptr
->ncounts
; j
> 0; j
--)
1448 if (__write_gcov_type (*count_ptr
, da_file
, 8) != 0)
1456 fprintf (stderr
, "arc profiling: Error writing output file %s.\n",
1460 if (fclose (da_file
) == EOF
)
1461 fprintf (stderr
, "arc profiling: Error closing output file %s.\n",
1469 __bb_init_func (struct bb
*blocks
)
1471 /* User is supposed to check whether the first word is non-0,
1472 but just in case.... */
1474 if (blocks
->zero_word
)
1477 /* Initialize destructor. */
1479 atexit (__bb_exit_func
);
1481 /* Set up linked list. */
1482 blocks
->zero_word
= 1;
1483 blocks
->next
= bb_head
;
1487 /* Called before fork or exec - write out profile information gathered so
1488 far and reset it to zero. This avoids duplication or loss of the
1489 profile information gathered so far. */
1491 __bb_fork_func (void)
1496 for (ptr
= bb_head
; ptr
!= (struct bb
*) 0; ptr
= ptr
->next
)
1499 for (i
= ptr
->ncounts
- 1; i
>= 0; i
--)
1504 #endif /* not inhibit_libc */
1505 #endif /* not BLOCK_PROFILER_CODE */
1508 #ifdef L_clear_cache
1509 /* Clear part of an instruction cache. */
1511 #define INSN_CACHE_PLANE_SIZE (INSN_CACHE_SIZE / INSN_CACHE_DEPTH)
1514 __clear_cache (char *beg
__attribute__((__unused__
)),
1515 char *end
__attribute__((__unused__
)))
1517 #ifdef CLEAR_INSN_CACHE
1518 CLEAR_INSN_CACHE (beg
, end
);
1520 #ifdef INSN_CACHE_SIZE
1521 static char array
[INSN_CACHE_SIZE
+ INSN_CACHE_PLANE_SIZE
+ INSN_CACHE_LINE_WIDTH
];
1522 static int initialized
;
1526 typedef (*function_ptr
) (void);
1528 #if (INSN_CACHE_SIZE / INSN_CACHE_LINE_WIDTH) < 16
1529 /* It's cheaper to clear the whole cache.
1530 Put in a series of jump instructions so that calling the beginning
1531 of the cache will clear the whole thing. */
1535 int ptr
= (((int) array
+ INSN_CACHE_LINE_WIDTH
- 1)
1536 & -INSN_CACHE_LINE_WIDTH
);
1537 int end_ptr
= ptr
+ INSN_CACHE_SIZE
;
1539 while (ptr
< end_ptr
)
1541 *(INSTRUCTION_TYPE
*)ptr
1542 = JUMP_AHEAD_INSTRUCTION
+ INSN_CACHE_LINE_WIDTH
;
1543 ptr
+= INSN_CACHE_LINE_WIDTH
;
1545 *(INSTRUCTION_TYPE
*) (ptr
- INSN_CACHE_LINE_WIDTH
) = RETURN_INSTRUCTION
;
1550 /* Call the beginning of the sequence. */
1551 (((function_ptr
) (((int) array
+ INSN_CACHE_LINE_WIDTH
- 1)
1552 & -INSN_CACHE_LINE_WIDTH
))
1555 #else /* Cache is large. */
1559 int ptr
= (((int) array
+ INSN_CACHE_LINE_WIDTH
- 1)
1560 & -INSN_CACHE_LINE_WIDTH
);
1562 while (ptr
< (int) array
+ sizeof array
)
1564 *(INSTRUCTION_TYPE
*)ptr
= RETURN_INSTRUCTION
;
1565 ptr
+= INSN_CACHE_LINE_WIDTH
;
1571 /* Find the location in array that occupies the same cache line as BEG. */
1573 offset
= ((int) beg
& -INSN_CACHE_LINE_WIDTH
) & (INSN_CACHE_PLANE_SIZE
- 1);
1574 start_addr
= (((int) (array
+ INSN_CACHE_PLANE_SIZE
- 1)
1575 & -INSN_CACHE_PLANE_SIZE
)
1578 /* Compute the cache alignment of the place to stop clearing. */
1579 #if 0 /* This is not needed for gcc's purposes. */
1580 /* If the block to clear is bigger than a cache plane,
1581 we clear the entire cache, and OFFSET is already correct. */
1582 if (end
< beg
+ INSN_CACHE_PLANE_SIZE
)
1584 offset
= (((int) (end
+ INSN_CACHE_LINE_WIDTH
- 1)
1585 & -INSN_CACHE_LINE_WIDTH
)
1586 & (INSN_CACHE_PLANE_SIZE
- 1));
1588 #if INSN_CACHE_DEPTH > 1
1589 end_addr
= (start_addr
& -INSN_CACHE_PLANE_SIZE
) + offset
;
1590 if (end_addr
<= start_addr
)
1591 end_addr
+= INSN_CACHE_PLANE_SIZE
;
1593 for (plane
= 0; plane
< INSN_CACHE_DEPTH
; plane
++)
1595 int addr
= start_addr
+ plane
* INSN_CACHE_PLANE_SIZE
;
1596 int stop
= end_addr
+ plane
* INSN_CACHE_PLANE_SIZE
;
1598 while (addr
!= stop
)
1600 /* Call the return instruction at ADDR. */
1601 ((function_ptr
) addr
) ();
1603 addr
+= INSN_CACHE_LINE_WIDTH
;
1606 #else /* just one plane */
1609 /* Call the return instruction at START_ADDR. */
1610 ((function_ptr
) start_addr
) ();
1612 start_addr
+= INSN_CACHE_LINE_WIDTH
;
1614 while ((start_addr
% INSN_CACHE_SIZE
) != offset
);
1615 #endif /* just one plane */
1616 #endif /* Cache is large */
1617 #endif /* Cache exists */
1618 #endif /* CLEAR_INSN_CACHE */
1621 #endif /* L_clear_cache */
1625 /* Jump to a trampoline, loading the static chain address. */
1627 #if defined(WINNT) && ! defined(__CYGWIN__) && ! defined (_UWIN)
1640 extern int VirtualProtect (char *, int, int, int *) __attribute__((stdcall));
1644 mprotect (char *addr
, int len
, int prot
)
1661 if (VirtualProtect (addr
, len
, np
, &op
))
1667 #endif /* WINNT && ! __CYGWIN__ && ! _UWIN */
1669 #ifdef TRANSFER_FROM_TRAMPOLINE
1670 TRANSFER_FROM_TRAMPOLINE
1673 #if defined (NeXT) && defined (__MACH__)
1675 /* Make stack executable so we can call trampolines on stack.
1676 This is called from INITIALIZE_TRAMPOLINE in next.h. */
1680 #include <mach/mach.h>
1684 __enable_execute_stack (char *addr
)
1687 char *eaddr
= addr
+ TRAMPOLINE_SIZE
;
1688 vm_address_t a
= (vm_address_t
) addr
;
1690 /* turn on execute access on stack */
1691 r
= vm_protect (task_self (), a
, TRAMPOLINE_SIZE
, FALSE
, VM_PROT_ALL
);
1692 if (r
!= KERN_SUCCESS
)
1694 mach_error("vm_protect VM_PROT_ALL", r
);
1698 /* We inline the i-cache invalidation for speed */
1700 #ifdef CLEAR_INSN_CACHE
1701 CLEAR_INSN_CACHE (addr
, eaddr
);
1703 __clear_cache ((int) addr
, (int) eaddr
);
1707 #endif /* defined (NeXT) && defined (__MACH__) */
1711 /* Make stack executable so we can call trampolines on stack.
1712 This is called from INITIALIZE_TRAMPOLINE in convex.h. */
1714 #include <sys/mman.h>
1715 #include <sys/vmparam.h>
1716 #include <machine/machparam.h>
1719 __enable_execute_stack (void)
1722 static unsigned lowest
= USRSTACK
;
1723 unsigned current
= (unsigned) &fp
& -NBPG
;
1725 if (lowest
> current
)
1727 unsigned len
= lowest
- current
;
1728 mremap (current
, &len
, PROT_READ
| PROT_WRITE
| PROT_EXEC
, MAP_PRIVATE
);
1732 /* Clear instruction cache in case an old trampoline is in it. */
1735 #endif /* __convex__ */
1739 /* Modified from the convex -code above. */
1741 #include <sys/param.h>
1743 #include <sys/m88kbcs.h>
1746 __enable_execute_stack (void)
1749 static unsigned long lowest
= USRSTACK
;
1750 unsigned long current
= (unsigned long) &save_errno
& -NBPC
;
1752 /* Ignore errno being set. memctl sets errno to EINVAL whenever the
1753 address is seen as 'negative'. That is the case with the stack. */
1756 if (lowest
> current
)
1758 unsigned len
=lowest
-current
;
1759 memctl(current
,len
,MCT_TEXT
);
1763 memctl(current
,NBPC
,MCT_TEXT
);
1767 #endif /* __sysV88__ */
1771 #include <sys/signal.h>
1774 /* Motorola forgot to put memctl.o in the libp version of libc881.a,
1775 so define it here, because we need it in __clear_insn_cache below */
1776 /* On older versions of this OS, no memctl or MCT_TEXT are defined;
1777 hence we enable this stuff only if MCT_TEXT is #define'd. */
1792 /* Clear instruction cache so we can call trampolines on stack.
1793 This is called from FINALIZE_TRAMPOLINE in mot3300.h. */
1796 __clear_insn_cache (void)
1801 /* Preserve errno, because users would be surprised to have
1802 errno changing without explicitly calling any system-call. */
1805 /* Keep it simple : memctl (MCT_TEXT) always fully clears the insn cache.
1806 No need to use an address derived from _start or %sp, as 0 works also. */
1807 memctl(0, 4096, MCT_TEXT
);
1812 #endif /* __sysV68__ */
1816 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1818 #include <sys/mman.h>
1819 #include <sys/types.h>
1820 #include <sys/param.h>
1821 #include <sys/vmmac.h>
1823 /* Modified from the convex -code above.
1824 mremap promises to clear the i-cache. */
1827 __enable_execute_stack (void)
1830 if (mprotect (((unsigned int)&fp
/PAGSIZ
)*PAGSIZ
, PAGSIZ
,
1831 PROT_READ
|PROT_WRITE
|PROT_EXEC
))
1833 perror ("mprotect in __enable_execute_stack");
1838 #endif /* __pyr__ */
1840 #if defined (sony_news) && defined (SYSTYPE_BSD)
1843 #include <sys/types.h>
1844 #include <sys/param.h>
1845 #include <syscall.h>
1846 #include <machine/sysnews.h>
1848 /* cacheflush function for NEWS-OS 4.2.
1849 This function is called from trampoline-initialize code
1850 defined in config/mips/mips.h. */
1853 cacheflush (char *beg
, int size
, int flag
)
1855 if (syscall (SYS_sysnews
, NEWS_CACHEFLUSH
, beg
, size
, FLUSH_BCACHE
))
1857 perror ("cache_flush");
1863 #endif /* sony_news */
1864 #endif /* L_trampoline */
1869 #include "gbl-ctors.h"
1870 /* Some systems use __main in a way incompatible with its use in gcc, in these
1871 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
1872 give the same symbol without quotes for an alternative entry point. You
1873 must define both, or neither. */
1875 #define NAME__MAIN "__main"
1876 #define SYMBOL__MAIN __main
1879 #ifdef INIT_SECTION_ASM_OP
1880 #undef HAS_INIT_SECTION
1881 #define HAS_INIT_SECTION
1884 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
1886 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
1887 code to run constructors. In that case, we need to handle EH here, too. */
1889 #ifdef EH_FRAME_SECTION_NAME
1890 #include "unwind-dw2-fde.h"
1891 extern unsigned char __EH_FRAME_BEGIN__
[];
1894 /* Run all the global destructors on exit from the program. */
1897 __do_global_dtors (void)
1899 #ifdef DO_GLOBAL_DTORS_BODY
1900 DO_GLOBAL_DTORS_BODY
;
1902 static func_ptr
*p
= __DTOR_LIST__
+ 1;
1909 #if defined (EH_FRAME_SECTION_NAME) && !defined (HAS_INIT_SECTION)
1911 static int completed
= 0;
1915 __deregister_frame_info (__EH_FRAME_BEGIN__
);
1922 #ifndef HAS_INIT_SECTION
1923 /* Run all the global constructors on entry to the program. */
1926 __do_global_ctors (void)
1928 #ifdef EH_FRAME_SECTION_NAME
1930 static struct object object
;
1931 __register_frame_info (__EH_FRAME_BEGIN__
, &object
);
1934 DO_GLOBAL_CTORS_BODY
;
1935 atexit (__do_global_dtors
);
1937 #endif /* no HAS_INIT_SECTION */
1939 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
1940 /* Subroutine called automatically by `main'.
1941 Compiling a global function named `main'
1942 produces an automatic call to this function at the beginning.
1944 For many systems, this routine calls __do_global_ctors.
1945 For systems which support a .init section we use the .init section
1946 to run __do_global_ctors, so we need not do anything here. */
1951 /* Support recursive calls to `main': run initializers just once. */
1952 static int initialized
;
1956 __do_global_ctors ();
1959 #endif /* no HAS_INIT_SECTION or INVOKE__main */
1961 #endif /* L__main */
1962 #endif /* __CYGWIN__ */
1966 #include "gbl-ctors.h"
1968 /* Provide default definitions for the lists of constructors and
1969 destructors, so that we don't get linker errors. These symbols are
1970 intentionally bss symbols, so that gld and/or collect will provide
1971 the right values. */
1973 /* We declare the lists here with two elements each,
1974 so that they are valid empty lists if no other definition is loaded.
1976 If we are using the old "set" extensions to have the gnu linker
1977 collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
1978 must be in the bss/common section.
1980 Long term no port should use those extensions. But many still do. */
1981 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
1982 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
1983 func_ptr __CTOR_LIST__
[2] = {0, 0};
1984 func_ptr __DTOR_LIST__
[2] = {0, 0};
1986 func_ptr __CTOR_LIST__
[2];
1987 func_ptr __DTOR_LIST__
[2];
1989 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
1990 #endif /* L_ctors */
1994 #include "gbl-ctors.h"
2002 static func_ptr
*atexit_chain
= 0;
2003 static long atexit_chain_length
= 0;
2004 static volatile long last_atexit_chain_slot
= -1;
2007 atexit (func_ptr func
)
2009 if (++last_atexit_chain_slot
== atexit_chain_length
)
2011 atexit_chain_length
+= 32;
2013 atexit_chain
= (func_ptr
*) realloc (atexit_chain
, atexit_chain_length
2014 * sizeof (func_ptr
));
2016 atexit_chain
= (func_ptr
*) malloc (atexit_chain_length
2017 * sizeof (func_ptr
));
2020 atexit_chain_length
= 0;
2021 last_atexit_chain_slot
= -1;
2026 atexit_chain
[last_atexit_chain_slot
] = func
;
2030 extern void _cleanup (void);
2031 extern void _exit (int) __attribute__ ((__noreturn__
));
2038 for ( ; last_atexit_chain_slot
-- >= 0; )
2040 (*atexit_chain
[last_atexit_chain_slot
+ 1]) ();
2041 atexit_chain
[last_atexit_chain_slot
+ 1] = 0;
2043 free (atexit_chain
);
2056 /* Simple; we just need a wrapper for ON_EXIT. */
2058 atexit (func_ptr func
)
2060 return ON_EXIT (func
);
2063 #endif /* ON_EXIT */
2064 #endif /* NEED_ATEXIT */