]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/savearea.h
xnu-344.49.tar.gz
[apple/xnu.git] / osfmk / ppc / savearea.h
1 /*
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 #ifndef _PPC_SAVEAREA_H_
26 #define _PPC_SAVEAREA_H_
27
28 #ifndef ASSEMBLER
29
30 #include <sys/appleapiopts.h>
31
32 #ifdef __APPLE_API_PRIVATE
33
34 #ifdef MACH_KERNEL_PRIVATE
35 #include <mach/ppc/vm_types.h>
36 typedef struct savearea_comm {
37
38 /*
39 * The following fields are common to all saveareas and are used to manage individual
40 * contexts.
41 *
42 * Fields that start with "save" are part of the individual saveareas. Those that
43 * start with "sac" pertain to the free pool stuff and are valid only on the first slot
44 * in the page.
45 */
46
47
48 /* Keep the save_prev, sac_next, and sac_prev in these positions, some assemble code depends upon it to
49 * match up with fields in saveanchor.
50 */
51 struct savearea *save_prev; /* The address of the previous (or next) savearea */
52 unsigned int *sac_next; /* Points to next savearea page that has a free slot - real */
53 unsigned int *sac_prev; /* Points to previous savearea page that has a free slot - real */
54 unsigned int save_flags; /* Various flags */
55 unsigned int save_level; /* Context ID */
56 unsigned int save_time[2]; /* Context save time - for debugging or performance */
57 struct thread_activation *save_act; /* Associated activation */
58
59 /* 0x20 */
60
61 unsigned int sac_vrswap; /* XOR mask to swap V to R or vice versa */
62 unsigned int sac_alloc; /* Bitmap of allocated slots */
63 unsigned int sac_flags; /* Various flags */
64 unsigned int save_misc0; /* Various stuff */
65 unsigned int save_misc1; /* Various stuff */
66 unsigned int save_misc2; /* Various stuff */
67 unsigned int save_misc3; /* Various stuff */
68 unsigned int save_misc4; /* Various stuff */
69
70 unsigned int save_040[8]; /* Fill 32 bytes */
71
72 /* offset 0x0060 */
73 } savearea_comm;
74 #endif
75
76 #ifdef BSD_KERNEL_PRIVATE
77 typedef struct savearea_comm {
78 unsigned int save_000[24];
79 } savearea_comm;
80 #endif
81
82 #if defined(MACH_KERNEL_PRIVATE) || defined(BSD_KERNEL_PRIVATE)
83 /*
84 * This type of savearea contains all of the general context.
85 */
86
87 typedef struct savearea {
88
89 savearea_comm save_hdr; /* Stuff common to all saveareas */
90
91 unsigned int save_060[8]; /* Fill 32 bytes */
92 /* offset 0x0080 */
93 unsigned int save_r0;
94 unsigned int save_r1;
95 unsigned int save_r2;
96 unsigned int save_r3;
97 unsigned int save_r4;
98 unsigned int save_r5;
99 unsigned int save_r6;
100 unsigned int save_r7;
101
102 /* offset 0x0A0 */
103 unsigned int save_r8;
104 unsigned int save_r9;
105 unsigned int save_r10;
106 unsigned int save_r11;
107 unsigned int save_r12;
108 unsigned int save_r13;
109 unsigned int save_r14;
110 unsigned int save_r15;
111
112 /* offset 0x0C0 */
113 unsigned int save_r16;
114 unsigned int save_r17;
115 unsigned int save_r18;
116 unsigned int save_r19;
117 unsigned int save_r20;
118 unsigned int save_r21;
119 unsigned int save_r22;
120 unsigned int save_r23;
121
122 /* offset 0x0E0 */
123 unsigned int save_r24;
124 unsigned int save_r25;
125 unsigned int save_r26;
126 unsigned int save_r27;
127 unsigned int save_r28;
128 unsigned int save_r29;
129 unsigned int save_r30;
130 unsigned int save_r31;
131
132 /* offset 0x100 */
133 unsigned int save_srr0;
134 unsigned int save_srr1;
135 unsigned int save_cr;
136 unsigned int save_xer;
137 unsigned int save_lr;
138 unsigned int save_ctr;
139 unsigned int save_dar;
140 unsigned int save_dsisr;
141
142
143 /* offset 0x120 */
144 unsigned int save_vscr[4];
145 unsigned int save_fpscrpad;
146 unsigned int save_fpscr;
147 unsigned int save_exception;
148 unsigned int save_vrsave;
149
150 /* offset 0x140 */
151 unsigned int save_sr0;
152 unsigned int save_sr1;
153 unsigned int save_sr2;
154 unsigned int save_sr3;
155 unsigned int save_sr4;
156 unsigned int save_sr5;
157 unsigned int save_sr6;
158 unsigned int save_sr7;
159
160 /* offset 0x160 */
161 unsigned int save_sr8;
162 unsigned int save_sr9;
163 unsigned int save_sr10;
164 unsigned int save_sr11;
165 unsigned int save_sr12;
166 unsigned int save_sr13;
167 unsigned int save_sr14;
168 unsigned int save_sr15;
169
170 /* offset 0x180 */
171 unsigned int save_180[8];
172 unsigned int save_1A0[8];
173 unsigned int save_1C0[8];
174 unsigned int save_1E0[8];
175 unsigned int save_200[8];
176 unsigned int save_220[8];
177 unsigned int save_240[8];
178 unsigned int save_260[8];
179
180 /* offset 0x280 */
181 } savearea;
182
183
184 /*
185 * This type of savearea contains all of the floating point context.
186 */
187
188 typedef struct savearea_fpu {
189
190 savearea_comm save_hdr; /* Stuff common to all saveareas */
191
192 unsigned int save_060[8]; /* Fill 32 bytes */
193 /* offset 0x0080 */
194 double save_fp0;
195 double save_fp1;
196 double save_fp2;
197 double save_fp3;
198
199 double save_fp4;
200 double save_fp5;
201 double save_fp6;
202 double save_fp7;
203
204 double save_fp8;
205 double save_fp9;
206 double save_fp10;
207 double save_fp11;
208
209 double save_fp12;
210 double save_fp13;
211 double save_fp14;
212 double save_fp15;
213
214 double save_fp16;
215 double save_fp17;
216 double save_fp18;
217 double save_fp19;
218
219 double save_fp20;
220 double save_fp21;
221 double save_fp22;
222 double save_fp23;
223
224 double save_fp24;
225 double save_fp25;
226 double save_fp26;
227 double save_fp27;
228
229 double save_fp28;
230 double save_fp29;
231 double save_fp30;
232 double save_fp31;
233 /* offset 0x180 */
234 unsigned int save_180[8];
235 unsigned int save_1A0[8];
236 unsigned int save_1C0[8];
237 unsigned int save_1E0[8];
238 unsigned int save_200[8];
239 unsigned int save_220[8];
240 unsigned int save_240[8];
241 unsigned int save_260[8];
242
243 /* offset 0x280 */
244 } savearea_fpu;
245
246
247
248 /*
249 * This type of savearea contains all of the vector context.
250 */
251
252 typedef struct savearea_vec {
253
254 savearea_comm save_hdr; /* Stuff common to all saveareas */
255
256 unsigned int save_060[7]; /* Fill 32 bytes */
257 unsigned int save_vrvalid; /* Valid registers in saved context */
258
259 /* offset 0x0080 */
260 unsigned int save_vr0[4];
261 unsigned int save_vr1[4];
262 unsigned int save_vr2[4];
263 unsigned int save_vr3[4];
264 unsigned int save_vr4[4];
265 unsigned int save_vr5[4];
266 unsigned int save_vr6[4];
267 unsigned int save_vr7[4];
268 unsigned int save_vr8[4];
269 unsigned int save_vr9[4];
270 unsigned int save_vr10[4];
271 unsigned int save_vr11[4];
272 unsigned int save_vr12[4];
273 unsigned int save_vr13[4];
274 unsigned int save_vr14[4];
275 unsigned int save_vr15[4];
276 unsigned int save_vr16[4];
277 unsigned int save_vr17[4];
278 unsigned int save_vr18[4];
279 unsigned int save_vr19[4];
280 unsigned int save_vr20[4];
281 unsigned int save_vr21[4];
282 unsigned int save_vr22[4];
283 unsigned int save_vr23[4];
284 unsigned int save_vr24[4];
285 unsigned int save_vr25[4];
286 unsigned int save_vr26[4];
287 unsigned int save_vr27[4];
288 unsigned int save_vr28[4];
289 unsigned int save_vr29[4];
290 unsigned int save_vr30[4];
291 unsigned int save_vr31[4];
292
293 /* offset 0x280 */
294 } savearea_vec;
295 #endif /* MACH_KERNEL_PRIVATE || BSD_KERNEL_PRIVATE */
296
297 #ifdef MACH_KERNEL_PRIVATE
298
299 struct Saveanchor {
300
301 /*
302 * Note that this force aligned in aligned_data.s and must be in V=R storage.
303 * Also, all addresses in chains are physical. This structure can only be
304 * updated with translation and interrupts disabled. This is because it is
305 * locked during exception processing and if we were to take a PTE miss while the
306 * lock were held, well, that would be very bad now wouldn't it?
307 */
308
309 unsigned int savelock; /* Lock word for savearea free list manipulation */
310 unsigned int *savepoolfwd; /* Forward anchor for the free pool */
311 unsigned int *savepoolbwd; /* Backward anchor for the free pool */
312 volatile unsigned int savefree; /* Anchor for the global free list */
313 volatile unsigned int savefreecnt; /* Number of saveareas on global free list */
314 volatile int saveadjust; /* If 0 number of saveareas is ok, otherwise number to change (positive means grow, negative means shrink */
315 volatile int saveinuse; /* Number of areas in use counting those on the local free list */
316 volatile int savetarget; /* Number of savearea's needed */
317 int savemaxcount; /* Maximum saveareas ever allocated */
318
319
320 };
321
322
323 #define sac_cnt (4096 / sizeof(savearea)) /* Number of saveareas per page */
324 #define sac_empty (0xFFFFFFFF << (32 - sac_cnt)) /* Mask with all entries empty */
325 #define sac_perm 0x40000000 /* Page permanently assigned */
326 #define sac_permb 1 /* Page permanently assigned - bit position */
327
328 #define LocalSaveTarget (((8 + sac_cnt - 1) / sac_cnt) * sac_cnt) /* Target for size of local savearea free list */
329 #define LocalSaveMin (LocalSaveTarget / 2) /* Min size of local savearea free list before we grow */
330 #define LocalSaveMax (LocalSaveTarget * 2) /* Max size of local savearea free list before we trim */
331
332 #define FreeListMin (2 * LocalSaveTarget * NCPUS) /* Always make sure there are enough to fill local list twice per processor */
333 #define SaveLowHysteresis LocalSaveTarget /* The number off from target before we adjust upwards */
334 #define SaveHighHysteresis FreeListMin /* The number off from target before we adjust downwards */
335 #define InitialSaveAreas (2 * FreeListMin) /* The number of saveareas to make at boot time */
336 #define InitialSaveTarget FreeListMin /* The number of saveareas for an initial target. This should be the minimum ever needed. */
337 #define InitialSaveBloks (InitialSaveAreas + sac_cnt - 1) / sac_cnt /* The number of savearea blocks to allocate at boot */
338
339
340 void save_release(struct savearea *); /* Release a save area */
341 struct savectl *save_dequeue(void); /* Find and dequeue one that is all empty */
342 unsigned int save_queue(struct savearea *); /* Add a new savearea block to the free list */
343 struct savearea *save_get(void); /* Obtains a savearea from the free list (returns virtual address) */
344 struct savearea *save_get_phys(void); /* Obtains a savearea from the free list (returns physical address) */
345 struct savearea *save_alloc(void); /* Obtains a savearea and allocates blocks if needed */
346 struct savearea *save_cpv(struct savearea *); /* Converts a physical savearea address to virtual */
347 void save_ret(struct savearea *); /* Returns a savearea to the free list */
348 void save_ret_phys(struct savearea *); /* Returns a savearea to the free list */
349 void save_adjust(void); /* Adjust size of the global free list */
350 struct savearea_comm *save_trim_freet(void); /* Remove free pages from savearea pool */
351
352 #endif /* MACH_KERNEL_PRIVATE */
353 #endif /* __APPLE_API_PRIVATE */
354
355 #endif /* ndef ASSEMBLER */
356
357 #define SAVattach 0x80000000 /* Savearea has valid context */
358 #define SAVrststk 0x00010000 /* Indicates that the current stack should be reset to empty */
359 #define SAVsyscall 0x00020000 /* Indicates that the savearea is associated with a syscall */
360 #define SAVredrive 0x00040000 /* Indicates that the low-level fault handler associated */
361 #define SAVtype 0x0000FF00 /* Shows type of savearea */
362 #define SAVtypeshft 8 /* Shift to position type */
363 #define SAVempty 0x86 /* Savearea is on free list */
364 #define SAVgeneral 0x01 /* Savearea contains general context */
365 #define SAVfloat 0x02 /* Savearea contains floating point context */
366 #define SAVvector 0x03 /* Savearea contains vector context */
367
368 #endif /* _PPC_SAVEAREA_H_ */