1 /* pj-dis.c -- Disassemble picoJava instructions.
2 Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3 Contributed by Steve Chamberlain, of Transmeta (sac@pobox.com).
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 #include "opcode/pj.h"
24 extern const pj_opc_info_t pj_opc_info[512];
26 static int get_int PARAMS ((bfd_vma, int *, struct disassemble_info *));
30 get_int (memaddr, iptr, info)
33 struct disassemble_info *info;
35 unsigned char ival[4];
37 int status = info->read_memory_func (memaddr, ival, 4, info);
39 *iptr = (ival[0] << 24)
48 print_insn_pj (addr, info)
50 struct disassemble_info *info;
52 fprintf_ftype fprintf_fn = info->fprintf_func;
53 void *stream = info->stream;
57 if ((status = info->read_memory_func (addr, &opcode, 1, info)))
63 if ((status = info->read_memory_func (addr + 1, &byte_2, 1, info)))
65 fprintf_fn (stream, "%s\t", pj_opc_info[opcode + byte_2].u.name);
71 int insn_start = addr;
72 const pj_opc_info_t *op = &pj_opc_info[opcode];
75 fprintf_fn (stream, "%s", op->u.name);
77 /* The tableswitch instruction is followed by the default
78 address, low value, high value and the destinations. */
80 if (strcmp (op->u.name, "tableswitch") == 0)
86 addr = (addr + 3) & ~3;
87 if ((status = get_int (addr, &val, info)))
90 fprintf_fn (stream, " default: ");
91 (*info->print_address_func) (val + insn_start, info);
94 if ((status = get_int (addr, &lowval, info)))
98 if ((status = get_int (addr, &highval, info)))
102 while (lowval <= highval)
104 if ((status = get_int (addr, &val, info)))
106 fprintf_fn (stream, " %d:[", lowval);
107 (*info->print_address_func) (val + insn_start, info);
108 fprintf_fn (stream, " ]");
112 return addr - insn_start;
115 /* The lookupswitch instruction is followed by the default
116 address, element count and pairs of values and
119 if (strcmp (op->u.name, "lookupswitch") == 0)
124 addr = (addr + 3) & ~3;
125 if ((status = get_int (addr, &val, info)))
129 fprintf_fn (stream, " default: ");
130 (*info->print_address_func) (val + insn_start, info);
132 if ((status = get_int (addr, &count, info)))
138 if ((status = get_int (addr, &val, info)))
141 fprintf_fn (stream, " %d:[", val);
143 if ((status = get_int (addr, &val, info)))
147 (*info->print_address_func) (val + insn_start, info);
148 fprintf_fn (stream, " ]");
150 return addr - insn_start;
152 for (a = 0; op->arg[a]; a++)
154 unsigned char data[4];
157 int size = ASIZE (op->arg[a]);
159 if ((status = info->read_memory_func (addr, data, size, info)))
162 val = (UNS (op->arg[0]) || ((data[0] & 0x80) == 0)) ? 0 : -1;
164 for (i = 0; i < size; i++)
165 val = (val << 8) | (data[i] & 0xff);
167 if (PCREL (op->arg[a]))
168 (*info->print_address_func) (val + insn_start, info);
170 fprintf_fn (stream, "%s%d", sep, val);
179 info->memory_error_func (status, addr, info);