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: