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