Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7033BC25B47 for ; Wed, 25 Oct 2023 13:52:03 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qveHM-0001d8-Eq; Wed, 25 Oct 2023 09:50: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 1qveHD-0001PU-Ar for qemu-riscv@nongnu.org; Wed, 25 Oct 2023 09:50:28 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qveHB-0002yY-Mv for qemu-riscv@nongnu.org; Wed, 25 Oct 2023 09:50:27 -0400 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1c0ecb9a075so41103485ad.2 for ; Wed, 25 Oct 2023 06:50:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1698241824; x=1698846624; 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=waCZsK0sspsHGxnpaGd6gIqrENxMiNl1xxH2aoo3R58=; b=WRWynaRTu1VGt8553NPf58+9bf2wk0Dqyt321sq3Uw6+jQNNrKEnS90r1NqRRCekFt mi3aWGL94P25G+2m1sdYkAkfV4p0N0H90JbYUH0HNI58PoRRTVF4PCPzbGeIOe/ArRWY lCGSjpiqxs2pRZ8aAJMRJLyF9nYXYGQfFwZFs5dolCj6UOJphQN9QlSyM7l3UAH6/IkR qtVux9x9zlXvH3s5wGGgM/1rLJSSFgybjsyNYRmhZ0OenzfwTguZT9ieF7d7WI7TFf9Q v3Ad4vdmR9oO5+Tb3y3/iAU6DKrK5uoGmixjbzX3OjaUl1z+T9jWpAaWfyd8Lu81GDXU w9+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698241824; x=1698846624; 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=waCZsK0sspsHGxnpaGd6gIqrENxMiNl1xxH2aoo3R58=; b=mpN13yaXVP7EUf+tEzP/HFphRT6Sh0OGwpP142Tete/A4k/cW6UhCxryw8+3oJtjSV 3VD+3i69LirO5piD1BrO35Arv7veOGZgGrBeq+YQ1US0fiC3+Fk3T5fxEHR3xAaiSxJf mS+fyTfytyUlS+M5iLZ9gpK5rkJPg6pZZKEia94BcTv5F23m75viQl7Dco/5YUuKg8Kl u4+FH8juQDZXjBz5GBHRqPTUVI4h6/L6yPG6chrCBi2Ngo+6OrEQmB4j89Yuy8q4ELXU +xm3SQ4vkfhjrIxodfL3ndCiAOoVYGnHPNemnsF8TC9p7ZvKnh2wjJfDZHahMTpvbuIT IFpw== X-Gm-Message-State: AOJu0Ywc9Fjp7rjZhz8y3D+Biqs2oFXa2Dnd4hBCEfu822slObL3wpmn Vk+xqEype9Dhw7zlTeGATuPukg== X-Google-Smtp-Source: AGHT+IHZEM43RYzbBtX15CrCm6kNZm0alQ+m3uX3wbihQd/sWI+jKEro4s/HixSV7F/ni1+fnB1yfw== X-Received: by 2002:a17:903:2283:b0:1ca:1cf3:e72e with SMTP id b3-20020a170903228300b001ca1cf3e72emr13891393plh.45.1698241824442; Wed, 25 Oct 2023 06:50:24 -0700 (PDT) Received: from grind.. ([191.255.2.33]) by smtp.gmail.com with ESMTPSA id jw4-20020a170903278400b001ca485b8515sm9252548plb.91.2023.10.25.06.50.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 06:50:23 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, bmeng@tinylab.org, liweiwei@iscas.ac.cn, zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com, Daniel Henrique Barboza Subject: [PATCH v4 5/9] target/riscv/tcg: add riscv_cpu_write_misa_bit() Date: Wed, 25 Oct 2023 10:49:57 -0300 Message-ID: <20231025135001.531224-6-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231025135001.531224-1-dbarboza@ventanamicro.com> References: <20231025135001.531224-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=dbarboza@ventanamicro.com; helo=mail-pl1-x636.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-riscv@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-riscv-bounces+qemu-riscv=archiver.kernel.org@nongnu.org Sender: qemu-riscv-bounces+qemu-riscv=archiver.kernel.org@nongnu.org We have two instances of the setting/clearing a MISA bit from env->misa_ext and env->misa_ext_mask pattern. And the next patch will end up adding one more. Create a helper to avoid code repetition. Signed-off-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis Reviewed-by: LIU Zhiwei --- target/riscv/tcg/tcg-cpu.c | 44 ++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c index f3fc318704..b2489a5317 100644 --- a/target/riscv/tcg/tcg-cpu.c +++ b/target/riscv/tcg/tcg-cpu.c @@ -42,6 +42,20 @@ static bool cpu_cfg_ext_is_user_set(uint32_t ext_offset) GUINT_TO_POINTER(ext_offset)); } +static void riscv_cpu_write_misa_bit(RISCVCPU *cpu, uint32_t bit, + bool enabled) +{ + CPURISCVState *env = &cpu->env; + + if (enabled) { + env->misa_ext |= bit; + env->misa_ext_mask |= bit; + } else { + env->misa_ext &= ~bit; + env->misa_ext_mask &= ~bit; + } +} + static void riscv_cpu_synchronize_from_tb(CPUState *cs, const TranslationBlock *tb) { @@ -692,20 +706,14 @@ static void cpu_set_misa_ext_cfg(Object *obj, Visitor *v, const char *name, return; } - if (value) { - if (!generic_cpu) { - g_autofree char *cpuname = riscv_cpu_get_name(cpu); - error_setg(errp, "'%s' CPU does not allow enabling extensions", - cpuname); - return; - } - - env->misa_ext |= misa_bit; - env->misa_ext_mask |= misa_bit; - } else { - env->misa_ext &= ~misa_bit; - env->misa_ext_mask &= ~misa_bit; + if (value && !generic_cpu) { + g_autofree char *cpuname = riscv_cpu_get_name(cpu); + error_setg(errp, "'%s' CPU does not allow enabling extensions", + cpuname); + return; } + + riscv_cpu_write_misa_bit(cpu, misa_bit, value); } static void cpu_get_misa_ext_cfg(Object *obj, Visitor *v, const char *name, @@ -749,7 +757,6 @@ static const RISCVCPUMisaExtConfig misa_ext_cfgs[] = { */ static void riscv_cpu_add_misa_properties(Object *cpu_obj) { - CPURISCVState *env = &RISCV_CPU(cpu_obj)->env; bool use_def_vals = riscv_cpu_is_generic(cpu_obj); int i; @@ -770,13 +777,8 @@ static void riscv_cpu_add_misa_properties(Object *cpu_obj) NULL, (void *)misa_cfg); object_property_set_description(cpu_obj, name, desc); if (use_def_vals) { - if (misa_cfg->enabled) { - env->misa_ext |= bit; - env->misa_ext_mask |= bit; - } else { - env->misa_ext &= ~bit; - env->misa_ext_mask &= ~bit; - } + riscv_cpu_write_misa_bit(RISCV_CPU(cpu_obj), bit, + misa_cfg->enabled); } } } -- 2.41.0