aboutsummaryrefslogtreecommitdiff
path: root/lib/lpc43xx
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lpc43xx')
-rw-r--r--lib/lpc43xx/libopencm3_lpc43xx.ld23
-rw-r--r--lib/lpc43xx/libopencm3_lpc43xx_rom_to_ram.ld23
-rw-r--r--lib/lpc43xx/vector.c15
3 files changed, 61 insertions, 0 deletions
diff --git a/lib/lpc43xx/libopencm3_lpc43xx.ld b/lib/lpc43xx/libopencm3_lpc43xx.ld
index 9402a54..5dad9ec 100644
--- a/lib/lpc43xx/libopencm3_lpc43xx.ld
+++ b/lib/lpc43xx/libopencm3_lpc43xx.ld
@@ -42,6 +42,29 @@ SECTIONS
. = ALIGN(4);
} >rom
+ /* C++ Static constructors/destructors, also used for __attribute__
+ * ((constructor)) and the likes */
+ .preinit_array : {
+ . = ALIGN(4);
+ __preinit_array_start = .;
+ KEEP (*(.preinit_array))
+ __preinit_array_end = .;
+ } >rom
+ .init_array : {
+ . = ALIGN(4);
+ __init_array_start = .;
+ KEEP (*(SORT(.init_array.*)))
+ KEEP (*(.init_array))
+ __init_array_end = .;
+ } >rom
+ .fini_array : {
+ . = ALIGN(4);
+ __fini_array_start = .;
+ KEEP (*(.fini_array))
+ KEEP (*(SORT(.fini_array.*)))
+ __fini_array_end = .;
+ } >rom
+
/*
* Another section used by C++ stuff, appears when using newlib with
* 64bit (long long) printf support
diff --git a/lib/lpc43xx/libopencm3_lpc43xx_rom_to_ram.ld b/lib/lpc43xx/libopencm3_lpc43xx_rom_to_ram.ld
index 06f7708..39602b5 100644
--- a/lib/lpc43xx/libopencm3_lpc43xx_rom_to_ram.ld
+++ b/lib/lpc43xx/libopencm3_lpc43xx_rom_to_ram.ld
@@ -43,6 +43,29 @@ SECTIONS
. = ALIGN(4);
} >rom
+ /* C++ Static constructors/destructors, also used for __attribute__
+ * ((constructor)) and the likes */
+ .preinit_array : {
+ . = ALIGN(4);
+ __preinit_array_start = .;
+ KEEP (*(.preinit_array))
+ __preinit_array_end = .;
+ } >rom
+ .init_array : {
+ . = ALIGN(4);
+ __init_array_start = .;
+ KEEP (*(SORT(.init_array.*)))
+ KEEP (*(.init_array))
+ __init_array_end = .;
+ } >rom
+ .fini_array : {
+ . = ALIGN(4);
+ __fini_array_start = .;
+ KEEP (*(.fini_array))
+ KEEP (*(SORT(.fini_array.*)))
+ __fini_array_end = .;
+ } >rom
+
/*
* Another section used by C++ stuff, appears when using newlib with
* 64bit (long long) printf support
diff --git a/lib/lpc43xx/vector.c b/lib/lpc43xx/vector.c
index 23008bc..d4aa2f5 100644
--- a/lib/lpc43xx/vector.c
+++ b/lib/lpc43xx/vector.c
@@ -23,6 +23,10 @@
/* Symbols exported by the linker script(s): */
extern unsigned _data_loadaddr, _data, _edata, _ebss, _stack;
extern unsigned _etext_ram, _text_ram, _etext_rom;
+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);
@@ -165,6 +169,7 @@ void (*const vector_table[]) (void) = {
void reset_handler(void)
{
volatile unsigned *src, *dest;
+ funcp_t *fp;
__asm__("MSR msp, %0" : : "r"(&_stack));
@@ -192,8 +197,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)