Add a copy of DEMCR to Cortex-M private data to preserve over 'run'.

This commit is contained in:
Gareth McMullin 2012-08-10 21:07:06 +12:00
parent 7be4866239
commit 9137c2d058
1 changed files with 41 additions and 36 deletions

View File

@ -1,7 +1,7 @@
/* /*
* This file is part of the Black Magic Debug project. * This file is part of the Black Magic Debug project.
* *
* Copyright (C) 2011 Black Sphere Technologies Ltd. * Copyright (C) 2012 Black Sphere Technologies Ltd.
* Written by Gareth McMullin <gareth@blacksphere.co.nz> * Written by Gareth McMullin <gareth@blacksphere.co.nz>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -217,6 +217,8 @@ struct cortexm_priv {
/* Breakpoint unit status */ /* Breakpoint unit status */
uint32_t hw_breakpoint[CORTEXM_MAX_BREAKPOINTS]; uint32_t hw_breakpoint[CORTEXM_MAX_BREAKPOINTS];
unsigned hw_breakpoint_max; unsigned hw_breakpoint_max;
/* Copy of DEMCR for vector-catch */
uint32_t demcr;
}; };
/* Register number tables */ /* Register number tables */
@ -346,9 +348,14 @@ cortexm_probe(struct target_s *target)
target->tdesc = tdesc_cortex_mf; target->tdesc = tdesc_cortex_mf;
} }
ap->priv = calloc(1, sizeof(struct cortexm_priv)); struct cortexm_priv *priv = calloc(1, sizeof(*priv));
ap->priv = priv;
ap->priv_free = free; ap->priv_free = free;
/* Default vectors to catch */
priv->demcr = CORTEXM_DEMCR_TRCENA | CORTEXM_DEMCR_VC_HARDERR |
CORTEXM_DEMCR_VC_CORERESET;
#define PROBE(x) \ #define PROBE(x) \
do { if (!(x)(target)) return 0; else target_check_error(target); } while (0) do { if (!(x)(target)) return 0; else target_check_error(target); } while (0)
@ -378,9 +385,7 @@ cortexm_attach(struct target_s *target)
while(!target_halt_wait(target)); while(!target_halt_wait(target));
/* Request halt on reset */ /* Request halt on reset */
adiv5_ap_mem_write(ap, CORTEXM_DEMCR, adiv5_ap_mem_write(ap, CORTEXM_DEMCR, priv->demcr);
CORTEXM_DEMCR_TRCENA | CORTEXM_DEMCR_VC_HARDERR |
CORTEXM_DEMCR_VC_CORERESET);
/* Reset DFSR flags */ /* Reset DFSR flags */
adiv5_ap_mem_write(ap, CORTEXM_DFSR, CORTEXM_DFSR_RESETALL); adiv5_ap_mem_write(ap, CORTEXM_DFSR, CORTEXM_DFSR_RESETALL);
@ -807,9 +812,9 @@ cortexm_check_hw_wp(struct target_s *target, uint32_t *addr)
static bool cortexm_vector_catch(target *t, int argc, char *argv[]) static bool cortexm_vector_catch(target *t, int argc, char *argv[])
{ {
ADIv5_AP_t *ap = adiv5_target_ap(t); ADIv5_AP_t *ap = adiv5_target_ap(t);
struct cortexm_priv *priv = ap->priv;
const char *vectors[] = {"reset", NULL, NULL, NULL, "mm", "nocp", const char *vectors[] = {"reset", NULL, NULL, NULL, "mm", "nocp",
"chk", "stat", "bus", "int", "hard"}; "chk", "stat", "bus", "int", "hard"};
uint32_t demcr = adiv5_ap_mem_read(ap, CORTEXM_DEMCR);
uint32_t tmp = 0; uint32_t tmp = 0;
unsigned i, j; unsigned i, j;
@ -824,18 +829,18 @@ static bool cortexm_vector_catch(target *t, int argc, char *argv[])
} }
if (argv[1][0] == 'e') if (argv[1][0] == 'e')
demcr |= tmp; priv->demcr |= tmp;
else else
demcr &= ~tmp; priv->demcr &= ~tmp;
adiv5_ap_mem_write(ap, CORTEXM_DEMCR, demcr); adiv5_ap_mem_write(ap, CORTEXM_DEMCR, priv->demcr);
} }
gdb_out("Catching vectors: "); gdb_out("Catching vectors: ");
for (i = 0; i < sizeof(vectors) / sizeof(char*); i++) { for (i = 0; i < sizeof(vectors) / sizeof(char*); i++) {
if (!vectors[i]) if (!vectors[i])
continue; continue;
if (demcr & (1 << i)) if (priv->demcr & (1 << i))
gdb_outf("%s ", vectors[i]); gdb_outf("%s ", vectors[i]);
} }
gdb_out("\n"); gdb_out("\n");