Skip to content

Commit a61e727

Browse files
committed
target/riscv: remove duplicate progbufsize field
* removed `progbuf_size` field from `riscv_info`; added getter * moved `impebreak` field from `riscv_info` to `riscv013_info` as implementation dependent field; added getter Signed-off-by: Farid Khaydari <[email protected]>
1 parent 8ea44aa commit a61e727

File tree

5 files changed

+42
-20
lines changed

5 files changed

+42
-20
lines changed

src/target/riscv/program.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ int riscv_program_ebreak(struct riscv_program *p)
183183
{
184184
struct target *target = p->target;
185185
RISCV_INFO(r);
186-
if (p->instruction_count == riscv_progbuf_size(p->target) &&
187-
r->impebreak) {
186+
if (p->instruction_count == riscv_progbuf_size(target) &&
187+
r->get_impebreak(target)) {
188188
return ERROR_OK;
189189
}
190190
return riscv_program_insert(p, ebreak());

src/target/riscv/riscv-011.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,6 +2356,16 @@ static int riscv011_authdata_write(struct target *target, uint32_t value, unsign
23562356
return ERROR_OK;
23572357
}
23582358

2359+
static bool riscv011_get_impebreak(const struct target *target)
2360+
{
2361+
return false;
2362+
}
2363+
2364+
static unsigned int riscv011_get_progbufsize(const struct target *target)
2365+
{
2366+
return 0;
2367+
}
2368+
23592369
static int init_target(struct command_context *cmd_ctx,
23602370
struct target *target)
23612371
{
@@ -2365,6 +2375,8 @@ static int init_target(struct command_context *cmd_ctx,
23652375
generic_info->authdata_read = &riscv011_authdata_read;
23662376
generic_info->authdata_write = &riscv011_authdata_write;
23672377
generic_info->print_info = &riscv011_print_info;
2378+
generic_info->get_impebreak = &riscv011_get_impebreak;
2379+
generic_info->get_progbufsize = &riscv011_get_progbufsize;
23682380

23692381
generic_info->version_specific = calloc(1, sizeof(riscv011_info_t));
23702382
if (!generic_info->version_specific)

src/target/riscv/riscv-013.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ static int read_memory(struct target *target, target_addr_t address,
6767
uint32_t size, uint32_t count, uint8_t *buffer, uint32_t increment);
6868
static int write_memory(struct target *target, target_addr_t address,
6969
uint32_t size, uint32_t count, const uint8_t *buffer);
70+
static bool riscv013_get_impebreak(const struct target *target);
71+
static unsigned int riscv013_get_progbufsize(const struct target *target);
7072

7173
typedef enum {
7274
HALT_GROUP,
@@ -153,7 +155,9 @@ typedef struct {
153155
/* Number of abstract command data registers. */
154156
unsigned datacount;
155157
/* Number of words in the Program Buffer. */
156-
unsigned progbufsize;
158+
unsigned int progbufsize;
159+
/* Hart contains an implicit ebreak at the end of the program buffer. */
160+
bool impebreak;
157161

158162
/* We cache the read-only bits of sbcs here. */
159163
uint32_t sbcs;
@@ -1310,9 +1314,7 @@ static unsigned int register_size(struct target *target, enum gdb_regno number)
13101314
static bool has_sufficient_progbuf(struct target *target, unsigned size)
13111315
{
13121316
RISCV013_INFO(info);
1313-
RISCV_INFO(r);
1314-
1315-
return info->progbufsize + r->impebreak >= size;
1317+
return info->progbufsize + info->impebreak >= size;
13161318
}
13171319

13181320
/**
@@ -2037,14 +2039,13 @@ static int examine(struct target *target)
20372039
LOG_TARGET_INFO(target, "datacount=%d progbufsize=%d",
20382040
info->datacount, info->progbufsize);
20392041

2040-
RISCV_INFO(r);
2041-
r->impebreak = get_field(dmstatus, DM_DMSTATUS_IMPEBREAK);
2042+
info->impebreak = get_field(dmstatus, DM_DMSTATUS_IMPEBREAK);
20422043

20432044
if (!has_sufficient_progbuf(target, 2)) {
20442045
LOG_TARGET_WARNING(target, "We won't be able to execute fence instructions on this "
20452046
"target. Memory may not always appear consistent. "
20462047
"(progbufsize=%d, impebreak=%d)", info->progbufsize,
2047-
r->impebreak);
2048+
info->impebreak);
20482049
}
20492050

20502051
if (info->progbufsize < 4 && riscv_enable_virtual) {
@@ -2060,6 +2061,8 @@ static int examine(struct target *target)
20602061
enum riscv_hart_state state_at_examine_start;
20612062
if (riscv_get_hart_state(target, &state_at_examine_start) != ERROR_OK)
20622063
return ERROR_FAIL;
2064+
2065+
RISCV_INFO(r);
20632066
const bool hart_halted_at_examine_start = state_at_examine_start == RISCV_STATE_HALTED;
20642067
if (!hart_halted_at_examine_start) {
20652068
r->prepped = true;
@@ -2073,10 +2076,6 @@ static int examine(struct target *target)
20732076
target->state = TARGET_HALTED;
20742077
target->debug_reason = hart_halted_at_examine_start ? DBG_REASON_UNDEFINED : DBG_REASON_DBGRQ;
20752078

2076-
/* Without knowing anything else we can at least mess with the
2077-
* program buffer. */
2078-
r->progbuf_size = info->progbufsize;
2079-
20802079
result = riscv013_reg_examine_all(target);
20812080
if (result != ERROR_OK)
20822081
return result;
@@ -2817,6 +2816,8 @@ static int init_target(struct command_context *cmd_ctx,
28172816
generic_info->read_memory = read_memory;
28182817
generic_info->data_bits = &riscv013_data_bits;
28192818
generic_info->print_info = &riscv013_print_info;
2819+
generic_info->get_impebreak = &riscv013_get_impebreak;
2820+
generic_info->get_progbufsize = &riscv013_get_progbufsize;
28202821

28212822
generic_info->handle_became_unavailable = &handle_became_unavailable;
28222823
generic_info->tick = &tick;
@@ -4872,6 +4873,18 @@ static int write_memory(struct target *target, target_addr_t address,
48724873
return ret;
48734874
}
48744875

4876+
static bool riscv013_get_impebreak(const struct target *target)
4877+
{
4878+
RISCV013_INFO(r);
4879+
return r->impebreak;
4880+
}
4881+
4882+
static unsigned int riscv013_get_progbufsize(const struct target *target)
4883+
{
4884+
RISCV013_INFO(r);
4885+
return r->progbufsize;
4886+
}
4887+
48754888
static int arch_state(struct target *target)
48764889
{
48774890
return ERROR_OK;

src/target/riscv/riscv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5569,7 +5569,7 @@ static enum riscv_halt_reason riscv_halt_reason(struct target *target)
55695569
size_t riscv_progbuf_size(struct target *target)
55705570
{
55715571
RISCV_INFO(r);
5572-
return r->progbuf_size;
5572+
return r->get_progbufsize(target);
55735573
}
55745574

55755575
int riscv_write_progbuf(struct target *target, int index, riscv_insn_t insn)

src/target/riscv/riscv.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,6 @@ struct riscv_info {
167167
* most recent halt was not caused by a trigger, then this is -1. */
168168
int64_t trigger_hit;
169169

170-
/* The number of entries in the program buffer. */
171-
int progbuf_size;
172-
173-
/* This hart contains an implicit ebreak at the end of the program buffer. */
174-
bool impebreak;
175-
176170
bool triggers_enumerated;
177171

178172
/* Decremented every scan, and when it reaches 0 we clear the learned
@@ -236,6 +230,9 @@ struct riscv_info {
236230
int (*dmi_read)(struct target *target, uint32_t *value, uint32_t address);
237231
int (*dmi_write)(struct target *target, uint32_t address, uint32_t value);
238232

233+
bool (*get_impebreak)(const struct target *target);
234+
unsigned int (*get_progbufsize)(const struct target *target);
235+
239236
/* Get the DMI address of target's DM's register.
240237
* The function should return the passed address
241238
* if the target is not assigned a DM yet.

0 commit comments

Comments
 (0)