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 /* In the first part of this file, we are interfacing to calls generated
44 by the compiler itself. These calls pass values into these routines
45 which have very specific modes (rather than very specific types), and
46 these compiler-generated calls also expect any return values to have
47 very specific modes (rather than very specific types). Thus, we need
48 to avoid using regular C language type names in this part of the file
49 because the sizes for those types can be configured to be anything.
50 Instead we use the following special type names. */
52 typedef unsigned int UQItype
__attribute__ ((mode (QI
)));
53 typedef int SItype
__attribute__ ((mode (SI
)));
54 typedef unsigned int USItype
__attribute__ ((mode (SI
)));
55 typedef int DItype
__attribute__ ((mode (DI
)));
56 typedef unsigned int UDItype
__attribute__ ((mode (DI
)));
57 typedef float SFtype
__attribute__ ((mode (SF
)));
58 typedef float DFtype
__attribute__ ((mode (DF
)));
59 #if LONG_DOUBLE_TYPE_SIZE == 96
60 typedef float XFtype
__attribute__ ((mode (XF
)));
62 #if LONG_DOUBLE_TYPE_SIZE == 128
63 typedef float TFtype
__attribute__ ((mode (TF
)));
67 typedef int word_type
__attribute__ ((mode (HI
)));
70 typedef int word_type
__attribute__ ((mode (SI
)));
73 typedef int word_type
__attribute__ ((mode (DI
)));
76 /* Make sure that we don't accidentally use any normal C language built-in
77 type names in the first part of this file. Instead we want to use *only*
78 the type names defined above. The following macro definitions insure
79 that if we *do* accidentally use some normal C language built-in type name,
80 we will get a syntax error. */
82 #define char bogus_type
83 #define short bogus_type
84 #define int bogus_type
85 #define long bogus_type
86 #define unsigned bogus_type
87 #define float bogus_type
88 #define double bogus_type
90 #define SI_TYPE_SIZE (sizeof (SItype) * BITS_PER_UNIT)
92 /* DIstructs are pairs of SItype values in the order determined by
96 struct DIstruct
{SItype high
, low
;};
98 struct DIstruct
{SItype low
, high
;};
101 /* We need this union to unpack/pack DImode values, since we don't have
102 any arithmetic yet. Incoming DImode parameters are stored into the
103 `ll' field, and the unpacked result is read from the struct `s'. */
111 #if defined (L_udivmoddi4) || defined (L_muldi3) || defined (L_udiv_w_sdiv)
113 #include "longlong.h"
115 #endif /* udiv or mul */
117 extern DItype
__fixunssfdi (SFtype a
);
118 extern DItype
__fixunsdfdi (DFtype a
);
119 #if LONG_DOUBLE_TYPE_SIZE == 96
120 extern DItype
__fixunsxfdi (XFtype a
);
122 #if LONG_DOUBLE_TYPE_SIZE == 128
123 extern DItype
__fixunstfdi (TFtype a
);
126 #if defined (L_negdi2) || defined (L_divdi3) || defined (L_moddi3)
127 #if defined (L_divdi3) || defined (L_moddi3)
140 w
.s
.high
= -uu
.s
.high
- ((USItype
) w
.s
.low
> 0);
161 bm
= (sizeof (SItype
) * BITS_PER_UNIT
) - b
;
165 w
.s
.high
= (USItype
)uu
.s
.low
<< -bm
;
169 USItype carries
= (USItype
)uu
.s
.low
>> bm
;
170 w
.s
.low
= (USItype
)uu
.s
.low
<< b
;
171 w
.s
.high
= ((USItype
)uu
.s
.high
<< b
) | carries
;
193 bm
= (sizeof (SItype
) * BITS_PER_UNIT
) - b
;
197 w
.s
.low
= (USItype
)uu
.s
.high
>> -bm
;
201 USItype carries
= (USItype
)uu
.s
.high
<< bm
;
202 w
.s
.high
= (USItype
)uu
.s
.high
>> b
;
203 w
.s
.low
= ((USItype
)uu
.s
.low
>> b
) | carries
;
225 bm
= (sizeof (SItype
) * BITS_PER_UNIT
) - b
;
229 w
.s
.high
= (USItype
)uu
.s
.low
<< -bm
;
233 USItype carries
= (USItype
)uu
.s
.low
>> bm
;
234 w
.s
.low
= (USItype
)uu
.s
.low
<< b
;
235 w
.s
.high
= ((USItype
)uu
.s
.high
<< b
) | carries
;
257 bm
= (sizeof (SItype
) * BITS_PER_UNIT
) - b
;
260 /* w.s.high = 1..1 or 0..0 */
261 w
.s
.high
= uu
.s
.high
>> (sizeof (SItype
) * BITS_PER_UNIT
- 1);
262 w
.s
.low
= uu
.s
.high
>> -bm
;
266 USItype carries
= (USItype
)uu
.s
.high
<< bm
;
267 w
.s
.high
= uu
.s
.high
>> b
;
268 w
.s
.low
= ((USItype
)uu
.s
.low
>> b
) | carries
;
283 w
.s
.low
= ffs (uu
.s
.low
);
286 w
.s
.low
= ffs (uu
.s
.high
);
289 w
.s
.low
+= BITS_PER_UNIT
* sizeof (SItype
);
307 w
.ll
= __umulsidi3 (uu
.s
.low
, vv
.s
.low
);
308 w
.s
.high
+= ((USItype
) uu
.s
.low
* (USItype
) vv
.s
.high
309 + (USItype
) uu
.s
.high
* (USItype
) vv
.s
.low
);
317 __udiv_w_sdiv (rp
, a1
, a0
, d
)
318 USItype
*rp
, a1
, a0
, d
;
325 if (a1
< d
- a1
- (a0
>> (SI_TYPE_SIZE
- 1)))
327 /* dividend, divisor, and quotient are nonnegative */
328 sdiv_qrnnd (q
, r
, a1
, a0
, d
);
332 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */
333 sub_ddmmss (c1
, c0
, a1
, a0
, d
>> 1, d
<< (SI_TYPE_SIZE
- 1));
334 /* Divide (c1*2^32 + c0) by d */
335 sdiv_qrnnd (q
, r
, c1
, c0
, d
);
336 /* Add 2^31 to quotient */
337 q
+= (USItype
) 1 << (SI_TYPE_SIZE
- 1);
342 b1
= d
>> 1; /* d/2, between 2^30 and 2^31 - 1 */
343 c1
= a1
>> 1; /* A/2 */
344 c0
= (a1
<< (SI_TYPE_SIZE
- 1)) + (a0
>> 1);
346 if (a1
< b1
) /* A < 2^32*b1, so A/2 < 2^31*b1 */
348 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
350 r
= 2*r
+ (a0
& 1); /* Remainder from A/(2*b1) */
367 else if (c1
< b1
) /* So 2^31 <= (A/2)/b1 < 2^32 */
370 c0
= ~c0
; /* logical NOT */
372 sdiv_qrnnd (q
, r
, c1
, c0
, b1
); /* (A/2) / (d/2) */
374 q
= ~q
; /* (A/2)/b1 */
377 r
= 2*r
+ (a0
& 1); /* A/(2*b1) */
395 else /* Implies c1 = b1 */
396 { /* Hence a1 = d - 1 = 2*b1 - 1 */
416 static const UQItype __clz_tab
[] =
418 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,
419 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,
420 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,
421 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,
422 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,
423 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,
424 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,
425 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,
429 __udivmoddi4 (n
, d
, rp
)
436 USItype d0
, d1
, n0
, n1
, n2
;
448 #if !UDIV_NEEDS_NORMALIZATION
455 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
458 /* Remainder in n0. */
465 d0
= 1 / d0
; /* Divide intentionally by zero. */
467 udiv_qrnnd (q1
, n1
, 0, n1
, d0
);
468 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
470 /* Remainder in n0. */
481 #else /* UDIV_NEEDS_NORMALIZATION */
489 count_leading_zeros (bm
, d0
);
493 /* Normalize, i.e. make the most significant bit of the
497 n1
= (n1
<< bm
) | (n0
>> (SI_TYPE_SIZE
- bm
));
501 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
504 /* Remainder in n0 >> bm. */
511 d0
= 1 / d0
; /* Divide intentionally by zero. */
513 count_leading_zeros (bm
, d0
);
517 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
518 conclude (the most significant bit of n1 is set) /\ (the
519 leading quotient digit q1 = 1).
521 This special case is necessary, not an optimization.
522 (Shifts counts of SI_TYPE_SIZE are undefined.) */
531 b
= SI_TYPE_SIZE
- bm
;
535 n1
= (n1
<< bm
) | (n0
>> b
);
538 udiv_qrnnd (q1
, n1
, n2
, n1
, d0
);
543 udiv_qrnnd (q0
, n0
, n1
, n0
, d0
);
545 /* Remainder in n0 >> bm. */
555 #endif /* UDIV_NEEDS_NORMALIZATION */
566 /* Remainder in n1n0. */
578 count_leading_zeros (bm
, d1
);
581 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
582 conclude (the most significant bit of n1 is set) /\ (the
583 quotient digit q0 = 0 or 1).
585 This special case is necessary, not an optimization. */
587 /* The condition on the next line takes advantage of that
588 n1 >= d1 (true due to program flow). */
589 if (n1
> d1
|| n0
>= d0
)
592 sub_ddmmss (n1
, n0
, n1
, n0
, d1
, d0
);
611 b
= SI_TYPE_SIZE
- bm
;
613 d1
= (d1
<< bm
) | (d0
>> b
);
616 n1
= (n1
<< bm
) | (n0
>> b
);
619 udiv_qrnnd (q0
, n1
, n2
, n1
, d1
);
620 umul_ppmm (m1
, m0
, q0
, d0
);
622 if (m1
> n1
|| (m1
== n1
&& m0
> n0
))
625 sub_ddmmss (m1
, m0
, m1
, m0
, d1
, d0
);
630 /* Remainder in (n1n0 - m1m0) >> bm. */
633 sub_ddmmss (n1
, n0
, n1
, n0
, m1
, m0
);
634 rr
.s
.low
= (n1
<< b
) | (n0
>> bm
);
635 rr
.s
.high
= n1
>> bm
;
649 UDItype
__udivmoddi4 ();
664 uu
.ll
= __negdi2 (uu
.ll
);
667 vv
.ll
= __negdi2 (vv
.ll
);
669 w
= __udivmoddi4 (uu
.ll
, vv
.ll
, (UDItype
*) 0);
678 UDItype
__udivmoddi4 ();
692 uu
.ll
= __negdi2 (uu
.ll
);
694 vv
.ll
= __negdi2 (vv
.ll
);
696 (void) __udivmoddi4 (uu
.ll
, vv
.ll
, &w
);
705 UDItype
__udivmoddi4 ();
712 (void) __udivmoddi4 (u
, v
, &w
);
719 UDItype
__udivmoddi4 ();
724 return __udivmoddi4 (n
, d
, (UDItype
*) 0);
735 au
.ll
= a
, bu
.ll
= b
;
737 if (au
.s
.high
< bu
.s
.high
)
739 else if (au
.s
.high
> bu
.s
.high
)
741 if ((USItype
) au
.s
.low
< (USItype
) bu
.s
.low
)
743 else if ((USItype
) au
.s
.low
> (USItype
) bu
.s
.low
)
756 au
.ll
= a
, bu
.ll
= b
;
758 if ((USItype
) au
.s
.high
< (USItype
) bu
.s
.high
)
760 else if ((USItype
) au
.s
.high
> (USItype
) bu
.s
.high
)
762 if ((USItype
) au
.s
.low
< (USItype
) bu
.s
.low
)
764 else if ((USItype
) au
.s
.low
> (USItype
) bu
.s
.low
)
770 #if defined(L_fixunstfdi) && (LONG_DOUBLE_TYPE_SIZE == 128)
771 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
772 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
784 /* Compute high word of result, as a flonum. */
785 b
= (a
/ HIGH_WORD_COEFF
);
786 /* Convert that to fixed (but not to DItype!),
787 and shift it into the high word. */
790 /* Remove high part from the TFtype, leaving the low part as flonum. */
792 /* Convert that to fixed (but not to DItype!) and add it in.
793 Sometimes A comes out negative. This is significant, since
794 A has more bits than a long int does. */
796 v
-= (USItype
) (- a
);
803 #if defined(L_fixtfdi) && (LONG_DOUBLE_TYPE_SIZE == 128)
809 return - __fixunstfdi (-a
);
810 return __fixunstfdi (a
);
814 #if defined(L_fixunsxfdi) && (LONG_DOUBLE_TYPE_SIZE == 96)
815 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
816 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
828 /* Compute high word of result, as a flonum. */
829 b
= (a
/ HIGH_WORD_COEFF
);
830 /* Convert that to fixed (but not to DItype!),
831 and shift it into the high word. */
834 /* Remove high part from the XFtype, leaving the low part as flonum. */
836 /* Convert that to fixed (but not to DItype!) and add it in.
837 Sometimes A comes out negative. This is significant, since
838 A has more bits than a long int does. */
840 v
-= (USItype
) (- a
);
847 #if defined(L_fixxfdi) && (LONG_DOUBLE_TYPE_SIZE == 96)
853 return - __fixunsxfdi (-a
);
854 return __fixunsxfdi (a
);
859 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
860 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
872 /* Compute high word of result, as a flonum. */
873 b
= (a
/ HIGH_WORD_COEFF
);
874 /* Convert that to fixed (but not to DItype!),
875 and shift it into the high word. */
878 /* Remove high part from the DFtype, leaving the low part as flonum. */
880 /* Convert that to fixed (but not to DItype!) and add it in.
881 Sometimes A comes out negative. This is significant, since
882 A has more bits than a long int does. */
884 v
-= (USItype
) (- a
);
897 return - __fixunsdfdi (-a
);
898 return __fixunsdfdi (a
);
903 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
904 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
907 __fixunssfdi (SFtype original_a
)
909 /* Convert the SFtype to a DFtype, because that is surely not going
910 to lose any bits. Some day someone else can write a faster version
911 that avoids converting to DFtype, and verify it really works right. */
912 DFtype a
= original_a
;
919 /* Compute high word of result, as a flonum. */
920 b
= (a
/ HIGH_WORD_COEFF
);
921 /* Convert that to fixed (but not to DItype!),
922 and shift it into the high word. */
925 /* Remove high part from the DFtype, leaving the low part as flonum. */
927 /* Convert that to fixed (but not to DItype!) and add it in.
928 Sometimes A comes out negative. This is significant, since
929 A has more bits than a long int does. */
931 v
-= (USItype
) (- a
);
943 return - __fixunssfdi (-a
);
944 return __fixunssfdi (a
);
948 #if defined(L_floatdixf) && (LONG_DOUBLE_TYPE_SIZE == 96)
949 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
950 #define HIGH_HALFWORD_COEFF (((UDItype) 1) << (WORD_SIZE / 2))
951 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
963 d
= (USItype
) (u
>> WORD_SIZE
);
964 d
*= HIGH_HALFWORD_COEFF
;
965 d
*= HIGH_HALFWORD_COEFF
;
966 d
+= (USItype
) (u
& (HIGH_WORD_COEFF
- 1));
968 return (negate
? -d
: d
);
972 #if defined(L_floatditf) && (LONG_DOUBLE_TYPE_SIZE == 128)
973 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
974 #define HIGH_HALFWORD_COEFF (((UDItype) 1) << (WORD_SIZE / 2))
975 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
987 d
= (USItype
) (u
>> WORD_SIZE
);
988 d
*= HIGH_HALFWORD_COEFF
;
989 d
*= HIGH_HALFWORD_COEFF
;
990 d
+= (USItype
) (u
& (HIGH_WORD_COEFF
- 1));
992 return (negate
? -d
: d
);
997 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
998 #define HIGH_HALFWORD_COEFF (((UDItype) 1) << (WORD_SIZE / 2))
999 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
1011 d
= (USItype
) (u
>> WORD_SIZE
);
1012 d
*= HIGH_HALFWORD_COEFF
;
1013 d
*= HIGH_HALFWORD_COEFF
;
1014 d
+= (USItype
) (u
& (HIGH_WORD_COEFF
- 1));
1016 return (negate
? -d
: d
);
1021 #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
1022 #define HIGH_HALFWORD_COEFF (((UDItype) 1) << (WORD_SIZE / 2))
1023 #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
1024 #define DI_SIZE (sizeof (DItype) * BITS_PER_UNIT)
1025 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
1029 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
1033 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
1048 /* Do the calculation in DFmode
1049 so that we don't lose any of the precision of the high word
1050 while multiplying it. */
1057 /* Protect against double-rounding error.
1058 Represent any low-order bits, that might be truncated in DFmode,
1059 by a bit that won't be lost. The bit can go in anywhere below the
1060 rounding position of the SFmode. A fixed mask and bit position
1061 handles all usual configurations. It doesn't handle the case
1062 of 128-bit DImode, however. */
1063 if (DF_SIZE
< DI_SIZE
1064 && DF_SIZE
> (DI_SIZE
- DF_SIZE
+ SF_SIZE
))
1066 #define REP_BIT ((USItype) 1 << (DI_SIZE - DF_SIZE))
1067 if (u
>= ((UDItype
) 1 << DF_SIZE
))
1069 if ((USItype
) u
& (REP_BIT
- 1))
1073 f
= (USItype
) (u
>> WORD_SIZE
);
1074 f
*= HIGH_HALFWORD_COEFF
;
1075 f
*= HIGH_HALFWORD_COEFF
;
1076 f
+= (USItype
) (u
& (HIGH_WORD_COEFF
- 1));
1078 return (SFtype
) (negate
? -f
: f
);
1082 #if defined(L_fixunsxfsi) && LONG_DOUBLE_TYPE_SIZE == 96
1083 #include "glimits.h"
1089 if (a
>= - (DFtype
) LONG_MIN
)
1090 return (SItype
) (a
+ LONG_MIN
) - LONG_MIN
;
1096 #include "glimits.h"
1102 if (a
>= - (DFtype
) LONG_MIN
)
1103 return (SItype
) (a
+ LONG_MIN
) - LONG_MIN
;
1109 #include "glimits.h"
1112 __fixunssfsi (SFtype a
)
1114 if (a
>= - (SFtype
) LONG_MIN
)
1115 return (SItype
) (a
+ LONG_MIN
) - LONG_MIN
;
1120 /* From here on down, the routines use normal data types. */
1122 #define SItype bogus_type
1123 #define USItype bogus_type
1124 #define DItype bogus_type
1125 #define UDItype bogus_type
1126 #define SFtype bogus_type
1127 #define DFtype bogus_type
1139 /* Like bcmp except the sign is meaningful.
1140 Reult is negative if S1 is less than S2,
1141 positive if S1 is greater, 0 if S1 and S2 are equal. */
1144 __gcc_bcmp (s1
, s2
, size
)
1145 unsigned char *s1
, *s2
;
1150 unsigned char c1
= *s1
++, c2
= *s2
++;
1162 #if defined(__svr4__) || defined(__alliant__)
1166 /* The Alliant needs the added underscore. */
1167 asm (".globl __builtin_saveregs");
1168 asm ("__builtin_saveregs:");
1169 asm (".globl ___builtin_saveregs");
1170 asm ("___builtin_saveregs:");
1172 asm (" andnot 0x0f,%sp,%sp"); /* round down to 16-byte boundary */
1173 asm (" adds -96,%sp,%sp"); /* allocate stack space for reg save
1174 area and also for a new va_list
1176 /* Save all argument registers in the arg reg save area. The
1177 arg reg save area must have the following layout (according
1189 asm (" fst.q %f8, 0(%sp)"); /* save floating regs (f8-f15) */
1190 asm (" fst.q %f12,16(%sp)");
1192 asm (" st.l %r16,32(%sp)"); /* save integer regs (r16-r27) */
1193 asm (" st.l %r17,36(%sp)");
1194 asm (" st.l %r18,40(%sp)");
1195 asm (" st.l %r19,44(%sp)");
1196 asm (" st.l %r20,48(%sp)");
1197 asm (" st.l %r21,52(%sp)");
1198 asm (" st.l %r22,56(%sp)");
1199 asm (" st.l %r23,60(%sp)");
1200 asm (" st.l %r24,64(%sp)");
1201 asm (" st.l %r25,68(%sp)");
1202 asm (" st.l %r26,72(%sp)");
1203 asm (" st.l %r27,76(%sp)");
1205 asm (" adds 80,%sp,%r16"); /* compute the address of the new
1206 va_list structure. Put in into
1207 r16 so that it will be returned
1210 /* Initialize all fields of the new va_list structure. This
1211 structure looks like:
1214 unsigned long ireg_used;
1215 unsigned long freg_used;
1221 asm (" st.l %r0, 0(%r16)"); /* nfixed */
1222 asm (" st.l %r0, 4(%r16)"); /* nfloating */
1223 asm (" st.l %sp, 8(%r16)"); /* __va_ctl points to __va_struct. */
1224 asm (" bri %r1"); /* delayed return */
1225 asm (" st.l %r28,12(%r16)"); /* pointer to overflow args */
1227 #else /* not __svr4__ */
1228 #if defined(__PARAGON__)
1230 * we'll use SVR4-ish varargs but need SVR3.2 assembler syntax,
1231 * and we stand a better chance of hooking into libraries
1232 * compiled by PGI. [andyp@ssd.intel.com]
1236 asm (".globl __builtin_saveregs");
1237 asm ("__builtin_saveregs:");
1238 asm (".globl ___builtin_saveregs");
1239 asm ("___builtin_saveregs:");
1241 asm (" andnot 0x0f,sp,sp"); /* round down to 16-byte boundary */
1242 asm (" adds -96,sp,sp"); /* allocate stack space for reg save
1243 area and also for a new va_list
1245 /* Save all argument registers in the arg reg save area. The
1246 arg reg save area must have the following layout (according
1258 asm (" fst.q f8, 0(sp)");
1259 asm (" fst.q f12,16(sp)");
1260 asm (" st.l r16,32(sp)");
1261 asm (" st.l r17,36(sp)");
1262 asm (" st.l r18,40(sp)");
1263 asm (" st.l r19,44(sp)");
1264 asm (" st.l r20,48(sp)");
1265 asm (" st.l r21,52(sp)");
1266 asm (" st.l r22,56(sp)");
1267 asm (" st.l r23,60(sp)");
1268 asm (" st.l r24,64(sp)");
1269 asm (" st.l r25,68(sp)");
1270 asm (" st.l r26,72(sp)");
1271 asm (" st.l r27,76(sp)");
1273 asm (" adds 80,sp,r16"); /* compute the address of the new
1274 va_list structure. Put in into
1275 r16 so that it will be returned
1278 /* Initialize all fields of the new va_list structure. This
1279 structure looks like:
1282 unsigned long ireg_used;
1283 unsigned long freg_used;
1289 asm (" st.l r0, 0(r16)"); /* nfixed */
1290 asm (" st.l r0, 4(r16)"); /* nfloating */
1291 asm (" st.l sp, 8(r16)"); /* __va_ctl points to __va_struct. */
1292 asm (" bri r1"); /* delayed return */
1293 asm (" st.l r28,12(r16)"); /* pointer to overflow args */
1294 #else /* not __PARAGON__ */
1298 asm (".globl ___builtin_saveregs");
1299 asm ("___builtin_saveregs:");
1300 asm (" mov sp,r30");
1301 asm (" andnot 0x0f,sp,sp");
1302 asm (" adds -96,sp,sp"); /* allocate sufficient space on the stack */
1304 /* Fill in the __va_struct. */
1305 asm (" st.l r16, 0(sp)"); /* save integer regs (r16-r27) */
1306 asm (" st.l r17, 4(sp)"); /* int fixed[12] */
1307 asm (" st.l r18, 8(sp)");
1308 asm (" st.l r19,12(sp)");
1309 asm (" st.l r20,16(sp)");
1310 asm (" st.l r21,20(sp)");
1311 asm (" st.l r22,24(sp)");
1312 asm (" st.l r23,28(sp)");
1313 asm (" st.l r24,32(sp)");
1314 asm (" st.l r25,36(sp)");
1315 asm (" st.l r26,40(sp)");
1316 asm (" st.l r27,44(sp)");
1318 asm (" fst.q f8, 48(sp)"); /* save floating regs (f8-f15) */
1319 asm (" fst.q f12,64(sp)"); /* int floating[8] */
1321 /* Fill in the __va_ctl. */
1322 asm (" st.l sp, 80(sp)"); /* __va_ctl points to __va_struct. */
1323 asm (" st.l r28,84(sp)"); /* pointer to more args */
1324 asm (" st.l r0, 88(sp)"); /* nfixed */
1325 asm (" st.l r0, 92(sp)"); /* nfloating */
1327 asm (" adds 80,sp,r16"); /* return address of the __va_ctl. */
1329 asm (" mov r30,sp");
1330 /* recover stack and pass address to start
1332 #endif /* not __PARAGON__ */
1333 #endif /* not __svr4__ */
1334 #else /* not __i860__ */
1336 asm (".global __builtin_saveregs");
1337 asm ("__builtin_saveregs:");
1338 asm (".global ___builtin_saveregs");
1339 asm ("___builtin_saveregs:");
1340 #ifdef NEED_PROC_COMMAND
1343 asm ("st %i0,[%fp+68]");
1344 asm ("st %i1,[%fp+72]");
1345 asm ("st %i2,[%fp+76]");
1346 asm ("st %i3,[%fp+80]");
1347 asm ("st %i4,[%fp+84]");
1349 asm ("st %i5,[%fp+88]");
1350 #ifdef NEED_TYPE_COMMAND
1351 asm (".type __builtin_saveregs,#function");
1352 asm (".size __builtin_saveregs,.-__builtin_saveregs");
1354 #else /* not __sparc__ */
1355 #if defined(__MIPSEL__) | defined(__R3000__) | defined(__R2000__) | defined(__mips__)
1358 asm (" .ent __builtin_saveregs");
1359 asm (" .globl __builtin_saveregs");
1360 asm ("__builtin_saveregs:");
1361 asm (" sw $4,0($30)");
1362 asm (" sw $5,4($30)");
1363 asm (" sw $6,8($30)");
1364 asm (" sw $7,12($30)");
1366 asm (" .end __builtin_saveregs");
1367 #else /* not __mips__, etc. */
1370 __builtin_saveregs ()
1375 #endif /* not __mips__ */
1376 #endif /* not __sparc__ */
1377 #endif /* not __i860__ */
1381 #ifndef inhibit_libc
1383 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1385 /* This is used by the `assert' macro. */
1387 __eprintf (string
, expression
, line
, filename
)
1389 const char *expression
;
1391 const char *filename
;
1393 fprintf (stderr
, string
, expression
, line
, filename
);
1403 /* Structure emitted by -a */
1407 const char *filename
;
1411 const unsigned long *addresses
;
1413 /* Older GCC's did not emit these fields. */
1415 const char **functions
;
1416 const long *line_nums
;
1417 const char **filenames
;
1420 #ifdef BLOCK_PROFILER_CODE
1423 #ifndef inhibit_libc
1425 /* Simple minded basic block profiling output dumper for
1426 systems that don't provde tcov support. At present,
1427 it requires atexit and stdio. */
1429 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1434 extern void atexit (void (*) (void));
1435 #define ON_EXIT(FUNC,ARG) atexit ((FUNC))
1438 extern void on_exit (void*, void*);
1439 #define ON_EXIT(FUNC,ARG) on_exit ((FUNC), (ARG))
1443 static struct bb
*bb_head
= (struct bb
*)0;
1445 /* Return the number of digits needed to print a value */
1446 /* __inline__ */ static int num_digits (long value
, int base
)
1448 int minus
= (value
< 0 && base
!= 16);
1449 unsigned long v
= (minus
) ? -value
: value
;
1463 __bb_exit_func (void)
1465 FILE *file
= fopen ("bb.out", "a");
1475 /* This is somewhat type incorrect, but it avoids worrying about
1476 exactly where time.h is included from. It should be ok unless
1477 a void * differs from other pointer formats, or if sizeof(long)
1478 is < sizeof (time_t). It would be nice if we could assume the
1479 use of rationale standards here. */
1481 time((void *) &time_value
);
1482 fprintf (file
, "Basic block profiling finished on %s\n", ctime ((void *) &time_value
));
1484 /* We check the length field explicitly in order to allow compatibility
1485 with older GCC's which did not provide it. */
1487 for (ptr
= bb_head
; ptr
!= (struct bb
*)0; ptr
= ptr
->next
)
1490 int func_p
= (ptr
->nwords
>= sizeof (struct bb
) && ptr
->nwords
<= 1000);
1491 int line_p
= (func_p
&& ptr
->line_nums
);
1492 int file_p
= (func_p
&& ptr
->filenames
);
1493 long ncounts
= ptr
->ncounts
;
1499 int blk_len
= num_digits (ncounts
, 10);
1504 fprintf (file
, "File %s, %ld basic blocks \n\n",
1505 ptr
->filename
, ncounts
);
1507 /* Get max values for each field. */
1508 for (i
= 0; i
< ncounts
; i
++)
1513 if (cnt_max
< ptr
->counts
[i
])
1514 cnt_max
= ptr
->counts
[i
];
1516 if (addr_max
< ptr
->addresses
[i
])
1517 addr_max
= ptr
->addresses
[i
];
1519 if (line_p
&& line_max
< ptr
->line_nums
[i
])
1520 line_max
= ptr
->line_nums
[i
];
1524 p
= (ptr
->functions
[i
]) ? (ptr
->functions
[i
]) : "<none>";
1532 p
= (ptr
->filenames
[i
]) ? (ptr
->filenames
[i
]) : "<none>";
1539 addr_len
= num_digits (addr_max
, 16);
1540 cnt_len
= num_digits (cnt_max
, 10);
1541 line_len
= num_digits (line_max
, 10);
1543 /* Now print out the basic block information. */
1544 for (i
= 0; i
< ncounts
; i
++)
1547 " Block #%*d: executed %*ld time(s) address= 0x%.*lx",
1549 cnt_len
, ptr
->counts
[i
],
1550 addr_len
, ptr
->addresses
[i
]);
1553 fprintf (file
, " function= %-*s", func_len
,
1554 (ptr
->functions
[i
]) ? ptr
->functions
[i
] : "<none>");
1557 fprintf (file
, " line= %*ld", line_len
, ptr
->line_nums
[i
]);
1560 fprintf (file
, " file= %s",
1561 (ptr
->filenames
[i
]) ? ptr
->filenames
[i
] : "<none>");
1563 fprintf (file
, "\n");
1566 fprintf (file
, "\n");
1570 fprintf (file
, "\n\n");
1576 __bb_init_func (struct bb
*blocks
)
1578 /* User is supposed to check whether the first word is non-0,
1579 but just in case.... */
1581 if (blocks
->zero_word
)
1585 /* Initialize destructor. */
1587 ON_EXIT (__bb_exit_func
, 0);
1590 /* Set up linked list. */
1591 blocks
->zero_word
= 1;
1592 blocks
->next
= bb_head
;
1596 #endif /* not inhibit_libc */
1597 #endif /* not BLOCK_PROFILER_CODE */
1600 /* Default free-store management functions for C++, per sections 12.5 and
1601 17.3.3 of the Working Paper. */
1604 /* operator new (size_t), described in 17.3.3.5. This function is used by
1605 C++ programs to allocate a block of memory to hold a single object. */
1607 typedef void (*vfp
)(void);
1608 extern vfp __new_handler
;
1611 __builtin_new (size_t sz
)
1615 /* malloc (0) is unpredictable; avoid it. */
1618 p
= (void *) malloc (sz
);
1621 (*__new_handler
) ();
1622 p
= (void *) malloc (sz
);
1627 #endif /* L_op_new */
1630 /* void * operator new [] (size_t), described in 17.3.3.6. This function
1631 is used by C++ programs to allocate a block of memory for an array. */
1633 extern void * __builtin_new (size_t);
1636 __builtin_vec_new (size_t sz
)
1638 return __builtin_new (sz
);
1640 #endif /* L_op_vnew */
1642 #ifdef L_new_handler
1643 /* set_new_handler (fvoid_t *) and the default new handler, described in
1644 17.3.3.2 and 17.3.3.5. These functions define the result of a failure
1645 to allocate the amount of memory requested from operator new or new []. */
1647 #ifndef inhibit_libc
1648 /* This gets us __GNU_LIBRARY__. */
1649 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1652 #ifdef __GNU_LIBRARY__
1653 /* Avoid forcing the library's meaning of `write' on the user program
1654 by using the "internal" name (for use within the library) */
1655 #define write(fd, buf, n) __write((fd), (buf), (n))
1657 #endif /* inhibit_libc */
1659 typedef void (*vfp
)(void);
1660 void __default_new_handler (void);
1662 vfp __new_handler
= __default_new_handler
;
1665 set_new_handler (vfp handler
)
1669 prev_handler
= __new_handler
;
1670 if (handler
== 0) handler
= __default_new_handler
;
1671 __new_handler
= handler
;
1672 return prev_handler
;
1675 #define MESSAGE "Virtual memory exceeded in `new'\n"
1678 __default_new_handler ()
1680 /* don't use fprintf (stderr, ...) because it may need to call malloc. */
1681 /* This should really print the name of the program, but that is hard to
1682 do. We need a standard, clean way to get at the name. */
1683 write (2, MESSAGE
, sizeof (MESSAGE
));
1684 /* don't call exit () because that may call global destructors which
1685 may cause a loop. */
1691 /* operator delete (void *), described in 17.3.3.3. This function is used
1692 by C++ programs to return to the free store a block of memory allocated
1693 as a single object. */
1696 __builtin_delete (void *ptr
)
1704 /* operator delete [] (void *), described in 17.3.3.4. This function is
1705 used by C++ programs to return to the free store a block of memory
1706 allocated as an array. */
1708 extern void __builtin_delete (void *);
1711 __builtin_vec_delete (void *ptr
)
1713 __builtin_delete (ptr
);
1717 /* End of C++ free-store management functions */
1720 unsigned int __shtab
[] = {
1721 0x00000001, 0x00000002, 0x00000004, 0x00000008,
1722 0x00000010, 0x00000020, 0x00000040, 0x00000080,
1723 0x00000100, 0x00000200, 0x00000400, 0x00000800,
1724 0x00001000, 0x00002000, 0x00004000, 0x00008000,
1725 0x00010000, 0x00020000, 0x00040000, 0x00080000,
1726 0x00100000, 0x00200000, 0x00400000, 0x00800000,
1727 0x01000000, 0x02000000, 0x04000000, 0x08000000,
1728 0x10000000, 0x20000000, 0x40000000, 0x80000000
1732 #ifdef L_clear_cache
1733 /* Clear part of an instruction cache. */
1735 #define INSN_CACHE_PLANE_SIZE (INSN_CACHE_SIZE / INSN_CACHE_DEPTH)
1738 __clear_cache (beg
, end
)
1741 #ifdef CLEAR_INSN_CACHE
1742 CLEAR_INSN_CACHE (beg
, end
);
1744 #ifdef INSN_CACHE_SIZE
1745 static char array
[INSN_CACHE_SIZE
+ INSN_CACHE_PLANE_SIZE
+ INSN_CACHE_LINE_WIDTH
];
1746 static int initialized
= 0;
1750 typedef (*function_ptr
) ();
1752 #if (INSN_CACHE_SIZE / INSN_CACHE_LINE_WIDTH) < 16
1753 /* It's cheaper to clear the whole cache.
1754 Put in a series of jump instructions so that calling the beginning
1755 of the cache will clear the whole thing. */
1759 int ptr
= (((int) array
+ INSN_CACHE_LINE_WIDTH
- 1)
1760 & -INSN_CACHE_LINE_WIDTH
);
1761 int end_ptr
= ptr
+ INSN_CACHE_SIZE
;
1763 while (ptr
< end_ptr
)
1765 *(INSTRUCTION_TYPE
*)ptr
1766 = JUMP_AHEAD_INSTRUCTION
+ INSN_CACHE_LINE_WIDTH
;
1767 ptr
+= INSN_CACHE_LINE_WIDTH
;
1769 *(INSTRUCTION_TYPE
*)(ptr
- INSN_CACHE_LINE_WIDTH
) = RETURN_INSTRUCTION
;
1774 /* Call the beginning of the sequence. */
1775 (((function_ptr
) (((int) array
+ INSN_CACHE_LINE_WIDTH
- 1)
1776 & -INSN_CACHE_LINE_WIDTH
))
1779 #else /* Cache is large. */
1783 int ptr
= (((int) array
+ INSN_CACHE_LINE_WIDTH
- 1)
1784 & -INSN_CACHE_LINE_WIDTH
);
1786 while (ptr
< (int) array
+ sizeof array
)
1788 *(INSTRUCTION_TYPE
*)ptr
= RETURN_INSTRUCTION
;
1789 ptr
+= INSN_CACHE_LINE_WIDTH
;
1795 /* Find the location in array that occupies the same cache line as BEG. */
1797 offset
= ((int) beg
& -INSN_CACHE_LINE_WIDTH
) & (INSN_CACHE_PLANE_SIZE
- 1);
1798 start_addr
= (((int) (array
+ INSN_CACHE_PLANE_SIZE
- 1)
1799 & -INSN_CACHE_PLANE_SIZE
)
1802 /* Compute the cache alignment of the place to stop clearing. */
1803 #if 0 /* This is not needed for gcc's purposes. */
1804 /* If the block to clear is bigger than a cache plane,
1805 we clear the entire cache, and OFFSET is already correct. */
1806 if (end
< beg
+ INSN_CACHE_PLANE_SIZE
)
1808 offset
= (((int) (end
+ INSN_CACHE_LINE_WIDTH
- 1)
1809 & -INSN_CACHE_LINE_WIDTH
)
1810 & (INSN_CACHE_PLANE_SIZE
- 1));
1812 #if INSN_CACHE_DEPTH > 1
1813 end_addr
= (start_addr
& -INSN_CACHE_PLANE_SIZE
) + offset
;
1814 if (end_addr
<= start_addr
)
1815 end_addr
+= INSN_CACHE_PLANE_SIZE
;
1817 for (plane
= 0; plane
< INSN_CACHE_DEPTH
; plane
++)
1819 int addr
= start_addr
+ plane
* INSN_CACHE_PLANE_SIZE
;
1820 int stop
= end_addr
+ plane
* INSN_CACHE_PLANE_SIZE
;
1822 while (addr
!= stop
)
1824 /* Call the return instruction at ADDR. */
1825 ((function_ptr
) addr
) ();
1827 addr
+= INSN_CACHE_LINE_WIDTH
;
1830 #else /* just one plane */
1833 /* Call the return instruction at START_ADDR. */
1834 ((function_ptr
) start_addr
) ();
1836 start_addr
+= INSN_CACHE_LINE_WIDTH
;
1838 while ((start_addr
% INSN_CACHE_SIZE
) != offset
);
1839 #endif /* just one plane */
1840 #endif /* Cache is large */
1841 #endif /* Cache exists */
1842 #endif /* CLEAR_INSN_CACHE */
1845 #endif /* L_clear_cache */
1849 /* Jump to a trampoline, loading the static chain address. */
1851 #ifdef TRANSFER_FROM_TRAMPOLINE
1852 TRANSFER_FROM_TRAMPOLINE
1855 #if defined (NeXT) && defined (__MACH__)
1857 /* Make stack executable so we can call trampolines on stack.
1858 This is called from INITIALIZE_TRAMPOLINE in next.h. */
1862 #include <mach/mach.h>
1866 __enable_execute_stack (addr
)
1870 char *eaddr
= addr
+ TRAMPOLINE_SIZE
;
1871 vm_address_t a
= (vm_address_t
) addr
;
1873 /* turn on execute access on stack */
1874 r
= vm_protect (task_self (), a
, TRAMPOLINE_SIZE
, FALSE
, VM_PROT_ALL
);
1875 if (r
!= KERN_SUCCESS
)
1877 mach_error("vm_protect VM_PROT_ALL", r
);
1881 /* We inline the i-cache invalidation for speed */
1883 #ifdef CLEAR_INSN_CACHE
1884 CLEAR_INSN_CACHE (addr
, eaddr
);
1886 __clear_cache ((int) addr
, (int) eaddr
);
1890 #endif /* defined (NeXT) && defined (__MACH__) */
1894 /* Make stack executable so we can call trampolines on stack.
1895 This is called from INITIALIZE_TRAMPOLINE in convex.h. */
1897 #include <sys/mman.h>
1898 #include <sys/vmparam.h>
1899 #include <machine/machparam.h>
1902 __enable_execute_stack ()
1905 static unsigned lowest
= USRSTACK
;
1906 unsigned current
= (unsigned) &fp
& -NBPG
;
1908 if (lowest
> current
)
1910 unsigned len
= lowest
- current
;
1911 mremap (current
, &len
, PROT_READ
| PROT_WRITE
| PROT_EXEC
, MAP_PRIVATE
);
1915 /* Clear instruction cache in case an old trampoline is in it. */
1918 #endif /* __convex__ */
1922 /* Modified from the convex -code above. */
1924 #include <sys/param.h>
1926 #include <sys/m88kbcs.h>
1929 __enable_execute_stack ()
1932 static unsigned long lowest
= USRSTACK
;
1933 unsigned long current
= (unsigned long) &save_errno
& -NBPC
;
1935 /* Ignore errno being set. memctl sets errno to EINVAL whenever the
1936 address is seen as 'negative'. That is the case with the stack. */
1939 if (lowest
> current
)
1941 unsigned len
=lowest
-current
;
1942 memctl(current
,len
,MCT_TEXT
);
1946 memctl(current
,NBPC
,MCT_TEXT
);
1950 #endif /* __DOLPHIN__ */
1954 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1956 #include <sys/mman.h>
1957 #include <sys/types.h>
1958 #include <sys/param.h>
1959 #include <sys/vmmac.h>
1961 /* Modified from the convex -code above.
1962 mremap promises to clear the i-cache. */
1965 __enable_execute_stack ()
1968 if (mprotect (((unsigned int)&fp
/PAGSIZ
)*PAGSIZ
, PAGSIZ
,
1969 PROT_READ
|PROT_WRITE
|PROT_EXEC
))
1971 perror ("mprotect in __enable_execute_stack");
1976 #endif /* __pyr__ */
1977 #endif /* L_trampoline */
1981 #include "gbl-ctors.h"
1982 /* Some systems use __main in a way incompatible with its use in gcc, in these
1983 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
1984 give the same symbol without quotes for an alternative entry point. You
1985 must define both, or niether. */
1987 #define NAME__MAIN "__main"
1988 #define SYMBOL__MAIN __main
1991 /* Run all the global destructors on exit from the program. */
1994 __do_global_dtors ()
1996 #ifdef DO_GLOBAL_DTORS_BODY
1997 DO_GLOBAL_DTORS_BODY
;
2000 for (p
= __DTOR_LIST__
+ 1; *p
; )
2005 #ifndef INIT_SECTION_ASM_OP
2006 /* Run all the global constructors on entry to the program. */
2009 #define ON_EXIT(a, b)
2011 /* Make sure the exit routine is pulled in to define the globals as
2012 bss symbols, just in case the linker does not automatically pull
2013 bss definitions from the library. */
2015 extern int _exit_dummy_decl
;
2016 int *_exit_dummy_ref
= &_exit_dummy_decl
;
2017 #endif /* ON_EXIT */
2020 __do_global_ctors ()
2022 DO_GLOBAL_CTORS_BODY
;
2023 ON_EXIT (__do_global_dtors
, 0);
2025 #endif /* no INIT_SECTION_ASM_OP */
2027 #if !defined (INIT_SECTION_ASM_OP) || defined (INVOKE__main)
2028 /* Subroutine called automatically by `main'.
2029 Compiling a global function named `main'
2030 produces an automatic call to this function at the beginning.
2032 For many systems, this routine calls __do_global_ctors.
2033 For systems which support a .init section we use the .init section
2034 to run __do_global_ctors, so we need not do anything here. */
2039 /* Support recursive calls to `main': run initializers just once. */
2040 static int initialized
= 0;
2044 __do_global_ctors ();
2047 #endif /* no INIT_SECTION_ASM_OP or INVOKE__main */
2049 #endif /* L__main */
2053 #include "gbl-ctors.h"
2055 /* Provide default definitions for the lists of constructors and
2056 destructors, so that we don't get linker errors. These symbols are
2057 intentionally bss symbols, so that gld and/or collect will provide
2058 the right values. */
2060 /* We declare the lists here with two elements each,
2061 so that they are valid empty lists if no other definition is loaded. */
2062 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
2064 /* After 2.3, try this definition on all systems. */
2065 func_ptr __CTOR_LIST__
[2] = {0, 0};
2066 func_ptr __DTOR_LIST__
[2] = {0, 0};
2068 func_ptr __CTOR_LIST__
[2];
2069 func_ptr __DTOR_LIST__
[2];
2071 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
2072 #endif /* L_ctors */
2076 #include "gbl-ctors.h"
2080 /* If we have no known way of registering our own __do_global_dtors
2081 routine so that it will be invoked at program exit time, then we
2082 have to define our own exit routine which will get this to happen. */
2084 extern void __do_global_dtors ();
2085 extern void _cleanup ();
2086 extern void _exit () __attribute__ ((noreturn
));
2092 __do_global_dtors ();
2102 int _exit_dummy_decl
= 0; /* prevent compiler & linker warnings */
2107 /* In a.out systems, we need to have these dummy constructor and destructor
2108 lists in the library.
2110 When using `collect', the first link will resolve __CTOR_LIST__
2111 and __DTOR_LIST__ to these symbols. We will then run "nm" on the
2112 result, build the correct __CTOR_LIST__ and __DTOR_LIST__, and relink.
2113 Since we don't do the second link if no constructors existed, these
2114 dummies must be fully functional empty lists.
2116 When using `gnu ld', these symbols will be used if there are no
2117 constructors. If there are constructors, the N_SETV symbol defined
2118 by the linker from the N_SETT's in input files will define __CTOR_LIST__
2119 and __DTOR_LIST__ rather than its being allocated as common storage
2120 by the definitions below.
2122 When using a linker that supports constructor and destructor segments,
2123 these definitions will not be used, since crtbegin.o and crtend.o
2124 (from crtstuff.c) will have already defined __CTOR_LIST__ and
2125 __DTOR_LIST__. The crt*.o files are passed directly to the linker
2126 on its command line, by gcc. */
2128 /* The list needs two elements: one is ignored (the old count); the
2129 second is the terminating zero. Since both values are zero, this
2130 declaration is not initialized, and it becomes `common'. */
2133 #include "gbl-ctors.h"
2134 func_ptr __CTOR_LIST__
[2];
2138 #include "gbl-ctors.h"
2139 func_ptr __DTOR_LIST__
[2];
2146 void *exception_handler
;
2149 struct exception_table_node
{
2150 exception_table
*table
;
2153 struct exception_table_node
*next
;
2156 static int except_table_pos
= 0;
2157 static void *except_pc
= (void *)0;
2158 static struct exception_table_node
*exception_table_list
= 0;
2160 static exception_table
*
2161 find_exception_table (pc
)
2164 register struct exception_table_node
*table
= exception_table_list
;
2165 for ( ; table
!= 0; table
= table
->next
)
2167 if (table
->start
<= pc
&& table
->end
> pc
)
2168 return table
->table
;
2173 /* this routine takes a pc, and the address of the exception handler associated
2174 with the closest exception table handler entry associated with that PC,
2175 or 0 if there are no table entries the PC fits in. The algorithm works
2176 something like this:
2178 while(current_entry exists) {
2179 if(current_entry.start < pc )
2180 current_entry = next_entry;
2182 if(prev_entry.start <= pc && prev_entry.end > pc) {
2183 save pointer to prev_entry;
2184 return prev_entry.exception_handler;
2191 Assuming a correctly sorted table (ascending order) this routine should
2192 return the tighest match...
2194 In the advent of a tie, we have to give the last entry, as it represents
2200 __find_first_exception_table_match(pc
)
2203 exception_table
*table
= find_exception_table (pc
);
2209 printf("find_first_exception_table_match(): pc = %x!\n",pc
);
2215 /* We can't do this yet, as we don't know that the table is sorted. */
2218 if (table
[pos
].start
> except_pc
)
2219 /* found the first table[pos].start > except_pc, so the previous
2220 entry better be the one we want! */
2222 } while(table
[pos
].exception_handler
!= (void*)-1);
2225 if (table
[pos
].start
<= except_pc
&& table
[pos
].end
> except_pc
)
2227 except_table_pos
= pos
;
2229 printf("find_first_eh_table_match(): found match: %x\n",table
[pos
].exception_handler
);
2231 return table
[pos
].exception_handler
;
2234 while (table
[++pos
].exception_handler
!= (void*)-1) {
2235 if (table
[pos
].start
<= except_pc
&& table
[pos
].end
> except_pc
)
2237 /* This can apply. Make sure it is better or as good as the previous
2239 /* The best one ends first. */
2240 if (best
== 0 || (table
[pos
].end
<= table
[best
].end
2241 /* The best one starts last. */
2242 && table
[pos
].start
>= table
[best
].start
))
2247 return table
[best
].exception_handler
;
2251 printf("find_first_eh_table_match(): else: returning NULL!\n");
2257 __throw_type_match (const char *catch_type
, const char *throw_type
)
2260 printf("__throw_type_match (): catch_type = %s, throw_type = %s\n",
2261 catch_type
, throw_type
);
2263 return strcmp (catch_type
, throw_type
);
2267 __register_exceptions (exception_table
*table
)
2269 struct exception_table_node
*node
= (struct exception_table_node
*)
2270 malloc (sizeof (struct exception_table_node
));
2271 exception_table
*range
= table
+ 1;
2272 node
->table
= table
;
2274 /* This look can be optimized away either if the table
2275 is sorted, or if we pass in extra parameters. */
2276 node
->start
= range
->start
;
2277 node
->end
= range
->end
;
2278 for (range
++ ; range
->start
!= (void*)(-1); range
++)
2280 if (range
->start
< node
->start
)
2281 node
->start
= range
->start
;
2282 if (range
->end
< node
->end
)
2283 node
->end
= range
->end
;
2286 node
->next
= exception_table_list
;
2287 exception_table_list
= node
;