Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1pa0Gi-0008H2-Sz for mharc-qemu-riscv@gnu.org; Wed, 08 Mar 2023 15:20:12 -0500 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 1pa0Gg-0008GW-Mc for qemu-riscv@nongnu.org; Wed, 08 Mar 2023 15:20:10 -0500 Received: from mail-oi1-x22e.google.com ([2607:f8b0:4864:20::22e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pa0Ge-0002kV-UR for qemu-riscv@nongnu.org; Wed, 08 Mar 2023 15:20:10 -0500 Received: by mail-oi1-x22e.google.com with SMTP id bi17so13016oib.3 for ; Wed, 08 Mar 2023 12:20:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1678306807; 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=0QTR0ZBEeetCDibdFu13o9OoCHPUbiVB3yz0NXvEhrk=; b=lR03a5vcekKH4a1JRJu3JnQCVU7mb90S/YtjgWZMCIh9UqtB8Aa3rAIxtX1bsGZBpn W64kqGD2Av43ohh16zCisgG2Xgj5NzB6IKrBvzbt/f8eHXxqv0lta5cP+OfRDyM2QVcu iomRZE2Nb21i7Fpl8CzV87B72+iHxlBbH//unROjOI6mBQVChISjtljLZOBWh7Z0k2q1 0azUwChszUWgEZ96x+eUjGLtedcEJKfNCCVI8ZljJF4b2yPBCawB8tuTJw3TJ72m/QDP 2BC5x17ZPYhlKQviofkWJy3v679p1voJRdGUgLDirHWDa3rAvt0wWWn88QIFxSTaWLzk rmJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678306807; 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=0QTR0ZBEeetCDibdFu13o9OoCHPUbiVB3yz0NXvEhrk=; b=lIaRkek/ti2BPafbiNWuqai1E23CB/iak8l+pm6Z0ySheNgKzBdm2SsMxo7a0qD1cV tDT8yYhyIwVHUI+pZoTmbGcSmWda49E5Thj/KGxZqRLpGFvTAn75752JXVTCyd0XiL/r vLqhaTMum7SEjDFL5mUNWQLopvn27R3bmXi8yyVU+0s3glnFyL5BISeX4XuNmC7ZV7Ui XRc9Y3tR1+pRk3ekICmUGO4XT6ev0+bpanLdaIGaxJsLBAk9uVyR/vPlD5Eos2rKX/Un W8xh63e+ePdwbLwQl/iMbZfJ5O87K7CELCbXM99lO4jLHxVhDA4meR7EL074l5cclRMM gPQg== X-Gm-Message-State: AO0yUKUgl8GY8uhKFZmSPMRU2kiWNFA7L8wzIhdSzn+rfzEflyraBQPa PB6ehVVAmnC1goRfB5MnWbb99g== X-Google-Smtp-Source: AK7set8e354WLnBXR+pzo3vswXBnqChg7S0unEQ3dw7sTm8weBO0TiezbKPAFML5fUsRqnAO7GGcxw== X-Received: by 2002:a05:6808:7c3:b0:367:7633:30dc with SMTP id f3-20020a05680807c300b00367763330dcmr7772087oij.40.1678306807684; Wed, 08 Mar 2023 12:20:07 -0800 (PST) Received: from grind.. ([177.189.53.31]) by smtp.gmail.com with ESMTPSA id i66-20020aca3b45000000b00383e9fa1eaasm6705790oia.43.2023.03.08.12.20.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Mar 2023 12:20:07 -0800 (PST) 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 for-8.1 12/17] target/riscv: put env->misa_ext <-> cpu->cfg code into helpers Date: Wed, 8 Mar 2023 17:19:20 -0300 Message-Id: <20230308201925.258223-13-dbarboza@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230308201925.258223-1-dbarboza@ventanamicro.com> References: <20230308201925.258223-1-dbarboza@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::22e; envelope-from=dbarboza@ventanamicro.com; helo=mail-oi1-x22e.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=unavailable 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: , X-List-Received-Date: Wed, 08 Mar 2023 20:20:10 -0000 The extremely tedious code that sets cpu->cfg based on misa_ext, and vice-versa, is scattered around riscv_cpu_validate_set_extensions() and set_misa(). Introduce helpers to do this work, cleaning up the logic of both functions a bit. While we're at it, add a note in cpu.h informing that any future change in MISA RV* bits should also be reflected in the helpers as well. Signed-off-by: Daniel Henrique Barboza --- target/riscv/cpu.c | 120 ++++++++++++++++++++++++--------------------- target/riscv/cpu.h | 3 +- 2 files changed, 65 insertions(+), 58 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index 48838471b8..a564de01df 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -234,10 +234,69 @@ const char *riscv_cpu_get_trap_name(target_ulong cause, bool async) } } -static void set_misa(CPURISCVState *env, RISCVMXL mxl, uint32_t ext) +static uint32_t riscv_get_misa_ext_with_cpucfg(RISCVCPUConfig *cfg) { - RISCVCPU *cpu; + uint32_t ext = 0; + if (cfg->ext_i) { + ext |= RVI; + } + if (cfg->ext_e) { + ext |= RVE; + } + if (cfg->ext_m) { + ext |= RVM; + } + if (cfg->ext_a) { + ext |= RVA; + } + if (cfg->ext_f) { + ext |= RVF; + } + if (cfg->ext_d) { + ext |= RVD; + } + if (cfg->ext_c) { + ext |= RVC; + } + if (cfg->ext_s) { + ext |= RVS; + } + if (cfg->ext_u) { + ext |= RVU; + } + if (cfg->ext_h) { + ext |= RVH; + } + if (cfg->ext_v) { + ext |= RVV; + } + if (cfg->ext_j) { + ext |= RVJ; + } + + return ext; +} + +static void riscv_set_cpucfg_with_misa(RISCVCPUConfig *cfg, + uint32_t misa_ext) +{ + cfg->ext_i = misa_ext & RVI; + cfg->ext_e = misa_ext & RVE; + cfg->ext_m = misa_ext & RVM; + cfg->ext_a = misa_ext & RVA; + cfg->ext_f = misa_ext & RVF; + cfg->ext_d = misa_ext & RVD; + cfg->ext_v = misa_ext & RVV; + cfg->ext_c = misa_ext & RVC; + cfg->ext_s = misa_ext & RVS; + cfg->ext_u = misa_ext & RVU; + cfg->ext_h = misa_ext & RVH; + cfg->ext_j = misa_ext & RVJ; +} + +static void set_misa(CPURISCVState *env, RISCVMXL mxl, uint32_t ext) +{ env->misa_mxl_max = env->misa_mxl = mxl; env->misa_ext_mask = env->misa_ext = ext; @@ -251,25 +310,7 @@ static void set_misa(CPURISCVState *env, RISCVMXL mxl, uint32_t ext) return; } - /* - * We can't use riscv_cpu_cfg() in this case because it is - * a read-only inline and we're going to change the values - * of cpu->cfg. - */ - cpu = env_archcpu(env); - - cpu->cfg.ext_i = ext & RVI; - cpu->cfg.ext_e = ext & RVE; - cpu->cfg.ext_m = ext & RVM; - cpu->cfg.ext_a = ext & RVA; - cpu->cfg.ext_f = ext & RVF; - cpu->cfg.ext_d = ext & RVD; - cpu->cfg.ext_v = ext & RVV; - cpu->cfg.ext_c = ext & RVC; - cpu->cfg.ext_s = ext & RVS; - cpu->cfg.ext_u = ext & RVU; - cpu->cfg.ext_h = ext & RVH; - cpu->cfg.ext_j = ext & RVJ; + riscv_set_cpucfg_with_misa(&env_archcpu(env)->cfg, ext); } #ifndef CONFIG_USER_ONLY @@ -1142,42 +1183,7 @@ static void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) cpu->cfg.ext_zksh = true; } - if (cpu->cfg.ext_i) { - ext |= RVI; - } - if (cpu->cfg.ext_e) { - ext |= RVE; - } - if (cpu->cfg.ext_m) { - ext |= RVM; - } - if (cpu->cfg.ext_a) { - ext |= RVA; - } - if (cpu->cfg.ext_f) { - ext |= RVF; - } - if (cpu->cfg.ext_d) { - ext |= RVD; - } - if (cpu->cfg.ext_c) { - ext |= RVC; - } - if (cpu->cfg.ext_s) { - ext |= RVS; - } - if (cpu->cfg.ext_u) { - ext |= RVU; - } - if (cpu->cfg.ext_h) { - ext |= RVH; - } - if (cpu->cfg.ext_v) { - ext |= RVV; - } - if (cpu->cfg.ext_j) { - ext |= RVJ; - } + ext = riscv_get_misa_ext_with_cpucfg(&cpu->cfg); env->misa_ext_mask = env->misa_ext = ext; } diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index f8baedd9c7..529d8044c4 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -66,7 +66,8 @@ #define RV(x) ((target_ulong)1 << (x - 'A')) /* - * Consider updating set_misa() when adding new + * Consider updating riscv_get_misa_ext_with_cpucfg() + * and riscv_set_cpucfg_with_misa() when adding new * MISA bits here. */ #define RVI RV('I') -- 2.39.2