Rev 1771 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1771 | Rev 1773 | ||
---|---|---|---|
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 | 38 | ||
39 | echo 'OUTPUT_FORMAT("elf64-sparc") |
39 | echo 'OUTPUT_FORMAT("elf64-sparc") |
40 | ENTRY(start) |
40 | ENTRY(start) |
41 | 41 | ||
42 | SECTIONS { |
42 | SECTIONS { |
43 | .boot 0x4000: AT (0) { |
43 | .boot 0x4000: AT (0x4000) { |
44 | *(BOOTSTRAP); |
44 | *(BOOTSTRAP); |
45 | *(.text); |
45 | *(.text); |
46 | *(.rodata); |
46 | *(.rodata); |
47 | *(.rodata.*); |
47 | *(.rodata.*); |
48 | *(.data); /* initialized data */ |
48 | *(.data); /* initialized data */ |
49 | *(.sdata); |
49 | *(.sdata); |
50 | *(.sdata2); |
50 | *(.sdata2); |
51 | *(.sbss); |
51 | *(.sbss); |
52 | *(.bss); /* uninitialized static variables */ |
52 | *(.bss); /* uninitialized static variables */ |
53 | *(COMMON);' > "$LINK" |
53 | *(COMMON);' > "$LINK" |
54 | 54 | ||
55 | echo '#ifndef ___COMPONENTS_H__ |
55 | echo '#ifndef ___COMPONENTS_H__ |
56 | #define ___COMPONENTS_H__ |
56 | #define ___COMPONENTS_H__ |
57 | 57 | ||
58 | typedef struct { |
58 | typedef struct { |
59 | char *name; |
59 | char *name; |
60 | 60 | ||
61 | void *start; |
61 | void *start; |
62 | void *end; |
62 | void *end; |
63 | unsigned int size; |
63 | unsigned int size; |
64 | } component_t;' > "$HEADER" |
64 | } component_t;' > "$HEADER" |
65 | 65 | ||
66 | COUNT="0" |
66 | COUNT="0" |
67 | DATA="" |
67 | DATA="" |
68 | 68 | ||
69 | for TASK in "$@" ; do |
69 | for TASK in "$@" ; do |
70 | BASENAME="`basename "$TASK" | sed 's/^\(.*\)\.[^.]*$/\1/'`" |
70 | BASENAME="`basename "$TASK" | sed 's/^\(.*\)\.[^.]*$/\1/'`" |
71 | OBJECT="${BASENAME}.o" |
71 | OBJECT="${BASENAME}.o" |
72 | SYMBOL="`echo "_binary_$TASK" | tr "./" "__"`" |
72 | SYMBOL="`echo "_binary_$TASK" | tr "./" "__"`" |
73 | MACRO="`echo "$BASENAME" | tr [:lower:] [:upper:]`" |
73 | MACRO="`echo "$BASENAME" | tr [:lower:] [:upper:]`" |
74 | echo "$TASK -> $OBJECT" |
74 | echo "$TASK -> $OBJECT" |
75 | 75 | ||
76 | echo " |
76 | echo " |
77 | . = ALIGN(8192); |
- | |
78 | *(.${BASENAME}_image);" >> "$LINK" |
77 | *(.${BASENAME}_image);" >> "$LINK" |
79 | 78 | ||
80 | echo " |
79 | echo " |
81 | extern int ${SYMBOL}_start; |
80 | extern int ${SYMBOL}_start; |
82 | extern int ${SYMBOL}_end; |
81 | extern int ${SYMBOL}_end; |
83 | 82 | ||
84 | #define ${MACRO}_START ((void *) &${SYMBOL}_start) |
83 | #define ${MACRO}_START ((void *) &${SYMBOL}_start) |
85 | #define ${MACRO}_END ((void *) &${SYMBOL}_end) |
84 | #define ${MACRO}_END ((void *) &${SYMBOL}_end) |
86 | #define ${MACRO}_SIZE ((unsigned int) ${MACRO}_END - (unsigned int) ${MACRO}_START)" >> "$HEADER" |
85 | #define ${MACRO}_SIZE ((unsigned int) ${MACRO}_END - (unsigned int) ${MACRO}_START)" >> "$HEADER" |
87 | 86 | ||
88 | "$OBJCOPY" -I binary -O elf64-sparc -B sparc --rename-section ".data=.${BASENAME}_image" "$TASK" "$OBJECT" |
87 | "$OBJCOPY" -I binary -O elf64-sparc -B sparc --rename-section ".data=.${BASENAME}_image" "$TASK" "$OBJECT" |
89 | 88 | ||
90 | DATA="${DATA} |
89 | DATA="${DATA} |
91 | components[$COUNT].name = \"${BASENAME}\"; |
90 | components[$COUNT].name = \"${BASENAME}\"; |
92 | components[$COUNT].start = ${MACRO}_START; |
91 | components[$COUNT].start = ${MACRO}_START; |
93 | components[$COUNT].end = ${MACRO}_END; |
92 | components[$COUNT].end = ${MACRO}_END; |
94 | components[$COUNT].size = ${MACRO}_SIZE;"; |
93 | components[$COUNT].size = ${MACRO}_SIZE;"; |
95 | COUNT="`expr "$COUNT" + 1`" |
94 | COUNT="`expr "$COUNT" + 1`" |
96 | done |
95 | done |
97 | 96 | ||
98 | echo ' } |
97 | echo ' } |
- | 98 | /DISCARD/ : { |
|
- | 99 | *(.comment); |
|
- | 100 | *(.note*); |
|
- | 101 | } |
|
99 | }' >> "$LINK" |
102 | }' >> "$LINK" |
100 | 103 | ||
101 | echo " |
104 | echo " |
102 | #define COMPONENTS $COUNT |
105 | #define COMPONENTS $COUNT |
103 | 106 | ||
104 | static void init_components(component_t components[]) |
107 | static void init_components(component_t components[]) |
105 | { |
108 | { |
106 | $DATA |
109 | $DATA |
107 | } |
110 | } |
108 | 111 | ||
109 | #endif |
112 | #endif |
110 | " >> "$HEADER" |
113 | " >> "$HEADER" |
111 | 114 |