re PR c++/10779 (Error cascade for unknown type in function prototype)
[gcc.git] / gcc / libgcc2.c
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, 1996, 1997, 1998, 1999,
4 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
11 version.
12
13 In addition to the permissions in the GNU General Public License, the
14 Free Software Foundation gives you unlimited permission to link the
15 compiled version of this file into combinations with other programs,
16 and to distribute those combinations without any restriction coming
17 from the use of this file. (The General Public License restrictions
18 do apply in other respects; for example, they cover modification of
19 the file, and distribution when not linked into a combine
20 executable.)
21
22 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
23 WARRANTY; without even the implied warranty of MERCHANTABILITY or
24 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
25 for more details.
26
27 You should have received a copy of the GNU General Public License
28 along with GCC; see the file COPYING. If not, write to the Free
29 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
30 02111-1307, USA. */
31
32
33 /* We include auto-host.h here to get HAVE_GAS_HIDDEN. This is
34 supposedly valid even though this is a "target" file. */
35 #include "auto-host.h"
36
37 /* It is incorrect to include config.h here, because this file is being
38 compiled for the target, and hence definitions concerning only the host
39 do not apply. */
40 #include "tconfig.h"
41 #include "tsystem.h"
42 #include "coretypes.h"
43 #include "tm.h"
44
45 /* Don't use `fancy_abort' here even if config.h says to use it. */
46 #ifdef abort
47 #undef abort
48 #endif
49
50 #ifdef HAVE_GAS_HIDDEN
51 #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
52 #else
53 #define ATTRIBUTE_HIDDEN
54 #endif
55
56 #include "libgcc2.h"
57 \f
58 #ifdef DECLARE_LIBRARY_RENAMES
59 DECLARE_LIBRARY_RENAMES
60 #endif
61
62 #if defined (L_negdi2)
63 DWtype
64 __negdi2 (DWtype u)
65 {
66 const DWunion uu = {.ll = u};
67 const DWunion w = { {.low = -uu.s.low,
68 .high = -uu.s.high - ((UWtype) -uu.s.low > 0) } };
69
70 return w.ll;
71 }
72 #endif
73
74 #ifdef L_addvsi3
75 Wtype
76 __addvsi3 (Wtype a, Wtype b)
77 {
78 const Wtype w = a + b;
79
80 if (b >= 0 ? w < a : w > a)
81 abort ();
82
83 return w;
84 }
85 #endif
86 \f
87 #ifdef L_addvdi3
88 DWtype
89 __addvdi3 (DWtype a, DWtype b)
90 {
91 const DWtype w = a + b;
92
93 if (b >= 0 ? w < a : w > a)
94 abort ();
95
96 return w;
97 }
98 #endif
99 \f
100 #ifdef L_subvsi3
101 Wtype
102 __subvsi3 (Wtype a, Wtype b)
103 {
104 const DWtype w = a - b;
105
106 if (b >= 0 ? w > a : w < a)
107 abort ();
108
109 return w;
110 }
111 #endif
112 \f
113 #ifdef L_subvdi3
114 DWtype
115 __subvdi3 (DWtype a, DWtype b)
116 {
117 const DWtype w = a - b;
118
119 if (b >= 0 ? w > a : w < a)
120 abort ();
121
122 return w;
123 }
124 #endif
125 \f
126 #ifdef L_mulvsi3
127 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
128 Wtype
129 __mulvsi3 (Wtype a, Wtype b)
130 {
131 const DWtype w = (DWtype) a * (DWtype) b;
132
133 if (((a >= 0) == (b >= 0))
134 ? (UDWtype) w > (UDWtype) (((DWtype) 1 << (WORD_SIZE - 1)) - 1)
135 : (UDWtype) w < (UDWtype) ((DWtype) -1 << (WORD_SIZE - 1)))
136 abort ();
137
138 return w;
139 }
140 #endif
141 \f
142 #ifdef L_negvsi2
143 Wtype
144 __negvsi2 (Wtype a)
145 {
146 const Wtype w = -a;
147
148 if (a >= 0 ? w > 0 : w < 0)
149 abort ();
150
151 return w;
152 }
153 #endif
154 \f
155 #ifdef L_negvdi2
156 DWtype
157 __negvdi2 (DWtype a)
158 {
159 const DWtype w = -a;
160
161 if (a >= 0 ? w > 0 : w < 0)
162 abort ();
163
164 return w;
165 }
166 #endif
167 \f
168 #ifdef L_absvsi2
169 Wtype
170 __absvsi2 (Wtype a)
171 {
172 Wtype w = a;
173
174 if (a < 0)
175 #ifdef L_negvsi2
176 w = __negvsi2 (a);
177 #else
178 w = -a;
179
180 if (w < 0)
181 abort ();
182 #endif
183
184 return w;
185 }
186 #endif
187 \f
188 #ifdef L_absvdi2
189 DWtype
190 __absvdi2 (DWtype a)
191 {
192 DWtype w = a;
193
194 if (a < 0)
195 #ifdef L_negvdi2
196 w = __negvdi2 (a);
197 #else
198 w = -a;
199
200 if (w < 0)
201 abort ();
202 #endif
203
204 return w;
205 }
206 #endif
207 \f
208 #ifdef L_mulvdi3
209 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
210 DWtype
211 __mulvdi3 (DWtype u, DWtype v)
212 {
213 /* The unchecked multiplication needs 3 Wtype x Wtype multiplications,
214 but the checked multiplication needs only two. */
215 const DWunion uu = {.ll = u};
216 const DWunion vv = {.ll = v};
217
218 if (__builtin_expect (uu.s.high == uu.s.low >> (WORD_SIZE - 1), 1))
219 {
220 /* u fits in a single Wtype. */
221 if (__builtin_expect (vv.s.high == vv.s.low >> (WORD_SIZE - 1), 1))
222 {
223 /* v fits in a single Wtype as well. */
224 /* A single multiplication. No overflow risk. */
225 return (DWtype) uu.s.low * (DWtype) vv.s.low;
226 }
227 else
228 {
229 /* Two multiplications. */
230 DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low
231 * (UDWtype) (UWtype) vv.s.low};
232 DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.low
233 * (UDWtype) (UWtype) vv.s.high};
234
235 if (vv.s.high < 0)
236 w1.s.high -= uu.s.low;
237 if (uu.s.low < 0)
238 w1.ll -= vv.ll;
239 w1.ll += (UWtype) w0.s.high;
240 if (__builtin_expect (w1.s.high == w1.s.low >> (WORD_SIZE - 1), 1))
241 {
242 w0.s.high = w1.s.low;
243 return w0.ll;
244 }
245 }
246 }
247 else
248 {
249 if (__builtin_expect (vv.s.high == vv.s.low >> (WORD_SIZE - 1), 1))
250 {
251 /* v fits into a single Wtype. */
252 /* Two multiplications. */
253 DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low
254 * (UDWtype) (UWtype) vv.s.low};
255 DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.high
256 * (UDWtype) (UWtype) vv.s.low};
257
258 if (uu.s.high < 0)
259 w1.s.high -= vv.s.low;
260 if (vv.s.low < 0)
261 w1.ll -= uu.ll;
262 w1.ll += (UWtype) w0.s.high;
263 if (__builtin_expect (w1.s.high == w1.s.low >> (WORD_SIZE - 1), 1))
264 {
265 w0.s.high = w1.s.low;
266 return w0.ll;
267 }
268 }
269 else
270 {
271 /* A few sign checks and a single multiplication. */
272 if (uu.s.high >= 0)
273 {
274 if (vv.s.high >= 0)
275 {
276 if (uu.s.high == 0 && vv.s.high == 0)
277 {
278 const DWtype w = (UDWtype) (UWtype) uu.s.low
279 * (UDWtype) (UWtype) vv.s.low;
280 if (__builtin_expect (w >= 0, 1))
281 return w;
282 }
283 }
284 else
285 {
286 if (uu.s.high == 0 && vv.s.high == (Wtype) -1)
287 {
288 DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
289 * (UDWtype) (UWtype) vv.s.low};
290
291 ww.s.high -= uu.s.low;
292 if (__builtin_expect (ww.s.high < 0, 1))
293 return ww.ll;
294 }
295 }
296 }
297 else
298 {
299 if (vv.s.high >= 0)
300 {
301 if (uu.s.high == (Wtype) -1 && vv.s.high == 0)
302 {
303 DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
304 * (UDWtype) (UWtype) vv.s.low};
305
306 ww.s.high -= vv.s.low;
307 if (__builtin_expect (ww.s.high < 0, 1))
308 return ww.ll;
309 }
310 }
311 else
312 {
313 if (uu.s.high == (Wtype) -1 && vv.s.high == (Wtype) - 1)
314 {
315 DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
316 * (UDWtype) (UWtype) vv.s.low};
317
318 ww.s.high -= uu.s.low;
319 ww.s.high -= vv.s.low;
320 if (__builtin_expect (ww.s.high >= 0, 1))
321 return ww.ll;
322 }
323 }
324 }
325 }
326 }
327
328 /* Overflow. */
329 abort ();
330 }
331 #endif
332 \f
333
334 /* Unless shift functions are defined with full ANSI prototypes,
335 parameter b will be promoted to int if word_type is smaller than an int. */
336 #ifdef L_lshrdi3
337 DWtype
338 __lshrdi3 (DWtype u, word_type b)
339 {
340 if (b == 0)
341 return u;
342
343 const DWunion uu = {.ll = u};
344 const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
345 DWunion w;
346
347 if (bm <= 0)
348 {
349 w.s.high = 0;
350 w.s.low = (UWtype) uu.s.high >> -bm;
351 }
352 else
353 {
354 const UWtype carries = (UWtype) uu.s.high << bm;
355
356 w.s.high = (UWtype) uu.s.high >> b;
357 w.s.low = ((UWtype) uu.s.low >> b) | carries;
358 }
359
360 return w.ll;
361 }
362 #endif
363
364 #ifdef L_ashldi3
365 DWtype
366 __ashldi3 (DWtype u, word_type b)
367 {
368 if (b == 0)
369 return u;
370
371 const DWunion uu = {.ll = u};
372 const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
373 DWunion w;
374
375 if (bm <= 0)
376 {
377 w.s.low = 0;
378 w.s.high = (UWtype) uu.s.low << -bm;
379 }
380 else
381 {
382 const UWtype carries = (UWtype) uu.s.low >> bm;
383
384 w.s.low = (UWtype) uu.s.low << b;
385 w.s.high = ((UWtype) uu.s.high << b) | carries;
386 }
387
388 return w.ll;
389 }
390 #endif
391
392 #ifdef L_ashrdi3
393 DWtype
394 __ashrdi3 (DWtype u, word_type b)
395 {
396 if (b == 0)
397 return u;
398
399 const DWunion uu = {.ll = u};
400 const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
401 DWunion w;
402
403 if (bm <= 0)
404 {
405 /* w.s.high = 1..1 or 0..0 */
406 w.s.high = uu.s.high >> (sizeof (Wtype) * BITS_PER_UNIT - 1);
407 w.s.low = uu.s.high >> -bm;
408 }
409 else
410 {
411 const UWtype carries = (UWtype) uu.s.high << bm;
412
413 w.s.high = uu.s.high >> b;
414 w.s.low = ((UWtype) uu.s.low >> b) | carries;
415 }
416
417 return w.ll;
418 }
419 #endif
420 \f
421 #ifdef L_ffssi2
422 #undef int
423 extern int __ffsSI2 (UWtype u);
424 int
425 __ffsSI2 (UWtype u)
426 {
427 UWtype count;
428
429 if (u == 0)
430 return 0;
431
432 count_trailing_zeros (count, u);
433 return count + 1;
434 }
435 #endif
436 \f
437 #ifdef L_ffsdi2
438 #undef int
439 extern int __ffsDI2 (DWtype u);
440 int
441 __ffsDI2 (DWtype u)
442 {
443 const DWunion uu = {.ll = u};
444 UWtype word, count, add;
445
446 if (uu.s.low != 0)
447 word = uu.s.low, add = 0;
448 else if (uu.s.high != 0)
449 word = uu.s.high, add = BITS_PER_UNIT * sizeof (Wtype);
450 else
451 return 0;
452
453 count_trailing_zeros (count, word);
454 return count + add + 1;
455 }
456 #endif
457 \f
458 #ifdef L_muldi3
459 DWtype
460 __muldi3 (DWtype u, DWtype v)
461 {
462 const DWunion uu = {.ll = u};
463 const DWunion vv = {.ll = v};
464 DWunion w = {.ll = __umulsidi3 (uu.s.low, vv.s.low)};
465
466 w.s.high += ((UWtype) uu.s.low * (UWtype) vv.s.high
467 + (UWtype) uu.s.high * (UWtype) vv.s.low);
468
469 return w.ll;
470 }
471 #endif
472 \f
473 #if (defined (L_udivdi3) || defined (L_divdi3) || \
474 defined (L_umoddi3) || defined (L_moddi3))
475 #if defined (sdiv_qrnnd)
476 #define L_udiv_w_sdiv
477 #endif
478 #endif
479
480 #ifdef L_udiv_w_sdiv
481 #if defined (sdiv_qrnnd)
482 #if (defined (L_udivdi3) || defined (L_divdi3) || \
483 defined (L_umoddi3) || defined (L_moddi3))
484 static inline __attribute__ ((__always_inline__))
485 #endif
486 UWtype
487 __udiv_w_sdiv (UWtype *rp, UWtype a1, UWtype a0, UWtype d)
488 {
489 UWtype q, r;
490 UWtype c0, c1, b1;
491
492 if ((Wtype) d >= 0)
493 {
494 if (a1 < d - a1 - (a0 >> (W_TYPE_SIZE - 1)))
495 {
496 /* dividend, divisor, and quotient are nonnegative */
497 sdiv_qrnnd (q, r, a1, a0, d);
498 }
499 else
500 {
501 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */
502 sub_ddmmss (c1, c0, a1, a0, d >> 1, d << (W_TYPE_SIZE - 1));
503 /* Divide (c1*2^32 + c0) by d */
504 sdiv_qrnnd (q, r, c1, c0, d);
505 /* Add 2^31 to quotient */
506 q += (UWtype) 1 << (W_TYPE_SIZE - 1);
507 }
508 }
509 else
510 {
511 b1 = d >> 1; /* d/2, between 2^30 and 2^31 - 1 */
512 c1 = a1 >> 1; /* A/2 */
513 c0 = (a1 << (W_TYPE_SIZE - 1)) + (a0 >> 1);
514
515 if (a1 < b1) /* A < 2^32*b1, so A/2 < 2^31*b1 */
516 {
517 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
518
519 r = 2*r + (a0 & 1); /* Remainder from A/(2*b1) */
520 if ((d & 1) != 0)
521 {
522 if (r >= q)
523 r = r - q;
524 else if (q - r <= d)
525 {
526 r = r - q + d;
527 q--;
528 }
529 else
530 {
531 r = r - q + 2*d;
532 q -= 2;
533 }
534 }
535 }
536 else if (c1 < b1) /* So 2^31 <= (A/2)/b1 < 2^32 */
537 {
538 c1 = (b1 - 1) - c1;
539 c0 = ~c0; /* logical NOT */
540
541 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
542
543 q = ~q; /* (A/2)/b1 */
544 r = (b1 - 1) - r;
545
546 r = 2*r + (a0 & 1); /* A/(2*b1) */
547
548 if ((d & 1) != 0)
549 {
550 if (r >= q)
551 r = r - q;
552 else if (q - r <= d)
553 {
554 r = r - q + d;
555 q--;
556 }
557 else
558 {
559 r = r - q + 2*d;
560 q -= 2;
561 }
562 }
563 }
564 else /* Implies c1 = b1 */
565 { /* Hence a1 = d - 1 = 2*b1 - 1 */
566 if (a0 >= -d)
567 {
568 q = -1;
569 r = a0 + d;
570 }
571 else
572 {
573 q = -2;
574 r = a0 + 2*d;
575 }
576 }
577 }
578
579 *rp = r;
580 return q;
581 }
582 #else
583 /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */
584 UWtype
585 __udiv_w_sdiv (UWtype *rp __attribute__ ((__unused__)),
586 UWtype a1 __attribute__ ((__unused__)),
587 UWtype a0 __attribute__ ((__unused__)),
588 UWtype d __attribute__ ((__unused__)))
589 {
590 return 0;
591 }
592 #endif
593 #endif
594 \f
595 #if (defined (L_udivdi3) || defined (L_divdi3) || \
596 defined (L_umoddi3) || defined (L_moddi3))
597 #define L_udivmoddi4
598 #endif
599
600 #ifdef L_clz
601 const UQItype __clz_tab[] =
602 {
603 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,
604 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,
605 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,
606 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,
607 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,
608 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,
609 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,
610 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,
611 };
612 #endif
613 \f
614 #ifdef L_clzsi2
615 #undef int
616 extern int __clzSI2 (UWtype x);
617 int
618 __clzSI2 (UWtype x)
619 {
620 Wtype ret;
621
622 count_leading_zeros (ret, x);
623
624 return ret;
625 }
626 #endif
627 \f
628 #ifdef L_clzdi2
629 #undef int
630 extern int __clzDI2 (UDWtype x);
631 int
632 __clzDI2 (UDWtype x)
633 {
634 const DWunion uu = {.ll = x};
635 UWtype word;
636 Wtype ret, add;
637
638 if (uu.s.high)
639 word = uu.s.high, add = 0;
640 else
641 word = uu.s.low, add = W_TYPE_SIZE;
642
643 count_leading_zeros (ret, word);
644 return ret + add;
645 }
646 #endif
647 \f
648 #ifdef L_ctzsi2
649 #undef int
650 extern int __ctzSI2 (UWtype x);
651 int
652 __ctzSI2 (UWtype x)
653 {
654 Wtype ret;
655
656 count_trailing_zeros (ret, x);
657
658 return ret;
659 }
660 #endif
661 \f
662 #ifdef L_ctzdi2
663 #undef int
664 extern int __ctzDI2 (UDWtype x);
665 int
666 __ctzDI2 (UDWtype x)
667 {
668 const DWunion uu = {.ll = x};
669 UWtype word;
670 Wtype ret, add;
671
672 if (uu.s.low)
673 word = uu.s.low, add = 0;
674 else
675 word = uu.s.high, add = W_TYPE_SIZE;
676
677 count_trailing_zeros (ret, word);
678 return ret + add;
679 }
680 #endif
681
682 #if (defined (L_popcountsi2) || defined (L_popcountdi2) \
683 || defined (L_popcount_tab))
684 extern const UQItype __popcount_tab[] ATTRIBUTE_HIDDEN;
685 #endif
686
687 #ifdef L_popcount_tab
688 const UQItype __popcount_tab[] =
689 {
690 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
691 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
692 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
693 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
694 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
695 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
696 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
697 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8,
698 };
699 #endif
700 \f
701 #ifdef L_popcountsi2
702 #undef int
703 extern int __popcountSI2 (UWtype x);
704 int
705 __popcountSI2 (UWtype x)
706 {
707 UWtype i, ret = 0;
708
709 for (i = 0; i < W_TYPE_SIZE; i += 8)
710 ret += __popcount_tab[(x >> i) & 0xff];
711
712 return ret;
713 }
714 #endif
715 \f
716 #ifdef L_popcountdi2
717 #undef int
718 extern int __popcountDI2 (UDWtype x);
719 int
720 __popcountDI2 (UDWtype x)
721 {
722 UWtype i, ret = 0;
723
724 for (i = 0; i < 2*W_TYPE_SIZE; i += 8)
725 ret += __popcount_tab[(x >> i) & 0xff];
726
727 return ret;
728 }
729 #endif
730 \f
731 #ifdef L_paritysi2
732 #undef int
733 extern int __paritySI2 (UWtype x);
734 int
735 __paritySI2 (UWtype x)
736 {
737 #if W_TYPE_SIZE > 64
738 # error "fill out the table"
739 #endif
740 #if W_TYPE_SIZE > 32
741 x ^= x >> 32;
742 #endif
743 #if W_TYPE_SIZE > 16
744 x ^= x >> 16;
745 #endif
746 x ^= x >> 8;
747 x ^= x >> 4;
748 x &= 0xf;
749 return (0x6996 >> x) & 1;
750 }
751 #endif
752 \f
753 #ifdef L_paritydi2
754 #undef int
755 extern int __parityDI2 (UDWtype x);
756 int
757 __parityDI2 (UDWtype x)
758 {
759 const DWunion uu = {.ll = x};
760 UWtype nx = uu.s.low ^ uu.s.high;
761
762 #if W_TYPE_SIZE > 64
763 # error "fill out the table"
764 #endif
765 #if W_TYPE_SIZE > 32
766 nx ^= nx >> 32;
767 #endif
768 #if W_TYPE_SIZE > 16
769 nx ^= nx >> 16;
770 #endif
771 nx ^= nx >> 8;
772 nx ^= nx >> 4;
773 nx &= 0xf;
774 return (0x6996 >> nx) & 1;
775 }
776 #endif
777
778 #ifdef L_udivmoddi4
779
780 #if (defined (L_udivdi3) || defined (L_divdi3) || \
781 defined (L_umoddi3) || defined (L_moddi3))
782 static inline __attribute__ ((__always_inline__))
783 #endif
784 UDWtype
785 __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
786 {
787 const DWunion nn = {.ll = n};
788 const DWunion dd = {.ll = d};
789 DWunion rr;
790 UWtype d0, d1, n0, n1, n2;
791 UWtype q0, q1;
792 UWtype b, bm;
793
794 d0 = dd.s.low;
795 d1 = dd.s.high;
796 n0 = nn.s.low;
797 n1 = nn.s.high;
798
799 #if !UDIV_NEEDS_NORMALIZATION
800 if (d1 == 0)
801 {
802 if (d0 > n1)
803 {
804 /* 0q = nn / 0D */
805
806 udiv_qrnnd (q0, n0, n1, n0, d0);
807 q1 = 0;
808
809 /* Remainder in n0. */
810 }
811 else
812 {
813 /* qq = NN / 0d */
814
815 if (d0 == 0)
816 d0 = 1 / d0; /* Divide intentionally by zero. */
817
818 udiv_qrnnd (q1, n1, 0, n1, d0);
819 udiv_qrnnd (q0, n0, n1, n0, d0);
820
821 /* Remainder in n0. */
822 }
823
824 if (rp != 0)
825 {
826 rr.s.low = n0;
827 rr.s.high = 0;
828 *rp = rr.ll;
829 }
830 }
831
832 #else /* UDIV_NEEDS_NORMALIZATION */
833
834 if (d1 == 0)
835 {
836 if (d0 > n1)
837 {
838 /* 0q = nn / 0D */
839
840 count_leading_zeros (bm, d0);
841
842 if (bm != 0)
843 {
844 /* Normalize, i.e. make the most significant bit of the
845 denominator set. */
846
847 d0 = d0 << bm;
848 n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm));
849 n0 = n0 << bm;
850 }
851
852 udiv_qrnnd (q0, n0, n1, n0, d0);
853 q1 = 0;
854
855 /* Remainder in n0 >> bm. */
856 }
857 else
858 {
859 /* qq = NN / 0d */
860
861 if (d0 == 0)
862 d0 = 1 / d0; /* Divide intentionally by zero. */
863
864 count_leading_zeros (bm, d0);
865
866 if (bm == 0)
867 {
868 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
869 conclude (the most significant bit of n1 is set) /\ (the
870 leading quotient digit q1 = 1).
871
872 This special case is necessary, not an optimization.
873 (Shifts counts of W_TYPE_SIZE are undefined.) */
874
875 n1 -= d0;
876 q1 = 1;
877 }
878 else
879 {
880 /* Normalize. */
881
882 b = W_TYPE_SIZE - bm;
883
884 d0 = d0 << bm;
885 n2 = n1 >> b;
886 n1 = (n1 << bm) | (n0 >> b);
887 n0 = n0 << bm;
888
889 udiv_qrnnd (q1, n1, n2, n1, d0);
890 }
891
892 /* n1 != d0... */
893
894 udiv_qrnnd (q0, n0, n1, n0, d0);
895
896 /* Remainder in n0 >> bm. */
897 }
898
899 if (rp != 0)
900 {
901 rr.s.low = n0 >> bm;
902 rr.s.high = 0;
903 *rp = rr.ll;
904 }
905 }
906 #endif /* UDIV_NEEDS_NORMALIZATION */
907
908 else
909 {
910 if (d1 > n1)
911 {
912 /* 00 = nn / DD */
913
914 q0 = 0;
915 q1 = 0;
916
917 /* Remainder in n1n0. */
918 if (rp != 0)
919 {
920 rr.s.low = n0;
921 rr.s.high = n1;
922 *rp = rr.ll;
923 }
924 }
925 else
926 {
927 /* 0q = NN / dd */
928
929 count_leading_zeros (bm, d1);
930 if (bm == 0)
931 {
932 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
933 conclude (the most significant bit of n1 is set) /\ (the
934 quotient digit q0 = 0 or 1).
935
936 This special case is necessary, not an optimization. */
937
938 /* The condition on the next line takes advantage of that
939 n1 >= d1 (true due to program flow). */
940 if (n1 > d1 || n0 >= d0)
941 {
942 q0 = 1;
943 sub_ddmmss (n1, n0, n1, n0, d1, d0);
944 }
945 else
946 q0 = 0;
947
948 q1 = 0;
949
950 if (rp != 0)
951 {
952 rr.s.low = n0;
953 rr.s.high = n1;
954 *rp = rr.ll;
955 }
956 }
957 else
958 {
959 UWtype m1, m0;
960 /* Normalize. */
961
962 b = W_TYPE_SIZE - bm;
963
964 d1 = (d1 << bm) | (d0 >> b);
965 d0 = d0 << bm;
966 n2 = n1 >> b;
967 n1 = (n1 << bm) | (n0 >> b);
968 n0 = n0 << bm;
969
970 udiv_qrnnd (q0, n1, n2, n1, d1);
971 umul_ppmm (m1, m0, q0, d0);
972
973 if (m1 > n1 || (m1 == n1 && m0 > n0))
974 {
975 q0--;
976 sub_ddmmss (m1, m0, m1, m0, d1, d0);
977 }
978
979 q1 = 0;
980
981 /* Remainder in (n1n0 - m1m0) >> bm. */
982 if (rp != 0)
983 {
984 sub_ddmmss (n1, n0, n1, n0, m1, m0);
985 rr.s.low = (n1 << b) | (n0 >> bm);
986 rr.s.high = n1 >> bm;
987 *rp = rr.ll;
988 }
989 }
990 }
991 }
992
993 const DWunion ww = {{.low = q0, .high = q1}};
994 return ww.ll;
995 }
996 #endif
997
998 #ifdef L_divdi3
999 DWtype
1000 __divdi3 (DWtype u, DWtype v)
1001 {
1002 word_type c = 0;
1003 DWunion uu = {.ll = u};
1004 DWunion vv = {.ll = v};
1005 DWtype w;
1006
1007 if (uu.s.high < 0)
1008 c = ~c,
1009 uu.ll = -uu.ll;
1010 if (vv.s.high < 0)
1011 c = ~c,
1012 vv.ll = -vv.ll;
1013
1014 w = __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) 0);
1015 if (c)
1016 w = -w;
1017
1018 return w;
1019 }
1020 #endif
1021
1022 #ifdef L_moddi3
1023 DWtype
1024 __moddi3 (DWtype u, DWtype v)
1025 {
1026 word_type c = 0;
1027 DWunion uu = {.ll = u};
1028 DWunion vv = {.ll = v};
1029 DWtype w;
1030
1031 if (uu.s.high < 0)
1032 c = ~c,
1033 uu.ll = -uu.ll;
1034 if (vv.s.high < 0)
1035 vv.ll = -vv.ll;
1036
1037 (void) __udivmoddi4 (uu.ll, vv.ll, &w);
1038 if (c)
1039 w = -w;
1040
1041 return w;
1042 }
1043 #endif
1044
1045 #ifdef L_umoddi3
1046 UDWtype
1047 __umoddi3 (UDWtype u, UDWtype v)
1048 {
1049 UDWtype w;
1050
1051 (void) __udivmoddi4 (u, v, &w);
1052
1053 return w;
1054 }
1055 #endif
1056
1057 #ifdef L_udivdi3
1058 UDWtype
1059 __udivdi3 (UDWtype n, UDWtype d)
1060 {
1061 return __udivmoddi4 (n, d, (UDWtype *) 0);
1062 }
1063 #endif
1064 \f
1065 #ifdef L_cmpdi2
1066 word_type
1067 __cmpdi2 (DWtype a, DWtype b)
1068 {
1069 const DWunion au = {.ll = a};
1070 const DWunion bu = {.ll = b};
1071
1072 if (au.s.high < bu.s.high)
1073 return 0;
1074 else if (au.s.high > bu.s.high)
1075 return 2;
1076 if ((UWtype) au.s.low < (UWtype) bu.s.low)
1077 return 0;
1078 else if ((UWtype) au.s.low > (UWtype) bu.s.low)
1079 return 2;
1080 return 1;
1081 }
1082 #endif
1083
1084 #ifdef L_ucmpdi2
1085 word_type
1086 __ucmpdi2 (DWtype a, DWtype b)
1087 {
1088 const DWunion au = {.ll = a};
1089 const DWunion bu = {.ll = b};
1090
1091 if ((UWtype) au.s.high < (UWtype) bu.s.high)
1092 return 0;
1093 else if ((UWtype) au.s.high > (UWtype) bu.s.high)
1094 return 2;
1095 if ((UWtype) au.s.low < (UWtype) bu.s.low)
1096 return 0;
1097 else if ((UWtype) au.s.low > (UWtype) bu.s.low)
1098 return 2;
1099 return 1;
1100 }
1101 #endif
1102 \f
1103 #if defined(L_fixunstfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1104 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1105 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1106
1107 DWtype
1108 __fixunstfDI (TFtype a)
1109 {
1110 if (a < 0)
1111 return 0;
1112
1113 /* Compute high word of result, as a flonum. */
1114 const TFtype b = (a / HIGH_WORD_COEFF);
1115 /* Convert that to fixed (but not to DWtype!),
1116 and shift it into the high word. */
1117 UDWtype v = (UWtype) b;
1118 v <<= WORD_SIZE;
1119 /* Remove high part from the TFtype, leaving the low part as flonum. */
1120 a -= (TFtype)v;
1121 /* Convert that to fixed (but not to DWtype!) and add it in.
1122 Sometimes A comes out negative. This is significant, since
1123 A has more bits than a long int does. */
1124 if (a < 0)
1125 v -= (UWtype) (- a);
1126 else
1127 v += (UWtype) a;
1128 return v;
1129 }
1130 #endif
1131
1132 #if defined(L_fixtfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1133 DWtype
1134 __fixtfdi (TFtype a)
1135 {
1136 if (a < 0)
1137 return - __fixunstfDI (-a);
1138 return __fixunstfDI (a);
1139 }
1140 #endif
1141
1142 #if defined(L_fixunsxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1143 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1144 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1145
1146 DWtype
1147 __fixunsxfDI (XFtype a)
1148 {
1149 if (a < 0)
1150 return 0;
1151
1152 /* Compute high word of result, as a flonum. */
1153 const XFtype b = (a / HIGH_WORD_COEFF);
1154 /* Convert that to fixed (but not to DWtype!),
1155 and shift it into the high word. */
1156 UDWtype v = (UWtype) b;
1157 v <<= WORD_SIZE;
1158 /* Remove high part from the XFtype, leaving the low part as flonum. */
1159 a -= (XFtype)v;
1160 /* Convert that to fixed (but not to DWtype!) and add it in.
1161 Sometimes A comes out negative. This is significant, since
1162 A has more bits than a long int does. */
1163 if (a < 0)
1164 v -= (UWtype) (- a);
1165 else
1166 v += (UWtype) a;
1167 return v;
1168 }
1169 #endif
1170
1171 #if defined(L_fixxfdi) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1172 DWtype
1173 __fixxfdi (XFtype a)
1174 {
1175 if (a < 0)
1176 return - __fixunsxfDI (-a);
1177 return __fixunsxfDI (a);
1178 }
1179 #endif
1180
1181 #ifdef L_fixunsdfdi
1182 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1183 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1184
1185 DWtype
1186 __fixunsdfDI (DFtype a)
1187 {
1188 /* Get high part of result. The division here will just moves the radix
1189 point and will not cause any rounding. Then the conversion to integral
1190 type chops result as desired. */
1191 const UWtype hi = a / HIGH_WORD_COEFF;
1192
1193 /* Get low part of result. Convert `hi' to floating type and scale it back,
1194 then subtract this from the number being converted. This leaves the low
1195 part. Convert that to integral type. */
1196 const UWtype lo = (a - ((DFtype) hi) * HIGH_WORD_COEFF);
1197
1198 /* Assemble result from the two parts. */
1199 return ((UDWtype) hi << WORD_SIZE) | lo;
1200 }
1201 #endif
1202
1203 #ifdef L_fixdfdi
1204 DWtype
1205 __fixdfdi (DFtype a)
1206 {
1207 if (a < 0)
1208 return - __fixunsdfDI (-a);
1209 return __fixunsdfDI (a);
1210 }
1211 #endif
1212
1213 #ifdef L_fixunssfdi
1214 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1215 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1216
1217 DWtype
1218 __fixunssfDI (SFtype original_a)
1219 {
1220 /* Convert the SFtype to a DFtype, because that is surely not going
1221 to lose any bits. Some day someone else can write a faster version
1222 that avoids converting to DFtype, and verify it really works right. */
1223 const DFtype a = original_a;
1224
1225 /* Get high part of result. The division here will just moves the radix
1226 point and will not cause any rounding. Then the conversion to integral
1227 type chops result as desired. */
1228 const UWtype hi = a / HIGH_WORD_COEFF;
1229
1230 /* Get low part of result. Convert `hi' to floating type and scale it back,
1231 then subtract this from the number being converted. This leaves the low
1232 part. Convert that to integral type. */
1233 const UWtype lo = (a - ((DFtype) hi) * HIGH_WORD_COEFF);
1234
1235 /* Assemble result from the two parts. */
1236 return ((UDWtype) hi << WORD_SIZE) | lo;
1237 }
1238 #endif
1239
1240 #ifdef L_fixsfdi
1241 DWtype
1242 __fixsfdi (SFtype a)
1243 {
1244 if (a < 0)
1245 return - __fixunssfDI (-a);
1246 return __fixunssfDI (a);
1247 }
1248 #endif
1249
1250 #if defined(L_floatdixf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96)
1251 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1252 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1253 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1254
1255 XFtype
1256 __floatdixf (DWtype u)
1257 {
1258 XFtype d = (Wtype) (u >> WORD_SIZE);
1259 d *= HIGH_HALFWORD_COEFF;
1260 d *= HIGH_HALFWORD_COEFF;
1261 d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1262
1263 return d;
1264 }
1265 #endif
1266
1267 #if defined(L_floatditf) && (LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 128)
1268 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1269 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1270 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1271
1272 TFtype
1273 __floatditf (DWtype u)
1274 {
1275 TFtype d = (Wtype) (u >> WORD_SIZE);
1276 d *= HIGH_HALFWORD_COEFF;
1277 d *= HIGH_HALFWORD_COEFF;
1278 d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1279
1280 return d;
1281 }
1282 #endif
1283
1284 #ifdef L_floatdidf
1285 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1286 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1287 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1288
1289 DFtype
1290 __floatdidf (DWtype u)
1291 {
1292 DFtype d = (Wtype) (u >> WORD_SIZE);
1293 d *= HIGH_HALFWORD_COEFF;
1294 d *= HIGH_HALFWORD_COEFF;
1295 d += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1296
1297 return d;
1298 }
1299 #endif
1300
1301 #ifdef L_floatdisf
1302 #define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
1303 #define HIGH_HALFWORD_COEFF (((UDWtype) 1) << (WORD_SIZE / 2))
1304 #define HIGH_WORD_COEFF (((UDWtype) 1) << WORD_SIZE)
1305
1306 #define DI_SIZE (sizeof (DWtype) * BITS_PER_UNIT)
1307 #define DF_SIZE DBL_MANT_DIG
1308 #define SF_SIZE FLT_MANT_DIG
1309
1310 SFtype
1311 __floatdisf (DWtype u)
1312 {
1313 /* Protect against double-rounding error.
1314 Represent any low-order bits, that might be truncated in DFmode,
1315 by a bit that won't be lost. The bit can go in anywhere below the
1316 rounding position of the SFmode. A fixed mask and bit position
1317 handles all usual configurations. It doesn't handle the case
1318 of 128-bit DImode, however. */
1319 if (DF_SIZE < DI_SIZE
1320 && DF_SIZE > (DI_SIZE - DF_SIZE + SF_SIZE))
1321 {
1322 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - DF_SIZE))
1323 if (! (- ((DWtype) 1 << DF_SIZE) < u
1324 && u < ((DWtype) 1 << DF_SIZE)))
1325 {
1326 if ((UDWtype) u & (REP_BIT - 1))
1327 {
1328 u &= ~ (REP_BIT - 1);
1329 u |= REP_BIT;
1330 }
1331 }
1332 }
1333 /* Do the calculation in DFmode
1334 so that we don't lose any of the precision of the high word
1335 while multiplying it. */
1336 DFtype f = (Wtype) (u >> WORD_SIZE);
1337 f *= HIGH_HALFWORD_COEFF;
1338 f *= HIGH_HALFWORD_COEFF;
1339 f += (UWtype) (u & (HIGH_WORD_COEFF - 1));
1340
1341 return (SFtype) f;
1342 }
1343 #endif
1344
1345 #if defined(L_fixunsxfsi) && LIBGCC2_LONG_DOUBLE_TYPE_SIZE == 96
1346 /* Reenable the normal types, in case limits.h needs them. */
1347 #undef char
1348 #undef short
1349 #undef int
1350 #undef long
1351 #undef unsigned
1352 #undef float
1353 #undef double
1354 #undef MIN
1355 #undef MAX
1356 #include <limits.h>
1357
1358 UWtype
1359 __fixunsxfSI (XFtype a)
1360 {
1361 if (a >= - (DFtype) Wtype_MIN)
1362 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1363 return (Wtype) a;
1364 }
1365 #endif
1366
1367 #ifdef L_fixunsdfsi
1368 /* Reenable the normal types, in case limits.h needs them. */
1369 #undef char
1370 #undef short
1371 #undef int
1372 #undef long
1373 #undef unsigned
1374 #undef float
1375 #undef double
1376 #undef MIN
1377 #undef MAX
1378 #include <limits.h>
1379
1380 UWtype
1381 __fixunsdfSI (DFtype a)
1382 {
1383 if (a >= - (DFtype) Wtype_MIN)
1384 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1385 return (Wtype) a;
1386 }
1387 #endif
1388
1389 #ifdef L_fixunssfsi
1390 /* Reenable the normal types, in case limits.h needs them. */
1391 #undef char
1392 #undef short
1393 #undef int
1394 #undef long
1395 #undef unsigned
1396 #undef float
1397 #undef double
1398 #undef MIN
1399 #undef MAX
1400 #include <limits.h>
1401
1402 UWtype
1403 __fixunssfSI (SFtype a)
1404 {
1405 if (a >= - (SFtype) Wtype_MIN)
1406 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
1407 return (Wtype) a;
1408 }
1409 #endif
1410 \f
1411 /* From here on down, the routines use normal data types. */
1412
1413 #define SItype bogus_type
1414 #define USItype bogus_type
1415 #define DItype bogus_type
1416 #define UDItype bogus_type
1417 #define SFtype bogus_type
1418 #define DFtype bogus_type
1419 #undef Wtype
1420 #undef UWtype
1421 #undef HWtype
1422 #undef UHWtype
1423 #undef DWtype
1424 #undef UDWtype
1425
1426 #undef char
1427 #undef short
1428 #undef int
1429 #undef long
1430 #undef unsigned
1431 #undef float
1432 #undef double
1433 \f
1434 #ifdef L__gcc_bcmp
1435
1436 /* Like bcmp except the sign is meaningful.
1437 Result is negative if S1 is less than S2,
1438 positive if S1 is greater, 0 if S1 and S2 are equal. */
1439
1440 int
1441 __gcc_bcmp (const unsigned char *s1, const unsigned char *s2, size_t size)
1442 {
1443 while (size > 0)
1444 {
1445 const unsigned char c1 = *s1++, c2 = *s2++;
1446 if (c1 != c2)
1447 return c1 - c2;
1448 size--;
1449 }
1450 return 0;
1451 }
1452
1453 #endif
1454 \f
1455 /* __eprintf used to be used by GCC's private version of <assert.h>.
1456 We no longer provide that header, but this routine remains in libgcc.a
1457 for binary backward compatibility. Note that it is not included in
1458 the shared version of libgcc. */
1459 #ifdef L_eprintf
1460 #ifndef inhibit_libc
1461
1462 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
1463 #include <stdio.h>
1464
1465 void
1466 __eprintf (const char *string, const char *expression,
1467 unsigned int line, const char *filename)
1468 {
1469 fprintf (stderr, string, expression, line, filename);
1470 fflush (stderr);
1471 abort ();
1472 }
1473
1474 #endif
1475 #endif
1476
1477 \f
1478 #ifdef L_clear_cache
1479 /* Clear part of an instruction cache. */
1480
1481 void
1482 __clear_cache (char *beg __attribute__((__unused__)),
1483 char *end __attribute__((__unused__)))
1484 {
1485 #ifdef CLEAR_INSN_CACHE
1486 CLEAR_INSN_CACHE (beg, end);
1487 #endif /* CLEAR_INSN_CACHE */
1488 }
1489
1490 #endif /* L_clear_cache */
1491 \f
1492 #ifdef L_trampoline
1493
1494 /* Jump to a trampoline, loading the static chain address. */
1495
1496 #if defined(WINNT) && ! defined(__CYGWIN__) && ! defined (_UWIN)
1497
1498 long
1499 getpagesize (void)
1500 {
1501 #ifdef _ALPHA_
1502 return 8192;
1503 #else
1504 return 4096;
1505 #endif
1506 }
1507
1508 #ifdef __i386__
1509 extern int VirtualProtect (char *, int, int, int *) __attribute__((stdcall));
1510 #endif
1511
1512 int
1513 mprotect (char *addr, int len, int prot)
1514 {
1515 int np, op;
1516
1517 if (prot == 7)
1518 np = 0x40;
1519 else if (prot == 5)
1520 np = 0x20;
1521 else if (prot == 4)
1522 np = 0x10;
1523 else if (prot == 3)
1524 np = 0x04;
1525 else if (prot == 1)
1526 np = 0x02;
1527 else if (prot == 0)
1528 np = 0x01;
1529
1530 if (VirtualProtect (addr, len, np, &op))
1531 return 0;
1532 else
1533 return -1;
1534 }
1535
1536 #endif /* WINNT && ! __CYGWIN__ && ! _UWIN */
1537
1538 #ifdef TRANSFER_FROM_TRAMPOLINE
1539 TRANSFER_FROM_TRAMPOLINE
1540 #endif
1541 #endif /* L_trampoline */
1542 \f
1543 #ifndef __CYGWIN__
1544 #ifdef L__main
1545
1546 #include "gbl-ctors.h"
1547 /* Some systems use __main in a way incompatible with its use in gcc, in these
1548 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
1549 give the same symbol without quotes for an alternative entry point. You
1550 must define both, or neither. */
1551 #ifndef NAME__MAIN
1552 #define NAME__MAIN "__main"
1553 #define SYMBOL__MAIN __main
1554 #endif
1555
1556 #ifdef INIT_SECTION_ASM_OP
1557 #undef HAS_INIT_SECTION
1558 #define HAS_INIT_SECTION
1559 #endif
1560
1561 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
1562
1563 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
1564 code to run constructors. In that case, we need to handle EH here, too. */
1565
1566 #ifdef EH_FRAME_SECTION_NAME
1567 #include "unwind-dw2-fde.h"
1568 extern unsigned char __EH_FRAME_BEGIN__[];
1569 #endif
1570
1571 /* Run all the global destructors on exit from the program. */
1572
1573 void
1574 __do_global_dtors (void)
1575 {
1576 #ifdef DO_GLOBAL_DTORS_BODY
1577 DO_GLOBAL_DTORS_BODY;
1578 #else
1579 static func_ptr *p = __DTOR_LIST__ + 1;
1580 while (*p)
1581 {
1582 p++;
1583 (*(p-1)) ();
1584 }
1585 #endif
1586 #if defined (EH_FRAME_SECTION_NAME) && !defined (HAS_INIT_SECTION)
1587 {
1588 static int completed = 0;
1589 if (! completed)
1590 {
1591 completed = 1;
1592 __deregister_frame_info (__EH_FRAME_BEGIN__);
1593 }
1594 }
1595 #endif
1596 }
1597 #endif
1598
1599 #ifndef HAS_INIT_SECTION
1600 /* Run all the global constructors on entry to the program. */
1601
1602 void
1603 __do_global_ctors (void)
1604 {
1605 #ifdef EH_FRAME_SECTION_NAME
1606 {
1607 static struct object object;
1608 __register_frame_info (__EH_FRAME_BEGIN__, &object);
1609 }
1610 #endif
1611 DO_GLOBAL_CTORS_BODY;
1612 atexit (__do_global_dtors);
1613 }
1614 #endif /* no HAS_INIT_SECTION */
1615
1616 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
1617 /* Subroutine called automatically by `main'.
1618 Compiling a global function named `main'
1619 produces an automatic call to this function at the beginning.
1620
1621 For many systems, this routine calls __do_global_ctors.
1622 For systems which support a .init section we use the .init section
1623 to run __do_global_ctors, so we need not do anything here. */
1624
1625 extern void SYMBOL__MAIN (void);
1626 void
1627 SYMBOL__MAIN (void)
1628 {
1629 /* Support recursive calls to `main': run initializers just once. */
1630 static int initialized;
1631 if (! initialized)
1632 {
1633 initialized = 1;
1634 __do_global_ctors ();
1635 }
1636 }
1637 #endif /* no HAS_INIT_SECTION or INVOKE__main */
1638
1639 #endif /* L__main */
1640 #endif /* __CYGWIN__ */
1641 \f
1642 #ifdef L_ctors
1643
1644 #include "gbl-ctors.h"
1645
1646 /* Provide default definitions for the lists of constructors and
1647 destructors, so that we don't get linker errors. These symbols are
1648 intentionally bss symbols, so that gld and/or collect will provide
1649 the right values. */
1650
1651 /* We declare the lists here with two elements each,
1652 so that they are valid empty lists if no other definition is loaded.
1653
1654 If we are using the old "set" extensions to have the gnu linker
1655 collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
1656 must be in the bss/common section.
1657
1658 Long term no port should use those extensions. But many still do. */
1659 #if !defined(INIT_SECTION_ASM_OP) && !defined(CTOR_LISTS_DEFINED_EXTERNALLY)
1660 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
1661 func_ptr __CTOR_LIST__[2] = {0, 0};
1662 func_ptr __DTOR_LIST__[2] = {0, 0};
1663 #else
1664 func_ptr __CTOR_LIST__[2];
1665 func_ptr __DTOR_LIST__[2];
1666 #endif
1667 #endif /* no INIT_SECTION_ASM_OP and not CTOR_LISTS_DEFINED_EXTERNALLY */
1668 #endif /* L_ctors */
1669