xref: /netbsd-src/sys/arch/amd64/include/mcontext.h (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1 /*	$NetBSD: mcontext.h,v 1.8 2006/03/29 23:07:50 cube 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 _AMD64_MCONTEXT_H_
40 #define _AMD64_MCONTEXT_H_
41 
42 /*
43  * General register state
44  */
45 #define _NGREG		26
46 typedef	unsigned long	__greg_t;
47 typedef	__greg_t	__gregset_t[_NGREG];
48 
49 /*
50  * This is laid out to match trapframe and intrframe (see <machine/frame.h>).
51  * Hence, memcpy between gregs and a trapframe is possible.
52  */
53 #define _REG_RDI	0
54 #define _REG_RSI	1
55 #define _REG_RDX	2
56 #define _REG_RCX	3
57 #define _REG_R8		4
58 #define _REG_R9		5
59 #define _REG_R10	6
60 #define _REG_R11	7
61 #define _REG_R12	8
62 #define _REG_R13	9
63 #define _REG_R14	10
64 #define _REG_R15	11
65 #define _REG_RBP	12
66 #define _REG_RBX	13
67 #define _REG_RAX	14
68 #define _REG_GS		15
69 #define _REG_FS		16
70 #define _REG_ES		17
71 #define _REG_DS		18
72 #define _REG_TRAPNO	19
73 #define _REG_ERR	20
74 #define _REG_RIP	21
75 #define _REG_CS		22
76 #define _REG_RFL	23
77 #define _REG_URSP	24
78 #define _REG_SS		25
79 
80 /*
81  * Floating point register state
82  */
83 typedef char __fpregset_t[512];
84 
85 /*
86  * The padding below is to make __fpregs have a 16-byte aligned offset
87  * within ucontext_t.
88  */
89 
90 typedef struct {
91 	__gregset_t	__gregs;
92 	long 		__pad;
93 	__fpregset_t	__fpregs;
94 } mcontext_t;
95 
96 #define _UC_UCONTEXT_ALIGN	(~0xf)
97 
98 #define _UC_MACHINE_SP(uc)	((uc)->uc_mcontext.__gregs[_REG_URSP] - 128)
99 #define _UC_MACHINE_PC(uc)	((uc)->uc_mcontext.__gregs[_REG_RIP])
100 #define _UC_MACHINE_INTRV(uc)	((uc)->uc_mcontext.__gregs[_REG_RAX])
101 
102 #define	_UC_MACHINE_SET_PC(uc, pc)	_UC_MACHINE_PC(uc) = (pc)
103 
104 /*
105  * mcontext extensions to handle signal delivery.
106  */
107 #define _UC_SETSTACK	0x00010000
108 #define _UC_CLRSTACK	0x00020000
109 
110 
111 #ifdef _KERNEL
112 
113 /*
114  * 32bit context definitions.
115  */
116 
117 #define _NGREG32	19
118 typedef unsigned int	__greg32_t;
119 typedef __greg32_t	__gregset32_t[_NGREG32];
120 
121 #define _REG32_GS	0
122 #define _REG32_FS	1
123 #define _REG32_ES	2
124 #define _REG32_DS	3
125 #define _REG32_EDI	4
126 #define _REG32_ESI	5
127 #define _REG32_EBP	6
128 #define _REG32_ESP	7
129 #define _REG32_EBX	8
130 #define _REG32_EDX	9
131 #define _REG32_ECX	10
132 #define _REG32_EAX	11
133 #define _REG32_TRAPNO	12
134 #define _REG32_ERR	13
135 #define _REG32_EIP	14
136 #define _REG32_CS	15
137 #define _REG32_EFL	16
138 #define _REG32_UESP	17
139 #define _REG32_SS	18
140 
141 #define _UC_MACHINE32_SP(uc)	((uc)->uc_mcontext.__gregs[_REG32_UESP])
142 
143 /*
144  * Floating point register state
145  */
146 typedef struct fxsave64 __fpregset32_t;
147 
148 typedef struct {
149 	__gregset32_t	__gregs;
150 	__fpregset32_t	__fpregs;
151 } mcontext32_t;
152 
153 #define _UC_MACHINE_PAD32	5
154 
155 struct trapframe;
156 struct lwp;
157 int check_mcontext(struct lwp *, const mcontext_t *, struct trapframe *);
158 
159 #endif /* _KERNEL */
160 
161 #endif	/* !_AMD64_MCONTEXT_H_ */
162