1 /* More subroutines needed by GCC output code on some machines. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 1989, 1992, 1993, 1994 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 other files,
22 some of which are compiled with GCC, to produce an executable,
23 this library does not by itself cause the resulting executable
24 to be covered by the GNU General Public License.
25 This exception does not however invalidate any other reasons why
26 the executable file might be covered by the GNU General Public License. */
28 /* It is incorrect to include config.h here, because this file is being
29 compiled for the target, and hence definitions concerning only the host
38 /* Don't use `fancy_abort' here even if config.h says to use it. */
43 /* Permit the tm.h file to select the endianness to use just for this
44 file. This is used when the endianness is determined when the
47 #ifndef LIBGCC2_WORDS_BIG_ENDIAN
48 #define LIBGCC2_WORDS_BIG_ENDIAN WORDS_BIG_ENDIAN
51 /* In the first part of this file, we are interfacing to calls generated
52 by the compiler itself. These calls pass values into these routines
53 which have very specific modes (rather than very specific types), and
54 these compiler-generated calls also expect any return values to have
55 very specific modes (rather than very specific types). Thus, we need
56 to avoid using regular C language type names in this part of the file
57 because the sizes for those types can be configured to be anything.
58 Instead we use the following special type names. */
60 typedef unsigned int UQItype __attribute__ ((mode (QI)));
61 typedef int SItype __attribute__ ((mode (SI)));
62 typedef unsigned int USItype __attribute__ ((mode (SI)));
63 typedef int DItype __attribute__ ((mode (DI)));
64 typedef unsigned int UDItype __attribute__ ((mode (DI)));
65 typedef float SFtype __attribute__ ((mode (SF)));
66 typedef float DFtype __attribute__ ((mode (DF)));
67 #if LONG_DOUBLE_TYPE_SIZE == 96
68 typedef float XFtype __attribute__ ((mode (XF)));
70 #if LONG_DOUBLE_TYPE_SIZE == 128
71 typedef float TFtype __attribute__ ((mode (TF)));
75 typedef int word_type __attribute__ ((mode (HI)));
78 typedef int word_type __attribute__ ((mode (SI)));
81 typedef int word_type __attribute__ ((mode (DI)));
84 /* Make sure that we don't accidentally use any normal C language built-in
85 type names in the first part of this file. Instead we want to use *only*
86 the type names defined above. The following macro definitions insure
87 that if we *do* accidentally use some normal C language built-in type name,
88 we will get a syntax error. */
90 #define char bogus_type
91 #define short bogus_type
92 #define int bogus_type
93 #define long bogus_type
94 #define unsigned bogus_type
95 #define float bogus_type
96 #define double bogus_type
98 #define SI_TYPE_SIZE (sizeof (SItype) * BITS_PER_UNIT)
100 /* DIstructs are pairs of SItype values in the order determined by
101 LIBGCC2_WORDS_BIG_ENDIAN. */
103 #if LIBGCC2_WORDS_BIG_ENDIAN
104 struct DIstruct {SItype high, low;};
106 struct DIstruct {SItype low, high;};
109 /* We need this union to unpack/pack DImode values, since we don't have
110 any arithmetic yet. Incoming DImode parameters are stored into the
111 `ll' field, and the unpacked result is read from the struct `s'. */
119 #if defined (L_udivmoddi4) || defined (L_muldi3) || defined (L_udiv_w_sdiv)
121 #include "longlong.h"
123 #endif /* udiv or mul */
125 extern DItype __fixunssfdi (SFtype a);
126 extern DItype __fixunsdfdi (DFtype a);
127 #if LONG_DOUBLE_TYPE_SIZE == 96
128 extern DItype __fixunsxfdi (XFtype a);
130 #if LONG_DOUBLE_TYPE_SIZE == 128
131 extern DItype __fixunstfdi (TFtype a);
134 #if defined (L_negdi2) || defined (L_divdi3) || defined (L_moddi3)
135 #if defined (L_divdi3) || defined (L_moddi3)
148 w.s.high = -uu.s.high - ((USItype) w.s.low > 0);
169 bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
173 w.s.high = (USItype)uu.s.low << -bm;
177 USItype carries = (USItype)uu.s.low >> bm;
178 w.s.low = (USItype)uu.s.low << b;
179 w.s.high = ((USItype)uu.s.high << b) | carries;
201 bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
205 w.s.low = (USItype)uu.s.high >> -bm;
209 USItype carries = (USItype)uu.s.high << bm;
210 w.s.high = (USItype)uu.s.high >> b;
211 w.s.low = ((USItype)uu.s.low >> b) | carries;
233 bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
237 w.s.high = (USItype)uu.s.low << -bm;
241 USItype carries = (USItype)uu.s.low >> bm;
242 w.s.low = (USItype)uu.s.low << b;
243 w.s.high = ((USItype)uu.s.high << b) | carries;
265 bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
268 /* w.s.high = 1..1 or 0..0 */
269 w.s.high = uu.s.high >> (sizeof (SItype) * BITS_PER_UNIT - 1);
270 w.s.low = uu.s.high >> -bm;
274 USItype carries = (USItype)uu.s.high << bm;
275 w.s.high = uu.s.high >> b;
276 w.s.low = ((USItype)uu.s.low >> b) | carries;
291 w.s.low = ffs (uu.s.low);
294 w.s.low = ffs (uu.s.high);
297 w.s.low += BITS_PER_UNIT * sizeof (SItype);
315 w.ll = __umulsidi3 (uu.s.low, vv.s.low);
316 w.s.high += ((USItype) uu.s.low * (USItype) vv.s.high
317 + (USItype) uu.s.high * (USItype) vv.s.low);
325 __udiv_w_sdiv (rp, a1, a0, d)
326 USItype *rp, a1, a0, d;
333 if (a1 < d - a1 - (a0 >> (SI_TYPE_SIZE - 1)))
335 /* dividend, divisor, and quotient are nonnegative */
336 sdiv_qrnnd (q, r, a1, a0, d);
340 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */
341 sub_ddmmss (c1, c0, a1, a0, d >> 1, d << (SI_TYPE_SIZE - 1));
342 /* Divide (c1*2^32 + c0) by d */
343 sdiv_qrnnd (q, r, c1, c0, d);
344 /* Add 2^31 to quotient */
345 q += (USItype) 1 << (SI_TYPE_SIZE - 1);
350 b1 = d >> 1; /* d/2, between 2^30 and 2^31 - 1 */
351 c1 = a1 >> 1; /* A/2 */
352 c0 = (a1 << (SI_TYPE_SIZE - 1)) + (a0 >> 1);
354 if (a1 < b1) /* A < 2^32*b1, so A/2 < 2^31*b1 */
356 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
358 r = 2*r + (a0 & 1); /* Remainder from A/(2*b1) */
375 else if (c1 < b1) /* So 2^31 <= (A/2)/b1 < 2^32 */
378 c0 = ~c0; /* logical NOT */
380 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
382 q = ~q; /* (A/2)/b1 */
385 r = 2*r + (a0 & 1); /* A/(2*b1) */
403 else /* Implies c1 = b1 */
404 { /* Hence a1 = d - 1 = 2*b1 - 1 */
424 static const UQItype __clz_tab[] =
426 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,
427 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,
428 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,
429 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,
430 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,
431 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,
432 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,
433 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,
437 __udivmoddi4 (n, d, rp)
444 USItype d0, d1, n0, n1, n2;
456 #if !UDIV_NEEDS_NORMALIZATION
463 udiv_qrnnd (q0, n0, n1, n0, d0);
466 /* Remainder in n0. */
473 d0 = 1 / d0; /* Divide intentionally by zero. */
475 udiv_qrnnd (q1, n1, 0, n1, d0);
476 udiv_qrnnd (q0, n0, n1, n0, d0);
478 /* Remainder in n0. */
489 #else /* UDIV_NEEDS_NORMALIZATION */
497 count_leading_zeros (bm, d0);
501 /* Normalize, i.e. make the most significant bit of the
505 n1 = (n1 << bm) | (n0 >> (SI_TYPE_SIZE - bm));
509 udiv_qrnnd (q0, n0, n1, n0, d0);
512 /* Remainder in n0 >> bm. */
519 d0 = 1 / d0; /* Divide intentionally by zero. */
521 count_leading_zeros (bm, d0);
525 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
526 conclude (the most significant bit of n1 is set) /\ (the
527 leading quotient digit q1 = 1).
529 This special case is necessary, not an optimization.
530 (Shifts counts of SI_TYPE_SIZE are undefined.) */
539 b = SI_TYPE_SIZE - bm;
543 n1 = (n1 << bm) | (n0 >> b);
546 udiv_qrnnd (q1, n1, n2, n1, d0);
551 udiv_qrnnd (q0, n0, n1, n0, d0);
553 /* Remainder in n0 >> bm. */
563 #endif /* UDIV_NEEDS_NORMALIZATION */
574 /* Remainder in n1n0. */
586 count_leading_zeros (bm, d1);
589 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
590 conclude (the most significant bit of n1 is set) /\ (the
591 quotient digit q0 = 0 or 1).
593 This special case is necessary, not an optimization. */
595 /* The condition on the next line takes advantage of that
596 n1 >= d1 (true due to program flow). */
597 if (n1 > d1 || n0 >= d0)
600 sub_ddmmss (n1, n0, n1, n0, d1, d0);
619 b = SI_TYPE_SIZE - bm;
621 d1 = (d1 << bm) | (d0 >> b);
624 n1 = (n1 << bm) | (n0 >> b);
627 udiv_qrnnd (q0, n1, n2, n1, d1);
628 umul_ppmm (m1, m0, q0, d0);
630 if (m1 > n1 || (m1 == n1 && m0 > n0))
633 sub_ddmmss (m1, m0, m1, m0, d1, d0);
638 /* Remainder in (n1n0 - m1m0) >> bm. */
641 sub_ddmmss (n1, n0, n1, n0, m1, m0);
642 rr.s.low = (n1 << b) | (n0 >> bm);
643 rr.s.high = n1 >> bm;
657 UDItype __udivmoddi4 ();
672 uu.ll = __negdi2 (uu.ll);
675 vv.ll = __negdi2 (vv.ll);
677 w = __udivmoddi4 (uu.ll, vv.ll, (UDItype *) 0);
686 UDItype __udivmoddi4 ();
700 uu.ll = __negdi2 (uu.ll);
702 vv.ll = __negdi2 (vv.ll);
704 (void) __udivmoddi4 (uu.ll, vv.ll, &w);
713 UDItype __udivmoddi4 ();
720 (void) __udivmoddi4 (u, v, &w);
727 UDItype __udivmoddi4 ();
732 return __udivmoddi4 (n, d, (UDItype *) 0);
743 au.ll = a, bu.ll = b;
745 if (au.s.high < bu.s.high)
747 else if (au.s.high > bu.s.high)
749 if ((USItype) au.s.low < (USItype) bu.s.low)
751 else if ((USItype) au.s.low > (USItype) bu.s.low)
764 au.ll = a, bu.ll = b;
766 if ((USItype) au.s.high < (USItype) bu.s.high)
768 else if ((USItype) au.s.high > (USItype) bu.s.high)
770 if ((USItype) au.s.low < (USItype) bu.s.low)
772 else if ((USItype) au.s.low > (USItype) bu.s.low)
778 #if defined(L_fixunstfdi) && (LONG_DOUBLE_TYPE_SIZE == 128)
779 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
780 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
792 /* Compute high word of result, as a flonum. */
793 b = (a / HIGH_WORD_COEFF);
794 /* Convert that to fixed (but not to DItype!),
795 and shift it into the high word. */
798 /* Remove high part from the TFtype, leaving the low part as flonum. */
800 /* Convert that to fixed (but not to DItype!) and add it in.
801 Sometimes A comes out negative. This is significant, since
802 A has more bits than a long int does. */
804 v -= (USItype) (- a);
811 #if defined(L_fixtfdi) && (LONG_DOUBLE_TYPE_SIZE == 128)
817 return - __fixunstfdi (-a);
818 return __fixunstfdi (a);
822 #if defined(L_fixunsxfdi) && (LONG_DOUBLE_TYPE_SIZE == 96)
823 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
824 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
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 XFtype, 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);
855 #if defined(L_fixxfdi) && (LONG_DOUBLE_TYPE_SIZE == 96)
861 return - __fixunsxfdi (-a);
862 return __fixunsxfdi (a);
867 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
868 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
880 /* Compute high word of result, as a flonum. */
881 b = (a / HIGH_WORD_COEFF);
882 /* Convert that to fixed (but not to DItype!),
883 and shift it into the high word. */
886 /* Remove high part from the DFtype, leaving the low part as flonum. */
888 /* Convert that to fixed (but not to DItype!) and add it in.
889 Sometimes A comes out negative. This is significant, since
890 A has more bits than a long int does. */
892 v -= (USItype) (- a);
905 return - __fixunsdfdi (-a);
906 return __fixunsdfdi (a);
911 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
912 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
915 __fixunssfdi (SFtype original_a)
917 /* Convert the SFtype to a DFtype, because that is surely not going
918 to lose any bits. Some day someone else can write a faster version
919 that avoids converting to DFtype, and verify it really works right. */
920 DFtype a = original_a;
927 /* Compute high word of result, as a flonum. */
928 b = (a / HIGH_WORD_COEFF);
929 /* Convert that to fixed (but not to DItype!),
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 DItype!) and add it in.
936 Sometimes A comes out negative. This is significant, since
937 A has more bits than a long int does. */
939 v -= (USItype) (- a);
951 return - __fixunssfdi (-a);
952 return __fixunssfdi (a);
956 #if defined(L_floatdixf) && (LONG_DOUBLE_TYPE_SIZE == 96)
957 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
958 #define HIGH_HALFWORD_COEFF (((UDItype) 1) << (WORD_SIZE / 2))
959 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
971 d = (USItype) (u >> WORD_SIZE);
972 d *= HIGH_HALFWORD_COEFF;
973 d *= HIGH_HALFWORD_COEFF;
974 d += (USItype) (u & (HIGH_WORD_COEFF - 1));
976 return (negate ? -d : d);
980 #if defined(L_floatditf) && (LONG_DOUBLE_TYPE_SIZE == 128)
981 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
982 #define HIGH_HALFWORD_COEFF (((UDItype) 1) << (WORD_SIZE / 2))
983 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
995 d = (USItype) (u >> WORD_SIZE);
996 d *= HIGH_HALFWORD_COEFF;
997 d *= HIGH_HALFWORD_COEFF;
998 d += (USItype) (u & (HIGH_WORD_COEFF - 1));
1000 return (negate ? -d : d);
1005 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
1006 #define HIGH_HALFWORD_COEFF (((UDItype) 1) << (WORD_SIZE / 2))
1007 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
1019 d = (USItype) (u >> WORD_SIZE);
1020 d *= HIGH_HALFWORD_COEFF;
1021 d *= HIGH_HALFWORD_COEFF;
1022 d += (USItype) (u & (HIGH_WORD_COEFF - 1));
1024 return (negate ? -d : d);
1029 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
1030 #define HIGH_HALFWORD_COEFF (((UDItype) 1) << (WORD_SIZE / 2))
1031 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
1032 #define DI_SIZE (sizeof (DItype) * BITS_PER_UNIT)
1033 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
1037 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
1041 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
1056 /* Do the calculation in DFmode
1057 so that we don't lose any of the precision of the high word
1058 while multiplying it. */
1065 /* Protect against double-rounding error.
1066 Represent any low-order bits, that might be truncated in DFmode,
1067 by a bit that won't be lost. The bit can go in anywhere below the
1068 rounding position of the SFmode. A fixed mask and bit position
1069 handles all usual configurations. It doesn't handle the case
1070 of 128-bit DImode, however. */
1071 if (DF_SIZE < DI_SIZE
1072 && DF_SIZE > (DI_SIZE - DF_SIZE + SF_SIZE))
1074 #define REP_BIT ((USItype) 1 << (DI_SIZE - DF_SIZE))
1075 if (u >= ((UDItype) 1 << DF_SIZE))
1077 if ((USItype) u & (REP_BIT - 1))
1081 f = (USItype) (u >> WORD_SIZE);
1082 f *= HIGH_HALFWORD_COEFF;
1083 f *= HIGH_HALFWORD_COEFF;
1084 f += (USItype) (u & (HIGH_WORD_COEFF - 1));
1086 return (SFtype) (negate ? -f : f);
1090 #if defined(L_fixunsxfsi) && LONG_DOUBLE_TYPE_SIZE == 96
1091 #include "glimits.h"
1097 if (a >= - (DFtype) LONG_MIN)
1098 return (SItype) (a + LONG_MIN) - LONG_MIN;
1104 #include "glimits.h"
1110 if (a >= - (DFtype) LONG_MIN)
1111 return (SItype) (a + LONG_MIN) - LONG_MIN;
1117 #include "glimits.h"
1120 __fixunssfsi (SFtype a)
1122 if (a >= - (SFtype) LONG_MIN)
1123 return (SItype) (a + LONG_MIN) - LONG_MIN;
1128 /* From here on down, the routines use normal data types. */
1130 #define SItype bogus_type
1131 #define USItype bogus_type
1132 #define DItype bogus_type
1133 #define UDItype bogus_type
1134 #define SFtype bogus_type
1135 #define DFtype bogus_type
1147 /* Like bcmp except the sign is meaningful.
1148 Reult is negative if S1 is less than S2,
1149 positive if S1 is greater, 0 if S1 and S2 are equal. */
1152 __gcc_bcmp (s1, s2, size)
1153 unsigned char *s1, *s2;
1158 unsigned char c1 = *s1++, c2 = *s2++;
1170 #if defined(__svr4__) || defined(__alliant__)
1174 /* The Alliant needs the added underscore. */
1175 asm (".globl __builtin_saveregs");
1176 asm ("__builtin_saveregs:");
1177 asm (".globl ___builtin_saveregs");
1178 asm ("___builtin_saveregs:");
1180 asm (" andnot 0x0f,%sp,%sp"); /* round down to 16-byte boundary */
1181 asm (" adds -96,%sp,%sp"); /* allocate stack space for reg save
1182 area and also for a new va_list
1184 /* Save all argument registers in the arg reg save area. The
1185 arg reg save area must have the following layout (according
1197 asm (" fst.q %f8, 0(%sp)"); /* save floating regs (f8-f15) */
1198 asm (" fst.q %f12,16(%sp)");
1200 asm (" st.l %r16,32(%sp)"); /* save integer regs (r16-r27) */
1201 asm (" st.l %r17,36(%sp)");
1202 asm (" st.l %r18,40(%sp)");
1203 asm (" st.l %r19,44(%sp)");
1204 asm (" st.l %r20,48(%sp)");
1205 asm (" st.l %r21,52(%sp)");
1206 asm (" st.l %r22,56(%sp)");
1207 asm (" st.l %r23,60(%sp)");
1208 asm (" st.l %r24,64(%sp)");
1209 asm (" st.l %r25,68(%sp)");
1210 asm (" st.l %r26,72(%sp)");
1211 asm (" st.l %r27,76(%sp)");
1213 asm (" adds 80,%sp,%r16"); /* compute the address of the new
1214 va_list structure. Put in into
1215 r16 so that it will be returned
1218 /* Initialize all fields of the new va_list structure. This
1219 structure looks like:
1222 unsigned long ireg_used;
1223 unsigned long freg_used;
1229 asm (" st.l %r0, 0(%r16)"); /* nfixed */
1230 asm (" st.l %r0, 4(%r16)"); /* nfloating */
1231 asm (" st.l %sp, 8(%r16)"); /* __va_ctl points to __va_struct. */
1232 asm (" bri %r1"); /* delayed return */
1233 asm (" st.l %r28,12(%r16)"); /* pointer to overflow args */
1235 #else /* not __svr4__ */
1236 #if defined(__PARAGON__)
1238 * we'll use SVR4-ish varargs but need SVR3.2 assembler syntax,
1239 * and we stand a better chance of hooking into libraries
1240 * compiled by PGI. [andyp@ssd.intel.com]
1244 asm (".globl __builtin_saveregs");
1245 asm ("__builtin_saveregs:");
1246 asm (".globl ___builtin_saveregs");
1247 asm ("___builtin_saveregs:");
1249 asm (" andnot 0x0f,sp,sp"); /* round down to 16-byte boundary */
1250 asm (" adds -96,sp,sp"); /* allocate stack space for reg save
1251 area and also for a new va_list
1253 /* Save all argument registers in the arg reg save area. The
1254 arg reg save area must have the following layout (according
1266 asm (" fst.q f8, 0(sp)");
1267 asm (" fst.q f12,16(sp)");
1268 asm (" st.l r16,32(sp)");
1269 asm (" st.l r17,36(sp)");
1270 asm (" st.l r18,40(sp)");
1271 asm (" st.l r19,44(sp)");
1272 asm (" st.l r20,48(sp)");
1273 asm (" st.l r21,52(sp)");
1274 asm (" st.l r22,56(sp)");
1275 asm (" st.l r23,60(sp)");
1276 asm (" st.l r24,64(sp)");
1277 asm (" st.l r25,68(sp)");
1278 asm (" st.l r26,72(sp)");
1279 asm (" st.l r27,76(sp)");
1281 asm (" adds 80,sp,r16"); /* compute the address of the new
1282 va_list structure. Put in into
1283 r16 so that it will be returned
1286 /* Initialize all fields of the new va_list structure. This
1287 structure looks like:
1290 unsigned long ireg_used;
1291 unsigned long freg_used;
1297 asm (" st.l r0, 0(r16)"); /* nfixed */
1298 asm (" st.l r0, 4(r16)"); /* nfloating */
1299 asm (" st.l sp, 8(r16)"); /* __va_ctl points to __va_struct. */
1300 asm (" bri r1"); /* delayed return */
1301 asm (" st.l r28,12(r16)"); /* pointer to overflow args */
1302 #else /* not __PARAGON__ */
1306 asm (".globl ___builtin_saveregs");
1307 asm ("___builtin_saveregs:");
1308 asm (" mov sp,r30");
1309 asm (" andnot 0x0f,sp,sp");
1310 asm (" adds -96,sp,sp"); /* allocate sufficient space on the stack */
1312 /* Fill in the __va_struct. */
1313 asm (" st.l r16, 0(sp)"); /* save integer regs (r16-r27) */
1314 asm (" st.l r17, 4(sp)"); /* int fixed[12] */
1315 asm (" st.l r18, 8(sp)");
1316 asm (" st.l r19,12(sp)");
1317 asm (" st.l r20,16(sp)");
1318 asm (" st.l r21,20(sp)");
1319 asm (" st.l r22,24(sp)");
1320 asm (" st.l r23,28(sp)");
1321 asm (" st.l r24,32(sp)");
1322 asm (" st.l r25,36(sp)");
1323 asm (" st.l r26,40(sp)");
1324 asm (" st.l r27,44(sp)");
1326 asm (" fst.q f8, 48(sp)"); /* save floating regs (f8-f15) */
1327 asm (" fst.q f12,64(sp)"); /* int floating[8] */
1329 /* Fill in the __va_ctl. */
1330 asm (" st.l sp, 80(sp)"); /* __va_ctl points to __va_struct. */
1331 asm (" st.l r28,84(sp)"); /* pointer to more args */
1332 asm (" st.l r0, 88(sp)"); /* nfixed */
1333 asm (" st.l r0, 92(sp)"); /* nfloating */
1335 asm (" adds 80,sp,r16"); /* return address of the __va_ctl. */
1337 asm (" mov r30,sp");
1338 /* recover stack and pass address to start
1340 #endif /* not __PARAGON__ */
1341 #endif /* not __svr4__ */
1342 #else /* not __i860__ */
1344 asm (".global __builtin_saveregs");
1345 asm ("__builtin_saveregs:");
1346 asm (".global ___builtin_saveregs");
1347 asm ("___builtin_saveregs:");
1348 #ifdef NEED_PROC_COMMAND
1351 asm ("st %i0,[%fp+68]");
1352 asm ("st %i1,[%fp+72]");
1353 asm ("st %i2,[%fp+76]");
1354 asm ("st %i3,[%fp+80]");
1355 asm ("st %i4,[%fp+84]");
1357 asm ("st %i5,[%fp+88]");
1358 #ifdef NEED_TYPE_COMMAND
1359 asm (".type __builtin_saveregs,#function");
1360 asm (".size __builtin_saveregs,.-__builtin_saveregs");
1362 #else /* not __sparc__ */
1363 #if defined(__MIPSEL__) | defined(__R3000__) | defined(__R2000__) | defined(__mips__)
1366 asm (" .ent __builtin_saveregs");
1367 asm (" .globl __builtin_saveregs");
1368 asm ("__builtin_saveregs:");
1369 asm (" sw $4,0($30)");
1370 asm (" sw $5,4($30)");
1371 asm (" sw $6,8($30)");
1372 asm (" sw $7,12($30)");
1374 asm (" .end __builtin_saveregs");
1375 #else /* not __mips__, etc. */
1378 __builtin_saveregs ()
1383 #endif /* not __mips__ */
1384 #endif /* not __sparc__ */
1385 #endif /* not __i860__ */
1389 #ifndef inhibit_libc
1391 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1393 /* This is used by the `assert' macro. */
1395 __eprintf (string, expression, line, filename)
1397 const char *expression;
1399 const char *filename;
1401 fprintf (stderr, string, expression, line, filename);
1411 /* Structure emitted by -a */
1415 const char *filename;
1419 const unsigned long *addresses;
1421 /* Older GCC's did not emit these fields. */
1423 const char **functions;
1424 const long *line_nums;
1425 const char **filenames;
1428 #ifdef BLOCK_PROFILER_CODE
1431 #ifndef inhibit_libc
1433 /* Simple minded basic block profiling output dumper for
1434 systems that don't provde tcov support. At present,
1435 it requires atexit and stdio. */
1437 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1442 extern void atexit (void (*) (void));
1443 #define ON_EXIT(FUNC,ARG) atexit ((FUNC))
1446 extern void on_exit (void*, void*);
1447 #define ON_EXIT(FUNC,ARG) on_exit ((FUNC), (ARG))
1451 static struct bb *bb_head = (struct bb *)0;
1453 /* Return the number of digits needed to print a value */
1454 /* __inline__ */ static int num_digits (long value, int base)
1456 int minus = (value < 0 && base != 16);
1457 unsigned long v = (minus) ? -value : value;
1471 __bb_exit_func (void)
1473 FILE *file = fopen ("bb.out", "a");
1483 /* This is somewhat type incorrect, but it avoids worrying about
1484 exactly where time.h is included from. It should be ok unless
1485 a void * differs from other pointer formats, or if sizeof(long)
1486 is < sizeof (time_t). It would be nice if we could assume the
1487 use of rationale standards here. */
1489 time((void *) &time_value);
1490 fprintf (file, "Basic block profiling finished on %s\n", ctime ((void *) &time_value));
1492 /* We check the length field explicitly in order to allow compatibility
1493 with older GCC's which did not provide it. */
1495 for (ptr = bb_head; ptr != (struct bb *)0; ptr = ptr->next)
1498 int func_p = (ptr->nwords >= sizeof (struct bb) && ptr->nwords <= 1000);
1499 int line_p = (func_p && ptr->line_nums);
1500 int file_p = (func_p && ptr->filenames);
1501 long ncounts = ptr->ncounts;
1507 int blk_len = num_digits (ncounts, 10);
1512 fprintf (file, "File %s, %ld basic blocks \n\n",
1513 ptr->filename, ncounts);
1515 /* Get max values for each field. */
1516 for (i = 0; i < ncounts; i++)
1521 if (cnt_max < ptr->counts[i])
1522 cnt_max = ptr->counts[i];
1524 if (addr_max < ptr->addresses[i])
1525 addr_max = ptr->addresses[i];
1527 if (line_p && line_max < ptr->line_nums[i])
1528 line_max = ptr->line_nums[i];
1532 p = (ptr->functions[i]) ? (ptr->functions[i]) : "<none>";
1540 p = (ptr->filenames[i]) ? (ptr->filenames[i]) : "<none>";
1547 addr_len = num_digits (addr_max, 16);
1548 cnt_len = num_digits (cnt_max, 10);
1549 line_len = num_digits (line_max, 10);
1551 /* Now print out the basic block information. */
1552 for (i = 0; i < ncounts; i++)
1555 " Block #%*d: executed %*ld time(s) address= 0x%.*lx",
1557 cnt_len, ptr->counts[i],
1558 addr_len, ptr->addresses[i]);
1561 fprintf (file, " function= %-*s", func_len,
1562 (ptr->functions[i]) ? ptr->functions[i] : "<none>");
1565 fprintf (file, " line= %*ld", line_len, ptr->line_nums[i]);
1568 fprintf (file, " file= %s",
1569 (ptr->filenames[i]) ? ptr->filenames[i] : "<none>");
1571 fprintf (file, "\n");
1574 fprintf (file, "\n");
1578 fprintf (file, "\n\n");
1584 __bb_init_func (struct bb *blocks)
1586 /* User is supposed to check whether the first word is non-0,
1587 but just in case.... */
1589 if (blocks->zero_word)
1593 /* Initialize destructor. */
1595 ON_EXIT (__bb_exit_func, 0);
1598 /* Set up linked list. */
1599 blocks->zero_word = 1;
1600 blocks->next = bb_head;
1604 #endif /* not inhibit_libc */
1605 #endif /* not BLOCK_PROFILER_CODE */
1608 /* Default free-store management functions for C++, per sections 12.5 and
1609 17.3.3 of the Working Paper. */
1612 /* operator new (size_t), described in 17.3.3.5. This function is used by
1613 C++ programs to allocate a block of memory to hold a single object. */
1615 typedef void (*vfp)(void);
1616 extern vfp __new_handler;
1619 __builtin_new (size_t sz)
1623 /* malloc (0) is unpredictable; avoid it. */
1626 p = (void *) malloc (sz);
1629 (*__new_handler) ();
1630 p = (void *) malloc (sz);
1635 #endif /* L_op_new */
1638 /* void * operator new [] (size_t), described in 17.3.3.6. This function
1639 is used by C++ programs to allocate a block of memory for an array. */
1641 extern void * __builtin_new (size_t);
1644 __builtin_vec_new (size_t sz)
1646 return __builtin_new (sz);
1648 #endif /* L_op_vnew */
1650 #ifdef L_new_handler
1651 /* set_new_handler (fvoid_t *) and the default new handler, described in
1652 17.3.3.2 and 17.3.3.5. These functions define the result of a failure
1653 to allocate the amount of memory requested from operator new or new []. */
1655 #ifndef inhibit_libc
1656 /* This gets us __GNU_LIBRARY__. */
1657 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1660 #ifdef __GNU_LIBRARY__
1661 /* Avoid forcing the library's meaning of `write' on the user program
1662 by using the "internal" name (for use within the library) */
1663 #define write(fd, buf, n) __write((fd), (buf), (n))
1665 #endif /* inhibit_libc */
1667 typedef void (*vfp)(void);
1668 void __default_new_handler (void);
1670 vfp __new_handler = __default_new_handler;
1673 set_new_handler (vfp handler)
1677 prev_handler = __new_handler;
1678 if (handler == 0) handler = __default_new_handler;
1679 __new_handler = handler;
1680 return prev_handler;
1683 #define MESSAGE "Virtual memory exceeded in `new'\n"
1686 __default_new_handler ()
1688 /* don't use fprintf (stderr, ...) because it may need to call malloc. */
1689 /* This should really print the name of the program, but that is hard to
1690 do. We need a standard, clean way to get at the name. */
1691 write (2, MESSAGE, sizeof (MESSAGE));
1692 /* don't call exit () because that may call global destructors which
1693 may cause a loop. */
1699 /* operator delete (void *), described in 17.3.3.3. This function is used
1700 by C++ programs to return to the free store a block of memory allocated
1701 as a single object. */
1704 __builtin_delete (void *ptr)
1712 /* operator delete [] (void *), described in 17.3.3.4. This function is
1713 used by C++ programs to return to the free store a block of memory
1714 allocated as an array. */
1716 extern void __builtin_delete (void *);
1719 __builtin_vec_delete (void *ptr)
1721 __builtin_delete (ptr);
1725 /* End of C++ free-store management functions */
1728 unsigned int __shtab[] = {
1729 0x00000001, 0x00000002, 0x00000004, 0x00000008,
1730 0x00000010, 0x00000020, 0x00000040, 0x00000080,
1731 0x00000100, 0x00000200, 0x00000400, 0x00000800,
1732 0x00001000, 0x00002000, 0x00004000, 0x00008000,
1733 0x00010000, 0x00020000, 0x00040000, 0x00080000,
1734 0x00100000, 0x00200000, 0x00400000, 0x00800000,
1735 0x01000000, 0x02000000, 0x04000000, 0x08000000,
1736 0x10000000, 0x20000000, 0x40000000, 0x80000000
1740 #ifdef L_clear_cache
1741 /* Clear part of an instruction cache. */
1743 #define INSN_CACHE_PLANE_SIZE (INSN_CACHE_SIZE / INSN_CACHE_DEPTH)
1746 __clear_cache (beg, end)
1749 #ifdef CLEAR_INSN_CACHE
1750 CLEAR_INSN_CACHE (beg, end);
1752 #ifdef INSN_CACHE_SIZE
1753 static char array[INSN_CACHE_SIZE + INSN_CACHE_PLANE_SIZE + INSN_CACHE_LINE_WIDTH];
1754 static int initialized = 0;
1758 typedef (*function_ptr) ();
1760 #if (INSN_CACHE_SIZE / INSN_CACHE_LINE_WIDTH) < 16
1761 /* It's cheaper to clear the whole cache.
1762 Put in a series of jump instructions so that calling the beginning
1763 of the cache will clear the whole thing. */
1767 int ptr = (((int) array + INSN_CACHE_LINE_WIDTH - 1)
1768 & -INSN_CACHE_LINE_WIDTH);
1769 int end_ptr = ptr + INSN_CACHE_SIZE;
1771 while (ptr < end_ptr)
1773 *(INSTRUCTION_TYPE *)ptr
1774 = JUMP_AHEAD_INSTRUCTION + INSN_CACHE_LINE_WIDTH;
1775 ptr += INSN_CACHE_LINE_WIDTH;
1777 *(INSTRUCTION_TYPE *)(ptr - INSN_CACHE_LINE_WIDTH) = RETURN_INSTRUCTION;
1782 /* Call the beginning of the sequence. */
1783 (((function_ptr) (((int) array + INSN_CACHE_LINE_WIDTH - 1)
1784 & -INSN_CACHE_LINE_WIDTH))
1787 #else /* Cache is large. */
1791 int ptr = (((int) array + INSN_CACHE_LINE_WIDTH - 1)
1792 & -INSN_CACHE_LINE_WIDTH);
1794 while (ptr < (int) array + sizeof array)
1796 *(INSTRUCTION_TYPE *)ptr = RETURN_INSTRUCTION;
1797 ptr += INSN_CACHE_LINE_WIDTH;
1803 /* Find the location in array that occupies the same cache line as BEG. */
1805 offset = ((int) beg & -INSN_CACHE_LINE_WIDTH) & (INSN_CACHE_PLANE_SIZE - 1);
1806 start_addr = (((int) (array + INSN_CACHE_PLANE_SIZE - 1)
1807 & -INSN_CACHE_PLANE_SIZE)
1810 /* Compute the cache alignment of the place to stop clearing. */
1811 #if 0 /* This is not needed for gcc's purposes. */
1812 /* If the block to clear is bigger than a cache plane,
1813 we clear the entire cache, and OFFSET is already correct. */
1814 if (end < beg + INSN_CACHE_PLANE_SIZE)
1816 offset = (((int) (end + INSN_CACHE_LINE_WIDTH - 1)
1817 & -INSN_CACHE_LINE_WIDTH)
1818 & (INSN_CACHE_PLANE_SIZE - 1));
1820 #if INSN_CACHE_DEPTH > 1
1821 end_addr = (start_addr & -INSN_CACHE_PLANE_SIZE) + offset;
1822 if (end_addr <= start_addr)
1823 end_addr += INSN_CACHE_PLANE_SIZE;
1825 for (plane = 0; plane < INSN_CACHE_DEPTH; plane++)
1827 int addr = start_addr + plane * INSN_CACHE_PLANE_SIZE;
1828 int stop = end_addr + plane * INSN_CACHE_PLANE_SIZE;
1830 while (addr != stop)
1832 /* Call the return instruction at ADDR. */
1833 ((function_ptr) addr) ();
1835 addr += INSN_CACHE_LINE_WIDTH;
1838 #else /* just one plane */
1841 /* Call the return instruction at START_ADDR. */
1842 ((function_ptr) start_addr) ();
1844 start_addr += INSN_CACHE_LINE_WIDTH;
1846 while ((start_addr % INSN_CACHE_SIZE) != offset);
1847 #endif /* just one plane */
1848 #endif /* Cache is large */
1849 #endif /* Cache exists */
1850 #endif /* CLEAR_INSN_CACHE */
1853 #endif /* L_clear_cache */
1857 /* Jump to a trampoline, loading the static chain address. */
1859 #ifdef TRANSFER_FROM_TRAMPOLINE
1860 TRANSFER_FROM_TRAMPOLINE
1863 #if defined (NeXT) && defined (__MACH__)
1865 /* Make stack executable so we can call trampolines on stack.
1866 This is called from INITIALIZE_TRAMPOLINE in next.h. */
1870 #include <mach/mach.h>
1874 __enable_execute_stack (addr)
1878 char *eaddr = addr + TRAMPOLINE_SIZE;
1879 vm_address_t a = (vm_address_t) addr;
1881 /* turn on execute access on stack */
1882 r = vm_protect (task_self (), a, TRAMPOLINE_SIZE, FALSE, VM_PROT_ALL);
1883 if (r != KERN_SUCCESS)
1885 mach_error("vm_protect VM_PROT_ALL", r);
1889 /* We inline the i-cache invalidation for speed */
1891 #ifdef CLEAR_INSN_CACHE
1892 CLEAR_INSN_CACHE (addr, eaddr);
1894 __clear_cache ((int) addr, (int) eaddr);
1898 #endif /* defined (NeXT) && defined (__MACH__) */
1902 /* Make stack executable so we can call trampolines on stack.
1903 This is called from INITIALIZE_TRAMPOLINE in convex.h. */
1905 #include <sys/mman.h>
1906 #include <sys/vmparam.h>
1907 #include <machine/machparam.h>
1910 __enable_execute_stack ()
1913 static unsigned lowest = USRSTACK;
1914 unsigned current = (unsigned) &fp & -NBPG;
1916 if (lowest > current)
1918 unsigned len = lowest - current;
1919 mremap (current, &len, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE);
1923 /* Clear instruction cache in case an old trampoline is in it. */
1926 #endif /* __convex__ */
1930 /* Modified from the convex -code above. */
1932 #include <sys/param.h>
1934 #include <sys/m88kbcs.h>
1937 __enable_execute_stack ()
1940 static unsigned long lowest = USRSTACK;
1941 unsigned long current = (unsigned long) &save_errno & -NBPC;
1943 /* Ignore errno being set. memctl sets errno to EINVAL whenever the
1944 address is seen as 'negative'. That is the case with the stack. */
1947 if (lowest > current)
1949 unsigned len=lowest-current;
1950 memctl(current,len,MCT_TEXT);
1954 memctl(current,NBPC,MCT_TEXT);
1958 #endif /* __DOLPHIN__ */
1962 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1964 #include <sys/mman.h>
1965 #include <sys/types.h>
1966 #include <sys/param.h>
1967 #include <sys/vmmac.h>
1969 /* Modified from the convex -code above.
1970 mremap promises to clear the i-cache. */
1973 __enable_execute_stack ()
1976 if (mprotect (((unsigned int)&fp/PAGSIZ)*PAGSIZ, PAGSIZ,
1977 PROT_READ|PROT_WRITE|PROT_EXEC))
1979 perror ("mprotect in __enable_execute_stack");
1984 #endif /* __pyr__ */
1985 #endif /* L_trampoline */
1989 #include "gbl-ctors.h"
1990 /* Some systems use __main in a way incompatible with its use in gcc, in these
1991 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
1992 give the same symbol without quotes for an alternative entry point. You
1993 must define both, or niether. */
1995 #define NAME__MAIN "__main"
1996 #define SYMBOL__MAIN __main
1999 #if !defined (INIT_SECTION_ASM_OP) || !defined (OBJECT_FORMAT_ELF)
2000 /* Run all the global destructors on exit from the program. */
2003 __do_global_dtors ()
2005 #ifdef DO_GLOBAL_DTORS_BODY
2006 DO_GLOBAL_DTORS_BODY;
2009 for (p = __DTOR_LIST__ + 1; *p; )
2015 #ifndef INIT_SECTION_ASM_OP
2016 /* Run all the global constructors on entry to the program. */
2019 #define ON_EXIT(a, b)
2021 /* Make sure the exit routine is pulled in to define the globals as
2022 bss symbols, just in case the linker does not automatically pull
2023 bss definitions from the library. */
2025 extern int _exit_dummy_decl;
2026 int *_exit_dummy_ref = &_exit_dummy_decl;
2027 #endif /* ON_EXIT */
2030 __do_global_ctors ()
2032 DO_GLOBAL_CTORS_BODY;
2033 ON_EXIT (__do_global_dtors, 0);
2035 #endif /* no INIT_SECTION_ASM_OP */
2037 #if !defined (INIT_SECTION_ASM_OP) || defined (INVOKE__main)
2038 /* Subroutine called automatically by `main'.
2039 Compiling a global function named `main'
2040 produces an automatic call to this function at the beginning.
2042 For many systems, this routine calls __do_global_ctors.
2043 For systems which support a .init section we use the .init section
2044 to run __do_global_ctors, so we need not do anything here. */
2049 /* Support recursive calls to `main': run initializers just once. */
2050 static int initialized = 0;
2054 __do_global_ctors ();
2057 #endif /* no INIT_SECTION_ASM_OP or INVOKE__main */
2059 #endif /* L__main */
2063 #include "gbl-ctors.h"
2065 /* Provide default definitions for the lists of constructors and
2066 destructors, so that we don't get linker errors. These symbols are
2067 intentionally bss symbols, so that gld and/or collect will provide
2068 the right values. */
2070 /* We declare the lists here with two elements each,
2071 so that they are valid empty lists if no other definition is loaded. */
2072 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
2074 /* After 2.3, try this definition on all systems. */
2075 func_ptr __CTOR_LIST__[2] = {0, 0};
2076 func_ptr __DTOR_LIST__[2] = {0, 0};
2078 func_ptr __CTOR_LIST__[2];
2079 func_ptr __DTOR_LIST__[2];
2081 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
2082 #endif /* L_ctors */
2086 #include "gbl-ctors.h"
2090 /* If we have no known way of registering our own __do_global_dtors
2091 routine so that it will be invoked at program exit time, then we
2092 have to define our own exit routine which will get this to happen. */
2094 extern void __do_global_dtors ();
2095 extern void _cleanup ();
2096 extern void _exit () __attribute__ ((noreturn));
2102 __do_global_dtors ();
2112 int _exit_dummy_decl = 0; /* prevent compiler & linker warnings */
2121 void *exception_handler;
2124 struct exception_table_node {
2125 exception_table *table;
2128 struct exception_table_node *next;
2131 static int except_table_pos = 0;
2132 static void *except_pc = (void *)0;
2133 static struct exception_table_node *exception_table_list = 0;
2135 static exception_table *
2136 find_exception_table (pc)
2139 register struct exception_table_node *table = exception_table_list;
2140 for ( ; table != 0; table = table->next)
2142 if (table->start <= pc && table->end > pc)
2143 return table->table;
2148 /* this routine takes a pc, and the address of the exception handler associated
2149 with the closest exception table handler entry associated with that PC,
2150 or 0 if there are no table entries the PC fits in. The algorithm works
2151 something like this:
2153 while(current_entry exists) {
2154 if(current_entry.start < pc )
2155 current_entry = next_entry;
2157 if(prev_entry.start <= pc && prev_entry.end > pc) {
2158 save pointer to prev_entry;
2159 return prev_entry.exception_handler;
2166 Assuming a correctly sorted table (ascending order) this routine should
2167 return the tighest match...
2169 In the advent of a tie, we have to give the last entry, as it represents
2175 __find_first_exception_table_match(pc)
2178 exception_table *table = find_exception_table (pc);
2184 printf("find_first_exception_table_match(): pc = %x!\n",pc);
2190 /* We can't do this yet, as we don't know that the table is sorted. */
2193 if (table[pos].start > except_pc)
2194 /* found the first table[pos].start > except_pc, so the previous
2195 entry better be the one we want! */
2197 } while(table[pos].exception_handler != (void*)-1);
2200 if (table[pos].start <= except_pc && table[pos].end > except_pc)
2202 except_table_pos = pos;
2204 printf("find_first_eh_table_match(): found match: %x\n",table[pos].exception_handler);
2206 return table[pos].exception_handler;
2209 while (table[++pos].exception_handler != (void*)-1) {
2210 if (table[pos].start <= except_pc && table[pos].end > except_pc)
2212 /* This can apply. Make sure it is better or as good as the previous
2214 /* The best one ends first. */
2215 if (best == 0 || (table[pos].end <= table[best].end
2216 /* The best one starts last. */
2217 && table[pos].start >= table[best].start))
2222 return table[best].exception_handler;
2226 printf("find_first_eh_table_match(): else: returning NULL!\n");
2232 __throw_type_match (const char *catch_type, const char *throw_type)
2235 printf("__throw_type_match (): catch_type = %s, throw_type = %s\n",
2236 catch_type, throw_type);
2238 return strcmp (catch_type, throw_type);
2242 __register_exceptions (exception_table *table)
2244 struct exception_table_node *node = (struct exception_table_node*)
2245 malloc (sizeof (struct exception_table_node));
2246 exception_table *range = table + 1;
2247 node->table = table;
2249 /* This look can be optimized away either if the table
2250 is sorted, or if we pass in extra parameters. */
2251 node->start = range->start;
2252 node->end = range->end;
2253 for (range++ ; range->start != (void*)(-1); range++)
2255 if (range->start < node->start)
2256 node->start = range->start;
2257 if (range->end > node->end)
2258 node->end = range->end;
2261 node->next = exception_table_list;
2262 exception_table_list = node;
2267 __unwind_function(void *ptr)
2269 asm("movl 8(%esp),%ecx");
2270 /* Undo current frame */
2271 asm("movl %ebp,%esp");
2273 asm("# like ret, but stay here");
2274 asm("addl $4,%esp");
2276 /* Now, undo previous frame. */
2277 /* This is a test routine, as we have to dynamically probe to find out
2278 what to pop for certain, this is just a guess. */
2279 asm("leal -16(%ebp),%esp");
2280 asm("pop %eax # really for popl %ebx");
2281 asm("pop %eax # really for popl %esi");
2282 asm("pop %eax # really for popl %edi");
2283 asm("movl %ebp,%esp");
2286 asm("movl %ecx,0(%esp)");
2293 #define MESSAGE "pure virtual method called\n"
2297 write (2, MESSAGE, sizeof (MESSAGE) - 1);