1 /* Disassembler interface for targets using CGEN. -*- C -*-
2 CGEN: Cpu tools GENerator
4 THIS FILE IS MACHINE GENERATED WITH CGEN.
5 - the resultant file is machine generated, cgen-dis.in isn't
7 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005
8 Free Software Foundation, Inc.
10 This file is part of the GNU Binutils and GDB, the GNU debugger.
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2, or (at your option)
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
26 /* ??? Eventually more and more of this stuff can go to cpu-independent files.
35 #include "libiberty.h"
40 /* Default text to print if an instruction isn't recognized. */
41 #define UNKNOWN_INSN_MSG _("*unknown*")
43 static void print_normal
44 (CGEN_CPU_DESC
, void *, long, unsigned int, bfd_vma
, int);
45 static void print_address
46 (CGEN_CPU_DESC
, void *, bfd_vma
, unsigned int, bfd_vma
, int) ATTRIBUTE_UNUSED
;
47 static void print_keyword
48 (CGEN_CPU_DESC
, void *, CGEN_KEYWORD
*, long, unsigned int) ATTRIBUTE_UNUSED
;
49 static void print_insn_normal
50 (CGEN_CPU_DESC
, void *, const CGEN_INSN
*, CGEN_FIELDS
*, bfd_vma
, int);
52 (CGEN_CPU_DESC
, bfd_vma
, disassemble_info
*, bfd_byte
*, unsigned);
53 static int default_print_insn
54 (CGEN_CPU_DESC
, bfd_vma
, disassemble_info
*) ATTRIBUTE_UNUSED
;
56 (CGEN_CPU_DESC
, bfd_vma
, disassemble_info
*, bfd_byte
*, int, CGEN_EXTRACT_INFO
*,
59 /* -- disassembler routines inserted here. */
63 print_at (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
65 long reloc_ann ATTRIBUTE_UNUSED
,
66 long value ATTRIBUTE_UNUSED
,
67 bfd_vma pc ATTRIBUTE_UNUSED
,
68 int length ATTRIBUTE_UNUSED
)
70 disassemble_info
*info
= (disassemble_info
*) dis_info
;
72 (*info
->fprintf_func
) (info
->stream
, "@");
76 print_spr (CGEN_CPU_DESC cd
,
82 /* Use the register index format for any unnamed registers. */
83 if (cgen_keyword_lookup_value (names
, regno
) == NULL
)
85 disassemble_info
*info
= (disassemble_info
*) dis_info
;
86 (*info
->fprintf_func
) (info
->stream
, "spr[%ld]", regno
);
89 print_keyword (cd
, dis_info
, names
, regno
, attrs
);
93 print_hi (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
96 unsigned int attrs ATTRIBUTE_UNUSED
,
97 bfd_vma pc ATTRIBUTE_UNUSED
,
98 int length ATTRIBUTE_UNUSED
)
100 disassemble_info
*info
= (disassemble_info
*) dis_info
;
102 (*info
->fprintf_func
) (info
->stream
, value
? "0x%lx" : "hi(0x%lx)", value
);
106 print_lo (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
109 unsigned int attrs ATTRIBUTE_UNUSED
,
110 bfd_vma pc ATTRIBUTE_UNUSED
,
111 int length ATTRIBUTE_UNUSED
)
113 disassemble_info
*info
= (disassemble_info
*) dis_info
;
115 (*info
->fprintf_func
) (info
->stream
, "0x%lx", value
);
117 (*info
->fprintf_func
) (info
->stream
, "lo(0x%lx)", value
);
122 void frv_cgen_print_operand
123 (CGEN_CPU_DESC
, int, PTR
, CGEN_FIELDS
*, void const *, bfd_vma
, int);
125 /* Main entry point for printing operands.
126 XINFO is a `void *' and not a `disassemble_info *' to not put a requirement
127 of dis-asm.h on cgen.h.
129 This function is basically just a big switch statement. Earlier versions
130 used tables to look up the function to use, but
131 - if the table contains both assembler and disassembler functions then
132 the disassembler contains much of the assembler and vice-versa,
133 - there's a lot of inlining possibilities as things grow,
134 - using a switch statement avoids the function call overhead.
136 This function could be moved into `print_insn_normal', but keeping it
137 separate makes clear the interface between `print_insn_normal' and each of
141 frv_cgen_print_operand (CGEN_CPU_DESC cd
,
145 void const *attrs ATTRIBUTE_UNUSED
,
149 disassemble_info
*info
= (disassemble_info
*) xinfo
;
153 case FRV_OPERAND_A0
:
154 print_normal (cd
, info
, fields
->f_A
, 0, pc
, length
);
156 case FRV_OPERAND_A1
:
157 print_normal (cd
, info
, fields
->f_A
, 0, pc
, length
);
159 case FRV_OPERAND_ACC40SI
:
160 print_keyword (cd
, info
, & frv_cgen_opval_acc_names
, fields
->f_ACC40Si
, 0);
162 case FRV_OPERAND_ACC40SK
:
163 print_keyword (cd
, info
, & frv_cgen_opval_acc_names
, fields
->f_ACC40Sk
, 0);
165 case FRV_OPERAND_ACC40UI
:
166 print_keyword (cd
, info
, & frv_cgen_opval_acc_names
, fields
->f_ACC40Ui
, 0);
168 case FRV_OPERAND_ACC40UK
:
169 print_keyword (cd
, info
, & frv_cgen_opval_acc_names
, fields
->f_ACC40Uk
, 0);
171 case FRV_OPERAND_ACCGI
:
172 print_keyword (cd
, info
, & frv_cgen_opval_accg_names
, fields
->f_ACCGi
, 0);
174 case FRV_OPERAND_ACCGK
:
175 print_keyword (cd
, info
, & frv_cgen_opval_accg_names
, fields
->f_ACCGk
, 0);
177 case FRV_OPERAND_CCI
:
178 print_keyword (cd
, info
, & frv_cgen_opval_cccr_names
, fields
->f_CCi
, 0);
180 case FRV_OPERAND_CPRDOUBLEK
:
181 print_keyword (cd
, info
, & frv_cgen_opval_cpr_names
, fields
->f_CPRk
, 0);
183 case FRV_OPERAND_CPRI
:
184 print_keyword (cd
, info
, & frv_cgen_opval_cpr_names
, fields
->f_CPRi
, 0);
186 case FRV_OPERAND_CPRJ
:
187 print_keyword (cd
, info
, & frv_cgen_opval_cpr_names
, fields
->f_CPRj
, 0);
189 case FRV_OPERAND_CPRK
:
190 print_keyword (cd
, info
, & frv_cgen_opval_cpr_names
, fields
->f_CPRk
, 0);
192 case FRV_OPERAND_CRI
:
193 print_keyword (cd
, info
, & frv_cgen_opval_cccr_names
, fields
->f_CRi
, 0);
195 case FRV_OPERAND_CRJ
:
196 print_keyword (cd
, info
, & frv_cgen_opval_cccr_names
, fields
->f_CRj
, 0);
198 case FRV_OPERAND_CRJ_FLOAT
:
199 print_keyword (cd
, info
, & frv_cgen_opval_cccr_names
, fields
->f_CRj_float
, 0);
201 case FRV_OPERAND_CRJ_INT
:
202 print_keyword (cd
, info
, & frv_cgen_opval_cccr_names
, fields
->f_CRj_int
, 0);
204 case FRV_OPERAND_CRK
:
205 print_keyword (cd
, info
, & frv_cgen_opval_cccr_names
, fields
->f_CRk
, 0);
207 case FRV_OPERAND_FCCI_1
:
208 print_keyword (cd
, info
, & frv_cgen_opval_fccr_names
, fields
->f_FCCi_1
, 0);
210 case FRV_OPERAND_FCCI_2
:
211 print_keyword (cd
, info
, & frv_cgen_opval_fccr_names
, fields
->f_FCCi_2
, 0);
213 case FRV_OPERAND_FCCI_3
:
214 print_keyword (cd
, info
, & frv_cgen_opval_fccr_names
, fields
->f_FCCi_3
, 0);
216 case FRV_OPERAND_FCCK
:
217 print_keyword (cd
, info
, & frv_cgen_opval_fccr_names
, fields
->f_FCCk
, 0);
219 case FRV_OPERAND_FRDOUBLEI
:
220 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRi
, 0);
222 case FRV_OPERAND_FRDOUBLEJ
:
223 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRj
, 0);
225 case FRV_OPERAND_FRDOUBLEK
:
226 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRk
, 0);
228 case FRV_OPERAND_FRI
:
229 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRi
, 0);
231 case FRV_OPERAND_FRINTI
:
232 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRi
, 0);
234 case FRV_OPERAND_FRINTIEVEN
:
235 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRi
, 0);
237 case FRV_OPERAND_FRINTJ
:
238 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRj
, 0);
240 case FRV_OPERAND_FRINTJEVEN
:
241 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRj
, 0);
243 case FRV_OPERAND_FRINTK
:
244 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRk
, 0);
246 case FRV_OPERAND_FRINTKEVEN
:
247 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRk
, 0);
249 case FRV_OPERAND_FRJ
:
250 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRj
, 0);
252 case FRV_OPERAND_FRK
:
253 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRk
, 0);
255 case FRV_OPERAND_FRKHI
:
256 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRk
, 0);
258 case FRV_OPERAND_FRKLO
:
259 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRk
, 0);
261 case FRV_OPERAND_GRDOUBLEK
:
262 print_keyword (cd
, info
, & frv_cgen_opval_gr_names
, fields
->f_GRk
, 0);
264 case FRV_OPERAND_GRI
:
265 print_keyword (cd
, info
, & frv_cgen_opval_gr_names
, fields
->f_GRi
, 0);
267 case FRV_OPERAND_GRJ
:
268 print_keyword (cd
, info
, & frv_cgen_opval_gr_names
, fields
->f_GRj
, 0);
270 case FRV_OPERAND_GRK
:
271 print_keyword (cd
, info
, & frv_cgen_opval_gr_names
, fields
->f_GRk
, 0);
273 case FRV_OPERAND_GRKHI
:
274 print_keyword (cd
, info
, & frv_cgen_opval_gr_names
, fields
->f_GRk
, 0);
276 case FRV_OPERAND_GRKLO
:
277 print_keyword (cd
, info
, & frv_cgen_opval_gr_names
, fields
->f_GRk
, 0);
279 case FRV_OPERAND_ICCI_1
:
280 print_keyword (cd
, info
, & frv_cgen_opval_iccr_names
, fields
->f_ICCi_1
, 0);
282 case FRV_OPERAND_ICCI_2
:
283 print_keyword (cd
, info
, & frv_cgen_opval_iccr_names
, fields
->f_ICCi_2
, 0);
285 case FRV_OPERAND_ICCI_3
:
286 print_keyword (cd
, info
, & frv_cgen_opval_iccr_names
, fields
->f_ICCi_3
, 0);
288 case FRV_OPERAND_LI
:
289 print_normal (cd
, info
, fields
->f_LI
, 0, pc
, length
);
291 case FRV_OPERAND_LRAD
:
292 print_normal (cd
, info
, fields
->f_LRAD
, 0, pc
, length
);
294 case FRV_OPERAND_LRAE
:
295 print_normal (cd
, info
, fields
->f_LRAE
, 0, pc
, length
);
297 case FRV_OPERAND_LRAS
:
298 print_normal (cd
, info
, fields
->f_LRAS
, 0, pc
, length
);
300 case FRV_OPERAND_TLBPRL
:
301 print_normal (cd
, info
, fields
->f_TLBPRL
, 0, pc
, length
);
303 case FRV_OPERAND_TLBPROPX
:
304 print_normal (cd
, info
, fields
->f_TLBPRopx
, 0, pc
, length
);
306 case FRV_OPERAND_AE
:
307 print_normal (cd
, info
, fields
->f_ae
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
309 case FRV_OPERAND_CALLANN
:
310 print_at (cd
, info
, fields
->f_reloc_ann
, 0, pc
, length
);
312 case FRV_OPERAND_CCOND
:
313 print_normal (cd
, info
, fields
->f_ccond
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
315 case FRV_OPERAND_COND
:
316 print_normal (cd
, info
, fields
->f_cond
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
318 case FRV_OPERAND_D12
:
319 print_normal (cd
, info
, fields
->f_d12
, 0|(1<<CGEN_OPERAND_SIGNED
), pc
, length
);
321 case FRV_OPERAND_DEBUG
:
322 print_normal (cd
, info
, fields
->f_debug
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
324 case FRV_OPERAND_EIR
:
325 print_normal (cd
, info
, fields
->f_eir
, 0, pc
, length
);
327 case FRV_OPERAND_HINT
:
328 print_normal (cd
, info
, fields
->f_hint
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
330 case FRV_OPERAND_HINT_NOT_TAKEN
:
331 print_keyword (cd
, info
, & frv_cgen_opval_h_hint_not_taken
, fields
->f_hint
, 0);
333 case FRV_OPERAND_HINT_TAKEN
:
334 print_keyword (cd
, info
, & frv_cgen_opval_h_hint_taken
, fields
->f_hint
, 0);
336 case FRV_OPERAND_LABEL16
:
337 print_address (cd
, info
, fields
->f_label16
, 0|(1<<CGEN_OPERAND_PCREL_ADDR
), pc
, length
);
339 case FRV_OPERAND_LABEL24
:
340 print_address (cd
, info
, fields
->f_label24
, 0|(1<<CGEN_OPERAND_PCREL_ADDR
)|(1<<CGEN_OPERAND_VIRTUAL
), pc
, length
);
342 case FRV_OPERAND_LDANN
:
343 print_at (cd
, info
, fields
->f_reloc_ann
, 0, pc
, length
);
345 case FRV_OPERAND_LDDANN
:
346 print_at (cd
, info
, fields
->f_reloc_ann
, 0, pc
, length
);
348 case FRV_OPERAND_LOCK
:
349 print_normal (cd
, info
, fields
->f_lock
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
351 case FRV_OPERAND_PACK
:
352 print_keyword (cd
, info
, & frv_cgen_opval_h_pack
, fields
->f_pack
, 0);
354 case FRV_OPERAND_S10
:
355 print_normal (cd
, info
, fields
->f_s10
, 0|(1<<CGEN_OPERAND_SIGNED
)|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
357 case FRV_OPERAND_S12
:
358 print_normal (cd
, info
, fields
->f_d12
, 0|(1<<CGEN_OPERAND_SIGNED
)|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
360 case FRV_OPERAND_S16
:
361 print_normal (cd
, info
, fields
->f_s16
, 0|(1<<CGEN_OPERAND_SIGNED
)|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
363 case FRV_OPERAND_S5
:
364 print_normal (cd
, info
, fields
->f_s5
, 0|(1<<CGEN_OPERAND_SIGNED
)|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
366 case FRV_OPERAND_S6
:
367 print_normal (cd
, info
, fields
->f_s6
, 0|(1<<CGEN_OPERAND_SIGNED
)|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
369 case FRV_OPERAND_S6_1
:
370 print_normal (cd
, info
, fields
->f_s6_1
, 0|(1<<CGEN_OPERAND_SIGNED
)|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
372 case FRV_OPERAND_SLO16
:
373 print_lo (cd
, info
, fields
->f_s16
, 0|(1<<CGEN_OPERAND_SIGNED
), pc
, length
);
375 case FRV_OPERAND_SPR
:
376 print_spr (cd
, info
, & frv_cgen_opval_spr_names
, fields
->f_spr
, 0|(1<<CGEN_OPERAND_VIRTUAL
));
378 case FRV_OPERAND_U12
:
379 print_normal (cd
, info
, fields
->f_u12
, 0|(1<<CGEN_OPERAND_SIGNED
)|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_VIRTUAL
), pc
, length
);
381 case FRV_OPERAND_U16
:
382 print_normal (cd
, info
, fields
->f_u16
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
384 case FRV_OPERAND_U6
:
385 print_normal (cd
, info
, fields
->f_u6
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
387 case FRV_OPERAND_UHI16
:
388 print_hi (cd
, info
, fields
->f_u16
, 0, pc
, length
);
390 case FRV_OPERAND_ULO16
:
391 print_lo (cd
, info
, fields
->f_u16
, 0, pc
, length
);
395 /* xgettext:c-format */
396 fprintf (stderr
, _("Unrecognized field %d while printing insn.\n"),
402 cgen_print_fn
* const frv_cgen_print_handlers
[] =
409 frv_cgen_init_dis (CGEN_CPU_DESC cd
)
411 frv_cgen_init_opcode_table (cd
);
412 frv_cgen_init_ibld_table (cd
);
413 cd
->print_handlers
= & frv_cgen_print_handlers
[0];
414 cd
->print_operand
= frv_cgen_print_operand
;
418 /* Default print handler. */
421 print_normal (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
425 bfd_vma pc ATTRIBUTE_UNUSED
,
426 int length ATTRIBUTE_UNUSED
)
428 disassemble_info
*info
= (disassemble_info
*) dis_info
;
430 #ifdef CGEN_PRINT_NORMAL
431 CGEN_PRINT_NORMAL (cd
, info
, value
, attrs
, pc
, length
);
434 /* Print the operand as directed by the attributes. */
435 if (CGEN_BOOL_ATTR (attrs
, CGEN_OPERAND_SEM_ONLY
))
436 ; /* nothing to do */
437 else if (CGEN_BOOL_ATTR (attrs
, CGEN_OPERAND_SIGNED
))
438 (*info
->fprintf_func
) (info
->stream
, "%ld", value
);
440 (*info
->fprintf_func
) (info
->stream
, "0x%lx", value
);
443 /* Default address handler. */
446 print_address (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
450 bfd_vma pc ATTRIBUTE_UNUSED
,
451 int length ATTRIBUTE_UNUSED
)
453 disassemble_info
*info
= (disassemble_info
*) dis_info
;
455 #ifdef CGEN_PRINT_ADDRESS
456 CGEN_PRINT_ADDRESS (cd
, info
, value
, attrs
, pc
, length
);
459 /* Print the operand as directed by the attributes. */
460 if (CGEN_BOOL_ATTR (attrs
, CGEN_OPERAND_SEM_ONLY
))
461 ; /* Nothing to do. */
462 else if (CGEN_BOOL_ATTR (attrs
, CGEN_OPERAND_PCREL_ADDR
))
463 (*info
->print_address_func
) (value
, info
);
464 else if (CGEN_BOOL_ATTR (attrs
, CGEN_OPERAND_ABS_ADDR
))
465 (*info
->print_address_func
) (value
, info
);
466 else if (CGEN_BOOL_ATTR (attrs
, CGEN_OPERAND_SIGNED
))
467 (*info
->fprintf_func
) (info
->stream
, "%ld", (long) value
);
469 (*info
->fprintf_func
) (info
->stream
, "0x%lx", (long) value
);
472 /* Keyword print handler. */
475 print_keyword (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
477 CGEN_KEYWORD
*keyword_table
,
479 unsigned int attrs ATTRIBUTE_UNUSED
)
481 disassemble_info
*info
= (disassemble_info
*) dis_info
;
482 const CGEN_KEYWORD_ENTRY
*ke
;
484 ke
= cgen_keyword_lookup_value (keyword_table
, value
);
486 (*info
->fprintf_func
) (info
->stream
, "%s", ke
->name
);
488 (*info
->fprintf_func
) (info
->stream
, "???");
491 /* Default insn printer.
493 DIS_INFO is defined as `void *' so the disassembler needn't know anything
494 about disassemble_info. */
497 print_insn_normal (CGEN_CPU_DESC cd
,
499 const CGEN_INSN
*insn
,
504 const CGEN_SYNTAX
*syntax
= CGEN_INSN_SYNTAX (insn
);
505 disassemble_info
*info
= (disassemble_info
*) dis_info
;
506 const CGEN_SYNTAX_CHAR_TYPE
*syn
;
508 CGEN_INIT_PRINT (cd
);
510 for (syn
= CGEN_SYNTAX_STRING (syntax
); *syn
; ++syn
)
512 if (CGEN_SYNTAX_MNEMONIC_P (*syn
))
514 (*info
->fprintf_func
) (info
->stream
, "%s", CGEN_INSN_MNEMONIC (insn
));
517 if (CGEN_SYNTAX_CHAR_P (*syn
))
519 (*info
->fprintf_func
) (info
->stream
, "%c", CGEN_SYNTAX_CHAR (*syn
));
523 /* We have an operand. */
524 frv_cgen_print_operand (cd
, CGEN_SYNTAX_FIELD (*syn
), info
,
525 fields
, CGEN_INSN_ATTRS (insn
), pc
, length
);
529 /* Subroutine of print_insn. Reads an insn into the given buffers and updates
531 Returns 0 if all is well, non-zero otherwise. */
534 read_insn (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
536 disassemble_info
*info
,
539 CGEN_EXTRACT_INFO
*ex_info
,
540 unsigned long *insn_value
)
542 int status
= (*info
->read_memory_func
) (pc
, buf
, buflen
, info
);
546 (*info
->memory_error_func
) (status
, pc
, info
);
550 ex_info
->dis_info
= info
;
551 ex_info
->valid
= (1 << buflen
) - 1;
552 ex_info
->insn_bytes
= buf
;
554 *insn_value
= bfd_get_bits (buf
, buflen
* 8, info
->endian
== BFD_ENDIAN_BIG
);
558 /* Utility to print an insn.
559 BUF is the base part of the insn, target byte order, BUFLEN bytes long.
560 The result is the size of the insn in bytes or zero for an unknown insn
561 or -1 if an error occurs fetching data (memory_error_func will have
565 print_insn (CGEN_CPU_DESC cd
,
567 disassemble_info
*info
,
571 CGEN_INSN_INT insn_value
;
572 const CGEN_INSN_LIST
*insn_list
;
573 CGEN_EXTRACT_INFO ex_info
;
576 /* Extract base part of instruction, just in case CGEN_DIS_* uses it. */
577 basesize
= cd
->base_insn_bitsize
< buflen
* 8 ?
578 cd
->base_insn_bitsize
: buflen
* 8;
579 insn_value
= cgen_get_insn_value (cd
, buf
, basesize
);
582 /* Fill in ex_info fields like read_insn would. Don't actually call
583 read_insn, since the incoming buffer is already read (and possibly
584 modified a la m32r). */
585 ex_info
.valid
= (1 << buflen
) - 1;
586 ex_info
.dis_info
= info
;
587 ex_info
.insn_bytes
= buf
;
589 /* The instructions are stored in hash lists.
590 Pick the first one and keep trying until we find the right one. */
592 insn_list
= CGEN_DIS_LOOKUP_INSN (cd
, (char *) buf
, insn_value
);
593 while (insn_list
!= NULL
)
595 const CGEN_INSN
*insn
= insn_list
->insn
;
598 unsigned long insn_value_cropped
;
600 #ifdef CGEN_VALIDATE_INSN_SUPPORTED
601 /* Not needed as insn shouldn't be in hash lists if not supported. */
602 /* Supported by this cpu? */
603 if (! frv_cgen_insn_supported (cd
, insn
))
605 insn_list
= CGEN_DIS_NEXT_INSN (insn_list
);
610 /* Basic bit mask must be correct. */
611 /* ??? May wish to allow target to defer this check until the extract
614 /* Base size may exceed this instruction's size. Extract the
615 relevant part from the buffer. */
616 if ((unsigned) (CGEN_INSN_BITSIZE (insn
) / 8) < buflen
&&
617 (unsigned) (CGEN_INSN_BITSIZE (insn
) / 8) <= sizeof (unsigned long))
618 insn_value_cropped
= bfd_get_bits (buf
, CGEN_INSN_BITSIZE (insn
),
619 info
->endian
== BFD_ENDIAN_BIG
);
621 insn_value_cropped
= insn_value
;
623 if ((insn_value_cropped
& CGEN_INSN_BASE_MASK (insn
))
624 == CGEN_INSN_BASE_VALUE (insn
))
626 /* Printing is handled in two passes. The first pass parses the
627 machine insn and extracts the fields. The second pass prints
630 /* Make sure the entire insn is loaded into insn_value, if it
632 if (((unsigned) CGEN_INSN_BITSIZE (insn
) > cd
->base_insn_bitsize
) &&
633 (unsigned) (CGEN_INSN_BITSIZE (insn
) / 8) <= sizeof (unsigned long))
635 unsigned long full_insn_value
;
636 int rc
= read_insn (cd
, pc
, info
, buf
,
637 CGEN_INSN_BITSIZE (insn
) / 8,
638 & ex_info
, & full_insn_value
);
641 length
= CGEN_EXTRACT_FN (cd
, insn
)
642 (cd
, insn
, &ex_info
, full_insn_value
, &fields
, pc
);
645 length
= CGEN_EXTRACT_FN (cd
, insn
)
646 (cd
, insn
, &ex_info
, insn_value_cropped
, &fields
, pc
);
648 /* Length < 0 -> error. */
653 CGEN_PRINT_FN (cd
, insn
) (cd
, info
, insn
, &fields
, pc
, length
);
654 /* Length is in bits, result is in bytes. */
659 insn_list
= CGEN_DIS_NEXT_INSN (insn_list
);
665 /* Default value for CGEN_PRINT_INSN.
666 The result is the size of the insn in bytes or zero for an unknown insn
667 or -1 if an error occured fetching bytes. */
669 #ifndef CGEN_PRINT_INSN
670 #define CGEN_PRINT_INSN default_print_insn
674 default_print_insn (CGEN_CPU_DESC cd
, bfd_vma pc
, disassemble_info
*info
)
676 bfd_byte buf
[CGEN_MAX_INSN_SIZE
];
680 /* Attempt to read the base part of the insn. */
681 buflen
= cd
->base_insn_bitsize
/ 8;
682 status
= (*info
->read_memory_func
) (pc
, buf
, buflen
, info
);
684 /* Try again with the minimum part, if min < base. */
685 if (status
!= 0 && (cd
->min_insn_bitsize
< cd
->base_insn_bitsize
))
687 buflen
= cd
->min_insn_bitsize
/ 8;
688 status
= (*info
->read_memory_func
) (pc
, buf
, buflen
, info
);
693 (*info
->memory_error_func
) (status
, pc
, info
);
697 return print_insn (cd
, pc
, info
, buf
, buflen
);
701 Print one instruction from PC on INFO->STREAM.
702 Return the size of the instruction (in bytes). */
704 typedef struct cpu_desc_list
706 struct cpu_desc_list
*next
;
714 print_insn_frv (bfd_vma pc
, disassemble_info
*info
)
716 static cpu_desc_list
*cd_list
= 0;
717 cpu_desc_list
*cl
= 0;
718 static CGEN_CPU_DESC cd
= 0;
719 static CGEN_BITSET
*prev_isa
;
720 static int prev_mach
;
721 static int prev_endian
;
725 int endian
= (info
->endian
== BFD_ENDIAN_BIG
727 : CGEN_ENDIAN_LITTLE
);
728 enum bfd_architecture arch
;
730 /* ??? gdb will set mach but leave the architecture as "unknown" */
731 #ifndef CGEN_BFD_ARCH
732 #define CGEN_BFD_ARCH bfd_arch_frv
735 if (arch
== bfd_arch_unknown
)
736 arch
= CGEN_BFD_ARCH
;
738 /* There's no standard way to compute the machine or isa number
739 so we leave it to the target. */
740 #ifdef CGEN_COMPUTE_MACH
741 mach
= CGEN_COMPUTE_MACH (info
);
746 #ifdef CGEN_COMPUTE_ISA
748 static CGEN_BITSET
*permanent_isa
;
751 permanent_isa
= cgen_bitset_create (MAX_ISAS
);
753 cgen_bitset_clear (isa
);
754 cgen_bitset_add (isa
, CGEN_COMPUTE_ISA (info
));
757 isa
= info
->insn_sets
;
760 /* If we've switched cpu's, try to find a handle we've used before */
762 && (cgen_bitset_compare (isa
, prev_isa
) != 0
764 || endian
!= prev_endian
))
767 for (cl
= cd_list
; cl
; cl
= cl
->next
)
769 if (cgen_bitset_compare (cl
->isa
, isa
) == 0 &&
771 cl
->endian
== endian
)
780 /* If we haven't initialized yet, initialize the opcode table. */
783 const bfd_arch_info_type
*arch_type
= bfd_lookup_arch (arch
, mach
);
784 const char *mach_name
;
788 mach_name
= arch_type
->printable_name
;
790 prev_isa
= cgen_bitset_copy (isa
);
792 prev_endian
= endian
;
793 cd
= frv_cgen_cpu_open (CGEN_CPU_OPEN_ISAS
, prev_isa
,
794 CGEN_CPU_OPEN_BFDMACH
, mach_name
,
795 CGEN_CPU_OPEN_ENDIAN
, prev_endian
,
800 /* Save this away for future reference. */
801 cl
= xmalloc (sizeof (struct cpu_desc_list
));
809 frv_cgen_init_dis (cd
);
812 /* We try to have as much common code as possible.
813 But at this point some targets need to take over. */
814 /* ??? Some targets may need a hook elsewhere. Try to avoid this,
815 but if not possible try to move this hook elsewhere rather than
817 length
= CGEN_PRINT_INSN (cd
, pc
, info
);
823 (*info
->fprintf_func
) (info
->stream
, UNKNOWN_INSN_MSG
);
824 return cd
->default_insn_bitsize
/ 8;