1 /* Disassemble h8500 instructions.
2 Copyright 1993, 1998, 2000, 2001 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20 #define DISASSEMBLER_TABLE
24 #include "h8500-opc.h"
28 /* Maximum length of an instruction. */
33 static int fetch_data
PARAMS ((struct disassemble_info
*, bfd_byte
*));
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 (info
, addr
)
53 struct disassemble_info
*info
;
57 struct private *priv
= (struct private *) info
->private_data
;
58 bfd_vma start
= priv
->insn_start
+ (priv
->max_fetched
- priv
->the_buffer
);
60 status
= (*info
->read_memory_func
) (start
,
62 addr
- priv
->max_fetched
,
66 (*info
->memory_error_func
) (status
, start
, info
);
67 longjmp (priv
->bailout
, 1);
70 priv
->max_fetched
= addr
;
74 static char *crname
[] = { "sr", "ccr", "*", "br", "ep", "dp", "*", "tp" };
77 print_insn_h8500 (addr
, info
)
79 disassemble_info
*info
;
81 h8500_opcode_info
*opcode
;
82 void *stream
= info
->stream
;
83 fprintf_ftype func
= info
->fprintf_func
;
86 bfd_byte
*buffer
= priv
.the_buffer
;
88 info
->private_data
= (PTR
) & priv
;
89 priv
.max_fetched
= priv
.the_buffer
;
90 priv
.insn_start
= addr
;
91 if (setjmp (priv
.bailout
) != 0)
102 for (opcode
= h8500_table
; opcode
->name
; opcode
++)
104 if ((opcode
->bytes
[0].contents
& 0x8) == 0)
105 printf ("%s\n", opcode
->name
);
110 /* Run down the table to find the one which matches. */
111 for (opcode
= h8500_table
; opcode
->name
; opcode
++)
125 for (byte
= 0; byte
< opcode
->length
; byte
++)
127 FETCH_DATA (info
, buffer
+ byte
+ 1);
128 if ((buffer
[byte
] & opcode
->bytes
[byte
].mask
)
129 != (opcode
->bytes
[byte
].contents
))
135 /* Extract any info parts. */
136 switch (opcode
->bytes
[byte
].insert
)
142 /* xgettext:c-format */
143 func (stream
, _("can't cope with insert %d\n"),
144 opcode
->bytes
[byte
].insert
);
147 rn
= buffer
[byte
] & 0x7;
150 rs
= buffer
[byte
] & 0x7;
153 cr
= buffer
[byte
] & 0x7;
158 cr
= buffer
[byte
] & 0x7;
163 FETCH_DATA (info
, buffer
+ byte
+ 2);
164 disp
= (buffer
[byte
] << 8) | (buffer
[byte
+ 1]);
168 disp
= ((char) (buffer
[byte
]));
172 rd
= buffer
[byte
] & 0x7;
175 FETCH_DATA (info
, buffer
+ byte
+ 3);
178 | (buffer
[byte
+ 1] << 8)
179 | (buffer
[byte
+ 2]);
182 FETCH_DATA (info
, buffer
+ byte
+ 2);
183 abs
= (buffer
[byte
] << 8) | (buffer
[byte
+ 1]);
186 abs
= (buffer
[byte
]);
189 FETCH_DATA (info
, buffer
+ byte
+ 2);
190 imm
= (buffer
[byte
] << 8) | (buffer
[byte
+ 1]);
193 imm
= (buffer
[byte
]) & 0xf;
197 imm
= (buffer
[byte
]);
200 FETCH_DATA (info
, buffer
+ byte
+ 2);
201 pcrel
= (buffer
[byte
] << 8) | (buffer
[byte
+ 1]);
204 pcrel
= (buffer
[byte
]);
207 switch (buffer
[byte
] & 0x7)
227 /* We get here when all the masks have passed so we can output
229 FETCH_DATA (info
, buffer
+ opcode
->length
);
230 for (i
= 0; i
< opcode
->length
; i
++)
232 (func
) (stream
, "%02x ", buffer
[i
]);
236 (func
) (stream
, " ");
238 (func
) (stream
, "%s\t", opcode
->name
);
239 for (i
= 0; i
< opcode
->nargs
; i
++)
242 (func
) (stream
, ",");
243 switch (opcode
->arg_type
[i
])
249 func (stream
, "@(0x%x:16,r%d)", disp
, rn
);
252 func (stream
, "@(0x%x:8 (%d),r%d)", disp
& 0xff, disp
, rn
);
255 func (stream
, "@(0x%x:16,r%d)", disp
, rd
);
258 func (stream
, "@(0x%x:8 (%d), r%d)", disp
& 0xff, disp
, rd
);
261 func (stream
, "@(0x%x:8 (%d), fp)", disp
& 0xff, disp
, rn
);
265 func (stream
, "%s", crname
[cr
]);
268 func (stream
, "r%d", rn
);
271 func (stream
, "r%d", rd
);
274 func (stream
, "r%d", rs
);
277 func (stream
, "@-r%d", rn
);
280 func (stream
, "@r%d+", rn
);
283 func (stream
, "@r%d", rn
);
286 func (stream
, "@r%d", rd
);
289 func (stream
, "@sp+");
292 func (stream
, "@-sp");
295 func (stream
, "@0x%0x:24", abs
);
298 func (stream
, "@0x%0x:16", abs
& 0xffff);
301 func (stream
, "@0x%0x:8", abs
& 0xff);
304 func (stream
, "#0x%0x:16", imm
& 0xffff);
311 for (i
= 0; i
< 8; i
++)
315 func (stream
, "r%d", i
);
325 func (stream
, "#0x%0x:8", imm
& 0xff);
328 func (stream
, "0x%0x:16",
329 (pcrel
+ addr
+ opcode
->length
) & 0xffff);
332 func (stream
, "#0x%0x:8",
333 ((char) pcrel
+ addr
+ opcode
->length
) & 0xffff);
336 func (stream
, "#%d:q", qim
);
339 func (stream
, "#%d:4", imm
);
343 return opcode
->length
;
348 /* Couldn't understand anything. */
349 /* xgettext:c-format */
350 func (stream
, _("%02x\t\t*unknown*"), buffer
[0]);
This page took 0.042868 seconds and 4 git commands to generate.