aboutsummaryrefslogtreecommitdiff
path: root/lib/lpc17xx/vector.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lpc17xx/vector.c')
-rw-r--r--lib/lpc17xx/vector.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/lpc17xx/vector.c b/lib/lpc17xx/vector.c
index 518f562..4cccb6e 100644
--- a/lib/lpc17xx/vector.c
+++ b/lib/lpc17xx/vector.c
@@ -21,6 +21,10 @@
/* Symbols exported by the linker script(s): */
extern unsigned _data_loadaddr, _data, _edata, _ebss, _stack;
+typedef void (*funcp_t) (void);
+extern funcp_t __preinit_array_start, __preinit_array_end;
+extern funcp_t __init_array_start, __init_array_end;
+extern funcp_t __fini_array_start, __fini_array_end;
void main(void);
void reset_handler(void);
@@ -60,6 +64,7 @@ void (*const vector_table[]) (void) = {
void reset_handler(void)
{
volatile unsigned *src, *dest;
+ funcp_t *fp;
__asm__("MSR msp, %0" : : "r"(&_stack));
@@ -69,8 +74,18 @@ void reset_handler(void)
while (dest < &_ebss)
*dest++ = 0;
+ /* Constructors. */
+ for (fp = &__preinit_array_start; fp < &__preinit_array_end; fp++)
+ (*fp)();
+ for (fp = &__init_array_start; fp < &__init_array_end; fp++)
+ (*fp)();
+
/* Call the application's entry point. */
main();
+
+ /* Destructors. */
+ for (fp = &__fini_array_start; fp < &__fini_array_end; fp++)
+ (*fp)();
}
void blocking_handler(void)