Coverage Report

Created: 2023-08-28 06:23

/src/binutils-gdb/opcodes/aarch64-opc.c
Line
Count
Source (jump to first uncovered line)
1
/* aarch64-opc.c -- AArch64 opcode support.
2
   Copyright (C) 2009-2023 Free Software Foundation, Inc.
3
   Contributed by ARM Ltd.
4
5
   This file is part of the GNU opcodes library.
6
7
   This library is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 3, or (at your option)
10
   any later version.
11
12
   It is distributed in the hope that it will be useful, but WITHOUT
13
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
15
   License for more details.
16
17
   You should have received a copy of the GNU General Public License
18
   along with this program; see the file COPYING3. If not,
19
   see <http://www.gnu.org/licenses/>.  */
20
21
#include "sysdep.h"
22
#include <assert.h>
23
#include <stdlib.h>
24
#include <stdio.h>
25
#include <stdint.h>
26
#include <stdarg.h>
27
#include <inttypes.h>
28
29
#include "opintl.h"
30
#include "libiberty.h"
31
32
#include "aarch64-opc.h"
33
34
#ifdef DEBUG_AARCH64
35
int debug_dump = false;
36
#endif /* DEBUG_AARCH64 */
37
38
/* The enumeration strings associated with each value of a 5-bit SVE
39
   pattern operand.  A null entry indicates a reserved meaning.  */
40
const char *const aarch64_sve_pattern_array[32] = {
41
  /* 0-7.  */
42
  "pow2",
43
  "vl1",
44
  "vl2",
45
  "vl3",
46
  "vl4",
47
  "vl5",
48
  "vl6",
49
  "vl7",
50
  /* 8-15.  */
51
  "vl8",
52
  "vl16",
53
  "vl32",
54
  "vl64",
55
  "vl128",
56
  "vl256",
57
  0,
58
  0,
59
  /* 16-23.  */
60
  0,
61
  0,
62
  0,
63
  0,
64
  0,
65
  0,
66
  0,
67
  0,
68
  /* 24-31.  */
69
  0,
70
  0,
71
  0,
72
  0,
73
  0,
74
  "mul4",
75
  "mul3",
76
  "all"
77
};
78
79
/* The enumeration strings associated with each value of a 4-bit SVE
80
   prefetch operand.  A null entry indicates a reserved meaning.  */
81
const char *const aarch64_sve_prfop_array[16] = {
82
  /* 0-7.  */
83
  "pldl1keep",
84
  "pldl1strm",
85
  "pldl2keep",
86
  "pldl2strm",
87
  "pldl3keep",
88
  "pldl3strm",
89
  0,
90
  0,
91
  /* 8-15.  */
92
  "pstl1keep",
93
  "pstl1strm",
94
  "pstl2keep",
95
  "pstl2strm",
96
  "pstl3keep",
97
  "pstl3strm",
98
  0,
99
  0
100
};
101
102
/* The enumeration strings associated with each value of a 6-bit RPRFM
103
   operation.  */
104
const char *const aarch64_rprfmop_array[64] = {
105
  "pldkeep",
106
  "pstkeep",
107
  0,
108
  0,
109
  "pldstrm",
110
  "pststrm"
111
};
112
113
/* Vector length multiples for a predicate-as-counter operand.  Used in things
114
   like AARCH64_OPND_SME_VLxN_10.  */
115
const char *const aarch64_sme_vlxn_array[2] = {
116
  "vlx2",
117
  "vlx4"
118
};
119
120
/* Helper functions to determine which operand to be used to encode/decode
121
   the size:Q fields for AdvSIMD instructions.  */
122
123
static inline bool
124
vector_qualifier_p (enum aarch64_opnd_qualifier qualifier)
125
0
{
126
0
  return (qualifier >= AARCH64_OPND_QLF_V_8B
127
0
    && qualifier <= AARCH64_OPND_QLF_V_1Q);
128
0
}
129
130
static inline bool
131
fp_qualifier_p (enum aarch64_opnd_qualifier qualifier)
132
0
{
133
0
  return (qualifier >= AARCH64_OPND_QLF_S_B
134
0
    && qualifier <= AARCH64_OPND_QLF_S_Q);
135
0
}
136
137
enum data_pattern
138
{
139
  DP_UNKNOWN,
140
  DP_VECTOR_3SAME,
141
  DP_VECTOR_LONG,
142
  DP_VECTOR_WIDE,
143
  DP_VECTOR_ACROSS_LANES,
144
};
145
146
static const char significant_operand_index [] =
147
{
148
  0,  /* DP_UNKNOWN, by default using operand 0.  */
149
  0,  /* DP_VECTOR_3SAME */
150
  1,  /* DP_VECTOR_LONG */
151
  2,  /* DP_VECTOR_WIDE */
152
  1,  /* DP_VECTOR_ACROSS_LANES */
153
};
154
155
/* Given a sequence of qualifiers in QUALIFIERS, determine and return
156
   the data pattern.
157
   N.B. QUALIFIERS is a possible sequence of qualifiers each of which
158
   corresponds to one of a sequence of operands.  */
159
160
static enum data_pattern
161
get_data_pattern (const aarch64_opnd_qualifier_seq_t qualifiers)
162
0
{
163
0
  if (vector_qualifier_p (qualifiers[0]))
164
0
    {
165
      /* e.g. v.4s, v.4s, v.4s
166
     or v.4h, v.4h, v.h[3].  */
167
0
      if (qualifiers[0] == qualifiers[1]
168
0
    && vector_qualifier_p (qualifiers[2])
169
0
    && (aarch64_get_qualifier_esize (qualifiers[0])
170
0
        == aarch64_get_qualifier_esize (qualifiers[1]))
171
0
    && (aarch64_get_qualifier_esize (qualifiers[0])
172
0
        == aarch64_get_qualifier_esize (qualifiers[2])))
173
0
  return DP_VECTOR_3SAME;
174
      /* e.g. v.8h, v.8b, v.8b.
175
           or v.4s, v.4h, v.h[2].
176
     or v.8h, v.16b.  */
177
0
      if (vector_qualifier_p (qualifiers[1])
178
0
    && aarch64_get_qualifier_esize (qualifiers[0]) != 0
179
0
    && (aarch64_get_qualifier_esize (qualifiers[0])
180
0
        == aarch64_get_qualifier_esize (qualifiers[1]) << 1))
181
0
  return DP_VECTOR_LONG;
182
      /* e.g. v.8h, v.8h, v.8b.  */
183
0
      if (qualifiers[0] == qualifiers[1]
184
0
    && vector_qualifier_p (qualifiers[2])
185
0
    && aarch64_get_qualifier_esize (qualifiers[0]) != 0
186
0
    && (aarch64_get_qualifier_esize (qualifiers[0])
187
0
        == aarch64_get_qualifier_esize (qualifiers[2]) << 1)
188
0
    && (aarch64_get_qualifier_esize (qualifiers[0])
189
0
        == aarch64_get_qualifier_esize (qualifiers[1])))
190
0
  return DP_VECTOR_WIDE;
191
0
    }
192
0
  else if (fp_qualifier_p (qualifiers[0]))
193
0
    {
194
      /* e.g. SADDLV <V><d>, <Vn>.<T>.  */
195
0
      if (vector_qualifier_p (qualifiers[1])
196
0
    && qualifiers[2] == AARCH64_OPND_QLF_NIL)
197
0
  return DP_VECTOR_ACROSS_LANES;
198
0
    }
199
200
0
  return DP_UNKNOWN;
201
0
}
202
203
/* Select the operand to do the encoding/decoding of the 'size:Q' fields in
204
   the AdvSIMD instructions.  */
205
/* N.B. it is possible to do some optimization that doesn't call
206
   get_data_pattern each time when we need to select an operand.  We can
207
   either buffer the caculated the result or statically generate the data,
208
   however, it is not obvious that the optimization will bring significant
209
   benefit.  */
210
211
int
212
aarch64_select_operand_for_sizeq_field_coding (const aarch64_opcode *opcode)
213
0
{
214
0
  return
215
0
    significant_operand_index [get_data_pattern (opcode->qualifiers_list[0])];
216
0
}
217

218
/* Instruction bit-fields.
219
+   Keep synced with 'enum aarch64_field_kind'.  */
220
const aarch64_field fields[] =
221
{
222
    {  0,  0 }, /* NIL.  */
223
    {  8,  4 }, /* CRm: in the system instructions.  */
224
    { 10,  2 }, /* CRm_dsb_nxs: 2-bit imm. encoded in CRm<3:2>.  */
225
    { 12,  4 }, /* CRn: in the system instructions.  */
226
    { 10,  8 }, /* CSSC_imm8.  */
227
    { 11,  1 }, /* H: in advsimd scalar x indexed element instructions.  */
228
    { 21,  1 }, /* L: in advsimd scalar x indexed element instructions.  */
229
    { 20,  1 }, /* M: in advsimd scalar x indexed element instructions.  */
230
    { 22,  1 }, /* N: in logical (immediate) instructions.  */
231
    { 30,  1 }, /* Q: in most AdvSIMD instructions.  */
232
    { 10,  5 }, /* Ra: in fp instructions.  */
233
    {  0,  5 }, /* Rd: in many integer instructions.  */
234
    { 16,  5 }, /* Rm: in ld/st reg offset and some integer inst.  */
235
    {  5,  5 }, /* Rn: in many integer instructions.  */
236
    { 16,  5 }, /* Rs: in load/store exclusive instructions.  */
237
    {  0,  5 }, /* Rt: in load/store instructions.  */
238
    { 10,  5 }, /* Rt2: in load/store pair instructions.  */
239
    { 12,  1 }, /* S: in load/store reg offset instructions.  */
240
    { 12,  2 }, /* SM3_imm2: Indexed element SM3 2 bits index immediate.  */
241
    {  1,  3 }, /* SME_Pdx2: predicate register, multiple of 2, [3:1].  */
242
    { 13,  3 }, /* SME_Pm: second source scalable predicate register P0-P7.  */
243
    {  0,  3 }, /* SME_PNd3: PN0-PN7, bits [2:0].  */
244
    {  5,  3 }, /* SME_PNn3: PN0-PN7, bits [7:5].  */
245
    { 16,  1 }, /* SME_Q: Q class bit, bit 16.  */
246
    { 16,  2 }, /* SME_Rm: index base register W12-W15 [17:16].  */
247
    { 13,  2 }, /* SME_Rv: vector select register W12-W15, bits [14:13].  */
248
    { 15,  1 }, /* SME_V: (horizontal / vertical tiles), bit 15.  */
249
    { 10,  1 }, /* SME_VL_10: VLx2 or VLx4, bit [10].  */
250
    { 13,  1 }, /* SME_VL_13: VLx2 or VLx4, bit [13].  */
251
    {  0,  2 }, /* SME_ZAda_2b: tile ZA0-ZA3.  */
252
    {  0,  3 }, /* SME_ZAda_3b: tile ZA0-ZA7.  */
253
    {  1,  4 }, /* SME_Zdn2: Z0-Z31, multiple of 2, bits [4:1].  */
254
    {  2,  3 }, /* SME_Zdn4: Z0-Z31, multiple of 4, bits [4:2].  */
255
    { 16,  4 }, /* SME_Zm: Z0-Z15, bits [19:16].  */
256
    { 17,  4 }, /* SME_Zm2: Z0-Z31, multiple of 2, bits [20:17].  */
257
    { 18,  3 }, /* SME_Zm4: Z0-Z31, multiple of 4, bits [20:18].  */
258
    {  6,  4 }, /* SME_Zn2: Z0-Z31, multiple of 2, bits [9:6].  */
259
    {  7,  3 }, /* SME_Zn4: Z0-Z31, multiple of 4, bits [9:7].  */
260
    {  4,  1 }, /* SME_ZtT: upper bit of Zt, bit [4].  */
261
    {  0,  3 }, /* SME_Zt3: lower 3 bits of Zt, bits [2:0].  */
262
    {  0,  2 }, /* SME_Zt2: lower 2 bits of Zt, bits [1:0].  */
263
    { 23,  1 }, /* SME_i1: immediate field, bit 23.  */
264
    { 12,  2 }, /* SME_size_12: bits [13:12].  */
265
    { 22,  2 }, /* SME_size_22: size<1>, size<0> class field, [23:22].  */
266
    { 23,  1 }, /* SME_sz_23: bit [23].  */
267
    { 22,  1 }, /* SME_tszh: immediate and qualifier field, bit 22.  */
268
    { 18,  3 }, /* SME_tszl: immediate and qualifier field, bits [20:18].  */
269
    { 0,   8 }, /* SME_zero_mask: list of up to 8 tile names separated by commas [7:0].  */
270
    {  4,  1 }, /* SVE_M_4: Merge/zero select, bit 4.  */
271
    { 14,  1 }, /* SVE_M_14: Merge/zero select, bit 14.  */
272
    { 16,  1 }, /* SVE_M_16: Merge/zero select, bit 16.  */
273
    { 17,  1 }, /* SVE_N: SVE equivalent of N.  */
274
    {  0,  4 }, /* SVE_Pd: p0-p15, bits [3,0].  */
275
    { 10,  3 }, /* SVE_Pg3: p0-p7, bits [12,10].  */
276
    {  5,  4 }, /* SVE_Pg4_5: p0-p15, bits [8,5].  */
277
    { 10,  4 }, /* SVE_Pg4_10: p0-p15, bits [13,10].  */
278
    { 16,  4 }, /* SVE_Pg4_16: p0-p15, bits [19,16].  */
279
    { 16,  4 }, /* SVE_Pm: p0-p15, bits [19,16].  */
280
    {  5,  4 }, /* SVE_Pn: p0-p15, bits [8,5].  */
281
    {  0,  4 }, /* SVE_Pt: p0-p15, bits [3,0].  */
282
    {  5,  5 }, /* SVE_Rm: SVE alternative position for Rm.  */
283
    { 16,  5 }, /* SVE_Rn: SVE alternative position for Rn.  */
284
    {  0,  5 }, /* SVE_Vd: Scalar SIMD&FP register, bits [4,0].  */
285
    {  5,  5 }, /* SVE_Vm: Scalar SIMD&FP register, bits [9,5].  */
286
    {  5,  5 }, /* SVE_Vn: Scalar SIMD&FP register, bits [9,5].  */
287
    {  5,  5 }, /* SVE_Za_5: SVE vector register, bits [9,5].  */
288
    { 16,  5 }, /* SVE_Za_16: SVE vector register, bits [20,16].  */
289
    {  0,  5 }, /* SVE_Zd: SVE vector register. bits [4,0].  */
290
    {  5,  5 }, /* SVE_Zm_5: SVE vector register, bits [9,5].  */
291
    { 16,  5 }, /* SVE_Zm_16: SVE vector register, bits [20,16]. */
292
    {  5,  5 }, /* SVE_Zn: SVE vector register, bits [9,5].  */
293
    {  0,  5 }, /* SVE_Zt: SVE vector register, bits [4,0].  */
294
    {  5,  1 }, /* SVE_i1: single-bit immediate.  */
295
    { 20,  1 }, /* SVE_i2h: high bit of 2bit immediate, bits.  */
296
    { 22,  1 }, /* SVE_i3h: high bit of 3-bit immediate.  */
297
    { 19,  2 }, /* SVE_i3h2: two high bits of 3bit immediate, bits [20,19].  */
298
    { 11,  1 }, /* SVE_i3l: low bit of 3-bit immediate.  */
299
    { 16,  3 }, /* SVE_imm3: 3-bit immediate field.  */
300
    { 16,  4 }, /* SVE_imm4: 4-bit immediate field.  */
301
    {  5,  5 }, /* SVE_imm5: 5-bit immediate field.  */
302
    { 16,  5 }, /* SVE_imm5b: secondary 5-bit immediate field.  */
303
    { 16,  6 }, /* SVE_imm6: 6-bit immediate field.  */
304
    { 14,  7 }, /* SVE_imm7: 7-bit immediate field.  */
305
    {  5,  8 }, /* SVE_imm8: 8-bit immediate field.  */
306
    {  5,  9 }, /* SVE_imm9: 9-bit immediate field.  */
307
    { 11,  6 }, /* SVE_immr: SVE equivalent of immr.  */
308
    {  5,  6 }, /* SVE_imms: SVE equivalent of imms.  */
309
    { 10,  2 }, /* SVE_msz: 2-bit shift amount for ADR.  */
310
    {  5,  5 }, /* SVE_pattern: vector pattern enumeration.  */
311
    {  0,  4 }, /* SVE_prfop: prefetch operation for SVE PRF[BHWD].  */
312
    { 16,  1 }, /* SVE_rot1: 1-bit rotation amount.  */
313
    { 10,  2 }, /* SVE_rot2: 2-bit rotation amount.  */
314
    { 10,  1 }, /* SVE_rot3: 1-bit rotation amount at bit 10.  */
315
    { 17,  2 }, /* SVE_size: 2-bit element size, bits [18,17].  */
316
    { 22,  1 }, /* SVE_sz: 1-bit element size select.  */
317
    { 30,  1 }, /* SVE_sz2: 1-bit element size select.  */
318
    { 16,  4 }, /* SVE_tsz: triangular size select.  */
319
    { 22,  2 }, /* SVE_tszh: triangular size select high, bits [23,22].  */
320
    {  8,  2 }, /* SVE_tszl_8: triangular size select low, bits [9,8].  */
321
    { 19,  2 }, /* SVE_tszl_19: triangular size select low, bits [20,19].  */
322
    { 14,  1 }, /* SVE_xs_14: UXTW/SXTW select (bit 14).  */
323
    { 22,  1 }, /* SVE_xs_22: UXTW/SXTW select (bit 22).  */
324
    { 22,  1 }, /* S_imm10: in LDRAA and LDRAB instructions.  */
325
    { 16,  3 }, /* abc: a:b:c bits in AdvSIMD modified immediate.  */
326
    { 13,  3 }, /* asisdlso_opcode: opcode in advsimd ld/st single element.  */
327
    { 19,  5 }, /* b40: in the test bit and branch instructions.  */
328
    { 31,  1 }, /* b5: in the test bit and branch instructions.  */
329
    { 12,  4 }, /* cmode: in advsimd modified immediate instructions.  */
330
    { 12,  4 }, /* cond: condition flags as a source operand.  */
331
    {  0,  4 }, /* cond2: condition in truly conditional-executed inst.  */
332
    {  5,  5 }, /* defgh: d:e:f:g:h bits in AdvSIMD modified immediate.  */
333
    { 21,  2 }, /* hw: in move wide constant instructions.  */
334
    {  0,  1 }, /* imm1_0: general immediate in bits [0].  */
335
    {  2,  1 }, /* imm1_2: general immediate in bits [2].  */
336
    {  8,  1 }, /* imm1_8: general immediate in bits [8].  */
337
    { 10,  1 }, /* imm1_10: general immediate in bits [10].  */
338
    { 15,  1 }, /* imm1_15: general immediate in bits [15].  */
339
    { 16,  1 }, /* imm1_16: general immediate in bits [16].  */
340
    {  0,  2 }, /* imm2_0: general immediate in bits [1:0].  */
341
    {  1,  2 }, /* imm2_1: general immediate in bits [2:1].  */
342
    {  8,  2 }, /* imm2_8: general immediate in bits [9:8].  */
343
    { 10,  2 }, /* imm2_10: 2-bit immediate, bits [11:10] */
344
    { 12,  2 }, /* imm2_12: 2-bit immediate, bits [13:12] */
345
    { 15,  2 }, /* imm2_15: 2-bit immediate, bits [16:15] */
346
    { 16,  2 }, /* imm2_16: 2-bit immediate, bits [17:16] */
347
    { 19,  2 }, /* imm2_19: 2-bit immediate, bits [20:19] */
348
    {  0,  3 }, /* imm3_0: general immediate in bits [2:0].  */
349
    {  5,  3 }, /* imm3_5: general immediate in bits [7:5].  */
350
    { 10,  3 }, /* imm3_10: in add/sub extended reg instructions.  */
351
    { 12,  3 }, /* imm3_12: general immediate in bits [14:12].  */
352
    { 14,  3 }, /* imm3_14: general immediate in bits [16:14].  */
353
    { 15,  3 }, /* imm3_15: general immediate in bits [17:15].  */
354
    {  0,  4 }, /* imm4_0: in rmif instructions.  */
355
    {  5,  4 }, /* imm4_5: in SME instructions.  */
356
    { 10,  4 }, /* imm4_10: in adddg/subg instructions.  */
357
    { 11,  4 }, /* imm4_11: in advsimd ext and advsimd ins instructions.  */
358
    { 14,  4 }, /* imm4_14: general immediate in bits [17:14].  */
359
    { 16,  5 }, /* imm5: in conditional compare (immediate) instructions.  */
360
    { 10,  6 }, /* imm6_10: in add/sub reg shifted instructions.  */
361
    { 15,  6 }, /* imm6_15: in rmif instructions.  */
362
    { 15,  7 }, /* imm7: in load/store pair pre/post index instructions.  */
363
    { 13,  8 }, /* imm8: in floating-point scalar move immediate inst.  */
364
    { 12,  9 }, /* imm9: in load/store pre/post index instructions.  */
365
    { 10, 12 }, /* imm12: in ld/st unsigned imm or add/sub shifted inst.  */
366
    {  5, 14 }, /* imm14: in test bit and branch instructions.  */
367
    {  0, 16 }, /* imm16_0: in udf instruction. */
368
    {  5, 16 }, /* imm16_5: in exception instructions.  */
369
    {  5, 19 }, /* imm19: e.g. in CBZ.  */
370
    {  0, 26 }, /* imm26: in unconditional branch instructions.  */
371
    { 16,  3 }, /* immb: in advsimd shift by immediate instructions.  */
372
    { 19,  4 }, /* immh: in advsimd shift by immediate instructions.  */
373
    {  5, 19 }, /* immhi: e.g. in ADRP.  */
374
    { 29,  2 }, /* immlo: e.g. in ADRP.  */
375
    { 16,  6 }, /* immr: in bitfield and logical immediate instructions.  */
376
    { 10,  6 }, /* imms: in bitfield and logical immediate instructions.  */
377
    { 11,  1 }, /* index: in ld/st inst deciding the pre/post-index.  */
378
    { 24,  1 }, /* index2: in ld/st pair inst deciding the pre/post-index.  */
379
    { 30,  2 }, /* ldst_size: size field in ld/st reg offset inst.  */
380
    { 13,  2 }, /* len: in advsimd tbl/tbx instructions.  */
381
    { 30,  1 }, /* lse_sz: in LSE extension atomic instructions.  */
382
    {  0,  4 }, /* nzcv: flag bit specifier, encoded in the "nzcv" field.  */
383
    { 29,  1 }, /* op: in AdvSIMD modified immediate instructions.  */
384
    { 19,  2 }, /* op0: in the system instructions.  */
385
    { 16,  3 }, /* op1: in the system instructions.  */
386
    {  5,  3 }, /* op2: in the system instructions.  */
387
    { 22,  2 }, /* opc: in load/store reg offset instructions.  */
388
    { 23,  1 }, /* opc1: in load/store reg offset instructions.  */
389
    { 12,  4 }, /* opcode: in advsimd load/store instructions.  */
390
    { 13,  3 }, /* option: in ld/st reg offset + add/sub extended reg inst.  */
391
    { 11,  2 }, /* rotate1: FCMLA immediate rotate.  */
392
    { 13,  2 }, /* rotate2: Indexed element FCMLA immediate rotate.  */
393
    { 12,  1 }, /* rotate3: FCADD immediate rotate.  */
394
    { 10,  6 }, /* scale: in the fixed-point scalar to fp converting inst.  */
395
    { 31,  1 }, /* sf: in integer data processing instructions.  */
396
    { 22,  2 }, /* shift: in add/sub reg/imm shifted instructions.  */
397
    { 22,  2 }, /* size: in most AdvSIMD and floating-point instructions.  */
398
    { 22,  1 }, /* sz: 1-bit element size select.  */
399
    { 22,  2 }, /* type: floating point type field in fp data inst.  */
400
    { 10,  2 }, /* vldst_size: size field in the AdvSIMD load/store inst.  */
401
};
402
403
enum aarch64_operand_class
404
aarch64_get_operand_class (enum aarch64_opnd type)
405
0
{
406
0
  return aarch64_operands[type].op_class;
407
0
}
408
409
const char *
410
aarch64_get_operand_name (enum aarch64_opnd type)
411
0
{
412
0
  return aarch64_operands[type].name;
413
0
}
414
415
/* Get operand description string.
416
   This is usually for the diagnosis purpose.  */
417
const char *
418
aarch64_get_operand_desc (enum aarch64_opnd type)
419
0
{
420
0
  return aarch64_operands[type].desc;
421
0
}
422
423
/* Table of all conditional affixes.  */
424
const aarch64_cond aarch64_conds[16] =
425
{
426
  {{"eq", "none"}, 0x0},
427
  {{"ne", "any"}, 0x1},
428
  {{"cs", "hs", "nlast"}, 0x2},
429
  {{"cc", "lo", "ul", "last"}, 0x3},
430
  {{"mi", "first"}, 0x4},
431
  {{"pl", "nfrst"}, 0x5},
432
  {{"vs"}, 0x6},
433
  {{"vc"}, 0x7},
434
  {{"hi", "pmore"}, 0x8},
435
  {{"ls", "plast"}, 0x9},
436
  {{"ge", "tcont"}, 0xa},
437
  {{"lt", "tstop"}, 0xb},
438
  {{"gt"}, 0xc},
439
  {{"le"}, 0xd},
440
  {{"al"}, 0xe},
441
  {{"nv"}, 0xf},
442
};
443
444
const aarch64_cond *
445
get_cond_from_value (aarch64_insn value)
446
0
{
447
0
  assert (value < 16);
448
0
  return &aarch64_conds[(unsigned int) value];
449
0
}
450
451
const aarch64_cond *
452
get_inverted_cond (const aarch64_cond *cond)
453
0
{
454
0
  return &aarch64_conds[cond->value ^ 0x1];
455
0
}
456
457
/* Table describing the operand extension/shifting operators; indexed by
458
   enum aarch64_modifier_kind.
459
460
   The value column provides the most common values for encoding modifiers,
461
   which enables table-driven encoding/decoding for the modifiers.  */
462
const struct aarch64_name_value_pair aarch64_operand_modifiers [] =
463
{
464
    {"none", 0x0},
465
    {"msl",  0x0},
466
    {"ror",  0x3},
467
    {"asr",  0x2},
468
    {"lsr",  0x1},
469
    {"lsl",  0x0},
470
    {"uxtb", 0x0},
471
    {"uxth", 0x1},
472
    {"uxtw", 0x2},
473
    {"uxtx", 0x3},
474
    {"sxtb", 0x4},
475
    {"sxth", 0x5},
476
    {"sxtw", 0x6},
477
    {"sxtx", 0x7},
478
    {"mul", 0x0},
479
    {"mul vl", 0x0},
480
    {NULL, 0},
481
};
482
483
enum aarch64_modifier_kind
484
aarch64_get_operand_modifier (const struct aarch64_name_value_pair *desc)
485
0
{
486
0
  return desc - aarch64_operand_modifiers;
487
0
}
488
489
aarch64_insn
490
aarch64_get_operand_modifier_value (enum aarch64_modifier_kind kind)
491
0
{
492
0
  return aarch64_operand_modifiers[kind].value;
493
0
}
494
495
enum aarch64_modifier_kind
496
aarch64_get_operand_modifier_from_value (aarch64_insn value,
497
           bool extend_p)
498
0
{
499
0
  if (extend_p)
500
0
    return AARCH64_MOD_UXTB + value;
501
0
  else
502
0
    return AARCH64_MOD_LSL - value;
503
0
}
504
505
bool
506
aarch64_extend_operator_p (enum aarch64_modifier_kind kind)
507
0
{
508
0
  return kind > AARCH64_MOD_LSL && kind <= AARCH64_MOD_SXTX;
509
0
}
510
511
static inline bool
512
aarch64_shift_operator_p (enum aarch64_modifier_kind kind)
513
0
{
514
0
  return kind >= AARCH64_MOD_ROR && kind <= AARCH64_MOD_LSL;
515
0
}
516
517
const struct aarch64_name_value_pair aarch64_barrier_options[16] =
518
{
519
    { "#0x00", 0x0 },
520
    { "oshld", 0x1 },
521
    { "oshst", 0x2 },
522
    { "osh",   0x3 },
523
    { "#0x04", 0x4 },
524
    { "nshld", 0x5 },
525
    { "nshst", 0x6 },
526
    { "nsh",   0x7 },
527
    { "#0x08", 0x8 },
528
    { "ishld", 0x9 },
529
    { "ishst", 0xa },
530
    { "ish",   0xb },
531
    { "#0x0c", 0xc },
532
    { "ld",    0xd },
533
    { "st",    0xe },
534
    { "sy",    0xf },
535
};
536
537
const struct aarch64_name_value_pair aarch64_barrier_dsb_nxs_options[4] =
538
{                       /*  CRm<3:2>  #imm  */
539
    { "oshnxs", 16 },    /*    00       16   */
540
    { "nshnxs", 20 },    /*    01       20   */
541
    { "ishnxs", 24 },    /*    10       24   */
542
    { "synxs",  28 },    /*    11       28   */
543
};
544
545
/* Table describing the operands supported by the aliases of the HINT
546
   instruction.
547
548
   The name column is the operand that is accepted for the alias.  The value
549
   column is the hint number of the alias.  The list of operands is terminated
550
   by NULL in the name column.  */
551
552
const struct aarch64_name_value_pair aarch64_hint_options[] =
553
{
554
  /* BTI.  This is also the F_DEFAULT entry for AARCH64_OPND_BTI_TARGET.  */
555
  { " ",  HINT_ENCODE (HINT_OPD_F_NOPRINT, 0x20) },
556
  { "csync",  HINT_OPD_CSYNC }, /* PSB CSYNC.  */
557
  { "c",  HINT_OPD_C },   /* BTI C.  */
558
  { "j",  HINT_OPD_J },   /* BTI J.  */
559
  { "jc", HINT_OPD_JC },    /* BTI JC.  */
560
  { NULL, HINT_OPD_NULL },
561
};
562
563
/* op -> op:       load = 0 instruction = 1 store = 2
564
   l  -> level:    1-3
565
   t  -> temporal: temporal (retained) = 0 non-temporal (streaming) = 1   */
566
#define B(op,l,t) (((op) << 3) | (((l) - 1) << 1) | (t))
567
const struct aarch64_name_value_pair aarch64_prfops[32] =
568
{
569
  { "pldl1keep", B(0, 1, 0) },
570
  { "pldl1strm", B(0, 1, 1) },
571
  { "pldl2keep", B(0, 2, 0) },
572
  { "pldl2strm", B(0, 2, 1) },
573
  { "pldl3keep", B(0, 3, 0) },
574
  { "pldl3strm", B(0, 3, 1) },
575
  { NULL, 0x06 },
576
  { NULL, 0x07 },
577
  { "plil1keep", B(1, 1, 0) },
578
  { "plil1strm", B(1, 1, 1) },
579
  { "plil2keep", B(1, 2, 0) },
580
  { "plil2strm", B(1, 2, 1) },
581
  { "plil3keep", B(1, 3, 0) },
582
  { "plil3strm", B(1, 3, 1) },
583
  { NULL, 0x0e },
584
  { NULL, 0x0f },
585
  { "pstl1keep", B(2, 1, 0) },
586
  { "pstl1strm", B(2, 1, 1) },
587
  { "pstl2keep", B(2, 2, 0) },
588
  { "pstl2strm", B(2, 2, 1) },
589
  { "pstl3keep", B(2, 3, 0) },
590
  { "pstl3strm", B(2, 3, 1) },
591
  { NULL, 0x16 },
592
  { NULL, 0x17 },
593
  { NULL, 0x18 },
594
  { NULL, 0x19 },
595
  { NULL, 0x1a },
596
  { NULL, 0x1b },
597
  { NULL, 0x1c },
598
  { NULL, 0x1d },
599
  { NULL, 0x1e },
600
  { NULL, 0x1f },
601
};
602
#undef B
603

604
/* Utilities on value constraint.  */
605
606
static inline int
607
value_in_range_p (int64_t value, int low, int high)
608
0
{
609
0
  return (value >= low && value <= high) ? 1 : 0;
610
0
}
611
612
/* Return true if VALUE is a multiple of ALIGN.  */
613
static inline int
614
value_aligned_p (int64_t value, int align)
615
0
{
616
0
  return (value % align) == 0;
617
0
}
618
619
/* A signed value fits in a field.  */
620
static inline int
621
value_fit_signed_field_p (int64_t value, unsigned width)
622
0
{
623
0
  assert (width < 32);
624
0
  if (width < sizeof (value) * 8)
625
0
    {
626
0
      int64_t lim = (uint64_t) 1 << (width - 1);
627
0
      if (value >= -lim && value < lim)
628
0
  return 1;
629
0
    }
630
0
  return 0;
631
0
}
632
633
/* An unsigned value fits in a field.  */
634
static inline int
635
value_fit_unsigned_field_p (int64_t value, unsigned width)
636
0
{
637
0
  assert (width < 32);
638
0
  if (width < sizeof (value) * 8)
639
0
    {
640
0
      int64_t lim = (uint64_t) 1 << width;
641
0
      if (value >= 0 && value < lim)
642
0
  return 1;
643
0
    }
644
0
  return 0;
645
0
}
646
647
/* Return 1 if OPERAND is SP or WSP.  */
648
int
649
aarch64_stack_pointer_p (const aarch64_opnd_info *operand)
650
0
{
651
0
  return ((aarch64_get_operand_class (operand->type)
652
0
     == AARCH64_OPND_CLASS_INT_REG)
653
0
    && operand_maybe_stack_pointer (aarch64_operands + operand->type)
654
0
    && operand->reg.regno == 31);
655
0
}
656
657
/* Return 1 if OPERAND is XZR or WZP.  */
658
int
659
aarch64_zero_register_p (const aarch64_opnd_info *operand)
660
0
{
661
0
  return ((aarch64_get_operand_class (operand->type)
662
0
     == AARCH64_OPND_CLASS_INT_REG)
663
0
    && !operand_maybe_stack_pointer (aarch64_operands + operand->type)
664
0
    && operand->reg.regno == 31);
665
0
}
666
667
/* Return true if the operand *OPERAND that has the operand code
668
   OPERAND->TYPE and been qualified by OPERAND->QUALIFIER can be also
669
   qualified by the qualifier TARGET.  */
670
671
static inline int
672
operand_also_qualified_p (const struct aarch64_opnd_info *operand,
673
        aarch64_opnd_qualifier_t target)
674
0
{
675
0
  switch (operand->qualifier)
676
0
    {
677
0
    case AARCH64_OPND_QLF_W:
678
0
      if (target == AARCH64_OPND_QLF_WSP && aarch64_stack_pointer_p (operand))
679
0
  return 1;
680
0
      break;
681
0
    case AARCH64_OPND_QLF_X:
682
0
      if (target == AARCH64_OPND_QLF_SP && aarch64_stack_pointer_p (operand))
683
0
  return 1;
684
0
      break;
685
0
    case AARCH64_OPND_QLF_WSP:
686
0
      if (target == AARCH64_OPND_QLF_W
687
0
    && operand_maybe_stack_pointer (aarch64_operands + operand->type))
688
0
  return 1;
689
0
      break;
690
0
    case AARCH64_OPND_QLF_SP:
691
0
      if (target == AARCH64_OPND_QLF_X
692
0
    && operand_maybe_stack_pointer (aarch64_operands + operand->type))
693
0
  return 1;
694
0
      break;
695
0
    default:
696
0
      break;
697
0
    }
698
699
0
  return 0;
700
0
}
701
702
/* Given qualifier sequence list QSEQ_LIST and the known qualifier KNOWN_QLF
703
   for operand KNOWN_IDX, return the expected qualifier for operand IDX.
704
705
   Return NIL if more than one expected qualifiers are found.  */
706
707
aarch64_opnd_qualifier_t
708
aarch64_get_expected_qualifier (const aarch64_opnd_qualifier_seq_t *qseq_list,
709
        int idx,
710
        const aarch64_opnd_qualifier_t known_qlf,
711
        int known_idx)
712
0
{
713
0
  int i, saved_i;
714
715
  /* Special case.
716
717
     When the known qualifier is NIL, we have to assume that there is only
718
     one qualifier sequence in the *QSEQ_LIST and return the corresponding
719
     qualifier directly.  One scenario is that for instruction
720
  PRFM <prfop>, [<Xn|SP>, #:lo12:<symbol>]
721
     which has only one possible valid qualifier sequence
722
  NIL, S_D
723
     the caller may pass NIL in KNOWN_QLF to obtain S_D so that it can
724
     determine the correct relocation type (i.e. LDST64_LO12) for PRFM.
725
726
     Because the qualifier NIL has dual roles in the qualifier sequence:
727
     it can mean no qualifier for the operand, or the qualifer sequence is
728
     not in use (when all qualifiers in the sequence are NILs), we have to
729
     handle this special case here.  */
730
0
  if (known_qlf == AARCH64_OPND_NIL)
731
0
    {
732
0
      assert (qseq_list[0][known_idx] == AARCH64_OPND_NIL);
733
0
      return qseq_list[0][idx];
734
0
    }
735
736
0
  for (i = 0, saved_i = -1; i < AARCH64_MAX_QLF_SEQ_NUM; ++i)
737
0
    {
738
0
      if (qseq_list[i][known_idx] == known_qlf)
739
0
  {
740
0
    if (saved_i != -1)
741
      /* More than one sequences are found to have KNOWN_QLF at
742
         KNOWN_IDX.  */
743
0
      return AARCH64_OPND_NIL;
744
0
    saved_i = i;
745
0
  }
746
0
    }
747
748
0
  return qseq_list[saved_i][idx];
749
0
}
750
751
enum operand_qualifier_kind
752
{
753
  OQK_NIL,
754
  OQK_OPD_VARIANT,
755
  OQK_VALUE_IN_RANGE,
756
  OQK_MISC,
757
};
758
759
/* Operand qualifier description.  */
760
struct operand_qualifier_data
761
{
762
  /* The usage of the three data fields depends on the qualifier kind.  */
763
  int data0;
764
  int data1;
765
  int data2;
766
  /* Description.  */
767
  const char *desc;
768
  /* Kind.  */
769
  enum operand_qualifier_kind kind;
770
};
771
772
/* Indexed by the operand qualifier enumerators.  */
773
struct operand_qualifier_data aarch64_opnd_qualifiers[] =
774
{
775
  {0, 0, 0, "NIL", OQK_NIL},
776
777
  /* Operand variant qualifiers.
778
     First 3 fields:
779
     element size, number of elements and common value for encoding.  */
780
781
  {4, 1, 0x0, "w", OQK_OPD_VARIANT},
782
  {8, 1, 0x1, "x", OQK_OPD_VARIANT},
783
  {4, 1, 0x0, "wsp", OQK_OPD_VARIANT},
784
  {8, 1, 0x1, "sp", OQK_OPD_VARIANT},
785
786
  {1, 1, 0x0, "b", OQK_OPD_VARIANT},
787
  {2, 1, 0x1, "h", OQK_OPD_VARIANT},
788
  {4, 1, 0x2, "s", OQK_OPD_VARIANT},
789
  {8, 1, 0x3, "d", OQK_OPD_VARIANT},
790
  {16, 1, 0x4, "q", OQK_OPD_VARIANT},
791
  {4, 1, 0x0, "4b", OQK_OPD_VARIANT},
792
  {4, 1, 0x0, "2h", OQK_OPD_VARIANT},
793
794
  {1, 4, 0x0, "4b", OQK_OPD_VARIANT},
795
  {1, 8, 0x0, "8b", OQK_OPD_VARIANT},
796
  {1, 16, 0x1, "16b", OQK_OPD_VARIANT},
797
  {2, 2, 0x0, "2h", OQK_OPD_VARIANT},
798
  {2, 4, 0x2, "4h", OQK_OPD_VARIANT},
799
  {2, 8, 0x3, "8h", OQK_OPD_VARIANT},
800
  {4, 2, 0x4, "2s", OQK_OPD_VARIANT},
801
  {4, 4, 0x5, "4s", OQK_OPD_VARIANT},
802
  {8, 1, 0x6, "1d", OQK_OPD_VARIANT},
803
  {8, 2, 0x7, "2d", OQK_OPD_VARIANT},
804
  {16, 1, 0x8, "1q", OQK_OPD_VARIANT},
805
806
  {0, 0, 0, "z", OQK_OPD_VARIANT},
807
  {0, 0, 0, "m", OQK_OPD_VARIANT},
808
809
  /* Qualifier for scaled immediate for Tag granule (stg,st2g,etc).  */
810
  {16, 0, 0, "tag", OQK_OPD_VARIANT},
811
812
  /* Qualifiers constraining the value range.
813
     First 3 fields:
814
     Lower bound, higher bound, unused.  */
815
816
  {0, 15, 0, "CR",       OQK_VALUE_IN_RANGE},
817
  {0,  7, 0, "imm_0_7" , OQK_VALUE_IN_RANGE},
818
  {0, 15, 0, "imm_0_15", OQK_VALUE_IN_RANGE},
819
  {0, 31, 0, "imm_0_31", OQK_VALUE_IN_RANGE},
820
  {0, 63, 0, "imm_0_63", OQK_VALUE_IN_RANGE},
821
  {1, 32, 0, "imm_1_32", OQK_VALUE_IN_RANGE},
822
  {1, 64, 0, "imm_1_64", OQK_VALUE_IN_RANGE},
823
824
  /* Qualifiers for miscellaneous purpose.
825
     First 3 fields:
826
     unused, unused and unused.  */
827
828
  {0, 0, 0, "lsl", 0},
829
  {0, 0, 0, "msl", 0},
830
831
  {0, 0, 0, "retrieving", 0},
832
};
833
834
static inline bool
835
operand_variant_qualifier_p (aarch64_opnd_qualifier_t qualifier)
836
0
{
837
0
  return aarch64_opnd_qualifiers[qualifier].kind == OQK_OPD_VARIANT;
838
0
}
839
840
static inline bool
841
qualifier_value_in_range_constraint_p (aarch64_opnd_qualifier_t qualifier)
842
0
{
843
0
  return aarch64_opnd_qualifiers[qualifier].kind == OQK_VALUE_IN_RANGE;
844
0
}
845
846
const char*
847
aarch64_get_qualifier_name (aarch64_opnd_qualifier_t qualifier)
848
0
{
849
0
  return aarch64_opnd_qualifiers[qualifier].desc;
850
0
}
851
852
/* Given an operand qualifier, return the expected data element size
853
   of a qualified operand.  */
854
unsigned char
855
aarch64_get_qualifier_esize (aarch64_opnd_qualifier_t qualifier)
856
0
{
857
0
  assert (operand_variant_qualifier_p (qualifier));
858
0
  return aarch64_opnd_qualifiers[qualifier].data0;
859
0
}
860
861
unsigned char
862
aarch64_get_qualifier_nelem (aarch64_opnd_qualifier_t qualifier)
863
0
{
864
0
  assert (operand_variant_qualifier_p (qualifier));
865
0
  return aarch64_opnd_qualifiers[qualifier].data1;
866
0
}
867
868
aarch64_insn
869
aarch64_get_qualifier_standard_value (aarch64_opnd_qualifier_t qualifier)
870
0
{
871
0
  assert (operand_variant_qualifier_p (qualifier));
872
0
  return aarch64_opnd_qualifiers[qualifier].data2;
873
0
}
874
875
static int
876
get_lower_bound (aarch64_opnd_qualifier_t qualifier)
877
0
{
878
0
  assert (qualifier_value_in_range_constraint_p (qualifier));
879
0
  return aarch64_opnd_qualifiers[qualifier].data0;
880
0
}
881
882
static int
883
get_upper_bound (aarch64_opnd_qualifier_t qualifier)
884
0
{
885
0
  assert (qualifier_value_in_range_constraint_p (qualifier));
886
0
  return aarch64_opnd_qualifiers[qualifier].data1;
887
0
}
888
889
#ifdef DEBUG_AARCH64
890
void
891
aarch64_verbose (const char *str, ...)
892
{
893
  va_list ap;
894
  va_start (ap, str);
895
  printf ("#### ");
896
  vprintf (str, ap);
897
  printf ("\n");
898
  va_end (ap);
899
}
900
901
static inline void
902
dump_qualifier_sequence (const aarch64_opnd_qualifier_t *qualifier)
903
{
904
  int i;
905
  printf ("#### \t");
906
  for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i, ++qualifier)
907
    printf ("%s,", aarch64_get_qualifier_name (*qualifier));
908
  printf ("\n");
909
}
910
911
static void
912
dump_match_qualifiers (const struct aarch64_opnd_info *opnd,
913
           const aarch64_opnd_qualifier_t *qualifier)
914
{
915
  int i;
916
  aarch64_opnd_qualifier_t curr[AARCH64_MAX_OPND_NUM];
917
918
  aarch64_verbose ("dump_match_qualifiers:");
919
  for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
920
    curr[i] = opnd[i].qualifier;
921
  dump_qualifier_sequence (curr);
922
  aarch64_verbose ("against");
923
  dump_qualifier_sequence (qualifier);
924
}
925
#endif /* DEBUG_AARCH64 */
926
927
/* This function checks if the given instruction INSN is a destructive
928
   instruction based on the usage of the registers.  It does not recognize
929
   unary destructive instructions.  */
930
bool
931
aarch64_is_destructive_by_operands (const aarch64_opcode *opcode)
932
0
{
933
0
  int i = 0;
934
0
  const enum aarch64_opnd *opnds = opcode->operands;
935
936
0
  if (opnds[0] == AARCH64_OPND_NIL)
937
0
    return false;
938
939
0
  while (opnds[++i] != AARCH64_OPND_NIL)
940
0
    if (opnds[i] == opnds[0])
941
0
      return true;
942
943
0
  return false;
944
0
}
945
946
/* TODO improve this, we can have an extra field at the runtime to
947
   store the number of operands rather than calculating it every time.  */
948
949
int
950
aarch64_num_of_operands (const aarch64_opcode *opcode)
951
0
{
952
0
  int i = 0;
953
0
  const enum aarch64_opnd *opnds = opcode->operands;
954
0
  while (opnds[i++] != AARCH64_OPND_NIL)
955
0
    ;
956
0
  --i;
957
0
  assert (i >= 0 && i <= AARCH64_MAX_OPND_NUM);
958
0
  return i;
959
0
}
960
961
/* Find the best matched qualifier sequence in *QUALIFIERS_LIST for INST.
962
   If succeeds, fill the found sequence in *RET, return 1; otherwise return 0.
963
964
   Store the smallest number of non-matching qualifiers in *INVALID_COUNT.
965
   This is always 0 if the function succeeds.
966
967
   N.B. on the entry, it is very likely that only some operands in *INST
968
   have had their qualifiers been established.
969
970
   If STOP_AT is not -1, the function will only try to match
971
   the qualifier sequence for operands before and including the operand
972
   of index STOP_AT; and on success *RET will only be filled with the first
973
   (STOP_AT+1) qualifiers.
974
975
   A couple examples of the matching algorithm:
976
977
   X,W,NIL should match
978
   X,W,NIL
979
980
   NIL,NIL should match
981
   X  ,NIL
982
983
   Apart from serving the main encoding routine, this can also be called
984
   during or after the operand decoding.  */
985
986
int
987
aarch64_find_best_match (const aarch64_inst *inst,
988
       const aarch64_opnd_qualifier_seq_t *qualifiers_list,
989
       int stop_at, aarch64_opnd_qualifier_t *ret,
990
       int *invalid_count)
991
0
{
992
0
  int i, num_opnds, invalid, min_invalid;
993
0
  const aarch64_opnd_qualifier_t *qualifiers;
994
995
0
  num_opnds = aarch64_num_of_operands (inst->opcode);
996
0
  if (num_opnds == 0)
997
0
    {
998
0
      DEBUG_TRACE ("SUCCEED: no operand");
999
0
      *invalid_count = 0;
1000
0
      return 1;
1001
0
    }
1002
1003
0
  if (stop_at < 0 || stop_at >= num_opnds)
1004
0
    stop_at = num_opnds - 1;
1005
1006
  /* For each pattern.  */
1007
0
  min_invalid = num_opnds;
1008
0
  for (i = 0; i < AARCH64_MAX_QLF_SEQ_NUM; ++i, ++qualifiers_list)
1009
0
    {
1010
0
      int j;
1011
0
      qualifiers = *qualifiers_list;
1012
1013
      /* Start as positive.  */
1014
0
      invalid = 0;
1015
1016
0
      DEBUG_TRACE ("%d", i);
1017
#ifdef DEBUG_AARCH64
1018
      if (debug_dump)
1019
  dump_match_qualifiers (inst->operands, qualifiers);
1020
#endif
1021
1022
      /* The first entry should be taken literally, even if it's an empty
1023
   qualifier sequence.  (This matters for strict testing.)  In other
1024
   positions an empty sequence acts as a terminator.  */
1025
0
      if (i > 0 && empty_qualifier_sequence_p (qualifiers))
1026
0
  break;
1027
1028
0
      for (j = 0; j < num_opnds && j <= stop_at; ++j, ++qualifiers)
1029
0
  {
1030
0
    if (inst->operands[j].qualifier == AARCH64_OPND_QLF_NIL
1031
0
        && !(inst->opcode->flags & F_STRICT))
1032
0
      {
1033
        /* Either the operand does not have qualifier, or the qualifier
1034
     for the operand needs to be deduced from the qualifier
1035
     sequence.
1036
     In the latter case, any constraint checking related with
1037
     the obtained qualifier should be done later in
1038
     operand_general_constraint_met_p.  */
1039
0
        continue;
1040
0
      }
1041
0
    else if (*qualifiers != inst->operands[j].qualifier)
1042
0
      {
1043
        /* Unless the target qualifier can also qualify the operand
1044
     (which has already had a non-nil qualifier), non-equal
1045
     qualifiers are generally un-matched.  */
1046
0
        if (operand_also_qualified_p (inst->operands + j, *qualifiers))
1047
0
    continue;
1048
0
        else
1049
0
    invalid += 1;
1050
0
      }
1051
0
    else
1052
0
      continue; /* Equal qualifiers are certainly matched.  */
1053
0
  }
1054
1055
0
      if (min_invalid > invalid)
1056
0
  min_invalid = invalid;
1057
1058
      /* Qualifiers established.  */
1059
0
      if (min_invalid == 0)
1060
0
  break;
1061
0
    }
1062
1063
0
  *invalid_count = min_invalid;
1064
0
  if (min_invalid == 0)
1065
0
    {
1066
      /* Fill the result in *RET.  */
1067
0
      int j;
1068
0
      qualifiers = *qualifiers_list;
1069
1070
0
      DEBUG_TRACE ("complete qualifiers using list %d", i);
1071
#ifdef DEBUG_AARCH64
1072
      if (debug_dump)
1073
  dump_qualifier_sequence (qualifiers);
1074
#endif
1075
1076
0
      for (j = 0; j <= stop_at; ++j, ++qualifiers)
1077
0
  ret[j] = *qualifiers;
1078
0
      for (; j < AARCH64_MAX_OPND_NUM; ++j)
1079
0
  ret[j] = AARCH64_OPND_QLF_NIL;
1080
1081
0
      DEBUG_TRACE ("SUCCESS");
1082
0
      return 1;
1083
0
    }
1084
1085
0
  DEBUG_TRACE ("FAIL");
1086
0
  return 0;
1087
0
}
1088
1089
/* Operand qualifier matching and resolving.
1090
1091
   Return 1 if the operand qualifier(s) in *INST match one of the qualifier
1092
   sequences in INST->OPCODE->qualifiers_list; otherwise return 0.
1093
1094
   Store the smallest number of non-matching qualifiers in *INVALID_COUNT.
1095
   This is always 0 if the function succeeds.
1096
1097
   if UPDATE_P, update the qualifier(s) in *INST after the matching
1098
   succeeds.  */
1099
1100
static int
1101
match_operands_qualifier (aarch64_inst *inst, bool update_p,
1102
        int *invalid_count)
1103
0
{
1104
0
  int i;
1105
0
  aarch64_opnd_qualifier_seq_t qualifiers;
1106
1107
0
  if (!aarch64_find_best_match (inst, inst->opcode->qualifiers_list, -1,
1108
0
        qualifiers, invalid_count))
1109
0
    {
1110
0
      DEBUG_TRACE ("matching FAIL");
1111
0
      return 0;
1112
0
    }
1113
1114
  /* Update the qualifiers.  */
1115
0
  if (update_p)
1116
0
    for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
1117
0
      {
1118
0
  if (inst->opcode->operands[i] == AARCH64_OPND_NIL)
1119
0
    break;
1120
0
  DEBUG_TRACE_IF (inst->operands[i].qualifier != qualifiers[i],
1121
0
      "update %s with %s for operand %d",
1122
0
      aarch64_get_qualifier_name (inst->operands[i].qualifier),
1123
0
      aarch64_get_qualifier_name (qualifiers[i]), i);
1124
0
  inst->operands[i].qualifier = qualifiers[i];
1125
0
      }
1126
1127
0
  DEBUG_TRACE ("matching SUCCESS");
1128
0
  return 1;
1129
0
}
1130
1131
/* Return TRUE if VALUE is a wide constant that can be moved into a general
1132
   register by MOVZ.
1133
1134
   IS32 indicates whether value is a 32-bit immediate or not.
1135
   If SHIFT_AMOUNT is not NULL, on the return of TRUE, the logical left shift
1136
   amount will be returned in *SHIFT_AMOUNT.  */
1137
1138
bool
1139
aarch64_wide_constant_p (uint64_t value, int is32, unsigned int *shift_amount)
1140
0
{
1141
0
  int amount;
1142
1143
0
  DEBUG_TRACE ("enter with 0x%" PRIx64 "(%" PRIi64 ")", value, value);
1144
1145
0
  if (is32)
1146
0
    {
1147
      /* Allow all zeros or all ones in top 32-bits, so that
1148
   32-bit constant expressions like ~0x80000000 are
1149
   permitted.  */
1150
0
      if (value >> 32 != 0 && value >> 32 != 0xffffffff)
1151
  /* Immediate out of range.  */
1152
0
  return false;
1153
0
      value &= 0xffffffff;
1154
0
    }
1155
1156
  /* first, try movz then movn */
1157
0
  amount = -1;
1158
0
  if ((value & ((uint64_t) 0xffff << 0)) == value)
1159
0
    amount = 0;
1160
0
  else if ((value & ((uint64_t) 0xffff << 16)) == value)
1161
0
    amount = 16;
1162
0
  else if (!is32 && (value & ((uint64_t) 0xffff << 32)) == value)
1163
0
    amount = 32;
1164
0
  else if (!is32 && (value & ((uint64_t) 0xffff << 48)) == value)
1165
0
    amount = 48;
1166
1167
0
  if (amount == -1)
1168
0
    {
1169
0
      DEBUG_TRACE ("exit false with 0x%" PRIx64 "(%" PRIi64 ")", value, value);
1170
0
      return false;
1171
0
    }
1172
1173
0
  if (shift_amount != NULL)
1174
0
    *shift_amount = amount;
1175
1176
0
  DEBUG_TRACE ("exit true with amount %d", amount);
1177
1178
0
  return true;
1179
0
}
1180
1181
/* Build the accepted values for immediate logical SIMD instructions.
1182
1183
   The standard encodings of the immediate value are:
1184
     N      imms     immr         SIMD size  R             S
1185
     1      ssssss   rrrrrr       64      UInt(rrrrrr)  UInt(ssssss)
1186
     0      0sssss   0rrrrr       32      UInt(rrrrr)   UInt(sssss)
1187
     0      10ssss   00rrrr       16      UInt(rrrr)    UInt(ssss)
1188
     0      110sss   000rrr       8       UInt(rrr)     UInt(sss)
1189
     0      1110ss   0000rr       4       UInt(rr)      UInt(ss)
1190
     0      11110s   00000r       2       UInt(r)       UInt(s)
1191
   where all-ones value of S is reserved.
1192
1193
   Let's call E the SIMD size.
1194
1195
   The immediate value is: S+1 bits '1' rotated to the right by R.
1196
1197
   The total of valid encodings is 64*63 + 32*31 + ... + 2*1 = 5334
1198
   (remember S != E - 1).  */
1199
1200
0
#define TOTAL_IMM_NB  5334
1201
1202
typedef struct
1203
{
1204
  uint64_t imm;
1205
  aarch64_insn encoding;
1206
} simd_imm_encoding;
1207
1208
static simd_imm_encoding simd_immediates[TOTAL_IMM_NB];
1209
1210
static int
1211
simd_imm_encoding_cmp(const void *i1, const void *i2)
1212
0
{
1213
0
  const simd_imm_encoding *imm1 = (const simd_imm_encoding *)i1;
1214
0
  const simd_imm_encoding *imm2 = (const simd_imm_encoding *)i2;
1215
1216
0
  if (imm1->imm < imm2->imm)
1217
0
    return -1;
1218
0
  if (imm1->imm > imm2->imm)
1219
0
    return +1;
1220
0
  return 0;
1221
0
}
1222
1223
/* immediate bitfield standard encoding
1224
   imm13<12> imm13<5:0> imm13<11:6> SIMD size R      S
1225
   1         ssssss     rrrrrr      64        rrrrrr ssssss
1226
   0         0sssss     0rrrrr      32        rrrrr  sssss
1227
   0         10ssss     00rrrr      16        rrrr   ssss
1228
   0         110sss     000rrr      8         rrr    sss
1229
   0         1110ss     0000rr      4         rr     ss
1230
   0         11110s     00000r      2         r      s  */
1231
static inline int
1232
encode_immediate_bitfield (int is64, uint32_t s, uint32_t r)
1233
0
{
1234
0
  return (is64 << 12) | (r << 6) | s;
1235
0
}
1236
1237
static void
1238
build_immediate_table (void)
1239
0
{
1240
0
  uint32_t log_e, e, s, r, s_mask;
1241
0
  uint64_t mask, imm;
1242
0
  int nb_imms;
1243
0
  int is64;
1244
1245
0
  nb_imms = 0;
1246
0
  for (log_e = 1; log_e <= 6; log_e++)
1247
0
    {
1248
      /* Get element size.  */
1249
0
      e = 1u << log_e;
1250
0
      if (log_e == 6)
1251
0
  {
1252
0
    is64 = 1;
1253
0
    mask = 0xffffffffffffffffull;
1254
0
    s_mask = 0;
1255
0
  }
1256
0
      else
1257
0
  {
1258
0
    is64 = 0;
1259
0
    mask = (1ull << e) - 1;
1260
    /* log_e  s_mask
1261
       1     ((1 << 4) - 1) << 2 = 111100
1262
       2     ((1 << 3) - 1) << 3 = 111000
1263
       3     ((1 << 2) - 1) << 4 = 110000
1264
       4     ((1 << 1) - 1) << 5 = 100000
1265
       5     ((1 << 0) - 1) << 6 = 000000  */
1266
0
    s_mask = ((1u << (5 - log_e)) - 1) << (log_e + 1);
1267
0
  }
1268
0
      for (s = 0; s < e - 1; s++)
1269
0
  for (r = 0; r < e; r++)
1270
0
    {
1271
      /* s+1 consecutive bits to 1 (s < 63) */
1272
0
      imm = (1ull << (s + 1)) - 1;
1273
      /* rotate right by r */
1274
0
      if (r != 0)
1275
0
        imm = (imm >> r) | ((imm << (e - r)) & mask);
1276
      /* replicate the constant depending on SIMD size */
1277
0
      switch (log_e)
1278
0
        {
1279
0
        case 1: imm = (imm <<  2) | imm;
1280
    /* Fall through.  */
1281
0
        case 2: imm = (imm <<  4) | imm;
1282
    /* Fall through.  */
1283
0
        case 3: imm = (imm <<  8) | imm;
1284
    /* Fall through.  */
1285
0
        case 4: imm = (imm << 16) | imm;
1286
    /* Fall through.  */
1287
0
        case 5: imm = (imm << 32) | imm;
1288
    /* Fall through.  */
1289
0
        case 6: break;
1290
0
        default: abort ();
1291
0
        }
1292
0
      simd_immediates[nb_imms].imm = imm;
1293
0
      simd_immediates[nb_imms].encoding =
1294
0
        encode_immediate_bitfield(is64, s | s_mask, r);
1295
0
      nb_imms++;
1296
0
    }
1297
0
    }
1298
0
  assert (nb_imms == TOTAL_IMM_NB);
1299
0
  qsort(simd_immediates, nb_imms,
1300
0
  sizeof(simd_immediates[0]), simd_imm_encoding_cmp);
1301
0
}
1302
1303
/* Return TRUE if VALUE is a valid logical immediate, i.e. bitmask, that can
1304
   be accepted by logical (immediate) instructions
1305
   e.g. ORR <Xd|SP>, <Xn>, #<imm>.
1306
1307
   ESIZE is the number of bytes in the decoded immediate value.
1308
   If ENCODING is not NULL, on the return of TRUE, the standard encoding for
1309
   VALUE will be returned in *ENCODING.  */
1310
1311
bool
1312
aarch64_logical_immediate_p (uint64_t value, int esize, aarch64_insn *encoding)
1313
0
{
1314
0
  simd_imm_encoding imm_enc;
1315
0
  const simd_imm_encoding *imm_encoding;
1316
0
  static bool initialized = false;
1317
0
  uint64_t upper;
1318
0
  int i;
1319
1320
0
  DEBUG_TRACE ("enter with 0x%" PRIx64 "(%" PRIi64 "), esize: %d", value,
1321
0
         value, esize);
1322
1323
0
  if (!initialized)
1324
0
    {
1325
0
      build_immediate_table ();
1326
0
      initialized = true;
1327
0
    }
1328
1329
  /* Allow all zeros or all ones in top bits, so that
1330
     constant expressions like ~1 are permitted.  */
1331
0
  upper = (uint64_t) -1 << (esize * 4) << (esize * 4);
1332
0
  if ((value & ~upper) != value && (value | upper) != value)
1333
0
    return false;
1334
1335
  /* Replicate to a full 64-bit value.  */
1336
0
  value &= ~upper;
1337
0
  for (i = esize * 8; i < 64; i *= 2)
1338
0
    value |= (value << i);
1339
1340
0
  imm_enc.imm = value;
1341
0
  imm_encoding = (const simd_imm_encoding *)
1342
0
    bsearch(&imm_enc, simd_immediates, TOTAL_IMM_NB,
1343
0
            sizeof(simd_immediates[0]), simd_imm_encoding_cmp);
1344
0
  if (imm_encoding == NULL)
1345
0
    {
1346
0
      DEBUG_TRACE ("exit with false");
1347
0
      return false;
1348
0
    }
1349
0
  if (encoding != NULL)
1350
0
    *encoding = imm_encoding->encoding;
1351
0
  DEBUG_TRACE ("exit with true");
1352
0
  return true;
1353
0
}
1354
1355
/* If 64-bit immediate IMM is in the format of
1356
   "aaaaaaaabbbbbbbbccccccccddddddddeeeeeeeeffffffffgggggggghhhhhhhh",
1357
   where a, b, c, d, e, f, g and h are independently 0 or 1, return an integer
1358
   of value "abcdefgh".  Otherwise return -1.  */
1359
int
1360
aarch64_shrink_expanded_imm8 (uint64_t imm)
1361
0
{
1362
0
  int i, ret;
1363
0
  uint32_t byte;
1364
1365
0
  ret = 0;
1366
0
  for (i = 0; i < 8; i++)
1367
0
    {
1368
0
      byte = (imm >> (8 * i)) & 0xff;
1369
0
      if (byte == 0xff)
1370
0
  ret |= 1 << i;
1371
0
      else if (byte != 0x00)
1372
0
  return -1;
1373
0
    }
1374
0
  return ret;
1375
0
}
1376
1377
/* Utility inline functions for operand_general_constraint_met_p.  */
1378
1379
static inline void
1380
set_error (aarch64_operand_error *mismatch_detail,
1381
     enum aarch64_operand_error_kind kind, int idx,
1382
     const char* error)
1383
0
{
1384
0
  if (mismatch_detail == NULL)
1385
0
    return;
1386
0
  mismatch_detail->kind = kind;
1387
0
  mismatch_detail->index = idx;
1388
0
  mismatch_detail->error = error;
1389
0
}
1390
1391
static inline void
1392
set_syntax_error (aarch64_operand_error *mismatch_detail, int idx,
1393
      const char* error)
1394
0
{
1395
0
  if (mismatch_detail == NULL)
1396
0
    return;
1397
0
  set_error (mismatch_detail, AARCH64_OPDE_SYNTAX_ERROR, idx, error);
1398
0
}
1399
1400
static inline void
1401
set_invalid_regno_error (aarch64_operand_error *mismatch_detail, int idx,
1402
       const char *prefix, int lower_bound, int upper_bound)
1403
0
{
1404
0
  if (mismatch_detail == NULL)
1405
0
    return;
1406
0
  set_error (mismatch_detail, AARCH64_OPDE_INVALID_REGNO, idx, NULL);
1407
0
  mismatch_detail->data[0].s = prefix;
1408
0
  mismatch_detail->data[1].i = lower_bound;
1409
0
  mismatch_detail->data[2].i = upper_bound;
1410
0
}
1411
1412
static inline void
1413
set_out_of_range_error (aarch64_operand_error *mismatch_detail,
1414
      int idx, int lower_bound, int upper_bound,
1415
      const char* error)
1416
0
{
1417
0
  if (mismatch_detail == NULL)
1418
0
    return;
1419
0
  set_error (mismatch_detail, AARCH64_OPDE_OUT_OF_RANGE, idx, error);
1420
0
  mismatch_detail->data[0].i = lower_bound;
1421
0
  mismatch_detail->data[1].i = upper_bound;
1422
0
}
1423
1424
static inline void
1425
set_imm_out_of_range_error (aarch64_operand_error *mismatch_detail,
1426
          int idx, int lower_bound, int upper_bound)
1427
0
{
1428
0
  if (mismatch_detail == NULL)
1429
0
    return;
1430
0
  set_out_of_range_error (mismatch_detail, idx, lower_bound, upper_bound,
1431
0
        _("immediate value"));
1432
0
}
1433
1434
static inline void
1435
set_offset_out_of_range_error (aarch64_operand_error *mismatch_detail,
1436
             int idx, int lower_bound, int upper_bound)
1437
0
{
1438
0
  if (mismatch_detail == NULL)
1439
0
    return;
1440
0
  set_out_of_range_error (mismatch_detail, idx, lower_bound, upper_bound,
1441
0
        _("immediate offset"));
1442
0
}
1443
1444
static inline void
1445
set_regno_out_of_range_error (aarch64_operand_error *mismatch_detail,
1446
            int idx, int lower_bound, int upper_bound)
1447
0
{
1448
0
  if (mismatch_detail == NULL)
1449
0
    return;
1450
0
  set_out_of_range_error (mismatch_detail, idx, lower_bound, upper_bound,
1451
0
        _("register number"));
1452
0
}
1453
1454
static inline void
1455
set_elem_idx_out_of_range_error (aarch64_operand_error *mismatch_detail,
1456
         int idx, int lower_bound, int upper_bound)
1457
0
{
1458
0
  if (mismatch_detail == NULL)
1459
0
    return;
1460
0
  set_out_of_range_error (mismatch_detail, idx, lower_bound, upper_bound,
1461
0
        _("register element index"));
1462
0
}
1463
1464
static inline void
1465
set_sft_amount_out_of_range_error (aarch64_operand_error *mismatch_detail,
1466
           int idx, int lower_bound, int upper_bound)
1467
0
{
1468
0
  if (mismatch_detail == NULL)
1469
0
    return;
1470
0
  set_out_of_range_error (mismatch_detail, idx, lower_bound, upper_bound,
1471
0
        _("shift amount"));
1472
0
}
1473
1474
/* Report that the MUL modifier in operand IDX should be in the range
1475
   [LOWER_BOUND, UPPER_BOUND].  */
1476
static inline void
1477
set_multiplier_out_of_range_error (aarch64_operand_error *mismatch_detail,
1478
           int idx, int lower_bound, int upper_bound)
1479
0
{
1480
0
  if (mismatch_detail == NULL)
1481
0
    return;
1482
0
  set_out_of_range_error (mismatch_detail, idx, lower_bound, upper_bound,
1483
0
        _("multiplier"));
1484
0
}
1485
1486
static inline void
1487
set_unaligned_error (aarch64_operand_error *mismatch_detail, int idx,
1488
         int alignment)
1489
0
{
1490
0
  if (mismatch_detail == NULL)
1491
0
    return;
1492
0
  set_error (mismatch_detail, AARCH64_OPDE_UNALIGNED, idx, NULL);
1493
0
  mismatch_detail->data[0].i = alignment;
1494
0
}
1495
1496
static inline void
1497
set_reg_list_length_error (aarch64_operand_error *mismatch_detail, int idx,
1498
         int expected_num)
1499
0
{
1500
0
  if (mismatch_detail == NULL)
1501
0
    return;
1502
0
  set_error (mismatch_detail, AARCH64_OPDE_REG_LIST_LENGTH, idx, NULL);
1503
0
  mismatch_detail->data[0].i = 1 << expected_num;
1504
0
}
1505
1506
static inline void
1507
set_reg_list_stride_error (aarch64_operand_error *mismatch_detail, int idx,
1508
         int expected_num)
1509
0
{
1510
0
  if (mismatch_detail == NULL)
1511
0
    return;
1512
0
  set_error (mismatch_detail, AARCH64_OPDE_REG_LIST_STRIDE, idx, NULL);
1513
0
  mismatch_detail->data[0].i = 1 << expected_num;
1514
0
}
1515
1516
static inline void
1517
set_invalid_vg_size (aarch64_operand_error *mismatch_detail,
1518
         int idx, int expected)
1519
0
{
1520
0
  if (mismatch_detail == NULL)
1521
0
    return;
1522
0
  set_error (mismatch_detail, AARCH64_OPDE_INVALID_VG_SIZE, idx, NULL);
1523
0
  mismatch_detail->data[0].i = expected;
1524
0
}
1525
1526
static inline void
1527
set_other_error (aarch64_operand_error *mismatch_detail, int idx,
1528
     const char* error)
1529
0
{
1530
0
  if (mismatch_detail == NULL)
1531
0
    return;
1532
0
  set_error (mismatch_detail, AARCH64_OPDE_OTHER_ERROR, idx, error);
1533
0
}
1534
1535
/* Check that indexed register operand OPND has a register in the range
1536
   [MIN_REGNO, MAX_REGNO] and an index in the range [MIN_INDEX, MAX_INDEX].
1537
   PREFIX is the register prefix, such as "z" for SVE vector registers.  */
1538
1539
static bool
1540
check_reglane (const aarch64_opnd_info *opnd,
1541
         aarch64_operand_error *mismatch_detail, int idx,
1542
         const char *prefix, int min_regno, int max_regno,
1543
         int min_index, int max_index)
1544
0
{
1545
0
  if (!value_in_range_p (opnd->reglane.regno, min_regno, max_regno))
1546
0
    {
1547
0
      set_invalid_regno_error (mismatch_detail, idx, prefix, min_regno,
1548
0
             max_regno);
1549
0
      return false;
1550
0
    }
1551
0
  if (!value_in_range_p (opnd->reglane.index, min_index, max_index))
1552
0
    {
1553
0
      set_elem_idx_out_of_range_error (mismatch_detail, idx, min_index,
1554
0
               max_index);
1555
0
      return false;
1556
0
    }
1557
0
  return true;
1558
0
}
1559
1560
/* Check that register list operand OPND has NUM_REGS registers and a
1561
   register stride of STRIDE.  */
1562
1563
static bool
1564
check_reglist (const aarch64_opnd_info *opnd,
1565
         aarch64_operand_error *mismatch_detail, int idx,
1566
         int num_regs, int stride)
1567
0
{
1568
0
  if (opnd->reglist.num_regs != num_regs)
1569
0
    {
1570
0
      set_reg_list_length_error (mismatch_detail, idx, num_regs);
1571
0
      return false;
1572
0
    }
1573
0
  if (opnd->reglist.stride != stride)
1574
0
    {
1575
0
      set_reg_list_stride_error (mismatch_detail, idx, stride);
1576
0
      return false;
1577
0
    }
1578
0
  return true;
1579
0
}
1580
1581
/* Check that indexed ZA operand OPND has:
1582
1583
   - a selection register in the range [MIN_WREG, MIN_WREG + 3]
1584
1585
   - RANGE_SIZE consecutive immediate offsets.
1586
1587
   - an initial immediate offset that is a multiple of RANGE_SIZE
1588
     in the range [0, MAX_VALUE * RANGE_SIZE]
1589
1590
   - a vector group size of GROUP_SIZE.  */
1591
1592
static bool
1593
check_za_access (const aarch64_opnd_info *opnd,
1594
     aarch64_operand_error *mismatch_detail, int idx,
1595
     int min_wreg, int max_value, unsigned int range_size,
1596
     int group_size)
1597
0
{
1598
0
  if (!value_in_range_p (opnd->indexed_za.index.regno, min_wreg, min_wreg + 3))
1599
0
    {
1600
0
      if (min_wreg == 12)
1601
0
  set_other_error (mismatch_detail, idx,
1602
0
       _("expected a selection register in the"
1603
0
         " range w12-w15"));
1604
0
      else if (min_wreg == 8)
1605
0
  set_other_error (mismatch_detail, idx,
1606
0
       _("expected a selection register in the"
1607
0
         " range w8-w11"));
1608
0
      else
1609
0
  abort ();
1610
0
      return false;
1611
0
    }
1612
1613
0
  int max_index = max_value * range_size;
1614
0
  if (!value_in_range_p (opnd->indexed_za.index.imm, 0, max_index))
1615
0
    {
1616
0
      set_offset_out_of_range_error (mismatch_detail, idx, 0, max_index);
1617
0
      return false;
1618
0
    }
1619
1620
0
  if ((opnd->indexed_za.index.imm % range_size) != 0)
1621
0
    {
1622
0
      assert (range_size == 2 || range_size == 4);
1623
0
      set_other_error (mismatch_detail, idx,
1624
0
           range_size == 2
1625
0
           ? _("starting offset is not a multiple of 2")
1626
0
           : _("starting offset is not a multiple of 4"));
1627
0
      return false;
1628
0
    }
1629
1630
0
  if (opnd->indexed_za.index.countm1 != range_size - 1)
1631
0
    {
1632
0
      if (range_size == 1)
1633
0
  set_other_error (mismatch_detail, idx,
1634
0
       _("expected a single offset rather than"
1635
0
         " a range"));
1636
0
      else if (range_size == 2)
1637
0
  set_other_error (mismatch_detail, idx,
1638
0
       _("expected a range of two offsets"));
1639
0
      else if (range_size == 4)
1640
0
  set_other_error (mismatch_detail, idx,
1641
0
       _("expected a range of four offsets"));
1642
0
      else
1643
0
  abort ();
1644
0
      return false;
1645
0
    }
1646
1647
  /* The vector group specifier is optional in assembly code.  */
1648
0
  if (opnd->indexed_za.group_size != 0
1649
0
      && opnd->indexed_za.group_size != group_size)
1650
0
    {
1651
0
      set_invalid_vg_size (mismatch_detail, idx, group_size);
1652
0
      return false;
1653
0
    }
1654
1655
0
  return true;
1656
0
}
1657
1658
/* General constraint checking based on operand code.
1659
1660
   Return 1 if OPNDS[IDX] meets the general constraint of operand code TYPE
1661
   as the IDXth operand of opcode OPCODE.  Otherwise return 0.
1662
1663
   This function has to be called after the qualifiers for all operands
1664
   have been resolved.
1665
1666
   Mismatching error message is returned in *MISMATCH_DETAIL upon request,
1667
   i.e. when MISMATCH_DETAIL is non-NULL.  This avoids the generation
1668
   of error message during the disassembling where error message is not
1669
   wanted.  We avoid the dynamic construction of strings of error messages
1670
   here (i.e. in libopcodes), as it is costly and complicated; instead, we
1671
   use a combination of error code, static string and some integer data to
1672
   represent an error.  */
1673
1674
static int
1675
operand_general_constraint_met_p (const aarch64_opnd_info *opnds, int idx,
1676
          enum aarch64_opnd type,
1677
          const aarch64_opcode *opcode,
1678
          aarch64_operand_error *mismatch_detail)
1679
0
{
1680
0
  unsigned num, modifiers, shift;
1681
0
  unsigned char size;
1682
0
  int64_t imm, min_value, max_value;
1683
0
  uint64_t uvalue, mask;
1684
0
  const aarch64_opnd_info *opnd = opnds + idx;
1685
0
  aarch64_opnd_qualifier_t qualifier = opnd->qualifier;
1686
0
  int i;
1687
1688
0
  assert (opcode->operands[idx] == opnd->type && opnd->type == type);
1689
1690
0
  switch (aarch64_operands[type].op_class)
1691
0
    {
1692
0
    case AARCH64_OPND_CLASS_INT_REG:
1693
      /* Check pair reg constraints for cas* instructions.  */
1694
0
      if (type == AARCH64_OPND_PAIRREG)
1695
0
  {
1696
0
    assert (idx == 1 || idx == 3);
1697
0
    if (opnds[idx - 1].reg.regno % 2 != 0)
1698
0
      {
1699
0
        set_syntax_error (mismatch_detail, idx - 1,
1700
0
        _("reg pair must start from even reg"));
1701
0
        return 0;
1702
0
      }
1703
0
    if (opnds[idx].reg.regno != opnds[idx - 1].reg.regno + 1)
1704
0
      {
1705
0
        set_syntax_error (mismatch_detail, idx,
1706
0
        _("reg pair must be contiguous"));
1707
0
        return 0;
1708
0
      }
1709
0
    break;
1710
0
  }
1711
1712
      /* <Xt> may be optional in some IC and TLBI instructions.  */
1713
0
      if (type == AARCH64_OPND_Rt_SYS)
1714
0
  {
1715
0
    assert (idx == 1 && (aarch64_get_operand_class (opnds[0].type)
1716
0
             == AARCH64_OPND_CLASS_SYSTEM));
1717
0
    if (opnds[1].present
1718
0
        && !aarch64_sys_ins_reg_has_xt (opnds[0].sysins_op))
1719
0
      {
1720
0
        set_other_error (mismatch_detail, idx, _("extraneous register"));
1721
0
        return 0;
1722
0
      }
1723
0
    if (!opnds[1].present
1724
0
        && aarch64_sys_ins_reg_has_xt (opnds[0].sysins_op))
1725
0
      {
1726
0
        set_other_error (mismatch_detail, idx, _("missing register"));
1727
0
        return 0;
1728
0
      }
1729
0
  }
1730
0
      switch (qualifier)
1731
0
  {
1732
0
  case AARCH64_OPND_QLF_WSP:
1733
0
  case AARCH64_OPND_QLF_SP:
1734
0
    if (!aarch64_stack_pointer_p (opnd))
1735
0
      {
1736
0
        set_other_error (mismatch_detail, idx,
1737
0
           _("stack pointer register expected"));
1738
0
        return 0;
1739
0
      }
1740
0
    break;
1741
0
  default:
1742
0
    break;
1743
0
  }
1744
0
      break;
1745
1746
0
    case AARCH64_OPND_CLASS_SVE_REG:
1747
0
      switch (type)
1748
0
  {
1749
0
  case AARCH64_OPND_SVE_Zm3_INDEX:
1750
0
  case AARCH64_OPND_SVE_Zm3_22_INDEX:
1751
0
  case AARCH64_OPND_SVE_Zm3_19_INDEX:
1752
0
  case AARCH64_OPND_SVE_Zm3_11_INDEX:
1753
0
  case AARCH64_OPND_SVE_Zm4_11_INDEX:
1754
0
  case AARCH64_OPND_SVE_Zm4_INDEX:
1755
0
    size = get_operand_fields_width (get_operand_from_code (type));
1756
0
    shift = get_operand_specific_data (&aarch64_operands[type]);
1757
0
    if (!check_reglane (opnd, mismatch_detail, idx,
1758
0
            "z", 0, (1 << shift) - 1,
1759
0
            0, (1u << (size - shift)) - 1))
1760
0
      return 0;
1761
0
    break;
1762
1763
0
  case AARCH64_OPND_SVE_Zn_INDEX:
1764
0
    size = aarch64_get_qualifier_esize (opnd->qualifier);
1765
0
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 31,
1766
0
            0, 64 / size - 1))
1767
0
      return 0;
1768
0
    break;
1769
1770
0
  case AARCH64_OPND_SME_PNn3_INDEX1:
1771
0
  case AARCH64_OPND_SME_PNn3_INDEX2:
1772
0
    size = get_operand_field_width (get_operand_from_code (type), 1);
1773
0
    if (!check_reglane (opnd, mismatch_detail, idx, "pn", 8, 15,
1774
0
            0, (1 << size) - 1))
1775
0
      return 0;
1776
0
    break;
1777
1778
0
  case AARCH64_OPND_SME_Zn_INDEX1_16:
1779
0
  case AARCH64_OPND_SME_Zn_INDEX2_15:
1780
0
  case AARCH64_OPND_SME_Zn_INDEX2_16:
1781
0
  case AARCH64_OPND_SME_Zn_INDEX3_14:
1782
0
  case AARCH64_OPND_SME_Zn_INDEX3_15:
1783
0
  case AARCH64_OPND_SME_Zn_INDEX4_14:
1784
0
    size = get_operand_fields_width (get_operand_from_code (type)) - 5;
1785
0
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 31,
1786
0
            0, (1 << size) - 1))
1787
0
      return 0;
1788
0
    break;
1789
1790
0
  case AARCH64_OPND_SME_Zm_INDEX1:
1791
0
  case AARCH64_OPND_SME_Zm_INDEX2:
1792
0
  case AARCH64_OPND_SME_Zm_INDEX3_1:
1793
0
  case AARCH64_OPND_SME_Zm_INDEX3_2:
1794
0
  case AARCH64_OPND_SME_Zm_INDEX3_10:
1795
0
  case AARCH64_OPND_SME_Zm_INDEX4_1:
1796
0
  case AARCH64_OPND_SME_Zm_INDEX4_10:
1797
0
    size = get_operand_fields_width (get_operand_from_code (type)) - 4;
1798
0
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 15,
1799
0
            0, (1 << size) - 1))
1800
0
      return 0;
1801
0
    break;
1802
1803
0
  case AARCH64_OPND_SME_Zm:
1804
0
    if (opnd->reg.regno > 15)
1805
0
      {
1806
0
        set_invalid_regno_error (mismatch_detail, idx, "z", 0, 15);
1807
0
        return 0;
1808
0
      }
1809
0
    break;
1810
1811
0
  case AARCH64_OPND_SME_PnT_Wm_imm:
1812
0
    size = aarch64_get_qualifier_esize (opnd->qualifier);
1813
0
    max_value = 16 / size - 1;
1814
0
    if (!check_za_access (opnd, mismatch_detail, idx,
1815
0
        12, max_value, 1, 0))
1816
0
      return 0;
1817
0
    break;
1818
1819
0
  default:
1820
0
    break;
1821
0
  }
1822
0
      break;
1823
1824
0
    case AARCH64_OPND_CLASS_SVE_REGLIST:
1825
0
      switch (type)
1826
0
  {
1827
0
  case AARCH64_OPND_SME_Pdx2:
1828
0
  case AARCH64_OPND_SME_Zdnx2:
1829
0
  case AARCH64_OPND_SME_Zdnx4:
1830
0
  case AARCH64_OPND_SME_Zmx2:
1831
0
  case AARCH64_OPND_SME_Zmx4:
1832
0
  case AARCH64_OPND_SME_Znx2:
1833
0
  case AARCH64_OPND_SME_Znx4:
1834
0
    num = get_operand_specific_data (&aarch64_operands[type]);
1835
0
    if (!check_reglist (opnd, mismatch_detail, idx, num, 1))
1836
0
      return 0;
1837
0
    if ((opnd->reglist.first_regno % num) != 0)
1838
0
      {
1839
0
        set_other_error (mismatch_detail, idx,
1840
0
             _("start register out of range"));
1841
0
        return 0;
1842
0
      }
1843
0
    break;
1844
1845
0
  case AARCH64_OPND_SME_Ztx2_STRIDED:
1846
0
  case AARCH64_OPND_SME_Ztx4_STRIDED:
1847
    /* 2-register lists have a stride of 8 and 4-register lists
1848
       have a stride of 4.  */
1849
0
    num = get_operand_specific_data (&aarch64_operands[type]);
1850
0
    if (!check_reglist (opnd, mismatch_detail, idx, num, 16 / num))
1851
0
      return 0;
1852
0
    num = 16 | (opnd->reglist.stride - 1);
1853
0
    if ((opnd->reglist.first_regno & ~num) != 0)
1854
0
      {
1855
0
        set_other_error (mismatch_detail, idx,
1856
0
             _("start register out of range"));
1857
0
        return 0;
1858
0
      }
1859
0
    break;
1860
1861
0
  case AARCH64_OPND_SME_PdxN:
1862
0
  case AARCH64_OPND_SVE_ZnxN:
1863
0
  case AARCH64_OPND_SVE_ZtxN:
1864
0
    num = get_opcode_dependent_value (opcode);
1865
0
    if (!check_reglist (opnd, mismatch_detail, idx, num, 1))
1866
0
      return 0;
1867
0
    break;
1868
1869
0
  default:
1870
0
    abort ();
1871
0
  }
1872
0
      break;
1873
1874
0
    case AARCH64_OPND_CLASS_ZA_ACCESS:
1875
0
      switch (type)
1876
0
  {
1877
0
  case AARCH64_OPND_SME_ZA_HV_idx_src:
1878
0
  case AARCH64_OPND_SME_ZA_HV_idx_dest:
1879
0
  case AARCH64_OPND_SME_ZA_HV_idx_ldstr:
1880
0
    size = aarch64_get_qualifier_esize (opnd->qualifier);
1881
0
    max_value = 16 / size - 1;
1882
0
    if (!check_za_access (opnd, mismatch_detail, idx, 12, max_value, 1,
1883
0
        get_opcode_dependent_value (opcode)))
1884
0
      return 0;
1885
0
    break;
1886
1887
0
  case AARCH64_OPND_SME_ZA_array_off4:
1888
0
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 15, 1,
1889
0
        get_opcode_dependent_value (opcode)))
1890
0
      return 0;
1891
0
    break;
1892
1893
0
  case AARCH64_OPND_SME_ZA_array_off3_0:
1894
0
  case AARCH64_OPND_SME_ZA_array_off3_5:
1895
0
    if (!check_za_access (opnd, mismatch_detail, idx, 8, 7, 1,
1896
0
        get_opcode_dependent_value (opcode)))
1897
0
      return 0;
1898
0
    break;
1899
1900
0
  case AARCH64_OPND_SME_ZA_array_off1x4:
1901
0
    if (!check_za_access (opnd, mismatch_detail, idx, 8, 1, 4,
1902
0
        get_opcode_dependent_value (opcode)))
1903
0
      return 0;
1904
0
    break;
1905
1906
0
  case AARCH64_OPND_SME_ZA_array_off2x2:
1907
0
    if (!check_za_access (opnd, mismatch_detail, idx, 8, 3, 2,
1908
0
        get_opcode_dependent_value (opcode)))
1909
0
      return 0;
1910
0
    break;
1911
1912
0
  case AARCH64_OPND_SME_ZA_array_off2x4:
1913
0
    if (!check_za_access (opnd, mismatch_detail, idx, 8, 3, 4,
1914
0
        get_opcode_dependent_value (opcode)))
1915
0
      return 0;
1916
0
    break;
1917
1918
0
  case AARCH64_OPND_SME_ZA_array_off3x2:
1919
0
    if (!check_za_access (opnd, mismatch_detail, idx, 8, 7, 2,
1920
0
        get_opcode_dependent_value (opcode)))
1921
0
      return 0;
1922
0
    break;
1923
1924
0
  case AARCH64_OPND_SME_ZA_HV_idx_srcxN:
1925
0
  case AARCH64_OPND_SME_ZA_HV_idx_destxN:
1926
0
    size = aarch64_get_qualifier_esize (opnd->qualifier);
1927
0
    num = get_opcode_dependent_value (opcode);
1928
0
    max_value = 16 / num / size;
1929
0
    if (max_value > 0)
1930
0
      max_value -= 1;
1931
0
    if (!check_za_access (opnd, mismatch_detail, idx,
1932
0
        12, max_value, num, 0))
1933
0
      return 0;
1934
0
    break;
1935
1936
0
  default:
1937
0
    abort ();
1938
0
  }
1939
0
      break;
1940
1941
0
    case AARCH64_OPND_CLASS_PRED_REG:
1942
0
      switch (type)
1943
0
  {
1944
0
  case AARCH64_OPND_SME_PNd3:
1945
0
  case AARCH64_OPND_SME_PNg3:
1946
0
    if (opnd->reg.regno < 8)
1947
0
      {
1948
0
        set_invalid_regno_error (mismatch_detail, idx, "pn", 8, 15);
1949
0
        return 0;
1950
0
      }
1951
0
    break;
1952
1953
0
  default:
1954
0
    if (opnd->reg.regno >= 8
1955
0
        && get_operand_fields_width (get_operand_from_code (type)) == 3)
1956
0
      {
1957
0
        set_invalid_regno_error (mismatch_detail, idx, "p", 0, 7);
1958
0
        return 0;
1959
0
      }
1960
0
    break;
1961
0
  }
1962
0
      break;
1963
1964
0
    case AARCH64_OPND_CLASS_COND:
1965
0
      if (type == AARCH64_OPND_COND1
1966
0
    && (opnds[idx].cond->value & 0xe) == 0xe)
1967
0
  {
1968
    /* Not allow AL or NV.  */
1969
0
    set_syntax_error (mismatch_detail, idx, NULL);
1970
0
  }
1971
0
      break;
1972
1973
0
    case AARCH64_OPND_CLASS_ADDRESS:
1974
      /* Check writeback.  */
1975
0
      switch (opcode->iclass)
1976
0
  {
1977
0
  case ldst_pos:
1978
0
  case ldst_unscaled:
1979
0
  case ldstnapair_offs:
1980
0
  case ldstpair_off:
1981
0
  case ldst_unpriv:
1982
0
    if (opnd->addr.writeback == 1)
1983
0
      {
1984
0
        set_syntax_error (mismatch_detail, idx,
1985
0
        _("unexpected address writeback"));
1986
0
        return 0;
1987
0
      }
1988
0
    break;
1989
0
  case ldst_imm10:
1990
0
    if (opnd->addr.writeback == 1 && opnd->addr.preind != 1)
1991
0
      {
1992
0
        set_syntax_error (mismatch_detail, idx,
1993
0
        _("unexpected address writeback"));
1994
0
        return 0;
1995
0
      }
1996
0
    break;
1997
0
  case ldst_imm9:
1998
0
  case ldstpair_indexed:
1999
0
  case asisdlsep:
2000
0
  case asisdlsop:
2001
0
    if (opnd->addr.writeback == 0)
2002
0
      {
2003
0
        set_syntax_error (mismatch_detail, idx,
2004
0
        _("address writeback expected"));
2005
0
        return 0;
2006
0
      }
2007
0
    break;
2008
0
  default:
2009
0
    assert (opnd->addr.writeback == 0);
2010
0
    break;
2011
0
  }
2012
0
      switch (type)
2013
0
  {
2014
0
  case AARCH64_OPND_ADDR_SIMM7:
2015
    /* Scaled signed 7 bits immediate offset.  */
2016
    /* Get the size of the data element that is accessed, which may be
2017
       different from that of the source register size,
2018
       e.g. in strb/ldrb.  */
2019
0
    size = aarch64_get_qualifier_esize (opnd->qualifier);
2020
0
    if (!value_in_range_p (opnd->addr.offset.imm, -64 * size, 63 * size))
2021
0
      {
2022
0
        set_offset_out_of_range_error (mismatch_detail, idx,
2023
0
               -64 * size, 63 * size);
2024
0
        return 0;
2025
0
      }
2026
0
    if (!value_aligned_p (opnd->addr.offset.imm, size))
2027
0
      {
2028
0
        set_unaligned_error (mismatch_detail, idx, size);
2029
0
        return 0;
2030
0
      }
2031
0
    break;
2032
0
  case AARCH64_OPND_ADDR_OFFSET:
2033
0
  case AARCH64_OPND_ADDR_SIMM9:
2034
    /* Unscaled signed 9 bits immediate offset.  */
2035
0
    if (!value_in_range_p (opnd->addr.offset.imm, -256, 255))
2036
0
      {
2037
0
        set_offset_out_of_range_error (mismatch_detail, idx, -256, 255);
2038
0
        return 0;
2039
0
      }
2040
0
    break;
2041
2042
0
  case AARCH64_OPND_ADDR_SIMM9_2:
2043
    /* Unscaled signed 9 bits immediate offset, which has to be negative
2044
       or unaligned.  */
2045
0
    size = aarch64_get_qualifier_esize (qualifier);
2046
0
    if ((value_in_range_p (opnd->addr.offset.imm, 0, 255)
2047
0
         && !value_aligned_p (opnd->addr.offset.imm, size))
2048
0
        || value_in_range_p (opnd->addr.offset.imm, -256, -1))
2049
0
      return 1;
2050
0
    set_other_error (mismatch_detail, idx,
2051
0
         _("negative or unaligned offset expected"));
2052
0
    return 0;
2053
2054
0
  case AARCH64_OPND_ADDR_SIMM10:
2055
    /* Scaled signed 10 bits immediate offset.  */
2056
0
    if (!value_in_range_p (opnd->addr.offset.imm, -4096, 4088))
2057
0
      {
2058
0
        set_offset_out_of_range_error (mismatch_detail, idx, -4096, 4088);
2059
0
        return 0;
2060
0
      }
2061
0
    if (!value_aligned_p (opnd->addr.offset.imm, 8))
2062
0
      {
2063
0
        set_unaligned_error (mismatch_detail, idx, 8);
2064
0
        return 0;
2065
0
      }
2066
0
    break;
2067
2068
0
  case AARCH64_OPND_ADDR_SIMM11:
2069
    /* Signed 11 bits immediate offset (multiple of 16).  */
2070
0
    if (!value_in_range_p (opnd->addr.offset.imm, -1024, 1008))
2071
0
      {
2072
0
        set_offset_out_of_range_error (mismatch_detail, idx, -1024, 1008);
2073
0
        return 0;
2074
0
      }
2075
2076
0
    if (!value_aligned_p (opnd->addr.offset.imm, 16))
2077
0
      {
2078
0
        set_unaligned_error (mismatch_detail, idx, 16);
2079
0
        return 0;
2080
0
      }
2081
0
    break;
2082
2083
0
  case AARCH64_OPND_ADDR_SIMM13:
2084
    /* Signed 13 bits immediate offset (multiple of 16).  */
2085
0
    if (!value_in_range_p (opnd->addr.offset.imm, -4096, 4080))
2086
0
      {
2087
0
        set_offset_out_of_range_error (mismatch_detail, idx, -4096, 4080);
2088
0
        return 0;
2089
0
      }
2090
2091
0
    if (!value_aligned_p (opnd->addr.offset.imm, 16))
2092
0
      {
2093
0
        set_unaligned_error (mismatch_detail, idx, 16);
2094
0
        return 0;
2095
0
      }
2096
0
    break;
2097
2098
0
  case AARCH64_OPND_SIMD_ADDR_POST:
2099
    /* AdvSIMD load/store multiple structures, post-index.  */
2100
0
    assert (idx == 1);
2101
0
    if (opnd->addr.offset.is_reg)
2102
0
      {
2103
0
        if (value_in_range_p (opnd->addr.offset.regno, 0, 30))
2104
0
    return 1;
2105
0
        else
2106
0
    {
2107
0
      set_other_error (mismatch_detail, idx,
2108
0
           _("invalid register offset"));
2109
0
      return 0;
2110
0
    }
2111
0
      }
2112
0
    else
2113
0
      {
2114
0
        const aarch64_opnd_info *prev = &opnds[idx-1];
2115
0
        unsigned num_bytes; /* total number of bytes transferred.  */
2116
        /* The opcode dependent area stores the number of elements in
2117
     each structure to be loaded/stored.  */
2118
0
        int is_ld1r = get_opcode_dependent_value (opcode) == 1;
2119
0
        if (opcode->operands[0] == AARCH64_OPND_LVt_AL)
2120
    /* Special handling of loading single structure to all lane.  */
2121
0
    num_bytes = (is_ld1r ? 1 : prev->reglist.num_regs)
2122
0
      * aarch64_get_qualifier_esize (prev->qualifier);
2123
0
        else
2124
0
    num_bytes = prev->reglist.num_regs
2125
0
      * aarch64_get_qualifier_esize (prev->qualifier)
2126
0
      * aarch64_get_qualifier_nelem (prev->qualifier);
2127
0
        if ((int) num_bytes != opnd->addr.offset.imm)
2128
0
    {
2129
0
      set_other_error (mismatch_detail, idx,
2130
0
           _("invalid post-increment amount"));
2131
0
      return 0;
2132
0
    }
2133
0
      }
2134
0
    break;
2135
2136
0
  case AARCH64_OPND_ADDR_REGOFF:
2137
    /* Get the size of the data element that is accessed, which may be
2138
       different from that of the source register size,
2139
       e.g. in strb/ldrb.  */
2140
0
    size = aarch64_get_qualifier_esize (opnd->qualifier);
2141
    /* It is either no shift or shift by the binary logarithm of SIZE.  */
2142
0
    if (opnd->shifter.amount != 0
2143
0
        && opnd->shifter.amount != (int)get_logsz (size))
2144
0
      {
2145
0
        set_other_error (mismatch_detail, idx,
2146
0
             _("invalid shift amount"));
2147
0
        return 0;
2148
0
      }
2149
    /* Only UXTW, LSL, SXTW and SXTX are the accepted extending
2150
       operators.  */
2151
0
    switch (opnd->shifter.kind)
2152
0
      {
2153
0
      case AARCH64_MOD_UXTW:
2154
0
      case AARCH64_MOD_LSL:
2155
0
      case AARCH64_MOD_SXTW:
2156
0
      case AARCH64_MOD_SXTX: break;
2157
0
      default:
2158
0
        set_other_error (mismatch_detail, idx,
2159
0
             _("invalid extend/shift operator"));
2160
0
        return 0;
2161
0
      }
2162
0
    break;
2163
2164
0
  case AARCH64_OPND_ADDR_UIMM12:
2165
0
    imm = opnd->addr.offset.imm;
2166
    /* Get the size of the data element that is accessed, which may be
2167
       different from that of the source register size,
2168
       e.g. in strb/ldrb.  */
2169
0
    size = aarch64_get_qualifier_esize (qualifier);
2170
0
    if (!value_in_range_p (opnd->addr.offset.imm, 0, 4095 * size))
2171
0
      {
2172
0
        set_offset_out_of_range_error (mismatch_detail, idx,
2173
0
               0, 4095 * size);
2174
0
        return 0;
2175
0
      }
2176
0
    if (!value_aligned_p (opnd->addr.offset.imm, size))
2177
0
      {
2178
0
        set_unaligned_error (mismatch_detail, idx, size);
2179
0
        return 0;
2180
0
      }
2181
0
    break;
2182
2183
0
  case AARCH64_OPND_ADDR_PCREL14:
2184
0
  case AARCH64_OPND_ADDR_PCREL19:
2185
0
  case AARCH64_OPND_ADDR_PCREL21:
2186
0
  case AARCH64_OPND_ADDR_PCREL26:
2187
0
    imm = opnd->imm.value;
2188
0
    if (operand_need_shift_by_two (get_operand_from_code (type)))
2189
0
      {
2190
        /* The offset value in a PC-relative branch instruction is alway
2191
     4-byte aligned and is encoded without the lowest 2 bits.  */
2192
0
        if (!value_aligned_p (imm, 4))
2193
0
    {
2194
0
      set_unaligned_error (mismatch_detail, idx, 4);
2195
0
      return 0;
2196
0
    }
2197
        /* Right shift by 2 so that we can carry out the following check
2198
     canonically.  */
2199
0
        imm >>= 2;
2200
0
      }
2201
0
    size = get_operand_fields_width (get_operand_from_code (type));
2202
0
    if (!value_fit_signed_field_p (imm, size))
2203
0
      {
2204
0
        set_other_error (mismatch_detail, idx,
2205
0
             _("immediate out of range"));
2206
0
        return 0;
2207
0
      }
2208
0
    break;
2209
2210
0
  case AARCH64_OPND_SME_ADDR_RI_U4xVL:
2211
0
    if (!value_in_range_p (opnd->addr.offset.imm, 0, 15))
2212
0
      {
2213
0
        set_offset_out_of_range_error (mismatch_detail, idx, 0, 15);
2214
0
        return 0;
2215
0
      }
2216
0
    break;
2217
2218
0
  case AARCH64_OPND_SVE_ADDR_RI_S4xVL:
2219
0
  case AARCH64_OPND_SVE_ADDR_RI_S4x2xVL:
2220
0
  case AARCH64_OPND_SVE_ADDR_RI_S4x3xVL:
2221
0
  case AARCH64_OPND_SVE_ADDR_RI_S4x4xVL:
2222
0
    min_value = -8;
2223
0
    max_value = 7;
2224
0
  sve_imm_offset_vl:
2225
0
    assert (!opnd->addr.offset.is_reg);
2226
0
    assert (opnd->addr.preind);
2227
0
    num = 1 + get_operand_specific_data (&aarch64_operands[type]);
2228
0
    min_value *= num;
2229
0
    max_value *= num;
2230
0
    if ((opnd->addr.offset.imm != 0 && !opnd->shifter.operator_present)
2231
0
        || (opnd->shifter.operator_present
2232
0
      && opnd->shifter.kind != AARCH64_MOD_MUL_VL))
2233
0
      {
2234
0
        set_other_error (mismatch_detail, idx,
2235
0
             _("invalid addressing mode"));
2236
0
        return 0;
2237
0
      }
2238
0
    if (!value_in_range_p (opnd->addr.offset.imm, min_value, max_value))
2239
0
      {
2240
0
        set_offset_out_of_range_error (mismatch_detail, idx,
2241
0
               min_value, max_value);
2242
0
        return 0;
2243
0
      }
2244
0
    if (!value_aligned_p (opnd->addr.offset.imm, num))
2245
0
      {
2246
0
        set_unaligned_error (mismatch_detail, idx, num);
2247
0
        return 0;
2248
0
      }
2249
0
    break;
2250
2251
0
  case AARCH64_OPND_SVE_ADDR_RI_S6xVL:
2252
0
    min_value = -32;
2253
0
    max_value = 31;
2254
0
    goto sve_imm_offset_vl;
2255
2256
0
  case AARCH64_OPND_SVE_ADDR_RI_S9xVL:
2257
0
    min_value = -256;
2258
0
    max_value = 255;
2259
0
    goto sve_imm_offset_vl;
2260
2261
0
  case AARCH64_OPND_SVE_ADDR_RI_U6:
2262
0
  case AARCH64_OPND_SVE_ADDR_RI_U6x2:
2263
0
  case AARCH64_OPND_SVE_ADDR_RI_U6x4:
2264
0
  case AARCH64_OPND_SVE_ADDR_RI_U6x8:
2265
0
    min_value = 0;
2266
0
    max_value = 63;
2267
0
  sve_imm_offset:
2268
0
    assert (!opnd->addr.offset.is_reg);
2269
0
    assert (opnd->addr.preind);
2270
0
    num = 1 << get_operand_specific_data (&aarch64_operands[type]);
2271
0
    min_value *= num;
2272
0
    max_value *= num;
2273
0
    if (opnd->shifter.operator_present
2274
0
        || opnd->shifter.amount_present)
2275
0
      {
2276
0
        set_other_error (mismatch_detail, idx,
2277
0
             _("invalid addressing mode"));
2278
0
        return 0;
2279
0
      }
2280
0
    if (!value_in_range_p (opnd->addr.offset.imm, min_value, max_value))
2281
0
      {
2282
0
        set_offset_out_of_range_error (mismatch_detail, idx,
2283
0
               min_value, max_value);
2284
0
        return 0;
2285
0
      }
2286
0
    if (!value_aligned_p (opnd->addr.offset.imm, num))
2287
0
      {
2288
0
        set_unaligned_error (mismatch_detail, idx, num);
2289
0
        return 0;
2290
0
      }
2291
0
    break;
2292
2293
0
  case AARCH64_OPND_SVE_ADDR_RI_S4x16:
2294
0
  case AARCH64_OPND_SVE_ADDR_RI_S4x32:
2295
0
    min_value = -8;
2296
0
    max_value = 7;
2297
0
    goto sve_imm_offset;
2298
2299
0
  case AARCH64_OPND_SVE_ADDR_ZX:
2300
    /* Everything is already ensured by parse_operands or
2301
       aarch64_ext_sve_addr_rr_lsl (because this is a very specific
2302
       argument type).  */
2303
0
    assert (opnd->addr.offset.is_reg);
2304
0
    assert (opnd->addr.preind);
2305
0
    assert ((aarch64_operands[type].flags & OPD_F_NO_ZR) == 0);
2306
0
    assert (opnd->shifter.kind == AARCH64_MOD_LSL);
2307
0
    assert (opnd->shifter.operator_present == 0);
2308
0
    break;
2309
2310
0
  case AARCH64_OPND_SVE_ADDR_R:
2311
0
  case AARCH64_OPND_SVE_ADDR_RR:
2312
0
  case AARCH64_OPND_SVE_ADDR_RR_LSL1:
2313
0
  case AARCH64_OPND_SVE_ADDR_RR_LSL2:
2314
0
  case AARCH64_OPND_SVE_ADDR_RR_LSL3:
2315
0
  case AARCH64_OPND_SVE_ADDR_RR_LSL4:
2316
0
  case AARCH64_OPND_SVE_ADDR_RX:
2317
0
  case AARCH64_OPND_SVE_ADDR_RX_LSL1:
2318
0
  case AARCH64_OPND_SVE_ADDR_RX_LSL2:
2319
0
  case AARCH64_OPND_SVE_ADDR_RX_LSL3:
2320
0
  case AARCH64_OPND_SVE_ADDR_RZ:
2321
0
  case AARCH64_OPND_SVE_ADDR_RZ_LSL1:
2322
0
  case AARCH64_OPND_SVE_ADDR_RZ_LSL2:
2323
0
  case AARCH64_OPND_SVE_ADDR_RZ_LSL3:
2324
0
    modifiers = 1 << AARCH64_MOD_LSL;
2325
0
  sve_rr_operand:
2326
0
    assert (opnd->addr.offset.is_reg);
2327
0
    assert (opnd->addr.preind);
2328
0
    if ((aarch64_operands[type].flags & OPD_F_NO_ZR) != 0
2329
0
        && opnd->addr.offset.regno == 31)
2330
0
      {
2331
0
        set_other_error (mismatch_detail, idx,
2332
0
             _("index register xzr is not allowed"));
2333
0
        return 0;
2334
0
      }
2335
0
    if (((1 << opnd->shifter.kind) & modifiers) == 0
2336
0
        || (opnd->shifter.amount
2337
0
      != get_operand_specific_data (&aarch64_operands[type])))
2338
0
      {
2339
0
        set_other_error (mismatch_detail, idx,
2340
0
             _("invalid addressing mode"));
2341
0
        return 0;
2342
0
      }
2343
0
    break;
2344
2345
0
  case AARCH64_OPND_SVE_ADDR_RZ_XTW_14:
2346
0
  case AARCH64_OPND_SVE_ADDR_RZ_XTW_22:
2347
0
  case AARCH64_OPND_SVE_ADDR_RZ_XTW1_14:
2348
0
  case AARCH64_OPND_SVE_ADDR_RZ_XTW1_22:
2349
0
  case AARCH64_OPND_SVE_ADDR_RZ_XTW2_14:
2350
0
  case AARCH64_OPND_SVE_ADDR_RZ_XTW2_22:
2351
0
  case AARCH64_OPND_SVE_ADDR_RZ_XTW3_14:
2352
0
  case AARCH64_OPND_SVE_ADDR_RZ_XTW3_22:
2353
0
    modifiers = (1 << AARCH64_MOD_SXTW) | (1 << AARCH64_MOD_UXTW);
2354
0
    goto sve_rr_operand;
2355
2356
0
  case AARCH64_OPND_SVE_ADDR_ZI_U5:
2357
0
  case AARCH64_OPND_SVE_ADDR_ZI_U5x2:
2358
0
  case AARCH64_OPND_SVE_ADDR_ZI_U5x4:
2359
0
  case AARCH64_OPND_SVE_ADDR_ZI_U5x8:
2360
0
    min_value = 0;
2361
0
    max_value = 31;
2362
0
    goto sve_imm_offset;
2363
2364
0
  case AARCH64_OPND_SVE_ADDR_ZZ_LSL:
2365
0
    modifiers = 1 << AARCH64_MOD_LSL;
2366
0
  sve_zz_operand:
2367
0
    assert (opnd->addr.offset.is_reg);
2368
0
    assert (opnd->addr.preind);
2369
0
    if (((1 << opnd->shifter.kind) & modifiers) == 0
2370
0
        || opnd->shifter.amount < 0
2371
0
        || opnd->shifter.amount > 3)
2372
0
      {
2373
0
        set_other_error (mismatch_detail, idx,
2374
0
             _("invalid addressing mode"));
2375
0
        return 0;
2376
0
      }
2377
0
    break;
2378
2379
0
  case AARCH64_OPND_SVE_ADDR_ZZ_SXTW:
2380
0
    modifiers = (1 << AARCH64_MOD_SXTW);
2381
0
    goto sve_zz_operand;
2382
2383
0
  case AARCH64_OPND_SVE_ADDR_ZZ_UXTW:
2384
0
    modifiers = 1 << AARCH64_MOD_UXTW;
2385
0
    goto sve_zz_operand;
2386
2387
0
  default:
2388
0
    break;
2389
0
  }
2390
0
      break;
2391
2392
0
    case AARCH64_OPND_CLASS_SIMD_REGLIST:
2393
0
      if (type == AARCH64_OPND_LEt)
2394
0
  {
2395
    /* Get the upper bound for the element index.  */
2396
0
    num = 16 / aarch64_get_qualifier_esize (qualifier) - 1;
2397
0
    if (!value_in_range_p (opnd->reglist.index, 0, num))
2398
0
      {
2399
0
        set_elem_idx_out_of_range_error (mismatch_detail, idx, 0, num);
2400
0
        return 0;
2401
0
      }
2402
0
  }
2403
      /* The opcode dependent area stores the number of elements in
2404
   each structure to be loaded/stored.  */
2405
0
      num = get_opcode_dependent_value (opcode);
2406
0
      switch (type)
2407
0
  {
2408
0
  case AARCH64_OPND_LVt:
2409
0
    assert (num >= 1 && num <= 4);
2410
    /* Unless LD1/ST1, the number of registers should be equal to that
2411
       of the structure elements.  */
2412
0
    if (num != 1 && !check_reglist (opnd, mismatch_detail, idx, num, 1))
2413
0
      return 0;
2414
0
    break;
2415
0
  case AARCH64_OPND_LVt_AL:
2416
0
  case AARCH64_OPND_LEt:
2417
0
    assert (num >= 1 && num <= 4);
2418
    /* The number of registers should be equal to that of the structure
2419
       elements.  */
2420
0
    if (!check_reglist (opnd, mismatch_detail, idx, num, 1))
2421
0
      return 0;
2422
0
    break;
2423
0
  default:
2424
0
    break;
2425
0
  }
2426
0
      if (opnd->reglist.stride != 1)
2427
0
  {
2428
0
    set_reg_list_stride_error (mismatch_detail, idx, 1);
2429
0
    return 0;
2430
0
  }
2431
0
      break;
2432
2433
0
    case AARCH64_OPND_CLASS_IMMEDIATE:
2434
      /* Constraint check on immediate operand.  */
2435
0
      imm = opnd->imm.value;
2436
      /* E.g. imm_0_31 constrains value to be 0..31.  */
2437
0
      if (qualifier_value_in_range_constraint_p (qualifier)
2438
0
    && !value_in_range_p (imm, get_lower_bound (qualifier),
2439
0
        get_upper_bound (qualifier)))
2440
0
  {
2441
0
    set_imm_out_of_range_error (mismatch_detail, idx,
2442
0
              get_lower_bound (qualifier),
2443
0
              get_upper_bound (qualifier));
2444
0
    return 0;
2445
0
  }
2446
2447
0
      switch (type)
2448
0
  {
2449
0
  case AARCH64_OPND_AIMM:
2450
0
    if (opnd->shifter.kind != AARCH64_MOD_LSL)
2451
0
      {
2452
0
        set_other_error (mismatch_detail, idx,
2453
0
             _("invalid shift operator"));
2454
0
        return 0;
2455
0
      }
2456
0
    if (opnd->shifter.amount != 0 && opnd->shifter.amount != 12)
2457
0
      {
2458
0
        set_other_error (mismatch_detail, idx,
2459
0
             _("shift amount must be 0 or 12"));
2460
0
        return 0;
2461
0
      }
2462
0
    if (!value_fit_unsigned_field_p (opnd->imm.value, 12))
2463
0
      {
2464
0
        set_other_error (mismatch_detail, idx,
2465
0
             _("immediate out of range"));
2466
0
        return 0;
2467
0
      }
2468
0
    break;
2469
2470
0
  case AARCH64_OPND_HALF:
2471
0
    assert (idx == 1 && opnds[0].type == AARCH64_OPND_Rd);
2472
0
    if (opnd->shifter.kind != AARCH64_MOD_LSL)
2473
0
      {
2474
0
        set_other_error (mismatch_detail, idx,
2475
0
             _("invalid shift operator"));
2476
0
        return 0;
2477
0
      }
2478
0
    size = aarch64_get_qualifier_esize (opnds[0].qualifier);
2479
0
    if (!value_aligned_p (opnd->shifter.amount, 16))
2480
0
      {
2481
0
        set_other_error (mismatch_detail, idx,
2482
0
             _("shift amount must be a multiple of 16"));
2483
0
        return 0;
2484
0
      }
2485
0
    if (!value_in_range_p (opnd->shifter.amount, 0, size * 8 - 16))
2486
0
      {
2487
0
        set_sft_amount_out_of_range_error (mismatch_detail, idx,
2488
0
             0, size * 8 - 16);
2489
0
        return 0;
2490
0
      }
2491
0
    if (opnd->imm.value < 0)
2492
0
      {
2493
0
        set_other_error (mismatch_detail, idx,
2494
0
             _("negative immediate value not allowed"));
2495
0
        return 0;
2496
0
      }
2497
0
    if (!value_fit_unsigned_field_p (opnd->imm.value, 16))
2498
0
      {
2499
0
        set_other_error (mismatch_detail, idx,
2500
0
             _("immediate out of range"));
2501
0
        return 0;
2502
0
      }
2503
0
    break;
2504
2505
0
  case AARCH64_OPND_IMM_MOV:
2506
0
      {
2507
0
        int esize = aarch64_get_qualifier_esize (opnds[0].qualifier);
2508
0
        imm = opnd->imm.value;
2509
0
        assert (idx == 1);
2510
0
        switch (opcode->op)
2511
0
    {
2512
0
    case OP_MOV_IMM_WIDEN:
2513
0
      imm = ~imm;
2514
      /* Fall through.  */
2515
0
    case OP_MOV_IMM_WIDE:
2516
0
      if (!aarch64_wide_constant_p (imm, esize == 4, NULL))
2517
0
        {
2518
0
          set_other_error (mismatch_detail, idx,
2519
0
               _("immediate out of range"));
2520
0
          return 0;
2521
0
        }
2522
0
      break;
2523
0
    case OP_MOV_IMM_LOG:
2524
0
      if (!aarch64_logical_immediate_p (imm, esize, NULL))
2525
0
        {
2526
0
          set_other_error (mismatch_detail, idx,
2527
0
               _("immediate out of range"));
2528
0
          return 0;
2529
0
        }
2530
0
      break;
2531
0
    default:
2532
0
      assert (0);
2533
0
      return 0;
2534
0
    }
2535
0
      }
2536
0
    break;
2537
2538
0
  case AARCH64_OPND_NZCV:
2539
0
  case AARCH64_OPND_CCMP_IMM:
2540
0
  case AARCH64_OPND_EXCEPTION:
2541
0
  case AARCH64_OPND_UNDEFINED:
2542
0
  case AARCH64_OPND_TME_UIMM16:
2543
0
  case AARCH64_OPND_UIMM4:
2544
0
  case AARCH64_OPND_UIMM4_ADDG:
2545
0
  case AARCH64_OPND_UIMM7:
2546
0
  case AARCH64_OPND_UIMM3_OP1:
2547
0
  case AARCH64_OPND_UIMM3_OP2:
2548
0
  case AARCH64_OPND_SVE_UIMM3:
2549
0
  case AARCH64_OPND_SVE_UIMM7:
2550
0
  case AARCH64_OPND_SVE_UIMM8:
2551
0
  case AARCH64_OPND_SVE_UIMM8_53:
2552
0
  case AARCH64_OPND_CSSC_UIMM8:
2553
0
    size = get_operand_fields_width (get_operand_from_code (type));
2554
0
    assert (size < 32);
2555
0
    if (!value_fit_unsigned_field_p (opnd->imm.value, size))
2556
0
      {
2557
0
        set_imm_out_of_range_error (mismatch_detail, idx, 0,
2558
0
            (1u << size) - 1);
2559
0
        return 0;
2560
0
      }
2561
0
    break;
2562
2563
0
  case AARCH64_OPND_UIMM10:
2564
    /* Scaled unsigned 10 bits immediate offset.  */
2565
0
    if (!value_in_range_p (opnd->imm.value, 0, 1008))
2566
0
      {
2567
0
        set_imm_out_of_range_error (mismatch_detail, idx, 0, 1008);
2568
0
        return 0;
2569
0
      }
2570
2571
0
    if (!value_aligned_p (opnd->imm.value, 16))
2572
0
      {
2573
0
        set_unaligned_error (mismatch_detail, idx, 16);
2574
0
        return 0;
2575
0
      }
2576
0
    break;
2577
2578
0
  case AARCH64_OPND_SIMM5:
2579
0
  case AARCH64_OPND_SVE_SIMM5:
2580
0
  case AARCH64_OPND_SVE_SIMM5B:
2581
0
  case AARCH64_OPND_SVE_SIMM6:
2582
0
  case AARCH64_OPND_SVE_SIMM8:
2583
0
  case AARCH64_OPND_CSSC_SIMM8:
2584
0
    size = get_operand_fields_width (get_operand_from_code (type));
2585
0
    assert (size < 32);
2586
0
    if (!value_fit_signed_field_p (opnd->imm.value, size))
2587
0
      {
2588
0
        set_imm_out_of_range_error (mismatch_detail, idx,
2589
0
            -(1 << (size - 1)),
2590
0
            (1 << (size - 1)) - 1);
2591
0
        return 0;
2592
0
      }
2593
0
    break;
2594
2595
0
  case AARCH64_OPND_WIDTH:
2596
0
    assert (idx > 1 && opnds[idx-1].type == AARCH64_OPND_IMM
2597
0
      && opnds[0].type == AARCH64_OPND_Rd);
2598
0
    size = get_upper_bound (qualifier);
2599
0
    if (opnd->imm.value + opnds[idx-1].imm.value > size)
2600
      /* lsb+width <= reg.size  */
2601
0
      {
2602
0
        set_imm_out_of_range_error (mismatch_detail, idx, 1,
2603
0
            size - opnds[idx-1].imm.value);
2604
0
        return 0;
2605
0
      }
2606
0
    break;
2607
2608
0
  case AARCH64_OPND_LIMM:
2609
0
  case AARCH64_OPND_SVE_LIMM:
2610
0
    {
2611
0
      int esize = aarch64_get_qualifier_esize (opnds[0].qualifier);
2612
0
      uint64_t uimm = opnd->imm.value;
2613
0
      if (opcode->op == OP_BIC)
2614
0
        uimm = ~uimm;
2615
0
      if (!aarch64_logical_immediate_p (uimm, esize, NULL))
2616
0
        {
2617
0
    set_other_error (mismatch_detail, idx,
2618
0
         _("immediate out of range"));
2619
0
    return 0;
2620
0
        }
2621
0
    }
2622
0
    break;
2623
2624
0
  case AARCH64_OPND_IMM0:
2625
0
  case AARCH64_OPND_FPIMM0:
2626
0
    if (opnd->imm.value != 0)
2627
0
      {
2628
0
        set_other_error (mismatch_detail, idx,
2629
0
             _("immediate zero expected"));
2630
0
        return 0;
2631
0
      }
2632
0
    break;
2633
2634
0
  case AARCH64_OPND_IMM_ROT1:
2635
0
  case AARCH64_OPND_IMM_ROT2:
2636
0
  case AARCH64_OPND_SVE_IMM_ROT2:
2637
0
    if (opnd->imm.value != 0
2638
0
        && opnd->imm.value != 90
2639
0
        && opnd->imm.value != 180
2640
0
        && opnd->imm.value != 270)
2641
0
      {
2642
0
        set_other_error (mismatch_detail, idx,
2643
0
             _("rotate expected to be 0, 90, 180 or 270"));
2644
0
        return 0;
2645
0
      }
2646
0
    break;
2647
2648
0
  case AARCH64_OPND_IMM_ROT3:
2649
0
  case AARCH64_OPND_SVE_IMM_ROT1:
2650
0
  case AARCH64_OPND_SVE_IMM_ROT3:
2651
0
    if (opnd->imm.value != 90 && opnd->imm.value != 270)
2652
0
      {
2653
0
        set_other_error (mismatch_detail, idx,
2654
0
             _("rotate expected to be 90 or 270"));
2655
0
        return 0;
2656
0
      }
2657
0
    break;
2658
2659
0
  case AARCH64_OPND_SHLL_IMM:
2660
0
    assert (idx == 2);
2661
0
    size = 8 * aarch64_get_qualifier_esize (opnds[idx - 1].qualifier);
2662
0
    if (opnd->imm.value != size)
2663
0
      {
2664
0
        set_other_error (mismatch_detail, idx,
2665
0
             _("invalid shift amount"));
2666
0
        return 0;
2667
0
      }
2668
0
    break;
2669
2670
0
  case AARCH64_OPND_IMM_VLSL:
2671
0
    size = aarch64_get_qualifier_esize (qualifier);
2672
0
    if (!value_in_range_p (opnd->imm.value, 0, size * 8 - 1))
2673
0
      {
2674
0
        set_imm_out_of_range_error (mismatch_detail, idx, 0,
2675
0
            size * 8 - 1);
2676
0
        return 0;
2677
0
      }
2678
0
    break;
2679
2680
0
  case AARCH64_OPND_IMM_VLSR:
2681
0
    size = aarch64_get_qualifier_esize (qualifier);
2682
0
    if (!value_in_range_p (opnd->imm.value, 1, size * 8))
2683
0
      {
2684
0
        set_imm_out_of_range_error (mismatch_detail, idx, 1, size * 8);
2685
0
        return 0;
2686
0
      }
2687
0
    break;
2688
2689
0
  case AARCH64_OPND_SIMD_IMM:
2690
0
  case AARCH64_OPND_SIMD_IMM_SFT:
2691
    /* Qualifier check.  */
2692
0
    switch (qualifier)
2693
0
      {
2694
0
      case AARCH64_OPND_QLF_LSL:
2695
0
        if (opnd->shifter.kind != AARCH64_MOD_LSL)
2696
0
    {
2697
0
      set_other_error (mismatch_detail, idx,
2698
0
           _("invalid shift operator"));
2699
0
      return 0;
2700
0
    }
2701
0
        break;
2702
0
      case AARCH64_OPND_QLF_MSL:
2703
0
        if (opnd->shifter.kind != AARCH64_MOD_MSL)
2704
0
    {
2705
0
      set_other_error (mismatch_detail, idx,
2706
0
           _("invalid shift operator"));
2707
0
      return 0;
2708
0
    }
2709
0
        break;
2710
0
      case AARCH64_OPND_QLF_NIL:
2711
0
        if (opnd->shifter.kind != AARCH64_MOD_NONE)
2712
0
    {
2713
0
      set_other_error (mismatch_detail, idx,
2714
0
           _("shift is not permitted"));
2715
0
      return 0;
2716
0
    }
2717
0
        break;
2718
0
      default:
2719
0
        assert (0);
2720
0
        return 0;
2721
0
      }
2722
    /* Is the immediate valid?  */
2723
0
    assert (idx == 1);
2724
0
    if (aarch64_get_qualifier_esize (opnds[0].qualifier) != 8)
2725
0
      {
2726
        /* uimm8 or simm8 */
2727
0
        if (!value_in_range_p (opnd->imm.value, -128, 255))
2728
0
    {
2729
0
      set_imm_out_of_range_error (mismatch_detail, idx, -128, 255);
2730
0
      return 0;
2731
0
    }
2732
0
      }
2733
0
    else if (aarch64_shrink_expanded_imm8 (opnd->imm.value) < 0)
2734
0
      {
2735
        /* uimm64 is not
2736
     'aaaaaaaabbbbbbbbccccccccddddddddeeeeeeee
2737
     ffffffffgggggggghhhhhhhh'.  */
2738
0
        set_other_error (mismatch_detail, idx,
2739
0
             _("invalid value for immediate"));
2740
0
        return 0;
2741
0
      }
2742
    /* Is the shift amount valid?  */
2743
0
    switch (opnd->shifter.kind)
2744
0
      {
2745
0
      case AARCH64_MOD_LSL:
2746
0
        size = aarch64_get_qualifier_esize (opnds[0].qualifier);
2747
0
        if (!value_in_range_p (opnd->shifter.amount, 0, (size - 1) * 8))
2748
0
    {
2749
0
      set_sft_amount_out_of_range_error (mismatch_detail, idx, 0,
2750
0
                 (size - 1) * 8);
2751
0
      return 0;
2752
0
    }
2753
0
        if (!value_aligned_p (opnd->shifter.amount, 8))
2754
0
    {
2755
0
      set_unaligned_error (mismatch_detail, idx, 8);
2756
0
      return 0;
2757
0
    }
2758
0
        break;
2759
0
      case AARCH64_MOD_MSL:
2760
        /* Only 8 and 16 are valid shift amount.  */
2761
0
        if (opnd->shifter.amount != 8 && opnd->shifter.amount != 16)
2762
0
    {
2763
0
      set_other_error (mismatch_detail, idx,
2764
0
           _("shift amount must be 0 or 16"));
2765
0
      return 0;
2766
0
    }
2767
0
        break;
2768
0
      default:
2769
0
        if (opnd->shifter.kind != AARCH64_MOD_NONE)
2770
0
    {
2771
0
      set_other_error (mismatch_detail, idx,
2772
0
           _("invalid shift operator"));
2773
0
      return 0;
2774
0
    }
2775
0
        break;
2776
0
      }
2777
0
    break;
2778
2779
0
  case AARCH64_OPND_FPIMM:
2780
0
  case AARCH64_OPND_SIMD_FPIMM:
2781
0
  case AARCH64_OPND_SVE_FPIMM8:
2782
0
    if (opnd->imm.is_fp == 0)
2783
0
      {
2784
0
        set_other_error (mismatch_detail, idx,
2785
0
             _("floating-point immediate expected"));
2786
0
        return 0;
2787
0
      }
2788
    /* The value is expected to be an 8-bit floating-point constant with
2789
       sign, 3-bit exponent and normalized 4 bits of precision, encoded
2790
       in "a:b:c:d:e:f:g:h" or FLD_imm8 (depending on the type of the
2791
       instruction).  */
2792
0
    if (!value_in_range_p (opnd->imm.value, 0, 255))
2793
0
      {
2794
0
        set_other_error (mismatch_detail, idx,
2795
0
             _("immediate out of range"));
2796
0
        return 0;
2797
0
      }
2798
0
    if (opnd->shifter.kind != AARCH64_MOD_NONE)
2799
0
      {
2800
0
        set_other_error (mismatch_detail, idx,
2801
0
             _("invalid shift operator"));
2802
0
        return 0;
2803
0
      }
2804
0
    break;
2805
2806
0
  case AARCH64_OPND_SVE_AIMM:
2807
0
    min_value = 0;
2808
0
  sve_aimm:
2809
0
    assert (opnd->shifter.kind == AARCH64_MOD_LSL);
2810
0
    size = aarch64_get_qualifier_esize (opnds[0].qualifier);
2811
0
    mask = ~((uint64_t) -1 << (size * 4) << (size * 4));
2812
0
    uvalue = opnd->imm.value;
2813
0
    shift = opnd->shifter.amount;
2814
0
    if (size == 1)
2815
0
      {
2816
0
        if (shift != 0)
2817
0
    {
2818
0
      set_other_error (mismatch_detail, idx,
2819
0
           _("no shift amount allowed for"
2820
0
             " 8-bit constants"));
2821
0
      return 0;
2822
0
    }
2823
0
      }
2824
0
    else
2825
0
      {
2826
0
        if (shift != 0 && shift != 8)
2827
0
    {
2828
0
      set_other_error (mismatch_detail, idx,
2829
0
           _("shift amount must be 0 or 8"));
2830
0
      return 0;
2831
0
    }
2832
0
        if (shift == 0 && (uvalue & 0xff) == 0)
2833
0
    {
2834
0
      shift = 8;
2835
0
      uvalue = (int64_t) uvalue / 256;
2836
0
    }
2837
0
      }
2838
0
    mask >>= shift;
2839
0
    if ((uvalue & mask) != uvalue && (uvalue | ~mask) != uvalue)
2840
0
      {
2841
0
        set_other_error (mismatch_detail, idx,
2842
0
             _("immediate too big for element size"));
2843
0
        return 0;
2844
0
      }
2845
0
    uvalue = (uvalue - min_value) & mask;
2846
0
    if (uvalue > 0xff)
2847
0
      {
2848
0
        set_other_error (mismatch_detail, idx,
2849
0
             _("invalid arithmetic immediate"));
2850
0
        return 0;
2851
0
      }
2852
0
    break;
2853
2854
0
  case AARCH64_OPND_SVE_ASIMM:
2855
0
    min_value = -128;
2856
0
    goto sve_aimm;
2857
2858
0
  case AARCH64_OPND_SVE_I1_HALF_ONE:
2859
0
    assert (opnd->imm.is_fp);
2860
0
    if (opnd->imm.value != 0x3f000000 && opnd->imm.value != 0x3f800000)
2861
0
      {
2862
0
        set_other_error (mismatch_detail, idx,
2863
0
             _("floating-point value must be 0.5 or 1.0"));
2864
0
        return 0;
2865
0
      }
2866
0
    break;
2867
2868
0
  case AARCH64_OPND_SVE_I1_HALF_TWO:
2869
0
    assert (opnd->imm.is_fp);
2870
0
    if (opnd->imm.value != 0x3f000000 && opnd->imm.value != 0x40000000)
2871
0
      {
2872
0
        set_other_error (mismatch_detail, idx,
2873
0
             _("floating-point value must be 0.5 or 2.0"));
2874
0
        return 0;
2875
0
      }
2876
0
    break;
2877
2878
0
  case AARCH64_OPND_SVE_I1_ZERO_ONE:
2879
0
    assert (opnd->imm.is_fp);
2880
0
    if (opnd->imm.value != 0 && opnd->imm.value != 0x3f800000)
2881
0
      {
2882
0
        set_other_error (mismatch_detail, idx,
2883
0
             _("floating-point value must be 0.0 or 1.0"));
2884
0
        return 0;
2885
0
      }
2886
0
    break;
2887
2888
0
  case AARCH64_OPND_SVE_INV_LIMM:
2889
0
    {
2890
0
      int esize = aarch64_get_qualifier_esize (opnds[0].qualifier);
2891
0
      uint64_t uimm = ~opnd->imm.value;
2892
0
      if (!aarch64_logical_immediate_p (uimm, esize, NULL))
2893
0
        {
2894
0
    set_other_error (mismatch_detail, idx,
2895
0
         _("immediate out of range"));
2896
0
    return 0;
2897
0
        }
2898
0
    }
2899
0
    break;
2900
2901
0
  case AARCH64_OPND_SVE_LIMM_MOV:
2902
0
    {
2903
0
      int esize = aarch64_get_qualifier_esize (opnds[0].qualifier);
2904
0
      uint64_t uimm = opnd->imm.value;
2905
0
      if (!aarch64_logical_immediate_p (uimm, esize, NULL))
2906
0
        {
2907
0
    set_other_error (mismatch_detail, idx,
2908
0
         _("immediate out of range"));
2909
0
    return 0;
2910
0
        }
2911
0
      if (!aarch64_sve_dupm_mov_immediate_p (uimm, esize))
2912
0
        {
2913
0
    set_other_error (mismatch_detail, idx,
2914
0
         _("invalid replicated MOV immediate"));
2915
0
    return 0;
2916
0
        }
2917
0
    }
2918
0
    break;
2919
2920
0
  case AARCH64_OPND_SVE_PATTERN_SCALED:
2921
0
    assert (opnd->shifter.kind == AARCH64_MOD_MUL);
2922
0
    if (!value_in_range_p (opnd->shifter.amount, 1, 16))
2923
0
      {
2924
0
        set_multiplier_out_of_range_error (mismatch_detail, idx, 1, 16);
2925
0
        return 0;
2926
0
      }
2927
0
    break;
2928
2929
0
  case AARCH64_OPND_SVE_SHLIMM_PRED:
2930
0
  case AARCH64_OPND_SVE_SHLIMM_UNPRED:
2931
0
  case AARCH64_OPND_SVE_SHLIMM_UNPRED_22:
2932
0
    size = aarch64_get_qualifier_esize (opnds[idx - 1].qualifier);
2933
0
    if (!value_in_range_p (opnd->imm.value, 0, 8 * size - 1))
2934
0
      {
2935
0
        set_imm_out_of_range_error (mismatch_detail, idx,
2936
0
            0, 8 * size - 1);
2937
0
        return 0;
2938
0
      }
2939
0
    break;
2940
2941
0
  case AARCH64_OPND_SME_SHRIMM4:
2942
0
    size = 1 << get_operand_fields_width (get_operand_from_code (type));
2943
0
    if (!value_in_range_p (opnd->imm.value, 1, size))
2944
0
      {
2945
0
        set_imm_out_of_range_error (mismatch_detail, idx, 1, size);
2946
0
        return 0;
2947
0
      }
2948
0
    break;
2949
2950
0
  case AARCH64_OPND_SME_SHRIMM5:
2951
0
  case AARCH64_OPND_SVE_SHRIMM_PRED:
2952
0
  case AARCH64_OPND_SVE_SHRIMM_UNPRED:
2953
0
  case AARCH64_OPND_SVE_SHRIMM_UNPRED_22:
2954
0
    num = (type == AARCH64_OPND_SVE_SHRIMM_UNPRED_22) ? 2 : 1;
2955
0
    size = aarch64_get_qualifier_esize (opnds[idx - num].qualifier);
2956
0
    if (!value_in_range_p (opnd->imm.value, 1, 8 * size))
2957
0
      {
2958
0
        set_imm_out_of_range_error (mismatch_detail, idx, 1, 8*size);
2959
0
        return 0;
2960
0
      }
2961
0
    break;
2962
2963
0
  case AARCH64_OPND_SME_ZT0_INDEX:
2964
0
    if (!value_in_range_p (opnd->imm.value, 0, 56))
2965
0
      {
2966
0
        set_elem_idx_out_of_range_error (mismatch_detail, idx, 0, 56);
2967
0
        return 0;
2968
0
      }
2969
0
    if (opnd->imm.value % 8 != 0)
2970
0
      {
2971
0
        set_other_error (mismatch_detail, idx,
2972
0
             _("byte index must be a multiple of 8"));
2973
0
        return 0;
2974
0
      }
2975
0
    break;
2976
2977
0
  default:
2978
0
    break;
2979
0
  }
2980
0
      break;
2981
2982
0
    case AARCH64_OPND_CLASS_SYSTEM:
2983
0
      switch (type)
2984
0
  {
2985
0
  case AARCH64_OPND_PSTATEFIELD:
2986
0
    for (i = 0; aarch64_pstatefields[i].name; ++i)
2987
0
      if (aarch64_pstatefields[i].value == opnd->pstatefield)
2988
0
        break;
2989
0
    assert (aarch64_pstatefields[i].name);
2990
0
    assert (idx == 0 && opnds[1].type == AARCH64_OPND_UIMM4);
2991
0
    max_value = F_GET_REG_MAX_VALUE (aarch64_pstatefields[i].flags);
2992
0
    if (opnds[1].imm.value < 0 || opnds[1].imm.value > max_value)
2993
0
      {
2994
0
        set_imm_out_of_range_error (mismatch_detail, 1, 0, max_value);
2995
0
        return 0;
2996
0
      }
2997
0
    break;
2998
0
  case AARCH64_OPND_PRFOP:
2999
0
    if (opcode->iclass == ldst_regoff && opnd->prfop->value >= 24)
3000
0
      {
3001
0
        set_other_error (mismatch_detail, idx,
3002
0
             _("the register-index form of PRFM does"
3003
0
         " not accept opcodes in the range 24-31"));
3004
0
        return 0;
3005
0
      }
3006
0
    break;
3007
0
  default:
3008
0
    break;
3009
0
  }
3010
0
      break;
3011
3012
0
    case AARCH64_OPND_CLASS_SIMD_ELEMENT:
3013
      /* Get the upper bound for the element index.  */
3014
0
      if (opcode->op == OP_FCMLA_ELEM)
3015
  /* FCMLA index range depends on the vector size of other operands
3016
     and is halfed because complex numbers take two elements.  */
3017
0
  num = aarch64_get_qualifier_nelem (opnds[0].qualifier)
3018
0
        * aarch64_get_qualifier_esize (opnds[0].qualifier) / 2;
3019
0
      else
3020
0
  num = 16;
3021
0
      num = num / aarch64_get_qualifier_esize (qualifier) - 1;
3022
0
      assert (aarch64_get_qualifier_nelem (qualifier) == 1);
3023
3024
      /* Index out-of-range.  */
3025
0
      if (!value_in_range_p (opnd->reglane.index, 0, num))
3026
0
  {
3027
0
    set_elem_idx_out_of_range_error (mismatch_detail, idx, 0, num);
3028
0
    return 0;
3029
0
  }
3030
      /* SMLAL<Q> <Vd>.<Ta>, <Vn>.<Tb>, <Vm>.<Ts>[<index>].
3031
   <Vm> Is the vector register (V0-V31) or (V0-V15), whose
3032
   number is encoded in "size:M:Rm":
3033
   size <Vm>
3034
   00   RESERVED
3035
   01   0:Rm
3036
   10   M:Rm
3037
   11   RESERVED  */
3038
0
      if (type == AARCH64_OPND_Em16 && qualifier == AARCH64_OPND_QLF_S_H
3039
0
    && !value_in_range_p (opnd->reglane.regno, 0, 15))
3040
0
  {
3041
0
    set_regno_out_of_range_error (mismatch_detail, idx, 0, 15);
3042
0
    return 0;
3043
0
  }
3044
0
      break;
3045
3046
0
    case AARCH64_OPND_CLASS_MODIFIED_REG:
3047
0
      assert (idx == 1 || idx == 2);
3048
0
      switch (type)
3049
0
  {
3050
0
  case AARCH64_OPND_Rm_EXT:
3051
0
    if (!aarch64_extend_operator_p (opnd->shifter.kind)
3052
0
        && opnd->shifter.kind != AARCH64_MOD_LSL)
3053
0
      {
3054
0
        set_other_error (mismatch_detail, idx,
3055
0
             _("extend operator expected"));
3056
0
        return 0;
3057
0
      }
3058
    /* It is not optional unless at least one of "Rd" or "Rn" is '11111'
3059
       (i.e. SP), in which case it defaults to LSL. The LSL alias is
3060
       only valid when "Rd" or "Rn" is '11111', and is preferred in that
3061
       case.  */
3062
0
    if (!aarch64_stack_pointer_p (opnds + 0)
3063
0
        && (idx != 2 || !aarch64_stack_pointer_p (opnds + 1)))
3064
0
      {
3065
0
        if (!opnd->shifter.operator_present)
3066
0
    {
3067
0
      set_other_error (mismatch_detail, idx,
3068
0
           _("missing extend operator"));
3069
0
      return 0;
3070
0
    }
3071
0
        else if (opnd->shifter.kind == AARCH64_MOD_LSL)
3072
0
    {
3073
0
      set_other_error (mismatch_detail, idx,
3074
0
           _("'LSL' operator not allowed"));
3075
0
      return 0;
3076
0
    }
3077
0
      }
3078
0
    assert (opnd->shifter.operator_present  /* Default to LSL.  */
3079
0
      || opnd->shifter.kind == AARCH64_MOD_LSL);
3080
0
    if (!value_in_range_p (opnd->shifter.amount, 0, 4))
3081
0
      {
3082
0
        set_sft_amount_out_of_range_error (mismatch_detail, idx, 0, 4);
3083
0
        return 0;
3084
0
      }
3085
    /* In the 64-bit form, the final register operand is written as Wm
3086
       for all but the (possibly omitted) UXTX/LSL and SXTX
3087
       operators.
3088
       N.B. GAS allows X register to be used with any operator as a
3089
       programming convenience.  */
3090
0
    if (qualifier == AARCH64_OPND_QLF_X
3091
0
        && opnd->shifter.kind != AARCH64_MOD_LSL
3092
0
        && opnd->shifter.kind != AARCH64_MOD_UXTX
3093
0
        && opnd->shifter.kind != AARCH64_MOD_SXTX)
3094
0
      {
3095
0
        set_other_error (mismatch_detail, idx, _("W register expected"));
3096
0
        return 0;
3097
0
      }
3098
0
    break;
3099
3100
0
  case AARCH64_OPND_Rm_SFT:
3101
    /* ROR is not available to the shifted register operand in
3102
       arithmetic instructions.  */
3103
0
    if (!aarch64_shift_operator_p (opnd->shifter.kind))
3104
0
      {
3105
0
        set_other_error (mismatch_detail, idx,
3106
0
             _("shift operator expected"));
3107
0
        return 0;
3108
0
      }
3109
0
    if (opnd->shifter.kind == AARCH64_MOD_ROR
3110
0
        && opcode->iclass != log_shift)
3111
0
      {
3112
0
        set_other_error (mismatch_detail, idx,
3113
0
             _("'ROR' operator not allowed"));
3114
0
        return 0;
3115
0
      }
3116
0
    num = qualifier == AARCH64_OPND_QLF_W ? 31 : 63;
3117
0
    if (!value_in_range_p (opnd->shifter.amount, 0, num))
3118
0
      {
3119
0
        set_sft_amount_out_of_range_error (mismatch_detail, idx, 0, num);
3120
0
        return 0;
3121
0
      }
3122
0
    break;
3123
3124
0
  default:
3125
0
    break;
3126
0
  }
3127
0
      break;
3128
3129
0
    default:
3130
0
      break;
3131
0
    }
3132
3133
0
  return 1;
3134
0
}
3135
3136
/* Main entrypoint for the operand constraint checking.
3137
3138
   Return 1 if operands of *INST meet the constraint applied by the operand
3139
   codes and operand qualifiers; otherwise return 0 and if MISMATCH_DETAIL is
3140
   not NULL, return the detail of the error in *MISMATCH_DETAIL.  N.B. when
3141
   adding more constraint checking, make sure MISMATCH_DETAIL->KIND is set
3142
   with a proper error kind rather than AARCH64_OPDE_NIL (GAS asserts non-NIL
3143
   error kind when it is notified that an instruction does not pass the check).
3144
3145
   Un-determined operand qualifiers may get established during the process.  */
3146
3147
int
3148
aarch64_match_operands_constraint (aarch64_inst *inst,
3149
           aarch64_operand_error *mismatch_detail)
3150
0
{
3151
0
  int i;
3152
3153
0
  DEBUG_TRACE ("enter");
3154
3155
0
  i = inst->opcode->tied_operand;
3156
3157
0
  if (i > 0)
3158
0
    {
3159
      /* Check for tied_operands with specific opcode iclass.  */
3160
0
      switch (inst->opcode->iclass)
3161
0
        {
3162
        /* For SME LDR and STR instructions #imm must have the same numerical
3163
           value for both operands.
3164
        */
3165
0
        case sme_ldr:
3166
0
        case sme_str:
3167
0
          assert (inst->operands[0].type == AARCH64_OPND_SME_ZA_array_off4);
3168
0
          assert (inst->operands[1].type == AARCH64_OPND_SME_ADDR_RI_U4xVL);
3169
0
          if (inst->operands[0].indexed_za.index.imm
3170
0
              != inst->operands[1].addr.offset.imm)
3171
0
            {
3172
0
              if (mismatch_detail)
3173
0
                {
3174
0
                  mismatch_detail->kind = AARCH64_OPDE_UNTIED_IMMS;
3175
0
                  mismatch_detail->index = i;
3176
0
                }
3177
0
              return 0;
3178
0
            }
3179
0
          break;
3180
3181
0
        default:
3182
0
    {
3183
      /* Check for cases where a source register needs to be the
3184
         same as the destination register.  Do this before
3185
         matching qualifiers since if an instruction has both
3186
         invalid tying and invalid qualifiers, the error about
3187
         qualifiers would suggest several alternative instructions
3188
         that also have invalid tying.  */
3189
0
      enum aarch64_operand_class op_class1
3190
0
         = aarch64_get_operand_class (inst->operands[0].type);
3191
0
      enum aarch64_operand_class op_class2
3192
0
         = aarch64_get_operand_class (inst->operands[i].type);
3193
0
      assert (op_class1 == op_class2);
3194
0
      if (op_class1 == AARCH64_OPND_CLASS_SVE_REGLIST
3195
0
    ? ((inst->operands[0].reglist.first_regno
3196
0
        != inst->operands[i].reglist.first_regno)
3197
0
       || (inst->operands[0].reglist.num_regs
3198
0
           != inst->operands[i].reglist.num_regs)
3199
0
       || (inst->operands[0].reglist.stride
3200
0
           != inst->operands[i].reglist.stride))
3201
0
    : (inst->operands[0].reg.regno
3202
0
       != inst->operands[i].reg.regno))
3203
0
        {
3204
0
    if (mismatch_detail)
3205
0
      {
3206
0
        mismatch_detail->kind = AARCH64_OPDE_UNTIED_OPERAND;
3207
0
        mismatch_detail->index = i;
3208
0
        mismatch_detail->error = NULL;
3209
0
      }
3210
0
    return 0;
3211
0
        }
3212
0
      break;
3213
0
    }
3214
0
        }
3215
0
    }
3216
3217
  /* Match operands' qualifier.
3218
     *INST has already had qualifier establish for some, if not all, of
3219
     its operands; we need to find out whether these established
3220
     qualifiers match one of the qualifier sequence in
3221
     INST->OPCODE->QUALIFIERS_LIST.  If yes, we will assign each operand
3222
     with the corresponding qualifier in such a sequence.
3223
     Only basic operand constraint checking is done here; the more thorough
3224
     constraint checking will carried out by operand_general_constraint_met_p,
3225
     which has be to called after this in order to get all of the operands'
3226
     qualifiers established.  */
3227
0
  int invalid_count;
3228
0
  if (match_operands_qualifier (inst, true /* update_p */,
3229
0
        &invalid_count) == 0)
3230
0
    {
3231
0
      DEBUG_TRACE ("FAIL on operand qualifier matching");
3232
0
      if (mismatch_detail)
3233
0
  {
3234
    /* Return an error type to indicate that it is the qualifier
3235
       matching failure; we don't care about which operand as there
3236
       are enough information in the opcode table to reproduce it.  */
3237
0
    mismatch_detail->kind = AARCH64_OPDE_INVALID_VARIANT;
3238
0
    mismatch_detail->index = -1;
3239
0
    mismatch_detail->error = NULL;
3240
0
    mismatch_detail->data[0].i = invalid_count;
3241
0
  }
3242
0
      return 0;
3243
0
    }
3244
3245
  /* Match operands' constraint.  */
3246
0
  for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
3247
0
    {
3248
0
      enum aarch64_opnd type = inst->opcode->operands[i];
3249
0
      if (type == AARCH64_OPND_NIL)
3250
0
  break;
3251
0
      if (inst->operands[i].skip)
3252
0
  {
3253
0
    DEBUG_TRACE ("skip the incomplete operand %d", i);
3254
0
    continue;
3255
0
  }
3256
0
      if (operand_general_constraint_met_p (inst->operands, i, type,
3257
0
              inst->opcode, mismatch_detail) == 0)
3258
0
  {
3259
0
    DEBUG_TRACE ("FAIL on operand %d", i);
3260
0
    return 0;
3261
0
  }
3262
0
    }
3263
3264
0
  DEBUG_TRACE ("PASS");
3265
3266
0
  return 1;
3267
0
}
3268
3269
/* Replace INST->OPCODE with OPCODE and return the replaced OPCODE.
3270
   Also updates the TYPE of each INST->OPERANDS with the corresponding
3271
   value of OPCODE->OPERANDS.
3272
3273
   Note that some operand qualifiers may need to be manually cleared by
3274
   the caller before it further calls the aarch64_opcode_encode; by
3275
   doing this, it helps the qualifier matching facilities work
3276
   properly.  */
3277
3278
const aarch64_opcode*
3279
aarch64_replace_opcode (aarch64_inst *inst, const aarch64_opcode *opcode)
3280
0
{
3281
0
  int i;
3282
0
  const aarch64_opcode *old = inst->opcode;
3283
3284
0
  inst->opcode = opcode;
3285
3286
  /* Update the operand types.  */
3287
0
  for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
3288
0
    {
3289
0
      inst->operands[i].type = opcode->operands[i];
3290
0
      if (opcode->operands[i] == AARCH64_OPND_NIL)
3291
0
  break;
3292
0
    }
3293
3294
0
  DEBUG_TRACE ("replace %s with %s", old->name, opcode->name);
3295
3296
0
  return old;
3297
0
}
3298
3299
int
3300
aarch64_operand_index (const enum aarch64_opnd *operands, enum aarch64_opnd operand)
3301
0
{
3302
0
  int i;
3303
0
  for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
3304
0
    if (operands[i] == operand)
3305
0
      return i;
3306
0
    else if (operands[i] == AARCH64_OPND_NIL)
3307
0
      break;
3308
0
  return -1;
3309
0
}
3310

3311
/* R0...R30, followed by FOR31.  */
3312
#define BANK(R, FOR31) \
3313
  { R  (0), R  (1), R  (2), R  (3), R  (4), R  (5), R  (6), R  (7), \
3314
    R  (8), R  (9), R (10), R (11), R (12), R (13), R (14), R (15), \
3315
    R (16), R (17), R (18), R (19), R (20), R (21), R (22), R (23), \
3316
    R (24), R (25), R (26), R (27), R (28), R (29), R (30),  FOR31 }
3317
/* [0][0]  32-bit integer regs with sp   Wn
3318
   [0][1]  64-bit integer regs with sp   Xn  sf=1
3319
   [1][0]  32-bit integer regs with #0   Wn
3320
   [1][1]  64-bit integer regs with #0   Xn  sf=1 */
3321
static const char *int_reg[2][2][32] = {
3322
#define R32(X) "w" #X
3323
#define R64(X) "x" #X
3324
  { BANK (R32, "wsp"), BANK (R64, "sp") },
3325
  { BANK (R32, "wzr"), BANK (R64, "xzr") }
3326
#undef R64
3327
#undef R32
3328
};
3329
3330
/* Names of the SVE vector registers, first with .S suffixes,
3331
   then with .D suffixes.  */
3332
3333
static const char *sve_reg[2][32] = {
3334
#define ZS(X) "z" #X ".s"
3335
#define ZD(X) "z" #X ".d"
3336
  BANK (ZS, ZS (31)), BANK (ZD, ZD (31))
3337
#undef ZD
3338
#undef ZS
3339
};
3340
#undef BANK
3341
3342
/* Return the integer register name.
3343
   if SP_REG_P is not 0, R31 is an SP reg, other R31 is the zero reg.  */
3344
3345
static inline const char *
3346
get_int_reg_name (int regno, aarch64_opnd_qualifier_t qualifier, int sp_reg_p)
3347
0
{
3348
0
  const int has_zr = sp_reg_p ? 0 : 1;
3349
0
  const int is_64 = aarch64_get_qualifier_esize (qualifier) == 4 ? 0 : 1;
3350
0
  return int_reg[has_zr][is_64][regno];
3351
0
}
3352
3353
/* Like get_int_reg_name, but IS_64 is always 1.  */
3354
3355
static inline const char *
3356
get_64bit_int_reg_name (int regno, int sp_reg_p)
3357
0
{
3358
0
  const int has_zr = sp_reg_p ? 0 : 1;
3359
0
  return int_reg[has_zr][1][regno];
3360
0
}
3361
3362
/* Get the name of the integer offset register in OPND, using the shift type
3363
   to decide whether it's a word or doubleword.  */
3364
3365
static inline const char *
3366
get_offset_int_reg_name (const aarch64_opnd_info *opnd)
3367
0
{
3368
0
  switch (opnd->shifter.kind)
3369
0
    {
3370
0
    case AARCH64_MOD_UXTW:
3371
0
    case AARCH64_MOD_SXTW:
3372
0
      return get_int_reg_name (opnd->addr.offset.regno, AARCH64_OPND_QLF_W, 0);
3373
3374
0
    case AARCH64_MOD_LSL:
3375
0
    case AARCH64_MOD_SXTX:
3376
0
      return get_int_reg_name (opnd->addr.offset.regno, AARCH64_OPND_QLF_X, 0);
3377
3378
0
    default:
3379
0
      abort ();
3380
0
    }
3381
0
}
3382
3383
/* Get the name of the SVE vector offset register in OPND, using the operand
3384
   qualifier to decide whether the suffix should be .S or .D.  */
3385
3386
static inline const char *
3387
get_addr_sve_reg_name (int regno, aarch64_opnd_qualifier_t qualifier)
3388
0
{
3389
0
  assert (qualifier == AARCH64_OPND_QLF_S_S
3390
0
    || qualifier == AARCH64_OPND_QLF_S_D);
3391
0
  return sve_reg[qualifier == AARCH64_OPND_QLF_S_D][regno];
3392
0
}
3393
3394
/* Types for expanding an encoded 8-bit value to a floating-point value.  */
3395
3396
typedef union
3397
{
3398
  uint64_t i;
3399
  double   d;
3400
} double_conv_t;
3401
3402
typedef union
3403
{
3404
  uint32_t i;
3405
  float    f;
3406
} single_conv_t;
3407
3408
typedef union
3409
{
3410
  uint32_t i;
3411
  float    f;
3412
} half_conv_t;
3413
3414
/* IMM8 is an 8-bit floating-point constant with sign, 3-bit exponent and
3415
   normalized 4 bits of precision, encoded in "a:b:c:d:e:f:g:h" or FLD_imm8
3416
   (depending on the type of the instruction).  IMM8 will be expanded to a
3417
   single-precision floating-point value (SIZE == 4) or a double-precision
3418
   floating-point value (SIZE == 8).  A half-precision floating-point value
3419
   (SIZE == 2) is expanded to a single-precision floating-point value.  The
3420
   expanded value is returned.  */
3421
3422
static uint64_t
3423
expand_fp_imm (int size, uint32_t imm8)
3424
0
{
3425
0
  uint64_t imm = 0;
3426
0
  uint32_t imm8_7, imm8_6_0, imm8_6, imm8_6_repl4;
3427
3428
0
  imm8_7 = (imm8 >> 7) & 0x01;  /* imm8<7>   */
3429
0
  imm8_6_0 = imm8 & 0x7f; /* imm8<6:0> */
3430
0
  imm8_6 = imm8_6_0 >> 6; /* imm8<6>   */
3431
0
  imm8_6_repl4 = (imm8_6 << 3) | (imm8_6 << 2)
3432
0
    | (imm8_6 << 1) | imm8_6; /* Replicate(imm8<6>,4) */
3433
0
  if (size == 8)
3434
0
    {
3435
0
      imm = (imm8_7 << (63-32))   /* imm8<7>  */
3436
0
  | ((imm8_6 ^ 1) << (62-32)) /* NOT(imm8<6)  */
3437
0
  | (imm8_6_repl4 << (58-32)) | (imm8_6 << (57-32))
3438
0
  | (imm8_6 << (56-32)) | (imm8_6 << (55-32)) /* Replicate(imm8<6>,7) */
3439
0
  | (imm8_6_0 << (48-32));  /* imm8<6>:imm8<5:0>    */
3440
0
      imm <<= 32;
3441
0
    }
3442
0
  else if (size == 4 || size == 2)
3443
0
    {
3444
0
      imm = (imm8_7 << 31)  /* imm8<7>              */
3445
0
  | ((imm8_6 ^ 1) << 30)  /* NOT(imm8<6>)         */
3446
0
  | (imm8_6_repl4 << 26)  /* Replicate(imm8<6>,4) */
3447
0
  | (imm8_6_0 << 19); /* imm8<6>:imm8<5:0>    */
3448
0
    }
3449
0
  else
3450
0
    {
3451
      /* An unsupported size.  */
3452
0
      assert (0);
3453
0
    }
3454
3455
0
  return imm;
3456
0
}
3457
3458
/* Return a string based on FMT with the register style applied.  */
3459
3460
static const char *
3461
style_reg (struct aarch64_styler *styler, const char *fmt, ...)
3462
0
{
3463
0
  const char *txt;
3464
0
  va_list ap;
3465
3466
0
  va_start (ap, fmt);
3467
0
  txt = styler->apply_style (styler, dis_style_register, fmt, ap);
3468
0
  va_end (ap);
3469
3470
0
  return txt;
3471
0
}
3472
3473
/* Return a string based on FMT with the immediate style applied.  */
3474
3475
static const char *
3476
style_imm (struct aarch64_styler *styler, const char *fmt, ...)
3477
0
{
3478
0
  const char *txt;
3479
0
  va_list ap;
3480
3481
0
  va_start (ap, fmt);
3482
0
  txt = styler->apply_style (styler, dis_style_immediate, fmt, ap);
3483
0
  va_end (ap);
3484
3485
0
  return txt;
3486
0
}
3487
3488
/* Return a string based on FMT with the sub-mnemonic style applied.  */
3489
3490
static const char *
3491
style_sub_mnem (struct aarch64_styler *styler, const char *fmt, ...)
3492
0
{
3493
0
  const char *txt;
3494
0
  va_list ap;
3495
3496
0
  va_start (ap, fmt);
3497
0
  txt = styler->apply_style (styler, dis_style_sub_mnemonic, fmt, ap);
3498
0
  va_end (ap);
3499
3500
0
  return txt;
3501
0
}
3502
3503
/* Return a string based on FMT with the address style applied.  */
3504
3505
static const char *
3506
style_addr (struct aarch64_styler *styler, const char *fmt, ...)
3507
0
{
3508
0
  const char *txt;
3509
0
  va_list ap;
3510
3511
0
  va_start (ap, fmt);
3512
0
  txt = styler->apply_style (styler, dis_style_address, fmt, ap);
3513
0
  va_end (ap);
3514
3515
0
  return txt;
3516
0
}
3517
3518
/* Produce the string representation of the register list operand *OPND
3519
   in the buffer pointed by BUF of size SIZE.  PREFIX is the part of
3520
   the register name that comes before the register number, such as "v".  */
3521
static void
3522
print_register_list (char *buf, size_t size, const aarch64_opnd_info *opnd,
3523
         const char *prefix, struct aarch64_styler *styler)
3524
0
{
3525
0
  const int mask = (prefix[0] == 'p' ? 15 : 31);
3526
0
  const int num_regs = opnd->reglist.num_regs;
3527
0
  const int stride = opnd->reglist.stride;
3528
0
  const int first_reg = opnd->reglist.first_regno;
3529
0
  const int last_reg = (first_reg + (num_regs - 1) * stride) & mask;
3530
0
  const char *qlf_name = aarch64_get_qualifier_name (opnd->qualifier);
3531
0
  char tb[16];  /* Temporary buffer.  */
3532
3533
0
  assert (opnd->type != AARCH64_OPND_LEt || opnd->reglist.has_index);
3534
0
  assert (num_regs >= 1 && num_regs <= 4);
3535
3536
  /* Prepare the index if any.  */
3537
0
  if (opnd->reglist.has_index)
3538
    /* PR 21096: The %100 is to silence a warning about possible truncation.  */
3539
0
    snprintf (tb, sizeof (tb), "[%s]",
3540
0
        style_imm (styler, "%" PRIi64, (opnd->reglist.index % 100)));
3541
0
  else
3542
0
    tb[0] = '\0';
3543
3544
  /* The hyphenated form is preferred for disassembly if there are
3545
     more than two registers in the list, and the register numbers
3546
     are monotonically increasing in increments of one.  */
3547
0
  if (stride == 1 && num_regs > 1)
3548
0
    snprintf (buf, size, "{%s-%s}%s",
3549
0
        style_reg (styler, "%s%d.%s", prefix, first_reg, qlf_name),
3550
0
        style_reg (styler, "%s%d.%s", prefix, last_reg, qlf_name), tb);
3551
0
  else
3552
0
    {
3553
0
      const int reg0 = first_reg;
3554
0
      const int reg1 = (first_reg + stride) & mask;
3555
0
      const int reg2 = (first_reg + stride * 2) & mask;
3556
0
      const int reg3 = (first_reg + stride * 3) & mask;
3557
3558
0
      switch (num_regs)
3559
0
  {
3560
0
  case 1:
3561
0
    snprintf (buf, size, "{%s}%s",
3562
0
        style_reg (styler, "%s%d.%s", prefix, reg0, qlf_name),
3563
0
        tb);
3564
0
    break;
3565
0
  case 2:
3566
0
    snprintf (buf, size, "{%s, %s}%s",
3567
0
        style_reg (styler, "%s%d.%s", prefix, reg0, qlf_name),
3568
0
        style_reg (styler, "%s%d.%s", prefix, reg1, qlf_name),
3569
0
        tb);
3570
0
    break;
3571
0
  case 3:
3572
0
    snprintf (buf, size, "{%s, %s, %s}%s",
3573
0
        style_reg (styler, "%s%d.%s", prefix, reg0, qlf_name),
3574
0
        style_reg (styler, "%s%d.%s", prefix, reg1, qlf_name),
3575
0
        style_reg (styler, "%s%d.%s", prefix, reg2, qlf_name),
3576
0
        tb);
3577
0
    break;
3578
0
  case 4:
3579
0
    snprintf (buf, size, "{%s, %s, %s, %s}%s",
3580
0
        style_reg (styler, "%s%d.%s", prefix, reg0, qlf_name),
3581
0
        style_reg (styler, "%s%d.%s", prefix, reg1, qlf_name),
3582
0
        style_reg (styler, "%s%d.%s", prefix, reg2, qlf_name),
3583
0
        style_reg (styler, "%s%d.%s", prefix, reg3, qlf_name),
3584
0
        tb);
3585
0
    break;
3586
0
  }
3587
0
    }
3588
0
}
3589
3590
/* Print the register+immediate address in OPND to BUF, which has SIZE
3591
   characters.  BASE is the name of the base register.  */
3592
3593
static void
3594
print_immediate_offset_address (char *buf, size_t size,
3595
        const aarch64_opnd_info *opnd,
3596
        const char *base,
3597
        struct aarch64_styler *styler)
3598
0
{
3599
0
  if (opnd->addr.writeback)
3600
0
    {
3601
0
      if (opnd->addr.preind)
3602
0
        {
3603
0
    if (opnd->type == AARCH64_OPND_ADDR_SIMM10 && !opnd->addr.offset.imm)
3604
0
      snprintf (buf, size, "[%s]!", style_reg (styler, base));
3605
0
          else
3606
0
      snprintf (buf, size, "[%s, %s]!",
3607
0
          style_reg (styler, base),
3608
0
          style_imm (styler, "#%d", opnd->addr.offset.imm));
3609
0
        }
3610
0
      else
3611
0
  snprintf (buf, size, "[%s], %s",
3612
0
      style_reg (styler, base),
3613
0
      style_imm (styler, "#%d", opnd->addr.offset.imm));
3614
0
    }
3615
0
  else
3616
0
    {
3617
0
      if (opnd->shifter.operator_present)
3618
0
  {
3619
0
    assert (opnd->shifter.kind == AARCH64_MOD_MUL_VL);
3620
0
    snprintf (buf, size, "[%s, %s, %s]",
3621
0
        style_reg (styler, base),
3622
0
        style_imm (styler, "#%d", opnd->addr.offset.imm),
3623
0
        style_sub_mnem (styler, "mul vl"));
3624
0
  }
3625
0
      else if (opnd->addr.offset.imm)
3626
0
  snprintf (buf, size, "[%s, %s]",
3627
0
      style_reg (styler, base),
3628
0
      style_imm (styler, "#%d", opnd->addr.offset.imm));
3629
0
      else
3630
0
  snprintf (buf, size, "[%s]", style_reg (styler, base));
3631
0
    }
3632
0
}
3633
3634
/* Produce the string representation of the register offset address operand
3635
   *OPND in the buffer pointed by BUF of size SIZE.  BASE and OFFSET are
3636
   the names of the base and offset registers.  */
3637
static void
3638
print_register_offset_address (char *buf, size_t size,
3639
             const aarch64_opnd_info *opnd,
3640
             const char *base, const char *offset,
3641
             struct aarch64_styler *styler)
3642
0
{
3643
0
  char tb[32];      /* Temporary buffer.  */
3644
0
  bool print_extend_p = true;
3645
0
  bool print_amount_p = true;
3646
0
  const char *shift_name = aarch64_operand_modifiers[opnd->shifter.kind].name;
3647
3648
0
  if (!opnd->shifter.amount && (opnd->qualifier != AARCH64_OPND_QLF_S_B
3649
0
        || !opnd->shifter.amount_present))
3650
0
    {
3651
      /* Not print the shift/extend amount when the amount is zero and
3652
         when it is not the special case of 8-bit load/store instruction.  */
3653
0
      print_amount_p = false;
3654
      /* Likewise, no need to print the shift operator LSL in such a
3655
   situation.  */
3656
0
      if (opnd->shifter.kind == AARCH64_MOD_LSL)
3657
0
  print_extend_p = false;
3658
0
    }
3659
3660
  /* Prepare for the extend/shift.  */
3661
0
  if (print_extend_p)
3662
0
    {
3663
0
      if (print_amount_p)
3664
0
  snprintf (tb, sizeof (tb), ", %s %s",
3665
0
      style_sub_mnem (styler, shift_name),
3666
0
      style_imm (styler, "#%" PRIi64,
3667
  /* PR 21096: The %100 is to silence a warning about possible truncation.  */
3668
0
           (opnd->shifter.amount % 100)));
3669
0
      else
3670
0
  snprintf (tb, sizeof (tb), ", %s",
3671
0
      style_sub_mnem (styler, shift_name));
3672
0
    }
3673
0
  else
3674
0
    tb[0] = '\0';
3675
3676
0
  snprintf (buf, size, "[%s, %s%s]", style_reg (styler, base),
3677
0
      style_reg (styler, offset), tb);
3678
0
}
3679
3680
/* Print ZA tiles from imm8 in ZERO instruction.
3681
3682
   The preferred disassembly of this instruction uses the shortest list of tile
3683
   names that represent the encoded immediate mask.
3684
3685
   For example:
3686
    * An all-ones immediate is disassembled as {ZA}.
3687
    * An all-zeros immediate is disassembled as an empty list { }.
3688
*/
3689
static void
3690
print_sme_za_list (char *buf, size_t size, int mask,
3691
       struct aarch64_styler *styler)
3692
0
{
3693
0
  const char* zan[] = { "za",    "za0.h", "za1.h", "za0.s",
3694
0
                        "za1.s", "za2.s", "za3.s", "za0.d",
3695
0
                        "za1.d", "za2.d", "za3.d", "za4.d",
3696
0
                        "za5.d", "za6.d", "za7.d", " " };
3697
0
  const int zan_v[] = { 0xff, 0x55, 0xaa, 0x11,
3698
0
                        0x22, 0x44, 0x88, 0x01,
3699
0
                        0x02, 0x04, 0x08, 0x10,
3700
0
                        0x20, 0x40, 0x80, 0x00 };
3701
0
  int i, k;
3702
0
  const int ZAN_SIZE = sizeof(zan) / sizeof(zan[0]);
3703
3704
0
  k = snprintf (buf, size, "{");
3705
0
  for (i = 0; i < ZAN_SIZE; i++)
3706
0
    {
3707
0
      if ((mask & zan_v[i]) == zan_v[i])
3708
0
        {
3709
0
          mask &= ~zan_v[i];
3710
0
          if (k > 1)
3711
0
      k += snprintf (buf + k, size - k, ", ");
3712
3713
0
    k += snprintf (buf + k, size - k, "%s", style_reg (styler, zan[i]));
3714
0
        }
3715
0
      if (mask == 0)
3716
0
        break;
3717
0
    }
3718
0
  snprintf (buf + k, size - k, "}");
3719
0
}
3720
3721
/* Generate the string representation of the operand OPNDS[IDX] for OPCODE
3722
   in *BUF.  The caller should pass in the maximum size of *BUF in SIZE.
3723
   PC, PCREL_P and ADDRESS are used to pass in and return information about
3724
   the PC-relative address calculation, where the PC value is passed in
3725
   PC.  If the operand is pc-relative related, *PCREL_P (if PCREL_P non-NULL)
3726
   will return 1 and *ADDRESS (if ADDRESS non-NULL) will return the
3727
   calculated address; otherwise, *PCREL_P (if PCREL_P non-NULL) returns 0.
3728
3729
   The function serves both the disassembler and the assembler diagnostics
3730
   issuer, which is the reason why it lives in this file.  */
3731
3732
void
3733
aarch64_print_operand (char *buf, size_t size, bfd_vma pc,
3734
           const aarch64_opcode *opcode,
3735
           const aarch64_opnd_info *opnds, int idx, int *pcrel_p,
3736
           bfd_vma *address, char** notes,
3737
           char *comment, size_t comment_size,
3738
           aarch64_feature_set features,
3739
           struct aarch64_styler *styler)
3740
0
{
3741
0
  unsigned int i, num_conds;
3742
0
  const char *name = NULL;
3743
0
  const aarch64_opnd_info *opnd = opnds + idx;
3744
0
  enum aarch64_modifier_kind kind;
3745
0
  uint64_t addr, enum_value;
3746
3747
0
  if (comment != NULL)
3748
0
    {
3749
0
      assert (comment_size > 0);
3750
0
      comment[0] = '\0';
3751
0
    }
3752
0
  else
3753
0
    assert (comment_size == 0);
3754
3755
0
  buf[0] = '\0';
3756
0
  if (pcrel_p)
3757
0
    *pcrel_p = 0;
3758
3759
0
  switch (opnd->type)
3760
0
    {
3761
0
    case AARCH64_OPND_Rd:
3762
0
    case AARCH64_OPND_Rn:
3763
0
    case AARCH64_OPND_Rm:
3764
0
    case AARCH64_OPND_Rt:
3765
0
    case AARCH64_OPND_Rt2:
3766
0
    case AARCH64_OPND_Rs:
3767
0
    case AARCH64_OPND_Ra:
3768
0
    case AARCH64_OPND_Rt_LS64:
3769
0
    case AARCH64_OPND_Rt_SYS:
3770
0
    case AARCH64_OPND_PAIRREG:
3771
0
    case AARCH64_OPND_SVE_Rm:
3772
      /* The optional-ness of <Xt> in e.g. IC <ic_op>{, <Xt>} is determined by
3773
   the <ic_op>, therefore we use opnd->present to override the
3774
   generic optional-ness information.  */
3775
0
      if (opnd->type == AARCH64_OPND_Rt_SYS)
3776
0
  {
3777
0
    if (!opnd->present)
3778
0
      break;
3779
0
  }
3780
      /* Omit the operand, e.g. RET.  */
3781
0
      else if (optional_operand_p (opcode, idx)
3782
0
         && (opnd->reg.regno
3783
0
       == get_optional_operand_default_value (opcode)))
3784
0
  break;
3785
0
      assert (opnd->qualifier == AARCH64_OPND_QLF_W
3786
0
        || opnd->qualifier == AARCH64_OPND_QLF_X);
3787
0
      snprintf (buf, size, "%s",
3788
0
    style_reg (styler, get_int_reg_name (opnd->reg.regno,
3789
0
                 opnd->qualifier, 0)));
3790
0
      break;
3791
3792
0
    case AARCH64_OPND_Rd_SP:
3793
0
    case AARCH64_OPND_Rn_SP:
3794
0
    case AARCH64_OPND_Rt_SP:
3795
0
    case AARCH64_OPND_SVE_Rn_SP:
3796
0
    case AARCH64_OPND_Rm_SP:
3797
0
      assert (opnd->qualifier == AARCH64_OPND_QLF_W
3798
0
        || opnd->qualifier == AARCH64_OPND_QLF_WSP
3799
0
        || opnd->qualifier == AARCH64_OPND_QLF_X
3800
0
        || opnd->qualifier == AARCH64_OPND_QLF_SP);
3801
0
      snprintf (buf, size, "%s",
3802
0
    style_reg (styler, get_int_reg_name (opnd->reg.regno,
3803
0
                 opnd->qualifier, 1)));
3804
0
      break;
3805
3806
0
    case AARCH64_OPND_Rm_EXT:
3807
0
      kind = opnd->shifter.kind;
3808
0
      assert (idx == 1 || idx == 2);
3809
0
      if ((aarch64_stack_pointer_p (opnds)
3810
0
     || (idx == 2 && aarch64_stack_pointer_p (opnds + 1)))
3811
0
    && ((opnd->qualifier == AARCH64_OPND_QLF_W
3812
0
         && opnds[0].qualifier == AARCH64_OPND_QLF_W
3813
0
         && kind == AARCH64_MOD_UXTW)
3814
0
        || (opnd->qualifier == AARCH64_OPND_QLF_X
3815
0
      && kind == AARCH64_MOD_UXTX)))
3816
0
  {
3817
    /* 'LSL' is the preferred form in this case.  */
3818
0
    kind = AARCH64_MOD_LSL;
3819
0
    if (opnd->shifter.amount == 0)
3820
0
      {
3821
        /* Shifter omitted.  */
3822
0
        snprintf (buf, size, "%s",
3823
0
      style_reg (styler,
3824
0
           get_int_reg_name (opnd->reg.regno,
3825
0
                 opnd->qualifier, 0)));
3826
0
        break;
3827
0
      }
3828
0
  }
3829
0
      if (opnd->shifter.amount)
3830
0
  snprintf (buf, size, "%s, %s %s",
3831
0
      style_reg (styler, get_int_reg_name (opnd->reg.regno, opnd->qualifier, 0)),
3832
0
      style_sub_mnem (styler, aarch64_operand_modifiers[kind].name),
3833
0
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
3834
0
      else
3835
0
  snprintf (buf, size, "%s, %s",
3836
0
      style_reg (styler, get_int_reg_name (opnd->reg.regno, opnd->qualifier, 0)),
3837
0
      style_sub_mnem (styler, aarch64_operand_modifiers[kind].name));
3838
0
      break;
3839
3840
0
    case AARCH64_OPND_Rm_SFT:
3841
0
      assert (opnd->qualifier == AARCH64_OPND_QLF_W
3842
0
        || opnd->qualifier == AARCH64_OPND_QLF_X);
3843
0
      if (opnd->shifter.amount == 0 && opnd->shifter.kind == AARCH64_MOD_LSL)
3844
0
  snprintf (buf, size, "%s",
3845
0
      style_reg (styler, get_int_reg_name (opnd->reg.regno,
3846
0
                   opnd->qualifier, 0)));
3847
0
      else
3848
0
  snprintf (buf, size, "%s, %s %s",
3849
0
      style_reg (styler, get_int_reg_name (opnd->reg.regno, opnd->qualifier, 0)),
3850
0
      style_sub_mnem (styler, aarch64_operand_modifiers[opnd->shifter.kind].name),
3851
0
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
3852
0
      break;
3853
3854
0
    case AARCH64_OPND_Fd:
3855
0
    case AARCH64_OPND_Fn:
3856
0
    case AARCH64_OPND_Fm:
3857
0
    case AARCH64_OPND_Fa:
3858
0
    case AARCH64_OPND_Ft:
3859
0
    case AARCH64_OPND_Ft2:
3860
0
    case AARCH64_OPND_Sd:
3861
0
    case AARCH64_OPND_Sn:
3862
0
    case AARCH64_OPND_Sm:
3863
0
    case AARCH64_OPND_SVE_VZn:
3864
0
    case AARCH64_OPND_SVE_Vd:
3865
0
    case AARCH64_OPND_SVE_Vm:
3866
0
    case AARCH64_OPND_SVE_Vn:
3867
0
      snprintf (buf, size, "%s",
3868
0
    style_reg (styler, "%s%d",
3869
0
         aarch64_get_qualifier_name (opnd->qualifier),
3870
0
         opnd->reg.regno));
3871
0
      break;
3872
3873
0
    case AARCH64_OPND_Va:
3874
0
    case AARCH64_OPND_Vd:
3875
0
    case AARCH64_OPND_Vn:
3876
0
    case AARCH64_OPND_Vm:
3877
0
      snprintf (buf, size, "%s",
3878
0
    style_reg (styler, "v%d.%s", opnd->reg.regno,
3879
0
         aarch64_get_qualifier_name (opnd->qualifier)));
3880
0
      break;
3881
3882
0
    case AARCH64_OPND_Ed:
3883
0
    case AARCH64_OPND_En:
3884
0
    case AARCH64_OPND_Em:
3885
0
    case AARCH64_OPND_Em16:
3886
0
    case AARCH64_OPND_SM3_IMM2:
3887
0
      snprintf (buf, size, "%s[%s]",
3888
0
    style_reg (styler, "v%d.%s", opnd->reglane.regno,
3889
0
         aarch64_get_qualifier_name (opnd->qualifier)),
3890
0
    style_imm (styler, "%" PRIi64, opnd->reglane.index));
3891
0
      break;
3892
3893
0
    case AARCH64_OPND_VdD1:
3894
0
    case AARCH64_OPND_VnD1:
3895
0
      snprintf (buf, size, "%s[%s]",
3896
0
    style_reg (styler, "v%d.d", opnd->reg.regno),
3897
0
    style_imm (styler, "1"));
3898
0
      break;
3899
3900
0
    case AARCH64_OPND_LVn:
3901
0
    case AARCH64_OPND_LVt:
3902
0
    case AARCH64_OPND_LVt_AL:
3903
0
    case AARCH64_OPND_LEt:
3904
0
      print_register_list (buf, size, opnd, "v", styler);
3905
0
      break;
3906
3907
0
    case AARCH64_OPND_SVE_Pd:
3908
0
    case AARCH64_OPND_SVE_Pg3:
3909
0
    case AARCH64_OPND_SVE_Pg4_5:
3910
0
    case AARCH64_OPND_SVE_Pg4_10:
3911
0
    case AARCH64_OPND_SVE_Pg4_16:
3912
0
    case AARCH64_OPND_SVE_Pm:
3913
0
    case AARCH64_OPND_SVE_Pn:
3914
0
    case AARCH64_OPND_SVE_Pt:
3915
0
    case AARCH64_OPND_SME_Pm:
3916
0
      if (opnd->qualifier == AARCH64_OPND_QLF_NIL)
3917
0
  snprintf (buf, size, "%s",
3918
0
      style_reg (styler, "p%d", opnd->reg.regno));
3919
0
      else if (opnd->qualifier == AARCH64_OPND_QLF_P_Z
3920
0
         || opnd->qualifier == AARCH64_OPND_QLF_P_M)
3921
0
  snprintf (buf, size, "%s",
3922
0
      style_reg (styler, "p%d/%s", opnd->reg.regno,
3923
0
           aarch64_get_qualifier_name (opnd->qualifier)));
3924
0
      else
3925
0
  snprintf (buf, size, "%s",
3926
0
      style_reg (styler, "p%d.%s", opnd->reg.regno,
3927
0
           aarch64_get_qualifier_name (opnd->qualifier)));
3928
0
      break;
3929
3930
0
    case AARCH64_OPND_SVE_PNd:
3931
0
    case AARCH64_OPND_SVE_PNg4_10:
3932
0
    case AARCH64_OPND_SVE_PNn:
3933
0
    case AARCH64_OPND_SVE_PNt:
3934
0
    case AARCH64_OPND_SME_PNd3:
3935
0
    case AARCH64_OPND_SME_PNg3:
3936
0
    case AARCH64_OPND_SME_PNn:
3937
0
      if (opnd->qualifier == AARCH64_OPND_QLF_NIL)
3938
0
  snprintf (buf, size, "%s",
3939
0
      style_reg (styler, "pn%d", opnd->reg.regno));
3940
0
      else if (opnd->qualifier == AARCH64_OPND_QLF_P_Z
3941
0
         || opnd->qualifier == AARCH64_OPND_QLF_P_M)
3942
0
  snprintf (buf, size, "%s",
3943
0
      style_reg (styler, "pn%d/%s", opnd->reg.regno,
3944
0
           aarch64_get_qualifier_name (opnd->qualifier)));
3945
0
      else
3946
0
  snprintf (buf, size, "%s",
3947
0
      style_reg (styler, "pn%d.%s", opnd->reg.regno,
3948
0
           aarch64_get_qualifier_name (opnd->qualifier)));
3949
0
      break;
3950
3951
0
    case AARCH64_OPND_SME_Pdx2:
3952
0
    case AARCH64_OPND_SME_PdxN:
3953
0
      print_register_list (buf, size, opnd, "p", styler);
3954
0
      break;
3955
3956
0
    case AARCH64_OPND_SME_PNn3_INDEX1:
3957
0
    case AARCH64_OPND_SME_PNn3_INDEX2:
3958
0
      snprintf (buf, size, "%s[%s]",
3959
0
    style_reg (styler, "pn%d", opnd->reglane.regno),
3960
0
    style_imm (styler, "%" PRIi64, opnd->reglane.index));
3961
0
      break;
3962
3963
0
    case AARCH64_OPND_SVE_Za_5:
3964
0
    case AARCH64_OPND_SVE_Za_16:
3965
0
    case AARCH64_OPND_SVE_Zd:
3966
0
    case AARCH64_OPND_SVE_Zm_5:
3967
0
    case AARCH64_OPND_SVE_Zm_16:
3968
0
    case AARCH64_OPND_SVE_Zn:
3969
0
    case AARCH64_OPND_SVE_Zt:
3970
0
    case AARCH64_OPND_SME_Zm:
3971
0
      if (opnd->qualifier == AARCH64_OPND_QLF_NIL)
3972
0
  snprintf (buf, size, "%s", style_reg (styler, "z%d", opnd->reg.regno));
3973
0
      else
3974
0
  snprintf (buf, size, "%s",
3975
0
      style_reg (styler, "z%d.%s", opnd->reg.regno,
3976
0
           aarch64_get_qualifier_name (opnd->qualifier)));
3977
0
      break;
3978
3979
0
    case AARCH64_OPND_SVE_ZnxN:
3980
0
    case AARCH64_OPND_SVE_ZtxN:
3981
0
    case AARCH64_OPND_SME_Zdnx2:
3982
0
    case AARCH64_OPND_SME_Zdnx4:
3983
0
    case AARCH64_OPND_SME_Zmx2:
3984
0
    case AARCH64_OPND_SME_Zmx4:
3985
0
    case AARCH64_OPND_SME_Znx2:
3986
0
    case AARCH64_OPND_SME_Znx4:
3987
0
    case AARCH64_OPND_SME_Ztx2_STRIDED:
3988
0
    case AARCH64_OPND_SME_Ztx4_STRIDED:
3989
0
      print_register_list (buf, size, opnd, "z", styler);
3990
0
      break;
3991
3992
0
    case AARCH64_OPND_SVE_Zm3_INDEX:
3993
0
    case AARCH64_OPND_SVE_Zm3_22_INDEX:
3994
0
    case AARCH64_OPND_SVE_Zm3_19_INDEX:
3995
0
    case AARCH64_OPND_SVE_Zm3_11_INDEX:
3996
0
    case AARCH64_OPND_SVE_Zm4_11_INDEX:
3997
0
    case AARCH64_OPND_SVE_Zm4_INDEX:
3998
0
    case AARCH64_OPND_SVE_Zn_INDEX:
3999
0
    case AARCH64_OPND_SME_Zm_INDEX1:
4000
0
    case AARCH64_OPND_SME_Zm_INDEX2:
4001
0
    case AARCH64_OPND_SME_Zm_INDEX3_1:
4002
0
    case AARCH64_OPND_SME_Zm_INDEX3_2:
4003
0
    case AARCH64_OPND_SME_Zm_INDEX3_10:
4004
0
    case AARCH64_OPND_SME_Zm_INDEX4_1:
4005
0
    case AARCH64_OPND_SME_Zm_INDEX4_10:
4006
0
    case AARCH64_OPND_SME_Zn_INDEX1_16:
4007
0
    case AARCH64_OPND_SME_Zn_INDEX2_15:
4008
0
    case AARCH64_OPND_SME_Zn_INDEX2_16:
4009
0
    case AARCH64_OPND_SME_Zn_INDEX3_14:
4010
0
    case AARCH64_OPND_SME_Zn_INDEX3_15:
4011
0
    case AARCH64_OPND_SME_Zn_INDEX4_14:
4012
0
      snprintf (buf, size, "%s[%s]",
4013
0
    (opnd->qualifier == AARCH64_OPND_QLF_NIL
4014
0
     ? style_reg (styler, "z%d", opnd->reglane.regno)
4015
0
     : style_reg (styler, "z%d.%s", opnd->reglane.regno,
4016
0
            aarch64_get_qualifier_name (opnd->qualifier))),
4017
0
    style_imm (styler, "%" PRIi64, opnd->reglane.index));
4018
0
      break;
4019
4020
0
    case AARCH64_OPND_SME_ZAda_2b:
4021
0
    case AARCH64_OPND_SME_ZAda_3b:
4022
0
      snprintf (buf, size, "%s",
4023
0
    style_reg (styler, "za%d.%s", opnd->reg.regno,
4024
0
         aarch64_get_qualifier_name (opnd->qualifier)));
4025
0
      break;
4026
4027
0
    case AARCH64_OPND_SME_ZA_HV_idx_src:
4028
0
    case AARCH64_OPND_SME_ZA_HV_idx_srcxN:
4029
0
    case AARCH64_OPND_SME_ZA_HV_idx_dest:
4030
0
    case AARCH64_OPND_SME_ZA_HV_idx_destxN:
4031
0
    case AARCH64_OPND_SME_ZA_HV_idx_ldstr:
4032
0
      snprintf (buf, size, "%s%s[%s, %s%s%s%s%s]%s",
4033
0
    opnd->type == AARCH64_OPND_SME_ZA_HV_idx_ldstr ? "{" : "",
4034
0
    style_reg (styler, "za%d%c.%s",
4035
0
         opnd->indexed_za.regno,
4036
0
         opnd->indexed_za.v == 1 ? 'v' : 'h',
4037
0
         aarch64_get_qualifier_name (opnd->qualifier)),
4038
0
    style_reg (styler, "w%d", opnd->indexed_za.index.regno),
4039
0
    style_imm (styler, "%" PRIi64, opnd->indexed_za.index.imm),
4040
0
    opnd->indexed_za.index.countm1 ? ":" : "",
4041
0
    (opnd->indexed_za.index.countm1
4042
0
     ? style_imm (styler, "%d",
4043
0
            opnd->indexed_za.index.imm
4044
0
            + opnd->indexed_za.index.countm1)
4045
0
     : ""),
4046
0
    opnd->indexed_za.group_size ? ", " : "",
4047
0
    opnd->indexed_za.group_size == 2
4048
0
    ? style_sub_mnem (styler, "vgx2")
4049
0
    : opnd->indexed_za.group_size == 4
4050
0
    ? style_sub_mnem (styler, "vgx4") : "",
4051
0
    opnd->type == AARCH64_OPND_SME_ZA_HV_idx_ldstr ? "}" : "");
4052
0
      break;
4053
4054
0
    case AARCH64_OPND_SME_list_of_64bit_tiles:
4055
0
      print_sme_za_list (buf, size, opnd->reg.regno, styler);
4056
0
      break;
4057
4058
0
    case AARCH64_OPND_SME_ZA_array_off1x4:
4059
0
    case AARCH64_OPND_SME_ZA_array_off2x2:
4060
0
    case AARCH64_OPND_SME_ZA_array_off2x4:
4061
0
    case AARCH64_OPND_SME_ZA_array_off3_0:
4062
0
    case AARCH64_OPND_SME_ZA_array_off3_5:
4063
0
    case AARCH64_OPND_SME_ZA_array_off3x2:
4064
0
    case AARCH64_OPND_SME_ZA_array_off4:
4065
0
      snprintf (buf, size, "%s[%s, %s%s%s%s%s]",
4066
0
    style_reg (styler, "za%s%s",
4067
0
         opnd->qualifier == AARCH64_OPND_QLF_NIL ? "" : ".",
4068
0
         (opnd->qualifier == AARCH64_OPND_QLF_NIL
4069
0
          ? ""
4070
0
          : aarch64_get_qualifier_name (opnd->qualifier))),
4071
0
    style_reg (styler, "w%d", opnd->indexed_za.index.regno),
4072
0
    style_imm (styler, "%" PRIi64, opnd->indexed_za.index.imm),
4073
0
    opnd->indexed_za.index.countm1 ? ":" : "",
4074
0
    (opnd->indexed_za.index.countm1
4075
0
     ? style_imm (styler, "%d",
4076
0
            opnd->indexed_za.index.imm
4077
0
            + opnd->indexed_za.index.countm1)
4078
0
     : ""),
4079
0
    opnd->indexed_za.group_size ? ", " : "",
4080
0
    opnd->indexed_za.group_size == 2
4081
0
    ? style_sub_mnem (styler, "vgx2")
4082
0
    : opnd->indexed_za.group_size == 4
4083
0
    ? style_sub_mnem (styler, "vgx4") : "");
4084
0
      break;
4085
4086
0
    case AARCH64_OPND_SME_SM_ZA:
4087
0
      snprintf (buf, size, "%s",
4088
0
    style_reg (styler, opnd->reg.regno == 's' ? "sm" : "za"));
4089
0
      break;
4090
4091
0
    case AARCH64_OPND_SME_PnT_Wm_imm:
4092
0
      snprintf (buf, size, "%s[%s, %s]",
4093
0
    style_reg (styler, "p%d.%s", opnd->indexed_za.regno,
4094
0
         aarch64_get_qualifier_name (opnd->qualifier)),
4095
0
    style_reg (styler, "w%d", opnd->indexed_za.index.regno),
4096
0
    style_imm (styler, "%" PRIi64, opnd->indexed_za.index.imm));
4097
0
      break;
4098
4099
0
    case AARCH64_OPND_SME_VLxN_10:
4100
0
    case AARCH64_OPND_SME_VLxN_13:
4101
0
      enum_value = opnd->imm.value;
4102
0
      assert (enum_value < ARRAY_SIZE (aarch64_sme_vlxn_array));
4103
0
      snprintf (buf, size, "%s",
4104
0
    style_sub_mnem (styler, aarch64_sme_vlxn_array[enum_value]));
4105
0
      break;
4106
4107
0
    case AARCH64_OPND_CRn:
4108
0
    case AARCH64_OPND_CRm:
4109
0
      snprintf (buf, size, "%s",
4110
0
    style_reg (styler, "C%" PRIi64, opnd->imm.value));
4111
0
      break;
4112
4113
0
    case AARCH64_OPND_IDX:
4114
0
    case AARCH64_OPND_MASK:
4115
0
    case AARCH64_OPND_IMM:
4116
0
    case AARCH64_OPND_IMM_2:
4117
0
    case AARCH64_OPND_WIDTH:
4118
0
    case AARCH64_OPND_UIMM3_OP1:
4119
0
    case AARCH64_OPND_UIMM3_OP2:
4120
0
    case AARCH64_OPND_BIT_NUM:
4121
0
    case AARCH64_OPND_IMM_VLSL:
4122
0
    case AARCH64_OPND_IMM_VLSR:
4123
0
    case AARCH64_OPND_SHLL_IMM:
4124
0
    case AARCH64_OPND_IMM0:
4125
0
    case AARCH64_OPND_IMMR:
4126
0
    case AARCH64_OPND_IMMS:
4127
0
    case AARCH64_OPND_UNDEFINED:
4128
0
    case AARCH64_OPND_FBITS:
4129
0
    case AARCH64_OPND_TME_UIMM16:
4130
0
    case AARCH64_OPND_SIMM5:
4131
0
    case AARCH64_OPND_SME_SHRIMM4:
4132
0
    case AARCH64_OPND_SME_SHRIMM5:
4133
0
    case AARCH64_OPND_SVE_SHLIMM_PRED:
4134
0
    case AARCH64_OPND_SVE_SHLIMM_UNPRED:
4135
0
    case AARCH64_OPND_SVE_SHLIMM_UNPRED_22:
4136
0
    case AARCH64_OPND_SVE_SHRIMM_PRED:
4137
0
    case AARCH64_OPND_SVE_SHRIMM_UNPRED:
4138
0
    case AARCH64_OPND_SVE_SHRIMM_UNPRED_22:
4139
0
    case AARCH64_OPND_SVE_SIMM5:
4140
0
    case AARCH64_OPND_SVE_SIMM5B:
4141
0
    case AARCH64_OPND_SVE_SIMM6:
4142
0
    case AARCH64_OPND_SVE_SIMM8:
4143
0
    case AARCH64_OPND_SVE_UIMM3:
4144
0
    case AARCH64_OPND_SVE_UIMM7:
4145
0
    case AARCH64_OPND_SVE_UIMM8:
4146
0
    case AARCH64_OPND_SVE_UIMM8_53:
4147
0
    case AARCH64_OPND_IMM_ROT1:
4148
0
    case AARCH64_OPND_IMM_ROT2:
4149
0
    case AARCH64_OPND_IMM_ROT3:
4150
0
    case AARCH64_OPND_SVE_IMM_ROT1:
4151
0
    case AARCH64_OPND_SVE_IMM_ROT2:
4152
0
    case AARCH64_OPND_SVE_IMM_ROT3:
4153
0
    case AARCH64_OPND_CSSC_SIMM8:
4154
0
    case AARCH64_OPND_CSSC_UIMM8:
4155
0
      snprintf (buf, size, "%s",
4156
0
    style_imm (styler, "#%" PRIi64, opnd->imm.value));
4157
0
      break;
4158
4159
0
    case AARCH64_OPND_SVE_I1_HALF_ONE:
4160
0
    case AARCH64_OPND_SVE_I1_HALF_TWO:
4161
0
    case AARCH64_OPND_SVE_I1_ZERO_ONE:
4162
0
      {
4163
0
  single_conv_t c;
4164
0
  c.i = opnd->imm.value;
4165
0
  snprintf (buf, size, "%s", style_imm (styler, "#%.1f", c.f));
4166
0
  break;
4167
0
      }
4168
4169
0
    case AARCH64_OPND_SVE_PATTERN:
4170
0
      if (optional_operand_p (opcode, idx)
4171
0
    && opnd->imm.value == get_optional_operand_default_value (opcode))
4172
0
  break;
4173
0
      enum_value = opnd->imm.value;
4174
0
      assert (enum_value < ARRAY_SIZE (aarch64_sve_pattern_array));
4175
0
      if (aarch64_sve_pattern_array[enum_value])
4176
0
  snprintf (buf, size, "%s",
4177
0
      style_reg (styler, aarch64_sve_pattern_array[enum_value]));
4178
0
      else
4179
0
  snprintf (buf, size, "%s",
4180
0
      style_imm (styler, "#%" PRIi64, opnd->imm.value));
4181
0
      break;
4182
4183
0
    case AARCH64_OPND_SVE_PATTERN_SCALED:
4184
0
      if (optional_operand_p (opcode, idx)
4185
0
    && !opnd->shifter.operator_present
4186
0
    && opnd->imm.value == get_optional_operand_default_value (opcode))
4187
0
  break;
4188
0
      enum_value = opnd->imm.value;
4189
0
      assert (enum_value < ARRAY_SIZE (aarch64_sve_pattern_array));
4190
0
      if (aarch64_sve_pattern_array[opnd->imm.value])
4191
0
  snprintf (buf, size, "%s",
4192
0
      style_reg (styler,
4193
0
           aarch64_sve_pattern_array[opnd->imm.value]));
4194
0
      else
4195
0
  snprintf (buf, size, "%s",
4196
0
      style_imm (styler, "#%" PRIi64, opnd->imm.value));
4197
0
      if (opnd->shifter.operator_present)
4198
0
  {
4199
0
    size_t len = strlen (buf);
4200
0
    const char *shift_name
4201
0
      = aarch64_operand_modifiers[opnd->shifter.kind].name;
4202
0
    snprintf (buf + len, size - len, ", %s %s",
4203
0
        style_sub_mnem (styler, shift_name),
4204
0
        style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
4205
0
  }
4206
0
      break;
4207
4208
0
    case AARCH64_OPND_SVE_PRFOP:
4209
0
      enum_value = opnd->imm.value;
4210
0
      assert (enum_value < ARRAY_SIZE (aarch64_sve_prfop_array));
4211
0
      if (aarch64_sve_prfop_array[enum_value])
4212
0
  snprintf (buf, size, "%s",
4213
0
      style_reg (styler, aarch64_sve_prfop_array[enum_value]));
4214
0
      else
4215
0
  snprintf (buf, size, "%s",
4216
0
      style_imm (styler, "#%" PRIi64, opnd->imm.value));
4217
0
      break;
4218
4219
0
    case AARCH64_OPND_IMM_MOV:
4220
0
      switch (aarch64_get_qualifier_esize (opnds[0].qualifier))
4221
0
  {
4222
0
  case 4: /* e.g. MOV Wd, #<imm32>.  */
4223
0
      {
4224
0
        int imm32 = opnd->imm.value;
4225
0
        snprintf (buf, size, "%s",
4226
0
      style_imm (styler, "#0x%-20x", imm32));
4227
0
        snprintf (comment, comment_size, "#%d", imm32);
4228
0
      }
4229
0
    break;
4230
0
  case 8: /* e.g. MOV Xd, #<imm64>.  */
4231
0
    snprintf (buf, size, "%s", style_imm (styler, "#0x%-20" PRIx64,
4232
0
            opnd->imm.value));
4233
0
    snprintf (comment, comment_size, "#%" PRIi64, opnd->imm.value);
4234
0
    break;
4235
0
  default:
4236
0
    snprintf (buf, size, "<invalid>");
4237
0
    break;
4238
0
  }
4239
0
      break;
4240
4241
0
    case AARCH64_OPND_FPIMM0:
4242
0
      snprintf (buf, size, "%s", style_imm (styler, "#0.0"));
4243
0
      break;
4244
4245
0
    case AARCH64_OPND_LIMM:
4246
0
    case AARCH64_OPND_AIMM:
4247
0
    case AARCH64_OPND_HALF:
4248
0
    case AARCH64_OPND_SVE_INV_LIMM:
4249
0
    case AARCH64_OPND_SVE_LIMM:
4250
0
    case AARCH64_OPND_SVE_LIMM_MOV:
4251
0
      if (opnd->shifter.amount)
4252
0
  snprintf (buf, size, "%s, %s %s",
4253
0
      style_imm (styler, "#0x%" PRIx64, opnd->imm.value),
4254
0
      style_sub_mnem (styler, "lsl"),
4255
0
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
4256
0
      else
4257
0
  snprintf (buf, size, "%s",
4258
0
      style_imm (styler, "#0x%" PRIx64, opnd->imm.value));
4259
0
      break;
4260
4261
0
    case AARCH64_OPND_SIMD_IMM:
4262
0
    case AARCH64_OPND_SIMD_IMM_SFT:
4263
0
      if ((! opnd->shifter.amount && opnd->shifter.kind == AARCH64_MOD_LSL)
4264
0
    || opnd->shifter.kind == AARCH64_MOD_NONE)
4265
0
  snprintf (buf, size, "%s",
4266
0
      style_imm (styler, "#0x%" PRIx64, opnd->imm.value));
4267
0
      else
4268
0
  snprintf (buf, size, "%s, %s %s",
4269
0
      style_imm (styler, "#0x%" PRIx64, opnd->imm.value),
4270
0
      style_sub_mnem (styler, aarch64_operand_modifiers[opnd->shifter.kind].name),
4271
0
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
4272
0
      break;
4273
4274
0
    case AARCH64_OPND_SVE_AIMM:
4275
0
    case AARCH64_OPND_SVE_ASIMM:
4276
0
      if (opnd->shifter.amount)
4277
0
  snprintf (buf, size, "%s, %s %s",
4278
0
      style_imm (styler, "#%" PRIi64, opnd->imm.value),
4279
0
      style_sub_mnem (styler, "lsl"),
4280
0
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
4281
0
      else
4282
0
  snprintf (buf, size, "%s",
4283
0
      style_imm (styler, "#%" PRIi64, opnd->imm.value));
4284
0
      break;
4285
4286
0
    case AARCH64_OPND_FPIMM:
4287
0
    case AARCH64_OPND_SIMD_FPIMM:
4288
0
    case AARCH64_OPND_SVE_FPIMM8:
4289
0
      switch (aarch64_get_qualifier_esize (opnds[0].qualifier))
4290
0
  {
4291
0
  case 2: /* e.g. FMOV <Hd>, #<imm>.  */
4292
0
      {
4293
0
        half_conv_t c;
4294
0
        c.i = expand_fp_imm (2, opnd->imm.value);
4295
0
        snprintf (buf, size, "%s", style_imm (styler, "#%.18e", c.f));
4296
0
      }
4297
0
    break;
4298
0
  case 4: /* e.g. FMOV <Vd>.4S, #<imm>.  */
4299
0
      {
4300
0
        single_conv_t c;
4301
0
        c.i = expand_fp_imm (4, opnd->imm.value);
4302
0
        snprintf (buf, size, "%s", style_imm (styler, "#%.18e", c.f));
4303
0
      }
4304
0
    break;
4305
0
  case 8: /* e.g. FMOV <Sd>, #<imm>.  */
4306
0
      {
4307
0
        double_conv_t c;
4308
0
        c.i = expand_fp_imm (8, opnd->imm.value);
4309
0
        snprintf (buf, size, "%s", style_imm (styler, "#%.18e", c.d));
4310
0
      }
4311
0
    break;
4312
0
  default:
4313
0
    snprintf (buf, size, "<invalid>");
4314
0
    break;
4315
0
  }
4316
0
      break;
4317
4318
0
    case AARCH64_OPND_CCMP_IMM:
4319
0
    case AARCH64_OPND_NZCV:
4320
0
    case AARCH64_OPND_EXCEPTION:
4321
0
    case AARCH64_OPND_UIMM4:
4322
0
    case AARCH64_OPND_UIMM4_ADDG:
4323
0
    case AARCH64_OPND_UIMM7:
4324
0
    case AARCH64_OPND_UIMM10:
4325
0
      if (optional_operand_p (opcode, idx)
4326
0
    && (opnd->imm.value ==
4327
0
        (int64_t) get_optional_operand_default_value (opcode)))
4328
  /* Omit the operand, e.g. DCPS1.  */
4329
0
  break;
4330
0
      snprintf (buf, size, "%s",
4331
0
    style_imm (styler, "#0x%x", (unsigned int) opnd->imm.value));
4332
0
      break;
4333
4334
0
    case AARCH64_OPND_COND:
4335
0
    case AARCH64_OPND_COND1:
4336
0
      snprintf (buf, size, "%s",
4337
0
    style_sub_mnem (styler, opnd->cond->names[0]));
4338
0
      num_conds = ARRAY_SIZE (opnd->cond->names);
4339
0
      for (i = 1; i < num_conds && opnd->cond->names[i]; ++i)
4340
0
  {
4341
0
    size_t len = comment != NULL ? strlen (comment) : 0;
4342
0
    if (i == 1)
4343
0
      snprintf (comment + len, comment_size - len, "%s = %s",
4344
0
          opnd->cond->names[0], opnd->cond->names[i]);
4345
0
    else
4346
0
      snprintf (comment + len, comment_size - len, ", %s",
4347
0
          opnd->cond->names[i]);
4348
0
  }
4349
0
      break;
4350
4351
0
    case AARCH64_OPND_ADDR_ADRP:
4352
0
      addr = ((pc + AARCH64_PCREL_OFFSET) & ~(uint64_t)0xfff)
4353
0
  + opnd->imm.value;
4354
0
      if (pcrel_p)
4355
0
  *pcrel_p = 1;
4356
0
      if (address)
4357
0
  *address = addr;
4358
      /* This is not necessary during the disassembling, as print_address_func
4359
   in the disassemble_info will take care of the printing.  But some
4360
   other callers may be still interested in getting the string in *STR,
4361
   so here we do snprintf regardless.  */
4362
0
      snprintf (buf, size, "%s", style_addr (styler, "#0x%" PRIx64 , addr));
4363
0
      break;
4364
4365
0
    case AARCH64_OPND_ADDR_PCREL14:
4366
0
    case AARCH64_OPND_ADDR_PCREL19:
4367
0
    case AARCH64_OPND_ADDR_PCREL21:
4368
0
    case AARCH64_OPND_ADDR_PCREL26:
4369
0
      addr = pc + AARCH64_PCREL_OFFSET + opnd->imm.value;
4370
0
      if (pcrel_p)
4371
0
  *pcrel_p = 1;
4372
0
      if (address)
4373
0
  *address = addr;
4374
      /* This is not necessary during the disassembling, as print_address_func
4375
   in the disassemble_info will take care of the printing.  But some
4376
   other callers may be still interested in getting the string in *STR,
4377
   so here we do snprintf regardless.  */
4378
0
      snprintf (buf, size, "%s", style_addr (styler, "#0x%" PRIx64, addr));
4379
0
      break;
4380
4381
0
    case AARCH64_OPND_ADDR_SIMPLE:
4382
0
    case AARCH64_OPND_SIMD_ADDR_SIMPLE:
4383
0
    case AARCH64_OPND_SIMD_ADDR_POST:
4384
0
      name = get_64bit_int_reg_name (opnd->addr.base_regno, 1);
4385
0
      if (opnd->type == AARCH64_OPND_SIMD_ADDR_POST)
4386
0
  {
4387
0
    if (opnd->addr.offset.is_reg)
4388
0
      snprintf (buf, size, "[%s], %s",
4389
0
          style_reg (styler, name),
4390
0
          style_reg (styler, "x%d", opnd->addr.offset.regno));
4391
0
    else
4392
0
      snprintf (buf, size, "[%s], %s",
4393
0
          style_reg (styler, name),
4394
0
          style_imm (styler, "#%d", opnd->addr.offset.imm));
4395
0
  }
4396
0
      else
4397
0
  snprintf (buf, size, "[%s]", style_reg (styler, name));
4398
0
      break;
4399
4400
0
    case AARCH64_OPND_ADDR_REGOFF:
4401
0
    case AARCH64_OPND_SVE_ADDR_R:
4402
0
    case AARCH64_OPND_SVE_ADDR_RR:
4403
0
    case AARCH64_OPND_SVE_ADDR_RR_LSL1:
4404
0
    case AARCH64_OPND_SVE_ADDR_RR_LSL2:
4405
0
    case AARCH64_OPND_SVE_ADDR_RR_LSL3:
4406
0
    case AARCH64_OPND_SVE_ADDR_RR_LSL4:
4407
0
    case AARCH64_OPND_SVE_ADDR_RX:
4408
0
    case AARCH64_OPND_SVE_ADDR_RX_LSL1:
4409
0
    case AARCH64_OPND_SVE_ADDR_RX_LSL2:
4410
0
    case AARCH64_OPND_SVE_ADDR_RX_LSL3:
4411
0
      print_register_offset_address
4412
0
  (buf, size, opnd, get_64bit_int_reg_name (opnd->addr.base_regno, 1),
4413
0
   get_offset_int_reg_name (opnd), styler);
4414
0
      break;
4415
4416
0
    case AARCH64_OPND_SVE_ADDR_ZX:
4417
0
      print_register_offset_address
4418
0
  (buf, size, opnd,
4419
0
   get_addr_sve_reg_name (opnd->addr.base_regno, opnd->qualifier),
4420
0
   get_64bit_int_reg_name (opnd->addr.offset.regno, 0), styler);
4421
0
      break;
4422
4423
0
    case AARCH64_OPND_SVE_ADDR_RZ:
4424
0
    case AARCH64_OPND_SVE_ADDR_RZ_LSL1:
4425
0
    case AARCH64_OPND_SVE_ADDR_RZ_LSL2:
4426
0
    case AARCH64_OPND_SVE_ADDR_RZ_LSL3:
4427
0
    case AARCH64_OPND_SVE_ADDR_RZ_XTW_14:
4428
0
    case AARCH64_OPND_SVE_ADDR_RZ_XTW_22:
4429
0
    case AARCH64_OPND_SVE_ADDR_RZ_XTW1_14:
4430
0
    case AARCH64_OPND_SVE_ADDR_RZ_XTW1_22:
4431
0
    case AARCH64_OPND_SVE_ADDR_RZ_XTW2_14:
4432
0
    case AARCH64_OPND_SVE_ADDR_RZ_XTW2_22:
4433
0
    case AARCH64_OPND_SVE_ADDR_RZ_XTW3_14:
4434
0
    case AARCH64_OPND_SVE_ADDR_RZ_XTW3_22:
4435
0
      print_register_offset_address
4436
0
  (buf, size, opnd, get_64bit_int_reg_name (opnd->addr.base_regno, 1),
4437
0
   get_addr_sve_reg_name (opnd->addr.offset.regno, opnd->qualifier),
4438
0
   styler);
4439
0
      break;
4440
4441
0
    case AARCH64_OPND_ADDR_SIMM7:
4442
0
    case AARCH64_OPND_ADDR_SIMM9:
4443
0
    case AARCH64_OPND_ADDR_SIMM9_2:
4444
0
    case AARCH64_OPND_ADDR_SIMM10:
4445
0
    case AARCH64_OPND_ADDR_SIMM11:
4446
0
    case AARCH64_OPND_ADDR_SIMM13:
4447
0
    case AARCH64_OPND_ADDR_OFFSET:
4448
0
    case AARCH64_OPND_SME_ADDR_RI_U4xVL:
4449
0
    case AARCH64_OPND_SVE_ADDR_RI_S4x16:
4450
0
    case AARCH64_OPND_SVE_ADDR_RI_S4x32:
4451
0
    case AARCH64_OPND_SVE_ADDR_RI_S4xVL:
4452
0
    case AARCH64_OPND_SVE_ADDR_RI_S4x2xVL:
4453
0
    case AARCH64_OPND_SVE_ADDR_RI_S4x3xVL:
4454
0
    case AARCH64_OPND_SVE_ADDR_RI_S4x4xVL:
4455
0
    case AARCH64_OPND_SVE_ADDR_RI_S6xVL:
4456
0
    case AARCH64_OPND_SVE_ADDR_RI_S9xVL:
4457
0
    case AARCH64_OPND_SVE_ADDR_RI_U6:
4458
0
    case AARCH64_OPND_SVE_ADDR_RI_U6x2:
4459
0
    case AARCH64_OPND_SVE_ADDR_RI_U6x4:
4460
0
    case AARCH64_OPND_SVE_ADDR_RI_U6x8:
4461
0
      print_immediate_offset_address
4462
0
  (buf, size, opnd, get_64bit_int_reg_name (opnd->addr.base_regno, 1),
4463
0
   styler);
4464
0
      break;
4465
4466
0
    case AARCH64_OPND_SVE_ADDR_ZI_U5:
4467
0
    case AARCH64_OPND_SVE_ADDR_ZI_U5x2:
4468
0
    case AARCH64_OPND_SVE_ADDR_ZI_U5x4:
4469
0
    case AARCH64_OPND_SVE_ADDR_ZI_U5x8:
4470
0
      print_immediate_offset_address
4471
0
  (buf, size, opnd,
4472
0
   get_addr_sve_reg_name (opnd->addr.base_regno, opnd->qualifier),
4473
0
   styler);
4474
0
      break;
4475
4476
0
    case AARCH64_OPND_SVE_ADDR_ZZ_LSL:
4477
0
    case AARCH64_OPND_SVE_ADDR_ZZ_SXTW:
4478
0
    case AARCH64_OPND_SVE_ADDR_ZZ_UXTW:
4479
0
      print_register_offset_address
4480
0
  (buf, size, opnd,
4481
0
   get_addr_sve_reg_name (opnd->addr.base_regno, opnd->qualifier),
4482
0
   get_addr_sve_reg_name (opnd->addr.offset.regno, opnd->qualifier),
4483
0
   styler);
4484
0
      break;
4485
4486
0
    case AARCH64_OPND_ADDR_UIMM12:
4487
0
      name = get_64bit_int_reg_name (opnd->addr.base_regno, 1);
4488
0
      if (opnd->addr.offset.imm)
4489
0
  snprintf (buf, size, "[%s, %s]",
4490
0
      style_reg (styler, name),
4491
0
      style_imm (styler, "#%d", opnd->addr.offset.imm));
4492
0
      else
4493
0
  snprintf (buf, size, "[%s]", style_reg (styler, name));
4494
0
      break;
4495
4496
0
    case AARCH64_OPND_SYSREG:
4497
0
      for (i = 0; aarch64_sys_regs[i].name; ++i)
4498
0
  {
4499
0
    const aarch64_sys_reg *sr = aarch64_sys_regs + i;
4500
4501
0
    bool exact_match
4502
0
      = (!(sr->flags & (F_REG_READ | F_REG_WRITE))
4503
0
      || (sr->flags & opnd->sysreg.flags) == opnd->sysreg.flags)
4504
0
      && AARCH64_CPU_HAS_FEATURE (features, sr->features);
4505
4506
    /* Try and find an exact match, But if that fails, return the first
4507
       partial match that was found.  */
4508
0
    if (aarch64_sys_regs[i].value == opnd->sysreg.value
4509
0
        && ! aarch64_sys_reg_deprecated_p (aarch64_sys_regs[i].flags)
4510
0
        && (name == NULL || exact_match))
4511
0
      {
4512
0
        name = aarch64_sys_regs[i].name;
4513
0
        if (exact_match)
4514
0
    {
4515
0
      if (notes)
4516
0
        *notes = NULL;
4517
0
      break;
4518
0
    }
4519
4520
        /* If we didn't match exactly, that means the presense of a flag
4521
     indicates what we didn't want for this instruction.  e.g. If
4522
     F_REG_READ is there, that means we were looking for a write
4523
     register.  See aarch64_ext_sysreg.  */
4524
0
        if (aarch64_sys_regs[i].flags & F_REG_WRITE)
4525
0
    *notes = _("reading from a write-only register");
4526
0
        else if (aarch64_sys_regs[i].flags & F_REG_READ)
4527
0
    *notes = _("writing to a read-only register");
4528
0
      }
4529
0
  }
4530
4531
0
      if (name)
4532
0
  snprintf (buf, size, "%s", style_reg (styler, name));
4533
0
      else
4534
0
  {
4535
    /* Implementation defined system register.  */
4536
0
    unsigned int value = opnd->sysreg.value;
4537
0
    snprintf (buf, size, "%s",
4538
0
        style_reg (styler, "s%u_%u_c%u_c%u_%u",
4539
0
             (value >> 14) & 0x3, (value >> 11) & 0x7,
4540
0
             (value >> 7) & 0xf, (value >> 3) & 0xf,
4541
0
             value & 0x7));
4542
0
  }
4543
0
      break;
4544
4545
0
    case AARCH64_OPND_PSTATEFIELD:
4546
0
      for (i = 0; aarch64_pstatefields[i].name; ++i)
4547
0
        if (aarch64_pstatefields[i].value == opnd->pstatefield)
4548
0
          {
4549
            /* PSTATEFIELD name is encoded partially in CRm[3:1] for SVCRSM,
4550
               SVCRZA and SVCRSMZA.  */
4551
0
            uint32_t flags = aarch64_pstatefields[i].flags;
4552
0
            if (flags & F_REG_IN_CRM
4553
0
                && (PSTATE_DECODE_CRM (opnd->sysreg.flags)
4554
0
                    != PSTATE_DECODE_CRM (flags)))
4555
0
              continue;
4556
0
            break;
4557
0
          }
4558
0
      assert (aarch64_pstatefields[i].name);
4559
0
      snprintf (buf, size, "%s",
4560
0
    style_reg (styler, aarch64_pstatefields[i].name));
4561
0
      break;
4562
4563
0
    case AARCH64_OPND_SYSREG_AT:
4564
0
    case AARCH64_OPND_SYSREG_DC:
4565
0
    case AARCH64_OPND_SYSREG_IC:
4566
0
    case AARCH64_OPND_SYSREG_TLBI:
4567
0
    case AARCH64_OPND_SYSREG_SR:
4568
0
      snprintf (buf, size, "%s", style_reg (styler, opnd->sysins_op->name));
4569
0
      break;
4570
4571
0
    case AARCH64_OPND_BARRIER:
4572
0
    case AARCH64_OPND_BARRIER_DSB_NXS:
4573
0
      {
4574
0
  if (opnd->barrier->name[0] == '#')
4575
0
    snprintf (buf, size, "%s", style_imm (styler, opnd->barrier->name));
4576
0
  else
4577
0
    snprintf (buf, size, "%s",
4578
0
        style_sub_mnem (styler, opnd->barrier->name));
4579
0
      }
4580
0
      break;
4581
4582
0
    case AARCH64_OPND_BARRIER_ISB:
4583
      /* Operand can be omitted, e.g. in DCPS1.  */
4584
0
      if (! optional_operand_p (opcode, idx)
4585
0
    || (opnd->barrier->value
4586
0
        != get_optional_operand_default_value (opcode)))
4587
0
  snprintf (buf, size, "%s",
4588
0
      style_imm (styler, "#0x%x", opnd->barrier->value));
4589
0
      break;
4590
4591
0
    case AARCH64_OPND_PRFOP:
4592
0
      if (opnd->prfop->name != NULL)
4593
0
  snprintf (buf, size, "%s", style_sub_mnem (styler, opnd->prfop->name));
4594
0
      else
4595
0
  snprintf (buf, size, "%s", style_imm (styler, "#0x%02x",
4596
0
                opnd->prfop->value));
4597
0
      break;
4598
4599
0
    case AARCH64_OPND_RPRFMOP:
4600
0
      enum_value = opnd->imm.value;
4601
0
      if (enum_value < ARRAY_SIZE (aarch64_rprfmop_array)
4602
0
    && aarch64_rprfmop_array[enum_value])
4603
0
  snprintf (buf, size, "%s",
4604
0
      style_reg (styler, aarch64_rprfmop_array[enum_value]));
4605
0
      else
4606
0
  snprintf (buf, size, "%s",
4607
0
      style_imm (styler, "#%" PRIi64, opnd->imm.value));
4608
0
      break;
4609
4610
0
    case AARCH64_OPND_BARRIER_PSB:
4611
0
      snprintf (buf, size, "%s", style_sub_mnem (styler, "csync"));
4612
0
      break;
4613
4614
0
    case AARCH64_OPND_SME_ZT0:
4615
0
      snprintf (buf, size, "%s", style_reg (styler, "zt0"));
4616
0
      break;
4617
4618
0
    case AARCH64_OPND_SME_ZT0_INDEX:
4619
0
      snprintf (buf, size, "%s[%s]", style_reg (styler, "zt0"),
4620
0
    style_imm (styler, "%d", (int) opnd->imm.value));
4621
0
      break;
4622
4623
0
    case AARCH64_OPND_SME_ZT0_LIST:
4624
0
      snprintf (buf, size, "{%s}", style_reg (styler, "zt0"));
4625
0
      break;
4626
4627
0
    case AARCH64_OPND_BTI_TARGET:
4628
0
      if ((HINT_FLAG (opnd->hint_option->value) & HINT_OPD_F_NOPRINT) == 0)
4629
0
  snprintf (buf, size, "%s",
4630
0
      style_sub_mnem (styler, opnd->hint_option->name));
4631
0
      break;
4632
4633
0
    case AARCH64_OPND_MOPS_ADDR_Rd:
4634
0
    case AARCH64_OPND_MOPS_ADDR_Rs:
4635
0
      snprintf (buf, size, "[%s]!",
4636
0
    style_reg (styler,
4637
0
         get_int_reg_name (opnd->reg.regno,
4638
0
               AARCH64_OPND_QLF_X, 0)));
4639
0
      break;
4640
4641
0
    case AARCH64_OPND_MOPS_WB_Rn:
4642
0
      snprintf (buf, size, "%s!",
4643
0
    style_reg (styler, get_int_reg_name (opnd->reg.regno,
4644
0
                 AARCH64_OPND_QLF_X, 0)));
4645
0
      break;
4646
4647
0
    default:
4648
0
      snprintf (buf, size, "<invalid>");
4649
0
      break;
4650
0
    }
4651
0
}
4652

4653
#define CPENC(op0,op1,crn,crm,op2) \
4654
0
  ((((op0) << 19) | ((op1) << 16) | ((crn) << 12) | ((crm) << 8) | ((op2) << 5)) >> 5)
4655
  /* for 3.9.3 Instructions for Accessing Special Purpose Registers */
4656
#define CPEN_(op1,crm,op2) CPENC(3,(op1),4,(crm),(op2))
4657
  /* for 3.9.10 System Instructions */
4658
0
#define CPENS(op1,crn,crm,op2) CPENC(1,(op1),(crn),(crm),(op2))
4659
4660
#define C0  0
4661
#define C1  1
4662
#define C2  2
4663
#define C3  3
4664
#define C4  4
4665
#define C5  5
4666
#define C6  6
4667
#define C7  7
4668
#define C8  8
4669
#define C9  9
4670
#define C10 10
4671
#define C11 11
4672
#define C12 12
4673
#define C13 13
4674
#define C14 14
4675
#define C15 15
4676
4677
#define SYSREG(name, encoding, flags, features) \
4678
  { name, encoding, flags, features }
4679
4680
#define SR_CORE(n,e,f) SYSREG (n,e,f,0)
4681
4682
#define SR_FEAT(n,e,f,feat) \
4683
  SYSREG ((n), (e), (f) | F_ARCHEXT, AARCH64_FEATURE_##feat)
4684
4685
#define SR_FEAT2(n,e,f,fe1,fe2) \
4686
  SYSREG ((n), (e), (f) | F_ARCHEXT, \
4687
    AARCH64_FEATURE_##fe1 | AARCH64_FEATURE_##fe2)
4688
4689
#define SR_V8_1_A(n,e,f) SR_FEAT2(n,e,f,V8A,V8_1A)
4690
#define SR_V8_4_A(n,e,f) SR_FEAT2(n,e,f,V8A,V8_4A)
4691
4692
#define SR_V8A(n,e,f)   SR_FEAT (n,e,f,V8A)
4693
#define SR_V8R(n,e,f)   SR_FEAT (n,e,f,V8R)
4694
#define SR_V8_1A(n,e,f)   SR_FEAT (n,e,f,V8_1A)
4695
#define SR_V8_2A(n,e,f)   SR_FEAT (n,e,f,V8_2A)
4696
#define SR_V8_3A(n,e,f)   SR_FEAT (n,e,f,V8_3A)
4697
#define SR_V8_4A(n,e,f)   SR_FEAT (n,e,f,V8_4A)
4698
#define SR_V8_6A(n,e,f)   SR_FEAT (n,e,f,V8_6A)
4699
#define SR_V8_7A(n,e,f)   SR_FEAT (n,e,f,V8_7A)
4700
#define SR_V8_8A(n,e,f)   SR_FEAT (n,e,f,V8_8A)
4701
/* Has no separate libopcodes feature flag, but separated out for clarity.  */
4702
#define SR_GIC(n,e,f)   SR_CORE (n,e,f)
4703
/* Has no separate libopcodes feature flag, but separated out for clarity.  */
4704
#define SR_AMU(n,e,f)   SR_FEAT (n,e,f,V8_4A)
4705
#define SR_LOR(n,e,f)   SR_FEAT (n,e,f,LOR)
4706
#define SR_PAN(n,e,f)   SR_FEAT (n,e,f,PAN)
4707
#define SR_RAS(n,e,f)   SR_FEAT (n,e,f,RAS)
4708
#define SR_RNG(n,e,f)   SR_FEAT (n,e,f,RNG)
4709
#define SR_SME(n,e,f)   SR_FEAT (n,e,f,SME)
4710
#define SR_SSBS(n,e,f)    SR_FEAT (n,e,f,SSBS)
4711
#define SR_SVE(n,e,f)   SR_FEAT (n,e,f,SVE)
4712
#define SR_ID_PFR2(n,e,f) SR_FEAT (n,e,f,ID_PFR2)
4713
#define SR_PROFILE(n,e,f) SR_FEAT (n,e,f,PROFILE)
4714
#define SR_MEMTAG(n,e,f)  SR_FEAT (n,e,f,MEMTAG)
4715
#define SR_SCXTNUM(n,e,f) SR_FEAT (n,e,f,SCXTNUM)
4716
4717
#define SR_EXPAND_ELx(f,x) \
4718
  f (x, 1),  \
4719
  f (x, 2),  \
4720
  f (x, 3),  \
4721
  f (x, 4),  \
4722
  f (x, 5),  \
4723
  f (x, 6),  \
4724
  f (x, 7),  \
4725
  f (x, 8),  \
4726
  f (x, 9),  \
4727
  f (x, 10), \
4728
  f (x, 11), \
4729
  f (x, 12), \
4730
  f (x, 13), \
4731
  f (x, 14), \
4732
  f (x, 15),
4733
4734
#define SR_EXPAND_EL12(f) \
4735
  SR_EXPAND_ELx (f,1) \
4736
  SR_EXPAND_ELx (f,2)
4737
4738
/* TODO there is one more issues need to be resolved
4739
   1. handle cpu-implementation-defined system registers.
4740
4741
   Note that the F_REG_{READ,WRITE} flags mean read-only and write-only
4742
   respectively.  If neither of these are set then the register is read-write.  */
4743
const aarch64_sys_reg aarch64_sys_regs [] =
4744
{
4745
  SR_CORE ("spsr_el1",    CPEN_ (0,C0,0),   0), /* = spsr_svc.  */
4746
  SR_V8_1A ("spsr_el12",    CPEN_ (5,C0,0),   0),
4747
  SR_CORE ("elr_el1",   CPEN_ (0,C0,1),   0),
4748
  SR_V8_1A ("elr_el12",   CPEN_ (5,C0,1),   0),
4749
  SR_CORE ("sp_el0",    CPEN_ (0,C1,0),   0),
4750
  SR_CORE ("spsel",   CPEN_ (0,C2,0),   0),
4751
  SR_CORE ("daif",    CPEN_ (3,C2,1),   0),
4752
  SR_CORE ("currentel",   CPEN_ (0,C2,2),   F_REG_READ),
4753
  SR_PAN  ("pan",   CPEN_ (0,C2,3),   0),
4754
  SR_V8_2A ("uao",    CPEN_ (0,C2,4),   0),
4755
  SR_CORE ("nzcv",    CPEN_ (3,C2,0),   0),
4756
  SR_SSBS ("ssbs",    CPEN_ (3,C2,6),   0),
4757
  SR_CORE ("fpcr",    CPEN_ (3,C4,0),   0),
4758
  SR_CORE ("fpsr",    CPEN_ (3,C4,1),   0),
4759
  SR_CORE ("dspsr_el0",   CPEN_ (3,C5,0),   0),
4760
  SR_CORE ("dlr_el0",   CPEN_ (3,C5,1),   0),
4761
  SR_CORE ("spsr_el2",    CPEN_ (4,C0,0),   0), /* = spsr_hyp.  */
4762
  SR_CORE ("elr_el2",   CPEN_ (4,C0,1),   0),
4763
  SR_CORE ("sp_el1",    CPEN_ (4,C1,0),   0),
4764
  SR_CORE ("spsr_irq",    CPEN_ (4,C3,0),   0),
4765
  SR_CORE ("spsr_abt",    CPEN_ (4,C3,1),   0),
4766
  SR_CORE ("spsr_und",    CPEN_ (4,C3,2),   0),
4767
  SR_CORE ("spsr_fiq",    CPEN_ (4,C3,3),   0),
4768
  SR_CORE ("spsr_el3",    CPEN_ (6,C0,0),   0),
4769
  SR_CORE ("elr_el3",   CPEN_ (6,C0,1),   0),
4770
  SR_CORE ("sp_el2",    CPEN_ (6,C1,0),   0),
4771
  SR_CORE ("spsr_svc",    CPEN_ (0,C0,0),   F_DEPRECATED), /* = spsr_el1.  */
4772
  SR_CORE ("spsr_hyp",    CPEN_ (4,C0,0),   F_DEPRECATED), /* = spsr_el2.  */
4773
  SR_CORE ("midr_el1",    CPENC (3,0,C0,C0,0),  F_REG_READ),
4774
  SR_CORE ("ctr_el0",   CPENC (3,3,C0,C0,1),  F_REG_READ),
4775
  SR_CORE ("mpidr_el1",   CPENC (3,0,C0,C0,5),  F_REG_READ),
4776
  SR_CORE ("revidr_el1",  CPENC (3,0,C0,C0,6),  F_REG_READ),
4777
  SR_CORE ("aidr_el1",    CPENC (3,1,C0,C0,7),  F_REG_READ),
4778
  SR_CORE ("dczid_el0",   CPENC (3,3,C0,C0,7),  F_REG_READ),
4779
  SR_CORE ("id_dfr0_el1", CPENC (3,0,C0,C1,2),  F_REG_READ),
4780
  SR_CORE ("id_dfr1_el1", CPENC (3,0,C0,C3,5),  F_REG_READ),
4781
  SR_CORE ("id_pfr0_el1", CPENC (3,0,C0,C1,0),  F_REG_READ),
4782
  SR_CORE ("id_pfr1_el1", CPENC (3,0,C0,C1,1),  F_REG_READ),
4783
  SR_ID_PFR2 ("id_pfr2_el1",  CPENC (3,0,C0,C3,4),  F_REG_READ),
4784
  SR_CORE ("id_afr0_el1", CPENC (3,0,C0,C1,3),  F_REG_READ),
4785
  SR_CORE ("id_mmfr0_el1",  CPENC (3,0,C0,C1,4),  F_REG_READ),
4786
  SR_CORE ("id_mmfr1_el1",  CPENC (3,0,C0,C1,5),  F_REG_READ),
4787
  SR_CORE ("id_mmfr2_el1",  CPENC (3,0,C0,C1,6),  F_REG_READ),
4788
  SR_CORE ("id_mmfr3_el1",  CPENC (3,0,C0,C1,7),  F_REG_READ),
4789
  SR_CORE ("id_mmfr4_el1",  CPENC (3,0,C0,C2,6),  F_REG_READ),
4790
  SR_CORE ("id_mmfr5_el1",  CPENC (3,0,C0,C3,6),  F_REG_READ),
4791
  SR_CORE ("id_isar0_el1",  CPENC (3,0,C0,C2,0),  F_REG_READ),
4792
  SR_CORE ("id_isar1_el1",  CPENC (3,0,C0,C2,1),  F_REG_READ),
4793
  SR_CORE ("id_isar2_el1",  CPENC (3,0,C0,C2,2),  F_REG_READ),
4794
  SR_CORE ("id_isar3_el1",  CPENC (3,0,C0,C2,3),  F_REG_READ),
4795
  SR_CORE ("id_isar4_el1",  CPENC (3,0,C0,C2,4),  F_REG_READ),
4796
  SR_CORE ("id_isar5_el1",  CPENC (3,0,C0,C2,5),  F_REG_READ),
4797
  SR_CORE ("id_isar6_el1",  CPENC (3,0,C0,C2,7),  F_REG_READ),
4798
  SR_CORE ("mvfr0_el1",   CPENC (3,0,C0,C3,0),  F_REG_READ),
4799
  SR_CORE ("mvfr1_el1",   CPENC (3,0,C0,C3,1),  F_REG_READ),
4800
  SR_CORE ("mvfr2_el1",   CPENC (3,0,C0,C3,2),  F_REG_READ),
4801
  SR_CORE ("ccsidr_el1",  CPENC (3,1,C0,C0,0),  F_REG_READ),
4802
  SR_V8_3A ("ccsidr2_el1",       CPENC (3,1,C0,C0,2),    F_REG_READ),
4803
  SR_CORE ("id_aa64pfr0_el1", CPENC (3,0,C0,C4,0),  F_REG_READ),
4804
  SR_CORE ("id_aa64pfr1_el1", CPENC (3,0,C0,C4,1),  F_REG_READ),
4805
  SR_CORE ("id_aa64dfr0_el1", CPENC (3,0,C0,C5,0),  F_REG_READ),
4806
  SR_CORE ("id_aa64dfr1_el1", CPENC (3,0,C0,C5,1),  F_REG_READ),
4807
  SR_CORE ("id_aa64isar0_el1",  CPENC (3,0,C0,C6,0),  F_REG_READ),
4808
  SR_CORE ("id_aa64isar1_el1",  CPENC (3,0,C0,C6,1),  F_REG_READ),
4809
  SR_CORE ("id_aa64isar2_el1",  CPENC (3,0,C0,C6,2),  F_REG_READ),
4810
  SR_CORE ("id_aa64mmfr0_el1",  CPENC (3,0,C0,C7,0),  F_REG_READ),
4811
  SR_CORE ("id_aa64mmfr1_el1",  CPENC (3,0,C0,C7,1),  F_REG_READ),
4812
  SR_CORE ("id_aa64mmfr2_el1",  CPENC (3,0,C0,C7,2),  F_REG_READ),
4813
  SR_CORE ("id_aa64afr0_el1", CPENC (3,0,C0,C5,4),  F_REG_READ),
4814
  SR_CORE ("id_aa64afr1_el1", CPENC (3,0,C0,C5,5),  F_REG_READ),
4815
  SR_SVE  ("id_aa64zfr0_el1", CPENC (3,0,C0,C4,4),  F_REG_READ),
4816
  SR_CORE ("clidr_el1",   CPENC (3,1,C0,C0,1),  F_REG_READ),
4817
  SR_CORE ("csselr_el1",  CPENC (3,2,C0,C0,0),  0),
4818
  SR_CORE ("vpidr_el2",   CPENC (3,4,C0,C0,0),  0),
4819
  SR_CORE ("vmpidr_el2",  CPENC (3,4,C0,C0,5),  0),
4820
  SR_CORE ("sctlr_el1",   CPENC (3,0,C1,C0,0),  0),
4821
  SR_CORE ("sctlr_el2",   CPENC (3,4,C1,C0,0),  0),
4822
  SR_CORE ("sctlr_el3",   CPENC (3,6,C1,C0,0),  0),
4823
  SR_V8_1A ("sctlr_el12", CPENC (3,5,C1,C0,0),  0),
4824
  SR_CORE ("actlr_el1",   CPENC (3,0,C1,C0,1),  0),
4825
  SR_CORE ("actlr_el2",   CPENC (3,4,C1,C0,1),  0),
4826
  SR_CORE ("actlr_el3",   CPENC (3,6,C1,C0,1),  0),
4827
  SR_CORE ("cpacr_el1",   CPENC (3,0,C1,C0,2),  0),
4828
  SR_V8_1A ("cpacr_el12", CPENC (3,5,C1,C0,2),  0),
4829
  SR_CORE ("cptr_el2",    CPENC (3,4,C1,C1,2),  0),
4830
  SR_CORE ("cptr_el3",    CPENC (3,6,C1,C1,2),  0),
4831
  SR_CORE ("scr_el3",   CPENC (3,6,C1,C1,0),  0),
4832
  SR_CORE ("hcr_el2",   CPENC (3,4,C1,C1,0),  0),
4833
  SR_CORE ("mdcr_el2",    CPENC (3,4,C1,C1,1),  0),
4834
  SR_CORE ("mdcr_el3",    CPENC (3,6,C1,C3,1),  0),
4835
  SR_CORE ("hstr_el2",    CPENC (3,4,C1,C1,3),  0),
4836
  SR_CORE ("hacr_el2",    CPENC (3,4,C1,C1,7),  0),
4837
  SR_SVE  ("zcr_el1",   CPENC (3,0,C1,C2,0),  0),
4838
  SR_SVE  ("zcr_el12",    CPENC (3,5,C1,C2,0),  0),
4839
  SR_SVE  ("zcr_el2",   CPENC (3,4,C1,C2,0),  0),
4840
  SR_SVE  ("zcr_el3",   CPENC (3,6,C1,C2,0),  0),
4841
  SR_CORE ("ttbr0_el1",   CPENC (3,0,C2,C0,0),  0),
4842
  SR_CORE ("ttbr1_el1",   CPENC (3,0,C2,C0,1),  0),
4843
  SR_V8A ("ttbr0_el2",    CPENC (3,4,C2,C0,0),  0),
4844
  SR_V8_1_A ("ttbr1_el2", CPENC (3,4,C2,C0,1),  0),
4845
  SR_CORE ("ttbr0_el3",   CPENC (3,6,C2,C0,0),  0),
4846
  SR_V8_1A ("ttbr0_el12", CPENC (3,5,C2,C0,0),  0),
4847
  SR_V8_1A ("ttbr1_el12", CPENC (3,5,C2,C0,1),  0),
4848
  SR_V8A ("vttbr_el2",    CPENC (3,4,C2,C1,0),  0),
4849
  SR_CORE ("tcr_el1",   CPENC (3,0,C2,C0,2),  0),
4850
  SR_CORE ("tcr_el2",   CPENC (3,4,C2,C0,2),  0),
4851
  SR_CORE ("tcr_el3",   CPENC (3,6,C2,C0,2),  0),
4852
  SR_V8_1A ("tcr_el12",   CPENC (3,5,C2,C0,2),  0),
4853
  SR_CORE ("vtcr_el2",    CPENC (3,4,C2,C1,2),  0),
4854
  SR_V8_3A ("apiakeylo_el1",  CPENC (3,0,C2,C1,0),  0),
4855
  SR_V8_3A ("apiakeyhi_el1",  CPENC (3,0,C2,C1,1),  0),
4856
  SR_V8_3A ("apibkeylo_el1",  CPENC (3,0,C2,C1,2),  0),
4857
  SR_V8_3A ("apibkeyhi_el1",  CPENC (3,0,C2,C1,3),  0),
4858
  SR_V8_3A ("apdakeylo_el1",  CPENC (3,0,C2,C2,0),  0),
4859
  SR_V8_3A ("apdakeyhi_el1",  CPENC (3,0,C2,C2,1),  0),
4860
  SR_V8_3A ("apdbkeylo_el1",  CPENC (3,0,C2,C2,2),  0),
4861
  SR_V8_3A ("apdbkeyhi_el1",  CPENC (3,0,C2,C2,3),  0),
4862
  SR_V8_3A ("apgakeylo_el1",  CPENC (3,0,C2,C3,0),  0),
4863
  SR_V8_3A ("apgakeyhi_el1",  CPENC (3,0,C2,C3,1),  0),
4864
  SR_CORE ("afsr0_el1",   CPENC (3,0,C5,C1,0),  0),
4865
  SR_CORE ("afsr1_el1",   CPENC (3,0,C5,C1,1),  0),
4866
  SR_CORE ("afsr0_el2",   CPENC (3,4,C5,C1,0),  0),
4867
  SR_CORE ("afsr1_el2",   CPENC (3,4,C5,C1,1),  0),
4868
  SR_CORE ("afsr0_el3",   CPENC (3,6,C5,C1,0),  0),
4869
  SR_V8_1A ("afsr0_el12", CPENC (3,5,C5,C1,0),  0),
4870
  SR_CORE ("afsr1_el3",   CPENC (3,6,C5,C1,1),  0),
4871
  SR_V8_1A ("afsr1_el12", CPENC (3,5,C5,C1,1),  0),
4872
  SR_CORE ("esr_el1",   CPENC (3,0,C5,C2,0),  0),
4873
  SR_CORE ("esr_el2",   CPENC (3,4,C5,C2,0),  0),
4874
  SR_CORE ("esr_el3",   CPENC (3,6,C5,C2,0),  0),
4875
  SR_V8_1A ("esr_el12",   CPENC (3,5,C5,C2,0),  0),
4876
  SR_RAS  ("vsesr_el2",   CPENC (3,4,C5,C2,3),  0),
4877
  SR_CORE ("fpexc32_el2", CPENC (3,4,C5,C3,0),  0),
4878
  SR_RAS  ("erridr_el1",  CPENC (3,0,C5,C3,0),  F_REG_READ),
4879
  SR_RAS  ("errselr_el1", CPENC (3,0,C5,C3,1),  0),
4880
  SR_RAS  ("erxfr_el1",   CPENC (3,0,C5,C4,0),  F_REG_READ),
4881
  SR_RAS  ("erxctlr_el1", CPENC (3,0,C5,C4,1),  0),
4882
  SR_RAS  ("erxstatus_el1", CPENC (3,0,C5,C4,2),  0),
4883
  SR_RAS  ("erxaddr_el1", CPENC (3,0,C5,C4,3),  0),
4884
  SR_RAS  ("erxmisc0_el1",  CPENC (3,0,C5,C5,0),  0),
4885
  SR_RAS  ("erxmisc1_el1",  CPENC (3,0,C5,C5,1),  0),
4886
  SR_RAS  ("erxmisc2_el1",  CPENC (3,0,C5,C5,2),  0),
4887
  SR_RAS  ("erxmisc3_el1",  CPENC (3,0,C5,C5,3),  0),
4888
  SR_RAS  ("erxpfgcdn_el1", CPENC (3,0,C5,C4,6),  0),
4889
  SR_RAS  ("erxpfgctl_el1", CPENC (3,0,C5,C4,5),  0),
4890
  SR_RAS  ("erxpfgf_el1", CPENC (3,0,C5,C4,4),  F_REG_READ),
4891
  SR_CORE ("far_el1",   CPENC (3,0,C6,C0,0),  0),
4892
  SR_CORE ("far_el2",   CPENC (3,4,C6,C0,0),  0),
4893
  SR_CORE ("far_el3",   CPENC (3,6,C6,C0,0),  0),
4894
  SR_V8_1A ("far_el12",   CPENC (3,5,C6,C0,0),  0),
4895
  SR_CORE ("hpfar_el2",   CPENC (3,4,C6,C0,4),  0),
4896
  SR_CORE ("par_el1",   CPENC (3,0,C7,C4,0),  0),
4897
  SR_CORE ("mair_el1",    CPENC (3,0,C10,C2,0), 0),
4898
  SR_CORE ("mair_el2",    CPENC (3,4,C10,C2,0), 0),
4899
  SR_CORE ("mair_el3",    CPENC (3,6,C10,C2,0), 0),
4900
  SR_V8_1A ("mair_el12",    CPENC (3,5,C10,C2,0), 0),
4901
  SR_CORE ("amair_el1",   CPENC (3,0,C10,C3,0), 0),
4902
  SR_CORE ("amair_el2",   CPENC (3,4,C10,C3,0), 0),
4903
  SR_CORE ("amair_el3",   CPENC (3,6,C10,C3,0), 0),
4904
  SR_V8_1A ("amair_el12", CPENC (3,5,C10,C3,0), 0),
4905
  SR_CORE ("vbar_el1",    CPENC (3,0,C12,C0,0), 0),
4906
  SR_CORE ("vbar_el2",    CPENC (3,4,C12,C0,0), 0),
4907
  SR_CORE ("vbar_el3",    CPENC (3,6,C12,C0,0), 0),
4908
  SR_V8_1A ("vbar_el12",    CPENC (3,5,C12,C0,0), 0),
4909
  SR_CORE ("rvbar_el1",   CPENC (3,0,C12,C0,1), F_REG_READ),
4910
  SR_CORE ("rvbar_el2",   CPENC (3,4,C12,C0,1), F_REG_READ),
4911
  SR_CORE ("rvbar_el3",   CPENC (3,6,C12,C0,1), F_REG_READ),
4912
  SR_CORE ("rmr_el1",   CPENC (3,0,C12,C0,2), 0),
4913
  SR_CORE ("rmr_el2",   CPENC (3,4,C12,C0,2), 0),
4914
  SR_CORE ("rmr_el3",   CPENC (3,6,C12,C0,2), 0),
4915
  SR_CORE ("isr_el1",   CPENC (3,0,C12,C1,0), F_REG_READ),
4916
  SR_RAS  ("disr_el1",    CPENC (3,0,C12,C1,1), 0),
4917
  SR_RAS  ("vdisr_el2",   CPENC (3,4,C12,C1,1), 0),
4918
  SR_CORE ("contextidr_el1",  CPENC (3,0,C13,C0,1), 0),
4919
  SR_V8_1A ("contextidr_el2", CPENC (3,4,C13,C0,1), 0),
4920
  SR_V8_1A ("contextidr_el12",  CPENC (3,5,C13,C0,1), 0),
4921
  SR_RNG  ("rndr",    CPENC (3,3,C2,C4,0),  F_REG_READ),
4922
  SR_RNG  ("rndrrs",    CPENC (3,3,C2,C4,1),  F_REG_READ),
4923
  SR_MEMTAG ("tco",   CPENC (3,3,C4,C2,7),  0),
4924
  SR_MEMTAG ("tfsre0_el1",  CPENC (3,0,C5,C6,1),  0),
4925
  SR_MEMTAG ("tfsr_el1",  CPENC (3,0,C5,C6,0),  0),
4926
  SR_MEMTAG ("tfsr_el2",  CPENC (3,4,C5,C6,0),  0),
4927
  SR_MEMTAG ("tfsr_el3",  CPENC (3,6,C5,C6,0),  0),
4928
  SR_MEMTAG ("tfsr_el12", CPENC (3,5,C5,C6,0),  0),
4929
  SR_MEMTAG ("rgsr_el1",  CPENC (3,0,C1,C0,5),  0),
4930
  SR_MEMTAG ("gcr_el1",   CPENC (3,0,C1,C0,6),  0),
4931
  SR_MEMTAG ("gmid_el1",  CPENC (3,1,C0,C0,4),  F_REG_READ),
4932
  SR_CORE ("tpidr_el0",   CPENC (3,3,C13,C0,2), 0),
4933
  SR_CORE ("tpidrro_el0",       CPENC (3,3,C13,C0,3), 0),
4934
  SR_CORE ("tpidr_el1",   CPENC (3,0,C13,C0,4), 0),
4935
  SR_CORE ("tpidr_el2",   CPENC (3,4,C13,C0,2), 0),
4936
  SR_CORE ("tpidr_el3",   CPENC (3,6,C13,C0,2), 0),
4937
  SR_SCXTNUM ("scxtnum_el0",  CPENC (3,3,C13,C0,7), 0),
4938
  SR_SCXTNUM ("scxtnum_el1",  CPENC (3,0,C13,C0,7), 0),
4939
  SR_SCXTNUM ("scxtnum_el2",  CPENC (3,4,C13,C0,7), 0),
4940
  SR_SCXTNUM ("scxtnum_el12",   CPENC (3,5,C13,C0,7), 0),
4941
  SR_SCXTNUM ("scxtnum_el3",    CPENC (3,6,C13,C0,7), 0),
4942
  SR_CORE ("teecr32_el1",       CPENC (2,2,C0, C0,0), 0), /* See section 3.9.7.1.  */
4943
  SR_CORE ("cntfrq_el0",  CPENC (3,3,C14,C0,0), 0),
4944
  SR_CORE ("cntpct_el0",  CPENC (3,3,C14,C0,1), F_REG_READ),
4945
  SR_CORE ("cntvct_el0",  CPENC (3,3,C14,C0,2), F_REG_READ),
4946
  SR_CORE ("cntvoff_el2",       CPENC (3,4,C14,C0,3), 0),
4947
  SR_CORE ("cntkctl_el1",       CPENC (3,0,C14,C1,0), 0),
4948
  SR_V8_1A ("cntkctl_el12", CPENC (3,5,C14,C1,0), 0),
4949
  SR_CORE ("cnthctl_el2", CPENC (3,4,C14,C1,0), 0),
4950
  SR_CORE ("cntp_tval_el0", CPENC (3,3,C14,C2,0), 0),
4951
  SR_V8_1A ("cntp_tval_el02", CPENC (3,5,C14,C2,0), 0),
4952
  SR_CORE ("cntp_ctl_el0",      CPENC (3,3,C14,C2,1), 0),
4953
  SR_V8_1A ("cntp_ctl_el02",  CPENC (3,5,C14,C2,1), 0),
4954
  SR_CORE ("cntp_cval_el0",     CPENC (3,3,C14,C2,2), 0),
4955
  SR_V8_1A ("cntp_cval_el02", CPENC (3,5,C14,C2,2), 0),
4956
  SR_CORE ("cntv_tval_el0",     CPENC (3,3,C14,C3,0), 0),
4957
  SR_V8_1A ("cntv_tval_el02", CPENC (3,5,C14,C3,0), 0),
4958
  SR_CORE ("cntv_ctl_el0",      CPENC (3,3,C14,C3,1), 0),
4959
  SR_V8_1A ("cntv_ctl_el02",  CPENC (3,5,C14,C3,1), 0),
4960
  SR_CORE ("cntv_cval_el0",     CPENC (3,3,C14,C3,2), 0),
4961
  SR_V8_1A ("cntv_cval_el02", CPENC (3,5,C14,C3,2), 0),
4962
  SR_CORE ("cnthp_tval_el2",  CPENC (3,4,C14,C2,0), 0),
4963
  SR_CORE ("cnthp_ctl_el2", CPENC (3,4,C14,C2,1), 0),
4964
  SR_CORE ("cnthp_cval_el2",  CPENC (3,4,C14,C2,2), 0),
4965
  SR_CORE ("cntps_tval_el1",  CPENC (3,7,C14,C2,0), 0),
4966
  SR_CORE ("cntps_ctl_el1", CPENC (3,7,C14,C2,1), 0),
4967
  SR_CORE ("cntps_cval_el1",  CPENC (3,7,C14,C2,2), 0),
4968
  SR_V8_1A ("cnthv_tval_el2", CPENC (3,4,C14,C3,0), 0),
4969
  SR_V8_1A ("cnthv_ctl_el2",  CPENC (3,4,C14,C3,1), 0),
4970
  SR_V8_1A ("cnthv_cval_el2", CPENC (3,4,C14,C3,2), 0),
4971
  SR_CORE ("dacr32_el2",  CPENC (3,4,C3,C0,0),  0),
4972
  SR_CORE ("ifsr32_el2",  CPENC (3,4,C5,C0,1),  0),
4973
  SR_CORE ("teehbr32_el1",  CPENC (2,2,C1,C0,0),  0),
4974
  SR_CORE ("sder32_el3",  CPENC (3,6,C1,C1,1),  0),
4975
  SR_CORE ("mdscr_el1",   CPENC (2,0,C0,C2,2),  0),
4976
  SR_CORE ("mdccsr_el0",  CPENC (2,3,C0,C1,0),  F_REG_READ),
4977
  SR_CORE ("mdccint_el1",       CPENC (2,0,C0,C2,0),  0),
4978
  SR_CORE ("dbgdtr_el0",  CPENC (2,3,C0,C4,0),  0),
4979
  SR_CORE ("dbgdtrrx_el0",  CPENC (2,3,C0,C5,0),  F_REG_READ),
4980
  SR_CORE ("dbgdtrtx_el0",  CPENC (2,3,C0,C5,0),  F_REG_WRITE),
4981
  SR_CORE ("osdtrrx_el1", CPENC (2,0,C0,C0,2),  0),
4982
  SR_CORE ("osdtrtx_el1", CPENC (2,0,C0,C3,2),  0),
4983
  SR_CORE ("oseccr_el1",  CPENC (2,0,C0,C6,2),  0),
4984
  SR_CORE ("dbgvcr32_el2",      CPENC (2,4,C0,C7,0),  0),
4985
  SR_CORE ("dbgbvr0_el1",       CPENC (2,0,C0,C0,4),  0),
4986
  SR_CORE ("dbgbvr1_el1",       CPENC (2,0,C0,C1,4),  0),
4987
  SR_CORE ("dbgbvr2_el1",       CPENC (2,0,C0,C2,4),  0),
4988
  SR_CORE ("dbgbvr3_el1",       CPENC (2,0,C0,C3,4),  0),
4989
  SR_CORE ("dbgbvr4_el1",       CPENC (2,0,C0,C4,4),  0),
4990
  SR_CORE ("dbgbvr5_el1",       CPENC (2,0,C0,C5,4),  0),
4991
  SR_CORE ("dbgbvr6_el1",       CPENC (2,0,C0,C6,4),  0),
4992
  SR_CORE ("dbgbvr7_el1",       CPENC (2,0,C0,C7,4),  0),
4993
  SR_CORE ("dbgbvr8_el1",       CPENC (2,0,C0,C8,4),  0),
4994
  SR_CORE ("dbgbvr9_el1",       CPENC (2,0,C0,C9,4),  0),
4995
  SR_CORE ("dbgbvr10_el1",      CPENC (2,0,C0,C10,4), 0),
4996
  SR_CORE ("dbgbvr11_el1",      CPENC (2,0,C0,C11,4), 0),
4997
  SR_CORE ("dbgbvr12_el1",      CPENC (2,0,C0,C12,4), 0),
4998
  SR_CORE ("dbgbvr13_el1",      CPENC (2,0,C0,C13,4), 0),
4999
  SR_CORE ("dbgbvr14_el1",      CPENC (2,0,C0,C14,4), 0),
5000
  SR_CORE ("dbgbvr15_el1",      CPENC (2,0,C0,C15,4), 0),
5001
  SR_CORE ("dbgbcr0_el1",       CPENC (2,0,C0,C0,5),  0),
5002
  SR_CORE ("dbgbcr1_el1",       CPENC (2,0,C0,C1,5),  0),
5003
  SR_CORE ("dbgbcr2_el1",       CPENC (2,0,C0,C2,5),  0),
5004
  SR_CORE ("dbgbcr3_el1",       CPENC (2,0,C0,C3,5),  0),
5005
  SR_CORE ("dbgbcr4_el1",       CPENC (2,0,C0,C4,5),  0),
5006
  SR_CORE ("dbgbcr5_el1",       CPENC (2,0,C0,C5,5),  0),
5007
  SR_CORE ("dbgbcr6_el1",       CPENC (2,0,C0,C6,5),  0),
5008
  SR_CORE ("dbgbcr7_el1",       CPENC (2,0,C0,C7,5),  0),
5009
  SR_CORE ("dbgbcr8_el1",       CPENC (2,0,C0,C8,5),  0),
5010
  SR_CORE ("dbgbcr9_el1",       CPENC (2,0,C0,C9,5),  0),
5011
  SR_CORE ("dbgbcr10_el1",      CPENC (2,0,C0,C10,5), 0),
5012
  SR_CORE ("dbgbcr11_el1",      CPENC (2,0,C0,C11,5), 0),
5013
  SR_CORE ("dbgbcr12_el1",      CPENC (2,0,C0,C12,5), 0),
5014
  SR_CORE ("dbgbcr13_el1",      CPENC (2,0,C0,C13,5), 0),
5015
  SR_CORE ("dbgbcr14_el1",      CPENC (2,0,C0,C14,5), 0),
5016
  SR_CORE ("dbgbcr15_el1",      CPENC (2,0,C0,C15,5), 0),
5017
  SR_CORE ("dbgwvr0_el1",       CPENC (2,0,C0,C0,6),  0),
5018
  SR_CORE ("dbgwvr1_el1",       CPENC (2,0,C0,C1,6),  0),
5019
  SR_CORE ("dbgwvr2_el1",       CPENC (2,0,C0,C2,6),  0),
5020
  SR_CORE ("dbgwvr3_el1",       CPENC (2,0,C0,C3,6),  0),
5021
  SR_CORE ("dbgwvr4_el1",       CPENC (2,0,C0,C4,6),  0),
5022
  SR_CORE ("dbgwvr5_el1",       CPENC (2,0,C0,C5,6),  0),
5023
  SR_CORE ("dbgwvr6_el1",       CPENC (2,0,C0,C6,6),  0),
5024
  SR_CORE ("dbgwvr7_el1",       CPENC (2,0,C0,C7,6),  0),
5025
  SR_CORE ("dbgwvr8_el1",       CPENC (2,0,C0,C8,6),  0),
5026
  SR_CORE ("dbgwvr9_el1",       CPENC (2,0,C0,C9,6),  0),
5027
  SR_CORE ("dbgwvr10_el1",      CPENC (2,0,C0,C10,6), 0),
5028
  SR_CORE ("dbgwvr11_el1",      CPENC (2,0,C0,C11,6), 0),
5029
  SR_CORE ("dbgwvr12_el1",      CPENC (2,0,C0,C12,6), 0),
5030
  SR_CORE ("dbgwvr13_el1",      CPENC (2,0,C0,C13,6), 0),
5031
  SR_CORE ("dbgwvr14_el1",      CPENC (2,0,C0,C14,6), 0),
5032
  SR_CORE ("dbgwvr15_el1",      CPENC (2,0,C0,C15,6), 0),
5033
  SR_CORE ("dbgwcr0_el1",       CPENC (2,0,C0,C0,7),  0),
5034
  SR_CORE ("dbgwcr1_el1",       CPENC (2,0,C0,C1,7),  0),
5035
  SR_CORE ("dbgwcr2_el1",       CPENC (2,0,C0,C2,7),  0),
5036
  SR_CORE ("dbgwcr3_el1",       CPENC (2,0,C0,C3,7),  0),
5037
  SR_CORE ("dbgwcr4_el1",       CPENC (2,0,C0,C4,7),  0),
5038
  SR_CORE ("dbgwcr5_el1",       CPENC (2,0,C0,C5,7),  0),
5039
  SR_CORE ("dbgwcr6_el1",       CPENC (2,0,C0,C6,7),  0),
5040
  SR_CORE ("dbgwcr7_el1",       CPENC (2,0,C0,C7,7),  0),
5041
  SR_CORE ("dbgwcr8_el1",       CPENC (2,0,C0,C8,7),  0),
5042
  SR_CORE ("dbgwcr9_el1",       CPENC (2,0,C0,C9,7),  0),
5043
  SR_CORE ("dbgwcr10_el1",      CPENC (2,0,C0,C10,7), 0),
5044
  SR_CORE ("dbgwcr11_el1",      CPENC (2,0,C0,C11,7), 0),
5045
  SR_CORE ("dbgwcr12_el1",      CPENC (2,0,C0,C12,7), 0),
5046
  SR_CORE ("dbgwcr13_el1",      CPENC (2,0,C0,C13,7), 0),
5047
  SR_CORE ("dbgwcr14_el1",      CPENC (2,0,C0,C14,7), 0),
5048
  SR_CORE ("dbgwcr15_el1",      CPENC (2,0,C0,C15,7), 0),
5049
  SR_CORE ("mdrar_el1",   CPENC (2,0,C1,C0,0),  F_REG_READ),
5050
  SR_CORE ("oslar_el1",   CPENC (2,0,C1,C0,4),  F_REG_WRITE),
5051
  SR_CORE ("oslsr_el1",   CPENC (2,0,C1,C1,4),  F_REG_READ),
5052
  SR_CORE ("osdlr_el1",   CPENC (2,0,C1,C3,4),  0),
5053
  SR_CORE ("dbgprcr_el1",       CPENC (2,0,C1,C4,4),  0),
5054
  SR_CORE ("dbgclaimset_el1",   CPENC (2,0,C7,C8,6),  0),
5055
  SR_CORE ("dbgclaimclr_el1",   CPENC (2,0,C7,C9,6),  0),
5056
  SR_CORE ("dbgauthstatus_el1", CPENC (2,0,C7,C14,6), F_REG_READ),
5057
  SR_PROFILE ("pmblimitr_el1",  CPENC (3,0,C9,C10,0), 0),
5058
  SR_PROFILE ("pmbptr_el1", CPENC (3,0,C9,C10,1), 0),
5059
  SR_PROFILE ("pmbsr_el1",  CPENC (3,0,C9,C10,3), 0),
5060
  SR_PROFILE ("pmbidr_el1", CPENC (3,0,C9,C10,7), F_REG_READ),
5061
  SR_PROFILE ("pmscr_el1",  CPENC (3,0,C9,C9,0),  0),
5062
  SR_PROFILE ("pmsicr_el1", CPENC (3,0,C9,C9,2),  0),
5063
  SR_PROFILE ("pmsirr_el1", CPENC (3,0,C9,C9,3),  0),
5064
  SR_PROFILE ("pmsfcr_el1", CPENC (3,0,C9,C9,4),  0),
5065
  SR_PROFILE ("pmsevfr_el1",  CPENC (3,0,C9,C9,5),  0),
5066
  SR_PROFILE ("pmslatfr_el1", CPENC (3,0,C9,C9,6),  0),
5067
  SR_PROFILE ("pmsidr_el1", CPENC (3,0,C9,C9,7),  F_REG_READ),
5068
  SR_PROFILE ("pmscr_el2",  CPENC (3,4,C9,C9,0),  0),
5069
  SR_PROFILE ("pmscr_el12", CPENC (3,5,C9,C9,0),  0),
5070
  SR_CORE ("pmcr_el0",    CPENC (3,3,C9,C12,0), 0),
5071
  SR_CORE ("pmcntenset_el0",    CPENC (3,3,C9,C12,1), 0),
5072
  SR_CORE ("pmcntenclr_el0",    CPENC (3,3,C9,C12,2), 0),
5073
  SR_CORE ("pmovsclr_el0",      CPENC (3,3,C9,C12,3), 0),
5074
  SR_CORE ("pmswinc_el0",       CPENC (3,3,C9,C12,4), F_REG_WRITE),
5075
  SR_CORE ("pmselr_el0",  CPENC (3,3,C9,C12,5), 0),
5076
  SR_CORE ("pmceid0_el0",       CPENC (3,3,C9,C12,6), F_REG_READ),
5077
  SR_CORE ("pmceid1_el0",       CPENC (3,3,C9,C12,7), F_REG_READ),
5078
  SR_CORE ("pmccntr_el0",       CPENC (3,3,C9,C13,0), 0),
5079
  SR_CORE ("pmxevtyper_el0",    CPENC (3,3,C9,C13,1), 0),
5080
  SR_CORE ("pmxevcntr_el0",     CPENC (3,3,C9,C13,2), 0),
5081
  SR_CORE ("pmuserenr_el0",     CPENC (3,3,C9,C14,0), 0),
5082
  SR_CORE ("pmintenset_el1",    CPENC (3,0,C9,C14,1), 0),
5083
  SR_CORE ("pmintenclr_el1",    CPENC (3,0,C9,C14,2), 0),
5084
  SR_CORE ("pmovsset_el0",      CPENC (3,3,C9,C14,3), 0),
5085
  SR_CORE ("pmevcntr0_el0",     CPENC (3,3,C14,C8,0), 0),
5086
  SR_CORE ("pmevcntr1_el0",     CPENC (3,3,C14,C8,1), 0),
5087
  SR_CORE ("pmevcntr2_el0",     CPENC (3,3,C14,C8,2), 0),
5088
  SR_CORE ("pmevcntr3_el0",     CPENC (3,3,C14,C8,3), 0),
5089
  SR_CORE ("pmevcntr4_el0",     CPENC (3,3,C14,C8,4), 0),
5090
  SR_CORE ("pmevcntr5_el0",     CPENC (3,3,C14,C8,5), 0),
5091
  SR_CORE ("pmevcntr6_el0",     CPENC (3,3,C14,C8,6), 0),
5092
  SR_CORE ("pmevcntr7_el0",     CPENC (3,3,C14,C8,7), 0),
5093
  SR_CORE ("pmevcntr8_el0",     CPENC (3,3,C14,C9,0), 0),
5094
  SR_CORE ("pmevcntr9_el0",     CPENC (3,3,C14,C9,1), 0),
5095
  SR_CORE ("pmevcntr10_el0",    CPENC (3,3,C14,C9,2), 0),
5096
  SR_CORE ("pmevcntr11_el0",    CPENC (3,3,C14,C9,3), 0),
5097
  SR_CORE ("pmevcntr12_el0",    CPENC (3,3,C14,C9,4), 0),
5098
  SR_CORE ("pmevcntr13_el0",    CPENC (3,3,C14,C9,5), 0),
5099
  SR_CORE ("pmevcntr14_el0",    CPENC (3,3,C14,C9,6), 0),
5100
  SR_CORE ("pmevcntr15_el0",    CPENC (3,3,C14,C9,7), 0),
5101
  SR_CORE ("pmevcntr16_el0",    CPENC (3,3,C14,C10,0),  0),
5102
  SR_CORE ("pmevcntr17_el0",    CPENC (3,3,C14,C10,1),  0),
5103
  SR_CORE ("pmevcntr18_el0",    CPENC (3,3,C14,C10,2),  0),
5104
  SR_CORE ("pmevcntr19_el0",    CPENC (3,3,C14,C10,3),  0),
5105
  SR_CORE ("pmevcntr20_el0",    CPENC (3,3,C14,C10,4),  0),
5106
  SR_CORE ("pmevcntr21_el0",    CPENC (3,3,C14,C10,5),  0),
5107
  SR_CORE ("pmevcntr22_el0",    CPENC (3,3,C14,C10,6),  0),
5108
  SR_CORE ("pmevcntr23_el0",    CPENC (3,3,C14,C10,7),  0),
5109
  SR_CORE ("pmevcntr24_el0",    CPENC (3,3,C14,C11,0),  0),
5110
  SR_CORE ("pmevcntr25_el0",    CPENC (3,3,C14,C11,1),  0),
5111
  SR_CORE ("pmevcntr26_el0",    CPENC (3,3,C14,C11,2),  0),
5112
  SR_CORE ("pmevcntr27_el0",    CPENC (3,3,C14,C11,3),  0),
5113
  SR_CORE ("pmevcntr28_el0",    CPENC (3,3,C14,C11,4),  0),
5114
  SR_CORE ("pmevcntr29_el0",    CPENC (3,3,C14,C11,5),  0),
5115
  SR_CORE ("pmevcntr30_el0",    CPENC (3,3,C14,C11,6),  0),
5116
  SR_CORE ("pmevtyper0_el0",    CPENC (3,3,C14,C12,0),  0),
5117
  SR_CORE ("pmevtyper1_el0",    CPENC (3,3,C14,C12,1),  0),
5118
  SR_CORE ("pmevtyper2_el0",    CPENC (3,3,C14,C12,2),  0),
5119
  SR_CORE ("pmevtyper3_el0",    CPENC (3,3,C14,C12,3),  0),
5120
  SR_CORE ("pmevtyper4_el0",    CPENC (3,3,C14,C12,4),  0),
5121
  SR_CORE ("pmevtyper5_el0",    CPENC (3,3,C14,C12,5),  0),
5122
  SR_CORE ("pmevtyper6_el0",    CPENC (3,3,C14,C12,6),  0),
5123
  SR_CORE ("pmevtyper7_el0",    CPENC (3,3,C14,C12,7),  0),
5124
  SR_CORE ("pmevtyper8_el0",    CPENC (3,3,C14,C13,0),  0),
5125
  SR_CORE ("pmevtyper9_el0",    CPENC (3,3,C14,C13,1),  0),
5126
  SR_CORE ("pmevtyper10_el0",   CPENC (3,3,C14,C13,2),  0),
5127
  SR_CORE ("pmevtyper11_el0",   CPENC (3,3,C14,C13,3),  0),
5128
  SR_CORE ("pmevtyper12_el0",   CPENC (3,3,C14,C13,4),  0),
5129
  SR_CORE ("pmevtyper13_el0",   CPENC (3,3,C14,C13,5),  0),
5130
  SR_CORE ("pmevtyper14_el0",   CPENC (3,3,C14,C13,6),  0),
5131
  SR_CORE ("pmevtyper15_el0",   CPENC (3,3,C14,C13,7),  0),
5132
  SR_CORE ("pmevtyper16_el0",   CPENC (3,3,C14,C14,0),  0),
5133
  SR_CORE ("pmevtyper17_el0",   CPENC (3,3,C14,C14,1),  0),
5134
  SR_CORE ("pmevtyper18_el0",   CPENC (3,3,C14,C14,2),  0),
5135
  SR_CORE ("pmevtyper19_el0",   CPENC (3,3,C14,C14,3),  0),
5136
  SR_CORE ("pmevtyper20_el0",   CPENC (3,3,C14,C14,4),  0),
5137
  SR_CORE ("pmevtyper21_el0",   CPENC (3,3,C14,C14,5),  0),
5138
  SR_CORE ("pmevtyper22_el0",   CPENC (3,3,C14,C14,6),  0),
5139
  SR_CORE ("pmevtyper23_el0",   CPENC (3,3,C14,C14,7),  0),
5140
  SR_CORE ("pmevtyper24_el0",   CPENC (3,3,C14,C15,0),  0),
5141
  SR_CORE ("pmevtyper25_el0",   CPENC (3,3,C14,C15,1),  0),
5142
  SR_CORE ("pmevtyper26_el0",   CPENC (3,3,C14,C15,2),  0),
5143
  SR_CORE ("pmevtyper27_el0",   CPENC (3,3,C14,C15,3),  0),
5144
  SR_CORE ("pmevtyper28_el0",   CPENC (3,3,C14,C15,4),  0),
5145
  SR_CORE ("pmevtyper29_el0",   CPENC (3,3,C14,C15,5),  0),
5146
  SR_CORE ("pmevtyper30_el0",   CPENC (3,3,C14,C15,6),  0),
5147
  SR_CORE ("pmccfiltr_el0",     CPENC (3,3,C14,C15,7),  0),
5148
5149
  SR_V8_4A ("dit",    CPEN_ (3,C2,5),   0),
5150
  SR_V8_4A ("trfcr_el1",    CPENC (3,0,C1,C2,1),  0),
5151
  SR_V8_4A ("pmmir_el1",    CPENC (3,0,C9,C14,6), F_REG_READ),
5152
  SR_V8_4A ("trfcr_el2",    CPENC (3,4,C1,C2,1),  0),
5153
  SR_V8_4A ("vstcr_el2",    CPENC (3,4,C2,C6,2),  0),
5154
  SR_V8_4_A ("vsttbr_el2",  CPENC (3,4,C2,C6,0),  0),
5155
  SR_V8_4A ("cnthvs_tval_el2",  CPENC (3,4,C14,C4,0), 0),
5156
  SR_V8_4A ("cnthvs_cval_el2",  CPENC (3,4,C14,C4,2), 0),
5157
  SR_V8_4A ("cnthvs_ctl_el2", CPENC (3,4,C14,C4,1), 0),
5158
  SR_V8_4A ("cnthps_tval_el2",  CPENC (3,4,C14,C5,0), 0),
5159
  SR_V8_4A ("cnthps_cval_el2",  CPENC (3,4,C14,C5,2), 0),
5160
  SR_V8_4A ("cnthps_ctl_el2", CPENC (3,4,C14,C5,1), 0),
5161
  SR_V8_4A ("sder32_el2", CPENC (3,4,C1,C3,1),  0),
5162
  SR_V8_4A ("vncr_el2",   CPENC (3,4,C2,C2,0),  0),
5163
  SR_V8_4A ("trfcr_el12", CPENC (3,5,C1,C2,1),  0),
5164
5165
  SR_CORE ("mpam0_el1",   CPENC (3,0,C10,C5,1), 0),
5166
  SR_CORE ("mpam1_el1",   CPENC (3,0,C10,C5,0), 0),
5167
  SR_CORE ("mpam1_el12",  CPENC (3,5,C10,C5,0), 0),
5168
  SR_CORE ("mpam2_el2",   CPENC (3,4,C10,C5,0), 0),
5169
  SR_CORE ("mpam3_el3",   CPENC (3,6,C10,C5,0), 0),
5170
  SR_CORE ("mpamhcr_el2", CPENC (3,4,C10,C4,0), 0),
5171
  SR_CORE ("mpamidr_el1", CPENC (3,0,C10,C4,4), F_REG_READ),
5172
  SR_CORE ("mpamvpm0_el2",  CPENC (3,4,C10,C6,0), 0),
5173
  SR_CORE ("mpamvpm1_el2",  CPENC (3,4,C10,C6,1), 0),
5174
  SR_CORE ("mpamvpm2_el2",  CPENC (3,4,C10,C6,2), 0),
5175
  SR_CORE ("mpamvpm3_el2",  CPENC (3,4,C10,C6,3), 0),
5176
  SR_CORE ("mpamvpm4_el2",  CPENC (3,4,C10,C6,4), 0),
5177
  SR_CORE ("mpamvpm5_el2",  CPENC (3,4,C10,C6,5), 0),
5178
  SR_CORE ("mpamvpm6_el2",  CPENC (3,4,C10,C6,6), 0),
5179
  SR_CORE ("mpamvpm7_el2",  CPENC (3,4,C10,C6,7), 0),
5180
  SR_CORE ("mpamvpmv_el2",  CPENC (3,4,C10,C4,1), 0),
5181
5182
  SR_V8R ("mpuir_el1",    CPENC (3,0,C0,C0,4),  F_REG_READ),
5183
  SR_V8R ("mpuir_el2",    CPENC (3,4,C0,C0,4),  F_REG_READ),
5184
  SR_V8R ("prbar_el1",    CPENC (3,0,C6,C8,0),  0),
5185
  SR_V8R ("prbar_el2",    CPENC (3,4,C6,C8,0),  0),
5186
5187
#define ENC_BARLAR(x,n,lar) \
5188
  CPENC (3, (x-1) << 2, C6, 8 | (n >> 1), ((n & 1) << 2) | lar)
5189
5190
#define PRBARn_ELx(x,n) SR_V8R ("prbar" #n "_el" #x, ENC_BARLAR (x,n,0), 0)
5191
#define PRLARn_ELx(x,n) SR_V8R ("prlar" #n "_el" #x, ENC_BARLAR (x,n,1), 0)
5192
5193
  SR_EXPAND_EL12 (PRBARn_ELx)
5194
  SR_V8R ("prenr_el1",    CPENC (3,0,C6,C1,1),  0),
5195
  SR_V8R ("prenr_el2",    CPENC (3,4,C6,C1,1),  0),
5196
  SR_V8R ("prlar_el1",    CPENC (3,0,C6,C8,1),  0),
5197
  SR_V8R ("prlar_el2",    CPENC (3,4,C6,C8,1),  0),
5198
  SR_EXPAND_EL12 (PRLARn_ELx)
5199
  SR_V8R ("prselr_el1", CPENC (3,0,C6,C2,1),  0),
5200
  SR_V8R ("prselr_el2", CPENC (3,4,C6,C2,1),  0),
5201
  SR_V8R ("vsctlr_el2", CPENC (3,4,C2,C0,0),  0),
5202
5203
  SR_CORE("trbbaser_el1",   CPENC (3,0,C9,C11,2), 0),
5204
  SR_CORE("trbidr_el1",   CPENC (3,0,C9,C11,7), F_REG_READ),
5205
  SR_CORE("trblimitr_el1",  CPENC (3,0,C9,C11,0), 0),
5206
  SR_CORE("trbmar_el1",   CPENC (3,0,C9,C11,4), 0),
5207
  SR_CORE("trbptr_el1",   CPENC (3,0,C9,C11,1), 0),
5208
  SR_CORE("trbsr_el1",    CPENC (3,0,C9,C11,3), 0),
5209
  SR_CORE("trbtrg_el1",   CPENC (3,0,C9,C11,6), 0),
5210
5211
  SR_CORE ("trcauthstatus", CPENC (2,1,C7,C14,6), F_REG_READ),
5212
  SR_CORE ("trccidr0",      CPENC (2,1,C7,C12,7), F_REG_READ),
5213
  SR_CORE ("trccidr1",      CPENC (2,1,C7,C13,7), F_REG_READ),
5214
  SR_CORE ("trccidr2",      CPENC (2,1,C7,C14,7), F_REG_READ),
5215
  SR_CORE ("trccidr3",      CPENC (2,1,C7,C15,7), F_REG_READ),
5216
  SR_CORE ("trcdevaff0",    CPENC (2,1,C7,C10,6), F_REG_READ),
5217
  SR_CORE ("trcdevaff1",    CPENC (2,1,C7,C11,6), F_REG_READ),
5218
  SR_CORE ("trcdevarch",    CPENC (2,1,C7,C15,6), F_REG_READ),
5219
  SR_CORE ("trcdevid",      CPENC (2,1,C7,C2,7),  F_REG_READ),
5220
  SR_CORE ("trcdevtype",    CPENC (2,1,C7,C3,7),  F_REG_READ),
5221
  SR_CORE ("trcidr0",       CPENC (2,1,C0,C8,7),  F_REG_READ),
5222
  SR_CORE ("trcidr1",       CPENC (2,1,C0,C9,7),  F_REG_READ),
5223
  SR_CORE ("trcidr2",       CPENC (2,1,C0,C10,7), F_REG_READ),
5224
  SR_CORE ("trcidr3",       CPENC (2,1,C0,C11,7), F_REG_READ),
5225
  SR_CORE ("trcidr4",       CPENC (2,1,C0,C12,7), F_REG_READ),
5226
  SR_CORE ("trcidr5",       CPENC (2,1,C0,C13,7), F_REG_READ),
5227
  SR_CORE ("trcidr6",       CPENC (2,1,C0,C14,7), F_REG_READ),
5228
  SR_CORE ("trcidr7",       CPENC (2,1,C0,C15,7), F_REG_READ),
5229
  SR_CORE ("trcidr8",       CPENC (2,1,C0,C0,6),  F_REG_READ),
5230
  SR_CORE ("trcidr9",       CPENC (2,1,C0,C1,6),  F_REG_READ),
5231
  SR_CORE ("trcidr10",      CPENC (2,1,C0,C2,6),  F_REG_READ),
5232
  SR_CORE ("trcidr11",      CPENC (2,1,C0,C3,6),  F_REG_READ),
5233
  SR_CORE ("trcidr12",      CPENC (2,1,C0,C4,6),  F_REG_READ),
5234
  SR_CORE ("trcidr13",      CPENC (2,1,C0,C5,6),  F_REG_READ),
5235
  SR_CORE ("trclsr",        CPENC (2,1,C7,C13,6), F_REG_READ),
5236
  SR_CORE ("trcoslsr",      CPENC (2,1,C1,C1,4),  F_REG_READ),
5237
  SR_CORE ("trcpdsr",       CPENC (2,1,C1,C5,4),  F_REG_READ),
5238
  SR_CORE ("trcpidr0",      CPENC (2,1,C7,C8,7),  F_REG_READ),
5239
  SR_CORE ("trcpidr1",      CPENC (2,1,C7,C9,7),  F_REG_READ),
5240
  SR_CORE ("trcpidr2",      CPENC (2,1,C7,C10,7), F_REG_READ),
5241
  SR_CORE ("trcpidr3",      CPENC (2,1,C7,C11,7), F_REG_READ),
5242
  SR_CORE ("trcpidr4",      CPENC (2,1,C7,C4,7),  F_REG_READ),
5243
  SR_CORE ("trcpidr5",      CPENC (2,1,C7,C5,7),  F_REG_READ),
5244
  SR_CORE ("trcpidr6",      CPENC (2,1,C7,C6,7),  F_REG_READ),
5245
  SR_CORE ("trcpidr7",      CPENC (2,1,C7,C7,7),  F_REG_READ),
5246
  SR_CORE ("trcstatr",      CPENC (2,1,C0,C3,0),  F_REG_READ),
5247
  SR_CORE ("trcacatr0",     CPENC (2,1,C2,C0,2),  0),
5248
  SR_CORE ("trcacatr1",     CPENC (2,1,C2,C2,2),  0),
5249
  SR_CORE ("trcacatr2",     CPENC (2,1,C2,C4,2),  0),
5250
  SR_CORE ("trcacatr3",     CPENC (2,1,C2,C6,2),  0),
5251
  SR_CORE ("trcacatr4",     CPENC (2,1,C2,C8,2),  0),
5252
  SR_CORE ("trcacatr5",     CPENC (2,1,C2,C10,2), 0),
5253
  SR_CORE ("trcacatr6",     CPENC (2,1,C2,C12,2), 0),
5254
  SR_CORE ("trcacatr7",     CPENC (2,1,C2,C14,2), 0),
5255
  SR_CORE ("trcacatr8",     CPENC (2,1,C2,C0,3),  0),
5256
  SR_CORE ("trcacatr9",     CPENC (2,1,C2,C2,3),  0),
5257
  SR_CORE ("trcacatr10",    CPENC (2,1,C2,C4,3),  0),
5258
  SR_CORE ("trcacatr11",    CPENC (2,1,C2,C6,3),  0),
5259
  SR_CORE ("trcacatr12",    CPENC (2,1,C2,C8,3),  0),
5260
  SR_CORE ("trcacatr13",    CPENC (2,1,C2,C10,3), 0),
5261
  SR_CORE ("trcacatr14",    CPENC (2,1,C2,C12,3), 0),
5262
  SR_CORE ("trcacatr15",    CPENC (2,1,C2,C14,3), 0),
5263
  SR_CORE ("trcacvr0",      CPENC (2,1,C2,C0,0),  0),
5264
  SR_CORE ("trcacvr1",      CPENC (2,1,C2,C2,0),  0),
5265
  SR_CORE ("trcacvr2",      CPENC (2,1,C2,C4,0),  0),
5266
  SR_CORE ("trcacvr3",      CPENC (2,1,C2,C6,0),  0),
5267
  SR_CORE ("trcacvr4",      CPENC (2,1,C2,C8,0),  0),
5268
  SR_CORE ("trcacvr5",      CPENC (2,1,C2,C10,0), 0),
5269
  SR_CORE ("trcacvr6",      CPENC (2,1,C2,C12,0), 0),
5270
  SR_CORE ("trcacvr7",      CPENC (2,1,C2,C14,0), 0),
5271
  SR_CORE ("trcacvr8",      CPENC (2,1,C2,C0,1),  0),
5272
  SR_CORE ("trcacvr9",      CPENC (2,1,C2,C2,1),  0),
5273
  SR_CORE ("trcacvr10",     CPENC (2,1,C2,C4,1),  0),
5274
  SR_CORE ("trcacvr11",     CPENC (2,1,C2,C6,1),  0),
5275
  SR_CORE ("trcacvr12",     CPENC (2,1,C2,C8,1),  0),
5276
  SR_CORE ("trcacvr13",     CPENC (2,1,C2,C10,1), 0),
5277
  SR_CORE ("trcacvr14",     CPENC (2,1,C2,C12,1), 0),
5278
  SR_CORE ("trcacvr15",     CPENC (2,1,C2,C14,1), 0),
5279
  SR_CORE ("trcauxctlr",    CPENC (2,1,C0,C6,0),  0),
5280
  SR_CORE ("trcbbctlr",     CPENC (2,1,C0,C15,0), 0),
5281
  SR_CORE ("trcccctlr",     CPENC (2,1,C0,C14,0), 0),
5282
  SR_CORE ("trccidcctlr0",  CPENC (2,1,C3,C0,2),  0),
5283
  SR_CORE ("trccidcctlr1",  CPENC (2,1,C3,C1,2),  0),
5284
  SR_CORE ("trccidcvr0",    CPENC (2,1,C3,C0,0),  0),
5285
  SR_CORE ("trccidcvr1",    CPENC (2,1,C3,C2,0),  0),
5286
  SR_CORE ("trccidcvr2",    CPENC (2,1,C3,C4,0),  0),
5287
  SR_CORE ("trccidcvr3",    CPENC (2,1,C3,C6,0),  0),
5288
  SR_CORE ("trccidcvr4",    CPENC (2,1,C3,C8,0),  0),
5289
  SR_CORE ("trccidcvr5",    CPENC (2,1,C3,C10,0), 0),
5290
  SR_CORE ("trccidcvr6",    CPENC (2,1,C3,C12,0), 0),
5291
  SR_CORE ("trccidcvr7",    CPENC (2,1,C3,C14,0), 0),
5292
  SR_CORE ("trcclaimclr",   CPENC (2,1,C7,C9,6),  0),
5293
  SR_CORE ("trcclaimset",   CPENC (2,1,C7,C8,6),  0),
5294
  SR_CORE ("trccntctlr0",   CPENC (2,1,C0,C4,5),  0),
5295
  SR_CORE ("trccntctlr1",   CPENC (2,1,C0,C5,5),  0),
5296
  SR_CORE ("trccntctlr2",   CPENC (2,1,C0,C6,5),  0),
5297
  SR_CORE ("trccntctlr3",   CPENC (2,1,C0,C7,5),  0),
5298
  SR_CORE ("trccntrldvr0",  CPENC (2,1,C0,C0,5),  0),
5299
  SR_CORE ("trccntrldvr1",  CPENC (2,1,C0,C1,5),  0),
5300
  SR_CORE ("trccntrldvr2",  CPENC (2,1,C0,C2,5),  0),
5301
  SR_CORE ("trccntrldvr3",  CPENC (2,1,C0,C3,5),  0),
5302
  SR_CORE ("trccntvr0",     CPENC (2,1,C0,C8,5),  0),
5303
  SR_CORE ("trccntvr1",     CPENC (2,1,C0,C9,5),  0),
5304
  SR_CORE ("trccntvr2",     CPENC (2,1,C0,C10,5), 0),
5305
  SR_CORE ("trccntvr3",     CPENC (2,1,C0,C11,5), 0),
5306
  SR_CORE ("trcconfigr",    CPENC (2,1,C0,C4,0),  0),
5307
  SR_CORE ("trcdvcmr0",     CPENC (2,1,C2,C0,6),  0),
5308
  SR_CORE ("trcdvcmr1",     CPENC (2,1,C2,C4,6),  0),
5309
  SR_CORE ("trcdvcmr2",     CPENC (2,1,C2,C8,6),  0),
5310
  SR_CORE ("trcdvcmr3",     CPENC (2,1,C2,C12,6), 0),
5311
  SR_CORE ("trcdvcmr4",     CPENC (2,1,C2,C0,7),  0),
5312
  SR_CORE ("trcdvcmr5",     CPENC (2,1,C2,C4,7),  0),
5313
  SR_CORE ("trcdvcmr6",     CPENC (2,1,C2,C8,7),  0),
5314
  SR_CORE ("trcdvcmr7",     CPENC (2,1,C2,C12,7), 0),
5315
  SR_CORE ("trcdvcvr0",     CPENC (2,1,C2,C0,4),  0),
5316
  SR_CORE ("trcdvcvr1",     CPENC (2,1,C2,C4,4),  0),
5317
  SR_CORE ("trcdvcvr2",     CPENC (2,1,C2,C8,4),  0),
5318
  SR_CORE ("trcdvcvr3",     CPENC (2,1,C2,C12,4), 0),
5319
  SR_CORE ("trcdvcvr4",     CPENC (2,1,C2,C0,5),  0),
5320
  SR_CORE ("trcdvcvr5",     CPENC (2,1,C2,C4,5),  0),
5321
  SR_CORE ("trcdvcvr6",     CPENC (2,1,C2,C8,5),  0),
5322
  SR_CORE ("trcdvcvr7",     CPENC (2,1,C2,C12,5), 0),
5323
  SR_CORE ("trceventctl0r", CPENC (2,1,C0,C8,0),  0),
5324
  SR_CORE ("trceventctl1r", CPENC (2,1,C0,C9,0),  0),
5325
  SR_CORE ("trcextinselr0", CPENC (2,1,C0,C8,4),  0),
5326
  SR_CORE ("trcextinselr",  CPENC (2,1,C0,C8,4),  0),
5327
  SR_CORE ("trcextinselr1", CPENC (2,1,C0,C9,4),  0),
5328
  SR_CORE ("trcextinselr2", CPENC (2,1,C0,C10,4), 0),
5329
  SR_CORE ("trcextinselr3", CPENC (2,1,C0,C11,4), 0),
5330
  SR_CORE ("trcimspec0",    CPENC (2,1,C0,C0,7),  0),
5331
  SR_CORE ("trcimspec1",    CPENC (2,1,C0,C1,7),  0),
5332
  SR_CORE ("trcimspec2",    CPENC (2,1,C0,C2,7),  0),
5333
  SR_CORE ("trcimspec3",    CPENC (2,1,C0,C3,7),  0),
5334
  SR_CORE ("trcimspec4",    CPENC (2,1,C0,C4,7),  0),
5335
  SR_CORE ("trcimspec5",    CPENC (2,1,C0,C5,7),  0),
5336
  SR_CORE ("trcimspec6",    CPENC (2,1,C0,C6,7),  0),
5337
  SR_CORE ("trcimspec7",    CPENC (2,1,C0,C7,7),  0),
5338
  SR_CORE ("trcitctrl",     CPENC (2,1,C7,C0,4),  0),
5339
  SR_CORE ("trcpdcr",       CPENC (2,1,C1,C4,4),  0),
5340
  SR_CORE ("trcprgctlr",    CPENC (2,1,C0,C1,0),  0),
5341
  SR_CORE ("trcprocselr",   CPENC (2,1,C0,C2,0),  0),
5342
  SR_CORE ("trcqctlr",      CPENC (2,1,C0,C1,1),  0),
5343
  SR_CORE ("trcrsr",        CPENC (2,1,C0,C10,0), 0),
5344
  SR_CORE ("trcrsctlr2",    CPENC (2,1,C1,C2,0),  0),
5345
  SR_CORE ("trcrsctlr3",    CPENC (2,1,C1,C3,0),  0),
5346
  SR_CORE ("trcrsctlr4",    CPENC (2,1,C1,C4,0),  0),
5347
  SR_CORE ("trcrsctlr5",    CPENC (2,1,C1,C5,0),  0),
5348
  SR_CORE ("trcrsctlr6",    CPENC (2,1,C1,C6,0),  0),
5349
  SR_CORE ("trcrsctlr7",    CPENC (2,1,C1,C7,0),  0),
5350
  SR_CORE ("trcrsctlr8",    CPENC (2,1,C1,C8,0),  0),
5351
  SR_CORE ("trcrsctlr9",    CPENC (2,1,C1,C9,0),  0),
5352
  SR_CORE ("trcrsctlr10",   CPENC (2,1,C1,C10,0), 0),
5353
  SR_CORE ("trcrsctlr11",   CPENC (2,1,C1,C11,0), 0),
5354
  SR_CORE ("trcrsctlr12",   CPENC (2,1,C1,C12,0), 0),
5355
  SR_CORE ("trcrsctlr13",   CPENC (2,1,C1,C13,0), 0),
5356
  SR_CORE ("trcrsctlr14",   CPENC (2,1,C1,C14,0), 0),
5357
  SR_CORE ("trcrsctlr15",   CPENC (2,1,C1,C15,0), 0),
5358
  SR_CORE ("trcrsctlr16",   CPENC (2,1,C1,C0,1),  0),
5359
  SR_CORE ("trcrsctlr17",   CPENC (2,1,C1,C1,1),  0),
5360
  SR_CORE ("trcrsctlr18",   CPENC (2,1,C1,C2,1),  0),
5361
  SR_CORE ("trcrsctlr19",   CPENC (2,1,C1,C3,1),  0),
5362
  SR_CORE ("trcrsctlr20",   CPENC (2,1,C1,C4,1),  0),
5363
  SR_CORE ("trcrsctlr21",   CPENC (2,1,C1,C5,1),  0),
5364
  SR_CORE ("trcrsctlr22",   CPENC (2,1,C1,C6,1),  0),
5365
  SR_CORE ("trcrsctlr23",   CPENC (2,1,C1,C7,1),  0),
5366
  SR_CORE ("trcrsctlr24",   CPENC (2,1,C1,C8,1),  0),
5367
  SR_CORE ("trcrsctlr25",   CPENC (2,1,C1,C9,1),  0),
5368
  SR_CORE ("trcrsctlr26",   CPENC (2,1,C1,C10,1), 0),
5369
  SR_CORE ("trcrsctlr27",   CPENC (2,1,C1,C11,1), 0),
5370
  SR_CORE ("trcrsctlr28",   CPENC (2,1,C1,C12,1), 0),
5371
  SR_CORE ("trcrsctlr29",   CPENC (2,1,C1,C13,1), 0),
5372
  SR_CORE ("trcrsctlr30",   CPENC (2,1,C1,C14,1), 0),
5373
  SR_CORE ("trcrsctlr31",   CPENC (2,1,C1,C15,1), 0),
5374
  SR_CORE ("trcseqevr0",    CPENC (2,1,C0,C0,4),  0),
5375
  SR_CORE ("trcseqevr1",    CPENC (2,1,C0,C1,4),  0),
5376
  SR_CORE ("trcseqevr2",    CPENC (2,1,C0,C2,4),  0),
5377
  SR_CORE ("trcseqrstevr",  CPENC (2,1,C0,C6,4),  0),
5378
  SR_CORE ("trcseqstr",     CPENC (2,1,C0,C7,4),  0),
5379
  SR_CORE ("trcssccr0",     CPENC (2,1,C1,C0,2),  0),
5380
  SR_CORE ("trcssccr1",     CPENC (2,1,C1,C1,2),  0),
5381
  SR_CORE ("trcssccr2",     CPENC (2,1,C1,C2,2),  0),
5382
  SR_CORE ("trcssccr3",     CPENC (2,1,C1,C3,2),  0),
5383
  SR_CORE ("trcssccr4",     CPENC (2,1,C1,C4,2),  0),
5384
  SR_CORE ("trcssccr5",     CPENC (2,1,C1,C5,2),  0),
5385
  SR_CORE ("trcssccr6",     CPENC (2,1,C1,C6,2),  0),
5386
  SR_CORE ("trcssccr7",     CPENC (2,1,C1,C7,2),  0),
5387
  SR_CORE ("trcsscsr0",     CPENC (2,1,C1,C8,2),  0),
5388
  SR_CORE ("trcsscsr1",     CPENC (2,1,C1,C9,2),  0),
5389
  SR_CORE ("trcsscsr2",     CPENC (2,1,C1,C10,2), 0),
5390
  SR_CORE ("trcsscsr3",     CPENC (2,1,C1,C11,2), 0),
5391
  SR_CORE ("trcsscsr4",     CPENC (2,1,C1,C12,2), 0),
5392
  SR_CORE ("trcsscsr5",     CPENC (2,1,C1,C13,2), 0),
5393
  SR_CORE ("trcsscsr6",     CPENC (2,1,C1,C14,2), 0),
5394
  SR_CORE ("trcsscsr7",     CPENC (2,1,C1,C15,2), 0),
5395
  SR_CORE ("trcsspcicr0",   CPENC (2,1,C1,C0,3),  0),
5396
  SR_CORE ("trcsspcicr1",   CPENC (2,1,C1,C1,3),  0),
5397
  SR_CORE ("trcsspcicr2",   CPENC (2,1,C1,C2,3),  0),
5398
  SR_CORE ("trcsspcicr3",   CPENC (2,1,C1,C3,3),  0),
5399
  SR_CORE ("trcsspcicr4",   CPENC (2,1,C1,C4,3),  0),
5400
  SR_CORE ("trcsspcicr5",   CPENC (2,1,C1,C5,3),  0),
5401
  SR_CORE ("trcsspcicr6",   CPENC (2,1,C1,C6,3),  0),
5402
  SR_CORE ("trcsspcicr7",   CPENC (2,1,C1,C7,3),  0),
5403
  SR_CORE ("trcstallctlr",  CPENC (2,1,C0,C11,0), 0),
5404
  SR_CORE ("trcsyncpr",     CPENC (2,1,C0,C13,0), 0),
5405
  SR_CORE ("trctraceidr",   CPENC (2,1,C0,C0,1),  0),
5406
  SR_CORE ("trctsctlr",     CPENC (2,1,C0,C12,0), 0),
5407
  SR_CORE ("trcvdarcctlr",  CPENC (2,1,C0,C10,2), 0),
5408
  SR_CORE ("trcvdctlr",     CPENC (2,1,C0,C8,2),  0),
5409
  SR_CORE ("trcvdsacctlr",  CPENC (2,1,C0,C9,2),  0),
5410
  SR_CORE ("trcvictlr",     CPENC (2,1,C0,C0,2),  0),
5411
  SR_CORE ("trcviiectlr",   CPENC (2,1,C0,C1,2),  0),
5412
  SR_CORE ("trcvipcssctlr", CPENC (2,1,C0,C3,2),  0),
5413
  SR_CORE ("trcvissctlr",   CPENC (2,1,C0,C2,2),  0),
5414
  SR_CORE ("trcvmidcctlr0", CPENC (2,1,C3,C2,2),  0),
5415
  SR_CORE ("trcvmidcctlr1", CPENC (2,1,C3,C3,2),  0),
5416
  SR_CORE ("trcvmidcvr0",   CPENC (2,1,C3,C0,1),  0),
5417
  SR_CORE ("trcvmidcvr1",   CPENC (2,1,C3,C2,1),  0),
5418
  SR_CORE ("trcvmidcvr2",   CPENC (2,1,C3,C4,1),  0),
5419
  SR_CORE ("trcvmidcvr3",   CPENC (2,1,C3,C6,1),  0),
5420
  SR_CORE ("trcvmidcvr4",   CPENC (2,1,C3,C8,1),  0),
5421
  SR_CORE ("trcvmidcvr5",   CPENC (2,1,C3,C10,1), 0),
5422
  SR_CORE ("trcvmidcvr6",   CPENC (2,1,C3,C12,1), 0),
5423
  SR_CORE ("trcvmidcvr7",   CPENC (2,1,C3,C14,1), 0),
5424
  SR_CORE ("trclar",        CPENC (2,1,C7,C12,6), F_REG_WRITE),
5425
  SR_CORE ("trcoslar",      CPENC (2,1,C1,C0,4),  F_REG_WRITE),
5426
5427
  SR_CORE ("csrcr_el0",     CPENC (2,3,C8,C0,0),  0),
5428
  SR_CORE ("csrptr_el0",    CPENC (2,3,C8,C0,1),  0),
5429
  SR_CORE ("csridr_el0",    CPENC (2,3,C8,C0,2),  F_REG_READ),
5430
  SR_CORE ("csrptridx_el0", CPENC (2,3,C8,C0,3),  F_REG_READ),
5431
  SR_CORE ("csrcr_el1",     CPENC (2,0,C8,C0,0),  0),
5432
  SR_CORE ("csrcr_el12",    CPENC (2,5,C8,C0,0),  0),
5433
  SR_CORE ("csrptr_el1",    CPENC (2,0,C8,C0,1),  0),
5434
  SR_CORE ("csrptr_el12",   CPENC (2,5,C8,C0,1),  0),
5435
  SR_CORE ("csrptridx_el1", CPENC (2,0,C8,C0,3),  F_REG_READ),
5436
  SR_CORE ("csrcr_el2",     CPENC (2,4,C8,C0,0),  0),
5437
  SR_CORE ("csrptr_el2",    CPENC (2,4,C8,C0,1),  0),
5438
  SR_CORE ("csrptridx_el2", CPENC (2,4,C8,C0,3),  F_REG_READ),
5439
5440
  SR_LOR ("lorid_el1",      CPENC (3,0,C10,C4,7),  F_REG_READ),
5441
  SR_LOR ("lorc_el1",       CPENC (3,0,C10,C4,3),  0),
5442
  SR_LOR ("lorea_el1",      CPENC (3,0,C10,C4,1),  0),
5443
  SR_LOR ("lorn_el1",       CPENC (3,0,C10,C4,2),  0),
5444
  SR_LOR ("lorsa_el1",      CPENC (3,0,C10,C4,0),  0),
5445
5446
  SR_CORE ("icc_ctlr_el3",  CPENC (3,6,C12,C12,4), 0),
5447
  SR_CORE ("icc_sre_el1",   CPENC (3,0,C12,C12,5), 0),
5448
  SR_CORE ("icc_sre_el2",   CPENC (3,4,C12,C9,5),  0),
5449
  SR_CORE ("icc_sre_el3",   CPENC (3,6,C12,C12,5), 0),
5450
  SR_CORE ("ich_vtr_el2",   CPENC (3,4,C12,C11,1), F_REG_READ),
5451
5452
  SR_CORE ("brbcr_el1",     CPENC (2,1,C9,C0,0),  0),
5453
  SR_CORE ("brbcr_el12",    CPENC (2,5,C9,C0,0),  0),
5454
  SR_CORE ("brbfcr_el1",    CPENC (2,1,C9,C0,1),  0),
5455
  SR_CORE ("brbts_el1",     CPENC (2,1,C9,C0,2),  0),
5456
  SR_CORE ("brbinfinj_el1", CPENC (2,1,C9,C1,0),  0),
5457
  SR_CORE ("brbsrcinj_el1", CPENC (2,1,C9,C1,1),  0),
5458
  SR_CORE ("brbtgtinj_el1", CPENC (2,1,C9,C1,2),  0),
5459
  SR_CORE ("brbidr0_el1",   CPENC (2,1,C9,C2,0),  F_REG_READ),
5460
  SR_CORE ("brbcr_el2",     CPENC (2,4,C9,C0,0),  0),
5461
  SR_CORE ("brbsrc0_el1",   CPENC (2,1,C8,C0,1),  F_REG_READ),
5462
  SR_CORE ("brbsrc1_el1",   CPENC (2,1,C8,C1,1),  F_REG_READ),
5463
  SR_CORE ("brbsrc2_el1",   CPENC (2,1,C8,C2,1),  F_REG_READ),
5464
  SR_CORE ("brbsrc3_el1",   CPENC (2,1,C8,C3,1),  F_REG_READ),
5465
  SR_CORE ("brbsrc4_el1",   CPENC (2,1,C8,C4,1),  F_REG_READ),
5466
  SR_CORE ("brbsrc5_el1",   CPENC (2,1,C8,C5,1),  F_REG_READ),
5467
  SR_CORE ("brbsrc6_el1",   CPENC (2,1,C8,C6,1),  F_REG_READ),
5468
  SR_CORE ("brbsrc7_el1",   CPENC (2,1,C8,C7,1),  F_REG_READ),
5469
  SR_CORE ("brbsrc8_el1",   CPENC (2,1,C8,C8,1),  F_REG_READ),
5470
  SR_CORE ("brbsrc9_el1",   CPENC (2,1,C8,C9,1),  F_REG_READ),
5471
  SR_CORE ("brbsrc10_el1",  CPENC (2,1,C8,C10,1), F_REG_READ),
5472
  SR_CORE ("brbsrc11_el1",  CPENC (2,1,C8,C11,1), F_REG_READ),
5473
  SR_CORE ("brbsrc12_el1",  CPENC (2,1,C8,C12,1), F_REG_READ),
5474
  SR_CORE ("brbsrc13_el1",  CPENC (2,1,C8,C13,1), F_REG_READ),
5475
  SR_CORE ("brbsrc14_el1",  CPENC (2,1,C8,C14,1), F_REG_READ),
5476
  SR_CORE ("brbsrc15_el1",  CPENC (2,1,C8,C15,1), F_REG_READ),
5477
  SR_CORE ("brbsrc16_el1",  CPENC (2,1,C8,C0,5),  F_REG_READ),
5478
  SR_CORE ("brbsrc17_el1",  CPENC (2,1,C8,C1,5),  F_REG_READ),
5479
  SR_CORE ("brbsrc18_el1",  CPENC (2,1,C8,C2,5),  F_REG_READ),
5480
  SR_CORE ("brbsrc19_el1",  CPENC (2,1,C8,C3,5),  F_REG_READ),
5481
  SR_CORE ("brbsrc20_el1",  CPENC (2,1,C8,C4,5),  F_REG_READ),
5482
  SR_CORE ("brbsrc21_el1",  CPENC (2,1,C8,C5,5),  F_REG_READ),
5483
  SR_CORE ("brbsrc22_el1",  CPENC (2,1,C8,C6,5),  F_REG_READ),
5484
  SR_CORE ("brbsrc23_el1",  CPENC (2,1,C8,C7,5),  F_REG_READ),
5485
  SR_CORE ("brbsrc24_el1",  CPENC (2,1,C8,C8,5),  F_REG_READ),
5486
  SR_CORE ("brbsrc25_el1",  CPENC (2,1,C8,C9,5),  F_REG_READ),
5487
  SR_CORE ("brbsrc26_el1",  CPENC (2,1,C8,C10,5), F_REG_READ),
5488
  SR_CORE ("brbsrc27_el1",  CPENC (2,1,C8,C11,5), F_REG_READ),
5489
  SR_CORE ("brbsrc28_el1",  CPENC (2,1,C8,C12,5), F_REG_READ),
5490
  SR_CORE ("brbsrc29_el1",  CPENC (2,1,C8,C13,5), F_REG_READ),
5491
  SR_CORE ("brbsrc30_el1",  CPENC (2,1,C8,C14,5), F_REG_READ),
5492
  SR_CORE ("brbsrc31_el1",  CPENC (2,1,C8,C15,5), F_REG_READ),
5493
  SR_CORE ("brbtgt0_el1",   CPENC (2,1,C8,C0,2),  F_REG_READ),
5494
  SR_CORE ("brbtgt1_el1",   CPENC (2,1,C8,C1,2),  F_REG_READ),
5495
  SR_CORE ("brbtgt2_el1",   CPENC (2,1,C8,C2,2),  F_REG_READ),
5496
  SR_CORE ("brbtgt3_el1",   CPENC (2,1,C8,C3,2),  F_REG_READ),
5497
  SR_CORE ("brbtgt4_el1",   CPENC (2,1,C8,C4,2),  F_REG_READ),
5498
  SR_CORE ("brbtgt5_el1",   CPENC (2,1,C8,C5,2),  F_REG_READ),
5499
  SR_CORE ("brbtgt6_el1",   CPENC (2,1,C8,C6,2),  F_REG_READ),
5500
  SR_CORE ("brbtgt7_el1",   CPENC (2,1,C8,C7,2),  F_REG_READ),
5501
  SR_CORE ("brbtgt8_el1",   CPENC (2,1,C8,C8,2),  F_REG_READ),
5502
  SR_CORE ("brbtgt9_el1",   CPENC (2,1,C8,C9,2),  F_REG_READ),
5503
  SR_CORE ("brbtgt10_el1",  CPENC (2,1,C8,C10,2), F_REG_READ),
5504
  SR_CORE ("brbtgt11_el1",  CPENC (2,1,C8,C11,2), F_REG_READ),
5505
  SR_CORE ("brbtgt12_el1",  CPENC (2,1,C8,C12,2), F_REG_READ),
5506
  SR_CORE ("brbtgt13_el1",  CPENC (2,1,C8,C13,2), F_REG_READ),
5507
  SR_CORE ("brbtgt14_el1",  CPENC (2,1,C8,C14,2), F_REG_READ),
5508
  SR_CORE ("brbtgt15_el1",  CPENC (2,1,C8,C15,2), F_REG_READ),
5509
  SR_CORE ("brbtgt16_el1",  CPENC (2,1,C8,C0,6),  F_REG_READ),
5510
  SR_CORE ("brbtgt17_el1",  CPENC (2,1,C8,C1,6),  F_REG_READ),
5511
  SR_CORE ("brbtgt18_el1",  CPENC (2,1,C8,C2,6),  F_REG_READ),
5512
  SR_CORE ("brbtgt19_el1",  CPENC (2,1,C8,C3,6),  F_REG_READ),
5513
  SR_CORE ("brbtgt20_el1",  CPENC (2,1,C8,C4,6),  F_REG_READ),
5514
  SR_CORE ("brbtgt21_el1",  CPENC (2,1,C8,C5,6),  F_REG_READ),
5515
  SR_CORE ("brbtgt22_el1",  CPENC (2,1,C8,C6,6),  F_REG_READ),
5516
  SR_CORE ("brbtgt23_el1",  CPENC (2,1,C8,C7,6),  F_REG_READ),
5517
  SR_CORE ("brbtgt24_el1",  CPENC (2,1,C8,C8,6),  F_REG_READ),
5518
  SR_CORE ("brbtgt25_el1",  CPENC (2,1,C8,C9,6),  F_REG_READ),
5519
  SR_CORE ("brbtgt26_el1",  CPENC (2,1,C8,C10,6), F_REG_READ),
5520
  SR_CORE ("brbtgt27_el1",  CPENC (2,1,C8,C11,6), F_REG_READ),
5521
  SR_CORE ("brbtgt28_el1",  CPENC (2,1,C8,C12,6), F_REG_READ),
5522
  SR_CORE ("brbtgt29_el1",  CPENC (2,1,C8,C13,6), F_REG_READ),
5523
  SR_CORE ("brbtgt30_el1",  CPENC (2,1,C8,C14,6), F_REG_READ),
5524
  SR_CORE ("brbtgt31_el1",  CPENC (2,1,C8,C15,6), F_REG_READ),
5525
  SR_CORE ("brbinf0_el1",   CPENC (2,1,C8,C0,0),  F_REG_READ),
5526
  SR_CORE ("brbinf1_el1",   CPENC (2,1,C8,C1,0),  F_REG_READ),
5527
  SR_CORE ("brbinf2_el1",   CPENC (2,1,C8,C2,0),  F_REG_READ),
5528
  SR_CORE ("brbinf3_el1",   CPENC (2,1,C8,C3,0),  F_REG_READ),
5529
  SR_CORE ("brbinf4_el1",   CPENC (2,1,C8,C4,0),  F_REG_READ),
5530
  SR_CORE ("brbinf5_el1",   CPENC (2,1,C8,C5,0),  F_REG_READ),
5531
  SR_CORE ("brbinf6_el1",   CPENC (2,1,C8,C6,0),  F_REG_READ),
5532
  SR_CORE ("brbinf7_el1",   CPENC (2,1,C8,C7,0),  F_REG_READ),
5533
  SR_CORE ("brbinf8_el1",   CPENC (2,1,C8,C8,0),  F_REG_READ),
5534
  SR_CORE ("brbinf9_el1",   CPENC (2,1,C8,C9,0),  F_REG_READ),
5535
  SR_CORE ("brbinf10_el1",  CPENC (2,1,C8,C10,0), F_REG_READ),
5536
  SR_CORE ("brbinf11_el1",  CPENC (2,1,C8,C11,0), F_REG_READ),
5537
  SR_CORE ("brbinf12_el1",  CPENC (2,1,C8,C12,0), F_REG_READ),
5538
  SR_CORE ("brbinf13_el1",  CPENC (2,1,C8,C13,0), F_REG_READ),
5539
  SR_CORE ("brbinf14_el1",  CPENC (2,1,C8,C14,0), F_REG_READ),
5540
  SR_CORE ("brbinf15_el1",  CPENC (2,1,C8,C15,0), F_REG_READ),
5541
  SR_CORE ("brbinf16_el1",  CPENC (2,1,C8,C0,4),  F_REG_READ),
5542
  SR_CORE ("brbinf17_el1",  CPENC (2,1,C8,C1,4),  F_REG_READ),
5543
  SR_CORE ("brbinf18_el1",  CPENC (2,1,C8,C2,4),  F_REG_READ),
5544
  SR_CORE ("brbinf19_el1",  CPENC (2,1,C8,C3,4),  F_REG_READ),
5545
  SR_CORE ("brbinf20_el1",  CPENC (2,1,C8,C4,4),  F_REG_READ),
5546
  SR_CORE ("brbinf21_el1",  CPENC (2,1,C8,C5,4),  F_REG_READ),
5547
  SR_CORE ("brbinf22_el1",  CPENC (2,1,C8,C6,4),  F_REG_READ),
5548
  SR_CORE ("brbinf23_el1",  CPENC (2,1,C8,C7,4),  F_REG_READ),
5549
  SR_CORE ("brbinf24_el1",  CPENC (2,1,C8,C8,4),  F_REG_READ),
5550
  SR_CORE ("brbinf25_el1",  CPENC (2,1,C8,C9,4),  F_REG_READ),
5551
  SR_CORE ("brbinf26_el1",  CPENC (2,1,C8,C10,4), F_REG_READ),
5552
  SR_CORE ("brbinf27_el1",  CPENC (2,1,C8,C11,4), F_REG_READ),
5553
  SR_CORE ("brbinf28_el1",  CPENC (2,1,C8,C12,4), F_REG_READ),
5554
  SR_CORE ("brbinf29_el1",  CPENC (2,1,C8,C13,4), F_REG_READ),
5555
  SR_CORE ("brbinf30_el1",  CPENC (2,1,C8,C14,4), F_REG_READ),
5556
  SR_CORE ("brbinf31_el1",  CPENC (2,1,C8,C15,4), F_REG_READ),
5557
5558
  SR_CORE ("accdata_el1",   CPENC (3,0,C13,C0,5), 0),
5559
5560
  SR_CORE ("mfar_el3",      CPENC (3,6,C6,C0,5), 0),
5561
  SR_CORE ("gpccr_el3",     CPENC (3,6,C2,C1,6), 0),
5562
  SR_CORE ("gptbr_el3",     CPENC (3,6,C2,C1,4), 0),
5563
5564
  SR_CORE ("mecidr_el2",    CPENC (3,4,C10,C8,7),  F_REG_READ),
5565
  SR_CORE ("mecid_p0_el2",  CPENC (3,4,C10,C8,0),  0),
5566
  SR_CORE ("mecid_a0_el2",  CPENC (3,4,C10,C8,1),  0),
5567
  SR_CORE ("mecid_p1_el2",  CPENC (3,4,C10,C8,2),  0),
5568
  SR_CORE ("mecid_a1_el2",  CPENC (3,4,C10,C8,3),  0),
5569
  SR_CORE ("vmecid_p_el2",  CPENC (3,4,C10,C9,0),  0),
5570
  SR_CORE ("vmecid_a_el2",  CPENC (3,4,C10,C9,1),  0),
5571
  SR_CORE ("mecid_rl_a_el3",CPENC (3,6,C10,C10,1), 0),
5572
5573
  SR_SME ("svcr",             CPENC (3,3,C4,C2,2),  0),
5574
  SR_SME ("id_aa64smfr0_el1", CPENC (3,0,C0,C4,5),  F_REG_READ),
5575
  SR_SME ("smcr_el1",         CPENC (3,0,C1,C2,6),  0),
5576
  SR_SME ("smcr_el12",        CPENC (3,5,C1,C2,6),  0),
5577
  SR_SME ("smcr_el2",         CPENC (3,4,C1,C2,6),  0),
5578
  SR_SME ("smcr_el3",         CPENC (3,6,C1,C2,6),  0),
5579
  SR_SME ("smpri_el1",        CPENC (3,0,C1,C2,4),  0),
5580
  SR_SME ("smprimap_el2",     CPENC (3,4,C1,C2,5),  0),
5581
  SR_SME ("smidr_el1",        CPENC (3,1,C0,C0,6),  F_REG_READ),
5582
  SR_SME ("tpidr2_el0",       CPENC (3,3,C13,C0,5), 0),
5583
  SR_SME ("mpamsm_el1",       CPENC (3,0,C10,C5,3), 0),
5584
5585
  SR_AMU ("amcr_el0",           CPENC (3,3,C13,C2,0),   0),
5586
  SR_AMU ("amcfgr_el0",         CPENC (3,3,C13,C2,1),   F_REG_READ),
5587
  SR_AMU ("amcgcr_el0",         CPENC (3,3,C13,C2,2),   F_REG_READ),
5588
  SR_AMU ("amuserenr_el0",      CPENC (3,3,C13,C2,3),   0),
5589
  SR_AMU ("amcntenclr0_el0",    CPENC (3,3,C13,C2,4),   0),
5590
  SR_AMU ("amcntenset0_el0",    CPENC (3,3,C13,C2,5),   0),
5591
  SR_AMU ("amcntenclr1_el0",    CPENC (3,3,C13,C3,0),   0),
5592
  SR_AMU ("amcntenset1_el0",    CPENC (3,3,C13,C3,1),   0),
5593
  SR_AMU ("amevcntr00_el0",     CPENC (3,3,C13,C4,0),   0),
5594
  SR_AMU ("amevcntr01_el0",     CPENC (3,3,C13,C4,1),   0),
5595
  SR_AMU ("amevcntr02_el0",     CPENC (3,3,C13,C4,2),   0),
5596
  SR_AMU ("amevcntr03_el0",     CPENC (3,3,C13,C4,3),   0),
5597
  SR_AMU ("amevtyper00_el0",    CPENC (3,3,C13,C6,0),   F_REG_READ),
5598
  SR_AMU ("amevtyper01_el0",    CPENC (3,3,C13,C6,1),   F_REG_READ),
5599
  SR_AMU ("amevtyper02_el0",    CPENC (3,3,C13,C6,2),   F_REG_READ),
5600
  SR_AMU ("amevtyper03_el0",    CPENC (3,3,C13,C6,3),   F_REG_READ),
5601
  SR_AMU ("amevcntr10_el0",     CPENC (3,3,C13,C12,0),  0),
5602
  SR_AMU ("amevcntr11_el0",     CPENC (3,3,C13,C12,1),  0),
5603
  SR_AMU ("amevcntr12_el0",     CPENC (3,3,C13,C12,2),  0),
5604
  SR_AMU ("amevcntr13_el0",     CPENC (3,3,C13,C12,3),  0),
5605
  SR_AMU ("amevcntr14_el0",     CPENC (3,3,C13,C12,4),  0),
5606
  SR_AMU ("amevcntr15_el0",     CPENC (3,3,C13,C12,5),  0),
5607
  SR_AMU ("amevcntr16_el0",     CPENC (3,3,C13,C12,6),  0),
5608
  SR_AMU ("amevcntr17_el0",     CPENC (3,3,C13,C12,7),  0),
5609
  SR_AMU ("amevcntr18_el0",     CPENC (3,3,C13,C13,0),  0),
5610
  SR_AMU ("amevcntr19_el0",     CPENC (3,3,C13,C13,1),  0),
5611
  SR_AMU ("amevcntr110_el0",    CPENC (3,3,C13,C13,2),  0),
5612
  SR_AMU ("amevcntr111_el0",    CPENC (3,3,C13,C13,3),  0),
5613
  SR_AMU ("amevcntr112_el0",    CPENC (3,3,C13,C13,4),  0),
5614
  SR_AMU ("amevcntr113_el0",    CPENC (3,3,C13,C13,5),  0),
5615
  SR_AMU ("amevcntr114_el0",    CPENC (3,3,C13,C13,6),  0),
5616
  SR_AMU ("amevcntr115_el0",    CPENC (3,3,C13,C13,7),  0),
5617
  SR_AMU ("amevtyper10_el0",    CPENC (3,3,C13,C14,0),  0),
5618
  SR_AMU ("amevtyper11_el0",    CPENC (3,3,C13,C14,1),  0),
5619
  SR_AMU ("amevtyper12_el0",    CPENC (3,3,C13,C14,2),  0),
5620
  SR_AMU ("amevtyper13_el0",    CPENC (3,3,C13,C14,3),  0),
5621
  SR_AMU ("amevtyper14_el0",    CPENC (3,3,C13,C14,4),  0),
5622
  SR_AMU ("amevtyper15_el0",    CPENC (3,3,C13,C14,5),  0),
5623
  SR_AMU ("amevtyper16_el0",    CPENC (3,3,C13,C14,6),  0),
5624
  SR_AMU ("amevtyper17_el0",    CPENC (3,3,C13,C14,7),  0),
5625
  SR_AMU ("amevtyper18_el0",    CPENC (3,3,C13,C15,0),  0),
5626
  SR_AMU ("amevtyper19_el0",    CPENC (3,3,C13,C15,1),  0),
5627
  SR_AMU ("amevtyper110_el0",   CPENC (3,3,C13,C15,2),  0),
5628
  SR_AMU ("amevtyper111_el0",   CPENC (3,3,C13,C15,3),  0),
5629
  SR_AMU ("amevtyper112_el0",   CPENC (3,3,C13,C15,4),  0),
5630
  SR_AMU ("amevtyper113_el0",   CPENC (3,3,C13,C15,5),  0),
5631
  SR_AMU ("amevtyper114_el0",   CPENC (3,3,C13,C15,6),  0),
5632
  SR_AMU ("amevtyper115_el0",   CPENC (3,3,C13,C15,7),  0),
5633
5634
  SR_GIC ("icc_pmr_el1",        CPENC (3,0,C4,C6,0),    0),
5635
  SR_GIC ("icc_iar0_el1",       CPENC (3,0,C12,C8,0),   F_REG_READ),
5636
  SR_GIC ("icc_eoir0_el1",      CPENC (3,0,C12,C8,1),   F_REG_WRITE),
5637
  SR_GIC ("icc_hppir0_el1",     CPENC (3,0,C12,C8,2),   F_REG_READ),
5638
  SR_GIC ("icc_bpr0_el1",       CPENC (3,0,C12,C8,3),   0),
5639
  SR_GIC ("icc_ap0r0_el1",      CPENC (3,0,C12,C8,4),   0),
5640
  SR_GIC ("icc_ap0r1_el1",      CPENC (3,0,C12,C8,5),   0),
5641
  SR_GIC ("icc_ap0r2_el1",      CPENC (3,0,C12,C8,6),   0),
5642
  SR_GIC ("icc_ap0r3_el1",      CPENC (3,0,C12,C8,7),   0),
5643
  SR_GIC ("icc_ap1r0_el1",      CPENC (3,0,C12,C9,0),   0),
5644
  SR_GIC ("icc_ap1r1_el1",      CPENC (3,0,C12,C9,1),   0),
5645
  SR_GIC ("icc_ap1r2_el1",      CPENC (3,0,C12,C9,2),   0),
5646
  SR_GIC ("icc_ap1r3_el1",      CPENC (3,0,C12,C9,3),   0),
5647
  SR_GIC ("icc_dir_el1",        CPENC (3,0,C12,C11,1),  F_REG_WRITE),
5648
  SR_GIC ("icc_rpr_el1",        CPENC (3,0,C12,C11,3),  F_REG_READ),
5649
  SR_GIC ("icc_sgi1r_el1",      CPENC (3,0,C12,C11,5),  F_REG_WRITE),
5650
  SR_GIC ("icc_asgi1r_el1",     CPENC (3,0,C12,C11,6),  F_REG_WRITE),
5651
  SR_GIC ("icc_sgi0r_el1",      CPENC (3,0,C12,C11,7),  F_REG_WRITE),
5652
  SR_GIC ("icc_iar1_el1",       CPENC (3,0,C12,C12,0),  F_REG_READ),
5653
  SR_GIC ("icc_eoir1_el1",      CPENC (3,0,C12,C12,1),  F_REG_WRITE),
5654
  SR_GIC ("icc_hppir1_el1",     CPENC (3,0,C12,C12,2),  F_REG_READ),
5655
  SR_GIC ("icc_bpr1_el1",       CPENC (3,0,C12,C12,3),  0),
5656
  SR_GIC ("icc_ctlr_el1",       CPENC (3,0,C12,C12,4),  0),
5657
  SR_GIC ("icc_igrpen0_el1",    CPENC (3,0,C12,C12,6),  0),
5658
  SR_GIC ("icc_igrpen1_el1",    CPENC (3,0,C12,C12,7),  0),
5659
  SR_GIC ("ich_ap0r0_el2",      CPENC (3,4,C12,C8,0),   0),
5660
  SR_GIC ("ich_ap0r1_el2",      CPENC (3,4,C12,C8,1),   0),
5661
  SR_GIC ("ich_ap0r2_el2",      CPENC (3,4,C12,C8,2),   0),
5662
  SR_GIC ("ich_ap0r3_el2",      CPENC (3,4,C12,C8,3),   0),
5663
  SR_GIC ("ich_ap1r0_el2",      CPENC (3,4,C12,C9,0),   0),
5664
  SR_GIC ("ich_ap1r1_el2",      CPENC (3,4,C12,C9,1),   0),
5665
  SR_GIC ("ich_ap1r2_el2",      CPENC (3,4,C12,C9,2),   0),
5666
  SR_GIC ("ich_ap1r3_el2",      CPENC (3,4,C12,C9,3),   0),
5667
  SR_GIC ("ich_hcr_el2",        CPENC (3,4,C12,C11,0),  0),
5668
  SR_GIC ("ich_misr_el2",       CPENC (3,4,C12,C11,2),  F_REG_READ),
5669
  SR_GIC ("ich_eisr_el2",       CPENC (3,4,C12,C11,3),  F_REG_READ),
5670
  SR_GIC ("ich_elrsr_el2",      CPENC (3,4,C12,C11,5),  F_REG_READ),
5671
  SR_GIC ("ich_vmcr_el2",       CPENC (3,4,C12,C11,7),  0),
5672
  SR_GIC ("ich_lr0_el2",        CPENC (3,4,C12,C12,0),  0),
5673
  SR_GIC ("ich_lr1_el2",        CPENC (3,4,C12,C12,1),  0),
5674
  SR_GIC ("ich_lr2_el2",        CPENC (3,4,C12,C12,2),  0),
5675
  SR_GIC ("ich_lr3_el2",        CPENC (3,4,C12,C12,3),  0),
5676
  SR_GIC ("ich_lr4_el2",        CPENC (3,4,C12,C12,4),  0),
5677
  SR_GIC ("ich_lr5_el2",        CPENC (3,4,C12,C12,5),  0),
5678
  SR_GIC ("ich_lr6_el2",        CPENC (3,4,C12,C12,6),  0),
5679
  SR_GIC ("ich_lr7_el2",        CPENC (3,4,C12,C12,7),  0),
5680
  SR_GIC ("ich_lr8_el2",        CPENC (3,4,C12,C13,0),  0),
5681
  SR_GIC ("ich_lr9_el2",        CPENC (3,4,C12,C13,1),  0),
5682
  SR_GIC ("ich_lr10_el2",       CPENC (3,4,C12,C13,2),  0),
5683
  SR_GIC ("ich_lr11_el2",       CPENC (3,4,C12,C13,3),  0),
5684
  SR_GIC ("ich_lr12_el2",       CPENC (3,4,C12,C13,4),  0),
5685
  SR_GIC ("ich_lr13_el2",       CPENC (3,4,C12,C13,5),  0),
5686
  SR_GIC ("ich_lr14_el2",       CPENC (3,4,C12,C13,6),  0),
5687
  SR_GIC ("ich_lr15_el2",       CPENC (3,4,C12,C13,7),  0),
5688
  SR_GIC ("icc_igrpen1_el3",    CPENC (3,6,C12,C12,7),  0),
5689
5690
  SR_V8_6A ("amcg1idr_el0",      CPENC (3,3,C13,C2,6),   F_REG_READ),
5691
  SR_V8_6A ("cntpctss_el0",      CPENC (3,3,C14,C0,5),   F_REG_READ),
5692
  SR_V8_6A ("cntvctss_el0",      CPENC (3,3,C14,C0,6),   F_REG_READ),
5693
  SR_V8_6A ("hfgrtr_el2",        CPENC (3,4,C1,C1,4),    0),
5694
  SR_V8_6A ("hfgwtr_el2",        CPENC (3,4,C1,C1,5),    0),
5695
  SR_V8_6A ("hfgitr_el2",        CPENC (3,4,C1,C1,6),    0),
5696
  SR_V8_6A ("hdfgrtr_el2",       CPENC (3,4,C3,C1,4),    0),
5697
  SR_V8_6A ("hdfgwtr_el2",       CPENC (3,4,C3,C1,5),    0),
5698
  SR_V8_6A ("hafgrtr_el2",       CPENC (3,4,C3,C1,6),    0),
5699
  SR_V8_6A ("amevcntvoff00_el2", CPENC (3,4,C13,C8,0),   0),
5700
  SR_V8_6A ("amevcntvoff01_el2", CPENC (3,4,C13,C8,1),   0),
5701
  SR_V8_6A ("amevcntvoff02_el2", CPENC (3,4,C13,C8,2),   0),
5702
  SR_V8_6A ("amevcntvoff03_el2", CPENC (3,4,C13,C8,3),   0),
5703
  SR_V8_6A ("amevcntvoff04_el2", CPENC (3,4,C13,C8,4),   0),
5704
  SR_V8_6A ("amevcntvoff05_el2", CPENC (3,4,C13,C8,5),   0),
5705
  SR_V8_6A ("amevcntvoff06_el2", CPENC (3,4,C13,C8,6),   0),
5706
  SR_V8_6A ("amevcntvoff07_el2", CPENC (3,4,C13,C8,7),   0),
5707
  SR_V8_6A ("amevcntvoff08_el2", CPENC (3,4,C13,C9,0),   0),
5708
  SR_V8_6A ("amevcntvoff09_el2", CPENC (3,4,C13,C9,1),   0),
5709
  SR_V8_6A ("amevcntvoff010_el2", CPENC (3,4,C13,C9,2),  0),
5710
  SR_V8_6A ("amevcntvoff011_el2", CPENC (3,4,C13,C9,3),  0),
5711
  SR_V8_6A ("amevcntvoff012_el2", CPENC (3,4,C13,C9,4),  0),
5712
  SR_V8_6A ("amevcntvoff013_el2", CPENC (3,4,C13,C9,5),  0),
5713
  SR_V8_6A ("amevcntvoff014_el2", CPENC (3,4,C13,C9,6),  0),
5714
  SR_V8_6A ("amevcntvoff015_el2", CPENC (3,4,C13,C9,7),  0),
5715
  SR_V8_6A ("amevcntvoff10_el2", CPENC (3,4,C13,C10,0),  0),
5716
  SR_V8_6A ("amevcntvoff11_el2", CPENC (3,4,C13,C10,1),  0),
5717
  SR_V8_6A ("amevcntvoff12_el2", CPENC (3,4,C13,C10,2),  0),
5718
  SR_V8_6A ("amevcntvoff13_el2", CPENC (3,4,C13,C10,3),  0),
5719
  SR_V8_6A ("amevcntvoff14_el2", CPENC (3,4,C13,C10,4),  0),
5720
  SR_V8_6A ("amevcntvoff15_el2", CPENC (3,4,C13,C10,5),  0),
5721
  SR_V8_6A ("amevcntvoff16_el2", CPENC (3,4,C13,C10,6),  0),
5722
  SR_V8_6A ("amevcntvoff17_el2", CPENC (3,4,C13,C10,7),  0),
5723
  SR_V8_6A ("amevcntvoff18_el2", CPENC (3,4,C13,C11,0),  0),
5724
  SR_V8_6A ("amevcntvoff19_el2", CPENC (3,4,C13,C11,1),  0),
5725
  SR_V8_6A ("amevcntvoff110_el2", CPENC (3,4,C13,C11,2), 0),
5726
  SR_V8_6A ("amevcntvoff111_el2", CPENC (3,4,C13,C11,3), 0),
5727
  SR_V8_6A ("amevcntvoff112_el2", CPENC (3,4,C13,C11,4), 0),
5728
  SR_V8_6A ("amevcntvoff113_el2", CPENC (3,4,C13,C11,5), 0),
5729
  SR_V8_6A ("amevcntvoff114_el2", CPENC (3,4,C13,C11,6), 0),
5730
  SR_V8_6A ("amevcntvoff115_el2", CPENC (3,4,C13,C11,7), 0),
5731
  SR_V8_6A ("cntpoff_el2",       CPENC (3,4,C14,C0,6),   0),
5732
5733
  SR_V8_7A ("pmsnevfr_el1",      CPENC (3,0,C9,C9,1),    0),
5734
  SR_V8_7A ("hcrx_el2",          CPENC (3,4,C1,C2,2),    0),
5735
5736
  SR_V8_8A ("allint",            CPENC (3,0,C4,C3,0),    0),
5737
  SR_V8_8A ("icc_nmiar1_el1",    CPENC (3,0,C12,C9,5),   F_REG_READ),
5738
5739
  { 0, CPENC (0,0,0,0,0), 0, 0 }
5740
};
5741
5742
bool
5743
aarch64_sys_reg_deprecated_p (const uint32_t reg_flags)
5744
0
{
5745
0
  return (reg_flags & F_DEPRECATED) != 0;
5746
0
}
5747
5748
/* The CPENC below is fairly misleading, the fields
5749
   here are not in CPENC form. They are in op2op1 form. The fields are encoded
5750
   by ins_pstatefield, which just shifts the value by the width of the fields
5751
   in a loop. So if you CPENC them only the first value will be set, the rest
5752
   are masked out to 0. As an example. op2 = 3, op1=2. CPENC would produce a
5753
   value of 0b110000000001000000 (0x30040) while what you want is
5754
   0b011010 (0x1a).  */
5755
const aarch64_sys_reg aarch64_pstatefields [] =
5756
{
5757
  SR_CORE ("spsel",   0x05, F_REG_MAX_VALUE (1)),
5758
  SR_CORE ("daifset",   0x1e, F_REG_MAX_VALUE (15)),
5759
  SR_CORE ("daifclr",   0x1f, F_REG_MAX_VALUE (15)),
5760
  SR_PAN  ("pan",   0x04, F_REG_MAX_VALUE (1)),
5761
  SR_V8_2A ("uao",    0x03, F_REG_MAX_VALUE (1)),
5762
  SR_SSBS ("ssbs",    0x19, F_REG_MAX_VALUE (1)),
5763
  SR_V8_4A ("dit",    0x1a, F_REG_MAX_VALUE (1)),
5764
  SR_MEMTAG ("tco",   0x1c, F_REG_MAX_VALUE (1)),
5765
  SR_SME  ("svcrsm",    0x1b, PSTATE_ENCODE_CRM_AND_IMM(0x2,0x1)
5766
        | F_REG_MAX_VALUE (1)),
5767
  SR_SME  ("svcrza",    0x1b, PSTATE_ENCODE_CRM_AND_IMM(0x4,0x1)
5768
        | F_REG_MAX_VALUE (1)),
5769
  SR_SME  ("svcrsmza",    0x1b, PSTATE_ENCODE_CRM_AND_IMM(0x6,0x1)
5770
        | F_REG_MAX_VALUE (1)),
5771
  SR_V8_8A ("allint",   0x08, F_REG_MAX_VALUE (1)),
5772
  { 0,    CPENC (0,0,0,0,0), 0, 0 },
5773
};
5774
5775
bool
5776
aarch64_pstatefield_supported_p (const aarch64_feature_set features,
5777
         const aarch64_sys_reg *reg)
5778
0
{
5779
0
  if (!(reg->flags & F_ARCHEXT))
5780
0
    return true;
5781
5782
0
  return AARCH64_CPU_HAS_ALL_FEATURES (features, reg->features);
5783
0
}
5784
5785
const aarch64_sys_ins_reg aarch64_sys_regs_ic[] =
5786
{
5787
    { "ialluis", CPENS(0,C7,C1,0), 0 },
5788
    { "iallu",   CPENS(0,C7,C5,0), 0 },
5789
    { "ivau",    CPENS (3, C7, C5, 1), F_HASXT },
5790
    { 0, CPENS(0,0,0,0), 0 }
5791
};
5792
5793
const aarch64_sys_ins_reg aarch64_sys_regs_dc[] =
5794
{
5795
    { "zva",      CPENS (3, C7, C4, 1),  F_HASXT },
5796
    { "gva",      CPENS (3, C7, C4, 3),  F_HASXT | F_ARCHEXT },
5797
    { "gzva",     CPENS (3, C7, C4, 4),  F_HASXT | F_ARCHEXT },
5798
    { "ivac",       CPENS (0, C7, C6, 1),  F_HASXT },
5799
    { "igvac",      CPENS (0, C7, C6, 3),  F_HASXT | F_ARCHEXT },
5800
    { "igsw",       CPENS (0, C7, C6, 4),  F_HASXT | F_ARCHEXT },
5801
    { "isw",      CPENS (0, C7, C6, 2),  F_HASXT },
5802
    { "igdvac",     CPENS (0, C7, C6, 5),  F_HASXT | F_ARCHEXT },
5803
    { "igdsw",      CPENS (0, C7, C6, 6),  F_HASXT | F_ARCHEXT },
5804
    { "cvac",       CPENS (3, C7, C10, 1), F_HASXT },
5805
    { "cgvac",      CPENS (3, C7, C10, 3), F_HASXT | F_ARCHEXT },
5806
    { "cgdvac",     CPENS (3, C7, C10, 5), F_HASXT | F_ARCHEXT },
5807
    { "csw",      CPENS (0, C7, C10, 2), F_HASXT },
5808
    { "cgsw",       CPENS (0, C7, C10, 4), F_HASXT | F_ARCHEXT },
5809
    { "cgdsw",      CPENS (0, C7, C10, 6), F_HASXT | F_ARCHEXT },
5810
    { "cvau",       CPENS (3, C7, C11, 1), F_HASXT },
5811
    { "cvap",       CPENS (3, C7, C12, 1), F_HASXT | F_ARCHEXT },
5812
    { "cgvap",      CPENS (3, C7, C12, 3), F_HASXT | F_ARCHEXT },
5813
    { "cgdvap",     CPENS (3, C7, C12, 5), F_HASXT | F_ARCHEXT },
5814
    { "cvadp",      CPENS (3, C7, C13, 1), F_HASXT | F_ARCHEXT },
5815
    { "cgvadp",     CPENS (3, C7, C13, 3), F_HASXT | F_ARCHEXT },
5816
    { "cgdvadp",    CPENS (3, C7, C13, 5), F_HASXT | F_ARCHEXT },
5817
    { "civac",      CPENS (3, C7, C14, 1), F_HASXT },
5818
    { "cigvac",     CPENS (3, C7, C14, 3), F_HASXT | F_ARCHEXT },
5819
    { "cigdvac",    CPENS (3, C7, C14, 5), F_HASXT | F_ARCHEXT },
5820
    { "cisw",       CPENS (0, C7, C14, 2), F_HASXT },
5821
    { "cigsw",      CPENS (0, C7, C14, 4), F_HASXT | F_ARCHEXT },
5822
    { "cigdsw",     CPENS (0, C7, C14, 6), F_HASXT | F_ARCHEXT },
5823
    { "cipapa",     CPENS (6, C7, C14, 1), F_HASXT },
5824
    { "cigdpapa",   CPENS (6, C7, C14, 5), F_HASXT },
5825
    { 0,       CPENS(0,0,0,0), 0 }
5826
};
5827
5828
const aarch64_sys_ins_reg aarch64_sys_regs_at[] =
5829
{
5830
    { "s1e1r",      CPENS (0, C7, C8, 0), F_HASXT },
5831
    { "s1e1w",      CPENS (0, C7, C8, 1), F_HASXT },
5832
    { "s1e0r",      CPENS (0, C7, C8, 2), F_HASXT },
5833
    { "s1e0w",      CPENS (0, C7, C8, 3), F_HASXT },
5834
    { "s12e1r",     CPENS (4, C7, C8, 4), F_HASXT },
5835
    { "s12e1w",     CPENS (4, C7, C8, 5), F_HASXT },
5836
    { "s12e0r",     CPENS (4, C7, C8, 6), F_HASXT },
5837
    { "s12e0w",     CPENS (4, C7, C8, 7), F_HASXT },
5838
    { "s1e2r",      CPENS (4, C7, C8, 0), F_HASXT },
5839
    { "s1e2w",      CPENS (4, C7, C8, 1), F_HASXT },
5840
    { "s1e3r",      CPENS (6, C7, C8, 0), F_HASXT },
5841
    { "s1e3w",      CPENS (6, C7, C8, 1), F_HASXT },
5842
    { "s1e1rp",     CPENS (0, C7, C9, 0), F_HASXT | F_ARCHEXT },
5843
    { "s1e1wp",     CPENS (0, C7, C9, 1), F_HASXT | F_ARCHEXT },
5844
    { 0,       CPENS(0,0,0,0), 0 }
5845
};
5846
5847
const aarch64_sys_ins_reg aarch64_sys_regs_tlbi[] =
5848
{
5849
    { "vmalle1",   CPENS(0,C8,C7,0), 0 },
5850
    { "vae1",      CPENS (0, C8, C7, 1), F_HASXT },
5851
    { "aside1",    CPENS (0, C8, C7, 2), F_HASXT },
5852
    { "vaae1",     CPENS (0, C8, C7, 3), F_HASXT },
5853
    { "vmalle1is", CPENS(0,C8,C3,0), 0 },
5854
    { "vae1is",    CPENS (0, C8, C3, 1), F_HASXT },
5855
    { "aside1is",  CPENS (0, C8, C3, 2), F_HASXT },
5856
    { "vaae1is",   CPENS (0, C8, C3, 3), F_HASXT },
5857
    { "ipas2e1is", CPENS (4, C8, C0, 1), F_HASXT },
5858
    { "ipas2le1is",CPENS (4, C8, C0, 5), F_HASXT },
5859
    { "ipas2e1",   CPENS (4, C8, C4, 1), F_HASXT },
5860
    { "ipas2le1",  CPENS (4, C8, C4, 5), F_HASXT },
5861
    { "vae2",      CPENS (4, C8, C7, 1), F_HASXT },
5862
    { "vae2is",    CPENS (4, C8, C3, 1), F_HASXT },
5863
    { "vmalls12e1",CPENS(4,C8,C7,6), 0 },
5864
    { "vmalls12e1is",CPENS(4,C8,C3,6), 0 },
5865
    { "vae3",      CPENS (6, C8, C7, 1), F_HASXT },
5866
    { "vae3is",    CPENS (6, C8, C3, 1), F_HASXT },
5867
    { "alle2",     CPENS(4,C8,C7,0), 0 },
5868
    { "alle2is",   CPENS(4,C8,C3,0), 0 },
5869
    { "alle1",     CPENS(4,C8,C7,4), 0 },
5870
    { "alle1is",   CPENS(4,C8,C3,4), 0 },
5871
    { "alle3",     CPENS(6,C8,C7,0), 0 },
5872
    { "alle3is",   CPENS(6,C8,C3,0), 0 },
5873
    { "vale1is",   CPENS (0, C8, C3, 5), F_HASXT },
5874
    { "vale2is",   CPENS (4, C8, C3, 5), F_HASXT },
5875
    { "vale3is",   CPENS (6, C8, C3, 5), F_HASXT },
5876
    { "vaale1is",  CPENS (0, C8, C3, 7), F_HASXT },
5877
    { "vale1",     CPENS (0, C8, C7, 5), F_HASXT },
5878
    { "vale2",     CPENS (4, C8, C7, 5), F_HASXT },
5879
    { "vale3",     CPENS (6, C8, C7, 5), F_HASXT },
5880
    { "vaale1",    CPENS (0, C8, C7, 7), F_HASXT },
5881
5882
    { "vmalle1os",    CPENS (0, C8, C1, 0), F_ARCHEXT },
5883
    { "vae1os",       CPENS (0, C8, C1, 1), F_HASXT | F_ARCHEXT },
5884
    { "aside1os",     CPENS (0, C8, C1, 2), F_HASXT | F_ARCHEXT },
5885
    { "vaae1os",      CPENS (0, C8, C1, 3), F_HASXT | F_ARCHEXT },
5886
    { "vale1os",      CPENS (0, C8, C1, 5), F_HASXT | F_ARCHEXT },
5887
    { "vaale1os",     CPENS (0, C8, C1, 7), F_HASXT | F_ARCHEXT },
5888
    { "ipas2e1os",    CPENS (4, C8, C4, 0), F_HASXT | F_ARCHEXT },
5889
    { "ipas2le1os",   CPENS (4, C8, C4, 4), F_HASXT | F_ARCHEXT },
5890
    { "vae2os",       CPENS (4, C8, C1, 1), F_HASXT | F_ARCHEXT },
5891
    { "vale2os",      CPENS (4, C8, C1, 5), F_HASXT | F_ARCHEXT },
5892
    { "vmalls12e1os", CPENS (4, C8, C1, 6), F_ARCHEXT },
5893
    { "vae3os",       CPENS (6, C8, C1, 1), F_HASXT | F_ARCHEXT },
5894
    { "vale3os",      CPENS (6, C8, C1, 5), F_HASXT | F_ARCHEXT },
5895
    { "alle2os",      CPENS (4, C8, C1, 0), F_ARCHEXT },
5896
    { "alle1os",      CPENS (4, C8, C1, 4), F_ARCHEXT },
5897
    { "alle3os",      CPENS (6, C8, C1, 0), F_ARCHEXT },
5898
5899
    { "rvae1",      CPENS (0, C8, C6, 1), F_HASXT | F_ARCHEXT },
5900
    { "rvaae1",     CPENS (0, C8, C6, 3), F_HASXT | F_ARCHEXT },
5901
    { "rvale1",     CPENS (0, C8, C6, 5), F_HASXT | F_ARCHEXT },
5902
    { "rvaale1",    CPENS (0, C8, C6, 7), F_HASXT | F_ARCHEXT },
5903
    { "rvae1is",    CPENS (0, C8, C2, 1), F_HASXT | F_ARCHEXT },
5904
    { "rvaae1is",   CPENS (0, C8, C2, 3), F_HASXT | F_ARCHEXT },
5905
    { "rvale1is",   CPENS (0, C8, C2, 5), F_HASXT | F_ARCHEXT },
5906
    { "rvaale1is",  CPENS (0, C8, C2, 7), F_HASXT | F_ARCHEXT },
5907
    { "rvae1os",    CPENS (0, C8, C5, 1), F_HASXT | F_ARCHEXT },
5908
    { "rvaae1os",   CPENS (0, C8, C5, 3), F_HASXT | F_ARCHEXT },
5909
    { "rvale1os",   CPENS (0, C8, C5, 5), F_HASXT | F_ARCHEXT },
5910
    { "rvaale1os",  CPENS (0, C8, C5, 7), F_HASXT | F_ARCHEXT },
5911
    { "ripas2e1is", CPENS (4, C8, C0, 2), F_HASXT | F_ARCHEXT },
5912
    { "ripas2le1is",CPENS (4, C8, C0, 6), F_HASXT | F_ARCHEXT },
5913
    { "ripas2e1",   CPENS (4, C8, C4, 2), F_HASXT | F_ARCHEXT },
5914
    { "ripas2le1",  CPENS (4, C8, C4, 6), F_HASXT | F_ARCHEXT },
5915
    { "ripas2e1os", CPENS (4, C8, C4, 3), F_HASXT | F_ARCHEXT },
5916
    { "ripas2le1os",CPENS (4, C8, C4, 7), F_HASXT | F_ARCHEXT },
5917
    { "rvae2",      CPENS (4, C8, C6, 1), F_HASXT | F_ARCHEXT },
5918
    { "rvale2",     CPENS (4, C8, C6, 5), F_HASXT | F_ARCHEXT },
5919
    { "rvae2is",    CPENS (4, C8, C2, 1), F_HASXT | F_ARCHEXT },
5920
    { "rvale2is",   CPENS (4, C8, C2, 5), F_HASXT | F_ARCHEXT },
5921
    { "rvae2os",    CPENS (4, C8, C5, 1), F_HASXT | F_ARCHEXT },
5922
    { "rvale2os",   CPENS (4, C8, C5, 5), F_HASXT | F_ARCHEXT },
5923
    { "rvae3",      CPENS (6, C8, C6, 1), F_HASXT | F_ARCHEXT },
5924
    { "rvale3",     CPENS (6, C8, C6, 5), F_HASXT | F_ARCHEXT },
5925
    { "rvae3is",    CPENS (6, C8, C2, 1), F_HASXT | F_ARCHEXT },
5926
    { "rvale3is",   CPENS (6, C8, C2, 5), F_HASXT | F_ARCHEXT },
5927
    { "rvae3os",    CPENS (6, C8, C5, 1), F_HASXT | F_ARCHEXT },
5928
    { "rvale3os",   CPENS (6, C8, C5, 5), F_HASXT | F_ARCHEXT },
5929
5930
    { "rpaos",      CPENS (6, C8, C4, 3), F_HASXT },
5931
    { "rpalos",     CPENS (6, C8, C4, 7), F_HASXT },
5932
    { "paallos",    CPENS (6, C8, C1, 4), 0},
5933
    { "paall",      CPENS (6, C8, C7, 4), 0},
5934
5935
    { 0,       CPENS(0,0,0,0), 0 }
5936
};
5937
5938
const aarch64_sys_ins_reg aarch64_sys_regs_sr[] =
5939
{
5940
    /* RCTX is somewhat unique in a way that it has different values
5941
       (op2) based on the instruction in which it is used (cfp/dvp/cpp).
5942
       Thus op2 is masked out and instead encoded directly in the
5943
       aarch64_opcode_table entries for the respective instructions.  */
5944
    { "rctx",   CPENS(3,C7,C3,0), F_HASXT | F_ARCHEXT | F_REG_WRITE}, /* WO */
5945
5946
    { 0,       CPENS(0,0,0,0), 0 }
5947
};
5948
5949
bool
5950
aarch64_sys_ins_reg_has_xt (const aarch64_sys_ins_reg *sys_ins_reg)
5951
0
{
5952
0
  return (sys_ins_reg->flags & F_HASXT) != 0;
5953
0
}
5954
5955
extern bool
5956
aarch64_sys_ins_reg_supported_p (const aarch64_feature_set features,
5957
     const char *reg_name,
5958
                 aarch64_insn reg_value,
5959
                 uint32_t reg_flags,
5960
                 aarch64_feature_set reg_features)
5961
0
{
5962
  /* Armv8-R has no EL3.  */
5963
0
  if (AARCH64_CPU_HAS_FEATURE (features, AARCH64_FEATURE_V8R))
5964
0
    {
5965
0
      const char *suffix = strrchr (reg_name, '_');
5966
0
      if (suffix && !strcmp (suffix, "_el3"))
5967
0
  return false;
5968
0
    }
5969
5970
0
  if (!(reg_flags & F_ARCHEXT))
5971
0
    return true;
5972
5973
0
  if (reg_features
5974
0
      && AARCH64_CPU_HAS_ALL_FEATURES (features, reg_features))
5975
0
    return true;
5976
5977
  /* ARMv8.4 TLB instructions.  */
5978
0
  if ((reg_value == CPENS (0, C8, C1, 0)
5979
0
       || reg_value == CPENS (0, C8, C1, 1)
5980
0
       || reg_value == CPENS (0, C8, C1, 2)
5981
0
       || reg_value == CPENS (0, C8, C1, 3)
5982
0
       || reg_value == CPENS (0, C8, C1, 5)
5983
0
       || reg_value == CPENS (0, C8, C1, 7)
5984
0
       || reg_value == CPENS (4, C8, C4, 0)
5985
0
       || reg_value == CPENS (4, C8, C4, 4)
5986
0
       || reg_value == CPENS (4, C8, C1, 1)
5987
0
       || reg_value == CPENS (4, C8, C1, 5)
5988
0
       || reg_value == CPENS (4, C8, C1, 6)
5989
0
       || reg_value == CPENS (6, C8, C1, 1)
5990
0
       || reg_value == CPENS (6, C8, C1, 5)
5991
0
       || reg_value == CPENS (4, C8, C1, 0)
5992
0
       || reg_value == CPENS (4, C8, C1, 4)
5993
0
       || reg_value == CPENS (6, C8, C1, 0)
5994
0
       || reg_value == CPENS (0, C8, C6, 1)
5995
0
       || reg_value == CPENS (0, C8, C6, 3)
5996
0
       || reg_value == CPENS (0, C8, C6, 5)
5997
0
       || reg_value == CPENS (0, C8, C6, 7)
5998
0
       || reg_value == CPENS (0, C8, C2, 1)
5999
0
       || reg_value == CPENS (0, C8, C2, 3)
6000
0
       || reg_value == CPENS (0, C8, C2, 5)
6001
0
       || reg_value == CPENS (0, C8, C2, 7)
6002
0
       || reg_value == CPENS (0, C8, C5, 1)
6003
0
       || reg_value == CPENS (0, C8, C5, 3)
6004
0
       || reg_value == CPENS (0, C8, C5, 5)
6005
0
       || reg_value == CPENS (0, C8, C5, 7)
6006
0
       || reg_value == CPENS (4, C8, C0, 2)
6007
0
       || reg_value == CPENS (4, C8, C0, 6)
6008
0
       || reg_value == CPENS (4, C8, C4, 2)
6009
0
       || reg_value == CPENS (4, C8, C4, 6)
6010
0
       || reg_value == CPENS (4, C8, C4, 3)
6011
0
       || reg_value == CPENS (4, C8, C4, 7)
6012
0
       || reg_value == CPENS (4, C8, C6, 1)
6013
0
       || reg_value == CPENS (4, C8, C6, 5)
6014
0
       || reg_value == CPENS (4, C8, C2, 1)
6015
0
       || reg_value == CPENS (4, C8, C2, 5)
6016
0
       || reg_value == CPENS (4, C8, C5, 1)
6017
0
       || reg_value == CPENS (4, C8, C5, 5)
6018
0
       || reg_value == CPENS (6, C8, C6, 1)
6019
0
       || reg_value == CPENS (6, C8, C6, 5)
6020
0
       || reg_value == CPENS (6, C8, C2, 1)
6021
0
       || reg_value == CPENS (6, C8, C2, 5)
6022
0
       || reg_value == CPENS (6, C8, C5, 1)
6023
0
       || reg_value == CPENS (6, C8, C5, 5))
6024
0
      && AARCH64_CPU_HAS_FEATURE (features, AARCH64_FEATURE_V8_4A))
6025
0
    return true;
6026
6027
  /* DC CVAP.  Values are from aarch64_sys_regs_dc.  */
6028
0
  if (reg_value == CPENS (3, C7, C12, 1)
6029
0
      && AARCH64_CPU_HAS_FEATURE (features, AARCH64_FEATURE_V8_2A))
6030
0
    return true;
6031
6032
  /* DC CVADP.  Values are from aarch64_sys_regs_dc.  */
6033
0
  if (reg_value == CPENS (3, C7, C13, 1)
6034
0
      && AARCH64_CPU_HAS_FEATURE (features, AARCH64_FEATURE_CVADP))
6035
0
    return true;
6036
6037
  /* DC <dc_op> for ARMv8.5-A Memory Tagging Extension.  */
6038
0
  if ((reg_value == CPENS (0, C7, C6, 3)
6039
0
       || reg_value == CPENS (0, C7, C6, 4)
6040
0
       || reg_value == CPENS (0, C7, C10, 4)
6041
0
       || reg_value == CPENS (0, C7, C14, 4)
6042
0
       || reg_value == CPENS (3, C7, C10, 3)
6043
0
       || reg_value == CPENS (3, C7, C12, 3)
6044
0
       || reg_value == CPENS (3, C7, C13, 3)
6045
0
       || reg_value == CPENS (3, C7, C14, 3)
6046
0
       || reg_value == CPENS (3, C7, C4, 3)
6047
0
       || reg_value == CPENS (0, C7, C6, 5)
6048
0
       || reg_value == CPENS (0, C7, C6, 6)
6049
0
       || reg_value == CPENS (0, C7, C10, 6)
6050
0
       || reg_value == CPENS (0, C7, C14, 6)
6051
0
       || reg_value == CPENS (3, C7, C10, 5)
6052
0
       || reg_value == CPENS (3, C7, C12, 5)
6053
0
       || reg_value == CPENS (3, C7, C13, 5)
6054
0
       || reg_value == CPENS (3, C7, C14, 5)
6055
0
       || reg_value == CPENS (3, C7, C4, 4))
6056
0
      && AARCH64_CPU_HAS_FEATURE (features, AARCH64_FEATURE_MEMTAG))
6057
0
    return true;
6058
6059
  /* AT S1E1RP, AT S1E1WP.  Values are from aarch64_sys_regs_at.  */
6060
0
  if ((reg_value == CPENS (0, C7, C9, 0)
6061
0
       || reg_value == CPENS (0, C7, C9, 1))
6062
0
      && AARCH64_CPU_HAS_FEATURE (features, AARCH64_FEATURE_V8_2A))
6063
0
    return true;
6064
6065
  /* CFP/DVP/CPP RCTX : Value are from aarch64_sys_regs_sr. */
6066
0
  if (reg_value == CPENS (3, C7, C3, 0)
6067
0
      && AARCH64_CPU_HAS_FEATURE (features, AARCH64_FEATURE_PREDRES))
6068
0
    return true;
6069
6070
0
  return false;
6071
0
}
6072
6073
#undef C0
6074
#undef C1
6075
#undef C2
6076
#undef C3
6077
#undef C4
6078
#undef C5
6079
#undef C6
6080
#undef C7
6081
#undef C8
6082
#undef C9
6083
#undef C10
6084
#undef C11
6085
#undef C12
6086
#undef C13
6087
#undef C14
6088
#undef C15
6089
6090
0
#define BIT(INSN,BT)     (((INSN) >> (BT)) & 1)
6091
0
#define BITS(INSN,HI,LO) (((INSN) >> (LO)) & ((1 << (((HI) - (LO)) + 1)) - 1))
6092
6093
static enum err_type
6094
verify_ldpsw (const struct aarch64_inst *inst ATTRIBUTE_UNUSED,
6095
        const aarch64_insn insn, bfd_vma pc ATTRIBUTE_UNUSED,
6096
        bool encoding ATTRIBUTE_UNUSED,
6097
        aarch64_operand_error *mismatch_detail ATTRIBUTE_UNUSED,
6098
        aarch64_instr_sequence *insn_sequence ATTRIBUTE_UNUSED)
6099
0
{
6100
0
  int t  = BITS (insn, 4, 0);
6101
0
  int n  = BITS (insn, 9, 5);
6102
0
  int t2 = BITS (insn, 14, 10);
6103
6104
0
  if (BIT (insn, 23))
6105
0
    {
6106
      /* Write back enabled.  */
6107
0
      if ((t == n || t2 == n) && n != 31)
6108
0
  return ERR_UND;
6109
0
    }
6110
6111
0
  if (BIT (insn, 22))
6112
0
    {
6113
      /* Load */
6114
0
      if (t == t2)
6115
0
  return ERR_UND;
6116
0
    }
6117
6118
0
  return ERR_OK;
6119
0
}
6120
6121
/* Verifier for vector by element 3 operands functions where the
6122
   conditions `if sz:L == 11 then UNDEFINED` holds.  */
6123
6124
static enum err_type
6125
verify_elem_sd (const struct aarch64_inst *inst, const aarch64_insn insn,
6126
    bfd_vma pc ATTRIBUTE_UNUSED, bool encoding,
6127
    aarch64_operand_error *mismatch_detail ATTRIBUTE_UNUSED,
6128
    aarch64_instr_sequence *insn_sequence ATTRIBUTE_UNUSED)
6129
0
{
6130
0
  const aarch64_insn undef_pattern = 0x3;
6131
0
  aarch64_insn value;
6132
6133
0
  assert (inst->opcode);
6134
0
  assert (inst->opcode->operands[2] == AARCH64_OPND_Em);
6135
0
  value = encoding ? inst->value : insn;
6136
0
  assert (value);
6137
6138
0
  if (undef_pattern == extract_fields (value, 0, 2, FLD_sz, FLD_L))
6139
0
    return ERR_UND;
6140
6141
0
  return ERR_OK;
6142
0
}
6143
6144
/* Check an instruction that takes three register operands and that
6145
   requires the register numbers to be distinct from one another.  */
6146
6147
static enum err_type
6148
verify_three_different_regs (const struct aarch64_inst *inst,
6149
           const aarch64_insn insn ATTRIBUTE_UNUSED,
6150
           bfd_vma pc ATTRIBUTE_UNUSED,
6151
           bool encoding ATTRIBUTE_UNUSED,
6152
           aarch64_operand_error *mismatch_detail
6153
             ATTRIBUTE_UNUSED,
6154
           aarch64_instr_sequence *insn_sequence
6155
             ATTRIBUTE_UNUSED)
6156
0
{
6157
0
  int rd, rs, rn;
6158
6159
0
  rd = inst->operands[0].reg.regno;
6160
0
  rs = inst->operands[1].reg.regno;
6161
0
  rn = inst->operands[2].reg.regno;
6162
0
  if (rd == rs || rd == rn || rs == rn)
6163
0
    {
6164
0
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6165
0
      mismatch_detail->error
6166
0
  = _("the three register operands must be distinct from one another");
6167
0
      mismatch_detail->index = -1;
6168
0
      return ERR_UND;
6169
0
    }
6170
6171
0
  return ERR_OK;
6172
0
}
6173
6174
/* Add INST to the end of INSN_SEQUENCE.  */
6175
6176
static void
6177
add_insn_to_sequence (const struct aarch64_inst *inst,
6178
          aarch64_instr_sequence *insn_sequence)
6179
0
{
6180
0
  insn_sequence->instr[insn_sequence->num_added_insns++] = *inst;
6181
0
}
6182
6183
/* Initialize an instruction sequence insn_sequence with the instruction INST.
6184
   If INST is NULL the given insn_sequence is cleared and the sequence is left
6185
   uninitialized.  */
6186
6187
void
6188
init_insn_sequence (const struct aarch64_inst *inst,
6189
        aarch64_instr_sequence *insn_sequence)
6190
0
{
6191
0
  int num_req_entries = 0;
6192
6193
0
  if (insn_sequence->instr)
6194
0
    {
6195
0
      XDELETE (insn_sequence->instr);
6196
0
      insn_sequence->instr = NULL;
6197
0
    }
6198
6199
  /* Handle all the cases here.  May need to think of something smarter than
6200
     a giant if/else chain if this grows.  At that time, a lookup table may be
6201
     best.  */
6202
0
  if (inst && inst->opcode->constraints & C_SCAN_MOVPRFX)
6203
0
    num_req_entries = 1;
6204
0
  if (inst && (inst->opcode->constraints & C_SCAN_MOPS_PME) == C_SCAN_MOPS_P)
6205
0
    num_req_entries = 2;
6206
6207
0
  insn_sequence->num_added_insns = 0;
6208
0
  insn_sequence->num_allocated_insns = num_req_entries;
6209
6210
0
  if (num_req_entries != 0)
6211
0
    {
6212
0
      insn_sequence->instr = XCNEWVEC (aarch64_inst, num_req_entries);
6213
0
      add_insn_to_sequence (inst, insn_sequence);
6214
0
    }
6215
0
}
6216
6217
/* Subroutine of verify_constraints.  Check whether the instruction
6218
   is part of a MOPS P/M/E sequence and, if so, whether sequencing
6219
   expectations are met.  Return true if the check passes, otherwise
6220
   describe the problem in MISMATCH_DETAIL.
6221
6222
   IS_NEW_SECTION is true if INST is assumed to start a new section.
6223
   The other arguments are as for verify_constraints.  */
6224
6225
static bool
6226
verify_mops_pme_sequence (const struct aarch64_inst *inst,
6227
        bool is_new_section,
6228
        aarch64_operand_error *mismatch_detail,
6229
        aarch64_instr_sequence *insn_sequence)
6230
0
{
6231
0
  const struct aarch64_opcode *opcode;
6232
0
  const struct aarch64_inst *prev_insn;
6233
0
  int i;
6234
6235
0
  opcode = inst->opcode;
6236
0
  if (insn_sequence->instr)
6237
0
    prev_insn = insn_sequence->instr + (insn_sequence->num_added_insns - 1);
6238
0
  else
6239
0
    prev_insn = NULL;
6240
6241
0
  if (prev_insn
6242
0
      && (prev_insn->opcode->constraints & C_SCAN_MOPS_PME)
6243
0
      && prev_insn->opcode != opcode - 1)
6244
0
    {
6245
0
      mismatch_detail->kind = AARCH64_OPDE_EXPECTED_A_AFTER_B;
6246
0
      mismatch_detail->error = NULL;
6247
0
      mismatch_detail->index = -1;
6248
0
      mismatch_detail->data[0].s = prev_insn->opcode[1].name;
6249
0
      mismatch_detail->data[1].s = prev_insn->opcode->name;
6250
0
      mismatch_detail->non_fatal = true;
6251
0
      return false;
6252
0
    }
6253
6254
0
  if (opcode->constraints & C_SCAN_MOPS_PME)
6255
0
    {
6256
0
      if (is_new_section || !prev_insn || prev_insn->opcode != opcode - 1)
6257
0
  {
6258
0
    mismatch_detail->kind = AARCH64_OPDE_A_SHOULD_FOLLOW_B;
6259
0
    mismatch_detail->error = NULL;
6260
0
    mismatch_detail->index = -1;
6261
0
    mismatch_detail->data[0].s = opcode->name;
6262
0
    mismatch_detail->data[1].s = opcode[-1].name;
6263
0
    mismatch_detail->non_fatal = true;
6264
0
    return false;
6265
0
  }
6266
6267
0
      for (i = 0; i < 3; ++i)
6268
  /* There's no specific requirement for the data register to be
6269
     the same between consecutive SET* instructions.  */
6270
0
  if ((opcode->operands[i] == AARCH64_OPND_MOPS_ADDR_Rd
6271
0
       || opcode->operands[i] == AARCH64_OPND_MOPS_ADDR_Rs
6272
0
       || opcode->operands[i] == AARCH64_OPND_MOPS_WB_Rn)
6273
0
      && prev_insn->operands[i].reg.regno != inst->operands[i].reg.regno)
6274
0
    {
6275
0
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6276
0
      if (opcode->operands[i] == AARCH64_OPND_MOPS_ADDR_Rd)
6277
0
        mismatch_detail->error = _("destination register differs from "
6278
0
           "preceding instruction");
6279
0
      else if (opcode->operands[i] == AARCH64_OPND_MOPS_ADDR_Rs)
6280
0
        mismatch_detail->error = _("source register differs from "
6281
0
           "preceding instruction");
6282
0
      else
6283
0
        mismatch_detail->error = _("size register differs from "
6284
0
           "preceding instruction");
6285
0
      mismatch_detail->index = i;
6286
0
      mismatch_detail->non_fatal = true;
6287
0
      return false;
6288
0
    }
6289
0
    }
6290
6291
0
  return true;
6292
0
}
6293
6294
/*  This function verifies that the instruction INST adheres to its specified
6295
    constraints.  If it does then ERR_OK is returned, if not then ERR_VFI is
6296
    returned and MISMATCH_DETAIL contains the reason why verification failed.
6297
6298
    The function is called both during assembly and disassembly.  If assembling
6299
    then ENCODING will be TRUE, else FALSE.  If dissassembling PC will be set
6300
    and will contain the PC of the current instruction w.r.t to the section.
6301
6302
    If ENCODING and PC=0 then you are at a start of a section.  The constraints
6303
    are verified against the given state insn_sequence which is updated as it
6304
    transitions through the verification.  */
6305
6306
enum err_type
6307
verify_constraints (const struct aarch64_inst *inst,
6308
        const aarch64_insn insn ATTRIBUTE_UNUSED,
6309
        bfd_vma pc,
6310
        bool encoding,
6311
        aarch64_operand_error *mismatch_detail,
6312
        aarch64_instr_sequence *insn_sequence)
6313
0
{
6314
0
  assert (inst);
6315
0
  assert (inst->opcode);
6316
6317
0
  const struct aarch64_opcode *opcode = inst->opcode;
6318
0
  if (!opcode->constraints && !insn_sequence->instr)
6319
0
    return ERR_OK;
6320
6321
0
  assert (insn_sequence);
6322
6323
0
  enum err_type res = ERR_OK;
6324
6325
  /* This instruction puts a constraint on the insn_sequence.  */
6326
0
  if (opcode->flags & F_SCAN)
6327
0
    {
6328
0
      if (insn_sequence->instr)
6329
0
  {
6330
0
    mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6331
0
    mismatch_detail->error = _("instruction opens new dependency "
6332
0
             "sequence without ending previous one");
6333
0
    mismatch_detail->index = -1;
6334
0
    mismatch_detail->non_fatal = true;
6335
0
    res = ERR_VFI;
6336
0
  }
6337
6338
0
      init_insn_sequence (inst, insn_sequence);
6339
0
      return res;
6340
0
    }
6341
6342
0
  bool is_new_section = (!encoding && pc == 0);
6343
0
  if (!verify_mops_pme_sequence (inst, is_new_section, mismatch_detail,
6344
0
         insn_sequence))
6345
0
    {
6346
0
      res = ERR_VFI;
6347
0
      if ((opcode->constraints & C_SCAN_MOPS_PME) != C_SCAN_MOPS_M)
6348
0
  init_insn_sequence (NULL, insn_sequence);
6349
0
    }
6350
6351
  /* Verify constraints on an existing sequence.  */
6352
0
  if (insn_sequence->instr)
6353
0
    {
6354
0
      const struct aarch64_opcode* inst_opcode = insn_sequence->instr->opcode;
6355
      /* If we're decoding and we hit PC=0 with an open sequence then we haven't
6356
   closed a previous one that we should have.  */
6357
0
      if (is_new_section && res == ERR_OK)
6358
0
  {
6359
0
    mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6360
0
    mismatch_detail->error = _("previous `movprfx' sequence not closed");
6361
0
    mismatch_detail->index = -1;
6362
0
    mismatch_detail->non_fatal = true;
6363
0
    res = ERR_VFI;
6364
    /* Reset the sequence.  */
6365
0
    init_insn_sequence (NULL, insn_sequence);
6366
0
    return res;
6367
0
  }
6368
6369
      /* Validate C_SCAN_MOVPRFX constraints.  Move this to a lookup table.  */
6370
0
      if (inst_opcode->constraints & C_SCAN_MOVPRFX)
6371
0
  {
6372
    /* Check to see if the MOVPRFX SVE instruction is followed by an SVE
6373
       instruction for better error messages.  */
6374
0
    if (!opcode->avariant
6375
0
        || !(*opcode->avariant &
6376
0
       (AARCH64_FEATURE_SVE | AARCH64_FEATURE_SVE2)))
6377
0
      {
6378
0
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6379
0
        mismatch_detail->error = _("SVE instruction expected after "
6380
0
           "`movprfx'");
6381
0
        mismatch_detail->index = -1;
6382
0
        mismatch_detail->non_fatal = true;
6383
0
        res = ERR_VFI;
6384
0
        goto done;
6385
0
      }
6386
6387
    /* Check to see if the MOVPRFX SVE instruction is followed by an SVE
6388
       instruction that is allowed to be used with a MOVPRFX.  */
6389
0
    if (!(opcode->constraints & C_SCAN_MOVPRFX))
6390
0
      {
6391
0
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6392
0
        mismatch_detail->error = _("SVE `movprfx' compatible instruction "
6393
0
           "expected");
6394
0
        mismatch_detail->index = -1;
6395
0
        mismatch_detail->non_fatal = true;
6396
0
        res = ERR_VFI;
6397
0
        goto done;
6398
0
      }
6399
6400
    /* Next check for usage of the predicate register.  */
6401
0
    aarch64_opnd_info blk_dest = insn_sequence->instr->operands[0];
6402
0
    aarch64_opnd_info blk_pred, inst_pred;
6403
0
    memset (&blk_pred, 0, sizeof (aarch64_opnd_info));
6404
0
    memset (&inst_pred, 0, sizeof (aarch64_opnd_info));
6405
0
    bool predicated = false;
6406
0
    assert (blk_dest.type == AARCH64_OPND_SVE_Zd);
6407
6408
    /* Determine if the movprfx instruction used is predicated or not.  */
6409
0
    if (insn_sequence->instr->operands[1].type == AARCH64_OPND_SVE_Pg3)
6410
0
      {
6411
0
        predicated = true;
6412
0
        blk_pred = insn_sequence->instr->operands[1];
6413
0
      }
6414
6415
0
    unsigned char max_elem_size = 0;
6416
0
    unsigned char current_elem_size;
6417
0
    int num_op_used = 0, last_op_usage = 0;
6418
0
    int i, inst_pred_idx = -1;
6419
0
    int num_ops = aarch64_num_of_operands (opcode);
6420
0
    for (i = 0; i < num_ops; i++)
6421
0
      {
6422
0
        aarch64_opnd_info inst_op = inst->operands[i];
6423
0
        switch (inst_op.type)
6424
0
    {
6425
0
      case AARCH64_OPND_SVE_Zd:
6426
0
      case AARCH64_OPND_SVE_Zm_5:
6427
0
      case AARCH64_OPND_SVE_Zm_16:
6428
0
      case AARCH64_OPND_SVE_Zn:
6429
0
      case AARCH64_OPND_SVE_Zt:
6430
0
      case AARCH64_OPND_SVE_Vm:
6431
0
      case AARCH64_OPND_SVE_Vn:
6432
0
      case AARCH64_OPND_Va:
6433
0
      case AARCH64_OPND_Vn:
6434
0
      case AARCH64_OPND_Vm:
6435
0
      case AARCH64_OPND_Sn:
6436
0
      case AARCH64_OPND_Sm:
6437
0
        if (inst_op.reg.regno == blk_dest.reg.regno)
6438
0
          {
6439
0
      num_op_used++;
6440
0
      last_op_usage = i;
6441
0
          }
6442
0
        current_elem_size
6443
0
          = aarch64_get_qualifier_esize (inst_op.qualifier);
6444
0
        if (current_elem_size > max_elem_size)
6445
0
          max_elem_size = current_elem_size;
6446
0
        break;
6447
0
      case AARCH64_OPND_SVE_Pd:
6448
0
      case AARCH64_OPND_SVE_Pg3:
6449
0
      case AARCH64_OPND_SVE_Pg4_5:
6450
0
      case AARCH64_OPND_SVE_Pg4_10:
6451
0
      case AARCH64_OPND_SVE_Pg4_16:
6452
0
      case AARCH64_OPND_SVE_Pm:
6453
0
      case AARCH64_OPND_SVE_Pn:
6454
0
      case AARCH64_OPND_SVE_Pt:
6455
0
      case AARCH64_OPND_SME_Pm:
6456
0
        inst_pred = inst_op;
6457
0
        inst_pred_idx = i;
6458
0
        break;
6459
0
      default:
6460
0
        break;
6461
0
    }
6462
0
      }
6463
6464
0
     assert (max_elem_size != 0);
6465
0
     aarch64_opnd_info inst_dest = inst->operands[0];
6466
     /* Determine the size that should be used to compare against the
6467
        movprfx size.  */
6468
0
     current_elem_size
6469
0
       = opcode->constraints & C_MAX_ELEM
6470
0
         ? max_elem_size
6471
0
         : aarch64_get_qualifier_esize (inst_dest.qualifier);
6472
6473
    /* If movprfx is predicated do some extra checks.  */
6474
0
    if (predicated)
6475
0
      {
6476
        /* The instruction must be predicated.  */
6477
0
        if (inst_pred_idx < 0)
6478
0
    {
6479
0
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6480
0
      mismatch_detail->error = _("predicated instruction expected "
6481
0
               "after `movprfx'");
6482
0
      mismatch_detail->index = -1;
6483
0
      mismatch_detail->non_fatal = true;
6484
0
      res = ERR_VFI;
6485
0
      goto done;
6486
0
    }
6487
6488
        /* The instruction must have a merging predicate.  */
6489
0
        if (inst_pred.qualifier != AARCH64_OPND_QLF_P_M)
6490
0
    {
6491
0
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6492
0
      mismatch_detail->error = _("merging predicate expected due "
6493
0
               "to preceding `movprfx'");
6494
0
      mismatch_detail->index = inst_pred_idx;
6495
0
      mismatch_detail->non_fatal = true;
6496
0
      res = ERR_VFI;
6497
0
      goto done;
6498
0
    }
6499
6500
        /* The same register must be used in instruction.  */
6501
0
        if (blk_pred.reg.regno != inst_pred.reg.regno)
6502
0
    {
6503
0
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6504
0
      mismatch_detail->error = _("predicate register differs "
6505
0
               "from that in preceding "
6506
0
               "`movprfx'");
6507
0
      mismatch_detail->index = inst_pred_idx;
6508
0
      mismatch_detail->non_fatal = true;
6509
0
      res = ERR_VFI;
6510
0
      goto done;
6511
0
    }
6512
0
      }
6513
6514
    /* Destructive operations by definition must allow one usage of the
6515
       same register.  */
6516
0
    int allowed_usage
6517
0
      = aarch64_is_destructive_by_operands (opcode) ? 2 : 1;
6518
6519
    /* Operand is not used at all.  */
6520
0
    if (num_op_used == 0)
6521
0
      {
6522
0
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6523
0
        mismatch_detail->error = _("output register of preceding "
6524
0
           "`movprfx' not used in current "
6525
0
           "instruction");
6526
0
        mismatch_detail->index = 0;
6527
0
        mismatch_detail->non_fatal = true;
6528
0
        res = ERR_VFI;
6529
0
        goto done;
6530
0
      }
6531
6532
    /* We now know it's used, now determine exactly where it's used.  */
6533
0
    if (blk_dest.reg.regno != inst_dest.reg.regno)
6534
0
      {
6535
0
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6536
0
        mismatch_detail->error = _("output register of preceding "
6537
0
           "`movprfx' expected as output");
6538
0
        mismatch_detail->index = 0;
6539
0
        mismatch_detail->non_fatal = true;
6540
0
        res = ERR_VFI;
6541
0
        goto done;
6542
0
      }
6543
6544
    /* Operand used more than allowed for the specific opcode type.  */
6545
0
    if (num_op_used > allowed_usage)
6546
0
      {
6547
0
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6548
0
        mismatch_detail->error = _("output register of preceding "
6549
0
           "`movprfx' used as input");
6550
0
        mismatch_detail->index = last_op_usage;
6551
0
        mismatch_detail->non_fatal = true;
6552
0
        res = ERR_VFI;
6553
0
        goto done;
6554
0
      }
6555
6556
    /* Now the only thing left is the qualifiers checks.  The register
6557
       must have the same maximum element size.  */
6558
0
    if (inst_dest.qualifier
6559
0
        && blk_dest.qualifier
6560
0
        && current_elem_size
6561
0
     != aarch64_get_qualifier_esize (blk_dest.qualifier))
6562
0
      {
6563
0
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6564
0
        mismatch_detail->error = _("register size not compatible with "
6565
0
           "previous `movprfx'");
6566
0
        mismatch_detail->index = 0;
6567
0
        mismatch_detail->non_fatal = true;
6568
0
        res = ERR_VFI;
6569
0
        goto done;
6570
0
      }
6571
0
  }
6572
6573
0
    done:
6574
0
      if (insn_sequence->num_added_insns == insn_sequence->num_allocated_insns)
6575
  /* We've checked the last instruction in the sequence and so
6576
     don't need the sequence any more.  */
6577
0
  init_insn_sequence (NULL, insn_sequence);
6578
0
      else
6579
0
  add_insn_to_sequence (inst, insn_sequence);
6580
0
    }
6581
6582
0
  return res;
6583
0
}
6584
6585
6586
/* Return true if VALUE cannot be moved into an SVE register using DUP
6587
   (with any element size, not just ESIZE) and if using DUPM would
6588
   therefore be OK.  ESIZE is the number of bytes in the immediate.  */
6589
6590
bool
6591
aarch64_sve_dupm_mov_immediate_p (uint64_t uvalue, int esize)
6592
0
{
6593
0
  int64_t svalue = uvalue;
6594
0
  uint64_t upper = (uint64_t) -1 << (esize * 4) << (esize * 4);
6595
6596
0
  if ((uvalue & ~upper) != uvalue && (uvalue | upper) != uvalue)
6597
0
    return false;
6598
0
  if (esize <= 4 || (uint32_t) uvalue == (uint32_t) (uvalue >> 32))
6599
0
    {
6600
0
      svalue = (int32_t) uvalue;
6601
0
      if (esize <= 2 || (uint16_t) uvalue == (uint16_t) (uvalue >> 16))
6602
0
  {
6603
0
    svalue = (int16_t) uvalue;
6604
0
    if (esize == 1 || (uint8_t) uvalue == (uint8_t) (uvalue >> 8))
6605
0
      return false;
6606
0
  }
6607
0
    }
6608
0
  if ((svalue & 0xff) == 0)
6609
0
    svalue /= 256;
6610
0
  return svalue < -128 || svalue >= 128;
6611
0
}
6612
6613
/* Return true if a CPU with the AARCH64_FEATURE_* bits in CPU_VARIANT
6614
   supports the instruction described by INST.  */
6615
6616
bool
6617
aarch64_cpu_supports_inst_p (uint64_t cpu_variant, aarch64_inst *inst)
6618
0
{
6619
0
  if (!inst->opcode->avariant
6620
0
      || !AARCH64_CPU_HAS_ALL_FEATURES (cpu_variant, *inst->opcode->avariant))
6621
0
    return false;
6622
6623
0
  if (inst->opcode->iclass == sme_fp_sd
6624
0
      && inst->operands[0].qualifier == AARCH64_OPND_QLF_S_D
6625
0
      && !AARCH64_CPU_HAS_ALL_FEATURES (cpu_variant,
6626
0
          AARCH64_FEATURE_SME_F64F64))
6627
0
    return false;
6628
6629
0
  if (inst->opcode->iclass == sme_int_sd
6630
0
      && inst->operands[0].qualifier == AARCH64_OPND_QLF_S_D
6631
0
      && !AARCH64_CPU_HAS_ALL_FEATURES (cpu_variant,
6632
0
          AARCH64_FEATURE_SME_I16I64))
6633
0
    return false;
6634
6635
0
  return true;
6636
0
}
6637
6638
/* Include the opcode description table as well as the operand description
6639
   table.  */
6640
#define VERIFIER(x) verify_##x
6641
#include "aarch64-tbl.h"