1 2 /*---------------------------------------------------------------*/ 3 /*--- begin libvex_guest_ppc64.h ---*/ 4 /*---------------------------------------------------------------*/ 5 6 /* 7 This file is part of Valgrind, a dynamic binary instrumentation 8 framework. 9 10 Copyright (C) 2004-2012 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_PPC64_H 37 #define __LIBVEX_PUB_GUEST_PPC64_H 38 39 #include "libvex_basictypes.h" 40 #include "libvex_emwarn.h" 41 42 /* 43 volatile == caller-saved (not preserved across function calls) 44 non-volatile == callee-saved (preserved across function calls) 45 46 r0 Volatile register used in function prologs 47 r1 Stack frame pointer 48 r2 TOC pointer 49 r3 Volatile parameter and return value register 50 r4-r10 Volatile registers used for function parameters 51 r11 Volatile register used in calls by pointer and as an 52 environment pointer for languages which require one 53 r12 Volatile register used for exception handling and glink code 54 r13 Reserved for use as system thread ID 55 r14-r31 Nonvolatile registers used for local variables 56 57 f0 Volatile scratch register 58 f1-f4 Volatile floating point parameter and return value registers 59 f5-f13 Volatile floating point parameter registers 60 f14-f31 Nonvolatile registers 61 62 LR Link register (volatile) 63 CTR Loop counter register (volatile) 64 XER Fixed point exception register (volatile) 65 FPSCR Floating point status and control register (volatile) 66 67 CR0-CR1 Volatile condition code register fields 68 CR2-CR4 Nonvolatile condition code register fields 69 CR5-CR7 Volatile condition code register fields 70 71 On processors with the VMX feature. 72 73 v0-v1 Volatile scratch registers 74 v2-v13 Volatile vector parameters registers 75 v14-v19 Volatile scratch registers 76 v20-v31 Non-volatile registers 77 vrsave Non-volatile 32-bit register 78 */ 79 80 81 /*---------------------------------------------------------------*/ 82 /*--- Vex's representation of the PPC64 CPU state ---*/ 83 /*---------------------------------------------------------------*/ 84 85 #define VEX_GUEST_PPC64_REDIR_STACK_SIZE (16/*entries*/ * 2/*words per entry*/) 86 87 typedef 88 struct { 89 /* Event check fail addr, counter, and padding to make GPR0 16 90 aligned. */ 91 /* 0 */ ULong host_EvC_FAILADDR; 92 /* 8 */ UInt host_EvC_COUNTER; 93 /* 12 */ UInt pad0; 94 /* Add 16 to all of the offsets below .. */ 95 /* General Purpose Registers */ 96 /* 0 */ ULong guest_GPR0; 97 /* 8 */ ULong guest_GPR1; 98 /* 16 */ ULong guest_GPR2; 99 /* 24 */ ULong guest_GPR3; 100 /* 32 */ ULong guest_GPR4; 101 /* 40 */ ULong guest_GPR5; 102 /* 48 */ ULong guest_GPR6; 103 /* 56 */ ULong guest_GPR7; 104 /* 64 */ ULong guest_GPR8; 105 /* 72 */ ULong guest_GPR9; 106 /* 80 */ ULong guest_GPR10; 107 /* 88 */ ULong guest_GPR11; 108 /* 96 */ ULong guest_GPR12; 109 /* 104 */ ULong guest_GPR13; 110 /* 112 */ ULong guest_GPR14; 111 /* 120 */ ULong guest_GPR15; 112 /* 128 */ ULong guest_GPR16; 113 /* 136 */ ULong guest_GPR17; 114 /* 144 */ ULong guest_GPR18; 115 /* 152 */ ULong guest_GPR19; 116 /* 160 */ ULong guest_GPR20; 117 /* 168 */ ULong guest_GPR21; 118 /* 176 */ ULong guest_GPR22; 119 /* 184 */ ULong guest_GPR23; 120 /* 192 */ ULong guest_GPR24; 121 /* 200 */ ULong guest_GPR25; 122 /* 208 */ ULong guest_GPR26; 123 /* 216 */ ULong guest_GPR27; 124 /* 224 */ ULong guest_GPR28; 125 /* 232 */ ULong guest_GPR29; 126 /* 240 */ ULong guest_GPR30; 127 /* 248 */ ULong guest_GPR31; 128 129 // Vector Registers, Floating Point Registers, and VSX Registers 130 // With ISA 2.06, the "Vector-Scalar Floating-point" category 131 // provides facilities to support vector and scalar binary floating- 132 // point operations. A unified register file is an integral part 133 // of this new facility, combining floating point and vector registers 134 // using a 64x128-bit vector. These are referred to as VSR[0..63]. 135 // The floating point registers are now mapped into double word element 0 136 // of VSR[0..31]. The 32x128-bit vector registers defined by the "Vector 137 // Facility [Category: Vector]" are now mapped to VSR[32..63]. 138 139 // IMPORTANT: the user of libvex must place the guest state so as 140 // to ensure that guest_VSR{0..63}, and any shadows thereof, are 141 // 16-aligned. 142 143 /* 256 */ U128 guest_VSR0; 144 /* 272 */ U128 guest_VSR1; 145 /* 288 */ U128 guest_VSR2; 146 /* 304 */ U128 guest_VSR3; 147 /* 320 */ U128 guest_VSR4; 148 /* 336 */ U128 guest_VSR5; 149 /* 352 */ U128 guest_VSR6; 150 /* 368 */ U128 guest_VSR7; 151 /* 384 */ U128 guest_VSR8; 152 /* 400 */ U128 guest_VSR9; 153 /* 416 */ U128 guest_VSR10; 154 /* 432 */ U128 guest_VSR11; 155 /* 448 */ U128 guest_VSR12; 156 /* 464 */ U128 guest_VSR13; 157 /* 480 */ U128 guest_VSR14; 158 /* 496 */ U128 guest_VSR15; 159 /* 512 */ U128 guest_VSR16; 160 /* 528 */ U128 guest_VSR17; 161 /* 544 */ U128 guest_VSR18; 162 /* 560 */ U128 guest_VSR19; 163 /* 576 */ U128 guest_VSR20; 164 /* 592 */ U128 guest_VSR21; 165 /* 608 */ U128 guest_VSR22; 166 /* 624 */ U128 guest_VSR23; 167 /* 640 */ U128 guest_VSR24; 168 /* 656 */ U128 guest_VSR25; 169 /* 672 */ U128 guest_VSR26; 170 /* 688 */ U128 guest_VSR27; 171 /* 704 */ U128 guest_VSR28; 172 /* 720 */ U128 guest_VSR29; 173 /* 736 */ U128 guest_VSR30; 174 /* 752 */ U128 guest_VSR31; 175 /* 768 */ U128 guest_VSR32; 176 /* 784 */ U128 guest_VSR33; 177 /* 800 */ U128 guest_VSR34; 178 /* 816 */ U128 guest_VSR35; 179 /* 832 */ U128 guest_VSR36; 180 /* 848 */ U128 guest_VSR37; 181 /* 864 */ U128 guest_VSR38; 182 /* 880 */ U128 guest_VSR39; 183 /* 896 */ U128 guest_VSR40; 184 /* 912 */ U128 guest_VSR41; 185 /* 928 */ U128 guest_VSR42; 186 /* 944 */ U128 guest_VSR43; 187 /* 960 */ U128 guest_VSR44; 188 /* 976 */ U128 guest_VSR45; 189 /* 992 */ U128 guest_VSR46; 190 /* 1008 */ U128 guest_VSR47; 191 /* 1024 */ U128 guest_VSR48; 192 /* 1040 */ U128 guest_VSR49; 193 /* 1056 */ U128 guest_VSR50; 194 /* 1072 */ U128 guest_VSR51; 195 /* 1088 */ U128 guest_VSR52; 196 /* 1104 */ U128 guest_VSR53; 197 /* 1120 */ U128 guest_VSR54; 198 /* 1136 */ U128 guest_VSR55; 199 /* 1152 */ U128 guest_VSR56; 200 /* 1168 */ U128 guest_VSR57; 201 /* 1184 */ U128 guest_VSR58; 202 /* 1200 */ U128 guest_VSR59; 203 /* 1216 */ U128 guest_VSR60; 204 /* 1232 */ U128 guest_VSR61; 205 /* 1248 */ U128 guest_VSR62; 206 /* 1264 */ U128 guest_VSR63; 207 208 /* 1280 */ ULong guest_CIA; // IP (no arch visible register) 209 /* 1288 */ ULong guest_LR; // Link Register 210 /* 1296 */ ULong guest_CTR; // Count Register 211 212 /* XER pieces */ 213 /* 1304 */ UChar guest_XER_SO; /* in lsb */ 214 /* 1305 */ UChar guest_XER_OV; /* in lsb */ 215 /* 1306 */ UChar guest_XER_CA; /* in lsb */ 216 /* 1307 */ UChar guest_XER_BC; /* all bits */ 217 218 /* CR pieces */ 219 /* 1308 */ UChar guest_CR0_321; /* in [3:1] */ 220 /* 1309 */ UChar guest_CR0_0; /* in lsb */ 221 /* 1310 */ UChar guest_CR1_321; /* in [3:1] */ 222 /* 1311 */ UChar guest_CR1_0; /* in lsb */ 223 /* 1312 */ UChar guest_CR2_321; /* in [3:1] */ 224 /* 1313 */ UChar guest_CR2_0; /* in lsb */ 225 /* 1314 */ UChar guest_CR3_321; /* in [3:1] */ 226 /* 1315 */ UChar guest_CR3_0; /* in lsb */ 227 /* 1316 */ UChar guest_CR4_321; /* in [3:1] */ 228 /* 1317 */ UChar guest_CR4_0; /* in lsb */ 229 /* 1318 */ UChar guest_CR5_321; /* in [3:1] */ 230 /* 1319 */ UChar guest_CR5_0; /* in lsb */ 231 /* 1320 */ UChar guest_CR6_321; /* in [3:1] */ 232 /* 1321 */ UChar guest_CR6_0; /* in lsb */ 233 /* 1322 */ UChar guest_CR7_321; /* in [3:1] */ 234 /* 1323 */ UChar guest_CR7_0; /* in lsb */ 235 236 /* FP Status and Control Register fields. Only rounding mode fields 237 are supported. */ 238 /* 1324 */ UChar guest_FPROUND; // Binary Floating Point Rounding Mode 239 /* 1325 */ UChar guest_DFPROUND; // Decimal Floating Point Rounding Mode 240 /* 1326 */ UChar pad1; 241 /* 1327 */ UChar pad2; 242 243 /* Vector Save/Restore Register */ 244 /* 1328 */ UInt guest_VRSAVE; 245 246 /* Vector Status and Control Register */ 247 /* 1332 */ UInt guest_VSCR; 248 249 /* Emulation warnings */ 250 /* 1336 */ UInt guest_EMWARN; 251 252 /* gcc adds 4 bytes padding here: pre-empt it. */ 253 /* 1340 */ UInt padding; 254 255 /* For icbi: record start and length of area to invalidate */ 256 /* 1344 */ ULong guest_TISTART; 257 /* 1352 */ ULong guest_TILEN; 258 259 /* Used to record the unredirected guest address at the start of 260 a translation whose start has been redirected. By reading 261 this pseudo-register shortly afterwards, the translation can 262 find out what the corresponding no-redirection address was. 263 Note, this is only set for wrap-style redirects, not for 264 replace-style ones. */ 265 /* 1360 */ ULong guest_NRADDR; 266 /* 1368 */ ULong guest_NRADDR_GPR2; 267 268 /* A grows-upwards stack for hidden saves/restores of LR and R2 269 needed for function interception and wrapping on ppc64-linux. 270 A horrible hack. REDIR_SP points to the highest live entry, 271 and so starts at -1. */ 272 /* 1376 */ ULong guest_REDIR_SP; 273 /* 1384 */ ULong guest_REDIR_STACK[VEX_GUEST_PPC64_REDIR_STACK_SIZE]; 274 275 /* Needed for AIX: CIA at the last SC insn. Used when backing up 276 to restart a syscall that has been interrupted by a signal. */ 277 /* 1640 */ ULong guest_IP_AT_SYSCALL; 278 279 /* SPRG3, which AIUI is readonly in user space. Needed for 280 threading on AIX. */ 281 /* 1648 */ ULong guest_SPRG3_RO; 282 283 /* offsets in comments are wrong ..*/ 284 /* Padding to make it have an 16-aligned size */ 285 /* 1656 */ ULong padding2; 286 /* 16XX */ ULong padding3; 287 /* 16XX */ ULong padding4; 288 } 289 VexGuestPPC64State; 290 291 292 /*---------------------------------------------------------------*/ 293 /*--- Utility functions for PPC64 guest stuff. ---*/ 294 /*---------------------------------------------------------------*/ 295 296 /* ALL THE FOLLOWING ARE VISIBLE TO LIBRARY CLIENT */ 297 298 /* Initialise all guest PPC64 state. */ 299 extern 300 void LibVEX_GuestPPC64_initialise ( /*OUT*/VexGuestPPC64State* vex_state ); 301 302 303 /* Write the given native %CR value to the supplied VexGuestPPC64State 304 structure. Note, %CR is 32-bits even for ppc64. */ 305 extern 306 void LibVEX_GuestPPC64_put_CR ( UInt cr_native, 307 /*OUT*/VexGuestPPC64State* vex_state ); 308 309 /* Extract from the supplied VexGuestPPC64State structure the 310 corresponding native %CR value. Note, %CR is 32-bits even for 311 ppc64. */ 312 extern 313 UInt LibVEX_GuestPPC64_get_CR ( /*IN*/VexGuestPPC64State* vex_state ); 314 315 316 /* Write the given native %XER value to the supplied 317 VexGuestPPC64State structure. Note, %XER is 32-bits even for 318 ppc64. */ 319 extern 320 void LibVEX_GuestPPC64_put_XER ( UInt xer_native, 321 /*OUT*/VexGuestPPC64State* vex_state ); 322 323 /* Extract from the supplied VexGuestPPC64State structure the 324 corresponding native %XER value. Note, %CR is 32-bits even for 325 ppc64. */ 326 extern 327 UInt LibVEX_GuestPPC64_get_XER ( /*IN*/VexGuestPPC64State* vex_state ); 328 329 #endif /* ndef __LIBVEX_PUB_GUEST_PPC64_H */ 330 331 332 /*---------------------------------------------------------------*/ 333 /*--- libvex_guest_ppc64.h ---*/ 334 /*---------------------------------------------------------------*/ 335