Merge remote-tracking branch 'remotes/dgilbert-gitlab/tags/pull-migration-20210726a...
[qemu/armbru.git] / disas / hexagon.c
blob3c24e2a94af686a20edd0a8b41a501ed080f61e7
1 /*
2 * Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
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, see <http://www.gnu.org/licenses/>.
19 * QEMU Hexagon Disassembler
22 #include "qemu/osdep.h"
23 #include "disas/dis-asm.h"
24 #include "target/hexagon/cpu_bits.h"
27 * We will disassemble a packet with up to 4 instructions, so we need
28 * a hefty size buffer.
30 #define PACKET_BUFFER_LEN 1028
32 int print_insn_hexagon(bfd_vma memaddr, struct disassemble_info *info)
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;
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;
47 (*info->memory_error_func)(status, memaddr, info);
48 return status;
50 if (is_packet_end(words[i])) {
51 found_end = true;
55 if (!found_end) {
56 (*info->fprintf_func)(info->stream, "<invalid>");
57 return PACKET_WORDS_MAX * sizeof(uint32_t);
60 len = disassemble_hexagon(words, i, memaddr, buf);
61 (*info->fprintf_func)(info->stream, "%s", buf->str);
62 g_string_free(buf, true);
64 return len;