2018-03-02 13:31:10 +01:00
|
|
|
/*
|
|
|
|
* QEMU RISC-V CPU
|
|
|
|
*
|
|
|
|
* Copyright (c) 2016-2017 Sagar Karandikar, sagark@eecs.berkeley.edu
|
|
|
|
* Copyright (c) 2017-2018 SiFive, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2 or later, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef RISCV_CPU_H
|
|
|
|
#define RISCV_CPU_H
|
|
|
|
|
2019-07-09 17:20:52 +02:00
|
|
|
#include "hw/core/cpu.h"
|
2020-07-01 17:24:52 +02:00
|
|
|
#include "hw/registerfields.h"
|
2023-09-25 19:56:58 +02:00
|
|
|
#include "hw/qdev-properties.h"
|
2018-03-02 13:31:10 +01:00
|
|
|
#include "exec/cpu-defs.h"
|
2022-03-23 16:57:39 +01:00
|
|
|
#include "qemu/cpu-float.h"
|
2020-09-03 22:43:22 +02:00
|
|
|
#include "qom/object.h"
|
2022-01-06 22:01:06 +01:00
|
|
|
#include "qemu/int128.h"
|
2021-10-20 05:16:57 +02:00
|
|
|
#include "cpu_bits.h"
|
2023-05-23 11:35:33 +02:00
|
|
|
#include "cpu_cfg.h"
|
riscv: Allow user to set the satp mode
RISC-V specifies multiple sizes for addressable memory and Linux probes for
the machine's support at startup via the satp CSR register (done in
csr.c:validate_vm).
As per the specification, sv64 must support sv57, which in turn must
support sv48...etc. So we can restrict machine support by simply setting the
"highest" supported mode and the bare mode is always supported.
You can set the satp mode using the new properties "sv32", "sv39", "sv48",
"sv57" and "sv64" as follows:
-cpu rv64,sv57=on # Linux will boot using sv57 scheme
-cpu rv64,sv39=on # Linux will boot using sv39 scheme
-cpu rv64,sv57=off # Linux will boot using sv48 scheme
-cpu rv64 # Linux will boot using sv57 scheme by default
We take the highest level set by the user:
-cpu rv64,sv48=on,sv57=on # Linux will boot using sv57 scheme
We make sure that invalid configurations are rejected:
-cpu rv64,sv39=off,sv48=on # sv39 must be supported if higher modes are
# enabled
We accept "redundant" configurations:
-cpu rv64,sv48=on,sv57=off # Linux will boot using sv48 scheme
And contradictory configurations:
-cpu rv64,sv48=on,sv48=off # Linux will boot using sv39 scheme
Co-Developed-by: Ludovic Henry <ludovic@rivosinc.com>
Signed-off-by: Ludovic Henry <ludovic@rivosinc.com>
Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Reviewed-by: Bin Meng <bmeng@tinylab.org>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Frank Chang <frank.chang@sifive.com>
Message-ID: <20230303131252.892893-4-alexghiti@rivosinc.com>
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2023-03-03 14:12:50 +01:00
|
|
|
#include "qapi/qapi-types-common.h"
|
2023-04-11 20:35:09 +02:00
|
|
|
#include "cpu-qom.h"
|
2018-03-02 13:31:10 +01:00
|
|
|
|
2023-10-13 11:35:04 +02:00
|
|
|
typedef struct CPUArchState CPURISCVState;
|
|
|
|
|
2023-10-06 09:55:13 +02:00
|
|
|
#define CPU_RESOLVING_TYPE TYPE_RISCV_CPU
|
|
|
|
|
2023-10-06 09:45:40 +02:00
|
|
|
#if defined(TARGET_RISCV32)
|
|
|
|
# define TYPE_RISCV_CPU_BASE TYPE_RISCV_CPU_BASE32
|
|
|
|
#elif defined(TARGET_RISCV64)
|
|
|
|
# define TYPE_RISCV_CPU_BASE TYPE_RISCV_CPU_BASE64
|
|
|
|
#endif
|
|
|
|
|
2019-03-22 19:51:19 +01:00
|
|
|
#define TCG_GUEST_DEFAULT_MO 0
|
|
|
|
|
2022-05-11 16:45:23 +02:00
|
|
|
/*
|
|
|
|
* RISC-V-specific extra insn start words:
|
|
|
|
* 1: Original instruction opcode
|
|
|
|
*/
|
|
|
|
#define TARGET_INSN_START_EXTRA_WORDS 1
|
|
|
|
|
2018-03-02 13:31:10 +01:00
|
|
|
#define RV(x) ((target_ulong)1 << (x - 'A'))
|
|
|
|
|
2023-07-06 12:17:29 +02:00
|
|
|
/*
|
2023-09-25 19:57:03 +02:00
|
|
|
* Update misa_bits[], misa_ext_info_arr[] and misa_ext_cfgs[]
|
2023-07-06 12:17:29 +02:00
|
|
|
* when adding new MISA bits here.
|
|
|
|
*/
|
2018-03-02 13:31:10 +01:00
|
|
|
#define RVI RV('I')
|
2018-03-05 01:28:00 +01:00
|
|
|
#define RVE RV('E') /* E and I are mutually exclusive */
|
2018-03-02 13:31:10 +01:00
|
|
|
#define RVM RV('M')
|
|
|
|
#define RVA RV('A')
|
|
|
|
#define RVF RV('F')
|
|
|
|
#define RVD RV('D')
|
2020-07-01 17:24:49 +02:00
|
|
|
#define RVV RV('V')
|
2018-03-02 13:31:10 +01:00
|
|
|
#define RVC RV('C')
|
|
|
|
#define RVS RV('S')
|
|
|
|
#define RVU RV('U')
|
2020-02-01 02:01:41 +01:00
|
|
|
#define RVH RV('H')
|
2021-10-25 19:36:02 +02:00
|
|
|
#define RVJ RV('J')
|
2023-04-06 20:03:50 +02:00
|
|
|
#define RVG RV('G')
|
2024-01-11 17:16:43 +01:00
|
|
|
#define RVB RV('B')
|
2018-03-02 13:31:10 +01:00
|
|
|
|
2023-09-25 19:57:03 +02:00
|
|
|
extern const uint32_t misa_bits[];
|
2023-07-06 12:17:29 +02:00
|
|
|
const char *riscv_get_misa_ext_name(uint32_t bit);
|
|
|
|
const char *riscv_get_misa_ext_description(uint32_t bit);
|
2018-03-02 13:31:10 +01:00
|
|
|
|
2023-09-12 15:24:17 +02:00
|
|
|
#define CPU_CFG_OFFSET(_prop) offsetof(struct RISCVCPUConfig, _prop)
|
|
|
|
|
2023-12-18 13:53:16 +01:00
|
|
|
typedef struct riscv_cpu_profile {
|
2023-12-18 13:53:32 +01:00
|
|
|
struct riscv_cpu_profile *parent;
|
2023-12-18 13:53:16 +01:00
|
|
|
const char *name;
|
|
|
|
uint32_t misa_ext;
|
|
|
|
bool enabled;
|
|
|
|
bool user_set;
|
2023-12-18 13:53:28 +01:00
|
|
|
int priv_spec;
|
2023-12-18 13:53:31 +01:00
|
|
|
int satp_mode;
|
2023-12-18 13:53:16 +01:00
|
|
|
const int32_t ext_offsets[];
|
|
|
|
} RISCVCPUProfile;
|
|
|
|
|
|
|
|
#define RISCV_PROFILE_EXT_LIST_END -1
|
2023-12-18 13:53:28 +01:00
|
|
|
#define RISCV_PROFILE_ATTR_UNUSED -1
|
2023-12-18 13:53:16 +01:00
|
|
|
|
|
|
|
extern RISCVCPUProfile *riscv_profiles[];
|
|
|
|
|
2022-03-03 19:54:35 +01:00
|
|
|
/* Privileged specification version */
|
target/riscv: rework 'priv_spec'
'priv_spec' and 'vext_spec' are two string options used as a fancy way
of setting integers in the CPU state (cpu->env.priv_ver and
cpu->env.vext_ver). It requires us to deal with string parsing and to
store them in cpu_cfg.
We must support these string options, but we don't need to store them.
We have a precedence for this kind of arrangement in target/ppc/compat.c,
ppc_compat_prop_get|set, getters and setters used for the
'max-cpu-compat' class property of the pseries ppc64 machine. We'll do
the same with both 'priv_spec' and 'vext_spec'.
For 'priv_spec', the validation from riscv_cpu_validate_priv_spec() will
be done by the prop_priv_spec_set() setter, while also preventing it to
be changed for vendor CPUs. Add two helpers that converts env->priv_ver
back and forth to its string representation. These helpers allow us to
get a string and set 'env->priv_ver' and return a string giving the
current env->priv_ver value. In other words, make the cpu->cfg.priv_spec
string obsolete.
Last but not the least, move the reworked 'priv_spec' option to
riscv_cpu_properties[].
After all said and done, we don't need to store the 'priv_spec' string in
the CPU state, and we're now protecting vendor CPUs from priv_ver
changes:
$ ./build/qemu-system-riscv64 -M virt -cpu sifive-e51,priv_spec="v1.12.0"
qemu-system-riscv64: can't apply global sifive-e51-riscv-cpu.priv_spec=v1.12.0:
CPU 'sifive-e51' does not allow changing the value of 'priv_spec'
Current 'priv_spec' val: v1.10.0
$
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Tested-by: Vladimir Isaev <vladimir.isaev@syntacore.com>
Message-ID: <20240105230546.265053-7-dbarboza@ventanamicro.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2024-01-06 00:05:35 +01:00
|
|
|
#define PRIV_VER_1_10_0_STR "v1.10.0"
|
|
|
|
#define PRIV_VER_1_11_0_STR "v1.11.0"
|
|
|
|
#define PRIV_VER_1_12_0_STR "v1.12.0"
|
2022-03-03 19:54:35 +01:00
|
|
|
enum {
|
|
|
|
PRIV_VERSION_1_10_0 = 0,
|
|
|
|
PRIV_VERSION_1_11_0,
|
2022-03-03 19:54:36 +01:00
|
|
|
PRIV_VERSION_1_12_0,
|
2023-05-17 15:57:07 +02:00
|
|
|
|
|
|
|
PRIV_VERSION_LATEST = PRIV_VERSION_1_12_0,
|
2022-03-03 19:54:35 +01:00
|
|
|
};
|
2018-03-02 13:31:10 +01:00
|
|
|
|
2021-12-10 08:55:47 +01:00
|
|
|
#define VEXT_VERSION_1_00_0 0x00010000
|
2024-01-06 00:05:36 +01:00
|
|
|
#define VEXT_VER_1_00_0_STR "v1.0"
|
2020-07-01 17:24:50 +02:00
|
|
|
|
2020-10-14 12:17:28 +02:00
|
|
|
enum {
|
|
|
|
TRANSLATE_SUCCESS,
|
|
|
|
TRANSLATE_FAIL,
|
|
|
|
TRANSLATE_PMP_FAIL,
|
|
|
|
TRANSLATE_G_STAGE_FAIL
|
|
|
|
};
|
|
|
|
|
2023-04-12 13:43:10 +02:00
|
|
|
/* Extension context status */
|
|
|
|
typedef enum {
|
|
|
|
EXT_STATUS_DISABLED = 0,
|
|
|
|
EXT_STATUS_INITIAL,
|
|
|
|
EXT_STATUS_CLEAN,
|
|
|
|
EXT_STATUS_DIRTY,
|
|
|
|
} RISCVExtStatus;
|
|
|
|
|
2018-03-02 13:31:10 +01:00
|
|
|
#define MMU_USER_IDX 3
|
|
|
|
|
|
|
|
#define MAX_RISCV_PMPS (16)
|
|
|
|
|
2021-05-16 22:53:33 +02:00
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
2018-03-02 13:31:10 +01:00
|
|
|
#include "pmp.h"
|
2022-03-15 07:55:23 +01:00
|
|
|
#include "debug.h"
|
2021-05-16 22:53:33 +02:00
|
|
|
#endif
|
2018-03-02 13:31:10 +01:00
|
|
|
|
2021-12-10 08:56:51 +01:00
|
|
|
#define RV_VLEN_MAX 1024
|
2022-06-21 01:15:57 +02:00
|
|
|
#define RV_MAX_MHPMEVENTS 32
|
2022-06-21 01:15:56 +02:00
|
|
|
#define RV_MAX_MHPMCOUNTERS 32
|
2020-07-01 17:24:49 +02:00
|
|
|
|
2021-12-10 08:55:59 +01:00
|
|
|
FIELD(VTYPE, VLMUL, 0, 3)
|
|
|
|
FIELD(VTYPE, VSEW, 3, 3)
|
2021-12-10 08:56:00 +01:00
|
|
|
FIELD(VTYPE, VTA, 6, 1)
|
|
|
|
FIELD(VTYPE, VMA, 7, 1)
|
2021-12-10 08:55:59 +01:00
|
|
|
FIELD(VTYPE, VEDIV, 8, 2)
|
|
|
|
FIELD(VTYPE, RESERVED, 10, sizeof(target_ulong) * 8 - 11)
|
2020-07-01 17:24:52 +02:00
|
|
|
|
2022-06-21 01:15:57 +02:00
|
|
|
typedef struct PMUCTRState {
|
|
|
|
/* Current value of a counter */
|
|
|
|
target_ulong mhpmcounter_val;
|
2023-04-05 10:58:12 +02:00
|
|
|
/* Current value of a counter in RV32 */
|
2022-06-21 01:15:57 +02:00
|
|
|
target_ulong mhpmcounterh_val;
|
|
|
|
/* Snapshot values of counter */
|
|
|
|
target_ulong mhpmcounter_prev;
|
|
|
|
/* Snapshort value of a counter in RV32 */
|
|
|
|
target_ulong mhpmcounterh_prev;
|
|
|
|
bool started;
|
2022-08-25 00:16:57 +02:00
|
|
|
/* Value beyond UINT32_MAX/UINT64_MAX before overflow interrupt trigger */
|
|
|
|
target_ulong irq_overflow_left;
|
2022-06-21 01:15:57 +02:00
|
|
|
} PMUCTRState;
|
|
|
|
|
2022-02-07 13:35:58 +01:00
|
|
|
struct CPUArchState {
|
2018-03-02 13:31:10 +01:00
|
|
|
target_ulong gpr[32];
|
2022-01-06 22:00:56 +01:00
|
|
|
target_ulong gprh[32]; /* 64 top bits of the 128-bit registers */
|
2020-07-01 17:24:49 +02:00
|
|
|
|
|
|
|
/* vector coprocessor state. */
|
|
|
|
uint64_t vreg[32 * RV_VLEN_MAX / 64] QEMU_ALIGNED(16);
|
|
|
|
target_ulong vxrm;
|
|
|
|
target_ulong vxsat;
|
|
|
|
target_ulong vl;
|
|
|
|
target_ulong vstart;
|
|
|
|
target_ulong vtype;
|
2022-01-20 13:20:42 +01:00
|
|
|
bool vill;
|
2020-07-01 17:24:49 +02:00
|
|
|
|
2018-03-02 13:31:10 +01:00
|
|
|
target_ulong pc;
|
|
|
|
target_ulong load_res;
|
|
|
|
target_ulong load_val;
|
|
|
|
|
2022-12-17 18:06:21 +01:00
|
|
|
/* Floating-Point state */
|
|
|
|
uint64_t fpr[32]; /* assume both F and D extensions */
|
2018-03-02 13:31:10 +01:00
|
|
|
target_ulong frm;
|
2022-12-17 18:06:21 +01:00
|
|
|
float_status fp_status;
|
2018-03-02 13:31:10 +01:00
|
|
|
|
|
|
|
target_ulong badaddr;
|
2022-05-11 16:45:23 +02:00
|
|
|
target_ulong bins;
|
2021-12-20 07:49:16 +01:00
|
|
|
|
2020-02-01 02:02:56 +01:00
|
|
|
target_ulong guest_phys_fault_addr;
|
2018-03-02 13:31:10 +01:00
|
|
|
|
|
|
|
target_ulong priv_ver;
|
2020-07-01 17:24:50 +02:00
|
|
|
target_ulong vext_ver;
|
2021-10-20 05:16:57 +02:00
|
|
|
|
|
|
|
/* RISCVMXL, but uint32_t for vmstate migration */
|
|
|
|
uint32_t misa_mxl; /* current mxl */
|
|
|
|
uint32_t misa_ext; /* current extensions */
|
|
|
|
uint32_t misa_ext_mask; /* max ext for this cpu */
|
2022-01-20 13:20:32 +01:00
|
|
|
uint32_t xl; /* current xlen */
|
2018-03-02 13:31:10 +01:00
|
|
|
|
2022-01-06 22:01:04 +01:00
|
|
|
/* 128-bit helpers upper part return value */
|
|
|
|
target_ulong retxh;
|
|
|
|
|
2023-03-07 09:14:00 +01:00
|
|
|
target_ulong jvt;
|
|
|
|
|
2019-03-16 02:20:46 +01:00
|
|
|
#ifdef CONFIG_USER_ONLY
|
|
|
|
uint32_t elf_flags;
|
|
|
|
#endif
|
|
|
|
|
2018-03-02 13:31:10 +01:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
target_ulong priv;
|
2020-02-01 02:01:51 +01:00
|
|
|
/* This contains QEMU specific information about the virt state. */
|
2023-03-27 10:08:53 +02:00
|
|
|
bool virt_enabled;
|
2022-02-04 18:46:39 +01:00
|
|
|
target_ulong geilen;
|
2022-09-14 12:11:06 +02:00
|
|
|
uint64_t resetvec;
|
2018-03-02 13:31:10 +01:00
|
|
|
|
|
|
|
target_ulong mhartid;
|
2020-10-26 12:55:25 +01:00
|
|
|
/*
|
|
|
|
* For RV32 this is 32-bit mstatus and 32-bit mstatush.
|
|
|
|
* For RV64 this is a 64-bit mstatus.
|
|
|
|
*/
|
|
|
|
uint64_t mstatus;
|
2018-04-08 23:25:25 +02:00
|
|
|
|
2022-02-04 18:46:46 +01:00
|
|
|
uint64_t mip;
|
2022-03-17 07:18:17 +01:00
|
|
|
/*
|
|
|
|
* MIP contains the software writable version of SEIP ORed with the
|
|
|
|
* external interrupt value. The MIP register is always up-to-date.
|
|
|
|
* To keep track of the current source, we also save booleans of the values
|
|
|
|
* here.
|
|
|
|
*/
|
|
|
|
bool external_seip;
|
|
|
|
bool software_seip;
|
2020-02-01 02:02:12 +01:00
|
|
|
|
2022-02-04 18:46:46 +01:00
|
|
|
uint64_t miclaim;
|
2018-04-08 23:25:25 +02:00
|
|
|
|
2022-02-04 18:46:46 +01:00
|
|
|
uint64_t mie;
|
|
|
|
uint64_t mideleg;
|
2018-03-02 13:31:10 +01:00
|
|
|
|
2023-10-16 13:17:35 +02:00
|
|
|
/*
|
|
|
|
* When mideleg[i]=0 and mvien[i]=1, sie[i] is no more
|
2023-11-14 17:11:33 +01:00
|
|
|
* alias of mie[i] and needs to be maintained separately.
|
2023-10-16 13:17:35 +02:00
|
|
|
*/
|
|
|
|
uint64_t sie;
|
|
|
|
|
2023-10-16 13:17:36 +02:00
|
|
|
/*
|
|
|
|
* When hideleg[i]=0 and hvien[i]=1, vsie[i] is no more
|
2023-11-14 17:11:33 +01:00
|
|
|
* alias of sie[i] (mie[i]) and needs to be maintained separately.
|
2023-10-16 13:17:36 +02:00
|
|
|
*/
|
|
|
|
uint64_t vsie;
|
|
|
|
|
2018-03-02 13:31:10 +01:00
|
|
|
target_ulong satp; /* since: priv-1.10.0 */
|
2021-03-19 20:45:29 +01:00
|
|
|
target_ulong stval;
|
2018-03-02 13:31:10 +01:00
|
|
|
target_ulong medeleg;
|
|
|
|
|
|
|
|
target_ulong stvec;
|
|
|
|
target_ulong sepc;
|
|
|
|
target_ulong scause;
|
|
|
|
|
|
|
|
target_ulong mtvec;
|
|
|
|
target_ulong mepc;
|
|
|
|
target_ulong mcause;
|
|
|
|
target_ulong mtval; /* since: priv-1.10.0 */
|
|
|
|
|
2022-02-04 18:46:45 +01:00
|
|
|
/* Machine and Supervisor interrupt priorities */
|
|
|
|
uint8_t miprio[64];
|
|
|
|
uint8_t siprio[64];
|
|
|
|
|
2022-02-04 18:46:50 +01:00
|
|
|
/* AIA CSRs */
|
|
|
|
target_ulong miselect;
|
|
|
|
target_ulong siselect;
|
2023-10-16 13:17:35 +02:00
|
|
|
uint64_t mvien;
|
|
|
|
uint64_t mvip;
|
2022-02-04 18:46:50 +01:00
|
|
|
|
2020-02-01 02:01:43 +01:00
|
|
|
/* Hypervisor CSRs */
|
|
|
|
target_ulong hstatus;
|
|
|
|
target_ulong hedeleg;
|
2022-02-04 18:46:46 +01:00
|
|
|
uint64_t hideleg;
|
2020-02-01 02:01:43 +01:00
|
|
|
target_ulong hcounteren;
|
|
|
|
target_ulong htval;
|
|
|
|
target_ulong htinst;
|
|
|
|
target_ulong hgatp;
|
2022-02-04 18:46:39 +01:00
|
|
|
target_ulong hgeie;
|
|
|
|
target_ulong hgeip;
|
2020-02-02 14:42:16 +01:00
|
|
|
uint64_t htimedelta;
|
2023-10-16 13:17:36 +02:00
|
|
|
uint64_t hvien;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Bits VSSIP, VSTIP and VSEIP in hvip are maintained in mip. Other bits
|
|
|
|
* from 0:12 are reserved. Bits 13:63 are not aliased and must be separately
|
|
|
|
* maintain in hvip.
|
|
|
|
*/
|
|
|
|
uint64_t hvip;
|
2020-02-01 02:01:43 +01:00
|
|
|
|
2022-02-04 18:46:45 +01:00
|
|
|
/* Hypervisor controlled virtual interrupt priorities */
|
2022-02-04 18:46:47 +01:00
|
|
|
target_ulong hvictl;
|
2022-02-04 18:46:45 +01:00
|
|
|
uint8_t hviprio[64];
|
|
|
|
|
2022-01-06 22:01:05 +01:00
|
|
|
/* Upper 64-bits of 128-bit CSRs */
|
|
|
|
uint64_t mscratchh;
|
|
|
|
uint64_t sscratchh;
|
|
|
|
|
2020-02-01 02:01:43 +01:00
|
|
|
/* Virtual CSRs */
|
2020-10-26 12:55:25 +01:00
|
|
|
/*
|
|
|
|
* For RV32 this is 32-bit vsstatus and 32-bit vsstatush.
|
|
|
|
* For RV64 this is a 64-bit vsstatus.
|
|
|
|
*/
|
|
|
|
uint64_t vsstatus;
|
2020-02-01 02:01:43 +01:00
|
|
|
target_ulong vstvec;
|
|
|
|
target_ulong vsscratch;
|
|
|
|
target_ulong vsepc;
|
|
|
|
target_ulong vscause;
|
|
|
|
target_ulong vstval;
|
|
|
|
target_ulong vsatp;
|
|
|
|
|
2022-02-04 18:46:50 +01:00
|
|
|
/* AIA VS-mode CSRs */
|
|
|
|
target_ulong vsiselect;
|
|
|
|
|
2020-02-01 02:01:43 +01:00
|
|
|
target_ulong mtval2;
|
|
|
|
target_ulong mtinst;
|
|
|
|
|
2020-02-01 02:02:12 +01:00
|
|
|
/* HS Backup CSRs */
|
|
|
|
target_ulong stvec_hs;
|
|
|
|
target_ulong sscratch_hs;
|
|
|
|
target_ulong sepc_hs;
|
|
|
|
target_ulong scause_hs;
|
|
|
|
target_ulong stval_hs;
|
|
|
|
target_ulong satp_hs;
|
2020-10-26 12:55:25 +01:00
|
|
|
uint64_t mstatus_hs;
|
2020-02-01 02:02:12 +01:00
|
|
|
|
2023-04-05 10:58:12 +02:00
|
|
|
/*
|
|
|
|
* Signals whether the current exception occurred with two-stage address
|
|
|
|
* translation active.
|
|
|
|
*/
|
2021-03-19 15:14:59 +01:00
|
|
|
bool two_stage_lookup;
|
2022-06-30 08:11:49 +02:00
|
|
|
/*
|
|
|
|
* Signals whether the current exception occurred while doing two-stage
|
|
|
|
* address translation for the VS-stage page table walk.
|
|
|
|
*/
|
|
|
|
bool two_stage_indirect_lookup;
|
2021-03-19 15:14:59 +01:00
|
|
|
|
2018-04-09 01:33:05 +02:00
|
|
|
target_ulong scounteren;
|
|
|
|
target_ulong mcounteren;
|
2018-03-02 13:31:10 +01:00
|
|
|
|
2022-06-21 01:15:55 +02:00
|
|
|
target_ulong mcountinhibit;
|
|
|
|
|
2022-06-21 01:15:57 +02:00
|
|
|
/* PMU counter state */
|
|
|
|
PMUCTRState pmu_ctrs[RV_MAX_MHPMCOUNTERS];
|
2022-06-21 01:15:56 +02:00
|
|
|
|
2023-04-05 10:58:12 +02:00
|
|
|
/* PMU event selector configured values. First three are unused */
|
2022-06-21 01:15:56 +02:00
|
|
|
target_ulong mhpmevent_val[RV_MAX_MHPMEVENTS];
|
|
|
|
|
2023-04-05 10:58:12 +02:00
|
|
|
/* PMU event selector configured values for RV32 */
|
2022-08-25 00:16:57 +02:00
|
|
|
target_ulong mhpmeventh_val[RV_MAX_MHPMEVENTS];
|
|
|
|
|
2018-03-02 13:31:10 +01:00
|
|
|
target_ulong sscratch;
|
|
|
|
target_ulong mscratch;
|
|
|
|
|
2022-08-25 00:13:56 +02:00
|
|
|
/* Sstc CSRs */
|
|
|
|
uint64_t stimecmp;
|
|
|
|
|
2022-08-25 00:13:57 +02:00
|
|
|
uint64_t vstimecmp;
|
|
|
|
|
2018-03-02 13:31:10 +01:00
|
|
|
/* physical memory protection */
|
|
|
|
pmp_table_t pmp_state;
|
2021-04-19 08:16:53 +02:00
|
|
|
target_ulong mseccfg;
|
2019-03-15 11:26:58 +01:00
|
|
|
|
2022-03-15 07:55:23 +01:00
|
|
|
/* trigger module */
|
|
|
|
target_ulong trigger_cur;
|
2022-09-09 15:42:10 +02:00
|
|
|
target_ulong tdata1[RV_MAX_TRIGGERS];
|
|
|
|
target_ulong tdata2[RV_MAX_TRIGGERS];
|
|
|
|
target_ulong tdata3[RV_MAX_TRIGGERS];
|
2023-12-19 13:32:44 +01:00
|
|
|
target_ulong mcontext;
|
2022-09-09 15:42:10 +02:00
|
|
|
struct CPUBreakpoint *cpu_breakpoint[RV_MAX_TRIGGERS];
|
|
|
|
struct CPUWatchpoint *cpu_watchpoint[RV_MAX_TRIGGERS];
|
2022-10-13 08:29:44 +02:00
|
|
|
QEMUTimer *itrigger_timer[RV_MAX_TRIGGERS];
|
|
|
|
int64_t last_icount;
|
2022-10-13 08:29:46 +02:00
|
|
|
bool itrigger_enabled;
|
2022-03-15 07:55:23 +01:00
|
|
|
|
2020-02-02 14:42:16 +01:00
|
|
|
/* machine specific rdtime callback */
|
2022-04-20 10:08:59 +02:00
|
|
|
uint64_t (*rdtime_fn)(void *);
|
|
|
|
void *rdtime_fn_arg;
|
2020-02-02 14:42:16 +01:00
|
|
|
|
2022-02-04 18:46:44 +01:00
|
|
|
/* machine specific AIA ireg read-modify-write callback */
|
|
|
|
#define AIA_MAKE_IREG(__isel, __priv, __virt, __vgein, __xlen) \
|
|
|
|
((((__xlen) & 0xff) << 24) | \
|
|
|
|
(((__vgein) & 0x3f) << 20) | \
|
|
|
|
(((__virt) & 0x1) << 18) | \
|
|
|
|
(((__priv) & 0x3) << 16) | \
|
|
|
|
(__isel & 0xffff))
|
|
|
|
#define AIA_IREG_ISEL(__ireg) ((__ireg) & 0xffff)
|
|
|
|
#define AIA_IREG_PRIV(__ireg) (((__ireg) >> 16) & 0x3)
|
|
|
|
#define AIA_IREG_VIRT(__ireg) (((__ireg) >> 18) & 0x1)
|
|
|
|
#define AIA_IREG_VGEIN(__ireg) (((__ireg) >> 20) & 0x3f)
|
|
|
|
#define AIA_IREG_XLEN(__ireg) (((__ireg) >> 24) & 0xff)
|
|
|
|
int (*aia_ireg_rmw_fn[4])(void *arg, target_ulong reg,
|
|
|
|
target_ulong *val, target_ulong new_val, target_ulong write_mask);
|
|
|
|
void *aia_ireg_rmw_fn_arg[4];
|
|
|
|
|
2019-03-15 11:26:58 +01:00
|
|
|
/* True if in debugger mode. */
|
|
|
|
bool debugger;
|
2021-10-25 19:36:04 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* CSRs for PointerMasking extension
|
|
|
|
*/
|
|
|
|
target_ulong mmte;
|
|
|
|
target_ulong mpmmask;
|
|
|
|
target_ulong mpmbase;
|
|
|
|
target_ulong spmmask;
|
|
|
|
target_ulong spmbase;
|
|
|
|
target_ulong upmmask;
|
|
|
|
target_ulong upmbase;
|
2022-03-03 19:54:39 +01:00
|
|
|
|
2023-07-14 13:19:10 +02:00
|
|
|
/* CSRs for execution environment configuration */
|
2022-03-03 19:54:39 +01:00
|
|
|
uint64_t menvcfg;
|
2022-10-16 14:47:22 +02:00
|
|
|
uint64_t mstateen[SMSTATEEN_MAX_COUNT];
|
|
|
|
uint64_t hstateen[SMSTATEEN_MAX_COUNT];
|
|
|
|
uint64_t sstateen[SMSTATEEN_MAX_COUNT];
|
2022-03-03 19:54:39 +01:00
|
|
|
target_ulong senvcfg;
|
|
|
|
uint64_t henvcfg;
|
2018-03-02 13:31:10 +01:00
|
|
|
#endif
|
2022-01-20 13:20:38 +01:00
|
|
|
target_ulong cur_pmmask;
|
|
|
|
target_ulong cur_pmbase;
|
2018-03-02 13:31:10 +01:00
|
|
|
|
|
|
|
/* Fields from here on are preserved across CPU reset. */
|
2022-08-25 00:13:56 +02:00
|
|
|
QEMUTimer *stimer; /* Internal timer for S-mode interrupt */
|
2022-08-25 00:13:57 +02:00
|
|
|
QEMUTimer *vstimer; /* Internal timer for VS-mode interrupt */
|
|
|
|
bool vstime_irq;
|
2022-01-12 09:13:22 +01:00
|
|
|
|
|
|
|
hwaddr kernel_addr;
|
|
|
|
hwaddr fdt_addr;
|
2022-01-12 09:13:26 +01:00
|
|
|
|
2023-04-04 11:15:05 +02:00
|
|
|
#ifdef CONFIG_KVM
|
2022-01-12 09:13:26 +01:00
|
|
|
/* kvm timer */
|
|
|
|
bool kvm_timer_dirty;
|
|
|
|
uint64_t kvm_timer_time;
|
|
|
|
uint64_t kvm_timer_compare;
|
|
|
|
uint64_t kvm_timer_state;
|
|
|
|
uint64_t kvm_timer_frequency;
|
2023-04-04 11:15:05 +02:00
|
|
|
#endif /* CONFIG_KVM */
|
2018-03-02 13:31:10 +01:00
|
|
|
};
|
|
|
|
|
2023-04-05 10:58:12 +02:00
|
|
|
/*
|
2018-03-02 13:31:10 +01:00
|
|
|
* RISCVCPU:
|
|
|
|
* @env: #CPURISCVState
|
|
|
|
*
|
|
|
|
* A RISCV CPU.
|
|
|
|
*/
|
2022-02-14 17:15:16 +01:00
|
|
|
struct ArchCPU {
|
2018-03-02 13:31:10 +01:00
|
|
|
CPUState parent_obj;
|
2023-09-13 02:47:56 +02:00
|
|
|
|
2018-03-02 13:31:10 +01:00
|
|
|
CPURISCVState env;
|
2019-04-20 04:24:01 +02:00
|
|
|
|
2021-01-16 06:41:22 +01:00
|
|
|
char *dyn_csr_xml;
|
2021-12-10 08:56:54 +01:00
|
|
|
char *dyn_vreg_xml;
|
2021-01-16 06:41:22 +01:00
|
|
|
|
2019-04-20 04:24:01 +02:00
|
|
|
/* Configuration Settings */
|
2022-02-02 01:52:43 +01:00
|
|
|
RISCVCPUConfig cfg;
|
2022-08-25 00:16:57 +02:00
|
|
|
|
|
|
|
QEMUTimer *pmu_timer;
|
|
|
|
/* A bitmask of Available programmable counters */
|
|
|
|
uint32_t pmu_avail_ctrs;
|
|
|
|
/* Mapping of events to counters */
|
|
|
|
GHashTable *pmu_event_ctr_map;
|
2020-09-03 22:43:22 +02:00
|
|
|
};
|
2018-03-02 13:31:10 +01:00
|
|
|
|
2023-10-13 11:35:04 +02:00
|
|
|
/**
|
|
|
|
* RISCVCPUClass:
|
|
|
|
* @parent_realize: The parent class' realize handler.
|
|
|
|
* @parent_phases: The parent class' reset phase handlers.
|
|
|
|
*
|
|
|
|
* A RISCV CPU model.
|
|
|
|
*/
|
|
|
|
struct RISCVCPUClass {
|
|
|
|
CPUClass parent_class;
|
|
|
|
|
|
|
|
DeviceRealize parent_realize;
|
|
|
|
ResettablePhases parent_phases;
|
2024-02-03 11:11:09 +01:00
|
|
|
uint32_t misa_mxl_max; /* max mxl for this cpu */
|
2023-10-13 11:35:04 +02:00
|
|
|
};
|
|
|
|
|
2018-03-02 13:31:10 +01:00
|
|
|
static inline int riscv_has_ext(CPURISCVState *env, target_ulong ext)
|
|
|
|
{
|
2021-10-20 05:16:57 +02:00
|
|
|
return (env->misa_ext & ext) != 0;
|
2018-03-02 13:31:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "cpu_user.h"
|
|
|
|
|
|
|
|
extern const char * const riscv_int_regnames[];
|
2022-01-06 22:00:56 +01:00
|
|
|
extern const char * const riscv_int_regnamesh[];
|
2018-03-02 13:31:10 +01:00
|
|
|
extern const char * const riscv_fpr_regnames[];
|
|
|
|
|
2020-08-14 05:58:19 +02:00
|
|
|
const char *riscv_cpu_get_trap_name(target_ulong cause, bool async);
|
2018-03-02 13:31:10 +01:00
|
|
|
void riscv_cpu_do_interrupt(CPUState *cpu);
|
2021-02-01 13:44:58 +01:00
|
|
|
int riscv_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs,
|
2022-08-11 14:10:54 +02:00
|
|
|
int cpuid, DumpState *s);
|
2021-02-01 13:44:58 +01:00
|
|
|
int riscv_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs,
|
2022-08-11 14:10:54 +02:00
|
|
|
int cpuid, DumpState *s);
|
2020-03-16 18:21:41 +01:00
|
|
|
int riscv_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg);
|
2018-03-02 13:31:10 +01:00
|
|
|
int riscv_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
|
2022-02-04 18:46:45 +01:00
|
|
|
int riscv_cpu_hviprio_index2irq(int index, int *out_irq, int *out_rdzero);
|
|
|
|
uint8_t riscv_cpu_default_priority(int irq);
|
2022-05-31 23:05:44 +02:00
|
|
|
uint64_t riscv_cpu_all_pending(CPURISCVState *env);
|
2022-02-04 18:46:45 +01:00
|
|
|
int riscv_cpu_mirq_pending(CPURISCVState *env);
|
|
|
|
int riscv_cpu_sirq_pending(CPURISCVState *env);
|
|
|
|
int riscv_cpu_vsirq_pending(CPURISCVState *env);
|
2019-07-31 01:35:24 +02:00
|
|
|
bool riscv_cpu_fp_enabled(CPURISCVState *env);
|
2022-02-04 18:46:39 +01:00
|
|
|
target_ulong riscv_cpu_get_geilen(CPURISCVState *env);
|
|
|
|
void riscv_cpu_set_geilen(CPURISCVState *env, target_ulong geilen);
|
2021-12-10 08:55:49 +01:00
|
|
|
bool riscv_cpu_vector_enabled(CPURISCVState *env);
|
2020-02-01 02:01:51 +01:00
|
|
|
void riscv_cpu_set_virt_enabled(CPURISCVState *env, bool enable);
|
2024-01-29 01:28:02 +01:00
|
|
|
int riscv_env_mmu_index(CPURISCVState *env, bool ifetch);
|
2022-04-20 15:26:02 +02:00
|
|
|
G_NORETURN void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr,
|
2023-04-05 10:58:13 +02:00
|
|
|
MMUAccessType access_type,
|
|
|
|
int mmu_idx, uintptr_t retaddr);
|
2019-04-02 12:12:38 +02:00
|
|
|
bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
|
|
|
|
MMUAccessType access_type, int mmu_idx,
|
|
|
|
bool probe, uintptr_t retaddr);
|
2018-03-02 13:31:10 +01:00
|
|
|
char *riscv_isa_string(RISCVCPU *cpu);
|
2024-01-24 13:55:49 +01:00
|
|
|
int riscv_cpu_max_xlen(RISCVCPUClass *mcc);
|
2024-01-12 15:01:54 +01:00
|
|
|
bool riscv_cpu_option_set(const char *optname);
|
2018-03-02 13:31:10 +01:00
|
|
|
|
2018-04-08 23:25:25 +02:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
target/riscv: support new isa extension detection devicetree properties
A few months ago I submitted a patch to various lists, deprecating
"riscv,isa" with a lengthy commit message [0] that is now commit
aeb71e42caae ("dt-bindings: riscv: deprecate riscv,isa") in the Linux
kernel tree. Primarily, the goal was to replace "riscv,isa" with a new
set of properties that allowed for strictly defining the meaning of
various extensions, where "riscv,isa" was tied to whatever definitions
inflicted upon us by the ISA manual, which have seen some variance over
time.
Two new properties were introduced: "riscv,isa-base" and
"riscv,isa-extensions". The former is a simple string to communicate the
base ISA implemented by a hart and the latter an array of strings used
to communicate the set of ISA extensions supported, per the definitions
of each substring in extensions.yaml [1]. A beneficial side effect was
also the ability to define vendor extensions in a more "official" way,
as the ISA manual and other RVI specifications only covered the format
for vendor extensions in the ISA string, but not the meaning of vendor
extensions, for obvious reasons.
Add support for setting these two new properties in the devicetrees for
the various devicetree platforms supported by QEMU for RISC-V. The Linux
kernel already supports parsing ISA extensions from these new
properties, and documenting them in the dt-binding is a requirement for
new extension detection being added to the kernel.
A side effect of the implementation is that the meaning for elements in
"riscv,isa" and in "riscv,isa-extensions" are now tied together as they
are constructed from the same source. The same applies to the ISA string
provided in ACPI tables, but there does not appear to be any strict
definitions of meanings in ACPI land either.
Link: https://lore.kernel.org/qemu-riscv/20230702-eats-scorebook-c951f170d29f@spud/ [0]
Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/riscv/extensions.yaml [1]
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Signed-off-by: Conor Dooley <conor.dooley@microchip.com>
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Message-ID: <20240124-unvarying-foothold-9dde2aaf95d4@spud>
[ Changes by AF:
- Rebase on recent changes
]
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2024-01-24 13:55:50 +01:00
|
|
|
void riscv_isa_write_fdt(RISCVCPU *cpu, void *fdt, char *nodename);
|
2022-12-16 12:08:50 +01:00
|
|
|
void riscv_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr,
|
|
|
|
vaddr addr, unsigned size,
|
|
|
|
MMUAccessType access_type,
|
|
|
|
int mmu_idx, MemTxAttrs attrs,
|
|
|
|
MemTxResult response, uintptr_t retaddr);
|
2022-12-06 16:20:51 +01:00
|
|
|
hwaddr riscv_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
|
2021-09-11 18:54:28 +02:00
|
|
|
bool riscv_cpu_exec_interrupt(CPUState *cs, int interrupt_request);
|
2020-02-01 02:02:12 +01:00
|
|
|
void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env);
|
2022-02-04 18:46:46 +01:00
|
|
|
int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint64_t interrupts);
|
2023-03-09 08:13:28 +01:00
|
|
|
uint64_t riscv_cpu_update_mip(CPURISCVState *env, uint64_t mask,
|
|
|
|
uint64_t value);
|
2023-10-16 13:17:34 +02:00
|
|
|
void riscv_cpu_interrupt(CPURISCVState *env);
|
2018-04-08 23:25:25 +02:00
|
|
|
#define BOOL_TO_MASK(x) (-!!(x)) /* helper for riscv_cpu_update_mip value */
|
2022-04-20 10:08:59 +02:00
|
|
|
void riscv_cpu_set_rdtime_fn(CPURISCVState *env, uint64_t (*fn)(void *),
|
|
|
|
void *arg);
|
2022-02-04 18:46:44 +01:00
|
|
|
void riscv_cpu_set_aia_ireg_rmw_fn(CPURISCVState *env, uint32_t priv,
|
|
|
|
int (*rmw_fn)(void *arg,
|
|
|
|
target_ulong reg,
|
|
|
|
target_ulong *val,
|
|
|
|
target_ulong new_val,
|
|
|
|
target_ulong write_mask),
|
|
|
|
void *rmw_fn_arg);
|
2023-03-07 09:14:00 +01:00
|
|
|
|
|
|
|
RISCVException smstateen_acc_ok(CPURISCVState *env, int index, uint64_t bit);
|
2018-04-08 23:25:25 +02:00
|
|
|
#endif
|
2019-01-15 00:58:23 +01:00
|
|
|
void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv);
|
2018-03-02 13:31:10 +01:00
|
|
|
|
|
|
|
void riscv_translate_init(void);
|
2022-04-20 15:26:02 +02:00
|
|
|
G_NORETURN void riscv_raise_exception(CPURISCVState *env,
|
|
|
|
uint32_t exception, uintptr_t pc);
|
2018-03-02 13:31:10 +01:00
|
|
|
|
2019-01-15 00:58:23 +01:00
|
|
|
target_ulong riscv_cpu_get_fflags(CPURISCVState *env);
|
|
|
|
void riscv_cpu_set_fflags(CPURISCVState *env, target_ulong);
|
2018-03-02 13:31:10 +01:00
|
|
|
|
2020-07-01 17:24:52 +02:00
|
|
|
#include "exec/cpu-all.h"
|
|
|
|
|
2021-10-15 09:45:02 +02:00
|
|
|
FIELD(TB_FLAGS, MEM_IDX, 0, 3)
|
2023-04-12 13:43:11 +02:00
|
|
|
FIELD(TB_FLAGS, FS, 3, 2)
|
|
|
|
/* Vector flags */
|
|
|
|
FIELD(TB_FLAGS, VS, 5, 2)
|
|
|
|
FIELD(TB_FLAGS, LMUL, 7, 3)
|
|
|
|
FIELD(TB_FLAGS, SEW, 10, 3)
|
|
|
|
FIELD(TB_FLAGS, VL_EQ_VLMAX, 13, 1)
|
|
|
|
FIELD(TB_FLAGS, VILL, 14, 1)
|
2023-04-12 13:43:18 +02:00
|
|
|
FIELD(TB_FLAGS, VSTART_EQ_ZERO, 15, 1)
|
2021-10-20 05:16:59 +02:00
|
|
|
/* The combination of MXL/SXL/UXL that applies to the current cpu mode. */
|
2023-04-12 13:43:12 +02:00
|
|
|
FIELD(TB_FLAGS, XL, 16, 2)
|
2021-10-25 19:36:08 +02:00
|
|
|
/* If PointerMasking should be applied */
|
2023-04-12 13:43:12 +02:00
|
|
|
FIELD(TB_FLAGS, PM_MASK_ENABLED, 18, 1)
|
|
|
|
FIELD(TB_FLAGS, PM_BASE_ENABLED, 19, 1)
|
|
|
|
FIELD(TB_FLAGS, VTA, 20, 1)
|
|
|
|
FIELD(TB_FLAGS, VMA, 21, 1)
|
2022-10-13 08:29:43 +02:00
|
|
|
/* Native debug itrigger */
|
2023-04-12 13:43:12 +02:00
|
|
|
FIELD(TB_FLAGS, ITRIGGER, 22, 1)
|
2023-04-12 13:43:09 +02:00
|
|
|
/* Virtual mode enabled */
|
2023-04-12 13:43:12 +02:00
|
|
|
FIELD(TB_FLAGS, VIRT_ENABLED, 23, 1)
|
2023-04-12 13:43:18 +02:00
|
|
|
FIELD(TB_FLAGS, PRIV, 24, 2)
|
2023-06-14 05:25:46 +02:00
|
|
|
FIELD(TB_FLAGS, AXL, 26, 2)
|
2020-07-01 17:24:52 +02:00
|
|
|
|
2021-10-20 05:16:58 +02:00
|
|
|
#ifdef TARGET_RISCV32
|
|
|
|
#define riscv_cpu_mxl(env) ((void)(env), MXL_RV32)
|
|
|
|
#else
|
|
|
|
static inline RISCVMXL riscv_cpu_mxl(CPURISCVState *env)
|
|
|
|
{
|
|
|
|
return env->misa_mxl;
|
|
|
|
}
|
|
|
|
#endif
|
2022-02-04 18:46:47 +01:00
|
|
|
#define riscv_cpu_mxl_bits(env) (1UL << (4 + riscv_cpu_mxl(env)))
|
2020-12-16 19:22:51 +01:00
|
|
|
|
2023-02-22 19:51:56 +01:00
|
|
|
static inline const RISCVCPUConfig *riscv_cpu_cfg(CPURISCVState *env)
|
|
|
|
{
|
|
|
|
return &env_archcpu(env)->cfg;
|
|
|
|
}
|
|
|
|
|
2023-06-14 05:25:46 +02:00
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
|
|
|
static inline int cpu_address_mode(CPURISCVState *env)
|
|
|
|
{
|
|
|
|
int mode = env->priv;
|
|
|
|
|
|
|
|
if (mode == PRV_M && get_field(env->mstatus, MSTATUS_MPRV)) {
|
|
|
|
mode = get_field(env->mstatus, MSTATUS_MPP);
|
|
|
|
}
|
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline RISCVMXL cpu_get_xl(CPURISCVState *env, target_ulong mode)
|
2022-01-20 13:20:32 +01:00
|
|
|
{
|
|
|
|
RISCVMXL xl = env->misa_mxl;
|
|
|
|
/*
|
|
|
|
* When emulating a 32-bit-only cpu, use RV32.
|
|
|
|
* When emulating a 64-bit cpu, and MXL has been reduced to RV32,
|
|
|
|
* MSTATUSH doesn't have UXL/SXL, therefore XLEN cannot be widened
|
|
|
|
* back to RV64 for lower privs.
|
|
|
|
*/
|
|
|
|
if (xl != MXL_RV32) {
|
2023-06-14 05:25:46 +02:00
|
|
|
switch (mode) {
|
2022-01-20 13:20:32 +01:00
|
|
|
case PRV_M:
|
|
|
|
break;
|
|
|
|
case PRV_U:
|
|
|
|
xl = get_field(env->mstatus, MSTATUS64_UXL);
|
|
|
|
break;
|
2023-04-07 03:47:42 +02:00
|
|
|
default: /* PRV_S */
|
2022-01-20 13:20:32 +01:00
|
|
|
xl = get_field(env->mstatus, MSTATUS64_SXL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return xl;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-06-14 05:25:46 +02:00
|
|
|
#if defined(TARGET_RISCV32)
|
|
|
|
#define cpu_recompute_xl(env) ((void)(env), MXL_RV32)
|
|
|
|
#else
|
|
|
|
static inline RISCVMXL cpu_recompute_xl(CPURISCVState *env)
|
|
|
|
{
|
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
|
|
|
return cpu_get_xl(env, env->priv);
|
|
|
|
#else
|
|
|
|
return env->misa_mxl;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(TARGET_RISCV32)
|
|
|
|
#define cpu_address_xl(env) ((void)(env), MXL_RV32)
|
|
|
|
#else
|
|
|
|
static inline RISCVMXL cpu_address_xl(CPURISCVState *env)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_USER_ONLY
|
|
|
|
return env->xl;
|
|
|
|
#else
|
|
|
|
int mode = cpu_address_mode(env);
|
|
|
|
|
|
|
|
return cpu_get_xl(env, mode);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-01-20 13:20:43 +01:00
|
|
|
static inline int riscv_cpu_xlen(CPURISCVState *env)
|
|
|
|
{
|
|
|
|
return 16 << env->xl;
|
|
|
|
}
|
|
|
|
|
2022-02-04 03:26:54 +01:00
|
|
|
#ifdef TARGET_RISCV32
|
|
|
|
#define riscv_cpu_sxl(env) ((void)(env), MXL_RV32)
|
|
|
|
#else
|
|
|
|
static inline RISCVMXL riscv_cpu_sxl(CPURISCVState *env)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_USER_ONLY
|
|
|
|
return env->misa_mxl;
|
|
|
|
#else
|
|
|
|
return get_field(env->mstatus, MSTATUS64_SXL);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-07-01 17:24:52 +02:00
|
|
|
/*
|
2021-12-10 08:56:12 +01:00
|
|
|
* Encode LMUL to lmul as follows:
|
|
|
|
* LMUL vlmul lmul
|
|
|
|
* 1 000 0
|
|
|
|
* 2 001 1
|
|
|
|
* 4 010 2
|
|
|
|
* 8 011 3
|
|
|
|
* - 100 -
|
|
|
|
* 1/8 101 -3
|
|
|
|
* 1/4 110 -2
|
|
|
|
* 1/2 111 -1
|
|
|
|
*
|
|
|
|
* then, we can calculate VLMAX = vlen >> (vsew + 3 - lmul)
|
|
|
|
* e.g. vlen = 256 bits, SEW = 16, LMUL = 1/8
|
|
|
|
* => VLMAX = vlen >> (1 + 3 - (-3))
|
|
|
|
* = 256 >> 7
|
|
|
|
* = 2
|
2020-07-01 17:24:52 +02:00
|
|
|
*/
|
2024-01-22 17:11:05 +01:00
|
|
|
static inline uint32_t vext_get_vlmax(uint32_t vlenb, uint32_t vsew,
|
|
|
|
int8_t lmul)
|
2020-07-01 17:24:52 +02:00
|
|
|
{
|
2024-01-22 17:11:05 +01:00
|
|
|
uint32_t vlen = vlenb << 3;
|
2024-01-22 17:11:04 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We need to use 'vlen' instead of 'vlenb' to
|
|
|
|
* preserve the '+ 3' in the formula. Otherwise
|
|
|
|
* we risk a negative shift if vsew < lmul.
|
|
|
|
*/
|
|
|
|
return vlen >> (vsew + 3 - lmul);
|
2020-07-01 17:24:52 +02:00
|
|
|
}
|
|
|
|
|
2023-06-21 15:56:24 +02:00
|
|
|
void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
|
|
|
|
uint64_t *cs_base, uint32_t *pflags);
|
2018-03-02 13:31:10 +01:00
|
|
|
|
2022-01-20 13:20:38 +01:00
|
|
|
void riscv_cpu_update_mask(CPURISCVState *env);
|
2023-12-18 13:53:30 +01:00
|
|
|
bool riscv_cpu_is_32bit(RISCVCPU *cpu);
|
2022-01-20 13:20:38 +01:00
|
|
|
|
2021-04-01 17:18:07 +02:00
|
|
|
RISCVException riscv_csrrw(CPURISCVState *env, int csrno,
|
|
|
|
target_ulong *ret_value,
|
|
|
|
target_ulong new_value, target_ulong write_mask);
|
|
|
|
RISCVException riscv_csrrw_debug(CPURISCVState *env, int csrno,
|
|
|
|
target_ulong *ret_value,
|
|
|
|
target_ulong new_value,
|
|
|
|
target_ulong write_mask);
|
2019-01-05 00:23:55 +01:00
|
|
|
|
2019-01-15 00:58:23 +01:00
|
|
|
static inline void riscv_csr_write(CPURISCVState *env, int csrno,
|
|
|
|
target_ulong val)
|
2019-01-05 00:23:55 +01:00
|
|
|
{
|
|
|
|
riscv_csrrw(env, csrno, NULL, val, MAKE_64BIT_MASK(0, TARGET_LONG_BITS));
|
|
|
|
}
|
|
|
|
|
2019-01-15 00:58:23 +01:00
|
|
|
static inline target_ulong riscv_csr_read(CPURISCVState *env, int csrno)
|
2019-01-05 00:23:55 +01:00
|
|
|
{
|
|
|
|
target_ulong val = 0;
|
|
|
|
riscv_csrrw(env, csrno, &val, 0, 0);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2021-04-01 17:17:39 +02:00
|
|
|
typedef RISCVException (*riscv_csr_predicate_fn)(CPURISCVState *env,
|
|
|
|
int csrno);
|
2021-04-01 17:17:57 +02:00
|
|
|
typedef RISCVException (*riscv_csr_read_fn)(CPURISCVState *env, int csrno,
|
|
|
|
target_ulong *ret_value);
|
|
|
|
typedef RISCVException (*riscv_csr_write_fn)(CPURISCVState *env, int csrno,
|
|
|
|
target_ulong new_value);
|
|
|
|
typedef RISCVException (*riscv_csr_op_fn)(CPURISCVState *env, int csrno,
|
|
|
|
target_ulong *ret_value,
|
|
|
|
target_ulong new_value,
|
|
|
|
target_ulong write_mask);
|
2019-01-05 00:23:55 +01:00
|
|
|
|
2022-01-06 22:01:06 +01:00
|
|
|
RISCVException riscv_csrrw_i128(CPURISCVState *env, int csrno,
|
|
|
|
Int128 *ret_value,
|
|
|
|
Int128 new_value, Int128 write_mask);
|
|
|
|
|
2022-01-06 22:01:08 +01:00
|
|
|
typedef RISCVException (*riscv_csr_read128_fn)(CPURISCVState *env, int csrno,
|
|
|
|
Int128 *ret_value);
|
|
|
|
typedef RISCVException (*riscv_csr_write128_fn)(CPURISCVState *env, int csrno,
|
|
|
|
Int128 new_value);
|
|
|
|
|
2019-01-05 00:23:55 +01:00
|
|
|
typedef struct {
|
2021-01-12 05:52:02 +01:00
|
|
|
const char *name;
|
2019-01-05 00:24:14 +01:00
|
|
|
riscv_csr_predicate_fn predicate;
|
2019-01-05 00:23:55 +01:00
|
|
|
riscv_csr_read_fn read;
|
|
|
|
riscv_csr_write_fn write;
|
|
|
|
riscv_csr_op_fn op;
|
2022-01-06 22:01:08 +01:00
|
|
|
riscv_csr_read128_fn read128;
|
|
|
|
riscv_csr_write128_fn write128;
|
2022-03-03 19:54:37 +01:00
|
|
|
/* The default priv spec version should be PRIV_VERSION_1_10_0 (i.e 0) */
|
|
|
|
uint32_t min_priv_ver;
|
2019-01-05 00:23:55 +01:00
|
|
|
} riscv_csr_operations;
|
|
|
|
|
2021-01-12 05:52:01 +01:00
|
|
|
/* CSR function table constants */
|
|
|
|
enum {
|
|
|
|
CSR_TABLE_SIZE = 0x1000
|
|
|
|
};
|
|
|
|
|
2023-04-05 10:58:12 +02:00
|
|
|
/*
|
2022-08-25 00:16:57 +02:00
|
|
|
* The event id are encoded based on the encoding specified in the
|
|
|
|
* SBI specification v0.3
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum riscv_pmu_event_idx {
|
|
|
|
RISCV_PMU_EVENT_HW_CPU_CYCLES = 0x01,
|
|
|
|
RISCV_PMU_EVENT_HW_INSTRUCTIONS = 0x02,
|
|
|
|
RISCV_PMU_EVENT_CACHE_DTLB_READ_MISS = 0x10019,
|
|
|
|
RISCV_PMU_EVENT_CACHE_DTLB_WRITE_MISS = 0x1001B,
|
|
|
|
RISCV_PMU_EVENT_CACHE_ITLB_PREFETCH_MISS = 0x10021,
|
|
|
|
};
|
|
|
|
|
2023-09-25 19:56:53 +02:00
|
|
|
/* used by tcg/tcg-cpu.c*/
|
|
|
|
void isa_ext_update_enabled(RISCVCPU *cpu, uint32_t ext_offset, bool en);
|
|
|
|
bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset);
|
2024-02-03 11:11:09 +01:00
|
|
|
void riscv_cpu_set_misa_ext(CPURISCVState *env, uint32_t ext);
|
2024-01-06 00:05:31 +01:00
|
|
|
bool riscv_cpu_is_vendor(Object *cpu_obj);
|
2023-09-25 19:56:53 +02:00
|
|
|
|
2023-09-25 19:56:58 +02:00
|
|
|
typedef struct RISCVCPUMultiExtConfig {
|
|
|
|
const char *name;
|
|
|
|
uint32_t offset;
|
|
|
|
bool enabled;
|
|
|
|
} RISCVCPUMultiExtConfig;
|
|
|
|
|
|
|
|
extern const RISCVCPUMultiExtConfig riscv_cpu_extensions[];
|
|
|
|
extern const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[];
|
|
|
|
extern const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[];
|
2023-12-18 13:53:14 +01:00
|
|
|
extern const RISCVCPUMultiExtConfig riscv_cpu_named_features[];
|
target/riscv: deprecate capital 'Z' CPU properties
At this moment there are eleven CPU extension properties that starts
with capital 'Z': Zifencei, Zicsr, Zihintntl, Zihintpause, Zawrs, Zfa,
Zfh, Zfhmin, Zve32f, Zve64f and Zve64d. All other extensions are named
with lower-case letters.
We want all properties to be named with lower-case letters since it's
consistent with the riscv-isa string that we create in the FDT. Having
these 11 properties to be exceptions can be confusing.
Deprecate all of them. Create their lower-case counterpart to be used as
maintained CPU properties. When trying to use any deprecated property a
warning message will be displayed, recommending users to switch to the
lower-case variant:
./build/qemu-system-riscv64 -M virt -cpu rv64,Zifencei=true --nographic
qemu-system-riscv64: warning: CPU property 'Zifencei' is deprecated. Please use 'zifencei' instead
This will give users some time to change their scripts before we remove
the capital 'Z' properties entirely.
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Message-ID: <20231009112817.8896-2-dbarboza@ventanamicro.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2023-10-09 13:28:17 +02:00
|
|
|
extern const RISCVCPUMultiExtConfig riscv_cpu_deprecated_exts[];
|
2023-09-25 19:56:58 +02:00
|
|
|
|
2023-09-25 19:57:08 +02:00
|
|
|
typedef struct isa_ext_data {
|
|
|
|
const char *name;
|
|
|
|
int min_version;
|
|
|
|
int ext_enable_offset;
|
|
|
|
} RISCVIsaExtData;
|
|
|
|
extern const RISCVIsaExtData isa_edata_arr[];
|
2023-09-26 20:31:08 +02:00
|
|
|
char *riscv_cpu_get_name(RISCVCPU *cpu);
|
2023-09-25 19:57:08 +02:00
|
|
|
|
2023-10-18 21:56:35 +02:00
|
|
|
void riscv_cpu_finalize_features(RISCVCPU *cpu, Error **errp);
|
2023-09-25 19:56:59 +02:00
|
|
|
void riscv_add_satp_mode_properties(Object *obj);
|
2023-10-18 21:56:37 +02:00
|
|
|
bool riscv_cpu_accelerator_compatible(RISCVCPU *cpu);
|
2023-09-25 19:56:58 +02:00
|
|
|
|
2021-01-12 05:52:01 +01:00
|
|
|
/* CSR function table */
|
2021-01-19 03:52:03 +01:00
|
|
|
extern riscv_csr_operations csr_ops[CSR_TABLE_SIZE];
|
2021-01-12 05:52:01 +01:00
|
|
|
|
riscv: Allow user to set the satp mode
RISC-V specifies multiple sizes for addressable memory and Linux probes for
the machine's support at startup via the satp CSR register (done in
csr.c:validate_vm).
As per the specification, sv64 must support sv57, which in turn must
support sv48...etc. So we can restrict machine support by simply setting the
"highest" supported mode and the bare mode is always supported.
You can set the satp mode using the new properties "sv32", "sv39", "sv48",
"sv57" and "sv64" as follows:
-cpu rv64,sv57=on # Linux will boot using sv57 scheme
-cpu rv64,sv39=on # Linux will boot using sv39 scheme
-cpu rv64,sv57=off # Linux will boot using sv48 scheme
-cpu rv64 # Linux will boot using sv57 scheme by default
We take the highest level set by the user:
-cpu rv64,sv48=on,sv57=on # Linux will boot using sv57 scheme
We make sure that invalid configurations are rejected:
-cpu rv64,sv39=off,sv48=on # sv39 must be supported if higher modes are
# enabled
We accept "redundant" configurations:
-cpu rv64,sv48=on,sv57=off # Linux will boot using sv48 scheme
And contradictory configurations:
-cpu rv64,sv48=on,sv48=off # Linux will boot using sv39 scheme
Co-Developed-by: Ludovic Henry <ludovic@rivosinc.com>
Signed-off-by: Ludovic Henry <ludovic@rivosinc.com>
Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Reviewed-by: Bin Meng <bmeng@tinylab.org>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Frank Chang <frank.chang@sifive.com>
Message-ID: <20230303131252.892893-4-alexghiti@rivosinc.com>
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2023-03-03 14:12:50 +01:00
|
|
|
extern const bool valid_vm_1_10_32[], valid_vm_1_10_64[];
|
|
|
|
|
2019-01-05 00:23:55 +01:00
|
|
|
void riscv_get_csr_ops(int csrno, riscv_csr_operations *ops);
|
|
|
|
void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops);
|
2018-03-02 13:31:10 +01:00
|
|
|
|
2019-03-15 11:26:59 +01:00
|
|
|
void riscv_cpu_register_gdb_regs_for_features(CPUState *cs);
|
|
|
|
|
riscv: Allow user to set the satp mode
RISC-V specifies multiple sizes for addressable memory and Linux probes for
the machine's support at startup via the satp CSR register (done in
csr.c:validate_vm).
As per the specification, sv64 must support sv57, which in turn must
support sv48...etc. So we can restrict machine support by simply setting the
"highest" supported mode and the bare mode is always supported.
You can set the satp mode using the new properties "sv32", "sv39", "sv48",
"sv57" and "sv64" as follows:
-cpu rv64,sv57=on # Linux will boot using sv57 scheme
-cpu rv64,sv39=on # Linux will boot using sv39 scheme
-cpu rv64,sv57=off # Linux will boot using sv48 scheme
-cpu rv64 # Linux will boot using sv57 scheme by default
We take the highest level set by the user:
-cpu rv64,sv48=on,sv57=on # Linux will boot using sv57 scheme
We make sure that invalid configurations are rejected:
-cpu rv64,sv39=off,sv48=on # sv39 must be supported if higher modes are
# enabled
We accept "redundant" configurations:
-cpu rv64,sv48=on,sv57=off # Linux will boot using sv48 scheme
And contradictory configurations:
-cpu rv64,sv48=on,sv48=off # Linux will boot using sv39 scheme
Co-Developed-by: Ludovic Henry <ludovic@rivosinc.com>
Signed-off-by: Ludovic Henry <ludovic@rivosinc.com>
Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Reviewed-by: Bin Meng <bmeng@tinylab.org>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Frank Chang <frank.chang@sifive.com>
Message-ID: <20230303131252.892893-4-alexghiti@rivosinc.com>
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2023-03-03 14:12:50 +01:00
|
|
|
uint8_t satp_mode_max_from_map(uint32_t map);
|
|
|
|
const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit);
|
|
|
|
|
2018-03-02 13:31:10 +01:00
|
|
|
#endif /* RISCV_CPU_H */
|