blob: d90b7d3bde462f5d0023b232e8571ae173c1ca62 [file] [log] [blame]
cerion896a1372005-01-25 12:24:25 +00001
2/*---------------------------------------------------------------*/
sewardj752f9062010-05-03 21:38:49 +00003/*--- begin libvex_guest_ppc32.h ---*/
cerion896a1372005-01-25 12:24:25 +00004/*---------------------------------------------------------------*/
5
6/*
sewardj752f9062010-05-03 21:38:49 +00007 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
cerion896a1372005-01-25 12:24:25 +00009
sewardj25e54732012-08-05 15:36:51 +000010 Copyright (C) 2004-2012 OpenWorks LLP
sewardj752f9062010-05-03 21:38:49 +000011 info@open-works.net
cerion896a1372005-01-25 12:24:25 +000012
sewardj752f9062010-05-03 21:38:49 +000013 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.
cerion896a1372005-01-25 12:24:25 +000017
sewardj752f9062010-05-03 21:38:49 +000018 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
sewardj7bd6ffe2005-08-03 16:07:36 +000026 02110-1301, USA.
27
sewardj752f9062010-05-03 21:38:49 +000028 The GNU General Public License is contained in the file COPYING.
cerion896a1372005-01-25 12:24:25 +000029
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.
cerion896a1372005-01-25 12:24:25 +000034*/
35
cerion1515db92005-01-25 17:21:23 +000036#ifndef __LIBVEX_PUB_GUEST_PPC32_H
37#define __LIBVEX_PUB_GUEST_PPC32_H
cerion896a1372005-01-25 12:24:25 +000038
39#include "libvex_basictypes.h"
cerion896a1372005-01-25 12:24:25 +000040
41
42/*---------------------------------------------------------------*/
cerion1515db92005-01-25 17:21:23 +000043/*--- Vex's representation of the PPC32 CPU state ---*/
cerion896a1372005-01-25 12:24:25 +000044/*---------------------------------------------------------------*/
45
sewardjaca070a2006-10-17 00:28:22 +000046#define VEX_GUEST_PPC32_REDIR_STACK_SIZE (16/*entries*/ * 2/*words per entry*/)
47
cerion896a1372005-01-25 12:24:25 +000048typedef
49 struct {
sewardj3dee8492012-04-20 00:13:28 +000050 /* Event check fail addr and counter. */
51 /* 0 */ UInt host_EvC_FAILADDR;
52 /* 4 */ UInt host_EvC_COUNTER;
53 /* 8 */ UInt pad3;
54 /* 12 */ UInt pad4;
55 /* Add 16 to all the numbers below. Sigh. */
cerion4e9083c2005-03-03 05:29:17 +000056 /* General Purpose Registers */
57 /* 0 */ UInt guest_GPR0;
58 /* 4 */ UInt guest_GPR1;
59 /* 8 */ UInt guest_GPR2;
60 /* 12 */ UInt guest_GPR3;
61 /* 16 */ UInt guest_GPR4;
62 /* 20 */ UInt guest_GPR5;
63 /* 24 */ UInt guest_GPR6;
64 /* 28 */ UInt guest_GPR7;
65 /* 32 */ UInt guest_GPR8;
66 /* 36 */ UInt guest_GPR9;
67 /* 40 */ UInt guest_GPR10;
68 /* 44 */ UInt guest_GPR11;
69 /* 48 */ UInt guest_GPR12;
70 /* 52 */ UInt guest_GPR13;
71 /* 56 */ UInt guest_GPR14;
72 /* 60 */ UInt guest_GPR15;
73 /* 64 */ UInt guest_GPR16;
74 /* 68 */ UInt guest_GPR17;
75 /* 72 */ UInt guest_GPR18;
76 /* 76 */ UInt guest_GPR19;
77 /* 80 */ UInt guest_GPR20;
78 /* 84 */ UInt guest_GPR21;
79 /* 88 */ UInt guest_GPR22;
80 /* 92 */ UInt guest_GPR23;
81 /* 96 */ UInt guest_GPR24;
82 /* 100 */ UInt guest_GPR25;
83 /* 104 */ UInt guest_GPR26;
84 /* 108 */ UInt guest_GPR27;
85 /* 112 */ UInt guest_GPR28;
86 /* 116 */ UInt guest_GPR29;
87 /* 120 */ UInt guest_GPR30;
88 /* 124 */ UInt guest_GPR31;
cerion896a1372005-01-25 12:24:25 +000089
sewardj66d5ef22011-04-15 11:55:00 +000090 // Vector Registers, Floating Point Registers, and VSX Registers
91 // With ISA 2.06, the "Vector-Scalar Floating-point" category
92 // provides facilities to support vector and scalar binary floating-
93 // point operations. A unified register file is an integral part
94 // of this new facility, combining floating point and vector registers
95 // using a 64x128-bit vector. These are referred to as VSR[0..63].
96 // The floating point registers are now mapped into double word element 0
97 // of VSR[0..31]. The 32x128-bit vector registers defined by the "Vector
98 // Facility [Category: Vector]" are now mapped to VSR[32..63].
cerion98d105a2005-02-04 16:13:58 +000099
sewardj478646f2008-05-01 20:13:04 +0000100 // IMPORTANT: the user of libvex must place the guest state so as
sewardj66d5ef22011-04-15 11:55:00 +0000101 // to ensure that guest_VSR{0..63}, and any shadows thereof, are
sewardj478646f2008-05-01 20:13:04 +0000102 // 16-aligned.
cerion6529aff2005-06-28 17:30:56 +0000103
sewardj66d5ef22011-04-15 11:55:00 +0000104 /* 128 */ U128 guest_VSR0;
105 /* 144 */ U128 guest_VSR1;
106 /* 160 */ U128 guest_VSR2;
107 /* 176 */ U128 guest_VSR3;
108 /* 192 */ U128 guest_VSR4;
109 /* 208 */ U128 guest_VSR5;
110 /* 224 */ U128 guest_VSR6;
111 /* 240 */ U128 guest_VSR7;
112 /* 256 */ U128 guest_VSR8;
113 /* 272 */ U128 guest_VSR9;
114 /* 288 */ U128 guest_VSR10;
115 /* 304 */ U128 guest_VSR11;
116 /* 320 */ U128 guest_VSR12;
117 /* 336 */ U128 guest_VSR13;
118 /* 352 */ U128 guest_VSR14;
119 /* 368 */ U128 guest_VSR15;
120 /* 384 */ U128 guest_VSR16;
121 /* 400 */ U128 guest_VSR17;
122 /* 416 */ U128 guest_VSR18;
123 /* 432 */ U128 guest_VSR19;
124 /* 448 */ U128 guest_VSR20;
125 /* 464 */ U128 guest_VSR21;
126 /* 480 */ U128 guest_VSR22;
127 /* 496 */ U128 guest_VSR23;
128 /* 512 */ U128 guest_VSR24;
129 /* 528 */ U128 guest_VSR25;
130 /* 544 */ U128 guest_VSR26;
131 /* 560 */ U128 guest_VSR27;
132 /* 576 */ U128 guest_VSR28;
133 /* 592 */ U128 guest_VSR29;
134 /* 608 */ U128 guest_VSR30;
135 /* 624 */ U128 guest_VSR31;
136 /* 640 */ U128 guest_VSR32;
137 /* 656 */ U128 guest_VSR33;
138 /* 672 */ U128 guest_VSR34;
139 /* 688 */ U128 guest_VSR35;
140 /* 704 */ U128 guest_VSR36;
141 /* 720 */ U128 guest_VSR37;
142 /* 736 */ U128 guest_VSR38;
143 /* 752 */ U128 guest_VSR39;
144 /* 768 */ U128 guest_VSR40;
145 /* 784 */ U128 guest_VSR41;
146 /* 800 */ U128 guest_VSR42;
147 /* 816 */ U128 guest_VSR43;
148 /* 832 */ U128 guest_VSR44;
149 /* 848 */ U128 guest_VSR45;
150 /* 864 */ U128 guest_VSR46;
151 /* 880 */ U128 guest_VSR47;
152 /* 896 */ U128 guest_VSR48;
153 /* 912 */ U128 guest_VSR49;
154 /* 928 */ U128 guest_VSR50;
155 /* 944 */ U128 guest_VSR51;
156 /* 960 */ U128 guest_VSR52;
157 /* 976 */ U128 guest_VSR53;
158 /* 992 */ U128 guest_VSR54;
159 /* 1008 */ U128 guest_VSR55;
160 /* 1024 */ U128 guest_VSR56;
161 /* 1040 */ U128 guest_VSR57;
162 /* 1056 */ U128 guest_VSR58;
163 /* 1072 */ U128 guest_VSR59;
164 /* 1088 */ U128 guest_VSR60;
165 /* 1104 */ U128 guest_VSR61;
166 /* 1120 */ U128 guest_VSR62;
167 /* 1136 */ U128 guest_VSR63;
168
169 /* 1152 */ UInt guest_CIA; // IP (no arch visible register)
170 /* 1156 */ UInt guest_LR; // Link Register
171 /* 1160 */ UInt guest_CTR; // Count Register
cerion896a1372005-01-25 12:24:25 +0000172
sewardjb51f0f42005-07-18 11:38:02 +0000173 /* XER pieces */
sewardj66d5ef22011-04-15 11:55:00 +0000174 /* 1164 */ UChar guest_XER_SO; /* in lsb */
175 /* 1165 */ UChar guest_XER_OV; /* in lsb */
176 /* 1166 */ UChar guest_XER_CA; /* in lsb */
177 /* 1167 */ UChar guest_XER_BC; /* all bits */
cerion896a1372005-01-25 12:24:25 +0000178
sewardjb51f0f42005-07-18 11:38:02 +0000179 /* CR pieces */
sewardj66d5ef22011-04-15 11:55:00 +0000180 /* 1168 */ UChar guest_CR0_321; /* in [3:1] */
181 /* 1169 */ UChar guest_CR0_0; /* in lsb */
182 /* 1170 */ UChar guest_CR1_321; /* in [3:1] */
183 /* 1171 */ UChar guest_CR1_0; /* in lsb */
184 /* 1172 */ UChar guest_CR2_321; /* in [3:1] */
185 /* 1173 */ UChar guest_CR2_0; /* in lsb */
186 /* 1174 */ UChar guest_CR3_321; /* in [3:1] */
187 /* 1175 */ UChar guest_CR3_0; /* in lsb */
188 /* 1176 */ UChar guest_CR4_321; /* in [3:1] */
189 /* 1177 */ UChar guest_CR4_0; /* in lsb */
190 /* 1178 */ UChar guest_CR5_321; /* in [3:1] */
191 /* 1179 */ UChar guest_CR5_0; /* in lsb */
192 /* 1180 */ UChar guest_CR6_321; /* in [3:1] */
193 /* 1181 */ UChar guest_CR6_0; /* in lsb */
194 /* 1182 */ UChar guest_CR7_321; /* in [3:1] */
195 /* 1183 */ UChar guest_CR7_0; /* in lsb */
cerione77ce012005-01-25 16:56:18 +0000196
sewardjc6bbd472012-04-02 10:20:48 +0000197 /* FP Status & Control Register fields. Only rounding mode fields are supported. */
198 /* 1184 */ UChar guest_FPROUND; // Binary Floating Point Rounding Mode
199 /* 1185 */ UChar guest_DFPROUND; // Decimal Floating Point Rounding Mode
200 /* 1186 */ UChar pad1;
201 /* 1187 */ UChar pad2;
cerion6529aff2005-06-28 17:30:56 +0000202
203 /* Vector Save/Restore Register */
sewardj66d5ef22011-04-15 11:55:00 +0000204 /* 1188 */ UInt guest_VRSAVE;
cerion6529aff2005-06-28 17:30:56 +0000205
206 /* Vector Status and Control Register */
sewardj66d5ef22011-04-15 11:55:00 +0000207 /* 1192 */ UInt guest_VSCR;
cerion896a1372005-01-25 12:24:25 +0000208
florian6ef84be2012-08-26 03:20:07 +0000209 /* Emulation notes */
210 /* 1196 */ UInt guest_EMNOTE;
cerion896a1372005-01-25 12:24:25 +0000211
sewardjce02aa72006-01-12 12:27:58 +0000212 /* For icbi: record start and length of area to invalidate */
sewardj66d5ef22011-04-15 11:55:00 +0000213 /* 1200 */ UInt guest_TISTART;
214 /* 1204 */ UInt guest_TILEN;
sewardjce02aa72006-01-12 12:27:58 +0000215
216 /* Used to record the unredirected guest address at the start of
217 a translation whose start has been redirected. By reading
218 this pseudo-register shortly afterwards, the translation can
219 find out what the corresponding no-redirection address was.
220 Note, this is only set for wrap-style redirects, not for
221 replace-style ones. */
sewardj66d5ef22011-04-15 11:55:00 +0000222 /* 1208 */ UInt guest_NRADDR;
223 /* 1212 */ UInt guest_NRADDR_GPR2; /* needed by aix */
sewardjaca070a2006-10-17 00:28:22 +0000224
225 /* A grows-upwards stack for hidden saves/restores of LR and R2
226 needed for function interception and wrapping on ppc32-aix5.
227 A horrible hack. REDIR_SP points to the highest live entry,
228 and so starts at -1. */
sewardj66d5ef22011-04-15 11:55:00 +0000229 /* 1216 */ UInt guest_REDIR_SP;
230 /* 1220 */ UInt guest_REDIR_STACK[VEX_GUEST_PPC32_REDIR_STACK_SIZE];
sewardjaca070a2006-10-17 00:28:22 +0000231
sewardje86310f2009-03-19 22:21:40 +0000232 /* Needed for AIX (but mandated for all guest architectures):
233 CIA at the last SC insn. Used when backing up to restart a
234 syscall that has been interrupted by a signal. */
sewardj66d5ef22011-04-15 11:55:00 +0000235 /* 1348 */ UInt guest_IP_AT_SYSCALL;
sewardjaca070a2006-10-17 00:28:22 +0000236
237 /* SPRG3, which AIUI is readonly in user space. Needed for
238 threading on AIX. */
sewardj66d5ef22011-04-15 11:55:00 +0000239 /* 1352 */ UInt guest_SPRG3_RO;
sewardj7787af42005-08-04 18:32:19 +0000240
cerion896a1372005-01-25 12:24:25 +0000241 /* Padding to make it have an 8-aligned size */
sewardj66d5ef22011-04-15 11:55:00 +0000242 /* 1356 */ UInt padding;
cerion896a1372005-01-25 12:24:25 +0000243 }
cerion1515db92005-01-25 17:21:23 +0000244 VexGuestPPC32State;
cerion896a1372005-01-25 12:24:25 +0000245
246
247/*---------------------------------------------------------------*/
cerion1515db92005-01-25 17:21:23 +0000248/*--- Utility functions for PPC32 guest stuff. ---*/
cerion896a1372005-01-25 12:24:25 +0000249/*---------------------------------------------------------------*/
250
251/* ALL THE FOLLOWING ARE VISIBLE TO LIBRARY CLIENT */
252
cerion1515db92005-01-25 17:21:23 +0000253/* Initialise all guest PPC32 state. */
cerion896a1372005-01-25 12:24:25 +0000254
255extern
cerion1515db92005-01-25 17:21:23 +0000256void LibVEX_GuestPPC32_initialise ( /*OUT*/VexGuestPPC32State* vex_state );
cerion896a1372005-01-25 12:24:25 +0000257
cerion900f6b52005-07-08 13:34:47 +0000258
sewardjb51f0f42005-07-18 11:38:02 +0000259/* Write the given native %CR value to the supplied VexGuestPPC32State
260 structure. */
cerion900f6b52005-07-08 13:34:47 +0000261extern
sewardjb51f0f42005-07-18 11:38:02 +0000262void LibVEX_GuestPPC32_put_CR ( UInt cr_native,
cerion900f6b52005-07-08 13:34:47 +0000263 /*OUT*/VexGuestPPC32State* vex_state );
264
cerioned623db2005-06-20 12:42:04 +0000265/* Extract from the supplied VexGuestPPC32State structure the
sewardjb51f0f42005-07-18 11:38:02 +0000266 corresponding native %CR value. */
cerion896a1372005-01-25 12:24:25 +0000267extern
florianefa834a2012-11-24 21:07:14 +0000268UInt LibVEX_GuestPPC32_get_CR ( /*IN*/const VexGuestPPC32State* vex_state );
cerion896a1372005-01-25 12:24:25 +0000269
sewardjb51f0f42005-07-18 11:38:02 +0000270
271/* Write the given native %XER value to the supplied VexGuestPPC32State
272 structure. */
cerion51900a22005-07-08 13:10:35 +0000273extern
sewardjb51f0f42005-07-18 11:38:02 +0000274void LibVEX_GuestPPC32_put_XER ( UInt xer_native,
275 /*OUT*/VexGuestPPC32State* vex_state );
276
277/* Extract from the supplied VexGuestPPC32State structure the
278 corresponding native %XER value. */
279extern
florianefa834a2012-11-24 21:07:14 +0000280UInt LibVEX_GuestPPC32_get_XER ( /*IN*/const VexGuestPPC32State* vex_state );
cerion896a1372005-01-25 12:24:25 +0000281
cerion1515db92005-01-25 17:21:23 +0000282#endif /* ndef __LIBVEX_PUB_GUEST_PPC32_H */
cerion896a1372005-01-25 12:24:25 +0000283
284
285/*---------------------------------------------------------------*/
cerion1515db92005-01-25 17:21:23 +0000286/*--- libvex_guest_ppc32.h ---*/
cerion896a1372005-01-25 12:24:25 +0000287/*---------------------------------------------------------------*/