From c530bd077bf487c1e76ec99af4d610061dadce12 Mon Sep 17 00:00:00 2001 From: dragonmux Date: Mon, 4 Jul 2022 05:40:15 -0400 Subject: [PATCH] misc: Switched to using C11 --- libopencm3 | 2 +- src/Makefile | 2 +- src/command.c | 5 +++++ src/gdb_main.c | 4 ++++ src/include/general.h | 5 ++--- src/platforms/common/jtagtap.c | 2 +- src/platforms/launchpad-icdi/platform.c | 2 +- src/platforms/native/platform.c | 6 +++--- src/platforms/stm32/dfu_f1.c | 3 +-- src/platforms/stm32/dfu_f4.c | 3 +-- src/platforms/stm32/gdb_if.c | 5 ++--- src/platforms/stm32/usbuart.c | 2 +- src/target/flashstub/stub.h | 3 +-- src/target/rp.c | 8 ++++---- 14 files changed, 28 insertions(+), 24 deletions(-) diff --git a/libopencm3 b/libopencm3 index 8435287..44e142d 160000 --- a/libopencm3 +++ b/libopencm3 @@ -1 +1 @@ -Subproject commit 8435287300e5ca9af9f889c529e7b1fa019c42fb +Subproject commit 44e142d4f97863e669737707a1a22bf40ed49bbc diff --git a/src/Makefile b/src/Makefile index b8e7921..c06fa28 100644 --- a/src/Makefile +++ b/src/Makefile @@ -9,7 +9,7 @@ Q := @ endif CFLAGS += -Wall -Wextra -Werror -Wno-char-subscripts \ - -std=gnu99 -g3 -MD -I./target \ + -std=c11 -g3 -MD -I./target \ -I. -Iinclude -I$(PLATFORM_DIR) ifeq ($(ENABLE_DEBUG), 1) diff --git a/src/command.c b/src/command.c index ddcdfc2..bcb845b 100644 --- a/src/command.c +++ b/src/command.c @@ -42,6 +42,8 @@ # include "traceswo.h" #endif +#include + static bool cmd_version(target *t, int argc, char **argv); static bool cmd_help(target *t, int argc, char **argv); @@ -117,6 +119,9 @@ int command_process(target *t, char *cmd) for(char *s = cmd; *s; s++) if((*s == ' ') || (*s == '\t')) argc++; + /* This needs replacing with something more sensible. + * It should be pinging -Wvla among other things, and it failing is straight-up UB + */ argv = alloca(sizeof(const char *) * argc); /* Tokenize cmd to find argv */ diff --git a/src/gdb_main.c b/src/gdb_main.c index 0713dae..917877e 100644 --- a/src/gdb_main.c +++ b/src/gdb_main.c @@ -39,6 +39,8 @@ #include "rtt.h" #endif +#include + enum gdb_signal { GDB_SIGINT = 2, GDB_SIGTRAP = 5, @@ -361,6 +363,8 @@ static void exec_q_rcmd(const char *packet,int len) /* calculate size and allocate buffer for command */ datalen = len / 2; + // This needs replacing with something more sensible. + // It should be pinging -Wvla among other things, and it failing is straight-up UB data = alloca(datalen + 1); /* dehexify command */ unhexify(data, packet, datalen); diff --git a/src/include/general.h b/src/include/general.h index 829c2f6..3c927e5 100644 --- a/src/include/general.h +++ b/src/include/general.h @@ -21,9 +21,8 @@ #ifndef __GENERAL_H #define __GENERAL_H -#if !defined(_GNU_SOURCE) -# define _GNU_SOURCE -#endif +#define _GNU_SOURCE +#define _DEFAULT_SOURCE #if !defined(__USE_MINGW_ANSI_STDIO) # define __USE_MINGW_ANSI_STDIO 1 #endif diff --git a/src/platforms/common/jtagtap.c b/src/platforms/common/jtagtap.c index 7ee0a23..7119e38 100644 --- a/src/platforms/common/jtagtap.c +++ b/src/platforms/common/jtagtap.c @@ -59,7 +59,7 @@ static void jtagtap_reset(void) if (platform_hwversion() == 0) { gpio_clear(TRST_PORT, TRST_PIN); for (volatile size_t i = 0; i < 10000; i++) - asm("nop"); + __asm__("nop"); gpio_set(TRST_PORT, TRST_PIN); } #endif diff --git a/src/platforms/launchpad-icdi/platform.c b/src/platforms/launchpad-icdi/platform.c index c26ce1f..2f2ad1e 100644 --- a/src/platforms/launchpad-icdi/platform.c +++ b/src/platforms/launchpad-icdi/platform.c @@ -92,7 +92,7 @@ void platform_nrst_set_val(bool assert) volatile int i; if (assert) { gpio_clear(NRST_PORT, NRST_PIN); - for(i = 0; i < 10000; i++) asm("nop"); + for(i = 0; i < 10000; i++) __asm__("nop"); } else { gpio_set(NRST_PORT, NRST_PIN); } diff --git a/src/platforms/native/platform.c b/src/platforms/native/platform.c index d62a9b2..64dee42 100644 --- a/src/platforms/native/platform.c +++ b/src/platforms/native/platform.c @@ -108,7 +108,7 @@ int platform_hwversion(void) gpio_set(GPIOB, hwversion_pins); /* Wait a little to make sure the pull up is in effect... */ - for(int i = 0; i < 100; i++) asm("nop"); + for(int i = 0; i < 100; i++) __asm__("nop"); /* Get all pins that are pulled low in hardware. * This also sets all the "unused" pins to 1. @@ -119,7 +119,7 @@ int platform_hwversion(void) gpio_clear(GPIOB, hwversion_pins); /* Wait a little to make sure the pull down is in effect... */ - for(int i = 0; i < 100; i++) asm("nop"); + for(int i = 0; i < 100; i++) __asm__("nop"); /* Get all the pins that are pulled high in hardware. */ uint16_t pins_positive = gpio_get(GPIOB, hwversion_pins); @@ -243,7 +243,7 @@ void platform_nrst_set_val(bool assert) gpio_set_val(NRST_PORT, NRST_PIN, !assert); } if (assert) { - for(int i = 0; i < 10000; i++) asm("nop"); + for(int i = 0; i < 10000; i++) __asm__("nop"); } } diff --git a/src/platforms/stm32/dfu_f1.c b/src/platforms/stm32/dfu_f1.c index fc9f418..26a0955 100644 --- a/src/platforms/stm32/dfu_f1.c +++ b/src/platforms/stm32/dfu_f1.c @@ -105,10 +105,9 @@ void dfu_jump_app_if_valid(void) /* Set vector table base address */ SCB_VTOR = app_address & 0x1FFFFF; /* Max 2 MByte Flash*/ /* Initialise master stack pointer */ - asm volatile ("msr msp, %0"::"g" + __asm__ volatile("msr msp, %0"::"g" (*(volatile uint32_t*)app_address)); /* Jump to application */ (*(void(**)())(app_address + 4))(); } } - diff --git a/src/platforms/stm32/dfu_f4.c b/src/platforms/stm32/dfu_f4.c index 5d0c25a..6ca32be 100644 --- a/src/platforms/stm32/dfu_f4.c +++ b/src/platforms/stm32/dfu_f4.c @@ -101,10 +101,9 @@ void dfu_jump_app_if_valid(void) SCB_VTOR = app_address & 0x1FFFFF; /* Max 2 MByte Flash*/ #endif /* Initialise master stack pointer */ - asm volatile ("msr msp, %0"::"g" + __asm__ volatile("msr msp, %0"::"g" (*(volatile uint32_t*)app_address)); /* Jump to application */ (*(void(**)())(app_address + 4))(); } } - diff --git a/src/platforms/stm32/gdb_if.c b/src/platforms/stm32/gdb_if.c index 6cc1f9c..ce534f0 100644 --- a/src/platforms/stm32/gdb_if.c +++ b/src/platforms/stm32/gdb_if.c @@ -81,7 +81,7 @@ static void gdb_if_update_buf(void) { while (cdcacm_get_config() != 1); #ifdef STM32F4 - asm volatile ("cpsid i; isb"); + __asm__ volatile("cpsid i; isb"); if (count_new) { memcpy(buffer_out, double_buffer_out, count_new); count_out = count_new; @@ -89,7 +89,7 @@ static void gdb_if_update_buf(void) out_ptr = 0; usbd_ep_nak_set(usbdev, CDCACM_GDB_ENDPOINT, 0); } - asm volatile ("cpsie i; isb"); + __asm__ volatile("cpsie i; isb"); #else count_out = usbd_ep_read_packet(usbdev, CDCACM_GDB_ENDPOINT, buffer_out, CDCACM_PACKET_SIZE); @@ -129,4 +129,3 @@ unsigned char gdb_if_getchar_to(int timeout) return -1; } - diff --git a/src/platforms/stm32/usbuart.c b/src/platforms/stm32/usbuart.c index 9a35466..4a8ae6d 100644 --- a/src/platforms/stm32/usbuart.c +++ b/src/platforms/stm32/usbuart.c @@ -629,7 +629,7 @@ void debug_monitor_handler_c(struct ex_frame *sp) } -asm(".globl debug_monitor_handler\n" +__asm__(".globl debug_monitor_handler\n" ".thumb_func\n" "debug_monitor_handler: \n" " mov r0, sp\n" diff --git a/src/target/flashstub/stub.h b/src/target/flashstub/stub.h index b837bae..bbcd2db 100644 --- a/src/target/flashstub/stub.h +++ b/src/target/flashstub/stub.h @@ -23,8 +23,7 @@ static inline void __attribute__((always_inline)) stub_exit(const int code) { - asm("bkpt %0"::"i"(code)); + __asm__("bkpt %0"::"i"(code)); } #endif - diff --git a/src/target/rp.c b/src/target/rp.c index 8261dc1..e889c4c 100644 --- a/src/target/rp.c +++ b/src/target/rp.c @@ -466,10 +466,10 @@ static bool rp_attach(target *t) if (!cortexm_attach(t)) return false; - struct rp_priv_s *ps = (struct rp_priv_s *)t->target_storage; - uint16_t *table = alloca(RP_MAX_TABLE_SIZE); - uint16_t table_offset = target_mem_read32(t, BOOTROM_MAGIC_ADDR + 4); - if (!table || target_mem_read(t, table, table_offset, RP_MAX_TABLE_SIZE)) + struct rp_priv_s *ps = (struct rp_priv_s*)t->target_storage; + uint16_t table[RP_MAX_TABLE_SIZE]; + uint16_t table_offset = target_mem_read32( t, BOOTROM_MAGIC_ADDR + 4); + if (target_mem_read(t, table, table_offset, RP_MAX_TABLE_SIZE)) return false; if (rp2040_fill_table(ps, table, RP_MAX_TABLE_SIZE)) return false;