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