From patchwork Sun Oct 30 22:28:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 620025 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2451402pvb; Sun, 30 Oct 2022 15:34:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6/IeLhDsYeg/w4cnP7seBFzDZOcRQNB40P8VCgiJkOIU7ZseMU71RFGTBQEXajM1PBVZKP X-Received: by 2002:a05:622a:54d:b0:39c:dadc:10db with SMTP id m13-20020a05622a054d00b0039cdadc10dbmr8424256qtx.504.1667169264487; Sun, 30 Oct 2022 15:34:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667169264; cv=none; d=google.com; s=arc-20160816; b=vdyp5HQJf8gAYa3KUo7l7o6JYFazg6wdeYMIb9hUfk1jqxXTG9fd+6IxC/BEPvFvyX hhmxLxj4SdEAg+IQDA/r26g5huakNJpwm3Wp20SS2DZr65Hy4rNZvphOLV5+rSkOzSZ6 RDuJosw697pI5ypZ2nrTYvN/ztB2BzLZqLfGkYjRhI+FcvoQ1m0W4TzgsRLYt8hsAa6K VbDHWQyFqOCdaoXYR98PwnSDZuXJ6KSA822yq0YuVl1dzg9VO0rsjlnA3L3uOrQRNtUm YhnJxcl6rjOUBeFkhKXphlN8pZ8sqRwoM4dbBMfwPcep4a2NhK2MXkFNN8lNhO/Nmfsa DFLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ITJ3L4PwJ5ZsTmRJYtpX31PZ6QQa3WN9qI3FxP4ohSo=; b=DkSw9AmpmzbKqAX0kgO4p0JbiovSyyAVaMsMuDOjb38QEqn/Nn6RVjKS5UqzjHvjrS kBrpICe6+t3stIwyu16vHrMykneoqdmodh5lakDaQKeC1FLi+KyWUcVO4S/E9RYSaA7Q yI9TINVO/WsmmQVEF8PumLt2x47V1E07T0IqNYVleJIZHBu6fNz3IifmfYCSgiYYe3mr QcR07l+6DDfLQHkc85+n7d7KBWlQcMPSRz2KlxswtQO7ONjC0Uv9ZtT2yyvOsI8JSChf 1y17Rtk/XQzwdsqN1BXfdqY2VdcZDnUUJeQIXxIURK67mPExTj/IFZV+fEyZwMoxgCgd RYJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="yqfyFZw/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 10-20020a05620a070a00b006fa299566bcsi927697qkc.581.2022.10.30.15.34.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 30 Oct 2022 15:34:24 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="yqfyFZw/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1opGpu-0006NM-O2; Sun, 30 Oct 2022 18:31:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1opGpt-0006KQ-VU for qemu-devel@nongnu.org; Sun, 30 Oct 2022 18:31:21 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1opGpr-0008BD-St for qemu-devel@nongnu.org; Sun, 30 Oct 2022 18:31:21 -0400 Received: by mail-wr1-x42a.google.com with SMTP id o4so13670761wrq.6 for ; Sun, 30 Oct 2022 15:31:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ITJ3L4PwJ5ZsTmRJYtpX31PZ6QQa3WN9qI3FxP4ohSo=; b=yqfyFZw/G/u5t1W4Q9dJIxiXyw23pQmFELyTrblG33sL5gdUBbBz5PPgmLOYLHZrDU SbxOdRIU4W05TFprolos+ylto2tKHoB2TasoVOWQCLVFFReq+GGST3nHHJ2J1TvbQysm hKYdunYj0+zMhlFTM5ZJtJhaUhOGVR6IilSdSijeAGWGGfEUm6E1jdUI4yCB77rlMvzn Jc+jHQY35WxCkKw0rzGUG5dMpg+RfVdUOfIVrb2tIjwPEqNvYoeFzs21lU0CD6/DsWDy 5xS99/FLinl4PMPUJ7dE7fXVbQtQID7grGZINU9WRFnza0siv8O40tSKW88gQT4p9qZ5 IpMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ITJ3L4PwJ5ZsTmRJYtpX31PZ6QQa3WN9qI3FxP4ohSo=; b=0AyMrtL6XAJPtl0qYuRKZwiqjw33nUn0/MgM3Wx4k9twPT0YE7xNlKzhoYE03FNc0X VdggnV3ltd2g+3GIiHhthDLJH614xV7YsPK7FyP48v2WLptPcY3gAx4MWMT2hm7k6giK LaRuhFyFWn/R9h7bBIQUaQFvWKqaq/32PG52QNbsS9ZASLHEY7j5BAPYPAPeEvuYNS6B qDd2M+jBwMj8XBbdgHy3WyhcRl9YwcwDd7wsryncgKV5zxfyD7CmW0T3VA19WhqZw2Aa dr7xYScErKkLAy8HDRTJB3DQGrmGDuS559jvemEeedeaLXYRhJTL5yG53PKI+CQ60xRu uhqQ== X-Gm-Message-State: ACrzQf0JGAohqJJdJRqKF5KIfbVswg0MWDgS6CBGw0hzwoWx625AizcX fG8jupFKO4lRma2ptmYLYnZ0RkAQpOehgQ== X-Received: by 2002:a5d:4604:0:b0:236:cfce:879d with SMTP id t4-20020a5d4604000000b00236cfce879dmr359677wrq.152.1667169078265; Sun, 30 Oct 2022 15:31:18 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id bv5-20020a0560001f0500b0022ac38fb20asm5211947wrb.111.2022.10.30.15.31.16 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 30 Oct 2022 15:31:17 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Aleksandar Rikalo , Huacai Chen , Stefan Pejic , Jiaxun Yang , Aurelien Jarno , Paul Burton , Milica Lazarevic , Richard Henderson Subject: [PULL 23/55] disas/nanomips: Remove NMD class Date: Sun, 30 Oct 2022 23:28:09 +0100 Message-Id: <20221030222841.42377-24-philmd@linaro.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221030222841.42377-1-philmd@linaro.org> References: <20221030222841.42377-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=philmd@linaro.org; helo=mail-wr1-x42a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Milica Lazarevic NMD class has been deleted. The following methods are now declared as static functions: - public NMD::Disassemble method - private NMD::Disassemble method - private NMD::extract_op_code_value helper method Also, the implementation of the print_insn_nanomips function and nanomips_dis function is moved to the end of the nanomips.cpp file, right after the implementation of the Disassemble function. Signed-off-by: Milica Lazarevic Reviewed-by: Richard Henderson Message-Id: <20220912122635.74032-10-milica.lazarevic@syrmia.com> Signed-off-by: Philippe Mathieu-Daudé --- disas/nanomips.cpp | 204 ++++++++++++++++++++++----------------------- disas/nanomips.h | 15 ---- 2 files changed, 101 insertions(+), 118 deletions(-) diff --git a/disas/nanomips.cpp b/disas/nanomips.cpp index a73eae5b33..0d67462e5d 100644 --- a/disas/nanomips.cpp +++ b/disas/nanomips.cpp @@ -41,105 +41,6 @@ #define IMGASSERTONCE(test) -static int nanomips_dis(char *buf, - Dis_info *info, - unsigned short one, - unsigned short two, - unsigned short three) -{ - std::string disasm; - uint16 bits[3] = {one, two, three}; - - TABLE_ENTRY_TYPE type; - NMD d; - int size = d.Disassemble(bits, disasm, type, info); - - strcpy(buf, disasm.c_str()); - return size; -} - -int print_insn_nanomips(bfd_vma memaddr, struct disassemble_info *info) -{ - int status; - bfd_byte buffer[2]; - uint16_t insn1 = 0, insn2 = 0, insn3 = 0; - char buf[200]; - - info->bytes_per_chunk = 2; - info->display_endian = info->endian; - info->insn_info_valid = 1; - info->branch_delay_insns = 0; - info->data_size = 0; - info->insn_type = dis_nonbranch; - info->target = 0; - info->target2 = 0; - - Dis_info disassm_info; - disassm_info.m_pc = memaddr; - - status = (*info->read_memory_func)(memaddr, buffer, 2, info); - if (status != 0) { - (*info->memory_error_func)(status, memaddr, info); - return -1; - } - - if (info->endian == BFD_ENDIAN_BIG) { - insn1 = bfd_getb16(buffer); - } else { - insn1 = bfd_getl16(buffer); - } - (*info->fprintf_func)(info->stream, "%04x ", insn1); - - /* Handle 32-bit opcodes. */ - if ((insn1 & 0x1000) == 0) { - status = (*info->read_memory_func)(memaddr + 2, buffer, 2, info); - if (status != 0) { - (*info->memory_error_func)(status, memaddr + 2, info); - return -1; - } - - if (info->endian == BFD_ENDIAN_BIG) { - insn2 = bfd_getb16(buffer); - } else { - insn2 = bfd_getl16(buffer); - } - (*info->fprintf_func)(info->stream, "%04x ", insn2); - } else { - (*info->fprintf_func)(info->stream, " "); - } - /* Handle 48-bit opcodes. */ - if ((insn1 >> 10) == 0x18) { - status = (*info->read_memory_func)(memaddr + 4, buffer, 2, info); - if (status != 0) { - (*info->memory_error_func)(status, memaddr + 4, info); - return -1; - } - - if (info->endian == BFD_ENDIAN_BIG) { - insn3 = bfd_getb16(buffer); - } else { - insn3 = bfd_getl16(buffer); - } - (*info->fprintf_func)(info->stream, "%04x ", insn3); - } else { - (*info->fprintf_func)(info->stream, " "); - } - - int length = nanomips_dis(buf, &disassm_info, insn1, insn2, insn3); - - /* FIXME: Should probably use a hash table on the major opcode here. */ - - (*info->fprintf_func) (info->stream, "%s", buf); - if (length > 0) { - return length / 8; - } - - info->insn_type = dis_noninsn; - - return insn3 ? 6 : insn2 ? 4 : 2; -} - - std::string img_format(const char *format, ...) { char buffer[256]; @@ -739,7 +640,7 @@ static std::string ADDRESS(uint64 value, int instruction_size, Dis_info *info) } -uint64 NMD::extract_op_code_value(const uint16 * data, int size) +static uint64 extract_op_code_value(const uint16 *data, int size) { switch (size) { case 16: @@ -765,7 +666,7 @@ uint64 NMD::extract_op_code_value(const uint16 * data, int size) * instruction size - negative is error * disassembly string - on error will constain error string */ -int NMD::Disassemble(const uint16 * data, std::string & dis, +static int Disassemble(const uint16 *data, std::string & dis, TABLE_ENTRY_TYPE & type, const Pool *table, int table_size, Dis_info *info) { @@ -22348,8 +22249,105 @@ static const Pool MAJOR[2] = { 0x0 }, /* P16 */ }; -int NMD::Disassemble(const uint16 *data, std::string & dis, - TABLE_ENTRY_TYPE & type, Dis_info *info) +static int Disassemble(const uint16 *data, std::string & dis, + TABLE_ENTRY_TYPE & type, Dis_info *info) { return Disassemble(data, dis, type, MAJOR, 2, info); } + +static int nanomips_dis(char *buf, + Dis_info *info, + unsigned short one, + unsigned short two, + unsigned short three) +{ + std::string disasm; + uint16 bits[3] = {one, two, three}; + + TABLE_ENTRY_TYPE type; + int size = Disassemble(bits, disasm, type, info); + + strcpy(buf, disasm.c_str()); + return size; +} + +int print_insn_nanomips(bfd_vma memaddr, struct disassemble_info *info) +{ + int status; + bfd_byte buffer[2]; + uint16_t insn1 = 0, insn2 = 0, insn3 = 0; + char buf[200]; + + info->bytes_per_chunk = 2; + info->display_endian = info->endian; + info->insn_info_valid = 1; + info->branch_delay_insns = 0; + info->data_size = 0; + info->insn_type = dis_nonbranch; + info->target = 0; + info->target2 = 0; + + Dis_info disassm_info; + disassm_info.m_pc = memaddr; + + status = (*info->read_memory_func)(memaddr, buffer, 2, info); + if (status != 0) { + (*info->memory_error_func)(status, memaddr, info); + return -1; + } + + if (info->endian == BFD_ENDIAN_BIG) { + insn1 = bfd_getb16(buffer); + } else { + insn1 = bfd_getl16(buffer); + } + (*info->fprintf_func)(info->stream, "%04x ", insn1); + + /* Handle 32-bit opcodes. */ + if ((insn1 & 0x1000) == 0) { + status = (*info->read_memory_func)(memaddr + 2, buffer, 2, info); + if (status != 0) { + (*info->memory_error_func)(status, memaddr + 2, info); + return -1; + } + + if (info->endian == BFD_ENDIAN_BIG) { + insn2 = bfd_getb16(buffer); + } else { + insn2 = bfd_getl16(buffer); + } + (*info->fprintf_func)(info->stream, "%04x ", insn2); + } else { + (*info->fprintf_func)(info->stream, " "); + } + /* Handle 48-bit opcodes. */ + if ((insn1 >> 10) == 0x18) { + status = (*info->read_memory_func)(memaddr + 4, buffer, 2, info); + if (status != 0) { + (*info->memory_error_func)(status, memaddr + 4, info); + return -1; + } + + if (info->endian == BFD_ENDIAN_BIG) { + insn3 = bfd_getb16(buffer); + } else { + insn3 = bfd_getl16(buffer); + } + (*info->fprintf_func)(info->stream, "%04x ", insn3); + } else { + (*info->fprintf_func)(info->stream, " "); + } + + int length = nanomips_dis(buf, &disassm_info, insn1, insn2, insn3); + + /* FIXME: Should probably use a hash table on the major opcode here. */ + + (*info->fprintf_func) (info->stream, "%s", buf); + if (length > 0) { + return length / 8; + } + + info->insn_type = dis_noninsn; + + return insn3 ? 6 : insn2 ? 4 : 2; +} diff --git a/disas/nanomips.h b/disas/nanomips.h index c56fc32b1e..47b44af751 100644 --- a/disas/nanomips.h +++ b/disas/nanomips.h @@ -80,19 +80,4 @@ typedef struct Pool { uint64 attributes; } Pool; -class NMD -{ -public: - - int Disassemble(const uint16 *data, std::string & dis, - TABLE_ENTRY_TYPE & type, Dis_info *info); - -private: - - uint64 extract_op_code_value(const uint16 *data, int size); - int Disassemble(const uint16 *data, std::string & dis, - TABLE_ENTRY_TYPE & type, const Pool *table, int table_size, - Dis_info *info); -}; - #endif