annotate src/link.c @ 306:be1abc4ac114

Corrected errors with parsing script and object files
author lost
date Fri, 23 Jan 2009 04:03:37 +0000
parents 13272197d278
children ecc092adc0be
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
301
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
1 /*
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
2 link.c
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
3 Copyright © 2009 William Astle
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
4
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
5 This file is part of LWLINK.
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
6
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
7 LWLINK is free software: you can redistribute it and/or modify it under the
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
10 version.
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
11
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
15 more details.
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
16
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
17 You should have received a copy of the GNU General Public License along with
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
19
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
20
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
21 Resolve section and symbol addresses; handle incomplete references
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
22 */
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
23
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
24 #ifdef HAVE_CONFIG_H
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
25 #include "config.h"
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
26 #endif
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
27
302
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
28 #include <stdio.h>
301
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
29 #include <stdlib.h>
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
30
302
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
31 #include "expr.h"
301
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
32 #include "lwlink.h"
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
33 #include "util.h"
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
34
303
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
35 struct section_list *sectlist = NULL;
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
36 int nsects = 0;
301
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
37
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
38 // work out section load order and resolve base addresses for each section
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
39 // make a list of sections to load in order
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
40 void resolve_sections(void)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
41 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
42 int laddr = 0;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
43 int ln, sn, fn;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
44
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
45 for (ln = 0; ln < linkscript.nlines; ln++)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
46 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
47 if (linkscript.lines[ln].sectname)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
48 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
49 int f = 0;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
50 // named section
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
51 // look for all instances of a section by the specified name
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
52 // and resolve base addresses and add to the list
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
53 for (fn = 0; fn < ninputfiles; fn++)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
54 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
55 for (sn = 0; sn < inputfiles[fn] -> nsections; sn++)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
56 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
57 if (!strcmp(linkscript.lines[ln].sectname, inputfiles[fn] -> sections[sn].name))
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
58 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
59 // we have a match
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
60 sectlist = lw_realloc(sectlist, sizeof(struct section_list) * (nsects + 1));
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
61 sectlist[nsects].ptr = &(inputfiles[fn] -> sections[sn]);
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
62
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
63 inputfiles[fn] -> sections[sn].processed = 1;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
64 if (!f && linkscript.lines[ln].loadat >= 0)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
65 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
66 f = 1;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
67 sectlist[nsects].forceaddr = 1;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
68 laddr = linkscript.lines[ln].loadat;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
69 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
70 else
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
71 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
72 sectlist[nsects].forceaddr = 0;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
73 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
74 inputfiles[fn] -> sections[sn].loadaddress = laddr;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
75 nsects++;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
76 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
77 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
78 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
79 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
80 else
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
81 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
82 // wildcard section
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
83 // look for all sections not yet processed that match flags
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
84
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
85 int f = 0;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
86 int fn0, sn0;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
87 char *sname;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
88
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
89 // named section
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
90 // look for all instances of a section by the specified name
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
91 // and resolve base addresses and add to the list
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
92 for (fn0 = 0; fn0 < ninputfiles; fn0++)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
93 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
94 for (sn0 = 0; sn0 < inputfiles[fn0] -> nsections; sn0++)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
95 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
96 // ignore if the "no flags" bit says to
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
97 if (linkscript.lines[ln].noflags && (inputfiles[fn0] -> sections[sn0].flags & linkscript.lines[ln].noflags))
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
98 continue;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
99 // ignore unless the yes flags tell us not to
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
100 if (linkscript.lines[ln].yesflags && (inputfiles[fn0] -> sections[sn0].flags & linkscript.lines[ln].yesflags == 0))
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
101 continue;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
102 if (inputfiles[fn0] -> sections[sn0].processed == 0)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
103 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
104 sname = inputfiles[fn0] -> sections[sn0].name;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
105 for (fn = 0; fn < ninputfiles; fn++)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
106 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
107 for (sn = 0; sn < inputfiles[fn] -> nsections; sn++)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
108 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
109 if (!strcmp(sname, inputfiles[fn] -> sections[sn].name))
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
110 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
111 // we have a match
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
112 sectlist = lw_realloc(sectlist, sizeof(struct section_list) * (nsects + 1));
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
113 sectlist[nsects].ptr = &(inputfiles[fn] -> sections[sn]);
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
114
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
115 inputfiles[fn] -> sections[sn].processed = 1;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
116 if (!f && linkscript.lines[ln].loadat >= 0)
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
117 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
118 f = 1;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
119 sectlist[nsects].forceaddr = 1;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
120 laddr = linkscript.lines[ln].loadat;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
121 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
122 else
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
123 {
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
124 sectlist[nsects].forceaddr = 0;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
125 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
126 inputfiles[fn] -> sections[sn].loadaddress = laddr;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
127 nsects++;
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
128 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
129 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
130 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
131 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
132 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
133 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
134 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
135 }
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
136
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
137 // theoretically, all the base addresses are set now
376cc55361c7 section order and address resolution done
lost
parents:
diff changeset
138 }
302
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
139
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
140 // resolve all incomplete references now
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
141 // anything that is unresolvable at this stage will throw an error
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
142 // because we know the load address of every section now
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
143 lw_expr_stack_t *resolve_sym(char *sym, int symtype, void *state)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
144 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
145 section_t *sect = state;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
146 lw_expr_term_t *term;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
147 int val = 0, i, fn;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
148 lw_expr_stack_t *s;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
149 symtab_t *se;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
150
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
151 if (symtype == 1)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
152 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
153 // local symbol
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
154 if (!sym)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
155 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
156 val = sect -> loadaddress;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
157 goto out;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
158 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
159
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
160 // start with this section
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
161 for (se = sect -> localsyms; se; se = se -> next)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
162 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
163 if (!strcmp(se -> sym, sym))
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
164 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
165 val = se -> offset + sect -> loadaddress;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
166 goto out;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
167 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
168 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
169 // not in this section - check all sections in this file
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
170 for (i = 0; i < sect -> file -> nsections; i++)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
171 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
172 for (se = sect -> file -> sections[i].localsyms; se; se = se -> next)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
173 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
174 if (!strcmp(se -> sym, sym))
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
175 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
176 val = se -> offset + sect -> file -> sections[i].loadaddress;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
177 goto out;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
178 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
179 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
180 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
181 // not found
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
182 fprintf(stderr, "Local symbol %s not found in %s:%s\n", sym, sect -> file -> filename, sect -> name);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
183 exit(1);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
184 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
185 else
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
186 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
187 // external symbol
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
188 // read all files in order until found (or not found)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
189 for (fn = 0; fn < ninputfiles; fn++)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
190 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
191 for (i = 0; i < inputfiles[fn] -> nsections; i++)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
192 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
193 for (se = inputfiles[fn] -> sections[i].exportedsyms; se; se = se -> next)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
194 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
195 if (!strcmp(sym, se -> sym))
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
196 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
197 val = se -> offset + inputfiles[fn] -> sections[i].loadaddress;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
198 goto out;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
199 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
200 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
201 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
202 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
203 fprintf(stderr, "External symbol %s not found in %s:%s\n", sym, sect -> file -> filename, sect -> name);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
204 exit(1);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
205 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
206 fprintf(stderr, "Shouldn't ever get here!!!\n");
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
207 exit(88);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
208 out:
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
209 s = lw_expr_stack_create();
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
210 term = lw_expr_term_create_int(val & 0xffff);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
211 lw_expr_stack_push(s, term);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
212 lw_expr_term_free(term);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
213 return s;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
214 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
215
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
216 void resolve_references(void)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
217 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
218 int sn;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
219 reloc_t *rl;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
220 int rval;
303
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
221
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
222 // resolve entry point if required
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
223 // this must resolve to an *exported* symbol and will resolve to the
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
224 // first instance of that symbol
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
225 if (linkscript.execsym)
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
226 {
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
227 lw_expr_stack_t *s;
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
228
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
229 s = resolve_sym(linkscript.execsym, 0, NULL);
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
230 linkscript.execaddr = lw_expr_get_value(s);
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
231 lw_expr_stack_free(s);
13272197d278 Added simplistic output module for DECB target
lost
parents: 302
diff changeset
232 }
302
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
233
306
be1abc4ac114 Corrected errors with parsing script and object files
lost
parents: 303
diff changeset
234 for (sn = 0; sn < nsects; sn++)
302
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
235 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
236 for (rl = sectlist[sn].ptr -> incompletes; rl; rl = rl -> next)
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
237 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
238 // do a "simplify" on the expression
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
239 rval = lw_expr_reval(rl -> expr, resolve_sym, sectlist[sn].ptr);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
240
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
241 // is it constant? error out if not
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
242 if (rval != 0 || !lw_expr_is_constant(rl -> expr))
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
243 {
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
244 fprintf(stderr, "Incomplete reference at %s:%s:%02X\n", sectlist[sn].ptr -> file -> filename, sectlist[sn].ptr -> name, rl -> offset);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
245 exit(1);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
246 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
247
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
248 // put the value into the relocation address
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
249 rval = lw_expr_get_value(rl -> expr);
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
250 sectlist[sn].ptr -> code[rl -> offset] = (rval >> 8) & 0xff;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
251 sectlist[sn].ptr -> code[rl -> offset + 1] = rval & 0xff;
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
252 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
253 }
eff969272fb9 resolve incomplete references done
lost
parents: 301
diff changeset
254 }