1 /* $NetBSD: frame.h,v 1.29 2020/07/06 09:34:17 rin 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 34 #ifndef _POWERPC_FRAME_H_ 35 #define _POWERPC_FRAME_H_ 36 37 #include <machine/types.h> 38 39 #ifdef _KERNEL_OPT 40 #include "opt_ppcarch.h" 41 #endif 42 43 /* 44 * We have to save all registers on every trap, because 45 * 1. user could attach this process every time 46 * 2. we must be able to restore all user registers in case of fork 47 * Actually, we do not save the fp registers on trap, since 48 * these are not used by the kernel. They are saved only when switching 49 * between processes using the FPU. 50 * 51 * Change ordering to cluster together these register_t's. XXX 52 */ 53 struct reg_sans_pc { 54 __register_t r_fixreg[32]; 55 __register_t r_lr; 56 uint32_t r_cr; 57 uint32_t r_xer; 58 __register_t r_ctr; 59 }; 60 61 #ifdef _LP64 62 struct reg_sans_pc32 { 63 __register32_t r_fixreg[32]; 64 __register32_t r_lr; 65 uint32_t r_cr; 66 uint32_t r_xer; 67 __register32_t r_ctr; 68 }; 69 #endif 70 71 struct utrapframe { 72 __register_t fixreg[32]; 73 __register_t lr; 74 int cr; 75 int xer; 76 __register_t ctr; 77 __register_t srr0; 78 __register_t srr1; 79 int vrsave; 80 int mq; 81 int spare; 82 }; 83 84 struct clockframe { 85 __register_t cf_srr0; 86 __register_t cf_srr1; 87 int cf_idepth; 88 }; 89 90 #ifdef _LP64 91 struct clockframe32 { 92 __register32_t cf_srr0; 93 __register32_t cf_srr1; 94 int cf_idepth; 95 }; 96 #endif 97 98 struct trapframe { 99 struct reg_sans_pc tf_ureg; 100 struct clockframe tf_cf; 101 uint32_t tf_exc; 102 #if defined(PPC_OEA) || defined(PPC_OEA64) || defined(PPC_OEA64_BRIDGE) 103 __register_t tf_dar; 104 __register_t tf_pad0[2]; 105 uint32_t tf_dsisr; 106 uint32_t tf_vrsave; 107 uint32_t tf_mq; 108 uint32_t tf_pad1[1]; 109 #endif 110 #if defined(PPC_BOOKE) || defined(PPC_IBM4XX) 111 __register_t tf_dear; 112 __register_t tf_mcar; 113 __register_t tf_sprg1; 114 uint32_t tf_esr; 115 uint32_t tf_mcsr; 116 uint32_t tf_pid; 117 uint32_t tf_spefscr; 118 #endif 119 }; 120 121 #ifdef _LP64 122 struct trapframe32 { 123 struct reg_sans_pc32 tf_ureg; 124 struct clockframe32 tf_cf; 125 uint32_t tf_exc; 126 #if defined(PPC_OEA) || defined(PPC_OEA64) || defined(PPC_OEA64_BRIDGE) 127 __register32_t tf_dar; 128 __register32_t tf_pad0[2]; 129 uint32_t tf_dsisr; 130 uint32_t tf_vrsave; 131 uint32_t tf_mq; 132 uint32_t tf_pad1[1]; 133 #endif 134 #if defined(PPC_BOOKE) || defined(PPC_IBM4XX) 135 __register32_t tf_dear; 136 __register32_t tf_mcar; 137 __register32_t tf_sprg1; 138 uint32_t tf_esr; 139 uint32_t tf_mcsr; 140 uint32_t tf_pid; 141 uint32_t tf_spefscr; 142 #endif 143 }; 144 #endif /* _LP64 */ 145 #define tf_fixreg tf_ureg.r_fixreg 146 #define tf_lr tf_ureg.r_lr 147 #define tf_cr tf_ureg.r_cr 148 #define tf_xer tf_ureg.r_xer 149 #define tf_ctr tf_ureg.r_ctr 150 #define tf_srr0 tf_cf.cf_srr0 151 #define tf_srr1 tf_cf.cf_srr1 152 #define tf_idepth tf_cf.cf_idepth 153 154 struct ktrapframe { 155 __register_t ktf_sp; 156 __register_t ktf_lr; 157 struct trapframe ktf_tf; 158 __register_t ktf_cframe_lr; /* for DDB */ 159 }; 160 161 #if defined(_KERNEL) 162 #ifdef _LP64 163 struct utrapframe32 { 164 __register32_t fixreg[32]; 165 __register32_t lr; 166 int cr; 167 int xer; 168 __register32_t ctr; 169 __register32_t srr0; 170 __register32_t srr1; 171 int vrsave; 172 int mq; 173 int spare; 174 }; 175 #endif 176 #endif /* _KERNEL */ 177 178 /* 179 * This is to ensure alignment of the stackpointer 180 */ 181 #define FRAMELEN roundup(sizeof(struct ktrapframe), CALLFRAMELEN) 182 #define ktrapframe(l) ((struct ktrapframe *)(uvm_lwp_getuarea(l) + USPACE - CALLFRAMELEN - FRAMELEN)) 183 #define trapframe(l) (&(ktrapframe(l)->ktf_tf)) 184 185 #define SFRAMELEN roundup(sizeof(struct switchframe), CALLFRAMELEN) 186 struct switchframe { 187 __register_t sf_sp; 188 __register_t sf_lr; 189 __register_t sf_user_sr; /* VSID on IBM4XX */ 190 __register_t sf_cr; /* why? CR is volatile. */ 191 __register_t sf_fixreg2; 192 __register_t sf_fixreg[19]; /* R13-R31 */ 193 }; 194 195 /* 196 * Call frame for PowerPC used during fork. 197 */ 198 #define CALLFRAMELEN sizeof(struct callframe) 199 struct callframe { 200 __register_t cf_sp; 201 __register_t cf_lr; 202 __register_t cf_r30; 203 __register_t cf_r31; 204 }; 205 206 #endif /* _POWERPC_FRAME_H_ */ 207