• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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-2011 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       // Vector Registers, Floating Point Registers, and VSX Registers
86       // With ISA 2.06, the "Vector-Scalar Floating-point" category
87       // provides facilities to support vector and scalar binary floating-
88       // point operations.  A unified register file is an integral part
89       // of this new facility, combining floating point and vector registers
90       // using a 64x128-bit vector.  These are referred to as VSR[0..63].
91       // The floating point registers are now mapped into double word element 0
92       // of VSR[0..31]. The 32x128-bit vector registers defined by the "Vector
93       // Facility [Category: Vector]" are now mapped to VSR[32..63].
94 
95       // IMPORTANT: the user of libvex must place the guest state so as
96       // to ensure that guest_VSR{0..63}, and any shadows thereof, are
97       // 16-aligned.
98 
99       /*  128 */ U128 guest_VSR0;
100       /*  144 */ U128 guest_VSR1;
101       /*  160 */ U128 guest_VSR2;
102       /*  176 */ U128 guest_VSR3;
103       /*  192 */ U128 guest_VSR4;
104       /*  208 */ U128 guest_VSR5;
105       /*  224 */ U128 guest_VSR6;
106       /*  240 */ U128 guest_VSR7;
107       /*  256 */ U128 guest_VSR8;
108       /*  272 */ U128 guest_VSR9;
109       /*  288 */ U128 guest_VSR10;
110       /*  304 */ U128 guest_VSR11;
111       /*  320 */ U128 guest_VSR12;
112       /*  336 */ U128 guest_VSR13;
113       /*  352 */ U128 guest_VSR14;
114       /*  368 */ U128 guest_VSR15;
115       /*  384 */ U128 guest_VSR16;
116       /*  400 */ U128 guest_VSR17;
117       /*  416 */ U128 guest_VSR18;
118       /*  432 */ U128 guest_VSR19;
119       /*  448 */ U128 guest_VSR20;
120       /*  464 */ U128 guest_VSR21;
121       /*  480 */ U128 guest_VSR22;
122       /*  496 */ U128 guest_VSR23;
123       /*  512 */ U128 guest_VSR24;
124       /*  528 */ U128 guest_VSR25;
125       /*  544 */ U128 guest_VSR26;
126       /*  560 */ U128 guest_VSR27;
127       /*  576 */ U128 guest_VSR28;
128       /*  592 */ U128 guest_VSR29;
129       /*  608 */ U128 guest_VSR30;
130       /*  624 */ U128 guest_VSR31;
131       /*  640 */ U128 guest_VSR32;
132       /*  656 */ U128 guest_VSR33;
133       /*  672 */ U128 guest_VSR34;
134       /*  688 */ U128 guest_VSR35;
135       /*  704 */ U128 guest_VSR36;
136       /*  720 */ U128 guest_VSR37;
137       /*  736 */ U128 guest_VSR38;
138       /*  752 */ U128 guest_VSR39;
139       /*  768 */ U128 guest_VSR40;
140       /*  784 */ U128 guest_VSR41;
141       /*  800 */ U128 guest_VSR42;
142       /*  816 */ U128 guest_VSR43;
143       /*  832 */ U128 guest_VSR44;
144       /*  848 */ U128 guest_VSR45;
145       /*  864 */ U128 guest_VSR46;
146       /*  880 */ U128 guest_VSR47;
147       /*  896 */ U128 guest_VSR48;
148       /*  912 */ U128 guest_VSR49;
149       /*  928 */ U128 guest_VSR50;
150       /*  944 */ U128 guest_VSR51;
151       /*  960 */ U128 guest_VSR52;
152       /*  976 */ U128 guest_VSR53;
153       /*  992 */ U128 guest_VSR54;
154       /* 1008 */ U128 guest_VSR55;
155       /* 1024 */ U128 guest_VSR56;
156       /* 1040 */ U128 guest_VSR57;
157       /* 1056 */ U128 guest_VSR58;
158       /* 1072 */ U128 guest_VSR59;
159       /* 1088 */ U128 guest_VSR60;
160       /* 1104 */ U128 guest_VSR61;
161       /* 1120 */ U128 guest_VSR62;
162       /* 1136 */ U128 guest_VSR63;
163 
164       /* 1152 */ UInt guest_CIA;    // IP (no arch visible register)
165       /* 1156 */ UInt guest_LR;     // Link Register
166       /* 1160 */ UInt guest_CTR;    // Count Register
167 
168       /* XER pieces */
169       /* 1164 */ UChar guest_XER_SO; /* in lsb */
170       /* 1165 */ UChar guest_XER_OV; /* in lsb */
171       /* 1166 */ UChar guest_XER_CA; /* in lsb */
172       /* 1167 */ UChar guest_XER_BC; /* all bits */
173 
174       /* CR pieces */
175       /* 1168 */ UChar guest_CR0_321; /* in [3:1] */
176       /* 1169 */ UChar guest_CR0_0;   /* in lsb */
177       /* 1170 */ UChar guest_CR1_321; /* in [3:1] */
178       /* 1171 */ UChar guest_CR1_0;   /* in lsb */
179       /* 1172 */ UChar guest_CR2_321; /* in [3:1] */
180       /* 1173 */ UChar guest_CR2_0;   /* in lsb */
181       /* 1174 */ UChar guest_CR3_321; /* in [3:1] */
182       /* 1175 */ UChar guest_CR3_0;   /* in lsb */
183       /* 1176 */ UChar guest_CR4_321; /* in [3:1] */
184       /* 1177 */ UChar guest_CR4_0;   /* in lsb */
185       /* 1178 */ UChar guest_CR5_321; /* in [3:1] */
186       /* 1179 */ UChar guest_CR5_0;   /* in lsb */
187       /* 1180 */ UChar guest_CR6_321; /* in [3:1] */
188       /* 1181 */ UChar guest_CR6_0;   /* in lsb */
189       /* 1182 */ UChar guest_CR7_321; /* in [3:1] */
190       /* 1183 */ UChar guest_CR7_0;   /* in lsb */
191 
192       /* FP Status & Control Register fields */
193       /* 1184 */ UInt guest_FPROUND; // FP Rounding Mode
194 
195       /* Vector Save/Restore Register */
196       /* 1188 */ UInt guest_VRSAVE;
197 
198       /* Vector Status and Control Register */
199       /* 1192 */ UInt guest_VSCR;
200 
201       /* Emulation warnings */
202       /* 1196 */ UInt guest_EMWARN;
203 
204       /* For icbi: record start and length of area to invalidate */
205       /* 1200 */ UInt guest_TISTART;
206       /* 1204 */ UInt guest_TILEN;
207 
208       /* Used to record the unredirected guest address at the start of
209          a translation whose start has been redirected.  By reading
210          this pseudo-register shortly afterwards, the translation can
211          find out what the corresponding no-redirection address was.
212          Note, this is only set for wrap-style redirects, not for
213          replace-style ones. */
214       /* 1208 */ UInt guest_NRADDR;
215       /* 1212 */ UInt guest_NRADDR_GPR2; /* needed by aix */
216 
217      /* A grows-upwards stack for hidden saves/restores of LR and R2
218         needed for function interception and wrapping on ppc32-aix5.
219         A horrible hack.  REDIR_SP points to the highest live entry,
220         and so starts at -1. */
221       /* 1216 */ UInt guest_REDIR_SP;
222       /* 1220 */ UInt guest_REDIR_STACK[VEX_GUEST_PPC32_REDIR_STACK_SIZE];
223 
224       /* Needed for AIX (but mandated for all guest architectures):
225          CIA at the last SC insn.  Used when backing up to restart a
226          syscall that has been interrupted by a signal. */
227       /* 1348 */ UInt guest_IP_AT_SYSCALL;
228 
229       /* SPRG3, which AIUI is readonly in user space.  Needed for
230          threading on AIX. */
231       /* 1352 */ UInt guest_SPRG3_RO;
232 
233       /* Padding to make it have an 8-aligned size */
234       /* 1356 */ UInt  padding;
235    }
236    VexGuestPPC32State;
237 
238 
239 /*---------------------------------------------------------------*/
240 /*--- Utility functions for PPC32 guest stuff.                ---*/
241 /*---------------------------------------------------------------*/
242 
243 /* ALL THE FOLLOWING ARE VISIBLE TO LIBRARY CLIENT */
244 
245 /* Initialise all guest PPC32 state. */
246 
247 extern
248 void LibVEX_GuestPPC32_initialise ( /*OUT*/VexGuestPPC32State* vex_state );
249 
250 
251 /* Write the given native %CR value to the supplied VexGuestPPC32State
252    structure. */
253 extern
254 void LibVEX_GuestPPC32_put_CR ( UInt cr_native,
255                                 /*OUT*/VexGuestPPC32State* vex_state );
256 
257 /* Extract from the supplied VexGuestPPC32State structure the
258    corresponding native %CR value. */
259 extern
260 UInt LibVEX_GuestPPC32_get_CR ( /*IN*/VexGuestPPC32State* vex_state );
261 
262 
263 /* Write the given native %XER value to the supplied VexGuestPPC32State
264    structure. */
265 extern
266 void LibVEX_GuestPPC32_put_XER ( UInt xer_native,
267                                  /*OUT*/VexGuestPPC32State* vex_state );
268 
269 /* Extract from the supplied VexGuestPPC32State structure the
270    corresponding native %XER value. */
271 extern
272 UInt LibVEX_GuestPPC32_get_XER ( /*IN*/VexGuestPPC32State* vex_state );
273 
274 #endif /* ndef __LIBVEX_PUB_GUEST_PPC32_H */
275 
276 
277 /*---------------------------------------------------------------*/
278 /*---                                    libvex_guest_ppc32.h ---*/
279 /*---------------------------------------------------------------*/
280