From d993c5a108563b6fd307506fae9863e4caf69ad0 Mon Sep 17 00:00:00 2001 From: Chun-Chieh Li Date: Wed, 2 Oct 2019 16:43:23 +0800 Subject: [PATCH] NUVOTON: Re-implement __PC() with toolchain built-in Re-implement __PC() by replacing BSP assembly with toolchain built-in. --- .../TARGET_M2351/device/M2351_funcs.S | 37 ------------------- .../TARGET_M2351/device/system_M2351.c | 16 ++++++++ .../TARGET_M261/device/system_M261.c | 16 ++++++++ 3 files changed, 32 insertions(+), 37 deletions(-) delete mode 100644 targets/TARGET_NUVOTON/TARGET_M2351/device/M2351_funcs.S diff --git a/targets/TARGET_NUVOTON/TARGET_M2351/device/M2351_funcs.S b/targets/TARGET_NUVOTON/TARGET_M2351/device/M2351_funcs.S deleted file mode 100644 index 16b8b2f74a..0000000000 --- a/targets/TARGET_NUVOTON/TARGET_M2351/device/M2351_funcs.S +++ /dev/null @@ -1,37 +0,0 @@ -#if defined(__CC_ARM) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) - AREA |.text|, CODE, READONLY -__PC PROC - EXPORT __PC -#elif defined(__GNUC__) - .text - .thumb - .thumb_func - .globl __PC - .type __PC, %function -__PC: -#else ;; for IAR, __ICCARM__ seems not defined in IAR asm - MODULE nvtfunc - - SECTION .text:CODE:REORDER:NOROOT(1) - THUMB - - PUBLIC __PC -__PC -#endif - - MOV r0, lr - BLX lr - - -#if defined(__CC_ARM) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) - ALIGN - ENDP - END -#elif defined(__GNUC__) - .align - .pool - .size __PC, . - __PC - .end -#else ;; for IAR, __ICCARM__ seems not defined in IAR asm - END -#endif \ No newline at end of file diff --git a/targets/TARGET_NUVOTON/TARGET_M2351/device/system_M2351.c b/targets/TARGET_NUVOTON/TARGET_M2351/device/system_M2351.c index e7cc9daed5..fa19e4857b 100644 --- a/targets/TARGET_NUVOTON/TARGET_M2351/device/system_M2351.c +++ b/targets/TARGET_NUVOTON/TARGET_M2351/device/system_M2351.c @@ -115,3 +115,19 @@ void AssertError(uint8_t * file, uint32_t line) } #endif +/* Return LR (return address) + * + * Replace BSP assembly implementation with toolchain built-in (borrow MBED_CALLER_ADDR()) + */ +uint32_t __PC(void) +{ +#if (defined(__GNUC__) || defined(__clang__)) && !defined(__CC_ARM) + return (uint32_t) __builtin_extract_return_addr(__builtin_return_address(0)); +#elif defined(__CC_ARM) + return (uint32_t) __builtin_return_address(0); +#elif defined(__ICCARM__) + return (uint32_t) __get_LR(); +#else + #error("__PC() not implemented") +#endif +} diff --git a/targets/TARGET_NUVOTON/TARGET_M261/device/system_M261.c b/targets/TARGET_NUVOTON/TARGET_M261/device/system_M261.c index 848cb2e18e..c68229592a 100644 --- a/targets/TARGET_NUVOTON/TARGET_M261/device/system_M261.c +++ b/targets/TARGET_NUVOTON/TARGET_M261/device/system_M261.c @@ -116,3 +116,19 @@ void AssertError(uint8_t * file, uint32_t line) } #endif +/* Return LR (return address) + * + * Replace BSP assembly implementation with toolchain built-in (borrow MBED_CALLER_ADDR()) + */ +uint32_t __PC(void) +{ +#if (defined(__GNUC__) || defined(__clang__)) && !defined(__CC_ARM) + return (uint32_t) __builtin_extract_return_addr(__builtin_return_address(0)); +#elif defined(__CC_ARM) + return (uint32_t) __builtin_return_address(0); +#elif defined(__ICCARM__) + return (uint32_t) __get_LR(); +#else + #error("__PC() not implemented") +#endif +}