1 | /* Disassembler interface for targets using CGEN. -*- C -*-
|
---|
2 | CGEN: Cpu tools GENerator
|
---|
3 |
|
---|
4 | THIS FILE IS MACHINE GENERATED WITH CGEN.
|
---|
5 | - the resultant file is machine generated, cgen-dis.in isn't
|
---|
6 |
|
---|
7 | Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002
|
---|
8 | Free Software Foundation, Inc.
|
---|
9 |
|
---|
10 | This file is part of the GNU Binutils and GDB, the GNU debugger.
|
---|
11 |
|
---|
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)
|
---|
15 | any later version.
|
---|
16 |
|
---|
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.
|
---|
21 |
|
---|
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. */
|
---|
25 |
|
---|
26 | /* ??? Eventually more and more of this stuff can go to cpu-independent files.
|
---|
27 | Keep that in mind. */
|
---|
28 |
|
---|
29 | #include "sysdep.h"
|
---|
30 | #include <stdio.h>
|
---|
31 | #include "ansidecl.h"
|
---|
32 | #include "dis-asm.h"
|
---|
33 | #include "bfd.h"
|
---|
34 | #include "symcat.h"
|
---|
35 | #include "libiberty.h"
|
---|
36 | #include "ip2k-desc.h"
|
---|
37 | #include "ip2k-opc.h"
|
---|
38 | #include "opintl.h"
|
---|
39 |
|
---|
40 | /* Default text to print if an instruction isn't recognized. */
|
---|
41 | #define UNKNOWN_INSN_MSG _("*unknown*")
|
---|
42 |
|
---|
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 *,
|
---|
51 | bfd_vma, int));
|
---|
52 | static int print_insn
|
---|
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 *));
|
---|
56 | static int read_insn
|
---|
57 | PARAMS ((CGEN_CPU_DESC, bfd_vma, disassemble_info *, char *, int,
|
---|
58 | CGEN_EXTRACT_INFO *, unsigned long *));
|
---|
59 | |
---|
60 |
|
---|
61 | /* -- disassembler routines inserted here */
|
---|
62 |
|
---|
63 | /* -- dis.c */
|
---|
64 |
|
---|
65 | #define PRINT_FUNC_DECL(name) \
|
---|
66 | static void name PARAMS ((CGEN_CPU_DESC, PTR, long, unsigned int, bfd_vma, int))
|
---|
67 |
|
---|
68 | PRINT_FUNC_DECL (print_fr);
|
---|
69 | PRINT_FUNC_DECL (print_dollarhex);
|
---|
70 | PRINT_FUNC_DECL (print_dollarhex8);
|
---|
71 | PRINT_FUNC_DECL (print_dollarhex16);
|
---|
72 | PRINT_FUNC_DECL (print_dollarhex_addr16h);
|
---|
73 | PRINT_FUNC_DECL (print_dollarhex_addr16l);
|
---|
74 | PRINT_FUNC_DECL (print_dollarhex_p);
|
---|
75 | PRINT_FUNC_DECL (print_dollarhex_cj);
|
---|
76 | PRINT_FUNC_DECL (print_decimal);
|
---|
77 |
|
---|
78 | static void
|
---|
79 | print_fr (cd, dis_info, value, attrs, pc, length)
|
---|
80 | CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
|
---|
81 | PTR dis_info;
|
---|
82 | long value;
|
---|
83 | unsigned int attrs ATTRIBUTE_UNUSED;
|
---|
84 | bfd_vma pc ATTRIBUTE_UNUSED;
|
---|
85 | int length ATTRIBUTE_UNUSED;
|
---|
86 | {
|
---|
87 | disassemble_info *info = (disassemble_info *) dis_info;
|
---|
88 | const CGEN_KEYWORD_ENTRY *ke;
|
---|
89 | extern CGEN_KEYWORD ip2k_cgen_opval_register_names;
|
---|
90 | long offsettest;
|
---|
91 | long offsetvalue;
|
---|
92 |
|
---|
93 | if ( value == 0 ) /* This is (IP) */
|
---|
94 | {
|
---|
95 | (*info->fprintf_func) (info->stream, "%s", "(IP)");
|
---|
96 | return;
|
---|
97 | }
|
---|
98 |
|
---|
99 | offsettest = value >> 7;
|
---|
100 | offsetvalue = value & 0x7F;
|
---|
101 |
|
---|
102 | /* Check to see if first two bits are 10 -> (DP) */
|
---|
103 | if ( offsettest == 2 )
|
---|
104 | {
|
---|
105 | if ( offsetvalue == 0 )
|
---|
106 | (*info->fprintf_func) (info->stream, "%s","(DP)");
|
---|
107 | else
|
---|
108 | (*info->fprintf_func) (info->stream, "$%x%s",offsetvalue, "(DP)");
|
---|
109 | return;
|
---|
110 | }
|
---|
111 |
|
---|
112 | /* Check to see if first two bits are 11 -> (SP) */
|
---|
113 | if ( offsettest == 3 )
|
---|
114 | {
|
---|
115 | if ( offsetvalue == 0 )
|
---|
116 | (*info->fprintf_func) (info->stream, "%s", "(SP)");
|
---|
117 | else
|
---|
118 | (*info->fprintf_func) (info->stream, "$%x%s", offsetvalue,"(SP)");
|
---|
119 | return;
|
---|
120 | }
|
---|
121 |
|
---|
122 | /* Attempt to print as a register keyword. */
|
---|
123 | ke = cgen_keyword_lookup_value (& ip2k_cgen_opval_register_names, value);
|
---|
124 | if (ke != NULL)
|
---|
125 | {
|
---|
126 | (*info->fprintf_func) (info->stream, "%s", ke->name);
|
---|
127 | return;
|
---|
128 | }
|
---|
129 |
|
---|
130 | /* Print as an address literal. */
|
---|
131 | (*info->fprintf_func) (info->stream, "$%02x", value);
|
---|
132 | }
|
---|
133 |
|
---|
134 | static void
|
---|
135 | print_dollarhex (cd, dis_info, value, attrs, pc, length)
|
---|
136 | CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
|
---|
137 | PTR dis_info;
|
---|
138 | long value;
|
---|
139 | unsigned int attrs ATTRIBUTE_UNUSED;
|
---|
140 | bfd_vma pc ATTRIBUTE_UNUSED;
|
---|
141 | int length ATTRIBUTE_UNUSED;
|
---|
142 | {
|
---|
143 | disassemble_info *info = (disassemble_info *) dis_info;
|
---|
144 |
|
---|
145 | (*info->fprintf_func) (info->stream, "$%x", value);
|
---|
146 | }
|
---|
147 |
|
---|
148 | static void
|
---|
149 | print_dollarhex8 (cd, dis_info, value, attrs, pc, length)
|
---|
150 | CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
|
---|
151 | PTR dis_info;
|
---|
152 | long value;
|
---|
153 | unsigned int attrs ATTRIBUTE_UNUSED;
|
---|
154 | bfd_vma pc ATTRIBUTE_UNUSED;
|
---|
155 | int length ATTRIBUTE_UNUSED;
|
---|
156 | {
|
---|
157 | disassemble_info *info = (disassemble_info *) dis_info;
|
---|
158 |
|
---|
159 | (*info->fprintf_func) (info->stream, "$%02x", value);
|
---|
160 | }
|
---|
161 |
|
---|
162 | static void
|
---|
163 | print_dollarhex16 (cd, dis_info, value, attrs, pc, length)
|
---|
164 | CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
|
---|
165 | PTR dis_info;
|
---|
166 | long value;
|
---|
167 | unsigned int attrs ATTRIBUTE_UNUSED;
|
---|
168 | bfd_vma pc ATTRIBUTE_UNUSED;
|
---|
169 | int length ATTRIBUTE_UNUSED;
|
---|
170 | {
|
---|
171 | disassemble_info *info = (disassemble_info *) dis_info;
|
---|
172 |
|
---|
173 | (*info->fprintf_func) (info->stream, "$%04x", value);
|
---|
174 | }
|
---|
175 |
|
---|
176 | static void
|
---|
177 | print_dollarhex_addr16h (cd, dis_info, value, attrs, pc, length)
|
---|
178 | CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
|
---|
179 | PTR dis_info;
|
---|
180 | long value;
|
---|
181 | unsigned int attrs ATTRIBUTE_UNUSED;
|
---|
182 | bfd_vma pc ATTRIBUTE_UNUSED;
|
---|
183 | int length ATTRIBUTE_UNUSED;
|
---|
184 | {
|
---|
185 | disassemble_info *info = (disassemble_info *) dis_info;
|
---|
186 |
|
---|
187 | /* This is a loadh instruction. Shift the value to the left */
|
---|
188 | /* by 8 bits so that disassembled code will reassemble properly. */
|
---|
189 | value = ((value << 8) & 0xFF00);
|
---|
190 |
|
---|
191 | (*info->fprintf_func) (info->stream, "$%04x", value);
|
---|
192 | }
|
---|
193 |
|
---|
194 | static void
|
---|
195 | print_dollarhex_addr16l (cd, dis_info, value, attrs, pc, length)
|
---|
196 | CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
|
---|
197 | PTR dis_info;
|
---|
198 | long value;
|
---|
199 | unsigned int attrs ATTRIBUTE_UNUSED;
|
---|
200 | bfd_vma pc ATTRIBUTE_UNUSED;
|
---|
201 | int length ATTRIBUTE_UNUSED;
|
---|
202 | {
|
---|
203 | disassemble_info *info = (disassemble_info *) dis_info;
|
---|
204 |
|
---|
205 | (*info->fprintf_func) (info->stream, "$%04x", value);
|
---|
206 | }
|
---|
207 |
|
---|
208 | static void
|
---|
209 | print_dollarhex_p (cd, dis_info, value, attrs, pc, length)
|
---|
210 | CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
|
---|
211 | PTR dis_info;
|
---|
212 | long value;
|
---|
213 | unsigned int attrs ATTRIBUTE_UNUSED;
|
---|
214 | bfd_vma pc ATTRIBUTE_UNUSED;
|
---|
215 | int length ATTRIBUTE_UNUSED;
|
---|
216 | {
|
---|
217 | disassemble_info *info = (disassemble_info *) dis_info;
|
---|
218 |
|
---|
219 | value = ((value << 14) & 0x1C000);
|
---|
220 | ;value = (value & 0x1FFFF);
|
---|
221 | (*info->fprintf_func) (info->stream, "$%05x", value);
|
---|
222 | }
|
---|
223 |
|
---|
224 | static void
|
---|
225 | print_dollarhex_cj (cd, dis_info, value, attrs, pc, length)
|
---|
226 | CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
|
---|
227 | PTR dis_info;
|
---|
228 | long value;
|
---|
229 | unsigned int attrs ATTRIBUTE_UNUSED;
|
---|
230 | bfd_vma pc ATTRIBUTE_UNUSED;
|
---|
231 | int length ATTRIBUTE_UNUSED;
|
---|
232 | {
|
---|
233 | disassemble_info *info = (disassemble_info *) dis_info;
|
---|
234 |
|
---|
235 | value = ((value << 1) & 0x1FFFF);
|
---|
236 | (*info->fprintf_func) (info->stream, "$%05x", value);
|
---|
237 | }
|
---|
238 |
|
---|
239 |
|
---|
240 | static void
|
---|
241 | print_decimal (cd, dis_info, value, attrs, pc, length)
|
---|
242 | CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
|
---|
243 | PTR dis_info;
|
---|
244 | long value;
|
---|
245 | unsigned int attrs ATTRIBUTE_UNUSED;
|
---|
246 | bfd_vma pc ATTRIBUTE_UNUSED;
|
---|
247 | int length ATTRIBUTE_UNUSED;
|
---|
248 | {
|
---|
249 | disassemble_info *info = (disassemble_info *) dis_info;
|
---|
250 |
|
---|
251 | (*info->fprintf_func) (info->stream, "%d", value);
|
---|
252 | }
|
---|
253 |
|
---|
254 |
|
---|
255 |
|
---|
256 | /* -- */
|
---|
257 |
|
---|
258 | void ip2k_cgen_print_operand
|
---|
259 | PARAMS ((CGEN_CPU_DESC, int, PTR, CGEN_FIELDS *,
|
---|
260 | void const *, bfd_vma, int));
|
---|
261 |
|
---|
262 | /* Main entry point for printing operands.
|
---|
263 | XINFO is a `void *' and not a `disassemble_info *' to not put a requirement
|
---|
264 | of dis-asm.h on cgen.h.
|
---|
265 |
|
---|
266 | This function is basically just a big switch statement. Earlier versions
|
---|
267 | used tables to look up the function to use, but
|
---|
268 | - if the table contains both assembler and disassembler functions then
|
---|
269 | the disassembler contains much of the assembler and vice-versa,
|
---|
270 | - there's a lot of inlining possibilities as things grow,
|
---|
271 | - using a switch statement avoids the function call overhead.
|
---|
272 |
|
---|
273 | This function could be moved into `print_insn_normal', but keeping it
|
---|
274 | separate makes clear the interface between `print_insn_normal' and each of
|
---|
275 | the handlers. */
|
---|
276 |
|
---|
277 | void
|
---|
278 | ip2k_cgen_print_operand (cd, opindex, xinfo, fields, attrs, pc, length)
|
---|
279 | CGEN_CPU_DESC cd;
|
---|
280 | int opindex;
|
---|
281 | PTR xinfo;
|
---|
282 | CGEN_FIELDS *fields;
|
---|
283 | void const *attrs ATTRIBUTE_UNUSED;
|
---|
284 | bfd_vma pc;
|
---|
285 | int length;
|
---|
286 | {
|
---|
287 | disassemble_info *info = (disassemble_info *) xinfo;
|
---|
288 |
|
---|
289 | switch (opindex)
|
---|
290 | {
|
---|
291 | case IP2K_OPERAND_ADDR16CJP :
|
---|
292 | print_dollarhex_cj (cd, info, fields->f_addr16cjp, 0|(1<<CGEN_OPERAND_ABS_ADDR), pc, length);
|
---|
293 | break;
|
---|
294 | case IP2K_OPERAND_ADDR16H :
|
---|
295 | print_dollarhex_addr16h (cd, info, fields->f_imm8, 0, pc, length);
|
---|
296 | break;
|
---|
297 | case IP2K_OPERAND_ADDR16L :
|
---|
298 | print_dollarhex_addr16l (cd, info, fields->f_imm8, 0, pc, length);
|
---|
299 | break;
|
---|
300 | case IP2K_OPERAND_ADDR16P :
|
---|
301 | print_dollarhex_p (cd, info, fields->f_page3, 0, pc, length);
|
---|
302 | break;
|
---|
303 | case IP2K_OPERAND_BITNO :
|
---|
304 | print_decimal (cd, info, fields->f_bitno, 0, pc, length);
|
---|
305 | break;
|
---|
306 | case IP2K_OPERAND_CBIT :
|
---|
307 | print_normal (cd, info, 0, 0, pc, length);
|
---|
308 | break;
|
---|
309 | case IP2K_OPERAND_DCBIT :
|
---|
310 | print_normal (cd, info, 0, 0, pc, length);
|
---|
311 | break;
|
---|
312 | case IP2K_OPERAND_FR :
|
---|
313 | print_fr (cd, info, fields->f_reg, 0|(1<<CGEN_OPERAND_ABS_ADDR), pc, length);
|
---|
314 | break;
|
---|
315 | case IP2K_OPERAND_LIT8 :
|
---|
316 | print_dollarhex8 (cd, info, fields->f_imm8, 0|(1<<CGEN_OPERAND_SIGNED), pc, length);
|
---|
317 | break;
|
---|
318 | case IP2K_OPERAND_PABITS :
|
---|
319 | print_normal (cd, info, 0, 0, pc, length);
|
---|
320 | break;
|
---|
321 | case IP2K_OPERAND_RETI3 :
|
---|
322 | print_dollarhex (cd, info, fields->f_reti3, 0, pc, length);
|
---|
323 | break;
|
---|
324 | case IP2K_OPERAND_ZBIT :
|
---|
325 | print_normal (cd, info, 0, 0, pc, length);
|
---|
326 | break;
|
---|
327 |
|
---|
328 | default :
|
---|
329 | /* xgettext:c-format */
|
---|
330 | fprintf (stderr, _("Unrecognized field %d while printing insn.\n"),
|
---|
331 | opindex);
|
---|
332 | abort ();
|
---|
333 | }
|
---|
334 | }
|
---|
335 |
|
---|
336 | cgen_print_fn * const ip2k_cgen_print_handlers[] =
|
---|
337 | {
|
---|
338 | print_insn_normal,
|
---|
339 | };
|
---|
340 |
|
---|
341 |
|
---|
342 | void
|
---|
343 | ip2k_cgen_init_dis (cd)
|
---|
344 | CGEN_CPU_DESC cd;
|
---|
345 | {
|
---|
346 | ip2k_cgen_init_opcode_table (cd);
|
---|
347 | ip2k_cgen_init_ibld_table (cd);
|
---|
348 | cd->print_handlers = & ip2k_cgen_print_handlers[0];
|
---|
349 | cd->print_operand = ip2k_cgen_print_operand;
|
---|
350 | }
|
---|
351 |
|
---|
352 | |
---|
353 |
|
---|
354 | /* Default print handler. */
|
---|
355 |
|
---|
356 | static void
|
---|
357 | print_normal (cd, dis_info, value, attrs, pc, length)
|
---|
358 | CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
|
---|
359 | PTR dis_info;
|
---|
360 | long value;
|
---|
361 | unsigned int attrs;
|
---|
362 | bfd_vma pc ATTRIBUTE_UNUSED;
|
---|
363 | int length ATTRIBUTE_UNUSED;
|
---|
364 | {
|
---|
365 | disassemble_info *info = (disassemble_info *) dis_info;
|
---|
366 |
|
---|
367 | #ifdef CGEN_PRINT_NORMAL
|
---|
368 | CGEN_PRINT_NORMAL (cd, info, value, attrs, pc, length);
|
---|
369 | #endif
|
---|
370 |
|
---|
371 | /* Print the operand as directed by the attributes. */
|
---|
372 | if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SEM_ONLY))
|
---|
373 | ; /* nothing to do */
|
---|
374 | else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SIGNED))
|
---|
375 | (*info->fprintf_func) (info->stream, "%ld", value);
|
---|
376 | else
|
---|
377 | (*info->fprintf_func) (info->stream, "0x%lx", value);
|
---|
378 | }
|
---|
379 |
|
---|
380 | /* Default address handler. */
|
---|
381 |
|
---|
382 | static void
|
---|
383 | print_address (cd, dis_info, value, attrs, pc, length)
|
---|
384 | CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
|
---|
385 | PTR dis_info;
|
---|
386 | bfd_vma value;
|
---|
387 | unsigned int attrs;
|
---|
388 | bfd_vma pc ATTRIBUTE_UNUSED;
|
---|
389 | int length ATTRIBUTE_UNUSED;
|
---|
390 | {
|
---|
391 | disassemble_info *info = (disassemble_info *) dis_info;
|
---|
392 |
|
---|
393 | #ifdef CGEN_PRINT_ADDRESS
|
---|
394 | CGEN_PRINT_ADDRESS (cd, info, value, attrs, pc, length);
|
---|
395 | #endif
|
---|
396 |
|
---|
397 | /* Print the operand as directed by the attributes. */
|
---|
398 | if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SEM_ONLY))
|
---|
399 | ; /* nothing to do */
|
---|
400 | else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_PCREL_ADDR))
|
---|
401 | (*info->print_address_func) (value, info);
|
---|
402 | else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_ABS_ADDR))
|
---|
403 | (*info->print_address_func) (value, info);
|
---|
404 | else if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_SIGNED))
|
---|
405 | (*info->fprintf_func) (info->stream, "%ld", (long) value);
|
---|
406 | else
|
---|
407 | (*info->fprintf_func) (info->stream, "0x%lx", (long) value);
|
---|
408 | }
|
---|
409 |
|
---|
410 | /* Keyword print handler. */
|
---|
411 |
|
---|
412 | static void
|
---|
413 | print_keyword (cd, dis_info, keyword_table, value, attrs)
|
---|
414 | CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
|
---|
415 | PTR dis_info;
|
---|
416 | CGEN_KEYWORD *keyword_table;
|
---|
417 | long value;
|
---|
418 | unsigned int attrs ATTRIBUTE_UNUSED;
|
---|
419 | {
|
---|
420 | disassemble_info *info = (disassemble_info *) dis_info;
|
---|
421 | const CGEN_KEYWORD_ENTRY *ke;
|
---|
422 |
|
---|
423 | ke = cgen_keyword_lookup_value (keyword_table, value);
|
---|
424 | if (ke != NULL)
|
---|
425 | (*info->fprintf_func) (info->stream, "%s", ke->name);
|
---|
426 | else
|
---|
427 | (*info->fprintf_func) (info->stream, "???");
|
---|
428 | }
|
---|
429 | |
---|
430 |
|
---|
431 | /* Default insn printer.
|
---|
432 |
|
---|
433 | DIS_INFO is defined as `PTR' so the disassembler needn't know anything
|
---|
434 | about disassemble_info. */
|
---|
435 |
|
---|
436 | static void
|
---|
437 | print_insn_normal (cd, dis_info, insn, fields, pc, length)
|
---|
438 | CGEN_CPU_DESC cd;
|
---|
439 | PTR dis_info;
|
---|
440 | const CGEN_INSN *insn;
|
---|
441 | CGEN_FIELDS *fields;
|
---|
442 | bfd_vma pc;
|
---|
443 | int length;
|
---|
444 | {
|
---|
445 | const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
|
---|
446 | disassemble_info *info = (disassemble_info *) dis_info;
|
---|
447 | const CGEN_SYNTAX_CHAR_TYPE *syn;
|
---|
448 |
|
---|
449 | CGEN_INIT_PRINT (cd);
|
---|
450 |
|
---|
451 | for (syn = CGEN_SYNTAX_STRING (syntax); *syn; ++syn)
|
---|
452 | {
|
---|
453 | if (CGEN_SYNTAX_MNEMONIC_P (*syn))
|
---|
454 | {
|
---|
455 | (*info->fprintf_func) (info->stream, "%s", CGEN_INSN_MNEMONIC (insn));
|
---|
456 | continue;
|
---|
457 | }
|
---|
458 | if (CGEN_SYNTAX_CHAR_P (*syn))
|
---|
459 | {
|
---|
460 | (*info->fprintf_func) (info->stream, "%c", CGEN_SYNTAX_CHAR (*syn));
|
---|
461 | continue;
|
---|
462 | }
|
---|
463 |
|
---|
464 | /* We have an operand. */
|
---|
465 | ip2k_cgen_print_operand (cd, CGEN_SYNTAX_FIELD (*syn), info,
|
---|
466 | fields, CGEN_INSN_ATTRS (insn), pc, length);
|
---|
467 | }
|
---|
468 | }
|
---|
469 | |
---|
470 |
|
---|
471 | /* Subroutine of print_insn. Reads an insn into the given buffers and updates
|
---|
472 | the extract info.
|
---|
473 | Returns 0 if all is well, non-zero otherwise. */
|
---|
474 |
|
---|
475 | static int
|
---|
476 | read_insn (cd, pc, info, buf, buflen, ex_info, insn_value)
|
---|
477 | CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
|
---|
478 | bfd_vma pc;
|
---|
479 | disassemble_info *info;
|
---|
480 | char *buf;
|
---|
481 | int buflen;
|
---|
482 | CGEN_EXTRACT_INFO *ex_info;
|
---|
483 | unsigned long *insn_value;
|
---|
484 | {
|
---|
485 | int status = (*info->read_memory_func) (pc, buf, buflen, info);
|
---|
486 | if (status != 0)
|
---|
487 | {
|
---|
488 | (*info->memory_error_func) (status, pc, info);
|
---|
489 | return -1;
|
---|
490 | }
|
---|
491 |
|
---|
492 | ex_info->dis_info = info;
|
---|
493 | ex_info->valid = (1 << buflen) - 1;
|
---|
494 | ex_info->insn_bytes = buf;
|
---|
495 |
|
---|
496 | *insn_value = bfd_get_bits (buf, buflen * 8, info->endian == BFD_ENDIAN_BIG);
|
---|
497 | return 0;
|
---|
498 | }
|
---|
499 |
|
---|
500 | /* Utility to print an insn.
|
---|
501 | BUF is the base part of the insn, target byte order, BUFLEN bytes long.
|
---|
502 | The result is the size of the insn in bytes or zero for an unknown insn
|
---|
503 | or -1 if an error occurs fetching data (memory_error_func will have
|
---|
504 | been called). */
|
---|
505 |
|
---|
506 | static int
|
---|
507 | print_insn (cd, pc, info, buf, buflen)
|
---|
508 | CGEN_CPU_DESC cd;
|
---|
509 | bfd_vma pc;
|
---|
510 | disassemble_info *info;
|
---|
511 | char *buf;
|
---|
512 | unsigned int buflen;
|
---|
513 | {
|
---|
514 | CGEN_INSN_INT insn_value;
|
---|
515 | const CGEN_INSN_LIST *insn_list;
|
---|
516 | CGEN_EXTRACT_INFO ex_info;
|
---|
517 | int basesize;
|
---|
518 |
|
---|
519 | /* Extract base part of instruction, just in case CGEN_DIS_* uses it. */
|
---|
520 | basesize = cd->base_insn_bitsize < buflen * 8 ?
|
---|
521 | cd->base_insn_bitsize : buflen * 8;
|
---|
522 | insn_value = cgen_get_insn_value (cd, buf, basesize);
|
---|
523 |
|
---|
524 |
|
---|
525 | /* Fill in ex_info fields like read_insn would. Don't actually call
|
---|
526 | read_insn, since the incoming buffer is already read (and possibly
|
---|
527 | modified a la m32r). */
|
---|
528 | ex_info.valid = (1 << buflen) - 1;
|
---|
529 | ex_info.dis_info = info;
|
---|
530 | ex_info.insn_bytes = buf;
|
---|
531 |
|
---|
532 | /* The instructions are stored in hash lists.
|
---|
533 | Pick the first one and keep trying until we find the right one. */
|
---|
534 |
|
---|
535 | insn_list = CGEN_DIS_LOOKUP_INSN (cd, buf, insn_value);
|
---|
536 | while (insn_list != NULL)
|
---|
537 | {
|
---|
538 | const CGEN_INSN *insn = insn_list->insn;
|
---|
539 | CGEN_FIELDS fields;
|
---|
540 | int length;
|
---|
541 | unsigned long insn_value_cropped;
|
---|
542 |
|
---|
543 | #ifdef CGEN_VALIDATE_INSN_SUPPORTED
|
---|
544 | /* Not needed as insn shouldn't be in hash lists if not supported. */
|
---|
545 | /* Supported by this cpu? */
|
---|
546 | if (! ip2k_cgen_insn_supported (cd, insn))
|
---|
547 | {
|
---|
548 | insn_list = CGEN_DIS_NEXT_INSN (insn_list);
|
---|
549 | continue;
|
---|
550 | }
|
---|
551 | #endif
|
---|
552 |
|
---|
553 | /* Basic bit mask must be correct. */
|
---|
554 | /* ??? May wish to allow target to defer this check until the extract
|
---|
555 | handler. */
|
---|
556 |
|
---|
557 | /* Base size may exceed this instruction's size. Extract the
|
---|
558 | relevant part from the buffer. */
|
---|
559 | if ((unsigned) (CGEN_INSN_BITSIZE (insn) / 8) < buflen &&
|
---|
560 | (unsigned) (CGEN_INSN_BITSIZE (insn) / 8) <= sizeof (unsigned long))
|
---|
561 | insn_value_cropped = bfd_get_bits (buf, CGEN_INSN_BITSIZE (insn),
|
---|
562 | info->endian == BFD_ENDIAN_BIG);
|
---|
563 | else
|
---|
564 | insn_value_cropped = insn_value;
|
---|
565 |
|
---|
566 | if ((insn_value_cropped & CGEN_INSN_BASE_MASK (insn))
|
---|
567 | == CGEN_INSN_BASE_VALUE (insn))
|
---|
568 | {
|
---|
569 | /* Printing is handled in two passes. The first pass parses the
|
---|
570 | machine insn and extracts the fields. The second pass prints
|
---|
571 | them. */
|
---|
572 |
|
---|
573 | /* Make sure the entire insn is loaded into insn_value, if it
|
---|
574 | can fit. */
|
---|
575 | if (((unsigned) CGEN_INSN_BITSIZE (insn) > cd->base_insn_bitsize) &&
|
---|
576 | (unsigned) (CGEN_INSN_BITSIZE (insn) / 8) <= sizeof (unsigned long))
|
---|
577 | {
|
---|
578 | unsigned long full_insn_value;
|
---|
579 | int rc = read_insn (cd, pc, info, buf,
|
---|
580 | CGEN_INSN_BITSIZE (insn) / 8,
|
---|
581 | & ex_info, & full_insn_value);
|
---|
582 | if (rc != 0)
|
---|
583 | return rc;
|
---|
584 | length = CGEN_EXTRACT_FN (cd, insn)
|
---|
585 | (cd, insn, &ex_info, full_insn_value, &fields, pc);
|
---|
586 | }
|
---|
587 | else
|
---|
588 | length = CGEN_EXTRACT_FN (cd, insn)
|
---|
589 | (cd, insn, &ex_info, insn_value_cropped, &fields, pc);
|
---|
590 |
|
---|
591 | /* length < 0 -> error */
|
---|
592 | if (length < 0)
|
---|
593 | return length;
|
---|
594 | if (length > 0)
|
---|
595 | {
|
---|
596 | CGEN_PRINT_FN (cd, insn) (cd, info, insn, &fields, pc, length);
|
---|
597 | /* length is in bits, result is in bytes */
|
---|
598 | return length / 8;
|
---|
599 | }
|
---|
600 | }
|
---|
601 |
|
---|
602 | insn_list = CGEN_DIS_NEXT_INSN (insn_list);
|
---|
603 | }
|
---|
604 |
|
---|
605 | return 0;
|
---|
606 | }
|
---|
607 |
|
---|
608 | /* Default value for CGEN_PRINT_INSN.
|
---|
609 | The result is the size of the insn in bytes or zero for an unknown insn
|
---|
610 | or -1 if an error occured fetching bytes. */
|
---|
611 |
|
---|
612 | #ifndef CGEN_PRINT_INSN
|
---|
613 | #define CGEN_PRINT_INSN default_print_insn
|
---|
614 | #endif
|
---|
615 |
|
---|
616 | static int
|
---|
617 | default_print_insn (cd, pc, info)
|
---|
618 | CGEN_CPU_DESC cd;
|
---|
619 | bfd_vma pc;
|
---|
620 | disassemble_info *info;
|
---|
621 | {
|
---|
622 | char buf[CGEN_MAX_INSN_SIZE];
|
---|
623 | int buflen;
|
---|
624 | int status;
|
---|
625 |
|
---|
626 | /* Attempt to read the base part of the insn. */
|
---|
627 | buflen = cd->base_insn_bitsize / 8;
|
---|
628 | status = (*info->read_memory_func) (pc, buf, buflen, info);
|
---|
629 |
|
---|
630 | /* Try again with the minimum part, if min < base. */
|
---|
631 | if (status != 0 && (cd->min_insn_bitsize < cd->base_insn_bitsize))
|
---|
632 | {
|
---|
633 | buflen = cd->min_insn_bitsize / 8;
|
---|
634 | status = (*info->read_memory_func) (pc, buf, buflen, info);
|
---|
635 | }
|
---|
636 |
|
---|
637 | if (status != 0)
|
---|
638 | {
|
---|
639 | (*info->memory_error_func) (status, pc, info);
|
---|
640 | return -1;
|
---|
641 | }
|
---|
642 |
|
---|
643 | return print_insn (cd, pc, info, buf, buflen);
|
---|
644 | }
|
---|
645 |
|
---|
646 | /* Main entry point.
|
---|
647 | Print one instruction from PC on INFO->STREAM.
|
---|
648 | Return the size of the instruction (in bytes). */
|
---|
649 |
|
---|
650 | typedef struct cpu_desc_list {
|
---|
651 | struct cpu_desc_list *next;
|
---|
652 | int isa;
|
---|
653 | int mach;
|
---|
654 | int endian;
|
---|
655 | CGEN_CPU_DESC cd;
|
---|
656 | } cpu_desc_list;
|
---|
657 |
|
---|
658 | int
|
---|
659 | print_insn_ip2k (pc, info)
|
---|
660 | bfd_vma pc;
|
---|
661 | disassemble_info *info;
|
---|
662 | {
|
---|
663 | static cpu_desc_list *cd_list = 0;
|
---|
664 | cpu_desc_list *cl = 0;
|
---|
665 | static CGEN_CPU_DESC cd = 0;
|
---|
666 | static int prev_isa;
|
---|
667 | static int prev_mach;
|
---|
668 | static int prev_endian;
|
---|
669 | int length;
|
---|
670 | int isa,mach;
|
---|
671 | int endian = (info->endian == BFD_ENDIAN_BIG
|
---|
672 | ? CGEN_ENDIAN_BIG
|
---|
673 | : CGEN_ENDIAN_LITTLE);
|
---|
674 | enum bfd_architecture arch;
|
---|
675 |
|
---|
676 | /* ??? gdb will set mach but leave the architecture as "unknown" */
|
---|
677 | #ifndef CGEN_BFD_ARCH
|
---|
678 | #define CGEN_BFD_ARCH bfd_arch_ip2k
|
---|
679 | #endif
|
---|
680 | arch = info->arch;
|
---|
681 | if (arch == bfd_arch_unknown)
|
---|
682 | arch = CGEN_BFD_ARCH;
|
---|
683 |
|
---|
684 | /* There's no standard way to compute the machine or isa number
|
---|
685 | so we leave it to the target. */
|
---|
686 | #ifdef CGEN_COMPUTE_MACH
|
---|
687 | mach = CGEN_COMPUTE_MACH (info);
|
---|
688 | #else
|
---|
689 | mach = info->mach;
|
---|
690 | #endif
|
---|
691 |
|
---|
692 | #ifdef CGEN_COMPUTE_ISA
|
---|
693 | isa = CGEN_COMPUTE_ISA (info);
|
---|
694 | #else
|
---|
695 | isa = info->insn_sets;
|
---|
696 | #endif
|
---|
697 |
|
---|
698 | /* If we've switched cpu's, try to find a handle we've used before */
|
---|
699 | if (cd
|
---|
700 | && (isa != prev_isa
|
---|
701 | || mach != prev_mach
|
---|
702 | || endian != prev_endian))
|
---|
703 | {
|
---|
704 | cd = 0;
|
---|
705 | for (cl = cd_list; cl; cl = cl->next)
|
---|
706 | {
|
---|
707 | if (cl->isa == isa &&
|
---|
708 | cl->mach == mach &&
|
---|
709 | cl->endian == endian)
|
---|
710 | {
|
---|
711 | cd = cl->cd;
|
---|
712 | break;
|
---|
713 | }
|
---|
714 | }
|
---|
715 | }
|
---|
716 |
|
---|
717 | /* If we haven't initialized yet, initialize the opcode table. */
|
---|
718 | if (! cd)
|
---|
719 | {
|
---|
720 | const bfd_arch_info_type *arch_type = bfd_lookup_arch (arch, mach);
|
---|
721 | const char *mach_name;
|
---|
722 |
|
---|
723 | if (!arch_type)
|
---|
724 | abort ();
|
---|
725 | mach_name = arch_type->printable_name;
|
---|
726 |
|
---|
727 | prev_isa = isa;
|
---|
728 | prev_mach = mach;
|
---|
729 | prev_endian = endian;
|
---|
730 | cd = ip2k_cgen_cpu_open (CGEN_CPU_OPEN_ISAS, prev_isa,
|
---|
731 | CGEN_CPU_OPEN_BFDMACH, mach_name,
|
---|
732 | CGEN_CPU_OPEN_ENDIAN, prev_endian,
|
---|
733 | CGEN_CPU_OPEN_END);
|
---|
734 | if (!cd)
|
---|
735 | abort ();
|
---|
736 |
|
---|
737 | /* save this away for future reference */
|
---|
738 | cl = xmalloc (sizeof (struct cpu_desc_list));
|
---|
739 | cl->cd = cd;
|
---|
740 | cl->isa = isa;
|
---|
741 | cl->mach = mach;
|
---|
742 | cl->endian = endian;
|
---|
743 | cl->next = cd_list;
|
---|
744 | cd_list = cl;
|
---|
745 |
|
---|
746 | ip2k_cgen_init_dis (cd);
|
---|
747 | }
|
---|
748 |
|
---|
749 | /* We try to have as much common code as possible.
|
---|
750 | But at this point some targets need to take over. */
|
---|
751 | /* ??? Some targets may need a hook elsewhere. Try to avoid this,
|
---|
752 | but if not possible try to move this hook elsewhere rather than
|
---|
753 | have two hooks. */
|
---|
754 | length = CGEN_PRINT_INSN (cd, pc, info);
|
---|
755 | if (length > 0)
|
---|
756 | return length;
|
---|
757 | if (length < 0)
|
---|
758 | return -1;
|
---|
759 |
|
---|
760 | (*info->fprintf_func) (info->stream, UNKNOWN_INSN_MSG);
|
---|
761 | return cd->default_insn_bitsize / 8;
|
---|
762 | }
|
---|