2018-03-02 15:31:10 +03: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 18:20:52 +03:00
|
|
|
#include "hw/core/cpu.h"
|
2020-07-01 18:24:52 +03:00
|
|
|
#include "hw/registerfields.h"
|
2018-03-02 15:31:10 +03:00
|
|
|
#include "exec/cpu-defs.h"
|
2022-03-23 18:57:39 +03:00
|
|
|
#include "qemu/cpu-float.h"
|
2020-09-03 23:43:22 +03:00
|
|
|
#include "qom/object.h"
|
2022-01-07 00:01:06 +03:00
|
|
|
#include "qemu/int128.h"
|
2021-10-20 06:16:57 +03:00
|
|
|
#include "cpu_bits.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 16:12:50 +03:00
|
|
|
#include "qapi/qapi-types-common.h"
|
2018-03-02 15:31:10 +03:00
|
|
|
|
2019-03-22 21:51:19 +03:00
|
|
|
#define TCG_GUEST_DEFAULT_MO 0
|
|
|
|
|
2022-05-11 17:45:23 +03:00
|
|
|
/*
|
|
|
|
* RISC-V-specific extra insn start words:
|
|
|
|
* 1: Original instruction opcode
|
|
|
|
*/
|
|
|
|
#define TARGET_INSN_START_EXTRA_WORDS 1
|
|
|
|
|
2018-03-02 15:31:10 +03:00
|
|
|
#define TYPE_RISCV_CPU "riscv-cpu"
|
|
|
|
|
|
|
|
#define RISCV_CPU_TYPE_SUFFIX "-" TYPE_RISCV_CPU
|
|
|
|
#define RISCV_CPU_TYPE_NAME(name) (name RISCV_CPU_TYPE_SUFFIX)
|
2018-02-07 13:40:25 +03:00
|
|
|
#define CPU_RESOLVING_TYPE TYPE_RISCV_CPU
|
2018-03-02 15:31:10 +03:00
|
|
|
|
|
|
|
#define TYPE_RISCV_CPU_ANY RISCV_CPU_TYPE_NAME("any")
|
2019-04-20 05:24:09 +03:00
|
|
|
#define TYPE_RISCV_CPU_BASE32 RISCV_CPU_TYPE_NAME("rv32")
|
|
|
|
#define TYPE_RISCV_CPU_BASE64 RISCV_CPU_TYPE_NAME("rv64")
|
2022-01-07 00:00:57 +03:00
|
|
|
#define TYPE_RISCV_CPU_BASE128 RISCV_CPU_TYPE_NAME("x-rv128")
|
2020-04-23 20:50:09 +03:00
|
|
|
#define TYPE_RISCV_CPU_IBEX RISCV_CPU_TYPE_NAME("lowrisc-ibex")
|
2021-04-01 21:14:54 +03:00
|
|
|
#define TYPE_RISCV_CPU_SHAKTI_C RISCV_CPU_TYPE_NAME("shakti-c")
|
2018-03-02 15:31:10 +03:00
|
|
|
#define TYPE_RISCV_CPU_SIFIVE_E31 RISCV_CPU_TYPE_NAME("sifive-e31")
|
2020-03-13 22:34:29 +03:00
|
|
|
#define TYPE_RISCV_CPU_SIFIVE_E34 RISCV_CPU_TYPE_NAME("sifive-e34")
|
2018-03-02 15:31:10 +03:00
|
|
|
#define TYPE_RISCV_CPU_SIFIVE_E51 RISCV_CPU_TYPE_NAME("sifive-e51")
|
|
|
|
#define TYPE_RISCV_CPU_SIFIVE_U34 RISCV_CPU_TYPE_NAME("sifive-u34")
|
|
|
|
#define TYPE_RISCV_CPU_SIFIVE_U54 RISCV_CPU_TYPE_NAME("sifive-u54")
|
2023-01-31 23:20:11 +03:00
|
|
|
#define TYPE_RISCV_CPU_THEAD_C906 RISCV_CPU_TYPE_NAME("thead-c906")
|
2022-01-12 11:13:25 +03:00
|
|
|
#define TYPE_RISCV_CPU_HOST RISCV_CPU_TYPE_NAME("host")
|
2018-03-02 15:31:10 +03:00
|
|
|
|
2020-12-16 21:22:29 +03: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
|
|
|
|
|
2018-03-02 15:31:10 +03:00
|
|
|
#define RV(x) ((target_ulong)1 << (x - 'A'))
|
|
|
|
|
2023-04-06 21:03:51 +03:00
|
|
|
/* Consider updating misa_ext_cfgs[] when adding new MISA bits here */
|
2018-03-02 15:31:10 +03:00
|
|
|
#define RVI RV('I')
|
2018-03-05 03:28:00 +03:00
|
|
|
#define RVE RV('E') /* E and I are mutually exclusive */
|
2018-03-02 15:31:10 +03:00
|
|
|
#define RVM RV('M')
|
|
|
|
#define RVA RV('A')
|
|
|
|
#define RVF RV('F')
|
|
|
|
#define RVD RV('D')
|
2020-07-01 18:24:49 +03:00
|
|
|
#define RVV RV('V')
|
2018-03-02 15:31:10 +03:00
|
|
|
#define RVC RV('C')
|
|
|
|
#define RVS RV('S')
|
|
|
|
#define RVU RV('U')
|
2020-02-01 04:01:41 +03:00
|
|
|
#define RVH RV('H')
|
2021-10-25 20:36:02 +03:00
|
|
|
#define RVJ RV('J')
|
2023-04-06 21:03:50 +03:00
|
|
|
#define RVG RV('G')
|
2018-03-02 15:31:10 +03:00
|
|
|
|
|
|
|
|
2022-03-03 21:54:35 +03:00
|
|
|
/* Privileged specification version */
|
|
|
|
enum {
|
|
|
|
PRIV_VERSION_1_10_0 = 0,
|
|
|
|
PRIV_VERSION_1_11_0,
|
2022-03-03 21:54:36 +03:00
|
|
|
PRIV_VERSION_1_12_0,
|
2022-03-03 21:54:35 +03:00
|
|
|
};
|
2018-03-02 15:31:10 +03:00
|
|
|
|
2021-12-10 10:55:47 +03:00
|
|
|
#define VEXT_VERSION_1_00_0 0x00010000
|
2020-07-01 18:24:50 +03:00
|
|
|
|
2020-10-14 13:17:28 +03:00
|
|
|
enum {
|
|
|
|
TRANSLATE_SUCCESS,
|
|
|
|
TRANSLATE_FAIL,
|
|
|
|
TRANSLATE_PMP_FAIL,
|
|
|
|
TRANSLATE_G_STAGE_FAIL
|
|
|
|
};
|
|
|
|
|
2018-03-02 15:31:10 +03:00
|
|
|
#define MMU_USER_IDX 3
|
|
|
|
|
|
|
|
#define MAX_RISCV_PMPS (16)
|
|
|
|
|
2022-02-07 15:35:58 +03:00
|
|
|
typedef struct CPUArchState CPURISCVState;
|
2018-03-02 15:31:10 +03:00
|
|
|
|
2021-05-16 23:53:33 +03:00
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
2018-03-02 15:31:10 +03:00
|
|
|
#include "pmp.h"
|
2022-03-15 09:55:23 +03:00
|
|
|
#include "debug.h"
|
2021-05-16 23:53:33 +03:00
|
|
|
#endif
|
2018-03-02 15:31:10 +03:00
|
|
|
|
2021-12-10 10:56:51 +03:00
|
|
|
#define RV_VLEN_MAX 1024
|
2022-06-21 02:15:57 +03:00
|
|
|
#define RV_MAX_MHPMEVENTS 32
|
2022-06-21 02:15:56 +03:00
|
|
|
#define RV_MAX_MHPMCOUNTERS 32
|
2020-07-01 18:24:49 +03:00
|
|
|
|
2021-12-10 10:55:59 +03:00
|
|
|
FIELD(VTYPE, VLMUL, 0, 3)
|
|
|
|
FIELD(VTYPE, VSEW, 3, 3)
|
2021-12-10 10:56:00 +03:00
|
|
|
FIELD(VTYPE, VTA, 6, 1)
|
|
|
|
FIELD(VTYPE, VMA, 7, 1)
|
2021-12-10 10:55:59 +03:00
|
|
|
FIELD(VTYPE, VEDIV, 8, 2)
|
|
|
|
FIELD(VTYPE, RESERVED, 10, sizeof(target_ulong) * 8 - 11)
|
2020-07-01 18:24:52 +03:00
|
|
|
|
2022-06-21 02:15:57 +03:00
|
|
|
typedef struct PMUCTRState {
|
|
|
|
/* Current value of a counter */
|
|
|
|
target_ulong mhpmcounter_val;
|
2023-04-05 11:58:12 +03:00
|
|
|
/* Current value of a counter in RV32 */
|
2022-06-21 02:15:57 +03: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 01:16:57 +03:00
|
|
|
/* Value beyond UINT32_MAX/UINT64_MAX before overflow interrupt trigger */
|
|
|
|
target_ulong irq_overflow_left;
|
2022-06-21 02:15:57 +03:00
|
|
|
} PMUCTRState;
|
|
|
|
|
2022-02-07 15:35:58 +03:00
|
|
|
struct CPUArchState {
|
2018-03-02 15:31:10 +03:00
|
|
|
target_ulong gpr[32];
|
2022-01-07 00:00:56 +03:00
|
|
|
target_ulong gprh[32]; /* 64 top bits of the 128-bit registers */
|
2020-07-01 18:24:49 +03: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 15:20:42 +03:00
|
|
|
bool vill;
|
2020-07-01 18:24:49 +03:00
|
|
|
|
2018-03-02 15:31:10 +03:00
|
|
|
target_ulong pc;
|
|
|
|
target_ulong load_res;
|
|
|
|
target_ulong load_val;
|
|
|
|
|
2022-12-17 20:06:21 +03:00
|
|
|
/* Floating-Point state */
|
|
|
|
uint64_t fpr[32]; /* assume both F and D extensions */
|
2018-03-02 15:31:10 +03:00
|
|
|
target_ulong frm;
|
2022-12-17 20:06:21 +03:00
|
|
|
float_status fp_status;
|
2018-03-02 15:31:10 +03:00
|
|
|
|
|
|
|
target_ulong badaddr;
|
2022-05-11 17:45:23 +03:00
|
|
|
target_ulong bins;
|
2021-12-20 09:49:16 +03:00
|
|
|
|
2020-02-01 04:02:56 +03:00
|
|
|
target_ulong guest_phys_fault_addr;
|
2018-03-02 15:31:10 +03:00
|
|
|
|
|
|
|
target_ulong priv_ver;
|
2021-05-05 19:06:18 +03:00
|
|
|
target_ulong bext_ver;
|
2020-07-01 18:24:50 +03:00
|
|
|
target_ulong vext_ver;
|
2021-10-20 06:16:57 +03:00
|
|
|
|
|
|
|
/* RISCVMXL, but uint32_t for vmstate migration */
|
|
|
|
uint32_t misa_mxl; /* current mxl */
|
|
|
|
uint32_t misa_mxl_max; /* max mxl for this cpu */
|
|
|
|
uint32_t misa_ext; /* current extensions */
|
|
|
|
uint32_t misa_ext_mask; /* max ext for this cpu */
|
2022-01-20 15:20:32 +03:00
|
|
|
uint32_t xl; /* current xlen */
|
2018-03-02 15:31:10 +03:00
|
|
|
|
2022-01-07 00:01:04 +03:00
|
|
|
/* 128-bit helpers upper part return value */
|
|
|
|
target_ulong retxh;
|
|
|
|
|
2023-03-07 11:14:00 +03:00
|
|
|
target_ulong jvt;
|
|
|
|
|
2019-03-16 04:20:46 +03:00
|
|
|
#ifdef CONFIG_USER_ONLY
|
|
|
|
uint32_t elf_flags;
|
|
|
|
#endif
|
|
|
|
|
2018-03-02 15:31:10 +03:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
target_ulong priv;
|
2020-02-01 04:01:51 +03:00
|
|
|
/* This contains QEMU specific information about the virt state. */
|
2023-03-27 11:08:53 +03:00
|
|
|
bool virt_enabled;
|
2022-02-04 20:46:39 +03:00
|
|
|
target_ulong geilen;
|
2022-09-14 13:11:06 +03:00
|
|
|
uint64_t resetvec;
|
2018-03-02 15:31:10 +03:00
|
|
|
|
|
|
|
target_ulong mhartid;
|
2020-10-26 14:55:25 +03: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-09 00:25:25 +03:00
|
|
|
|
2022-02-04 20:46:46 +03:00
|
|
|
uint64_t mip;
|
2022-03-17 09:18:17 +03: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 04:02:12 +03:00
|
|
|
|
2022-02-04 20:46:46 +03:00
|
|
|
uint64_t miclaim;
|
2018-04-09 00:25:25 +03:00
|
|
|
|
2022-02-04 20:46:46 +03:00
|
|
|
uint64_t mie;
|
|
|
|
uint64_t mideleg;
|
2018-03-02 15:31:10 +03:00
|
|
|
|
|
|
|
target_ulong satp; /* since: priv-1.10.0 */
|
2021-03-19 22:45:29 +03:00
|
|
|
target_ulong stval;
|
2018-03-02 15:31:10 +03: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 20:46:45 +03:00
|
|
|
/* Machine and Supervisor interrupt priorities */
|
|
|
|
uint8_t miprio[64];
|
|
|
|
uint8_t siprio[64];
|
|
|
|
|
2022-02-04 20:46:50 +03:00
|
|
|
/* AIA CSRs */
|
|
|
|
target_ulong miselect;
|
|
|
|
target_ulong siselect;
|
|
|
|
|
2020-02-01 04:01:43 +03:00
|
|
|
/* Hypervisor CSRs */
|
|
|
|
target_ulong hstatus;
|
|
|
|
target_ulong hedeleg;
|
2022-02-04 20:46:46 +03:00
|
|
|
uint64_t hideleg;
|
2020-02-01 04:01:43 +03:00
|
|
|
target_ulong hcounteren;
|
|
|
|
target_ulong htval;
|
|
|
|
target_ulong htinst;
|
|
|
|
target_ulong hgatp;
|
2022-02-04 20:46:39 +03:00
|
|
|
target_ulong hgeie;
|
|
|
|
target_ulong hgeip;
|
2020-02-02 16:42:16 +03:00
|
|
|
uint64_t htimedelta;
|
2020-02-01 04:01:43 +03:00
|
|
|
|
2022-02-04 20:46:45 +03:00
|
|
|
/* Hypervisor controlled virtual interrupt priorities */
|
2022-02-04 20:46:47 +03:00
|
|
|
target_ulong hvictl;
|
2022-02-04 20:46:45 +03:00
|
|
|
uint8_t hviprio[64];
|
|
|
|
|
2022-01-07 00:01:05 +03:00
|
|
|
/* Upper 64-bits of 128-bit CSRs */
|
|
|
|
uint64_t mscratchh;
|
|
|
|
uint64_t sscratchh;
|
|
|
|
|
2020-02-01 04:01:43 +03:00
|
|
|
/* Virtual CSRs */
|
2020-10-26 14:55:25 +03: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 04:01:43 +03:00
|
|
|
target_ulong vstvec;
|
|
|
|
target_ulong vsscratch;
|
|
|
|
target_ulong vsepc;
|
|
|
|
target_ulong vscause;
|
|
|
|
target_ulong vstval;
|
|
|
|
target_ulong vsatp;
|
|
|
|
|
2022-02-04 20:46:50 +03:00
|
|
|
/* AIA VS-mode CSRs */
|
|
|
|
target_ulong vsiselect;
|
|
|
|
|
2020-02-01 04:01:43 +03:00
|
|
|
target_ulong mtval2;
|
|
|
|
target_ulong mtinst;
|
|
|
|
|
2020-02-01 04:02:12 +03: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 14:55:25 +03:00
|
|
|
uint64_t mstatus_hs;
|
2020-02-01 04:02:12 +03:00
|
|
|
|
2023-04-05 11:58:12 +03:00
|
|
|
/*
|
|
|
|
* Signals whether the current exception occurred with two-stage address
|
|
|
|
* translation active.
|
|
|
|
*/
|
2021-03-19 17:14:59 +03:00
|
|
|
bool two_stage_lookup;
|
2022-06-30 09:11:49 +03: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 17:14:59 +03:00
|
|
|
|
2018-04-09 02:33:05 +03:00
|
|
|
target_ulong scounteren;
|
|
|
|
target_ulong mcounteren;
|
2018-03-02 15:31:10 +03:00
|
|
|
|
2022-06-21 02:15:55 +03:00
|
|
|
target_ulong mcountinhibit;
|
|
|
|
|
2022-06-21 02:15:57 +03:00
|
|
|
/* PMU counter state */
|
|
|
|
PMUCTRState pmu_ctrs[RV_MAX_MHPMCOUNTERS];
|
2022-06-21 02:15:56 +03:00
|
|
|
|
2023-04-05 11:58:12 +03:00
|
|
|
/* PMU event selector configured values. First three are unused */
|
2022-06-21 02:15:56 +03:00
|
|
|
target_ulong mhpmevent_val[RV_MAX_MHPMEVENTS];
|
|
|
|
|
2023-04-05 11:58:12 +03:00
|
|
|
/* PMU event selector configured values for RV32 */
|
2022-08-25 01:16:57 +03:00
|
|
|
target_ulong mhpmeventh_val[RV_MAX_MHPMEVENTS];
|
|
|
|
|
2018-03-02 15:31:10 +03:00
|
|
|
target_ulong sscratch;
|
|
|
|
target_ulong mscratch;
|
|
|
|
|
2022-08-25 01:13:56 +03:00
|
|
|
/* Sstc CSRs */
|
|
|
|
uint64_t stimecmp;
|
|
|
|
|
2022-08-25 01:13:57 +03:00
|
|
|
uint64_t vstimecmp;
|
|
|
|
|
2018-03-02 15:31:10 +03:00
|
|
|
/* physical memory protection */
|
|
|
|
pmp_table_t pmp_state;
|
2021-04-19 09:16:53 +03:00
|
|
|
target_ulong mseccfg;
|
2019-03-15 13:26:58 +03:00
|
|
|
|
2022-03-15 09:55:23 +03:00
|
|
|
/* trigger module */
|
|
|
|
target_ulong trigger_cur;
|
2022-09-09 16:42:10 +03:00
|
|
|
target_ulong tdata1[RV_MAX_TRIGGERS];
|
|
|
|
target_ulong tdata2[RV_MAX_TRIGGERS];
|
|
|
|
target_ulong tdata3[RV_MAX_TRIGGERS];
|
|
|
|
struct CPUBreakpoint *cpu_breakpoint[RV_MAX_TRIGGERS];
|
|
|
|
struct CPUWatchpoint *cpu_watchpoint[RV_MAX_TRIGGERS];
|
2022-10-13 09:29:44 +03:00
|
|
|
QEMUTimer *itrigger_timer[RV_MAX_TRIGGERS];
|
|
|
|
int64_t last_icount;
|
2022-10-13 09:29:46 +03:00
|
|
|
bool itrigger_enabled;
|
2022-03-15 09:55:23 +03:00
|
|
|
|
2020-02-02 16:42:16 +03:00
|
|
|
/* machine specific rdtime callback */
|
2022-04-20 11:08:59 +03:00
|
|
|
uint64_t (*rdtime_fn)(void *);
|
|
|
|
void *rdtime_fn_arg;
|
2020-02-02 16:42:16 +03:00
|
|
|
|
2022-02-04 20:46:44 +03: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 13:26:58 +03:00
|
|
|
/* True if in debugger mode. */
|
|
|
|
bool debugger;
|
2021-10-25 20:36:04 +03: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 21:54:39 +03:00
|
|
|
|
|
|
|
/* CSRs for execution enviornment configuration */
|
|
|
|
uint64_t menvcfg;
|
2022-10-16 15:47:22 +03:00
|
|
|
uint64_t mstateen[SMSTATEEN_MAX_COUNT];
|
|
|
|
uint64_t hstateen[SMSTATEEN_MAX_COUNT];
|
|
|
|
uint64_t sstateen[SMSTATEEN_MAX_COUNT];
|
2022-03-03 21:54:39 +03:00
|
|
|
target_ulong senvcfg;
|
|
|
|
uint64_t henvcfg;
|
2018-03-02 15:31:10 +03:00
|
|
|
#endif
|
2022-01-20 15:20:38 +03:00
|
|
|
target_ulong cur_pmmask;
|
|
|
|
target_ulong cur_pmbase;
|
2018-03-02 15:31:10 +03:00
|
|
|
|
|
|
|
/* Fields from here on are preserved across CPU reset. */
|
2022-08-25 01:13:56 +03:00
|
|
|
QEMUTimer *stimer; /* Internal timer for S-mode interrupt */
|
2022-08-25 01:13:57 +03:00
|
|
|
QEMUTimer *vstimer; /* Internal timer for VS-mode interrupt */
|
|
|
|
bool vstime_irq;
|
2022-01-12 11:13:22 +03:00
|
|
|
|
|
|
|
hwaddr kernel_addr;
|
|
|
|
hwaddr fdt_addr;
|
2022-01-12 11:13:26 +03: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;
|
2018-03-02 15:31:10 +03:00
|
|
|
};
|
|
|
|
|
2022-02-14 19:08:40 +03:00
|
|
|
OBJECT_DECLARE_CPU_TYPE(RISCVCPU, RISCVCPUClass, RISCV_CPU)
|
2018-03-02 15:31:10 +03:00
|
|
|
|
2023-04-05 11:58:12 +03:00
|
|
|
/*
|
2018-03-02 15:31:10 +03:00
|
|
|
* RISCVCPUClass:
|
|
|
|
* @parent_realize: The parent class' realize handler.
|
2022-11-24 14:50:17 +03:00
|
|
|
* @parent_phases: The parent class' reset phase handlers.
|
2018-03-02 15:31:10 +03:00
|
|
|
*
|
|
|
|
* A RISCV CPU model.
|
|
|
|
*/
|
2020-09-03 23:43:22 +03:00
|
|
|
struct RISCVCPUClass {
|
2023-04-05 11:58:12 +03:00
|
|
|
/* < private > */
|
2018-03-02 15:31:10 +03:00
|
|
|
CPUClass parent_class;
|
2023-04-05 11:58:12 +03:00
|
|
|
/* < public > */
|
2018-03-02 15:31:10 +03:00
|
|
|
DeviceRealize parent_realize;
|
2022-11-24 14:50:17 +03:00
|
|
|
ResettablePhases parent_phases;
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2018-03-02 15:31:10 +03: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 16:12:50 +03:00
|
|
|
/*
|
|
|
|
* map is a 16-bit bitmap: the most significant set bit in map is the maximum
|
2023-03-03 16:12:51 +03:00
|
|
|
* satp mode that is supported. It may be chosen by the user and must respect
|
|
|
|
* what qemu implements (valid_1_10_32/64) and what the hw is capable of
|
|
|
|
* (supported bitmap below).
|
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 16:12:50 +03:00
|
|
|
*
|
|
|
|
* init is a 16-bit bitmap used to make sure the user selected a correct
|
|
|
|
* configuration as per the specification.
|
2023-03-03 16:12:51 +03:00
|
|
|
*
|
|
|
|
* supported is a 16-bit bitmap used to reflect the hw capabilities.
|
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 16:12:50 +03:00
|
|
|
*/
|
|
|
|
typedef struct {
|
2023-03-03 16:12:51 +03:00
|
|
|
uint16_t map, init, supported;
|
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 16:12:50 +03:00
|
|
|
} RISCVSATPMap;
|
|
|
|
|
2022-02-02 03:52:43 +03:00
|
|
|
struct RISCVCPUConfig {
|
|
|
|
bool ext_zba;
|
|
|
|
bool ext_zbb;
|
|
|
|
bool ext_zbc;
|
2022-04-23 05:34:57 +03:00
|
|
|
bool ext_zbkb;
|
|
|
|
bool ext_zbkc;
|
|
|
|
bool ext_zbkx;
|
2022-02-02 03:52:43 +03:00
|
|
|
bool ext_zbs;
|
2023-03-07 11:13:54 +03:00
|
|
|
bool ext_zca;
|
|
|
|
bool ext_zcb;
|
|
|
|
bool ext_zcd;
|
2023-03-07 11:14:03 +03:00
|
|
|
bool ext_zce;
|
2023-03-07 11:13:54 +03:00
|
|
|
bool ext_zcf;
|
|
|
|
bool ext_zcmp;
|
|
|
|
bool ext_zcmt;
|
2022-04-23 05:34:57 +03:00
|
|
|
bool ext_zk;
|
|
|
|
bool ext_zkn;
|
|
|
|
bool ext_zknd;
|
|
|
|
bool ext_zkne;
|
|
|
|
bool ext_zknh;
|
|
|
|
bool ext_zkr;
|
|
|
|
bool ext_zks;
|
|
|
|
bool ext_zksed;
|
|
|
|
bool ext_zksh;
|
|
|
|
bool ext_zkt;
|
2022-02-02 03:52:43 +03:00
|
|
|
bool ext_ifencei;
|
|
|
|
bool ext_icsr;
|
2023-02-24 16:25:35 +03:00
|
|
|
bool ext_icbom;
|
2023-02-24 16:25:34 +03:00
|
|
|
bool ext_icboz;
|
2023-02-21 12:10:09 +03:00
|
|
|
bool ext_zicond;
|
2022-07-25 06:47:28 +03:00
|
|
|
bool ext_zihintpause;
|
2022-10-16 15:47:22 +03:00
|
|
|
bool ext_smstateen;
|
2022-08-25 01:13:56 +03:00
|
|
|
bool ext_sstc;
|
2023-02-24 07:08:49 +03:00
|
|
|
bool ext_svadu;
|
2022-02-04 05:26:57 +03:00
|
|
|
bool ext_svinval;
|
2022-02-04 05:26:54 +03:00
|
|
|
bool ext_svnapot;
|
|
|
|
bool ext_svpbmt;
|
2022-02-11 07:39:15 +03:00
|
|
|
bool ext_zdinx;
|
2022-10-05 17:49:48 +03:00
|
|
|
bool ext_zawrs;
|
2022-02-02 03:52:43 +03:00
|
|
|
bool ext_zfh;
|
|
|
|
bool ext_zfhmin;
|
2022-02-11 07:39:15 +03:00
|
|
|
bool ext_zfinx;
|
|
|
|
bool ext_zhinx;
|
|
|
|
bool ext_zhinxmin;
|
2022-02-02 03:52:43 +03:00
|
|
|
bool ext_zve32f;
|
|
|
|
bool ext_zve64f;
|
2023-02-15 05:05:29 +03:00
|
|
|
bool ext_zve64d;
|
2022-05-31 06:07:32 +03:00
|
|
|
bool ext_zmmul;
|
2023-02-15 05:05:29 +03:00
|
|
|
bool ext_zvfh;
|
|
|
|
bool ext_zvfhmin;
|
2022-08-20 07:29:58 +03:00
|
|
|
bool ext_smaia;
|
|
|
|
bool ext_ssaia;
|
2022-08-25 01:16:57 +03:00
|
|
|
bool ext_sscofpmf;
|
2022-06-06 09:16:16 +03:00
|
|
|
bool rvv_ta_all_1s;
|
2022-06-20 09:51:02 +03:00
|
|
|
bool rvv_ma_all_1s;
|
2022-02-02 03:52:43 +03:00
|
|
|
|
2022-04-22 07:04:34 +03:00
|
|
|
uint32_t mvendorid;
|
|
|
|
uint64_t marchid;
|
2022-05-23 18:31:46 +03:00
|
|
|
uint64_t mimpid;
|
2022-04-22 07:04:34 +03:00
|
|
|
|
2022-02-02 03:52:48 +03:00
|
|
|
/* Vendor-specific custom extensions */
|
2023-01-31 23:20:02 +03:00
|
|
|
bool ext_xtheadba;
|
2023-01-31 23:20:03 +03:00
|
|
|
bool ext_xtheadbb;
|
2023-01-31 23:20:04 +03:00
|
|
|
bool ext_xtheadbs;
|
2023-01-31 23:20:00 +03:00
|
|
|
bool ext_xtheadcmo;
|
2023-01-31 23:20:05 +03:00
|
|
|
bool ext_xtheadcondmov;
|
2023-01-31 23:20:09 +03:00
|
|
|
bool ext_xtheadfmemidx;
|
2023-01-31 23:20:12 +03:00
|
|
|
bool ext_xtheadfmv;
|
2023-01-31 23:20:06 +03:00
|
|
|
bool ext_xtheadmac;
|
2023-01-31 23:20:08 +03:00
|
|
|
bool ext_xtheadmemidx;
|
2023-01-31 23:20:07 +03:00
|
|
|
bool ext_xtheadmempair;
|
2023-01-31 23:20:01 +03:00
|
|
|
bool ext_xtheadsync;
|
2022-02-02 03:52:48 +03:00
|
|
|
bool ext_XVentanaCondOps;
|
|
|
|
|
2022-06-21 02:15:54 +03:00
|
|
|
uint8_t pmu_num;
|
2022-02-02 03:52:43 +03:00
|
|
|
char *priv_spec;
|
|
|
|
char *user_spec;
|
|
|
|
char *bext_spec;
|
|
|
|
char *vext_spec;
|
|
|
|
uint16_t vlen;
|
|
|
|
uint16_t elen;
|
2023-02-24 16:25:35 +03:00
|
|
|
uint16_t cbom_blocksize;
|
2023-02-24 16:25:34 +03:00
|
|
|
uint16_t cboz_blocksize;
|
2022-02-02 03:52:43 +03:00
|
|
|
bool mmu;
|
|
|
|
bool pmp;
|
|
|
|
bool epmp;
|
2022-04-21 03:33:20 +03:00
|
|
|
bool debug;
|
target/riscv: allow MISA writes as experimental
At this moment, and apparently since ever, we have no way of enabling
RISCV_FEATURE_MISA. This means that all the code from write_misa(), all
the nuts and bolts that handles how to properly write this CSR, has
always been a no-op as well because write_misa() will always exit
earlier.
This seems to be benign in the majority of cases. Booting an Ubuntu
'virt' guest and logging all the calls to 'write_misa' shows that no
writes to MISA CSR was attempted. Writing MISA, i.e. enabling/disabling
RISC-V extensions after the machine is powered on, seems to be a niche
use.
After discussions in the mailing list, most notably in [1], we reached
the consensus that this code is not suited to be exposed to users
because it's not well tested, but at the same time removing it is a bit
extreme because we would like to fix it, and it's easier to do so with
the code available to use instead of fetching it from git log.
The approach taken here is to get rid of RISCV_FEATURE_MISA altogether
and use a new experimental flag called x-misa-w. The default value is
false, meaning that we're keeping the existing behavior of doing nothing
if a write_misa() is attempted. As with any existing experimental flag,
x-misa-w is also a temporary flag that we need to remove once we fix
write_misa().
[1] https://lists.gnu.org/archive/html/qemu-devel/2023-02/msg05092.html
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Weiwei Li <liweiwei@iscas.ac.cn>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Reviewed-by: Bin Meng <bmeng@tinylab.org>
Reviewed-by: Weiwei Li<liweiwei@iscas.ac.cn>
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
Message-ID: <20230222185205.355361-4-dbarboza@ventanamicro.com>
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
2023-02-22 21:51:58 +03:00
|
|
|
bool misa_w;
|
2022-05-10 14:29:08 +03:00
|
|
|
|
|
|
|
bool short_isa_string;
|
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 16:12:50 +03:00
|
|
|
|
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
RISCVSATPMap satp_mode;
|
|
|
|
#endif
|
2022-02-02 03:52:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct RISCVCPUConfig RISCVCPUConfig;
|
|
|
|
|
2023-04-05 11:58:12 +03:00
|
|
|
/*
|
2018-03-02 15:31:10 +03:00
|
|
|
* RISCVCPU:
|
|
|
|
* @env: #CPURISCVState
|
|
|
|
*
|
|
|
|
* A RISCV CPU.
|
|
|
|
*/
|
2022-02-14 19:15:16 +03:00
|
|
|
struct ArchCPU {
|
2023-04-05 11:58:12 +03:00
|
|
|
/* < private > */
|
2018-03-02 15:31:10 +03:00
|
|
|
CPUState parent_obj;
|
2023-04-05 11:58:12 +03:00
|
|
|
/* < public > */
|
2019-03-23 03:16:06 +03:00
|
|
|
CPUNegativeOffsetState neg;
|
2018-03-02 15:31:10 +03:00
|
|
|
CPURISCVState env;
|
2019-04-20 05:24:01 +03:00
|
|
|
|
2021-01-16 08:41:22 +03:00
|
|
|
char *dyn_csr_xml;
|
2021-12-10 10:56:54 +03:00
|
|
|
char *dyn_vreg_xml;
|
2021-01-16 08:41:22 +03:00
|
|
|
|
2019-04-20 05:24:01 +03:00
|
|
|
/* Configuration Settings */
|
2022-02-02 03:52:43 +03:00
|
|
|
RISCVCPUConfig cfg;
|
2022-08-25 01:16:57 +03: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 23:43:22 +03:00
|
|
|
};
|
2018-03-02 15:31:10 +03:00
|
|
|
|
|
|
|
static inline int riscv_has_ext(CPURISCVState *env, target_ulong ext)
|
|
|
|
{
|
2021-10-20 06:16:57 +03:00
|
|
|
return (env->misa_ext & ext) != 0;
|
2018-03-02 15:31:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "cpu_user.h"
|
|
|
|
|
|
|
|
extern const char * const riscv_int_regnames[];
|
2022-01-07 00:00:56 +03:00
|
|
|
extern const char * const riscv_int_regnamesh[];
|
2018-03-02 15:31:10 +03:00
|
|
|
extern const char * const riscv_fpr_regnames[];
|
|
|
|
|
2020-08-14 06:58:19 +03:00
|
|
|
const char *riscv_cpu_get_trap_name(target_ulong cause, bool async);
|
2018-03-02 15:31:10 +03:00
|
|
|
void riscv_cpu_do_interrupt(CPUState *cpu);
|
2021-02-01 15:44:58 +03:00
|
|
|
int riscv_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs,
|
2022-08-11 15:10:54 +03:00
|
|
|
int cpuid, DumpState *s);
|
2021-02-01 15:44:58 +03:00
|
|
|
int riscv_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs,
|
2022-08-11 15:10:54 +03:00
|
|
|
int cpuid, DumpState *s);
|
2020-03-16 20:21:41 +03:00
|
|
|
int riscv_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg);
|
2018-03-02 15:31:10 +03:00
|
|
|
int riscv_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
|
2022-02-04 20:46:45 +03:00
|
|
|
int riscv_cpu_hviprio_index2irq(int index, int *out_irq, int *out_rdzero);
|
|
|
|
uint8_t riscv_cpu_default_priority(int irq);
|
2022-06-01 00:05:44 +03:00
|
|
|
uint64_t riscv_cpu_all_pending(CPURISCVState *env);
|
2022-02-04 20:46:45 +03: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 02:35:24 +03:00
|
|
|
bool riscv_cpu_fp_enabled(CPURISCVState *env);
|
2022-02-04 20:46:39 +03:00
|
|
|
target_ulong riscv_cpu_get_geilen(CPURISCVState *env);
|
|
|
|
void riscv_cpu_set_geilen(CPURISCVState *env, target_ulong geilen);
|
2021-12-10 10:55:49 +03:00
|
|
|
bool riscv_cpu_vector_enabled(CPURISCVState *env);
|
2020-02-01 04:01:51 +03:00
|
|
|
void riscv_cpu_set_virt_enabled(CPURISCVState *env, bool enable);
|
2020-11-04 07:43:29 +03:00
|
|
|
bool riscv_cpu_two_stage_lookup(int mmu_idx);
|
2018-03-02 15:31:10 +03:00
|
|
|
int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch);
|
2022-04-20 16:26:02 +03:00
|
|
|
G_NORETURN void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr,
|
2023-04-05 11:58:13 +03:00
|
|
|
MMUAccessType access_type,
|
|
|
|
int mmu_idx, uintptr_t retaddr);
|
2019-04-02 13:12:38 +03: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 15:31:10 +03:00
|
|
|
char *riscv_isa_string(RISCVCPU *cpu);
|
2019-04-17 22:17:57 +03:00
|
|
|
void riscv_cpu_list(void);
|
2018-03-02 15:31:10 +03:00
|
|
|
|
|
|
|
#define cpu_list riscv_cpu_list
|
|
|
|
#define cpu_mmu_index riscv_cpu_mmu_index
|
|
|
|
|
2018-04-09 00:25:25 +03:00
|
|
|
#ifndef CONFIG_USER_ONLY
|
2022-12-16 14:08:50 +03: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 18:20:51 +03:00
|
|
|
hwaddr riscv_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
|
2021-09-11 19:54:28 +03:00
|
|
|
bool riscv_cpu_exec_interrupt(CPUState *cs, int interrupt_request);
|
2020-02-01 04:02:12 +03:00
|
|
|
void riscv_cpu_swap_hypervisor_regs(CPURISCVState *env);
|
2022-02-04 20:46:46 +03:00
|
|
|
int riscv_cpu_claim_interrupts(RISCVCPU *cpu, uint64_t interrupts);
|
2023-03-09 10:13:28 +03:00
|
|
|
uint64_t riscv_cpu_update_mip(CPURISCVState *env, uint64_t mask,
|
|
|
|
uint64_t value);
|
2018-04-09 00:25:25 +03:00
|
|
|
#define BOOL_TO_MASK(x) (-!!(x)) /* helper for riscv_cpu_update_mip value */
|
2022-04-20 11:08:59 +03:00
|
|
|
void riscv_cpu_set_rdtime_fn(CPURISCVState *env, uint64_t (*fn)(void *),
|
|
|
|
void *arg);
|
2022-02-04 20:46:44 +03: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 11:14:00 +03:00
|
|
|
|
|
|
|
RISCVException smstateen_acc_ok(CPURISCVState *env, int index, uint64_t bit);
|
2018-04-09 00:25:25 +03:00
|
|
|
#endif
|
2019-01-15 02:58:23 +03:00
|
|
|
void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv);
|
2018-03-02 15:31:10 +03:00
|
|
|
|
|
|
|
void riscv_translate_init(void);
|
2022-04-20 16:26:02 +03:00
|
|
|
G_NORETURN void riscv_raise_exception(CPURISCVState *env,
|
|
|
|
uint32_t exception, uintptr_t pc);
|
2018-03-02 15:31:10 +03:00
|
|
|
|
2019-01-15 02:58:23 +03:00
|
|
|
target_ulong riscv_cpu_get_fflags(CPURISCVState *env);
|
|
|
|
void riscv_cpu_set_fflags(CPURISCVState *env, target_ulong);
|
2018-03-02 15:31:10 +03:00
|
|
|
|
2020-11-04 07:43:23 +03:00
|
|
|
#define TB_FLAGS_PRIV_MMU_MASK 3
|
|
|
|
#define TB_FLAGS_PRIV_HYP_ACCESS_MASK (1 << 2)
|
2019-01-15 02:57:50 +03:00
|
|
|
#define TB_FLAGS_MSTATUS_FS MSTATUS_FS
|
2021-12-10 10:55:49 +03:00
|
|
|
#define TB_FLAGS_MSTATUS_VS MSTATUS_VS
|
2018-03-02 15:31:10 +03:00
|
|
|
|
2020-07-01 18:24:52 +03:00
|
|
|
#include "exec/cpu-all.h"
|
|
|
|
|
2021-10-15 10:45:02 +03:00
|
|
|
FIELD(TB_FLAGS, MEM_IDX, 0, 3)
|
2021-12-10 10:55:59 +03:00
|
|
|
FIELD(TB_FLAGS, LMUL, 3, 3)
|
2021-10-15 10:45:02 +03:00
|
|
|
FIELD(TB_FLAGS, SEW, 6, 3)
|
2021-12-10 10:55:59 +03:00
|
|
|
/* Skip MSTATUS_VS (0x600) bits */
|
|
|
|
FIELD(TB_FLAGS, VL_EQ_VLMAX, 11, 1)
|
|
|
|
FIELD(TB_FLAGS, VILL, 12, 1)
|
|
|
|
/* Skip MSTATUS_FS (0x6000) bits */
|
2020-11-04 07:43:31 +03:00
|
|
|
/* Is a Hypervisor instruction load/store allowed? */
|
2021-12-10 10:55:59 +03:00
|
|
|
FIELD(TB_FLAGS, HLSX, 15, 1)
|
|
|
|
FIELD(TB_FLAGS, MSTATUS_HS_FS, 16, 2)
|
|
|
|
FIELD(TB_FLAGS, MSTATUS_HS_VS, 18, 2)
|
2021-10-20 06:16:59 +03:00
|
|
|
/* The combination of MXL/SXL/UXL that applies to the current cpu mode. */
|
2021-12-10 10:55:59 +03:00
|
|
|
FIELD(TB_FLAGS, XL, 20, 2)
|
2021-10-25 20:36:08 +03:00
|
|
|
/* If PointerMasking should be applied */
|
2022-01-20 15:20:41 +03:00
|
|
|
FIELD(TB_FLAGS, PM_MASK_ENABLED, 22, 1)
|
|
|
|
FIELD(TB_FLAGS, PM_BASE_ENABLED, 23, 1)
|
2022-06-06 09:16:16 +03:00
|
|
|
FIELD(TB_FLAGS, VTA, 24, 1)
|
2022-06-20 09:51:02 +03:00
|
|
|
FIELD(TB_FLAGS, VMA, 25, 1)
|
2022-10-13 09:29:43 +03:00
|
|
|
/* Native debug itrigger */
|
|
|
|
FIELD(TB_FLAGS, ITRIGGER, 26, 1)
|
2020-07-01 18:24:52 +03:00
|
|
|
|
2021-10-20 06:16:58 +03: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 20:46:47 +03:00
|
|
|
#define riscv_cpu_mxl_bits(env) (1UL << (4 + riscv_cpu_mxl(env)))
|
2020-12-16 21:22:51 +03:00
|
|
|
|
2023-02-22 21:51:56 +03:00
|
|
|
static inline const RISCVCPUConfig *riscv_cpu_cfg(CPURISCVState *env)
|
|
|
|
{
|
|
|
|
return &env_archcpu(env)->cfg;
|
|
|
|
}
|
|
|
|
|
2022-01-20 15:20:32 +03:00
|
|
|
#if defined(TARGET_RISCV32)
|
|
|
|
#define cpu_recompute_xl(env) ((void)(env), MXL_RV32)
|
|
|
|
#else
|
|
|
|
static inline RISCVMXL cpu_recompute_xl(CPURISCVState *env)
|
|
|
|
{
|
|
|
|
RISCVMXL xl = env->misa_mxl;
|
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
|
|
|
/*
|
|
|
|
* 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) {
|
|
|
|
switch (env->priv) {
|
|
|
|
case PRV_M:
|
|
|
|
break;
|
|
|
|
case PRV_U:
|
|
|
|
xl = get_field(env->mstatus, MSTATUS64_UXL);
|
|
|
|
break;
|
2023-04-07 04:47:42 +03:00
|
|
|
default: /* PRV_S */
|
2022-01-20 15:20:32 +03:00
|
|
|
xl = get_field(env->mstatus, MSTATUS64_SXL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return xl;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-01-20 15:20:43 +03:00
|
|
|
static inline int riscv_cpu_xlen(CPURISCVState *env)
|
|
|
|
{
|
|
|
|
return 16 << env->xl;
|
|
|
|
}
|
|
|
|
|
2022-02-04 05:26:54 +03: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 18:24:52 +03:00
|
|
|
/*
|
2021-12-10 10:56:12 +03: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 18:24:52 +03:00
|
|
|
*/
|
|
|
|
static inline uint32_t vext_get_vlmax(RISCVCPU *cpu, target_ulong vtype)
|
|
|
|
{
|
2021-12-10 10:56:12 +03:00
|
|
|
uint8_t sew = FIELD_EX64(vtype, VTYPE, VSEW);
|
|
|
|
int8_t lmul = sextract32(FIELD_EX64(vtype, VTYPE, VLMUL), 0, 3);
|
2020-07-01 18:24:52 +03:00
|
|
|
return cpu->cfg.vlen >> (sew + 3 - lmul);
|
|
|
|
}
|
|
|
|
|
2021-10-20 06:16:55 +03:00
|
|
|
void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc,
|
|
|
|
target_ulong *cs_base, uint32_t *pflags);
|
2018-03-02 15:31:10 +03:00
|
|
|
|
2022-01-20 15:20:38 +03:00
|
|
|
void riscv_cpu_update_mask(CPURISCVState *env);
|
|
|
|
|
2021-04-01 18:18:07 +03: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 02:23:55 +03:00
|
|
|
|
2019-01-15 02:58:23 +03:00
|
|
|
static inline void riscv_csr_write(CPURISCVState *env, int csrno,
|
|
|
|
target_ulong val)
|
2019-01-05 02:23:55 +03:00
|
|
|
{
|
|
|
|
riscv_csrrw(env, csrno, NULL, val, MAKE_64BIT_MASK(0, TARGET_LONG_BITS));
|
|
|
|
}
|
|
|
|
|
2019-01-15 02:58:23 +03:00
|
|
|
static inline target_ulong riscv_csr_read(CPURISCVState *env, int csrno)
|
2019-01-05 02:23:55 +03:00
|
|
|
{
|
|
|
|
target_ulong val = 0;
|
|
|
|
riscv_csrrw(env, csrno, &val, 0, 0);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2021-04-01 18:17:39 +03:00
|
|
|
typedef RISCVException (*riscv_csr_predicate_fn)(CPURISCVState *env,
|
|
|
|
int csrno);
|
2021-04-01 18:17:57 +03: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 02:23:55 +03:00
|
|
|
|
2022-01-07 00:01:06 +03:00
|
|
|
RISCVException riscv_csrrw_i128(CPURISCVState *env, int csrno,
|
|
|
|
Int128 *ret_value,
|
|
|
|
Int128 new_value, Int128 write_mask);
|
|
|
|
|
2022-01-07 00:01:08 +03: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 02:23:55 +03:00
|
|
|
typedef struct {
|
2021-01-12 07:52:02 +03:00
|
|
|
const char *name;
|
2019-01-05 02:24:14 +03:00
|
|
|
riscv_csr_predicate_fn predicate;
|
2019-01-05 02:23:55 +03:00
|
|
|
riscv_csr_read_fn read;
|
|
|
|
riscv_csr_write_fn write;
|
|
|
|
riscv_csr_op_fn op;
|
2022-01-07 00:01:08 +03:00
|
|
|
riscv_csr_read128_fn read128;
|
|
|
|
riscv_csr_write128_fn write128;
|
2022-03-03 21:54:37 +03:00
|
|
|
/* The default priv spec version should be PRIV_VERSION_1_10_0 (i.e 0) */
|
|
|
|
uint32_t min_priv_ver;
|
2019-01-05 02:23:55 +03:00
|
|
|
} riscv_csr_operations;
|
|
|
|
|
2021-01-12 07:52:01 +03:00
|
|
|
/* CSR function table constants */
|
|
|
|
enum {
|
|
|
|
CSR_TABLE_SIZE = 0x1000
|
|
|
|
};
|
|
|
|
|
2023-04-05 11:58:12 +03:00
|
|
|
/*
|
2022-08-25 01:16:57 +03: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,
|
|
|
|
};
|
|
|
|
|
2021-01-12 07:52:01 +03:00
|
|
|
/* CSR function table */
|
2021-01-19 05:52:03 +03:00
|
|
|
extern riscv_csr_operations csr_ops[CSR_TABLE_SIZE];
|
2021-01-12 07:52:01 +03: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 16:12:50 +03:00
|
|
|
extern const bool valid_vm_1_10_32[], valid_vm_1_10_64[];
|
|
|
|
|
2019-01-05 02:23:55 +03: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 15:31:10 +03:00
|
|
|
|
2019-03-15 13:26:59 +03: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 16:12:50 +03: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 15:31:10 +03:00
|
|
|
#endif /* RISCV_CPU_H */
|