From patchwork Tue Jul 11 12:14:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 701505 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp5681074wrs; Tue, 11 Jul 2023 05:18:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlGbKGCXeMqRfU1CTl/6GSD3wGLN35FK1nUYg1J8H/JtlKwd6GWG2mEfQdYf9Go1fxKeJyi7 X-Received: by 2002:a05:622a:284:b0:400:9b80:e89a with SMTP id z4-20020a05622a028400b004009b80e89amr19132161qtw.35.1689077916219; Tue, 11 Jul 2023 05:18:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689077916; cv=none; d=google.com; s=arc-20160816; b=xX4mnCT5sE/Ue1PurPciP3StW2cT0M72grzfpJ3VNa37D36rCfz5283klKJtABIRL/ whT4+MR47MmXt2E4EjQMIqFpjYTALjAph8uEvsp8+vcxCsMmVAWxNWJfMlWGtRRakAjd ztPMoSHfGreI+QUbphV4DFSeKZ4dJvl6jQM92gjbYM3moxzjU9+9wuNVsHuUg1yStJhw 0CRMSCNTY2xeLV8DvmhoXII/A+E1K2HzC29e+q7Ot8Zx+DAH3Z6gHXShpextIvDZ18Gt gDMQ8yS3Z6v9q5LrE0xIjx8kvrmutqeEeTf4d3bXC3/TN+4OD/0F0F9a7galXwyCJ1Mj DjUQ== 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:cc:to :from:dkim-signature; bh=HaANU2OE+dOsUg4Qmvd15nGlRm3AOspQfp2v6+k0l68=; fh=2qKuH1n6VH6wba+79M4ShbS8g9JCHC0RUwOvmGU6vBg=; b=HDU/58xMONGuWykzHw35Q+s0fgMR35A7Hx4TU/3yLKkFbr2diOIRL2RFrnnfoYu9sI mFSUmO8J0aNE5EWZwY1xCefpzZupudMYoyo/o6gUyQ1PGiX8U96NvgVrU60L2qB4JkdX svEv0FtVw7T1/hHC8A5/tJKR0x+qeWbsZsV2B1NirCOGv9S1eb3yBB/KLVV+heN56xbm KcU8XA5YZuai7SOnoHyzUmWCmnUQIFclgO/Jy4m2EVvzqWxp6ZxBiiFqF03L54mBOexG 6r11ARewxbN7fPE8IAI0G9whGsG836NBJD6ChEyGREEBF3/v5g3xWSRE8Cflvm4pqDPn +Eng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JuHIkB7d; 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 f13-20020a05622a1a0d00b00403a9dc72bbsi807446qtb.609.2023.07.11.05.18.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Jul 2023 05:18:36 -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=JuHIkB7d; 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 1qJCHc-0001nD-88; Tue, 11 Jul 2023 08:15:56 -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 1qJCHQ-0001Uo-I2 for qemu-devel@nongnu.org; Tue, 11 Jul 2023 08:15:44 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qJCHN-0005OG-Ha for qemu-devel@nongnu.org; Tue, 11 Jul 2023 08:15:44 -0400 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-3fb4146e8ceso59112625e9.0 for ; Tue, 11 Jul 2023 05:15:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1689077740; x=1691669740; 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=HaANU2OE+dOsUg4Qmvd15nGlRm3AOspQfp2v6+k0l68=; b=JuHIkB7dbyhCA8xiqVqVsJ0E2jPSxh+Yrp8t4FGJVOKQePKyMOMHmhsZai0teUDnLO 5+pp6j+yPWTG2/FMSvnxX7x6puSrz+7znAiC7EvVL24p2i9V5SrhXauQmVNuDdaGv0wZ mR3yjYjRrjWmMssrXl3jYY5emxSnifVJCqevEb6jLysajxycbeNKLaAXEoeJhogVsp9v X4IrXs6sbRPEtbOU90LpgSLh/9x+C2D7XkrYnwfozFwVsNEkBGAOspYwmoQqoC0M1/0N 96gJh8cAdb4r+1cAbGVhOcv9qKfhaS+rE/DgTOcSCYIaGvIVAxtwpVc/ms0hb2pBNtRK 3l8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689077740; x=1691669740; 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=HaANU2OE+dOsUg4Qmvd15nGlRm3AOspQfp2v6+k0l68=; b=BrzqjKA4Qn6xfW4JEoN0H0ABUm8iRbRCa9OrmvZCf3aAWYLYdtMcWK0/tEF9s3LY1r 0TbM/90cWFYwifXJxPkItd6HSv5CFd22hX9SHWJcbcqGtkgJvhmaD/ijyG3RTs/mwai2 VIx0sx+s/KiSHF9bf+6EvxALevuw4X9QKgLZulie4yBgQX1dRmtHio0T87JwSaPGEsru b7LjmThrVnNnfJbb5KSPf3srOKFDPY3UooFY41FfyVsRoAUk0uS8SlDzpkKgX9SZfM9F f4a0JnnMgVdAxawlh+UpCDSBM662FE3pSEh+n/vJVWZ9krQ5KM8kCEihiAc3I36max6L 4Pxg== X-Gm-Message-State: ABy/qLastNpFhpxbf3MkX2zByM7ve0fa9fdhI1JAkcTobixkxi1OF1Ys EuHLJND2hSnVO0DaoSsCWWCeApNGI9IEhLrpSM4= X-Received: by 2002:a5d:6e90:0:b0:314:475:bc47 with SMTP id k16-20020a5d6e90000000b003140475bc47mr12691389wrz.69.1689077739820; Tue, 11 Jul 2023 05:15:39 -0700 (PDT) Received: from m1x-phil.lan ([176.187.194.156]) by smtp.gmail.com with ESMTPSA id v16-20020a5d6110000000b003063db8f45bsm2128927wrt.23.2023.07.11.05.15.38 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 11 Jul 2023 05:15:39 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, Daniel Henrique Barboza , =?utf-8?q?Philippe_Mat?= =?utf-8?q?hieu-Daud=C3=A9?= Subject: [PATCH v3 08/16] target/riscv: Move TCG-specific cpu_get_tb_cpu_state() to tcg/cpu.c Date: Tue, 11 Jul 2023 14:14:45 +0200 Message-Id: <20230711121453.59138-9-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230711121453.59138-1-philmd@linaro.org> References: <20230711121453.59138-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=philmd@linaro.org; helo=mail-wm1-x335.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, T_SCC_BODY_TEXT_LINE=-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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Signed-off-by: Philippe Mathieu-Daudé Acked-by: Alistair Francis --- target/riscv/cpu_helper.c | 84 ------------------------------- target/riscv/tcg/cpu.c | 98 ++++++++++++++++++++++++++++++++++++ target/riscv/tcg/meson.build | 1 + 3 files changed, 99 insertions(+), 84 deletions(-) create mode 100644 target/riscv/tcg/cpu.c diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 597c47bc56..6f8778c6d3 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -64,90 +64,6 @@ int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch) #endif } -void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, - uint64_t *cs_base, uint32_t *pflags) -{ - CPUState *cs = env_cpu(env); - RISCVCPU *cpu = RISCV_CPU(cs); - RISCVExtStatus fs, vs; - uint32_t flags = 0; - - *pc = env->xl == MXL_RV32 ? env->pc & UINT32_MAX : env->pc; - *cs_base = 0; - - if (cpu->cfg.ext_zve32f) { - /* - * If env->vl equals to VLMAX, we can use generic vector operation - * expanders (GVEC) to accerlate the vector operations. - * However, as LMUL could be a fractional number. The maximum - * vector size can be operated might be less than 8 bytes, - * which is not supported by GVEC. So we set vl_eq_vlmax flag to true - * only when maxsz >= 8 bytes. - */ - uint32_t vlmax = vext_get_vlmax(cpu, env->vtype); - uint32_t sew = FIELD_EX64(env->vtype, VTYPE, VSEW); - uint32_t maxsz = vlmax << sew; - bool vl_eq_vlmax = (env->vstart == 0) && (vlmax == env->vl) && - (maxsz >= 8); - flags = FIELD_DP32(flags, TB_FLAGS, VILL, env->vill); - flags = FIELD_DP32(flags, TB_FLAGS, SEW, sew); - flags = FIELD_DP32(flags, TB_FLAGS, LMUL, - FIELD_EX64(env->vtype, VTYPE, VLMUL)); - flags = FIELD_DP32(flags, TB_FLAGS, VL_EQ_VLMAX, vl_eq_vlmax); - flags = FIELD_DP32(flags, TB_FLAGS, VTA, - FIELD_EX64(env->vtype, VTYPE, VTA)); - flags = FIELD_DP32(flags, TB_FLAGS, VMA, - FIELD_EX64(env->vtype, VTYPE, VMA)); - flags = FIELD_DP32(flags, TB_FLAGS, VSTART_EQ_ZERO, env->vstart == 0); - } else { - flags = FIELD_DP32(flags, TB_FLAGS, VILL, 1); - } - -#ifdef CONFIG_USER_ONLY - fs = EXT_STATUS_DIRTY; - vs = EXT_STATUS_DIRTY; -#else - flags = FIELD_DP32(flags, TB_FLAGS, PRIV, env->priv); - - flags |= cpu_mmu_index(env, 0); - fs = get_field(env->mstatus, MSTATUS_FS); - vs = get_field(env->mstatus, MSTATUS_VS); - - if (env->virt_enabled) { - flags = FIELD_DP32(flags, TB_FLAGS, VIRT_ENABLED, 1); - /* - * Merge DISABLED and !DIRTY states using MIN. - * We will set both fields when dirtying. - */ - fs = MIN(fs, get_field(env->mstatus_hs, MSTATUS_FS)); - vs = MIN(vs, get_field(env->mstatus_hs, MSTATUS_VS)); - } - - /* With Zfinx, floating point is enabled/disabled by Smstateen. */ - if (!riscv_has_ext(env, RVF)) { - fs = (smstateen_acc_ok(env, 0, SMSTATEEN0_FCSR) == RISCV_EXCP_NONE) - ? EXT_STATUS_DIRTY : EXT_STATUS_DISABLED; - } - - if (cpu->cfg.debug && !icount_enabled()) { - flags = FIELD_DP32(flags, TB_FLAGS, ITRIGGER, env->itrigger_enabled); - } -#endif - - flags = FIELD_DP32(flags, TB_FLAGS, FS, fs); - flags = FIELD_DP32(flags, TB_FLAGS, VS, vs); - flags = FIELD_DP32(flags, TB_FLAGS, XL, env->xl); - flags = FIELD_DP32(flags, TB_FLAGS, AXL, cpu_address_xl(env)); - if (env->cur_pmmask != 0) { - flags = FIELD_DP32(flags, TB_FLAGS, PM_MASK_ENABLED, 1); - } - if (env->cur_pmbase != 0) { - flags = FIELD_DP32(flags, TB_FLAGS, PM_BASE_ENABLED, 1); - } - - *pflags = flags; -} - void riscv_cpu_update_mask(CPURISCVState *env) { target_ulong mask = 0, base = 0; diff --git a/target/riscv/tcg/cpu.c b/target/riscv/tcg/cpu.c new file mode 100644 index 0000000000..2ae6919b80 --- /dev/null +++ b/target/riscv/tcg/cpu.c @@ -0,0 +1,98 @@ +/* + * RISC-V CPU helpers (TCG specific) + * + * Copyright (c) 2016-2017 Sagar Karandikar, sagark@eecs.berkeley.edu + * Copyright (c) 2017-2018 SiFive, Inc. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "cpu.h" +#ifndef CONFIG_USER_ONLY +#include "sysemu/cpu-timers.h" +#endif + +void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, + uint64_t *cs_base, uint32_t *pflags) +{ + CPUState *cs = env_cpu(env); + RISCVCPU *cpu = RISCV_CPU(cs); + RISCVExtStatus fs, vs; + uint32_t flags = 0; + + *pc = env->xl == MXL_RV32 ? env->pc & UINT32_MAX : env->pc; + *cs_base = 0; + + if (cpu->cfg.ext_zve32f) { + /* + * If env->vl equals to VLMAX, we can use generic vector operation + * expanders (GVEC) to accerlate the vector operations. + * However, as LMUL could be a fractional number. The maximum + * vector size can be operated might be less than 8 bytes, + * which is not supported by GVEC. So we set vl_eq_vlmax flag to true + * only when maxsz >= 8 bytes. + */ + uint32_t vlmax = vext_get_vlmax(cpu, env->vtype); + uint32_t sew = FIELD_EX64(env->vtype, VTYPE, VSEW); + uint32_t maxsz = vlmax << sew; + bool vl_eq_vlmax = (env->vstart == 0) && (vlmax == env->vl) && + (maxsz >= 8); + flags = FIELD_DP32(flags, TB_FLAGS, VILL, env->vill); + flags = FIELD_DP32(flags, TB_FLAGS, SEW, sew); + flags = FIELD_DP32(flags, TB_FLAGS, LMUL, + FIELD_EX64(env->vtype, VTYPE, VLMUL)); + flags = FIELD_DP32(flags, TB_FLAGS, VL_EQ_VLMAX, vl_eq_vlmax); + flags = FIELD_DP32(flags, TB_FLAGS, VTA, + FIELD_EX64(env->vtype, VTYPE, VTA)); + flags = FIELD_DP32(flags, TB_FLAGS, VMA, + FIELD_EX64(env->vtype, VTYPE, VMA)); + flags = FIELD_DP32(flags, TB_FLAGS, VSTART_EQ_ZERO, env->vstart == 0); + } else { + flags = FIELD_DP32(flags, TB_FLAGS, VILL, 1); + } + +#ifdef CONFIG_USER_ONLY + fs = EXT_STATUS_DIRTY; + vs = EXT_STATUS_DIRTY; +#else + flags = FIELD_DP32(flags, TB_FLAGS, PRIV, env->priv); + + flags |= cpu_mmu_index(env, 0); + fs = get_field(env->mstatus, MSTATUS_FS); + vs = get_field(env->mstatus, MSTATUS_VS); + + if (env->virt_enabled) { + flags = FIELD_DP32(flags, TB_FLAGS, VIRT_ENABLED, 1); + /* + * Merge DISABLED and !DIRTY states using MIN. + * We will set both fields when dirtying. + */ + fs = MIN(fs, get_field(env->mstatus_hs, MSTATUS_FS)); + vs = MIN(vs, get_field(env->mstatus_hs, MSTATUS_VS)); + } + + /* With Zfinx, floating point is enabled/disabled by Smstateen. */ + if (!riscv_has_ext(env, RVF)) { + fs = (smstateen_acc_ok(env, 0, SMSTATEEN0_FCSR) == RISCV_EXCP_NONE) + ? EXT_STATUS_DIRTY : EXT_STATUS_DISABLED; + } + + if (cpu->cfg.debug && !icount_enabled()) { + flags = FIELD_DP32(flags, TB_FLAGS, ITRIGGER, env->itrigger_enabled); + } +#endif + + flags = FIELD_DP32(flags, TB_FLAGS, FS, fs); + flags = FIELD_DP32(flags, TB_FLAGS, VS, vs); + flags = FIELD_DP32(flags, TB_FLAGS, XL, env->xl); + flags = FIELD_DP32(flags, TB_FLAGS, AXL, cpu_address_xl(env)); + if (env->cur_pmmask != 0) { + flags = FIELD_DP32(flags, TB_FLAGS, PM_MASK_ENABLED, 1); + } + if (env->cur_pmbase != 0) { + flags = FIELD_DP32(flags, TB_FLAGS, PM_BASE_ENABLED, 1); + } + + *pflags = flags; +} diff --git a/target/riscv/tcg/meson.build b/target/riscv/tcg/meson.build index 65670493b1..a615aafd9a 100644 --- a/target/riscv/tcg/meson.build +++ b/target/riscv/tcg/meson.build @@ -8,6 +8,7 @@ gen = [ riscv_ss.add(when: 'CONFIG_TCG', if_true: gen) riscv_ss.add(when: 'CONFIG_TCG', if_true: files( + 'cpu.c', 'fpu_helper.c', 'op_helper.c', 'vector_helper.c',