summaryrefslogtreecommitdiffstats
path: root/src/target/firmware/board/common
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/board/common
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/board/common')
-rw-r--r--src/target/firmware/board/common/compal_osmoload.lds13
-rw-r--r--src/target/firmware/board/common/compal_ramload.lds13
-rw-r--r--src/target/firmware/board/common/compal_ramload_start.S7
3 files changed, 33 insertions, 0 deletions
diff --git a/src/target/firmware/board/common/compal_osmoload.lds b/src/target/firmware/board/common/compal_osmoload.lds
index d2d96d3a..6f6a9679 100644
--- a/src/target/firmware/board/common/compal_osmoload.lds
+++ b/src/target/firmware/board/common/compal_osmoload.lds
@@ -27,6 +27,19 @@ SECTIONS
KEEP(*(.text.exceptions))
* (.text.exceptions)
. = ALIGN(4);
+
+ /* constructors and destructors */
+ . = ALIGN(4);
+ __CTOR_LIST__ = .;
+ LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
+ *(SORT(.ctors))
+ LONG(0) /* end of list */
+ __CTOR_END__ = .;
+ __DTOR_LIST__ = .;
+ LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)
+ *(SORT(.dtors))
+ LONG(0) /* end of list */
+ __DTOR_END__ = .;
} > LRAM
PROVIDE(_exceptions = LOADADDR(.text.exceptions));
diff --git a/src/target/firmware/board/common/compal_ramload.lds b/src/target/firmware/board/common/compal_ramload.lds
index 65a1baa7..1ea782ed 100644
--- a/src/target/firmware/board/common/compal_ramload.lds
+++ b/src/target/firmware/board/common/compal_ramload.lds
@@ -43,6 +43,19 @@ SECTIONS
/* gcc voodoo */
*(.glue_7t) *(.glue_7) *(.vfp11_veneer) *(.v4_bx)
. = ALIGN(4);
+
+ /* constructors and destructors */
+ . = ALIGN(4);
+ __CTOR_LIST__ = .;
+ LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
+ *(SORT(.ctors))
+ LONG(0) /* end of list */
+ __CTOR_END__ = .;
+ __DTOR_LIST__ = .;
+ LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)
+ *(SORT(.dtors))
+ LONG(0) /* end of list */
+ __DTOR_END__ = .;
} > LRAM
PROVIDE(_text_start = LOADADDR(.text));
PROVIDE(_text_end = LOADADDR(.text) + SIZEOF(.text));
diff --git a/src/target/firmware/board/common/compal_ramload_start.S b/src/target/firmware/board/common/compal_ramload_start.S
index 8c5d2cc6..c89c881c 100644
--- a/src/target/firmware/board/common/compal_ramload_start.S
+++ b/src/target/firmware/board/common/compal_ramload_start.S
@@ -56,6 +56,11 @@ _start:
@ldr r0, =0xfffffe00
@bl memdump
+ /* call constructor functions */
+ ldr r0, _ctor_list
+ ldr r1, _ctor_end
+ bl do_global_ctors
+
/* jump to main */
ldr pc, _jump_main
@@ -64,6 +69,8 @@ _end: b _end
b _start
_jump_main: .word main
+_ctor_list: .word __CTOR_LIST__
+_ctor_end: .word __CTOR_END__
/* handler for all kinds of aborts */
handle_abort: