tc-mn10300.c revision 1.10 1 1.1 christos /* tc-mn10300.c -- Assembler code for the Matsushita 10300
2 1.10 christos Copyright (C) 1996-2025 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.10 christos int mn10300_reg_operands[MN10300_MAX_OPERANDS];
111 1.1 christos
112 1.10 christos const char md_shortopts[] = "";
114 1.1 christos
115 1.1 christos const struct option md_longopts[] =
116 1.1 christos {
117 1.10 christos {NULL, no_argument, NULL, 0}
118 1.1 christos };
119 1.1 christos
120 1.1 christos const 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.8 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.6 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.8 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.3 christos char c;
338 1.1 christos
339 1.3 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.3 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.8 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.8 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.8 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.8 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.8 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.8 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.8 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.8 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.8 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.3 christos char c;
410 1.1 christos
411 1.3 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.3 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.8 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.8 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.5 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.5 christos return 0;
456 1.1 christos }
457 1.1 christos
458 1.8 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 if (fragP->fr_subtype == 0)
473 1.1 christos {
474 1.1 christos fix_new (fragP, fragP->fr_fix + 1, 1, fragP->fr_symbol,
475 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
476 1.1 christos fragP->fr_var = 0;
477 1.1 christos fragP->fr_fix += 2;
478 1.1 christos }
479 1.1 christos else if (fragP->fr_subtype == 1)
480 1.1 christos {
481 1.1 christos /* Reverse the condition of the first branch. */
482 1.1 christos int offset = fragP->fr_fix;
483 1.1 christos int opcode = fragP->fr_literal[offset] & 0xff;
484 1.1 christos
485 1.1 christos switch (opcode)
486 1.1 christos {
487 1.1 christos case 0xc8:
488 1.1 christos opcode = 0xc9;
489 1.1 christos break;
490 1.1 christos case 0xc9:
491 1.1 christos opcode = 0xc8;
492 1.1 christos break;
493 1.1 christos case 0xc0:
494 1.1 christos opcode = 0xc2;
495 1.1 christos break;
496 1.1 christos case 0xc2:
497 1.1 christos opcode = 0xc0;
498 1.1 christos break;
499 1.1 christos case 0xc3:
500 1.1 christos opcode = 0xc1;
501 1.1 christos break;
502 1.1 christos case 0xc1:
503 1.1 christos opcode = 0xc3;
504 1.1 christos break;
505 1.1 christos case 0xc4:
506 1.1 christos opcode = 0xc6;
507 1.1 christos break;
508 1.1 christos case 0xc6:
509 1.1 christos opcode = 0xc4;
510 1.1 christos break;
511 1.1 christos case 0xc7:
512 1.1 christos opcode = 0xc5;
513 1.1 christos break;
514 1.1 christos case 0xc5:
515 1.1 christos opcode = 0xc7;
516 1.1 christos break;
517 1.1 christos default:
518 1.1 christos abort ();
519 1.1 christos }
520 1.1 christos fragP->fr_literal[offset] = opcode;
521 1.1 christos
522 1.8 christos /* Create a fixup for the reversed conditional branch. */
523 1.1 christos sprintf (buf, ".%s_%ld", FAKE_LABEL_NAME, label_count++);
524 1.1 christos fix_new (fragP, fragP->fr_fix + 1, 1,
525 1.1 christos symbol_new (buf, sec, fragP->fr_next, 0),
526 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
527 1.1 christos
528 1.1 christos /* Now create the unconditional branch + fixup to the
529 1.1 christos final target. */
530 1.1 christos fragP->fr_literal[offset + 2] = 0xcc;
531 1.1 christos fix_new (fragP, fragP->fr_fix + 3, 2, fragP->fr_symbol,
532 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
533 1.1 christos fragP->fr_var = 0;
534 1.1 christos fragP->fr_fix += 5;
535 1.1 christos }
536 1.1 christos else if (fragP->fr_subtype == 2)
537 1.1 christos {
538 1.1 christos /* Reverse the condition of the first branch. */
539 1.1 christos int offset = fragP->fr_fix;
540 1.1 christos int opcode = fragP->fr_literal[offset] & 0xff;
541 1.1 christos
542 1.1 christos switch (opcode)
543 1.1 christos {
544 1.1 christos case 0xc8:
545 1.1 christos opcode = 0xc9;
546 1.1 christos break;
547 1.1 christos case 0xc9:
548 1.1 christos opcode = 0xc8;
549 1.1 christos break;
550 1.1 christos case 0xc0:
551 1.1 christos opcode = 0xc2;
552 1.1 christos break;
553 1.1 christos case 0xc2:
554 1.1 christos opcode = 0xc0;
555 1.1 christos break;
556 1.1 christos case 0xc3:
557 1.1 christos opcode = 0xc1;
558 1.1 christos break;
559 1.1 christos case 0xc1:
560 1.1 christos opcode = 0xc3;
561 1.1 christos break;
562 1.1 christos case 0xc4:
563 1.1 christos opcode = 0xc6;
564 1.1 christos break;
565 1.1 christos case 0xc6:
566 1.1 christos opcode = 0xc4;
567 1.1 christos break;
568 1.1 christos case 0xc7:
569 1.1 christos opcode = 0xc5;
570 1.1 christos break;
571 1.1 christos case 0xc5:
572 1.1 christos opcode = 0xc7;
573 1.1 christos break;
574 1.1 christos default:
575 1.1 christos abort ();
576 1.1 christos }
577 1.1 christos fragP->fr_literal[offset] = opcode;
578 1.1 christos
579 1.8 christos /* Create a fixup for the reversed conditional branch. */
580 1.1 christos sprintf (buf, ".%s_%ld", FAKE_LABEL_NAME, label_count++);
581 1.1 christos fix_new (fragP, fragP->fr_fix + 1, 1,
582 1.1 christos symbol_new (buf, sec, fragP->fr_next, 0),
583 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
584 1.1 christos
585 1.1 christos /* Now create the unconditional branch + fixup to the
586 1.1 christos final target. */
587 1.1 christos fragP->fr_literal[offset + 2] = 0xdc;
588 1.1 christos fix_new (fragP, fragP->fr_fix + 3, 4, fragP->fr_symbol,
589 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
590 1.1 christos fragP->fr_var = 0;
591 1.1 christos fragP->fr_fix += 7;
592 1.1 christos }
593 1.1 christos else if (fragP->fr_subtype == 3)
594 1.1 christos {
595 1.1 christos fix_new (fragP, fragP->fr_fix + 2, 1, fragP->fr_symbol,
596 1.1 christos fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
597 1.1 christos fragP->fr_var = 0;
598 1.1 christos fragP->fr_fix += 3;
599 1.1 christos }
600 1.1 christos else if (fragP->fr_subtype == 4)
601 1.1 christos {
602 1.1 christos /* Reverse the condition of the first branch. */
603 1.1 christos int offset = fragP->fr_fix;
604 1.1 christos int opcode = fragP->fr_literal[offset + 1] & 0xff;
605 1.1 christos
606 1.1 christos switch (opcode)
607 1.1 christos {
608 1.1 christos case 0xe8:
609 1.1 christos opcode = 0xe9;
610 1.1 christos break;
611 1.1 christos case 0xe9:
612 1.1 christos opcode = 0xe8;
613 1.1 christos break;
614 1.1 christos case 0xea:
615 1.1 christos opcode = 0xeb;
616 1.1 christos break;
617 1.1 christos case 0xeb:
618 1.1 christos opcode = 0xea;
619 1.1 christos break;
620 1.1 christos default:
621 1.1 christos abort ();
622 1.1 christos }
623 1.1 christos fragP->fr_literal[offset + 1] = opcode;
624 1.1 christos
625 1.8 christos /* Create a fixup for the reversed conditional branch. */
626 1.1 christos sprintf (buf, ".%s_%ld", FAKE_LABEL_NAME, label_count++);
627 1.1 christos fix_new (fragP, fragP->fr_fix + 2, 1,
628 1.1 christos symbol_new (buf, sec, fragP->fr_next, 0),
629 1.1 christos fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
630 1.1 christos
631 1.1 christos /* Now create the unconditional branch + fixup to the
632 1.1 christos final target. */
633 1.1 christos fragP->fr_literal[offset + 3] = 0xcc;
634 1.1 christos fix_new (fragP, fragP->fr_fix + 4, 2, fragP->fr_symbol,
635 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
636 1.1 christos fragP->fr_var = 0;
637 1.1 christos fragP->fr_fix += 6;
638 1.1 christos }
639 1.1 christos else if (fragP->fr_subtype == 5)
640 1.1 christos {
641 1.1 christos /* Reverse the condition of the first branch. */
642 1.1 christos int offset = fragP->fr_fix;
643 1.1 christos int opcode = fragP->fr_literal[offset + 1] & 0xff;
644 1.1 christos
645 1.1 christos switch (opcode)
646 1.1 christos {
647 1.1 christos case 0xe8:
648 1.1 christos opcode = 0xe9;
649 1.1 christos break;
650 1.1 christos case 0xea:
651 1.1 christos opcode = 0xeb;
652 1.1 christos break;
653 1.1 christos case 0xeb:
654 1.1 christos opcode = 0xea;
655 1.1 christos break;
656 1.1 christos default:
657 1.1 christos abort ();
658 1.1 christos }
659 1.1 christos fragP->fr_literal[offset + 1] = opcode;
660 1.1 christos
661 1.8 christos /* Create a fixup for the reversed conditional branch. */
662 1.1 christos sprintf (buf, ".%s_%ld", FAKE_LABEL_NAME, label_count++);
663 1.1 christos fix_new (fragP, fragP->fr_fix + 2, 1,
664 1.1 christos symbol_new (buf, sec, fragP->fr_next, 0),
665 1.1 christos fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
666 1.1 christos
667 1.1 christos /* Now create the unconditional branch + fixup to the
668 1.1 christos final target. */
669 1.1 christos fragP->fr_literal[offset + 3] = 0xdc;
670 1.1 christos fix_new (fragP, fragP->fr_fix + 4, 4, fragP->fr_symbol,
671 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
672 1.1 christos fragP->fr_var = 0;
673 1.1 christos fragP->fr_fix += 8;
674 1.1 christos }
675 1.1 christos else if (fragP->fr_subtype == 6)
676 1.1 christos {
677 1.1 christos int offset = fragP->fr_fix;
678 1.1 christos
679 1.1 christos fragP->fr_literal[offset] = 0xcd;
680 1.1 christos fix_new (fragP, fragP->fr_fix + 1, 2, fragP->fr_symbol,
681 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
682 1.1 christos fragP->fr_var = 0;
683 1.1 christos fragP->fr_fix += 5;
684 1.1 christos }
685 1.1 christos else if (fragP->fr_subtype == 7)
686 1.1 christos {
687 1.1 christos int offset = fragP->fr_fix;
688 1.1 christos
689 1.1 christos fragP->fr_literal[offset] = 0xdd;
690 1.1 christos fragP->fr_literal[offset + 5] = fragP->fr_literal[offset + 3];
691 1.1 christos fragP->fr_literal[offset + 6] = fragP->fr_literal[offset + 4];
692 1.1 christos fragP->fr_literal[offset + 3] = 0;
693 1.1 christos fragP->fr_literal[offset + 4] = 0;
694 1.1 christos
695 1.1 christos fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol,
696 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
697 1.1 christos fragP->fr_var = 0;
698 1.1 christos fragP->fr_fix += 7;
699 1.1 christos }
700 1.1 christos else if (fragP->fr_subtype == 8)
701 1.1 christos {
702 1.1 christos int offset = fragP->fr_fix;
703 1.1 christos
704 1.1 christos fragP->fr_literal[offset] = 0xfa;
705 1.1 christos fragP->fr_literal[offset + 1] = 0xff;
706 1.1 christos fix_new (fragP, fragP->fr_fix + 2, 2, fragP->fr_symbol,
707 1.1 christos fragP->fr_offset + 2, 1, BFD_RELOC_16_PCREL);
708 1.1 christos fragP->fr_var = 0;
709 1.1 christos fragP->fr_fix += 4;
710 1.1 christos }
711 1.1 christos else if (fragP->fr_subtype == 9)
712 1.1 christos {
713 1.1 christos int offset = fragP->fr_fix;
714 1.1 christos
715 1.1 christos fragP->fr_literal[offset] = 0xfc;
716 1.1 christos fragP->fr_literal[offset + 1] = 0xff;
717 1.1 christos
718 1.1 christos fix_new (fragP, fragP->fr_fix + 2, 4, fragP->fr_symbol,
719 1.1 christos fragP->fr_offset + 2, 1, BFD_RELOC_32_PCREL);
720 1.1 christos fragP->fr_var = 0;
721 1.1 christos fragP->fr_fix += 6;
722 1.1 christos }
723 1.1 christos else if (fragP->fr_subtype == 10)
724 1.1 christos {
725 1.1 christos fragP->fr_literal[fragP->fr_fix] = 0xca;
726 1.1 christos fix_new (fragP, fragP->fr_fix + 1, 1, fragP->fr_symbol,
727 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
728 1.1 christos fragP->fr_var = 0;
729 1.1 christos fragP->fr_fix += 2;
730 1.1 christos }
731 1.1 christos else if (fragP->fr_subtype == 11)
732 1.1 christos {
733 1.1 christos int offset = fragP->fr_fix;
734 1.1 christos
735 1.1 christos fragP->fr_literal[offset] = 0xcc;
736 1.1 christos
737 1.1 christos fix_new (fragP, fragP->fr_fix + 1, 2, fragP->fr_symbol,
738 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
739 1.1 christos fragP->fr_var = 0;
740 1.1 christos fragP->fr_fix += 3;
741 1.1 christos }
742 1.1 christos else if (fragP->fr_subtype == 12)
743 1.1 christos {
744 1.1 christos int offset = fragP->fr_fix;
745 1.1 christos
746 1.1 christos fragP->fr_literal[offset] = 0xdc;
747 1.1 christos
748 1.1 christos fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol,
749 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
750 1.1 christos fragP->fr_var = 0;
751 1.1 christos fragP->fr_fix += 5;
752 1.1 christos }
753 1.1 christos else if (fragP->fr_subtype == 13)
754 1.1 christos {
755 1.1 christos fix_new (fragP, fragP->fr_fix + 2, 1, fragP->fr_symbol,
756 1.1 christos fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
757 1.1 christos fragP->fr_var = 0;
758 1.1 christos fragP->fr_fix += 3;
759 1.1 christos }
760 1.1 christos else if (fragP->fr_subtype == 14)
761 1.1 christos {
762 1.1 christos /* Reverse the condition of the first branch. */
763 1.1 christos int offset = fragP->fr_fix;
764 1.1 christos int opcode = fragP->fr_literal[offset + 1] & 0xff;
765 1.1 christos
766 1.1 christos switch (opcode)
767 1.1 christos {
768 1.1 christos case 0xd0:
769 1.1 christos opcode = 0xd1;
770 1.1 christos break;
771 1.1 christos case 0xd1:
772 1.1 christos opcode = 0xd0;
773 1.1 christos break;
774 1.1 christos case 0xd2:
775 1.1 christos opcode = 0xdc;
776 1.1 christos break;
777 1.1 christos case 0xd3:
778 1.1 christos opcode = 0xdb;
779 1.1 christos break;
780 1.1 christos case 0xd4:
781 1.1 christos opcode = 0xda;
782 1.1 christos break;
783 1.1 christos case 0xd5:
784 1.1 christos opcode = 0xd9;
785 1.1 christos break;
786 1.1 christos case 0xd6:
787 1.1 christos opcode = 0xd8;
788 1.1 christos break;
789 1.1 christos case 0xd7:
790 1.1 christos opcode = 0xdd;
791 1.1 christos break;
792 1.1 christos case 0xd8:
793 1.1 christos opcode = 0xd6;
794 1.1 christos break;
795 1.1 christos case 0xd9:
796 1.1 christos opcode = 0xd5;
797 1.1 christos break;
798 1.1 christos case 0xda:
799 1.1 christos opcode = 0xd4;
800 1.1 christos break;
801 1.1 christos case 0xdb:
802 1.1 christos opcode = 0xd3;
803 1.1 christos break;
804 1.1 christos case 0xdc:
805 1.1 christos opcode = 0xd2;
806 1.1 christos break;
807 1.1 christos case 0xdd:
808 1.1 christos opcode = 0xd7;
809 1.1 christos break;
810 1.1 christos default:
811 1.1 christos abort ();
812 1.1 christos }
813 1.1 christos fragP->fr_literal[offset + 1] = opcode;
814 1.1 christos
815 1.8 christos /* Create a fixup for the reversed conditional branch. */
816 1.1 christos sprintf (buf, ".%s_%ld", FAKE_LABEL_NAME, label_count++);
817 1.1 christos fix_new (fragP, fragP->fr_fix + 2, 1,
818 1.1 christos symbol_new (buf, sec, fragP->fr_next, 0),
819 1.1 christos fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
820 1.1 christos
821 1.1 christos /* Now create the unconditional branch + fixup to the
822 1.1 christos final target. */
823 1.1 christos fragP->fr_literal[offset + 3] = 0xcc;
824 1.1 christos fix_new (fragP, fragP->fr_fix + 4, 2, fragP->fr_symbol,
825 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
826 1.1 christos fragP->fr_var = 0;
827 1.1 christos fragP->fr_fix += 6;
828 1.1 christos }
829 1.1 christos else if (fragP->fr_subtype == 15)
830 1.1 christos {
831 1.1 christos /* Reverse the condition of the first branch. */
832 1.1 christos int offset = fragP->fr_fix;
833 1.1 christos int opcode = fragP->fr_literal[offset + 1] & 0xff;
834 1.1 christos
835 1.1 christos switch (opcode)
836 1.1 christos {
837 1.1 christos case 0xd0:
838 1.1 christos opcode = 0xd1;
839 1.1 christos break;
840 1.1 christos case 0xd1:
841 1.1 christos opcode = 0xd0;
842 1.1 christos break;
843 1.1 christos case 0xd2:
844 1.1 christos opcode = 0xdc;
845 1.1 christos break;
846 1.1 christos case 0xd3:
847 1.1 christos opcode = 0xdb;
848 1.1 christos break;
849 1.1 christos case 0xd4:
850 1.1 christos opcode = 0xda;
851 1.1 christos break;
852 1.1 christos case 0xd5:
853 1.1 christos opcode = 0xd9;
854 1.1 christos break;
855 1.1 christos case 0xd6:
856 1.1 christos opcode = 0xd8;
857 1.1 christos break;
858 1.1 christos case 0xd7:
859 1.1 christos opcode = 0xdd;
860 1.1 christos break;
861 1.1 christos case 0xd8:
862 1.1 christos opcode = 0xd6;
863 1.1 christos break;
864 1.1 christos case 0xd9:
865 1.1 christos opcode = 0xd5;
866 1.1 christos break;
867 1.1 christos case 0xda:
868 1.1 christos opcode = 0xd4;
869 1.1 christos break;
870 1.1 christos case 0xdb:
871 1.1 christos opcode = 0xd3;
872 1.1 christos break;
873 1.1 christos case 0xdc:
874 1.1 christos opcode = 0xd2;
875 1.1 christos break;
876 1.1 christos case 0xdd:
877 1.1 christos opcode = 0xd7;
878 1.1 christos break;
879 1.1 christos default:
880 1.1 christos abort ();
881 1.1 christos }
882 1.1 christos fragP->fr_literal[offset + 1] = opcode;
883 1.1 christos
884 1.8 christos /* Create a fixup for the reversed conditional branch. */
885 1.1 christos sprintf (buf, ".%s_%ld", FAKE_LABEL_NAME, label_count++);
886 1.1 christos fix_new (fragP, fragP->fr_fix + 2, 1,
887 1.1 christos symbol_new (buf, sec, fragP->fr_next, 0),
888 1.1 christos fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
889 1.1 christos
890 1.1 christos /* Now create the unconditional branch + fixup to the
891 1.1 christos final target. */
892 1.1 christos fragP->fr_literal[offset + 3] = 0xdc;
893 1.1 christos fix_new (fragP, fragP->fr_fix + 4, 4, fragP->fr_symbol,
894 1.1 christos fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
895 1.1 christos fragP->fr_var = 0;
896 1.1 christos fragP->fr_fix += 8;
897 1.1 christos }
898 1.1 christos else
899 1.1 christos abort ();
900 1.1 christos }
901 1.1 christos
902 1.7 christos valueT
903 1.1 christos md_section_align (asection *seg, valueT addr)
904 1.10 christos {
905 1.1 christos int align = bfd_section_alignment (seg);
906 1.1 christos
907 1.1 christos return (addr + ((valueT) 1 << align) - 1) & -((valueT) 1 << align);
908 1.1 christos }
909 1.1 christos
910 1.5 christos void
911 1.1 christos md_begin (void)
912 1.1 christos {
913 1.8 christos const char *prev_name = "";
914 1.1 christos const struct mn10300_opcode *op;
915 1.1 christos
916 1.1 christos mn10300_hash = str_htab_create ();
917 1.1 christos
918 1.1 christos /* Insert unique names into hash table. The MN10300 instruction set
919 1.1 christos has many identical opcode names that have different opcodes based
920 1.1 christos on the operands. This hash table then provides a quick index to
921 1.1 christos the first opcode with a particular name in the opcode table. */
922 1.1 christos
923 1.1 christos op = mn10300_opcodes;
924 1.1 christos while (op->name)
925 1.10 christos {
926 1.8 christos if (strcmp (prev_name, op->name))
927 1.1 christos {
928 1.1 christos prev_name = op->name;
929 1.1 christos str_hash_insert (mn10300_hash, op->name, op, 0);
930 1.1 christos }
931 1.1 christos op++;
932 1.1 christos }
933 1.1 christos
934 1.1 christos /* Set the default machine type. */
935 1.1 christos #ifdef TE_LINUX
936 1.1 christos if (!bfd_set_arch_mach (stdoutput, bfd_arch_mn10300, AM33_2))
937 1.3 christos as_warn (_("could not set architecture and machine"));
938 1.1 christos
939 1.1 christos current_machine = AM33_2;
940 1.1 christos #else
941 1.1 christos if (!bfd_set_arch_mach (stdoutput, bfd_arch_mn10300, MN103))
942 1.1 christos as_warn (_("could not set architecture and machine"));
943 1.5 christos
944 1.5 christos current_machine = MN103;
945 1.5 christos #endif
946 1.1 christos
947 1.1 christos /* Set linkrelax here to avoid fixups in most sections. */
948 1.1 christos linkrelax = 1;
949 1.1 christos }
950 1.1 christos
951 1.1 christos static symbolS *GOT_symbol;
952 1.1 christos
953 1.1 christos static inline int
954 1.1 christos mn10300_PIC_related_p (symbolS *sym)
955 1.1 christos {
956 1.1 christos expressionS *exp;
957 1.1 christos
958 1.1 christos if (! sym)
959 1.1 christos return 0;
960 1.1 christos
961 1.1 christos if (sym == GOT_symbol)
962 1.1 christos return 1;
963 1.1 christos
964 1.1 christos exp = symbol_get_value_expression (sym);
965 1.1 christos
966 1.1 christos return (exp->X_op == O_PIC_reloc
967 1.1 christos || mn10300_PIC_related_p (exp->X_add_symbol)
968 1.1 christos || mn10300_PIC_related_p (exp->X_op_symbol));
969 1.1 christos }
970 1.1 christos
971 1.1 christos static inline int
972 1.1 christos mn10300_check_fixup (struct mn10300_fixup *fixup)
973 1.1 christos {
974 1.1 christos expressionS *exp = &fixup->exp;
975 1.1 christos
976 1.1 christos repeat:
977 1.1 christos switch (exp->X_op)
978 1.1 christos {
979 1.1 christos case O_add:
980 1.1 christos case O_subtract: /* If we're sufficiently unlucky that the label
981 1.1 christos and the expression that references it happen
982 1.1 christos to end up in different frags, the subtract
983 1.1 christos won't be simplified within expression(). */
984 1.1 christos /* The PIC-related operand must be the first operand of a sum. */
985 1.1 christos if (exp != &fixup->exp || mn10300_PIC_related_p (exp->X_op_symbol))
986 1.1 christos return 1;
987 1.1 christos
988 1.1 christos if (exp->X_add_symbol && exp->X_add_symbol == GOT_symbol)
989 1.1 christos fixup->reloc = BFD_RELOC_32_GOT_PCREL;
990 1.1 christos
991 1.1 christos exp = symbol_get_value_expression (exp->X_add_symbol);
992 1.1 christos goto repeat;
993 1.1 christos
994 1.1 christos case O_symbol:
995 1.1 christos if (exp->X_add_symbol && exp->X_add_symbol == GOT_symbol)
996 1.1 christos fixup->reloc = BFD_RELOC_32_GOT_PCREL;
997 1.1 christos break;
998 1.1 christos
999 1.1 christos case O_PIC_reloc:
1000 1.1 christos fixup->reloc = exp->X_md;
1001 1.1 christos exp->X_op = O_symbol;
1002 1.1 christos if (fixup->reloc == BFD_RELOC_32_PLT_PCREL
1003 1.1 christos && fixup->opindex >= 0
1004 1.1 christos && (mn10300_operands[fixup->opindex].flags
1005 1.1 christos & MN10300_OPERAND_RELAX))
1006 1.1 christos return 1;
1007 1.1 christos break;
1008 1.1 christos
1009 1.1 christos default:
1010 1.1 christos return (mn10300_PIC_related_p (exp->X_add_symbol)
1011 1.1 christos || mn10300_PIC_related_p (exp->X_op_symbol));
1012 1.1 christos }
1013 1.1 christos
1014 1.1 christos return 0;
1015 1.3 christos }
1016 1.3 christos
1017 1.1 christos void
1018 1.1 christos mn10300_cons_fix_new (fragS *frag, int off, int size, expressionS *exp,
1019 1.1 christos bfd_reloc_code_real_type r ATTRIBUTE_UNUSED)
1020 1.1 christos {
1021 1.1 christos struct mn10300_fixup fixup;
1022 1.1 christos
1023 1.1 christos fixup.opindex = -1;
1024 1.1 christos fixup.exp = *exp;
1025 1.1 christos fixup.reloc = BFD_RELOC_UNUSED;
1026 1.1 christos
1027 1.1 christos mn10300_check_fixup (&fixup);
1028 1.1 christos
1029 1.1 christos if (fixup.reloc == BFD_RELOC_MN10300_GOT32)
1030 1.1 christos switch (size)
1031 1.1 christos {
1032 1.1 christos case 2:
1033 1.1 christos fixup.reloc = BFD_RELOC_MN10300_GOT16;
1034 1.1 christos break;
1035 1.1 christos
1036 1.1 christos case 3:
1037 1.1 christos fixup.reloc = BFD_RELOC_MN10300_GOT24;
1038 1.1 christos break;
1039 1.1 christos
1040 1.1 christos case 4:
1041 1.1 christos break;
1042 1.1 christos
1043 1.1 christos default:
1044 1.1 christos goto error;
1045 1.1 christos }
1046 1.1 christos else if (fixup.reloc == BFD_RELOC_UNUSED)
1047 1.1 christos switch (size)
1048 1.1 christos {
1049 1.1 christos case 1:
1050 1.1 christos fixup.reloc = BFD_RELOC_8;
1051 1.1 christos break;
1052 1.1 christos
1053 1.1 christos case 2:
1054 1.1 christos fixup.reloc = BFD_RELOC_16;
1055 1.1 christos break;
1056 1.1 christos
1057 1.1 christos case 3:
1058 1.1 christos fixup.reloc = BFD_RELOC_24;
1059 1.1 christos break;
1060 1.1 christos
1061 1.1 christos case 4:
1062 1.1 christos fixup.reloc = BFD_RELOC_32;
1063 1.1 christos break;
1064 1.1 christos
1065 1.1 christos default:
1066 1.1 christos goto error;
1067 1.1 christos }
1068 1.1 christos else if (size != 4)
1069 1.1 christos {
1070 1.1 christos error:
1071 1.3 christos as_bad (_("unsupported BFD relocation size %u"), size);
1072 1.1 christos fixup.reloc = BFD_RELOC_UNUSED;
1073 1.1 christos }
1074 1.1 christos
1075 1.8 christos fix_new_exp (frag, off, size, &fixup.exp, 0, fixup.reloc);
1076 1.1 christos }
1077 1.1 christos
1078 1.1 christos static bool
1079 1.1 christos check_operand (const struct mn10300_operand *operand,
1080 1.1 christos offsetT val)
1081 1.1 christos {
1082 1.1 christos /* No need to check 32bit operands for a bit. Note that
1083 1.1 christos MN10300_OPERAND_SPLIT is an implicit 32bit operand. */
1084 1.1 christos if (operand->bits != 32
1085 1.1 christos && (operand->flags & MN10300_OPERAND_SPLIT) == 0)
1086 1.1 christos {
1087 1.1 christos long min, max;
1088 1.1 christos offsetT test;
1089 1.1 christos int bits;
1090 1.1 christos
1091 1.1 christos bits = operand->bits;
1092 1.1 christos if (operand->flags & MN10300_OPERAND_24BIT)
1093 1.1 christos bits = 24;
1094 1.1 christos
1095 1.1 christos if ((operand->flags & MN10300_OPERAND_SIGNED) != 0)
1096 1.1 christos {
1097 1.1 christos max = (1 << (bits - 1)) - 1;
1098 1.1 christos min = - (1 << (bits - 1));
1099 1.1 christos }
1100 1.1 christos else
1101 1.1 christos {
1102 1.1 christos max = (1 << bits) - 1;
1103 1.1 christos min = 0;
1104 1.1 christos }
1105 1.10 christos
1106 1.8 christos test = val;
1107 1.1 christos
1108 1.8 christos if (test < min || test > max)
1109 1.1 christos return false;
1110 1.1 christos }
1111 1.1 christos return true;
1112 1.1 christos }
1113 1.1 christos
1114 1.1 christos /* Insert an operand value into an instruction. */
1115 1.1 christos
1116 1.1 christos static void
1117 1.1 christos mn10300_insert_operand (unsigned long *insnp,
1118 1.1 christos unsigned long *extensionp,
1119 1.1 christos const struct mn10300_operand *operand,
1120 1.1 christos offsetT val,
1121 1.1 christos char *file,
1122 1.1 christos unsigned int line,
1123 1.1 christos unsigned int shift)
1124 1.1 christos {
1125 1.1 christos /* No need to check 32bit operands for a bit. Note that
1126 1.1 christos MN10300_OPERAND_SPLIT is an implicit 32bit operand. */
1127 1.1 christos if (operand->bits != 32
1128 1.1 christos && (operand->flags & MN10300_OPERAND_SPLIT) == 0)
1129 1.1 christos {
1130 1.1 christos long min, max;
1131 1.1 christos offsetT test;
1132 1.1 christos int bits;
1133 1.1 christos
1134 1.1 christos bits = operand->bits;
1135 1.1 christos if (operand->flags & MN10300_OPERAND_24BIT)
1136 1.1 christos bits = 24;
1137 1.1 christos
1138 1.1 christos if ((operand->flags & MN10300_OPERAND_SIGNED) != 0)
1139 1.1 christos {
1140 1.1 christos max = (1 << (bits - 1)) - 1;
1141 1.1 christos min = - (1 << (bits - 1));
1142 1.1 christos }
1143 1.1 christos else
1144 1.1 christos {
1145 1.1 christos max = (1 << bits) - 1;
1146 1.1 christos min = 0;
1147 1.1 christos }
1148 1.10 christos
1149 1.10 christos test = val;
1150 1.10 christos
1151 1.1 christos if (test < min || test > max)
1152 1.1 christos as_warn_value_out_of_range (_("operand"), test, (offsetT) min,
1153 1.1 christos (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.10 christos }
1213 1.1 christos else if ((operand->flags & MN10300_OPERAND_EXTENDED) == 0)
1214 1.1 christos {
1215 1.1 christos *insnp |= ((val & ((1 << operand->bits) - 1))
1216 1.10 christos << (operand->shift + shift));
1217 1.1 christos
1218 1.1 christos if ((operand->flags & MN10300_OPERAND_REPEATED) != 0)
1219 1.1 christos *insnp |= ((val & ((1 << operand->bits) - 1))
1220 1.1 christos << (operand->shift + shift + operand->bits));
1221 1.10 christos }
1222 1.1 christos else
1223 1.1 christos {
1224 1.1 christos *extensionp |= ((val & ((1 << operand->bits) - 1))
1225 1.10 christos << (operand->shift + shift));
1226 1.1 christos
1227 1.1 christos if ((operand->flags & MN10300_OPERAND_REPEATED) != 0)
1228 1.1 christos *extensionp |= ((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.10 christos int match;
1245 1.1 christos
1246 1.1 christos /* Get the opcode. */
1247 1.1 christos for (s = str; !is_end_of_stmt (*s) && !is_whitespace (*s); s++)
1248 1.1 christos ;
1249 1.1 christos if (*s != '\0')
1250 1.10 christos *s++ = '\0';
1251 1.1 christos
1252 1.1 christos /* Find the first opcode with the proper name. */
1253 1.1 christos 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.10 christos }
1259 1.1 christos
1260 1.1 christos str = s;
1261 1.1 christos while (is_whitespace (*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.10 christos next_opindex = 0;
1308 1.1 christos }
1309 1.1 christos
1310 1.1 christos while (is_whitespace (*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.3 christos }
1350 1.3 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.3 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.3 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.3 christos }
1401 1.3 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.3 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.3 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.3 christos }
1416 1.3 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.3 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.3 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.3 christos }
1431 1.3 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.3 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.3 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.3 christos }
1446 1.3 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.3 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.3 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.3 christos }
1461 1.3 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.3 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.3 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.3 christos }
1476 1.3 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.3 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.3 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.3 christos }
1502 1.3 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.3 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.3 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.3 christos }
1517 1.3 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.3 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.3 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.3 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.3 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.3 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.3 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.3 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.3 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.3 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.3 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.3 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.3 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.9 christos else
1673 1.1 christos {
1674 1.1 christos expression (&ex);
1675 1.1 christos resolve_register (&ex);
1676 1.1 christos }
1677 1.1 christos
1678 1.1 christos switch (ex.X_op)
1679 1.1 christos {
1680 1.1 christos case O_illegal:
1681 1.1 christos errmsg = _("illegal operand");
1682 1.1 christos goto error;
1683 1.1 christos case O_absent:
1684 1.1 christos errmsg = _("missing operand");
1685 1.1 christos goto error;
1686 1.1 christos case O_register:
1687 1.1 christos {
1688 1.1 christos int mask;
1689 1.1 christos
1690 1.1 christos mask = MN10300_OPERAND_DREG | MN10300_OPERAND_AREG;
1691 1.1 christos if (HAVE_AM33)
1692 1.1 christos mask |= MN10300_OPERAND_RREG | MN10300_OPERAND_XRREG;
1693 1.1 christos if (HAVE_AM33_2)
1694 1.1 christos mask |= MN10300_OPERAND_FSREG | MN10300_OPERAND_FDREG;
1695 1.1 christos if ((operand->flags & mask) == 0)
1696 1.1 christos {
1697 1.1 christos input_line_pointer = hold;
1698 1.1 christos str = hold;
1699 1.1 christos goto error;
1700 1.1 christos }
1701 1.1 christos
1702 1.1 christos if (opcode->format == FMT_D1 || opcode->format == FMT_S1)
1703 1.1 christos extra_shift = 8;
1704 1.1 christos else if (opcode->format == FMT_D2
1705 1.1 christos || opcode->format == FMT_D4
1706 1.1 christos || opcode->format == FMT_S2
1707 1.1 christos || opcode->format == FMT_S4
1708 1.1 christos || opcode->format == FMT_S6
1709 1.1 christos || opcode->format == FMT_D5)
1710 1.1 christos extra_shift = 16;
1711 1.1 christos else if (opcode->format == FMT_D7)
1712 1.1 christos extra_shift = 8;
1713 1.1 christos else if (opcode->format == FMT_D8 || opcode->format == FMT_D9)
1714 1.1 christos extra_shift = 8;
1715 1.1 christos else
1716 1.1 christos extra_shift = 0;
1717 1.1 christos
1718 1.1 christos mn10300_insert_operand (& insn, & extension, operand,
1719 1.1 christos ex.X_add_number, NULL,
1720 1.1 christos 0, extra_shift);
1721 1.1 christos
1722 1.1 christos /* And note the register number in the register array. */
1723 1.1 christos mn10300_reg_operands[op_idx - 1] = ex.X_add_number;
1724 1.1 christos break;
1725 1.1 christos }
1726 1.1 christos
1727 1.1 christos case O_constant:
1728 1.1 christos /* If this operand can be promoted, and it doesn't
1729 1.1 christos fit into the allocated bitfield for this insn,
1730 1.1 christos then promote it (ie this opcode does not match). */
1731 1.1 christos if (operand->flags
1732 1.1 christos & (MN10300_OPERAND_PROMOTE | MN10300_OPERAND_RELAX)
1733 1.1 christos && !check_operand (operand, ex.X_add_number))
1734 1.1 christos {
1735 1.1 christos input_line_pointer = hold;
1736 1.1 christos str = hold;
1737 1.1 christos goto error;
1738 1.1 christos }
1739 1.1 christos
1740 1.1 christos mn10300_insert_operand (& insn, & extension, operand,
1741 1.1 christos ex.X_add_number, NULL, 0, 0);
1742 1.1 christos break;
1743 1.1 christos
1744 1.1 christos default:
1745 1.1 christos /* If this operand can be promoted, then this opcode didn't
1746 1.1 christos match since we can't know if it needed promotion! */
1747 1.1 christos if (operand->flags & MN10300_OPERAND_PROMOTE)
1748 1.1 christos {
1749 1.1 christos input_line_pointer = hold;
1750 1.1 christos str = hold;
1751 1.1 christos goto error;
1752 1.1 christos }
1753 1.1 christos
1754 1.1 christos /* We need to generate a fixup for this expression. */
1755 1.1 christos if (fc >= MAX_INSN_FIXUPS)
1756 1.1 christos as_fatal (_("too many fixups"));
1757 1.1 christos fixups[fc].exp = ex;
1758 1.1 christos fixups[fc].opindex = *opindex_ptr;
1759 1.1 christos fixups[fc].reloc = BFD_RELOC_UNUSED;
1760 1.1 christos if (mn10300_check_fixup (& fixups[fc]))
1761 1.1 christos goto error;
1762 1.1 christos ++fc;
1763 1.8 christos break;
1764 1.1 christos }
1765 1.1 christos
1766 1.1 christos keep_going:
1767 1.10 christos str = input_line_pointer;
1768 1.1 christos input_line_pointer = hold;
1769 1.1 christos
1770 1.1 christos while (is_whitespace (*str) || *str == ',')
1771 1.1 christos ++str;
1772 1.1 christos }
1773 1.1 christos
1774 1.1 christos /* Make sure we used all the operands! */
1775 1.1 christos if (*str != ',')
1776 1.1 christos match = 1;
1777 1.1 christos
1778 1.1 christos /* If this instruction has registers that must not match, verify
1779 1.1 christos that they do indeed not match. */
1780 1.1 christos if (opcode->no_match_operands)
1781 1.1 christos {
1782 1.1 christos /* Look at each operand to see if it's marked. */
1783 1.1 christos for (i = 0; i < MN10300_MAX_OPERANDS; i++)
1784 1.1 christos {
1785 1.1 christos if ((1 << i) & opcode->no_match_operands)
1786 1.1 christos {
1787 1.1 christos int j;
1788 1.1 christos
1789 1.1 christos /* operand I is marked. Check that it does not match any
1790 1.1 christos operands > I which are marked. */
1791 1.1 christos for (j = i + 1; j < MN10300_MAX_OPERANDS; j++)
1792 1.1 christos {
1793 1.1 christos if (((1 << j) & opcode->no_match_operands)
1794 1.1 christos && mn10300_reg_operands[i] == mn10300_reg_operands[j])
1795 1.1 christos {
1796 1.1 christos errmsg = _("Invalid register specification.");
1797 1.1 christos match = 0;
1798 1.1 christos goto error;
1799 1.1 christos }
1800 1.1 christos }
1801 1.1 christos }
1802 1.1 christos }
1803 1.1 christos }
1804 1.1 christos
1805 1.1 christos error:
1806 1.1 christos if (match == 0)
1807 1.1 christos {
1808 1.1 christos next_opcode = opcode + 1;
1809 1.1 christos if (!strcmp (next_opcode->name, opcode->name))
1810 1.1 christos {
1811 1.1 christos opcode = next_opcode;
1812 1.1 christos continue;
1813 1.1 christos }
1814 1.1 christos
1815 1.1 christos as_bad ("%s", errmsg);
1816 1.1 christos return;
1817 1.1 christos }
1818 1.10 christos break;
1819 1.1 christos }
1820 1.1 christos
1821 1.10 christos while (is_whitespace (*str))
1822 1.1 christos ++str;
1823 1.1 christos
1824 1.1 christos if (!is_end_of_stmt (*str))
1825 1.1 christos as_bad (_("junk at end of line: `%s'"), str);
1826 1.1 christos
1827 1.1 christos input_line_pointer = str;
1828 1.1 christos
1829 1.1 christos /* Determine the size of the instruction. */
1830 1.1 christos if (opcode->format == FMT_S0)
1831 1.1 christos size = 1;
1832 1.1 christos
1833 1.1 christos if (opcode->format == FMT_S1 || opcode->format == FMT_D0)
1834 1.1 christos size = 2;
1835 1.1 christos
1836 1.1 christos if (opcode->format == FMT_S2 || opcode->format == FMT_D1)
1837 1.1 christos size = 3;
1838 1.1 christos
1839 1.1 christos if (opcode->format == FMT_D6)
1840 1.1 christos size = 3;
1841 1.1 christos
1842 1.1 christos if (opcode->format == FMT_D7 || opcode->format == FMT_D10)
1843 1.1 christos size = 4;
1844 1.1 christos
1845 1.1 christos if (opcode->format == FMT_D8)
1846 1.1 christos size = 6;
1847 1.1 christos
1848 1.1 christos if (opcode->format == FMT_D9)
1849 1.1 christos size = 7;
1850 1.1 christos
1851 1.1 christos if (opcode->format == FMT_S4)
1852 1.1 christos size = 5;
1853 1.1 christos
1854 1.1 christos if (opcode->format == FMT_S6 || opcode->format == FMT_D5)
1855 1.1 christos size = 7;
1856 1.1 christos
1857 1.1 christos if (opcode->format == FMT_D2)
1858 1.1 christos size = 4;
1859 1.1 christos
1860 1.1 christos if (opcode->format == FMT_D3)
1861 1.1 christos size = 5;
1862 1.1 christos
1863 1.1 christos if (opcode->format == FMT_D4)
1864 1.1 christos size = 6;
1865 1.1 christos
1866 1.1 christos if (relaxable && fc > 0)
1867 1.1 christos {
1868 1.1 christos /* On a 64-bit host the size of an 'int' is not the same
1869 1.6 christos as the size of a pointer, so we need a union to convert
1870 1.1 christos the opindex field of the fr_cgen structure into a char *
1871 1.1 christos so that it can be stored in the frag. We do not have
1872 1.1 christos to worry about losing accuracy as we are not going to
1873 1.1 christos be even close to the 32bit limit of the int. */
1874 1.1 christos union
1875 1.1 christos {
1876 1.1 christos int opindex;
1877 1.1 christos char * ptr;
1878 1.1 christos }
1879 1.1 christos opindex_converter;
1880 1.1 christos int type;
1881 1.1 christos
1882 1.1 christos /* We want to anchor the line info to the previous frag (if
1883 1.1 christos there isn't one, create it), so that, when the insn is
1884 1.1 christos resized, we still get the right address for the beginning of
1885 1.1 christos the region. */
1886 1.1 christos f = frag_more (0);
1887 1.1 christos dwarf2_emit_insn (0);
1888 1.1 christos
1889 1.1 christos /* bCC */
1890 1.1 christos if (size == 2)
1891 1.1 christos {
1892 1.1 christos /* Handle bra specially. Basically treat it like jmp so
1893 1.1 christos that we automatically handle 8, 16 and 32 bit offsets
1894 1.1 christos correctly as well as jumps to an undefined address.
1895 1.1 christos
1896 1.1 christos It is also important to not treat it like other bCC
1897 1.1 christos instructions since the long forms of bra is different
1898 1.1 christos from other bCC instructions. */
1899 1.1 christos if (opcode->opcode == 0xca00)
1900 1.1 christos type = 10;
1901 1.1 christos else
1902 1.1 christos type = 0;
1903 1.1 christos }
1904 1.1 christos /* call */
1905 1.1 christos else if (size == 5)
1906 1.1 christos type = 6;
1907 1.1 christos /* calls */
1908 1.1 christos else if (size == 4)
1909 1.1 christos type = 8;
1910 1.1 christos /* jmp */
1911 1.1 christos else if (size == 3 && opcode->opcode == 0xcc0000)
1912 1.1 christos type = 10;
1913 1.1 christos else if (size == 3 && (opcode->opcode & 0xfff000) == 0xf8d000)
1914 1.1 christos type = 13;
1915 1.1 christos /* bCC (uncommon cases) */
1916 1.1 christos else
1917 1.1 christos type = 3;
1918 1.1 christos
1919 1.1 christos opindex_converter.opindex = fixups[0].opindex;
1920 1.1 christos f = frag_var (rs_machine_dependent, 8, 8 - size, type,
1921 1.1 christos fixups[0].exp.X_add_symbol,
1922 1.1 christos fixups[0].exp.X_add_number,
1923 1.1 christos opindex_converter.ptr);
1924 1.1 christos
1925 1.1 christos /* This is pretty hokey. We basically just care about the
1926 1.1 christos opcode, so we have to write out the first word big endian.
1927 1.1 christos
1928 1.1 christos The exception is "call", which has two operands that we
1929 1.1 christos care about.
1930 1.1 christos
1931 1.1 christos The first operand (the register list) happens to be in the
1932 1.1 christos first instruction word, and will be in the right place if
1933 1.1 christos we output the first word in big endian mode.
1934 1.1 christos
1935 1.1 christos The second operand (stack size) is in the extension word,
1936 1.1 christos and we want it to appear as the first character in the extension
1937 1.1 christos word (as it appears in memory). Luckily, writing the extension
1938 1.1 christos word in big endian format will do what we want. */
1939 1.1 christos number_to_chars_bigendian (f, insn, size > 4 ? 4 : size);
1940 1.1 christos if (size > 8)
1941 1.1 christos {
1942 1.1 christos number_to_chars_bigendian (f + 4, extension, 4);
1943 1.1 christos number_to_chars_bigendian (f + 8, 0, size - 8);
1944 1.1 christos }
1945 1.1 christos else if (size > 4)
1946 1.1 christos number_to_chars_bigendian (f + 4, extension, size - 4);
1947 1.1 christos }
1948 1.1 christos else
1949 1.1 christos {
1950 1.1 christos /* Allocate space for the instruction. */
1951 1.1 christos f = frag_more (size);
1952 1.1 christos
1953 1.1 christos /* Fill in bytes for the instruction. Note that opcode fields
1954 1.1 christos are written big-endian, 16 & 32bit immediates are written
1955 1.1 christos little endian. Egad. */
1956 1.1 christos if (opcode->format == FMT_S0
1957 1.1 christos || opcode->format == FMT_S1
1958 1.1 christos || opcode->format == FMT_D0
1959 1.1 christos || opcode->format == FMT_D6
1960 1.1 christos || opcode->format == FMT_D7
1961 1.1 christos || opcode->format == FMT_D10
1962 1.1 christos || opcode->format == FMT_D1)
1963 1.1 christos {
1964 1.1 christos number_to_chars_bigendian (f, insn, size);
1965 1.1 christos }
1966 1.1 christos else if (opcode->format == FMT_S2
1967 1.1 christos && opcode->opcode != 0xdf0000
1968 1.1 christos && opcode->opcode != 0xde0000)
1969 1.1 christos {
1970 1.1 christos /* A format S2 instruction that is _not_ "ret" and "retf". */
1971 1.1 christos number_to_chars_bigendian (f, (insn >> 16) & 0xff, 1);
1972 1.1 christos number_to_chars_littleendian (f + 1, insn & 0xffff, 2);
1973 1.1 christos }
1974 1.1 christos else if (opcode->format == FMT_S2)
1975 1.1 christos {
1976 1.1 christos /* This must be a ret or retf, which is written entirely in
1977 1.1 christos big-endian format. */
1978 1.1 christos number_to_chars_bigendian (f, insn, 3);
1979 1.1 christos }
1980 1.1 christos else if (opcode->format == FMT_S4
1981 1.1 christos && opcode->opcode != 0xdc000000)
1982 1.1 christos {
1983 1.1 christos /* This must be a format S4 "call" instruction. What a pain. */
1984 1.1 christos unsigned long temp = (insn >> 8) & 0xffff;
1985 1.1 christos number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
1986 1.1 christos number_to_chars_littleendian (f + 1, temp, 2);
1987 1.1 christos number_to_chars_bigendian (f + 3, insn & 0xff, 1);
1988 1.1 christos number_to_chars_bigendian (f + 4, extension & 0xff, 1);
1989 1.1 christos }
1990 1.1 christos else if (opcode->format == FMT_S4)
1991 1.1 christos {
1992 1.1 christos /* This must be a format S4 "jmp" instruction. */
1993 1.1 christos unsigned long temp = ((insn & 0xffffff) << 8) | (extension & 0xff);
1994 1.1 christos number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
1995 1.1 christos number_to_chars_littleendian (f + 1, temp, 4);
1996 1.1 christos }
1997 1.1 christos else if (opcode->format == FMT_S6)
1998 1.1 christos {
1999 1.1 christos unsigned long temp = ((insn & 0xffffff) << 8)
2000 1.1 christos | ((extension >> 16) & 0xff);
2001 1.1 christos number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
2002 1.1 christos number_to_chars_littleendian (f + 1, temp, 4);
2003 1.1 christos number_to_chars_bigendian (f + 5, (extension >> 8) & 0xff, 1);
2004 1.1 christos number_to_chars_bigendian (f + 6, extension & 0xff, 1);
2005 1.1 christos }
2006 1.1 christos else if (opcode->format == FMT_D2
2007 1.1 christos && opcode->opcode != 0xfaf80000
2008 1.1 christos && opcode->opcode != 0xfaf00000
2009 1.1 christos && opcode->opcode != 0xfaf40000)
2010 1.1 christos {
2011 1.1 christos /* A format D2 instruction where the 16bit immediate is
2012 1.1 christos really a single 16bit value, not two 8bit values. */
2013 1.1 christos number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
2014 1.1 christos number_to_chars_littleendian (f + 2, insn & 0xffff, 2);
2015 1.1 christos }
2016 1.1 christos else if (opcode->format == FMT_D2)
2017 1.1 christos {
2018 1.1 christos /* A format D2 instruction where the 16bit immediate
2019 1.1 christos is really two 8bit immediates. */
2020 1.1 christos number_to_chars_bigendian (f, insn, 4);
2021 1.1 christos }
2022 1.1 christos else if (opcode->format == FMT_D3)
2023 1.1 christos {
2024 1.1 christos number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
2025 1.1 christos number_to_chars_littleendian (f + 2, insn & 0xffff, 2);
2026 1.1 christos number_to_chars_bigendian (f + 4, extension & 0xff, 1);
2027 1.1 christos }
2028 1.1 christos else if (opcode->format == FMT_D4)
2029 1.1 christos {
2030 1.1 christos unsigned long temp = ((insn & 0xffff) << 16) | (extension & 0xffff);
2031 1.1 christos
2032 1.1 christos number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
2033 1.1 christos number_to_chars_littleendian (f + 2, temp, 4);
2034 1.1 christos }
2035 1.1 christos else if (opcode->format == FMT_D5)
2036 1.1 christos {
2037 1.1 christos unsigned long temp = (((insn & 0xffff) << 16)
2038 1.1 christos | ((extension >> 8) & 0xffff));
2039 1.1 christos
2040 1.1 christos number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
2041 1.1 christos number_to_chars_littleendian (f + 2, temp, 4);
2042 1.1 christos number_to_chars_bigendian (f + 6, extension & 0xff, 1);
2043 1.1 christos }
2044 1.1 christos else if (opcode->format == FMT_D8)
2045 1.1 christos {
2046 1.1 christos unsigned long temp = ((insn & 0xff) << 16) | (extension & 0xffff);
2047 1.1 christos
2048 1.1 christos number_to_chars_bigendian (f, (insn >> 8) & 0xffffff, 3);
2049 1.1 christos number_to_chars_bigendian (f + 3, (temp & 0xff), 1);
2050 1.1 christos number_to_chars_littleendian (f + 4, temp >> 8, 2);
2051 1.1 christos }
2052 1.1 christos else if (opcode->format == FMT_D9)
2053 1.1 christos {
2054 1.1 christos unsigned long temp = ((insn & 0xff) << 24) | (extension & 0xffffff);
2055 1.1 christos
2056 1.1 christos number_to_chars_bigendian (f, (insn >> 8) & 0xffffff, 3);
2057 1.1 christos number_to_chars_littleendian (f + 3, temp, 4);
2058 1.1 christos }
2059 1.1 christos
2060 1.1 christos /* Create any fixups. */
2061 1.1 christos for (i = 0; i < fc; i++)
2062 1.1 christos {
2063 1.1 christos const struct mn10300_operand *operand;
2064 1.1 christos int reloc_size;
2065 1.1 christos
2066 1.1 christos operand = &mn10300_operands[fixups[i].opindex];
2067 1.1 christos if (fixups[i].reloc != BFD_RELOC_UNUSED
2068 1.1 christos && fixups[i].reloc != BFD_RELOC_32_GOT_PCREL
2069 1.1 christos && fixups[i].reloc != BFD_RELOC_32_GOTOFF
2070 1.1 christos && fixups[i].reloc != BFD_RELOC_32_PLT_PCREL
2071 1.1 christos && fixups[i].reloc != BFD_RELOC_MN10300_TLS_GD
2072 1.1 christos && fixups[i].reloc != BFD_RELOC_MN10300_TLS_LD
2073 1.1 christos && fixups[i].reloc != BFD_RELOC_MN10300_TLS_LDO
2074 1.1 christos && fixups[i].reloc != BFD_RELOC_MN10300_TLS_GOTIE
2075 1.1 christos && fixups[i].reloc != BFD_RELOC_MN10300_TLS_IE
2076 1.1 christos && fixups[i].reloc != BFD_RELOC_MN10300_TLS_LE
2077 1.1 christos && fixups[i].reloc != BFD_RELOC_MN10300_GOT32)
2078 1.1 christos {
2079 1.1 christos reloc_howto_type *reloc_howto;
2080 1.1 christos int offset;
2081 1.1 christos
2082 1.1 christos reloc_howto = bfd_reloc_type_lookup (stdoutput,
2083 1.1 christos fixups[i].reloc);
2084 1.1 christos
2085 1.1 christos if (!reloc_howto)
2086 1.1 christos abort ();
2087 1.1 christos
2088 1.1 christos reloc_size = bfd_get_reloc_size (reloc_howto);
2089 1.1 christos
2090 1.1 christos if (reloc_size < 1 || reloc_size > 4)
2091 1.1 christos abort ();
2092 1.1 christos
2093 1.1 christos offset = 4 - size;
2094 1.1 christos fix_new_exp (frag_now, f - frag_now->fr_literal + offset,
2095 1.1 christos reloc_size, &fixups[i].exp,
2096 1.1 christos reloc_howto->pc_relative,
2097 1.1 christos fixups[i].reloc);
2098 1.1 christos }
2099 1.1 christos else
2100 1.1 christos {
2101 1.1 christos int reloc, pcrel, offset;
2102 1.1 christos fixS *fixP;
2103 1.1 christos
2104 1.1 christos reloc = BFD_RELOC_NONE;
2105 1.1 christos if (fixups[i].reloc != BFD_RELOC_UNUSED)
2106 1.1 christos reloc = fixups[i].reloc;
2107 1.1 christos /* How big is the reloc? Remember SPLIT relocs are
2108 1.1 christos implicitly 32bits. */
2109 1.1 christos if ((operand->flags & MN10300_OPERAND_SPLIT) != 0)
2110 1.1 christos reloc_size = 32;
2111 1.1 christos else if ((operand->flags & MN10300_OPERAND_24BIT) != 0)
2112 1.1 christos reloc_size = 24;
2113 1.1 christos else
2114 1.1 christos reloc_size = operand->bits;
2115 1.1 christos
2116 1.1 christos /* Is the reloc pc-relative? */
2117 1.1 christos pcrel = (operand->flags & MN10300_OPERAND_PCREL) != 0;
2118 1.1 christos if (reloc != BFD_RELOC_NONE)
2119 1.1 christos pcrel = bfd_reloc_type_lookup (stdoutput, reloc)->pc_relative;
2120 1.1 christos
2121 1.1 christos offset = size - (reloc_size + operand->shift) / 8;
2122 1.1 christos
2123 1.1 christos /* Choose a proper BFD relocation type. */
2124 1.1 christos if (reloc != BFD_RELOC_NONE)
2125 1.1 christos ;
2126 1.1 christos else if (pcrel)
2127 1.1 christos {
2128 1.1 christos if (reloc_size == 32)
2129 1.1 christos reloc = BFD_RELOC_32_PCREL;
2130 1.1 christos else if (reloc_size == 16)
2131 1.1 christos reloc = BFD_RELOC_16_PCREL;
2132 1.1 christos else if (reloc_size == 8)
2133 1.1 christos reloc = BFD_RELOC_8_PCREL;
2134 1.1 christos else
2135 1.1 christos abort ();
2136 1.1 christos }
2137 1.1 christos else
2138 1.1 christos {
2139 1.1 christos if (reloc_size == 32)
2140 1.1 christos reloc = BFD_RELOC_32;
2141 1.1 christos else if (reloc_size == 16)
2142 1.1 christos reloc = BFD_RELOC_16;
2143 1.1 christos else if (reloc_size == 8)
2144 1.1 christos reloc = BFD_RELOC_8;
2145 1.1 christos else
2146 1.1 christos abort ();
2147 1.1 christos }
2148 1.10 christos
2149 1.1 christos fixP = fix_new_exp (frag_now, f - frag_now->fr_literal + offset,
2150 1.1 christos reloc_size / 8, &fixups[i].exp, pcrel,
2151 1.1 christos reloc);
2152 1.1 christos
2153 1.1 christos if (pcrel)
2154 1.1 christos fixP->fx_offset += offset;
2155 1.1 christos }
2156 1.1 christos }
2157 1.1 christos
2158 1.1 christos dwarf2_emit_insn (size);
2159 1.8 christos }
2160 1.1 christos
2161 1.1 christos /* Label this frag as one that contains instructions. */
2162 1.1 christos frag_now->tc_frag_data = true;
2163 1.1 christos }
2164 1.1 christos
2165 1.1 christos /* If while processing a fixup, a reloc really needs to be created
2166 1.1 christos then it is done here. */
2167 1.1 christos
2168 1.1 christos arelent **
2169 1.1 christos tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp)
2170 1.1 christos {
2171 1.1 christos static arelent * no_relocs = NULL;
2172 1.10 christos static arelent * relocs[MAX_RELOC_EXPANSION + 1];
2173 1.1 christos arelent *reloc;
2174 1.1 christos
2175 1.1 christos reloc = notes_alloc (sizeof (arelent));
2176 1.1 christos
2177 1.1 christos reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
2178 1.1 christos if (reloc->howto == NULL)
2179 1.1 christos {
2180 1.10 christos as_bad_where (fixp->fx_file, fixp->fx_line,
2181 1.1 christos _("reloc %d not supported by object file format"),
2182 1.1 christos (int) fixp->fx_r_type);
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.10 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 = notes_alloc (sizeof (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.10 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.3 christos reloc2->sym_ptr_ptr = notes_alloc (sizeof (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.10 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;
2226 1.10 christos }
2227 1.1 christos else
2228 1.1 christos {
2229 1.1 christos reloc->sym_ptr_ptr = notes_alloc (sizeof (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.10 christos break;
2261 1.1 christos
2262 1.1 christos default:
2263 1.1 christos reloc->sym_ptr_ptr = &bfd_abs_section_ptr->symbol;
2264 1.10 christos return relocs;
2265 1.1 christos }
2266 1.1 christos
2267 1.1 christos return &no_relocs;
2268 1.1 christos }
2269 1.10 christos }
2270 1.1 christos else
2271 1.1 christos {
2272 1.1 christos reloc->sym_ptr_ptr = notes_alloc (sizeof (asymbol *));
2273 1.1 christos *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2274 1.1 christos reloc->addend = fixp->fx_offset;
2275 1.1 christos }
2276 1.1 christos return relocs;
2277 1.1 christos }
2278 1.1 christos
2279 1.8 christos /* Returns true iff the symbol attached to the frag is at a known location
2280 1.1 christos in the given section, (and hence the relocation to it can be relaxed by
2281 1.1 christos the assembler). */
2282 1.1 christos static inline bool
2283 1.3 christos has_known_symbol_location (fragS * fragp, asection * sec)
2284 1.1 christos {
2285 1.1 christos symbolS * sym = fragp->fr_symbol;
2286 1.1 christos
2287 1.1 christos return sym != NULL
2288 1.1 christos && S_IS_DEFINED (sym)
2289 1.1 christos && ! S_IS_WEAK (sym)
2290 1.1 christos && S_GET_SEGMENT (sym) == sec;
2291 1.1 christos }
2292 1.1 christos
2293 1.1 christos int
2294 1.1 christos md_estimate_size_before_relax (fragS *fragp, asection *seg)
2295 1.1 christos {
2296 1.1 christos if (fragp->fr_subtype == 6
2297 1.1 christos && ! has_known_symbol_location (fragp, seg))
2298 1.1 christos fragp->fr_subtype = 7;
2299 1.1 christos else if (fragp->fr_subtype == 8
2300 1.1 christos && ! has_known_symbol_location (fragp, seg))
2301 1.1 christos fragp->fr_subtype = 9;
2302 1.1 christos else if (fragp->fr_subtype == 10
2303 1.1 christos && ! has_known_symbol_location (fragp, seg))
2304 1.1 christos fragp->fr_subtype = 12;
2305 1.1 christos
2306 1.1 christos if (fragp->fr_subtype == 13)
2307 1.1 christos return 3;
2308 1.1 christos
2309 1.1 christos if (fragp->fr_subtype >= sizeof (md_relax_table) / sizeof (md_relax_table[0]))
2310 1.1 christos abort ();
2311 1.1 christos
2312 1.1 christos return md_relax_table[fragp->fr_subtype].rlx_length;
2313 1.1 christos }
2314 1.1 christos
2315 1.10 christos long
2316 1.1 christos md_pcrel_from (fixS *fixp)
2317 1.1 christos {
2318 1.1 christos if (fixp->fx_addsy != NULL
2319 1.1 christos && (!S_IS_DEFINED (fixp->fx_addsy) || S_IS_WEAK (fixp->fx_addsy)))
2320 1.1 christos /* The symbol is undefined or weak. Let the linker figure it out. */
2321 1.1 christos return 0;
2322 1.1 christos
2323 1.1 christos return fixp->fx_frag->fr_address + fixp->fx_where;
2324 1.1 christos }
2325 1.1 christos
2326 1.1 christos void
2327 1.1 christos md_apply_fix (fixS * fixP, valueT * valP, segT seg)
2328 1.10 christos {
2329 1.1 christos char * fixpos = fixP->fx_where + fixP->fx_frag->fr_literal;
2330 1.1 christos int size = 0;
2331 1.1 christos int value = *valP;
2332 1.1 christos
2333 1.1 christos gas_assert (fixP->fx_r_type < BFD_RELOC_UNUSED);
2334 1.1 christos
2335 1.1 christos /* This should never happen. */
2336 1.1 christos if (seg->flags & SEC_ALLOC)
2337 1.1 christos abort ();
2338 1.1 christos
2339 1.1 christos /* The value we are passed in *valuep includes the symbol values.
2340 1.1 christos If we are doing this relocation the code in write.c is going to
2341 1.1 christos call bfd_install_relocation, which is also going to use the symbol
2342 1.1 christos value. That means that if the reloc is fully resolved we want to
2343 1.1 christos use *valuep since bfd_install_relocation is not being used.
2344 1.1 christos
2345 1.1 christos However, if the reloc is not fully resolved we do not want to use
2346 1.1 christos *valuep, and must use fx_offset instead. However, if the reloc
2347 1.1 christos is PC relative, we do want to use *valuep since it includes the
2348 1.1 christos result of md_pcrel_from. */
2349 1.1 christos if (fixP->fx_addsy != NULL && ! fixP->fx_pcrel)
2350 1.1 christos value = fixP->fx_offset;
2351 1.1 christos
2352 1.1 christos /* If the fix is relative to a symbol which is not defined, or not
2353 1.1 christos in the same segment as the fix, we cannot resolve it here. */
2354 1.1 christos if (fixP->fx_addsy != NULL
2355 1.1 christos && (! S_IS_DEFINED (fixP->fx_addsy)
2356 1.1 christos || (S_GET_SEGMENT (fixP->fx_addsy) != seg)))
2357 1.1 christos {
2358 1.1 christos fixP->fx_done = 0;
2359 1.1 christos return;
2360 1.1 christos }
2361 1.1 christos
2362 1.1 christos switch (fixP->fx_r_type)
2363 1.1 christos {
2364 1.1 christos case BFD_RELOC_8:
2365 1.1 christos case BFD_RELOC_8_PCREL:
2366 1.1 christos size = 1;
2367 1.1 christos break;
2368 1.1 christos
2369 1.1 christos case BFD_RELOC_16:
2370 1.1 christos case BFD_RELOC_16_PCREL:
2371 1.1 christos size = 2;
2372 1.1 christos break;
2373 1.1 christos
2374 1.1 christos case BFD_RELOC_32:
2375 1.1 christos case BFD_RELOC_32_PCREL:
2376 1.1 christos size = 4;
2377 1.1 christos break;
2378 1.1 christos
2379 1.1 christos case BFD_RELOC_VTABLE_INHERIT:
2380 1.1 christos case BFD_RELOC_VTABLE_ENTRY:
2381 1.1 christos fixP->fx_done = 0;
2382 1.1 christos return;
2383 1.1 christos
2384 1.3 christos case BFD_RELOC_MN10300_ALIGN:
2385 1.1 christos fixP->fx_done = 1;
2386 1.1 christos return;
2387 1.1 christos
2388 1.1 christos case BFD_RELOC_NONE:
2389 1.1 christos default:
2390 1.1 christos as_bad_where (fixP->fx_file, fixP->fx_line,
2391 1.1 christos _("Bad relocation fixup type (%d)"), fixP->fx_r_type);
2392 1.1 christos }
2393 1.1 christos
2394 1.1 christos md_number_to_chars (fixpos, value, size);
2395 1.1 christos
2396 1.1 christos /* If a symbol remains, pass the fixup, as a reloc, onto the linker. */
2397 1.1 christos if (fixP->fx_addsy == NULL)
2398 1.1 christos fixP->fx_done = 1;
2399 1.1 christos }
2400 1.1 christos
2401 1.8 christos /* Return zero if the fixup in fixp should be left alone and not
2402 1.1 christos adjusted. */
2403 1.1 christos
2404 1.1 christos bool
2405 1.1 christos mn10300_fix_adjustable (struct fix *fixp)
2406 1.1 christos {
2407 1.8 christos if (fixp->fx_pcrel)
2408 1.1 christos {
2409 1.1 christos if (TC_FORCE_RELOCATION_LOCAL (fixp))
2410 1.1 christos return false;
2411 1.1 christos }
2412 1.8 christos /* Non-relative relocs can (and must) be adjusted if they do
2413 1.1 christos not meet the criteria below, or the generic criteria. */
2414 1.1 christos else if (TC_FORCE_RELOCATION (fixp))
2415 1.1 christos return false;
2416 1.1 christos
2417 1.1 christos /* Do not adjust relocations involving symbols in code sections,
2418 1.1 christos because it breaks linker relaxations. This could be fixed in the
2419 1.8 christos linker, but this fix is simpler, and it pretty much only affects
2420 1.1 christos object size a little bit. */
2421 1.1 christos if (S_GET_SEGMENT (fixp->fx_addsy)->flags & SEC_CODE)
2422 1.1 christos return false;
2423 1.6 christos
2424 1.1 christos /* Likewise, do not adjust symbols that won't be merged, or debug
2425 1.1 christos symbols, because they too break relaxation. We do want to adjust
2426 1.8 christos other mergeable symbols, like .rodata, because code relaxations
2427 1.1 christos need section-relative symbols to properly relax them. */
2428 1.8 christos if (! (S_GET_SEGMENT (fixp->fx_addsy)->flags & SEC_MERGE))
2429 1.8 christos return false;
2430 1.1 christos
2431 1.8 christos if (startswith (S_GET_SEGMENT (fixp->fx_addsy)->name, ".debug"))
2432 1.1 christos return false;
2433 1.1 christos
2434 1.1 christos return true;
2435 1.1 christos }
2436 1.1 christos
2437 1.1 christos static void
2438 1.1 christos set_arch_mach (int mach)
2439 1.1 christos {
2440 1.1 christos if (!bfd_set_arch_mach (stdoutput, bfd_arch_mn10300, mach))
2441 1.1 christos as_warn (_("could not set architecture and machine"));
2442 1.1 christos
2443 1.1 christos current_machine = mach;
2444 1.5 christos }
2445 1.1 christos
2446 1.1 christos static inline char *
2447 1.1 christos mn10300_end_of_match (char *cont, const char *what)
2448 1.8 christos {
2449 1.1 christos int len = strlen (what);
2450 1.1 christos
2451 1.1 christos if (startswith (cont, what)
2452 1.1 christos && ! is_part_of_name (cont[len]))
2453 1.3 christos return cont + len;
2454 1.1 christos
2455 1.1 christos return NULL;
2456 1.1 christos }
2457 1.1 christos
2458 1.1 christos int
2459 1.1 christos mn10300_parse_name (char const *name,
2460 1.1 christos expressionS *exprP,
2461 1.1 christos enum expr_mode mode,
2462 1.1 christos char *nextcharP)
2463 1.1 christos {
2464 1.1 christos char *next = input_line_pointer;
2465 1.1 christos char *next_end;
2466 1.1 christos int reloc_type;
2467 1.1 christos segT segment;
2468 1.1 christos
2469 1.1 christos exprP->X_op_symbol = NULL;
2470 1.1 christos
2471 1.1 christos if (strcmp (name, GLOBAL_OFFSET_TABLE_NAME) == 0)
2472 1.1 christos {
2473 1.1 christos if (! GOT_symbol)
2474 1.1 christos GOT_symbol = symbol_find_or_make (name);
2475 1.1 christos
2476 1.1 christos exprP->X_add_symbol = GOT_symbol;
2477 1.1 christos no_suffix:
2478 1.10 christos /* If we have an absolute symbol or a reg,
2479 1.1 christos then we know its value now. */
2480 1.1 christos segment = S_GET_SEGMENT (exprP->X_add_symbol);
2481 1.1 christos if (!expr_defer_p (mode) && segment == absolute_section)
2482 1.1 christos {
2483 1.1 christos exprP->X_op = O_constant;
2484 1.10 christos exprP->X_add_number = S_GET_VALUE (exprP->X_add_symbol);
2485 1.1 christos exprP->X_add_symbol = NULL;
2486 1.1 christos }
2487 1.1 christos else if (!expr_defer_p (mode) && segment == reg_section)
2488 1.1 christos {
2489 1.1 christos exprP->X_op = O_register;
2490 1.1 christos exprP->X_add_number = S_GET_VALUE (exprP->X_add_symbol);
2491 1.1 christos exprP->X_add_symbol = NULL;
2492 1.1 christos }
2493 1.1 christos else
2494 1.1 christos {
2495 1.1 christos exprP->X_op = O_symbol;
2496 1.1 christos exprP->X_add_number = 0;
2497 1.1 christos }
2498 1.1 christos
2499 1.1 christos return 1;
2500 1.3 christos }
2501 1.1 christos
2502 1.1 christos exprP->X_add_symbol = symbol_find_or_make (name);
2503 1.1 christos
2504 1.1 christos if (*nextcharP != '@')
2505 1.1 christos goto no_suffix;
2506 1.1 christos else if ((next_end = mn10300_end_of_match (next + 1, "GOTOFF")))
2507 1.1 christos reloc_type = BFD_RELOC_32_GOTOFF;
2508 1.1 christos else if ((next_end = mn10300_end_of_match (next + 1, "GOT")))
2509 1.1 christos reloc_type = BFD_RELOC_MN10300_GOT32;
2510 1.1 christos else if ((next_end = mn10300_end_of_match (next + 1, "PLT")))
2511 1.1 christos reloc_type = BFD_RELOC_32_PLT_PCREL;
2512 1.1 christos else if ((next_end = mn10300_end_of_match (next + 1, "tlsgd")))
2513 1.1 christos reloc_type = BFD_RELOC_MN10300_TLS_GD;
2514 1.1 christos else if ((next_end = mn10300_end_of_match (next + 1, "tlsldm")))
2515 1.1 christos reloc_type = BFD_RELOC_MN10300_TLS_LD;
2516 1.1 christos else if ((next_end = mn10300_end_of_match (next + 1, "dtpoff")))
2517 1.1 christos reloc_type = BFD_RELOC_MN10300_TLS_LDO;
2518 1.1 christos else if ((next_end = mn10300_end_of_match (next + 1, "gotntpoff")))
2519 1.1 christos reloc_type = BFD_RELOC_MN10300_TLS_GOTIE;
2520 1.1 christos else if ((next_end = mn10300_end_of_match (next + 1, "indntpoff")))
2521 1.1 christos reloc_type = BFD_RELOC_MN10300_TLS_IE;
2522 1.1 christos else if ((next_end = mn10300_end_of_match (next + 1, "tpoff")))
2523 1.1 christos reloc_type = BFD_RELOC_MN10300_TLS_LE;
2524 1.1 christos else
2525 1.1 christos goto no_suffix;
2526 1.1 christos
2527 1.1 christos *input_line_pointer = *nextcharP;
2528 1.1 christos input_line_pointer = next_end;
2529 1.1 christos *nextcharP = *input_line_pointer;
2530 1.1 christos *input_line_pointer = '\0';
2531 1.1 christos
2532 1.1 christos exprP->X_op = O_PIC_reloc;
2533 1.1 christos exprP->X_add_number = 0;
2534 1.1 christos exprP->X_md = reloc_type;
2535 1.1 christos
2536 1.1 christos return 1;
2537 1.1 christos }
2538 1.1 christos
2539 1.1 christos /* The target specific pseudo-ops which we support. */
2540 1.1 christos const pseudo_typeS md_pseudo_table[] =
2541 1.1 christos {
2542 1.1 christos { "am30", set_arch_mach, AM30 },
2543 1.1 christos { "am33", set_arch_mach, AM33 },
2544 1.1 christos { "am33_2", set_arch_mach, AM33_2 },
2545 1.1 christos { "mn10300", set_arch_mach, MN103 },
2546 1.1 christos {NULL, 0, 0}
2547 1.1 christos };
2548 1.1 christos
2549 1.1 christos /* Returns FALSE if there is some mn10300 specific reason why the
2550 1.8 christos subtraction of two same-section symbols cannot be computed by
2551 1.1 christos the assembler. */
2552 1.1 christos
2553 1.8 christos bool
2554 1.1 christos mn10300_allow_local_subtract (expressionS * left, expressionS * right, segT section)
2555 1.1 christos {
2556 1.1 christos bool result;
2557 1.1 christos fragS * left_frag;
2558 1.1 christos fragS * right_frag;
2559 1.1 christos fragS * frag;
2560 1.1 christos
2561 1.8 christos /* If we are not performing linker relaxation then we have nothing
2562 1.1 christos to worry about. */
2563 1.1 christos if (linkrelax == 0)
2564 1.1 christos return true;
2565 1.8 christos
2566 1.1 christos /* If the symbols are not in a code section then they are OK. */
2567 1.1 christos if ((section->flags & SEC_CODE) == 0)
2568 1.1 christos return true;
2569 1.1 christos
2570 1.1 christos /* Otherwise we have to scan the fragments between the two symbols.
2571 1.1 christos If any instructions are found then we have to assume that linker
2572 1.1 christos relaxation may change their size and so we must delay resolving
2573 1.1 christos the subtraction until the final link. */
2574 1.1 christos left_frag = symbol_get_frag (left->X_add_symbol);
2575 1.1 christos right_frag = symbol_get_frag (right->X_add_symbol);
2576 1.1 christos
2577 1.8 christos if (left_frag == right_frag)
2578 1.1 christos return ! left_frag->tc_frag_data;
2579 1.1 christos
2580 1.1 christos result = true;
2581 1.8 christos for (frag = left_frag; frag != NULL; frag = frag->fr_next)
2582 1.1 christos {
2583 1.1 christos if (frag->tc_frag_data)
2584 1.1 christos result = false;
2585 1.1 christos if (frag == right_frag)
2586 1.1 christos break;
2587 1.1 christos }
2588 1.1 christos
2589 1.1 christos if (frag == NULL)
2590 1.8 christos for (frag = right_frag; frag != NULL; frag = frag->fr_next)
2591 1.1 christos {
2592 1.1 christos if (frag->tc_frag_data)
2593 1.1 christos result = false;
2594 1.1 christos if (frag == left_frag)
2595 1.1 christos break;
2596 1.1 christos }
2597 1.1 christos
2598 1.8 christos if (frag == NULL)
2599 1.1 christos /* The two symbols are on disjoint fragment chains
2600 1.1 christos - we cannot possibly compute their difference. */
2601 1.1 christos return false;
2602 1.1 christos
2603 1.1 christos return result;
2604 1.1 christos }
2605 1.1 christos
2606 1.1 christos /* When relaxing, we need to output a reloc for any .align directive
2607 1.1 christos that requests alignment to a two byte boundary or larger. */
2608 1.1 christos
2609 1.1 christos void
2610 1.1 christos mn10300_handle_align (fragS *frag)
2611 1.1 christos {
2612 1.1 christos if (linkrelax
2613 1.1 christos && (frag->fr_type == rs_align
2614 1.1 christos || frag->fr_type == rs_align_code)
2615 1.1 christos && frag->fr_address + frag->fr_fix > 0
2616 1.1 christos && frag->fr_offset > 1
2617 1.7 christos && now_seg != bss_section
2618 1.1 christos /* Do not create relocs for the merging sections - such
2619 1.6 christos relocs will prevent the contents from being merged. */
2620 1.1 christos && (bfd_section_flags (now_seg) & SEC_MERGE) == 0)
2621 1.1 christos /* Create a new fixup to record the alignment request. The symbol is
2622 1.1 christos irrelevant but must be present so we use the absolute section symbol.
2623 1.8 christos The offset from the symbol is used to record the power-of-two alignment
2624 1.1 christos value. The size is set to 0 because the frag may already be aligned,
2625 1.1 christos thus causing cvt_frag_to_fill to reduce the size of the frag to zero. */
2626 1.1 christos fix_new (frag, frag->fr_fix, 0, & abs_symbol, frag->fr_offset, false,
2627 1.8 christos BFD_RELOC_MN10300_ALIGN);
2628 1.1 christos }
2629 1.1 christos
2630 1.1 christos bool
2631 1.1 christos mn10300_force_relocation (struct fix * fixp)
2632 1.1 christos {
2633 1.8 christos if (linkrelax
2634 1.1 christos && (fixp->fx_pcrel
2635 1.1 christos || fixp->fx_r_type == BFD_RELOC_MN10300_ALIGN))
2636 1.1 christos return true;
2637
2638 return generic_force_reloc (fixp);
2639 }
2640