From patchwork Wed Jun 5 21:15:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 801647 Delivered-To: patch@linaro.org Received: by 2002:a5d:5610:0:b0:35b:5a80:51b4 with SMTP id l16csp37299wrv; Wed, 5 Jun 2024 14:19:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCV8yziQy1XgOSYNTAhkYaxkWVzizfUy8BsynVzQB6oIr66P2VcoaIsfZpcOwFrl5B86gVSG1H8PEEU5NnOTA9ZW X-Google-Smtp-Source: AGHT+IHiAggqXQ5FVADjmRx+3PGuYY+qxbDZztaeKg+K9wGeI/VZycWGAWe4VJBCmKS9DfKBmBgn X-Received: by 2002:a05:6830:1d44:b0:6f0:e6e2:83b4 with SMTP id 46e09a7af769-6f943435316mr4076024a34.11.1717622346715; Wed, 05 Jun 2024 14:19:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717622346; cv=none; d=google.com; s=arc-20160816; b=fGedtbCjrUM79qY9FXSiN6prGabYuPSqoqm/xxQsMIal4Wf/rMzVC3ZL4B3clcP9qy Y/8U0y/LpAzTA4M94E95JU/cqHUB7/JWbk/UhVD4qPtBIPOX8THguQ3Y6G5+Wa+5K7nt 0fjMoWkH+tBL7neylqHtkGyxeF4E0tWb4gixpKEfjOeXBQCwRqJnI9+q73/h/HyZidxP rCmpwxA7tABYdVEVztkXTwu77XHO5My+miAqkIXX8bB+Cv3hu9j9qv+LbrqQdcpc9w83 ht0B5bLjGzOGg16wpKo+d+1IwOUkQMwdyhmWBLhp4QSUrWKA8J3hXvqfxFumsYhXLhvw EzFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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:to:from :dkim-signature; bh=jmQ99CuVUixUPYiVE7xGV4zGNIbhyMF+JitbLNxBw0o=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=AbyHtF7kwiP/EY3VbzyBRw79DvRbjRAuB2LsRCSsjM3pAqHcGdzyNcjMcZ2mdhc4lj 7B5VIkDC42boWglS270lfrbJ4GIb9/Z6elXEPLTaUCcucHm/EUHPJrQ1Z/0pqbBAtiPy Cuef+Sup/Ea/LUz8RIXGRSxu1z6TGjFoaghHsYp4nCooPkEnYZkIDKloyin1PuYlCe7e BliZi7PpzI+6Zu7vICeMAn4IfRdAvypTXZyCx7aFDF0SxXsBjPa6Mm2K2EA832EP4655 mcymsF0XJVacoewUUZJi4v2p6BAz56/bdDC5nRNRsrwd8LZmHMG+0JWHmkOyZUkOup6M hvtg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WNQ2F0ia; 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 d75a77b69052e-44025cfddffsi43741281cf.801.2024.06.05.14.19.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jun 2024 14:19:06 -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=WNQ2F0ia; 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 1sExyr-0000c5-Je; Wed, 05 Jun 2024 17:15:37 -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 1sExyn-0000bB-NR for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:33 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sExyg-0003NU-NP for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:31 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-7024cd9dd3dso194825b3a.3 for ; Wed, 05 Jun 2024 14:15:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717622124; x=1718226924; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=jmQ99CuVUixUPYiVE7xGV4zGNIbhyMF+JitbLNxBw0o=; b=WNQ2F0iaOcHO3J6nVUQmpSJ1/rGj2cy1IJECvqZ1jtjl6uF9OWpPJyj8KUmcMKyw/x XZ4ib6+S7yd3rowQCl7HNJrbG3x43SishYVna+r4kZgjHeUp1LSJcn5I5K4pC4/1HOhe 5xBGI9Sqo+h8aDkoqw3qf6D8VMyBeGejGKgJUTsm5jfl6tb4n8AOm1g7MpjKdPBgjgAF B9FzohcuSriVGDu9UNfuHRT7junD2sJDAeYOaWBv6+UBD3iihQuZ7o5hDfYf8MSRdqX9 P2N1+5johABXt3c3LdqQY33Ch5kJEL1uw0VzT1yaw8sMWi3N60deRu5nvzqBq32JlBTW jUWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717622124; x=1718226924; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jmQ99CuVUixUPYiVE7xGV4zGNIbhyMF+JitbLNxBw0o=; b=Q8OaNkBLGiP3nE+hSbpOYzGsJ8OV7RvsvUbpJlev9XM+dI4Vkiuw6B71y/iFz5KgyX x/XayN0ZJj+Uuf+y03OoMRIFP5E3869saNuECWHi3UyqgZTM7RAfm2yE97sbEwHmnfs8 4KydIfA2bmsRV5rWBLAw3Mrj5z5fM9iyRWECfKj1wd9YQS6m1R/Q4bkiw24er1f8l1O2 JKZh+/O9Cww8Y1x1/A+f2dRKlWznA8iXWYoEgbUwVYyg14eS6PShRvsxeoNl4JHWU6jm aAejjRQOjCE15vSVSsgtIloOdnzcqKEpaMoZlmU3uxPldtQsz3m5lhgmaPbXrfGfeiLM lyQA== X-Gm-Message-State: AOJu0YzLYLAyji9YJ+pri9zNFCOwt7jo8G/E+EBSm/C51asCRMjQ75Ru dyybmgUCJbgEPk0CB8D8g36KwaCGTnE9UMb+e6WBDB47zriePwKloCu0SVoZKo4ACnl+JU0b2EB k X-Received: by 2002:a05:6a00:194b:b0:6ed:4288:68bc with SMTP id d2e1a72fcca58-703e59bb6aamr4140262b3a.19.1717622123610; Wed, 05 Jun 2024 14:15:23 -0700 (PDT) Received: from stoup.. ([71.212.132.216]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70242aec7d0sm9347538b3a.99.2024.06.05.14.15.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 14:15:23 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PULL 01/16] util/hexdump: Use a GString for qemu_hexdump_line Date: Wed, 5 Jun 2024 14:15:06 -0700 Message-Id: <20240605211521.577094-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605211521.577094-1-richard.henderson@linaro.org> References: <20240605211521.577094-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42e.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, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Allocate a new, or append to an existing GString instead of using a fixed sized buffer. Require the caller to determine the length of the line -- do not bound len here. Signed-off-by: Richard Henderson Message-Id: <20240412073346.458116-4-richard.henderson@linaro.org> --- include/qemu/cutils.h | 15 ++++++++++----- hw/virtio/vhost-vdpa.c | 14 ++++++++------ util/hexdump.c | 27 ++++++++++++++++----------- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h index c5dea63742..14a3285343 100644 --- a/include/qemu/cutils.h +++ b/include/qemu/cutils.h @@ -282,12 +282,17 @@ static inline const char *yes_no(bool b) */ int parse_debug_env(const char *name, int max, int initial); -/* - * Hexdump a line of a byte buffer into a hexadecimal/ASCII buffer +/** + * qemu_hexdump_line: + * @str: GString into which to append + * @buf: buffer to dump + * @len: number of bytes to dump + * + * Append @len bytes of @buf as hexadecimal into @str. + * If @str is NULL, allocate a new string and return it; + * otherwise return @str. */ -#define QEMU_HEXDUMP_LINE_BYTES 16 /* Number of bytes to dump */ -#define QEMU_HEXDUMP_LINE_LEN 75 /* Number of characters in line */ -void qemu_hexdump_line(char *line, const void *bufptr, size_t len); +GString *qemu_hexdump_line(GString *str, const void *buf, size_t len); /* * Hexdump a buffer to a file. An optional string prefix is added to every line diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 7368b71902..419463c154 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -944,13 +944,15 @@ static int vhost_vdpa_set_config_call(struct vhost_dev *dev, static void vhost_vdpa_dump_config(struct vhost_dev *dev, const uint8_t *config, uint32_t config_len) { - int b, len; - char line[QEMU_HEXDUMP_LINE_LEN]; + g_autoptr(GString) str = g_string_sized_new(4 * 16); + size_t b, len; - for (b = 0; b < config_len; b += 16) { - len = config_len - b; - qemu_hexdump_line(line, config + b, len); - trace_vhost_vdpa_dump_config(dev, b, line); + for (b = 0; b < config_len; b += len) { + len = MIN(config_len - b, 16); + + g_string_truncate(str, 0); + qemu_hexdump_line(str, config + b, len); + trace_vhost_vdpa_dump_config(dev, b, str->str); } } diff --git a/util/hexdump.c b/util/hexdump.c index 0f943e31e5..521e346bc6 100644 --- a/util/hexdump.c +++ b/util/hexdump.c @@ -16,22 +16,25 @@ #include "qemu/osdep.h" #include "qemu/cutils.h" -void qemu_hexdump_line(char *line, const void *bufptr, size_t len) +GString *qemu_hexdump_line(GString *str, const void *vbuf, size_t len) { - const char *buf = bufptr; - int i; + const uint8_t *buf = vbuf; + size_t i; - if (len > QEMU_HEXDUMP_LINE_BYTES) { - len = QEMU_HEXDUMP_LINE_BYTES; + if (str == NULL) { + /* Estimate the length of the output to avoid reallocs. */ + i = len * 3 + len / 4; + str = g_string_sized_new(i + 1); } for (i = 0; i < len; i++) { if (i != 0 && (i % 4) == 0) { - *line++ = ' '; + g_string_append_c(str, ' '); } - line += sprintf(line, " %02x", (unsigned char)buf[i]); + g_string_append_printf(str, " %02x", buf[i]); } - *line = '\0'; + + return str; } static void asciidump_line(char *line, const void *bufptr, size_t len) @@ -49,24 +52,26 @@ static void asciidump_line(char *line, const void *bufptr, size_t len) *line = '\0'; } +#define QEMU_HEXDUMP_LINE_BYTES 16 #define QEMU_HEXDUMP_LINE_WIDTH \ (QEMU_HEXDUMP_LINE_BYTES * 2 + QEMU_HEXDUMP_LINE_BYTES / 4) void qemu_hexdump(FILE *fp, const char *prefix, const void *bufptr, size_t size) { - char line[QEMU_HEXDUMP_LINE_LEN]; + g_autoptr(GString) str = g_string_sized_new(QEMU_HEXDUMP_LINE_WIDTH + 1); char ascii[QEMU_HEXDUMP_LINE_BYTES + 1]; size_t b, len; for (b = 0; b < size; b += len) { len = MIN(size - b, QEMU_HEXDUMP_LINE_BYTES); - qemu_hexdump_line(line, bufptr + b, len); + g_string_truncate(str, 0); + qemu_hexdump_line(str, bufptr + b, len); asciidump_line(ascii, bufptr + b, len); fprintf(fp, "%s: %04zx: %-*s %s\n", - prefix, b, QEMU_HEXDUMP_LINE_WIDTH, line, ascii); + prefix, b, QEMU_HEXDUMP_LINE_WIDTH, str->str, ascii); } } From patchwork Wed Jun 5 21:15:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 801636 Delivered-To: patch@linaro.org Received: by 2002:a5d:5610:0:b0:35b:5a80:51b4 with SMTP id l16csp36295wrv; Wed, 5 Jun 2024 14:16:19 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCU3mvfX9Y8MEVzJyL2ILlJbGLvYjvtfPa5TTFg1zqDYGKFXgSDdk+DcXWSMxY8NMJYeUbRFueTdhRF4klek+9oJ X-Google-Smtp-Source: AGHT+IFOMyTpILdh/I6LJUG5mAzRdqjUZdiyZJMDr4iPTEN1w1KkiAMi3U50x7Rka7gvIzYyyxap X-Received: by 2002:a05:622a:3d1:b0:43d:e767:f106 with SMTP id d75a77b69052e-440362c9f7amr17809411cf.30.1717622179614; Wed, 05 Jun 2024 14:16:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717622179; cv=none; d=google.com; s=arc-20160816; b=Fy3KI7v8ZSlTdpU/y5b3+mfoAx4uH+S13cO91xIuB0XUiJ7q4VA6MBna0gXfF/SWHC ZKZxYppX5F819yUVvhIVW5dfM9iYKrRprwmWGPMC8K6ff37XxNNJRnNfhSF4aHqnzNDo 09GebcVtWLUZ1kk2z/Yi6rX5hbnIYxAdAys6X7yvfoNfLewFSIyQIUfpl32bbSpKhmBy 8SxDN2sZnmCTKT9BpvOddYNpz5XLl5Y4pvS3tGk5i1UVkdIlzL8PQ/AJvt4mnXm9bPd2 aaYAWmrAcCHKbBXc5gDf8olOiAt7fR6RQngjo70g5X7b7Rc0WoEfwjJPP4AI922miUsC kvAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=bXrzk8wYIq+rswdQhA3YXFWLO6A516BGL94YqrvehJo=; fh=kQadAhxV42GJ3cd2VUw1RyURv/zJQGvmUdF7iLEVTtc=; b=ToeiRZeGqfqqF439Fj3o8K5SrJ//2aStVdLeYZGfdFltmwkzLoRRRrgS1JzfEoQ9CM 2/p5T0kymvXB4VJXgWeDeWwy6Wz9FwDQeAqrlrOedPzPqeq7tjgTaCbny1mii7k7VIPx FjHYf8SQAyWIAo0cTQQpQzCLJgdzrguaJh6kQU47os1smdrbFW72WPfKkcT9zj83Gos1 /wMW2DpNMUB8188kiEnOjiMDqg3lFdnKdhzw9AccgFj7ixd5HFDc1Rr+dIE2ljVVRx4c dkuGe/xRwkk7GXiZg2KwEarzkpvHzUuEgAoUNutQulweXFqw7YhX9wEzTDNVn5Re/nUA SzGw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tLWVGEFc; 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 d75a77b69052e-4401c5bb2ccsi53522251cf.733.2024.06.05.14.16.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jun 2024 14:16:19 -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=tLWVGEFc; 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 1sExyq-0000bg-VH; Wed, 05 Jun 2024 17:15:37 -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 1sExyn-0000bA-NN for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:33 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sExyh-0003PB-8M for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:32 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-70260814b2dso170306b3a.1 for ; Wed, 05 Jun 2024 14:15:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717622125; x=1718226925; darn=nongnu.org; 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=bXrzk8wYIq+rswdQhA3YXFWLO6A516BGL94YqrvehJo=; b=tLWVGEFcmkPuQeLPS498yUhqhZXKb4+MiiblCrqAyfRjGW4vIrd8GCxBqts6RtUw6s 2apYz6d7f8JL2Qv98PPCFU6loZdKCMC5zl6wmLcpC7q11J5/RWzWzjib2S1MJ9CU93Zm /E+M0oB9EW0W62ZgiWCvdfwTneGbZHMphzf6Y5QEW8iLhoun+NXib2VMPU6aL7dA2GNF 2RnzeDyiNqU8JaUcM2spKZVjQD76wZIKSrHZnV/cQuZVWsrF+WseFfdMj8lk75rX77f2 J3wDkSK5E15HcpRfWV5mQkTSRgLuTTkh/58RtIKPgOzdHflB90ZM6ZXv0JFF6NmM4Lfr FSCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717622125; x=1718226925; 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=bXrzk8wYIq+rswdQhA3YXFWLO6A516BGL94YqrvehJo=; b=KgTiFyBGw4aef3gE9RUmMK9wcKrQODOTf1lZp7L2L3OzUVkv3yW3sIyLvRiGGxRi/J ZEZsJxY/eVnszZWQS8+QFq+ozAKK1VwCAnqXBBE85SM1oreUZdBIF4rOVM8/2c6Ln81C /lgoM+Xa7FSUz9x2VU6KBiMBQoPKFAwsn+x3qus9AQj6Cr2I0bdLavZvXKWWE6uZVUey YicEG8xuqV4liHsgojZ2wzUV6JRU+zdQbdTsRCe4y0uAA9VC4C3JdLa2imkBkAK4V5zb M16o1LqqgsLVnLUo1AgucmseFSpru4Gg3NcTC5OrYq/2CcGpA5meBNbu6ACfbDwYTOEN g0vA== X-Gm-Message-State: AOJu0YxVKt5lNUgjnIqfB+GReO2jHhdvhz+5+zuWcNJUntEgsi46bzu6 KZOi4sUgTVURx+j2U4ILGc/auOphmrZUPWoUmb9VdcsVAbRm4YOY8pbCrxIXIStJImuoSkw24bT c X-Received: by 2002:a05:6a00:4fd4:b0:6f6:76c8:122c with SMTP id d2e1a72fcca58-703f88a3f75mr997990b3a.16.1717622124539; Wed, 05 Jun 2024 14:15:24 -0700 (PDT) Received: from stoup.. ([71.212.132.216]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70242aec7d0sm9347538b3a.99.2024.06.05.14.15.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 14:15:24 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 02/16] util/hexdump: Add unit_len and block_len to qemu_hexdump_line Date: Wed, 5 Jun 2024 14:15:07 -0700 Message-Id: <20240605211521.577094-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605211521.577094-1-richard.henderson@linaro.org> References: <20240605211521.577094-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x435.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, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Generalize the current 1 byte unit and 4 byte blocking within the output. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20240412073346.458116-5-richard.henderson@linaro.org> --- include/qemu/cutils.h | 6 +++++- hw/virtio/vhost-vdpa.c | 2 +- util/hexdump.c | 30 +++++++++++++++++++++--------- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h index 14a3285343..da15547bfb 100644 --- a/include/qemu/cutils.h +++ b/include/qemu/cutils.h @@ -287,12 +287,16 @@ int parse_debug_env(const char *name, int max, int initial); * @str: GString into which to append * @buf: buffer to dump * @len: number of bytes to dump + * @unit_len: add a space between every @unit_len bytes + * @block_len: add an extra space between every @block_len bytes * * Append @len bytes of @buf as hexadecimal into @str. + * Add spaces between every @unit_len and @block_len bytes. * If @str is NULL, allocate a new string and return it; * otherwise return @str. */ -GString *qemu_hexdump_line(GString *str, const void *buf, size_t len); +GString *qemu_hexdump_line(GString *str, const void *buf, size_t len, + size_t unit_len, size_t block_len); /* * Hexdump a buffer to a file. An optional string prefix is added to every line diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 419463c154..3cdaa12ed5 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -951,7 +951,7 @@ static void vhost_vdpa_dump_config(struct vhost_dev *dev, const uint8_t *config, len = MIN(config_len - b, 16); g_string_truncate(str, 0); - qemu_hexdump_line(str, config + b, len); + qemu_hexdump_line(str, config + b, len, 1, 4); trace_vhost_vdpa_dump_config(dev, b, str->str); } } diff --git a/util/hexdump.c b/util/hexdump.c index 521e346bc6..b29326b7f2 100644 --- a/util/hexdump.c +++ b/util/hexdump.c @@ -1,5 +1,5 @@ /* - * Helper to hexdump a buffer +* Helper to hexdump a buffer * * Copyright (c) 2013 Red Hat, Inc. * Copyright (c) 2013 Gerd Hoffmann @@ -16,22 +16,34 @@ #include "qemu/osdep.h" #include "qemu/cutils.h" -GString *qemu_hexdump_line(GString *str, const void *vbuf, size_t len) +GString *qemu_hexdump_line(GString *str, const void *vbuf, size_t len, + size_t unit_len, size_t block_len) { const uint8_t *buf = vbuf; - size_t i; + size_t u, b; if (str == NULL) { /* Estimate the length of the output to avoid reallocs. */ - i = len * 3 + len / 4; - str = g_string_sized_new(i + 1); + size_t est = len * 2; + if (unit_len) { + est += len / unit_len; + } + if (block_len) { + est += len / block_len; + } + str = g_string_sized_new(est + 1); } - for (i = 0; i < len; i++) { - if (i != 0 && (i % 4) == 0) { + for (u = 0, b = 0; len; u++, b++, len--, buf++) { + if (unit_len && u == unit_len) { g_string_append_c(str, ' '); + u = 0; } - g_string_append_printf(str, " %02x", buf[i]); + if (block_len && b == block_len) { + g_string_append_c(str, ' '); + b = 0; + } + g_string_append_printf(str, "%02x", *buf); } return str; @@ -67,7 +79,7 @@ void qemu_hexdump(FILE *fp, const char *prefix, len = MIN(size - b, QEMU_HEXDUMP_LINE_BYTES); g_string_truncate(str, 0); - qemu_hexdump_line(str, bufptr + b, len); + qemu_hexdump_line(str, bufptr + b, len, 1, 4); asciidump_line(ascii, bufptr + b, len); fprintf(fp, "%s: %04zx: %-*s %s\n", From patchwork Wed Jun 5 21:15:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 801645 Delivered-To: patch@linaro.org Received: by 2002:a5d:5610:0:b0:35b:5a80:51b4 with SMTP id l16csp37008wrv; Wed, 5 Jun 2024 14:18:12 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXndlSYQC+76WJEHXWCi7k7qIxaibKwnaZsk2LCL7fEJZYM/AirZzyl9q6mORhU0Yx797XiedC0x3XDMzIn7o+4 X-Google-Smtp-Source: AGHT+IGV8Au2uTtY+BVuNDNp1wjeIogcVAYxc/bkZFqTb//c5lW6j77f1tr6i3gNxRe9xBI79wJh X-Received: by 2002:a05:6e02:1b09:b0:374:9f16:d7 with SMTP id e9e14a558f8ab-374b1f027fcmr40680545ab.13.1717622292546; Wed, 05 Jun 2024 14:18:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717622292; cv=none; d=google.com; s=arc-20160816; b=AxkMTWCUL+X9eDT2jgsjecYJsiaUkLa6MT8ZONsi2y5kQLx6uVMcraV/qjjQozJJMh +Jutn/aP8b3rjMl7om2S4bkRt1UPxw6kI7VD/eFv27xK5PtqvvYhqLL8FXTF9nLkEt8Y 2sntc4Bn7brBjuY1BXwZafnm9dYk+pszQ1zhnRqPMYp/Z5l9+Kj7wfvwtwNBTV+3dXc/ Y1m4Fq+JPATiZLRGIi952Ni9j2+lp4zMsp+BGdphoBmHCrDkOLGwnsq1x5H3ziRYosOB kSVQvEA5fZCIvKQEyqjCpRYdbFPf0vlQ1emmga4LPSS/67oQwU0QsjnF1Di6Mwt3h50C PqpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=DtdfLvGNq7oKYg7RFoNL4PoVXIIUjVrx0tqYusGM3x8=; fh=kQadAhxV42GJ3cd2VUw1RyURv/zJQGvmUdF7iLEVTtc=; b=Vqvfc7RmfsGezEedfH1WVqQt0S2KAWQMfHGnbd4yTSIOB5qbCE+nhccoHfzBDQdd4d Mwyt4+G1YzcFoh3VH6Ru8Nu6GKEiUpOOK44h08jYHwhMhgXnArAolQYoKNfVUog4UE1w gVHQRdl5S4bW1sXr/brRSgHCxwQRBs8p+JKY0XHzfapo/oCfuBgRD0piiCMloDlhfG6P jpi22vpo0gSnrJ+lmd8JW1Nv7CdyOJOdLcaumheM5MFw2xJh+sIgI9N7zf7hUMA2Eoue 9V2HmG4S/Vu9bJumkIekrKKUVVlO62Xgir31mhrIfenMXUZqXAW2kP/K6rqyovWA/sFh ymgg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="W/vBvgb6"; 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 af79cd13be357-7951f10e1b6si375082885a.432.2024.06.05.14.18.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jun 2024 14:18:12 -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="W/vBvgb6"; 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 1sExz0-0000eJ-Gs; Wed, 05 Jun 2024 17:15:46 -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 1sExyt-0000cA-4y for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:39 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sExyi-0003PI-8E for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:36 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-703ed15b273so231564b3a.1 for ; Wed, 05 Jun 2024 14:15:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717622126; x=1718226926; darn=nongnu.org; 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=DtdfLvGNq7oKYg7RFoNL4PoVXIIUjVrx0tqYusGM3x8=; b=W/vBvgb6b9uNTvDGoTZk04dmdVx4wQFRskozZSwCg02r5VhMJZyr9eNFE4/+D9vilY BETNF5yQSMt67uTArEYYDhj8sSj7FXhJR3Tljq94QI0BeNlyTGGGmnCdHrlg/wcdFv47 fZrGEFSeHkjR6RnQOgl086v0jrAkNeQUmeUisP7mUB2rRzvOFJZLOX+XtfXM3kNsFoU3 o5qFxw2fq1RLh9IAuOJ7tIrSR7cztQ6MbR/8t2Ek2gnst9iKeb4U+GFkJN74qxDdqkxw c8BpuRnJCs6oWahYmw7C84aYJLmtBA4qJbE96qlPmUImeXnR1I0aMZP0Zox3VCrjwDJw 1SlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717622126; x=1718226926; 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=DtdfLvGNq7oKYg7RFoNL4PoVXIIUjVrx0tqYusGM3x8=; b=mbw7U6YVBOkqbO6jF24eOEyzojZdTFTMx0yGemha1+S1J+0/IfsZjRVPCys9KoYh6n YM+W/andBCcaMfMDk+lJwOcfFxVWl8VBoyuE1QqAXkI5TmyZmITUsxCEtIr5y7SeFsT6 b8n/a2DVWb9yL8JTnwnGIS371OyF34EsXc8XDlMAsIQXGS9bP42jZgJgPl240O7KzDsx 9gHWLpevxiZ9dKSqKWuvnwEfm526ZEm3HUtISM8jZxsE1rcbXwG1u1iYmKPoqBj6ey/M WizXGm7YvZ2sC9LZaEyzmPEjFpKtu4JeSNGzOrWHNdYE8SCkRUr17/yc5pEA4z57ve0A pFSw== X-Gm-Message-State: AOJu0Yy2XlAOPtT8z5hPhStVO751b5ewI8arHU6S2tKG4xcjLBA42FGf mUOWoEzy5yQRFs/z65pdcUAF6pGg5swyRgHsJhr+etbXYvJ42MlBVTS8oiGOjtdJp8d4ZQUcP3/ j X-Received: by 2002:a05:6a21:3998:b0:1b2:2ed2:b80a with SMTP id adf61e73a8af0-1b2b76374f4mr4477852637.61.1717622125595; Wed, 05 Jun 2024 14:15:25 -0700 (PDT) Received: from stoup.. ([71.212.132.216]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70242aec7d0sm9347538b3a.99.2024.06.05.14.15.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 14:15:25 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 03/16] util/hexdump: Inline g_string_append_printf "%02x" Date: Wed, 5 Jun 2024 14:15:08 -0700 Message-Id: <20240605211521.577094-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605211521.577094-1-richard.henderson@linaro.org> References: <20240605211521.577094-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42c.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, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Trivial arithmetic can be used for emitting the nibbles, rather than full-blown printf formatting. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20240412073346.458116-6-richard.henderson@linaro.org> --- util/hexdump.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/util/hexdump.c b/util/hexdump.c index b29326b7f2..ae0d4992dc 100644 --- a/util/hexdump.c +++ b/util/hexdump.c @@ -16,6 +16,11 @@ #include "qemu/osdep.h" #include "qemu/cutils.h" +static inline char hexdump_nibble(unsigned x) +{ + return (x < 10 ? '0' : 'a' - 10) + x; +} + GString *qemu_hexdump_line(GString *str, const void *vbuf, size_t len, size_t unit_len, size_t block_len) { @@ -35,6 +40,8 @@ GString *qemu_hexdump_line(GString *str, const void *vbuf, size_t len, } for (u = 0, b = 0; len; u++, b++, len--, buf++) { + uint8_t c; + if (unit_len && u == unit_len) { g_string_append_c(str, ' '); u = 0; @@ -43,7 +50,10 @@ GString *qemu_hexdump_line(GString *str, const void *vbuf, size_t len, g_string_append_c(str, ' '); b = 0; } - g_string_append_printf(str, "%02x", *buf); + + c = *buf; + g_string_append_c(str, hexdump_nibble(c / 16)); + g_string_append_c(str, hexdump_nibble(c % 16)); } return str; From patchwork Wed Jun 5 21:15:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 801634 Delivered-To: patch@linaro.org Received: by 2002:a5d:5610:0:b0:35b:5a80:51b4 with SMTP id l16csp36294wrv; Wed, 5 Jun 2024 14:16:19 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXBz4ubmehd+NzzyMLPFLiF5zftNy5f0pcHJF3BAcb1hkHVnj31aYK3I/0Zkx8QeRoLxlCCGfXNaUw/8ELsgotS X-Google-Smtp-Source: AGHT+IEOlhNd/ZJUuf6H6dzHYq67jc2BzccGvrMEAWhr7a9XW8NnCdBXs9SZmj+UFoeVS6meTf1m X-Received: by 2002:a05:6214:3b86:b0:6ae:24da:ba2b with SMTP id 6a1803df08f44-6b04ccd8285mr6684896d6.60.1717622179623; Wed, 05 Jun 2024 14:16:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717622179; cv=none; d=google.com; s=arc-20160816; b=sEwbvinrbs/FZPY1Lo/gi5QufoyrYvFp5TG2H7vyACN8mrzDEBQTDUioCYEP45rlxk AQnmqSKEJZWj8KsfM0wqyAQRpwlvQ7m/ZisEi4HxpTRwPK4cdsbBnGVmnZrjs51xYN4M IHiDGEM7FfcnZz06f5Za36YxFypxeuqXW+/1dksOMib8XcNQgtHsuIyNrJ2JTKUhecOO UzS8tXJOHQ/3KzGG8d41KYlVbD/EPxAk0uIznbhTr2SaXp/CWdb2Zv+lTc3pQzGcVLuA 9ZVLKMZhXCu2UGbgrksHUF9vxtN2lZOkAWdDeyXS+8a2wy52WAYDe8aZJgYUE3IyZM40 YXmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=BA7oin0aTWc6AVl6UHRopsqXqPUuD9tfreQpdBVLhl8=; fh=i/pWNGcx7KiR3ewgypxpPkuORYlkCnVXLqKVm9/UgNc=; b=i3yA3a5TJlwL4PLr0VtqSNKA+5epCsk9Tm6jvVWPrOLJkgoYBoBtPnk9UTNceU4EXU l30WVagAduFobrT6+nCSKrNi40/4Qz4mDycrD21CeR8M17hNgbJMu75DdwhnawHb1/JO 1kC9QGbKtdMdw9b8/CJ24D3nRNAN/1l11O84xlNsR23XjijPKKDFwCVP4E6+hlYxZOzV pI5gjG8WZMS+cL6RBbkdJwMrxYnpC5wLEJ7noEuJWLW6ltPthQI3CBauk0eNHd5d8Mgw vfUEWNqdkLt82wrU+Zotr1OcoHlmLumhREm4RImvSRut9WXSlRRMT/6Db4kCamTKRmIr myyA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iU0qnl2q; 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 d75a77b69052e-44038a6eb6csi80311cf.153.2024.06.05.14.16.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jun 2024 14:16:19 -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=iU0qnl2q; 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 1sExyv-0000ct-2g; Wed, 05 Jun 2024 17:15:41 -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 1sExyt-0000cC-5H for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:39 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sExyi-0003Pb-8I for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:36 -0400 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-70249faa853so185198b3a.3 for ; Wed, 05 Jun 2024 14:15:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717622126; x=1718226926; darn=nongnu.org; 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=BA7oin0aTWc6AVl6UHRopsqXqPUuD9tfreQpdBVLhl8=; b=iU0qnl2qfQDmYuo1qAuthBgF8N/Cn0hRqIgb9bretfYubueqser2bEKndADPZqilHi MlimSH5sEkFCGqDkAwCzDlV/QzqGw8isB43cgl7o0YjzbKa9XFp1xpdgYEDltM8zmL/T phxNi2ggH9B+m3yzAc8tI8P/BapNX+oyQYCDmKq528uDRKTf3n9JfRgYc749Wckex38i o7SU2WpgXrSP8jl0WwANhsU69GOVqcyHyxvBBC54tLWgkQrU/vcFiAnVtzzmaDb8BDLo D4sEXUmTQQkFgJWk8FvE8i7EQMssy8R9RWWnIOOI/uIcAs64waaXKIlT9K/wpCOmAntP EqjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717622126; x=1718226926; 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=BA7oin0aTWc6AVl6UHRopsqXqPUuD9tfreQpdBVLhl8=; b=j/y45uxH4EKNrwlsmjChXh9OH8LzVWUJ6ZTRAqbCugl3G0W413U3rNqyTPIG3jPIkq uVCfKBm5sT8O/+Rg1sRZrC9uKOtxmpzsok+lMmuSW6Ns3frIZab6QAptFUi0Ht7RYrYy S1SVNIEuzNpiCQqPwkhCps3SWaU4fwomBCG6snUg3cjGVqUxh0GJoXEAUISvBw3Zo0ZX nUPT5wvsxgtGSDzo9J7vS21Cop7Shbbx3bxhcdsBdn5hEIYv9k2c+C8RCpMa//4yIEEZ Ygc36BF4PqGMnOGNYJEsVsj5LtoDyl4n+Q83NaTYg05KKC5DZk4dB5u+h3ONUY4NJGYY aW3w== X-Gm-Message-State: AOJu0Yys9UyYfvTKSGwp19d+Z/fOInSEjS2j8xh+7J3oMBw71hoTPJKM 6R8ad2GO3mw46Gn2YC3XSAnh4xXXoSyoRmTDsNLtX17nfaHYPRQVku3DDFZv4v2pMWHr5uFSMSF n X-Received: by 2002:a05:6a20:7348:b0:1af:f8e7:76d4 with SMTP id adf61e73a8af0-1b2b6ed9cbemr4875899637.18.1717622126493; Wed, 05 Jun 2024 14:15:26 -0700 (PDT) Received: from stoup.. ([71.212.132.216]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70242aec7d0sm9347538b3a.99.2024.06.05.14.15.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 14:15:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Pierrick Bouvier Subject: [PULL 04/16] hw/mips/malta: Add re-usable rng_seed_hex_new() method Date: Wed, 5 Jun 2024 14:15:09 -0700 Message-Id: <20240605211521.577094-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605211521.577094-1-richard.henderson@linaro.org> References: <20240605211521.577094-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x431.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, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Philippe Mathieu-Daudé sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1. Extract common code from reinitialize_rng_seed and load_kernel to rng_seed_hex_new. Using qemu_hexdump_line both fixes the deprecation warning and simplifies the code base. Signed-off-by: Philippe Mathieu-Daudé [rth: Use qemu_hexdump_line.] Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier Message-Id: <20240412073346.458116-7-richard.henderson@linaro.org> --- hw/mips/malta.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/hw/mips/malta.c b/hw/mips/malta.c index af74008c82..664a2ae0a9 100644 --- a/hw/mips/malta.c +++ b/hw/mips/malta.c @@ -26,6 +26,7 @@ #include "qemu/units.h" #include "qemu/bitops.h" #include "qemu/datadir.h" +#include "qemu/cutils.h" #include "qemu/guest-random.h" #include "hw/clock.h" #include "hw/southbridge/piix.h" @@ -850,15 +851,18 @@ static void G_GNUC_PRINTF(3, 4) prom_set(uint32_t *prom_buf, int index, va_end(ap); } -static void reinitialize_rng_seed(void *opaque) +static GString *rng_seed_hex_new(void) { - char *rng_seed_hex = opaque; uint8_t rng_seed[32]; qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed)); - for (size_t i = 0; i < sizeof(rng_seed); ++i) { - sprintf(rng_seed_hex + i * 2, "%02x", rng_seed[i]); - } + return qemu_hexdump_line(NULL, rng_seed, sizeof(rng_seed), 0, 0); +} + +static void reinitialize_rng_seed(void *opaque) +{ + g_autoptr(GString) hex = rng_seed_hex_new(); + memcpy(opaque, hex->str, hex->len); } /* Kernel */ @@ -870,8 +874,6 @@ static uint64_t load_kernel(void) uint32_t *prom_buf; long prom_size; int prom_index = 0; - uint8_t rng_seed[32]; - char rng_seed_hex[sizeof(rng_seed) * 2 + 1]; size_t rng_seed_prom_offset; kernel_size = load_elf(loaderparams.kernel_filename, NULL, @@ -946,14 +948,13 @@ static uint64_t load_kernel(void) prom_set(prom_buf, prom_index++, "modetty0"); prom_set(prom_buf, prom_index++, "38400n8r"); - qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed)); - for (size_t i = 0; i < sizeof(rng_seed); ++i) { - sprintf(rng_seed_hex + i * 2, "%02x", rng_seed[i]); - } prom_set(prom_buf, prom_index++, "rngseed"); rng_seed_prom_offset = prom_index * ENVP_ENTRY_SIZE + sizeof(uint32_t) * ENVP_NB_ENTRIES; - prom_set(prom_buf, prom_index++, "%s", rng_seed_hex); + { + g_autoptr(GString) hex = rng_seed_hex_new(); + prom_set(prom_buf, prom_index++, "%s", hex->str); + } prom_set(prom_buf, prom_index++, NULL); From patchwork Wed Jun 5 21:15:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 801639 Delivered-To: patch@linaro.org Received: by 2002:a5d:5610:0:b0:35b:5a80:51b4 with SMTP id l16csp36561wrv; Wed, 5 Jun 2024 14:17:01 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVM9BeSwzPN8Lj6833TnQ8qK9CcUmnd7yjEtC/MucGSy2YAhQ7Jg/6n/2Cf4a53/KDahqHCMhI69yLxfG2QSRHX X-Google-Smtp-Source: AGHT+IFRgT9+tKrJCBrcv0+MPyxCDsX8QnQKdjx9Ct/PU4r2thqj8sstuN7NSlr+9/XEwoLtZVRk X-Received: by 2002:a81:b344:0:b0:627:ee15:a93c with SMTP id 00721157ae682-62cbb4d6d0emr38224867b3.17.1717622221254; Wed, 05 Jun 2024 14:17:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717622221; cv=none; d=google.com; s=arc-20160816; b=IqdnP41SKuiXKKILXESCHTIB/MS1naHqwrWdG/W0cUyIshlkT0gXH0TMTSJsx8sb4Z EVN/XMrp6aLb0Ux8qeL/h9KEHi60tWjHAvrgjQ8L6hGkIfH76x5m0VInsJbSWwrfk1uV qvOWffEljjbkvqFOH1rJ1TZq3nJLNCtJAt/Bs6zxqxsct/SZGgsE2ZOAnsIkxrUZ0139 MPGT0fNmPU8vCN6bul/QYBeRj+h/kcCqul7T/a1MFw4J83EdXc546avFL6MXVaZDLJFE QdB0g4r3yN2VG/H5YUAuUYtehj66A3jlekyHeR8MAsn4FZskRF4m7UaQDhZhpEIXsl60 oE3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=8p2HosDvmS098I1PRmfiW9ZIdsUwMQx7c58R0dSQai4=; fh=kQadAhxV42GJ3cd2VUw1RyURv/zJQGvmUdF7iLEVTtc=; b=n0sod41H4OHmqcYekmzYgkMyDhtMJwfZojPXlYAfUEMK2bQCabOEgTylAPB3PH8pX7 bAse01LoJA6LYO/5CVaBi6bYc1PGf8Xy+pdr+dWKcFUQyhJISJhkFqr9u/iAG3F1oxF4 yE/pPI/q++GtdfwSxcZQr642yYt5XRQLjOyEaEHWs6lm9PJ042M3e571WlI6rkSKrepl ehzfFM7zj857lOK2QrK5Ega76XlkX0HLgiX9dUN4etdJEugl1rAyhcOsh2UsEragGr2i 5W1LrAtMw0COawodzB9jEAk2eIadyJpLqy7RtEE+CtL2Pfg/i05oryL/ZYH0siWlUlKx mkvQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R0791uS8; 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 6a1803df08f44-6ae4a733b64si1125086d6.73.2024.06.05.14.17.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jun 2024 14:17:01 -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=R0791uS8; 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 1sExyu-0000co-88; Wed, 05 Jun 2024 17:15:41 -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 1sExyt-0000c8-4k for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:39 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sExyi-0003Pq-Q0 for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:36 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-7026ad046a2so193465b3a.2 for ; Wed, 05 Jun 2024 14:15:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717622127; x=1718226927; darn=nongnu.org; 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=8p2HosDvmS098I1PRmfiW9ZIdsUwMQx7c58R0dSQai4=; b=R0791uS8OGP1PWYcA/klgSCD4zbtg8gWGfQsLXvZ+bQM4a1V1RYx8MjtYilRy2UkzW cJ3f99PtFZViwUmKXLpnxabMHuddx4QZbzrARxdY80QlnM6xV6IiwIS0eCalluu00UJk akDpPrzNwtXmyidXdAItXV/xRanMPmFoxzYDVS3JHrjvlVGZoCKfNT7SWzvasAU86MyJ Oxz12KtvsMzPV55rXLlomUQEgbpRPJX+MZqGkwLRkEHnQ0rIyWkxI1LyutcB0WkdiWLb bFfYrn1O0zaAsGd0qu72Z+x6haQq6gQwDIZGBc5+DXMyzBGbotjIfXpzZxq6Hlr/BRYK EUaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717622127; x=1718226927; 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=8p2HosDvmS098I1PRmfiW9ZIdsUwMQx7c58R0dSQai4=; b=PNTZPvjwpUk2AllTnpv2g/HS1rf1ZpZ2C+RhSLXpvFjmrKO6F/PtKzTsWMluElTP60 4Vr0zTpjyLANhQQmoRBnHkRH3vqlXbvRJqDkW3z/KJYTKQgdpI/FNBXc/n4oSmcePu18 PXd7tmWMeHdifc9J+MsnURfHfUZKhW4PPGpaZWB3DSNDs4uEVkyEuRQs6OcXmZMCnh1A dzb+fftNH2wyats7OD2NISSQyWXzTRw55evEDQYV4WewA5eZ1FrjpSmqpat5BLadYYdy PtXI0AfLMr4BXaIcmYPy3pG6PeDlVKjS0xw7NdzmwS23Tgzk5aVUCHoJLTiEdcwJ2++R HnJw== X-Gm-Message-State: AOJu0YycHwauV5dcXGkJ2P8vuS0ve419Ht7xPnUUW4fap0cGLVQq7zWq TGm67lvOe4euRDMiFvXQr3ORUbhR+jbXVZQEDokKEWttk6qQxHNQXwbjuBLIr1l/Q+YBlwZAFmW l X-Received: by 2002:a05:6a20:a122:b0:1af:d19b:a76 with SMTP id adf61e73a8af0-1b2b6e2a28fmr4536166637.12.1717622127326; Wed, 05 Jun 2024 14:15:27 -0700 (PDT) Received: from stoup.. ([71.212.132.216]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70242aec7d0sm9347538b3a.99.2024.06.05.14.15.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 14:15:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 05/16] system/qtest: Replace sprintf by qemu_hexdump_line Date: Wed, 5 Jun 2024 14:15:10 -0700 Message-Id: <20240605211521.577094-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605211521.577094-1-richard.henderson@linaro.org> References: <20240605211521.577094-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x429.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, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Philippe Mathieu-Daudé sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1. Using qemu_hexdump_line both fixes the deprecation warning and simplifies the code base. Signed-off-by: Philippe Mathieu-Daudé ` [rth: Use qemu_hexdump_line] Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20240412073346.458116-8-richard.henderson@linaro.org> --- system/qtest.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/system/qtest.c b/system/qtest.c index 6da58b3874..507a358f3b 100644 --- a/system/qtest.c +++ b/system/qtest.c @@ -601,9 +601,9 @@ static void qtest_process_command(CharBackend *chr, gchar **words) qtest_send_prefix(chr); qtest_sendf(chr, "OK 0x%016" PRIx64 "\n", value); } else if (strcmp(words[0], "read") == 0) { - uint64_t addr, len, i; + g_autoptr(GString) enc = NULL; + uint64_t addr, len; uint8_t *data; - char *enc; int ret; g_assert(words[1] && words[2]); @@ -618,16 +618,12 @@ static void qtest_process_command(CharBackend *chr, gchar **words) address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED, data, len); - enc = g_malloc(2 * len + 1); - for (i = 0; i < len; i++) { - sprintf(&enc[i * 2], "%02x", data[i]); - } + enc = qemu_hexdump_line(NULL, data, len, 0, 0); qtest_send_prefix(chr); - qtest_sendf(chr, "OK 0x%s\n", enc); + qtest_sendf(chr, "OK 0x%s\n", enc->str); g_free(data); - g_free(enc); } else if (strcmp(words[0], "b64read") == 0) { uint64_t addr, len; uint8_t *data; From patchwork Wed Jun 5 21:15:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 801637 Delivered-To: patch@linaro.org Received: by 2002:a5d:5610:0:b0:35b:5a80:51b4 with SMTP id l16csp36539wrv; Wed, 5 Jun 2024 14:16:58 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUKuu2IY69cuMDNIRGxNynvZRXMuf3Mmor0t+Z52iaDVrKABxS7n2HVAh76hCeY/M36ePyWZ1bc5xaQh8aejgYa X-Google-Smtp-Source: AGHT+IFjB8W633lEY5XqxHGAY/Zgta36d77hbK1Wwi7lNNEEJuqmAIWrNPoHvOHdVWA/wAo38y8W X-Received: by 2002:a05:620a:70db:b0:794:d593:8a7f with SMTP id af79cd13be357-79523fc2cdamr381189585a.54.1717622218534; Wed, 05 Jun 2024 14:16:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717622218; cv=none; d=google.com; s=arc-20160816; b=M3XORoBFRVhpegKYc2ynUinpwKyD/av3vGPWqVNmJeYjk4OrrG02g0PIP1QtlAIbYd 9mDLMOJECHds3QGtBNAyb/ZzLE+bTblO1H7ET63qEyDK6jXgJyau6MiuyrgbD+zFSkCy vWW+cEmwYVyAzaIZYTlLa3ghP8uH0+tXFZr4kND5gjv2Gje14kX6Bj2x6b12UgqT5UBb KvTbxDkt263JLxTBGfdtRUeiR4RSCyo728dJMODVoE8J4/jB+uzOGvXD2zPjqEi5A31H Oi2SpDL+63esbk7Oi4/KMwmNAmtChlhBKNderbKnkIsSBT/DnQuBZkD3hTz77XO+viag zS5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=TgL42mC7jE0u3HD5Jwp7lhtcm3jXE8Mj7V3RtjF1NUM=; fh=kQadAhxV42GJ3cd2VUw1RyURv/zJQGvmUdF7iLEVTtc=; b=v5HUlJEG5HBDnEc1q+GJ2mdekE+RCha71Y8lAmpNTWl6+4JvGec48OAJuLFaIX8t8V R5hVC4B1hwdAFCPi6xCmK0IkMyOaGDnNoxXxrvb9un6BfdpOYC98auFaB4XbmnCMo3VH LjKcNGAuH0Jf3hMjAatnCQNO2Iqn+A5QhE/HRk4P0zsFrhgQX/kWhkmlEnpvPJj3abr5 qwWxhwGqoHObk4ADWpDpH7SW96VqPNXBUqhbfqqIBCQxMsv5R+r/XEiZOk3WHMbBj7Mu eNpvh8gCBu8HMJEDanBjXwp5XlSFBWiNx4z8Nn4VHDs2D7+XnS48dkxEqIZqhIl+q4/2 AwJQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eOJ7K1dY; 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 af79cd13be357-794f30630fbsi1542469785a.226.2024.06.05.14.16.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jun 2024 14:16:58 -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=eOJ7K1dY; 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 1sExz2-0000fs-KK; Wed, 05 Jun 2024 17:15:48 -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 1sExyu-0000cw-S5 for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:41 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sExyj-0003Q1-Ge for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:39 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-7023b6d810bso199745b3a.3 for ; Wed, 05 Jun 2024 14:15:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717622128; x=1718226928; darn=nongnu.org; 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=TgL42mC7jE0u3HD5Jwp7lhtcm3jXE8Mj7V3RtjF1NUM=; b=eOJ7K1dYloajCjYjB4VRf+l9+CMpLo05pKi92Ggd/ivvGS9HO9XsmsN99tcXGJk7+x LcMiskv2owZM29Go2f6nGb3WoqekUY0Kb5uEq6NFXDx8aQUlDbJhZx4m9So3p3/rgQB5 gDcwduJTygYIILh4D8gwhgD+O/76GVqbqj3H/2DxjMOKEUkDssyyTEiDtvSaSJk82EpZ w2ikQmrkomOzgL1Byoe1LWyn4u9qznvUZQVmejGuErIDi1XXU68pWE+xWXWWamlQ0PCS qgqfF4YTkNheslx5fFdDx5n7RMKbh0R6EonB2xthAzsv9F8LTxooLNVcbirCvIakm613 aH8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717622128; x=1718226928; 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=TgL42mC7jE0u3HD5Jwp7lhtcm3jXE8Mj7V3RtjF1NUM=; b=V5jr8ZpHJkRFDEN7B8yJa74zHVSzUdbKIpgZJ/5yE3cgifkSRa1Ociz6WkWUG5rr80 RSgu80f17bKvxp+6Ci4WrYpJvqToDoSiwQWPj9ABa8rAlJ9f8sdVFBG02WxJSvuNpLaj GkekUOdRid4e3xlQ2FqUmcNDt8qIPRR0TCKIypZnt58HulC6dz4nPqJHK1q28mLCEmxa v2UK7zog8PVnXVfZ0wN7+OAVSqoZpUE4e9LiAsAwafxg/3Th9Y1eIqZSW8P3uC018ZM9 CEWRCBHP0dD9E5NYDg+FZw6Qy7e4sBa9CQnfevVxnxrz7UAb0DbqlBp1HTBYHDnrbBGB vDjg== X-Gm-Message-State: AOJu0YzAnkOWNAtTwIE4P+ypKlqbzys3xEG7zmUTmIwkbsW/4UTcqYqb WqvbRrsg9TqhGoEm46J186GNd3gXsGoda0BxaikryR/G8PIpGgXv4xavO6R1MEn30IeC+vdNJPr D X-Received: by 2002:a05:6a00:1d0c:b0:703:efa7:e594 with SMTP id d2e1a72fcca58-703efa7e8dfmr2127404b3a.33.1717622128148; Wed, 05 Jun 2024 14:15:28 -0700 (PDT) Received: from stoup.. ([71.212.132.216]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70242aec7d0sm9347538b3a.99.2024.06.05.14.15.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 14:15:27 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 06/16] hw/scsi/scsi-disk: Use qemu_hexdump_line to avoid sprintf Date: Wed, 5 Jun 2024 14:15:11 -0700 Message-Id: <20240605211521.577094-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605211521.577094-1-richard.henderson@linaro.org> References: <20240605211521.577094-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42c.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, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Philippe Mathieu-Daudé sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1. Using qemu_hexdump_line both fixes the deprecation warning and simplifies the code base. Note that this drops the "0x" prefix to every byte, which should be of no consequence to tracing. Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20240412073346.458116-9-richard.henderson@linaro.org> --- hw/scsi/scsi-disk.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 4bd7af9d0c..f386a2f01c 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2648,19 +2648,12 @@ static const SCSIReqOps *const scsi_disk_reqops_dispatch[256] = { static void scsi_disk_new_request_dump(uint32_t lun, uint32_t tag, uint8_t *buf) { - int i; int len = scsi_cdb_length(buf); - char *line_buffer, *p; + g_autoptr(GString) str = NULL; assert(len > 0 && len <= 16); - line_buffer = g_malloc(len * 5 + 1); - - for (i = 0, p = line_buffer; i < len; i++) { - p += sprintf(p, " 0x%02x", buf[i]); - } - trace_scsi_disk_new_request(lun, tag, line_buffer); - - g_free(line_buffer); + str = qemu_hexdump_line(NULL, buf, len, 1, 0); + trace_scsi_disk_new_request(lun, tag, str->str); } static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t lun, From patchwork Wed Jun 5 21:15:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 801640 Delivered-To: patch@linaro.org Received: by 2002:a5d:5610:0:b0:35b:5a80:51b4 with SMTP id l16csp36565wrv; Wed, 5 Jun 2024 14:17:02 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXqfSCtZPjgBnMJj61Zn0nN/aSzrn5Yp3/NyWKfvASREVNFr+/OvERmqbb/j/kK/Qdu3/4MaolFWokMZa3RUSFF X-Google-Smtp-Source: AGHT+IHuo8RR0PJIJnO3zI7JYJjgzP7+MaDDExNltY/TXpR+sjM1HatGt0U6u7pt/mhnltldk73y X-Received: by 2002:a05:6214:3911:b0:6af:c66a:d5a8 with SMTP id 6a1803df08f44-6b030aa0653mr39389856d6.51.1717622222100; Wed, 05 Jun 2024 14:17:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717622222; cv=none; d=google.com; s=arc-20160816; b=MgvKC9uPdUf3Ri5BqWGxQKFh7v4F2lALzFNHiJN8OvUTQrcccTfL1qfpfukLQVfMfj GKYeM/MHI6gZI7TQX6X58B659r/LJgtMY4Qo4ptoM64ZhxVNwGNobWGYf0iH2gu6cRsU F37+ewkLPZABG99p47CggrMT658W25VzUxG6VmJ7A8MMT9V+lPjjBua1b8LhAgaX9Qrt mJ/gf7ZUtnSTfOd1t8785MkNkNeccJDp0kU3o0eqgEKnOPQbDolgsLGQKvUrVBj5ZoUN S6nfT7qOWn7BxgHG7JA95Gfm/K7CShh2jLADE2ncAhu/AMix2ZngYj27/J5bgcZUPy8W qYZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=eAoOiYM0ExI1FMuz9eK9AmdYVnEbXhJzPvY/2SnngcQ=; fh=i/pWNGcx7KiR3ewgypxpPkuORYlkCnVXLqKVm9/UgNc=; b=e36C6OLq6TKa+QtEK7hY+xwECWcOvSSCTI9SSW3BS5sU+4srZ8eQQq4tG5rNH6VfEw m34XlOXMNMzPFjhaNcHDtgcbUtbgfMOWP7wHOOK4ZQnug5m0Ksa9KkJWT7ZTmOfGtg7/ ZVqmTD0DZvh2vtdBG+mPGXlvnWH26T/6AexyqaNppGiOUYQqI3oRqhOILQbjzVlfmANs 8EyKNOJeKT28Zcx4VFLP6pnxVlMaNimN1gQyss9Y73Xa8la+1vMVL930EwUM2zVoMP7o f/NOzITOeDnkjwpqd4bvbGIC1WFOdQPYRAdzotfXc4wRBO4EoYO0EgQF342QBxrl6reg xhbg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QtgsMBIp; 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 6a1803df08f44-6ae4b43a860si147633216d6.552.2024.06.05.14.17.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jun 2024 14:17:02 -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=QtgsMBIp; 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 1sExz7-0000hj-MY; Wed, 05 Jun 2024 17:15:53 -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 1sExyw-0000dT-Lr for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:44 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sExyk-0003Q5-OC for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:40 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-7023b6d810bso199757b3a.3 for ; Wed, 05 Jun 2024 14:15:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717622129; x=1718226929; darn=nongnu.org; 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=eAoOiYM0ExI1FMuz9eK9AmdYVnEbXhJzPvY/2SnngcQ=; b=QtgsMBIp6h/xkL8VDLa0Mj2Vh2tbESFm8q3i+Zr9uKPcbUY2e6YVvOMhYLz7Kvionk n5jLUIBTFz8wDfthJlZJjkiwfujawyAfClE2+Ms/OjA0VfsLuUcLbH/6+uMyPodJ0DV5 4m97hEPEv2krQ3Dz60x2tzSH/vDDrwS05NckABC2DsX9RgUkA6jDp6vYntBmMjECF97H UDiM4v0SN3Ey4YclN3UWRejIlpq/alpxlfE8XsHjQj59b+1IKjl52GLv8swfPrtg9i12 AzcxW0C2uT28w1fvfpJrs1Ya74RlRmjAtMDKHoqMkw7T+SQXVjGKvKAfb5Z3Zh4fKJJ+ hGRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717622129; x=1718226929; 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=eAoOiYM0ExI1FMuz9eK9AmdYVnEbXhJzPvY/2SnngcQ=; b=JTTfOu0nDc4gq17Y7gknl40u/1ytj85gFQvMnAJ8IZuMdeA4P2V+f1NOfTjP4gP+t4 h/Npg/2KveIE7Slkt1eS2iIGsZ9s6S0CF/hU46WcGdZzP6pkWdSFCzfAbhC8csdIjiOG Ko9uNUstEro0wKrdpPz4f2byofsxARblSx8/MSPrN8uoROI8krMd5LuF1EnPTQ9LLk7v LVh3H092Uz2vNgwwlf9WvgfU1sEunX5M5+vU7A9L7tlOWAyh7CQOlqBa6tWJ0AEhRDMV xXCij99WHYXOlV7tdQN5QmZlQGvmoma3fqw+eZtnbcznZdq4Bjlzwr6anM02eS0jelzR 1ieQ== X-Gm-Message-State: AOJu0YwYG/ZuDjz/xUkobW1ffq42WrW5YGlBXKwvM1lgjssowBJOHmJs FLp7VAoJLNiu7grW/jlE8npBIy5PreFHxUqkF1ouwNxf5S2Ml4h26wp61GuOTWJzC7inlfcUmJy F X-Received: by 2002:a05:6a21:8195:b0:1b2:710a:5cfc with SMTP id adf61e73a8af0-1b2b71790c0mr3595401637.57.1717622129084; Wed, 05 Jun 2024 14:15:29 -0700 (PDT) Received: from stoup.. ([71.212.132.216]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70242aec7d0sm9347538b3a.99.2024.06.05.14.15.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 14:15:28 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Pierrick Bouvier Subject: [PULL 07/16] hw/ide/atapi: Use qemu_hexdump_line to avoid sprintf Date: Wed, 5 Jun 2024 14:15:12 -0700 Message-Id: <20240605211521.577094-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605211521.577094-1-richard.henderson@linaro.org> References: <20240605211521.577094-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42d.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, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Philippe Mathieu-Daudé sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1. Using qemu_hexdump_line both fixes the deprecation warning and simplifies the code base. Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier Message-Id: <20240412073346.458116-10-richard.henderson@linaro.org> --- hw/ide/atapi.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c index 73ec373184..fcb6cca157 100644 --- a/hw/ide/atapi.c +++ b/hw/ide/atapi.c @@ -24,6 +24,7 @@ */ #include "qemu/osdep.h" +#include "qemu/cutils.h" #include "hw/scsi/scsi.h" #include "sysemu/block-backend.h" #include "scsi/constants.h" @@ -1309,14 +1310,9 @@ void ide_atapi_cmd(IDEState *s) trace_ide_atapi_cmd(s, s->io_buffer[0]); if (trace_event_get_state_backends(TRACE_IDE_ATAPI_CMD_PACKET)) { - /* Each pretty-printed byte needs two bytes and a space; */ - char *ppacket = g_malloc(ATAPI_PACKET_SIZE * 3 + 1); - int i; - for (i = 0; i < ATAPI_PACKET_SIZE; i++) { - sprintf(ppacket + (i * 3), "%02x ", buf[i]); - } - trace_ide_atapi_cmd_packet(s, s->lcyl | (s->hcyl << 8), ppacket); - g_free(ppacket); + g_autoptr(GString) str = + qemu_hexdump_line(NULL, buf, ATAPI_PACKET_SIZE, 1, 0); + trace_ide_atapi_cmd_packet(s, s->lcyl | (s->hcyl << 8), str->str); } /* From patchwork Wed Jun 5 21:15:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 801649 Delivered-To: patch@linaro.org Received: by 2002:a5d:5610:0:b0:35b:5a80:51b4 with SMTP id l16csp37324wrv; Wed, 5 Jun 2024 14:19:11 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVHeG42oeg2KEZecxpB21eFUas2jiUZgYTMKXFYldegb5AFRo4++wy+xoumpk82Bh8uxN+GDwV/5M9yKPuMU7ms X-Google-Smtp-Source: AGHT+IGzxhAxBQq1El3QVqfNRKEp6aVMPH8Mp/RWe8QWu0CCpJ1IB2rZCvSG5aVOzzAsCf405h3e X-Received: by 2002:aca:2b0d:0:b0:3d1:e004:1929 with SMTP id 5614622812f47-3d204267dd0mr3350794b6e.2.1717622351047; Wed, 05 Jun 2024 14:19:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717622351; cv=none; d=google.com; s=arc-20160816; b=uqw1uRCI43lsIKD3oXIBWQGzMp5EFtlJC3tKXSWCOJajyU75WPRiHwxWfaxLnCHOvd DYDHIGyDNCr5WRXP8sidEbu6DVbPoMbJTdjzEJADAIawUfzxRtlKuwmtSKbX+ei9IEn5 Q44mn8X/IQpLNPsvzm5PcnbvOUIdiFfrlqCOED8EioLjHwsQ5rs3TOojfq7F0X69GAb9 fuhpkRiCUmd2/OaImdG3kDHSwNApBzvYlNKRaJYs/kjI2Vl9e4iqYZKKPQNa0crzdzsz p+2/mPQJ+FcgXvI98h95BVhko5P67AMV1Uz3afwqHvgbF20D6OXm6OWRba3ZyLKHRkGI uvbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=L6Mj0yPmK4aF2gdBWUJi8XJKeBX80hKgL2mV428joew=; fh=i/pWNGcx7KiR3ewgypxpPkuORYlkCnVXLqKVm9/UgNc=; b=r+T8hheT0e8L0XSMYJUeKMxCJJl0fKQbIvujOx7g7l42SHd+55UUUTrLAiCkFx5Jbu JRB7HBuxcppWLoqCq/qOCWSVfwfrxrEHgpzP+uH4Iv2+EmXxCaxMp/gZPcayAdEzAmwp N74qjyHmbezVzx1aVKI9lrmbpdZlcMk5T6nzQUCJM9cLNMCqqjo5gl8DspxUYei4jyAm /yha3k2nluHL3+mDHE3D2YvC+ozweUnydqUdV14NK0d0zchWIuoPUjb2e6vDfgBjHRpt 98KrOz84vMdgwZAZIlOy6fBeNJYUqcGqj8jawgsJnODraWmEsW5w7Zqdc6KXDTdFGuFV qHww==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=X9U12m3Z; 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 af79cd13be357-794f32a1bd7si1217185385a.542.2024.06.05.14.19.10 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jun 2024 14:19:11 -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=X9U12m3Z; 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 1sExz6-0000hL-TI; Wed, 05 Jun 2024 17:15:52 -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 1sExyw-0000dS-L4 for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:44 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sExym-0003QF-T0 for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:40 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-7025b253f64so210725b3a.3 for ; Wed, 05 Jun 2024 14:15:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717622130; x=1718226930; darn=nongnu.org; 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=L6Mj0yPmK4aF2gdBWUJi8XJKeBX80hKgL2mV428joew=; b=X9U12m3ZOWpkFESkavbYaNI0cWJ6ox6wsAwDBdUmcVj7DySqYHVscny641v/NgXxB4 XPr6pcnCovVesTMDBWgzvVQgLR4L6aLsuSrqOisQ7JWipd7iizvY4lnOy9LV8K4ew4eu vwaBM8E3+sSZZ2laPJkiz28l2LEhG7MKRWHEaXS0DDBH41kB+TBRTgHoGtUdWBOamUsN N2wqfgVTjpjLzI3unmyHI7lefazyks5uscKkSuY2dxOFR3EeJdQdcRXmzm+mXHGWflle /ZEJdQgeIwjNWsRWPrmM4voVVtEbiLCG/GoHywDj6E0We1r9UwYQplkHcr8Uyow/+g8T KJRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717622130; x=1718226930; 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=L6Mj0yPmK4aF2gdBWUJi8XJKeBX80hKgL2mV428joew=; b=aGoktzJvtrpWODXBxutJnupwwHIXwJ/k6BMLhebehCEweeuDsCRYJnWLehCqv7LDZW JGqdDRGTo+4Cr8s/k58gjL8paRDiWv3oHzbKO9OkVK37ZT1a5ryILHZbvmrA9Horygb8 c/B6EIhzyI7UrQFnCI6OwNNB+S+K+3IDIIc4Si3CKZFOkFOWVNaAWdUbj25T+xfvHtgM 00TJ5bUrIh03bpKBlxM0B+s9xxjMuF/5J7bApc+MCbVfUz/ukKhtjNssURtDhzmelyb6 iZ1tdb/LhPBMOw7o5sb8+2BEByE9noULk/q1QhZLsm/o7VpUjXaPfgvo1uS9O5LY4eC+ 13Xg== X-Gm-Message-State: AOJu0YxB/iDkJUiVK48EZyPtRUkXgK0oyXWrf5JQ3kGwh1aBZtoIK/z0 yZuw8kjfnc63YvXtNLXPDXuOGDFCVVwDB5qAnZBpOSkNBelsq0JmgzCgUogyS6iKVne5rm+gRuF c X-Received: by 2002:a05:6a20:918e:b0:1a7:bb6d:6589 with SMTP id adf61e73a8af0-1b2b6fd4af7mr4730011637.29.1717622130022; Wed, 05 Jun 2024 14:15:30 -0700 (PDT) Received: from stoup.. ([71.212.132.216]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70242aec7d0sm9347538b3a.99.2024.06.05.14.15.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 14:15:29 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Pierrick Bouvier Subject: [PULL 08/16] hw/dma/pl330: Use qemu_hexdump_line to avoid sprintf Date: Wed, 5 Jun 2024 14:15:13 -0700 Message-Id: <20240605211521.577094-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605211521.577094-1-richard.henderson@linaro.org> References: <20240605211521.577094-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x432.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, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Philippe Mathieu-Daudé sprintf() is deprecated on Darwin since macOS 13.0 / XCode 14.1. Using qemu_hexdump_line both fixes the deprecation warning and simplifies the code base. Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier Message-Id: <20240412073346.458116-11-richard.henderson@linaro.org> --- hw/dma/pl330.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/hw/dma/pl330.c b/hw/dma/pl330.c index 70a502d245..5f89295af3 100644 --- a/hw/dma/pl330.c +++ b/hw/dma/pl330.c @@ -15,6 +15,7 @@ */ #include "qemu/osdep.h" +#include "qemu/cutils.h" #include "hw/irq.h" #include "hw/qdev-properties.h" #include "hw/sysbus.h" @@ -317,22 +318,14 @@ typedef struct PL330InsnDesc { static void pl330_hexdump(uint8_t *buf, size_t size) { - unsigned int b, i, len; - char tmpbuf[80]; + g_autoptr(GString) str = g_string_sized_new(64); + size_t b, len; - for (b = 0; b < size; b += 16) { - len = size - b; - if (len > 16) { - len = 16; - } - tmpbuf[0] = '\0'; - for (i = 0; i < len; i++) { - if ((i % 4) == 0) { - strcat(tmpbuf, " "); - } - sprintf(tmpbuf + strlen(tmpbuf), " %02x", buf[b + i]); - } - trace_pl330_hexdump(b, tmpbuf); + for (b = 0; b < size; b += len) { + len = MIN(16, size - b); + g_string_truncate(str, 0); + qemu_hexdump_line(str, buf + b, len, 1, 4); + trace_pl330_hexdump(b, str->str); } } From patchwork Wed Jun 5 21:15:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 801635 Delivered-To: patch@linaro.org Received: by 2002:a5d:5610:0:b0:35b:5a80:51b4 with SMTP id l16csp36298wrv; Wed, 5 Jun 2024 14:16:20 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXIDPWeGlS9tZtmlq3FEnwcnUu/4e2pdfQaOOVt4Rugd4wC16ZFUXpD2UO08/3sJdQgHb3r/rDTvy7msMco8T/E X-Google-Smtp-Source: AGHT+IGejxxBf8TWOZyjXxBm5cmoVLhZovXp0VdHlJOoJjjONIktu+Qk6QSnid/e0XvktS+wJjlg X-Received: by 2002:ae9:e514:0:b0:794:f27e:634a with SMTP id af79cd13be357-79523fc2e0bmr371531685a.58.1717622179661; Wed, 05 Jun 2024 14:16:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717622179; cv=none; d=google.com; s=arc-20160816; b=dO+U3ipogvCGdTdof2TO1hy9v3a2uXJ2RhIgQAedPGfnp7Ox9JO4fXOR4WLB1TcbzM kL2MqGBk6tlRdolqbuczwBgPIY/lFvS8dY3Fr3LzD21zsYKehnDJ0pcGDpcS5cYNGMrB e8PJaq0fhZm/17q6SHqZ3hM7Crcdwr3zYW6w0jAZADhzyssLbDQLXaRggOHK/gh7fpa8 jleyQoMDuENnrRhvqn36CmJkOmN8snSI2BemI21SfZ6ADgXlQR0MNzgodsJaW+DzdsZD qfI6AgEKl8/05OxU783h0TMuwND7OXuadqe1gfx1BcNYhCPE/w0sFmSTOLVOMzYjrCH0 cNeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=NfrVlKNrjZVUEIrdKdz8B/16XtB8Z0PZL9Z34MyohBI=; fh=vm85eyWrvOAHduw3sqEA+cYBqvHB7M0MHFcRJg7VWOo=; b=cL8I/fzqsVETByAmPBJ2TsUEfw9pCPQ4FzReiU+9x55pJ5jrip3wG4mXX5/dnqFLFM orxh52VCapeC+Ga6cBceuPFqlnI715auxq4MCOkQKFdkLSzDexl2f6nC49zO23YIMplb IEJikALoExg6/PhFV1BTYUQeKwg31OPk1NRTEIP3kEN+C+ONtELnynjjtIQlBsATF8Uk ve/a64UtQMPGD0jVQ9mNdKf+3PkH0EpBr1IFNIwAu3Ds3SFAfNPYNKz2PKq53CK4f7nP So38eV/ESUr40kw7LoSctCPOfcI8pgDGlDImLKfbKAXTE8PCNnYCDsGjaG831jeyqLn3 v3TA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZK9PEeoE; 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 d75a77b69052e-4403438cb63si12271611cf.349.2024.06.05.14.16.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jun 2024 14:16:19 -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=ZK9PEeoE; 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 1sExz4-0000gL-E1; Wed, 05 Jun 2024 17:15:51 -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 1sExyw-0000dR-Km for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:44 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sExyn-0003QR-Fq for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:41 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-7023b6d810bso199779b3a.3 for ; Wed, 05 Jun 2024 14:15:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717622131; x=1718226931; darn=nongnu.org; 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=NfrVlKNrjZVUEIrdKdz8B/16XtB8Z0PZL9Z34MyohBI=; b=ZK9PEeoEBRpJE7mfuhPf8hFW9pu7yjCaOPwE6xukRk/8YzMsnIURWg2SQ25KTmCSLm YgGI2GEcUh9eCINe98uAq7ygAXheTGwwXe8Z4Q2Y9qHKSCnyPzKLEX1YQTlBPIIvb8Y+ 52cdqRIRCOg4hZ7FNP6R6aQUqMXrC3/bBPS8dIm70NNXtcZy4dBPXyUf4N6zSx2gggT0 uhI4r/moV05BzofMd2QKdxxdtcERXZqQoriPgraZpnqFWVkG7Bbb/5nStFSHaU2wichf gDsIlQZgi5puiIust6iP/kUf3xNp4VSqXyEv0kdZOYl6d6iqHyYyzOJibhFel58xByg0 blzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717622131; x=1718226931; 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=NfrVlKNrjZVUEIrdKdz8B/16XtB8Z0PZL9Z34MyohBI=; b=PcQ3aVcIPgm1OQMp7b/xcjKCiodjslc4stHbd0nrOZ/FZFQhcjorn3Rbo5g2BVQ7v4 uqOFBsriZAv6h46zG7IjvtDKXdCSEEIeYIMrOdVqtZiL6/KBYzfD9B+20F1CKGWsm3U9 4arzBGFnfMciBO9vZPp8HN0sGnbeI1Pp6fW9EuP6s6mmWLM6WqacPgGgifEqQaIVgEGd fALu6ZzNVh64A+pzy7AdTUCCVi+Xb7I81bXHKT/IUC32bWTcDFAPUyBntPcbLvrZ2hWX m9C6kTLlndELKTu97Dg7brAU6JduAHA/6mWpWUbTRuAY820R8IxHm2JdTRCxHD/vm5Fp zCtw== X-Gm-Message-State: AOJu0YxuoCXyGkJrt+Xa1wbP6KD87ydLV9G+0g4I9tZvPBnPkzZhEAQe vcXG1mmdg7kMU3ZvM4BjTNkTcpX8J3MhED5J4S5r72hE5liSSVCHyRq7G4uk5K+RRhQRqGCXzGI 6 X-Received: by 2002:a05:6a20:1590:b0:1af:d153:b76a with SMTP id adf61e73a8af0-1b2b6f68b99mr4849695637.18.1717622130797; Wed, 05 Jun 2024 14:15:30 -0700 (PDT) Received: from stoup.. ([71.212.132.216]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70242aec7d0sm9347538b3a.99.2024.06.05.14.15.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 14:15:30 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier Subject: [PULL 09/16] disas/microblaze: Split out print_immval_addr Date: Wed, 5 Jun 2024 14:15:14 -0700 Message-Id: <20240605211521.577094-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605211521.577094-1-richard.henderson@linaro.org> References: <20240605211521.577094-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42e.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, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Unify the code blocks that try to print a symbolic address. Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier Message-Id: <20240412073346.458116-15-richard.henderson@linaro.org> --- disas/microblaze.c | 89 +++++++++++++++------------------------------- 1 file changed, 29 insertions(+), 60 deletions(-) diff --git a/disas/microblaze.c b/disas/microblaze.c index 49a4c0fd40..3473c94164 100644 --- a/disas/microblaze.c +++ b/disas/microblaze.c @@ -767,6 +767,24 @@ read_insn_microblaze (bfd_vma memaddr, return inst; } +static void print_immval_addr(struct disassemble_info *info, bool immfound, + int immval, unsigned inst, int addend) +{ + if (info->print_address_func && info->symbol_at_address_func) { + if (immfound) { + immval |= get_int_field_imm(inst) & 0x0000ffff; + } else { + immval = (int16_t)get_int_field_imm(inst); + } + immval += addend; + if (immval != 0 && info->symbol_at_address_func(immval, info)) { + info->fprintf_func(info->stream, "\t// "); + info->print_address_func (immval, info); + } else if (addend) { + info->fprintf_func(info->stream, "\t// %x", immval); + } + } +} int print_insn_microblaze (bfd_vma memaddr, struct disassemble_info * info) @@ -821,18 +839,8 @@ print_insn_microblaze (bfd_vma memaddr, struct disassemble_info * info) break; case INST_TYPE_RD_R1_IMM: fprintf_func(stream, "\t%s, %s, %s", get_field_rd(inst), get_field_r1(inst), get_field_imm(inst)); - if (info->print_address_func && get_int_field_r1(inst) == 0 && info->symbol_at_address_func) { - if (immfound) - immval |= (get_int_field_imm(inst) & 0x0000ffff); - else { - immval = get_int_field_imm(inst); - if (immval & 0x8000) - immval |= 0xFFFF0000; - } - if (immval > 0 && info->symbol_at_address_func(immval, info)) { - fprintf_func (stream, "\t// "); - info->print_address_func (immval, info); - } + if (get_int_field_r1(inst) == 0) { + print_immval_addr(info, immfound, immval, inst, 0); } break; case INST_TYPE_RD_R1_IMM5: @@ -860,61 +868,22 @@ print_insn_microblaze (bfd_vma memaddr, struct disassemble_info * info) fprintf_func(stream, "\t%s, %s", get_field_r1(inst), get_field_imm(inst)); /* The non-pc relative instructions are returns, which shouldn't have a label printed */ - if (info->print_address_func && op->inst_offset_type == INST_PC_OFFSET && info->symbol_at_address_func) { - if (immfound) - immval |= (get_int_field_imm(inst) & 0x0000ffff); - else { - immval = get_int_field_imm(inst); - if (immval & 0x8000) - immval |= 0xFFFF0000; - } - immval += memaddr; - if (immval > 0 && info->symbol_at_address_func(immval, info)) { - fprintf_func (stream, "\t// "); - info->print_address_func (immval, info); - } else { - fprintf_func (stream, "\t\t// "); - fprintf_func (stream, "%x", immval); - } + if (op->inst_offset_type == INST_PC_OFFSET) { + print_immval_addr(info, immfound, immval, inst, memaddr); } break; case INST_TYPE_RD_IMM: fprintf_func(stream, "\t%s, %s", get_field_rd(inst), get_field_imm(inst)); - if (info->print_address_func && info->symbol_at_address_func) { - if (immfound) - immval |= (get_int_field_imm(inst) & 0x0000ffff); - else { - immval = get_int_field_imm(inst); - if (immval & 0x8000) - immval |= 0xFFFF0000; - } - if (op->inst_offset_type == INST_PC_OFFSET) - immval += (int) memaddr; - if (info->symbol_at_address_func(immval, info)) { - fprintf_func (stream, "\t// "); - info->print_address_func (immval, info); - } - } + print_immval_addr(info, immfound, immval, inst, + op->inst_offset_type == INST_PC_OFFSET + ? memaddr : 0); break; case INST_TYPE_IMM: fprintf_func(stream, "\t%s", get_field_imm(inst)); - if (info->print_address_func && info->symbol_at_address_func && op->instr != imm) { - if (immfound) - immval |= (get_int_field_imm(inst) & 0x0000ffff); - else { - immval = get_int_field_imm(inst); - if (immval & 0x8000) - immval |= 0xFFFF0000; - } - if (op->inst_offset_type == INST_PC_OFFSET) - immval += (int) memaddr; - if (immval > 0 && info->symbol_at_address_func(immval, info)) { - fprintf_func (stream, "\t// "); - info->print_address_func (immval, info); - } else if (op->inst_offset_type == INST_PC_OFFSET) { - fprintf_func (stream, "\t\t// "); - fprintf_func (stream, "%x", immval); - } + if (op->instr != imm) { + print_immval_addr(info, immfound, immval, inst, + op->inst_offset_type == INST_PC_OFFSET + ? memaddr : 0); } break; case INST_TYPE_RD_R2: From patchwork Wed Jun 5 21:15:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 801648 Delivered-To: patch@linaro.org Received: by 2002:a5d:5610:0:b0:35b:5a80:51b4 with SMTP id l16csp37297wrv; Wed, 5 Jun 2024 14:19:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWC98R+GtVD0IxhZ0T5PKA/Je89nWdZSU5tGrUzlVZj44BFw8YI5PrRCOUXMBxjvRrV0yp+aBKgDi1U7Oeg/LNR X-Google-Smtp-Source: AGHT+IGwHaDBGPnk6gUQr8GwBL3auCpSvc2te4ep7tiERFa7FWZjE8+YWR5F46i5XlcJI9iE/nAh X-Received: by 2002:a05:622a:110c:b0:439:577d:9a93 with SMTP id d75a77b69052e-4402b5f085cmr47624171cf.20.1717622346440; Wed, 05 Jun 2024 14:19:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717622346; cv=none; d=google.com; s=arc-20160816; b=U32d1cgnIO/vJx44XiRdF1kQw9EqsaBIXOmzEojVp8dHN7IXYfdj0N/thuufUSnUEm f0q6YelOdysqCvdDppgiSSdZ51kqYExXPmDdbOlulVChJuDdYSdIQRYXlh0VwcQr9H7F 4AF9YZfG0Ts/yZQm4R8bduHz1G5PTzci6iz9z/mkD+sHtxpvp5ADhfHct2vZgW+iG1JV WBWhmrVUWT3Zo1pRJUXzyfcm87YmjmtyMBhf4pKmU86M55BALiSGMprDwBsdMAG8Bc6z sjUDvAOw6j3zXff/2zbB9F13X5fb4pNatZ+FthgcXZt+dlimlJCTHsa8gbC9TiUysZGt i1MQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=MwnaX3mRNj652UfeczAgAmblf4E/jxKIUVCTWxHM3qo=; fh=vm85eyWrvOAHduw3sqEA+cYBqvHB7M0MHFcRJg7VWOo=; b=xoaekZDo5mAyiPoeOts/NnWMYvbO1zL7hiAuaswtHsx5cynmMafvKEiUnH51Yk5asq 30rWiZ4K59VoxuBRsw8ilkW4MU28ICRjlz28kzoCKRKrCRsWmaFp/ABJe2abExOnDlOO Hw30big5mAR0G4ZmIVkb8Q/nikBW/Z4422014uCOzsSWRZupbahRp+ucNPMHTa4+3tdr egvVcHDVUwrvw5j42gN1GauFOkig4zYHudc/0M5mdtb7yfEebHvzy8Lrh0Wl0/CeDwg+ Iw0S5W5oRRGqzVYjdd+f1xabl8RF+BN+jr/fDLA/2V1/2EfLbYh+zVKFP8stl2O2lo8P r0wA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S1vIL7JE; 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 d75a77b69052e-43ff25b5580si15300411cf.751.2024.06.05.14.19.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jun 2024 14:19:06 -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=S1vIL7JE; 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 1sExz6-0000h3-Bf; Wed, 05 Jun 2024 17:15:52 -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 1sExyy-0000eC-R0 for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:45 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sExyn-0003Qa-G0 for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:44 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-7025b84c0daso205624b3a.2 for ; Wed, 05 Jun 2024 14:15:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717622132; x=1718226932; darn=nongnu.org; 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=MwnaX3mRNj652UfeczAgAmblf4E/jxKIUVCTWxHM3qo=; b=S1vIL7JEAJTcZ/x3LOBCzySlqO0PRsoew0ttzlspGR7CA9pi0TAFN2XUrVTBPt18K/ AaNLXVEM/U59jTgxacAibUiGtRCEY6tC7CR05xIQ8Kt/XNO4CLkGHeEo2u0RYFT3FuXX nP+IYifC9V/RKwsXCsADMigqPevfUqCrEOT9AvE6UksfX1mPf3NvrMy+VZLYgHW9OFzm GXRzucSQz7RWpI7GEH+8zHltTvSRMraOqTHBI84bde1a5a+gQxsGizohx/PhkQOoKedx VcYLnUVATrT68vOoaftU2sjeq7xQF6eSy0y9k4OEJUHFw82HadE4ivR+k6he0gV3nExR rbWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717622132; x=1718226932; 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=MwnaX3mRNj652UfeczAgAmblf4E/jxKIUVCTWxHM3qo=; b=GiukU+YTS7/Rin341XVWqsEVWRZRdhyU0qZJbR6RmbGdEewd/6RdM/hM94vRrAzzZq 5z1XAeVrT5ylmbDf4JKpm45S2aXcW2l6tKQFr9Vndh69z6eIJtvYD9gUjPrWa48K30SL s5sxx919DaBL1v7bzDCYDP3LzvwpzO3Dj0mjUvSx6n9F2/+t+aYVRKTX3SAq3dk5SV8K lILi6BuyDPU3oYHGbD4O8qTVFIaep2TODU3l/Y67czXVkwHYPmqEquuvNSDvUZmVDfqk G0MnGRxxhZjokiVsAcf0x7KuQV5/yX5tpka2UgQXJtVOFUQGDLIytgO1CkQ/EzvjEfK8 CtIw== X-Gm-Message-State: AOJu0YxjA/tWuegpqKk+PZmdKt0g1GJ0hPAZvBTbNx+A/rmY0NYnaO6O lKvEX+wp0wpN3WT8ob39xXPxK6VdZyRdUR6UIH6L3NfyvOvryw8FcvqfQo4aUfaOAsHwpP5tMtJ m X-Received: by 2002:a05:6a21:3996:b0:1b2:ae30:95b5 with SMTP id adf61e73a8af0-1b2b7154eb3mr4608750637.56.1717622131620; Wed, 05 Jun 2024 14:15:31 -0700 (PDT) Received: from stoup.. ([71.212.132.216]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70242aec7d0sm9347538b3a.99.2024.06.05.14.15.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 14:15:31 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier Subject: [PULL 10/16] disas/microblaze: Re-indent print_insn_microblaze Date: Wed, 5 Jun 2024 14:15:15 -0700 Message-Id: <20240605211521.577094-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605211521.577094-1-richard.henderson@linaro.org> References: <20240605211521.577094-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42c.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, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier Message-Id: <20240412073346.458116-16-richard.henderson@linaro.org> --- disas/microblaze.c | 263 ++++++++++++++++++++++++--------------------- 1 file changed, 141 insertions(+), 122 deletions(-) diff --git a/disas/microblaze.c b/disas/microblaze.c index 3473c94164..c729c76585 100644 --- a/disas/microblaze.c +++ b/disas/microblaze.c @@ -787,134 +787,153 @@ static void print_immval_addr(struct disassemble_info *info, bool immfound, } int -print_insn_microblaze (bfd_vma memaddr, struct disassemble_info * info) +print_insn_microblaze(bfd_vma memaddr, struct disassemble_info *info) { - fprintf_function fprintf_func = info->fprintf_func; - void * stream = info->stream; - unsigned long inst, prev_inst; - const struct op_code_struct *op, *pop; - int immval = 0; - bfd_boolean immfound = FALSE; - static bfd_vma prev_insn_addr = -1; /*init the prev insn addr */ - static int prev_insn_vma = -1; /*init the prev insn vma */ - int curr_insn_vma = info->buffer_vma; + fprintf_function fprintf_func = info->fprintf_func; + void *stream = info->stream; + unsigned long inst, prev_inst; + const struct op_code_struct *op, *pop; + int immval = 0; + bool immfound = false; + static bfd_vma prev_insn_addr = -1; /*init the prev insn addr */ + static int prev_insn_vma = -1; /*init the prev insn vma */ + int curr_insn_vma = info->buffer_vma; - info->bytes_per_chunk = 4; + info->bytes_per_chunk = 4; - inst = read_insn_microblaze (memaddr, info, &op); - if (inst == 0) { - return -1; - } + inst = read_insn_microblaze (memaddr, info, &op); + if (inst == 0) { + return -1; + } - if (prev_insn_vma == curr_insn_vma) { - if (memaddr-(info->bytes_per_chunk) == prev_insn_addr) { - prev_inst = read_insn_microblaze (prev_insn_addr, info, &pop); - if (prev_inst == 0) - return -1; - if (pop->instr == imm) { - immval = (get_int_field_imm(prev_inst) << 16) & 0xffff0000; - immfound = TRUE; + if (prev_insn_vma == curr_insn_vma) { + if (memaddr - info->bytes_per_chunk == prev_insn_addr) { + prev_inst = read_insn_microblaze (prev_insn_addr, info, &pop); + if (prev_inst == 0) + return -1; + if (pop->instr == imm) { + immval = (get_int_field_imm(prev_inst) << 16) & 0xffff0000; + immfound = TRUE; + } + else { + immval = 0; + immfound = FALSE; + } + } } - else { - immval = 0; - immfound = FALSE; - } - } - } - /* make curr insn as prev insn */ - prev_insn_addr = memaddr; - prev_insn_vma = curr_insn_vma; + /* make curr insn as prev insn */ + prev_insn_addr = memaddr; + prev_insn_vma = curr_insn_vma; - if (op->name == 0) { - fprintf_func (stream, ".short 0x%04lx", inst); - } - else - { - fprintf_func (stream, "%s", op->name); + if (op->name == 0) { + fprintf_func (stream, ".short 0x%04lx", inst); + return 4; + } + + fprintf_func (stream, "%s", op->name); - switch (op->inst_type) - { - case INST_TYPE_RD_R1_R2: - fprintf_func(stream, "\t%s, %s, %s", get_field_rd(inst), get_field_r1(inst), get_field_r2(inst)); - break; - case INST_TYPE_RD_R1_IMM: - fprintf_func(stream, "\t%s, %s, %s", get_field_rd(inst), get_field_r1(inst), get_field_imm(inst)); - if (get_int_field_r1(inst) == 0) { - print_immval_addr(info, immfound, immval, inst, 0); - } - break; - case INST_TYPE_RD_R1_IMM5: - fprintf_func(stream, "\t%s, %s, %s", get_field_rd(inst), get_field_r1(inst), get_field_imm5(inst)); - break; - case INST_TYPE_RD_RFSL: - fprintf_func(stream, "\t%s, %s", get_field_rd(inst), get_field_rfsl(inst)); - break; - case INST_TYPE_R1_RFSL: - fprintf_func(stream, "\t%s, %s", get_field_r1(inst), get_field_rfsl(inst)); - break; - case INST_TYPE_RD_SPECIAL: - fprintf_func(stream, "\t%s, %s", get_field_rd(inst), get_field_special(inst, op)); - break; - case INST_TYPE_SPECIAL_R1: - fprintf_func(stream, "\t%s, %s", get_field_special(inst, op), get_field_r1(inst)); - break; - case INST_TYPE_RD_R1: - fprintf_func(stream, "\t%s, %s", get_field_rd(inst), get_field_r1(inst)); - break; - case INST_TYPE_R1_R2: - fprintf_func(stream, "\t%s, %s", get_field_r1(inst), get_field_r2(inst)); - break; - case INST_TYPE_R1_IMM: - fprintf_func(stream, "\t%s, %s", get_field_r1(inst), get_field_imm(inst)); - /* The non-pc relative instructions are returns, which shouldn't - have a label printed */ - if (op->inst_offset_type == INST_PC_OFFSET) { - print_immval_addr(info, immfound, immval, inst, memaddr); - } - break; - case INST_TYPE_RD_IMM: - fprintf_func(stream, "\t%s, %s", get_field_rd(inst), get_field_imm(inst)); - print_immval_addr(info, immfound, immval, inst, - op->inst_offset_type == INST_PC_OFFSET - ? memaddr : 0); - break; - case INST_TYPE_IMM: - fprintf_func(stream, "\t%s", get_field_imm(inst)); - if (op->instr != imm) { - print_immval_addr(info, immfound, immval, inst, - op->inst_offset_type == INST_PC_OFFSET - ? memaddr : 0); - } - break; - case INST_TYPE_RD_R2: - fprintf_func(stream, "\t%s, %s", get_field_rd(inst), get_field_r2(inst)); - break; - case INST_TYPE_R2: - fprintf_func(stream, "\t%s", get_field_r2(inst)); - break; - case INST_TYPE_R1: - fprintf_func(stream, "\t%s", get_field_r1(inst)); - break; - case INST_TYPE_RD_R1_SPECIAL: - fprintf_func(stream, "\t%s, %s", get_field_rd(inst), get_field_r2(inst)); - break; - case INST_TYPE_RD_IMM15: - fprintf_func(stream, "\t%s, %s", get_field_rd(inst), get_field_imm15(inst)); - break; - /* For tuqula instruction */ - case INST_TYPE_RD: - fprintf_func(stream, "\t%s", get_field_rd(inst)); - break; - case INST_TYPE_RFSL: - fprintf_func(stream, "\t%s", get_field_rfsl(inst)); - break; - default: - /* if the disassembler lags the instruction set */ - fprintf_func (stream, "\tundecoded operands, inst is 0x%04lx", inst); - break; - } + switch (op->inst_type) { + case INST_TYPE_RD_R1_R2: + fprintf_func(stream, "\t%s, %s, %s", + get_field_rd(inst), get_field_r1(inst), + get_field_r2(inst)); + break; + case INST_TYPE_RD_R1_IMM: + fprintf_func(stream, "\t%s, %s, %s", + get_field_rd(inst), get_field_r1(inst), + get_field_imm(inst)); + if (get_int_field_r1(inst) == 0) { + print_immval_addr(info, immfound, immval, inst, 0); + } + break; + case INST_TYPE_RD_R1_IMM5: + fprintf_func(stream, "\t%s, %s, %s", + get_field_rd(inst), get_field_r1(inst), + get_field_imm5(inst)); + break; + case INST_TYPE_RD_RFSL: + fprintf_func(stream, "\t%s, %s", + get_field_rd(inst), get_field_rfsl(inst)); + break; + case INST_TYPE_R1_RFSL: + fprintf_func(stream, "\t%s, %s", + get_field_r1(inst), get_field_rfsl(inst)); + break; + case INST_TYPE_RD_SPECIAL: + fprintf_func(stream, "\t%s, %s", + get_field_rd(inst), get_field_special(inst, op)); + break; + case INST_TYPE_SPECIAL_R1: + fprintf_func(stream, "\t%s, %s", + get_field_special(inst, op), get_field_r1(inst)); + break; + case INST_TYPE_RD_R1: + fprintf_func(stream, "\t%s, %s", + get_field_rd(inst), get_field_r1(inst)); + break; + case INST_TYPE_R1_R2: + fprintf_func(stream, "\t%s, %s", + get_field_r1(inst), get_field_r2(inst)); + break; + case INST_TYPE_R1_IMM: + fprintf_func(stream, "\t%s, %s", + get_field_r1(inst), get_field_imm(inst)); + /* + * The non-pc relative instructions are returns, + * which shouldn't have a label printed. + */ + if (op->inst_offset_type == INST_PC_OFFSET) { + print_immval_addr(info, immfound, immval, inst, memaddr); + } + break; + case INST_TYPE_RD_IMM: + fprintf_func(stream, "\t%s, %s", + get_field_rd(inst), get_field_imm(inst)); + print_immval_addr(info, immfound, immval, inst, + op->inst_offset_type == INST_PC_OFFSET + ? memaddr : 0); + break; + case INST_TYPE_IMM: + fprintf_func(stream, "\t%s", get_field_imm(inst)); + if (op->instr != imm) { + print_immval_addr(info, immfound, immval, inst, + op->inst_offset_type == INST_PC_OFFSET + ? memaddr : 0); + } + break; + case INST_TYPE_RD_R2: + fprintf_func(stream, "\t%s, %s", + get_field_rd(inst), get_field_r2(inst)); + break; + case INST_TYPE_R2: + fprintf_func(stream, "\t%s", + get_field_r2(inst)); + break; + case INST_TYPE_R1: + fprintf_func(stream, "\t%s", + get_field_r1(inst)); + break; + case INST_TYPE_RD_R1_SPECIAL: + fprintf_func(stream, "\t%s, %s", + get_field_rd(inst), get_field_r2(inst)); + break; + case INST_TYPE_RD_IMM15: + fprintf_func(stream, "\t%s, %s", + get_field_rd(inst), get_field_imm15(inst)); + break; + /* For tuqula instruction */ + case INST_TYPE_RD: + fprintf_func(stream, "\t%s", + get_field_rd(inst)); + break; + case INST_TYPE_RFSL: + fprintf_func(stream, "\t%s", + get_field_rfsl(inst)); + break; + default: + /* if the disassembler lags the instruction set */ + fprintf_func(stream, "\tundecoded operands, inst is 0x%04lx", inst); + break; } - - /* Say how many bytes we consumed? */ - return 4; + return 4; } From patchwork Wed Jun 5 21:15:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 801638 Delivered-To: patch@linaro.org Received: by 2002:a5d:5610:0:b0:35b:5a80:51b4 with SMTP id l16csp36541wrv; Wed, 5 Jun 2024 14:16:59 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUy9XJvkjg2HRAuZwxBW7NhLnWKhTuYAcVozF+TESXd62/paGp1dlUQr71rEmdPH/UHvfnXMUb6ZgxkGj2TTwzL X-Google-Smtp-Source: AGHT+IHOuhN4coHn6u7MoCIOw3OV71/Ii37dAyU5HwyG0m3HVsU4g/oLKixeGY+HZp0r7HEVZY8c X-Received: by 2002:a05:6808:7c4:b0:3d1:cc2a:f142 with SMTP id 5614622812f47-3d2043ad6e7mr4186823b6e.34.1717622219180; Wed, 05 Jun 2024 14:16:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717622219; cv=none; d=google.com; s=arc-20160816; b=q6p9QPCOkTDjH1HjNVBGsDFSOXIHwE0fi2SaZOvXXXxwTpvYLVbjOIQ4ZlCqEf4x3a SXxgHEBr3G+1h6jgSkTFRCKOYomMTghi5iOj2SAn6n63RA9Fi9CJBEJFOgghQMyM1150 hHGtSkb0sh4JJipSEEYwinjBBrlWtdekkMMCnLnb+gpO1A0dsUyp8qyPfvzlPlS4CT/6 F/QabfAg7FtX3eHOMJwYcfHLrec9ImRA5G1CeXjbppYp328UaPpRz3aqy9ryJlF6N+zE KVX72MtCCozGY2+iVbYpCecsUFWuEIW5Czo+O/+VVMoU6L60e+1OylDeLibsucu500G1 UM9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=P9TeIKJ5a0Abz4CX9bNs6c78/V1xEablimfS+HQJI64=; fh=vm85eyWrvOAHduw3sqEA+cYBqvHB7M0MHFcRJg7VWOo=; b=WrJwr5MPYWS0ftPjx4yMsWceELTkk/HORrTmZEJpcwiKpM8+nt5O49SeC6BWCwUoOd Wp1nd2A06u8d/LWrunLMF/D5wjUzgXwRExuSbQkXRzf2SXn55leScx0G33hbSlPGiafH O4wQDV13oBBGxPE/f9xwq1mMyIKlwP2XSoa9Zp2rLwf1BuPA3dauynKM73rFr1cWTVKR b2D2aWSkC/viTctIQCqJWYaYlr6/mJsus79J8y/r+kFcDyau64EMi5hNmTcnmylpBokh zI2mo1XYGPfE0xJZRmD6D5GlF00G1eB79QDuiUbPwUHd0/WOIVcK6QTBjpeg20+KZGPW Nb0w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="U/AtkR6L"; 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 af79cd13be357-795196d66b0si449308585a.602.2024.06.05.14.16.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jun 2024 14:16:59 -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="U/AtkR6L"; 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 1sExzB-0000ih-0E; Wed, 05 Jun 2024 17:15:57 -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 1sExyz-0000eE-3Y for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:45 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sExyo-0003Qn-08 for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:44 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-70249faa853so185248b3a.3 for ; Wed, 05 Jun 2024 14:15:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717622133; x=1718226933; darn=nongnu.org; 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=P9TeIKJ5a0Abz4CX9bNs6c78/V1xEablimfS+HQJI64=; b=U/AtkR6LtL44ZIdz07E8rh5TmeJ3hn5PwwYE1yb0qSLMdm7Wj32NfZlMzLdCeOoCW5 zc9AkRkHWgsj48dzn2pp0oV38thP/xwNVRYUYRzGHDjAp5ovUKDv/FjJlLzNsWAGCEec wWgMBgnll5Uy5cXlqDZhgrI0rQ2vWYSgwURaTy3r+McUMi338xpreXpq54kesc5/k1aC odO3S+jeuwkKOaIJNeO//cZy1JV1aaS1h1mOoZN0IZOXPlpMcteKt+2sKyd+kN7jFnG7 9/zw7FUSAJsVhfFU453DDydb9SXKGbVt/dqkqlv8T1na2cu3zv6trETIyHo5gGccBfcb VNIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717622133; x=1718226933; 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=P9TeIKJ5a0Abz4CX9bNs6c78/V1xEablimfS+HQJI64=; b=ADHVFC+QvNvH4iBjdu+FgtPS0LsfKt8KsyPTpbP/TsRljDOQEK4dh1siMOzbqoPTqW BgqwAUdFCsL0LpQXXAnLgRiAapaMPbRPVed/6e8YaADOZAgKJZQOeSsDCnzAhsdF5TyD VpJSLYi8x6vH0acd86/tYAxzQwdUBd62tpjiW807dvppQNI13TxCUnRpNLyIvqThttxn 7E8q+mmK4pmjrtyx2X9MvRSVLuHximXohV4UhGhgCO+oeUHTqbUO1+YLS2YEbZXQI7S4 OEo1X7bGnNCnJ8xZPL6TVQlVF9SVP2ewSasEMz7QWD8o9/ni/CpNK7eX69rzjY69YaWR +qhQ== X-Gm-Message-State: AOJu0YyiMPd2iJgN6RIa5KaXEYkKrxmm7bdIPZhF7bPFLDONOup1iz6u Zf4lOFEyos3wqJffR9s9q4MmYuHs86u3nbizSGJYkV+YOXWBZ1QopdGG5Ld2uAm203WetLzQUfD K X-Received: by 2002:a05:6a00:811:b0:702:2f19:659c with SMTP id d2e1a72fcca58-703e5a0cec7mr4603508b3a.31.1717622132575; Wed, 05 Jun 2024 14:15:32 -0700 (PDT) Received: from stoup.. ([71.212.132.216]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70242aec7d0sm9347538b3a.99.2024.06.05.14.15.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 14:15:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier Subject: [PULL 11/16] disas/microblaze: Merge op->name output into each fprintf Date: Wed, 5 Jun 2024 14:15:16 -0700 Message-Id: <20240605211521.577094-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605211521.577094-1-richard.henderson@linaro.org> References: <20240605211521.577094-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x435.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, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org In the common case, issue one single fprintf. Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier Message-Id: <20240412073346.458116-17-richard.henderson@linaro.org> --- disas/microblaze.c | 80 +++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/disas/microblaze.c b/disas/microblaze.c index c729c76585..a537ac65dd 100644 --- a/disas/microblaze.c +++ b/disas/microblaze.c @@ -830,54 +830,52 @@ print_insn_microblaze(bfd_vma memaddr, struct disassemble_info *info) return 4; } - fprintf_func (stream, "%s", op->name); - switch (op->inst_type) { case INST_TYPE_RD_R1_R2: - fprintf_func(stream, "\t%s, %s, %s", - get_field_rd(inst), get_field_r1(inst), + fprintf_func(stream, "%s\t%s, %s, %s", + op->name, get_field_rd(inst), get_field_r1(inst), get_field_r2(inst)); break; case INST_TYPE_RD_R1_IMM: - fprintf_func(stream, "\t%s, %s, %s", - get_field_rd(inst), get_field_r1(inst), + fprintf_func(stream, "%s\t%s, %s, %s", + op->name, get_field_rd(inst), get_field_r1(inst), get_field_imm(inst)); if (get_int_field_r1(inst) == 0) { print_immval_addr(info, immfound, immval, inst, 0); } break; case INST_TYPE_RD_R1_IMM5: - fprintf_func(stream, "\t%s, %s, %s", - get_field_rd(inst), get_field_r1(inst), + fprintf_func(stream, "%s\t%s, %s, %s", + op->name, get_field_rd(inst), get_field_r1(inst), get_field_imm5(inst)); break; case INST_TYPE_RD_RFSL: - fprintf_func(stream, "\t%s, %s", - get_field_rd(inst), get_field_rfsl(inst)); + fprintf_func(stream, "%s\t%s, %s", + op->name, get_field_rd(inst), get_field_rfsl(inst)); break; case INST_TYPE_R1_RFSL: - fprintf_func(stream, "\t%s, %s", - get_field_r1(inst), get_field_rfsl(inst)); + fprintf_func(stream, "%s\t%s, %s", + op->name, get_field_r1(inst), get_field_rfsl(inst)); break; case INST_TYPE_RD_SPECIAL: - fprintf_func(stream, "\t%s, %s", - get_field_rd(inst), get_field_special(inst, op)); + fprintf_func(stream, "%s\t%s, %s", + op->name, get_field_rd(inst), get_field_special(inst, op)); break; case INST_TYPE_SPECIAL_R1: - fprintf_func(stream, "\t%s, %s", - get_field_special(inst, op), get_field_r1(inst)); + fprintf_func(stream, "%s\t%s, %s", + op->name, get_field_special(inst, op), get_field_r1(inst)); break; case INST_TYPE_RD_R1: - fprintf_func(stream, "\t%s, %s", - get_field_rd(inst), get_field_r1(inst)); + fprintf_func(stream, "%s\t%s, %s", + op->name, get_field_rd(inst), get_field_r1(inst)); break; case INST_TYPE_R1_R2: - fprintf_func(stream, "\t%s, %s", - get_field_r1(inst), get_field_r2(inst)); + fprintf_func(stream, "%s\t%s, %s", + op->name, get_field_r1(inst), get_field_r2(inst)); break; case INST_TYPE_R1_IMM: - fprintf_func(stream, "\t%s, %s", - get_field_r1(inst), get_field_imm(inst)); + fprintf_func(stream, "%s\t%s, %s", + op->name, get_field_r1(inst), get_field_imm(inst)); /* * The non-pc relative instructions are returns, * which shouldn't have a label printed. @@ -887,14 +885,15 @@ print_insn_microblaze(bfd_vma memaddr, struct disassemble_info *info) } break; case INST_TYPE_RD_IMM: - fprintf_func(stream, "\t%s, %s", - get_field_rd(inst), get_field_imm(inst)); + fprintf_func(stream, "%s\t%s, %s", + op->name, get_field_rd(inst), get_field_imm(inst)); print_immval_addr(info, immfound, immval, inst, op->inst_offset_type == INST_PC_OFFSET ? memaddr : 0); break; case INST_TYPE_IMM: - fprintf_func(stream, "\t%s", get_field_imm(inst)); + fprintf_func(stream, "%s\t%s", + op->name, get_field_imm(inst)); if (op->instr != imm) { print_immval_addr(info, immfound, immval, inst, op->inst_offset_type == INST_PC_OFFSET @@ -902,37 +901,38 @@ print_insn_microblaze(bfd_vma memaddr, struct disassemble_info *info) } break; case INST_TYPE_RD_R2: - fprintf_func(stream, "\t%s, %s", - get_field_rd(inst), get_field_r2(inst)); + fprintf_func(stream, "%s\t%s, %s", + op->name, get_field_rd(inst), get_field_r2(inst)); break; case INST_TYPE_R2: - fprintf_func(stream, "\t%s", - get_field_r2(inst)); + fprintf_func(stream, "%s\t%s", + op->name, get_field_r2(inst)); break; case INST_TYPE_R1: - fprintf_func(stream, "\t%s", - get_field_r1(inst)); + fprintf_func(stream, "%s\t%s", + op->name, get_field_r1(inst)); break; case INST_TYPE_RD_R1_SPECIAL: - fprintf_func(stream, "\t%s, %s", - get_field_rd(inst), get_field_r2(inst)); + fprintf_func(stream, "%s\t%s, %s", + op->name, get_field_rd(inst), get_field_r2(inst)); break; case INST_TYPE_RD_IMM15: - fprintf_func(stream, "\t%s, %s", - get_field_rd(inst), get_field_imm15(inst)); + fprintf_func(stream, "%s\t%s, %s", + op->name, get_field_rd(inst), get_field_imm15(inst)); break; /* For tuqula instruction */ case INST_TYPE_RD: - fprintf_func(stream, "\t%s", - get_field_rd(inst)); + fprintf_func(stream, "%s\t%s", + op->name, get_field_rd(inst)); break; case INST_TYPE_RFSL: - fprintf_func(stream, "\t%s", - get_field_rfsl(inst)); + fprintf_func(stream, "%s\t%s", + op->name, get_field_rfsl(inst)); break; default: /* if the disassembler lags the instruction set */ - fprintf_func(stream, "\tundecoded operands, inst is 0x%04lx", inst); + fprintf_func(stream, "%s\tundecoded operands, inst is 0x%04lx", + op->name, inst); break; } return 4; From patchwork Wed Jun 5 21:15:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 801641 Delivered-To: patch@linaro.org Received: by 2002:a5d:5610:0:b0:35b:5a80:51b4 with SMTP id l16csp36708wrv; Wed, 5 Jun 2024 14:17:22 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVQ9Zbh8QrELySVTn6aCeftMg+Z9SNSXos5E3jfvqDqrfNDcFOsQSCDQWRIuR7BU4QbyNNKtjkTIUB+ycdHhSDs X-Google-Smtp-Source: AGHT+IEgn1VjMhslJrLnnmAaI5hPPQW4GcBoqYkP4LjEE0fhkXRekMCr4lyg8yW2BjQtqR3Me2i/ X-Received: by 2002:a05:6358:6f06:b0:19b:27ce:5db7 with SMTP id e5c5f4694b2df-19c66dac28dmr451063455d.3.1717622242268; Wed, 05 Jun 2024 14:17:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717622242; cv=none; d=google.com; s=arc-20160816; b=FJVhWVbl/lwRnq+U/GCz15zIdlBbiiD7FFYR2DxxWR9WT4AX+A3pkG7zjfuUKVnAdX oAxzIZeF4BhIIwALynOoItIEPfCDHtOvhFYQk9/YkZeuLf1ode/sVE+DUkD4F0bcN1pu /NF4X2OTIOIEwv6guGq7n8ww5SCIQzEu4nQfGEyvPnyu4cH5eba9RbJN5+Tr9+3P00Ni lPYXH/INU4lMsB4cufLfSpU5w+LFtqK3ISvQCi2Kyingg24HqUFXMt7YVmHj06V2FZ0b d9ReorqUjUSGJ5/mjQBAP5J8rYSQPBxkoreyEvnZi6KMrVR8r+2HpvO+0fTV0MECKO3c yXKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=ZFxHmpuLno/vzESqMH03QaHYXrgS2cWTQ/a+ozUvhB0=; fh=vm85eyWrvOAHduw3sqEA+cYBqvHB7M0MHFcRJg7VWOo=; b=Wx+AtVbD+XOr+CZ/EdlySL/gveMkrFjrz6cNCqtVpQ5j0sQsTBACph/zVda4Kyy1W1 eHSKwcF/CD53KfTZ8UVk/ic/vrOafiAsGcRnGZPdQc95MsqdpgoxnhUVTNSFo30TBfCx MPF+C4/Y5dHGsES4wAL8gWv53slXO+EatuO3D63N/85vnK/oQueGpOJZLmv3GlFGOh/u paurDhPN3sLJMkOtzxh7dqr3KN9lCdg//aItGRhRcrWs0rvxl1hkW9f06fv9gVkBbDsF /XPyIO84ZW1N0uVhDuGr/Zd6SGU6y83KMpGr5aeq4vTnEZjRooutuDzxcppmDeDV+uMM uBgA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DlT8CeQ+; 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 6a1803df08f44-6ae4b415240si64935996d6.369.2024.06.05.14.17.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jun 2024 14:17:22 -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=DlT8CeQ+; 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 1sExz2-0000ft-VT; Wed, 05 Jun 2024 17:15:48 -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 1sExz0-0000ec-J1 for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:47 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sExyp-0003R8-31 for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:46 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-703ed5d37acso209616b3a.0 for ; Wed, 05 Jun 2024 14:15:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717622133; x=1718226933; darn=nongnu.org; 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=ZFxHmpuLno/vzESqMH03QaHYXrgS2cWTQ/a+ozUvhB0=; b=DlT8CeQ+dyq7X+YC5B4SShHZnYGNLHkxz/+4350yQ3s2ZRv4xmZes90k03y8nXvl/8 peBtDh8/w9JZgDULyaFOqcLoVfyHT9fyTiqz9kIT85PZE22qwk9StD+IPwdiLby14vHG xiwBM+0Wyk7AUl4gqJYh/0B8XEQUJD0oDKLv2UwlMFuR33KtyEuQIihvKESCpZ4T07Dy ILSVYeBbP0qh5pNwTcm/Q5RBOqOuo4CQV19Qi6Ed0zNoG87sjDmVd71Xrc0coKy5aaiC kyikqCazANFXho6PHcfx0A56NLGsYl0ndgPhobba4C79kSfdka/vWSAZWV35JX5nFzUT Wt0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717622133; x=1718226933; 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=ZFxHmpuLno/vzESqMH03QaHYXrgS2cWTQ/a+ozUvhB0=; b=E+nl18UnBPoX351zmgC+Aplh6C9Z8CY3aaHmdHDHbMQxArgETLzrRRFHokUQE+fp87 kKGwRHSZAEqQaLEVoywMTHVADgBwtRi/m0uR+b21qNE1Q8MUsuMm4hSGNRXWzbpQwC7B wOvRIaKVUyXtKlqkVLuLz9SNhjFVtIySAxTfC9Eki/Ix5Mg40kYI3FqYuxtg3NQwo8tj w31SbtQ8qqyy6QXfUKBNC4IPewgLSNgSFd2rlDThw5xeI+MdjvAwOJwrCYDzH0rfXw3U /W7zI/Qrc74Lvh724oqnQpp3OwhZlm6PwgtLTGZ5gUvXU+syHJIrSptc5vHN2iKog+iI nprA== X-Gm-Message-State: AOJu0Ywt0JDrsCBeJPbyUKkj8wqqboNfV+PLHFUSGjLTveoi1Je6YsCz XnNAHBst0NXpbHzO/pU64Dn3VJ6HiKnzqJREyGybyngy6ouH29Tket9xnh5ovLH/uiVIIFTdmWT f X-Received: by 2002:a05:6a00:1991:b0:6ed:de70:5ef8 with SMTP id d2e1a72fcca58-703e5986e56mr4814896b3a.6.1717622133569; Wed, 05 Jun 2024 14:15:33 -0700 (PDT) Received: from stoup.. ([71.212.132.216]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70242aec7d0sm9347538b3a.99.2024.06.05.14.15.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 14:15:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier Subject: [PULL 12/16] disas/microblaze: Print registers directly with PRIreg Date: Wed, 5 Jun 2024 14:15:17 -0700 Message-Id: <20240605211521.577094-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605211521.577094-1-richard.henderson@linaro.org> References: <20240605211521.577094-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42e.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, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Use a printf format instead of sprintf into a buffer. Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier Message-Id: <20240412073346.458116-18-richard.henderson@linaro.org> --- disas/microblaze.c | 54 ++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/disas/microblaze.c b/disas/microblaze.c index a537ac65dd..c12968f3b9 100644 --- a/disas/microblaze.c +++ b/disas/microblaze.c @@ -563,7 +563,7 @@ static const struct op_code_struct { }; /* prefix for register names */ -static const char register_prefix[] = "r"; +#define register_prefix "r" static const char fsl_register_prefix[] = "rfsl"; static const char pvr_register_prefix[] = "rpvr"; @@ -579,15 +579,16 @@ static const char pvr_register_prefix[] = "rpvr"; #include "disas/dis-asm.h" -#define get_field_rd(instr) get_field(instr, RD_MASK, RD_LOW) -#define get_field_r1(instr) get_field(instr, RA_MASK, RA_LOW) -#define get_field_r2(instr) get_field(instr, RB_MASK, RB_LOW) +#define PRIreg register_prefix "%ld" + +#define get_field_rd(instr) ((instr & RD_MASK) >> RD_LOW) +#define get_field_r1(instr) ((instr & RA_MASK) >> RA_LOW) +#define get_field_r2(instr) ((instr & RB_MASK) >> RB_LOW) #define get_int_field_imm(instr) ((instr & IMM_MASK) >> IMM_LOW) #define get_int_field_r1(instr) ((instr & RA_MASK) >> RA_LOW) /* Local function prototypes. */ -static char * get_field (long instr, long mask, unsigned short low); static char * get_field_imm (long instr); static char * get_field_imm5 (long instr); static char * get_field_rfsl (long instr); @@ -596,15 +597,6 @@ static char * get_field_imm15 (long instr); static char * get_field_unsigned_imm (long instr); #endif -static char * -get_field (long instr, long mask, unsigned short low) -{ - char tmpstr[25]; - snprintf(tmpstr, sizeof(tmpstr), "%s%d", register_prefix, - (int)((instr & mask) >> low)); - return(strdup(tmpstr)); -} - static char * get_field_imm (long instr) { @@ -832,12 +824,12 @@ print_insn_microblaze(bfd_vma memaddr, struct disassemble_info *info) switch (op->inst_type) { case INST_TYPE_RD_R1_R2: - fprintf_func(stream, "%s\t%s, %s, %s", + fprintf_func(stream, "%s\t" PRIreg ", " PRIreg ", " PRIreg, op->name, get_field_rd(inst), get_field_r1(inst), get_field_r2(inst)); break; case INST_TYPE_RD_R1_IMM: - fprintf_func(stream, "%s\t%s, %s, %s", + fprintf_func(stream, "%s\t" PRIreg ", " PRIreg ", %s", op->name, get_field_rd(inst), get_field_r1(inst), get_field_imm(inst)); if (get_int_field_r1(inst) == 0) { @@ -845,36 +837,36 @@ print_insn_microblaze(bfd_vma memaddr, struct disassemble_info *info) } break; case INST_TYPE_RD_R1_IMM5: - fprintf_func(stream, "%s\t%s, %s, %s", + fprintf_func(stream, "%s\t" PRIreg ", " PRIreg ", %s", op->name, get_field_rd(inst), get_field_r1(inst), get_field_imm5(inst)); break; case INST_TYPE_RD_RFSL: - fprintf_func(stream, "%s\t%s, %s", + fprintf_func(stream, "%s\t" PRIreg ", %s", op->name, get_field_rd(inst), get_field_rfsl(inst)); break; case INST_TYPE_R1_RFSL: - fprintf_func(stream, "%s\t%s, %s", + fprintf_func(stream, "%s\t" PRIreg ", %s", op->name, get_field_r1(inst), get_field_rfsl(inst)); break; case INST_TYPE_RD_SPECIAL: - fprintf_func(stream, "%s\t%s, %s", + fprintf_func(stream, "%s\t" PRIreg ", %s", op->name, get_field_rd(inst), get_field_special(inst, op)); break; case INST_TYPE_SPECIAL_R1: - fprintf_func(stream, "%s\t%s, %s", + fprintf_func(stream, "%s\t%s, " PRIreg, op->name, get_field_special(inst, op), get_field_r1(inst)); break; case INST_TYPE_RD_R1: - fprintf_func(stream, "%s\t%s, %s", + fprintf_func(stream, "%s\t" PRIreg ", " PRIreg, op->name, get_field_rd(inst), get_field_r1(inst)); break; case INST_TYPE_R1_R2: - fprintf_func(stream, "%s\t%s, %s", + fprintf_func(stream, "%s\t" PRIreg ", " PRIreg, op->name, get_field_r1(inst), get_field_r2(inst)); break; case INST_TYPE_R1_IMM: - fprintf_func(stream, "%s\t%s, %s", + fprintf_func(stream, "%s\t" PRIreg ", %s", op->name, get_field_r1(inst), get_field_imm(inst)); /* * The non-pc relative instructions are returns, @@ -885,7 +877,7 @@ print_insn_microblaze(bfd_vma memaddr, struct disassemble_info *info) } break; case INST_TYPE_RD_IMM: - fprintf_func(stream, "%s\t%s, %s", + fprintf_func(stream, "%s\t" PRIreg ", %s", op->name, get_field_rd(inst), get_field_imm(inst)); print_immval_addr(info, immfound, immval, inst, op->inst_offset_type == INST_PC_OFFSET @@ -901,28 +893,28 @@ print_insn_microblaze(bfd_vma memaddr, struct disassemble_info *info) } break; case INST_TYPE_RD_R2: - fprintf_func(stream, "%s\t%s, %s", + fprintf_func(stream, "%s\t" PRIreg ", " PRIreg, op->name, get_field_rd(inst), get_field_r2(inst)); break; case INST_TYPE_R2: - fprintf_func(stream, "%s\t%s", + fprintf_func(stream, "%s\t" PRIreg, op->name, get_field_r2(inst)); break; case INST_TYPE_R1: - fprintf_func(stream, "%s\t%s", + fprintf_func(stream, "%s\t" PRIreg, op->name, get_field_r1(inst)); break; case INST_TYPE_RD_R1_SPECIAL: - fprintf_func(stream, "%s\t%s, %s", + fprintf_func(stream, "%s\t" PRIreg ", " PRIreg, op->name, get_field_rd(inst), get_field_r2(inst)); break; case INST_TYPE_RD_IMM15: - fprintf_func(stream, "%s\t%s, %s", + fprintf_func(stream, "%s\t" PRIreg ", %s", op->name, get_field_rd(inst), get_field_imm15(inst)); break; /* For tuqula instruction */ case INST_TYPE_RD: - fprintf_func(stream, "%s\t%s", + fprintf_func(stream, "%s\t" PRIreg, op->name, get_field_rd(inst)); break; case INST_TYPE_RFSL: From patchwork Wed Jun 5 21:15:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 801642 Delivered-To: patch@linaro.org Received: by 2002:a5d:5610:0:b0:35b:5a80:51b4 with SMTP id l16csp36733wrv; Wed, 5 Jun 2024 14:17:25 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWrU1p91tDrS2nIHvQKki8JMv45No8b1ovCAWyiBuN2o3nadPuuAd+Q+ls+oI6cqrPDHNl5XynDQy00I64HRp/m X-Google-Smtp-Source: AGHT+IFCLtbEllyx3vsTPZfOLWJfRZBuFMU8LL2jRTwY5WOZzP1wUiKUKNCN6j5r/TZ3sXz7P+kU X-Received: by 2002:a05:6820:2212:b0:5b9:fc9f:6a6c with SMTP id 006d021491bc7-5ba78d3b48cmr4164610eaf.0.1717622245366; Wed, 05 Jun 2024 14:17:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717622245; cv=none; d=google.com; s=arc-20160816; b=qsuzC9EoSjIO6/Nxrn3BOUNDnOOUrLv8hFdEpkBfdtg8JRP9dpMmrNS+BgsA922/4C lMeeAUOv/Zg/ERo2+ZJJwMfuod+jgwaVgWyjLqp5M2zeg9TBgj3RAADVRK2SK+4RHX8f n/dJNn+hXsd2848tZCj0cUk9ruUFnh+j356uUDi1ynnGCtRB35gWppcgdGMgx2jnI3Eg PL2f2V7JjCyc1fSdCcmfPKDNCOjf9g3TpWfQqk8W1UxEFAFPfb5u4wUditEXyoaS45ap oglB8V66lX4WEbfxhDbMqgBheA0fyCLr0Gs5H98imU2HqH3qZRtQ61BByPdHlTpXnzSz H5eQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=WG33VLZJC75PnOwvnc92vEocKZlB7Ym1PixDIRSe3h0=; fh=vm85eyWrvOAHduw3sqEA+cYBqvHB7M0MHFcRJg7VWOo=; b=sn1fP/Eprx7bay0tsLB7ekPxUipzomJZeAQ8x5ng85ahcJc3R4Z9rft6Zsi/Ynvqv4 /ffcjne3CD9JHFU8VLzNQ4ItYXuCkvZ/+yRWhCdqwCjgY3vs4xMpD+a+X6LZVDvy1BBD D5hEYLAc6BCHaQTMuYkbERVItjVTUp2fWCNjnSMQnlMBDgoW7VBzMK5qyYY0yKmsxYZC iVInk9SzlC7idjhlMljQ453Qq2B5oPklQdD3WDu22pk15xB36ZU+kQ9l2Y/AYS1EJxe9 13DPO8vFNr6DqG+CkXaZAqRGdyhVyQmoa92INz3O9+aHtKjIfzr127gc1t9gYN+jSBmF jThw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="MeCgxm/d"; 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 af79cd13be357-794f32a5331si77484685a.572.2024.06.05.14.17.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jun 2024 14:17:25 -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="MeCgxm/d"; 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 1sExzC-0000jb-QR; Wed, 05 Jun 2024 17:15:58 -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 1sExz4-0000gS-Gp for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:51 -0400 Received: from mail-pf1-x429.google.com ([2607:f8b0:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sExyt-0003RL-L4 for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:50 -0400 Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-70249faa853so185264b3a.3 for ; Wed, 05 Jun 2024 14:15:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717622135; x=1718226935; darn=nongnu.org; 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=WG33VLZJC75PnOwvnc92vEocKZlB7Ym1PixDIRSe3h0=; b=MeCgxm/dwyzn8ly/hvJE2AixVt40RUVBP4Zij5nbGVTzsKbEjDDMmpL99l4uzgBft3 0NFNtBAI/i/BlmlgbNnElLKbNNo/SsL0hnud0NIRIXsbmnPYCeO7dyAHTDPXYmLpkkK9 zKZZi8T2J8p2JD6JyY60M6eRD6cIcfkvWxhRkyX9bsWYKvzHfpOcRLZwLeeS6kziEme1 cOIsAR3eWIhvIBUv66DeuQzgeakIF5AuhVWDjjlZNsH77CI9Jz9N8lIa3KeiTZTpRgxr 0dN2aNBeT+ZcpSWkaVmtzm0GNOVn6p/dDH13sJ4094r/PSTfFutciuqMnyr3TN1o+EzF O+Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717622135; x=1718226935; 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=WG33VLZJC75PnOwvnc92vEocKZlB7Ym1PixDIRSe3h0=; b=JKjDZ7Y6IYRShqnm+ImfpQeIZokuFu2LGkch9yGPN0mgs3gYgFNi4d6gNcQj5MPCxg U9vyLGS2VU7hhEABMIKJVaQj+BYZ4UJg1N79m8D120IuFp/QIUoqrnjZjL3SHbRlM0mi gZgkKyICaoHfpUoRVQnnCJ5LQuk54Plw68uzsT10IR8dRN3kz5h0cWmF95a7pt1S5XoR E9yc4THHOw635VjopPVAulB7tAnU0XvBUeYHvc2Ou57ekGcYAXj04ClnP/iAGdv59pGE Th3aOTP7bn+sKFLlnskv8XHCxR+9jNOWexnJpMVyiEDqaAUTkjOgBWyXoNFH/GTeUsMa xvSA== X-Gm-Message-State: AOJu0YxmnxMFU0AVKvCAHCj4H3r/yE/IcsahTRxJ6AaMs6Ay6CdvYdHK BcaLIn5JHXEBfD5YdZrV6DzmYrxqTF9QMRQz5dvXF40nl2dd6pXFt6N763XeUPhTyooduOWiwCA E X-Received: by 2002:a05:6a20:f39c:b0:1a9:ffa0:d007 with SMTP id adf61e73a8af0-1b2b71c805bmr3812989637.58.1717622134556; Wed, 05 Jun 2024 14:15:34 -0700 (PDT) Received: from stoup.. ([71.212.132.216]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70242aec7d0sm9347538b3a.99.2024.06.05.14.15.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 14:15:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier Subject: [PULL 13/16] disas/microblaze: Print immediates directly with PRIimm Date: Wed, 5 Jun 2024 14:15:18 -0700 Message-Id: <20240605211521.577094-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605211521.577094-1-richard.henderson@linaro.org> References: <20240605211521.577094-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::429; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x429.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, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Use a printf format instead of sprintf into a buffer. Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier Message-Id: <20240412073346.458116-19-richard.henderson@linaro.org> --- disas/microblaze.c | 61 +++++++++------------------------------------- 1 file changed, 11 insertions(+), 50 deletions(-) diff --git a/disas/microblaze.c b/disas/microblaze.c index c12968f3b9..390f98c0a3 100644 --- a/disas/microblaze.c +++ b/disas/microblaze.c @@ -580,40 +580,21 @@ static const char pvr_register_prefix[] = "rpvr"; #include "disas/dis-asm.h" #define PRIreg register_prefix "%ld" +#define PRIimm "%d" #define get_field_rd(instr) ((instr & RD_MASK) >> RD_LOW) #define get_field_r1(instr) ((instr & RA_MASK) >> RA_LOW) #define get_field_r2(instr) ((instr & RB_MASK) >> RB_LOW) +#define get_field_imm(instr) ((int16_t)instr) +#define get_field_imm5(instr) ((int)instr & IMM5_MASK) +#define get_field_imm15(instr) ((int)instr & IMM15_MASK) + #define get_int_field_imm(instr) ((instr & IMM_MASK) >> IMM_LOW) #define get_int_field_r1(instr) ((instr & RA_MASK) >> RA_LOW) /* Local function prototypes. */ -static char * get_field_imm (long instr); -static char * get_field_imm5 (long instr); static char * get_field_rfsl (long instr); -static char * get_field_imm15 (long instr); -#if 0 -static char * get_field_unsigned_imm (long instr); -#endif - -static char * -get_field_imm (long instr) -{ - char tmpstr[25]; - snprintf(tmpstr, sizeof(tmpstr), "%d", - (short)((instr & IMM_MASK) >> IMM_LOW)); - return(strdup(tmpstr)); -} - -static char * -get_field_imm5 (long instr) -{ - char tmpstr[25]; - snprintf(tmpstr, sizeof(tmpstr), "%d", - (short)((instr & IMM5_MASK) >> IMM_LOW)); - return(strdup(tmpstr)); -} static char * get_field_rfsl (long instr) @@ -624,26 +605,6 @@ get_field_rfsl (long instr) return(strdup(tmpstr)); } -static char * -get_field_imm15 (long instr) -{ - char tmpstr[25]; - snprintf(tmpstr, sizeof(tmpstr), "%d", - (short)((instr & IMM15_MASK) >> IMM_LOW)); - return(strdup(tmpstr)); -} - -#if 0 -static char * -get_field_unsigned_imm (long instr) -{ - char tmpstr[25]; - snprintf(tmpstr, sizeof(tmpstr), "%d", - (int)((instr & IMM_MASK) >> IMM_LOW)); - return(strdup(tmpstr)); -} -#endif - /* char * get_field_special (instr) @@ -829,7 +790,7 @@ print_insn_microblaze(bfd_vma memaddr, struct disassemble_info *info) get_field_r2(inst)); break; case INST_TYPE_RD_R1_IMM: - fprintf_func(stream, "%s\t" PRIreg ", " PRIreg ", %s", + fprintf_func(stream, "%s\t" PRIreg ", " PRIreg ", " PRIimm, op->name, get_field_rd(inst), get_field_r1(inst), get_field_imm(inst)); if (get_int_field_r1(inst) == 0) { @@ -837,7 +798,7 @@ print_insn_microblaze(bfd_vma memaddr, struct disassemble_info *info) } break; case INST_TYPE_RD_R1_IMM5: - fprintf_func(stream, "%s\t" PRIreg ", " PRIreg ", %s", + fprintf_func(stream, "%s\t" PRIreg ", " PRIreg ", " PRIimm, op->name, get_field_rd(inst), get_field_r1(inst), get_field_imm5(inst)); break; @@ -866,7 +827,7 @@ print_insn_microblaze(bfd_vma memaddr, struct disassemble_info *info) op->name, get_field_r1(inst), get_field_r2(inst)); break; case INST_TYPE_R1_IMM: - fprintf_func(stream, "%s\t" PRIreg ", %s", + fprintf_func(stream, "%s\t" PRIreg ", " PRIimm, op->name, get_field_r1(inst), get_field_imm(inst)); /* * The non-pc relative instructions are returns, @@ -877,14 +838,14 @@ print_insn_microblaze(bfd_vma memaddr, struct disassemble_info *info) } break; case INST_TYPE_RD_IMM: - fprintf_func(stream, "%s\t" PRIreg ", %s", + fprintf_func(stream, "%s\t" PRIreg ", " PRIimm, op->name, get_field_rd(inst), get_field_imm(inst)); print_immval_addr(info, immfound, immval, inst, op->inst_offset_type == INST_PC_OFFSET ? memaddr : 0); break; case INST_TYPE_IMM: - fprintf_func(stream, "%s\t%s", + fprintf_func(stream, "%s\t" PRIimm, op->name, get_field_imm(inst)); if (op->instr != imm) { print_immval_addr(info, immfound, immval, inst, @@ -909,7 +870,7 @@ print_insn_microblaze(bfd_vma memaddr, struct disassemble_info *info) op->name, get_field_rd(inst), get_field_r2(inst)); break; case INST_TYPE_RD_IMM15: - fprintf_func(stream, "%s\t" PRIreg ", %s", + fprintf_func(stream, "%s\t" PRIreg ", " PRIimm, op->name, get_field_rd(inst), get_field_imm15(inst)); break; /* For tuqula instruction */ From patchwork Wed Jun 5 21:15:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 801646 Delivered-To: patch@linaro.org Received: by 2002:a5d:5610:0:b0:35b:5a80:51b4 with SMTP id l16csp37232wrv; Wed, 5 Jun 2024 14:18:56 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWw2hx131+q9Oy6A5/IPwBL/bpcJ+q1/WBUPig0sowv4D0+3qO454bCpH1OJt93Ww+5PJwnxwNBY6yMN9LuX868 X-Google-Smtp-Source: AGHT+IEr9F8ObJBzgVbuub1fesWrCj4amn4xgl7ZKosaKsQAQkSKO4Xldhk4KgenxRrLs2N78DUl X-Received: by 2002:aca:1712:0:b0:3c9:6c32:b1ec with SMTP id 5614622812f47-3d2043dc3a0mr3831426b6e.56.1717622335765; Wed, 05 Jun 2024 14:18:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717622335; cv=none; d=google.com; s=arc-20160816; b=rJqiKc9HWhCG2xeXof0RcEIDhfr69VML0SYaKxfW0uM9ChwBRDQ6ok0O1l6m41W9rm 8wgkMQXEWm0sMXsfmJQ3ZW9oV1MsAOtbobuafokG70qZsgmKiSivxdk+Xe/xGd3Po6KR YpQXj3Zvj+ZRnKzHiUby/Uch9okvBlMkWtCmN2j2RTHcy9PMKLHqbjVZN4U3NEiCenN2 M3twX/V8lB96tK4DzfkzZKpw8kdbfaDDTETWGXrfuaCtgH4V3LiW9BLOU+Wc+UY5vRGp EXKRbNfYPjCUtn8yoV9HSjONMG65+f7JeNdeJoKlVdy1PvgR8XM4gpa3jzRIYQ1Mnu5x gaHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=9ILfcAsPqRhnr4sSxUgoQKpIDcJ0mZe41RgVmdO69OU=; fh=vm85eyWrvOAHduw3sqEA+cYBqvHB7M0MHFcRJg7VWOo=; b=uwD9K7zg4S3cWnFbvMgxEtH9uW43DohcUyl/7f/2rs8HVtyhUDMDG+ojy5B0mP525r LL8DrKDVO37j6I/Z7PusJ57yC7wdES7Fl55EJgksW6saugGCGSEr7Rwp56wk4syGoAMZ umoIuBixbJyXkt6FD9hvZqEIGBDFYFnkMfCnl5o47JVx3eIYmALsye9x0tOey7RmdN6i SXH36e+vMHla32xea8Xqsb1jE0V2+odPejG5IVOCk8gNB0RSEyOU2IzWUWk7ONSS7d42 C7RVR9+FZvkbl6X2LXEE69xFeUDnjuU+/kJh9PxA7vX7oKyPqPP8+uHjoTcGSKjm9kDd +dkw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AaOZDN0y; 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 af79cd13be357-794f4d91d24si1483611085a.193.2024.06.05.14.18.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jun 2024 14:18:55 -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=AaOZDN0y; 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 1sExz6-0000gj-84; Wed, 05 Jun 2024 17:15:52 -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 1sExz0-0000ef-Jo for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:47 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sExys-0003RX-TW for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:46 -0400 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-702508bf0a9so216624b3a.0 for ; Wed, 05 Jun 2024 14:15:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717622135; x=1718226935; darn=nongnu.org; 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=9ILfcAsPqRhnr4sSxUgoQKpIDcJ0mZe41RgVmdO69OU=; b=AaOZDN0yCNLi5u/+tRV8i+SsIbW47qvnsEqfvrN+5wHqzabQQMp4a4EJ8DpSycvVVt tXfSIUraUvaXy6jcUFR2xEhtksukQhMkYdZGiAN2mkssdqoXFOdSUTnZMusHMfmZEsAP +AokTYImaTFoA08Zv8Wtm/Gm2hxLamS54sQXMJSEcNKyE0kJ4i837aV0iYnkcUcRzSxp c0zb/lGYyl/oMb84I/kSSxckue3KU7lRq6aoAYTbuon30ln/nYC0HBU0tcFTD70YsRb5 ze3tzI3BSJzrQg/mzbBZXzReqNRJYSRB9YCQSp+jRl9UilqkSWsA5LYYk/eNHFTi+pX5 paCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717622135; x=1718226935; 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=9ILfcAsPqRhnr4sSxUgoQKpIDcJ0mZe41RgVmdO69OU=; b=MkuGYElfx3JiV/oiEsYlKYDfUwIzYIOwGRVlaNZjL4VuvjLjKAMyOL6PlgJ1FtKWlc gZoHQcbqxJ7dJ+CURPiidvtEEfhFpP1e3A85hdceUySNguMR83oQ4lVKYqvyBWbOnxqW kjfiTgYbXzO8PX+3UXBlpNqNtao3KgLA0FRDwNts/NykL7By50z652ZwN6vLB7IyjJQL mt830XpSt1SPQtnnOSQ4njF2qXRgUIZKguE+xWyb1vt8GF5IOjoP1wl3j3pV2Hd5yjjb /JJ5E/ZzN79rNYmg6LCBAJSYiFQK0u+ryIP5J+4NOcDyrEV/Zao5Kq/pYKn8WMAgZF5h kM2w== X-Gm-Message-State: AOJu0YwCo+O2E1/DRZtYrvREHarzjbYbisio2VJ0qwbabSaN7BaKJBsY XxOZjBLAV7ToDO/3dfq0GtVgvz2OTBcLsLP7pVcXGvpvmALiwFfAbShITQHDPegAcBBMPECsaPv L X-Received: by 2002:a05:6a00:99d:b0:6f3:ecdc:220e with SMTP id d2e1a72fcca58-703e5a249e0mr4497949b3a.24.1717622135494; Wed, 05 Jun 2024 14:15:35 -0700 (PDT) Received: from stoup.. ([71.212.132.216]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70242aec7d0sm9347538b3a.99.2024.06.05.14.15.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 14:15:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier Subject: [PULL 14/16] disas/microblaze: Print registers directly with PRIrfsl Date: Wed, 5 Jun 2024 14:15:19 -0700 Message-Id: <20240605211521.577094-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605211521.577094-1-richard.henderson@linaro.org> References: <20240605211521.577094-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42d.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, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Use a printf format instead of sprintf into a buffer. Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier Message-Id: <20240412073346.458116-20-richard.henderson@linaro.org> --- disas/microblaze.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/disas/microblaze.c b/disas/microblaze.c index 390f98c0a3..24febfdea9 100644 --- a/disas/microblaze.c +++ b/disas/microblaze.c @@ -564,7 +564,6 @@ static const struct op_code_struct { /* prefix for register names */ #define register_prefix "r" -static const char fsl_register_prefix[] = "rfsl"; static const char pvr_register_prefix[] = "rpvr"; @@ -580,11 +579,13 @@ static const char pvr_register_prefix[] = "rpvr"; #include "disas/dis-asm.h" #define PRIreg register_prefix "%ld" +#define PRIrfsl register_prefix "fsl%ld" #define PRIimm "%d" #define get_field_rd(instr) ((instr & RD_MASK) >> RD_LOW) #define get_field_r1(instr) ((instr & RA_MASK) >> RA_LOW) #define get_field_r2(instr) ((instr & RB_MASK) >> RB_LOW) +#define get_field_rfsl(instr) (instr & RFSL_MASK) #define get_field_imm(instr) ((int16_t)instr) #define get_field_imm5(instr) ((int)instr & IMM5_MASK) #define get_field_imm15(instr) ((int)instr & IMM15_MASK) @@ -592,19 +593,6 @@ static const char pvr_register_prefix[] = "rpvr"; #define get_int_field_imm(instr) ((instr & IMM_MASK) >> IMM_LOW) #define get_int_field_r1(instr) ((instr & RA_MASK) >> RA_LOW) -/* Local function prototypes. */ - -static char * get_field_rfsl (long instr); - -static char * -get_field_rfsl (long instr) -{ - char tmpstr[25]; - snprintf(tmpstr, sizeof(tmpstr), "%s%d", fsl_register_prefix, - (short)((instr & RFSL_MASK) >> IMM_LOW)); - return(strdup(tmpstr)); -} - /* char * get_field_special (instr) @@ -803,11 +791,11 @@ print_insn_microblaze(bfd_vma memaddr, struct disassemble_info *info) get_field_imm5(inst)); break; case INST_TYPE_RD_RFSL: - fprintf_func(stream, "%s\t" PRIreg ", %s", + fprintf_func(stream, "%s\t" PRIreg ", " PRIrfsl, op->name, get_field_rd(inst), get_field_rfsl(inst)); break; case INST_TYPE_R1_RFSL: - fprintf_func(stream, "%s\t" PRIreg ", %s", + fprintf_func(stream, "%s\t" PRIreg ", " PRIrfsl, op->name, get_field_r1(inst), get_field_rfsl(inst)); break; case INST_TYPE_RD_SPECIAL: @@ -879,7 +867,7 @@ print_insn_microblaze(bfd_vma memaddr, struct disassemble_info *info) op->name, get_field_rd(inst)); break; case INST_TYPE_RFSL: - fprintf_func(stream, "%s\t%s", + fprintf_func(stream, "%s\t" PRIrfsl, op->name, get_field_rfsl(inst)); break; default: From patchwork Wed Jun 5 21:15:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 801643 Delivered-To: patch@linaro.org Received: by 2002:a5d:5610:0:b0:35b:5a80:51b4 with SMTP id l16csp36805wrv; Wed, 5 Jun 2024 14:17:36 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVPPGU2uFON48kxI4p3CsDdi23f7GD4C8+ekEtXYbabD/tV3GveA1bQyMdaktWm8nuL4Y+z4lm/hoxJyZ6lyOSP X-Google-Smtp-Source: AGHT+IGqfP+QjlZFtE2sr1p200w1+N6vZtOZfVL0+rCa/vtjbRNQ4dsUgy7JqX+H80mseiKrLxgC X-Received: by 2002:a05:6870:8995:b0:22a:5ffd:5e40 with SMTP id 586e51a60fabf-251220ffb84mr4214295fac.59.1717622256163; Wed, 05 Jun 2024 14:17:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717622256; cv=none; d=google.com; s=arc-20160816; b=hanV4ASusTV3+8+yGCA7poGrU2fwC4NsXokkJZRTEXDVOJN2Nsh+9uPaZ65x6Q//zJ 3KbdEpTt/ZxZNOxZ5Xti9tfvwZA0itPZe4pYg3tnKlMb9jT2qmbz/sPpn8l9/d7/0889 eXgUIJumDHMURZ7pyNdSvQrhRKq+AO8cvq4DR4Mw41MD+xX1PRLkDT8YJj20MxCQUwqu cS45WQcOTHpNTM3wIK9iAdwFnvJWW7Y7TvdOzrqf01XoJx+yoQgCkm8sRmBIBrnG3ric Hlpi3mPd/fLTx6fGaMCerEoRKhHCF2OGk1QxU/PgopnllJx5YD8S/5Sgn5ei87OCtlii EBJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=Chtdl64sSN7t9wuikeNXRUJv7hjmKkzPpF45qIUWzPg=; fh=vm85eyWrvOAHduw3sqEA+cYBqvHB7M0MHFcRJg7VWOo=; b=SU2vRD6lb5QNS6mT84fBBW06TRBXQU62xegUiSuxFtLOn/PZMmCqjR7vWTPX5UsZit H4Xn7+0byetg1lWdAZDFOKnjWdf3hSKNkPCQxx3rzxl9lDb/sxMCsrIYrDa7oNBzEgJk A93waZD2qPWM1slIa7giGu28cQ6Fh2+cbPd+8rZL1qtIvY8qrjYu1Lw3SR5w+LuTjL1p 3Zcvvvx++unmeP/Eky+FFhDF3/PS32qvAnMG3zaVw46E2NZU/4NRHCKK/J8URqXzzpoW lLaWPxPekXEpUOK0MjS1gmGg9+BHMkSGk/VJoKucS0PxRuo2KqnLLvwmQzgsE/lvokYn lYXQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="UvnZ7sm/"; 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 af79cd13be357-795304afe38si25591185a.533.2024.06.05.14.17.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jun 2024 14:17:36 -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="UvnZ7sm/"; 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 1sExzC-0000jD-3Z; Wed, 05 Jun 2024 17:15:58 -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 1sExz2-0000fw-VE for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:48 -0400 Received: from mail-pf1-x431.google.com ([2607:f8b0:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sExys-0003Rh-Th for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:48 -0400 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-703ed5d37acso209639b3a.0 for ; Wed, 05 Jun 2024 14:15:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717622136; x=1718226936; darn=nongnu.org; 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=Chtdl64sSN7t9wuikeNXRUJv7hjmKkzPpF45qIUWzPg=; b=UvnZ7sm//ZBM+OB38VIHn88VIEujWtVEM+OZpQmDdnA1KkTXyx4KAEEbz4ZQsHNCth eDOwSPcc90f0cZ4uqo02tAiiSwxDTuBmpoBMnoU0RWr85/ji1iJCsPGAZEsoUquTd7Kd Bxxw6mHvMCsqhVTUsbg4BnitaPtiPWGg7uVdqWsEKaxGif0j7Vnnsnw5sijz7VMVoDrU iLDNYscu39rZp6kOSSrY4S0DQAB8sF7UNtvLvMJc4mN465foarfkXgTxoNEdHIjzfjZk To2sYJcW9uRNsZuyAjewVjIVeb48hnY/TlyIsjXIGxv1OPgSZuPBQfPFwd7D32ik03xL 5N2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717622136; x=1718226936; 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=Chtdl64sSN7t9wuikeNXRUJv7hjmKkzPpF45qIUWzPg=; b=ZppCoa3O41TyDcFrjoGB46pQcZqfijP1WEb2nt0WWNAG8L9Z7oQ302GXNfXyOl/uL8 1SMS996gUw/p8GAhNamidJTgYI93ypf1ekcHy0kBFaePM/E2QIqZp7nbng9mGjRunNIe I8MhEkWW5MHXx44UCcFeILInYWYt0MCH7anshtbkFq94HU1z85QrmhyxB+h1TmZXWixV +uDxl9DY+elEIOXeNGMvSf9M1QULw2zfy0Ri6DELckM2J/IOu63aSvDGD5RM4smfxWMq 1U+Yj+mW8NHIqkNGXcDgzl0P0d2Gkju9QGmJKpEqAx4w0hekEibrAqSpzBj+x5iXJfgP u7pQ== X-Gm-Message-State: AOJu0YxWMyx+bc047QY+jrO8HxsOwzNPwG8yKzV29K2LjFDXF40x179K NS0Z2gJpzulntQbQIdiRJ+gt3BOT5TgMHuaCYi5tPhIXN/9S4yy8W3IXbYA1GikikxIx+llGLkX H X-Received: by 2002:a05:6a00:330e:b0:702:6dc7:2368 with SMTP id d2e1a72fcca58-703e59b05fdmr3970041b3a.12.1717622136356; Wed, 05 Jun 2024 14:15:36 -0700 (PDT) Received: from stoup.. ([71.212.132.216]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70242aec7d0sm9347538b3a.99.2024.06.05.14.15.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 14:15:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Pierrick Bouvier Subject: [PULL 15/16] disas/microblaze: Split get_field_special Date: Wed, 5 Jun 2024 14:15:20 -0700 Message-Id: <20240605211521.577094-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605211521.577094-1-richard.henderson@linaro.org> References: <20240605211521.577094-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::431; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x431.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, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Extract the raw special index and a function to lookup a name. Signed-off-by: Richard Henderson Reviewed-by: Pierrick Bouvier Message-Id: <20240412073346.458116-21-richard.henderson@linaro.org> --- disas/microblaze.c | 142 +++++++++++++++++++-------------------------- 1 file changed, 61 insertions(+), 81 deletions(-) diff --git a/disas/microblaze.c b/disas/microblaze.c index 24febfdea9..197327fae4 100644 --- a/disas/microblaze.c +++ b/disas/microblaze.c @@ -564,8 +564,6 @@ static const struct op_code_struct { /* prefix for register names */ #define register_prefix "r" -static const char pvr_register_prefix[] = "rpvr"; - /* #defines for valid immediate range */ #define MIN_IMM ((int) 0x80000000) @@ -580,6 +578,7 @@ static const char pvr_register_prefix[] = "rpvr"; #define PRIreg register_prefix "%ld" #define PRIrfsl register_prefix "fsl%ld" +#define PRIpvr register_prefix "pvr%d" #define PRIimm "%d" #define get_field_rd(instr) ((instr & RD_MASK) >> RD_LOW) @@ -593,83 +592,48 @@ static const char pvr_register_prefix[] = "rpvr"; #define get_int_field_imm(instr) ((instr & IMM_MASK) >> IMM_LOW) #define get_int_field_r1(instr) ((instr & RA_MASK) >> RA_LOW) -/* - char * - get_field_special (instr) - long instr; - { - char tmpstr[25]; - - snprintf(tmpstr, sizeof(tmpstr), "%s%s", register_prefix, - (((instr & IMM_MASK) >> IMM_LOW) & REG_MSR_MASK) == 0 ? "pc" : "msr"); - - return(strdup(tmpstr)); - } -*/ - -static char * -get_field_special(long instr, const struct op_code_struct *op) +static int get_field_special(long instr, const struct op_code_struct *op) { - char tmpstr[25]; - char spr[6]; + return ((instr & IMM_MASK) >> IMM_LOW) ^ op->immval_mask; +} - switch ( (((instr & IMM_MASK) >> IMM_LOW) ^ op->immval_mask) ) { - - case REG_MSR_MASK : - strcpy(spr, "msr"); - break; - case REG_PC_MASK : - strcpy(spr, "pc"); - break; - case REG_EAR_MASK : - strcpy(spr, "ear"); - break; - case REG_ESR_MASK : - strcpy(spr, "esr"); - break; - case REG_FSR_MASK : - strcpy(spr, "fsr"); - break; - case REG_BTR_MASK : - strcpy(spr, "btr"); - break; - case REG_EDR_MASK : - strcpy(spr, "edr"); - break; - case REG_PID_MASK : - strcpy(spr, "pid"); - break; - case REG_ZPR_MASK : - strcpy(spr, "zpr"); - break; - case REG_TLBX_MASK : - strcpy(spr, "tlbx"); - break; - case REG_TLBLO_MASK : - strcpy(spr, "tlblo"); - break; - case REG_TLBHI_MASK : - strcpy(spr, "tlbhi"); - break; - case REG_TLBSX_MASK : - strcpy(spr, "tlbsx"); - break; - default : - { - if ( ((((instr & IMM_MASK) >> IMM_LOW) ^ op->immval_mask) & 0xE000) == REG_PVR_MASK) { - snprintf(tmpstr, sizeof(tmpstr), "%s%u", pvr_register_prefix, - (unsigned short)(((instr & IMM_MASK) >> IMM_LOW) ^ - op->immval_mask) ^ REG_PVR_MASK); - return(strdup(tmpstr)); - } else { - strcpy(spr, "pc"); - } - } - break; - } - - snprintf(tmpstr, sizeof(tmpstr), "%s%s", register_prefix, spr); - return(strdup(tmpstr)); +/* Returns NULL for PVR registers, which should be rendered differently. */ +static const char *get_special_name(int special) +{ + switch (special) { + case REG_MSR_MASK: + return register_prefix "msr"; + case REG_PC_MASK: + return register_prefix "pc"; + case REG_EAR_MASK: + return register_prefix "ear"; + case REG_ESR_MASK: + return register_prefix "esr"; + case REG_FSR_MASK: + return register_prefix "fsr"; + case REG_BTR_MASK: + return register_prefix "btr"; + case REG_EDR_MASK: + return register_prefix "edr"; + case REG_PID_MASK: + return register_prefix "pid"; + case REG_ZPR_MASK: + return register_prefix "zpr"; + case REG_TLBX_MASK: + return register_prefix "tlbx"; + case REG_TLBLO_MASK: + return register_prefix "tlblo"; + case REG_TLBHI_MASK: + return register_prefix "tlbhi"; + case REG_TLBSX_MASK: + return register_prefix "tlbsx"; + default: + if ((special & 0xE000) == REG_PVR_MASK) { + /* pvr register */ + return NULL; + } + return register_prefix "pc"; + } } static unsigned long @@ -739,6 +703,8 @@ print_insn_microblaze(bfd_vma memaddr, struct disassemble_info *info) static bfd_vma prev_insn_addr = -1; /*init the prev insn addr */ static int prev_insn_vma = -1; /*init the prev insn vma */ int curr_insn_vma = info->buffer_vma; + int special; + const char *special_name; info->bytes_per_chunk = 4; @@ -799,12 +765,26 @@ print_insn_microblaze(bfd_vma memaddr, struct disassemble_info *info) op->name, get_field_r1(inst), get_field_rfsl(inst)); break; case INST_TYPE_RD_SPECIAL: - fprintf_func(stream, "%s\t" PRIreg ", %s", - op->name, get_field_rd(inst), get_field_special(inst, op)); + special = get_field_special(inst, op); + special_name = get_special_name(special); + if (special_name) { + fprintf_func(stream, "%s\t" PRIreg ", %s", + op->name, get_field_rd(inst), special_name); + } else { + fprintf_func(stream, "%s\t" PRIreg ", " PRIpvr, + op->name, get_field_rd(inst), special ^ REG_PVR_MASK); + } break; case INST_TYPE_SPECIAL_R1: - fprintf_func(stream, "%s\t%s, " PRIreg, - op->name, get_field_special(inst, op), get_field_r1(inst)); + special = get_field_special(inst, op); + special_name = get_special_name(special); + if (special_name) { + fprintf_func(stream, "%s\t%s, " PRIreg, + op->name, special_name, get_field_r1(inst)); + } else { + fprintf_func(stream, "%s\t" PRIpvr ", " PRIreg, + op->name, special ^ REG_PVR_MASK, get_field_r1(inst)); + } break; case INST_TYPE_RD_R1: fprintf_func(stream, "%s\t" PRIreg ", " PRIreg, From patchwork Wed Jun 5 21:15:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 801644 Delivered-To: patch@linaro.org Received: by 2002:a5d:5610:0:b0:35b:5a80:51b4 with SMTP id l16csp36969wrv; Wed, 5 Jun 2024 14:18:07 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVQrVJJcKhS7VwhhJRruhclRfI7qxc9aliFCI+i32rP03kXMqzFlnDhGR5WD9DLlQYdBQruLVLhNguBcHX7n+lR X-Google-Smtp-Source: AGHT+IEDc/+2nQ53Ws33Kntir6zil7awTpO/6/J64AnEnPqOE/FM57gEbzGSjecSmAqFQDsOL7d4 X-Received: by 2002:a05:620a:2ea:b0:795:2891:12df with SMTP id af79cd13be357-79528911570mr254491085a.47.1717622286804; Wed, 05 Jun 2024 14:18:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717622286; cv=none; d=google.com; s=arc-20160816; b=W4fsErBEkiwSeDVfSYWG8oASPJfOETljKFJ4tfC0wBwITYOT/c8LJaifw/aY6G49jg vYGSzDTiyC0XU9T9PJ8YLotdRJMZ390Zp6KuNRingg7DTWf3SV8902L+gs5Un021KtXc bpX43a6HJ/FDMoEW8pwOMeDyfYJq78Z7HyllIW2V516liO294jfCbhhh7WbxBoBQy0Y1 LQsu/eMWK9w42kzege+TNkzntxV9HxdLERxP4jBQ+nENOVpDaGU7E/0xdy3zr0cQMcOL Plb6sh4FiofYwApngIhGXAXHEqopaMCpu/RS+8Qw+7i+wdXPwqOXFnPTswaFNeVrG6oY Rw6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=NRnvBT7dCcRQW46yZ2cILgjEvSH0UMGtXyMJE1zUYf4=; fh=NRbVEM4N+WnQUFmJW8uGobWq0XkOiK4QdifPqAAMoww=; b=VD3Pck/u0MAL/ZuSx0lij/isUTmgNyafB1DdOx9q01ZHvVxrP/lMzEjnXMu4K/KVQ5 GYtjxX4LD44CFG+nDgTrx2YpX/HXIBCRKDvjfxRi95tCnxmtK4a4nGyOg6vgtX+OjXGD 6DdzMOlk9E6GFqg7e0u55H9BuWjRHu0LwhRshuvDUN87DRHwefgZKJWv/++/N9m5hH+L j8M5naxZokfBY5DLT1/aLVgN32Rn9qgIU0kWWpTwdCyn371qwr7b5lVomWq3LzCfolgW 0ug7FfGwwqYYg9PCfe+K2magnl+MVG5rbR42BaWsjuf1gO7tndP9YEIzTMMZ8bOAFHQk qOCw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S9kKFkx2; 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 af79cd13be357-794f2f177easi1387383485a.169.2024.06.05.14.18.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 05 Jun 2024 14:18:06 -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=S9kKFkx2; 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 1sExzD-0000jn-MN; Wed, 05 Jun 2024 17:15:59 -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 1sExz2-0000fr-J3 for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:48 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sExyt-0003Rz-1g for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:48 -0400 Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-6f6a045d476so195668b3a.1 for ; Wed, 05 Jun 2024 14:15:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717622137; x=1718226937; darn=nongnu.org; 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=NRnvBT7dCcRQW46yZ2cILgjEvSH0UMGtXyMJE1zUYf4=; b=S9kKFkx20O5iBGODTxQSGVUjSxOWAZreFkd8sJdIMwY7SovB/JQw5x1bLKaX3b43Sj DK9cOVLC8xTDyIFt8KD7ebFxyEBAKDtjbxaq5NLrdeNoW3zOxFR3YErXHFP4SwCmzZVG YYfEwHfeNAmgUKKucG5q7NaJL0DCP+C7oYtaB19Q3OXBKCcLOPMp50SdpSeFPOBhE+0n 7+zGk6kNZATq3GEX+kT5V+Kdm4JGDHyplnXd4PSxkMLlhS34RnF9NCUPj2V/tDhHpT6K W3nbXeL21JJOV7PEmiqzTxd4FUQXhCTzhBd4GnUTXSeBH0vCPZUInQzj8ZD+WIsdepKg y2KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717622137; x=1718226937; 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=NRnvBT7dCcRQW46yZ2cILgjEvSH0UMGtXyMJE1zUYf4=; b=qibHiHPtGzikPLpuLfveMWnE84uvvzmfKP2LLbL+Y0lYX7nA+4wonN/Ela497ebcvt YFT170tv5iqM5lz+N1CFtkntu+BKiGb7sI6fl5uwNC2elJoTOPId6T57Uuf8Qgmm+ZYg rQSbYLkNTpBH+RRFwn0AWAIpohM4PvExkzqpx/mWINqLETMNtFb28aonxZNMUbDlCN8R ahuqTtlyv0Zdq/F5Qt9p5vzAl1yVZaMOaTCHgqmUqX185tuOPlKd1Cy6VhFcHzQqWF9V 8GdeYixwF37VK1EGKEdAv1MopwFoJRpnRkd5GG0W+9XDZS0uex0fNaBZpb2WBXol9L0w quxQ== X-Gm-Message-State: AOJu0YyYCcQ8aJsjyBERGd7w4XJuOtkJfWaYiMpMuohA5Hk274Hk0ZsH zUTHoDei2SwKWthUHaKG9shOj1VaQ2eRnPhtAoQ8fSTnzM5762P9La9v4Mhh66t/P9K0gK55efj M X-Received: by 2002:a05:6a20:2593:b0:1a3:8e1d:16b8 with SMTP id adf61e73a8af0-1b2b6ffee37mr4401487637.28.1717622137280; Wed, 05 Jun 2024 14:15:37 -0700 (PDT) Received: from stoup.. ([71.212.132.216]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70242aec7d0sm9347538b3a.99.2024.06.05.14.15.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 14:15:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Alistair Francis , Pierrick Bouvier Subject: [PULL 16/16] disas/riscv: Use GString in format_inst Date: Wed, 5 Jun 2024 14:15:21 -0700 Message-Id: <20240605211521.577094-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605211521.577094-1-richard.henderson@linaro.org> References: <20240605211521.577094-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x432.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, T_SCC_BODY_TEXT_LINE=-0.01 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Allocate and fill a GString instead of snprintf and appending to a fixed sized buffer. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis Reviewed-by: Pierrick Bouvier Message-Id: <20240412073346.458116-22-richard.henderson@linaro.org> --- disas/riscv.c | 209 ++++++++++++++++++++++---------------------------- 1 file changed, 92 insertions(+), 117 deletions(-) diff --git a/disas/riscv.c b/disas/riscv.c index 297cfa2f63..90d6b26de9 100644 --- a/disas/riscv.c +++ b/disas/riscv.c @@ -4820,272 +4820,249 @@ static size_t inst_length(rv_inst inst) /* format instruction */ -static void append(char *s1, const char *s2, size_t n) -{ - size_t l1 = strlen(s1); - if (n - l1 - 1 > 0) { - strncat(s1, s2, n - l1); - } -} - -static void format_inst(char *buf, size_t buflen, size_t tab, rv_decode *dec) +static GString *format_inst(size_t tab, rv_decode *dec) { const rv_opcode_data *opcode_data = dec->opcode_data; - char tmp[64]; + GString *buf = g_string_sized_new(64); const char *fmt; fmt = opcode_data[dec->op].format; while (*fmt) { switch (*fmt) { case 'O': - append(buf, opcode_data[dec->op].name, buflen); + g_string_append(buf, opcode_data[dec->op].name); break; case '(': - append(buf, "(", buflen); - break; case ',': - append(buf, ",", buflen); - break; case ')': - append(buf, ")", buflen); - break; case '-': - append(buf, "-", buflen); + g_string_append_c(buf, *fmt); break; case 'b': - snprintf(tmp, sizeof(tmp), "%d", dec->bs); - append(buf, tmp, buflen); + g_string_append_printf(buf, "%d", dec->bs); break; case 'n': - snprintf(tmp, sizeof(tmp), "%d", dec->rnum); - append(buf, tmp, buflen); + g_string_append_printf(buf, "%d", dec->rnum); break; case '0': - append(buf, rv_ireg_name_sym[dec->rd], buflen); + g_string_append(buf, rv_ireg_name_sym[dec->rd]); break; case '1': - append(buf, rv_ireg_name_sym[dec->rs1], buflen); + g_string_append(buf, rv_ireg_name_sym[dec->rs1]); break; case '2': - append(buf, rv_ireg_name_sym[dec->rs2], buflen); + g_string_append(buf, rv_ireg_name_sym[dec->rs2]); break; case '3': - append(buf, dec->cfg->ext_zfinx ? rv_ireg_name_sym[dec->rd] : - rv_freg_name_sym[dec->rd], - buflen); + if (dec->cfg->ext_zfinx) { + g_string_append(buf, rv_ireg_name_sym[dec->rd]); + } else { + g_string_append(buf, rv_freg_name_sym[dec->rd]); + } break; case '4': - append(buf, dec->cfg->ext_zfinx ? rv_ireg_name_sym[dec->rs1] : - rv_freg_name_sym[dec->rs1], - buflen); + if (dec->cfg->ext_zfinx) { + g_string_append(buf, rv_ireg_name_sym[dec->rs1]); + } else { + g_string_append(buf, rv_freg_name_sym[dec->rs1]); + } break; case '5': - append(buf, dec->cfg->ext_zfinx ? rv_ireg_name_sym[dec->rs2] : - rv_freg_name_sym[dec->rs2], - buflen); + if (dec->cfg->ext_zfinx) { + g_string_append(buf, rv_ireg_name_sym[dec->rs2]); + } else { + g_string_append(buf, rv_freg_name_sym[dec->rs2]); + } break; case '6': - append(buf, dec->cfg->ext_zfinx ? rv_ireg_name_sym[dec->rs3] : - rv_freg_name_sym[dec->rs3], - buflen); + if (dec->cfg->ext_zfinx) { + g_string_append(buf, rv_ireg_name_sym[dec->rs3]); + } else { + g_string_append(buf, rv_freg_name_sym[dec->rs3]); + } break; case '7': - snprintf(tmp, sizeof(tmp), "%d", dec->rs1); - append(buf, tmp, buflen); + g_string_append_printf(buf, "%d", dec->rs1); break; case 'i': - snprintf(tmp, sizeof(tmp), "%d", dec->imm); - append(buf, tmp, buflen); + g_string_append_printf(buf, "%d", dec->imm); break; case 'u': - snprintf(tmp, sizeof(tmp), "%u", ((uint32_t)dec->imm & 0b111111)); - append(buf, tmp, buflen); + g_string_append_printf(buf, "%u", ((uint32_t)dec->imm & 0b111111)); break; case 'j': - snprintf(tmp, sizeof(tmp), "%d", dec->imm1); - append(buf, tmp, buflen); + g_string_append_printf(buf, "%d", dec->imm1); break; case 'o': - snprintf(tmp, sizeof(tmp), "%d", dec->imm); - append(buf, tmp, buflen); - while (strlen(buf) < tab * 2) { - append(buf, " ", buflen); + g_string_append_printf(buf, "%d", dec->imm); + while (buf->len < tab * 2) { + g_string_append_c(buf, ' '); } - snprintf(tmp, sizeof(tmp), "# 0x%" PRIx64, - dec->pc + dec->imm); - append(buf, tmp, buflen); + g_string_append_printf(buf, "# 0x%" PRIx64, dec->pc + dec->imm); break; case 'U': fmt++; - snprintf(tmp, sizeof(tmp), "%d", dec->imm >> 12); - append(buf, tmp, buflen); + g_string_append_printf(buf, "%d", dec->imm >> 12); if (*fmt == 'o') { - while (strlen(buf) < tab * 2) { - append(buf, " ", buflen); + while (buf->len < tab * 2) { + g_string_append_c(buf, ' '); } - snprintf(tmp, sizeof(tmp), "# 0x%" PRIx64, - dec->pc + dec->imm); - append(buf, tmp, buflen); + g_string_append_printf(buf, "# 0x%" PRIx64, dec->pc + dec->imm); } break; case 'c': { const char *name = csr_name(dec->imm & 0xfff); if (name) { - append(buf, name, buflen); + g_string_append(buf, name); } else { - snprintf(tmp, sizeof(tmp), "0x%03x", dec->imm & 0xfff); - append(buf, tmp, buflen); + g_string_append_printf(buf, "0x%03x", dec->imm & 0xfff); } break; } case 'r': switch (dec->rm) { case rv_rm_rne: - append(buf, "rne", buflen); + g_string_append(buf, "rne"); break; case rv_rm_rtz: - append(buf, "rtz", buflen); + g_string_append(buf, "rtz"); break; case rv_rm_rdn: - append(buf, "rdn", buflen); + g_string_append(buf, "rdn"); break; case rv_rm_rup: - append(buf, "rup", buflen); + g_string_append(buf, "rup"); break; case rv_rm_rmm: - append(buf, "rmm", buflen); + g_string_append(buf, "rmm"); break; case rv_rm_dyn: - append(buf, "dyn", buflen); + g_string_append(buf, "dyn"); break; default: - append(buf, "inv", buflen); + g_string_append(buf, "inv"); break; } break; case 'p': if (dec->pred & rv_fence_i) { - append(buf, "i", buflen); + g_string_append_c(buf, 'i'); } if (dec->pred & rv_fence_o) { - append(buf, "o", buflen); + g_string_append_c(buf, 'o'); } if (dec->pred & rv_fence_r) { - append(buf, "r", buflen); + g_string_append_c(buf, 'r'); } if (dec->pred & rv_fence_w) { - append(buf, "w", buflen); + g_string_append_c(buf, 'w'); } break; case 's': if (dec->succ & rv_fence_i) { - append(buf, "i", buflen); + g_string_append_c(buf, 'i'); } if (dec->succ & rv_fence_o) { - append(buf, "o", buflen); + g_string_append_c(buf, 'o'); } if (dec->succ & rv_fence_r) { - append(buf, "r", buflen); + g_string_append_c(buf, 'r'); } if (dec->succ & rv_fence_w) { - append(buf, "w", buflen); + g_string_append_c(buf, 'w'); } break; case '\t': - while (strlen(buf) < tab) { - append(buf, " ", buflen); + while (buf->len < tab) { + g_string_append_c(buf, ' '); } break; case 'A': if (dec->aq) { - append(buf, ".aq", buflen); + g_string_append(buf, ".aq"); } break; case 'R': if (dec->rl) { - append(buf, ".rl", buflen); + g_string_append(buf, ".rl"); } break; case 'l': - append(buf, ",v0", buflen); + g_string_append(buf, ",v0"); break; case 'm': if (dec->vm == 0) { - append(buf, ",v0.t", buflen); + g_string_append(buf, ",v0.t"); } break; case 'D': - append(buf, rv_vreg_name_sym[dec->rd], buflen); + g_string_append(buf, rv_vreg_name_sym[dec->rd]); break; case 'E': - append(buf, rv_vreg_name_sym[dec->rs1], buflen); + g_string_append(buf, rv_vreg_name_sym[dec->rs1]); break; case 'F': - append(buf, rv_vreg_name_sym[dec->rs2], buflen); + g_string_append(buf, rv_vreg_name_sym[dec->rs2]); break; case 'G': - append(buf, rv_vreg_name_sym[dec->rs3], buflen); + g_string_append(buf, rv_vreg_name_sym[dec->rs3]); break; case 'v': { - char nbuf[32] = {0}; const int sew = 1 << (((dec->vzimm >> 3) & 0b111) + 3); - sprintf(nbuf, "%d", sew); const int lmul = dec->vzimm & 0b11; const int flmul = (dec->vzimm >> 2) & 1; const char *vta = (dec->vzimm >> 6) & 1 ? "ta" : "tu"; const char *vma = (dec->vzimm >> 7) & 1 ? "ma" : "mu"; - append(buf, "e", buflen); - append(buf, nbuf, buflen); - append(buf, ",m", buflen); + + g_string_append_printf(buf, "e%d,m", sew); if (flmul) { switch (lmul) { case 3: - sprintf(nbuf, "f2"); + g_string_append(buf, "f2"); break; case 2: - sprintf(nbuf, "f4"); + g_string_append(buf, "f4"); break; case 1: - sprintf(nbuf, "f8"); - break; + g_string_append(buf, "f8"); + break; } - append(buf, nbuf, buflen); } else { - sprintf(nbuf, "%d", 1 << lmul); - append(buf, nbuf, buflen); + g_string_append_printf(buf, "%d", 1 << lmul); } - append(buf, ",", buflen); - append(buf, vta, buflen); - append(buf, ",", buflen); - append(buf, vma, buflen); + g_string_append_c(buf, ','); + g_string_append(buf, vta); + g_string_append_c(buf, ','); + g_string_append(buf, vma); break; } case 'x': { switch (dec->rlist) { case 4: - snprintf(tmp, sizeof(tmp), "{ra}"); + g_string_append(buf, "{ra}"); break; case 5: - snprintf(tmp, sizeof(tmp), "{ra, s0}"); + g_string_append(buf, "{ra, s0}"); break; case 15: - snprintf(tmp, sizeof(tmp), "{ra, s0-s11}"); + g_string_append(buf, "{ra, s0-s11}"); break; default: - snprintf(tmp, sizeof(tmp), "{ra, s0-s%d}", dec->rlist - 5); + g_string_append_printf(buf, "{ra, s0-s%d}", dec->rlist - 5); break; } - append(buf, tmp, buflen); break; } case 'h': - append(buf, rv_fli_name_const[dec->imm], buflen); + g_string_append(buf, rv_fli_name_const[dec->imm]); break; default: break; } fmt++; } + + return buf; } /* lift instruction to pseudo-instruction */ @@ -5171,9 +5148,8 @@ static void decode_inst_decompress(rv_decode *dec, rv_isa isa) /* disassemble instruction */ -static void -disasm_inst(char *buf, size_t buflen, rv_isa isa, uint64_t pc, rv_inst inst, - RISCVCPUConfig *cfg) +static GString *disasm_inst(rv_isa isa, uint64_t pc, rv_inst inst, + RISCVCPUConfig *cfg) { rv_decode dec = { 0 }; dec.pc = pc; @@ -5220,7 +5196,7 @@ disasm_inst(char *buf, size_t buflen, rv_isa isa, uint64_t pc, rv_inst inst, decode_inst_operands(&dec, isa); decode_inst_decompress(&dec, isa); decode_inst_lift_pseudo(&dec); - format_inst(buf, buflen, 24, &dec); + return format_inst(24, &dec); } #define INST_FMT_2 "%04" PRIx64 " " @@ -5231,7 +5207,6 @@ disasm_inst(char *buf, size_t buflen, rv_isa isa, uint64_t pc, rv_inst inst, static int print_insn_riscv(bfd_vma memaddr, struct disassemble_info *info, rv_isa isa) { - char buf[128] = { 0 }; bfd_byte packet[2]; rv_inst inst = 0; size_t len = 2; @@ -5272,9 +5247,9 @@ print_insn_riscv(bfd_vma memaddr, struct disassemble_info *info, rv_isa isa) } } - disasm_inst(buf, sizeof(buf), isa, memaddr, inst, - (RISCVCPUConfig *)info->target_info); - (*info->fprintf_func)(info->stream, "%s", buf); + g_autoptr(GString) str = + disasm_inst(isa, memaddr, inst, (RISCVCPUConfig *)info->target_info); + (*info->fprintf_func)(info->stream, "%s", str->str); return len; }