mirror of
https://github.com/qemu/qemu.git
synced 2024-12-02 00:03:35 +08:00
cc0fdb2985
The current PMP check function checks for env->priv which is not the effective memory privilege mode. For example, mstatus.MPRV could be set while executing in M-Mode, and in that case the privilege mode for the PMP check should be S-Mode rather than M-Mode (in env->priv) if mstatus.MPP == PRV_S. This patch passes the effective memory privilege mode to the PMP check. Functions that call the PMP check should pass the correct memory privilege mode after reading mstatus' MPRV/MPP or hstatus.SPRV (if Hypervisor mode exists). Suggested-by: Alistair Francis <alistair.francis@wdc.com> Signed-off-by: Hesham Almatary <Hesham.Almatary@cl.cam.ac.uk> Reviewed-by: Palmer Dabbelt <palmer@sifive.com> Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
65 lines
2.0 KiB
C
65 lines
2.0 KiB
C
/*
|
|
* QEMU RISC-V PMP (Physical Memory Protection)
|
|
*
|
|
* Author: Daire McNamara, daire.mcnamara@emdalo.com
|
|
* Ivan Griffin, ivan.griffin@emdalo.com
|
|
*
|
|
* This provides a RISC-V Physical Memory Protection interface
|
|
*
|
|
* 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_PMP_H
|
|
#define RISCV_PMP_H
|
|
|
|
typedef enum {
|
|
PMP_READ = 1 << 0,
|
|
PMP_WRITE = 1 << 1,
|
|
PMP_EXEC = 1 << 2,
|
|
PMP_LOCK = 1 << 7
|
|
} pmp_priv_t;
|
|
|
|
typedef enum {
|
|
PMP_AMATCH_OFF, /* Null (off) */
|
|
PMP_AMATCH_TOR, /* Top of Range */
|
|
PMP_AMATCH_NA4, /* Naturally aligned four-byte region */
|
|
PMP_AMATCH_NAPOT /* Naturally aligned power-of-two region */
|
|
} pmp_am_t;
|
|
|
|
typedef struct {
|
|
target_ulong addr_reg;
|
|
uint8_t cfg_reg;
|
|
} pmp_entry_t;
|
|
|
|
typedef struct {
|
|
target_ulong sa;
|
|
target_ulong ea;
|
|
} pmp_addr_t;
|
|
|
|
typedef struct {
|
|
pmp_entry_t pmp[MAX_RISCV_PMPS];
|
|
pmp_addr_t addr[MAX_RISCV_PMPS];
|
|
uint32_t num_rules;
|
|
} pmp_table_t;
|
|
|
|
void pmpcfg_csr_write(CPURISCVState *env, uint32_t reg_index,
|
|
target_ulong val);
|
|
target_ulong pmpcfg_csr_read(CPURISCVState *env, uint32_t reg_index);
|
|
void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index,
|
|
target_ulong val);
|
|
target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index);
|
|
bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr,
|
|
target_ulong size, pmp_priv_t priv, target_ulong mode);
|
|
|
|
#endif
|