1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27: #include "sysdep.h"
28: #include "bfd.h"
29: #include "ld.h"
30: #include "ldexp.h"
31: #include "ldlang.h"
32: #include "ldmisc.h"
33: #include "mri.h"
34: #include <ldgram.h>
35: #include "libiberty.h"
36:
37: struct section_name_struct {
38: struct section_name_struct *next;
39: const char *name;
40: const char *alias;
41: etree_type *vma;
42: etree_type *align;
43: etree_type *subalign;
44: int ok_to_load;
45: };
46:
47: static unsigned int symbol_truncate = 10000;
48: static struct section_name_struct *order;
49: static struct section_name_struct *only_load;
50: static struct section_name_struct *address;
51: static struct section_name_struct *alias;
52:
53: static struct section_name_struct *alignment;
54: static struct section_name_struct *subalignment;
55:
56: static struct section_name_struct **
57: lookup (const char *name, struct section_name_struct **list)
58: {
59: struct section_name_struct **ptr = list;
60:
61: while (*ptr)
62: {
63: if (strcmp (name, (*ptr)->name) == 0)
64:
65:
66: *ptr = (*ptr)->next;
67: else
68: ptr = &((*ptr)->next);
69: }
70:
71: *ptr = xmalloc (sizeof (struct section_name_struct));
72: return ptr;
73: }
74:
75: static void
76: mri_add_to_list (struct section_name_struct **list,
77: const char *name,
78: etree_type *vma,
79: const char *zalias,
80: etree_type *align,
81: etree_type *subalign)
82: {
83: struct section_name_struct **ptr = lookup (name, list);
84:
85: (*ptr)->name = name;
86: (*ptr)->vma = vma;
87: (*ptr)->next = NULL;
88: (*ptr)->ok_to_load = 0;
89: (*ptr)->alias = zalias;
90: (*ptr)->align = align;
91: (*ptr)->subalign = subalign;
92: }
93:
94: void
95: mri_output_section (const char *name, etree_type *vma)
96: {
97: mri_add_to_list (&address, name, vma, 0, 0, 0);
98: }
99:
100:
101:
102:
103: void
104: mri_only_load (const char *name)
105: {
106: mri_add_to_list (&only_load, name, 0, 0, 0, 0);
107: }
108:
109: void
110: mri_base (etree_type *exp)
111: {
112: base = exp;
113: }
114:
115: static int done_tree = 0;
116:
117: void
118: mri_draw_tree (void)
119: {
120: if (done_tree)
121: return;
122:
123:
124:
125:
126:
127: if (address != NULL)
128: {
129: struct section_name_struct *alist;
130: struct section_name_struct *olist;
131:
132: if (order == NULL)
133: order = address;
134:
135: for (alist = address;
136: alist != NULL;
137: alist = alist->next)
138: {
139: int done = 0;
140:
141: for (olist = order; done == 0 && olist != NULL; olist = olist->next)
142: {
143: if (strcmp (alist->name, olist->name) == 0)
144: {
145: olist->vma = alist->vma;
146: done = 1;
147: }
148: }
149:
150: if (!done)
151: {
152:
153: mri_add_to_list (&order, alist->name, alist->vma, 0, 0, 0);
154: }
155: }
156: }
157:
158:
159:
160: if (only_load != NULL)
161: {
162: struct section_name_struct *ptr1;
163: struct section_name_struct *ptr2;
164:
165: if (order == NULL)
166: order = only_load;
167:
168:
169: for (ptr1 = only_load; ptr1; ptr1 = ptr1->next)
170: for (ptr2 = order; ptr2; ptr2 = ptr2->next)
171: if (strcmp (ptr2->name, ptr1->name) == 0)
172: ptr2->ok_to_load = 1;
173: }
174: else
175: {
176:
177: struct section_name_struct *ptr;
178:
179: for (ptr = order; ptr; ptr = ptr->next)
180: ptr->ok_to_load = 1;
181: }
182:
183:
184: if (order != NULL)
185: {
186:
187: struct section_name_struct *p = order;
188:
189: while (p)
190: {
191: struct section_name_struct *aptr;
192: etree_type *align = 0;
193: etree_type *subalign = 0;
194: struct wildcard_list *tmp;
195:
196:
197: for (aptr = alignment; aptr; aptr = aptr->next)
198: if (strcmp (aptr->name, p->name) == 0)
199: align = aptr->align;
200:
201: for (aptr = subalignment; aptr; aptr = aptr->next)
202: if (strcmp (aptr->name, p->name) == 0)
203: subalign = aptr->subalign;
204:
205: if (base == 0)
206: base = p->vma ? p->vma : exp_nameop (NAME, ".");
207:
208: lang_enter_output_section_statement (p->name, base,
209: p->ok_to_load ? 0 : noload_section,
210: align, subalign, NULL, 0);
211: base = 0;
212: tmp = xmalloc (sizeof *tmp);
213: tmp->next = NULL;
214: tmp->spec.name = p->name;
215: tmp->spec.exclude_name_list = NULL;
216: tmp->spec.sorted = none;
217: lang_add_wild (NULL, tmp, FALSE);
218:
219:
220: for (aptr = alias; aptr; aptr = aptr->next)
221: if (strcmp (aptr->alias, p->name) == 0)
222: {
223: tmp = xmalloc (sizeof *tmp);
224: tmp->next = NULL;
225: tmp->spec.name = aptr->name;
226: tmp->spec.exclude_name_list = NULL;
227: tmp->spec.sorted = none;
228: lang_add_wild (NULL, tmp, FALSE);
229: }
230:
231: lang_leave_output_section_statement (0, "*default*", NULL, NULL);
232:
233: p = p->next;
234: }
235: }
236:
237: done_tree = 1;
238: }
239:
240: void
241: mri_load (const char *name)
242: {
243: base = 0;
244: lang_add_input_file (name, lang_input_file_is_file_enum, NULL);
245: }
246:
247: void
248: mri_order (const char *name)
249: {
250: mri_add_to_list (&order, name, 0, 0, 0, 0);
251: }
252:
253: void
254: mri_alias (const char *want, const char *is, int isn)
255: {
256: if (!is)
257: {
258: char buf[20];
259:
260:
261: sprintf (buf, "%d", isn);
262:
263: is = xstrdup (buf);
264:
265: if (is == NULL)
266: abort ();
267: }
268:
269: mri_add_to_list (&alias, is, 0, want, 0, 0);
270: }
271:
272: void
273: mri_name (const char *name)
274: {
275: lang_add_output (name, 1);
276: }
277:
278: void
279: mri_format (const char *name)
280: {
281: if (strcmp (name, "S") == 0)
282: lang_add_output_format ("srec", NULL, NULL, 1);
283:
284: else if (strcmp (name, "IEEE") == 0)
285: lang_add_output_format ("ieee", NULL, NULL, 1);
286:
287: else if (strcmp (name, "COFF") == 0)
288: lang_add_output_format ("coff-m68k", NULL, NULL, 1);
289:
290: else
291: einfo (_("%P%F: unknown format type %s\n"), name);
292: }
293:
294: void
295: mri_public (const char *name, etree_type *exp)
296: {
297: lang_add_assignment (exp_assop ('=', name, exp));
298: }
299:
300: void
301: mri_align (const char *name, etree_type *exp)
302: {
303: mri_add_to_list (&alignment, name, 0, 0, exp, 0);
304: }
305:
306: void
307: mri_alignmod (const char *name, etree_type *exp)
308: {
309: mri_add_to_list (&subalignment, name, 0, 0, 0, exp);
310: }
311:
312: void
313: mri_truncate (unsigned int exp)
314: {
315: symbol_truncate = exp;
316: }