xref: /netbsd-src/sys/arch/ia64/include/mcontext.h (revision 16543c49052c820334cffc5c69b2afde18f02458)
1*16543c49Schristos /*	$NetBSD: mcontext.h,v 1.16 2024/11/30 01:04:10 christos Exp $	*/
2ba7cbe76Scherry 
3ba7cbe76Scherry /*-
4ba7cbe76Scherry  * Copyright (c) 1999 The NetBSD Foundation, Inc.
5ba7cbe76Scherry  * All rights reserved.
6ba7cbe76Scherry  *
7bea6fe22Sscole  * Copyright (c) 1999, 2003 Marcel Moolenaar
8bea6fe22Sscole  *
9ba7cbe76Scherry  * This code is derived from software contributed to The NetBSD Foundation
10ba7cbe76Scherry  * by Klaus Klein.
11ba7cbe76Scherry  *
12ba7cbe76Scherry  * Redistribution and use in source and binary forms, with or without
13ba7cbe76Scherry  * modification, are permitted provided that the following conditions
14ba7cbe76Scherry  * are met:
15ba7cbe76Scherry  * 1. Redistributions of source code must retain the above copyright
16ba7cbe76Scherry  *    notice, this list of conditions and the following disclaimer.
17ba7cbe76Scherry  * 2. Redistributions in binary form must reproduce the above copyright
18ba7cbe76Scherry  *    notice, this list of conditions and the following disclaimer in the
19ba7cbe76Scherry  *    documentation and/or other materials provided with the distribution.
20bea6fe22Sscole  * 3. The name of the author may not be used to endorse or promote products
21bea6fe22Sscole  *    derived from this software without specific prior written permission.
22ba7cbe76Scherry  *
23ba7cbe76Scherry  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24ba7cbe76Scherry  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25ba7cbe76Scherry  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26ba7cbe76Scherry  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27ba7cbe76Scherry  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28ba7cbe76Scherry  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29ba7cbe76Scherry  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30ba7cbe76Scherry  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31ba7cbe76Scherry  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32ba7cbe76Scherry  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33ba7cbe76Scherry  * POSSIBILITY OF SUCH DAMAGE.
34ba7cbe76Scherry  */
35ba7cbe76Scherry 
36ba7cbe76Scherry #ifndef _IA64_MCONTEXT_H_
37ba7cbe76Scherry #define _IA64_MCONTEXT_H_
38ba7cbe76Scherry 
39ba7cbe76Scherry #include <machine/_regset.h>
40ba7cbe76Scherry 
41bea6fe22Sscole /* XXX fix this, just get to compile for now */
424ab1daa4Sscole #define _NGREG	1
43bea6fe22Sscole 
44bea6fe22Sscole #ifndef __ASSEMBLER__
45bea6fe22Sscole typedef unsigned long __greg_t;
46bea6fe22Sscole typedef __greg_t __gregset_t[_NGREG];
47bea6fe22Sscole 
48bea6fe22Sscole typedef struct {
49bea6fe22Sscole   union _ia64_fpreg __fpregs[_NGREG];
50bea6fe22Sscole } __fpregset_t;
51bea6fe22Sscole 
52bea6fe22Sscole #endif /* __ASSEMBLER__ */
53bea6fe22Sscole 
54ba7cbe76Scherry /*
55ba7cbe76Scherry  * The mc_flags field provides the necessary clues when dealing with the gory
56ba7cbe76Scherry  * details of ia64 specific contexts. A comprehensive explanation is added for
57ba7cbe76Scherry  * everybody's sanity, including the author's.
58ba7cbe76Scherry  *
59ba7cbe76Scherry  * The first and foremost variation in the context is synchronous contexts
60ba7cbe76Scherry  * (= synctx) versus asynchronous contexts (= asynctx). A synctx is created
61ba7cbe76Scherry  * synchronously WRT program execution and has the advantage that none of the
62ba7cbe76Scherry  * scratch registers have to be saved. They are assumed to be clobbered by the
63ba7cbe76Scherry  * call to the function that creates the context. An asynctx needs to have the
64ba7cbe76Scherry  * scratch registers preserved because it can describe any point in a thread's
65ba7cbe76Scherry  * (or process') execution.
66ba7cbe76Scherry  * The second variation is for synchronous contexts. When the kernel creates
67ba7cbe76Scherry  * a synchronous context if needs to preserve the scratch registers, because
68ba7cbe76Scherry  * the syscall argument and return values are stored there in the trapframe
69ba7cbe76Scherry  * and they need to be preserved in order to restart a syscall or return the
70ba7cbe76Scherry  * proper return values. Also, the IIP and CFM fields need to be preserved
71ba7cbe76Scherry  * as they point to the syscall stub, which the kernel saves as a favor to
72ba7cbe76Scherry  * userland (it keeps the stubs small and simple).
73ba7cbe76Scherry  *
74ba7cbe76Scherry  * Below a description of the flags and their meaning:
75ba7cbe76Scherry  *
76ba7cbe76Scherry  *	_MC_FLAGS_ASYNC_CONTEXT
77ba7cbe76Scherry  *		If set, indicates that mc_scratch and mc_scratch_fp are both
78ba7cbe76Scherry  *		valid. IFF not set, _MC_FLAGS_SYSCALL_CONTEXT indicates if the
79ba7cbe76Scherry  *		synchronous context is one corresponding to a syscall or not.
80ba7cbe76Scherry  *		Only the kernel is expected to create such a context and it's
81ba7cbe76Scherry  *		probably wise to let the kernel restore it.
82ba7cbe76Scherry  *	_MC_FLAGS_HIGHFP_VALID
83ba7cbe76Scherry  *		If set, indicates that the high FP registers (f32-f127) are
84ba7cbe76Scherry  *		valid. This flag is very likely not going to be set for any
85ba7cbe76Scherry  *		sensible synctx, but is not explicitly disallowed. Any synctx
86ba7cbe76Scherry  *		that has this flag may or may not have the high FP registers
87ba7cbe76Scherry  *		restored. In short: don't do it.
88ba7cbe76Scherry  *	_MC_FLAGS_SYSCALL_CONTEXT
89ba7cbe76Scherry  *		If set (hence _MC_FLAGS_ASYNC_CONTEXT is not set) indicates
90ba7cbe76Scherry  *		that the scratch registers contain syscall arguments and
91ba7cbe76Scherry  *		return values and that additionally IIP and CFM are valid.
92ba7cbe76Scherry  *		Only the kernel is expected to create such a context. It's
93ba7cbe76Scherry  *		probably wise to let the kernel restore it.
94ba7cbe76Scherry  */
95ba7cbe76Scherry 
96ba7cbe76Scherry typedef struct __mcontext {
97ba7cbe76Scherry 	unsigned long		mc_flags;
98ba7cbe76Scherry #define	_MC_FLAGS_ASYNC_CONTEXT		0x0001
99ba7cbe76Scherry #define	_MC_FLAGS_HIGHFP_VALID		0x0002
100ba7cbe76Scherry #define	_MC_FLAGS_SYSCALL_CONTEXT	0x0008
101ba7cbe76Scherry 	unsigned long		_reserved_;
102ba7cbe76Scherry 	struct _special		mc_special;
103ba7cbe76Scherry 	struct _callee_saved	mc_preserved;
104ba7cbe76Scherry 	struct _callee_saved_fp	mc_preserved_fp;
105ba7cbe76Scherry 	struct _caller_saved	mc_scratch;
106ba7cbe76Scherry 	struct _caller_saved_fp	mc_scratch_fp;
107ba7cbe76Scherry 	struct _high_fp		mc_high_fp;
108bea6fe22Sscole 
109bea6fe22Sscole 	/* XXX fix */
110bea6fe22Sscole 	__gregset_t		__gregs;
111bea6fe22Sscole 	__fpregset_t		__fpregs;
112ba7cbe76Scherry } mcontext_t;
113ba7cbe76Scherry 
114098fbe09Sscole #define _UC_MACHINE_SP(uc)	((uc)->uc_mcontext.mc_special.sp)  /* gregs[12] */
11530eabea3Skamil #define _UC_MACHINE_FP(uc)	0 /* Not supported in target */
116bea6fe22Sscole #define	_UC_MACHINE_PC(uc)	((uc)->uc_mcontext.mc_special.iip)
117f55b16a2Sscole #define	_UC_MACHINE_INTRV(uc)	((uc)->uc_mcontext.mc_scratch.gr8) /* gregs[8] */
11830eabea3Skamil #define _UC_MACHINE_SET_PC(uc, pc)	(uc)->uc_mcontext.mc_special.iip = (pc)
119ba7cbe76Scherry 
12043bbf82aSchristos #define	_UC_TLSBASE	_UC_MD_BIT16
12143bbf82aSchristos #define	_UC_SETSTACK	_UC_MD_BIT17
12243bbf82aSchristos #define	_UC_CLRSTACK	_UC_MD_BIT18
12343bbf82aSchristos 
124ba7cbe76Scherry #endif	/* !_IA64_MCONTEXT_H_ */
125