forked from riscv-collab/riscv-openocd
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
target/riscv: separate register cache stuff into files
This commits creates file structure for register cache related functions. Specifically: * `riscv_reg.h` -- general interface to registers. Safe to use after register cache initialization is successful. * `riscv_reg_impl.h` -- helper functions to use while implementing register cache initialization. * `riscv_reg.c` -- definitions of functions from `riscv_reg.h` and `riscv_reg_impl.h`. * `riscv-011_reg.h` -- register cache interface specific to 0.11 targets. * `riscv-013_reg.h` -- register cache interface specific to 0.13+ targets. * `riscv-011/0.13.h` -- version-specific methods used to access registers. Will be extended as needed once other functionality (not related to register access) is separated (e.g. DM/DTM specific stuff). Checkpatch-ignore: SPDX_LICENSE_TAG Change-Id: I7918f78d0d79b97188c5703efd0296660e529f2a Signed-off-by: Evgeniy Naydanov <[email protected]>
- Loading branch information
Showing
16 changed files
with
1,548 additions
and
1,374 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#ifndef OPENOCD_TARGET_RISCV_RISCV_011_H | ||
#define OPENOCD_TARGET_RISCV_RISCV_011_H | ||
|
||
#include "riscv.h" | ||
#include "gdb_regs.h" | ||
#include "target/target.h" | ||
|
||
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); | ||
|
||
#endif /*OPENOCD_TARGET_RISCV_RISCV_011_H*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#ifdef HAVE_CONFIG_H | ||
#include "config.h" | ||
#endif | ||
|
||
#include "riscv-011_reg.h" | ||
|
||
#include "riscv_reg_impl.h" | ||
#include "riscv-011.h" | ||
|
||
static int riscv011_reg_get(struct reg *reg) | ||
{ | ||
struct target * const target = get_target_from_reg(reg); | ||
riscv_reg_t value; | ||
const int result = riscv011_get_register(target, &value, reg->number); | ||
if (result != ERROR_OK) | ||
return result; | ||
buf_set_u64(reg->value, 0, reg->size, value); | ||
return ERROR_OK; | ||
} | ||
|
||
static int riscv011_reg_set(struct reg *reg, uint8_t *buf) | ||
{ | ||
const riscv_reg_t value = buf_get_u64(buf, 0, reg->size); | ||
struct target * const target = get_target_from_reg(reg); | ||
return riscv011_set_register(target, reg->number, value); | ||
} | ||
|
||
static const struct reg_arch_type *riscv011_gdb_regno_reg_type(uint32_t regno) | ||
{ | ||
static const struct reg_arch_type riscv011_reg_type = { | ||
.get = riscv011_reg_get, | ||
.set = riscv011_reg_set | ||
}; | ||
return &riscv011_reg_type; | ||
} | ||
|
||
static int riscv011_init_reg(struct target *target, uint32_t regno) | ||
{ | ||
return init_reg(target, regno, riscv011_gdb_regno_reg_type(regno)); | ||
} | ||
|
||
int riscv011_init_registers(struct target *target) | ||
{ | ||
//TODO move to init | ||
if (riscv_init_reg_cache(target) != ERROR_OK) | ||
return ERROR_FAIL; | ||
|
||
init_shared_reg_info(target); | ||
|
||
for (uint32_t regno = 0; regno < target->reg_cache->num_regs; ++regno) | ||
if (riscv011_init_reg(target, regno) != ERROR_OK) | ||
return ERROR_FAIL; | ||
|
||
if (expose_csrs(target) != ERROR_OK) | ||
return ERROR_FAIL; | ||
|
||
hide_csrs(target); | ||
|
||
return ERROR_OK; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef OPENOCD_TARGET_RISCV_RISCV_REG_011_H | ||
#define OPENOCD_TARGET_RISCV_RISCV_REG_011_H | ||
|
||
#include "target/target.h" | ||
|
||
/** | ||
* This file describes additional register cache interface available to the | ||
* RISC-V Debug Specification v0.11 targets. | ||
*/ | ||
|
||
/** | ||
* Initialize register cache. After this function all registers can be | ||
* safely accessed via functions described here and in `riscv_reg.h`. | ||
*/ | ||
int riscv011_init_registers(struct target *target); | ||
|
||
#endif /*OPENOCD_TARGET_RISCV_RISCV_REG_011_H*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef OPENOCD_TARGET_RISCV_RISCV_013_H | ||
#define OPENOCD_TARGET_RISCV_RISCV_013_H | ||
|
||
#include "riscv.h" | ||
|
||
/** | ||
* TODO: This functions will be and replaced here by specific access methods | ||
* (e.g. abstract commands, program buffer writes and so on.), while specifics | ||
* on how to use them to get a register's value will be in `riscv-013_reg.c`. | ||
*/ | ||
int riscv013_get_register(struct target *target, | ||
riscv_reg_t *value, enum gdb_regno rid); | ||
int riscv013_get_register_buf(struct target *target, uint8_t *value, | ||
enum gdb_regno regno); | ||
int riscv013_set_register(struct target *target, enum gdb_regno rid, | ||
riscv_reg_t value); | ||
int riscv013_set_register_buf(struct target *target, enum gdb_regno regno, | ||
const uint8_t *value); | ||
|
||
#endif /*OPENOCD_TARGET_RISCV_RISCV_013_H*/ |
Oops, something went wrong.