OSDN Git Service

e92f2a4eb0cb3f0f8cfac323e6b83afc24d612df
[pf3gnuchains/gcc-fork.git] / boehm-gc / include / private / gcconfig.h
1 /* 
2  * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
3  * Copyright (c) 1991-1994 by Xerox Corporation.  All rights reserved.
4  * Copyright (c) 1996 by Silicon Graphics.  All rights reserved.
5  * Copyright (c) 2000 by Hewlett-Packard Company.  All rights reserved.
6  *
7  * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
8  * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
9  *
10  * Permission is hereby granted to use or copy this program
11  * for any purpose,  provided the above notices are retained on all copies.
12  * Permission to modify the code and to distribute modified code is granted,
13  * provided the above notices are retained, and a notice that the code was
14  * modified is included with the above copyright notice.
15  */
16  
17 #ifndef GCCONFIG_H
18
19 # define GCCONFIG_H
20
21 /* Machine dependent parameters.  Some tuning parameters can be found   */
22 /* near the top of gc_private.h.                                        */
23
24 /* Machine specific parts contributed by various people.  See README file. */
25
26 /* First a unified test for Linux: */
27 # if defined(linux) || defined(__linux__)
28 #    define LINUX
29 # endif
30
31 /* And one for NetBSD: */
32 # if defined(__NetBSD__)
33 #    define NETBSD
34 # endif
35
36 /* And one for OpenBSD: */
37 # if defined(__OpenBSD__)
38 #    define OPENBSD
39 # endif
40
41 /* Determine the machine type: */
42 # if defined(sun) && defined(mc68000)
43 #    define M68K
44 #    define SUNOS4
45 #    define mach_type_known
46 # endif
47 # if defined(hp9000s300)
48 #    define M68K
49 #    define HP
50 #    define mach_type_known
51 # endif
52 # if defined(OPENBSD) && defined(m68k)
53 #    define M68K
54 #    define mach_type_known
55 # endif
56 # if defined(OPENBSD) && defined(__sparc__)
57 #    define SPARC
58 #    define mach_type_known
59 # endif
60 # if defined(NETBSD) && defined(m68k)
61 #    define M68K
62 #    define mach_type_known
63 # endif
64 # if defined(NETBSD) && defined(__powerpc__)
65 #    define POWERPC
66 #    define mach_type_known
67 # endif
68 # if defined(NETBSD) && defined(__arm32__)
69 #    define ARM32
70 #    define mach_type_known
71 # endif
72 # if defined(vax)
73 #    define VAX
74 #    ifdef ultrix
75 #       define ULTRIX
76 #    else
77 #       define BSD
78 #    endif
79 #    define mach_type_known
80 # endif
81 # if defined(mips) || defined(__mips)
82 #    define MIPS
83 #    if !defined(LINUX)
84 #      if defined(ultrix) || defined(__ultrix) || defined(__NetBSD__)
85 #        define ULTRIX
86 #      else
87 #        if defined(_SYSTYPE_SVR4) || defined(SYSTYPE_SVR4) \
88             || defined(__SYSTYPE_SVR4__)
89 #          define IRIX5   /* or IRIX 6.X */
90 #        else
91 #          define RISCOS  /* or IRIX 4.X */
92 #        endif
93 #      endif
94 #    endif /* !LINUX */
95 #    if defined(__NetBSD__) && defined(__MIPSEL__)
96 #      undef ULTRIX
97 #    endif
98 #    define mach_type_known
99 # endif
100 # if defined(sequent) && (defined(i386) || defined(__i386__))
101 #    define I386
102 #    define SEQUENT
103 #    define mach_type_known
104 # endif
105 # if defined(sun) && (defined(i386) || defined(__i386__))
106 #    define I386
107 #    define SUNOS5
108 #    define mach_type_known
109 # endif
110 # if (defined(__OS2__) || defined(__EMX__)) && defined(__32BIT__)
111 #    define I386
112 #    define OS2
113 #    define mach_type_known
114 # endif
115 # if defined(ibm032)
116 #   define RT
117 #   define mach_type_known
118 # endif
119 # if defined(sun) && (defined(sparc) || defined(__sparc))
120 #   define SPARC
121     /* Test for SunOS 5.x */
122 #     include <errno.h>
123 #     ifdef ECHRNG
124 #       define SUNOS5
125 #     else
126 #       define SUNOS4
127 #     endif
128 #   define mach_type_known
129 # endif
130 # if defined(sparc) && defined(unix) && !defined(sun) && !defined(linux) \
131      && !defined(__OpenBSD__) && !(__NetBSD__)
132 #   define SPARC
133 #   define DRSNX
134 #   define mach_type_known
135 # endif
136 # if defined(_IBMR2)
137 #   define RS6000
138 #   define mach_type_known
139 # endif
140 # if defined(__NetBSD__) && defined(__sparc__)
141 #   define SPARC
142 #   define mach_type_known
143 # endif
144 # if defined(_M_XENIX) && defined(_M_SYSV) && defined(_M_I386)
145         /* The above test may need refinement   */
146 #   define I386
147 #   if defined(_SCO_ELF)
148 #     define SCO_ELF
149 #   else
150 #     define SCO
151 #   endif
152 #   define mach_type_known
153 # endif
154 # if defined(_AUX_SOURCE)
155 #   define M68K
156 #   define SYSV
157 #   define mach_type_known
158 # endif
159 # if defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0) \
160      || defined(hppa) || defined(__hppa__)
161 #   define HP_PA
162 #   ifndef LINUX
163 #     define HPUX
164 #   endif
165 #   define mach_type_known
166 # endif
167 # if defined(__ia64) && defined(_HPUX_SOURCE)
168 #   define IA64
169 #   define HPUX
170 #   define mach_type_known
171 # endif
172 # if defined(__BEOS__) && defined(_X86_)
173 #    define I386
174 #    define BEOS
175 #    define mach_type_known
176 # endif
177 # if defined(LINUX) && (defined(i386) || defined(__i386__))
178 #    define I386
179 #    define mach_type_known
180 # endif
181 # if defined(LINUX) && (defined(__ia64__) || defined(__ia64))
182 #    define IA64
183 #    define mach_type_known
184 # endif
185 # if defined(LINUX) && (defined(powerpc) || defined(__powerpc__))
186 #    define POWERPC
187 #    define mach_type_known
188 # endif
189 # if defined(LINUX) && defined(__mc68000__)
190 #    define M68K
191 #    define mach_type_known
192 # endif
193 # if defined(LINUX) && (defined(sparc) || defined(__sparc__))
194 #    define SPARC
195 #    define mach_type_known
196 # endif
197 # if defined(LINUX) && defined(__arm__)
198 #    define ARM32
199 #    define mach_type_known
200 # endif
201 # if defined(LINUX) && defined(__sh__)
202 #    define SH
203 #    define mach_type_known
204 # endif
205 # if defined(__alpha) || defined(__alpha__)
206 #   define ALPHA
207 #   if !defined(LINUX) && !defined(NETBSD) && !defined(OPENBSD)
208 #     define OSF1       /* a.k.a Digital Unix */
209 #   endif
210 #   define mach_type_known
211 # endif
212 # if defined(_AMIGA) && !defined(AMIGA)
213 #   define AMIGA
214 # endif
215 # ifdef AMIGA 
216 #   define M68K
217 #   define mach_type_known
218 # endif
219 # if defined(THINK_C) || defined(__MWERKS__) && !defined(__powerc)
220 #   define M68K
221 #   define MACOS
222 #   define mach_type_known
223 # endif
224 # if defined(__MWERKS__) && defined(__powerc)
225 #   define POWERPC
226 #   define MACOS
227 #   define mach_type_known
228 # endif
229 # if defined(macosx) || \
230      defined(__APPLE__) && defined(__MACH__) && defined(__ppc__)
231 #    define MACOSX
232 #    define POWERPC
233 #    define mach_type_known
234 # endif
235 # if defined(__APPLE__) && defined(__MACH__) && defined(__i386__)
236 #    define MACOSX
237 #    define I386
238      --> Not really supported, but at least we recognize it.
239 # endif
240 # if defined(NeXT) && defined(mc68000)
241 #   define M68K
242 #   define NEXT
243 #   define mach_type_known
244 # endif
245 # if defined(NeXT) && (defined(i386) || defined(__i386__))
246 #   define I386
247 #   define NEXT
248 #   define mach_type_known
249 # endif
250 # if defined(__OpenBSD__) && (defined(i386) || defined(__i386__))
251 #   define I386
252 #   define OPENBSD
253 #   define mach_type_known
254 # endif
255 # if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
256 #   define I386
257 #   define FREEBSD
258 #   define mach_type_known
259 # endif
260 # if defined(__NetBSD__) && (defined(i386) || defined(__i386__))
261 #   define I386
262 #   define mach_type_known
263 # endif
264 # if defined(bsdi) && (defined(i386) || defined(__i386__))
265 #    define I386
266 #    define BSDI
267 #    define mach_type_known
268 # endif
269 # if !defined(mach_type_known) && defined(__386BSD__)
270 #   define I386
271 #   define THREE86BSD
272 #   define mach_type_known
273 # endif
274 # if defined(_CX_UX) && defined(_M88K)
275 #   define M88K
276 #   define CX_UX
277 #   define mach_type_known
278 # endif
279 # if defined(DGUX)
280 #   define M88K
281     /* DGUX defined */
282 #   define mach_type_known
283 # endif
284 # if defined(_WIN32_WCE)
285     /* SH3, SH4, MIPS already defined for corresponding architectures */
286 #   if defined(SH3) || defined(SH4)
287 #     define SH
288 #   endif
289 #   if defined(x86)
290 #     define I386
291 #   endif
292 #   if defined(ARM)
293 #     define ARM32
294 #   endif
295 #   define MSWINCE
296 #   define mach_type_known
297 # else
298 #   if (defined(_MSDOS) || defined(_MSC_VER)) && (_M_IX86 >= 300) \
299         || defined(_WIN32) && !defined(__CYGWIN32__) && !defined(__CYGWIN__)
300 #     define I386
301 #     define MSWIN32    /* or Win32s */
302 #     define mach_type_known
303 #   endif
304 # endif
305 # if defined(__DJGPP__)
306 #   define I386
307 #   ifndef DJGPP
308 #     define DJGPP  /* MSDOS running the DJGPP port of GCC */
309 #   endif
310 #   define mach_type_known
311 # endif
312 # if defined(__CYGWIN32__) || defined(__CYGWIN__)
313 #   define I386
314 #   define CYGWIN32
315 #   define mach_type_known
316 # endif
317 # if defined(__MINGW32__)
318 #   define I386
319 #   define MSWIN32
320 #   define mach_type_known
321 # endif
322 # if defined(__BORLANDC__)
323 #   define I386
324 #   define MSWIN32
325 #   define mach_type_known
326 # endif
327 # if defined(_UTS) && !defined(mach_type_known)
328 #   define S370
329 #   define UTS4
330 #   define mach_type_known
331 # endif
332 # if defined(__pj__)
333 #   define PJ
334 #   define mach_type_known
335 # endif
336 # if defined(__embedded__) && defined(PPC)
337 #   define POWERPC
338 #   define NOSYS
339 #   define mach_type_known
340 # endif
341 /* Ivan Demakov */
342 # if defined(__WATCOMC__) && defined(__386__)
343 #   define I386
344 #   if !defined(OS2) && !defined(MSWIN32) && !defined(DOS4GW)
345 #     if defined(__OS2__)
346 #       define OS2
347 #     else
348 #       if defined(__WINDOWS_386__) || defined(__NT__)
349 #         define MSWIN32
350 #       else
351 #         define DOS4GW
352 #       endif
353 #     endif
354 #   endif
355 #   define mach_type_known
356 # endif
357 # if defined(__s390__) && defined(LINUX)
358 #    define S370
359 #    define mach_type_known
360 # endif
361 # if defined(__GNU__)
362 #   if defined(__i386__)
363 /* The Debian Hurd running on generic PC */  
364 #     define  HURD
365 #     define  I386
366 #     define  mach_type_known
367 #    endif 
368 # endif
369
370 /* Feel free to add more clauses here */
371
372 /* Or manually define the machine type here.  A machine type is         */
373 /* characterized by the architecture.  Some                             */
374 /* machine types are further subdivided by OS.                          */
375 /* the macros ULTRIX, RISCOS, and BSD to distinguish.                   */
376 /* Note that SGI IRIX is treated identically to RISCOS.                 */
377 /* SYSV on an M68K actually means A/UX.                                 */
378 /* The distinction in these cases is usually the stack starting address */
379 # ifndef mach_type_known
380         --> unknown machine type
381 # endif
382                     /* Mapping is: M68K       ==> Motorola 680X0        */
383                     /*             (SUNOS4,HP,NEXT, and SYSV (A/UX),    */
384                     /*             MACOS and AMIGA variants)            */
385                     /*             I386       ==> Intel 386             */
386                     /*              (SEQUENT, OS2, SCO, LINUX, NETBSD,  */
387                     /*               FREEBSD, THREE86BSD, MSWIN32,      */
388                     /*               BSDI,SUNOS5, NEXT, other variants) */
389                     /*             NS32K      ==> Encore Multimax       */
390                     /*             MIPS       ==> R2000 or R3000        */
391                     /*                  (RISCOS, ULTRIX variants)       */
392                     /*             VAX        ==> DEC VAX               */
393                     /*                  (BSD, ULTRIX variants)          */
394                     /*             RS6000     ==> IBM RS/6000 AIX3.X    */
395                     /*             RT         ==> IBM PC/RT             */
396                     /*             HP_PA      ==> HP9000/700 & /800     */
397                     /*                            HP/UX, LINUX          */
398                     /*             SPARC      ==> SPARC v7/v8/v9        */
399                     /*                  (SUNOS4, SUNOS5, LINUX,         */
400                     /*                   DRSNX variants)                */
401                     /*             ALPHA      ==> DEC Alpha             */
402                     /*                  (OSF1 and LINUX variants)       */
403                     /*             M88K       ==> Motorola 88XX0        */
404                     /*                  (CX_UX and DGUX)                */
405                     /*             S370       ==> 370-like machine      */
406                     /*                  running Amdahl UTS4             */
407                     /*                  or a 390 running LINUX          */
408                     /*             ARM32      ==> Intel StrongARM       */
409                     /*             IA64       ==> Intel IPF             */
410                     /*                            (e.g. Itanium)        */
411                     /*                  (LINUX and HPUX)                */
412                     /*             IA64_32    ==> IA64 w/32 bit ABI     */
413                     /*                  (HPUX)                          */
414                     /*             SH         ==> Hitachi SuperH        */
415                     /*                  (LINUX & MSWINCE)               */
416
417
418 /*
419  * For each architecture and OS, the following need to be defined:
420  *
421  * CPP_WORD_SZ is a simple integer constant representing the word size.
422  * in bits.  We assume byte addressibility, where a byte has 8 bits.
423  * We also assume CPP_WORD_SZ is either 32 or 64.
424  * (We care about the length of pointers, not hardware
425  * bus widths.  Thus a 64 bit processor with a C compiler that uses
426  * 32 bit pointers should use CPP_WORD_SZ of 32, not 64. Default is 32.)
427  *
428  * MACH_TYPE is a string representation of the machine type.
429  * OS_TYPE is analogous for the OS.
430  *
431  * ALIGNMENT is the largest N, such that
432  * all pointer are guaranteed to be aligned on N byte boundaries.
433  * defining it to be 1 will always work, but perform poorly.
434  *
435  * DATASTART is the beginning of the data segment.
436  * On UNIX systems, the collector will scan the area between DATASTART
437  * and DATAEND for root pointers.
438  *
439  * DATAEND, if not &end.
440  *
441  * ALIGN_DOUBLE of GC_malloc should return blocks aligned to twice
442  * the pointer size.
443  *
444  * STACKBOTTOM is the cool end of the stack, which is usually the
445  * highest address in the stack.
446  * Under PCR or OS/2, we have other ways of finding thread stacks.
447  * For each machine, the following should:
448  * 1) define STACK_GROWS_UP if the stack grows toward higher addresses, and
449  * 2) define exactly one of
450  *      STACKBOTTOM (should be defined to be an expression)
451  *      HEURISTIC1
452  *      HEURISTIC2
453  * If either of the last two macros are defined, then STACKBOTTOM is computed
454  * during collector startup using one of the following two heuristics:
455  * HEURISTIC1:  Take an address inside GC_init's frame, and round it up to
456  *              the next multiple of STACK_GRAN.
457  * HEURISTIC2:  Take an address inside GC_init's frame, increment it repeatedly
458  *              in small steps (decrement if STACK_GROWS_UP), and read the value
459  *              at each location.  Remember the value when the first
460  *              Segmentation violation or Bus error is signalled.  Round that
461  *              to the nearest plausible page boundary, and use that instead
462  *              of STACKBOTTOM.
463  *
464  * Gustavo Rodriguez-Rivera points out that on most (all?) Unix machines,
465  * the value of environ is a pointer that can serve as STACKBOTTOM.
466  * I expect that HEURISTIC2 can be replaced by this approach, which
467  * interferes far less with debugging.  However it has the disadvantage
468  * that it's confused by a putenv call before the collector is initialized.
469  * This could be dealt with by intercepting putenv ...
470  *
471  * If no expression for STACKBOTTOM can be found, and neither of the above
472  * heuristics are usable, the collector can still be used with all of the above
473  * undefined, provided one of the following is done:
474  * 1) GC_mark_roots can be changed to somehow mark from the correct stack(s)
475  *    without reference to STACKBOTTOM.  This is appropriate for use in
476  *    conjunction with thread packages, since there will be multiple stacks.
477  *    (Allocating thread stacks in the heap, and treating them as ordinary
478  *    heap data objects is also possible as a last resort.  However, this is
479  *    likely to introduce significant amounts of excess storage retention
480  *    unless the dead parts of the thread stacks are periodically cleared.)
481  * 2) Client code may set GC_stackbottom before calling any GC_ routines.
482  *    If the author of the client code controls the main program, this is
483  *    easily accomplished by introducing a new main program, setting
484  *    GC_stackbottom to the address of a local variable, and then calling
485  *    the original main program.  The new main program would read something
486  *    like:
487  *
488  *              # include "gc_private.h"
489  *
490  *              main(argc, argv, envp)
491  *              int argc;
492  *              char **argv, **envp;
493  *              {
494  *                  int dummy;
495  *
496  *                  GC_stackbottom = (ptr_t)(&dummy);
497  *                  return(real_main(argc, argv, envp));
498  *              }
499  *
500  *
501  * Each architecture may also define the style of virtual dirty bit
502  * implementation to be used:
503  *   MPROTECT_VDB: Write protect the heap and catch faults.
504  *   PROC_VDB: Use the SVR4 /proc primitives to read dirty bits.
505  *
506  * An architecture may define DYNAMIC_LOADING if dynamic_load.c
507  * defined GC_register_dynamic_libraries() for the architecture.
508  *
509  * An architecture may define PREFETCH(x) to preload the cache with *x.
510  * This defaults to a no-op.
511  *
512  * PREFETCH_FOR_WRITE(x) is used if *x is about to be written.
513  *
514  * An architecture may also define CLEAR_DOUBLE(x) to be a fast way to
515  * clear the two words at GC_malloc-aligned address x.  By default,
516  * word stores of 0 are used instead.
517  */
518
519 /* If we are using a recent version of gcc, we can use __builtin_unwind_init()
520  * to push the relevant registers onto the stack.  This generally makes
521  * USE_GENERIC_PUSH_REGS the preferred approach for marking from registers.
522  */
523 # if defined(__GNUC__) && ((__GNUC__ >= 3) || \
524                            (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
525 #   define HAVE_BUILTIN_UNWIND_INIT
526 # endif
527
528 # define STACK_GRAN 0x1000000
529 # ifdef M68K
530 #   define MACH_TYPE "M68K"
531 #   define ALIGNMENT 2
532 #   ifdef OPENBSD
533 #       define OS_TYPE "OPENBSD"
534 #       define HEURISTIC2
535         extern char etext;
536 #       define DATASTART ((ptr_t)(&etext))
537 #   endif
538 #   ifdef NETBSD
539 #       define OS_TYPE "NETBSD"
540 #       define HEURISTIC2
541         extern char etext;
542 #       define DATASTART ((ptr_t)(&etext))
543 #   endif
544 #   ifdef LINUX
545 #       define OS_TYPE "LINUX"
546 #       define STACKBOTTOM ((ptr_t)0xf0000000)
547 /* #       define MPROTECT_VDB - Reported to not work  9/17/01 */
548 #       ifdef __ELF__
549 #            define DYNAMIC_LOADING
550 #            include <features.h>
551 #            if defined(__GLIBC__)&& __GLIBC__>=2
552 #              define LINUX_DATA_START
553 #            else /* !GLIBC2 */
554                extern char **__environ;
555 #              define DATASTART ((ptr_t)(&__environ))
556                              /* hideous kludge: __environ is the first */
557                              /* word in crt0.o, and delimits the start */
558                              /* of the data segment, no matter which   */
559                              /* ld options were passed through.        */
560                              /* We could use _etext instead, but that  */
561                              /* would include .rodata, which may       */
562                              /* contain large read-only data tables    */
563                              /* that we'd rather not scan.             */
564 #            endif /* !GLIBC2 */
565              extern int _end;
566 #            define DATAEND (&_end)
567 #       else
568              extern int etext;
569 #            define DATASTART ((ptr_t)((((word) (&etext)) + 0xfff) & ~0xfff))
570 #       endif
571 #   endif
572 #   ifdef SUNOS4
573 #       define OS_TYPE "SUNOS4"
574         extern char etext;
575 #       define DATASTART ((ptr_t)((((word) (&etext)) + 0x1ffff) & ~0x1ffff))
576 #       define HEURISTIC1       /* differs      */
577 #       define DYNAMIC_LOADING
578 #   endif
579 #   ifdef HP
580 #       define OS_TYPE "HP"
581         extern char etext;
582 #       define DATASTART ((ptr_t)((((word) (&etext)) + 0xfff) & ~0xfff))
583 #       define STACKBOTTOM ((ptr_t) 0xffeffffc)
584                               /* empirically determined.  seems to work. */
585 #       include <unistd.h>
586 #       define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
587 #   endif
588 #   ifdef SYSV
589 #       define OS_TYPE "SYSV"
590         extern etext;
591 #       define DATASTART ((ptr_t)((((word) (&etext)) + 0x3fffff) \
592                                    & ~0x3fffff) \
593                                   +((word)&etext & 0x1fff))
594         /* This only works for shared-text binaries with magic number 0413.
595            The other sorts of SysV binaries put the data at the end of the text,
596            in which case the default of &etext would work.  Unfortunately,
597            handling both would require having the magic-number available.
598                                 -- Parag
599            */
600 #       define STACKBOTTOM ((ptr_t)0xFFFFFFFE)
601                         /* The stack starts at the top of memory, but   */
602                         /* 0x0 cannot be used as setjump_test complains */
603                         /* that the stack direction is incorrect.  Two  */
604                         /* bytes down from 0x0 should be safe enough.   */
605                         /*              --Parag                         */
606 #       include <sys/mmu.h>
607 #       define GETPAGESIZE() PAGESIZE   /* Is this still right? */
608 #   endif
609 #   ifdef AMIGA
610 #       define OS_TYPE "AMIGA"
611                 /* STACKBOTTOM and DATASTART handled specially  */
612                 /* in os_dep.c                                  */
613 #       define DATAEND  /* not needed */
614 #       define GETPAGESIZE() 4096
615 #   endif
616 #   ifdef MACOS
617 #     ifndef __LOWMEM__
618 #     include <LowMem.h>
619 #     endif
620 #     define OS_TYPE "MACOS"
621                         /* see os_dep.c for details of global data segments. */
622 #     define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
623 #     define DATAEND    /* not needed */
624 #     define GETPAGESIZE() 4096
625 #   endif
626 #   ifdef NEXT
627 #       define OS_TYPE "NEXT"
628 #       define DATASTART ((ptr_t) get_etext())
629 #       define STACKBOTTOM ((ptr_t) 0x4000000)
630 #       define DATAEND  /* not needed */
631 #   endif
632 # endif
633
634 # ifdef POWERPC
635 #   define MACH_TYPE "POWERPC"
636 #   ifdef MACOS
637 #     define ALIGNMENT 2  /* Still necessary?  Could it be 4?   */
638 #     ifndef __LOWMEM__
639 #     include <LowMem.h>
640 #     endif
641 #     define OS_TYPE "MACOS"
642                         /* see os_dep.c for details of global data segments. */
643 #     define STACKBOTTOM ((ptr_t) LMGetCurStackBase())
644 #     define DATAEND  /* not needed */
645 #   endif
646 #   ifdef LINUX
647 #     define ALIGNMENT 4        /* Guess.  Can someone verify?  */
648                                 /* This was 2, but that didn't sound right. */
649 #     define OS_TYPE "LINUX"
650 #     define HEURISTIC1
651 #     define DYNAMIC_LOADING
652 #     undef STACK_GRAN
653 #     define STACK_GRAN 0x10000000
654         /* Stack usually starts at 0x80000000 */
655 #     define LINUX_DATA_START
656       extern int _end;
657 #     define DATAEND (&_end)
658 #   endif
659 #   ifdef MACOSX
660       /* There are reasons to suspect this may not be reliable.         */
661 #     define ALIGNMENT 4
662 #     define OS_TYPE "MACOSX"
663 #     define DATASTART ((ptr_t) get_etext())
664 #     define STACKBOTTOM ((ptr_t) 0xc0000000)
665 #     define DATAEND    /* not needed */
666 #     define MPROTECT_VDB
667 #     include <unistd.h>
668 #     define GETPAGESIZE() getpagesize()
669 #   endif
670 #   ifdef NETBSD
671 #     define ALIGNMENT 4
672 #     define OS_TYPE "NETBSD"
673 #     define HEURISTIC2
674       extern char etext;
675 #     define DATASTART GC_data_start
676 #     define DYNAMIC_LOADING
677 #   endif
678 #   ifdef NOSYS
679 #     define ALIGNMENT 4
680 #     define OS_TYPE "NOSYS"
681       extern void __end, __dso_handle;
682 #     define DATASTART (&__dso_handle)  /* OK, that's ugly.  */
683 #     define DATAEND (&__end)
684         /* Stack starts at 0xE0000000 for the simulator.  */
685 #     undef STACK_GRAN
686 #     define STACK_GRAN 0x10000000
687 #     define HEURISTIC1
688 #   endif
689 # endif
690
691 # ifdef VAX
692 #   define MACH_TYPE "VAX"
693 #   define ALIGNMENT 4  /* Pointers are longword aligned by 4.2 C compiler */
694     extern char etext;
695 #   define DATASTART ((ptr_t)(&etext))
696 #   ifdef BSD
697 #       define OS_TYPE "BSD"
698 #       define HEURISTIC1
699                         /* HEURISTIC2 may be OK, but it's hard to test. */
700 #   endif
701 #   ifdef ULTRIX
702 #       define OS_TYPE "ULTRIX"
703 #       define STACKBOTTOM ((ptr_t) 0x7fffc800)
704 #   endif
705 # endif
706
707 # ifdef RT
708 #   define MACH_TYPE "RT"
709 #   define ALIGNMENT 4
710 #   define DATASTART ((ptr_t) 0x10000000)
711 #   define STACKBOTTOM ((ptr_t) 0x1fffd800)
712 # endif
713
714 # ifdef SPARC
715 #   define MACH_TYPE "SPARC"
716 #   if defined(__arch64__) || defined(__sparcv9)
717 #     define ALIGNMENT 8
718 #   else
719 #     define ALIGNMENT 4        /* Required by hardware */
720 #   endif
721 #   define ALIGN_DOUBLE
722 #   ifdef SUNOS5
723 #       define OS_TYPE "SUNOS5"
724         extern int _etext;
725         extern int _end;
726         extern char * GC_SysVGetDataStart();
727 #       define DATASTART (ptr_t)GC_SysVGetDataStart(0x10000, &_etext)
728 #       define DATAEND (&_end)
729 #       ifndef USE_MMAP
730 #           define USE_MMAP
731 #       endif
732 #       ifdef USE_MMAP
733 #         define HEAP_START (ptr_t)0x40000000
734 #       else
735 #         define HEAP_START DATAEND
736 #       endif
737 #       define PROC_VDB
738 /*      HEURISTIC1 reportedly no longer works under 2.7.                */
739 /*      HEURISTIC2 probably works, but this appears to be preferable.   */
740 /*      Apparently USRSTACK is defined to be USERLIMIT, but in some     */
741 /*      installations that's undefined.  We work around this with a     */
742 /*      gross hack:                                                     */
743 #       include <sys/vmparam.h>
744 #       ifdef USERLIMIT
745           /* This should work everywhere, but doesn't.  */
746 #         define STACKBOTTOM USRSTACK
747 #       else
748 #         define HEURISTIC2
749 #       endif
750 #       include <unistd.h>
751 #       define GETPAGESIZE()  sysconf(_SC_PAGESIZE)
752                 /* getpagesize() appeared to be missing from at least one */
753                 /* Solaris 5.4 installation.  Weird.                      */
754 #       define DYNAMIC_LOADING
755 #   endif
756 #   ifdef SUNOS4
757 #       define OS_TYPE "SUNOS4"
758         /* [If you have a weak stomach, don't read this.]               */
759         /* We would like to use:                                        */
760 /* #       define DATASTART ((ptr_t)((((word) (&etext)) + 0x1fff) & ~0x1fff)) */
761         /* This fails occasionally, due to an ancient, but very         */
762         /* persistent ld bug.  &etext is set 32 bytes too high.         */
763         /* We instead read the text segment size from the a.out         */
764         /* header, which happens to be mapped into our address space    */
765         /* at the start of the text segment.  The detective work here   */
766         /* was done by Robert Ehrlich, Manuel Serrano, and Bernard      */
767         /* Serpette of INRIA.                                           */
768         /* This assumes ZMAGIC, i.e. demand-loadable executables.       */
769 #       define TEXTSTART 0x2000
770 #       define DATASTART ((ptr_t)(*(int *)(TEXTSTART+0x4)+TEXTSTART))
771 #       define MPROTECT_VDB
772 #       define HEURISTIC1
773 #       define DYNAMIC_LOADING
774 #   endif
775 #   ifdef DRSNX
776 #       define CPP_WORDSZ 32
777 #       define OS_TYPE "DRSNX"
778         extern char * GC_SysVGetDataStart();
779         extern int etext;
780 #       define DATASTART (ptr_t)GC_SysVGetDataStart(0x10000, &etext)
781 #       define MPROTECT_VDB
782 #       define STACKBOTTOM ((ptr_t) 0xdfff0000)
783 #       define DYNAMIC_LOADING
784 #   endif
785 #   ifdef LINUX
786 #     define OS_TYPE "LINUX"
787 #     ifdef __ELF__
788 #       define DYNAMIC_LOADING
789 #     else
790           Linux Sparc/a.out not supported
791 #     endif
792       extern int _end;
793       extern int _etext;
794 #     define DATAEND (&_end)
795 #     define SVR4
796 #     ifdef __arch64__
797 #       define STACKBOTTOM ((ptr_t) 0x80000000000ULL)
798 #       define DATASTART (ptr_t)GC_SysVGetDataStart(0x100000, &_etext)
799 #       define CPP_WORDSZ 64
800 #     else
801 #       define STACKBOTTOM ((ptr_t) 0xf0000000)
802 #       define DATASTART (ptr_t)GC_SysVGetDataStart(0x10000, &_etext)
803 #     endif
804 #   endif
805 #   ifdef OPENBSD
806 #     define OS_TYPE "OPENBSD"
807 #     define STACKBOTTOM ((ptr_t) 0xf8000000)
808       extern int etext;
809 #     define DATASTART ((ptr_t)(&etext))
810 #   endif
811 #   ifdef NETBSD
812 #     define OS_TYPE "NETBSD"
813 #     define HEURISTIC2
814 #     ifdef __ELF__
815 #       define DATASTART GC_data_start
816 #       define DYNAMIC_LOADING
817 #     else
818         extern char etext;
819 #       define DATASTART ((ptr_t)(&etext))
820 #     endif
821 #   endif
822 # endif
823
824 # ifdef I386
825 #   define MACH_TYPE "I386"
826 #   define ALIGNMENT 4  /* Appears to hold for all "32 bit" compilers   */
827                         /* except Borland.  The -a4 option fixes        */
828                         /* Borland.                                     */
829                         /* Ivan Demakov: For Watcom the option is -zp4. */
830 #   ifndef SMALL_CONFIG
831 #     define ALIGN_DOUBLE /* Not strictly necessary, but may give speed   */
832                           /* improvement on Pentiums.                     */
833 #   endif
834 #   ifdef HAVE_BUILTIN_UNWIND_INIT
835 #       define USE_GENERIC_PUSH_REGS
836 #   endif
837 #   ifdef SEQUENT
838 #       define OS_TYPE "SEQUENT"
839         extern int etext;
840 #       define DATASTART ((ptr_t)((((word) (&etext)) + 0xfff) & ~0xfff))
841 #       define STACKBOTTOM ((ptr_t) 0x3ffff000) 
842 #   endif
843 #   ifdef BEOS
844 #     define OS_TYPE "BEOS"
845 #     include <OS.h>
846 #     define GETPAGESIZE() B_PAGE_SIZE
847       extern int etext;
848 #     define DATASTART ((ptr_t)((((word) (&etext)) + 0xfff) & ~0xfff))
849 #   endif
850 #   ifdef SUNOS5
851 #       define OS_TYPE "SUNOS5"
852         extern int _etext, _end;
853         extern char * GC_SysVGetDataStart();
854 #       define DATASTART GC_SysVGetDataStart(0x1000, &_etext)
855 #       define DATAEND (&_end)
856 /*      # define STACKBOTTOM ((ptr_t)(&_start)) worked through 2.7,     */
857 /*      but reportedly breaks under 2.8.  It appears that the stack     */
858 /*      base is a property of the executable, so this should not break  */
859 /*      old executables.                                                */
860 /*      HEURISTIC2 probably works, but this appears to be preferable.   */
861 #       include <sys/vmparam.h>
862 #       define STACKBOTTOM USRSTACK
863 /** At least in Solaris 2.5, PROC_VDB gives wrong values for dirty bits. */
864 #       ifdef SOLARIS25_PROC_VDB_BUG_FIXED
865 #         define PROC_VDB
866 #       endif
867 #       define DYNAMIC_LOADING
868 #       ifndef USE_MMAP
869 #           define USE_MMAP
870 #       endif
871 #       ifdef USE_MMAP
872 #         define HEAP_START (ptr_t)0x40000000
873 #       else
874 #         define HEAP_START DATAEND
875 #       endif
876 #   endif
877 #   ifdef SCO
878 #       define OS_TYPE "SCO"
879         extern int etext;
880 #       define DATASTART ((ptr_t)((((word) (&etext)) + 0x3fffff) \
881                                   & ~0x3fffff) \
882                                  +((word)&etext & 0xfff))
883 #       define STACKBOTTOM ((ptr_t) 0x7ffffffc)
884 #   endif
885 #   ifdef SCO_ELF
886 #       define OS_TYPE "SCO_ELF"
887         extern int etext;
888 #       define DATASTART ((ptr_t)(&etext))
889 #       define STACKBOTTOM ((ptr_t) 0x08048000)
890 #       define DYNAMIC_LOADING
891 #       define ELF_CLASS ELFCLASS32
892 #   endif
893 #   ifdef LINUX
894 #       define OS_TYPE "LINUX"
895 #       define LINUX_STACKBOTTOM
896 #       if 0
897 #         define HEURISTIC1
898 #         undef STACK_GRAN
899 #         define STACK_GRAN 0x10000000
900           /* STACKBOTTOM is usually 0xc0000000, but this changes with   */
901           /* different kernel configurations.  In particular, systems   */
902           /* with 2GB physical memory will usually move the user        */
903           /* address space limit, and hence initial SP to 0x80000000.   */
904 #       endif
905 #       if !defined(GC_LINUX_THREADS) || !defined(REDIRECT_MALLOC)
906 #           define MPROTECT_VDB
907 #       else
908             /* We seem to get random errors in incremental mode,        */
909             /* possibly because Linux threads is itself a malloc client */
910             /* and can't deal with the signals.                         */
911 #       endif
912 #       ifdef __ELF__
913 #            define DYNAMIC_LOADING
914 #            ifdef UNDEFINED    /* includes ro data */
915                extern int _etext;
916 #              define DATASTART ((ptr_t)((((word) (&_etext)) + 0xfff) & ~0xfff))
917 #            endif
918 #            include <features.h>
919 #            if defined(__GLIBC__) && __GLIBC__ >= 2
920 #                define LINUX_DATA_START
921 #            else
922                  extern char **__environ;
923 #                define DATASTART ((ptr_t)(&__environ))
924                               /* hideous kludge: __environ is the first */
925                               /* word in crt0.o, and delimits the start */
926                               /* of the data segment, no matter which   */
927                               /* ld options were passed through.        */
928                               /* We could use _etext instead, but that  */
929                               /* would include .rodata, which may       */
930                               /* contain large read-only data tables    */
931                               /* that we'd rather not scan.             */
932 #            endif
933              extern int _end;
934 #            define DATAEND (&_end)
935 #       else
936              extern int etext;
937 #            define DATASTART ((ptr_t)((((word) (&etext)) + 0xfff) & ~0xfff))
938 #       endif
939 #       ifdef USE_I686_PREFETCH
940 #         define PREFETCH(x) \
941             __asm__ __volatile__ ("     prefetchnta     %0": : "m"(*(char *)(x)))
942             /* Empirically prefetcht0 is much more effective at reducing        */
943             /* cache miss stalls for the targetted load instructions.  But it   */
944             /* seems to interfere enough with other cache traffic that the net  */
945             /* result is worse than prefetchnta.                                */
946 #         if 0 
947             /* Using prefetches for write seems to have a slight negative       */
948             /* impact on performance, at least for a PIII/500.                  */
949 #           define PREFETCH_FOR_WRITE(x) \
950               __asm__ __volatile__ ("   prefetcht0      %0": : "m"(*(char *)(x)))
951 #         endif
952 #       endif
953 #       ifdef USE_3DNOW_PREFETCH
954 #         define PREFETCH(x) \
955             __asm__ __volatile__ ("     prefetch        %0": : "m"(*(char *)(x)))
956 #         define PREFETCH_FOR_WRITE(x) \
957             __asm__ __volatile__ ("     prefetchw       %0": : "m"(*(char *)(x)))
958 #       endif
959 #   endif
960 #   ifdef CYGWIN32
961 #       define OS_TYPE "CYGWIN32"
962           extern int _data_start__;
963           extern int _data_end__;
964           extern int _bss_start__;
965           extern int _bss_end__;
966         /* For binutils 2.9.1, we have                  */
967         /*      DATASTART   = _data_start__             */
968         /*      DATAEND     = _bss_end__                */
969         /* whereas for some earlier versions it was     */
970         /*      DATASTART   = _bss_start__              */
971         /*      DATAEND     = _data_end__               */
972         /* To get it right for both, we take the        */
973         /* minumum/maximum of the two.                  */
974 #       define MAX(x,y) ((x) > (y) ? (x) : (y))
975 #       define MIN(x,y) ((x) < (y) ? (x) : (y))
976 #       define DATASTART ((ptr_t) MIN(&_data_start__, &_bss_start__))
977 #       define DATAEND   ((ptr_t) MAX(&_data_end__, &_bss_end__))
978 #       undef STACK_GRAN
979 #       define STACK_GRAN 0x10000
980 #       define HEURISTIC1
981 #   endif
982 #   ifdef OS2
983 #       define OS_TYPE "OS2"
984                 /* STACKBOTTOM and DATASTART are handled specially in   */
985                 /* os_dep.c. OS2 actually has the right                 */
986                 /* system call!                                         */
987 #       define DATAEND  /* not needed */
988 #       define USE_GENERIC_PUSH_REGS
989 #   endif
990 #   ifdef MSWIN32
991 #       define OS_TYPE "MSWIN32"
992                 /* STACKBOTTOM and DATASTART are handled specially in   */
993                 /* os_dep.c.                                            */
994 #       ifndef __WATCOMC__
995 #         define MPROTECT_VDB
996 #       endif
997 #       define DATAEND  /* not needed */
998 #   endif
999 #   ifdef MSWINCE
1000 #       define OS_TYPE "MSWINCE"
1001 #       define DATAEND  /* not needed */
1002 #   endif
1003 #   ifdef DJGPP
1004 #       define OS_TYPE "DJGPP"
1005 #       include "stubinfo.h"
1006         extern int etext;
1007         extern int _stklen;
1008         extern int __djgpp_stack_limit;
1009 #       define DATASTART ((ptr_t)((((word) (&etext)) + 0x1ff) & ~0x1ff))
1010 /* #       define STACKBOTTOM ((ptr_t)((word) _stubinfo + _stubinfo->size \
1011                                                      + _stklen)) */
1012 #       define STACKBOTTOM ((ptr_t)((word) __djgpp_stack_limit + _stklen))
1013                 /* This may not be right.  */
1014 #   endif
1015 #   ifdef OPENBSD
1016 #       define OS_TYPE "OPENBSD"
1017 #   endif
1018 #   ifdef FREEBSD
1019 #       define OS_TYPE "FREEBSD"
1020 #       define MPROTECT_VDB
1021 #       define FREEBSD_STACKBOTTOM
1022 #       ifdef __ELF__
1023 #           define DYNAMIC_LOADING
1024 #       endif
1025 #   endif
1026 #   ifdef NETBSD
1027 #       define OS_TYPE "NETBSD"
1028 #   endif
1029 #   ifdef THREE86BSD
1030 #       define OS_TYPE "THREE86BSD"
1031 #   endif
1032 #   ifdef BSDI
1033 #       define OS_TYPE "BSDI"
1034 #   endif
1035 #   if defined(OPENBSD) || defined(NETBSD) || defined(FREEBSD) \
1036         || defined(THREE86BSD) || defined(BSDI)
1037 #       define HEURISTIC2
1038         extern char etext;
1039 #       define DATASTART ((ptr_t)(&etext))
1040 #   endif
1041 #   ifdef NEXT
1042 #       define OS_TYPE "NEXT"
1043 #       define DATASTART ((ptr_t) get_etext())
1044 #       define STACKBOTTOM ((ptr_t)0xc0000000)
1045 #       define DATAEND  /* not needed */
1046 #   endif
1047 #   ifdef DOS4GW
1048 #     define OS_TYPE "DOS4GW"
1049       extern long __nullarea;
1050       extern char _end;
1051       extern char *_STACKTOP;
1052       /* Depending on calling conventions Watcom C either precedes
1053          or does not precedes with undescore names of C-variables.
1054          Make sure startup code variables always have the same names.  */
1055       #pragma aux __nullarea "*";
1056       #pragma aux _end "*";
1057 #     define STACKBOTTOM ((ptr_t) _STACKTOP)
1058                          /* confused? me too. */
1059 #     define DATASTART ((ptr_t) &__nullarea)
1060 #     define DATAEND ((ptr_t) &_end)
1061 #   endif
1062 #   ifdef HURD
1063 #     define OS_TYPE "HURD"
1064 #     define STACK_GROWS_DOWN
1065 #     define HEURISTIC2
1066       extern int  __data_start;
1067 #     define DATASTART ( (ptr_t) (&__data_start))
1068       extern int   _end;
1069 #     define DATAEND ( (ptr_t) (&_end))
1070 /* #     define MPROTECT_VDB  Not quite working yet? */
1071 #     define DYNAMIC_LOADING
1072 #   endif
1073 # endif
1074
1075 # ifdef NS32K
1076 #   define MACH_TYPE "NS32K"
1077 #   define ALIGNMENT 4
1078     extern char **environ;
1079 #   define DATASTART ((ptr_t)(&environ))
1080                               /* hideous kludge: environ is the first   */
1081                               /* word in crt0.o, and delimits the start */
1082                               /* of the data segment, no matter which   */
1083                               /* ld options were passed through.        */
1084 #   define STACKBOTTOM ((ptr_t) 0xfffff000) /* for Encore */
1085 # endif
1086
1087 # ifdef MIPS
1088 #   define MACH_TYPE "MIPS"
1089 #   ifdef LINUX
1090       /* This was developed for a linuxce style platform.  Probably     */
1091       /* needs to be tweaked for workstation class machines.            */
1092 #     define OS_TYPE "LINUX"
1093       extern int __data_start;
1094 #     define DATASTART ((ptr_t)(&__data_start))
1095 #     define ALIGNMENT 4
1096 #     define USE_GENERIC_PUSH_REGS
1097 #     define STACKBOTTOM ((ptr_t)0x7fff8000)
1098         /* Older toolchains may need 0x80000000.        */
1099         /* In many cases, this should probably use LINUX_STACKBOTTOM    */
1100         /* instead. But some kernel versions seem to give the wrong     */
1101         /* value from /proc.                                            */
1102 #   endif /* Linux */
1103 #   ifdef ULTRIX
1104 #       define HEURISTIC2
1105 #       define DATASTART (ptr_t)0x10000000
1106                               /* Could probably be slightly higher since */
1107                               /* startup code allocates lots of stuff.   */
1108 #       define OS_TYPE "ULTRIX"
1109 #       define ALIGNMENT 4
1110 #   endif
1111 #   ifdef RISCOS
1112 #       define HEURISTIC2
1113 #       define DATASTART (ptr_t)0x10000000
1114 #       define OS_TYPE "RISCOS"
1115 #       define ALIGNMENT 4  /* Required by hardware */
1116 #   endif
1117 #   ifdef IRIX5
1118 #       define HEURISTIC2
1119         extern int _fdata;
1120 #       define DATASTART ((ptr_t)(&_fdata))
1121 #       ifdef USE_MMAP
1122 #         define HEAP_START (ptr_t)0x30000000
1123 #       else
1124 #         define HEAP_START DATASTART
1125 #       endif
1126                               /* Lowest plausible heap address.         */
1127                               /* In the MMAP case, we map there.        */
1128                               /* In either case it is used to identify  */
1129                               /* heap sections so they're not           */
1130                               /* considered as roots.                   */
1131 #       define OS_TYPE "IRIX5"
1132 #       define MPROTECT_VDB
1133 #       ifdef _MIPS_SZPTR
1134 #         define CPP_WORDSZ _MIPS_SZPTR
1135 #         define ALIGNMENT (_MIPS_SZPTR/8)
1136 #         if CPP_WORDSZ != 64
1137 #           define ALIGN_DOUBLE
1138 #         endif
1139 #       else
1140 #         define ALIGNMENT 4
1141 #         define ALIGN_DOUBLE
1142 #       endif
1143 #       define DYNAMIC_LOADING
1144 #   endif
1145 #   ifdef MSWINCE
1146 #       define OS_TYPE "MSWINCE"
1147 #       define ALIGNMENT 4
1148 #       define DATAEND /* not needed */
1149 #   endif
1150 #   if defined(NETBSD)
1151       /* This also checked for __MIPSEL__ .  Why?  NETBSD recognition   */
1152       /* should be handled at the top of the file.                      */
1153 #     define ALIGNMENT 4
1154 #     define OS_TYPE "NETBSD"
1155 #     define HEURISTIC2
1156 #     define USE_GENERIC_PUSH_REGS
1157 #     ifdef __ELF__
1158         extern int etext;
1159 #       define DATASTART GC_data_start
1160 #       define NEED_FIND_LIMIT
1161 #       define DYNAMIC_LOADING
1162 #     else
1163 #       define DATASTART ((ptr_t) 0x10000000)
1164 #       define STACKBOTTOM ((ptr_t) 0x7ffff000)
1165 #     endif /* _ELF_ */
1166 #  endif
1167 # endif
1168
1169 # ifdef RS6000
1170 #   define MACH_TYPE "RS6000"
1171 #   define ALIGNMENT 4
1172 #   define DATASTART ((ptr_t)0x20000000)
1173     extern int errno;
1174 #   define STACKBOTTOM ((ptr_t)((ulong)&errno))
1175 #   define DYNAMIC_LOADING
1176         /* For really old versions of AIX, this may have to be removed. */
1177 # endif
1178
1179 # ifdef HP_PA
1180 #   define MACH_TYPE "HP_PA"
1181 #   ifdef __LP64__
1182 #     define CPP_WORDSZ 64
1183 #     define ALIGNMENT 8
1184 #   else
1185 #     define CPP_WORDSZ 32
1186 #     define ALIGNMENT 4
1187 #     define ALIGN_DOUBLE
1188 #   endif
1189 #   if !defined(GC_HPUX_THREADS) && !defined(GC_LINUX_THREADS)
1190 #     ifndef LINUX /* For now. */
1191 #       define MPROTECT_VDB
1192 #     endif
1193 #   else
1194 #     define GENERIC_COMPARE_AND_SWAP
1195         /* No compare-and-swap instruction.  Use pthread mutexes        */
1196         /* when we absolutely have to.                                  */
1197 #     ifdef PARALLEL_MARK
1198 #       define USE_MARK_BYTES
1199                 /* Minimize compare-and-swap usage.             */
1200 #     endif
1201 #   endif
1202 #   define STACK_GROWS_UP
1203 #   ifdef HPUX
1204 #     define OS_TYPE "HPUX"
1205       extern int __data_start;
1206 #     define DATASTART ((ptr_t)(&__data_start))
1207 #     if 0
1208         /* The following appears to work for 7xx systems running HP/UX  */
1209         /* 9.xx Furthermore, it might result in much faster             */
1210         /* collections than HEURISTIC2, which may involve scanning      */
1211         /* segments that directly precede the stack.  It is not the     */
1212         /* default, since it may not work on older machine/OS           */
1213         /* combinations. (Thanks to Raymond X.T. Nijssen for uncovering */
1214         /* this.)                                                       */
1215 #       define STACKBOTTOM ((ptr_t) 0x7b033000)  /* from /etc/conf/h/param.h */
1216 #     else
1217         /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2       */
1218         /* to this.  Note that the GC must be initialized before the    */
1219         /* first putenv call.                                           */
1220         extern char ** environ;
1221 #       define STACKBOTTOM ((ptr_t)environ)
1222 #     endif
1223 #     define DYNAMIC_LOADING
1224 #     include <unistd.h>
1225 #     define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1226 #     ifndef __GNUC__
1227 #       define PREFETCH(x)  { \
1228                               register long addr = (long)(x); \
1229                               (void) _asm ("LDW", 0, 0, addr, 0); \
1230                             }
1231 #     endif
1232 #   endif /* HPUX */
1233 #   ifdef LINUX
1234 #     define OS_TYPE "LINUX"
1235 #     define LINUX_STACKBOTTOM
1236 #     define DYNAMIC_LOADING
1237 #     define LINUX_DATA_START
1238       extern int _end;
1239 #     define DATAEND (&_end)
1240 #   endif /* LINUX */
1241 # endif /* HP_PA */
1242
1243 # ifdef ALPHA
1244 #   define MACH_TYPE "ALPHA"
1245 #   define ALIGNMENT 8
1246 #   ifdef NETBSD
1247 #       define OS_TYPE "NETBSD"
1248 #       define HEURISTIC2
1249 #       define DATASTART GC_data_start
1250 #       define ELFCLASS32 32
1251 #       define ELFCLASS64 64
1252 #       define ELF_CLASS ELFCLASS64
1253 #       define CPP_WORDSZ 64
1254 #       define DYNAMIC_LOADING
1255 #   endif
1256 #   ifdef OPENBSD
1257 #       define OS_TYPE "OPENBSD"
1258 #       define HEURISTIC2
1259 #       define CPP_WORDSZ 64
1260 #       ifdef __ELF__   /* since OpenBSD/Alpha 2.9 */
1261 #          define DATASTART GC_data_start
1262 #          define ELFCLASS32 32
1263 #          define ELFCLASS64 64
1264 #          define ELF_CLASS ELFCLASS64
1265 #       else            /* ECOFF, until OpenBSD/Alpha 2.7 */
1266 #          define DATASTART ((ptr_t) 0x140000000)
1267 #       endif
1268 #   endif
1269 #   ifdef OSF1
1270 #       define OS_TYPE "OSF1"
1271 #       define DATASTART ((ptr_t) 0x140000000)
1272         extern int _end;
1273 #       define DATAEND ((ptr_t) &_end)
1274         extern char ** environ;
1275         /* round up from the value of environ to the nearest page boundary */
1276         /* Probably breaks if putenv is called before collector            */
1277         /* initialization.                                                 */
1278 #       define STACKBOTTOM ((ptr_t)(((word)(environ) | (getpagesize()-1))+1))
1279 /* #    define HEURISTIC2 */
1280         /* Normally HEURISTIC2 is too conervative, since                */
1281         /* the text segment immediately follows the stack.              */
1282         /* Hence we give an upper pound.                                */
1283         /* This is currently unused, since we disabled HEURISTIC2       */
1284         extern int __start;
1285 #       define HEURISTIC2_LIMIT ((ptr_t)((word)(&__start) & ~(getpagesize()-1)))
1286 #       define CPP_WORDSZ 64
1287 #       define MPROTECT_VDB
1288 #       define DYNAMIC_LOADING
1289 #   endif
1290 #   ifdef LINUX
1291 #       define OS_TYPE "LINUX"
1292 #       define CPP_WORDSZ 64
1293 #       define STACKBOTTOM ((ptr_t) 0x120000000)
1294 #       ifdef __ELF__
1295 #         define SEARCH_FOR_DATA_START
1296 #         define DATASTART GC_data_start
1297 #         define DYNAMIC_LOADING
1298 #       else
1299 #           define DATASTART ((ptr_t) 0x140000000)
1300 #       endif
1301         extern int _end;
1302 #       define DATAEND (&_end)
1303 #       define MPROTECT_VDB
1304                 /* Has only been superficially tested.  May not */
1305                 /* work on all versions.                        */
1306 #   endif
1307 # endif
1308
1309 # ifdef IA64
1310 #   define MACH_TYPE "IA64"
1311 #   define USE_GENERIC_PUSH_REGS
1312         /* We need to get preserved registers in addition to register   */
1313         /* windows.   That's easiest to do with setjmp.                 */
1314 #   ifdef PARALLEL_MARK
1315 #       define USE_MARK_BYTES
1316             /* Compare-and-exchange is too expensive to use for         */
1317             /* setting mark bits.                                       */
1318 #   endif
1319 #   ifdef HPUX
1320 #       ifdef _ILP32
1321 #         define CPP_WORDSZ 32
1322 #         define ALIGN_DOUBLE
1323             /* Requires 8 byte alignment for malloc */
1324 #         define ALIGNMENT 4
1325 #       else
1326 #         ifndef _LP64
1327                 ---> unknown ABI
1328 #         endif
1329 #         define CPP_WORDSZ 64
1330 #         define ALIGN_DOUBLE
1331             /* Requires 16 byte alignment for malloc */
1332 #         define ALIGNMENT 8
1333 #       endif
1334 #       define OS_TYPE "HPUX"   
1335         extern int __data_start;
1336 #       define DATASTART ((ptr_t)(&__data_start))
1337         /* Gustavo Rodriguez-Rivera suggested changing HEURISTIC2       */
1338         /* to this.  Note that the GC must be initialized before the    */
1339         /* first putenv call.                                           */
1340         extern char ** environ;
1341 #       define STACKBOTTOM ((ptr_t)environ)
1342 #       define DYNAMIC_LOADING
1343 #       include <unistd.h>
1344 #       define GETPAGESIZE() sysconf(_SC_PAGE_SIZE)
1345         /* The following was empirically determined, and is probably    */
1346         /* not very robust.                                             */
1347         /* Note that the backing store base seems to be at a nice       */
1348         /* address minus one page.                                      */
1349 #       define BACKING_STORE_DISPLACEMENT 0x1000000
1350 #       define BACKING_STORE_ALIGNMENT 0x1000
1351 #       define BACKING_STORE_BASE \
1352           (ptr_t)(((word)GC_stackbottom - BACKING_STORE_DISPLACEMENT - 1) \
1353                         & ~(BACKING_STORE_ALIGNMENT - 1))
1354 #   endif
1355 #   ifdef LINUX
1356 #       define CPP_WORDSZ 64
1357 #       define ALIGN_DOUBLE
1358           /* Requires 16 byte alignment for malloc */
1359 #       define ALIGNMENT 8
1360 #       define OS_TYPE "LINUX"
1361         /* The following works on NUE and older kernels:        */
1362 /* #       define STACKBOTTOM ((ptr_t) 0xa000000000000000l)     */
1363         /* This does not work on NUE:                           */
1364 #       define LINUX_STACKBOTTOM
1365         /* We also need the base address of the register stack  */
1366         /* backing store.  This is computed in                  */
1367         /* GC_linux_register_stack_base based on the following  */
1368         /* constants:                                           */
1369 #       define BACKING_STORE_ALIGNMENT 0x100000
1370 #       define BACKING_STORE_DISPLACEMENT 0x80000000
1371         extern char * GC_register_stackbottom;
1372 #       define BACKING_STORE_BASE ((ptr_t)GC_register_stackbottom)
1373 #       define SEARCH_FOR_DATA_START
1374 #       define DATASTART GC_data_start
1375 #       define DYNAMIC_LOADING
1376 #       define MPROTECT_VDB
1377                 /* Requires Linux 2.3.47 or later.      */
1378         extern int _end;
1379 #       define DATAEND (&_end)
1380 #       ifdef __GNUC__
1381 #         define PREFETCH(x) \
1382             __asm__ ("  lfetch  [%0]": : "r"((void *)(x)))
1383 #         define PREFETCH_FOR_WRITE(x) \
1384             __asm__ ("  lfetch.excl     [%0]": : "r"((void *)(x)))
1385 #         define CLEAR_DOUBLE(x) \
1386             __asm__ ("  stf.spill       [%0]=f0": : "r"((void *)(x)))
1387 #       endif
1388 #   endif
1389 # endif
1390
1391 # ifdef M88K
1392 #   define MACH_TYPE "M88K"
1393 #   define ALIGNMENT 4
1394 #   define ALIGN_DOUBLE
1395     extern int etext;
1396 #   ifdef CX_UX
1397 #       define OS_TYPE "CX_UX"
1398 #       define DATASTART ((((word)&etext + 0x3fffff) & ~0x3fffff) + 0x10000)
1399 #   endif
1400 #   ifdef  DGUX
1401 #       define OS_TYPE "DGUX"
1402         extern char * GC_SysVGetDataStart();
1403 #       define DATASTART (ptr_t)GC_SysVGetDataStart(0x10000, &etext)
1404 #   endif
1405 #   define STACKBOTTOM ((char*)0xf0000000) /* determined empirically */
1406 # endif
1407
1408 # ifdef S370
1409 #   define MACH_TYPE "S370"
1410 #   define ALIGNMENT 4  /* Required by hardware */
1411 #   define USE_GENERIC_PUSH_REGS
1412 #   ifdef UTS4
1413 #       define OS_TYPE "UTS4"
1414         extern int etext;
1415         extern int _etext;
1416         extern int _end;
1417         extern char * GC_SysVGetDataStart();
1418 #       define DATASTART (ptr_t)GC_SysVGetDataStart(0x10000, &_etext)
1419 #       define DATAEND (&_end)
1420 #       define HEURISTIC2
1421 #   endif
1422 #   ifdef LINUX
1423 #       define OS_TYPE "LINUX"
1424 #       define HEURISTIC1
1425 #       define DYNAMIC_LOADING
1426         extern int __data_start;
1427 #       define DATASTART ((ptr_t)(&__data_start))
1428 #   endif
1429 # endif
1430
1431 # if defined(PJ)
1432 #   define ALIGNMENT 4
1433     extern int _etext;
1434 #   define DATASTART ((ptr_t)(&_etext))
1435 #   define HEURISTIC1
1436 # endif
1437
1438 # ifdef ARM32
1439 #   define CPP_WORDSZ 32
1440 #   define MACH_TYPE "ARM32"
1441 #   define ALIGNMENT 4
1442 #   ifdef NETBSD
1443 #       define OS_TYPE "NETBSD"
1444 #       define HEURISTIC2
1445         extern char etext;
1446 #       define DATASTART ((ptr_t)(&etext))
1447 #       define USE_GENERIC_PUSH_REGS
1448 #   endif
1449 #   ifdef LINUX
1450 #       define OS_TYPE "LINUX"
1451 #       define HEURISTIC1
1452 #       undef STACK_GRAN
1453 #       define STACK_GRAN 0x10000000
1454 #       define USE_GENERIC_PUSH_REGS
1455 #       ifdef __ELF__
1456 #            define DYNAMIC_LOADING
1457 #            include <features.h>
1458 #            if defined(__GLIBC__) && __GLIBC__ >= 2
1459 #                define LINUX_DATA_START
1460 #            else
1461                  extern char **__environ;
1462 #                define DATASTART ((ptr_t)(&__environ))
1463                               /* hideous kludge: __environ is the first */
1464                               /* word in crt0.o, and delimits the start */
1465                               /* of the data segment, no matter which   */
1466                               /* ld options were passed through.        */
1467                               /* We could use _etext instead, but that  */
1468                               /* would include .rodata, which may       */
1469                               /* contain large read-only data tables    */
1470                               /* that we'd rather not scan.             */
1471 #            endif
1472              extern int _end;
1473 #            define DATAEND (&_end)
1474 #       else
1475              extern int etext;
1476 #            define DATASTART ((ptr_t)((((word) (&etext)) + 0xfff) & ~0xfff))
1477 #       endif
1478 #   endif
1479 #   ifdef MSWINCE
1480 #     define OS_TYPE "MSWINCE"
1481 #     define DATAEND /* not needed */
1482 #   endif
1483 #endif
1484
1485 # ifdef SH
1486 #   define MACH_TYPE "SH"
1487 #   define ALIGNMENT 4
1488 #   ifdef MSWINCE
1489 #     define OS_TYPE "MSWINCE"
1490 #     define DATAEND /* not needed */
1491 #   endif
1492 #   ifdef LINUX
1493 #     define OS_TYPE "LINUX"
1494 #     define STACKBOTTOM ((ptr_t) 0x7c000000)
1495 #     define USE_GENERIC_PUSH_REGS
1496 #     define DYNAMIC_LOADING
1497 #     define LINUX_DATA_START
1498       extern int _end;
1499 #     define DATAEND (&_end)
1500 #   endif
1501 # endif
1502  
1503 # ifdef SH4
1504 #   define MACH_TYPE "SH4"
1505 #   define OS_TYPE "MSWINCE"
1506 #   define ALIGNMENT 4
1507 #   define DATAEND /* not needed */
1508 # endif
1509
1510 #ifdef LINUX_DATA_START
1511     /* Some Linux distributions arrange to define __data_start.  Some   */
1512     /* define data_start as a weak symbol.  The latter is technically   */
1513     /* broken, since the user program may define data_start, in which   */
1514     /* case we lose.  Nonetheless, we try both, prefering __data_start. */
1515     /* We assume gcc.   */
1516 #   pragma weak __data_start
1517     extern int __data_start;
1518 #   pragma weak data_start
1519     extern int data_start;
1520 #   define DATASTART ((ptr_t)(&__data_start != 0? &__data_start : &data_start))
1521 #endif
1522
1523 #if defined(LINUX) && defined(REDIRECT_MALLOC)
1524     /* Rld appears to allocate some memory with its own allocator, and  */
1525     /* some through malloc, which might be redirected.  To make this    */
1526     /* work with collectable memory, we have to scan memory allocated   */
1527     /* by rld's internal malloc.                                        */
1528 #   define USE_PROC_FOR_LIBRARIES
1529 #endif
1530     
1531 # ifndef STACK_GROWS_UP
1532 #   define STACK_GROWS_DOWN
1533 # endif
1534
1535 # ifndef CPP_WORDSZ
1536 #   define CPP_WORDSZ 32
1537 # endif
1538
1539 # ifndef OS_TYPE
1540 #   define OS_TYPE ""
1541 # endif
1542
1543 # ifndef DATAEND
1544     extern int end;
1545 #   define DATAEND (&end)
1546 # endif
1547
1548 # if defined(SVR4) && !defined(GETPAGESIZE)
1549 #    include <unistd.h>
1550 #    define GETPAGESIZE()  sysconf(_SC_PAGESIZE)
1551 # endif
1552
1553 # ifndef GETPAGESIZE
1554 #   if defined(SUNOS5) || defined(IRIX5)
1555 #       include <unistd.h>
1556 #   endif
1557 #   define GETPAGESIZE() getpagesize()
1558 # endif
1559
1560 # if defined(SUNOS5) || defined(DRSNX) || defined(UTS4)
1561     /* OS has SVR4 generic features.  Probably others also qualify.     */
1562 #   define SVR4
1563 # endif
1564
1565 # if defined(SUNOS5) || defined(DRSNX)
1566     /* OS has SUNOS5 style semi-undocumented interface to dynamic       */
1567     /* loader.                                                          */
1568 #   define SUNOS5DL
1569     /* OS has SUNOS5 style signal handlers.                             */
1570 #   define SUNOS5SIGS
1571 # endif
1572
1573 # if defined(HPUX)
1574 #   define SUNOS5SIGS
1575 # endif
1576
1577 # if defined(SVR4) || defined(LINUX) || defined(IRIX) || defined(HPUX) \
1578     || defined(OPENBSD) || defined(NETBSD) || defined(FREEBSD) \
1579     || defined(BSD) || defined(AIX) || defined(MACOSX) || defined(OSF1)
1580 #   define UNIX_LIKE   /* Basic Unix-like system calls work.    */
1581 # endif
1582
1583 # if CPP_WORDSZ != 32 && CPP_WORDSZ != 64
1584    -> bad word size
1585 # endif
1586
1587 # ifdef PCR
1588 #   undef DYNAMIC_LOADING
1589 #   undef STACKBOTTOM
1590 #   undef HEURISTIC1
1591 #   undef HEURISTIC2
1592 #   undef PROC_VDB
1593 #   undef MPROTECT_VDB
1594 #   define PCR_VDB
1595 # endif
1596
1597 # ifdef SRC_M3
1598 /* Postponed for now. */
1599 #   undef PROC_VDB
1600 #   undef MPROTECT_VDB
1601 # endif
1602
1603 # ifdef SMALL_CONFIG
1604 /* Presumably not worth the space it takes. */
1605 #   undef PROC_VDB
1606 #   undef MPROTECT_VDB
1607 # endif
1608
1609 # ifdef USE_MUNMAP
1610 #   undef MPROTECT_VDB  /* Can't deal with address space holes. */
1611 # endif
1612
1613 # ifdef PARALLEL_MARK
1614 #   undef MPROTECT_VDB  /* For now.     */
1615 # endif
1616
1617 # if !defined(PCR_VDB) && !defined(PROC_VDB) && !defined(MPROTECT_VDB)
1618 #   define DEFAULT_VDB
1619 # endif
1620
1621 # ifndef PREFETCH
1622 #   define PREFETCH(x)
1623 #   define NO_PREFETCH
1624 # endif
1625
1626 # ifndef PREFETCH_FOR_WRITE
1627 #   define PREFETCH_FOR_WRITE(x)
1628 #   define NO_PREFETCH_FOR_WRITE
1629 # endif
1630
1631 # ifndef CACHE_LINE_SIZE
1632 #   define CACHE_LINE_SIZE 32   /* Wild guess   */
1633 # endif
1634
1635 # ifndef CLEAR_DOUBLE
1636 #   define CLEAR_DOUBLE(x) \
1637         ((word*)x)[0] = 0; \
1638         ((word*)x)[1] = 0;
1639 # endif /* CLEAR_DOUBLE */
1640
1641 /* Internally we use GC_SOLARIS_THREADS to test for either old or pthreads. */
1642 # if defined(GC_SOLARIS_PTHREADS) && !defined(GC_SOLARIS_THREADS)
1643 #   define GC_SOLARIS_THREADS
1644 # endif
1645
1646 # if defined(GC_IRIX_THREADS) && !defined(IRIX5)
1647 --> inconsistent configuration
1648 # endif
1649 # if defined(GC_LINUX_THREADS) && !defined(LINUX)
1650 --> inconsistent configuration
1651 # endif
1652 # if defined(GC_SOLARIS_THREADS) && !defined(SUNOS5)
1653 --> inconsistent configuration
1654 # endif
1655 # if defined(GC_HPUX_THREADS) && !defined(HPUX)
1656 --> inconsistent configuration
1657 # endif
1658 # if defined(GC_WIN32_THREADS) && !defined(MSWIN32)
1659     /* Ideally CYGWIN32 should work, in addition to MSWIN32.  I suspect */
1660     /* the necessary code is mostly there, but nobody has actually made */
1661     /* sure the right combination of pieces is compiled in, etc.        */
1662 --> inconsistent configuration
1663 # endif
1664
1665 # if defined(PCR) || defined(SRC_M3) || \
1666         defined(GC_SOLARIS_THREADS) || defined(GC_WIN32_THREADS) || \
1667         defined(GC_PTHREADS)
1668 #   define THREADS
1669 # endif
1670
1671 # if defined(HP_PA) || defined(M88K) || defined(POWERPC) && !defined(MACOSX) \
1672      || defined(LINT) || defined(MSWINCE) \
1673      || (defined(I386) && defined(__LCC__))
1674         /* Use setjmp based hack to mark from callee-save registers.    */
1675         /* The define should move to the individual platform            */
1676         /* descriptions.                                                */
1677 #       define USE_GENERIC_PUSH_REGS
1678 # endif
1679 # if defined(I386) && defined(LINUX)
1680     /* SAVE_CALL_CHAIN is supported if the code is compiled to save     */
1681     /* frame pointers by default, i.e. no -fomit-frame-pointer flag.    */
1682 # ifdef SAVE_CALL_COUNT
1683 #   define SAVE_CALL_CHAIN 
1684 # endif
1685 # endif
1686 # if defined(SPARC)
1687 #   define SAVE_CALL_CHAIN
1688 #   define ASM_CLEAR_CODE       /* Stack clearing is crucial, and we    */
1689                                 /* include assembly code to do it well. */
1690 # endif
1691
1692 # endif /* GCCONFIG_H */