1 /* C++ interface to the GNU disassembler library (libopcodes).
2 Copyright 2001, 2003, 2004 Brian R. Gaeke.
3
4 This file is part of VMIPS.
5
6 VMIPS is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2 of the License, or (at your
9 option) any later version.
10
11 VMIPS is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License along
17 with VMIPS; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19
20 #include "stub-dis.h"
21
Disassembler(bool host_is_bigendian,FILE * stream)22 Disassembler::Disassembler (bool host_is_bigendian, FILE *stream) {
23 if (host_is_bigendian) {
24 insn_printer_func = print_insn_big_mips;
25 } else {
26 insn_printer_func = print_insn_little_mips;
27 }
28 INIT_DISASSEMBLE_INFO(disasm_info, stream, fprintf);
29 disasm_info.buffer_length = 4;
30 }
31
disassemble(uint32 pc,uint32 instr)32 void Disassembler::disassemble (uint32 pc, uint32 instr) {
33 // Point libopcodes at the instruction.
34 disasm_info.buffer_vma = pc;
35 disasm_info.buffer = (bfd_byte *) &instr;
36
37 // Disassemble the instruction, which is in *host* byte order.
38 insn_printer_func(pc, &disasm_info);
39 putc('\n', (FILE *)disasm_info.stream); // End the line.
40 }
41