]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/thread.h
xnu-792.17.14.tar.gz
[apple/xnu.git] / osfmk / i386 / thread.h
1 /*
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * @OSF_COPYRIGHT@
30 */
31 /*
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
34 * All Rights Reserved.
35 *
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
41 *
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
45 *
46 * Carnegie Mellon requests users of this software to return to
47 *
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
52 *
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
55 */
56 /*
57 */
58
59 /*
60 * File: machine/thread.h
61 *
62 * This file contains the structure definitions for the thread
63 * state as applied to I386 processors.
64 */
65
66 #ifndef _I386_THREAD_H_
67 #define _I386_THREAD_H_
68
69 #include <mach/boolean.h>
70 #include <mach/i386/vm_types.h>
71 #include <mach/i386/fp_reg.h>
72 #include <mach/thread_status.h>
73
74 #include <kern/lock.h>
75
76 #include <i386/iopb.h>
77 #include <i386/seg.h>
78 #include <i386/tss.h>
79 #include <i386/eflags.h>
80
81 /*
82 * i386_saved_state:
83 *
84 * Has been exported to servers. See: mach/i386/thread_status.h
85 *
86 * This structure corresponds to the state of user registers
87 * as saved upon kernel entry. It lives in the pcb.
88 * It is also pushed onto the stack for exceptions in the kernel.
89 * For performance, it is also used directly in syscall exceptions
90 * if the server has requested i386_THREAD_STATE flavor for the exception
91 * port.
92 *
93 * We define the following as an alias for the "esp" field of the
94 * structure, because we actually save cr2 here, not the kernel esp.
95 */
96 #define cr2 esp
97
98 /*
99 * Save area for user floating-point state.
100 * Allocated only when necessary.
101 */
102
103 struct i386_fpsave_state {
104 boolean_t fp_valid;
105 struct i386_fp_save fp_save_state;
106 struct i386_fp_regs fp_regs;
107 struct i386_fx_save fx_save_state __attribute__ ((aligned (16)));
108 int fp_save_flavor;
109 };
110
111 /*
112 * v86_assist_state:
113 *
114 * This structure provides data to simulate 8086 mode
115 * interrupts. It lives in the pcb.
116 */
117
118 struct v86_assist_state {
119 vm_offset_t int_table;
120 unsigned short int_count;
121 unsigned short flags; /* 8086 flag bits */
122 };
123 #define V86_IF_PENDING 0x8000 /* unused bit */
124
125 /*
126 * i386_interrupt_state:
127 *
128 * This structure describes the set of registers that must
129 * be pushed on the current ring-0 stack by an interrupt before
130 * we can switch to the interrupt stack.
131 */
132
133 struct i386_interrupt_state {
134 int gs;
135 int fs;
136 int es;
137 int ds;
138 int edx;
139 int ecx;
140 int eax;
141 int eip;
142 int cs;
143 int efl;
144 };
145
146 /*
147 * i386_kernel_state:
148 *
149 * This structure corresponds to the state of kernel registers
150 * as saved in a context-switch. It lives at the base of the stack.
151 */
152
153 struct i386_kernel_state {
154 int k_ebx; /* kernel context */
155 int k_esp;
156 int k_ebp;
157 int k_edi;
158 int k_esi;
159 int k_eip;
160 };
161
162 /*
163 * i386_machine_state:
164 *
165 * This structure corresponds to special machine state.
166 * It lives in the pcb. It is not saved by default.
167 */
168
169 struct i386_machine_state {
170 iopb_tss_t io_tss;
171 struct user_ldt * ldt;
172 struct i386_fpsave_state *ifps;
173 struct v86_assist_state v86s;
174 };
175
176 typedef struct pcb {
177 struct i386_interrupt_state iis[2]; /* interrupt and NMI */
178 struct i386_saved_state iss;
179 struct i386_machine_state ims;
180 #ifdef MACH_BSD
181 unsigned long cthread_self; /* for use of cthread package */
182 struct real_descriptor cthread_desc;
183 unsigned long uldt_selector; /* user ldt selector to set */
184 struct real_descriptor uldt_desc; /* the actual user setable ldt data */
185 #endif
186 decl_simple_lock_data(,lock)
187 } *pcb_t;
188
189 /*
190 * Maps state flavor to number of words in the state:
191 */
192 __private_extern__ unsigned int _MachineStateCount[];
193
194 #define USER_REGS(ThrAct) (&(ThrAct)->machine.pcb->iss)
195
196 #define act_machine_state_ptr(ThrAct) (thread_state_t)USER_REGS(ThrAct)
197
198
199 #define is_user_thread(ThrAct) \
200 ((USER_REGS(ThrAct)->efl & EFL_VM) \
201 || ((USER_REGS(ThrAct)->cs & 0x03) != 0))
202
203 #define user_pc(ThrAct) (USER_REGS(ThrAct)->eip)
204 #define user_sp(ThrAct) (USER_REGS(ThrAct)->uesp)
205
206 struct machine_thread {
207 /*
208 * pointer to process control block
209 * (actual storage may as well be here, too)
210 */
211 struct pcb xxx_pcb;
212 pcb_t pcb;
213
214 };
215
216 extern struct i386_saved_state *get_user_regs(thread_t);
217
218 extern void *act_thread_csave(void);
219 extern void act_thread_catt(void *ctx);
220 extern void act_thread_cfree(void *ctx);
221
222 /*
223 * i386_exception_link:
224 *
225 * This structure lives at the high end of the kernel stack.
226 * It points to the current thread`s user registers.
227 */
228 struct i386_exception_link {
229 struct i386_saved_state *saved_state;
230 };
231
232
233 /*
234 * On the kernel stack is:
235 * stack: ...
236 * struct i386_exception_link
237 * struct i386_kernel_state
238 * stack+KERNEL_STACK_SIZE
239 */
240
241 #define STACK_IKS(stack) \
242 ((struct i386_kernel_state *)((stack) + KERNEL_STACK_SIZE) - 1)
243 #define STACK_IEL(stack) \
244 ((struct i386_exception_link *)STACK_IKS(stack) - 1)
245
246 /*
247 * Return address of the function that called current function, given
248 * address of the first parameter of current function.
249 */
250 #define GET_RETURN_PC(addr) (*((vm_offset_t *)addr - 1))
251
252 /*
253 * Defining this indicates that MD code will supply an exception()
254 * routine, conformant with kern/exception.c (dependency alert!)
255 * but which does wonderfully fast, machine-dependent magic.
256 */
257 #define MACHINE_FAST_EXCEPTION 1
258
259 #endif /* _I386_THREAD_H_ */