2022-03-15 09:55:23 +03:00
|
|
|
/*
|
|
|
|
* QEMU RISC-V Native Debug Support
|
|
|
|
*
|
|
|
|
* Copyright (c) 2022 Wind River Systems, Inc.
|
|
|
|
*
|
|
|
|
* Author:
|
|
|
|
* Bin Meng <bin.meng@windriver.com>
|
|
|
|
*
|
|
|
|
* 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_DEBUG_H
|
|
|
|
#define RISCV_DEBUG_H
|
|
|
|
|
2024-03-26 20:37:25 +03:00
|
|
|
#include "exec/breakpoint.h"
|
|
|
|
|
2022-09-09 16:42:08 +03:00
|
|
|
#define RV_MAX_TRIGGERS 2
|
2022-03-15 09:55:23 +03:00
|
|
|
|
|
|
|
/* register index of tdata CSRs */
|
|
|
|
enum {
|
|
|
|
TDATA1 = 0,
|
|
|
|
TDATA2,
|
|
|
|
TDATA3,
|
|
|
|
TDATA_NUM
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
TRIGGER_TYPE_NO_EXIST = 0, /* trigger does not exist */
|
|
|
|
TRIGGER_TYPE_AD_MATCH = 2, /* address/data match trigger */
|
|
|
|
TRIGGER_TYPE_INST_CNT = 3, /* instruction count trigger */
|
|
|
|
TRIGGER_TYPE_INT = 4, /* interrupt trigger */
|
|
|
|
TRIGGER_TYPE_EXCP = 5, /* exception trigger */
|
|
|
|
TRIGGER_TYPE_AD_MATCH6 = 6, /* new address/data match trigger */
|
|
|
|
TRIGGER_TYPE_EXT_SRC = 7, /* external source trigger */
|
2022-09-09 16:42:08 +03:00
|
|
|
TRIGGER_TYPE_UNAVAIL = 15, /* trigger exists, but unavailable */
|
|
|
|
TRIGGER_TYPE_NUM
|
2022-03-15 09:55:23 +03:00
|
|
|
} trigger_type_t;
|
|
|
|
|
2022-09-09 16:42:13 +03:00
|
|
|
/* actions */
|
|
|
|
typedef enum {
|
|
|
|
DBG_ACTION_NONE = -1, /* sentinel value */
|
|
|
|
DBG_ACTION_BP = 0,
|
|
|
|
DBG_ACTION_DBG_MODE,
|
|
|
|
DBG_ACTION_TRACE0,
|
|
|
|
DBG_ACTION_TRACE1,
|
|
|
|
DBG_ACTION_TRACE2,
|
|
|
|
DBG_ACTION_TRACE3,
|
|
|
|
DBG_ACTION_EXT_DBG0 = 8,
|
|
|
|
DBG_ACTION_EXT_DBG1
|
|
|
|
} trigger_action_t;
|
|
|
|
|
2022-09-09 16:42:08 +03:00
|
|
|
/* tdata1 field masks */
|
2022-03-15 09:55:23 +03:00
|
|
|
|
|
|
|
#define RV32_TYPE(t) ((uint32_t)(t) << 28)
|
|
|
|
#define RV32_TYPE_MASK (0xf << 28)
|
|
|
|
#define RV32_DMODE BIT(27)
|
2022-09-09 16:42:09 +03:00
|
|
|
#define RV32_DATA_MASK 0x7ffffff
|
2022-03-15 09:55:23 +03:00
|
|
|
#define RV64_TYPE(t) ((uint64_t)(t) << 60)
|
|
|
|
#define RV64_TYPE_MASK (0xfULL << 60)
|
|
|
|
#define RV64_DMODE BIT_ULL(59)
|
2022-09-09 16:42:09 +03:00
|
|
|
#define RV64_DATA_MASK 0x7ffffffffffffff
|
2022-03-15 09:55:23 +03:00
|
|
|
|
|
|
|
/* mcontrol field masks */
|
|
|
|
|
|
|
|
#define TYPE2_LOAD BIT(0)
|
|
|
|
#define TYPE2_STORE BIT(1)
|
|
|
|
#define TYPE2_EXEC BIT(2)
|
|
|
|
#define TYPE2_U BIT(3)
|
|
|
|
#define TYPE2_S BIT(4)
|
|
|
|
#define TYPE2_M BIT(6)
|
|
|
|
#define TYPE2_MATCH (0xf << 7)
|
|
|
|
#define TYPE2_CHAIN BIT(11)
|
|
|
|
#define TYPE2_ACTION (0xf << 12)
|
|
|
|
#define TYPE2_SIZELO (0x3 << 16)
|
|
|
|
#define TYPE2_TIMING BIT(18)
|
|
|
|
#define TYPE2_SELECT BIT(19)
|
|
|
|
#define TYPE2_HIT BIT(20)
|
|
|
|
#define TYPE2_SIZEHI (0x3 << 21) /* RV64 only */
|
|
|
|
|
2022-09-09 16:42:15 +03:00
|
|
|
/* mcontrol6 field masks */
|
|
|
|
|
|
|
|
#define TYPE6_LOAD BIT(0)
|
|
|
|
#define TYPE6_STORE BIT(1)
|
|
|
|
#define TYPE6_EXEC BIT(2)
|
|
|
|
#define TYPE6_U BIT(3)
|
|
|
|
#define TYPE6_S BIT(4)
|
|
|
|
#define TYPE6_M BIT(6)
|
|
|
|
#define TYPE6_MATCH (0xf << 7)
|
|
|
|
#define TYPE6_CHAIN BIT(11)
|
|
|
|
#define TYPE6_ACTION (0xf << 12)
|
|
|
|
#define TYPE6_SIZE (0xf << 16)
|
|
|
|
#define TYPE6_TIMING BIT(20)
|
|
|
|
#define TYPE6_SELECT BIT(21)
|
|
|
|
#define TYPE6_HIT BIT(22)
|
|
|
|
#define TYPE6_VU BIT(23)
|
|
|
|
#define TYPE6_VS BIT(24)
|
|
|
|
|
2022-03-15 09:55:23 +03:00
|
|
|
/* access size */
|
|
|
|
enum {
|
|
|
|
SIZE_ANY = 0,
|
|
|
|
SIZE_1B,
|
|
|
|
SIZE_2B,
|
|
|
|
SIZE_4B,
|
|
|
|
SIZE_6B,
|
|
|
|
SIZE_8B,
|
|
|
|
SIZE_10B,
|
|
|
|
SIZE_12B,
|
|
|
|
SIZE_14B,
|
|
|
|
SIZE_16B,
|
|
|
|
SIZE_NUM = 16
|
|
|
|
};
|
|
|
|
|
2022-10-13 09:29:43 +03:00
|
|
|
/* itrigger filed masks */
|
|
|
|
#define ITRIGGER_ACTION 0x3f
|
|
|
|
#define ITRIGGER_U BIT(6)
|
|
|
|
#define ITRIGGER_S BIT(7)
|
|
|
|
#define ITRIGGER_PENDING BIT(8)
|
|
|
|
#define ITRIGGER_M BIT(9)
|
|
|
|
#define ITRIGGER_COUNT (0x3fff << 10)
|
|
|
|
#define ITRIGGER_HIT BIT(24)
|
|
|
|
#define ITRIGGER_VU BIT(25)
|
|
|
|
#define ITRIGGER_VS BIT(26)
|
|
|
|
|
target/riscv: Add textra matching condition for the triggers
According to RISC-V Debug specification, the optional textra32 and
textra64 trigger CSRs can be used to configure additional matching
conditions for the triggers. For example, if the textra.MHSELECT field
is set to 4 (mcontext), this trigger will only match or fire if the low
bits of mcontext/hcontext equal textra.MHVALUE field.
This commit adds the aforementioned matching condition as common trigger
matching conditions. Currently, the only legal values of textra.MHSELECT
are 0 (ignore) and 4 (mcontext). When textra.MHSELECT is 0, we pass the
checking. When textra.MHSELECT is 4, we compare textra.MHVALUE with
mcontext CSR. The remaining fields, such as textra.SBYTEMASK,
textra.SVALUE, and textra.SSELECT, are hardwired to zero for now. Thus,
we skip checking them here.
Signed-off-by: Alvin Chang <alvinga@andestech.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20240826024657.262553-3-alvinga@andestech.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2024-08-26 05:46:57 +03:00
|
|
|
#define MHSELECT_IGNORE 0
|
|
|
|
#define MHSELECT_MCONTEXT 4
|
|
|
|
|
2022-03-15 09:55:23 +03:00
|
|
|
bool tdata_available(CPURISCVState *env, int tdata_index);
|
|
|
|
|
|
|
|
target_ulong tselect_csr_read(CPURISCVState *env);
|
|
|
|
void tselect_csr_write(CPURISCVState *env, target_ulong val);
|
|
|
|
|
|
|
|
target_ulong tdata_csr_read(CPURISCVState *env, int tdata_index);
|
|
|
|
void tdata_csr_write(CPURISCVState *env, int tdata_index, target_ulong val);
|
|
|
|
|
2022-09-09 16:42:12 +03:00
|
|
|
target_ulong tinfo_csr_read(CPURISCVState *env);
|
|
|
|
|
2022-04-21 03:33:19 +03:00
|
|
|
void riscv_cpu_debug_excp_handler(CPUState *cs);
|
|
|
|
bool riscv_cpu_debug_check_breakpoint(CPUState *cs);
|
|
|
|
bool riscv_cpu_debug_check_watchpoint(CPUState *cs, CPUWatchpoint *wp);
|
|
|
|
|
2023-08-18 06:40:58 +03:00
|
|
|
void riscv_trigger_realize(CPURISCVState *env);
|
|
|
|
void riscv_trigger_reset_hold(CPURISCVState *env);
|
2022-04-21 03:33:21 +03:00
|
|
|
|
2022-10-13 09:29:43 +03:00
|
|
|
bool riscv_itrigger_enabled(CPURISCVState *env);
|
2022-10-13 09:29:44 +03:00
|
|
|
void riscv_itrigger_update_priv(CPURISCVState *env);
|
2022-03-15 09:55:23 +03:00
|
|
|
#endif /* RISCV_DEBUG_H */
|