target/riscv: fix unused initialization
[fw/openocd] / src / target / riscv / riscv.c
index 084939e116f3c8dc9002c87a97ac98b04416ae47..c25efcde9a0d8cfbfe3004633dbfdc8be627de58 100644 (file)
@@ -1,4 +1,4 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
+// SPDX-License-Identifier: GPL-2.0-or-later
 
 #include <assert.h>
 #include <stdlib.h>
@@ -13,6 +13,7 @@
 #include "target/target.h"
 #include "target/algorithm.h"
 #include "target/target_type.h"
+#include <target/smp.h>
 #include "jtag/jtag.h"
 #include "target/register.h"
 #include "target/breakpoints.h"
@@ -108,37 +109,37 @@ typedef enum slot {
 #define MAX_HWBPS                      16
 #define DRAM_CACHE_SIZE                16
 
-uint8_t ir_dtmcontrol[4] = {DTMCONTROL};
+static uint8_t ir_dtmcontrol[4] = {DTMCONTROL};
 struct scan_field select_dtmcontrol = {
        .in_value = NULL,
        .out_value = ir_dtmcontrol
 };
-uint8_t ir_dbus[4] = {DBUS};
+static uint8_t ir_dbus[4] = {DBUS};
 struct scan_field select_dbus = {
        .in_value = NULL,
        .out_value = ir_dbus
 };
-uint8_t ir_idcode[4] = {0x1};
+static uint8_t ir_idcode[4] = {0x1};
 struct scan_field select_idcode = {
        .in_value = NULL,
        .out_value = ir_idcode
 };
 
-bscan_tunnel_type_t bscan_tunnel_type;
+static bscan_tunnel_type_t bscan_tunnel_type;
 int bscan_tunnel_ir_width; /* if zero, then tunneling is not present/active */
 
 static const uint8_t bscan_zero[4] = {0};
 static const uint8_t bscan_one[4] = {1};
 
-uint8_t ir_user4[4];
-struct scan_field select_user4 = {
+static uint8_t ir_user4[4];
+static struct scan_field select_user4 = {
        .in_value = NULL,
        .out_value = ir_user4
 };
 
 
-uint8_t bscan_tunneled_ir_width[4] = {5};  /* overridden by assignment in riscv_init_target */
-struct scan_field _bscan_tunnel_data_register_select_dmi[] = {
+static uint8_t bscan_tunneled_ir_width[4] = {5};  /* overridden by assignment in riscv_init_target */
+static struct scan_field _bscan_tunnel_data_register_select_dmi[] = {
                {
                        .num_bits = 3,
                        .out_value = bscan_zero,
@@ -161,7 +162,7 @@ struct scan_field _bscan_tunnel_data_register_select_dmi[] = {
                }
 };
 
-struct scan_field _bscan_tunnel_nested_tap_select_dmi[] = {
+static struct scan_field _bscan_tunnel_nested_tap_select_dmi[] = {
                {
                        .num_bits = 1,
                        .out_value = bscan_zero,
@@ -183,11 +184,11 @@ struct scan_field _bscan_tunnel_nested_tap_select_dmi[] = {
                        .in_value = NULL,
                }
 };
-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 = ARRAY_SIZE(_bscan_tunnel_nested_tap_select_dmi);
+static struct scan_field *bscan_tunnel_nested_tap_select_dmi = _bscan_tunnel_nested_tap_select_dmi;
+static 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 = ARRAY_SIZE(_bscan_tunnel_data_register_select_dmi);
+static struct scan_field *bscan_tunnel_data_register_select_dmi = _bscan_tunnel_data_register_select_dmi;
+static uint32_t bscan_tunnel_data_register_select_dmi_num_fields = ARRAY_SIZE(_bscan_tunnel_data_register_select_dmi);
 
 struct trigger {
        uint64_t address;
@@ -204,7 +205,7 @@ int riscv_command_timeout_sec = DEFAULT_COMMAND_TIMEOUT_SEC;
 /* Wall-clock timeout after reset. Settable via RISC-V Target commands.*/
 int riscv_reset_timeout_sec = DEFAULT_RESET_TIMEOUT_SEC;
 
-bool riscv_enable_virt2phys = true;
+static bool riscv_enable_virt2phys = true;
 bool riscv_ebreakm = true;
 bool riscv_ebreaks = true;
 bool riscv_ebreaku = true;
@@ -216,7 +217,7 @@ static enum {
        RO_REVERSED
 } resume_order;
 
-const virt2phys_info_t sv32 = {
+static const virt2phys_info_t sv32 = {
        .name = "Sv32",
        .va_bits = 32,
        .level = 2,
@@ -229,7 +230,7 @@ const virt2phys_info_t sv32 = {
        .pa_ppn_mask = {0x3ff, 0xfff},
 };
 
-const virt2phys_info_t sv39 = {
+static const virt2phys_info_t sv39 = {
        .name = "Sv39",
        .va_bits = 39,
        .level = 3,
@@ -242,7 +243,7 @@ const virt2phys_info_t sv39 = {
        .pa_ppn_mask = {0x1ff, 0x1ff, 0x3ffffff},
 };
 
-const virt2phys_info_t sv48 = {
+static const virt2phys_info_t sv48 = {
        .name = "Sv48",
        .va_bits = 48,
        .level = 4,
@@ -255,7 +256,12 @@ const virt2phys_info_t sv48 = {
        .pa_ppn_mask = {0x1ff, 0x1ff, 0x1ff, 0x1ffff},
 };
 
-void riscv_sample_buf_maybe_add_timestamp(struct target *target, bool before)
+static enum riscv_halt_reason riscv_halt_reason(struct target *target, int hartid);
+static void riscv_info_init(struct target *target, struct riscv_info *r);
+static void riscv_invalidate_register_cache(struct target *target);
+static int riscv_step_rtos_hart(struct target *target);
+
+static void riscv_sample_buf_maybe_add_timestamp(struct target *target, bool before)
 {
        RISCV_INFO(r);
        uint32_t now = timeval_ms() & 0xffffffff;
@@ -404,13 +410,12 @@ static uint32_t dtmcontrol_scan(struct target *target, uint32_t out)
 
 static struct target_type *get_target_type(struct target *target)
 {
-       riscv_info_t *info = (riscv_info_t *) target->arch_info;
-
-       if (!info) {
+       if (!target->arch_info) {
                LOG_ERROR("Target has not been initialized");
                return NULL;
        }
 
+       RISCV_INFO(info);
        switch (info->dtm_version) {
                case 0:
                        return &riscv011_target;
@@ -425,7 +430,7 @@ static struct target_type *get_target_type(struct target *target)
 static int riscv_create_target(struct target *target, Jim_Interp *interp)
 {
        LOG_DEBUG("riscv_create_target()");
-       target->arch_info = calloc(1, sizeof(riscv_info_t));
+       target->arch_info = calloc(1, sizeof(struct riscv_info));
        if (!target->arch_info) {
                LOG_ERROR("Failed to allocate RISC-V target structure.");
                return ERROR_FAIL;
@@ -476,6 +481,8 @@ static void riscv_free_registers(struct target *target)
                        /* Free the ones we allocated separately. */
                        for (unsigned i = GDB_REGNO_COUNT; i < target->reg_cache->num_regs; i++)
                                free(target->reg_cache->reg_list[i].arch_info);
+                       for (unsigned int i = 0; i < target->reg_cache->num_regs; i++)
+                               free(target->reg_cache->reg_list[i].value);
                        free(target->reg_cache->reg_list);
                }
                free(target->reg_cache);
@@ -486,14 +493,17 @@ static void riscv_deinit_target(struct target *target)
 {
        LOG_DEBUG("riscv_deinit_target()");
 
-       riscv_info_t *info = target->arch_info;
+       struct riscv_info *info = target->arch_info;
        struct target_type *tt = get_target_type(target);
 
-       if (tt && info->version_specific)
+       if (tt && info && info->version_specific)
                tt->deinit_target(target);
 
        riscv_free_registers(target);
 
+       if (!info)
+               return;
+
        range_list_t *entry, *tmp;
        list_for_each_entry_safe(entry, tmp, &info->expose_csr, list) {
                free(entry->name);
@@ -703,7 +713,6 @@ static int add_trigger(struct target *target, struct trigger *trigger)
                        return result;
                int type = get_field(tdata1, MCONTROL_TYPE(riscv_xlen(target)));
 
-               result = ERROR_OK;
                switch (type) {
                        case 1:
                                result = maybe_add_trigger_t1(target, trigger, tdata1);
@@ -856,7 +865,7 @@ int riscv_read_by_any_size(struct target *target, target_addr_t address, uint32_
        return ERROR_FAIL;
 }
 
-int riscv_add_breakpoint(struct target *target, struct breakpoint *breakpoint)
+static int riscv_add_breakpoint(struct target *target, struct breakpoint *breakpoint)
 {
        LOG_DEBUG("[%d] @0x%" TARGET_PRIxADDR, target->coreid, breakpoint->address);
        assert(breakpoint);
@@ -900,7 +909,7 @@ int riscv_add_breakpoint(struct target *target, struct breakpoint *breakpoint)
                return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
        }
 
-       breakpoint->set = true;
+       breakpoint->is_set = true;
        return ERROR_OK;
 }
 
@@ -936,7 +945,7 @@ static int remove_trigger(struct target *target, struct trigger *trigger)
        return ERROR_OK;
 }
 
-int riscv_remove_breakpoint(struct target *target,
+static int riscv_remove_breakpoint(struct target *target,
                struct breakpoint *breakpoint)
 {
        if (breakpoint->type == BKPT_SOFT) {
@@ -960,7 +969,7 @@ int riscv_remove_breakpoint(struct target *target,
                return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
        }
 
-       breakpoint->set = false;
+       breakpoint->is_set = false;
 
        return ERROR_OK;
 }
@@ -987,7 +996,7 @@ int riscv_add_watchpoint(struct target *target, struct watchpoint *watchpoint)
        int result = add_trigger(target, &trigger);
        if (result != ERROR_OK)
                return result;
-       watchpoint->set = true;
+       watchpoint->is_set = true;
 
        return ERROR_OK;
 }
@@ -1003,7 +1012,7 @@ int riscv_remove_watchpoint(struct target *target,
        int result = remove_trigger(target, &trigger);
        if (result != ERROR_OK)
                return result;
-       watchpoint->set = false;
+       watchpoint->is_set = false;
 
        return ERROR_OK;
 }
@@ -1014,7 +1023,7 @@ int riscv_remove_watchpoint(struct target *target,
  * The GDB server uses this information to tell GDB what data address has
  * been hit, which enables GDB to print the hit variable along with its old
  * and new value. */
-int riscv_hit_watchpoint(struct target *target, struct watchpoint **hit_watchpoint)
+static int riscv_hit_watchpoint(struct target *target, struct watchpoint **hit_watchpoint)
 {
        struct watchpoint *wp = target->watchpoints;
 
@@ -1157,7 +1166,7 @@ int riscv_select_current_hart(struct target *target)
        return riscv_set_current_hartid(target, target->coreid);
 }
 
-int halt_prep(struct target *target)
+static int halt_prep(struct target *target)
 {
        RISCV_INFO(r);
 
@@ -1177,7 +1186,7 @@ int halt_prep(struct target *target)
        return ERROR_OK;
 }
 
-int riscv_halt_go_all_harts(struct target *target)
+static int riscv_halt_go_all_harts(struct target *target)
 {
        RISCV_INFO(r);
 
@@ -1195,9 +1204,9 @@ int riscv_halt_go_all_harts(struct target *target)
        return ERROR_OK;
 }
 
-int halt_go(struct target *target)
+static int halt_go(struct target *target)
 {
-       riscv_info_t *r = riscv_info(target);
+       RISCV_INFO(r);
        int result;
        if (!r->is_halted) {
                struct target_type *tt = get_target_type(target);
@@ -1230,22 +1239,23 @@ int riscv_halt(struct target *target)
 
        int result = ERROR_OK;
        if (target->smp) {
-               for (struct target_list *tlist = target->head; tlist; tlist = tlist->next) {
+               struct target_list *tlist;
+               foreach_smp_target(tlist, target->smp_targets) {
                        struct target *t = tlist->target;
                        if (halt_prep(t) != ERROR_OK)
                                result = ERROR_FAIL;
                }
 
-               for (struct target_list *tlist = target->head; tlist; tlist = tlist->next) {
+               foreach_smp_target(tlist, target->smp_targets) {
                        struct target *t = tlist->target;
-                       riscv_info_t *i = riscv_info(t);
+                       struct riscv_info *i = riscv_info(t);
                        if (i->prepped) {
                                if (halt_go(t) != ERROR_OK)
                                        result = ERROR_FAIL;
                        }
                }
 
-               for (struct target_list *tlist = target->head; tlist; tlist = tlist->next) {
+               foreach_smp_target(tlist, target->smp_targets) {
                        struct target *t = tlist->target;
                        if (halt_finish(t) != ERROR_OK)
                                return ERROR_FAIL;
@@ -1278,7 +1288,7 @@ static int riscv_deassert_reset(struct target *target)
        return tt->deassert_reset(target);
 }
 
-int riscv_resume_prep_all_harts(struct target *target)
+static int riscv_resume_prep_all_harts(struct target *target)
 {
        RISCV_INFO(r);
 
@@ -1334,9 +1344,9 @@ static int disable_triggers(struct target *target, riscv_reg_t *state)
                struct watchpoint *watchpoint = target->watchpoints;
                int i = 0;
                while (watchpoint) {
-                       LOG_DEBUG("watchpoint %d: set=%d", i, watchpoint->set);
-                       state[i] = watchpoint->set;
-                       if (watchpoint->set) {
+                       LOG_DEBUG("watchpoint %d: set=%d", i, watchpoint->is_set);
+                       state[i] = watchpoint->is_set;
+                       if (watchpoint->is_set) {
                                if (riscv_remove_watchpoint(target, watchpoint) != ERROR_OK)
                                        return ERROR_FAIL;
                        }
@@ -1430,7 +1440,7 @@ static int resume_prep(struct target *target, int current,
 static int resume_go(struct target *target, int current,
                target_addr_t address, int handle_breakpoints, int debug_execution)
 {
-       riscv_info_t *r = riscv_info(target);
+       RISCV_INFO(r);
        int result;
        if (!r->is_halted) {
                struct target_type *tt = get_target_type(target);
@@ -1456,7 +1466,7 @@ static int resume_finish(struct target *target)
  * @par single_hart When true, only resume a single hart even if SMP is
  * configured.  This is used to run algorithms on just one hart.
  */
-int riscv_resume(
+static int riscv_resume(
                struct target *target,
                int current,
                target_addr_t address,
@@ -1467,16 +1477,19 @@ int riscv_resume(
        LOG_DEBUG("handle_breakpoints=%d", handle_breakpoints);
        int result = ERROR_OK;
        if (target->smp && !single_hart) {
-               for (struct target_list *tlist = target->head; tlist; tlist = tlist->next) {
+               struct target_list *tlist;
+               foreach_smp_target_direction(resume_order == RO_NORMAL,
+                                                                        tlist, target->smp_targets) {
                        struct target *t = tlist->target;
                        if (resume_prep(t, current, address, handle_breakpoints,
                                                debug_execution) != ERROR_OK)
                                result = ERROR_FAIL;
                }
 
-               for (struct target_list *tlist = target->head; tlist; tlist = tlist->next) {
+               foreach_smp_target_direction(resume_order == RO_NORMAL,
+                                                                        tlist, target->smp_targets) {
                        struct target *t = tlist->target;
-                       riscv_info_t *i = riscv_info(t);
+                       struct riscv_info *i = riscv_info(t);
                        if (i->prepped) {
                                if (resume_go(t, current, address, handle_breakpoints,
                                                        debug_execution) != ERROR_OK)
@@ -1484,7 +1497,8 @@ int riscv_resume(
                        }
                }
 
-               for (struct target_list *tlist = target->head; tlist; tlist = tlist->next) {
+               foreach_smp_target_direction(resume_order == RO_NORMAL,
+                                                                        tlist, target->smp_targets) {
                        struct target *t = tlist->target;
                        if (resume_finish(t) != ERROR_OK)
                                return ERROR_FAIL;
@@ -1732,7 +1746,7 @@ static int riscv_write_memory(struct target *target, target_addr_t address,
        return tt->write_memory(target, address, size, count, buffer);
 }
 
-const char *riscv_get_gdb_arch(struct target *target)
+static const char *riscv_get_gdb_arch(struct target *target)
 {
        switch (riscv_xlen(target)) {
                case 32:
@@ -1749,8 +1763,8 @@ static int riscv_get_gdb_reg_list_internal(struct target *target,
                enum target_register_class reg_class, bool read)
 {
        RISCV_INFO(r);
-       LOG_DEBUG("current_hartid=%d, reg_class=%d, read=%d",
-                       r->current_hartid, reg_class, read);
+       LOG_DEBUG("[%s] {%d} reg_class=%d, read=%d",
+                       target_name(target), r->current_hartid, reg_class, read);
 
        if (!target->reg_cache) {
                LOG_ERROR("Target not initialized. Return ERROR_FAIL.");
@@ -2095,7 +2109,7 @@ static enum riscv_poll_hart riscv_poll_hart(struct target *target, int hartid)
        return RPH_NO_CHANGE;
 }
 
-int set_debug_reason(struct target *target, enum riscv_halt_reason halt_reason)
+static int set_debug_reason(struct target *target, enum riscv_halt_reason halt_reason)
 {
        switch (halt_reason) {
                case RISCV_HALT_BREAKPOINT:
@@ -2121,7 +2135,7 @@ int set_debug_reason(struct target *target, enum riscv_halt_reason halt_reason)
        return ERROR_OK;
 }
 
-int sample_memory(struct target *target)
+static int sample_memory(struct target *target)
 {
        RISCV_INFO(r);
 
@@ -2178,11 +2192,10 @@ int riscv_openocd_poll(struct target *target)
                unsigned halts_discovered = 0;
                unsigned should_remain_halted = 0;
                unsigned should_resume = 0;
-               unsigned i = 0;
-               for (struct target_list *list = target->head; list;
-                               list = list->next, i++) {
+               struct target_list *list;
+               foreach_smp_target(list, target->smp_targets) {
                        struct target *t = list->target;
-                       riscv_info_t *r = riscv_info(t);
+                       struct riscv_info *r = riscv_info(t);
                        enum riscv_poll_hart out = riscv_poll_hart(t, r->current_hartid);
                        switch (out) {
                        case RPH_NO_CHANGE:
@@ -2202,17 +2215,17 @@ int riscv_openocd_poll(struct target *target)
                                if (halt_reason == RISCV_HALT_BREAKPOINT) {
                                        int retval;
                                        switch (riscv_semihosting(t, &retval)) {
-                                       case SEMI_NONE:
-                                       case SEMI_WAITING:
+                                       case SEMIHOSTING_NONE:
+                                       case SEMIHOSTING_WAITING:
                                                /* This hart should remain halted. */
                                                should_remain_halted++;
                                                break;
-                                       case SEMI_HANDLED:
+                                       case SEMIHOSTING_HANDLED:
                                                /* This hart should be resumed, along with any other
                                                         * harts that halted due to haltgroups. */
                                                should_resume++;
                                                break;
-                                       case SEMI_ERROR:
+                                       case SEMIHOSTING_ERROR:
                                                return retval;
                                        }
                                } else if (halt_reason != RISCV_HALT_GROUP) {
@@ -2240,8 +2253,7 @@ int riscv_openocd_poll(struct target *target)
                }
 
                /* Sample memory if any target is running. */
-               for (struct target_list *list = target->head; list;
-                               list = list->next, i++) {
+               foreach_smp_target(list, target->smp_targets) {
                        struct target *t = list->target;
                        if (t->state == TARGET_RUNNING) {
                                sample_memory(target);
@@ -2274,15 +2286,15 @@ int riscv_openocd_poll(struct target *target)
        if (target->debug_reason == DBG_REASON_BREAKPOINT) {
                int retval;
                switch (riscv_semihosting(target, &retval)) {
-                       case SEMI_NONE:
-                       case SEMI_WAITING:
+                       case SEMIHOSTING_NONE:
+                       case SEMIHOSTING_WAITING:
                                target_call_event_callbacks(target, TARGET_EVENT_HALTED);
                                break;
-                       case SEMI_HANDLED:
+                       case SEMIHOSTING_HANDLED:
                                if (riscv_resume(target, true, 0, 0, 0, false) != ERROR_OK)
                                        return ERROR_FAIL;
                                break;
-                       case SEMI_ERROR:
+                       case SEMIHOSTING_ERROR:
                                return retval;
                }
        } else {
@@ -2450,7 +2462,7 @@ COMMAND_HANDLER(riscv_set_enable_virtual)
        return ERROR_OK;
 }
 
-int parse_ranges(struct list_head *ranges, const char *tcl_arg, const char *reg_type, unsigned int max_val)
+static int parse_ranges(struct list_head *ranges, const char *tcl_arg, const char *reg_type, unsigned int max_val)
 {
        char *args = strdup(tcl_arg);
        if (!args)
@@ -3108,9 +3120,8 @@ static const struct command_registration riscv_exec_command_handlers[] = {
  * protocol, then a command like `riscv semihosting enable` will make
  * sense, but for now all semihosting commands are prefixed with `arm`.
  */
-extern const struct command_registration semihosting_common_handlers[];
 
-const struct command_registration riscv_command_handlers[] = {
+static const struct command_registration riscv_command_handlers[] = {
        {
                .name = "riscv",
                .mode = COMMAND_ANY,
@@ -3192,11 +3203,14 @@ struct target_type riscv_target = {
 
 /*** RISC-V Interface ***/
 
-void riscv_info_init(struct target *target, riscv_info_t *r)
+/* Initializes the shared RISC-V structure. */
+static void riscv_info_init(struct target *target, struct riscv_info *r)
 {
        memset(r, 0, sizeof(*r));
+
+       r->common_magic = RISCV_COMMON_MAGIC;
+
        r->dtm_version = 1;
-       r->registers_initialized = false;
        r->current_hartid = target->coreid;
        r->version_specific = NULL;
 
@@ -3235,7 +3249,9 @@ static int riscv_resume_go_all_harts(struct target *target)
        return ERROR_OK;
 }
 
-int riscv_step_rtos_hart(struct target *target)
+/* Steps the hart that's currently selected in the RTOS, or if there is no RTOS
+ * then the only hart. */
+static int riscv_step_rtos_hart(struct target *target)
 {
        RISCV_INFO(r);
        if (riscv_select_current_hart(target) != ERROR_OK)
@@ -3293,18 +3309,15 @@ int riscv_set_current_hartid(struct target *target, int hartid)
        return ERROR_OK;
 }
 
-void riscv_invalidate_register_cache(struct target *target)
+/* Invalidates the register cache. */
+static void riscv_invalidate_register_cache(struct target *target)
 {
-       RISCV_INFO(r);
-
        LOG_DEBUG("[%d]", target->coreid);
        register_cache_invalidate(target->reg_cache);
        for (size_t i = 0; i < target->reg_cache->num_regs; ++i) {
                struct reg *reg = &target->reg_cache->reg_list[i];
                reg->valid = false;
        }
-
-       r->registers_initialized = true;
 }
 
 int riscv_current_hartid(const struct target *target)
@@ -3447,7 +3460,7 @@ bool riscv_is_halted(struct target *target)
        return r->is_halted(target);
 }
 
-enum riscv_halt_reason riscv_halt_reason(struct target *target, int hartid)
+static enum riscv_halt_reason riscv_halt_reason(struct target *target, int hartid)
 {
        RISCV_INFO(r);
        if (riscv_set_current_hartid(target, hartid) != ERROR_OK)
@@ -3569,6 +3582,10 @@ int riscv_enumerate_triggers(struct target *target)
                                if (tdata1 & MCONTROL_DMODE(riscv_xlen(target)))
                                        riscv_set_register(target, GDB_REGNO_TDATA1, 0);
                                break;
+                       case 6:
+                               if (tdata1 & MCONTROL_DMODE(riscv_xlen(target)))
+                                       riscv_set_register(target, GDB_REGNO_TDATA1, 0);
+                               break;
                }
        }
 
@@ -4475,7 +4492,7 @@ int riscv_init_registers(struct target *target)
                        assert(reg_name < info->reg_names + target->reg_cache->num_regs *
                                        max_reg_name_len);
                }
-               r->value = info->reg_cache_values[number];
+               r->value = calloc(1, DIV_ROUND_UP(r->size, 8));
        }
 
        return ERROR_OK;