OpenOCD
riscv-011_reg.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 #ifdef HAVE_CONFIG_H
4 #include "config.h"
5 #endif
6 
7 #include "riscv-011_reg.h"
8 
9 #include "riscv_reg_impl.h"
10 #include "riscv-011.h"
11 
12 static int riscv011_reg_get(struct reg *reg)
13 {
14  struct target * const target = riscv_reg_impl_get_target(reg);
15  riscv_reg_t value;
16  const int result = riscv011_get_register(target, &value, reg->number);
17  if (result != ERROR_OK)
18  return result;
19  buf_set_u64(reg->value, 0, reg->size, value);
20  return ERROR_OK;
21 }
22 
23 static int riscv011_reg_set(struct reg *reg, uint8_t *buf)
24 {
25  const riscv_reg_t value = buf_get_u64(buf, 0, reg->size);
26  struct target * const target = riscv_reg_impl_get_target(reg);
27  return riscv011_set_register(target, reg->number, value);
28 }
29 
30 static const struct reg_arch_type *riscv011_gdb_regno_reg_type(uint32_t regno)
31 {
32  static const struct reg_arch_type riscv011_reg_type = {
34  .set = riscv011_reg_set
35  };
36  return &riscv011_reg_type;
37 }
38 
39 
41 {
43  if (res != ERROR_OK)
44  return res;
45 
47 
48  RISCV_INFO(r);
49  assert(!r->vlenb
50  && "VLENB discovery is not supported on RISC-V 0.11 targets");
51  /* Existence of some registers depends on others.
52  * E.g. the presence of "v0-31" registers is infered from "vlenb" being
53  * non-zero.
54  * Currently, discovery of the following registers is not supported on
55  * RISC-V 0.11 targets. */
56  uint32_t non_discoverable_regs[] = {
60  };
61  for (unsigned int i = 0; i < ARRAY_SIZE(non_discoverable_regs); ++i) {
62  const uint32_t regno = non_discoverable_regs[i];
64  /*exist*/ false, riscv011_gdb_regno_reg_type(regno));
65  if (res != ERROR_OK)
66  return res;
67  }
68 
69  for (uint32_t regno = 0; regno < target->reg_cache->num_regs; ++regno) {
70  const struct reg * const reg = riscv_reg_impl_cache_entry(target, regno);
72  continue;
76  if (res != ERROR_OK)
77  return res;
78  }
79 
81  return ERROR_FAIL;
82 
84 
85  return ERROR_OK;
86 }
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.
Definition: binarybuffer.h:134
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.
Definition: binarybuffer.h:65
@ GDB_REGNO_MTOPI
Definition: gdb_regs.h:109
@ GDB_REGNO_MTOPEI
Definition: gdb_regs.h:110
@ GDB_REGNO_VLENB
Definition: gdb_regs.h:90
#define ERROR_FAIL
Definition: log.h:175
#define ERROR_OK
Definition: log.h:169
int riscv011_get_register(struct target *target, riscv_reg_t *value, enum gdb_regno regid)
Definition: riscv-011.c:1344
int riscv011_set_register(struct target *target, enum gdb_regno regid, riscv_reg_t value)
Definition: riscv-011.c:1392
static int riscv011_reg_get(struct reg *reg)
Definition: riscv-011_reg.c:12
int riscv011_reg_init_all(struct target *target)
This file describes additional register cache interface available to the RISC-V Debug Specification v...
Definition: riscv-011_reg.c:40
static int riscv011_reg_set(struct reg *reg, uint8_t *buf)
Definition: riscv-011_reg.c:23
static const struct reg_arch_type * riscv011_gdb_regno_reg_type(uint32_t regno)
Definition: riscv-011_reg.c:30
#define RISCV_INFO(R)
Definition: riscv.h:426
uint64_t riscv_reg_t
Definition: riscv.h:46
void riscv_reg_impl_hide_csrs(const struct target *target)
Hide additional CSRs, as specified by riscv_info_t::hide_csr list.
Definition: riscv_reg.c:736
bool riscv_reg_impl_gdb_regno_exist(const struct target *target, uint32_t regno)
For most registers, returns whether they exist or not.
Definition: riscv_reg.c:368
struct target * riscv_reg_impl_get_target(const struct reg *reg)
Return the target that owns the cache entry.
Definition: riscv_reg.c:207
int riscv_reg_impl_expose_csrs(const struct target *target)
Expose additional CSRs, as specified by riscv_info_t::expose_csr list.
Definition: riscv_reg.c:709
int riscv_reg_impl_init_cache_entry(struct target *target, uint32_t regno, bool exist, const struct reg_arch_type *reg_type)
Initialize register.
Definition: riscv_reg.c:608
int riscv_reg_impl_init_cache(struct target *target)
Initialize register cache.
Definition: riscv_reg.c:678
struct reg * riscv_reg_impl_cache_entry(const struct target *target, uint32_t number)
Return the entry in the register cache of the target.
Definition: riscv_reg.c:571
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 void init_shared_reg_info(struct target *target)
int(* get)(struct reg *reg)
Definition: register.h:152
unsigned int num_regs
Definition: register.h:148
Definition: register.h:111
uint32_t size
Definition: register.h:132
uint8_t * value
Definition: register.h:122
uint32_t number
Definition: register.h:115
Definition: target.h:119
struct reg_cache * reg_cache
Definition: target.h:161
#define ARRAY_SIZE(x)
Compute the number of elements of a variable length array.
Definition: types.h:57