1 2 /*--------------------------------------------------------------------*/ 3 /*--- begin genoffsets.c ---*/ 4 /*--------------------------------------------------------------------*/ 5 6 /* 7 This file is part of Valgrind, a dynamic binary instrumentation 8 framework. 9 10 Copyright (C) 2004-2015 OpenWorks LLP 11 info (at) 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 #include <stdio.h> 37 38 /* A program which, when compiled to assembly, exposes various guest 39 state offsets. The program isn't executed, since that breaks 40 cross-compilation. 41 42 It does rely on the assumption that 'my_offsetof(Ty,Field)' is 43 folded to a constant at a compile time, which seems a bit dodgy 44 to me. On gcc4 it is possible to use __builtin_offsetof, which 45 sounds safer, but that doesn't exist on older gccs. Oh Well. 46 */ 47 48 #include "../pub/libvex_basictypes.h" 49 #include "../pub/libvex_guest_x86.h" 50 #include "../pub/libvex_guest_amd64.h" 51 #include "../pub/libvex_guest_ppc32.h" 52 #include "../pub/libvex_guest_ppc64.h" 53 #include "../pub/libvex_guest_arm.h" 54 #include "../pub/libvex_guest_arm64.h" 55 #include "../pub/libvex_guest_s390x.h" 56 #include "../pub/libvex_guest_mips32.h" 57 #include "../pub/libvex_guest_mips64.h" 58 #include "../pub/libvex_guest_tilegx.h" 59 60 #define VG_STRINGIFZ(__str) #__str 61 #define VG_STRINGIFY(__str) VG_STRINGIFZ(__str) 62 63 #define my_offsetof(__type,__field) (&((__type*)0)->__field) 64 65 /* This forces gcc to evaluate the my_offsetof call at compile time, 66 and then emits it in the assembly, along with the nonsense string 67 "xyzzy", for easy greppability. Once this file is compiled to 68 assembly, the lines containing "xyzzy" are grepped out and sed-ed 69 to produce the final result. See the Makefile rule for 70 pub/libvex_guest_offsets.h. */ 71 #define GENOFFSET(_structUppercase,_structLowercase,_fieldname) \ 72 __asm__ __volatile__ ( \ 73 "\n#define OFFSET_" \ 74 VG_STRINGIFY(_structLowercase) "_" \ 75 VG_STRINGIFY(_fieldname) \ 76 " xyzzy%0\n" : /*out*/ \ 77 : /*in*/ "n" \ 78 (my_offsetof(VexGuest##_structUppercase##State, \ 79 guest_##_fieldname)) \ 80 ) 81 82 void foo ( void ); 83 __attribute__((noinline)) 84 void foo ( void ) 85 { 86 // x86 87 GENOFFSET(X86,x86,EAX); 88 GENOFFSET(X86,x86,EBX); 89 GENOFFSET(X86,x86,ECX); 90 GENOFFSET(X86,x86,EDX); 91 GENOFFSET(X86,x86,ESI); 92 GENOFFSET(X86,x86,EDI); 93 GENOFFSET(X86,x86,EBP); 94 GENOFFSET(X86,x86,ESP); 95 GENOFFSET(X86,x86,EIP); 96 GENOFFSET(X86,x86,CS); 97 GENOFFSET(X86,x86,DS); 98 GENOFFSET(X86,x86,ES); 99 GENOFFSET(X86,x86,FS); 100 GENOFFSET(X86,x86,GS); 101 GENOFFSET(X86,x86,SS); 102 103 // amd64 104 GENOFFSET(AMD64,amd64,RAX); 105 GENOFFSET(AMD64,amd64,RBX); 106 GENOFFSET(AMD64,amd64,RCX); 107 GENOFFSET(AMD64,amd64,RDX); 108 GENOFFSET(AMD64,amd64,RSI); 109 GENOFFSET(AMD64,amd64,RDI); 110 GENOFFSET(AMD64,amd64,RSP); 111 GENOFFSET(AMD64,amd64,RBP); 112 GENOFFSET(AMD64,amd64,R8); 113 GENOFFSET(AMD64,amd64,R9); 114 GENOFFSET(AMD64,amd64,R10); 115 GENOFFSET(AMD64,amd64,R11); 116 GENOFFSET(AMD64,amd64,R12); 117 GENOFFSET(AMD64,amd64,R13); 118 GENOFFSET(AMD64,amd64,R14); 119 GENOFFSET(AMD64,amd64,R15); 120 GENOFFSET(AMD64,amd64,RIP); 121 122 // ppc32 123 GENOFFSET(PPC32,ppc32,GPR0); 124 GENOFFSET(PPC32,ppc32,GPR1); 125 GENOFFSET(PPC32,ppc32,GPR2); 126 GENOFFSET(PPC32,ppc32,GPR3); 127 GENOFFSET(PPC32,ppc32,GPR4); 128 GENOFFSET(PPC32,ppc32,GPR5); 129 GENOFFSET(PPC32,ppc32,GPR6); 130 GENOFFSET(PPC32,ppc32,GPR7); 131 GENOFFSET(PPC32,ppc32,GPR8); 132 GENOFFSET(PPC32,ppc32,GPR9); 133 GENOFFSET(PPC32,ppc32,GPR10); 134 GENOFFSET(PPC32,ppc32,CIA); 135 GENOFFSET(PPC32,ppc32,CR0_0); 136 137 // ppc64 138 GENOFFSET(PPC64,ppc64,GPR0); 139 GENOFFSET(PPC64,ppc64,GPR1); 140 GENOFFSET(PPC64,ppc64,GPR2); 141 GENOFFSET(PPC64,ppc64,GPR3); 142 GENOFFSET(PPC64,ppc64,GPR4); 143 GENOFFSET(PPC64,ppc64,GPR5); 144 GENOFFSET(PPC64,ppc64,GPR6); 145 GENOFFSET(PPC64,ppc64,GPR7); 146 GENOFFSET(PPC64,ppc64,GPR8); 147 GENOFFSET(PPC64,ppc64,GPR9); 148 GENOFFSET(PPC64,ppc64,GPR10); 149 GENOFFSET(PPC64,ppc64,CIA); 150 GENOFFSET(PPC64,ppc64,CR0_0); 151 152 // arm 153 GENOFFSET(ARM,arm,R0); 154 GENOFFSET(ARM,arm,R1); 155 GENOFFSET(ARM,arm,R2); 156 GENOFFSET(ARM,arm,R3); 157 GENOFFSET(ARM,arm,R4); 158 GENOFFSET(ARM,arm,R5); 159 GENOFFSET(ARM,arm,R7); 160 GENOFFSET(ARM,arm,R13); 161 GENOFFSET(ARM,arm,R14); 162 GENOFFSET(ARM,arm,R15T); 163 164 // arm64 165 GENOFFSET(ARM64,arm64,X0); 166 GENOFFSET(ARM64,arm64,X1); 167 GENOFFSET(ARM64,arm64,X2); 168 GENOFFSET(ARM64,arm64,X3); 169 GENOFFSET(ARM64,arm64,X4); 170 GENOFFSET(ARM64,arm64,X5); 171 GENOFFSET(ARM64,arm64,X6); 172 GENOFFSET(ARM64,arm64,X7); 173 GENOFFSET(ARM64,arm64,X8); 174 GENOFFSET(ARM64,arm64,XSP); 175 GENOFFSET(ARM64,arm64,PC); 176 177 // s390x 178 GENOFFSET(S390X,s390x,r2); 179 GENOFFSET(S390X,s390x,r3); 180 GENOFFSET(S390X,s390x,r4); 181 GENOFFSET(S390X,s390x,r5); 182 GENOFFSET(S390X,s390x,r6); 183 GENOFFSET(S390X,s390x,r7); 184 GENOFFSET(S390X,s390x,r15); 185 GENOFFSET(S390X,s390x,IA); 186 GENOFFSET(S390X,s390x,SYSNO); 187 GENOFFSET(S390X,s390x,IP_AT_SYSCALL); 188 GENOFFSET(S390X,s390x,fpc); 189 GENOFFSET(S390X,s390x,CC_OP); 190 GENOFFSET(S390X,s390x,CC_DEP1); 191 GENOFFSET(S390X,s390x,CC_DEP2); 192 GENOFFSET(S390X,s390x,CC_NDEP); 193 194 // MIPS32 195 GENOFFSET(MIPS32,mips32,r0); 196 GENOFFSET(MIPS32,mips32,r1); 197 GENOFFSET(MIPS32,mips32,r2); 198 GENOFFSET(MIPS32,mips32,r3); 199 GENOFFSET(MIPS32,mips32,r4); 200 GENOFFSET(MIPS32,mips32,r5); 201 GENOFFSET(MIPS32,mips32,r6); 202 GENOFFSET(MIPS32,mips32,r7); 203 GENOFFSET(MIPS32,mips32,r8); 204 GENOFFSET(MIPS32,mips32,r9); 205 GENOFFSET(MIPS32,mips32,r10); 206 GENOFFSET(MIPS32,mips32,r11); 207 GENOFFSET(MIPS32,mips32,r12); 208 GENOFFSET(MIPS32,mips32,r13); 209 GENOFFSET(MIPS32,mips32,r14); 210 GENOFFSET(MIPS32,mips32,r15); 211 GENOFFSET(MIPS32,mips32,r15); 212 GENOFFSET(MIPS32,mips32,r17); 213 GENOFFSET(MIPS32,mips32,r18); 214 GENOFFSET(MIPS32,mips32,r19); 215 GENOFFSET(MIPS32,mips32,r20); 216 GENOFFSET(MIPS32,mips32,r21); 217 GENOFFSET(MIPS32,mips32,r22); 218 GENOFFSET(MIPS32,mips32,r23); 219 GENOFFSET(MIPS32,mips32,r24); 220 GENOFFSET(MIPS32,mips32,r25); 221 GENOFFSET(MIPS32,mips32,r26); 222 GENOFFSET(MIPS32,mips32,r27); 223 GENOFFSET(MIPS32,mips32,r28); 224 GENOFFSET(MIPS32,mips32,r29); 225 GENOFFSET(MIPS32,mips32,r30); 226 GENOFFSET(MIPS32,mips32,r31); 227 GENOFFSET(MIPS32,mips32,PC); 228 GENOFFSET(MIPS32,mips32,HI); 229 GENOFFSET(MIPS32,mips32,LO); 230 231 // MIPS64 232 GENOFFSET(MIPS64,mips64,r0); 233 GENOFFSET(MIPS64,mips64,r1); 234 GENOFFSET(MIPS64,mips64,r2); 235 GENOFFSET(MIPS64,mips64,r3); 236 GENOFFSET(MIPS64,mips64,r4); 237 GENOFFSET(MIPS64,mips64,r5); 238 GENOFFSET(MIPS64,mips64,r6); 239 GENOFFSET(MIPS64,mips64,r7); 240 GENOFFSET(MIPS64,mips64,r8); 241 GENOFFSET(MIPS64,mips64,r9); 242 GENOFFSET(MIPS64,mips64,r10); 243 GENOFFSET(MIPS64,mips64,r11); 244 GENOFFSET(MIPS64,mips64,r12); 245 GENOFFSET(MIPS64,mips64,r13); 246 GENOFFSET(MIPS64,mips64,r14); 247 GENOFFSET(MIPS64,mips64,r15); 248 GENOFFSET(MIPS64,mips64,r15); 249 GENOFFSET(MIPS64,mips64,r17); 250 GENOFFSET(MIPS64,mips64,r18); 251 GENOFFSET(MIPS64,mips64,r19); 252 GENOFFSET(MIPS64,mips64,r20); 253 GENOFFSET(MIPS64,mips64,r21); 254 GENOFFSET(MIPS64,mips64,r22); 255 GENOFFSET(MIPS64,mips64,r23); 256 GENOFFSET(MIPS64,mips64,r24); 257 GENOFFSET(MIPS64,mips64,r25); 258 GENOFFSET(MIPS64,mips64,r26); 259 GENOFFSET(MIPS64,mips64,r27); 260 GENOFFSET(MIPS64,mips64,r28); 261 GENOFFSET(MIPS64,mips64,r29); 262 GENOFFSET(MIPS64,mips64,r30); 263 GENOFFSET(MIPS64,mips64,r31); 264 GENOFFSET(MIPS64,mips64,PC); 265 GENOFFSET(MIPS64,mips64,HI); 266 GENOFFSET(MIPS64,mips64,LO); 267 268 // Tilegx 269 GENOFFSET(TILEGX,tilegx,r0); 270 GENOFFSET(TILEGX,tilegx,r1); 271 GENOFFSET(TILEGX,tilegx,r2); 272 GENOFFSET(TILEGX,tilegx,r3); 273 GENOFFSET(TILEGX,tilegx,r4); 274 GENOFFSET(TILEGX,tilegx,r5); 275 GENOFFSET(TILEGX,tilegx,r6); 276 GENOFFSET(TILEGX,tilegx,r7); 277 GENOFFSET(TILEGX,tilegx,r8); 278 GENOFFSET(TILEGX,tilegx,r9); 279 GENOFFSET(TILEGX,tilegx,r10); 280 GENOFFSET(TILEGX,tilegx,r11); 281 GENOFFSET(TILEGX,tilegx,r12); 282 GENOFFSET(TILEGX,tilegx,r13); 283 GENOFFSET(TILEGX,tilegx,r14); 284 GENOFFSET(TILEGX,tilegx,r15); 285 GENOFFSET(TILEGX,tilegx,r16); 286 GENOFFSET(TILEGX,tilegx,r17); 287 GENOFFSET(TILEGX,tilegx,r18); 288 GENOFFSET(TILEGX,tilegx,r19); 289 GENOFFSET(TILEGX,tilegx,r20); 290 GENOFFSET(TILEGX,tilegx,r21); 291 GENOFFSET(TILEGX,tilegx,r22); 292 GENOFFSET(TILEGX,tilegx,r23); 293 GENOFFSET(TILEGX,tilegx,r24); 294 GENOFFSET(TILEGX,tilegx,r25); 295 GENOFFSET(TILEGX,tilegx,r26); 296 GENOFFSET(TILEGX,tilegx,r27); 297 GENOFFSET(TILEGX,tilegx,r28); 298 GENOFFSET(TILEGX,tilegx,r29); 299 GENOFFSET(TILEGX,tilegx,r30); 300 GENOFFSET(TILEGX,tilegx,r31); 301 GENOFFSET(TILEGX,tilegx,r32); 302 GENOFFSET(TILEGX,tilegx,r33); 303 GENOFFSET(TILEGX,tilegx,r34); 304 GENOFFSET(TILEGX,tilegx,r35); 305 GENOFFSET(TILEGX,tilegx,r36); 306 GENOFFSET(TILEGX,tilegx,r37); 307 GENOFFSET(TILEGX,tilegx,r38); 308 GENOFFSET(TILEGX,tilegx,r39); 309 GENOFFSET(TILEGX,tilegx,r40); 310 GENOFFSET(TILEGX,tilegx,r41); 311 GENOFFSET(TILEGX,tilegx,r42); 312 GENOFFSET(TILEGX,tilegx,r43); 313 GENOFFSET(TILEGX,tilegx,r44); 314 GENOFFSET(TILEGX,tilegx,r45); 315 GENOFFSET(TILEGX,tilegx,r46); 316 GENOFFSET(TILEGX,tilegx,r47); 317 GENOFFSET(TILEGX,tilegx,r48); 318 GENOFFSET(TILEGX,tilegx,r49); 319 GENOFFSET(TILEGX,tilegx,r50); 320 GENOFFSET(TILEGX,tilegx,r51); 321 GENOFFSET(TILEGX,tilegx,r52); 322 GENOFFSET(TILEGX,tilegx,r53); 323 GENOFFSET(TILEGX,tilegx,r54); 324 GENOFFSET(TILEGX,tilegx,r55); 325 GENOFFSET(TILEGX,tilegx,pc); 326 GENOFFSET(TILEGX,tilegx,EMNOTE); 327 GENOFFSET(TILEGX,tilegx,CMSTART); 328 GENOFFSET(TILEGX,tilegx,NRADDR); 329 } 330 331 /*--------------------------------------------------------------------*/ 332 /*--- end genoffsets.c ---*/ 333 /*--------------------------------------------------------------------*/ 334