1 /* pj-dis.c -- Disassemble picoJava instructions.
2 Copyright (C) 1999-2024 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 "libiberty.h"
25 #include "opcode/pj.h"
26 #include "disassemble.h"
28 extern const pj_opc_info_t pj_opc_info
[512];
31 get_int (bfd_vma memaddr
, int *iptr
, struct disassemble_info
*info
)
33 unsigned char ival
[4];
34 int status
= info
->read_memory_func (memaddr
, ival
, 4, info
);
36 *iptr
= (((unsigned) ival
[0] << 24)
45 print_insn_pj (bfd_vma addr
, struct disassemble_info
*info
)
47 fprintf_ftype fprintf_fn
= info
->fprintf_func
;
48 void *stream
= info
->stream
;
52 if ((status
= info
->read_memory_func (addr
, &opcode
, 1, info
)))
59 if ((status
= info
->read_memory_func (addr
+ 1, &byte_2
, 1, info
)))
61 fprintf_fn (stream
, "%s", pj_opc_info
[opcode
+ byte_2
].u
.name
);
67 int insn_start
= addr
;
68 const pj_opc_info_t
*op
= &pj_opc_info
[opcode
];
72 fprintf_fn (stream
, "%s", op
->u
.name
);
74 /* The tableswitch instruction is followed by the default
75 address, low value, high value and the destinations. */
77 if (strcmp (op
->u
.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
)
101 if ((status
= get_int (addr
, &val
, info
)))
103 fprintf_fn (stream
, " %d:[", lowval
);
104 (*info
->print_address_func
) (val
+ insn_start
, info
);
105 fprintf_fn (stream
, " ]");
109 return addr
- insn_start
;
112 /* The lookupswitch instruction is followed by the default
113 address, element count and pairs of values and
115 if (strcmp (op
->u
.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
)))
134 if ((status
= get_int (addr
, &val
, info
)))
137 fprintf_fn (stream
, " %d:[", val
);
139 if ((status
= get_int (addr
, &val
, info
)))
143 (*info
->print_address_func
) (val
+ insn_start
, info
);
144 fprintf_fn (stream
, " ]");
146 return addr
- insn_start
;
149 for (a
= 0; a
< ARRAY_SIZE (op
->arg
) && op
->arg
[a
]; a
++)
151 unsigned char data
[4];
154 int size
= ASIZE (op
->arg
[a
]);
156 if ((status
= info
->read_memory_func (addr
, data
, size
, info
)))
159 val
= (UNS (op
->arg
[0]) || ((data
[0] & 0x80) == 0)) ? 0 : -1;
161 for (i
= 0; i
< size
; i
++)
162 val
= ((unsigned) val
<< 8) | (data
[i
] & 0xff);
164 fprintf_fn (stream
, "%s", sep
);
165 if (PCREL (op
->arg
[a
]))
166 (*info
->print_address_func
) (val
+ insn_start
, info
);
168 fprintf_fn (stream
, "%d", val
);
177 info
->memory_error_func (status
, addr
, info
);