]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
6601e61a | 2 | * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved. |
1c79356b | 3 | * |
6601e61a | 4 | * @APPLE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
6601e61a A |
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. | |
8f6c56a5 | 11 | * |
6601e61a A |
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 | |
8f6c56a5 A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
6601e61a A |
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. | |
8f6c56a5 | 19 | * |
6601e61a | 20 | * @APPLE_LICENSE_HEADER_END@ |
1c79356b A |
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> | |
91447636 | 66 | #include <mach/thread_status.h> |
1c79356b A |
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> | |
91447636 A |
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. | |
6601e61a A |
86 | * |
87 | * We define the following as an alias for the "esp" field of the | |
88 | * structure, because we actually save cr2 here, not the kernel esp. | |
91447636 | 89 | */ |
6601e61a | 90 | #define cr2 esp |
91447636 A |
91 | |
92 | /* | |
93 | * Save area for user floating-point state. | |
94 | * Allocated only when necessary. | |
95 | */ | |
96 | ||
6601e61a | 97 | struct i386_fpsave_state { |
91447636 | 98 | boolean_t fp_valid; |
6601e61a A |
99 | struct i386_fp_save fp_save_state; |
100 | struct i386_fp_regs fp_regs; | |
101 | struct i386_fx_save fx_save_state __attribute__ ((aligned (16))); | |
102 | int fp_save_flavor; | |
103 | }; | |
104 | ||
105 | /* | |
106 | * v86_assist_state: | |
107 | * | |
108 | * This structure provides data to simulate 8086 mode | |
109 | * interrupts. It lives in the pcb. | |
110 | */ | |
111 | ||
112 | struct v86_assist_state { | |
113 | vm_offset_t int_table; | |
114 | unsigned short int_count; | |
115 | unsigned short flags; /* 8086 flag bits */ | |
8f6c56a5 | 116 | }; |
6601e61a A |
117 | #define V86_IF_PENDING 0x8000 /* unused bit */ |
118 | ||
119 | /* | |
120 | * i386_interrupt_state: | |
121 | * | |
122 | * This structure describes the set of registers that must | |
123 | * be pushed on the current ring-0 stack by an interrupt before | |
124 | * we can switch to the interrupt stack. | |
125 | */ | |
8f6c56a5 | 126 | |
6601e61a A |
127 | struct i386_interrupt_state { |
128 | int gs; | |
129 | int fs; | |
130 | int es; | |
131 | int ds; | |
132 | int edx; | |
133 | int ecx; | |
134 | int eax; | |
135 | int eip; | |
136 | int cs; | |
137 | int efl; | |
138 | }; | |
8f6c56a5 A |
139 | |
140 | /* | |
6601e61a | 141 | * i386_kernel_state: |
91447636 A |
142 | * |
143 | * This structure corresponds to the state of kernel registers | |
144 | * as saved in a context-switch. It lives at the base of the stack. | |
145 | */ | |
146 | ||
6601e61a | 147 | struct i386_kernel_state { |
91447636 A |
148 | int k_ebx; /* kernel context */ |
149 | int k_esp; | |
150 | int k_ebp; | |
151 | int k_edi; | |
152 | int k_esi; | |
153 | int k_eip; | |
154 | }; | |
155 | ||
6601e61a A |
156 | /* |
157 | * i386_machine_state: | |
158 | * | |
159 | * This structure corresponds to special machine state. | |
160 | * It lives in the pcb. It is not saved by default. | |
161 | */ | |
162 | ||
163 | struct i386_machine_state { | |
164 | iopb_tss_t io_tss; | |
165 | struct user_ldt * ldt; | |
166 | struct i386_fpsave_state *ifps; | |
167 | struct v86_assist_state v86s; | |
168 | }; | |
91447636 A |
169 | |
170 | typedef struct pcb { | |
6601e61a A |
171 | struct i386_interrupt_state iis[2]; /* interrupt and NMI */ |
172 | struct i386_saved_state iss; | |
173 | struct i386_machine_state ims; | |
91447636 | 174 | #ifdef MACH_BSD |
6601e61a | 175 | unsigned long cthread_self; /* for use of cthread package */ |
91447636 | 176 | struct real_descriptor cthread_desc; |
6601e61a A |
177 | unsigned long uldt_selector; /* user ldt selector to set */ |
178 | struct real_descriptor uldt_desc; /* the actual user setable ldt data */ | |
91447636 | 179 | #endif |
6601e61a | 180 | decl_simple_lock_data(,lock) |
91447636 A |
181 | } *pcb_t; |
182 | ||
183 | /* | |
184 | * Maps state flavor to number of words in the state: | |
185 | */ | |
186 | __private_extern__ unsigned int _MachineStateCount[]; | |
187 | ||
6601e61a | 188 | #define USER_REGS(ThrAct) (&(ThrAct)->machine.pcb->iss) |
91447636 | 189 | |
6601e61a | 190 | #define act_machine_state_ptr(ThrAct) (thread_state_t)USER_REGS(ThrAct) |
8ad349bb | 191 | |
8f6c56a5 | 192 | |
6601e61a A |
193 | #define is_user_thread(ThrAct) \ |
194 | ((USER_REGS(ThrAct)->efl & EFL_VM) \ | |
195 | || ((USER_REGS(ThrAct)->cs & 0x03) != 0)) | |
196 | ||
197 | #define user_pc(ThrAct) (USER_REGS(ThrAct)->eip) | |
198 | #define user_sp(ThrAct) (USER_REGS(ThrAct)->uesp) | |
199 | ||
91447636 A |
200 | struct machine_thread { |
201 | /* | |
202 | * pointer to process control block | |
203 | * (actual storage may as well be here, too) | |
204 | */ | |
205 | struct pcb xxx_pcb; | |
206 | pcb_t pcb; | |
207 | ||
208 | }; | |
209 | ||
6601e61a | 210 | extern struct i386_saved_state *get_user_regs(thread_t); |
91447636 A |
211 | |
212 | extern void *act_thread_csave(void); | |
213 | extern void act_thread_catt(void *ctx); | |
214 | extern void act_thread_cfree(void *ctx); | |
1c79356b A |
215 | |
216 | /* | |
217 | * i386_exception_link: | |
218 | * | |
219 | * This structure lives at the high end of the kernel stack. | |
220 | * It points to the current thread`s user registers. | |
221 | */ | |
222 | struct i386_exception_link { | |
6601e61a | 223 | struct i386_saved_state *saved_state; |
1c79356b A |
224 | }; |
225 | ||
226 | ||
227 | /* | |
228 | * On the kernel stack is: | |
229 | * stack: ... | |
230 | * struct i386_exception_link | |
231 | * struct i386_kernel_state | |
232 | * stack+KERNEL_STACK_SIZE | |
233 | */ | |
234 | ||
235 | #define STACK_IKS(stack) \ | |
6601e61a | 236 | ((struct i386_kernel_state *)((stack) + KERNEL_STACK_SIZE) - 1) |
1c79356b A |
237 | #define STACK_IEL(stack) \ |
238 | ((struct i386_exception_link *)STACK_IKS(stack) - 1) | |
239 | ||
1c79356b A |
240 | /* |
241 | * Return address of the function that called current function, given | |
242 | * address of the first parameter of current function. | |
243 | */ | |
244 | #define GET_RETURN_PC(addr) (*((vm_offset_t *)addr - 1)) | |
245 | ||
246 | /* | |
247 | * Defining this indicates that MD code will supply an exception() | |
248 | * routine, conformant with kern/exception.c (dependency alert!) | |
249 | * but which does wonderfully fast, machine-dependent magic. | |
250 | */ | |
251 | #define MACHINE_FAST_EXCEPTION 1 | |
252 | ||
1c79356b | 253 | #endif /* _I386_THREAD_H_ */ |