Home | History | Annotate | Line # | Download | only in include
mcontext.h revision 1.11.8.1
      1  1.11.8.1    bouyer /*	$NetBSD: mcontext.h,v 1.11.8.1 2011/03/05 15:09:48 bouyer Exp $	*/
      2       1.2   thorpej 
      3       1.2   thorpej /*-
      4       1.2   thorpej  * Copyright (c) 1999, 2002 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, and by Jason R. Thorpe of Wasabi Systems, Inc.
      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  *
     19       1.2   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.2   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.2   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.2   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.2   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.2   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.2   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.2   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.2   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.2   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.2   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     30       1.2   thorpej  */
     31       1.2   thorpej 
     32       1.2   thorpej #ifndef _MIPS_MCONTEXT_H_
     33       1.2   thorpej #define _MIPS_MCONTEXT_H_
     34       1.2   thorpej 
     35       1.2   thorpej /*
     36       1.2   thorpej  * General register state
     37       1.2   thorpej  */
     38       1.2   thorpej #define _NGREG		37	/* R0-R31, MDLO, MDHI, CAUSE, PC, SR */
     39       1.2   thorpej 
     40       1.2   thorpej #define _REG_R0		0
     41       1.2   thorpej #define _REG_AT		1
     42       1.2   thorpej #define _REG_V0		2
     43       1.2   thorpej #define _REG_V1		3
     44       1.2   thorpej #define _REG_A0		4
     45       1.2   thorpej #define _REG_A1		5
     46       1.2   thorpej #define _REG_A2		6
     47       1.2   thorpej #define _REG_A3		7
     48       1.2   thorpej #define _REG_T0		8
     49       1.2   thorpej #define _REG_T1		9
     50       1.2   thorpej #define _REG_T2		10
     51       1.2   thorpej #define _REG_T3		11
     52       1.2   thorpej #define _REG_T4		12
     53       1.2   thorpej #define _REG_T5		13
     54       1.2   thorpej #define _REG_T6		14
     55       1.2   thorpej #define _REG_T7		15
     56       1.2   thorpej #define _REG_S0		16
     57       1.2   thorpej #define _REG_S1		17
     58       1.2   thorpej #define _REG_S2		18
     59       1.2   thorpej #define _REG_S3		19
     60       1.2   thorpej #define _REG_S4		20
     61       1.2   thorpej #define _REG_S5		21
     62       1.2   thorpej #define _REG_S6		22
     63       1.2   thorpej #define _REG_S7		23
     64       1.2   thorpej #define _REG_T8		24
     65       1.2   thorpej #define _REG_T9		25
     66       1.2   thorpej #define _REG_K0		26
     67       1.2   thorpej #define _REG_K1		27
     68       1.2   thorpej #define _REG_GP		28
     69       1.2   thorpej #define _REG_SP		29
     70       1.2   thorpej #define _REG_S8		30
     71       1.2   thorpej #define _REG_RA		31
     72       1.2   thorpej 
     73       1.2   thorpej /* XXX: The following conflict with <mips/regnum.h> */
     74       1.2   thorpej #define _REG_MDLO	32
     75       1.2   thorpej #define _REG_MDHI	33
     76       1.2   thorpej #define _REG_CAUSE	34
     77       1.2   thorpej #define _REG_EPC	35
     78       1.2   thorpej #define _REG_SR		36
     79       1.2   thorpej 
     80       1.2   thorpej #ifndef __ASSEMBLER__
     81       1.2   thorpej 
     82       1.2   thorpej /* Make sure this is signed; we need pointers to be sign-extended. */
     83       1.2   thorpej #if defined(__mips_n32)
     84      1.11      matt typedef	long long	__greg_t;
     85       1.2   thorpej #else
     86      1.11      matt typedef	long		__greg_t;
     87       1.2   thorpej #endif /* __mips_n32 */
     88       1.2   thorpej 
     89       1.2   thorpej typedef	__greg_t	__gregset_t[_NGREG];
     90       1.2   thorpej 
     91       1.2   thorpej /*
     92      1.11      matt  * For the O32/O64 ABI, there are 16 doubles, one at each even FP reg
     93       1.6    simonb  * number.  The FP registers themselves are 32-bits.
     94       1.6    simonb  *
     95       1.6    simonb  * For 64-bit ABIs (include N32), each FP register is a 64-bit double.
     96       1.6    simonb  */
     97       1.6    simonb typedef	__greg_t	__freg_t;
     98       1.6    simonb 
     99       1.6    simonb /*
    100       1.2   thorpej  * Floating point register state
    101       1.2   thorpej  */
    102      1.11      matt struct __fpregset_nabi {
    103       1.6    simonb 	union {
    104       1.6    simonb 		double	__fp64_dregs[32];
    105       1.6    simonb 		__freg_t __fp_regs[32];
    106       1.6    simonb 	} __fp_r;
    107      1.11      matt 	__greg_t	__fp_csr;
    108      1.11      matt };
    109      1.11      matt struct __fpregset_oabi {
    110       1.2   thorpej 	union {
    111       1.6    simonb 		double	__fp_dregs[16];
    112       1.6    simonb 		float	__fp_fregs[32];
    113      1.11      matt 		__int32_t __fp_regs[32];
    114       1.2   thorpej 	} __fp_r;
    115       1.2   thorpej 	unsigned int	__fp_csr;
    116       1.2   thorpej 	unsigned int	__fp_pad;
    117      1.11      matt };
    118      1.11      matt 
    119      1.11      matt #if __mips_n32 || __mips_n64
    120      1.11      matt typedef struct __fpregset_nabi __fpregset_t;
    121      1.11      matt #else
    122      1.11      matt typedef struct __fpregset_oabi __fpregset_t;
    123      1.11      matt #endif
    124       1.2   thorpej 
    125       1.2   thorpej typedef struct {
    126       1.2   thorpej 	__gregset_t	__gregs;
    127       1.2   thorpej 	__fpregset_t	__fpregs;
    128  1.11.8.1    bouyer 	__greg_t	_mc_tlsbase;
    129  1.11.8.1    bouyer #if !__mips_n32
    130  1.11.8.1    bouyer 	__greg_t	__mc_unused;
    131  1.11.8.1    bouyer #endif
    132       1.2   thorpej } mcontext_t;
    133       1.2   thorpej 
    134  1.11.8.1    bouyer #if defined(_KERNEL) && !defined(__mips_o32)
    135      1.11      matt typedef	__int32_t	__greg32_t;
    136      1.11      matt typedef __greg32_t	__gregset32_t[_NGREG];
    137      1.11      matt 
    138      1.11      matt typedef struct {
    139      1.11      matt 	__gregset32_t		__gregs;
    140      1.11      matt 	struct __fpregset_oabi	__fpregs;
    141  1.11.8.1    bouyer 	__greg32_t		_mc_tlsbase;
    142  1.11.8.1    bouyer 	__greg32_t		__mc_unused;
    143      1.11      matt } mcontext_o32_t;
    144      1.11      matt 
    145      1.11      matt typedef struct {
    146      1.11      matt 	__gregset_t		__gregs;
    147      1.11      matt 	struct __fpregset_nabi	__fpregs;
    148  1.11.8.1    bouyer 	__greg_t		_mc_tlsbase;
    149      1.11      matt } mcontext32_t;
    150      1.11      matt 
    151      1.11      matt #endif /* _KERNEL && _LP64 */
    152      1.11      matt 
    153      1.10      matt #endif /* !__ASSEMBLER__ */
    154       1.9      matt 
    155  1.11.8.1    bouyer #define _UC_MACHINE_PAD		14	/* Padding appended to ucontext_t */
    156       1.9      matt 
    157       1.5  christos #define	_UC_SETSTACK	0x00010000
    158       1.5  christos #define	_UC_CLRSTACK	0x00020000
    159  1.11.8.1    bouyer #define	_UC_TLSBASE	0x00040000
    160       1.2   thorpej 
    161       1.2   thorpej #define _UC_MACHINE_SP(uc)	((uc)->uc_mcontext.__gregs[_REG_SP])
    162       1.4   thorpej #define _UC_MACHINE_PC(uc)	((uc)->uc_mcontext.__gregs[_REG_EPC])
    163       1.4   thorpej #define _UC_MACHINE_INTRV(uc)	((uc)->uc_mcontext.__gregs[_REG_V0])
    164       1.4   thorpej 
    165       1.4   thorpej #define	_UC_MACHINE_SET_PC(uc, pc)	_UC_MACHINE_PC(uc) = (pc)
    166       1.2   thorpej 
    167      1.11      matt #define _UC_MACHINE32_SP(uc)	_UC_MACHINE_SP(uc)
    168      1.11      matt #define _UC_MACHINE32_PC(uc)	_UC_MACHINE_PC(uc)
    169      1.11      matt #define _UC_MACHINE32_INTRV(uc)	_UC_MACHINE_INTRV(uc)
    170  1.11.8.1    bouyer #define _UC_MACHINE32_PAD	14	/* Padding appended to ucontext32_t */
    171      1.11      matt 
    172      1.11      matt #define	_UC_MACHINE32_SET_PC(uc, pc)	_UC_MACHINE_PC((uc), (pc))
    173      1.11      matt 
    174  1.11.8.1    bouyer #define	__UCONTEXT_SIZE_O32	(40 + 296 +  56)	/* 392 */
    175  1.11.8.1    bouyer #define	__UCONTEXT_SIZE_N32	(40 + 568 +  56)	/* 664 */
    176  1.11.8.1    bouyer #define	__UCONTEXT_SIZE_N64	(56 + 576 + 112)	/* 774 */
    177  1.11.8.1    bouyer 
    178  1.11.8.1    bouyer #ifdef __mips_o32
    179  1.11.8.1    bouyer #define	__UCONTEXT_SIZE		__UCONTEXT_SIZE_O32
    180  1.11.8.1    bouyer #elif __mips_n32
    181  1.11.8.1    bouyer #define	__UCONTEXT_SIZE		__UCONTEXT_SIZE_N32
    182  1.11.8.1    bouyer #elif __mips_n64
    183  1.11.8.1    bouyer #define	__UCONTEXT_SIZE		__UCONTEXT_SIZE_N64
    184  1.11.8.1    bouyer #define	__UCONTEXT32_SIZE	__UCONTEXT_SIZE_N32
    185  1.11.8.1    bouyer #elif
    186  1.11.8.1    bouyer #error O64 is not supported
    187  1.11.8.1    bouyer #endif
    188  1.11.8.1    bouyer 
    189  1.11.8.1    bouyer #ifndef __ASSEMBLER__
    190  1.11.8.1    bouyer static __inline void *
    191  1.11.8.1    bouyer __lwp_getprivate_fast(void)
    192  1.11.8.1    bouyer {
    193  1.11.8.1    bouyer 	register void *__tcb;
    194  1.11.8.1    bouyer 
    195  1.11.8.1    bouyer 	__asm volatile(".set push; .set mips32r2; "
    196  1.11.8.1    bouyer 		"rdhwr %0, $29; .set pop" : "=v"(__tcb));
    197  1.11.8.1    bouyer 	return __tcb;
    198  1.11.8.1    bouyer }
    199  1.11.8.1    bouyer #endif
    200  1.11.8.1    bouyer 
    201       1.2   thorpej #endif	/* _MIPS_MCONTEXT_H_ */
    202