-
Notifications
You must be signed in to change notification settings - Fork 319
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 commit 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). Change-Id: I7918f78d0d79b97188c5703efd0296660e529f2a Signed-off-by: Evgeniy Naydanov <evgeniy.naydanov@syntacore.com>
- Loading branch information
Showing
17 changed files
with
1,679 additions
and
1,488 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
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,15 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
|
||
#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,61 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
#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 = riscv_reg_impl_get_target(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 = riscv_reg_impl_get_target(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 riscv_reg_impl_init_one(target, regno, riscv011_gdb_regno_reg_type(regno)); | ||
} | ||
|
||
int riscv011_reg_init_all(struct target *target) | ||
{ | ||
if (riscv_reg_imp_init_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 (riscv_reg_impl_expose_csrs(target) != ERROR_OK) | ||
return ERROR_FAIL; | ||
|
||
riscv_reg_impl_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,19 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
|
||
#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_reg_init_all(struct target *target); | ||
|
||
#endif /*OPENOCD_TARGET_RISCV_RISCV_REG_011_H*/ |
Oops, something went wrong.