[Bug 172] Add support for GCC's weak attribute

via D.gnu d.gnu at puremagic.com
Sun Apr 5 03:56:57 PDT 2015


http://bugzilla.gdcproject.org/show_bug.cgi?id=172

Jens Bauer <jens-bugzilla at gpio.dk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jens-bugzilla at gpio.dk

--- Comment #1 from Jens Bauer <jens-bugzilla at gpio.dk> ---
Having support for this will be highly appreciated.

Especially weak,alias is important on microcontrollers, which have exception
vectors.

Small C Example (this one is for ARM Cortex-M microcontrollers):

---8<-----8<-----8<-----
#define WA(a)   __attribute__((weak, alias(#a)))
#define WE      WA(defaultExceptionHandler)
#define WR      WA(defaultResetHandler)

typedef void (*const VectorFunc)(void);

static void defaultResetHandler(void) __attribute__((__interrupt__));


/* $0000 System Exception Vector Handlers: */
void WR Reset_Handler(void);        /*   1 $0004 Reset */
void WE NMI_Handler(void);          /*   2 $0008 Non Maskable Interrupt */
void WE HardFault_Handler(void);    /*   3 $000c Hard Fault */

...
...

/* Vector Table */
__attribute__((section(".isr_vector"))) VectorFunc g_pfnVectors[] =
{
    (VectorFunc)STACK_ADDRESS,  /*   0 $0000 Initial Stack Pointer */
    Reset_Handler,              /*   1 $0004 Reset Vector */
    NMI_Handler,                /*   2 $0008 Non Maskable Interrupt Vector */
    HardFault_Handler,          /*   3 $000c Hard Fault Vector */

    ...
    ...
};

static void defaultResetHandler(void)
{
    while(1){ asm volatile("wfi"); }
}
--->8----->8----->8-----

The above example demonstrates the use of the section attribute and the use of
the weak+alias attribute.
The weak+alias is used for having default implementations of all the exception
handlers (including Reset_Handler).
This means that the user can just start writing code, but allows customization
in case an implementation, which is either simpler or more advanced than the
provided one is required.

-- 
You are receiving this mail because:
You are watching all bug changes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/d.gnu/attachments/20150405/eeeb2792/attachment.html>


More information about the D.gnu mailing list