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
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 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 PARAMS ((CGEN_CPU_DESC
, PTR
, long, unsigned int, bfd_vma
, int));
45 static void print_address
46 PARAMS ((CGEN_CPU_DESC
, PTR
, bfd_vma
, unsigned int, bfd_vma
, int));
47 static void print_keyword
48 PARAMS ((CGEN_CPU_DESC
, PTR
, CGEN_KEYWORD
*, long, unsigned int));
49 static void print_insn_normal
50 PARAMS ((CGEN_CPU_DESC
, PTR
, const CGEN_INSN
*, CGEN_FIELDS
*,
53 PARAMS ((CGEN_CPU_DESC
, bfd_vma
, disassemble_info
*, char *, unsigned));
54 static int default_print_insn
55 PARAMS ((CGEN_CPU_DESC
, bfd_vma
, disassemble_info
*));
57 PARAMS ((CGEN_CPU_DESC
, bfd_vma
, disassemble_info
*, char *, int,
58 CGEN_EXTRACT_INFO
*, unsigned long *));
60 /* -- disassembler routines inserted here */
64 PARAMS ((CGEN_CPU_DESC
, PTR
, CGEN_KEYWORD
*, long, unsigned));
66 PARAMS ((CGEN_CPU_DESC
, PTR
, long, unsigned, bfd_vma
, int));
68 PARAMS ((CGEN_CPU_DESC
, PTR
, long, unsigned, bfd_vma
, int));
71 print_spr (cd
, dis_info
, names
, regno
, attrs
)
78 /* Use the register index format for any unnamed registers. */
79 if (cgen_keyword_lookup_value (names
, regno
) == NULL
)
81 disassemble_info
*info
= (disassemble_info
*) dis_info
;
82 (*info
->fprintf_func
) (info
->stream
, "spr[%ld]", regno
);
85 print_keyword (cd
, dis_info
, names
, regno
, attrs
);
89 print_hi (cd
, dis_info
, value
, attrs
, pc
, length
)
90 CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
;
93 unsigned int attrs ATTRIBUTE_UNUSED
;
94 bfd_vma pc ATTRIBUTE_UNUSED
;
95 int length ATTRIBUTE_UNUSED
;
97 disassemble_info
*info
= (disassemble_info
*) dis_info
;
99 (*info
->fprintf_func
) (info
->stream
, "0x%lx", value
);
101 (*info
->fprintf_func
) (info
->stream
, "hi(0x%lx)", value
);
105 print_lo (cd
, dis_info
, value
, attrs
, pc
, length
)
106 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 PARAMS ((CGEN_CPU_DESC
, int, PTR
, CGEN_FIELDS
*,
124 void const *, bfd_vma
, int));
126 /* Main entry point for printing operands.
127 XINFO is a `void *' and not a `disassemble_info *' to not put a requirement
128 of dis-asm.h on cgen.h.
130 This function is basically just a big switch statement. Earlier versions
131 used tables to look up the function to use, but
132 - if the table contains both assembler and disassembler functions then
133 the disassembler contains much of the assembler and vice-versa,
134 - there's a lot of inlining possibilities as things grow,
135 - using a switch statement avoids the function call overhead.
137 This function could be moved into `print_insn_normal', but keeping it
138 separate makes clear the interface between `print_insn_normal' and each of
142 frv_cgen_print_operand (cd
, opindex
, xinfo
, fields
, attrs
, pc
, length
)
147 void const *attrs ATTRIBUTE_UNUSED
;
151 disassemble_info
*info
= (disassemble_info
*) xinfo
;
156 print_normal (cd
, info
, fields
->f_A
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
158 case FRV_OPERAND_ACC40SI
:
159 print_keyword (cd
, info
, & frv_cgen_opval_acc_names
, fields
->f_ACC40Si
, 0);
161 case FRV_OPERAND_ACC40SK
:
162 print_keyword (cd
, info
, & frv_cgen_opval_acc_names
, fields
->f_ACC40Sk
, 0);
164 case FRV_OPERAND_ACC40UI
:
165 print_keyword (cd
, info
, & frv_cgen_opval_acc_names
, fields
->f_ACC40Ui
, 0);
167 case FRV_OPERAND_ACC40UK
:
168 print_keyword (cd
, info
, & frv_cgen_opval_acc_names
, fields
->f_ACC40Uk
, 0);
170 case FRV_OPERAND_ACCGI
:
171 print_keyword (cd
, info
, & frv_cgen_opval_accg_names
, fields
->f_ACCGi
, 0);
173 case FRV_OPERAND_ACCGK
:
174 print_keyword (cd
, info
, & frv_cgen_opval_accg_names
, fields
->f_ACCGk
, 0);
176 case FRV_OPERAND_CCI
:
177 print_keyword (cd
, info
, & frv_cgen_opval_cccr_names
, fields
->f_CCi
, 0);
179 case FRV_OPERAND_CPRDOUBLEK
:
180 print_keyword (cd
, info
, & frv_cgen_opval_cpr_names
, fields
->f_CPRk
, 0);
182 case FRV_OPERAND_CPRI
:
183 print_keyword (cd
, info
, & frv_cgen_opval_cpr_names
, fields
->f_CPRi
, 0);
185 case FRV_OPERAND_CPRJ
:
186 print_keyword (cd
, info
, & frv_cgen_opval_cpr_names
, fields
->f_CPRj
, 0);
188 case FRV_OPERAND_CPRK
:
189 print_keyword (cd
, info
, & frv_cgen_opval_cpr_names
, fields
->f_CPRk
, 0);
191 case FRV_OPERAND_CRI
:
192 print_keyword (cd
, info
, & frv_cgen_opval_cccr_names
, fields
->f_CRi
, 0);
194 case FRV_OPERAND_CRJ
:
195 print_keyword (cd
, info
, & frv_cgen_opval_cccr_names
, fields
->f_CRj
, 0);
197 case FRV_OPERAND_CRJ_FLOAT
:
198 print_keyword (cd
, info
, & frv_cgen_opval_cccr_names
, fields
->f_CRj_float
, 0);
200 case FRV_OPERAND_CRJ_INT
:
201 print_keyword (cd
, info
, & frv_cgen_opval_cccr_names
, fields
->f_CRj_int
, 0);
203 case FRV_OPERAND_CRK
:
204 print_keyword (cd
, info
, & frv_cgen_opval_cccr_names
, fields
->f_CRk
, 0);
206 case FRV_OPERAND_FCCI_1
:
207 print_keyword (cd
, info
, & frv_cgen_opval_fccr_names
, fields
->f_FCCi_1
, 0);
209 case FRV_OPERAND_FCCI_2
:
210 print_keyword (cd
, info
, & frv_cgen_opval_fccr_names
, fields
->f_FCCi_2
, 0);
212 case FRV_OPERAND_FCCI_3
:
213 print_keyword (cd
, info
, & frv_cgen_opval_fccr_names
, fields
->f_FCCi_3
, 0);
215 case FRV_OPERAND_FCCK
:
216 print_keyword (cd
, info
, & frv_cgen_opval_fccr_names
, fields
->f_FCCk
, 0);
218 case FRV_OPERAND_FRDOUBLEI
:
219 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRi
, 0);
221 case FRV_OPERAND_FRDOUBLEJ
:
222 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRj
, 0);
224 case FRV_OPERAND_FRDOUBLEK
:
225 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRk
, 0);
227 case FRV_OPERAND_FRI
:
228 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRi
, 0);
230 case FRV_OPERAND_FRINTI
:
231 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRi
, 0);
233 case FRV_OPERAND_FRINTIEVEN
:
234 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRi
, 0);
236 case FRV_OPERAND_FRINTJ
:
237 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRj
, 0);
239 case FRV_OPERAND_FRINTJEVEN
:
240 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRj
, 0);
242 case FRV_OPERAND_FRINTK
:
243 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRk
, 0);
245 case FRV_OPERAND_FRINTKEVEN
:
246 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRk
, 0);
248 case FRV_OPERAND_FRJ
:
249 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRj
, 0);
251 case FRV_OPERAND_FRK
:
252 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRk
, 0);
254 case FRV_OPERAND_FRKHI
:
255 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRk
, 0);
257 case FRV_OPERAND_FRKLO
:
258 print_keyword (cd
, info
, & frv_cgen_opval_fr_names
, fields
->f_FRk
, 0);
260 case FRV_OPERAND_GRDOUBLEK
:
261 print_keyword (cd
, info
, & frv_cgen_opval_gr_names
, fields
->f_GRk
, 0);
263 case FRV_OPERAND_GRI
:
264 print_keyword (cd
, info
, & frv_cgen_opval_gr_names
, fields
->f_GRi
, 0);
266 case FRV_OPERAND_GRJ
:
267 print_keyword (cd
, info
, & frv_cgen_opval_gr_names
, fields
->f_GRj
, 0);
269 case FRV_OPERAND_GRK
:
270 print_keyword (cd
, info
, & frv_cgen_opval_gr_names
, fields
->f_GRk
, 0);
272 case FRV_OPERAND_GRKHI
:
273 print_keyword (cd
, info
, & frv_cgen_opval_gr_names
, fields
->f_GRk
, 0);
275 case FRV_OPERAND_GRKLO
:
276 print_keyword (cd
, info
, & frv_cgen_opval_gr_names
, fields
->f_GRk
, 0);
278 case FRV_OPERAND_ICCI_1
:
279 print_keyword (cd
, info
, & frv_cgen_opval_iccr_names
, fields
->f_ICCi_1
, 0);
281 case FRV_OPERAND_ICCI_2
:
282 print_keyword (cd
, info
, & frv_cgen_opval_iccr_names
, fields
->f_ICCi_2
, 0);
284 case FRV_OPERAND_ICCI_3
:
285 print_keyword (cd
, info
, & frv_cgen_opval_iccr_names
, fields
->f_ICCi_3
, 0);
287 case FRV_OPERAND_LI
:
288 print_normal (cd
, info
, fields
->f_LI
, 0, pc
, length
);
290 case FRV_OPERAND_AE
:
291 print_normal (cd
, info
, fields
->f_ae
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
293 case FRV_OPERAND_CCOND
:
294 print_normal (cd
, info
, fields
->f_ccond
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
296 case FRV_OPERAND_COND
:
297 print_normal (cd
, info
, fields
->f_cond
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
299 case FRV_OPERAND_D12
:
300 print_normal (cd
, info
, fields
->f_d12
, 0|(1<<CGEN_OPERAND_SIGNED
), pc
, length
);
302 case FRV_OPERAND_DEBUG
:
303 print_normal (cd
, info
, fields
->f_debug
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
305 case FRV_OPERAND_EIR
:
306 print_normal (cd
, info
, fields
->f_eir
, 0, pc
, length
);
308 case FRV_OPERAND_HINT
:
309 print_normal (cd
, info
, fields
->f_hint
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
311 case FRV_OPERAND_HINT_NOT_TAKEN
:
312 print_keyword (cd
, info
, & frv_cgen_opval_h_hint_not_taken
, fields
->f_hint
, 0);
314 case FRV_OPERAND_HINT_TAKEN
:
315 print_keyword (cd
, info
, & frv_cgen_opval_h_hint_taken
, fields
->f_hint
, 0);
317 case FRV_OPERAND_LABEL16
:
318 print_address (cd
, info
, fields
->f_label16
, 0|(1<<CGEN_OPERAND_PCREL_ADDR
), pc
, length
);
320 case FRV_OPERAND_LABEL24
:
321 print_address (cd
, info
, fields
->f_label24
, 0|(1<<CGEN_OPERAND_PCREL_ADDR
)|(1<<CGEN_OPERAND_VIRTUAL
), pc
, length
);
323 case FRV_OPERAND_LOCK
:
324 print_normal (cd
, info
, fields
->f_lock
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
326 case FRV_OPERAND_PACK
:
327 print_keyword (cd
, info
, & frv_cgen_opval_h_pack
, fields
->f_pack
, 0);
329 case FRV_OPERAND_S10
:
330 print_normal (cd
, info
, fields
->f_s10
, 0|(1<<CGEN_OPERAND_SIGNED
)|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
332 case FRV_OPERAND_S12
:
333 print_normal (cd
, info
, fields
->f_d12
, 0|(1<<CGEN_OPERAND_SIGNED
)|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
335 case FRV_OPERAND_S16
:
336 print_normal (cd
, info
, fields
->f_s16
, 0|(1<<CGEN_OPERAND_SIGNED
)|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
338 case FRV_OPERAND_S5
:
339 print_normal (cd
, info
, fields
->f_s5
, 0|(1<<CGEN_OPERAND_SIGNED
)|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
341 case FRV_OPERAND_S6
:
342 print_normal (cd
, info
, fields
->f_s6
, 0|(1<<CGEN_OPERAND_SIGNED
)|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
344 case FRV_OPERAND_S6_1
:
345 print_normal (cd
, info
, fields
->f_s6_1
, 0|(1<<CGEN_OPERAND_SIGNED
)|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
347 case FRV_OPERAND_SLO16
:
348 print_lo (cd
, info
, fields
->f_s16
, 0|(1<<CGEN_OPERAND_SIGNED
), pc
, length
);
350 case FRV_OPERAND_SPR
:
351 print_spr (cd
, info
, & frv_cgen_opval_spr_names
, fields
->f_spr
, 0|(1<<CGEN_OPERAND_VIRTUAL
));
353 case FRV_OPERAND_U12
:
354 print_normal (cd
, info
, fields
->f_u12
, 0|(1<<CGEN_OPERAND_SIGNED
)|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_VIRTUAL
), pc
, length
);
356 case FRV_OPERAND_U16
:
357 print_normal (cd
, info
, fields
->f_u16
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
359 case FRV_OPERAND_U6
:
360 print_normal (cd
, info
, fields
->f_u6
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
), pc
, length
);
362 case FRV_OPERAND_UHI16
:
363 print_hi (cd
, info
, fields
->f_u16
, 0, pc
, length
);
365 case FRV_OPERAND_ULO16
:
366 print_lo (cd
, info
, fields
->f_u16
, 0, pc
, length
);
370 /* xgettext:c-format */
371 fprintf (stderr
, _("Unrecognized field %d while printing insn.\n"),
377 cgen_print_fn
* const frv_cgen_print_handlers
[] =
384 frv_cgen_init_dis (cd
)
387 frv_cgen_init_opcode_table (cd
);
388 frv_cgen_init_ibld_table (cd
);
389 cd
->print_handlers
= & frv_cgen_print_handlers
[0];
390 cd
->print_operand
= frv_cgen_print_operand
;
394 /* Default print handler. */
397 print_normal (cd
, dis_info
, value
, attrs
, pc
, length
)
398 CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
;
402 bfd_vma pc ATTRIBUTE_UNUSED
;
403 int length ATTRIBUTE_UNUSED
;
405 disassemble_info
*info
= (disassemble_info
*) dis_info
;
407 #ifdef CGEN_PRINT_NORMAL
408 CGEN_PRINT_NORMAL (cd
, info
, value
, attrs
, pc
, length
);
411 /* Print the operand as directed by the attributes. */
412 if (CGEN_BOOL_ATTR (attrs
, CGEN_OPERAND_SEM_ONLY
))
413 ; /* nothing to do */
414 else if (CGEN_BOOL_ATTR (attrs
, CGEN_OPERAND_SIGNED
))
415 (*info
->fprintf_func
) (info
->stream
, "%ld", value
);
417 (*info
->fprintf_func
) (info
->stream
, "0x%lx", value
);
420 /* Default address handler. */
423 print_address (cd
, dis_info
, value
, attrs
, pc
, length
)
424 CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
;
428 bfd_vma pc ATTRIBUTE_UNUSED
;
429 int length ATTRIBUTE_UNUSED
;
431 disassemble_info
*info
= (disassemble_info
*) dis_info
;
433 #ifdef CGEN_PRINT_ADDRESS
434 CGEN_PRINT_ADDRESS (cd
, info
, value
, attrs
, pc
, length
);
437 /* Print the operand as directed by the attributes. */
438 if (CGEN_BOOL_ATTR (attrs
, CGEN_OPERAND_SEM_ONLY
))
439 ; /* nothing to do */
440 else if (CGEN_BOOL_ATTR (attrs
, CGEN_OPERAND_PCREL_ADDR
))
441 (*info
->print_address_func
) (value
, info
);
442 else if (CGEN_BOOL_ATTR (attrs
, CGEN_OPERAND_ABS_ADDR
))
443 (*info
->print_address_func
) (value
, info
);
444 else if (CGEN_BOOL_ATTR (attrs
, CGEN_OPERAND_SIGNED
))
445 (*info
->fprintf_func
) (info
->stream
, "%ld", (long) value
);
447 (*info
->fprintf_func
) (info
->stream
, "0x%lx", (long) value
);
450 /* Keyword print handler. */
453 print_keyword (cd
, dis_info
, keyword_table
, value
, attrs
)
454 CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
;
456 CGEN_KEYWORD
*keyword_table
;
458 unsigned int attrs ATTRIBUTE_UNUSED
;
460 disassemble_info
*info
= (disassemble_info
*) dis_info
;
461 const CGEN_KEYWORD_ENTRY
*ke
;
463 ke
= cgen_keyword_lookup_value (keyword_table
, value
);
465 (*info
->fprintf_func
) (info
->stream
, "%s", ke
->name
);
467 (*info
->fprintf_func
) (info
->stream
, "???");
470 /* Default insn printer.
472 DIS_INFO is defined as `PTR' so the disassembler needn't know anything
473 about disassemble_info. */
476 print_insn_normal (cd
, dis_info
, insn
, fields
, pc
, length
)
479 const CGEN_INSN
*insn
;
484 const CGEN_SYNTAX
*syntax
= CGEN_INSN_SYNTAX (insn
);
485 disassemble_info
*info
= (disassemble_info
*) dis_info
;
486 const CGEN_SYNTAX_CHAR_TYPE
*syn
;
488 CGEN_INIT_PRINT (cd
);
490 for (syn
= CGEN_SYNTAX_STRING (syntax
); *syn
; ++syn
)
492 if (CGEN_SYNTAX_MNEMONIC_P (*syn
))
494 (*info
->fprintf_func
) (info
->stream
, "%s", CGEN_INSN_MNEMONIC (insn
));
497 if (CGEN_SYNTAX_CHAR_P (*syn
))
499 (*info
->fprintf_func
) (info
->stream
, "%c", CGEN_SYNTAX_CHAR (*syn
));
503 /* We have an operand. */
504 frv_cgen_print_operand (cd
, CGEN_SYNTAX_FIELD (*syn
), info
,
505 fields
, CGEN_INSN_ATTRS (insn
), pc
, length
);
509 /* Subroutine of print_insn. Reads an insn into the given buffers and updates
511 Returns 0 if all is well, non-zero otherwise. */
514 read_insn (cd
, pc
, info
, buf
, buflen
, ex_info
, insn_value
)
515 CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
;
517 disassemble_info
*info
;
520 CGEN_EXTRACT_INFO
*ex_info
;
521 unsigned long *insn_value
;
523 int status
= (*info
->read_memory_func
) (pc
, buf
, buflen
, info
);
526 (*info
->memory_error_func
) (status
, pc
, info
);
530 ex_info
->dis_info
= info
;
531 ex_info
->valid
= (1 << buflen
) - 1;
532 ex_info
->insn_bytes
= buf
;
534 *insn_value
= bfd_get_bits (buf
, buflen
* 8, info
->endian
== BFD_ENDIAN_BIG
);
538 /* Utility to print an insn.
539 BUF is the base part of the insn, target byte order, BUFLEN bytes long.
540 The result is the size of the insn in bytes or zero for an unknown insn
541 or -1 if an error occurs fetching data (memory_error_func will have
545 print_insn (cd
, pc
, info
, buf
, buflen
)
548 disassemble_info
*info
;
552 CGEN_INSN_INT insn_value
;
553 const CGEN_INSN_LIST
*insn_list
;
554 CGEN_EXTRACT_INFO ex_info
;
557 /* Extract base part of instruction, just in case CGEN_DIS_* uses it. */
558 basesize
= cd
->base_insn_bitsize
< buflen
* 8 ?
559 cd
->base_insn_bitsize
: buflen
* 8;
560 insn_value
= cgen_get_insn_value (cd
, buf
, basesize
);
563 /* Fill in ex_info fields like read_insn would. Don't actually call
564 read_insn, since the incoming buffer is already read (and possibly
565 modified a la m32r). */
566 ex_info
.valid
= (1 << buflen
) - 1;
567 ex_info
.dis_info
= info
;
568 ex_info
.insn_bytes
= buf
;
570 /* The instructions are stored in hash lists.
571 Pick the first one and keep trying until we find the right one. */
573 insn_list
= CGEN_DIS_LOOKUP_INSN (cd
, buf
, insn_value
);
574 while (insn_list
!= NULL
)
576 const CGEN_INSN
*insn
= insn_list
->insn
;
579 unsigned long insn_value_cropped
;
581 #ifdef CGEN_VALIDATE_INSN_SUPPORTED
582 /* Not needed as insn shouldn't be in hash lists if not supported. */
583 /* Supported by this cpu? */
584 if (! frv_cgen_insn_supported (cd
, insn
))
586 insn_list
= CGEN_DIS_NEXT_INSN (insn_list
);
591 /* Basic bit mask must be correct. */
592 /* ??? May wish to allow target to defer this check until the extract
595 /* Base size may exceed this instruction's size. Extract the
596 relevant part from the buffer. */
597 if ((unsigned) (CGEN_INSN_BITSIZE (insn
) / 8) < buflen
&&
598 (unsigned) (CGEN_INSN_BITSIZE (insn
) / 8) <= sizeof (unsigned long))
599 insn_value_cropped
= bfd_get_bits (buf
, CGEN_INSN_BITSIZE (insn
),
600 info
->endian
== BFD_ENDIAN_BIG
);
602 insn_value_cropped
= insn_value
;
604 if ((insn_value_cropped
& CGEN_INSN_BASE_MASK (insn
))
605 == CGEN_INSN_BASE_VALUE (insn
))
607 /* Printing is handled in two passes. The first pass parses the
608 machine insn and extracts the fields. The second pass prints
611 /* Make sure the entire insn is loaded into insn_value, if it
613 if (((unsigned) CGEN_INSN_BITSIZE (insn
) > cd
->base_insn_bitsize
) &&
614 (unsigned) (CGEN_INSN_BITSIZE (insn
) / 8) <= sizeof (unsigned long))
616 unsigned long full_insn_value
;
617 int rc
= read_insn (cd
, pc
, info
, buf
,
618 CGEN_INSN_BITSIZE (insn
) / 8,
619 & ex_info
, & full_insn_value
);
622 length
= CGEN_EXTRACT_FN (cd
, insn
)
623 (cd
, insn
, &ex_info
, full_insn_value
, &fields
, pc
);
626 length
= CGEN_EXTRACT_FN (cd
, insn
)
627 (cd
, insn
, &ex_info
, insn_value_cropped
, &fields
, pc
);
629 /* length < 0 -> error */
634 CGEN_PRINT_FN (cd
, insn
) (cd
, info
, insn
, &fields
, pc
, length
);
635 /* length is in bits, result is in bytes */
640 insn_list
= CGEN_DIS_NEXT_INSN (insn_list
);
646 /* Default value for CGEN_PRINT_INSN.
647 The result is the size of the insn in bytes or zero for an unknown insn
648 or -1 if an error occured fetching bytes. */
650 #ifndef CGEN_PRINT_INSN
651 #define CGEN_PRINT_INSN default_print_insn
655 default_print_insn (cd
, pc
, info
)
658 disassemble_info
*info
;
660 char buf
[CGEN_MAX_INSN_SIZE
];
664 /* Attempt to read the base part of the insn. */
665 buflen
= cd
->base_insn_bitsize
/ 8;
666 status
= (*info
->read_memory_func
) (pc
, buf
, buflen
, info
);
668 /* Try again with the minimum part, if min < base. */
669 if (status
!= 0 && (cd
->min_insn_bitsize
< cd
->base_insn_bitsize
))
671 buflen
= cd
->min_insn_bitsize
/ 8;
672 status
= (*info
->read_memory_func
) (pc
, buf
, buflen
, info
);
677 (*info
->memory_error_func
) (status
, pc
, info
);
681 return print_insn (cd
, pc
, info
, buf
, buflen
);
685 Print one instruction from PC on INFO->STREAM.
686 Return the size of the instruction (in bytes). */
688 typedef struct cpu_desc_list
{
689 struct cpu_desc_list
*next
;
697 print_insn_frv (pc
, info
)
699 disassemble_info
*info
;
701 static cpu_desc_list
*cd_list
= 0;
702 cpu_desc_list
*cl
= 0;
703 static CGEN_CPU_DESC cd
= 0;
705 static int prev_mach
;
706 static int prev_endian
;
709 int endian
= (info
->endian
== BFD_ENDIAN_BIG
711 : CGEN_ENDIAN_LITTLE
);
712 enum bfd_architecture arch
;
714 /* ??? gdb will set mach but leave the architecture as "unknown" */
715 #ifndef CGEN_BFD_ARCH
716 #define CGEN_BFD_ARCH bfd_arch_frv
719 if (arch
== bfd_arch_unknown
)
720 arch
= CGEN_BFD_ARCH
;
722 /* There's no standard way to compute the machine or isa number
723 so we leave it to the target. */
724 #ifdef CGEN_COMPUTE_MACH
725 mach
= CGEN_COMPUTE_MACH (info
);
730 #ifdef CGEN_COMPUTE_ISA
731 isa
= CGEN_COMPUTE_ISA (info
);
733 isa
= info
->insn_sets
;
736 /* If we've switched cpu's, try to find a handle we've used before */
740 || endian
!= prev_endian
))
743 for (cl
= cd_list
; cl
; cl
= cl
->next
)
745 if (cl
->isa
== isa
&&
747 cl
->endian
== endian
)
755 /* If we haven't initialized yet, initialize the opcode table. */
758 const bfd_arch_info_type
*arch_type
= bfd_lookup_arch (arch
, mach
);
759 const char *mach_name
;
763 mach_name
= arch_type
->printable_name
;
767 prev_endian
= endian
;
768 cd
= frv_cgen_cpu_open (CGEN_CPU_OPEN_ISAS
, prev_isa
,
769 CGEN_CPU_OPEN_BFDMACH
, mach_name
,
770 CGEN_CPU_OPEN_ENDIAN
, prev_endian
,
775 /* save this away for future reference */
776 cl
= xmalloc (sizeof (struct cpu_desc_list
));
784 frv_cgen_init_dis (cd
);
787 /* We try to have as much common code as possible.
788 But at this point some targets need to take over. */
789 /* ??? Some targets may need a hook elsewhere. Try to avoid this,
790 but if not possible try to move this hook elsewhere rather than
792 length
= CGEN_PRINT_INSN (cd
, pc
, info
);
798 (*info
->fprintf_func
) (info
->stream
, UNKNOWN_INSN_MSG
);
799 return cd
->default_insn_bitsize
/ 8;