2 * Copyright (c) 2000 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@
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
31 * All Rights Reserved.
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
43 * Carnegie Mellon requests users of this software to return to
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
56 * File: thread_status.h
57 * Author: Avadis Tevanian, Jr.
60 * This file contains the structure definitions for the thread
61 * state as applied to I386 processors.
64 #ifndef _MACH_I386_THREAD_STATUS_H_
65 #define _MACH_I386_THREAD_STATUS_H_
67 #include <mach/i386/fp_reg.h>
68 #include <mach/i386/thread_state.h>
69 #include <architecture/i386/frame.h> /* FIXME */
70 #include <architecture/i386/fpu.h> /* FIXME */
72 * i386_thread_state this is the structure that is exported
73 * to user threads for use in status/mutate
74 * calls. This structure should never
77 * i386_float_state exported to use threads for access to
78 * floating point registers. Try not to
79 * change this one, either.
81 * i386_isa_port_map_state exported to user threads to allow
82 * selective in/out operations
84 * i386_v86_assist_state
86 * thread_syscall_state
89 /* THREAD_STATE_FLAVOR_LIST 0 */
90 #define i386_NEW_THREAD_STATE 1 /* used to be i386_THREAD_STATE */
91 #define i386_FLOAT_STATE 2
92 #define i386_ISA_PORT_MAP_STATE 3
93 #define i386_V86_ASSIST_STATE 4
94 #define i386_REGS_SEGS_STATE 5
95 #define THREAD_SYSCALL_STATE 6
96 #define THREAD_STATE_NONE 7
97 #define i386_SAVED_STATE 8
101 * VALID_THREAD_STATE_FLAVOR is a platform specific macro that when passed
102 * an exception flavor will return if that is a defined flavor for that
103 * platform. The macro must be manually updated to include all of the valid
104 * exception flavors as defined above.
106 #define VALID_THREAD_STATE_FLAVOR(x) \
107 ((x == i386_NEW_THREAD_STATE) || \
108 (x == i386_FLOAT_STATE) || \
109 (x == i386_ISA_PORT_MAP_STATE) || \
110 (x == i386_V86_ASSIST_STATE) || \
111 (x == i386_REGS_SEGS_STATE) || \
112 (x == THREAD_SYSCALL_STATE) || \
113 (x == THREAD_STATE_NONE) || \
114 (x == i386_SAVED_STATE))
117 * This structure is used for both
118 * i386_THREAD_STATE and i386_REGS_SEGS_STATE.
120 struct i386_new_thread_state
{
139 #define i386_NEW_THREAD_STATE_COUNT \
140 (sizeof (struct i386_new_thread_state)/sizeof(unsigned int))
143 * Subset of saved state stored by processor on kernel-to-kernel
144 * trap. (Used by ddb to examine state guaranteed to be present
145 * on all traps into debugger.)
147 struct i386_saved_state_from_kernel
{
155 unsigned int esp
; /* kernel esp stored by pusha -
156 we save cr2 here later */
169 * The format in which thread state is saved by Mach on this machine. This
170 * state flavor is most efficient for exception RPC's to kernel-loaded
171 * servers, because copying can be avoided:
173 struct i386_saved_state
{
181 unsigned int esp
; /* kernel esp stored by pusha -
182 we save cr2 here later */
195 unsigned int v86_es
; /* virtual 8086 segment registers */
200 #define i386_SAVED_ARGV_COUNT 7
201 unsigned int argv_status
; /* Boolean flag indicating whether or
202 * not Mach copied in the args */
203 unsigned int argv
[i386_SAVED_ARGV_COUNT
];
204 /* The return address, and the first several
205 * function call args from the stack, for
206 * efficient syscall exceptions */
208 #define i386_SAVED_STATE_COUNT (sizeof (struct i386_saved_state)/sizeof(unsigned int))
209 #define i386_REGS_SEGS_STATE_COUNT i386_SAVED_STATE_COUNT
212 * Machine-independent way for servers and Mach's exception mechanism to
213 * choose the most efficient state flavor for exception RPC's:
215 #define MACHINE_THREAD_STATE i386_SAVED_STATE
216 #define MACHINE_THREAD_STATE_COUNT i386_SAVED_STATE_COUNT
219 * Largest state on this machine:
220 * (be sure mach/machine/thread_state.h matches!)
222 #define THREAD_MACHINE_STATE_MAX i386_SAVED_STATE_COUNT
225 * Floating point state.
227 * fpkind tells in what way floating point operations are supported.
228 * See the values for fp_kind in <mach/i386/fp_reg.h>.
230 * If the kind is FP_NO, then calls to set the state will fail, and
231 * thread_getstatus will return garbage for the rest of the state.
232 * If "initialized" is false, then the rest of the state is garbage.
233 * Clients can set "initialized" to false to force the coprocessor to
235 * "exc_status" is non-zero if the thread has noticed (but not
236 * proceeded from) a coprocessor exception. It contains the status
237 * word with the exception bits set. The status word in "fp_status"
238 * will have the exception bits turned off. If an exception bit in
239 * "fp_status" is turned on, then "exc_status" should be zero. This
240 * happens when the coprocessor exception is noticed after the system
241 * has context switched to some other thread.
243 * If kind is FP_387, then "state" is a i387_state. Other kinds might
244 * also use i387_state, but somebody will have to verify it (XXX).
245 * Note that the registers are ordered from top-of-stack down, not
246 * according to physical register number.
249 #define FP_STATE_BYTES \
250 (sizeof (struct i386_fp_save) + sizeof (struct i386_fp_regs))
252 struct i386_float_state
{
253 int fpkind
; /* FP_NO..FP_387 (readonly) */
255 unsigned char hw_state
[FP_STATE_BYTES
]; /* actual "hardware" state */
256 int exc_status
; /* exception status (readonly) */
258 #define i386_FLOAT_STATE_COUNT \
259 (sizeof(struct i386_float_state)/sizeof(unsigned int))
262 #define PORT_MAP_BITS 0x400
263 struct i386_isa_port_map_state
{
264 unsigned char pm
[PORT_MAP_BITS
>>3];
267 #define i386_ISA_PORT_MAP_STATE_COUNT \
268 (sizeof(struct i386_isa_port_map_state)/sizeof(unsigned int))
271 * V8086 assist supplies a pointer to an interrupt
272 * descriptor table in task space.
274 struct i386_v86_assist_state
{
275 unsigned int int_table
; /* interrupt table address */
276 int int_count
; /* interrupt table size */
279 struct v86_interrupt_table
{
280 unsigned int count
; /* count of pending interrupts */
281 unsigned short mask
; /* ignore this interrupt if true */
282 unsigned short vec
; /* vector to take */
285 #define i386_V86_ASSIST_STATE_COUNT \
286 (sizeof(struct i386_v86_assist_state)/sizeof(unsigned int))
288 struct thread_syscall_state
{
296 #define i386_THREAD_SYSCALL_STATE_COUNT \
297 (sizeof(struct thread_syscall_state) / sizeof(unsigned int))
300 * Main thread state consists of
301 * general registers, segment registers,
305 #define i386_THREAD_STATE -1
324 } i386_thread_state_t
;
326 #define i386_THREAD_STATE_COUNT \
327 ( sizeof (i386_thread_state_t) / sizeof (int) )
330 * Default segment register values.
333 #define USER_CODE_SELECTOR 0x0017
334 #define USER_DATA_SELECTOR 0x001f
335 #define KERN_CODE_SELECTOR 0x0008
336 #define KERN_DATA_SELECTOR 0x0010
339 * Thread floating point state
340 * includes FPU environment as
341 * well as the register stack.
344 #define i386_THREAD_FPSTATE -2
349 } i386_thread_fpstate_t
;
351 #define i386_THREAD_FPSTATE_COUNT \
352 ( sizeof (i386_thread_fpstate_t) / sizeof (int) )
355 * Extra state that may be
356 * useful to exception handlers.
359 #define i386_THREAD_EXCEPTSTATE -3
364 } i386_thread_exceptstate_t
;
366 #define i386_THREAD_EXCEPTSTATE_COUNT \
367 ( sizeof (i386_thread_exceptstate_t) / sizeof (int) )
370 * Per-thread variable used
371 * to store 'self' id for cthreads.
374 #define i386_THREAD_CTHREADSTATE -4
378 } i386_thread_cthreadstate_t
;
380 #define i386_THREAD_CTHREADSTATE_COUNT \
381 ( sizeof (i386_thread_cthreadstate_t) / sizeof (int) )
383 #endif /* _MACH_I386_THREAD_STATUS_H_ */