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