1 | #! /bin/sh
|
---|
2 |
|
---|
3 | #
|
---|
4 | # Copyright (C) 2006 Martin Decky
|
---|
5 | # All rights reserved.
|
---|
6 | #
|
---|
7 | # Redistribution and use in source and binary forms, with or without
|
---|
8 | # modification, are permitted provided that the following conditions
|
---|
9 | # are met:
|
---|
10 | #
|
---|
11 | # - Redistributions of source code must retain the above copyright
|
---|
12 | # notice, this list of conditions and the following disclaimer.
|
---|
13 | # - Redistributions in binary form must reproduce the above copyright
|
---|
14 | # notice, this list of conditions and the following disclaimer in the
|
---|
15 | # documentation and/or other materials provided with the distribution.
|
---|
16 | # - The name of the author may not be used to endorse or promote products
|
---|
17 | # derived from this software without specific prior written permission.
|
---|
18 | #
|
---|
19 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
20 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
21 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
22 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
23 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
24 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
25 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
26 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
27 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
28 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
29 | #
|
---|
30 |
|
---|
31 | [ "$#" -lt 1 ] && exit 1
|
---|
32 |
|
---|
33 | OBJCOPY="$1"
|
---|
34 | LINK="_link.ld"
|
---|
35 | HEADER="_components.h"
|
---|
36 |
|
---|
37 | shift
|
---|
38 | echo 'OUTPUT_FORMAT("elf64-ia64-little")
|
---|
39 | ENTRY(start)
|
---|
40 |
|
---|
41 | SECTIONS {
|
---|
42 | .boot 0x4400000: AT (0x4400000) {
|
---|
43 | *(BOOTSTRAP);
|
---|
44 |
|
---|
45 | . = ALIGN (0x4000);
|
---|
46 |
|
---|
47 | ' > "$LINK"
|
---|
48 |
|
---|
49 | echo '#ifndef ___COMPONENTS_H__
|
---|
50 | #define ___COMPONENTS_H__
|
---|
51 |
|
---|
52 | typedef struct {
|
---|
53 | char *name;
|
---|
54 |
|
---|
55 | void *start;
|
---|
56 | void *end;
|
---|
57 | unsigned int size;
|
---|
58 | } component_t;' > "$HEADER"
|
---|
59 |
|
---|
60 |
|
---|
61 | COUNT="0"
|
---|
62 | DATA=""
|
---|
63 |
|
---|
64 | for TASK in "$@" ; do
|
---|
65 | BASENAME="`basename "$TASK" | sed 's/^\(.*\)\.[^.]*$/\1/'`"
|
---|
66 | OBJECT="${BASENAME}.o"
|
---|
67 | SYMBOL="`echo "_binary_$TASK" | tr "./" "__"`"
|
---|
68 | MACRO="`echo "$BASENAME" | tr [:lower:] [:upper:]`"
|
---|
69 | echo "$TASK -> $OBJECT"
|
---|
70 |
|
---|
71 | echo "
|
---|
72 | *(.${BASENAME}_image);
|
---|
73 | . = ALIGN (0x4000);" >> "$LINK"
|
---|
74 | echo "
|
---|
75 | extern int ${SYMBOL}_start;
|
---|
76 | extern int ${SYMBOL}_end;
|
---|
77 |
|
---|
78 | #define ${MACRO}_START ((void *) &${SYMBOL}_start)
|
---|
79 | #define ${MACRO}_END ((void *) &${SYMBOL}_end)
|
---|
80 | #define ${MACRO}_SIZE ((unsigned long) ${MACRO}_END - (unsigned long) ${MACRO}_START)" >> "$HEADER"
|
---|
81 |
|
---|
82 | "$OBJCOPY" -I binary -O elf64-ia64-little -B ia64 --rename-section ".data=.${BASENAME}_image" "$TASK" "$OBJECT"
|
---|
83 |
|
---|
84 | DATA="${DATA}
|
---|
85 | components[$COUNT].name = \"${BASENAME}\";
|
---|
86 | components[$COUNT].start = ${MACRO}_START;
|
---|
87 | components[$COUNT].end = ${MACRO}_END;
|
---|
88 | components[$COUNT].size = ${MACRO}_SIZE;";
|
---|
89 | COUNT="`expr "$COUNT" + 1`"
|
---|
90 | done
|
---|
91 |
|
---|
92 | echo '
|
---|
93 | *(.text);
|
---|
94 | *(.rodata);
|
---|
95 | *(.rodata.*);
|
---|
96 | *(.data); /* initialized data */
|
---|
97 | _got = . ;
|
---|
98 | *(.got .got.*);
|
---|
99 | *(.sdata);
|
---|
100 | *(.sdata2);
|
---|
101 | *(.sbss);
|
---|
102 | *(.bss); /* uninitialized static variables */
|
---|
103 | *(COMMON);' >> "$LINK"
|
---|
104 |
|
---|
105 | echo ' }
|
---|
106 | /DISCARD/ : {
|
---|
107 | *(.comment);
|
---|
108 | *(.note*);
|
---|
109 | }
|
---|
110 | }' >> "$LINK"
|
---|
111 |
|
---|
112 | echo "
|
---|
113 | #define COMPONENTS $COUNT
|
---|
114 |
|
---|
115 | static void init_components(component_t components[])
|
---|
116 | {
|
---|
117 | $DATA
|
---|
118 | }
|
---|
119 |
|
---|
120 | #endif
|
---|
121 | " >> "$HEADER"
|
---|