Skip to content

Commit d7a7c98

Browse files
authored
Merge pull request riscv-collab#1125 from fk-sc/fk-sc/field-duplication
target/riscv: remove duplicate of progbufsize field
2 parents 909bbb8 + a61e727 commit d7a7c98

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
@@ -68,6 +68,8 @@ static int read_memory(struct target *target, target_addr_t address,
6868
uint32_t size, uint32_t count, uint8_t *buffer, uint32_t increment);
6969
static int write_memory(struct target *target, target_addr_t address,
7070
uint32_t size, uint32_t count, const uint8_t *buffer);
71+
static bool riscv013_get_impebreak(const struct target *target);
72+
static unsigned int riscv013_get_progbufsize(const struct target *target);
7173

7274
typedef enum {
7375
HALT_GROUP,
@@ -154,7 +156,9 @@ typedef struct {
154156
/* Number of abstract command data registers. */
155157
unsigned datacount;
156158
/* Number of words in the Program Buffer. */
157-
unsigned progbufsize;
159+
unsigned int progbufsize;
160+
/* Hart contains an implicit ebreak at the end of the program buffer. */
161+
bool impebreak;
158162

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

13191321
/**
@@ -2038,14 +2040,13 @@ static int examine(struct target *target)
20382040
LOG_TARGET_INFO(target, "datacount=%d progbufsize=%d",
20392041
info->datacount, info->progbufsize);
20402042

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

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

20512052
if (info->progbufsize < 4 && riscv_enable_virtual) {
@@ -2061,6 +2062,8 @@ static int examine(struct target *target)
20612062
enum riscv_hart_state state_at_examine_start;
20622063
if (riscv_get_hart_state(target, &state_at_examine_start) != ERROR_OK)
20632064
return ERROR_FAIL;
2065+
2066+
RISCV_INFO(r);
20642067
const bool hart_halted_at_examine_start = state_at_examine_start == RISCV_STATE_HALTED;
20652068
if (!hart_halted_at_examine_start) {
20662069
r->prepped = true;
@@ -2074,10 +2077,6 @@ static int examine(struct target *target)
20742077
target->state = TARGET_HALTED;
20752078
target->debug_reason = hart_halted_at_examine_start ? DBG_REASON_UNDEFINED : DBG_REASON_DBGRQ;
20762079

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

28222823
generic_info->handle_became_unavailable = &handle_became_unavailable;
28232824
generic_info->tick = &tick;
@@ -4875,6 +4876,18 @@ static int write_memory(struct target *target, target_addr_t address,
48754876
return ret;
48764877
}
48774878

4879+
static bool riscv013_get_impebreak(const struct target *target)
4880+
{
4881+
RISCV013_INFO(r);
4882+
return r->impebreak;
4883+
}
4884+
4885+
static unsigned int riscv013_get_progbufsize(const struct target *target)
4886+
{
4887+
RISCV013_INFO(r);
4888+
return r->progbufsize;
4889+
}
4890+
48784891
static int arch_state(struct target *target)
48794892
{
48804893
return ERROR_OK;

src/target/riscv/riscv.c

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

55745574
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)