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);
128 const int size_buf = strlen(
name) + 1;
130 char *
const buf = calloc(size_buf,
sizeof(
char));
132 LOG_ERROR(
"Failed to allocate memory for a register name.");
147 assert(entry->
low == entry->
high);
150 if (
info->reg_names[regno])
159 const int size_buf = snprintf(
NULL, 0,
"%s%d", name_prefix, num) + 1;
161 char *
const buf = calloc(size_buf,
sizeof(
char));
163 LOG_ERROR(
"Failed to allocate memory for a register name.");
166 int result = snprintf(buf, size_buf,
"%s%d", name_prefix, num);
167 assert(result > 0 && result <= (size_buf - 1));
176 assert(
info->custom_register_names.reg_names);
177 assert(regno - GDB_REGNO_COUNT <= info->custom_register_names.num_entries);
181 if (!
info->reg_names)
184 if (
info->reg_names[regno])
185 return info->reg_names[regno];
190 return info->reg_names[regno];
194 return info->reg_names[regno];
198 if (!
info->reg_names[regno])
200 return info->reg_names[regno];
202 assert(!
"Encountered uninitialized entry in reg_names table");
217 .
name =
"org.gnu.gdb.riscv.cpu"
226 .
name =
"org.gnu.gdb.riscv.fpu"
232 .
name =
"org.gnu.gdb.riscv.vector"
234 return &feature_vector;
238 .
name =
"org.gnu.gdb.riscv.csr"
244 .
name =
"org.gnu.gdb.riscv.virtual"
246 return &feature_virtual;
250 .
name =
"org.gnu.gdb.riscv.custom"
252 return &feature_custom;
275 {
"float", &type_ieee_single, single_double_fields + 1},
276 {
"double", &type_ieee_double,
NULL},
279 .
fields = single_double_fields
285 {.reg_type_union = &single_double_union}
288 &type_ieee_single_double :
293 return &
info->type_vector;
327 switch (csr_number) {
359 #define DECLARE_CSR(csr_name, number)[number] = true,
365 return is_csr_in_buf[csr_num];
375 &&
"Existence of other registers is determined "
376 "depending on existence of these ones, so "
377 "whether these register exist or not should be "
395 switch (csr_number) {
557 unsigned int start = 0;
561 assert(regno >= regno_start);
562 offset = regno - regno_start;
563 const unsigned int regs_in_range =
range->high -
range->low + 1;
564 if (
offset < regs_in_range)
566 regno_start += regs_in_range;
643 unsigned int custom_regs_num = 0;
647 custom_regs_num += entry->
high - entry->
low + 1;
650 if (!custom_regs_num)
653 custom_register_names->
reg_names = calloc(custom_regs_num,
sizeof(
char *));
655 LOG_ERROR(
"Failed to allocate memory for custom_register_names->reg_names");
658 custom_register_names->
num_entries = custom_regs_num;
659 char **reg_names = custom_register_names->
reg_names;
661 unsigned int next_custom_reg_index = 0;
663 for (
unsigned int custom_number =
range->low; custom_number <= range->high; ++custom_number) {
667 reg_names[next_custom_reg_index] =
670 if (!reg_names[next_custom_reg_index])
672 ++next_custom_reg_index;
714 assert(entry->
low <= entry->
high);
718 regno <= last_regno; ++regno) {
723 "Not exposing CSR %d: register already exists.",
744 regno <= last_regno; ++regno) {
749 "Not hiding CSR %d: register does not exist.",
846 "Target not halted, writing to target: %s <- 0x%" PRIx64,
855 if (!cacheable || (write_through && need_to_write)) {
857 "Writing to target: %s <- 0x%" PRIx64
" (cacheable=%s, valid=%s, dirty=%s)",
873 "Wrote 0x%" PRIx64
" to %s (cacheable=%s, valid=%s, dirty=%s)",
882 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,...)
#define LOG_TARGET_WARNING(target, fmt_str,...)
#define LOG_TARGET_ERROR(target, fmt_str,...)
#define LOG_TARGET_DEBUG(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 char * init_reg_name(const char *name)
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 char * init_reg_name_with_prefix(const char *name_prefix, unsigned int num)
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