1 /* Disassemble h8500 instructions.
2 Copyright 1993, 1998, 2000, 2001, 2002, 2004, 2005
3 Free Software Foundation, Inc.
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., 51 Franklin Street - Fifth Floor, Boston,
18 MA 02110-1301, USA. */
22 #define DISASSEMBLER_TABLE
26 #include "h8500-opc.h"
30 /* Maximum length of an instruction. */
37 /* Points to first byte not fetched. */
38 bfd_byte
*max_fetched
;
39 bfd_byte the_buffer
[MAXLEN
];
44 /* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
45 to ADDR (exclusive) are valid. Returns 1 for success, longjmps
47 #define FETCH_DATA(info, addr) \
48 ((addr) <= ((struct private *)(info->private_data))->max_fetched \
49 ? 1 : fetch_data ((info), (addr)))
52 fetch_data (struct disassemble_info
*info
, bfd_byte
*addr
)
55 struct private *priv
= (struct private *) info
->private_data
;
56 bfd_vma start
= priv
->insn_start
+ (priv
->max_fetched
- priv
->the_buffer
);
58 status
= (*info
->read_memory_func
) (start
,
60 addr
- priv
->max_fetched
,
64 (*info
->memory_error_func
) (status
, start
, info
);
65 longjmp (priv
->bailout
, 1);
68 priv
->max_fetched
= addr
;
72 static char *crname
[] = { "sr", "ccr", "*", "br", "ep", "dp", "*", "tp" };
75 print_insn_h8500 (bfd_vma addr
, disassemble_info
*info
)
77 const h8500_opcode_info
*opcode
;
78 void *stream
= info
->stream
;
79 fprintf_ftype func
= info
->fprintf_func
;
81 bfd_byte
*buffer
= priv
.the_buffer
;
83 info
->private_data
= (PTR
) & priv
;
84 priv
.max_fetched
= priv
.the_buffer
;
85 priv
.insn_start
= addr
;
86 if (setjmp (priv
.bailout
) != 0)
90 /* Run down the table to find the one which matches. */
91 for (opcode
= h8500_table
; opcode
->name
; opcode
++)
105 for (byte
= 0; byte
< opcode
->length
; byte
++)
107 FETCH_DATA (info
, buffer
+ byte
+ 1);
108 if ((buffer
[byte
] & opcode
->bytes
[byte
].mask
)
109 != (opcode
->bytes
[byte
].contents
))
114 /* Extract any info parts. */
115 switch (opcode
->bytes
[byte
].insert
)
121 /* xgettext:c-format */
122 func (stream
, _("can't cope with insert %d\n"),
123 opcode
->bytes
[byte
].insert
);
126 rn
= buffer
[byte
] & 0x7;
129 rs
= buffer
[byte
] & 0x7;
132 cr
= buffer
[byte
] & 0x7;
137 cr
= buffer
[byte
] & 0x7;
142 FETCH_DATA (info
, buffer
+ byte
+ 2);
143 disp
= (buffer
[byte
] << 8) | (buffer
[byte
+ 1]);
147 disp
= ((char) (buffer
[byte
]));
151 rd
= buffer
[byte
] & 0x7;
154 FETCH_DATA (info
, buffer
+ byte
+ 3);
157 | (buffer
[byte
+ 1] << 8)
158 | (buffer
[byte
+ 2]);
161 FETCH_DATA (info
, buffer
+ byte
+ 2);
162 abs
= (buffer
[byte
] << 8) | (buffer
[byte
+ 1]);
165 abs
= (buffer
[byte
]);
168 FETCH_DATA (info
, buffer
+ byte
+ 2);
169 imm
= (buffer
[byte
] << 8) | (buffer
[byte
+ 1]);
172 imm
= (buffer
[byte
]) & 0xf;
176 imm
= (buffer
[byte
]);
179 FETCH_DATA (info
, buffer
+ byte
+ 2);
180 pcrel
= (buffer
[byte
] << 8) | (buffer
[byte
+ 1]);
183 pcrel
= (buffer
[byte
]);
186 switch (buffer
[byte
] & 0x7)
206 /* We get here when all the masks have passed so we can output
208 FETCH_DATA (info
, buffer
+ opcode
->length
);
209 (func
) (stream
, "%s\t", opcode
->name
);
210 for (i
= 0; i
< opcode
->nargs
; i
++)
213 (func
) (stream
, ",");
214 switch (opcode
->arg_type
[i
])
220 func (stream
, "@(0x%x:16,r%d)", disp
, rn
);
223 func (stream
, "@(0x%x:8 (%d),r%d)", disp
& 0xff, disp
, rn
);
226 func (stream
, "@(0x%x:16,r%d)", disp
, rd
);
229 func (stream
, "@(0x%x:8 (%d), r%d)", disp
& 0xff, disp
, rd
);
232 func (stream
, "@(0x%x:8 (%d), fp)", disp
& 0xff, disp
);
236 func (stream
, "%s", crname
[cr
]);
239 func (stream
, "r%d", rn
);
242 func (stream
, "r%d", rd
);
245 func (stream
, "r%d", rs
);
248 func (stream
, "@-r%d", rn
);
251 func (stream
, "@r%d+", rn
);
254 func (stream
, "@r%d", rn
);
257 func (stream
, "@r%d", rd
);
260 func (stream
, "@sp+");
263 func (stream
, "@-sp");
266 func (stream
, "@0x%0x:24", abs
);
269 func (stream
, "@0x%0x:16", abs
& 0xffff);
272 func (stream
, "@0x%0x:8", abs
& 0xff);
275 func (stream
, "#0x%0x:16", imm
& 0xffff);
283 for (i
= 0; i
< 8; i
++)
287 func (stream
, "r%d", i
);
297 func (stream
, "#0x%0x:8", imm
& 0xff);
300 func (stream
, "0x%0x:16",
301 (int)(pcrel
+ addr
+ opcode
->length
) & 0xffff);
304 func (stream
, "#0x%0x:8",
305 (int)((char) pcrel
+ addr
+ opcode
->length
) & 0xffff);
308 func (stream
, "#%d:q", qim
);
311 func (stream
, "#%d:4", imm
);
315 return opcode
->length
;
320 /* Couldn't understand anything. */
321 /* xgettext:c-format */
322 func (stream
, _("%02x\t\t*unknown*"), buffer
[0]);