xref: /netbsd-src/sys/arch/i386/include/mcontext.h (revision 16543c49052c820334cffc5c69b2afde18f02458)
1*16543c49Schristos /*	$NetBSD: mcontext.h,v 1.19 2024/11/30 01:04:10 christos Exp $	*/
2a50e3bc1Sthorpej 
3a50e3bc1Sthorpej /*-
4a50e3bc1Sthorpej  * Copyright (c) 1999 The NetBSD Foundation, Inc.
5a50e3bc1Sthorpej  * All rights reserved.
6a50e3bc1Sthorpej  *
7a50e3bc1Sthorpej  * This code is derived from software contributed to The NetBSD Foundation
8a50e3bc1Sthorpej  * by Klaus Klein.
9a50e3bc1Sthorpej  *
10a50e3bc1Sthorpej  * Redistribution and use in source and binary forms, with or without
11a50e3bc1Sthorpej  * modification, are permitted provided that the following conditions
12a50e3bc1Sthorpej  * are met:
13a50e3bc1Sthorpej  * 1. Redistributions of source code must retain the above copyright
14a50e3bc1Sthorpej  *    notice, this list of conditions and the following disclaimer.
15a50e3bc1Sthorpej  * 2. Redistributions in binary form must reproduce the above copyright
16a50e3bc1Sthorpej  *    notice, this list of conditions and the following disclaimer in the
17a50e3bc1Sthorpej  *    documentation and/or other materials provided with the distribution.
18a50e3bc1Sthorpej  *
19a50e3bc1Sthorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20a50e3bc1Sthorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21a50e3bc1Sthorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22a50e3bc1Sthorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23a50e3bc1Sthorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24a50e3bc1Sthorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25a50e3bc1Sthorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26a50e3bc1Sthorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27a50e3bc1Sthorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28a50e3bc1Sthorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29a50e3bc1Sthorpej  * POSSIBILITY OF SUCH DAMAGE.
30a50e3bc1Sthorpej  */
31a50e3bc1Sthorpej 
32a50e3bc1Sthorpej #ifndef _I386_MCONTEXT_H_
33a50e3bc1Sthorpej #define _I386_MCONTEXT_H_
34a50e3bc1Sthorpej 
351dc335c0Schristos 
361dc335c0Schristos /*
371dc335c0Schristos  * mcontext extensions to handle signal delivery.
381dc335c0Schristos  */
391853c81aSthorpej #define	_UC_SETSTACK	_UC_MD_BIT16
401853c81aSthorpej #define	_UC_CLRSTACK	_UC_MD_BIT17
411853c81aSthorpej #define	_UC_VM		_UC_MD_BIT18
421853c81aSthorpej #define	_UC_TLSBASE	_UC_MD_BIT19
431dc335c0Schristos 
44a50e3bc1Sthorpej /*
45a50e3bc1Sthorpej  * Layout of mcontext_t according to the System V Application Binary Interface,
46a50e3bc1Sthorpej  * Intel386(tm) Architecture Processor Supplement, Fourth Edition.
47a50e3bc1Sthorpej  */
48a50e3bc1Sthorpej 
49a50e3bc1Sthorpej /*
50a50e3bc1Sthorpej  * General register state
51a50e3bc1Sthorpej  */
52a50e3bc1Sthorpej #define _NGREG		19
53a50e3bc1Sthorpej typedef	int		__greg_t;
54a50e3bc1Sthorpej typedef	__greg_t	__gregset_t[_NGREG];
55a50e3bc1Sthorpej 
56a50e3bc1Sthorpej #define _REG_GS		0
57a50e3bc1Sthorpej #define _REG_FS		1
58a50e3bc1Sthorpej #define _REG_ES		2
59a50e3bc1Sthorpej #define _REG_DS		3
60a50e3bc1Sthorpej #define _REG_EDI	4
61a50e3bc1Sthorpej #define _REG_ESI	5
62a50e3bc1Sthorpej #define _REG_EBP	6
63a50e3bc1Sthorpej #define _REG_ESP	7
64a50e3bc1Sthorpej #define _REG_EBX	8
65a50e3bc1Sthorpej #define _REG_EDX	9
66a50e3bc1Sthorpej #define _REG_ECX	10
67a50e3bc1Sthorpej #define _REG_EAX	11
68a50e3bc1Sthorpej #define _REG_TRAPNO	12
69a50e3bc1Sthorpej #define _REG_ERR	13
70a50e3bc1Sthorpej #define _REG_EIP	14
71a50e3bc1Sthorpej #define _REG_CS		15
72a50e3bc1Sthorpej #define _REG_EFL	16
73a50e3bc1Sthorpej #define _REG_UESP	17
74a50e3bc1Sthorpej #define _REG_SS		18
75a50e3bc1Sthorpej 
76a50e3bc1Sthorpej /*
77a50e3bc1Sthorpej  * Floating point register state
78a50e3bc1Sthorpej  */
79a50e3bc1Sthorpej typedef struct {
80a50e3bc1Sthorpej 	union {
81a50e3bc1Sthorpej 		struct {
82a50e3bc1Sthorpej 			int	__fp_state[27];	/* Environment and registers */
83f0aa8ebfSdsl 		} __fpchip_state;	/* x87 regs in fsave format */
84a50e3bc1Sthorpej 		struct {
85a50e3bc1Sthorpej 			char	__fp_xmm[512];
86f0aa8ebfSdsl 		} __fp_xmm_state;	/* x87 and xmm regs in fxsave format */
87a50e3bc1Sthorpej 		int	__fp_fpregs[128];
88a50e3bc1Sthorpej 	} __fp_reg_set;
89b5e700c7Sdsl 	int 	__fp_pad[33];			/* Historic padding */
90a50e3bc1Sthorpej } __fpregset_t;
91f0aa8ebfSdsl __CTASSERT(sizeof (__fpregset_t) == 512 + 33 * 4);
92a50e3bc1Sthorpej 
93a50e3bc1Sthorpej typedef struct {
94a50e3bc1Sthorpej 	__gregset_t	__gregs;
95a50e3bc1Sthorpej 	__fpregset_t	__fpregs;
961631a780Sjoerg 	__greg_t	_mc_tlsbase;
97a50e3bc1Sthorpej } mcontext_t;
98a50e3bc1Sthorpej 
991853c81aSthorpej #define _UC_FXSAVE	_UC_MD_BIT5	/* FP state is in FXSAVE format in XMM space */
100a50e3bc1Sthorpej 
1011631a780Sjoerg #define _UC_MACHINE_PAD	4	/* Padding appended to ucontext_t */
102a50e3bc1Sthorpej 
103a50e3bc1Sthorpej #define _UC_UCONTEXT_ALIGN	(~0xf)
104a50e3bc1Sthorpej 
105901da40cSthorpej #ifndef _UC_MACHINE_SP
106a50e3bc1Sthorpej #define _UC_MACHINE_SP(uc)	((uc)->uc_mcontext.__gregs[_REG_UESP])
107a50e3bc1Sthorpej #endif
10884799695Skamil #define _UC_MACHINE_FP(uc)	((uc)->uc_mcontext.__gregs[_REG_EBP])
109901da40cSthorpej #define _UC_MACHINE_PC(uc)	((uc)->uc_mcontext.__gregs[_REG_EIP])
110901da40cSthorpej #define _UC_MACHINE_INTRV(uc)	((uc)->uc_mcontext.__gregs[_REG_EAX])
111901da40cSthorpej 
112901da40cSthorpej #define	_UC_MACHINE_SET_PC(uc, pc)	_UC_MACHINE_PC(uc) = (pc)
113a50e3bc1Sthorpej 
11413d02bb5Sjoerg #define	__UCONTEXT_SIZE	776
11513d02bb5Sjoerg 
116a50e3bc1Sthorpej #endif	/* !_I386_MCONTEXT_H_ */
117