Skip to content

Commit a00cfed

Browse files
taylorsimpsonrth7680
authored andcommitted
Hexagon (disas) disassembler
Add hexagon to disas/meson.build Add disas/hexagon.c Add hexagon to include/disas/dis-asm.h Signed-off-by: Taylor Simpson <[email protected]> Tested-by: Philippe Mathieu-Daudé <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Message-Id: <[email protected]> Signed-off-by: Richard Henderson <[email protected]>
1 parent 45183cc commit a00cfed

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

disas/hexagon.c

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
3+
*
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.
8+
*
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.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
/*
19+
* QEMU Hexagon Disassembler
20+
*/
21+
22+
#include "qemu/osdep.h"
23+
#include "disas/dis-asm.h"
24+
#include "target/hexagon/cpu_bits.h"
25+
26+
/*
27+
* We will disassemble a packet with up to 4 instructions, so we need
28+
* a hefty size buffer.
29+
*/
30+
#define PACKET_BUFFER_LEN 1028
31+
32+
int print_insn_hexagon(bfd_vma memaddr, struct disassemble_info *info)
33+
{
34+
uint32_t words[PACKET_WORDS_MAX];
35+
bool found_end = false;
36+
GString *buf = g_string_sized_new(PACKET_BUFFER_LEN);
37+
int i, len;
38+
39+
for (i = 0; i < PACKET_WORDS_MAX && !found_end; i++) {
40+
int status = (*info->read_memory_func)(memaddr + i * sizeof(uint32_t),
41+
(bfd_byte *)&words[i],
42+
sizeof(uint32_t), info);
43+
if (status) {
44+
if (i > 0) {
45+
break;
46+
}
47+
(*info->memory_error_func)(status, memaddr, info);
48+
return status;
49+
}
50+
if (is_packet_end(words[i])) {
51+
found_end = true;
52+
}
53+
}
54+
55+
if (!found_end) {
56+
(*info->fprintf_func)(info->stream, "<invalid>");
57+
return PACKET_WORDS_MAX * sizeof(uint32_t);
58+
}
59+
60+
len = disassemble_hexagon(words, i, memaddr, buf);
61+
(*info->fprintf_func)(info->stream, "%s", buf->str);
62+
g_string_free(buf, true);
63+
64+
return len;
65+
}

disas/meson.build

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ common_ss.add(when: 'CONFIG_ARM_A64_DIS', if_true: files('arm-a64.cc'))
66
common_ss.add_all(when: 'CONFIG_ARM_A64_DIS', if_true: libvixl_ss)
77
common_ss.add(when: 'CONFIG_ARM_DIS', if_true: files('arm.c'))
88
common_ss.add(when: 'CONFIG_CRIS_DIS', if_true: files('cris.c'))
9+
common_ss.add(when: 'CONFIG_HEXAGON_DIS', if_true: files('hexagon.c'))
910
common_ss.add(when: 'CONFIG_HPPA_DIS', if_true: files('hppa.c'))
1011
common_ss.add(when: 'CONFIG_I386_DIS', if_true: files('i386.c'))
1112
common_ss.add(when: 'CONFIG_LM32_DIS', if_true: files('lm32.c'))

include/disas/dis-asm.h

+1
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ int print_insn_xtensa (bfd_vma, disassemble_info*);
459459
int print_insn_riscv32 (bfd_vma, disassemble_info*);
460460
int print_insn_riscv64 (bfd_vma, disassemble_info*);
461461
int print_insn_rx(bfd_vma, disassemble_info *);
462+
int print_insn_hexagon(bfd_vma, disassemble_info *);
462463

463464
#ifdef CONFIG_CAPSTONE
464465
bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t size);

0 commit comments

Comments
 (0)