Clean up return type of riscv_progbuf_size() + related

SSIA

Change-Id: I3e0b2fad84411c530f56cdbe33f3d8b4dbf81cf6
Signed-off-by: Jan Matyas <jan.matyas@codasip.com>
This commit is contained in:
Jan Matyas 2025-02-28 11:20:10 +01:00
parent b272470dff
commit 64f30dc279
5 changed files with 11 additions and 13 deletions

View File

@ -20,7 +20,7 @@ int riscv_program_init(struct riscv_program *p, struct target *target)
p->target = target; p->target = target;
p->instruction_count = 0; p->instruction_count = 0;
for (size_t i = 0; i < RISCV_MAX_PROGBUF_SIZE; ++i) for (unsigned int i = 0; i < RISCV013_MAX_PROGBUF_SIZE; ++i)
p->progbuf[i] = (uint32_t)(-1); p->progbuf[i] = (uint32_t)(-1);
p->execution_result = RISCV_PROGBUF_EXEC_RESULT_NOT_EXECUTED; p->execution_result = RISCV_PROGBUF_EXEC_RESULT_NOT_EXECUTED;
@ -47,9 +47,9 @@ int riscv_program_exec(struct riscv_program *p, struct target *t)
if (riscv_program_ebreak(p) != ERROR_OK) { if (riscv_program_ebreak(p) != ERROR_OK) {
LOG_TARGET_ERROR(t, "Unable to insert ebreak into program buffer"); LOG_TARGET_ERROR(t, "Unable to insert ebreak into program buffer");
for (size_t i = 0; i < riscv_progbuf_size(p->target); ++i) for (unsigned int i = 0; i < riscv_progbuf_size(p->target); ++i)
LOG_TARGET_ERROR(t, "progbuf[%02x]: DASM(0x%08" PRIx32 ") [0x%08" PRIx32 "]", LOG_TARGET_ERROR(t, "progbuf[%02x]: DASM(0x%08" PRIx32 ") [0x%08" PRIx32 "]",
(int)i, p->progbuf[i], p->progbuf[i]); i, p->progbuf[i], p->progbuf[i]);
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -198,8 +198,8 @@ int riscv_program_insert(struct riscv_program *p, riscv_insn_t i)
{ {
if (p->instruction_count >= riscv_progbuf_size(p->target)) { if (p->instruction_count >= riscv_progbuf_size(p->target)) {
LOG_TARGET_ERROR(p->target, "Unable to insert program into progbuf, " LOG_TARGET_ERROR(p->target, "Unable to insert program into progbuf, "
"capacity would be exceeded (progbufsize=%d).", "capacity would be exceeded (progbufsize=%u).",
(int)riscv_progbuf_size(p->target)); riscv_progbuf_size(p->target));
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -5,9 +5,7 @@
#include "riscv.h" #include "riscv.h"
#define RISCV_MAX_PROGBUF_SIZE 32 #define RISCV013_MAX_PROGBUF_SIZE 16
#define RISCV_REGISTER_COUNT 32
#define RISCV_DSCRATCH_COUNT 2
typedef enum { typedef enum {
RISCV_PROGBUF_EXEC_RESULT_NOT_EXECUTED, RISCV_PROGBUF_EXEC_RESULT_NOT_EXECUTED,
@ -23,10 +21,10 @@ typedef enum {
struct riscv_program { struct riscv_program {
struct target *target; struct target *target;
uint32_t progbuf[RISCV_MAX_PROGBUF_SIZE]; uint32_t progbuf[RISCV013_MAX_PROGBUF_SIZE];
/* Number of 32-bit instructions in the program. */ /* Number of 32-bit instructions in the program. */
size_t instruction_count; unsigned int instruction_count;
/* execution result of the program */ /* execution result of the program */
/* TODO: remove this field. We should make it a parameter to riscv_program_exec */ /* TODO: remove this field. We should make it a parameter to riscv_program_exec */

View File

@ -5338,7 +5338,7 @@ static enum riscv_halt_reason riscv013_halt_reason(struct target *target)
static int riscv013_write_progbuf(struct target *target, unsigned int index, riscv_insn_t data) static int riscv013_write_progbuf(struct target *target, unsigned int index, riscv_insn_t data)
{ {
assert(index < RISCV_MAX_PROGBUF_SIZE); assert(index < RISCV013_MAX_PROGBUF_SIZE);
dm013_info_t *dm = get_dm(target); dm013_info_t *dm = get_dm(target);
if (!dm) if (!dm)

View File

@ -6048,7 +6048,7 @@ static enum riscv_halt_reason riscv_halt_reason(struct target *target)
return r->halt_reason(target); return r->halt_reason(target);
} }
size_t riscv_progbuf_size(struct target *target) unsigned int riscv_progbuf_size(struct target *target)
{ {
RISCV_INFO(r); RISCV_INFO(r);
return r->get_progbufsize(target); return r->get_progbufsize(target);

View File

@ -473,7 +473,7 @@ int riscv_get_hart_state(struct target *target, enum riscv_hart_state *state);
/* These helper functions let the generic program interface get target-specific /* These helper functions let the generic program interface get target-specific
* information. */ * information. */
size_t riscv_progbuf_size(struct target *target); unsigned int riscv_progbuf_size(struct target *target);
riscv_insn_t riscv_read_progbuf(struct target *target, int index); riscv_insn_t riscv_read_progbuf(struct target *target, int index);
int riscv_write_progbuf(struct target *target, unsigned int index, riscv_insn_t insn); int riscv_write_progbuf(struct target *target, unsigned int index, riscv_insn_t insn);