summaryrefslogtreecommitdiffstats
path: root/src/target/firmware/lib
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2010-06-24 11:46:47 +0200
committerHarald Welte <laforge@gnumonks.org>2010-06-24 11:46:47 +0200
commit7419d6559f22ec7c364e7bdedd5e179d34f79775 (patch)
treec72ce4245b22e65e484fde4a4b391f5317996812 /src/target/firmware/lib
parent15c584ef625111ae25cf733a9b5715f9e3e6ed26 (diff)
[firmware] Add support for __attribute__ ((constructor))
We modify the linker scripts to include the .ctors and .dtors sections and add some code to actually call them before we jump to the main() function.
Diffstat (limited to 'src/target/firmware/lib')
-rw-r--r--src/target/firmware/lib/Makefile2
-rw-r--r--src/target/firmware/lib/ctors.c11
2 files changed, 12 insertions, 1 deletions
diff --git a/src/target/firmware/lib/Makefile b/src/target/firmware/lib/Makefile
index 85427439..987857c9 100644
--- a/src/target/firmware/lib/Makefile
+++ b/src/target/firmware/lib/Makefile
@@ -1,7 +1,7 @@
LIBRARIES+=mini
mini_DIR=lib
-mini_SRCS=vsprintf.c string.c ctype.c printf.c console.c \
+mini_SRCS=vsprintf.c string.c ctype.c printf.c console.c ctors.c \
changebit.S clearbit.S div64.S lib1funcs.S memcpy.S memset.S setbit.S testchangebit.S testclearbit.S testsetbit.S
diff --git a/src/target/firmware/lib/ctors.c b/src/target/firmware/lib/ctors.c
new file mode 100644
index 00000000..6136a884
--- /dev/null
+++ b/src/target/firmware/lib/ctors.c
@@ -0,0 +1,11 @@
+
+/* iterate over list of constructor functions and call each element */
+void do_global_ctors(const char *ctors_start, const char *ctors_end)
+{
+ typedef void (*func_ptr)(void);
+ func_ptr *func;
+
+ for (func = (func_ptr *) ctors_start;
+ *func && (func != (func_ptr *) ctors_end); func++)
+ (*func)();
+}