Add support for displaying disassembled Thumb instrucitons.
[external/binutils.git] / opcodes / disassemble.c
1 /* Select disassembly routine for specified architecture.
2    Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
17
18 #include "ansidecl.h"
19 #include "dis-asm.h"
20
21 #ifdef ARCH_all
22 #define ARCH_a29k
23 #define ARCH_alpha
24 #define ARCH_arc
25 #define ARCH_arm
26 #define ARCH_d10v
27 /* start-sanitize-d30v */
28 #define ARCH_d30v
29 /* end-sanitize-d30v */
30 #define ARCH_h8300
31 #define ARCH_h8500
32 #define ARCH_hppa
33 #define ARCH_i386
34 #define ARCH_i960
35 #define ARCH_m32r
36 #define ARCH_m68k
37 #define ARCH_m88k
38 #define ARCH_mips
39 #define ARCH_mn10200
40 #define ARCH_mn10300
41 #define ARCH_ns32k
42 #define ARCH_powerpc
43 #define ARCH_rs6000
44 #define ARCH_sh
45 #define ARCH_sparc
46 /* start-sanitize-tic80 */
47 #define ARCH_tic80
48 /* end-sanitize-tic80 */
49 #define ARCH_v850
50 #define ARCH_w65
51 #define ARCH_z8k
52 #endif
53
54 disassembler_ftype
55 disassembler (abfd)
56      bfd *abfd;
57 {
58   enum bfd_architecture a = bfd_get_arch (abfd);
59   disassembler_ftype disassemble;
60
61   switch (a)
62     {
63       /* If you add a case to this table, also add it to the
64          ARCH_all definition right above this function.  */
65 #ifdef ARCH_a29k
66     case bfd_arch_a29k:
67       /* As far as I know we only handle big-endian 29k objects.  */
68       disassemble = print_insn_big_a29k;
69       break;
70 #endif
71 #ifdef ARCH_alpha
72     case bfd_arch_alpha:
73       disassemble = print_insn_alpha;
74       break;
75 #endif
76 #ifdef ARCH_arc
77     case bfd_arch_arc:
78       {
79         disassemble = arc_get_disassembler (bfd_get_mach (abfd),
80                                             bfd_big_endian (abfd));
81         break;
82       }
83 #endif
84 #ifdef ARCH_arm
85     case bfd_arch_arm:
86       if (bfd_big_endian (abfd))
87         disassemble = print_insn_big_arm;
88       else
89         disassemble = print_insn_little_arm;
90       break;
91 #endif
92 #ifdef ARCH_d10v
93     case bfd_arch_d10v:
94       disassemble = print_insn_d10v;
95       break;
96 #endif
97 /* start-sanitize-d30v */
98 #ifdef ARCH_d30v
99     case bfd_arch_d30v:
100       disassemble = print_insn_d30v;
101       break;
102 #endif
103 /* end-sanitize-d30v */
104 #ifdef ARCH_h8300
105     case bfd_arch_h8300:
106       if (bfd_get_mach(abfd) == bfd_mach_h8300h)
107         disassemble = print_insn_h8300h;
108       else if (bfd_get_mach(abfd) == bfd_mach_h8300s)
109         disassemble = print_insn_h8300s;
110       else 
111         disassemble = print_insn_h8300;
112       break;
113 #endif
114 #ifdef ARCH_h8500
115     case bfd_arch_h8500:
116       disassemble = print_insn_h8500;
117       break;
118 #endif
119 #ifdef ARCH_hppa
120     case bfd_arch_hppa:
121       disassemble = print_insn_hppa;
122       break;
123 #endif
124 #ifdef ARCH_i386
125     case bfd_arch_i386:
126       disassemble = print_insn_i386;
127       break;
128 #endif
129 #ifdef ARCH_i960
130     case bfd_arch_i960:
131       disassemble = print_insn_i960;
132       break;
133 #endif
134 #ifdef ARCH_m32r
135     case bfd_arch_m32r:
136       disassemble = print_insn_m32r;
137       break;
138 #endif
139 #ifdef ARCH_m68k
140     case bfd_arch_m68k:
141       disassemble = print_insn_m68k;
142       break;
143 #endif
144 #ifdef ARCH_m88k
145     case bfd_arch_m88k:
146       disassemble = print_insn_m88k;
147       break;
148 #endif
149 #ifdef ARCH_ns32k
150     case bfd_arch_ns32k:
151       disassemble = print_insn_ns32k;
152       break;
153 #endif
154 #ifdef ARCH_mips
155     case bfd_arch_mips:
156       if (bfd_big_endian (abfd))
157         disassemble = print_insn_big_mips;
158       else
159         disassemble = print_insn_little_mips;
160       break;
161 #endif
162 #ifdef ARCH_mn10200
163     case bfd_arch_mn10200:
164       disassemble = print_insn_mn10200;
165       break;
166 #endif
167 #ifdef ARCH_mn10300
168     case bfd_arch_mn10300:
169       disassemble = print_insn_mn10300;
170       break;
171 #endif
172 #ifdef ARCH_powerpc
173     case bfd_arch_powerpc:
174       if (bfd_big_endian (abfd))
175         disassemble = print_insn_big_powerpc;
176       else
177         disassemble = print_insn_little_powerpc;
178       break;
179 #endif
180 #ifdef ARCH_rs6000
181     case bfd_arch_rs6000:
182       disassemble = print_insn_rs6000;
183       break;
184 #endif
185 #ifdef ARCH_sh
186     case bfd_arch_sh:
187       if (bfd_big_endian (abfd))
188         disassemble = print_insn_sh;
189       else
190         disassemble = print_insn_shl;
191       break;
192 #endif
193 #ifdef ARCH_sparc
194     case bfd_arch_sparc:
195       disassemble = print_insn_sparc;
196       break;
197 #endif
198 /* start-sanitize-tic80 */
199 #ifdef ARCH_tic80
200     case bfd_arch_tic80:
201       disassemble = print_insn_tic80;
202       break;
203 #endif
204 /* end-sanitize-tic80 */
205 #ifdef ARCH_v850
206     case bfd_arch_v850:
207       disassemble = print_insn_v850;
208       break;
209 #endif
210 #ifdef ARCH_w65
211     case bfd_arch_w65:
212       disassemble = print_insn_w65;
213       break;
214 #endif
215 #ifdef ARCH_z8k
216     case bfd_arch_z8k:
217       if (bfd_get_mach(abfd) == bfd_mach_z8001)
218         disassemble = print_insn_z8001;
219       else 
220         disassemble = print_insn_z8002;
221       break;
222 #endif
223     default:
224       return 0;
225     }
226   return disassemble;
227 }
228
229 /* Notify the disassembler of the address associated with the
230    instruction being decoded: */
231
232 void
233 disasm_symaddr (sym, info)
234      asymbol *sym;
235      disassemble_info *info;
236 {
237 #ifdef ARCH_arm
238   /* decide if symbol is thumb or not */
239   if (info->flavour == bfd_target_coff_flavour)
240     {
241 /* This is not ideal including these here, since we may not be
242    building a COFF targetted world at all... so coffsymbol() may not
243    be available. (TO BE SORTED OUT) */
244 #include "coff/internal.h"
245 #include "libcoff.h"
246       coff_symbol_type *cs = coffsymbol (sym);
247       if (   cs->native->u.syment.n_sclass == C_THUMBEXT
248           || cs->native->u.syment.n_sclass == C_THUMBSTAT
249           || cs->native->u.syment.n_sclass == C_THUMBLABEL
250           || cs->native->u.syment.n_sclass == C_THUMBEXTFUNC
251           || cs->native->u.syment.n_sclass == C_THUMBSTATFUNC)
252        info->flags |= 0x1;
253       else
254        info->flags &= ~0x1;
255     }
256 #endif
257   /* Do nothing for other architectures at the moment */
258 }