1 /* Disassemble SH instructions.
2 Copyright (C) 1993, 1995 Free Software Foundation, Inc.
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.
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.
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. */
28 print_insn_shx(memaddr, info)
30 struct disassemble_info *info;
32 fprintf_ftype fprintf = info->fprintf_func;
33 void *stream = info->stream;
34 unsigned char insn[2];
35 unsigned char nibs[4];
40 status = info->read_memory_func(memaddr, insn, 2, info);
44 info->memory_error_func(status, memaddr, info);
50 if (info->flags & LITTLE_BIT)
52 nibs[0] = (insn[1] >> 4) & 0xf;
53 nibs[1] = insn[1] & 0xf;
55 nibs[2] = (insn[0] >> 4) & 0xf;
56 nibs[3] = insn[0] & 0xf;
60 nibs[0] = (insn[0] >> 4) & 0xf;
61 nibs[1] = insn[0] & 0xf;
63 nibs[2] = (insn[1] >> 4) & 0xf;
64 nibs[3] = insn[1] & 0xf;
67 for (op = sh_table; op->name; op++)
73 for (n = 0; n < 4; n++) {
74 int i = op->nibbles[n];
77 if (nibs[n] == i) continue;
83 imm = (nibs[2] << 4) | (nibs[3]);
86 imm = ((char)imm) * 2 + 4 ;
90 imm = ((nibs[1]) << 8) | (nibs[2] << 4) | (nibs[3]);
107 imm = (nibs[2] << 4) | nibs[3];
110 imm = ((nibs[2] << 4) | nibs[3]) <<1;
116 imm = ((nibs[2] << 4) | nibs[3]) <<2;
121 imm = ((nibs[2] << 4) | nibs[3]) <<1;
124 imm = ((nibs[2] << 4) | nibs[3]) <<2;
127 imm = (nibs[2] << 4) | (nibs[3]);
144 fprintf(stream,"%s\t", op->name);
145 for (n = 0; n < 3 && op->arg[n] != A_END; n++)
147 if (n && op->arg[1] != A_END)
152 fprintf(stream,"#%d", (char)(imm));
155 fprintf(stream,"r0");
158 fprintf(stream,"r%d", rn);
161 fprintf(stream,"@r%d+", rn);
164 fprintf(stream,"@-r%d", rn);
167 fprintf(stream,"@r%d", rn);
170 fprintf(stream,"@(%d,r%d)",imm, rn);
173 fprintf(stream,"r%d", rm);
176 fprintf(stream,"@r%d+", rm);
179 fprintf(stream,"@-r%d", rm);
182 fprintf(stream,"@r%d", rm);
185 fprintf(stream,"@(%d,r%d)",imm, rm);
188 fprintf(stream,"0x%0x", imm+ 4+(memaddr&relmask));
191 fprintf(stream,"@(r0,r%d)", rn);
194 fprintf(stream,"@(r0,r%d)", rm);
197 fprintf(stream,"@(%d,gbr)",imm);
200 fprintf(stream,"@(r0,gbr)");
204 (*info->print_address_func) (imm + memaddr, info);
207 fprintf(stream,"sr");
210 fprintf(stream,"gbr");
213 fprintf(stream,"vbr");
216 fprintf(stream,"ssr");
219 fprintf(stream,"spc");
222 fprintf(stream,"mach");
225 fprintf(stream,"macl");
228 fprintf(stream,"pr");
230 /* start-sanitize-sh3e */
232 fprintf(stream,"fr%d", rn);
235 fprintf(stream,"fr%d", rm);
239 fprintf(stream,"fpscr");
243 fprintf(stream,"fpul");
246 fprintf(stream,"fr0");
248 /* end-sanitize-sh3e */
254 if (!(info->flags & 1)
255 && (op->name[0] == 'j'
256 || (op->name[0] == 'b'
257 && (op->name[1] == 'r'
258 || op->name[1] == 's'))
259 || (op->name[0] == 'r' && op->name[1] == 't')
260 || (op->name[0] == 'b' && op->name[2] == '.')))
263 fprintf(stream,"\t(slot "); print_insn_shx(memaddr +2, info);
274 fprintf(stream,".word 0x%x%x%x%x", nibs[0], nibs[1], nibs[2], nibs[3]);
280 print_insn_shl(memaddr, info)
282 struct disassemble_info *info;
285 info->flags = LITTLE_BIT;
286 r =print_insn_shx (memaddr, info);
291 print_insn_sh(memaddr, info)
293 struct disassemble_info *info;
297 r =print_insn_shx (memaddr, info);