]>
Commit | Line | Data |
---|---|---|
3b16e843 | 1 | /* Assembly backend for the OpenRISC 1000. |
aef6203b | 2 | Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc. |
3b16e843 NC |
3 | Contributed by Damjan Lampret <[email protected]>. |
4 | Modified bu Johan Rydberg, <[email protected]>. | |
5 | Based upon a29k port. | |
6 | ||
7 | This file is part of GAS, the GNU Assembler. | |
8 | ||
9 | GAS is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
11 | the Free Software Foundation; either version 2, or (at your option) | |
12 | any later version. | |
13 | ||
14 | GAS is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
20 | along with GAS; see the file COPYING. If not, write to | |
21 | the Free Software Foundation, 59 Temple Place - Suite 330, | |
22 | Boston, MA 02111-1307, USA. */ | |
23 | ||
24 | /* tc-a29k.c used as a template. */ | |
25 | ||
26 | #include "safe-ctype.h" | |
27 | #include "as.h" | |
28 | #include "opcode/or32.h" | |
29 | ||
30 | #ifdef BFD_ASSEMBLER | |
5d6255fe | 31 | #include "elf/or32.h" |
3b16e843 NC |
32 | #endif |
33 | ||
34 | #define DEBUG 0 | |
35 | ||
36 | #ifndef REGISTER_PREFIX | |
37 | #define REGISTER_PREFIX '%' | |
38 | #endif | |
39 | ||
40 | /* Make it easier to clone this machine desc into another one. */ | |
41 | #define machine_opcode or32_opcode | |
42 | #define machine_opcodes or32_opcodes | |
43 | #define machine_ip or32_ip | |
44 | #define machine_it or32_it | |
45 | ||
46 | /* Handle of the OPCODE hash table. */ | |
47 | static struct hash_control *op_hash = NULL; | |
48 | ||
49 | struct machine_it | |
50 | { | |
51 | char * error; | |
52 | unsigned long opcode; | |
53 | struct nlist * nlistp; | |
54 | expressionS exp; | |
55 | int pcrel; | |
56 | int reloc_offset; /* Offset of reloc within insn. */ | |
57 | int reloc; | |
58 | } | |
59 | the_insn; | |
60 | ||
61 | static void machine_ip PARAMS ((char *)); | |
62 | ||
63 | const pseudo_typeS md_pseudo_table[] = | |
64 | { | |
65 | {"align", s_align_bytes, 4 }, | |
66 | {"space", s_space, 0 }, | |
5d6255fe | 67 | {"cputype", s_ignore, 0 }, |
3b16e843 NC |
68 | {"reg", s_lsym, 0 }, /* Register equate, same as equ. */ |
69 | {"sect", s_ignore, 0 }, /* Creation of coff sections. */ | |
70 | {"proc", s_ignore, 0 }, /* Start of a function. */ | |
71 | {"endproc", s_ignore, 0 }, /* Function end. */ | |
72 | {"word", cons, 4 }, | |
73 | {NULL, 0, 0 }, | |
74 | }; | |
75 | ||
76 | int md_short_jump_size = 4; | |
77 | int md_long_jump_size = 4; | |
78 | ||
79 | #if defined(BFD_HEADERS) | |
80 | #ifdef RELSZ | |
81 | const int md_reloc_size = RELSZ; /* Coff headers. */ | |
82 | #else | |
83 | const int md_reloc_size = 12; /* Something else headers. */ | |
84 | #endif | |
85 | #else | |
86 | const int md_reloc_size = 12; /* Not bfdized. */ | |
87 | #endif | |
88 | ||
89 | /* This array holds the chars that always start a comment. | |
90 | If the pre-processor is disabled, these aren't very useful. */ | |
91 | const char comment_chars[] = "#"; | |
92 | ||
93 | /* This array holds the chars that only start a comment at the beginning of | |
94 | a line. If the line seems to have the form '# 123 filename' | |
95 | .line and .file directives will appear in the pre-processed output. */ | |
96 | /* Note that input_file.c hand checks for '#' at the beginning of the | |
97 | first line of the input file. This is because the compiler outputs | |
98 | #NO_APP at the beginning of its output. */ | |
99 | /* Also note that comments like this one will always work. */ | |
100 | const char line_comment_chars[] = "#"; | |
101 | ||
102 | /* We needed an unused char for line separation to work around the | |
103 | lack of macros, using sed and such. */ | |
104 | const char line_separator_chars[] = ";"; | |
105 | ||
106 | /* Chars that can be used to separate mant from exp in floating point nums. */ | |
107 | const char EXP_CHARS[] = "eE"; | |
108 | ||
109 | /* Chars that mean this number is a floating point constant. | |
110 | As in 0f12.456 | |
111 | or 0d1.2345e12. */ | |
112 | const char FLT_CHARS[] = "rRsSfFdDxXpP"; | |
113 | ||
114 | /* "l.jalr r9" precalculated opcode. */ | |
115 | static unsigned long jalr_r9_opcode; | |
116 | ||
117 | ||
118 | static int check_invalid_opcode PARAMS ((unsigned long)); | |
119 | static void encode PARAMS ((const struct machine_opcode *, unsigned long *, signed long, char)); | |
717acf4b | 120 | static char *parse_operand PARAMS ((char *, expressionS *, int)); |
3b16e843 NC |
121 | |
122 | /* Set bits in machine opcode according to insn->encoding | |
5d6255fe | 123 | description and passed operand. */ |
3b16e843 | 124 | |
5d6255fe | 125 | static void |
3b16e843 NC |
126 | encode (insn, opcode, param_val, param_ch) |
127 | const struct machine_opcode *insn; | |
128 | unsigned long *opcode; | |
129 | signed long param_val; | |
130 | char param_ch; | |
131 | { | |
132 | int opc_pos = 0; | |
133 | int param_pos = 0; | |
134 | char *enc; | |
135 | ||
136 | #if DEBUG | |
137 | printf (" encode: opcode=%.8lx param_val=%.8lx abs=%.8lx param_ch=%c\n", | |
138 | *opcode, param_val, abs (param_val), param_ch); | |
139 | #endif | |
140 | for (enc = insn->encoding; *enc != '\0'; enc++) | |
141 | if (*enc == param_ch) | |
142 | { | |
143 | if (enc - 2 >= insn->encoding && (*(enc - 2) == '0') && (*(enc - 1) == 'x')) | |
144 | continue; | |
145 | else | |
146 | param_pos ++; | |
147 | } | |
148 | ||
149 | opc_pos = 32; | |
150 | ||
151 | for (enc = insn->encoding; *enc != '\0';) | |
152 | { | |
5d6255fe | 153 | if ((*enc == '0') && (*(enc + 1) == 'x')) |
3b16e843 NC |
154 | { |
155 | int tmp = strtol (enc, NULL, 16); | |
156 | ||
157 | opc_pos -= 4; | |
158 | *opcode |= tmp << opc_pos; | |
159 | enc += 3; | |
160 | } | |
5d6255fe | 161 | else if ((*enc == '0') || (*enc == '-')) |
3b16e843 NC |
162 | { |
163 | opc_pos--; | |
164 | enc++; | |
165 | } | |
5d6255fe | 166 | else if (*enc == '1') |
3b16e843 NC |
167 | { |
168 | opc_pos--; | |
169 | *opcode |= 1 << opc_pos; | |
170 | enc++; | |
171 | } | |
5d6255fe | 172 | else if (*enc == param_ch) |
3b16e843 NC |
173 | { |
174 | opc_pos--; | |
175 | param_pos--; | |
176 | *opcode |= ((param_val >> param_pos) & 0x1) << opc_pos; | |
177 | enc++; | |
178 | } | |
5d6255fe | 179 | else if (ISALPHA (*enc)) |
3b16e843 NC |
180 | { |
181 | opc_pos--; | |
182 | enc++; | |
183 | } | |
184 | else | |
185 | enc++; | |
186 | } | |
5d6255fe | 187 | |
3b16e843 NC |
188 | #if DEBUG |
189 | printf (" opcode=%.8lx\n", *opcode); | |
190 | #endif | |
191 | } | |
192 | ||
193 | /* This function is called once, at assembler startup time. It should | |
194 | set up all the tables, etc., that the MD part of the assembler will | |
195 | need. */ | |
196 | ||
197 | void | |
198 | md_begin () | |
199 | { | |
200 | const char *retval = NULL; | |
201 | int lose = 0; | |
202 | int skipnext = 0; | |
203 | unsigned int i; | |
204 | ||
205 | /* Hash up all the opcodes for fast use later. */ | |
206 | op_hash = hash_new (); | |
207 | ||
208 | for (i = 0; i < or32_num_opcodes; i++) | |
209 | { | |
210 | const char *name = machine_opcodes[i].name; | |
211 | ||
212 | if (skipnext) | |
213 | { | |
214 | skipnext = 0; | |
215 | continue; | |
216 | } | |
217 | ||
218 | retval = hash_insert (op_hash, name, (PTR) &machine_opcodes[i]); | |
219 | if (retval != NULL) | |
220 | { | |
221 | fprintf (stderr, "internal error: can't hash `%s': %s\n", | |
222 | machine_opcodes[i].name, retval); | |
223 | lose = 1; | |
224 | } | |
225 | } | |
226 | ||
227 | if (lose) | |
228 | as_fatal (_("Broken assembler. No assembly attempted.")); | |
229 | ||
230 | encode (&machine_opcodes[insn_index ("l.jalr")], &jalr_r9_opcode, 9, 'B'); | |
231 | } | |
232 | ||
67c1ffbe | 233 | /* Returns non zero if instruction is to be used. */ |
3b16e843 NC |
234 | |
235 | static int | |
236 | check_invalid_opcode (opcode) | |
237 | unsigned long opcode; | |
238 | { | |
239 | return opcode == jalr_r9_opcode; | |
240 | } | |
241 | ||
242 | /* Assemble a single instruction. Its label has already been handled | |
243 | by the generic front end. We just parse opcode and operands, and | |
244 | produce the bytes of data and relocation. */ | |
245 | ||
246 | void | |
247 | md_assemble (str) | |
248 | char *str; | |
249 | { | |
250 | char *toP; | |
251 | ||
252 | #if DEBUG | |
253 | printf ("NEW INSTRUCTION\n"); | |
254 | #endif | |
255 | ||
256 | know (str); | |
257 | machine_ip (str); | |
258 | toP = frag_more (4); | |
259 | ||
260 | /* Put out the opcode. */ | |
261 | md_number_to_chars (toP, the_insn.opcode, 4); | |
262 | ||
263 | /* Put out the symbol-dependent stuff. */ | |
264 | #ifdef BFD_ASSEMBLER | |
265 | if (the_insn.reloc != BFD_RELOC_NONE) | |
266 | #else | |
267 | if (the_insn.reloc != NO_RELOC) | |
268 | #endif | |
269 | { | |
270 | fix_new_exp (frag_now, | |
271 | (toP - frag_now->fr_literal + the_insn.reloc_offset), | |
272 | 4, /* size */ | |
273 | &the_insn.exp, | |
274 | the_insn.pcrel, | |
275 | the_insn.reloc); | |
276 | } | |
277 | } | |
278 | ||
279 | /* This is true of the we have issued a "lo(" or "hi"(. */ | |
280 | static int waiting_for_shift = 0; | |
281 | ||
282 | static int mask_or_shift = 0; | |
283 | ||
284 | #ifdef BFD_ASSEMBLER | |
285 | static char * | |
286 | parse_operand (s, operandp, opt) | |
287 | char *s; | |
288 | expressionS *operandp; | |
289 | int opt; | |
290 | { | |
291 | char *save = input_line_pointer; | |
292 | char *new; | |
293 | ||
294 | #if DEBUG | |
295 | printf (" PROCESS NEW OPERAND(%s) == %c (%d)\n", s, opt ? opt : '!', opt); | |
296 | #endif | |
297 | ||
298 | input_line_pointer = s; | |
299 | ||
300 | if (strncasecmp (s, "HI(", 3) == 0) | |
301 | { | |
302 | waiting_for_shift = 1; | |
303 | mask_or_shift = BFD_RELOC_HI16; | |
304 | ||
305 | input_line_pointer += 3; | |
306 | } | |
307 | else if (strncasecmp (s, "LO(", 3) == 0) | |
308 | { | |
309 | mask_or_shift = BFD_RELOC_LO16; | |
310 | ||
311 | input_line_pointer += 3; | |
312 | } | |
313 | else | |
314 | mask_or_shift = 0; | |
315 | ||
316 | if ((*s == '(') && (*(s+1) == 'r')) | |
317 | s++; | |
318 | ||
5d6255fe | 319 | if ((*s == 'r') && ISDIGIT (*(s + 1))) |
3b16e843 NC |
320 | { |
321 | operandp->X_add_number = strtol (s + 1, NULL, 10); | |
322 | operandp->X_op = O_register; | |
323 | for (; (*s != ',') && (*s != '\0');) | |
5d6255fe | 324 | s++; |
3b16e843 | 325 | input_line_pointer = save; |
5d6255fe | 326 | return s; |
3b16e843 NC |
327 | } |
328 | ||
329 | expression (operandp); | |
330 | ||
331 | if (operandp->X_op == O_absent) | |
332 | { | |
333 | if (! opt) | |
334 | as_bad (_("missing operand")); | |
335 | else | |
336 | { | |
337 | operandp->X_add_number = 0; | |
338 | operandp->X_op = O_constant; | |
339 | } | |
340 | } | |
5d6255fe | 341 | |
3b16e843 NC |
342 | new = input_line_pointer; |
343 | input_line_pointer = save; | |
5d6255fe | 344 | |
3b16e843 NC |
345 | #if DEBUG |
346 | printf (" %s=parse_operand(%s): operandp->X_op = %u\n", new, s, operandp->X_op); | |
347 | #endif | |
348 | ||
349 | return new; | |
350 | } | |
351 | #else | |
352 | ||
717acf4b | 353 | static char * |
3b16e843 NC |
354 | parse_operand (s, operandp, opt) |
355 | char *s; | |
356 | expressionS *operandp; | |
357 | int opt; | |
358 | { | |
359 | char *save = input_line_pointer; | |
360 | char *new; | |
361 | ||
362 | #if DEBUG | |
363 | printf (" PROCESS NEW OPERAND(%s) == %c (%d)\n", s, opt ? opt : '!', opt); | |
364 | #endif | |
365 | ||
366 | input_line_pointer = s; | |
367 | ||
368 | if (strncasecmp (s, "HI(", 3) == 0) | |
369 | { | |
370 | waiting_for_shift = 1; | |
371 | mask_or_shift = RELOC_CONSTH; | |
372 | ||
373 | input_line_pointer += 3; | |
374 | } | |
375 | else if (strncasecmp (s, "LO(", 3) == 0) | |
376 | { | |
377 | mask_or_shift = RELOC_CONST; | |
378 | ||
379 | input_line_pointer += 3; | |
380 | } | |
381 | else | |
382 | mask_or_shift = 0; | |
383 | ||
384 | ||
385 | expression (operandp); | |
386 | ||
387 | if (operandp->X_op == O_absent) | |
388 | { | |
389 | if (! opt) | |
390 | as_bad (_("missing operand")); | |
391 | else | |
392 | { | |
393 | operandp->X_add_number = 0; | |
394 | operandp->X_op = O_constant; | |
395 | } | |
396 | } | |
5d6255fe | 397 | |
3b16e843 NC |
398 | new = input_line_pointer; |
399 | input_line_pointer = save; | |
5d6255fe KH |
400 | |
401 | if ((operandp->X_op == O_symbol) && (*s != '_')) | |
3b16e843 NC |
402 | { |
403 | #if DEBUG | |
404 | printf ("symbol: '%s'\n", save); | |
405 | #endif | |
406 | ||
407 | for (save = s; s < new; s++) | |
408 | if ((*s == REGISTER_PREFIX) && (*(s + 1) == 'r')) /* Register prefix. */ | |
409 | s++; | |
410 | ||
5d6255fe | 411 | if ((*s == 'r') && ISDIGIT (*(s + 1))) |
3b16e843 NC |
412 | { |
413 | operandp->X_add_number = strtol (s + 1, NULL, 10); | |
414 | operandp->X_op = O_register; | |
415 | } | |
416 | s = save; | |
417 | } | |
418 | ||
419 | #if DEBUG | |
420 | printf (" %s=parse_operand(%s): operandp->X_op = %u\n", new, s, operandp->X_op); | |
421 | #endif | |
422 | ||
423 | return new; | |
424 | } | |
425 | #endif | |
426 | ||
427 | /* Instruction parsing. Takes a string containing the opcode. | |
428 | Operands are at input_line_pointer. Output is in the_insn. | |
429 | Warnings or errors are generated. */ | |
430 | ||
431 | #ifdef BFD_ASSEMBLER | |
432 | static void | |
433 | machine_ip (str) | |
434 | char *str; | |
435 | { | |
436 | char *s; | |
437 | const char *args; | |
438 | const struct machine_opcode *insn; | |
439 | char *argsStart; | |
440 | unsigned long opcode; | |
441 | expressionS the_operand; | |
442 | expressionS *operand = &the_operand; | |
443 | unsigned int regno; | |
444 | int reloc = BFD_RELOC_NONE; | |
445 | ||
446 | #if DEBUG | |
447 | printf ("machine_ip(%s)\n", str); | |
448 | #endif | |
449 | ||
450 | s = str; | |
451 | for (; ISALNUM (*s) || *s == '.'; ++s) | |
452 | if (ISUPPER (*s)) | |
453 | *s = TOLOWER (*s); | |
454 | ||
455 | switch (*s) | |
456 | { | |
457 | case '\0': | |
458 | break; | |
459 | ||
460 | case ' ': /* FIXME-SOMEDAY more whitespace. */ | |
461 | *s++ = '\0'; | |
462 | break; | |
463 | ||
464 | default: | |
465 | as_bad (_("unknown opcode1: `%s'"), str); | |
466 | return; | |
467 | } | |
468 | ||
469 | if ((insn = (struct machine_opcode *) hash_find (op_hash, str)) == NULL) | |
470 | { | |
471 | as_bad (_("unknown opcode2 `%s'."), str); | |
472 | return; | |
473 | } | |
474 | ||
475 | argsStart = s; | |
476 | opcode = 0; | |
477 | memset (&the_insn, '\0', sizeof (the_insn)); | |
478 | the_insn.reloc = BFD_RELOC_NONE; | |
479 | ||
480 | reloc = BFD_RELOC_NONE; | |
481 | ||
482 | /* Build the opcode, checking as we go to make sure that the | |
483 | operands match. | |
5d6255fe | 484 | |
3b16e843 NC |
485 | If an operand matches, we modify the_insn or opcode appropriately, |
486 | and do a "continue". If an operand fails to match, we "break". */ | |
487 | if (insn->args[0] != '\0') | |
488 | { | |
489 | /* Prime the pump. */ | |
490 | s = parse_operand (s, operand, insn->args[0] == 'I'); | |
491 | } | |
492 | ||
493 | for (args = insn->args;; ++args) | |
494 | { | |
495 | #if DEBUG | |
496 | printf (" args = %s\n", args); | |
497 | #endif | |
498 | switch (*args) | |
499 | { | |
500 | case '\0': /* End of args. */ | |
501 | /* We have have 0 args, do the bazoooka! */ | |
502 | if (args == insn->args) | |
503 | encode (insn, &opcode, 0, 0); | |
504 | ||
505 | if (*s == '\0') | |
506 | { | |
507 | /* We are truly done. */ | |
508 | the_insn.opcode = opcode; | |
509 | if (check_invalid_opcode (opcode)) | |
5d6255fe | 510 | as_bad (_("instruction not allowed: %s"), str); |
3b16e843 NC |
511 | return; |
512 | } | |
513 | as_bad (_("too many operands: %s"), s); | |
514 | break; | |
515 | ||
516 | case ',': /* Must match a comma. */ | |
517 | if (*s++ == ',') | |
518 | { | |
519 | reloc = BFD_RELOC_NONE; | |
520 | ||
521 | /* Parse next operand. */ | |
522 | s = parse_operand (s, operand, args[1] == 'I'); | |
523 | #if DEBUG | |
524 | printf (" ',' case: operand->X_add_number = %d, *args = %s, *s = %s\n", | |
525 | operand->X_add_number, args, s); | |
5d6255fe | 526 | #endif |
3b16e843 NC |
527 | continue; |
528 | } | |
529 | break; | |
530 | ||
531 | case '(': /* Must match a (. */ | |
532 | s = parse_operand (s, operand, args[1] == 'I'); | |
533 | continue; | |
5d6255fe | 534 | |
3b16e843 NC |
535 | case ')': /* Must match a ). */ |
536 | continue; | |
537 | ||
538 | case 'r': /* A general register. */ | |
539 | args++; | |
540 | ||
541 | if (operand->X_op != O_register) | |
542 | break; /* Only registers. */ | |
5d6255fe | 543 | |
3b16e843 NC |
544 | know (operand->X_add_symbol == 0); |
545 | know (operand->X_op_symbol == 0); | |
546 | regno = operand->X_add_number; | |
547 | encode (insn, &opcode, regno, *args); | |
548 | #if DEBUG | |
549 | printf (" r: operand->X_op = %d\n", operand->X_op); | |
550 | #endif | |
551 | continue; | |
552 | ||
553 | default: | |
554 | /* if (! ISALPHA (*args)) | |
555 | break; */ /* Only immediate values. */ | |
5d6255fe | 556 | |
3b16e843 NC |
557 | if (mask_or_shift) |
558 | { | |
559 | #if DEBUG | |
560 | printf ("mask_or_shift = %d\n", mask_or_shift); | |
561 | #endif | |
562 | reloc = mask_or_shift; | |
563 | } | |
564 | mask_or_shift = 0; | |
5d6255fe KH |
565 | |
566 | if (strncasecmp (args, "LO(", 3) == 0) | |
3b16e843 NC |
567 | { |
568 | #if DEBUG | |
569 | printf ("reloc_const\n"); | |
570 | #endif | |
571 | reloc = BFD_RELOC_LO16; | |
572 | } | |
5d6255fe | 573 | else if (strncasecmp (args, "HI(", 3) == 0) |
3b16e843 NC |
574 | { |
575 | #if DEBUG | |
576 | printf ("reloc_consth\n"); | |
577 | #endif | |
578 | reloc = BFD_RELOC_HI16; | |
579 | } | |
5d6255fe KH |
580 | |
581 | if (*s == '(') | |
3b16e843 NC |
582 | { |
583 | operand->X_op = O_constant; | |
3b16e843 NC |
584 | } |
585 | else if (*s == ')') | |
586 | s += 1; | |
587 | #if DEBUG | |
588 | printf (" default case: operand->X_add_number = %d, *args = %s, *s = %s\n", operand->X_add_number, args, s); | |
589 | #endif | |
590 | if (operand->X_op == O_constant) | |
591 | { | |
592 | if (reloc == BFD_RELOC_NONE) | |
593 | { | |
594 | bfd_vma v, mask; | |
595 | ||
596 | mask = 0x3ffffff; | |
597 | v = abs (operand->X_add_number) & ~ mask; | |
598 | if (v) | |
599 | as_bad (_("call/jmp target out of range (1)")); | |
600 | } | |
601 | ||
602 | if (reloc == BFD_RELOC_HI16) | |
603 | operand->X_add_number = ((operand->X_add_number >> 16) & 0xffff); | |
604 | ||
605 | the_insn.pcrel = 0; | |
606 | encode (insn, &opcode, operand->X_add_number, *args); | |
607 | /* the_insn.reloc = BFD_RELOC_NONE; */ | |
5d6255fe | 608 | continue; |
3b16e843 NC |
609 | } |
610 | ||
611 | if (reloc == BFD_RELOC_NONE) | |
612 | the_insn.reloc = BFD_RELOC_32_GOT_PCREL; | |
613 | else | |
614 | the_insn.reloc = reloc; | |
615 | ||
616 | /* the_insn.reloc = insn->reloc; */ | |
617 | #if DEBUG | |
618 | printf (" reloc sym=%d\n", the_insn.reloc); | |
619 | printf (" BFD_RELOC_NONE=%d\n", BFD_RELOC_NONE); | |
620 | #endif | |
621 | the_insn.exp = *operand; | |
5d6255fe | 622 | |
3b16e843 NC |
623 | /* the_insn.reloc_offset = 1; */ |
624 | the_insn.pcrel = 1; /* Assume PC-relative jump. */ | |
625 | ||
626 | /* FIXME-SOON, Do we figure out whether abs later, after | |
627 | know sym val? */ | |
628 | if (reloc == BFD_RELOC_LO16 || reloc == BFD_RELOC_HI16) | |
629 | the_insn.pcrel = 0; | |
630 | ||
631 | encode (insn, &opcode, operand->X_add_number, *args); | |
632 | continue; | |
633 | } | |
5d6255fe | 634 | |
3b16e843 NC |
635 | /* Types or values of args don't match. */ |
636 | as_bad (_("invalid operands")); | |
637 | return; | |
638 | } | |
639 | } | |
640 | ||
641 | #else | |
642 | ||
643 | static void | |
644 | machine_ip (str) | |
645 | char *str; | |
646 | { | |
647 | char *s; | |
648 | const char *args; | |
649 | const struct machine_opcode *insn; | |
650 | char *argsStart; | |
651 | unsigned long opcode; | |
652 | expressionS the_operand; | |
653 | expressionS *operand = &the_operand; | |
654 | unsigned int regno; | |
655 | int reloc = NO_RELOC; | |
656 | ||
657 | #if DEBUG | |
658 | printf ("machine_ip(%s)\n", str); | |
659 | #endif | |
660 | ||
661 | s = str; | |
662 | for (; ISALNUM (*s) || *s == '.'; ++s) | |
663 | if (ISUPPER (*s)) | |
664 | *s = TOLOWER (*s); | |
665 | ||
666 | switch (*s) | |
667 | { | |
668 | case '\0': | |
669 | break; | |
670 | ||
671 | case ' ': /* FIXME-SOMEDAY more whitespace. */ | |
672 | *s++ = '\0'; | |
673 | break; | |
674 | ||
675 | default: | |
676 | as_bad (_("unknown opcode1: `%s'"), str); | |
677 | return; | |
678 | } | |
679 | ||
680 | if ((insn = (struct machine_opcode *) hash_find (op_hash, str)) == NULL) | |
681 | { | |
682 | as_bad (_("unknown opcode2 `%s'."), str); | |
683 | return; | |
684 | } | |
685 | ||
686 | argsStart = s; | |
687 | opcode = 0; | |
688 | memset (&the_insn, '\0', sizeof (the_insn)); | |
689 | the_insn.reloc = NO_RELOC; | |
690 | ||
691 | reloc = NO_RELOC; | |
692 | ||
693 | /* Build the opcode, checking as we go to make sure that the | |
694 | operands match. | |
5d6255fe | 695 | |
3b16e843 NC |
696 | If an operand matches, we modify the_insn or opcode appropriately, |
697 | and do a "continue". If an operand fails to match, we "break". */ | |
698 | if (insn->args[0] != '\0') | |
5d6255fe | 699 | /* Prime the pump. */ |
3b16e843 NC |
700 | s = parse_operand (s, operand, |
701 | insn->args[0] == 'I' | |
702 | || strcmp (insn->name, "l.nop") == 0); | |
703 | ||
704 | for (args = insn->args;; ++args) | |
705 | { | |
706 | #if DEBUG | |
707 | printf (" args = %s\n", args); | |
708 | #endif | |
709 | switch (*args) | |
710 | { | |
711 | case '\0': /* End of args. */ | |
712 | /* We have have 0 args, do the bazoooka! */ | |
713 | if (args == insn->args) | |
714 | encode (insn, &opcode, 0, 0); | |
715 | ||
716 | if (*s == '\0') | |
717 | { | |
718 | /* We are truly done. */ | |
719 | the_insn.opcode = opcode; | |
720 | if (check_invalid_opcode (opcode)) | |
5d6255fe | 721 | as_bad (_("instruction not allowed: %s"), str); |
3b16e843 NC |
722 | return; |
723 | } | |
724 | as_bad (_("too many operands: %s"), s); | |
725 | break; | |
726 | ||
727 | case ',': /* Must match a comma. */ | |
728 | if (*s++ == ',') | |
729 | { | |
730 | reloc = NO_RELOC; | |
731 | ||
732 | /* Parse next operand. */ | |
733 | s = parse_operand (s, operand, args[1] == 'I'); | |
734 | #if DEBUG | |
735 | printf (" ',' case: operand->X_add_number = %d, *args = %s, *s = %s\n", | |
736 | operand->X_add_number, args, s); | |
5d6255fe | 737 | #endif |
3b16e843 NC |
738 | continue; |
739 | } | |
740 | break; | |
741 | ||
742 | case '(': /* Must match a (. */ | |
743 | s = parse_operand (s, operand, args[1] == 'I'); | |
744 | continue; | |
5d6255fe | 745 | |
3b16e843 NC |
746 | case ')': /* Must match a ). */ |
747 | continue; | |
748 | ||
749 | case 'r': /* A general register. */ | |
750 | args++; | |
751 | ||
752 | if (operand->X_op != O_register) | |
753 | break; /* Only registers. */ | |
5d6255fe | 754 | |
3b16e843 NC |
755 | know (operand->X_add_symbol == 0); |
756 | know (operand->X_op_symbol == 0); | |
757 | regno = operand->X_add_number; | |
758 | encode (insn, &opcode, regno, *args); | |
759 | #if DEBUG | |
760 | printf (" r: operand->X_op = %d\n", operand->X_op); | |
761 | #endif | |
762 | continue; | |
763 | ||
764 | default: | |
765 | /* if (! ISALPHA (*args)) | |
766 | break; */ /* Only immediate values. */ | |
5d6255fe | 767 | |
3b16e843 NC |
768 | if (mask_or_shift) |
769 | { | |
770 | #if DEBUG | |
771 | printf ("mask_or_shift = %d\n", mask_or_shift); | |
772 | #endif | |
773 | reloc = mask_or_shift; | |
774 | } | |
775 | mask_or_shift = 0; | |
5d6255fe KH |
776 | |
777 | if (strncasecmp (args, "LO(", 3) == 0) | |
3b16e843 NC |
778 | { |
779 | #if DEBUG | |
780 | printf ("reloc_const\n"); | |
781 | #endif | |
782 | reloc = RELOC_CONST; | |
783 | } | |
5d6255fe | 784 | else if (strncasecmp (args, "HI(", 3) == 0) |
3b16e843 NC |
785 | { |
786 | #if DEBUG | |
787 | printf ("reloc_consth\n"); | |
788 | #endif | |
789 | reloc = RELOC_CONSTH; | |
790 | } | |
5d6255fe KH |
791 | |
792 | if (*s == '(') | |
3b16e843 NC |
793 | { |
794 | operand->X_op = O_constant; | |
3b16e843 NC |
795 | } |
796 | else if (*s == ')') | |
797 | s += 1; | |
798 | #if DEBUG | |
799 | printf (" default case: operand->X_add_number = %d, *args = %s, *s = %s\n", | |
800 | operand->X_add_number, args, s); | |
801 | #endif | |
802 | if (operand->X_op == O_constant) | |
803 | { | |
804 | if (reloc == NO_RELOC) | |
805 | { | |
806 | unsigned long v, mask; | |
807 | ||
808 | mask = 0x3ffffff; | |
809 | v = abs (operand->X_add_number) & ~ mask; | |
810 | if (v) | |
811 | as_bad (_("call/jmp target out of range (1)")); | |
812 | } | |
813 | ||
814 | if (reloc == RELOC_CONSTH) | |
815 | operand->X_add_number = ((operand->X_add_number>>16) & 0xffff); | |
816 | ||
817 | the_insn.pcrel = 0; | |
818 | encode (insn, &opcode, operand->X_add_number, *args); | |
819 | /* the_insn.reloc = NO_RELOC; */ | |
5d6255fe | 820 | continue; |
3b16e843 NC |
821 | } |
822 | ||
823 | if (reloc == NO_RELOC) | |
824 | the_insn.reloc = RELOC_JUMPTARG; | |
825 | else | |
826 | the_insn.reloc = reloc; | |
827 | #if DEBUG | |
828 | printf (" reloc sym=%d\n", the_insn.reloc); | |
829 | printf (" NO_RELOC=%d\n", NO_RELOC); | |
830 | #endif | |
831 | the_insn.exp = *operand; | |
5d6255fe | 832 | |
3b16e843 NC |
833 | /* the_insn.reloc_offset = 1; */ |
834 | the_insn.pcrel = 1; /* Assume PC-relative jump. */ | |
835 | ||
836 | /* FIXME-SOON, Do we figure out whether abs later, after | |
837 | know sym val? */ | |
838 | if (reloc == RELOC_CONST || reloc == RELOC_CONSTH) | |
839 | the_insn.pcrel = 0; | |
840 | ||
841 | encode (insn, &opcode, operand->X_add_number, *args); | |
842 | continue; | |
843 | } | |
5d6255fe | 844 | |
3b16e843 NC |
845 | /* Types or values of args don't match. */ |
846 | as_bad (_("invalid operands")); | |
847 | return; | |
848 | } | |
849 | } | |
850 | #endif | |
851 | ||
852 | /* This is identical to the md_atof in m68k.c. I think this is right, | |
853 | but I'm not sure. | |
854 | ||
855 | Turn a string in input_line_pointer into a floating point constant | |
856 | of type type, and store the appropriate bytes in *litP. The number | |
857 | of LITTLENUMS emitted is stored in *sizeP . An error message is | |
858 | returned, or NULL on OK. */ | |
859 | ||
860 | /* Equal to MAX_PRECISION in atof-ieee.c. */ | |
861 | #define MAX_LITTLENUMS 6 | |
862 | ||
863 | char * | |
864 | md_atof (type, litP, sizeP) | |
865 | char type; | |
866 | char * litP; | |
867 | int * sizeP; | |
868 | { | |
869 | int prec; | |
870 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
871 | LITTLENUM_TYPE *wordP; | |
872 | char *t; | |
873 | ||
874 | switch (type) | |
875 | { | |
876 | case 'f': | |
877 | case 'F': | |
878 | case 's': | |
879 | case 'S': | |
880 | prec = 2; | |
881 | break; | |
882 | ||
883 | case 'd': | |
884 | case 'D': | |
885 | case 'r': | |
886 | case 'R': | |
887 | prec = 4; | |
888 | break; | |
889 | ||
890 | case 'x': | |
891 | case 'X': | |
892 | prec = 6; | |
893 | break; | |
894 | ||
895 | case 'p': | |
896 | case 'P': | |
897 | prec = 6; | |
898 | break; | |
899 | ||
900 | default: | |
901 | *sizeP = 0; | |
902 | return _("Bad call to MD_ATOF()"); | |
903 | } | |
904 | ||
905 | t = atof_ieee (input_line_pointer, type, words); | |
906 | if (t) | |
907 | input_line_pointer = t; | |
908 | ||
909 | *sizeP = prec * sizeof (LITTLENUM_TYPE); | |
910 | ||
911 | for (wordP = words; prec--;) | |
912 | { | |
913 | md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE)); | |
914 | litP += sizeof (LITTLENUM_TYPE); | |
915 | } | |
916 | ||
917 | return NULL; | |
918 | } | |
919 | ||
920 | /* Write out big-endian. */ | |
921 | ||
922 | void | |
923 | md_number_to_chars (buf, val, n) | |
924 | char *buf; | |
925 | valueT val; | |
926 | int n; | |
927 | { | |
928 | number_to_chars_bigendian (buf, val, n); | |
929 | } | |
930 | ||
931 | #ifdef BFD_ASSEMBLER | |
932 | void | |
933 | md_apply_fix3 (fixP, val, seg) | |
934 | fixS * fixP; | |
935 | valueT * val; | |
936 | segT seg ATTRIBUTE_UNUSED; | |
937 | { | |
938 | char *buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
939 | long t_val; | |
940 | ||
941 | t_val = (long) *val; | |
942 | ||
943 | #if DEBUG | |
944 | printf ("md_apply_fix val:%x\n", t_val); | |
945 | #endif | |
946 | ||
947 | fixP->fx_addnumber = t_val; /* Remember value for emit_reloc. */ | |
948 | ||
949 | know (fixP->fx_size == 4); | |
950 | know (fixP->fx_r_type < BFD_RELOC_NONE); | |
951 | ||
952 | switch (fixP->fx_r_type) | |
953 | { | |
954 | case BFD_RELOC_32: /* XXXXXXXX pattern in a word. */ | |
955 | #if DEBUG | |
956 | printf ("reloc_const: val=%x\n", t_val); | |
957 | #endif | |
958 | buf[0] = t_val >> 24; | |
959 | buf[1] = t_val >> 16; | |
960 | buf[2] = t_val >> 8; | |
961 | buf[3] = t_val; | |
962 | break; | |
963 | ||
964 | case BFD_RELOC_16: /* XXXX0000 pattern in a word. */ | |
965 | #if DEBUG | |
966 | printf ("reloc_const: val=%x\n", t_val); | |
967 | #endif | |
968 | buf[0] = t_val >> 8; | |
969 | buf[1] = t_val; | |
970 | break; | |
971 | ||
972 | case BFD_RELOC_8: /* XX000000 pattern in a word. */ | |
973 | #if DEBUG | |
974 | printf ("reloc_const: val=%x\n", t_val); | |
975 | #endif | |
976 | buf[0] = t_val; | |
977 | break; | |
978 | ||
979 | case BFD_RELOC_LO16: /* 0000XXXX pattern in a word. */ | |
980 | #if DEBUG | |
981 | printf ("reloc_const: val=%x\n", t_val); | |
982 | #endif | |
983 | buf[2] = t_val >> 8; /* Holds bits 0000XXXX. */ | |
984 | buf[3] = t_val; | |
985 | break; | |
986 | ||
987 | case BFD_RELOC_HI16: /* 0000XXXX pattern in a word. */ | |
988 | #if DEBUG | |
989 | printf ("reloc_consth: val=%x\n", t_val); | |
990 | #endif | |
991 | buf[2] = t_val >> 24; /* Holds bits XXXX0000. */ | |
992 | buf[3] = t_val >> 16; | |
993 | break; | |
994 | ||
995 | case BFD_RELOC_32_GOT_PCREL: /* 0000XXXX pattern in a word. */ | |
996 | if (!fixP->fx_done) | |
65ec77d2 | 997 | ; |
3b16e843 NC |
998 | else if (fixP->fx_pcrel) |
999 | { | |
1000 | long v = t_val >> 28; | |
1001 | ||
1002 | if (v != 0 && v != -1) | |
1003 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
1004 | _("call/jmp target out of range (2)")); | |
1005 | } | |
1006 | else | |
1007 | /* This case was supposed to be handled in machine_ip. */ | |
1008 | abort (); | |
1009 | ||
1010 | buf[0] |= (t_val >> 26) & 0x03; /* Holds bits 0FFFFFFC of address. */ | |
1011 | buf[1] = t_val >> 18; | |
1012 | buf[2] = t_val >> 10; | |
1013 | buf[3] = t_val >> 2; | |
1014 | break; | |
1015 | ||
1016 | case BFD_RELOC_VTABLE_INHERIT: | |
1017 | case BFD_RELOC_VTABLE_ENTRY: | |
1018 | fixP->fx_done = 0; | |
1019 | break; | |
1020 | ||
1021 | case BFD_RELOC_NONE: | |
1022 | default: | |
1023 | as_bad (_("bad relocation type: 0x%02x"), fixP->fx_r_type); | |
1024 | break; | |
1025 | } | |
1026 | ||
1027 | if (fixP->fx_addsy == (symbolS *) NULL) | |
1028 | fixP->fx_done = 1; | |
1029 | } | |
1030 | #else | |
1031 | void | |
1032 | md_apply_fix3 (fixP, valP, seg) | |
1033 | fixS *fixP; | |
1034 | valueT *valP; | |
1035 | segT seg ATTRIBUTE_UNUSED; | |
1036 | { | |
a161fe53 | 1037 | long val = *valP; |
3b16e843 NC |
1038 | char *buf = fixP->fx_where + fixP->fx_frag->fr_literal; |
1039 | ||
1040 | #if DEBUG | |
1041 | printf ("md_apply_fix val:%x\n", val); | |
1042 | #endif | |
1043 | ||
1044 | fixP->fx_addnumber = val; /* Remember value for emit_reloc. */ | |
1045 | ||
1046 | know (fixP->fx_size == 4); | |
1047 | know (fixP->fx_r_type < NO_RELOC); | |
1048 | ||
1049 | /* This is a hack. There should be a better way to handle this. */ | |
1050 | if (fixP->fx_r_type == RELOC_WDISP30 && fixP->fx_addsy) | |
1051 | val += fixP->fx_where + fixP->fx_frag->fr_address; | |
1052 | ||
1053 | switch (fixP->fx_r_type) | |
1054 | { | |
1055 | case RELOC_32: | |
1056 | buf[0] = val >> 24; | |
1057 | buf[1] = val >> 16; | |
1058 | buf[2] = val >> 8; | |
1059 | buf[3] = val; | |
1060 | break; | |
1061 | ||
1062 | case RELOC_8: | |
1063 | buf[0] = val; | |
1064 | break; | |
1065 | ||
1066 | case RELOC_WDISP30: | |
717acf4b | 1067 | val = (val >> 2) + 1; |
3b16e843 NC |
1068 | buf[0] |= (val >> 24) & 0x3f; |
1069 | buf[1] = (val >> 16); | |
1070 | buf[2] = val >> 8; | |
1071 | buf[3] = val; | |
1072 | break; | |
1073 | ||
1074 | case RELOC_HI22: | |
1075 | buf[1] |= (val >> 26) & 0x3f; | |
1076 | buf[2] = val >> 18; | |
1077 | buf[3] = val >> 10; | |
1078 | break; | |
1079 | ||
1080 | case RELOC_LO10: | |
1081 | buf[2] |= (val >> 8) & 0x03; | |
1082 | buf[3] = val; | |
1083 | break; | |
1084 | ||
1085 | case RELOC_BASE13: | |
1086 | buf[2] |= (val >> 8) & 0x1f; | |
1087 | buf[3] = val; | |
1088 | break; | |
1089 | ||
1090 | case RELOC_WDISP22: | |
717acf4b | 1091 | val = (val >> 2) + 1; |
3b16e843 NC |
1092 | /* FALLTHROUGH */ |
1093 | case RELOC_BASE22: | |
1094 | buf[1] |= (val >> 16) & 0x3f; | |
1095 | buf[2] = val >> 8; | |
1096 | buf[3] = val; | |
1097 | break; | |
1098 | ||
1099 | case RELOC_JUMPTARG: /* 0000XXXX pattern in a word. */ | |
1100 | if (!fixP->fx_done) | |
1101 | { | |
1102 | /* The linker tries to support both AMD and old GNU style | |
1103 | R_IREL relocs. That means that if the addend is exactly | |
1104 | the negative of the address within the section, the | |
1105 | linker will not handle it correctly. */ | |
3b16e843 NC |
1106 | } |
1107 | else if (fixP->fx_pcrel) | |
1108 | { | |
1109 | long v = val >> 28; | |
3b16e843 NC |
1110 | if (v != 0 && v != -1) |
1111 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
1112 | _("call/jmp target out of range (2)")); | |
3b16e843 NC |
1113 | } |
1114 | else | |
1115 | /* This case was supposed to be handled in machine_ip. */ | |
1116 | abort (); | |
1117 | ||
1118 | buf[0] |= (val >> 26) & 0x03; /* Holds bits 0FFFFFFC of address. */ | |
1119 | buf[1] = val >> 18; | |
1120 | buf[2] = val >> 10; | |
1121 | buf[3] = val >> 2; | |
1122 | break; | |
1123 | ||
1124 | case RELOC_CONST: /* 0000XXXX pattern in a word. */ | |
1125 | #if DEBUG | |
1126 | printf ("reloc_const: val=%x\n", val); | |
1127 | #endif | |
1128 | buf[2] = val >> 8; /* Holds bits 0000XXXX. */ | |
1129 | buf[3] = val; | |
1130 | break; | |
1131 | ||
1132 | case RELOC_CONSTH: /* 0000XXXX pattern in a word. */ | |
1133 | #if DEBUG | |
1134 | printf ("reloc_consth: val=%x\n", val); | |
1135 | #endif | |
1136 | buf[2] = val >> 24; /* Holds bits XXXX0000. */ | |
1137 | buf[3] = val >> 16; | |
1138 | break; | |
1139 | ||
1140 | case BFD_RELOC_VTABLE_INHERIT: | |
1141 | case BFD_RELOC_VTABLE_ENTRY: | |
1142 | fixP->fx_done = 0; | |
1143 | break; | |
1144 | ||
1145 | case NO_RELOC: | |
1146 | default: | |
1147 | as_bad (_("bad relocation type: 0x%02x"), fixP->fx_r_type); | |
1148 | break; | |
1149 | } | |
1150 | ||
1151 | if (fixP->fx_addsy == (symbolS *) NULL) | |
1152 | fixP->fx_done = 1; | |
1153 | } | |
1154 | #endif | |
1155 | ||
1156 | #ifdef OBJ_COFF | |
1157 | short | |
1158 | tc_coff_fix2rtype (fixP) | |
1159 | fixS *fixP; | |
1160 | { | |
1161 | #if DEBUG | |
1162 | printf ("tc_coff_fix2rtype\n"); | |
1163 | #endif | |
1164 | ||
1165 | switch (fixP->fx_r_type) | |
1166 | { | |
1167 | case RELOC_32: | |
1168 | return (R_WORD); | |
1169 | case RELOC_8: | |
1170 | return (R_BYTE); | |
1171 | case RELOC_CONST: | |
1172 | return (R_ILOHALF); | |
1173 | case RELOC_CONSTH: | |
1174 | return (R_IHIHALF); | |
1175 | case RELOC_JUMPTARG: | |
1176 | return (R_IREL); | |
1177 | default: | |
1178 | printf ("need %d\n", fixP->fx_r_type); | |
1179 | abort (); | |
1180 | } | |
1181 | ||
1182 | return 0; | |
1183 | } | |
1184 | ||
1185 | #endif /* OBJ_COFF */ | |
1186 | ||
1187 | /* Should never be called for or32. */ | |
1188 | ||
1189 | void | |
1190 | md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol) | |
1191 | char * ptr ATTRIBUTE_UNUSED; | |
1192 | addressT from_addr ATTRIBUTE_UNUSED; | |
1193 | addressT to_addr ATTRIBUTE_UNUSED; | |
1194 | fragS * frag ATTRIBUTE_UNUSED; | |
1195 | symbolS * to_symbol ATTRIBUTE_UNUSED; | |
1196 | { | |
1197 | as_fatal ("or32_create_short_jmp\n"); | |
1198 | } | |
1199 | ||
1200 | /* Should never be called for or32. */ | |
1201 | ||
1202 | #ifndef BFD_ASSEMBLER | |
1203 | void | |
1204 | md_convert_frag (headers, seg, fragP) | |
1205 | object_headers * headers ATTRIBUTE_UNUSED; | |
1206 | segT seg ATTRIBUTE_UNUSED; | |
1207 | register fragS * fragP ATTRIBUTE_UNUSED; | |
1208 | { | |
1209 | as_fatal ("or32_convert_frag\n"); | |
1210 | } | |
1211 | ||
1212 | #else | |
1213 | void | |
1214 | md_convert_frag (headers, seg, fragP) | |
1215 | bfd * headers ATTRIBUTE_UNUSED; | |
1216 | segT seg ATTRIBUTE_UNUSED; | |
1217 | fragS * fragP ATTRIBUTE_UNUSED; | |
1218 | { | |
1219 | as_fatal ("or32_convert_frag\n"); | |
5d6255fe | 1220 | } |
3b16e843 NC |
1221 | #endif |
1222 | ||
1223 | /* Should never be called for or32. */ | |
1224 | ||
1225 | void | |
1226 | md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol) | |
1227 | char * ptr ATTRIBUTE_UNUSED; | |
1228 | addressT from_addr ATTRIBUTE_UNUSED; | |
1229 | addressT to_addr ATTRIBUTE_UNUSED; | |
1230 | fragS * frag ATTRIBUTE_UNUSED; | |
1231 | symbolS * to_symbol ATTRIBUTE_UNUSED; | |
1232 | { | |
1233 | as_fatal ("or32_create_long_jump\n"); | |
1234 | } | |
1235 | ||
1236 | /* Should never be called for or32. */ | |
1237 | ||
1238 | int | |
1239 | md_estimate_size_before_relax (fragP, segtype) | |
1240 | fragS * fragP ATTRIBUTE_UNUSED; | |
1241 | segT segtype ATTRIBUTE_UNUSED; | |
1242 | { | |
1243 | as_fatal ("or32_estimate_size_before_relax\n"); | |
1244 | return 0; | |
1245 | } | |
1246 | ||
1247 | /* Translate internal representation of relocation info to target format. | |
1248 | ||
1249 | On sparc/29k: first 4 bytes are normal unsigned long address, next three | |
1250 | bytes are index, most sig. byte first. Byte 7 is broken up with | |
1251 | bit 7 as external, bits 6 & 5 unused, and the lower | |
1252 | five bits as relocation type. Next 4 bytes are long addend. */ | |
1253 | /* Thanx and a tip of the hat to Michael Bloom, [email protected]. */ | |
1254 | ||
1255 | #ifdef OBJ_AOUT | |
1256 | void | |
1257 | tc_aout_fix_to_chars (where, fixP, segment_address_in_file) | |
1258 | char *where; | |
1259 | fixS *fixP; | |
1260 | relax_addressT segment_address_in_file; | |
1261 | { | |
1262 | long r_symbolnum; | |
1263 | ||
1264 | #if DEBUG | |
1265 | printf ("tc_aout_fix_to_chars\n"); | |
5d6255fe | 1266 | #endif |
3b16e843 NC |
1267 | |
1268 | know (fixP->fx_r_type < BFD_RELOC_NONE); | |
1269 | know (fixP->fx_addsy != NULL); | |
1270 | ||
1271 | md_number_to_chars | |
1272 | (where, | |
1273 | fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file, | |
1274 | 4); | |
1275 | ||
1276 | r_symbolnum = (S_IS_DEFINED (fixP->fx_addsy) | |
1277 | ? S_GET_TYPE (fixP->fx_addsy) | |
1278 | : fixP->fx_addsy->sy_number); | |
1279 | ||
1280 | where[4] = (r_symbolnum >> 16) & 0x0ff; | |
1281 | where[5] = (r_symbolnum >> 8) & 0x0ff; | |
1282 | where[6] = r_symbolnum & 0x0ff; | |
1283 | where[7] = (((!S_IS_DEFINED (fixP->fx_addsy)) << 7) & 0x80) | (0 & 0x60) | (fixP->fx_r_type & 0x1F); | |
1284 | ||
1285 | /* Also easy. */ | |
1286 | md_number_to_chars (&where[8], fixP->fx_addnumber, 4); | |
1287 | } | |
1288 | ||
1289 | #endif /* OBJ_AOUT */ | |
1290 | \f | |
1291 | const char *md_shortopts = ""; | |
1292 | ||
1293 | struct option md_longopts[] = | |
1294 | { | |
1295 | { NULL, no_argument, NULL, 0 } | |
1296 | }; | |
1297 | size_t md_longopts_size = sizeof (md_longopts); | |
1298 | ||
1299 | int | |
1300 | md_parse_option (c, arg) | |
1301 | int c ATTRIBUTE_UNUSED; | |
1302 | char * arg ATTRIBUTE_UNUSED; | |
1303 | { | |
1304 | return 0; | |
1305 | } | |
1306 | ||
1307 | void | |
1308 | md_show_usage (stream) | |
1309 | FILE * stream ATTRIBUTE_UNUSED; | |
1310 | { | |
1311 | } | |
1312 | \f | |
1313 | /* This is called when a line is unrecognized. This is used to handle | |
1314 | definitions of or32 style local labels. */ | |
1315 | ||
1316 | int | |
1317 | or32_unrecognized_line (c) | |
1318 | int c; | |
1319 | { | |
1320 | int lab; | |
1321 | char *s; | |
1322 | ||
1323 | if (c != '$' | |
1324 | || ! ISDIGIT ((unsigned char) input_line_pointer[0])) | |
1325 | return 0; | |
1326 | ||
1327 | s = input_line_pointer; | |
1328 | ||
1329 | lab = 0; | |
1330 | while (ISDIGIT ((unsigned char) *s)) | |
1331 | { | |
1332 | lab = lab * 10 + *s - '0'; | |
1333 | ++s; | |
1334 | } | |
1335 | ||
1336 | if (*s != ':') | |
1337 | /* Not a label definition. */ | |
1338 | return 0; | |
1339 | ||
1340 | if (dollar_label_defined (lab)) | |
1341 | { | |
1342 | as_bad (_("label \"$%d\" redefined"), lab); | |
1343 | return 0; | |
1344 | } | |
1345 | ||
1346 | define_dollar_label (lab); | |
1347 | colon (dollar_label_name (lab, 0)); | |
1348 | input_line_pointer = s + 1; | |
1349 | ||
1350 | return 1; | |
1351 | } | |
1352 | ||
1353 | #ifndef BFD_ASSEMBLER | |
1354 | /* Record a fixup for a cons expression. */ | |
1355 | /* | |
1356 | void | |
1357 | or32_cons_fix_new (frag, where, nbytes, exp) | |
1358 | fragS *frag; | |
1359 | int where; | |
1360 | int nbytes; | |
1361 | expressionS *exp; | |
1362 | { | |
1363 | fix_new_exp (frag, where, nbytes, exp, 0, | |
1364 | nbytes == 5 ? RELOC_32 | |
1365 | : nbytes == 2 ? RELOC_16 | |
1366 | : RELOC_8); | |
1367 | } | |
1368 | void | |
1369 | tc_aout_pre_write_hook () | |
1370 | { | |
1371 | #if DEBUG | |
1372 | printf ("In tc_aout_pre_write_hook()\n"); | |
1373 | #endif | |
5d6255fe KH |
1374 | } |
1375 | */ | |
3b16e843 NC |
1376 | #endif |
1377 | ||
1378 | /* Default the values of symbols known that should be "predefined". We | |
1379 | don't bother to predefine them unless you actually use one, since there | |
1380 | are a lot of them. */ | |
1381 | ||
1382 | symbolS * | |
1383 | md_undefined_symbol (name) | |
1384 | char *name ATTRIBUTE_UNUSED; | |
1385 | { | |
1386 | #ifndef BFD_ASSEMBLER | |
1387 | long regnum; | |
1388 | char testbuf[5 + /*SLOP*/ 5]; | |
1389 | ||
1390 | #if DEBUG | |
1391 | printf ("md_undefined_symbol(%s)\n", name); | |
1392 | #endif | |
1393 | ||
1394 | /* Register name. */ | |
5d6255fe KH |
1395 | if (name[0] == 'r' || name[0] == 'R' || name[0] == 'a' || name[0] == 'b') |
1396 | { | |
3b16e843 NC |
1397 | /* Parse the number, make sure it has no extra zeroes or |
1398 | trailing chars. */ | |
1399 | regnum = atol (& name[1]); | |
1400 | ||
1401 | if (regnum > 31) | |
1402 | as_fatal (_("register out of range")); | |
1403 | ||
1404 | sprintf (testbuf, "%ld", regnum); | |
1405 | ||
1406 | if (strcmp (testbuf, &name[1]) != 0) | |
1407 | return NULL; /* gr007 or lr7foo or whatever. */ | |
1408 | ||
1409 | /* We have a wiener! Define and return a new symbol for it. */ | |
1410 | return (symbol_new (name, SEG_REGISTER, (valueT) regnum, | |
1411 | &zero_address_frag)); | |
1412 | } | |
1413 | #endif | |
1414 | return NULL; | |
1415 | } | |
1416 | ||
1417 | /* Parse an operand that is machine-specific. */ | |
1418 | ||
1419 | void | |
1420 | md_operand (expressionP) | |
1421 | expressionS *expressionP; | |
1422 | { | |
1423 | #if DEBUG | |
1424 | printf (" md_operand(input_line_pointer = %s)\n", input_line_pointer); | |
1425 | #endif | |
1426 | ||
1427 | if (input_line_pointer[0] == REGISTER_PREFIX && input_line_pointer[1] == 'r') | |
1428 | { | |
1429 | /* We have a numeric register expression. No biggy. */ | |
1430 | input_line_pointer += 2; /* Skip %r */ | |
1431 | (void) expression (expressionP); | |
1432 | ||
1433 | if (expressionP->X_op != O_constant | |
1434 | || expressionP->X_add_number > 255) | |
1435 | as_bad (_("Invalid expression after %%%%\n")); | |
1436 | expressionP->X_op = O_register; | |
1437 | } | |
1438 | else if (input_line_pointer[0] == '&') | |
1439 | { | |
1440 | /* We are taking the 'address' of a register...this one is not | |
1441 | in the manual, but it *is* in traps/fpsymbol.h! What they | |
1442 | seem to want is the register number, as an absolute number. */ | |
1443 | input_line_pointer++; /* Skip & */ | |
1444 | (void) expression (expressionP); | |
1445 | ||
1446 | if (expressionP->X_op != O_register) | |
1447 | as_bad (_("invalid register in & expression")); | |
1448 | else | |
1449 | expressionP->X_op = O_constant; | |
1450 | } | |
1451 | else if (input_line_pointer[0] == '$' | |
1452 | && ISDIGIT ((unsigned char) input_line_pointer[1])) | |
1453 | { | |
1454 | long lab; | |
1455 | char *name; | |
1456 | symbolS *sym; | |
5d6255fe | 1457 | |
3b16e843 NC |
1458 | /* This is a local label. */ |
1459 | ++input_line_pointer; | |
1460 | lab = (long) get_absolute_expression (); | |
1461 | ||
1462 | if (dollar_label_defined (lab)) | |
1463 | { | |
1464 | name = dollar_label_name (lab, 0); | |
1465 | sym = symbol_find (name); | |
1466 | } | |
1467 | else | |
1468 | { | |
1469 | name = dollar_label_name (lab, 1); | |
1470 | sym = symbol_find_or_make (name); | |
1471 | } | |
1472 | ||
1473 | expressionP->X_op = O_symbol; | |
1474 | expressionP->X_add_symbol = sym; | |
1475 | expressionP->X_add_number = 0; | |
1476 | } | |
1477 | else if (input_line_pointer[0] == '$') | |
1478 | { | |
1479 | char *s; | |
1480 | char type; | |
1481 | int fieldnum, fieldlimit; | |
1482 | LITTLENUM_TYPE floatbuf[8]; | |
1483 | ||
1484 | /* $float(), $doubleN(), or $extendN() convert floating values | |
1485 | to integers. */ | |
1486 | s = input_line_pointer; | |
1487 | ||
1488 | ++s; | |
1489 | ||
1490 | fieldnum = 0; | |
1491 | if (strncmp (s, "double", sizeof "double" - 1) == 0) | |
1492 | { | |
1493 | s += sizeof "double" - 1; | |
1494 | type = 'd'; | |
1495 | fieldlimit = 2; | |
1496 | } | |
1497 | else if (strncmp (s, "float", sizeof "float" - 1) == 0) | |
1498 | { | |
1499 | s += sizeof "float" - 1; | |
1500 | type = 'f'; | |
1501 | fieldlimit = 1; | |
1502 | } | |
1503 | else if (strncmp (s, "extend", sizeof "extend" - 1) == 0) | |
1504 | { | |
1505 | s += sizeof "extend" - 1; | |
1506 | type = 'x'; | |
1507 | fieldlimit = 4; | |
1508 | } | |
5d6255fe | 1509 | else |
3b16e843 NC |
1510 | return; |
1511 | ||
1512 | if (ISDIGIT (*s)) | |
1513 | { | |
1514 | fieldnum = *s - '0'; | |
1515 | ++s; | |
1516 | } | |
1517 | if (fieldnum >= fieldlimit) | |
1518 | return; | |
1519 | ||
1520 | SKIP_WHITESPACE (); | |
1521 | if (*s != '(') | |
1522 | return; | |
1523 | ++s; | |
1524 | SKIP_WHITESPACE (); | |
1525 | ||
1526 | s = atof_ieee (s, type, floatbuf); | |
1527 | if (s == NULL) | |
1528 | return; | |
1529 | s = s; | |
1530 | ||
1531 | SKIP_WHITESPACE (); | |
1532 | if (*s != ')') | |
1533 | return; | |
1534 | ++s; | |
1535 | SKIP_WHITESPACE (); | |
1536 | ||
1537 | input_line_pointer = s; | |
5d6255fe | 1538 | expressionP->X_op = O_constant; |
3b16e843 NC |
1539 | expressionP->X_unsigned = 1; |
1540 | expressionP->X_add_number = ((floatbuf[fieldnum * 2] | |
1541 | << LITTLENUM_NUMBER_OF_BITS) | |
1542 | + floatbuf[fieldnum * 2 + 1]); | |
1543 | } | |
1544 | } | |
1545 | ||
1546 | /* Round up a section size to the appropriate boundary. */ | |
1547 | ||
1548 | valueT | |
1549 | md_section_align (segment, size) | |
1550 | segT segment ATTRIBUTE_UNUSED; | |
1551 | valueT size ATTRIBUTE_UNUSED; | |
1552 | { | |
1553 | return size; /* Byte alignment is fine. */ | |
1554 | } | |
1555 | ||
1556 | /* Exactly what point is a PC-relative offset relative TO? | |
1557 | On the 29000, they're relative to the address of the instruction, | |
1558 | which we have set up as the address of the fixup too. */ | |
1559 | ||
1560 | long | |
1561 | md_pcrel_from (fixP) | |
1562 | fixS *fixP; | |
1563 | { | |
1564 | return fixP->fx_where + fixP->fx_frag->fr_address; | |
1565 | } | |
1566 | ||
1567 | /* Generate a reloc for a fixup. */ | |
1568 | ||
1569 | #ifdef BFD_ASSEMBLER | |
1570 | arelent * | |
1571 | tc_gen_reloc (seg, fixp) | |
1572 | asection *seg ATTRIBUTE_UNUSED; | |
1573 | fixS *fixp; | |
1574 | { | |
1575 | arelent *reloc; | |
1576 | ||
1577 | reloc = (arelent *) xmalloc (sizeof (arelent)); | |
1578 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); | |
1579 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
1580 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
1581 | /* reloc->address = fixp->fx_frag->fr_address + fixp->fx_where + fixp->fx_addnumber;*/ | |
1582 | reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type); | |
1583 | ||
1584 | if (reloc->howto == (reloc_howto_type *) NULL) | |
1585 | { | |
1586 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
1587 | _("reloc %d not supported by object file format"), | |
1588 | (int) fixp->fx_r_type); | |
1589 | return NULL; | |
1590 | } | |
1591 | ||
a161fe53 AM |
1592 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) |
1593 | reloc->address = fixp->fx_offset; | |
3b16e843 | 1594 | |
a161fe53 | 1595 | reloc->addend = fixp->fx_addnumber; |
3b16e843 NC |
1596 | return reloc; |
1597 | } | |
1598 | #endif | |
1599 |