Home | History | Annotate | Download | only in pub
      1 
      2 /*---------------------------------------------------------------*/
      3 /*--- begin                              libvex_guest_arm64.h ---*/
      4 /*---------------------------------------------------------------*/
      5 
      6 /*
      7    This file is part of Valgrind, a dynamic binary instrumentation
      8    framework.
      9 
     10    Copyright (C) 2013-2015 OpenWorks
     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 
     31 #ifndef __LIBVEX_PUB_GUEST_ARM64_H
     32 #define __LIBVEX_PUB_GUEST_ARM64_H
     33 
     34 #include "libvex_basictypes.h"
     35 
     36 
     37 /*---------------------------------------------------------------*/
     38 /*--- Vex's representation of the ARM64 CPU state.            ---*/
     39 /*---------------------------------------------------------------*/
     40 
     41 typedef
     42    struct {
     43       /* Event check fail addr and counter. */
     44       /* 0 */  ULong host_EvC_FAILADDR;
     45       /* 8 */  UInt  host_EvC_COUNTER;
     46       /* 12 */ UInt  pad0;
     47       /* 16 */
     48       ULong guest_X0;
     49       ULong guest_X1;
     50       ULong guest_X2;
     51       ULong guest_X3;
     52       ULong guest_X4;
     53       ULong guest_X5;
     54       ULong guest_X6;
     55       ULong guest_X7;
     56       ULong guest_X8;
     57       ULong guest_X9;
     58       ULong guest_X10;
     59       ULong guest_X11;
     60       ULong guest_X12;
     61       ULong guest_X13;
     62       ULong guest_X14;
     63       ULong guest_X15;
     64       ULong guest_X16;
     65       ULong guest_X17;
     66       ULong guest_X18;
     67       ULong guest_X19;
     68       ULong guest_X20;
     69       ULong guest_X21;
     70       ULong guest_X22;
     71       ULong guest_X23;
     72       ULong guest_X24;
     73       ULong guest_X25;
     74       ULong guest_X26;
     75       ULong guest_X27;
     76       ULong guest_X28;
     77       ULong guest_X29;
     78       ULong guest_X30;     /* link register */
     79       ULong guest_XSP;
     80       ULong guest_PC;
     81 
     82       /* 4-word thunk used to calculate N(sign) Z(zero) C(carry,
     83          unsigned overflow) and V(signed overflow) flags. */
     84       ULong guest_CC_OP;
     85       ULong guest_CC_DEP1;
     86       ULong guest_CC_DEP2;
     87       ULong guest_CC_NDEP;
     88 
     89       /* User-space thread register? */
     90       ULong guest_TPIDR_EL0;
     91 
     92       /* FP/SIMD state */
     93       U128 guest_Q0;
     94       U128 guest_Q1;
     95       U128 guest_Q2;
     96       U128 guest_Q3;
     97       U128 guest_Q4;
     98       U128 guest_Q5;
     99       U128 guest_Q6;
    100       U128 guest_Q7;
    101       U128 guest_Q8;
    102       U128 guest_Q9;
    103       U128 guest_Q10;
    104       U128 guest_Q11;
    105       U128 guest_Q12;
    106       U128 guest_Q13;
    107       U128 guest_Q14;
    108       U128 guest_Q15;
    109       U128 guest_Q16;
    110       U128 guest_Q17;
    111       U128 guest_Q18;
    112       U128 guest_Q19;
    113       U128 guest_Q20;
    114       U128 guest_Q21;
    115       U128 guest_Q22;
    116       U128 guest_Q23;
    117       U128 guest_Q24;
    118       U128 guest_Q25;
    119       U128 guest_Q26;
    120       U128 guest_Q27;
    121       U128 guest_Q28;
    122       U128 guest_Q29;
    123       U128 guest_Q30;
    124       U128 guest_Q31;
    125 
    126       /* A 128-bit value which is used to represent the FPSR.QC (sticky
    127          saturation) flag, when necessary.  If the value stored here
    128          is zero, FPSR.QC is currently zero.  If it is any other value,
    129          FPSR.QC is currently one.  We don't currently represent any
    130          other bits of FPSR, so this is all that that is for FPSR. */
    131       U128 guest_QCFLAG;
    132 
    133       /* Various pseudo-regs mandated by Vex or Valgrind. */
    134       /* Emulation notes */
    135       UInt guest_EMNOTE;
    136 
    137       /* For clflush/clinval: record start and length of area */
    138       ULong guest_CMSTART;
    139       ULong guest_CMLEN;
    140 
    141       /* Used to record the unredirected guest address at the start of
    142          a translation whose start has been redirected.  By reading
    143          this pseudo-register shortly afterwards, the translation can
    144          find out what the corresponding no-redirection address was.
    145          Note, this is only set for wrap-style redirects, not for
    146          replace-style ones. */
    147       ULong guest_NRADDR;
    148 
    149       /* Needed for Darwin (but mandated for all guest architectures):
    150          program counter at the last syscall insn (int 0x80/81/82,
    151          sysenter, syscall, svc).  Used when backing up to restart a
    152          syscall that has been interrupted by a signal. */
    153       ULong guest_IP_AT_SYSCALL;
    154 
    155       /* The complete FPCR.  Default value seems to be zero.  We
    156          ignore all bits except 23 and 22, which are the rounding
    157          mode.  The guest is unconstrained in what values it can write
    158          to and read from this register, but the emulation only takes
    159          note of bits 23 and 22. */
    160       UInt  guest_FPCR;
    161 
    162       /* Padding to make it have an 16-aligned size */
    163       /* UInt  pad_end_0; */
    164       /* ULong pad_end_1; */
    165    }
    166    VexGuestARM64State;
    167 
    168 
    169 /*---------------------------------------------------------------*/
    170 /*--- Utility functions for ARM64 guest stuff.                ---*/
    171 /*---------------------------------------------------------------*/
    172 
    173 /* ALL THE FOLLOWING ARE VISIBLE TO LIBRARY CLIENT */
    174 
    175 /* Initialise all guest ARM64 state. */
    176 
    177 extern
    178 void LibVEX_GuestARM64_initialise ( /*OUT*/VexGuestARM64State* vex_state );
    179 
    180 /* Calculate the ARM64 flag state from the saved data, in the format
    181    32x0:n:z:c:v:28x0. */
    182 extern
    183 ULong LibVEX_GuestARM64_get_nzcv ( /*IN*/
    184                                    const VexGuestARM64State* vex_state );
    185 
    186 /* Calculate the ARM64 FPSR state from the saved data, in the format
    187    36x0:qc:27x0 */
    188 extern
    189 ULong LibVEX_GuestARM64_get_fpsr ( /*IN*/
    190                                    const VexGuestARM64State* vex_state );
    191 
    192 /* Set the ARM64 FPSR representation from the given FPSR value. */
    193 extern
    194 void LibVEX_GuestARM64_set_fpsr ( /*MOD*/VexGuestARM64State* vex_state,
    195                                   ULong fpsr );
    196 
    197 
    198 #endif /* ndef __LIBVEX_PUB_GUEST_ARM64_H */
    199 
    200 
    201 /*---------------------------------------------------------------*/
    202 /*---                                    libvex_guest_arm64.h ---*/
    203 /*---------------------------------------------------------------*/
    204