1 2 /*---------------------------------------------------------------*/ 3 /*--- begin libvex_guest_ppc32.h ---*/ 4 /*---------------------------------------------------------------*/ 5 6 /* 7 This file is part of Valgrind, a dynamic binary instrumentation 8 framework. 9 10 Copyright (C) 2004-2010 OpenWorks LLP 11 info@open-works.net 12 13 This program is free software; you can redistribute it and/or 14 modify it under the terms of the GNU General Public License as 15 published by the Free Software Foundation; either version 2 of the 16 License, or (at your option) any later version. 17 18 This program is distributed in the hope that it will be useful, but 19 WITHOUT ANY WARRANTY; without even the implied warranty of 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21 General Public License for more details. 22 23 You should have received a copy of the GNU General Public License 24 along with this program; if not, write to the Free Software 25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 26 02110-1301, USA. 27 28 The GNU General Public License is contained in the file COPYING. 29 30 Neither the names of the U.S. Department of Energy nor the 31 University of California nor the names of its contributors may be 32 used to endorse or promote products derived from this software 33 without prior written permission. 34 */ 35 36 #ifndef __LIBVEX_PUB_GUEST_PPC32_H 37 #define __LIBVEX_PUB_GUEST_PPC32_H 38 39 #include "libvex_basictypes.h" 40 #include "libvex_emwarn.h" 41 42 43 /*---------------------------------------------------------------*/ 44 /*--- Vex's representation of the PPC32 CPU state ---*/ 45 /*---------------------------------------------------------------*/ 46 47 #define VEX_GUEST_PPC32_REDIR_STACK_SIZE (16/*entries*/ * 2/*words per entry*/) 48 49 typedef 50 struct { 51 /* General Purpose Registers */ 52 /* 0 */ UInt guest_GPR0; 53 /* 4 */ UInt guest_GPR1; 54 /* 8 */ UInt guest_GPR2; 55 /* 12 */ UInt guest_GPR3; 56 /* 16 */ UInt guest_GPR4; 57 /* 20 */ UInt guest_GPR5; 58 /* 24 */ UInt guest_GPR6; 59 /* 28 */ UInt guest_GPR7; 60 /* 32 */ UInt guest_GPR8; 61 /* 36 */ UInt guest_GPR9; 62 /* 40 */ UInt guest_GPR10; 63 /* 44 */ UInt guest_GPR11; 64 /* 48 */ UInt guest_GPR12; 65 /* 52 */ UInt guest_GPR13; 66 /* 56 */ UInt guest_GPR14; 67 /* 60 */ UInt guest_GPR15; 68 /* 64 */ UInt guest_GPR16; 69 /* 68 */ UInt guest_GPR17; 70 /* 72 */ UInt guest_GPR18; 71 /* 76 */ UInt guest_GPR19; 72 /* 80 */ UInt guest_GPR20; 73 /* 84 */ UInt guest_GPR21; 74 /* 88 */ UInt guest_GPR22; 75 /* 92 */ UInt guest_GPR23; 76 /* 96 */ UInt guest_GPR24; 77 /* 100 */ UInt guest_GPR25; 78 /* 104 */ UInt guest_GPR26; 79 /* 108 */ UInt guest_GPR27; 80 /* 112 */ UInt guest_GPR28; 81 /* 116 */ UInt guest_GPR29; 82 /* 120 */ UInt guest_GPR30; 83 /* 124 */ UInt guest_GPR31; 84 85 // Floating Point Registers 86 /* 128 */ ULong guest_FPR0; 87 /* 136 */ ULong guest_FPR1; 88 /* 144 */ ULong guest_FPR2; 89 /* 152 */ ULong guest_FPR3; 90 /* 160 */ ULong guest_FPR4; 91 /* 168 */ ULong guest_FPR5; 92 /* 176 */ ULong guest_FPR6; 93 /* 184 */ ULong guest_FPR7; 94 /* 192 */ ULong guest_FPR8; 95 /* 200 */ ULong guest_FPR9; 96 /* 208 */ ULong guest_FPR10; 97 /* 216 */ ULong guest_FPR11; 98 /* 224 */ ULong guest_FPR12; 99 /* 232 */ ULong guest_FPR13; 100 /* 240 */ ULong guest_FPR14; 101 /* 248 */ ULong guest_FPR15; 102 /* 256 */ ULong guest_FPR16; 103 /* 264 */ ULong guest_FPR17; 104 /* 272 */ ULong guest_FPR18; 105 /* 280 */ ULong guest_FPR19; 106 /* 288 */ ULong guest_FPR20; 107 /* 296 */ ULong guest_FPR21; 108 /* 304 */ ULong guest_FPR22; 109 /* 312 */ ULong guest_FPR23; 110 /* 320 */ ULong guest_FPR24; 111 /* 328 */ ULong guest_FPR25; 112 /* 336 */ ULong guest_FPR26; 113 /* 344 */ ULong guest_FPR27; 114 /* 352 */ ULong guest_FPR28; 115 /* 360 */ ULong guest_FPR29; 116 /* 368 */ ULong guest_FPR30; 117 /* 376 */ ULong guest_FPR31; 118 119 // Vector Registers 120 // IMPORTANT: the user of libvex must place the guest state so as 121 // to ensure that guest_VR{0..31}, and any shadows thereof, are 122 // 16-aligned. 123 /* 384 */ U128 guest_VR0; 124 /* 400 */ U128 guest_VR1; 125 /* 416 */ U128 guest_VR2; 126 /* 432 */ U128 guest_VR3; 127 /* 448 */ U128 guest_VR4; 128 /* 464 */ U128 guest_VR5; 129 /* 480 */ U128 guest_VR6; 130 /* 496 */ U128 guest_VR7; 131 /* 512 */ U128 guest_VR8; 132 /* 528 */ U128 guest_VR9; 133 /* 544 */ U128 guest_VR10; 134 /* 560 */ U128 guest_VR11; 135 /* 576 */ U128 guest_VR12; 136 /* 592 */ U128 guest_VR13; 137 /* 608 */ U128 guest_VR14; 138 /* 624 */ U128 guest_VR15; 139 /* 640 */ U128 guest_VR16; 140 /* 656 */ U128 guest_VR17; 141 /* 672 */ U128 guest_VR18; 142 /* 688 */ U128 guest_VR19; 143 /* 704 */ U128 guest_VR20; 144 /* 720 */ U128 guest_VR21; 145 /* 736 */ U128 guest_VR22; 146 /* 752 */ U128 guest_VR23; 147 /* 768 */ U128 guest_VR24; 148 /* 784 */ U128 guest_VR25; 149 /* 800 */ U128 guest_VR26; 150 /* 816 */ U128 guest_VR27; 151 /* 832 */ U128 guest_VR28; 152 /* 848 */ U128 guest_VR29; 153 /* 864 */ U128 guest_VR30; 154 /* 880 */ U128 guest_VR31; 155 156 /* 896 */ UInt guest_CIA; // IP (no arch visible register) 157 /* 900 */ UInt guest_LR; // Link Register 158 /* 904 */ UInt guest_CTR; // Count Register 159 160 /* XER pieces */ 161 /* 908 */ UChar guest_XER_SO; /* in lsb */ 162 /* 909 */ UChar guest_XER_OV; /* in lsb */ 163 /* 910 */ UChar guest_XER_CA; /* in lsb */ 164 /* 911 */ UChar guest_XER_BC; /* all bits */ 165 166 /* CR pieces */ 167 /* 912 */ UChar guest_CR0_321; /* in [3:1] */ 168 /* 913 */ UChar guest_CR0_0; /* in lsb */ 169 /* 914 */ UChar guest_CR1_321; /* in [3:1] */ 170 /* 915 */ UChar guest_CR1_0; /* in lsb */ 171 /* 916 */ UChar guest_CR2_321; /* in [3:1] */ 172 /* 917 */ UChar guest_CR2_0; /* in lsb */ 173 /* 918 */ UChar guest_CR3_321; /* in [3:1] */ 174 /* 919 */ UChar guest_CR3_0; /* in lsb */ 175 /* 920 */ UChar guest_CR4_321; /* in [3:1] */ 176 /* 921 */ UChar guest_CR4_0; /* in lsb */ 177 /* 922 */ UChar guest_CR5_321; /* in [3:1] */ 178 /* 923 */ UChar guest_CR5_0; /* in lsb */ 179 /* 924 */ UChar guest_CR6_321; /* in [3:1] */ 180 /* 925 */ UChar guest_CR6_0; /* in lsb */ 181 /* 926 */ UChar guest_CR7_321; /* in [3:1] */ 182 /* 927 */ UChar guest_CR7_0; /* in lsb */ 183 184 /* FP Status & Control Register fields */ 185 /* 928 */ UInt guest_FPROUND; // FP Rounding Mode 186 187 /* Vector Save/Restore Register */ 188 /* 932 */ UInt guest_VRSAVE; 189 190 /* Vector Status and Control Register */ 191 /* 936 */ UInt guest_VSCR; 192 193 /* Emulation warnings */ 194 /* 940 */ UInt guest_EMWARN; 195 196 /* For icbi: record start and length of area to invalidate */ 197 /* 944 */ UInt guest_TISTART; 198 /* 948 */ UInt guest_TILEN; 199 200 /* Used to record the unredirected guest address at the start of 201 a translation whose start has been redirected. By reading 202 this pseudo-register shortly afterwards, the translation can 203 find out what the corresponding no-redirection address was. 204 Note, this is only set for wrap-style redirects, not for 205 replace-style ones. */ 206 /* 952 */ UInt guest_NRADDR; 207 /* 956 */ UInt guest_NRADDR_GPR2; /* needed by aix */ 208 209 /* A grows-upwards stack for hidden saves/restores of LR and R2 210 needed for function interception and wrapping on ppc32-aix5. 211 A horrible hack. REDIR_SP points to the highest live entry, 212 and so starts at -1. */ 213 /* 960 */ UInt guest_REDIR_SP; 214 /* 964 */ UInt guest_REDIR_STACK[VEX_GUEST_PPC32_REDIR_STACK_SIZE]; 215 216 /* Needed for AIX (but mandated for all guest architectures): 217 CIA at the last SC insn. Used when backing up to restart a 218 syscall that has been interrupted by a signal. */ 219 /* ??? */ UInt guest_IP_AT_SYSCALL; 220 221 /* SPRG3, which AIUI is readonly in user space. Needed for 222 threading on AIX. */ 223 /* ??? */ UInt guest_SPRG3_RO; 224 225 /* Padding to make it have an 8-aligned size */ 226 /* UInt padding; */ 227 } 228 VexGuestPPC32State; 229 230 231 /*---------------------------------------------------------------*/ 232 /*--- Utility functions for PPC32 guest stuff. ---*/ 233 /*---------------------------------------------------------------*/ 234 235 /* ALL THE FOLLOWING ARE VISIBLE TO LIBRARY CLIENT */ 236 237 /* Initialise all guest PPC32 state. */ 238 239 extern 240 void LibVEX_GuestPPC32_initialise ( /*OUT*/VexGuestPPC32State* vex_state ); 241 242 243 /* Write the given native %CR value to the supplied VexGuestPPC32State 244 structure. */ 245 extern 246 void LibVEX_GuestPPC32_put_CR ( UInt cr_native, 247 /*OUT*/VexGuestPPC32State* vex_state ); 248 249 /* Extract from the supplied VexGuestPPC32State structure the 250 corresponding native %CR value. */ 251 extern 252 UInt LibVEX_GuestPPC32_get_CR ( /*IN*/VexGuestPPC32State* vex_state ); 253 254 255 /* Write the given native %XER value to the supplied VexGuestPPC32State 256 structure. */ 257 extern 258 void LibVEX_GuestPPC32_put_XER ( UInt xer_native, 259 /*OUT*/VexGuestPPC32State* vex_state ); 260 261 /* Extract from the supplied VexGuestPPC32State structure the 262 corresponding native %XER value. */ 263 extern 264 UInt LibVEX_GuestPPC32_get_XER ( /*IN*/VexGuestPPC32State* vex_state ); 265 266 #endif /* ndef __LIBVEX_PUB_GUEST_PPC32_H */ 267 268 269 /*---------------------------------------------------------------*/ 270 /*--- libvex_guest_ppc32.h ---*/ 271 /*---------------------------------------------------------------*/ 272