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