Home | History | Annotate | Line # | Download | only in opcodes
aarch64-opc.c revision 1.7
      1  1.1  christos /* aarch64-opc.c -- AArch64 opcode support.
      2  1.7  christos    Copyright (C) 2009-2017 Free Software Foundation, Inc.
      3  1.1  christos    Contributed by ARM Ltd.
      4  1.1  christos 
      5  1.1  christos    This file is part of the GNU opcodes library.
      6  1.1  christos 
      7  1.1  christos    This library is free software; you can redistribute it and/or modify
      8  1.1  christos    it under the terms of the GNU General Public License as published by
      9  1.1  christos    the Free Software Foundation; either version 3, or (at your option)
     10  1.1  christos    any later version.
     11  1.1  christos 
     12  1.1  christos    It is distributed in the hope that it will be useful, but WITHOUT
     13  1.1  christos    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
     14  1.1  christos    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
     15  1.1  christos    License for more details.
     16  1.1  christos 
     17  1.1  christos    You should have received a copy of the GNU General Public License
     18  1.1  christos    along with this program; see the file COPYING3. If not,
     19  1.1  christos    see <http://www.gnu.org/licenses/>.  */
     20  1.1  christos 
     21  1.1  christos #include "sysdep.h"
     22  1.1  christos #include <assert.h>
     23  1.1  christos #include <stdlib.h>
     24  1.1  christos #include <stdio.h>
     25  1.1  christos #include <stdint.h>
     26  1.1  christos #include <stdarg.h>
     27  1.1  christos #include <inttypes.h>
     28  1.1  christos 
     29  1.1  christos #include "opintl.h"
     30  1.7  christos #include "libiberty.h"
     31  1.1  christos 
     32  1.1  christos #include "aarch64-opc.h"
     33  1.1  christos 
     34  1.1  christos #ifdef DEBUG_AARCH64
     35  1.1  christos int debug_dump = FALSE;
     36  1.1  christos #endif /* DEBUG_AARCH64 */
     37  1.1  christos 
     38  1.7  christos /* The enumeration strings associated with each value of a 5-bit SVE
     39  1.7  christos    pattern operand.  A null entry indicates a reserved meaning.  */
     40  1.7  christos const char *const aarch64_sve_pattern_array[32] = {
     41  1.7  christos   /* 0-7.  */
     42  1.7  christos   "pow2",
     43  1.7  christos   "vl1",
     44  1.7  christos   "vl2",
     45  1.7  christos   "vl3",
     46  1.7  christos   "vl4",
     47  1.7  christos   "vl5",
     48  1.7  christos   "vl6",
     49  1.7  christos   "vl7",
     50  1.7  christos   /* 8-15.  */
     51  1.7  christos   "vl8",
     52  1.7  christos   "vl16",
     53  1.7  christos   "vl32",
     54  1.7  christos   "vl64",
     55  1.7  christos   "vl128",
     56  1.7  christos   "vl256",
     57  1.7  christos   0,
     58  1.7  christos   0,
     59  1.7  christos   /* 16-23.  */
     60  1.7  christos   0,
     61  1.7  christos   0,
     62  1.7  christos   0,
     63  1.7  christos   0,
     64  1.7  christos   0,
     65  1.7  christos   0,
     66  1.7  christos   0,
     67  1.7  christos   0,
     68  1.7  christos   /* 24-31.  */
     69  1.7  christos   0,
     70  1.7  christos   0,
     71  1.7  christos   0,
     72  1.7  christos   0,
     73  1.7  christos   0,
     74  1.7  christos   "mul4",
     75  1.7  christos   "mul3",
     76  1.7  christos   "all"
     77  1.7  christos };
     78  1.7  christos 
     79  1.7  christos /* The enumeration strings associated with each value of a 4-bit SVE
     80  1.7  christos    prefetch operand.  A null entry indicates a reserved meaning.  */
     81  1.7  christos const char *const aarch64_sve_prfop_array[16] = {
     82  1.7  christos   /* 0-7.  */
     83  1.7  christos   "pldl1keep",
     84  1.7  christos   "pldl1strm",
     85  1.7  christos   "pldl2keep",
     86  1.7  christos   "pldl2strm",
     87  1.7  christos   "pldl3keep",
     88  1.7  christos   "pldl3strm",
     89  1.7  christos   0,
     90  1.7  christos   0,
     91  1.7  christos   /* 8-15.  */
     92  1.7  christos   "pstl1keep",
     93  1.7  christos   "pstl1strm",
     94  1.7  christos   "pstl2keep",
     95  1.7  christos   "pstl2strm",
     96  1.7  christos   "pstl3keep",
     97  1.7  christos   "pstl3strm",
     98  1.7  christos   0,
     99  1.7  christos   0
    100  1.7  christos };
    101  1.7  christos 
    102  1.1  christos /* Helper functions to determine which operand to be used to encode/decode
    103  1.1  christos    the size:Q fields for AdvSIMD instructions.  */
    104  1.1  christos 
    105  1.1  christos static inline bfd_boolean
    106  1.1  christos vector_qualifier_p (enum aarch64_opnd_qualifier qualifier)
    107  1.1  christos {
    108  1.1  christos   return ((qualifier >= AARCH64_OPND_QLF_V_8B
    109  1.1  christos 	  && qualifier <= AARCH64_OPND_QLF_V_1Q) ? TRUE
    110  1.1  christos 	  : FALSE);
    111  1.1  christos }
    112  1.1  christos 
    113  1.1  christos static inline bfd_boolean
    114  1.1  christos fp_qualifier_p (enum aarch64_opnd_qualifier qualifier)
    115  1.1  christos {
    116  1.1  christos   return ((qualifier >= AARCH64_OPND_QLF_S_B
    117  1.1  christos 	  && qualifier <= AARCH64_OPND_QLF_S_Q) ? TRUE
    118  1.1  christos 	  : FALSE);
    119  1.1  christos }
    120  1.1  christos 
    121  1.1  christos enum data_pattern
    122  1.1  christos {
    123  1.1  christos   DP_UNKNOWN,
    124  1.1  christos   DP_VECTOR_3SAME,
    125  1.1  christos   DP_VECTOR_LONG,
    126  1.1  christos   DP_VECTOR_WIDE,
    127  1.1  christos   DP_VECTOR_ACROSS_LANES,
    128  1.1  christos };
    129  1.1  christos 
    130  1.1  christos static const char significant_operand_index [] =
    131  1.1  christos {
    132  1.1  christos   0,	/* DP_UNKNOWN, by default using operand 0.  */
    133  1.1  christos   0,	/* DP_VECTOR_3SAME */
    134  1.1  christos   1,	/* DP_VECTOR_LONG */
    135  1.1  christos   2,	/* DP_VECTOR_WIDE */
    136  1.1  christos   1,	/* DP_VECTOR_ACROSS_LANES */
    137  1.1  christos };
    138  1.1  christos 
    139  1.1  christos /* Given a sequence of qualifiers in QUALIFIERS, determine and return
    140  1.1  christos    the data pattern.
    141  1.1  christos    N.B. QUALIFIERS is a possible sequence of qualifiers each of which
    142  1.1  christos    corresponds to one of a sequence of operands.  */
    143  1.1  christos 
    144  1.1  christos static enum data_pattern
    145  1.1  christos get_data_pattern (const aarch64_opnd_qualifier_seq_t qualifiers)
    146  1.1  christos {
    147  1.1  christos   if (vector_qualifier_p (qualifiers[0]) == TRUE)
    148  1.1  christos     {
    149  1.1  christos       /* e.g. v.4s, v.4s, v.4s
    150  1.1  christos 	   or v.4h, v.4h, v.h[3].  */
    151  1.1  christos       if (qualifiers[0] == qualifiers[1]
    152  1.1  christos 	  && vector_qualifier_p (qualifiers[2]) == TRUE
    153  1.1  christos 	  && (aarch64_get_qualifier_esize (qualifiers[0])
    154  1.1  christos 	      == aarch64_get_qualifier_esize (qualifiers[1]))
    155  1.1  christos 	  && (aarch64_get_qualifier_esize (qualifiers[0])
    156  1.1  christos 	      == aarch64_get_qualifier_esize (qualifiers[2])))
    157  1.1  christos 	return DP_VECTOR_3SAME;
    158  1.1  christos       /* e.g. v.8h, v.8b, v.8b.
    159  1.1  christos            or v.4s, v.4h, v.h[2].
    160  1.1  christos 	   or v.8h, v.16b.  */
    161  1.1  christos       if (vector_qualifier_p (qualifiers[1]) == TRUE
    162  1.1  christos 	  && aarch64_get_qualifier_esize (qualifiers[0]) != 0
    163  1.1  christos 	  && (aarch64_get_qualifier_esize (qualifiers[0])
    164  1.1  christos 	      == aarch64_get_qualifier_esize (qualifiers[1]) << 1))
    165  1.1  christos 	return DP_VECTOR_LONG;
    166  1.1  christos       /* e.g. v.8h, v.8h, v.8b.  */
    167  1.1  christos       if (qualifiers[0] == qualifiers[1]
    168  1.1  christos 	  && vector_qualifier_p (qualifiers[2]) == TRUE
    169  1.1  christos 	  && aarch64_get_qualifier_esize (qualifiers[0]) != 0
    170  1.1  christos 	  && (aarch64_get_qualifier_esize (qualifiers[0])
    171  1.1  christos 	      == aarch64_get_qualifier_esize (qualifiers[2]) << 1)
    172  1.1  christos 	  && (aarch64_get_qualifier_esize (qualifiers[0])
    173  1.1  christos 	      == aarch64_get_qualifier_esize (qualifiers[1])))
    174  1.1  christos 	return DP_VECTOR_WIDE;
    175  1.1  christos     }
    176  1.1  christos   else if (fp_qualifier_p (qualifiers[0]) == TRUE)
    177  1.1  christos     {
    178  1.1  christos       /* e.g. SADDLV <V><d>, <Vn>.<T>.  */
    179  1.1  christos       if (vector_qualifier_p (qualifiers[1]) == TRUE
    180  1.1  christos 	  && qualifiers[2] == AARCH64_OPND_QLF_NIL)
    181  1.1  christos 	return DP_VECTOR_ACROSS_LANES;
    182  1.1  christos     }
    183  1.1  christos 
    184  1.1  christos   return DP_UNKNOWN;
    185  1.1  christos }
    186  1.1  christos 
    187  1.1  christos /* Select the operand to do the encoding/decoding of the 'size:Q' fields in
    188  1.1  christos    the AdvSIMD instructions.  */
    189  1.1  christos /* N.B. it is possible to do some optimization that doesn't call
    190  1.1  christos    get_data_pattern each time when we need to select an operand.  We can
    191  1.1  christos    either buffer the caculated the result or statically generate the data,
    192  1.1  christos    however, it is not obvious that the optimization will bring significant
    193  1.1  christos    benefit.  */
    194  1.1  christos 
    195  1.1  christos int
    196  1.1  christos aarch64_select_operand_for_sizeq_field_coding (const aarch64_opcode *opcode)
    197  1.1  christos {
    198  1.1  christos   return
    199  1.1  christos     significant_operand_index [get_data_pattern (opcode->qualifiers_list[0])];
    200  1.1  christos }
    201  1.1  christos 
    202  1.1  christos const aarch64_field fields[] =
    204  1.1  christos {
    205  1.1  christos     {  0,  0 },	/* NIL.  */
    206  1.1  christos     {  0,  4 },	/* cond2: condition in truly conditional-executed inst.  */
    207  1.1  christos     {  0,  4 },	/* nzcv: flag bit specifier, encoded in the "nzcv" field.  */
    208  1.1  christos     {  5,  5 },	/* defgh: d:e:f:g:h bits in AdvSIMD modified immediate.  */
    209  1.1  christos     { 16,  3 },	/* abc: a:b:c bits in AdvSIMD modified immediate.  */
    210  1.1  christos     {  5, 19 },	/* imm19: e.g. in CBZ.  */
    211  1.1  christos     {  5, 19 },	/* immhi: e.g. in ADRP.  */
    212  1.1  christos     { 29,  2 },	/* immlo: e.g. in ADRP.  */
    213  1.1  christos     { 22,  2 },	/* size: in most AdvSIMD and floating-point instructions.  */
    214  1.1  christos     { 10,  2 },	/* vldst_size: size field in the AdvSIMD load/store inst.  */
    215  1.1  christos     { 29,  1 },	/* op: in AdvSIMD modified immediate instructions.  */
    216  1.1  christos     { 30,  1 },	/* Q: in most AdvSIMD instructions.  */
    217  1.1  christos     {  0,  5 },	/* Rt: in load/store instructions.  */
    218  1.1  christos     {  0,  5 },	/* Rd: in many integer instructions.  */
    219  1.1  christos     {  5,  5 },	/* Rn: in many integer instructions.  */
    220  1.1  christos     { 10,  5 },	/* Rt2: in load/store pair instructions.  */
    221  1.1  christos     { 10,  5 },	/* Ra: in fp instructions.  */
    222  1.1  christos     {  5,  3 },	/* op2: in the system instructions.  */
    223  1.1  christos     {  8,  4 },	/* CRm: in the system instructions.  */
    224  1.1  christos     { 12,  4 },	/* CRn: in the system instructions.  */
    225  1.1  christos     { 16,  3 },	/* op1: in the system instructions.  */
    226  1.1  christos     { 19,  2 },	/* op0: in the system instructions.  */
    227  1.1  christos     { 10,  3 },	/* imm3: in add/sub extended reg instructions.  */
    228  1.1  christos     { 12,  4 },	/* cond: condition flags as a source operand.  */
    229  1.1  christos     { 12,  4 },	/* opcode: in advsimd load/store instructions.  */
    230  1.1  christos     { 12,  4 },	/* cmode: in advsimd modified immediate instructions.  */
    231  1.1  christos     { 13,  3 },	/* asisdlso_opcode: opcode in advsimd ld/st single element.  */
    232  1.1  christos     { 13,  2 },	/* len: in advsimd tbl/tbx instructions.  */
    233  1.1  christos     { 16,  5 },	/* Rm: in ld/st reg offset and some integer inst.  */
    234  1.1  christos     { 16,  5 },	/* Rs: in load/store exclusive instructions.  */
    235  1.1  christos     { 13,  3 },	/* option: in ld/st reg offset + add/sub extended reg inst.  */
    236  1.1  christos     { 12,  1 },	/* S: in load/store reg offset instructions.  */
    237  1.1  christos     { 21,  2 },	/* hw: in move wide constant instructions.  */
    238  1.1  christos     { 22,  2 },	/* opc: in load/store reg offset instructions.  */
    239  1.1  christos     { 23,  1 },	/* opc1: in load/store reg offset instructions.  */
    240  1.1  christos     { 22,  2 },	/* shift: in add/sub reg/imm shifted instructions.  */
    241  1.1  christos     { 22,  2 },	/* type: floating point type field in fp data inst.  */
    242  1.1  christos     { 30,  2 },	/* ldst_size: size field in ld/st reg offset inst.  */
    243  1.1  christos     { 10,  6 },	/* imm6: in add/sub reg shifted instructions.  */
    244  1.1  christos     { 11,  4 },	/* imm4: in advsimd ext and advsimd ins instructions.  */
    245  1.1  christos     { 16,  5 },	/* imm5: in conditional compare (immediate) instructions.  */
    246  1.1  christos     { 15,  7 },	/* imm7: in load/store pair pre/post index instructions.  */
    247  1.1  christos     { 13,  8 },	/* imm8: in floating-point scalar move immediate inst.  */
    248  1.1  christos     { 12,  9 },	/* imm9: in load/store pre/post index instructions.  */
    249  1.1  christos     { 10, 12 },	/* imm12: in ld/st unsigned imm or add/sub shifted inst.  */
    250  1.1  christos     {  5, 14 },	/* imm14: in test bit and branch instructions.  */
    251  1.1  christos     {  5, 16 },	/* imm16: in exception instructions.  */
    252  1.1  christos     {  0, 26 },	/* imm26: in unconditional branch instructions.  */
    253  1.1  christos     { 10,  6 },	/* imms: in bitfield and logical immediate instructions.  */
    254  1.1  christos     { 16,  6 },	/* immr: in bitfield and logical immediate instructions.  */
    255  1.1  christos     { 16,  3 },	/* immb: in advsimd shift by immediate instructions.  */
    256  1.7  christos     { 19,  4 },	/* immh: in advsimd shift by immediate instructions.  */
    257  1.1  christos     { 22,  1 },	/* S: in LDRAA and LDRAB instructions.  */
    258  1.1  christos     { 22,  1 },	/* N: in logical (immediate) instructions.  */
    259  1.1  christos     { 11,  1 },	/* index: in ld/st inst deciding the pre/post-index.  */
    260  1.1  christos     { 24,  1 },	/* index2: in ld/st pair inst deciding the pre/post-index.  */
    261  1.3  christos     { 31,  1 },	/* sf: in integer data processing instructions.  */
    262  1.1  christos     { 30,  1 },	/* lse_size: in LSE extension atomic instructions.  */
    263  1.1  christos     { 11,  1 },	/* H: in advsimd scalar x indexed element instructions.  */
    264  1.1  christos     { 21,  1 },	/* L: in advsimd scalar x indexed element instructions.  */
    265  1.1  christos     { 20,  1 },	/* M: in advsimd scalar x indexed element instructions.  */
    266  1.1  christos     { 31,  1 },	/* b5: in the test bit and branch instructions.  */
    267  1.1  christos     { 19,  5 },	/* b40: in the test bit and branch instructions.  */
    268  1.7  christos     { 10,  6 },	/* scale: in the fixed-point scalar to fp converting inst.  */
    269  1.7  christos     {  4,  1 }, /* SVE_M_4: Merge/zero select, bit 4.  */
    270  1.7  christos     { 14,  1 }, /* SVE_M_14: Merge/zero select, bit 14.  */
    271  1.7  christos     { 16,  1 }, /* SVE_M_16: Merge/zero select, bit 16.  */
    272  1.7  christos     { 17,  1 }, /* SVE_N: SVE equivalent of N.  */
    273  1.7  christos     {  0,  4 }, /* SVE_Pd: p0-p15, bits [3,0].  */
    274  1.7  christos     { 10,  3 }, /* SVE_Pg3: p0-p7, bits [12,10].  */
    275  1.7  christos     {  5,  4 }, /* SVE_Pg4_5: p0-p15, bits [8,5].  */
    276  1.7  christos     { 10,  4 }, /* SVE_Pg4_10: p0-p15, bits [13,10].  */
    277  1.7  christos     { 16,  4 }, /* SVE_Pg4_16: p0-p15, bits [19,16].  */
    278  1.7  christos     { 16,  4 }, /* SVE_Pm: p0-p15, bits [19,16].  */
    279  1.7  christos     {  5,  4 }, /* SVE_Pn: p0-p15, bits [8,5].  */
    280  1.7  christos     {  0,  4 }, /* SVE_Pt: p0-p15, bits [3,0].  */
    281  1.7  christos     {  5,  5 }, /* SVE_Rm: SVE alternative position for Rm.  */
    282  1.7  christos     { 16,  5 }, /* SVE_Rn: SVE alternative position for Rn.  */
    283  1.7  christos     {  0,  5 }, /* SVE_Vd: Scalar SIMD&FP register, bits [4,0].  */
    284  1.7  christos     {  5,  5 }, /* SVE_Vm: Scalar SIMD&FP register, bits [9,5].  */
    285  1.7  christos     {  5,  5 }, /* SVE_Vn: Scalar SIMD&FP register, bits [9,5].  */
    286  1.7  christos     {  5,  5 }, /* SVE_Za_5: SVE vector register, bits [9,5].  */
    287  1.7  christos     { 16,  5 }, /* SVE_Za_16: SVE vector register, bits [20,16].  */
    288  1.7  christos     {  0,  5 }, /* SVE_Zd: SVE vector register. bits [4,0].  */
    289  1.7  christos     {  5,  5 }, /* SVE_Zm_5: SVE vector register, bits [9,5].  */
    290  1.7  christos     { 16,  5 }, /* SVE_Zm_16: SVE vector register, bits [20,16]. */
    291  1.7  christos     {  5,  5 }, /* SVE_Zn: SVE vector register, bits [9,5].  */
    292  1.7  christos     {  0,  5 }, /* SVE_Zt: SVE vector register, bits [4,0].  */
    293  1.7  christos     {  5,  1 }, /* SVE_i1: single-bit immediate.  */
    294  1.7  christos     { 22,  1 }, /* SVE_i3h: high bit of 3-bit immediate.  */
    295  1.7  christos     { 16,  3 }, /* SVE_imm3: 3-bit immediate field.  */
    296  1.7  christos     { 16,  4 }, /* SVE_imm4: 4-bit immediate field.  */
    297  1.7  christos     {  5,  5 }, /* SVE_imm5: 5-bit immediate field.  */
    298  1.7  christos     { 16,  5 }, /* SVE_imm5b: secondary 5-bit immediate field.  */
    299  1.7  christos     { 16,  6 }, /* SVE_imm6: 6-bit immediate field.  */
    300  1.7  christos     { 14,  7 }, /* SVE_imm7: 7-bit immediate field.  */
    301  1.7  christos     {  5,  8 }, /* SVE_imm8: 8-bit immediate field.  */
    302  1.7  christos     {  5,  9 }, /* SVE_imm9: 9-bit immediate field.  */
    303  1.7  christos     { 11,  6 }, /* SVE_immr: SVE equivalent of immr.  */
    304  1.7  christos     {  5,  6 }, /* SVE_imms: SVE equivalent of imms.  */
    305  1.7  christos     { 10,  2 }, /* SVE_msz: 2-bit shift amount for ADR.  */
    306  1.7  christos     {  5,  5 }, /* SVE_pattern: vector pattern enumeration.  */
    307  1.7  christos     {  0,  4 }, /* SVE_prfop: prefetch operation for SVE PRF[BHWD].  */
    308  1.7  christos     { 16,  1 }, /* SVE_rot1: 1-bit rotation amount.  */
    309  1.7  christos     { 10,  2 }, /* SVE_rot2: 2-bit rotation amount.  */
    310  1.7  christos     { 22,  1 }, /* SVE_sz: 1-bit element size select.  */
    311  1.7  christos     { 16,  4 }, /* SVE_tsz: triangular size select.  */
    312  1.7  christos     { 22,  2 }, /* SVE_tszh: triangular size select high, bits [23,22].  */
    313  1.7  christos     {  8,  2 }, /* SVE_tszl_8: triangular size select low, bits [9,8].  */
    314  1.7  christos     { 19,  2 }, /* SVE_tszl_19: triangular size select low, bits [20,19].  */
    315  1.7  christos     { 14,  1 }, /* SVE_xs_14: UXTW/SXTW select (bit 14).  */
    316  1.7  christos     { 22,  1 }, /* SVE_xs_22: UXTW/SXTW select (bit 22).  */
    317  1.7  christos     { 11,  2 }, /* rotate1: FCMLA immediate rotate.  */
    318  1.7  christos     { 13,  2 }, /* rotate2: Indexed element FCMLA immediate rotate.  */
    319  1.1  christos     { 12,  1 }, /* rotate3: FCADD immediate rotate.  */
    320  1.1  christos };
    321  1.1  christos 
    322  1.1  christos enum aarch64_operand_class
    323  1.1  christos aarch64_get_operand_class (enum aarch64_opnd type)
    324  1.1  christos {
    325  1.1  christos   return aarch64_operands[type].op_class;
    326  1.1  christos }
    327  1.1  christos 
    328  1.1  christos const char *
    329  1.1  christos aarch64_get_operand_name (enum aarch64_opnd type)
    330  1.1  christos {
    331  1.1  christos   return aarch64_operands[type].name;
    332  1.1  christos }
    333  1.1  christos 
    334  1.1  christos /* Get operand description string.
    335  1.1  christos    This is usually for the diagnosis purpose.  */
    336  1.1  christos const char *
    337  1.1  christos aarch64_get_operand_desc (enum aarch64_opnd type)
    338  1.1  christos {
    339  1.1  christos   return aarch64_operands[type].desc;
    340  1.1  christos }
    341  1.1  christos 
    342  1.1  christos /* Table of all conditional affixes.  */
    343  1.1  christos const aarch64_cond aarch64_conds[16] =
    344  1.7  christos {
    345  1.7  christos   {{"eq", "none"}, 0x0},
    346  1.7  christos   {{"ne", "any"}, 0x1},
    347  1.7  christos   {{"cs", "hs", "nlast"}, 0x2},
    348  1.7  christos   {{"cc", "lo", "ul", "last"}, 0x3},
    349  1.7  christos   {{"mi", "first"}, 0x4},
    350  1.1  christos   {{"pl", "nfrst"}, 0x5},
    351  1.1  christos   {{"vs"}, 0x6},
    352  1.7  christos   {{"vc"}, 0x7},
    353  1.7  christos   {{"hi", "pmore"}, 0x8},
    354  1.7  christos   {{"ls", "plast"}, 0x9},
    355  1.7  christos   {{"ge", "tcont"}, 0xa},
    356  1.1  christos   {{"lt", "tstop"}, 0xb},
    357  1.1  christos   {{"gt"}, 0xc},
    358  1.1  christos   {{"le"}, 0xd},
    359  1.1  christos   {{"al"}, 0xe},
    360  1.1  christos   {{"nv"}, 0xf},
    361  1.1  christos };
    362  1.1  christos 
    363  1.1  christos const aarch64_cond *
    364  1.1  christos get_cond_from_value (aarch64_insn value)
    365  1.1  christos {
    366  1.1  christos   assert (value < 16);
    367  1.1  christos   return &aarch64_conds[(unsigned int) value];
    368  1.1  christos }
    369  1.1  christos 
    370  1.1  christos const aarch64_cond *
    371  1.1  christos get_inverted_cond (const aarch64_cond *cond)
    372  1.1  christos {
    373  1.1  christos   return &aarch64_conds[cond->value ^ 0x1];
    374  1.1  christos }
    375  1.1  christos 
    376  1.1  christos /* Table describing the operand extension/shifting operators; indexed by
    377  1.1  christos    enum aarch64_modifier_kind.
    378  1.1  christos 
    379  1.1  christos    The value column provides the most common values for encoding modifiers,
    380  1.1  christos    which enables table-driven encoding/decoding for the modifiers.  */
    381  1.1  christos const struct aarch64_name_value_pair aarch64_operand_modifiers [] =
    382  1.1  christos {
    383  1.1  christos     {"none", 0x0},
    384  1.1  christos     {"msl",  0x0},
    385  1.1  christos     {"ror",  0x3},
    386  1.1  christos     {"asr",  0x2},
    387  1.1  christos     {"lsr",  0x1},
    388  1.1  christos     {"lsl",  0x0},
    389  1.1  christos     {"uxtb", 0x0},
    390  1.1  christos     {"uxth", 0x1},
    391  1.1  christos     {"uxtw", 0x2},
    392  1.1  christos     {"uxtx", 0x3},
    393  1.1  christos     {"sxtb", 0x4},
    394  1.1  christos     {"sxth", 0x5},
    395  1.1  christos     {"sxtw", 0x6},
    396  1.7  christos     {"sxtx", 0x7},
    397  1.7  christos     {"mul", 0x0},
    398  1.1  christos     {"mul vl", 0x0},
    399  1.1  christos     {NULL, 0},
    400  1.1  christos };
    401  1.1  christos 
    402  1.1  christos enum aarch64_modifier_kind
    403  1.1  christos aarch64_get_operand_modifier (const struct aarch64_name_value_pair *desc)
    404  1.1  christos {
    405  1.1  christos   return desc - aarch64_operand_modifiers;
    406  1.1  christos }
    407  1.1  christos 
    408  1.1  christos aarch64_insn
    409  1.1  christos aarch64_get_operand_modifier_value (enum aarch64_modifier_kind kind)
    410  1.1  christos {
    411  1.1  christos   return aarch64_operand_modifiers[kind].value;
    412  1.1  christos }
    413  1.1  christos 
    414  1.1  christos enum aarch64_modifier_kind
    415  1.1  christos aarch64_get_operand_modifier_from_value (aarch64_insn value,
    416  1.1  christos 					 bfd_boolean extend_p)
    417  1.1  christos {
    418  1.1  christos   if (extend_p == TRUE)
    419  1.1  christos     return AARCH64_MOD_UXTB + value;
    420  1.1  christos   else
    421  1.1  christos     return AARCH64_MOD_LSL - value;
    422  1.1  christos }
    423  1.1  christos 
    424  1.1  christos bfd_boolean
    425  1.1  christos aarch64_extend_operator_p (enum aarch64_modifier_kind kind)
    426  1.1  christos {
    427  1.1  christos   return (kind > AARCH64_MOD_LSL && kind <= AARCH64_MOD_SXTX)
    428  1.1  christos     ? TRUE : FALSE;
    429  1.1  christos }
    430  1.1  christos 
    431  1.1  christos static inline bfd_boolean
    432  1.1  christos aarch64_shift_operator_p (enum aarch64_modifier_kind kind)
    433  1.1  christos {
    434  1.1  christos   return (kind >= AARCH64_MOD_ROR && kind <= AARCH64_MOD_LSL)
    435  1.1  christos     ? TRUE : FALSE;
    436  1.1  christos }
    437  1.1  christos 
    438  1.1  christos const struct aarch64_name_value_pair aarch64_barrier_options[16] =
    439  1.1  christos {
    440  1.1  christos     { "#0x00", 0x0 },
    441  1.1  christos     { "oshld", 0x1 },
    442  1.1  christos     { "oshst", 0x2 },
    443  1.1  christos     { "osh",   0x3 },
    444  1.1  christos     { "#0x04", 0x4 },
    445  1.1  christos     { "nshld", 0x5 },
    446  1.1  christos     { "nshst", 0x6 },
    447  1.1  christos     { "nsh",   0x7 },
    448  1.1  christos     { "#0x08", 0x8 },
    449  1.1  christos     { "ishld", 0x9 },
    450  1.1  christos     { "ishst", 0xa },
    451  1.1  christos     { "ish",   0xb },
    452  1.1  christos     { "#0x0c", 0xc },
    453  1.1  christos     { "ld",    0xd },
    454  1.1  christos     { "st",    0xe },
    455  1.1  christos     { "sy",    0xf },
    456  1.1  christos };
    457  1.6  christos 
    458  1.6  christos /* Table describing the operands supported by the aliases of the HINT
    459  1.6  christos    instruction.
    460  1.6  christos 
    461  1.6  christos    The name column is the operand that is accepted for the alias.  The value
    462  1.6  christos    column is the hint number of the alias.  The list of operands is terminated
    463  1.6  christos    by NULL in the name column.  */
    464  1.6  christos 
    465  1.6  christos const struct aarch64_name_value_pair aarch64_hint_options[] =
    466  1.6  christos {
    467  1.6  christos   { "csync", 0x11 },    /* PSB CSYNC.  */
    468  1.6  christos   { NULL, 0x0 },
    469  1.6  christos };
    470  1.1  christos 
    471  1.1  christos /* op -> op:       load = 0 instruction = 1 store = 2
    472  1.1  christos    l  -> level:    1-3
    473  1.1  christos    t  -> temporal: temporal (retained) = 0 non-temporal (streaming) = 1   */
    474  1.1  christos #define B(op,l,t) (((op) << 3) | (((l) - 1) << 1) | (t))
    475  1.1  christos const struct aarch64_name_value_pair aarch64_prfops[32] =
    476  1.1  christos {
    477  1.1  christos   { "pldl1keep", B(0, 1, 0) },
    478  1.1  christos   { "pldl1strm", B(0, 1, 1) },
    479  1.1  christos   { "pldl2keep", B(0, 2, 0) },
    480  1.1  christos   { "pldl2strm", B(0, 2, 1) },
    481  1.1  christos   { "pldl3keep", B(0, 3, 0) },
    482  1.1  christos   { "pldl3strm", B(0, 3, 1) },
    483  1.1  christos   { NULL, 0x06 },
    484  1.1  christos   { NULL, 0x07 },
    485  1.1  christos   { "plil1keep", B(1, 1, 0) },
    486  1.1  christos   { "plil1strm", B(1, 1, 1) },
    487  1.1  christos   { "plil2keep", B(1, 2, 0) },
    488  1.1  christos   { "plil2strm", B(1, 2, 1) },
    489  1.1  christos   { "plil3keep", B(1, 3, 0) },
    490  1.1  christos   { "plil3strm", B(1, 3, 1) },
    491  1.1  christos   { NULL, 0x0e },
    492  1.1  christos   { NULL, 0x0f },
    493  1.1  christos   { "pstl1keep", B(2, 1, 0) },
    494  1.1  christos   { "pstl1strm", B(2, 1, 1) },
    495  1.1  christos   { "pstl2keep", B(2, 2, 0) },
    496  1.1  christos   { "pstl2strm", B(2, 2, 1) },
    497  1.1  christos   { "pstl3keep", B(2, 3, 0) },
    498  1.1  christos   { "pstl3strm", B(2, 3, 1) },
    499  1.1  christos   { NULL, 0x16 },
    500  1.1  christos   { NULL, 0x17 },
    501  1.1  christos   { NULL, 0x18 },
    502  1.1  christos   { NULL, 0x19 },
    503  1.1  christos   { NULL, 0x1a },
    504  1.1  christos   { NULL, 0x1b },
    505  1.1  christos   { NULL, 0x1c },
    506  1.1  christos   { NULL, 0x1d },
    507  1.1  christos   { NULL, 0x1e },
    508  1.1  christos   { NULL, 0x1f },
    509  1.1  christos };
    510  1.1  christos #undef B
    511  1.1  christos 
    512  1.1  christos /* Utilities on value constraint.  */
    514  1.1  christos 
    515  1.1  christos static inline int
    516  1.1  christos value_in_range_p (int64_t value, int low, int high)
    517  1.1  christos {
    518  1.1  christos   return (value >= low && value <= high) ? 1 : 0;
    519  1.7  christos }
    520  1.1  christos 
    521  1.1  christos /* Return true if VALUE is a multiple of ALIGN.  */
    522  1.1  christos static inline int
    523  1.7  christos value_aligned_p (int64_t value, int align)
    524  1.1  christos {
    525  1.1  christos   return (value % align) == 0;
    526  1.1  christos }
    527  1.1  christos 
    528  1.1  christos /* A signed value fits in a field.  */
    529  1.1  christos static inline int
    530  1.1  christos value_fit_signed_field_p (int64_t value, unsigned width)
    531  1.1  christos {
    532  1.1  christos   assert (width < 32);
    533  1.1  christos   if (width < sizeof (value) * 8)
    534  1.1  christos     {
    535  1.1  christos       int64_t lim = (int64_t)1 << (width - 1);
    536  1.1  christos       if (value >= -lim && value < lim)
    537  1.1  christos 	return 1;
    538  1.1  christos     }
    539  1.1  christos   return 0;
    540  1.1  christos }
    541  1.1  christos 
    542  1.1  christos /* An unsigned value fits in a field.  */
    543  1.1  christos static inline int
    544  1.1  christos value_fit_unsigned_field_p (int64_t value, unsigned width)
    545  1.1  christos {
    546  1.1  christos   assert (width < 32);
    547  1.1  christos   if (width < sizeof (value) * 8)
    548  1.1  christos     {
    549  1.1  christos       int64_t lim = (int64_t)1 << width;
    550  1.1  christos       if (value >= 0 && value < lim)
    551  1.1  christos 	return 1;
    552  1.1  christos     }
    553  1.1  christos   return 0;
    554  1.1  christos }
    555  1.1  christos 
    556  1.1  christos /* Return 1 if OPERAND is SP or WSP.  */
    557  1.1  christos int
    558  1.1  christos aarch64_stack_pointer_p (const aarch64_opnd_info *operand)
    559  1.1  christos {
    560  1.1  christos   return ((aarch64_get_operand_class (operand->type)
    561  1.1  christos 	   == AARCH64_OPND_CLASS_INT_REG)
    562  1.1  christos 	  && operand_maybe_stack_pointer (aarch64_operands + operand->type)
    563  1.1  christos 	  && operand->reg.regno == 31);
    564  1.1  christos }
    565  1.1  christos 
    566  1.1  christos /* Return 1 if OPERAND is XZR or WZP.  */
    567  1.1  christos int
    568  1.1  christos aarch64_zero_register_p (const aarch64_opnd_info *operand)
    569  1.1  christos {
    570  1.1  christos   return ((aarch64_get_operand_class (operand->type)
    571  1.1  christos 	   == AARCH64_OPND_CLASS_INT_REG)
    572  1.1  christos 	  && !operand_maybe_stack_pointer (aarch64_operands + operand->type)
    573  1.1  christos 	  && operand->reg.regno == 31);
    574  1.1  christos }
    575  1.1  christos 
    576  1.1  christos /* Return true if the operand *OPERAND that has the operand code
    577  1.1  christos    OPERAND->TYPE and been qualified by OPERAND->QUALIFIER can be also
    578  1.1  christos    qualified by the qualifier TARGET.  */
    579  1.1  christos 
    580  1.1  christos static inline int
    581  1.1  christos operand_also_qualified_p (const struct aarch64_opnd_info *operand,
    582  1.1  christos 			  aarch64_opnd_qualifier_t target)
    583  1.1  christos {
    584  1.1  christos   switch (operand->qualifier)
    585  1.1  christos     {
    586  1.1  christos     case AARCH64_OPND_QLF_W:
    587  1.1  christos       if (target == AARCH64_OPND_QLF_WSP && aarch64_stack_pointer_p (operand))
    588  1.1  christos 	return 1;
    589  1.1  christos       break;
    590  1.1  christos     case AARCH64_OPND_QLF_X:
    591  1.1  christos       if (target == AARCH64_OPND_QLF_SP && aarch64_stack_pointer_p (operand))
    592  1.1  christos 	return 1;
    593  1.1  christos       break;
    594  1.1  christos     case AARCH64_OPND_QLF_WSP:
    595  1.1  christos       if (target == AARCH64_OPND_QLF_W
    596  1.1  christos 	  && operand_maybe_stack_pointer (aarch64_operands + operand->type))
    597  1.1  christos 	return 1;
    598  1.1  christos       break;
    599  1.1  christos     case AARCH64_OPND_QLF_SP:
    600  1.1  christos       if (target == AARCH64_OPND_QLF_X
    601  1.1  christos 	  && operand_maybe_stack_pointer (aarch64_operands + operand->type))
    602  1.1  christos 	return 1;
    603  1.1  christos       break;
    604  1.1  christos     default:
    605  1.1  christos       break;
    606  1.1  christos     }
    607  1.1  christos 
    608  1.1  christos   return 0;
    609  1.1  christos }
    610  1.1  christos 
    611  1.1  christos /* Given qualifier sequence list QSEQ_LIST and the known qualifier KNOWN_QLF
    612  1.1  christos    for operand KNOWN_IDX, return the expected qualifier for operand IDX.
    613  1.1  christos 
    614  1.1  christos    Return NIL if more than one expected qualifiers are found.  */
    615  1.1  christos 
    616  1.1  christos aarch64_opnd_qualifier_t
    617  1.1  christos aarch64_get_expected_qualifier (const aarch64_opnd_qualifier_seq_t *qseq_list,
    618  1.1  christos 				int idx,
    619  1.1  christos 				const aarch64_opnd_qualifier_t known_qlf,
    620  1.1  christos 				int known_idx)
    621  1.1  christos {
    622  1.1  christos   int i, saved_i;
    623  1.1  christos 
    624  1.1  christos   /* Special case.
    625  1.1  christos 
    626  1.1  christos      When the known qualifier is NIL, we have to assume that there is only
    627  1.1  christos      one qualifier sequence in the *QSEQ_LIST and return the corresponding
    628  1.1  christos      qualifier directly.  One scenario is that for instruction
    629  1.1  christos 	PRFM <prfop>, [<Xn|SP>, #:lo12:<symbol>]
    630  1.1  christos      which has only one possible valid qualifier sequence
    631  1.1  christos 	NIL, S_D
    632  1.1  christos      the caller may pass NIL in KNOWN_QLF to obtain S_D so that it can
    633  1.1  christos      determine the correct relocation type (i.e. LDST64_LO12) for PRFM.
    634  1.1  christos 
    635  1.1  christos      Because the qualifier NIL has dual roles in the qualifier sequence:
    636  1.1  christos      it can mean no qualifier for the operand, or the qualifer sequence is
    637  1.1  christos      not in use (when all qualifiers in the sequence are NILs), we have to
    638  1.1  christos      handle this special case here.  */
    639  1.1  christos   if (known_qlf == AARCH64_OPND_NIL)
    640  1.1  christos     {
    641  1.1  christos       assert (qseq_list[0][known_idx] == AARCH64_OPND_NIL);
    642  1.1  christos       return qseq_list[0][idx];
    643  1.1  christos     }
    644  1.1  christos 
    645  1.1  christos   for (i = 0, saved_i = -1; i < AARCH64_MAX_QLF_SEQ_NUM; ++i)
    646  1.1  christos     {
    647  1.1  christos       if (qseq_list[i][known_idx] == known_qlf)
    648  1.1  christos 	{
    649  1.1  christos 	  if (saved_i != -1)
    650  1.1  christos 	    /* More than one sequences are found to have KNOWN_QLF at
    651  1.1  christos 	       KNOWN_IDX.  */
    652  1.1  christos 	    return AARCH64_OPND_NIL;
    653  1.1  christos 	  saved_i = i;
    654  1.1  christos 	}
    655  1.1  christos     }
    656  1.1  christos 
    657  1.1  christos   return qseq_list[saved_i][idx];
    658  1.1  christos }
    659  1.1  christos 
    660  1.1  christos enum operand_qualifier_kind
    661  1.1  christos {
    662  1.1  christos   OQK_NIL,
    663  1.1  christos   OQK_OPD_VARIANT,
    664  1.1  christos   OQK_VALUE_IN_RANGE,
    665  1.1  christos   OQK_MISC,
    666  1.1  christos };
    667  1.1  christos 
    668  1.1  christos /* Operand qualifier description.  */
    669  1.1  christos struct operand_qualifier_data
    670  1.1  christos {
    671  1.1  christos   /* The usage of the three data fields depends on the qualifier kind.  */
    672  1.1  christos   int data0;
    673  1.1  christos   int data1;
    674  1.1  christos   int data2;
    675  1.1  christos   /* Description.  */
    676  1.1  christos   const char *desc;
    677  1.1  christos   /* Kind.  */
    678  1.1  christos   enum operand_qualifier_kind kind;
    679  1.1  christos };
    680  1.1  christos 
    681  1.1  christos /* Indexed by the operand qualifier enumerators.  */
    682  1.1  christos struct operand_qualifier_data aarch64_opnd_qualifiers[] =
    683  1.1  christos {
    684  1.1  christos   {0, 0, 0, "NIL", OQK_NIL},
    685  1.1  christos 
    686  1.1  christos   /* Operand variant qualifiers.
    687  1.1  christos      First 3 fields:
    688  1.1  christos      element size, number of elements and common value for encoding.  */
    689  1.1  christos 
    690  1.1  christos   {4, 1, 0x0, "w", OQK_OPD_VARIANT},
    691  1.1  christos   {8, 1, 0x1, "x", OQK_OPD_VARIANT},
    692  1.1  christos   {4, 1, 0x0, "wsp", OQK_OPD_VARIANT},
    693  1.1  christos   {8, 1, 0x1, "sp", OQK_OPD_VARIANT},
    694  1.1  christos 
    695  1.1  christos   {1, 1, 0x0, "b", OQK_OPD_VARIANT},
    696  1.1  christos   {2, 1, 0x1, "h", OQK_OPD_VARIANT},
    697  1.1  christos   {4, 1, 0x2, "s", OQK_OPD_VARIANT},
    698  1.1  christos   {8, 1, 0x3, "d", OQK_OPD_VARIANT},
    699  1.1  christos   {16, 1, 0x4, "q", OQK_OPD_VARIANT},
    700  1.1  christos 
    701  1.6  christos   {1, 8, 0x0, "8b", OQK_OPD_VARIANT},
    702  1.1  christos   {1, 16, 0x1, "16b", OQK_OPD_VARIANT},
    703  1.1  christos   {2, 2, 0x0, "2h", OQK_OPD_VARIANT},
    704  1.1  christos   {2, 4, 0x2, "4h", OQK_OPD_VARIANT},
    705  1.1  christos   {2, 8, 0x3, "8h", OQK_OPD_VARIANT},
    706  1.1  christos   {4, 2, 0x4, "2s", OQK_OPD_VARIANT},
    707  1.1  christos   {4, 4, 0x5, "4s", OQK_OPD_VARIANT},
    708  1.1  christos   {8, 1, 0x6, "1d", OQK_OPD_VARIANT},
    709  1.1  christos   {8, 2, 0x7, "2d", OQK_OPD_VARIANT},
    710  1.7  christos   {16, 1, 0x8, "1q", OQK_OPD_VARIANT},
    711  1.7  christos 
    712  1.7  christos   {0, 0, 0, "z", OQK_OPD_VARIANT},
    713  1.1  christos   {0, 0, 0, "m", OQK_OPD_VARIANT},
    714  1.1  christos 
    715  1.1  christos   /* Qualifiers constraining the value range.
    716  1.1  christos      First 3 fields:
    717  1.7  christos      Lower bound, higher bound, unused.  */
    718  1.1  christos 
    719  1.1  christos   {0, 15, 0, "CR",       OQK_VALUE_IN_RANGE},
    720  1.1  christos   {0,  7, 0, "imm_0_7" , OQK_VALUE_IN_RANGE},
    721  1.1  christos   {0, 15, 0, "imm_0_15", OQK_VALUE_IN_RANGE},
    722  1.1  christos   {0, 31, 0, "imm_0_31", OQK_VALUE_IN_RANGE},
    723  1.1  christos   {0, 63, 0, "imm_0_63", OQK_VALUE_IN_RANGE},
    724  1.1  christos   {1, 32, 0, "imm_1_32", OQK_VALUE_IN_RANGE},
    725  1.1  christos   {1, 64, 0, "imm_1_64", OQK_VALUE_IN_RANGE},
    726  1.1  christos 
    727  1.1  christos   /* Qualifiers for miscellaneous purpose.
    728  1.1  christos      First 3 fields:
    729  1.1  christos      unused, unused and unused.  */
    730  1.1  christos 
    731  1.1  christos   {0, 0, 0, "lsl", 0},
    732  1.1  christos   {0, 0, 0, "msl", 0},
    733  1.1  christos 
    734  1.1  christos   {0, 0, 0, "retrieving", 0},
    735  1.1  christos };
    736  1.1  christos 
    737  1.1  christos static inline bfd_boolean
    738  1.1  christos operand_variant_qualifier_p (aarch64_opnd_qualifier_t qualifier)
    739  1.1  christos {
    740  1.1  christos   return (aarch64_opnd_qualifiers[qualifier].kind == OQK_OPD_VARIANT)
    741  1.1  christos     ? TRUE : FALSE;
    742  1.1  christos }
    743  1.1  christos 
    744  1.1  christos static inline bfd_boolean
    745  1.1  christos qualifier_value_in_range_constraint_p (aarch64_opnd_qualifier_t qualifier)
    746  1.1  christos {
    747  1.1  christos   return (aarch64_opnd_qualifiers[qualifier].kind == OQK_VALUE_IN_RANGE)
    748  1.1  christos     ? TRUE : FALSE;
    749  1.1  christos }
    750  1.1  christos 
    751  1.1  christos const char*
    752  1.1  christos aarch64_get_qualifier_name (aarch64_opnd_qualifier_t qualifier)
    753  1.1  christos {
    754  1.1  christos   return aarch64_opnd_qualifiers[qualifier].desc;
    755  1.1  christos }
    756  1.1  christos 
    757  1.1  christos /* Given an operand qualifier, return the expected data element size
    758  1.1  christos    of a qualified operand.  */
    759  1.1  christos unsigned char
    760  1.1  christos aarch64_get_qualifier_esize (aarch64_opnd_qualifier_t qualifier)
    761  1.1  christos {
    762  1.1  christos   assert (operand_variant_qualifier_p (qualifier) == TRUE);
    763  1.1  christos   return aarch64_opnd_qualifiers[qualifier].data0;
    764  1.1  christos }
    765  1.1  christos 
    766  1.1  christos unsigned char
    767  1.1  christos aarch64_get_qualifier_nelem (aarch64_opnd_qualifier_t qualifier)
    768  1.1  christos {
    769  1.1  christos   assert (operand_variant_qualifier_p (qualifier) == TRUE);
    770  1.1  christos   return aarch64_opnd_qualifiers[qualifier].data1;
    771  1.1  christos }
    772  1.1  christos 
    773  1.1  christos aarch64_insn
    774  1.1  christos aarch64_get_qualifier_standard_value (aarch64_opnd_qualifier_t qualifier)
    775  1.1  christos {
    776  1.1  christos   assert (operand_variant_qualifier_p (qualifier) == TRUE);
    777  1.1  christos   return aarch64_opnd_qualifiers[qualifier].data2;
    778  1.1  christos }
    779  1.1  christos 
    780  1.1  christos static int
    781  1.1  christos get_lower_bound (aarch64_opnd_qualifier_t qualifier)
    782  1.1  christos {
    783  1.1  christos   assert (qualifier_value_in_range_constraint_p (qualifier) == TRUE);
    784  1.1  christos   return aarch64_opnd_qualifiers[qualifier].data0;
    785  1.1  christos }
    786  1.1  christos 
    787  1.1  christos static int
    788  1.1  christos get_upper_bound (aarch64_opnd_qualifier_t qualifier)
    789  1.1  christos {
    790  1.1  christos   assert (qualifier_value_in_range_constraint_p (qualifier) == TRUE);
    791  1.1  christos   return aarch64_opnd_qualifiers[qualifier].data1;
    792  1.1  christos }
    793  1.1  christos 
    794  1.1  christos #ifdef DEBUG_AARCH64
    795  1.1  christos void
    796  1.1  christos aarch64_verbose (const char *str, ...)
    797  1.1  christos {
    798  1.1  christos   va_list ap;
    799  1.1  christos   va_start (ap, str);
    800  1.1  christos   printf ("#### ");
    801  1.1  christos   vprintf (str, ap);
    802  1.1  christos   printf ("\n");
    803  1.1  christos   va_end (ap);
    804  1.1  christos }
    805  1.1  christos 
    806  1.1  christos static inline void
    807  1.1  christos dump_qualifier_sequence (const aarch64_opnd_qualifier_t *qualifier)
    808  1.1  christos {
    809  1.1  christos   int i;
    810  1.1  christos   printf ("#### \t");
    811  1.1  christos   for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i, ++qualifier)
    812  1.1  christos     printf ("%s,", aarch64_get_qualifier_name (*qualifier));
    813  1.1  christos   printf ("\n");
    814  1.1  christos }
    815  1.1  christos 
    816  1.1  christos static void
    817  1.1  christos dump_match_qualifiers (const struct aarch64_opnd_info *opnd,
    818  1.1  christos 		       const aarch64_opnd_qualifier_t *qualifier)
    819  1.1  christos {
    820  1.1  christos   int i;
    821  1.1  christos   aarch64_opnd_qualifier_t curr[AARCH64_MAX_OPND_NUM];
    822  1.1  christos 
    823  1.1  christos   aarch64_verbose ("dump_match_qualifiers:");
    824  1.1  christos   for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
    825  1.1  christos     curr[i] = opnd[i].qualifier;
    826  1.1  christos   dump_qualifier_sequence (curr);
    827  1.1  christos   aarch64_verbose ("against");
    828  1.1  christos   dump_qualifier_sequence (qualifier);
    829  1.1  christos }
    830  1.1  christos #endif /* DEBUG_AARCH64 */
    831  1.1  christos 
    832  1.1  christos /* TODO improve this, we can have an extra field at the runtime to
    833  1.1  christos    store the number of operands rather than calculating it every time.  */
    834  1.1  christos 
    835  1.1  christos int
    836  1.1  christos aarch64_num_of_operands (const aarch64_opcode *opcode)
    837  1.1  christos {
    838  1.1  christos   int i = 0;
    839  1.1  christos   const enum aarch64_opnd *opnds = opcode->operands;
    840  1.1  christos   while (opnds[i++] != AARCH64_OPND_NIL)
    841  1.1  christos     ;
    842  1.1  christos   --i;
    843  1.1  christos   assert (i >= 0 && i <= AARCH64_MAX_OPND_NUM);
    844  1.1  christos   return i;
    845  1.1  christos }
    846  1.1  christos 
    847  1.1  christos /* Find the best matched qualifier sequence in *QUALIFIERS_LIST for INST.
    848  1.1  christos    If succeeds, fill the found sequence in *RET, return 1; otherwise return 0.
    849  1.1  christos 
    850  1.1  christos    N.B. on the entry, it is very likely that only some operands in *INST
    851  1.1  christos    have had their qualifiers been established.
    852  1.1  christos 
    853  1.1  christos    If STOP_AT is not -1, the function will only try to match
    854  1.1  christos    the qualifier sequence for operands before and including the operand
    855  1.1  christos    of index STOP_AT; and on success *RET will only be filled with the first
    856  1.1  christos    (STOP_AT+1) qualifiers.
    857  1.1  christos 
    858  1.1  christos    A couple examples of the matching algorithm:
    859  1.1  christos 
    860  1.1  christos    X,W,NIL should match
    861  1.1  christos    X,W,NIL
    862  1.1  christos 
    863  1.1  christos    NIL,NIL should match
    864  1.1  christos    X  ,NIL
    865  1.1  christos 
    866  1.1  christos    Apart from serving the main encoding routine, this can also be called
    867  1.1  christos    during or after the operand decoding.  */
    868  1.1  christos 
    869  1.1  christos int
    870  1.1  christos aarch64_find_best_match (const aarch64_inst *inst,
    871  1.1  christos 			 const aarch64_opnd_qualifier_seq_t *qualifiers_list,
    872  1.1  christos 			 int stop_at, aarch64_opnd_qualifier_t *ret)
    873  1.1  christos {
    874  1.1  christos   int found = 0;
    875  1.1  christos   int i, num_opnds;
    876  1.1  christos   const aarch64_opnd_qualifier_t *qualifiers;
    877  1.1  christos 
    878  1.1  christos   num_opnds = aarch64_num_of_operands (inst->opcode);
    879  1.1  christos   if (num_opnds == 0)
    880  1.1  christos     {
    881  1.1  christos       DEBUG_TRACE ("SUCCEED: no operand");
    882  1.1  christos       return 1;
    883  1.1  christos     }
    884  1.1  christos 
    885  1.1  christos   if (stop_at < 0 || stop_at >= num_opnds)
    886  1.1  christos     stop_at = num_opnds - 1;
    887  1.1  christos 
    888  1.1  christos   /* For each pattern.  */
    889  1.1  christos   for (i = 0; i < AARCH64_MAX_QLF_SEQ_NUM; ++i, ++qualifiers_list)
    890  1.1  christos     {
    891  1.1  christos       int j;
    892  1.1  christos       qualifiers = *qualifiers_list;
    893  1.1  christos 
    894  1.1  christos       /* Start as positive.  */
    895  1.1  christos       found = 1;
    896  1.1  christos 
    897  1.1  christos       DEBUG_TRACE ("%d", i);
    898  1.1  christos #ifdef DEBUG_AARCH64
    899  1.1  christos       if (debug_dump)
    900  1.1  christos 	dump_match_qualifiers (inst->operands, qualifiers);
    901  1.1  christos #endif
    902  1.1  christos 
    903  1.1  christos       /* Most opcodes has much fewer patterns in the list.
    904  1.1  christos 	 First NIL qualifier indicates the end in the list.   */
    905  1.1  christos       if (empty_qualifier_sequence_p (qualifiers) == TRUE)
    906  1.1  christos 	{
    907  1.1  christos 	  DEBUG_TRACE_IF (i == 0, "SUCCEED: empty qualifier list");
    908  1.1  christos 	  if (i)
    909  1.1  christos 	    found = 0;
    910  1.1  christos 	  break;
    911  1.1  christos 	}
    912  1.1  christos 
    913  1.1  christos       for (j = 0; j < num_opnds && j <= stop_at; ++j, ++qualifiers)
    914  1.1  christos 	{
    915  1.1  christos 	  if (inst->operands[j].qualifier == AARCH64_OPND_QLF_NIL)
    916  1.1  christos 	    {
    917  1.1  christos 	      /* Either the operand does not have qualifier, or the qualifier
    918  1.1  christos 		 for the operand needs to be deduced from the qualifier
    919  1.1  christos 		 sequence.
    920  1.1  christos 		 In the latter case, any constraint checking related with
    921  1.1  christos 		 the obtained qualifier should be done later in
    922  1.1  christos 		 operand_general_constraint_met_p.  */
    923  1.1  christos 	      continue;
    924  1.1  christos 	    }
    925  1.1  christos 	  else if (*qualifiers != inst->operands[j].qualifier)
    926  1.1  christos 	    {
    927  1.1  christos 	      /* Unless the target qualifier can also qualify the operand
    928  1.1  christos 		 (which has already had a non-nil qualifier), non-equal
    929  1.1  christos 		 qualifiers are generally un-matched.  */
    930  1.1  christos 	      if (operand_also_qualified_p (inst->operands + j, *qualifiers))
    931  1.1  christos 		continue;
    932  1.1  christos 	      else
    933  1.1  christos 		{
    934  1.1  christos 		  found = 0;
    935  1.1  christos 		  break;
    936  1.1  christos 		}
    937  1.1  christos 	    }
    938  1.1  christos 	  else
    939  1.1  christos 	    continue;	/* Equal qualifiers are certainly matched.  */
    940  1.1  christos 	}
    941  1.1  christos 
    942  1.1  christos       /* Qualifiers established.  */
    943  1.1  christos       if (found == 1)
    944  1.1  christos 	break;
    945  1.1  christos     }
    946  1.1  christos 
    947  1.1  christos   if (found == 1)
    948  1.1  christos     {
    949  1.1  christos       /* Fill the result in *RET.  */
    950  1.1  christos       int j;
    951  1.1  christos       qualifiers = *qualifiers_list;
    952  1.1  christos 
    953  1.1  christos       DEBUG_TRACE ("complete qualifiers using list %d", i);
    954  1.1  christos #ifdef DEBUG_AARCH64
    955  1.1  christos       if (debug_dump)
    956  1.1  christos 	dump_qualifier_sequence (qualifiers);
    957  1.1  christos #endif
    958  1.1  christos 
    959  1.1  christos       for (j = 0; j <= stop_at; ++j, ++qualifiers)
    960  1.1  christos 	ret[j] = *qualifiers;
    961  1.1  christos       for (; j < AARCH64_MAX_OPND_NUM; ++j)
    962  1.1  christos 	ret[j] = AARCH64_OPND_QLF_NIL;
    963  1.1  christos 
    964  1.1  christos       DEBUG_TRACE ("SUCCESS");
    965  1.1  christos       return 1;
    966  1.1  christos     }
    967  1.1  christos 
    968  1.1  christos   DEBUG_TRACE ("FAIL");
    969  1.1  christos   return 0;
    970  1.1  christos }
    971  1.1  christos 
    972  1.1  christos /* Operand qualifier matching and resolving.
    973  1.1  christos 
    974  1.1  christos    Return 1 if the operand qualifier(s) in *INST match one of the qualifier
    975  1.1  christos    sequences in INST->OPCODE->qualifiers_list; otherwise return 0.
    976  1.1  christos 
    977  1.1  christos    if UPDATE_P == TRUE, update the qualifier(s) in *INST after the matching
    978  1.1  christos    succeeds.  */
    979  1.1  christos 
    980  1.1  christos static int
    981  1.7  christos match_operands_qualifier (aarch64_inst *inst, bfd_boolean update_p)
    982  1.1  christos {
    983  1.1  christos   int i, nops;
    984  1.1  christos   aarch64_opnd_qualifier_seq_t qualifiers;
    985  1.1  christos 
    986  1.1  christos   if (!aarch64_find_best_match (inst, inst->opcode->qualifiers_list, -1,
    987  1.1  christos 			       qualifiers))
    988  1.1  christos     {
    989  1.1  christos       DEBUG_TRACE ("matching FAIL");
    990  1.1  christos       return 0;
    991  1.7  christos     }
    992  1.7  christos 
    993  1.7  christos   if (inst->opcode->flags & F_STRICT)
    994  1.7  christos     {
    995  1.7  christos       /* Require an exact qualifier match, even for NIL qualifiers.  */
    996  1.7  christos       nops = aarch64_num_of_operands (inst->opcode);
    997  1.7  christos       for (i = 0; i < nops; ++i)
    998  1.7  christos 	if (inst->operands[i].qualifier != qualifiers[i])
    999  1.7  christos 	  return FALSE;
   1000  1.1  christos     }
   1001  1.1  christos 
   1002  1.1  christos   /* Update the qualifiers.  */
   1003  1.1  christos   if (update_p == TRUE)
   1004  1.1  christos     for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
   1005  1.1  christos       {
   1006  1.1  christos 	if (inst->opcode->operands[i] == AARCH64_OPND_NIL)
   1007  1.1  christos 	  break;
   1008  1.1  christos 	DEBUG_TRACE_IF (inst->operands[i].qualifier != qualifiers[i],
   1009  1.1  christos 			"update %s with %s for operand %d",
   1010  1.1  christos 			aarch64_get_qualifier_name (inst->operands[i].qualifier),
   1011  1.1  christos 			aarch64_get_qualifier_name (qualifiers[i]), i);
   1012  1.1  christos 	inst->operands[i].qualifier = qualifiers[i];
   1013  1.1  christos       }
   1014  1.1  christos 
   1015  1.1  christos   DEBUG_TRACE ("matching SUCCESS");
   1016  1.1  christos   return 1;
   1017  1.1  christos }
   1018  1.1  christos 
   1019  1.1  christos /* Return TRUE if VALUE is a wide constant that can be moved into a general
   1020  1.1  christos    register by MOVZ.
   1021  1.1  christos 
   1022  1.1  christos    IS32 indicates whether value is a 32-bit immediate or not.
   1023  1.1  christos    If SHIFT_AMOUNT is not NULL, on the return of TRUE, the logical left shift
   1024  1.1  christos    amount will be returned in *SHIFT_AMOUNT.  */
   1025  1.1  christos 
   1026  1.1  christos bfd_boolean
   1027  1.1  christos aarch64_wide_constant_p (int64_t value, int is32, unsigned int *shift_amount)
   1028  1.1  christos {
   1029  1.1  christos   int amount;
   1030  1.1  christos 
   1031  1.1  christos   DEBUG_TRACE ("enter with 0x%" PRIx64 "(%" PRIi64 ")", value, value);
   1032  1.1  christos 
   1033  1.1  christos   if (is32)
   1034  1.1  christos     {
   1035  1.1  christos       /* Allow all zeros or all ones in top 32-bits, so that
   1036  1.1  christos 	 32-bit constant expressions like ~0x80000000 are
   1037  1.1  christos 	 permitted.  */
   1038  1.1  christos       uint64_t ext = value;
   1039  1.1  christos       if (ext >> 32 != 0 && ext >> 32 != (uint64_t) 0xffffffff)
   1040  1.1  christos 	/* Immediate out of range.  */
   1041  1.1  christos 	return FALSE;
   1042  1.1  christos       value &= (int64_t) 0xffffffff;
   1043  1.1  christos     }
   1044  1.1  christos 
   1045  1.1  christos   /* first, try movz then movn */
   1046  1.1  christos   amount = -1;
   1047  1.1  christos   if ((value & ((int64_t) 0xffff << 0)) == value)
   1048  1.1  christos     amount = 0;
   1049  1.1  christos   else if ((value & ((int64_t) 0xffff << 16)) == value)
   1050  1.1  christos     amount = 16;
   1051  1.1  christos   else if (!is32 && (value & ((int64_t) 0xffff << 32)) == value)
   1052  1.1  christos     amount = 32;
   1053  1.1  christos   else if (!is32 && (value & ((int64_t) 0xffff << 48)) == value)
   1054  1.1  christos     amount = 48;
   1055  1.1  christos 
   1056  1.1  christos   if (amount == -1)
   1057  1.1  christos     {
   1058  1.1  christos       DEBUG_TRACE ("exit FALSE with 0x%" PRIx64 "(%" PRIi64 ")", value, value);
   1059  1.1  christos       return FALSE;
   1060  1.1  christos     }
   1061  1.1  christos 
   1062  1.1  christos   if (shift_amount != NULL)
   1063  1.1  christos     *shift_amount = amount;
   1064  1.1  christos 
   1065  1.1  christos   DEBUG_TRACE ("exit TRUE with amount %d", amount);
   1066  1.1  christos 
   1067  1.1  christos   return TRUE;
   1068  1.1  christos }
   1069  1.1  christos 
   1070  1.1  christos /* Build the accepted values for immediate logical SIMD instructions.
   1071  1.1  christos 
   1072  1.1  christos    The standard encodings of the immediate value are:
   1073  1.1  christos      N      imms     immr         SIMD size  R             S
   1074  1.1  christos      1      ssssss   rrrrrr       64      UInt(rrrrrr)  UInt(ssssss)
   1075  1.1  christos      0      0sssss   0rrrrr       32      UInt(rrrrr)   UInt(sssss)
   1076  1.1  christos      0      10ssss   00rrrr       16      UInt(rrrr)    UInt(ssss)
   1077  1.1  christos      0      110sss   000rrr       8       UInt(rrr)     UInt(sss)
   1078  1.1  christos      0      1110ss   0000rr       4       UInt(rr)      UInt(ss)
   1079  1.1  christos      0      11110s   00000r       2       UInt(r)       UInt(s)
   1080  1.1  christos    where all-ones value of S is reserved.
   1081  1.1  christos 
   1082  1.1  christos    Let's call E the SIMD size.
   1083  1.1  christos 
   1084  1.1  christos    The immediate value is: S+1 bits '1' rotated to the right by R.
   1085  1.1  christos 
   1086  1.1  christos    The total of valid encodings is 64*63 + 32*31 + ... + 2*1 = 5334
   1087  1.1  christos    (remember S != E - 1).  */
   1088  1.1  christos 
   1089  1.1  christos #define TOTAL_IMM_NB  5334
   1090  1.1  christos 
   1091  1.1  christos typedef struct
   1092  1.1  christos {
   1093  1.1  christos   uint64_t imm;
   1094  1.1  christos   aarch64_insn encoding;
   1095  1.1  christos } simd_imm_encoding;
   1096  1.1  christos 
   1097  1.1  christos static simd_imm_encoding simd_immediates[TOTAL_IMM_NB];
   1098  1.1  christos 
   1099  1.1  christos static int
   1100  1.1  christos simd_imm_encoding_cmp(const void *i1, const void *i2)
   1101  1.1  christos {
   1102  1.1  christos   const simd_imm_encoding *imm1 = (const simd_imm_encoding *)i1;
   1103  1.1  christos   const simd_imm_encoding *imm2 = (const simd_imm_encoding *)i2;
   1104  1.1  christos 
   1105  1.1  christos   if (imm1->imm < imm2->imm)
   1106  1.1  christos     return -1;
   1107  1.1  christos   if (imm1->imm > imm2->imm)
   1108  1.1  christos     return +1;
   1109  1.1  christos   return 0;
   1110  1.1  christos }
   1111  1.1  christos 
   1112  1.1  christos /* immediate bitfield standard encoding
   1113  1.1  christos    imm13<12> imm13<5:0> imm13<11:6> SIMD size R      S
   1114  1.1  christos    1         ssssss     rrrrrr      64        rrrrrr ssssss
   1115  1.1  christos    0         0sssss     0rrrrr      32        rrrrr  sssss
   1116  1.1  christos    0         10ssss     00rrrr      16        rrrr   ssss
   1117  1.1  christos    0         110sss     000rrr      8         rrr    sss
   1118  1.1  christos    0         1110ss     0000rr      4         rr     ss
   1119  1.1  christos    0         11110s     00000r      2         r      s  */
   1120  1.1  christos static inline int
   1121  1.1  christos encode_immediate_bitfield (int is64, uint32_t s, uint32_t r)
   1122  1.1  christos {
   1123  1.1  christos   return (is64 << 12) | (r << 6) | s;
   1124  1.1  christos }
   1125  1.1  christos 
   1126  1.1  christos static void
   1127  1.1  christos build_immediate_table (void)
   1128  1.1  christos {
   1129  1.1  christos   uint32_t log_e, e, s, r, s_mask;
   1130  1.1  christos   uint64_t mask, imm;
   1131  1.1  christos   int nb_imms;
   1132  1.1  christos   int is64;
   1133  1.1  christos 
   1134  1.1  christos   nb_imms = 0;
   1135  1.1  christos   for (log_e = 1; log_e <= 6; log_e++)
   1136  1.1  christos     {
   1137  1.1  christos       /* Get element size.  */
   1138  1.1  christos       e = 1u << log_e;
   1139  1.1  christos       if (log_e == 6)
   1140  1.1  christos 	{
   1141  1.1  christos 	  is64 = 1;
   1142  1.1  christos 	  mask = 0xffffffffffffffffull;
   1143  1.1  christos 	  s_mask = 0;
   1144  1.1  christos 	}
   1145  1.1  christos       else
   1146  1.1  christos 	{
   1147  1.1  christos 	  is64 = 0;
   1148  1.1  christos 	  mask = (1ull << e) - 1;
   1149  1.1  christos 	  /* log_e  s_mask
   1150  1.1  christos 	     1     ((1 << 4) - 1) << 2 = 111100
   1151  1.1  christos 	     2     ((1 << 3) - 1) << 3 = 111000
   1152  1.1  christos 	     3     ((1 << 2) - 1) << 4 = 110000
   1153  1.1  christos 	     4     ((1 << 1) - 1) << 5 = 100000
   1154  1.1  christos 	     5     ((1 << 0) - 1) << 6 = 000000  */
   1155  1.1  christos 	  s_mask = ((1u << (5 - log_e)) - 1) << (log_e + 1);
   1156  1.1  christos 	}
   1157  1.1  christos       for (s = 0; s < e - 1; s++)
   1158  1.1  christos 	for (r = 0; r < e; r++)
   1159  1.1  christos 	  {
   1160  1.1  christos 	    /* s+1 consecutive bits to 1 (s < 63) */
   1161  1.1  christos 	    imm = (1ull << (s + 1)) - 1;
   1162  1.1  christos 	    /* rotate right by r */
   1163  1.1  christos 	    if (r != 0)
   1164  1.1  christos 	      imm = (imm >> r) | ((imm << (e - r)) & mask);
   1165  1.1  christos 	    /* replicate the constant depending on SIMD size */
   1166  1.1  christos 	    switch (log_e)
   1167  1.7  christos 	      {
   1168  1.1  christos 	      case 1: imm = (imm <<  2) | imm;
   1169  1.7  christos 		/* Fall through.  */
   1170  1.1  christos 	      case 2: imm = (imm <<  4) | imm;
   1171  1.7  christos 		/* Fall through.  */
   1172  1.1  christos 	      case 3: imm = (imm <<  8) | imm;
   1173  1.7  christos 		/* Fall through.  */
   1174  1.1  christos 	      case 4: imm = (imm << 16) | imm;
   1175  1.7  christos 		/* Fall through.  */
   1176  1.1  christos 	      case 5: imm = (imm << 32) | imm;
   1177  1.1  christos 		/* Fall through.  */
   1178  1.1  christos 	      case 6: break;
   1179  1.1  christos 	      default: abort ();
   1180  1.1  christos 	      }
   1181  1.1  christos 	    simd_immediates[nb_imms].imm = imm;
   1182  1.1  christos 	    simd_immediates[nb_imms].encoding =
   1183  1.1  christos 	      encode_immediate_bitfield(is64, s | s_mask, r);
   1184  1.1  christos 	    nb_imms++;
   1185  1.1  christos 	  }
   1186  1.1  christos     }
   1187  1.1  christos   assert (nb_imms == TOTAL_IMM_NB);
   1188  1.1  christos   qsort(simd_immediates, nb_imms,
   1189  1.1  christos 	sizeof(simd_immediates[0]), simd_imm_encoding_cmp);
   1190  1.1  christos }
   1191  1.1  christos 
   1192  1.1  christos /* Return TRUE if VALUE is a valid logical immediate, i.e. bitmask, that can
   1193  1.1  christos    be accepted by logical (immediate) instructions
   1194  1.7  christos    e.g. ORR <Xd|SP>, <Xn>, #<imm>.
   1195  1.1  christos 
   1196  1.1  christos    ESIZE is the number of bytes in the decoded immediate value.
   1197  1.1  christos    If ENCODING is not NULL, on the return of TRUE, the standard encoding for
   1198  1.1  christos    VALUE will be returned in *ENCODING.  */
   1199  1.7  christos 
   1200  1.1  christos bfd_boolean
   1201  1.1  christos aarch64_logical_immediate_p (uint64_t value, int esize, aarch64_insn *encoding)
   1202  1.1  christos {
   1203  1.1  christos   simd_imm_encoding imm_enc;
   1204  1.7  christos   const simd_imm_encoding *imm_encoding;
   1205  1.7  christos   static bfd_boolean initialized = FALSE;
   1206  1.1  christos   uint64_t upper;
   1207  1.1  christos   int i;
   1208  1.1  christos 
   1209  1.1  christos   DEBUG_TRACE ("enter with 0x%" PRIx64 "(%" PRIi64 "), is32: %d", value,
   1210  1.1  christos 	       value, is32);
   1211  1.1  christos 
   1212  1.1  christos   if (initialized == FALSE)
   1213  1.1  christos     {
   1214  1.1  christos       build_immediate_table ();
   1215  1.1  christos       initialized = TRUE;
   1216  1.7  christos     }
   1217  1.7  christos 
   1218  1.7  christos   /* Allow all zeros or all ones in top bits, so that
   1219  1.7  christos      constant expressions like ~1 are permitted.  */
   1220  1.7  christos   upper = (uint64_t) -1 << (esize * 4) << (esize * 4);
   1221  1.1  christos   if ((value & ~upper) != value && (value | upper) != value)
   1222  1.7  christos     return FALSE;
   1223  1.7  christos 
   1224  1.7  christos   /* Replicate to a full 64-bit value.  */
   1225  1.7  christos   value &= ~upper;
   1226  1.1  christos   for (i = esize * 8; i < 64; i *= 2)
   1227  1.1  christos     value |= (value << i);
   1228  1.1  christos 
   1229  1.1  christos   imm_enc.imm = value;
   1230  1.1  christos   imm_encoding = (const simd_imm_encoding *)
   1231  1.1  christos     bsearch(&imm_enc, simd_immediates, TOTAL_IMM_NB,
   1232  1.1  christos             sizeof(simd_immediates[0]), simd_imm_encoding_cmp);
   1233  1.1  christos   if (imm_encoding == NULL)
   1234  1.1  christos     {
   1235  1.1  christos       DEBUG_TRACE ("exit with FALSE");
   1236  1.1  christos       return FALSE;
   1237  1.1  christos     }
   1238  1.1  christos   if (encoding != NULL)
   1239  1.1  christos     *encoding = imm_encoding->encoding;
   1240  1.1  christos   DEBUG_TRACE ("exit with TRUE");
   1241  1.1  christos   return TRUE;
   1242  1.1  christos }
   1243  1.1  christos 
   1244  1.1  christos /* If 64-bit immediate IMM is in the format of
   1245  1.1  christos    "aaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeffffffffgggggggghhhhhhhh",
   1246  1.1  christos    where a, b, c, d, e, f, g and h are independently 0 or 1, return an integer
   1247  1.1  christos    of value "abcdefgh".  Otherwise return -1.  */
   1248  1.1  christos int
   1249  1.1  christos aarch64_shrink_expanded_imm8 (uint64_t imm)
   1250  1.1  christos {
   1251  1.1  christos   int i, ret;
   1252  1.1  christos   uint32_t byte;
   1253  1.1  christos 
   1254  1.1  christos   ret = 0;
   1255  1.1  christos   for (i = 0; i < 8; i++)
   1256  1.1  christos     {
   1257  1.1  christos       byte = (imm >> (8 * i)) & 0xff;
   1258  1.1  christos       if (byte == 0xff)
   1259  1.1  christos 	ret |= 1 << i;
   1260  1.1  christos       else if (byte != 0x00)
   1261  1.1  christos 	return -1;
   1262  1.1  christos     }
   1263  1.1  christos   return ret;
   1264  1.1  christos }
   1265  1.1  christos 
   1266  1.1  christos /* Utility inline functions for operand_general_constraint_met_p.  */
   1267  1.1  christos 
   1268  1.1  christos static inline void
   1269  1.1  christos set_error (aarch64_operand_error *mismatch_detail,
   1270  1.1  christos 	   enum aarch64_operand_error_kind kind, int idx,
   1271  1.1  christos 	   const char* error)
   1272  1.1  christos {
   1273  1.1  christos   if (mismatch_detail == NULL)
   1274  1.1  christos     return;
   1275  1.1  christos   mismatch_detail->kind = kind;
   1276  1.1  christos   mismatch_detail->index = idx;
   1277  1.1  christos   mismatch_detail->error = error;
   1278  1.1  christos }
   1279  1.1  christos 
   1280  1.1  christos static inline void
   1281  1.1  christos set_syntax_error (aarch64_operand_error *mismatch_detail, int idx,
   1282  1.1  christos 		  const char* error)
   1283  1.1  christos {
   1284  1.1  christos   if (mismatch_detail == NULL)
   1285  1.1  christos     return;
   1286  1.1  christos   set_error (mismatch_detail, AARCH64_OPDE_SYNTAX_ERROR, idx, error);
   1287  1.1  christos }
   1288  1.1  christos 
   1289  1.1  christos static inline void
   1290  1.1  christos set_out_of_range_error (aarch64_operand_error *mismatch_detail,
   1291  1.1  christos 			int idx, int lower_bound, int upper_bound,
   1292  1.1  christos 			const char* error)
   1293  1.1  christos {
   1294  1.1  christos   if (mismatch_detail == NULL)
   1295  1.1  christos     return;
   1296  1.1  christos   set_error (mismatch_detail, AARCH64_OPDE_OUT_OF_RANGE, idx, error);
   1297  1.1  christos   mismatch_detail->data[0] = lower_bound;
   1298  1.1  christos   mismatch_detail->data[1] = upper_bound;
   1299  1.1  christos }
   1300  1.1  christos 
   1301  1.1  christos static inline void
   1302  1.1  christos set_imm_out_of_range_error (aarch64_operand_error *mismatch_detail,
   1303  1.1  christos 			    int idx, int lower_bound, int upper_bound)
   1304  1.1  christos {
   1305  1.1  christos   if (mismatch_detail == NULL)
   1306  1.1  christos     return;
   1307  1.1  christos   set_out_of_range_error (mismatch_detail, idx, lower_bound, upper_bound,
   1308  1.1  christos 			  _("immediate value"));
   1309  1.1  christos }
   1310  1.1  christos 
   1311  1.1  christos static inline void
   1312  1.1  christos set_offset_out_of_range_error (aarch64_operand_error *mismatch_detail,
   1313  1.1  christos 			       int idx, int lower_bound, int upper_bound)
   1314  1.1  christos {
   1315  1.1  christos   if (mismatch_detail == NULL)
   1316  1.1  christos     return;
   1317  1.1  christos   set_out_of_range_error (mismatch_detail, idx, lower_bound, upper_bound,
   1318  1.1  christos 			  _("immediate offset"));
   1319  1.1  christos }
   1320  1.1  christos 
   1321  1.1  christos static inline void
   1322  1.1  christos set_regno_out_of_range_error (aarch64_operand_error *mismatch_detail,
   1323  1.1  christos 			      int idx, int lower_bound, int upper_bound)
   1324  1.1  christos {
   1325  1.1  christos   if (mismatch_detail == NULL)
   1326  1.1  christos     return;
   1327  1.1  christos   set_out_of_range_error (mismatch_detail, idx, lower_bound, upper_bound,
   1328  1.1  christos 			  _("register number"));
   1329  1.1  christos }
   1330  1.1  christos 
   1331  1.1  christos static inline void
   1332  1.1  christos set_elem_idx_out_of_range_error (aarch64_operand_error *mismatch_detail,
   1333  1.1  christos 				 int idx, int lower_bound, int upper_bound)
   1334  1.1  christos {
   1335  1.1  christos   if (mismatch_detail == NULL)
   1336  1.1  christos     return;
   1337  1.1  christos   set_out_of_range_error (mismatch_detail, idx, lower_bound, upper_bound,
   1338  1.1  christos 			  _("register element index"));
   1339  1.1  christos }
   1340  1.1  christos 
   1341  1.1  christos static inline void
   1342  1.1  christos set_sft_amount_out_of_range_error (aarch64_operand_error *mismatch_detail,
   1343  1.1  christos 				   int idx, int lower_bound, int upper_bound)
   1344  1.1  christos {
   1345  1.1  christos   if (mismatch_detail == NULL)
   1346  1.1  christos     return;
   1347  1.1  christos   set_out_of_range_error (mismatch_detail, idx, lower_bound, upper_bound,
   1348  1.1  christos 			  _("shift amount"));
   1349  1.7  christos }
   1350  1.7  christos 
   1351  1.7  christos /* Report that the MUL modifier in operand IDX should be in the range
   1352  1.7  christos    [LOWER_BOUND, UPPER_BOUND].  */
   1353  1.7  christos static inline void
   1354  1.7  christos set_multiplier_out_of_range_error (aarch64_operand_error *mismatch_detail,
   1355  1.7  christos 				   int idx, int lower_bound, int upper_bound)
   1356  1.7  christos {
   1357  1.7  christos   if (mismatch_detail == NULL)
   1358  1.7  christos     return;
   1359  1.7  christos   set_out_of_range_error (mismatch_detail, idx, lower_bound, upper_bound,
   1360  1.7  christos 			  _("multiplier"));
   1361  1.1  christos }
   1362  1.1  christos 
   1363  1.1  christos static inline void
   1364  1.1  christos set_unaligned_error (aarch64_operand_error *mismatch_detail, int idx,
   1365  1.1  christos 		     int alignment)
   1366  1.1  christos {
   1367  1.1  christos   if (mismatch_detail == NULL)
   1368  1.1  christos     return;
   1369  1.1  christos   set_error (mismatch_detail, AARCH64_OPDE_UNALIGNED, idx, NULL);
   1370  1.1  christos   mismatch_detail->data[0] = alignment;
   1371  1.1  christos }
   1372  1.1  christos 
   1373  1.1  christos static inline void
   1374  1.1  christos set_reg_list_error (aarch64_operand_error *mismatch_detail, int idx,
   1375  1.1  christos 		    int expected_num)
   1376  1.1  christos {
   1377  1.1  christos   if (mismatch_detail == NULL)
   1378  1.1  christos     return;
   1379  1.1  christos   set_error (mismatch_detail, AARCH64_OPDE_REG_LIST, idx, NULL);
   1380  1.1  christos   mismatch_detail->data[0] = expected_num;
   1381  1.1  christos }
   1382  1.1  christos 
   1383  1.1  christos static inline void
   1384  1.1  christos set_other_error (aarch64_operand_error *mismatch_detail, int idx,
   1385  1.1  christos 		 const char* error)
   1386  1.1  christos {
   1387  1.1  christos   if (mismatch_detail == NULL)
   1388  1.1  christos     return;
   1389  1.1  christos   set_error (mismatch_detail, AARCH64_OPDE_OTHER_ERROR, idx, error);
   1390  1.1  christos }
   1391  1.1  christos 
   1392  1.1  christos /* General constraint checking based on operand code.
   1393  1.1  christos 
   1394  1.1  christos    Return 1 if OPNDS[IDX] meets the general constraint of operand code TYPE
   1395  1.1  christos    as the IDXth operand of opcode OPCODE.  Otherwise return 0.
   1396  1.1  christos 
   1397  1.1  christos    This function has to be called after the qualifiers for all operands
   1398  1.1  christos    have been resolved.
   1399  1.1  christos 
   1400  1.1  christos    Mismatching error message is returned in *MISMATCH_DETAIL upon request,
   1401  1.1  christos    i.e. when MISMATCH_DETAIL is non-NULL.  This avoids the generation
   1402  1.1  christos    of error message during the disassembling where error message is not
   1403  1.1  christos    wanted.  We avoid the dynamic construction of strings of error messages
   1404  1.1  christos    here (i.e. in libopcodes), as it is costly and complicated; instead, we
   1405  1.1  christos    use a combination of error code, static string and some integer data to
   1406  1.1  christos    represent an error.  */
   1407  1.1  christos 
   1408  1.1  christos static int
   1409  1.1  christos operand_general_constraint_met_p (const aarch64_opnd_info *opnds, int idx,
   1410  1.1  christos 				  enum aarch64_opnd type,
   1411  1.1  christos 				  const aarch64_opcode *opcode,
   1412  1.7  christos 				  aarch64_operand_error *mismatch_detail)
   1413  1.1  christos {
   1414  1.7  christos   unsigned num, modifiers, shift;
   1415  1.7  christos   unsigned char size;
   1416  1.1  christos   int64_t imm, min_value, max_value;
   1417  1.1  christos   uint64_t uvalue, mask;
   1418  1.1  christos   const aarch64_opnd_info *opnd = opnds + idx;
   1419  1.1  christos   aarch64_opnd_qualifier_t qualifier = opnd->qualifier;
   1420  1.1  christos 
   1421  1.1  christos   assert (opcode->operands[idx] == opnd->type && opnd->type == type);
   1422  1.1  christos 
   1423  1.1  christos   switch (aarch64_operands[type].op_class)
   1424  1.3  christos     {
   1425  1.3  christos     case AARCH64_OPND_CLASS_INT_REG:
   1426  1.3  christos       /* Check pair reg constraints for cas* instructions.  */
   1427  1.3  christos       if (type == AARCH64_OPND_PAIRREG)
   1428  1.3  christos 	{
   1429  1.3  christos 	  assert (idx == 1 || idx == 3);
   1430  1.3  christos 	  if (opnds[idx - 1].reg.regno % 2 != 0)
   1431  1.3  christos 	    {
   1432  1.3  christos 	      set_syntax_error (mismatch_detail, idx - 1,
   1433  1.3  christos 				_("reg pair must start from even reg"));
   1434  1.3  christos 	      return 0;
   1435  1.3  christos 	    }
   1436  1.3  christos 	  if (opnds[idx].reg.regno != opnds[idx - 1].reg.regno + 1)
   1437  1.3  christos 	    {
   1438  1.3  christos 	      set_syntax_error (mismatch_detail, idx,
   1439  1.3  christos 				_("reg pair must be contiguous"));
   1440  1.3  christos 	      return 0;
   1441  1.3  christos 	    }
   1442  1.3  christos 	  break;
   1443  1.1  christos 	}
   1444  1.1  christos 
   1445  1.1  christos       /* <Xt> may be optional in some IC and TLBI instructions.  */
   1446  1.1  christos       if (type == AARCH64_OPND_Rt_SYS)
   1447  1.1  christos 	{
   1448  1.6  christos 	  assert (idx == 1 && (aarch64_get_operand_class (opnds[0].type)
   1449  1.6  christos 			       == AARCH64_OPND_CLASS_SYSTEM));
   1450  1.1  christos 	  if (opnds[1].present
   1451  1.1  christos 	      && !aarch64_sys_ins_reg_has_xt (opnds[0].sysins_op))
   1452  1.1  christos 	    {
   1453  1.1  christos 	      set_other_error (mismatch_detail, idx, _("extraneous register"));
   1454  1.6  christos 	      return 0;
   1455  1.6  christos 	    }
   1456  1.1  christos 	  if (!opnds[1].present
   1457  1.1  christos 	      && aarch64_sys_ins_reg_has_xt (opnds[0].sysins_op))
   1458  1.1  christos 	    {
   1459  1.1  christos 	      set_other_error (mismatch_detail, idx, _("missing register"));
   1460  1.1  christos 	      return 0;
   1461  1.1  christos 	    }
   1462  1.1  christos 	}
   1463  1.1  christos       switch (qualifier)
   1464  1.1  christos 	{
   1465  1.1  christos 	case AARCH64_OPND_QLF_WSP:
   1466  1.1  christos 	case AARCH64_OPND_QLF_SP:
   1467  1.1  christos 	  if (!aarch64_stack_pointer_p (opnd))
   1468  1.1  christos 	    {
   1469  1.1  christos 	      set_other_error (mismatch_detail, idx,
   1470  1.1  christos 			       _("stack pointer register expected"));
   1471  1.1  christos 	      return 0;
   1472  1.1  christos 	    }
   1473  1.1  christos 	  break;
   1474  1.1  christos 	default:
   1475  1.1  christos 	  break;
   1476  1.1  christos 	}
   1477  1.7  christos       break;
   1478  1.7  christos 
   1479  1.7  christos     case AARCH64_OPND_CLASS_SVE_REG:
   1480  1.7  christos       switch (type)
   1481  1.7  christos 	{
   1482  1.7  christos 	case AARCH64_OPND_SVE_Zm3_INDEX:
   1483  1.7  christos 	case AARCH64_OPND_SVE_Zm3_22_INDEX:
   1484  1.7  christos 	case AARCH64_OPND_SVE_Zm4_INDEX:
   1485  1.7  christos 	  size = get_operand_fields_width (get_operand_from_code (type));
   1486  1.7  christos 	  shift = get_operand_specific_data (&aarch64_operands[type]);
   1487  1.7  christos 	  mask = (1 << shift) - 1;
   1488  1.7  christos 	  if (opnd->reg.regno > mask)
   1489  1.7  christos 	    {
   1490  1.7  christos 	      assert (mask == 7 || mask == 15);
   1491  1.7  christos 	      set_other_error (mismatch_detail, idx,
   1492  1.7  christos 			       mask == 15
   1493  1.7  christos 			       ? _("z0-z15 expected")
   1494  1.7  christos 			       : _("z0-z7 expected"));
   1495  1.7  christos 	      return 0;
   1496  1.7  christos 	    }
   1497  1.7  christos 	  mask = (1 << (size - shift)) - 1;
   1498  1.7  christos 	  if (!value_in_range_p (opnd->reglane.index, 0, mask))
   1499  1.7  christos 	    {
   1500  1.7  christos 	      set_elem_idx_out_of_range_error (mismatch_detail, idx, 0, mask);
   1501  1.7  christos 	      return 0;
   1502  1.7  christos 	    }
   1503  1.7  christos 	  break;
   1504  1.7  christos 
   1505  1.7  christos 	case AARCH64_OPND_SVE_Zn_INDEX:
   1506  1.7  christos 	  size = aarch64_get_qualifier_esize (opnd->qualifier);
   1507  1.7  christos 	  if (!value_in_range_p (opnd->reglane.index, 0, 64 / size - 1))
   1508  1.7  christos 	    {
   1509  1.7  christos 	      set_elem_idx_out_of_range_error (mismatch_detail, idx,
   1510  1.7  christos 					       0, 64 / size - 1);
   1511  1.7  christos 	      return 0;
   1512  1.7  christos 	    }
   1513  1.7  christos 	  break;
   1514  1.7  christos 
   1515  1.7  christos 	case AARCH64_OPND_SVE_ZnxN:
   1516  1.7  christos 	case AARCH64_OPND_SVE_ZtxN:
   1517  1.7  christos 	  if (opnd->reglist.num_regs != get_opcode_dependent_value (opcode))
   1518  1.7  christos 	    {
   1519  1.7  christos 	      set_other_error (mismatch_detail, idx,
   1520  1.7  christos 			       _("invalid register list"));
   1521  1.7  christos 	      return 0;
   1522  1.7  christos 	    }
   1523  1.7  christos 	  break;
   1524  1.7  christos 
   1525  1.7  christos 	default:
   1526  1.7  christos 	  break;
   1527  1.7  christos 	}
   1528  1.7  christos       break;
   1529  1.7  christos 
   1530  1.7  christos     case AARCH64_OPND_CLASS_PRED_REG:
   1531  1.7  christos       if (opnd->reg.regno >= 8
   1532  1.7  christos 	  && get_operand_fields_width (get_operand_from_code (type)) == 3)
   1533  1.7  christos 	{
   1534  1.7  christos 	  set_other_error (mismatch_detail, idx, _("p0-p7 expected"));
   1535  1.7  christos 	  return 0;
   1536  1.7  christos 	}
   1537  1.1  christos       break;
   1538  1.1  christos 
   1539  1.1  christos     case AARCH64_OPND_CLASS_COND:
   1540  1.1  christos       if (type == AARCH64_OPND_COND1
   1541  1.1  christos 	  && (opnds[idx].cond->value & 0xe) == 0xe)
   1542  1.1  christos 	{
   1543  1.1  christos 	  /* Not allow AL or NV.  */
   1544  1.1  christos 	  set_syntax_error (mismatch_detail, idx, NULL);
   1545  1.1  christos 	}
   1546  1.1  christos       break;
   1547  1.1  christos 
   1548  1.1  christos     case AARCH64_OPND_CLASS_ADDRESS:
   1549  1.1  christos       /* Check writeback.  */
   1550  1.1  christos       switch (opcode->iclass)
   1551  1.1  christos 	{
   1552  1.1  christos 	case ldst_pos:
   1553  1.1  christos 	case ldst_unscaled:
   1554  1.1  christos 	case ldstnapair_offs:
   1555  1.1  christos 	case ldstpair_off:
   1556  1.1  christos 	case ldst_unpriv:
   1557  1.1  christos 	  if (opnd->addr.writeback == 1)
   1558  1.1  christos 	    {
   1559  1.1  christos 	      set_syntax_error (mismatch_detail, idx,
   1560  1.1  christos 				_("unexpected address writeback"));
   1561  1.1  christos 	      return 0;
   1562  1.7  christos 	    }
   1563  1.7  christos 	  break;
   1564  1.7  christos 	case ldst_imm10:
   1565  1.7  christos 	  if (opnd->addr.writeback == 1 && opnd->addr.preind != 1)
   1566  1.7  christos 	    {
   1567  1.7  christos 	      set_syntax_error (mismatch_detail, idx,
   1568  1.7  christos 				_("unexpected address writeback"));
   1569  1.7  christos 	      return 0;
   1570  1.1  christos 	    }
   1571  1.1  christos 	  break;
   1572  1.1  christos 	case ldst_imm9:
   1573  1.1  christos 	case ldstpair_indexed:
   1574  1.1  christos 	case asisdlsep:
   1575  1.1  christos 	case asisdlsop:
   1576  1.1  christos 	  if (opnd->addr.writeback == 0)
   1577  1.1  christos 	    {
   1578  1.1  christos 	      set_syntax_error (mismatch_detail, idx,
   1579  1.1  christos 				_("address writeback expected"));
   1580  1.1  christos 	      return 0;
   1581  1.1  christos 	    }
   1582  1.1  christos 	  break;
   1583  1.1  christos 	default:
   1584  1.1  christos 	  assert (opnd->addr.writeback == 0);
   1585  1.1  christos 	  break;
   1586  1.1  christos 	}
   1587  1.1  christos       switch (type)
   1588  1.1  christos 	{
   1589  1.1  christos 	case AARCH64_OPND_ADDR_SIMM7:
   1590  1.1  christos 	  /* Scaled signed 7 bits immediate offset.  */
   1591  1.1  christos 	  /* Get the size of the data element that is accessed, which may be
   1592  1.1  christos 	     different from that of the source register size,
   1593  1.1  christos 	     e.g. in strb/ldrb.  */
   1594  1.1  christos 	  size = aarch64_get_qualifier_esize (opnd->qualifier);
   1595  1.1  christos 	  if (!value_in_range_p (opnd->addr.offset.imm, -64 * size, 63 * size))
   1596  1.1  christos 	    {
   1597  1.1  christos 	      set_offset_out_of_range_error (mismatch_detail, idx,
   1598  1.1  christos 					     -64 * size, 63 * size);
   1599  1.1  christos 	      return 0;
   1600  1.1  christos 	    }
   1601  1.1  christos 	  if (!value_aligned_p (opnd->addr.offset.imm, size))
   1602  1.1  christos 	    {
   1603  1.1  christos 	      set_unaligned_error (mismatch_detail, idx, size);
   1604  1.1  christos 	      return 0;
   1605  1.1  christos 	    }
   1606  1.1  christos 	  break;
   1607  1.1  christos 	case AARCH64_OPND_ADDR_SIMM9:
   1608  1.1  christos 	  /* Unscaled signed 9 bits immediate offset.  */
   1609  1.1  christos 	  if (!value_in_range_p (opnd->addr.offset.imm, -256, 255))
   1610  1.1  christos 	    {
   1611  1.1  christos 	      set_offset_out_of_range_error (mismatch_detail, idx, -256, 255);
   1612  1.1  christos 	      return 0;
   1613  1.1  christos 	    }
   1614  1.1  christos 	  break;
   1615  1.1  christos 
   1616  1.1  christos 	case AARCH64_OPND_ADDR_SIMM9_2:
   1617  1.1  christos 	  /* Unscaled signed 9 bits immediate offset, which has to be negative
   1618  1.1  christos 	     or unaligned.  */
   1619  1.1  christos 	  size = aarch64_get_qualifier_esize (qualifier);
   1620  1.1  christos 	  if ((value_in_range_p (opnd->addr.offset.imm, 0, 255)
   1621  1.1  christos 	       && !value_aligned_p (opnd->addr.offset.imm, size))
   1622  1.1  christos 	      || value_in_range_p (opnd->addr.offset.imm, -256, -1))
   1623  1.1  christos 	    return 1;
   1624  1.1  christos 	  set_other_error (mismatch_detail, idx,
   1625  1.1  christos 			   _("negative or unaligned offset expected"));
   1626  1.7  christos 	  return 0;
   1627  1.7  christos 
   1628  1.7  christos 	case AARCH64_OPND_ADDR_SIMM10:
   1629  1.7  christos 	  /* Scaled signed 10 bits immediate offset.  */
   1630  1.7  christos 	  if (!value_in_range_p (opnd->addr.offset.imm, -4096, 4088))
   1631  1.7  christos 	    {
   1632  1.7  christos 	      set_offset_out_of_range_error (mismatch_detail, idx, -4096, 4088);
   1633  1.7  christos 	      return 0;
   1634  1.7  christos 	    }
   1635  1.7  christos 	  if (!value_aligned_p (opnd->addr.offset.imm, 8))
   1636  1.7  christos 	    {
   1637  1.7  christos 	      set_unaligned_error (mismatch_detail, idx, 8);
   1638  1.7  christos 	      return 0;
   1639  1.7  christos 	    }
   1640  1.1  christos 	  break;
   1641  1.1  christos 
   1642  1.1  christos 	case AARCH64_OPND_SIMD_ADDR_POST:
   1643  1.1  christos 	  /* AdvSIMD load/store multiple structures, post-index.  */
   1644  1.1  christos 	  assert (idx == 1);
   1645  1.1  christos 	  if (opnd->addr.offset.is_reg)
   1646  1.1  christos 	    {
   1647  1.1  christos 	      if (value_in_range_p (opnd->addr.offset.regno, 0, 30))
   1648  1.1  christos 		return 1;
   1649  1.1  christos 	      else
   1650  1.1  christos 		{
   1651  1.1  christos 		  set_other_error (mismatch_detail, idx,
   1652  1.1  christos 				   _("invalid register offset"));
   1653  1.1  christos 		  return 0;
   1654  1.1  christos 		}
   1655  1.1  christos 	    }
   1656  1.1  christos 	  else
   1657  1.1  christos 	    {
   1658  1.1  christos 	      const aarch64_opnd_info *prev = &opnds[idx-1];
   1659  1.1  christos 	      unsigned num_bytes; /* total number of bytes transferred.  */
   1660  1.1  christos 	      /* The opcode dependent area stores the number of elements in
   1661  1.1  christos 		 each structure to be loaded/stored.  */
   1662  1.1  christos 	      int is_ld1r = get_opcode_dependent_value (opcode) == 1;
   1663  1.1  christos 	      if (opcode->operands[0] == AARCH64_OPND_LVt_AL)
   1664  1.1  christos 		/* Special handling of loading single structure to all lane.  */
   1665  1.1  christos 		num_bytes = (is_ld1r ? 1 : prev->reglist.num_regs)
   1666  1.1  christos 		  * aarch64_get_qualifier_esize (prev->qualifier);
   1667  1.1  christos 	      else
   1668  1.1  christos 		num_bytes = prev->reglist.num_regs
   1669  1.1  christos 		  * aarch64_get_qualifier_esize (prev->qualifier)
   1670  1.1  christos 		  * aarch64_get_qualifier_nelem (prev->qualifier);
   1671  1.1  christos 	      if ((int) num_bytes != opnd->addr.offset.imm)
   1672  1.1  christos 		{
   1673  1.1  christos 		  set_other_error (mismatch_detail, idx,
   1674  1.1  christos 				   _("invalid post-increment amount"));
   1675  1.1  christos 		  return 0;
   1676  1.1  christos 		}
   1677  1.1  christos 	    }
   1678  1.1  christos 	  break;
   1679  1.1  christos 
   1680  1.1  christos 	case AARCH64_OPND_ADDR_REGOFF:
   1681  1.1  christos 	  /* Get the size of the data element that is accessed, which may be
   1682  1.1  christos 	     different from that of the source register size,
   1683  1.1  christos 	     e.g. in strb/ldrb.  */
   1684  1.1  christos 	  size = aarch64_get_qualifier_esize (opnd->qualifier);
   1685  1.1  christos 	  /* It is either no shift or shift by the binary logarithm of SIZE.  */
   1686  1.1  christos 	  if (opnd->shifter.amount != 0
   1687  1.1  christos 	      && opnd->shifter.amount != (int)get_logsz (size))
   1688  1.1  christos 	    {
   1689  1.1  christos 	      set_other_error (mismatch_detail, idx,
   1690  1.1  christos 			       _("invalid shift amount"));
   1691  1.1  christos 	      return 0;
   1692  1.1  christos 	    }
   1693  1.1  christos 	  /* Only UXTW, LSL, SXTW and SXTX are the accepted extending
   1694  1.1  christos 	     operators.  */
   1695  1.1  christos 	  switch (opnd->shifter.kind)
   1696  1.1  christos 	    {
   1697  1.1  christos 	    case AARCH64_MOD_UXTW:
   1698  1.1  christos 	    case AARCH64_MOD_LSL:
   1699  1.1  christos 	    case AARCH64_MOD_SXTW:
   1700  1.1  christos 	    case AARCH64_MOD_SXTX: break;
   1701  1.1  christos 	    default:
   1702  1.1  christos 	      set_other_error (mismatch_detail, idx,
   1703  1.1  christos 			       _("invalid extend/shift operator"));
   1704  1.1  christos 	      return 0;
   1705  1.1  christos 	    }
   1706  1.1  christos 	  break;
   1707  1.1  christos 
   1708  1.1  christos 	case AARCH64_OPND_ADDR_UIMM12:
   1709  1.1  christos 	  imm = opnd->addr.offset.imm;
   1710  1.1  christos 	  /* Get the size of the data element that is accessed, which may be
   1711  1.1  christos 	     different from that of the source register size,
   1712  1.1  christos 	     e.g. in strb/ldrb.  */
   1713  1.1  christos 	  size = aarch64_get_qualifier_esize (qualifier);
   1714  1.1  christos 	  if (!value_in_range_p (opnd->addr.offset.imm, 0, 4095 * size))
   1715  1.1  christos 	    {
   1716  1.1  christos 	      set_offset_out_of_range_error (mismatch_detail, idx,
   1717  1.1  christos 					     0, 4095 * size);
   1718  1.1  christos 	      return 0;
   1719  1.1  christos 	    }
   1720  1.1  christos 	  if (!value_aligned_p (opnd->addr.offset.imm, size))
   1721  1.1  christos 	    {
   1722  1.1  christos 	      set_unaligned_error (mismatch_detail, idx, size);
   1723  1.1  christos 	      return 0;
   1724  1.1  christos 	    }
   1725  1.1  christos 	  break;
   1726  1.1  christos 
   1727  1.1  christos 	case AARCH64_OPND_ADDR_PCREL14:
   1728  1.1  christos 	case AARCH64_OPND_ADDR_PCREL19:
   1729  1.1  christos 	case AARCH64_OPND_ADDR_PCREL21:
   1730  1.1  christos 	case AARCH64_OPND_ADDR_PCREL26:
   1731  1.1  christos 	  imm = opnd->imm.value;
   1732  1.1  christos 	  if (operand_need_shift_by_two (get_operand_from_code (type)))
   1733  1.1  christos 	    {
   1734  1.1  christos 	      /* The offset value in a PC-relative branch instruction is alway
   1735  1.1  christos 		 4-byte aligned and is encoded without the lowest 2 bits.  */
   1736  1.1  christos 	      if (!value_aligned_p (imm, 4))
   1737  1.1  christos 		{
   1738  1.1  christos 		  set_unaligned_error (mismatch_detail, idx, 4);
   1739  1.1  christos 		  return 0;
   1740  1.1  christos 		}
   1741  1.1  christos 	      /* Right shift by 2 so that we can carry out the following check
   1742  1.1  christos 		 canonically.  */
   1743  1.1  christos 	      imm >>= 2;
   1744  1.1  christos 	    }
   1745  1.1  christos 	  size = get_operand_fields_width (get_operand_from_code (type));
   1746  1.1  christos 	  if (!value_fit_signed_field_p (imm, size))
   1747  1.1  christos 	    {
   1748  1.1  christos 	      set_other_error (mismatch_detail, idx,
   1749  1.1  christos 			       _("immediate out of range"));
   1750  1.1  christos 	      return 0;
   1751  1.1  christos 	    }
   1752  1.7  christos 	  break;
   1753  1.7  christos 
   1754  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RI_S4xVL:
   1755  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RI_S4x2xVL:
   1756  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RI_S4x3xVL:
   1757  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RI_S4x4xVL:
   1758  1.7  christos 	  min_value = -8;
   1759  1.7  christos 	  max_value = 7;
   1760  1.7  christos 	sve_imm_offset_vl:
   1761  1.7  christos 	  assert (!opnd->addr.offset.is_reg);
   1762  1.7  christos 	  assert (opnd->addr.preind);
   1763  1.7  christos 	  num = 1 + get_operand_specific_data (&aarch64_operands[type]);
   1764  1.7  christos 	  min_value *= num;
   1765  1.7  christos 	  max_value *= num;
   1766  1.7  christos 	  if ((opnd->addr.offset.imm != 0 && !opnd->shifter.operator_present)
   1767  1.7  christos 	      || (opnd->shifter.operator_present
   1768  1.7  christos 		  && opnd->shifter.kind != AARCH64_MOD_MUL_VL))
   1769  1.7  christos 	    {
   1770  1.7  christos 	      set_other_error (mismatch_detail, idx,
   1771  1.7  christos 			       _("invalid addressing mode"));
   1772  1.7  christos 	      return 0;
   1773  1.7  christos 	    }
   1774  1.7  christos 	  if (!value_in_range_p (opnd->addr.offset.imm, min_value, max_value))
   1775  1.7  christos 	    {
   1776  1.7  christos 	      set_offset_out_of_range_error (mismatch_detail, idx,
   1777  1.7  christos 					     min_value, max_value);
   1778  1.7  christos 	      return 0;
   1779  1.7  christos 	    }
   1780  1.7  christos 	  if (!value_aligned_p (opnd->addr.offset.imm, num))
   1781  1.7  christos 	    {
   1782  1.7  christos 	      set_unaligned_error (mismatch_detail, idx, num);
   1783  1.7  christos 	      return 0;
   1784  1.7  christos 	    }
   1785  1.7  christos 	  break;
   1786  1.7  christos 
   1787  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RI_S6xVL:
   1788  1.7  christos 	  min_value = -32;
   1789  1.7  christos 	  max_value = 31;
   1790  1.7  christos 	  goto sve_imm_offset_vl;
   1791  1.7  christos 
   1792  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RI_S9xVL:
   1793  1.7  christos 	  min_value = -256;
   1794  1.7  christos 	  max_value = 255;
   1795  1.7  christos 	  goto sve_imm_offset_vl;
   1796  1.7  christos 
   1797  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RI_U6:
   1798  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RI_U6x2:
   1799  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RI_U6x4:
   1800  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RI_U6x8:
   1801  1.7  christos 	  min_value = 0;
   1802  1.7  christos 	  max_value = 63;
   1803  1.7  christos 	sve_imm_offset:
   1804  1.7  christos 	  assert (!opnd->addr.offset.is_reg);
   1805  1.7  christos 	  assert (opnd->addr.preind);
   1806  1.7  christos 	  num = 1 << get_operand_specific_data (&aarch64_operands[type]);
   1807  1.7  christos 	  min_value *= num;
   1808  1.7  christos 	  max_value *= num;
   1809  1.7  christos 	  if (opnd->shifter.operator_present
   1810  1.7  christos 	      || opnd->shifter.amount_present)
   1811  1.7  christos 	    {
   1812  1.7  christos 	      set_other_error (mismatch_detail, idx,
   1813  1.7  christos 			       _("invalid addressing mode"));
   1814  1.7  christos 	      return 0;
   1815  1.7  christos 	    }
   1816  1.7  christos 	  if (!value_in_range_p (opnd->addr.offset.imm, min_value, max_value))
   1817  1.7  christos 	    {
   1818  1.7  christos 	      set_offset_out_of_range_error (mismatch_detail, idx,
   1819  1.7  christos 					     min_value, max_value);
   1820  1.7  christos 	      return 0;
   1821  1.7  christos 	    }
   1822  1.7  christos 	  if (!value_aligned_p (opnd->addr.offset.imm, num))
   1823  1.7  christos 	    {
   1824  1.7  christos 	      set_unaligned_error (mismatch_detail, idx, num);
   1825  1.7  christos 	      return 0;
   1826  1.7  christos 	    }
   1827  1.7  christos 	  break;
   1828  1.7  christos 
   1829  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RI_S4x16:
   1830  1.7  christos 	  min_value = -8;
   1831  1.7  christos 	  max_value = 7;
   1832  1.7  christos 	  goto sve_imm_offset;
   1833  1.7  christos 
   1834  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RR:
   1835  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RR_LSL1:
   1836  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RR_LSL2:
   1837  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RR_LSL3:
   1838  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RX:
   1839  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RX_LSL1:
   1840  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RX_LSL2:
   1841  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RX_LSL3:
   1842  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RZ:
   1843  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RZ_LSL1:
   1844  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RZ_LSL2:
   1845  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RZ_LSL3:
   1846  1.7  christos 	  modifiers = 1 << AARCH64_MOD_LSL;
   1847  1.7  christos 	sve_rr_operand:
   1848  1.7  christos 	  assert (opnd->addr.offset.is_reg);
   1849  1.7  christos 	  assert (opnd->addr.preind);
   1850  1.7  christos 	  if ((aarch64_operands[type].flags & OPD_F_NO_ZR) != 0
   1851  1.7  christos 	      && opnd->addr.offset.regno == 31)
   1852  1.7  christos 	    {
   1853  1.7  christos 	      set_other_error (mismatch_detail, idx,
   1854  1.7  christos 			       _("index register xzr is not allowed"));
   1855  1.7  christos 	      return 0;
   1856  1.7  christos 	    }
   1857  1.7  christos 	  if (((1 << opnd->shifter.kind) & modifiers) == 0
   1858  1.7  christos 	      || (opnd->shifter.amount
   1859  1.7  christos 		  != get_operand_specific_data (&aarch64_operands[type])))
   1860  1.7  christos 	    {
   1861  1.7  christos 	      set_other_error (mismatch_detail, idx,
   1862  1.7  christos 			       _("invalid addressing mode"));
   1863  1.7  christos 	      return 0;
   1864  1.7  christos 	    }
   1865  1.7  christos 	  break;
   1866  1.7  christos 
   1867  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RZ_XTW_14:
   1868  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RZ_XTW_22:
   1869  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RZ_XTW1_14:
   1870  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RZ_XTW1_22:
   1871  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RZ_XTW2_14:
   1872  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RZ_XTW2_22:
   1873  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RZ_XTW3_14:
   1874  1.7  christos 	case AARCH64_OPND_SVE_ADDR_RZ_XTW3_22:
   1875  1.7  christos 	  modifiers = (1 << AARCH64_MOD_SXTW) | (1 << AARCH64_MOD_UXTW);
   1876  1.7  christos 	  goto sve_rr_operand;
   1877  1.7  christos 
   1878  1.7  christos 	case AARCH64_OPND_SVE_ADDR_ZI_U5:
   1879  1.7  christos 	case AARCH64_OPND_SVE_ADDR_ZI_U5x2:
   1880  1.7  christos 	case AARCH64_OPND_SVE_ADDR_ZI_U5x4:
   1881  1.7  christos 	case AARCH64_OPND_SVE_ADDR_ZI_U5x8:
   1882  1.7  christos 	  min_value = 0;
   1883  1.7  christos 	  max_value = 31;
   1884  1.7  christos 	  goto sve_imm_offset;
   1885  1.7  christos 
   1886  1.7  christos 	case AARCH64_OPND_SVE_ADDR_ZZ_LSL:
   1887  1.7  christos 	  modifiers = 1 << AARCH64_MOD_LSL;
   1888  1.7  christos 	sve_zz_operand:
   1889  1.7  christos 	  assert (opnd->addr.offset.is_reg);
   1890  1.7  christos 	  assert (opnd->addr.preind);
   1891  1.7  christos 	  if (((1 << opnd->shifter.kind) & modifiers) == 0
   1892  1.7  christos 	      || opnd->shifter.amount < 0
   1893  1.7  christos 	      || opnd->shifter.amount > 3)
   1894  1.7  christos 	    {
   1895  1.7  christos 	      set_other_error (mismatch_detail, idx,
   1896  1.7  christos 			       _("invalid addressing mode"));
   1897  1.7  christos 	      return 0;
   1898  1.7  christos 	    }
   1899  1.7  christos 	  break;
   1900  1.7  christos 
   1901  1.7  christos 	case AARCH64_OPND_SVE_ADDR_ZZ_SXTW:
   1902  1.7  christos 	  modifiers = (1 << AARCH64_MOD_SXTW);
   1903  1.7  christos 	  goto sve_zz_operand;
   1904  1.7  christos 
   1905  1.7  christos 	case AARCH64_OPND_SVE_ADDR_ZZ_UXTW:
   1906  1.7  christos 	  modifiers = 1 << AARCH64_MOD_UXTW;
   1907  1.1  christos 	  goto sve_zz_operand;
   1908  1.1  christos 
   1909  1.1  christos 	default:
   1910  1.1  christos 	  break;
   1911  1.1  christos 	}
   1912  1.1  christos       break;
   1913  1.6  christos 
   1914  1.6  christos     case AARCH64_OPND_CLASS_SIMD_REGLIST:
   1915  1.6  christos       if (type == AARCH64_OPND_LEt)
   1916  1.6  christos 	{
   1917  1.6  christos 	  /* Get the upper bound for the element index.  */
   1918  1.6  christos 	  num = 16 / aarch64_get_qualifier_esize (qualifier) - 1;
   1919  1.6  christos 	  if (!value_in_range_p (opnd->reglist.index, 0, num))
   1920  1.6  christos 	    {
   1921  1.6  christos 	      set_elem_idx_out_of_range_error (mismatch_detail, idx, 0, num);
   1922  1.6  christos 	      return 0;
   1923  1.1  christos 	    }
   1924  1.1  christos 	}
   1925  1.1  christos       /* The opcode dependent area stores the number of elements in
   1926  1.1  christos 	 each structure to be loaded/stored.  */
   1927  1.1  christos       num = get_opcode_dependent_value (opcode);
   1928  1.1  christos       switch (type)
   1929  1.1  christos 	{
   1930  1.1  christos 	case AARCH64_OPND_LVt:
   1931  1.1  christos 	  assert (num >= 1 && num <= 4);
   1932  1.1  christos 	  /* Unless LD1/ST1, the number of registers should be equal to that
   1933  1.1  christos 	     of the structure elements.  */
   1934  1.1  christos 	  if (num != 1 && opnd->reglist.num_regs != num)
   1935  1.1  christos 	    {
   1936  1.1  christos 	      set_reg_list_error (mismatch_detail, idx, num);
   1937  1.1  christos 	      return 0;
   1938  1.1  christos 	    }
   1939  1.1  christos 	  break;
   1940  1.1  christos 	case AARCH64_OPND_LVt_AL:
   1941  1.1  christos 	case AARCH64_OPND_LEt:
   1942  1.1  christos 	  assert (num >= 1 && num <= 4);
   1943  1.1  christos 	  /* The number of registers should be equal to that of the structure
   1944  1.1  christos 	     elements.  */
   1945  1.1  christos 	  if (opnd->reglist.num_regs != num)
   1946  1.1  christos 	    {
   1947  1.1  christos 	      set_reg_list_error (mismatch_detail, idx, num);
   1948  1.1  christos 	      return 0;
   1949  1.1  christos 	    }
   1950  1.1  christos 	  break;
   1951  1.1  christos 	default:
   1952  1.1  christos 	  break;
   1953  1.1  christos 	}
   1954  1.1  christos       break;
   1955  1.1  christos 
   1956  1.1  christos     case AARCH64_OPND_CLASS_IMMEDIATE:
   1957  1.1  christos       /* Constraint check on immediate operand.  */
   1958  1.1  christos       imm = opnd->imm.value;
   1959  1.1  christos       /* E.g. imm_0_31 constrains value to be 0..31.  */
   1960  1.1  christos       if (qualifier_value_in_range_constraint_p (qualifier)
   1961  1.1  christos 	  && !value_in_range_p (imm, get_lower_bound (qualifier),
   1962  1.1  christos 				get_upper_bound (qualifier)))
   1963  1.1  christos 	{
   1964  1.1  christos 	  set_imm_out_of_range_error (mismatch_detail, idx,
   1965  1.1  christos 				      get_lower_bound (qualifier),
   1966  1.1  christos 				      get_upper_bound (qualifier));
   1967  1.1  christos 	  return 0;
   1968  1.1  christos 	}
   1969  1.1  christos 
   1970  1.1  christos       switch (type)
   1971  1.1  christos 	{
   1972  1.1  christos 	case AARCH64_OPND_AIMM:
   1973  1.1  christos 	  if (opnd->shifter.kind != AARCH64_MOD_LSL)
   1974  1.1  christos 	    {
   1975  1.1  christos 	      set_other_error (mismatch_detail, idx,
   1976  1.1  christos 			       _("invalid shift operator"));
   1977  1.1  christos 	      return 0;
   1978  1.1  christos 	    }
   1979  1.1  christos 	  if (opnd->shifter.amount != 0 && opnd->shifter.amount != 12)
   1980  1.7  christos 	    {
   1981  1.1  christos 	      set_other_error (mismatch_detail, idx,
   1982  1.1  christos 			       _("shift amount must be 0 or 12"));
   1983  1.1  christos 	      return 0;
   1984  1.1  christos 	    }
   1985  1.1  christos 	  if (!value_fit_unsigned_field_p (opnd->imm.value, 12))
   1986  1.1  christos 	    {
   1987  1.1  christos 	      set_other_error (mismatch_detail, idx,
   1988  1.1  christos 			       _("immediate out of range"));
   1989  1.1  christos 	      return 0;
   1990  1.1  christos 	    }
   1991  1.1  christos 	  break;
   1992  1.1  christos 
   1993  1.1  christos 	case AARCH64_OPND_HALF:
   1994  1.1  christos 	  assert (idx == 1 && opnds[0].type == AARCH64_OPND_Rd);
   1995  1.1  christos 	  if (opnd->shifter.kind != AARCH64_MOD_LSL)
   1996  1.1  christos 	    {
   1997  1.1  christos 	      set_other_error (mismatch_detail, idx,
   1998  1.1  christos 			       _("invalid shift operator"));
   1999  1.1  christos 	      return 0;
   2000  1.1  christos 	    }
   2001  1.1  christos 	  size = aarch64_get_qualifier_esize (opnds[0].qualifier);
   2002  1.1  christos 	  if (!value_aligned_p (opnd->shifter.amount, 16))
   2003  1.7  christos 	    {
   2004  1.1  christos 	      set_other_error (mismatch_detail, idx,
   2005  1.1  christos 			       _("shift amount must be a multiple of 16"));
   2006  1.1  christos 	      return 0;
   2007  1.1  christos 	    }
   2008  1.1  christos 	  if (!value_in_range_p (opnd->shifter.amount, 0, size * 8 - 16))
   2009  1.1  christos 	    {
   2010  1.1  christos 	      set_sft_amount_out_of_range_error (mismatch_detail, idx,
   2011  1.1  christos 						 0, size * 8 - 16);
   2012  1.1  christos 	      return 0;
   2013  1.1  christos 	    }
   2014  1.1  christos 	  if (opnd->imm.value < 0)
   2015  1.1  christos 	    {
   2016  1.1  christos 	      set_other_error (mismatch_detail, idx,
   2017  1.1  christos 			       _("negative immediate value not allowed"));
   2018  1.1  christos 	      return 0;
   2019  1.1  christos 	    }
   2020  1.1  christos 	  if (!value_fit_unsigned_field_p (opnd->imm.value, 16))
   2021  1.1  christos 	    {
   2022  1.1  christos 	      set_other_error (mismatch_detail, idx,
   2023  1.1  christos 			       _("immediate out of range"));
   2024  1.1  christos 	      return 0;
   2025  1.1  christos 	    }
   2026  1.1  christos 	  break;
   2027  1.1  christos 
   2028  1.7  christos 	case AARCH64_OPND_IMM_MOV:
   2029  1.1  christos 	    {
   2030  1.1  christos 	      int esize = aarch64_get_qualifier_esize (opnds[0].qualifier);
   2031  1.1  christos 	      imm = opnd->imm.value;
   2032  1.1  christos 	      assert (idx == 1);
   2033  1.1  christos 	      switch (opcode->op)
   2034  1.1  christos 		{
   2035  1.7  christos 		case OP_MOV_IMM_WIDEN:
   2036  1.1  christos 		  imm = ~imm;
   2037  1.7  christos 		  /* Fall through.  */
   2038  1.1  christos 		case OP_MOV_IMM_WIDE:
   2039  1.1  christos 		  if (!aarch64_wide_constant_p (imm, esize == 4, NULL))
   2040  1.1  christos 		    {
   2041  1.1  christos 		      set_other_error (mismatch_detail, idx,
   2042  1.1  christos 				       _("immediate out of range"));
   2043  1.1  christos 		      return 0;
   2044  1.1  christos 		    }
   2045  1.7  christos 		  break;
   2046  1.1  christos 		case OP_MOV_IMM_LOG:
   2047  1.1  christos 		  if (!aarch64_logical_immediate_p (imm, esize, NULL))
   2048  1.1  christos 		    {
   2049  1.1  christos 		      set_other_error (mismatch_detail, idx,
   2050  1.1  christos 				       _("immediate out of range"));
   2051  1.1  christos 		      return 0;
   2052  1.1  christos 		    }
   2053  1.1  christos 		  break;
   2054  1.1  christos 		default:
   2055  1.1  christos 		  assert (0);
   2056  1.1  christos 		  return 0;
   2057  1.1  christos 		}
   2058  1.1  christos 	    }
   2059  1.1  christos 	  break;
   2060  1.1  christos 
   2061  1.1  christos 	case AARCH64_OPND_NZCV:
   2062  1.1  christos 	case AARCH64_OPND_CCMP_IMM:
   2063  1.1  christos 	case AARCH64_OPND_EXCEPTION:
   2064  1.1  christos 	case AARCH64_OPND_UIMM4:
   2065  1.1  christos 	case AARCH64_OPND_UIMM7:
   2066  1.7  christos 	case AARCH64_OPND_UIMM3_OP1:
   2067  1.7  christos 	case AARCH64_OPND_UIMM3_OP2:
   2068  1.7  christos 	case AARCH64_OPND_SVE_UIMM3:
   2069  1.7  christos 	case AARCH64_OPND_SVE_UIMM7:
   2070  1.1  christos 	case AARCH64_OPND_SVE_UIMM8:
   2071  1.1  christos 	case AARCH64_OPND_SVE_UIMM8_53:
   2072  1.1  christos 	  size = get_operand_fields_width (get_operand_from_code (type));
   2073  1.1  christos 	  assert (size < 32);
   2074  1.1  christos 	  if (!value_fit_unsigned_field_p (opnd->imm.value, size))
   2075  1.1  christos 	    {
   2076  1.1  christos 	      set_imm_out_of_range_error (mismatch_detail, idx, 0,
   2077  1.1  christos 					  (1 << size) - 1);
   2078  1.1  christos 	      return 0;
   2079  1.1  christos 	    }
   2080  1.7  christos 	  break;
   2081  1.7  christos 
   2082  1.7  christos 	case AARCH64_OPND_SIMM5:
   2083  1.7  christos 	case AARCH64_OPND_SVE_SIMM5:
   2084  1.7  christos 	case AARCH64_OPND_SVE_SIMM5B:
   2085  1.7  christos 	case AARCH64_OPND_SVE_SIMM6:
   2086  1.7  christos 	case AARCH64_OPND_SVE_SIMM8:
   2087  1.7  christos 	  size = get_operand_fields_width (get_operand_from_code (type));
   2088  1.7  christos 	  assert (size < 32);
   2089  1.7  christos 	  if (!value_fit_signed_field_p (opnd->imm.value, size))
   2090  1.7  christos 	    {
   2091  1.7  christos 	      set_imm_out_of_range_error (mismatch_detail, idx,
   2092  1.7  christos 					  -(1 << (size - 1)),
   2093  1.7  christos 					  (1 << (size - 1)) - 1);
   2094  1.7  christos 	      return 0;
   2095  1.7  christos 	    }
   2096  1.1  christos 	  break;
   2097  1.6  christos 
   2098  1.1  christos 	case AARCH64_OPND_WIDTH:
   2099  1.1  christos 	  assert (idx > 1 && opnds[idx-1].type == AARCH64_OPND_IMM
   2100  1.1  christos 		  && opnds[0].type == AARCH64_OPND_Rd);
   2101  1.1  christos 	  size = get_upper_bound (qualifier);
   2102  1.1  christos 	  if (opnd->imm.value + opnds[idx-1].imm.value > size)
   2103  1.1  christos 	    /* lsb+width <= reg.size  */
   2104  1.1  christos 	    {
   2105  1.1  christos 	      set_imm_out_of_range_error (mismatch_detail, idx, 1,
   2106  1.1  christos 					  size - opnds[idx-1].imm.value);
   2107  1.1  christos 	      return 0;
   2108  1.1  christos 	    }
   2109  1.1  christos 	  break;
   2110  1.7  christos 
   2111  1.7  christos 	case AARCH64_OPND_LIMM:
   2112  1.7  christos 	case AARCH64_OPND_SVE_LIMM:
   2113  1.7  christos 	  {
   2114  1.7  christos 	    int esize = aarch64_get_qualifier_esize (opnds[0].qualifier);
   2115  1.7  christos 	    uint64_t uimm = opnd->imm.value;
   2116  1.7  christos 	    if (opcode->op == OP_BIC)
   2117  1.7  christos 	      uimm = ~uimm;
   2118  1.7  christos 	    if (aarch64_logical_immediate_p (uimm, esize, NULL) == FALSE)
   2119  1.7  christos 	      {
   2120  1.7  christos 		set_other_error (mismatch_detail, idx,
   2121  1.7  christos 				 _("immediate out of range"));
   2122  1.7  christos 		return 0;
   2123  1.1  christos 	      }
   2124  1.1  christos 	  }
   2125  1.1  christos 	  break;
   2126  1.1  christos 
   2127  1.1  christos 	case AARCH64_OPND_IMM0:
   2128  1.1  christos 	case AARCH64_OPND_FPIMM0:
   2129  1.1  christos 	  if (opnd->imm.value != 0)
   2130  1.1  christos 	    {
   2131  1.1  christos 	      set_other_error (mismatch_detail, idx,
   2132  1.1  christos 			       _("immediate zero expected"));
   2133  1.1  christos 	      return 0;
   2134  1.1  christos 	    }
   2135  1.7  christos 	  break;
   2136  1.7  christos 
   2137  1.7  christos 	case AARCH64_OPND_IMM_ROT1:
   2138  1.7  christos 	case AARCH64_OPND_IMM_ROT2:
   2139  1.7  christos 	case AARCH64_OPND_SVE_IMM_ROT2:
   2140  1.7  christos 	  if (opnd->imm.value != 0
   2141  1.7  christos 	      && opnd->imm.value != 90
   2142  1.7  christos 	      && opnd->imm.value != 180
   2143  1.7  christos 	      && opnd->imm.value != 270)
   2144  1.7  christos 	    {
   2145  1.7  christos 	      set_other_error (mismatch_detail, idx,
   2146  1.7  christos 			       _("rotate expected to be 0, 90, 180 or 270"));
   2147  1.7  christos 	      return 0;
   2148  1.7  christos 	    }
   2149  1.7  christos 	  break;
   2150  1.7  christos 
   2151  1.7  christos 	case AARCH64_OPND_IMM_ROT3:
   2152  1.7  christos 	case AARCH64_OPND_SVE_IMM_ROT1:
   2153  1.7  christos 	  if (opnd->imm.value != 90 && opnd->imm.value != 270)
   2154  1.7  christos 	    {
   2155  1.7  christos 	      set_other_error (mismatch_detail, idx,
   2156  1.7  christos 			       _("rotate expected to be 90 or 270"));
   2157  1.7  christos 	      return 0;
   2158  1.7  christos 	    }
   2159  1.1  christos 	  break;
   2160  1.1  christos 
   2161  1.1  christos 	case AARCH64_OPND_SHLL_IMM:
   2162  1.1  christos 	  assert (idx == 2);
   2163  1.1  christos 	  size = 8 * aarch64_get_qualifier_esize (opnds[idx - 1].qualifier);
   2164  1.1  christos 	  if (opnd->imm.value != size)
   2165  1.1  christos 	    {
   2166  1.1  christos 	      set_other_error (mismatch_detail, idx,
   2167  1.1  christos 			       _("invalid shift amount"));
   2168  1.1  christos 	      return 0;
   2169  1.1  christos 	    }
   2170  1.1  christos 	  break;
   2171  1.1  christos 
   2172  1.1  christos 	case AARCH64_OPND_IMM_VLSL:
   2173  1.1  christos 	  size = aarch64_get_qualifier_esize (qualifier);
   2174  1.1  christos 	  if (!value_in_range_p (opnd->imm.value, 0, size * 8 - 1))
   2175  1.1  christos 	    {
   2176  1.1  christos 	      set_imm_out_of_range_error (mismatch_detail, idx, 0,
   2177  1.1  christos 					  size * 8 - 1);
   2178  1.1  christos 	      return 0;
   2179  1.1  christos 	    }
   2180  1.1  christos 	  break;
   2181  1.1  christos 
   2182  1.1  christos 	case AARCH64_OPND_IMM_VLSR:
   2183  1.1  christos 	  size = aarch64_get_qualifier_esize (qualifier);
   2184  1.1  christos 	  if (!value_in_range_p (opnd->imm.value, 1, size * 8))
   2185  1.1  christos 	    {
   2186  1.1  christos 	      set_imm_out_of_range_error (mismatch_detail, idx, 1, size * 8);
   2187  1.1  christos 	      return 0;
   2188  1.1  christos 	    }
   2189  1.1  christos 	  break;
   2190  1.1  christos 
   2191  1.1  christos 	case AARCH64_OPND_SIMD_IMM:
   2192  1.1  christos 	case AARCH64_OPND_SIMD_IMM_SFT:
   2193  1.1  christos 	  /* Qualifier check.  */
   2194  1.1  christos 	  switch (qualifier)
   2195  1.1  christos 	    {
   2196  1.1  christos 	    case AARCH64_OPND_QLF_LSL:
   2197  1.1  christos 	      if (opnd->shifter.kind != AARCH64_MOD_LSL)
   2198  1.1  christos 		{
   2199  1.1  christos 		  set_other_error (mismatch_detail, idx,
   2200  1.1  christos 				   _("invalid shift operator"));
   2201  1.1  christos 		  return 0;
   2202  1.1  christos 		}
   2203  1.1  christos 	      break;
   2204  1.1  christos 	    case AARCH64_OPND_QLF_MSL:
   2205  1.1  christos 	      if (opnd->shifter.kind != AARCH64_MOD_MSL)
   2206  1.1  christos 		{
   2207  1.1  christos 		  set_other_error (mismatch_detail, idx,
   2208  1.1  christos 				   _("invalid shift operator"));
   2209  1.1  christos 		  return 0;
   2210  1.1  christos 		}
   2211  1.1  christos 	      break;
   2212  1.1  christos 	    case AARCH64_OPND_QLF_NIL:
   2213  1.1  christos 	      if (opnd->shifter.kind != AARCH64_MOD_NONE)
   2214  1.1  christos 		{
   2215  1.1  christos 		  set_other_error (mismatch_detail, idx,
   2216  1.1  christos 				   _("shift is not permitted"));
   2217  1.1  christos 		  return 0;
   2218  1.1  christos 		}
   2219  1.1  christos 	      break;
   2220  1.1  christos 	    default:
   2221  1.1  christos 	      assert (0);
   2222  1.1  christos 	      return 0;
   2223  1.1  christos 	    }
   2224  1.1  christos 	  /* Is the immediate valid?  */
   2225  1.1  christos 	  assert (idx == 1);
   2226  1.1  christos 	  if (aarch64_get_qualifier_esize (opnds[0].qualifier) != 8)
   2227  1.1  christos 	    {
   2228  1.1  christos 	      /* uimm8 or simm8 */
   2229  1.1  christos 	      if (!value_in_range_p (opnd->imm.value, -128, 255))
   2230  1.1  christos 		{
   2231  1.1  christos 		  set_imm_out_of_range_error (mismatch_detail, idx, -128, 255);
   2232  1.1  christos 		  return 0;
   2233  1.1  christos 		}
   2234  1.1  christos 	    }
   2235  1.1  christos 	  else if (aarch64_shrink_expanded_imm8 (opnd->imm.value) < 0)
   2236  1.1  christos 	    {
   2237  1.1  christos 	      /* uimm64 is not
   2238  1.1  christos 		 'aaaaaaaabbbbbbbbccccccccddddddddeeeeeeee
   2239  1.1  christos 		 ffffffffgggggggghhhhhhhh'.  */
   2240  1.1  christos 	      set_other_error (mismatch_detail, idx,
   2241  1.1  christos 			       _("invalid value for immediate"));
   2242  1.1  christos 	      return 0;
   2243  1.1  christos 	    }
   2244  1.1  christos 	  /* Is the shift amount valid?  */
   2245  1.1  christos 	  switch (opnd->shifter.kind)
   2246  1.1  christos 	    {
   2247  1.1  christos 	    case AARCH64_MOD_LSL:
   2248  1.1  christos 	      size = aarch64_get_qualifier_esize (opnds[0].qualifier);
   2249  1.1  christos 	      if (!value_in_range_p (opnd->shifter.amount, 0, (size - 1) * 8))
   2250  1.1  christos 		{
   2251  1.1  christos 		  set_sft_amount_out_of_range_error (mismatch_detail, idx, 0,
   2252  1.1  christos 						     (size - 1) * 8);
   2253  1.1  christos 		  return 0;
   2254  1.1  christos 		}
   2255  1.1  christos 	      if (!value_aligned_p (opnd->shifter.amount, 8))
   2256  1.1  christos 		{
   2257  1.1  christos 		  set_unaligned_error (mismatch_detail, idx, 8);
   2258  1.1  christos 		  return 0;
   2259  1.1  christos 		}
   2260  1.1  christos 	      break;
   2261  1.1  christos 	    case AARCH64_MOD_MSL:
   2262  1.1  christos 	      /* Only 8 and 16 are valid shift amount.  */
   2263  1.1  christos 	      if (opnd->shifter.amount != 8 && opnd->shifter.amount != 16)
   2264  1.7  christos 		{
   2265  1.1  christos 		  set_other_error (mismatch_detail, idx,
   2266  1.1  christos 				   _("shift amount must be 0 or 16"));
   2267  1.1  christos 		  return 0;
   2268  1.1  christos 		}
   2269  1.1  christos 	      break;
   2270  1.1  christos 	    default:
   2271  1.1  christos 	      if (opnd->shifter.kind != AARCH64_MOD_NONE)
   2272  1.1  christos 		{
   2273  1.1  christos 		  set_other_error (mismatch_detail, idx,
   2274  1.1  christos 				   _("invalid shift operator"));
   2275  1.1  christos 		  return 0;
   2276  1.1  christos 		}
   2277  1.1  christos 	      break;
   2278  1.1  christos 	    }
   2279  1.1  christos 	  break;
   2280  1.1  christos 
   2281  1.7  christos 	case AARCH64_OPND_FPIMM:
   2282  1.1  christos 	case AARCH64_OPND_SIMD_FPIMM:
   2283  1.1  christos 	case AARCH64_OPND_SVE_FPIMM8:
   2284  1.1  christos 	  if (opnd->imm.is_fp == 0)
   2285  1.1  christos 	    {
   2286  1.1  christos 	      set_other_error (mismatch_detail, idx,
   2287  1.1  christos 			       _("floating-point immediate expected"));
   2288  1.1  christos 	      return 0;
   2289  1.1  christos 	    }
   2290  1.1  christos 	  /* The value is expected to be an 8-bit floating-point constant with
   2291  1.1  christos 	     sign, 3-bit exponent and normalized 4 bits of precision, encoded
   2292  1.1  christos 	     in "a:b:c:d:e:f:g:h" or FLD_imm8 (depending on the type of the
   2293  1.1  christos 	     instruction).  */
   2294  1.1  christos 	  if (!value_in_range_p (opnd->imm.value, 0, 255))
   2295  1.1  christos 	    {
   2296  1.1  christos 	      set_other_error (mismatch_detail, idx,
   2297  1.1  christos 			       _("immediate out of range"));
   2298  1.1  christos 	      return 0;
   2299  1.1  christos 	    }
   2300  1.1  christos 	  if (opnd->shifter.kind != AARCH64_MOD_NONE)
   2301  1.1  christos 	    {
   2302  1.1  christos 	      set_other_error (mismatch_detail, idx,
   2303  1.1  christos 			       _("invalid shift operator"));
   2304  1.1  christos 	      return 0;
   2305  1.1  christos 	    }
   2306  1.7  christos 	  break;
   2307  1.7  christos 
   2308  1.7  christos 	case AARCH64_OPND_SVE_AIMM:
   2309  1.7  christos 	  min_value = 0;
   2310  1.7  christos 	sve_aimm:
   2311  1.7  christos 	  assert (opnd->shifter.kind == AARCH64_MOD_LSL);
   2312  1.7  christos 	  size = aarch64_get_qualifier_esize (opnds[0].qualifier);
   2313  1.7  christos 	  mask = ~((uint64_t) -1 << (size * 4) << (size * 4));
   2314  1.7  christos 	  uvalue = opnd->imm.value;
   2315  1.7  christos 	  shift = opnd->shifter.amount;
   2316  1.7  christos 	  if (size == 1)
   2317  1.7  christos 	    {
   2318  1.7  christos 	      if (shift != 0)
   2319  1.7  christos 		{
   2320  1.7  christos 		  set_other_error (mismatch_detail, idx,
   2321  1.7  christos 				   _("no shift amount allowed for"
   2322  1.7  christos 				     " 8-bit constants"));
   2323  1.7  christos 		  return 0;
   2324  1.7  christos 		}
   2325  1.7  christos 	    }
   2326  1.7  christos 	  else
   2327  1.7  christos 	    {
   2328  1.7  christos 	      if (shift != 0 && shift != 8)
   2329  1.7  christos 		{
   2330  1.7  christos 		  set_other_error (mismatch_detail, idx,
   2331  1.7  christos 				   _("shift amount must be 0 or 8"));
   2332  1.7  christos 		  return 0;
   2333  1.7  christos 		}
   2334  1.7  christos 	      if (shift == 0 && (uvalue & 0xff) == 0)
   2335  1.7  christos 		{
   2336  1.7  christos 		  shift = 8;
   2337  1.7  christos 		  uvalue = (int64_t) uvalue / 256;
   2338  1.7  christos 		}
   2339  1.7  christos 	    }
   2340  1.7  christos 	  mask >>= shift;
   2341  1.7  christos 	  if ((uvalue & mask) != uvalue && (uvalue | ~mask) != uvalue)
   2342  1.7  christos 	    {
   2343  1.7  christos 	      set_other_error (mismatch_detail, idx,
   2344  1.7  christos 			       _("immediate too big for element size"));
   2345  1.7  christos 	      return 0;
   2346  1.7  christos 	    }
   2347  1.7  christos 	  uvalue = (uvalue - min_value) & mask;
   2348  1.7  christos 	  if (uvalue > 0xff)
   2349  1.7  christos 	    {
   2350  1.7  christos 	      set_other_error (mismatch_detail, idx,
   2351  1.7  christos 			       _("invalid arithmetic immediate"));
   2352  1.7  christos 	      return 0;
   2353  1.7  christos 	    }
   2354  1.7  christos 	  break;
   2355  1.7  christos 
   2356  1.7  christos 	case AARCH64_OPND_SVE_ASIMM:
   2357  1.7  christos 	  min_value = -128;
   2358  1.7  christos 	  goto sve_aimm;
   2359  1.7  christos 
   2360  1.7  christos 	case AARCH64_OPND_SVE_I1_HALF_ONE:
   2361  1.7  christos 	  assert (opnd->imm.is_fp);
   2362  1.7  christos 	  if (opnd->imm.value != 0x3f000000 && opnd->imm.value != 0x3f800000)
   2363  1.7  christos 	    {
   2364  1.7  christos 	      set_other_error (mismatch_detail, idx,
   2365  1.7  christos 			       _("floating-point value must be 0.5 or 1.0"));
   2366  1.7  christos 	      return 0;
   2367  1.7  christos 	    }
   2368  1.7  christos 	  break;
   2369  1.7  christos 
   2370  1.7  christos 	case AARCH64_OPND_SVE_I1_HALF_TWO:
   2371  1.7  christos 	  assert (opnd->imm.is_fp);
   2372  1.7  christos 	  if (opnd->imm.value != 0x3f000000 && opnd->imm.value != 0x40000000)
   2373  1.7  christos 	    {
   2374  1.7  christos 	      set_other_error (mismatch_detail, idx,
   2375  1.7  christos 			       _("floating-point value must be 0.5 or 2.0"));
   2376  1.7  christos 	      return 0;
   2377  1.7  christos 	    }
   2378  1.7  christos 	  break;
   2379  1.7  christos 
   2380  1.7  christos 	case AARCH64_OPND_SVE_I1_ZERO_ONE:
   2381  1.7  christos 	  assert (opnd->imm.is_fp);
   2382  1.7  christos 	  if (opnd->imm.value != 0 && opnd->imm.value != 0x3f800000)
   2383  1.7  christos 	    {
   2384  1.7  christos 	      set_other_error (mismatch_detail, idx,
   2385  1.7  christos 			       _("floating-point value must be 0.0 or 1.0"));
   2386  1.7  christos 	      return 0;
   2387  1.7  christos 	    }
   2388  1.7  christos 	  break;
   2389  1.7  christos 
   2390  1.7  christos 	case AARCH64_OPND_SVE_INV_LIMM:
   2391  1.7  christos 	  {
   2392  1.7  christos 	    int esize = aarch64_get_qualifier_esize (opnds[0].qualifier);
   2393  1.7  christos 	    uint64_t uimm = ~opnd->imm.value;
   2394  1.7  christos 	    if (!aarch64_logical_immediate_p (uimm, esize, NULL))
   2395  1.7  christos 	      {
   2396  1.7  christos 		set_other_error (mismatch_detail, idx,
   2397  1.7  christos 				 _("immediate out of range"));
   2398  1.7  christos 		return 0;
   2399  1.7  christos 	      }
   2400  1.7  christos 	  }
   2401  1.7  christos 	  break;
   2402  1.7  christos 
   2403  1.7  christos 	case AARCH64_OPND_SVE_LIMM_MOV:
   2404  1.7  christos 	  {
   2405  1.7  christos 	    int esize = aarch64_get_qualifier_esize (opnds[0].qualifier);
   2406  1.7  christos 	    uint64_t uimm = opnd->imm.value;
   2407  1.7  christos 	    if (!aarch64_logical_immediate_p (uimm, esize, NULL))
   2408  1.7  christos 	      {
   2409  1.7  christos 		set_other_error (mismatch_detail, idx,
   2410  1.7  christos 				 _("immediate out of range"));
   2411  1.7  christos 		return 0;
   2412  1.7  christos 	      }
   2413  1.7  christos 	    if (!aarch64_sve_dupm_mov_immediate_p (uimm, esize))
   2414  1.7  christos 	      {
   2415  1.7  christos 		set_other_error (mismatch_detail, idx,
   2416  1.7  christos 				 _("invalid replicated MOV immediate"));
   2417  1.7  christos 		return 0;
   2418  1.7  christos 	      }
   2419  1.7  christos 	  }
   2420  1.7  christos 	  break;
   2421  1.7  christos 
   2422  1.7  christos 	case AARCH64_OPND_SVE_PATTERN_SCALED:
   2423  1.7  christos 	  assert (opnd->shifter.kind == AARCH64_MOD_MUL);
   2424  1.7  christos 	  if (!value_in_range_p (opnd->shifter.amount, 1, 16))
   2425  1.7  christos 	    {
   2426  1.7  christos 	      set_multiplier_out_of_range_error (mismatch_detail, idx, 1, 16);
   2427  1.7  christos 	      return 0;
   2428  1.7  christos 	    }
   2429  1.7  christos 	  break;
   2430  1.7  christos 
   2431  1.7  christos 	case AARCH64_OPND_SVE_SHLIMM_PRED:
   2432  1.7  christos 	case AARCH64_OPND_SVE_SHLIMM_UNPRED:
   2433  1.7  christos 	  size = aarch64_get_qualifier_esize (opnds[idx - 1].qualifier);
   2434  1.7  christos 	  if (!value_in_range_p (opnd->imm.value, 0, 8 * size - 1))
   2435  1.7  christos 	    {
   2436  1.7  christos 	      set_imm_out_of_range_error (mismatch_detail, idx,
   2437  1.7  christos 					  0, 8 * size - 1);
   2438  1.7  christos 	      return 0;
   2439  1.7  christos 	    }
   2440  1.7  christos 	  break;
   2441  1.7  christos 
   2442  1.7  christos 	case AARCH64_OPND_SVE_SHRIMM_PRED:
   2443  1.7  christos 	case AARCH64_OPND_SVE_SHRIMM_UNPRED:
   2444  1.7  christos 	  size = aarch64_get_qualifier_esize (opnds[idx - 1].qualifier);
   2445  1.7  christos 	  if (!value_in_range_p (opnd->imm.value, 1, 8 * size))
   2446  1.7  christos 	    {
   2447  1.7  christos 	      set_imm_out_of_range_error (mismatch_detail, idx, 1, 8 * size);
   2448  1.7  christos 	      return 0;
   2449  1.7  christos 	    }
   2450  1.1  christos 	  break;
   2451  1.1  christos 
   2452  1.1  christos 	default:
   2453  1.1  christos 	  break;
   2454  1.1  christos 	}
   2455  1.1  christos       break;
   2456  1.1  christos 
   2457  1.1  christos     case AARCH64_OPND_CLASS_SYSTEM:
   2458  1.1  christos       switch (type)
   2459  1.1  christos 	{
   2460  1.6  christos 	case AARCH64_OPND_PSTATEFIELD:
   2461  1.6  christos 	  assert (idx == 0 && opnds[1].type == AARCH64_OPND_UIMM4);
   2462  1.6  christos 	  /* MSR UAO, #uimm4
   2463  1.6  christos 	     MSR PAN, #uimm4
   2464  1.6  christos 	     The immediate must be #0 or #1.  */
   2465  1.6  christos 	  if ((opnd->pstatefield == 0x03	/* UAO.  */
   2466  1.6  christos 	       || opnd->pstatefield == 0x04)	/* PAN.  */
   2467  1.6  christos 	      && opnds[1].imm.value > 1)
   2468  1.6  christos 	    {
   2469  1.6  christos 	      set_imm_out_of_range_error (mismatch_detail, idx, 0, 1);
   2470  1.1  christos 	      return 0;
   2471  1.1  christos 	    }
   2472  1.1  christos 	  /* MSR SPSel, #uimm4
   2473  1.1  christos 	     Uses uimm4 as a control value to select the stack pointer: if
   2474  1.1  christos 	     bit 0 is set it selects the current exception level's stack
   2475  1.1  christos 	     pointer, if bit 0 is clear it selects shared EL0 stack pointer.
   2476  1.1  christos 	     Bits 1 to 3 of uimm4 are reserved and should be zero.  */
   2477  1.1  christos 	  if (opnd->pstatefield == 0x05 /* spsel */ && opnds[1].imm.value > 1)
   2478  1.1  christos 	    {
   2479  1.1  christos 	      set_imm_out_of_range_error (mismatch_detail, idx, 0, 1);
   2480  1.1  christos 	      return 0;
   2481  1.1  christos 	    }
   2482  1.1  christos 	  break;
   2483  1.1  christos 	default:
   2484  1.1  christos 	  break;
   2485  1.1  christos 	}
   2486  1.1  christos       break;
   2487  1.1  christos 
   2488  1.7  christos     case AARCH64_OPND_CLASS_SIMD_ELEMENT:
   2489  1.7  christos       /* Get the upper bound for the element index.  */
   2490  1.7  christos       if (opcode->op == OP_FCMLA_ELEM)
   2491  1.7  christos 	/* FCMLA index range depends on the vector size of other operands
   2492  1.7  christos 	   and is halfed because complex numbers take two elements.  */
   2493  1.7  christos 	num = aarch64_get_qualifier_nelem (opnds[0].qualifier)
   2494  1.7  christos 	      * aarch64_get_qualifier_esize (opnds[0].qualifier) / 2;
   2495  1.7  christos       else
   2496  1.7  christos 	num = 16;
   2497  1.1  christos       num = num / aarch64_get_qualifier_esize (qualifier) - 1;
   2498  1.1  christos 
   2499  1.1  christos       /* Index out-of-range.  */
   2500  1.1  christos       if (!value_in_range_p (opnd->reglane.index, 0, num))
   2501  1.1  christos 	{
   2502  1.1  christos 	  set_elem_idx_out_of_range_error (mismatch_detail, idx, 0, num);
   2503  1.1  christos 	  return 0;
   2504  1.1  christos 	}
   2505  1.1  christos       /* SMLAL<Q> <Vd>.<Ta>, <Vn>.<Tb>, <Vm>.<Ts>[<index>].
   2506  1.1  christos 	 <Vm>	Is the vector register (V0-V31) or (V0-V15), whose
   2507  1.1  christos 	 number is encoded in "size:M:Rm":
   2508  1.1  christos 	 size	<Vm>
   2509  1.1  christos 	 00		RESERVED
   2510  1.1  christos 	 01		0:Rm
   2511  1.1  christos 	 10		M:Rm
   2512  1.1  christos 	 11		RESERVED  */
   2513  1.1  christos       if (type == AARCH64_OPND_Em && qualifier == AARCH64_OPND_QLF_S_H
   2514  1.1  christos 	  && !value_in_range_p (opnd->reglane.regno, 0, 15))
   2515  1.1  christos 	{
   2516  1.1  christos 	  set_regno_out_of_range_error (mismatch_detail, idx, 0, 15);
   2517  1.1  christos 	  return 0;
   2518  1.1  christos 	}
   2519  1.1  christos       break;
   2520  1.1  christos 
   2521  1.1  christos     case AARCH64_OPND_CLASS_MODIFIED_REG:
   2522  1.1  christos       assert (idx == 1 || idx == 2);
   2523  1.1  christos       switch (type)
   2524  1.1  christos 	{
   2525  1.1  christos 	case AARCH64_OPND_Rm_EXT:
   2526  1.1  christos 	  if (aarch64_extend_operator_p (opnd->shifter.kind) == FALSE
   2527  1.1  christos 	      && opnd->shifter.kind != AARCH64_MOD_LSL)
   2528  1.1  christos 	    {
   2529  1.1  christos 	      set_other_error (mismatch_detail, idx,
   2530  1.1  christos 			       _("extend operator expected"));
   2531  1.1  christos 	      return 0;
   2532  1.1  christos 	    }
   2533  1.1  christos 	  /* It is not optional unless at least one of "Rd" or "Rn" is '11111'
   2534  1.1  christos 	     (i.e. SP), in which case it defaults to LSL. The LSL alias is
   2535  1.1  christos 	     only valid when "Rd" or "Rn" is '11111', and is preferred in that
   2536  1.1  christos 	     case.  */
   2537  1.1  christos 	  if (!aarch64_stack_pointer_p (opnds + 0)
   2538  1.1  christos 	      && (idx != 2 || !aarch64_stack_pointer_p (opnds + 1)))
   2539  1.1  christos 	    {
   2540  1.1  christos 	      if (!opnd->shifter.operator_present)
   2541  1.1  christos 		{
   2542  1.1  christos 		  set_other_error (mismatch_detail, idx,
   2543  1.1  christos 				   _("missing extend operator"));
   2544  1.1  christos 		  return 0;
   2545  1.1  christos 		}
   2546  1.1  christos 	      else if (opnd->shifter.kind == AARCH64_MOD_LSL)
   2547  1.1  christos 		{
   2548  1.1  christos 		  set_other_error (mismatch_detail, idx,
   2549  1.1  christos 				   _("'LSL' operator not allowed"));
   2550  1.1  christos 		  return 0;
   2551  1.1  christos 		}
   2552  1.1  christos 	    }
   2553  1.1  christos 	  assert (opnd->shifter.operator_present	/* Default to LSL.  */
   2554  1.1  christos 		  || opnd->shifter.kind == AARCH64_MOD_LSL);
   2555  1.1  christos 	  if (!value_in_range_p (opnd->shifter.amount, 0, 4))
   2556  1.1  christos 	    {
   2557  1.1  christos 	      set_sft_amount_out_of_range_error (mismatch_detail, idx, 0, 4);
   2558  1.1  christos 	      return 0;
   2559  1.1  christos 	    }
   2560  1.1  christos 	  /* In the 64-bit form, the final register operand is written as Wm
   2561  1.1  christos 	     for all but the (possibly omitted) UXTX/LSL and SXTX
   2562  1.1  christos 	     operators.
   2563  1.1  christos 	     N.B. GAS allows X register to be used with any operator as a
   2564  1.1  christos 	     programming convenience.  */
   2565  1.1  christos 	  if (qualifier == AARCH64_OPND_QLF_X
   2566  1.1  christos 	      && opnd->shifter.kind != AARCH64_MOD_LSL
   2567  1.1  christos 	      && opnd->shifter.kind != AARCH64_MOD_UXTX
   2568  1.1  christos 	      && opnd->shifter.kind != AARCH64_MOD_SXTX)
   2569  1.1  christos 	    {
   2570  1.1  christos 	      set_other_error (mismatch_detail, idx, _("W register expected"));
   2571  1.1  christos 	      return 0;
   2572  1.1  christos 	    }
   2573  1.1  christos 	  break;
   2574  1.1  christos 
   2575  1.1  christos 	case AARCH64_OPND_Rm_SFT:
   2576  1.1  christos 	  /* ROR is not available to the shifted register operand in
   2577  1.1  christos 	     arithmetic instructions.  */
   2578  1.1  christos 	  if (aarch64_shift_operator_p (opnd->shifter.kind) == FALSE)
   2579  1.1  christos 	    {
   2580  1.1  christos 	      set_other_error (mismatch_detail, idx,
   2581  1.1  christos 			       _("shift operator expected"));
   2582  1.1  christos 	      return 0;
   2583  1.1  christos 	    }
   2584  1.1  christos 	  if (opnd->shifter.kind == AARCH64_MOD_ROR
   2585  1.1  christos 	      && opcode->iclass != log_shift)
   2586  1.1  christos 	    {
   2587  1.1  christos 	      set_other_error (mismatch_detail, idx,
   2588  1.1  christos 			       _("'ROR' operator not allowed"));
   2589  1.1  christos 	      return 0;
   2590  1.1  christos 	    }
   2591  1.1  christos 	  num = qualifier == AARCH64_OPND_QLF_W ? 31 : 63;
   2592  1.1  christos 	  if (!value_in_range_p (opnd->shifter.amount, 0, num))
   2593  1.1  christos 	    {
   2594  1.1  christos 	      set_sft_amount_out_of_range_error (mismatch_detail, idx, 0, num);
   2595  1.1  christos 	      return 0;
   2596  1.1  christos 	    }
   2597  1.1  christos 	  break;
   2598  1.1  christos 
   2599  1.1  christos 	default:
   2600  1.1  christos 	  break;
   2601  1.1  christos 	}
   2602  1.1  christos       break;
   2603  1.1  christos 
   2604  1.1  christos     default:
   2605  1.1  christos       break;
   2606  1.1  christos     }
   2607  1.1  christos 
   2608  1.1  christos   return 1;
   2609  1.1  christos }
   2610  1.1  christos 
   2611  1.1  christos /* Main entrypoint for the operand constraint checking.
   2612  1.1  christos 
   2613  1.1  christos    Return 1 if operands of *INST meet the constraint applied by the operand
   2614  1.1  christos    codes and operand qualifiers; otherwise return 0 and if MISMATCH_DETAIL is
   2615  1.1  christos    not NULL, return the detail of the error in *MISMATCH_DETAIL.  N.B. when
   2616  1.1  christos    adding more constraint checking, make sure MISMATCH_DETAIL->KIND is set
   2617  1.1  christos    with a proper error kind rather than AARCH64_OPDE_NIL (GAS asserts non-NIL
   2618  1.1  christos    error kind when it is notified that an instruction does not pass the check).
   2619  1.1  christos 
   2620  1.1  christos    Un-determined operand qualifiers may get established during the process.  */
   2621  1.1  christos 
   2622  1.1  christos int
   2623  1.1  christos aarch64_match_operands_constraint (aarch64_inst *inst,
   2624  1.1  christos 				   aarch64_operand_error *mismatch_detail)
   2625  1.1  christos {
   2626  1.1  christos   int i;
   2627  1.1  christos 
   2628  1.7  christos   DEBUG_TRACE ("enter");
   2629  1.7  christos 
   2630  1.7  christos   /* Check for cases where a source register needs to be the same as the
   2631  1.7  christos      destination register.  Do this before matching qualifiers since if
   2632  1.7  christos      an instruction has both invalid tying and invalid qualifiers,
   2633  1.7  christos      the error about qualifiers would suggest several alternative
   2634  1.7  christos      instructions that also have invalid tying.  */
   2635  1.7  christos   i = inst->opcode->tied_operand;
   2636  1.7  christos   if (i > 0 && (inst->operands[0].reg.regno != inst->operands[i].reg.regno))
   2637  1.7  christos     {
   2638  1.7  christos       if (mismatch_detail)
   2639  1.7  christos 	{
   2640  1.7  christos 	  mismatch_detail->kind = AARCH64_OPDE_UNTIED_OPERAND;
   2641  1.7  christos 	  mismatch_detail->index = i;
   2642  1.7  christos 	  mismatch_detail->error = NULL;
   2643  1.7  christos 	}
   2644  1.7  christos       return 0;
   2645  1.1  christos     }
   2646  1.1  christos 
   2647  1.1  christos   /* Match operands' qualifier.
   2648  1.1  christos      *INST has already had qualifier establish for some, if not all, of
   2649  1.1  christos      its operands; we need to find out whether these established
   2650  1.1  christos      qualifiers match one of the qualifier sequence in
   2651  1.1  christos      INST->OPCODE->QUALIFIERS_LIST.  If yes, we will assign each operand
   2652  1.1  christos      with the corresponding qualifier in such a sequence.
   2653  1.1  christos      Only basic operand constraint checking is done here; the more thorough
   2654  1.1  christos      constraint checking will carried out by operand_general_constraint_met_p,
   2655  1.1  christos      which has be to called after this in order to get all of the operands'
   2656  1.1  christos      qualifiers established.  */
   2657  1.1  christos   if (match_operands_qualifier (inst, TRUE /* update_p */) == 0)
   2658  1.1  christos     {
   2659  1.1  christos       DEBUG_TRACE ("FAIL on operand qualifier matching");
   2660  1.1  christos       if (mismatch_detail)
   2661  1.1  christos 	{
   2662  1.1  christos 	  /* Return an error type to indicate that it is the qualifier
   2663  1.1  christos 	     matching failure; we don't care about which operand as there
   2664  1.1  christos 	     are enough information in the opcode table to reproduce it.  */
   2665  1.1  christos 	  mismatch_detail->kind = AARCH64_OPDE_INVALID_VARIANT;
   2666  1.1  christos 	  mismatch_detail->index = -1;
   2667  1.1  christos 	  mismatch_detail->error = NULL;
   2668  1.1  christos 	}
   2669  1.1  christos       return 0;
   2670  1.1  christos     }
   2671  1.1  christos 
   2672  1.1  christos   /* Match operands' constraint.  */
   2673  1.1  christos   for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
   2674  1.1  christos     {
   2675  1.1  christos       enum aarch64_opnd type = inst->opcode->operands[i];
   2676  1.1  christos       if (type == AARCH64_OPND_NIL)
   2677  1.1  christos 	break;
   2678  1.1  christos       if (inst->operands[i].skip)
   2679  1.1  christos 	{
   2680  1.1  christos 	  DEBUG_TRACE ("skip the incomplete operand %d", i);
   2681  1.1  christos 	  continue;
   2682  1.1  christos 	}
   2683  1.1  christos       if (operand_general_constraint_met_p (inst->operands, i, type,
   2684  1.1  christos 					    inst->opcode, mismatch_detail) == 0)
   2685  1.1  christos 	{
   2686  1.1  christos 	  DEBUG_TRACE ("FAIL on operand %d", i);
   2687  1.1  christos 	  return 0;
   2688  1.1  christos 	}
   2689  1.1  christos     }
   2690  1.1  christos 
   2691  1.1  christos   DEBUG_TRACE ("PASS");
   2692  1.1  christos 
   2693  1.1  christos   return 1;
   2694  1.1  christos }
   2695  1.1  christos 
   2696  1.1  christos /* Replace INST->OPCODE with OPCODE and return the replaced OPCODE.
   2697  1.1  christos    Also updates the TYPE of each INST->OPERANDS with the corresponding
   2698  1.1  christos    value of OPCODE->OPERANDS.
   2699  1.1  christos 
   2700  1.1  christos    Note that some operand qualifiers may need to be manually cleared by
   2701  1.1  christos    the caller before it further calls the aarch64_opcode_encode; by
   2702  1.1  christos    doing this, it helps the qualifier matching facilities work
   2703  1.1  christos    properly.  */
   2704  1.1  christos 
   2705  1.1  christos const aarch64_opcode*
   2706  1.1  christos aarch64_replace_opcode (aarch64_inst *inst, const aarch64_opcode *opcode)
   2707  1.1  christos {
   2708  1.1  christos   int i;
   2709  1.1  christos   const aarch64_opcode *old = inst->opcode;
   2710  1.1  christos 
   2711  1.1  christos   inst->opcode = opcode;
   2712  1.1  christos 
   2713  1.1  christos   /* Update the operand types.  */
   2714  1.1  christos   for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
   2715  1.1  christos     {
   2716  1.1  christos       inst->operands[i].type = opcode->operands[i];
   2717  1.1  christos       if (opcode->operands[i] == AARCH64_OPND_NIL)
   2718  1.1  christos 	break;
   2719  1.1  christos     }
   2720  1.1  christos 
   2721  1.1  christos   DEBUG_TRACE ("replace %s with %s", old->name, opcode->name);
   2722  1.1  christos 
   2723  1.1  christos   return old;
   2724  1.1  christos }
   2725  1.1  christos 
   2726  1.1  christos int
   2727  1.1  christos aarch64_operand_index (const enum aarch64_opnd *operands, enum aarch64_opnd operand)
   2728  1.1  christos {
   2729  1.1  christos   int i;
   2730  1.1  christos   for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
   2731  1.1  christos     if (operands[i] == operand)
   2732  1.1  christos       return i;
   2733  1.1  christos     else if (operands[i] == AARCH64_OPND_NIL)
   2734  1.1  christos       break;
   2735  1.1  christos   return -1;
   2736  1.7  christos }
   2737  1.7  christos 
   2738  1.7  christos /* R0...R30, followed by FOR31.  */
   2740  1.7  christos #define BANK(R, FOR31) \
   2741  1.7  christos   { R  (0), R  (1), R  (2), R  (3), R  (4), R  (5), R  (6), R  (7), \
   2742  1.1  christos     R  (8), R  (9), R (10), R (11), R (12), R (13), R (14), R (15), \
   2743  1.1  christos     R (16), R (17), R (18), R (19), R (20), R (21), R (22), R (23), \
   2744  1.1  christos     R (24), R (25), R (26), R (27), R (28), R (29), R (30),  FOR31 }
   2745  1.1  christos /* [0][0]  32-bit integer regs with sp   Wn
   2746  1.1  christos    [0][1]  64-bit integer regs with sp   Xn  sf=1
   2747  1.7  christos    [1][0]  32-bit integer regs with #0   Wn
   2748  1.7  christos    [1][1]  64-bit integer regs with #0   Xn  sf=1 */
   2749  1.7  christos static const char *int_reg[2][2][32] = {
   2750  1.7  christos #define R32(X) "w" #X
   2751  1.1  christos #define R64(X) "x" #X
   2752  1.1  christos   { BANK (R32, "wsp"), BANK (R64, "sp") },
   2753  1.1  christos   { BANK (R32, "wzr"), BANK (R64, "xzr") }
   2754  1.1  christos #undef R64
   2755  1.7  christos #undef R32
   2756  1.7  christos };
   2757  1.7  christos 
   2758  1.7  christos /* Names of the SVE vector registers, first with .S suffixes,
   2759  1.7  christos    then with .D suffixes.  */
   2760  1.7  christos 
   2761  1.7  christos static const char *sve_reg[2][32] = {
   2762  1.7  christos #define ZS(X) "z" #X ".s"
   2763  1.7  christos #define ZD(X) "z" #X ".d"
   2764  1.7  christos   BANK (ZS, ZS (31)), BANK (ZD, ZD (31))
   2765  1.7  christos #undef ZD
   2766  1.7  christos #undef ZS
   2767  1.1  christos };
   2768  1.1  christos #undef BANK
   2769  1.1  christos 
   2770  1.1  christos /* Return the integer register name.
   2771  1.1  christos    if SP_REG_P is not 0, R31 is an SP reg, other R31 is the zero reg.  */
   2772  1.1  christos 
   2773  1.1  christos static inline const char *
   2774  1.1  christos get_int_reg_name (int regno, aarch64_opnd_qualifier_t qualifier, int sp_reg_p)
   2775  1.1  christos {
   2776  1.1  christos   const int has_zr = sp_reg_p ? 0 : 1;
   2777  1.1  christos   const int is_64 = aarch64_get_qualifier_esize (qualifier) == 4 ? 0 : 1;
   2778  1.1  christos   return int_reg[has_zr][is_64][regno];
   2779  1.1  christos }
   2780  1.1  christos 
   2781  1.1  christos /* Like get_int_reg_name, but IS_64 is always 1.  */
   2782  1.1  christos 
   2783  1.1  christos static inline const char *
   2784  1.1  christos get_64bit_int_reg_name (int regno, int sp_reg_p)
   2785  1.1  christos {
   2786  1.1  christos   const int has_zr = sp_reg_p ? 0 : 1;
   2787  1.7  christos   return int_reg[has_zr][1][regno];
   2788  1.7  christos }
   2789  1.7  christos 
   2790  1.7  christos /* Get the name of the integer offset register in OPND, using the shift type
   2791  1.7  christos    to decide whether it's a word or doubleword.  */
   2792  1.7  christos 
   2793  1.7  christos static inline const char *
   2794  1.7  christos get_offset_int_reg_name (const aarch64_opnd_info *opnd)
   2795  1.7  christos {
   2796  1.7  christos   switch (opnd->shifter.kind)
   2797  1.7  christos     {
   2798  1.7  christos     case AARCH64_MOD_UXTW:
   2799  1.7  christos     case AARCH64_MOD_SXTW:
   2800  1.7  christos       return get_int_reg_name (opnd->addr.offset.regno, AARCH64_OPND_QLF_W, 0);
   2801  1.7  christos 
   2802  1.7  christos     case AARCH64_MOD_LSL:
   2803  1.7  christos     case AARCH64_MOD_SXTX:
   2804  1.7  christos       return get_int_reg_name (opnd->addr.offset.regno, AARCH64_OPND_QLF_X, 0);
   2805  1.7  christos 
   2806  1.7  christos     default:
   2807  1.7  christos       abort ();
   2808  1.7  christos     }
   2809  1.7  christos }
   2810  1.7  christos 
   2811  1.7  christos /* Get the name of the SVE vector offset register in OPND, using the operand
   2812  1.7  christos    qualifier to decide whether the suffix should be .S or .D.  */
   2813  1.7  christos 
   2814  1.7  christos static inline const char *
   2815  1.7  christos get_addr_sve_reg_name (int regno, aarch64_opnd_qualifier_t qualifier)
   2816  1.7  christos {
   2817  1.7  christos   assert (qualifier == AARCH64_OPND_QLF_S_S
   2818  1.7  christos 	  || qualifier == AARCH64_OPND_QLF_S_D);
   2819  1.1  christos   return sve_reg[qualifier == AARCH64_OPND_QLF_S_D][regno];
   2820  1.1  christos }
   2821  1.1  christos 
   2822  1.1  christos /* Types for expanding an encoded 8-bit value to a floating-point value.  */
   2823  1.1  christos 
   2824  1.1  christos typedef union
   2825  1.1  christos {
   2826  1.1  christos   uint64_t i;
   2827  1.1  christos   double   d;
   2828  1.1  christos } double_conv_t;
   2829  1.1  christos 
   2830  1.1  christos typedef union
   2831  1.1  christos {
   2832  1.1  christos   uint32_t i;
   2833  1.6  christos   float    f;
   2834  1.6  christos } single_conv_t;
   2835  1.6  christos 
   2836  1.6  christos typedef union
   2837  1.6  christos {
   2838  1.6  christos   uint32_t i;
   2839  1.1  christos   float    f;
   2840  1.1  christos } half_conv_t;
   2841  1.1  christos 
   2842  1.6  christos /* IMM8 is an 8-bit floating-point constant with sign, 3-bit exponent and
   2843  1.6  christos    normalized 4 bits of precision, encoded in "a:b:c:d:e:f:g:h" or FLD_imm8
   2844  1.6  christos    (depending on the type of the instruction).  IMM8 will be expanded to a
   2845  1.6  christos    single-precision floating-point value (SIZE == 4) or a double-precision
   2846  1.1  christos    floating-point value (SIZE == 8).  A half-precision floating-point value
   2847  1.1  christos    (SIZE == 2) is expanded to a single-precision floating-point value.  The
   2848  1.6  christos    expanded value is returned.  */
   2849  1.1  christos 
   2850  1.1  christos static uint64_t
   2851  1.1  christos expand_fp_imm (int size, uint32_t imm8)
   2852  1.1  christos {
   2853  1.1  christos   uint64_t imm;
   2854  1.1  christos   uint32_t imm8_7, imm8_6_0, imm8_6, imm8_6_repl4;
   2855  1.1  christos 
   2856  1.1  christos   imm8_7 = (imm8 >> 7) & 0x01;	/* imm8<7>   */
   2857  1.1  christos   imm8_6_0 = imm8 & 0x7f;	/* imm8<6:0> */
   2858  1.6  christos   imm8_6 = imm8_6_0 >> 6;	/* imm8<6>   */
   2859  1.1  christos   imm8_6_repl4 = (imm8_6 << 3) | (imm8_6 << 2)
   2860  1.1  christos     | (imm8_6 << 1) | imm8_6;	/* Replicate(imm8<6>,4) */
   2861  1.1  christos   if (size == 8)
   2862  1.1  christos     {
   2863  1.1  christos       imm = (imm8_7 << (63-32))		/* imm8<7>  */
   2864  1.1  christos 	| ((imm8_6 ^ 1) << (62-32))	/* NOT(imm8<6)	*/
   2865  1.1  christos 	| (imm8_6_repl4 << (58-32)) | (imm8_6 << (57-32))
   2866  1.1  christos 	| (imm8_6 << (56-32)) | (imm8_6 << (55-32)) /* Replicate(imm8<6>,7) */
   2867  1.6  christos 	| (imm8_6_0 << (48-32));	/* imm8<6>:imm8<5:0>    */
   2868  1.1  christos       imm <<= 32;
   2869  1.1  christos     }
   2870  1.1  christos   else if (size == 4 || size == 2)
   2871  1.1  christos     {
   2872  1.1  christos       imm = (imm8_7 << 31)	/* imm8<7>              */
   2873  1.1  christos 	| ((imm8_6 ^ 1) << 30)	/* NOT(imm8<6>)         */
   2874  1.6  christos 	| (imm8_6_repl4 << 26)	/* Replicate(imm8<6>,4) */
   2875  1.6  christos 	| (imm8_6_0 << 19);	/* imm8<6>:imm8<5:0>    */
   2876  1.6  christos     }
   2877  1.6  christos   else
   2878  1.6  christos     {
   2879  1.1  christos       /* An unsupported size.  */
   2880  1.1  christos       assert (0);
   2881  1.1  christos     }
   2882  1.1  christos 
   2883  1.1  christos   return imm;
   2884  1.7  christos }
   2885  1.7  christos 
   2886  1.1  christos /* Produce the string representation of the register list operand *OPND
   2887  1.7  christos    in the buffer pointed by BUF of size SIZE.  PREFIX is the part of
   2888  1.7  christos    the register name that comes before the register number, such as "v".  */
   2889  1.1  christos static void
   2890  1.1  christos print_register_list (char *buf, size_t size, const aarch64_opnd_info *opnd,
   2891  1.1  christos 		     const char *prefix)
   2892  1.1  christos {
   2893  1.1  christos   const int num_regs = opnd->reglist.num_regs;
   2894  1.1  christos   const int first_reg = opnd->reglist.first_regno;
   2895  1.1  christos   const int last_reg = (first_reg + num_regs - 1) & 0x1f;
   2896  1.1  christos   const char *qlf_name = aarch64_get_qualifier_name (opnd->qualifier);
   2897  1.1  christos   char tb[8];	/* Temporary buffer.  */
   2898  1.1  christos 
   2899  1.1  christos   assert (opnd->type != AARCH64_OPND_LEt || opnd->reglist.has_index);
   2900  1.1  christos   assert (num_regs >= 1 && num_regs <= 4);
   2901  1.7  christos 
   2902  1.7  christos   /* Prepare the index if any.  */
   2903  1.1  christos   if (opnd->reglist.has_index)
   2904  1.1  christos     /* PR 21096: The %100 is to silence a warning about possible truncation.  */
   2905  1.1  christos     snprintf (tb, 8, "[%" PRIi64 "]", (opnd->reglist.index % 100));
   2906  1.1  christos   else
   2907  1.1  christos     tb[0] = '\0';
   2908  1.1  christos 
   2909  1.1  christos   /* The hyphenated form is preferred for disassembly if there are
   2910  1.7  christos      more than two registers in the list, and the register numbers
   2911  1.7  christos      are monotonically increasing in increments of one.  */
   2912  1.1  christos   if (num_regs > 2 && last_reg > first_reg)
   2913  1.1  christos     snprintf (buf, size, "{%s%d.%s-%s%d.%s}%s", prefix, first_reg, qlf_name,
   2914  1.1  christos 	      prefix, last_reg, qlf_name, tb);
   2915  1.1  christos   else
   2916  1.1  christos     {
   2917  1.1  christos       const int reg0 = first_reg;
   2918  1.1  christos       const int reg1 = (first_reg + 1) & 0x1f;
   2919  1.1  christos       const int reg2 = (first_reg + 2) & 0x1f;
   2920  1.1  christos       const int reg3 = (first_reg + 3) & 0x1f;
   2921  1.1  christos 
   2922  1.7  christos       switch (num_regs)
   2923  1.1  christos 	{
   2924  1.1  christos 	case 1:
   2925  1.7  christos 	  snprintf (buf, size, "{%s%d.%s}%s", prefix, reg0, qlf_name, tb);
   2926  1.7  christos 	  break;
   2927  1.1  christos 	case 2:
   2928  1.1  christos 	  snprintf (buf, size, "{%s%d.%s, %s%d.%s}%s", prefix, reg0, qlf_name,
   2929  1.7  christos 		    prefix, reg1, qlf_name, tb);
   2930  1.7  christos 	  break;
   2931  1.7  christos 	case 3:
   2932  1.1  christos 	  snprintf (buf, size, "{%s%d.%s, %s%d.%s, %s%d.%s}%s",
   2933  1.1  christos 		    prefix, reg0, qlf_name, prefix, reg1, qlf_name,
   2934  1.7  christos 		    prefix, reg2, qlf_name, tb);
   2935  1.7  christos 	  break;
   2936  1.7  christos 	case 4:
   2937  1.1  christos 	  snprintf (buf, size, "{%s%d.%s, %s%d.%s, %s%d.%s, %s%d.%s}%s",
   2938  1.1  christos 		    prefix, reg0, qlf_name, prefix, reg1, qlf_name,
   2939  1.1  christos 		    prefix, reg2, qlf_name, prefix, reg3, qlf_name, tb);
   2940  1.1  christos 	  break;
   2941  1.1  christos 	}
   2942  1.7  christos     }
   2943  1.7  christos }
   2944  1.7  christos 
   2945  1.7  christos /* Print the register+immediate address in OPND to BUF, which has SIZE
   2946  1.7  christos    characters.  BASE is the name of the base register.  */
   2947  1.7  christos 
   2948  1.7  christos static void
   2949  1.7  christos print_immediate_offset_address (char *buf, size_t size,
   2950  1.7  christos 				const aarch64_opnd_info *opnd,
   2951  1.7  christos 				const char *base)
   2952  1.7  christos {
   2953  1.7  christos   if (opnd->addr.writeback)
   2954  1.7  christos     {
   2955  1.7  christos       if (opnd->addr.preind)
   2956  1.7  christos 	snprintf (buf, size, "[%s, #%d]!", base, opnd->addr.offset.imm);
   2957  1.7  christos       else
   2958  1.7  christos 	snprintf (buf, size, "[%s], #%d", base, opnd->addr.offset.imm);
   2959  1.7  christos     }
   2960  1.7  christos   else
   2961  1.7  christos     {
   2962  1.7  christos       if (opnd->shifter.operator_present)
   2963  1.7  christos 	{
   2964  1.7  christos 	  assert (opnd->shifter.kind == AARCH64_MOD_MUL_VL);
   2965  1.7  christos 	  snprintf (buf, size, "[%s, #%d, mul vl]",
   2966  1.7  christos 		    base, opnd->addr.offset.imm);
   2967  1.7  christos 	}
   2968  1.7  christos       else if (opnd->addr.offset.imm)
   2969  1.7  christos 	snprintf (buf, size, "[%s, #%d]", base, opnd->addr.offset.imm);
   2970  1.7  christos       else
   2971  1.7  christos 	snprintf (buf, size, "[%s]", base);
   2972  1.1  christos     }
   2973  1.7  christos }
   2974  1.7  christos 
   2975  1.1  christos /* Produce the string representation of the register offset address operand
   2976  1.1  christos    *OPND in the buffer pointed by BUF of size SIZE.  BASE and OFFSET are
   2977  1.7  christos    the names of the base and offset registers.  */
   2978  1.7  christos static void
   2979  1.1  christos print_register_offset_address (char *buf, size_t size,
   2980  1.6  christos 			       const aarch64_opnd_info *opnd,
   2981  1.1  christos 			       const char *base, const char *offset)
   2982  1.1  christos {
   2983  1.1  christos   char tb[16];			/* Temporary buffer.  */
   2984  1.1  christos   bfd_boolean print_extend_p = TRUE;
   2985  1.1  christos   bfd_boolean print_amount_p = TRUE;
   2986  1.1  christos   const char *shift_name = aarch64_operand_modifiers[opnd->shifter.kind].name;
   2987  1.1  christos 
   2988  1.1  christos   if (!opnd->shifter.amount && (opnd->qualifier != AARCH64_OPND_QLF_S_B
   2989  1.1  christos 				|| !opnd->shifter.amount_present))
   2990  1.1  christos     {
   2991  1.1  christos       /* Not print the shift/extend amount when the amount is zero and
   2992  1.1  christos          when it is not the special case of 8-bit load/store instruction.  */
   2993  1.7  christos       print_amount_p = FALSE;
   2994  1.1  christos       /* Likewise, no need to print the shift operator LSL in such a
   2995  1.1  christos 	 situation.  */
   2996  1.1  christos       if (opnd->shifter.kind == AARCH64_MOD_LSL)
   2997  1.1  christos 	print_extend_p = FALSE;
   2998  1.1  christos     }
   2999  1.1  christos 
   3000  1.1  christos   /* Prepare for the extend/shift.  */
   3001  1.7  christos   if (print_extend_p)
   3002  1.7  christos     {
   3003  1.7  christos       if (print_amount_p)
   3004  1.1  christos 	snprintf (tb, sizeof (tb), ", %s #%" PRIi64, shift_name,
   3005  1.7  christos   /* PR 21096: The %100 is to silence a warning about possible truncation.  */
   3006  1.1  christos 		  (opnd->shifter.amount % 100));
   3007  1.1  christos       else
   3008  1.1  christos 	snprintf (tb, sizeof (tb), ", %s", shift_name);
   3009  1.1  christos     }
   3010  1.7  christos   else
   3011  1.1  christos     tb[0] = '\0';
   3012  1.1  christos 
   3013  1.1  christos   snprintf (buf, size, "[%s, %s%s]", base, offset, tb);
   3014  1.1  christos }
   3015  1.1  christos 
   3016  1.1  christos /* Generate the string representation of the operand OPNDS[IDX] for OPCODE
   3017  1.1  christos    in *BUF.  The caller should pass in the maximum size of *BUF in SIZE.
   3018  1.1  christos    PC, PCREL_P and ADDRESS are used to pass in and return information about
   3019  1.1  christos    the PC-relative address calculation, where the PC value is passed in
   3020  1.1  christos    PC.  If the operand is pc-relative related, *PCREL_P (if PCREL_P non-NULL)
   3021  1.1  christos    will return 1 and *ADDRESS (if ADDRESS non-NULL) will return the
   3022  1.1  christos    calculated address; otherwise, *PCREL_P (if PCREL_P non-NULL) returns 0.
   3023  1.1  christos 
   3024  1.1  christos    The function serves both the disassembler and the assembler diagnostics
   3025  1.1  christos    issuer, which is the reason why it lives in this file.  */
   3026  1.1  christos 
   3027  1.1  christos void
   3028  1.1  christos aarch64_print_operand (char *buf, size_t size, bfd_vma pc,
   3029  1.1  christos 		       const aarch64_opcode *opcode,
   3030  1.7  christos 		       const aarch64_opnd_info *opnds, int idx, int *pcrel_p,
   3031  1.1  christos 		       bfd_vma *address)
   3032  1.1  christos {
   3033  1.1  christos   unsigned int i, num_conds;
   3034  1.7  christos   const char *name = NULL;
   3035  1.1  christos   const aarch64_opnd_info *opnd = opnds + idx;
   3036  1.1  christos   enum aarch64_modifier_kind kind;
   3037  1.1  christos   uint64_t addr, enum_value;
   3038  1.1  christos 
   3039  1.1  christos   buf[0] = '\0';
   3040  1.1  christos   if (pcrel_p)
   3041  1.1  christos     *pcrel_p = 0;
   3042  1.1  christos 
   3043  1.1  christos   switch (opnd->type)
   3044  1.1  christos     {
   3045  1.1  christos     case AARCH64_OPND_Rd:
   3046  1.1  christos     case AARCH64_OPND_Rn:
   3047  1.1  christos     case AARCH64_OPND_Rm:
   3048  1.1  christos     case AARCH64_OPND_Rt:
   3049  1.1  christos     case AARCH64_OPND_Rt2:
   3050  1.3  christos     case AARCH64_OPND_Rs:
   3051  1.7  christos     case AARCH64_OPND_Ra:
   3052  1.1  christos     case AARCH64_OPND_Rt_SYS:
   3053  1.1  christos     case AARCH64_OPND_PAIRREG:
   3054  1.1  christos     case AARCH64_OPND_SVE_Rm:
   3055  1.7  christos       /* The optional-ness of <Xt> in e.g. IC <ic_op>{, <Xt>} is determined by
   3056  1.7  christos 	 the <ic_op>, therefore we we use opnd->present to override the
   3057  1.7  christos 	 generic optional-ness information.  */
   3058  1.7  christos       if (opnd->type == AARCH64_OPND_Rt_SYS)
   3059  1.7  christos 	{
   3060  1.1  christos 	  if (!opnd->present)
   3061  1.7  christos 	    break;
   3062  1.7  christos 	}
   3063  1.7  christos       /* Omit the operand, e.g. RET.  */
   3064  1.1  christos       else if (optional_operand_p (opcode, idx)
   3065  1.1  christos 	       && (opnd->reg.regno
   3066  1.1  christos 		   == get_optional_operand_default_value (opcode)))
   3067  1.1  christos 	break;
   3068  1.1  christos       assert (opnd->qualifier == AARCH64_OPND_QLF_W
   3069  1.1  christos 	      || opnd->qualifier == AARCH64_OPND_QLF_X);
   3070  1.1  christos       snprintf (buf, size, "%s",
   3071  1.1  christos 		get_int_reg_name (opnd->reg.regno, opnd->qualifier, 0));
   3072  1.1  christos       break;
   3073  1.7  christos 
   3074  1.7  christos     case AARCH64_OPND_Rd_SP:
   3075  1.1  christos     case AARCH64_OPND_Rn_SP:
   3076  1.1  christos     case AARCH64_OPND_SVE_Rn_SP:
   3077  1.1  christos     case AARCH64_OPND_Rm_SP:
   3078  1.1  christos       assert (opnd->qualifier == AARCH64_OPND_QLF_W
   3079  1.1  christos 	      || opnd->qualifier == AARCH64_OPND_QLF_WSP
   3080  1.1  christos 	      || opnd->qualifier == AARCH64_OPND_QLF_X
   3081  1.1  christos 	      || opnd->qualifier == AARCH64_OPND_QLF_SP);
   3082  1.1  christos       snprintf (buf, size, "%s",
   3083  1.1  christos 		get_int_reg_name (opnd->reg.regno, opnd->qualifier, 1));
   3084  1.1  christos       break;
   3085  1.1  christos 
   3086  1.1  christos     case AARCH64_OPND_Rm_EXT:
   3087  1.1  christos       kind = opnd->shifter.kind;
   3088  1.1  christos       assert (idx == 1 || idx == 2);
   3089  1.1  christos       if ((aarch64_stack_pointer_p (opnds)
   3090  1.1  christos 	   || (idx == 2 && aarch64_stack_pointer_p (opnds + 1)))
   3091  1.1  christos 	  && ((opnd->qualifier == AARCH64_OPND_QLF_W
   3092  1.1  christos 	       && opnds[0].qualifier == AARCH64_OPND_QLF_W
   3093  1.1  christos 	       && kind == AARCH64_MOD_UXTW)
   3094  1.1  christos 	      || (opnd->qualifier == AARCH64_OPND_QLF_X
   3095  1.1  christos 		  && kind == AARCH64_MOD_UXTX)))
   3096  1.1  christos 	{
   3097  1.1  christos 	  /* 'LSL' is the preferred form in this case.  */
   3098  1.1  christos 	  kind = AARCH64_MOD_LSL;
   3099  1.1  christos 	  if (opnd->shifter.amount == 0)
   3100  1.1  christos 	    {
   3101  1.1  christos 	      /* Shifter omitted.  */
   3102  1.1  christos 	      snprintf (buf, size, "%s",
   3103  1.1  christos 			get_int_reg_name (opnd->reg.regno, opnd->qualifier, 0));
   3104  1.1  christos 	      break;
   3105  1.7  christos 	    }
   3106  1.1  christos 	}
   3107  1.1  christos       if (opnd->shifter.amount)
   3108  1.1  christos 	snprintf (buf, size, "%s, %s #%" PRIi64,
   3109  1.1  christos 		  get_int_reg_name (opnd->reg.regno, opnd->qualifier, 0),
   3110  1.1  christos 		  aarch64_operand_modifiers[kind].name,
   3111  1.1  christos 		  opnd->shifter.amount);
   3112  1.1  christos       else
   3113  1.1  christos 	snprintf (buf, size, "%s, %s",
   3114  1.1  christos 		  get_int_reg_name (opnd->reg.regno, opnd->qualifier, 0),
   3115  1.1  christos 		  aarch64_operand_modifiers[kind].name);
   3116  1.1  christos       break;
   3117  1.1  christos 
   3118  1.1  christos     case AARCH64_OPND_Rm_SFT:
   3119  1.1  christos       assert (opnd->qualifier == AARCH64_OPND_QLF_W
   3120  1.1  christos 	      || opnd->qualifier == AARCH64_OPND_QLF_X);
   3121  1.1  christos       if (opnd->shifter.amount == 0 && opnd->shifter.kind == AARCH64_MOD_LSL)
   3122  1.7  christos 	snprintf (buf, size, "%s",
   3123  1.1  christos 		  get_int_reg_name (opnd->reg.regno, opnd->qualifier, 0));
   3124  1.1  christos       else
   3125  1.1  christos 	snprintf (buf, size, "%s, %s #%" PRIi64,
   3126  1.1  christos 		  get_int_reg_name (opnd->reg.regno, opnd->qualifier, 0),
   3127  1.1  christos 		  aarch64_operand_modifiers[opnd->shifter.kind].name,
   3128  1.1  christos 		  opnd->shifter.amount);
   3129  1.1  christos       break;
   3130  1.1  christos 
   3131  1.1  christos     case AARCH64_OPND_Fd:
   3132  1.1  christos     case AARCH64_OPND_Fn:
   3133  1.1  christos     case AARCH64_OPND_Fm:
   3134  1.1  christos     case AARCH64_OPND_Fa:
   3135  1.1  christos     case AARCH64_OPND_Ft:
   3136  1.1  christos     case AARCH64_OPND_Ft2:
   3137  1.7  christos     case AARCH64_OPND_Sd:
   3138  1.7  christos     case AARCH64_OPND_Sn:
   3139  1.7  christos     case AARCH64_OPND_Sm:
   3140  1.7  christos     case AARCH64_OPND_SVE_VZn:
   3141  1.1  christos     case AARCH64_OPND_SVE_Vd:
   3142  1.1  christos     case AARCH64_OPND_SVE_Vm:
   3143  1.1  christos     case AARCH64_OPND_SVE_Vn:
   3144  1.1  christos       snprintf (buf, size, "%s%d", aarch64_get_qualifier_name (opnd->qualifier),
   3145  1.1  christos 		opnd->reg.regno);
   3146  1.1  christos       break;
   3147  1.1  christos 
   3148  1.1  christos     case AARCH64_OPND_Vd:
   3149  1.1  christos     case AARCH64_OPND_Vn:
   3150  1.1  christos     case AARCH64_OPND_Vm:
   3151  1.1  christos       snprintf (buf, size, "v%d.%s", opnd->reg.regno,
   3152  1.1  christos 		aarch64_get_qualifier_name (opnd->qualifier));
   3153  1.1  christos       break;
   3154  1.1  christos 
   3155  1.6  christos     case AARCH64_OPND_Ed:
   3156  1.1  christos     case AARCH64_OPND_En:
   3157  1.1  christos     case AARCH64_OPND_Em:
   3158  1.1  christos       snprintf (buf, size, "v%d.%s[%" PRIi64 "]", opnd->reglane.regno,
   3159  1.1  christos 		aarch64_get_qualifier_name (opnd->qualifier),
   3160  1.1  christos 		opnd->reglane.index);
   3161  1.1  christos       break;
   3162  1.1  christos 
   3163  1.1  christos     case AARCH64_OPND_VdD1:
   3164  1.1  christos     case AARCH64_OPND_VnD1:
   3165  1.1  christos       snprintf (buf, size, "v%d.d[1]", opnd->reg.regno);
   3166  1.1  christos       break;
   3167  1.1  christos 
   3168  1.1  christos     case AARCH64_OPND_LVn:
   3169  1.7  christos     case AARCH64_OPND_LVt:
   3170  1.7  christos     case AARCH64_OPND_LVt_AL:
   3171  1.7  christos     case AARCH64_OPND_LEt:
   3172  1.7  christos       print_register_list (buf, size, opnd, "v");
   3173  1.7  christos       break;
   3174  1.7  christos 
   3175  1.7  christos     case AARCH64_OPND_SVE_Pd:
   3176  1.7  christos     case AARCH64_OPND_SVE_Pg3:
   3177  1.7  christos     case AARCH64_OPND_SVE_Pg4_5:
   3178  1.7  christos     case AARCH64_OPND_SVE_Pg4_10:
   3179  1.7  christos     case AARCH64_OPND_SVE_Pg4_16:
   3180  1.7  christos     case AARCH64_OPND_SVE_Pm:
   3181  1.7  christos     case AARCH64_OPND_SVE_Pn:
   3182  1.7  christos     case AARCH64_OPND_SVE_Pt:
   3183  1.7  christos       if (opnd->qualifier == AARCH64_OPND_QLF_NIL)
   3184  1.7  christos 	snprintf (buf, size, "p%d", opnd->reg.regno);
   3185  1.7  christos       else if (opnd->qualifier == AARCH64_OPND_QLF_P_Z
   3186  1.7  christos 	       || opnd->qualifier == AARCH64_OPND_QLF_P_M)
   3187  1.7  christos 	snprintf (buf, size, "p%d/%s", opnd->reg.regno,
   3188  1.7  christos 		  aarch64_get_qualifier_name (opnd->qualifier));
   3189  1.1  christos       else
   3190  1.1  christos 	snprintf (buf, size, "p%d.%s", opnd->reg.regno,
   3191  1.7  christos 		  aarch64_get_qualifier_name (opnd->qualifier));
   3192  1.7  christos       break;
   3193  1.7  christos 
   3194  1.7  christos     case AARCH64_OPND_SVE_Za_5:
   3195  1.7  christos     case AARCH64_OPND_SVE_Za_16:
   3196  1.7  christos     case AARCH64_OPND_SVE_Zd:
   3197  1.7  christos     case AARCH64_OPND_SVE_Zm_5:
   3198  1.7  christos     case AARCH64_OPND_SVE_Zm_16:
   3199  1.7  christos     case AARCH64_OPND_SVE_Zn:
   3200  1.7  christos     case AARCH64_OPND_SVE_Zt:
   3201  1.7  christos       if (opnd->qualifier == AARCH64_OPND_QLF_NIL)
   3202  1.7  christos 	snprintf (buf, size, "z%d", opnd->reg.regno);
   3203  1.7  christos       else
   3204  1.7  christos 	snprintf (buf, size, "z%d.%s", opnd->reg.regno,
   3205  1.7  christos 		  aarch64_get_qualifier_name (opnd->qualifier));
   3206  1.7  christos       break;
   3207  1.7  christos 
   3208  1.7  christos     case AARCH64_OPND_SVE_ZnxN:
   3209  1.7  christos     case AARCH64_OPND_SVE_ZtxN:
   3210  1.7  christos       print_register_list (buf, size, opnd, "z");
   3211  1.7  christos       break;
   3212  1.7  christos 
   3213  1.7  christos     case AARCH64_OPND_SVE_Zm3_INDEX:
   3214  1.7  christos     case AARCH64_OPND_SVE_Zm3_22_INDEX:
   3215  1.7  christos     case AARCH64_OPND_SVE_Zm4_INDEX:
   3216  1.7  christos     case AARCH64_OPND_SVE_Zn_INDEX:
   3217  1.7  christos       snprintf (buf, size, "z%d.%s[%" PRIi64 "]", opnd->reglane.regno,
   3218  1.7  christos 		aarch64_get_qualifier_name (opnd->qualifier),
   3219  1.7  christos 		opnd->reglane.index);
   3220  1.7  christos       break;
   3221  1.7  christos 
   3222  1.1  christos     case AARCH64_OPND_CRn:
   3223  1.1  christos     case AARCH64_OPND_CRm:
   3224  1.1  christos       snprintf (buf, size, "C%" PRIi64, opnd->imm.value);
   3225  1.1  christos       break;
   3226  1.1  christos 
   3227  1.1  christos     case AARCH64_OPND_IDX:
   3228  1.1  christos     case AARCH64_OPND_IMM:
   3229  1.1  christos     case AARCH64_OPND_WIDTH:
   3230  1.1  christos     case AARCH64_OPND_UIMM3_OP1:
   3231  1.1  christos     case AARCH64_OPND_UIMM3_OP2:
   3232  1.1  christos     case AARCH64_OPND_BIT_NUM:
   3233  1.1  christos     case AARCH64_OPND_IMM_VLSL:
   3234  1.1  christos     case AARCH64_OPND_IMM_VLSR:
   3235  1.1  christos     case AARCH64_OPND_SHLL_IMM:
   3236  1.1  christos     case AARCH64_OPND_IMM0:
   3237  1.7  christos     case AARCH64_OPND_IMMR:
   3238  1.7  christos     case AARCH64_OPND_IMMS:
   3239  1.7  christos     case AARCH64_OPND_FBITS:
   3240  1.7  christos     case AARCH64_OPND_SIMM5:
   3241  1.7  christos     case AARCH64_OPND_SVE_SHLIMM_PRED:
   3242  1.7  christos     case AARCH64_OPND_SVE_SHLIMM_UNPRED:
   3243  1.7  christos     case AARCH64_OPND_SVE_SHRIMM_PRED:
   3244  1.7  christos     case AARCH64_OPND_SVE_SHRIMM_UNPRED:
   3245  1.7  christos     case AARCH64_OPND_SVE_SIMM5:
   3246  1.7  christos     case AARCH64_OPND_SVE_SIMM5B:
   3247  1.7  christos     case AARCH64_OPND_SVE_SIMM6:
   3248  1.7  christos     case AARCH64_OPND_SVE_SIMM8:
   3249  1.7  christos     case AARCH64_OPND_SVE_UIMM3:
   3250  1.7  christos     case AARCH64_OPND_SVE_UIMM7:
   3251  1.7  christos     case AARCH64_OPND_SVE_UIMM8:
   3252  1.7  christos     case AARCH64_OPND_SVE_UIMM8_53:
   3253  1.7  christos     case AARCH64_OPND_IMM_ROT1:
   3254  1.7  christos     case AARCH64_OPND_IMM_ROT2:
   3255  1.1  christos     case AARCH64_OPND_IMM_ROT3:
   3256  1.1  christos     case AARCH64_OPND_SVE_IMM_ROT1:
   3257  1.1  christos     case AARCH64_OPND_SVE_IMM_ROT2:
   3258  1.7  christos       snprintf (buf, size, "#%" PRIi64, opnd->imm.value);
   3259  1.7  christos       break;
   3260  1.7  christos 
   3261  1.7  christos     case AARCH64_OPND_SVE_I1_HALF_ONE:
   3262  1.7  christos     case AARCH64_OPND_SVE_I1_HALF_TWO:
   3263  1.7  christos     case AARCH64_OPND_SVE_I1_ZERO_ONE:
   3264  1.7  christos       {
   3265  1.7  christos 	single_conv_t c;
   3266  1.7  christos 	c.i = opnd->imm.value;
   3267  1.7  christos 	snprintf (buf, size, "#%.1f", c.f);
   3268  1.7  christos 	break;
   3269  1.7  christos       }
   3270  1.7  christos 
   3271  1.7  christos     case AARCH64_OPND_SVE_PATTERN:
   3272  1.7  christos       if (optional_operand_p (opcode, idx)
   3273  1.7  christos 	  && opnd->imm.value == get_optional_operand_default_value (opcode))
   3274  1.7  christos 	break;
   3275  1.7  christos       enum_value = opnd->imm.value;
   3276  1.7  christos       assert (enum_value < ARRAY_SIZE (aarch64_sve_pattern_array));
   3277  1.7  christos       if (aarch64_sve_pattern_array[enum_value])
   3278  1.7  christos 	snprintf (buf, size, "%s", aarch64_sve_pattern_array[enum_value]);
   3279  1.7  christos       else
   3280  1.7  christos 	snprintf (buf, size, "#%" PRIi64, opnd->imm.value);
   3281  1.7  christos       break;
   3282  1.7  christos 
   3283  1.7  christos     case AARCH64_OPND_SVE_PATTERN_SCALED:
   3284  1.7  christos       if (optional_operand_p (opcode, idx)
   3285  1.7  christos 	  && !opnd->shifter.operator_present
   3286  1.7  christos 	  && opnd->imm.value == get_optional_operand_default_value (opcode))
   3287  1.7  christos 	break;
   3288  1.7  christos       enum_value = opnd->imm.value;
   3289  1.7  christos       assert (enum_value < ARRAY_SIZE (aarch64_sve_pattern_array));
   3290  1.7  christos       if (aarch64_sve_pattern_array[opnd->imm.value])
   3291  1.7  christos 	snprintf (buf, size, "%s", aarch64_sve_pattern_array[opnd->imm.value]);
   3292  1.7  christos       else
   3293  1.7  christos 	snprintf (buf, size, "#%" PRIi64, opnd->imm.value);
   3294  1.7  christos       if (opnd->shifter.operator_present)
   3295  1.7  christos 	{
   3296  1.7  christos 	  size_t len = strlen (buf);
   3297  1.7  christos 	  snprintf (buf + len, size - len, ", %s #%" PRIi64,
   3298  1.7  christos 		    aarch64_operand_modifiers[opnd->shifter.kind].name,
   3299  1.7  christos 		    opnd->shifter.amount);
   3300  1.7  christos 	}
   3301  1.7  christos       break;
   3302  1.7  christos 
   3303  1.7  christos     case AARCH64_OPND_SVE_PRFOP:
   3304  1.7  christos       enum_value = opnd->imm.value;
   3305  1.7  christos       assert (enum_value < ARRAY_SIZE (aarch64_sve_prfop_array));
   3306  1.7  christos       if (aarch64_sve_prfop_array[enum_value])
   3307  1.7  christos 	snprintf (buf, size, "%s", aarch64_sve_prfop_array[enum_value]);
   3308  1.7  christos       else
   3309  1.1  christos 	snprintf (buf, size, "#%" PRIi64, opnd->imm.value);
   3310  1.1  christos       break;
   3311  1.1  christos 
   3312  1.1  christos     case AARCH64_OPND_IMM_MOV:
   3313  1.1  christos       switch (aarch64_get_qualifier_esize (opnds[0].qualifier))
   3314  1.1  christos 	{
   3315  1.1  christos 	case 4:	/* e.g. MOV Wd, #<imm32>.  */
   3316  1.1  christos 	    {
   3317  1.1  christos 	      int imm32 = opnd->imm.value;
   3318  1.1  christos 	      snprintf (buf, size, "#0x%-20x\t// #%d", imm32, imm32);
   3319  1.1  christos 	    }
   3320  1.1  christos 	  break;
   3321  1.1  christos 	case 8:	/* e.g. MOV Xd, #<imm64>.  */
   3322  1.1  christos 	  snprintf (buf, size, "#0x%-20" PRIx64 "\t// #%" PRIi64,
   3323  1.1  christos 		    opnd->imm.value, opnd->imm.value);
   3324  1.1  christos 	  break;
   3325  1.1  christos 	default: assert (0);
   3326  1.1  christos 	}
   3327  1.1  christos       break;
   3328  1.1  christos 
   3329  1.1  christos     case AARCH64_OPND_FPIMM0:
   3330  1.1  christos       snprintf (buf, size, "#0.0");
   3331  1.1  christos       break;
   3332  1.1  christos 
   3333  1.7  christos     case AARCH64_OPND_LIMM:
   3334  1.7  christos     case AARCH64_OPND_AIMM:
   3335  1.7  christos     case AARCH64_OPND_HALF:
   3336  1.1  christos     case AARCH64_OPND_SVE_INV_LIMM:
   3337  1.7  christos     case AARCH64_OPND_SVE_LIMM:
   3338  1.1  christos     case AARCH64_OPND_SVE_LIMM_MOV:
   3339  1.1  christos       if (opnd->shifter.amount)
   3340  1.1  christos 	snprintf (buf, size, "#0x%" PRIx64 ", lsl #%" PRIi64, opnd->imm.value,
   3341  1.1  christos 		  opnd->shifter.amount);
   3342  1.1  christos       else
   3343  1.1  christos 	snprintf (buf, size, "#0x%" PRIx64, opnd->imm.value);
   3344  1.1  christos       break;
   3345  1.1  christos 
   3346  1.1  christos     case AARCH64_OPND_SIMD_IMM:
   3347  1.1  christos     case AARCH64_OPND_SIMD_IMM_SFT:
   3348  1.1  christos       if ((! opnd->shifter.amount && opnd->shifter.kind == AARCH64_MOD_LSL)
   3349  1.7  christos 	  || opnd->shifter.kind == AARCH64_MOD_NONE)
   3350  1.1  christos 	snprintf (buf, size, "#0x%" PRIx64, opnd->imm.value);
   3351  1.1  christos       else
   3352  1.1  christos 	snprintf (buf, size, "#0x%" PRIx64 ", %s #%" PRIi64, opnd->imm.value,
   3353  1.1  christos 		  aarch64_operand_modifiers[opnd->shifter.kind].name,
   3354  1.7  christos 		  opnd->shifter.amount);
   3355  1.7  christos       break;
   3356  1.7  christos 
   3357  1.7  christos     case AARCH64_OPND_SVE_AIMM:
   3358  1.7  christos     case AARCH64_OPND_SVE_ASIMM:
   3359  1.7  christos       if (opnd->shifter.amount)
   3360  1.7  christos 	snprintf (buf, size, "#%" PRIi64 ", lsl #%" PRIi64, opnd->imm.value,
   3361  1.7  christos 		  opnd->shifter.amount);
   3362  1.7  christos       else
   3363  1.1  christos 	snprintf (buf, size, "#%" PRIi64, opnd->imm.value);
   3364  1.1  christos       break;
   3365  1.7  christos 
   3366  1.1  christos     case AARCH64_OPND_FPIMM:
   3367  1.1  christos     case AARCH64_OPND_SIMD_FPIMM:
   3368  1.6  christos     case AARCH64_OPND_SVE_FPIMM8:
   3369  1.6  christos       switch (aarch64_get_qualifier_esize (opnds[0].qualifier))
   3370  1.6  christos 	{
   3371  1.6  christos 	case 2:	/* e.g. FMOV <Hd>, #<imm>.  */
   3372  1.6  christos 	    {
   3373  1.6  christos 	      half_conv_t c;
   3374  1.6  christos 	      c.i = expand_fp_imm (2, opnd->imm.value);
   3375  1.1  christos 	      snprintf (buf, size,  "#%.18e", c.f);
   3376  1.1  christos 	    }
   3377  1.1  christos 	  break;
   3378  1.6  christos 	case 4:	/* e.g. FMOV <Vd>.4S, #<imm>.  */
   3379  1.1  christos 	    {
   3380  1.1  christos 	      single_conv_t c;
   3381  1.1  christos 	      c.i = expand_fp_imm (4, opnd->imm.value);
   3382  1.1  christos 	      snprintf (buf, size,  "#%.18e", c.f);
   3383  1.1  christos 	    }
   3384  1.1  christos 	  break;
   3385  1.6  christos 	case 8:	/* e.g. FMOV <Sd>, #<imm>.  */
   3386  1.1  christos 	    {
   3387  1.1  christos 	      double_conv_t c;
   3388  1.1  christos 	      c.i = expand_fp_imm (8, opnd->imm.value);
   3389  1.1  christos 	      snprintf (buf, size,  "#%.18e", c.d);
   3390  1.1  christos 	    }
   3391  1.1  christos 	  break;
   3392  1.1  christos 	default: assert (0);
   3393  1.1  christos 	}
   3394  1.1  christos       break;
   3395  1.1  christos 
   3396  1.1  christos     case AARCH64_OPND_CCMP_IMM:
   3397  1.1  christos     case AARCH64_OPND_NZCV:
   3398  1.1  christos     case AARCH64_OPND_EXCEPTION:
   3399  1.1  christos     case AARCH64_OPND_UIMM4:
   3400  1.1  christos     case AARCH64_OPND_UIMM7:
   3401  1.1  christos       if (optional_operand_p (opcode, idx) == TRUE
   3402  1.1  christos 	  && (opnd->imm.value ==
   3403  1.1  christos 	      (int64_t) get_optional_operand_default_value (opcode)))
   3404  1.1  christos 	/* Omit the operand, e.g. DCPS1.  */
   3405  1.1  christos 	break;
   3406  1.1  christos       snprintf (buf, size, "#0x%x", (unsigned int)opnd->imm.value);
   3407  1.1  christos       break;
   3408  1.1  christos 
   3409  1.7  christos     case AARCH64_OPND_COND:
   3410  1.7  christos     case AARCH64_OPND_COND1:
   3411  1.7  christos       snprintf (buf, size, "%s", opnd->cond->names[0]);
   3412  1.7  christos       num_conds = ARRAY_SIZE (opnd->cond->names);
   3413  1.7  christos       for (i = 1; i < num_conds && opnd->cond->names[i]; ++i)
   3414  1.7  christos 	{
   3415  1.7  christos 	  size_t len = strlen (buf);
   3416  1.7  christos 	  if (i == 1)
   3417  1.7  christos 	    snprintf (buf + len, size - len, "  // %s = %s",
   3418  1.7  christos 		      opnd->cond->names[0], opnd->cond->names[i]);
   3419  1.7  christos 	  else
   3420  1.1  christos 	    snprintf (buf + len, size - len, ", %s",
   3421  1.1  christos 		      opnd->cond->names[i]);
   3422  1.1  christos 	}
   3423  1.1  christos       break;
   3424  1.1  christos 
   3425  1.1  christos     case AARCH64_OPND_ADDR_ADRP:
   3426  1.1  christos       addr = ((pc + AARCH64_PCREL_OFFSET) & ~(uint64_t)0xfff)
   3427  1.1  christos 	+ opnd->imm.value;
   3428  1.1  christos       if (pcrel_p)
   3429  1.1  christos 	*pcrel_p = 1;
   3430  1.1  christos       if (address)
   3431  1.1  christos 	*address = addr;
   3432  1.1  christos       /* This is not necessary during the disassembling, as print_address_func
   3433  1.1  christos 	 in the disassemble_info will take care of the printing.  But some
   3434  1.1  christos 	 other callers may be still interested in getting the string in *STR,
   3435  1.1  christos 	 so here we do snprintf regardless.  */
   3436  1.1  christos       snprintf (buf, size, "#0x%" PRIx64, addr);
   3437  1.1  christos       break;
   3438  1.1  christos 
   3439  1.1  christos     case AARCH64_OPND_ADDR_PCREL14:
   3440  1.1  christos     case AARCH64_OPND_ADDR_PCREL19:
   3441  1.1  christos     case AARCH64_OPND_ADDR_PCREL21:
   3442  1.1  christos     case AARCH64_OPND_ADDR_PCREL26:
   3443  1.1  christos       addr = pc + AARCH64_PCREL_OFFSET + opnd->imm.value;
   3444  1.1  christos       if (pcrel_p)
   3445  1.1  christos 	*pcrel_p = 1;
   3446  1.1  christos       if (address)
   3447  1.1  christos 	*address = addr;
   3448  1.1  christos       /* This is not necessary during the disassembling, as print_address_func
   3449  1.1  christos 	 in the disassemble_info will take care of the printing.  But some
   3450  1.1  christos 	 other callers may be still interested in getting the string in *STR,
   3451  1.1  christos 	 so here we do snprintf regardless.  */
   3452  1.1  christos       snprintf (buf, size, "#0x%" PRIx64, addr);
   3453  1.1  christos       break;
   3454  1.1  christos 
   3455  1.1  christos     case AARCH64_OPND_ADDR_SIMPLE:
   3456  1.1  christos     case AARCH64_OPND_SIMD_ADDR_SIMPLE:
   3457  1.1  christos     case AARCH64_OPND_SIMD_ADDR_POST:
   3458  1.1  christos       name = get_64bit_int_reg_name (opnd->addr.base_regno, 1);
   3459  1.1  christos       if (opnd->type == AARCH64_OPND_SIMD_ADDR_POST)
   3460  1.1  christos 	{
   3461  1.1  christos 	  if (opnd->addr.offset.is_reg)
   3462  1.1  christos 	    snprintf (buf, size, "[%s], x%d", name, opnd->addr.offset.regno);
   3463  1.1  christos 	  else
   3464  1.1  christos 	    snprintf (buf, size, "[%s], #%d", name, opnd->addr.offset.imm);
   3465  1.1  christos 	}
   3466  1.1  christos       else
   3467  1.1  christos 	snprintf (buf, size, "[%s]", name);
   3468  1.7  christos       break;
   3469  1.7  christos 
   3470  1.7  christos     case AARCH64_OPND_ADDR_REGOFF:
   3471  1.7  christos     case AARCH64_OPND_SVE_ADDR_RR:
   3472  1.7  christos     case AARCH64_OPND_SVE_ADDR_RR_LSL1:
   3473  1.7  christos     case AARCH64_OPND_SVE_ADDR_RR_LSL2:
   3474  1.7  christos     case AARCH64_OPND_SVE_ADDR_RR_LSL3:
   3475  1.7  christos     case AARCH64_OPND_SVE_ADDR_RX:
   3476  1.7  christos     case AARCH64_OPND_SVE_ADDR_RX_LSL1:
   3477  1.7  christos     case AARCH64_OPND_SVE_ADDR_RX_LSL2:
   3478  1.7  christos     case AARCH64_OPND_SVE_ADDR_RX_LSL3:
   3479  1.7  christos       print_register_offset_address
   3480  1.7  christos 	(buf, size, opnd, get_64bit_int_reg_name (opnd->addr.base_regno, 1),
   3481  1.7  christos 	 get_offset_int_reg_name (opnd));
   3482  1.7  christos       break;
   3483  1.7  christos 
   3484  1.7  christos     case AARCH64_OPND_SVE_ADDR_RZ:
   3485  1.7  christos     case AARCH64_OPND_SVE_ADDR_RZ_LSL1:
   3486  1.7  christos     case AARCH64_OPND_SVE_ADDR_RZ_LSL2:
   3487  1.7  christos     case AARCH64_OPND_SVE_ADDR_RZ_LSL3:
   3488  1.7  christos     case AARCH64_OPND_SVE_ADDR_RZ_XTW_14:
   3489  1.7  christos     case AARCH64_OPND_SVE_ADDR_RZ_XTW_22:
   3490  1.7  christos     case AARCH64_OPND_SVE_ADDR_RZ_XTW1_14:
   3491  1.7  christos     case AARCH64_OPND_SVE_ADDR_RZ_XTW1_22:
   3492  1.7  christos     case AARCH64_OPND_SVE_ADDR_RZ_XTW2_14:
   3493  1.7  christos     case AARCH64_OPND_SVE_ADDR_RZ_XTW2_22:
   3494  1.7  christos     case AARCH64_OPND_SVE_ADDR_RZ_XTW3_14:
   3495  1.7  christos     case AARCH64_OPND_SVE_ADDR_RZ_XTW3_22:
   3496  1.1  christos       print_register_offset_address
   3497  1.1  christos 	(buf, size, opnd, get_64bit_int_reg_name (opnd->addr.base_regno, 1),
   3498  1.1  christos 	 get_addr_sve_reg_name (opnd->addr.offset.regno, opnd->qualifier));
   3499  1.1  christos       break;
   3500  1.1  christos 
   3501  1.7  christos     case AARCH64_OPND_ADDR_SIMM7:
   3502  1.7  christos     case AARCH64_OPND_ADDR_SIMM9:
   3503  1.7  christos     case AARCH64_OPND_ADDR_SIMM9_2:
   3504  1.7  christos     case AARCH64_OPND_ADDR_SIMM10:
   3505  1.7  christos     case AARCH64_OPND_SVE_ADDR_RI_S4x16:
   3506  1.7  christos     case AARCH64_OPND_SVE_ADDR_RI_S4xVL:
   3507  1.7  christos     case AARCH64_OPND_SVE_ADDR_RI_S4x2xVL:
   3508  1.7  christos     case AARCH64_OPND_SVE_ADDR_RI_S4x3xVL:
   3509  1.7  christos     case AARCH64_OPND_SVE_ADDR_RI_S4x4xVL:
   3510  1.7  christos     case AARCH64_OPND_SVE_ADDR_RI_S6xVL:
   3511  1.7  christos     case AARCH64_OPND_SVE_ADDR_RI_S9xVL:
   3512  1.7  christos     case AARCH64_OPND_SVE_ADDR_RI_U6:
   3513  1.7  christos     case AARCH64_OPND_SVE_ADDR_RI_U6x2:
   3514  1.7  christos     case AARCH64_OPND_SVE_ADDR_RI_U6x4:
   3515  1.7  christos     case AARCH64_OPND_SVE_ADDR_RI_U6x8:
   3516  1.7  christos       print_immediate_offset_address
   3517  1.7  christos 	(buf, size, opnd, get_64bit_int_reg_name (opnd->addr.base_regno, 1));
   3518  1.7  christos       break;
   3519  1.7  christos 
   3520  1.7  christos     case AARCH64_OPND_SVE_ADDR_ZI_U5:
   3521  1.7  christos     case AARCH64_OPND_SVE_ADDR_ZI_U5x2:
   3522  1.7  christos     case AARCH64_OPND_SVE_ADDR_ZI_U5x4:
   3523  1.7  christos     case AARCH64_OPND_SVE_ADDR_ZI_U5x8:
   3524  1.7  christos       print_immediate_offset_address
   3525  1.7  christos 	(buf, size, opnd,
   3526  1.7  christos 	 get_addr_sve_reg_name (opnd->addr.base_regno, opnd->qualifier));
   3527  1.7  christos       break;
   3528  1.7  christos 
   3529  1.7  christos     case AARCH64_OPND_SVE_ADDR_ZZ_LSL:
   3530  1.7  christos     case AARCH64_OPND_SVE_ADDR_ZZ_SXTW:
   3531  1.7  christos     case AARCH64_OPND_SVE_ADDR_ZZ_UXTW:
   3532  1.7  christos       print_register_offset_address
   3533  1.1  christos 	(buf, size, opnd,
   3534  1.1  christos 	 get_addr_sve_reg_name (opnd->addr.base_regno, opnd->qualifier),
   3535  1.1  christos 	 get_addr_sve_reg_name (opnd->addr.offset.regno, opnd->qualifier));
   3536  1.1  christos       break;
   3537  1.1  christos 
   3538  1.7  christos     case AARCH64_OPND_ADDR_UIMM12:
   3539  1.1  christos       name = get_64bit_int_reg_name (opnd->addr.base_regno, 1);
   3540  1.1  christos       if (opnd->addr.offset.imm)
   3541  1.1  christos 	snprintf (buf, size, "[%s, #%d]", name, opnd->addr.offset.imm);
   3542  1.1  christos       else
   3543  1.1  christos 	snprintf (buf, size, "[%s]", name);
   3544  1.1  christos       break;
   3545  1.1  christos 
   3546  1.1  christos     case AARCH64_OPND_SYSREG:
   3547  1.1  christos       for (i = 0; aarch64_sys_regs[i].name; ++i)
   3548  1.1  christos 	if (aarch64_sys_regs[i].value == opnd->sysreg
   3549  1.1  christos 	    && ! aarch64_sys_reg_deprecated_p (&aarch64_sys_regs[i]))
   3550  1.1  christos 	  break;
   3551  1.1  christos       if (aarch64_sys_regs[i].name)
   3552  1.1  christos 	snprintf (buf, size, "%s", aarch64_sys_regs[i].name);
   3553  1.1  christos       else
   3554  1.1  christos 	{
   3555  1.1  christos 	  /* Implementation defined system register.  */
   3556  1.1  christos 	  unsigned int value = opnd->sysreg;
   3557  1.1  christos 	  snprintf (buf, size, "s%u_%u_c%u_c%u_%u", (value >> 14) & 0x3,
   3558  1.1  christos 		    (value >> 11) & 0x7, (value >> 7) & 0xf, (value >> 3) & 0xf,
   3559  1.1  christos 		    value & 0x7);
   3560  1.1  christos 	}
   3561  1.1  christos       break;
   3562  1.1  christos 
   3563  1.1  christos     case AARCH64_OPND_PSTATEFIELD:
   3564  1.1  christos       for (i = 0; aarch64_pstatefields[i].name; ++i)
   3565  1.1  christos 	if (aarch64_pstatefields[i].value == opnd->pstatefield)
   3566  1.1  christos 	  break;
   3567  1.1  christos       assert (aarch64_pstatefields[i].name);
   3568  1.1  christos       snprintf (buf, size, "%s", aarch64_pstatefields[i].name);
   3569  1.1  christos       break;
   3570  1.1  christos 
   3571  1.1  christos     case AARCH64_OPND_SYSREG_AT:
   3572  1.6  christos     case AARCH64_OPND_SYSREG_DC:
   3573  1.1  christos     case AARCH64_OPND_SYSREG_IC:
   3574  1.1  christos     case AARCH64_OPND_SYSREG_TLBI:
   3575  1.1  christos       snprintf (buf, size, "%s", opnd->sysins_op->name);
   3576  1.1  christos       break;
   3577  1.1  christos 
   3578  1.1  christos     case AARCH64_OPND_BARRIER:
   3579  1.1  christos       snprintf (buf, size, "%s", opnd->barrier->name);
   3580  1.1  christos       break;
   3581  1.1  christos 
   3582  1.1  christos     case AARCH64_OPND_BARRIER_ISB:
   3583  1.1  christos       /* Operand can be omitted, e.g. in DCPS1.  */
   3584  1.1  christos       if (! optional_operand_p (opcode, idx)
   3585  1.1  christos 	  || (opnd->barrier->value
   3586  1.1  christos 	      != get_optional_operand_default_value (opcode)))
   3587  1.1  christos 	snprintf (buf, size, "#0x%x", opnd->barrier->value);
   3588  1.1  christos       break;
   3589  1.1  christos 
   3590  1.1  christos     case AARCH64_OPND_PRFOP:
   3591  1.1  christos       if (opnd->prfop->name != NULL)
   3592  1.1  christos 	snprintf (buf, size, "%s", opnd->prfop->name);
   3593  1.1  christos       else
   3594  1.6  christos 	snprintf (buf, size, "#0x%02x", opnd->prfop->value);
   3595  1.6  christos       break;
   3596  1.6  christos 
   3597  1.6  christos     case AARCH64_OPND_BARRIER_PSB:
   3598  1.1  christos       snprintf (buf, size, "%s", opnd->hint_option->name);
   3599  1.1  christos       break;
   3600  1.1  christos 
   3601  1.1  christos     default:
   3602  1.1  christos       assert (0);
   3603  1.1  christos     }
   3604  1.1  christos }
   3605  1.1  christos 
   3606  1.1  christos #define CPENC(op0,op1,crn,crm,op2) \
   3608  1.1  christos   ((((op0) << 19) | ((op1) << 16) | ((crn) << 12) | ((crm) << 8) | ((op2) << 5)) >> 5)
   3609  1.1  christos   /* for 3.9.3 Instructions for Accessing Special Purpose Registers */
   3610  1.1  christos #define CPEN_(op1,crm,op2) CPENC(3,(op1),4,(crm),(op2))
   3611  1.1  christos   /* for 3.9.10 System Instructions */
   3612  1.1  christos #define CPENS(op1,crn,crm,op2) CPENC(1,(op1),(crn),(crm),(op2))
   3613  1.1  christos 
   3614  1.1  christos #define C0  0
   3615  1.1  christos #define C1  1
   3616  1.1  christos #define C2  2
   3617  1.1  christos #define C3  3
   3618  1.1  christos #define C4  4
   3619  1.1  christos #define C5  5
   3620  1.1  christos #define C6  6
   3621  1.1  christos #define C7  7
   3622  1.1  christos #define C8  8
   3623  1.1  christos #define C9  9
   3624  1.1  christos #define C10 10
   3625  1.1  christos #define C11 11
   3626  1.1  christos #define C12 12
   3627  1.1  christos #define C13 13
   3628  1.1  christos #define C14 14
   3629  1.1  christos #define C15 15
   3630  1.1  christos 
   3631  1.1  christos #ifdef F_DEPRECATED
   3632  1.5  christos #undef F_DEPRECATED
   3633  1.5  christos #endif
   3634  1.5  christos #define F_DEPRECATED	0x1	/* Deprecated system register.  */
   3635  1.5  christos 
   3636  1.5  christos #ifdef F_ARCHEXT
   3637  1.6  christos #undef F_ARCHEXT
   3638  1.6  christos #endif
   3639  1.6  christos #define F_ARCHEXT	0x2	/* Architecture dependent system register.  */
   3640  1.6  christos 
   3641  1.6  christos #ifdef F_HASXT
   3642  1.6  christos #undef F_HASXT
   3643  1.5  christos #endif
   3644  1.1  christos #define F_HASXT		0x4	/* System instruction register <Xt>
   3645  1.1  christos 				   operand.  */
   3646  1.1  christos 
   3647  1.1  christos 
   3648  1.1  christos /* TODO there are two more issues need to be resolved
   3649  1.1  christos    1. handle read-only and write-only system registers
   3650  1.6  christos    2. handle cpu-implementation-defined system registers.  */
   3651  1.1  christos const aarch64_sys_reg aarch64_sys_regs [] =
   3652  1.6  christos {
   3653  1.1  christos   { "spsr_el1",         CPEN_(0,C0,0),	0 }, /* = spsr_svc */
   3654  1.1  christos   { "spsr_el12",	CPEN_ (5, C0, 0), F_ARCHEXT },
   3655  1.1  christos   { "elr_el1",          CPEN_(0,C0,1),	0 },
   3656  1.1  christos   { "elr_el12",	CPEN_ (5, C0, 1), F_ARCHEXT },
   3657  1.5  christos   { "sp_el0",           CPEN_(0,C1,0),	0 },
   3658  1.6  christos   { "spsel",            CPEN_(0,C2,0),	0 },
   3659  1.1  christos   { "daif",             CPEN_(3,C2,1),	0 },
   3660  1.1  christos   { "currentel",        CPEN_(0,C2,2),	0 }, /* RO */
   3661  1.1  christos   { "pan",		CPEN_(0,C2,3),	F_ARCHEXT },
   3662  1.1  christos   { "uao",		CPEN_ (0, C2, 4), F_ARCHEXT },
   3663  1.1  christos   { "nzcv",             CPEN_(3,C2,0),	0 },
   3664  1.1  christos   { "fpcr",             CPEN_(3,C4,0),	0 },
   3665  1.1  christos   { "fpsr",             CPEN_(3,C4,1),	0 },
   3666  1.1  christos   { "dspsr_el0",        CPEN_(3,C5,0),	0 },
   3667  1.1  christos   { "dlr_el0",          CPEN_(3,C5,1),	0 },
   3668  1.1  christos   { "spsr_el2",         CPEN_(4,C0,0),	0 }, /* = spsr_hyp */
   3669  1.1  christos   { "elr_el2",          CPEN_(4,C0,1),	0 },
   3670  1.1  christos   { "sp_el1",           CPEN_(4,C1,0),	0 },
   3671  1.1  christos   { "spsr_irq",         CPEN_(4,C3,0),	0 },
   3672  1.1  christos   { "spsr_abt",         CPEN_(4,C3,1),	0 },
   3673  1.1  christos   { "spsr_und",         CPEN_(4,C3,2),	0 },
   3674  1.1  christos   { "spsr_fiq",         CPEN_(4,C3,3),	0 },
   3675  1.1  christos   { "spsr_el3",         CPEN_(6,C0,0),	0 },
   3676  1.1  christos   { "elr_el3",          CPEN_(6,C0,1),	0 },
   3677  1.1  christos   { "sp_el2",           CPEN_(6,C1,0),	0 },
   3678  1.1  christos   { "spsr_svc",         CPEN_(0,C0,0),	F_DEPRECATED }, /* = spsr_el1 */
   3679  1.1  christos   { "spsr_hyp",         CPEN_(4,C0,0),	F_DEPRECATED }, /* = spsr_el2 */
   3680  1.1  christos   { "midr_el1",         CPENC(3,0,C0,C0,0),	0 }, /* RO */
   3681  1.1  christos   { "ctr_el0",          CPENC(3,3,C0,C0,1),	0 }, /* RO */
   3682  1.1  christos   { "mpidr_el1",        CPENC(3,0,C0,C0,5),	0 }, /* RO */
   3683  1.1  christos   { "revidr_el1",       CPENC(3,0,C0,C0,6),	0 }, /* RO */
   3684  1.1  christos   { "aidr_el1",         CPENC(3,1,C0,C0,7),	0 }, /* RO */
   3685  1.1  christos   { "dczid_el0",        CPENC(3,3,C0,C0,7),	0 }, /* RO */
   3686  1.1  christos   { "id_dfr0_el1",      CPENC(3,0,C0,C1,2),	0 }, /* RO */
   3687  1.1  christos   { "id_pfr0_el1",      CPENC(3,0,C0,C1,0),	0 }, /* RO */
   3688  1.1  christos   { "id_pfr1_el1",      CPENC(3,0,C0,C1,1),	0 }, /* RO */
   3689  1.1  christos   { "id_afr0_el1",      CPENC(3,0,C0,C1,3),	0 }, /* RO */
   3690  1.5  christos   { "id_mmfr0_el1",     CPENC(3,0,C0,C1,4),	0 }, /* RO */
   3691  1.1  christos   { "id_mmfr1_el1",     CPENC(3,0,C0,C1,5),	0 }, /* RO */
   3692  1.1  christos   { "id_mmfr2_el1",     CPENC(3,0,C0,C1,6),	0 }, /* RO */
   3693  1.1  christos   { "id_mmfr3_el1",     CPENC(3,0,C0,C1,7),	0 }, /* RO */
   3694  1.1  christos   { "id_mmfr4_el1",     CPENC(3,0,C0,C2,6),	0 }, /* RO */
   3695  1.1  christos   { "id_isar0_el1",     CPENC(3,0,C0,C2,0),	0 }, /* RO */
   3696  1.1  christos   { "id_isar1_el1",     CPENC(3,0,C0,C2,1),	0 }, /* RO */
   3697  1.1  christos   { "id_isar2_el1",     CPENC(3,0,C0,C2,2),	0 }, /* RO */
   3698  1.1  christos   { "id_isar3_el1",     CPENC(3,0,C0,C2,3),	0 }, /* RO */
   3699  1.1  christos   { "id_isar4_el1",     CPENC(3,0,C0,C2,4),	0 }, /* RO */
   3700  1.1  christos   { "id_isar5_el1",     CPENC(3,0,C0,C2,5),	0 }, /* RO */
   3701  1.1  christos   { "mvfr0_el1",        CPENC(3,0,C0,C3,0),	0 }, /* RO */
   3702  1.1  christos   { "mvfr1_el1",        CPENC(3,0,C0,C3,1),	0 }, /* RO */
   3703  1.1  christos   { "mvfr2_el1",        CPENC(3,0,C0,C3,2),	0 }, /* RO */
   3704  1.1  christos   { "ccsidr_el1",       CPENC(3,1,C0,C0,0),	0 }, /* RO */
   3705  1.1  christos   { "id_aa64pfr0_el1",  CPENC(3,0,C0,C4,0),	0 }, /* RO */
   3706  1.1  christos   { "id_aa64pfr1_el1",  CPENC(3,0,C0,C4,1),	0 }, /* RO */
   3707  1.1  christos   { "id_aa64dfr0_el1",  CPENC(3,0,C0,C5,0),	0 }, /* RO */
   3708  1.1  christos   { "id_aa64dfr1_el1",  CPENC(3,0,C0,C5,1),	0 }, /* RO */
   3709  1.6  christos   { "id_aa64isar0_el1", CPENC(3,0,C0,C6,0),	0 }, /* RO */
   3710  1.1  christos   { "id_aa64isar1_el1", CPENC(3,0,C0,C6,1),	0 }, /* RO */
   3711  1.1  christos   { "id_aa64mmfr0_el1", CPENC(3,0,C0,C7,0),	0 }, /* RO */
   3712  1.7  christos   { "id_aa64mmfr1_el1", CPENC(3,0,C0,C7,1),	0 }, /* RO */
   3713  1.1  christos   { "id_aa64mmfr2_el1", CPENC (3, 0, C0, C7, 2), F_ARCHEXT }, /* RO */
   3714  1.1  christos   { "id_aa64afr0_el1",  CPENC(3,0,C0,C5,4),	0 }, /* RO */
   3715  1.1  christos   { "id_aa64afr1_el1",  CPENC(3,0,C0,C5,5),	0 }, /* RO */
   3716  1.1  christos   { "id_aa64zfr0_el1",  CPENC (3, 0, C0, C4, 4), F_ARCHEXT }, /* RO */
   3717  1.1  christos   { "clidr_el1",        CPENC(3,1,C0,C0,1),	0 }, /* RO */
   3718  1.1  christos   { "csselr_el1",       CPENC(3,2,C0,C0,0),	0 }, /* RO */
   3719  1.1  christos   { "vpidr_el2",        CPENC(3,4,C0,C0,0),	0 },
   3720  1.6  christos   { "vmpidr_el2",       CPENC(3,4,C0,C0,5),	0 },
   3721  1.1  christos   { "sctlr_el1",        CPENC(3,0,C1,C0,0),	0 },
   3722  1.1  christos   { "sctlr_el2",        CPENC(3,4,C1,C0,0),	0 },
   3723  1.1  christos   { "sctlr_el3",        CPENC(3,6,C1,C0,0),	0 },
   3724  1.1  christos   { "sctlr_el12",	CPENC (3, 5, C1, C0, 0), F_ARCHEXT },
   3725  1.6  christos   { "actlr_el1",        CPENC(3,0,C1,C0,1),	0 },
   3726  1.1  christos   { "actlr_el2",        CPENC(3,4,C1,C0,1),	0 },
   3727  1.1  christos   { "actlr_el3",        CPENC(3,6,C1,C0,1),	0 },
   3728  1.1  christos   { "cpacr_el1",        CPENC(3,0,C1,C0,2),	0 },
   3729  1.1  christos   { "cpacr_el12",	CPENC (3, 5, C1, C0, 2), F_ARCHEXT },
   3730  1.1  christos   { "cptr_el2",         CPENC(3,4,C1,C1,2),	0 },
   3731  1.1  christos   { "cptr_el3",         CPENC(3,6,C1,C1,2),	0 },
   3732  1.1  christos   { "scr_el3",          CPENC(3,6,C1,C1,0),	0 },
   3733  1.1  christos   { "hcr_el2",          CPENC(3,4,C1,C1,0),	0 },
   3734  1.7  christos   { "mdcr_el2",         CPENC(3,4,C1,C1,1),	0 },
   3735  1.7  christos   { "mdcr_el3",         CPENC(3,6,C1,C3,1),	0 },
   3736  1.7  christos   { "hstr_el2",         CPENC(3,4,C1,C1,3),	0 },
   3737  1.7  christos   { "hacr_el2",         CPENC(3,4,C1,C1,7),	0 },
   3738  1.7  christos   { "zcr_el1",          CPENC (3, 0, C1, C2, 0), F_ARCHEXT },
   3739  1.1  christos   { "zcr_el12",         CPENC (3, 5, C1, C2, 0), F_ARCHEXT },
   3740  1.1  christos   { "zcr_el2",          CPENC (3, 4, C1, C2, 0), F_ARCHEXT },
   3741  1.1  christos   { "zcr_el3",          CPENC (3, 6, C1, C2, 0), F_ARCHEXT },
   3742  1.6  christos   { "zidr_el1",         CPENC (3, 0, C0, C0, 7), F_ARCHEXT },
   3743  1.1  christos   { "ttbr0_el1",        CPENC(3,0,C2,C0,0),	0 },
   3744  1.6  christos   { "ttbr1_el1",        CPENC(3,0,C2,C0,1),	0 },
   3745  1.6  christos   { "ttbr0_el2",        CPENC(3,4,C2,C0,0),	0 },
   3746  1.1  christos   { "ttbr1_el2",	CPENC (3, 4, C2, C0, 1), F_ARCHEXT },
   3747  1.1  christos   { "ttbr0_el3",        CPENC(3,6,C2,C0,0),	0 },
   3748  1.1  christos   { "ttbr0_el12",	CPENC (3, 5, C2, C0, 0), F_ARCHEXT },
   3749  1.1  christos   { "ttbr1_el12",	CPENC (3, 5, C2, C0, 1), F_ARCHEXT },
   3750  1.6  christos   { "vttbr_el2",        CPENC(3,4,C2,C1,0),	0 },
   3751  1.1  christos   { "tcr_el1",          CPENC(3,0,C2,C0,2),	0 },
   3752  1.7  christos   { "tcr_el2",          CPENC(3,4,C2,C0,2),	0 },
   3753  1.7  christos   { "tcr_el3",          CPENC(3,6,C2,C0,2),	0 },
   3754  1.7  christos   { "tcr_el12",		CPENC (3, 5, C2, C0, 2), F_ARCHEXT },
   3755  1.7  christos   { "vtcr_el2",         CPENC(3,4,C2,C1,2),	0 },
   3756  1.7  christos   { "apiakeylo_el1",	CPENC (3, 0, C2, C1, 0), F_ARCHEXT },
   3757  1.7  christos   { "apiakeyhi_el1",	CPENC (3, 0, C2, C1, 1), F_ARCHEXT },
   3758  1.7  christos   { "apibkeylo_el1",	CPENC (3, 0, C2, C1, 2), F_ARCHEXT },
   3759  1.7  christos   { "apibkeyhi_el1",	CPENC (3, 0, C2, C1, 3), F_ARCHEXT },
   3760  1.7  christos   { "apdakeylo_el1",	CPENC (3, 0, C2, C2, 0), F_ARCHEXT },
   3761  1.7  christos   { "apdakeyhi_el1",	CPENC (3, 0, C2, C2, 1), F_ARCHEXT },
   3762  1.1  christos   { "apdbkeylo_el1",	CPENC (3, 0, C2, C2, 2), F_ARCHEXT },
   3763  1.1  christos   { "apdbkeyhi_el1",	CPENC (3, 0, C2, C2, 3), F_ARCHEXT },
   3764  1.1  christos   { "apgakeylo_el1",	CPENC (3, 0, C2, C3, 0), F_ARCHEXT },
   3765  1.1  christos   { "apgakeyhi_el1",	CPENC (3, 0, C2, C3, 1), F_ARCHEXT },
   3766  1.1  christos   { "afsr0_el1",        CPENC(3,0,C5,C1,0),	0 },
   3767  1.6  christos   { "afsr1_el1",        CPENC(3,0,C5,C1,1),	0 },
   3768  1.1  christos   { "afsr0_el2",        CPENC(3,4,C5,C1,0),	0 },
   3769  1.6  christos   { "afsr1_el2",        CPENC(3,4,C5,C1,1),	0 },
   3770  1.1  christos   { "afsr0_el3",        CPENC(3,6,C5,C1,0),	0 },
   3771  1.1  christos   { "afsr0_el12",	CPENC (3, 5, C5, C1, 0), F_ARCHEXT },
   3772  1.1  christos   { "afsr1_el3",        CPENC(3,6,C5,C1,1),	0 },
   3773  1.6  christos   { "afsr1_el12",	CPENC (3, 5, C5, C1, 1), F_ARCHEXT },
   3774  1.6  christos   { "esr_el1",          CPENC(3,0,C5,C2,0),	0 },
   3775  1.1  christos   { "esr_el2",          CPENC(3,4,C5,C2,0),	0 },
   3776  1.6  christos   { "esr_el3",          CPENC(3,6,C5,C2,0),	0 },
   3777  1.6  christos   { "esr_el12",		CPENC (3, 5, C5, C2, 0), F_ARCHEXT },
   3778  1.6  christos   { "vsesr_el2",	CPENC (3, 4, C5, C2, 3), F_ARCHEXT }, /* RO */
   3779  1.6  christos   { "fpexc32_el2",      CPENC(3,4,C5,C3,0),	0 },
   3780  1.6  christos   { "erridr_el1",	CPENC (3, 0, C5, C3, 0), F_ARCHEXT }, /* RO */
   3781  1.6  christos   { "errselr_el1",	CPENC (3, 0, C5, C3, 1), F_ARCHEXT },
   3782  1.6  christos   { "erxfr_el1",	CPENC (3, 0, C5, C4, 0), F_ARCHEXT }, /* RO */
   3783  1.6  christos   { "erxctlr_el1",	CPENC (3, 0, C5, C4, 1), F_ARCHEXT },
   3784  1.1  christos   { "erxstatus_el1",	CPENC (3, 0, C5, C4, 2), F_ARCHEXT },
   3785  1.1  christos   { "erxaddr_el1",	CPENC (3, 0, C5, C4, 3), F_ARCHEXT },
   3786  1.1  christos   { "erxmisc0_el1",	CPENC (3, 0, C5, C5, 0), F_ARCHEXT },
   3787  1.6  christos   { "erxmisc1_el1",	CPENC (3, 0, C5, C5, 1), F_ARCHEXT },
   3788  1.1  christos   { "far_el1",          CPENC(3,0,C6,C0,0),	0 },
   3789  1.1  christos   { "far_el2",          CPENC(3,4,C6,C0,0),	0 },
   3790  1.1  christos   { "far_el3",          CPENC(3,6,C6,C0,0),	0 },
   3791  1.1  christos   { "far_el12",		CPENC (3, 5, C6, C0, 0), F_ARCHEXT },
   3792  1.1  christos   { "hpfar_el2",        CPENC(3,4,C6,C0,4),	0 },
   3793  1.6  christos   { "par_el1",          CPENC(3,0,C7,C4,0),	0 },
   3794  1.1  christos   { "mair_el1",         CPENC(3,0,C10,C2,0),	0 },
   3795  1.1  christos   { "mair_el2",         CPENC(3,4,C10,C2,0),	0 },
   3796  1.1  christos   { "mair_el3",         CPENC(3,6,C10,C2,0),	0 },
   3797  1.6  christos   { "mair_el12",	CPENC (3, 5, C10, C2, 0), F_ARCHEXT },
   3798  1.1  christos   { "amair_el1",        CPENC(3,0,C10,C3,0),	0 },
   3799  1.1  christos   { "amair_el2",        CPENC(3,4,C10,C3,0),	0 },
   3800  1.1  christos   { "amair_el3",        CPENC(3,6,C10,C3,0),	0 },
   3801  1.6  christos   { "amair_el12",	CPENC (3, 5, C10, C3, 0), F_ARCHEXT },
   3802  1.1  christos   { "vbar_el1",         CPENC(3,0,C12,C0,0),	0 },
   3803  1.1  christos   { "vbar_el2",         CPENC(3,4,C12,C0,0),	0 },
   3804  1.1  christos   { "vbar_el3",         CPENC(3,6,C12,C0,0),	0 },
   3805  1.1  christos   { "vbar_el12",	CPENC (3, 5, C12, C0, 0), F_ARCHEXT },
   3806  1.1  christos   { "rvbar_el1",        CPENC(3,0,C12,C0,1),	0 }, /* RO */
   3807  1.1  christos   { "rvbar_el2",        CPENC(3,4,C12,C0,1),	0 }, /* RO */
   3808  1.1  christos   { "rvbar_el3",        CPENC(3,6,C12,C0,1),	0 }, /* RO */
   3809  1.6  christos   { "rmr_el1",          CPENC(3,0,C12,C0,2),	0 },
   3810  1.6  christos   { "rmr_el2",          CPENC(3,4,C12,C0,2),	0 },
   3811  1.1  christos   { "rmr_el3",          CPENC(3,6,C12,C0,2),	0 },
   3812  1.6  christos   { "isr_el1",          CPENC(3,0,C12,C1,0),	0 }, /* RO */
   3813  1.6  christos   { "disr_el1",		CPENC (3, 0, C12, C1, 1), F_ARCHEXT },
   3814  1.1  christos   { "vdisr_el2",	CPENC (3, 4, C12, C1, 1), F_ARCHEXT },
   3815  1.1  christos   { "contextidr_el1",   CPENC(3,0,C13,C0,1),	0 },
   3816  1.1  christos   { "contextidr_el2",	CPENC (3, 4, C13, C0, 1), F_ARCHEXT },
   3817  1.1  christos   { "contextidr_el12",	CPENC (3, 5, C13, C0, 1), F_ARCHEXT },
   3818  1.1  christos   { "tpidr_el0",        CPENC(3,3,C13,C0,2),	0 },
   3819  1.1  christos   { "tpidrro_el0",      CPENC(3,3,C13,C0,3),	0 }, /* RO */
   3820  1.1  christos   { "tpidr_el1",        CPENC(3,0,C13,C0,4),	0 },
   3821  1.1  christos   { "tpidr_el2",        CPENC(3,4,C13,C0,2),	0 },
   3822  1.1  christos   { "tpidr_el3",        CPENC(3,6,C13,C0,2),	0 },
   3823  1.1  christos   { "teecr32_el1",      CPENC(2,2,C0, C0,0),	0 }, /* See section 3.9.7.1 */
   3824  1.1  christos   { "cntfrq_el0",       CPENC(3,3,C14,C0,0),	0 }, /* RO */
   3825  1.6  christos   { "cntpct_el0",       CPENC(3,3,C14,C0,1),	0 }, /* RO */
   3826  1.1  christos   { "cntvct_el0",       CPENC(3,3,C14,C0,2),	0 }, /* RO */
   3827  1.1  christos   { "cntvoff_el2",      CPENC(3,4,C14,C0,3),	0 },
   3828  1.6  christos   { "cntkctl_el1",      CPENC(3,0,C14,C1,0),	0 },
   3829  1.1  christos   { "cntkctl_el12",	CPENC (3, 5, C14, C1, 0), F_ARCHEXT },
   3830  1.6  christos   { "cnthctl_el2",      CPENC(3,4,C14,C1,0),	0 },
   3831  1.1  christos   { "cntp_tval_el0",    CPENC(3,3,C14,C2,0),	0 },
   3832  1.6  christos   { "cntp_tval_el02",	CPENC (3, 5, C14, C2, 0), F_ARCHEXT },
   3833  1.1  christos   { "cntp_ctl_el0",     CPENC(3,3,C14,C2,1),	0 },
   3834  1.6  christos   { "cntp_ctl_el02",	CPENC (3, 5, C14, C2, 1), F_ARCHEXT },
   3835  1.1  christos   { "cntp_cval_el0",    CPENC(3,3,C14,C2,2),	0 },
   3836  1.6  christos   { "cntp_cval_el02",	CPENC (3, 5, C14, C2, 2), F_ARCHEXT },
   3837  1.1  christos   { "cntv_tval_el0",    CPENC(3,3,C14,C3,0),	0 },
   3838  1.6  christos   { "cntv_tval_el02",	CPENC (3, 5, C14, C3, 0), F_ARCHEXT },
   3839  1.1  christos   { "cntv_ctl_el0",     CPENC(3,3,C14,C3,1),	0 },
   3840  1.1  christos   { "cntv_ctl_el02",	CPENC (3, 5, C14, C3, 1), F_ARCHEXT },
   3841  1.1  christos   { "cntv_cval_el0",    CPENC(3,3,C14,C3,2),	0 },
   3842  1.1  christos   { "cntv_cval_el02",	CPENC (3, 5, C14, C3, 2), F_ARCHEXT },
   3843  1.1  christos   { "cnthp_tval_el2",   CPENC(3,4,C14,C2,0),	0 },
   3844  1.1  christos   { "cnthp_ctl_el2",    CPENC(3,4,C14,C2,1),	0 },
   3845  1.6  christos   { "cnthp_cval_el2",   CPENC(3,4,C14,C2,2),	0 },
   3846  1.6  christos   { "cntps_tval_el1",   CPENC(3,7,C14,C2,0),	0 },
   3847  1.6  christos   { "cntps_ctl_el1",    CPENC(3,7,C14,C2,1),	0 },
   3848  1.1  christos   { "cntps_cval_el1",   CPENC(3,7,C14,C2,2),	0 },
   3849  1.1  christos   { "cnthv_tval_el2",	CPENC (3, 4, C14, C3, 0), F_ARCHEXT },
   3850  1.1  christos   { "cnthv_ctl_el2",	CPENC (3, 4, C14, C3, 1), F_ARCHEXT },
   3851  1.1  christos   { "cnthv_cval_el2",	CPENC (3, 4, C14, C3, 2), F_ARCHEXT },
   3852  1.1  christos   { "dacr32_el2",       CPENC(3,4,C3,C0,0),	0 },
   3853  1.1  christos   { "ifsr32_el2",       CPENC(3,4,C5,C0,1),	0 },
   3854  1.1  christos   { "teehbr32_el1",     CPENC(2,2,C1,C0,0),	0 },
   3855  1.1  christos   { "sder32_el3",       CPENC(3,6,C1,C1,1),	0 },
   3856  1.1  christos   { "mdscr_el1",         CPENC(2,0,C0, C2, 2),	0 },
   3857  1.1  christos   { "mdccsr_el0",        CPENC(2,3,C0, C1, 0),	0 },  /* r */
   3858  1.1  christos   { "mdccint_el1",       CPENC(2,0,C0, C2, 0),	0 },
   3859  1.1  christos   { "dbgdtr_el0",        CPENC(2,3,C0, C4, 0),	0 },
   3860  1.1  christos   { "dbgdtrrx_el0",      CPENC(2,3,C0, C5, 0),	0 },  /* r */
   3861  1.1  christos   { "dbgdtrtx_el0",      CPENC(2,3,C0, C5, 0),	0 },  /* w */
   3862  1.1  christos   { "osdtrrx_el1",       CPENC(2,0,C0, C0, 2),	0 },  /* r */
   3863  1.1  christos   { "osdtrtx_el1",       CPENC(2,0,C0, C3, 2),	0 },  /* w */
   3864  1.1  christos   { "oseccr_el1",        CPENC(2,0,C0, C6, 2),	0 },
   3865  1.1  christos   { "dbgvcr32_el2",      CPENC(2,4,C0, C7, 0),	0 },
   3866  1.1  christos   { "dbgbvr0_el1",       CPENC(2,0,C0, C0, 4),	0 },
   3867  1.1  christos   { "dbgbvr1_el1",       CPENC(2,0,C0, C1, 4),	0 },
   3868  1.1  christos   { "dbgbvr2_el1",       CPENC(2,0,C0, C2, 4),	0 },
   3869  1.1  christos   { "dbgbvr3_el1",       CPENC(2,0,C0, C3, 4),	0 },
   3870  1.1  christos   { "dbgbvr4_el1",       CPENC(2,0,C0, C4, 4),	0 },
   3871  1.1  christos   { "dbgbvr5_el1",       CPENC(2,0,C0, C5, 4),	0 },
   3872  1.1  christos   { "dbgbvr6_el1",       CPENC(2,0,C0, C6, 4),	0 },
   3873  1.1  christos   { "dbgbvr7_el1",       CPENC(2,0,C0, C7, 4),	0 },
   3874  1.1  christos   { "dbgbvr8_el1",       CPENC(2,0,C0, C8, 4),	0 },
   3875  1.1  christos   { "dbgbvr9_el1",       CPENC(2,0,C0, C9, 4),	0 },
   3876  1.1  christos   { "dbgbvr10_el1",      CPENC(2,0,C0, C10,4),	0 },
   3877  1.1  christos   { "dbgbvr11_el1",      CPENC(2,0,C0, C11,4),	0 },
   3878  1.1  christos   { "dbgbvr12_el1",      CPENC(2,0,C0, C12,4),	0 },
   3879  1.1  christos   { "dbgbvr13_el1",      CPENC(2,0,C0, C13,4),	0 },
   3880  1.1  christos   { "dbgbvr14_el1",      CPENC(2,0,C0, C14,4),	0 },
   3881  1.1  christos   { "dbgbvr15_el1",      CPENC(2,0,C0, C15,4),	0 },
   3882  1.1  christos   { "dbgbcr0_el1",       CPENC(2,0,C0, C0, 5),	0 },
   3883  1.1  christos   { "dbgbcr1_el1",       CPENC(2,0,C0, C1, 5),	0 },
   3884  1.1  christos   { "dbgbcr2_el1",       CPENC(2,0,C0, C2, 5),	0 },
   3885  1.1  christos   { "dbgbcr3_el1",       CPENC(2,0,C0, C3, 5),	0 },
   3886  1.1  christos   { "dbgbcr4_el1",       CPENC(2,0,C0, C4, 5),	0 },
   3887  1.1  christos   { "dbgbcr5_el1",       CPENC(2,0,C0, C5, 5),	0 },
   3888  1.1  christos   { "dbgbcr6_el1",       CPENC(2,0,C0, C6, 5),	0 },
   3889  1.1  christos   { "dbgbcr7_el1",       CPENC(2,0,C0, C7, 5),	0 },
   3890  1.1  christos   { "dbgbcr8_el1",       CPENC(2,0,C0, C8, 5),	0 },
   3891  1.1  christos   { "dbgbcr9_el1",       CPENC(2,0,C0, C9, 5),	0 },
   3892  1.1  christos   { "dbgbcr10_el1",      CPENC(2,0,C0, C10,5),	0 },
   3893  1.1  christos   { "dbgbcr11_el1",      CPENC(2,0,C0, C11,5),	0 },
   3894  1.1  christos   { "dbgbcr12_el1",      CPENC(2,0,C0, C12,5),	0 },
   3895  1.1  christos   { "dbgbcr13_el1",      CPENC(2,0,C0, C13,5),	0 },
   3896  1.1  christos   { "dbgbcr14_el1",      CPENC(2,0,C0, C14,5),	0 },
   3897  1.1  christos   { "dbgbcr15_el1",      CPENC(2,0,C0, C15,5),	0 },
   3898  1.1  christos   { "dbgwvr0_el1",       CPENC(2,0,C0, C0, 6),	0 },
   3899  1.1  christos   { "dbgwvr1_el1",       CPENC(2,0,C0, C1, 6),	0 },
   3900  1.1  christos   { "dbgwvr2_el1",       CPENC(2,0,C0, C2, 6),	0 },
   3901  1.1  christos   { "dbgwvr3_el1",       CPENC(2,0,C0, C3, 6),	0 },
   3902  1.1  christos   { "dbgwvr4_el1",       CPENC(2,0,C0, C4, 6),	0 },
   3903  1.1  christos   { "dbgwvr5_el1",       CPENC(2,0,C0, C5, 6),	0 },
   3904  1.1  christos   { "dbgwvr6_el1",       CPENC(2,0,C0, C6, 6),	0 },
   3905  1.1  christos   { "dbgwvr7_el1",       CPENC(2,0,C0, C7, 6),	0 },
   3906  1.1  christos   { "dbgwvr8_el1",       CPENC(2,0,C0, C8, 6),	0 },
   3907  1.1  christos   { "dbgwvr9_el1",       CPENC(2,0,C0, C9, 6),	0 },
   3908  1.1  christos   { "dbgwvr10_el1",      CPENC(2,0,C0, C10,6),	0 },
   3909  1.1  christos   { "dbgwvr11_el1",      CPENC(2,0,C0, C11,6),	0 },
   3910  1.1  christos   { "dbgwvr12_el1",      CPENC(2,0,C0, C12,6),	0 },
   3911  1.1  christos   { "dbgwvr13_el1",      CPENC(2,0,C0, C13,6),	0 },
   3912  1.1  christos   { "dbgwvr14_el1",      CPENC(2,0,C0, C14,6),	0 },
   3913  1.1  christos   { "dbgwvr15_el1",      CPENC(2,0,C0, C15,6),	0 },
   3914  1.1  christos   { "dbgwcr0_el1",       CPENC(2,0,C0, C0, 7),	0 },
   3915  1.1  christos   { "dbgwcr1_el1",       CPENC(2,0,C0, C1, 7),	0 },
   3916  1.1  christos   { "dbgwcr2_el1",       CPENC(2,0,C0, C2, 7),	0 },
   3917  1.1  christos   { "dbgwcr3_el1",       CPENC(2,0,C0, C3, 7),	0 },
   3918  1.1  christos   { "dbgwcr4_el1",       CPENC(2,0,C0, C4, 7),	0 },
   3919  1.1  christos   { "dbgwcr5_el1",       CPENC(2,0,C0, C5, 7),	0 },
   3920  1.1  christos   { "dbgwcr6_el1",       CPENC(2,0,C0, C6, 7),	0 },
   3921  1.1  christos   { "dbgwcr7_el1",       CPENC(2,0,C0, C7, 7),	0 },
   3922  1.1  christos   { "dbgwcr8_el1",       CPENC(2,0,C0, C8, 7),	0 },
   3923  1.1  christos   { "dbgwcr9_el1",       CPENC(2,0,C0, C9, 7),	0 },
   3924  1.1  christos   { "dbgwcr10_el1",      CPENC(2,0,C0, C10,7),	0 },
   3925  1.1  christos   { "dbgwcr11_el1",      CPENC(2,0,C0, C11,7),	0 },
   3926  1.1  christos   { "dbgwcr12_el1",      CPENC(2,0,C0, C12,7),	0 },
   3927  1.1  christos   { "dbgwcr13_el1",      CPENC(2,0,C0, C13,7),	0 },
   3928  1.1  christos   { "dbgwcr14_el1",      CPENC(2,0,C0, C14,7),	0 },
   3929  1.1  christos   { "dbgwcr15_el1",      CPENC(2,0,C0, C15,7),	0 },
   3930  1.1  christos   { "mdrar_el1",         CPENC(2,0,C1, C0, 0),	0 },  /* r */
   3931  1.1  christos   { "oslar_el1",         CPENC(2,0,C1, C0, 4),	0 },  /* w */
   3932  1.1  christos   { "oslsr_el1",         CPENC(2,0,C1, C1, 4),	0 },  /* r */
   3933  1.1  christos   { "osdlr_el1",         CPENC(2,0,C1, C3, 4),	0 },
   3934  1.6  christos   { "dbgprcr_el1",       CPENC(2,0,C1, C4, 4),	0 },
   3935  1.6  christos   { "dbgclaimset_el1",   CPENC(2,0,C7, C8, 6),	0 },
   3936  1.6  christos   { "dbgclaimclr_el1",   CPENC(2,0,C7, C9, 6),	0 },
   3937  1.6  christos   { "dbgauthstatus_el1", CPENC(2,0,C7, C14,6),	0 },  /* r */
   3938  1.6  christos   { "pmblimitr_el1",	 CPENC (3, 0, C9, C10, 0), F_ARCHEXT },  /* rw */
   3939  1.6  christos   { "pmbptr_el1",	 CPENC (3, 0, C9, C10, 1), F_ARCHEXT },  /* rw */
   3940  1.6  christos   { "pmbsr_el1",	 CPENC (3, 0, C9, C10, 3), F_ARCHEXT },  /* rw */
   3941  1.6  christos   { "pmbidr_el1",	 CPENC (3, 0, C9, C10, 7), F_ARCHEXT },  /* ro */
   3942  1.6  christos   { "pmscr_el1",	 CPENC (3, 0, C9, C9, 0),  F_ARCHEXT },  /* rw */
   3943  1.6  christos   { "pmsicr_el1",	 CPENC (3, 0, C9, C9, 2),  F_ARCHEXT },  /* rw */
   3944  1.6  christos   { "pmsirr_el1",	 CPENC (3, 0, C9, C9, 3),  F_ARCHEXT },  /* rw */
   3945  1.6  christos   { "pmsfcr_el1",	 CPENC (3, 0, C9, C9, 4),  F_ARCHEXT },  /* rw */
   3946  1.6  christos   { "pmsevfr_el1",	 CPENC (3, 0, C9, C9, 5),  F_ARCHEXT },  /* rw */
   3947  1.1  christos   { "pmslatfr_el1",	 CPENC (3, 0, C9, C9, 6),  F_ARCHEXT },  /* rw */
   3948  1.1  christos   { "pmsidr_el1",	 CPENC (3, 0, C9, C9, 7),  F_ARCHEXT },  /* ro */
   3949  1.1  christos   { "pmscr_el2",	 CPENC (3, 4, C9, C9, 0),  F_ARCHEXT },  /* rw */
   3950  1.1  christos   { "pmscr_el12",	 CPENC (3, 5, C9, C9, 0),  F_ARCHEXT },  /* rw */
   3951  1.1  christos   { "pmcr_el0",          CPENC(3,3,C9,C12, 0),	0 },
   3952  1.1  christos   { "pmcntenset_el0",    CPENC(3,3,C9,C12, 1),	0 },
   3953  1.1  christos   { "pmcntenclr_el0",    CPENC(3,3,C9,C12, 2),	0 },
   3954  1.1  christos   { "pmovsclr_el0",      CPENC(3,3,C9,C12, 3),	0 },
   3955  1.1  christos   { "pmswinc_el0",       CPENC(3,3,C9,C12, 4),	0 },  /* w */
   3956  1.1  christos   { "pmselr_el0",        CPENC(3,3,C9,C12, 5),	0 },
   3957  1.1  christos   { "pmceid0_el0",       CPENC(3,3,C9,C12, 6),	0 },  /* r */
   3958  1.1  christos   { "pmceid1_el0",       CPENC(3,3,C9,C12, 7),	0 },  /* r */
   3959  1.1  christos   { "pmccntr_el0",       CPENC(3,3,C9,C13, 0),	0 },
   3960  1.1  christos   { "pmxevtyper_el0",    CPENC(3,3,C9,C13, 1),	0 },
   3961  1.1  christos   { "pmxevcntr_el0",     CPENC(3,3,C9,C13, 2),	0 },
   3962  1.1  christos   { "pmuserenr_el0",     CPENC(3,3,C9,C14, 0),	0 },
   3963  1.1  christos   { "pmintenset_el1",    CPENC(3,0,C9,C14, 1),	0 },
   3964  1.1  christos   { "pmintenclr_el1",    CPENC(3,0,C9,C14, 2),	0 },
   3965  1.1  christos   { "pmovsset_el0",      CPENC(3,3,C9,C14, 3),	0 },
   3966  1.1  christos   { "pmevcntr0_el0",     CPENC(3,3,C14,C8, 0),	0 },
   3967  1.1  christos   { "pmevcntr1_el0",     CPENC(3,3,C14,C8, 1),	0 },
   3968  1.1  christos   { "pmevcntr2_el0",     CPENC(3,3,C14,C8, 2),	0 },
   3969  1.1  christos   { "pmevcntr3_el0",     CPENC(3,3,C14,C8, 3),	0 },
   3970  1.1  christos   { "pmevcntr4_el0",     CPENC(3,3,C14,C8, 4),	0 },
   3971  1.1  christos   { "pmevcntr5_el0",     CPENC(3,3,C14,C8, 5),	0 },
   3972  1.1  christos   { "pmevcntr6_el0",     CPENC(3,3,C14,C8, 6),	0 },
   3973  1.1  christos   { "pmevcntr7_el0",     CPENC(3,3,C14,C8, 7),	0 },
   3974  1.1  christos   { "pmevcntr8_el0",     CPENC(3,3,C14,C9, 0),	0 },
   3975  1.1  christos   { "pmevcntr9_el0",     CPENC(3,3,C14,C9, 1),	0 },
   3976  1.1  christos   { "pmevcntr10_el0",    CPENC(3,3,C14,C9, 2),	0 },
   3977  1.1  christos   { "pmevcntr11_el0",    CPENC(3,3,C14,C9, 3),	0 },
   3978  1.1  christos   { "pmevcntr12_el0",    CPENC(3,3,C14,C9, 4),	0 },
   3979  1.1  christos   { "pmevcntr13_el0",    CPENC(3,3,C14,C9, 5),	0 },
   3980  1.1  christos   { "pmevcntr14_el0",    CPENC(3,3,C14,C9, 6),	0 },
   3981  1.1  christos   { "pmevcntr15_el0",    CPENC(3,3,C14,C9, 7),	0 },
   3982  1.1  christos   { "pmevcntr16_el0",    CPENC(3,3,C14,C10,0),	0 },
   3983  1.1  christos   { "pmevcntr17_el0",    CPENC(3,3,C14,C10,1),	0 },
   3984  1.1  christos   { "pmevcntr18_el0",    CPENC(3,3,C14,C10,2),	0 },
   3985  1.1  christos   { "pmevcntr19_el0",    CPENC(3,3,C14,C10,3),	0 },
   3986  1.1  christos   { "pmevcntr20_el0",    CPENC(3,3,C14,C10,4),	0 },
   3987  1.1  christos   { "pmevcntr21_el0",    CPENC(3,3,C14,C10,5),	0 },
   3988  1.1  christos   { "pmevcntr22_el0",    CPENC(3,3,C14,C10,6),	0 },
   3989  1.1  christos   { "pmevcntr23_el0",    CPENC(3,3,C14,C10,7),	0 },
   3990  1.1  christos   { "pmevcntr24_el0",    CPENC(3,3,C14,C11,0),	0 },
   3991  1.1  christos   { "pmevcntr25_el0",    CPENC(3,3,C14,C11,1),	0 },
   3992  1.1  christos   { "pmevcntr26_el0",    CPENC(3,3,C14,C11,2),	0 },
   3993  1.1  christos   { "pmevcntr27_el0",    CPENC(3,3,C14,C11,3),	0 },
   3994  1.1  christos   { "pmevcntr28_el0",    CPENC(3,3,C14,C11,4),	0 },
   3995  1.1  christos   { "pmevcntr29_el0",    CPENC(3,3,C14,C11,5),	0 },
   3996  1.1  christos   { "pmevcntr30_el0",    CPENC(3,3,C14,C11,6),	0 },
   3997  1.1  christos   { "pmevtyper0_el0",    CPENC(3,3,C14,C12,0),	0 },
   3998  1.1  christos   { "pmevtyper1_el0",    CPENC(3,3,C14,C12,1),	0 },
   3999  1.1  christos   { "pmevtyper2_el0",    CPENC(3,3,C14,C12,2),	0 },
   4000  1.1  christos   { "pmevtyper3_el0",    CPENC(3,3,C14,C12,3),	0 },
   4001  1.1  christos   { "pmevtyper4_el0",    CPENC(3,3,C14,C12,4),	0 },
   4002  1.1  christos   { "pmevtyper5_el0",    CPENC(3,3,C14,C12,5),	0 },
   4003  1.1  christos   { "pmevtyper6_el0",    CPENC(3,3,C14,C12,6),	0 },
   4004  1.1  christos   { "pmevtyper7_el0",    CPENC(3,3,C14,C12,7),	0 },
   4005  1.1  christos   { "pmevtyper8_el0",    CPENC(3,3,C14,C13,0),	0 },
   4006  1.1  christos   { "pmevtyper9_el0",    CPENC(3,3,C14,C13,1),	0 },
   4007  1.1  christos   { "pmevtyper10_el0",   CPENC(3,3,C14,C13,2),	0 },
   4008  1.1  christos   { "pmevtyper11_el0",   CPENC(3,3,C14,C13,3),	0 },
   4009  1.1  christos   { "pmevtyper12_el0",   CPENC(3,3,C14,C13,4),	0 },
   4010  1.1  christos   { "pmevtyper13_el0",   CPENC(3,3,C14,C13,5),	0 },
   4011  1.1  christos   { "pmevtyper14_el0",   CPENC(3,3,C14,C13,6),	0 },
   4012  1.1  christos   { "pmevtyper15_el0",   CPENC(3,3,C14,C13,7),	0 },
   4013  1.1  christos   { "pmevtyper16_el0",   CPENC(3,3,C14,C14,0),	0 },
   4014  1.1  christos   { "pmevtyper17_el0",   CPENC(3,3,C14,C14,1),	0 },
   4015  1.1  christos   { "pmevtyper18_el0",   CPENC(3,3,C14,C14,2),	0 },
   4016  1.1  christos   { "pmevtyper19_el0",   CPENC(3,3,C14,C14,3),	0 },
   4017  1.1  christos   { "pmevtyper20_el0",   CPENC(3,3,C14,C14,4),	0 },
   4018  1.1  christos   { "pmevtyper21_el0",   CPENC(3,3,C14,C14,5),	0 },
   4019  1.1  christos   { "pmevtyper22_el0",   CPENC(3,3,C14,C14,6),	0 },
   4020  1.1  christos   { "pmevtyper23_el0",   CPENC(3,3,C14,C14,7),	0 },
   4021  1.1  christos   { "pmevtyper24_el0",   CPENC(3,3,C14,C15,0),	0 },
   4022  1.1  christos   { "pmevtyper25_el0",   CPENC(3,3,C14,C15,1),	0 },
   4023  1.1  christos   { "pmevtyper26_el0",   CPENC(3,3,C14,C15,2),	0 },
   4024  1.1  christos   { "pmevtyper27_el0",   CPENC(3,3,C14,C15,3),	0 },
   4025  1.1  christos   { "pmevtyper28_el0",   CPENC(3,3,C14,C15,4),	0 },
   4026  1.1  christos   { "pmevtyper29_el0",   CPENC(3,3,C14,C15,5),	0 },
   4027  1.1  christos   { "pmevtyper30_el0",   CPENC(3,3,C14,C15,6),	0 },
   4028  1.1  christos   { "pmccfiltr_el0",     CPENC(3,3,C14,C15,7),	0 },
   4029  1.1  christos   { 0,          CPENC(0,0,0,0,0),	0 },
   4030  1.1  christos };
   4031  1.1  christos 
   4032  1.1  christos bfd_boolean
   4033  1.1  christos aarch64_sys_reg_deprecated_p (const aarch64_sys_reg *reg)
   4034  1.5  christos {
   4035  1.5  christos   return (reg->flags & F_DEPRECATED) != 0;
   4036  1.5  christos }
   4037  1.5  christos 
   4038  1.5  christos bfd_boolean
   4039  1.5  christos aarch64_sys_reg_supported_p (const aarch64_feature_set features,
   4040  1.5  christos 			     const aarch64_sys_reg *reg)
   4041  1.5  christos {
   4042  1.5  christos   if (!(reg->flags & F_ARCHEXT))
   4043  1.5  christos     return TRUE;
   4044  1.5  christos 
   4045  1.5  christos   /* PAN.  Values are from aarch64_sys_regs.  */
   4046  1.6  christos   if (reg->value == CPEN_(0,C2,3)
   4047  1.6  christos       && !AARCH64_CPU_HAS_FEATURE (features, AARCH64_FEATURE_PAN))
   4048  1.6  christos     return FALSE;
   4049  1.6  christos 
   4050  1.6  christos   /* Virtualization host extensions: system registers.  */
   4051  1.6  christos   if ((reg->value == CPENC (3, 4, C2, C0, 1)
   4052  1.6  christos        || reg->value == CPENC (3, 4, C13, C0, 1)
   4053  1.6  christos        || reg->value == CPENC (3, 4, C14, C3, 0)
   4054  1.6  christos        || reg->value == CPENC (3, 4, C14, C3, 1)
   4055  1.6  christos        || reg->value == CPENC (3, 4, C14, C3, 2))
   4056  1.6  christos       && !AARCH64_CPU_HAS_FEATURE (features, AARCH64_FEATURE_V8_1))
   4057  1.6  christos       return FALSE;
   4058  1.6  christos 
   4059  1.6  christos   /* Virtualization host extensions: *_el12 names of *_el1 registers.  */
   4060  1.6  christos   if ((reg->value == CPEN_ (5, C0, 0)
   4061  1.6  christos        || reg->value == CPEN_ (5, C0, 1)
   4062  1.6  christos        || reg->value == CPENC (3, 5, C1, C0, 0)
   4063  1.6  christos        || reg->value == CPENC (3, 5, C1, C0, 2)
   4064  1.6  christos        || reg->value == CPENC (3, 5, C2, C0, 0)
   4065  1.6  christos        || reg->value == CPENC (3, 5, C2, C0, 1)
   4066  1.6  christos        || reg->value == CPENC (3, 5, C2, C0, 2)
   4067  1.6  christos        || reg->value == CPENC (3, 5, C5, C1, 0)
   4068  1.6  christos        || reg->value == CPENC (3, 5, C5, C1, 1)
   4069  1.6  christos        || reg->value == CPENC (3, 5, C5, C2, 0)
   4070  1.6  christos        || reg->value == CPENC (3, 5, C6, C0, 0)
   4071  1.6  christos        || reg->value == CPENC (3, 5, C10, C2, 0)
   4072  1.6  christos        || reg->value == CPENC (3, 5, C10, C3, 0)
   4073  1.6  christos        || reg->value == CPENC (3, 5, C12, C0, 0)
   4074  1.6  christos        || reg->value == CPENC (3, 5, C13, C0, 1)
   4075  1.6  christos        || reg->value == CPENC (3, 5, C14, C1, 0))
   4076  1.6  christos       && !AARCH64_CPU_HAS_FEATURE (features, AARCH64_FEATURE_V8_1))
   4077  1.6  christos     return FALSE;
   4078  1.6  christos 
   4079  1.6  christos   /* Virtualization host extensions: *_el02 names of *_el0 registers.  */
   4080  1.6  christos   if ((reg->value == CPENC (3, 5, C14, C2, 0)
   4081  1.6  christos        || reg->value == CPENC (3, 5, C14, C2, 1)
   4082  1.6  christos        || reg->value == CPENC (3, 5, C14, C2, 2)
   4083  1.6  christos        || reg->value == CPENC (3, 5, C14, C3, 0)
   4084  1.6  christos        || reg->value == CPENC (3, 5, C14, C3, 1)
   4085  1.6  christos        || reg->value == CPENC (3, 5, C14, C3, 2))
   4086  1.6  christos       && !AARCH64_CPU_HAS_FEATURE (features, AARCH64_FEATURE_V8_1))
   4087  1.6  christos     return FALSE;
   4088  1.6  christos 
   4089  1.6  christos   /* ARMv8.2 features.  */
   4090  1.6  christos 
   4091  1.6  christos   /* ID_AA64MMFR2_EL1.  */
   4092  1.6  christos   if (reg->value == CPENC (3, 0, C0, C7, 2)
   4093  1.6  christos       && !AARCH64_CPU_HAS_FEATURE (features, AARCH64_FEATURE_V8_2))
   4094  1.6  christos     return FALSE;
   4095  1.6  christos 
   4096  1.6  christos   /* PSTATE.UAO.  */
   4097  1.6  christos   if (reg->value == CPEN_ (0, C2, 4)
   4098  1.6  christos       && !AARCH64_CPU_HAS_FEATURE (features, AARCH64_FEATURE_V8_2))
   4099  1.6  christos     return FALSE;
   4100  1.6  christos 
   4101  1.6  christos   /* RAS extension.  */
   4102  1.6  christos 
   4103  1.6  christos   /* ERRIDR_EL1, ERRSELR_EL1, ERXFR_EL1, ERXCTLR_EL1, ERXSTATUS_EL, ERXADDR_EL1,
   4104  1.6  christos      ERXMISC0_EL1 AND ERXMISC1_EL1.  */
   4105  1.6  christos   if ((reg->value == CPENC (3, 0, C5, C3, 0)
   4106  1.6  christos        || reg->value == CPENC (3, 0, C5, C3, 1)
   4107  1.6  christos        || reg->value == CPENC (3, 0, C5, C3, 2)
   4108  1.6  christos        || reg->value == CPENC (3, 0, C5, C3, 3)
   4109  1.6  christos        || reg->value == CPENC (3, 0, C5, C4, 0)
   4110  1.6  christos        || reg->value == CPENC (3, 0, C5, C4, 1)
   4111  1.6  christos        || reg->value == CPENC (3, 0, C5, C4, 2)
   4112  1.6  christos        || reg->value == CPENC (3, 0, C5, C4, 3)
   4113  1.6  christos        || reg->value == CPENC (3, 0, C5, C5, 0)
   4114  1.6  christos        || reg->value == CPENC (3, 0, C5, C5, 1))
   4115  1.6  christos       && !AARCH64_CPU_HAS_FEATURE (features, AARCH64_FEATURE_RAS))
   4116  1.6  christos     return FALSE;
   4117  1.6  christos 
   4118  1.6  christos   /* VSESR_EL2, DISR_EL1 and VDISR_EL2.  */
   4119  1.6  christos   if ((reg->value == CPENC (3, 4, C5, C2, 3)
   4120  1.6  christos        || reg->value == CPENC (3, 0, C12, C1, 1)
   4121  1.6  christos        || reg->value == CPENC (3, 4, C12, C1, 1))
   4122  1.6  christos       && !AARCH64_CPU_HAS_FEATURE (features, AARCH64_FEATURE_RAS))
   4123  1.6  christos     return FALSE;
   4124  1.6  christos 
   4125  1.6  christos   /* Statistical Profiling extension.  */
   4126  1.6  christos   if ((reg->value == CPENC (3, 0, C9, C10, 0)
   4127  1.6  christos        || reg->value == CPENC (3, 0, C9, C10, 1)
   4128  1.6  christos        || reg->value == CPENC (3, 0, C9, C10, 3)
   4129  1.6  christos        || reg->value == CPENC (3, 0, C9, C10, 7)
   4130  1.6  christos        || reg->value == CPENC (3, 0, C9, C9, 0)
   4131  1.6  christos        || reg->value == CPENC (3, 0, C9, C9, 2)
   4132  1.6  christos        || reg->value == CPENC (3, 0, C9, C9, 3)
   4133  1.6  christos        || reg->value == CPENC (3, 0, C9, C9, 4)
   4134  1.6  christos        || reg->value == CPENC (3, 0, C9, C9, 5)
   4135  1.6  christos        || reg->value == CPENC (3, 0, C9, C9, 6)
   4136  1.6  christos        || reg->value == CPENC (3, 0, C9, C9, 7)
   4137  1.6  christos        || reg->value == CPENC (3, 4, C9, C9, 0)
   4138  1.7  christos        || reg->value == CPENC (3, 5, C9, C9, 0))
   4139  1.7  christos       && !AARCH64_CPU_HAS_FEATURE (features, AARCH64_FEATURE_PROFILE))
   4140  1.7  christos     return FALSE;
   4141  1.7  christos 
   4142  1.7  christos   /* ARMv8.3 Pointer authentication keys.  */
   4143  1.7  christos   if ((reg->value == CPENC (3, 0, C2, C1, 0)
   4144  1.7  christos        || reg->value == CPENC (3, 0, C2, C1, 1)
   4145  1.7  christos        || reg->value == CPENC (3, 0, C2, C1, 2)
   4146  1.7  christos        || reg->value == CPENC (3, 0, C2, C1, 3)
   4147  1.7  christos        || reg->value == CPENC (3, 0, C2, C2, 0)
   4148  1.7  christos        || reg->value == CPENC (3, 0, C2, C2, 1)
   4149  1.7  christos        || reg->value == CPENC (3, 0, C2, C2, 2)
   4150  1.7  christos        || reg->value == CPENC (3, 0, C2, C2, 3)
   4151  1.7  christos        || reg->value == CPENC (3, 0, C2, C3, 0)
   4152  1.7  christos        || reg->value == CPENC (3, 0, C2, C3, 1))
   4153  1.7  christos       && !AARCH64_CPU_HAS_FEATURE (features, AARCH64_FEATURE_V8_3))
   4154  1.7  christos     return FALSE;
   4155  1.7  christos 
   4156  1.7  christos   /* SVE.  */
   4157  1.7  christos   if ((reg->value == CPENC (3, 0, C0, C4, 4)
   4158  1.7  christos        || reg->value == CPENC (3, 0, C1, C2, 0)
   4159  1.7  christos        || reg->value == CPENC (3, 4, C1, C2, 0)
   4160  1.7  christos        || reg->value == CPENC (3, 6, C1, C2, 0)
   4161  1.7  christos        || reg->value == CPENC (3, 5, C1, C2, 0)
   4162  1.5  christos        || reg->value == CPENC (3, 0, C0, C0, 7))
   4163  1.5  christos       && !AARCH64_CPU_HAS_FEATURE (features, AARCH64_FEATURE_SVE))
   4164  1.5  christos     return FALSE;
   4165  1.1  christos 
   4166  1.1  christos   return TRUE;
   4167  1.1  christos }
   4168  1.1  christos 
   4169  1.1  christos const aarch64_sys_reg aarch64_pstatefields [] =
   4170  1.5  christos {
   4171  1.6  christos   { "spsel",            0x05,	0 },
   4172  1.1  christos   { "daifset",          0x1e,	0 },
   4173  1.1  christos   { "daifclr",          0x1f,	0 },
   4174  1.1  christos   { "pan",		0x04,	F_ARCHEXT },
   4175  1.5  christos   { "uao",		0x03,	F_ARCHEXT },
   4176  1.5  christos   { 0,          CPENC(0,0,0,0,0), 0 },
   4177  1.5  christos };
   4178  1.5  christos 
   4179  1.5  christos bfd_boolean
   4180  1.5  christos aarch64_pstatefield_supported_p (const aarch64_feature_set features,
   4181  1.5  christos 				 const aarch64_sys_reg *reg)
   4182  1.5  christos {
   4183  1.5  christos   if (!(reg->flags & F_ARCHEXT))
   4184  1.5  christos     return TRUE;
   4185  1.5  christos 
   4186  1.5  christos   /* PAN.  Values are from aarch64_pstatefields.  */
   4187  1.6  christos   if (reg->value == 0x04
   4188  1.6  christos       && !AARCH64_CPU_HAS_FEATURE (features, AARCH64_FEATURE_PAN))
   4189  1.6  christos     return FALSE;
   4190  1.6  christos 
   4191  1.6  christos   /* UAO.  Values are from aarch64_pstatefields.  */
   4192  1.5  christos   if (reg->value == 0x03
   4193  1.5  christos       && !AARCH64_CPU_HAS_FEATURE (features, AARCH64_FEATURE_V8_2))
   4194  1.5  christos     return FALSE;
   4195  1.1  christos 
   4196  1.1  christos   return TRUE;
   4197  1.1  christos }
   4198  1.1  christos 
   4199  1.6  christos const aarch64_sys_ins_reg aarch64_sys_regs_ic[] =
   4200  1.1  christos {
   4201  1.1  christos     { "ialluis", CPENS(0,C7,C1,0), 0 },
   4202  1.1  christos     { "iallu",   CPENS(0,C7,C5,0), 0 },
   4203  1.1  christos     { "ivau",    CPENS (3, C7, C5, 1), F_HASXT },
   4204  1.1  christos     { 0, CPENS(0,0,0,0), 0 }
   4205  1.6  christos };
   4206  1.6  christos 
   4207  1.6  christos const aarch64_sys_ins_reg aarch64_sys_regs_dc[] =
   4208  1.6  christos {
   4209  1.6  christos     { "zva",	    CPENS (3, C7, C4, 1),  F_HASXT },
   4210  1.6  christos     { "ivac",       CPENS (0, C7, C6, 1),  F_HASXT },
   4211  1.6  christos     { "isw",	    CPENS (0, C7, C6, 2),  F_HASXT },
   4212  1.6  christos     { "cvac",       CPENS (3, C7, C10, 1), F_HASXT },
   4213  1.6  christos     { "csw",	    CPENS (0, C7, C10, 2), F_HASXT },
   4214  1.1  christos     { "cvau",       CPENS (3, C7, C11, 1), F_HASXT },
   4215  1.1  christos     { "cvap",       CPENS (3, C7, C12, 1), F_HASXT | F_ARCHEXT },
   4216  1.1  christos     { "civac",      CPENS (3, C7, C14, 1), F_HASXT },
   4217  1.1  christos     { "cisw",       CPENS (0, C7, C14, 2), F_HASXT },
   4218  1.1  christos     { 0,       CPENS(0,0,0,0), 0 }
   4219  1.6  christos };
   4220  1.6  christos 
   4221  1.6  christos const aarch64_sys_ins_reg aarch64_sys_regs_at[] =
   4222  1.6  christos {
   4223  1.6  christos     { "s1e1r",      CPENS (0, C7, C8, 0), F_HASXT },
   4224  1.6  christos     { "s1e1w",      CPENS (0, C7, C8, 1), F_HASXT },
   4225  1.6  christos     { "s1e0r",      CPENS (0, C7, C8, 2), F_HASXT },
   4226  1.6  christos     { "s1e0w",      CPENS (0, C7, C8, 3), F_HASXT },
   4227  1.6  christos     { "s12e1r",     CPENS (4, C7, C8, 4), F_HASXT },
   4228  1.6  christos     { "s12e1w",     CPENS (4, C7, C8, 5), F_HASXT },
   4229  1.6  christos     { "s12e0r",     CPENS (4, C7, C8, 6), F_HASXT },
   4230  1.6  christos     { "s12e0w",     CPENS (4, C7, C8, 7), F_HASXT },
   4231  1.6  christos     { "s1e2r",      CPENS (4, C7, C8, 0), F_HASXT },
   4232  1.6  christos     { "s1e2w",      CPENS (4, C7, C8, 1), F_HASXT },
   4233  1.1  christos     { "s1e3r",      CPENS (6, C7, C8, 0), F_HASXT },
   4234  1.1  christos     { "s1e3w",      CPENS (6, C7, C8, 1), F_HASXT },
   4235  1.1  christos     { "s1e1rp",     CPENS (0, C7, C9, 0), F_HASXT | F_ARCHEXT },
   4236  1.1  christos     { "s1e1wp",     CPENS (0, C7, C9, 1), F_HASXT | F_ARCHEXT },
   4237  1.1  christos     { 0,       CPENS(0,0,0,0), 0 }
   4238  1.1  christos };
   4239  1.6  christos 
   4240  1.6  christos const aarch64_sys_ins_reg aarch64_sys_regs_tlbi[] =
   4241  1.6  christos {
   4242  1.1  christos     { "vmalle1",   CPENS(0,C8,C7,0), 0 },
   4243  1.6  christos     { "vae1",      CPENS (0, C8, C7, 1), F_HASXT },
   4244  1.6  christos     { "aside1",    CPENS (0, C8, C7, 2), F_HASXT },
   4245  1.6  christos     { "vaae1",     CPENS (0, C8, C7, 3), F_HASXT },
   4246  1.6  christos     { "vmalle1is", CPENS(0,C8,C3,0), 0 },
   4247  1.6  christos     { "vae1is",    CPENS (0, C8, C3, 1), F_HASXT },
   4248  1.6  christos     { "aside1is",  CPENS (0, C8, C3, 2), F_HASXT },
   4249  1.6  christos     { "vaae1is",   CPENS (0, C8, C3, 3), F_HASXT },
   4250  1.6  christos     { "ipas2e1is", CPENS (4, C8, C0, 1), F_HASXT },
   4251  1.6  christos     { "ipas2le1is",CPENS (4, C8, C0, 5), F_HASXT },
   4252  1.1  christos     { "ipas2e1",   CPENS (4, C8, C4, 1), F_HASXT },
   4253  1.1  christos     { "ipas2le1",  CPENS (4, C8, C4, 5), F_HASXT },
   4254  1.6  christos     { "vae2",      CPENS (4, C8, C7, 1), F_HASXT },
   4255  1.6  christos     { "vae2is",    CPENS (4, C8, C3, 1), F_HASXT },
   4256  1.1  christos     { "vmalls12e1",CPENS(4,C8,C7,6), 0 },
   4257  1.1  christos     { "vmalls12e1is",CPENS(4,C8,C3,6), 0 },
   4258  1.1  christos     { "vae3",      CPENS (6, C8, C7, 1), F_HASXT },
   4259  1.1  christos     { "vae3is",    CPENS (6, C8, C3, 1), F_HASXT },
   4260  1.1  christos     { "alle2",     CPENS(4,C8,C7,0), 0 },
   4261  1.1  christos     { "alle2is",   CPENS(4,C8,C3,0), 0 },
   4262  1.6  christos     { "alle1",     CPENS(4,C8,C7,4), 0 },
   4263  1.6  christos     { "alle1is",   CPENS(4,C8,C3,4), 0 },
   4264  1.6  christos     { "alle3",     CPENS(6,C8,C7,0), 0 },
   4265  1.6  christos     { "alle3is",   CPENS(6,C8,C3,0), 0 },
   4266  1.6  christos     { "vale1is",   CPENS (0, C8, C3, 5), F_HASXT },
   4267  1.6  christos     { "vale2is",   CPENS (4, C8, C3, 5), F_HASXT },
   4268  1.6  christos     { "vale3is",   CPENS (6, C8, C3, 5), F_HASXT },
   4269  1.6  christos     { "vaale1is",  CPENS (0, C8, C3, 7), F_HASXT },
   4270  1.1  christos     { "vale1",     CPENS (0, C8, C7, 5), F_HASXT },
   4271  1.1  christos     { "vale2",     CPENS (4, C8, C7, 5), F_HASXT },
   4272  1.1  christos     { "vale3",     CPENS (6, C8, C7, 5), F_HASXT },
   4273  1.6  christos     { "vaale1",    CPENS (0, C8, C7, 7), F_HASXT },
   4274  1.6  christos     { 0,       CPENS(0,0,0,0), 0 }
   4275  1.6  christos };
   4276  1.6  christos 
   4277  1.6  christos bfd_boolean
   4278  1.6  christos aarch64_sys_ins_reg_has_xt (const aarch64_sys_ins_reg *sys_ins_reg)
   4279  1.6  christos {
   4280  1.6  christos   return (sys_ins_reg->flags & F_HASXT) != 0;
   4281  1.6  christos }
   4282  1.6  christos 
   4283  1.6  christos extern bfd_boolean
   4284  1.6  christos aarch64_sys_ins_reg_supported_p (const aarch64_feature_set features,
   4285  1.6  christos 				 const aarch64_sys_ins_reg *reg)
   4286  1.6  christos {
   4287  1.6  christos   if (!(reg->flags & F_ARCHEXT))
   4288  1.6  christos     return TRUE;
   4289  1.6  christos 
   4290  1.6  christos   /* DC CVAP.  Values are from aarch64_sys_regs_dc.  */
   4291  1.6  christos   if (reg->value == CPENS (3, C7, C12, 1)
   4292  1.6  christos       && !AARCH64_CPU_HAS_FEATURE (features, AARCH64_FEATURE_V8_2))
   4293  1.6  christos     return FALSE;
   4294  1.6  christos 
   4295  1.6  christos   /* AT S1E1RP, AT S1E1WP.  Values are from aarch64_sys_regs_at.  */
   4296  1.6  christos   if ((reg->value == CPENS (0, C7, C9, 0)
   4297  1.6  christos        || reg->value == CPENS (0, C7, C9, 1))
   4298  1.6  christos       && !AARCH64_CPU_HAS_FEATURE (features, AARCH64_FEATURE_V8_2))
   4299  1.6  christos     return FALSE;
   4300  1.1  christos 
   4301  1.1  christos   return TRUE;
   4302  1.1  christos }
   4303  1.1  christos 
   4304  1.1  christos #undef C0
   4305  1.1  christos #undef C1
   4306  1.1  christos #undef C2
   4307  1.1  christos #undef C3
   4308  1.1  christos #undef C4
   4309  1.1  christos #undef C5
   4310  1.1  christos #undef C6
   4311  1.1  christos #undef C7
   4312  1.1  christos #undef C8
   4313  1.1  christos #undef C9
   4314  1.1  christos #undef C10
   4315  1.1  christos #undef C11
   4316  1.1  christos #undef C12
   4317  1.6  christos #undef C13
   4318  1.6  christos #undef C14
   4319  1.6  christos #undef C15
   4320  1.6  christos 
   4321  1.6  christos #define BIT(INSN,BT)     (((INSN) >> (BT)) & 1)
   4322  1.6  christos #define BITS(INSN,HI,LO) (((INSN) >> (LO)) & ((1 << (((HI) - (LO)) + 1)) - 1))
   4323  1.6  christos 
   4324  1.6  christos static bfd_boolean
   4325  1.6  christos verify_ldpsw (const struct aarch64_opcode * opcode ATTRIBUTE_UNUSED,
   4326  1.6  christos 	      const aarch64_insn insn)
   4327  1.6  christos {
   4328  1.6  christos   int t  = BITS (insn, 4, 0);
   4329  1.6  christos   int n  = BITS (insn, 9, 5);
   4330  1.6  christos   int t2 = BITS (insn, 14, 10);
   4331  1.6  christos 
   4332  1.6  christos   if (BIT (insn, 23))
   4333  1.6  christos     {
   4334  1.6  christos       /* Write back enabled.  */
   4335  1.6  christos       if ((t == n || t2 == n) && n != 31)
   4336  1.6  christos 	return FALSE;
   4337  1.6  christos     }
   4338  1.6  christos 
   4339  1.6  christos   if (BIT (insn, 22))
   4340  1.6  christos     {
   4341  1.6  christos       /* Load */
   4342  1.6  christos       if (t == t2)
   4343  1.6  christos 	return FALSE;
   4344  1.6  christos     }
   4345  1.7  christos 
   4346  1.7  christos   return TRUE;
   4347  1.7  christos }
   4348  1.7  christos 
   4349  1.7  christos /* Return true if VALUE cannot be moved into an SVE register using DUP
   4350  1.7  christos    (with any element size, not just ESIZE) and if using DUPM would
   4351  1.7  christos    therefore be OK.  ESIZE is the number of bytes in the immediate.  */
   4352  1.7  christos 
   4353  1.7  christos bfd_boolean
   4354  1.7  christos aarch64_sve_dupm_mov_immediate_p (uint64_t uvalue, int esize)
   4355  1.7  christos {
   4356  1.7  christos   int64_t svalue = uvalue;
   4357  1.7  christos   uint64_t upper = (uint64_t) -1 << (esize * 4) << (esize * 4);
   4358  1.7  christos 
   4359  1.7  christos   if ((uvalue & ~upper) != uvalue && (uvalue | upper) != uvalue)
   4360  1.7  christos     return FALSE;
   4361  1.7  christos   if (esize <= 4 || (uint32_t) uvalue == (uint32_t) (uvalue >> 32))
   4362  1.7  christos     {
   4363  1.7  christos       svalue = (int32_t) uvalue;
   4364  1.7  christos       if (esize <= 2 || (uint16_t) uvalue == (uint16_t) (uvalue >> 16))
   4365  1.7  christos 	{
   4366  1.7  christos 	  svalue = (int16_t) uvalue;
   4367  1.7  christos 	  if (esize == 1 || (uint8_t) uvalue == (uint8_t) (uvalue >> 8))
   4368  1.7  christos 	    return FALSE;
   4369  1.7  christos 	}
   4370  1.7  christos     }
   4371  1.7  christos   if ((svalue & 0xff) == 0)
   4372  1.1  christos     svalue /= 256;
   4373  1.1  christos   return svalue < -128 || svalue >= 128;
   4374  1.6  christos }
   4375  1.1  christos 
   4376                /* Include the opcode description table as well as the operand description
   4377                   table.  */
   4378                #define VERIFIER(x) verify_##x
   4379                #include "aarch64-tbl.h"
   4380