]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/savearea.h
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
25 #ifndef _PPC_SAVEAREA_H_
26 #define _PPC_SAVEAREA_H_
30 #include <sys/appleapiopts.h>
32 #ifdef __APPLE_API_PRIVATE
34 #ifdef MACH_KERNEL_PRIVATE
35 #include <mach/ppc/vm_types.h>
36 typedef struct savearea_comm
{
39 * The following fields are common to all saveareas and are used to manage individual
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
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.
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 */
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 */
70 unsigned int save_040
[8]; /* Fill 32 bytes */
76 #ifdef BSD_KERNEL_PRIVATE
77 typedef struct savearea_comm
{
78 unsigned int save_000
[24];
82 #if defined(MACH_KERNEL_PRIVATE) || defined(BSD_KERNEL_PRIVATE)
84 * This type of savearea contains all of the general context.
87 typedef struct savearea
{
89 savearea_comm save_hdr
; /* Stuff common to all saveareas */
91 unsigned int save_060
[8]; /* Fill 32 bytes */
100 unsigned int save_r7
;
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
;
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
;
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
;
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
;
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
;
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
;
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
;
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];
185 * This type of savearea contains all of the floating point context.
188 typedef struct savearea_fpu
{
190 savearea_comm save_hdr
; /* Stuff common to all saveareas */
192 unsigned int save_060
[8]; /* Fill 32 bytes */
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];
249 * This type of savearea contains all of the vector context.
252 typedef struct savearea_vec
{
254 savearea_comm save_hdr
; /* Stuff common to all saveareas */
256 unsigned int save_060
[7]; /* Fill 32 bytes */
257 unsigned int save_vrvalid
; /* Valid registers in saved context */
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];
295 #endif /* MACH_KERNEL_PRIVATE || BSD_KERNEL_PRIVATE */
297 #ifdef MACH_KERNEL_PRIVATE
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?
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 */
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 */
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 */
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 */
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 */
352 #endif /* MACH_KERNEL_PRIVATE */
353 #endif /* __APPLE_API_PRIVATE */
355 #endif /* ndef ASSEMBLER */
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 */
368 #endif /* _PPC_SAVEAREA_H_ */