From patchwork Wed Aug 8 12:39:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 143624 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp808428ljj; Wed, 8 Aug 2018 06:09:57 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwT7hu5uzn5iIvx5zgnZb03vnrBPStYOThuvIr93HUG0WaGEdWTIPKgp24au5wgnqwkJGIO X-Received: by 2002:a37:9486:: with SMTP id w128-v6mr2326163qkd.362.1533733797377; Wed, 08 Aug 2018 06:09:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533733797; cv=none; d=google.com; s=arc-20160816; b=Ev9nGVDxhEMjGC4fg4o8+6Q2Nlk+JlI8Qob3fGTWYlyW6nhVpB79YV9xzMNjbM8hpv jzObxjbycrtJUO97L6xrucIBbM98EHwIlPSExy8RG0RluTcLqz7Z6huBb49mU/pshM2A gpRE6mFV+V5IcrBVGf72Eh53gDuITpnw2svHASzAXIVqkiQgzHqYHVGhQ+/VrUBvEu9R aeAyyO6JhJsvOHC64TaYC1FTjssKjLRbSeCA92SXQJoSSd0sZLFB5eFUaiQMEXXvExay 9GSR6LLIulI0WapSOI5ZDhtyp6XH6Wvy3sT1Pr/htYMFuX9iyRdmKnkcCF6wRgeaZ/6I /LSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=NfB+spkOifa3a7y5U9IVxta48XMAdJfKSFRw8wrslHE=; b=C9Zz6vHhJC+Chi/XAj+zVjxPS+5S17xgO41W2EECVSsafsCACiOdJUjORkOaKraTxp Ez20ilkqrpNpaFS5ANxTlCvX0MgzxcviRgVsmziem/4Drd4PeQlrnmVr1nmTUQ3QXeU1 ues8NdaM4GKDQCAYhv5/JfHLftqjLYmSdnhVYvQBhe+O1pnXcg4+fJViiQgMOHb/jvG4 1jWGce0b3op5gAJ4rbVmFgs43W1VCeeIpMViLEjQbU1niewkycRVb+xMK/ze7dLGW9g5 0aS8vSdk0dqgBbM8fbXgxh5/cSrfK3qR2JA/WvQ8EpkrYv/IAkxkDGVGQV+i92jTnEUZ 6t+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=U8J6waLL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 70-v6si2664615qke.242.2018.08.08.06.09.57 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 08 Aug 2018 06:09:57 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=U8J6waLL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43643 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnODs-0004Tu-Q6 for patch@linaro.org; Wed, 08 Aug 2018 09:09:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35420) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnNka-0004Vx-Bb for qemu-devel@nongnu.org; Wed, 08 Aug 2018 08:39:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fnNkX-0006rs-N3 for qemu-devel@nongnu.org; Wed, 08 Aug 2018 08:39:40 -0400 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]:44737) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fnNkX-0006q9-Eo for qemu-devel@nongnu.org; Wed, 08 Aug 2018 08:39:37 -0400 Received: by mail-wr1-x42e.google.com with SMTP id r16-v6so1865389wrt.11 for ; Wed, 08 Aug 2018 05:39:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NfB+spkOifa3a7y5U9IVxta48XMAdJfKSFRw8wrslHE=; b=U8J6waLLUD130oGVM03Uk+/1D+NSOLzaTeKKMsRPkkKCgJ510bHz6YrhPGsGF5J2zJ 0IkrggYkorJQm+X82jgoOfE7rqjzB6DfsOjpp7ow9g0Xu6OxXe/Ke9cwQZVzPy54YXxL snlAtW7Mda9Io3m/N9RqvW5OMOBl/2i2bOgIU= 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:mime-version:content-transfer-encoding; bh=NfB+spkOifa3a7y5U9IVxta48XMAdJfKSFRw8wrslHE=; b=ammcnEVQLr1W1U2o5kdHcNdscSajpbx0lTNx2OihUelRoTvrJuOyyj7LuZxTF8XAzI Ni6gF1GjWs2FQyKhQYQU35OszMPqGBSeQS/Mq2CYVj2uB3Yf5F1gZpDGLYkCu+UzIuMc IRR5WMSh79WFDxWLZte5lJ6fXTnzIJFHoupBvf+DYeAk96PxaD10t1NlfG32DEKGmHnG 8W71aBcypB+cQVVuvdSiHhx1Bm+wNZQ9CyJkJrFqeo7zmK8Z7Do4c3i0NtNWLaO3ACW+ eozLaotlUPaCyY1LrwvUFbgQFfxSR4SlreXzj/SkFQl1W9NJPz1ugxRBzfqNov2WFNfX rNZA== X-Gm-Message-State: AOUpUlGktQ2iE4RV5IY3sGQdR6FRDM4JSZei0eENAHqMH4g2GDzc4mXK YjhYQlfer/sGOOYFqJL4pSfN3g== X-Received: by 2002:adf:9485:: with SMTP id 5-v6mr1888358wrr.82.1533731976288; Wed, 08 Aug 2018 05:39:36 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id x82-v6sm12682336wmd.11.2018.08.08.05.39.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 08 Aug 2018 05:39:35 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 64E1F3E0619; Wed, 8 Aug 2018 13:39:34 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Wed, 8 Aug 2018 13:39:31 +0100 Message-Id: <20180808123934.17450-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180808123934.17450-1-alex.bennee@linaro.org> References: <20180808123934.17450-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42e Subject: [Qemu-devel] [RFC PATCH 1/4] scripts/decodetree.py: add a disassembly generator (HACK!) 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: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-arm@nongnu.org, richard.henderson@linaro.org, Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Given our issues with failing disassembly we could try and re-use the decode tree data to output what instruction is being decoded. This will be used if registered as a fall-back for when the "proper" disassembler fails to decode an instruction. Signed-off-by: Alex Bennée --- scripts/decodetree.py | 52 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 6 deletions(-) -- 2.17.1 Acked-by: Eduardo Habkost diff --git a/scripts/decodetree.py b/scripts/decodetree.py index 277f9a9bba..f4b4318c96 100755 --- a/scripts/decodetree.py +++ b/scripts/decodetree.py @@ -169,6 +169,7 @@ input_file = '' output_file = None output_fd = None insntype = 'uint32_t' +disassemble = False re_ident = '[a-zA-Z][a-zA-Z0-9_]*' @@ -467,6 +468,7 @@ class Pattern(General): def output_code(self, i, extracted, outerbits, outermask): global translate_prefix + global disassemble ind = str_indent(i) arg = self.base.base.name output(ind, '/* line ', str(self.lineno), ' */\n') @@ -474,8 +476,34 @@ class Pattern(General): output(ind, self.base.extract_name(), '(&u.f_', arg, ', insn);\n') for n, f in self.fields.items(): output(ind, 'u.f_', arg, '.', n, ' = ', f.str_extract(), ';\n') - output(ind, 'return ', translate_prefix, '_', self.name, - '(ctx, &u.f_', arg, ', insn);\n') + output(ind, 'return ', translate_prefix, '_', self.name) + if disassemble: + output("(dstr, maxd, ") + else: + output("(ctx, ") + + output('&u.f_', arg) + + if disassemble: + output(");\n") + else: + output(', insn);\n') + + def output_formatter(self): + global translate_prefix + arg = self.base.base.name + output('/* line ', str(self.lineno), ' */\n') + output('typedef ', self.base.base.struct_name(), + ' arg_', self.name, ';\n') + output(translate_scope, 'bool ', translate_prefix, '_', self.name, + '(char *ptr, size_t n, arg_', self.name, ' *a)\n') + output("{\n") + output(str_indent(4), 'snprintf(ptr, n, "', self.name) + # fill in arguments here + output('"); \n') + output(str_indent(4), "return true;\n") + output("}\n") + # end Pattern @@ -973,11 +1001,12 @@ def main(): global insnwidth global insntype global insnmask + global disassemble decode_function = 'decode' decode_scope = 'static ' - long_opts = ['decode=', 'translate=', 'output=', 'insnwidth='] + long_opts = ['decode=', 'translate=', 'output=', 'insnwidth=', 'disassemble'] try: (opts, args) = getopt.getopt(sys.argv[1:], 'o:w:', long_opts) except getopt.GetoptError as err: @@ -998,6 +1027,8 @@ def main(): insnmask = 0xffff elif insnwidth != 32: error(0, 'cannot handle insns of width', insnwidth) + elif o == '--disassemble': + disassemble = True else: assert False, 'unhandled option' @@ -1031,7 +1062,10 @@ def main(): if i.base.base != p.base.base: error(0, i.name, ' has conflicting argument sets') else: - i.output_decl() + if disassemble: + i.output_formatter() + else: + i.output_decl() out_pats[i.name] = i output('\n') @@ -1039,8 +1073,14 @@ def main(): f = formats[n] f.output_extract() - output(decode_scope, 'bool ', decode_function, - '(DisasContext *ctx, ', insntype, ' insn)\n{\n') + output(decode_scope, 'bool ', decode_function) + + if disassemble: + output("(char *dstr, size_t maxd, ") + else: + output('(DisasContext *ctx, ') + + output(insntype, ' insn)\n{\n') i4 = str_indent(4) output(i4, 'union {\n')