]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/thread.h
xnu-792.6.56.tar.gz
[apple/xnu.git] / osfmk / ppc / thread.h
1 /*
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /*
24 * @OSF_COPYRIGHT@
25 */
26
27 /*
28 * File: machine/thread.h
29 *
30 * This file contains the structure definitions for the thread
31 * state as applied to PPC processors.
32 */
33
34 #ifndef _PPC_THREAD_H_
35 #define _PPC_THREAD_H_
36
37 #include <mach/boolean.h>
38 #include <mach/ppc/vm_types.h>
39 #include <mach/thread_status.h>
40 #include <kern/lock.h>
41 #include <kern/clock.h>
42 #include <ppc/savearea.h>
43
44 /*
45 * Kernel state structure
46 *
47 * This holds the kernel state that is saved and restored across context
48 * switches.
49 */
50
51 /*
52 * PPC process control block
53 *
54 * The PCB holds normal context. It does not contain vector or floating point
55 * registers.
56 *
57 */
58
59 typedef struct savearea pcb;
60 typedef struct savearea *pcb_t;
61
62 struct facility_context {
63
64 savearea_fpu *FPUsave; /* The floating point savearea */
65 savearea *FPUlevel; /* The floating point context level */
66 unsigned int FPUcpu; /* The last processor to enable floating point */
67 unsigned int FPUsync; /* Sync lock */
68 savearea_vec *VMXsave; /* The VMX savearea */
69 savearea *VMXlevel; /* The VMX context level */
70 unsigned int VMXcpu; /* The last processor to enable vector */
71 unsigned int VMXsync; /* Sync lock */
72 struct thread *facAct;
73 };
74
75 typedef struct facility_context facility_context;
76
77 /*
78 * Maps state flavor to number of words in the state:
79 */
80 __private_extern__ unsigned int _MachineStateCount[];
81
82 #define USER_REGS(ThrAct) ((ThrAct)->machine.pcb)
83
84 #define user_pc(ThrAct) ((ThrAct)->machine.pcb->save_srr0)
85
86 #define act_machine_state_ptr(ThrAct) (thread_state_t)USER_REGS(ThrAct)
87
88 struct machine_thread {
89 /*
90 * pointer to process control block control blocks. Potentially
91 * one for each active facility context. They may point to the
92 * same saveareas.
93 */
94 savearea *pcb; /* The "normal" savearea */
95 savearea *upcb; /* The "normal" user savearea */
96 facility_context *curctx; /* Current facility context */
97 facility_context *deferctx; /* Deferred facility context */
98 facility_context facctx; /* "Normal" facility context */
99 struct vmmCntrlEntry *vmmCEntry; /* Pointer current emulation context or 0 */
100 struct vmmCntrlTable *vmmControl; /* Pointer to virtual machine monitor control table */
101 uint64_t qactTimer; /* Time thread needs to interrupt. This is a single-shot timer. Zero is unset */
102 unsigned int umwSpace; /* Address space ID for user memory window */
103 #define umwSwitchAway 0x80000000 /* Context switched away from thread since MapUserAddressWindow */
104 #define umwSwitchAwayb 0
105 addr64_t umwRelo; /* Relocation value for user memory window */
106 unsigned int ksp; /* points to TOP OF STACK or zero */
107 unsigned int preemption_count; /* preemption count */
108 struct per_proc_info *PerProc; /* current per processor data */
109 unsigned int bbDescAddr; /* Points to Blue Box Trap descriptor area in kernel (page aligned) */
110 unsigned int bbUserDA; /* Points to Blue Box Trap descriptor area in user (page aligned) */
111 unsigned int bbTableStart; /* Points to Blue Box Trap dispatch area in user */
112 unsigned int emPendRupts; /* Number of pending emulated interruptions */
113 unsigned int bbTaskID; /* Opaque task ID for Blue Box threads */
114 unsigned int bbTaskEnv; /* Opaque task data reference for Blue Box threads */
115 unsigned int specFlags; /* Special flags */
116 unsigned int pmcovfl[8]; /* PMC overflow count */
117 unsigned int perfmonFlags; /* Perfmon facility flags */
118 unsigned int bbTrap; /* Blue Box trap vector */
119 unsigned int bbSysCall; /* Blue Box syscall vector */
120 unsigned int bbInterrupt; /* Blue Box interrupt vector */
121 unsigned int bbPending; /* Blue Box pending interrupt vector */
122
123 /* special flags bits */
124
125 #define ignoreZeroFaultbit 0
126 #define floatUsedbit 1
127 #define vectorUsedbit 2
128 #define runningVMbit 4
129 #define floatCngbit 5
130 #define vectorCngbit 6
131 #define timerPopbit 7
132 #define userProtKeybit 8
133 #define FamVMenabit 11
134 #define FamVMmodebit 12
135 #define perfMonitorbit 13
136 #define OnProcbit 14
137 /* NOTE: Do not move or assign bit 31 without changing exception vector ultra fast path code */
138 #define bbThreadbit 28
139 #define bbNoMachSCbit 29
140 #define bbPreemptivebit 30
141 #define spfReserved1 31 /* See note above */
142
143 #define ignoreZeroFault 0x80000000 /* (1<<(31-ignoreZeroFaultbit)) */
144 #define floatUsed 0x40000000 /* (1<<(31-floatUsedbit)) */
145 #define vectorUsed 0x20000000 /* (1<<(31-vectorUsedbit)) */
146
147 #define runningVM 0x08000000 /* (1<<(31-runningVMbit)) */
148 #define floatCng 0x04000000 /* (1<<(31-floatCngbit)) */
149 #define vectorCng 0x02000000 /* (1<<(31-vectorCngbit)) */
150 #define timerPop 0x01000000 /* (1<<(31-timerPopbit)) */
151
152 #define userProtKey 0x00800000 /* (1<<(31-userProtKeybit)) */
153
154 #define FamVMena 0x00100000 /* (1<<(31-FamVMenabit)) */
155 #define FamVMmode 0x00080000 /* (1<<(31-FamVMmodebit)) */
156 #define perfMonitor 0x00040000 /* (1<<(31-perfMonitorbit)) */
157 #define OnProc 0x00020000 /* (1<<(31-OnProcbit)) */
158
159 #define bbThread 0x00000008 /* (1<<(31-bbThreadbit)) */
160 #define bbNoMachSC 0x00000004 /* (1<<(31-bbNoMachSCbit)) */
161 #define bbPreemptive 0x00000002 /* (1<<(31-bbPreemptivebit)) */
162
163 #define fvChkb 0
164 #define fvChk 0x80000000
165
166 #ifdef MACH_BSD
167 uint64_t cthread_self; /* for use of cthread package */
168 #endif
169
170 };
171
172 extern struct savearea *find_user_regs(thread_t);
173 extern struct savearea *get_user_regs(thread_t);
174 extern struct savearea_fpu *find_user_fpu(thread_t);
175 extern struct savearea_vec *find_user_vec(thread_t);
176 extern struct savearea_vec *find_user_vec_curr(void);
177 extern int thread_enable_fpe(thread_t act, int onoff);
178
179 extern struct savearea *find_kern_regs(thread_t);
180
181 extern void *act_thread_csave(void);
182 extern void act_thread_catt(void *ctx);
183 extern void act_thread_cfree(void *ctx);
184
185 /*
186 * Return address of the function that called current function, given
187 * address of the first parameter of current function. We can't
188 * do it this way, since parameter was copied from a register
189 * into a local variable. Call an assembly sub-function to
190 * return this.
191 */
192
193 extern vm_offset_t getrpc(void);
194 #define GET_RETURN_PC(addr) getrpc()
195
196 #define STACK_IKS(stack) \
197 ((vm_offset_t)(((vm_offset_t)stack)+KERNEL_STACK_SIZE)-FM_SIZE)
198
199 /*
200 * Defining this indicates that MD code will supply an exception()
201 * routine, conformant with kern/exception.c (dependency alert!)
202 * but which does wonderfully fast, machine-dependent magic.
203 */
204
205 #define MACHINE_FAST_EXCEPTION 1
206
207 #endif /* _PPC_THREAD_H_ */