Home | History | Annotate | Line # | Download | only in include
mcontext.h revision 1.5
      1  1.5       pk /*	$NetBSD: mcontext.h,v 1.5 2004/01/01 15:02:31 pk Exp $	*/
      2  1.2  thorpej 
      3  1.2  thorpej /*-
      4  1.2  thorpej  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5  1.2  thorpej  * All rights reserved.
      6  1.2  thorpej  *
      7  1.2  thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.2  thorpej  * by Klaus Klein.
      9  1.2  thorpej  *
     10  1.2  thorpej  * Redistribution and use in source and binary forms, with or without
     11  1.2  thorpej  * modification, are permitted provided that the following conditions
     12  1.2  thorpej  * are met:
     13  1.2  thorpej  * 1. Redistributions of source code must retain the above copyright
     14  1.2  thorpej  *    notice, this list of conditions and the following disclaimer.
     15  1.2  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.2  thorpej  *    notice, this list of conditions and the following disclaimer in the
     17  1.2  thorpej  *    documentation and/or other materials provided with the distribution.
     18  1.2  thorpej  * 3. All advertising materials mentioning features or use of this software
     19  1.2  thorpej  *    must display the following acknowledgement:
     20  1.2  thorpej  *        This product includes software developed by the NetBSD
     21  1.2  thorpej  *        Foundation, Inc. and its contributors.
     22  1.2  thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.2  thorpej  *    contributors may be used to endorse or promote products derived
     24  1.2  thorpej  *    from this software without specific prior written permission.
     25  1.2  thorpej  *
     26  1.2  thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.2  thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.2  thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.2  thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.2  thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.2  thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.2  thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.2  thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.2  thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.2  thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.2  thorpej  * POSSIBILITY OF SUCH DAMAGE.
     37  1.2  thorpej  */
     38  1.2  thorpej 
     39  1.2  thorpej #ifndef _SPARC_MCONTEXT_H_
     40  1.2  thorpej #define _SPARC_MCONTEXT_H_
     41  1.2  thorpej 
     42  1.5       pk #define _UC_SETSTACK	0x00010000
     43  1.5       pk #define _UC_CLRSTACK	0x00020000
     44  1.5       pk 
     45  1.2  thorpej /*
     46  1.2  thorpej  * Layout of mcontext_t according the System V Application Binary Interface,
     47  1.2  thorpej  * Edition 4.1, SPARC Processor ABI Supplement and updated for SPARC v9.
     48  1.2  thorpej  */
     49  1.2  thorpej 
     50  1.2  thorpej #ifdef __arch64__
     51  1.2  thorpej #define	_NGREG	21	/* %ccr, pc, npc, %g1-7, %o0-7, %asi, %fprs */
     52  1.2  thorpej #else
     53  1.2  thorpej #define	_NGREG	19	/* %psr, pc, npc, %g1-7, %o0-7 */
     54  1.2  thorpej #endif
     55  1.2  thorpej typedef	long int	__greg_t;
     56  1.2  thorpej typedef	__greg_t	__gregset_t[_NGREG];
     57  1.2  thorpej 
     58  1.2  thorpej /* Offsets into gregset_t, for convenience. */
     59  1.2  thorpej #ifdef __arch64__
     60  1.2  thorpej #define	_REG_CCR	0
     61  1.2  thorpej #else
     62  1.2  thorpej #define	_REG_PSR	0
     63  1.2  thorpej #endif
     64  1.2  thorpej #define	_REG_PC		1
     65  1.2  thorpej #define	_REG_nPC	2
     66  1.2  thorpej #define	_REG_Y		3
     67  1.2  thorpej #define	_REG_G1		4
     68  1.2  thorpej #define	_REG_G2		5
     69  1.2  thorpej #define	_REG_G3		6
     70  1.2  thorpej #define	_REG_G4		7
     71  1.2  thorpej #define	_REG_G5		8
     72  1.2  thorpej #define	_REG_G6		9
     73  1.2  thorpej #define	_REG_G7		10
     74  1.2  thorpej #define	_REG_O0		11
     75  1.2  thorpej #define	_REG_O1		12
     76  1.2  thorpej #define	_REG_O2		13
     77  1.2  thorpej #define	_REG_O3		14
     78  1.2  thorpej #define	_REG_O4		15
     79  1.2  thorpej #define	_REG_O5		16
     80  1.2  thorpej #define	_REG_O6		17
     81  1.2  thorpej #define	_REG_O7		18
     82  1.2  thorpej #ifdef __arch64__
     83  1.2  thorpej #define	_REG_ASI	19
     84  1.2  thorpej #define	_REG_FPRS	20
     85  1.2  thorpej #endif
     86  1.2  thorpej 
     87  1.2  thorpej 
     88  1.2  thorpej #define	_SPARC_MAXREGWINDOW	31
     89  1.2  thorpej 
     90  1.2  thorpej /* Layout of a register window. */
     91  1.2  thorpej typedef struct {
     92  1.2  thorpej 	__greg_t	__rw_local[8];	/* %l0-7 */
     93  1.2  thorpej 	__greg_t	__rw_in[8];	/* %i0-7 */
     94  1.2  thorpej } __rwindow_t;
     95  1.2  thorpej 
     96  1.2  thorpej /* Description of available register windows. */
     97  1.2  thorpej typedef struct {
     98  1.2  thorpej 	int		__wbcnt;
     99  1.2  thorpej 	__greg_t *	__spbuf[_SPARC_MAXREGWINDOW];
    100  1.2  thorpej 	__rwindow_t	__wbuf[_SPARC_MAXREGWINDOW];
    101  1.2  thorpej } __gwindows_t;
    102  1.2  thorpej 
    103  1.2  thorpej /* FPU address queue */
    104  1.2  thorpej struct __fpq {
    105  1.2  thorpej 	unsigned int *	__fpq_addr;	/* address */
    106  1.2  thorpej 	unsigned int	__fpq_instr;	/* instruction */
    107  1.2  thorpej };
    108  1.2  thorpej 
    109  1.2  thorpej struct __fq {
    110  1.2  thorpej 	union {
    111  1.2  thorpej 		double		__whole;
    112  1.2  thorpej 		struct __fpq	__fpq;
    113  1.2  thorpej 	} _FQu;
    114  1.2  thorpej };
    115  1.2  thorpej 
    116  1.2  thorpej /* FPU state description */
    117  1.2  thorpej typedef struct {
    118  1.2  thorpej 	union {
    119  1.2  thorpej 		unsigned int	__fpu_regs[32];
    120  1.2  thorpej #ifdef __arch64__
    121  1.2  thorpej 		double		__fpu_dregs[32];
    122  1.2  thorpej 		long double	__fpu_qregs[16];
    123  1.2  thorpej #else
    124  1.2  thorpej 		double		__fpu_dregs[16];
    125  1.2  thorpej #endif
    126  1.2  thorpej 	} __fpu_fr;				/* FPR contents */
    127  1.2  thorpej 	struct __fq *	__fpu_q;		/* pointer to FPU insn queue */
    128  1.2  thorpej 	unsigned long	__fpu_fsr;		/* %fsr */
    129  1.2  thorpej 	unsigned char	__fpu_qcnt;		/* # entries in __fpu_q */
    130  1.2  thorpej 	unsigned char	__fpu_q_entrysize; 	/* size of a __fpu_q entry */
    131  1.2  thorpej 	unsigned char	__fpu_en;		/* this context valid? */
    132  1.2  thorpej } __fpregset_t;
    133  1.2  thorpej 
    134  1.2  thorpej /* `Extra Register State'(?) */
    135  1.2  thorpej typedef struct {
    136  1.2  thorpej 	unsigned int	__xrs_id;	/* See below */
    137  1.2  thorpej 	char *		__xrs_ptr;	/* points into filler area */
    138  1.2  thorpej } __xrs_t;
    139  1.2  thorpej 
    140  1.2  thorpej #define	_XRS_ID		0x78727300	/* 'xrs\0' */
    141  1.2  thorpej 
    142  1.2  thorpej #ifdef __arch64__
    143  1.2  thorpej /* Ancillary State Registers, 16-31 are available to user programs */
    144  1.2  thorpej typedef	long		__asrset_t[16];	/* %asr16-31 */
    145  1.2  thorpej #endif
    146  1.2  thorpej 
    147  1.2  thorpej typedef struct {
    148  1.2  thorpej 	__gregset_t	__gregs;	/* GPR state */
    149  1.2  thorpej 	__gwindows_t *	__gwins;	/* may point to register windows */
    150  1.2  thorpej 	__fpregset_t	__fpregs;	/* FPU state, if any */
    151  1.2  thorpej 	__xrs_t		__xrs;		/* may indicate extra reg state */
    152  1.2  thorpej #ifdef __arch64__
    153  1.2  thorpej 	__asrset_t	__asrs;		/* ASR state */
    154  1.2  thorpej #endif
    155  1.4       pk } mcontext_t;
    156  1.2  thorpej 
    157  1.2  thorpej #ifdef __arch64__
    158  1.4       pk #define _UC_MACHINE_PAD	8		/* Padding appended to ucontext_t */
    159  1.2  thorpej #define	_UC_MACHINE_SP(uc)	(((uc)->uc_mcontext.__gregs[_REG_O6])+0x7ff)
    160  1.2  thorpej #else
    161  1.4       pk #define _UC_MACHINE_PAD	43		/* Padding appended to ucontext_t */
    162  1.2  thorpej #define	_UC_MACHINE_SP(uc)	((uc)->uc_mcontext.__gregs[_REG_O6])
    163  1.2  thorpej #endif
    164  1.3  thorpej #define	_UC_MACHINE_PC(uc)	((uc)->uc_mcontext.__gregs[_REG_PC])
    165  1.3  thorpej #define	_UC_MACHINE_INTRV(uc)	((uc)->uc_mcontext.__gregs[_REG_O0])
    166  1.3  thorpej 
    167  1.3  thorpej #define	_UC_MACHINE_SET_PC(uc, pc)					\
    168  1.3  thorpej do {									\
    169  1.3  thorpej 	(uc)->uc_mcontext.__gregs[_REG_PC] = (pc);			\
    170  1.3  thorpej 	(uc)->uc_mcontext.__gregs[_REG_nPC] = (pc) + 4;			\
    171  1.3  thorpej } while (/*CONSTCOND*/0)
    172  1.2  thorpej 
    173  1.2  thorpej #endif	/* !_SPARC_MCONTEXT_H_ */
    174