xref: /netbsd-src/sys/arch/i386/include/mcontext.h (revision aaf4ece63a859a04e37cf3a7229b5fab0157cc06)
1 /*	$NetBSD: mcontext.h,v 1.6 2003/10/08 22:43:01 thorpej Exp $	*/
2 
3 /*-
4  * Copyright (c) 1999 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Klaus Klein.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #ifndef _I386_MCONTEXT_H_
40 #define _I386_MCONTEXT_H_
41 
42 
43 /*
44  * mcontext extensions to handle signal delivery.
45  */
46 #define _UC_SETSTACK	0x00010000
47 #define _UC_CLRSTACK	0x00020000
48 #define _UC_VM		0x00040000
49 
50 /*
51  * Layout of mcontext_t according to the System V Application Binary Interface,
52  * Intel386(tm) Architecture Processor Supplement, Fourth Edition.
53  */
54 
55 /*
56  * General register state
57  */
58 #define _NGREG		19
59 typedef	int		__greg_t;
60 typedef	__greg_t	__gregset_t[_NGREG];
61 
62 #define _REG_GS		0
63 #define _REG_FS		1
64 #define _REG_ES		2
65 #define _REG_DS		3
66 #define _REG_EDI	4
67 #define _REG_ESI	5
68 #define _REG_EBP	6
69 #define _REG_ESP	7
70 #define _REG_EBX	8
71 #define _REG_EDX	9
72 #define _REG_ECX	10
73 #define _REG_EAX	11
74 #define _REG_TRAPNO	12
75 #define _REG_ERR	13
76 #define _REG_EIP	14
77 #define _REG_CS		15
78 #define _REG_EFL	16
79 #define _REG_UESP	17
80 #define _REG_SS		18
81 
82 /*
83  * Floating point register state
84  */
85 typedef struct {
86 	union {
87 		struct {
88 			int	__fp_state[27];	/* Environment and registers */
89 			int	__fp_status;	/* Software status word */
90 		} __fpchip_state;
91 		struct {
92 			char	__fp_emul[246];
93 			char	__fp_epad[2];
94 		} __fp_emul_space;
95 		struct {
96 			char	__fp_xmm[512];
97 		} __fp_xmm_state;
98 		int	__fp_fpregs[128];
99 	} __fp_reg_set;
100 	long	__fp_wregs[33];			/* Weitek? */
101 } __fpregset_t;
102 
103 typedef struct {
104 	__gregset_t	__gregs;
105 	__fpregset_t	__fpregs;
106 } mcontext_t;
107 
108 #define _UC_FXSAVE	0x20	/* FP state is in FXSAVE format in XMM space */
109 
110 #define _UC_MACHINE_PAD	5	/* Padding appended to ucontext_t */
111 
112 #define _UC_UCONTEXT_ALIGN	(~0xf)
113 
114 #ifdef _KERNEL_OPT
115 #include "opt_vm86.h"
116 #ifdef VM86
117 /*#include <machine/psl.h>*/
118 #define PSL_VM 0x00020000
119 #define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_UESP] + \
120 	((uc)->uc_mcontext.__gregs[_REG_EFL] & PSL_VM ? \
121 	 ((uc)->uc_mcontext.__gregs[_REG_SS] << 4) : 0))
122 #endif /* VM86 */
123 #endif /* _KERNEL_OPT */
124 
125 #ifndef _UC_MACHINE_SP
126 #define _UC_MACHINE_SP(uc)	((uc)->uc_mcontext.__gregs[_REG_UESP])
127 #endif
128 #define _UC_MACHINE_PC(uc)	((uc)->uc_mcontext.__gregs[_REG_EIP])
129 #define _UC_MACHINE_INTRV(uc)	((uc)->uc_mcontext.__gregs[_REG_EAX])
130 
131 #define	_UC_MACHINE_SET_PC(uc, pc)	_UC_MACHINE_PC(uc) = (pc)
132 
133 #endif	/* !_I386_MCONTEXT_H_ */
134