Back to index

cell-binutils  2.17cvs20070401
disassemble.c
Go to the documentation of this file.
00001 /* Select disassembly routine for specified architecture.
00002    Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
00003    2004, 2005, 2006 Free Software Foundation, Inc.
00004 
00005    This program is free software; you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published by
00007    the Free Software Foundation; either version 2 of the License, or
00008    (at your option) any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014 
00015    You should have received a copy of the GNU General Public License
00016    along with this program; if not, write to the Free Software
00017    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00018 
00019 #include "sysdep.h"
00020 #include "dis-asm.h"
00021 
00022 #ifdef ARCH_all
00023 #define ARCH_alpha
00024 #define ARCH_arc
00025 #define ARCH_arm
00026 #define ARCH_avr
00027 #define ARCH_bfin
00028 #define ARCH_cris
00029 #define ARCH_crx
00030 #define ARCH_d10v
00031 #define ARCH_d30v
00032 #define ARCH_dlx
00033 #define ARCH_fr30
00034 #define ARCH_frv
00035 #define ARCH_h8300
00036 #define ARCH_h8500
00037 #define ARCH_hppa
00038 #define ARCH_i370
00039 #define ARCH_i386
00040 #define ARCH_i860
00041 #define ARCH_i960
00042 #define ARCH_ia64
00043 #define ARCH_ip2k
00044 #define ARCH_iq2000
00045 #define ARCH_m32c
00046 #define ARCH_m32r
00047 #define ARCH_m68hc11
00048 #define ARCH_m68hc12
00049 #define ARCH_m68k
00050 #define ARCH_m88k
00051 #define ARCH_maxq
00052 #define ARCH_mcore
00053 #define ARCH_mep
00054 #define ARCH_mips
00055 #define ARCH_mmix
00056 #define ARCH_mn10200
00057 #define ARCH_mn10300
00058 #define ARCH_mt
00059 #define ARCH_msp430
00060 #define ARCH_ns32k
00061 #define ARCH_openrisc
00062 #define ARCH_or32
00063 #define ARCH_pdp11
00064 #define ARCH_pj
00065 #define ARCH_powerpc
00066 #define ARCH_rs6000
00067 #define ARCH_s390
00068 #define ARCH_score
00069 #define ARCH_sh
00070 #define ARCH_sparc
00071 #define ARCH_spu
00072 #define ARCH_tic30
00073 #define ARCH_tic4x
00074 #define ARCH_tic54x
00075 #define ARCH_tic80
00076 #define ARCH_v850
00077 #define ARCH_vax
00078 #define ARCH_w65
00079 #define ARCH_xstormy16
00080 #define ARCH_xc16x
00081 #define ARCH_xtensa
00082 #define ARCH_z80
00083 #define ARCH_z8k
00084 #define INCLUDE_SHMEDIA
00085 #endif
00086 
00087 #ifdef ARCH_m32c
00088 #include "m32c-desc.h"
00089 #endif
00090 
00091 disassembler_ftype
00092 disassembler (abfd)
00093      bfd *abfd;
00094 {
00095   enum bfd_architecture a = bfd_get_arch (abfd);
00096   disassembler_ftype disassemble;
00097 
00098   switch (a)
00099     {
00100       /* If you add a case to this table, also add it to the
00101         ARCH_all definition right above this function.  */
00102 #ifdef ARCH_alpha
00103     case bfd_arch_alpha:
00104       disassemble = print_insn_alpha;
00105       break;
00106 #endif
00107 #ifdef ARCH_arc
00108     case bfd_arch_arc:
00109       {
00110        disassemble = arc_get_disassembler (abfd);
00111        break;
00112       }
00113 #endif
00114 #ifdef ARCH_arm
00115     case bfd_arch_arm:
00116       if (bfd_big_endian (abfd))
00117        disassemble = print_insn_big_arm;
00118       else
00119        disassemble = print_insn_little_arm;
00120       break;
00121 #endif
00122 #ifdef ARCH_avr
00123     case bfd_arch_avr:
00124       disassemble = print_insn_avr;
00125       break;
00126 #endif
00127 #ifdef ARCH_bfin
00128     case bfd_arch_bfin:
00129       disassemble = print_insn_bfin;
00130       break;
00131 #endif
00132 #ifdef ARCH_cris
00133     case bfd_arch_cris:
00134       disassemble = cris_get_disassembler (abfd);
00135       break;
00136 #endif
00137 #ifdef ARCH_crx
00138     case bfd_arch_crx:
00139       disassemble = print_insn_crx;
00140       break;
00141 #endif
00142 #ifdef ARCH_d10v
00143     case bfd_arch_d10v:
00144       disassemble = print_insn_d10v;
00145       break;
00146 #endif
00147 #ifdef ARCH_d30v
00148     case bfd_arch_d30v:
00149       disassemble = print_insn_d30v;
00150       break;
00151 #endif
00152 #ifdef ARCH_dlx
00153     case bfd_arch_dlx:
00154       /* As far as I know we only handle big-endian DLX objects.  */
00155       disassemble = print_insn_dlx;
00156       break;
00157 #endif
00158 #ifdef ARCH_h8300
00159     case bfd_arch_h8300:
00160       if (bfd_get_mach (abfd) == bfd_mach_h8300h
00161          || bfd_get_mach (abfd) == bfd_mach_h8300hn)
00162        disassemble = print_insn_h8300h;
00163       else if (bfd_get_mach (abfd) == bfd_mach_h8300s
00164               || bfd_get_mach (abfd) == bfd_mach_h8300sn
00165               || bfd_get_mach (abfd) == bfd_mach_h8300sx
00166               || bfd_get_mach (abfd) == bfd_mach_h8300sxn)
00167        disassemble = print_insn_h8300s;
00168       else
00169        disassemble = print_insn_h8300;
00170       break;
00171 #endif
00172 #ifdef ARCH_h8500
00173     case bfd_arch_h8500:
00174       disassemble = print_insn_h8500;
00175       break;
00176 #endif
00177 #ifdef ARCH_hppa
00178     case bfd_arch_hppa:
00179       disassemble = print_insn_hppa;
00180       break;
00181 #endif
00182 #ifdef ARCH_i370
00183     case bfd_arch_i370:
00184       disassemble = print_insn_i370;
00185       break;
00186 #endif
00187 #ifdef ARCH_i386
00188     case bfd_arch_i386:
00189       disassemble = print_insn_i386;
00190       break;
00191 #endif
00192 #ifdef ARCH_i860
00193     case bfd_arch_i860:
00194       disassemble = print_insn_i860;
00195       break;
00196 #endif
00197 #ifdef ARCH_i960
00198     case bfd_arch_i960:
00199       disassemble = print_insn_i960;
00200       break;
00201 #endif
00202 #ifdef ARCH_ia64
00203     case bfd_arch_ia64:
00204       disassemble = print_insn_ia64;
00205       break;
00206 #endif
00207 #ifdef ARCH_ip2k
00208     case bfd_arch_ip2k:
00209       disassemble = print_insn_ip2k;
00210       break;
00211 #endif
00212 #ifdef ARCH_fr30
00213     case bfd_arch_fr30:
00214       disassemble = print_insn_fr30;
00215       break;
00216 #endif
00217 #ifdef ARCH_m32r
00218     case bfd_arch_m32r:
00219       disassemble = print_insn_m32r;
00220       break;
00221 #endif
00222 #if defined(ARCH_m68hc11) || defined(ARCH_m68hc12)
00223     case bfd_arch_m68hc11:
00224       disassemble = print_insn_m68hc11;
00225       break;
00226     case bfd_arch_m68hc12:
00227       disassemble = print_insn_m68hc12;
00228       break;
00229 #endif
00230 #ifdef ARCH_m68k
00231     case bfd_arch_m68k:
00232       disassemble = print_insn_m68k;
00233       break;
00234 #endif
00235 #ifdef ARCH_m88k
00236     case bfd_arch_m88k:
00237       disassemble = print_insn_m88k;
00238       break;
00239 #endif
00240 #ifdef ARCH_maxq
00241     case bfd_arch_maxq:
00242       disassemble = print_insn_maxq_little;
00243       break;
00244 #endif
00245 #ifdef ARCH_mt
00246     case bfd_arch_mt:
00247       disassemble = print_insn_mt;
00248       break;
00249 #endif
00250 #ifdef ARCH_msp430
00251     case bfd_arch_msp430:
00252       disassemble = print_insn_msp430;
00253       break;
00254 #endif
00255 #ifdef ARCH_ns32k
00256     case bfd_arch_ns32k:
00257       disassemble = print_insn_ns32k;
00258       break;
00259 #endif
00260 #ifdef ARCH_mcore
00261     case bfd_arch_mcore:
00262       disassemble = print_insn_mcore;
00263       break;
00264 #endif
00265 #ifdef ARCH_mep
00266     case bfd_arch_mep:
00267       disassemble = print_insn_mep;
00268       break;
00269 #endif
00270 #ifdef ARCH_mips
00271     case bfd_arch_mips:
00272       if (bfd_big_endian (abfd))
00273        disassemble = print_insn_big_mips;
00274       else
00275        disassemble = print_insn_little_mips;
00276       break;
00277 #endif
00278 #ifdef ARCH_mmix
00279     case bfd_arch_mmix:
00280       disassemble = print_insn_mmix;
00281       break;
00282 #endif
00283 #ifdef ARCH_mn10200
00284     case bfd_arch_mn10200:
00285       disassemble = print_insn_mn10200;
00286       break;
00287 #endif
00288 #ifdef ARCH_mn10300
00289     case bfd_arch_mn10300:
00290       disassemble = print_insn_mn10300;
00291       break;
00292 #endif
00293 #ifdef ARCH_openrisc
00294     case bfd_arch_openrisc:
00295       disassemble = print_insn_openrisc;
00296       break;
00297 #endif
00298 #ifdef ARCH_or32
00299     case bfd_arch_or32:
00300       if (bfd_big_endian (abfd))
00301         disassemble = print_insn_big_or32;
00302       else
00303         disassemble = print_insn_little_or32;
00304       break;
00305 #endif
00306 #ifdef ARCH_pdp11
00307     case bfd_arch_pdp11:
00308       disassemble = print_insn_pdp11;
00309       break;
00310 #endif
00311 #ifdef ARCH_pj
00312     case bfd_arch_pj:
00313       disassemble = print_insn_pj;
00314       break;
00315 #endif
00316 #ifdef ARCH_powerpc
00317     case bfd_arch_powerpc:
00318       if (bfd_big_endian (abfd))
00319        disassemble = print_insn_big_powerpc;
00320       else
00321        disassemble = print_insn_little_powerpc;
00322       break;
00323 #endif
00324 #ifdef ARCH_rs6000
00325     case bfd_arch_rs6000:
00326       if (bfd_get_mach (abfd) == bfd_mach_ppc_620)
00327        disassemble = print_insn_big_powerpc;
00328       else
00329        disassemble = print_insn_rs6000;
00330       break;
00331 #endif
00332 #ifdef ARCH_s390
00333     case bfd_arch_s390:
00334       disassemble = print_insn_s390;
00335       break;
00336 #endif
00337 #ifdef ARCH_score
00338     case bfd_arch_score:
00339       if (bfd_big_endian (abfd))
00340         disassemble = print_insn_big_score;      
00341       else
00342         disassemble = print_insn_little_score; 
00343      break;
00344 #endif
00345 #ifdef ARCH_sh
00346     case bfd_arch_sh:
00347       disassemble = print_insn_sh;
00348       break;
00349 #endif
00350 #ifdef ARCH_sparc
00351     case bfd_arch_sparc:
00352       disassemble = print_insn_sparc;
00353       break;
00354 #endif
00355 #ifdef ARCH_spu
00356     case bfd_arch_spu:
00357       disassemble = print_insn_spu;
00358       break;
00359 #endif
00360 #ifdef ARCH_tic30
00361     case bfd_arch_tic30:
00362       disassemble = print_insn_tic30;
00363       break;
00364 #endif
00365 #ifdef ARCH_tic4x
00366     case bfd_arch_tic4x:
00367       disassemble = print_insn_tic4x;
00368       break;
00369 #endif
00370 #ifdef ARCH_tic54x
00371     case bfd_arch_tic54x:
00372       disassemble = print_insn_tic54x;
00373       break;
00374 #endif
00375 #ifdef ARCH_tic80
00376     case bfd_arch_tic80:
00377       disassemble = print_insn_tic80;
00378       break;
00379 #endif
00380 #ifdef ARCH_v850
00381     case bfd_arch_v850:
00382       disassemble = print_insn_v850;
00383       break;
00384 #endif
00385 #ifdef ARCH_w65
00386     case bfd_arch_w65:
00387       disassemble = print_insn_w65;
00388       break;
00389 #endif
00390 #ifdef ARCH_xstormy16
00391     case bfd_arch_xstormy16:
00392       disassemble = print_insn_xstormy16;
00393       break;
00394 #endif
00395 #ifdef ARCH_xc16x
00396     case bfd_arch_xc16x:
00397       disassemble = print_insn_xc16x;
00398       break;
00399 #endif
00400 #ifdef ARCH_xtensa
00401     case bfd_arch_xtensa:
00402       disassemble = print_insn_xtensa;
00403       break;
00404 #endif
00405 #ifdef ARCH_z80
00406     case bfd_arch_z80:
00407       disassemble = print_insn_z80;
00408       break;
00409 #endif
00410 #ifdef ARCH_z8k
00411     case bfd_arch_z8k:
00412       if (bfd_get_mach(abfd) == bfd_mach_z8001)
00413        disassemble = print_insn_z8001;
00414       else
00415        disassemble = print_insn_z8002;
00416       break;
00417 #endif
00418 #ifdef ARCH_vax
00419     case bfd_arch_vax:
00420       disassemble = print_insn_vax;
00421       break;
00422 #endif
00423 #ifdef ARCH_frv
00424     case bfd_arch_frv:
00425       disassemble = print_insn_frv;
00426       break;
00427 #endif
00428 #ifdef ARCH_iq2000
00429     case bfd_arch_iq2000:
00430       disassemble = print_insn_iq2000;
00431       break;
00432 #endif
00433 #ifdef ARCH_m32c
00434     case bfd_arch_m32c:
00435       disassemble = print_insn_m32c;
00436       break;
00437 #endif
00438     default:
00439       return 0;
00440     }
00441   return disassemble;
00442 }
00443 
00444 void
00445 disassembler_usage (stream)
00446      FILE * stream ATTRIBUTE_UNUSED;
00447 {
00448 #ifdef ARCH_arm
00449   print_arm_disassembler_options (stream);
00450 #endif
00451 #ifdef ARCH_mips
00452   print_mips_disassembler_options (stream);
00453 #endif
00454 #ifdef ARCH_powerpc
00455   print_ppc_disassembler_options (stream);
00456 #endif
00457 #ifdef ARCH_i386
00458   print_i386_disassembler_options (stream);
00459 #endif
00460 
00461   return;
00462 }
00463 
00464 void
00465 disassemble_init_for_target (struct disassemble_info * info)
00466 {
00467   if (info == NULL)
00468     return;
00469 
00470   switch (info->arch)
00471     {
00472 #ifdef ARCH_arm
00473     case bfd_arch_arm:
00474       info->symbol_is_valid = arm_symbol_is_valid;
00475       info->disassembler_needs_relocs = TRUE;
00476       break;
00477 #endif
00478 #ifdef ARCH_ia64
00479     case bfd_arch_ia64:
00480       info->skip_zeroes = 16;
00481       break;
00482 #endif
00483 #ifdef ARCH_tic4x
00484     case bfd_arch_tic4x:
00485       info->skip_zeroes = 32;
00486       break;
00487 #endif
00488 #ifdef ARCH_mep
00489     case bfd_arch_mep:
00490       info->skip_zeroes = 256;
00491       info->skip_zeroes_at_end = 0;
00492       break;
00493 #endif
00494 #ifdef ARCH_m32c
00495     case bfd_arch_m32c:
00496       info->endian = BFD_ENDIAN_BIG;
00497       if (! info->insn_sets)
00498        {
00499          info->insn_sets = cgen_bitset_create (ISA_MAX);
00500          if (info->mach == bfd_mach_m16c)
00501            cgen_bitset_set (info->insn_sets, ISA_M16C);
00502          else
00503            cgen_bitset_set (info->insn_sets, ISA_M32C);
00504        }
00505       break;
00506 #endif
00507     default:
00508       break;
00509     }
00510 }