riscv: replace macro DIM() with ARRAY_SIZE()
OpenOCD already defines the macro ARRAY_SIZE, while riscv code uses a local macro DIM. Prefer using the macro ARRAY_SIZE() instead of DIM(). Not all the riscv code has been upstreamed, yes; this patch only covers the code already upstreamed. Change-Id: I89a58a6d91916d85c53ba5e4091b558271f8d618 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
This commit is contained in:
parent
6f5259db05
commit
9bdd1daec3
|
@ -70,8 +70,6 @@
|
|||
#define get_field(reg, mask) (((reg) & (mask)) / ((mask) & ~((mask) << 1)))
|
||||
#define set_field(reg, mask, val) (((reg) & ~(mask)) | (((val) * ((mask) & ~((mask) << 1))) & (mask)))
|
||||
|
||||
#define DIM(x) (sizeof(x)/sizeof(*x))
|
||||
|
||||
/* Constants for legacy SiFive hardware breakpoints. */
|
||||
#define CSR_BPCONTROL_X (1<<0)
|
||||
#define CSR_BPCONTROL_W (1<<1)
|
||||
|
@ -1634,7 +1632,7 @@ static riscv_error_t handle_halt_routine(struct target *target)
|
|||
|
||||
/* Read S0 from dscratch */
|
||||
unsigned int csr[] = {CSR_DSCRATCH0, CSR_DPC, CSR_DCSR};
|
||||
for (unsigned int i = 0; i < DIM(csr); i++) {
|
||||
for (unsigned int i = 0; i < ARRAY_SIZE(csr); i++) {
|
||||
scans_add_write32(scans, 0, csrr(S0, csr[i]), true);
|
||||
scans_add_read(scans, SLOT0, false);
|
||||
}
|
||||
|
|
|
@ -85,8 +85,6 @@ void read_memory_sba_simple(struct target *target, target_addr_t addr,
|
|||
#define get_field(reg, mask) (((reg) & (mask)) / ((mask) & ~((mask) << 1)))
|
||||
#define set_field(reg, mask, val) (((reg) & ~(mask)) | (((val) * ((mask) & ~((mask) << 1))) & (mask)))
|
||||
|
||||
#define DIM(x) (sizeof(x)/sizeof(*x))
|
||||
|
||||
#define CSR_DCSR_CAUSE_SWBP 1
|
||||
#define CSR_DCSR_CAUSE_TRIGGER 2
|
||||
#define CSR_DCSR_CAUSE_DEBUGINT 3
|
||||
|
@ -361,7 +359,7 @@ static void decode_dmi(char *text, unsigned address, unsigned data)
|
|||
};
|
||||
|
||||
text[0] = 0;
|
||||
for (unsigned i = 0; i < DIM(description); i++) {
|
||||
for (unsigned i = 0; i < ARRAY_SIZE(description); i++) {
|
||||
if (description[i].address == address) {
|
||||
uint64_t mask = description[i].mask;
|
||||
unsigned value = get_field(data, mask);
|
||||
|
|
|
@ -24,8 +24,6 @@
|
|||
#define get_field(reg, mask) (((reg) & (mask)) / ((mask) & ~((mask) << 1)))
|
||||
#define set_field(reg, mask, val) (((reg) & ~(mask)) | (((val) * ((mask) & ~((mask) << 1))) & (mask)))
|
||||
|
||||
#define DIM(x) (sizeof(x)/sizeof(*x))
|
||||
|
||||
/* Constants for legacy SiFive hardware breakpoints. */
|
||||
#define CSR_BPCONTROL_X (1<<0)
|
||||
#define CSR_BPCONTROL_W (1<<1)
|
||||
|
@ -185,10 +183,10 @@ struct scan_field _bscan_tunnel_nested_tap_select_dmi[] = {
|
|||
}
|
||||
};
|
||||
struct scan_field *bscan_tunnel_nested_tap_select_dmi = _bscan_tunnel_nested_tap_select_dmi;
|
||||
uint32_t bscan_tunnel_nested_tap_select_dmi_num_fields = DIM(_bscan_tunnel_nested_tap_select_dmi);
|
||||
uint32_t bscan_tunnel_nested_tap_select_dmi_num_fields = ARRAY_SIZE(_bscan_tunnel_nested_tap_select_dmi);
|
||||
|
||||
struct scan_field *bscan_tunnel_data_register_select_dmi = _bscan_tunnel_data_register_select_dmi;
|
||||
uint32_t bscan_tunnel_data_register_select_dmi_num_fields = DIM(_bscan_tunnel_data_register_select_dmi);
|
||||
uint32_t bscan_tunnel_data_register_select_dmi_num_fields = ARRAY_SIZE(_bscan_tunnel_data_register_select_dmi);
|
||||
|
||||
struct trigger {
|
||||
uint64_t address;
|
||||
|
@ -352,8 +350,8 @@ uint32_t dtmcontrol_scan_via_bscan(struct target *target, uint32_t out)
|
|||
tunneled_dr[0].in_value = NULL;
|
||||
}
|
||||
jtag_add_ir_scan(target->tap, &select_user4, TAP_IDLE);
|
||||
jtag_add_dr_scan(target->tap, DIM(tunneled_ir), tunneled_ir, TAP_IDLE);
|
||||
jtag_add_dr_scan(target->tap, DIM(tunneled_dr), tunneled_dr, TAP_IDLE);
|
||||
jtag_add_dr_scan(target->tap, ARRAY_SIZE(tunneled_ir), tunneled_ir, TAP_IDLE);
|
||||
jtag_add_dr_scan(target->tap, ARRAY_SIZE(tunneled_dr), tunneled_dr, TAP_IDLE);
|
||||
select_dmi_via_bscan(target);
|
||||
|
||||
int retval = jtag_execute_queue();
|
||||
|
@ -1849,7 +1847,7 @@ static int riscv_run_algorithm(struct target *target, int num_mem_params,
|
|||
GDB_REGNO_PC,
|
||||
GDB_REGNO_MSTATUS, GDB_REGNO_MEPC, GDB_REGNO_MCAUSE,
|
||||
};
|
||||
for (unsigned i = 0; i < DIM(regnums); i++) {
|
||||
for (unsigned i = 0; i < ARRAY_SIZE(regnums); i++) {
|
||||
enum gdb_regno regno = regnums[i];
|
||||
riscv_reg_t reg_value;
|
||||
if (riscv_get_register(target, ®_value, regno) != ERROR_OK)
|
||||
|
@ -4152,7 +4150,7 @@ int riscv_init_registers(struct target *target)
|
|||
#undef DECLARE_CSR
|
||||
};
|
||||
/* encoding.h does not contain the registers in sorted order. */
|
||||
qsort(csr_info, DIM(csr_info), sizeof(*csr_info), cmp_csr_info);
|
||||
qsort(csr_info, ARRAY_SIZE(csr_info), sizeof(*csr_info), cmp_csr_info);
|
||||
unsigned csr_info_index = 0;
|
||||
|
||||
int custom_within_range = 0;
|
||||
|
@ -4411,7 +4409,7 @@ int riscv_init_registers(struct target *target)
|
|||
unsigned csr_number = number - GDB_REGNO_CSR0;
|
||||
|
||||
while (csr_info[csr_info_index].number < csr_number &&
|
||||
csr_info_index < DIM(csr_info) - 1) {
|
||||
csr_info_index < ARRAY_SIZE(csr_info) - 1) {
|
||||
csr_info_index++;
|
||||
}
|
||||
if (csr_info[csr_info_index].number == csr_number) {
|
||||
|
|
Loading…
Reference in New Issue