93 #define DECLARE_CSR(csr_name, number)[(number) + GDB_REGNO_CSR0] = #csr_name,
102 if (!
info->custom_register_names.reg_names)
105 for (
unsigned int i = 0; i <
info->custom_register_names.num_entries; i++)
106 free(
info->custom_register_names.reg_names[i]);
107 free(
info->custom_register_names.reg_names);
108 info->custom_register_names.reg_names =
NULL;
115 if (!
info->reg_names)
119 free(
info->reg_names[i]);
120 free(
info->reg_names);
134 assert(entry->
low == entry->
high);
137 if (
info->reg_names[regno])
139 info->reg_names[regno] = strdup(entry->
name);
140 if (!
info->reg_names[regno])
141 LOG_ERROR(
"Failed to allocate memory for a register name");
150 assert(
info->custom_register_names.reg_names);
151 assert(regno - GDB_REGNO_COUNT <= info->custom_register_names.num_entries);
155 if (!
info->reg_names)
158 if (
info->reg_names[regno])
159 return info->reg_names[regno];
164 if (!
info->reg_names[regno])
165 LOG_ERROR(
"Failed to allocate memory for a register name");
166 return info->reg_names[regno];
170 if (!
info->reg_names[regno])
171 LOG_ERROR(
"Failed to allocate memory for a register name");
172 return info->reg_names[regno];
176 if (!
info->reg_names[regno])
178 if (!
info->reg_names[regno])
179 LOG_ERROR(
"Failed to allocate memory for a register name");
180 return info->reg_names[regno];
182 assert(!
"Encountered uninitialized entry in reg_names table");
197 .
name =
"org.gnu.gdb.riscv.cpu"
206 .
name =
"org.gnu.gdb.riscv.fpu"
212 .
name =
"org.gnu.gdb.riscv.vector"
214 return &feature_vector;
218 .
name =
"org.gnu.gdb.riscv.csr"
224 .
name =
"org.gnu.gdb.riscv.virtual"
226 return &feature_virtual;
230 .
name =
"org.gnu.gdb.riscv.custom"
232 return &feature_custom;
255 {
"float", &type_ieee_single, single_double_fields + 1},
256 {
"double", &type_ieee_double,
NULL},
259 .
fields = single_double_fields
265 {.reg_type_union = &single_double_union}
268 &type_ieee_single_double :
273 return &
info->type_vector;
307 switch (csr_number) {
339 #define DECLARE_CSR(csr_name, number)[number] = true,
345 return is_csr_in_buf[csr_num];
355 &&
"Existence of other registers is determined "
356 "depending on existence of these ones, so "
357 "whether these register exist or not should be "
375 switch (csr_number) {
537 unsigned int start = 0;
541 assert(regno >= regno_start);
542 offset = regno - regno_start;
543 const unsigned int regs_in_range =
range->high -
range->low + 1;
544 if (
offset < regs_in_range)
546 regno_start += regs_in_range;
623 unsigned int custom_regs_num = 0;
627 custom_regs_num += entry->
high - entry->
low + 1;
630 if (!custom_regs_num)
633 custom_register_names->
reg_names = calloc(custom_regs_num,
sizeof(
char *));
635 LOG_ERROR(
"Failed to allocate memory for custom_register_names->reg_names");
638 custom_register_names->
num_entries = custom_regs_num;
639 char **reg_names = custom_register_names->
reg_names;
641 unsigned int next_custom_reg_index = 0;
643 for (
unsigned int custom_number =
range->low; custom_number <= range->high; ++custom_number) {
645 reg_names[next_custom_reg_index] = strdup(
range->name);
647 reg_names[next_custom_reg_index] =
650 if (!reg_names[next_custom_reg_index]) {
651 LOG_ERROR(
"Failed to allocate memory for a register name");
654 ++next_custom_reg_index;
696 assert(entry->
low <= entry->
high);
700 regno <= last_regno; ++regno) {
705 "Not exposing CSR %d: register already exists.",
726 regno <= last_regno; ++regno) {
731 "Not hiding CSR %d: register does not exist.",
828 "Target not halted, writing to target: %s <- 0x%" PRIx64,
837 if (!cacheable || (write_through && need_to_write)) {
839 "Writing to target: %s <- 0x%" PRIx64
" (cacheable=%s, valid=%s, dirty=%s)",
855 "Wrote 0x%" PRIx64
" to %s (cacheable=%s, valid=%s, dirty=%s)",
864 bool any_dirty =
false;
static uint64_t buf_get_u64(const uint8_t *_buffer, unsigned int first, unsigned int num)
Retrieves num bits from _buffer, starting at the first bit, returning the bits in a 64-bit word.
static void buf_set_u64(uint8_t *_buffer, unsigned int first, unsigned int num, uint64_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
#define DTM_DTMCS_VERSION_0_11
uint32_t size
Size of dw_spi_transaction::buffer.
#define CSR_MHPMCOUNTER17H
#define CSR_HPMCOUNTER25H
#define CSR_MHPMCOUNTER7H
#define CSR_MHPMCOUNTER27H
#define CSR_HPMCOUNTER22H
#define CSR_MHPMCOUNTER18H
#define CSR_MHPMCOUNTER21H
#define CSR_HPMCOUNTER15H
#define CSR_HPMCOUNTER12H
#define CSR_HPMCOUNTER19H
#define CSR_MHPMCOUNTER28H
#define CSR_MHPMCOUNTER9H
#define CSR_MHPMCOUNTER29H
#define CSR_MHPMCOUNTER10H
#define CSR_MHPMCOUNTER11H
#define CSR_MHPMCOUNTER12H
#define CSR_HPMCOUNTER31H
#define CSR_MHPMCOUNTER25H
#define CSR_MHPMCOUNTER26H
#define CSR_HPMCOUNTER27H
#define CSR_HPMCOUNTER17H
#define CSR_MHPMCOUNTER5H
#define CSR_HPMCOUNTER21H
#define CSR_MHPMCOUNTER24H
#define CSR_HPMCOUNTER18H
#define CSR_MHPMCOUNTER8H
#define CSR_HPMCOUNTER14H
#define CSR_MHPMCOUNTER20H
#define CSR_HPMCOUNTER28H
#define CSR_MHPMCOUNTER31H
#define CSR_MCOUNTINHIBIT
#define CSR_MHPMCOUNTER6H
#define CSR_HPMCOUNTER16H
#define CSR_MHPMCOUNTER23H
#define CSR_HPMCOUNTER20H
#define CSR_MHPMCOUNTER15H
#define CSR_HPMCOUNTER23H
#define CSR_HPMCOUNTER30H
#define CSR_MHPMCOUNTER14H
#define CSR_HPMCOUNTER13H
#define CSR_MHPMCOUNTER13H
#define CSR_HPMCOUNTER26H
#define CSR_MHPMCOUNTER4H
#define CSR_HPMCOUNTER11H
#define CSR_HPMCOUNTER24H
#define CSR_MHPMCOUNTER22H
#define CSR_HPMCOUNTER29H
#define CSR_HPMCOUNTER10H
#define CSR_MHPMCOUNTER19H
#define CSR_MHPMCOUNTER16H
#define CSR_MHPMCOUNTER30H
enum esirisc_reg_num number
static uint64_t set_field(uint64_t reg, uint64_t mask, uint64_t val)
static uint64_t get_field(uint64_t reg, uint64_t mask)
static int list_empty(const struct list_head *head)
#define list_for_each_entry(p, h, field)
void log_printf_lf(enum log_levels level, const char *file, unsigned int line, const char *function, const char *format,...)
char * alloc_printf(const char *format,...)
#define LOG_TARGET_WARNING(target, fmt_str,...)
#define LOG_TARGET_ERROR(target, fmt_str,...)
#define LOG_TARGET_DEBUG(target, fmt_str,...)
#define LOG_TARGET_DEBUG_IO(target, fmt_str,...)
#define LOG_ERROR(expr ...)
void register_cache_invalidate(struct reg_cache *cache)
Marks the contents of the register cache as invalid (and clean).
int riscv011_get_register(struct target *target, riscv_reg_t *value, enum gdb_regno regid)
int riscv011_set_register(struct target *target, enum gdb_regno regid, riscv_reg_t value)
int riscv013_set_register(struct target *target, enum gdb_regno rid, riscv_reg_t value)
int riscv013_get_register(struct target *target, riscv_reg_t *value, enum gdb_regno rid)
unsigned int riscv_xlen(const struct target *target)
bool riscv_supports_extension(const struct target *target, char letter)
unsigned int riscv_vlenb(const struct target *target)
int riscv_reg_impl_set_exist(const struct target *target, uint32_t regno, bool exist)
Mark register as existing or not.
static struct reg_feature * gdb_regno_feature(uint32_t regno)
static int riscv_set_or_write_register(struct target *target, enum gdb_regno regid, riscv_reg_t value, bool write_through)
This function is used internally by functions that change register values.
void riscv_reg_impl_hide_csrs(const struct target *target)
Hide additional CSRs, as specified by riscv_info_t::hide_csr list.
static int resize_reg(const struct target *target, uint32_t regno, bool exist, uint32_t size)
bool riscv_reg_impl_gdb_regno_exist(const struct target *target, uint32_t regno)
For most registers, returns whether they exist or not.
static bool reg_exists(const struct target *target, uint32_t regno)
static int init_custom_register_names(struct list_head *expose_custom, struct reg_name_table *custom_register_names)
struct target * riscv_reg_impl_get_target(const struct reg *reg)
Return the target that owns the cache entry.
static unsigned int gdb_regno_custom_number(const struct target *target, uint32_t regno)
int riscv_reg_set(struct target *target, enum gdb_regno regid, riscv_reg_t value)
This function is used to change the value of a register.
void riscv_reg_cache_invalidate_all(struct target *target)
Invalidate all registers - forget their cached register values.
static void init_custom_csr_names(const struct target *target)
const char * riscv_reg_gdb_regno_name(const struct target *target, enum gdb_regno regno)
This file describes the register cache interface available to the RISC-V target.
int riscv_reg_impl_expose_csrs(const struct target *target)
Expose additional CSRs, as specified by riscv_info_t::expose_csr list.
int riscv_reg_impl_init_cache_entry(struct target *target, uint32_t regno, bool exist, const struct reg_arch_type *reg_type)
Initialize register.
static void free_reg_names(struct target *target)
int riscv_reg_impl_init_cache(struct target *target)
Initialize register cache.
static struct reg_data_type * gdb_regno_reg_data_type(const struct target *target, uint32_t regno)
static bool vlenb_exists(const struct target *target)
uint32_t gdb_regno_size(const struct target *target, uint32_t regno)
int riscv_reg_flush_all(struct target *target)
Write all dirty registers to the target.
static bool is_known_standard_csr(unsigned int csr_num)
static const char * gdb_regno_group(uint32_t regno)
int riscv_reg_get(struct target *target, riscv_reg_t *value, enum gdb_regno regid)
This function is used to get the value of a register.
static const char *const default_reg_names[GDB_REGNO_COUNT]
TODO: Currently reg->get/set is implemented in terms of riscv_get/set_register.
struct reg * riscv_reg_impl_cache_entry(const struct target *target, uint32_t number)
Return the entry in the register cache of the target.
static void free_custom_register_names(struct target *target)
int riscv_reg_write(struct target *target, enum gdb_regno regid, riscv_reg_t value)
This function is used to change the value of a register.
void riscv_reg_free_all(struct target *target)
Free register cache and associated structures.
bool riscv_reg_cache_any_dirty(const struct target *target, int log_level)
Check whether there are any dirty registers in the OpenOCD's register cache.
static bool gdb_regno_caller_save(uint32_t regno)
static bool riscv_reg_impl_is_initialized(const struct reg *reg)
This file describes the helpers to use during register cache initialization of a RISC-V target.
static bool riscv_reg_impl_gdb_regno_cacheable(enum gdb_regno regno, bool is_write)
If write is true: return true iff we are guaranteed that the register will contain exactly the value ...
struct reg_data_type_union_field * fields
struct reg_feature * feature
struct reg_data_type * reg_data_type
const struct reg_arch_type * type
unsigned int custom_number
struct reg_cache * reg_cache
static const char * target_name(const struct target *target)
Returns the instance-specific name of the specified target.
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.
#define DIV_ROUND_UP(m, n)
Rounds m up to the nearest multiple of n using division.
static struct ublast_lowlevel_priv info