diff --git a/src/Makefile b/src/Makefile index b0933ec..54a63f7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -5,6 +5,7 @@ VPATH += $(PLATFORM_DIR) BUILDDATE := `date +"%Y%m%d"` CFLAGS += -Wall -Wextra -Wno-pointer-sign -Wno-char-subscripts\ + -Wno-sign-compare \ -O2 -std=gnu99 -g3 -DBUILDDATE=\"$(BUILDDATE)\"\ -I. -Iinclude -I$(PLATFORM_DIR) \ -DVERSION_SUFFIX=\"`../scripts/setlocalversion`\" -MD diff --git a/src/cortexm.c b/src/cortexm.c index 0462a5f..43f3d98 100644 --- a/src/cortexm.c +++ b/src/cortexm.c @@ -29,14 +29,24 @@ * There are way too many magic numbers used here. */ #include +#include #include "general.h" #include "jtagtap.h" #include "jtag_scan.h" #include "adiv5.h" #include "target.h" +#include "command.h" +#include "gdb_packet.h" -static char cortexm_driver_str[] = "ARM Cortex-M3"; +static char cortexm_driver_str[] = "ARM Cortex-M"; + +static bool cortexm_vector_catch(target *t, int argc, char *argv[]); + +const struct command_s cortexm_cmd_list[] = { + {"vector_catch", (cmd_handler)cortexm_vector_catch, "Catch exception vectors"}, + {NULL, NULL, NULL} +}; /* target options recognised by the Cortex-M target */ #define TOPT_FLAVOUR_V6M (1<<0) /* if not set, target is assumed to be v7m */ @@ -313,6 +323,8 @@ cortexm_probe(struct target_s *target) target->fault_unwind = cortexm_fault_unwind; target->regs_size = sizeof(regnum_cortex_m); /* XXX: detect FP extension */ + target_add_commands(target, cortexm_cmd_list, cortexm_driver_str); + /* Probe for FP extension */ ADIv5_AP_t *ap = adiv5_target_ap(target); uint32_t cpacr = adiv5_ap_mem_read(ap, CORTEXM_CPACR); @@ -737,3 +749,41 @@ cortexm_check_hw_wp(struct target_s *target, uint32_t *addr) return 1; } +static bool cortexm_vector_catch(target *t, int argc, char *argv[]) +{ + ADIv5_AP_t *ap = adiv5_target_ap(t); + const char *vectors[] = {"reset", NULL, NULL, NULL, "mm", "nocp", + "chk", "stat", "bus", "int", "hard"}; + uint32_t demcr = adiv5_ap_mem_read(ap, CORTEXM_DEMCR); + uint32_t tmp = 0; + unsigned i, j; + + if ((argc < 3) || ((argv[1][0] != 'e') && (argv[1][0] != 'd'))) { + gdb_out("usage: monitor vector_catch (enable|disable) " + "(hard|int|bus|stat|chk|nocp|mm|reset)\n"); + } else { + for (j = 0; j < argc; j++) + for (i = 0; i < sizeof(vectors) / sizeof(char*); i++) { + if (vectors[i] && !strcmp(vectors[i], argv[j])) + tmp |= 1 << i; + } + + if (argv[1][0] == 'e') + demcr |= tmp; + else + demcr &= ~tmp; + + adiv5_ap_mem_write(ap, CORTEXM_DEMCR, demcr); + } + + gdb_out("Catching vectors: "); + for (i = 0; i < sizeof(vectors) / sizeof(char*); i++) { + if (!vectors[i]) + continue; + if (demcr & (1 << i)) + gdb_outf("%s ", vectors[i]); + } + gdb_out("\n"); + return true; +} +