From nobody Sun Feb 8 08:43:14 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1509767764932188.05000257420272; Fri, 3 Nov 2017 20:56:04 -0700 (PDT) Received: from localhost ([::1]:39243 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eApYt-0005Md-5f for importer@patchew.org; Fri, 03 Nov 2017 23:55:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45021) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eApPn-0006M0-CD for qemu-devel@nongnu.org; Fri, 03 Nov 2017 23:46:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eApPm-0001BX-2r for qemu-devel@nongnu.org; Fri, 03 Nov 2017 23:46:35 -0400 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]:54184) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eApPl-00019r-NS for qemu-devel@nongnu.org; Fri, 03 Nov 2017 23:46:34 -0400 Received: by mail-lf0-x241.google.com with SMTP id l23so5145452lfk.10 for ; Fri, 03 Nov 2017 20:46:33 -0700 (PDT) Received: from octofox.net (jcmvbkbc-1-pt.tunnel.tserv24.sto1.ipv6.he.net. [2001:470:27:1fa::2]) by smtp.gmail.com with ESMTPSA id h3sm1258383lfj.26.2017.11.03.20.46.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 03 Nov 2017 20:46:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jhsmbc+GRO/c470J7CvtAiVOuiPHejysehG/a20BGMQ=; b=o0g4YwW3lvUz3UIRrC0SGWroDuweMWc0xjMXGzj6Loq0AlFNeAU/vQ9W0nY6HV6ayf 85ZQG49wF8jB3Ed5o18oxF3VmVujzhISr7oXGM5VMSw0Jxa9tzPVuNryd/CQ/KTIi1qN PJVJ/elYf9xBtOrf3fpHQHwjHaVa69gkMsvreWedIXcRxBS5rAXQMGi8KEwSulaEGjwR rFYsuR2liNECNjqxNmPwTIzB1OpnsJh+UC04PKNx9xQw+AjLy3yPQzbUv/UtvGFerwDL cBwkQ9DOHiytcUQ/KP41ZjZcHaw7Q2WeQaTL7alFyxImxLZg1oIghvuVGY/jWtsllaCj 8twQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jhsmbc+GRO/c470J7CvtAiVOuiPHejysehG/a20BGMQ=; b=Twhn85UUbt8LSwxZr9maFOn9BdOvlQkatFaN52LB4KouGIHCnRJMjSyuDl5xKCcp/+ 9yePdFVcfJiZoEFX7iySw+ag6Ba2v/XuzhGlnG2e2C+7xL9GIOtGC8jvGZ6g61PA7jOO zB7pMq/h0dXt0yNCDIhQlVIK56nPH4uVGe0d+6EZhpMhfVadDO7x28QbjWoTLIg9eF+h 5Ao/n24If0bjkG51yJh7myg6kSoLXWb224cTj22Ti/2EGJgdYmXOgkJx7xa2rHcudxWX ERaVo6zhZtpDZiSMSoY91O0zKSFZ0Ol2p+e0TOzPPS4mPloJ2xmh6j2vC5eoB9/VwcpW XtiA== X-Gm-Message-State: AMCzsaUIaPvzbsS6Uf0ebmu4RkeOdzofbAEXsZSe/5Qn811OSeBZQEJB M/KuLCRLXhNUOCF9ellA7Ar60A== X-Google-Smtp-Source: ABhQp+SBBTdoASfTKccGsHYaqV5M6ZPW+Kui8M1zI1Wj8bfV+elurn1JxRItRthQcOjMq3cqvNP/ZA== X-Received: by 10.46.64.82 with SMTP id n79mr3980731lja.129.1509767192164; Fri, 03 Nov 2017 20:46:32 -0700 (PDT) From: Max Filippov To: qemu-devel@nongnu.org Date: Fri, 3 Nov 2017 20:45:21 -0700 Message-Id: <1509767121-26925-17-git-send-email-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1509767121-26925-1-git-send-email-jcmvbkbc@gmail.com> References: <1509767121-26925-1-git-send-email-jcmvbkbc@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4010:c07::241 Subject: [Qemu-devel] [PATCH 16/16] target/xtensa: implement disassembler X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Max Filippov , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add disas/xtensa.c and use libisa for instruction decoding/opcode name lookup. Signed-off-by: Max Filippov --- MAINTAINERS | 1 + disas/Makefile.objs | 1 + disas/xtensa.c | 133 ++++++++++++++++++++++++++++++++++++++++++++++++= ++++ include/disas/bfd.h | 1 + target/xtensa/cpu.c | 9 ++++ 5 files changed, 145 insertions(+) create mode 100644 disas/xtensa.c diff --git a/MAINTAINERS b/MAINTAINERS index 265006324231..1aed66f07af7 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -259,6 +259,7 @@ S: Maintained F: target/xtensa/ F: hw/xtensa/ F: tests/tcg/xtensa/ +F: disas/xtensa.c =20 TriCore M: Bastian Koppelmann diff --git a/disas/Makefile.objs b/disas/Makefile.objs index 194648fb1ac9..53556f8f5a9f 100644 --- a/disas/Makefile.objs +++ b/disas/Makefile.objs @@ -21,6 +21,7 @@ common-obj-$(CONFIG_S390_DIS) +=3D s390.o common-obj-$(CONFIG_SH4_DIS) +=3D sh4.o common-obj-$(CONFIG_SPARC_DIS) +=3D sparc.o common-obj-$(CONFIG_LM32_DIS) +=3D lm32.o +common-obj-$(CONFIG_XTENSA_DIS) +=3D xtensa.o =20 # TODO: As long as the TCG interpreter and its generated code depend # on the QEMU target, we cannot compile the disassembler here. diff --git a/disas/xtensa.c b/disas/xtensa.c new file mode 100644 index 000000000000..114326a4fc2e --- /dev/null +++ b/disas/xtensa.c @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2017, Max Filippov, Open Source and Linux Lab. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are = met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in t= he + * documentation and/or other materials provided with the distributi= on. + * * Neither the name of the Open Source and Linux Lab nor the + * names of its contributors may be used to endorse or promote produ= cts + * derived from this software without specific prior written permiss= ion. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS= IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, T= HE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP= OSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMA= GES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERV= ICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED= AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR T= ORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE O= F THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "qemu/osdep.h" +#include "disas/bfd.h" +#include "hw/xtensa/xtensa-isa.h" + +int print_insn_xtensa(bfd_vma memaddr, struct disassemble_info *info) +{ + xtensa_isa isa =3D info->private_data; + xtensa_insnbuf insnbuf =3D xtensa_insnbuf_alloc(isa); + xtensa_insnbuf slotbuf =3D xtensa_insnbuf_alloc(isa); + bfd_byte *buffer =3D g_malloc(1); + int status =3D info->read_memory_func(memaddr, buffer, 1, info); + xtensa_format fmt; + unsigned slot, slots; + unsigned len; + + if (status) { + info->memory_error_func(status, memaddr, info); + len =3D -1; + goto out; + } + len =3D xtensa_isa_length_from_chars(isa, buffer); + if (len =3D=3D XTENSA_UNDEFINED) { + info->fprintf_func(info->stream, ".byte 0x%02x", buffer[0]); + len =3D 1; + goto out; + } + buffer =3D g_realloc(buffer, len); + status =3D info->read_memory_func(memaddr + 1, buffer + 1, len - 1, in= fo); + if (status) { + info->fprintf_func(info->stream, ".byte 0x%02x", buffer[0]); + info->memory_error_func(status, memaddr + 1, info); + len =3D 1; + goto out; + } + + xtensa_insnbuf_from_chars(isa, insnbuf, buffer, len); + fmt =3D xtensa_format_decode(isa, insnbuf); + if (fmt =3D=3D XTENSA_UNDEFINED) { + unsigned i; + + for (i =3D 0; i < len; ++i) { + info->fprintf_func(info->stream, "%s 0x%02x", + i ? ", " : ".byte ", buffer[i]); + } + goto out; + } + slots =3D xtensa_format_num_slots(isa, fmt); + + if (slots > 1) { + info->fprintf_func(info->stream, "{ "); + } + + for (slot =3D 0; slot < slots; ++slot) { + xtensa_opcode opc; + unsigned opnd, vopnd, opnds; + + if (slot) { + info->fprintf_func(info->stream, "; "); + } + xtensa_format_get_slot(isa, fmt, slot, insnbuf, slotbuf); + opc =3D xtensa_opcode_decode(isa, fmt, slot, slotbuf); + if (opc =3D=3D XTENSA_UNDEFINED) { + info->fprintf_func(info->stream, "???"); + continue; + } + opnds =3D xtensa_opcode_num_operands(isa, opc); + + info->fprintf_func(info->stream, "%s", xtensa_opcode_name(isa, opc= )); + + for (opnd =3D vopnd =3D 0; opnd < opnds; ++opnd) { + if (xtensa_operand_is_visible(isa, opc, opnd)) { + uint32_t v =3D 0xbadc0de; + int rc; + + info->fprintf_func(info->stream, vopnd ? ", " : "\t"); + xtensa_operand_get_field(isa, opc, opnd, fmt, slot, + slotbuf, &v); + rc =3D xtensa_operand_decode(isa, opc, opnd, &v); + if (rc =3D=3D XTENSA_UNDEFINED) { + info->fprintf_func(info->stream, "???"); + } else if (xtensa_operand_is_register(isa, opc, opnd)) { + xtensa_regfile rf =3D xtensa_operand_regfile(isa, opc,= opnd); + + info->fprintf_func(info->stream, "%s%d", + xtensa_regfile_shortname(isa, rf), = v); + } else if (xtensa_operand_is_PCrelative(isa, opc, opnd)) { + xtensa_operand_undo_reloc(isa, opc, opnd, &v, memaddr); + info->fprintf_func(info->stream, "0x%x", v); + } else { + info->fprintf_func(info->stream, "%d", v); + } + ++vopnd; + } + } + } + if (slots > 1) { + info->fprintf_func(info->stream, " }"); + } + +out: + g_free(buffer); + xtensa_insnbuf_free(isa, insnbuf); + xtensa_insnbuf_free(isa, slotbuf); + + return len; +} diff --git a/include/disas/bfd.h b/include/disas/bfd.h index 1f88c9e9d526..5e0e34dc9640 100644 --- a/include/disas/bfd.h +++ b/include/disas/bfd.h @@ -426,6 +426,7 @@ int print_insn_ia64 (bfd_vma, disassemble_i= nfo*); int print_insn_lm32 (bfd_vma, disassemble_info*); int print_insn_big_nios2 (bfd_vma, disassemble_info*); int print_insn_little_nios2 (bfd_vma, disassemble_info*); +int print_insn_xtensa (bfd_vma, disassemble_info*); =20 #if 0 /* Fetch the disassembler for a given BFD, if that support is available. = */ diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c index a5651e5dab92..65a76b794149 100644 --- a/target/xtensa/cpu.c +++ b/target/xtensa/cpu.c @@ -93,6 +93,14 @@ static ObjectClass *xtensa_cpu_class_by_name(const char = *cpu_model) return oc; } =20 +static void xtensa_cpu_disas_set_info(CPUState *cs, disassemble_info *info) +{ + XtensaCPU *cpu =3D XTENSA_CPU(cs); + + info->private_data =3D cpu->env.config->isa; + info->print_insn =3D print_insn_xtensa; +} + static void xtensa_cpu_realizefn(DeviceState *dev, Error **errp) { CPUState *cs =3D CPU(dev); @@ -164,6 +172,7 @@ static void xtensa_cpu_class_init(ObjectClass *oc, void= *data) cc->do_unassigned_access =3D xtensa_cpu_do_unassigned_access; #endif cc->debug_excp_handler =3D xtensa_breakpoint_handler; + cc->disas_set_info =3D xtensa_cpu_disas_set_info; cc->tcg_initialize =3D xtensa_translate_init; dc->vmsd =3D &vmstate_xtensa_cpu; } --=20 2.1.4