1 /* $NetBSD: mcontext.h,v 1.9 2008/04/28 20:23:36 martin Exp $ */ 2 3 /*- 4 * Copyright (c) 2001 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 _SPARC_MCONTEXT_H_ 33 #define _SPARC_MCONTEXT_H_ 34 35 #define _UC_SETSTACK 0x00010000 36 #define _UC_CLRSTACK 0x00020000 37 38 /* 39 * Layout of mcontext_t according the System V Application Binary Interface, 40 * Edition 4.1, SPARC Processor ABI Supplement and updated for SPARC v9. 41 */ 42 43 #ifdef __arch64__ 44 #define _NGREG 21 /* %ccr, pc, npc, %g1-7, %o0-7, %asi, %fprs */ 45 #else 46 #define _NGREG 19 /* %psr, pc, npc, %g1-7, %o0-7 */ 47 #endif 48 typedef long int __greg_t; 49 typedef __greg_t __gregset_t[_NGREG]; 50 51 /* Offsets into gregset_t, for convenience. */ 52 #ifdef __arch64__ 53 #define _REG_CCR 0 54 #else 55 #define _REG_PSR 0 56 #endif 57 #define _REG_PC 1 58 #define _REG_nPC 2 59 #define _REG_Y 3 60 #define _REG_G1 4 61 #define _REG_G2 5 62 #define _REG_G3 6 63 #define _REG_G4 7 64 #define _REG_G5 8 65 #define _REG_G6 9 66 #define _REG_G7 10 67 #define _REG_O0 11 68 #define _REG_O1 12 69 #define _REG_O2 13 70 #define _REG_O3 14 71 #define _REG_O4 15 72 #define _REG_O5 16 73 #define _REG_O6 17 74 #define _REG_O7 18 75 #ifdef __arch64__ 76 #define _REG_ASI 19 77 #define _REG_FPRS 20 78 #endif 79 80 81 #define _SPARC_MAXREGWINDOW 31 82 83 /* Layout of a register window. */ 84 typedef struct { 85 __greg_t __rw_local[8]; /* %l0-7 */ 86 __greg_t __rw_in[8]; /* %i0-7 */ 87 } __rwindow_t; 88 89 /* Description of available register windows. */ 90 typedef struct { 91 int __wbcnt; 92 __greg_t * __spbuf[_SPARC_MAXREGWINDOW]; 93 __rwindow_t __wbuf[_SPARC_MAXREGWINDOW]; 94 } __gwindows_t; 95 96 /* FPU address queue */ 97 struct __fpq { 98 unsigned int * __fpq_addr; /* address */ 99 unsigned int __fpq_instr; /* instruction */ 100 }; 101 102 struct __fq { 103 union { 104 double __whole; 105 struct __fpq __fpq; 106 } _FQu; 107 }; 108 109 /* FPU state description */ 110 typedef struct { 111 union { 112 unsigned int __fpu_regs[32]; 113 #ifdef __arch64__ 114 double __fpu_dregs[32]; 115 long double __fpu_qregs[16]; 116 #else 117 double __fpu_dregs[16]; 118 #endif 119 } __fpu_fr; /* FPR contents */ 120 struct __fq * __fpu_q; /* pointer to FPU insn queue */ 121 unsigned long __fpu_fsr; /* %fsr */ 122 unsigned char __fpu_qcnt; /* # entries in __fpu_q */ 123 unsigned char __fpu_q_entrysize; /* size of a __fpu_q entry */ 124 unsigned char __fpu_en; /* this context valid? */ 125 } __fpregset_t; 126 127 /* `Extra Register State'(?) */ 128 typedef struct { 129 unsigned int __xrs_id; /* See below */ 130 char * __xrs_ptr; /* points into filler area */ 131 } __xrs_t; 132 133 #define _XRS_ID 0x78727300 /* 'xrs\0' */ 134 135 #ifdef __arch64__ 136 /* Ancillary State Registers, 16-31 are available to user programs */ 137 typedef long __asrset_t[16]; /* %asr16-31 */ 138 #endif 139 140 typedef struct { 141 __gregset_t __gregs; /* GPR state */ 142 __gwindows_t * __gwins; /* may point to register windows */ 143 __fpregset_t __fpregs; /* FPU state, if any */ 144 __xrs_t __xrs; /* may indicate extra reg state */ 145 #ifdef __arch64__ 146 __asrset_t __asrs; /* ASR state */ 147 #endif 148 } mcontext_t; 149 150 #ifdef __arch64__ 151 #define _UC_MACHINE_PAD 8 /* Padding appended to ucontext_t */ 152 #define _UC_MACHINE_SP(uc) (((uc)->uc_mcontext.__gregs[_REG_O6])+0x7ff) 153 #define _UC_MACHINE32_PAD 43 /* compat_netbsd32 variant */ 154 #define _UC_MACHINE32_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_O6]) 155 #else 156 #define _UC_MACHINE_PAD 43 /* Padding appended to ucontext_t */ 157 #define _UC_MACHINE_SP(uc) ((uc)->uc_mcontext.__gregs[_REG_O6]) 158 #endif 159 #define _UC_MACHINE_PC(uc) ((uc)->uc_mcontext.__gregs[_REG_PC]) 160 #define _UC_MACHINE_INTRV(uc) ((uc)->uc_mcontext.__gregs[_REG_O0]) 161 162 #define _UC_MACHINE_SET_PC(uc, pc) \ 163 do { \ 164 (uc)->uc_mcontext.__gregs[_REG_PC] = (pc); \ 165 (uc)->uc_mcontext.__gregs[_REG_nPC] = (pc) + 4; \ 166 } while (/*CONSTCOND*/0) 167 168 #endif /* !_SPARC_MCONTEXT_H_ */ 169