]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/thread.h
xnu-792.10.96.tar.gz
[apple/xnu.git] / osfmk / i386 / thread.h
1 /*
2 * Copyright (c) 2000-2006 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 /*
23 * @OSF_COPYRIGHT@
24 */
25 /*
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
28 * All Rights Reserved.
29 *
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
35 *
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
39 *
40 * Carnegie Mellon requests users of this software to return to
41 *
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
46 *
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
49 */
50 /*
51 */
52
53 /*
54 * File: machine/thread.h
55 *
56 * This file contains the structure definitions for the thread
57 * state as applied to I386 processors.
58 */
59
60 #ifndef _I386_THREAD_H_
61 #define _I386_THREAD_H_
62
63 #include <mach/boolean.h>
64 #include <mach/i386/vm_types.h>
65 #include <mach/i386/fp_reg.h>
66 #include <mach/thread_status.h>
67
68 #include <kern/lock.h>
69
70 #include <i386/iopb.h>
71 #include <i386/seg.h>
72 #include <i386/tss.h>
73 #include <i386/eflags.h>
74
75 /*
76 * i386_saved_state:
77 *
78 * Has been exported to servers. See: mach/i386/thread_status.h
79 *
80 * This structure corresponds to the state of user registers
81 * as saved upon kernel entry. It lives in the pcb.
82 * It is also pushed onto the stack for exceptions in the kernel.
83 * For performance, it is also used directly in syscall exceptions
84 * if the server has requested i386_THREAD_STATE flavor for the exception
85 * port.
86 */
87
88 /*
89 * Save area for user floating-point state.
90 * Allocated only when necessary.
91 */
92
93 struct x86_fpsave_state {
94 boolean_t fp_valid;
95 enum {
96 FXSAVE32 = 1,
97 FXSAVE64 = 2
98 } fp_save_layout;
99 struct x86_fx_save fx_save_state __attribute__ ((aligned (16)));
100 };
101
102
103 /*
104 * x86_kernel_state32:
105 *
106 * This structure corresponds to the state of kernel registers
107 * as saved in a context-switch. It lives at the base of the stack.
108 * kernel only runs in 32 bit mode for now
109 */
110
111 struct x86_kernel_state32 {
112 int k_ebx; /* kernel context */
113 int k_esp;
114 int k_ebp;
115 int k_edi;
116 int k_esi;
117 int k_eip;
118 /*
119 * Kernel stacks are 16-byte aligned with a 4-byte i386_exception_link at
120 * the top, followed by an x86_kernel_state32. After both structs have
121 * been pushed, we want to be 16-byte aligned. A dummy int gets us there.
122 */
123 int dummy;
124 };
125
126
127 typedef struct pcb {
128 void *sf;
129 x86_saved_state_t *iss;
130 struct x86_fpsave_state *ifps;
131 #ifdef MACH_BSD
132 uint64_t cthread_self; /* for use of cthread package */
133 struct real_descriptor cthread_desc;
134 unsigned long uldt_selector; /* user ldt selector to set */
135 struct real_descriptor uldt_desc; /* the actual user setable ldt data */
136 #endif
137 decl_simple_lock_data(,lock);
138 uint64_t iss_pte0;
139 uint64_t iss_pte1;
140 void *ids;
141 } *pcb_t;
142
143
144 /*
145 * Maps state flavor to number of words in the state:
146 */
147 __private_extern__ unsigned int _MachineStateCount[];
148
149 #define USER_STATE(ThrAct) ((ThrAct)->machine.pcb->iss)
150 #define USER_REGS32(ThrAct) (saved_state32(USER_STATE(ThrAct)))
151 #define USER_REGS64(ThrAct) (saved_state64(USER_STATE(ThrAct)))
152
153 #define user_pc(ThrAct) (is_saved_state32(USER_STATE(ThrAct)) ? \
154 USER_REGS32(ThrAct)->eip : \
155 USER_REGS64(ThrAct)->isf.rip )
156
157
158 struct machine_thread {
159 /*
160 * pointer to process control block
161 * (actual storage may as well be here, too)
162 */
163 struct pcb xxx_pcb;
164 pcb_t pcb;
165
166 uint32_t specFlags;
167 #define OnProc 0x1
168
169 struct {
170 user_addr_t user_base;
171 } copy_window[NCOPY_WINDOWS];
172 int nxt_window;
173 int copyio_state;
174 #define WINDOWS_DIRTY 0
175 #define WINDOWS_CLEAN 1
176 #define WINDOWS_CLOSED 2
177 #define WINDOWS_OPENED 3
178 uint64_t physwindow_pte;
179 int physwindow_busy;
180 };
181
182
183 extern void *get_user_regs(thread_t);
184
185 extern void *act_thread_csave(void);
186 extern void act_thread_catt(void *ctx);
187 extern void act_thread_cfree(void *ctx);
188
189 /*
190 * i386_exception_link:
191 *
192 * This structure lives at the high end of the kernel stack.
193 * It points to the current thread`s user registers.
194 */
195 struct i386_exception_link {
196 x86_saved_state_t *saved_state;
197 };
198
199
200 /*
201 * On the kernel stack is:
202 * stack: ...
203 * struct i386_exception_link
204 * struct i386_kernel_state
205 * stack+KERNEL_STACK_SIZE
206 */
207
208 #define STACK_IKS(stack) \
209 ((struct x86_kernel_state32 *)((stack) + KERNEL_STACK_SIZE) - 1)
210 #define STACK_IEL(stack) \
211 ((struct i386_exception_link *)STACK_IKS(stack) - 1)
212
213 /*
214 * Return address of the function that called current function, given
215 * address of the first parameter of current function.
216 */
217 #define GET_RETURN_PC(addr) (*((vm_offset_t *)addr - 1))
218
219 /*
220 * Defining this indicates that MD code will supply an exception()
221 * routine, conformant with kern/exception.c (dependency alert!)
222 * but which does wonderfully fast, machine-dependent magic.
223 */
224 #define MACHINE_FAST_EXCEPTION 1
225
226 #endif /* _I386_THREAD_H_ */