annotate old-trunk/lwlink/script.c @ 339:eb230fa7d28e

Prepare for migration to hg
author lost
date Fri, 19 Mar 2010 02:54:14 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1 /*
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
2 script.c
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
3 Copyright © 2009 William Astle
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
4
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
5 This file is part of LWLINK.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
6
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
7 LWLINK is free software: you can redistribute it and/or modify it under the
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
10 version.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
11
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
15 more details.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
16
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
17 You should have received a copy of the GNU General Public License along with
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
19
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
20
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
21 Read and parse linker scripts
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
22 */
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
23
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
24 #include <config.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
25
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
26 #include <errno.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
27 #include <stdio.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
28 #include <stdlib.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
29 #include <string.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
30
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
31 #include "lwlink.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
32 #include "util.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
33
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
34 // the built-in DECB target linker script
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
35 static char *decb_script =
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
36 "section init load 2000\n"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
37 "section code\n"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
38 "section *,!bss\n"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
39 "section *,bss\n"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
40 "entry 2000\n"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
41 ;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
42
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
43 // the built-in RAW target linker script
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
44 static char *raw_script =
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
45 "section init load 0000\n"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
46 "section code\n"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
47 "section *,!bss\n"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
48 "section *,bss\n"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
49 ;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
50
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
51 static char *lwex0_script =
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
52 "section init load 0100\n"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
53 "section .text\n"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
54 "section .data\n"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
55 "section *,!bss\n"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
56 "section *,bss\n"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
57 "entry __start\n"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
58 "stacksize 0100\n" // default 256 byte stack
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
59 ;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
60
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
61 // the "simple" script
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
62 static char *simple_script =
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
63 "section *,!bss\n"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
64 "section *,bss\n"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
65 ;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
66
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
67 linkscript_t linkscript = { 0, NULL, -1 };
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
68
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
69 void setup_script()
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
70 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
71 char *script, *oscript;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
72 long size;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
73
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
74 // read the file if needed
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
75 if (scriptfile)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
76 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
77 FILE *f;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
78 long bread;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
79
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
80 f = fopen(scriptfile, "rb");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
81 if (!f)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
82 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
83 fprintf(stderr, "Can't open file %s:", scriptfile);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
84 perror("");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
85 exit(1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
86 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
87 fseek(f, 0, SEEK_END);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
88 size = ftell(f);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
89 rewind(f);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
90
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
91 script = lw_malloc(size + 2);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
92
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
93 bread = fread(script, 1, size, f);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
94 if (bread < size)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
95 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
96 fprintf(stderr, "Short read on file %s (%ld/%ld):", scriptfile, bread, size);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
97 perror("");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
98 exit(1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
99 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
100 fclose(f);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
101
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
102 script[size] = '\n';
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
103 script[size + 1] = '\0';
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
104 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
105 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
106 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
107 // fetch defaults based on output mode
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
108 switch (outformat)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
109 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
110 case OUTPUT_RAW:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
111 script = raw_script;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
112 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
113
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
114 case OUTPUT_DECB:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
115 script = decb_script;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
116 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
117
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
118 case OUTPUT_LWEX0:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
119 script = lwex0_script;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
120 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
121
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
122 default:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
123 script = simple_script;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
124 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
125 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
126
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
127 size = strlen(script);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
128 if (nscriptls)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
129 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
130 char *rscript;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
131 int i;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
132 // prepend the "extra" script lines
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
133 for (i = 0; i < nscriptls; i++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
134 size += strlen(scriptls[i]) + 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
135
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
136 rscript = lw_malloc(size + 1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
137 oscript = rscript;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
138 for (i = 0; i < nscriptls; i++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
139 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
140 oscript += sprintf(oscript, "%s\n", scriptls[i]);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
141 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
142 strcpy(oscript, script);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
143 script = rscript;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
144 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
145 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
146
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
147 if (outformat == OUTPUT_LWEX0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
148 linkscript.stacksize = 0x100;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
149
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
150 oscript = script;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
151 // now parse the script file
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
152 while (*script)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
153 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
154 char *ptr, *ptr2, *line;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
155
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
156 for (ptr = script; *ptr && *ptr != '\n' && *ptr != '\r'; ptr++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
157 /* do nothing */ ;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
158
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
159 line = lw_malloc(ptr - script + 1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
160 memcpy(line, script, ptr - script);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
161 line[ptr - script] = '\0';
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
162
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
163 // skip line terms
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
164 for (script = ptr + 1; *script == '\n' || *script == '\r'; script++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
165 /* do nothing */ ;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
166
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
167 // ignore leading whitespace
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
168 for (ptr = line; *ptr && isspace(*ptr); ptr++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
169 /* do nothing */ ;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
170
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
171 // ignore blank lines
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
172 if (!*ptr)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
173 continue;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
174
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
175 for (ptr = line; *ptr && !isspace(*ptr); ptr++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
176 /* do nothing */ ;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
177
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
178 // now ptr points to the char past the first word
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
179 // NUL it out
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
180 if (*ptr)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
181 *ptr++ = '\0';
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
182
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
183 // skip spaces after the first word
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
184 for ( ; *ptr && isspace(*ptr); ptr++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
185 /* do nothing */ ;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
186
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
187 if (!strcmp(line, "pad"))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
188 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
189 // padding
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
190 // parse the hex number and stow it
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
191 linkscript.padsize = strtol(ptr, NULL, 16);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
192 if (linkscript.padsize < 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
193 linkscript.padsize = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
194 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
195 else if (!strcmp(line, "stacksize"))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
196 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
197 // stack size for targets that support it
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
198 // parse the hex number and stow it
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
199 linkscript.padsize = strtol(ptr, NULL, 16);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
200 if (linkscript.stacksize < 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
201 linkscript.stacksize = 0x100;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
202 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
203 else if (!strcmp(line, "entry"))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
204 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
205 int eaddr;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
206
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
207 eaddr = strtol(ptr, &ptr2, 16);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
208 if (*ptr2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
209 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
210 linkscript.execaddr = -1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
211 linkscript.execsym = lw_strdup(ptr);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
212 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
213 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
214 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
215 linkscript.execaddr = eaddr;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
216 linkscript.execsym = NULL;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
217 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
218 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
219 else if (!strcmp(line, "section"))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
220 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
221 // section
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
222 // parse out the section name and flags
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
223 for (ptr2 = ptr; *ptr2 && !isspace(*ptr2); ptr2++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
224 /* do nothing */ ;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
225
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
226 if (*ptr2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
227 *ptr2++ = '\0';
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
228
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
229 while (*ptr2 && isspace(*ptr2))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
230 ptr2++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
231
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
232 // ptr now points to the section name and flags and ptr2
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
233 // to the first non-space character following
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
234
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
235 // then look for "load <addr>" clause
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
236 if (*ptr2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
237 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
238 if (!strncmp(ptr2, "load", 4))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
239 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
240 ptr2 += 4;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
241 while (*ptr2 && isspace(*ptr2))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
242 ptr2++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
243
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
244 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
245 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
246 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
247 fprintf(stderr, "%s: bad script\n", scriptfile);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
248 exit(1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
249 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
250 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
251
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
252 // now ptr2 points to the load address if there is one
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
253 // or NUL if not
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
254 linkscript.lines = lw_realloc(linkscript.lines, sizeof(struct scriptline_s) * (linkscript.nlines + 1));
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
255
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
256 linkscript.lines[linkscript.nlines].noflags = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
257 linkscript.lines[linkscript.nlines].yesflags = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
258 if (*ptr2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
259 linkscript.lines[linkscript.nlines].loadat = strtol(ptr2, NULL, 16);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
260 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
261 linkscript.lines[linkscript.nlines].loadat = -1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
262 for (ptr2 = ptr; *ptr2 && *ptr2 != ','; ptr2++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
263 /* do nothing */ ;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
264 if (*ptr2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
265 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
266 *ptr2++ = '\0';
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
267 if (!strcmp(ptr2, "!bss"))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
268 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
269 linkscript.lines[linkscript.nlines].noflags = SECTION_BSS;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
270 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
271 else if (!strcmp(ptr2, "bss"))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
272 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
273 linkscript.lines[linkscript.nlines].yesflags = SECTION_BSS;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
274 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
275 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
276 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
277 fprintf(stderr, "%s: bad script\n", scriptfile);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
278 exit(1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
279 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
280 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
281 if (ptr[0] == '*' && ptr[1] == '\0')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
282 linkscript.lines[linkscript.nlines].sectname = NULL;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
283 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
284 linkscript.lines[linkscript.nlines].sectname = lw_strdup(ptr);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
285 linkscript.nlines++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
286 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
287 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
288 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
289 fprintf(stderr, "%s: bad script\n", scriptfile);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
290 exit(1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
291 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
292 lw_free(line);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
293 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
294
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
295 if (scriptfile || nscriptls)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
296 lw_free(oscript);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
297 }