]> git.sur5r.net Git - openocd/blobdiff - src/target/cortex_a.c
target: cortex_a: fix segfault when SPSR is not properly handled
[openocd] / src / target / cortex_a.c
index 91fa48e1adcc1e56aabb13a3b8e0ef7387a5f28a..8c8a2b79ea5719ebbf5e8a7f30a2ac2951f7af7d 100644 (file)
@@ -54,6 +54,7 @@
 #include "target_type.h"
 #include "arm_opcodes.h"
 #include "arm_semihosting.h"
+#include "jtag/swd.h"
 #include <helper/time_support.h>
 
 static int cortex_a_poll(struct target *target);
@@ -1240,16 +1241,18 @@ static int cortex_a_debug_entry(struct target *target)
                reg->dirty = reg->valid;
        }
 
-       /* read Saved PSR */
-       retval = cortex_a_dap_read_coreregister_u32(target, &spsr, 17);
-       /*  store current spsr */
-       if (retval != ERROR_OK)
-               return retval;
+       if (arm->spsr) {
+               /* read Saved PSR */
+               retval = cortex_a_dap_read_coreregister_u32(target, &spsr, 17);
+               /*  store current spsr */
+               if (retval != ERROR_OK)
+                       return retval;
 
-       reg = arm->spsr;
-       buf_set_u32(reg->value, 0, 32, spsr);
-       reg->valid = 1;
-       reg->dirty = 0;
+               reg = arm->spsr;
+               buf_set_u32(reg->value, 0, 32, spsr);
+               reg->valid = 1;
+               reg->dirty = 0;
+       }
 
 #if 0
 /* TODO, Move this */
@@ -1867,9 +1870,15 @@ static int cortex_a_assert_reset(struct target *target)
                /* REVISIT handle "pulls" cases, if there's
                 * hardware that needs them to work.
                 */
-               if (target->reset_halt)
-                       if (jtag_get_reset_config() & RESET_SRST_NO_GATING)
-                               jtag_add_reset(0, 1);
+
+               /*
+                * FIXME: fix reset when transport is SWD. This is a temporary
+                * work-around for release v0.10 that is not intended to stay!
+                */
+               if (transport_is_swd() ||
+                               (target->reset_halt && (jtag_get_reset_config() & RESET_SRST_NO_GATING)))
+                       jtag_add_reset(0, 1);
+
        } else {
                LOG_ERROR("%s: how to reset?", target_name(target));
                return ERROR_FAIL;
@@ -3103,6 +3112,7 @@ static int cortex_a_init_target(struct command_context *cmd_ctx,
        struct target *target)
 {
        /* examine_first() does a bunch of this */
+       arm_semihosting_init(target);
        return ERROR_OK;
 }