summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--entry.cpp16
1 files changed, 16 insertions, 0 deletions
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);