]>
Commit | Line | Data |
---|---|---|
a00cfed0 TS |
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; | |
a7686d5d | 36 | GString *buf; |
a00cfed0 TS |
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 | ||
a7686d5d | 60 | buf = g_string_sized_new(PACKET_BUFFER_LEN); |
a00cfed0 TS |
61 | len = disassemble_hexagon(words, i, memaddr, buf); |
62 | (*info->fprintf_func)(info->stream, "%s", buf->str); | |
63 | g_string_free(buf, true); | |
64 | ||
65 | return len; | |
66 | } |