xref: /openbmc/qemu/disas/objdump.c (revision 2e1cacfb)
1 /*
2  * Dump disassembly as text, for processing by scripts/disas-objdump.pl.
3  * SPDX-License-Identifier: GPL-2.0-or-later
4  */
5 
6 #include "qemu/osdep.h"
7 #include "disas-internal.h"
8 
9 
10 static int print_insn_objdump(bfd_vma pc, disassemble_info *info,
11                               const char *prefix)
12 {
13     int i, n = info->buffer_length;
14     g_autofree uint8_t *buf = g_malloc(n);
15 
16     if (info->read_memory_func(pc, buf, n, info) == 0) {
17         for (i = 0; i < n; ++i) {
18             if (i % 32 == 0) {
19                 info->fprintf_func(info->stream, "\n%s: ", prefix);
20             }
21             info->fprintf_func(info->stream, "%02x", buf[i]);
22         }
23     } else {
24         info->fprintf_func(info->stream, "unable to read memory");
25     }
26     return n;
27 }
28 
29 int print_insn_od_host(bfd_vma pc, disassemble_info *info)
30 {
31     return print_insn_objdump(pc, info, "OBJD-H");
32 }
33 
34 int print_insn_od_target(bfd_vma pc, disassemble_info *info)
35 {
36     return print_insn_objdump(pc, info, "OBJD-T");
37 }
38