1 /* More subroutines needed by GCC output code on some machines. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 1989, 1992 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* As a special exception, if you link this library with files
22 compiled with GCC to produce an executable, this does not cause
23 the resulting executable to be covered by the GNU General Public License.
24 This exception does not however invalidate any other reasons why
25 the executable file might be covered by the GNU General Public License. */
27 /* It is incorrect to include config.h here, because this file is being
28 compiled for the target, and hence definitions concerning only the host
37 /* Don't use `fancy_abort' here even if config.h says to use it. */
42 /* In the first part of this file, we are interfacing to calls generated
43 by the compiler itself. These calls pass values into these routines
44 which have very specific modes (rather than very specific types), and
45 these compiler-generated calls also expect any return values to have
46 very specific modes (rather than very specific types). Thus, we need
47 to avoid using regular C language type names in this part of the file
48 because the sizes for those types can be configured to be anything.
49 Instead we use the following special type names. */
51 typedef unsigned int UQItype __attribute__ ((mode (QI)));
52 typedef int SItype __attribute__ ((mode (SI)));
53 typedef unsigned int USItype __attribute__ ((mode (SI)));
54 typedef int DItype __attribute__ ((mode (DI)));
55 typedef unsigned int UDItype __attribute__ ((mode (DI)));
56 typedef float SFtype __attribute__ ((mode (SF)));
57 typedef float DFtype __attribute__ ((mode (DF)));
59 typedef float XFtype __attribute__ ((mode (XF)));
61 #if LONG_DOUBLE_TYPE_SIZE == 128
62 typedef float TFtype __attribute__ ((mode (TF)));
65 /* Make sure that we don't accidentally use any normal C language built-in
66 type names in the first part of this file. Instead we want to use *only*
67 the type names defined above. The following macro definitions insure
68 that if we *do* accidentally use soem normal C language built-in type name,
69 we will get a syntax error. */
71 #define char bogus_type
72 #define short bogus_type
73 #define int bogus_type
74 #define long bogus_type
75 #define unsigned bogus_type
76 #define float bogus_type
77 #define double bogus_type
79 #define SI_TYPE_SIZE (sizeof (SItype) * BITS_PER_UNIT)
81 /* DIstructs are pairs of SItype values in the order determined by
85 struct DIstruct {SItype high, low;};
87 struct DIstruct {SItype low, high;};
90 /* We need this union to unpack/pack DImode values, since we don't have
91 any arithmetic yet. Incoming DImode parameters are stored into the
92 `ll' field, and the unpacked result is read from the struct `s'. */
100 #if defined (L_udivmoddi4) || defined (L_muldi3) || defined (L_udiv_w_sdiv)
102 #include "longlong.h"
104 #endif /* udiv or mul */
106 extern DItype __fixunssfdi (SFtype a);
107 extern DItype __fixunsdfdi (DFtype a);
109 #if defined (L_negdi2) || defined (L_divdi3) || defined (L_moddi3)
110 #if defined (L_divdi3) || defined (L_moddi3)
123 w.s.high = -uu.s.high - ((USItype) w.s.low > 0);
144 bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
148 w.s.high = (USItype)uu.s.low << -bm;
152 USItype carries = (USItype)uu.s.low >> bm;
153 w.s.low = (USItype)uu.s.low << b;
154 w.s.high = ((USItype)uu.s.high << b) | carries;
176 bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
180 w.s.low = (USItype)uu.s.high >> -bm;
184 USItype carries = (USItype)uu.s.high << bm;
185 w.s.high = (USItype)uu.s.high >> b;
186 w.s.low = ((USItype)uu.s.low >> b) | carries;
208 bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
212 w.s.high = (USItype)uu.s.low << -bm;
216 USItype carries = (USItype)uu.s.low >> bm;
217 w.s.low = (USItype)uu.s.low << b;
218 w.s.high = ((USItype)uu.s.high << b) | carries;
240 bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
243 /* w.s.high = 1..1 or 0..0 */
244 w.s.high = uu.s.high >> (sizeof (SItype) * BITS_PER_UNIT - 1);
245 w.s.low = uu.s.high >> -bm;
249 USItype carries = (USItype)uu.s.high << bm;
250 w.s.high = uu.s.high >> b;
251 w.s.low = ((USItype)uu.s.low >> b) | carries;
266 w.s.low = ffs (uu.s.low);
269 w.s.low = ffs (uu.s.high);
272 w.s.low += BITS_PER_UNIT * sizeof (SItype);
290 w.ll = __umulsidi3 (uu.s.low, vv.s.low);
291 w.s.high += ((USItype) uu.s.low * (USItype) vv.s.high
292 + (USItype) uu.s.high * (USItype) vv.s.low);
300 __udiv_w_sdiv (rp, a1, a0, d)
301 USItype *rp, a1, a0, d;
308 if (a1 < d - a1 - (a0 >> (SI_TYPE_SIZE - 1)))
310 /* dividend, divisor, and quotient are nonnegative */
311 sdiv_qrnnd (q, r, a1, a0, d);
315 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */
316 sub_ddmmss (c1, c0, a1, a0, d >> 1, d << (SI_TYPE_SIZE - 1));
317 /* Divide (c1*2^32 + c0) by d */
318 sdiv_qrnnd (q, r, c1, c0, d);
319 /* Add 2^31 to quotient */
320 q += (USItype) 1 << (SI_TYPE_SIZE - 1);
325 b1 = d >> 1; /* d/2, between 2^30 and 2^31 - 1 */
326 c1 = a1 >> 1; /* A/2 */
327 c0 = (a1 << (SI_TYPE_SIZE - 1)) + (a0 >> 1);
329 if (a1 < b1) /* A < 2^32*b1, so A/2 < 2^31*b1 */
331 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
333 r = 2*r + (a0 & 1); /* Remainder from A/(2*b1) */
350 else if (c1 < b1) /* So 2^31 <= (A/2)/b1 < 2^32 */
353 c0 = ~c0; /* logical NOT */
355 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
357 q = ~q; /* (A/2)/b1 */
360 r = 2*r + (a0 & 1); /* A/(2*b1) */
378 else /* Implies c1 = b1 */
379 { /* Hence a1 = d - 1 = 2*b1 - 1 */
399 static const UQItype __clz_tab[] =
401 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,
402 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,
403 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,
404 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,
405 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,
406 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,
407 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,
408 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,
412 __udivmoddi4 (n, d, rp)
419 USItype d0, d1, n0, n1, n2;
431 #if !UDIV_NEEDS_NORMALIZATION
438 udiv_qrnnd (q0, n0, n1, n0, d0);
441 /* Remainder in n0. */
448 d0 = 1 / d0; /* Divide intentionally by zero. */
450 udiv_qrnnd (q1, n1, 0, n1, d0);
451 udiv_qrnnd (q0, n0, n1, n0, d0);
453 /* Remainder in n0. */
464 #else /* UDIV_NEEDS_NORMALIZATION */
472 count_leading_zeros (bm, d0);
476 /* Normalize, i.e. make the most significant bit of the
480 n1 = (n1 << bm) | (n0 >> (SI_TYPE_SIZE - bm));
484 udiv_qrnnd (q0, n0, n1, n0, d0);
487 /* Remainder in n0 >> bm. */
494 d0 = 1 / d0; /* Divide intentionally by zero. */
496 count_leading_zeros (bm, d0);
500 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
501 conclude (the most significant bit of n1 is set) /\ (the
502 leading quotient digit q1 = 1).
504 This special case is necessary, not an optimization.
505 (Shifts counts of SI_TYPE_SIZE are undefined.) */
514 b = SI_TYPE_SIZE - bm;
518 n1 = (n1 << bm) | (n0 >> b);
521 udiv_qrnnd (q1, n1, n2, n1, d0);
526 udiv_qrnnd (q0, n0, n1, n0, d0);
528 /* Remainder in n0 >> bm. */
538 #endif /* UDIV_NEEDS_NORMALIZATION */
549 /* Remainder in n1n0. */
561 count_leading_zeros (bm, d1);
564 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
565 conclude (the most significant bit of n1 is set) /\ (the
566 quotient digit q0 = 0 or 1).
568 This special case is necessary, not an optimization. */
570 /* The condition on the next line takes advantage of that
571 n1 >= d1 (true due to program flow). */
572 if (n1 > d1 || n0 >= d0)
575 sub_ddmmss (n1, n0, n1, n0, d1, d0);
594 b = SI_TYPE_SIZE - bm;
596 d1 = (d1 << bm) | (d0 >> b);
599 n1 = (n1 << bm) | (n0 >> b);
602 udiv_qrnnd (q0, n1, n2, n1, d1);
603 umul_ppmm (m1, m0, q0, d0);
605 if (m1 > n1 || (m1 == n1 && m0 > n0))
608 sub_ddmmss (m1, m0, m1, m0, d1, d0);
613 /* Remainder in (n1n0 - m1m0) >> bm. */
616 sub_ddmmss (n1, n0, n1, n0, m1, m0);
617 rr.s.low = (n1 << b) | (n0 >> bm);
618 rr.s.high = n1 >> bm;
632 UDItype __udivmoddi4 ();
646 uu.ll = __negdi2 (uu.ll);
649 vv.ll = __negdi2 (vv.ll);
651 w = __udivmoddi4 (uu.ll, vv.ll, (UDItype *) 0);
660 UDItype __udivmoddi4 ();
674 uu.ll = __negdi2 (uu.ll);
676 vv.ll = __negdi2 (vv.ll);
678 (void) __udivmoddi4 (uu.ll, vv.ll, &w);
687 UDItype __udivmoddi4 ();
694 (void) __udivmoddi4 (u, v, &w);
701 UDItype __udivmoddi4 ();
706 return __udivmoddi4 (n, d, (UDItype *) 0);
717 au.ll = a, bu.ll = b;
719 if (au.s.high < bu.s.high)
721 else if (au.s.high > bu.s.high)
723 if ((USItype) au.s.low < (USItype) bu.s.low)
725 else if ((USItype) au.s.low > (USItype) bu.s.low)
738 au.ll = a, bu.ll = b;
740 if ((USItype) au.s.high < (USItype) bu.s.high)
742 else if ((USItype) au.s.high > (USItype) bu.s.high)
744 if ((USItype) au.s.low < (USItype) bu.s.low)
746 else if ((USItype) au.s.low > (USItype) bu.s.low)
752 #if defined(L_fixunstfdi) && (LONG_DOUBLE_TYPE_SIZE == 128)
753 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
754 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
766 /* Compute high word of result, as a flonum. */
767 b = (a / HIGH_WORD_COEFF);
768 /* Convert that to fixed (but not to DItype!),
769 and shift it into the high word. */
772 /* Remove high part from the TFtype, leaving the low part as flonum. */
774 /* Convert that to fixed (but not to DItype!) and add it in.
775 Sometimes A comes out negative. This is significant, since
776 A has more bits than a long int does. */
778 v -= (USItype) (- a);
785 #if defined(L_fixtfdi) && (LONG_DOUBLE_TYPE_SIZE == 128)
791 return - __fixunstfdi (-a);
792 return __fixunstfdi (a);
797 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
798 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
810 /* Compute high word of result, as a flonum. */
811 b = (a / HIGH_WORD_COEFF);
812 /* Convert that to fixed (but not to DItype!),
813 and shift it into the high word. */
816 /* Remove high part from the DFtype, leaving the low part as flonum. */
818 /* Convert that to fixed (but not to DItype!) and add it in.
819 Sometimes A comes out negative. This is significant, since
820 A has more bits than a long int does. */
822 v -= (USItype) (- a);
835 return - __fixunsdfdi (-a);
836 return __fixunsdfdi (a);
841 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
842 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
845 __fixunssfdi (SFtype original_a)
847 /* Convert the SFtype to a DFtype, because that is surely not going
848 to lose any bits. Some day someone else can write a faster version
849 that avoids converting to DFtype, and verify it really works right. */
850 DFtype a = original_a;
857 /* Compute high word of result, as a flonum. */
858 b = (a / HIGH_WORD_COEFF);
859 /* Convert that to fixed (but not to DItype!),
860 and shift it into the high word. */
863 /* Remove high part from the DFtype, leaving the low part as flonum. */
865 /* Convert that to fixed (but not to DItype!) and add it in.
866 Sometimes A comes out negative. This is significant, since
867 A has more bits than a long int does. */
869 v -= (USItype) (- a);
881 return - __fixunssfdi (-a);
882 return __fixunssfdi (a);
886 #if defined(L_floatditf) && (LONG_DOUBLE_TYPE_SIZE == 128)
887 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
888 #define HIGH_HALFWORD_COEFF (((UDItype) 1) << (WORD_SIZE / 2))
889 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
901 d = (USItype) (u >> WORD_SIZE);
902 d *= HIGH_HALFWORD_COEFF;
903 d *= HIGH_HALFWORD_COEFF;
904 d += (USItype) (u & (HIGH_WORD_COEFF - 1));
906 return (negate ? -d : d);
911 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
912 #define HIGH_HALFWORD_COEFF (((UDItype) 1) << (WORD_SIZE / 2))
913 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
925 d = (USItype) (u >> WORD_SIZE);
926 d *= HIGH_HALFWORD_COEFF;
927 d *= HIGH_HALFWORD_COEFF;
928 d += (USItype) (u & (HIGH_WORD_COEFF - 1));
930 return (negate ? -d : d);
935 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
936 #define HIGH_HALFWORD_COEFF (((UDItype) 1) << (WORD_SIZE / 2))
937 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
949 f = (USItype) (u >> WORD_SIZE);
950 f *= HIGH_HALFWORD_COEFF;
951 f *= HIGH_HALFWORD_COEFF;
952 f += (USItype) (u & (HIGH_WORD_COEFF - 1));
954 return (negate ? -f : f);
965 if (a >= - (DFtype) LONG_MIN)
966 return (SItype) (a + LONG_MIN) - LONG_MIN;
975 __fixunssfsi (SFtype a)
977 if (a >= - (SFtype) LONG_MIN)
978 return (SItype) (a + LONG_MIN) - LONG_MIN;
983 /* From here on down, the routines use normal data types. */
985 #define SItype bogus_type
986 #define USItype bogus_type
987 #define DItype bogus_type
988 #define UDItype bogus_type
989 #define SFtype bogus_type
990 #define DFtype bogus_type
1002 /* Like bcmp except the sign is meaningful.
1003 Reult is negative if S1 is less than S2,
1004 positive if S1 is greater, 0 if S1 and S2 are equal. */
1007 __gcc_bcmp (s1, s2, size)
1008 unsigned char *s1, *s2;
1013 unsigned char c1 = *s1++, c2 = *s2++;
1025 #if defined(__svr4__) || defined(__alliant__)
1029 /* The Alliant needs the added underscore. */
1030 asm (".globl __builtin_saveregs");
1031 asm ("__builtin_saveregs:");
1032 asm (".globl ___builtin_saveregs");
1033 asm ("___builtin_saveregs:");
1035 asm (" andnot 0x0f,%sp,%sp"); /* round down to 16-byte boundary */
1036 asm (" adds -96,%sp,%sp"); /* allocate stack space for reg save
1037 area and also for a new va_list
1039 /* Save all argument registers in the arg reg save area. The
1040 arg reg save area must have the following layout (according
1052 asm (" fst.q %f8, 0(%sp)"); /* save floating regs (f8-f15) */
1053 asm (" fst.q %f12,16(%sp)");
1055 asm (" st.l %r16,32(%sp)"); /* save integer regs (r16-r27) */
1056 asm (" st.l %r17,36(%sp)");
1057 asm (" st.l %r18,40(%sp)");
1058 asm (" st.l %r19,44(%sp)");
1059 asm (" st.l %r20,48(%sp)");
1060 asm (" st.l %r21,52(%sp)");
1061 asm (" st.l %r22,56(%sp)");
1062 asm (" st.l %r23,60(%sp)");
1063 asm (" st.l %r24,64(%sp)");
1064 asm (" st.l %r25,68(%sp)");
1065 asm (" st.l %r26,72(%sp)");
1066 asm (" st.l %r27,76(%sp)");
1068 asm (" adds 80,%sp,%r16"); /* compute the address of the new
1069 va_list structure. Put in into
1070 r16 so that it will be returned
1073 /* Initialize all fields of the new va_list structure. This
1074 structure looks like:
1077 unsigned long ireg_used;
1078 unsigned long freg_used;
1084 asm (" st.l %r0, 0(%r16)"); /* nfixed */
1085 asm (" st.l %r0, 4(%r16)"); /* nfloating */
1086 asm (" st.l %sp, 8(%r16)"); /* __va_ctl points to __va_struct. */
1087 asm (" bri %r1"); /* delayed return */
1088 asm (" st.l %r28,12(%r16)"); /* pointer to overflow args */
1090 #else /* not __SVR4__ */
1094 asm (".globl ___builtin_saveregs");
1095 asm ("___builtin_saveregs:");
1096 asm (" mov sp,r30");
1097 asm (" andnot 0x0f,sp,sp");
1098 asm (" adds -96,sp,sp"); /* allocate sufficient space on the stack */
1100 /* Fill in the __va_struct. */
1101 asm (" st.l r16, 0(sp)"); /* save integer regs (r16-r27) */
1102 asm (" st.l r17, 4(sp)"); /* int fixed[12] */
1103 asm (" st.l r18, 8(sp)");
1104 asm (" st.l r19,12(sp)");
1105 asm (" st.l r20,16(sp)");
1106 asm (" st.l r21,20(sp)");
1107 asm (" st.l r22,24(sp)");
1108 asm (" st.l r23,28(sp)");
1109 asm (" st.l r24,32(sp)");
1110 asm (" st.l r25,36(sp)");
1111 asm (" st.l r26,40(sp)");
1112 asm (" st.l r27,44(sp)");
1114 asm (" fst.q f8, 48(sp)"); /* save floating regs (f8-f15) */
1115 asm (" fst.q f12,64(sp)"); /* int floating[8] */
1117 /* Fill in the __va_ctl. */
1118 asm (" st.l sp, 80(sp)"); /* __va_ctl points to __va_struct. */
1119 asm (" st.l r28,84(sp)"); /* pointer to more args */
1120 asm (" st.l r0, 88(sp)"); /* nfixed */
1121 asm (" st.l r0, 92(sp)"); /* nfloating */
1123 asm (" adds 80,sp,r16"); /* return address of the __va_ctl. */
1125 asm (" mov r30,sp");
1126 /* recover stack and pass address to start
1128 #endif /* not __SVR4__ */
1129 #else /* not __i860__ */
1131 asm (".global __builtin_saveregs");
1132 asm ("__builtin_saveregs:");
1133 asm (".global ___builtin_saveregs");
1134 asm ("___builtin_saveregs:");
1135 #ifdef NEED_PROC_COMMAND
1138 asm ("st %i0,[%fp+68]");
1139 asm ("st %i1,[%fp+72]");
1140 asm ("st %i2,[%fp+76]");
1141 asm ("st %i3,[%fp+80]");
1142 asm ("st %i4,[%fp+84]");
1144 asm ("st %i5,[%fp+88]");
1145 #ifdef NEED_TYPE_COMMAND
1146 asm (".type __builtin_saveregs,#function");
1147 asm (".size __builtin_saveregs,.-__builtin_saveregs");
1149 #else /* not __sparc__ */
1150 #if defined(__MIPSEL__) | defined(__R3000__) | defined(__R2000__) | defined(__mips__)
1153 asm (" .ent __builtin_saveregs");
1154 asm (" .globl __builtin_saveregs");
1155 asm ("__builtin_saveregs:");
1156 asm (" sw $4,0($30)");
1157 asm (" sw $5,4($30)");
1158 asm (" sw $6,8($30)");
1159 asm (" sw $7,12($30)");
1161 asm (" .end __builtin_saveregs");
1162 #else /* not __mips__, etc. */
1163 __builtin_saveregs ()
1167 #endif /* not __mips__ */
1168 #endif /* not __sparc__ */
1169 #endif /* not __i860__ */
1173 #ifndef inhibit_eprintf
1175 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1177 /* This is used by the `assert' macro. */
1179 __eprintf (string, expression, line, filename)
1181 const char *expression;
1183 const char *filename;
1185 fprintf (stderr, string, expression, line, filename);
1194 /* Avoid warning from ranlib about empty object file. */
1196 __bb_avoid_warning ()
1199 #if defined (__sun__) && defined (__mc68000__)
1210 extern int ___tcov_init;
1212 __bb_init_func (blocks)
1216 ___tcov_init_func ();
1218 ___bb_link (blocks->filename, blocks->counts, blocks->ncounts);
1224 /* frills for C++ */
1227 typedef void (*vfp)(void);
1229 extern vfp __new_handler;
1231 /* void * operator new (size_t sz) */
1233 __builtin_new (size_t sz)
1237 /* malloc (0) is unpredictable; avoid it. */
1240 p = (void *) malloc (sz);
1242 (*__new_handler) ();
1245 #endif /* L_op_new */
1247 #ifdef L_new_handler
1249 /* This gets us __GNU_LIBRARY__. */
1250 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1253 #ifdef __GNU_LIBRARY__
1254 /* Avoid forcing the library's meaning of `write' on the user program
1255 by using the "internal" name (for use within the library) */
1256 #define write(fd, buf, n) __write((fd), (buf), (n))
1259 typedef void (*vfp)(void);
1261 extern void *__builtin_new (size_t);
1262 static void default_new_handler (void);
1264 vfp __new_handler = default_new_handler;
1267 __set_new_handler (handler)
1272 prev_handler = __new_handler;
1273 if (handler == 0) handler = default_new_handler;
1274 __new_handler = handler;
1275 return prev_handler;
1279 set_new_handler (handler)
1282 return __set_new_handler (handler);
1285 #define MESSAGE "Virtual memory exceeded in `new'\n"
1288 default_new_handler ()
1290 /* don't use fprintf (stderr, ...) because it may need to call malloc. */
1291 /* This should really print the name of the program, but that is hard to
1292 do. We need a standard, clean way to get at the name. */
1293 write (2, MESSAGE, sizeof (MESSAGE));
1294 /* don't call exit () because that may call global destructors which
1295 may cause a loop. */
1301 /* void operator delete (void *ptr) */
1303 __builtin_delete (void *ptr)
1311 unsigned int __shtab[] = {
1312 0x00000001, 0x00000002, 0x00000004, 0x00000008,
1313 0x00000010, 0x00000020, 0x00000040, 0x00000080,
1314 0x00000100, 0x00000200, 0x00000400, 0x00000800,
1315 0x00001000, 0x00002000, 0x00004000, 0x00008000,
1316 0x00010000, 0x00020000, 0x00040000, 0x00080000,
1317 0x00100000, 0x00200000, 0x00400000, 0x00800000,
1318 0x01000000, 0x02000000, 0x04000000, 0x08000000,
1319 0x10000000, 0x20000000, 0x40000000, 0x80000000
1323 #ifdef L_clear_cache
1324 /* Clear part of an instruction cache. */
1326 #define INSN_CACHE_PLANE_SIZE (INSN_CACHE_SIZE / INSN_CACHE_DEPTH)
1329 __clear_cache (beg, end)
1332 #ifdef INSN_CACHE_SIZE
1333 static char array[INSN_CACHE_SIZE + INSN_CACHE_PLANE_SIZE + INSN_CACHE_LINE_WIDTH];
1334 static int initialized = 0;
1338 typedef (*function_ptr) ();
1340 #if (INSN_CACHE_SIZE / INSN_CACHE_LINE_WIDTH) < 16
1341 /* It's cheaper to clear the whole cache.
1342 Put in a series of jump instructions so that calling the beginning
1343 of the cache will clear the whole thing. */
1347 int ptr = (((int) array + INSN_CACHE_LINE_WIDTH - 1)
1348 & -INSN_CACHE_LINE_WIDTH);
1349 int end_ptr = ptr + INSN_CACHE_SIZE;
1351 while (ptr < end_ptr)
1353 *(INSTRUCTION_TYPE *)ptr
1354 = JUMP_AHEAD_INSTRUCTION + INSN_CACHE_LINE_WIDTH;
1355 ptr += INSN_CACHE_LINE_WIDTH;
1357 *(INSTRUCTION_TYPE *)(ptr - INSN_CACHE_LINE_WIDTH) = RETURN_INSTRUCTION;
1362 /* Call the beginning of the sequence. */
1363 (((function_ptr) (((int) array + INSN_CACHE_LINE_WIDTH - 1)
1364 & -INSN_CACHE_LINE_WIDTH))
1367 #else /* Cache is large. */
1371 int ptr = (((int) array + INSN_CACHE_LINE_WIDTH - 1)
1372 & -INSN_CACHE_LINE_WIDTH);
1374 while (ptr < (int) array + sizeof array)
1376 *(INSTRUCTION_TYPE *)ptr = RETURN_INSTRUCTION;
1377 ptr += INSN_CACHE_LINE_WIDTH;
1383 /* Find the location in array that occupies the same cache line as BEG. */
1385 offset = ((int) beg & -INSN_CACHE_LINE_WIDTH) & (INSN_CACHE_PLANE_SIZE - 1);
1386 start_addr = (((int) (array + INSN_CACHE_PLANE_SIZE - 1)
1387 & -INSN_CACHE_PLANE_SIZE)
1390 /* Compute the cache alignment of the place to stop clearing. */
1391 #if 0 /* This is not needed for gcc's purposes. */
1392 /* If the block to clear is bigger than a cache plane,
1393 we clear the entire cache, and OFFSET is already correct. */
1394 if (end < beg + INSN_CACHE_PLANE_SIZE)
1396 offset = (((int) (end + INSN_CACHE_LINE_WIDTH - 1)
1397 & -INSN_CACHE_LINE_WIDTH)
1398 & (INSN_CACHE_PLANE_SIZE - 1));
1400 #if INSN_CACHE_DEPTH > 1
1401 end_addr = (start_addr & -INSN_CACHE_PLANE_SIZE) + offset;
1402 if (end_addr <= start_addr)
1403 end_addr += INSN_CACHE_PLANE_SIZE;
1405 for (plane = 0; plane < INSN_CACHE_DEPTH; plane++)
1407 int addr = start_addr + plane * INSN_CACHE_PLANE_SIZE;
1408 int stop = end_addr + plane * INSN_CACHE_PLANE_SIZE;
1410 while (addr != stop)
1412 /* Call the return instruction at ADDR. */
1413 ((function_ptr) addr) ();
1415 addr += INSN_CACHE_LINE_WIDTH;
1418 #else /* just one plane */
1421 /* Call the return instruction at START_ADDR. */
1422 ((function_ptr) start_addr) ();
1424 start_addr += INSN_CACHE_LINE_WIDTH;
1426 while ((start_addr % INSN_CACHE_SIZE) != offset);
1427 #endif /* just one plane */
1428 #endif /* Cache is large */
1429 #endif /* Cache exists */
1432 #endif /* L_clear_cache */
1436 /* Jump to a trampoline, loading the static chain address. */
1438 #ifdef TRANSFER_FROM_TRAMPOLINE
1439 TRANSFER_FROM_TRAMPOLINE
1444 /* Make stack executable so we can call trampolines on stack.
1445 This is called from INITIALIZE_TRAMPOLINE in convex.h. */
1447 #include <sys/mman.h>
1448 #include <sys/vmparam.h>
1449 #include <machine/machparam.h>
1452 __enable_execute_stack ()
1455 static unsigned lowest = USRSTACK;
1456 unsigned current = (unsigned) &fp & -NBPG;
1458 if (lowest > current)
1460 unsigned len = lowest - current;
1461 mremap (current, &len, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE);
1465 /* Clear instruction cache in case an old trampoline is in it. */
1468 #endif /* __convex__ */
1472 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1474 #include <sys/mman.h>
1475 #include <sys/types.h>
1476 #include <sys/param.h>
1477 #include <sys/vmmac.h>
1479 /* Modified from the convex -code above.
1480 mremap promises to clear the i-cache. */
1483 __enable_execute_stack ()
1486 if (mprotect (((unsigned int)&fp/PAGSIZ)*PAGSIZ, PAGSIZ,
1487 PROT_READ|PROT_WRITE|PROT_EXEC))
1489 perror ("mprotect in __enable_execute_stack");
1494 #endif /* __pyr__ */
1495 #endif /* L_trampoline */
1499 #include "gbl-ctors.h"
1501 /* Run all the global destructors on exit from the program. */
1504 __do_global_dtors ()
1506 #ifdef DO_GLOBAL_DTORS_BODY
1507 DO_GLOBAL_DTORS_BODY;
1509 unsigned nptrs = (unsigned HOST_WIDE_INT) __DTOR_LIST__[0];
1512 /* Some systems place the number of pointers
1513 in the first word of the table.
1514 On other systems, that word is -1.
1515 In all cases, the table is null-terminated. */
1517 /* If the length is not recorded, count up to the null. */
1519 for (nptrs = 0; __DTOR_LIST__[nptrs + 1] != 0; nptrs++);
1521 /* GNU LD format. */
1522 for (i = nptrs; i >= 1; i--)
1523 __DTOR_LIST__[i] ();
1527 #ifndef INIT_SECTION_ASM_OP
1528 /* Run all the global constructors on entry to the program. */
1531 #define ON_EXIT(a, b)
1533 /* Make sure the exit routine is pulled in to define the globals as
1534 bss symbols, just in case the linker does not automatically pull
1535 bss definitions from the library. */
1537 extern int _exit_dummy_decl;
1538 int *_exit_dummy_ref = &_exit_dummy_decl;
1539 #endif /* ON_EXIT */
1542 __do_global_ctors ()
1544 DO_GLOBAL_CTORS_BODY;
1545 ON_EXIT (__do_global_dtors, 0);
1547 #endif /* no INIT_SECTION_ASM_OP */
1549 #if !defined (INIT_SECTION_ASM_OP) || defined (INVOKE__main)
1550 /* Subroutine called automatically by `main'.
1551 Compiling a global function named `main'
1552 produces an automatic call to this function at the beginning.
1554 For many systems, this routine calls __do_global_ctors.
1555 For systems which support a .init section we use the .init section
1556 to run __do_global_ctors, so we need not do anything here. */
1561 /* Support recursive calls to `main': run initializers just once. */
1562 static int initialized = 0;
1566 __do_global_ctors ();
1569 #endif /* no INIT_SECTION_ASM_OP or INVOKE__main */
1571 #endif /* L__main */
1575 #include "gbl-ctors.h"
1577 /* Provide default definitions for the lists of constructors and
1578 destructors, so that we don't get linker errors. These symbols are
1579 intentionally bss symbols, so that gld and/or collect will provide
1580 the right values. */
1582 /* We declare the lists here with two elements each,
1583 so that they are valid empty lists if no other definition is loaded. */
1584 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
1586 /* After 2.3, try this definition on all systems. */
1587 func_ptr __CTOR_LIST__[2] = {0, 0};
1588 func_ptr __DTOR_LIST__[2] = {0, 0};
1590 func_ptr __CTOR_LIST__[2];
1591 func_ptr __DTOR_LIST__[2];
1593 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
1594 #endif /* L_ctors */
1598 #include "gbl-ctors.h"
1602 /* If we have no known way of registering our own __do_global_dtors
1603 routine so that it will be invoked at program exit time, then we
1604 have to define our own exit routine which will get this to happen. */
1606 extern void __do_global_dtors ();
1607 extern void _cleanup ();
1608 extern volatile void _exit ();
1614 __do_global_dtors ();
1624 int _exit_dummy_decl = 0; /* prevent compiler & linker warnings */
1629 /* In a.out systems, we need to have these dummy constructor and destructor
1630 lists in the library.
1632 When using `collect', the first link will resolve __CTOR_LIST__
1633 and __DTOR_LIST__ to these symbols. We will then run "nm" on the
1634 result, build the correct __CTOR_LIST__ and __DTOR_LIST__, and relink.
1635 Since we don't do the second link if no constructors existed, these
1636 dummies must be fully functional empty lists.
1638 When using `gnu ld', these symbols will be used if there are no
1639 constructors. If there are constructors, the N_SETV symbol defined
1640 by the linker from the N_SETT's in input files will define __CTOR_LIST__
1641 and __DTOR_LIST__ rather than its being allocated as common storage
1642 by the definitions below.
1644 When using a linker that supports constructor and destructor segments,
1645 these definitions will not be used, since crtbegin.o and crtend.o
1646 (from crtstuff.c) will have already defined __CTOR_LIST__ and
1647 __DTOR_LIST__. The crt*.o files are passed directly to the linker
1648 on its command line, by gcc. */
1650 /* The list needs two elements: one is ignored (the old count); the
1651 second is the terminating zero. Since both values are zero, this
1652 declaration is not initialized, and it becomes `common'. */
1655 #include "gbl-ctors.h"
1656 func_ptr __CTOR_LIST__[2];
1660 #include "gbl-ctors.h"
1661 func_ptr __DTOR_LIST__[2];