From 7419d6559f22ec7c364e7bdedd5e179d34f79775 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 24 Jun 2010 11:46:47 +0200 Subject: [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. --- src/target/firmware/lib/Makefile | 2 +- src/target/firmware/lib/ctors.c | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/target/firmware/lib/ctors.c (limited to 'src/target/firmware/lib') 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)(); +} -- cgit v1.2.3