c49ea50e991438b843b928788bf1aa9b681ceb99
[projects/cmucl/cmucl.git] / src / lisp / x86-validate.h
1 /*
2  *
3  * This code was written as part of the CMU Common Lisp project at
4  * Carnegie Mellon University, and has been placed in the public domain.
5  *
6  *  $Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/lisp/x86-validate.h,v 1.34 2010/12/22 05:55:22 rtoy Exp $
7  *
8  */
9
10 #ifndef _X86_VALIDATE_H_
11 #define _X86_VALIDATE_H_
12
13 /*
14  * Also look in compiler/x86/parms.lisp for some of the parameters.
15  *
16  * Address map:
17  *
18  *  FreeBSD:
19  *      0x00000000->0x0E000000  224M C program and memory allocation.
20  *      0x0E000000->0x10000000   32M Foreign segment.
21  *      0x10000000->0x20000000  256M Read-Only Space.
22  *      0x20000000->0x28000000  128M Reserved for shared libraries.
23  *      0x28000000->0x38000000  256M Static Space.
24  *      0x38000000->0x40000000  128M Binding stack growing up.
25  *      0x40000000->0x48000000  128M Control stack growing down.
26  *      0x48000000->0xB0000000 1664M Dynamic Space.
27  *      0xB0000000->0xB1000000       Foreign Linkage Table
28  *      0xE0000000->            256M C stack - Alien stack.
29  *
30  *  OpenBSD:
31  *      0x00000000->0x0E000000  224M C program and memory allocation.
32  *      0x0E000000->0x10000000   32M Foreign segment.
33  *      0x10000000->0x20000000  256M Read-Only Space.
34  *      0x20000000->0x28000000  128M Binding stack growing up.
35  *      0x28000000->0x38000000  256M Static Space.
36  *      0x38000000->0x40000000  128M Control stack growing down.
37  *      0x40000000->0x48000000  128M Reserved for shared libraries.
38  *      0x48000000->0xB0000000 1664M Dynamic Space.
39  *      0xB0000000->0xB1000000   16M Foreign Linkage Table
40  *      0xE0000000->            256M C stack - Alien stack.
41  *
42  *  NetBSD:
43  *      0x00000000->0x0E000000  224M C program and memory allocation.
44  *      0x0E000000->0x10000000   32M Foreign segment.
45  *      0x10000000->0x20000000  256M Read-Only Space.
46  *      0x28000000->0x38000000  256M Static Space.
47  *      0x38000000->0x40000000  128M Binding stack growing up.
48  *      0x40000000->0x48000000  128M Control stack growing down.
49  *      0x48800000->0xB0000000 1656M Dynamic Space.
50  *      0xB0000000->0xB1000000   16M Foreign Linkage Table
51  *      0xE0000000->            256M C stack - Alien stack.
52  *
53  *  Linux:
54  *      0x00000000->0x08000000  128M Unused.
55  *      0x08000000->0x10000000  128M C program and memory allocation.
56  *      0x10000000->0x20000000  256M Read-Only Space.
57  *      0x20000000->0x28000000  128M Binding stack growing up.
58  *      0x28000000->0x38000000  256M Static Space.
59  *      0x38000000->0x40000000  128M Control stack growing down.
60  *      0x40000000->0x48000000  128M Reserved for shared libraries.
61  *      0x58000000->0x58100000   16M Foreign Linkage Table
62  *      0x58100000->0xBE000000 1631M Dynamic Space.
63  *      0xBFFF0000->0xC0000000       Unknown Linux mapping
64  *
65  *      (Note: 0x58000000 allows us to run on a Linux system on an AMD
66  *      x86-64.  Hence we have a gap of unused memory starting at
67  *      0x48000000.)
68  */
69
70 #ifdef __FreeBSD__
71 #define READ_ONLY_SPACE_START   (0x10000000)
72 #define READ_ONLY_SPACE_SIZE    (0x0ffff000)    /* 256MB - 1 page */
73
74 #define STATIC_SPACE_START      (0x28f00000)
75 #define STATIC_SPACE_SIZE       (0x0f0ff000)    /* 241MB - 1 page */
76
77 #define BINDING_STACK_START     (0x38000000)
78 #define BINDING_STACK_SIZE      (0x07fff000)    /* 128MB - 1 page */
79
80 #define CONTROL_STACK_START     0x40000000
81 #define CONTROL_STACK_SIZE      0x07fd8000      /* 128MB - SIGSTKSZ */
82 #define SIGNAL_STACK_START      0x47fd8000
83 #define SIGNAL_STACK_SIZE       SIGSTKSZ
84
85 #define DYNAMIC_0_SPACE_START   (0x48000000UL)
86 #ifdef GENCGC
87 #define DYNAMIC_SPACE_SIZE      (0x78000000UL)  /* May be up to 1.7 GB */
88 #else
89 #define DYNAMIC_SPACE_SIZE      (0x04000000UL)  /* 64MB */
90 #endif
91 #define DEFAULT_DYNAMIC_SPACE_SIZE      (0x20000000UL)  /* 512MB */
92 #ifdef LINKAGE_TABLE
93 #define FOREIGN_LINKAGE_SPACE_START ((unsigned long) LinkageSpaceStart)
94 #define FOREIGN_LINKAGE_SPACE_SIZE (0x100000UL) /* 1MB */
95 #endif
96 #endif /* __FreeBSD__ */
97
98
99 #ifdef __OpenBSD__
100 #define READ_ONLY_SPACE_START   (0x10000000)
101 #define READ_ONLY_SPACE_SIZE    (0x0ffff000)    /* 256MB - 1 page */
102
103 #define STATIC_SPACE_START      (0x28000000)
104 #define STATIC_SPACE_SIZE       (0x0ffff000)    /* 256MB - 1 page */
105
106 #define BINDING_STACK_START     (0x38000000)
107 #define BINDING_STACK_SIZE      (0x07fff000)    /* 128MB - 1 page */
108
109 #define CONTROL_STACK_START     (0x40000000)
110 #define CONTROL_STACK_SIZE      (0x07fd8000)    /* 128MB - SIGSTKSZ */
111
112 #define SIGNAL_STACK_START      (0x47fd8000)
113 #define SIGNAL_STACK_SIZE       SIGSTKSZ
114
115 #define DYNAMIC_0_SPACE_START   (0x48000000)
116 #ifdef GENCGC
117 #define DYNAMIC_SPACE_SIZE      (0x68000000)    /* 1.625GB */
118 #else
119 #define DYNAMIC_SPACE_SIZE      (0x04000000)    /* 64MB */
120 #endif
121 #define DEFAULT_DYNAMIC_SPACE_SIZE      (0x20000000)    /* 512MB */
122 #endif
123
124 #if defined(__NetBSD__) || defined(DARWIN)
125 #define READ_ONLY_SPACE_START   (SpaceStart_TargetReadOnly)
126 #define READ_ONLY_SPACE_SIZE    (0x0ffff000)    /* 256MB - 1 page */
127
128 #define STATIC_SPACE_START      (SpaceStart_TargetStatic)
129 #define STATIC_SPACE_SIZE       (0x0ffff000)    /* 256MB - 1 page */
130
131 #define BINDING_STACK_START     (0x38000000)
132 #define BINDING_STACK_SIZE      (0x07fff000)    /* 128MB - 1 page */
133
134 #define CONTROL_STACK_START     (0x40000000)
135 #if defined(DARWIN)
136 /*
137  * According to /usr/include/sys/signal.h, MINSIGSTKSZ is 32K and
138  * SIGSTKSZ is 128K.  We should account for that appropriately.
139  */
140 #define CONTROL_STACK_SIZE      (0x07fdf000)    /* 128MB - SIGSTKSZ - 1 page */
141
142 #define SIGNAL_STACK_START      (0x47fe0000)    /* One page past the end of the control stack */
143 #define SIGNAL_STACK_SIZE       SIGSTKSZ
144 #else
145 #define CONTROL_STACK_SIZE      (0x07fd8000)    /* 128MB - SIGSTKSZ */
146
147 #define SIGNAL_STACK_START      (0x47fd8000)
148 #define SIGNAL_STACK_SIZE       SIGSTKSZ
149 #endif
150
151 #define DYNAMIC_0_SPACE_START   (SpaceStart_TargetDynamic)
152 #ifdef GENCGC
153 #if defined(DARWIN)
154 /*
155  * On Darwin, /usr/lib/dyld appears to always be loaded at address
156  * #x8fe2e000.  Hence, the maximum dynamic space size is 1206050816
157  * bytes, or just over 1.150 GB.  Set the limit to 1.150 GB.
158  */
159 #define DYNAMIC_SPACE_SIZE      (0x47E00000U)   /* 1.150GB */
160 #else
161 #define DYNAMIC_SPACE_SIZE      (0x67800000U)   /* 1.656GB */
162 #endif
163 #else
164 #define DYNAMIC_SPACE_SIZE      (0x04000000U)   /* 64MB */
165 #endif
166 #define DEFAULT_DYNAMIC_SPACE_SIZE      (0x20000000U)   /* 512MB */
167 #ifdef LINKAGE_TABLE
168 #define FOREIGN_LINKAGE_SPACE_START (LinkageSpaceStart)
169 #define FOREIGN_LINKAGE_SPACE_SIZE (0x100000)   /* 1MB */
170 #endif
171 #endif /* __NetBSD__ || DARWIN */
172
173 #ifdef __linux__
174 #define READ_ONLY_SPACE_START   (SpaceStart_TargetReadOnly)
175 #define READ_ONLY_SPACE_SIZE    (0x0ffff000)    /* 256MB - 1 page */
176
177 #define STATIC_SPACE_START      (SpaceStart_TargetStatic)
178 #define STATIC_SPACE_SIZE       (0x0ffff000)    /* 256MB - 1 page */
179
180 #define BINDING_STACK_START     (0x20000000)
181 #define BINDING_STACK_SIZE      (0x07fff000)    /* 128MB - 1 page */
182
183 #define CONTROL_STACK_START     0x38000000
184 #define CONTROL_STACK_SIZE      (0x07fff000 - 8192)
185
186 #define SIGNAL_STACK_START      CONTROL_STACK_END
187 #define SIGNAL_STACK_SIZE       SIGSTKSZ
188
189 #define DYNAMIC_0_SPACE_START   (SpaceStart_TargetDynamic)
190
191 #ifdef GENCGC
192 #define DYNAMIC_SPACE_SIZE      (0x66000000)    /* 1.632GB */
193 #else
194 #define DYNAMIC_SPACE_SIZE      (0x04000000)    /* 64MB */
195 #endif
196 #define DEFAULT_DYNAMIC_SPACE_SIZE      (0x20000000)    /* 512MB */
197 #ifdef LINKAGE_TABLE
198 #define FOREIGN_LINKAGE_SPACE_START (LinkageSpaceStart)
199 #define FOREIGN_LINKAGE_SPACE_SIZE (0x100000)   /* 1MB */
200 #endif
201 #endif
202
203 #ifdef SOLARIS
204 /*
205  * The memory map for Solaris/x86 looks roughly like
206  *
207  *      0x08045000->0x08050000   C stack?
208  *      0x08050000->             Code + C heap
209  *      0x10000000->0x20000000   256 MB read-only space
210  *      0x20000000->0x28000000   128M Binding stack growing up.
211  *      0x28000000->0x30000000   256M Static Space.
212  *      0x30000000->0x31000000   16M Foreign linkage table
213  *      0x38000000->0x40000000   128M Control stack growing down.
214  *      0x40000000->0xD0000000   2304M Dynamic Space.
215  *
216  * Starting at 0xd0ce0000 there is some mapped anon memory.  libc
217  * seems to start at 0xd0d40000 and other places.  Looks like memory
218  * above 0xd0ffe000 or so is not mapped.
219  */
220
221 #define READ_ONLY_SPACE_START   (SpaceStart_TargetReadOnly)
222 #define READ_ONLY_SPACE_SIZE    (0x0ffff000)    /* 256MB - 1 page */
223
224 #define STATIC_SPACE_START      (SpaceStart_TargetStatic)
225 #define STATIC_SPACE_SIZE       (0x0ffff000)    /* 256MB - 1 page */
226
227 #define BINDING_STACK_START     (0x20000000)
228 #define BINDING_STACK_SIZE      (0x07fff000)    /* 128MB - 1 page */
229
230 #define CONTROL_STACK_START     0x38000000
231 #define CONTROL_STACK_SIZE      (0x07fff000 - 8192)
232 #define SIGNAL_STACK_START      CONTROL_STACK_END
233 #define SIGNAL_STACK_SIZE       SIGSTKSZ
234
235 #define DYNAMIC_0_SPACE_START   (SpaceStart_TargetDynamic)
236
237 #ifdef GENCGC
238 #define DYNAMIC_SPACE_SIZE      (0x90000000)    /* 2.304GB */
239 #else
240 #define DYNAMIC_SPACE_SIZE      (0x04000000)    /* 64MB */
241 #endif
242 #define DEFAULT_DYNAMIC_SPACE_SIZE      (0x20000000)    /* 512MB */
243 #ifdef LINKAGE_TABLE
244 #define FOREIGN_LINKAGE_SPACE_START (LinkageSpaceStart)
245 #define FOREIGN_LINKAGE_SPACE_SIZE (0x100000)   /* 1MB */
246 #endif
247 #endif
248
249 #define CONTROL_STACK_END       (CONTROL_STACK_START + control_stack_size)
250
251 /* Note that GENCGC only uses dynamic_space 0. */
252 #define DYNAMIC_1_SPACE_START   (DYNAMIC_0_SPACE_START + DYNAMIC_SPACE_SIZE)
253
254 #endif /* _X86_VALIDATE_H_ */