From patchwork Fri Apr 12 07:33:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 788271 Delivered-To: patch@linaro.org Received: by 2002:adf:e6ca:0:b0:346:15ad:a2a with SMTP id y10csp591429wrm; Fri, 12 Apr 2024 00:37:46 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWnaIRqgsFSf0oyniGLhWI9QOryr0o0JYtWX9oBF/7ZbvVNvLl99WlwKsibhYUb6QrmWpzA5uFea85rGm+LkZak X-Google-Smtp-Source: AGHT+IHqN5XrPbKHc5ZenZdb8DFfc2woiCf91OSPROhm92Lco9fav2aYo8xkgiMX2eRQ1hJIqdCE X-Received: by 2002:a05:6214:410e:b0:69b:2675:e466 with SMTP id kc14-20020a056214410e00b0069b2675e466mr2284230qvb.29.1712907465917; Fri, 12 Apr 2024 00:37:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712907465; cv=none; d=google.com; s=arc-20160816; b=KVu5s9k84l/Bu+gdy/PuKW4sWyHrA7hC+Pe2JE+veKKNORvYAOBDix4BLErTxTU+/U 1wkieddX6peDW14Nc90JeyutGaNAqAxKrqfYBKJvkDXjHD55Pu9vEa9EPwBwVsjX3FcU 8Lgvap2Uuili+zkPxU/eS9eQTAG/dxVHIpXobmiQuulBhnqoKYoc7cUSlKXvEBPITtL6 +D6WZD73EHNXunQvIcCHFHaz7iArRLQB06h9j2JA2W55lwcciEmYs5s9YM0ue+fkMh1W Bk0Bz4XmzfIvQEL9rxM/+vdyLzp+0GweEOiT9R8JmUVuSSgAv5zrkvoA5wX45Xjy46yx lhjw== 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=P54+4fCIsAAc0bVMNSYixg4SDN1lDlZ7gzm2KMiAs9s=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=yXVavjR6A32GKdFMUN8JVpCPMc8TT8SRlo+FXAmdcfW2r9WQl+2i4xuUwEKrff/1OP mVNzyXEr1mhdWDTMueteiTsUB0H2kSDPPHpxewj+SNRS2Uhnm2gFT3BN9kXv0en45orw BKu34C1abLJm6fhYkTxg3ir1R5AaS2cXm6N0lB7hZ+qXpuuJUfvAH9d/XIkIJZ0PONRE MLtuZAq+MvjtYFFsiC9UHlHk5fN+JEfL4x7hPfib7vOv+M5Keb1etbKXQEzWhOrGlBHu 4IOGvxKIM6gEK8Yz44koHdc3FT2eDtUlQd/03aeiUmyOm/R3jpbvQBtCvLWbeQyEMn9Z TFxg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tpTyIsUA; 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 dk5-20020a056214092500b0069b16ced7b0si3074640qvb.233.2024.04.12.00.37.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Apr 2024 00:37:45 -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=tpTyIsUA; 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 1rvBQN-00076E-TS; Fri, 12 Apr 2024 03:34:15 -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 1rvBQJ-00074f-DW for qemu-devel@nongnu.org; Fri, 12 Apr 2024 03:34:11 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rvBQB-0007CW-OL for qemu-devel@nongnu.org; Fri, 12 Apr 2024 03:34:08 -0400 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1e2bbc2048eso5649145ad.3 for ; Fri, 12 Apr 2024 00:34:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712907242; x=1713512042; 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=P54+4fCIsAAc0bVMNSYixg4SDN1lDlZ7gzm2KMiAs9s=; b=tpTyIsUAm7ryE46ydOJ/Xkhlq+UQK7abWiVVTN4ACh6QckrdoU7LinmRUvs3KQ55hX AU3G37Sd1pi7CCrXnzoRFOimA7fFLOK9VmfuWzzUHdhY827SF0lb8ZlICVUrmfcPMFEH HeANxQxhI7EUDBNBPtLek0qzeRQdAcoZU0TRSB+EjI2P2/RNd1J9efiX74+B6TA090r0 P3XhgLyGx8g2RpKRXThMHwUxRH6flC+2CpzE87xKvmftviZI713yd6QTTAhL02z7I43N o6lEZGwTLWl2I6OcKjg9Z5TGuJj5oStDdNdjDwNNh4mYnvCVdWq3BtJMVHGU4n//T0mE 6vkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712907242; x=1713512042; 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=P54+4fCIsAAc0bVMNSYixg4SDN1lDlZ7gzm2KMiAs9s=; b=aEiat/dY6DIswfjwmSHdTtPc3hlrwHwiOT1kDHp+q019rPXNU5iGZZ2e2WqEh+W8+2 yczGY0X89Dlzv4wyO28ClwkdDwKjXBcpW3XwfqiMkawU4okBBLQI1Y0rLdvdzkBQq97Y zEWCv3bAW2sWfgrUWYS6XzsjoGGJ6eE9gIq5ENqak400HVXhOH+IWwDbGt6ehkVaG2W/ fmj1V0AYWZBcCTey3rfrp/EvuVNo+fUwxbKm6+E8fkfZlxgsw8GxSFX4Wc5n5U+uM5a/ PTtIUgKAvelPRLdSOCVY1wVTg77PkHnmJ8HRrp4rp/lL1sO9OfVBR0UeUjcr1MuPYDs9 tXbg== X-Gm-Message-State: AOJu0YwoDtuF0khjGYoA/tjlVjjSYWR3IY+NalVbhuJtxZJlOEheMZTG qXrLNTOLPmlfMzMQx40GYWOdDjmRtdadOIu2McvxSc33sUY+9v44hmYQp6+K0WlMqYn30VyPMho Y X-Received: by 2002:a17:903:228e:b0:1e3:c9f6:c4b with SMTP id b14-20020a170903228e00b001e3c9f60c4bmr2135075plh.10.1712907242144; Fri, 12 Apr 2024 00:34:02 -0700 (PDT) Received: from stoup.. (174-21-72-5.tukw.qwest.net. [174.21.72.5]) by smtp.gmail.com with ESMTPSA id e5-20020a17090301c500b001e556734814sm2206099plh.134.2024.04.12.00.34.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 00:34:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 18/27] disas/microblaze: Print immediates directly with PRIimm Date: Fri, 12 Apr 2024 00:33:37 -0700 Message-Id: <20240412073346.458116-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240412073346.458116-1-richard.henderson@linaro.org> References: <20240412073346.458116-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 --- 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 */