tc-mn10300.c revision 1.1.1.6 1 1.1 christos /* tc-mn10300.c -- Assembler code for the Matsushita 10300
2 1.1.1.6 christos Copyright (C) 1996-2022 Free Software Foundation, Inc.
3 1.1 christos
4 1.1 christos This file is part of GAS, the GNU Assembler.
5 1.1 christos
6 1.1 christos GAS is free software; you can redistribute it and/or modify
7 1.1 christos it under the terms of the GNU General Public License as published by
8 1.1 christos the Free Software Foundation; either version 3, or (at your option)
9 1.1 christos any later version.
10 1.1 christos
11 1.1 christos GAS is distributed in the hope that it will be useful,
12 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
13 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 1.1 christos GNU General Public License for more details.
15 1.1 christos
16 1.1 christos You should have received a copy of the GNU General Public License
17 1.1 christos along with GAS; see the file COPYING. If not, write to
18 1.1 christos the Free Software Foundation, 51 Franklin Street - Fifth Floor,
19 1.1 christos Boston, MA 02110-1301, USA. */
20 1.1 christos
21 1.1 christos #include "as.h"
22 1.1 christos #include "safe-ctype.h"
23 1.1 christos #include "subsegs.h"
24 1.1 christos #include "opcode/mn10300.h"
25 1.1 christos #include "dwarf2dbg.h"
26 1.1 christos #include "libiberty.h"
27 1.1 christos
28 1.1 christos /* Structure to hold information about predefined registers. */
30 1.1 christos struct reg_name
31 1.1 christos {
32 1.1 christos const char *name;
33 1.1 christos int value;
34 1.1 christos };
35 1.1 christos
36 1.1 christos /* Generic assembler global variables which must be defined by all
37 1.1 christos targets. */
38 1.1 christos
39 1.1 christos /* Characters which always start a comment. */
40 1.1 christos const char comment_chars[] = "#";
41 1.1 christos
42 1.1 christos /* Characters which start a comment at the beginning of a line. */
43 1.1 christos const char line_comment_chars[] = ";#";
44 1.1 christos
45 1.1 christos /* Characters which may be used to separate multiple commands on a
46 1.1 christos single line. */
47 1.1 christos const char line_separator_chars[] = ";";
48 1.1 christos
49 1.1 christos /* Characters which are used to indicate an exponent in a floating
50 1.1 christos point number. */
51 1.1 christos const char EXP_CHARS[] = "eE";
52 1.1 christos
53 1.1 christos /* Characters which mean that a number is a floating point constant,
54 1.1 christos as in 0d1.0. */
55 1.1 christos const char FLT_CHARS[] = "dD";
56 1.1 christos
57 1.1 christos const relax_typeS md_relax_table[] =
59 1.1 christos {
60 1.1 christos /* The plus values for the bCC and fBCC instructions in the table below
61 1.1 christos are because the branch instruction is translated into a jump
62 1.1 christos instruction that is now +2 or +3 bytes further on in memory, and the
63 1.1 christos correct size of jump instruction must be selected. */
64 1.1 christos /* bCC relaxing. */
65 1.1 christos {0x7f, -0x80, 2, 1},
66 1.1 christos {0x7fff + 2, -0x8000 + 2, 5, 2},
67 1.1 christos {0x7fffffff, -0x80000000, 7, 0},
68 1.1 christos
69 1.1 christos /* bCC relaxing (uncommon cases for 3byte length instructions) */
70 1.1 christos {0x7f, -0x80, 3, 4},
71 1.1 christos {0x7fff + 3, -0x8000 + 3, 6, 5},
72 1.1 christos {0x7fffffff, -0x80000000, 8, 0},
73 1.1 christos
74 1.1 christos /* call relaxing. */
75 1.1 christos {0x7fff, -0x8000, 5, 7},
76 1.1 christos {0x7fffffff, -0x80000000, 7, 0},
77 1.1 christos
78 1.1 christos /* calls relaxing. */
79 1.1 christos {0x7fff, -0x8000, 4, 9},
80 1.1 christos {0x7fffffff, -0x80000000, 6, 0},
81 1.1 christos
82 1.1 christos /* jmp relaxing. */
83 1.1 christos {0x7f, -0x80, 2, 11},
84 1.1 christos {0x7fff, -0x8000, 3, 12},
85 1.1 christos {0x7fffffff, -0x80000000, 5, 0},
86 1.1 christos
87 1.1 christos /* fbCC relaxing. */
88 1.1 christos {0x7f, -0x80, 3, 14},
89 1.1 christos {0x7fff + 3, -0x8000 + 3, 6, 15},
90 1.1 christos {0x7fffffff, -0x80000000, 8, 0},
91 1.1 christos
92 1.1 christos };
93 1.1 christos
94 1.1 christos static int current_machine;
95 1.1 christos
96 1.1 christos /* Fixups. */
97 1.1 christos #define MAX_INSN_FIXUPS 5
98 1.1 christos
99 1.1 christos struct mn10300_fixup
100 1.1 christos {
101 1.1 christos expressionS exp;
102 1.1 christos int opindex;
103 1.1 christos bfd_reloc_code_real_type reloc;
104 1.1 christos };
105 1.1 christos struct mn10300_fixup fixups[MAX_INSN_FIXUPS];
106 1.1 christos static int fc;
107 1.1 christos
108 1.1 christos /* We must store the value of each register operand so that we can
109 1.1 christos verify that certain registers do not match. */
110 1.1 christos int mn10300_reg_operands[MN10300_MAX_OPERANDS];
111 1.1 christos
112 1.1 christos const char *md_shortopts = "";
114 1.1 christos
115 1.1 christos struct option md_longopts[] =
116 1.1 christos {
117 1.1 christos {NULL, no_argument, NULL, 0}
118 1.1 christos };
119 1.1 christos
120 1.1 christos size_t md_longopts_size = sizeof (md_longopts);
121 1.1 christos
122 1.1 christos #define HAVE_AM33_2 (current_machine == AM33_2)
123 1.1 christos #define HAVE_AM33 (current_machine == AM33 || HAVE_AM33_2)
124 1.1.1.6 christos #define HAVE_AM30 (current_machine == AM30)
125 1.1 christos
126 1.1 christos /* Opcode hash table. */
127 1.1 christos static htab_t mn10300_hash;
128 1.1 christos
129 1.1 christos /* This table is sorted. Suitable for searching by a binary search. */
130 1.1 christos static const struct reg_name data_registers[] =
131 1.1 christos {
132 1.1 christos { "d0", 0 },
133 1.1 christos { "d1", 1 },
134 1.1 christos { "d2", 2 },
135 1.1 christos { "d3", 3 },
136 1.1 christos };
137 1.1 christos
138 1.1 christos static const struct reg_name address_registers[] =
139 1.1 christos {
140 1.1 christos { "a0", 0 },
141 1.1 christos { "a1", 1 },
142 1.1 christos { "a2", 2 },
143 1.1 christos { "a3", 3 },
144 1.1 christos };
145 1.1 christos
146 1.1 christos static const struct reg_name r_registers[] =
147 1.1 christos {
148 1.1 christos { "a0", 8 },
149 1.1 christos { "a1", 9 },
150 1.1 christos { "a2", 10 },
151 1.1 christos { "a3", 11 },
152 1.1 christos { "d0", 12 },
153 1.1 christos { "d1", 13 },
154 1.1 christos { "d2", 14 },
155 1.1 christos { "d3", 15 },
156 1.1 christos { "e0", 0 },
157 1.1 christos { "e1", 1 },
158 1.1 christos { "e10", 10 },
159 1.1 christos { "e11", 11 },
160 1.1 christos { "e12", 12 },
161 1.1 christos { "e13", 13 },
162 1.1 christos { "e14", 14 },
163 1.1 christos { "e15", 15 },
164 1.1 christos { "e2", 2 },
165 1.1 christos { "e3", 3 },
166 1.1 christos { "e4", 4 },
167 1.1 christos { "e5", 5 },
168 1.1 christos { "e6", 6 },
169 1.1 christos { "e7", 7 },
170 1.1 christos { "e8", 8 },
171 1.1 christos { "e9", 9 },
172 1.1 christos { "r0", 0 },
173 1.1 christos { "r1", 1 },
174 1.1 christos { "r10", 10 },
175 1.1 christos { "r11", 11 },
176 1.1 christos { "r12", 12 },
177 1.1 christos { "r13", 13 },
178 1.1 christos { "r14", 14 },
179 1.1 christos { "r15", 15 },
180 1.1 christos { "r2", 2 },
181 1.1 christos { "r3", 3 },
182 1.1 christos { "r4", 4 },
183 1.1 christos { "r5", 5 },
184 1.1 christos { "r6", 6 },
185 1.1 christos { "r7", 7 },
186 1.1 christos { "r8", 8 },
187 1.1 christos { "r9", 9 },
188 1.1 christos };
189 1.1 christos
190 1.1 christos static const struct reg_name xr_registers[] =
191 1.1 christos {
192 1.1 christos { "mcrh", 2 },
193 1.1 christos { "mcrl", 3 },
194 1.1 christos { "mcvf", 4 },
195 1.1 christos { "mdrq", 1 },
196 1.1 christos { "sp", 0 },
197 1.1 christos { "xr0", 0 },
198 1.1 christos { "xr1", 1 },
199 1.1 christos { "xr10", 10 },
200 1.1 christos { "xr11", 11 },
201 1.1 christos { "xr12", 12 },
202 1.1 christos { "xr13", 13 },
203 1.1 christos { "xr14", 14 },
204 1.1 christos { "xr15", 15 },
205 1.1 christos { "xr2", 2 },
206 1.1 christos { "xr3", 3 },
207 1.1 christos { "xr4", 4 },
208 1.1 christos { "xr5", 5 },
209 1.1 christos { "xr6", 6 },
210 1.1 christos { "xr7", 7 },
211 1.1 christos { "xr8", 8 },
212 1.1 christos { "xr9", 9 },
213 1.1 christos };
214 1.1 christos
215 1.1 christos static const struct reg_name float_registers[] =
216 1.1 christos {
217 1.1 christos { "fs0", 0 },
218 1.1 christos { "fs1", 1 },
219 1.1 christos { "fs10", 10 },
220 1.1 christos { "fs11", 11 },
221 1.1 christos { "fs12", 12 },
222 1.1 christos { "fs13", 13 },
223 1.1 christos { "fs14", 14 },
224 1.1 christos { "fs15", 15 },
225 1.1 christos { "fs16", 16 },
226 1.1 christos { "fs17", 17 },
227 1.1 christos { "fs18", 18 },
228 1.1 christos { "fs19", 19 },
229 1.1 christos { "fs2", 2 },
230 1.1 christos { "fs20", 20 },
231 1.1 christos { "fs21", 21 },
232 1.1 christos { "fs22", 22 },
233 1.1 christos { "fs23", 23 },
234 1.1 christos { "fs24", 24 },
235 1.1 christos { "fs25", 25 },
236 1.1 christos { "fs26", 26 },
237 1.1 christos { "fs27", 27 },
238 1.1 christos { "fs28", 28 },
239 1.1 christos { "fs29", 29 },
240 1.1 christos { "fs3", 3 },
241 1.1 christos { "fs30", 30 },
242 1.1 christos { "fs31", 31 },
243 1.1 christos { "fs4", 4 },
244 1.1 christos { "fs5", 5 },
245 1.1 christos { "fs6", 6 },
246 1.1 christos { "fs7", 7 },
247 1.1 christos { "fs8", 8 },
248 1.1 christos { "fs9", 9 },
249 1.1 christos };
250 1.1 christos
251 1.1 christos static const struct reg_name double_registers[] =
252 1.1 christos {
253 1.1 christos { "fd0", 0 },
254 1.1 christos { "fd10", 10 },
255 1.1 christos { "fd12", 12 },
256 1.1 christos { "fd14", 14 },
257 1.1 christos { "fd16", 16 },
258 1.1 christos { "fd18", 18 },
259 1.1 christos { "fd2", 2 },
260 1.1 christos { "fd20", 20 },
261 1.1 christos { "fd22", 22 },
262 1.1 christos { "fd24", 24 },
263 1.1 christos { "fd26", 26 },
264 1.1 christos { "fd28", 28 },
265 1.1 christos { "fd30", 30 },
266 1.1 christos { "fd4", 4 },
267 1.1 christos { "fd6", 6 },
268 1.1 christos { "fd8", 8 },
269 1.1 christos };
270 1.1 christos
271 1.1 christos /* We abuse the `value' field, that would be otherwise unused, to
272 1.1 christos encode the architecture on which (access to) the register was
273 1.1 christos introduced. FIXME: we should probably warn when we encounter a
274 1.1 christos register name when assembling for an architecture that doesn't
275 1.1 christos support it, before parsing it as a symbol name. */
276 1.1 christos static const struct reg_name other_registers[] =
277 1.1 christos {
278 1.1 christos { "epsw", AM33 },
279 1.1 christos { "mdr", 0 },
280 1.1 christos { "pc", AM33 },
281 1.1 christos { "psw", 0 },
282 1.1 christos { "sp", 0 },
283 1.1 christos { "ssp", 0 },
284 1.1 christos { "usp", 0 },
285 1.1 christos };
286 1.1 christos
287 1.1.1.4 christos #define OTHER_REG_NAME_CNT ARRAY_SIZE (other_registers)
288 1.1 christos
289 1.1 christos /* Perform a binary search of the given register table REGS to see
290 1.1 christos if NAME is a valid register name. Returns the register number from
291 1.1 christos the array on success, or -1 on failure. */
292 1.1 christos
293 1.1 christos static int
294 1.1 christos reg_name_search (const struct reg_name *regs,
295 1.1 christos int regcount,
296 1.1 christos const char *name)
297 1.1 christos {
298 1.1 christos int low, high;
299 1.1 christos
300 1.1 christos low = 0;
301 1.1 christos high = regcount - 1;
302 1.1 christos
303 1.1 christos do
304 1.1 christos {
305 1.1 christos int cmp, middle;
306 1.1 christos
307 1.1 christos middle = (low + high) / 2;
308 1.1 christos cmp = strcasecmp (name, regs[middle].name);
309 1.1 christos if (cmp < 0)
310 1.1 christos high = middle - 1;
311 1.1 christos else if (cmp > 0)
312 1.1 christos low = middle + 1;
313 1.1 christos else
314 1.1 christos return regs[middle].value;
315 1.1 christos }
316 1.1 christos while (low <= high);
317 1.1 christos
318 1.1 christos return -1;
319 1.1 christos }
320 1.1 christos
321 1.1 christos /* Looks at the current position in the input line to see if it is
322 1.1 christos the name of a register in TABLE. If it is, then the name is
323 1.1 christos converted into an expression returned in EXPRESSIONP (with X_op
324 1.1 christos set to O_register and X_add_number set to the register number), the
325 1.1 christos input pointer is left pointing at the first non-blank character after
326 1.1.1.6 christos the name and the function returns TRUE. Otherwise the input pointer
327 1.1 christos is left alone and the function returns FALSE. */
328 1.1 christos
329 1.1 christos static bool
330 1.1 christos get_register_name (expressionS * expressionP,
331 1.1 christos const struct reg_name * table,
332 1.1 christos size_t table_length)
333 1.1 christos {
334 1.1 christos int reg_number;
335 1.1 christos char *name;
336 1.1 christos char *start;
337 1.1.1.2 christos char c;
338 1.1 christos
339 1.1.1.2 christos /* Find the spelling of the operand. */
340 1.1 christos start = input_line_pointer;
341 1.1 christos
342 1.1 christos c = get_symbol_name (&name);
343 1.1.1.2 christos reg_number = reg_name_search (table, table_length, name);
344 1.1 christos
345 1.1 christos /* Put back the delimiting char. */
346 1.1 christos (void) restore_line_pointer (c);
347 1.1 christos
348 1.1 christos /* Look to see if it's in the register table. */
349 1.1 christos if (reg_number >= 0)
350 1.1 christos {
351 1.1 christos expressionP->X_op = O_register;
352 1.1 christos expressionP->X_add_number = reg_number;
353 1.1 christos
354 1.1 christos /* Make the rest nice. */
355 1.1.1.6 christos expressionP->X_add_symbol = NULL;
356 1.1 christos expressionP->X_op_symbol = NULL;
357 1.1 christos
358 1.1 christos return true;
359 1.1 christos }
360 1.1.1.6 christos
361 1.1 christos /* Reset the line as if we had not done anything. */
362 1.1 christos input_line_pointer = start;
363 1.1.1.6 christos return false;
364 1.1 christos }
365 1.1 christos
366 1.1 christos static bool
367 1.1 christos r_register_name (expressionS *expressionP)
368 1.1 christos {
369 1.1 christos return get_register_name (expressionP, r_registers, ARRAY_SIZE (r_registers));
370 1.1.1.6 christos }
371 1.1 christos
372 1.1 christos
373 1.1 christos static bool
374 1.1 christos xr_register_name (expressionS *expressionP)
375 1.1 christos {
376 1.1.1.6 christos return get_register_name (expressionP, xr_registers, ARRAY_SIZE (xr_registers));
377 1.1 christos }
378 1.1 christos
379 1.1 christos static bool
380 1.1 christos data_register_name (expressionS *expressionP)
381 1.1 christos {
382 1.1.1.6 christos return get_register_name (expressionP, data_registers, ARRAY_SIZE (data_registers));
383 1.1 christos }
384 1.1 christos
385 1.1 christos static bool
386 1.1 christos address_register_name (expressionS *expressionP)
387 1.1 christos {
388 1.1.1.6 christos return get_register_name (expressionP, address_registers, ARRAY_SIZE (address_registers));
389 1.1 christos }
390 1.1 christos
391 1.1 christos static bool
392 1.1 christos float_register_name (expressionS *expressionP)
393 1.1 christos {
394 1.1.1.6 christos return get_register_name (expressionP, float_registers, ARRAY_SIZE (float_registers));
395 1.1 christos }
396 1.1 christos
397 1.1 christos static bool
398 1.1 christos double_register_name (expressionS *expressionP)
399 1.1 christos {
400 1.1.1.6 christos return get_register_name (expressionP, double_registers, ARRAY_SIZE (double_registers));
401 1.1 christos }
402 1.1 christos
403 1.1 christos static bool
404 1.1 christos other_register_name (expressionS *expressionP)
405 1.1 christos {
406 1.1 christos int reg_number;
407 1.1 christos char *name;
408 1.1 christos char *start;
409 1.1.1.2 christos char c;
410 1.1 christos
411 1.1.1.2 christos /* Find the spelling of the operand. */
412 1.1 christos start = input_line_pointer;
413 1.1 christos
414 1.1 christos c = get_symbol_name (&name);
415 1.1.1.2 christos reg_number = reg_name_search (other_registers, ARRAY_SIZE (other_registers), name);
416 1.1 christos
417 1.1 christos /* Put back the delimiting char. */
418 1.1 christos (void) restore_line_pointer (c);
419 1.1 christos
420 1.1 christos /* Look to see if it's in the register table. */
421 1.1 christos if (reg_number == 0
422 1.1 christos || (reg_number == AM33 && HAVE_AM33))
423 1.1 christos {
424 1.1 christos expressionP->X_op = O_register;
425 1.1 christos expressionP->X_add_number = 0;
426 1.1 christos
427 1.1 christos /* Make the rest nice. */
428 1.1.1.6 christos expressionP->X_add_symbol = NULL;
429 1.1 christos expressionP->X_op_symbol = NULL;
430 1.1 christos
431 1.1 christos return true;
432 1.1 christos }
433 1.1.1.6 christos
434 1.1 christos /* Reset the line as if we had not done anything. */
435 1.1 christos input_line_pointer = start;
436 1.1 christos return false;
437 1.1 christos }
438 1.1 christos
439 1.1 christos void
440 1.1 christos md_show_usage (FILE *stream)
441 1.1 christos {
442 1.1 christos fprintf (stream, _("MN10300 assembler options:\n\
443 1.1 christos none yet\n"));
444 1.1.1.3 christos }
445 1.1 christos
446 1.1 christos int
447 1.1 christos md_parse_option (int c ATTRIBUTE_UNUSED, const char *arg ATTRIBUTE_UNUSED)
448 1.1 christos {
449 1.1 christos return 0;
450 1.1 christos }
451 1.1 christos
452 1.1 christos symbolS *
453 1.1 christos md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
454 1.1 christos {
455 1.1.1.3 christos return 0;
456 1.1 christos }
457 1.1 christos
458 1.1.1.6 christos const char *
459 1.1 christos md_atof (int type, char *litp, int *sizep)
460 1.1 christos {
461 1.1 christos return ieee_md_atof (type, litp, sizep, false);
462 1.1 christos }
463 1.1 christos
464 1.1 christos void
465 1.1 christos md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
466 1.1 christos asection *sec,
467 1.1 christos fragS *fragP)
468 1.1 christos {
469 1.1 christos static unsigned long label_count = 0;
470 1.1 christos char buf[40];
471 1.1 christos
472 1.1 christos subseg_change (sec, 0);
473 1.1 christos if (fragP->fr_subtype == 0)
474 1.1 christos {
475 1.1 christos fix_new (fragP, fragP->fr_fix + 1, 1, fragP->fr_symbol,
476 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
477 1.1 christos fragP->fr_var = 0;
478 1.1 christos fragP->fr_fix += 2;
479 1.1 christos }
480 1.1 christos else if (fragP->fr_subtype == 1)
481 1.1 christos {
482 1.1 christos /* Reverse the condition of the first branch. */
483 1.1 christos int offset = fragP->fr_fix;
484 1.1 christos int opcode = fragP->fr_literal[offset] & 0xff;
485 1.1 christos
486 1.1 christos switch (opcode)
487 1.1 christos {
488 1.1 christos case 0xc8:
489 1.1 christos opcode = 0xc9;
490 1.1 christos break;
491 1.1 christos case 0xc9:
492 1.1 christos opcode = 0xc8;
493 1.1 christos break;
494 1.1 christos case 0xc0:
495 1.1 christos opcode = 0xc2;
496 1.1 christos break;
497 1.1 christos case 0xc2:
498 1.1 christos opcode = 0xc0;
499 1.1 christos break;
500 1.1 christos case 0xc3:
501 1.1 christos opcode = 0xc1;
502 1.1 christos break;
503 1.1 christos case 0xc1:
504 1.1 christos opcode = 0xc3;
505 1.1 christos break;
506 1.1 christos case 0xc4:
507 1.1 christos opcode = 0xc6;
508 1.1 christos break;
509 1.1 christos case 0xc6:
510 1.1 christos opcode = 0xc4;
511 1.1 christos break;
512 1.1 christos case 0xc7:
513 1.1 christos opcode = 0xc5;
514 1.1 christos break;
515 1.1 christos case 0xc5:
516 1.1 christos opcode = 0xc7;
517 1.1 christos break;
518 1.1 christos default:
519 1.1 christos abort ();
520 1.1 christos }
521 1.1 christos fragP->fr_literal[offset] = opcode;
522 1.1 christos
523 1.1.1.6 christos /* Create a fixup for the reversed conditional branch. */
524 1.1 christos sprintf (buf, ".%s_%ld", FAKE_LABEL_NAME, label_count++);
525 1.1 christos fix_new (fragP, fragP->fr_fix + 1, 1,
526 1.1 christos symbol_new (buf, sec, fragP->fr_next, 0),
527 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
528 1.1 christos
529 1.1 christos /* Now create the unconditional branch + fixup to the
530 1.1 christos final target. */
531 1.1 christos fragP->fr_literal[offset + 2] = 0xcc;
532 1.1 christos fix_new (fragP, fragP->fr_fix + 3, 2, fragP->fr_symbol,
533 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
534 1.1 christos fragP->fr_var = 0;
535 1.1 christos fragP->fr_fix += 5;
536 1.1 christos }
537 1.1 christos else if (fragP->fr_subtype == 2)
538 1.1 christos {
539 1.1 christos /* Reverse the condition of the first branch. */
540 1.1 christos int offset = fragP->fr_fix;
541 1.1 christos int opcode = fragP->fr_literal[offset] & 0xff;
542 1.1 christos
543 1.1 christos switch (opcode)
544 1.1 christos {
545 1.1 christos case 0xc8:
546 1.1 christos opcode = 0xc9;
547 1.1 christos break;
548 1.1 christos case 0xc9:
549 1.1 christos opcode = 0xc8;
550 1.1 christos break;
551 1.1 christos case 0xc0:
552 1.1 christos opcode = 0xc2;
553 1.1 christos break;
554 1.1 christos case 0xc2:
555 1.1 christos opcode = 0xc0;
556 1.1 christos break;
557 1.1 christos case 0xc3:
558 1.1 christos opcode = 0xc1;
559 1.1 christos break;
560 1.1 christos case 0xc1:
561 1.1 christos opcode = 0xc3;
562 1.1 christos break;
563 1.1 christos case 0xc4:
564 1.1 christos opcode = 0xc6;
565 1.1 christos break;
566 1.1 christos case 0xc6:
567 1.1 christos opcode = 0xc4;
568 1.1 christos break;
569 1.1 christos case 0xc7:
570 1.1 christos opcode = 0xc5;
571 1.1 christos break;
572 1.1 christos case 0xc5:
573 1.1 christos opcode = 0xc7;
574 1.1 christos break;
575 1.1 christos default:
576 1.1 christos abort ();
577 1.1 christos }
578 1.1 christos fragP->fr_literal[offset] = opcode;
579 1.1 christos
580 1.1.1.6 christos /* Create a fixup for the reversed conditional branch. */
581 1.1 christos sprintf (buf, ".%s_%ld", FAKE_LABEL_NAME, label_count++);
582 1.1 christos fix_new (fragP, fragP->fr_fix + 1, 1,
583 1.1 christos symbol_new (buf, sec, fragP->fr_next, 0),
584 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
585 1.1 christos
586 1.1 christos /* Now create the unconditional branch + fixup to the
587 1.1 christos final target. */
588 1.1 christos fragP->fr_literal[offset + 2] = 0xdc;
589 1.1 christos fix_new (fragP, fragP->fr_fix + 3, 4, fragP->fr_symbol,
590 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
591 1.1 christos fragP->fr_var = 0;
592 1.1 christos fragP->fr_fix += 7;
593 1.1 christos }
594 1.1 christos else if (fragP->fr_subtype == 3)
595 1.1 christos {
596 1.1 christos fix_new (fragP, fragP->fr_fix + 2, 1, fragP->fr_symbol,
597 1.1 christos fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
598 1.1 christos fragP->fr_var = 0;
599 1.1 christos fragP->fr_fix += 3;
600 1.1 christos }
601 1.1 christos else if (fragP->fr_subtype == 4)
602 1.1 christos {
603 1.1 christos /* Reverse the condition of the first branch. */
604 1.1 christos int offset = fragP->fr_fix;
605 1.1 christos int opcode = fragP->fr_literal[offset + 1] & 0xff;
606 1.1 christos
607 1.1 christos switch (opcode)
608 1.1 christos {
609 1.1 christos case 0xe8:
610 1.1 christos opcode = 0xe9;
611 1.1 christos break;
612 1.1 christos case 0xe9:
613 1.1 christos opcode = 0xe8;
614 1.1 christos break;
615 1.1 christos case 0xea:
616 1.1 christos opcode = 0xeb;
617 1.1 christos break;
618 1.1 christos case 0xeb:
619 1.1 christos opcode = 0xea;
620 1.1 christos break;
621 1.1 christos default:
622 1.1 christos abort ();
623 1.1 christos }
624 1.1 christos fragP->fr_literal[offset + 1] = opcode;
625 1.1 christos
626 1.1.1.6 christos /* Create a fixup for the reversed conditional branch. */
627 1.1 christos sprintf (buf, ".%s_%ld", FAKE_LABEL_NAME, label_count++);
628 1.1 christos fix_new (fragP, fragP->fr_fix + 2, 1,
629 1.1 christos symbol_new (buf, sec, fragP->fr_next, 0),
630 1.1 christos fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
631 1.1 christos
632 1.1 christos /* Now create the unconditional branch + fixup to the
633 1.1 christos final target. */
634 1.1 christos fragP->fr_literal[offset + 3] = 0xcc;
635 1.1 christos fix_new (fragP, fragP->fr_fix + 4, 2, fragP->fr_symbol,
636 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
637 1.1 christos fragP->fr_var = 0;
638 1.1 christos fragP->fr_fix += 6;
639 1.1 christos }
640 1.1 christos else if (fragP->fr_subtype == 5)
641 1.1 christos {
642 1.1 christos /* Reverse the condition of the first branch. */
643 1.1 christos int offset = fragP->fr_fix;
644 1.1 christos int opcode = fragP->fr_literal[offset + 1] & 0xff;
645 1.1 christos
646 1.1 christos switch (opcode)
647 1.1 christos {
648 1.1 christos case 0xe8:
649 1.1 christos opcode = 0xe9;
650 1.1 christos break;
651 1.1 christos case 0xea:
652 1.1 christos opcode = 0xeb;
653 1.1 christos break;
654 1.1 christos case 0xeb:
655 1.1 christos opcode = 0xea;
656 1.1 christos break;
657 1.1 christos default:
658 1.1 christos abort ();
659 1.1 christos }
660 1.1 christos fragP->fr_literal[offset + 1] = opcode;
661 1.1 christos
662 1.1.1.6 christos /* Create a fixup for the reversed conditional branch. */
663 1.1 christos sprintf (buf, ".%s_%ld", FAKE_LABEL_NAME, label_count++);
664 1.1 christos fix_new (fragP, fragP->fr_fix + 2, 1,
665 1.1 christos symbol_new (buf, sec, fragP->fr_next, 0),
666 1.1 christos fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
667 1.1 christos
668 1.1 christos /* Now create the unconditional branch + fixup to the
669 1.1 christos final target. */
670 1.1 christos fragP->fr_literal[offset + 3] = 0xdc;
671 1.1 christos fix_new (fragP, fragP->fr_fix + 4, 4, fragP->fr_symbol,
672 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
673 1.1 christos fragP->fr_var = 0;
674 1.1 christos fragP->fr_fix += 8;
675 1.1 christos }
676 1.1 christos else if (fragP->fr_subtype == 6)
677 1.1 christos {
678 1.1 christos int offset = fragP->fr_fix;
679 1.1 christos
680 1.1 christos fragP->fr_literal[offset] = 0xcd;
681 1.1 christos fix_new (fragP, fragP->fr_fix + 1, 2, fragP->fr_symbol,
682 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
683 1.1 christos fragP->fr_var = 0;
684 1.1 christos fragP->fr_fix += 5;
685 1.1 christos }
686 1.1 christos else if (fragP->fr_subtype == 7)
687 1.1 christos {
688 1.1 christos int offset = fragP->fr_fix;
689 1.1 christos
690 1.1 christos fragP->fr_literal[offset] = 0xdd;
691 1.1 christos fragP->fr_literal[offset + 5] = fragP->fr_literal[offset + 3];
692 1.1 christos fragP->fr_literal[offset + 6] = fragP->fr_literal[offset + 4];
693 1.1 christos fragP->fr_literal[offset + 3] = 0;
694 1.1 christos fragP->fr_literal[offset + 4] = 0;
695 1.1 christos
696 1.1 christos fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol,
697 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
698 1.1 christos fragP->fr_var = 0;
699 1.1 christos fragP->fr_fix += 7;
700 1.1 christos }
701 1.1 christos else if (fragP->fr_subtype == 8)
702 1.1 christos {
703 1.1 christos int offset = fragP->fr_fix;
704 1.1 christos
705 1.1 christos fragP->fr_literal[offset] = 0xfa;
706 1.1 christos fragP->fr_literal[offset + 1] = 0xff;
707 1.1 christos fix_new (fragP, fragP->fr_fix + 2, 2, fragP->fr_symbol,
708 1.1 christos fragP->fr_offset + 2, 1, BFD_RELOC_16_PCREL);
709 1.1 christos fragP->fr_var = 0;
710 1.1 christos fragP->fr_fix += 4;
711 1.1 christos }
712 1.1 christos else if (fragP->fr_subtype == 9)
713 1.1 christos {
714 1.1 christos int offset = fragP->fr_fix;
715 1.1 christos
716 1.1 christos fragP->fr_literal[offset] = 0xfc;
717 1.1 christos fragP->fr_literal[offset + 1] = 0xff;
718 1.1 christos
719 1.1 christos fix_new (fragP, fragP->fr_fix + 2, 4, fragP->fr_symbol,
720 1.1 christos fragP->fr_offset + 2, 1, BFD_RELOC_32_PCREL);
721 1.1 christos fragP->fr_var = 0;
722 1.1 christos fragP->fr_fix += 6;
723 1.1 christos }
724 1.1 christos else if (fragP->fr_subtype == 10)
725 1.1 christos {
726 1.1 christos fragP->fr_literal[fragP->fr_fix] = 0xca;
727 1.1 christos fix_new (fragP, fragP->fr_fix + 1, 1, fragP->fr_symbol,
728 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
729 1.1 christos fragP->fr_var = 0;
730 1.1 christos fragP->fr_fix += 2;
731 1.1 christos }
732 1.1 christos else if (fragP->fr_subtype == 11)
733 1.1 christos {
734 1.1 christos int offset = fragP->fr_fix;
735 1.1 christos
736 1.1 christos fragP->fr_literal[offset] = 0xcc;
737 1.1 christos
738 1.1 christos fix_new (fragP, fragP->fr_fix + 1, 2, fragP->fr_symbol,
739 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
740 1.1 christos fragP->fr_var = 0;
741 1.1 christos fragP->fr_fix += 3;
742 1.1 christos }
743 1.1 christos else if (fragP->fr_subtype == 12)
744 1.1 christos {
745 1.1 christos int offset = fragP->fr_fix;
746 1.1 christos
747 1.1 christos fragP->fr_literal[offset] = 0xdc;
748 1.1 christos
749 1.1 christos fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol,
750 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
751 1.1 christos fragP->fr_var = 0;
752 1.1 christos fragP->fr_fix += 5;
753 1.1 christos }
754 1.1 christos else if (fragP->fr_subtype == 13)
755 1.1 christos {
756 1.1 christos fix_new (fragP, fragP->fr_fix + 2, 1, fragP->fr_symbol,
757 1.1 christos fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
758 1.1 christos fragP->fr_var = 0;
759 1.1 christos fragP->fr_fix += 3;
760 1.1 christos }
761 1.1 christos else if (fragP->fr_subtype == 14)
762 1.1 christos {
763 1.1 christos /* Reverse the condition of the first branch. */
764 1.1 christos int offset = fragP->fr_fix;
765 1.1 christos int opcode = fragP->fr_literal[offset + 1] & 0xff;
766 1.1 christos
767 1.1 christos switch (opcode)
768 1.1 christos {
769 1.1 christos case 0xd0:
770 1.1 christos opcode = 0xd1;
771 1.1 christos break;
772 1.1 christos case 0xd1:
773 1.1 christos opcode = 0xd0;
774 1.1 christos break;
775 1.1 christos case 0xd2:
776 1.1 christos opcode = 0xdc;
777 1.1 christos break;
778 1.1 christos case 0xd3:
779 1.1 christos opcode = 0xdb;
780 1.1 christos break;
781 1.1 christos case 0xd4:
782 1.1 christos opcode = 0xda;
783 1.1 christos break;
784 1.1 christos case 0xd5:
785 1.1 christos opcode = 0xd9;
786 1.1 christos break;
787 1.1 christos case 0xd6:
788 1.1 christos opcode = 0xd8;
789 1.1 christos break;
790 1.1 christos case 0xd7:
791 1.1 christos opcode = 0xdd;
792 1.1 christos break;
793 1.1 christos case 0xd8:
794 1.1 christos opcode = 0xd6;
795 1.1 christos break;
796 1.1 christos case 0xd9:
797 1.1 christos opcode = 0xd5;
798 1.1 christos break;
799 1.1 christos case 0xda:
800 1.1 christos opcode = 0xd4;
801 1.1 christos break;
802 1.1 christos case 0xdb:
803 1.1 christos opcode = 0xd3;
804 1.1 christos break;
805 1.1 christos case 0xdc:
806 1.1 christos opcode = 0xd2;
807 1.1 christos break;
808 1.1 christos case 0xdd:
809 1.1 christos opcode = 0xd7;
810 1.1 christos break;
811 1.1 christos default:
812 1.1 christos abort ();
813 1.1 christos }
814 1.1 christos fragP->fr_literal[offset + 1] = opcode;
815 1.1 christos
816 1.1.1.6 christos /* Create a fixup for the reversed conditional branch. */
817 1.1 christos sprintf (buf, ".%s_%ld", FAKE_LABEL_NAME, label_count++);
818 1.1 christos fix_new (fragP, fragP->fr_fix + 2, 1,
819 1.1 christos symbol_new (buf, sec, fragP->fr_next, 0),
820 1.1 christos fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
821 1.1 christos
822 1.1 christos /* Now create the unconditional branch + fixup to the
823 1.1 christos final target. */
824 1.1 christos fragP->fr_literal[offset + 3] = 0xcc;
825 1.1 christos fix_new (fragP, fragP->fr_fix + 4, 2, fragP->fr_symbol,
826 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
827 1.1 christos fragP->fr_var = 0;
828 1.1 christos fragP->fr_fix += 6;
829 1.1 christos }
830 1.1 christos else if (fragP->fr_subtype == 15)
831 1.1 christos {
832 1.1 christos /* Reverse the condition of the first branch. */
833 1.1 christos int offset = fragP->fr_fix;
834 1.1 christos int opcode = fragP->fr_literal[offset + 1] & 0xff;
835 1.1 christos
836 1.1 christos switch (opcode)
837 1.1 christos {
838 1.1 christos case 0xd0:
839 1.1 christos opcode = 0xd1;
840 1.1 christos break;
841 1.1 christos case 0xd1:
842 1.1 christos opcode = 0xd0;
843 1.1 christos break;
844 1.1 christos case 0xd2:
845 1.1 christos opcode = 0xdc;
846 1.1 christos break;
847 1.1 christos case 0xd3:
848 1.1 christos opcode = 0xdb;
849 1.1 christos break;
850 1.1 christos case 0xd4:
851 1.1 christos opcode = 0xda;
852 1.1 christos break;
853 1.1 christos case 0xd5:
854 1.1 christos opcode = 0xd9;
855 1.1 christos break;
856 1.1 christos case 0xd6:
857 1.1 christos opcode = 0xd8;
858 1.1 christos break;
859 1.1 christos case 0xd7:
860 1.1 christos opcode = 0xdd;
861 1.1 christos break;
862 1.1 christos case 0xd8:
863 1.1 christos opcode = 0xd6;
864 1.1 christos break;
865 1.1 christos case 0xd9:
866 1.1 christos opcode = 0xd5;
867 1.1 christos break;
868 1.1 christos case 0xda:
869 1.1 christos opcode = 0xd4;
870 1.1 christos break;
871 1.1 christos case 0xdb:
872 1.1 christos opcode = 0xd3;
873 1.1 christos break;
874 1.1 christos case 0xdc:
875 1.1 christos opcode = 0xd2;
876 1.1 christos break;
877 1.1 christos case 0xdd:
878 1.1 christos opcode = 0xd7;
879 1.1 christos break;
880 1.1 christos default:
881 1.1 christos abort ();
882 1.1 christos }
883 1.1 christos fragP->fr_literal[offset + 1] = opcode;
884 1.1 christos
885 1.1.1.6 christos /* Create a fixup for the reversed conditional branch. */
886 1.1 christos sprintf (buf, ".%s_%ld", FAKE_LABEL_NAME, label_count++);
887 1.1 christos fix_new (fragP, fragP->fr_fix + 2, 1,
888 1.1 christos symbol_new (buf, sec, fragP->fr_next, 0),
889 1.1 christos fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
890 1.1 christos
891 1.1 christos /* Now create the unconditional branch + fixup to the
892 1.1 christos final target. */
893 1.1 christos fragP->fr_literal[offset + 3] = 0xdc;
894 1.1 christos fix_new (fragP, fragP->fr_fix + 4, 4, fragP->fr_symbol,
895 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
896 1.1 christos fragP->fr_var = 0;
897 1.1 christos fragP->fr_fix += 8;
898 1.1 christos }
899 1.1 christos else
900 1.1 christos abort ();
901 1.1 christos }
902 1.1 christos
903 1.1.1.5 christos valueT
904 1.1 christos md_section_align (asection *seg, valueT addr)
905 1.1.1.2 christos {
906 1.1 christos int align = bfd_section_alignment (seg);
907 1.1 christos
908 1.1 christos return ((addr + (1 << align) - 1) & -(1 << align));
909 1.1 christos }
910 1.1 christos
911 1.1.1.3 christos void
912 1.1 christos md_begin (void)
913 1.1 christos {
914 1.1.1.6 christos const char *prev_name = "";
915 1.1 christos const struct mn10300_opcode *op;
916 1.1 christos
917 1.1 christos mn10300_hash = str_htab_create ();
918 1.1 christos
919 1.1 christos /* Insert unique names into hash table. The MN10300 instruction set
920 1.1 christos has many identical opcode names that have different opcodes based
921 1.1 christos on the operands. This hash table then provides a quick index to
922 1.1 christos the first opcode with a particular name in the opcode table. */
923 1.1 christos
924 1.1 christos op = mn10300_opcodes;
925 1.1 christos while (op->name)
926 1.1 christos {
927 1.1.1.6 christos if (strcmp (prev_name, op->name))
928 1.1 christos {
929 1.1 christos prev_name = (char *) op->name;
930 1.1 christos str_hash_insert (mn10300_hash, op->name, op, 0);
931 1.1 christos }
932 1.1 christos op++;
933 1.1 christos }
934 1.1 christos
935 1.1 christos /* Set the default machine type. */
936 1.1 christos #ifdef TE_LINUX
937 1.1 christos if (!bfd_set_arch_mach (stdoutput, bfd_arch_mn10300, AM33_2))
938 1.1.1.2 christos as_warn (_("could not set architecture and machine"));
939 1.1 christos
940 1.1 christos current_machine = AM33_2;
941 1.1 christos #else
942 1.1 christos if (!bfd_set_arch_mach (stdoutput, bfd_arch_mn10300, MN103))
943 1.1 christos as_warn (_("could not set architecture and machine"));
944 1.1.1.3 christos
945 1.1.1.3 christos current_machine = MN103;
946 1.1.1.3 christos #endif
947 1.1 christos
948 1.1 christos /* Set linkrelax here to avoid fixups in most sections. */
949 1.1 christos linkrelax = 1;
950 1.1 christos }
951 1.1 christos
952 1.1 christos static symbolS *GOT_symbol;
953 1.1 christos
954 1.1 christos static inline int
955 1.1 christos mn10300_PIC_related_p (symbolS *sym)
956 1.1 christos {
957 1.1 christos expressionS *exp;
958 1.1 christos
959 1.1 christos if (! sym)
960 1.1 christos return 0;
961 1.1 christos
962 1.1 christos if (sym == GOT_symbol)
963 1.1 christos return 1;
964 1.1 christos
965 1.1 christos exp = symbol_get_value_expression (sym);
966 1.1 christos
967 1.1 christos return (exp->X_op == O_PIC_reloc
968 1.1 christos || mn10300_PIC_related_p (exp->X_add_symbol)
969 1.1 christos || mn10300_PIC_related_p (exp->X_op_symbol));
970 1.1 christos }
971 1.1 christos
972 1.1 christos static inline int
973 1.1 christos mn10300_check_fixup (struct mn10300_fixup *fixup)
974 1.1 christos {
975 1.1 christos expressionS *exp = &fixup->exp;
976 1.1 christos
977 1.1 christos repeat:
978 1.1 christos switch (exp->X_op)
979 1.1 christos {
980 1.1 christos case O_add:
981 1.1 christos case O_subtract: /* If we're sufficiently unlucky that the label
982 1.1 christos and the expression that references it happen
983 1.1 christos to end up in different frags, the subtract
984 1.1 christos won't be simplified within expression(). */
985 1.1 christos /* The PIC-related operand must be the first operand of a sum. */
986 1.1 christos if (exp != &fixup->exp || mn10300_PIC_related_p (exp->X_op_symbol))
987 1.1 christos return 1;
988 1.1 christos
989 1.1 christos if (exp->X_add_symbol && exp->X_add_symbol == GOT_symbol)
990 1.1 christos fixup->reloc = BFD_RELOC_32_GOT_PCREL;
991 1.1 christos
992 1.1 christos exp = symbol_get_value_expression (exp->X_add_symbol);
993 1.1 christos goto repeat;
994 1.1 christos
995 1.1 christos case O_symbol:
996 1.1 christos if (exp->X_add_symbol && exp->X_add_symbol == GOT_symbol)
997 1.1 christos fixup->reloc = BFD_RELOC_32_GOT_PCREL;
998 1.1 christos break;
999 1.1 christos
1000 1.1 christos case O_PIC_reloc:
1001 1.1 christos fixup->reloc = exp->X_md;
1002 1.1 christos exp->X_op = O_symbol;
1003 1.1 christos if (fixup->reloc == BFD_RELOC_32_PLT_PCREL
1004 1.1 christos && fixup->opindex >= 0
1005 1.1 christos && (mn10300_operands[fixup->opindex].flags
1006 1.1 christos & MN10300_OPERAND_RELAX))
1007 1.1 christos return 1;
1008 1.1 christos break;
1009 1.1 christos
1010 1.1 christos default:
1011 1.1 christos return (mn10300_PIC_related_p (exp->X_add_symbol)
1012 1.1 christos || mn10300_PIC_related_p (exp->X_op_symbol));
1013 1.1 christos }
1014 1.1 christos
1015 1.1 christos return 0;
1016 1.1.1.2 christos }
1017 1.1.1.2 christos
1018 1.1 christos void
1019 1.1 christos mn10300_cons_fix_new (fragS *frag, int off, int size, expressionS *exp,
1020 1.1 christos bfd_reloc_code_real_type r ATTRIBUTE_UNUSED)
1021 1.1 christos {
1022 1.1 christos struct mn10300_fixup fixup;
1023 1.1 christos
1024 1.1 christos fixup.opindex = -1;
1025 1.1 christos fixup.exp = *exp;
1026 1.1 christos fixup.reloc = BFD_RELOC_UNUSED;
1027 1.1 christos
1028 1.1 christos mn10300_check_fixup (&fixup);
1029 1.1 christos
1030 1.1 christos if (fixup.reloc == BFD_RELOC_MN10300_GOT32)
1031 1.1 christos switch (size)
1032 1.1 christos {
1033 1.1 christos case 2:
1034 1.1 christos fixup.reloc = BFD_RELOC_MN10300_GOT16;
1035 1.1 christos break;
1036 1.1 christos
1037 1.1 christos case 3:
1038 1.1 christos fixup.reloc = BFD_RELOC_MN10300_GOT24;
1039 1.1 christos break;
1040 1.1 christos
1041 1.1 christos case 4:
1042 1.1 christos break;
1043 1.1 christos
1044 1.1 christos default:
1045 1.1 christos goto error;
1046 1.1 christos }
1047 1.1 christos else if (fixup.reloc == BFD_RELOC_UNUSED)
1048 1.1 christos switch (size)
1049 1.1 christos {
1050 1.1 christos case 1:
1051 1.1 christos fixup.reloc = BFD_RELOC_8;
1052 1.1 christos break;
1053 1.1 christos
1054 1.1 christos case 2:
1055 1.1 christos fixup.reloc = BFD_RELOC_16;
1056 1.1 christos break;
1057 1.1 christos
1058 1.1 christos case 3:
1059 1.1 christos fixup.reloc = BFD_RELOC_24;
1060 1.1 christos break;
1061 1.1 christos
1062 1.1 christos case 4:
1063 1.1 christos fixup.reloc = BFD_RELOC_32;
1064 1.1 christos break;
1065 1.1 christos
1066 1.1 christos default:
1067 1.1 christos goto error;
1068 1.1 christos }
1069 1.1 christos else if (size != 4)
1070 1.1 christos {
1071 1.1 christos error:
1072 1.1.1.2 christos as_bad (_("unsupported BFD relocation size %u"), size);
1073 1.1 christos fixup.reloc = BFD_RELOC_UNUSED;
1074 1.1 christos }
1075 1.1 christos
1076 1.1.1.6 christos fix_new_exp (frag, off, size, &fixup.exp, 0, fixup.reloc);
1077 1.1 christos }
1078 1.1 christos
1079 1.1 christos static bool
1080 1.1 christos check_operand (const struct mn10300_operand *operand,
1081 1.1 christos offsetT val)
1082 1.1 christos {
1083 1.1 christos /* No need to check 32bit operands for a bit. Note that
1084 1.1 christos MN10300_OPERAND_SPLIT is an implicit 32bit operand. */
1085 1.1 christos if (operand->bits != 32
1086 1.1 christos && (operand->flags & MN10300_OPERAND_SPLIT) == 0)
1087 1.1 christos {
1088 1.1 christos long min, max;
1089 1.1 christos offsetT test;
1090 1.1 christos int bits;
1091 1.1 christos
1092 1.1 christos bits = operand->bits;
1093 1.1 christos if (operand->flags & MN10300_OPERAND_24BIT)
1094 1.1 christos bits = 24;
1095 1.1 christos
1096 1.1 christos if ((operand->flags & MN10300_OPERAND_SIGNED) != 0)
1097 1.1 christos {
1098 1.1 christos max = (1 << (bits - 1)) - 1;
1099 1.1 christos min = - (1 << (bits - 1));
1100 1.1 christos }
1101 1.1 christos else
1102 1.1 christos {
1103 1.1 christos max = (1 << bits) - 1;
1104 1.1 christos min = 0;
1105 1.1 christos }
1106 1.1 christos
1107 1.1.1.6 christos test = val;
1108 1.1 christos
1109 1.1.1.6 christos if (test < (offsetT) min || test > (offsetT) max)
1110 1.1 christos return false;
1111 1.1 christos }
1112 1.1 christos return true;
1113 1.1 christos }
1114 1.1 christos
1115 1.1 christos /* Insert an operand value into an instruction. */
1116 1.1 christos
1117 1.1 christos static void
1118 1.1 christos mn10300_insert_operand (unsigned long *insnp,
1119 1.1 christos unsigned long *extensionp,
1120 1.1 christos const struct mn10300_operand *operand,
1121 1.1 christos offsetT val,
1122 1.1 christos char *file,
1123 1.1 christos unsigned int line,
1124 1.1 christos unsigned int shift)
1125 1.1 christos {
1126 1.1 christos /* No need to check 32bit operands for a bit. Note that
1127 1.1 christos MN10300_OPERAND_SPLIT is an implicit 32bit operand. */
1128 1.1 christos if (operand->bits != 32
1129 1.1 christos && (operand->flags & MN10300_OPERAND_SPLIT) == 0)
1130 1.1 christos {
1131 1.1 christos long min, max;
1132 1.1 christos offsetT test;
1133 1.1 christos int bits;
1134 1.1 christos
1135 1.1 christos bits = operand->bits;
1136 1.1 christos if (operand->flags & MN10300_OPERAND_24BIT)
1137 1.1 christos bits = 24;
1138 1.1 christos
1139 1.1 christos if ((operand->flags & MN10300_OPERAND_SIGNED) != 0)
1140 1.1 christos {
1141 1.1 christos max = (1 << (bits - 1)) - 1;
1142 1.1 christos min = - (1 << (bits - 1));
1143 1.1 christos }
1144 1.1 christos else
1145 1.1 christos {
1146 1.1 christos max = (1 << bits) - 1;
1147 1.1 christos min = 0;
1148 1.1 christos }
1149 1.1 christos
1150 1.1 christos test = val;
1151 1.1 christos
1152 1.1 christos if (test < (offsetT) min || test > (offsetT) max)
1153 1.1 christos as_warn_value_out_of_range (_("operand"), test, (offsetT) min, (offsetT) max, file, line);
1154 1.1 christos }
1155 1.1 christos
1156 1.1 christos if ((operand->flags & MN10300_OPERAND_SPLIT) != 0)
1157 1.1 christos {
1158 1.1 christos *insnp |= (val >> (32 - operand->bits)) & ((1 << operand->bits) - 1);
1159 1.1 christos *extensionp |= ((val & ((1 << (32 - operand->bits)) - 1))
1160 1.1 christos << operand->shift);
1161 1.1 christos }
1162 1.1 christos else if ((operand->flags & MN10300_OPERAND_24BIT) != 0)
1163 1.1 christos {
1164 1.1 christos *insnp |= (val >> (24 - operand->bits)) & ((1 << operand->bits) - 1);
1165 1.1 christos *extensionp |= ((val & ((1 << (24 - operand->bits)) - 1))
1166 1.1 christos << operand->shift);
1167 1.1 christos }
1168 1.1 christos else if ((operand->flags & (MN10300_OPERAND_FSREG | MN10300_OPERAND_FDREG)))
1169 1.1 christos {
1170 1.1 christos /* See devo/opcodes/m10300-opc.c just before #define FSM0 for an
1171 1.1 christos explanation of these variables. Note that FMT-implied shifts
1172 1.1 christos are not taken into account for FP registers. */
1173 1.1 christos unsigned long mask_low, mask_high;
1174 1.1 christos int shl_low, shr_high, shl_high;
1175 1.1 christos
1176 1.1 christos switch (operand->bits)
1177 1.1 christos {
1178 1.1 christos case 5:
1179 1.1 christos /* Handle regular FP registers. */
1180 1.1 christos if (operand->shift >= 0)
1181 1.1 christos {
1182 1.1 christos /* This is an `m' register. */
1183 1.1 christos shl_low = operand->shift;
1184 1.1 christos shl_high = 8 + (8 & shl_low) + (shl_low & 4) / 4;
1185 1.1 christos }
1186 1.1 christos else
1187 1.1 christos {
1188 1.1 christos /* This is an `n' register. */
1189 1.1 christos shl_low = -operand->shift;
1190 1.1 christos shl_high = shl_low / 4;
1191 1.1 christos }
1192 1.1 christos
1193 1.1 christos mask_low = 0x0f;
1194 1.1 christos mask_high = 0x10;
1195 1.1 christos shr_high = 4;
1196 1.1 christos break;
1197 1.1 christos
1198 1.1 christos case 3:
1199 1.1 christos /* Handle accumulators. */
1200 1.1 christos shl_low = -operand->shift;
1201 1.1 christos shl_high = 0;
1202 1.1 christos mask_low = 0x03;
1203 1.1 christos mask_high = 0x04;
1204 1.1 christos shr_high = 2;
1205 1.1 christos break;
1206 1.1 christos
1207 1.1 christos default:
1208 1.1 christos abort ();
1209 1.1 christos }
1210 1.1 christos *insnp |= ((((val & mask_high) >> shr_high) << shl_high)
1211 1.1 christos | ((val & mask_low) << shl_low));
1212 1.1 christos }
1213 1.1 christos else if ((operand->flags & MN10300_OPERAND_EXTENDED) == 0)
1214 1.1 christos {
1215 1.1 christos *insnp |= (((long) val & ((1 << operand->bits) - 1))
1216 1.1 christos << (operand->shift + shift));
1217 1.1 christos
1218 1.1 christos if ((operand->flags & MN10300_OPERAND_REPEATED) != 0)
1219 1.1 christos *insnp |= (((long) val & ((1 << operand->bits) - 1))
1220 1.1 christos << (operand->shift + shift + operand->bits));
1221 1.1 christos }
1222 1.1 christos else
1223 1.1 christos {
1224 1.1 christos *extensionp |= (((long) val & ((1 << operand->bits) - 1))
1225 1.1 christos << (operand->shift + shift));
1226 1.1 christos
1227 1.1 christos if ((operand->flags & MN10300_OPERAND_REPEATED) != 0)
1228 1.1 christos *extensionp |= (((long) val & ((1 << operand->bits) - 1))
1229 1.1 christos << (operand->shift + shift + operand->bits));
1230 1.1 christos }
1231 1.1 christos }
1232 1.1 christos
1233 1.1 christos void
1234 1.1 christos md_assemble (char *str)
1235 1.1 christos {
1236 1.1 christos char *s;
1237 1.1 christos struct mn10300_opcode *opcode;
1238 1.1 christos struct mn10300_opcode *next_opcode;
1239 1.1 christos const unsigned char *opindex_ptr;
1240 1.1 christos int next_opindex, relaxable;
1241 1.1 christos unsigned long insn, extension, size = 0;
1242 1.1 christos char *f;
1243 1.1 christos int i;
1244 1.1 christos int match;
1245 1.1 christos
1246 1.1 christos /* Get the opcode. */
1247 1.1 christos for (s = str; *s != '\0' && !ISSPACE (*s); s++)
1248 1.1 christos ;
1249 1.1 christos if (*s != '\0')
1250 1.1.1.6 christos *s++ = '\0';
1251 1.1 christos
1252 1.1 christos /* Find the first opcode with the proper name. */
1253 1.1 christos opcode = (struct mn10300_opcode *) str_hash_find (mn10300_hash, str);
1254 1.1 christos if (opcode == NULL)
1255 1.1 christos {
1256 1.1 christos as_bad (_("Unrecognized opcode: `%s'"), str);
1257 1.1 christos return;
1258 1.1 christos }
1259 1.1 christos
1260 1.1 christos str = s;
1261 1.1 christos while (ISSPACE (*str))
1262 1.1 christos ++str;
1263 1.1 christos
1264 1.1 christos input_line_pointer = str;
1265 1.1 christos
1266 1.1 christos for (;;)
1267 1.1 christos {
1268 1.1 christos const char *errmsg;
1269 1.1 christos int op_idx;
1270 1.1 christos char *hold;
1271 1.1 christos int extra_shift = 0;
1272 1.1 christos
1273 1.1 christos errmsg = _("Invalid opcode/operands");
1274 1.1 christos
1275 1.1 christos /* Reset the array of register operands. */
1276 1.1 christos memset (mn10300_reg_operands, -1, sizeof (mn10300_reg_operands));
1277 1.1 christos
1278 1.1 christos relaxable = 0;
1279 1.1 christos fc = 0;
1280 1.1 christos match = 0;
1281 1.1 christos next_opindex = 0;
1282 1.1 christos insn = opcode->opcode;
1283 1.1 christos extension = 0;
1284 1.1 christos
1285 1.1 christos /* If the instruction is not available on the current machine
1286 1.1 christos then it can not possibly match. */
1287 1.1 christos if (opcode->machine
1288 1.1 christos && !(opcode->machine == AM33_2 && HAVE_AM33_2)
1289 1.1 christos && !(opcode->machine == AM33 && HAVE_AM33)
1290 1.1 christos && !(opcode->machine == AM30 && HAVE_AM30))
1291 1.1 christos goto error;
1292 1.1 christos
1293 1.1 christos for (op_idx = 1, opindex_ptr = opcode->operands;
1294 1.1 christos *opindex_ptr != 0;
1295 1.1 christos opindex_ptr++, op_idx++)
1296 1.1 christos {
1297 1.1 christos const struct mn10300_operand *operand;
1298 1.1 christos expressionS ex;
1299 1.1 christos
1300 1.1 christos if (next_opindex == 0)
1301 1.1 christos {
1302 1.1 christos operand = &mn10300_operands[*opindex_ptr];
1303 1.1 christos }
1304 1.1 christos else
1305 1.1 christos {
1306 1.1 christos operand = &mn10300_operands[next_opindex];
1307 1.1 christos next_opindex = 0;
1308 1.1 christos }
1309 1.1 christos
1310 1.1 christos while (*str == ' ' || *str == ',')
1311 1.1 christos ++str;
1312 1.1 christos
1313 1.1 christos if (operand->flags & MN10300_OPERAND_RELAX)
1314 1.1 christos relaxable = 1;
1315 1.1 christos
1316 1.1 christos /* Gather the operand. */
1317 1.1 christos hold = input_line_pointer;
1318 1.1 christos input_line_pointer = str;
1319 1.1 christos
1320 1.1 christos if (operand->flags & MN10300_OPERAND_PAREN)
1321 1.1 christos {
1322 1.1 christos if (*input_line_pointer != ')' && *input_line_pointer != '(')
1323 1.1 christos {
1324 1.1 christos input_line_pointer = hold;
1325 1.1 christos str = hold;
1326 1.1 christos goto error;
1327 1.1 christos }
1328 1.1 christos input_line_pointer++;
1329 1.1 christos goto keep_going;
1330 1.1 christos }
1331 1.1 christos /* See if we can match the operands. */
1332 1.1 christos else if (operand->flags & MN10300_OPERAND_DREG)
1333 1.1 christos {
1334 1.1 christos if (!data_register_name (&ex))
1335 1.1 christos {
1336 1.1 christos input_line_pointer = hold;
1337 1.1 christos str = hold;
1338 1.1 christos goto error;
1339 1.1 christos }
1340 1.1 christos }
1341 1.1 christos else if (operand->flags & MN10300_OPERAND_AREG)
1342 1.1 christos {
1343 1.1 christos if (!address_register_name (&ex))
1344 1.1 christos {
1345 1.1 christos input_line_pointer = hold;
1346 1.1 christos str = hold;
1347 1.1 christos goto error;
1348 1.1 christos }
1349 1.1.1.2 christos }
1350 1.1.1.2 christos else if (operand->flags & MN10300_OPERAND_SP)
1351 1.1 christos {
1352 1.1 christos char *start;
1353 1.1 christos char c = get_symbol_name (&start);
1354 1.1.1.2 christos
1355 1.1 christos if (strcasecmp (start, "sp") != 0)
1356 1.1 christos {
1357 1.1 christos (void) restore_line_pointer (c);
1358 1.1 christos input_line_pointer = hold;
1359 1.1.1.2 christos str = hold;
1360 1.1 christos goto error;
1361 1.1 christos }
1362 1.1 christos (void) restore_line_pointer (c);
1363 1.1 christos goto keep_going;
1364 1.1 christos }
1365 1.1 christos else if (operand->flags & MN10300_OPERAND_RREG)
1366 1.1 christos {
1367 1.1 christos if (!r_register_name (&ex))
1368 1.1 christos {
1369 1.1 christos input_line_pointer = hold;
1370 1.1 christos str = hold;
1371 1.1 christos goto error;
1372 1.1 christos }
1373 1.1 christos }
1374 1.1 christos else if (operand->flags & MN10300_OPERAND_XRREG)
1375 1.1 christos {
1376 1.1 christos if (!xr_register_name (&ex))
1377 1.1 christos {
1378 1.1 christos input_line_pointer = hold;
1379 1.1 christos str = hold;
1380 1.1 christos goto error;
1381 1.1 christos }
1382 1.1 christos }
1383 1.1 christos else if (operand->flags & MN10300_OPERAND_FSREG)
1384 1.1 christos {
1385 1.1 christos if (!float_register_name (&ex))
1386 1.1 christos {
1387 1.1 christos input_line_pointer = hold;
1388 1.1 christos str = hold;
1389 1.1 christos goto error;
1390 1.1 christos }
1391 1.1 christos }
1392 1.1 christos else if (operand->flags & MN10300_OPERAND_FDREG)
1393 1.1 christos {
1394 1.1 christos if (!double_register_name (&ex))
1395 1.1 christos {
1396 1.1 christos input_line_pointer = hold;
1397 1.1 christos str = hold;
1398 1.1 christos goto error;
1399 1.1 christos }
1400 1.1.1.2 christos }
1401 1.1.1.2 christos else if (operand->flags & MN10300_OPERAND_FPCR)
1402 1.1 christos {
1403 1.1 christos char *start;
1404 1.1 christos char c = get_symbol_name (&start);
1405 1.1.1.2 christos
1406 1.1 christos if (strcasecmp (start, "fpcr") != 0)
1407 1.1 christos {
1408 1.1 christos (void) restore_line_pointer (c);
1409 1.1 christos input_line_pointer = hold;
1410 1.1.1.2 christos str = hold;
1411 1.1 christos goto error;
1412 1.1 christos }
1413 1.1 christos (void) restore_line_pointer (c);
1414 1.1 christos goto keep_going;
1415 1.1.1.2 christos }
1416 1.1.1.2 christos else if (operand->flags & MN10300_OPERAND_USP)
1417 1.1 christos {
1418 1.1 christos char *start;
1419 1.1 christos char c = get_symbol_name (&start);
1420 1.1.1.2 christos
1421 1.1 christos if (strcasecmp (start, "usp") != 0)
1422 1.1 christos {
1423 1.1 christos (void) restore_line_pointer (c);
1424 1.1 christos input_line_pointer = hold;
1425 1.1.1.2 christos str = hold;
1426 1.1 christos goto error;
1427 1.1 christos }
1428 1.1 christos (void) restore_line_pointer (c);
1429 1.1 christos goto keep_going;
1430 1.1.1.2 christos }
1431 1.1.1.2 christos else if (operand->flags & MN10300_OPERAND_SSP)
1432 1.1 christos {
1433 1.1 christos char *start;
1434 1.1 christos char c = get_symbol_name (&start);
1435 1.1.1.2 christos
1436 1.1 christos if (strcasecmp (start, "ssp") != 0)
1437 1.1 christos {
1438 1.1 christos (void) restore_line_pointer (c);
1439 1.1 christos input_line_pointer = hold;
1440 1.1.1.2 christos str = hold;
1441 1.1 christos goto error;
1442 1.1 christos }
1443 1.1 christos (void) restore_line_pointer (c);
1444 1.1 christos goto keep_going;
1445 1.1.1.2 christos }
1446 1.1.1.2 christos else if (operand->flags & MN10300_OPERAND_MSP)
1447 1.1 christos {
1448 1.1 christos char *start;
1449 1.1 christos char c = get_symbol_name (&start);
1450 1.1.1.2 christos
1451 1.1 christos if (strcasecmp (start, "msp") != 0)
1452 1.1 christos {
1453 1.1 christos (void) restore_line_pointer (c);
1454 1.1 christos input_line_pointer = hold;
1455 1.1.1.2 christos str = hold;
1456 1.1 christos goto error;
1457 1.1 christos }
1458 1.1 christos (void) restore_line_pointer (c);
1459 1.1 christos goto keep_going;
1460 1.1.1.2 christos }
1461 1.1.1.2 christos else if (operand->flags & MN10300_OPERAND_PC)
1462 1.1 christos {
1463 1.1 christos char *start;
1464 1.1 christos char c = get_symbol_name (&start);
1465 1.1.1.2 christos
1466 1.1 christos if (strcasecmp (start, "pc") != 0)
1467 1.1 christos {
1468 1.1 christos (void) restore_line_pointer (c);
1469 1.1 christos input_line_pointer = hold;
1470 1.1.1.2 christos str = hold;
1471 1.1 christos goto error;
1472 1.1 christos }
1473 1.1 christos (void) restore_line_pointer (c);
1474 1.1 christos goto keep_going;
1475 1.1.1.2 christos }
1476 1.1.1.2 christos else if (operand->flags & MN10300_OPERAND_EPSW)
1477 1.1 christos {
1478 1.1 christos char *start;
1479 1.1 christos char c = get_symbol_name (&start);
1480 1.1.1.2 christos
1481 1.1 christos if (strcasecmp (start, "epsw") != 0)
1482 1.1 christos {
1483 1.1 christos (void) restore_line_pointer (c);
1484 1.1 christos input_line_pointer = hold;
1485 1.1.1.2 christos str = hold;
1486 1.1 christos goto error;
1487 1.1 christos }
1488 1.1 christos (void) restore_line_pointer (c);
1489 1.1 christos goto keep_going;
1490 1.1 christos }
1491 1.1 christos else if (operand->flags & MN10300_OPERAND_PLUS)
1492 1.1 christos {
1493 1.1 christos if (*input_line_pointer != '+')
1494 1.1 christos {
1495 1.1 christos input_line_pointer = hold;
1496 1.1 christos str = hold;
1497 1.1 christos goto error;
1498 1.1 christos }
1499 1.1 christos input_line_pointer++;
1500 1.1 christos goto keep_going;
1501 1.1.1.2 christos }
1502 1.1.1.2 christos else if (operand->flags & MN10300_OPERAND_PSW)
1503 1.1 christos {
1504 1.1 christos char *start;
1505 1.1 christos char c = get_symbol_name (&start);
1506 1.1.1.2 christos
1507 1.1 christos if (strcasecmp (start, "psw") != 0)
1508 1.1 christos {
1509 1.1 christos (void) restore_line_pointer (c);
1510 1.1 christos input_line_pointer = hold;
1511 1.1.1.2 christos str = hold;
1512 1.1 christos goto error;
1513 1.1 christos }
1514 1.1 christos (void) restore_line_pointer (c);
1515 1.1 christos goto keep_going;
1516 1.1.1.2 christos }
1517 1.1.1.2 christos else if (operand->flags & MN10300_OPERAND_MDR)
1518 1.1 christos {
1519 1.1 christos char *start;
1520 1.1 christos char c = get_symbol_name (&start);
1521 1.1.1.2 christos
1522 1.1 christos if (strcasecmp (start, "mdr") != 0)
1523 1.1 christos {
1524 1.1 christos (void) restore_line_pointer (c);
1525 1.1 christos input_line_pointer = hold;
1526 1.1.1.2 christos str = hold;
1527 1.1 christos goto error;
1528 1.1 christos }
1529 1.1 christos (void) restore_line_pointer (c);
1530 1.1 christos goto keep_going;
1531 1.1 christos }
1532 1.1 christos else if (operand->flags & MN10300_OPERAND_REG_LIST)
1533 1.1 christos {
1534 1.1 christos unsigned int value = 0;
1535 1.1 christos if (*input_line_pointer != '[')
1536 1.1 christos {
1537 1.1 christos input_line_pointer = hold;
1538 1.1 christos str = hold;
1539 1.1 christos goto error;
1540 1.1 christos }
1541 1.1 christos
1542 1.1 christos /* Eat the '['. */
1543 1.1 christos input_line_pointer++;
1544 1.1 christos
1545 1.1 christos /* We used to reject a null register list here; however,
1546 1.1 christos we accept it now so the compiler can emit "call"
1547 1.1 christos instructions for all calls to named functions.
1548 1.1 christos
1549 1.1 christos The linker can then fill in the appropriate bits for the
1550 1.1 christos register list and stack size or change the instruction
1551 1.1 christos into a "calls" if using "call" is not profitable. */
1552 1.1 christos while (*input_line_pointer != ']')
1553 1.1 christos {
1554 1.1 christos char *start;
1555 1.1 christos char c;
1556 1.1 christos
1557 1.1.1.2 christos if (*input_line_pointer == ',')
1558 1.1 christos input_line_pointer++;
1559 1.1 christos
1560 1.1 christos c = get_symbol_name (&start);
1561 1.1 christos
1562 1.1.1.2 christos if (strcasecmp (start, "d2") == 0)
1563 1.1 christos {
1564 1.1 christos value |= 0x80;
1565 1.1 christos (void) restore_line_pointer (c);
1566 1.1 christos }
1567 1.1.1.2 christos else if (strcasecmp (start, "d3") == 0)
1568 1.1 christos {
1569 1.1 christos value |= 0x40;
1570 1.1 christos (void) restore_line_pointer (c);
1571 1.1 christos }
1572 1.1.1.2 christos else if (strcasecmp (start, "a2") == 0)
1573 1.1 christos {
1574 1.1 christos value |= 0x20;
1575 1.1 christos (void) restore_line_pointer (c);
1576 1.1 christos }
1577 1.1.1.2 christos else if (strcasecmp (start, "a3") == 0)
1578 1.1 christos {
1579 1.1 christos value |= 0x10;
1580 1.1 christos (void) restore_line_pointer (c);
1581 1.1 christos }
1582 1.1.1.2 christos else if (strcasecmp (start, "other") == 0)
1583 1.1 christos {
1584 1.1 christos value |= 0x08;
1585 1.1 christos (void) restore_line_pointer (c);
1586 1.1 christos }
1587 1.1 christos else if (HAVE_AM33
1588 1.1.1.2 christos && strcasecmp (start, "exreg0") == 0)
1589 1.1 christos {
1590 1.1 christos value |= 0x04;
1591 1.1 christos (void) restore_line_pointer (c);
1592 1.1 christos }
1593 1.1 christos else if (HAVE_AM33
1594 1.1.1.2 christos && strcasecmp (start, "exreg1") == 0)
1595 1.1 christos {
1596 1.1 christos value |= 0x02;
1597 1.1 christos (void) restore_line_pointer (c);
1598 1.1 christos }
1599 1.1 christos else if (HAVE_AM33
1600 1.1.1.2 christos && strcasecmp (start, "exother") == 0)
1601 1.1 christos {
1602 1.1 christos value |= 0x01;
1603 1.1 christos (void) restore_line_pointer (c);
1604 1.1 christos }
1605 1.1 christos else if (HAVE_AM33
1606 1.1.1.2 christos && strcasecmp (start, "all") == 0)
1607 1.1 christos {
1608 1.1 christos value |= 0xff;
1609 1.1 christos (void) restore_line_pointer (c);
1610 1.1 christos }
1611 1.1 christos else
1612 1.1 christos {
1613 1.1 christos input_line_pointer = hold;
1614 1.1 christos str = hold;
1615 1.1 christos goto error;
1616 1.1 christos }
1617 1.1 christos }
1618 1.1 christos input_line_pointer++;
1619 1.1 christos mn10300_insert_operand (& insn, & extension, operand,
1620 1.1 christos value, NULL, 0, 0);
1621 1.1 christos goto keep_going;
1622 1.1 christos
1623 1.1 christos }
1624 1.1 christos else if (data_register_name (&ex))
1625 1.1 christos {
1626 1.1 christos input_line_pointer = hold;
1627 1.1 christos str = hold;
1628 1.1 christos goto error;
1629 1.1 christos }
1630 1.1 christos else if (address_register_name (&ex))
1631 1.1 christos {
1632 1.1 christos input_line_pointer = hold;
1633 1.1 christos str = hold;
1634 1.1 christos goto error;
1635 1.1 christos }
1636 1.1 christos else if (other_register_name (&ex))
1637 1.1 christos {
1638 1.1 christos input_line_pointer = hold;
1639 1.1 christos str = hold;
1640 1.1 christos goto error;
1641 1.1 christos }
1642 1.1 christos else if (HAVE_AM33 && r_register_name (&ex))
1643 1.1 christos {
1644 1.1 christos input_line_pointer = hold;
1645 1.1 christos str = hold;
1646 1.1 christos goto error;
1647 1.1 christos }
1648 1.1 christos else if (HAVE_AM33 && xr_register_name (&ex))
1649 1.1 christos {
1650 1.1 christos input_line_pointer = hold;
1651 1.1 christos str = hold;
1652 1.1 christos goto error;
1653 1.1 christos }
1654 1.1 christos else if (HAVE_AM33_2 && float_register_name (&ex))
1655 1.1 christos {
1656 1.1 christos input_line_pointer = hold;
1657 1.1 christos str = hold;
1658 1.1 christos goto error;
1659 1.1 christos }
1660 1.1 christos else if (HAVE_AM33_2 && double_register_name (&ex))
1661 1.1 christos {
1662 1.1 christos input_line_pointer = hold;
1663 1.1 christos str = hold;
1664 1.1 christos goto error;
1665 1.1 christos }
1666 1.1 christos else if (*str == ')' || *str == '(')
1667 1.1 christos {
1668 1.1 christos input_line_pointer = hold;
1669 1.1 christos str = hold;
1670 1.1 christos goto error;
1671 1.1 christos }
1672 1.1 christos else
1673 1.1 christos {
1674 1.1 christos expression (&ex);
1675 1.1 christos }
1676 1.1 christos
1677 1.1 christos switch (ex.X_op)
1678 1.1 christos {
1679 1.1 christos case O_illegal:
1680 1.1 christos errmsg = _("illegal operand");
1681 1.1 christos goto error;
1682 1.1 christos case O_absent:
1683 1.1 christos errmsg = _("missing operand");
1684 1.1 christos goto error;
1685 1.1 christos case O_register:
1686 1.1 christos {
1687 1.1 christos int mask;
1688 1.1 christos
1689 1.1 christos mask = MN10300_OPERAND_DREG | MN10300_OPERAND_AREG;
1690 1.1 christos if (HAVE_AM33)
1691 1.1 christos mask |= MN10300_OPERAND_RREG | MN10300_OPERAND_XRREG;
1692 1.1 christos if (HAVE_AM33_2)
1693 1.1 christos mask |= MN10300_OPERAND_FSREG | MN10300_OPERAND_FDREG;
1694 1.1 christos if ((operand->flags & mask) == 0)
1695 1.1 christos {
1696 1.1 christos input_line_pointer = hold;
1697 1.1 christos str = hold;
1698 1.1 christos goto error;
1699 1.1 christos }
1700 1.1 christos
1701 1.1 christos if (opcode->format == FMT_D1 || opcode->format == FMT_S1)
1702 1.1 christos extra_shift = 8;
1703 1.1 christos else if (opcode->format == FMT_D2
1704 1.1 christos || opcode->format == FMT_D4
1705 1.1 christos || opcode->format == FMT_S2
1706 1.1 christos || opcode->format == FMT_S4
1707 1.1 christos || opcode->format == FMT_S6
1708 1.1 christos || opcode->format == FMT_D5)
1709 1.1 christos extra_shift = 16;
1710 1.1 christos else if (opcode->format == FMT_D7)
1711 1.1 christos extra_shift = 8;
1712 1.1 christos else if (opcode->format == FMT_D8 || opcode->format == FMT_D9)
1713 1.1 christos extra_shift = 8;
1714 1.1 christos else
1715 1.1 christos extra_shift = 0;
1716 1.1 christos
1717 1.1 christos mn10300_insert_operand (& insn, & extension, operand,
1718 1.1 christos ex.X_add_number, NULL,
1719 1.1 christos 0, extra_shift);
1720 1.1 christos
1721 1.1 christos /* And note the register number in the register array. */
1722 1.1 christos mn10300_reg_operands[op_idx - 1] = ex.X_add_number;
1723 1.1 christos break;
1724 1.1 christos }
1725 1.1 christos
1726 1.1 christos case O_constant:
1727 1.1 christos /* If this operand can be promoted, and it doesn't
1728 1.1 christos fit into the allocated bitfield for this insn,
1729 1.1 christos then promote it (ie this opcode does not match). */
1730 1.1 christos if (operand->flags
1731 1.1 christos & (MN10300_OPERAND_PROMOTE | MN10300_OPERAND_RELAX)
1732 1.1 christos && !check_operand (operand, ex.X_add_number))
1733 1.1 christos {
1734 1.1 christos input_line_pointer = hold;
1735 1.1 christos str = hold;
1736 1.1 christos goto error;
1737 1.1 christos }
1738 1.1 christos
1739 1.1 christos mn10300_insert_operand (& insn, & extension, operand,
1740 1.1 christos ex.X_add_number, NULL, 0, 0);
1741 1.1 christos break;
1742 1.1 christos
1743 1.1 christos default:
1744 1.1 christos /* If this operand can be promoted, then this opcode didn't
1745 1.1 christos match since we can't know if it needed promotion! */
1746 1.1 christos if (operand->flags & MN10300_OPERAND_PROMOTE)
1747 1.1 christos {
1748 1.1 christos input_line_pointer = hold;
1749 1.1 christos str = hold;
1750 1.1 christos goto error;
1751 1.1 christos }
1752 1.1 christos
1753 1.1 christos /* We need to generate a fixup for this expression. */
1754 1.1 christos if (fc >= MAX_INSN_FIXUPS)
1755 1.1 christos as_fatal (_("too many fixups"));
1756 1.1 christos fixups[fc].exp = ex;
1757 1.1 christos fixups[fc].opindex = *opindex_ptr;
1758 1.1 christos fixups[fc].reloc = BFD_RELOC_UNUSED;
1759 1.1 christos if (mn10300_check_fixup (& fixups[fc]))
1760 1.1 christos goto error;
1761 1.1 christos ++fc;
1762 1.1.1.6 christos break;
1763 1.1 christos }
1764 1.1 christos
1765 1.1 christos keep_going:
1766 1.1 christos str = input_line_pointer;
1767 1.1 christos input_line_pointer = hold;
1768 1.1 christos
1769 1.1 christos while (*str == ' ' || *str == ',')
1770 1.1 christos ++str;
1771 1.1 christos }
1772 1.1 christos
1773 1.1 christos /* Make sure we used all the operands! */
1774 1.1 christos if (*str != ',')
1775 1.1 christos match = 1;
1776 1.1 christos
1777 1.1 christos /* If this instruction has registers that must not match, verify
1778 1.1 christos that they do indeed not match. */
1779 1.1 christos if (opcode->no_match_operands)
1780 1.1 christos {
1781 1.1 christos /* Look at each operand to see if it's marked. */
1782 1.1 christos for (i = 0; i < MN10300_MAX_OPERANDS; i++)
1783 1.1 christos {
1784 1.1 christos if ((1 << i) & opcode->no_match_operands)
1785 1.1 christos {
1786 1.1 christos int j;
1787 1.1 christos
1788 1.1 christos /* operand I is marked. Check that it does not match any
1789 1.1 christos operands > I which are marked. */
1790 1.1 christos for (j = i + 1; j < MN10300_MAX_OPERANDS; j++)
1791 1.1 christos {
1792 1.1 christos if (((1 << j) & opcode->no_match_operands)
1793 1.1 christos && mn10300_reg_operands[i] == mn10300_reg_operands[j])
1794 1.1 christos {
1795 1.1 christos errmsg = _("Invalid register specification.");
1796 1.1 christos match = 0;
1797 1.1 christos goto error;
1798 1.1 christos }
1799 1.1 christos }
1800 1.1 christos }
1801 1.1 christos }
1802 1.1 christos }
1803 1.1 christos
1804 1.1 christos error:
1805 1.1 christos if (match == 0)
1806 1.1 christos {
1807 1.1 christos next_opcode = opcode + 1;
1808 1.1 christos if (!strcmp (next_opcode->name, opcode->name))
1809 1.1 christos {
1810 1.1 christos opcode = next_opcode;
1811 1.1 christos continue;
1812 1.1 christos }
1813 1.1 christos
1814 1.1 christos as_bad ("%s", errmsg);
1815 1.1 christos return;
1816 1.1 christos }
1817 1.1 christos break;
1818 1.1 christos }
1819 1.1 christos
1820 1.1 christos while (ISSPACE (*str))
1821 1.1 christos ++str;
1822 1.1 christos
1823 1.1 christos if (*str != '\0')
1824 1.1 christos as_bad (_("junk at end of line: `%s'"), str);
1825 1.1 christos
1826 1.1 christos input_line_pointer = str;
1827 1.1 christos
1828 1.1 christos /* Determine the size of the instruction. */
1829 1.1 christos if (opcode->format == FMT_S0)
1830 1.1 christos size = 1;
1831 1.1 christos
1832 1.1 christos if (opcode->format == FMT_S1 || opcode->format == FMT_D0)
1833 1.1 christos size = 2;
1834 1.1 christos
1835 1.1 christos if (opcode->format == FMT_S2 || opcode->format == FMT_D1)
1836 1.1 christos size = 3;
1837 1.1 christos
1838 1.1 christos if (opcode->format == FMT_D6)
1839 1.1 christos size = 3;
1840 1.1 christos
1841 1.1 christos if (opcode->format == FMT_D7 || opcode->format == FMT_D10)
1842 1.1 christos size = 4;
1843 1.1 christos
1844 1.1 christos if (opcode->format == FMT_D8)
1845 1.1 christos size = 6;
1846 1.1 christos
1847 1.1 christos if (opcode->format == FMT_D9)
1848 1.1 christos size = 7;
1849 1.1 christos
1850 1.1 christos if (opcode->format == FMT_S4)
1851 1.1 christos size = 5;
1852 1.1 christos
1853 1.1 christos if (opcode->format == FMT_S6 || opcode->format == FMT_D5)
1854 1.1 christos size = 7;
1855 1.1 christos
1856 1.1 christos if (opcode->format == FMT_D2)
1857 1.1 christos size = 4;
1858 1.1 christos
1859 1.1 christos if (opcode->format == FMT_D3)
1860 1.1 christos size = 5;
1861 1.1 christos
1862 1.1 christos if (opcode->format == FMT_D4)
1863 1.1 christos size = 6;
1864 1.1 christos
1865 1.1 christos if (relaxable && fc > 0)
1866 1.1 christos {
1867 1.1 christos /* On a 64-bit host the size of an 'int' is not the same
1868 1.1.1.4 christos as the size of a pointer, so we need a union to convert
1869 1.1 christos the opindex field of the fr_cgen structure into a char *
1870 1.1 christos so that it can be stored in the frag. We do not have
1871 1.1 christos to worry about losing accuracy as we are not going to
1872 1.1 christos be even close to the 32bit limit of the int. */
1873 1.1 christos union
1874 1.1 christos {
1875 1.1 christos int opindex;
1876 1.1 christos char * ptr;
1877 1.1 christos }
1878 1.1 christos opindex_converter;
1879 1.1 christos int type;
1880 1.1 christos
1881 1.1 christos /* We want to anchor the line info to the previous frag (if
1882 1.1 christos there isn't one, create it), so that, when the insn is
1883 1.1 christos resized, we still get the right address for the beginning of
1884 1.1 christos the region. */
1885 1.1 christos f = frag_more (0);
1886 1.1 christos dwarf2_emit_insn (0);
1887 1.1 christos
1888 1.1 christos /* bCC */
1889 1.1 christos if (size == 2)
1890 1.1 christos {
1891 1.1 christos /* Handle bra specially. Basically treat it like jmp so
1892 1.1 christos that we automatically handle 8, 16 and 32 bit offsets
1893 1.1 christos correctly as well as jumps to an undefined address.
1894 1.1 christos
1895 1.1 christos It is also important to not treat it like other bCC
1896 1.1 christos instructions since the long forms of bra is different
1897 1.1 christos from other bCC instructions. */
1898 1.1 christos if (opcode->opcode == 0xca00)
1899 1.1 christos type = 10;
1900 1.1 christos else
1901 1.1 christos type = 0;
1902 1.1 christos }
1903 1.1 christos /* call */
1904 1.1 christos else if (size == 5)
1905 1.1 christos type = 6;
1906 1.1 christos /* calls */
1907 1.1 christos else if (size == 4)
1908 1.1 christos type = 8;
1909 1.1 christos /* jmp */
1910 1.1 christos else if (size == 3 && opcode->opcode == 0xcc0000)
1911 1.1 christos type = 10;
1912 1.1 christos else if (size == 3 && (opcode->opcode & 0xfff000) == 0xf8d000)
1913 1.1 christos type = 13;
1914 1.1 christos /* bCC (uncommon cases) */
1915 1.1 christos else
1916 1.1 christos type = 3;
1917 1.1 christos
1918 1.1 christos opindex_converter.opindex = fixups[0].opindex;
1919 1.1 christos f = frag_var (rs_machine_dependent, 8, 8 - size, type,
1920 1.1 christos fixups[0].exp.X_add_symbol,
1921 1.1 christos fixups[0].exp.X_add_number,
1922 1.1 christos opindex_converter.ptr);
1923 1.1 christos
1924 1.1 christos /* This is pretty hokey. We basically just care about the
1925 1.1 christos opcode, so we have to write out the first word big endian.
1926 1.1 christos
1927 1.1 christos The exception is "call", which has two operands that we
1928 1.1 christos care about.
1929 1.1 christos
1930 1.1 christos The first operand (the register list) happens to be in the
1931 1.1 christos first instruction word, and will be in the right place if
1932 1.1 christos we output the first word in big endian mode.
1933 1.1 christos
1934 1.1 christos The second operand (stack size) is in the extension word,
1935 1.1 christos and we want it to appear as the first character in the extension
1936 1.1 christos word (as it appears in memory). Luckily, writing the extension
1937 1.1 christos word in big endian format will do what we want. */
1938 1.1 christos number_to_chars_bigendian (f, insn, size > 4 ? 4 : size);
1939 1.1 christos if (size > 8)
1940 1.1 christos {
1941 1.1 christos number_to_chars_bigendian (f + 4, extension, 4);
1942 1.1 christos number_to_chars_bigendian (f + 8, 0, size - 8);
1943 1.1 christos }
1944 1.1 christos else if (size > 4)
1945 1.1 christos number_to_chars_bigendian (f + 4, extension, size - 4);
1946 1.1 christos }
1947 1.1 christos else
1948 1.1 christos {
1949 1.1 christos /* Allocate space for the instruction. */
1950 1.1 christos f = frag_more (size);
1951 1.1 christos
1952 1.1 christos /* Fill in bytes for the instruction. Note that opcode fields
1953 1.1 christos are written big-endian, 16 & 32bit immediates are written
1954 1.1 christos little endian. Egad. */
1955 1.1 christos if (opcode->format == FMT_S0
1956 1.1 christos || opcode->format == FMT_S1
1957 1.1 christos || opcode->format == FMT_D0
1958 1.1 christos || opcode->format == FMT_D6
1959 1.1 christos || opcode->format == FMT_D7
1960 1.1 christos || opcode->format == FMT_D10
1961 1.1 christos || opcode->format == FMT_D1)
1962 1.1 christos {
1963 1.1 christos number_to_chars_bigendian (f, insn, size);
1964 1.1 christos }
1965 1.1 christos else if (opcode->format == FMT_S2
1966 1.1 christos && opcode->opcode != 0xdf0000
1967 1.1 christos && opcode->opcode != 0xde0000)
1968 1.1 christos {
1969 1.1 christos /* A format S2 instruction that is _not_ "ret" and "retf". */
1970 1.1 christos number_to_chars_bigendian (f, (insn >> 16) & 0xff, 1);
1971 1.1 christos number_to_chars_littleendian (f + 1, insn & 0xffff, 2);
1972 1.1 christos }
1973 1.1 christos else if (opcode->format == FMT_S2)
1974 1.1 christos {
1975 1.1 christos /* This must be a ret or retf, which is written entirely in
1976 1.1 christos big-endian format. */
1977 1.1 christos number_to_chars_bigendian (f, insn, 3);
1978 1.1 christos }
1979 1.1 christos else if (opcode->format == FMT_S4
1980 1.1 christos && opcode->opcode != 0xdc000000)
1981 1.1 christos {
1982 1.1 christos /* This must be a format S4 "call" instruction. What a pain. */
1983 1.1 christos unsigned long temp = (insn >> 8) & 0xffff;
1984 1.1 christos number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
1985 1.1 christos number_to_chars_littleendian (f + 1, temp, 2);
1986 1.1 christos number_to_chars_bigendian (f + 3, insn & 0xff, 1);
1987 1.1 christos number_to_chars_bigendian (f + 4, extension & 0xff, 1);
1988 1.1 christos }
1989 1.1 christos else if (opcode->format == FMT_S4)
1990 1.1 christos {
1991 1.1 christos /* This must be a format S4 "jmp" instruction. */
1992 1.1 christos unsigned long temp = ((insn & 0xffffff) << 8) | (extension & 0xff);
1993 1.1 christos number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
1994 1.1 christos number_to_chars_littleendian (f + 1, temp, 4);
1995 1.1 christos }
1996 1.1 christos else if (opcode->format == FMT_S6)
1997 1.1 christos {
1998 1.1 christos unsigned long temp = ((insn & 0xffffff) << 8)
1999 1.1 christos | ((extension >> 16) & 0xff);
2000 1.1 christos number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
2001 1.1 christos number_to_chars_littleendian (f + 1, temp, 4);
2002 1.1 christos number_to_chars_bigendian (f + 5, (extension >> 8) & 0xff, 1);
2003 1.1 christos number_to_chars_bigendian (f + 6, extension & 0xff, 1);
2004 1.1 christos }
2005 1.1 christos else if (opcode->format == FMT_D2
2006 1.1 christos && opcode->opcode != 0xfaf80000
2007 1.1 christos && opcode->opcode != 0xfaf00000
2008 1.1 christos && opcode->opcode != 0xfaf40000)
2009 1.1 christos {
2010 1.1 christos /* A format D2 instruction where the 16bit immediate is
2011 1.1 christos really a single 16bit value, not two 8bit values. */
2012 1.1 christos number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
2013 1.1 christos number_to_chars_littleendian (f + 2, insn & 0xffff, 2);
2014 1.1 christos }
2015 1.1 christos else if (opcode->format == FMT_D2)
2016 1.1 christos {
2017 1.1 christos /* A format D2 instruction where the 16bit immediate
2018 1.1 christos is really two 8bit immediates. */
2019 1.1 christos number_to_chars_bigendian (f, insn, 4);
2020 1.1 christos }
2021 1.1 christos else if (opcode->format == FMT_D3)
2022 1.1 christos {
2023 1.1 christos number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
2024 1.1 christos number_to_chars_littleendian (f + 2, insn & 0xffff, 2);
2025 1.1 christos number_to_chars_bigendian (f + 4, extension & 0xff, 1);
2026 1.1 christos }
2027 1.1 christos else if (opcode->format == FMT_D4)
2028 1.1 christos {
2029 1.1 christos unsigned long temp = ((insn & 0xffff) << 16) | (extension & 0xffff);
2030 1.1 christos
2031 1.1 christos number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
2032 1.1 christos number_to_chars_littleendian (f + 2, temp, 4);
2033 1.1 christos }
2034 1.1 christos else if (opcode->format == FMT_D5)
2035 1.1 christos {
2036 1.1 christos unsigned long temp = (((insn & 0xffff) << 16)
2037 1.1 christos | ((extension >> 8) & 0xffff));
2038 1.1 christos
2039 1.1 christos number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
2040 1.1 christos number_to_chars_littleendian (f + 2, temp, 4);
2041 1.1 christos number_to_chars_bigendian (f + 6, extension & 0xff, 1);
2042 1.1 christos }
2043 1.1 christos else if (opcode->format == FMT_D8)
2044 1.1 christos {
2045 1.1 christos unsigned long temp = ((insn & 0xff) << 16) | (extension & 0xffff);
2046 1.1 christos
2047 1.1 christos number_to_chars_bigendian (f, (insn >> 8) & 0xffffff, 3);
2048 1.1 christos number_to_chars_bigendian (f + 3, (temp & 0xff), 1);
2049 1.1 christos number_to_chars_littleendian (f + 4, temp >> 8, 2);
2050 1.1 christos }
2051 1.1 christos else if (opcode->format == FMT_D9)
2052 1.1 christos {
2053 1.1 christos unsigned long temp = ((insn & 0xff) << 24) | (extension & 0xffffff);
2054 1.1 christos
2055 1.1 christos number_to_chars_bigendian (f, (insn >> 8) & 0xffffff, 3);
2056 1.1 christos number_to_chars_littleendian (f + 3, temp, 4);
2057 1.1 christos }
2058 1.1 christos
2059 1.1 christos /* Create any fixups. */
2060 1.1 christos for (i = 0; i < fc; i++)
2061 1.1 christos {
2062 1.1 christos const struct mn10300_operand *operand;
2063 1.1 christos int reloc_size;
2064 1.1 christos
2065 1.1 christos operand = &mn10300_operands[fixups[i].opindex];
2066 1.1 christos if (fixups[i].reloc != BFD_RELOC_UNUSED
2067 1.1 christos && fixups[i].reloc != BFD_RELOC_32_GOT_PCREL
2068 1.1 christos && fixups[i].reloc != BFD_RELOC_32_GOTOFF
2069 1.1 christos && fixups[i].reloc != BFD_RELOC_32_PLT_PCREL
2070 1.1 christos && fixups[i].reloc != BFD_RELOC_MN10300_TLS_GD
2071 1.1 christos && fixups[i].reloc != BFD_RELOC_MN10300_TLS_LD
2072 1.1 christos && fixups[i].reloc != BFD_RELOC_MN10300_TLS_LDO
2073 1.1 christos && fixups[i].reloc != BFD_RELOC_MN10300_TLS_GOTIE
2074 1.1 christos && fixups[i].reloc != BFD_RELOC_MN10300_TLS_IE
2075 1.1 christos && fixups[i].reloc != BFD_RELOC_MN10300_TLS_LE
2076 1.1 christos && fixups[i].reloc != BFD_RELOC_MN10300_GOT32)
2077 1.1 christos {
2078 1.1 christos reloc_howto_type *reloc_howto;
2079 1.1 christos int offset;
2080 1.1 christos
2081 1.1 christos reloc_howto = bfd_reloc_type_lookup (stdoutput,
2082 1.1 christos fixups[i].reloc);
2083 1.1 christos
2084 1.1 christos if (!reloc_howto)
2085 1.1 christos abort ();
2086 1.1 christos
2087 1.1 christos reloc_size = bfd_get_reloc_size (reloc_howto);
2088 1.1 christos
2089 1.1 christos if (reloc_size < 1 || reloc_size > 4)
2090 1.1 christos abort ();
2091 1.1 christos
2092 1.1 christos offset = 4 - size;
2093 1.1 christos fix_new_exp (frag_now, f - frag_now->fr_literal + offset,
2094 1.1 christos reloc_size, &fixups[i].exp,
2095 1.1 christos reloc_howto->pc_relative,
2096 1.1 christos fixups[i].reloc);
2097 1.1 christos }
2098 1.1 christos else
2099 1.1 christos {
2100 1.1 christos int reloc, pcrel, offset;
2101 1.1 christos fixS *fixP;
2102 1.1 christos
2103 1.1 christos reloc = BFD_RELOC_NONE;
2104 1.1 christos if (fixups[i].reloc != BFD_RELOC_UNUSED)
2105 1.1 christos reloc = fixups[i].reloc;
2106 1.1 christos /* How big is the reloc? Remember SPLIT relocs are
2107 1.1 christos implicitly 32bits. */
2108 1.1 christos if ((operand->flags & MN10300_OPERAND_SPLIT) != 0)
2109 1.1 christos reloc_size = 32;
2110 1.1 christos else if ((operand->flags & MN10300_OPERAND_24BIT) != 0)
2111 1.1 christos reloc_size = 24;
2112 1.1 christos else
2113 1.1 christos reloc_size = operand->bits;
2114 1.1 christos
2115 1.1 christos /* Is the reloc pc-relative? */
2116 1.1 christos pcrel = (operand->flags & MN10300_OPERAND_PCREL) != 0;
2117 1.1 christos if (reloc != BFD_RELOC_NONE)
2118 1.1 christos pcrel = bfd_reloc_type_lookup (stdoutput, reloc)->pc_relative;
2119 1.1 christos
2120 1.1 christos offset = size - (reloc_size + operand->shift) / 8;
2121 1.1 christos
2122 1.1 christos /* Choose a proper BFD relocation type. */
2123 1.1 christos if (reloc != BFD_RELOC_NONE)
2124 1.1 christos ;
2125 1.1 christos else if (pcrel)
2126 1.1 christos {
2127 1.1 christos if (reloc_size == 32)
2128 1.1 christos reloc = BFD_RELOC_32_PCREL;
2129 1.1 christos else if (reloc_size == 16)
2130 1.1 christos reloc = BFD_RELOC_16_PCREL;
2131 1.1 christos else if (reloc_size == 8)
2132 1.1 christos reloc = BFD_RELOC_8_PCREL;
2133 1.1 christos else
2134 1.1 christos abort ();
2135 1.1 christos }
2136 1.1 christos else
2137 1.1 christos {
2138 1.1 christos if (reloc_size == 32)
2139 1.1 christos reloc = BFD_RELOC_32;
2140 1.1 christos else if (reloc_size == 16)
2141 1.1 christos reloc = BFD_RELOC_16;
2142 1.1 christos else if (reloc_size == 8)
2143 1.1 christos reloc = BFD_RELOC_8;
2144 1.1 christos else
2145 1.1 christos abort ();
2146 1.1 christos }
2147 1.1 christos
2148 1.1 christos fixP = fix_new_exp (frag_now, f - frag_now->fr_literal + offset,
2149 1.1 christos reloc_size / 8, &fixups[i].exp, pcrel,
2150 1.1 christos ((bfd_reloc_code_real_type) reloc));
2151 1.1 christos
2152 1.1 christos if (pcrel)
2153 1.1 christos fixP->fx_offset += offset;
2154 1.1 christos }
2155 1.1 christos }
2156 1.1 christos
2157 1.1 christos dwarf2_emit_insn (size);
2158 1.1.1.6 christos }
2159 1.1 christos
2160 1.1 christos /* Label this frag as one that contains instructions. */
2161 1.1 christos frag_now->tc_frag_data = true;
2162 1.1 christos }
2163 1.1 christos
2164 1.1 christos /* If while processing a fixup, a reloc really needs to be created
2165 1.1 christos then it is done here. */
2166 1.1 christos
2167 1.1 christos arelent **
2168 1.1 christos tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp)
2169 1.1 christos {
2170 1.1 christos static arelent * no_relocs = NULL;
2171 1.1.1.3 christos static arelent * relocs[MAX_RELOC_EXPANSION + 1];
2172 1.1 christos arelent *reloc;
2173 1.1 christos
2174 1.1 christos reloc = XNEW (arelent);
2175 1.1 christos
2176 1.1 christos reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
2177 1.1 christos if (reloc->howto == NULL)
2178 1.1 christos {
2179 1.1 christos as_bad_where (fixp->fx_file, fixp->fx_line,
2180 1.1 christos _("reloc %d not supported by object file format"),
2181 1.1 christos (int) fixp->fx_r_type);
2182 1.1 christos free (reloc);
2183 1.1 christos return & no_relocs;
2184 1.1 christos }
2185 1.1 christos
2186 1.1 christos reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2187 1.1 christos relocs[0] = reloc;
2188 1.1 christos relocs[1] = NULL;
2189 1.1 christos
2190 1.1 christos if (fixp->fx_subsy
2191 1.1 christos && S_GET_SEGMENT (fixp->fx_subsy) == absolute_section)
2192 1.1 christos {
2193 1.1 christos fixp->fx_offset -= S_GET_VALUE (fixp->fx_subsy);
2194 1.1 christos fixp->fx_subsy = NULL;
2195 1.1 christos }
2196 1.1 christos
2197 1.1 christos if (fixp->fx_addsy && fixp->fx_subsy)
2198 1.1 christos {
2199 1.1 christos asection *asec, *ssec;
2200 1.1 christos
2201 1.1 christos asec = S_GET_SEGMENT (fixp->fx_addsy);
2202 1.1 christos ssec = S_GET_SEGMENT (fixp->fx_subsy);
2203 1.1 christos
2204 1.1 christos /* If we have a difference between two (non-absolute) symbols we must
2205 1.1 christos generate two relocs (one for each symbol) and allow the linker to
2206 1.1 christos resolve them - relaxation may change the distances between symbols,
2207 1.1.1.3 christos even local symbols defined in the same section. */
2208 1.1 christos if (ssec != absolute_section || asec != absolute_section)
2209 1.1 christos {
2210 1.1 christos arelent * reloc2 = XNEW (arelent);
2211 1.1 christos
2212 1.1 christos relocs[0] = reloc2;
2213 1.1 christos relocs[1] = reloc;
2214 1.1 christos
2215 1.1.1.3 christos reloc2->address = reloc->address;
2216 1.1 christos reloc2->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_MN10300_SYM_DIFF);
2217 1.1 christos reloc2->addend = - S_GET_VALUE (fixp->fx_subsy);
2218 1.1.1.2 christos reloc2->sym_ptr_ptr = XNEW (asymbol *);
2219 1.1 christos *reloc2->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_subsy);
2220 1.1 christos
2221 1.1 christos reloc->addend = fixp->fx_offset;
2222 1.1 christos if (asec == absolute_section)
2223 1.1 christos {
2224 1.1 christos reloc->addend += S_GET_VALUE (fixp->fx_addsy);
2225 1.1 christos reloc->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
2226 1.1.1.3 christos }
2227 1.1 christos else
2228 1.1 christos {
2229 1.1 christos reloc->sym_ptr_ptr = XNEW (asymbol *);
2230 1.1 christos *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2231 1.1 christos }
2232 1.1 christos
2233 1.1 christos fixp->fx_pcrel = 0;
2234 1.1 christos fixp->fx_done = 1;
2235 1.1 christos return relocs;
2236 1.1 christos }
2237 1.1 christos else
2238 1.1 christos {
2239 1.1 christos char *fixpos = fixp->fx_where + fixp->fx_frag->fr_literal;
2240 1.1 christos
2241 1.1 christos reloc->addend = (S_GET_VALUE (fixp->fx_addsy)
2242 1.1 christos - S_GET_VALUE (fixp->fx_subsy) + fixp->fx_offset);
2243 1.1 christos
2244 1.1 christos switch (fixp->fx_r_type)
2245 1.1 christos {
2246 1.1 christos case BFD_RELOC_8:
2247 1.1 christos md_number_to_chars (fixpos, reloc->addend, 1);
2248 1.1 christos break;
2249 1.1 christos
2250 1.1 christos case BFD_RELOC_16:
2251 1.1 christos md_number_to_chars (fixpos, reloc->addend, 2);
2252 1.1 christos break;
2253 1.1 christos
2254 1.1 christos case BFD_RELOC_24:
2255 1.1 christos md_number_to_chars (fixpos, reloc->addend, 3);
2256 1.1 christos break;
2257 1.1 christos
2258 1.1 christos case BFD_RELOC_32:
2259 1.1 christos md_number_to_chars (fixpos, reloc->addend, 4);
2260 1.1 christos break;
2261 1.1 christos
2262 1.1 christos default:
2263 1.1 christos reloc->sym_ptr_ptr
2264 1.1 christos = (asymbol **) bfd_abs_section_ptr->symbol_ptr_ptr;
2265 1.1 christos return relocs;
2266 1.1 christos }
2267 1.1 christos
2268 1.1 christos free (reloc);
2269 1.1 christos return & no_relocs;
2270 1.1 christos }
2271 1.1.1.3 christos }
2272 1.1 christos else
2273 1.1 christos {
2274 1.1 christos reloc->sym_ptr_ptr = XNEW (asymbol *);
2275 1.1 christos *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2276 1.1 christos reloc->addend = fixp->fx_offset;
2277 1.1 christos }
2278 1.1 christos return relocs;
2279 1.1 christos }
2280 1.1 christos
2281 1.1.1.6 christos /* Returns true iff the symbol attached to the frag is at a known location
2282 1.1 christos in the given section, (and hence the relocation to it can be relaxed by
2283 1.1 christos the assembler). */
2284 1.1 christos static inline bool
2285 1.1.1.2 christos has_known_symbol_location (fragS * fragp, asection * sec)
2286 1.1 christos {
2287 1.1 christos symbolS * sym = fragp->fr_symbol;
2288 1.1 christos
2289 1.1 christos return sym != NULL
2290 1.1 christos && S_IS_DEFINED (sym)
2291 1.1 christos && ! S_IS_WEAK (sym)
2292 1.1 christos && S_GET_SEGMENT (sym) == sec;
2293 1.1 christos }
2294 1.1 christos
2295 1.1 christos int
2296 1.1 christos md_estimate_size_before_relax (fragS *fragp, asection *seg)
2297 1.1 christos {
2298 1.1 christos if (fragp->fr_subtype == 6
2299 1.1 christos && ! has_known_symbol_location (fragp, seg))
2300 1.1 christos fragp->fr_subtype = 7;
2301 1.1 christos else if (fragp->fr_subtype == 8
2302 1.1 christos && ! has_known_symbol_location (fragp, seg))
2303 1.1 christos fragp->fr_subtype = 9;
2304 1.1 christos else if (fragp->fr_subtype == 10
2305 1.1 christos && ! has_known_symbol_location (fragp, seg))
2306 1.1 christos fragp->fr_subtype = 12;
2307 1.1 christos
2308 1.1 christos if (fragp->fr_subtype == 13)
2309 1.1 christos return 3;
2310 1.1 christos
2311 1.1 christos if (fragp->fr_subtype >= sizeof (md_relax_table) / sizeof (md_relax_table[0]))
2312 1.1 christos abort ();
2313 1.1 christos
2314 1.1 christos return md_relax_table[fragp->fr_subtype].rlx_length;
2315 1.1 christos }
2316 1.1 christos
2317 1.1 christos long
2318 1.1 christos md_pcrel_from (fixS *fixp)
2319 1.1 christos {
2320 1.1 christos if (fixp->fx_addsy != (symbolS *) NULL
2321 1.1 christos && (!S_IS_DEFINED (fixp->fx_addsy) || S_IS_WEAK (fixp->fx_addsy)))
2322 1.1 christos /* The symbol is undefined or weak. Let the linker figure it out. */
2323 1.1 christos return 0;
2324 1.1 christos
2325 1.1 christos return fixp->fx_frag->fr_address + fixp->fx_where;
2326 1.1 christos }
2327 1.1 christos
2328 1.1 christos void
2329 1.1 christos md_apply_fix (fixS * fixP, valueT * valP, segT seg)
2330 1.1 christos {
2331 1.1 christos char * fixpos = fixP->fx_where + fixP->fx_frag->fr_literal;
2332 1.1 christos int size = 0;
2333 1.1 christos int value = (int) * valP;
2334 1.1 christos
2335 1.1 christos gas_assert (fixP->fx_r_type < BFD_RELOC_UNUSED);
2336 1.1 christos
2337 1.1 christos /* This should never happen. */
2338 1.1 christos if (seg->flags & SEC_ALLOC)
2339 1.1 christos abort ();
2340 1.1 christos
2341 1.1 christos /* The value we are passed in *valuep includes the symbol values.
2342 1.1 christos If we are doing this relocation the code in write.c is going to
2343 1.1 christos call bfd_install_relocation, which is also going to use the symbol
2344 1.1 christos value. That means that if the reloc is fully resolved we want to
2345 1.1 christos use *valuep since bfd_install_relocation is not being used.
2346 1.1 christos
2347 1.1 christos However, if the reloc is not fully resolved we do not want to use
2348 1.1 christos *valuep, and must use fx_offset instead. However, if the reloc
2349 1.1 christos is PC relative, we do want to use *valuep since it includes the
2350 1.1 christos result of md_pcrel_from. */
2351 1.1 christos if (fixP->fx_addsy != NULL && ! fixP->fx_pcrel)
2352 1.1 christos value = fixP->fx_offset;
2353 1.1 christos
2354 1.1 christos /* If the fix is relative to a symbol which is not defined, or not
2355 1.1 christos in the same segment as the fix, we cannot resolve it here. */
2356 1.1 christos if (fixP->fx_addsy != NULL
2357 1.1 christos && (! S_IS_DEFINED (fixP->fx_addsy)
2358 1.1 christos || (S_GET_SEGMENT (fixP->fx_addsy) != seg)))
2359 1.1 christos {
2360 1.1 christos fixP->fx_done = 0;
2361 1.1 christos return;
2362 1.1 christos }
2363 1.1 christos
2364 1.1 christos switch (fixP->fx_r_type)
2365 1.1 christos {
2366 1.1 christos case BFD_RELOC_8:
2367 1.1 christos case BFD_RELOC_8_PCREL:
2368 1.1 christos size = 1;
2369 1.1 christos break;
2370 1.1 christos
2371 1.1 christos case BFD_RELOC_16:
2372 1.1 christos case BFD_RELOC_16_PCREL:
2373 1.1 christos size = 2;
2374 1.1 christos break;
2375 1.1 christos
2376 1.1 christos case BFD_RELOC_32:
2377 1.1 christos case BFD_RELOC_32_PCREL:
2378 1.1 christos size = 4;
2379 1.1 christos break;
2380 1.1 christos
2381 1.1 christos case BFD_RELOC_VTABLE_INHERIT:
2382 1.1 christos case BFD_RELOC_VTABLE_ENTRY:
2383 1.1 christos fixP->fx_done = 0;
2384 1.1 christos return;
2385 1.1 christos
2386 1.1.1.2 christos case BFD_RELOC_MN10300_ALIGN:
2387 1.1 christos fixP->fx_done = 1;
2388 1.1 christos return;
2389 1.1 christos
2390 1.1 christos case BFD_RELOC_NONE:
2391 1.1 christos default:
2392 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line,
2393 1.1 christos _("Bad relocation fixup type (%d)"), fixP->fx_r_type);
2394 1.1 christos }
2395 1.1 christos
2396 1.1 christos md_number_to_chars (fixpos, value, size);
2397 1.1 christos
2398 1.1 christos /* If a symbol remains, pass the fixup, as a reloc, onto the linker. */
2399 1.1 christos if (fixP->fx_addsy == NULL)
2400 1.1 christos fixP->fx_done = 1;
2401 1.1 christos }
2402 1.1 christos
2403 1.1.1.6 christos /* Return zero if the fixup in fixp should be left alone and not
2404 1.1 christos adjusted. */
2405 1.1 christos
2406 1.1 christos bool
2407 1.1 christos mn10300_fix_adjustable (struct fix *fixp)
2408 1.1 christos {
2409 1.1.1.6 christos if (fixp->fx_pcrel)
2410 1.1 christos {
2411 1.1 christos if (TC_FORCE_RELOCATION_LOCAL (fixp))
2412 1.1 christos return false;
2413 1.1 christos }
2414 1.1.1.6 christos /* Non-relative relocs can (and must) be adjusted if they do
2415 1.1 christos not meet the criteria below, or the generic criteria. */
2416 1.1 christos else if (TC_FORCE_RELOCATION (fixp))
2417 1.1 christos return false;
2418 1.1 christos
2419 1.1 christos /* Do not adjust relocations involving symbols in code sections,
2420 1.1 christos because it breaks linker relaxations. This could be fixed in the
2421 1.1.1.6 christos linker, but this fix is simpler, and it pretty much only affects
2422 1.1 christos object size a little bit. */
2423 1.1 christos if (S_GET_SEGMENT (fixp->fx_addsy)->flags & SEC_CODE)
2424 1.1 christos return false;
2425 1.1.1.4 christos
2426 1.1 christos /* Likewise, do not adjust symbols that won't be merged, or debug
2427 1.1 christos symbols, because they too break relaxation. We do want to adjust
2428 1.1.1.6 christos other mergeable symbols, like .rodata, because code relaxations
2429 1.1 christos need section-relative symbols to properly relax them. */
2430 1.1.1.6 christos if (! (S_GET_SEGMENT (fixp->fx_addsy)->flags & SEC_MERGE))
2431 1.1.1.6 christos return false;
2432 1.1 christos
2433 1.1.1.6 christos if (startswith (S_GET_SEGMENT (fixp->fx_addsy)->name, ".debug"))
2434 1.1 christos return false;
2435 1.1 christos
2436 1.1 christos return true;
2437 1.1 christos }
2438 1.1 christos
2439 1.1 christos static void
2440 1.1 christos set_arch_mach (int mach)
2441 1.1 christos {
2442 1.1 christos if (!bfd_set_arch_mach (stdoutput, bfd_arch_mn10300, mach))
2443 1.1 christos as_warn (_("could not set architecture and machine"));
2444 1.1 christos
2445 1.1 christos current_machine = mach;
2446 1.1.1.3 christos }
2447 1.1 christos
2448 1.1 christos static inline char *
2449 1.1 christos mn10300_end_of_match (char *cont, const char *what)
2450 1.1.1.6 christos {
2451 1.1 christos int len = strlen (what);
2452 1.1 christos
2453 1.1 christos if (startswith (cont, what)
2454 1.1 christos && ! is_part_of_name (cont[len]))
2455 1.1.1.2 christos return cont + len;
2456 1.1 christos
2457 1.1 christos return NULL;
2458 1.1 christos }
2459 1.1 christos
2460 1.1 christos int
2461 1.1 christos mn10300_parse_name (char const *name,
2462 1.1 christos expressionS *exprP,
2463 1.1 christos enum expr_mode mode,
2464 1.1 christos char *nextcharP)
2465 1.1 christos {
2466 1.1 christos char *next = input_line_pointer;
2467 1.1 christos char *next_end;
2468 1.1 christos int reloc_type;
2469 1.1 christos segT segment;
2470 1.1 christos
2471 1.1 christos exprP->X_op_symbol = NULL;
2472 1.1 christos
2473 1.1 christos if (strcmp (name, GLOBAL_OFFSET_TABLE_NAME) == 0)
2474 1.1 christos {
2475 1.1 christos if (! GOT_symbol)
2476 1.1 christos GOT_symbol = symbol_find_or_make (name);
2477 1.1 christos
2478 1.1 christos exprP->X_add_symbol = GOT_symbol;
2479 1.1 christos no_suffix:
2480 1.1 christos /* If we have an absolute symbol or a reg,
2481 1.1 christos then we know its value now. */
2482 1.1 christos segment = S_GET_SEGMENT (exprP->X_add_symbol);
2483 1.1 christos if (mode != expr_defer && segment == absolute_section)
2484 1.1 christos {
2485 1.1 christos exprP->X_op = O_constant;
2486 1.1 christos exprP->X_add_number = S_GET_VALUE (exprP->X_add_symbol);
2487 1.1 christos exprP->X_add_symbol = NULL;
2488 1.1 christos }
2489 1.1 christos else if (mode != expr_defer && segment == reg_section)
2490 1.1 christos {
2491 1.1 christos exprP->X_op = O_register;
2492 1.1 christos exprP->X_add_number = S_GET_VALUE (exprP->X_add_symbol);
2493 1.1 christos exprP->X_add_symbol = NULL;
2494 1.1 christos }
2495 1.1 christos else
2496 1.1 christos {
2497 1.1 christos exprP->X_op = O_symbol;
2498 1.1 christos exprP->X_add_number = 0;
2499 1.1 christos }
2500 1.1 christos
2501 1.1 christos return 1;
2502 1.1.1.2 christos }
2503 1.1 christos
2504 1.1 christos exprP->X_add_symbol = symbol_find_or_make (name);
2505 1.1 christos
2506 1.1 christos if (*nextcharP != '@')
2507 1.1 christos goto no_suffix;
2508 1.1 christos else if ((next_end = mn10300_end_of_match (next + 1, "GOTOFF")))
2509 1.1 christos reloc_type = BFD_RELOC_32_GOTOFF;
2510 1.1 christos else if ((next_end = mn10300_end_of_match (next + 1, "GOT")))
2511 1.1 christos reloc_type = BFD_RELOC_MN10300_GOT32;
2512 1.1 christos else if ((next_end = mn10300_end_of_match (next + 1, "PLT")))
2513 1.1 christos reloc_type = BFD_RELOC_32_PLT_PCREL;
2514 1.1 christos else if ((next_end = mn10300_end_of_match (next + 1, "tlsgd")))
2515 1.1 christos reloc_type = BFD_RELOC_MN10300_TLS_GD;
2516 1.1 christos else if ((next_end = mn10300_end_of_match (next + 1, "tlsldm")))
2517 1.1 christos reloc_type = BFD_RELOC_MN10300_TLS_LD;
2518 1.1 christos else if ((next_end = mn10300_end_of_match (next + 1, "dtpoff")))
2519 1.1 christos reloc_type = BFD_RELOC_MN10300_TLS_LDO;
2520 1.1 christos else if ((next_end = mn10300_end_of_match (next + 1, "gotntpoff")))
2521 1.1 christos reloc_type = BFD_RELOC_MN10300_TLS_GOTIE;
2522 1.1 christos else if ((next_end = mn10300_end_of_match (next + 1, "indntpoff")))
2523 1.1 christos reloc_type = BFD_RELOC_MN10300_TLS_IE;
2524 1.1 christos else if ((next_end = mn10300_end_of_match (next + 1, "tpoff")))
2525 1.1 christos reloc_type = BFD_RELOC_MN10300_TLS_LE;
2526 1.1 christos else
2527 1.1 christos goto no_suffix;
2528 1.1 christos
2529 1.1 christos *input_line_pointer = *nextcharP;
2530 1.1 christos input_line_pointer = next_end;
2531 1.1 christos *nextcharP = *input_line_pointer;
2532 1.1 christos *input_line_pointer = '\0';
2533 1.1 christos
2534 1.1 christos exprP->X_op = O_PIC_reloc;
2535 1.1 christos exprP->X_add_number = 0;
2536 1.1 christos exprP->X_md = reloc_type;
2537 1.1 christos
2538 1.1 christos return 1;
2539 1.1 christos }
2540 1.1 christos
2541 1.1 christos /* The target specific pseudo-ops which we support. */
2542 1.1 christos const pseudo_typeS md_pseudo_table[] =
2543 1.1 christos {
2544 1.1 christos { "am30", set_arch_mach, AM30 },
2545 1.1 christos { "am33", set_arch_mach, AM33 },
2546 1.1 christos { "am33_2", set_arch_mach, AM33_2 },
2547 1.1 christos { "mn10300", set_arch_mach, MN103 },
2548 1.1 christos {NULL, 0, 0}
2549 1.1 christos };
2550 1.1 christos
2551 1.1 christos /* Returns FALSE if there is some mn10300 specific reason why the
2552 1.1.1.6 christos subtraction of two same-section symbols cannot be computed by
2553 1.1 christos the assembler. */
2554 1.1 christos
2555 1.1.1.6 christos bool
2556 1.1 christos mn10300_allow_local_subtract (expressionS * left, expressionS * right, segT section)
2557 1.1 christos {
2558 1.1 christos bool result;
2559 1.1 christos fragS * left_frag;
2560 1.1 christos fragS * right_frag;
2561 1.1 christos fragS * frag;
2562 1.1 christos
2563 1.1.1.6 christos /* If we are not performing linker relaxation then we have nothing
2564 1.1 christos to worry about. */
2565 1.1 christos if (linkrelax == 0)
2566 1.1 christos return true;
2567 1.1.1.6 christos
2568 1.1 christos /* If the symbols are not in a code section then they are OK. */
2569 1.1 christos if ((section->flags & SEC_CODE) == 0)
2570 1.1 christos return true;
2571 1.1 christos
2572 1.1 christos /* Otherwise we have to scan the fragments between the two symbols.
2573 1.1 christos If any instructions are found then we have to assume that linker
2574 1.1 christos relaxation may change their size and so we must delay resolving
2575 1.1 christos the subtraction until the final link. */
2576 1.1 christos left_frag = symbol_get_frag (left->X_add_symbol);
2577 1.1 christos right_frag = symbol_get_frag (right->X_add_symbol);
2578 1.1 christos
2579 1.1.1.6 christos if (left_frag == right_frag)
2580 1.1 christos return ! left_frag->tc_frag_data;
2581 1.1 christos
2582 1.1 christos result = true;
2583 1.1.1.6 christos for (frag = left_frag; frag != NULL; frag = frag->fr_next)
2584 1.1 christos {
2585 1.1 christos if (frag->tc_frag_data)
2586 1.1 christos result = false;
2587 1.1 christos if (frag == right_frag)
2588 1.1 christos break;
2589 1.1 christos }
2590 1.1 christos
2591 1.1 christos if (frag == NULL)
2592 1.1.1.6 christos for (frag = right_frag; frag != NULL; frag = frag->fr_next)
2593 1.1 christos {
2594 1.1 christos if (frag->tc_frag_data)
2595 1.1 christos result = false;
2596 1.1 christos if (frag == left_frag)
2597 1.1 christos break;
2598 1.1 christos }
2599 1.1 christos
2600 1.1.1.6 christos if (frag == NULL)
2601 1.1 christos /* The two symbols are on disjoint fragment chains
2602 1.1 christos - we cannot possibly compute their difference. */
2603 1.1 christos return false;
2604 1.1 christos
2605 1.1 christos return result;
2606 1.1 christos }
2607 1.1 christos
2608 1.1 christos /* When relaxing, we need to output a reloc for any .align directive
2609 1.1 christos that requests alignment to a two byte boundary or larger. */
2610 1.1 christos
2611 1.1 christos void
2612 1.1 christos mn10300_handle_align (fragS *frag)
2613 1.1 christos {
2614 1.1 christos if (linkrelax
2615 1.1 christos && (frag->fr_type == rs_align
2616 1.1 christos || frag->fr_type == rs_align_code)
2617 1.1 christos && frag->fr_address + frag->fr_fix > 0
2618 1.1 christos && frag->fr_offset > 1
2619 1.1.1.5 christos && now_seg != bss_section
2620 1.1 christos /* Do not create relocs for the merging sections - such
2621 1.1.1.4 christos relocs will prevent the contents from being merged. */
2622 1.1 christos && (bfd_section_flags (now_seg) & SEC_MERGE) == 0)
2623 1.1 christos /* Create a new fixup to record the alignment request. The symbol is
2624 1.1 christos irrelevant but must be present so we use the absolute section symbol.
2625 1.1.1.6 christos The offset from the symbol is used to record the power-of-two alignment
2626 1.1 christos value. The size is set to 0 because the frag may already be aligned,
2627 1.1 christos thus causing cvt_frag_to_fill to reduce the size of the frag to zero. */
2628 1.1 christos fix_new (frag, frag->fr_fix, 0, & abs_symbol, frag->fr_offset, false,
2629 1.1.1.6 christos BFD_RELOC_MN10300_ALIGN);
2630 1.1 christos }
2631 1.1 christos
2632 1.1 christos bool
2633 1.1 christos mn10300_force_relocation (struct fix * fixp)
2634 1.1 christos {
2635 1.1.1.6 christos if (linkrelax
2636 1.1 christos && (fixp->fx_pcrel
2637 1.1 christos || fixp->fx_r_type == BFD_RELOC_MN10300_ALIGN))
2638 1.1 christos return true;
2639
2640 return generic_force_reloc (fixp);
2641 }
2642