Correct comment on first line of file.
[deliverable/binutils-gdb.git] / opcodes / sh-dis.c
1 /* Disassemble SH instructions.
2 Copyright (C) 1993, 1995 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 <stdio.h>
19 #define STATIC_TABLE
20 #define DEFINE_TABLE
21
22 #include "sh-opc.h"
23 #include "dis-asm.h"
24
25 #define LITTLE_BIT 2
26
27 static int
28 print_insn_shx(memaddr, info)
29 bfd_vma memaddr;
30 struct disassemble_info *info;
31 {
32 fprintf_ftype fprintf = info->fprintf_func;
33 void *stream = info->stream;
34 unsigned char insn[2];
35 unsigned char nibs[4];
36 int status;
37 int relmask = ~0;
38 sh_opcode_info *op;
39
40 status = info->read_memory_func(memaddr, insn, 2, info);
41
42 if (status != 0)
43 {
44 info->memory_error_func(status, memaddr, info);
45 return -1;
46 }
47
48
49
50 if (info->flags & LITTLE_BIT)
51 {
52 nibs[0] = (insn[1] >> 4) & 0xf;
53 nibs[1] = insn[1] & 0xf;
54
55 nibs[2] = (insn[0] >> 4) & 0xf;
56 nibs[3] = insn[0] & 0xf;
57 }
58 else
59 {
60 nibs[0] = (insn[0] >> 4) & 0xf;
61 nibs[1] = insn[0] & 0xf;
62
63 nibs[2] = (insn[1] >> 4) & 0xf;
64 nibs[3] = insn[1] & 0xf;
65 }
66
67 for (op = sh_table; op->name; op++)
68 {
69 int n;
70 int imm;
71 int rn;
72 int rm;
73 for (n = 0; n < 4; n++) {
74 int i = op->nibbles[n];
75 if (i < 16)
76 {
77 if (nibs[n] == i) continue;
78 goto fail;
79 }
80 switch (i)
81 {
82 case BRANCH_8:
83 imm = (nibs[2] << 4) | (nibs[3]);
84 if (imm & 0x80)
85 imm |= ~0xff;
86 imm = ((char)imm) * 2 + 4 ;
87 goto ok;
88
89 case BRANCH_12:
90 imm = ((nibs[1]) << 8) | (nibs[2] << 4) | (nibs[3]);
91 if (imm & 0x800)
92 imm |= ~0xfff;
93 imm = imm * 2 + 4;
94 goto ok;
95 case IMM_4:
96 imm = nibs[3];
97 goto ok;
98 case IMM_4BY2:
99 imm = nibs[3] <<1;
100 goto ok;
101 case IMM_4BY4:
102 imm = nibs[3] <<2;
103 goto ok;
104
105
106 case IMM_8:
107 imm = (nibs[2] << 4) | nibs[3];
108 goto ok;
109 case PCRELIMM_8BY2:
110 imm = ((nibs[2] << 4) | nibs[3]) <<1;
111 relmask = ~1;
112
113 goto ok;
114
115 case PCRELIMM_8BY4:
116 imm = ((nibs[2] << 4) | nibs[3]) <<2;
117 relmask = ~3;
118 goto ok;
119
120 case IMM_8BY2:
121 imm = ((nibs[2] << 4) | nibs[3]) <<1;
122 goto ok;
123 case IMM_8BY4:
124 imm = ((nibs[2] << 4) | nibs[3]) <<2;
125 goto ok;
126 case DISP_8:
127 imm = (nibs[2] << 4) | (nibs[3]);
128 goto ok;
129 case DISP_4:
130 imm = nibs[3];
131 goto ok;
132 case REG_N:
133 rn = nibs[n];
134 break;
135 case REG_M:
136 rm = nibs[n];
137 break;
138 default:
139 abort();
140 }
141
142 }
143 ok:
144 fprintf(stream,"%s\t", op->name);
145 for (n = 0; n < 2 && op->arg[n] != A_END; n++)
146 {
147 if (n && op->arg[1] != A_END)
148 fprintf(stream,",");
149 switch (op->arg[n])
150 {
151 case A_IMM:
152 fprintf(stream,"#%d", (char)(imm));
153 break;
154 case A_R0:
155 fprintf(stream,"r0");
156 break;
157 case A_REG_N:
158 fprintf(stream,"r%d", rn);
159 break;
160 case A_INC_N:
161 fprintf(stream,"@r%d+", rn);
162 break;
163 case A_DEC_N:
164 fprintf(stream,"@-r%d", rn);
165 break;
166 case A_IND_N:
167 fprintf(stream,"@r%d", rn);
168 break;
169 case A_DISP_REG_N:
170 fprintf(stream,"@(%d,r%d)",imm, rn);
171 break;
172 case A_REG_M:
173 fprintf(stream,"r%d", rm);
174 break;
175 case A_INC_M:
176 fprintf(stream,"@r%d+", rm);
177 break;
178 case A_DEC_M:
179 fprintf(stream,"@-r%d", rm);
180 break;
181 case A_IND_M:
182 fprintf(stream,"@r%d", rm);
183 break;
184 case A_DISP_REG_M:
185 fprintf(stream,"@(%d,r%d)",imm, rm);
186 break;
187 case A_DISP_PC:
188 fprintf(stream,"0x%0x", imm+ 4+(memaddr&relmask));
189 break;
190 case A_IND_R0_REG_N:
191 fprintf(stream,"@(r0,r%d)", rn);
192 break;
193 case A_IND_R0_REG_M:
194 fprintf(stream,"@(r0,r%d)", rm);
195 break;
196 case A_DISP_GBR:
197 fprintf(stream,"@(%d,gbr)",imm);
198 break;
199 case A_R0_GBR:
200 fprintf(stream,"@(r0,gbr)");
201 break;
202 case A_BDISP12:
203 case A_BDISP8:
204 (*info->print_address_func) (imm + memaddr, info);
205 break;
206 case A_SR:
207 fprintf(stream,"sr");
208 break;
209 case A_GBR:
210 fprintf(stream,"gbr");
211 break;
212 case A_VBR:
213 fprintf(stream,"vbr");
214 break;
215 case A_MACH:
216 fprintf(stream,"mach");
217 break;
218 case A_MACL:
219 fprintf(stream,"macl");
220 break;
221 case A_PR:
222 fprintf(stream,"pr");
223 break;
224 /* start-sanitize-sh3e */
225 case F_REG_N:
226 fprintf(stream,"fr%d", rn);
227 break;
228 case F_REG_M:
229 fprintf(stream,"fr%d", rm);
230 break;
231 case FPSCR_M:
232 case FPSCR_N:
233 fprintf(stream,"fpscr");
234 break;
235 case FPUL_M:
236 case FPUL_N:
237 fprintf(stream,"fpul");
238 break;
239 /* end-sanitize-sh3e */
240 default:
241 abort();
242 }
243
244 }
245 if (!(info->flags & 1)
246 && (op->name[0] == 'j'
247 || (op->name[0] == 'b'
248 && (op->name[1] == 'r'
249 || op->name[1] == 's'))
250 || (op->name[0] == 'r' && op->name[1] == 't')
251 || (op->name[0] == 'b' && op->name[2] == '.')))
252 {
253 info->flags |= 1;
254 fprintf(stream,"\t(slot "); print_insn_shx(memaddr +2, info);
255 info->flags &= ~1;
256 fprintf(stream,")");
257 return 4;
258 }
259
260 return 2;
261 fail:
262 ;
263
264 }
265 fprintf(stream,".word 0x%x%x%x%x", nibs[0], nibs[1], nibs[2], nibs[3]);
266 return 2;
267 }
268
269
270 int
271 print_insn_shl(memaddr, info)
272 bfd_vma memaddr;
273 struct disassemble_info *info;
274 {
275 int r;
276 info->flags = LITTLE_BIT;
277 r =print_insn_shx (memaddr, info);
278 return r;
279 }
280
281 int
282 print_insn_sh(memaddr, info)
283 bfd_vma memaddr;
284 struct disassemble_info *info;
285 {
286 int r;
287 info->flags = 0;
288 r =print_insn_shx (memaddr, info);
289 return r;
290 }
This page took 0.043121 seconds and 4 git commands to generate.