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 accidentaly 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* accidently 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;
269 w.ll = __umulsidi3 (uu.s.low, vv.s.low);
270 w.s.high += ((USItype) uu.s.low * (USItype) vv.s.high
271 + (USItype) uu.s.high * (USItype) vv.s.low);
279 __udiv_w_sdiv (rp, a1, a0, d)
280 USItype *rp, a1, a0, d;
287 if (a1 < d - a1 - (a0 >> 31))
289 /* dividend, divisor, and quotient are nonnegative */
290 sdiv_qrnnd (q, r, a1, a0, d);
294 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */
295 sub_ddmmss (c1, c0, a1, a0, d >> 1, d << 31);
296 /* Divide (c1*2^32 + c0) by d */
297 sdiv_qrnnd (q, r, c1, c0, d);
298 /* Add 2^31 to quotient */
304 b1 = d >> 1; /* d/2, between 2^30 and 2^31 - 1 */
305 c1 = a1 >> 1; /* A/2 */
306 c0 = (a1 << 31) + (a0 >> 1);
308 if (a1 < b1) /* A < 2^32*b1, so A/2 < 2^31*b1 */
310 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
312 r = 2*r + (a0 & 1); /* Remainder from A/(2*b1) */
329 else if (c1 < b1) /* So 2^31 <= (A/2)/b1 < 2^32 */
332 c0 = ~c0; /* logical NOT */
334 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
336 q = ~q; /* (A/2)/b1 */
339 r = 2*r + (a0 & 1); /* A/(2*b1) */
357 else /* Implies c1 = b1 */
358 { /* Hence a1 = d - 1 = 2*b1 - 1 */
378 static const UQItype __clz_tab[] =
380 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,
381 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,
382 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,
383 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,
384 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,
385 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,
386 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,
387 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,
391 __udivmoddi4 (n, d, rp)
398 USItype d0, d1, n0, n1, n2;
410 #if !UDIV_NEEDS_NORMALIZATION
417 udiv_qrnnd (q0, n0, n1, n0, d0);
420 /* Remainder in n0. */
427 d0 = 1 / d0; /* Divide intentionally by zero. */
429 udiv_qrnnd (q1, n1, 0, n1, d0);
430 udiv_qrnnd (q0, n0, n1, n0, d0);
432 /* Remainder in n0. */
443 #else /* UDIV_NEEDS_NORMALIZATION */
451 count_leading_zeros (bm, d0);
455 /* Normalize, i.e. make the most significant bit of the
459 n1 = (n1 << bm) | (n0 >> (SI_TYPE_SIZE - bm));
463 udiv_qrnnd (q0, n0, n1, n0, d0);
466 /* Remainder in n0 >> bm. */
473 d0 = 1 / d0; /* Divide intentionally by zero. */
475 count_leading_zeros (bm, d0);
479 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
480 conclude (the most significant bit of n1 is set) /\ (the
481 leading quotient digit q1 = 1).
483 This special case is necessary, not an optimization.
484 (Shifts counts of SI_TYPE_SIZE are undefined.) */
493 b = SI_TYPE_SIZE - bm;
497 n1 = (n1 << bm) | (n0 >> b);
500 udiv_qrnnd (q1, n1, n2, n1, d0);
505 udiv_qrnnd (q0, n0, n1, n0, d0);
507 /* Remainder in n0 >> bm. */
517 #endif /* UDIV_NEEDS_NORMALIZATION */
528 /* Remainder in n1n0. */
540 count_leading_zeros (bm, d1);
543 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
544 conclude (the most significant bit of n1 is set) /\ (the
545 quotient digit q0 = 0 or 1).
547 This special case is necessary, not an optimization. */
549 /* The condition on the next line takes advantage of that
550 n1 >= d1 (true due to program flow). */
551 if (n1 > d1 || n0 >= d0)
554 sub_ddmmss (n1, n0, n1, n0, d1, d0);
573 b = SI_TYPE_SIZE - bm;
575 d1 = (d1 << bm) | (d0 >> b);
578 n1 = (n1 << bm) | (n0 >> b);
581 udiv_qrnnd (q0, n1, n2, n1, d1);
582 umul_ppmm (m1, m0, q0, d0);
584 if (m1 > n1 || (m1 == n1 && m0 > n0))
587 sub_ddmmss (m1, m0, m1, m0, d1, d0);
592 /* Remainder in (n1n0 - m1m0) >> bm. */
595 sub_ddmmss (n1, n0, n1, n0, m1, m0);
596 rr.s.low = (n1 << b) | (n0 >> bm);
597 rr.s.high = n1 >> bm;
611 UDItype __udivmoddi4 ();
625 uu.ll = __negdi2 (uu.ll);
628 vv.ll = __negdi2 (vv.ll);
630 w = __udivmoddi4 (uu.ll, vv.ll, (UDItype *) 0);
639 UDItype __udivmoddi4 ();
653 uu.ll = __negdi2 (uu.ll);
655 vv.ll = __negdi2 (vv.ll);
657 (void) __udivmoddi4 (uu.ll, vv.ll, &w);
666 UDItype __udivmoddi4 ();
673 (void) __udivmoddi4 (u, v, &w);
680 UDItype __udivmoddi4 ();
685 return __udivmoddi4 (n, d, (UDItype *) 0);
696 au.ll = a, bu.ll = b;
698 if (au.s.high < bu.s.high)
700 else if (au.s.high > bu.s.high)
702 if ((USItype) au.s.low < (USItype) bu.s.low)
704 else if ((USItype) au.s.low > (USItype) bu.s.low)
717 au.ll = a, bu.ll = b;
719 if ((USItype) au.s.high < (USItype) bu.s.high)
721 else if ((USItype) au.s.high > (USItype) bu.s.high)
723 if ((USItype) au.s.low < (USItype) bu.s.low)
725 else if ((USItype) au.s.low > (USItype) bu.s.low)
731 #if defined(L_fixunstfdi) && (LONG_DOUBLE_TYPE_SIZE == 128)
732 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
733 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
745 /* Compute high word of result, as a flonum. */
746 b = (a / HIGH_WORD_COEFF);
747 /* Convert that to fixed (but not to DItype!),
748 and shift it into the high word. */
751 /* Remove high part from the TFtype, leaving the low part as flonum. */
753 /* Convert that to fixed (but not to DItype!) and add it in.
754 Sometimes A comes out negative. This is significant, since
755 A has more bits than a long int does. */
757 v -= (USItype) (- a);
764 #if defined(L_fixtfdi) && (LONG_DOUBLE_TYPE_SIZE == 128)
770 return - __fixunstfdi (-a);
771 return __fixunstfdi (a);
776 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
777 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
789 /* Compute high word of result, as a flonum. */
790 b = (a / HIGH_WORD_COEFF);
791 /* Convert that to fixed (but not to DItype!),
792 and shift it into the high word. */
795 /* Remove high part from the DFtype, leaving the low part as flonum. */
797 /* Convert that to fixed (but not to DItype!) and add it in.
798 Sometimes A comes out negative. This is significant, since
799 A has more bits than a long int does. */
801 v -= (USItype) (- a);
814 return - __fixunsdfdi (-a);
815 return __fixunsdfdi (a);
820 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
821 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
824 __fixunssfdi (SFtype original_a)
826 /* Convert the SFtype to a DFtype, because that is surely not going
827 to lose any bits. Some day someone else can write a faster version
828 that avoids converting to DFtype, and verify it really works right. */
829 DFtype a = original_a;
836 /* Compute high word of result, as a flonum. */
837 b = (a / HIGH_WORD_COEFF);
838 /* Convert that to fixed (but not to DItype!),
839 and shift it into the high word. */
842 /* Remove high part from the DFtype, leaving the low part as flonum. */
844 /* Convert that to fixed (but not to DItype!) and add it in.
845 Sometimes A comes out negative. This is significant, since
846 A has more bits than a long int does. */
848 v -= (USItype) (- a);
860 return - __fixunssfdi (-a);
861 return __fixunssfdi (a);
865 #if defined(L_floatditf) && (LONG_DOUBLE_TYPE_SIZE == 128)
866 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
867 #define HIGH_HALFWORD_COEFF (((UDItype) 1) << (WORD_SIZE / 2))
868 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
880 d = (USItype) (u >> WORD_SIZE);
881 d *= HIGH_HALFWORD_COEFF;
882 d *= HIGH_HALFWORD_COEFF;
883 d += (USItype) (u & (HIGH_WORD_COEFF - 1));
885 return (negate ? -d : d);
890 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
891 #define HIGH_HALFWORD_COEFF (((UDItype) 1) << (WORD_SIZE / 2))
892 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
904 d = (USItype) (u >> WORD_SIZE);
905 d *= HIGH_HALFWORD_COEFF;
906 d *= HIGH_HALFWORD_COEFF;
907 d += (USItype) (u & (HIGH_WORD_COEFF - 1));
909 return (negate ? -d : d);
914 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
915 #define HIGH_HALFWORD_COEFF (((UDItype) 1) << (WORD_SIZE / 2))
916 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
928 f = (USItype) (u >> WORD_SIZE);
929 f *= HIGH_HALFWORD_COEFF;
930 f *= HIGH_HALFWORD_COEFF;
931 f += (USItype) (u & (HIGH_WORD_COEFF - 1));
933 return (negate ? -f : f);
944 if (a >= - (DFtype) LONG_MIN)
945 return (SItype) (a + LONG_MIN) - LONG_MIN;
954 __fixunssfsi (SFtype a)
956 if (a >= - (SFtype) LONG_MIN)
957 return (SItype) (a + LONG_MIN) - LONG_MIN;
962 /* From here on down, the routines use normal data types. */
964 #define SItype bogus_type
965 #define USItype bogus_type
966 #define DItype bogus_type
967 #define UDItype bogus_type
968 #define SFtype bogus_type
969 #define DFtype bogus_type
981 /* Like bcmp except the sign is meaningful.
982 Reult is negative if S1 is less than S2,
983 positive if S1 is greater, 0 if S1 and S2 are equal. */
986 __gcc_bcmp (s1, s2, size)
987 unsigned char *s1, *s2;
992 unsigned char c1 = *s1++, c2 = *s2++;
1004 #if defined(__svr4__) || defined(__alliant__)
1008 /* The Alliant needs the added underscore. */
1009 asm (".globl __builtin_saveregs");
1010 asm ("__builtin_saveregs:");
1011 asm (".globl ___builtin_saveregs");
1012 asm ("___builtin_saveregs:");
1014 asm (" andnot 0x0f,%sp,%sp"); /* round down to 16-byte boundary */
1015 asm (" adds -96,%sp,%sp"); /* allocate stack space for reg save
1016 area and also for a new va_list
1018 /* Save all argument registers in the arg reg save area. The
1019 arg reg save area must have the following layout (according
1031 asm (" fst.q %f8, 0(%sp)"); /* save floating regs (f8-f15) */
1032 asm (" fst.q %f12,16(%sp)");
1034 asm (" st.l %r16,32(%sp)"); /* save integer regs (r16-r27) */
1035 asm (" st.l %r17,36(%sp)");
1036 asm (" st.l %r18,40(%sp)");
1037 asm (" st.l %r19,44(%sp)");
1038 asm (" st.l %r20,48(%sp)");
1039 asm (" st.l %r21,52(%sp)");
1040 asm (" st.l %r22,56(%sp)");
1041 asm (" st.l %r23,60(%sp)");
1042 asm (" st.l %r24,64(%sp)");
1043 asm (" st.l %r25,68(%sp)");
1044 asm (" st.l %r26,72(%sp)");
1045 asm (" st.l %r27,76(%sp)");
1047 asm (" adds 80,%sp,%r16"); /* compute the address of the new
1048 va_list structure. Put in into
1049 r16 so that it will be returned
1052 /* Initialize all fields of the new va_list structure. This
1053 structure looks like:
1056 unsigned long ireg_used;
1057 unsigned long freg_used;
1063 asm (" st.l %r0, 0(%r16)"); /* nfixed */
1064 asm (" st.l %r0, 4(%r16)"); /* nfloating */
1065 asm (" st.l %sp, 8(%r16)"); /* __va_ctl points to __va_struct. */
1066 asm (" bri %r1"); /* delayed return */
1067 asm (" st.l %r28,12(%r16)"); /* pointer to overflow args */
1069 #else /* not __SVR4__ */
1073 asm (".globl ___builtin_saveregs");
1074 asm ("___builtin_saveregs:");
1075 asm (" mov sp,r30");
1076 asm (" andnot 0x0f,sp,sp");
1077 asm (" adds -96,sp,sp"); /* allocate sufficient space on the stack */
1079 /* Fill in the __va_struct. */
1080 asm (" st.l r16, 0(sp)"); /* save integer regs (r16-r27) */
1081 asm (" st.l r17, 4(sp)"); /* int fixed[12] */
1082 asm (" st.l r18, 8(sp)");
1083 asm (" st.l r19,12(sp)");
1084 asm (" st.l r20,16(sp)");
1085 asm (" st.l r21,20(sp)");
1086 asm (" st.l r22,24(sp)");
1087 asm (" st.l r23,28(sp)");
1088 asm (" st.l r24,32(sp)");
1089 asm (" st.l r25,36(sp)");
1090 asm (" st.l r26,40(sp)");
1091 asm (" st.l r27,44(sp)");
1093 asm (" fst.q f8, 48(sp)"); /* save floating regs (f8-f15) */
1094 asm (" fst.q f12,64(sp)"); /* int floating[8] */
1096 /* Fill in the __va_ctl. */
1097 asm (" st.l sp, 80(sp)"); /* __va_ctl points to __va_struct. */
1098 asm (" st.l r28,84(sp)"); /* pointer to more args */
1099 asm (" st.l r0, 88(sp)"); /* nfixed */
1100 asm (" st.l r0, 92(sp)"); /* nfloating */
1102 asm (" adds 80,sp,r16"); /* return address of the __va_ctl. */
1104 asm (" mov r30,sp");
1105 /* recover stack and pass address to start
1107 #endif /* not __SVR4__ */
1108 #else /* not __i860__ */
1110 asm (".global __builtin_saveregs");
1111 asm ("__builtin_saveregs:");
1112 asm (".global ___builtin_saveregs");
1113 asm ("___builtin_saveregs:");
1114 #ifdef NEED_PROC_COMMAND
1117 asm ("st %i0,[%fp+68]");
1118 asm ("st %i1,[%fp+72]");
1119 asm ("st %i2,[%fp+76]");
1120 asm ("st %i3,[%fp+80]");
1121 asm ("st %i4,[%fp+84]");
1123 asm ("st %i5,[%fp+88]");
1124 #ifdef NEED_TYPE_COMMAND
1125 asm (".type __builtin_saveregs,#function");
1126 asm (".size __builtin_saveregs,.-__builtin_saveregs");
1128 #else /* not __sparc__ */
1129 #if defined(__MIPSEL__) | defined(__R3000__) | defined(__R2000__) | defined(__mips__)
1132 asm (" .ent __builtin_saveregs");
1133 asm (" .globl __builtin_saveregs");
1134 asm ("__builtin_saveregs:");
1135 asm (" sw $4,0($30)");
1136 asm (" sw $5,4($30)");
1137 asm (" sw $6,8($30)");
1138 asm (" sw $7,12($30)");
1140 asm (" .end __builtin_saveregs");
1141 #else /* not __mips__, etc. */
1142 __builtin_saveregs ()
1146 #endif /* not __mips__ */
1147 #endif /* not __sparc__ */
1148 #endif /* not __i860__ */
1152 #ifndef inhibit_eprintf
1154 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1156 /* This is used by the `assert' macro. */
1158 __eprintf (string, expression, line, filename)
1160 const char *expression;
1162 const char *filename;
1164 fprintf (stderr, string, expression, line, filename);
1173 /* Avoid warning from ranlib about empty object file. */
1175 __bb_avoid_warning ()
1178 #if defined (__sun__) && defined (__mc68000__)
1189 extern int ___tcov_init;
1191 __bb_init_func (blocks)
1195 ___tcov_init_func ();
1197 ___bb_link (blocks->filename, blocks->counts, blocks->ncounts);
1203 /* frills for C++ */
1205 #ifdef L_builtin_new
1206 typedef void (*vfp)(void);
1208 extern vfp __new_handler;
1216 /* malloc (0) is unpredictable; avoid it. */
1219 p = (void *) malloc (sz);
1221 (*__new_handler) ();
1228 /* This gets us __GNU_LIBRARY__. */
1229 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1232 #ifdef __GNU_LIBRARY__
1233 /* Avoid forcing the library's meaning of `write' on the user program
1234 by using the "internal" name (for use within the library) */
1235 #define write(fd, buf, n) __write((fd), (buf), (n))
1238 typedef void (*vfp)(void);
1240 extern void *__builtin_new (size_t);
1241 static void default_new_handler (void);
1243 vfp __new_handler = default_new_handler;
1246 __builtin_vec_new (p, maxindex, size, ctor)
1250 void (*ctor)(void *);
1253 size_t nelts = maxindex + 1;
1257 p = __builtin_new (nelts * size);
1261 for (i = 0; i < nelts; i++)
1271 __set_new_handler (handler)
1276 prev_handler = __new_handler;
1277 if (handler == 0) handler = default_new_handler;
1278 __new_handler = handler;
1279 return prev_handler;
1283 set_new_handler (handler)
1286 return __set_new_handler (handler);
1289 #define MESSAGE "Virtual memory exceeded in `new'\n"
1292 default_new_handler ()
1294 /* don't use fprintf (stderr, ...) because it may need to call malloc. */
1295 /* This should really print the name of the program, but that is hard to
1296 do. We need a standard, clean way to get at the name. */
1297 write (2, MESSAGE, sizeof (MESSAGE));
1298 /* don't call exit () because that may call global destructors which
1299 may cause a loop. */
1304 #ifdef L_builtin_del
1305 typedef void (*vfp)(void);
1308 __builtin_delete (ptr)
1316 __builtin_vec_delete (ptr, maxindex, size, dtor, auto_delete_vec, auto_delete)
1320 void (*dtor)(void *, int);
1324 size_t nelts = maxindex + 1;
1327 ptr += nelts * size;
1329 for (i = 0; i < nelts; i++)
1332 (*dtor) (ptr, auto_delete);
1335 if (auto_delete_vec)
1336 __builtin_delete (p);
1342 unsigned int __shtab[] = {
1343 0x00000001, 0x00000002, 0x00000004, 0x00000008,
1344 0x00000010, 0x00000020, 0x00000040, 0x00000080,
1345 0x00000100, 0x00000200, 0x00000400, 0x00000800,
1346 0x00001000, 0x00002000, 0x00004000, 0x00008000,
1347 0x00010000, 0x00020000, 0x00040000, 0x00080000,
1348 0x00100000, 0x00200000, 0x00400000, 0x00800000,
1349 0x01000000, 0x02000000, 0x04000000, 0x08000000,
1350 0x10000000, 0x20000000, 0x40000000, 0x80000000
1354 #ifdef L_clear_cache
1355 /* Clear part of an instruction cache. */
1357 #define INSN_CACHE_PLANE_SIZE (INSN_CACHE_SIZE / INSN_CACHE_DEPTH)
1360 __clear_cache (beg, end)
1363 #ifdef INSN_CACHE_SIZE
1364 static char array[INSN_CACHE_SIZE + INSN_CACHE_PLANE_SIZE + INSN_CACHE_LINE_WIDTH];
1365 static int initialized = 0;
1369 typedef (*function_ptr) ();
1371 #if (INSN_CACHE_SIZE / INSN_CACHE_LINE_WIDTH) < 16
1372 /* It's cheaper to clear the whole cache.
1373 Put in a series of jump instructions so that calling the beginning
1374 of the cache will clear the whole thing. */
1378 int ptr = (((int) array + INSN_CACHE_LINE_WIDTH - 1)
1379 & -INSN_CACHE_LINE_WIDTH);
1380 int end_ptr = ptr + INSN_CACHE_SIZE;
1382 while (ptr < end_ptr)
1384 *(INSTRUCTION_TYPE *)ptr
1385 = JUMP_AHEAD_INSTRUCTION + INSN_CACHE_LINE_WIDTH;
1386 ptr += INSN_CACHE_LINE_WIDTH;
1388 *(INSTRUCTION_TYPE *)(ptr - INSN_CACHE_LINE_WIDTH) = RETURN_INSTRUCTION;
1393 /* Call the beginning of the sequence. */
1394 (((function_ptr) (((int) array + INSN_CACHE_LINE_WIDTH - 1)
1395 & -INSN_CACHE_LINE_WIDTH))
1398 #else /* Cache is large. */
1402 int ptr = (((int) array + INSN_CACHE_LINE_WIDTH - 1)
1403 & -INSN_CACHE_LINE_WIDTH);
1405 while (ptr < (int) array + sizeof array)
1407 *(INSTRUCTION_TYPE *)ptr = RETURN_INSTRUCTION;
1408 ptr += INSN_CACHE_LINE_WIDTH;
1414 /* Find the location in array that occupies the same cache line as BEG. */
1416 offset = ((int) beg & -INSN_CACHE_LINE_WIDTH) & (INSN_CACHE_PLANE_SIZE - 1);
1417 start_addr = (((int) (array + INSN_CACHE_PLANE_SIZE - 1)
1418 & -INSN_CACHE_PLANE_SIZE)
1421 /* Compute the cache alignment of the place to stop clearing. */
1422 #if 0 /* This is not needed for gcc's purposes. */
1423 /* If the block to clear is bigger than a cache plane,
1424 we clear the entire cache, and OFFSET is already correct. */
1425 if (end < beg + INSN_CACHE_PLANE_SIZE)
1427 offset = (((int) (end + INSN_CACHE_LINE_WIDTH - 1)
1428 & -INSN_CACHE_LINE_WIDTH)
1429 & (INSN_CACHE_PLANE_SIZE - 1));
1431 #if INSN_CACHE_DEPTH > 1
1432 end_addr = (start_addr & -INSN_CACHE_PLANE_SIZE) + offset;
1433 if (end_addr <= start_addr)
1434 end_addr += INSN_CACHE_PLANE_SIZE;
1436 for (plane = 0; plane < INSN_CACHE_DEPTH; plane++)
1438 int addr = start_addr + plane * INSN_CACHE_PLANE_SIZE;
1439 int stop = end_addr + plane * INSN_CACHE_PLANE_SIZE;
1441 while (addr != stop)
1443 /* Call the return instruction at ADDR. */
1444 ((function_ptr) addr) ();
1446 addr += INSN_CACHE_LINE_WIDTH;
1449 #else /* just one plane */
1452 /* Call the return instruction at START_ADDR. */
1453 ((function_ptr) start_addr) ();
1455 start_addr += INSN_CACHE_LINE_WIDTH;
1457 while ((start_addr % INSN_CACHE_SIZE) != offset);
1458 #endif /* just one plane */
1459 #endif /* Cache is large */
1460 #endif /* Cache exists */
1463 #endif /* L_clear_cache */
1467 /* Jump to a trampoline, loading the static chain address. */
1469 #ifdef TRANSFER_FROM_TRAMPOLINE
1470 TRANSFER_FROM_TRAMPOLINE
1475 /* Make stack executable so we can call trampolines on stack.
1476 This is called from INITIALIZE_TRAMPOLINE in convex.h. */
1478 #include <sys/mman.h>
1479 #include <sys/vmparam.h>
1480 #include <machine/machparam.h>
1483 __enable_execute_stack ()
1486 static unsigned lowest = USRSTACK;
1487 unsigned current = (unsigned) &fp & -NBPG;
1489 if (lowest > current)
1491 unsigned len = lowest - current;
1492 mremap (current, &len, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE);
1496 /* Clear instruction cache in case an old trampoline is in it. */
1499 #endif /* __convex__ */
1503 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1505 #include <sys/mman.h>
1506 #include <sys/types.h>
1507 #include <sys/param.h>
1508 #include <sys/vmmac.h>
1510 /* Modified from the convex -code above.
1511 mremap promises to clear the i-cache. */
1514 __enable_execute_stack ()
1517 if (mprotect (((unsigned int)&fp/PAGSIZ)*PAGSIZ, PAGSIZ,
1518 PROT_READ|PROT_WRITE|PROT_EXEC))
1520 perror ("mprotect in __enable_execute_stack");
1525 #endif /* __pyr__ */
1526 #endif /* L_trampoline */
1530 #include "gbl-ctors.h"
1532 /* Run all the global destructors on exit from the program. */
1535 __do_global_dtors ()
1537 #ifdef DO_GLOBAL_DTORS_BODY
1538 DO_GLOBAL_DTORS_BODY;
1540 unsigned nptrs = (unsigned HOST_WIDE_INT) __DTOR_LIST__[0];
1543 /* Some systems place the number of pointers
1544 in the first word of the table.
1545 On other systems, that word is -1.
1546 In all cases, the table is null-terminated. */
1548 /* If the length is not recorded, count up to the null. */
1550 for (nptrs = 0; __DTOR_LIST__[nptrs + 1] != 0; nptrs++);
1552 /* GNU LD format. */
1553 for (i = nptrs; i >= 1; i--)
1554 __DTOR_LIST__[i] ();
1558 #ifndef INIT_SECTION_ASM_OP
1559 /* Run all the global constructors on entry to the program. */
1562 #define ON_EXIT(a, b)
1564 /* Make sure the exit routine is pulled in to define the globals as
1565 bss symbols, just in case the linker does not automatically pull
1566 bss definitions from the library. */
1568 extern int _exit_dummy_decl;
1569 int *_exit_dummy_ref = &_exit_dummy_decl;
1570 #endif /* ON_EXIT */
1573 __do_global_ctors ()
1575 DO_GLOBAL_CTORS_BODY;
1576 ON_EXIT (__do_global_dtors, 0);
1578 #endif /* no INIT_SECTION_ASM_OP */
1580 #if !defined (INIT_SECTION_ASM_OP) || defined (INVOKE__main)
1581 /* Subroutine called automatically by `main'.
1582 Compiling a global function named `main'
1583 produces an automatic call to this function at the beginning.
1585 For many systems, this routine calls __do_global_ctors.
1586 For systems which support a .init section we use the .init section
1587 to run __do_global_ctors, so we need not do anything here. */
1592 /* Support recursive calls to `main': run initializers just once. */
1593 static int initialized = 0;
1597 __do_global_ctors ();
1600 #endif /* no INIT_SECTION_ASM_OP or INVOKE__main */
1602 #endif /* L__main */
1606 #include "gbl-ctors.h"
1608 /* Provide default definitions for the lists of constructors and
1609 destructors, so that we don't get linker errors. These symbols are
1610 intentionally bss symbols, so that gld and/or collect will provide
1611 the right values. */
1613 /* We declare the lists here with two elements each,
1614 so that they are valid empty lists if no other definition is loaded. */
1615 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
1617 /* After 2.3, try this definition on all systems. */
1618 func_ptr __CTOR_LIST__[2] = {0, 0};
1619 func_ptr __DTOR_LIST__[2] = {0, 0};
1621 func_ptr __CTOR_LIST__[2];
1622 func_ptr __DTOR_LIST__[2];
1624 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
1625 #endif /* L_ctors */
1629 #include "gbl-ctors.h"
1633 /* If we have no known way of registering our own __do_global_dtors
1634 routine so that it will be invoked at program exit time, then we
1635 have to define our own exit routine which will get this to happen. */
1637 extern void __do_global_dtors ();
1638 extern void _cleanup ();
1639 extern volatile void _exit ();
1645 __do_global_dtors ();
1655 int _exit_dummy_decl = 0; /* prevent compiler & linker warnings */
1660 /* In a.out systems, we need to have these dummy constructor and destructor
1661 lists in the library.
1663 When using `collect', the first link will resolve __CTOR_LIST__
1664 and __DTOR_LIST__ to these symbols. We will then run "nm" on the
1665 result, build the correct __CTOR_LIST__ and __DTOR_LIST__, and relink.
1666 Since we don't do the second link if no constructors existed, these
1667 dummies must be fully functional empty lists.
1669 When using `gnu ld', these symbols will be used if there are no
1670 constructors. If there are constructors, the N_SETV symbol defined
1671 by the linker from the N_SETT's in input files will define __CTOR_LIST__
1672 and __DTOR_LIST__ rather than its being allocated as common storage
1673 by the definitions below.
1675 When using a linker that supports constructor and destructor segments,
1676 these definitions will not be used, since crtbegin.o and crtend.o
1677 (from crtstuff.c) will have already defined __CTOR_LIST__ and
1678 __DTOR_LIST__. The crt*.o files are passed directly to the linker
1679 on its command line, by gcc. */
1681 /* The list needs two elements: one is ignored (the old count); the
1682 second is the terminating zero. Since both values are zero, this
1683 declaration is not initialized, and it becomes `common'. */
1686 #include "gbl-ctors.h"
1687 func_ptr __CTOR_LIST__[2];
1691 #include "gbl-ctors.h"
1692 func_ptr __DTOR_LIST__[2];