introduce svp64 prefixing
[binutils-gdb.git] / opcodes / ppc-opc.c
1 /* ppc-opc.c -- PowerPC opcode list
2 Copyright (C) 1994-2021 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, Cygnus Support
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 file; see the file COPYING. If not, write to the
19 Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
21
22 #include "sysdep.h"
23 #include <stdio.h>
24 #include "opcode/ppc.h"
25 #include "opintl.h"
26
27 /* This file holds the PowerPC opcode table. The opcode table
28 includes almost all of the extended instruction mnemonics. This
29 permits the disassembler to use them, and simplifies the assembler
30 logic, at the cost of increasing the table size. The table is
31 strictly constant data, so the compiler should be able to put it in
32 the text segment.
33
34 This file also holds the operand table. All knowledge about
35 inserting operands into instructions and vice-versa is kept in this
36 file. */
37
38 /* The functions used to insert and extract complicated operands. */
39
40 /* The ARX, ARY, RX and RY operands are alternate encodings of GPRs. */
41
42 static uint64_t
43 insert_arx (uint64_t insn,
44 int64_t value,
45 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
46 const char **errmsg ATTRIBUTE_UNUSED)
47 {
48 value -= 8;
49 if (value < 0 || value >= 16)
50 {
51 *errmsg = _("invalid register");
52 value = 0xf;
53 }
54 return insn | value;
55 }
56
57 static int64_t
58 extract_arx (uint64_t insn,
59 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
60 int *invalid ATTRIBUTE_UNUSED)
61 {
62 return (insn & 0xf) + 8;
63 }
64
65 static uint64_t
66 insert_ary (uint64_t insn,
67 int64_t value,
68 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
69 const char **errmsg ATTRIBUTE_UNUSED)
70 {
71 value -= 8;
72 if (value < 0 || value >= 16)
73 {
74 *errmsg = _("invalid register");
75 value = 0xf;
76 }
77 return insn | (value << 4);
78 }
79
80 static int64_t
81 extract_ary (uint64_t insn,
82 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
83 int *invalid ATTRIBUTE_UNUSED)
84 {
85 return ((insn >> 4) & 0xf) + 8;
86 }
87
88 static uint64_t
89 insert_rx (uint64_t insn,
90 int64_t value,
91 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
92 const char **errmsg)
93 {
94 if (value >= 0 && value < 8)
95 ;
96 else if (value >= 24 && value <= 31)
97 value -= 16;
98 else
99 {
100 *errmsg = _("invalid register");
101 value = 0xf;
102 }
103 return insn | value;
104 }
105
106 static int64_t
107 extract_rx (uint64_t insn,
108 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
109 int *invalid ATTRIBUTE_UNUSED)
110 {
111 int64_t value = insn & 0xf;
112 if (value >= 0 && value < 8)
113 return value;
114 else
115 return value + 16;
116 }
117
118 static uint64_t
119 insert_ry (uint64_t insn,
120 int64_t value,
121 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
122 const char **errmsg)
123 {
124 if (value >= 0 && value < 8)
125 ;
126 else if (value >= 24 && value <= 31)
127 value -= 16;
128 else
129 {
130 *errmsg = _("invalid register");
131 value = 0xf;
132 }
133 return insn | (value << 4);
134 }
135
136 static int64_t
137 extract_ry (uint64_t insn,
138 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
139 int *invalid ATTRIBUTE_UNUSED)
140 {
141 int64_t value = (insn >> 4) & 0xf;
142 if (value >= 0 && value < 8)
143 return value;
144 else
145 return value + 16;
146 }
147
148 /* The BA and BB fields in an XL form instruction or the RA and RB fields or
149 VRA and VRB fields in a VX form instruction when they must be the same.
150 This is used for extended mnemonics like crclr. The extraction function
151 enforces that the fields are the same. */
152
153 static uint64_t
154 insert_bab (uint64_t insn,
155 int64_t value,
156 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
157 const char **errmsg ATTRIBUTE_UNUSED)
158 {
159 value &= 0x1f;
160 return insn | (value << 16) | (value << 11);
161 }
162
163 static int64_t
164 extract_bab (uint64_t insn,
165 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
166 int *invalid)
167 {
168 int64_t ba = (insn >> 16) & 0x1f;
169 int64_t bb = (insn >> 11) & 0x1f;
170
171 if (ba != bb)
172 *invalid = 1;
173 return ba;
174 }
175
176 /* The BT, BA and BB fields in an XL form instruction when they must all be
177 the same. This is used for extended mnemonics like crclr. The extraction
178 function enforces that the fields are the same. */
179
180 static uint64_t
181 insert_btab (uint64_t insn,
182 int64_t value,
183 ppc_cpu_t dialect,
184 const char **errmsg)
185 {
186 value &= 0x1f;
187 return (value << 21) | insert_bab (insn, value, dialect, errmsg);
188 }
189
190 static int64_t
191 extract_btab (uint64_t insn,
192 ppc_cpu_t dialect,
193 int *invalid)
194 {
195 int64_t bt = (insn >> 21) & 0x1f;
196 int64_t bab = extract_bab (insn, dialect, invalid);
197
198 if (bt != bab)
199 *invalid = 1;
200 return bt;
201 }
202
203 /* The BD field in a B form instruction when the - modifier is used.
204 This modifier means that the branch is not expected to be taken.
205 For chips built to versions of the architecture prior to version 2
206 (ie. not Power4 compatible), we set the y bit of the BO field to 1
207 if the offset is negative. When extracting, we require that the y
208 bit be 1 and that the offset be positive, since if the y bit is 0
209 we just want to print the normal form of the instruction.
210 Power4 compatible targets use two bits, "a", and "t", instead of
211 the "y" bit. "at" == 00 => no hint, "at" == 01 => unpredictable,
212 "at" == 10 => not taken, "at" == 11 => taken. The "t" bit is 00001
213 in BO field, the "a" bit is 00010 for branch on CR(BI) and 01000
214 for branch on CTR. We only handle the taken/not-taken hint here.
215 Note that we don't relax the conditions tested here when
216 disassembling with -Many because insns using extract_bdm and
217 extract_bdp always occur in pairs. One or the other will always
218 be valid. */
219
220 #define ISA_V2 (PPC_OPCODE_POWER4 | PPC_OPCODE_E500MC | PPC_OPCODE_TITAN)
221
222 static uint64_t
223 insert_bdm (uint64_t insn,
224 int64_t value,
225 ppc_cpu_t dialect,
226 const char **errmsg ATTRIBUTE_UNUSED)
227 {
228 if ((dialect & ISA_V2) == 0)
229 {
230 if ((value & 0x8000) != 0)
231 insn |= 1 << 21;
232 }
233 else
234 {
235 if ((insn & (0x14 << 21)) == (0x04 << 21))
236 insn |= 0x02 << 21;
237 else if ((insn & (0x14 << 21)) == (0x10 << 21))
238 insn |= 0x08 << 21;
239 }
240 return insn | (value & 0xfffc);
241 }
242
243 static int64_t
244 extract_bdm (uint64_t insn,
245 ppc_cpu_t dialect,
246 int *invalid)
247 {
248 if ((dialect & ISA_V2) == 0)
249 {
250 if (((insn & (1 << 21)) == 0) != ((insn & (1 << 15)) == 0))
251 *invalid = 1;
252 }
253 else
254 {
255 if ((insn & (0x17 << 21)) != (0x06 << 21)
256 && (insn & (0x1d << 21)) != (0x18 << 21))
257 *invalid = 1;
258 }
259
260 return ((insn & 0xfffc) ^ 0x8000) - 0x8000;
261 }
262
263 /* The BD field in a B form instruction when the + modifier is used.
264 This is like BDM, above, except that the branch is expected to be
265 taken. */
266
267 static uint64_t
268 insert_bdp (uint64_t insn,
269 int64_t value,
270 ppc_cpu_t dialect,
271 const char **errmsg ATTRIBUTE_UNUSED)
272 {
273 if ((dialect & ISA_V2) == 0)
274 {
275 if ((value & 0x8000) == 0)
276 insn |= 1 << 21;
277 }
278 else
279 {
280 if ((insn & (0x14 << 21)) == (0x04 << 21))
281 insn |= 0x03 << 21;
282 else if ((insn & (0x14 << 21)) == (0x10 << 21))
283 insn |= 0x09 << 21;
284 }
285 return insn | (value & 0xfffc);
286 }
287
288 static int64_t
289 extract_bdp (uint64_t insn,
290 ppc_cpu_t dialect,
291 int *invalid)
292 {
293 if ((dialect & ISA_V2) == 0)
294 {
295 if (((insn & (1 << 21)) == 0) == ((insn & (1 << 15)) == 0))
296 *invalid = 1;
297 }
298 else
299 {
300 if ((insn & (0x17 << 21)) != (0x07 << 21)
301 && (insn & (0x1d << 21)) != (0x19 << 21))
302 *invalid = 1;
303 }
304
305 return ((insn & 0xfffc) ^ 0x8000) - 0x8000;
306 }
307
308 static inline int
309 valid_bo_pre_v2 (int64_t value)
310 {
311 /* Certain encodings have bits that are required to be zero.
312 These are (z must be zero, y may be anything):
313 0000y
314 0001y
315 001zy
316 0100y
317 0101y
318 011zy
319 1z00y
320 1z01y
321 1z1zz
322 */
323 if ((value & 0x14) == 0)
324 /* BO: 0000y, 0001y, 0100y, 0101y. */
325 return 1;
326 else if ((value & 0x14) == 0x4)
327 /* BO: 001zy, 011zy. */
328 return (value & 0x2) == 0;
329 else if ((value & 0x14) == 0x10)
330 /* BO: 1z00y, 1z01y. */
331 return (value & 0x8) == 0;
332 else
333 /* BO: 1z1zz. */
334 return value == 0x14;
335 }
336
337 static inline int
338 valid_bo_post_v2 (int64_t value)
339 {
340 /* Certain encodings have bits that are required to be zero.
341 These are (z must be zero, a & t may be anything):
342 0000z
343 0001z
344 001at
345 0100z
346 0101z
347 011at
348 1a00t
349 1a01t
350 1z1zz
351 */
352 if ((value & 0x14) == 0)
353 /* BO: 0000z, 0001z, 0100z, 0101z. */
354 return (value & 0x1) == 0;
355 else if ((value & 0x14) == 0x14)
356 /* BO: 1z1zz. */
357 return value == 0x14;
358 else if ((value & 0x14) == 0x4)
359 /* BO: 001at, 011at, with "at" == 0b01 being reserved. */
360 return (value & 0x3) != 1;
361 else if ((value & 0x14) == 0x10)
362 /* BO: 1a00t, 1a01t, with "at" == 0b01 being reserved. */
363 return (value & 0x9) != 1;
364 else
365 return 1;
366 }
367
368 /* Check for legal values of a BO field. */
369
370 static int
371 valid_bo (int64_t value, ppc_cpu_t dialect, int extract)
372 {
373 int valid_y = valid_bo_pre_v2 (value);
374 int valid_at = valid_bo_post_v2 (value);
375
376 /* When disassembling with -Many, accept either encoding on the
377 second pass through opcodes. */
378 if (extract && dialect == ~(ppc_cpu_t) PPC_OPCODE_ANY)
379 return valid_y || valid_at;
380 if ((dialect & ISA_V2) == 0)
381 return valid_y;
382 else
383 return valid_at;
384 }
385
386 /* The BO field in a B form instruction. Warn about attempts to set
387 the field to an illegal value. */
388
389 static uint64_t
390 insert_bo (uint64_t insn,
391 int64_t value,
392 ppc_cpu_t dialect,
393 const char **errmsg)
394 {
395 if (!valid_bo (value, dialect, 0))
396 *errmsg = _("invalid conditional option");
397 else if (PPC_OP (insn) == 19
398 && (((insn >> 1) & 0x3ff) == 528) && ! (value & 4))
399 *errmsg = _("invalid counter access");
400 return insn | ((value & 0x1f) << 21);
401 }
402
403 static int64_t
404 extract_bo (uint64_t insn,
405 ppc_cpu_t dialect,
406 int *invalid)
407 {
408 int64_t value = (insn >> 21) & 0x1f;
409 if (!valid_bo (value, dialect, 1))
410 *invalid = 1;
411 return value;
412 }
413
414 /* For the given BO value, return a bit mask detailing which bits
415 define the branch hints. */
416
417 static int64_t
418 get_bo_hint_mask (int64_t bo, ppc_cpu_t dialect)
419 {
420 if ((dialect & ISA_V2) == 0)
421 {
422 if ((bo & 0x14) != 0x14)
423 /* BO: 0000y, 0001y, 001zy, 0100y, 0101y, 011zy, 1z00y, 1z01y . */
424 return 1;
425 else
426 /* BO: 1z1zz. */
427 return 0;
428 }
429 else
430 {
431 if ((bo & 0x14) == 0x4)
432 /* BO: 001at, 011at. */
433 return 0x3;
434 else if ((bo & 0x14) == 0x10)
435 /* BO: 1a00t, 1a01t. */
436 return 0x9;
437 else
438 /* BO: 0000z, 0001z, 0100z, 0101z, 1z1zz. */
439 return 0;
440 }
441 }
442
443 /* The BO field in a B form instruction when the + or - modifier is used. */
444
445 static uint64_t
446 insert_boe (uint64_t insn,
447 int64_t value,
448 ppc_cpu_t dialect,
449 const char **errmsg,
450 int branch_taken)
451 {
452 int64_t implied_hint;
453 int64_t hint_mask = get_bo_hint_mask (value, dialect);
454
455 if (branch_taken)
456 implied_hint = hint_mask;
457 else
458 implied_hint = hint_mask & ~1;
459
460 /* The branch hint bit(s) in the BO field must either be zero or exactly
461 match the branch hint bits implied by the '+' or '-' modifier. */
462 if (implied_hint == 0)
463 *errmsg = _("BO value implies no branch hint, when using + or - modifier");
464 else if ((value & hint_mask) != 0
465 && (value & hint_mask) != implied_hint)
466 {
467 if ((dialect & ISA_V2) == 0)
468 *errmsg = _("attempt to set y bit when using + or - modifier");
469 else
470 *errmsg = _("attempt to set 'at' bits when using + or - modifier");
471 }
472
473 value |= implied_hint;
474
475 return insert_bo (insn, value, dialect, errmsg);
476 }
477
478 static int64_t
479 extract_boe (uint64_t insn,
480 ppc_cpu_t dialect,
481 int *invalid,
482 int branch_taken)
483 {
484 int64_t value = (insn >> 21) & 0x1f;
485 int64_t implied_hint;
486 int64_t hint_mask = get_bo_hint_mask (value, dialect);
487
488 if (branch_taken)
489 implied_hint = hint_mask;
490 else
491 implied_hint = hint_mask & ~1;
492
493 if (!valid_bo (value, dialect, 1)
494 || implied_hint == 0
495 || (value & hint_mask) != implied_hint)
496 *invalid = 1;
497 return value;
498 }
499
500 /* The BO field in a B form instruction when the - modifier is used. */
501
502 static uint64_t
503 insert_bom (uint64_t insn,
504 int64_t value,
505 ppc_cpu_t dialect,
506 const char **errmsg)
507 {
508 return insert_boe (insn, value, dialect, errmsg, 0);
509 }
510
511 static int64_t
512 extract_bom (uint64_t insn,
513 ppc_cpu_t dialect,
514 int *invalid)
515 {
516 return extract_boe (insn, dialect, invalid, 0);
517 }
518
519 /* The BO field in a B form instruction when the + modifier is used. */
520
521 static uint64_t
522 insert_bop (uint64_t insn,
523 int64_t value,
524 ppc_cpu_t dialect,
525 const char **errmsg)
526 {
527 return insert_boe (insn, value, dialect, errmsg, 1);
528 }
529
530 static int64_t
531 extract_bop (uint64_t insn,
532 ppc_cpu_t dialect,
533 int *invalid)
534 {
535 return extract_boe (insn, dialect, invalid, 1);
536 }
537
538 /* The DCMX field in a X form instruction when the field is split
539 into separate DC, DM and DX fields. */
540
541 static uint64_t
542 insert_dcmxs (uint64_t insn,
543 int64_t value,
544 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
545 const char **errmsg ATTRIBUTE_UNUSED)
546 {
547 return (insn
548 | ((value & 0x1f) << 16)
549 | ((value & 0x20) >> 3)
550 | (value & 0x40));
551 }
552
553 static int64_t
554 extract_dcmxs (uint64_t insn,
555 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
556 int *invalid ATTRIBUTE_UNUSED)
557 {
558 return (insn & 0x40) | ((insn << 3) & 0x20) | ((insn >> 16) & 0x1f);
559 }
560
561 /* The DW field in a X form instruction when the field is split
562 into separate D and DX fields. */
563
564 static uint64_t
565 insert_dw (uint64_t insn,
566 int64_t value,
567 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
568 const char **errmsg ATTRIBUTE_UNUSED)
569 {
570 /* DW offsets must be in the range [-512, -8] and be a multiple of 8. */
571 if (value < -512
572 || value > -8
573 || (value & 0x7) != 0)
574 *errmsg = _("invalid offset: must be in the range [-512, -8] "
575 "and be a multiple of 8");
576
577 return insn | ((value & 0xf8) << 18) | ((value >> 8) & 1);
578 }
579
580 static int64_t
581 extract_dw (uint64_t insn,
582 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
583 int *invalid ATTRIBUTE_UNUSED)
584 {
585 int64_t dw = ((insn & 1) << 8) | ((insn >> 18) & 0xf8);
586 return dw - 512;
587 }
588
589 /* The D field in a DX form instruction when the field is split
590 into separate D0, D1 and D2 fields. */
591
592 static uint64_t
593 insert_dxd (uint64_t insn,
594 int64_t value,
595 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
596 const char **errmsg ATTRIBUTE_UNUSED)
597 {
598 return insn | (value & 0xffc1) | ((value & 0x3e) << 15);
599 }
600
601 static int64_t
602 extract_dxd (uint64_t insn,
603 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
604 int *invalid ATTRIBUTE_UNUSED)
605 {
606 uint64_t dxd = (insn & 0xffc1) | ((insn >> 15) & 0x3e);
607 return (dxd ^ 0x8000) - 0x8000;
608 }
609
610 static uint64_t
611 insert_dxdn (uint64_t insn,
612 int64_t value,
613 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
614 const char **errmsg ATTRIBUTE_UNUSED)
615 {
616 return insert_dxd (insn, -value, dialect, errmsg);
617 }
618
619 static int64_t
620 extract_dxdn (uint64_t insn,
621 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
622 int *invalid)
623 {
624 return -extract_dxd (insn, dialect, invalid);
625 }
626
627 /* The D field in a 64-bit D form prefix instruction when the field is split
628 into separate D0 and D1 fields. */
629
630 static uint64_t
631 insert_d34 (uint64_t insn,
632 int64_t value,
633 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
634 const char **errmsg ATTRIBUTE_UNUSED)
635 {
636 return insn | ((value & 0x3ffff0000ULL) << 16) | (value & 0xffff);
637 }
638
639 static int64_t
640 extract_d34 (uint64_t insn,
641 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
642 int *invalid ATTRIBUTE_UNUSED)
643 {
644 int64_t mask = 1ULL << 33;
645 int64_t value = ((insn >> 16) & 0x3ffff0000ULL) | (insn & 0xffff);
646 value = (value ^ mask) - mask;
647 return value;
648 }
649
650 /* The NSI34 field in an 8-byte D form prefix instruction. This is the same
651 as the SI34 field, only negated. The extraction function always marks it
652 as invalid, since we never want to recognize an instruction which uses
653 a field of this type. */
654
655 static uint64_t
656 insert_nsi34 (uint64_t insn,
657 int64_t value,
658 ppc_cpu_t dialect,
659 const char **errmsg)
660 {
661 return insert_d34 (insn, -value, dialect, errmsg);
662 }
663
664 static int64_t
665 extract_nsi34 (uint64_t insn,
666 ppc_cpu_t dialect,
667 int *invalid)
668 {
669 int64_t value = extract_d34 (insn, dialect, invalid);
670 *invalid = 1;
671 return -value;
672 }
673
674 /* The split IMM32 field in a vector splat insn. */
675
676 static uint64_t
677 insert_imm32 (uint64_t insn,
678 int64_t value,
679 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
680 const char **errmsg ATTRIBUTE_UNUSED)
681 {
682 return insn | ((value & 0xffff0000) << 16) | (value & 0xffff);
683 }
684
685 static int64_t
686 extract_imm32 (uint64_t insn,
687 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
688 int *invalid ATTRIBUTE_UNUSED)
689 {
690 return (insn & 0xffff) | ((insn >> 16) & 0xffff0000);
691 }
692
693 /* The R field in an 8-byte prefix instruction when there are restrictions
694 between R's value and the RA value (ie, they cannot both be non zero). */
695
696 static uint64_t
697 insert_pcrel (uint64_t insn,
698 int64_t value,
699 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
700 const char **errmsg)
701 {
702 value &= 0x1;
703 int64_t ra = (insn >> 16) & 0x1f;
704 if (ra != 0 && value != 0)
705 *errmsg = _("invalid R operand");
706
707 return insn | (value << 52);
708 }
709
710 static int64_t
711 extract_pcrel (uint64_t insn,
712 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
713 int *invalid)
714 {
715 /* If called with *invalid < 0 to return the value for missing
716 operands, *invalid will be the negative count of missing operands
717 including this one. Return a default value of 1 if the PRA0/PRAQ
718 operand was also omitted (ie. *invalid is -2). Return a default
719 value of 0 if the PRA0/PRAQ operand was not omitted
720 (ie. *invalid is -1). */
721 if (*invalid < 0)
722 return ~ *invalid & 1;
723
724 int64_t ra = (insn >> 16) & 0x1f;
725 int64_t pcrel = (insn >> 52) & 0x1;
726 if (ra != 0 && pcrel != 0)
727 *invalid = 1;
728
729 return pcrel;
730 }
731
732 /* Variant of extract_pcrel that sets invalid for R bit set. The idea
733 is to disassemble "paddi rt,0,offset,1" as "pla rt,offset". */
734
735 static int64_t
736 extract_pcrel0 (uint64_t insn,
737 ppc_cpu_t dialect,
738 int *invalid)
739 {
740 int64_t pcrel = extract_pcrel (insn, dialect, invalid);
741 if (pcrel)
742 *invalid = 1;
743 return pcrel;
744 }
745
746 /* FXM mask in mfcr and mtcrf instructions. */
747
748 static uint64_t
749 insert_fxm (uint64_t insn,
750 int64_t value,
751 ppc_cpu_t dialect,
752 const char **errmsg)
753 {
754 /* If we're handling the mfocrf and mtocrf insns ensure that exactly
755 one bit of the mask field is set. */
756 if ((insn & (1 << 20)) != 0)
757 {
758 if (value == 0 || (value & -value) != value)
759 {
760 *errmsg = _("invalid mask field");
761 value = 0;
762 }
763 }
764
765 /* If only one bit of the FXM field is set, we can use the new form
766 of the instruction, which is faster. Unlike the Power4 branch hint
767 encoding, this is not backward compatible. Do not generate the
768 new form unless -mpower4 has been given, or -many and the two
769 operand form of mfcr was used. */
770 else if (value > 0
771 && (value & -value) == value
772 && ((dialect & PPC_OPCODE_POWER4) != 0
773 || ((dialect & PPC_OPCODE_ANY) != 0
774 && (insn & (0x3ff << 1)) == 19 << 1)))
775 insn |= 1 << 20;
776
777 /* Any other value on mfcr is an error. */
778 else if ((insn & (0x3ff << 1)) == 19 << 1)
779 {
780 /* A value of -1 means we used the one operand form of
781 mfcr which is valid. */
782 if (value != -1)
783 *errmsg = _("invalid mfcr mask");
784 value = 0;
785 }
786
787 return insn | ((value & 0xff) << 12);
788 }
789
790 static int64_t
791 extract_fxm (uint64_t insn,
792 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
793 int *invalid)
794 {
795 /* Return a value of -1 for a missing optional operand, which is
796 used as a flag by insert_fxm. */
797 if (*invalid < 0)
798 return -1;
799
800 int64_t mask = (insn >> 12) & 0xff;
801 /* Is this a Power4 insn? */
802 if ((insn & (1 << 20)) != 0)
803 {
804 /* Exactly one bit of MASK should be set. */
805 if (mask == 0 || (mask & -mask) != mask)
806 *invalid = 1;
807 }
808
809 /* Check that non-power4 form of mfcr has a zero MASK. */
810 else if ((insn & (0x3ff << 1)) == 19 << 1)
811 {
812 if (mask != 0)
813 *invalid = 1;
814 else
815 mask = -1;
816 }
817
818 return mask;
819 }
820
821 /* L field in the paste. instruction. */
822
823 static uint64_t
824 insert_l1opt (uint64_t insn,
825 int64_t value,
826 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
827 const char **errmsg ATTRIBUTE_UNUSED)
828 {
829 return insn | ((value & 1) << 21);
830 }
831
832 static int64_t
833 extract_l1opt (uint64_t insn,
834 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
835 int *invalid)
836 {
837 /* Return a value of 1 for a missing optional operand. */
838 if (*invalid < 0)
839 return 1;
840
841 return (insn >> 21) & 1;
842 }
843
844 static uint64_t
845 insert_li20 (uint64_t insn,
846 int64_t value,
847 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
848 const char **errmsg ATTRIBUTE_UNUSED)
849 {
850 return (insn
851 | ((value & 0xf0000) >> 5)
852 | ((value & 0x0f800) << 5)
853 | (value & 0x7ff));
854 }
855
856 static int64_t
857 extract_li20 (uint64_t insn,
858 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
859 int *invalid ATTRIBUTE_UNUSED)
860 {
861 return ((((insn << 5) & 0xf0000)
862 | ((insn >> 5) & 0xf800)
863 | (insn & 0x7ff)) ^ 0x80000) - 0x80000;
864 }
865
866 /* The 2-bit/3-bit L or 2-bit WC field in a SYNC, DCBF or WAIT instruction.
867 For SYNC, some L values are reserved:
868 * Values 6 and 7 are reserved on newer server cpus.
869 * Value 3 is reserved on all server cpus.
870 * Value 2 is reserved on all other cpus.
871 For DCBF, some L values are reserved:
872 * Values 2, 5 and 7 are reserved on all cpus.
873 For WAIT, some WC values are reserved:
874 * Value 3 is reserved on all server cpus.
875 * Values 1 and 2 are reserved on older server cpus. */
876
877 static uint64_t
878 insert_ls (uint64_t insn,
879 int64_t value,
880 ppc_cpu_t dialect,
881 const char **errmsg)
882 {
883 int64_t mask;
884
885 if (((insn >> 1) & 0x3ff) == 598)
886 {
887 /* For SYNC, some L values are illegal. */
888 mask = (dialect & PPC_OPCODE_POWER10) ? 0x7 : 0x3;
889
890 /* If the value is within range, check for other illegal values. */
891 if ((value & mask) == value)
892 switch (value)
893 {
894 case 2:
895 if (dialect & PPC_OPCODE_POWER4)
896 break;
897 /* Fall through. */
898 case 3:
899 case 6:
900 case 7:
901 *errmsg = _("illegal L operand value");
902 break;
903 default:
904 break;
905 }
906 }
907 else if (((insn >> 1) & 0x3ff) == 86)
908 {
909 /* For DCBF, some L values are illegal. */
910 mask = (dialect & PPC_OPCODE_POWER10) ? 0x7 : 0x3;
911
912 /* If the value is within range, check for other illegal values. */
913 if ((value & mask) == value)
914 switch (value)
915 {
916 case 2:
917 case 5:
918 case 7:
919 *errmsg = _("illegal L operand value");
920 break;
921 default:
922 break;
923 }
924 }
925 else
926 {
927 /* For WAIT, some WC values are illegal. */
928 mask = 0x3;
929
930 /* If the value is within range, check for other illegal values. */
931 if ((dialect & PPC_OPCODE_A2) == 0
932 && (dialect & PPC_OPCODE_E500MC) == 0
933 && (value & mask) == value)
934 switch (value)
935 {
936 case 1:
937 case 2:
938 if (dialect & PPC_OPCODE_POWER10)
939 break;
940 /* Fall through. */
941 case 3:
942 *errmsg = _("illegal WC operand value");
943 break;
944 default:
945 break;
946 }
947 }
948
949 return insn | ((value & mask) << 21);
950 }
951
952 static int64_t
953 extract_ls (uint64_t insn,
954 ppc_cpu_t dialect,
955 int *invalid)
956 {
957 uint64_t value;
958
959 /* Missing optional operands have a value of zero. */
960 if (*invalid < 0)
961 return 0;
962
963 if (((insn >> 1) & 0x3ff) == 598)
964 {
965 /* For SYNC, some L values are illegal. */
966 int64_t mask = (dialect & PPC_OPCODE_POWER10) ? 0x7 : 0x3;
967
968 value = (insn >> 21) & mask;
969 switch (value)
970 {
971 case 2:
972 if (dialect & PPC_OPCODE_POWER4)
973 break;
974 /* Fall through. */
975 case 3:
976 case 6:
977 case 7:
978 *invalid = 1;
979 break;
980 default:
981 break;
982 }
983 }
984 else if (((insn >> 1) & 0x3ff) == 86)
985 {
986 /* For DCBF, some L values are illegal. */
987 int64_t mask = (dialect & PPC_OPCODE_POWER10) ? 0x7 : 0x3;
988
989 value = (insn >> 21) & mask;
990 switch (value)
991 {
992 case 2:
993 case 5:
994 case 7:
995 *invalid = 1;
996 break;
997 default:
998 break;
999 }
1000 }
1001 else
1002 {
1003 /* For WAIT, some WC values are illegal. */
1004 value = (insn >> 21) & 0x3;
1005 if ((dialect & PPC_OPCODE_A2) == 0
1006 && (dialect & PPC_OPCODE_E500MC) == 0)
1007 switch (value)
1008 {
1009 case 1:
1010 case 2:
1011 if (dialect & PPC_OPCODE_POWER10)
1012 break;
1013 /* Fall through. */
1014 case 3:
1015 *invalid = 1;
1016 break;
1017 default:
1018 break;
1019 }
1020 }
1021
1022 return value;
1023 }
1024
1025 /* The 4-bit E field in a sync instruction that accepts 2 operands.
1026 If ESYNC is non-zero, then the L field must be either 0 or 1 and
1027 the complement of ESYNC-bit2. */
1028
1029 static uint64_t
1030 insert_esync (uint64_t insn,
1031 int64_t value,
1032 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1033 const char **errmsg)
1034 {
1035 uint64_t ls = (insn >> 21) & 0x03;
1036
1037 if (value != 0
1038 && ((~value >> 1) & 0x1) != ls)
1039 *errmsg = _("incompatible L operand value");
1040
1041 return insn | ((value & 0xf) << 16);
1042 }
1043
1044 static int64_t
1045 extract_esync (uint64_t insn,
1046 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1047 int *invalid)
1048 {
1049 /* Missing optional operands have a value of zero. */
1050 if (*invalid < 0)
1051 return 0;
1052
1053 uint64_t ls = (insn >> 21) & 0x3;
1054 uint64_t value = (insn >> 16) & 0xf;
1055 if (value != 0
1056 && ((~value >> 1) & 0x1) != ls)
1057 *invalid = 1;
1058 return value;
1059 }
1060
1061 /* The MB and ME fields in an M form instruction expressed as a single
1062 operand which is itself a bitmask. The extraction function always
1063 marks it as invalid, since we never want to recognize an
1064 instruction which uses a field of this type. */
1065
1066 static uint64_t
1067 insert_mbe (uint64_t insn,
1068 int64_t value,
1069 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1070 const char **errmsg)
1071 {
1072 uint64_t uval, mask;
1073 long mb, me, mx, count, last;
1074
1075 uval = value;
1076
1077 if (uval == 0)
1078 {
1079 *errmsg = _("illegal bitmask");
1080 return insn;
1081 }
1082
1083 mb = 0;
1084 me = 32;
1085 if ((uval & 1) != 0)
1086 last = 1;
1087 else
1088 last = 0;
1089 count = 0;
1090
1091 /* mb: location of last 0->1 transition */
1092 /* me: location of last 1->0 transition */
1093 /* count: # transitions */
1094
1095 for (mx = 0, mask = (uint64_t) 1 << 31; mx < 32; ++mx, mask >>= 1)
1096 {
1097 if ((uval & mask) && !last)
1098 {
1099 ++count;
1100 mb = mx;
1101 last = 1;
1102 }
1103 else if (!(uval & mask) && last)
1104 {
1105 ++count;
1106 me = mx;
1107 last = 0;
1108 }
1109 }
1110 if (me == 0)
1111 me = 32;
1112
1113 if (count != 2 && (count != 0 || ! last))
1114 *errmsg = _("illegal bitmask");
1115
1116 return insn | (mb << 6) | ((me - 1) << 1);
1117 }
1118
1119 static int64_t
1120 extract_mbe (uint64_t insn,
1121 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1122 int *invalid)
1123 {
1124 int64_t ret;
1125 long mb, me;
1126 long i;
1127
1128 *invalid = 1;
1129
1130 mb = (insn >> 6) & 0x1f;
1131 me = (insn >> 1) & 0x1f;
1132 if (mb < me + 1)
1133 {
1134 ret = 0;
1135 for (i = mb; i <= me; i++)
1136 ret |= (uint64_t) 1 << (31 - i);
1137 }
1138 else if (mb == me + 1)
1139 ret = ~0;
1140 else /* (mb > me + 1) */
1141 {
1142 ret = ~0;
1143 for (i = me + 1; i < mb; i++)
1144 ret &= ~((uint64_t) 1 << (31 - i));
1145 }
1146 return ret;
1147 }
1148
1149 /* The MB or ME field in an MD or MDS form instruction. The high bit
1150 is wrapped to the low end. */
1151
1152 static uint64_t
1153 insert_mb6 (uint64_t insn,
1154 int64_t value,
1155 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1156 const char **errmsg ATTRIBUTE_UNUSED)
1157 {
1158 return insn | ((value & 0x1f) << 6) | (value & 0x20);
1159 }
1160
1161 static int64_t
1162 extract_mb6 (uint64_t insn,
1163 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1164 int *invalid ATTRIBUTE_UNUSED)
1165 {
1166 return ((insn >> 6) & 0x1f) | (insn & 0x20);
1167 }
1168
1169 /* The NB field in an X form instruction. The value 32 is stored as
1170 0. */
1171
1172 static int64_t
1173 extract_nb (uint64_t insn,
1174 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1175 int *invalid ATTRIBUTE_UNUSED)
1176 {
1177 int64_t ret;
1178
1179 ret = (insn >> 11) & 0x1f;
1180 if (ret == 0)
1181 ret = 32;
1182 return ret;
1183 }
1184
1185 /* The NB field in an lswi instruction, which has special value
1186 restrictions. The value 32 is stored as 0. */
1187
1188 static uint64_t
1189 insert_nbi (uint64_t insn,
1190 int64_t value,
1191 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1192 const char **errmsg ATTRIBUTE_UNUSED)
1193 {
1194 int64_t rtvalue = (insn >> 21) & 0x1f;
1195 int64_t ravalue = (insn >> 16) & 0x1f;
1196
1197 if (value == 0)
1198 value = 32;
1199 if (rtvalue + (value + 3) / 4 > (rtvalue > ravalue ? ravalue + 32
1200 : ravalue))
1201 *errmsg = _("address register in load range");
1202 return insn | ((value & 0x1f) << 11);
1203 }
1204
1205 /* The NSI field in a D form instruction. This is the same as the SI
1206 field, only negated. The extraction function always marks it as
1207 invalid, since we never want to recognize an instruction which uses
1208 a field of this type. */
1209
1210 static uint64_t
1211 insert_nsi (uint64_t insn,
1212 int64_t value,
1213 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1214 const char **errmsg ATTRIBUTE_UNUSED)
1215 {
1216 return insn | (-value & 0xffff);
1217 }
1218
1219 static int64_t
1220 extract_nsi (uint64_t insn,
1221 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1222 int *invalid)
1223 {
1224 *invalid = 1;
1225 return -(((insn & 0xffff) ^ 0x8000) - 0x8000);
1226 }
1227
1228 /* The 2-bit SC field in a SYNC or PL field in a WAIT instruction.
1229 For WAIT, some PL values are reserved:
1230 * Values 1, 2 and 3 are reserved. */
1231
1232 static uint64_t
1233 insert_pl (uint64_t insn,
1234 int64_t value,
1235 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1236 const char **errmsg)
1237 {
1238 /* For WAIT, some PL values are illegal. */
1239 if (((insn >> 1) & 0x3ff) == 30
1240 && value != 0)
1241 *errmsg = _("illegal PL operand value");
1242 return insn | ((value & 0x3) << 16);
1243 }
1244
1245 static int64_t
1246 extract_pl (uint64_t insn,
1247 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1248 int *invalid)
1249 {
1250 /* Missing optional operands have a value of zero. */
1251 if (*invalid < 0)
1252 return 0;
1253
1254 uint64_t value = (insn >> 16) & 0x3;
1255
1256 /* For WAIT, some PL values are illegal. */
1257 if (((insn >> 1) & 0x3ff) == 30
1258 && value != 0)
1259 *invalid = 1;
1260 return value;
1261 }
1262
1263 /* The RA field in a D or X form instruction which is an updating
1264 load, which means that the RA field may not be zero and may not
1265 equal the RT field. */
1266
1267 static uint64_t
1268 insert_ral (uint64_t insn,
1269 int64_t value,
1270 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1271 const char **errmsg)
1272 {
1273 if (value == 0
1274 || (uint64_t) value == ((insn >> 21) & 0x1f))
1275 *errmsg = "invalid register operand when updating";
1276 return insn | ((value & 0x1f) << 16);
1277 }
1278
1279 static int64_t
1280 extract_ral (uint64_t insn,
1281 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1282 int *invalid)
1283 {
1284 int64_t rtvalue = (insn >> 21) & 0x1f;
1285 int64_t ravalue = (insn >> 16) & 0x1f;
1286
1287 if (rtvalue == ravalue || ravalue == 0)
1288 *invalid = 1;
1289 return ravalue;
1290 }
1291
1292 /* The RA field in an lmw instruction, which has special value
1293 restrictions. */
1294
1295 static uint64_t
1296 insert_ram (uint64_t insn,
1297 int64_t value,
1298 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1299 const char **errmsg)
1300 {
1301 if ((uint64_t) value >= ((insn >> 21) & 0x1f))
1302 *errmsg = _("index register in load range");
1303 return insn | ((value & 0x1f) << 16);
1304 }
1305
1306 static int64_t
1307 extract_ram (uint64_t insn,
1308 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1309 int *invalid)
1310 {
1311 uint64_t rtvalue = (insn >> 21) & 0x1f;
1312 uint64_t ravalue = (insn >> 16) & 0x1f;
1313
1314 if (ravalue >= rtvalue)
1315 *invalid = 1;
1316 return ravalue;
1317 }
1318
1319 /* The RA field in the DQ form lq or an lswx instruction, which have special
1320 value restrictions. */
1321
1322 static uint64_t
1323 insert_raq (uint64_t insn,
1324 int64_t value,
1325 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1326 const char **errmsg)
1327 {
1328 int64_t rtvalue = (insn >> 21) & 0x1f;
1329
1330 if (value == rtvalue)
1331 *errmsg = _("source and target register operands must be different");
1332 return insn | ((value & 0x1f) << 16);
1333 }
1334
1335 static int64_t
1336 extract_raq (uint64_t insn,
1337 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1338 int *invalid)
1339 {
1340 /* Missing optional operands have a value of zero. */
1341 if (*invalid < 0)
1342 return 0;
1343
1344 uint64_t rtvalue = (insn >> 21) & 0x1f;
1345 uint64_t ravalue = (insn >> 16) & 0x1f;
1346 if (ravalue == rtvalue)
1347 *invalid = 1;
1348 return ravalue;
1349 }
1350
1351 /* The RA field in a D or X form instruction which is an updating
1352 store or an updating floating point load, which means that the RA
1353 field may not be zero. */
1354
1355 static uint64_t
1356 insert_ras (uint64_t insn,
1357 int64_t value,
1358 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1359 const char **errmsg)
1360 {
1361 if (value == 0)
1362 *errmsg = _("invalid register operand when updating");
1363 return insn | ((value & 0x1f) << 16);
1364 }
1365
1366 static int64_t
1367 extract_ras (uint64_t insn,
1368 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1369 int *invalid)
1370 {
1371 uint64_t ravalue = (insn >> 16) & 0x1f;
1372
1373 if (ravalue == 0)
1374 *invalid = 1;
1375 return ravalue;
1376 }
1377
1378 /* The RS and RB fields in an X form instruction when they must be the same.
1379 This is used for extended mnemonics like mr. The extraction function
1380 enforces that the fields are the same. */
1381
1382 static uint64_t
1383 insert_rsb (uint64_t insn,
1384 int64_t value,
1385 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1386 const char **errmsg ATTRIBUTE_UNUSED)
1387 {
1388 value &= 0x1f;
1389 return insn | (value << 21) | (value << 11);
1390 }
1391
1392 static int64_t
1393 extract_rsb (uint64_t insn,
1394 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1395 int *invalid)
1396 {
1397 int64_t rs = (insn >> 21) & 0x1f;
1398 int64_t rb = (insn >> 11) & 0x1f;
1399
1400 if (rs != rb)
1401 *invalid = 1;
1402 return rs;
1403 }
1404
1405 /* The RB field in an lswx instruction, which has special value
1406 restrictions. */
1407
1408 static uint64_t
1409 insert_rbx (uint64_t insn,
1410 int64_t value,
1411 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1412 const char **errmsg)
1413 {
1414 int64_t rtvalue = (insn >> 21) & 0x1f;
1415
1416 if (value == rtvalue)
1417 *errmsg = _("source and target register operands must be different");
1418 return insn | ((value & 0x1f) << 11);
1419 }
1420
1421 static int64_t
1422 extract_rbx (uint64_t insn,
1423 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1424 int *invalid)
1425 {
1426 uint64_t rtvalue = (insn >> 21) & 0x1f;
1427 uint64_t rbvalue = (insn >> 11) & 0x1f;
1428
1429 if (rbvalue == rtvalue)
1430 *invalid = 1;
1431 return rbvalue;
1432 }
1433
1434 /* The SCI8 field is made up of SCL and {U,N}I8 fields. */
1435 static uint64_t
1436 insert_sci8 (uint64_t insn,
1437 int64_t value,
1438 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1439 const char **errmsg)
1440 {
1441 uint64_t fill_scale = 0;
1442 uint64_t ui8 = value;
1443
1444 if ((ui8 & 0xffffff00) == 0)
1445 ;
1446 else if ((ui8 & 0xffffff00) == 0xffffff00)
1447 fill_scale = 0x400;
1448 else if ((ui8 & 0xffff00ff) == 0)
1449 {
1450 fill_scale = 1 << 8;
1451 ui8 >>= 8;
1452 }
1453 else if ((ui8 & 0xffff00ff) == 0xffff00ff)
1454 {
1455 fill_scale = 0x400 | (1 << 8);
1456 ui8 >>= 8;
1457 }
1458 else if ((ui8 & 0xff00ffff) == 0)
1459 {
1460 fill_scale = 2 << 8;
1461 ui8 >>= 16;
1462 }
1463 else if ((ui8 & 0xff00ffff) == 0xff00ffff)
1464 {
1465 fill_scale = 0x400 | (2 << 8);
1466 ui8 >>= 16;
1467 }
1468 else if ((ui8 & 0x00ffffff) == 0)
1469 {
1470 fill_scale = 3 << 8;
1471 ui8 >>= 24;
1472 }
1473 else if ((ui8 & 0x00ffffff) == 0x00ffffff)
1474 {
1475 fill_scale = 0x400 | (3 << 8);
1476 ui8 >>= 24;
1477 }
1478 else
1479 {
1480 *errmsg = _("illegal immediate value");
1481 ui8 = 0;
1482 }
1483
1484 return insn | fill_scale | (ui8 & 0xff);
1485 }
1486
1487 static int64_t
1488 extract_sci8 (uint64_t insn,
1489 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1490 int *invalid ATTRIBUTE_UNUSED)
1491 {
1492 int64_t fill = insn & 0x400;
1493 int64_t scale_factor = (insn & 0x300) >> 5;
1494 int64_t value = (insn & 0xff) << scale_factor;
1495
1496 if (fill != 0)
1497 value |= ~((int64_t) 0xff << scale_factor);
1498 return value;
1499 }
1500
1501 static uint64_t
1502 insert_sci8n (uint64_t insn,
1503 int64_t value,
1504 ppc_cpu_t dialect,
1505 const char **errmsg)
1506 {
1507 return insert_sci8 (insn, -value, dialect, errmsg);
1508 }
1509
1510 static int64_t
1511 extract_sci8n (uint64_t insn,
1512 ppc_cpu_t dialect,
1513 int *invalid)
1514 {
1515 return -extract_sci8 (insn, dialect, invalid);
1516 }
1517
1518 static uint64_t
1519 insert_oimm (uint64_t insn,
1520 int64_t value,
1521 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1522 const char **errmsg ATTRIBUTE_UNUSED)
1523 {
1524 return insn | (((value - 1) & 0x1f) << 4);
1525 }
1526
1527 static int64_t
1528 extract_oimm (uint64_t insn,
1529 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1530 int *invalid ATTRIBUTE_UNUSED)
1531 {
1532 return ((insn >> 4) & 0x1f) + 1;
1533 }
1534
1535 /* The SH field in an MD form instruction. This is split. */
1536
1537 static uint64_t
1538 insert_sh6 (uint64_t insn,
1539 int64_t value,
1540 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1541 const char **errmsg ATTRIBUTE_UNUSED)
1542 {
1543 return insn | ((value & 0x1f) << 11) | ((value & 0x20) >> 4);
1544 }
1545
1546 static int64_t
1547 extract_sh6 (uint64_t insn,
1548 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1549 int *invalid ATTRIBUTE_UNUSED)
1550 {
1551 return ((insn >> 11) & 0x1f) | ((insn << 4) & 0x20);
1552 }
1553
1554 /* The SPR field in an XFX form instruction. This is flipped--the
1555 lower 5 bits are stored in the upper 5 and vice- versa. */
1556
1557 static uint64_t
1558 insert_spr (uint64_t insn,
1559 int64_t value,
1560 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1561 const char **errmsg ATTRIBUTE_UNUSED)
1562 {
1563 return insn | ((value & 0x1f) << 16) | ((value & 0x3e0) << 6);
1564 }
1565
1566 static int64_t
1567 extract_spr (uint64_t insn,
1568 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1569 int *invalid ATTRIBUTE_UNUSED)
1570 {
1571 return ((insn >> 16) & 0x1f) | ((insn >> 6) & 0x3e0);
1572 }
1573
1574 /* Some dialects have 8 [DI]BAT registers instead of the standard 4. */
1575 #define ALLOW8_BAT (PPC_OPCODE_750)
1576
1577 static uint64_t
1578 insert_sprbat (uint64_t insn,
1579 int64_t value,
1580 ppc_cpu_t dialect,
1581 const char **errmsg)
1582 {
1583 if ((uint64_t) value > 7
1584 || ((uint64_t) value > 3 && (dialect & ALLOW8_BAT) == 0))
1585 *errmsg = _("invalid bat number");
1586
1587 /* If this is [di]bat4..7 then use spr 560..575, otherwise 528..543. */
1588 if ((uint64_t) value > 3)
1589 value = ((value & 3) << 6) | 1;
1590 else
1591 value = value << 6;
1592
1593 return insn | (value << 11);
1594 }
1595
1596 static int64_t
1597 extract_sprbat (uint64_t insn,
1598 ppc_cpu_t dialect,
1599 int *invalid)
1600 {
1601 uint64_t val = (insn >> 17) & 0x3;
1602
1603 val = val + ((insn >> 9) & 0x4);
1604 if (val > 3 && (dialect & ALLOW8_BAT) == 0)
1605 *invalid = 1;
1606 return val;
1607 }
1608
1609 /* Some dialects have 8 SPRG registers instead of the standard 4. */
1610 #define ALLOW8_SPRG (PPC_OPCODE_BOOKE | PPC_OPCODE_405)
1611
1612 static uint64_t
1613 insert_sprg (uint64_t insn,
1614 int64_t value,
1615 ppc_cpu_t dialect,
1616 const char **errmsg)
1617 {
1618 if ((uint64_t) value > 7
1619 || ((uint64_t) value > 3 && (dialect & ALLOW8_SPRG) == 0))
1620 *errmsg = _("invalid sprg number");
1621
1622 /* If this is mfsprg4..7 then use spr 260..263 which can be read in
1623 user mode. Anything else must use spr 272..279. */
1624 if ((uint64_t) value <= 3 || (insn & 0x100) != 0)
1625 value |= 0x10;
1626
1627 return insn | ((value & 0x17) << 16);
1628 }
1629
1630 static int64_t
1631 extract_sprg (uint64_t insn,
1632 ppc_cpu_t dialect,
1633 int *invalid)
1634 {
1635 uint64_t val = (insn >> 16) & 0x1f;
1636
1637 /* mfsprg can use 260..263 and 272..279. mtsprg only uses spr 272..279
1638 If not BOOKE, 405 or VLE, then both use only 272..275. */
1639 if ((val - 0x10 > 3 && (dialect & ALLOW8_SPRG) == 0)
1640 || (val - 0x10 > 7 && (insn & 0x100) != 0)
1641 || val <= 3
1642 || (val & 8) != 0)
1643 *invalid = 1;
1644 return val & 7;
1645 }
1646
1647 /* The TBR field in an XFX instruction. This is just like SPR, but it
1648 is optional. */
1649
1650 static uint64_t
1651 insert_tbr (uint64_t insn,
1652 int64_t value,
1653 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1654 const char **errmsg)
1655 {
1656 if (value != 268 && value != 269)
1657 *errmsg = _("invalid tbr number");
1658 return insn | ((value & 0x1f) << 16) | ((value & 0x3e0) << 6);
1659 }
1660
1661 static int64_t
1662 extract_tbr (uint64_t insn,
1663 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1664 int *invalid)
1665 {
1666 /* Missing optional operands have a value of 268. */
1667 if (*invalid < 0)
1668 return 268;
1669
1670 int64_t ret = ((insn >> 16) & 0x1f) | ((insn >> 6) & 0x3e0);
1671 if (ret != 268 && ret != 269)
1672 *invalid = 1;
1673 return ret;
1674 }
1675
1676 /* The XT and XS fields in an XX1 or XX3 form instruction. This is split. */
1677
1678 static uint64_t
1679 insert_xt6 (uint64_t insn,
1680 int64_t value,
1681 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1682 const char **errmsg ATTRIBUTE_UNUSED)
1683 {
1684 return insn | ((value & 0x1f) << 21) | ((value & 0x20) >> 5);
1685 }
1686
1687 static int64_t
1688 extract_xt6 (uint64_t insn,
1689 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1690 int *invalid ATTRIBUTE_UNUSED)
1691 {
1692 return ((insn << 5) & 0x20) | ((insn >> 21) & 0x1f);
1693 }
1694
1695 /* The XT and XS fields in an DQ form VSX instruction. This is split. */
1696 static uint64_t
1697 insert_xtq6 (uint64_t insn,
1698 int64_t value,
1699 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1700 const char **errmsg ATTRIBUTE_UNUSED)
1701 {
1702 return insn | ((value & 0x1f) << 21) | ((value & 0x20) >> 2);
1703 }
1704
1705 static int64_t
1706 extract_xtq6 (uint64_t insn,
1707 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1708 int *invalid ATTRIBUTE_UNUSED)
1709 {
1710 return ((insn << 2) & 0x20) | ((insn >> 21) & 0x1f);
1711 }
1712
1713 /* The XA field in an XX3 form instruction. This is split. */
1714
1715 static uint64_t
1716 insert_xa6 (uint64_t insn,
1717 int64_t value,
1718 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1719 const char **errmsg ATTRIBUTE_UNUSED)
1720 {
1721 return insn | ((value & 0x1f) << 16) | ((value & 0x20) >> 3);
1722 }
1723
1724 static int64_t
1725 extract_xa6 (uint64_t insn,
1726 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1727 int *invalid ATTRIBUTE_UNUSED)
1728 {
1729 return ((insn << 3) & 0x20) | ((insn >> 16) & 0x1f);
1730 }
1731
1732 /* The XA field in an MMA XX3 form instruction. This is split
1733 and must not overlap with the ACC operand. */
1734
1735 static uint64_t
1736 insert_xa6a (uint64_t insn,
1737 int64_t value,
1738 ppc_cpu_t dialect,
1739 const char **errmsg)
1740 {
1741 int64_t acc = (insn >> 23) & 0x7;
1742 if ((value >> 2) == acc)
1743 *errmsg = _("VSR overlaps ACC operand");
1744 return insert_xa6 (insn, value, dialect, errmsg);
1745 }
1746
1747 static int64_t
1748 extract_xa6a (uint64_t insn,
1749 ppc_cpu_t dialect,
1750 int *invalid)
1751 {
1752 int64_t acc = (insn >> 23) & 0x7;
1753 int64_t value = extract_xa6 (insn, dialect, invalid);
1754 if ((value >> 2) == acc)
1755 *invalid = 1;
1756 return value;
1757 }
1758
1759 /* The XB field in an XX3 form instruction. This is split. */
1760
1761 static uint64_t
1762 insert_xb6 (uint64_t insn,
1763 int64_t value,
1764 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1765 const char **errmsg ATTRIBUTE_UNUSED)
1766 {
1767 return insn | ((value & 0x1f) << 11) | ((value & 0x20) >> 4);
1768 }
1769
1770 static int64_t
1771 extract_xb6 (uint64_t insn,
1772 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1773 int *invalid ATTRIBUTE_UNUSED)
1774 {
1775 return ((insn << 4) & 0x20) | ((insn >> 11) & 0x1f);
1776 }
1777
1778 /* The XB field in an MMA XX3 form instruction. This is split
1779 and must not overlap with the ACC operand. */
1780
1781 static uint64_t
1782 insert_xb6a (uint64_t insn,
1783 int64_t value,
1784 ppc_cpu_t dialect,
1785 const char **errmsg)
1786 {
1787 int64_t acc = (insn >> 23) & 0x7;
1788 if ((value >> 2) == acc)
1789 *errmsg = _("VSR overlaps ACC operand");
1790 return insert_xb6 (insn, value, dialect, errmsg);
1791 }
1792
1793 static int64_t
1794 extract_xb6a (uint64_t insn,
1795 ppc_cpu_t dialect,
1796 int *invalid)
1797 {
1798 int64_t acc = (insn >> 23) & 0x7;
1799 int64_t value = extract_xb6 (insn, dialect, invalid);
1800 if ((value >> 2) == acc)
1801 *invalid = 1;
1802 return value;
1803 }
1804
1805 /* The XA and XB fields in an XX3 form instruction when they must be the same.
1806 This is used for extended mnemonics like xvmovdp. The extraction function
1807 enforces that the fields are the same. */
1808
1809 static uint64_t
1810 insert_xab6 (uint64_t insn,
1811 int64_t value,
1812 ppc_cpu_t dialect,
1813 const char **errmsg)
1814 {
1815 return insert_xa6 (insn, value, dialect, errmsg)
1816 | insert_xb6 (insn, value, dialect, errmsg);
1817 }
1818
1819 static int64_t
1820 extract_xab6 (uint64_t insn,
1821 ppc_cpu_t dialect,
1822 int *invalid)
1823 {
1824 int64_t xa6 = extract_xa6 (insn, dialect, invalid);
1825 int64_t xb6 = extract_xb6 (insn, dialect, invalid);
1826
1827 if (xa6 != xb6)
1828 *invalid = 1;
1829 return xa6;
1830 }
1831
1832 /* The XC field in an XX4 form instruction. This is split. */
1833
1834 static uint64_t
1835 insert_xc6 (uint64_t insn,
1836 int64_t value,
1837 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1838 const char **errmsg ATTRIBUTE_UNUSED)
1839 {
1840 return insn | ((value & 0x1f) << 6) | ((value & 0x20) >> 2);
1841 }
1842
1843 static int64_t
1844 extract_xc6 (uint64_t insn,
1845 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1846 int *invalid ATTRIBUTE_UNUSED)
1847 {
1848 return ((insn << 2) & 0x20) | ((insn >> 6) & 0x1f);
1849 }
1850
1851 /* The split XTp field in a vector paired insn. */
1852
1853 static uint64_t
1854 insert_xtp (uint64_t insn,
1855 int64_t value,
1856 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1857 const char **errmsg ATTRIBUTE_UNUSED)
1858 {
1859 return insn | ((value & 0x1e) << 21) | ((value & 0x20) << (21 - 5));
1860 }
1861
1862 static int64_t
1863 extract_xtp (uint64_t insn,
1864 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1865 int *invalid ATTRIBUTE_UNUSED)
1866 {
1867 return ((insn >> (21 - 5)) & 0x20) | ((insn >> 21) & 0x1e);
1868 }
1869
1870 /* The split XT field in a vector splat insn. */
1871
1872 static uint64_t
1873 insert_xts (uint64_t insn,
1874 int64_t value,
1875 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1876 const char **errmsg ATTRIBUTE_UNUSED)
1877 {
1878 return insn | ((value & 0x1f) << 21) | ((value & 0x20) << (16 - 5));
1879 }
1880
1881 static int64_t
1882 extract_xts (uint64_t insn,
1883 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1884 int *invalid ATTRIBUTE_UNUSED)
1885 {
1886 return ((insn >> (16 - 5)) & 0x20) | ((insn >> 21) & 0x1f);
1887 }
1888
1889 static uint64_t
1890 insert_dm (uint64_t insn,
1891 int64_t value,
1892 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1893 const char **errmsg)
1894 {
1895 if (value != 0 && value != 1)
1896 *errmsg = _("invalid constant");
1897 return insn | (((value) ? 3 : 0) << 8);
1898 }
1899
1900 static int64_t
1901 extract_dm (uint64_t insn,
1902 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1903 int *invalid)
1904 {
1905 int64_t value = (insn >> 8) & 3;
1906 if (value != 0 && value != 3)
1907 *invalid = 1;
1908 return (value) ? 1 : 0;
1909 }
1910
1911 /* The VLESIMM field in an I16A form instruction. This is split. */
1912
1913 static uint64_t
1914 insert_vlesi (uint64_t insn,
1915 int64_t value,
1916 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1917 const char **errmsg ATTRIBUTE_UNUSED)
1918 {
1919 return insn | ((value & 0xf800) << 10) | (value & 0x7ff);
1920 }
1921
1922 static int64_t
1923 extract_vlesi (uint64_t insn,
1924 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1925 int *invalid ATTRIBUTE_UNUSED)
1926 {
1927 int64_t value = ((insn >> 10) & 0xf800) | (insn & 0x7ff);
1928 value = (value ^ 0x8000) - 0x8000;
1929 return value;
1930 }
1931
1932 static uint64_t
1933 insert_vlensi (uint64_t insn,
1934 int64_t value,
1935 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1936 const char **errmsg ATTRIBUTE_UNUSED)
1937 {
1938 value = -value;
1939 return insn | ((value & 0xf800) << 10) | (value & 0x7ff);
1940 }
1941 static int64_t
1942 extract_vlensi (uint64_t insn,
1943 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1944 int *invalid)
1945 {
1946 int64_t value = ((insn >> 10) & 0xf800) | (insn & 0x7ff);
1947 value = (value ^ 0x8000) - 0x8000;
1948 /* Don't use for disassembly. */
1949 *invalid = 1;
1950 return -value;
1951 }
1952
1953 /* The VLEUIMM field in an I16A form instruction. This is split. */
1954
1955 static uint64_t
1956 insert_vleui (uint64_t insn,
1957 int64_t value,
1958 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1959 const char **errmsg ATTRIBUTE_UNUSED)
1960 {
1961 return insn | ((value & 0xf800) << 10) | (value & 0x7ff);
1962 }
1963
1964 static int64_t
1965 extract_vleui (uint64_t insn,
1966 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1967 int *invalid ATTRIBUTE_UNUSED)
1968 {
1969 return ((insn >> 10) & 0xf800) | (insn & 0x7ff);
1970 }
1971
1972 /* The VLEUIMML field in an I16L form instruction. This is split. */
1973
1974 static uint64_t
1975 insert_vleil (uint64_t insn,
1976 int64_t value,
1977 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1978 const char **errmsg ATTRIBUTE_UNUSED)
1979 {
1980 return insn | ((value & 0xf800) << 5) | (value & 0x7ff);
1981 }
1982
1983 static int64_t
1984 extract_vleil (uint64_t insn,
1985 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1986 int *invalid ATTRIBUTE_UNUSED)
1987 {
1988 return ((insn >> 5) & 0xf800) | (insn & 0x7ff);
1989 }
1990
1991 static uint64_t
1992 insert_evuimm1_ex0 (uint64_t insn,
1993 int64_t value,
1994 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
1995 const char **errmsg)
1996 {
1997 if (value <= 0 || value > 0x1f)
1998 *errmsg = _("UIMM = 00000 is illegal");
1999 return insn | ((value & 0x1f) << 11);
2000 }
2001
2002 static int64_t
2003 extract_evuimm1_ex0 (uint64_t insn,
2004 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
2005 int *invalid)
2006 {
2007 int64_t value = ((insn >> 11) & 0x1f);
2008 if (value == 0)
2009 *invalid = 1;
2010
2011 return value;
2012 }
2013
2014 static uint64_t
2015 insert_evuimm2_ex0 (uint64_t insn,
2016 int64_t value,
2017 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
2018 const char **errmsg)
2019 {
2020 if (value <= 0 || value > 0x3e)
2021 *errmsg = _("UIMM = 00000 is illegal");
2022 return insn | ((value & 0x3e) << 10);
2023 }
2024
2025 static int64_t
2026 extract_evuimm2_ex0 (uint64_t insn,
2027 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
2028 int *invalid)
2029 {
2030 int64_t value = ((insn >> 10) & 0x3e);
2031 if (value == 0)
2032 *invalid = 1;
2033
2034 return value;
2035 }
2036
2037 static uint64_t
2038 insert_evuimm4_ex0 (uint64_t insn,
2039 int64_t value,
2040 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
2041 const char **errmsg)
2042 {
2043 if (value <= 0 || value > 0x7c)
2044 *errmsg = _("UIMM = 00000 is illegal");
2045 return insn | ((value & 0x7c) << 9);
2046 }
2047
2048 static int64_t
2049 extract_evuimm4_ex0 (uint64_t insn,
2050 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
2051 int *invalid)
2052 {
2053 int64_t value = ((insn >> 9) & 0x7c);
2054 if (value == 0)
2055 *invalid = 1;
2056
2057 return value;
2058 }
2059
2060 static uint64_t
2061 insert_evuimm8_ex0 (uint64_t insn,
2062 int64_t value,
2063 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
2064 const char **errmsg)
2065 {
2066 if (value <= 0 || value > 0xf8)
2067 *errmsg = _("UIMM = 00000 is illegal");
2068 return insn | ((value & 0xf8) << 8);
2069 }
2070
2071 static int64_t
2072 extract_evuimm8_ex0 (uint64_t insn,
2073 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
2074 int *invalid)
2075 {
2076 int64_t value = ((insn >> 8) & 0xf8);
2077 if (value == 0)
2078 *invalid = 1;
2079
2080 return value;
2081 }
2082
2083 static uint64_t
2084 insert_evuimm_lt8 (uint64_t insn,
2085 int64_t value,
2086 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
2087 const char **errmsg)
2088 {
2089 if (value < 0 || value > 7)
2090 *errmsg = _("UIMM values >7 are illegal");
2091 return insn | ((value & 0x7) << 11);
2092 }
2093
2094 static int64_t
2095 extract_evuimm_lt8 (uint64_t insn,
2096 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
2097 int *invalid)
2098 {
2099 int64_t value = ((insn >> 11) & 0x1f);
2100 if (value > 7)
2101 *invalid = 1;
2102
2103 return value;
2104 }
2105
2106 static uint64_t
2107 insert_evuimm_lt16 (uint64_t insn,
2108 int64_t value,
2109 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
2110 const char **errmsg)
2111 {
2112 if (value < 0 || value > 15)
2113 *errmsg = _("UIMM values >15 are illegal");
2114 return insn | ((value & 0xf) << 11);
2115 }
2116
2117 static int64_t
2118 extract_evuimm_lt16 (uint64_t insn,
2119 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
2120 int *invalid)
2121 {
2122 int64_t value = ((insn >> 11) & 0x1f);
2123 if (value > 15)
2124 *invalid = 1;
2125
2126 return value;
2127 }
2128
2129 static uint64_t
2130 insert_rD_rS_even (uint64_t insn,
2131 int64_t value,
2132 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
2133 const char **errmsg)
2134 {
2135 if ((value & 0x1) != 0)
2136 *errmsg = _("GPR odd is illegal");
2137 return insn | ((value & 0x1e) << 21);
2138 }
2139
2140 static int64_t
2141 extract_rD_rS_even (uint64_t insn,
2142 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
2143 int *invalid)
2144 {
2145 int64_t value = ((insn >> 21) & 0x1f);
2146 if ((value & 0x1) != 0)
2147 *invalid = 1;
2148
2149 return value;
2150 }
2151
2152 static uint64_t
2153 insert_off_lsp (uint64_t insn,
2154 int64_t value,
2155 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
2156 const char **errmsg)
2157 {
2158 if (value <= 0 || value > 0x3)
2159 *errmsg = _("invalid offset");
2160 return insn | (value & 0x3);
2161 }
2162
2163 static int64_t
2164 extract_off_lsp (uint64_t insn,
2165 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
2166 int *invalid)
2167 {
2168 int64_t value = (insn & 0x3);
2169 if (value == 0)
2170 *invalid = 1;
2171
2172 return value;
2173 }
2174
2175 static uint64_t
2176 insert_off_spe2 (uint64_t insn,
2177 int64_t value,
2178 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
2179 const char **errmsg)
2180 {
2181 if (value <= 0 || value > 0x7)
2182 *errmsg = _("invalid offset");
2183 return insn | (value & 0x7);
2184 }
2185
2186 static int64_t
2187 extract_off_spe2 (uint64_t insn,
2188 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
2189 int *invalid)
2190 {
2191 int64_t value = (insn & 0x7);
2192 if (value == 0)
2193 *invalid = 1;
2194
2195 return value;
2196 }
2197
2198 static uint64_t
2199 insert_Ddd (uint64_t insn,
2200 int64_t value,
2201 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
2202 const char **errmsg)
2203 {
2204 if (value < 0 || value > 0x7)
2205 *errmsg = _("invalid Ddd value");
2206 return insn | ((value & 0x3) << 11) | ((value & 0x4) >> 2);
2207 }
2208
2209 static int64_t
2210 extract_Ddd (uint64_t insn,
2211 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
2212 int *invalid ATTRIBUTE_UNUSED)
2213 {
2214 return ((insn >> 11) & 0x3) | ((insn << 2) & 0x4);
2215 }
2216
2217 static uint64_t
2218 insert_sxl (uint64_t insn,
2219 int64_t value,
2220 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
2221 const char **errmsg ATTRIBUTE_UNUSED)
2222 {
2223 return insn | ((value & 0x1) << 11);
2224 }
2225
2226 static int64_t
2227 extract_sxl (uint64_t insn,
2228 ppc_cpu_t dialect ATTRIBUTE_UNUSED,
2229 int *invalid)
2230 {
2231 /* Missing optional operands have a value of one. */
2232 if (*invalid < 0)
2233 return 1;
2234 return (insn >> 11) & 0x1;
2235 }
2236 \f
2237 /* The operands table.
2238
2239 The fields are bitm, shift, insert, extract, flags.
2240
2241 We used to put parens around the various additions, like the one
2242 for BA just below. However, that caused trouble with feeble
2243 compilers with a limit on depth of a parenthesized expression, like
2244 (reportedly) the compiler in Microsoft Developer Studio 5. So we
2245 omit the parens, since the macros are never used in a context where
2246 the addition will be ambiguous. */
2247
2248 const struct powerpc_operand powerpc_operands[] =
2249 {
2250 /* The zero index is used to indicate the end of the list of
2251 operands. */
2252 #define UNUSED 0
2253 { 0, 0, NULL, NULL, 0 },
2254
2255 /* The BA field in an XL form instruction. */
2256 #define BA UNUSED + 1
2257 /* The BI field in a B form or XL form instruction. */
2258 #define BI BA
2259 #define BI_MASK (0x1f << 16)
2260 { 0x1f, 16, NULL, NULL, PPC_OPERAND_CR_BIT },
2261
2262 /* The BT, BA and BB fields in a XL form instruction when they must all
2263 be the same. */
2264 #define BTAB BA + 1
2265 { 0x1f, 21, insert_btab, extract_btab, PPC_OPERAND_CR_BIT },
2266
2267 /* The BB field in an XL form instruction. */
2268 #define BB BTAB + 1
2269 #define BB_MASK (0x1f << 11)
2270 { 0x1f, 11, NULL, NULL, PPC_OPERAND_CR_BIT },
2271
2272 /* The BA and BB fields in a XL form instruction when they must be
2273 the same. */
2274 #define BAB BB + 1
2275 { 0x1f, 16, insert_bab, extract_bab, PPC_OPERAND_CR_BIT },
2276
2277 /* The VRA and VRB fields in a VX form instruction when they must be the same.
2278 This is used for extended mnemonics like vmr. */
2279 #define VAB BAB + 1
2280 { 0x1f, 16, insert_bab, extract_bab, PPC_OPERAND_VR },
2281
2282 /* The RA and RB fields in a VX form instruction when they must be the same.
2283 This is used for extended mnemonics like evmr. */
2284 #define RAB VAB + 1
2285 { 0x1f, 16, insert_bab, extract_bab, PPC_OPERAND_GPR },
2286
2287 /* The BD field in a B form instruction. The lower two bits are
2288 forced to zero. */
2289 #define BD RAB + 1
2290 { 0xfffc, 0, NULL, NULL, PPC_OPERAND_RELATIVE | PPC_OPERAND_SIGNED },
2291
2292 /* The BD field in a B form instruction when absolute addressing is
2293 used. */
2294 #define BDA BD + 1
2295 { 0xfffc, 0, NULL, NULL, PPC_OPERAND_ABSOLUTE | PPC_OPERAND_SIGNED },
2296
2297 /* The BD field in a B form instruction when the - modifier is used.
2298 This sets the y bit of the BO field appropriately. */
2299 #define BDM BDA + 1
2300 { 0xfffc, 0, insert_bdm, extract_bdm,
2301 PPC_OPERAND_RELATIVE | PPC_OPERAND_SIGNED },
2302
2303 /* The BD field in a B form instruction when the - modifier is used
2304 and absolute address is used. */
2305 #define BDMA BDM + 1
2306 { 0xfffc, 0, insert_bdm, extract_bdm,
2307 PPC_OPERAND_ABSOLUTE | PPC_OPERAND_SIGNED },
2308
2309 /* The BD field in a B form instruction when the + modifier is used.
2310 This sets the y bit of the BO field appropriately. */
2311 #define BDP BDMA + 1
2312 { 0xfffc, 0, insert_bdp, extract_bdp,
2313 PPC_OPERAND_RELATIVE | PPC_OPERAND_SIGNED },
2314
2315 /* The BD field in a B form instruction when the + modifier is used
2316 and absolute addressing is used. */
2317 #define BDPA BDP + 1
2318 { 0xfffc, 0, insert_bdp, extract_bdp,
2319 PPC_OPERAND_ABSOLUTE | PPC_OPERAND_SIGNED },
2320
2321 /* The BF field in an X or XL form instruction. */
2322 #define BF BDPA + 1
2323 /* The CRFD field in an X form instruction. */
2324 #define CRFD BF
2325 /* The CRD field in an XL form instruction. */
2326 #define CRD BF
2327 { 0x7, 23, NULL, NULL, PPC_OPERAND_CR_REG },
2328
2329 /* The BF field in an X or XL form instruction. */
2330 #define BFF BF + 1
2331 { 0x7, 23, NULL, NULL, 0 },
2332
2333 /* The ACC field in a VSX ACC 8LS:D-form instruction. */
2334 #define ACC BFF + 1
2335 { 0x7, 23, NULL, NULL, PPC_OPERAND_ACC },
2336
2337 /* An optional BF field. This is used for comparison instructions,
2338 in which an omitted BF field is taken as zero. */
2339 #define OBF ACC + 1
2340 { 0x7, 23, NULL, NULL, PPC_OPERAND_CR_REG | PPC_OPERAND_OPTIONAL },
2341
2342 /* The BFA field in an X or XL form instruction. */
2343 #define BFA OBF + 1
2344 { 0x7, 18, NULL, NULL, PPC_OPERAND_CR_REG },
2345
2346 /* The BO field in a B form instruction. Certain values are
2347 illegal. */
2348 #define BO BFA + 1
2349 #define BO_MASK (0x1f << 21)
2350 { 0x1f, 21, insert_bo, extract_bo, 0 },
2351
2352 /* The BO field in a B form instruction when the - modifier is used. */
2353 #define BOM BO + 1
2354 { 0x1f, 21, insert_bom, extract_bom, 0 },
2355
2356 /* The BO field in a B form instruction when the + modifier is used. */
2357 #define BOP BOM + 1
2358 { 0x1f, 21, insert_bop, extract_bop, 0 },
2359
2360 /* The RM field in an X form instruction. */
2361 #define RM BOP + 1
2362 #define DD RM
2363 { 0x3, 11, NULL, NULL, 0 },
2364
2365 #define BH RM + 1
2366 { 0x3, 11, NULL, NULL, PPC_OPERAND_OPTIONAL },
2367
2368 /* The BT field in an X or XL form instruction. */
2369 #define BT BH + 1
2370 { 0x1f, 21, NULL, NULL, PPC_OPERAND_CR_BIT },
2371
2372 /* The BT field in a mtfsb0 or mtfsb1 instruction. */
2373 #define BTF BT + 1
2374 { 0x1f, 21, NULL, NULL, PPC_OPERAND_CR_BIT | PPC_OPERAND_CR_REG },
2375
2376 /* The BI16 field in a BD8 form instruction. */
2377 #define BI16 BTF + 1
2378 { 0x3, 8, NULL, NULL, PPC_OPERAND_CR_BIT },
2379
2380 /* The BI32 field in a BD15 form instruction. */
2381 #define BI32 BI16 + 1
2382 { 0xf, 16, NULL, NULL, PPC_OPERAND_CR_BIT },
2383
2384 /* The BO32 field in a BD15 form instruction. */
2385 #define BO32 BI32 + 1
2386 { 0x3, 20, NULL, NULL, 0 },
2387
2388 /* The B8 field in a BD8 form instruction. */
2389 #define B8 BO32 + 1
2390 { 0x1fe, -1, NULL, NULL, PPC_OPERAND_RELATIVE | PPC_OPERAND_SIGNED },
2391
2392 /* The B15 field in a BD15 form instruction. The lowest bit is
2393 forced to zero. */
2394 #define B15 B8 + 1
2395 { 0xfffe, 0, NULL, NULL, PPC_OPERAND_RELATIVE | PPC_OPERAND_SIGNED },
2396
2397 /* The B24 field in a BD24 form instruction. The lowest bit is
2398 forced to zero. */
2399 #define B24 B15 + 1
2400 { 0x1fffffe, 0, NULL, NULL, PPC_OPERAND_RELATIVE | PPC_OPERAND_SIGNED },
2401
2402 /* The condition register number portion of the BI field in a B form
2403 or XL form instruction. This is used for the extended
2404 conditional branch mnemonics, which set the lower two bits of the
2405 BI field. This field is optional. */
2406 #define CR B24 + 1
2407 { 0x7, 18, NULL, NULL, PPC_OPERAND_CR_REG | PPC_OPERAND_OPTIONAL },
2408
2409 /* The CRB field in an X form instruction. */
2410 #define CRB CR + 1
2411 /* The MB field in an M form instruction. */
2412 #define MB CRB
2413 #define MB_MASK (0x1f << 6)
2414 { 0x1f, 6, NULL, NULL, 0 },
2415
2416 /* The CRD32 field in an XL form instruction. */
2417 #define CRD32 CRB + 1
2418 { 0x3, 21, NULL, NULL, PPC_OPERAND_CR_REG },
2419
2420 /* The CRFS field in an X form instruction. */
2421 #define CRFS CRD32 + 1
2422 { 0x7, 0, NULL, NULL, PPC_OPERAND_CR_REG },
2423
2424 #define CRS CRFS + 1
2425 { 0x3, 18, NULL, NULL, PPC_OPERAND_CR_REG | PPC_OPERAND_OPTIONAL },
2426
2427 /* The CT field in an X form instruction. */
2428 #define CT CRS + 1
2429 /* The MO field in an mbar instruction. */
2430 #define MO CT
2431 { 0x1f, 21, NULL, NULL, PPC_OPERAND_OPTIONAL },
2432
2433 /* The D field in a D form instruction. This is a displacement off
2434 a register, and implies that the next operand is a register in
2435 parentheses. */
2436 #define D CT + 1
2437 { 0xffff, 0, NULL, NULL, PPC_OPERAND_PARENS | PPC_OPERAND_SIGNED },
2438
2439 /* The D8 field in a D form instruction. This is a displacement off
2440 a register, and implies that the next operand is a register in
2441 parentheses. */
2442 #define D8 D + 1
2443 { 0xff, 0, NULL, NULL, PPC_OPERAND_PARENS | PPC_OPERAND_SIGNED },
2444
2445 /* The DCMX field in an X form instruction. */
2446 #define DCMX D8 + 1
2447 { 0x7f, 16, NULL, NULL, 0 },
2448
2449 /* The split DCMX field in an X form instruction. */
2450 #define DCMXS DCMX + 1
2451 { 0x7f, PPC_OPSHIFT_INV, insert_dcmxs, extract_dcmxs, 0 },
2452
2453 /* The DQ field in a DQ form instruction. This is like D, but the
2454 lower four bits are forced to zero. */
2455 #define DQ DCMXS + 1
2456 { 0xfff0, 0, NULL, NULL,
2457 PPC_OPERAND_PARENS | PPC_OPERAND_SIGNED | PPC_OPERAND_DQ },
2458
2459 /* The DS field in a DS form instruction. This is like D, but the
2460 lower two bits are forced to zero. */
2461 #define DS DQ + 1
2462 { 0xfffc, 0, NULL, NULL,
2463 PPC_OPERAND_PARENS | PPC_OPERAND_SIGNED | PPC_OPERAND_DS },
2464
2465 /* The D field in an 8-byte D form prefix instruction. This is a displacement
2466 off a register, and implies that the next operand is a register in
2467 parentheses. */
2468 #define D34 DS + 1
2469 { UINT64_C(0x3ffffffff), PPC_OPSHIFT_INV, insert_d34, extract_d34,
2470 PPC_OPERAND_PARENS | PPC_OPERAND_SIGNED },
2471
2472 /* The SI field in an 8-byte D form prefix instruction. */
2473 #define SI34 D34 + 1
2474 { UINT64_C(0x3ffffffff), PPC_OPSHIFT_INV, insert_d34, extract_d34, PPC_OPERAND_SIGNED },
2475
2476 /* The NSI field in an 8-byte D form prefix instruction. This is the
2477 same as the SI34 field, only negated. */
2478 #define NSI34 SI34 + 1
2479 { UINT64_C(0x3ffffffff), PPC_OPSHIFT_INV, insert_nsi34, extract_nsi34,
2480 PPC_OPERAND_NEGATIVE | PPC_OPERAND_SIGNED },
2481
2482 /* The IMM32 field in a vector splat immediate prefix instruction. */
2483 #define IMM32 NSI34 + 1
2484 { 0xffffffff, PPC_OPSHIFT_INV, insert_imm32, extract_imm32, 0},
2485
2486 /* The UIM field in a vector permute extended prefix instruction. */
2487 #define UIM3 IMM32 + 1
2488 { 0x7, 32, NULL, NULL, 0},
2489
2490 /* The UIM field in a vector eval prefix instruction. */
2491 #define UIM8 UIM3 + 1
2492 { 0xff, 32, NULL, NULL, 0},
2493
2494 /* The IX field in xxsplti32dx. */
2495 #define IX UIM8 + 1
2496 { 0x1, 17, NULL, NULL, 0 },
2497
2498 /* The PMSK field in GER rank 8 prefix instructions. */
2499 #define PMSK8 IX + 1
2500 { 0xff, 40, NULL, NULL, 0 },
2501
2502 /* The PMSK field in GER rank 4 prefix instructions. */
2503 #define PMSK4 PMSK8 + 1
2504 { 0xf, 44, NULL, NULL, 0 },
2505
2506 /* The PMSK field in GER rank 2 prefix instructions. */
2507 #define PMSK2 PMSK4 + 1
2508 { 0x3, 46, NULL, NULL, 0 },
2509
2510 /* The XMSK field in GER prefix instructions. */
2511 #define XMSK PMSK2 + 1
2512 { 0xf, 36, NULL, NULL, 0 },
2513
2514 /* The YMSK field in GER prefix instructions. */
2515 #define YMSK XMSK + 1
2516 { 0xf, 32, NULL, NULL, 0 },
2517
2518 /* The YMSK field in 64-bit GER prefix instructions. */
2519 #define YMSK2 YMSK + 1
2520 { 0x3, 34, NULL, NULL, 0 },
2521
2522 /* The DUIS or BHRBE fields in a XFX form instruction, 10 bits
2523 unsigned imediate */
2524 #define DUIS YMSK2 + 1
2525 #define BHRBE DUIS
2526 { 0x3ff, 11, NULL, NULL, 0 },
2527
2528 /* The split DW field in a X form instruction. */
2529 #define DW DUIS + 1
2530 { -1, PPC_OPSHIFT_INV, insert_dw, extract_dw,
2531 PPC_OPERAND_PARENS | PPC_OPERAND_SIGNED},
2532
2533 /* The split D field in a DX form instruction. */
2534 #define DXD DW + 1
2535 { 0xffff, PPC_OPSHIFT_INV, insert_dxd, extract_dxd,
2536 PPC_OPERAND_SIGNED | PPC_OPERAND_SIGNOPT},
2537
2538 /* The split ND field in a DX form instruction.
2539 This is the same as the DX field, only negated. */
2540 #define NDXD DXD + 1
2541 { 0xffff, PPC_OPSHIFT_INV, insert_dxdn, extract_dxdn,
2542 PPC_OPERAND_NEGATIVE | PPC_OPERAND_SIGNED | PPC_OPERAND_SIGNOPT},
2543
2544 /* The E field in a wrteei instruction. */
2545 /* And the W bit in the pair singles instructions. */
2546 /* And the ST field in a VX form instruction. */
2547 #define E NDXD + 1
2548 #define PSW E
2549 #define ST E
2550 { 0x1, 15, NULL, NULL, 0 },
2551
2552 /* The FL1 field in a POWER SC form instruction. */
2553 #define FL1 E + 1
2554 /* The U field in an X form instruction. */
2555 #define U FL1
2556 { 0xf, 12, NULL, NULL, 0 },
2557
2558 /* The FL2 field in a POWER SC form instruction. */
2559 #define FL2 FL1 + 1
2560 { 0x7, 2, NULL, NULL, 0 },
2561
2562 /* The FLM field in an XFL form instruction. */
2563 #define FLM FL2 + 1
2564 { 0xff, 17, NULL, NULL, 0 },
2565
2566 /* The FRA field in an X or A form instruction. */
2567 #define FRA FLM + 1
2568 #define FRA_MASK (0x1f << 16)
2569 { 0x1f, 16, NULL, NULL, PPC_OPERAND_FPR },
2570
2571 /* The FRAp field of DFP instructions. */
2572 #define FRAp FRA + 1
2573 { 0x1e, 16, NULL, NULL, PPC_OPERAND_FPR },
2574
2575 /* The FRB field in an X or A form instruction. */
2576 #define FRB FRAp + 1
2577 #define FRB_MASK (0x1f << 11)
2578 { 0x1f, 11, NULL, NULL, PPC_OPERAND_FPR },
2579
2580 /* The FRBp field of DFP instructions. */
2581 #define FRBp FRB + 1
2582 { 0x1e, 11, NULL, NULL, PPC_OPERAND_FPR },
2583
2584 /* The FRC field in an A form instruction. */
2585 #define FRC FRBp + 1
2586 #define FRC_MASK (0x1f << 6)
2587 { 0x1f, 6, NULL, NULL, PPC_OPERAND_FPR },
2588
2589 /* The FRS field in an X form instruction or the FRT field in a D, X
2590 or A form instruction. */
2591 #define FRS FRC + 1
2592 #define FRT FRS
2593 { 0x1f, 21, NULL, NULL, PPC_OPERAND_FPR },
2594
2595 /* The FRSp field of stfdp or the FRTp field of lfdp and DFP
2596 instructions. */
2597 #define FRSp FRS + 1
2598 #define FRTp FRSp
2599 { 0x1e, 21, NULL, NULL, PPC_OPERAND_FPR },
2600
2601 /* The FXM field in an XFX instruction. */
2602 #define FXM FRSp + 1
2603 { 0xff, 12, insert_fxm, extract_fxm, 0 },
2604
2605 /* Power4 version for mfcr. */
2606 #define FXM4 FXM + 1
2607 { 0xff, 12, insert_fxm, extract_fxm, PPC_OPERAND_OPTIONAL },
2608
2609 /* The IMM20 field in an LI instruction. */
2610 #define IMM20 FXM4 + 1
2611 { 0xfffff, PPC_OPSHIFT_INV, insert_li20, extract_li20, PPC_OPERAND_SIGNED},
2612
2613 /* The L field in a D or X form instruction. */
2614 #define L IMM20 + 1
2615 { 0x1, 21, NULL, NULL, 0 },
2616
2617 /* The optional L field in tlbie and tlbiel instructions. */
2618 #define LOPT L + 1
2619 /* The R field in a HTM X form instruction. */
2620 #define HTM_R LOPT
2621 { 0x1, 21, NULL, NULL, PPC_OPERAND_OPTIONAL },
2622
2623 /* The optional L field in the paste. instruction. This is similar to LOPT
2624 above, but with a default value of 1. */
2625 #define L1OPT LOPT + 1
2626 { 0x1, 21, insert_l1opt, extract_l1opt, PPC_OPERAND_OPTIONAL },
2627
2628 /* The optional (for 32-bit) L field in cmp[l][i] instructions. */
2629 #define L32OPT L1OPT + 1
2630 { 0x1, 21, NULL, NULL, PPC_OPERAND_OPTIONAL | PPC_OPERAND_OPTIONAL32 },
2631
2632 /* The 2-bit L or WC field in an X (sync, dcbf or wait) form instruction. */
2633 #define L2OPT L32OPT + 1
2634 #define LS L2OPT
2635 #define WC L2OPT
2636 { 0x3, 21, insert_ls, extract_ls, PPC_OPERAND_OPTIONAL },
2637
2638 /* The LEV field in a POWER SVC / POWER9 SCV form instruction. */
2639 #define SVC_LEV L2OPT + 1
2640 { 0x7f, 5, NULL, NULL, 0 },
2641
2642 /* The LEV field in an SC form instruction. */
2643 #define LEV SVC_LEV + 1
2644 { 0x7f, 5, NULL, NULL, PPC_OPERAND_OPTIONAL },
2645
2646 /* The LI field in an I form instruction. The lower two bits are
2647 forced to zero. */
2648 #define LI LEV + 1
2649 { 0x3fffffc, 0, NULL, NULL, PPC_OPERAND_RELATIVE | PPC_OPERAND_SIGNED },
2650
2651 /* The LI field in an I form instruction when used as an absolute
2652 address. */
2653 #define LIA LI + 1
2654 { 0x3fffffc, 0, NULL, NULL, PPC_OPERAND_ABSOLUTE | PPC_OPERAND_SIGNED },
2655
2656 /* The 3-bit L field in a sync or dcbf instruction. */
2657 #define LS3 LIA + 1
2658 #define L3OPT LS3
2659 { 0x7, 21, insert_ls, extract_ls, PPC_OPERAND_OPTIONAL },
2660
2661 /* The ME field in an M form instruction. */
2662 #define ME LS3 + 1
2663 #define ME_MASK (0x1f << 1)
2664 { 0x1f, 1, NULL, NULL, 0 },
2665
2666 /* The MB and ME fields in an M form instruction expressed a single
2667 operand which is a bitmask indicating which bits to select. This
2668 is a two operand form using PPC_OPERAND_NEXT. See the
2669 description in opcode/ppc.h for what this means. */
2670 #define MBE ME + 1
2671 { 0x1f, 6, NULL, NULL, PPC_OPERAND_OPTIONAL | PPC_OPERAND_NEXT },
2672 { -1, 0, insert_mbe, extract_mbe, 0 },
2673
2674 /* The MB or ME field in an MD or MDS form instruction. The high
2675 bit is wrapped to the low end. */
2676 #define MB6 MBE + 2
2677 #define ME6 MB6
2678 #define MB6_MASK (0x3f << 5)
2679 { 0x3f, 5, insert_mb6, extract_mb6, 0 },
2680
2681 /* The NB field in an X form instruction. The value 32 is stored as
2682 0. */
2683 #define NB MB6 + 1
2684 { 0x1f, 11, NULL, extract_nb, PPC_OPERAND_PLUS1 },
2685
2686 /* The NBI field in an lswi instruction, which has special value
2687 restrictions. The value 32 is stored as 0. */
2688 #define NBI NB + 1
2689 { 0x1f, 11, insert_nbi, extract_nb, PPC_OPERAND_PLUS1 },
2690
2691 /* The NSI field in a D form instruction. This is the same as the
2692 SI field, only negated. */
2693 #define NSI NBI + 1
2694 { 0xffff, 0, insert_nsi, extract_nsi,
2695 PPC_OPERAND_NEGATIVE | PPC_OPERAND_SIGNED },
2696
2697 /* The NSI field in a D form instruction when we accept a wide range
2698 of positive values. */
2699 #define NSISIGNOPT NSI + 1
2700 { 0xffff, 0, insert_nsi, extract_nsi,
2701 PPC_OPERAND_NEGATIVE | PPC_OPERAND_SIGNED | PPC_OPERAND_SIGNOPT },
2702
2703 /* The RA field in an D, DS, DQ, X, XO, M, or MDS form instruction. */
2704 #define RA NSISIGNOPT + 1
2705 #define RA_MASK (0x1f << 16)
2706 { 0x1f, 16, NULL, NULL, PPC_OPERAND_GPR },
2707
2708 /* As above, but 0 in the RA field means zero, not r0. */
2709 #define RA0 RA + 1
2710 { 0x1f, 16, NULL, NULL, PPC_OPERAND_GPR_0 },
2711
2712 /* Similar to above, but optional. */
2713 #define PRA0 RA0 + 1
2714 { 0x1f, 16, NULL, NULL, PPC_OPERAND_GPR_0 | PPC_OPERAND_OPTIONAL },
2715
2716 /* The RA field in the DQ form lq or an lswx instruction, which have
2717 special value restrictions. */
2718 #define RAQ PRA0 + 1
2719 #define RAX RAQ
2720 { 0x1f, 16, insert_raq, extract_raq, PPC_OPERAND_GPR_0 },
2721
2722 /* Similar to above, but optional. */
2723 #define PRAQ RAQ + 1
2724 { 0x1f, 16, insert_raq, extract_raq,
2725 PPC_OPERAND_GPR_0 | PPC_OPERAND_OPTIONAL },
2726
2727 /* The R field in an 8-byte D, DS, DQ or X form prefix instruction. */
2728 #define PCREL PRAQ + 1
2729 #define PCREL_MASK (1ULL << 52)
2730 { 0x1, 52, insert_pcrel, extract_pcrel, PPC_OPERAND_OPTIONAL },
2731
2732 #define PCREL0 PCREL + 1
2733 { 0x1, 52, insert_pcrel, extract_pcrel0, PPC_OPERAND_OPTIONAL },
2734
2735 /* The RA field in a D or X form instruction which is an updating
2736 load, which means that the RA field may not be zero and may not
2737 equal the RT field. */
2738 #define RAL PCREL0 + 1
2739 { 0x1f, 16, insert_ral, extract_ral, PPC_OPERAND_GPR_0 },
2740
2741 /* The RA field in an lmw instruction, which has special value
2742 restrictions. */
2743 #define RAM RAL + 1
2744 { 0x1f, 16, insert_ram, extract_ram, PPC_OPERAND_GPR_0 },
2745
2746 /* The RA field in a D or X form instruction which is an updating
2747 store or an updating floating point load, which means that the RA
2748 field may not be zero. */
2749 #define RAS RAM + 1
2750 { 0x1f, 16, insert_ras, extract_ras, PPC_OPERAND_GPR_0 },
2751
2752 /* The RA field of the tlbwe, dccci and iccci instructions,
2753 which are optional. */
2754 #define RAOPT RAS + 1
2755 { 0x1f, 16, NULL, NULL, PPC_OPERAND_GPR | PPC_OPERAND_OPTIONAL },
2756
2757 /* The RB field in an X, XO, M, or MDS form instruction. */
2758 #define RB RAOPT + 1
2759 #define RB_MASK (0x1f << 11)
2760 { 0x1f, 11, NULL, NULL, PPC_OPERAND_GPR },
2761
2762 /* The RS and RB fields in an X form instruction when they must be the same.
2763 This is used for extended mnemonics like mr. */
2764 #define RSB RB + 1
2765 { 0x1f, 11, insert_rsb, extract_rsb, PPC_OPERAND_GPR },
2766
2767 /* The RB field in an lswx instruction, which has special value
2768 restrictions. */
2769 #define RBX RSB + 1
2770 { 0x1f, 11, insert_rbx, extract_rbx, PPC_OPERAND_GPR },
2771
2772 /* The RB field of the dccci and iccci instructions, which are optional. */
2773 #define RBOPT RBX + 1
2774 { 0x1f, 11, NULL, NULL, PPC_OPERAND_GPR | PPC_OPERAND_OPTIONAL },
2775
2776 /* The RC register field in an maddld, maddhd or maddhdu instruction. */
2777 #define RC RBOPT + 1
2778 { 0x1f, 6, NULL, NULL, PPC_OPERAND_GPR },
2779
2780 /* The RS field in a D, DS, X, XFX, XS, M, MD or MDS form
2781 instruction or the RT field in a D, DS, X, XFX or XO form
2782 instruction. */
2783 #define RS RC + 1
2784 #define RT RS
2785 #define RT_MASK (0x1f << 21)
2786 #define RD RS
2787 { 0x1f, 21, NULL, NULL, PPC_OPERAND_GPR },
2788
2789 #define RD_EVEN RS + 1
2790 #define RS_EVEN RD_EVEN
2791 { 0x1f, 21, insert_rD_rS_even, extract_rD_rS_even, PPC_OPERAND_GPR },
2792
2793 /* The RS and RT fields of the DS form stq and DQ form lq instructions,
2794 which have special value restrictions. */
2795 #define RSQ RS_EVEN + 1
2796 #define RTQ RSQ
2797 #define Q_MASK (1 << 21)
2798 { 0x1e, 21, NULL, NULL, PPC_OPERAND_GPR },
2799
2800 /* The RS field of the tlbwe instruction, which is optional. */
2801 #define RSO RSQ + 1
2802 #define RTO RSO
2803 { 0x1f, 21, NULL, NULL, PPC_OPERAND_GPR | PPC_OPERAND_OPTIONAL },
2804
2805 /* The RX field of the SE_RR form instruction. */
2806 #define RX RSO + 1
2807 { 0x1f, PPC_OPSHIFT_INV, insert_rx, extract_rx, PPC_OPERAND_GPR },
2808
2809 /* The ARX field of the SE_RR form instruction. */
2810 #define ARX RX + 1
2811 { 0x1f, PPC_OPSHIFT_INV, insert_arx, extract_arx, PPC_OPERAND_GPR },
2812
2813 /* The RY field of the SE_RR form instruction. */
2814 #define RY ARX + 1
2815 #define RZ RY
2816 { 0x1f, PPC_OPSHIFT_INV, insert_ry, extract_ry, PPC_OPERAND_GPR },
2817
2818 /* The ARY field of the SE_RR form instruction. */
2819 #define ARY RY + 1
2820 { 0x1f, PPC_OPSHIFT_INV, insert_ary, extract_ary, PPC_OPERAND_GPR },
2821
2822 /* The SCLSCI8 field in a D form instruction. */
2823 #define SCLSCI8 ARY + 1
2824 { 0xffffffff, PPC_OPSHIFT_INV, insert_sci8, extract_sci8, 0 },
2825
2826 /* The SCLSCI8N field in a D form instruction. This is the same as the
2827 SCLSCI8 field, only negated. */
2828 #define SCLSCI8N SCLSCI8 + 1
2829 { 0xffffffff, PPC_OPSHIFT_INV, insert_sci8n, extract_sci8n,
2830 PPC_OPERAND_NEGATIVE | PPC_OPERAND_SIGNED },
2831
2832 /* The SD field of the SD4 form instruction. */
2833 #define SE_SD SCLSCI8N + 1
2834 { 0xf, 8, NULL, NULL, PPC_OPERAND_PARENS },
2835
2836 /* The SD field of the SD4 form instruction, for halfword. */
2837 #define SE_SDH SE_SD + 1
2838 { 0x1e, 7, NULL, NULL, PPC_OPERAND_PARENS },
2839
2840 /* The SD field of the SD4 form instruction, for word. */
2841 #define SE_SDW SE_SDH + 1
2842 { 0x3c, 6, NULL, NULL, PPC_OPERAND_PARENS },
2843
2844 /* The SH field in an X or M form instruction. */
2845 #define SH SE_SDW + 1
2846 #define SH_MASK (0x1f << 11)
2847 /* The other UIMM field in a EVX form instruction. */
2848 #define EVUIMM SH
2849 /* The FC field in an atomic X form instruction. */
2850 #define FC SH
2851 #define UIM5 SH
2852 { 0x1f, 11, NULL, NULL, 0 },
2853
2854 #define EVUIMM_LT8 SH + 1
2855 { 0x1f, 11, insert_evuimm_lt8, extract_evuimm_lt8, 0 },
2856
2857 #define EVUIMM_LT16 EVUIMM_LT8 + 1
2858 { 0x1f, 11, insert_evuimm_lt16, extract_evuimm_lt16, 0 },
2859
2860 /* The SI field in a HTM X form instruction. */
2861 #define HTM_SI EVUIMM_LT16 + 1
2862 { 0x1f, 11, NULL, NULL, PPC_OPERAND_SIGNED },
2863
2864 /* The SH field in an MD form instruction. This is split. */
2865 #define SH6 HTM_SI + 1
2866 #define SH6_MASK ((0x1f << 11) | (1 << 1))
2867 { 0x3f, PPC_OPSHIFT_INV, insert_sh6, extract_sh6, 0 },
2868
2869 /* The SH field of some variants of the tlbre and tlbwe
2870 instructions, and the ELEV field of the e_sc instruction. */
2871 #define SHO SH6 + 1
2872 #define ELEV SHO
2873 { 0x1f, 11, NULL, NULL, PPC_OPERAND_OPTIONAL },
2874
2875 /* The SI field in a D form instruction. */
2876 #define SI SHO + 1
2877 { 0xffff, 0, NULL, NULL, PPC_OPERAND_SIGNED },
2878
2879 /* The SI field in a D form instruction when we accept a wide range
2880 of positive values. */
2881 #define SISIGNOPT SI + 1
2882 { 0xffff, 0, NULL, NULL, PPC_OPERAND_SIGNED | PPC_OPERAND_SIGNOPT },
2883
2884 /* The SI8 field in a D form instruction. */
2885 #define SI8 SISIGNOPT + 1
2886 { 0xff, 0, NULL, NULL, PPC_OPERAND_SIGNED },
2887
2888 /* The SPR field in an XFX form instruction. This is flipped--the
2889 lower 5 bits are stored in the upper 5 and vice- versa. */
2890 #define SPR SI8 + 1
2891 #define PMR SPR
2892 #define TMR SPR
2893 #define SPR_MASK (0x3ff << 11)
2894 { 0x3ff, 11, insert_spr, extract_spr, PPC_OPERAND_SPR },
2895
2896 /* The BAT index number in an XFX form m[ft]ibat[lu] instruction. */
2897 #define SPRBAT SPR + 1
2898 #define SPRBAT_MASK (0xc1 << 11)
2899 { 0x7, PPC_OPSHIFT_INV, insert_sprbat, extract_sprbat, PPC_OPERAND_SPR },
2900
2901 /* The GQR index number in an XFX form m[ft]gqr instruction. */
2902 #define SPRGQR SPRBAT + 1
2903 #define SPRGQR_MASK (0x7 << 16)
2904 { 0x7, 16, NULL, NULL, PPC_OPERAND_GQR },
2905
2906 /* The SPRG register number in an XFX form m[ft]sprg instruction. */
2907 #define SPRG SPRGQR + 1
2908 { 0x1f, 16, insert_sprg, extract_sprg, PPC_OPERAND_SPR },
2909
2910 /* The SR field in an X form instruction. */
2911 #define SR SPRG + 1
2912 /* The 4-bit UIMM field in a VX form instruction. */
2913 #define UIMM4 SR
2914 { 0xf, 16, NULL, NULL, 0 },
2915
2916 /* The STRM field in an X AltiVec form instruction. */
2917 #define STRM SR + 1
2918 /* The T field in a tlbilx form instruction. */
2919 #define T STRM
2920 /* The L field in wclr instructions. */
2921 #define L2 STRM
2922 { 0x3, 21, NULL, NULL, 0 },
2923
2924 /* The ESYNC field in an X (sync) form instruction. */
2925 #define ESYNC STRM + 1
2926 { 0xf, 16, insert_esync, extract_esync, PPC_OPERAND_OPTIONAL },
2927
2928 /* The SV field in a POWER SC form instruction. */
2929 #define SV ESYNC + 1
2930 { 0x3fff, 2, NULL, NULL, 0 },
2931
2932 /* The TBR field in an XFX form instruction. This is like the SPR
2933 field, but it is optional. */
2934 #define TBR SV + 1
2935 { 0x3ff, 11, insert_tbr, extract_tbr,
2936 PPC_OPERAND_SPR | PPC_OPERAND_OPTIONAL },
2937
2938 /* The TO field in a D or X form instruction. */
2939 #define TO TBR + 1
2940 #define DUI TO
2941 #define TO_MASK (0x1f << 21)
2942 { 0x1f, 21, NULL, NULL, 0 },
2943
2944 /* The UI field in a D form instruction. */
2945 #define UI TO + 1
2946 { 0xffff, 0, NULL, NULL, 0 },
2947
2948 #define UISIGNOPT UI + 1
2949 { 0xffff, 0, NULL, NULL, PPC_OPERAND_SIGNOPT },
2950
2951 /* The IMM field in an SE_IM5 instruction. */
2952 #define UI5 UISIGNOPT + 1
2953 { 0x1f, 4, NULL, NULL, 0 },
2954
2955 /* The OIMM field in an SE_OIM5 instruction. */
2956 #define OIMM5 UI5 + 1
2957 { 0x1f, 4, insert_oimm, extract_oimm, PPC_OPERAND_PLUS1 },
2958
2959 /* The UI7 field in an SE_LI instruction. */
2960 #define UI7 OIMM5 + 1
2961 { 0x7f, 4, NULL, NULL, 0 },
2962
2963 /* The VA field in a VA, VX or VXR form instruction. */
2964 #define VA UI7 + 1
2965 { 0x1f, 16, NULL, NULL, PPC_OPERAND_VR },
2966
2967 /* The VB field in a VA, VX or VXR form instruction. */
2968 #define VB VA + 1
2969 { 0x1f, 11, NULL, NULL, PPC_OPERAND_VR },
2970
2971 /* The VC field in a VA form instruction. */
2972 #define VC VB + 1
2973 { 0x1f, 6, NULL, NULL, PPC_OPERAND_VR },
2974
2975 /* The VD or VS field in a VA, VX, VXR or X form instruction. */
2976 #define VD VC + 1
2977 #define VS VD
2978 { 0x1f, 21, NULL, NULL, PPC_OPERAND_VR },
2979
2980 /* The SIMM field in a VX form instruction, and TE in Z form. */
2981 #define SIMM VD + 1
2982 #define TE SIMM
2983 { 0x1f, 16, NULL, NULL, PPC_OPERAND_SIGNED},
2984
2985 /* The UIMM field in a VX form instruction. */
2986 #define UIMM SIMM + 1
2987 #define DCTL UIMM
2988 { 0x1f, 16, NULL, NULL, 0 },
2989
2990 /* The 3-bit UIMM field in a VX form instruction. */
2991 #define UIMM3 UIMM + 1
2992 { 0x7, 16, NULL, NULL, 0 },
2993
2994 /* The 6-bit UIM field in a X form instruction. */
2995 #define UIM6 UIMM3 + 1
2996 { 0x3f, 16, NULL, NULL, 0 },
2997
2998 /* The SIX field in a VX form instruction. */
2999 #define SIX UIM6 + 1
3000 #define MMMM SIX
3001 { 0xf, 11, NULL, NULL, 0 },
3002
3003 /* The PS field in a VX form instruction. */
3004 #define PS SIX + 1
3005 { 0x1, 9, NULL, NULL, 0 },
3006
3007 /* The SH field in a vector shift double by bit immediate instruction. */
3008 #define SH3 PS + 1
3009 { 0x7, 6, NULL, NULL, 0 },
3010
3011 /* The SHB field in a VA form instruction. */
3012 #define SHB SH3 + 1
3013 { 0xf, 6, NULL, NULL, 0 },
3014
3015 /* The other UIMM field in a half word EVX form instruction. */
3016 #define EVUIMM_1 SHB + 1
3017 { 0x1f, 11, NULL, NULL, PPC_OPERAND_PARENS },
3018
3019 #define EVUIMM_1_EX0 EVUIMM_1 + 1
3020 { 0x1f, 11, insert_evuimm1_ex0, extract_evuimm1_ex0, PPC_OPERAND_PARENS },
3021
3022 #define EVUIMM_2 EVUIMM_1_EX0 + 1
3023 { 0x3e, 10, NULL, NULL, PPC_OPERAND_PARENS },
3024
3025 #define EVUIMM_2_EX0 EVUIMM_2 + 1
3026 { 0x3e, 10, insert_evuimm2_ex0, extract_evuimm2_ex0, PPC_OPERAND_PARENS },
3027
3028 /* The other UIMM field in a word EVX form instruction. */
3029 #define EVUIMM_4 EVUIMM_2_EX0 + 1
3030 { 0x7c, 9, NULL, NULL, PPC_OPERAND_PARENS },
3031
3032 #define EVUIMM_4_EX0 EVUIMM_4 + 1
3033 { 0x7c, 9, insert_evuimm4_ex0, extract_evuimm4_ex0, PPC_OPERAND_PARENS },
3034
3035 /* The other UIMM field in a double EVX form instruction. */
3036 #define EVUIMM_8 EVUIMM_4_EX0 + 1
3037 { 0xf8, 8, NULL, NULL, PPC_OPERAND_PARENS },
3038
3039 #define EVUIMM_8_EX0 EVUIMM_8 + 1
3040 { 0xf8, 8, insert_evuimm8_ex0, extract_evuimm8_ex0, PPC_OPERAND_PARENS },
3041
3042 /* The WS or DRM field in an X form instruction. */
3043 #define WS EVUIMM_8_EX0 + 1
3044 #define DRM WS
3045 /* The NNN field in a VX form instruction for SPE2 */
3046 #define NNN WS
3047 { 0x7, 11, NULL, NULL, 0 },
3048
3049 /* PowerPC paired singles extensions. */
3050 /* W bit in the pair singles instructions for x type instructions. */
3051 #define PSWM WS + 1
3052 /* The BO16 field in a BD8 form instruction. */
3053 #define BO16 PSWM
3054 { 0x1, 10, 0, 0, 0 },
3055
3056 /* IDX bits for quantization in the pair singles instructions. */
3057 #define PSQ PSWM + 1
3058 { 0x7, 12, 0, 0, PPC_OPERAND_GQR },
3059
3060 /* IDX bits for quantization in the pair singles x-type instructions. */
3061 #define PSQM PSQ + 1
3062 { 0x7, 7, 0, 0, PPC_OPERAND_GQR },
3063
3064 /* Smaller D field for quantization in the pair singles instructions. */
3065 #define PSD PSQM + 1
3066 { 0xfff, 0, 0, 0, PPC_OPERAND_PARENS | PPC_OPERAND_SIGNED },
3067
3068 /* The L field in an mtmsrd or A form instruction or R or W in an
3069 X form. */
3070 #define A_L PSD + 1
3071 #define W A_L
3072 #define X_R A_L
3073 { 0x1, 16, NULL, NULL, PPC_OPERAND_OPTIONAL },
3074
3075 /* The RMC or CY field in a Z23 form instruction. */
3076 #define RMC A_L + 1
3077 #define CY RMC
3078 { 0x3, 9, NULL, NULL, 0 },
3079
3080 #define R RMC + 1
3081 #define MP R
3082 { 0x1, 16, NULL, NULL, 0 },
3083
3084 #define RIC R + 1
3085 { 0x3, 18, NULL, NULL, PPC_OPERAND_OPTIONAL },
3086
3087 #define PRS RIC + 1
3088 { 0x1, 17, NULL, NULL, PPC_OPERAND_OPTIONAL },
3089
3090 #define SP PRS + 1
3091 { 0x3, 19, NULL, NULL, 0 },
3092
3093 #define S SP + 1
3094 { 0x1, 20, NULL, NULL, 0 },
3095
3096 /* The S field in a XL form instruction. */
3097 #define SXL S + 1
3098 { 0x1, 11, insert_sxl, extract_sxl, PPC_OPERAND_OPTIONAL },
3099
3100 /* SH field starting at bit position 16. */
3101 #define SH16 SXL + 1
3102 /* The DCM and DGM fields in a Z form instruction. */
3103 #define DCM SH16
3104 #define DGM DCM
3105 { 0x3f, 10, NULL, NULL, 0 },
3106
3107 /* The EH field in larx instruction. */
3108 #define EH SH16 + 1
3109 { 0x1, 0, NULL, NULL, PPC_OPERAND_OPTIONAL },
3110
3111 /* The L field in an mtfsf or XFL form instruction. */
3112 /* The A field in a HTM X form instruction. */
3113 #define XFL_L EH + 1
3114 #define HTM_A XFL_L
3115 { 0x1, 25, NULL, NULL, PPC_OPERAND_OPTIONAL},
3116
3117 /* Xilinx APU related masks and macros */
3118 #define FCRT XFL_L + 1
3119 #define FCRT_MASK (0x1f << 21)
3120 { 0x1f, 21, 0, 0, PPC_OPERAND_FCR },
3121
3122 /* Xilinx FSL related masks and macros */
3123 #define FSL FCRT + 1
3124 #define FSL_MASK (0x1f << 11)
3125 { 0x1f, 11, 0, 0, PPC_OPERAND_FSL },
3126
3127 /* Xilinx UDI related masks and macros */
3128 #define URT FSL + 1
3129 { 0x1f, 21, 0, 0, PPC_OPERAND_UDI },
3130
3131 #define URA URT + 1
3132 { 0x1f, 16, 0, 0, PPC_OPERAND_UDI },
3133
3134 #define URB URA + 1
3135 { 0x1f, 11, 0, 0, PPC_OPERAND_UDI },
3136
3137 #define URC URB + 1
3138 { 0x1f, 6, 0, 0, PPC_OPERAND_UDI },
3139
3140 /* The VLESIMM field in a D form instruction. */
3141 #define VLESIMM URC + 1
3142 { 0xffff, PPC_OPSHIFT_INV, insert_vlesi, extract_vlesi,
3143 PPC_OPERAND_SIGNED | PPC_OPERAND_SIGNOPT },
3144
3145 /* The VLENSIMM field in a D form instruction. */
3146 #define VLENSIMM VLESIMM + 1
3147 { 0xffff, PPC_OPSHIFT_INV, insert_vlensi, extract_vlensi,
3148 PPC_OPERAND_NEGATIVE | PPC_OPERAND_SIGNED | PPC_OPERAND_SIGNOPT },
3149
3150 /* The VLEUIMM field in a D form instruction. */
3151 #define VLEUIMM VLENSIMM + 1
3152 { 0xffff, PPC_OPSHIFT_INV, insert_vleui, extract_vleui, 0 },
3153
3154 /* The VLEUIMML field in a D form instruction. */
3155 #define VLEUIMML VLEUIMM + 1
3156 { 0xffff, PPC_OPSHIFT_INV, insert_vleil, extract_vleil, 0 },
3157
3158 /* The XT and XS fields in an XX1 or XX3 form instruction. This is
3159 split. */
3160 #define XS6 VLEUIMML + 1
3161 #define XT6 XS6
3162 { 0x3f, PPC_OPSHIFT_INV, insert_xt6, extract_xt6, PPC_OPERAND_VSR },
3163
3164 /* The XT and XS fields in an DQ form VSX instruction. This is split. */
3165 #define XSQ6 XT6 + 1
3166 #define XTQ6 XSQ6
3167 { 0x3f, PPC_OPSHIFT_INV, insert_xtq6, extract_xtq6, PPC_OPERAND_VSR },
3168
3169 /* The split XTp field in a vector paired instruction. */
3170 #define XTP XSQ6 + 1
3171 { 0x3e, PPC_OPSHIFT_INV, insert_xtp, extract_xtp, PPC_OPERAND_VSR },
3172
3173 #define XTS XTP + 1
3174 { 0x3f, PPC_OPSHIFT_INV, insert_xts, extract_xts, PPC_OPERAND_VSR },
3175
3176 /* The XT field in a plxv instruction. Runs into the OP field. */
3177 #define XTOP XTS + 1
3178 { 0x3f, 21, NULL, NULL, PPC_OPERAND_VSR },
3179
3180 /* The XA field in an XX3 form instruction. This is split. */
3181 #define XA6 XTOP + 1
3182 { 0x3f, PPC_OPSHIFT_INV, insert_xa6, extract_xa6, PPC_OPERAND_VSR },
3183
3184 /* The XA field in an MMA XX3 form instruction. This is split and
3185 must not overlap with the ACC operand. */
3186 #define XA6a XA6 + 1
3187 { 0x3f, PPC_OPSHIFT_INV, insert_xa6a, extract_xa6a, PPC_OPERAND_VSR },
3188
3189 /* The XAp field in an MMA XX3 form instruction. This is split.
3190 This is like XA6a, but must be even. */
3191 #define XA6ap XA6a + 1
3192 { 0x3e, PPC_OPSHIFT_INV, insert_xa6a, extract_xa6a, PPC_OPERAND_VSR },
3193
3194 /* The XB field in an XX2 or XX3 form instruction. This is split. */
3195 #define XB6 XA6ap + 1
3196 { 0x3f, PPC_OPSHIFT_INV, insert_xb6, extract_xb6, PPC_OPERAND_VSR },
3197
3198 /* The XB field in an XX3 form instruction. This is split and
3199 must not overlap with the ACC operand. */
3200 #define XB6a XB6 + 1
3201 { 0x3f, PPC_OPSHIFT_INV, insert_xb6a, extract_xb6a, PPC_OPERAND_VSR },
3202
3203 /* The XA and XB fields in an XX3 form instruction when they must be the same.
3204 This is used in extended mnemonics like xvmovdp. This is split. */
3205 #define XAB6 XB6a + 1
3206 { 0x3f, PPC_OPSHIFT_INV, insert_xab6, extract_xab6, PPC_OPERAND_VSR },
3207
3208 /* The XC field in an XX4 form instruction. This is split. */
3209 #define XC6 XAB6 + 1
3210 { 0x3f, PPC_OPSHIFT_INV, insert_xc6, extract_xc6, PPC_OPERAND_VSR },
3211
3212 /* The DM or SHW field in an XX3 form instruction. */
3213 #define DM XC6 + 1
3214 #define SHW DM
3215 { 0x3, 8, NULL, NULL, 0 },
3216
3217 /* The DM field in an extended mnemonic XX3 form instruction. */
3218 #define DMEX DM + 1
3219 { 0x3, 8, insert_dm, extract_dm, 0 },
3220
3221 /* The UIM field in an XX2 form instruction. */
3222 #define UIM DMEX + 1
3223 /* The 2-bit UIMM field in a VX form instruction. */
3224 #define UIMM2 UIM
3225 /* The 2-bit L field in a darn instruction. */
3226 #define LRAND UIM
3227 { 0x3, 16, NULL, NULL, 0 },
3228
3229 #define ERAT_T UIM + 1
3230 { 0x7, 21, NULL, NULL, 0 },
3231
3232 #define IH ERAT_T + 1
3233 { 0x7, 21, NULL, NULL, PPC_OPERAND_OPTIONAL },
3234
3235 /* The 2-bit SC or PL field in an X form instruction. */
3236 #define SC2 IH + 1
3237 #define PL SC2
3238 { 0x3, 16, insert_pl, extract_pl, PPC_OPERAND_OPTIONAL },
3239
3240 /* The 8-bit IMM8 field in a XX1 form instruction. */
3241 #define IMM8 SC2 + 1
3242 { 0xff, 11, NULL, NULL, PPC_OPERAND_SIGNOPT },
3243
3244 #define VX_OFF IMM8 + 1
3245 { 0x3, 0, insert_off_lsp, extract_off_lsp, 0 },
3246
3247 #define VX_OFF_SPE2 VX_OFF + 1
3248 { 0x7, 0, insert_off_spe2, extract_off_spe2, 0 },
3249
3250 #define BBB VX_OFF_SPE2 + 1
3251 { 0x7, 13, NULL, NULL, 0 },
3252
3253 #define DDD BBB + 1
3254 #define VX_MASK_DDD (VX_MASK & ~0x1)
3255 { 0x7, PPC_OPSHIFT_INV, insert_Ddd, extract_Ddd, 0 },
3256
3257 #define HH DDD + 1
3258 { 0x3, 13, NULL, NULL, 0 },
3259 };
3260
3261 const unsigned int num_powerpc_operands = (sizeof (powerpc_operands)
3262 / sizeof (powerpc_operands[0]));
3263 \f
3264 /* Macros used to form opcodes. */
3265
3266 /* The main opcode. */
3267 #define OP(x) ((((uint64_t)(x)) & 0x3f) << 26)
3268 #define OP_MASK OP (0x3f)
3269
3270 /* The prefix opcode. */
3271 #define PREFIX_OP (1ULL << 58)
3272
3273 /* The 2-bit prefix form. */
3274 #define PREFIX_FORM(x) ((x & 3ULL) << 56)
3275
3276 #define SUFFIX_MASK ((1ULL << 32) - 1)
3277 #define PREFIX_MASK (SUFFIX_MASK << 32)
3278
3279 /* Prefix insn, eight byte load/store form 8LS. */
3280 #define P8LS (PREFIX_OP | PREFIX_FORM (0))
3281
3282 /* Prefix insn, eight byte register to register form 8RR. */
3283 #define P8RR (PREFIX_OP | PREFIX_FORM (1))
3284
3285 /* Prefix insn, modified load/store form MLS. */
3286 #define PMLS (PREFIX_OP | PREFIX_FORM (2))
3287
3288 /* Prefix insn, modified register to register form MRR. */
3289 #define PMRR (PREFIX_OP | PREFIX_FORM (3))
3290
3291 /* Prefix insn, modified masked immediate register to register form MMIRR. */
3292 #define PMMIRR (PREFIX_OP | PREFIX_FORM (3) | (9ULL << 52))
3293
3294 /* An 8-byte D form prefix instruction. */
3295 #define P_D_MASK (((-1ULL << 50) & ~PCREL_MASK) | OP_MASK)
3296
3297 /* The same as P_D_MASK, but with the RA and PCREL fields specified. */
3298 #define P_DRAPCREL_MASK (P_D_MASK | PCREL_MASK | RA_MASK)
3299
3300 /* Mask for prefix X form instructions. */
3301 #define P_X_MASK (PREFIX_MASK | X_MASK)
3302 #define P_XX1_MASK (PREFIX_MASK | XX1_MASK)
3303
3304 /* Mask for prefix vector permute insns. */
3305 #define P_XX4_MASK (PREFIX_MASK | XX4_MASK)
3306 #define P_UXX4_MASK (P_XX4_MASK & ~(7ULL << 32))
3307 #define P_U8XX4_MASK (P_XX4_MASK & ~(0xffULL << 32))
3308
3309 /* MMIRR:XX3-form 8-byte outer product instructions. */
3310 #define P_GER_MASK ((-1ULL << 40) | XX3_MASK | (3 << 21) | 1)
3311 #define P_GER2_MASK (P_GER_MASK & ~(3ULL << 46))
3312 #define P_GER4_MASK (P_GER_MASK & ~(15ULL << 44))
3313 #define P_GER8_MASK (P_GER_MASK & ~(255ULL << 40))
3314 #define P_GER64_MASK (P_GER_MASK | (3ULL << 32))
3315
3316 /* Vector splat immediate op. */
3317 #define VSOP(op, xop) (OP (op) | (xop << 17))
3318 #define P_VS_MASK ((-1ULL << 48) | VSOP (0x3f, 0xf))
3319 #define P_VSI_MASK ((-1ULL << 48) | VSOP (0x3f, 0xe))
3320
3321 /* The main opcode combined with a trap code in the TO field of a D
3322 form instruction. Used for extended mnemonics for the trap
3323 instructions. */
3324 #define OPTO(x,to) (OP (x) | ((((uint64_t)(to)) & 0x1f) << 21))
3325 #define OPTO_MASK (OP_MASK | TO_MASK)
3326
3327 /* The main opcode combined with a comparison size bit in the L field
3328 of a D form or X form instruction. Used for extended mnemonics for
3329 the comparison instructions. */
3330 #define OPL(x,l) (OP (x) | ((((uint64_t)(l)) & 1) << 21))
3331 #define OPL_MASK OPL (0x3f,1)
3332
3333 /* The main opcode combined with an update code in D form instruction.
3334 Used for extended mnemonics for VLE memory instructions. */
3335 #define OPVUP(x,vup) (OP (x) | ((((uint64_t)(vup)) & 0xff) << 8))
3336 #define OPVUP_MASK OPVUP (0x3f, 0xff)
3337
3338 /* The main opcode combined with an update code and the RT fields
3339 specified in D form instruction. Used for VLE volatile context
3340 save/restore instructions. */
3341 #define OPVUPRT(x,vup,rt) \
3342 (OPVUP (x, vup) \
3343 | ((((uint64_t)(rt)) & 0x1f) << 21))
3344 #define OPVUPRT_MASK OPVUPRT (0x3f, 0xff, 0x1f)
3345
3346 /* An A form instruction. */
3347 #define A(op, xop, rc) \
3348 (OP (op) \
3349 | ((((uint64_t)(xop)) & 0x1f) << 1) \
3350 | (((uint64_t)(rc)) & 1))
3351 #define A_MASK A (0x3f, 0x1f, 1)
3352
3353 /* An A_MASK with the FRB field fixed. */
3354 #define AFRB_MASK (A_MASK | FRB_MASK)
3355
3356 /* An A_MASK with the FRC field fixed. */
3357 #define AFRC_MASK (A_MASK | FRC_MASK)
3358
3359 /* An A_MASK with the FRA and FRC fields fixed. */
3360 #define AFRAFRC_MASK (A_MASK | FRA_MASK | FRC_MASK)
3361
3362 /* An AFRAFRC_MASK, but with L bit clear. */
3363 #define AFRALFRC_MASK (AFRAFRC_MASK & ~((uint64_t) 1 << 16))
3364
3365 /* A B form instruction. */
3366 #define B(op, aa, lk) \
3367 (OP (op) \
3368 | ((((uint64_t)(aa)) & 1) << 1) \
3369 | ((lk) & 1))
3370 #define B_MASK B (0x3f, 1, 1)
3371
3372 /* A BD8 form instruction. This is a 16-bit instruction. */
3373 #define BD8(op, aa, lk) \
3374 (((((uint64_t)(op)) & 0x3f) << 10) \
3375 | (((aa) & 1) << 9) \
3376 | (((lk) & 1) << 8))
3377 #define BD8_MASK BD8 (0x3f, 1, 1)
3378
3379 /* Another BD8 form instruction. This is a 16-bit instruction. */
3380 #define BD8IO(op) ((((uint64_t)(op)) & 0x1f) << 11)
3381 #define BD8IO_MASK BD8IO (0x1f)
3382
3383 /* A BD8 form instruction for simplified mnemonics. */
3384 #define EBD8IO(op, bo, bi) (BD8IO ((op)) | ((bo) << 10) | ((bi) << 8))
3385 /* A mask that excludes BO32 and BI32. */
3386 #define EBD8IO1_MASK 0xf800
3387 /* A mask that includes BO32 and excludes BI32. */
3388 #define EBD8IO2_MASK 0xfc00
3389 /* A mask that include BO32 AND BI32. */
3390 #define EBD8IO3_MASK 0xff00
3391
3392 /* A BD15 form instruction. */
3393 #define BD15(op, aa, lk) \
3394 (OP (op) \
3395 | ((((uint64_t)(aa)) & 0xf) << 22) \
3396 | ((lk) & 1))
3397 #define BD15_MASK BD15 (0x3f, 0xf, 1)
3398
3399 /* A BD15 form instruction for extended conditional branch mnemonics. */
3400 #define EBD15(op, aa, bo, lk) \
3401 (((op) & 0x3fu) << 26) \
3402 | (((aa) & 0xf) << 22) \
3403 | (((bo) & 0x3) << 20) \
3404 | ((lk) & 1)
3405 #define EBD15_MASK 0xfff00001
3406
3407 /* A BD15 form instruction for extended conditional branch mnemonics
3408 with BI. */
3409 #define EBD15BI(op, aa, bo, bi, lk) \
3410 ((((op) & 0x3fu) << 26) \
3411 | (((aa) & 0xf) << 22) \