From fa046601a54ddf2137048f11594ed7d72ede995a Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Sat, 28 Feb 2015 20:50:10 -0800 Subject: Add exception handling mechanism and raise exception on low-level comms failure. --- src/Makefile | 1 + src/adiv5_jtagdp.c | 7 ++-- src/adiv5_swdp.c | 9 +++-- src/exception.c | 39 ++++++++++++++++++++++ src/include/exception.h | 74 +++++++++++++++++++++++++++++++++++++++++ src/platforms/native/platform.h | 1 + 6 files changed, 122 insertions(+), 9 deletions(-) create mode 100644 src/exception.c create mode 100644 src/include/exception.h (limited to 'src') diff --git a/src/Makefile b/src/Makefile index 02b5690..73fb8e9 100644 --- a/src/Makefile +++ b/src/Makefile @@ -24,6 +24,7 @@ SRC = \ command.c \ cortexm.c \ crc32.c \ + exception.c \ gdb_if.c \ gdb_main.c \ gdb_packet.c \ diff --git a/src/adiv5_jtagdp.c b/src/adiv5_jtagdp.c index 5049e3c..bb478d1 100644 --- a/src/adiv5_jtagdp.c +++ b/src/adiv5_jtagdp.c @@ -23,6 +23,7 @@ */ #include "general.h" +#include "exception.h" #include "adiv5.h" #include "jtag_scan.h" #include "jtagtap.h" @@ -93,10 +94,8 @@ static uint32_t adiv5_jtagdp_low_access(ADIv5_DP_t *dp, uint8_t RnW, if (dp->allow_timeout && (ack == JTAGDP_ACK_WAIT)) return 0; - if((ack != JTAGDP_ACK_OK)) { - /* Fatal error if invalid ACK response */ - PLATFORM_FATAL_ERROR(1); - } + if((ack != JTAGDP_ACK_OK)) + raise_exception(EXCEPTION_ERROR, "JTAG-DP invalid ACK"); return (uint32_t)(response >> 3); } diff --git a/src/adiv5_swdp.c b/src/adiv5_swdp.c index 9ac791a..d5193ac 100644 --- a/src/adiv5_swdp.c +++ b/src/adiv5_swdp.c @@ -23,6 +23,7 @@ */ #include "general.h" +#include "exception.h" #include "adiv5.h" #include "swdptap.h" #include "jtagtap.h" @@ -143,14 +144,12 @@ static uint32_t adiv5_swdp_low_access(ADIv5_DP_t *dp, uint8_t RnW, return 0; } - if(ack != SWDP_ACK_OK) { - /* Fatal error if invalid ACK response */ - PLATFORM_FATAL_ERROR(1); - } + if(ack != SWDP_ACK_OK) + raise_exception(EXCEPTION_ERROR, "SWDP invalid ACK"); if(RnW) { if(swdptap_seq_in_parity(&response, 32)) /* Give up on parity error */ - PLATFORM_FATAL_ERROR(1); + raise_exception(EXCEPTION_ERROR, "SWDP Parity error"); } else { swdptap_seq_out_parity(value, 32); } diff --git a/src/exception.c b/src/exception.c new file mode 100644 index 0000000..33e3869 --- /dev/null +++ b/src/exception.c @@ -0,0 +1,39 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2015 Black Sphere Technologies Ltd. + * Written by Gareth McMullin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "general.h" +#include "exception.h" + +struct exception *innermost_exception; + +void raise_exception(uint32_t type, const char *msg) +{ + struct exception *e; + for (e = innermost_exception; e; e = e->outer) { + if (e->mask & type) { + e->type = type; + e->msg = msg; + innermost_exception = e->outer; + longjmp(e->jmpbuf, type); + } + } + PLATFORM_FATAL_ERROR(type); +} + diff --git a/src/include/exception.h b/src/include/exception.h new file mode 100644 index 0000000..180398d --- /dev/null +++ b/src/include/exception.h @@ -0,0 +1,74 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2015 Black Sphere Technologies Ltd. + * Written by Gareth McMullin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* Exception handling to escape deep nesting. + * Used for the case of communicaiton failure and timeouts. + */ + +/* Example usage: + * + * volatile struct exception e; + * TRY_CATCH (e, EXCEPTION_TIMEOUT) { + * ... + * raise_exception(EXCEPTION_TIMEOUT, "Timeout occurred"); + * ... + * } + * if (e.type == EXCEPTION_TIMEOUT) { + * printf("timeout: %s\n", e.msg); + * } + */ + +/* Limitations: + * Can't use break, return, goto, etc from inside the TRY_CATCH block. + */ + +#ifndef __EXCEPTION_H +#define __EXCEPTION_H + +#include +#include + +#define EXCEPTION_ERROR 0x01 +#define EXCEPTION_TIMEOUT 0x02 +#define EXCEPTION_ALL -1 + +struct exception { + uint32_t type; + const char *msg; + /* private */ + uint32_t mask; + jmp_buf jmpbuf; + struct exception *outer; +}; + +extern struct exception *innermost_exception; + +#define TRY_CATCH(e, type_mask) \ + (e).type = 0; \ + (e).mask = (type_mask); \ + (e).outer = innermost_exception; \ + innermost_exception = (void*)&(e); \ + if (setjmp(innermost_exception->jmpbuf) == 0) \ + for (;innermost_exception == &(e); innermost_exception = (e).outer) + +void raise_exception(uint32_t type, const char *msg); + +#endif + diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index ae9bcef..3b1769b 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -153,6 +153,7 @@ extern jmp_buf fatal_error_jmpbuf; #define SET_IDLE_STATE(state) {gpio_set_val(LED_PORT, LED_IDLE_RUN, state);} #define SET_ERROR_STATE(state) {gpio_set_val(LED_PORT, LED_ERROR, state);} +#include "target.h" #define PLATFORM_SET_FATAL_ERROR_RECOVERY() {setjmp(fatal_error_jmpbuf);} #define PLATFORM_FATAL_ERROR(error) do { \ if(running_status) gdb_putpacketz("X1D"); \ -- cgit v1.2.3 From d6225eec763bd49ef3cb8edac5138df9e524a073 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Sat, 28 Feb 2015 20:53:25 -0800 Subject: Raise timeout exception when target is in WFI. Ignore the exception when polling for halt, and report the exception to the user if halting the target fails. Remove old allow_timeout flag in DP struct that's no longer needed.--- src/adiv5_jtagdp.c | 4 ++-- src/adiv5_swdp.c | 4 ++-- src/cortexm.c | 29 +++++++++++++++++++---------- src/include/adiv5.h | 4 ---- 4 files changed, 23 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/adiv5_jtagdp.c b/src/adiv5_jtagdp.c index bb478d1..a460113 100644 --- a/src/adiv5_jtagdp.c +++ b/src/adiv5_jtagdp.c @@ -91,8 +91,8 @@ static uint32_t adiv5_jtagdp_low_access(ADIv5_DP_t *dp, uint8_t RnW, ack = response & 0x07; } while(--tries && (ack == JTAGDP_ACK_WAIT)); - if (dp->allow_timeout && (ack == JTAGDP_ACK_WAIT)) - return 0; + if (ack == JTAGDP_ACK_WAIT) + raise_exception(EXCEPTION_TIMEOUT, "JTAG-DP ACK timeout"); if((ack != JTAGDP_ACK_OK)) raise_exception(EXCEPTION_ERROR, "JTAG-DP invalid ACK"); diff --git a/src/adiv5_swdp.c b/src/adiv5_swdp.c index d5193ac..1a6b158 100644 --- a/src/adiv5_swdp.c +++ b/src/adiv5_swdp.c @@ -136,8 +136,8 @@ static uint32_t adiv5_swdp_low_access(ADIv5_DP_t *dp, uint8_t RnW, ack = swdptap_seq_in(3); } while(--tries && ack == SWDP_ACK_WAIT); - if (dp->allow_timeout && (ack == SWDP_ACK_WAIT)) - return 0; + if (ack == SWDP_ACK_WAIT) + raise_exception(EXCEPTION_TIMEOUT, "SWDP ACK timeout"); if(ack == SWDP_ACK_FAULT) { dp->fault = 1; diff --git a/src/cortexm.c b/src/cortexm.c index a129a3c..f20f282 100644 --- a/src/cortexm.c +++ b/src/cortexm.c @@ -29,6 +29,7 @@ * There are way too many magic numbers used here. */ #include "general.h" +#include "exception.h" #include "jtagtap.h" #include "jtag_scan.h" #include "adiv5.h" @@ -467,12 +468,15 @@ cortexm_reset(struct target_s *target) static void cortexm_halt_request(struct target_s *target) { - ADIv5_AP_t *ap = adiv5_target_ap(target); - - ap->dp->allow_timeout = false; - target_mem_write32(target, CORTEXM_DHCSR, - CORTEXM_DHCSR_DBGKEY | CORTEXM_DHCSR_C_HALT | - CORTEXM_DHCSR_C_DEBUGEN); + volatile struct exception e; + TRY_CATCH (e, EXCEPTION_TIMEOUT) { + target_mem_write32(target, CORTEXM_DHCSR, CORTEXM_DHCSR_DBGKEY | + CORTEXM_DHCSR_C_HALT | + CORTEXM_DHCSR_C_DEBUGEN); + } + if (e.type) { + gdb_out("Timeout sending interrupt, is target in WFI?\n"); + } } static int @@ -480,10 +484,16 @@ cortexm_halt_wait(struct target_s *target) { ADIv5_AP_t *ap = adiv5_target_ap(target); struct cortexm_priv *priv = ap->priv; - if (!(target_mem_read32(target, CORTEXM_DHCSR) & CORTEXM_DHCSR_S_HALT)) - return 0; - ap->dp->allow_timeout = false; + uint32_t dhcsr = 0; + volatile struct exception e; + TRY_CATCH (e, EXCEPTION_TIMEOUT) { + /* If this times out because the target is in WFI then + * the target is still running. */ + dhcsr = target_mem_read32(target, CORTEXM_DHCSR); + } + if (e.type || !(dhcsr & CORTEXM_DHCSR_S_HALT)) + return 0; /* We've halted. Let's find out why. */ uint32_t dfsr = target_mem_read32(target, CORTEXM_DFSR); @@ -543,7 +553,6 @@ void cortexm_halt_resume(struct target_s *target, bool step) } target_mem_write32(target, CORTEXM_DHCSR, dhcsr); - ap->dp->allow_timeout = true; } static int cortexm_fault_unwind(struct target_s *target) diff --git a/src/include/adiv5.h b/src/include/adiv5.h index 6896f6d..12d3bf4 100644 --- a/src/include/adiv5.h +++ b/src/include/adiv5.h @@ -107,12 +107,8 @@ typedef struct ADIv5_DP_s { uint32_t idcode; - bool allow_timeout; - uint32_t (*dp_read)(struct ADIv5_DP_s *dp, uint16_t addr); - uint32_t (*error)(struct ADIv5_DP_s *dp); - uint32_t (*low_access)(struct ADIv5_DP_s *dp, uint8_t RnW, uint16_t addr, uint32_t value); -- cgit v1.2.3 From d0a03f55a6e66907f73d046adb6f211da2544d29 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Sat, 28 Feb 2015 20:56:03 -0800 Subject: Handle timeout exceptions during scans and report to the user. --- src/command.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/command.c b/src/command.c index f271085..2c2a198 100644 --- a/src/command.c +++ b/src/command.c @@ -23,6 +23,7 @@ */ #include "general.h" +#include "exception.h" #include "command.h" #include "gdb_packet.h" #include "jtag_scan.h" @@ -138,19 +139,30 @@ bool cmd_help(target *t) static bool cmd_jtag_scan(target *t, int argc, char **argv) { (void)t; - uint8_t *irlens = NULL; + uint8_t irlens[argc]; gdb_outf("Target voltage: %s\n", platform_target_voltage()); if (argc > 1) { /* Accept a list of IR lengths on command line */ - irlens = alloca(argc); for (int i = 1; i < argc; i++) irlens[i-1] = atoi(argv[i]); irlens[argc-1] = 0; } - int devs = jtag_scan(irlens); + int devs = -1; + volatile struct exception e; + TRY_CATCH (e, EXCEPTION_ALL) { + devs = jtag_scan(argc > 1 ? irlens : NULL); + } + switch (e.type) { + case EXCEPTION_TIMEOUT: + gdb_outf("Timeout during scan. Is target stuck in WFI?\n"); + break; + case EXCEPTION_ERROR: + gdb_outf("Exception: %s\n", e.msg); + break; + } if(devs < 0) { gdb_out("JTAG device scan failed!\n"); @@ -174,13 +186,25 @@ bool cmd_swdp_scan(void) { gdb_outf("Target voltage: %s\n", platform_target_voltage()); - if(adiv5_swdp_scan() < 0) { + int devs = -1; + volatile struct exception e; + TRY_CATCH (e, EXCEPTION_ALL) { + devs = adiv5_swdp_scan(); + } + switch (e.type) { + case EXCEPTION_TIMEOUT: + gdb_outf("Timeout during scan. Is target stuck in WFI?\n"); + break; + case EXCEPTION_ERROR: + gdb_outf("Exception: %s\n", e.msg); + break; + } + + if(devs < 0) { gdb_out("SW-DP scan failed!\n"); return false; } - //gdb_outf("SW-DP detected IDCODE: 0x%08X\n", adiv5_dp_list->idcode); - cmd_targets(NULL); return true; -- cgit v1.2.3 From 83b83ca48f71639d14673d1deb544bf39a7332be Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Mon, 2 Mar 2015 23:10:15 -0800 Subject: Use controlled timeout on SW/JTAG DP transactions. --- src/adiv5_jtagdp.c | 4 ++-- src/adiv5_swdp.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/adiv5_jtagdp.c b/src/adiv5_jtagdp.c index a460113..d97bc99 100644 --- a/src/adiv5_jtagdp.c +++ b/src/adiv5_jtagdp.c @@ -85,11 +85,11 @@ static uint32_t adiv5_jtagdp_low_access(ADIv5_DP_t *dp, uint8_t RnW, jtag_dev_write_ir(dp->dev, APnDP ? IR_APACC : IR_DPACC); - int tries = 1000; + platform_timeout_set(2000); do { jtag_dev_shift_dr(dp->dev, (uint8_t*)&response, (uint8_t*)&request, 35); ack = response & 0x07; - } while(--tries && (ack == JTAGDP_ACK_WAIT)); + } while(!platform_timeout_is_expired() && (ack == JTAGDP_ACK_WAIT)); if (ack == JTAGDP_ACK_WAIT) raise_exception(EXCEPTION_TIMEOUT, "JTAG-DP ACK timeout"); diff --git a/src/adiv5_swdp.c b/src/adiv5_swdp.c index 1a6b158..b53fcb5 100644 --- a/src/adiv5_swdp.c +++ b/src/adiv5_swdp.c @@ -130,11 +130,11 @@ static uint32_t adiv5_swdp_low_access(ADIv5_DP_t *dp, uint8_t RnW, if((addr == 4) || (addr == 8)) request ^= 0x20; - size_t tries = 1000; + platform_timeout_set(2000); do { swdptap_seq_out(request, 8); ack = swdptap_seq_in(3); - } while(--tries && ack == SWDP_ACK_WAIT); + } while (!platform_timeout_is_expired() && ack == SWDP_ACK_WAIT); if (ack == SWDP_ACK_WAIT) raise_exception(EXCEPTION_TIMEOUT, "SWDP ACK timeout"); -- cgit v1.2.3 From 9a8dbdeff7b9bac70719ddb51a6f83a1266a2d44 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Mon, 2 Mar 2015 23:27:42 -0800 Subject: Fix errors when building for non-native platforms. --- src/platforms/f4discovery/platform.h | 1 + src/platforms/launchpad-icdi/platform.c | 14 ++++++++++++-- src/platforms/launchpad-icdi/platform.h | 2 ++ src/platforms/libftdi/platform.c | 19 +++++++++++++++++++ src/platforms/stlink/platform.h | 1 + src/platforms/swlink/platform.h | 1 + 6 files changed, 36 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/platforms/f4discovery/platform.h b/src/platforms/f4discovery/platform.h index 3c5c582..68027ee 100644 --- a/src/platforms/f4discovery/platform.h +++ b/src/platforms/f4discovery/platform.h @@ -28,6 +28,7 @@ #include "gpio.h" #include "morse.h" #include "timing.h" +#include "target.h" #include diff --git a/src/platforms/launchpad-icdi/platform.c b/src/platforms/launchpad-icdi/platform.c index e689f0c..1a3598a 100644 --- a/src/platforms/launchpad-icdi/platform.c +++ b/src/platforms/launchpad-icdi/platform.c @@ -86,10 +86,20 @@ platform_init(void) cdcacm_init(); } +void platform_timeout_set(uint32_t ms) +{ + timeout_counter = ms / 10; +} + +bool platform_timeout_is_expired(void) +{ + return timeout_counter == 0; +} + void platform_delay(uint32_t delay) { - timeout_counter = delay * 10; - while(timeout_counter); + platform_timeout_set(delay); + while (platform_timeout_is_expired()); } const char *platform_target_voltage(void) diff --git a/src/platforms/launchpad-icdi/platform.h b/src/platforms/launchpad-icdi/platform.h index eb3ac6e..ddc2035 100644 --- a/src/platforms/launchpad-icdi/platform.h +++ b/src/platforms/launchpad-icdi/platform.h @@ -18,6 +18,8 @@ #define __PLATFORM_H #include "gdb_packet.h" +#include "target.h" +#include "morse.h" #include diff --git a/src/platforms/libftdi/platform.c b/src/platforms/libftdi/platform.c index 634090d..3062698 100644 --- a/src/platforms/libftdi/platform.c +++ b/src/platforms/libftdi/platform.c @@ -21,6 +21,7 @@ #include "gdb_if.h" #include +#include struct ftdi_context *ftdic; @@ -258,3 +259,21 @@ void platform_delay(uint32_t delay) usleep(delay * 100000); } +static uint32_t timeout_time; +static uint32_t time_ms(void) +{ + struct timeval tv; + gettimeofday(&tv, NULL); + return (tv.tv_sec * 1000) + (tv.tv_usec / 1000); +} + +void platform_timeout_set(uint32_t ms) +{ + timeout_time = time_ms() + ms; +} + +bool platform_timeout_is_expired(void) +{ + return time_ms() > timeout_time; +} + diff --git a/src/platforms/stlink/platform.h b/src/platforms/stlink/platform.h index f026db3..549b6d6 100644 --- a/src/platforms/stlink/platform.h +++ b/src/platforms/stlink/platform.h @@ -27,6 +27,7 @@ #include "gdb_packet.h" #include "gpio.h" #include "timing.h" +#include "target.h" #include #include diff --git a/src/platforms/swlink/platform.h b/src/platforms/swlink/platform.h index 27cc299..e82124a 100644 --- a/src/platforms/swlink/platform.h +++ b/src/platforms/swlink/platform.h @@ -27,6 +27,7 @@ #include "gdb_packet.h" #include "gpio.h" #include "timing.h" +#include "target.h" #include -- cgit v1.2.3 From 588bad34ba2386737bec4bf4daf50633b0a8fe98 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Sun, 15 Mar 2015 20:47:10 -0700 Subject: Build with -Os for swlink. --- src/platforms/swlink/Makefile.inc | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/platforms/swlink/Makefile.inc b/src/platforms/swlink/Makefile.inc index ca793d4..0ca2a3b 100644 --- a/src/platforms/swlink/Makefile.inc +++ b/src/platforms/swlink/Makefile.inc @@ -2,6 +2,7 @@ CROSS_COMPILE ?= arm-none-eabi- CC = $(CROSS_COMPILE)gcc OBJCOPY = $(CROSS_COMPILE)objcopy +OPT_FLAGS = -Os CFLAGS += -mcpu=cortex-m3 -mthumb \ -DSTM32F1 -DDISCOVERY_SWLINK -I../libopencm3/include \ -I platforms/stm32 -- cgit v1.2.3 From 5ab8564ff67583ac8df977bb6efca047b12e0aed Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Sun, 22 Mar 2015 14:05:12 -0700 Subject: Clean up handling of lost targets using new exceptions mechanism. --- src/cortexm.c | 17 +++++++++++++++-- src/exception.c | 2 +- src/gdb_main.c | 6 ++++++ src/main.c | 16 ++++++++++++++-- src/platforms/stm32/timing.c | 1 + 5 files changed, 37 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/cortexm.c b/src/cortexm.c index f20f282..f6a0ea3 100644 --- a/src/cortexm.c +++ b/src/cortexm.c @@ -37,6 +37,7 @@ #include "command.h" #include "gdb_packet.h" #include "cortexm.h" +#include "morse.h" #include @@ -57,6 +58,7 @@ const struct command_s cortexm_cmd_list[] = { #define SIGINT 2 #define SIGTRAP 5 #define SIGSEGV 11 +#define SIGLOST 29 static int cortexm_regs_read(struct target_s *target, void *data); static int cortexm_regs_write(struct target_s *target, const void *data); @@ -487,12 +489,23 @@ cortexm_halt_wait(struct target_s *target) uint32_t dhcsr = 0; volatile struct exception e; - TRY_CATCH (e, EXCEPTION_TIMEOUT) { + TRY_CATCH (e, EXCEPTION_ALL) { /* If this times out because the target is in WFI then * the target is still running. */ dhcsr = target_mem_read32(target, CORTEXM_DHCSR); } - if (e.type || !(dhcsr & CORTEXM_DHCSR_S_HALT)) + switch (e.type) { + case EXCEPTION_ERROR: + /* Oh crap, there's no recovery from this... */ + target_list_free(); + morse("TARGET LOST.", 1); + return SIGLOST; + case EXCEPTION_TIMEOUT: + /* Timeout isn't a problem, target could be in WFI */ + return 0; + } + + if (!(dhcsr & CORTEXM_DHCSR_S_HALT)) return 0; /* We've halted. Let's find out why. */ diff --git a/src/exception.c b/src/exception.c index 33e3869..3d43f99 100644 --- a/src/exception.c +++ b/src/exception.c @@ -34,6 +34,6 @@ void raise_exception(uint32_t type, const char *msg) longjmp(e->jmpbuf, type); } } - PLATFORM_FATAL_ERROR(type); + abort(); } diff --git a/src/gdb_main.c b/src/gdb_main.c index 7bb788b..750dfe2 100644 --- a/src/gdb_main.c +++ b/src/gdb_main.c @@ -158,6 +158,12 @@ gdb_main(void) if (sig < 0) break; + /* Target disappeared */ + if (cur_target == NULL) { + gdb_putpacket_f("X%02X", sig); + break; + } + /* Report reason for halt */ if(target_check_hw_wp(cur_target, &watch_addr)) { /* Watchpoint hit */ diff --git a/src/main.c b/src/main.c index 60db15c..d1b3c86 100644 --- a/src/main.c +++ b/src/main.c @@ -28,6 +28,9 @@ #include "jtagtap.h" #include "jtag_scan.h" #include "target.h" +#include "exception.h" +#include "gdb_packet.h" +#include "morse.h" int main(int argc, char **argv) @@ -39,9 +42,18 @@ main(int argc, char **argv) (void) argv; platform_init(); #endif - PLATFORM_SET_FATAL_ERROR_RECOVERY(); - gdb_main(); + while (true) { + volatile struct exception e; + TRY_CATCH(e, EXCEPTION_ALL) { + gdb_main(); + } + if (e.type == EXCEPTION_ERROR) { + gdb_putpacketz("EFF"); + target_list_free(); + morse("TARGET LOST.", 1); + } + } /* Should never get here */ return 0; diff --git a/src/platforms/stm32/timing.c b/src/platforms/stm32/timing.c index cac22ca..55a217a 100644 --- a/src/platforms/stm32/timing.c +++ b/src/platforms/stm32/timing.c @@ -17,6 +17,7 @@ * along with this program. If not, see . */ #include "general.h" +#include "morse.h" #include #include -- cgit v1.2.3 From 68f54a35457da4c07ec84bd7e0c2823183e8811e Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Sun, 22 Mar 2015 14:06:56 -0700 Subject: Remove old platform specific error handling macros. --- src/platforms/f4discovery/platform.h | 15 --------------- src/platforms/launchpad-icdi/platform.c | 1 - src/platforms/launchpad-icdi/platform.h | 17 ----------------- src/platforms/libftdi/platform.h | 3 --- src/platforms/native/platform.c | 2 -- src/platforms/native/platform.h | 17 ----------------- src/platforms/stlink/platform.c | 2 -- src/platforms/stlink/platform.h | 15 --------------- src/platforms/swlink/platform.c | 2 -- src/platforms/swlink/platform.h | 15 --------------- 10 files changed, 89 deletions(-) (limited to 'src') diff --git a/src/platforms/f4discovery/platform.h b/src/platforms/f4discovery/platform.h index 68027ee..92ae046 100644 --- a/src/platforms/f4discovery/platform.h +++ b/src/platforms/f4discovery/platform.h @@ -24,11 +24,8 @@ #ifndef __PLATFORM_H #define __PLATFORM_H -#include "gdb_packet.h" #include "gpio.h" -#include "morse.h" #include "timing.h" -#include "target.h" #include @@ -142,8 +139,6 @@ #define DEBUG(...) -extern jmp_buf fatal_error_jmpbuf; - #define gpio_set_val(port, pin, val) do { \ if(val) \ gpio_set((port), (pin)); \ @@ -155,16 +150,6 @@ extern jmp_buf fatal_error_jmpbuf; #define SET_IDLE_STATE(state) {gpio_set_val(LED_PORT, LED_IDLE_RUN, state);} #define SET_ERROR_STATE(state) {gpio_set_val(LED_PORT, LED_ERROR, state);} -#define PLATFORM_SET_FATAL_ERROR_RECOVERY() {setjmp(fatal_error_jmpbuf);} -#define PLATFORM_FATAL_ERROR(error) { \ - if(running_status) gdb_putpacketz("X1D"); \ - else gdb_putpacketz("EFF"); \ - running_status = 0; \ - target_list_free(); \ - morse("TARGET LOST.", 1); \ - longjmp(fatal_error_jmpbuf, (error)); \ -} - static inline int platform_hwversion(void) { return 0; diff --git a/src/platforms/launchpad-icdi/platform.c b/src/platforms/launchpad-icdi/platform.c index 1a3598a..ff67fa0 100644 --- a/src/platforms/launchpad-icdi/platform.c +++ b/src/platforms/launchpad-icdi/platform.c @@ -33,7 +33,6 @@ extern void trace_tick(void); -jmp_buf fatal_error_jmpbuf; uint8_t running_status; volatile uint32_t timeout_counter; diff --git a/src/platforms/launchpad-icdi/platform.h b/src/platforms/launchpad-icdi/platform.h index ddc2035..c13172f 100644 --- a/src/platforms/launchpad-icdi/platform.h +++ b/src/platforms/launchpad-icdi/platform.h @@ -17,12 +17,6 @@ #ifndef __PLATFORM_H #define __PLATFORM_H -#include "gdb_packet.h" -#include "target.h" -#include "morse.h" - -#include - #include #include @@ -31,7 +25,6 @@ #define DFU_IDENT "Black Magic Firmware Upgrade (Launchpad)" #define DFU_IFACE_STRING "lolwut" -extern jmp_buf fatal_error_jmpbuf; extern uint8_t running_status; extern volatile uint32_t timeout_counter; @@ -108,16 +101,6 @@ extern usbd_driver lm4f_usb_driver; #define SET_IDLE_STATE(state) {} #define SET_ERROR_STATE(state) SET_IDLE_STATE(state) -#define PLATFORM_SET_FATAL_ERROR_RECOVERY() {setjmp(fatal_error_jmpbuf);} -#define PLATFORM_FATAL_ERROR(error) { \ - if( running_status ) gdb_putpacketz("X1D"); \ - else gdb_putpacketz("EFF"); \ - running_status = 0; \ - target_list_free(); \ - morse("TARGET LOST.", 1); \ - longjmp(fatal_error_jmpbuf, (error)); \ -} - #define PLATFORM_HAS_TRACESWO inline static void gpio_set_val(uint32_t port, uint8_t pin, uint8_t val) { diff --git a/src/platforms/libftdi/platform.h b/src/platforms/libftdi/platform.h index 135b2e3..8611674 100644 --- a/src/platforms/libftdi/platform.h +++ b/src/platforms/libftdi/platform.h @@ -36,9 +36,6 @@ #define SET_IDLE_STATE(state) #define SET_ERROR_STATE(state) -#define PLATFORM_FATAL_ERROR(error) abort() -#define PLATFORM_SET_FATAL_ERROR_RECOVERY() - extern struct ftdi_context *ftdic; void platform_buffer_flush(void); diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index ac54b4b..babb498 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -35,8 +35,6 @@ #include #include -jmp_buf fatal_error_jmpbuf; - static void adc_init(void); static void setup_vbus_irq(void); diff --git a/src/platforms/native/platform.h b/src/platforms/native/platform.h index 3b1769b..6958585 100644 --- a/src/platforms/native/platform.h +++ b/src/platforms/native/platform.h @@ -24,13 +24,9 @@ #ifndef __PLATFORM_H #define __PLATFORM_H -#include "gdb_packet.h" #include "gpio.h" -#include "morse.h" #include "timing.h" -#include - #define PLATFORM_HAS_TRACESWO #define PLATFORM_HAS_POWER_SWITCH #define BOARD_IDENT "Black Magic Probe" @@ -147,23 +143,10 @@ #define DEBUG(...) -extern jmp_buf fatal_error_jmpbuf; - #define SET_RUN_STATE(state) {running_status = (state);} #define SET_IDLE_STATE(state) {gpio_set_val(LED_PORT, LED_IDLE_RUN, state);} #define SET_ERROR_STATE(state) {gpio_set_val(LED_PORT, LED_ERROR, state);} -#include "target.h" -#define PLATFORM_SET_FATAL_ERROR_RECOVERY() {setjmp(fatal_error_jmpbuf);} -#define PLATFORM_FATAL_ERROR(error) do { \ - if(running_status) gdb_putpacketz("X1D"); \ - else gdb_putpacketz("EFF"); \ - running_status = 0; \ - target_list_free(); \ - morse("TARGET LOST.", 1); \ - longjmp(fatal_error_jmpbuf, (error)); \ -} while (0) - /* Use newlib provided integer only stdio functions */ #define sscanf siscanf #define sprintf siprintf diff --git a/src/platforms/stlink/platform.c b/src/platforms/stlink/platform.c index fb10faa..dd501a4 100644 --- a/src/platforms/stlink/platform.c +++ b/src/platforms/stlink/platform.c @@ -36,8 +36,6 @@ uint8_t running_status; volatile uint32_t timeout_counter; -jmp_buf fatal_error_jmpbuf; - uint16_t led_idle_run; /* Pins PC[14:13] are used to detect hardware revision. Read * 11 for STLink V1 e.g. on VL Discovery, tag as hwversion 0 diff --git a/src/platforms/stlink/platform.h b/src/platforms/stlink/platform.h index 549b6d6..aa02ac0 100644 --- a/src/platforms/stlink/platform.h +++ b/src/platforms/stlink/platform.h @@ -24,17 +24,13 @@ #ifndef __PLATFORM_H #define __PLATFORM_H -#include "gdb_packet.h" #include "gpio.h" #include "timing.h" -#include "target.h" #include #include #include -#include - #define BOARD_IDENT "Black Magic Probe (STLINK), (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" #define BOARD_IDENT_DFU "Black Magic (Upgrade) for STLink/Discovery, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" #define BOARD_IDENT_UPD "Black Magic (DFU Upgrade) for STLink/Discovery, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" @@ -131,23 +127,12 @@ #define DEBUG(...) -extern jmp_buf fatal_error_jmpbuf; - extern uint16_t led_idle_run; #define LED_IDLE_RUN led_idle_run #define SET_RUN_STATE(state) {running_status = (state);} #define SET_IDLE_STATE(state) {gpio_set_val(LED_PORT, led_idle_run, state);} #define SET_ERROR_STATE(x) -#define PLATFORM_SET_FATAL_ERROR_RECOVERY() {setjmp(fatal_error_jmpbuf);} -#define PLATFORM_FATAL_ERROR(error) do { \ - if(running_status) gdb_putpacketz("X1D"); \ - else gdb_putpacketz("EFF"); \ - running_status = 0; \ - target_list_free(); \ - longjmp(fatal_error_jmpbuf, (error)); \ -} while (0) - /* Use newlib provided integer only stdio functions */ #define sscanf siscanf #define sprintf siprintf diff --git a/src/platforms/swlink/platform.c b/src/platforms/swlink/platform.c index cbdae0c..02cde19 100644 --- a/src/platforms/swlink/platform.c +++ b/src/platforms/swlink/platform.c @@ -33,8 +33,6 @@ #include #include -jmp_buf fatal_error_jmpbuf; - void platform_init(void) { uint32_t data; diff --git a/src/platforms/swlink/platform.h b/src/platforms/swlink/platform.h index e82124a..2c6fb76 100644 --- a/src/platforms/swlink/platform.h +++ b/src/platforms/swlink/platform.h @@ -24,12 +24,8 @@ #ifndef __PLATFORM_H #define __PLATFORM_H -#include "gdb_packet.h" #include "gpio.h" #include "timing.h" -#include "target.h" - -#include #define BOARD_IDENT "Black Magic Probe (SWLINK), (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" #define BOARD_IDENT_DFU "Black Magic (Upgrade), STM8S Discovery, (Firmware 1.5" VERSION_SUFFIX ", build " BUILDDATE ")" @@ -126,21 +122,10 @@ #define DEBUG(...) -extern jmp_buf fatal_error_jmpbuf; - #define SET_RUN_STATE(state) {running_status = (state);} #define SET_IDLE_STATE(state) {gpio_set_val(LED_PORT, LED_IDLE_RUN, state);} #define SET_ERROR_STATE(x) -#define PLATFORM_SET_FATAL_ERROR_RECOVERY() {setjmp(fatal_error_jmpbuf);} -#define PLATFORM_FATAL_ERROR(error) { \ - if(running_status) gdb_putpacketz("X1D"); \ - else gdb_putpacketz("EFF"); \ - running_status = 0; \ - target_list_free(); \ - longjmp(fatal_error_jmpbuf, (error)); \ -} - /* Use newlib provided integer only stdio functions */ #define sscanf siscanf #define sprintf siprintf -- cgit v1.2.3