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
39 /* Don't use `fancy_abort' here even if config.h says to use it. */
46 #if defined (L_negdi2)
56 w.s.high = -uu.s.high - ((UWtype) w.s.low > 0);
64 __addvsi3 (Wtype a, Wtype b)
70 if (b >= 0 ? w < a : w > a)
79 __addvdi3 (DWtype a, DWtype b)
85 if (b >= 0 ? w < a : w > a)
94 __subvsi3 (Wtype a, Wtype b)
97 return __addvsi3 (a, (-b));
103 if (b >= 0 ? w > a : w < a)
113 __subvdi3 (DWtype a, DWtype b)
122 if (b >= 0 ? w > a : w < a)
132 __mulvsi3 (Wtype a, Wtype b)
138 if (((a >= 0) == (b >= 0)) ? w < 0 : w > 0)
153 if (a >= 0 ? w > 0 : w < 0)
168 if (a >= 0 ? w > 0 : w < 0)
217 __mulvdi3 (DWtype u, DWtype v)
223 if (((u >= 0) == (v >= 0)) ? w < 0 : w > 0)
231 /* Unless shift functions are defined whith full ANSI prototypes,
232 parameter b will be promoted to int if word_type is smaller than an int. */
235 __lshrdi3 (DWtype u, word_type b)
246 bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
250 w.s.low = (UWtype) uu.s.high >> -bm;
254 UWtype carries = (UWtype) uu.s.high << bm;
256 w.s.high = (UWtype) uu.s.high >> b;
257 w.s.low = ((UWtype) uu.s.low >> b) | carries;
266 __ashldi3 (DWtype u, word_type b)
277 bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
281 w.s.high = (UWtype) uu.s.low << -bm;
285 UWtype carries = (UWtype) uu.s.low >> bm;
287 w.s.low = (UWtype) uu.s.low << b;
288 w.s.high = ((UWtype) uu.s.high << b) | carries;
297 __ashrdi3 (DWtype u, word_type b)
308 bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
311 /* w.s.high = 1..1 or 0..0 */
312 w.s.high = uu.s.high >> (sizeof (Wtype) * BITS_PER_UNIT - 1);
313 w.s.low = uu.s.high >> -bm;
317 UWtype carries = (UWtype) uu.s.high << bm;
319 w.s.high = uu.s.high >> b;
320 w.s.low = ((UWtype) uu.s.low >> b) | carries;
332 UWtype word, count, add;
336 word = uu.s.low, add = 0;
337 else if (uu.s.high != 0)
338 word = uu.s.high, add = BITS_PER_UNIT * sizeof (Wtype);
342 count_trailing_zeros (count, word);
343 return count + add + 1;
349 __muldi3 (DWtype u, DWtype v)
357 w.ll = __umulsidi3 (uu.s.low, vv.s.low);
358 w.s.high += ((UWtype) uu.s.low * (UWtype) vv.s.high
359 + (UWtype) uu.s.high * (UWtype) vv.s.low);
366 #if defined (sdiv_qrnnd)
368 __udiv_w_sdiv (UWtype *rp, UWtype a1, UWtype a0, UWtype d)
375 if (a1 < d - a1 - (a0 >> (W_TYPE_SIZE - 1)))
377 /* dividend, divisor, and quotient are nonnegative */
378 sdiv_qrnnd (q, r, a1, a0, d);
382 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */
383 sub_ddmmss (c1, c0, a1, a0, d >> 1, d << (W_TYPE_SIZE - 1));
384 /* Divide (c1*2^32 + c0) by d */
385 sdiv_qrnnd (q, r, c1, c0, d);
386 /* Add 2^31 to quotient */
387 q += (UWtype) 1 << (W_TYPE_SIZE - 1);
392 b1 = d >> 1; /* d/2, between 2^30 and 2^31 - 1 */
393 c1 = a1 >> 1; /* A/2 */
394 c0 = (a1 << (W_TYPE_SIZE - 1)) + (a0 >> 1);
396 if (a1 < b1) /* A < 2^32*b1, so A/2 < 2^31*b1 */
398 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
400 r = 2*r + (a0 & 1); /* Remainder from A/(2*b1) */
417 else if (c1 < b1) /* So 2^31 <= (A/2)/b1 < 2^32 */
420 c0 = ~c0; /* logical NOT */
422 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
424 q = ~q; /* (A/2)/b1 */
427 r = 2*r + (a0 & 1); /* A/(2*b1) */
445 else /* Implies c1 = b1 */
446 { /* Hence a1 = d - 1 = 2*b1 - 1 */
464 /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */
466 __udiv_w_sdiv (UWtype *rp __attribute__ ((__unused__)),
467 UWtype a1 __attribute__ ((__unused__)),
468 UWtype a0 __attribute__ ((__unused__)),
469 UWtype d __attribute__ ((__unused__)))
476 #if (defined (L_udivdi3) || defined (L_divdi3) || \
477 defined (L_umoddi3) || defined (L_moddi3))
482 const UQItype __clz_tab[] =
484 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,
485 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,
486 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,
487 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,
488 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,
489 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,
490 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,
491 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,
497 #if (defined (L_udivdi3) || defined (L_divdi3) || \
498 defined (L_umoddi3) || defined (L_moddi3))
502 __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
507 UWtype d0, d1, n0, n1, n2;
519 #if !UDIV_NEEDS_NORMALIZATION
526 udiv_qrnnd (q0, n0, n1, n0, d0);
529 /* Remainder in n0. */
536 d0 = 1 / d0; /* Divide intentionally by zero. */
538 udiv_qrnnd (q1, n1, 0, n1, d0);
539 udiv_qrnnd (q0, n0, n1, n0, d0);
541 /* Remainder in n0. */
552 #else /* UDIV_NEEDS_NORMALIZATION */
560 count_leading_zeros (bm, d0);
564 /* Normalize, i.e. make the most significant bit of the
568 n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm));
572 udiv_qrnnd (q0, n0, n1, n0, d0);
575 /* Remainder in n0 >> bm. */
582 d0 = 1 / d0; /* Divide intentionally by zero. */
584 count_leading_zeros (bm, d0);
588 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
589 conclude (the most significant bit of n1 is set) /\ (the
590 leading quotient digit q1 = 1).
592 This special case is necessary, not an optimization.
593 (Shifts counts of W_TYPE_SIZE are undefined.) */
602 b = W_TYPE_SIZE - bm;
606 n1 = (n1 << bm) | (n0 >> b);
609 udiv_qrnnd (q1, n1, n2, n1, d0);
614 udiv_qrnnd (q0, n0, n1, n0, d0);
616 /* Remainder in n0 >> bm. */
626 #endif /* UDIV_NEEDS_NORMALIZATION */
637 /* Remainder in n1n0. */
649 count_leading_zeros (bm, d1);
652 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
653 conclude (the most significant bit of n1 is set) /\ (the
654 quotient digit q0 = 0 or 1).
656 This special case is necessary, not an optimization. */
658 /* The condition on the next line takes advantage of that
659 n1 >= d1 (true due to program flow). */
660 if (n1 > d1 || n0 >= d0)
663 sub_ddmmss (n1, n0, n1, n0, d1, d0);
682 b = W_TYPE_SIZE - bm;
684 d1 = (d1 << bm) | (d0 >> b);
687 n1 = (n1 << bm) | (n0 >> b);
690 udiv_qrnnd (q0, n1, n2, n1, d1);
691 umul_ppmm (m1, m0, q0, d0);
693 if (m1 > n1 || (m1 == n1 && m0 > n0))
696 sub_ddmmss (m1, m0, m1, m0, d1, d0);
701 /* Remainder in (n1n0 - m1m0) >> bm. */
704 sub_ddmmss (n1, n0, n1, n0, m1, m0);
705 rr.s.low = (n1 << b) | (n0 >> bm);
706 rr.s.high = n1 >> bm;
721 __divdi3 (DWtype u, DWtype v)
737 w = __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) 0);
747 __moddi3 (DWtype u, DWtype v)
762 (void) __udivmoddi4 (uu.ll, vv.ll, &w);
772 __umoddi3 (UDWtype u, UDWtype v)
776 (void) __udivmoddi4 (u, v, &w);
784 __udivdi3 (UDWtype n, UDWtype d)
786 return __udivmoddi4 (n, d, (UDWtype *) 0);
792 __cmpdi2 (DWtype a, DWtype b)
796 au.ll = a, bu.ll = b;
798 if (au.s.high < bu.s.high)
800 else if (au.s.high > bu.s.high)
802 if ((UWtype) au.s.low < (UWtype) bu.s.low)
804 else if ((UWtype) au.s.low > (UWtype) bu.s.low)
812 __ucmpdi2 (DWtype a, DWtype b)
816 au.ll = a, bu.ll = b;
818 if ((UWtype) au.s.high < (UWtype) bu.s.high)
820 else if ((UWtype) au.s.high > (UWtype) bu.s.high)
822 if ((UWtype) au.s.low < (UWtype) bu.s.low)
824 else if ((UWtype) au.s.low > (UWtype) bu.s.low)
830 #if defined(L_fixunstfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
831 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
832 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
835 __fixunstfDI (TFtype a)
843 /* Compute high word of result, as a flonum. */
844 b = (a / HIGH_WORD_COEFF);
845 /* Convert that to fixed (but not to DWtype!),
846 and shift it into the high word. */
849 /* Remove high part from the TFtype, leaving the low part as flonum. */
851 /* Convert that to fixed (but not to DWtype!) and add it in.
852 Sometimes A comes out negative. This is significant, since
853 A has more bits than a long int does. */
862 #if defined(L_fixtfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
867 return - __fixunstfDI (-a);
868 return __fixunstfDI (a);
872 #if defined(L_fixunsxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
873 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
874 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
877 __fixunsxfDI (XFtype a)
885 /* Compute high word of result, as a flonum. */
886 b = (a / HIGH_WORD_COEFF);
887 /* Convert that to fixed (but not to DWtype!),
888 and shift it into the high word. */
891 /* Remove high part from the XFtype, leaving the low part as flonum. */
893 /* Convert that to fixed (but not to DWtype!) and add it in.
894 Sometimes A comes out negative. This is significant, since
895 A has more bits than a long int does. */
904 #if defined(L_fixxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
909 return - __fixunsxfDI (-a);
910 return __fixunsxfDI (a);
915 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
916 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
919 __fixunsdfDI (DFtype a)
927 /* Compute high word of result, as a flonum. */
928 b = (a / HIGH_WORD_COEFF);
929 /* Convert that to fixed (but not to DWtype!),
930 and shift it into the high word. */
933 /* Remove high part from the DFtype, leaving the low part as flonum. */
935 /* Convert that to fixed (but not to DWtype!) and add it in.
936 Sometimes A comes out negative. This is significant, since
937 A has more bits than a long int does. */
951 return - __fixunsdfDI (-a);
952 return __fixunsdfDI (a);
957 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
958 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
961 __fixunssfDI (SFtype original_a)
963 /* Convert the SFtype to a DFtype, because that is surely not going
964 to lose any bits. Some day someone else can write a faster version
965 that avoids converting to DFtype, and verify it really works right. */
966 DFtype a = original_a;
973 /* Compute high word of result, as a flonum. */
974 b = (a / HIGH_WORD_COEFF);
975 /* Convert that to fixed (but not to DWtype!),
976 and shift it into the high word. */
979 /* Remove high part from the DFtype, leaving the low part as flonum. */
981 /* Convert that to fixed (but not to DWtype!) and add it in.
982 Sometimes A comes out negative. This is significant, since
983 A has more bits than a long int does. */
997 return - __fixunssfDI (-a);
998 return __fixunssfDI (a);
1002 #if defined(L_floatdixf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1003 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1004 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1005 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1008 __floatdixf (DWtype u)
1012 d = (Wtype) (u >> WORD_SIZE);
1013 d *= HIGH_HALFWORD_COEFF;
1014 d *= HIGH_HALFWORD_COEFF;
1015 d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1021 #if defined(L_floatditf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1022 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1023 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1024 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1027 __floatditf (DWtype u)
1031 d = (Wtype) (u >> WORD_SIZE);
1032 d *= HIGH_HALFWORD_COEFF;
1033 d *= HIGH_HALFWORD_COEFF;
1034 d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1041 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1042 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1043 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1046 __floatdidf (DWtype u)
1050 d = (Wtype) (u >> WORD_SIZE);
1051 d *= HIGH_HALFWORD_COEFF;
1052 d *= HIGH_HALFWORD_COEFF;
1053 d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1060 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1061 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1062 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1064 #define DI_SIZE (sizeof (DWtype) * BITS_PER_UNIT)
1065 #define DF_SIZE DBL_MANT_DIG
1066 #define SF_SIZE FLT_MANT_DIG
1069 __floatdisf (DWtype u)
1071 /* Do the calculation in DFmode
1072 so that we don't lose any of the precision of the high word
1073 while multiplying it. */
1076 /* Protect against double-rounding error.
1077 Represent any low-order bits, that might be truncated in DFmode,
1078 by a bit that won't be lost. The bit can go in anywhere below the
1079 rounding position of the SFmode. A fixed mask and bit position
1080 handles all usual configurations. It doesn't handle the case
1081 of 128-bit DImode, however. */
1082 if (DF_SIZE < DI_SIZE
1083 && DF_SIZE > (DI_SIZE - DF_SIZE + SF_SIZE))
1085 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - DF_SIZE))
1086 if (! (- ((DWtype) 1 << DF_SIZE) < u
1087 && u < ((DWtype) 1 << DF_SIZE)))
1089 if ((UDWtype) u & (REP_BIT - 1))
1093 f = (Wtype) (u >> WORD_SIZE);
1094 f *= HIGH_HALFWORD_COEFF;
1095 f *= HIGH_HALFWORD_COEFF;
1096 f += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1102 #if defined(L_fixunsxfsi) && LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96
1103 /* Reenable the normal types, in case limits.h needs them. */
1116 __fixunsxfSI (XFtype a)
1118 if (a >= - (DFtype) Wtype_MIN)
1119 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1125 /* Reenable the normal types, in case limits.h needs them. */
1138 __fixunsdfSI (DFtype a)
1140 if (a >= - (DFtype) Wtype_MIN)
1141 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1147 /* Reenable the normal types, in case limits.h needs them. */
1160 __fixunssfSI (SFtype a)
1162 if (a >= - (SFtype) Wtype_MIN)
1163 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1168 /* From here on down, the routines use normal data types. */
1170 #define SItype bogus_type
1171 #define USItype bogus_type
1172 #define DItype bogus_type
1173 #define UDItype bogus_type
1174 #define SFtype bogus_type
1175 #define DFtype bogus_type
1193 /* Like bcmp except the sign is meaningful.
1194 Result is negative if S1 is less than S2,
1195 positive if S1 is greater, 0 if S1 and S2 are equal. */
1198 __gcc_bcmp (const unsigned char *s1, const unsigned char *s2, size_t size)
1202 unsigned char c1 = *s1++, c2 = *s2++;
1212 /* __eprintf used to be used by GCC's private version of <assert.h>.
1213 We no longer provide that header, but this routine remains in libgcc.a
1214 for binary backward compatibility. Note that it is not included in
1215 the shared version of libgcc. */
1217 #ifndef inhibit_libc
1219 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1223 __eprintf (const char *string, const char *expression,
1224 unsigned int line, const char *filename)
1226 fprintf (stderr, string, expression, line, filename);
1236 struct bb_function_info {
1242 /* Structure emitted by -a */
1246 const char *filename;
1251 /* Older GCC's did not emit these fields. */
1253 struct bb_function_info *function_infos;
1256 #ifndef inhibit_libc
1258 /* Simple minded basic block profiling output dumper for
1259 systems that don't provide tcov support. At present,
1260 it requires atexit and stdio. */
1262 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1265 #include "gbl-ctors.h"
1266 #include "gcov-io.h"
1268 #ifdef TARGET_HAS_F_SETLKW
1275 static struct bb *bb_head;
1277 int __global_counters = 0, __gthreads_active = 0;
1280 __bb_exit_func (void)
1284 long n_counters_p = 0;
1285 gcov_type max_counter_p = 0;
1286 gcov_type sum_counters_p = 0;
1291 /* Calculate overall "statistics". */
1293 for (ptr = bb_head; ptr != (struct bb *) 0; ptr = ptr->next)
1297 n_counters_p += ptr->ncounts;
1299 for (i = 0; i < ptr->ncounts; i++)
1301 sum_counters_p += ptr->counts[i];
1303 if (ptr->counts[i] > max_counter_p)
1304 max_counter_p = ptr->counts[i];
1308 for (ptr = bb_head; ptr != (struct bb *) 0; ptr = ptr->next)
1310 gcov_type max_counter_o = 0;
1311 gcov_type sum_counters_o = 0;
1314 /* Calculate the per-object statistics. */
1316 for (i = 0; i < ptr->ncounts; i++)
1318 sum_counters_o += ptr->counts[i];
1320 if (ptr->counts[i] > max_counter_o)
1321 max_counter_o = ptr->counts[i];
1324 /* open the file for appending, creating it if necessary. */
1325 da_file = fopen (ptr->filename, "ab");
1326 /* Some old systems might not allow the 'b' mode modifier.
1327 Therefore, try to open without it. This can lead to a race
1328 condition so that when you delete and re-create the file, the
1329 file might be opened in text mode, but then, you shouldn't
1330 delete the file in the first place. */
1332 da_file = fopen (ptr->filename, "a");
1335 fprintf (stderr, "arc profiling: Can't open output file %s.\n",
1340 /* After a fork, another process might try to read and/or write
1341 the same file simultanously. So if we can, lock the file to
1342 avoid race conditions. */
1343 #if defined (TARGET_HAS_F_SETLKW)
1345 struct flock s_flock;
1347 s_flock.l_type = F_WRLCK;
1348 s_flock.l_whence = SEEK_SET;
1349 s_flock.l_start = 0;
1351 s_flock.l_pid = getpid ();
1353 while (fcntl (fileno (da_file), F_SETLKW, &s_flock)
1358 if (__write_long (-123, da_file, 4) != 0) /* magic */
1360 fprintf (stderr, "arc profiling: Error writing output file %s.\n",
1366 struct bb_function_info *fn_info;
1367 gcov_type *count_ptr = ptr->counts;
1369 int count_functions = 0;
1371 for (fn_info = ptr->function_infos; fn_info->arc_count != -1;
1375 /* number of functions in this block. */
1376 __write_long (count_functions, da_file, 4);
1378 /* length of extra data in bytes. */
1379 __write_long ((4 + 8 + 8) + (4 + 8 + 8), da_file, 4);
1381 /* overall statistics. */
1382 /* number of counters. */
1383 __write_long (n_counters_p, da_file, 4);
1384 /* sum of counters. */
1385 __write_gcov_type (sum_counters_p, da_file, 8);
1386 /* maximal counter. */
1387 __write_gcov_type (max_counter_p, da_file, 8);
1389 /* per-object statistics. */
1390 /* number of counters. */
1391 __write_long (ptr->ncounts, da_file, 4);
1392 /* sum of counters. */
1393 __write_gcov_type (sum_counters_o, da_file, 8);
1394 /* maximal counter. */
1395 __write_gcov_type (max_counter_o, da_file, 8);
1397 /* write execution counts for each function. */
1399 for (fn_info = ptr->function_infos; fn_info->arc_count != -1;
1403 if (__write_gcov_string
1404 (fn_info->name, strlen (fn_info->name), da_file, -1) != 0)
1407 "arc profiling: Error writing output file %s.\n",
1412 if (__write_long (fn_info->checksum, da_file, 4) != 0)
1415 "arc profiling: Error writing output file %s.\n",
1420 if (__write_long (fn_info->arc_count, da_file, 4) != 0)
1423 "arc profiling: Error writing output file %s.\n",
1428 for (i = fn_info->arc_count; i > 0; i--, count_ptr++)
1430 if (__write_gcov_type (*count_ptr, da_file, 8) != 0)
1434 if (i) /* there was an error */
1437 "arc profiling: Error writing output file %s.\n",
1444 if (fclose (da_file) != 0)
1445 fprintf (stderr, "arc profiling: Error closing output file %s.\n",
1451 __bb_init_func (struct bb *blocks)
1453 /* User is supposed to check whether the first word is non-0,
1454 but just in case.... */
1456 if (blocks->zero_word)
1459 /* Initialize destructor and per-thread data. */
1461 atexit (__bb_exit_func);
1463 /* Set up linked list. */
1464 blocks->zero_word = 1;
1465 blocks->next = bb_head;
1469 /* Called before fork or exec - write out profile information gathered so
1470 far and reset it to zero. This avoids duplication or loss of the
1471 profile information gathered so far. */
1473 __bb_fork_func (void)
1478 for (ptr = bb_head; ptr != (struct bb *) 0; ptr = ptr->next)
1481 for (i = ptr->ncounts - 1; i >= 0; i--)
1486 #endif /* not inhibit_libc */
1489 #ifdef L_clear_cache
1490 /* Clear part of an instruction cache. */
1492 #define INSN_CACHE_PLANE_SIZE (INSN_CACHE_SIZE / INSN_CACHE_DEPTH)
1495 __clear_cache (char *beg __attribute__((__unused__)),
1496 char *end __attribute__((__unused__)))
1498 #ifdef CLEAR_INSN_CACHE
1499 CLEAR_INSN_CACHE (beg, end);
1501 #ifdef INSN_CACHE_SIZE
1502 static char array[INSN_CACHE_SIZE + INSN_CACHE_PLANE_SIZE + INSN_CACHE_LINE_WIDTH];
1503 static int initialized;
1507 typedef (*function_ptr) (void);
1509 #if (INSN_CACHE_SIZE / INSN_CACHE_LINE_WIDTH) < 16
1510 /* It's cheaper to clear the whole cache.
1511 Put in a series of jump instructions so that calling the beginning
1512 of the cache will clear the whole thing. */
1516 int ptr = (((int) array + INSN_CACHE_LINE_WIDTH - 1)
1517 & -INSN_CACHE_LINE_WIDTH);
1518 int end_ptr = ptr + INSN_CACHE_SIZE;
1520 while (ptr < end_ptr)
1522 *(INSTRUCTION_TYPE *)ptr
1523 = JUMP_AHEAD_INSTRUCTION + INSN_CACHE_LINE_WIDTH;
1524 ptr += INSN_CACHE_LINE_WIDTH;
1526 *(INSTRUCTION_TYPE *) (ptr - INSN_CACHE_LINE_WIDTH) = RETURN_INSTRUCTION;
1531 /* Call the beginning of the sequence. */
1532 (((function_ptr) (((int) array + INSN_CACHE_LINE_WIDTH - 1)
1533 & -INSN_CACHE_LINE_WIDTH))
1536 #else /* Cache is large. */
1540 int ptr = (((int) array + INSN_CACHE_LINE_WIDTH - 1)
1541 & -INSN_CACHE_LINE_WIDTH);
1543 while (ptr < (int) array + sizeof array)
1545 *(INSTRUCTION_TYPE *)ptr = RETURN_INSTRUCTION;
1546 ptr += INSN_CACHE_LINE_WIDTH;
1552 /* Find the location in array that occupies the same cache line as BEG. */
1554 offset = ((int) beg & -INSN_CACHE_LINE_WIDTH) & (INSN_CACHE_PLANE_SIZE - 1);
1555 start_addr = (((int) (array + INSN_CACHE_PLANE_SIZE - 1)
1556 & -INSN_CACHE_PLANE_SIZE)
1559 /* Compute the cache alignment of the place to stop clearing. */
1560 #if 0 /* This is not needed for gcc's purposes. */
1561 /* If the block to clear is bigger than a cache plane,
1562 we clear the entire cache, and OFFSET is already correct. */
1563 if (end < beg + INSN_CACHE_PLANE_SIZE)
1565 offset = (((int) (end + INSN_CACHE_LINE_WIDTH - 1)
1566 & -INSN_CACHE_LINE_WIDTH)
1567 & (INSN_CACHE_PLANE_SIZE - 1));
1569 #if INSN_CACHE_DEPTH > 1
1570 end_addr = (start_addr & -INSN_CACHE_PLANE_SIZE) + offset;
1571 if (end_addr <= start_addr)
1572 end_addr += INSN_CACHE_PLANE_SIZE;
1574 for (plane = 0; plane < INSN_CACHE_DEPTH; plane++)
1576 int addr = start_addr + plane * INSN_CACHE_PLANE_SIZE;
1577 int stop = end_addr + plane * INSN_CACHE_PLANE_SIZE;
1579 while (addr != stop)
1581 /* Call the return instruction at ADDR. */
1582 ((function_ptr) addr) ();
1584 addr += INSN_CACHE_LINE_WIDTH;
1587 #else /* just one plane */
1590 /* Call the return instruction at START_ADDR. */
1591 ((function_ptr) start_addr) ();
1593 start_addr += INSN_CACHE_LINE_WIDTH;
1595 while ((start_addr % INSN_CACHE_SIZE) != offset);
1596 #endif /* just one plane */
1597 #endif /* Cache is large */
1598 #endif /* Cache exists */
1599 #endif /* CLEAR_INSN_CACHE */
1602 #endif /* L_clear_cache */
1606 /* Jump to a trampoline, loading the static chain address. */
1608 #if defined(WINNT) && ! defined(__CYGWIN__) && ! defined (_UWIN)
1621 extern int VirtualProtect (char *, int, int, int *) __attribute__((stdcall));
1625 mprotect (char *addr, int len, int prot)
1642 if (VirtualProtect (addr, len, np, &op))
1648 #endif /* WINNT && ! __CYGWIN__ && ! _UWIN */
1650 #ifdef TRANSFER_FROM_TRAMPOLINE
1651 TRANSFER_FROM_TRAMPOLINE
1654 #if defined (NeXT) && defined (__MACH__)
1656 /* Make stack executable so we can call trampolines on stack.
1657 This is called from INITIALIZE_TRAMPOLINE in next.h. */
1661 #include <mach/mach.h>
1665 __enable_execute_stack (char *addr)
1668 char *eaddr = addr + TRAMPOLINE_SIZE;
1669 vm_address_t a = (vm_address_t) addr;
1671 /* turn on execute access on stack */
1672 r = vm_protect (task_self (), a, TRAMPOLINE_SIZE, FALSE, VM_PROT_ALL);
1673 if (r != KERN_SUCCESS)
1675 mach_error("vm_protect VM_PROT_ALL", r);
1679 /* We inline the i-cache invalidation for speed */
1681 #ifdef CLEAR_INSN_CACHE
1682 CLEAR_INSN_CACHE (addr, eaddr);
1684 __clear_cache ((int) addr, (int) eaddr);
1688 #endif /* defined (NeXT) && defined (__MACH__) */
1692 /* Make stack executable so we can call trampolines on stack.
1693 This is called from INITIALIZE_TRAMPOLINE in convex.h. */
1695 #include <sys/mman.h>
1696 #include <sys/vmparam.h>
1697 #include <machine/machparam.h>
1700 __enable_execute_stack (void)
1703 static unsigned lowest = USRSTACK;
1704 unsigned current = (unsigned) &fp & -NBPG;
1706 if (lowest > current)
1708 unsigned len = lowest - current;
1709 mremap (current, &len, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE);
1713 /* Clear instruction cache in case an old trampoline is in it. */
1716 #endif /* __convex__ */
1720 /* Modified from the convex -code above. */
1722 #include <sys/param.h>
1724 #include <sys/m88kbcs.h>
1727 __enable_execute_stack (void)
1730 static unsigned long lowest = USRSTACK;
1731 unsigned long current = (unsigned long) &save_errno & -NBPC;
1733 /* Ignore errno being set. memctl sets errno to EINVAL whenever the
1734 address is seen as 'negative'. That is the case with the stack. */
1737 if (lowest > current)
1739 unsigned len=lowest-current;
1740 memctl(current,len,MCT_TEXT);
1744 memctl(current,NBPC,MCT_TEXT);
1748 #endif /* __sysV88__ */
1752 #include <sys/signal.h>
1755 /* Motorola forgot to put memctl.o in the libp version of libc881.a,
1756 so define it here, because we need it in __clear_insn_cache below */
1757 /* On older versions of this OS, no memctl or MCT_TEXT are defined;
1758 hence we enable this stuff only if MCT_TEXT is #define'd. */
1773 /* Clear instruction cache so we can call trampolines on stack.
1774 This is called from FINALIZE_TRAMPOLINE in mot3300.h. */
1777 __clear_insn_cache (void)
1782 /* Preserve errno, because users would be surprised to have
1783 errno changing without explicitly calling any system-call. */
1786 /* Keep it simple : memctl (MCT_TEXT) always fully clears the insn cache.
1787 No need to use an address derived from _start or %sp, as 0 works also. */
1788 memctl(0, 4096, MCT_TEXT);
1793 #endif /* __sysV68__ */
1797 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1799 #include <sys/mman.h>
1800 #include <sys/types.h>
1801 #include <sys/param.h>
1802 #include <sys/vmmac.h>
1804 /* Modified from the convex -code above.
1805 mremap promises to clear the i-cache. */
1808 __enable_execute_stack (void)
1811 if (mprotect (((unsigned int)&fp/PAGSIZ)*PAGSIZ, PAGSIZ,
1812 PROT_READ|PROT_WRITE|PROT_EXEC))
1814 perror ("mprotect in __enable_execute_stack");
1819 #endif /* __pyr__ */
1821 #if defined (sony_news) && defined (SYSTYPE_BSD)
1824 #include <sys/types.h>
1825 #include <sys/param.h>
1826 #include <syscall.h>
1827 #include <machine/sysnews.h>
1829 /* cacheflush function for NEWS-OS 4.2.
1830 This function is called from trampoline-initialize code
1831 defined in config/mips/mips.h. */
1834 cacheflush (char *beg, int size, int flag)
1836 if (syscall (SYS_sysnews, NEWS_CACHEFLUSH, beg, size, FLUSH_BCACHE))
1838 perror ("cache_flush");
1844 #endif /* sony_news */
1845 #endif /* L_trampoline */
1850 #include "gbl-ctors.h"
1851 /* Some systems use __main in a way incompatible with its use in gcc, in these
1852 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
1853 give the same symbol without quotes for an alternative entry point. You
1854 must define both, or neither. */
1856 #define NAME__MAIN "__main"
1857 #define SYMBOL__MAIN __main
1860 #ifdef INIT_SECTION_ASM_OP
1861 #undef HAS_INIT_SECTION
1862 #define HAS_INIT_SECTION
1865 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
1867 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
1868 code to run constructors. In that case, we need to handle EH here, too. */
1870 #ifdef EH_FRAME_SECTION_NAME
1871 #include "unwind-dw2-fde.h"
1872 extern unsigned char __EH_FRAME_BEGIN__[];
1875 /* Run all the global destructors on exit from the program. */
1878 __do_global_dtors (void)
1880 #ifdef DO_GLOBAL_DTORS_BODY
1881 DO_GLOBAL_DTORS_BODY;
1883 static func_ptr *p = __DTOR_LIST__ + 1;
1890 #if defined (EH_FRAME_SECTION_NAME) && !defined (HAS_INIT_SECTION)
1892 static int completed = 0;
1896 __deregister_frame_info (__EH_FRAME_BEGIN__);
1903 #ifndef HAS_INIT_SECTION
1904 /* Run all the global constructors on entry to the program. */
1907 __do_global_ctors (void)
1909 #ifdef EH_FRAME_SECTION_NAME
1911 static struct object object;
1912 __register_frame_info (__EH_FRAME_BEGIN__, &object);
1915 DO_GLOBAL_CTORS_BODY;
1916 atexit (__do_global_dtors);
1918 #endif /* no HAS_INIT_SECTION */
1920 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
1921 /* Subroutine called automatically by `main'.
1922 Compiling a global function named `main'
1923 produces an automatic call to this function at the beginning.
1925 For many systems, this routine calls __do_global_ctors.
1926 For systems which support a .init section we use the .init section
1927 to run __do_global_ctors, so we need not do anything here. */
1932 /* Support recursive calls to `main': run initializers just once. */
1933 static int initialized;
1937 __do_global_ctors ();
1940 #endif /* no HAS_INIT_SECTION or INVOKE__main */
1942 #endif /* L__main */
1943 #endif /* __CYGWIN__ */
1947 #include "gbl-ctors.h"
1949 /* Provide default definitions for the lists of constructors and
1950 destructors, so that we don't get linker errors. These symbols are
1951 intentionally bss symbols, so that gld and/or collect will provide
1952 the right values. */
1954 /* We declare the lists here with two elements each,
1955 so that they are valid empty lists if no other definition is loaded.
1957 If we are using the old "set" extensions to have the gnu linker
1958 collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
1959 must be in the bss/common section.
1961 Long term no port should use those extensions. But many still do. */
1962 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
1963 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
1964 func_ptr __CTOR_LIST__[2] = {0, 0};
1965 func_ptr __DTOR_LIST__[2] = {0, 0};
1967 func_ptr __CTOR_LIST__[2];
1968 func_ptr __DTOR_LIST__[2];
1970 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
1971 #endif /* L_ctors */
1975 #include "gbl-ctors.h"
1983 static func_ptr *atexit_chain = 0;
1984 static long atexit_chain_length = 0;
1985 static volatile long last_atexit_chain_slot = -1;
1988 atexit (func_ptr func)
1990 if (++last_atexit_chain_slot == atexit_chain_length)
1992 atexit_chain_length += 32;
1994 atexit_chain = (func_ptr *) realloc (atexit_chain, atexit_chain_length
1995 * sizeof (func_ptr));
1997 atexit_chain = (func_ptr *) malloc (atexit_chain_length
1998 * sizeof (func_ptr));
2001 atexit_chain_length = 0;
2002 last_atexit_chain_slot = -1;
2007 atexit_chain[last_atexit_chain_slot] = func;
2011 extern void _cleanup (void);
2012 extern void _exit (int) __attribute__ ((__noreturn__));
2019 for ( ; last_atexit_chain_slot-- >= 0; )
2021 (*atexit_chain[last_atexit_chain_slot + 1]) ();
2022 atexit_chain[last_atexit_chain_slot + 1] = 0;
2024 free (atexit_chain);
2037 /* Simple; we just need a wrapper for ON_EXIT. */
2039 atexit (func_ptr func)
2041 return ON_EXIT (func);
2044 #endif /* ON_EXIT */
2045 #endif /* NEED_ATEXIT */