home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / gcc / libgcc2.c < prev    next >
C/C++ Source or Header  |  1997-02-07  |  61KB  |  2,687 lines

  1. /* More subroutines needed by GCC output code on some machines.  */
  2. /* Compile this one with gcc.  */
  3. /* Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
  4.  
  5. This file is part of GNU CC.
  6.  
  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)
  10. any later version.
  11.  
  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.
  16.  
  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, 59 Temple Place - Suite 330,
  20. Boston, MA 02111-1307, USA.  */
  21.  
  22. /* As a special exception, if you link this library with other files,
  23.    some of which are compiled with GCC, to produce an executable,
  24.    this library does not by itself cause the resulting executable
  25.    to be covered by the GNU General Public License.
  26.    This exception does not however invalidate any other reasons why
  27.    the executable file might be covered by the GNU General Public License.  */
  28.  
  29. /* It is incorrect to include config.h here, because this file is being
  30.    compiled for the target, and hence definitions concerning only the host
  31.    do not apply.  */
  32.  
  33. #include "tconfig.h"
  34. #include "machmode.h"
  35. #include "defaults.h" 
  36. #ifndef L_trampoline
  37. #include <stddef.h>
  38. #endif
  39. #ifdef SHLIB
  40. #include <libsys/shlib.h>
  41. extern void* malloc (int);
  42. extern int write (int, const char*, int);
  43. extern void free (void*);
  44. #endif
  45.  
  46. /* Don't use `fancy_abort' here even if config.h says to use it.  */
  47. #ifdef abort
  48. #undef abort
  49. #endif
  50.  
  51. #if (SUPPORTS_WEAK == 1) && defined (ASM_OUTPUT_DEF)
  52. #define WEAK_ALIAS
  53. #endif
  54.  
  55. /* Permit the tm.h file to select the endianness to use just for this
  56.    file.  This is used when the endianness is determined when the
  57.    compiler is run.  */
  58.  
  59. #ifndef LIBGCC2_WORDS_BIG_ENDIAN
  60. #define LIBGCC2_WORDS_BIG_ENDIAN WORDS_BIG_ENDIAN
  61. #endif
  62.  
  63. /* Make symbols public by default instead of __private_extern__,
  64.    as required when making a static archive on OPENSTEP for Mach.  */
  65. #ifndef PRIVATE_EXTERN
  66. #define PRIVATE_EXTERN
  67. #endif
  68.  
  69. /* Similar to GLOBAL_ASM_OP: how to declare a __private_extern__ symbol in
  70.    assembly language.  Defaults to .global, since very few systems support
  71.    the notion of __private_extern__ symbols.  */
  72. #ifndef PRIVATE_EXTERN_ASM_OP
  73. #define PRIVATE_EXTERN_ASM_OP ".global"
  74. #endif
  75.  
  76. /* In the first part of this file, we are interfacing to calls generated
  77.    by the compiler itself.  These calls pass values into these routines
  78.    which have very specific modes (rather than very specific types), and
  79.    these compiler-generated calls also expect any return values to have
  80.    very specific modes (rather than very specific types).  Thus, we need
  81.    to avoid using regular C language type names in this part of the file
  82.    because the sizes for those types can be configured to be anything.
  83.    Instead we use the following special type names.  */
  84.  
  85. typedef unsigned int UQItype    __attribute__ ((mode (QI)));
  86. typedef      int SItype    __attribute__ ((mode (SI)));
  87. typedef unsigned int USItype    __attribute__ ((mode (SI)));
  88. typedef         int DItype    __attribute__ ((mode (DI)));
  89. typedef unsigned int UDItype    __attribute__ ((mode (DI)));
  90.  
  91. typedef     float SFtype    __attribute__ ((mode (SF)));
  92. typedef        float DFtype    __attribute__ ((mode (DF)));
  93.  
  94. #if LONG_DOUBLE_TYPE_SIZE == 96
  95. typedef        float XFtype    __attribute__ ((mode (XF)));
  96. #endif
  97. #if LONG_DOUBLE_TYPE_SIZE == 128
  98. typedef        float TFtype    __attribute__ ((mode (TF)));
  99. #endif
  100.  
  101. typedef int word_type __attribute__ ((mode (__word__)));
  102.  
  103. /* Make sure that we don't accidentally use any normal C language built-in
  104.    type names in the first part of this file.  Instead we want to use *only*
  105.    the type names defined above.  The following macro definitions insure
  106.    that if we *do* accidentally use some normal C language built-in type name,
  107.    we will get a syntax error.  */
  108.  
  109. #define char bogus_type
  110. #define short bogus_type
  111. #define int bogus_type
  112. #define long bogus_type
  113. #define unsigned bogus_type
  114. #define float bogus_type
  115. #define double bogus_type
  116.  
  117. #define SI_TYPE_SIZE (sizeof (SItype) * BITS_PER_UNIT)
  118.  
  119. /* DIstructs are pairs of SItype values in the order determined by
  120.    LIBGCC2_WORDS_BIG_ENDIAN.  */
  121.  
  122. #if LIBGCC2_WORDS_BIG_ENDIAN
  123.   struct DIstruct {SItype high, low;};
  124. #else
  125.   struct DIstruct {SItype low, high;};
  126. #endif
  127.  
  128. /* We need this union to unpack/pack DImode values, since we don't have
  129.    any arithmetic yet.  Incoming DImode parameters are stored into the
  130.    `ll' field, and the unpacked result is read from the struct `s'.  */
  131.  
  132. typedef union
  133. {
  134.   struct DIstruct s;
  135.   DItype ll;
  136. } DIunion;
  137.  
  138. #if (defined (L_udivmoddi4) || defined (L_muldi3) || defined (L_udiv_w_sdiv)\
  139.      || defined (L_divdi3) || defined (L_udivdi3) \
  140.      || defined (L_moddi3) || defined (L_umoddi3))
  141.  
  142. #include "longlong.h"
  143.  
  144. #endif /* udiv or mul */
  145.  
  146. extern DItype __fixunssfdi (SFtype a);
  147. extern DItype __fixunsdfdi (DFtype a);
  148. #if LONG_DOUBLE_TYPE_SIZE == 96
  149. extern DItype __fixunsxfdi (XFtype a);
  150. #endif
  151. #if LONG_DOUBLE_TYPE_SIZE == 128
  152. extern DItype __fixunstfdi (TFtype a);
  153. #endif
  154.  
  155. #if defined (L_negdi2) || defined (L_divdi3) || defined (L_moddi3)
  156. #if defined (L_divdi3) || defined (L_moddi3)
  157. static inline
  158. #else
  159. PRIVATE_EXTERN
  160. #endif
  161. DItype
  162. __negdi2 (u)
  163.      DItype u;
  164. {
  165.   DIunion w;
  166.   DIunion uu;
  167.  
  168.   uu.ll = u;
  169.  
  170.   w.s.low = -uu.s.low;
  171.   w.s.high = -uu.s.high - ((USItype) w.s.low > 0);
  172.  
  173.   return w.ll;
  174. }
  175. #endif
  176.  
  177. #ifdef L_lshrdi3
  178. PRIVATE_EXTERN
  179. DItype
  180. __lshrdi3 (u, b)
  181.      DItype u;
  182.      word_type b;
  183. {
  184.   DIunion w;
  185.   word_type bm;
  186.   DIunion uu;
  187.  
  188.   if (b == 0)
  189.     return u;
  190.  
  191.   uu.ll = u;
  192.  
  193.   bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
  194.   if (bm <= 0)
  195.     {
  196.       w.s.high = 0;
  197.       w.s.low = (USItype)uu.s.high >> -bm;
  198.     }
  199.   else
  200.     {
  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;
  204.     }
  205.  
  206.   return w.ll;
  207. }
  208. #endif
  209.  
  210. #ifdef L_ashldi3
  211. PRIVATE_EXTERN
  212. DItype
  213. __ashldi3 (u, b)
  214.      DItype u;
  215.      word_type b;
  216. {
  217.   DIunion w;
  218.   word_type bm;
  219.   DIunion uu;
  220.  
  221.   if (b == 0)
  222.     return u;
  223.  
  224.   uu.ll = u;
  225.  
  226.   bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
  227.   if (bm <= 0)
  228.     {
  229.       w.s.low = 0;
  230.       w.s.high = (USItype)uu.s.low << -bm;
  231.     }
  232.   else
  233.     {
  234.       USItype carries = (USItype)uu.s.low >> bm;
  235.       w.s.low = (USItype)uu.s.low << b;
  236.       w.s.high = ((USItype)uu.s.high << b) | carries;
  237.     }
  238.  
  239.   return w.ll;
  240. }
  241. #endif
  242.  
  243. #ifdef L_ashrdi3
  244. PRIVATE_EXTERN
  245. DItype
  246. __ashrdi3 (u, b)
  247.      DItype u;
  248.      word_type b;
  249. {
  250.   DIunion w;
  251.   word_type bm;
  252.   DIunion uu;
  253.  
  254.   if (b == 0)
  255.     return u;
  256.  
  257.   uu.ll = u;
  258.  
  259.   bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
  260.   if (bm <= 0)
  261.     {
  262.       /* w.s.high = 1..1 or 0..0 */
  263.       w.s.high = uu.s.high >> (sizeof (SItype) * BITS_PER_UNIT - 1);
  264.       w.s.low = uu.s.high >> -bm;
  265.     }
  266.   else
  267.     {
  268.       USItype carries = (USItype)uu.s.high << bm;
  269.       w.s.high = uu.s.high >> b;
  270.       w.s.low = ((USItype)uu.s.low >> b) | carries;
  271.     }
  272.  
  273.   return w.ll;
  274. }
  275. #endif
  276.  
  277. #ifdef L_ffsdi2
  278. PRIVATE_EXTERN
  279. DItype
  280. __ffsdi2 (u)
  281.      DItype u;
  282. {
  283.   DIunion uu, w;
  284.   uu.ll = u;
  285.   w.s.high = 0;
  286.   w.s.low = ffs (uu.s.low);
  287.   if (w.s.low != 0)
  288.     return w.ll;
  289.   w.s.low = ffs (uu.s.high);
  290.   if (w.s.low != 0)
  291.     {
  292.       w.s.low += BITS_PER_UNIT * sizeof (SItype);
  293.       return w.ll;
  294.     }
  295.   return w.ll;
  296. }
  297. #endif
  298.  
  299. #ifdef L_muldi3
  300. PRIVATE_EXTERN
  301. DItype
  302. __muldi3 (u, v)
  303.      DItype u, v;
  304. {
  305.   DIunion w;
  306.   DIunion uu, vv;
  307.  
  308.   uu.ll = u,
  309.   vv.ll = v;
  310.  
  311.   w.ll = __umulsidi3 (uu.s.low, vv.s.low);
  312.   w.s.high += ((USItype) uu.s.low * (USItype) vv.s.high
  313.            + (USItype) uu.s.high * (USItype) vv.s.low);
  314.  
  315.   return w.ll;
  316. }
  317. #endif
  318.  
  319. #ifdef L_udiv_w_sdiv
  320. #if defined (sdiv_qrnnd)
  321. PRIVATE_EXTERN
  322. USItype
  323. __udiv_w_sdiv (rp, a1, a0, d)
  324.      USItype *rp, a1, a0, d;
  325. {
  326.   USItype q, r;
  327.   USItype c0, c1, b1;
  328.  
  329.   if ((SItype) d >= 0)
  330.     {
  331.       if (a1 < d - a1 - (a0 >> (SI_TYPE_SIZE - 1)))
  332.     {
  333.       /* dividend, divisor, and quotient are nonnegative */
  334.       sdiv_qrnnd (q, r, a1, a0, d);
  335.     }
  336.       else
  337.     {
  338.       /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */
  339.       sub_ddmmss (c1, c0, a1, a0, d >> 1, d << (SI_TYPE_SIZE - 1));
  340.       /* Divide (c1*2^32 + c0) by d */
  341.       sdiv_qrnnd (q, r, c1, c0, d);
  342.       /* Add 2^31 to quotient */
  343.       q += (USItype) 1 << (SI_TYPE_SIZE - 1);
  344.     }
  345.     }
  346.   else
  347.     {
  348.       b1 = d >> 1;            /* d/2, between 2^30 and 2^31 - 1 */
  349.       c1 = a1 >> 1;            /* A/2 */
  350.       c0 = (a1 << (SI_TYPE_SIZE - 1)) + (a0 >> 1);
  351.  
  352.       if (a1 < b1)            /* A < 2^32*b1, so A/2 < 2^31*b1 */
  353.     {
  354.       sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
  355.  
  356.       r = 2*r + (a0 & 1);        /* Remainder from A/(2*b1) */
  357.       if ((d & 1) != 0)
  358.         {
  359.           if (r >= q)
  360.         r = r - q;
  361.           else if (q - r <= d)
  362.         {
  363.           r = r - q + d;
  364.           q--;
  365.         }
  366.           else
  367.         {
  368.           r = r - q + 2*d;
  369.           q -= 2;
  370.         }
  371.         }
  372.     }
  373.       else if (c1 < b1)            /* So 2^31 <= (A/2)/b1 < 2^32 */
  374.     {
  375.       c1 = (b1 - 1) - c1;
  376.       c0 = ~c0;            /* logical NOT */
  377.  
  378.       sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
  379.  
  380.       q = ~q;            /* (A/2)/b1 */
  381.       r = (b1 - 1) - r;
  382.  
  383.       r = 2*r + (a0 & 1);        /* A/(2*b1) */
  384.  
  385.       if ((d & 1) != 0)
  386.         {
  387.           if (r >= q)
  388.         r = r - q;
  389.           else if (q - r <= d)
  390.         {
  391.           r = r - q + d;
  392.           q--;
  393.         }
  394.           else
  395.         {
  396.           r = r - q + 2*d;
  397.           q -= 2;
  398.         }
  399.         }
  400.     }
  401.       else                /* Implies c1 = b1 */
  402.     {                /* Hence a1 = d - 1 = 2*b1 - 1 */
  403.       if (a0 >= -d)
  404.         {
  405.           q = -1;
  406.           r = a0 + d;
  407.         }
  408.       else
  409.         {
  410.           q = -2;
  411.           r = a0 + 2*d;
  412.         }
  413.     }
  414.     }
  415.  
  416.   *rp = r;
  417.   return q;
  418. }
  419. #else
  420. /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv.  */
  421. PRIVATE_EXTERN
  422. USItype
  423. __udiv_w_sdiv (rp, a1, a0, d)
  424.      USItype *rp, a1, a0, d;
  425. {}
  426. #endif
  427. #endif
  428.  
  429. #if (defined (L_udivdi3) || defined (L_divdi3) || \
  430.      defined (L_umoddi3) || defined (L_moddi3))
  431. #define L_udivmoddi4
  432. #endif
  433.  
  434. #ifdef L_udivmoddi4
  435. static const UQItype __clz_tab[] =
  436. {
  437.   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,
  438.   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,
  439.   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,
  440.   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,
  441.   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,
  442.   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,
  443.   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,
  444.   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,
  445. };
  446.  
  447. #if (defined (L_udivdi3) || defined (L_divdi3) || \
  448.      defined (L_umoddi3) || defined (L_moddi3))
  449. static inline
  450. #else
  451. PRIVATE_EXTERN
  452. #endif
  453. UDItype
  454. __udivmoddi4 (n, d, rp)
  455.      UDItype n, d;
  456.      UDItype *rp;
  457. {
  458.   DIunion ww;
  459.   DIunion nn, dd;
  460.   DIunion rr;
  461.   USItype d0, d1, n0, n1, n2;
  462.   USItype q0, q1;
  463.   USItype b, bm;
  464.  
  465.   nn.ll = n;
  466.   dd.ll = d;
  467.  
  468.   d0 = dd.s.low;
  469.   d1 = dd.s.high;
  470.   n0 = nn.s.low;
  471.   n1 = nn.s.high;
  472.  
  473. #if !UDIV_NEEDS_NORMALIZATION
  474.   if (d1 == 0)
  475.     {
  476.       if (d0 > n1)
  477.     {
  478.       /* 0q = nn / 0D */
  479.  
  480.       udiv_qrnnd (q0, n0, n1, n0, d0);
  481.       q1 = 0;
  482.  
  483.       /* Remainder in n0.  */
  484.     }
  485.       else
  486.     {
  487.       /* qq = NN / 0d */
  488.  
  489.       if (d0 == 0)
  490.         d0 = 1 / d0;    /* Divide intentionally by zero.  */
  491.  
  492.       udiv_qrnnd (q1, n1, 0, n1, d0);
  493.       udiv_qrnnd (q0, n0, n1, n0, d0);
  494.  
  495.       /* Remainder in n0.  */
  496.     }
  497.  
  498.       if (rp != 0)
  499.     {
  500.       rr.s.low = n0;
  501.       rr.s.high = 0;
  502.       *rp = rr.ll;
  503.     }
  504.     }
  505.  
  506. #else /* UDIV_NEEDS_NORMALIZATION */
  507.  
  508.   if (d1 == 0)
  509.     {
  510.       if (d0 > n1)
  511.     {
  512.       /* 0q = nn / 0D */
  513.  
  514.       count_leading_zeros (bm, d0);
  515.  
  516.       if (bm != 0)
  517.         {
  518.           /* Normalize, i.e. make the most significant bit of the
  519.          denominator set.  */
  520.  
  521.           d0 = d0 << bm;
  522.           n1 = (n1 << bm) | (n0 >> (SI_TYPE_SIZE - bm));
  523.           n0 = n0 << bm;
  524.         }
  525.  
  526.       udiv_qrnnd (q0, n0, n1, n0, d0);
  527.       q1 = 0;
  528.  
  529.       /* Remainder in n0 >> bm.  */
  530.     }
  531.       else
  532.     {
  533.       /* qq = NN / 0d */
  534.  
  535.       if (d0 == 0)
  536.         d0 = 1 / d0;    /* Divide intentionally by zero.  */
  537.  
  538.       count_leading_zeros (bm, d0);
  539.  
  540.       if (bm == 0)
  541.         {
  542.           /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
  543.          conclude (the most significant bit of n1 is set) /\ (the
  544.          leading quotient digit q1 = 1).
  545.  
  546.          This special case is necessary, not an optimization.
  547.          (Shifts counts of SI_TYPE_SIZE are undefined.)  */
  548.  
  549.           n1 -= d0;
  550.           q1 = 1;
  551.         }
  552.       else
  553.         {
  554.           /* Normalize.  */
  555.  
  556.           b = SI_TYPE_SIZE - bm;
  557.  
  558.           d0 = d0 << bm;
  559.           n2 = n1 >> b;
  560.           n1 = (n1 << bm) | (n0 >> b);
  561.           n0 = n0 << bm;
  562.  
  563.           udiv_qrnnd (q1, n1, n2, n1, d0);
  564.         }
  565.  
  566.       /* n1 != d0... */
  567.  
  568.       udiv_qrnnd (q0, n0, n1, n0, d0);
  569.  
  570.       /* Remainder in n0 >> bm.  */
  571.     }
  572.  
  573.       if (rp != 0)
  574.     {
  575.       rr.s.low = n0 >> bm;
  576.       rr.s.high = 0;
  577.       *rp = rr.ll;
  578.     }
  579.     }
  580. #endif /* UDIV_NEEDS_NORMALIZATION */
  581.  
  582.   else
  583.     {
  584.       if (d1 > n1)
  585.     {
  586.       /* 00 = nn / DD */
  587.  
  588.       q0 = 0;
  589.       q1 = 0;
  590.  
  591.       /* Remainder in n1n0.  */
  592.       if (rp != 0)
  593.         {
  594.           rr.s.low = n0;
  595.           rr.s.high = n1;
  596.           *rp = rr.ll;
  597.         }
  598.     }
  599.       else
  600.     {
  601.       /* 0q = NN / dd */
  602.  
  603.       count_leading_zeros (bm, d1);
  604.       if (bm == 0)
  605.         {
  606.           /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
  607.          conclude (the most significant bit of n1 is set) /\ (the
  608.          quotient digit q0 = 0 or 1).
  609.  
  610.          This special case is necessary, not an optimization.  */
  611.  
  612.           /* The condition on the next line takes advantage of that
  613.          n1 >= d1 (true due to program flow).  */
  614.           if (n1 > d1 || n0 >= d0)
  615.         {
  616.           q0 = 1;
  617.           sub_ddmmss (n1, n0, n1, n0, d1, d0);
  618.         }
  619.           else
  620.         q0 = 0;
  621.  
  622.           q1 = 0;
  623.  
  624.           if (rp != 0)
  625.         {
  626.           rr.s.low = n0;
  627.           rr.s.high = n1;
  628.           *rp = rr.ll;
  629.         }
  630.         }
  631.       else
  632.         {
  633.           USItype m1, m0;
  634.           /* Normalize.  */
  635.  
  636.           b = SI_TYPE_SIZE - bm;
  637.  
  638.           d1 = (d1 << bm) | (d0 >> b);
  639.           d0 = d0 << bm;
  640.           n2 = n1 >> b;
  641.           n1 = (n1 << bm) | (n0 >> b);
  642.           n0 = n0 << bm;
  643.  
  644.           udiv_qrnnd (q0, n1, n2, n1, d1);
  645.           umul_ppmm (m1, m0, q0, d0);
  646.  
  647.           if (m1 > n1 || (m1 == n1 && m0 > n0))
  648.         {
  649.           q0--;
  650.           sub_ddmmss (m1, m0, m1, m0, d1, d0);
  651.         }
  652.  
  653.           q1 = 0;
  654.  
  655.           /* Remainder in (n1n0 - m1m0) >> bm.  */
  656.           if (rp != 0)
  657.         {
  658.           sub_ddmmss (n1, n0, n1, n0, m1, m0);
  659.           rr.s.low = (n1 << b) | (n0 >> bm);
  660.           rr.s.high = n1 >> bm;
  661.           *rp = rr.ll;
  662.         }
  663.         }
  664.     }
  665.     }
  666.  
  667.   ww.s.low = q0;
  668.   ww.s.high = q1;
  669.   return ww.ll;
  670. }
  671. #endif
  672.  
  673. #ifdef L_divdi3
  674. UDItype __udivmoddi4 ();
  675.  
  676. PRIVATE_EXTERN
  677. DItype
  678. __divdi3 (u, v)
  679.      DItype u, v;
  680. {
  681.   word_type c = 0;
  682.   DIunion uu, vv;
  683.   DItype w;
  684.  
  685.   uu.ll = u;
  686.   vv.ll = v;
  687.  
  688.   if (uu.s.high < 0)
  689.     c = ~c,
  690.     uu.ll = __negdi2 (uu.ll);
  691.   if (vv.s.high < 0)
  692.     c = ~c,
  693.     vv.ll = __negdi2 (vv.ll);
  694.  
  695.   w = __udivmoddi4 (uu.ll, vv.ll, (UDItype *) 0);
  696.   if (c)
  697.     w = __negdi2 (w);
  698.  
  699.   return w;
  700. }
  701. #endif
  702.  
  703. #ifdef L_moddi3
  704. UDItype __udivmoddi4 ();
  705. PRIVATE_EXTERN
  706. DItype
  707. __moddi3 (u, v)
  708.      DItype u, v;
  709. {
  710.   word_type c = 0;
  711.   DIunion uu, vv;
  712.   DItype w;
  713.  
  714.   uu.ll = u;
  715.   vv.ll = v;
  716.  
  717.   if (uu.s.high < 0)
  718.     c = ~c,
  719.     uu.ll = __negdi2 (uu.ll);
  720.   if (vv.s.high < 0)
  721.     vv.ll = __negdi2 (vv.ll);
  722.  
  723.   (void) __udivmoddi4 (uu.ll, vv.ll, &w);
  724.   if (c)
  725.     w = __negdi2 (w);
  726.  
  727.   return w;
  728. }
  729. #endif
  730.  
  731. #ifdef L_umoddi3
  732. UDItype __udivmoddi4 ();
  733. PRIVATE_EXTERN
  734. UDItype
  735. __umoddi3 (u, v)
  736.      UDItype u, v;
  737. {
  738.   UDItype w;
  739.  
  740.   (void) __udivmoddi4 (u, v, &w);
  741.  
  742.   return w;
  743. }
  744. #endif
  745.  
  746. #ifdef L_udivdi3
  747. UDItype __udivmoddi4 ();
  748. PRIVATE_EXTERN
  749. UDItype
  750. __udivdi3 (n, d)
  751.      UDItype n, d;
  752. {
  753.   return __udivmoddi4 (n, d, (UDItype *) 0);
  754. }
  755. #endif
  756.  
  757. #ifdef L_cmpdi2
  758. PRIVATE_EXTERN
  759. word_type
  760. __cmpdi2 (a, b)
  761.      DItype a, b;
  762. {
  763.   DIunion au, bu;
  764.  
  765.   au.ll = a, bu.ll = b;
  766.  
  767.   if (au.s.high < bu.s.high)
  768.     return 0;
  769.   else if (au.s.high > bu.s.high)
  770.     return 2;
  771.   if ((USItype) au.s.low < (USItype) bu.s.low)
  772.     return 0;
  773.   else if ((USItype) au.s.low > (USItype) bu.s.low)
  774.     return 2;
  775.   return 1;
  776. }
  777. #endif
  778.  
  779. #ifdef L_ucmpdi2
  780. PRIVATE_EXTERN
  781. word_type
  782. __ucmpdi2 (a, b)
  783.      DItype a, b;
  784. {
  785.   DIunion au, bu;
  786.  
  787.   au.ll = a, bu.ll = b;
  788.  
  789.   if ((USItype) au.s.high < (USItype) bu.s.high)
  790.     return 0;
  791.   else if ((USItype) au.s.high > (USItype) bu.s.high)
  792.     return 2;
  793.   if ((USItype) au.s.low < (USItype) bu.s.low)
  794.     return 0;
  795.   else if ((USItype) au.s.low > (USItype) bu.s.low)
  796.     return 2;
  797.   return 1;
  798. }
  799. #endif
  800.  
  801. #if defined(L_fixunstfdi) && (LONG_DOUBLE_TYPE_SIZE == 128)
  802. #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
  803. #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
  804.  
  805. PRIVATE_EXTERN
  806. DItype
  807. __fixunstfdi (a)
  808.      TFtype a;
  809. {
  810.   TFtype b;
  811.   UDItype v;
  812.  
  813.   if (a < 0)
  814.     return 0;
  815.  
  816.   /* Compute high word of result, as a flonum.  */
  817.   b = (a / HIGH_WORD_COEFF);
  818.   /* Convert that to fixed (but not to DItype!),
  819.      and shift it into the high word.  */
  820.   v = (USItype) b;
  821.   v <<= WORD_SIZE;
  822.   /* Remove high part from the TFtype, leaving the low part as flonum.  */
  823.   a -= (TFtype)v;
  824.   /* Convert that to fixed (but not to DItype!) and add it in.
  825.      Sometimes A comes out negative.  This is significant, since
  826.      A has more bits than a long int does.  */
  827.   if (a < 0)
  828.     v -= (USItype) (- a);
  829.   else
  830.     v += (USItype) a;
  831.   return v;
  832. }
  833. #endif
  834.  
  835. #if defined(L_fixtfdi) && (LONG_DOUBLE_TYPE_SIZE == 128)
  836. PRIVATE_EXTERN
  837. DItype
  838. __fixtfdi (a)
  839.      TFtype a;
  840. {
  841.   if (a < 0)
  842.     return - __fixunstfdi (-a);
  843.   return __fixunstfdi (a);
  844. }
  845. #endif
  846.  
  847. #if defined(L_fixunsxfdi) && (LONG_DOUBLE_TYPE_SIZE == 96)
  848. #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
  849. #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
  850.  
  851. PRIVATE_EXTERN
  852. DItype
  853. __fixunsxfdi (a)
  854.      XFtype a;
  855. {
  856.   XFtype b;
  857.   UDItype v;
  858.  
  859.   if (a < 0)
  860.     return 0;
  861.  
  862.   /* Compute high word of result, as a flonum.  */
  863.   b = (a / HIGH_WORD_COEFF);
  864.   /* Convert that to fixed (but not to DItype!),
  865.      and shift it into the high word.  */
  866.   v = (USItype) b;
  867.   v <<= WORD_SIZE;
  868.   /* Remove high part from the XFtype, leaving the low part as flonum.  */
  869.   a -= (XFtype)v;
  870.   /* Convert that to fixed (but not to DItype!) and add it in.
  871.      Sometimes A comes out negative.  This is significant, since
  872.      A has more bits than a long int does.  */
  873.   if (a < 0)
  874.     v -= (USItype) (- a);
  875.   else
  876.     v += (USItype) a;
  877.   return v;
  878. }
  879. #endif
  880.  
  881. #if defined(L_fixxfdi) && (LONG_DOUBLE_TYPE_SIZE == 96)
  882. PRIVATE_EXTERN
  883. DItype
  884. __fixxfdi (a)
  885.      XFtype a;
  886. {
  887.   if (a < 0)
  888.     return - __fixunsxfdi (-a);
  889.   return __fixunsxfdi (a);
  890. }
  891. #endif
  892.  
  893. #ifdef L_fixunsdfdi
  894. #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
  895. #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
  896.  
  897. PRIVATE_EXTERN
  898. DItype
  899. __fixunsdfdi (a)
  900.      DFtype a;
  901. {
  902.   DFtype b;
  903.   UDItype v;
  904.  
  905.   if (a < 0)
  906.     return 0;
  907.  
  908.   /* Compute high word of result, as a flonum.  */
  909.   b = (a / HIGH_WORD_COEFF);
  910.   /* Convert that to fixed (but not to DItype!),
  911.      and shift it into the high word.  */
  912.   v = (USItype) b;
  913.   v <<= WORD_SIZE;
  914.   /* Remove high part from the DFtype, leaving the low part as flonum.  */
  915.   a -= (DFtype)v;
  916.   /* Convert that to fixed (but not to DItype!) and add it in.
  917.      Sometimes A comes out negative.  This is significant, since
  918.      A has more bits than a long int does.  */
  919.   if (a < 0)
  920.     v -= (USItype) (- a);
  921.   else
  922.     v += (USItype) a;
  923.   return v;
  924. }
  925. #endif
  926.  
  927. #ifdef L_fixdfdi
  928. PRIVATE_EXTERN
  929. DItype
  930. __fixdfdi (a)
  931.      DFtype a;
  932. {
  933.   if (a < 0)
  934.     return - __fixunsdfdi (-a);
  935.   return __fixunsdfdi (a);
  936. }
  937. #endif
  938.  
  939. #ifdef L_fixunssfdi
  940. #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
  941. #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
  942.  
  943. PRIVATE_EXTERN
  944. DItype
  945. __fixunssfdi (SFtype original_a)
  946. {
  947.   /* Convert the SFtype to a DFtype, because that is surely not going
  948.      to lose any bits.  Some day someone else can write a faster version
  949.      that avoids converting to DFtype, and verify it really works right.  */
  950.   DFtype a = original_a;
  951.   DFtype b;
  952.   UDItype v;
  953.  
  954.   if (a < 0)
  955.     return 0;
  956.  
  957.   /* Compute high word of result, as a flonum.  */
  958.   b = (a / HIGH_WORD_COEFF);
  959.   /* Convert that to fixed (but not to DItype!),
  960.      and shift it into the high word.  */
  961.   v = (USItype) b;
  962.   v <<= WORD_SIZE;
  963.   /* Remove high part from the DFtype, leaving the low part as flonum.  */
  964.   a -= (DFtype)v;
  965.   /* Convert that to fixed (but not to DItype!) and add it in.
  966.      Sometimes A comes out negative.  This is significant, since
  967.      A has more bits than a long int does.  */
  968.   if (a < 0)
  969.     v -= (USItype) (- a);
  970.   else
  971.     v += (USItype) a;
  972.   return v;
  973. }
  974. #endif
  975.  
  976. #ifdef L_fixsfdi
  977. PRIVATE_EXTERN
  978. DItype
  979. __fixsfdi (SFtype a)
  980. {
  981.   if (a < 0)
  982.     return - __fixunssfdi (-a);
  983.   return __fixunssfdi (a);
  984. }
  985. #endif
  986.  
  987. #if defined(L_floatdixf) && (LONG_DOUBLE_TYPE_SIZE == 96)
  988. #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
  989. #define HIGH_HALFWORD_COEFF (((UDItype) 1) << (WORD_SIZE / 2))
  990. #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
  991.  
  992. PRIVATE_EXTERN
  993. XFtype
  994. __floatdixf (u)
  995.      DItype u;
  996. {
  997.   XFtype d;
  998.   SItype negate = 0;
  999.  
  1000.   if (u < 0)
  1001.     u = -u, negate = 1;
  1002.  
  1003.   d = (USItype) (u >> WORD_SIZE);
  1004.   d *= HIGH_HALFWORD_COEFF;
  1005.   d *= HIGH_HALFWORD_COEFF;
  1006.   d += (USItype) (u & (HIGH_WORD_COEFF - 1));
  1007.  
  1008.   return (negate ? -d : d);
  1009. }
  1010. #endif
  1011.  
  1012. #if defined(L_floatditf) && (LONG_DOUBLE_TYPE_SIZE == 128)
  1013. #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
  1014. #define HIGH_HALFWORD_COEFF (((UDItype) 1) << (WORD_SIZE / 2))
  1015. #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
  1016.  
  1017. PRIVATE_EXTERN
  1018. TFtype
  1019. __floatditf (u)
  1020.      DItype u;
  1021. {
  1022.   TFtype d;
  1023.   SItype negate = 0;
  1024.  
  1025.   if (u < 0)
  1026.     u = -u, negate = 1;
  1027.  
  1028.   d = (USItype) (u >> WORD_SIZE);
  1029.   d *= HIGH_HALFWORD_COEFF;
  1030.   d *= HIGH_HALFWORD_COEFF;
  1031.   d += (USItype) (u & (HIGH_WORD_COEFF - 1));
  1032.  
  1033.   return (negate ? -d : d);
  1034. }
  1035. #endif
  1036.  
  1037. #ifdef L_floatdidf
  1038. #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
  1039. #define HIGH_HALFWORD_COEFF (((UDItype) 1) << (WORD_SIZE / 2))
  1040. #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
  1041.  
  1042. PRIVATE_EXTERN
  1043. DFtype
  1044. __floatdidf (u)
  1045.      DItype u;
  1046. {
  1047.   DFtype d;
  1048.   SItype negate = 0;
  1049.  
  1050.   if (u < 0)
  1051.     u = -u, negate = 1;
  1052.  
  1053.   d = (USItype) (u >> WORD_SIZE);
  1054.   d *= HIGH_HALFWORD_COEFF;
  1055.   d *= HIGH_HALFWORD_COEFF;
  1056.   d += (USItype) (u & (HIGH_WORD_COEFF - 1));
  1057.  
  1058.   return (negate ? -d : d);
  1059. }
  1060. #endif
  1061.  
  1062. #ifdef L_floatdisf
  1063. #define WORD_SIZE (sizeof (SItype) * BITS_PER_UNIT)
  1064. #define HIGH_HALFWORD_COEFF (((UDItype) 1) << (WORD_SIZE / 2))
  1065. #define HIGH_WORD_COEFF (((UDItype) 1) << WORD_SIZE)
  1066. #define DI_SIZE (sizeof (DItype) * BITS_PER_UNIT)
  1067.  
  1068. /* Define codes for all the float formats that we know of.  Note
  1069.    that this is copied from real.h.  */
  1070.    
  1071. #define UNKNOWN_FLOAT_FORMAT 0
  1072. #define IEEE_FLOAT_FORMAT 1
  1073. #define VAX_FLOAT_FORMAT 2
  1074. #define IBM_FLOAT_FORMAT 3
  1075.  
  1076. /* Default to IEEE float if not specified.  Nearly all machines use it.  */
  1077. #ifndef HOST_FLOAT_FORMAT
  1078. #define    HOST_FLOAT_FORMAT    IEEE_FLOAT_FORMAT
  1079. #endif
  1080.  
  1081. #if HOST_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
  1082. #define DF_SIZE 53
  1083. #define SF_SIZE 24
  1084. #endif
  1085.  
  1086. #if HOST_FLOAT_FORMAT == IBM_FLOAT_FORMAT
  1087. #define DF_SIZE 56
  1088. #define SF_SIZE 24
  1089. #endif
  1090.  
  1091. #if HOST_FLOAT_FORMAT == VAX_FLOAT_FORMAT
  1092. #define DF_SIZE 56
  1093. #define SF_SIZE 24
  1094. #endif
  1095.  
  1096. PRIVATE_EXTERN
  1097. SFtype
  1098. __floatdisf (u)
  1099.      DItype u;
  1100. {
  1101.   /* Do the calculation in DFmode
  1102.      so that we don't lose any of the precision of the high word
  1103.      while multiplying it.  */
  1104.   DFtype f;
  1105.   SItype negate = 0;
  1106.  
  1107.   if (u < 0)
  1108.     u = -u, negate = 1;
  1109.  
  1110.   /* Protect against double-rounding error.
  1111.      Represent any low-order bits, that might be truncated in DFmode,
  1112.      by a bit that won't be lost.  The bit can go in anywhere below the
  1113.      rounding position of the SFmode.  A fixed mask and bit position
  1114.      handles all usual configurations.  It doesn't handle the case
  1115.      of 128-bit DImode, however.  */
  1116.   if (DF_SIZE < DI_SIZE
  1117.       && DF_SIZE > (DI_SIZE - DF_SIZE + SF_SIZE))
  1118.     {
  1119. #define REP_BIT ((USItype) 1 << (DI_SIZE - DF_SIZE))
  1120.       if (u >= ((UDItype) 1 << DF_SIZE))
  1121.     {
  1122.       if ((USItype) u & (REP_BIT - 1))
  1123.         u |= REP_BIT;
  1124.     }
  1125.     }
  1126.   f = (USItype) (u >> WORD_SIZE);
  1127.   f *= HIGH_HALFWORD_COEFF;
  1128.   f *= HIGH_HALFWORD_COEFF;
  1129.   f += (USItype) (u & (HIGH_WORD_COEFF - 1));
  1130.  
  1131.   return (SFtype) (negate ? -f : f);
  1132. }
  1133. #endif
  1134.  
  1135. #if defined(L_fixunsxfsi) && LONG_DOUBLE_TYPE_SIZE == 96
  1136. /* Reenable the normal types, in case limits.h needs them.  */
  1137. #undef char
  1138. #undef short
  1139. #undef int
  1140. #undef long
  1141. #undef unsigned
  1142. #undef float
  1143. #undef double
  1144. #undef MIN
  1145. #undef MAX
  1146. #include <limits.h>
  1147.  
  1148. PRIVATE_EXTERN
  1149. USItype
  1150. __fixunsxfsi (a)
  1151.      XFtype a;
  1152. {
  1153.   if (a >= - (DFtype) LONG_MIN)
  1154.     return (SItype) (a + LONG_MIN) - LONG_MIN;
  1155.   return (SItype) a;
  1156. }
  1157. #endif
  1158.  
  1159. #ifdef L_fixunsdfsi
  1160. /* Reenable the normal types, in case limits.h needs them.  */
  1161. #undef char
  1162. #undef short
  1163. #undef int
  1164. #undef long
  1165. #undef unsigned
  1166. #undef float
  1167. #undef double
  1168. #undef MIN
  1169. #undef MAX
  1170. #include <limits.h>
  1171.  
  1172. PRIVATE_EXTERN
  1173. USItype
  1174. __fixunsdfsi (a)
  1175.      DFtype a;
  1176. {
  1177.   if (a >= - (DFtype) LONG_MIN)
  1178.     return (SItype) (a + LONG_MIN) - LONG_MIN;
  1179.   return (SItype) a;
  1180. }
  1181. #endif
  1182.  
  1183. #ifdef L_fixunssfsi
  1184. /* Reenable the normal types, in case limits.h needs them.  */
  1185. #undef char
  1186. #undef short
  1187. #undef int
  1188. #undef long
  1189. #undef unsigned
  1190. #undef float
  1191. #undef double
  1192. #undef MIN
  1193. #undef MAX
  1194. #include <limits.h>
  1195.  
  1196. PRIVATE_EXTERN
  1197. USItype
  1198. __fixunssfsi (SFtype a)
  1199. {
  1200.   if (a >= - (SFtype) LONG_MIN)
  1201.     return (SItype) (a + LONG_MIN) - LONG_MIN;
  1202.   return (SItype) a;
  1203. }
  1204. #endif
  1205.  
  1206. /* From here on down, the routines use normal data types.  */
  1207.  
  1208. #define SItype bogus_type
  1209. #define USItype bogus_type
  1210. #define DItype bogus_type
  1211. #define UDItype bogus_type
  1212. #define SFtype bogus_type
  1213. #define DFtype bogus_type
  1214.  
  1215. #undef char
  1216. #undef short
  1217. #undef int
  1218. #undef long
  1219. #undef unsigned
  1220. #undef float
  1221. #undef double
  1222.  
  1223. #ifdef L__gcc_bcmp
  1224.  
  1225. /* Like bcmp except the sign is meaningful.
  1226.    Result is negative if S1 is less than S2,
  1227.    positive if S1 is greater, 0 if S1 and S2 are equal.  */
  1228.  
  1229. PRIVATE_EXTERN
  1230. int
  1231. __gcc_bcmp (s1, s2, size)
  1232.      unsigned char *s1, *s2;
  1233.      size_t size;
  1234. {
  1235.   while (size > 0)
  1236.     {
  1237.       unsigned char c1 = *s1++, c2 = *s2++;
  1238.       if (c1 != c2)
  1239.     return c1 - c2;
  1240.       size--;
  1241.     }
  1242.   return 0;
  1243. }
  1244.  
  1245. #endif
  1246.  
  1247. #ifdef L_varargs
  1248. #ifdef __i860__
  1249. #if defined(__svr4__) || defined(__alliant__)
  1250.     asm ("    .text");
  1251.     asm ("    .align    4");
  1252.  
  1253. /* The Alliant needs the added underscore.  */
  1254.     asm (".globl    __builtin_saveregs");
  1255. asm ("__builtin_saveregs:");
  1256.     asm (".globl    ___builtin_saveregs");
  1257. asm ("___builtin_saveregs:");
  1258.  
  1259.         asm ("    andnot    0x0f,%sp,%sp");    /* round down to 16-byte boundary */
  1260.     asm ("    adds    -96,%sp,%sp");  /* allocate stack space for reg save
  1261.                        area and also for a new va_list
  1262.                        structure */
  1263.     /* Save all argument registers in the arg reg save area.  The
  1264.        arg reg save area must have the following layout (according
  1265.        to the svr4 ABI):
  1266.  
  1267.         struct {
  1268.           union  {
  1269.             float freg[8];
  1270.             double dreg[4];
  1271.           } float_regs;
  1272.           long    ireg[12];
  1273.         };
  1274.     */
  1275.  
  1276.     asm ("    fst.q    %f8,  0(%sp)"); /* save floating regs (f8-f15)  */
  1277.     asm ("    fst.q    %f12,16(%sp)"); 
  1278.  
  1279.     asm ("    st.l    %r16,32(%sp)"); /* save integer regs (r16-r27) */
  1280.     asm ("    st.l    %r17,36(%sp)"); 
  1281.     asm ("    st.l    %r18,40(%sp)");
  1282.     asm ("    st.l    %r19,44(%sp)");
  1283.     asm ("    st.l    %r20,48(%sp)");
  1284.     asm ("    st.l    %r21,52(%sp)");
  1285.     asm ("    st.l    %r22,56(%sp)");
  1286.     asm ("    st.l    %r23,60(%sp)");
  1287.     asm ("    st.l    %r24,64(%sp)");
  1288.     asm ("    st.l    %r25,68(%sp)");
  1289.     asm ("    st.l    %r26,72(%sp)");
  1290.     asm ("    st.l    %r27,76(%sp)");
  1291.  
  1292.     asm ("    adds    80,%sp,%r16");  /* compute the address of the new
  1293.                        va_list structure.  Put in into
  1294.                        r16 so that it will be returned
  1295.                        to the caller.  */
  1296.  
  1297.     /* Initialize all fields of the new va_list structure.  This
  1298.        structure looks like:
  1299.  
  1300.         typedef struct {
  1301.             unsigned long    ireg_used;
  1302.             unsigned long    freg_used;
  1303.             long        *reg_base;
  1304.             long        *mem_ptr;
  1305.         } va_list;
  1306.     */
  1307.  
  1308.     asm ("    st.l    %r0, 0(%r16)"); /* nfixed */
  1309.     asm ("    st.l    %r0, 4(%r16)"); /* nfloating */
  1310.     asm ("  st.l    %sp, 8(%r16)"); /* __va_ctl points to __va_struct.  */
  1311.     asm ("    bri    %r1");        /* delayed return */
  1312.     asm ("    st.l    %r28,12(%r16)"); /* pointer to overflow args */
  1313.  
  1314. #else /* not __svr4__ */
  1315. #if defined(__PARAGON__)
  1316.     /*
  1317.      *    we'll use SVR4-ish varargs but need SVR3.2 assembler syntax,
  1318.      *    and we stand a better chance of hooking into libraries
  1319.      *    compiled by PGI.  [andyp@ssd.intel.com]
  1320.      */
  1321.     asm ("    .text");
  1322.     asm ("    .align    4");
  1323.     asm (".globl    __builtin_saveregs");
  1324. asm ("__builtin_saveregs:");
  1325.     asm (".globl    ___builtin_saveregs");
  1326. asm ("___builtin_saveregs:");
  1327.  
  1328.         asm ("    andnot    0x0f,sp,sp");    /* round down to 16-byte boundary */
  1329.     asm ("    adds    -96,sp,sp");    /* allocate stack space for reg save
  1330.                        area and also for a new va_list
  1331.                        structure */
  1332.     /* Save all argument registers in the arg reg save area.  The
  1333.        arg reg save area must have the following layout (according
  1334.        to the svr4 ABI):
  1335.  
  1336.         struct {
  1337.           union  {
  1338.             float freg[8];
  1339.             double dreg[4];
  1340.           } float_regs;
  1341.           long    ireg[12];
  1342.         };
  1343.     */
  1344.  
  1345.     asm ("    fst.q    f8,  0(sp)");
  1346.     asm ("    fst.q    f12,16(sp)"); 
  1347.     asm ("    st.l    r16,32(sp)");
  1348.     asm ("    st.l    r17,36(sp)"); 
  1349.     asm ("    st.l    r18,40(sp)");
  1350.     asm ("    st.l    r19,44(sp)");
  1351.     asm ("    st.l    r20,48(sp)");
  1352.     asm ("    st.l    r21,52(sp)");
  1353.     asm ("    st.l    r22,56(sp)");
  1354.     asm ("    st.l    r23,60(sp)");
  1355.     asm ("    st.l    r24,64(sp)");
  1356.     asm ("    st.l    r25,68(sp)");
  1357.     asm ("    st.l    r26,72(sp)");
  1358.     asm ("    st.l    r27,76(sp)");
  1359.  
  1360.     asm ("    adds    80,sp,r16");  /* compute the address of the new
  1361.                        va_list structure.  Put in into
  1362.                        r16 so that it will be returned
  1363.                        to the caller.  */
  1364.  
  1365.     /* Initialize all fields of the new va_list structure.  This
  1366.        structure looks like:
  1367.  
  1368.         typedef struct {
  1369.             unsigned long    ireg_used;
  1370.             unsigned long    freg_used;
  1371.             long        *reg_base;
  1372.             long        *mem_ptr;
  1373.         } va_list;
  1374.     */
  1375.  
  1376.     asm ("    st.l    r0, 0(r16)"); /* nfixed */
  1377.     asm ("    st.l    r0, 4(r16)"); /* nfloating */
  1378.     asm ("  st.l    sp, 8(r16)"); /* __va_ctl points to __va_struct.  */
  1379.     asm ("    bri    r1");        /* delayed return */
  1380.     asm ("     st.l    r28,12(r16)"); /* pointer to overflow args */
  1381. #else /* not __PARAGON__ */
  1382.     asm ("    .text");
  1383.     asm ("    .align    4");
  1384.  
  1385.     asm (".globl    ___builtin_saveregs");
  1386.     asm ("___builtin_saveregs:");
  1387.     asm ("    mov    sp,r30");
  1388.     asm ("    andnot    0x0f,sp,sp");
  1389.     asm ("    adds    -96,sp,sp");  /* allocate sufficient space on the stack */
  1390.  
  1391. /* Fill in the __va_struct.  */
  1392.     asm ("    st.l    r16, 0(sp)"); /* save integer regs (r16-r27) */
  1393.     asm ("    st.l    r17, 4(sp)"); /* int    fixed[12] */
  1394.     asm ("    st.l    r18, 8(sp)");
  1395.     asm ("    st.l    r19,12(sp)");
  1396.     asm ("    st.l    r20,16(sp)");
  1397.     asm ("    st.l    r21,20(sp)");
  1398.     asm ("    st.l    r22,24(sp)");
  1399.     asm ("    st.l    r23,28(sp)");
  1400.     asm ("    st.l    r24,32(sp)");
  1401.     asm ("    st.l    r25,36(sp)");
  1402.     asm ("    st.l    r26,40(sp)");
  1403.     asm ("    st.l    r27,44(sp)");
  1404.  
  1405.     asm ("    fst.q    f8, 48(sp)"); /* save floating regs (f8-f15) */
  1406.     asm ("    fst.q    f12,64(sp)"); /* int floating[8] */
  1407.  
  1408. /* Fill in the __va_ctl.  */
  1409.     asm ("  st.l    sp, 80(sp)"); /* __va_ctl points to __va_struct.  */
  1410.     asm ("    st.l    r28,84(sp)"); /* pointer to more args */
  1411.     asm ("    st.l    r0, 88(sp)"); /* nfixed */
  1412.     asm ("    st.l    r0, 92(sp)"); /* nfloating */
  1413.  
  1414.     asm ("    adds    80,sp,r16");  /* return address of the __va_ctl.  */
  1415.     asm ("    bri    r1");
  1416.     asm ("    mov    r30,sp");
  1417.                 /* recover stack and pass address to start 
  1418.                    of data.  */
  1419. #endif /* not __PARAGON__ */
  1420. #endif /* not __svr4__ */
  1421. #else /* not __i860__ */
  1422. #ifdef __sparc__
  1423. #ifndef NEXT_SEMANTICS
  1424.     asm (".global __builtin_saveregs");
  1425.     asm ("__builtin_saveregs:");
  1426. #endif
  1427.     asm (PRIVATE_EXTERN_ASM_OP " ___builtin_saveregs");
  1428.     asm ("___builtin_saveregs:");
  1429. #ifdef NEED_PROC_COMMAND
  1430.     asm (".proc 020");
  1431. #endif
  1432.     asm ("st %i0,[%fp+68]");
  1433.     asm ("st %i1,[%fp+72]");
  1434.     asm ("st %i2,[%fp+76]");
  1435.     asm ("st %i3,[%fp+80]");
  1436.     asm ("st %i4,[%fp+84]");
  1437.     asm ("retl");
  1438.     asm ("st %i5,[%fp+88]");
  1439. #ifdef NEED_TYPE_COMMAND
  1440. #ifndef NEXT_SEMANTICS
  1441.     asm (".type __builtin_saveregs,#function");
  1442.     asm (".size __builtin_saveregs,.-__builtin_saveregs");
  1443. #endif
  1444. #endif
  1445. #else /* not __sparc__ */
  1446. #if defined(__MIPSEL__) | defined(__R3000__) | defined(__R2000__) | defined(__mips__)
  1447.  
  1448.   asm ("    .text");
  1449.   asm ("    .ent __builtin_saveregs");
  1450.   asm ("    .globl __builtin_saveregs");
  1451.   asm ("__builtin_saveregs:");
  1452.   asm ("    sw    $4,0($30)");
  1453.   asm ("    sw    $5,4($30)");
  1454.   asm ("    sw    $6,8($30)");
  1455.   asm ("    sw    $7,12($30)");
  1456.   asm ("    j    $31");
  1457.   asm ("    .end __builtin_saveregs");
  1458. #else /* not __mips__, etc. */
  1459.  
  1460. PRIVATE_EXTERN
  1461. void *
  1462. __builtin_saveregs ()
  1463. {
  1464.   abort ();
  1465. }
  1466.  
  1467. #endif /* not __mips__ */
  1468. #endif /* not __sparc__ */
  1469. #endif /* not __i860__ */
  1470. #endif
  1471.  
  1472. #ifdef L_eprintf
  1473. #ifndef inhibit_libc
  1474.  
  1475. #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch.  */
  1476. #include <stdio.h>
  1477. /* This is used by the `assert' macro.  */
  1478. PRIVATE_EXTERN
  1479. void
  1480. __eprintf (string, expression, line, filename)
  1481.      const char *string;
  1482.      const char *expression;
  1483.      int line;
  1484.      const char *filename;
  1485. {
  1486.   fprintf (stderr, string, expression, line, filename);
  1487.   fflush (stderr);
  1488.   abort ();
  1489. }
  1490.  
  1491. #endif
  1492. #endif
  1493.  
  1494. #ifdef L_bb
  1495.  
  1496. /* Structure emitted by -a  */
  1497. struct bb
  1498. {
  1499.   long zero_word;
  1500.   const char *filename;
  1501.   long *counts;
  1502.   long ncounts;
  1503.   struct bb *next;
  1504.   const unsigned long *addresses;
  1505.  
  1506.   /* Older GCC's did not emit these fields.  */
  1507.   long nwords;
  1508.   const char **functions;
  1509.   const long *line_nums;
  1510.   const char **filenames;
  1511. };
  1512.  
  1513. #ifdef BLOCK_PROFILER_CODE
  1514. BLOCK_PROFILER_CODE
  1515. #else
  1516. #ifndef inhibit_libc
  1517.  
  1518. /* Simple minded basic block profiling output dumper for
  1519.    systems that don't provide tcov support.  At present,
  1520.    it requires atexit and stdio.  */
  1521.  
  1522. #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch.  */
  1523. #include <stdio.h>
  1524. char *ctime ();
  1525.  
  1526. #ifdef HAVE_ATEXIT
  1527. #ifdef WINNT
  1528. extern int atexit (void (*) (void));
  1529. #else
  1530. extern void atexit (void (*) (void));
  1531. #endif
  1532. #define ON_EXIT(FUNC,ARG) atexit ((FUNC))
  1533. #else
  1534. #ifdef sun
  1535. extern void on_exit (void*, void*);
  1536. #define ON_EXIT(FUNC,ARG) on_exit ((FUNC), (ARG))
  1537. #endif
  1538. #endif
  1539.  
  1540. static struct bb *bb_head;
  1541.  
  1542. /* Return the number of digits needed to print a value */
  1543. /* __inline__ */ static int num_digits (long value, int base)
  1544. {
  1545.   int minus = (value < 0 && base != 16);
  1546.   unsigned long v = (minus) ? -value : value;
  1547.   int ret = minus;
  1548.  
  1549.   do
  1550.     {
  1551.       v /= base;
  1552.       ret++;
  1553.     }
  1554.   while (v);
  1555.  
  1556.   return ret;
  1557. }
  1558.  
  1559. PRIVATE_EXTERN
  1560. void
  1561. __bb_exit_func (void)
  1562. {
  1563.   FILE *file = fopen ("bb.out", "a");
  1564.   long time_value;
  1565.  
  1566.   if (!file)
  1567.     perror ("bb.out");
  1568.  
  1569.   else
  1570.     {
  1571.       struct bb *ptr;
  1572.  
  1573.       /* This is somewhat type incorrect, but it avoids worrying about
  1574.      exactly where time.h is included from.  It should be ok unless
  1575.      a void * differs from other pointer formats, or if sizeof(long)
  1576.      is < sizeof (time_t).  It would be nice if we could assume the
  1577.      use of rationale standards here.  */
  1578.  
  1579.       time((void *) &time_value);
  1580.       fprintf (file, "Basic block profiling finished on %s\n", ctime ((void *) &time_value));
  1581.  
  1582.       /* We check the length field explicitly in order to allow compatibility
  1583.      with older GCC's which did not provide it.  */
  1584.  
  1585.       for (ptr = bb_head; ptr != (struct bb *)0; ptr = ptr->next)
  1586.     {
  1587.       int i;
  1588.       int func_p    = (ptr->nwords >= sizeof (struct bb) && ptr->nwords <= 1000);
  1589.       int line_p    = (func_p && ptr->line_nums);
  1590.       int file_p    = (func_p && ptr->filenames);
  1591.       long ncounts    = ptr->ncounts;
  1592.       long cnt_max  = 0;
  1593.       long line_max = 0;
  1594.       long addr_max = 0;
  1595.       int file_len    = 0;
  1596.       int func_len    = 0;
  1597.       int blk_len    = num_digits (ncounts, 10);
  1598.       int cnt_len;
  1599.       int line_len;
  1600.       int addr_len;
  1601.  
  1602.       fprintf (file, "File %s, %ld basic blocks \n\n",
  1603.            ptr->filename, ncounts);
  1604.  
  1605.       /* Get max values for each field.  */
  1606.       for (i = 0; i < ncounts; i++)
  1607.         {
  1608.           const char *p;
  1609.           int len;
  1610.  
  1611.           if (cnt_max < ptr->counts[i])
  1612.         cnt_max = ptr->counts[i];
  1613.  
  1614.           if (addr_max < ptr->addresses[i])
  1615.         addr_max = ptr->addresses[i];
  1616.  
  1617.           if (line_p && line_max < ptr->line_nums[i])
  1618.         line_max = ptr->line_nums[i];
  1619.  
  1620.           if (func_p)
  1621.         {
  1622.           p = (ptr->functions[i]) ? (ptr->functions[i]) : "<none>";
  1623.           len = strlen (p);
  1624.           if (func_len < len)
  1625.             func_len = len;
  1626.         }
  1627.  
  1628.           if (file_p)
  1629.         {
  1630.           p = (ptr->filenames[i]) ? (ptr->filenames[i]) : "<none>";
  1631.           len = strlen (p);
  1632.           if (file_len < len)
  1633.             file_len = len;
  1634.         }
  1635.         }
  1636.  
  1637.       addr_len = num_digits (addr_max, 16);
  1638.       cnt_len  = num_digits (cnt_max, 10);
  1639.       line_len = num_digits (line_max, 10);
  1640.  
  1641.       /* Now print out the basic block information.  */
  1642.       for (i = 0; i < ncounts; i++)
  1643.         {
  1644.           fprintf (file,
  1645.                "    Block #%*d: executed %*ld time(s) address= 0x%.*lx",
  1646.                blk_len, i+1,
  1647.                cnt_len, ptr->counts[i],
  1648.                addr_len, ptr->addresses[i]);
  1649.  
  1650.           if (func_p)
  1651.         fprintf (file, " function= %-*s", func_len,
  1652.              (ptr->functions[i]) ? ptr->functions[i] : "<none>");
  1653.  
  1654.           if (line_p)
  1655.         fprintf (file, " line= %*ld", line_len, ptr->line_nums[i]);
  1656.  
  1657.           if (file_p)
  1658.         fprintf (file, " file= %s",
  1659.              (ptr->filenames[i]) ? ptr->filenames[i] : "<none>");
  1660.  
  1661.           fprintf (file, "\n");
  1662.         }
  1663.  
  1664.       fprintf (file, "\n");
  1665.       fflush (file);
  1666.     }
  1667.  
  1668.       fprintf (file, "\n\n");
  1669.       fclose (file);
  1670.     }
  1671. }
  1672.  
  1673. PRIVATE_EXTERN
  1674. void
  1675. __bb_init_func (struct bb *blocks)
  1676. {
  1677.   /* User is supposed to check whether the first word is non-0,
  1678.      but just in case.... */
  1679.  
  1680.   if (blocks->zero_word)
  1681.     return;
  1682.  
  1683. #ifdef ON_EXIT
  1684.   /* Initialize destructor.  */
  1685.   if (!bb_head)
  1686.     ON_EXIT (__bb_exit_func, 0);
  1687. #endif
  1688.  
  1689.   /* Set up linked list.  */
  1690.   blocks->zero_word = 1;
  1691.   blocks->next = bb_head;
  1692.   bb_head = blocks;
  1693. }
  1694.  
  1695. #endif /* not inhibit_libc */
  1696. #endif /* not BLOCK_PROFILER_CODE */
  1697. #endif /* L_bb */
  1698.  
  1699. /* Default free-store management functions for C++, per sections 12.5 and
  1700.    17.3.3 of the Working Paper. */
  1701.  
  1702. #ifdef L_op_new
  1703. /* operator new (size_t), described in 17.3.3.5.  This function is used by
  1704.    C++ programs to allocate a block of memory to hold a single object. */
  1705.  
  1706. typedef void (*vfp)(void);
  1707. #ifdef NEXT_SEMANTICS
  1708. extern vfp __get_new_handler ();
  1709. #else
  1710. extern vfp __new_handler;
  1711. extern void __default_new_handler (void);
  1712. #endif
  1713.  
  1714. #ifdef WEAK_ALIAS
  1715. void * __builtin_new (size_t sz)
  1716.      __attribute__ ((weak, alias ("___builtin_new")));
  1717. void *
  1718. ___builtin_new (size_t sz)
  1719. #else
  1720. PRIVATE_EXTERN
  1721. void *
  1722. __builtin_new (size_t sz)
  1723. #endif
  1724. {
  1725.   void *p;
  1726. #ifdef NEXT_SEMANTICS
  1727.   vfp handler = __get_new_handler ();
  1728. #else
  1729.   vfp handler = (__new_handler) ? __new_handler : __default_new_handler;
  1730. #endif
  1731.  
  1732.   /* malloc (0) is unpredictable; avoid it.  */
  1733.   if (sz == 0)
  1734.     sz = 1;
  1735.   p = (void *) malloc (sz);
  1736.   while (p == 0)
  1737.     {
  1738.       (*handler) ();
  1739.       p = (void *) malloc (sz);
  1740.     }
  1741.   
  1742.   return p;
  1743. }
  1744. #endif /* L_op_new */
  1745.  
  1746. #ifdef L_op_vnew
  1747. /* void * operator new [] (size_t), described in 17.3.3.6.  This function
  1748.    is used by C++ programs to allocate a block of memory for an array.  */
  1749.  
  1750. extern void * __builtin_new (size_t);
  1751.  
  1752. #ifdef WEAK_ALIAS
  1753. void * __builtin_vec_new (size_t sz)
  1754.      __attribute__ ((weak, alias ("___builtin_vec_new")));
  1755. void *
  1756. ___builtin_vec_new (size_t sz)
  1757. #else
  1758. PRIVATE_EXTERN
  1759. void *
  1760. __builtin_vec_new (size_t sz)
  1761. #endif
  1762. {
  1763.   return __builtin_new (sz);
  1764. }
  1765. #endif /* L_op_vnew */
  1766.  
  1767. #ifdef L_new_handler
  1768. /* set_new_handler (fvoid_t *) and the default new handler, described in
  1769.    17.3.3.2 and 17.3.3.5.  These functions define the result of a failure
  1770.    to allocate the amount of memory requested from operator new or new []. */
  1771.  
  1772. #ifndef inhibit_libc
  1773. /* This gets us __GNU_LIBRARY__.  */
  1774. #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch.  */
  1775. #include <stdio.h>
  1776.  
  1777. #ifdef __GNU_LIBRARY__
  1778.   /* Avoid forcing the library's meaning of `write' on the user program
  1779.      by using the "internal" name (for use within the library)  */
  1780. #define write(fd, buf, n)    __write((fd), (buf), (n))
  1781. #endif
  1782. #endif /* inhibit_libc */
  1783.  
  1784. typedef void (*vfp)(void);
  1785. void __default_new_handler (void);
  1786.  
  1787. #ifdef NEXT_SEMANTICS
  1788. static 
  1789. #endif
  1790. vfp __new_handler = (vfp)0;
  1791.  
  1792. #ifdef NEXT_SEMANTICS
  1793. PRIVATE_EXTERN
  1794. vfp
  1795. __get_new_handler ()
  1796. {
  1797.   return __new_handler;
  1798. }
  1799. #endif
  1800.  
  1801. PRIVATE_EXTERN
  1802. vfp
  1803. set_new_handler (vfp handler)
  1804. {
  1805.   vfp prev_handler;
  1806.  
  1807.   prev_handler = __new_handler;
  1808.   if (handler == 0) handler = __default_new_handler;
  1809.   __new_handler = handler;
  1810.   return prev_handler;
  1811. }
  1812.  
  1813. #define MESSAGE "Virtual memory exceeded in `new'\n"
  1814.  
  1815. PRIVATE_EXTERN
  1816. void
  1817. __default_new_handler ()
  1818. {
  1819. #ifndef inhibit_libc
  1820.   /* don't use fprintf (stderr, ...) because it may need to call malloc.  */
  1821.   /* This should really print the name of the program, but that is hard to
  1822.      do.  We need a standard, clean way to get at the name.  */
  1823.   write (2, MESSAGE, sizeof (MESSAGE));
  1824. #endif
  1825.   /* don't call exit () because that may call global destructors which
  1826.      may cause a loop.  */
  1827.   _exit (-1);
  1828. }
  1829. #endif
  1830.  
  1831. #ifdef L_op_delete
  1832. /* operator delete (void *), described in 17.3.3.3.  This function is used
  1833.    by C++ programs to return to the free store a block of memory allocated
  1834.    as a single object. */
  1835.  
  1836. #ifdef WEAK_ALIAS
  1837. void __builtin_delete (void *ptr)
  1838.      __attribute__ ((weak, alias ("___builtin_delete")));
  1839. void
  1840. ___builtin_delete (void *ptr)
  1841. #else
  1842. PRIVATE_EXTERN
  1843. void
  1844. __builtin_delete (void *ptr)
  1845. #endif
  1846. {
  1847.   if (ptr)
  1848.     free (ptr);
  1849. }
  1850. #endif
  1851.  
  1852. #ifdef L_op_vdel
  1853. /* operator delete [] (void *), described in 17.3.3.4.  This function is
  1854.    used by C++ programs to return to the free store a block of memory
  1855.    allocated as an array. */
  1856.  
  1857. extern void __builtin_delete (void *);
  1858.  
  1859. #ifdef WEAK_ALIAS
  1860. void __builtin_vec_delete (void *ptr)
  1861.      __attribute__ ((weak, alias ("___builtin_vec_delete")));
  1862. void
  1863. ___builtin_vec_delete (void *ptr)
  1864. #else
  1865. PRIVATE_EXTERN
  1866. void
  1867. __builtin_vec_delete (void *ptr)
  1868. #endif
  1869. {
  1870.   __builtin_delete (ptr);
  1871. }
  1872. #endif
  1873.  
  1874. /* End of C++ free-store management functions */
  1875.  
  1876. #ifdef L_shtab
  1877. PRIVATE_EXTERN
  1878. unsigned int __shtab[] = {
  1879.     0x00000001, 0x00000002, 0x00000004, 0x00000008,
  1880.     0x00000010, 0x00000020, 0x00000040, 0x00000080,
  1881.     0x00000100, 0x00000200, 0x00000400, 0x00000800,
  1882.     0x00001000, 0x00002000, 0x00004000, 0x00008000,
  1883.     0x00010000, 0x00020000, 0x00040000, 0x00080000,
  1884.     0x00100000, 0x00200000, 0x00400000, 0x00800000,
  1885.     0x01000000, 0x02000000, 0x04000000, 0x08000000,
  1886.     0x10000000, 0x20000000, 0x40000000, 0x80000000
  1887.   };
  1888. #endif
  1889.  
  1890. #ifdef L_clear_cache
  1891. /* Clear part of an instruction cache.  */
  1892.  
  1893. #define INSN_CACHE_PLANE_SIZE (INSN_CACHE_SIZE / INSN_CACHE_DEPTH)
  1894.  
  1895. PRIVATE_EXTERN
  1896. void
  1897. __clear_cache (beg, end)
  1898.      char *beg, *end;
  1899. {
  1900. #ifdef CLEAR_INSN_CACHE 
  1901.   CLEAR_INSN_CACHE (beg, end);
  1902. #else
  1903. #ifdef INSN_CACHE_SIZE
  1904.   static char array[INSN_CACHE_SIZE + INSN_CACHE_PLANE_SIZE + INSN_CACHE_LINE_WIDTH];
  1905.   static int initialized;
  1906.   int offset;
  1907.   void *start_addr
  1908.   void *end_addr;
  1909.   typedef (*function_ptr) ();
  1910.  
  1911. #if (INSN_CACHE_SIZE / INSN_CACHE_LINE_WIDTH) < 16
  1912.   /* It's cheaper to clear the whole cache.
  1913.      Put in a series of jump instructions so that calling the beginning
  1914.      of the cache will clear the whole thing.  */
  1915.  
  1916.   if (! initialized)
  1917.     {
  1918.       int ptr = (((int) array + INSN_CACHE_LINE_WIDTH - 1)
  1919.          & -INSN_CACHE_LINE_WIDTH);
  1920.       int end_ptr = ptr + INSN_CACHE_SIZE;
  1921.  
  1922.       while (ptr < end_ptr)
  1923.     {
  1924.       *(INSTRUCTION_TYPE *)ptr
  1925.         = JUMP_AHEAD_INSTRUCTION + INSN_CACHE_LINE_WIDTH;
  1926.       ptr += INSN_CACHE_LINE_WIDTH;
  1927.     }
  1928.       *(INSTRUCTION_TYPE *)(ptr - INSN_CACHE_LINE_WIDTH) = RETURN_INSTRUCTION;
  1929.  
  1930.       initialized = 1;
  1931.     }
  1932.  
  1933.   /* Call the beginning of the sequence.  */
  1934.   (((function_ptr) (((int) array + INSN_CACHE_LINE_WIDTH - 1)
  1935.             & -INSN_CACHE_LINE_WIDTH))
  1936.    ());
  1937.  
  1938. #else /* Cache is large.  */
  1939.  
  1940.   if (! initialized)
  1941.     {
  1942.       int ptr = (((int) array + INSN_CACHE_LINE_WIDTH - 1)
  1943.          & -INSN_CACHE_LINE_WIDTH);
  1944.  
  1945.       while (ptr < (int) array + sizeof array)
  1946.     {
  1947.       *(INSTRUCTION_TYPE *)ptr = RETURN_INSTRUCTION;
  1948.       ptr += INSN_CACHE_LINE_WIDTH;
  1949.     }
  1950.  
  1951.       initialized = 1;
  1952.     }
  1953.  
  1954.   /* Find the location in array that occupies the same cache line as BEG.  */
  1955.  
  1956.   offset = ((int) beg & -INSN_CACHE_LINE_WIDTH) & (INSN_CACHE_PLANE_SIZE - 1);
  1957.   start_addr = (((int) (array + INSN_CACHE_PLANE_SIZE - 1)
  1958.          & -INSN_CACHE_PLANE_SIZE)
  1959.         + offset);
  1960.  
  1961.   /* Compute the cache alignment of the place to stop clearing.  */
  1962. #if 0  /* This is not needed for gcc's purposes.  */
  1963.   /* If the block to clear is bigger than a cache plane,
  1964.      we clear the entire cache, and OFFSET is already correct.  */ 
  1965.   if (end < beg + INSN_CACHE_PLANE_SIZE)
  1966. #endif
  1967.     offset = (((int) (end + INSN_CACHE_LINE_WIDTH - 1)
  1968.            & -INSN_CACHE_LINE_WIDTH)
  1969.           & (INSN_CACHE_PLANE_SIZE - 1));
  1970.  
  1971. #if INSN_CACHE_DEPTH > 1
  1972.   end_addr = (start_addr & -INSN_CACHE_PLANE_SIZE) + offset;
  1973.   if (end_addr <= start_addr)
  1974.     end_addr += INSN_CACHE_PLANE_SIZE;
  1975.  
  1976.   for (plane = 0; plane < INSN_CACHE_DEPTH; plane++)
  1977.     {
  1978.       int addr = start_addr + plane * INSN_CACHE_PLANE_SIZE;
  1979.       int stop = end_addr + plane * INSN_CACHE_PLANE_SIZE;
  1980.  
  1981.       while (addr != stop)
  1982.     {
  1983.       /* Call the return instruction at ADDR.  */
  1984.       ((function_ptr) addr) ();
  1985.  
  1986.       addr += INSN_CACHE_LINE_WIDTH;
  1987.     }
  1988.     }
  1989. #else /* just one plane */
  1990.   do
  1991.     {
  1992.       /* Call the return instruction at START_ADDR.  */
  1993.       ((function_ptr) start_addr) ();
  1994.  
  1995.       start_addr += INSN_CACHE_LINE_WIDTH;
  1996.     }
  1997.   while ((start_addr % INSN_CACHE_SIZE) != offset);
  1998. #endif /* just one plane */
  1999. #endif /* Cache is large */
  2000. #endif /* Cache exists */
  2001. #endif /* CLEAR_INSN_CACHE */
  2002. }
  2003.  
  2004. #endif /* L_clear_cache */
  2005.  
  2006. #ifdef L_trampoline
  2007.  
  2008. /* Jump to a trampoline, loading the static chain address.  */
  2009.  
  2010. #ifdef WINNT
  2011.  
  2012. #include <windows.h>
  2013.  
  2014. long getpagesize()
  2015. {
  2016. #ifdef _ALPHA_
  2017.   return 8192;
  2018. #else
  2019.   return 4096;
  2020. #endif
  2021. }
  2022.  
  2023. int mprotect(addr, len, prot)
  2024.   char *addr;
  2025.   int len, prot;
  2026. {
  2027.   int np, op;
  2028.  
  2029.   if (prot == 7) np = 0x40;
  2030.   else if (prot == 5) np = 0x20;
  2031.   else if (prot == 4) np = 0x10;
  2032.   else if (prot == 3) np = 0x04;
  2033.   else if (prot == 1) np = 0x02;
  2034.   else if (prot == 0) np = 0x01;
  2035.  
  2036.   if (VirtualProtect (addr, len, np, &op))
  2037.     return 0;
  2038.   else
  2039.     return -1;
  2040.     
  2041. }
  2042.  
  2043. #endif
  2044.  
  2045. #ifdef TRANSFER_FROM_TRAMPOLINE 
  2046. TRANSFER_FROM_TRAMPOLINE 
  2047. #endif
  2048.  
  2049. #if defined (NeXT) && defined (__MACH__)
  2050.  
  2051. /* Make stack executable so we can call trampolines on stack.
  2052.    This is called from INITIALIZE_TRAMPOLINE in next.h.  */
  2053. #if !defined (NS_TARGET_MAJOR) || NS_TARGET_MAJOR < 4
  2054. #ifdef NeXTStep21
  2055.  #include <mach.h>
  2056. #else
  2057.  #include <mach/mach.h>
  2058. #endif
  2059. #endif /* !defined (NS_TARGET_MAJOR) */
  2060.  
  2061. PRIVATE_EXTERN
  2062. void
  2063. __enable_execute_stack (addr)
  2064.      char *addr;
  2065. {
  2066. #if defined (NEXT_SEMANTICS) && defined (TARGET_V9)
  2067. /* Do not reference target_flags, since otherwise you get an undefined symbol
  2068.    when linking!  */
  2069. #define TARGET_V9_SAVE TARGET_V9
  2070. #undef TARGET_V9
  2071. #define TARGET_V9 0
  2072. #endif
  2073.   char *eaddr = addr + TRAMPOLINE_SIZE;
  2074. #if defined (NEXT_SEMANTICS) && defined (TARGET_V9)
  2075. #undef TARGET_V9
  2076. #define TARGET_V9 TARGET_V9_SAVE
  2077. #endif
  2078. #if !defined (NS_TARGET_MAJOR) || NS_TARGET_MAJOR < 4
  2079.   kern_return_t r;
  2080.   vm_address_t a = (vm_address_t) addr;
  2081.  
  2082.   /* turn on execute access on stack */
  2083.   r = vm_protect (task_self (), a, TRAMPOLINE_SIZE, FALSE, VM_PROT_ALL);
  2084.   if (r != KERN_SUCCESS)
  2085.     {
  2086.       mach_error("vm_protect VM_PROT_ALL", r);
  2087.       exit(1);
  2088.     }
  2089. #endif /* !defined (NS_TARGET_MAJOR) */
  2090.  
  2091.   /* We inline the i-cache invalidation for speed */
  2092.  
  2093. #ifdef CLEAR_INSN_CACHE
  2094.   CLEAR_INSN_CACHE (addr, eaddr);
  2095. #else
  2096.   __clear_cache ((int) addr, (int) eaddr);
  2097. #endif
  2098.  
  2099. #endif /* defined (NeXT) && defined (__MACH__) */
  2100.  
  2101. #ifdef __convex__
  2102.  
  2103. /* Make stack executable so we can call trampolines on stack.
  2104.    This is called from INITIALIZE_TRAMPOLINE in convex.h.  */
  2105.  
  2106. #include <sys/mman.h>
  2107. #include <sys/vmparam.h>
  2108. #include <machine/machparam.h>
  2109.  
  2110. void
  2111. __enable_execute_stack ()
  2112. {
  2113.   int fp;
  2114.   static unsigned lowest = USRSTACK;
  2115.   unsigned current = (unsigned) &fp & -NBPG;
  2116.  
  2117.   if (lowest > current)
  2118.     {
  2119.       unsigned len = lowest - current;
  2120.       mremap (current, &len, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE);
  2121.       lowest = current;
  2122.     }
  2123.  
  2124.   /* Clear instruction cache in case an old trampoline is in it. */
  2125.   asm ("pich");
  2126. }
  2127. #endif /* __convex__ */
  2128.  
  2129. #ifdef __DOLPHIN__
  2130.  
  2131. /* Modified from the convex -code above. */
  2132.  
  2133. #include <sys/param.h>
  2134. #include <errno.h>
  2135. #include <sys/m88kbcs.h>
  2136.  
  2137. void
  2138. __enable_execute_stack ()
  2139. {
  2140.   int save_errno;
  2141.   static unsigned long lowest = USRSTACK;
  2142.   unsigned long current = (unsigned long) &save_errno & -NBPC;
  2143.   
  2144.   /* Ignore errno being set. memctl sets errno to EINVAL whenever the
  2145.      address is seen as 'negative'. That is the case with the stack.   */
  2146.  
  2147.   save_errno=errno;
  2148.   if (lowest > current)
  2149.     {
  2150.       unsigned len=lowest-current;
  2151.       memctl(current,len,MCT_TEXT);
  2152.       lowest = current;
  2153.     }
  2154.   else
  2155.     memctl(current,NBPC,MCT_TEXT);
  2156.   errno=save_errno;
  2157. }
  2158.  
  2159. #endif /* __DOLPHIN__ */
  2160.  
  2161. #ifdef __pyr__
  2162.  
  2163. #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch.  */
  2164. #include <stdio.h>
  2165. #include <sys/mman.h>
  2166. #include <sys/types.h>
  2167. #include <sys/param.h>
  2168. #include <sys/vmmac.h>
  2169.  
  2170. /* Modified from the convex -code above.
  2171.    mremap promises to clear the i-cache. */
  2172.  
  2173. void
  2174. __enable_execute_stack ()
  2175. {
  2176.   int fp;
  2177.   if (mprotect (((unsigned int)&fp/PAGSIZ)*PAGSIZ, PAGSIZ,
  2178.         PROT_READ|PROT_WRITE|PROT_EXEC))
  2179.     {
  2180.       perror ("mprotect in __enable_execute_stack");
  2181.       fflush (stderr);
  2182.       abort ();
  2183.     }
  2184. }
  2185. #endif /* __pyr__ */
  2186. #endif /* L_trampoline */
  2187.  
  2188. #ifdef L__main
  2189.  
  2190. #include "gbl-ctors.h"
  2191. /* Some systems use __main in a way incompatible with its use in gcc, in these
  2192.    cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
  2193.    give the same symbol without quotes for an alternative entry point.  You
  2194.    must define both, or neither. */
  2195. #ifndef NAME__MAIN
  2196. #define NAME__MAIN "__main"
  2197. #define SYMBOL__MAIN __main
  2198. #endif
  2199.  
  2200. #if !defined (INIT_SECTION_ASM_OP) || !defined (OBJECT_FORMAT_ELF) || defined (NEXT_PDO)
  2201. /* Run all the global destructors on exit from the program.  */
  2202.  
  2203. PRIVATE_EXTERN
  2204. void
  2205. __do_global_dtors ()
  2206. {
  2207. #ifdef DO_GLOBAL_DTORS_BODY
  2208.   DO_GLOBAL_DTORS_BODY;
  2209. #else
  2210.   func_ptr *p;
  2211.   for (p = __DTOR_LIST__ + 1; *p; )
  2212.     (*p++) ();
  2213. #endif
  2214. }
  2215. #endif
  2216.  
  2217. #ifndef INIT_SECTION_ASM_OP
  2218. /* Run all the global constructors on entry to the program.  */
  2219.  
  2220. #ifndef ON_EXIT
  2221. #define ON_EXIT(a, b)
  2222. #else
  2223. /* Make sure the exit routine is pulled in to define the globals as
  2224.    bss symbols, just in case the linker does not automatically pull
  2225.    bss definitions from the library.  */
  2226.  
  2227. #ifndef NEXT_SEMANTICS
  2228. extern int _exit_dummy_decl;
  2229. int *_exit_dummy_ref = &_exit_dummy_decl;
  2230. #endif
  2231. #endif /* ON_EXIT */
  2232.  
  2233. void
  2234. __do_global_ctors ()
  2235. {
  2236.   DO_GLOBAL_CTORS_BODY;
  2237.   ON_EXIT (__do_global_dtors, 0);
  2238. }
  2239. #endif /* no INIT_SECTION_ASM_OP */
  2240.  
  2241. #ifdef NEXT_PDO
  2242. /* do some hokey stuff to get automatic _objcInit to work
  2243.    this data location is referenced in the NEXT_PDO runtime
  2244.    so that we can do the magic rendezvous.  */
  2245.  
  2246. #ifdef __osf__
  2247. long int _objcInit_addr;
  2248. #else
  2249. int _objcInit_addr;
  2250. #endif /* __osf__ */
  2251.  
  2252. int __NXArgc;
  2253. char **__NXArgv;
  2254. #endif /* NEXT_PDO */
  2255.  
  2256. #if !defined (INIT_SECTION_ASM_OP) || defined (INVOKE__main)
  2257. /* Subroutine called automatically by `main'.
  2258.    Compiling a global function named `main'
  2259.    produces an automatic call to this function at the beginning.
  2260.  
  2261.    For many systems, this routine calls __do_global_ctors.
  2262.    For systems which support a .init section we use the .init section
  2263.    to run __do_global_ctors, so we need not do anything here.  */
  2264.  
  2265. #if defined (_WIN32) && defined (NEXT_PDO)
  2266. #include <windows.h>
  2267. __declspec (dllimport) void _fpreset ();
  2268. #endif
  2269.  
  2270. #ifdef NEXT_EXTENSION
  2271. int __gnuc_argc;
  2272. const char **__gnuc_argv;
  2273. #endif
  2274.  
  2275. void
  2276. #if defined (NEXT_EXTENSION) || defined (NEXT_PDO)
  2277. SYMBOL__MAIN (int argc, const char **argv)
  2278. #else
  2279. SYMBOL__MAIN ()
  2280. #endif
  2281. {
  2282.   /* Support recursive calls to `main': run initializers just once.  */
  2283.   static int initialized = 0;
  2284.  
  2285. #ifdef NEXT_PDO
  2286. #ifdef sparc
  2287. #define PRECIOUS_REGS "i0", "i1", "i2", "i3", "i4", "i5", \
  2288. "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7",\
  2289.   "o0", "o1", "o2", "o3", "o4", "o5", "o7"
  2290.  
  2291.   asm volatile("mov %%sp,%%g1": :);
  2292.   asm volatile("restore": :);
  2293.   asm volatile("st %%i0,%0": "=m" (__NXArgc): : PRECIOUS_REGS);
  2294.   asm volatile("st %%i1,%0": "=m" (__NXArgv): : PRECIOUS_REGS);
  2295.   asm volatile("save %%g0,0,%%g0": :);
  2296.   asm volatile("mov %%g1,%%sp": :);
  2297. #endif/* def sparc */
  2298. #ifdef hpux
  2299.   extern int __argc_value;
  2300.   extern char **__argv_value;
  2301.  
  2302.   __NXArgc = __argc_value;
  2303.   __NXArgv = __argv_value;
  2304. #endif/* def hpux */
  2305. #if __alpha__ || __alpha
  2306.   asm volatile("stq $16,%0": "=m" (__NXArgc));
  2307.   asm volatile("stq $17,%0": "=m" (__NXArgv));
  2308. #endif
  2309. #ifdef _WIN32
  2310.   extern int __argc;
  2311.   extern char** __argv;
  2312.  
  2313.   __NXArgc = __argc;
  2314.   __NXArgv = __argv;
  2315. #endif _WIN32
  2316. #endif/* def NEXT_PDO */
  2317.  
  2318. #ifdef NEXT_EXTENSION
  2319.   __gnuc_argc = argc;
  2320.   __gnuc_argv = argv;
  2321. #endif
  2322.  
  2323.   if (! initialized)
  2324.     {
  2325.       initialized = 1;
  2326. #if defined (NEXT_PDO) && defined (_WIN32)
  2327.       /* The Microsoft compiler keeps track internally of whether a program
  2328.      uses floating point support and if it does, it will call this
  2329.      function to startup the floating point support.  Initially, the
  2330.      easy way to get gcc to support this is to just call the function
  2331.      directly here when gcc is initialized.  Perhaps we should be doing
  2332.      this the same way MS does it, but I don't know how much of a
  2333.      benefit it is right now.  PDM */
  2334.       _fpreset ();
  2335.       _objcInit_addr = GetProcAddress (GetModuleHandle ("NEXTPDO.DLL"),
  2336.                        "_objcInit");
  2337. #endif /* NEXT_PDO && _WIN32 */
  2338.       __do_global_ctors ();
  2339. #ifdef NEXT_PDO
  2340.       if (_objcInit_addr)
  2341.     ((void (*)())_objcInit_addr)();
  2342. #endif /* NEXT_PDO */
  2343.     }
  2344. }
  2345. #endif /* no INIT_SECTION_ASM_OP or INVOKE__main */
  2346.  
  2347. #if defined (NEXT_PDO) && defined (_WIN32)
  2348. const char* _NSRootDirectory (void)
  2349. {
  2350.   static const char* root = NULL;
  2351.   if (!root)
  2352.     if (!(root = getenv ("NEXT_ROOT")))
  2353.       root = "";
  2354.   return root;
  2355. }
  2356. #endif
  2357.  
  2358. #endif /* L__main */
  2359.  
  2360. #ifdef L_ctors
  2361.  
  2362. #include "gbl-ctors.h"
  2363.  
  2364. /* Provide default definitions for the lists of constructors and
  2365.    destructors, so that we don't get linker errors.  These symbols are
  2366.    intentionally bss symbols, so that gld and/or collect will provide
  2367.    the right values.  */
  2368.  
  2369. /* We declare the lists here with two elements each,
  2370.    so that they are valid empty lists if no other definition is loaded.  */
  2371. #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
  2372. #if defined(__NeXT__) || defined(_AIX)
  2373. /* After 2.3, try this definition on all systems.  */
  2374. PRIVATE_EXTERN
  2375. func_ptr __CTOR_LIST__[2] = {0, 0};
  2376. PRIVATE_EXTERN
  2377. func_ptr __DTOR_LIST__[2] = {0, 0};
  2378. #else
  2379. func_ptr __CTOR_LIST__[2];
  2380. func_ptr __DTOR_LIST__[2];
  2381. #endif
  2382. #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
  2383. #endif /* L_ctors */
  2384.  
  2385. #ifdef L_exit
  2386.  
  2387. #include "gbl-ctors.h"
  2388.  
  2389. #ifndef ON_EXIT
  2390.  
  2391. /* If we have no known way of registering our own __do_global_dtors
  2392.    routine so that it will be invoked at program exit time, then we
  2393.    have to define our own exit routine which will get this to happen.  */
  2394.  
  2395. extern void __do_global_dtors ();
  2396. extern void _cleanup ();
  2397. extern void _exit () __attribute__ ((noreturn));
  2398.  
  2399. void 
  2400. exit (status)
  2401.      int status;
  2402. {
  2403. #if !defined (INIT_SECTION_ASM_OP) || !defined (OBJECT_FORMAT_ELF)
  2404.   __do_global_dtors ();
  2405. #endif
  2406. #ifdef EXIT_BODY
  2407.   EXIT_BODY;
  2408. #else
  2409.   _cleanup ();
  2410. #endif
  2411.   _exit (status);
  2412. }
  2413.  
  2414. #else
  2415. PRIVATE_EXTERN
  2416. int _exit_dummy_decl = 0;    /* prevent compiler & linker warnings */
  2417. #endif
  2418.  
  2419. #endif /* L_exit */
  2420.  
  2421. #ifdef L_eh
  2422. typedef struct {
  2423.   void *start;
  2424.   void *end;
  2425.   void *exception_handler;
  2426. } exception_table;
  2427.  
  2428. struct exception_table_node {
  2429.   exception_table *table;
  2430.   void *start;
  2431.   void *end;
  2432.   struct exception_table_node *next;
  2433. };
  2434.  
  2435. static int except_table_pos;
  2436. static void *except_pc;
  2437. static struct exception_table_node *exception_table_list;
  2438.  
  2439. static exception_table *
  2440. find_exception_table (pc)
  2441.      void* pc;
  2442. {
  2443.   register struct exception_table_node *table = exception_table_list;
  2444.   for ( ; table != 0; table = table->next)
  2445.     {
  2446.       if (table->start <= pc && table->end > pc)
  2447.     return table->table;
  2448.     }
  2449.   return 0;
  2450. }
  2451.  
  2452. /* this routine takes a pc, and the address of the exception handler associated
  2453.    with the closest exception table handler entry associated with that PC,
  2454.    or 0 if there are no table entries the PC fits in.  The algorithm works
  2455.    something like this:
  2456.  
  2457.     while(current_entry exists) {
  2458.         if(current_entry.start < pc )
  2459.             current_entry = next_entry;
  2460.         else {
  2461.             if(prev_entry.start <= pc && prev_entry.end > pc) {
  2462.                 save pointer to prev_entry;
  2463.                 return prev_entry.exception_handler;
  2464.              }
  2465.             else return 0;
  2466.          }
  2467.      }
  2468.     return 0;
  2469.  
  2470.    Assuming a correctly sorted table (ascending order) this routine should
  2471.    return the tightest match...
  2472.  
  2473.    In the advent of a tie, we have to give the last entry, as it represents
  2474.    an inner block.
  2475.  */
  2476.  
  2477.  
  2478. PRIVATE_EXTERN
  2479. void *
  2480. __find_first_exception_table_match(pc)
  2481. void *pc;
  2482. {
  2483.   exception_table *table = find_exception_table (pc);
  2484.   int pos = 0;
  2485.   int best = 0;
  2486.   if (table == 0)
  2487.     return (void*)0;
  2488. #if 0
  2489.   printf("find_first_exception_table_match(): pc = %x!\n",pc);
  2490. #endif
  2491.  
  2492.   except_pc = pc;
  2493.  
  2494. #if 0
  2495.   /* We can't do this yet, as we don't know that the table is sorted.  */
  2496.   do {
  2497.     ++pos;
  2498.     if (table[pos].start > except_pc)
  2499.       /* found the first table[pos].start > except_pc, so the previous
  2500.      entry better be the one we want! */
  2501.       break;
  2502.   } while(table[pos].exception_handler != (void*)-1);
  2503.  
  2504.   --pos;
  2505.   if (table[pos].start <= except_pc && table[pos].end > except_pc)
  2506.     {
  2507.       except_table_pos = pos;
  2508. #if 0
  2509.       printf("find_first_eh_table_match(): found match: %x\n",table[pos].exception_handler);
  2510. #endif
  2511.       return table[pos].exception_handler;
  2512.     }
  2513. #else
  2514.   while (table[++pos].exception_handler != (void*)-1) {
  2515.     if (table[pos].start <= except_pc && table[pos].end > except_pc)
  2516.       {
  2517.     /* This can apply.  Make sure it is better or as good as the previous
  2518.        best.  */
  2519.     /* The best one ends first. */
  2520.     if (best == 0 || (table[pos].end <= table[best].end
  2521.               /* The best one starts last.  */
  2522.               && table[pos].start >= table[best].start))
  2523.       best = pos;
  2524.       }
  2525.   }
  2526.   if (best != 0)
  2527.     return table[best].exception_handler;
  2528. #endif
  2529.  
  2530. #if 0
  2531.   printf("find_first_eh_table_match(): else: returning NULL!\n");
  2532. #endif
  2533.   return (void*)0;
  2534. }
  2535.  
  2536. PRIVATE_EXTERN
  2537. void *
  2538. __throw_type_match (void *catch_type, void *throw_type, void* obj)
  2539. {
  2540. #if 0
  2541.  printf("__throw_type_match (): catch_type = %s, throw_type = %s\n",
  2542.     catch_type, throw_type);
  2543. #endif
  2544.  if (strcmp ((const char *)catch_type, (const char *)throw_type) == 0)
  2545.    return obj;
  2546.  return 0;
  2547. }
  2548.  
  2549. PRIVATE_EXTERN
  2550. void
  2551. __register_exceptions (exception_table *table)
  2552. {
  2553.   struct exception_table_node *node;
  2554.   exception_table *range = table + 1;
  2555.  
  2556.   if (range->start == (void*)-1)
  2557.     return;
  2558.  
  2559.   node = (struct exception_table_node*)
  2560.     malloc (sizeof (struct exception_table_node));
  2561.   node->table = table;
  2562.  
  2563.   /* This look can be optimized away either if the table
  2564.      is sorted, or if we pass in extra parameters. */
  2565.   node->start = range->start;
  2566.   node->end = range->end;
  2567.   for (range++ ; range->start != (void*)(-1); range++)
  2568.     {
  2569.       if (range->start < node->start)
  2570.     node->start = range->start;
  2571.       if (range->end > node->end)
  2572.     node->end = range->end;
  2573.     }
  2574.  
  2575.   node->next = exception_table_list;
  2576.   exception_table_list = node;
  2577. }
  2578.  
  2579. #if #machine(i386)
  2580. PRIVATE_EXTERN
  2581. void
  2582. __unwind_function(void *ptr)
  2583. {
  2584.   asm("movl 8(%esp),%ecx");
  2585.   /* Undo current frame */
  2586.   asm("movl %ebp,%esp");
  2587.   asm("popl %ebp");
  2588.   /* like ret, but stay here */
  2589.   asm("addl $4,%esp");
  2590.   
  2591.   /* Now, undo previous frame. */
  2592.   /* This is a test routine, as we have to dynamically probe to find out
  2593.      what to pop for certain, this is just a guess. */
  2594.   asm("leal -16(%ebp),%esp");
  2595.   asm("pop %ebx");
  2596.   asm("pop %esi");
  2597.   asm("pop %edi");
  2598.   asm("movl %ebp,%esp");
  2599.   asm("popl %ebp");
  2600.  
  2601.   asm("movl %ecx,0(%esp)");
  2602.   asm("ret");
  2603. }
  2604. #elif #machine(rs6000)
  2605. __unwind_function(void *ptr)
  2606. {
  2607.   asm("mr 31,1");
  2608.   asm("l 1,0(1)");
  2609.   asm("l 31,-4(1)");
  2610.   asm("# br");
  2611.  
  2612.   asm("mr 31,1");
  2613.   asm("l 1,0(1)");
  2614.   /* use 31 as a scratch register to restore the link register. */
  2615.   asm("l 31, 8(1);mtlr 31 # l lr,8(1)");
  2616.   asm("l 31,-4(1)");
  2617.   asm("# br");
  2618.   asm("mtctr 3;bctr # b 3");
  2619. }
  2620. #elif #machine(powerpc)
  2621. __unwind_function(void *ptr)
  2622. {
  2623.   asm("mr 31,1");
  2624.   asm("lwz 1,0(1)");
  2625.   asm("lwz 31,-4(1)");
  2626.   asm("# br");
  2627.  
  2628.   asm("mr 31,1");
  2629.   asm("lwz 1,0(1)");
  2630.   /* use 31 as a scratch register to restore the link register. */
  2631.   asm("lwz 31, 8(1);mtlr 31 # l lr,8(1)");
  2632.   asm("lwz 31,-4(1)");
  2633.   asm("# br");
  2634.   asm("mtctr 3;bctr # b 3");
  2635. }
  2636. #elif #machine(vax)
  2637. __unwind_function(void *ptr)
  2638. {
  2639.   __label__ return_again;
  2640.  
  2641.   /* Replace our frame's return address with the label below.
  2642.      During execution, we will first return here instead of to
  2643.      caller, then second return takes caller's frame off the stack.
  2644.      Two returns matches two actual calls, so is less likely to
  2645.      confuse debuggers.  `16' corresponds to RETURN_ADDRESS_OFFSET.  */
  2646.   __asm ("movl %0,16(fp)" : : "p" (&& return_again));
  2647.   return;
  2648.  
  2649.  return_again:
  2650.   return;
  2651. }
  2652. #else
  2653. PRIVATE_EXTERN
  2654. __unwind_function(void *ptr)
  2655. {
  2656.   abort ();
  2657. }
  2658. #endif /* powerpc */
  2659. #endif /* L_eh */
  2660.  
  2661. #ifdef L_pure
  2662. #ifndef inhibit_libc
  2663. /* This gets us __GNU_LIBRARY__.  */
  2664. #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch.  */
  2665. #include <stdio.h>
  2666.  
  2667. #ifdef __GNU_LIBRARY__
  2668.   /* Avoid forcing the library's meaning of `write' on the user program
  2669.      by using the "internal" name (for use within the library)  */
  2670. #define write(fd, buf, n)    __write((fd), (buf), (n))
  2671. #endif
  2672. #endif /* inhibit_libc */
  2673.  
  2674. #define MESSAGE "pure virtual method called\n"
  2675.  
  2676. PRIVATE_EXTERN
  2677. void
  2678. __pure_virtual ()
  2679. {
  2680. #ifndef inhibit_libc
  2681.   write (2, MESSAGE, sizeof (MESSAGE) - 1);
  2682. #endif
  2683.   _exit (-1);
  2684. }
  2685. #endif
  2686.