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