Home | History | Annotate | Line # | Download | only in include
mcontext.h revision 1.8.52.1
      1 /*	$NetBSD: mcontext.h,v 1.8.52.1 2008/01/08 22:09:19 bouyer 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  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #ifndef _AMD64_MCONTEXT_H_
     40 #define _AMD64_MCONTEXT_H_
     41 
     42 #include <machine/frame_regs.h>
     43 
     44 /*
     45  * General register state
     46  */
     47 #define GREG_OFFSETS(reg, REG, idx) _REG_##REG = idx,
     48 enum { _FRAME_GREG(GREG_OFFSETS) _NGREG = 26 };
     49 #undef GREG_OFFSETS
     50 
     51 typedef	unsigned long	__greg_t;
     52 typedef	__greg_t	__gregset_t[_NGREG];
     53 
     54 /* These names are for compatibility */
     55 #define	_REG_URSP	_REG_RSP
     56 #define	_REG_RFL	_REG_RFLAGS
     57 
     58 /*
     59  * Floating point register state
     60  */
     61 typedef char __fpregset_t[512];
     62 
     63 /*
     64  * The padding below is to make __fpregs have a 16-byte aligned offset
     65  * within ucontext_t.
     66  */
     67 
     68 typedef struct {
     69 	__gregset_t	__gregs;
     70 	long 		__pad;
     71 	__fpregset_t	__fpregs;
     72 } mcontext_t;
     73 
     74 #define _UC_UCONTEXT_ALIGN	(~0xf)
     75 
     76 #define _UC_MACHINE_SP(uc)	((uc)->uc_mcontext.__gregs[_REG_RSP] - 128)
     77 #define _UC_MACHINE_PC(uc)	((uc)->uc_mcontext.__gregs[_REG_RIP])
     78 #define _UC_MACHINE_INTRV(uc)	((uc)->uc_mcontext.__gregs[_REG_RAX])
     79 
     80 #define	_UC_MACHINE_SET_PC(uc, pc)	_UC_MACHINE_PC(uc) = (pc)
     81 
     82 /*
     83  * mcontext extensions to handle signal delivery.
     84  */
     85 #define _UC_SETSTACK	0x00010000
     86 #define _UC_CLRSTACK	0x00020000
     87 
     88 
     89 #ifdef _KERNEL
     90 
     91 /*
     92  * 32bit context definitions.
     93  */
     94 
     95 #define _NGREG32	19
     96 typedef unsigned int	__greg32_t;
     97 typedef __greg32_t	__gregset32_t[_NGREG32];
     98 
     99 #define _REG32_GS	0
    100 #define _REG32_FS	1
    101 #define _REG32_ES	2
    102 #define _REG32_DS	3
    103 #define _REG32_EDI	4
    104 #define _REG32_ESI	5
    105 #define _REG32_EBP	6
    106 #define _REG32_ESP	7
    107 #define _REG32_EBX	8
    108 #define _REG32_EDX	9
    109 #define _REG32_ECX	10
    110 #define _REG32_EAX	11
    111 #define _REG32_TRAPNO	12
    112 #define _REG32_ERR	13
    113 #define _REG32_EIP	14
    114 #define _REG32_CS	15
    115 #define _REG32_EFL	16
    116 #define _REG32_UESP	17
    117 #define _REG32_SS	18
    118 
    119 #define _UC_MACHINE32_SP(uc)	((uc)->uc_mcontext.__gregs[_REG32_UESP])
    120 
    121 /*
    122  * Floating point register state
    123  */
    124 typedef struct fxsave64 __fpregset32_t;
    125 
    126 typedef struct {
    127 	__gregset32_t	__gregs;
    128 	__fpregset32_t	__fpregs;
    129 } mcontext32_t;
    130 
    131 #define _UC_MACHINE_PAD32	5
    132 
    133 struct trapframe;
    134 struct lwp;
    135 int check_mcontext(struct lwp *, const mcontext_t *, struct trapframe *);
    136 
    137 #endif /* _KERNEL */
    138 
    139 #endif	/* !_AMD64_MCONTEXT_H_ */
    140