From nobody Wed Nov 13 07:17:07 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1694554029; cv=none; d=zohomail.com; s=zohoarc; b=KB7HvN6aP5aJl33aeaSv4RofjHO14e2RMYREaS8rhZTeOSTevf9UGdFr8Gjbt1l3/bRVcQSd2b/xArji5L8rMoO2vDs2OVwYK1aSCcFaeUrSqXMhTjs2h+eHVPQGRbunvGcl4xrgRbrP8wWT7rMKC8aM2gC+IRtVcnTYbMnZu4U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694554029; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dE6SZcUTvxnbu/Alt5R7481oeWmTREolDdAvvYc8wwc=; b=YfUjOg+q3B7omNwED2tBJdeCaJcsi7z7jdBg7nLGtH1Xeqw2plrNm9BuAIoWTJe4VTMhhvP6Xiz7jNqNig+v2lBthT4cTGwsEXyO4BOAxLBkk7PQCNMZSz8r2gkgsQ+B0S5qFRz83+xU0YrsIheNaPI9Mx+xlUqsUG0gfWrekRs= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16945540290231008.1118075563719; Tue, 12 Sep 2023 14:27:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgAuQ-0006Fb-JM; Tue, 12 Sep 2023 17:26: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 1qgAuP-0006Eq-28; Tue, 12 Sep 2023 17:26:57 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qgAuM-0007Ai-Js; Tue, 12 Sep 2023 17:26:56 -0400 Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38BLGxBl013703; Mon, 11 Sep 2023 21:23:45 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3t29dya6jq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 Sep 2023 21:23:45 +0000 Received: from m0356517.ppops.net (m0356517.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 38BL9JJj020951; Mon, 11 Sep 2023 21:23:44 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3t29dya6ja-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 Sep 2023 21:23:44 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 38BLG1LA012064; Mon, 11 Sep 2023 21:23:43 GMT Received: from smtprelay06.wdc07v.mail.ibm.com ([172.16.1.73]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3t13dye2jm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 Sep 2023 21:23:43 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay06.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 38BLNhLL57475456 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 11 Sep 2023 21:23:43 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E12095805D; Mon, 11 Sep 2023 21:23:42 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CE98558057; Mon, 11 Sep 2023 21:23:42 +0000 (GMT) Received: from mamboa4.aus.stglabs.ibm.com (unknown [9.3.84.87]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTPS; Mon, 11 Sep 2023 21:23:42 +0000 (GMT) Received: from mamboa4.aus.stglabs.ibm.com (localhost [127.0.0.1]) by mamboa4.aus.stglabs.ibm.com (Postfix) with ESMTPS id 3E7A416A083B; Mon, 11 Sep 2023 16:23:42 -0500 (CDT) Received: (from mglenn@localhost) by mamboa4.aus.stglabs.ibm.com (8.15.2/8.15.2/Submit) id 38BLNgZO2260447; Mon, 11 Sep 2023 16:23:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=dE6SZcUTvxnbu/Alt5R7481oeWmTREolDdAvvYc8wwc=; b=m9UARPdE+fMxll3vi0yyXlR9ua/3xeVQkHLgDX1xEj9ZtBNBa/63wVTUx9EWDFurXgGI QkyBe4X3ZH6foJBVHqe9HiGLfiNhZpOpXfN/QqrpMyPZ8JP9co6Vnr/SVAoZRZcf1FaJ 2DABncS4BBmBVydH33e3P80a+W08nRmFj+IqtphmADKi4eDf8dOPzqwD8v+O3aYQLGa4 lWf8w4+Awph9RxAD+CJcwCRDj7MpC6h50mwcgP9/W4nIxbomZSmTY3epkhdo/l8wsS3J ZMiXOnsJ+7YIrT/7b6SmK9ExH22rVzwyu6cxKNw+9kzkwBTYJVmMEo47t8e57LXEuB03 Kw== From: Glenn Miles To: qemu-devel@nongnu.org Cc: Glenn Miles , Daniel Henrique Barboza , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , Greg Kurz , Nicholas Piggin , qemu-ppc@nongnu.org (open list:PowerPC TCG CPUs) Subject: [PATCH 3/4] target/ppc: Add clrbhrb and mfbhrbe instructions Date: Mon, 11 Sep 2023 16:23:39 -0500 Message-Id: <20230911212340.2260383-4-milesg@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230911212340.2260383-1-milesg@linux.vnet.ibm.com> References: <20230911212340.2260383-1-milesg@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-GUID: GFTSqe8FSUJTxJf2IUmS7qVO0BI6T4wm X-Proofpoint-ORIG-GUID: zU9ZSxXYVHZdIBX1F-EYbKEk4md_mZc8 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-11_16,2023-09-05_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 clxscore=1015 malwarescore=0 priorityscore=1501 spamscore=0 phishscore=0 mlxlogscore=247 mlxscore=0 adultscore=0 impostorscore=0 lowpriorityscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309110194 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: none client-ip=148.163.156.1; envelope-from=mglenn@mamboa4.aus.stglabs.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ibm.com) X-ZM-MESSAGEID: 1694554031093100005 Content-Type: text/plain; charset="utf-8" Add support for the clrbhrb and mfbhrbe instructions. Since neither instruction is believed to be critical to performance, both instructions were implemented using helper functions. Access to both instructions is controlled by bits in the HFSCR (for privileged state) and MMCR0 (for problem state). A new function, helper_mmcr0_facility_check, was added for checking MMCR0[BHRBA] and raising a facility_unavailable exception if required. Signed-off-by: Glenn Miles --- target/ppc/cpu.h | 1 + target/ppc/helper.h | 4 ++++ target/ppc/misc_helper.c | 43 ++++++++++++++++++++++++++++++++++++++++ target/ppc/translate.c | 13 ++++++++++++ 4 files changed, 61 insertions(+) diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index bda1afb700..ee81ede4ee 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -541,6 +541,7 @@ FIELD(MSR, LE, MSR_LE, 1) =20 /* HFSCR bits */ #define HFSCR_MSGP PPC_BIT(53) /* Privileged Message Send Facilities */ +#define HFSCR_BHRB PPC_BIT(59) /* BHRB Instructions */ #define HFSCR_IC_MSGP 0xA =20 #define DBCR0_ICMP (1 << 27) diff --git a/target/ppc/helper.h b/target/ppc/helper.h index 1a3d9a7e57..bbc32ff114 100644 --- a/target/ppc/helper.h +++ b/target/ppc/helper.h @@ -816,3 +816,7 @@ DEF_HELPER_4(DSCLIQ, void, env, fprp, fprp, i32) =20 DEF_HELPER_1(tbegin, void, env) DEF_HELPER_FLAGS_1(fixup_thrm, TCG_CALL_NO_RWG, void, env) + +DEF_HELPER_1(clrbhrb, void, env) +DEF_HELPER_FLAGS_2(mfbhrbe, TCG_CALL_NO_WG, i64, env, i32) + diff --git a/target/ppc/misc_helper.c b/target/ppc/misc_helper.c index 692d058665..45abe04f66 100644 --- a/target/ppc/misc_helper.c +++ b/target/ppc/misc_helper.c @@ -139,6 +139,17 @@ void helper_fscr_facility_check(CPUPPCState *env, uint= 32_t bit, #endif } =20 +static void helper_mmcr0_facility_check(CPUPPCState *env, uint32_t bit, + uint32_t sprn, uint32_t cause) +{ +#ifdef TARGET_PPC64 + if (FIELD_EX64(env->msr, MSR, PR) && + !(env->spr[SPR_POWER_MMCR0] & (1ULL << bit))) { + raise_fu_exception(env, bit, sprn, cause, GETPC()); + } +#endif +} + void helper_msr_facility_check(CPUPPCState *env, uint32_t bit, uint32_t sprn, uint32_t cause) { @@ -351,3 +362,35 @@ void helper_fixup_thrm(CPUPPCState *env) env->spr[i] =3D v; } } + +void helper_clrbhrb(CPUPPCState *env) +{ + helper_hfscr_facility_check(env, HFSCR_BHRB, "clrbhrb", FSCR_IC_BHRB); + + helper_mmcr0_facility_check(env, MMCR0_BHRBA, 0, FSCR_IC_BHRB); + + memset(env->bhrb, 0, sizeof(env->bhrb)); +} + +uint64_t helper_mfbhrbe(CPUPPCState *env, uint32_t bhrbe) +{ + unsigned int index; + + helper_hfscr_facility_check(env, HFSCR_BHRB, "mfbhrbe", FSCR_IC_BHRB); + + helper_mmcr0_facility_check(env, MMCR0_BHRBA, 0, FSCR_IC_BHRB); + + if ((bhrbe >=3D env->bhrb_num_entries) || + (env->spr[SPR_POWER_MMCR0] & MMCR0_PMAE)) { + return 0; + } + + /* + * Note: bhrb_offset is the byte offset for writing the + * next entry (over the oldest entry), which is why we + * must offset bhrbe by 1 to get to the 0th entry. + */ + index =3D ((env->bhrb_offset / sizeof(uint64_t)) - (bhrbe + 1)) % + env->bhrb_num_entries; + return env->bhrb[index]; +} diff --git a/target/ppc/translate.c b/target/ppc/translate.c index 7824475f54..b330871793 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -6549,12 +6549,25 @@ static void gen_brh(DisasContext *ctx) } #endif =20 +static void gen_clrbhrb(DisasContext *ctx) +{ + gen_helper_clrbhrb(cpu_env); +} + +static void gen_mfbhrbe(DisasContext *ctx) +{ + TCGv_i32 bhrbe =3D tcg_constant_i32(_SPR(ctx->opcode)); + gen_helper_mfbhrbe(cpu_gpr[rD(ctx->opcode)], cpu_env, bhrbe); +} + static opcode_t opcodes[] =3D { #if defined(TARGET_PPC64) GEN_HANDLER_E(brd, 0x1F, 0x1B, 0x05, 0x0000F801, PPC_NONE, PPC2_ISA310), GEN_HANDLER_E(brw, 0x1F, 0x1B, 0x04, 0x0000F801, PPC_NONE, PPC2_ISA310), GEN_HANDLER_E(brh, 0x1F, 0x1B, 0x06, 0x0000F801, PPC_NONE, PPC2_ISA310), #endif +GEN_HANDLER_E(clrbhrb, 0x1F, 0x0E, 0x0D, 0x3FFF801, PPC_NONE, PPC2_ISA207S= ), +GEN_HANDLER_E(mfbhrbe, 0x1F, 0x0E, 0x09, 0x0000001, PPC_NONE, PPC2_ISA207S= ), GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE), #if defined(TARGET_PPC64) GEN_HANDLER_E(cmpeqb, 0x1F, 0x00, 0x07, 0x00600000, PPC_NONE, PPC2_ISA300), --=20 2.31.1