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