Coverage Report

Created: 2023-08-28 06:31

/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
926k
{
126
926k
  return (qualifier >= AARCH64_OPND_QLF_V_8B
127
926k
    && qualifier <= AARCH64_OPND_QLF_V_1Q);
128
926k
}
129
130
static inline bool
131
fp_qualifier_p (enum aarch64_opnd_qualifier qualifier)
132
311
{
133
311
  return (qualifier >= AARCH64_OPND_QLF_S_B
134
311
    && qualifier <= AARCH64_OPND_QLF_S_Q);
135
311
}
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
395k
{
163
395k
  if (vector_qualifier_p (qualifiers[0]))
164
395k
    {
165
      /* e.g. v.4s, v.4s, v.4s
166
     or v.4h, v.4h, v.h[3].  */
167
395k
      if (qualifiers[0] == qualifiers[1]
168
395k
    && vector_qualifier_p (qualifiers[2])
169
395k
    && (aarch64_get_qualifier_esize (qualifiers[0])
170
120k
        == aarch64_get_qualifier_esize (qualifiers[1]))
171
395k
    && (aarch64_get_qualifier_esize (qualifiers[0])
172
120k
        == aarch64_get_qualifier_esize (qualifiers[2])))
173
116k
  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
278k
      if (vector_qualifier_p (qualifiers[1])
178
278k
    && aarch64_get_qualifier_esize (qualifiers[0]) != 0
179
278k
    && (aarch64_get_qualifier_esize (qualifiers[0])
180
171k
        == aarch64_get_qualifier_esize (qualifiers[1]) << 1))
181
70.6k
  return DP_VECTOR_LONG;
182
      /* e.g. v.8h, v.8h, v.8b.  */
183
208k
      if (qualifiers[0] == qualifiers[1]
184
208k
    && vector_qualifier_p (qualifiers[2])
185
208k
    && aarch64_get_qualifier_esize (qualifiers[0]) != 0
186
208k
    && (aarch64_get_qualifier_esize (qualifiers[0])
187
4.60k
        == aarch64_get_qualifier_esize (qualifiers[2]) << 1)
188
208k
    && (aarch64_get_qualifier_esize (qualifiers[0])
189
4.60k
        == aarch64_get_qualifier_esize (qualifiers[1])))
190
4.60k
  return DP_VECTOR_WIDE;
191
208k
    }
192
311
  else if (fp_qualifier_p (qualifiers[0]))
193
311
    {
194
      /* e.g. SADDLV <V><d>, <Vn>.<T>.  */
195
311
      if (vector_qualifier_p (qualifiers[1])
196
311
    && qualifiers[2] == AARCH64_OPND_QLF_NIL)
197
285
  return DP_VECTOR_ACROSS_LANES;
198
311
    }
199
200
203k
  return DP_UNKNOWN;
201
395k
}
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
395k
{
214
395k
  return
215
395k
    significant_operand_index [get_data_pattern (opcode->qualifiers_list[0])];
216
395k
}
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
4.15M
{
406
4.15M
  return aarch64_operands[type].op_class;
407
4.15M
}
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
111k
{
447
111k
  assert (value < 16);
448
111k
  return &aarch64_conds[(unsigned int) value];
449
111k
}
450
451
const aarch64_cond *
452
get_inverted_cond (const aarch64_cond *cond)
453
966
{
454
966
  return &aarch64_conds[cond->value ^ 0x1];
455
966
}
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
1.11M
{
499
1.11M
  if (extend_p)
500
135k
    return AARCH64_MOD_UXTB + value;
501
978k
  else
502
978k
    return AARCH64_MOD_LSL - value;
503
1.11M
}
504
505
bool
506
aarch64_extend_operator_p (enum aarch64_modifier_kind kind)
507
72.4k
{
508
72.4k
  return kind > AARCH64_MOD_LSL && kind <= AARCH64_MOD_SXTX;
509
72.4k
}
510
511
static inline bool
512
aarch64_shift_operator_p (enum aarch64_modifier_kind kind)
513
932k
{
514
932k
  return kind >= AARCH64_MOD_ROR && kind <= AARCH64_MOD_LSL;
515
932k
}
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
4.04M
{
609
4.04M
  return (value >= low && value <= high) ? 1 : 0;
610
4.04M
}
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
2.93M
{
616
2.93M
  return (value % align) == 0;
617
2.93M
}
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
1.83M
{
623
1.83M
  assert (width < 32);
624
1.83M
  if (width < sizeof (value) * 8)
625
1.83M
    {
626
1.83M
      int64_t lim = (uint64_t) 1 << (width - 1);
627
1.83M
      if (value >= -lim && value < lim)
628
1.83M
  return 1;
629
1.83M
    }
630
0
  return 0;
631
1.83M
}
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
2.66M
{
637
2.66M
  assert (width < 32);
638
2.66M
  if (width < sizeof (value) * 8)
639
2.66M
    {
640
2.66M
      int64_t lim = (uint64_t) 1 << width;
641
2.66M
      if (value >= 0 && value < lim)
642
2.66M
  return 1;
643
2.66M
    }
644
0
  return 0;
645
2.66M
}
646
647
/* Return 1 if OPERAND is SP or WSP.  */
648
int
649
aarch64_stack_pointer_p (const aarch64_opnd_info *operand)
650
226k
{
651
226k
  return ((aarch64_get_operand_class (operand->type)
652
226k
     == AARCH64_OPND_CLASS_INT_REG)
653
226k
    && operand_maybe_stack_pointer (aarch64_operands + operand->type)
654
226k
    && operand->reg.regno == 31);
655
226k
}
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
6.91M
{
675
6.91M
  switch (operand->qualifier)
676
6.91M
    {
677
5.17k
    case AARCH64_OPND_QLF_W:
678
5.17k
      if (target == AARCH64_OPND_QLF_WSP && aarch64_stack_pointer_p (operand))
679
423
  return 1;
680
4.75k
      break;
681
1.92M
    case AARCH64_OPND_QLF_X:
682
1.92M
      if (target == AARCH64_OPND_QLF_SP && aarch64_stack_pointer_p (operand))
683
177
  return 1;
684
1.92M
      break;
685
1.92M
    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
4.98M
    default:
696
4.98M
      break;
697
6.91M
    }
698
699
6.91M
  return 0;
700
6.91M
}
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
16.4M
{
837
16.4M
  return aarch64_opnd_qualifiers[qualifier].kind == OQK_OPD_VARIANT;
838
16.4M
}
839
840
static inline bool
841
qualifier_value_in_range_constraint_p (aarch64_opnd_qualifier_t qualifier)
842
5.97M
{
843
5.97M
  return aarch64_opnd_qualifiers[qualifier].kind == OQK_VALUE_IN_RANGE;
844
5.97M
}
845
846
const char*
847
aarch64_get_qualifier_name (aarch64_opnd_qualifier_t qualifier)
848
4.97M
{
849
4.97M
  return aarch64_opnd_qualifiers[qualifier].desc;
850
4.97M
}
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
11.7M
{
857
11.7M
  assert (operand_variant_qualifier_p (qualifier));
858
11.7M
  return aarch64_opnd_qualifiers[qualifier].data0;
859
11.7M
}
860
861
unsigned char
862
aarch64_get_qualifier_nelem (aarch64_opnd_qualifier_t qualifier)
863
97.8k
{
864
97.8k
  assert (operand_variant_qualifier_p (qualifier));
865
97.8k
  return aarch64_opnd_qualifiers[qualifier].data1;
866
97.8k
}
867
868
aarch64_insn
869
aarch64_get_qualifier_standard_value (aarch64_opnd_qualifier_t qualifier)
870
4.64M
{
871
4.64M
  assert (operand_variant_qualifier_p (qualifier));
872
4.64M
  return aarch64_opnd_qualifiers[qualifier].data2;
873
4.64M
}
874
875
static int
876
get_lower_bound (aarch64_opnd_qualifier_t qualifier)
877
870k
{
878
870k
  assert (qualifier_value_in_range_constraint_p (qualifier));
879
870k
  return aarch64_opnd_qualifiers[qualifier].data0;
880
870k
}
881
882
static int
883
get_upper_bound (aarch64_opnd_qualifier_t qualifier)
884
953k
{
885
953k
  assert (qualifier_value_in_range_constraint_p (qualifier));
886
953k
  return aarch64_opnd_qualifiers[qualifier].data1;
887
953k
}
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
22
{
933
22
  int i = 0;
934
22
  const enum aarch64_opnd *opnds = opcode->operands;
935
936
22
  if (opnds[0] == AARCH64_OPND_NIL)
937
0
    return false;
938
939
72
  while (opnds[++i] != AARCH64_OPND_NIL)
940
58
    if (opnds[i] == opnds[0])
941
8
      return true;
942
943
14
  return false;
944
22
}
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
12.9M
{
952
12.9M
  int i = 0;
953
12.9M
  const enum aarch64_opnd *opnds = opcode->operands;
954
44.9M
  while (opnds[i++] != AARCH64_OPND_NIL)
955
32.0M
    ;
956
12.9M
  --i;
957
12.9M
  assert (i >= 0 && i <= AARCH64_MAX_OPND_NUM);
958
12.9M
  return i;
959
12.9M
}
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
11.5M
{
992
11.5M
  int i, num_opnds, invalid, min_invalid;
993
11.5M
  const aarch64_opnd_qualifier_t *qualifiers;
994
995
11.5M
  num_opnds = aarch64_num_of_operands (inst->opcode);
996
11.5M
  if (num_opnds == 0)
997
4
    {
998
4
      DEBUG_TRACE ("SUCCEED: no operand");
999
4
      *invalid_count = 0;
1000
4
      return 1;
1001
4
    }
1002
1003
11.5M
  if (stop_at < 0 || stop_at >= num_opnds)
1004
10.0M
    stop_at = num_opnds - 1;
1005
1006
  /* For each pattern.  */
1007
11.5M
  min_invalid = num_opnds;
1008
16.6M
  for (i = 0; i < AARCH64_MAX_QLF_SEQ_NUM; ++i, ++qualifiers_list)
1009
16.6M
    {
1010
16.6M
      int j;
1011
16.6M
      qualifiers = *qualifiers_list;
1012
1013
      /* Start as positive.  */
1014
16.6M
      invalid = 0;
1015
1016
16.6M
      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
16.6M
      if (i > 0 && empty_qualifier_sequence_p (qualifiers))
1026
84.4k
  break;
1027
1028
57.7M
      for (j = 0; j < num_opnds && j <= stop_at; ++j, ++qualifiers)
1029
41.2M
  {
1030
41.2M
    if (inst->operands[j].qualifier == AARCH64_OPND_QLF_NIL
1031
41.2M
        && !(inst->opcode->flags & F_STRICT))
1032
22.1M
      {
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
22.1M
        continue;
1040
22.1M
      }
1041
19.0M
    else if (*qualifiers != inst->operands[j].qualifier)
1042
6.91M
      {
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
6.91M
        if (operand_also_qualified_p (inst->operands + j, *qualifiers))
1047
600
    continue;
1048
6.91M
        else
1049
6.91M
    invalid += 1;
1050
6.91M
      }
1051
12.1M
    else
1052
12.1M
      continue; /* Equal qualifiers are certainly matched.  */
1053
41.2M
  }
1054
1055
16.5M
      if (min_invalid > invalid)
1056
14.6M
  min_invalid = invalid;
1057
1058
      /* Qualifiers established.  */
1059
16.5M
      if (min_invalid == 0)
1060
11.4M
  break;
1061
16.5M
    }
1062
1063
11.5M
  *invalid_count = min_invalid;
1064
11.5M
  if (min_invalid == 0)
1065
11.4M
    {
1066
      /* Fill the result in *RET.  */
1067
11.4M
      int j;
1068
11.4M
      qualifiers = *qualifiers_list;
1069
1070
11.4M
      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
38.8M
      for (j = 0; j <= stop_at; ++j, ++qualifiers)
1077
27.3M
  ret[j] = *qualifiers;
1078
52.9M
      for (; j < AARCH64_MAX_OPND_NUM; ++j)
1079
41.5M
  ret[j] = AARCH64_OPND_QLF_NIL;
1080
1081
11.4M
      DEBUG_TRACE ("SUCCESS");
1082
11.4M
      return 1;
1083
11.4M
    }
1084
1085
84.4k
  DEBUG_TRACE ("FAIL");
1086
84.4k
  return 0;
1087
11.5M
}
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
10.0M
{
1104
10.0M
  int i;
1105
10.0M
  aarch64_opnd_qualifier_seq_t qualifiers;
1106
1107
10.0M
  if (!aarch64_find_best_match (inst, inst->opcode->qualifiers_list, -1,
1108
10.0M
        qualifiers, invalid_count))
1109
48.3k
    {
1110
48.3k
      DEBUG_TRACE ("matching FAIL");
1111
48.3k
      return 0;
1112
48.3k
    }
1113
1114
  /* Update the qualifiers.  */
1115
9.97M
  if (update_p)
1116
33.5M
    for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
1117
33.5M
      {
1118
33.5M
  if (inst->opcode->operands[i] == AARCH64_OPND_NIL)
1119
9.97M
    break;
1120
23.5M
  DEBUG_TRACE_IF (inst->operands[i].qualifier != qualifiers[i],
1121
23.5M
      "update %s with %s for operand %d",
1122
23.5M
      aarch64_get_qualifier_name (inst->operands[i].qualifier),
1123
23.5M
      aarch64_get_qualifier_name (qualifiers[i]), i);
1124
23.5M
  inst->operands[i].qualifier = qualifiers[i];
1125
23.5M
      }
1126
1127
9.97M
  DEBUG_TRACE ("matching SUCCESS");
1128
9.97M
  return 1;
1129
10.0M
}
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
180k
{
1141
180k
  int amount;
1142
1143
180k
  DEBUG_TRACE ("enter with 0x%" PRIx64 "(%" PRIi64 ")", value, value);
1144
1145
180k
  if (is32)
1146
49.6k
    {
1147
      /* Allow all zeros or all ones in top 32-bits, so that
1148
   32-bit constant expressions like ~0x80000000 are
1149
   permitted.  */
1150
49.6k
      if (value >> 32 != 0 && value >> 32 != 0xffffffff)
1151
  /* Immediate out of range.  */
1152
0
  return false;
1153
49.6k
      value &= 0xffffffff;
1154
49.6k
    }
1155
1156
  /* first, try movz then movn */
1157
180k
  amount = -1;
1158
180k
  if ((value & ((uint64_t) 0xffff << 0)) == value)
1159
66.7k
    amount = 0;
1160
113k
  else if ((value & ((uint64_t) 0xffff << 16)) == value)
1161
21.4k
    amount = 16;
1162
92.3k
  else if (!is32 && (value & ((uint64_t) 0xffff << 32)) == value)
1163
14.2k
    amount = 32;
1164
78.1k
  else if (!is32 && (value & ((uint64_t) 0xffff << 48)) == value)
1165
11.2k
    amount = 48;
1166
1167
180k
  if (amount == -1)
1168
66.8k
    {
1169
66.8k
      DEBUG_TRACE ("exit false with 0x%" PRIx64 "(%" PRIi64 ")", value, value);
1170
66.8k
      return false;
1171
66.8k
    }
1172
1173
113k
  if (shift_amount != NULL)
1174
0
    *shift_amount = amount;
1175
1176
113k
  DEBUG_TRACE ("exit true with amount %d", amount);
1177
1178
113k
  return true;
1179
180k
}
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
402k
#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
4.74M
{
1213
4.74M
  const simd_imm_encoding *imm1 = (const simd_imm_encoding *)i1;
1214
4.74M
  const simd_imm_encoding *imm2 = (const simd_imm_encoding *)i2;
1215
1216
4.74M
  if (imm1->imm < imm2->imm)
1217
2.36M
    return -1;
1218
2.37M
  if (imm1->imm > imm2->imm)
1219
1.97M
    return +1;
1220
402k
  return 0;
1221
2.37M
}
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
10.6k
{
1234
10.6k
  return (is64 << 12) | (r << 6) | s;
1235
10.6k
}
1236
1237
static void
1238
build_immediate_table (void)
1239
2
{
1240
2
  uint32_t log_e, e, s, r, s_mask;
1241
2
  uint64_t mask, imm;
1242
2
  int nb_imms;
1243
2
  int is64;
1244
1245
2
  nb_imms = 0;
1246
14
  for (log_e = 1; log_e <= 6; log_e++)
1247
12
    {
1248
      /* Get element size.  */
1249
12
      e = 1u << log_e;
1250
12
      if (log_e == 6)
1251
2
  {
1252
2
    is64 = 1;
1253
2
    mask = 0xffffffffffffffffull;
1254
2
    s_mask = 0;
1255
2
  }
1256
10
      else
1257
10
  {
1258
10
    is64 = 0;
1259
10
    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
10
    s_mask = ((1u << (5 - log_e)) - 1) << (log_e + 1);
1267
10
  }
1268
252
      for (s = 0; s < e - 1; s++)
1269
10.9k
  for (r = 0; r < e; r++)
1270
10.6k
    {
1271
      /* s+1 consecutive bits to 1 (s < 63) */
1272
10.6k
      imm = (1ull << (s + 1)) - 1;
1273
      /* rotate right by r */
1274
10.6k
      if (r != 0)
1275
10.4k
        imm = (imm >> r) | ((imm << (e - r)) & mask);
1276
      /* replicate the constant depending on SIMD size */
1277
10.6k
      switch (log_e)
1278
10.6k
        {
1279
4
        case 1: imm = (imm <<  2) | imm;
1280
    /* Fall through.  */
1281
28
        case 2: imm = (imm <<  4) | imm;
1282
    /* Fall through.  */
1283
140
        case 3: imm = (imm <<  8) | imm;
1284
    /* Fall through.  */
1285
620
        case 4: imm = (imm << 16) | imm;
1286
    /* Fall through.  */
1287
2.60k
        case 5: imm = (imm << 32) | imm;
1288
    /* Fall through.  */
1289
10.6k
        case 6: break;
1290
0
        default: abort ();
1291
10.6k
        }
1292
10.6k
      simd_immediates[nb_imms].imm = imm;
1293
10.6k
      simd_immediates[nb_imms].encoding =
1294
10.6k
        encode_immediate_bitfield(is64, s | s_mask, r);
1295
10.6k
      nb_imms++;
1296
10.6k
    }
1297
12
    }
1298
2
  assert (nb_imms == TOTAL_IMM_NB);
1299
2
  qsort(simd_immediates, nb_imms,
1300
2
  sizeof(simd_immediates[0]), simd_imm_encoding_cmp);
1301
2
}
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
402k
{
1314
402k
  simd_imm_encoding imm_enc;
1315
402k
  const simd_imm_encoding *imm_encoding;
1316
402k
  static bool initialized = false;
1317
402k
  uint64_t upper;
1318
402k
  int i;
1319
1320
402k
  DEBUG_TRACE ("enter with 0x%" PRIx64 "(%" PRIi64 "), esize: %d", value,
1321
402k
         value, esize);
1322
1323
402k
  if (!initialized)
1324
2
    {
1325
2
      build_immediate_table ();
1326
2
      initialized = true;
1327
2
    }
1328
1329
  /* Allow all zeros or all ones in top bits, so that
1330
     constant expressions like ~1 are permitted.  */
1331
402k
  upper = (uint64_t) -1 << (esize * 4) << (esize * 4);
1332
402k
  if ((value & ~upper) != value && (value | upper) != value)
1333
0
    return false;
1334
1335
  /* Replicate to a full 64-bit value.  */
1336
402k
  value &= ~upper;
1337
646k
  for (i = esize * 8; i < 64; i *= 2)
1338
243k
    value |= (value << i);
1339
1340
402k
  imm_enc.imm = value;
1341
402k
  imm_encoding = (const simd_imm_encoding *)
1342
402k
    bsearch(&imm_enc, simd_immediates, TOTAL_IMM_NB,
1343
402k
            sizeof(simd_immediates[0]), simd_imm_encoding_cmp);
1344
402k
  if (imm_encoding == NULL)
1345
0
    {
1346
0
      DEBUG_TRACE ("exit with false");
1347
0
      return false;
1348
0
    }
1349
402k
  if (encoding != NULL)
1350
0
    *encoding = imm_encoding->encoding;
1351
402k
  DEBUG_TRACE ("exit with true");
1352
402k
  return true;
1353
402k
}
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
67
{
1362
67
  int i, ret;
1363
67
  uint32_t byte;
1364
1365
67
  ret = 0;
1366
603
  for (i = 0; i < 8; i++)
1367
536
    {
1368
536
      byte = (imm >> (8 * i)) & 0xff;
1369
536
      if (byte == 0xff)
1370
254
  ret |= 1 << i;
1371
282
      else if (byte != 0x00)
1372
0
  return -1;
1373
536
    }
1374
67
  return ret;
1375
67
}
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
1.55k
{
1395
1.55k
  if (mismatch_detail == NULL)
1396
1.55k
    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
110k
{
1428
110k
  if (mismatch_detail == NULL)
1429
110k
    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
1.11k
{
1458
1.11k
  if (mismatch_detail == NULL)
1459
1.11k
    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
181k
{
1468
181k
  if (mismatch_detail == NULL)
1469
181k
    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
874
{
1500
874
  if (mismatch_detail == NULL)
1501
874
    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
41.7k
{
1530
41.7k
  if (mismatch_detail == NULL)
1531
41.7k
    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
42.4k
{
1545
42.4k
  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
42.4k
  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
42.4k
  return true;
1558
42.4k
}
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
475k
{
1568
475k
  if (opnd->reglist.num_regs != num_regs)
1569
874
    {
1570
874
      set_reg_list_length_error (mismatch_detail, idx, num_regs);
1571
874
      return false;
1572
874
    }
1573
474k
  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
474k
  return true;
1579
474k
}
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
88.2k
{
1598
88.2k
  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
88.2k
  int max_index = max_value * range_size;
1614
88.2k
  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
88.2k
  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
88.2k
  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
88.2k
  if (opnd->indexed_za.group_size != 0
1649
88.2k
      && 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
88.2k
  return true;
1656
88.2k
}
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
23.4M
{
1680
23.4M
  unsigned num, modifiers, shift;
1681
23.4M
  unsigned char size;
1682
23.4M
  int64_t imm, min_value, max_value;
1683
23.4M
  uint64_t uvalue, mask;
1684
23.4M
  const aarch64_opnd_info *opnd = opnds + idx;
1685
23.4M
  aarch64_opnd_qualifier_t qualifier = opnd->qualifier;
1686
23.4M
  int i;
1687
1688
23.4M
  assert (opcode->operands[idx] == opnd->type && opnd->type == type);
1689
1690
23.4M
  switch (aarch64_operands[type].op_class)
1691
23.4M
    {
1692
8.36M
    case AARCH64_OPND_CLASS_INT_REG:
1693
      /* Check pair reg constraints for cas* instructions.  */
1694
8.36M
      if (type == AARCH64_OPND_PAIRREG)
1695
3.65k
  {
1696
3.65k
    assert (idx == 1 || idx == 3);
1697
3.65k
    if (opnds[idx - 1].reg.regno % 2 != 0)
1698
1.55k
      {
1699
1.55k
        set_syntax_error (mismatch_detail, idx - 1,
1700
1.55k
        _("reg pair must start from even reg"));
1701
1.55k
        return 0;
1702
1.55k
      }
1703
2.10k
    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
2.10k
    break;
1710
2.10k
  }
1711
1712
      /* <Xt> may be optional in some IC and TLBI instructions.  */
1713
8.36M
      if (type == AARCH64_OPND_Rt_SYS)
1714
262
  {
1715
262
    assert (idx == 1 && (aarch64_get_operand_class (opnds[0].type)
1716
262
             == AARCH64_OPND_CLASS_SYSTEM));
1717
262
    if (opnds[1].present
1718
262
        && !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
262
    if (!opnds[1].present
1724
262
        && 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
262
  }
1730
8.36M
      switch (qualifier)
1731
8.36M
  {
1732
2.94k
  case AARCH64_OPND_QLF_WSP:
1733
6.52k
  case AARCH64_OPND_QLF_SP:
1734
6.52k
    if (!aarch64_stack_pointer_p (opnd))
1735
3.70k
      {
1736
3.70k
        set_other_error (mismatch_detail, idx,
1737
3.70k
           _("stack pointer register expected"));
1738
3.70k
        return 0;
1739
3.70k
      }
1740
2.81k
    break;
1741
8.35M
  default:
1742
8.35M
    break;
1743
8.36M
  }
1744
8.36M
      break;
1745
1746
8.36M
    case AARCH64_OPND_CLASS_SVE_REG:
1747
1.44M
      switch (type)
1748
1.44M
  {
1749
4.35k
  case AARCH64_OPND_SVE_Zm3_INDEX:
1750
7.90k
  case AARCH64_OPND_SVE_Zm3_22_INDEX:
1751
8.13k
  case AARCH64_OPND_SVE_Zm3_19_INDEX:
1752
16.0k
  case AARCH64_OPND_SVE_Zm3_11_INDEX:
1753
21.4k
  case AARCH64_OPND_SVE_Zm4_11_INDEX:
1754
26.1k
  case AARCH64_OPND_SVE_Zm4_INDEX:
1755
26.1k
    size = get_operand_fields_width (get_operand_from_code (type));
1756
26.1k
    shift = get_operand_specific_data (&aarch64_operands[type]);
1757
26.1k
    if (!check_reglane (opnd, mismatch_detail, idx,
1758
26.1k
            "z", 0, (1 << shift) - 1,
1759
26.1k
            0, (1u << (size - shift)) - 1))
1760
0
      return 0;
1761
26.1k
    break;
1762
1763
26.1k
  case AARCH64_OPND_SVE_Zn_INDEX:
1764
1.71k
    size = aarch64_get_qualifier_esize (opnd->qualifier);
1765
1.71k
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 31,
1766
1.71k
            0, 64 / size - 1))
1767
0
      return 0;
1768
1.71k
    break;
1769
1770
1.71k
  case AARCH64_OPND_SME_PNn3_INDEX1:
1771
15
  case AARCH64_OPND_SME_PNn3_INDEX2:
1772
15
    size = get_operand_field_width (get_operand_from_code (type), 1);
1773
15
    if (!check_reglane (opnd, mismatch_detail, idx, "pn", 8, 15,
1774
15
            0, (1 << size) - 1))
1775
0
      return 0;
1776
15
    break;
1777
1778
15
  case AARCH64_OPND_SME_Zn_INDEX1_16:
1779
18
  case AARCH64_OPND_SME_Zn_INDEX2_15:
1780
22
  case AARCH64_OPND_SME_Zn_INDEX2_16:
1781
30
  case AARCH64_OPND_SME_Zn_INDEX3_14:
1782
139
  case AARCH64_OPND_SME_Zn_INDEX3_15:
1783
185
  case AARCH64_OPND_SME_Zn_INDEX4_14:
1784
185
    size = get_operand_fields_width (get_operand_from_code (type)) - 5;
1785
185
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 31,
1786
185
            0, (1 << size) - 1))
1787
0
      return 0;
1788
185
    break;
1789
1790
186
  case AARCH64_OPND_SME_Zm_INDEX1:
1791
1.59k
  case AARCH64_OPND_SME_Zm_INDEX2:
1792
2.30k
  case AARCH64_OPND_SME_Zm_INDEX3_1:
1793
4.22k
  case AARCH64_OPND_SME_Zm_INDEX3_2:
1794
10.1k
  case AARCH64_OPND_SME_Zm_INDEX3_10:
1795
11.0k
  case AARCH64_OPND_SME_Zm_INDEX4_1:
1796
14.4k
  case AARCH64_OPND_SME_Zm_INDEX4_10:
1797
14.4k
    size = get_operand_fields_width (get_operand_from_code (type)) - 4;
1798
14.4k
    if (!check_reglane (opnd, mismatch_detail, idx, "z", 0, 15,
1799
14.4k
            0, (1 << size) - 1))
1800
0
      return 0;
1801
14.4k
    break;
1802
1803
14.4k
  case AARCH64_OPND_SME_Zm:
1804
3.61k
    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
3.61k
    break;
1810
1811
3.61k
  case AARCH64_OPND_SME_PnT_Wm_imm:
1812
1.81k
    size = aarch64_get_qualifier_esize (opnd->qualifier);
1813
1.81k
    max_value = 16 / size - 1;
1814
1.81k
    if (!check_za_access (opnd, mismatch_detail, idx,
1815
1.81k
        12, max_value, 1, 0))
1816
0
      return 0;
1817
1.81k
    break;
1818
1819
1.39M
  default:
1820
1.39M
    break;
1821
1.44M
  }
1822
1.44M
      break;
1823
1824
1.44M
    case AARCH64_OPND_CLASS_SVE_REGLIST:
1825
419k
      switch (type)
1826
419k
  {
1827
483
  case AARCH64_OPND_SME_Pdx2:
1828
18.9k
  case AARCH64_OPND_SME_Zdnx2:
1829
25.1k
  case AARCH64_OPND_SME_Zdnx4:
1830
26.1k
  case AARCH64_OPND_SME_Zmx2:
1831
26.3k
  case AARCH64_OPND_SME_Zmx4:
1832
31.4k
  case AARCH64_OPND_SME_Znx2:
1833
33.2k
  case AARCH64_OPND_SME_Znx4:
1834
33.2k
    num = get_operand_specific_data (&aarch64_operands[type]);
1835
33.2k
    if (!check_reglist (opnd, mismatch_detail, idx, num, 1))
1836
0
      return 0;
1837
33.2k
    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
33.2k
    break;
1844
1845
33.2k
  case AARCH64_OPND_SME_Ztx2_STRIDED:
1846
13.6k
  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
13.6k
    num = get_operand_specific_data (&aarch64_operands[type]);
1850
13.6k
    if (!check_reglist (opnd, mismatch_detail, idx, num, 16 / num))
1851
0
      return 0;
1852
13.6k
    num = 16 | (opnd->reglist.stride - 1);
1853
13.6k
    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
13.6k
    break;
1860
1861
13.6k
  case AARCH64_OPND_SME_PdxN:
1862
6.89k
  case AARCH64_OPND_SVE_ZnxN:
1863
372k
  case AARCH64_OPND_SVE_ZtxN:
1864
372k
    num = get_opcode_dependent_value (opcode);
1865
372k
    if (!check_reglist (opnd, mismatch_detail, idx, num, 1))
1866
0
      return 0;
1867
372k
    break;
1868
1869
372k
  default:
1870
0
    abort ();
1871
419k
  }
1872
419k
      break;
1873
1874
419k
    case AARCH64_OPND_CLASS_ZA_ACCESS:
1875
86.4k
      switch (type)
1876
86.4k
  {
1877
661
  case AARCH64_OPND_SME_ZA_HV_idx_src:
1878
12.8k
  case AARCH64_OPND_SME_ZA_HV_idx_dest:
1879
66.0k
  case AARCH64_OPND_SME_ZA_HV_idx_ldstr:
1880
66.0k
    size = aarch64_get_qualifier_esize (opnd->qualifier);
1881
66.0k
    max_value = 16 / size - 1;
1882
66.0k
    if (!check_za_access (opnd, mismatch_detail, idx, 12, max_value, 1,
1883
66.0k
        get_opcode_dependent_value (opcode)))
1884
0
      return 0;
1885
66.0k
    break;
1886
1887
66.0k
  case AARCH64_OPND_SME_ZA_array_off4:
1888
876
    if (!check_za_access (opnd, mismatch_detail, idx, 12, 15, 1,
1889
876
        get_opcode_dependent_value (opcode)))
1890
0
      return 0;
1891
876
    break;
1892
1893
3.46k
  case AARCH64_OPND_SME_ZA_array_off3_0:
1894
3.49k
  case AARCH64_OPND_SME_ZA_array_off3_5:
1895
3.49k
    if (!check_za_access (opnd, mismatch_detail, idx, 8, 7, 1,
1896
3.49k
        get_opcode_dependent_value (opcode)))
1897
0
      return 0;
1898
3.49k
    break;
1899
1900
3.49k
  case AARCH64_OPND_SME_ZA_array_off1x4:
1901
2.74k
    if (!check_za_access (opnd, mismatch_detail, idx, 8, 1, 4,
1902
2.74k
        get_opcode_dependent_value (opcode)))
1903
0
      return 0;
1904
2.74k
    break;
1905
1906
2.74k
  case AARCH64_OPND_SME_ZA_array_off2x2:
1907
2.64k
    if (!check_za_access (opnd, mismatch_detail, idx, 8, 3, 2,
1908
2.64k
        get_opcode_dependent_value (opcode)))
1909
0
      return 0;
1910
2.64k
    break;
1911
1912
5.76k
  case AARCH64_OPND_SME_ZA_array_off2x4:
1913
5.76k
    if (!check_za_access (opnd, mismatch_detail, idx, 8, 3, 4,
1914
5.76k
        get_opcode_dependent_value (opcode)))
1915
0
      return 0;
1916
5.76k
    break;
1917
1918
5.76k
  case AARCH64_OPND_SME_ZA_array_off3x2:
1919
4.13k
    if (!check_za_access (opnd, mismatch_detail, idx, 8, 7, 2,
1920
4.13k
        get_opcode_dependent_value (opcode)))
1921
0
      return 0;
1922
4.13k
    break;
1923
1924
4.13k
  case AARCH64_OPND_SME_ZA_HV_idx_srcxN:
1925
712
  case AARCH64_OPND_SME_ZA_HV_idx_destxN:
1926
712
    size = aarch64_get_qualifier_esize (opnd->qualifier);
1927
712
    num = get_opcode_dependent_value (opcode);
1928
712
    max_value = 16 / num / size;
1929
712
    if (max_value > 0)
1930
677
      max_value -= 1;
1931
712
    if (!check_za_access (opnd, mismatch_detail, idx,
1932
712
        12, max_value, num, 0))
1933
0
      return 0;
1934
712
    break;
1935
1936
712
  default:
1937
0
    abort ();
1938
86.4k
  }
1939
86.4k
      break;
1940
1941
1.12M
    case AARCH64_OPND_CLASS_PRED_REG:
1942
1.12M
      switch (type)
1943
1.12M
  {
1944
2.28k
  case AARCH64_OPND_SME_PNd3:
1945
38.7k
  case AARCH64_OPND_SME_PNg3:
1946
38.7k
    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
38.7k
    break;
1952
1953
1.08M
  default:
1954
1.08M
    if (opnd->reg.regno >= 8
1955
1.08M
        && 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
1.08M
    break;
1961
1.12M
  }
1962
1.12M
      break;
1963
1964
1.12M
    case AARCH64_OPND_CLASS_COND:
1965
38.6k
      if (type == AARCH64_OPND_COND1
1966
38.6k
    && (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
38.6k
      break;
1972
1973
4.36M
    case AARCH64_OPND_CLASS_ADDRESS:
1974
      /* Check writeback.  */
1975
4.36M
      switch (opcode->iclass)
1976
4.36M
  {
1977
400k
  case ldst_pos:
1978
511k
  case ldst_unscaled:
1979
709k
  case ldstnapair_offs:
1980
937k
  case ldstpair_off:
1981
958k
  case ldst_unpriv:
1982
958k
    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
958k
    break;
1989
958k
  case ldst_imm10:
1990
16.6k
    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
16.6k
    break;
1997
91.2k
  case ldst_imm9:
1998
400k
  case ldstpair_indexed:
1999
410k
  case asisdlsep:
2000
440k
  case asisdlsop:
2001
440k
    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
440k
    break;
2008
2.94M
  default:
2009
2.94M
    assert (opnd->addr.writeback == 0);
2010
2.94M
    break;
2011
4.36M
  }
2012
4.36M
      switch (type)
2013
4.36M
  {
2014
697k
  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
697k
    size = aarch64_get_qualifier_esize (opnd->qualifier);
2020
697k
    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
697k
    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
697k
    break;
2032
697k
  case AARCH64_OPND_ADDR_OFFSET:
2033
208k
  case AARCH64_OPND_ADDR_SIMM9:
2034
    /* Unscaled signed 9 bits immediate offset.  */
2035
208k
    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
208k
    break;
2041
2042
208k
  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
16.6k
  case AARCH64_OPND_ADDR_SIMM10:
2055
    /* Scaled signed 10 bits immediate offset.  */
2056
16.6k
    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
16.6k
    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
16.6k
    break;
2067
2068
37.3k
  case AARCH64_OPND_ADDR_SIMM11:
2069
    /* Signed 11 bits immediate offset (multiple of 16).  */
2070
37.3k
    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
37.3k
    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
37.3k
    break;
2082
2083
37.3k
  case AARCH64_OPND_ADDR_SIMM13:
2084
    /* Signed 13 bits immediate offset (multiple of 16).  */
2085
15.4k
    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
15.4k
    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
15.4k
    break;
2097
2098
40.0k
  case AARCH64_OPND_SIMD_ADDR_POST:
2099
    /* AdvSIMD load/store multiple structures, post-index.  */
2100
40.0k
    assert (idx == 1);
2101
40.0k
    if (opnd->addr.offset.is_reg)
2102
38.4k
      {
2103
38.4k
        if (value_in_range_p (opnd->addr.offset.regno, 0, 30))
2104
38.4k
    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
38.4k
      }
2112
1.57k
    else
2113
1.57k
      {
2114
1.57k
        const aarch64_opnd_info *prev = &opnds[idx-1];
2115
1.57k
        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
1.57k
        int is_ld1r = get_opcode_dependent_value (opcode) == 1;
2119
1.57k
        if (opcode->operands[0] == AARCH64_OPND_LVt_AL)
2120
    /* Special handling of loading single structure to all lane.  */
2121
140
    num_bytes = (is_ld1r ? 1 : prev->reglist.num_regs)
2122
140
      * aarch64_get_qualifier_esize (prev->qualifier);
2123
1.43k
        else
2124
1.43k
    num_bytes = prev->reglist.num_regs
2125
1.43k
      * aarch64_get_qualifier_esize (prev->qualifier)
2126
1.43k
      * aarch64_get_qualifier_nelem (prev->qualifier);
2127
1.57k
        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
1.57k
      }
2134
1.57k
    break;
2135
2136
62.6k
  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
62.6k
    size = aarch64_get_qualifier_esize (opnd->qualifier);
2141
    /* It is either no shift or shift by the binary logarithm of SIZE.  */
2142
62.6k
    if (opnd->shifter.amount != 0
2143
62.6k
        && 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
62.6k
    switch (opnd->shifter.kind)
2152
62.6k
      {
2153
4.21k
      case AARCH64_MOD_UXTW:
2154
15.0k
      case AARCH64_MOD_LSL:
2155
20.8k
      case AARCH64_MOD_SXTW:
2156
26.2k
      case AARCH64_MOD_SXTX: break;
2157
36.4k
      default:
2158
36.4k
        set_other_error (mismatch_detail, idx,
2159
36.4k
             _("invalid extend/shift operator"));
2160
36.4k
        return 0;
2161
62.6k
      }
2162
26.2k
    break;
2163
2164
400k
  case AARCH64_OPND_ADDR_UIMM12:
2165
400k
    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
400k
    size = aarch64_get_qualifier_esize (qualifier);
2170
400k
    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
400k
    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
400k
    break;
2182
2183
400k
  case AARCH64_OPND_ADDR_PCREL14:
2184
950k
  case AARCH64_OPND_ADDR_PCREL19:
2185
1.37M
  case AARCH64_OPND_ADDR_PCREL21:
2186
1.81M
  case AARCH64_OPND_ADDR_PCREL26:
2187
1.81M
    imm = opnd->imm.value;
2188
1.81M
    if (operand_need_shift_by_two (get_operand_from_code (type)))
2189
1.38M
      {
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
1.38M
        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
1.38M
        imm >>= 2;
2200
1.38M
      }
2201
1.81M
    size = get_operand_fields_width (get_operand_from_code (type));
2202
1.81M
    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
1.81M
    break;
2209
2210
1.81M
  case AARCH64_OPND_SME_ADDR_RI_U4xVL:
2211
876
    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
876
    break;
2217
2218
75.3k
  case AARCH64_OPND_SVE_ADDR_RI_S4xVL:
2219
87.5k
  case AARCH64_OPND_SVE_ADDR_RI_S4x2xVL:
2220
91.2k
  case AARCH64_OPND_SVE_ADDR_RI_S4x3xVL:
2221
99.6k
  case AARCH64_OPND_SVE_ADDR_RI_S4x4xVL:
2222
99.6k
    min_value = -8;
2223
99.6k
    max_value = 7;
2224
112k
  sve_imm_offset_vl:
2225
112k
    assert (!opnd->addr.offset.is_reg);
2226
112k
    assert (opnd->addr.preind);
2227
112k
    num = 1 + get_operand_specific_data (&aarch64_operands[type]);
2228
112k
    min_value *= num;
2229
112k
    max_value *= num;
2230
112k
    if ((opnd->addr.offset.imm != 0 && !opnd->shifter.operator_present)
2231
112k
        || (opnd->shifter.operator_present
2232
112k
      && 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
112k
    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
112k
    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
112k
    break;
2250
2251
112k
  case AARCH64_OPND_SVE_ADDR_RI_S6xVL:
2252
3.98k
    min_value = -32;
2253
3.98k
    max_value = 31;
2254
3.98k
    goto sve_imm_offset_vl;
2255
2256
8.94k
  case AARCH64_OPND_SVE_ADDR_RI_S9xVL:
2257
8.94k
    min_value = -256;
2258
8.94k
    max_value = 255;
2259
8.94k
    goto sve_imm_offset_vl;
2260
2261
15.2k
  case AARCH64_OPND_SVE_ADDR_RI_U6:
2262
23.1k
  case AARCH64_OPND_SVE_ADDR_RI_U6x2:
2263
29.6k
  case AARCH64_OPND_SVE_ADDR_RI_U6x4:
2264
31.6k
  case AARCH64_OPND_SVE_ADDR_RI_U6x8:
2265
31.6k
    min_value = 0;
2266
31.6k
    max_value = 63;
2267
59.8k
  sve_imm_offset:
2268
59.8k
    assert (!opnd->addr.offset.is_reg);
2269
59.8k
    assert (opnd->addr.preind);
2270
59.8k
    num = 1 << get_operand_specific_data (&aarch64_operands[type]);
2271
59.8k
    min_value *= num;
2272
59.8k
    max_value *= num;
2273
59.8k
    if (opnd->shifter.operator_present
2274
59.8k
        || 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
59.8k
    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
59.8k
    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
59.8k
    break;
2292
2293
59.8k
  case AARCH64_OPND_SVE_ADDR_RI_S4x16:
2294
2.94k
  case AARCH64_OPND_SVE_ADDR_RI_S4x32:
2295
2.94k
    min_value = -8;
2296
2.94k
    max_value = 7;
2297
2.94k
    goto sve_imm_offset;
2298
2299
17.3k
  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
17.3k
    assert (opnd->addr.offset.is_reg);
2304
17.3k
    assert (opnd->addr.preind);
2305
17.3k
    assert ((aarch64_operands[type].flags & OPD_F_NO_ZR) == 0);
2306
17.3k
    assert (opnd->shifter.kind == AARCH64_MOD_LSL);
2307
17.3k
    assert (opnd->shifter.operator_present == 0);
2308
17.3k
    break;
2309
2310
17.3k
  case AARCH64_OPND_SVE_ADDR_R:
2311
28.1k
  case AARCH64_OPND_SVE_ADDR_RR:
2312
44.8k
  case AARCH64_OPND_SVE_ADDR_RR_LSL1:
2313
56.6k
  case AARCH64_OPND_SVE_ADDR_RR_LSL2:
2314
82.3k
  case AARCH64_OPND_SVE_ADDR_RR_LSL3:
2315
90.6k
  case AARCH64_OPND_SVE_ADDR_RR_LSL4:
2316
108k
  case AARCH64_OPND_SVE_ADDR_RX:
2317
121k
  case AARCH64_OPND_SVE_ADDR_RX_LSL1:
2318
138k
  case AARCH64_OPND_SVE_ADDR_RX_LSL2:
2319
148k
  case AARCH64_OPND_SVE_ADDR_RX_LSL3:
2320
177k
  case AARCH64_OPND_SVE_ADDR_RZ:
2321
181k
  case AARCH64_OPND_SVE_ADDR_RZ_LSL1:
2322
185k
  case AARCH64_OPND_SVE_ADDR_RZ_LSL2:
2323
189k
  case AARCH64_OPND_SVE_ADDR_RZ_LSL3:
2324
189k
    modifiers = 1 << AARCH64_MOD_LSL;
2325
304k
  sve_rr_operand:
2326
304k
    assert (opnd->addr.offset.is_reg);
2327
304k
    assert (opnd->addr.preind);
2328
304k
    if ((aarch64_operands[type].flags & OPD_F_NO_ZR) != 0
2329
304k
        && 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
304k
    if (((1 << opnd->shifter.kind) & modifiers) == 0
2336
304k
        || (opnd->shifter.amount
2337
304k
      != 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
304k
    break;
2344
2345
304k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW_14:
2346
69.7k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW_22:
2347
73.2k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW1_14:
2348
85.9k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW1_22:
2349
88.3k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW2_14:
2350
99.4k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW2_22:
2351
101k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW3_14:
2352
114k
  case AARCH64_OPND_SVE_ADDR_RZ_XTW3_22:
2353
114k
    modifiers = (1 << AARCH64_MOD_SXTW) | (1 << AARCH64_MOD_UXTW);
2354
114k
    goto sve_rr_operand;
2355
2356
8.40k
  case AARCH64_OPND_SVE_ADDR_ZI_U5:
2357
17.0k
  case AARCH64_OPND_SVE_ADDR_ZI_U5x2:
2358
22.2k
  case AARCH64_OPND_SVE_ADDR_ZI_U5x4:
2359
25.2k
  case AARCH64_OPND_SVE_ADDR_ZI_U5x8:
2360
25.2k
    min_value = 0;
2361
25.2k
    max_value = 31;
2362
25.2k
    goto sve_imm_offset;
2363
2364
1.19k
  case AARCH64_OPND_SVE_ADDR_ZZ_LSL:
2365
1.19k
    modifiers = 1 << AARCH64_MOD_LSL;
2366
2.63k
  sve_zz_operand:
2367
2.63k
    assert (opnd->addr.offset.is_reg);
2368
2.63k
    assert (opnd->addr.preind);
2369
2.63k
    if (((1 << opnd->shifter.kind) & modifiers) == 0
2370
2.63k
        || opnd->shifter.amount < 0
2371
2.63k
        || 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
2.63k
    break;
2378
2379
2.63k
  case AARCH64_OPND_SVE_ADDR_ZZ_SXTW:
2380
329
    modifiers = (1 << AARCH64_MOD_SXTW);
2381
329
    goto sve_zz_operand;
2382
2383
1.10k
  case AARCH64_OPND_SVE_ADDR_ZZ_UXTW:
2384
1.10k
    modifiers = 1 << AARCH64_MOD_UXTW;
2385
1.10k
    goto sve_zz_operand;
2386
2387
576k
  default:
2388
576k
    break;
2389
4.36M
  }
2390
4.28M
      break;
2391
2392
4.28M
    case AARCH64_OPND_CLASS_SIMD_REGLIST:
2393
77.7k
      if (type == AARCH64_OPND_LEt)
2394
35.9k
  {
2395
    /* Get the upper bound for the element index.  */
2396
35.9k
    num = 16 / aarch64_get_qualifier_esize (qualifier) - 1;
2397
35.9k
    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
35.9k
  }
2403
      /* The opcode dependent area stores the number of elements in
2404
   each structure to be loaded/stored.  */
2405
77.7k
      num = get_opcode_dependent_value (opcode);
2406
77.7k
      switch (type)
2407
77.7k
  {
2408
21.8k
  case AARCH64_OPND_LVt:
2409
21.8k
    assert (num >= 1 && num <= 4);
2410
    /* Unless LD1/ST1, the number of registers should be equal to that
2411
       of the structure elements.  */
2412
21.8k
    if (num != 1 && !check_reglist (opnd, mismatch_detail, idx, num, 1))
2413
874
      return 0;
2414
21.0k
    break;
2415
21.0k
  case AARCH64_OPND_LVt_AL:
2416
38.6k
  case AARCH64_OPND_LEt:
2417
38.6k
    assert (num >= 1 && num <= 4);
2418
    /* The number of registers should be equal to that of the structure
2419
       elements.  */
2420
38.6k
    if (!check_reglist (opnd, mismatch_detail, idx, num, 1))
2421
0
      return 0;
2422
38.6k
    break;
2423
38.6k
  default:
2424
17.3k
    break;
2425
77.7k
  }
2426
76.9k
      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
76.9k
      break;
2432
2433
4.15M
    case AARCH64_OPND_CLASS_IMMEDIATE:
2434
      /* Constraint check on immediate operand.  */
2435
4.15M
      imm = opnd->imm.value;
2436
      /* E.g. imm_0_31 constrains value to be 0..31.  */
2437
4.15M
      if (qualifier_value_in_range_constraint_p (qualifier)
2438
4.15M
    && !value_in_range_p (imm, get_lower_bound (qualifier),
2439
760k
        get_upper_bound (qualifier)))
2440
110k
  {
2441
110k
    set_imm_out_of_range_error (mismatch_detail, idx,
2442
110k
              get_lower_bound (qualifier),
2443
110k
              get_upper_bound (qualifier));
2444
110k
    return 0;
2445
110k
  }
2446
2447
4.04M
      switch (type)
2448
4.04M
  {
2449
549k
  case AARCH64_OPND_AIMM:
2450
549k
    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
549k
    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
549k
    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
549k
    break;
2469
2470
549k
  case AARCH64_OPND_HALF:
2471
202k
    assert (idx == 1 && opnds[0].type == AARCH64_OPND_Rd);
2472
202k
    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
202k
    size = aarch64_get_qualifier_esize (opnds[0].qualifier);
2479
202k
    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
202k
    if (!value_in_range_p (opnd->shifter.amount, 0, size * 8 - 16))
2486
32.0k
      {
2487
32.0k
        set_sft_amount_out_of_range_error (mismatch_detail, idx,
2488
32.0k
             0, size * 8 - 16);
2489
32.0k
        return 0;
2490
32.0k
      }
2491
170k
    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
170k
    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
170k
    break;
2504
2505
170k
  case AARCH64_OPND_IMM_MOV:
2506
114k
      {
2507
114k
        int esize = aarch64_get_qualifier_esize (opnds[0].qualifier);
2508
114k
        imm = opnd->imm.value;
2509
114k
        assert (idx == 1);
2510
114k
        switch (opcode->op)
2511
114k
    {
2512
65.2k
    case OP_MOV_IMM_WIDEN:
2513
65.2k
      imm = ~imm;
2514
      /* Fall through.  */
2515
113k
    case OP_MOV_IMM_WIDE:
2516
113k
      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
113k
      break;
2523
113k
    case OP_MOV_IMM_LOG:
2524
986
      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
986
      break;
2531
986
    default:
2532
0
      assert (0);
2533
0
      return 0;
2534
114k
    }
2535
114k
      }
2536
114k
    break;
2537
2538
114k
  case AARCH64_OPND_NZCV:
2539
16.0k
  case AARCH64_OPND_CCMP_IMM:
2540
17.1k
  case AARCH64_OPND_EXCEPTION:
2541
1.88M
  case AARCH64_OPND_UNDEFINED:
2542
1.88M
  case AARCH64_OPND_TME_UIMM16:
2543
1.88M
  case AARCH64_OPND_UIMM4:
2544
1.88M
  case AARCH64_OPND_UIMM4_ADDG:
2545
1.88M
  case AARCH64_OPND_UIMM7:
2546
1.89M
  case AARCH64_OPND_UIMM3_OP1:
2547
1.89M
  case AARCH64_OPND_UIMM3_OP2:
2548
1.89M
  case AARCH64_OPND_SVE_UIMM3:
2549
1.93M
  case AARCH64_OPND_SVE_UIMM7:
2550
1.93M
  case AARCH64_OPND_SVE_UIMM8:
2551
1.94M
  case AARCH64_OPND_SVE_UIMM8_53:
2552
1.94M
  case AARCH64_OPND_CSSC_UIMM8:
2553
1.94M
    size = get_operand_fields_width (get_operand_from_code (type));
2554
1.94M
    assert (size < 32);
2555
1.94M
    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
1.94M
    break;
2562
2563
1.94M
  case AARCH64_OPND_UIMM10:
2564
    /* Scaled unsigned 10 bits immediate offset.  */
2565
7.10k
    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
7.10k
    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
7.10k
    break;
2577
2578
15.1k
  case AARCH64_OPND_SIMM5:
2579
16.0k
  case AARCH64_OPND_SVE_SIMM5:
2580
16.5k
  case AARCH64_OPND_SVE_SIMM5B:
2581
18.6k
  case AARCH64_OPND_SVE_SIMM6:
2582
19.3k
  case AARCH64_OPND_SVE_SIMM8:
2583
21.9k
  case AARCH64_OPND_CSSC_SIMM8:
2584
21.9k
    size = get_operand_fields_width (get_operand_from_code (type));
2585
21.9k
    assert (size < 32);
2586
21.9k
    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
21.9k
    break;
2594
2595
82.4k
  case AARCH64_OPND_WIDTH:
2596
82.4k
    assert (idx > 1 && opnds[idx-1].type == AARCH64_OPND_IMM
2597
82.4k
      && opnds[0].type == AARCH64_OPND_Rd);
2598
82.4k
    size = get_upper_bound (qualifier);
2599
82.4k
    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
82.4k
    break;
2607
2608
354k
  case AARCH64_OPND_LIMM:
2609
399k
  case AARCH64_OPND_SVE_LIMM:
2610
399k
    {
2611
399k
      int esize = aarch64_get_qualifier_esize (opnds[0].qualifier);
2612
399k
      uint64_t uimm = opnd->imm.value;
2613
399k
      if (opcode->op == OP_BIC)
2614
0
        uimm = ~uimm;
2615
399k
      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
399k
    }
2622
399k
    break;
2623
2624
399k
  case AARCH64_OPND_IMM0:
2625
712
  case AARCH64_OPND_FPIMM0:
2626
712
    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
712
    break;
2633
2634
1.24k
  case AARCH64_OPND_IMM_ROT1:
2635
20.6k
  case AARCH64_OPND_IMM_ROT2:
2636
29.8k
  case AARCH64_OPND_SVE_IMM_ROT2:
2637
29.8k
    if (opnd->imm.value != 0
2638
29.8k
        && opnd->imm.value != 90
2639
29.8k
        && opnd->imm.value != 180
2640
29.8k
        && 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
29.8k
    break;
2647
2648
29.8k
  case AARCH64_OPND_IMM_ROT3:
2649
1.38k
  case AARCH64_OPND_SVE_IMM_ROT1:
2650
1.39k
  case AARCH64_OPND_SVE_IMM_ROT3:
2651
1.39k
    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
1.39k
    break;
2658
2659
1.39k
  case AARCH64_OPND_SHLL_IMM:
2660
49
    assert (idx == 2);
2661
49
    size = 8 * aarch64_get_qualifier_esize (opnds[idx - 1].qualifier);
2662
49
    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
49
    break;
2669
2670
12.1k
  case AARCH64_OPND_IMM_VLSL:
2671
12.1k
    size = aarch64_get_qualifier_esize (qualifier);
2672
12.1k
    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
12.1k
    break;
2679
2680
17.6k
  case AARCH64_OPND_IMM_VLSR:
2681
17.6k
    size = aarch64_get_qualifier_esize (qualifier);
2682
17.6k
    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
17.6k
    break;
2688
2689
17.6k
  case AARCH64_OPND_SIMD_IMM:
2690
3.21k
  case AARCH64_OPND_SIMD_IMM_SFT:
2691
    /* Qualifier check.  */
2692
3.21k
    switch (qualifier)
2693
3.21k
      {
2694
2.84k
      case AARCH64_OPND_QLF_LSL:
2695
2.84k
        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
2.84k
        break;
2702
2.84k
      case AARCH64_OPND_QLF_MSL:
2703
300
        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
300
        break;
2710
300
      case AARCH64_OPND_QLF_NIL:
2711
67
        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
67
        break;
2718
67
      default:
2719
0
        assert (0);
2720
0
        return 0;
2721
3.21k
      }
2722
    /* Is the immediate valid?  */
2723
3.21k
    assert (idx == 1);
2724
3.21k
    if (aarch64_get_qualifier_esize (opnds[0].qualifier) != 8)
2725
3.14k
      {
2726
        /* uimm8 or simm8 */
2727
3.14k
        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
3.14k
      }
2733
67
    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
3.21k
    switch (opnd->shifter.kind)
2744
3.21k
      {
2745
2.84k
      case AARCH64_MOD_LSL:
2746
2.84k
        size = aarch64_get_qualifier_esize (opnds[0].qualifier);
2747
2.84k
        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
2.84k
        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
2.84k
        break;
2759
2.84k
      case AARCH64_MOD_MSL:
2760
        /* Only 8 and 16 are valid shift amount.  */
2761
300
        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
300
        break;
2768
300
      default:
2769
67
        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
67
        break;
2776
3.21k
      }
2777
3.21k
    break;
2778
2779
3.21k
  case AARCH64_OPND_FPIMM:
2780
912
  case AARCH64_OPND_SIMD_FPIMM:
2781
3.33k
  case AARCH64_OPND_SVE_FPIMM8:
2782
3.33k
    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
3.33k
    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
3.33k
    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
3.33k
    break;
2805
2806
3.33k
  case AARCH64_OPND_SVE_AIMM:
2807
2.29k
    min_value = 0;
2808
34.7k
  sve_aimm:
2809
34.7k
    assert (opnd->shifter.kind == AARCH64_MOD_LSL);
2810
34.7k
    size = aarch64_get_qualifier_esize (opnds[0].qualifier);
2811
34.7k
    mask = ~((uint64_t) -1 << (size * 4) << (size * 4));
2812
34.7k
    uvalue = opnd->imm.value;
2813
34.7k
    shift = opnd->shifter.amount;
2814
34.7k
    if (size == 1)
2815
4.93k
      {
2816
4.93k
        if (shift != 0)
2817
4
    {
2818
4
      set_other_error (mismatch_detail, idx,
2819
4
           _("no shift amount allowed for"
2820
4
             " 8-bit constants"));
2821
4
      return 0;
2822
4
    }
2823
4.93k
      }
2824
29.7k
    else
2825
29.7k
      {
2826
29.7k
        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
29.7k
        if (shift == 0 && (uvalue & 0xff) == 0)
2833
15.7k
    {
2834
15.7k
      shift = 8;
2835
15.7k
      uvalue = (int64_t) uvalue / 256;
2836
15.7k
    }
2837
29.7k
      }
2838
34.7k
    mask >>= shift;
2839
34.7k
    if ((uvalue & mask) != uvalue && (uvalue | ~mask) != uvalue)
2840
1.28k
      {
2841
1.28k
        set_other_error (mismatch_detail, idx,
2842
1.28k
             _("immediate too big for element size"));
2843
1.28k
        return 0;
2844
1.28k
      }
2845
33.4k
    uvalue = (uvalue - min_value) & mask;
2846
33.4k
    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
33.4k
    break;
2853
2854
33.4k
  case AARCH64_OPND_SVE_ASIMM:
2855
32.4k
    min_value = -128;
2856
32.4k
    goto sve_aimm;
2857
2858
73
  case AARCH64_OPND_SVE_I1_HALF_ONE:
2859
73
    assert (opnd->imm.is_fp);
2860
73
    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
73
    break;
2867
2868
73
  case AARCH64_OPND_SVE_I1_HALF_TWO:
2869
10
    assert (opnd->imm.is_fp);
2870
10
    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
10
    break;
2877
2878
10
  case AARCH64_OPND_SVE_I1_ZERO_ONE:
2879
10
    assert (opnd->imm.is_fp);
2880
10
    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
10
    break;
2887
2888
10
  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
1.55k
  case AARCH64_OPND_SVE_LIMM_MOV:
2902
1.55k
    {
2903
1.55k
      int esize = aarch64_get_qualifier_esize (opnds[0].qualifier);
2904
1.55k
      uint64_t uimm = opnd->imm.value;
2905
1.55k
      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
1.55k
      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
1.55k
    }
2918
1.55k
    break;
2919
2920
6.81k
  case AARCH64_OPND_SVE_PATTERN_SCALED:
2921
6.81k
    assert (opnd->shifter.kind == AARCH64_MOD_MUL);
2922
6.81k
    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
6.81k
    break;
2928
2929
6.81k
  case AARCH64_OPND_SVE_SHLIMM_PRED:
2930
1.31k
  case AARCH64_OPND_SVE_SHLIMM_UNPRED:
2931
2.76k
  case AARCH64_OPND_SVE_SHLIMM_UNPRED_22:
2932
2.76k
    size = aarch64_get_qualifier_esize (opnds[idx - 1].qualifier);
2933
2.76k
    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
2.76k
    break;
2940
2941
2.76k
  case AARCH64_OPND_SME_SHRIMM4:
2942
91
    size = 1 << get_operand_fields_width (get_operand_from_code (type));
2943
91
    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
91
    break;
2949
2950
144
  case AARCH64_OPND_SME_SHRIMM5:
2951
2.32k
  case AARCH64_OPND_SVE_SHRIMM_PRED:
2952
5.52k
  case AARCH64_OPND_SVE_SHRIMM_UNPRED:
2953
11.9k
  case AARCH64_OPND_SVE_SHRIMM_UNPRED_22:
2954
11.9k
    num = (type == AARCH64_OPND_SVE_SHRIMM_UNPRED_22) ? 2 : 1;
2955
11.9k
    size = aarch64_get_qualifier_esize (opnds[idx - num].qualifier);
2956
11.9k
    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
11.9k
    break;
2962
2963
11.9k
  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
593k
  default:
2978
593k
    break;
2979
4.04M
  }
2980
4.01M
      break;
2981
2982
4.01M
    case AARCH64_OPND_CLASS_SYSTEM:
2983
80.7k
      switch (type)
2984
80.7k
  {
2985
365
  case AARCH64_OPND_PSTATEFIELD:
2986
496
    for (i = 0; aarch64_pstatefields[i].name; ++i)
2987
496
      if (aarch64_pstatefields[i].value == opnd->pstatefield)
2988
365
        break;
2989
365
    assert (aarch64_pstatefields[i].name);
2990
365
    assert (idx == 0 && opnds[1].type == AARCH64_OPND_UIMM4);
2991
365
    max_value = F_GET_REG_MAX_VALUE (aarch64_pstatefields[i].flags);
2992
365
    if (opnds[1].imm.value < 0 || opnds[1].imm.value > max_value)
2993
318
      {
2994
318
        set_imm_out_of_range_error (mismatch_detail, 1, 0, max_value);
2995
318
        return 0;
2996
318
      }
2997
47
    break;
2998
69.2k
  case AARCH64_OPND_PRFOP:
2999
69.2k
    if (opcode->iclass == ldst_regoff && opnd->prfop->value >= 24)
3000
309
      {
3001
309
        set_other_error (mismatch_detail, idx,
3002
309
             _("the register-index form of PRFM does"
3003
309
         " not accept opcodes in the range 24-31"));
3004
309
        return 0;
3005
309
      }
3006
68.9k
    break;
3007
68.9k
  default:
3008
11.1k
    break;
3009
80.7k
  }
3010
80.0k
      break;
3011
3012
84.6k
    case AARCH64_OPND_CLASS_SIMD_ELEMENT:
3013
      /* Get the upper bound for the element index.  */
3014
84.6k
      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
10.2k
  num = aarch64_get_qualifier_nelem (opnds[0].qualifier)
3018
10.2k
        * aarch64_get_qualifier_esize (opnds[0].qualifier) / 2;
3019
74.4k
      else
3020
74.4k
  num = 16;
3021
84.6k
      num = num / aarch64_get_qualifier_esize (qualifier) - 1;
3022
84.6k
      assert (aarch64_get_qualifier_nelem (qualifier) == 1);
3023
3024
      /* Index out-of-range.  */
3025
84.6k
      if (!value_in_range_p (opnd->reglane.index, 0, num))
3026
1.11k
  {
3027
1.11k
    set_elem_idx_out_of_range_error (mismatch_detail, idx, 0, num);
3028
1.11k
    return 0;
3029
1.11k
  }
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
83.5k
      if (type == AARCH64_OPND_Em16 && qualifier == AARCH64_OPND_QLF_S_H
3039
83.5k
    && !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
83.5k
      break;
3045
3046
1.00M
    case AARCH64_OPND_CLASS_MODIFIED_REG:
3047
1.00M
      assert (idx == 1 || idx == 2);
3048
1.00M
      switch (type)
3049
1.00M
  {
3050
72.4k
  case AARCH64_OPND_Rm_EXT:
3051
72.4k
    if (!aarch64_extend_operator_p (opnd->shifter.kind)
3052
72.4k
        && 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
72.4k
    if (!aarch64_stack_pointer_p (opnds + 0)
3063
72.4k
        && (idx != 2 || !aarch64_stack_pointer_p (opnds + 1)))
3064
69.5k
      {
3065
69.5k
        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
69.5k
        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
69.5k
      }
3078
72.4k
    assert (opnd->shifter.operator_present  /* Default to LSL.  */
3079
72.4k
      || opnd->shifter.kind == AARCH64_MOD_LSL);
3080
72.4k
    if (!value_in_range_p (opnd->shifter.amount, 0, 4))
3081
17.6k
      {
3082
17.6k
        set_sft_amount_out_of_range_error (mismatch_detail, idx, 0, 4);
3083
17.6k
        return 0;
3084
17.6k
      }
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
54.7k
    if (qualifier == AARCH64_OPND_QLF_X
3091
54.7k
        && opnd->shifter.kind != AARCH64_MOD_LSL
3092
54.7k
        && opnd->shifter.kind != AARCH64_MOD_UXTX
3093
54.7k
        && 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
54.7k
    break;
3099
3100
932k
  case AARCH64_OPND_Rm_SFT:
3101
    /* ROR is not available to the shifted register operand in
3102
       arithmetic instructions.  */
3103
932k
    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
932k
    if (opnd->shifter.kind == AARCH64_MOD_ROR
3110
932k
        && 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
932k
    num = qualifier == AARCH64_OPND_QLF_W ? 31 : 63;
3117
932k
    if (!value_in_range_p (opnd->shifter.amount, 0, num))
3118
131k
      {
3119
131k
        set_sft_amount_out_of_range_error (mismatch_detail, idx, 0, num);
3120
131k
        return 0;
3121
131k
      }
3122
800k
    break;
3123
3124
800k
  default:
3125
0
    break;
3126
1.00M
  }
3127
855k
      break;
3128
3129
2.19M
    default:
3130
2.19M
      break;
3131
23.4M
    }
3132
3133
23.0M
  return 1;
3134
23.4M
}
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
10.0M
{
3151
10.0M
  int i;
3152
3153
10.0M
  DEBUG_TRACE ("enter");
3154
3155
10.0M
  i = inst->opcode->tied_operand;
3156
3157
10.0M
  if (i > 0)
3158
90.9k
    {
3159
      /* Check for tied_operands with specific opcode iclass.  */
3160
90.9k
      switch (inst->opcode->iclass)
3161
90.9k
        {
3162
        /* For SME LDR and STR instructions #imm must have the same numerical
3163
           value for both operands.
3164
        */
3165
874
        case sme_ldr:
3166
876
        case sme_str:
3167
876
          assert (inst->operands[0].type == AARCH64_OPND_SME_ZA_array_off4);
3168
876
          assert (inst->operands[1].type == AARCH64_OPND_SME_ADDR_RI_U4xVL);
3169
876
          if (inst->operands[0].indexed_za.index.imm
3170
876
              != 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
876
          break;
3180
3181
90.0k
        default:
3182
90.0k
    {
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
90.0k
      enum aarch64_operand_class op_class1
3190
90.0k
         = aarch64_get_operand_class (inst->operands[0].type);
3191
90.0k
      enum aarch64_operand_class op_class2
3192
90.0k
         = aarch64_get_operand_class (inst->operands[i].type);
3193
90.0k
      assert (op_class1 == op_class2);
3194
90.0k
      if (op_class1 == AARCH64_OPND_CLASS_SVE_REGLIST
3195
90.0k
    ? ((inst->operands[0].reglist.first_regno
3196
125
        != inst->operands[i].reglist.first_regno)
3197
125
       || (inst->operands[0].reglist.num_regs
3198
125
           != inst->operands[i].reglist.num_regs)
3199
125
       || (inst->operands[0].reglist.stride
3200
125
           != inst->operands[i].reglist.stride))
3201
90.0k
    : (inst->operands[0].reg.regno
3202
89.9k
       != 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
90.0k
      break;
3213
90.0k
    }
3214
90.9k
        }
3215
90.9k
    }
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
10.0M
  int invalid_count;
3228
10.0M
  if (match_operands_qualifier (inst, true /* update_p */,
3229
10.0M
        &invalid_count) == 0)
3230
48.3k
    {
3231
48.3k
      DEBUG_TRACE ("FAIL on operand qualifier matching");
3232
48.3k
      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
48.3k
      return 0;
3243
48.3k
    }
3244
3245
  /* Match operands' constraint.  */
3246
33.0M
  for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
3247
33.0M
    {
3248
33.0M
      enum aarch64_opnd type = inst->opcode->operands[i];
3249
33.0M
      if (type == AARCH64_OPND_NIL)
3250
9.63M
  break;
3251
23.4M
      if (inst->operands[i].skip)
3252
0
  {
3253
0
    DEBUG_TRACE ("skip the incomplete operand %d", i);
3254
0
    continue;
3255
0
  }
3256
23.4M
      if (operand_general_constraint_met_p (inst->operands, i, type,
3257
23.4M
              inst->opcode, mismatch_detail) == 0)
3258
337k
  {
3259
337k
    DEBUG_TRACE ("FAIL on operand %d", i);
3260
337k
    return 0;
3261
337k
  }
3262
23.4M
    }
3263
3264
9.63M
  DEBUG_TRACE ("PASS");
3265
3266
9.63M
  return 1;
3267
9.97M
}
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
200k
{
3281
200k
  int i;
3282
200k
  const aarch64_opcode *old = inst->opcode;
3283
3284
200k
  inst->opcode = opcode;
3285
3286
  /* Update the operand types.  */
3287
767k
  for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
3288
767k
    {
3289
767k
      inst->operands[i].type = opcode->operands[i];
3290
767k
      if (opcode->operands[i] == AARCH64_OPND_NIL)
3291
200k
  break;
3292
767k
    }
3293
3294
200k
  DEBUG_TRACE ("replace %s with %s", old->name, opcode->name);
3295
3296
200k
  return old;
3297
200k
}
3298
3299
int
3300
aarch64_operand_index (const enum aarch64_opnd *operands, enum aarch64_opnd operand)
3301
346k
{
3302
346k
  int i;
3303
381k
  for (i = 0; i < AARCH64_MAX_OPND_NUM; ++i)
3304
381k
    if (operands[i] == operand)
3305
344k
      return i;
3306
36.7k
    else if (operands[i] == AARCH64_OPND_NIL)
3307
2.06k
      break;
3308
2.06k
  return -1;
3309
346k
}
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
6.61M
{
3348
6.61M
  const int has_zr = sp_reg_p ? 0 : 1;
3349
6.61M
  const int is_64 = aarch64_get_qualifier_esize (qualifier) == 4 ? 0 : 1;
3350
6.61M
  return int_reg[has_zr][is_64][regno];
3351
6.61M
}
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
2.18M
{
3358
2.18M
  const int has_zr = sp_reg_p ? 0 : 1;
3359
2.18M
  return int_reg[has_zr][1][regno];
3360
2.18M
}
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
174k
{
3368
174k
  switch (opnd->shifter.kind)
3369
174k
    {
3370
4.21k
    case AARCH64_MOD_UXTW:
3371
10.0k
    case AARCH64_MOD_SXTW:
3372
10.0k
      return get_int_reg_name (opnd->addr.offset.regno, AARCH64_OPND_QLF_W, 0);
3373
3374
159k
    case AARCH64_MOD_LSL:
3375
164k
    case AARCH64_MOD_SXTX:
3376
164k
      return get_int_reg_name (opnd->addr.offset.regno, AARCH64_OPND_QLF_X, 0);
3377
3378
0
    default:
3379
0
      abort ();
3380
174k
    }
3381
174k
}
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
204k
{
3389
204k
  assert (qualifier == AARCH64_OPND_QLF_S_S
3390
204k
    || qualifier == AARCH64_OPND_QLF_S_D);
3391
204k
  return sve_reg[qualifier == AARCH64_OPND_QLF_S_D][regno];
3392
204k
}
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
2.12k
{
3425
2.12k
  uint64_t imm = 0;
3426
2.12k
  uint32_t imm8_7, imm8_6_0, imm8_6, imm8_6_repl4;
3427
3428
2.12k
  imm8_7 = (imm8 >> 7) & 0x01;  /* imm8<7>   */
3429
2.12k
  imm8_6_0 = imm8 & 0x7f; /* imm8<6:0> */
3430
2.12k
  imm8_6 = imm8_6_0 >> 6; /* imm8<6>   */
3431
2.12k
  imm8_6_repl4 = (imm8_6 << 3) | (imm8_6 << 2)
3432
2.12k
    | (imm8_6 << 1) | imm8_6; /* Replicate(imm8<6>,4) */
3433
2.12k
  if (size == 8)
3434
433
    {
3435
433
      imm = (imm8_7 << (63-32))   /* imm8<7>  */
3436
433
  | ((imm8_6 ^ 1) << (62-32)) /* NOT(imm8<6)  */
3437
433
  | (imm8_6_repl4 << (58-32)) | (imm8_6 << (57-32))
3438
433
  | (imm8_6 << (56-32)) | (imm8_6 << (55-32)) /* Replicate(imm8<6>,7) */
3439
433
  | (imm8_6_0 << (48-32));  /* imm8<6>:imm8<5:0>    */
3440
433
      imm <<= 32;
3441
433
    }
3442
1.68k
  else if (size == 4 || size == 2)
3443
1.68k
    {
3444
1.68k
      imm = (imm8_7 << 31)  /* imm8<7>              */
3445
1.68k
  | ((imm8_6 ^ 1) << 30)  /* NOT(imm8<6>)         */
3446
1.68k
  | (imm8_6_repl4 << 26)  /* Replicate(imm8<6>,4) */
3447
1.68k
  | (imm8_6_0 << 19); /* imm8<6>:imm8<5:0>    */
3448
1.68k
    }
3449
0
  else
3450
0
    {
3451
      /* An unsupported size.  */
3452
0
      assert (0);
3453
0
    }
3454
3455
2.12k
  return imm;
3456
2.12k
}
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
14.4M
{
3463
14.4M
  const char *txt;
3464
14.4M
  va_list ap;
3465
3466
14.4M
  va_start (ap, fmt);
3467
14.4M
  txt = styler->apply_style (styler, dis_style_register, fmt, ap);
3468
14.4M
  va_end (ap);
3469
3470
14.4M
  return txt;
3471
14.4M
}
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
5.84M
{
3478
5.84M
  const char *txt;
3479
5.84M
  va_list ap;
3480
3481
5.84M
  va_start (ap, fmt);
3482
5.84M
  txt = styler->apply_style (styler, dis_style_immediate, fmt, ap);
3483
5.84M
  va_end (ap);
3484
3485
5.84M
  return txt;
3486
5.84M
}
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
1.14M
{
3493
1.14M
  const char *txt;
3494
1.14M
  va_list ap;
3495
3496
1.14M
  va_start (ap, fmt);
3497
1.14M
  txt = styler->apply_style (styler, dis_style_sub_mnemonic, fmt, ap);
3498
1.14M
  va_end (ap);
3499
3500
1.14M
  return txt;
3501
1.14M
}
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
2.09M
{
3508
2.09M
  const char *txt;
3509
2.09M
  va_list ap;
3510
3511
2.09M
  va_start (ap, fmt);
3512
2.09M
  txt = styler->apply_style (styler, dis_style_address, fmt, ap);
3513
2.09M
  va_end (ap);
3514
3515
2.09M
  return txt;
3516
2.09M
}
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
496k
{
3525
496k
  const int mask = (prefix[0] == 'p' ? 15 : 31);
3526
496k
  const int num_regs = opnd->reglist.num_regs;
3527
496k
  const int stride = opnd->reglist.stride;
3528
496k
  const int first_reg = opnd->reglist.first_regno;
3529
496k
  const int last_reg = (first_reg + (num_regs - 1) * stride) & mask;
3530
496k
  const char *qlf_name = aarch64_get_qualifier_name (opnd->qualifier);
3531
496k
  char tb[16];  /* Temporary buffer.  */
3532
3533
496k
  assert (opnd->type != AARCH64_OPND_LEt || opnd->reglist.has_index);
3534
496k
  assert (num_regs >= 1 && num_regs <= 4);
3535
3536
  /* Prepare the index if any.  */
3537
496k
  if (opnd->reglist.has_index)
3538
    /* PR 21096: The %100 is to silence a warning about possible truncation.  */
3539
35.9k
    snprintf (tb, sizeof (tb), "[%s]",
3540
35.9k
        style_imm (styler, "%" PRIi64, (opnd->reglist.index % 100)));
3541
460k
  else
3542
460k
    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
496k
  if (stride == 1 && num_regs > 1)
3548
116k
    snprintf (buf, size, "{%s-%s}%s",
3549
116k
        style_reg (styler, "%s%d.%s", prefix, first_reg, qlf_name),
3550
116k
        style_reg (styler, "%s%d.%s", prefix, last_reg, qlf_name), tb);
3551
380k
  else
3552
380k
    {
3553
380k
      const int reg0 = first_reg;
3554
380k
      const int reg1 = (first_reg + stride) & mask;
3555
380k
      const int reg2 = (first_reg + stride * 2) & mask;
3556
380k
      const int reg3 = (first_reg + stride * 3) & mask;
3557
3558
380k
      switch (num_regs)
3559
380k
  {
3560
367k
  case 1:
3561
367k
    snprintf (buf, size, "{%s}%s",
3562
367k
        style_reg (styler, "%s%d.%s", prefix, reg0, qlf_name),
3563
367k
        tb);
3564
367k
    break;
3565
9.09k
  case 2:
3566
9.09k
    snprintf (buf, size, "{%s, %s}%s",
3567
9.09k
        style_reg (styler, "%s%d.%s", prefix, reg0, qlf_name),
3568
9.09k
        style_reg (styler, "%s%d.%s", prefix, reg1, qlf_name),
3569
9.09k
        tb);
3570
9.09k
    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
4.54k
  case 4:
3579
4.54k
    snprintf (buf, size, "{%s, %s, %s, %s}%s",
3580
4.54k
        style_reg (styler, "%s%d.%s", prefix, reg0, qlf_name),
3581
4.54k
        style_reg (styler, "%s%d.%s", prefix, reg1, qlf_name),
3582
4.54k
        style_reg (styler, "%s%d.%s", prefix, reg2, qlf_name),
3583
4.54k
        style_reg (styler, "%s%d.%s", prefix, reg3, qlf_name),
3584
4.54k
        tb);
3585
4.54k
    break;
3586
380k
  }
3587
380k
    }
3588
496k
}
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
1.14M
{
3599
1.14M
  if (opnd->addr.writeback)
3600
410k
    {
3601
410k
      if (opnd->addr.preind)
3602
207k
        {
3603
207k
    if (opnd->type == AARCH64_OPND_ADDR_SIMM10 && !opnd->addr.offset.imm)
3604
6
      snprintf (buf, size, "[%s]!", style_reg (styler, base));
3605
207k
          else
3606
207k
      snprintf (buf, size, "[%s, %s]!",
3607
207k
          style_reg (styler, base),
3608
207k
          style_imm (styler, "#%d", opnd->addr.offset.imm));
3609
207k
        }
3610
202k
      else
3611
202k
  snprintf (buf, size, "[%s], %s",
3612
202k
      style_reg (styler, base),
3613
202k
      style_imm (styler, "#%d", opnd->addr.offset.imm));
3614
410k
    }
3615
737k
  else
3616
737k
    {
3617
737k
      if (opnd->shifter.operator_present)
3618
107k
  {
3619
107k
    assert (opnd->shifter.kind == AARCH64_MOD_MUL_VL);
3620
107k
    snprintf (buf, size, "[%s, %s, %s]",
3621
107k
        style_reg (styler, base),
3622
107k
        style_imm (styler, "#%d", opnd->addr.offset.imm),
3623
107k
        style_sub_mnem (styler, "mul vl"));
3624
107k
  }
3625
630k
      else if (opnd->addr.offset.imm)
3626
562k
  snprintf (buf, size, "[%s, %s]",
3627
562k
      style_reg (styler, base),
3628
562k
      style_imm (styler, "#%d", opnd->addr.offset.imm));
3629
67.7k
      else
3630
67.7k
  snprintf (buf, size, "[%s]", style_reg (styler, base));
3631
737k
    }
3632
1.14M
}
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
351k
{
3643
351k
  char tb[32];      /* Temporary buffer.  */
3644
351k
  bool print_extend_p = true;
3645
351k
  bool print_amount_p = true;
3646
351k
  const char *shift_name = aarch64_operand_modifiers[opnd->shifter.kind].name;
3647
3648
351k
  if (!opnd->shifter.amount && (opnd->qualifier != AARCH64_OPND_QLF_S_B
3649
177k
        || !opnd->shifter.amount_present))
3650
175k
    {
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
175k
      print_amount_p = false;
3654
      /* Likewise, no need to print the shift operator LSL in such a
3655
   situation.  */
3656
175k
      if (opnd->shifter.kind == AARCH64_MOD_LSL)
3657
97.3k
  print_extend_p = false;
3658
175k
    }
3659
3660
  /* Prepare for the extend/shift.  */
3661
351k
  if (print_extend_p)
3662
253k
    {
3663
253k
      if (print_amount_p)
3664
175k
  snprintf (tb, sizeof (tb), ", %s %s",
3665
175k
      style_sub_mnem (styler, shift_name),
3666
175k
      style_imm (styler, "#%" PRIi64,
3667
  /* PR 21096: The %100 is to silence a warning about possible truncation.  */
3668
175k
           (opnd->shifter.amount % 100)));
3669
77.7k
      else
3670
77.7k
  snprintf (tb, sizeof (tb), ", %s",
3671
77.7k
      style_sub_mnem (styler, shift_name));
3672
253k
    }
3673
97.3k
  else
3674
97.3k
    tb[0] = '\0';
3675
3676
351k
  snprintf (buf, size, "[%s, %s%s]", style_reg (styler, base),
3677
351k
      style_reg (styler, offset), tb);
3678
351k
}
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
42
{
3693
42
  const char* zan[] = { "za",    "za0.h", "za1.h", "za0.s",
3694
42
                        "za1.s", "za2.s", "za3.s", "za0.d",
3695
42
                        "za1.d", "za2.d", "za3.d", "za4.d",
3696
42
                        "za5.d", "za6.d", "za7.d", " " };
3697
42
  const int zan_v[] = { 0xff, 0x55, 0xaa, 0x11,
3698
42
                        0x22, 0x44, 0x88, 0x01,
3699
42
                        0x02, 0x04, 0x08, 0x10,
3700
42
                        0x20, 0x40, 0x80, 0x00 };
3701
42
  int i, k;
3702
42
  const int ZAN_SIZE = sizeof(zan) / sizeof(zan[0]);
3703
3704
42
  k = snprintf (buf, size, "{");
3705
438
  for (i = 0; i < ZAN_SIZE; i++)
3706
438
    {
3707
438
      if ((mask & zan_v[i]) == zan_v[i])
3708
147
        {
3709
147
          mask &= ~zan_v[i];
3710
147
          if (k > 1)
3711
108
      k += snprintf (buf + k, size - k, ", ");
3712
3713
147
    k += snprintf (buf + k, size - k, "%s", style_reg (styler, zan[i]));
3714
147
        }
3715
438
      if (mask == 0)
3716
42
        break;
3717
438
    }
3718
42
  snprintf (buf + k, size - k, "}");
3719
42
}
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
19.2M
{
3741
19.2M
  unsigned int i, num_conds;
3742
19.2M
  const char *name = NULL;
3743
19.2M
  const aarch64_opnd_info *opnd = opnds + idx;
3744
19.2M
  enum aarch64_modifier_kind kind;
3745
19.2M
  uint64_t addr, enum_value;
3746
3747
19.2M
  if (comment != NULL)
3748
19.2M
    {
3749
19.2M
      assert (comment_size > 0);
3750
19.2M
      comment[0] = '\0';
3751
19.2M
    }
3752
0
  else
3753
0
    assert (comment_size == 0);
3754
3755
19.2M
  buf[0] = '\0';
3756
19.2M
  if (pcrel_p)
3757
19.2M
    *pcrel_p = 0;
3758
3759
19.2M
  switch (opnd->type)
3760
19.2M
    {
3761
1.82M
    case AARCH64_OPND_Rd:
3762
2.76M
    case AARCH64_OPND_Rn:
3763
2.86M
    case AARCH64_OPND_Rm:
3764
4.55M
    case AARCH64_OPND_Rt:
3765
4.91M
    case AARCH64_OPND_Rt2:
3766
5.06M
    case AARCH64_OPND_Rs:
3767
5.11M
    case AARCH64_OPND_Ra:
3768
5.11M
    case AARCH64_OPND_Rt_LS64:
3769
5.11M
    case AARCH64_OPND_Rt_SYS:
3770
5.11M
    case AARCH64_OPND_PAIRREG:
3771
5.11M
    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
5.11M
      if (opnd->type == AARCH64_OPND_Rt_SYS)
3776
262
  {
3777
262
    if (!opnd->present)
3778
262
      break;
3779
262
  }
3780
      /* Omit the operand, e.g. RET.  */
3781
5.11M
      else if (optional_operand_p (opcode, idx)
3782
5.11M
         && (opnd->reg.regno
3783
5.01k
       == get_optional_operand_default_value (opcode)))
3784
3.63k
  break;
3785
5.11M
      assert (opnd->qualifier == AARCH64_OPND_QLF_W
3786
5.11M
        || opnd->qualifier == AARCH64_OPND_QLF_X);
3787
5.11M
      snprintf (buf, size, "%s",
3788
5.11M
    style_reg (styler, get_int_reg_name (opnd->reg.regno,
3789
5.11M
                 opnd->qualifier, 0)));
3790
5.11M
      break;
3791
3792
329k
    case AARCH64_OPND_Rd_SP:
3793
679k
    case AARCH64_OPND_Rn_SP:
3794
694k
    case AARCH64_OPND_Rt_SP:
3795
696k
    case AARCH64_OPND_SVE_Rn_SP:
3796
697k
    case AARCH64_OPND_Rm_SP:
3797
697k
      assert (opnd->qualifier == AARCH64_OPND_QLF_W
3798
697k
        || opnd->qualifier == AARCH64_OPND_QLF_WSP
3799
697k
        || opnd->qualifier == AARCH64_OPND_QLF_X
3800
697k
        || opnd->qualifier == AARCH64_OPND_QLF_SP);
3801
697k
      snprintf (buf, size, "%s",
3802
697k
    style_reg (styler, get_int_reg_name (opnd->reg.regno,
3803
697k
                 opnd->qualifier, 1)));
3804
697k
      break;
3805
3806
35.6k
    case AARCH64_OPND_Rm_EXT:
3807
35.6k
      kind = opnd->shifter.kind;
3808
35.6k
      assert (idx == 1 || idx == 2);
3809
35.6k
      if ((aarch64_stack_pointer_p (opnds)
3810
35.6k
     || (idx == 2 && aarch64_stack_pointer_p (opnds + 1)))
3811
35.6k
    && ((opnd->qualifier == AARCH64_OPND_QLF_W
3812
1.42k
         && opnds[0].qualifier == AARCH64_OPND_QLF_W
3813
1.42k
         && kind == AARCH64_MOD_UXTW)
3814
1.42k
        || (opnd->qualifier == AARCH64_OPND_QLF_X
3815
1.31k
      && kind == AARCH64_MOD_UXTX)))
3816
302
  {
3817
    /* 'LSL' is the preferred form in this case.  */
3818
302
    kind = AARCH64_MOD_LSL;
3819
302
    if (opnd->shifter.amount == 0)
3820
112
      {
3821
        /* Shifter omitted.  */
3822
112
        snprintf (buf, size, "%s",
3823
112
      style_reg (styler,
3824
112
           get_int_reg_name (opnd->reg.regno,
3825
112
                 opnd->qualifier, 0)));
3826
112
        break;
3827
112
      }
3828
302
  }
3829
35.5k
      if (opnd->shifter.amount)
3830
27.4k
  snprintf (buf, size, "%s, %s %s",
3831
27.4k
      style_reg (styler, get_int_reg_name (opnd->reg.regno, opnd->qualifier, 0)),
3832
27.4k
      style_sub_mnem (styler, aarch64_operand_modifiers[kind].name),
3833
27.4k
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
3834
8.16k
      else
3835
8.16k
  snprintf (buf, size, "%s, %s",
3836
8.16k
      style_reg (styler, get_int_reg_name (opnd->reg.regno, opnd->qualifier, 0)),
3837
8.16k
      style_sub_mnem (styler, aarch64_operand_modifiers[kind].name));
3838
35.5k
      break;
3839
3840
556k
    case AARCH64_OPND_Rm_SFT:
3841
556k
      assert (opnd->qualifier == AARCH64_OPND_QLF_W
3842
556k
        || opnd->qualifier == AARCH64_OPND_QLF_X);
3843
556k
      if (opnd->shifter.amount == 0 && opnd->shifter.kind == AARCH64_MOD_LSL)
3844
65.9k
  snprintf (buf, size, "%s",
3845
65.9k
      style_reg (styler, get_int_reg_name (opnd->reg.regno,
3846
65.9k
                   opnd->qualifier, 0)));
3847
490k
      else
3848
490k
  snprintf (buf, size, "%s, %s %s",
3849
490k
      style_reg (styler, get_int_reg_name (opnd->reg.regno, opnd->qualifier, 0)),
3850
490k
      style_sub_mnem (styler, aarch64_operand_modifiers[opnd->shifter.kind].name),
3851
490k
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
3852
556k
      break;
3853
3854
60.6k
    case AARCH64_OPND_Fd:
3855
125k
    case AARCH64_OPND_Fn:
3856
185k
    case AARCH64_OPND_Fm:
3857
234k
    case AARCH64_OPND_Fa:
3858
1.01M
    case AARCH64_OPND_Ft:
3859
1.40M
    case AARCH64_OPND_Ft2:
3860
1.43M
    case AARCH64_OPND_Sd:
3861
1.46M
    case AARCH64_OPND_Sn:
3862
1.47M
    case AARCH64_OPND_Sm:
3863
1.47M
    case AARCH64_OPND_SVE_VZn:
3864
1.47M
    case AARCH64_OPND_SVE_Vd:
3865
1.47M
    case AARCH64_OPND_SVE_Vm:
3866
1.47M
    case AARCH64_OPND_SVE_Vn:
3867
1.47M
      snprintf (buf, size, "%s",
3868
1.47M
    style_reg (styler, "%s%d",
3869
1.47M
         aarch64_get_qualifier_name (opnd->qualifier),
3870
1.47M
         opnd->reg.regno));
3871
1.47M
      break;
3872
3873
13.9k
    case AARCH64_OPND_Va:
3874
281k
    case AARCH64_OPND_Vd:
3875
523k
    case AARCH64_OPND_Vn:
3876
696k
    case AARCH64_OPND_Vm:
3877
696k
      snprintf (buf, size, "%s",
3878
696k
    style_reg (styler, "v%d.%s", opnd->reg.regno,
3879
696k
         aarch64_get_qualifier_name (opnd->qualifier)));
3880
696k
      break;
3881
3882
1.96k
    case AARCH64_OPND_Ed:
3883
5.40k
    case AARCH64_OPND_En:
3884
25.7k
    case AARCH64_OPND_Em:
3885
79.3k
    case AARCH64_OPND_Em16:
3886
79.3k
    case AARCH64_OPND_SM3_IMM2:
3887
79.3k
      snprintf (buf, size, "%s[%s]",
3888
79.3k
    style_reg (styler, "v%d.%s", opnd->reglane.regno,
3889
79.3k
         aarch64_get_qualifier_name (opnd->qualifier)),
3890
79.3k
    style_imm (styler, "%" PRIi64, opnd->reglane.index));
3891
79.3k
      break;
3892
3893
54
    case AARCH64_OPND_VdD1:
3894
153
    case AARCH64_OPND_VnD1:
3895
153
      snprintf (buf, size, "%s[%s]",
3896
153
    style_reg (styler, "v%d.d", opnd->reg.regno),
3897
153
    style_imm (styler, "1"));
3898
153
      break;
3899
3900
17.3k
    case AARCH64_OPND_LVn:
3901
38.3k
    case AARCH64_OPND_LVt:
3902
41.0k
    case AARCH64_OPND_LVt_AL:
3903
76.9k
    case AARCH64_OPND_LEt:
3904
76.9k
      print_register_list (buf, size, opnd, "v", styler);
3905
76.9k
      break;
3906
3907
113k
    case AARCH64_OPND_SVE_Pd:
3908
881k
    case AARCH64_OPND_SVE_Pg3:
3909
882k
    case AARCH64_OPND_SVE_Pg4_5:
3910
900k
    case AARCH64_OPND_SVE_Pg4_10:
3911
917k
    case AARCH64_OPND_SVE_Pg4_16:
3912
923k
    case AARCH64_OPND_SVE_Pm:
3913
930k
    case AARCH64_OPND_SVE_Pn:
3914
932k
    case AARCH64_OPND_SVE_Pt:
3915
1.00M
    case AARCH64_OPND_SME_Pm:
3916
1.00M
      if (opnd->qualifier == AARCH64_OPND_QLF_NIL)
3917
170k
  snprintf (buf, size, "%s",
3918
170k
      style_reg (styler, "p%d", opnd->reg.regno));
3919
830k
      else if (opnd->qualifier == AARCH64_OPND_QLF_P_Z
3920
830k
         || opnd->qualifier == AARCH64_OPND_QLF_P_M)
3921
705k
  snprintf (buf, size, "%s",
3922
705k
      style_reg (styler, "p%d/%s", opnd->reg.regno,
3923
705k
           aarch64_get_qualifier_name (opnd->qualifier)));
3924
124k
      else
3925
124k
  snprintf (buf, size, "%s",
3926
124k
      style_reg (styler, "p%d.%s", opnd->reg.regno,
3927
124k
           aarch64_get_qualifier_name (opnd->qualifier)));
3928
1.00M
      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
2.28k
    case AARCH64_OPND_SME_PNd3:
3935
38.7k
    case AARCH64_OPND_SME_PNg3:
3936
38.9k
    case AARCH64_OPND_SME_PNn:
3937
38.9k
      if (opnd->qualifier == AARCH64_OPND_QLF_NIL)
3938
15.8k
  snprintf (buf, size, "%s",
3939
15.8k
      style_reg (styler, "pn%d", opnd->reg.regno));
3940
23.0k
      else if (opnd->qualifier == AARCH64_OPND_QLF_P_Z
3941
23.0k
         || opnd->qualifier == AARCH64_OPND_QLF_P_M)
3942
20.6k
  snprintf (buf, size, "%s",
3943
20.6k
      style_reg (styler, "pn%d/%s", opnd->reg.regno,
3944
20.6k
           aarch64_get_qualifier_name (opnd->qualifier)));
3945
2.45k
      else
3946
2.45k
  snprintf (buf, size, "%s",
3947
2.45k
      style_reg (styler, "pn%d.%s", opnd->reg.regno,
3948
2.45k
           aarch64_get_qualifier_name (opnd->qualifier)));
3949
38.9k
      break;
3950
3951
483
    case AARCH64_OPND_SME_Pdx2:
3952
491
    case AARCH64_OPND_SME_PdxN:
3953
491
      print_register_list (buf, size, opnd, "p", styler);
3954
491
      break;
3955
3956
8
    case AARCH64_OPND_SME_PNn3_INDEX1:
3957
15
    case AARCH64_OPND_SME_PNn3_INDEX2:
3958
15
      snprintf (buf, size, "%s[%s]",
3959
15
    style_reg (styler, "pn%d", opnd->reglane.regno),
3960
15
    style_imm (styler, "%" PRIi64, opnd->reglane.index));
3961
15
      break;
3962
3963
13.7k
    case AARCH64_OPND_SVE_Za_5:
3964
24.7k
    case AARCH64_OPND_SVE_Za_16:
3965
426k
    case AARCH64_OPND_SVE_Zd:
3966
474k
    case AARCH64_OPND_SVE_Zm_5:
3967
770k
    case AARCH64_OPND_SVE_Zm_16:
3968
1.17M
    case AARCH64_OPND_SVE_Zn:
3969
1.18M
    case AARCH64_OPND_SVE_Zt:
3970
1.18M
    case AARCH64_OPND_SME_Zm:
3971
1.18M
      if (opnd->qualifier == AARCH64_OPND_QLF_NIL)
3972
6.38k
  snprintf (buf, size, "%s", style_reg (styler, "z%d", opnd->reg.regno));
3973
1.18M
      else
3974
1.18M
  snprintf (buf, size, "%s",
3975
1.18M
      style_reg (styler, "z%d.%s", opnd->reg.regno,
3976
1.18M
           aarch64_get_qualifier_name (opnd->qualifier)));
3977
1.18M
      break;
3978
3979
6.89k
    case AARCH64_OPND_SVE_ZnxN:
3980
372k
    case AARCH64_OPND_SVE_ZtxN:
3981
391k
    case AARCH64_OPND_SME_Zdnx2:
3982
397k
    case AARCH64_OPND_SME_Zdnx4:
3983
398k
    case AARCH64_OPND_SME_Zmx2:
3984
398k
    case AARCH64_OPND_SME_Zmx4:
3985
403k
    case AARCH64_OPND_SME_Znx2:
3986
405k
    case AARCH64_OPND_SME_Znx4:
3987
414k
    case AARCH64_OPND_SME_Ztx2_STRIDED:
3988
419k
    case AARCH64_OPND_SME_Ztx4_STRIDED:
3989
419k
      print_register_list (buf, size, opnd, "z", styler);
3990
419k
      break;
3991
3992
4.35k
    case AARCH64_OPND_SVE_Zm3_INDEX:
3993
7.90k
    case AARCH64_OPND_SVE_Zm3_22_INDEX:
3994
8.13k
    case AARCH64_OPND_SVE_Zm3_19_INDEX:
3995
16.0k
    case AARCH64_OPND_SVE_Zm3_11_INDEX:
3996
21.4k
    case AARCH64_OPND_SVE_Zm4_11_INDEX:
3997
26.1k
    case AARCH64_OPND_SVE_Zm4_INDEX:
3998
26.9k
    case AARCH64_OPND_SVE_Zn_INDEX:
3999
27.1k
    case AARCH64_OPND_SME_Zm_INDEX1:
4000
28.5k
    case AARCH64_OPND_SME_Zm_INDEX2:
4001
29.2k
    case AARCH64_OPND_SME_Zm_INDEX3_1:
4002
31.1k
    case AARCH64_OPND_SME_Zm_INDEX3_2:
4003
37.1k
    case AARCH64_OPND_SME_Zm_INDEX3_10:
4004
38.0k
    case AARCH64_OPND_SME_Zm_INDEX4_1:
4005
41.3k
    case AARCH64_OPND_SME_Zm_INDEX4_10:
4006
41.3k
    case AARCH64_OPND_SME_Zn_INDEX1_16:
4007
41.4k
    case AARCH64_OPND_SME_Zn_INDEX2_15:
4008
41.4k
    case AARCH64_OPND_SME_Zn_INDEX2_16:
4009
41.4k
    case AARCH64_OPND_SME_Zn_INDEX3_14:
4010
41.5k
    case AARCH64_OPND_SME_Zn_INDEX3_15:
4011
41.5k
    case AARCH64_OPND_SME_Zn_INDEX4_14:
4012
41.5k
      snprintf (buf, size, "%s[%s]",
4013
41.5k
    (opnd->qualifier == AARCH64_OPND_QLF_NIL
4014
41.5k
     ? style_reg (styler, "z%d", opnd->reglane.regno)
4015
41.5k
     : style_reg (styler, "z%d.%s", opnd->reglane.regno,
4016
41.3k
            aarch64_get_qualifier_name (opnd->qualifier))),
4017
41.5k
    style_imm (styler, "%" PRIi64, opnd->reglane.index));
4018
41.5k
      break;
4019
4020
47.5k
    case AARCH64_OPND_SME_ZAda_2b:
4021
67.8k
    case AARCH64_OPND_SME_ZAda_3b:
4022
67.8k
      snprintf (buf, size, "%s",
4023
67.8k
    style_reg (styler, "za%d.%s", opnd->reg.regno,
4024
67.8k
         aarch64_get_qualifier_name (opnd->qualifier)));
4025
67.8k
      break;
4026
4027
661
    case AARCH64_OPND_SME_ZA_HV_idx_src:
4028
987
    case AARCH64_OPND_SME_ZA_HV_idx_srcxN:
4029
13.1k
    case AARCH64_OPND_SME_ZA_HV_idx_dest:
4030
13.5k
    case AARCH64_OPND_SME_ZA_HV_idx_destxN:
4031
66.7k
    case AARCH64_OPND_SME_ZA_HV_idx_ldstr:
4032
66.7k
      snprintf (buf, size, "%s%s[%s, %s%s%s%s%s]%s",
4033
66.7k
    opnd->type == AARCH64_OPND_SME_ZA_HV_idx_ldstr ? "{" : "",
4034
66.7k
    style_reg (styler, "za%d%c.%s",
4035
66.7k
         opnd->indexed_za.regno,
4036
66.7k
         opnd->indexed_za.v == 1 ? 'v' : 'h',
4037
66.7k
         aarch64_get_qualifier_name (opnd->qualifier)),
4038
66.7k
    style_reg (styler, "w%d", opnd->indexed_za.index.regno),
4039
66.7k
    style_imm (styler, "%" PRIi64, opnd->indexed_za.index.imm),
4040
66.7k
    opnd->indexed_za.index.countm1 ? ":" : "",
4041
66.7k
    (opnd->indexed_za.index.countm1
4042
66.7k
     ? style_imm (styler, "%d",
4043
712
            opnd->indexed_za.index.imm
4044
712
            + opnd->indexed_za.index.countm1)
4045
66.7k
     : ""),
4046
66.7k
    opnd->indexed_za.group_size ? ", " : "",
4047
66.7k
    opnd->indexed_za.group_size == 2
4048
66.7k
    ? style_sub_mnem (styler, "vgx2")
4049
66.7k
    : opnd->indexed_za.group_size == 4
4050
66.7k
    ? style_sub_mnem (styler, "vgx4") : "",
4051
66.7k
    opnd->type == AARCH64_OPND_SME_ZA_HV_idx_ldstr ? "}" : "");
4052
66.7k
      break;
4053
4054
42
    case AARCH64_OPND_SME_list_of_64bit_tiles:
4055
42
      print_sme_za_list (buf, size, opnd->reg.regno, styler);
4056
42
      break;
4057
4058
2.74k
    case AARCH64_OPND_SME_ZA_array_off1x4:
4059
5.38k
    case AARCH64_OPND_SME_ZA_array_off2x2:
4060
11.1k
    case AARCH64_OPND_SME_ZA_array_off2x4:
4061
14.6k
    case AARCH64_OPND_SME_ZA_array_off3_0:
4062
14.6k
    case AARCH64_OPND_SME_ZA_array_off3_5:
4063
18.7k
    case AARCH64_OPND_SME_ZA_array_off3x2:
4064
19.6k
    case AARCH64_OPND_SME_ZA_array_off4:
4065
19.6k
      snprintf (buf, size, "%s[%s, %s%s%s%s%s]",
4066
19.6k
    style_reg (styler, "za%s%s",
4067
19.6k
         opnd->qualifier == AARCH64_OPND_QLF_NIL ? "" : ".",
4068
19.6k
         (opnd->qualifier == AARCH64_OPND_QLF_NIL
4069
19.6k
          ? ""
4070
19.6k
          : aarch64_get_qualifier_name (opnd->qualifier))),
4071
19.6k
    style_reg (styler, "w%d", opnd->indexed_za.index.regno),
4072
19.6k
    style_imm (styler, "%" PRIi64, opnd->indexed_za.index.imm),
4073
19.6k
    opnd->indexed_za.index.countm1 ? ":" : "",
4074
19.6k
    (opnd->indexed_za.index.countm1
4075
19.6k
     ? style_imm (styler, "%d",
4076
15.2k
            opnd->indexed_za.index.imm
4077
15.2k
            + opnd->indexed_za.index.countm1)
4078
19.6k
     : ""),
4079
19.6k
    opnd->indexed_za.group_size ? ", " : "",
4080
19.6k
    opnd->indexed_za.group_size == 2
4081
19.6k
    ? style_sub_mnem (styler, "vgx2")
4082
19.6k
    : opnd->indexed_za.group_size == 4
4083
14.1k
    ? style_sub_mnem (styler, "vgx4") : "");
4084
19.6k
      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
1.81k
    case AARCH64_OPND_SME_PnT_Wm_imm:
4092
1.81k
      snprintf (buf, size, "%s[%s, %s]",
4093
1.81k
    style_reg (styler, "p%d.%s", opnd->indexed_za.regno,
4094
1.81k
         aarch64_get_qualifier_name (opnd->qualifier)),
4095
1.81k
    style_reg (styler, "w%d", opnd->indexed_za.index.regno),
4096
1.81k
    style_imm (styler, "%" PRIi64, opnd->indexed_za.index.imm));
4097
1.81k
      break;
4098
4099
170
    case AARCH64_OPND_SME_VLxN_10:
4100
2.45k
    case AARCH64_OPND_SME_VLxN_13:
4101
2.45k
      enum_value = opnd->imm.value;
4102
2.45k
      assert (enum_value < ARRAY_SIZE (aarch64_sme_vlxn_array));
4103
2.45k
      snprintf (buf, size, "%s",
4104
2.45k
    style_sub_mnem (styler, aarch64_sme_vlxn_array[enum_value]));
4105
2.45k
      break;
4106
4107
2.81k
    case AARCH64_OPND_CRn:
4108
5.63k
    case AARCH64_OPND_CRm:
4109
5.63k
      snprintf (buf, size, "%s",
4110
5.63k
    style_reg (styler, "C%" PRIi64, opnd->imm.value));
4111
5.63k
      break;
4112
4113
8.76k
    case AARCH64_OPND_IDX:
4114
10.1k
    case AARCH64_OPND_MASK:
4115
102k
    case AARCH64_OPND_IMM:
4116
103k
    case AARCH64_OPND_IMM_2:
4117
185k
    case AARCH64_OPND_WIDTH:
4118
188k
    case AARCH64_OPND_UIMM3_OP1:
4119
191k
    case AARCH64_OPND_UIMM3_OP2:
4120
438k
    case AARCH64_OPND_BIT_NUM:
4121
450k
    case AARCH64_OPND_IMM_VLSL:
4122
467k
    case AARCH64_OPND_IMM_VLSR:
4123
467k
    case AARCH64_OPND_SHLL_IMM:
4124
467k
    case AARCH64_OPND_IMM0:
4125
467k
    case AARCH64_OPND_IMMR:
4126
474k
    case AARCH64_OPND_IMMS:
4127
2.33M
    case AARCH64_OPND_UNDEFINED:
4128
2.34M
    case AARCH64_OPND_FBITS:
4129
2.34M
    case AARCH64_OPND_TME_UIMM16:
4130
2.35M
    case AARCH64_OPND_SIMM5:
4131
2.35M
    case AARCH64_OPND_SME_SHRIMM4:
4132
2.35M
    case AARCH64_OPND_SME_SHRIMM5:
4133
2.35M
    case AARCH64_OPND_SVE_SHLIMM_PRED:
4134
2.35M
    case AARCH64_OPND_SVE_SHLIMM_UNPRED:
4135
2.36M
    case AARCH64_OPND_SVE_SHLIMM_UNPRED_22:
4136
2.36M
    case AARCH64_OPND_SVE_SHRIMM_PRED:
4137
2.36M
    case AARCH64_OPND_SVE_SHRIMM_UNPRED:
4138
2.37M
    case AARCH64_OPND_SVE_SHRIMM_UNPRED_22:
4139
2.37M
    case AARCH64_OPND_SVE_SIMM5:
4140
2.37M
    case AARCH64_OPND_SVE_SIMM5B:
4141
2.37M
    case AARCH64_OPND_SVE_SIMM6:
4142
2.37M
    case AARCH64_OPND_SVE_SIMM8:
4143
2.37M
    case AARCH64_OPND_SVE_UIMM3:
4144
2.41M
    case AARCH64_OPND_SVE_UIMM7:
4145
2.41M
    case AARCH64_OPND_SVE_UIMM8:
4146
2.42M
    case AARCH64_OPND_SVE_UIMM8_53:
4147
2.42M
    case AARCH64_OPND_IMM_ROT1:
4148
2.44M
    case AARCH64_OPND_IMM_ROT2:
4149
2.44M
    case AARCH64_OPND_IMM_ROT3:
4150
2.44M
    case AARCH64_OPND_SVE_IMM_ROT1:
4151
2.45M
    case AARCH64_OPND_SVE_IMM_ROT2:
4152
2.45M
    case AARCH64_OPND_SVE_IMM_ROT3:
4153
2.45M
    case AARCH64_OPND_CSSC_SIMM8:
4154
2.45M
    case AARCH64_OPND_CSSC_UIMM8:
4155
2.45M
      snprintf (buf, size, "%s",
4156
2.45M
    style_imm (styler, "#%" PRIi64, opnd->imm.value));
4157
2.45M
      break;
4158
4159
73
    case AARCH64_OPND_SVE_I1_HALF_ONE:
4160
83
    case AARCH64_OPND_SVE_I1_HALF_TWO:
4161
93
    case AARCH64_OPND_SVE_I1_ZERO_ONE:
4162
93
      {
4163
93
  single_conv_t c;
4164
93
  c.i = opnd->imm.value;
4165
93
  snprintf (buf, size, "%s", style_imm (styler, "#%.1f", c.f));
4166
93
  break;
4167
83
      }
4168
4169
17
    case AARCH64_OPND_SVE_PATTERN:
4170
17
      if (optional_operand_p (opcode, idx)
4171
17
    && opnd->imm.value == get_optional_operand_default_value (opcode))
4172
11
  break;
4173
6
      enum_value = opnd->imm.value;
4174
6
      assert (enum_value < ARRAY_SIZE (aarch64_sve_pattern_array));
4175
6
      if (aarch64_sve_pattern_array[enum_value])
4176
3
  snprintf (buf, size, "%s",
4177
3
      style_reg (styler, aarch64_sve_pattern_array[enum_value]));
4178
3
      else
4179
3
  snprintf (buf, size, "%s",
4180
3
      style_imm (styler, "#%" PRIi64, opnd->imm.value));
4181
6
      break;
4182
4183
6.81k
    case AARCH64_OPND_SVE_PATTERN_SCALED:
4184
6.81k
      if (optional_operand_p (opcode, idx)
4185
6.81k
    && !opnd->shifter.operator_present
4186
6.81k
    && opnd->imm.value == get_optional_operand_default_value (opcode))
4187
19
  break;
4188
6.79k
      enum_value = opnd->imm.value;
4189
6.79k
      assert (enum_value < ARRAY_SIZE (aarch64_sve_pattern_array));
4190
6.79k
      if (aarch64_sve_pattern_array[opnd->imm.value])
4191
4.40k
  snprintf (buf, size, "%s",
4192
4.40k
      style_reg (styler,
4193
4.40k
           aarch64_sve_pattern_array[opnd->imm.value]));
4194
2.38k
      else
4195
2.38k
  snprintf (buf, size, "%s",
4196
2.38k
      style_imm (styler, "#%" PRIi64, opnd->imm.value));
4197
6.79k
      if (opnd->shifter.operator_present)
4198
5.90k
  {
4199
5.90k
    size_t len = strlen (buf);
4200
5.90k
    const char *shift_name
4201
5.90k
      = aarch64_operand_modifiers[opnd->shifter.kind].name;
4202
5.90k
    snprintf (buf + len, size - len, ", %s %s",
4203
5.90k
        style_sub_mnem (styler, shift_name),
4204
5.90k
        style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
4205
5.90k
  }
4206
6.79k
      break;
4207
4208
30.3k
    case AARCH64_OPND_SVE_PRFOP:
4209
30.3k
      enum_value = opnd->imm.value;
4210
30.3k
      assert (enum_value < ARRAY_SIZE (aarch64_sve_prfop_array));
4211
30.3k
      if (aarch64_sve_prfop_array[enum_value])
4212
19.9k
  snprintf (buf, size, "%s",
4213
19.9k
      style_reg (styler, aarch64_sve_prfop_array[enum_value]));
4214
10.3k
      else
4215
10.3k
  snprintf (buf, size, "%s",
4216
10.3k
      style_imm (styler, "#%" PRIi64, opnd->imm.value));
4217
30.3k
      break;
4218
4219
114k
    case AARCH64_OPND_IMM_MOV:
4220
114k
      switch (aarch64_get_qualifier_esize (opnds[0].qualifier))
4221
114k
  {
4222
34.9k
  case 4: /* e.g. MOV Wd, #<imm32>.  */
4223
34.9k
      {
4224
34.9k
        int imm32 = opnd->imm.value;
4225
34.9k
        snprintf (buf, size, "%s",
4226
34.9k
      style_imm (styler, "#0x%-20x", imm32));
4227
34.9k
        snprintf (comment, comment_size, "#%d", imm32);
4228
34.9k
      }
4229
34.9k
    break;
4230
79.3k
  case 8: /* e.g. MOV Xd, #<imm64>.  */
4231
79.3k
    snprintf (buf, size, "%s", style_imm (styler, "#0x%-20" PRIx64,
4232
79.3k
            opnd->imm.value));
4233
79.3k
    snprintf (comment, comment_size, "#%" PRIi64, opnd->imm.value);
4234
79.3k
    break;
4235
0
  default:
4236
0
    snprintf (buf, size, "<invalid>");
4237
0
    break;
4238
114k
  }
4239
114k
      break;
4240
4241
114k
    case AARCH64_OPND_FPIMM0:
4242
561
      snprintf (buf, size, "%s", style_imm (styler, "#0.0"));
4243
561
      break;
4244
4245
194k
    case AARCH64_OPND_LIMM:
4246
498k
    case AARCH64_OPND_AIMM:
4247
555k
    case AARCH64_OPND_HALF:
4248
555k
    case AARCH64_OPND_SVE_INV_LIMM:
4249
576k
    case AARCH64_OPND_SVE_LIMM:
4250
578k
    case AARCH64_OPND_SVE_LIMM_MOV:
4251
578k
      if (opnd->shifter.amount)
4252
166k
  snprintf (buf, size, "%s, %s %s",
4253
166k
      style_imm (styler, "#0x%" PRIx64, opnd->imm.value),
4254
166k
      style_sub_mnem (styler, "lsl"),
4255
166k
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
4256
411k
      else
4257
411k
  snprintf (buf, size, "%s",
4258
411k
      style_imm (styler, "#0x%" PRIx64, opnd->imm.value));
4259
578k
      break;
4260
4261
67
    case AARCH64_OPND_SIMD_IMM:
4262
3.21k
    case AARCH64_OPND_SIMD_IMM_SFT:
4263
3.21k
      if ((! opnd->shifter.amount && opnd->shifter.kind == AARCH64_MOD_LSL)
4264
3.21k
    || opnd->shifter.kind == AARCH64_MOD_NONE)
4265
1.35k
  snprintf (buf, size, "%s",
4266
1.35k
      style_imm (styler, "#0x%" PRIx64, opnd->imm.value));
4267
1.85k
      else
4268
1.85k
  snprintf (buf, size, "%s, %s %s",
4269
1.85k
      style_imm (styler, "#0x%" PRIx64, opnd->imm.value),
4270
1.85k
      style_sub_mnem (styler, aarch64_operand_modifiers[opnd->shifter.kind].name),
4271
1.85k
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
4272
3.21k
      break;
4273
4274
1.83k
    case AARCH64_OPND_SVE_AIMM:
4275
17.6k
    case AARCH64_OPND_SVE_ASIMM:
4276
17.6k
      if (opnd->shifter.amount)
4277
20
  snprintf (buf, size, "%s, %s %s",
4278
20
      style_imm (styler, "#%" PRIi64, opnd->imm.value),
4279
20
      style_sub_mnem (styler, "lsl"),
4280
20
      style_imm (styler, "#%" PRIi64, opnd->shifter.amount));
4281
17.6k
      else
4282
17.6k
  snprintf (buf, size, "%s",
4283
17.6k
      style_imm (styler, "#%" PRIi64, opnd->imm.value));
4284
17.6k
      break;
4285
4286
122
    case AARCH64_OPND_FPIMM:
4287
912
    case AARCH64_OPND_SIMD_FPIMM:
4288
2.12k
    case AARCH64_OPND_SVE_FPIMM8:
4289
2.12k
      switch (aarch64_get_qualifier_esize (opnds[0].qualifier))
4290
2.12k
  {
4291
1.07k
  case 2: /* e.g. FMOV <Hd>, #<imm>.  */
4292
1.07k
      {
4293
1.07k
        half_conv_t c;
4294
1.07k
        c.i = expand_fp_imm (2, opnd->imm.value);
4295
1.07k
        snprintf (buf, size, "%s", style_imm (styler, "#%.18e", c.f));
4296
1.07k
      }
4297
1.07k
    break;
4298
617
  case 4: /* e.g. FMOV <Vd>.4S, #<imm>.  */
4299
617
      {
4300
617
        single_conv_t c;
4301
617
        c.i = expand_fp_imm (4, opnd->imm.value);
4302
617
        snprintf (buf, size, "%s", style_imm (styler, "#%.18e", c.f));
4303
617
      }
4304
617
    break;
4305
433
  case 8: /* e.g. FMOV <Sd>, #<imm>.  */
4306
433
      {
4307
433
        double_conv_t c;
4308
433
        c.i = expand_fp_imm (8, opnd->imm.value);
4309
433
        snprintf (buf, size, "%s", style_imm (styler, "#%.18e", c.d));
4310
433
      }
4311
433
    break;
4312
0
  default:
4313
0
    snprintf (buf, size, "<invalid>");
4314
0
    break;
4315
2.12k
  }
4316
2.12k
      break;
4317
4318
3.08k
    case AARCH64_OPND_CCMP_IMM:
4319
16.0k
    case AARCH64_OPND_NZCV:
4320
17.1k
    case AARCH64_OPND_EXCEPTION:
4321
17.1k
    case AARCH64_OPND_UIMM4:
4322
24.2k
    case AARCH64_OPND_UIMM4_ADDG:
4323
24.3k
    case AARCH64_OPND_UIMM7:
4324
31.4k
    case AARCH64_OPND_UIMM10:
4325
31.4k
      if (optional_operand_p (opcode, idx)
4326
31.4k
    && (opnd->imm.value ==
4327
338
        (int64_t) get_optional_operand_default_value (opcode)))
4328
  /* Omit the operand, e.g. DCPS1.  */
4329
7
  break;
4330
31.3k
      snprintf (buf, size, "%s",
4331
31.3k
    style_imm (styler, "#0x%x", (unsigned int) opnd->imm.value));
4332
31.3k
      break;
4333
4334
29.3k
    case AARCH64_OPND_COND:
4335
30.3k
    case AARCH64_OPND_COND1:
4336
30.3k
      snprintf (buf, size, "%s",
4337
30.3k
    style_sub_mnem (styler, opnd->cond->names[0]));
4338
30.3k
      num_conds = ARRAY_SIZE (opnd->cond->names);
4339
58.0k
      for (i = 1; i < num_conds && opnd->cond->names[i]; ++i)
4340
27.7k
  {
4341
27.7k
    size_t len = comment != NULL ? strlen (comment) : 0;
4342
27.7k
    if (i == 1)
4343
20.9k
      snprintf (comment + len, comment_size - len, "%s = %s",
4344
20.9k
          opnd->cond->names[0], opnd->cond->names[i]);
4345
6.80k
    else
4346
6.80k
      snprintf (comment + len, comment_size - len, ", %s",
4347
6.80k
          opnd->cond->names[i]);
4348
27.7k
  }
4349
30.3k
      break;
4350
4351
283k
    case AARCH64_OPND_ADDR_ADRP:
4352
283k
      addr = ((pc + AARCH64_PCREL_OFFSET) & ~(uint64_t)0xfff)
4353
283k
  + opnd->imm.value;
4354
283k
      if (pcrel_p)
4355
283k
  *pcrel_p = 1;
4356
283k
      if (address)
4357
283k
  *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
283k
      snprintf (buf, size, "%s", style_addr (styler, "#0x%" PRIx64 , addr));
4363
283k
      break;
4364
4365
247k
    case AARCH64_OPND_ADDR_PCREL14:
4366
950k
    case AARCH64_OPND_ADDR_PCREL19:
4367
1.37M
    case AARCH64_OPND_ADDR_PCREL21:
4368
1.81M
    case AARCH64_OPND_ADDR_PCREL26:
4369
1.81M
      addr = pc + AARCH64_PCREL_OFFSET + opnd->imm.value;
4370
1.81M
      if (pcrel_p)
4371
1.81M
  *pcrel_p = 1;
4372
1.81M
      if (address)
4373
1.81M
  *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
1.81M
      snprintf (buf, size, "%s", style_addr (styler, "#0x%" PRIx64, addr));
4379
1.81M
      break;
4380
4381
255k
    case AARCH64_OPND_ADDR_SIMPLE:
4382
275k
    case AARCH64_OPND_SIMD_ADDR_SIMPLE:
4383
315k
    case AARCH64_OPND_SIMD_ADDR_POST:
4384
315k
      name = get_64bit_int_reg_name (opnd->addr.base_regno, 1);
4385
315k
      if (opnd->type == AARCH64_OPND_SIMD_ADDR_POST)
4386
40.0k
  {
4387
40.0k
    if (opnd->addr.offset.is_reg)
4388
38.4k
      snprintf (buf, size, "[%s], %s",
4389
38.4k
          style_reg (styler, name),
4390
38.4k
          style_reg (styler, "x%d", opnd->addr.offset.regno));
4391
1.57k
    else
4392
1.57k
      snprintf (buf, size, "[%s], %s",
4393
1.57k
          style_reg (styler, name),
4394
1.57k
          style_imm (styler, "#%d", opnd->addr.offset.imm));
4395
40.0k
  }
4396
275k
      else
4397
275k
  snprintf (buf, size, "[%s]", style_reg (styler, name));
4398
315k
      break;
4399
4400
26.2k
    case AARCH64_OPND_ADDR_REGOFF:
4401
26.2k
    case AARCH64_OPND_SVE_ADDR_R:
4402
54.3k
    case AARCH64_OPND_SVE_ADDR_RR:
4403
71.0k
    case AARCH64_OPND_SVE_ADDR_RR_LSL1:
4404
82.8k
    case AARCH64_OPND_SVE_ADDR_RR_LSL2:
4405
108k
    case AARCH64_OPND_SVE_ADDR_RR_LSL3:
4406
116k
    case AARCH64_OPND_SVE_ADDR_RR_LSL4:
4407
134k
    case AARCH64_OPND_SVE_ADDR_RX:
4408
147k
    case AARCH64_OPND_SVE_ADDR_RX_LSL1:
4409
164k
    case AARCH64_OPND_SVE_ADDR_RX_LSL2:
4410
174k
    case AARCH64_OPND_SVE_ADDR_RX_LSL3:
4411
174k
      print_register_offset_address
4412
174k
  (buf, size, opnd, get_64bit_int_reg_name (opnd->addr.base_regno, 1),
4413
174k
   get_offset_int_reg_name (opnd), styler);
4414
174k
      break;
4415
4416
17.3k
    case AARCH64_OPND_SVE_ADDR_ZX:
4417
17.3k
      print_register_offset_address
4418
17.3k
  (buf, size, opnd,
4419
17.3k
   get_addr_sve_reg_name (opnd->addr.base_regno, opnd->qualifier),
4420
17.3k
   get_64bit_int_reg_name (opnd->addr.offset.regno, 0), styler);
4421
17.3k
      break;
4422
4423
28.9k
    case AARCH64_OPND_SVE_ADDR_RZ:
4424
33.2k
    case AARCH64_OPND_SVE_ADDR_RZ_LSL1:
4425
36.6k
    case AARCH64_OPND_SVE_ADDR_RZ_LSL2:
4426
41.4k
    case AARCH64_OPND_SVE_ADDR_RZ_LSL3:
4427
50.6k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW_14:
4428
111k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW_22:
4429
114k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW1_14:
4430
127k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW1_22:
4431
129k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW2_14:
4432
140k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW2_22:
4433
142k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW3_14:
4434
156k
    case AARCH64_OPND_SVE_ADDR_RZ_XTW3_22:
4435
156k
      print_register_offset_address
4436
156k
  (buf, size, opnd, get_64bit_int_reg_name (opnd->addr.base_regno, 1),
4437
156k
   get_addr_sve_reg_name (opnd->addr.offset.regno, opnd->qualifier),
4438
156k
   styler);
4439
156k
      break;
4440
4441
697k
    case AARCH64_OPND_ADDR_SIMM7:
4442
882k
    case AARCH64_OPND_ADDR_SIMM9:
4443
882k
    case AARCH64_OPND_ADDR_SIMM9_2:
4444
898k
    case AARCH64_OPND_ADDR_SIMM10:
4445
936k
    case AARCH64_OPND_ADDR_SIMM11:
4446
951k
    case AARCH64_OPND_ADDR_SIMM13:
4447
975k
    case AARCH64_OPND_ADDR_OFFSET:
4448
976k
    case AARCH64_OPND_SME_ADDR_RI_U4xVL:
4449
977k
    case AARCH64_OPND_SVE_ADDR_RI_S4x16:
4450
979k
    case AARCH64_OPND_SVE_ADDR_RI_S4x32:
4451
1.05M
    case AARCH64_OPND_SVE_ADDR_RI_S4xVL:
4452
1.06M
    case AARCH64_OPND_SVE_ADDR_RI_S4x2xVL:
4453
1.07M
    case AARCH64_OPND_SVE_ADDR_RI_S4x3xVL:
4454
1.07M
    case AARCH64_OPND_SVE_ADDR_RI_S4x4xVL:
4455
1.08M
    case AARCH64_OPND_SVE_ADDR_RI_S6xVL:
4456
1.09M
    case AARCH64_OPND_SVE_ADDR_RI_S9xVL:
4457
1.10M
    case AARCH64_OPND_SVE_ADDR_RI_U6:
4458
1.11M
    case AARCH64_OPND_SVE_ADDR_RI_U6x2:
4459
1.12M
    case AARCH64_OPND_SVE_ADDR_RI_U6x4:
4460
1.12M
    case AARCH64_OPND_SVE_ADDR_RI_U6x8:
4461
1.12M
      print_immediate_offset_address
4462
1.12M
  (buf, size, opnd, get_64bit_int_reg_name (opnd->addr.base_regno, 1),
4463
1.12M
   styler);
4464
1.12M
      break;
4465
4466
8.40k
    case AARCH64_OPND_SVE_ADDR_ZI_U5:
4467
17.0k
    case AARCH64_OPND_SVE_ADDR_ZI_U5x2:
4468
22.2k
    case AARCH64_OPND_SVE_ADDR_ZI_U5x4:
4469
25.2k
    case AARCH64_OPND_SVE_ADDR_ZI_U5x8:
4470
25.2k
      print_immediate_offset_address
4471
25.2k
  (buf, size, opnd,
4472
25.2k
   get_addr_sve_reg_name (opnd->addr.base_regno, opnd->qualifier),
4473
25.2k
   styler);
4474
25.2k
      break;
4475
4476
1.19k
    case AARCH64_OPND_SVE_ADDR_ZZ_LSL:
4477
1.52k
    case AARCH64_OPND_SVE_ADDR_ZZ_SXTW:
4478
2.63k
    case AARCH64_OPND_SVE_ADDR_ZZ_UXTW:
4479
2.63k
      print_register_offset_address
4480
2.63k
  (buf, size, opnd,
4481
2.63k
   get_addr_sve_reg_name (opnd->addr.base_regno, opnd->qualifier),
4482
2.63k
   get_addr_sve_reg_name (opnd->addr.offset.regno, opnd->qualifier),
4483
2.63k
   styler);
4484
2.63k
      break;
4485
4486
400k
    case AARCH64_OPND_ADDR_UIMM12:
4487
400k
      name = get_64bit_int_reg_name (opnd->addr.base_regno, 1);
4488
400k
      if (opnd->addr.offset.imm)
4489
381k
  snprintf (buf, size, "[%s, %s]",
4490
381k
      style_reg (styler, name),
4491
381k
      style_imm (styler, "#%d", opnd->addr.offset.imm));
4492
19.4k
      else
4493
19.4k
  snprintf (buf, size, "[%s]", style_reg (styler, name));
4494
400k
      break;
4495
4496
9.38k
    case AARCH64_OPND_SYSREG:
4497
9.55M
      for (i = 0; aarch64_sys_regs[i].name; ++i)
4498
9.54M
  {
4499
9.54M
    const aarch64_sys_reg *sr = aarch64_sys_regs + i;
4500
4501
9.54M
    bool exact_match
4502
9.54M
      = (!(sr->flags & (F_REG_READ | F_REG_WRITE))
4503
9.54M
      || (sr->flags & opnd->sysreg.flags) == opnd->sysreg.flags)
4504
9.54M
      && 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
9.54M
    if (aarch64_sys_regs[i].value == opnd->sysreg.value
4509
9.54M
        && ! aarch64_sys_reg_deprecated_p (aarch64_sys_regs[i].flags)
4510
9.54M
        && (name == NULL || exact_match))
4511
243
      {
4512
243
        name = aarch64_sys_regs[i].name;
4513
243
        if (exact_match)
4514
152
    {
4515
152
      if (notes)
4516
152
        *notes = NULL;
4517
152
      break;
4518
152
    }
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
91
        if (aarch64_sys_regs[i].flags & F_REG_WRITE)
4525
0
    *notes = _("reading from a write-only register");
4526
91
        else if (aarch64_sys_regs[i].flags & F_REG_READ)
4527
40
    *notes = _("writing to a read-only register");
4528
91
      }
4529
9.54M
  }
4530
4531
9.38k
      if (name)
4532
242
  snprintf (buf, size, "%s", style_reg (styler, name));
4533
9.14k
      else
4534
9.14k
  {
4535
    /* Implementation defined system register.  */
4536
9.14k
    unsigned int value = opnd->sysreg.value;
4537
9.14k
    snprintf (buf, size, "%s",
4538
9.14k
        style_reg (styler, "s%u_%u_c%u_c%u_%u",
4539
9.14k
             (value >> 14) & 0x3, (value >> 11) & 0x7,
4540
9.14k
             (value >> 7) & 0xf, (value >> 3) & 0xf,
4541
9.14k
             value & 0x7));
4542
9.14k
  }
4543
9.38k
      break;
4544
4545
47
    case AARCH64_OPND_PSTATEFIELD:
4546
136
      for (i = 0; aarch64_pstatefields[i].name; ++i)
4547
136
        if (aarch64_pstatefields[i].value == opnd->pstatefield)
4548
47
          {
4549
            /* PSTATEFIELD name is encoded partially in CRm[3:1] for SVCRSM,
4550
               SVCRZA and SVCRSMZA.  */
4551
47
            uint32_t flags = aarch64_pstatefields[i].flags;
4552
47
            if (flags & F_REG_IN_CRM
4553
47
                && (PSTATE_DECODE_CRM (opnd->sysreg.flags)
4554
0
                    != PSTATE_DECODE_CRM (flags)))
4555
0
              continue;
4556
47
            break;
4557
47
          }
4558
47
      assert (aarch64_pstatefields[i].name);
4559
47
      snprintf (buf, size, "%s",
4560
47
    style_reg (styler, aarch64_pstatefields[i].name));
4561
47
      break;
4562
4563
27
    case AARCH64_OPND_SYSREG_AT:
4564
105
    case AARCH64_OPND_SYSREG_DC:
4565
361
    case AARCH64_OPND_SYSREG_IC:
4566
367
    case AARCH64_OPND_SYSREG_TLBI:
4567
367
    case AARCH64_OPND_SYSREG_SR:
4568
367
      snprintf (buf, size, "%s", style_reg (styler, opnd->sysins_op->name));
4569
367
      break;
4570
4571
27
    case AARCH64_OPND_BARRIER:
4572
45
    case AARCH64_OPND_BARRIER_DSB_NXS:
4573
45
      {
4574
45
  if (opnd->barrier->name[0] == '#')
4575
26
    snprintf (buf, size, "%s", style_imm (styler, opnd->barrier->name));
4576
19
  else
4577
19
    snprintf (buf, size, "%s",
4578
19
        style_sub_mnem (styler, opnd->barrier->name));
4579
45
      }
4580
45
      break;
4581
4582
278
    case AARCH64_OPND_BARRIER_ISB:
4583
      /* Operand can be omitted, e.g. in DCPS1.  */
4584
278
      if (! optional_operand_p (opcode, idx)
4585
278
    || (opnd->barrier->value
4586
278
        != get_optional_operand_default_value (opcode)))
4587
34
  snprintf (buf, size, "%s",
4588
34
      style_imm (styler, "#0x%x", opnd->barrier->value));
4589
278
      break;
4590
4591
68.4k
    case AARCH64_OPND_PRFOP:
4592
68.4k
      if (opnd->prfop->name != NULL)
4593
39.2k
  snprintf (buf, size, "%s", style_sub_mnem (styler, opnd->prfop->name));
4594
29.1k
      else
4595
29.1k
  snprintf (buf, size, "%s", style_imm (styler, "#0x%02x",
4596
29.1k
                opnd->prfop->value));
4597
68.4k
      break;
4598
4599
191
    case AARCH64_OPND_RPRFMOP:
4600
191
      enum_value = opnd->imm.value;
4601
191
      if (enum_value < ARRAY_SIZE (aarch64_rprfmop_array)
4602
191
    && aarch64_rprfmop_array[enum_value])
4603
8
  snprintf (buf, size, "%s",
4604
8
      style_reg (styler, aarch64_rprfmop_array[enum_value]));
4605
183
      else
4606
183
  snprintf (buf, size, "%s",
4607
183
      style_imm (styler, "#%" PRIi64, opnd->imm.value));
4608
191
      break;
4609
4610
18
    case AARCH64_OPND_BARRIER_PSB:
4611
18
      snprintf (buf, size, "%s", style_sub_mnem (styler, "csync"));
4612
18
      break;
4613
4614
207
    case AARCH64_OPND_SME_ZT0:
4615
207
      snprintf (buf, size, "%s", style_reg (styler, "zt0"));
4616
207
      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
1
    case AARCH64_OPND_SME_ZT0_LIST:
4624
1
      snprintf (buf, size, "{%s}", style_reg (styler, "zt0"));
4625
1
      break;
4626
4627
534
    case AARCH64_OPND_BTI_TARGET:
4628
534
      if ((HINT_FLAG (opnd->hint_option->value) & HINT_OPD_F_NOPRINT) == 0)
4629
533
  snprintf (buf, size, "%s",
4630
533
      style_sub_mnem (styler, opnd->hint_option->name));
4631
534
      break;
4632
4633
11.7k
    case AARCH64_OPND_MOPS_ADDR_Rd:
4634
21.2k
    case AARCH64_OPND_MOPS_ADDR_Rs:
4635
21.2k
      snprintf (buf, size, "[%s]!",
4636
21.2k
    style_reg (styler,
4637
21.2k
         get_int_reg_name (opnd->reg.regno,
4638
21.2k
               AARCH64_OPND_QLF_X, 0)));
4639
21.2k
      break;
4640
4641
11.7k
    case AARCH64_OPND_MOPS_WB_Rn:
4642
11.7k
      snprintf (buf, size, "%s!",
4643
11.7k
    style_reg (styler, get_int_reg_name (opnd->reg.regno,
4644
11.7k
                 AARCH64_OPND_QLF_X, 0)));
4645
11.7k
      break;
4646
4647
0
    default:
4648
0
      snprintf (buf, size, "<invalid>");
4649
0
      break;
4650
19.2M
    }
4651
19.2M
}
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
243
{
5745
243
  return (reg_flags & F_DEPRECATED) != 0;
5746
243
}
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
524
{
5952
524
  return (sys_ins_reg->flags & F_HASXT) != 0;
5953
524
}
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
140k
#define BIT(INSN,BT)     (((INSN) >> (BT)) & 1)
6091
213k
#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
71.2k
{
6100
71.2k
  int t  = BITS (insn, 4, 0);
6101
71.2k
  int n  = BITS (insn, 9, 5);
6102
71.2k
  int t2 = BITS (insn, 14, 10);
6103
6104
71.2k
  if (BIT (insn, 23))
6105
23.9k
    {
6106
      /* Write back enabled.  */
6107
23.9k
      if ((t == n || t2 == n) && n != 31)
6108
1.57k
  return ERR_UND;
6109
23.9k
    }
6110
6111
69.7k
  if (BIT (insn, 22))
6112
69.7k
    {
6113
      /* Load */
6114
69.7k
      if (t == t2)
6115
3.81k
  return ERR_UND;
6116
69.7k
    }
6117
6118
65.8k
  return ERR_OK;
6119
69.7k
}
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
5.88k
{
6130
5.88k
  const aarch64_insn undef_pattern = 0x3;
6131
5.88k
  aarch64_insn value;
6132
6133
5.88k
  assert (inst->opcode);
6134
5.88k
  assert (inst->opcode->operands[2] == AARCH64_OPND_Em);
6135
5.88k
  value = encoding ? inst->value : insn;
6136
5.88k
  assert (value);
6137
6138
5.88k
  if (undef_pattern == extract_fields (value, 0, 2, FLD_sz, FLD_L))
6139
1.36k
    return ERR_UND;
6140
6141
4.51k
  return ERR_OK;
6142
5.88k
}
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
12.7k
{
6157
12.7k
  int rd, rs, rn;
6158
6159
12.7k
  rd = inst->operands[0].reg.regno;
6160
12.7k
  rs = inst->operands[1].reg.regno;
6161
12.7k
  rn = inst->operands[2].reg.regno;
6162
12.7k
  if (rd == rs || rd == rn || rs == rn)
6163
980
    {
6164
980
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6165
980
      mismatch_detail->error
6166
980
  = _("the three register operands must be distinct from one another");
6167
980
      mismatch_detail->index = -1;
6168
980
      return ERR_UND;
6169
980
    }
6170
6171
11.7k
  return ERR_OK;
6172
12.7k
}
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
5.09k
{
6180
5.09k
  insn_sequence->instr[insn_sequence->num_added_insns++] = *inst;
6181
5.09k
}
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
11.6k
{
6191
11.6k
  int num_req_entries = 0;
6192
6193
11.6k
  if (insn_sequence->instr)
6194
4.70k
    {
6195
4.70k
      XDELETE (insn_sequence->instr);
6196
4.70k
      insn_sequence->instr = NULL;
6197
4.70k
    }
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
11.6k
  if (inst && inst->opcode->constraints & C_SCAN_MOVPRFX)
6203
333
    num_req_entries = 1;
6204
11.6k
  if (inst && (inst->opcode->constraints & C_SCAN_MOPS_PME) == C_SCAN_MOPS_P)
6205
4.37k
    num_req_entries = 2;
6206
6207
11.6k
  insn_sequence->num_added_insns = 0;
6208
11.6k
  insn_sequence->num_allocated_insns = num_req_entries;
6209
6210
11.6k
  if (num_req_entries != 0)
6211
4.70k
    {
6212
4.70k
      insn_sequence->instr = XCNEWVEC (aarch64_inst, num_req_entries);
6213
4.70k
      add_insn_to_sequence (inst, insn_sequence);
6214
4.70k
    }
6215
11.6k
}
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
242k
{
6231
242k
  const struct aarch64_opcode *opcode;
6232
242k
  const struct aarch64_inst *prev_insn;
6233
242k
  int i;
6234
6235
242k
  opcode = inst->opcode;
6236
242k
  if (insn_sequence->instr)
6237
4.95k
    prev_insn = insn_sequence->instr + (insn_sequence->num_added_insns - 1);
6238
237k
  else
6239
237k
    prev_insn = NULL;
6240
6241
242k
  if (prev_insn
6242
242k
      && (prev_insn->opcode->constraints & C_SCAN_MOPS_PME)
6243
242k
      && prev_insn->opcode != opcode - 1)
6244
4.25k
    {
6245
4.25k
      mismatch_detail->kind = AARCH64_OPDE_EXPECTED_A_AFTER_B;
6246
4.25k
      mismatch_detail->error = NULL;
6247
4.25k
      mismatch_detail->index = -1;
6248
4.25k
      mismatch_detail->data[0].s = prev_insn->opcode[1].name;
6249
4.25k
      mismatch_detail->data[1].s = prev_insn->opcode->name;
6250
4.25k
      mismatch_detail->non_fatal = true;
6251
4.25k
      return false;
6252
4.25k
    }
6253
6254
237k
  if (opcode->constraints & C_SCAN_MOPS_PME)
6255
7.33k
    {
6256
7.33k
      if (is_new_section || !prev_insn || prev_insn->opcode != opcode - 1)
6257
6.96k
  {
6258
6.96k
    mismatch_detail->kind = AARCH64_OPDE_A_SHOULD_FOLLOW_B;
6259
6.96k
    mismatch_detail->error = NULL;
6260
6.96k
    mismatch_detail->index = -1;
6261
6.96k
    mismatch_detail->data[0].s = opcode->name;
6262
6.96k
    mismatch_detail->data[1].s = opcode[-1].name;
6263
6.96k
    mismatch_detail->non_fatal = true;
6264
6.96k
    return false;
6265
6.96k
  }
6266
6267
642
      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
641
  if ((opcode->operands[i] == AARCH64_OPND_MOPS_ADDR_Rd
6271
641
       || opcode->operands[i] == AARCH64_OPND_MOPS_ADDR_Rs
6272
641
       || opcode->operands[i] == AARCH64_OPND_MOPS_WB_Rn)
6273
641
      && prev_insn->operands[i].reg.regno != inst->operands[i].reg.regno)
6274
368
    {
6275
368
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6276
368
      if (opcode->operands[i] == AARCH64_OPND_MOPS_ADDR_Rd)
6277
226
        mismatch_detail->error = _("destination register differs from "
6278
142
           "preceding instruction");
6279
142
      else if (opcode->operands[i] == AARCH64_OPND_MOPS_ADDR_Rs)
6280
3
        mismatch_detail->error = _("source register differs from "
6281
139
           "preceding instruction");
6282
139
      else
6283
139
        mismatch_detail->error = _("size register differs from "
6284
368
           "preceding instruction");
6285
368
      mismatch_detail->index = i;
6286
368
      mismatch_detail->non_fatal = true;
6287
368
      return false;
6288
368
    }
6289
369
    }
6290
6291
230k
  return true;
6292
237k
}
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
8.59M
{
6314
8.59M
  assert (inst);
6315
8.59M
  assert (inst->opcode);
6316
6317
8.59M
  const struct aarch64_opcode *opcode = inst->opcode;
6318
8.59M
  if (!opcode->constraints && !insn_sequence->instr)
6319
8.34M
    return ERR_OK;
6320
6321
246k
  assert (insn_sequence);
6322
6323
246k
  enum err_type res = ERR_OK;
6324
6325
  /* This instruction puts a constraint on the insn_sequence.  */
6326
246k
  if (opcode->flags & F_SCAN)
6327
4.70k
    {
6328
4.70k
      if (insn_sequence->instr)
6329
148
  {
6330
148
    mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6331
148
    mismatch_detail->error = _("instruction opens new dependency "
6332
148
             "sequence without ending previous one");
6333
148
    mismatch_detail->index = -1;
6334
148
    mismatch_detail->non_fatal = true;
6335
148
    res = ERR_VFI;
6336
148
  }
6337
6338
4.70k
      init_insn_sequence (inst, insn_sequence);
6339
4.70k
      return res;
6340
4.70k
    }
6341
6342
242k
  bool is_new_section = (!encoding && pc == 0);
6343
242k
  if (!verify_mops_pme_sequence (inst, is_new_section, mismatch_detail,
6344
242k
         insn_sequence))
6345
11.5k
    {
6346
11.5k
      res = ERR_VFI;
6347
11.5k
      if ((opcode->constraints & C_SCAN_MOPS_PME) != C_SCAN_MOPS_M)
6348
6.65k
  init_insn_sequence (NULL, insn_sequence);
6349
11.5k
    }
6350
6351
  /* Verify constraints on an existing sequence.  */
6352
242k
  if (insn_sequence->instr)
6353
713
    {
6354
713
      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
713
      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
713
      if (inst_opcode->constraints & C_SCAN_MOVPRFX)
6371
322
  {
6372
    /* Check to see if the MOVPRFX SVE instruction is followed by an SVE
6373
       instruction for better error messages.  */
6374
322
    if (!opcode->avariant
6375
322
        || !(*opcode->avariant &
6376
322
       (AARCH64_FEATURE_SVE | AARCH64_FEATURE_SVE2)))
6377
254
      {
6378
254
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6379
254
        mismatch_detail->error = _("SVE instruction expected after "
6380
254
           "`movprfx'");
6381
254
        mismatch_detail->index = -1;
6382
254
        mismatch_detail->non_fatal = true;
6383
254
        res = ERR_VFI;
6384
254
        goto done;
6385
254
      }
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
68
    if (!(opcode->constraints & C_SCAN_MOVPRFX))
6390
30
      {
6391
30
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6392
30
        mismatch_detail->error = _("SVE `movprfx' compatible instruction "
6393
30
           "expected");
6394
30
        mismatch_detail->index = -1;
6395
30
        mismatch_detail->non_fatal = true;
6396
30
        res = ERR_VFI;
6397
30
        goto done;
6398
30
      }
6399
6400
    /* Next check for usage of the predicate register.  */
6401
38
    aarch64_opnd_info blk_dest = insn_sequence->instr->operands[0];
6402
38
    aarch64_opnd_info blk_pred, inst_pred;
6403
38
    memset (&blk_pred, 0, sizeof (aarch64_opnd_info));
6404
38
    memset (&inst_pred, 0, sizeof (aarch64_opnd_info));
6405
38
    bool predicated = false;
6406
38
    assert (blk_dest.type == AARCH64_OPND_SVE_Zd);
6407
6408
    /* Determine if the movprfx instruction used is predicated or not.  */
6409
38
    if (insn_sequence->instr->operands[1].type == AARCH64_OPND_SVE_Pg3)
6410
38
      {
6411
38
        predicated = true;
6412
38
        blk_pred = insn_sequence->instr->operands[1];
6413
38
      }
6414
6415
38
    unsigned char max_elem_size = 0;
6416
38
    unsigned char current_elem_size;
6417
38
    int num_op_used = 0, last_op_usage = 0;
6418
38
    int i, inst_pred_idx = -1;
6419
38
    int num_ops = aarch64_num_of_operands (opcode);
6420
184
    for (i = 0; i < num_ops; i++)
6421
146
      {
6422
146
        aarch64_opnd_info inst_op = inst->operands[i];
6423
146
        switch (inst_op.type)
6424
146
    {
6425
49
      case AARCH64_OPND_SVE_Zd:
6426
59
      case AARCH64_OPND_SVE_Zm_5:
6427
81
      case AARCH64_OPND_SVE_Zm_16:
6428
96
      case AARCH64_OPND_SVE_Zn:
6429
96
      case AARCH64_OPND_SVE_Zt:
6430
96
      case AARCH64_OPND_SVE_Vm:
6431
96
      case AARCH64_OPND_SVE_Vn:
6432
96
      case AARCH64_OPND_Va:
6433
96
      case AARCH64_OPND_Vn:
6434
96
      case AARCH64_OPND_Vm:
6435
96
      case AARCH64_OPND_Sn:
6436
96
      case AARCH64_OPND_Sm:
6437
96
        if (inst_op.reg.regno == blk_dest.reg.regno)
6438
20
          {
6439
20
      num_op_used++;
6440
20
      last_op_usage = i;
6441
20
          }
6442
96
        current_elem_size
6443
96
          = aarch64_get_qualifier_esize (inst_op.qualifier);
6444
96
        if (current_elem_size > max_elem_size)
6445
38
          max_elem_size = current_elem_size;
6446
96
        break;
6447
0
      case AARCH64_OPND_SVE_Pd:
6448
32
      case AARCH64_OPND_SVE_Pg3:
6449
32
      case AARCH64_OPND_SVE_Pg4_5:
6450
32
      case AARCH64_OPND_SVE_Pg4_10:
6451
34
      case AARCH64_OPND_SVE_Pg4_16:
6452
34
      case AARCH64_OPND_SVE_Pm:
6453
34
      case AARCH64_OPND_SVE_Pn:
6454
34
      case AARCH64_OPND_SVE_Pt:
6455
34
      case AARCH64_OPND_SME_Pm:
6456
34
        inst_pred = inst_op;
6457
34
        inst_pred_idx = i;
6458
34
        break;
6459
16
      default:
6460
16
        break;
6461
146
    }
6462
146
      }
6463
6464
38
     assert (max_elem_size != 0);
6465
38
     aarch64_opnd_info inst_dest = inst->operands[0];
6466
     /* Determine the size that should be used to compare against the
6467
        movprfx size.  */
6468
38
     current_elem_size
6469
38
       = opcode->constraints & C_MAX_ELEM
6470
38
         ? max_elem_size
6471
38
         : aarch64_get_qualifier_esize (inst_dest.qualifier);
6472
6473
    /* If movprfx is predicated do some extra checks.  */
6474
38
    if (predicated)
6475
38
      {
6476
        /* The instruction must be predicated.  */
6477
38
        if (inst_pred_idx < 0)
6478
4
    {
6479
4
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6480
4
      mismatch_detail->error = _("predicated instruction expected "
6481
4
               "after `movprfx'");
6482
4
      mismatch_detail->index = -1;
6483
4
      mismatch_detail->non_fatal = true;
6484
4
      res = ERR_VFI;
6485
4
      goto done;
6486
4
    }
6487
6488
        /* The instruction must have a merging predicate.  */
6489
34
        if (inst_pred.qualifier != AARCH64_OPND_QLF_P_M)
6490
2
    {
6491
2
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6492
2
      mismatch_detail->error = _("merging predicate expected due "
6493
2
               "to preceding `movprfx'");
6494
2
      mismatch_detail->index = inst_pred_idx;
6495
2
      mismatch_detail->non_fatal = true;
6496
2
      res = ERR_VFI;
6497
2
      goto done;
6498
2
    }
6499
6500
        /* The same register must be used in instruction.  */
6501
32
        if (blk_pred.reg.regno != inst_pred.reg.regno)
6502
10
    {
6503
10
      mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6504
10
      mismatch_detail->error = _("predicate register differs "
6505
10
               "from that in preceding "
6506
10
               "`movprfx'");
6507
10
      mismatch_detail->index = inst_pred_idx;
6508
10
      mismatch_detail->non_fatal = true;
6509
10
      res = ERR_VFI;
6510
10
      goto done;
6511
10
    }
6512
32
      }
6513
6514
    /* Destructive operations by definition must allow one usage of the
6515
       same register.  */
6516
22
    int allowed_usage
6517
22
      = aarch64_is_destructive_by_operands (opcode) ? 2 : 1;
6518
6519
    /* Operand is not used at all.  */
6520
22
    if (num_op_used == 0)
6521
16
      {
6522
16
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6523
16
        mismatch_detail->error = _("output register of preceding "
6524
16
           "`movprfx' not used in current "
6525
16
           "instruction");
6526
16
        mismatch_detail->index = 0;
6527
16
        mismatch_detail->non_fatal = true;
6528
16
        res = ERR_VFI;
6529
16
        goto done;
6530
16
      }
6531
6532
    /* We now know it's used, now determine exactly where it's used.  */
6533
6
    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
6
    if (num_op_used > allowed_usage)
6546
6
      {
6547
6
        mismatch_detail->kind = AARCH64_OPDE_SYNTAX_ERROR;
6548
6
        mismatch_detail->error = _("output register of preceding "
6549
6
           "`movprfx' used as input");
6550
6
        mismatch_detail->index = last_op_usage;
6551
6
        mismatch_detail->non_fatal = true;
6552
6
        res = ERR_VFI;
6553
6
        goto done;
6554
6
      }
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
713
    done:
6574
713
      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
322
  init_insn_sequence (NULL, insn_sequence);
6578
391
      else
6579
391
  add_insn_to_sequence (inst, insn_sequence);
6580
713
    }
6581
6582
242k
  return res;
6583
242k
}
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
3.99k
{
6593
3.99k
  int64_t svalue = uvalue;
6594
3.99k
  uint64_t upper = (uint64_t) -1 << (esize * 4) << (esize * 4);
6595
6596
3.99k
  if ((uvalue & ~upper) != uvalue && (uvalue | upper) != uvalue)
6597
0
    return false;
6598
3.99k
  if (esize <= 4 || (uint32_t) uvalue == (uint32_t) (uvalue >> 32))
6599
3.67k
    {
6600
3.67k
      svalue = (int32_t) uvalue;
6601
3.67k
      if (esize <= 2 || (uint16_t) uvalue == (uint16_t) (uvalue >> 16))
6602
706
  {
6603
706
    svalue = (int16_t) uvalue;
6604
706
    if (esize == 1 || (uint8_t) uvalue == (uint8_t) (uvalue >> 8))
6605
444
      return false;
6606
706
  }
6607
3.67k
    }
6608
3.54k
  if ((svalue & 0xff) == 0)
6609
2.43k
    svalue /= 256;
6610
3.54k
  return svalue < -128 || svalue >= 128;
6611
3.99k
}
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"