1 /* pj-dis.c -- Disassemble picoJava instructions.
2 Copyright 1999, 2000, 2001, 2002, 2005, 2007 Free Software Foundation, Inc.
3 Contributed by Steve Chamberlain, of Transmeta (sac@pobox.com).
5 This file is part of the GNU opcodes library.
7 This library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 It is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
24 #include "opcode/pj.h"
27 extern const pj_opc_info_t pj_opc_info
[512];
30 get_int (bfd_vma memaddr
, int *iptr
, struct disassemble_info
*info
)
32 unsigned char ival
[4];
33 int status
= info
->read_memory_func (memaddr
, ival
, 4, info
);
35 *iptr
= (ival
[0] << 24)
44 print_insn_pj (bfd_vma addr
, struct disassemble_info
*info
)
46 fprintf_ftype fprintf_fn
= info
->fprintf_func
;
47 void *stream
= info
->stream
;
51 if ((status
= info
->read_memory_func (addr
, &opcode
, 1, info
)))
58 if ((status
= info
->read_memory_func (addr
+ 1, &byte_2
, 1, info
)))
60 fprintf_fn (stream
, "%s\t", pj_opc_info
[opcode
+ byte_2
].u
.name
);
66 int insn_start
= addr
;
67 const pj_opc_info_t
*op
= &pj_opc_info
[opcode
];
71 fprintf_fn (stream
, "%s", op
->u
.name
);
73 /* The tableswitch instruction is followed by the default
74 address, low value, high value and the destinations. */
76 if (strcmp (op
->u
.name
, "tableswitch") == 0)
82 addr
= (addr
+ 3) & ~3;
83 if ((status
= get_int (addr
, &val
, info
)))
86 fprintf_fn (stream
, " default: ");
87 (*info
->print_address_func
) (val
+ insn_start
, info
);
90 if ((status
= get_int (addr
, &lowval
, info
)))
94 if ((status
= get_int (addr
, &highval
, info
)))
98 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
114 if (strcmp (op
->u
.name
, "lookupswitch") == 0)
119 addr
= (addr
+ 3) & ~3;
120 if ((status
= get_int (addr
, &val
, info
)))
124 fprintf_fn (stream
, " default: ");
125 (*info
->print_address_func
) (val
+ insn_start
, info
);
127 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
;
148 for (a
= 0; op
->arg
[a
]; a
++)
150 unsigned char data
[4];
153 int size
= ASIZE (op
->arg
[a
]);
155 if ((status
= info
->read_memory_func (addr
, data
, size
, info
)))
158 val
= (UNS (op
->arg
[0]) || ((data
[0] & 0x80) == 0)) ? 0 : -1;
160 for (i
= 0; i
< size
; i
++)
161 val
= (val
<< 8) | (data
[i
] & 0xff);
163 if (PCREL (op
->arg
[a
]))
164 (*info
->print_address_func
) (val
+ insn_start
, info
);
166 fprintf_fn (stream
, "%s%d", sep
, val
);
175 info
->memory_error_func (status
, addr
, info
);