1 /* spu.c -- Assembler for the IBM Synergistic Processing Unit (SPU)
3 Copyright (C) 2006-2020 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
23 #include "safe-ctype.h"
25 #include "dwarf2dbg.h"
27 const struct spu_opcode spu_opcodes
[] = {
28 #define APUOP(TAG,MACFORMAT,OPCODE,MNEMONIC,ASMFORMAT,DEP,PIPE) \
29 { MACFORMAT, (OPCODE ## u) << (32-11), MNEMONIC, ASMFORMAT },
30 #define APUOPFB(TAG,MACFORMAT,OPCODE,FB,MNEMONIC,ASMFORMAT,DEP,PIPE) \
31 { MACFORMAT, ((OPCODE) << (32-11)) | ((FB) << (32-18)), MNEMONIC, ASMFORMAT },
32 #include "opcode/spu-insns.h"
37 static const int spu_num_opcodes
=
38 sizeof (spu_opcodes
) / sizeof (spu_opcodes
[0]);
45 expressionS exp
[MAX_RELOCS
];
46 int reloc_arg
[MAX_RELOCS
];
47 bfd_reloc_code_real_type reloc
[MAX_RELOCS
];
51 static const char *get_imm (const char *param
, struct spu_insn
*insn
, int arg
);
52 static const char *get_reg (const char *param
, struct spu_insn
*insn
, int arg
,
54 static int calcop (struct spu_opcode
*format
, const char *param
,
55 struct spu_insn
*insn
);
56 static void spu_brinfo (int);
57 static void spu_cons (int);
60 static htab_t op_hash
= NULL
;
62 /* These bits should be turned off in the first address of every segment */
65 /* These chars start a comment anywhere in a source file (except inside
67 const char comment_chars
[] = "#";
69 /* These chars only start a comment at the beginning of a line. */
70 const char line_comment_chars
[] = "#";
72 /* gods own line continuation char */
73 const char line_separator_chars
[] = ";";
75 /* Chars that can be used to separate mant from exp in floating point nums */
76 const char EXP_CHARS
[] = "eE";
78 /* Chars that mean this number is a floating point constant */
80 /* or 0H1.234E-12 (see exp chars above) */
81 const char FLT_CHARS
[] = "dDfF";
83 const pseudo_typeS md_pseudo_table
[] =
85 {"align", s_align_ptwo
, 4},
86 {"brinfo", spu_brinfo
, 0},
87 {"bss", s_lcomm_bytes
, 1},
89 {"dfloat", float_cons
, 'd'},
90 {"ffloat", float_cons
, 'f'},
91 {"global", s_globl
, 0},
94 {"long", spu_cons
, 4},
95 {"quad", spu_cons
, 8},
96 {"string", stringer
, 8 + 1},
97 {"word", spu_cons
, 4},
98 /* Force set to be treated as an instruction. */
101 /* Likewise for eqv. */
107 /* Bits plugged into branch instruction offset field. */
115 /* initialize hash table */
117 op_hash
= str_htab_create ();
119 /* loop until you see the end of the list */
121 for (i
= 0; i
< spu_num_opcodes
; i
++)
122 /* hash each mnemonic and record its position */
123 if (str_hash_find (op_hash
, spu_opcodes
[i
].mnemonic
) == NULL
)
124 str_hash_insert (op_hash
, spu_opcodes
[i
].mnemonic
,
125 (void *) &spu_opcodes
[i
]);
128 const char *md_shortopts
= "";
129 struct option md_longopts
[] = {
130 #define OPTION_APUASM (OPTION_MD_BASE)
131 {"apuasm", no_argument
, NULL
, OPTION_APUASM
},
132 #define OPTION_DD2 (OPTION_MD_BASE+1)
133 {"mdd2.0", no_argument
, NULL
, OPTION_DD2
},
134 #define OPTION_DD1 (OPTION_MD_BASE+2)
135 {"mdd1.0", no_argument
, NULL
, OPTION_DD1
},
136 #define OPTION_DD3 (OPTION_MD_BASE+3)
137 {"mdd3.0", no_argument
, NULL
, OPTION_DD3
},
138 { NULL
, no_argument
, NULL
, 0 }
140 size_t md_longopts_size
= sizeof (md_longopts
);
142 /* When set (by -apuasm) our assembler emulates the behaviour of apuasm.
143 * e.g. don't add bias to float conversion and don't right shift
144 * immediate values. */
145 static int emulate_apuasm
;
147 /* Use the dd2.0 instructions set. The only differences are some new
148 * register names and the orx insn */
149 static int use_dd2
= 1;
152 md_parse_option (int c
, const char *arg ATTRIBUTE_UNUSED
)
175 md_show_usage (FILE *stream
)
179 --apuasm emulate behaviour of apuasm\n"),
190 bfd_reloc_code_real_type reloc
;
193 static struct arg_encode arg_encode
[A_MAX
] = {
194 { 7, 0, 0, 0, 127, 0, -1, 0 }, /* A_T */
195 { 7, 7, 0, 0, 127, 0, -1, 0 }, /* A_A */
196 { 7, 14, 0, 0, 127, 0, -1, 0 }, /* A_B */
197 { 7, 21, 0, 0, 127, 0, -1, 0 }, /* A_C */
198 { 7, 7, 0, 0, 127, 0, -1, 0 }, /* A_S */
199 { 7, 7, 0, 0, 127, 0, -1, 0 }, /* A_H */
200 { 0, 0, 0, 0, -1, 0, -1, 0 }, /* A_P */
201 { 7, 14, 0, 0, -1, 0, -1, BFD_RELOC_SPU_IMM7
}, /* A_S3 */
202 { 7, 14, 0, -32, 31, -31, 0, BFD_RELOC_SPU_IMM7
}, /* A_S6 */
203 { 7, 14, 0, 0, -1, 0, -1, BFD_RELOC_SPU_IMM7
}, /* A_S7N */
204 { 7, 14, 0, -64, 63, -63, 0, BFD_RELOC_SPU_IMM7
}, /* A_S7 */
205 { 8, 14, 0, 0, 127, 0, -1, BFD_RELOC_SPU_IMM8
}, /* A_U7A */
206 { 8, 14, 0, 0, 127, 0, -1, BFD_RELOC_SPU_IMM8
}, /* A_U7B */
207 { 10, 14, 0, -512, 511, -128, 255, BFD_RELOC_SPU_IMM10
}, /* A_S10B */
208 { 10, 14, 0, -512, 511, 0, -1, BFD_RELOC_SPU_IMM10
}, /* A_S10 */
209 { 2, 23, 9, -1024, 1023, 0, -1, BFD_RELOC_SPU_PCREL9a
}, /* A_S11 */
210 { 2, 14, 9, -1024, 1023, 0, -1, BFD_RELOC_SPU_PCREL9b
}, /* A_S11I */
211 { 10, 14, 4, -8192, 8191, 0, -1, BFD_RELOC_SPU_IMM10W
}, /* A_S14 */
212 { 16, 7, 0, -32768, 32767, 0, -1, BFD_RELOC_SPU_IMM16
}, /* A_S16 */
213 { 16, 7, 2, -131072, 262143, 0, -1, BFD_RELOC_SPU_IMM16W
}, /* A_S18 */
214 { 16, 7, 2, -262144, 262143, 0, -1, BFD_RELOC_SPU_PCREL16
}, /* A_R18 */
215 { 7, 14, 0, 0, -1, 0, -1, BFD_RELOC_SPU_IMM7
}, /* A_U3 */
216 { 7, 14, 0, 0, 127, 0, 31, BFD_RELOC_SPU_IMM7
}, /* A_U5 */
217 { 7, 14, 0, 0, 127, 0, 63, BFD_RELOC_SPU_IMM7
}, /* A_U6 */
218 { 7, 14, 0, 0, -1, 0, -1, BFD_RELOC_SPU_IMM7
}, /* A_U7 */
219 { 14, 0, 0, 0, 16383, 0, -1, 0 }, /* A_U14 */
220 { 16, 7, 0, -32768, 65535, 0, -1, BFD_RELOC_SPU_IMM16
}, /* A_X16 */
221 { 18, 7, 0, 0, 262143, 0, -1, BFD_RELOC_SPU_IMM18
}, /* A_U18 */
224 /* Some flags for handling errors. This is very hackish and added after
226 static int syntax_error_arg
;
227 static const char *syntax_error_param
;
228 static int syntax_reg
;
231 insn_fmt_string (struct spu_opcode
*format
)
237 len
+= sprintf (&buf
[len
], "%s\t", format
->mnemonic
);
238 for (i
= 1; i
<= format
->arg
[0]; i
++)
240 int arg
= format
->arg
[i
];
242 if (i
> 1 && arg
!= A_P
&& format
->arg
[i
-1] != A_P
)
247 exp
= i
== syntax_error_arg
? "REG" : "reg";
249 exp
= i
== syntax_error_arg
? "IMM" : "imm";
250 len
+= sprintf (&buf
[len
], "%s", exp
);
251 if (i
> 1 && format
->arg
[i
-1] == A_P
)
259 md_assemble (char *op
)
261 char *param
, *thisfrag
;
263 struct spu_opcode
*format
;
264 struct spu_insn insn
;
269 /* skip over instruction to find parameters */
271 for (param
= op
; *param
!= 0 && !ISSPACE (*param
); param
++)
276 if (c
!= 0 && c
!= '\n')
279 /* try to find the instruction in the hash table */
281 if ((format
= (struct spu_opcode
*) str_hash_find (op_hash
, op
)) == NULL
)
283 as_bad (_("Invalid mnemonic '%s'"), op
);
287 if (!use_dd2
&& strcmp (format
->mnemonic
, "orx") == 0)
289 as_bad (_("'%s' is only available in DD2.0 or higher."), op
);
295 /* try parsing this instruction into insn */
296 for (i
= 0; i
< MAX_RELOCS
; i
++)
298 insn
.exp
[i
].X_add_symbol
= 0;
299 insn
.exp
[i
].X_op_symbol
= 0;
300 insn
.exp
[i
].X_add_number
= 0;
301 insn
.exp
[i
].X_op
= O_illegal
;
302 insn
.reloc_arg
[i
] = -1;
303 insn
.reloc
[i
] = BFD_RELOC_NONE
;
305 insn
.opcode
= format
->opcode
;
306 insn
.tag
= (enum spu_insns
) (format
- spu_opcodes
);
308 syntax_error_arg
= 0;
309 syntax_error_param
= 0;
311 if (calcop (format
, param
, &insn
))
314 /* if it doesn't parse try the next instruction */
315 if (!strcmp (format
[0].mnemonic
, format
[1].mnemonic
))
319 int parg
= format
[0].arg
[syntax_error_arg
-1];
321 as_fatal (_("Error in argument %d. Expecting: \"%s\""),
322 syntax_error_arg
- (parg
== A_P
),
323 insn_fmt_string (format
));
329 && ! (insn
.tag
== M_RDCH
330 || insn
.tag
== M_RCHCNT
331 || insn
.tag
== M_WRCH
))
332 as_warn (_("Mixing register syntax, with and without '$'."));
333 if (syntax_error_param
)
335 const char *d
= syntax_error_param
;
338 as_warn (_("Treating '%-*s' as a symbol."), (int)(syntax_error_param
- d
), d
);
342 && (insn
.tag
<= M_BRASL
343 || (insn
.tag
>= M_BRZ
&& insn
.tag
<= M_BRHNZ
))
344 && (insn
.opcode
& 0x7ff80) == 0
345 && (insn
.reloc_arg
[0] == A_R18
346 || insn
.reloc_arg
[0] == A_S18
347 || insn
.reloc_arg
[1] == A_R18
348 || insn
.reloc_arg
[1] == A_S18
))
349 insn
.opcode
|= brinfo
<< 7;
351 /* grow the current frag and plop in the opcode */
353 thisfrag
= frag_more (4);
354 md_number_to_chars (thisfrag
, insn
.opcode
, 4);
356 /* if this instruction requires labels mark it for later */
358 for (i
= 0; i
< MAX_RELOCS
; i
++)
359 if (insn
.reloc_arg
[i
] >= 0)
362 bfd_reloc_code_real_type reloc
= insn
.reloc
[i
];
365 if (reloc
== BFD_RELOC_SPU_PCREL9a
366 || reloc
== BFD_RELOC_SPU_PCREL9b
367 || reloc
== BFD_RELOC_SPU_PCREL16
)
369 fixP
= fix_new_exp (frag_now
,
370 thisfrag
- frag_now
->fr_literal
,
375 fixP
->tc_fix_data
.arg_format
= insn
.reloc_arg
[i
];
376 fixP
->tc_fix_data
.insn_tag
= insn
.tag
;
378 dwarf2_emit_insn (4);
380 /* .brinfo lasts exactly one instruction. */
385 calcop (struct spu_opcode
*format
, const char *param
, struct spu_insn
*insn
)
391 for (i
= 1; i
<= format
->arg
[0]; i
++)
393 arg
= format
->arg
[i
];
394 syntax_error_arg
= i
;
396 while (ISSPACE (*param
))
398 if (*param
== 0 || *param
== ',')
401 param
= get_reg (param
, insn
, arg
, 1);
403 param
= get_imm (param
, insn
, arg
);
414 while (ISSPACE (*param
))
417 if (arg
!= A_P
&& paren
)
423 else if (i
< format
->arg
[0]
424 && format
->arg
[i
] != A_P
425 && format
->arg
[i
+1] != A_P
)
434 while (ISSPACE (*param
))
436 return !paren
&& (*param
== 0 || *param
== '\n');
445 #define REG_NAME(NO,NM) { NO, sizeof (NM) - 1, NM }
447 static struct reg_name reg_name
[] = {
448 REG_NAME (0, "lr"), /* link register */
449 REG_NAME (1, "sp"), /* stack pointer */
450 REG_NAME (0, "rp"), /* link register */
451 REG_NAME (127, "fp"), /* frame pointer */
454 static struct reg_name sp_reg_name
[] = {
457 static struct reg_name ch_reg_name
[] = {
458 REG_NAME ( 0, "SPU_RdEventStat"),
459 REG_NAME ( 1, "SPU_WrEventMask"),
460 REG_NAME ( 2, "SPU_WrEventAck"),
461 REG_NAME ( 3, "SPU_RdSigNotify1"),
462 REG_NAME ( 4, "SPU_RdSigNotify2"),
463 REG_NAME ( 7, "SPU_WrDec"),
464 REG_NAME ( 8, "SPU_RdDec"),
465 REG_NAME ( 11, "SPU_RdEventMask"), /* DD2.0 only */
466 REG_NAME ( 13, "SPU_RdMachStat"),
467 REG_NAME ( 14, "SPU_WrSRR0"),
468 REG_NAME ( 15, "SPU_RdSRR0"),
469 REG_NAME ( 28, "SPU_WrOutMbox"),
470 REG_NAME ( 29, "SPU_RdInMbox"),
471 REG_NAME ( 30, "SPU_WrOutIntrMbox"),
472 REG_NAME ( 9, "MFC_WrMSSyncReq"),
473 REG_NAME ( 12, "MFC_RdTagMask"), /* DD2.0 only */
474 REG_NAME ( 16, "MFC_LSA"),
475 REG_NAME ( 17, "MFC_EAH"),
476 REG_NAME ( 18, "MFC_EAL"),
477 REG_NAME ( 19, "MFC_Size"),
478 REG_NAME ( 20, "MFC_TagID"),
479 REG_NAME ( 21, "MFC_Cmd"),
480 REG_NAME ( 22, "MFC_WrTagMask"),
481 REG_NAME ( 23, "MFC_WrTagUpdate"),
482 REG_NAME ( 24, "MFC_RdTagStat"),
483 REG_NAME ( 25, "MFC_RdListStallStat"),
484 REG_NAME ( 26, "MFC_WrListStallAck"),
485 REG_NAME ( 27, "MFC_RdAtomicStat"),
490 get_reg (const char *param
, struct spu_insn
*insn
, int arg
, int accept_expr
)
501 if (arg
== A_H
) /* Channel */
503 if ((param
[0] == 'c' || param
[0] == 'C')
504 && (param
[1] == 'h' || param
[1] == 'H')
505 && ISDIGIT (param
[2]))
508 else if (arg
== A_S
) /* Special purpose register */
510 if ((param
[0] == 's' || param
[0] == 'S')
511 && (param
[1] == 'p' || param
[1] == 'P')
512 && ISDIGIT (param
[2]))
516 if (ISDIGIT (*param
))
519 while (ISDIGIT (*param
))
520 regno
= regno
* 10 + *param
++ - '0';
525 unsigned int i
, n
, l
= 0;
527 if (arg
== A_H
) /* Channel */
530 n
= sizeof (ch_reg_name
) / sizeof (*ch_reg_name
);
532 else if (arg
== A_S
) /* Special purpose register */
535 n
= sizeof (sp_reg_name
) / sizeof (*sp_reg_name
);
540 n
= sizeof (reg_name
) / sizeof (*reg_name
);
543 for (i
= 0; i
< n
; i
++)
545 && 0 == strncasecmp (param
, rn
[i
].name
, rn
[i
].length
))
557 as_bad (_("'SPU_RdEventMask' (channel 11) is only available in DD2.0 or higher."));
558 else if (regno
== 12)
559 as_bad (_("'MFC_RdTagMask' (channel 12) is only available in DD2.0 or higher."));
564 insn
->opcode
|= regno
<< arg_encode
[arg
].pos
;
565 if ((!saw_prefix
&& syntax_reg
== 1)
566 || (saw_prefix
&& syntax_reg
== 2))
568 syntax_reg
|= saw_prefix
? 1 : 2;
576 save_ptr
= input_line_pointer
;
577 input_line_pointer
= (char *)param
;
579 param
= input_line_pointer
;
580 input_line_pointer
= save_ptr
;
581 if (ex
.X_op
== O_register
|| ex
.X_op
== O_constant
)
583 insn
->opcode
|= ex
.X_add_number
<< arg_encode
[arg
].pos
;
591 get_imm (const char *param
, struct spu_insn
*insn
, int arg
)
595 int low
= 0, high
= 0;
596 int reloc_i
= insn
->reloc_arg
[0] >= 0 ? 1 : 0;
598 if (strncasecmp (param
, "%lo(", 4) == 0)
602 as_warn (_("Using old style, %%lo(expr), please change to PPC style, expr@l."));
604 else if (strncasecmp (param
, "%hi(", 4) == 0)
608 as_warn (_("Using old style, %%hi(expr), please change to PPC style, expr@h."));
610 else if (strncasecmp (param
, "%pic(", 5) == 0)
612 /* Currently we expect %pic(expr) == expr, so do nothing here.
613 i.e. for code loaded at address 0 $toc will be 0. */
619 /* Symbols can start with $, but if this symbol matches a register
620 name, it's probably a mistake. The only way to avoid this
621 warning is to rename the symbol. */
622 struct spu_insn tmp_insn
;
623 const char *np
= get_reg (param
, &tmp_insn
, arg
, 0);
626 syntax_error_param
= np
;
629 save_ptr
= input_line_pointer
;
630 input_line_pointer
= (char *) param
;
631 expression (&insn
->exp
[reloc_i
]);
632 param
= input_line_pointer
;
633 input_line_pointer
= save_ptr
;
635 /* Similar to ppc_elf_suffix in tc-ppc.c. We have so few cases to
636 handle we do it inlined here. */
637 if (param
[0] == '@' && !ISALNUM (param
[2]) && param
[2] != '@')
639 if (param
[1] == 'h' || param
[1] == 'H')
644 else if (param
[1] == 'l' || param
[1] == 'L')
651 if (insn
->exp
[reloc_i
].X_op
== O_constant
)
653 val
= insn
->exp
[reloc_i
].X_add_number
;
657 /* Convert the value to a format we expect. */
658 val
<<= arg_encode
[arg
].rshift
;
661 else if (arg
== A_U7B
)
670 /* Warn about out of range expressions. */
672 int hi
= arg_encode
[arg
].hi
;
673 int lo
= arg_encode
[arg
].lo
;
674 int whi
= arg_encode
[arg
].whi
;
675 int wlo
= arg_encode
[arg
].wlo
;
677 if (hi
> lo
&& (val
< lo
|| val
> hi
))
678 as_fatal (_("Constant expression %d out of range, [%d, %d]."),
680 else if (whi
> wlo
&& (val
< wlo
|| val
> whi
))
681 as_warn (_("Constant expression %d out of range, [%d, %d]."),
687 else if (arg
== A_U7B
)
690 /* Branch hints have a split encoding. Do the bottom part. */
691 if (arg
== A_S11
|| arg
== A_S11I
)
692 insn
->opcode
|= ((val
>> 2) & 0x7f);
694 insn
->opcode
|= (((val
>> arg_encode
[arg
].rshift
)
695 & ((1 << arg_encode
[arg
].size
) - 1))
696 << arg_encode
[arg
].pos
);
700 insn
->reloc_arg
[reloc_i
] = arg
;
702 insn
->reloc
[reloc_i
] = BFD_RELOC_SPU_HI16
;
704 insn
->reloc
[reloc_i
] = BFD_RELOC_SPU_LO16
;
706 insn
->reloc
[reloc_i
] = arg_encode
[arg
].reloc
;
713 md_atof (int type
, char *litP
, int *sizeP
)
715 return ieee_md_atof (type
, litP
, sizeP
, TRUE
);
718 #ifndef WORKING_DOT_WORD
719 int md_short_jump_size
= 4;
722 md_create_short_jump (char *ptr
,
723 addressT from_addr ATTRIBUTE_UNUSED
,
724 addressT to_addr ATTRIBUTE_UNUSED
,
728 ptr
[0] = (char) 0xc0;
733 ptr
- frag
->fr_literal
,
738 BFD_RELOC_SPU_PCREL16
);
741 int md_long_jump_size
= 4;
744 md_create_long_jump (char *ptr
,
745 addressT from_addr ATTRIBUTE_UNUSED
,
746 addressT to_addr ATTRIBUTE_UNUSED
,
750 ptr
[0] = (char) 0xc0;
755 ptr
- frag
->fr_literal
,
760 BFD_RELOC_SPU_PCREL16
);
764 /* Handle .brinfo <priority>,<lrlive>. */
766 spu_brinfo (int ignore ATTRIBUTE_UNUSED
)
771 priority
= get_absolute_expression ();
775 if (*input_line_pointer
== ',')
777 ++input_line_pointer
;
778 lrlive
= get_absolute_expression ();
781 if (priority
> 0x1fff)
783 as_bad (_("invalid priority '%lu'"), (unsigned long) priority
);
789 as_bad (_("invalid lrlive '%lu'"), (unsigned long) lrlive
);
793 brinfo
= (lrlive
<< 13) | priority
;
794 demand_empty_rest_of_line ();
797 /* Support @ppu on symbols referenced in .int/.long/.word/.quad. */
799 spu_cons (int nbytes
)
803 if (is_it_end_of_statement ())
805 demand_empty_rest_of_line ();
811 char *save
= input_line_pointer
;
813 /* Use deferred_expression here so that an expression involving
814 a symbol that happens to be defined already as an spu symbol,
816 deferred_expression (&exp
);
817 if ((exp
.X_op
== O_symbol
818 || exp
.X_op
== O_constant
)
819 && strncasecmp (input_line_pointer
, "@ppu", 4) == 0)
821 char *p
= frag_more (nbytes
);
822 enum bfd_reloc_code_real reloc
;
824 /* Check for identifier@suffix+constant. */
825 input_line_pointer
+= 4;
826 if (*input_line_pointer
== '-' || *input_line_pointer
== '+')
830 save
= input_line_pointer
;
831 expression (&new_exp
);
832 if (new_exp
.X_op
== O_constant
)
833 exp
.X_add_number
+= new_exp
.X_add_number
;
835 input_line_pointer
= save
;
838 reloc
= nbytes
== 4 ? BFD_RELOC_SPU_PPU32
: BFD_RELOC_SPU_PPU64
;
839 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
, nbytes
,
844 /* Don't use deferred_expression for anything else.
845 deferred_expression won't evaulate dot at the point it is
847 input_line_pointer
= save
;
849 emit_expr (&exp
, nbytes
);
852 while (*input_line_pointer
++ == ',');
854 /* Put terminator back into stream. */
855 input_line_pointer
--;
856 demand_empty_rest_of_line ();
860 md_estimate_size_before_relax (fragS
*fragP ATTRIBUTE_UNUSED
,
861 segT segment_type ATTRIBUTE_UNUSED
)
863 as_fatal (_("Relaxation should never occur"));
867 /* If while processing a fixup, a reloc really needs to be created,
868 then it is done here. */
871 tc_gen_reloc (asection
*seg ATTRIBUTE_UNUSED
, fixS
*fixp
)
874 reloc
= XNEW (arelent
);
875 reloc
->sym_ptr_ptr
= XNEW (asymbol
*);
877 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
878 else if (fixp
->fx_subsy
)
879 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_subsy
);
882 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
883 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
884 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
886 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
887 _("reloc %d not supported by object file format"),
888 (int) fixp
->fx_r_type
);
891 reloc
->addend
= fixp
->fx_addnumber
;
895 /* Round up a section's size to the appropriate boundary. */
898 md_section_align (segT seg
, valueT size
)
900 int align
= bfd_section_alignment (seg
);
901 valueT mask
= ((valueT
) 1 << align
) - 1;
903 return (size
+ mask
) & ~mask
;
906 /* Where a PC relative offset is calculated from. On the spu they
907 are calculated from the beginning of the branch instruction. */
910 md_pcrel_from (fixS
*fixp
)
912 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
915 /* Fill in rs_align_code fragments. */
918 spu_handle_align (fragS
*fragp
)
920 static const unsigned char nop_pattern
[8] = {
921 0x40, 0x20, 0x00, 0x00, /* even nop */
922 0x00, 0x20, 0x00, 0x00, /* odd nop */
928 if (fragp
->fr_type
!= rs_align_code
)
931 bytes
= fragp
->fr_next
->fr_address
- fragp
->fr_address
- fragp
->fr_fix
;
932 p
= fragp
->fr_literal
+ fragp
->fr_fix
;
940 fragp
->fr_fix
+= fix
;
944 memcpy (p
, &nop_pattern
[4], 4);
950 memcpy (p
, nop_pattern
, 8);
955 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
960 char *place
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
962 if (fixP
->fx_subsy
!= (symbolS
*) NULL
)
964 /* We can't actually support subtracting a symbol. */
965 as_bad_where (fixP
->fx_file
, fixP
->fx_line
, _("expression too complex"));
968 if (fixP
->fx_addsy
!= NULL
)
972 /* Hack around bfd_install_relocation brain damage. */
973 val
+= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
975 switch (fixP
->fx_r_type
)
978 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
981 case BFD_RELOC_SPU_PCREL16
:
982 case BFD_RELOC_SPU_PCREL9a
:
983 case BFD_RELOC_SPU_PCREL9b
:
984 case BFD_RELOC_32_PCREL
:
988 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
989 _("expression too complex"));
995 fixP
->fx_addnumber
= val
;
997 if (fixP
->fx_r_type
== BFD_RELOC_SPU_PPU32
998 || fixP
->fx_r_type
== BFD_RELOC_SPU_PPU64
999 || fixP
->fx_r_type
== BFD_RELOC_SPU_ADD_PIC
)
1002 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
1007 if (fixP
->tc_fix_data
.arg_format
> A_P
)
1009 int hi
= arg_encode
[fixP
->tc_fix_data
.arg_format
].hi
;
1010 int lo
= arg_encode
[fixP
->tc_fix_data
.arg_format
].lo
;
1011 if (hi
> lo
&& ((offsetT
) val
< lo
|| (offsetT
) val
> hi
))
1012 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1013 _("Relocation doesn't fit. (relocation value = 0x%lx)"),
1017 switch (fixP
->fx_r_type
)
1020 md_number_to_chars (place
, val
, 1);
1024 md_number_to_chars (place
, val
, 2);
1028 case BFD_RELOC_32_PCREL
:
1029 md_number_to_chars (place
, val
, 4);
1033 md_number_to_chars (place
, val
, 8);
1036 case BFD_RELOC_SPU_IMM7
:
1041 case BFD_RELOC_SPU_IMM8
:
1046 case BFD_RELOC_SPU_IMM10
:
1051 case BFD_RELOC_SPU_IMM10W
:
1053 mask
= 0x3ff0 << 10;
1056 case BFD_RELOC_SPU_IMM16
:
1061 case BFD_RELOC_SPU_IMM16W
:
1063 mask
= 0x3fffc << 5;
1066 case BFD_RELOC_SPU_IMM18
:
1068 mask
= 0x3ffff << 7;
1071 case BFD_RELOC_SPU_PCREL9a
:
1072 res
= ((val
& 0x1fc) >> 2) | ((val
& 0x600) << 14);
1073 mask
= (0x1fc >> 2) | (0x600 << 14);
1076 case BFD_RELOC_SPU_PCREL9b
:
1077 res
= ((val
& 0x1fc) >> 2) | ((val
& 0x600) << 5);
1078 mask
= (0x1fc >> 2) | (0x600 << 5);
1081 case BFD_RELOC_SPU_PCREL16
:
1083 mask
= 0x3fffc << 5;
1086 case BFD_RELOC_SPU_HI16
:
1091 case BFD_RELOC_SPU_LO16
:
1097 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1098 _("reloc %d not supported by object file format"),
1099 (int) fixP
->fx_r_type
);
1103 place
[0] = (place
[0] & (~mask
>> 24)) | ((res
>> 24) & 0xff);
1104 place
[1] = (place
[1] & (~mask
>> 16)) | ((res
>> 16) & 0xff);
1105 place
[2] = (place
[2] & (~mask
>> 8)) | ((res
>> 8) & 0xff);
1106 place
[3] = (place
[3] & ~mask
) | (res
& 0xff);