mcontext.h revision 1.3
11.3Smartin/*	$NetBSD: mcontext.h,v 1.3 2012/12/26 19:43:10 martin Exp $	*/
21.1Scherry
31.1Scherry/*-
41.1Scherry * Copyright (c) 1999 The NetBSD Foundation, Inc.
51.1Scherry * All rights reserved.
61.1Scherry *
71.1Scherry * This code is derived from software contributed to The NetBSD Foundation
81.1Scherry * by Klaus Klein.
91.1Scherry *
101.1Scherry * Redistribution and use in source and binary forms, with or without
111.1Scherry * modification, are permitted provided that the following conditions
121.1Scherry * are met:
131.1Scherry * 1. Redistributions of source code must retain the above copyright
141.1Scherry *    notice, this list of conditions and the following disclaimer.
151.1Scherry * 2. Redistributions in binary form must reproduce the above copyright
161.1Scherry *    notice, this list of conditions and the following disclaimer in the
171.1Scherry *    documentation and/or other materials provided with the distribution.
181.1Scherry *
191.1Scherry * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.1Scherry * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.1Scherry * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.1Scherry * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.1Scherry * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.1Scherry * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.1Scherry * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.1Scherry * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.1Scherry * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.1Scherry * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.1Scherry * POSSIBILITY OF SUCH DAMAGE.
301.1Scherry */
311.1Scherry
321.1Scherry#ifndef _IA64_MCONTEXT_H_
331.1Scherry#define _IA64_MCONTEXT_H_
341.1Scherry
351.1Scherry#include <machine/_regset.h>
361.1Scherry
371.1Scherry/*
381.1Scherry * The mc_flags field provides the necessary clues when dealing with the gory
391.1Scherry * details of ia64 specific contexts. A comprehensive explanation is added for
401.1Scherry * everybody's sanity, including the author's.
411.1Scherry *
421.1Scherry * The first and foremost variation in the context is synchronous contexts
431.1Scherry * (= synctx) versus asynchronous contexts (= asynctx). A synctx is created
441.1Scherry * synchronously WRT program execution and has the advantage that none of the
451.1Scherry * scratch registers have to be saved. They are assumed to be clobbered by the
461.1Scherry * call to the function that creates the context. An asynctx needs to have the
471.1Scherry * scratch registers preserved because it can describe any point in a thread's
481.1Scherry * (or process') execution.
491.1Scherry * The second variation is for synchronous contexts. When the kernel creates
501.1Scherry * a synchronous context if needs to preserve the scratch registers, because
511.1Scherry * the syscall argument and return values are stored there in the trapframe
521.1Scherry * and they need to be preserved in order to restart a syscall or return the
531.1Scherry * proper return values. Also, the IIP and CFM fields need to be preserved
541.1Scherry * as they point to the syscall stub, which the kernel saves as a favor to
551.1Scherry * userland (it keeps the stubs small and simple).
561.1Scherry *
571.1Scherry * Below a description of the flags and their meaning:
581.1Scherry *
591.1Scherry *	_MC_FLAGS_ASYNC_CONTEXT
601.1Scherry *		If set, indicates that mc_scratch and mc_scratch_fp are both
611.1Scherry *		valid. IFF not set, _MC_FLAGS_SYSCALL_CONTEXT indicates if the
621.1Scherry *		synchronous context is one corresponding to a syscall or not.
631.1Scherry *		Only the kernel is expected to create such a context and it's
641.1Scherry *		probably wise to let the kernel restore it.
651.1Scherry *	_MC_FLAGS_HIGHFP_VALID
661.1Scherry *		If set, indicates that the high FP registers (f32-f127) are
671.1Scherry *		valid. This flag is very likely not going to be set for any
681.1Scherry *		sensible synctx, but is not explicitly disallowed. Any synctx
691.1Scherry *		that has this flag may or may not have the high FP registers
701.1Scherry *		restored. In short: don't do it.
711.1Scherry *	_MC_FLAGS_SYSCALL_CONTEXT
721.1Scherry *		If set (hence _MC_FLAGS_ASYNC_CONTEXT is not set) indicates
731.1Scherry *		that the scratch registers contain syscall arguments and
741.1Scherry *		return values and that additionally IIP and CFM are valid.
751.1Scherry *		Only the kernel is expected to create such a context. It's
761.1Scherry *		probably wise to let the kernel restore it.
771.1Scherry */
781.1Scherry
791.1Scherrytypedef struct __mcontext {
801.1Scherry	unsigned long		mc_flags;
811.1Scherry#define	_MC_FLAGS_ASYNC_CONTEXT		0x0001
821.1Scherry#define	_MC_FLAGS_HIGHFP_VALID		0x0002
831.1Scherry#define	_MC_FLAGS_KSE_SET_MBOX		0x0004	/* Undocumented. Has to go. */
841.1Scherry#define	_MC_FLAGS_SYSCALL_CONTEXT	0x0008
851.1Scherry	unsigned long		_reserved_;
861.1Scherry	struct _special		mc_special;
871.1Scherry	struct _callee_saved	mc_preserved;
881.1Scherry	struct _callee_saved_fp	mc_preserved_fp;
891.1Scherry	struct _caller_saved	mc_scratch;
901.1Scherry	struct _caller_saved_fp	mc_scratch_fp;
911.1Scherry	struct _high_fp		mc_high_fp;
921.1Scherry} mcontext_t;
931.1Scherry
941.1Scherry#ifndef _UC_MACHINE_SP
951.1Scherry#define _UC_MACHINE_SP(uc)	((uc)->uc_mcontext.mc_special.sp)
961.1Scherry#endif
971.1Scherry
981.3Smartinstatic __inline void *
991.3Smartin__lwp_getprivate_fast(void)
1001.3Smartin{
1011.3Smartin	return (void*)0;
1021.3Smartin}
1031.3Smartin
1041.1Scherry#endif	/* !_IA64_MCONTEXT_H_ */
105