1 /* pj-dis.c -- Disassemble picoJava instructions.
2 Copyright (C) 1999 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. */
22 #include "opcode/pj.h"
25 extern const pj_opc_info_t pj_opc_info
[512];
27 static int get_int (memaddr
, iptr
, info
)
30 struct disassemble_info
*info
;
32 unsigned char ival
[4];
34 int status
= info
->read_memory_func (memaddr
, ival
, 4, info
);
36 *iptr
= (ival
[0] << 24)
45 print_insn_pj (addr
, info
)
47 struct disassemble_info
*info
;
49 fprintf_ftype fprintf_fn
= info
->fprintf_func
;
50 void *stream
= info
->stream
;
54 if ((status
= info
->read_memory_func (addr
, &opcode
, 1, info
)))
60 if ((status
= info
->read_memory_func (addr
+ 1, &byte_2
, 1, info
)))
62 fprintf_fn (stream
, "%s\t", pj_opc_info
[opcode
+ byte_2
].name
);
68 int insn_start
= addr
;
69 const pj_opc_info_t
*op
= &pj_opc_info
[opcode
];
72 fprintf_fn (stream
, "%s", op
->name
);
74 /* The tableswitch instruction is followed by the default
75 address, low value, high value and the destinations. */
77 if (strcmp (op
->name
, "tableswitch") == 0)
83 addr
= (addr
+ 3) & ~3;
84 if ((status
= get_int (addr
, &val
, info
)))
87 fprintf_fn (stream
," default: ");
88 (*info
->print_address_func
) (val
+ insn_start
, info
);
91 if ((status
= get_int (addr
, &lowval
, info
)))
95 if ((status
= get_int (addr
, &highval
, info
)))
99 while (lowval
<= highval
) {
100 if ((status
= get_int (addr
, &val
, info
)))
102 fprintf_fn (stream
," %d:[", lowval
);
103 (*info
->print_address_func
) (val
+ insn_start
, info
);
104 fprintf_fn (stream
," ]");
108 return addr
- insn_start
;
111 /* The lookupswitch instruction is followed by the default
112 address, element count and pairs of values and
115 if (strcmp (op
->name
, "lookupswitch") == 0)
120 addr
= (addr
+ 3) & ~3;
121 if ((status
= get_int (addr
, &val
, info
)))
125 fprintf_fn (stream
," default: ");
126 (*info
->print_address_func
) (val
+ insn_start
, info
);
128 if ((status
= get_int (addr
, &count
, info
)))
133 if ((status
= get_int (addr
, &val
, info
)))
136 fprintf_fn (stream
," %d:[", val
);
138 if ((status
= get_int (addr
, &val
, info
)))
142 (*info
->print_address_func
) (val
+ insn_start
, info
);
143 fprintf_fn (stream
," ]");
145 return addr
- insn_start
;
147 for (a
= 0; op
->arg
[a
]; a
++)
149 unsigned char data
[4];
152 int size
= ASIZE (op
->arg
[a
]);
154 if ((status
= info
->read_memory_func (addr
, data
, size
, info
)))
157 val
= (UNS (op
->arg
[0]) || ((data
[0] & 0x80) == 0)) ? 0 : -1;
159 for (i
= 0; i
< size
; i
++)
160 val
= (val
<< 8) | (data
[i
] & 0xff);
162 if (PCREL (op
->arg
[a
]))
163 (*info
->print_address_func
) (val
+ insn_start
, info
);
165 fprintf_fn (stream
, "%s%d", sep
, val
);
174 info
->memory_error_func (status
, addr
, info
);