From: Stephan Baerwolf Date: Tue, 10 Sep 2013 19:34:44 +0000 (+0200) Subject: further trick to optimize code size X-Git-Tag: testing-head~23 X-Git-Url: http://git.linex4red.de/pub/USBaspLoader.git/commitdiff_plain/206b8f6f5fc48e9cc2b3432314191ffc0fc7804f further trick to optimize code size This is a very dangerous path to go, but it is worth it. Signed-off-by: Stephan Baerwolf --- diff --git a/firmware/main.c b/firmware/main.c index 8114dda..2c029b8 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -113,7 +113,13 @@ typedef union longConverter{ #if BOOTLOADER_CAN_EXIT -static volatile unsigned char stayinloader = 0xfe; +# if ((HAVE_UNPRECISEWAIT)) +/* here we have to assume we need to optimize for every byte */ +#define __REGISTER_stayinloader_initialValue 0xfe +volatile register uint8_t stayinloader __asm__("r17"); +# else +static volatile uint8_t stayinloader = 0xfe; +# endif #endif static longConverter_t currentAddress; /* in bytes */ @@ -196,6 +202,18 @@ static const uchar signatureBytes[4] = { /* ------------------------------------------------------------------------ */ +#if (__REGISTER_stayinloader_initialValue) +/* need to put it after libc init - otherwise it fucks up the register */ +void __attribute__ ((section(".init8"),naked,used,no_instrument_function)) __REGISTER_stayinloader_initialValue_INITIALIZATION(void); +void __REGISTER_stayinloader_initialValue_INITIALIZATION(void) { + asm volatile ( + "ldi %[silreg] , %[silval]\n\t" + : [silreg] "=a" (stayinloader) + : [silval] "M" (__REGISTER_stayinloader_initialValue) + ); +} +#endif + #if (HAVE_BOOTLOADERENTRY_FROMSOFTWARE) void __attribute__ ((section(".init3"),naked,used,no_instrument_function)) __BOOTLOADERENTRY_FROMSOFTWARE__bootup_investigate_RAMEND(void); void __BOOTLOADERENTRY_FROMSOFTWARE__bootup_investigate_RAMEND(void) {