1 /* Disassembler interface for targets using CGEN. -*- C -*-
2 CGEN: Cpu tools GENerator
4 THIS FILE IS USED TO GENERATE fr30-dis.c.
6 Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
8 This file is part of the GNU Binutils and GDB, the GNU debugger.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software Foundation, Inc.,
22 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
35 #define INLINE __inline__
40 /* Default text to print if an instruction isn't recognized. */
41 #define UNKNOWN_INSN_MSG _("*unknown*")
43 /* Used by the ifield rtx function. */
44 #define FLD(f) (fields->f)
46 static int extract_normal
47 PARAMS ((CGEN_OPCODE_DESC
, CGEN_EXTRACT_INFO
*, CGEN_INSN_INT
,
48 unsigned int, unsigned int, unsigned int, unsigned int,
49 unsigned int, unsigned int, bfd_vma
, long *));
50 static void print_normal
51 PARAMS ((CGEN_OPCODE_DESC
, PTR
, long, unsigned int, bfd_vma
, int));
52 static void print_address
53 PARAMS ((CGEN_OPCODE_DESC
, PTR
, bfd_vma
, unsigned int, bfd_vma
, int));
54 static void print_keyword
55 PARAMS ((CGEN_OPCODE_DESC
, PTR
, CGEN_KEYWORD
*, long, unsigned int));
56 static int extract_insn_normal
57 PARAMS ((CGEN_OPCODE_DESC
, const CGEN_INSN
*, CGEN_EXTRACT_INFO
*,
58 CGEN_INSN_INT
, CGEN_FIELDS
*, bfd_vma
));
59 static void print_insn_normal
60 PARAMS ((CGEN_OPCODE_DESC
, PTR
, const CGEN_INSN
*, CGEN_FIELDS
*,
62 static int print_insn
PARAMS ((CGEN_OPCODE_DESC
, bfd_vma
,
63 disassemble_info
*, char *, int));
64 static int default_print_insn
65 PARAMS ((CGEN_OPCODE_DESC
, bfd_vma
, disassemble_info
*));
67 /* -- disassembler routines inserted here */
71 print_register_list (dis_info
, value
, offset
)
76 disassemble_info
*info
= dis_info
;
81 (*info
->fprintf_func
) (info
->stream
, "r%i", index
+ offset
);
83 for (index
= 1; index
<= 7; ++index
)
87 (*info
->fprintf_func
) (info
->stream
, ",r%i", index
+ offset
);
92 print_hi_register_list (od
, dis_info
, value
, attrs
, pc
, length
)
100 print_register_list (dis_info
, value
, 8);
104 print_low_register_list (od
, dis_info
, value
, attrs
, pc
, length
)
112 print_register_list (dis_info
, value
, 0);
116 print_m4 (od
, dis_info
, value
, attrs
, pc
, length
)
124 disassemble_info
*info
= (disassemble_info
*) dis_info
;
125 (*info
->fprintf_func
) (info
->stream
, "%ld", value
);
129 /* Main entry point for operand extraction.
131 This function is basically just a big switch statement. Earlier versions
132 used tables to look up the function to use, but
133 - if the table contains both assembler and disassembler functions then
134 the disassembler contains much of the assembler and vice-versa,
135 - there's a lot of inlining possibilities as things grow,
136 - using a switch statement avoids the function call overhead.
138 This function could be moved into `print_insn_normal', but keeping it
139 separate makes clear the interface between `print_insn_normal' and each of
144 fr30_cgen_extract_operand (od
, opindex
, ex_info
, insn_value
, fields
, pc
)
147 CGEN_EXTRACT_INFO
*ex_info
;
148 CGEN_INSN_INT insn_value
;
149 CGEN_FIELDS
* fields
;
153 unsigned int total_length
= CGEN_FIELDS_BITSIZE (fields
);
157 case FR30_OPERAND_RI
:
158 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_UNSIGNED
), 0, 12, 4, 16, total_length
, pc
, & fields
->f_Ri
);
160 case FR30_OPERAND_RJ
:
161 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_UNSIGNED
), 0, 8, 4, 16, total_length
, pc
, & fields
->f_Rj
);
163 case FR30_OPERAND_RIC
:
164 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_UNSIGNED
), 16, 12, 4, 16, total_length
, pc
, & fields
->f_Ric
);
166 case FR30_OPERAND_RJC
:
167 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_UNSIGNED
), 16, 8, 4, 16, total_length
, pc
, & fields
->f_Rjc
);
169 case FR30_OPERAND_CRI
:
170 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_UNSIGNED
), 16, 12, 4, 16, total_length
, pc
, & fields
->f_CRi
);
172 case FR30_OPERAND_CRJ
:
173 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_UNSIGNED
), 16, 8, 4, 16, total_length
, pc
, & fields
->f_CRj
);
175 case FR30_OPERAND_RS1
:
176 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_UNSIGNED
), 0, 8, 4, 16, total_length
, pc
, & fields
->f_Rs1
);
178 case FR30_OPERAND_RS2
:
179 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_UNSIGNED
), 0, 12, 4, 16, total_length
, pc
, & fields
->f_Rs2
);
181 case FR30_OPERAND_R13
:
182 length
= extract_normal (od
, ex_info
, insn_value
, 0, 0, 0, 0, 0, total_length
, pc
, & fields
->f_nil
);
184 case FR30_OPERAND_R14
:
185 length
= extract_normal (od
, ex_info
, insn_value
, 0, 0, 0, 0, 0, total_length
, pc
, & fields
->f_nil
);
187 case FR30_OPERAND_R15
:
188 length
= extract_normal (od
, ex_info
, insn_value
, 0, 0, 0, 0, 0, total_length
, pc
, & fields
->f_nil
);
190 case FR30_OPERAND_PS
:
191 length
= extract_normal (od
, ex_info
, insn_value
, 0, 0, 0, 0, 0, total_length
, pc
, & fields
->f_nil
);
193 case FR30_OPERAND_U4
:
194 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_UNSIGNED
), 0, 8, 4, 16, total_length
, pc
, & fields
->f_u4
);
196 case FR30_OPERAND_U4C
:
197 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_UNSIGNED
), 0, 12, 4, 16, total_length
, pc
, & fields
->f_u4c
);
199 case FR30_OPERAND_U8
:
200 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_UNSIGNED
), 0, 8, 8, 16, total_length
, pc
, & fields
->f_u8
);
202 case FR30_OPERAND_I8
:
203 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_UNSIGNED
), 0, 4, 8, 16, total_length
, pc
, & fields
->f_i8
);
205 case FR30_OPERAND_UDISP6
:
208 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_UNSIGNED
), 0, 8, 4, 16, total_length
, pc
, & value
);
209 value
= ((value
) << (2));
210 fields
->f_udisp6
= value
;
213 case FR30_OPERAND_DISP8
:
214 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_SIGNED
), 0, 4, 8, 16, total_length
, pc
, & fields
->f_disp8
);
216 case FR30_OPERAND_DISP9
:
219 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_SIGNED
), 0, 4, 8, 16, total_length
, pc
, & value
);
220 value
= ((value
) << (1));
221 fields
->f_disp9
= value
;
224 case FR30_OPERAND_DISP10
:
227 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_SIGNED
), 0, 4, 8, 16, total_length
, pc
, & value
);
228 value
= ((value
) << (2));
229 fields
->f_disp10
= value
;
232 case FR30_OPERAND_S10
:
235 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_SIGNED
), 0, 8, 8, 16, total_length
, pc
, & value
);
236 value
= ((value
) << (2));
237 fields
->f_s10
= value
;
240 case FR30_OPERAND_U10
:
243 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_UNSIGNED
), 0, 8, 8, 16, total_length
, pc
, & value
);
244 value
= ((value
) << (2));
245 fields
->f_u10
= value
;
248 case FR30_OPERAND_I32
:
249 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_SIGN_OPT
)|(1<<CGEN_OPERAND_UNSIGNED
), 16, 0, 32, 32, total_length
, pc
, & fields
->f_i32
);
251 case FR30_OPERAND_M4
:
254 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_UNSIGNED
), 0, 8, 4, 16, total_length
, pc
, & value
);
255 value
= ((value
) | (((-1) << (4))));
256 fields
->f_m4
= value
;
259 case FR30_OPERAND_I20
:
261 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_UNSIGNED
)|(1<<CGEN_OPERAND_VIRTUAL
), 0, 8, 4, 16, total_length
, pc
, & fields
->f_i20_4
);
262 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_UNSIGNED
)|(1<<CGEN_OPERAND_VIRTUAL
), 16, 0, 16, 16, total_length
, pc
, & fields
->f_i20_16
);
264 FLD (f_i20
) = ((((FLD (f_i20_4
)) << (16))) | (FLD (f_i20_16
)));
268 case FR30_OPERAND_DIR8
:
269 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_UNSIGNED
), 0, 8, 8, 16, total_length
, pc
, & fields
->f_dir8
);
271 case FR30_OPERAND_DIR9
:
274 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_UNSIGNED
), 0, 8, 8, 16, total_length
, pc
, & value
);
275 value
= ((value
) << (1));
276 fields
->f_dir9
= value
;
279 case FR30_OPERAND_DIR10
:
282 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_UNSIGNED
), 0, 8, 8, 16, total_length
, pc
, & value
);
283 value
= ((value
) << (2));
284 fields
->f_dir10
= value
;
287 case FR30_OPERAND_LABEL9
:
290 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_PCREL_ADDR
)|(1<<CGEN_OPERAND_SIGNED
), 0, 8, 8, 16, total_length
, pc
, & value
);
291 value
= ((((value
) << (1))) + (((pc
) + (2))));
292 fields
->f_rel9
= value
;
295 case FR30_OPERAND_LABEL12
:
298 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_PCREL_ADDR
)|(1<<CGEN_OPERAND_SIGNED
), 0, 5, 11, 16, total_length
, pc
, & value
);
299 value
= ((((value
) << (1))) + (((pc
) + (2))));
300 fields
->f_rel12
= value
;
303 case FR30_OPERAND_REGLIST_LOW
:
304 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_UNSIGNED
), 0, 8, 8, 16, total_length
, pc
, & fields
->f_reglist_low
);
306 case FR30_OPERAND_REGLIST_HI
:
307 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_UNSIGNED
), 0, 8, 8, 16, total_length
, pc
, & fields
->f_reglist_hi
);
309 case FR30_OPERAND_CC
:
310 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_UNSIGNED
), 0, 4, 4, 16, total_length
, pc
, & fields
->f_cc
);
312 case FR30_OPERAND_CCC
:
313 length
= extract_normal (od
, ex_info
, insn_value
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_UNSIGNED
), 16, 0, 8, 16, total_length
, pc
, & fields
->f_ccc
);
317 /* xgettext:c-format */
318 fprintf (stderr
, _("Unrecognized field %d while decoding insn.\n"),
326 /* Main entry point for printing operands.
328 This function is basically just a big switch statement. Earlier versions
329 used tables to look up the function to use, but
330 - if the table contains both assembler and disassembler functions then
331 the disassembler contains much of the assembler and vice-versa,
332 - there's a lot of inlining possibilities as things grow,
333 - using a switch statement avoids the function call overhead.
335 This function could be moved into `print_insn_normal', but keeping it
336 separate makes clear the interface between `print_insn_normal' and each of
341 fr30_cgen_print_operand (od
, opindex
, info
, fields
, attrs
, pc
, length
)
344 disassemble_info
* info
;
345 CGEN_FIELDS
* fields
;
352 case FR30_OPERAND_RI
:
353 print_keyword (od
, info
, & fr30_cgen_opval_h_gr
, fields
->f_Ri
, 0|(1<<CGEN_OPERAND_UNSIGNED
));
355 case FR30_OPERAND_RJ
:
356 print_keyword (od
, info
, & fr30_cgen_opval_h_gr
, fields
->f_Rj
, 0|(1<<CGEN_OPERAND_UNSIGNED
));
358 case FR30_OPERAND_RIC
:
359 print_keyword (od
, info
, & fr30_cgen_opval_h_gr
, fields
->f_Ric
, 0|(1<<CGEN_OPERAND_UNSIGNED
));
361 case FR30_OPERAND_RJC
:
362 print_keyword (od
, info
, & fr30_cgen_opval_h_gr
, fields
->f_Rjc
, 0|(1<<CGEN_OPERAND_UNSIGNED
));
364 case FR30_OPERAND_CRI
:
365 print_keyword (od
, info
, & fr30_cgen_opval_h_cr
, fields
->f_CRi
, 0|(1<<CGEN_OPERAND_UNSIGNED
));
367 case FR30_OPERAND_CRJ
:
368 print_keyword (od
, info
, & fr30_cgen_opval_h_cr
, fields
->f_CRj
, 0|(1<<CGEN_OPERAND_UNSIGNED
));
370 case FR30_OPERAND_RS1
:
371 print_keyword (od
, info
, & fr30_cgen_opval_h_dr
, fields
->f_Rs1
, 0|(1<<CGEN_OPERAND_UNSIGNED
));
373 case FR30_OPERAND_RS2
:
374 print_keyword (od
, info
, & fr30_cgen_opval_h_dr
, fields
->f_Rs2
, 0|(1<<CGEN_OPERAND_UNSIGNED
));
376 case FR30_OPERAND_R13
:
377 print_keyword (od
, info
, & fr30_cgen_opval_h_r13
, fields
->f_nil
, 0);
379 case FR30_OPERAND_R14
:
380 print_keyword (od
, info
, & fr30_cgen_opval_h_r14
, fields
->f_nil
, 0);
382 case FR30_OPERAND_R15
:
383 print_keyword (od
, info
, & fr30_cgen_opval_h_r15
, fields
->f_nil
, 0);
385 case FR30_OPERAND_PS
:
386 print_keyword (od
, info
, & fr30_cgen_opval_h_ps
, fields
->f_nil
, 0);
388 case FR30_OPERAND_U4
:
389 print_normal (od
, info
, fields
->f_u4
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_UNSIGNED
), pc
, length
);
391 case FR30_OPERAND_U4C
:
392 print_normal (od
, info
, fields
->f_u4c
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_UNSIGNED
), pc
, length
);
394 case FR30_OPERAND_U8
:
395 print_normal (od
, info
, fields
->f_u8
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_UNSIGNED
), pc
, length
);
397 case FR30_OPERAND_I8
:
398 print_normal (od
, info
, fields
->f_i8
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_UNSIGNED
), pc
, length
);
400 case FR30_OPERAND_UDISP6
:
401 print_normal (od
, info
, fields
->f_udisp6
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_UNSIGNED
), pc
, length
);
403 case FR30_OPERAND_DISP8
:
404 print_normal (od
, info
, fields
->f_disp8
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_SIGNED
), pc
, length
);
406 case FR30_OPERAND_DISP9
:
407 print_normal (od
, info
, fields
->f_disp9
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_SIGNED
), pc
, length
);
409 case FR30_OPERAND_DISP10
:
410 print_normal (od
, info
, fields
->f_disp10
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_SIGNED
), pc
, length
);
412 case FR30_OPERAND_S10
:
413 print_normal (od
, info
, fields
->f_s10
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_SIGNED
), pc
, length
);
415 case FR30_OPERAND_U10
:
416 print_normal (od
, info
, fields
->f_u10
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_UNSIGNED
), pc
, length
);
418 case FR30_OPERAND_I32
:
419 print_normal (od
, info
, fields
->f_i32
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_SIGN_OPT
)|(1<<CGEN_OPERAND_UNSIGNED
), pc
, length
);
421 case FR30_OPERAND_M4
:
422 print_m4 (od
, info
, fields
->f_m4
, 0|(1<<CGEN_OPERAND_UNSIGNED
), pc
, length
);
424 case FR30_OPERAND_I20
:
425 print_normal (od
, info
, fields
->f_i20
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_UNSIGNED
)|(1<<CGEN_OPERAND_VIRTUAL
), pc
, length
);
427 case FR30_OPERAND_DIR8
:
428 print_normal (od
, info
, fields
->f_dir8
, 0|(1<<CGEN_OPERAND_UNSIGNED
), pc
, length
);
430 case FR30_OPERAND_DIR9
:
431 print_normal (od
, info
, fields
->f_dir9
, 0|(1<<CGEN_OPERAND_UNSIGNED
), pc
, length
);
433 case FR30_OPERAND_DIR10
:
434 print_normal (od
, info
, fields
->f_dir10
, 0|(1<<CGEN_OPERAND_UNSIGNED
), pc
, length
);
436 case FR30_OPERAND_LABEL9
:
437 print_address (od
, info
, fields
->f_rel9
, 0|(1<<CGEN_OPERAND_PCREL_ADDR
)|(1<<CGEN_OPERAND_SIGNED
), pc
, length
);
439 case FR30_OPERAND_LABEL12
:
440 print_address (od
, info
, fields
->f_rel12
, 0|(1<<CGEN_OPERAND_PCREL_ADDR
)|(1<<CGEN_OPERAND_SIGNED
), pc
, length
);
442 case FR30_OPERAND_REGLIST_LOW
:
443 print_low_register_list (od
, info
, fields
->f_reglist_low
, 0|(1<<CGEN_OPERAND_UNSIGNED
), pc
, length
);
445 case FR30_OPERAND_REGLIST_HI
:
446 print_hi_register_list (od
, info
, fields
->f_reglist_hi
, 0|(1<<CGEN_OPERAND_UNSIGNED
), pc
, length
);
448 case FR30_OPERAND_CC
:
449 print_normal (od
, info
, fields
->f_cc
, 0|(1<<CGEN_OPERAND_UNSIGNED
), pc
, length
);
451 case FR30_OPERAND_CCC
:
452 print_normal (od
, info
, fields
->f_ccc
, 0|(1<<CGEN_OPERAND_HASH_PREFIX
)|(1<<CGEN_OPERAND_UNSIGNED
), pc
, length
);
456 /* xgettext:c-format */
457 fprintf (stderr
, _("Unrecognized field %d while printing insn.\n"),
463 cgen_extract_fn
* const fr30_cgen_extract_handlers
[] =
469 cgen_print_fn
* const fr30_cgen_print_handlers
[] =
477 fr30_cgen_init_dis (od
)
483 #if ! CGEN_INT_INSN_P
485 /* Subroutine of extract_normal.
486 Ensure sufficient bytes are cached in EX_INFO.
487 OFFSET is the offset in bytes from the start of the insn of the value.
488 BYTES is the length of the needed value.
489 Returns 1 for success, 0 for failure. */
492 fill_cache (od
, ex_info
, offset
, bytes
, pc
)
494 CGEN_EXTRACT_INFO
*ex_info
;
498 /* It's doubtful that the middle part has already been fetched so
499 we don't optimize that case. kiss. */
501 disassemble_info
*info
= (disassemble_info
*) ex_info
->dis_info
;
503 /* First do a quick check. */
504 mask
= (1 << bytes
) - 1;
505 if (((ex_info
->valid
>> offset
) & mask
) == mask
)
508 /* Search for the first byte we need to read. */
509 for (mask
= 1 << offset
; bytes
> 0; --bytes
, ++offset
, mask
<<= 1)
510 if (! (mask
& ex_info
->valid
))
518 status
= (*info
->read_memory_func
)
519 (pc
, ex_info
->insn_bytes
+ offset
, bytes
, info
);
523 (*info
->memory_error_func
) (status
, pc
, info
);
527 ex_info
->valid
|= ((1 << bytes
) - 1) << offset
;
533 /* Subroutine of extract_normal. */
536 extract_1 (od
, ex_info
, start
, length
, word_length
, bufp
, pc
)
538 CGEN_EXTRACT_INFO
*ex_info
;
539 int start
,length
,word_length
;
543 unsigned long x
,mask
;
545 int big_p
= CGEN_OPCODE_INSN_ENDIAN (od
) == CGEN_ENDIAN_BIG
;
554 x
= bfd_getb16 (bufp
);
556 x
= bfd_getl16 (bufp
);
559 /* ??? This may need reworking as these cases don't necessarily
560 want the first byte and the last two bytes handled like this. */
562 x
= (bufp
[0] << 16) | bfd_getb16 (bufp
+ 1);
564 x
= bfd_getl16 (bufp
) | (bufp
[2] << 16);
568 x
= bfd_getb32 (bufp
);
570 x
= bfd_getl32 (bufp
);
576 /* Written this way to avoid undefined behaviour. */
577 mask
= (((1L << (length
- 1)) - 1) << 1) | 1;
578 if (CGEN_INSN_LSB0_P
)
579 shift
= (start
+ 1) - length
;
581 shift
= (word_length
- (start
+ length
));
582 return (x
>> shift
) & mask
;
585 #endif /* ! CGEN_INT_INSN_P */
587 /* Default extraction routine.
589 INSN_VALUE is the first CGEN_BASE_INSN_SIZE bits of the insn in host order,
590 or sometimes less for cases like the m32r where the base insn size is 32
591 but some insns are 16 bits.
592 ATTRS is a mask of the boolean attributes. We only need `UNSIGNED',
593 but for generality we take a bitmask of all of them.
594 WORD_OFFSET is the offset in bits from the start of the insn of the value.
595 WORD_LENGTH is the length of the word in bits in which the value resides.
596 START is the starting bit number in the word, architecture origin.
597 LENGTH is the length of VALUE in bits.
598 TOTAL_LENGTH is the total length of the insn in bits.
600 Returns 1 for success, 0 for failure. */
602 /* ??? The return code isn't properly used. wip. */
604 /* ??? This doesn't handle bfd_vma's. Create another function when
608 extract_normal (od
, ex_info
, insn_value
, attrs
, word_offset
, start
, length
,
609 word_length
, total_length
, pc
, valuep
)
611 CGEN_EXTRACT_INFO
*ex_info
;
612 CGEN_INSN_INT insn_value
;
614 unsigned int word_offset
, start
, length
, word_length
, total_length
;
620 /* If LENGTH is zero, this operand doesn't contribute to the value
621 so give it a standard value of zero. */
632 if (word_length
> 32)
635 /* For architectures with insns smaller than the insn-base-bitsize,
636 word_length may be too big. */
637 #if CGEN_MIN_INSN_BITSIZE < CGEN_BASE_INSN_BITSIZE
639 && word_length
> total_length
)
640 word_length
= total_length
;
643 /* Does the value reside in INSN_VALUE? */
645 if (word_offset
== 0)
647 /* Written this way to avoid undefined behaviour. */
648 CGEN_INSN_INT mask
= (((1L << (length
- 1)) - 1) << 1) | 1;
650 if (CGEN_INSN_LSB0_P
)
651 value
= insn_value
>> ((start
+ 1) - length
);
653 value
= insn_value
>> (word_length
- (start
+ length
));
656 if (! (attrs
& CGEN_ATTR_MASK (CGEN_OPERAND_UNSIGNED
))
657 && (value
& (1L << (length
- 1))))
661 #if ! CGEN_INT_INSN_P
665 unsigned char *bufp
= ex_info
->insn_bytes
+ word_offset
/ 8;
667 if (word_length
> 32)
670 if (fill_cache (od
, ex_info
, word_offset
/ 8, word_length
/ 8, pc
) == 0)
673 value
= extract_1 (od
, ex_info
, start
, length
, word_length
, bufp
, pc
);
676 #endif /* ! CGEN_INT_INSN_P */
683 /* Default print handler. */
686 print_normal (od
, dis_info
, value
, attrs
, pc
, length
)
694 disassemble_info
*info
= (disassemble_info
*) dis_info
;
696 #ifdef CGEN_PRINT_NORMAL
697 CGEN_PRINT_NORMAL (od
, info
, value
, attrs
, pc
, length
);
700 /* Print the operand as directed by the attributes. */
701 if (CGEN_BOOL_ATTR (attrs
, CGEN_OPERAND_SEM_ONLY
))
702 ; /* nothing to do */
703 else if (CGEN_BOOL_ATTR (attrs
, CGEN_OPERAND_UNSIGNED
))
704 (*info
->fprintf_func
) (info
->stream
, "0x%lx", value
);
706 (*info
->fprintf_func
) (info
->stream
, "%ld", value
);
709 /* Default address handler. */
712 print_address (od
, dis_info
, value
, attrs
, pc
, length
)
720 disassemble_info
*info
= (disassemble_info
*) dis_info
;
722 #ifdef CGEN_PRINT_ADDRESS
723 CGEN_PRINT_ADDRESS (od
, info
, value
, attrs
, pc
, length
);
726 /* Print the operand as directed by the attributes. */
727 if (CGEN_BOOL_ATTR (attrs
, CGEN_OPERAND_SEM_ONLY
))
728 ; /* nothing to do */
729 else if (CGEN_BOOL_ATTR (attrs
, CGEN_OPERAND_PCREL_ADDR
))
730 (*info
->print_address_func
) (value
, info
);
731 else if (CGEN_BOOL_ATTR (attrs
, CGEN_OPERAND_ABS_ADDR
))
732 (*info
->print_address_func
) (value
, info
);
733 else if (CGEN_BOOL_ATTR (attrs
, CGEN_OPERAND_UNSIGNED
))
734 (*info
->fprintf_func
) (info
->stream
, "0x%lx", (long) value
);
736 (*info
->fprintf_func
) (info
->stream
, "%ld", (long) value
);
739 /* Keyword print handler. */
742 print_keyword (od
, dis_info
, keyword_table
, value
, attrs
)
745 CGEN_KEYWORD
*keyword_table
;
749 disassemble_info
*info
= (disassemble_info
*) dis_info
;
750 const CGEN_KEYWORD_ENTRY
*ke
;
752 ke
= cgen_keyword_lookup_value (keyword_table
, value
);
754 (*info
->fprintf_func
) (info
->stream
, "%s", ke
->name
);
756 (*info
->fprintf_func
) (info
->stream
, "???");
759 /* Default insn extractor.
761 INSN_VALUE is the first CGEN_BASE_INSN_SIZE bytes, translated to host order.
762 The extracted fields are stored in FIELDS.
763 EX_INFO is used to handle reading variable length insns.
764 Return the length of the insn in bits, or 0 if no match,
765 or -1 if an error occurs fetching data (memory_error_func will have
769 extract_insn_normal (od
, insn
, ex_info
, insn_value
, fields
, pc
)
771 const CGEN_INSN
*insn
;
772 CGEN_EXTRACT_INFO
*ex_info
;
773 CGEN_INSN_INT insn_value
;
777 const CGEN_SYNTAX
*syntax
= CGEN_INSN_SYNTAX (insn
);
778 const unsigned char *syn
;
780 CGEN_FIELDS_BITSIZE (fields
) = CGEN_INSN_BITSIZE (insn
);
782 CGEN_INIT_EXTRACT (od
);
784 for (syn
= CGEN_SYNTAX_STRING (syntax
); *syn
; ++syn
)
788 if (CGEN_SYNTAX_CHAR_P (*syn
))
791 length
= fr30_cgen_extract_operand (od
, CGEN_SYNTAX_FIELD (*syn
),
792 ex_info
, insn_value
, fields
, pc
);
797 /* We recognized and successfully extracted this insn. */
798 return CGEN_INSN_BITSIZE (insn
);
801 /* Default insn printer.
803 DIS_INFO is defined as `PTR' so the disassembler needn't know anything
804 about disassemble_info. */
807 print_insn_normal (od
, dis_info
, insn
, fields
, pc
, length
)
810 const CGEN_INSN
*insn
;
815 const CGEN_SYNTAX
*syntax
= CGEN_INSN_SYNTAX (insn
);
816 disassemble_info
*info
= (disassemble_info
*) dis_info
;
817 const unsigned char *syn
;
819 CGEN_INIT_PRINT (od
);
821 for (syn
= CGEN_SYNTAX_STRING (syntax
); *syn
; ++syn
)
823 if (CGEN_SYNTAX_MNEMONIC_P (*syn
))
825 (*info
->fprintf_func
) (info
->stream
, "%s", CGEN_INSN_MNEMONIC (insn
));
828 if (CGEN_SYNTAX_CHAR_P (*syn
))
830 (*info
->fprintf_func
) (info
->stream
, "%c", CGEN_SYNTAX_CHAR (*syn
));
834 /* We have an operand. */
835 fr30_cgen_print_operand (od
, CGEN_SYNTAX_FIELD (*syn
), info
,
836 fields
, CGEN_INSN_ATTRS (insn
), pc
, length
);
840 /* Utility to print an insn.
841 BUF is the base part of the insn, target byte order, BUFLEN bytes long.
842 The result is the size of the insn in bytes or zero for an unknown insn
843 or -1 if an error occurs fetching data (memory_error_func will have
847 print_insn (od
, pc
, info
, buf
, buflen
)
850 disassemble_info
*info
;
854 unsigned long insn_value
;
855 const CGEN_INSN_LIST
*insn_list
;
856 CGEN_EXTRACT_INFO ex_info
;
858 ex_info
.dis_info
= info
;
859 ex_info
.valid
= (1 << CGEN_BASE_INSN_SIZE
) - 1;
860 ex_info
.insn_bytes
= buf
;
868 insn_value
= info
->endian
== BFD_ENDIAN_BIG
? bfd_getb16 (buf
) : bfd_getl16 (buf
);
871 insn_value
= info
->endian
== BFD_ENDIAN_BIG
? bfd_getb32 (buf
) : bfd_getl32 (buf
);
877 /* The instructions are stored in hash lists.
878 Pick the first one and keep trying until we find the right one. */
880 insn_list
= CGEN_DIS_LOOKUP_INSN (od
, buf
, insn_value
);
881 while (insn_list
!= NULL
)
883 const CGEN_INSN
*insn
= insn_list
->insn
;
887 #if 0 /* not needed as insn shouldn't be in hash lists if not supported */
888 /* Supported by this cpu? */
889 if (! fr30_cgen_insn_supported (od
, insn
))
893 /* Basic bit mask must be correct. */
894 /* ??? May wish to allow target to defer this check until the extract
896 if ((insn_value
& CGEN_INSN_BASE_MASK (insn
))
897 == CGEN_INSN_BASE_VALUE (insn
))
899 /* Printing is handled in two passes. The first pass parses the
900 machine insn and extracts the fields. The second pass prints
903 length
= (*CGEN_EXTRACT_FN (insn
)) (od
, insn
, &ex_info
, insn_value
,
905 /* length < 0 -> error */
910 (*CGEN_PRINT_FN (insn
)) (od
, info
, insn
, &fields
, pc
, length
);
911 /* length is in bits, result is in bytes */
916 insn_list
= CGEN_DIS_NEXT_INSN (insn_list
);
922 /* Default value for CGEN_PRINT_INSN.
923 The result is the size of the insn in bytes or zero for an unknown insn
924 or -1 if an error occured fetching bytes. */
926 #ifndef CGEN_PRINT_INSN
927 #define CGEN_PRINT_INSN default_print_insn
931 default_print_insn (od
, pc
, info
)
934 disassemble_info
*info
;
936 char buf
[CGEN_MAX_INSN_SIZE
];
939 /* Read the base part of the insn. */
941 status
= (*info
->read_memory_func
) (pc
, buf
, CGEN_BASE_INSN_SIZE
, info
);
944 (*info
->memory_error_func
) (status
, pc
, info
);
948 return print_insn (od
, pc
, info
, buf
, CGEN_BASE_INSN_SIZE
);
952 Print one instruction from PC on INFO->STREAM.
953 Return the size of the instruction (in bytes). */
956 print_insn_fr30 (pc
, info
)
958 disassemble_info
*info
;
961 static CGEN_OPCODE_DESC od
= 0;
962 int mach
= info
->mach
;
963 int big_p
= info
->endian
== BFD_ENDIAN_BIG
;
965 /* If we haven't initialized yet, initialize the opcode table. */
968 od
= fr30_cgen_opcode_open (mach
,
971 : CGEN_ENDIAN_LITTLE
);
972 fr30_cgen_init_dis (od
);
974 /* If we've switched cpu's, re-initialize. */
975 /* ??? Perhaps we should use BFD_ENDIAN. */
976 else if (mach
!= CGEN_OPCODE_MACH (od
)
977 || (CGEN_OPCODE_ENDIAN (od
)
978 != (big_p
? CGEN_ENDIAN_BIG
: CGEN_ENDIAN_LITTLE
)))
980 cgen_set_cpu (od
, mach
, big_p
? CGEN_ENDIAN_BIG
: CGEN_ENDIAN_LITTLE
);
983 /* We try to have as much common code as possible.
984 But at this point some targets need to take over. */
985 /* ??? Some targets may need a hook elsewhere. Try to avoid this,
986 but if not possible try to move this hook elsewhere rather than
988 length
= CGEN_PRINT_INSN (od
, pc
, info
);
994 (*info
->fprintf_func
) (info
->stream
, UNKNOWN_INSN_MSG
);
995 return CGEN_DEFAULT_INSN_SIZE
;