Home | History | Annotate | Download | only in pub
      1 
      2 /*---------------------------------------------------------------*/
      3 /*--- begin                              libvex_guest_ppc64.h ---*/
      4 /*---------------------------------------------------------------*/
      5 
      6 /*
      7    This file is part of Valgrind, a dynamic binary instrumentation
      8    framework.
      9 
     10    Copyright (C) 2004-2010 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_PPC64_H
     37 #define __LIBVEX_PUB_GUEST_PPC64_H
     38 
     39 #include "libvex_basictypes.h"
     40 #include "libvex_emwarn.h"
     41 
     42 /*
     43     volatile ==  caller-saved (not preserved across function calls)
     44 non-volatile ==  callee-saved (preserved across function calls)
     45 
     46 r0        Volatile register used in function prologs
     47 r1        Stack frame pointer
     48 r2        TOC pointer
     49 r3        Volatile parameter and return value register
     50 r4-r10    Volatile registers used for function parameters
     51 r11       Volatile register used in calls by pointer and as an
     52           environment pointer for languages which require one
     53 r12       Volatile register used for exception handling and glink code
     54 r13       Reserved for use as system thread ID
     55 r14-r31   Nonvolatile registers used for local variables
     56 
     57 f0        Volatile scratch register
     58 f1-f4     Volatile floating point parameter and return value registers
     59 f5-f13    Volatile floating point parameter registers
     60 f14-f31   Nonvolatile registers
     61 
     62 LR        Link register (volatile)
     63 CTR       Loop counter register (volatile)
     64 XER       Fixed point exception register (volatile)
     65 FPSCR     Floating point status and control register (volatile)
     66 
     67 CR0-CR1   Volatile condition code register fields
     68 CR2-CR4   Nonvolatile condition code register fields
     69 CR5-CR7   Volatile condition code register fields
     70 
     71 On processors with the VMX feature.
     72 
     73 v0-v1     Volatile scratch registers
     74 v2-v13    Volatile vector parameters registers
     75 v14-v19   Volatile scratch registers
     76 v20-v31   Non-volatile registers
     77 vrsave    Non-volatile 32-bit register
     78 */
     79 
     80 
     81 /*---------------------------------------------------------------*/
     82 /*--- Vex's representation of the PPC64 CPU state             ---*/
     83 /*---------------------------------------------------------------*/
     84 
     85 #define VEX_GUEST_PPC64_REDIR_STACK_SIZE (16/*entries*/ * 2/*words per entry*/)
     86 
     87 typedef
     88    struct {
     89       /* General Purpose Registers */
     90       /*   0 */ ULong guest_GPR0;
     91       /*   8 */ ULong guest_GPR1;
     92       /*  16 */ ULong guest_GPR2;
     93       /*  24 */ ULong guest_GPR3;
     94       /*  32 */ ULong guest_GPR4;
     95       /*  40 */ ULong guest_GPR5;
     96       /*  48 */ ULong guest_GPR6;
     97       /*  56 */ ULong guest_GPR7;
     98       /*  64 */ ULong guest_GPR8;
     99       /*  72 */ ULong guest_GPR9;
    100       /*  80 */ ULong guest_GPR10;
    101       /*  88 */ ULong guest_GPR11;
    102       /*  96 */ ULong guest_GPR12;
    103       /* 104 */ ULong guest_GPR13;
    104       /* 112 */ ULong guest_GPR14;
    105       /* 120 */ ULong guest_GPR15;
    106       /* 128 */ ULong guest_GPR16;
    107       /* 136 */ ULong guest_GPR17;
    108       /* 144 */ ULong guest_GPR18;
    109       /* 152 */ ULong guest_GPR19;
    110       /* 160 */ ULong guest_GPR20;
    111       /* 168 */ ULong guest_GPR21;
    112       /* 176 */ ULong guest_GPR22;
    113       /* 184 */ ULong guest_GPR23;
    114       /* 192 */ ULong guest_GPR24;
    115       /* 200 */ ULong guest_GPR25;
    116       /* 208 */ ULong guest_GPR26;
    117       /* 216 */ ULong guest_GPR27;
    118       /* 224 */ ULong guest_GPR28;
    119       /* 232 */ ULong guest_GPR29;
    120       /* 240 */ ULong guest_GPR30;
    121       /* 248 */ ULong guest_GPR31;
    122 
    123       // Floating Point Registers
    124       /* 256 */ ULong guest_FPR0;
    125       /* 264 */ ULong guest_FPR1;
    126       /* 272 */ ULong guest_FPR2;
    127       /* 280 */ ULong guest_FPR3;
    128       /* 288 */ ULong guest_FPR4;
    129       /* 296 */ ULong guest_FPR5;
    130       /* 304 */ ULong guest_FPR6;
    131       /* 312 */ ULong guest_FPR7;
    132       /* 320 */ ULong guest_FPR8;
    133       /* 328 */ ULong guest_FPR9;
    134       /* 336 */ ULong guest_FPR10;
    135       /* 344 */ ULong guest_FPR11;
    136       /* 352 */ ULong guest_FPR12;
    137       /* 360 */ ULong guest_FPR13;
    138       /* 368 */ ULong guest_FPR14;
    139       /* 376 */ ULong guest_FPR15;
    140       /* 384 */ ULong guest_FPR16;
    141       /* 392 */ ULong guest_FPR17;
    142       /* 400 */ ULong guest_FPR18;
    143       /* 408 */ ULong guest_FPR19;
    144       /* 416 */ ULong guest_FPR20;
    145       /* 424 */ ULong guest_FPR21;
    146       /* 432 */ ULong guest_FPR22;
    147       /* 440 */ ULong guest_FPR23;
    148       /* 448 */ ULong guest_FPR24;
    149       /* 456 */ ULong guest_FPR25;
    150       /* 464 */ ULong guest_FPR26;
    151       /* 472 */ ULong guest_FPR27;
    152       /* 480 */ ULong guest_FPR28;
    153       /* 488 */ ULong guest_FPR29;
    154       /* 496 */ ULong guest_FPR30;
    155       /* 504 */ ULong guest_FPR31;
    156 
    157       // Vector Registers
    158       // IMPORTANT: the user of libvex must place the guest state so as
    159       // to ensure that guest_VR{0..31}, and any shadows thereof, are
    160       // 16-aligned.
    161       /*  512 */ U128 guest_VR0;
    162       /*  528 */ U128 guest_VR1;
    163       /*  544 */ U128 guest_VR2;
    164       /*  560 */ U128 guest_VR3;
    165       /*  576 */ U128 guest_VR4;
    166       /*  592 */ U128 guest_VR5;
    167       /*  608 */ U128 guest_VR6;
    168       /*  624 */ U128 guest_VR7;
    169       /*  640 */ U128 guest_VR8;
    170       /*  656 */ U128 guest_VR9;
    171       /*  672 */ U128 guest_VR10;
    172       /*  688 */ U128 guest_VR11;
    173       /*  704 */ U128 guest_VR12;
    174       /*  720 */ U128 guest_VR13;
    175       /*  736 */ U128 guest_VR14;
    176       /*  752 */ U128 guest_VR15;
    177       /*  768 */ U128 guest_VR16;
    178       /*  784 */ U128 guest_VR17;
    179       /*  800 */ U128 guest_VR18;
    180       /*  816 */ U128 guest_VR19;
    181       /*  832 */ U128 guest_VR20;
    182       /*  848 */ U128 guest_VR21;
    183       /*  864 */ U128 guest_VR22;
    184       /*  880 */ U128 guest_VR23;
    185       /*  896 */ U128 guest_VR24;
    186       /*  912 */ U128 guest_VR25;
    187       /*  928 */ U128 guest_VR26;
    188       /*  944 */ U128 guest_VR27;
    189       /*  960 */ U128 guest_VR28;
    190       /*  976 */ U128 guest_VR29;
    191       /*  992 */ U128 guest_VR30;
    192       /* 1008 */ U128 guest_VR31;
    193 
    194       /* 1024 */ ULong guest_CIA;    // IP (no arch visible register)
    195       /* 1032 */ ULong guest_LR;     // Link Register
    196       /* 1040 */ ULong guest_CTR;    // Count Register
    197 
    198       /* XER pieces */
    199       /* 1048 */ UChar guest_XER_SO; /* in lsb */
    200       /* 1049 */ UChar guest_XER_OV; /* in lsb */
    201       /* 1050 */ UChar guest_XER_CA; /* in lsb */
    202       /* 1051 */ UChar guest_XER_BC; /* all bits */
    203 
    204       /* CR pieces */
    205       /* 1052 */ UChar guest_CR0_321; /* in [3:1] */
    206       /* 1053 */ UChar guest_CR0_0;   /* in lsb */
    207       /* 1054 */ UChar guest_CR1_321; /* in [3:1] */
    208       /* 1055 */ UChar guest_CR1_0;   /* in lsb */
    209       /* 1056 */ UChar guest_CR2_321; /* in [3:1] */
    210       /* 1057 */ UChar guest_CR2_0;   /* in lsb */
    211       /* 1058 */ UChar guest_CR3_321; /* in [3:1] */
    212       /* 1059 */ UChar guest_CR3_0;   /* in lsb */
    213       /* 1060 */ UChar guest_CR4_321; /* in [3:1] */
    214       /* 1061 */ UChar guest_CR4_0;   /* in lsb */
    215       /* 1062 */ UChar guest_CR5_321; /* in [3:1] */
    216       /* 1063 */ UChar guest_CR5_0;   /* in lsb */
    217       /* 1064 */ UChar guest_CR6_321; /* in [3:1] */
    218       /* 1065 */ UChar guest_CR6_0;   /* in lsb */
    219       /* 1066 */ UChar guest_CR7_321; /* in [3:1] */
    220       /* 1067 */ UChar guest_CR7_0;   /* in lsb */
    221 
    222       /* FP Status & Control Register fields */
    223       /* 1068 */ UInt guest_FPROUND; // FP Rounding Mode
    224 
    225       /* Vector Save/Restore Register */
    226       /* 1072 */ UInt guest_VRSAVE;
    227 
    228       /* Vector Status and Control Register */
    229       /* 1076 */ UInt guest_VSCR;
    230 
    231       /* Emulation warnings */
    232       /* 1080 */ UInt guest_EMWARN;
    233 
    234       /* gcc adds 4 bytes padding here: pre-empt it. */
    235       /* 1084 */ UInt  padding;
    236 
    237       /* For icbi: record start and length of area to invalidate */
    238       /* 1088 */ ULong guest_TISTART;
    239       /* 1096 */ ULong guest_TILEN;
    240 
    241       /* Used to record the unredirected guest address at the start of
    242          a translation whose start has been redirected.  By reading
    243          this pseudo-register shortly afterwards, the translation can
    244          find out what the corresponding no-redirection address was.
    245          Note, this is only set for wrap-style redirects, not for
    246          replace-style ones. */
    247       /* 1104 */ ULong guest_NRADDR;
    248       /* 1112 */ ULong guest_NRADDR_GPR2;
    249 
    250      /* A grows-upwards stack for hidden saves/restores of LR and R2
    251         needed for function interception and wrapping on ppc64-linux.
    252         A horrible hack.  REDIR_SP points to the highest live entry,
    253         and so starts at -1. */
    254       /* 1120 */ ULong guest_REDIR_SP;
    255       /* 1128 */ ULong guest_REDIR_STACK[VEX_GUEST_PPC64_REDIR_STACK_SIZE];
    256 
    257       /* Needed for AIX: CIA at the last SC insn.  Used when backing up
    258          to restart a syscall that has been interrupted by a signal. */
    259       /* 1384 */ ULong guest_IP_AT_SYSCALL;
    260 
    261       /* SPRG3, which AIUI is readonly in user space.  Needed for
    262          threading on AIX. */
    263       /* ???? */ ULong guest_SPRG3_RO;
    264 
    265       /* Padding to make it have an 8-aligned size */
    266       /* ???? */ ULong padding2;
    267    }
    268    VexGuestPPC64State;
    269 
    270 
    271 /*---------------------------------------------------------------*/
    272 /*--- Utility functions for PPC64 guest stuff.                ---*/
    273 /*---------------------------------------------------------------*/
    274 
    275 /* ALL THE FOLLOWING ARE VISIBLE TO LIBRARY CLIENT */
    276 
    277 /* Initialise all guest PPC64 state. */
    278 extern
    279 void LibVEX_GuestPPC64_initialise ( /*OUT*/VexGuestPPC64State* vex_state );
    280 
    281 
    282 /* Write the given native %CR value to the supplied VexGuestPPC64State
    283    structure.  Note, %CR is 32-bits even for ppc64. */
    284 extern
    285 void LibVEX_GuestPPC64_put_CR ( UInt cr_native,
    286                                 /*OUT*/VexGuestPPC64State* vex_state );
    287 
    288 /* Extract from the supplied VexGuestPPC64State structure the
    289    corresponding native %CR value.  Note, %CR is 32-bits even for
    290    ppc64. */
    291 extern
    292 UInt LibVEX_GuestPPC64_get_CR ( /*IN*/VexGuestPPC64State* vex_state );
    293 
    294 
    295 /* Write the given native %XER value to the supplied
    296    VexGuestPPC64State structure.  Note, %XER is 32-bits even for
    297    ppc64. */
    298 extern
    299 void LibVEX_GuestPPC64_put_XER ( UInt xer_native,
    300                                  /*OUT*/VexGuestPPC64State* vex_state );
    301 
    302 /* Extract from the supplied VexGuestPPC64State structure the
    303    corresponding native %XER value.  Note, %CR is 32-bits even for
    304    ppc64. */
    305 extern
    306 UInt LibVEX_GuestPPC64_get_XER ( /*IN*/VexGuestPPC64State* vex_state );
    307 
    308 #endif /* ndef __LIBVEX_PUB_GUEST_PPC64_H */
    309 
    310 
    311 /*---------------------------------------------------------------*/
    312 /*---                                    libvex_guest_ppc64.h ---*/
    313 /*---------------------------------------------------------------*/
    314