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 static int extract_normal
44 PARAMS ((CGEN_OPCODE_DESC, CGEN_EXTRACT_INFO *, CGEN_INSN_INT,
45 unsigned int, int, int, int, bfd_vma, long *));
46 static void print_normal
47 PARAMS ((CGEN_OPCODE_DESC, PTR, long, unsigned int, bfd_vma, int));
48 static void print_address
49 PARAMS ((CGEN_OPCODE_DESC, PTR, bfd_vma, unsigned int, bfd_vma, int));
50 static void print_keyword
51 PARAMS ((CGEN_OPCODE_DESC, PTR, CGEN_KEYWORD *, long, unsigned int));
52 static int extract_insn_normal
53 PARAMS ((CGEN_OPCODE_DESC, const CGEN_INSN *, CGEN_EXTRACT_INFO *,
54 CGEN_INSN_INT, CGEN_FIELDS *, bfd_vma));
55 static void print_insn_normal
56 PARAMS ((CGEN_OPCODE_DESC, PTR, const CGEN_INSN *, CGEN_FIELDS *,
58 static int print_insn PARAMS ((CGEN_OPCODE_DESC, bfd_vma,
59 disassemble_info *, char *, int));
60 static int default_print_insn
61 PARAMS ((CGEN_OPCODE_DESC, bfd_vma, disassemble_info *));
63 /* -- disassembler routines inserted here */
67 print_register_list (dis_info, value, offset)
72 disassemble_info *info = dis_info;
77 (*info->fprintf_func) (info->stream, "r%i", index + offset);
79 for (index = 1; index <= 7; ++index)
83 (*info->fprintf_func) (info->stream, ",r%i", index + offset);
88 print_hi_register_list (od, dis_info, value, attrs, pc, length)
96 print_register_list (dis_info, value, 8);
100 print_low_register_list (od, dis_info, value, attrs, pc, length)
108 print_register_list (dis_info, value, 0);
112 print_label9 (od, dis_info, value, attrs, pc, length)
120 disassemble_info *info = (disassemble_info *) dis_info;
121 (*info->fprintf_func) (info->stream, "0x%lx", value);
126 /* Main entry point for operand extraction.
128 This function is basically just a big switch statement. Earlier versions
129 used tables to look up the function to use, but
130 - if the table contains both assembler and disassembler functions then
131 the disassembler contains much of the assembler and vice-versa,
132 - there's a lot of inlining possibilities as things grow,
133 - using a switch statement avoids the function call overhead.
135 This function could be moved into `print_insn_normal', but keeping it
136 separate makes clear the interface between `print_insn_normal' and each of
141 fr30_cgen_extract_operand (od, opindex, ex_info, insn_value, fields, pc)
144 CGEN_EXTRACT_INFO *ex_info;
145 CGEN_INSN_INT insn_value;
146 CGEN_FIELDS * fields;
153 case FR30_OPERAND_RI :
154 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_UNSIGNED), 12, 4, CGEN_FIELDS_BITSIZE (fields), pc, & fields->f_Ri);
156 case FR30_OPERAND_RJ :
157 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_UNSIGNED), 8, 4, CGEN_FIELDS_BITSIZE (fields), pc, & fields->f_Rj);
159 case FR30_OPERAND_RIC :
160 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_UNSIGNED), 28, 4, CGEN_FIELDS_BITSIZE (fields), pc, & fields->f_Ric);
162 case FR30_OPERAND_RJC :
163 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_UNSIGNED), 24, 4, CGEN_FIELDS_BITSIZE (fields), pc, & fields->f_Rjc);
165 case FR30_OPERAND_CRI :
166 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_UNSIGNED), 28, 4, CGEN_FIELDS_BITSIZE (fields), pc, & fields->f_CRi);
168 case FR30_OPERAND_CRJ :
169 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_UNSIGNED), 24, 4, CGEN_FIELDS_BITSIZE (fields), pc, & fields->f_CRj);
171 case FR30_OPERAND_RS1 :
172 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_UNSIGNED), 8, 4, CGEN_FIELDS_BITSIZE (fields), pc, & fields->f_Rs1);
174 case FR30_OPERAND_RS2 :
175 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_UNSIGNED), 12, 4, CGEN_FIELDS_BITSIZE (fields), pc, & fields->f_Rs2);
177 case FR30_OPERAND_R13 :
178 length = extract_normal (od, ex_info, insn_value, 0, 0, 0, CGEN_FIELDS_BITSIZE (fields), pc, & fields->f_nil);
180 case FR30_OPERAND_R14 :
181 length = extract_normal (od, ex_info, insn_value, 0, 0, 0, CGEN_FIELDS_BITSIZE (fields), pc, & fields->f_nil);
183 case FR30_OPERAND_R15 :
184 length = extract_normal (od, ex_info, insn_value, 0, 0, 0, CGEN_FIELDS_BITSIZE (fields), pc, & fields->f_nil);
186 case FR30_OPERAND_PS :
187 length = extract_normal (od, ex_info, insn_value, 0, 0, 0, CGEN_FIELDS_BITSIZE (fields), pc, & fields->f_nil);
189 case FR30_OPERAND_U4 :
190 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), 8, 4, CGEN_FIELDS_BITSIZE (fields), pc, & fields->f_u4);
192 case FR30_OPERAND_U4C :
193 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), 12, 4, CGEN_FIELDS_BITSIZE (fields), pc, & fields->f_u4c);
195 case FR30_OPERAND_M4 :
198 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), 8, 4, CGEN_FIELDS_BITSIZE (fields), pc, & value);
199 value = ((value) | ((! (15))));
200 fields->f_m4 = value;
203 case FR30_OPERAND_U8 :
204 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), 8, 8, CGEN_FIELDS_BITSIZE (fields), pc, & fields->f_u8);
206 case FR30_OPERAND_I8 :
207 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), 4, 8, CGEN_FIELDS_BITSIZE (fields), pc, & fields->f_i8);
209 case FR30_OPERAND_UDISP6 :
212 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), 8, 4, CGEN_FIELDS_BITSIZE (fields), pc, & value);
213 value = ((value) << (2));
214 fields->f_udisp6 = value;
217 case FR30_OPERAND_DISP8 :
218 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_SIGNED), 4, 8, CGEN_FIELDS_BITSIZE (fields), pc, & fields->f_disp8);
220 case FR30_OPERAND_DISP9 :
223 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_SIGNED), 4, 8, CGEN_FIELDS_BITSIZE (fields), pc, & value);
224 value = ((value) << (1));
225 fields->f_disp9 = value;
228 case FR30_OPERAND_DISP10 :
231 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_SIGNED), 4, 8, CGEN_FIELDS_BITSIZE (fields), pc, & value);
232 value = ((value) << (2));
233 fields->f_disp10 = value;
236 case FR30_OPERAND_S10 :
239 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_SIGNED), 8, 8, CGEN_FIELDS_BITSIZE (fields), pc, & value);
240 value = ((value) << (2));
241 fields->f_s10 = value;
244 case FR30_OPERAND_U10 :
247 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), 8, 8, CGEN_FIELDS_BITSIZE (fields), pc, & value);
248 value = ((value) << (2));
249 fields->f_u10 = value;
252 case FR30_OPERAND_I32 :
253 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_SIGN_OPT)|(1<<CGEN_OPERAND_UNSIGNED), 16, 32, CGEN_FIELDS_BITSIZE (fields), pc, & fields->f_i32);
255 case FR30_OPERAND_DIR8 :
256 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_UNSIGNED), 8, 8, CGEN_FIELDS_BITSIZE (fields), pc, & fields->f_dir8);
258 case FR30_OPERAND_DIR9 :
261 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_UNSIGNED), 8, 8, CGEN_FIELDS_BITSIZE (fields), pc, & value);
262 value = ((value) << (1));
263 fields->f_dir9 = value;
266 case FR30_OPERAND_DIR10 :
269 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_UNSIGNED), 8, 8, CGEN_FIELDS_BITSIZE (fields), pc, & value);
270 value = ((value) << (2));
271 fields->f_dir10 = value;
274 case FR30_OPERAND_LABEL9 :
277 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR)|(1<<CGEN_OPERAND_SIGNED), 8, 8, CGEN_FIELDS_BITSIZE (fields), pc, & value);
278 value = ((((value) << (1))) + (((pc) + (2))));
279 fields->f_rel9 = value;
282 case FR30_OPERAND_LABEL12 :
285 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_PCREL_ADDR)|(1<<CGEN_OPERAND_SIGNED), 5, 11, CGEN_FIELDS_BITSIZE (fields), pc, & value);
286 value = ((((value) << (1))) + (((pc) & (-2))));
287 fields->f_rel12 = value;
290 case FR30_OPERAND_REGLIST_LOW :
291 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_UNSIGNED), 8, 8, CGEN_FIELDS_BITSIZE (fields), pc, & fields->f_reglist_low);
293 case FR30_OPERAND_REGLIST_HI :
294 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_UNSIGNED), 8, 8, CGEN_FIELDS_BITSIZE (fields), pc, & fields->f_reglist_hi);
296 case FR30_OPERAND_CC :
297 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_UNSIGNED), 4, 4, CGEN_FIELDS_BITSIZE (fields), pc, & fields->f_cc);
299 case FR30_OPERAND_CCC :
300 length = extract_normal (od, ex_info, insn_value, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), 16, 8, CGEN_FIELDS_BITSIZE (fields), pc, & fields->f_ccc);
304 /* xgettext:c-format */
305 fprintf (stderr, _("Unrecognized field %d while decoding insn.\n"),
313 /* Main entry point for printing operands.
315 This function is basically just a big switch statement. Earlier versions
316 used tables to look up the function to use, but
317 - if the table contains both assembler and disassembler functions then
318 the disassembler contains much of the assembler and vice-versa,
319 - there's a lot of inlining possibilities as things grow,
320 - using a switch statement avoids the function call overhead.
322 This function could be moved into `print_insn_normal', but keeping it
323 separate makes clear the interface between `print_insn_normal' and each of
328 fr30_cgen_print_operand (od, opindex, info, fields, attrs, pc, length)
331 disassemble_info * info;
332 CGEN_FIELDS * fields;
339 case FR30_OPERAND_RI :
340 print_keyword (od, info, & fr30_cgen_opval_h_gr, fields->f_Ri, 0|(1<<CGEN_OPERAND_UNSIGNED));
342 case FR30_OPERAND_RJ :
343 print_keyword (od, info, & fr30_cgen_opval_h_gr, fields->f_Rj, 0|(1<<CGEN_OPERAND_UNSIGNED));
345 case FR30_OPERAND_RIC :
346 print_keyword (od, info, & fr30_cgen_opval_h_gr, fields->f_Ric, 0|(1<<CGEN_OPERAND_UNSIGNED));
348 case FR30_OPERAND_RJC :
349 print_keyword (od, info, & fr30_cgen_opval_h_gr, fields->f_Rjc, 0|(1<<CGEN_OPERAND_UNSIGNED));
351 case FR30_OPERAND_CRI :
352 print_keyword (od, info, & fr30_cgen_opval_h_cr, fields->f_CRi, 0|(1<<CGEN_OPERAND_UNSIGNED));
354 case FR30_OPERAND_CRJ :
355 print_keyword (od, info, & fr30_cgen_opval_h_cr, fields->f_CRj, 0|(1<<CGEN_OPERAND_UNSIGNED));
357 case FR30_OPERAND_RS1 :
358 print_keyword (od, info, & fr30_cgen_opval_h_dr, fields->f_Rs1, 0|(1<<CGEN_OPERAND_UNSIGNED));
360 case FR30_OPERAND_RS2 :
361 print_keyword (od, info, & fr30_cgen_opval_h_dr, fields->f_Rs2, 0|(1<<CGEN_OPERAND_UNSIGNED));
363 case FR30_OPERAND_R13 :
364 print_keyword (od, info, & fr30_cgen_opval_h_r13, fields->f_nil, 0);
366 case FR30_OPERAND_R14 :
367 print_keyword (od, info, & fr30_cgen_opval_h_r14, fields->f_nil, 0);
369 case FR30_OPERAND_R15 :
370 print_keyword (od, info, & fr30_cgen_opval_h_r15, fields->f_nil, 0);
372 case FR30_OPERAND_PS :
373 print_keyword (od, info, & fr30_cgen_opval_h_ps, fields->f_nil, 0);
375 case FR30_OPERAND_U4 :
376 print_normal (od, info, fields->f_u4, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), pc, length);
378 case FR30_OPERAND_U4C :
379 print_normal (od, info, fields->f_u4c, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), pc, length);
381 case FR30_OPERAND_M4 :
382 print_normal (od, info, fields->f_m4, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), pc, length);
384 case FR30_OPERAND_U8 :
385 print_normal (od, info, fields->f_u8, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), pc, length);
387 case FR30_OPERAND_I8 :
388 print_normal (od, info, fields->f_i8, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), pc, length);
390 case FR30_OPERAND_UDISP6 :
391 print_normal (od, info, fields->f_udisp6, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), pc, length);
393 case FR30_OPERAND_DISP8 :
394 print_normal (od, info, fields->f_disp8, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_SIGNED), pc, length);
396 case FR30_OPERAND_DISP9 :
397 print_normal (od, info, fields->f_disp9, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_SIGNED), pc, length);
399 case FR30_OPERAND_DISP10 :
400 print_normal (od, info, fields->f_disp10, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_SIGNED), pc, length);
402 case FR30_OPERAND_S10 :
403 print_normal (od, info, fields->f_s10, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_SIGNED), pc, length);
405 case FR30_OPERAND_U10 :
406 print_normal (od, info, fields->f_u10, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), pc, length);
408 case FR30_OPERAND_I32 :
409 print_normal (od, info, fields->f_i32, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_SIGN_OPT)|(1<<CGEN_OPERAND_UNSIGNED), pc, length);
411 case FR30_OPERAND_DIR8 :
412 print_normal (od, info, fields->f_dir8, 0|(1<<CGEN_OPERAND_UNSIGNED), pc, length);
414 case FR30_OPERAND_DIR9 :
415 print_normal (od, info, fields->f_dir9, 0|(1<<CGEN_OPERAND_UNSIGNED), pc, length);
417 case FR30_OPERAND_DIR10 :
418 print_normal (od, info, fields->f_dir10, 0|(1<<CGEN_OPERAND_UNSIGNED), pc, length);
420 case FR30_OPERAND_LABEL9 :
421 print_label9 (od, info, fields->f_rel9, 0|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR)|(1<<CGEN_OPERAND_SIGNED), pc, length);
423 case FR30_OPERAND_LABEL12 :
424 print_normal (od, info, fields->f_rel12, 0|(1<<CGEN_OPERAND_PCREL_ADDR)|(1<<CGEN_OPERAND_SIGNED), pc, length);
426 case FR30_OPERAND_REGLIST_LOW :
427 print_low_register_list (od, info, fields->f_reglist_low, 0|(1<<CGEN_OPERAND_UNSIGNED), pc, length);
429 case FR30_OPERAND_REGLIST_HI :
430 print_hi_register_list (od, info, fields->f_reglist_hi, 0|(1<<CGEN_OPERAND_UNSIGNED), pc, length);
432 case FR30_OPERAND_CC :
433 print_normal (od, info, fields->f_cc, 0|(1<<CGEN_OPERAND_UNSIGNED), pc, length);
435 case FR30_OPERAND_CCC :
436 print_normal (od, info, fields->f_ccc, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), pc, length);
440 /* xgettext:c-format */
441 fprintf (stderr, _("Unrecognized field %d while printing insn.\n"),
447 cgen_extract_fn * const fr30_cgen_extract_handlers[] =
453 cgen_print_fn * const fr30_cgen_print_handlers[] =
461 fr30_cgen_init_dis (od)
467 #if ! CGEN_INT_INSN_P
469 /* Subroutine of extract_normal.
470 Ensure sufficient bytes are cached in EX_INFO.
471 Returns 1 for success, 0 for failure. */
474 fill_cache (od, ex_info, offset, bytes, pc)
476 CGEN_EXTRACT_INFO *ex_info;
480 /* It's doubtful that the middle part has already been fetched so
481 we don't optimize that case. kiss. */
483 disassemble_info *info = (disassemble_info *) ex_info->dis_info;
485 /* First do a quick check. */
486 mask = (1 << bytes) - 1;
487 if (((ex_info->valid >> offset) & mask) == mask)
490 /* Search for the first byte we need to read. */
491 for (mask = 1 << offset; bytes > 0; --bytes, ++offset, mask <<= 1)
492 if (! (mask & ex_info->valid))
500 status = (*info->read_memory_func)
501 (pc, ex_info->insn_bytes + offset, bytes, info);
505 (*info->memory_error_func) (status, pc, info);
509 ex_info->valid |= ((1 << bytes) - 1) << offset;
515 /* Subroutine of extract_normal. */
518 extract_1 (od, ex_info, start, length, word_length, bufp, pc)
520 CGEN_EXTRACT_INFO *ex_info;
521 int start,length,word_length;
525 unsigned long x,mask;
527 int big_p = CGEN_OPCODE_INSN_ENDIAN (od) == CGEN_ENDIAN_BIG;
536 x = bfd_getb16 (bufp);
538 x = bfd_getl16 (bufp);
541 /* ??? This may need reworking as these cases don't necessarily
542 want the first byte and the last two bytes handled like this. */
544 x = (bufp[0] << 16) | bfd_getb16 (bufp + 1);
546 x = bfd_getl16 (bufp) | (bufp[2] << 16);
550 x = bfd_getb32 (bufp);
552 x = bfd_getl32 (bufp);
558 /* Written this way to avoid undefined behaviour. */
559 mask = (((1L << (length - 1)) - 1) << 1) | 1;
560 if (CGEN_INSN_LSB0_P)
563 shift = (word_length - (start + length));
564 return (x >> shift) & mask;
567 #endif /* ! CGEN_INT_INSN_P */
569 /* Default extraction routine.
571 INSN_VALUE is the first CGEN_BASE_INSN_SIZE bits of the insn in host order,
572 or sometimes less for cases like the m32r where the base insn size is 32
573 but some insns are 16 bits.
574 ATTRS is a mask of the boolean attributes. We only need `unsigned',
575 but for generality we take a bitmask of all of them.
576 TOTAL_LENGTH is the length of the insn in bits.
578 Returns 1 for success, 0 for failure. */
580 /* ??? This doesn't handle bfd_vma's. Create another function when
584 extract_normal (od, ex_info, insn_value, attrs, start, length, total_length, pc, valuep)
586 CGEN_EXTRACT_INFO *ex_info;
587 CGEN_INSN_INT insn_value;
589 int start, length, total_length;
595 /* If LENGTH is zero, this operand doesn't contribute to the value
596 so give it a standard value of zero. */
605 ? ((total_length - start) <= CGEN_BASE_INSN_BITSIZE)
606 : ((start + length) <= CGEN_BASE_INSN_BITSIZE)))
608 /* Written this way to avoid undefined behaviour. */
609 unsigned long mask = (((1L << (length - 1)) - 1) << 1) | 1;
611 if (CGEN_INSN_LSB0_P)
612 value = insn_value >> start;
614 value = insn_value >> (total_length - (start + length));
617 if (! (attrs & CGEN_ATTR_MASK (CGEN_OPERAND_UNSIGNED))
618 && (value & (1L << (length - 1))))
622 #if ! CGEN_INT_INSN_P
624 /* The hard case is probably too slow for the normal cases.
625 It's certainly more difficult to understand than the normal case.
626 Thus this is split into two. The hard case is defined
627 to be when a field straddles a (loosely defined) word boundary
628 (??? which may require target specific help to determine). */
630 #define HARD_CASE_P 0 /* FIXME:wip */
632 else if (HARD_CASE_P)
638 unsigned char *bufp = ex_info->insn_bytes;
644 /* Adjust start,total_length,bufp to point to the pseudo-word that holds
645 the value. For example in a 48 bit insn where the value to insert
646 (say an immediate value) is the last 16 bits then fetch_length here
647 would be 16. To handle a 24 bit insn with an 18 bit immediate,
648 extract_1 handles 24 bits. */
650 if (total_length > 32)
652 int needed_width = start % 8 + length;
653 int fetch_length = (needed_width <= 8 ? 8
654 : needed_width <= 16 ? 16
657 if (CGEN_INSN_LSB0_P)
659 if (CGEN_INSN_WORD_ENDIAN (od) == CGEN_ENDIAN_BIG)
669 total_length = fetch_length;
674 if (CGEN_INSN_WORD_ENDIAN (od) == CGEN_ENDIAN_BIG)
680 total_length = fetch_length;
689 if (fill_cache (od, ex_info, offset / 8, total_length / 8, pc) == 0)
692 value = extract_1 (od, ex_info, start, length, total_length, bufp, pc);
695 #endif /* ! CGEN_INT_INSN_P */
702 /* Default print handler. */
705 print_normal (od, dis_info, value, attrs, pc, length)
713 disassemble_info *info = (disassemble_info *) dis_info;
715 #ifdef CGEN_PRINT_NORMAL
716 CGEN_PRINT_NORMAL (od, info, value, attrs, pc, length);
719 /* Print the operand as directed by the attributes. */
720 if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SEM_ONLY))
721 ; /* nothing to do */
722 else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_UNSIGNED))
723 (*info->fprintf_func) (info->stream, "0x%lx", value);
725 (*info->fprintf_func) (info->stream, "%ld", value);
728 /* Default address handler. */
731 print_address (od, dis_info, value, attrs, pc, length)
739 disassemble_info *info = (disassemble_info *) dis_info;
741 #ifdef CGEN_PRINT_ADDRESS
742 CGEN_PRINT_ADDRESS (od, info, value, attrs, pc, length);
745 /* Print the operand as directed by the attributes. */
746 if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SEM_ONLY))
747 ; /* nothing to do */
748 else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_PCREL_ADDR))
749 (*info->print_address_func) (value, info);
750 else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_ABS_ADDR))
751 (*info->print_address_func) (value, info);
752 else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_UNSIGNED))
753 (*info->fprintf_func) (info->stream, "0x%lx", (long) value);
755 (*info->fprintf_func) (info->stream, "%ld", (long) value);
758 /* Keyword print handler. */
761 print_keyword (od, dis_info, keyword_table, value, attrs)
764 CGEN_KEYWORD *keyword_table;
768 disassemble_info *info = (disassemble_info *) dis_info;
769 const CGEN_KEYWORD_ENTRY *ke;
771 ke = cgen_keyword_lookup_value (keyword_table, value);
773 (*info->fprintf_func) (info->stream, "%s", ke->name);
775 (*info->fprintf_func) (info->stream, "???");
778 /* Default insn extractor.
780 INSN_VALUE is the first CGEN_BASE_INSN_SIZE bytes, translated to host order.
781 The extracted fields are stored in FIELDS.
782 EX_INFO is used to handle reading variable length insns.
783 Return the length of the insn in bits, or 0 if no match,
784 or -1 if an error occurs fetching data (memory_error_func will have
788 extract_insn_normal (od, insn, ex_info, insn_value, fields, pc)
790 const CGEN_INSN *insn;
791 CGEN_EXTRACT_INFO *ex_info;
792 CGEN_INSN_INT insn_value;
796 const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
797 const unsigned char *syn;
799 CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
801 CGEN_INIT_EXTRACT (od);
803 for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn)
807 if (CGEN_SYNTAX_CHAR_P (*syn))
810 length = fr30_cgen_extract_operand (od, CGEN_SYNTAX_FIELD (*syn),
811 ex_info, insn_value, fields, pc);
816 /* We recognized and successfully extracted this insn. */
817 return CGEN_INSN_BITSIZE (insn);
820 /* Default insn printer.
822 DIS_INFO is defined as `PTR' so the disassembler needn't know anything
823 about disassemble_info. */
826 print_insn_normal (od, dis_info, insn, fields, pc, length)
829 const CGEN_INSN *insn;
834 const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
835 disassemble_info *info = (disassemble_info *) dis_info;
836 const unsigned char *syn;
838 CGEN_INIT_PRINT (od);
840 for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn)
842 if (CGEN_SYNTAX_MNEMONIC_P (*syn))
844 (*info->fprintf_func) (info->stream, "%s", CGEN_INSN_MNEMONIC (insn));
847 if (CGEN_SYNTAX_CHAR_P (*syn))
849 (*info->fprintf_func) (info->stream, "%c", CGEN_SYNTAX_CHAR (*syn));
853 /* We have an operand. */
854 fr30_cgen_print_operand (od, CGEN_SYNTAX_FIELD (*syn), info,
855 fields, CGEN_INSN_ATTRS (insn), pc, length);
859 /* Utility to print an insn.
860 BUF is the base part of the insn, target byte order, BUFLEN bytes long.
861 The result is the size of the insn in bytes or zero for an unknown insn
862 or -1 if an error occurs fetching data (memory_error_func will have
866 print_insn (od, pc, info, buf, buflen)
869 disassemble_info *info;
873 unsigned long insn_value;
874 const CGEN_INSN_LIST *insn_list;
875 CGEN_EXTRACT_INFO ex_info;
877 ex_info.dis_info = info;
878 ex_info.valid = (1 << CGEN_BASE_INSN_SIZE) - 1;
879 ex_info.insn_bytes = buf;
887 insn_value = info->endian == BFD_ENDIAN_BIG ? bfd_getb16 (buf) : bfd_getl16 (buf);
890 insn_value = info->endian == BFD_ENDIAN_BIG ? bfd_getb32 (buf) : bfd_getl32 (buf);
896 /* The instructions are stored in hash lists.
897 Pick the first one and keep trying until we find the right one. */
899 insn_list = CGEN_DIS_LOOKUP_INSN (od, buf, insn_value);
900 while (insn_list != NULL)
902 const CGEN_INSN *insn = insn_list->insn;
906 #if 0 /* not needed as insn shouldn't be in hash lists if not supported */
907 /* Supported by this cpu? */
908 if (! fr30_cgen_insn_supported (od, insn))
912 /* Basic bit mask must be correct. */
913 /* ??? May wish to allow target to defer this check until the extract
915 if ((insn_value & CGEN_INSN_MASK (insn)) == CGEN_INSN_VALUE (insn))
917 /* Printing is handled in two passes. The first pass parses the
918 machine insn and extracts the fields. The second pass prints
921 length = (*CGEN_EXTRACT_FN (insn)) (od, insn, &ex_info, insn_value,
923 /* length < 0 -> error */
928 (*CGEN_PRINT_FN (insn)) (od, info, insn, &fields, pc, length);
929 /* length is in bits, result is in bytes */
934 insn_list = CGEN_DIS_NEXT_INSN (insn_list);
940 /* Default value for CGEN_PRINT_INSN.
941 The result is the size of the insn in bytes or zero for an unknown insn
942 or -1 if an error occured fetching bytes. */
944 #ifndef CGEN_PRINT_INSN
945 #define CGEN_PRINT_INSN default_print_insn
949 default_print_insn (od, pc, info)
952 disassemble_info *info;
954 char buf[CGEN_MAX_INSN_SIZE];
957 /* Read the base part of the insn. */
959 status = (*info->read_memory_func) (pc, buf, CGEN_BASE_INSN_SIZE, info);
962 (*info->memory_error_func) (status, pc, info);
966 return print_insn (od, pc, info, buf, CGEN_BASE_INSN_SIZE);
970 Print one instruction from PC on INFO->STREAM.
971 Return the size of the instruction (in bytes). */
974 print_insn_fr30 (pc, info)
976 disassemble_info *info;
979 static CGEN_OPCODE_DESC od = 0;
980 int mach = info->mach;
981 int big_p = info->endian == BFD_ENDIAN_BIG;
983 /* If we haven't initialized yet, initialize the opcode table. */
986 od = fr30_cgen_opcode_open (mach,
989 : CGEN_ENDIAN_LITTLE);
990 fr30_cgen_init_dis (od);
992 /* If we've switched cpu's, re-initialize. */
993 /* ??? Perhaps we should use BFD_ENDIAN. */
994 else if (mach != CGEN_OPCODE_MACH (od)
995 || (CGEN_OPCODE_ENDIAN (od)
996 != (big_p ? CGEN_ENDIAN_BIG : CGEN_ENDIAN_LITTLE)))
998 cgen_set_cpu (od, mach, big_p ? CGEN_ENDIAN_BIG : CGEN_ENDIAN_LITTLE);
1001 /* We try to have as much common code as possible.
1002 But at this point some targets need to take over. */
1003 /* ??? Some targets may need a hook elsewhere. Try to avoid this,
1004 but if not possible try to move this hook elsewhere rather than
1006 length = CGEN_PRINT_INSN (od, pc, info);
1012 (*info->fprintf_func) (info->stream, UNKNOWN_INSN_MSG);
1013 return CGEN_DEFAULT_INSN_SIZE;