1 /* ppc-dis.c -- Disassemble PowerPC instructions
2 Copyright (C) 1994-2017 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, Cygnus Support
5 This file is part of the GNU opcodes library.
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)
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.
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. */
28 #include "opcode/ppc.h"
29 #include "libiberty.h"
31 /* This file provides several disassembler functions, all of which use
32 the disassembler interface defined in dis-asm.h. Several functions
33 are provided because this file handles disassembly for the PowerPC
34 in both big and little endian mode and also for the POWER (RS/6000)
36 static int print_insn_powerpc (bfd_vma
, struct disassemble_info
*, int,
41 /* Stash the result of parsing disassembler_options here. */
45 #define POWERPC_DIALECT(INFO) \
46 (((struct dis_private *) ((INFO)->private_data))->dialect)
54 struct ppc_mopt ppc_opts
[] = {
55 { "403", PPC_OPCODE_PPC
| PPC_OPCODE_403
,
57 { "405", PPC_OPCODE_PPC
| PPC_OPCODE_403
| PPC_OPCODE_405
,
59 { "440", (PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
| PPC_OPCODE_440
60 | PPC_OPCODE_ISEL
| PPC_OPCODE_RFMCI
),
62 { "464", (PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
| PPC_OPCODE_440
63 | PPC_OPCODE_ISEL
| PPC_OPCODE_RFMCI
),
65 { "476", (PPC_OPCODE_PPC
| PPC_OPCODE_ISEL
| PPC_OPCODE_440
66 | PPC_OPCODE_476
| PPC_OPCODE_POWER4
| PPC_OPCODE_POWER5
),
68 { "601", PPC_OPCODE_PPC
| PPC_OPCODE_601
,
70 { "603", PPC_OPCODE_PPC
,
72 { "604", PPC_OPCODE_PPC
,
74 { "620", PPC_OPCODE_PPC
| PPC_OPCODE_64
,
76 { "7400", PPC_OPCODE_PPC
| PPC_OPCODE_ALTIVEC
,
78 { "7410", PPC_OPCODE_PPC
| PPC_OPCODE_ALTIVEC
,
80 { "7450", PPC_OPCODE_PPC
| PPC_OPCODE_7450
| PPC_OPCODE_ALTIVEC
,
82 { "7455", PPC_OPCODE_PPC
| PPC_OPCODE_ALTIVEC
,
84 { "750cl", PPC_OPCODE_PPC
| PPC_OPCODE_750
| PPC_OPCODE_PPCPS
86 { "821", PPC_OPCODE_PPC
| PPC_OPCODE_860
,
88 { "850", PPC_OPCODE_PPC
| PPC_OPCODE_860
,
90 { "860", PPC_OPCODE_PPC
| PPC_OPCODE_860
,
92 { "a2", (PPC_OPCODE_PPC
| PPC_OPCODE_ISEL
| PPC_OPCODE_POWER4
93 | PPC_OPCODE_POWER5
| PPC_OPCODE_CACHELCK
| PPC_OPCODE_64
96 { "altivec", PPC_OPCODE_PPC
,
100 { "booke", PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
,
102 { "booke32", PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
,
104 { "cell", (PPC_OPCODE_PPC
| PPC_OPCODE_64
| PPC_OPCODE_POWER4
105 | PPC_OPCODE_CELL
| PPC_OPCODE_ALTIVEC
),
107 { "com", PPC_OPCODE_COMMON
,
109 { "e200z4", (PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
| PPC_OPCODE_SPE
110 | PPC_OPCODE_ISEL
| PPC_OPCODE_EFS
| PPC_OPCODE_BRLOCK
111 | PPC_OPCODE_PMR
| PPC_OPCODE_CACHELCK
| PPC_OPCODE_RFMCI
112 | PPC_OPCODE_E500
| PPC_OPCODE_E200Z4
),
114 { "e300", PPC_OPCODE_PPC
| PPC_OPCODE_E300
,
116 { "e500", (PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
| PPC_OPCODE_SPE
117 | PPC_OPCODE_ISEL
| PPC_OPCODE_EFS
| PPC_OPCODE_BRLOCK
118 | PPC_OPCODE_PMR
| PPC_OPCODE_CACHELCK
| PPC_OPCODE_RFMCI
121 { "e500mc", (PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
| PPC_OPCODE_ISEL
122 | PPC_OPCODE_PMR
| PPC_OPCODE_CACHELCK
| PPC_OPCODE_RFMCI
123 | PPC_OPCODE_E500MC
),
125 { "e500mc64", (PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
| PPC_OPCODE_ISEL
126 | PPC_OPCODE_PMR
| PPC_OPCODE_CACHELCK
| PPC_OPCODE_RFMCI
127 | PPC_OPCODE_E500MC
| PPC_OPCODE_64
| PPC_OPCODE_POWER5
128 | PPC_OPCODE_POWER6
| PPC_OPCODE_POWER7
),
130 { "e5500", (PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
| PPC_OPCODE_ISEL
131 | PPC_OPCODE_PMR
| PPC_OPCODE_CACHELCK
| PPC_OPCODE_RFMCI
132 | PPC_OPCODE_E500MC
| PPC_OPCODE_64
| PPC_OPCODE_POWER4
133 | PPC_OPCODE_POWER5
| PPC_OPCODE_POWER6
134 | PPC_OPCODE_POWER7
),
136 { "e6500", (PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
| PPC_OPCODE_ISEL
137 | PPC_OPCODE_PMR
| PPC_OPCODE_CACHELCK
| PPC_OPCODE_RFMCI
138 | PPC_OPCODE_E500MC
| PPC_OPCODE_64
| PPC_OPCODE_ALTIVEC
139 | PPC_OPCODE_ALTIVEC2
| PPC_OPCODE_E6500
| PPC_OPCODE_POWER4
140 | PPC_OPCODE_POWER5
| PPC_OPCODE_POWER6
| PPC_OPCODE_POWER7
),
142 { "e500x2", (PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
| PPC_OPCODE_SPE
143 | PPC_OPCODE_ISEL
| PPC_OPCODE_EFS
| PPC_OPCODE_BRLOCK
144 | PPC_OPCODE_PMR
| PPC_OPCODE_CACHELCK
| PPC_OPCODE_RFMCI
147 { "efs", PPC_OPCODE_PPC
| PPC_OPCODE_EFS
,
149 { "power4", PPC_OPCODE_PPC
| PPC_OPCODE_64
| PPC_OPCODE_POWER4
,
151 { "power5", (PPC_OPCODE_PPC
| PPC_OPCODE_64
| PPC_OPCODE_POWER4
152 | PPC_OPCODE_POWER5
),
154 { "power6", (PPC_OPCODE_PPC
| PPC_OPCODE_64
| PPC_OPCODE_POWER4
155 | PPC_OPCODE_POWER5
| PPC_OPCODE_POWER6
| PPC_OPCODE_ALTIVEC
),
157 { "power7", (PPC_OPCODE_PPC
| PPC_OPCODE_ISEL
| PPC_OPCODE_64
158 | PPC_OPCODE_POWER4
| PPC_OPCODE_POWER5
| PPC_OPCODE_POWER6
159 | PPC_OPCODE_POWER7
| PPC_OPCODE_ALTIVEC
| PPC_OPCODE_VSX
),
161 { "power8", (PPC_OPCODE_PPC
| PPC_OPCODE_ISEL
| PPC_OPCODE_64
162 | PPC_OPCODE_POWER4
| PPC_OPCODE_POWER5
| PPC_OPCODE_POWER6
163 | PPC_OPCODE_POWER7
| PPC_OPCODE_POWER8
| PPC_OPCODE_HTM
164 | PPC_OPCODE_ALTIVEC
| PPC_OPCODE_ALTIVEC2
| PPC_OPCODE_VSX
),
166 { "power9", (PPC_OPCODE_PPC
| PPC_OPCODE_ISEL
| PPC_OPCODE_64
167 | PPC_OPCODE_POWER4
| PPC_OPCODE_POWER5
| PPC_OPCODE_POWER6
168 | PPC_OPCODE_POWER7
| PPC_OPCODE_POWER8
| PPC_OPCODE_POWER9
169 | PPC_OPCODE_HTM
| PPC_OPCODE_ALTIVEC
| PPC_OPCODE_ALTIVEC2
170 | PPC_OPCODE_VSX
| PPC_OPCODE_VSX3
),
172 { "ppc", PPC_OPCODE_PPC
,
174 { "ppc32", PPC_OPCODE_PPC
,
176 { "32", PPC_OPCODE_PPC
,
178 { "ppc64", PPC_OPCODE_PPC
| PPC_OPCODE_64
,
180 { "64", PPC_OPCODE_PPC
| PPC_OPCODE_64
,
182 { "ppc64bridge", PPC_OPCODE_PPC
| PPC_OPCODE_64_BRIDGE
,
184 { "ppcps", PPC_OPCODE_PPC
| PPC_OPCODE_PPCPS
,
186 { "pwr", PPC_OPCODE_POWER
,
188 { "pwr2", PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
,
190 { "pwr4", PPC_OPCODE_PPC
| PPC_OPCODE_64
| PPC_OPCODE_POWER4
,
192 { "pwr5", (PPC_OPCODE_PPC
| PPC_OPCODE_64
| PPC_OPCODE_POWER4
193 | PPC_OPCODE_POWER5
),
195 { "pwr5x", (PPC_OPCODE_PPC
| PPC_OPCODE_64
| PPC_OPCODE_POWER4
196 | PPC_OPCODE_POWER5
),
198 { "pwr6", (PPC_OPCODE_PPC
| PPC_OPCODE_64
| PPC_OPCODE_POWER4
199 | PPC_OPCODE_POWER5
| PPC_OPCODE_POWER6
| PPC_OPCODE_ALTIVEC
),
201 { "pwr7", (PPC_OPCODE_PPC
| PPC_OPCODE_ISEL
| PPC_OPCODE_64
202 | PPC_OPCODE_POWER4
| PPC_OPCODE_POWER5
| PPC_OPCODE_POWER6
203 | PPC_OPCODE_POWER7
| PPC_OPCODE_ALTIVEC
| PPC_OPCODE_VSX
),
205 { "pwr8", (PPC_OPCODE_PPC
| PPC_OPCODE_ISEL
| PPC_OPCODE_64
206 | PPC_OPCODE_POWER4
| PPC_OPCODE_POWER5
| PPC_OPCODE_POWER6
207 | PPC_OPCODE_POWER7
| PPC_OPCODE_POWER8
| PPC_OPCODE_HTM
208 | PPC_OPCODE_ALTIVEC
| PPC_OPCODE_ALTIVEC2
| PPC_OPCODE_VSX
),
210 { "pwr9", (PPC_OPCODE_PPC
| PPC_OPCODE_ISEL
| PPC_OPCODE_64
211 | PPC_OPCODE_POWER4
| PPC_OPCODE_POWER5
| PPC_OPCODE_POWER6
212 | PPC_OPCODE_POWER7
| PPC_OPCODE_POWER8
| PPC_OPCODE_POWER9
213 | PPC_OPCODE_HTM
| PPC_OPCODE_ALTIVEC
| PPC_OPCODE_ALTIVEC2
214 | PPC_OPCODE_VSX
| PPC_OPCODE_VSX3
),
216 { "pwrx", PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
,
218 { "spe", PPC_OPCODE_PPC
| PPC_OPCODE_EFS
,
220 { "titan", (PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
| PPC_OPCODE_PMR
221 | PPC_OPCODE_RFMCI
| PPC_OPCODE_TITAN
),
223 { "vle", (PPC_OPCODE_PPC
| PPC_OPCODE_BOOKE
| PPC_OPCODE_SPE
224 | PPC_OPCODE_ISEL
| PPC_OPCODE_EFS
| PPC_OPCODE_BRLOCK
225 | PPC_OPCODE_PMR
| PPC_OPCODE_CACHELCK
| PPC_OPCODE_RFMCI
228 { "vsx", PPC_OPCODE_PPC
,
230 { "htm", PPC_OPCODE_PPC
,
234 /* Switch between Booke and VLE dialects for interlinked dumps. */
236 get_powerpc_dialect (struct disassemble_info
*info
)
238 ppc_cpu_t dialect
= 0;
240 dialect
= POWERPC_DIALECT (info
);
242 /* Disassemble according to the section headers flags for VLE-mode. */
243 if (dialect
& PPC_OPCODE_VLE
244 && info
->section
!= NULL
&& info
->section
->owner
!= NULL
245 && bfd_get_flavour (info
->section
->owner
) == bfd_target_elf_flavour
246 && elf_object_id (info
->section
->owner
) == PPC32_ELF_DATA
247 && (elf_section_flags (info
->section
) & SHF_PPC_VLE
) != 0)
250 return dialect
& ~ PPC_OPCODE_VLE
;
253 /* Handle -m and -M options that set cpu type, and .machine arg. */
256 ppc_parse_cpu (ppc_cpu_t ppc_cpu
, ppc_cpu_t
*sticky
, const char *arg
)
260 for (i
= 0; i
< ARRAY_SIZE (ppc_opts
); i
++)
261 if (disassembler_options_cmp (ppc_opts
[i
].opt
, arg
) == 0)
263 if (ppc_opts
[i
].sticky
)
265 *sticky
|= ppc_opts
[i
].sticky
;
266 if ((ppc_cpu
& ~*sticky
) != 0)
269 ppc_cpu
= ppc_opts
[i
].cpu
;
272 if (i
>= ARRAY_SIZE (ppc_opts
))
279 /* Determine which set of machines to disassemble for. */
282 powerpc_init_dialect (struct disassemble_info
*info
)
284 ppc_cpu_t dialect
= 0;
285 ppc_cpu_t sticky
= 0;
286 struct dis_private
*priv
= calloc (sizeof (*priv
), 1);
293 case bfd_mach_ppc_403
:
294 case bfd_mach_ppc_403gc
:
295 dialect
= ppc_parse_cpu (dialect
, &sticky
, "403");
297 case bfd_mach_ppc_405
:
298 dialect
= ppc_parse_cpu (dialect
, &sticky
, "405");
300 case bfd_mach_ppc_601
:
301 dialect
= ppc_parse_cpu (dialect
, &sticky
, "601");
303 case bfd_mach_ppc_a35
:
304 case bfd_mach_ppc_rs64ii
:
305 case bfd_mach_ppc_rs64iii
:
306 dialect
= ppc_parse_cpu (dialect
, &sticky
, "pwr2") | PPC_OPCODE_64
;
308 case bfd_mach_ppc_e500
:
309 dialect
= ppc_parse_cpu (dialect
, &sticky
, "e500");
311 case bfd_mach_ppc_e500mc
:
312 dialect
= ppc_parse_cpu (dialect
, &sticky
, "e500mc");
314 case bfd_mach_ppc_e500mc64
:
315 dialect
= ppc_parse_cpu (dialect
, &sticky
, "e500mc64");
317 case bfd_mach_ppc_e5500
:
318 dialect
= ppc_parse_cpu (dialect
, &sticky
, "e5500");
320 case bfd_mach_ppc_e6500
:
321 dialect
= ppc_parse_cpu (dialect
, &sticky
, "e6500");
323 case bfd_mach_ppc_titan
:
324 dialect
= ppc_parse_cpu (dialect
, &sticky
, "titan");
326 case bfd_mach_ppc_vle
:
327 dialect
= ppc_parse_cpu (dialect
, &sticky
, "vle");
330 dialect
= ppc_parse_cpu (dialect
, &sticky
, "power9") | PPC_OPCODE_ANY
;
335 FOR_EACH_DISASSEMBLER_OPTION (opt
, info
->disassembler_options
)
337 ppc_cpu_t new_cpu
= 0;
339 if (disassembler_options_cmp (opt
, "32") == 0)
340 dialect
&= ~(ppc_cpu_t
) PPC_OPCODE_64
;
341 else if (disassembler_options_cmp (opt
, "64") == 0)
342 dialect
|= PPC_OPCODE_64
;
343 else if ((new_cpu
= ppc_parse_cpu (dialect
, &sticky
, opt
)) != 0)
346 fprintf (stderr
, _("warning: ignoring unknown -M%s option\n"), opt
);
349 info
->private_data
= priv
;
350 POWERPC_DIALECT(info
) = dialect
;
353 #define PPC_OPCD_SEGS 64
354 static unsigned short powerpc_opcd_indices
[PPC_OPCD_SEGS
+1];
355 #define VLE_OPCD_SEGS 32
356 static unsigned short vle_opcd_indices
[VLE_OPCD_SEGS
+1];
358 /* Calculate opcode table indices to speed up disassembly,
362 disassemble_init_powerpc (struct disassemble_info
*info
)
367 if (powerpc_opcd_indices
[PPC_OPCD_SEGS
] == 0)
370 i
= powerpc_num_opcodes
;
373 unsigned op
= PPC_OP (powerpc_opcodes
[i
].opcode
);
375 powerpc_opcd_indices
[op
] = i
;
378 last
= powerpc_num_opcodes
;
379 for (i
= PPC_OPCD_SEGS
; i
> 0; --i
)
381 if (powerpc_opcd_indices
[i
] == 0)
382 powerpc_opcd_indices
[i
] = last
;
383 last
= powerpc_opcd_indices
[i
];
389 unsigned op
= VLE_OP (vle_opcodes
[i
].opcode
, vle_opcodes
[i
].mask
);
390 unsigned seg
= VLE_OP_TO_SEG (op
);
392 vle_opcd_indices
[seg
] = i
;
395 last
= vle_num_opcodes
;
396 for (i
= VLE_OPCD_SEGS
; i
> 0; --i
)
398 if (vle_opcd_indices
[i
] == 0)
399 vle_opcd_indices
[i
] = last
;
400 last
= vle_opcd_indices
[i
];
404 if (info
->arch
== bfd_arch_powerpc
)
405 powerpc_init_dialect (info
);
408 /* Print a big endian PowerPC instruction. */
411 print_insn_big_powerpc (bfd_vma memaddr
, struct disassemble_info
*info
)
413 return print_insn_powerpc (memaddr
, info
, 1, get_powerpc_dialect (info
));
416 /* Print a little endian PowerPC instruction. */
419 print_insn_little_powerpc (bfd_vma memaddr
, struct disassemble_info
*info
)
421 return print_insn_powerpc (memaddr
, info
, 0, get_powerpc_dialect (info
));
424 /* Print a POWER (RS/6000) instruction. */
427 print_insn_rs6000 (bfd_vma memaddr
, struct disassemble_info
*info
)
429 return print_insn_powerpc (memaddr
, info
, 1, PPC_OPCODE_POWER
);
432 /* Extract the operand value from the PowerPC or POWER instruction. */
435 operand_value_powerpc (const struct powerpc_operand
*operand
,
436 unsigned long insn
, ppc_cpu_t dialect
)
440 /* Extract the value from the instruction. */
441 if (operand
->extract
)
442 value
= (*operand
->extract
) (insn
, dialect
, &invalid
);
445 if (operand
->shift
>= 0)
446 value
= (insn
>> operand
->shift
) & operand
->bitm
;
448 value
= (insn
<< -operand
->shift
) & operand
->bitm
;
449 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
451 /* BITM is always some number of zeros followed by some
452 number of ones, followed by some number of zeros. */
453 unsigned long top
= operand
->bitm
;
454 /* top & -top gives the rightmost 1 bit, so this
455 fills in any trailing zeros. */
456 top
|= (top
& -top
) - 1;
458 value
= (value
^ top
) - top
;
465 /* Determine whether the optional operand(s) should be printed. */
468 skip_optional_operands (const unsigned char *opindex
,
469 unsigned long insn
, ppc_cpu_t dialect
)
471 const struct powerpc_operand
*operand
;
473 for (; *opindex
!= 0; opindex
++)
475 operand
= &powerpc_operands
[*opindex
];
476 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0
477 || ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
478 && operand_value_powerpc (operand
, insn
, dialect
) !=
479 ppc_optional_operand_value (operand
)))
486 /* Find a match for INSN in the opcode table, given machine DIALECT.
487 A DIALECT of -1 is special, matching all machine opcode variations. */
489 static const struct powerpc_opcode
*
490 lookup_powerpc (unsigned long insn
, ppc_cpu_t dialect
)
492 const struct powerpc_opcode
*opcode
;
493 const struct powerpc_opcode
*opcode_end
;
496 /* Get the major opcode of the instruction. */
499 /* Find the first match in the opcode table for this major opcode. */
500 opcode_end
= powerpc_opcodes
+ powerpc_opcd_indices
[op
+ 1];
501 for (opcode
= powerpc_opcodes
+ powerpc_opcd_indices
[op
];
505 const unsigned char *opindex
;
506 const struct powerpc_operand
*operand
;
509 if ((insn
& opcode
->mask
) != opcode
->opcode
510 || (dialect
!= (ppc_cpu_t
) -1
511 && ((opcode
->flags
& dialect
) == 0
512 || (opcode
->deprecated
& dialect
) != 0)))
515 /* Check validity of operands. */
517 for (opindex
= opcode
->operands
; *opindex
!= 0; opindex
++)
519 operand
= powerpc_operands
+ *opindex
;
520 if (operand
->extract
)
521 (*operand
->extract
) (insn
, dialect
, &invalid
);
532 /* Find a match for INSN in the VLE opcode table. */
534 static const struct powerpc_opcode
*
535 lookup_vle (unsigned long insn
)
537 const struct powerpc_opcode
*opcode
;
538 const struct powerpc_opcode
*opcode_end
;
542 if (op
>= 0x20 && op
<= 0x37)
544 /* This insn has a 4-bit opcode. */
547 seg
= VLE_OP_TO_SEG (op
);
549 /* Find the first match in the opcode table for this major opcode. */
550 opcode_end
= vle_opcodes
+ vle_opcd_indices
[seg
+ 1];
551 for (opcode
= vle_opcodes
+ vle_opcd_indices
[seg
];
555 unsigned long table_opcd
= opcode
->opcode
;
556 unsigned long table_mask
= opcode
->mask
;
557 bfd_boolean table_op_is_short
= PPC_OP_SE_VLE(table_mask
);
559 const unsigned char *opindex
;
560 const struct powerpc_operand
*operand
;
564 if (table_op_is_short
)
566 if ((insn2
& table_mask
) != table_opcd
)
569 /* Check validity of operands. */
571 for (opindex
= opcode
->operands
; *opindex
!= 0; ++opindex
)
573 operand
= powerpc_operands
+ *opindex
;
574 if (operand
->extract
)
575 (*operand
->extract
) (insn
, (ppc_cpu_t
)0, &invalid
);
586 /* Print a PowerPC or POWER instruction. */
589 print_insn_powerpc (bfd_vma memaddr
,
590 struct disassemble_info
*info
,
597 const struct powerpc_opcode
*opcode
;
598 bfd_boolean insn_is_short
;
600 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 4, info
);
603 /* The final instruction may be a 2-byte VLE insn. */
604 if ((dialect
& PPC_OPCODE_VLE
) != 0)
606 /* Clear buffer so unused bytes will not have garbage in them. */
607 buffer
[0] = buffer
[1] = buffer
[2] = buffer
[3] = 0;
608 status
= (*info
->read_memory_func
) (memaddr
, buffer
, 2, info
);
611 (*info
->memory_error_func
) (status
, memaddr
, info
);
617 (*info
->memory_error_func
) (status
, memaddr
, info
);
623 insn
= bfd_getb32 (buffer
);
625 insn
= bfd_getl32 (buffer
);
627 /* Get the major opcode of the insn. */
629 insn_is_short
= FALSE
;
630 if ((dialect
& PPC_OPCODE_VLE
) != 0)
632 opcode
= lookup_vle (insn
);
634 insn_is_short
= PPC_OP_SE_VLE(opcode
->mask
);
637 opcode
= lookup_powerpc (insn
, dialect
);
638 if (opcode
== NULL
&& (dialect
& PPC_OPCODE_ANY
) != 0)
639 opcode
= lookup_powerpc (insn
, (ppc_cpu_t
) -1);
643 const unsigned char *opindex
;
644 const struct powerpc_operand
*operand
;
649 if (opcode
->operands
[0] != 0)
650 (*info
->fprintf_func
) (info
->stream
, "%-7s ", opcode
->name
);
652 (*info
->fprintf_func
) (info
->stream
, "%s", opcode
->name
);
655 /* The operands will be fetched out of the 16-bit instruction. */
658 /* Now extract and print the operands. */
662 for (opindex
= opcode
->operands
; *opindex
!= 0; opindex
++)
666 operand
= powerpc_operands
+ *opindex
;
668 /* Operands that are marked FAKE are simply ignored. We
669 already made sure that the extract function considered
670 the instruction to be valid. */
671 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
674 /* If all of the optional operands have the value zero,
675 then don't print any of them. */
676 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
678 if (skip_optional
< 0)
679 skip_optional
= skip_optional_operands (opindex
, insn
,
685 value
= operand_value_powerpc (operand
, insn
, dialect
);
689 (*info
->fprintf_func
) (info
->stream
, ",");
693 /* Print the operand as directed by the flags. */
694 if ((operand
->flags
& PPC_OPERAND_GPR
) != 0
695 || ((operand
->flags
& PPC_OPERAND_GPR_0
) != 0 && value
!= 0))
696 (*info
->fprintf_func
) (info
->stream
, "r%ld", value
);
697 else if ((operand
->flags
& PPC_OPERAND_FPR
) != 0)
698 (*info
->fprintf_func
) (info
->stream
, "f%ld", value
);
699 else if ((operand
->flags
& PPC_OPERAND_VR
) != 0)
700 (*info
->fprintf_func
) (info
->stream
, "v%ld", value
);
701 else if ((operand
->flags
& PPC_OPERAND_VSR
) != 0)
702 (*info
->fprintf_func
) (info
->stream
, "vs%ld", value
);
703 else if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0)
704 (*info
->print_address_func
) (memaddr
+ value
, info
);
705 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0)
706 (*info
->print_address_func
) ((bfd_vma
) value
& 0xffffffff, info
);
707 else if ((operand
->flags
& PPC_OPERAND_FSL
) != 0)
708 (*info
->fprintf_func
) (info
->stream
, "fsl%ld", value
);
709 else if ((operand
->flags
& PPC_OPERAND_FCR
) != 0)
710 (*info
->fprintf_func
) (info
->stream
, "fcr%ld", value
);
711 else if ((operand
->flags
& PPC_OPERAND_UDI
) != 0)
712 (*info
->fprintf_func
) (info
->stream
, "%ld", value
);
713 else if ((operand
->flags
& PPC_OPERAND_CR_REG
) != 0
714 && (((dialect
& PPC_OPCODE_PPC
) != 0)
715 || ((dialect
& PPC_OPCODE_VLE
) != 0)))
716 (*info
->fprintf_func
) (info
->stream
, "cr%ld", value
);
717 else if (((operand
->flags
& PPC_OPERAND_CR_BIT
) != 0)
718 && (((dialect
& PPC_OPCODE_PPC
) != 0)
719 || ((dialect
& PPC_OPCODE_VLE
) != 0)))
721 static const char *cbnames
[4] = { "lt", "gt", "eq", "so" };
727 (*info
->fprintf_func
) (info
->stream
, "4*cr%d+", cr
);
729 (*info
->fprintf_func
) (info
->stream
, "%s", cbnames
[cc
]);
732 (*info
->fprintf_func
) (info
->stream
, "%d", (int) value
);
736 (*info
->fprintf_func
) (info
->stream
, ")");
740 if ((operand
->flags
& PPC_OPERAND_PARENS
) == 0)
744 (*info
->fprintf_func
) (info
->stream
, "(");
749 /* We have found and printed an instruction.
750 If it was a short VLE instruction we have more to do. */
757 /* Otherwise, return. */
761 /* We could not find a match. */
762 (*info
->fprintf_func
) (info
->stream
, ".long 0x%lx", insn
);
767 const disasm_options_t
*
768 disassembler_options_powerpc (void)
770 static disasm_options_t
*opts
= NULL
;
774 size_t i
, num_options
= ARRAY_SIZE (ppc_opts
);
775 opts
= XNEW (disasm_options_t
);
776 opts
->name
= XNEWVEC (const char *, num_options
+ 1);
777 for (i
= 0; i
< num_options
; i
++)
778 opts
->name
[i
] = ppc_opts
[i
].opt
;
779 /* The array we return must be NULL terminated. */
780 opts
->name
[i
] = NULL
;
781 opts
->description
= NULL
;
788 print_ppc_disassembler_options (FILE *stream
)
792 fprintf (stream
, _("\n\
793 The following PPC specific disassembler options are supported for use with\n\
796 for (col
= 0, i
= 0; i
< ARRAY_SIZE (ppc_opts
); i
++)
798 col
+= fprintf (stream
, " %s,", ppc_opts
[i
].opt
);
801 fprintf (stream
, "\n");
805 fprintf (stream
, "\n");