1 /* Disassemble SH instructions.
2 Copyright (C) 1993, 94, 95, 96, 1997 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_fn = 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);
48 if (info->flags & LITTLE_BIT)
50 nibs[0] = (insn[1] >> 4) & 0xf;
51 nibs[1] = insn[1] & 0xf;
53 nibs[2] = (insn[0] >> 4) & 0xf;
54 nibs[3] = insn[0] & 0xf;
58 nibs[0] = (insn[0] >> 4) & 0xf;
59 nibs[1] = insn[0] & 0xf;
61 nibs[2] = (insn[1] >> 4) & 0xf;
62 nibs[3] = insn[1] & 0xf;
65 for (op = sh_table; op->name; op++)
73 for (n = 0; n < 4; n++)
75 int i = op->nibbles[n];
86 imm = (nibs[2] << 4) | (nibs[3]);
89 imm = ((char)imm) * 2 + 4 ;
92 imm = ((nibs[1]) << 8) | (nibs[2] << 4) | (nibs[3]);
107 imm = (nibs[2] << 4) | nibs[3];
110 imm = ((nibs[2] << 4) | nibs[3]) <<1;
114 imm = ((nibs[2] << 4) | nibs[3]) <<2;
118 imm = ((nibs[2] << 4) | nibs[3]) <<1;
121 imm = ((nibs[2] << 4) | nibs[3]) <<2;
124 imm = (nibs[2] << 4) | (nibs[3]);
144 fprintf_fn (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)
148 fprintf_fn (stream, ",");
152 fprintf_fn (stream, "#%d", (char)(imm));
155 fprintf_fn (stream, "r0");
158 fprintf_fn (stream, "r%d", rn);
161 fprintf_fn (stream, "@r%d+", rn);
164 fprintf_fn (stream, "@-r%d", rn);
167 fprintf_fn (stream, "@r%d", rn);
170 fprintf_fn (stream, "@(%d,r%d)", imm, rn);
173 fprintf_fn (stream, "r%d", rm);
176 fprintf_fn (stream, "@r%d+", rm);
179 fprintf_fn (stream, "@-r%d", rm);
182 fprintf_fn (stream, "@r%d", rm);
185 fprintf_fn (stream, "@(%d,r%d)", imm, rm);
188 fprintf_fn (stream, "r%d_bank", rb);
191 fprintf_fn (stream, "0x%0x", imm + 4 + (memaddr & relmask));
194 fprintf_fn (stream, "@(r0,r%d)", rn);
197 fprintf_fn (stream, "@(r0,r%d)", rm);
200 fprintf_fn (stream, "@(%d,gbr)",imm);
203 fprintf_fn (stream, "@(r0,gbr)");
207 (*info->print_address_func) (imm + memaddr, info);
210 fprintf_fn (stream, "sr");
213 fprintf_fn (stream, "gbr");
216 fprintf_fn (stream, "vbr");
219 fprintf_fn (stream, "ssr");
222 fprintf_fn (stream, "spc");
225 fprintf_fn (stream, "mach");
228 fprintf_fn (stream ,"macl");
231 fprintf_fn (stream, "pr");
234 fprintf_fn (stream, "fr%d", rn);
237 fprintf_fn (stream, "fr%d", rm);
241 fprintf_fn (stream, "fpscr");
245 fprintf_fn (stream, "fpul");
248 fprintf_fn (stream, "fr0");
256 if (!(info->flags & 1)
257 && (op->name[0] == 'j'
258 || (op->name[0] == 'b'
259 && (op->name[1] == 'r'
260 || op->name[1] == 's'))
261 || (op->name[0] == 'r' && op->name[1] == 't')
262 || (op->name[0] == 'b' && op->name[2] == '.')))
265 fprintf_fn (stream, "\t(slot ");
266 print_insn_shx (memaddr + 2, info);
268 fprintf_fn (stream, ")");
277 fprintf_fn (stream, ".word 0x%x%x%x%x", nibs[0], nibs[1], nibs[2], nibs[3]);
282 print_insn_shl (memaddr, info)
284 struct disassemble_info *info;
288 info->flags = LITTLE_BIT;
289 r = print_insn_shx (memaddr, info);
294 print_insn_sh (memaddr, info)
296 struct disassemble_info *info;
301 r = print_insn_shx (memaddr, info);