Commit | Line | Data |
---|---|---|
3b16e843 | 1 | /* Assembly backend for the OpenRISC 1000. |
aa820537 | 2 | Copyright (C) 2002, 2003, 2005, 2007, 2009 |
541d2ffd | 3 | Free Software Foundation, Inc. |
3b16e843 NC |
4 | Contributed by Damjan Lampret <lampret@opencores.org>. |
5 | Modified bu Johan Rydberg, <johan.rydberg@netinsight.se>. | |
6 | Based upon a29k port. | |
7 | ||
8 | This file is part of GAS, the GNU Assembler. | |
9 | ||
10 | GAS is free software; you can redistribute it and/or modify | |
11 | it under the terms of the GNU General Public License as published by | |
ec2655a6 | 12 | the Free Software Foundation; either version 3, or (at your option) |
3b16e843 NC |
13 | any later version. |
14 | ||
15 | GAS is distributed in the hope that it will be useful, | |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU General Public License | |
21 | along with GAS; see the file COPYING. If not, write to | |
4b4da160 NC |
22 | the Free Software Foundation, 51 Franklin Street - Fifth Floor, |
23 | Boston, MA 02110-1301, USA. */ | |
3b16e843 NC |
24 | |
25 | /* tc-a29k.c used as a template. */ | |
26 | ||
27 | #include "safe-ctype.h" | |
28 | #include "as.h" | |
29 | #include "opcode/or32.h" | |
5d6255fe | 30 | #include "elf/or32.h" |
3b16e843 NC |
31 | |
32 | #define DEBUG 0 | |
33 | ||
34 | #ifndef REGISTER_PREFIX | |
35 | #define REGISTER_PREFIX '%' | |
36 | #endif | |
37 | ||
38 | /* Make it easier to clone this machine desc into another one. */ | |
39 | #define machine_opcode or32_opcode | |
40 | #define machine_opcodes or32_opcodes | |
41 | #define machine_ip or32_ip | |
42 | #define machine_it or32_it | |
43 | ||
44 | /* Handle of the OPCODE hash table. */ | |
45 | static struct hash_control *op_hash = NULL; | |
46 | ||
47 | struct machine_it | |
ea1562b3 NC |
48 | { |
49 | char * error; | |
50 | unsigned long opcode; | |
51 | struct nlist * nlistp; | |
52 | expressionS exp; | |
53 | int pcrel; | |
54 | int reloc_offset; /* Offset of reloc within insn. */ | |
55 | int reloc; | |
56 | } | |
3b16e843 NC |
57 | the_insn; |
58 | ||
3b16e843 | 59 | const pseudo_typeS md_pseudo_table[] = |
ea1562b3 NC |
60 | { |
61 | {"align", s_align_bytes, 4 }, | |
62 | {"space", s_space, 0 }, | |
63 | {"cputype", s_ignore, 0 }, | |
64 | {"reg", s_lsym, 0 }, /* Register equate, same as equ. */ | |
65 | {"sect", s_ignore, 0 }, /* Creation of coff sections. */ | |
66 | {"proc", s_ignore, 0 }, /* Start of a function. */ | |
67 | {"endproc", s_ignore, 0 }, /* Function end. */ | |
68 | {"word", cons, 4 }, | |
69 | {NULL, 0, 0 }, | |
70 | }; | |
3b16e843 NC |
71 | |
72 | int md_short_jump_size = 4; | |
73 | int md_long_jump_size = 4; | |
74 | ||
3b16e843 NC |
75 | /* This array holds the chars that always start a comment. |
76 | If the pre-processor is disabled, these aren't very useful. */ | |
77 | const char comment_chars[] = "#"; | |
78 | ||
79 | /* This array holds the chars that only start a comment at the beginning of | |
80 | a line. If the line seems to have the form '# 123 filename' | |
81 | .line and .file directives will appear in the pre-processed output. */ | |
82 | /* Note that input_file.c hand checks for '#' at the beginning of the | |
83 | first line of the input file. This is because the compiler outputs | |
84 | #NO_APP at the beginning of its output. */ | |
85 | /* Also note that comments like this one will always work. */ | |
86 | const char line_comment_chars[] = "#"; | |
87 | ||
88 | /* We needed an unused char for line separation to work around the | |
89 | lack of macros, using sed and such. */ | |
90 | const char line_separator_chars[] = ";"; | |
91 | ||
92 | /* Chars that can be used to separate mant from exp in floating point nums. */ | |
93 | const char EXP_CHARS[] = "eE"; | |
94 | ||
95 | /* Chars that mean this number is a floating point constant. | |
96 | As in 0f12.456 | |
97 | or 0d1.2345e12. */ | |
98 | const char FLT_CHARS[] = "rRsSfFdDxXpP"; | |
99 | ||
100 | /* "l.jalr r9" precalculated opcode. */ | |
101 | static unsigned long jalr_r9_opcode; | |
102 | ||
ea1562b3 | 103 | static void machine_ip (char *); |
3b16e843 | 104 | |
3b16e843 NC |
105 | |
106 | /* Set bits in machine opcode according to insn->encoding | |
5d6255fe | 107 | description and passed operand. */ |
3b16e843 | 108 | |
5d6255fe | 109 | static void |
ea1562b3 NC |
110 | encode (const struct machine_opcode *insn, |
111 | unsigned long *opcode, | |
112 | signed long param_val, | |
113 | char param_ch) | |
3b16e843 NC |
114 | { |
115 | int opc_pos = 0; | |
116 | int param_pos = 0; | |
117 | char *enc; | |
118 | ||
119 | #if DEBUG | |
120 | printf (" encode: opcode=%.8lx param_val=%.8lx abs=%.8lx param_ch=%c\n", | |
121 | *opcode, param_val, abs (param_val), param_ch); | |
122 | #endif | |
123 | for (enc = insn->encoding; *enc != '\0'; enc++) | |
124 | if (*enc == param_ch) | |
125 | { | |
126 | if (enc - 2 >= insn->encoding && (*(enc - 2) == '0') && (*(enc - 1) == 'x')) | |
127 | continue; | |
128 | else | |
129 | param_pos ++; | |
130 | } | |
131 | ||
132 | opc_pos = 32; | |
133 | ||
134 | for (enc = insn->encoding; *enc != '\0';) | |
135 | { | |
5d6255fe | 136 | if ((*enc == '0') && (*(enc + 1) == 'x')) |
3b16e843 NC |
137 | { |
138 | int tmp = strtol (enc, NULL, 16); | |
139 | ||
140 | opc_pos -= 4; | |
141 | *opcode |= tmp << opc_pos; | |
142 | enc += 3; | |
143 | } | |
5d6255fe | 144 | else if ((*enc == '0') || (*enc == '-')) |
3b16e843 NC |
145 | { |
146 | opc_pos--; | |
147 | enc++; | |
148 | } | |
5d6255fe | 149 | else if (*enc == '1') |
3b16e843 NC |
150 | { |
151 | opc_pos--; | |
152 | *opcode |= 1 << opc_pos; | |
153 | enc++; | |
154 | } | |
5d6255fe | 155 | else if (*enc == param_ch) |
3b16e843 NC |
156 | { |
157 | opc_pos--; | |
158 | param_pos--; | |
159 | *opcode |= ((param_val >> param_pos) & 0x1) << opc_pos; | |
160 | enc++; | |
161 | } | |
5d6255fe | 162 | else if (ISALPHA (*enc)) |
3b16e843 NC |
163 | { |
164 | opc_pos--; | |
165 | enc++; | |
166 | } | |
167 | else | |
168 | enc++; | |
169 | } | |
5d6255fe | 170 | |
3b16e843 NC |
171 | #if DEBUG |
172 | printf (" opcode=%.8lx\n", *opcode); | |
173 | #endif | |
174 | } | |
175 | ||
176 | /* This function is called once, at assembler startup time. It should | |
177 | set up all the tables, etc., that the MD part of the assembler will | |
178 | need. */ | |
179 | ||
180 | void | |
ea1562b3 | 181 | md_begin (void) |
3b16e843 NC |
182 | { |
183 | const char *retval = NULL; | |
184 | int lose = 0; | |
185 | int skipnext = 0; | |
186 | unsigned int i; | |
187 | ||
188 | /* Hash up all the opcodes for fast use later. */ | |
189 | op_hash = hash_new (); | |
190 | ||
191 | for (i = 0; i < or32_num_opcodes; i++) | |
192 | { | |
193 | const char *name = machine_opcodes[i].name; | |
194 | ||
195 | if (skipnext) | |
196 | { | |
197 | skipnext = 0; | |
198 | continue; | |
199 | } | |
200 | ||
ea1562b3 | 201 | retval = hash_insert (op_hash, name, (void *) &machine_opcodes[i]); |
3b16e843 NC |
202 | if (retval != NULL) |
203 | { | |
204 | fprintf (stderr, "internal error: can't hash `%s': %s\n", | |
205 | machine_opcodes[i].name, retval); | |
206 | lose = 1; | |
207 | } | |
208 | } | |
209 | ||
210 | if (lose) | |
211 | as_fatal (_("Broken assembler. No assembly attempted.")); | |
212 | ||
213 | encode (&machine_opcodes[insn_index ("l.jalr")], &jalr_r9_opcode, 9, 'B'); | |
214 | } | |
215 | ||
67c1ffbe | 216 | /* Returns non zero if instruction is to be used. */ |
3b16e843 NC |
217 | |
218 | static int | |
ea1562b3 | 219 | check_invalid_opcode (unsigned long opcode) |
3b16e843 NC |
220 | { |
221 | return opcode == jalr_r9_opcode; | |
222 | } | |
223 | ||
224 | /* Assemble a single instruction. Its label has already been handled | |
225 | by the generic front end. We just parse opcode and operands, and | |
226 | produce the bytes of data and relocation. */ | |
227 | ||
228 | void | |
ea1562b3 | 229 | md_assemble (char *str) |
3b16e843 NC |
230 | { |
231 | char *toP; | |
232 | ||
233 | #if DEBUG | |
234 | printf ("NEW INSTRUCTION\n"); | |
235 | #endif | |
236 | ||
237 | know (str); | |
238 | machine_ip (str); | |
239 | toP = frag_more (4); | |
240 | ||
241 | /* Put out the opcode. */ | |
242 | md_number_to_chars (toP, the_insn.opcode, 4); | |
243 | ||
244 | /* Put out the symbol-dependent stuff. */ | |
3b16e843 | 245 | if (the_insn.reloc != BFD_RELOC_NONE) |
3b16e843 NC |
246 | { |
247 | fix_new_exp (frag_now, | |
248 | (toP - frag_now->fr_literal + the_insn.reloc_offset), | |
249 | 4, /* size */ | |
250 | &the_insn.exp, | |
251 | the_insn.pcrel, | |
252 | the_insn.reloc); | |
253 | } | |
254 | } | |
255 | ||
256 | /* This is true of the we have issued a "lo(" or "hi"(. */ | |
257 | static int waiting_for_shift = 0; | |
258 | ||
259 | static int mask_or_shift = 0; | |
260 | ||
3b16e843 | 261 | static char * |
ea1562b3 | 262 | parse_operand (char *s, expressionS *operandp, int opt) |
3b16e843 NC |
263 | { |
264 | char *save = input_line_pointer; | |
d3ce72d0 | 265 | char *new_pointer; |
3b16e843 NC |
266 | |
267 | #if DEBUG | |
268 | printf (" PROCESS NEW OPERAND(%s) == %c (%d)\n", s, opt ? opt : '!', opt); | |
269 | #endif | |
270 | ||
271 | input_line_pointer = s; | |
272 | ||
273 | if (strncasecmp (s, "HI(", 3) == 0) | |
274 | { | |
275 | waiting_for_shift = 1; | |
276 | mask_or_shift = BFD_RELOC_HI16; | |
277 | ||
278 | input_line_pointer += 3; | |
279 | } | |
280 | else if (strncasecmp (s, "LO(", 3) == 0) | |
281 | { | |
282 | mask_or_shift = BFD_RELOC_LO16; | |
283 | ||
284 | input_line_pointer += 3; | |
285 | } | |
286 | else | |
287 | mask_or_shift = 0; | |
288 | ||
289 | if ((*s == '(') && (*(s+1) == 'r')) | |
290 | s++; | |
291 | ||
5d6255fe | 292 | if ((*s == 'r') && ISDIGIT (*(s + 1))) |
3b16e843 NC |
293 | { |
294 | operandp->X_add_number = strtol (s + 1, NULL, 10); | |
295 | operandp->X_op = O_register; | |
296 | for (; (*s != ',') && (*s != '\0');) | |
5d6255fe | 297 | s++; |
3b16e843 | 298 | input_line_pointer = save; |
5d6255fe | 299 | return s; |
3b16e843 NC |
300 | } |
301 | ||
302 | expression (operandp); | |
303 | ||
304 | if (operandp->X_op == O_absent) | |
305 | { | |
306 | if (! opt) | |
307 | as_bad (_("missing operand")); | |
308 | else | |
309 | { | |
310 | operandp->X_add_number = 0; | |
311 | operandp->X_op = O_constant; | |
312 | } | |
313 | } | |
5d6255fe | 314 | |
d3ce72d0 | 315 | new_pointer = input_line_pointer; |
3b16e843 | 316 | input_line_pointer = save; |
5d6255fe | 317 | |
3b16e843 | 318 | #if DEBUG |
d3ce72d0 NC |
319 | printf (" %s=parse_operand(%s): operandp->X_op = %u\n", new_pointer, s, |
320 | operandp->X_op); | |
3b16e843 NC |
321 | #endif |
322 | ||
d3ce72d0 | 323 | return new_pointer; |
3b16e843 | 324 | } |
3b16e843 NC |
325 | |
326 | /* Instruction parsing. Takes a string containing the opcode. | |
327 | Operands are at input_line_pointer. Output is in the_insn. | |
328 | Warnings or errors are generated. */ | |
329 | ||
3b16e843 | 330 | static void |
ea1562b3 | 331 | machine_ip (char *str) |
3b16e843 NC |
332 | { |
333 | char *s; | |
334 | const char *args; | |
335 | const struct machine_opcode *insn; | |
336 | char *argsStart; | |
337 | unsigned long opcode; | |
338 | expressionS the_operand; | |
339 | expressionS *operand = &the_operand; | |
340 | unsigned int regno; | |
341 | int reloc = BFD_RELOC_NONE; | |
342 | ||
343 | #if DEBUG | |
344 | printf ("machine_ip(%s)\n", str); | |
345 | #endif | |
346 | ||
347 | s = str; | |
348 | for (; ISALNUM (*s) || *s == '.'; ++s) | |
349 | if (ISUPPER (*s)) | |
350 | *s = TOLOWER (*s); | |
351 | ||
352 | switch (*s) | |
353 | { | |
354 | case '\0': | |
355 | break; | |
356 | ||
357 | case ' ': /* FIXME-SOMEDAY more whitespace. */ | |
358 | *s++ = '\0'; | |
359 | break; | |
360 | ||
361 | default: | |
362 | as_bad (_("unknown opcode1: `%s'"), str); | |
363 | return; | |
364 | } | |
365 | ||
366 | if ((insn = (struct machine_opcode *) hash_find (op_hash, str)) == NULL) | |
367 | { | |
368 | as_bad (_("unknown opcode2 `%s'."), str); | |
369 | return; | |
370 | } | |
371 | ||
372 | argsStart = s; | |
373 | opcode = 0; | |
374 | memset (&the_insn, '\0', sizeof (the_insn)); | |
375 | the_insn.reloc = BFD_RELOC_NONE; | |
376 | ||
377 | reloc = BFD_RELOC_NONE; | |
378 | ||
379 | /* Build the opcode, checking as we go to make sure that the | |
380 | operands match. | |
5d6255fe | 381 | |
3b16e843 NC |
382 | If an operand matches, we modify the_insn or opcode appropriately, |
383 | and do a "continue". If an operand fails to match, we "break". */ | |
384 | if (insn->args[0] != '\0') | |
ea1562b3 NC |
385 | /* Prime the pump. */ |
386 | s = parse_operand (s, operand, insn->args[0] == 'I'); | |
3b16e843 NC |
387 | |
388 | for (args = insn->args;; ++args) | |
389 | { | |
390 | #if DEBUG | |
391 | printf (" args = %s\n", args); | |
392 | #endif | |
393 | switch (*args) | |
394 | { | |
395 | case '\0': /* End of args. */ | |
396 | /* We have have 0 args, do the bazoooka! */ | |
397 | if (args == insn->args) | |
398 | encode (insn, &opcode, 0, 0); | |
399 | ||
400 | if (*s == '\0') | |
401 | { | |
402 | /* We are truly done. */ | |
403 | the_insn.opcode = opcode; | |
404 | if (check_invalid_opcode (opcode)) | |
5d6255fe | 405 | as_bad (_("instruction not allowed: %s"), str); |
3b16e843 NC |
406 | return; |
407 | } | |
408 | as_bad (_("too many operands: %s"), s); | |
409 | break; | |
410 | ||
411 | case ',': /* Must match a comma. */ | |
412 | if (*s++ == ',') | |
413 | { | |
414 | reloc = BFD_RELOC_NONE; | |
415 | ||
416 | /* Parse next operand. */ | |
417 | s = parse_operand (s, operand, args[1] == 'I'); | |
418 | #if DEBUG | |
419 | printf (" ',' case: operand->X_add_number = %d, *args = %s, *s = %s\n", | |
420 | operand->X_add_number, args, s); | |
5d6255fe | 421 | #endif |
3b16e843 NC |
422 | continue; |
423 | } | |
424 | break; | |
425 | ||
426 | case '(': /* Must match a (. */ | |
427 | s = parse_operand (s, operand, args[1] == 'I'); | |
428 | continue; | |
5d6255fe | 429 | |
3b16e843 NC |
430 | case ')': /* Must match a ). */ |
431 | continue; | |
432 | ||
433 | case 'r': /* A general register. */ | |
434 | args++; | |
435 | ||
436 | if (operand->X_op != O_register) | |
437 | break; /* Only registers. */ | |
5d6255fe | 438 | |
3b16e843 NC |
439 | know (operand->X_add_symbol == 0); |
440 | know (operand->X_op_symbol == 0); | |
441 | regno = operand->X_add_number; | |
442 | encode (insn, &opcode, regno, *args); | |
443 | #if DEBUG | |
444 | printf (" r: operand->X_op = %d\n", operand->X_op); | |
445 | #endif | |
446 | continue; | |
447 | ||
448 | default: | |
449 | /* if (! ISALPHA (*args)) | |
450 | break; */ /* Only immediate values. */ | |
5d6255fe | 451 | |
3b16e843 NC |
452 | if (mask_or_shift) |
453 | { | |
454 | #if DEBUG | |
455 | printf ("mask_or_shift = %d\n", mask_or_shift); | |
456 | #endif | |
457 | reloc = mask_or_shift; | |
458 | } | |
459 | mask_or_shift = 0; | |
5d6255fe KH |
460 | |
461 | if (strncasecmp (args, "LO(", 3) == 0) | |
3b16e843 NC |
462 | { |
463 | #if DEBUG | |
464 | printf ("reloc_const\n"); | |
465 | #endif | |
466 | reloc = BFD_RELOC_LO16; | |
467 | } | |
5d6255fe | 468 | else if (strncasecmp (args, "HI(", 3) == 0) |
3b16e843 NC |
469 | { |
470 | #if DEBUG | |
471 | printf ("reloc_consth\n"); | |
472 | #endif | |
473 | reloc = BFD_RELOC_HI16; | |
474 | } | |
5d6255fe KH |
475 | |
476 | if (*s == '(') | |
ea1562b3 | 477 | operand->X_op = O_constant; |
3b16e843 NC |
478 | else if (*s == ')') |
479 | s += 1; | |
480 | #if DEBUG | |
481 | printf (" default case: operand->X_add_number = %d, *args = %s, *s = %s\n", operand->X_add_number, args, s); | |
482 | #endif | |
483 | if (operand->X_op == O_constant) | |
484 | { | |
485 | if (reloc == BFD_RELOC_NONE) | |
486 | { | |
487 | bfd_vma v, mask; | |
488 | ||
489 | mask = 0x3ffffff; | |
490 | v = abs (operand->X_add_number) & ~ mask; | |
491 | if (v) | |
492 | as_bad (_("call/jmp target out of range (1)")); | |
493 | } | |
494 | ||
495 | if (reloc == BFD_RELOC_HI16) | |
496 | operand->X_add_number = ((operand->X_add_number >> 16) & 0xffff); | |
497 | ||
498 | the_insn.pcrel = 0; | |
499 | encode (insn, &opcode, operand->X_add_number, *args); | |
500 | /* the_insn.reloc = BFD_RELOC_NONE; */ | |
5d6255fe | 501 | continue; |
3b16e843 NC |
502 | } |
503 | ||
504 | if (reloc == BFD_RELOC_NONE) | |
505 | the_insn.reloc = BFD_RELOC_32_GOT_PCREL; | |
506 | else | |
507 | the_insn.reloc = reloc; | |
508 | ||
509 | /* the_insn.reloc = insn->reloc; */ | |
510 | #if DEBUG | |
511 | printf (" reloc sym=%d\n", the_insn.reloc); | |
512 | printf (" BFD_RELOC_NONE=%d\n", BFD_RELOC_NONE); | |
513 | #endif | |
514 | the_insn.exp = *operand; | |
5d6255fe | 515 | |
3b16e843 NC |
516 | /* the_insn.reloc_offset = 1; */ |
517 | the_insn.pcrel = 1; /* Assume PC-relative jump. */ | |
518 | ||
519 | /* FIXME-SOON, Do we figure out whether abs later, after | |
520 | know sym val? */ | |
521 | if (reloc == BFD_RELOC_LO16 || reloc == BFD_RELOC_HI16) | |
522 | the_insn.pcrel = 0; | |
523 | ||
524 | encode (insn, &opcode, operand->X_add_number, *args); | |
525 | continue; | |
526 | } | |
5d6255fe | 527 | |
3b16e843 NC |
528 | /* Types or values of args don't match. */ |
529 | as_bad (_("invalid operands")); | |
530 | return; | |
531 | } | |
532 | } | |
533 | ||
3b16e843 | 534 | char * |
ea1562b3 | 535 | md_atof (int type, char * litP, int * sizeP) |
3b16e843 | 536 | { |
499ac353 | 537 | return ieee_md_atof (type, litP, sizeP, TRUE); |
3b16e843 NC |
538 | } |
539 | ||
540 | /* Write out big-endian. */ | |
541 | ||
542 | void | |
ea1562b3 | 543 | md_number_to_chars (char *buf, valueT val, int n) |
3b16e843 NC |
544 | { |
545 | number_to_chars_bigendian (buf, val, n); | |
546 | } | |
547 | ||
3b16e843 | 548 | void |
55cf6793 | 549 | md_apply_fix (fixS * fixP, valueT * val, segT seg ATTRIBUTE_UNUSED) |
3b16e843 NC |
550 | { |
551 | char *buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
552 | long t_val; | |
553 | ||
554 | t_val = (long) *val; | |
555 | ||
556 | #if DEBUG | |
557 | printf ("md_apply_fix val:%x\n", t_val); | |
558 | #endif | |
559 | ||
560 | fixP->fx_addnumber = t_val; /* Remember value for emit_reloc. */ | |
561 | ||
3b16e843 NC |
562 | switch (fixP->fx_r_type) |
563 | { | |
564 | case BFD_RELOC_32: /* XXXXXXXX pattern in a word. */ | |
565 | #if DEBUG | |
566 | printf ("reloc_const: val=%x\n", t_val); | |
567 | #endif | |
568 | buf[0] = t_val >> 24; | |
569 | buf[1] = t_val >> 16; | |
570 | buf[2] = t_val >> 8; | |
571 | buf[3] = t_val; | |
572 | break; | |
573 | ||
574 | case BFD_RELOC_16: /* XXXX0000 pattern in a word. */ | |
575 | #if DEBUG | |
576 | printf ("reloc_const: val=%x\n", t_val); | |
577 | #endif | |
578 | buf[0] = t_val >> 8; | |
579 | buf[1] = t_val; | |
580 | break; | |
581 | ||
582 | case BFD_RELOC_8: /* XX000000 pattern in a word. */ | |
583 | #if DEBUG | |
584 | printf ("reloc_const: val=%x\n", t_val); | |
585 | #endif | |
586 | buf[0] = t_val; | |
587 | break; | |
588 | ||
589 | case BFD_RELOC_LO16: /* 0000XXXX pattern in a word. */ | |
590 | #if DEBUG | |
591 | printf ("reloc_const: val=%x\n", t_val); | |
592 | #endif | |
593 | buf[2] = t_val >> 8; /* Holds bits 0000XXXX. */ | |
594 | buf[3] = t_val; | |
595 | break; | |
596 | ||
597 | case BFD_RELOC_HI16: /* 0000XXXX pattern in a word. */ | |
598 | #if DEBUG | |
599 | printf ("reloc_consth: val=%x\n", t_val); | |
600 | #endif | |
601 | buf[2] = t_val >> 24; /* Holds bits XXXX0000. */ | |
602 | buf[3] = t_val >> 16; | |
603 | break; | |
604 | ||
605 | case BFD_RELOC_32_GOT_PCREL: /* 0000XXXX pattern in a word. */ | |
606 | if (!fixP->fx_done) | |
65ec77d2 | 607 | ; |
3b16e843 NC |
608 | else if (fixP->fx_pcrel) |
609 | { | |
610 | long v = t_val >> 28; | |
611 | ||
612 | if (v != 0 && v != -1) | |
613 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
614 | _("call/jmp target out of range (2)")); | |
615 | } | |
616 | else | |
617 | /* This case was supposed to be handled in machine_ip. */ | |
618 | abort (); | |
619 | ||
620 | buf[0] |= (t_val >> 26) & 0x03; /* Holds bits 0FFFFFFC of address. */ | |
621 | buf[1] = t_val >> 18; | |
622 | buf[2] = t_val >> 10; | |
623 | buf[3] = t_val >> 2; | |
624 | break; | |
625 | ||
626 | case BFD_RELOC_VTABLE_INHERIT: | |
627 | case BFD_RELOC_VTABLE_ENTRY: | |
628 | fixP->fx_done = 0; | |
629 | break; | |
630 | ||
631 | case BFD_RELOC_NONE: | |
632 | default: | |
633 | as_bad (_("bad relocation type: 0x%02x"), fixP->fx_r_type); | |
634 | break; | |
635 | } | |
636 | ||
637 | if (fixP->fx_addsy == (symbolS *) NULL) | |
638 | fixP->fx_done = 1; | |
639 | } | |
3b16e843 NC |
640 | |
641 | /* Should never be called for or32. */ | |
642 | ||
643 | void | |
ea1562b3 NC |
644 | md_create_short_jump (char * ptr ATTRIBUTE_UNUSED, |
645 | addressT from_addr ATTRIBUTE_UNUSED, | |
646 | addressT to_addr ATTRIBUTE_UNUSED, | |
647 | fragS * frag ATTRIBUTE_UNUSED, | |
648 | symbolS * to_symbol ATTRIBUTE_UNUSED) | |
3b16e843 NC |
649 | { |
650 | as_fatal ("or32_create_short_jmp\n"); | |
651 | } | |
652 | ||
653 | /* Should never be called for or32. */ | |
654 | ||
3b16e843 | 655 | void |
ea1562b3 NC |
656 | md_convert_frag (bfd * headers ATTRIBUTE_UNUSED, |
657 | segT seg ATTRIBUTE_UNUSED, | |
658 | fragS * fragP ATTRIBUTE_UNUSED) | |
3b16e843 NC |
659 | { |
660 | as_fatal ("or32_convert_frag\n"); | |
5d6255fe | 661 | } |
3b16e843 NC |
662 | |
663 | /* Should never be called for or32. */ | |
664 | ||
665 | void | |
ea1562b3 NC |
666 | md_create_long_jump (char * ptr ATTRIBUTE_UNUSED, |
667 | addressT from_addr ATTRIBUTE_UNUSED, | |
668 | addressT to_addr ATTRIBUTE_UNUSED, | |
669 | fragS * frag ATTRIBUTE_UNUSED, | |
670 | symbolS * to_symbol ATTRIBUTE_UNUSED) | |
3b16e843 NC |
671 | { |
672 | as_fatal ("or32_create_long_jump\n"); | |
673 | } | |
674 | ||
675 | /* Should never be called for or32. */ | |
676 | ||
677 | int | |
ea1562b3 NC |
678 | md_estimate_size_before_relax (fragS * fragP ATTRIBUTE_UNUSED, |
679 | segT segtype ATTRIBUTE_UNUSED) | |
3b16e843 NC |
680 | { |
681 | as_fatal ("or32_estimate_size_before_relax\n"); | |
682 | return 0; | |
683 | } | |
684 | ||
685 | /* Translate internal representation of relocation info to target format. | |
686 | ||
687 | On sparc/29k: first 4 bytes are normal unsigned long address, next three | |
688 | bytes are index, most sig. byte first. Byte 7 is broken up with | |
689 | bit 7 as external, bits 6 & 5 unused, and the lower | |
690 | five bits as relocation type. Next 4 bytes are long addend. */ | |
691 | /* Thanx and a tip of the hat to Michael Bloom, mb@ttidca.tti.com. */ | |
692 | ||
693 | #ifdef OBJ_AOUT | |
694 | void | |
ea1562b3 NC |
695 | tc_aout_fix_to_chars (char *where, |
696 | fixS *fixP, | |
697 | relax_addressT segment_address_in_file) | |
3b16e843 NC |
698 | { |
699 | long r_symbolnum; | |
700 | ||
701 | #if DEBUG | |
702 | printf ("tc_aout_fix_to_chars\n"); | |
5d6255fe | 703 | #endif |
3b16e843 NC |
704 | |
705 | know (fixP->fx_r_type < BFD_RELOC_NONE); | |
706 | know (fixP->fx_addsy != NULL); | |
707 | ||
708 | md_number_to_chars | |
709 | (where, | |
710 | fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file, | |
711 | 4); | |
712 | ||
713 | r_symbolnum = (S_IS_DEFINED (fixP->fx_addsy) | |
714 | ? S_GET_TYPE (fixP->fx_addsy) | |
715 | : fixP->fx_addsy->sy_number); | |
716 | ||
717 | where[4] = (r_symbolnum >> 16) & 0x0ff; | |
718 | where[5] = (r_symbolnum >> 8) & 0x0ff; | |
719 | where[6] = r_symbolnum & 0x0ff; | |
720 | where[7] = (((!S_IS_DEFINED (fixP->fx_addsy)) << 7) & 0x80) | (0 & 0x60) | (fixP->fx_r_type & 0x1F); | |
721 | ||
722 | /* Also easy. */ | |
723 | md_number_to_chars (&where[8], fixP->fx_addnumber, 4); | |
724 | } | |
725 | ||
726 | #endif /* OBJ_AOUT */ | |
727 | \f | |
728 | const char *md_shortopts = ""; | |
729 | ||
730 | struct option md_longopts[] = | |
ea1562b3 NC |
731 | { |
732 | { NULL, no_argument, NULL, 0 } | |
733 | }; | |
3b16e843 NC |
734 | size_t md_longopts_size = sizeof (md_longopts); |
735 | ||
736 | int | |
ea1562b3 | 737 | md_parse_option (int c ATTRIBUTE_UNUSED, char * arg ATTRIBUTE_UNUSED) |
3b16e843 NC |
738 | { |
739 | return 0; | |
740 | } | |
741 | ||
742 | void | |
ea1562b3 | 743 | md_show_usage (FILE * stream ATTRIBUTE_UNUSED) |
3b16e843 NC |
744 | { |
745 | } | |
746 | \f | |
747 | /* This is called when a line is unrecognized. This is used to handle | |
748 | definitions of or32 style local labels. */ | |
749 | ||
750 | int | |
ea1562b3 | 751 | or32_unrecognized_line (int c) |
3b16e843 NC |
752 | { |
753 | int lab; | |
754 | char *s; | |
755 | ||
756 | if (c != '$' | |
757 | || ! ISDIGIT ((unsigned char) input_line_pointer[0])) | |
758 | return 0; | |
759 | ||
760 | s = input_line_pointer; | |
761 | ||
762 | lab = 0; | |
763 | while (ISDIGIT ((unsigned char) *s)) | |
764 | { | |
765 | lab = lab * 10 + *s - '0'; | |
766 | ++s; | |
767 | } | |
768 | ||
769 | if (*s != ':') | |
770 | /* Not a label definition. */ | |
771 | return 0; | |
772 | ||
773 | if (dollar_label_defined (lab)) | |
774 | { | |
775 | as_bad (_("label \"$%d\" redefined"), lab); | |
776 | return 0; | |
777 | } | |
778 | ||
779 | define_dollar_label (lab); | |
780 | colon (dollar_label_name (lab, 0)); | |
781 | input_line_pointer = s + 1; | |
782 | ||
783 | return 1; | |
784 | } | |
785 | ||
3b16e843 NC |
786 | /* Default the values of symbols known that should be "predefined". We |
787 | don't bother to predefine them unless you actually use one, since there | |
788 | are a lot of them. */ | |
789 | ||
790 | symbolS * | |
ea1562b3 | 791 | md_undefined_symbol (char *name ATTRIBUTE_UNUSED) |
3b16e843 | 792 | { |
3b16e843 NC |
793 | return NULL; |
794 | } | |
795 | ||
796 | /* Parse an operand that is machine-specific. */ | |
797 | ||
798 | void | |
ea1562b3 | 799 | md_operand (expressionS *expressionP) |
3b16e843 NC |
800 | { |
801 | #if DEBUG | |
802 | printf (" md_operand(input_line_pointer = %s)\n", input_line_pointer); | |
803 | #endif | |
804 | ||
805 | if (input_line_pointer[0] == REGISTER_PREFIX && input_line_pointer[1] == 'r') | |
806 | { | |
807 | /* We have a numeric register expression. No biggy. */ | |
808 | input_line_pointer += 2; /* Skip %r */ | |
809 | (void) expression (expressionP); | |
810 | ||
811 | if (expressionP->X_op != O_constant | |
812 | || expressionP->X_add_number > 255) | |
813 | as_bad (_("Invalid expression after %%%%\n")); | |
814 | expressionP->X_op = O_register; | |
815 | } | |
816 | else if (input_line_pointer[0] == '&') | |
817 | { | |
818 | /* We are taking the 'address' of a register...this one is not | |
819 | in the manual, but it *is* in traps/fpsymbol.h! What they | |
820 | seem to want is the register number, as an absolute number. */ | |
821 | input_line_pointer++; /* Skip & */ | |
822 | (void) expression (expressionP); | |
823 | ||
824 | if (expressionP->X_op != O_register) | |
825 | as_bad (_("invalid register in & expression")); | |
826 | else | |
827 | expressionP->X_op = O_constant; | |
828 | } | |
829 | else if (input_line_pointer[0] == '$' | |
830 | && ISDIGIT ((unsigned char) input_line_pointer[1])) | |
831 | { | |
832 | long lab; | |
833 | char *name; | |
834 | symbolS *sym; | |
5d6255fe | 835 | |
3b16e843 NC |
836 | /* This is a local label. */ |
837 | ++input_line_pointer; | |
838 | lab = (long) get_absolute_expression (); | |
839 | ||
840 | if (dollar_label_defined (lab)) | |
841 | { | |
842 | name = dollar_label_name (lab, 0); | |
843 | sym = symbol_find (name); | |
844 | } | |
845 | else | |
846 | { | |
847 | name = dollar_label_name (lab, 1); | |
848 | sym = symbol_find_or_make (name); | |
849 | } | |
850 | ||
851 | expressionP->X_op = O_symbol; | |
852 | expressionP->X_add_symbol = sym; | |
853 | expressionP->X_add_number = 0; | |
854 | } | |
855 | else if (input_line_pointer[0] == '$') | |
856 | { | |
857 | char *s; | |
858 | char type; | |
859 | int fieldnum, fieldlimit; | |
860 | LITTLENUM_TYPE floatbuf[8]; | |
861 | ||
862 | /* $float(), $doubleN(), or $extendN() convert floating values | |
863 | to integers. */ | |
864 | s = input_line_pointer; | |
865 | ||
866 | ++s; | |
867 | ||
868 | fieldnum = 0; | |
869 | if (strncmp (s, "double", sizeof "double" - 1) == 0) | |
870 | { | |
871 | s += sizeof "double" - 1; | |
872 | type = 'd'; | |
873 | fieldlimit = 2; | |
874 | } | |
875 | else if (strncmp (s, "float", sizeof "float" - 1) == 0) | |
876 | { | |
877 | s += sizeof "float" - 1; | |
878 | type = 'f'; | |
879 | fieldlimit = 1; | |
880 | } | |
881 | else if (strncmp (s, "extend", sizeof "extend" - 1) == 0) | |
882 | { | |
883 | s += sizeof "extend" - 1; | |
884 | type = 'x'; | |
885 | fieldlimit = 4; | |
886 | } | |
5d6255fe | 887 | else |
3b16e843 NC |
888 | return; |
889 | ||
890 | if (ISDIGIT (*s)) | |
891 | { | |
892 | fieldnum = *s - '0'; | |
893 | ++s; | |
894 | } | |
895 | if (fieldnum >= fieldlimit) | |
896 | return; | |
897 | ||
898 | SKIP_WHITESPACE (); | |
899 | if (*s != '(') | |
900 | return; | |
901 | ++s; | |
902 | SKIP_WHITESPACE (); | |
903 | ||
904 | s = atof_ieee (s, type, floatbuf); | |
905 | if (s == NULL) | |
906 | return; | |
907 | s = s; | |
908 | ||
909 | SKIP_WHITESPACE (); | |
910 | if (*s != ')') | |
911 | return; | |
912 | ++s; | |
913 | SKIP_WHITESPACE (); | |
914 | ||
915 | input_line_pointer = s; | |
5d6255fe | 916 | expressionP->X_op = O_constant; |
3b16e843 NC |
917 | expressionP->X_unsigned = 1; |
918 | expressionP->X_add_number = ((floatbuf[fieldnum * 2] | |
919 | << LITTLENUM_NUMBER_OF_BITS) | |
920 | + floatbuf[fieldnum * 2 + 1]); | |
921 | } | |
922 | } | |
923 | ||
924 | /* Round up a section size to the appropriate boundary. */ | |
925 | ||
926 | valueT | |
ea1562b3 | 927 | md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size ATTRIBUTE_UNUSED) |
3b16e843 NC |
928 | { |
929 | return size; /* Byte alignment is fine. */ | |
930 | } | |
931 | ||
932 | /* Exactly what point is a PC-relative offset relative TO? | |
933 | On the 29000, they're relative to the address of the instruction, | |
934 | which we have set up as the address of the fixup too. */ | |
935 | ||
936 | long | |
ea1562b3 | 937 | md_pcrel_from (fixS *fixP) |
3b16e843 NC |
938 | { |
939 | return fixP->fx_where + fixP->fx_frag->fr_address; | |
940 | } | |
941 | ||
942 | /* Generate a reloc for a fixup. */ | |
943 | ||
3b16e843 | 944 | arelent * |
ea1562b3 | 945 | tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp) |
3b16e843 NC |
946 | { |
947 | arelent *reloc; | |
948 | ||
ea1562b3 NC |
949 | reloc = xmalloc (sizeof (arelent)); |
950 | reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *)); | |
3b16e843 NC |
951 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); |
952 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
953 | /* reloc->address = fixp->fx_frag->fr_address + fixp->fx_where + fixp->fx_addnumber;*/ | |
954 | reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type); | |
955 | ||
956 | if (reloc->howto == (reloc_howto_type *) NULL) | |
957 | { | |
958 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
959 | _("reloc %d not supported by object file format"), | |
960 | (int) fixp->fx_r_type); | |
961 | return NULL; | |
962 | } | |
963 | ||
a161fe53 AM |
964 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) |
965 | reloc->address = fixp->fx_offset; | |
3b16e843 | 966 | |
a161fe53 | 967 | reloc->addend = fixp->fx_addnumber; |
3b16e843 NC |
968 | return reloc; |
969 | } |