From nobody Fri Nov 14 19:45:39 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1761747590; cv=none; d=zohomail.com; s=zohoarc; b=XPNBUM0RxLFaxAiwiFnQkWzda9TY/9vgbJMuKdsA8KKckwEp4lwZrT4tKHL5feN/FT5cPcZvc1ONJpX7m1HhQW/oHjkVIrJ3w9CPG0sQkiUcnIhBihsA2evBEchdG0Sl4eGHOUusp91QrB96IcS+I8oNfZe/gd79dfV+gs5sKOM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761747590; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=poUkJzrIRnT1qAE62jh+3b2s1+llTl5d/4CRcHNKOhA=; b=XxRvpLlXN48RtZc9G9BZFXOFTVAGKSeSDJQ3B/5+cF+gfx7Ag832jnwV+refD859/ye5DrXNH11AZxa4eRfW74c/7lE1UpWYfhPrKucS8r3iJyLtVo8Ez9gERNlLsr15748g7XXTXgUpGUqbtT2P6IoPIbsf5wW0bU8Cm0A5MOo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1761747590856545.1194586829646; Wed, 29 Oct 2025 07:19:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vE70W-00033t-4W; Wed, 29 Oct 2025 10:18:36 -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 1vE70E-00031R-1E for qemu-devel@nongnu.org; Wed, 29 Oct 2025 10:18:24 -0400 Received: from mail-lj1-x22a.google.com ([2a00:1450:4864:20::22a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vE702-0007Wk-Fy for qemu-devel@nongnu.org; Wed, 29 Oct 2025 10:18:14 -0400 Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-378d710caedso79876021fa.3 for ; Wed, 29 Oct 2025 07:18:04 -0700 (PDT) Received: from gmail.com (213-67-3-247-no600.tbcn.telia.com. [213.67.3.247]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-378ee0e5239sm35112611fa.53.2025.10.29.07.18.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Oct 2025 07:18:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1761747482; x=1762352282; 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=poUkJzrIRnT1qAE62jh+3b2s1+llTl5d/4CRcHNKOhA=; b=lw5KxvALJl1Ii3ttu+bfGoim/EXbjFwzGgDJM4svgUvfmmKI622t7SyVZvJK3frv1T 5vPLy3kjoi4bGiEl5XB1JQltJvgHFj4ojUGwEG4yKXG0yOs5XHDHns+gH9xi6hTV1Uy9 5WBjQobTIfgK6cI9uOGszBu10Q6LQBls7CltgDndVKoZmkVKsI5BIovhY16FA/snwOLI wuVOEB615avHH8vjItuJLKuITLanaekuThNRKAd7jNQSGs7Svk49TaltT88fVVylNjd9 vTAjDKLbggGO+Mm41jdRyTOP+NVnMI89RjLUKTNomxjkbG2+xXn9+Dw8suqmODv1WEKO NHNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761747482; x=1762352282; 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=poUkJzrIRnT1qAE62jh+3b2s1+llTl5d/4CRcHNKOhA=; b=kNecx5ji4VtsRP5OkQNMbilz9qcKrvTPiPRPN0+dnlmp6Ab7PGdcX+BFKoiacrrHpV EV+p14qa2xrFckckcDbSD+0M9XVE7EwQO1WL1QGbecg3GYQ4JIY0Iw8csgUYD+mWjnvn qzRN+XiwBQ6frMda0sSxkcz1O60XpBv9lHpJ34/seKP100U81oHL4YBpWPLu9n0yJ67F a9Jpwmtt/AjI3dt2nN074Mdv2IUMfaJyHmKewAy9SvuN90XHXKFfe0q+gAwOrQlstvAc 7LKZDX+eJkfo7HNqk1rKhbks/sxZjycPocZl3YGrJRTzNjRcJbSkFyQqiRjGG9EGmHzm 9mgA== X-Gm-Message-State: AOJu0YxyoK/rfG9DeLBljBb4hetYdM9IlnF+CktqmiRV9fBIBCwQIQYM HmW+9zREmOlE+qT2dptT7/CCWcz972T2ZSvmCIhVk/aPcFFuD4KA2tySp8MTyHyMJiI= X-Gm-Gg: ASbGncu2M4+9wBYV8um2sO/NmJmZwuwpoPpF+oeqzkB6t5wmjmcvbKzbNKb6YIxqgPg WKM+smUlSXUrCU6J7x3ggvC2JMLssBcC3QbyZhzxYW4JqsubqPk9iwBg4Ipnx5S/EKVT/fgd6d3 HL3vKnJAPok+2wNygBEmSwca9d/ZEg8v1FFeJ3jl5ZN0h+UDFbc/jQoLS7xXmbnIpMvd9IeTec5 q4wUpn4Gox/sYvblj3AARl6XX6T9B+YumO7GyjjsQ8lYKwXIcBCZr1tF4GV5/wn4cwCA9HePx5r zjd+109NMEIx8tJBjSwE6igAaNRy2/lC6Q+qqstrE8EaoRCfD7M7bQkUCxTPIr0XdD+YJLw8FpC yarg77h3sqEBrriXF0bcF7mfojyDqdS3LDXAR1Hgb/fYQ1nBOSSZKaI/YR4xfbBH9oXKWJF4eco SIy5HOhNmRq/RCdmQh3dpFjT4gm001c/Tmd2jYupIAJlfP01w= X-Google-Smtp-Source: AGHT+IGjQuKOriJDB2PpQsVZyQTy6Jb8FsvFirJckFgjTp07BXMdiOPC0Pj/93QkIynxp7iPfPN1Ng== X-Received: by 2002:a2e:bcc7:0:b0:37a:57c:adde with SMTP id 38308e7fff4ca-37a057caf49mr9578741fa.48.1761747481377; Wed, 29 Oct 2025 07:18:01 -0700 (PDT) From: "Edgar E. Iglesias" To: qemu-devel@nongnu.org, "Edgar E. Iglesias" Cc: richard.henderson@linaro.org, edgar.iglesias@amd.com Subject: [PULL v1 3/3] target/microblaze: Handle signed division overflows Date: Wed, 29 Oct 2025 15:17:49 +0100 Message-ID: <20251029141749.1274729-4-edgar.iglesias@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251029141749.1274729-1-edgar.iglesias@gmail.com> References: <20251029141749.1274729-1-edgar.iglesias@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::22a; envelope-from=edgar.iglesias@gmail.com; helo=mail-lj1-x22a.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1761747592648154100 Content-Type: text/plain; charset="utf-8" From: "Edgar E. Iglesias" Handle signed division overflows as specified in UG984: https://docs.amd.com/r/en-US/ug984-vivado-microblaze-ref/idiv Signed-off-by: Edgar E. Iglesias Reviewed-by: Richard Henderson --- target/microblaze/cpu.h | 1 + target/microblaze/op_helper.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/target/microblaze/cpu.h b/target/microblaze/cpu.h index 14b107876a..d26b933b6d 100644 --- a/target/microblaze/cpu.h +++ b/target/microblaze/cpu.h @@ -87,6 +87,7 @@ typedef struct CPUArchState CPUMBState; #define ESR_ESS_FSL_OFFSET 5 =20 #define ESR_ESS_MASK (0x7f << 5) +#define ESR_ESS_DEC_OF (1 << 11) /* DEC: 0=3DDBZ, 1=3DOF */ =20 #define ESR_EC_FSL 0 #define ESR_EC_UNALIGNED_DATA 1 diff --git a/target/microblaze/op_helper.c b/target/microblaze/op_helper.c index d3f688e375..31da2c7c3a 100644 --- a/target/microblaze/op_helper.c +++ b/target/microblaze/op_helper.c @@ -89,6 +89,21 @@ uint32_t helper_divs(CPUMBState *env, uint32_t ra, uint3= 2_t rb) raise_divzero(env, ESR_EC_DIVZERO, GETPC()); return 0; } + + /* + * Check for division overflows. + * + * Spec: https://docs.amd.com/r/en-US/ug984-vivado-microblaze-ref/idiv + * UG984, Chapter 5 MicroBlaze Instruction Set Architecture, idiv. + * + * If the U bit is clear, the value of rA is -1, and the value of rB is + * -2147483648 (divide overflow), the DZO bit in MSR will be set and + * the value in rD will be -2147483648, unless an exception is generat= ed. + */ + if ((int32_t)ra =3D=3D -1 && (int32_t)rb =3D=3D INT32_MIN) { + raise_divzero(env, ESR_EC_DIVZERO | ESR_ESS_DEC_OF, GETPC()); + return INT32_MIN; + } return (int32_t)rb / (int32_t)ra; } =20 --=20 2.43.0