1 /* $NetBSD: frame.h,v 1.27 2016/01/24 19:49:35 christos Exp $ */ 2 3 /* 4 * Copyright (C) 1995, 1996 Wolfgang Solfrank. 5 * Copyright (C) 1995, 1996 TooLs GmbH. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by TooLs GmbH. 19 * 4. The name of TooLs GmbH may not be used to endorse or promote products 20 * derived from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 #ifndef _POWERPC_FRAME_H_ 34 #define _POWERPC_FRAME_H_ 35 36 #include <machine/types.h> 37 38 #ifdef _KERNEL 39 #ifdef _KERNEL_OPT 40 #include "opt_ppcarch.h" 41 #endif 42 #endif 43 44 /* 45 * We have to save all registers on every trap, because 46 * 1. user could attach this process every time 47 * 2. we must be able to restore all user registers in case of fork 48 * Actually, we do not save the fp registers on trap, since 49 * these are not used by the kernel. They are saved only when switching 50 * between processes using the FPU. 51 * 52 * Change ordering to cluster together these register_t's. XXX 53 */ 54 struct reg_sans_pc { 55 __register_t r_fixreg[32]; 56 __register_t r_lr; 57 uint32_t r_cr; 58 uint32_t r_xer; 59 __register_t r_ctr; 60 }; 61 62 #ifdef _LP64 63 struct reg_sans_pc32 { 64 __register32_t r_fixreg[32]; 65 __register32_t r_lr; 66 uint32_t r_cr; 67 uint32_t r_xer; 68 __register32_t r_ctr; 69 }; 70 #endif 71 72 struct utrapframe { 73 __register_t fixreg[32]; 74 __register_t lr; 75 int cr; 76 int xer; 77 __register_t ctr; 78 __register_t srr0; 79 __register_t srr1; 80 int vrsave; 81 int mq; 82 int spare; 83 }; 84 85 struct clockframe { 86 __register_t cf_srr0; 87 __register_t cf_srr1; 88 int cf_idepth; 89 }; 90 91 #ifdef _LP64 92 struct clockframe32 { 93 __register32_t cf_srr0; 94 __register32_t cf_srr1; 95 int cf_idepth; 96 }; 97 #endif 98 99 struct trapframe { 100 struct reg_sans_pc tf_ureg; 101 struct clockframe tf_cf; 102 uint32_t tf_exc; 103 #if defined(PPC_OEA) || defined(PPC_OEA64) || defined(PPC_OEA64_BRIDGE) 104 __register_t tf_dar; 105 __register_t tf_pad0[2]; 106 uint32_t tf_dsisr; 107 uint32_t tf_vrsave; 108 uint32_t tf_mq; 109 uint32_t tf_pad1[1]; 110 #endif 111 #if defined(PPC_BOOKE) || defined(PPC_IBM4XX) 112 __register_t tf_dear; 113 __register_t tf_mcar; 114 __register_t tf_sprg1; 115 uint32_t tf_esr; 116 uint32_t tf_mcsr; 117 uint32_t tf_pid; 118 uint32_t tf_spefscr; 119 #endif 120 }; 121 122 #ifdef _LP64 123 struct trapframe32 { 124 struct reg_sans_pc32 tf_ureg; 125 struct clockframe32 tf_cf; 126 uint32_t tf_exc; 127 #if defined(PPC_OEA) || defined(PPC_OEA64) || defined(PPC_OEA64_BRIDGE) 128 __register32_t tf_dar; 129 __register32_t tf_pad0[2]; 130 uint32_t tf_dsisr; 131 uint32_t tf_vrsave; 132 uint32_t tf_mq; 133 uint32_t tf_pad1[1]; 134 #endif 135 #if defined(PPC_BOOKE) || defined(PPC_IBM4XX) 136 __register32_t tf_dear; 137 __register32_t tf_mcar; 138 __register32_t tf_sprg1; 139 uint32_t tf_esr; 140 uint32_t tf_mcsr; 141 uint32_t tf_pid; 142 uint32_t tf_spefscr; 143 #endif 144 }; 145 #endif /* _LP64 */ 146 #define tf_fixreg tf_ureg.r_fixreg 147 #define tf_lr tf_ureg.r_lr 148 #define tf_cr tf_ureg.r_cr 149 #define tf_xer tf_ureg.r_xer 150 #define tf_ctr tf_ureg.r_ctr 151 #define tf_srr0 tf_cf.cf_srr0 152 #define tf_srr1 tf_cf.cf_srr1 153 #define tf_idepth tf_cf.cf_idepth 154 155 struct ktrapframe { 156 __register_t ktf_sp; 157 __register_t ktf_lr; 158 struct trapframe ktf_tf; 159 __register_t ktf_cframe_lr; /* for DDB */ 160 }; 161 162 #if defined(_KERNEL) || defined(_LKM) 163 #ifdef _LP64 164 struct utrapframe32 { 165 __register32_t fixreg[32]; 166 __register32_t lr; 167 int cr; 168 int xer; 169 __register32_t ctr; 170 __register32_t srr0; 171 __register32_t srr1; 172 int vrsave; 173 int mq; 174 int spare; 175 }; 176 #endif 177 #endif /* _KERNEL || _LKM */ 178 179 /* 180 * This is to ensure alignment of the stackpointer 181 */ 182 #define FRAMELEN roundup(sizeof(struct ktrapframe), CALLFRAMELEN) 183 #define ktrapframe(l) ((struct ktrapframe *)(uvm_lwp_getuarea(l) + USPACE - CALLFRAMELEN - FRAMELEN)) 184 #define trapframe(l) (&(ktrapframe(l)->ktf_tf)) 185 186 #define SFRAMELEN roundup(sizeof(struct switchframe), CALLFRAMELEN) 187 struct switchframe { 188 __register_t sf_sp; 189 __register_t sf_lr; 190 __register_t sf_user_sr; /* VSID on IBM4XX */ 191 __register_t sf_cr; /* why? CR is volatile. */ 192 __register_t sf_fixreg2; 193 __register_t sf_fixreg[19]; /* R13-R31 */ 194 }; 195 196 /* 197 * Call frame for PowerPC used during fork. 198 */ 199 #define CALLFRAMELEN sizeof(struct callframe) 200 struct callframe { 201 __register_t cf_sp; 202 __register_t cf_lr; 203 __register_t cf_r30; 204 __register_t cf_r31; 205 }; 206 207 #endif /* _POWERPC_FRAME_H_ */ 208