2 /*--------------------------------------------------------------------*/
3 /*--- begin genoffsets.c ---*/
4 /*--------------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright (C) 2004-2010 OpenWorks LLP
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.
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.
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
28 The GNU General Public License is contained in the file COPYING.
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.
38 /* A program which, when compiled to assembly, exposes various guest
39 state offsets. The program isn't executed, since that breaks
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.
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"
55 #define VG_STRINGIFZ(__str) #__str
56 #define VG_STRINGIFY(__str) VG_STRINGIFZ(__str)
58 #define my_offsetof(__type,__field) (&((__type*)0)->__field)
60 /* This forces gcc to evaluate the my_offsetof call at compile time,
61 and then emits it in the assembly, along with the nonsense string
62 "xyzzy", for easy greppability. Once this file is compiled to
63 assembly, the lines containing "xyzzy" are grepped out and sed-ed
64 to produce the final result. See the Makefile rule for
65 pub/libvex_guest_offsets.h. */
66 #define GENOFFSET(_structUppercase,_structLowercase,_fieldname) \
67 __asm__ __volatile__ ( \
69 VG_STRINGIFY(_structLowercase) "_" \
70 VG_STRINGIFY(_fieldname) \
71 " xyzzy%0\n" : /*out*/ \
73 (my_offsetof(VexGuest##_structUppercase##State, \
74 guest_##_fieldname)) \
78 __attribute__((noinline))
82 GENOFFSET(X86,x86,EAX);
83 GENOFFSET(X86,x86,EBX);
84 GENOFFSET(X86,x86,ECX);
85 GENOFFSET(X86,x86,EDX);
86 GENOFFSET(X86,x86,ESI);
87 GENOFFSET(X86,x86,EDI);
88 GENOFFSET(X86,x86,EBP);
89 GENOFFSET(X86,x86,ESP);
90 GENOFFSET(X86,x86,EIP);
91 GENOFFSET(X86,x86,CS);
92 GENOFFSET(X86,x86,DS);
93 GENOFFSET(X86,x86,ES);
94 GENOFFSET(X86,x86,FS);
95 GENOFFSET(X86,x86,GS);
96 GENOFFSET(X86,x86,SS);
99 GENOFFSET(AMD64,amd64,RAX);
100 GENOFFSET(AMD64,amd64,RBX);
101 GENOFFSET(AMD64,amd64,RCX);
102 GENOFFSET(AMD64,amd64,RDX);
103 GENOFFSET(AMD64,amd64,RSI);
104 GENOFFSET(AMD64,amd64,RDI);
105 GENOFFSET(AMD64,amd64,RSP);
106 GENOFFSET(AMD64,amd64,RBP);
107 GENOFFSET(AMD64,amd64,R8);
108 GENOFFSET(AMD64,amd64,R9);
109 GENOFFSET(AMD64,amd64,R10);
110 GENOFFSET(AMD64,amd64,R11);
111 GENOFFSET(AMD64,amd64,R12);
112 GENOFFSET(AMD64,amd64,R13);
113 GENOFFSET(AMD64,amd64,R14);
114 GENOFFSET(AMD64,amd64,R15);
115 GENOFFSET(AMD64,amd64,RIP);
118 GENOFFSET(PPC32,ppc32,GPR0);
119 GENOFFSET(PPC32,ppc32,GPR1);
120 GENOFFSET(PPC32,ppc32,GPR2);
121 GENOFFSET(PPC32,ppc32,GPR3);
122 GENOFFSET(PPC32,ppc32,GPR4);
123 GENOFFSET(PPC32,ppc32,GPR5);
124 GENOFFSET(PPC32,ppc32,GPR6);
125 GENOFFSET(PPC32,ppc32,GPR7);
126 GENOFFSET(PPC32,ppc32,GPR8);
127 GENOFFSET(PPC32,ppc32,GPR9);
128 GENOFFSET(PPC32,ppc32,GPR10);
129 GENOFFSET(PPC32,ppc32,CIA);
130 GENOFFSET(PPC32,ppc32,CR0_0);
133 GENOFFSET(PPC64,ppc64,GPR0);
134 GENOFFSET(PPC64,ppc64,GPR1);
135 GENOFFSET(PPC64,ppc64,GPR2);
136 GENOFFSET(PPC64,ppc64,GPR3);
137 GENOFFSET(PPC64,ppc64,GPR4);
138 GENOFFSET(PPC64,ppc64,GPR5);
139 GENOFFSET(PPC64,ppc64,GPR6);
140 GENOFFSET(PPC64,ppc64,GPR7);
141 GENOFFSET(PPC64,ppc64,GPR8);
142 GENOFFSET(PPC64,ppc64,GPR9);
143 GENOFFSET(PPC64,ppc64,GPR10);
144 GENOFFSET(PPC64,ppc64,CIA);
145 GENOFFSET(PPC64,ppc64,CR0_0);
148 GENOFFSET(ARM,arm,R0);
149 GENOFFSET(ARM,arm,R1);
150 GENOFFSET(ARM,arm,R2);
151 GENOFFSET(ARM,arm,R3);
152 GENOFFSET(ARM,arm,R4);
153 GENOFFSET(ARM,arm,R5);
154 GENOFFSET(ARM,arm,R7);
155 GENOFFSET(ARM,arm,R13);
156 GENOFFSET(ARM,arm,R14);
157 GENOFFSET(ARM,arm,R15);
160 /*--------------------------------------------------------------------*/
161 /*--- end genoffsets.c ---*/
162 /*--------------------------------------------------------------------*/