From 28284d92087d8915f0032a6edb76a622d9d07966 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sat, 3 Sep 2011 15:25:23 +0200 Subject: Call constructors and destructors. --- entry.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/entry.cpp b/entry.cpp index 4faca0e..e819c78 100644 --- a/entry.cpp +++ b/entry.cpp @@ -3,12 +3,18 @@ int main(); +typedef void (*funcp_t)(); + // Symbols from linker script. extern uint32_t _data_rom; extern uint32_t _data_start; extern uint32_t _data_end; extern uint32_t _bss_start; extern uint32_t _bss_end; +extern funcp_t _init_array_start; +extern funcp_t _init_array_end; +extern funcp_t _fini_array_start; +extern funcp_t _fini_array_end; void __attribute__((naked)) entry() { // Initialize clock. @@ -30,11 +36,21 @@ void __attribute__((naked)) entry() { } // Call constructors. + funcp_t* fp = &_init_array_start; + + while(fp < &_init_array_end) { + (*fp++)(); + } // Call main(). main(); // Call destructors. + fp = &_fini_array_start; + + while(fp < &_fini_array_end) { + (*fp++)(); + } // Halt. while(1); -- cgit v1.2.3