1 /* $NetBSD: mcontext.h,v 1.2 2008/04/28 20:23:25 martin 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 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef _IA64_MCONTEXT_H_ 33 #define _IA64_MCONTEXT_H_ 34 35 #include <machine/_regset.h> 36 37 /* 38 * The mc_flags field provides the necessary clues when dealing with the gory 39 * details of ia64 specific contexts. A comprehensive explanation is added for 40 * everybody's sanity, including the author's. 41 * 42 * The first and foremost variation in the context is synchronous contexts 43 * (= synctx) versus asynchronous contexts (= asynctx). A synctx is created 44 * synchronously WRT program execution and has the advantage that none of the 45 * scratch registers have to be saved. They are assumed to be clobbered by the 46 * call to the function that creates the context. An asynctx needs to have the 47 * scratch registers preserved because it can describe any point in a thread's 48 * (or process') execution. 49 * The second variation is for synchronous contexts. When the kernel creates 50 * a synchronous context if needs to preserve the scratch registers, because 51 * the syscall argument and return values are stored there in the trapframe 52 * and they need to be preserved in order to restart a syscall or return the 53 * proper return values. Also, the IIP and CFM fields need to be preserved 54 * as they point to the syscall stub, which the kernel saves as a favor to 55 * userland (it keeps the stubs small and simple). 56 * 57 * Below a description of the flags and their meaning: 58 * 59 * _MC_FLAGS_ASYNC_CONTEXT 60 * If set, indicates that mc_scratch and mc_scratch_fp are both 61 * valid. IFF not set, _MC_FLAGS_SYSCALL_CONTEXT indicates if the 62 * synchronous context is one corresponding to a syscall or not. 63 * Only the kernel is expected to create such a context and it's 64 * probably wise to let the kernel restore it. 65 * _MC_FLAGS_HIGHFP_VALID 66 * If set, indicates that the high FP registers (f32-f127) are 67 * valid. This flag is very likely not going to be set for any 68 * sensible synctx, but is not explicitly disallowed. Any synctx 69 * that has this flag may or may not have the high FP registers 70 * restored. In short: don't do it. 71 * _MC_FLAGS_SYSCALL_CONTEXT 72 * If set (hence _MC_FLAGS_ASYNC_CONTEXT is not set) indicates 73 * that the scratch registers contain syscall arguments and 74 * return values and that additionally IIP and CFM are valid. 75 * Only the kernel is expected to create such a context. It's 76 * probably wise to let the kernel restore it. 77 */ 78 79 typedef struct __mcontext { 80 unsigned long mc_flags; 81 #define _MC_FLAGS_ASYNC_CONTEXT 0x0001 82 #define _MC_FLAGS_HIGHFP_VALID 0x0002 83 #define _MC_FLAGS_KSE_SET_MBOX 0x0004 /* Undocumented. Has to go. */ 84 #define _MC_FLAGS_SYSCALL_CONTEXT 0x0008 85 unsigned long _reserved_; 86 struct _special mc_special; 87 struct _callee_saved mc_preserved; 88 struct _callee_saved_fp mc_preserved_fp; 89 struct _caller_saved mc_scratch; 90 struct _caller_saved_fp mc_scratch_fp; 91 struct _high_fp mc_high_fp; 92 } mcontext_t; 93 94 #ifndef _UC_MACHINE_SP 95 #define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.mc_special.sp) 96 #endif 97 98 #endif /* !_IA64_MCONTEXT_H_ */ 99