Ticket #12241: thread_status.h

File thread_status.h, 14.0 KB (added by mdickens@…, 17 years ago)

"thread_status.h" i386-64 replacement file from Xcode 2.4.1

Line 
1/*
2 * Copyright (c) 2000-2005 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 *      File:   thread_status.h
54 *      Author: Avadis Tevanian, Jr.
55 *      Date:   1985
56 *
57 *      This file contains the structure definitions for the thread
58 *      state as applied to I386 processors.
59 */
60
61#ifndef _MACH_I386_THREAD_STATUS_H_
62#define _MACH_I386_THREAD_STATUS_H_
63
64#include <mach/message.h>
65#include <mach/i386/fp_reg.h>
66#include <mach/i386/thread_state.h>
67#include <i386/eflags.h>
68
69
70
71/*
72 * the i386_xxxx form is kept for legacy purposes since these types
73 * are externally known... eventually they should be deprecated.
74 * our internal implementation has moved to the following naming convention
75 *
76 *   x86_xxxx32 names are used to deal with 32 bit states
77 *   x86_xxxx64 names are used to deal with 64 bit states
78 *   x86_xxxx   names are used to deal with either 32 or 64 bit states
79 *      via a self-describing mechanism
80 */
81
82
83
84/*
85 * these are the legacy names which should be deprecated in the future
86 * they are externally known which is the only reason we don't just get
87 * rid of them
88 */
89#define i386_THREAD_STATE               1
90#define i386_FLOAT_STATE                2
91#define i386_EXCEPTION_STATE            3
92
93
94/*
95 * THREAD_STATE_FLAVOR_LIST 0
96 *      these are the supported flavors
97 */
98#define x86_THREAD_STATE32              1
99#define x86_FLOAT_STATE32               2
100#define x86_EXCEPTION_STATE32           3
101#define x86_THREAD_STATE64              4
102#define x86_FLOAT_STATE64               5
103#define x86_EXCEPTION_STATE64           6
104#define x86_THREAD_STATE                7
105#define x86_FLOAT_STATE                 8
106#define x86_EXCEPTION_STATE             9
107#define x86_DEBUG_STATE32               10
108#define x86_DEBUG_STATE64               11
109#define x86_DEBUG_STATE                 12
110#define THREAD_STATE_NONE               13
111
112
113
114/*
115 * Largest state on this machine:
116 * (be sure mach/machine/thread_state.h matches!)
117 */
118#define THREAD_MACHINE_STATE_MAX        THREAD_STATE_MAX
119
120
121/*
122 * VALID_THREAD_STATE_FLAVOR is a platform specific macro that when passed
123 * an exception flavor will return if that is a defined flavor for that
124 * platform. The macro must be manually updated to include all of the valid
125 * exception flavors as defined above.
126 */
127#define VALID_THREAD_STATE_FLAVOR(x)       \
128        ((x == x86_THREAD_STATE32)      || \
129         (x == x86_FLOAT_STATE32)       || \
130         (x == x86_EXCEPTION_STATE32)   || \
131         (x == x86_DEBUG_STATE32)       || \
132         (x == x86_THREAD_STATE64)      || \
133         (x == x86_FLOAT_STATE64)       || \
134         (x == x86_EXCEPTION_STATE64)   || \
135         (x == x86_DEBUG_STATE64)       || \
136         (x == x86_THREAD_STATE)        || \
137         (x == x86_FLOAT_STATE)         || \
138         (x == x86_EXCEPTION_STATE)     || \
139         (x == x86_DEBUG_STATE)         || \
140         (x == THREAD_STATE_NONE))
141
142
143
144struct x86_state_hdr {
145    int         flavor;
146    int         count;
147};
148typedef struct x86_state_hdr x86_state_hdr_t;
149
150
151/*
152 * Main thread state consists of
153 * general registers, segment registers,
154 * eip and eflags.
155 */
156
157struct i386_thread_state {
158    unsigned int        eax;
159    unsigned int        ebx;
160    unsigned int        ecx;
161    unsigned int        edx;
162    unsigned int        edi;
163    unsigned int        esi;
164    unsigned int        ebp;
165    unsigned int        esp;
166    unsigned int        ss;
167    unsigned int        eflags;
168    unsigned int        eip;
169    unsigned int        cs;
170    unsigned int        ds;
171    unsigned int        es;
172    unsigned int        fs;
173    unsigned int        gs;
174} ;
175
176/*
177 * to be depecrated in the future
178 */
179typedef struct i386_thread_state i386_thread_state_t;
180#define i386_THREAD_STATE_COUNT ((mach_msg_type_number_t) \
181    ( sizeof (i386_thread_state_t) / sizeof (int) ))
182
183
184typedef struct i386_thread_state x86_thread_state32_t;
185#define x86_THREAD_STATE32_COUNT ((mach_msg_type_number_t) \
186    ( sizeof (x86_thread_state32_t) / sizeof (int) ))
187
188
189
190
191struct x86_thread_state64 {
192    uint64_t            rax;
193    uint64_t            rbx;
194    uint64_t            rcx;
195    uint64_t            rdx;
196    uint64_t            rdi;
197    uint64_t            rsi;
198    uint64_t            rbp;
199    uint64_t            rsp;
200    uint64_t            r8;
201    uint64_t            r9;
202    uint64_t            r10;
203    uint64_t            r11;
204    uint64_t            r12;
205    uint64_t            r13;
206    uint64_t            r14;
207    uint64_t            r15;
208    uint64_t            rip;
209    uint64_t            rflags;
210    uint64_t            cs;
211    uint64_t            fs;
212    uint64_t            gs;
213} ;
214
215
216typedef struct x86_thread_state64 x86_thread_state64_t;
217#define x86_THREAD_STATE64_COUNT        ((mach_msg_type_number_t) \
218    ( sizeof (x86_thread_state64_t) / sizeof (int) ))
219
220
221
222
223struct x86_thread_state {
224    x86_state_hdr_t             tsh;
225    union {
226        x86_thread_state32_t    ts32;
227        x86_thread_state64_t    ts64;
228    } uts;
229} ;
230
231
232typedef struct x86_thread_state x86_thread_state_t;
233#define x86_THREAD_STATE_COUNT  ((mach_msg_type_number_t) \
234    ( sizeof (x86_thread_state_t) / sizeof (int) ))
235
236
237
238/*
239 * Default segment register values.
240 */
241   
242#define USER_CODE_SELECTOR      0x0017
243#define USER_DATA_SELECTOR      0x001f
244#define KERN_CODE_SELECTOR      0x0008
245#define KERN_DATA_SELECTOR      0x0010
246
247typedef struct fp_control {
248    unsigned short              invalid :1,
249                                denorm  :1,
250                                zdiv    :1,
251                                ovrfl   :1,
252                                undfl   :1,
253                                precis  :1,
254                                        :2,
255                                pc      :2,
256#define FP_PREC_24B             0
257#define FP_PREC_53B             2
258#define FP_PREC_64B             3
259                                rc      :2,
260#define FP_RND_NEAR             0
261#define FP_RND_DOWN             1
262#define FP_RND_UP               2
263#define FP_CHOP                 3
264                                /*inf*/ :1,
265                                        :3;
266} fp_control_t;
267/*
268 * Status word.
269 */
270
271typedef struct fp_status {
272    unsigned short              invalid :1,
273                                denorm  :1,
274                                zdiv    :1,
275                                ovrfl   :1,
276                                undfl   :1,
277                                precis  :1,
278                                stkflt  :1,
279                                errsumm :1,
280                                c0      :1,
281                                c1      :1,
282                                c2      :1,
283                                tos     :3,
284                                c3      :1,
285                                busy    :1;
286} fp_status_t;
287                               
288/* defn of 80bit x87 FPU or MMX register  */
289struct mmst_reg {
290        char    mmst_reg[10];
291        char    mmst_rsrv[6];
292};
293
294
295/* defn of 128 bit XMM regs */
296struct xmm_reg {
297        char            xmm_reg[16];
298};
299
300/*
301 * Floating point state.
302 */
303
304#define FP_STATE_BYTES          512     /* number of chars worth of data from fpu_fcw */
305
306/* For legacy reasons we need to leave the hw_state as char bytes */
307struct i386_float_state {
308        int                     fpu_reserved[2];
309        fp_control_t            fpu_fcw;                        /* x87 FPU control word */
310        fp_status_t             fpu_fsw;                        /* x87 FPU status word */
311        uint8_t                 fpu_ftw;                        /* x87 FPU tag word */
312        uint8_t                 fpu_rsrv1;                      /* reserved */ 
313        uint16_t                fpu_fop;                        /* x87 FPU Opcode */
314        uint32_t                fpu_ip;                         /* x87 FPU Instruction Pointer offset */
315        uint16_t                fpu_cs;                         /* x87 FPU Instruction Pointer Selector */
316        uint16_t                fpu_rsrv2;                      /* reserved */
317        uint32_t                fpu_dp;                         /* x87 FPU Instruction Operand(Data) Pointer offset */
318        uint16_t                fpu_ds;                         /* x87 FPU Instruction Operand(Data) Pointer Selector */
319        uint16_t                fpu_rsrv3;                      /* reserved */
320        uint32_t                fpu_mxcsr;                      /* MXCSR Register state */
321        uint32_t                fpu_mxcsrmask;          /* MXCSR mask */
322        struct mmst_reg fpu_stmm0;              /* ST0/MM0   */
323        struct mmst_reg fpu_stmm1;              /* ST1/MM1  */
324        struct mmst_reg fpu_stmm2;              /* ST2/MM2  */
325        struct mmst_reg fpu_stmm3;              /* ST3/MM3  */
326        struct mmst_reg fpu_stmm4;              /* ST4/MM4  */
327        struct mmst_reg fpu_stmm5;              /* ST5/MM5  */
328        struct mmst_reg fpu_stmm6;              /* ST6/MM6  */
329        struct mmst_reg fpu_stmm7;              /* ST7/MM7  */
330        struct xmm_reg  fpu_xmm0;               /* XMM 0  */
331        struct xmm_reg  fpu_xmm1;               /* XMM 1  */
332        struct xmm_reg  fpu_xmm2;               /* XMM 2  */
333        struct xmm_reg  fpu_xmm3;               /* XMM 3  */
334        struct xmm_reg  fpu_xmm4;               /* XMM 4  */
335        struct xmm_reg  fpu_xmm5;               /* XMM 5  */
336        struct xmm_reg  fpu_xmm6;               /* XMM 6  */
337        struct xmm_reg  fpu_xmm7;               /* XMM 7  */
338        char                    fpu_rsrv4[14*16];       /* reserved */
339        int                     fpu_reserved1;
340};
341
342
343/*
344 * to be depecrated in the future
345 */
346typedef struct i386_float_state i386_float_state_t;
347#define i386_FLOAT_STATE_COUNT ((mach_msg_type_number_t) \
348                (sizeof(i386_float_state_t)/sizeof(unsigned int)))
349         
350typedef struct i386_float_state x86_float_state32_t;
351#define x86_FLOAT_STATE32_COUNT ((mach_msg_type_number_t) \
352                (sizeof(x86_float_state32_t)/sizeof(unsigned int)))
353         
354
355struct x86_float_state64 {
356        int                     fpu_reserved[2];
357        fp_control_t            fpu_fcw;                        /* x87 FPU control word */
358        fp_status_t             fpu_fsw;                        /* x87 FPU status word */
359        uint8_t                 fpu_ftw;                        /* x87 FPU tag word */
360        uint8_t                 fpu_rsrv1;                      /* reserved */ 
361        uint16_t                fpu_fop;                        /* x87 FPU Opcode */
362        uint32_t                fpu_ip;                         /* x87 FPU Instruction Pointer offset */
363        uint16_t                fpu_cs;                         /* x87 FPU Instruction Pointer Selector */
364        uint16_t                fpu_rsrv2;                      /* reserved */
365        uint32_t                fpu_dp;                         /* x87 FPU Instruction Operand(Data) Pointer offset */
366        uint16_t                fpu_ds;                         /* x87 FPU Instruction Operand(Data) Pointer Selector */
367        uint16_t                fpu_rsrv3;                      /* reserved */
368        uint32_t                fpu_mxcsr;                      /* MXCSR Register state */
369        uint32_t                fpu_mxcsrmask;          /* MXCSR mask */
370        struct mmst_reg fpu_stmm0;              /* ST0/MM0   */
371        struct mmst_reg fpu_stmm1;              /* ST1/MM1  */
372        struct mmst_reg fpu_stmm2;              /* ST2/MM2  */
373        struct mmst_reg fpu_stmm3;              /* ST3/MM3  */
374        struct mmst_reg fpu_stmm4;              /* ST4/MM4  */
375        struct mmst_reg fpu_stmm5;              /* ST5/MM5  */
376        struct mmst_reg fpu_stmm6;              /* ST6/MM6  */
377        struct mmst_reg fpu_stmm7;              /* ST7/MM7  */
378        struct xmm_reg  fpu_xmm0;               /* XMM 0  */
379        struct xmm_reg  fpu_xmm1;               /* XMM 1  */
380        struct xmm_reg  fpu_xmm2;               /* XMM 2  */
381        struct xmm_reg  fpu_xmm3;               /* XMM 3  */
382        struct xmm_reg  fpu_xmm4;               /* XMM 4  */
383        struct xmm_reg  fpu_xmm5;               /* XMM 5  */
384        struct xmm_reg  fpu_xmm6;               /* XMM 6  */
385        struct xmm_reg  fpu_xmm7;               /* XMM 7  */
386        struct xmm_reg  fpu_xmm8;               /* XMM 8  */
387        struct xmm_reg  fpu_xmm9;               /* XMM 9  */
388        struct xmm_reg  fpu_xmm10;              /* XMM 10  */
389        struct xmm_reg  fpu_xmm11;              /* XMM 11 */
390        struct xmm_reg  fpu_xmm12;              /* XMM 12  */
391        struct xmm_reg  fpu_xmm13;              /* XMM 13  */
392        struct xmm_reg  fpu_xmm14;              /* XMM 14  */
393        struct xmm_reg  fpu_xmm15;              /* XMM 15  */
394        char                    fpu_rsrv4[6*16];        /* reserved */
395        int                     fpu_reserved1;
396};
397
398typedef struct x86_float_state64 x86_float_state64_t;
399#define x86_FLOAT_STATE64_COUNT ((mach_msg_type_number_t) \
400                (sizeof(x86_float_state64_t)/sizeof(unsigned int)))
401               
402         
403
404
405struct x86_float_state {
406    x86_state_hdr_t             fsh;
407    union {
408        x86_float_state32_t     fs32;
409        x86_float_state64_t     fs64;
410    } ufs;
411} ;
412
413
414typedef struct x86_float_state x86_float_state_t;
415#define x86_FLOAT_STATE_COUNT   ((mach_msg_type_number_t) \
416    ( sizeof (x86_float_state_t) / sizeof (int) ))
417
418
419
420/*
421 * Extra state that may be
422 * useful to exception handlers.
423 */
424
425struct i386_exception_state {
426    unsigned int        trapno;
427    unsigned int        err;
428    unsigned int        faultvaddr;
429};
430
431/*
432 * to be depecrated in the future
433 */
434typedef struct i386_exception_state i386_exception_state_t;
435#define i386_EXCEPTION_STATE_COUNT      ((mach_msg_type_number_t) \
436    ( sizeof (i386_exception_state_t) / sizeof (int) ))
437
438#define I386_EXCEPTION_STATE_COUNT i386_EXCEPTION_STATE_COUNT
439
440typedef struct i386_exception_state x86_exception_state32_t;
441#define x86_EXCEPTION_STATE32_COUNT     ((mach_msg_type_number_t) \
442    ( sizeof (x86_exception_state32_t) / sizeof (int) ))
443
444struct x86_debug_state32 {
445        unsigned int dr0;
446        unsigned int dr1;
447        unsigned int dr2;
448        unsigned int dr3;
449        unsigned int dr4;
450        unsigned int dr5;
451        unsigned int dr6;
452        unsigned int dr7;
453};
454
455typedef struct x86_debug_state32 x86_debug_state32_t;
456#define x86_DEBUG_STATE32_COUNT       ((mach_msg_type_number_t) \
457        ( sizeof (x86_debug_state32_t) / sizeof (int) ))
458#define X86_DEBUG_STATE32_COUNT x86_DEBUG_STATE32_COUNT
459
460
461struct x86_exception_state64 {
462    unsigned int        trapno;
463    unsigned int        err;
464    uint64_t            faultvaddr;
465};
466
467typedef struct x86_exception_state64 x86_exception_state64_t;
468#define x86_EXCEPTION_STATE64_COUNT     ((mach_msg_type_number_t) \
469    ( sizeof (x86_exception_state64_t) / sizeof (int) ))
470
471
472struct x86_debug_state64 {
473        uint64_t dr0;
474        uint64_t dr1;
475        uint64_t dr2;
476        uint64_t dr3;
477        uint64_t dr4;
478        uint64_t dr5;
479        uint64_t dr6;
480        uint64_t dr7;
481};
482
483
484typedef struct x86_debug_state64 x86_debug_state64_t;
485#define x86_DEBUG_STATE64_COUNT ((mach_msg_type_number_t) \
486    ( sizeof (x86_debug_state64_t) / sizeof (int) ))
487
488#define X86_DEBUG_STATE64_COUNT x86_DEBUG_STATE64_COUNT
489
490
491
492struct x86_exception_state {
493    x86_state_hdr_t             esh;
494    union {
495        x86_exception_state32_t es32;
496        x86_exception_state64_t es64;
497    } ues;
498} ;
499
500
501typedef struct x86_exception_state x86_exception_state_t;
502#define x86_EXCEPTION_STATE_COUNT       ((mach_msg_type_number_t) \
503    ( sizeof (x86_exception_state_t) / sizeof (int) ))
504
505struct x86_debug_state {
506        x86_state_hdr_t                 dsh;
507        union {
508                x86_debug_state32_t     ds32;
509                x86_debug_state64_t     ds64;
510        } uds;
511};
512
513
514
515typedef struct x86_debug_state x86_debug_state_t;
516#define x86_DEBUG_STATE_COUNT ((mach_msg_type_number_t) \
517                (sizeof(x86_debug_state_t)/sizeof(unsigned int)))
518
519/*
520 * Machine-independent way for servers and Mach's exception mechanism to
521 * choose the most efficient state flavor for exception RPC's:
522 */
523#define MACHINE_THREAD_STATE            x86_THREAD_STATE
524#define MACHINE_THREAD_STATE_COUNT      x86_THREAD_STATE_COUNT
525
526
527
528#endif  /* _MACH_I386_THREAD_STATUS_H_ */