1 /* Disassemble h8500 instructions.
2 Copyright (C) 1993 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20 #define DISASSEMBLER_TABLE
23 #include "h8500-opc.h"
26 /* Maximum length of an instruction. */
33 /* Points to first byte not fetched. */
34 bfd_byte
*max_fetched
;
35 bfd_byte the_buffer
[MAXLEN
];
40 /* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive)
41 to ADDR (exclusive) are valid. Returns 1 for success, longjmps
43 #define FETCH_DATA(info, addr) \
44 ((addr) <= ((struct private *)(info->private_data))->max_fetched \
45 ? 1 : fetch_data ((info), (addr)))
48 fetch_data (info
, addr
)
49 struct disassemble_info
*info
;
53 struct private *priv
= (struct private *)info
->private_data
;
54 bfd_vma start
= priv
->insn_start
+ (priv
->max_fetched
- priv
->the_buffer
);
56 status
= (*info
->read_memory_func
) (start
,
58 addr
- priv
->max_fetched
,
62 (*info
->memory_error_func
) (status
, start
, info
);
63 longjmp (priv
->bailout
);
66 priv
->max_fetched
= addr
;
70 static char *crname
[] =
71 {"sr", "ccr", "*", "br", "ep", "dp", "*", "tp"};
74 print_insn_h8500 (addr
, info
)
76 disassemble_info
*info
;
78 h8500_opcode_info
*opcode
;
79 void *stream
= info
->stream
;
80 fprintf_ftype func
= info
->fprintf_func
;
83 bfd_byte
*buffer
= priv
.the_buffer
;
85 info
->private_data
= (PTR
) &priv
;
86 priv
.max_fetched
= priv
.the_buffer
;
87 priv
.insn_start
= addr
;
88 if (setjmp (priv
.bailout
) != 0)
92 /* Run down the table to find the one which matches */
93 for (opcode
= h8500_table
; opcode
->name
; opcode
++)
106 for (byte
= 0; byte
< opcode
->length
; byte
++)
108 FETCH_DATA (info
, buffer
+ byte
+ 1);
109 if ((buffer
[byte
] & opcode
->bytes
[byte
].mask
)
110 != (opcode
->bytes
[byte
].contents
))
116 /* extract any info parts */
117 switch (opcode
->bytes
[byte
].insert
)
123 func (stream
, "can't cope with insert %d\n",
124 opcode
->bytes
[byte
].insert
);
127 rn
= buffer
[byte
] & 0x7;
130 rs
= buffer
[byte
] & 0x7;
133 cr
= buffer
[byte
] & 0x7;
138 cr
= buffer
[byte
] & 0x7;
143 FETCH_DATA (info
, buffer
+ byte
+ 2);
144 disp
= (buffer
[byte
] << 8) | (buffer
[byte
+ 1]);
148 disp
= ((char) (buffer
[byte
]));
152 rd
= buffer
[byte
] & 0x7;
155 FETCH_DATA (info
, buffer
+ byte
+ 3);
158 | (buffer
[byte
+ 1] << 8)
159 | (buffer
[byte
+ 2]);
162 FETCH_DATA (info
, buffer
+ byte
+ 2);
163 abs
= (buffer
[byte
] << 8) | (buffer
[byte
+ 1]);
166 abs
= (buffer
[byte
]);
169 FETCH_DATA (info
, buffer
+ byte
+ 2);
170 imm
= (buffer
[byte
] << 8) | (buffer
[byte
+ 1]);
173 imm
= (buffer
[byte
]) & 0xf;
177 imm
= (buffer
[byte
]);
180 FETCH_DATA (info
, buffer
+ byte
+ 2);
181 pcrel
= (buffer
[byte
] << 8) | (buffer
[byte
+ 1]);
184 pcrel
= (buffer
[byte
]);
187 switch (buffer
[byte
] & 0x7)
207 /* We get here when all the masks have passed so we can output the
209 FETCH_DATA (info
, buffer
+ opcode
->length
);
210 for (i
= 0; i
< opcode
->length
; i
++)
212 (func
) (stream
, "%02x ", buffer
[i
]);
216 (func
) (stream
, " ");
218 (func
) (stream
, "%s\t", opcode
->name
);
219 for (i
= 0; i
< opcode
->nargs
; i
++)
222 (func
) (stream
, ",");
223 switch (opcode
->arg_type
[i
])
229 func (stream
, "@(0x%x:16,r%d)", disp
, rn
);
232 func (stream
, "@(0x%x:8 (%d),r%d)", disp
& 0xff, disp
, rn
);
235 func (stream
, "@(0x%x:16,r%d)", disp
, rd
);
238 func (stream
, "@(0x%x:8 (%d), r%d)", disp
& 0xff, disp
, rd
);
241 func (stream
, "@(0x%x:8 (%d), fp)", disp
& 0xff, disp
, rn
);
245 func (stream
, "%s", crname
[cr
]);
248 func (stream
, "r%d", rn
);
251 func (stream
, "r%d", rd
);
254 func (stream
, "r%d", rs
);
257 func (stream
, "@-r%d", rn
);
260 func (stream
, "@r%d+", rn
);
263 func (stream
, "@r%d", rn
);
266 func (stream
, "@r%d", rd
);
269 func (stream
, "@sp+");
272 func (stream
, "@-sp");
275 func (stream
, "@0x%0x:24", abs
);
278 func (stream
, "@0x%0x:16", abs
& 0xffff);
281 func (stream
, "@0x%0x:8", abs
& 0xff);
284 func (stream
, "#0x%0x:16", imm
& 0xffff);
291 for (i
= 0; i
< 8; i
++)
299 func (stream
, "r%d", i
);
305 func (stream
, "#0x%0x:8", imm
& 0xff);
308 func (stream
, "0x%0x:16", (pcrel
+ addr
+ opcode
->length
) & 0xffff);
311 func (stream
, "#0x%0x:8",
312 ((char) pcrel
+ addr
+ opcode
->length
) & 0xffff);
315 func (stream
, "#%d:q", qim
);
318 func (stream
, "#%d:4", imm
);
322 return opcode
->length
;
326 /* Couldn't understand anything */
327 func (stream
, "%02x\t\t*unknown*", buffer
[0]);