* config/tc-ppc.c (md_apply_fix3): Give a useful error message
[deliverable/binutils-gdb.git] / gas / config / tc-ppc.c
1 /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2 Copyright (C) 1994, 1995, 1996 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, Cygnus Support.
4
5 This file is part of GAS, the GNU Assembler.
6
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 2, or (at your option)
10 any later version.
11
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.
16
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
19 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21 #include <stdio.h>
22 #include <ctype.h>
23 #include "as.h"
24 #include "subsegs.h"
25
26 #include "opcode/ppc.h"
27
28 #ifdef OBJ_ELF
29 #include "elf/ppc.h"
30 #endif
31
32 #ifdef TE_PE
33 #include "coff/pe.h"
34 #endif
35
36 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
37
38 /* Tell the main code what the endianness is. */
39 extern int target_big_endian;
40
41 /* Whether or not, we've set target_big_endian. */
42 static int set_target_endian = 0;
43
44 /* Whether to use user friendly register names. */
45 #ifndef TARGET_REG_NAMES_P
46 #ifdef TE_PE
47 #define TARGET_REG_NAMES_P true
48 #else
49 #define TARGET_REG_NAMES_P false
50 #endif
51 #endif
52
53 static boolean reg_names_p = TARGET_REG_NAMES_P;
54
55 static void ppc_set_cpu PARAMS ((void));
56 static unsigned long ppc_insert_operand
57 PARAMS ((unsigned long insn, const struct powerpc_operand *operand,
58 offsetT val, char *file, unsigned int line));
59 static void ppc_macro PARAMS ((char *str, const struct powerpc_macro *macro));
60 static void ppc_byte PARAMS ((int));
61 static int ppc_is_toc_sym PARAMS ((symbolS *sym));
62 static void ppc_tc PARAMS ((int));
63
64 #ifdef OBJ_XCOFF
65 static void ppc_comm PARAMS ((int));
66 static void ppc_bb PARAMS ((int));
67 static void ppc_bc PARAMS ((int));
68 static void ppc_bf PARAMS ((int));
69 static void ppc_biei PARAMS ((int));
70 static void ppc_bs PARAMS ((int));
71 static void ppc_eb PARAMS ((int));
72 static void ppc_ec PARAMS ((int));
73 static void ppc_ef PARAMS ((int));
74 static void ppc_es PARAMS ((int));
75 static void ppc_csect PARAMS ((int));
76 static void ppc_change_csect PARAMS ((symbolS *));
77 static void ppc_function PARAMS ((int));
78 static void ppc_extern PARAMS ((int));
79 static void ppc_lglobl PARAMS ((int));
80 static void ppc_section PARAMS ((int));
81 static void ppc_stabx PARAMS ((int));
82 static void ppc_rename PARAMS ((int));
83 static void ppc_toc PARAMS ((int));
84 #endif
85
86 #ifdef OBJ_ELF
87 static bfd_reloc_code_real_type ppc_elf_suffix PARAMS ((char **));
88 static void ppc_elf_cons PARAMS ((int));
89 static void ppc_elf_rdata PARAMS ((int));
90 static void ppc_elf_lcomm PARAMS ((int));
91 static void ppc_elf_validate_fix PARAMS ((fixS *, segT));
92 #endif
93
94 #ifdef TE_PE
95 static void ppc_set_current_section PARAMS ((segT));
96 static void ppc_previous PARAMS ((int));
97 static void ppc_pdata PARAMS ((int));
98 static void ppc_ydata PARAMS ((int));
99 static void ppc_reldata PARAMS ((int));
100 static void ppc_rdata PARAMS ((int));
101 static void ppc_ualong PARAMS ((int));
102 static void ppc_znop PARAMS ((int));
103 static void ppc_pe_comm PARAMS ((int));
104 static void ppc_pe_section PARAMS ((int));
105 static void ppc_pe_function PARAMS ((int));
106 static void ppc_pe_tocd PARAMS ((int));
107 #endif
108 \f
109 /* Generic assembler global variables which must be defined by all
110 targets. */
111
112 /* Characters which always start a comment. */
113 #ifdef TARGET_SOLARIS_COMMENT
114 const char comment_chars[] = "#!";
115 #else
116 const char comment_chars[] = "#";
117 #endif
118
119 /* Characters which start a comment at the beginning of a line. */
120 const char line_comment_chars[] = "#";
121
122 /* Characters which may be used to separate multiple commands on a
123 single line. */
124 const char line_separator_chars[] = ";";
125
126 /* Characters which are used to indicate an exponent in a floating
127 point number. */
128 const char EXP_CHARS[] = "eE";
129
130 /* Characters which mean that a number is a floating point constant,
131 as in 0d1.0. */
132 const char FLT_CHARS[] = "dD";
133 \f
134 /* The target specific pseudo-ops which we support. */
135
136 const pseudo_typeS md_pseudo_table[] =
137 {
138 /* Pseudo-ops which must be overridden. */
139 { "byte", ppc_byte, 0 },
140
141 #ifdef OBJ_XCOFF
142 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
143 legitimately belong in the obj-*.c file. However, XCOFF is based
144 on COFF, and is only implemented for the RS/6000. We just use
145 obj-coff.c, and add what we need here. */
146 { "comm", ppc_comm, 0 },
147 { "lcomm", ppc_comm, 1 },
148 { "bb", ppc_bb, 0 },
149 { "bc", ppc_bc, 0 },
150 { "bf", ppc_bf, 0 },
151 { "bi", ppc_biei, 0 },
152 { "bs", ppc_bs, 0 },
153 { "csect", ppc_csect, 0 },
154 { "data", ppc_section, 'd' },
155 { "eb", ppc_eb, 0 },
156 { "ec", ppc_ec, 0 },
157 { "ef", ppc_ef, 0 },
158 { "ei", ppc_biei, 1 },
159 { "es", ppc_es, 0 },
160 { "extern", ppc_extern, 0 },
161 { "function", ppc_function, 0 },
162 { "lglobl", ppc_lglobl, 0 },
163 { "rename", ppc_rename, 0 },
164 { "stabx", ppc_stabx, 0 },
165 { "text", ppc_section, 't' },
166 { "toc", ppc_toc, 0 },
167 #endif
168
169 #ifdef OBJ_ELF
170 { "long", ppc_elf_cons, 4 },
171 { "word", ppc_elf_cons, 2 },
172 { "short", ppc_elf_cons, 2 },
173 { "rdata", ppc_elf_rdata, 0 },
174 { "rodata", ppc_elf_rdata, 0 },
175 { "lcomm", ppc_elf_lcomm, 0 },
176 #endif
177
178 #ifdef TE_PE
179 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
180 { "previous", ppc_previous, 0 },
181 { "pdata", ppc_pdata, 0 },
182 { "ydata", ppc_ydata, 0 },
183 { "reldata", ppc_reldata, 0 },
184 { "rdata", ppc_rdata, 0 },
185 { "ualong", ppc_ualong, 0 },
186 { "znop", ppc_znop, 0 },
187 { "comm", ppc_pe_comm, 0 },
188 { "lcomm", ppc_pe_comm, 1 },
189 { "section", ppc_pe_section, 0 },
190 { "function", ppc_pe_function,0 },
191 { "tocd", ppc_pe_tocd, 0 },
192 #endif
193
194 /* This pseudo-op is used even when not generating XCOFF output. */
195 { "tc", ppc_tc, 0 },
196
197 { NULL, NULL, 0 }
198 };
199
200 \f
201 /* Predefined register names if -mregnames (or default for Windows NT). */
202 /* In general, there are lots of them, in an attempt to be compatible */
203 /* with a number of other Windows NT assemblers. */
204
205 /* Structure to hold information about predefined registers. */
206 struct pd_reg
207 {
208 char *name;
209 int value;
210 };
211
212 /* List of registers that are pre-defined:
213
214 Each general register has predefined names of the form:
215 1. r<reg_num> which has the value <reg_num>.
216 2. r.<reg_num> which has the value <reg_num>.
217
218
219 Each floating point register has predefined names of the form:
220 1. f<reg_num> which has the value <reg_num>.
221 2. f.<reg_num> which has the value <reg_num>.
222
223 Each condition register has predefined names of the form:
224 1. cr<reg_num> which has the value <reg_num>.
225 2. cr.<reg_num> which has the value <reg_num>.
226
227 There are individual registers as well:
228 sp or r.sp has the value 1
229 rtoc or r.toc has the value 2
230 fpscr has the value 0
231 xer has the value 1
232 lr has the value 8
233 ctr has the value 9
234 pmr has the value 0
235 dar has the value 19
236 dsisr has the value 18
237 dec has the value 22
238 sdr1 has the value 25
239 srr0 has the value 26
240 srr1 has the value 27
241
242 The table is sorted. Suitable for searching by a binary search. */
243
244 static const struct pd_reg pre_defined_registers[] =
245 {
246 { "cr.0", 0 }, /* Condition Registers */
247 { "cr.1", 1 },
248 { "cr.2", 2 },
249 { "cr.3", 3 },
250 { "cr.4", 4 },
251 { "cr.5", 5 },
252 { "cr.6", 6 },
253 { "cr.7", 7 },
254
255 { "cr0", 0 },
256 { "cr1", 1 },
257 { "cr2", 2 },
258 { "cr3", 3 },
259 { "cr4", 4 },
260 { "cr5", 5 },
261 { "cr6", 6 },
262 { "cr7", 7 },
263
264 { "ctr", 9 },
265
266 { "dar", 19 }, /* Data Access Register */
267 { "dec", 22 }, /* Decrementer */
268 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
269
270 { "f.0", 0 }, /* Floating point registers */
271 { "f.1", 1 },
272 { "f.10", 10 },
273 { "f.11", 11 },
274 { "f.12", 12 },
275 { "f.13", 13 },
276 { "f.14", 14 },
277 { "f.15", 15 },
278 { "f.16", 16 },
279 { "f.17", 17 },
280 { "f.18", 18 },
281 { "f.19", 19 },
282 { "f.2", 2 },
283 { "f.20", 20 },
284 { "f.21", 21 },
285 { "f.22", 22 },
286 { "f.23", 23 },
287 { "f.24", 24 },
288 { "f.25", 25 },
289 { "f.26", 26 },
290 { "f.27", 27 },
291 { "f.28", 28 },
292 { "f.29", 29 },
293 { "f.3", 3 },
294 { "f.30", 30 },
295 { "f.31", 31 },
296 { "f.4", 4 },
297 { "f.5", 5 },
298 { "f.6", 6 },
299 { "f.7", 7 },
300 { "f.8", 8 },
301 { "f.9", 9 },
302
303 { "f0", 0 },
304 { "f1", 1 },
305 { "f10", 10 },
306 { "f11", 11 },
307 { "f12", 12 },
308 { "f13", 13 },
309 { "f14", 14 },
310 { "f15", 15 },
311 { "f16", 16 },
312 { "f17", 17 },
313 { "f18", 18 },
314 { "f19", 19 },
315 { "f2", 2 },
316 { "f20", 20 },
317 { "f21", 21 },
318 { "f22", 22 },
319 { "f23", 23 },
320 { "f24", 24 },
321 { "f25", 25 },
322 { "f26", 26 },
323 { "f27", 27 },
324 { "f28", 28 },
325 { "f29", 29 },
326 { "f3", 3 },
327 { "f30", 30 },
328 { "f31", 31 },
329 { "f4", 4 },
330 { "f5", 5 },
331 { "f6", 6 },
332 { "f7", 7 },
333 { "f8", 8 },
334 { "f9", 9 },
335
336 { "fpscr", 0 },
337
338 { "lr", 8 }, /* Link Register */
339
340 { "pmr", 0 },
341
342 { "r.0", 0 }, /* General Purpose Registers */
343 { "r.1", 1 },
344 { "r.10", 10 },
345 { "r.11", 11 },
346 { "r.12", 12 },
347 { "r.13", 13 },
348 { "r.14", 14 },
349 { "r.15", 15 },
350 { "r.16", 16 },
351 { "r.17", 17 },
352 { "r.18", 18 },
353 { "r.19", 19 },
354 { "r.2", 2 },
355 { "r.20", 20 },
356 { "r.21", 21 },
357 { "r.22", 22 },
358 { "r.23", 23 },
359 { "r.24", 24 },
360 { "r.25", 25 },
361 { "r.26", 26 },
362 { "r.27", 27 },
363 { "r.28", 28 },
364 { "r.29", 29 },
365 { "r.3", 3 },
366 { "r.30", 30 },
367 { "r.31", 31 },
368 { "r.4", 4 },
369 { "r.5", 5 },
370 { "r.6", 6 },
371 { "r.7", 7 },
372 { "r.8", 8 },
373 { "r.9", 9 },
374
375 { "r.sp", 1 }, /* Stack Pointer */
376
377 { "r.toc", 2 }, /* Pointer to the table of contents */
378
379 { "r0", 0 }, /* More general purpose registers */
380 { "r1", 1 },
381 { "r10", 10 },
382 { "r11", 11 },
383 { "r12", 12 },
384 { "r13", 13 },
385 { "r14", 14 },
386 { "r15", 15 },
387 { "r16", 16 },
388 { "r17", 17 },
389 { "r18", 18 },
390 { "r19", 19 },
391 { "r2", 2 },
392 { "r20", 20 },
393 { "r21", 21 },
394 { "r22", 22 },
395 { "r23", 23 },
396 { "r24", 24 },
397 { "r25", 25 },
398 { "r26", 26 },
399 { "r27", 27 },
400 { "r28", 28 },
401 { "r29", 29 },
402 { "r3", 3 },
403 { "r30", 30 },
404 { "r31", 31 },
405 { "r4", 4 },
406 { "r5", 5 },
407 { "r6", 6 },
408 { "r7", 7 },
409 { "r8", 8 },
410 { "r9", 9 },
411
412 { "rtoc", 2 }, /* Table of contents */
413
414 { "sdr1", 25 }, /* Storage Description Register 1 */
415
416 { "sp", 1 },
417
418 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
419 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
420
421 { "xer", 1 },
422
423 };
424
425 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
426
427 /* Given NAME, find the register number associated with that name, return
428 the integer value associated with the given name or -1 on failure. */
429
430 static int reg_name_search PARAMS ( (char * name) );
431
432 static int
433 reg_name_search (name)
434 char *name;
435 {
436 int middle, low, high;
437 int cmp;
438
439 low = 0;
440 high = REG_NAME_CNT - 1;
441
442 do
443 {
444 middle = (low + high) / 2;
445 cmp = strcasecmp (name, pre_defined_registers[middle].name);
446 if (cmp < 0)
447 high = middle - 1;
448 else if (cmp > 0)
449 low = middle + 1;
450 else
451 return pre_defined_registers[middle].value;
452 }
453 while (low <= high);
454
455 return -1;
456 }
457
458 /*
459 * Summary of register_name().
460 *
461 * in: Input_line_pointer points to 1st char of operand.
462 *
463 * out: A expressionS.
464 * The operand may have been a register: in this case, X_op == O_register,
465 * X_add_number is set to the register number, and truth is returned.
466 * Input_line_pointer->(next non-blank) char after operand, or is in its
467 * original state.
468 */
469
470 static boolean
471 register_name (expressionP)
472 expressionS *expressionP;
473 {
474 int reg_number;
475 char *name;
476 char *start;
477 char c;
478
479 /* Find the spelling of the operand */
480 start = name = input_line_pointer;
481 if (name[0] == '%' && isalpha (name[1]))
482 name = ++input_line_pointer;
483
484 else if (!reg_names_p || !isalpha (name[0]))
485 return false;
486
487 c = get_symbol_end ();
488 reg_number = reg_name_search (name);
489
490 /* look to see if it's in the register table */
491 if (reg_number >= 0)
492 {
493 expressionP->X_op = O_register;
494 expressionP->X_add_number = reg_number;
495
496 /* make the rest nice */
497 expressionP->X_add_symbol = NULL;
498 expressionP->X_op_symbol = NULL;
499 *input_line_pointer = c; /* put back the delimiting char */
500 return true;
501 }
502 else
503 {
504 /* reset the line as if we had not done anything */
505 *input_line_pointer = c; /* put back the delimiting char */
506 input_line_pointer = start; /* reset input_line pointer */
507 return false;
508 }
509 }
510
511 \f
512 /* Local variables. */
513
514 /* The type of processor we are assembling for. This is one or more
515 of the PPC_OPCODE flags defined in opcode/ppc.h. */
516 static int ppc_cpu = 0;
517
518 /* The size of the processor we are assembling for. This is either
519 PPC_OPCODE_32 or PPC_OPCODE_64. */
520 static int ppc_size = PPC_OPCODE_32;
521
522 /* Opcode hash table. */
523 static struct hash_control *ppc_hash;
524
525 /* Macro hash table. */
526 static struct hash_control *ppc_macro_hash;
527
528 #ifdef OBJ_ELF
529 /* Whether to warn about non PC relative relocations that aren't
530 in the .got2 section. */
531 static boolean mrelocatable = false;
532
533 /* Flags to set in the elf header */
534 static flagword ppc_flags = 0;
535 #endif
536
537 #ifdef OBJ_XCOFF
538
539 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
540 using a bunch of different sections. These assembler sections,
541 however, are all encompassed within the .text or .data sections of
542 the final output file. We handle this by using different
543 subsegments within these main segments. */
544
545 /* Next subsegment to allocate within the .text segment. */
546 static subsegT ppc_text_subsegment = 2;
547
548 /* Linked list of csects in the text section. */
549 static symbolS *ppc_text_csects;
550
551 /* Next subsegment to allocate within the .data segment. */
552 static subsegT ppc_data_subsegment = 2;
553
554 /* Linked list of csects in the data section. */
555 static symbolS *ppc_data_csects;
556
557 /* The current csect. */
558 static symbolS *ppc_current_csect;
559
560 /* The RS/6000 assembler uses a TOC which holds addresses of functions
561 and variables. Symbols are put in the TOC with the .tc pseudo-op.
562 A special relocation is used when accessing TOC entries. We handle
563 the TOC as a subsegment within the .data segment. We set it up if
564 we see a .toc pseudo-op, and save the csect symbol here. */
565 static symbolS *ppc_toc_csect;
566
567 /* The first frag in the TOC subsegment. */
568 static fragS *ppc_toc_frag;
569
570 /* The first frag in the first subsegment after the TOC in the .data
571 segment. NULL if there are no subsegments after the TOC. */
572 static fragS *ppc_after_toc_frag;
573
574 /* The current static block. */
575 static symbolS *ppc_current_block;
576
577 /* The COFF debugging section; set by md_begin. This is not the
578 .debug section, but is instead the secret BFD section which will
579 cause BFD to set the section number of a symbol to N_DEBUG. */
580 static asection *ppc_coff_debug_section;
581
582 #endif /* OBJ_XCOFF */
583
584 #ifdef TE_PE
585
586 /* Various sections that we need for PE coff support. */
587 static segT ydata_section;
588 static segT pdata_section;
589 static segT reldata_section;
590 static segT rdata_section;
591 static segT tocdata_section;
592
593 /* The current section and the previous section. See ppc_previous. */
594 static segT ppc_previous_section;
595 static segT ppc_current_section;
596
597 #endif /* TE_PE */
598
599 #ifdef OBJ_ELF
600 symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
601 #endif /* OBJ_ELF */
602
603 #ifndef WORKING_DOT_WORD
604 const int md_short_jump_size = 4;
605 const int md_long_jump_size = 4;
606 #endif
607 \f
608 #ifdef OBJ_ELF
609 CONST char *md_shortopts = "b:l:usm:VQ:";
610 #else
611 CONST char *md_shortopts = "um:";
612 #endif
613 struct option md_longopts[] = {
614 {NULL, no_argument, NULL, 0}
615 };
616 size_t md_longopts_size = sizeof(md_longopts);
617
618 int
619 md_parse_option (c, arg)
620 int c;
621 char *arg;
622 {
623 switch (c)
624 {
625 case 'u':
626 /* -u means that any undefined symbols should be treated as
627 external, which is the default for gas anyhow. */
628 break;
629
630 #ifdef OBJ_ELF
631 case 'l':
632 /* Solaris as takes -le (presumably for little endian). For completeness
633 sake, recognize -be also. */
634 if (strcmp (arg, "e") == 0)
635 {
636 target_big_endian = 0;
637 set_target_endian = 1;
638 }
639 else
640 return 0;
641
642 break;
643
644 case 'b':
645 if (strcmp (arg, "e") == 0)
646 {
647 target_big_endian = 1;
648 set_target_endian = 1;
649 }
650 else
651 return 0;
652
653 break;
654 #endif
655
656 case 'm':
657 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
658 (RIOS2). */
659 if (strcmp (arg, "pwrx") == 0 || strcmp (arg, "pwr2") == 0)
660 ppc_cpu = PPC_OPCODE_POWER | PPC_OPCODE_POWER2;
661 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
662 else if (strcmp (arg, "pwr") == 0)
663 ppc_cpu = PPC_OPCODE_POWER;
664 /* -m601 means to assemble for the Motorola PowerPC 601, which includes
665 instructions that are holdovers from the Power. */
666 else if (strcmp (arg, "601") == 0)
667 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_601;
668 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
669 Motorola PowerPC 603/604. */
670 else if (strcmp (arg, "ppc") == 0
671 || strcmp (arg, "ppc32") == 0
672 || strcmp (arg, "403") == 0
673 || strcmp (arg, "603") == 0
674 || strcmp (arg, "604") == 0)
675 ppc_cpu = PPC_OPCODE_PPC;
676 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
677 620. */
678 else if (strcmp (arg, "ppc64") == 0 || strcmp (arg, "620") == 0)
679 {
680 ppc_cpu = PPC_OPCODE_PPC;
681 ppc_size = PPC_OPCODE_64;
682 }
683 /* -mcom means assemble for the common intersection between Power
684 and PowerPC. At present, we just allow the union, rather
685 than the intersection. */
686 else if (strcmp (arg, "com") == 0)
687 ppc_cpu = PPC_OPCODE_COMMON;
688 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
689 else if (strcmp (arg, "any") == 0)
690 ppc_cpu = PPC_OPCODE_ANY;
691
692 else if (strcmp (arg, "regnames") == 0)
693 reg_names_p = true;
694
695 else if (strcmp (arg, "no-regnames") == 0)
696 reg_names_p = false;
697
698 #ifdef OBJ_ELF
699 /* -mrelocatable/-mrelocatable-lib -- warn about initializations that require relocation */
700 else if (strcmp (arg, "relocatable") == 0)
701 {
702 mrelocatable = true;
703 ppc_flags |= EF_PPC_RELOCATABLE;
704 }
705
706 else if (strcmp (arg, "relocatable-lib") == 0)
707 {
708 mrelocatable = true;
709 ppc_flags |= EF_PPC_RELOCATABLE_LIB;
710 }
711
712 /* -memb, set embedded bit */
713 else if (strcmp (arg, "emb") == 0)
714 ppc_flags |= EF_PPC_EMB;
715
716 /* -mlittle/-mbig set the endianess */
717 else if (strcmp (arg, "little") == 0 || strcmp (arg, "little-endian") == 0)
718 {
719 target_big_endian = 0;
720 set_target_endian = 1;
721 }
722
723 else if (strcmp (arg, "big") == 0 || strcmp (arg, "big-endian") == 0)
724 {
725 target_big_endian = 1;
726 set_target_endian = 1;
727 }
728 #endif
729 else
730 {
731 as_bad ("invalid switch -m%s", arg);
732 return 0;
733 }
734 break;
735
736 #ifdef OBJ_ELF
737 /* -V: SVR4 argument to print version ID. */
738 case 'V':
739 print_version_id ();
740 break;
741
742 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
743 should be emitted or not. FIXME: Not implemented. */
744 case 'Q':
745 break;
746
747 /* Solaris takes -s to specify that .stabs go in a .stabs section,
748 rather than .stabs.excl, which is ignored by the linker.
749 FIXME: Not implemented. */
750 case 's':
751 if (arg)
752 return 0;
753
754 break;
755 #endif
756
757 default:
758 return 0;
759 }
760
761 return 1;
762 }
763
764 void
765 md_show_usage (stream)
766 FILE *stream;
767 {
768 fprintf(stream, "\
769 PowerPC options:\n\
770 -u ignored\n\
771 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
772 -mpwr generate code for IBM POWER (RIOS1)\n\
773 -m601 generate code for Motorola PowerPC 601\n\
774 -mppc, -mppc32, -m403, -m603, -m604\n\
775 generate code for Motorola PowerPC 603/604\n\
776 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
777 -mcom generate code Power/PowerPC common instructions\n\
778 -many generate code for any architecture (PWR/PWRX/PPC)\n\
779 -mregnames Allow symbolic names for registers\n\
780 -mno-regnames Do not allow symbolic names for registers\n");
781 #ifdef OBJ_ELF
782 fprintf(stream, "\
783 -mrelocatable support for GCC's -mrelocatble option\n\
784 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
785 -memb set PPC_EMB bit in ELF flags\n\
786 -mlittle, -mlittle-endian\n\
787 generate code for a little endian machine\n\
788 -mbig, -mbig-endian generate code for a big endian machine\n\
789 -V print assembler version number\n\
790 -Qy, -Qn ignored\n");
791 #endif
792 }
793 \f
794 /* Set ppc_cpu if it is not already set. */
795
796 static void
797 ppc_set_cpu ()
798 {
799 const char *default_os = TARGET_OS;
800 const char *default_cpu = TARGET_CPU;
801
802 if (ppc_cpu == 0)
803 {
804 if (strncmp (default_os, "aix", 3) == 0
805 && default_os[3] >= '4' && default_os[3] <= '9')
806 ppc_cpu = PPC_OPCODE_COMMON;
807 else if (strncmp (default_os, "aix3", 4) == 0)
808 ppc_cpu = PPC_OPCODE_POWER;
809 else if (strcmp (default_cpu, "rs6000") == 0)
810 ppc_cpu = PPC_OPCODE_POWER;
811 else if (strcmp (default_cpu, "powerpc") == 0
812 || strcmp (default_cpu, "powerpcle") == 0)
813 ppc_cpu = PPC_OPCODE_PPC;
814 else
815 as_fatal ("Unknown default cpu = %s, os = %s", default_cpu, default_os);
816 }
817 }
818
819 /* Figure out the BFD architecture to use. */
820
821 enum bfd_architecture
822 ppc_arch ()
823 {
824 const char *default_cpu = TARGET_CPU;
825 ppc_set_cpu ();
826
827 if ((ppc_cpu & PPC_OPCODE_PPC) != 0)
828 return bfd_arch_powerpc;
829 else if ((ppc_cpu & PPC_OPCODE_POWER) != 0)
830 return bfd_arch_rs6000;
831 else if ((ppc_cpu & (PPC_OPCODE_COMMON | PPC_OPCODE_ANY)) != 0)
832 {
833 if (strcmp (default_cpu, "rs6000") == 0)
834 return bfd_arch_rs6000;
835 else if (strcmp (default_cpu, "powerpc") == 0
836 || strcmp (default_cpu, "powerpcle") == 0)
837 return bfd_arch_powerpc;
838 }
839
840 as_fatal ("Neither Power nor PowerPC opcodes were selected.");
841 return bfd_arch_unknown;
842 }
843
844 /* This function is called when the assembler starts up. It is called
845 after the options have been parsed and the output file has been
846 opened. */
847
848 void
849 md_begin ()
850 {
851 register const struct powerpc_opcode *op;
852 const struct powerpc_opcode *op_end;
853 const struct powerpc_macro *macro;
854 const struct powerpc_macro *macro_end;
855 boolean dup_insn = false;
856
857 ppc_set_cpu ();
858
859 #ifdef OBJ_ELF
860 /* Set the ELF flags if desired. */
861 if (ppc_flags)
862 bfd_set_private_flags (stdoutput, ppc_flags);
863 #endif
864
865 /* Insert the opcodes into a hash table. */
866 ppc_hash = hash_new ();
867
868 op_end = powerpc_opcodes + powerpc_num_opcodes;
869 for (op = powerpc_opcodes; op < op_end; op++)
870 {
871 know ((op->opcode & op->mask) == op->opcode);
872
873 if ((op->flags & ppc_cpu) != 0
874 && ((op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == 0
875 || (op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == ppc_size))
876 {
877 const char *retval;
878
879 retval = hash_insert (ppc_hash, op->name, (PTR) op);
880 if (retval != (const char *) NULL)
881 {
882 /* Ignore Power duplicates for -m601 */
883 if ((ppc_cpu & PPC_OPCODE_601) != 0
884 && (op->flags & PPC_OPCODE_POWER) != 0)
885 continue;
886
887 as_bad ("Internal assembler error for instruction %s", op->name);
888 dup_insn = true;
889 }
890 }
891 }
892
893 /* Insert the macros into a hash table. */
894 ppc_macro_hash = hash_new ();
895
896 macro_end = powerpc_macros + powerpc_num_macros;
897 for (macro = powerpc_macros; macro < macro_end; macro++)
898 {
899 if ((macro->flags & ppc_cpu) != 0)
900 {
901 const char *retval;
902
903 retval = hash_insert (ppc_macro_hash, macro->name, (PTR) macro);
904 if (retval != (const char *) NULL)
905 {
906 as_bad ("Internal assembler error for macro %s", macro->name);
907 dup_insn = true;
908 }
909 }
910 }
911
912 if (dup_insn)
913 abort ();
914
915 /* Tell the main code what the endianness is if it is not overidden by the user. */
916 if (!set_target_endian)
917 {
918 set_target_endian = 1;
919 target_big_endian = PPC_BIG_ENDIAN;
920 }
921
922 #ifdef OBJ_XCOFF
923 ppc_coff_debug_section = coff_section_from_bfd_index (stdoutput, N_DEBUG);
924
925 /* Create dummy symbols to serve as initial csects. This forces the
926 text csects to precede the data csects. These symbols will not
927 be output. */
928 ppc_text_csects = symbol_make ("dummy\001");
929 ppc_text_csects->sy_tc.within = ppc_text_csects;
930 ppc_data_csects = symbol_make ("dummy\001");
931 ppc_data_csects->sy_tc.within = ppc_data_csects;
932 #endif
933
934 #ifdef TE_PE
935
936 ppc_current_section = text_section;
937 ppc_previous_section = 0;
938
939 #endif
940 }
941
942 /* Insert an operand value into an instruction. */
943
944 static unsigned long
945 ppc_insert_operand (insn, operand, val, file, line)
946 unsigned long insn;
947 const struct powerpc_operand *operand;
948 offsetT val;
949 char *file;
950 unsigned int line;
951 {
952 if (operand->bits != 32)
953 {
954 long min, max;
955 offsetT test;
956
957 if ((operand->flags & PPC_OPERAND_SIGNED) != 0)
958 {
959 if ((operand->flags & PPC_OPERAND_SIGNOPT) != 0
960 && ppc_size == PPC_OPCODE_32)
961 max = (1 << operand->bits) - 1;
962 else
963 max = (1 << (operand->bits - 1)) - 1;
964 min = - (1 << (operand->bits - 1));
965 }
966 else
967 {
968 max = (1 << operand->bits) - 1;
969 min = 0;
970 }
971
972 if ((operand->flags & PPC_OPERAND_NEGATIVE) != 0)
973 test = - val;
974 else
975 test = val;
976
977 if (test < (offsetT) min || test > (offsetT) max)
978 {
979 const char *err =
980 "operand out of range (%s not between %ld and %ld)";
981 char buf[100];
982
983 sprint_value (buf, test);
984 if (file == (char *) NULL)
985 as_warn (err, buf, min, max);
986 else
987 as_warn_where (file, line, err, buf, min, max);
988 }
989 }
990
991 if (operand->insert)
992 {
993 const char *errmsg;
994
995 errmsg = NULL;
996 insn = (*operand->insert) (insn, (long) val, &errmsg);
997 if (errmsg != (const char *) NULL)
998 as_warn (errmsg);
999 }
1000 else
1001 insn |= (((long) val & ((1 << operand->bits) - 1))
1002 << operand->shift);
1003
1004 return insn;
1005 }
1006
1007 \f
1008 #ifdef OBJ_ELF
1009 /* Parse @got, etc. and return the desired relocation. */
1010 static bfd_reloc_code_real_type
1011 ppc_elf_suffix (str_p)
1012 char **str_p;
1013 {
1014 struct map_bfd {
1015 char *string;
1016 int length;
1017 bfd_reloc_code_real_type reloc;
1018 };
1019
1020 char ident[20];
1021 char *str = *str_p;
1022 char *str2;
1023 int ch;
1024 int len;
1025 struct map_bfd *ptr;
1026
1027 #define MAP(str,reloc) { str, sizeof(str)-1, reloc }
1028
1029 static struct map_bfd mapping[] = {
1030 MAP ("l", BFD_RELOC_LO16),
1031 MAP ("h", BFD_RELOC_HI16),
1032 MAP ("ha", BFD_RELOC_HI16_S),
1033 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN),
1034 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN),
1035 MAP ("got", BFD_RELOC_16_GOTOFF),
1036 MAP ("got@l", BFD_RELOC_LO16_GOTOFF),
1037 MAP ("got@h", BFD_RELOC_HI16_GOTOFF),
1038 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF),
1039 MAP ("fixup", BFD_RELOC_CTOR), /* warnings with -mrelocatable */
1040 MAP ("pltrel24", BFD_RELOC_24_PLT_PCREL),
1041 MAP ("copy", BFD_RELOC_PPC_COPY),
1042 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT),
1043 MAP ("local24pc", BFD_RELOC_PPC_LOCAL24PC),
1044 MAP ("plt", BFD_RELOC_32_PLTOFF),
1045 MAP ("pltrel", BFD_RELOC_32_PLT_PCREL),
1046 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF),
1047 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF),
1048 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF),
1049 MAP ("sdarel", BFD_RELOC_GPREL16),
1050 MAP ("sectoff", BFD_RELOC_32_BASEREL),
1051 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL),
1052 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL),
1053 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL),
1054 MAP ("naddr", BFD_RELOC_PPC_EMB_NADDR32),
1055 MAP ("naddr16", BFD_RELOC_PPC_EMB_NADDR16),
1056 MAP ("naddr@l", BFD_RELOC_PPC_EMB_NADDR16_LO),
1057 MAP ("naddr@h", BFD_RELOC_PPC_EMB_NADDR16_HI),
1058 MAP ("naddr@ha", BFD_RELOC_PPC_EMB_NADDR16_HA),
1059 MAP ("sdai16", BFD_RELOC_PPC_EMB_SDAI16),
1060 MAP ("sda2rel", BFD_RELOC_PPC_EMB_SDA2REL),
1061 MAP ("sda2i16", BFD_RELOC_PPC_EMB_SDA2I16),
1062 MAP ("sda21", BFD_RELOC_PPC_EMB_SDA21),
1063 MAP ("mrkref", BFD_RELOC_PPC_EMB_MRKREF),
1064 MAP ("relsect", BFD_RELOC_PPC_EMB_RELSEC16),
1065 MAP ("relsect@l", BFD_RELOC_PPC_EMB_RELST_LO),
1066 MAP ("relsect@h", BFD_RELOC_PPC_EMB_RELST_HI),
1067 MAP ("relsect@ha", BFD_RELOC_PPC_EMB_RELST_HA),
1068 MAP ("bitfld", BFD_RELOC_PPC_EMB_BIT_FLD),
1069 MAP ("relsda", BFD_RELOC_PPC_EMB_RELSDA),
1070 MAP ("xgot", BFD_RELOC_PPC_TOC16),
1071
1072 { (char *)0, 0, BFD_RELOC_UNUSED }
1073 };
1074
1075 if (*str++ != '@')
1076 return BFD_RELOC_UNUSED;
1077
1078 for (ch = *str, str2 = ident;
1079 (str2 < ident + sizeof (ident) - 1
1080 && (isalnum (ch) || ch == '@'));
1081 ch = *++str)
1082 {
1083 *str2++ = (islower (ch)) ? ch : tolower (ch);
1084 }
1085
1086 *str2 = '\0';
1087 len = str2 - ident;
1088
1089 ch = ident[0];
1090 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
1091 if (ch == ptr->string[0] && len == ptr->length && memcmp (ident, ptr->string, ptr->length) == 0)
1092 {
1093 *str_p = str;
1094 return ptr->reloc;
1095 }
1096
1097 return BFD_RELOC_UNUSED;
1098 }
1099
1100 /* Like normal .long/.short/.word, except support @got, etc. */
1101 /* clobbers input_line_pointer, checks */
1102 /* end-of-line. */
1103 static void
1104 ppc_elf_cons (nbytes)
1105 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
1106 {
1107 expressionS exp;
1108 bfd_reloc_code_real_type reloc;
1109
1110 if (is_it_end_of_statement ())
1111 {
1112 demand_empty_rest_of_line ();
1113 return;
1114 }
1115
1116 do
1117 {
1118 expression (&exp);
1119 if (exp.X_op == O_symbol
1120 && *input_line_pointer == '@'
1121 && (reloc = ppc_elf_suffix (&input_line_pointer)) != BFD_RELOC_UNUSED)
1122 {
1123 reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc);
1124 int size = bfd_get_reloc_size (reloc_howto);
1125
1126 if (size > nbytes)
1127 as_bad ("%s relocations do not fit in %d bytes\n", reloc_howto->name, nbytes);
1128
1129 else
1130 {
1131 register char *p = frag_more ((int) nbytes);
1132 int offset = nbytes - size;
1133
1134 fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size, &exp, 0, reloc);
1135 }
1136 }
1137 else
1138 emit_expr (&exp, (unsigned int) nbytes);
1139 }
1140 while (*input_line_pointer++ == ',');
1141
1142 input_line_pointer--; /* Put terminator back into stream. */
1143 demand_empty_rest_of_line ();
1144 }
1145
1146 /* Solaris pseduo op to change to the .rodata section. */
1147 static void
1148 ppc_elf_rdata (xxx)
1149 int xxx;
1150 {
1151 char *save_line = input_line_pointer;
1152 static char section[] = ".rodata\n";
1153
1154 /* Just pretend this is .section .rodata */
1155 input_line_pointer = section;
1156 obj_elf_section (xxx);
1157
1158 input_line_pointer = save_line;
1159 }
1160
1161 /* Pseudo op to make file scope bss items */
1162 static void
1163 ppc_elf_lcomm(xxx)
1164 int xxx;
1165 {
1166 register char *name;
1167 register char c;
1168 register char *p;
1169 offsetT size;
1170 register symbolS *symbolP;
1171 offsetT align;
1172 segT old_sec;
1173 int old_subsec;
1174 char *pfrag;
1175 int align2;
1176
1177 name = input_line_pointer;
1178 c = get_symbol_end ();
1179
1180 /* just after name is now '\0' */
1181 p = input_line_pointer;
1182 *p = c;
1183 SKIP_WHITESPACE ();
1184 if (*input_line_pointer != ',')
1185 {
1186 as_bad ("Expected comma after symbol-name: rest of line ignored.");
1187 ignore_rest_of_line ();
1188 return;
1189 }
1190
1191 input_line_pointer++; /* skip ',' */
1192 if ((size = get_absolute_expression ()) < 0)
1193 {
1194 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) size);
1195 ignore_rest_of_line ();
1196 return;
1197 }
1198
1199 /* The third argument to .lcomm is the alignment. */
1200 if (*input_line_pointer != ',')
1201 align = 3;
1202 else
1203 {
1204 ++input_line_pointer;
1205 align = get_absolute_expression ();
1206 if (align <= 0)
1207 {
1208 as_warn ("ignoring bad alignment");
1209 align = 3;
1210 }
1211 }
1212
1213 *p = 0;
1214 symbolP = symbol_find_or_make (name);
1215 *p = c;
1216
1217 if (S_IS_DEFINED (symbolP))
1218 {
1219 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1220 S_GET_NAME (symbolP));
1221 ignore_rest_of_line ();
1222 return;
1223 }
1224
1225 if (S_GET_VALUE (symbolP) && S_GET_VALUE (symbolP) != (valueT) size)
1226 {
1227 as_bad ("Length of .lcomm \"%s\" is already %ld. Not changed to %ld.",
1228 S_GET_NAME (symbolP),
1229 (long) S_GET_VALUE (symbolP),
1230 (long) size);
1231
1232 ignore_rest_of_line ();
1233 return;
1234 }
1235
1236 /* allocate_bss: */
1237 old_sec = now_seg;
1238 old_subsec = now_subseg;
1239 if (align)
1240 {
1241 /* convert to a power of 2 alignment */
1242 for (align2 = 0; (align & 1) == 0; align >>= 1, ++align2);
1243 if (align != 1)
1244 {
1245 as_bad ("Common alignment not a power of 2");
1246 ignore_rest_of_line ();
1247 return;
1248 }
1249 }
1250 else
1251 align2 = 0;
1252
1253 record_alignment (bss_section, align2);
1254 subseg_set (bss_section, 0);
1255 if (align2)
1256 frag_align (align2, 0);
1257 if (S_GET_SEGMENT (symbolP) == bss_section)
1258 symbolP->sy_frag->fr_symbol = 0;
1259 symbolP->sy_frag = frag_now;
1260 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
1261 (char *) 0);
1262 *pfrag = 0;
1263 S_SET_SIZE (symbolP, size);
1264 S_SET_SEGMENT (symbolP, bss_section);
1265 S_CLEAR_EXTERNAL (symbolP);
1266 subseg_set (old_sec, old_subsec);
1267 demand_empty_rest_of_line ();
1268 }
1269
1270 /* Validate any relocations emitted for -mrelocatable, possibly adding
1271 fixups for word relocations in writable segments, so we can adjust
1272 them at runtime. */
1273 static void
1274 ppc_elf_validate_fix (fixp, seg)
1275 fixS *fixp;
1276 segT seg;
1277 {
1278 if (mrelocatable
1279 && !fixp->fx_done
1280 && !fixp->fx_pcrel
1281 && fixp->fx_r_type <= BFD_RELOC_UNUSED
1282 && fixp->fx_r_type != BFD_RELOC_16_GOTOFF
1283 && fixp->fx_r_type != BFD_RELOC_HI16_GOTOFF
1284 && fixp->fx_r_type != BFD_RELOC_LO16_GOTOFF
1285 && fixp->fx_r_type != BFD_RELOC_HI16_S_GOTOFF
1286 && fixp->fx_r_type != BFD_RELOC_32_BASEREL
1287 && fixp->fx_r_type != BFD_RELOC_LO16_BASEREL
1288 && fixp->fx_r_type != BFD_RELOC_HI16_BASEREL
1289 && fixp->fx_r_type != BFD_RELOC_HI16_S_BASEREL
1290 && strcmp (segment_name (seg), ".got2") != 0
1291 && strcmp (segment_name (seg), ".dtors") != 0
1292 && strcmp (segment_name (seg), ".ctors") != 0
1293 && strcmp (segment_name (seg), ".fixup") != 0
1294 && strcmp (segment_name (seg), ".stab") != 0
1295 && strcmp (segment_name (seg), ".gcc_except_table") != 0
1296 && strcmp (segment_name (seg), ".ex_shared") != 0)
1297 {
1298 if ((seg->flags & (SEC_READONLY | SEC_CODE)) != 0
1299 || fixp->fx_r_type != BFD_RELOC_CTOR)
1300 {
1301 as_warn_where (fixp->fx_file, fixp->fx_line,
1302 "Relocation cannot be done when using -mrelocatable");
1303 }
1304 }
1305 }
1306 #endif /* OBJ_ELF */
1307 \f
1308 #ifdef TE_PE
1309
1310 /*
1311 * Summary of parse_toc_entry().
1312 *
1313 * in: Input_line_pointer points to the '[' in one of:
1314 *
1315 * [toc] [tocv] [toc32] [toc64]
1316 *
1317 * Anything else is an error of one kind or another.
1318 *
1319 * out:
1320 * return value: success or failure
1321 * toc_kind: kind of toc reference
1322 * input_line_pointer:
1323 * success: first char after the ']'
1324 * failure: unchanged
1325 *
1326 * settings:
1327 *
1328 * [toc] - rv == success, toc_kind = default_toc
1329 * [tocv] - rv == success, toc_kind = data_in_toc
1330 * [toc32] - rv == success, toc_kind = must_be_32
1331 * [toc64] - rv == success, toc_kind = must_be_64
1332 *
1333 */
1334
1335 enum toc_size_qualifier
1336 {
1337 default_toc, /* The toc cell constructed should be the system default size */
1338 data_in_toc, /* This is a direct reference to a toc cell */
1339 must_be_32, /* The toc cell constructed must be 32 bits wide */
1340 must_be_64 /* The toc cell constructed must be 64 bits wide */
1341 };
1342
1343 static int
1344 parse_toc_entry(toc_kind)
1345 enum toc_size_qualifier *toc_kind;
1346 {
1347 char *start;
1348 char *toc_spec;
1349 char c;
1350 enum toc_size_qualifier t;
1351
1352 /* save the input_line_pointer */
1353 start = input_line_pointer;
1354
1355 /* skip over the '[' , and whitespace */
1356 ++input_line_pointer;
1357 SKIP_WHITESPACE ();
1358
1359 /* find the spelling of the operand */
1360 toc_spec = input_line_pointer;
1361 c = get_symbol_end ();
1362
1363 if (strcmp(toc_spec, "toc") == 0)
1364 {
1365 t = default_toc;
1366 }
1367 else if (strcmp(toc_spec, "tocv") == 0)
1368 {
1369 t = data_in_toc;
1370 }
1371 else if (strcmp(toc_spec, "toc32") == 0)
1372 {
1373 t = must_be_32;
1374 }
1375 else if (strcmp(toc_spec, "toc64") == 0)
1376 {
1377 t = must_be_64;
1378 }
1379 else
1380 {
1381 as_bad ("syntax error: invalid toc specifier `%s'", toc_spec);
1382 *input_line_pointer = c; /* put back the delimiting char */
1383 input_line_pointer = start; /* reset input_line pointer */
1384 return 0;
1385 }
1386
1387 /* now find the ']' */
1388 *input_line_pointer = c; /* put back the delimiting char */
1389
1390 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1391 c = *input_line_pointer++; /* input_line_pointer->past char in c. */
1392
1393 if (c != ']')
1394 {
1395 as_bad ("syntax error: expected `]', found `%c'", c);
1396 input_line_pointer = start; /* reset input_line pointer */
1397 return 0;
1398 }
1399
1400 *toc_kind = t; /* set return value */
1401 return 1;
1402 }
1403 #endif
1404 \f
1405
1406 /* We need to keep a list of fixups. We can't simply generate them as
1407 we go, because that would require us to first create the frag, and
1408 that would screw up references to ``.''. */
1409
1410 struct ppc_fixup
1411 {
1412 expressionS exp;
1413 int opindex;
1414 bfd_reloc_code_real_type reloc;
1415 };
1416
1417 #define MAX_INSN_FIXUPS (5)
1418
1419 /* This routine is called for each instruction to be assembled. */
1420
1421 void
1422 md_assemble (str)
1423 char *str;
1424 {
1425 char *s;
1426 const struct powerpc_opcode *opcode;
1427 unsigned long insn;
1428 const unsigned char *opindex_ptr;
1429 int skip_optional;
1430 int need_paren;
1431 int next_opindex;
1432 struct ppc_fixup fixups[MAX_INSN_FIXUPS];
1433 int fc;
1434 char *f;
1435 int i;
1436 #ifdef OBJ_ELF
1437 bfd_reloc_code_real_type reloc;
1438 #endif
1439
1440 /* Get the opcode. */
1441 for (s = str; *s != '\0' && ! isspace (*s); s++)
1442 ;
1443 if (*s != '\0')
1444 *s++ = '\0';
1445
1446 /* Look up the opcode in the hash table. */
1447 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, str);
1448 if (opcode == (const struct powerpc_opcode *) NULL)
1449 {
1450 const struct powerpc_macro *macro;
1451
1452 macro = (const struct powerpc_macro *) hash_find (ppc_macro_hash, str);
1453 if (macro == (const struct powerpc_macro *) NULL)
1454 as_bad ("Unrecognized opcode: `%s'", str);
1455 else
1456 ppc_macro (s, macro);
1457
1458 return;
1459 }
1460
1461 insn = opcode->opcode;
1462
1463 str = s;
1464 while (isspace (*str))
1465 ++str;
1466
1467 /* PowerPC operands are just expressions. The only real issue is
1468 that a few operand types are optional. All cases which might use
1469 an optional operand separate the operands only with commas (in
1470 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1471 cases never have optional operands). There is never more than
1472 one optional operand for an instruction. So, before we start
1473 seriously parsing the operands, we check to see if we have an
1474 optional operand, and, if we do, we count the number of commas to
1475 see whether the operand should be omitted. */
1476 skip_optional = 0;
1477 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1478 {
1479 const struct powerpc_operand *operand;
1480
1481 operand = &powerpc_operands[*opindex_ptr];
1482 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0)
1483 {
1484 unsigned int opcount;
1485
1486 /* There is an optional operand. Count the number of
1487 commas in the input line. */
1488 if (*str == '\0')
1489 opcount = 0;
1490 else
1491 {
1492 opcount = 1;
1493 s = str;
1494 while ((s = strchr (s, ',')) != (char *) NULL)
1495 {
1496 ++opcount;
1497 ++s;
1498 }
1499 }
1500
1501 /* If there are fewer operands in the line then are called
1502 for by the instruction, we want to skip the optional
1503 operand. */
1504 if (opcount < strlen (opcode->operands))
1505 skip_optional = 1;
1506
1507 break;
1508 }
1509 }
1510
1511 /* Gather the operands. */
1512 need_paren = 0;
1513 next_opindex = 0;
1514 fc = 0;
1515 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1516 {
1517 const struct powerpc_operand *operand;
1518 const char *errmsg;
1519 char *hold;
1520 expressionS ex;
1521 char endc;
1522
1523 if (next_opindex == 0)
1524 operand = &powerpc_operands[*opindex_ptr];
1525 else
1526 {
1527 operand = &powerpc_operands[next_opindex];
1528 next_opindex = 0;
1529 }
1530
1531 errmsg = NULL;
1532
1533 /* If this is a fake operand, then we do not expect anything
1534 from the input. */
1535 if ((operand->flags & PPC_OPERAND_FAKE) != 0)
1536 {
1537 insn = (*operand->insert) (insn, 0L, &errmsg);
1538 if (errmsg != (const char *) NULL)
1539 as_warn (errmsg);
1540 continue;
1541 }
1542
1543 /* If this is an optional operand, and we are skipping it, just
1544 insert a zero. */
1545 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0
1546 && skip_optional)
1547 {
1548 if (operand->insert)
1549 {
1550 insn = (*operand->insert) (insn, 0L, &errmsg);
1551 if (errmsg != (const char *) NULL)
1552 as_warn (errmsg);
1553 }
1554 if ((operand->flags & PPC_OPERAND_NEXT) != 0)
1555 next_opindex = *opindex_ptr + 1;
1556 continue;
1557 }
1558
1559 /* Gather the operand. */
1560 hold = input_line_pointer;
1561 input_line_pointer = str;
1562
1563 #ifdef TE_PE
1564 if (*input_line_pointer == '[')
1565 {
1566 /* We are expecting something like the second argument here:
1567
1568 lwz r4,[toc].GS.0.static_int(rtoc)
1569 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1570 The argument following the `]' must be a symbol name, and the
1571 register must be the toc register: 'rtoc' or '2'
1572
1573 The effect is to 0 as the displacement field
1574 in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1575 the appropriate variation) reloc against it based on the symbol.
1576 The linker will build the toc, and insert the resolved toc offset.
1577
1578 Note:
1579 o The size of the toc entry is currently assumed to be
1580 32 bits. This should not be assumed to be a hard coded
1581 number.
1582 o In an effort to cope with a change from 32 to 64 bits,
1583 there are also toc entries that are specified to be
1584 either 32 or 64 bits:
1585 lwz r4,[toc32].GS.0.static_int(rtoc)
1586 lwz r4,[toc64].GS.0.static_int(rtoc)
1587 These demand toc entries of the specified size, and the
1588 instruction probably requires it.
1589 */
1590
1591 int valid_toc;
1592 enum toc_size_qualifier toc_kind;
1593 bfd_reloc_code_real_type toc_reloc;
1594
1595 /* go parse off the [tocXX] part */
1596 valid_toc = parse_toc_entry(&toc_kind);
1597
1598 if (!valid_toc)
1599 {
1600 /* Note: message has already been issued. */
1601 /* FIXME: what sort of recovery should we do? */
1602 /* demand_rest_of_line(); return; ? */
1603 }
1604
1605 /* Now get the symbol following the ']' */
1606 expression(&ex);
1607
1608 switch (toc_kind)
1609 {
1610 case default_toc:
1611 /* In this case, we may not have seen the symbol yet, since */
1612 /* it is allowed to appear on a .extern or .globl or just be */
1613 /* a label in the .data section. */
1614 toc_reloc = BFD_RELOC_PPC_TOC16;
1615 break;
1616 case data_in_toc:
1617 /* 1. The symbol must be defined and either in the toc */
1618 /* section, or a global. */
1619 /* 2. The reloc generated must have the TOCDEFN flag set in */
1620 /* upper bit mess of the reloc type. */
1621 /* FIXME: It's a little confusing what the tocv qualifier can */
1622 /* be used for. At the very least, I've seen three */
1623 /* uses, only one of which I'm sure I can explain. */
1624 if (ex.X_op == O_symbol)
1625 {
1626 assert (ex.X_add_symbol != NULL);
1627 if (ex.X_add_symbol->bsym->section != tocdata_section)
1628 {
1629 as_warn("[tocv] symbol is not a toc symbol");
1630 }
1631 }
1632
1633 toc_reloc = BFD_RELOC_PPC_TOC16;
1634 break;
1635 case must_be_32:
1636 /* FIXME: these next two specifically specify 32/64 bit toc */
1637 /* entries. We don't support them today. Is this the */
1638 /* right way to say that? */
1639 toc_reloc = BFD_RELOC_UNUSED;
1640 as_bad ("Unimplemented toc32 expression modifier");
1641 break;
1642 case must_be_64:
1643 /* FIXME: see above */
1644 toc_reloc = BFD_RELOC_UNUSED;
1645 as_bad ("Unimplemented toc64 expression modifier");
1646 break;
1647 default:
1648 fprintf(stderr,
1649 "Unexpected return value [%d] from parse_toc_entry!\n",
1650 toc_kind);
1651 abort();
1652 break;
1653 }
1654
1655 /* We need to generate a fixup for this expression. */
1656 if (fc >= MAX_INSN_FIXUPS)
1657 as_fatal ("too many fixups");
1658
1659 fixups[fc].reloc = toc_reloc;
1660 fixups[fc].exp = ex;
1661 fixups[fc].opindex = *opindex_ptr;
1662 ++fc;
1663
1664 /* Ok. We've set up the fixup for the instruction. Now make it
1665 look like the constant 0 was found here */
1666 ex.X_unsigned = 1;
1667 ex.X_op = O_constant;
1668 ex.X_add_number = 0;
1669 ex.X_add_symbol = NULL;
1670 ex.X_op_symbol = NULL;
1671 }
1672
1673 else
1674 #endif /* TE_PE */
1675 if (!register_name(&ex))
1676 expression (&ex);
1677
1678 str = input_line_pointer;
1679 input_line_pointer = hold;
1680
1681 if (ex.X_op == O_illegal)
1682 as_bad ("illegal operand");
1683 else if (ex.X_op == O_absent)
1684 as_bad ("missing operand");
1685 else if (ex.X_op == O_register)
1686 {
1687 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
1688 (char *) NULL, 0);
1689 }
1690 else if (ex.X_op == O_constant)
1691 {
1692 #ifdef OBJ_ELF
1693 /* Allow @HA, @L, @H on constants. */
1694 char *orig_str = str;
1695
1696 if ((reloc = ppc_elf_suffix (&str)) != BFD_RELOC_UNUSED)
1697 switch (reloc)
1698 {
1699 default:
1700 str = orig_str;
1701 break;
1702
1703 case BFD_RELOC_LO16:
1704 if (ex.X_unsigned)
1705 ex.X_add_number &= 0xffff;
1706 else
1707 ex.X_add_number = (((ex.X_add_number & 0xffff)
1708 ^ 0x8000)
1709 - 0x8000);
1710 break;
1711
1712 case BFD_RELOC_HI16:
1713 ex.X_add_number = (ex.X_add_number >> 16) & 0xffff;
1714 break;
1715
1716 case BFD_RELOC_HI16_S:
1717 ex.X_add_number = (((ex.X_add_number >> 16) & 0xffff)
1718 + ((ex.X_add_number >> 15) & 1));
1719 break;
1720 }
1721 #endif
1722 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
1723 (char *) NULL, 0);
1724 }
1725 #ifdef OBJ_ELF
1726 else if ((reloc = ppc_elf_suffix (&str)) != BFD_RELOC_UNUSED)
1727 {
1728 /* For the absoulte forms of branchs, convert the PC relative form back into
1729 the absolute. */
1730 if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0)
1731 {
1732 switch (reloc)
1733 {
1734 case BFD_RELOC_PPC_B26:
1735 reloc = BFD_RELOC_PPC_BA26;
1736 break;
1737 case BFD_RELOC_PPC_B16:
1738 reloc = BFD_RELOC_PPC_BA16;
1739 break;
1740 case BFD_RELOC_PPC_B16_BRTAKEN:
1741 reloc = BFD_RELOC_PPC_BA16_BRTAKEN;
1742 break;
1743 case BFD_RELOC_PPC_B16_BRNTAKEN:
1744 reloc = BFD_RELOC_PPC_BA16_BRNTAKEN;
1745 break;
1746 default:
1747 break;
1748 }
1749 }
1750
1751 /* We need to generate a fixup for this expression. */
1752 if (fc >= MAX_INSN_FIXUPS)
1753 as_fatal ("too many fixups");
1754 fixups[fc].exp = ex;
1755 fixups[fc].opindex = 0;
1756 fixups[fc].reloc = reloc;
1757 ++fc;
1758 }
1759 #endif /* OBJ_ELF */
1760
1761 else
1762 {
1763 /* We need to generate a fixup for this expression. */
1764 if (fc >= MAX_INSN_FIXUPS)
1765 as_fatal ("too many fixups");
1766 fixups[fc].exp = ex;
1767 fixups[fc].opindex = *opindex_ptr;
1768 fixups[fc].reloc = BFD_RELOC_UNUSED;
1769 ++fc;
1770 }
1771
1772 if (need_paren)
1773 {
1774 endc = ')';
1775 need_paren = 0;
1776 }
1777 else if ((operand->flags & PPC_OPERAND_PARENS) != 0)
1778 {
1779 endc = '(';
1780 need_paren = 1;
1781 }
1782 else
1783 endc = ',';
1784
1785 /* The call to expression should have advanced str past any
1786 whitespace. */
1787 if (*str != endc
1788 && (endc != ',' || *str != '\0'))
1789 {
1790 as_bad ("syntax error; found `%c' but expected `%c'", *str, endc);
1791 break;
1792 }
1793
1794 if (*str != '\0')
1795 ++str;
1796 }
1797
1798 while (isspace (*str))
1799 ++str;
1800
1801 if (*str != '\0')
1802 as_bad ("junk at end of line: `%s'", str);
1803
1804 /* Write out the instruction. */
1805 f = frag_more (4);
1806 md_number_to_chars (f, insn, 4);
1807
1808 /* Create any fixups. At this point we do not use a
1809 bfd_reloc_code_real_type, but instead just use the
1810 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1811 handle fixups for any operand type, although that is admittedly
1812 not a very exciting feature. We pick a BFD reloc type in
1813 md_apply_fix. */
1814 for (i = 0; i < fc; i++)
1815 {
1816 const struct powerpc_operand *operand;
1817
1818 operand = &powerpc_operands[fixups[i].opindex];
1819 if (fixups[i].reloc != BFD_RELOC_UNUSED)
1820 {
1821 reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
1822 int size;
1823 int offset;
1824 fixS *fixP;
1825
1826 if (!reloc_howto)
1827 abort ();
1828
1829 size = bfd_get_reloc_size (reloc_howto);
1830 offset = target_big_endian ? (4 - size) : 0;
1831
1832 if (size < 1 || size > 4)
1833 abort();
1834
1835 fixP = fix_new_exp (frag_now, f - frag_now->fr_literal + offset, size,
1836 &fixups[i].exp, reloc_howto->pc_relative,
1837 fixups[i].reloc);
1838
1839 /* Turn off complaints that the addend is too large for things like
1840 foo+100000@ha. */
1841 switch (fixups[i].reloc)
1842 {
1843 case BFD_RELOC_16_GOTOFF:
1844 case BFD_RELOC_PPC_TOC16:
1845 case BFD_RELOC_LO16:
1846 case BFD_RELOC_HI16:
1847 case BFD_RELOC_HI16_S:
1848 fixP->fx_no_overflow = 1;
1849 break;
1850 default:
1851 break;
1852 }
1853 }
1854 else
1855 fix_new_exp (frag_now, f - frag_now->fr_literal, 4,
1856 &fixups[i].exp,
1857 (operand->flags & PPC_OPERAND_RELATIVE) != 0,
1858 ((bfd_reloc_code_real_type)
1859 (fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
1860 }
1861 }
1862
1863 #ifndef WORKING_DOT_WORD
1864 /* Handle long and short jumps */
1865 void
1866 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
1867 char *ptr;
1868 addressT from_addr, to_addr;
1869 fragS *frag;
1870 symbolS *to_symbol;
1871 {
1872 abort ();
1873 }
1874
1875 void
1876 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
1877 char *ptr;
1878 addressT from_addr, to_addr;
1879 fragS *frag;
1880 symbolS *to_symbol;
1881 {
1882 abort ();
1883 }
1884 #endif
1885
1886 /* Handle a macro. Gather all the operands, transform them as
1887 described by the macro, and call md_assemble recursively. All the
1888 operands are separated by commas; we don't accept parentheses
1889 around operands here. */
1890
1891 static void
1892 ppc_macro (str, macro)
1893 char *str;
1894 const struct powerpc_macro *macro;
1895 {
1896 char *operands[10];
1897 unsigned int count;
1898 char *s;
1899 unsigned int len;
1900 const char *format;
1901 int arg;
1902 char *send;
1903 char *complete;
1904
1905 /* Gather the users operands into the operands array. */
1906 count = 0;
1907 s = str;
1908 while (1)
1909 {
1910 if (count >= sizeof operands / sizeof operands[0])
1911 break;
1912 operands[count++] = s;
1913 s = strchr (s, ',');
1914 if (s == (char *) NULL)
1915 break;
1916 *s++ = '\0';
1917 }
1918
1919 if (count != macro->operands)
1920 {
1921 as_bad ("wrong number of operands");
1922 return;
1923 }
1924
1925 /* Work out how large the string must be (the size is unbounded
1926 because it includes user input). */
1927 len = 0;
1928 format = macro->format;
1929 while (*format != '\0')
1930 {
1931 if (*format != '%')
1932 {
1933 ++len;
1934 ++format;
1935 }
1936 else
1937 {
1938 arg = strtol (format + 1, &send, 10);
1939 know (send != format && arg >= 0 && arg < count);
1940 len += strlen (operands[arg]);
1941 format = send;
1942 }
1943 }
1944
1945 /* Put the string together. */
1946 complete = s = (char *) alloca (len + 1);
1947 format = macro->format;
1948 while (*format != '\0')
1949 {
1950 if (*format != '%')
1951 *s++ = *format++;
1952 else
1953 {
1954 arg = strtol (format + 1, &send, 10);
1955 strcpy (s, operands[arg]);
1956 s += strlen (s);
1957 format = send;
1958 }
1959 }
1960 *s = '\0';
1961
1962 /* Assemble the constructed instruction. */
1963 md_assemble (complete);
1964 }
1965 \f
1966 #ifdef OBJ_ELF
1967 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED */
1968
1969 int
1970 ppc_section_letter (letter, ptr_msg)
1971 int letter;
1972 char **ptr_msg;
1973 {
1974 if (letter == 'e')
1975 return SHF_EXCLUDE;
1976
1977 *ptr_msg = "Bad .section directive: want a,w,x,e in string";
1978 return 0;
1979 }
1980
1981 int
1982 ppc_section_word (ptr_str)
1983 char **ptr_str;
1984 {
1985 if (strncmp (*ptr_str, "exclude", sizeof ("exclude")-1) == 0)
1986 {
1987 *ptr_str += sizeof ("exclude")-1;
1988 return SHF_EXCLUDE;
1989 }
1990
1991 return 0;
1992 }
1993
1994 int
1995 ppc_section_type (ptr_str)
1996 char **ptr_str;
1997 {
1998 if (strncmp (*ptr_str, "ordered", sizeof ("ordered")-1) == 0)
1999 {
2000 *ptr_str += sizeof ("ordered")-1;
2001 return SHT_ORDERED;
2002 }
2003
2004 return 0;
2005 }
2006
2007 int
2008 ppc_section_flags (flags, attr, type)
2009 int flags;
2010 int attr;
2011 int type;
2012 {
2013 if (type == SHT_ORDERED)
2014 flags |= SEC_ALLOC | SEC_LOAD | SEC_SORT_ENTRIES;
2015
2016 if (attr & SHF_EXCLUDE)
2017 flags |= SEC_EXCLUDE;
2018
2019 return flags;
2020 }
2021 #endif /* OBJ_ELF */
2022
2023 \f
2024 /* Pseudo-op handling. */
2025
2026 /* The .byte pseudo-op. This is similar to the normal .byte
2027 pseudo-op, but it can also take a single ASCII string. */
2028
2029 static void
2030 ppc_byte (ignore)
2031 int ignore;
2032 {
2033 if (*input_line_pointer != '\"')
2034 {
2035 cons (1);
2036 return;
2037 }
2038
2039 /* Gather characters. A real double quote is doubled. Unusual
2040 characters are not permitted. */
2041 ++input_line_pointer;
2042 while (1)
2043 {
2044 char c;
2045
2046 c = *input_line_pointer++;
2047
2048 if (c == '\"')
2049 {
2050 if (*input_line_pointer != '\"')
2051 break;
2052 ++input_line_pointer;
2053 }
2054
2055 FRAG_APPEND_1_CHAR (c);
2056 }
2057
2058 demand_empty_rest_of_line ();
2059 }
2060 \f
2061 #ifdef OBJ_XCOFF
2062
2063 /* XCOFF specific pseudo-op handling. */
2064
2065 /* This is set if we are creating a .stabx symbol, since we don't want
2066 to handle symbol suffixes for such symbols. */
2067 static boolean ppc_stab_symbol;
2068
2069 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2070 symbols in the .bss segment as though they were local common
2071 symbols, and uses a different smclas. */
2072
2073 static void
2074 ppc_comm (lcomm)
2075 int lcomm;
2076 {
2077 asection *current_seg = now_seg;
2078 subsegT current_subseg = now_subseg;
2079 char *name;
2080 char endc;
2081 char *end_name;
2082 offsetT size;
2083 offsetT align;
2084 symbolS *lcomm_sym = NULL;
2085 symbolS *sym;
2086 char *pfrag;
2087
2088 name = input_line_pointer;
2089 endc = get_symbol_end ();
2090 end_name = input_line_pointer;
2091 *end_name = endc;
2092
2093 if (*input_line_pointer != ',')
2094 {
2095 as_bad ("missing size");
2096 ignore_rest_of_line ();
2097 return;
2098 }
2099 ++input_line_pointer;
2100
2101 size = get_absolute_expression ();
2102 if (size < 0)
2103 {
2104 as_bad ("negative size");
2105 ignore_rest_of_line ();
2106 return;
2107 }
2108
2109 if (! lcomm)
2110 {
2111 /* The third argument to .comm is the alignment. */
2112 if (*input_line_pointer != ',')
2113 align = 3;
2114 else
2115 {
2116 ++input_line_pointer;
2117 align = get_absolute_expression ();
2118 if (align <= 0)
2119 {
2120 as_warn ("ignoring bad alignment");
2121 align = 3;
2122 }
2123 }
2124 }
2125 else
2126 {
2127 char *lcomm_name;
2128 char lcomm_endc;
2129
2130 if (size <= 1)
2131 align = 0;
2132 else if (size <= 2)
2133 align = 1;
2134 else if (size <= 4)
2135 align = 2;
2136 else
2137 align = 3;
2138
2139 /* The third argument to .lcomm appears to be the real local
2140 common symbol to create. References to the symbol named in
2141 the first argument are turned into references to the third
2142 argument. */
2143 if (*input_line_pointer != ',')
2144 {
2145 as_bad ("missing real symbol name");
2146 ignore_rest_of_line ();
2147 return;
2148 }
2149 ++input_line_pointer;
2150
2151 lcomm_name = input_line_pointer;
2152 lcomm_endc = get_symbol_end ();
2153
2154 lcomm_sym = symbol_find_or_make (lcomm_name);
2155
2156 *input_line_pointer = lcomm_endc;
2157 }
2158
2159 *end_name = '\0';
2160 sym = symbol_find_or_make (name);
2161 *end_name = endc;
2162
2163 if (S_IS_DEFINED (sym)
2164 || S_GET_VALUE (sym) != 0)
2165 {
2166 as_bad ("attempt to redefine symbol");
2167 ignore_rest_of_line ();
2168 return;
2169 }
2170
2171 record_alignment (bss_section, align);
2172
2173 if (! lcomm
2174 || ! S_IS_DEFINED (lcomm_sym))
2175 {
2176 symbolS *def_sym;
2177 offsetT def_size;
2178
2179 if (! lcomm)
2180 {
2181 def_sym = sym;
2182 def_size = size;
2183 S_SET_EXTERNAL (sym);
2184 }
2185 else
2186 {
2187 lcomm_sym->sy_tc.output = 1;
2188 def_sym = lcomm_sym;
2189 def_size = 0;
2190 }
2191
2192 subseg_set (bss_section, 1);
2193 frag_align (align, 0);
2194
2195 def_sym->sy_frag = frag_now;
2196 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, def_sym,
2197 def_size, (char *) NULL);
2198 *pfrag = 0;
2199 S_SET_SEGMENT (def_sym, bss_section);
2200 def_sym->sy_tc.align = align;
2201 }
2202 else if (lcomm)
2203 {
2204 /* Align the size of lcomm_sym. */
2205 lcomm_sym->sy_frag->fr_offset =
2206 ((lcomm_sym->sy_frag->fr_offset + (1 << align) - 1)
2207 &~ ((1 << align) - 1));
2208 if (align > lcomm_sym->sy_tc.align)
2209 lcomm_sym->sy_tc.align = align;
2210 }
2211
2212 if (lcomm)
2213 {
2214 /* Make sym an offset from lcomm_sym. */
2215 S_SET_SEGMENT (sym, bss_section);
2216 sym->sy_frag = lcomm_sym->sy_frag;
2217 S_SET_VALUE (sym, lcomm_sym->sy_frag->fr_offset);
2218 lcomm_sym->sy_frag->fr_offset += size;
2219 }
2220
2221 subseg_set (current_seg, current_subseg);
2222
2223 demand_empty_rest_of_line ();
2224 }
2225
2226 /* The .csect pseudo-op. This switches us into a different
2227 subsegment. The first argument is a symbol whose value is the
2228 start of the .csect. In COFF, csect symbols get special aux
2229 entries defined by the x_csect field of union internal_auxent. The
2230 optional second argument is the alignment (the default is 2). */
2231
2232 static void
2233 ppc_csect (ignore)
2234 int ignore;
2235 {
2236 char *name;
2237 char endc;
2238 symbolS *sym;
2239
2240 name = input_line_pointer;
2241 endc = get_symbol_end ();
2242
2243 sym = symbol_find_or_make (name);
2244
2245 *input_line_pointer = endc;
2246
2247 if (S_GET_NAME (sym)[0] == '\0')
2248 {
2249 /* An unnamed csect is assumed to be [PR]. */
2250 sym->sy_tc.class = XMC_PR;
2251 }
2252
2253 ppc_change_csect (sym);
2254
2255 if (*input_line_pointer == ',')
2256 {
2257 ++input_line_pointer;
2258 sym->sy_tc.align = get_absolute_expression ();
2259 }
2260
2261 demand_empty_rest_of_line ();
2262 }
2263
2264 /* Change to a different csect. */
2265
2266 static void
2267 ppc_change_csect (sym)
2268 symbolS *sym;
2269 {
2270 if (S_IS_DEFINED (sym))
2271 subseg_set (S_GET_SEGMENT (sym), sym->sy_tc.subseg);
2272 else
2273 {
2274 symbolS **list_ptr;
2275 int after_toc;
2276 symbolS *list;
2277
2278 /* This is a new csect. We need to look at the symbol class to
2279 figure out whether it should go in the text section or the
2280 data section. */
2281 after_toc = 0;
2282 switch (sym->sy_tc.class)
2283 {
2284 case XMC_PR:
2285 case XMC_RO:
2286 case XMC_DB:
2287 case XMC_GL:
2288 case XMC_XO:
2289 case XMC_SV:
2290 case XMC_TI:
2291 case XMC_TB:
2292 S_SET_SEGMENT (sym, text_section);
2293 sym->sy_tc.subseg = ppc_text_subsegment;
2294 ++ppc_text_subsegment;
2295 list_ptr = &ppc_text_csects;
2296 break;
2297 case XMC_RW:
2298 case XMC_TC0:
2299 case XMC_TC:
2300 case XMC_DS:
2301 case XMC_UA:
2302 case XMC_BS:
2303 case XMC_UC:
2304 if (ppc_toc_csect != NULL
2305 && ppc_toc_csect->sy_tc.subseg + 1 == ppc_data_subsegment)
2306 after_toc = 1;
2307 S_SET_SEGMENT (sym, data_section);
2308 sym->sy_tc.subseg = ppc_data_subsegment;
2309 ++ppc_data_subsegment;
2310 list_ptr = &ppc_data_csects;
2311 break;
2312 default:
2313 abort ();
2314 }
2315
2316 subseg_new (segment_name (S_GET_SEGMENT (sym)), sym->sy_tc.subseg);
2317 if (after_toc)
2318 ppc_after_toc_frag = frag_now;
2319
2320 sym->sy_frag = frag_now;
2321 S_SET_VALUE (sym, (valueT) frag_now_fix ());
2322
2323 sym->sy_tc.align = 2;
2324 sym->sy_tc.output = 1;
2325 sym->sy_tc.within = sym;
2326
2327 for (list = *list_ptr;
2328 list->sy_tc.next != (symbolS *) NULL;
2329 list = list->sy_tc.next)
2330 ;
2331 list->sy_tc.next = sym;
2332
2333 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2334 symbol_append (sym, list->sy_tc.within, &symbol_rootP, &symbol_lastP);
2335 }
2336
2337 ppc_current_csect = sym;
2338 }
2339
2340 /* This function handles the .text and .data pseudo-ops. These
2341 pseudo-ops aren't really used by XCOFF; we implement them for the
2342 convenience of people who aren't used to XCOFF. */
2343
2344 static void
2345 ppc_section (type)
2346 int type;
2347 {
2348 const char *name;
2349 symbolS *sym;
2350
2351 if (type == 't')
2352 name = ".text[PR]";
2353 else if (type == 'd')
2354 name = ".data[RW]";
2355 else
2356 abort ();
2357
2358 sym = symbol_find_or_make (name);
2359
2360 ppc_change_csect (sym);
2361
2362 demand_empty_rest_of_line ();
2363 }
2364
2365 /* The .extern pseudo-op. We create an undefined symbol. */
2366
2367 static void
2368 ppc_extern (ignore)
2369 int ignore;
2370 {
2371 char *name;
2372 char endc;
2373
2374 name = input_line_pointer;
2375 endc = get_symbol_end ();
2376
2377 (void) symbol_find_or_make (name);
2378
2379 *input_line_pointer = endc;
2380
2381 demand_empty_rest_of_line ();
2382 }
2383
2384 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
2385
2386 static void
2387 ppc_lglobl (ignore)
2388 int ignore;
2389 {
2390 char *name;
2391 char endc;
2392 symbolS *sym;
2393
2394 name = input_line_pointer;
2395 endc = get_symbol_end ();
2396
2397 sym = symbol_find_or_make (name);
2398
2399 *input_line_pointer = endc;
2400
2401 sym->sy_tc.output = 1;
2402
2403 demand_empty_rest_of_line ();
2404 }
2405
2406 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2407 although I don't know why it bothers. */
2408
2409 static void
2410 ppc_rename (ignore)
2411 int ignore;
2412 {
2413 char *name;
2414 char endc;
2415 symbolS *sym;
2416 int len;
2417
2418 name = input_line_pointer;
2419 endc = get_symbol_end ();
2420
2421 sym = symbol_find_or_make (name);
2422
2423 *input_line_pointer = endc;
2424
2425 if (*input_line_pointer != ',')
2426 {
2427 as_bad ("missing rename string");
2428 ignore_rest_of_line ();
2429 return;
2430 }
2431 ++input_line_pointer;
2432
2433 sym->sy_tc.real_name = demand_copy_C_string (&len);
2434
2435 demand_empty_rest_of_line ();
2436 }
2437
2438 /* The .stabx pseudo-op. This is similar to a normal .stabs
2439 pseudo-op, but slightly different. A sample is
2440 .stabx "main:F-1",.main,142,0
2441 The first argument is the symbol name to create. The second is the
2442 value, and the third is the storage class. The fourth seems to be
2443 always zero, and I am assuming it is the type. */
2444
2445 static void
2446 ppc_stabx (ignore)
2447 int ignore;
2448 {
2449 char *name;
2450 int len;
2451 symbolS *sym;
2452 expressionS exp;
2453
2454 name = demand_copy_C_string (&len);
2455
2456 if (*input_line_pointer != ',')
2457 {
2458 as_bad ("missing value");
2459 return;
2460 }
2461 ++input_line_pointer;
2462
2463 ppc_stab_symbol = true;
2464 sym = symbol_make (name);
2465 ppc_stab_symbol = false;
2466
2467 sym->sy_tc.real_name = name;
2468
2469 (void) expression (&exp);
2470
2471 switch (exp.X_op)
2472 {
2473 case O_illegal:
2474 case O_absent:
2475 case O_big:
2476 as_bad ("illegal .stabx expression; zero assumed");
2477 exp.X_add_number = 0;
2478 /* Fall through. */
2479 case O_constant:
2480 S_SET_VALUE (sym, (valueT) exp.X_add_number);
2481 sym->sy_frag = &zero_address_frag;
2482 break;
2483
2484 case O_symbol:
2485 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section)
2486 sym->sy_value = exp;
2487 else
2488 {
2489 S_SET_VALUE (sym,
2490 exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
2491 sym->sy_frag = exp.X_add_symbol->sy_frag;
2492 }
2493 break;
2494
2495 default:
2496 /* The value is some complex expression. This will probably
2497 fail at some later point, but this is probably the right
2498 thing to do here. */
2499 sym->sy_value = exp;
2500 break;
2501 }
2502
2503 S_SET_SEGMENT (sym, ppc_coff_debug_section);
2504 sym->bsym->flags |= BSF_DEBUGGING;
2505
2506 if (*input_line_pointer != ',')
2507 {
2508 as_bad ("missing class");
2509 return;
2510 }
2511 ++input_line_pointer;
2512
2513 S_SET_STORAGE_CLASS (sym, get_absolute_expression ());
2514
2515 if (*input_line_pointer != ',')
2516 {
2517 as_bad ("missing type");
2518 return;
2519 }
2520 ++input_line_pointer;
2521
2522 S_SET_DATA_TYPE (sym, get_absolute_expression ());
2523
2524 sym->sy_tc.output = 1;
2525
2526 if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
2527 sym->sy_tc.within = ppc_current_block;
2528
2529 if (exp.X_op != O_symbol
2530 || ! S_IS_EXTERNAL (exp.X_add_symbol)
2531 || S_GET_SEGMENT (exp.X_add_symbol) != bss_section)
2532 ppc_frob_label (sym);
2533 else
2534 {
2535 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2536 symbol_append (sym, exp.X_add_symbol, &symbol_rootP, &symbol_lastP);
2537 if (ppc_current_csect->sy_tc.within == exp.X_add_symbol)
2538 ppc_current_csect->sy_tc.within = sym;
2539 }
2540
2541 demand_empty_rest_of_line ();
2542 }
2543
2544 /* The .function pseudo-op. This takes several arguments. The first
2545 argument seems to be the external name of the symbol. The second
2546 argment seems to be the label for the start of the function. gcc
2547 uses the same name for both. I have no idea what the third and
2548 fourth arguments are meant to be. The optional fifth argument is
2549 an expression for the size of the function. In COFF this symbol
2550 gets an aux entry like that used for a csect. */
2551
2552 static void
2553 ppc_function (ignore)
2554 int ignore;
2555 {
2556 char *name;
2557 char endc;
2558 char *s;
2559 symbolS *ext_sym;
2560 symbolS *lab_sym;
2561
2562 name = input_line_pointer;
2563 endc = get_symbol_end ();
2564
2565 /* Ignore any [PR] suffix. */
2566 name = ppc_canonicalize_symbol_name (name);
2567 s = strchr (name, '[');
2568 if (s != (char *) NULL
2569 && strcmp (s + 1, "PR]") == 0)
2570 *s = '\0';
2571
2572 ext_sym = symbol_find_or_make (name);
2573
2574 *input_line_pointer = endc;
2575
2576 if (*input_line_pointer != ',')
2577 {
2578 as_bad ("missing symbol name");
2579 ignore_rest_of_line ();
2580 return;
2581 }
2582 ++input_line_pointer;
2583
2584 name = input_line_pointer;
2585 endc = get_symbol_end ();
2586
2587 lab_sym = symbol_find_or_make (name);
2588
2589 *input_line_pointer = endc;
2590
2591 if (ext_sym != lab_sym)
2592 {
2593 ext_sym->sy_value.X_op = O_symbol;
2594 ext_sym->sy_value.X_add_symbol = lab_sym;
2595 ext_sym->sy_value.X_op_symbol = NULL;
2596 ext_sym->sy_value.X_add_number = 0;
2597 }
2598
2599 if (ext_sym->sy_tc.class == -1)
2600 ext_sym->sy_tc.class = XMC_PR;
2601 ext_sym->sy_tc.output = 1;
2602
2603 if (*input_line_pointer == ',')
2604 {
2605 expressionS ignore;
2606
2607 /* Ignore the third argument. */
2608 ++input_line_pointer;
2609 expression (&ignore);
2610 if (*input_line_pointer == ',')
2611 {
2612 /* Ignore the fourth argument. */
2613 ++input_line_pointer;
2614 expression (&ignore);
2615 if (*input_line_pointer == ',')
2616 {
2617 /* The fifth argument is the function size. */
2618 ++input_line_pointer;
2619 ext_sym->sy_tc.size = symbol_new ("L0\001",
2620 absolute_section,
2621 (valueT) 0,
2622 &zero_address_frag);
2623 pseudo_set (ext_sym->sy_tc.size);
2624 }
2625 }
2626 }
2627
2628 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
2629 SF_SET_FUNCTION (ext_sym);
2630 SF_SET_PROCESS (ext_sym);
2631 coff_add_linesym (ext_sym);
2632
2633 demand_empty_rest_of_line ();
2634 }
2635
2636 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
2637 ".bf". */
2638
2639 static void
2640 ppc_bf (ignore)
2641 int ignore;
2642 {
2643 symbolS *sym;
2644
2645 sym = symbol_make (".bf");
2646 S_SET_SEGMENT (sym, text_section);
2647 sym->sy_frag = frag_now;
2648 S_SET_VALUE (sym, frag_now_fix ());
2649 S_SET_STORAGE_CLASS (sym, C_FCN);
2650
2651 coff_line_base = get_absolute_expression ();
2652
2653 S_SET_NUMBER_AUXILIARY (sym, 1);
2654 SA_SET_SYM_LNNO (sym, coff_line_base);
2655
2656 sym->sy_tc.output = 1;
2657
2658 ppc_frob_label (sym);
2659
2660 demand_empty_rest_of_line ();
2661 }
2662
2663 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
2664 ".ef", except that the line number is absolute, not relative to the
2665 most recent ".bf" symbol. */
2666
2667 static void
2668 ppc_ef (ignore)
2669 int ignore;
2670 {
2671 symbolS *sym;
2672
2673 sym = symbol_make (".ef");
2674 S_SET_SEGMENT (sym, text_section);
2675 sym->sy_frag = frag_now;
2676 S_SET_VALUE (sym, frag_now_fix ());
2677 S_SET_STORAGE_CLASS (sym, C_FCN);
2678 S_SET_NUMBER_AUXILIARY (sym, 1);
2679 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
2680 sym->sy_tc.output = 1;
2681
2682 ppc_frob_label (sym);
2683
2684 demand_empty_rest_of_line ();
2685 }
2686
2687 /* The .bi and .ei pseudo-ops. These take a string argument and
2688 generates a C_BINCL or C_EINCL symbol, which goes at the start of
2689 the symbol list. */
2690
2691 static void
2692 ppc_biei (ei)
2693 int ei;
2694 {
2695 char *name;
2696 int len;
2697 symbolS *sym;
2698 symbolS *look;
2699
2700 name = demand_copy_C_string (&len);
2701
2702 /* The value of these symbols is actually file offset. Here we set
2703 the value to the index into the line number entries. In
2704 ppc_frob_symbols we set the fix_line field, which will cause BFD
2705 to do the right thing. */
2706
2707 sym = symbol_make (name);
2708 /* obj-coff.c currently only handles line numbers correctly in the
2709 .text section. */
2710 S_SET_SEGMENT (sym, text_section);
2711 S_SET_VALUE (sym, coff_n_line_nos);
2712 sym->bsym->flags |= BSF_DEBUGGING;
2713
2714 S_SET_STORAGE_CLASS (sym, ei ? C_EINCL : C_BINCL);
2715 sym->sy_tc.output = 1;
2716
2717 for (look = symbol_rootP;
2718 (look != (symbolS *) NULL
2719 && (S_GET_STORAGE_CLASS (look) == C_FILE
2720 || S_GET_STORAGE_CLASS (look) == C_BINCL
2721 || S_GET_STORAGE_CLASS (look) == C_EINCL));
2722 look = symbol_next (look))
2723 ;
2724 if (look != (symbolS *) NULL)
2725 {
2726 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2727 symbol_insert (sym, look, &symbol_rootP, &symbol_lastP);
2728 }
2729
2730 demand_empty_rest_of_line ();
2731 }
2732
2733 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
2734 There is one argument, which is a csect symbol. The value of the
2735 .bs symbol is the index of this csect symbol. */
2736
2737 static void
2738 ppc_bs (ignore)
2739 int ignore;
2740 {
2741 char *name;
2742 char endc;
2743 symbolS *csect;
2744 symbolS *sym;
2745
2746 if (ppc_current_block != NULL)
2747 as_bad ("nested .bs blocks");
2748
2749 name = input_line_pointer;
2750 endc = get_symbol_end ();
2751
2752 csect = symbol_find_or_make (name);
2753
2754 *input_line_pointer = endc;
2755
2756 sym = symbol_make (".bs");
2757 S_SET_SEGMENT (sym, now_seg);
2758 S_SET_STORAGE_CLASS (sym, C_BSTAT);
2759 sym->bsym->flags |= BSF_DEBUGGING;
2760 sym->sy_tc.output = 1;
2761
2762 sym->sy_tc.within = csect;
2763
2764 ppc_frob_label (sym);
2765
2766 ppc_current_block = sym;
2767
2768 demand_empty_rest_of_line ();
2769 }
2770
2771 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
2772
2773 static void
2774 ppc_es (ignore)
2775 int ignore;
2776 {
2777 symbolS *sym;
2778
2779 if (ppc_current_block == NULL)
2780 as_bad (".es without preceding .bs");
2781
2782 sym = symbol_make (".es");
2783 S_SET_SEGMENT (sym, now_seg);
2784 S_SET_STORAGE_CLASS (sym, C_ESTAT);
2785 sym->bsym->flags |= BSF_DEBUGGING;
2786 sym->sy_tc.output = 1;
2787
2788 ppc_frob_label (sym);
2789
2790 ppc_current_block = NULL;
2791
2792 demand_empty_rest_of_line ();
2793 }
2794
2795 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
2796 line number. */
2797
2798 static void
2799 ppc_bb (ignore)
2800 int ignore;
2801 {
2802 symbolS *sym;
2803
2804 sym = symbol_make (".bb");
2805 S_SET_SEGMENT (sym, text_section);
2806 sym->sy_frag = frag_now;
2807 S_SET_VALUE (sym, frag_now_fix ());
2808 S_SET_STORAGE_CLASS (sym, C_BLOCK);
2809
2810 S_SET_NUMBER_AUXILIARY (sym, 1);
2811 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
2812
2813 sym->sy_tc.output = 1;
2814
2815 SF_SET_PROCESS (sym);
2816
2817 ppc_frob_label (sym);
2818
2819 demand_empty_rest_of_line ();
2820 }
2821
2822 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
2823 line number. */
2824
2825 static void
2826 ppc_eb (ignore)
2827 int ignore;
2828 {
2829 symbolS *sym;
2830
2831 sym = symbol_make (".eb");
2832 S_SET_SEGMENT (sym, text_section);
2833 sym->sy_frag = frag_now;
2834 S_SET_VALUE (sym, frag_now_fix ());
2835 S_SET_STORAGE_CLASS (sym, C_BLOCK);
2836 S_SET_NUMBER_AUXILIARY (sym, 1);
2837 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
2838 sym->sy_tc.output = 1;
2839
2840 SF_SET_PROCESS (sym);
2841
2842 ppc_frob_label (sym);
2843
2844 demand_empty_rest_of_line ();
2845 }
2846
2847 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
2848 specified name. */
2849
2850 static void
2851 ppc_bc (ignore)
2852 int ignore;
2853 {
2854 char *name;
2855 int len;
2856 symbolS *sym;
2857
2858 name = demand_copy_C_string (&len);
2859 sym = symbol_make (name);
2860 S_SET_SEGMENT (sym, ppc_coff_debug_section);
2861 sym->bsym->flags |= BSF_DEBUGGING;
2862 S_SET_STORAGE_CLASS (sym, C_BCOMM);
2863 S_SET_VALUE (sym, 0);
2864 sym->sy_tc.output = 1;
2865
2866 ppc_frob_label (sym);
2867
2868 demand_empty_rest_of_line ();
2869 }
2870
2871 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
2872
2873 static void
2874 ppc_ec (ignore)
2875 int ignore;
2876 {
2877 symbolS *sym;
2878
2879 sym = symbol_make (".ec");
2880 S_SET_SEGMENT (sym, ppc_coff_debug_section);
2881 sym->bsym->flags |= BSF_DEBUGGING;
2882 S_SET_STORAGE_CLASS (sym, C_ECOMM);
2883 S_SET_VALUE (sym, 0);
2884 sym->sy_tc.output = 1;
2885
2886 ppc_frob_label (sym);
2887
2888 demand_empty_rest_of_line ();
2889 }
2890
2891 /* The .toc pseudo-op. Switch to the .toc subsegment. */
2892
2893 static void
2894 ppc_toc (ignore)
2895 int ignore;
2896 {
2897 if (ppc_toc_csect != (symbolS *) NULL)
2898 subseg_set (data_section, ppc_toc_csect->sy_tc.subseg);
2899 else
2900 {
2901 subsegT subseg;
2902 symbolS *sym;
2903 symbolS *list;
2904
2905 subseg = ppc_data_subsegment;
2906 ++ppc_data_subsegment;
2907
2908 subseg_new (segment_name (data_section), subseg);
2909 ppc_toc_frag = frag_now;
2910
2911 sym = symbol_find_or_make ("TOC[TC0]");
2912 sym->sy_frag = frag_now;
2913 S_SET_SEGMENT (sym, data_section);
2914 S_SET_VALUE (sym, (valueT) frag_now_fix ());
2915 sym->sy_tc.subseg = subseg;
2916 sym->sy_tc.output = 1;
2917 sym->sy_tc.within = sym;
2918
2919 ppc_toc_csect = sym;
2920
2921 for (list = ppc_data_csects;
2922 list->sy_tc.next != (symbolS *) NULL;
2923 list = list->sy_tc.next)
2924 ;
2925 list->sy_tc.next = sym;
2926
2927 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2928 symbol_append (sym, list->sy_tc.within, &symbol_rootP, &symbol_lastP);
2929 }
2930
2931 ppc_current_csect = ppc_toc_csect;
2932
2933 demand_empty_rest_of_line ();
2934 }
2935
2936 #endif /* OBJ_XCOFF */
2937 \f
2938 /* The .tc pseudo-op. This is used when generating either XCOFF or
2939 ELF. This takes two or more arguments.
2940
2941 When generating XCOFF output, the first argument is the name to
2942 give to this location in the toc; this will be a symbol with class
2943 TC. The rest of the arguments are 4 byte values to actually put at
2944 this location in the TOC; often there is just one more argument, a
2945 relocateable symbol reference.
2946
2947 When not generating XCOFF output, the arguments are the same, but
2948 the first argument is simply ignored. */
2949
2950 static void
2951 ppc_tc (ignore)
2952 int ignore;
2953 {
2954 #ifdef OBJ_XCOFF
2955
2956 /* Define the TOC symbol name. */
2957 {
2958 char *name;
2959 char endc;
2960 symbolS *sym;
2961
2962 if (ppc_toc_csect == (symbolS *) NULL
2963 || ppc_toc_csect != ppc_current_csect)
2964 {
2965 as_bad (".tc not in .toc section");
2966 ignore_rest_of_line ();
2967 return;
2968 }
2969
2970 name = input_line_pointer;
2971 endc = get_symbol_end ();
2972
2973 sym = symbol_find_or_make (name);
2974
2975 *input_line_pointer = endc;
2976
2977 if (S_IS_DEFINED (sym))
2978 {
2979 symbolS *label;
2980
2981 label = ppc_current_csect->sy_tc.within;
2982 if (label->sy_tc.class != XMC_TC0)
2983 {
2984 as_warn (".tc with no label");
2985 ignore_rest_of_line ();
2986 return;
2987 }
2988
2989 S_SET_SEGMENT (label, S_GET_SEGMENT (sym));
2990 label->sy_frag = sym->sy_frag;
2991 S_SET_VALUE (label, S_GET_VALUE (sym));
2992
2993 while (! is_end_of_line[(unsigned char) *input_line_pointer])
2994 ++input_line_pointer;
2995
2996 return;
2997 }
2998
2999 S_SET_SEGMENT (sym, now_seg);
3000 sym->sy_frag = frag_now;
3001 S_SET_VALUE (sym, (valueT) frag_now_fix ());
3002 sym->sy_tc.class = XMC_TC;
3003 sym->sy_tc.output = 1;
3004
3005 ppc_frob_label (sym);
3006 }
3007
3008 #else /* ! defined (OBJ_XCOFF) */
3009
3010 /* Skip the TOC symbol name. */
3011 while (is_part_of_name (*input_line_pointer)
3012 || *input_line_pointer == '['
3013 || *input_line_pointer == ']'
3014 || *input_line_pointer == '{'
3015 || *input_line_pointer == '}')
3016 ++input_line_pointer;
3017
3018 /* Align to a four byte boundary. */
3019 frag_align (2, 0);
3020 record_alignment (now_seg, 2);
3021
3022 #endif /* ! defined (OBJ_XCOFF) */
3023
3024 if (*input_line_pointer != ',')
3025 demand_empty_rest_of_line ();
3026 else
3027 {
3028 ++input_line_pointer;
3029 cons (4);
3030 }
3031 }
3032 \f
3033 #ifdef TE_PE
3034
3035 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
3036
3037 /* Set the current section. */
3038 static void
3039 ppc_set_current_section (new)
3040 segT new;
3041 {
3042 ppc_previous_section = ppc_current_section;
3043 ppc_current_section = new;
3044 }
3045
3046 /* pseudo-op: .previous
3047 behaviour: toggles the current section with the previous section.
3048 errors: None
3049 warnings: "No previous section"
3050 */
3051 static void
3052 ppc_previous(ignore)
3053 int ignore;
3054 {
3055 symbolS *tmp;
3056
3057 if (ppc_previous_section == NULL)
3058 {
3059 as_warn("No previous section to return to. Directive ignored.");
3060 return;
3061 }
3062
3063 subseg_set(ppc_previous_section, 0);
3064
3065 ppc_set_current_section(ppc_previous_section);
3066 }
3067
3068 /* pseudo-op: .pdata
3069 behaviour: predefined read only data section
3070 double word aligned
3071 errors: None
3072 warnings: None
3073 initial: .section .pdata "adr3"
3074 a - don't know -- maybe a misprint
3075 d - initialized data
3076 r - readable
3077 3 - double word aligned (that would be 4 byte boundary)
3078
3079 commentary:
3080 Tag index tables (also known as the function table) for exception
3081 handling, debugging, etc.
3082
3083 */
3084 static void
3085 ppc_pdata(ignore)
3086 int ignore;
3087 {
3088 if (pdata_section == 0)
3089 {
3090 pdata_section = subseg_new (".pdata", 0);
3091
3092 bfd_set_section_flags (stdoutput, pdata_section,
3093 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3094 | SEC_READONLY | SEC_DATA ));
3095
3096 bfd_set_section_alignment (stdoutput, pdata_section, 2);
3097 }
3098 else
3099 {
3100 pdata_section = subseg_new(".pdata", 0);
3101 }
3102 ppc_set_current_section(pdata_section);
3103 }
3104
3105 /* pseudo-op: .ydata
3106 behaviour: predefined read only data section
3107 double word aligned
3108 errors: None
3109 warnings: None
3110 initial: .section .ydata "drw3"
3111 a - don't know -- maybe a misprint
3112 d - initialized data
3113 r - readable
3114 3 - double word aligned (that would be 4 byte boundary)
3115 commentary:
3116 Tag tables (also known as the scope table) for exception handling,
3117 debugging, etc.
3118 */
3119 static void
3120 ppc_ydata(ignore)
3121 int ignore;
3122 {
3123 if (ydata_section == 0)
3124 {
3125 ydata_section = subseg_new (".ydata", 0);
3126 bfd_set_section_flags (stdoutput, ydata_section,
3127 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3128 | SEC_READONLY | SEC_DATA ));
3129
3130 bfd_set_section_alignment (stdoutput, ydata_section, 3);
3131 }
3132 else
3133 {
3134 ydata_section = subseg_new (".ydata", 0);
3135 }
3136 ppc_set_current_section(ydata_section);
3137 }
3138
3139 /* pseudo-op: .reldata
3140 behaviour: predefined read write data section
3141 double word aligned (4-byte)
3142 FIXME: relocation is applied to it
3143 FIXME: what's the difference between this and .data?
3144 errors: None
3145 warnings: None
3146 initial: .section .reldata "drw3"
3147 d - initialized data
3148 r - readable
3149 w - writeable
3150 3 - double word aligned (that would be 8 byte boundary)
3151
3152 commentary:
3153 Like .data, but intended to hold data subject to relocation, such as
3154 function descriptors, etc.
3155 */
3156 static void
3157 ppc_reldata(ignore)
3158 int ignore;
3159 {
3160 if (reldata_section == 0)
3161 {
3162 reldata_section = subseg_new (".reldata", 0);
3163
3164 bfd_set_section_flags (stdoutput, reldata_section,
3165 ( SEC_ALLOC | SEC_LOAD | SEC_RELOC
3166 | SEC_DATA ));
3167
3168 bfd_set_section_alignment (stdoutput, reldata_section, 2);
3169 }
3170 else
3171 {
3172 reldata_section = subseg_new (".reldata", 0);
3173 }
3174 ppc_set_current_section(reldata_section);
3175 }
3176
3177 /* pseudo-op: .rdata
3178 behaviour: predefined read only data section
3179 double word aligned
3180 errors: None
3181 warnings: None
3182 initial: .section .rdata "dr3"
3183 d - initialized data
3184 r - readable
3185 3 - double word aligned (that would be 4 byte boundary)
3186 */
3187 static void
3188 ppc_rdata(ignore)
3189 int ignore;
3190 {
3191 if (rdata_section == 0)
3192 {
3193 rdata_section = subseg_new (".rdata", 0);
3194 bfd_set_section_flags (stdoutput, rdata_section,
3195 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3196 | SEC_READONLY | SEC_DATA ));
3197
3198 bfd_set_section_alignment (stdoutput, rdata_section, 2);
3199 }
3200 else
3201 {
3202 rdata_section = subseg_new (".rdata", 0);
3203 }
3204 ppc_set_current_section(rdata_section);
3205 }
3206
3207 /* pseudo-op: .ualong
3208 behaviour: much like .int, with the exception that no alignment is
3209 performed.
3210 FIXME: test the alignment statement
3211 errors: None
3212 warnings: None
3213 */
3214 static void
3215 ppc_ualong(ignore)
3216 int ignore;
3217 {
3218 /* try for long */
3219 cons ( 4 );
3220 }
3221
3222 /* pseudo-op: .znop <symbol name>
3223 behaviour: Issue a nop instruction
3224 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
3225 the supplied symbol name.
3226 errors: None
3227 warnings: Missing symbol name
3228 */
3229 static void
3230 ppc_znop(ignore)
3231 int ignore;
3232 {
3233 unsigned long insn;
3234 const struct powerpc_opcode *opcode;
3235 expressionS ex;
3236 char *f;
3237
3238 symbolS *sym;
3239
3240 /* Strip out the symbol name */
3241 char *symbol_name;
3242 char c;
3243 char *name;
3244 unsigned int exp;
3245 flagword flags;
3246 asection *sec;
3247
3248 symbol_name = input_line_pointer;
3249 c = get_symbol_end ();
3250
3251 name = xmalloc (input_line_pointer - symbol_name + 1);
3252 strcpy (name, symbol_name);
3253
3254 sym = symbol_find_or_make (name);
3255
3256 *input_line_pointer = c;
3257
3258 SKIP_WHITESPACE ();
3259
3260 /* Look up the opcode in the hash table. */
3261 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, "nop");
3262
3263 /* stick in the nop */
3264 insn = opcode->opcode;
3265
3266 /* Write out the instruction. */
3267 f = frag_more (4);
3268 md_number_to_chars (f, insn, 4);
3269 fix_new (frag_now,
3270 f - frag_now->fr_literal,
3271 4,
3272 sym,
3273 0,
3274 0,
3275 BFD_RELOC_16_GOT_PCREL);
3276
3277 }
3278
3279 /* pseudo-op:
3280 behaviour:
3281 errors:
3282 warnings:
3283 */
3284 static void
3285 ppc_pe_comm(lcomm)
3286 int lcomm;
3287 {
3288 register char *name;
3289 register char c;
3290 register char *p;
3291 offsetT temp;
3292 register symbolS *symbolP;
3293 offsetT align;
3294
3295 name = input_line_pointer;
3296 c = get_symbol_end ();
3297
3298 /* just after name is now '\0' */
3299 p = input_line_pointer;
3300 *p = c;
3301 SKIP_WHITESPACE ();
3302 if (*input_line_pointer != ',')
3303 {
3304 as_bad ("Expected comma after symbol-name: rest of line ignored.");
3305 ignore_rest_of_line ();
3306 return;
3307 }
3308
3309 input_line_pointer++; /* skip ',' */
3310 if ((temp = get_absolute_expression ()) < 0)
3311 {
3312 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp);
3313 ignore_rest_of_line ();
3314 return;
3315 }
3316
3317 if (! lcomm)
3318 {
3319 /* The third argument to .comm is the alignment. */
3320 if (*input_line_pointer != ',')
3321 align = 3;
3322 else
3323 {
3324 ++input_line_pointer;
3325 align = get_absolute_expression ();
3326 if (align <= 0)
3327 {
3328 as_warn ("ignoring bad alignment");
3329 align = 3;
3330 }
3331 }
3332 }
3333
3334 *p = 0;
3335 symbolP = symbol_find_or_make (name);
3336
3337 *p = c;
3338 if (S_IS_DEFINED (symbolP))
3339 {
3340 as_bad ("Ignoring attempt to re-define symbol `%s'.",
3341 S_GET_NAME (symbolP));
3342 ignore_rest_of_line ();
3343 return;
3344 }
3345
3346 if (S_GET_VALUE (symbolP))
3347 {
3348 if (S_GET_VALUE (symbolP) != (valueT) temp)
3349 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
3350 S_GET_NAME (symbolP),
3351 (long) S_GET_VALUE (symbolP),
3352 (long) temp);
3353 }
3354 else
3355 {
3356 S_SET_VALUE (symbolP, (valueT) temp);
3357 S_SET_EXTERNAL (symbolP);
3358 }
3359
3360 demand_empty_rest_of_line ();
3361 }
3362
3363 /*
3364 * implement the .section pseudo op:
3365 * .section name {, "flags"}
3366 * ^ ^
3367 * | +--- optional flags: 'b' for bss
3368 * | 'i' for info
3369 * +-- section name 'l' for lib
3370 * 'n' for noload
3371 * 'o' for over
3372 * 'w' for data
3373 * 'd' (apparently m88k for data)
3374 * 'x' for text
3375 * But if the argument is not a quoted string, treat it as a
3376 * subsegment number.
3377 *
3378 * FIXME: this is a copy of the section processing from obj-coff.c, with
3379 * additions/changes for the moto-pas assembler support. There are three
3380 * categories:
3381 *
3382 * FIXME: I just noticed this. This doesn't work at all really. It it
3383 * setting bits that bfd probably neither understands or uses. The
3384 * correct approach (?) will have to incorporate extra fields attached
3385 * to the section to hold the system specific stuff. (krk)
3386 *
3387 * Section Contents:
3388 * 'a' - unknown - referred to in documentation, but no definition supplied
3389 * 'c' - section has code
3390 * 'd' - section has initialized data
3391 * 'u' - section has uninitialized data
3392 * 'i' - section contains directives (info)
3393 * 'n' - section can be discarded
3394 * 'R' - remove section at link time
3395 *
3396 * Section Protection:
3397 * 'r' - section is readable
3398 * 'w' - section is writeable
3399 * 'x' - section is executable
3400 * 's' - section is sharable
3401 *
3402 * Section Alignment:
3403 * '0' - align to byte boundary
3404 * '1' - align to halfword undary
3405 * '2' - align to word boundary
3406 * '3' - align to doubleword boundary
3407 * '4' - align to quadword boundary
3408 * '5' - align to 32 byte boundary
3409 * '6' - align to 64 byte boundary
3410 *
3411 */
3412
3413 void
3414 ppc_pe_section (ignore)
3415 int ignore;
3416 {
3417 /* Strip out the section name */
3418 char *section_name;
3419 char c;
3420 char *name;
3421 unsigned int exp;
3422 flagword flags;
3423 segT sec;
3424 int align;
3425
3426 section_name = input_line_pointer;
3427 c = get_symbol_end ();
3428
3429 name = xmalloc (input_line_pointer - section_name + 1);
3430 strcpy (name, section_name);
3431
3432 *input_line_pointer = c;
3433
3434 SKIP_WHITESPACE ();
3435
3436 exp = 0;
3437 flags = SEC_NO_FLAGS;
3438
3439 if (strcmp (name, ".idata$2") == 0)
3440 {
3441 align = 0;
3442 }
3443 else if (strcmp (name, ".idata$3") == 0)
3444 {
3445 align = 0;
3446 }
3447 else if (strcmp (name, ".idata$4") == 0)
3448 {
3449 align = 2;
3450 }
3451 else if (strcmp (name, ".idata$5") == 0)
3452 {
3453 align = 2;
3454 }
3455 else if (strcmp (name, ".idata$6") == 0)
3456 {
3457 align = 1;
3458 }
3459 else
3460 align = 4; /* default alignment to 16 byte boundary */
3461
3462 if (*input_line_pointer == ',')
3463 {
3464 ++input_line_pointer;
3465 SKIP_WHITESPACE ();
3466 if (*input_line_pointer != '"')
3467 exp = get_absolute_expression ();
3468 else
3469 {
3470 ++input_line_pointer;
3471 while (*input_line_pointer != '"'
3472 && ! is_end_of_line[(unsigned char) *input_line_pointer])
3473 {
3474 switch (*input_line_pointer)
3475 {
3476 /* Section Contents */
3477 case 'a': /* unknown */
3478 as_warn ("Unsupported section attribute -- 'a'");
3479 break;
3480 case 'c': /* code section */
3481 flags |= SEC_CODE;
3482 break;
3483 case 'd': /* section has initialized data */
3484 flags |= SEC_DATA;
3485 break;
3486 case 'u': /* section has uninitialized data */
3487 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
3488 in winnt.h */
3489 flags |= SEC_ROM;
3490 break;
3491 case 'i': /* section contains directives (info) */
3492 /* FIXME: This is IMAGE_SCN_LNK_INFO
3493 in winnt.h */
3494 flags |= SEC_HAS_CONTENTS;
3495 break;
3496 case 'n': /* section can be discarded */
3497 flags &=~ SEC_LOAD;
3498 break;
3499 case 'R': /* Remove section at link time */
3500 flags |= SEC_NEVER_LOAD;
3501 break;
3502
3503 /* Section Protection */
3504 case 'r': /* section is readable */
3505 flags |= IMAGE_SCN_MEM_READ;
3506 break;
3507 case 'w': /* section is writeable */
3508 flags |= IMAGE_SCN_MEM_WRITE;
3509 break;
3510 case 'x': /* section is executable */
3511 flags |= IMAGE_SCN_MEM_EXECUTE;
3512 break;
3513 case 's': /* section is sharable */
3514 flags |= IMAGE_SCN_MEM_SHARED;
3515 break;
3516
3517 /* Section Alignment */
3518 case '0': /* align to byte boundary */
3519 flags |= IMAGE_SCN_ALIGN_1BYTES;
3520 align = 0;
3521 break;
3522 case '1': /* align to halfword boundary */
3523 flags |= IMAGE_SCN_ALIGN_2BYTES;
3524 align = 1;
3525 break;
3526 case '2': /* align to word boundary */
3527 flags |= IMAGE_SCN_ALIGN_4BYTES;
3528 align = 2;
3529 break;
3530 case '3': /* align to doubleword boundary */
3531 flags |= IMAGE_SCN_ALIGN_8BYTES;
3532 align = 3;
3533 break;
3534 case '4': /* align to quadword boundary */
3535 flags |= IMAGE_SCN_ALIGN_16BYTES;
3536 align = 4;
3537 break;
3538 case '5': /* align to 32 byte boundary */
3539 flags |= IMAGE_SCN_ALIGN_32BYTES;
3540 align = 5;
3541 break;
3542 case '6': /* align to 64 byte boundary */
3543 flags |= IMAGE_SCN_ALIGN_64BYTES;
3544 align = 6;
3545 break;
3546
3547 default:
3548 as_warn("unknown section attribute '%c'",
3549 *input_line_pointer);
3550 break;
3551 }
3552 ++input_line_pointer;
3553 }
3554 if (*input_line_pointer == '"')
3555 ++input_line_pointer;
3556 }
3557 }
3558
3559 sec = subseg_new (name, (subsegT) exp);
3560
3561 ppc_set_current_section(sec);
3562
3563 if (flags != SEC_NO_FLAGS)
3564 {
3565 if (! bfd_set_section_flags (stdoutput, sec, flags))
3566 as_warn ("error setting flags for \"%s\": %s",
3567 bfd_section_name (stdoutput, sec),
3568 bfd_errmsg (bfd_get_error ()));
3569 }
3570
3571 bfd_set_section_alignment(stdoutput, sec, align);
3572
3573 }
3574
3575 static void
3576 ppc_pe_function (ignore)
3577 int ignore;
3578 {
3579 char *name;
3580 char endc;
3581 symbolS *ext_sym;
3582
3583 name = input_line_pointer;
3584 endc = get_symbol_end ();
3585
3586 ext_sym = symbol_find_or_make (name);
3587
3588 *input_line_pointer = endc;
3589
3590 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
3591 SF_SET_FUNCTION (ext_sym);
3592 SF_SET_PROCESS (ext_sym);
3593 coff_add_linesym (ext_sym);
3594
3595 demand_empty_rest_of_line ();
3596 }
3597
3598 static void
3599 ppc_pe_tocd (ignore)
3600 int ignore;
3601 {
3602 if (tocdata_section == 0)
3603 {
3604 tocdata_section = subseg_new (".tocd", 0);
3605 /* FIXME: section flags won't work */
3606 bfd_set_section_flags (stdoutput, tocdata_section,
3607 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3608 | SEC_READONLY | SEC_DATA ));
3609
3610 bfd_set_section_alignment (stdoutput, tocdata_section, 2);
3611 }
3612 else
3613 {
3614 rdata_section = subseg_new (".tocd", 0);
3615 }
3616
3617 ppc_set_current_section(tocdata_section);
3618
3619 demand_empty_rest_of_line ();
3620 }
3621
3622 /* Don't adjust TOC relocs to use the section symbol. */
3623
3624 int
3625 ppc_pe_fix_adjustable (fix)
3626 fixS *fix;
3627 {
3628 return fix->fx_r_type != BFD_RELOC_PPC_TOC16;
3629 }
3630
3631 #endif
3632 \f
3633 #ifdef OBJ_XCOFF
3634
3635 /* XCOFF specific symbol and file handling. */
3636
3637 /* Canonicalize the symbol name. We use the to force the suffix, if
3638 any, to use square brackets, and to be in upper case. */
3639
3640 char *
3641 ppc_canonicalize_symbol_name (name)
3642 char *name;
3643 {
3644 char *s;
3645
3646 if (ppc_stab_symbol)
3647 return name;
3648
3649 for (s = name; *s != '\0' && *s != '{' && *s != '['; s++)
3650 ;
3651 if (*s != '\0')
3652 {
3653 char brac;
3654
3655 if (*s == '[')
3656 brac = ']';
3657 else
3658 {
3659 *s = '[';
3660 brac = '}';
3661 }
3662
3663 for (s++; *s != '\0' && *s != brac; s++)
3664 if (islower (*s))
3665 *s = toupper (*s);
3666
3667 if (*s == '\0' || s[1] != '\0')
3668 as_bad ("bad symbol suffix");
3669
3670 *s = ']';
3671 }
3672
3673 return name;
3674 }
3675
3676 /* Set the class of a symbol based on the suffix, if any. This is
3677 called whenever a new symbol is created. */
3678
3679 void
3680 ppc_symbol_new_hook (sym)
3681 symbolS *sym;
3682 {
3683 const char *s;
3684
3685 sym->sy_tc.next = NULL;
3686 sym->sy_tc.output = 0;
3687 sym->sy_tc.class = -1;
3688 sym->sy_tc.real_name = NULL;
3689 sym->sy_tc.subseg = 0;
3690 sym->sy_tc.align = 0;
3691 sym->sy_tc.size = NULL;
3692 sym->sy_tc.within = NULL;
3693
3694 if (ppc_stab_symbol)
3695 return;
3696
3697 s = strchr (S_GET_NAME (sym), '[');
3698 if (s == (const char *) NULL)
3699 {
3700 /* There is no suffix. */
3701 return;
3702 }
3703
3704 ++s;
3705
3706 switch (s[0])
3707 {
3708 case 'B':
3709 if (strcmp (s, "BS]") == 0)
3710 sym->sy_tc.class = XMC_BS;
3711 break;
3712 case 'D':
3713 if (strcmp (s, "DB]") == 0)
3714 sym->sy_tc.class = XMC_DB;
3715 else if (strcmp (s, "DS]") == 0)
3716 sym->sy_tc.class = XMC_DS;
3717 break;
3718 case 'G':
3719 if (strcmp (s, "GL]") == 0)
3720 sym->sy_tc.class = XMC_GL;
3721 break;
3722 case 'P':
3723 if (strcmp (s, "PR]") == 0)
3724 sym->sy_tc.class = XMC_PR;
3725 break;
3726 case 'R':
3727 if (strcmp (s, "RO]") == 0)
3728 sym->sy_tc.class = XMC_RO;
3729 else if (strcmp (s, "RW]") == 0)
3730 sym->sy_tc.class = XMC_RW;
3731 break;
3732 case 'S':
3733 if (strcmp (s, "SV]") == 0)
3734 sym->sy_tc.class = XMC_SV;
3735 break;
3736 case 'T':
3737 if (strcmp (s, "TC]") == 0)
3738 sym->sy_tc.class = XMC_TC;
3739 else if (strcmp (s, "TI]") == 0)
3740 sym->sy_tc.class = XMC_TI;
3741 else if (strcmp (s, "TB]") == 0)
3742 sym->sy_tc.class = XMC_TB;
3743 else if (strcmp (s, "TC0]") == 0 || strcmp (s, "T0]") == 0)
3744 sym->sy_tc.class = XMC_TC0;
3745 break;
3746 case 'U':
3747 if (strcmp (s, "UA]") == 0)
3748 sym->sy_tc.class = XMC_UA;
3749 else if (strcmp (s, "UC]") == 0)
3750 sym->sy_tc.class = XMC_UC;
3751 break;
3752 case 'X':
3753 if (strcmp (s, "XO]") == 0)
3754 sym->sy_tc.class = XMC_XO;
3755 break;
3756 }
3757
3758 if (sym->sy_tc.class == -1)
3759 as_bad ("Unrecognized symbol suffix");
3760 }
3761
3762 /* Set the class of a label based on where it is defined. This
3763 handles symbols without suffixes. Also, move the symbol so that it
3764 follows the csect symbol. */
3765
3766 void
3767 ppc_frob_label (sym)
3768 symbolS *sym;
3769 {
3770 if (ppc_current_csect != (symbolS *) NULL)
3771 {
3772 if (sym->sy_tc.class == -1)
3773 sym->sy_tc.class = ppc_current_csect->sy_tc.class;
3774
3775 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3776 symbol_append (sym, ppc_current_csect->sy_tc.within, &symbol_rootP,
3777 &symbol_lastP);
3778 ppc_current_csect->sy_tc.within = sym;
3779 }
3780 }
3781
3782 /* This variable is set by ppc_frob_symbol if any absolute symbols are
3783 seen. It tells ppc_adjust_symtab whether it needs to look through
3784 the symbols. */
3785
3786 static boolean ppc_saw_abs;
3787
3788 /* Change the name of a symbol just before writing it out. Set the
3789 real name if the .rename pseudo-op was used. Otherwise, remove any
3790 class suffix. Return 1 if the symbol should not be included in the
3791 symbol table. */
3792
3793 int
3794 ppc_frob_symbol (sym)
3795 symbolS *sym;
3796 {
3797 static symbolS *ppc_last_function;
3798 static symbolS *set_end;
3799
3800 /* Discard symbols that should not be included in the output symbol
3801 table. */
3802 if (! sym->sy_used_in_reloc
3803 && ((sym->bsym->flags & BSF_SECTION_SYM) != 0
3804 || (! S_IS_EXTERNAL (sym)
3805 && ! sym->sy_tc.output
3806 && S_GET_STORAGE_CLASS (sym) != C_FILE)))
3807 return 1;
3808
3809 if (sym->sy_tc.real_name != (char *) NULL)
3810 S_SET_NAME (sym, sym->sy_tc.real_name);
3811 else
3812 {
3813 const char *name;
3814 const char *s;
3815
3816 name = S_GET_NAME (sym);
3817 s = strchr (name, '[');
3818 if (s != (char *) NULL)
3819 {
3820 unsigned int len;
3821 char *snew;
3822
3823 len = s - name;
3824 snew = xmalloc (len + 1);
3825 memcpy (snew, name, len);
3826 snew[len] = '\0';
3827
3828 S_SET_NAME (sym, snew);
3829 }
3830 }
3831
3832 if (set_end != (symbolS *) NULL)
3833 {
3834 SA_SET_SYM_ENDNDX (set_end, sym);
3835 set_end = NULL;
3836 }
3837
3838 if (SF_GET_FUNCTION (sym))
3839 {
3840 if (ppc_last_function != (symbolS *) NULL)
3841 as_warn ("two .function pseudo-ops with no intervening .ef");
3842 ppc_last_function = sym;
3843 if (sym->sy_tc.size != (symbolS *) NULL)
3844 {
3845 resolve_symbol_value (sym->sy_tc.size);
3846 SA_SET_SYM_FSIZE (sym, (long) S_GET_VALUE (sym->sy_tc.size));
3847 }
3848 }
3849 else if (S_GET_STORAGE_CLASS (sym) == C_FCN
3850 && strcmp (S_GET_NAME (sym), ".ef") == 0)
3851 {
3852 if (ppc_last_function == (symbolS *) NULL)
3853 as_warn (".ef with no preceding .function");
3854 else
3855 {
3856 set_end = ppc_last_function;
3857 ppc_last_function = NULL;
3858
3859 /* We don't have a C_EFCN symbol, but we need to force the
3860 COFF backend to believe that it has seen one. */
3861 coff_last_function = NULL;
3862 }
3863 }
3864
3865 if (! S_IS_EXTERNAL (sym)
3866 && (sym->bsym->flags & BSF_SECTION_SYM) == 0
3867 && S_GET_STORAGE_CLASS (sym) != C_FILE
3868 && S_GET_STORAGE_CLASS (sym) != C_FCN
3869 && S_GET_STORAGE_CLASS (sym) != C_BLOCK
3870 && S_GET_STORAGE_CLASS (sym) != C_BSTAT
3871 && S_GET_STORAGE_CLASS (sym) != C_ESTAT
3872 && S_GET_STORAGE_CLASS (sym) != C_BINCL
3873 && S_GET_STORAGE_CLASS (sym) != C_EINCL
3874 && S_GET_SEGMENT (sym) != ppc_coff_debug_section)
3875 S_SET_STORAGE_CLASS (sym, C_HIDEXT);
3876
3877 if (S_GET_STORAGE_CLASS (sym) == C_EXT
3878 || S_GET_STORAGE_CLASS (sym) == C_HIDEXT)
3879 {
3880 int i;
3881 union internal_auxent *a;
3882
3883 /* Create a csect aux. */
3884 i = S_GET_NUMBER_AUXILIARY (sym);
3885 S_SET_NUMBER_AUXILIARY (sym, i + 1);
3886 a = &coffsymbol (sym->bsym)->native[i + 1].u.auxent;
3887 if (sym->sy_tc.class == XMC_TC0)
3888 {
3889 /* This is the TOC table. */
3890 know (strcmp (S_GET_NAME (sym), "TOC") == 0);
3891 a->x_csect.x_scnlen.l = 0;
3892 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
3893 }
3894 else if (sym->sy_tc.subseg != 0)
3895 {
3896 /* This is a csect symbol. x_scnlen is the size of the
3897 csect. */
3898 if (sym->sy_tc.next == (symbolS *) NULL)
3899 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
3900 S_GET_SEGMENT (sym))
3901 - S_GET_VALUE (sym));
3902 else
3903 {
3904 resolve_symbol_value (sym->sy_tc.next);
3905 a->x_csect.x_scnlen.l = (S_GET_VALUE (sym->sy_tc.next)
3906 - S_GET_VALUE (sym));
3907 }
3908 a->x_csect.x_smtyp = (sym->sy_tc.align << 3) | XTY_SD;
3909 }
3910 else if (S_GET_SEGMENT (sym) == bss_section)
3911 {
3912 /* This is a common symbol. */
3913 a->x_csect.x_scnlen.l = sym->sy_frag->fr_offset;
3914 a->x_csect.x_smtyp = (sym->sy_tc.align << 3) | XTY_CM;
3915 if (S_IS_EXTERNAL (sym))
3916 sym->sy_tc.class = XMC_RW;
3917 else
3918 sym->sy_tc.class = XMC_BS;
3919 }
3920 else if (S_GET_SEGMENT (sym) == absolute_section)
3921 {
3922 /* This is an absolute symbol. The csect will be created by
3923 ppc_adjust_symtab. */
3924 ppc_saw_abs = true;
3925 a->x_csect.x_smtyp = XTY_LD;
3926 if (sym->sy_tc.class == -1)
3927 sym->sy_tc.class = XMC_XO;
3928 }
3929 else if (! S_IS_DEFINED (sym))
3930 {
3931 /* This is an external symbol. */
3932 a->x_csect.x_scnlen.l = 0;
3933 a->x_csect.x_smtyp = XTY_ER;
3934 }
3935 else if (sym->sy_tc.class == XMC_TC)
3936 {
3937 symbolS *next;
3938
3939 /* This is a TOC definition. x_scnlen is the size of the
3940 TOC entry. */
3941 next = symbol_next (sym);
3942 while (next->sy_tc.class == XMC_TC0)
3943 next = symbol_next (next);
3944 if (next == (symbolS *) NULL
3945 || next->sy_tc.class != XMC_TC)
3946 {
3947 if (ppc_after_toc_frag == (fragS *) NULL)
3948 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
3949 data_section)
3950 - S_GET_VALUE (sym));
3951 else
3952 a->x_csect.x_scnlen.l = (ppc_after_toc_frag->fr_address
3953 - S_GET_VALUE (sym));
3954 }
3955 else
3956 {
3957 resolve_symbol_value (next);
3958 a->x_csect.x_scnlen.l = (S_GET_VALUE (next)
3959 - S_GET_VALUE (sym));
3960 }
3961 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
3962 }
3963 else
3964 {
3965 symbolS *csect;
3966
3967 /* This is a normal symbol definition. x_scnlen is the
3968 symbol index of the containing csect. */
3969 if (S_GET_SEGMENT (sym) == text_section)
3970 csect = ppc_text_csects;
3971 else if (S_GET_SEGMENT (sym) == data_section)
3972 csect = ppc_data_csects;
3973 else
3974 abort ();
3975
3976 /* Skip the initial dummy symbol. */
3977 csect = csect->sy_tc.next;
3978
3979 if (csect == (symbolS *) NULL)
3980 {
3981 as_warn ("warning: symbol %s has no csect", S_GET_NAME (sym));
3982 a->x_csect.x_scnlen.l = 0;
3983 }
3984 else
3985 {
3986 while (csect->sy_tc.next != (symbolS *) NULL)
3987 {
3988 resolve_symbol_value (csect->sy_tc.next);
3989 if (S_GET_VALUE (csect->sy_tc.next) > S_GET_VALUE (sym))
3990 break;
3991 csect = csect->sy_tc.next;
3992 }
3993
3994 a->x_csect.x_scnlen.p = coffsymbol (csect->bsym)->native;
3995 coffsymbol (sym->bsym)->native[i + 1].fix_scnlen = 1;
3996 }
3997 a->x_csect.x_smtyp = XTY_LD;
3998 }
3999
4000 a->x_csect.x_parmhash = 0;
4001 a->x_csect.x_snhash = 0;
4002 if (sym->sy_tc.class == -1)
4003 a->x_csect.x_smclas = XMC_PR;
4004 else
4005 a->x_csect.x_smclas = sym->sy_tc.class;
4006 a->x_csect.x_stab = 0;
4007 a->x_csect.x_snstab = 0;
4008
4009 /* Don't let the COFF backend resort these symbols. */
4010 sym->bsym->flags |= BSF_NOT_AT_END;
4011 }
4012 else if (S_GET_STORAGE_CLASS (sym) == C_BSTAT)
4013 {
4014 /* We want the value to be the symbol index of the referenced
4015 csect symbol. BFD will do that for us if we set the right
4016 flags. */
4017 S_SET_VALUE (sym,
4018 (valueT) coffsymbol (sym->sy_tc.within->bsym)->native);
4019 coffsymbol (sym->bsym)->native->fix_value = 1;
4020 }
4021 else if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
4022 {
4023 symbolS *block;
4024 symbolS *csect;
4025
4026 /* The value is the offset from the enclosing csect. */
4027 block = sym->sy_tc.within;
4028 csect = block->sy_tc.within;
4029 resolve_symbol_value (csect);
4030 S_SET_VALUE (sym, S_GET_VALUE (sym) - S_GET_VALUE (csect));
4031 }
4032 else if (S_GET_STORAGE_CLASS (sym) == C_BINCL
4033 || S_GET_STORAGE_CLASS (sym) == C_EINCL)
4034 {
4035 /* We want the value to be a file offset into the line numbers.
4036 BFD will do that for us if we set the right flags. We have
4037 already set the value correctly. */
4038 coffsymbol (sym->bsym)->native->fix_line = 1;
4039 }
4040
4041 return 0;
4042 }
4043
4044 /* Adjust the symbol table. This creates csect symbols for all
4045 absolute symbols. */
4046
4047 void
4048 ppc_adjust_symtab ()
4049 {
4050 symbolS *sym;
4051
4052 if (! ppc_saw_abs)
4053 return;
4054
4055 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
4056 {
4057 symbolS *csect;
4058 int i;
4059 union internal_auxent *a;
4060
4061 if (S_GET_SEGMENT (sym) != absolute_section)
4062 continue;
4063
4064 csect = symbol_create (".abs[XO]", absolute_section,
4065 S_GET_VALUE (sym), &zero_address_frag);
4066 csect->bsym->value = S_GET_VALUE (sym);
4067 S_SET_STORAGE_CLASS (csect, C_HIDEXT);
4068 i = S_GET_NUMBER_AUXILIARY (csect);
4069 S_SET_NUMBER_AUXILIARY (csect, i + 1);
4070 a = &coffsymbol (csect->bsym)->native[i + 1].u.auxent;
4071 a->x_csect.x_scnlen.l = 0;
4072 a->x_csect.x_smtyp = XTY_SD;
4073 a->x_csect.x_parmhash = 0;
4074 a->x_csect.x_snhash = 0;
4075 a->x_csect.x_smclas = XMC_XO;
4076 a->x_csect.x_stab = 0;
4077 a->x_csect.x_snstab = 0;
4078
4079 symbol_insert (csect, sym, &symbol_rootP, &symbol_lastP);
4080
4081 i = S_GET_NUMBER_AUXILIARY (sym);
4082 a = &coffsymbol (sym->bsym)->native[i].u.auxent;
4083 a->x_csect.x_scnlen.p = coffsymbol (csect->bsym)->native;
4084 coffsymbol (sym->bsym)->native[i].fix_scnlen = 1;
4085 }
4086
4087 ppc_saw_abs = false;
4088 }
4089
4090 /* Set the VMA for a section. This is called on all the sections in
4091 turn. */
4092
4093 void
4094 ppc_frob_section (sec)
4095 asection *sec;
4096 {
4097 static bfd_size_type vma = 0;
4098
4099 bfd_set_section_vma (stdoutput, sec, vma);
4100 vma += bfd_section_size (stdoutput, sec);
4101 }
4102
4103 #endif /* OBJ_XCOFF */
4104 \f
4105 /* Turn a string in input_line_pointer into a floating point constant
4106 of type type, and store the appropriate bytes in *litp. The number
4107 of LITTLENUMS emitted is stored in *sizep . An error message is
4108 returned, or NULL on OK. */
4109
4110 char *
4111 md_atof (type, litp, sizep)
4112 int type;
4113 char *litp;
4114 int *sizep;
4115 {
4116 int prec;
4117 LITTLENUM_TYPE words[4];
4118 char *t;
4119 int i;
4120
4121 switch (type)
4122 {
4123 case 'f':
4124 prec = 2;
4125 break;
4126
4127 case 'd':
4128 prec = 4;
4129 break;
4130
4131 default:
4132 *sizep = 0;
4133 return "bad call to md_atof";
4134 }
4135
4136 t = atof_ieee (input_line_pointer, type, words);
4137 if (t)
4138 input_line_pointer = t;
4139
4140 *sizep = prec * 2;
4141
4142 if (target_big_endian)
4143 {
4144 for (i = 0; i < prec; i++)
4145 {
4146 md_number_to_chars (litp, (valueT) words[i], 2);
4147 litp += 2;
4148 }
4149 }
4150 else
4151 {
4152 for (i = prec - 1; i >= 0; i--)
4153 {
4154 md_number_to_chars (litp, (valueT) words[i], 2);
4155 litp += 2;
4156 }
4157 }
4158
4159 return NULL;
4160 }
4161
4162 /* Write a value out to the object file, using the appropriate
4163 endianness. */
4164
4165 void
4166 md_number_to_chars (buf, val, n)
4167 char *buf;
4168 valueT val;
4169 int n;
4170 {
4171 if (target_big_endian)
4172 number_to_chars_bigendian (buf, val, n);
4173 else
4174 number_to_chars_littleendian (buf, val, n);
4175 }
4176
4177 /* Align a section (I don't know why this is machine dependent). */
4178
4179 valueT
4180 md_section_align (seg, addr)
4181 asection *seg;
4182 valueT addr;
4183 {
4184 int align = bfd_get_section_alignment (stdoutput, seg);
4185
4186 return ((addr + (1 << align) - 1) & (-1 << align));
4187 }
4188
4189 /* We don't have any form of relaxing. */
4190
4191 int
4192 md_estimate_size_before_relax (fragp, seg)
4193 fragS *fragp;
4194 asection *seg;
4195 {
4196 abort ();
4197 return 0;
4198 }
4199
4200 /* Convert a machine dependent frag. We never generate these. */
4201
4202 void
4203 md_convert_frag (abfd, sec, fragp)
4204 bfd *abfd;
4205 asection *sec;
4206 fragS *fragp;
4207 {
4208 abort ();
4209 }
4210
4211 /* We have no need to default values of symbols. */
4212
4213 /*ARGSUSED*/
4214 symbolS *
4215 md_undefined_symbol (name)
4216 char *name;
4217 {
4218 return 0;
4219 }
4220 \f
4221 /* Functions concerning relocs. */
4222
4223 /* The location from which a PC relative jump should be calculated,
4224 given a PC relative reloc. */
4225
4226 long
4227 md_pcrel_from_section (fixp, sec)
4228 fixS *fixp;
4229 segT sec;
4230 {
4231 #ifdef OBJ_ELF
4232 if (fixp->fx_addsy != (symbolS *) NULL
4233 && (! S_IS_DEFINED (fixp->fx_addsy)
4234 || TC_FORCE_RELOCATION_SECTION (fixp, sec)))
4235 return 0;
4236 #endif
4237
4238 return fixp->fx_frag->fr_address + fixp->fx_where;
4239 }
4240
4241 #ifdef OBJ_XCOFF
4242
4243 /* This is called to see whether a fixup should be adjusted to use a
4244 section symbol. We take the opportunity to change a fixup against
4245 a symbol in the TOC subsegment into a reloc against the
4246 corresponding .tc symbol. */
4247
4248 int
4249 ppc_fix_adjustable (fix)
4250 fixS *fix;
4251 {
4252 valueT val;
4253
4254 resolve_symbol_value (fix->fx_addsy);
4255 val = S_GET_VALUE (fix->fx_addsy);
4256 if (ppc_toc_csect != (symbolS *) NULL
4257 && fix->fx_addsy != (symbolS *) NULL
4258 && fix->fx_addsy != ppc_toc_csect
4259 && S_GET_SEGMENT (fix->fx_addsy) == data_section
4260 && val >= ppc_toc_frag->fr_address
4261 && (ppc_after_toc_frag == (fragS *) NULL
4262 || val < ppc_after_toc_frag->fr_address))
4263 {
4264 symbolS *sy;
4265
4266 for (sy = symbol_next (ppc_toc_csect);
4267 sy != (symbolS *) NULL;
4268 sy = symbol_next (sy))
4269 {
4270 if (sy->sy_tc.class == XMC_TC0)
4271 continue;
4272 if (sy->sy_tc.class != XMC_TC)
4273 break;
4274 resolve_symbol_value (sy);
4275 if (val == S_GET_VALUE (sy))
4276 {
4277 fix->fx_addsy = sy;
4278 fix->fx_addnumber = val - ppc_toc_frag->fr_address;
4279 return 0;
4280 }
4281 }
4282
4283 as_bad_where (fix->fx_file, fix->fx_line,
4284 "symbol in .toc does not match any .tc");
4285 }
4286
4287 /* Possibly adjust the reloc to be against the csect. */
4288 if (fix->fx_addsy != (symbolS *) NULL
4289 && fix->fx_addsy->sy_tc.subseg == 0
4290 && fix->fx_addsy->sy_tc.class != XMC_TC0
4291 && fix->fx_addsy->sy_tc.class != XMC_TC
4292 && S_GET_SEGMENT (fix->fx_addsy) != bss_section)
4293 {
4294 symbolS *csect;
4295
4296 if (S_GET_SEGMENT (fix->fx_addsy) == text_section)
4297 csect = ppc_text_csects;
4298 else if (S_GET_SEGMENT (fix->fx_addsy) == data_section)
4299 csect = ppc_data_csects;
4300 else
4301 abort ();
4302
4303 /* Skip the initial dummy symbol. */
4304 csect = csect->sy_tc.next;
4305
4306 if (csect != (symbolS *) NULL)
4307 {
4308 while (csect->sy_tc.next != (symbolS *) NULL
4309 && (csect->sy_tc.next->sy_frag->fr_address
4310 <= fix->fx_addsy->sy_frag->fr_address))
4311 csect = csect->sy_tc.next;
4312
4313 fix->fx_offset += (S_GET_VALUE (fix->fx_addsy)
4314 - csect->sy_frag->fr_address);
4315 fix->fx_addsy = csect;
4316 }
4317 }
4318
4319 /* Adjust a reloc against a .lcomm symbol to be against the base
4320 .lcomm. */
4321 if (fix->fx_addsy != (symbolS *) NULL
4322 && S_GET_SEGMENT (fix->fx_addsy) == bss_section
4323 && ! S_IS_EXTERNAL (fix->fx_addsy))
4324 {
4325 resolve_symbol_value (fix->fx_addsy->sy_frag->fr_symbol);
4326 fix->fx_offset += (S_GET_VALUE (fix->fx_addsy)
4327 - S_GET_VALUE (fix->fx_addsy->sy_frag->fr_symbol));
4328 fix->fx_addsy = fix->fx_addsy->sy_frag->fr_symbol;
4329 }
4330
4331 return 0;
4332 }
4333
4334 #endif
4335
4336 /* See whether a symbol is in the TOC section. */
4337
4338 static int
4339 ppc_is_toc_sym (sym)
4340 symbolS *sym;
4341 {
4342 #ifdef OBJ_XCOFF
4343 return sym->sy_tc.class == XMC_TC;
4344 #else
4345 return strcmp (segment_name (S_GET_SEGMENT (sym)), ".got") == 0;
4346 #endif
4347 }
4348
4349 /* Apply a fixup to the object code. This is called for all the
4350 fixups we generated by the call to fix_new_exp, above. In the call
4351 above we used a reloc code which was the largest legal reloc code
4352 plus the operand index. Here we undo that to recover the operand
4353 index. At this point all symbol values should be fully resolved,
4354 and we attempt to completely resolve the reloc. If we can not do
4355 that, we determine the correct reloc code and put it back in the
4356 fixup. */
4357
4358 int
4359 md_apply_fix3 (fixp, valuep, seg)
4360 fixS *fixp;
4361 valueT *valuep;
4362 segT seg;
4363 {
4364 valueT value;
4365
4366 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
4367 the symbol values. Since we are using BFD_ASSEMBLER, if we are
4368 doing this relocation the code in write.c is going to call
4369 bfd_perform_relocation, which is also going to use the symbol
4370 value. That means that if the reloc is fully resolved we want to
4371 use *valuep since bfd_perform_relocation is not being used.
4372 However, if the reloc is not fully resolved we do not want to use
4373 *valuep, and must use fx_offset instead. However, if the reloc
4374 is PC relative, we do want to use *valuep since it includes the
4375 result of md_pcrel_from. This is confusing. */
4376
4377 if (fixp->fx_addsy == (symbolS *) NULL)
4378 {
4379 value = *valuep;
4380 fixp->fx_done = 1;
4381 }
4382 else if (fixp->fx_pcrel)
4383 value = *valuep;
4384 else
4385 {
4386 value = fixp->fx_offset;
4387 if (fixp->fx_subsy != (symbolS *) NULL)
4388 {
4389 if (S_GET_SEGMENT (fixp->fx_subsy) == absolute_section)
4390 value -= S_GET_VALUE (fixp->fx_subsy);
4391 else
4392 {
4393 /* We can't actually support subtracting a symbol. */
4394 as_bad_where (fixp->fx_file, fixp->fx_line,
4395 "expression too complex");
4396 }
4397 }
4398 }
4399
4400 if ((int) fixp->fx_r_type >= (int) BFD_RELOC_UNUSED)
4401 {
4402 int opindex;
4403 const struct powerpc_operand *operand;
4404 char *where;
4405 unsigned long insn;
4406
4407 opindex = (int) fixp->fx_r_type - (int) BFD_RELOC_UNUSED;
4408
4409 operand = &powerpc_operands[opindex];
4410
4411 #ifdef OBJ_XCOFF
4412 /* It appears that an instruction like
4413 l 9,LC..1(30)
4414 when LC..1 is not a TOC symbol does not generate a reloc. It
4415 uses the offset of LC..1 within its csect. However, .long
4416 LC..1 will generate a reloc. I can't find any documentation
4417 on how these cases are to be distinguished, so this is a wild
4418 guess. These cases are generated by gcc -mminimal-toc. */
4419 if ((operand->flags & PPC_OPERAND_PARENS) != 0
4420 && operand->bits == 16
4421 && operand->shift == 0
4422 && operand->insert == NULL
4423 && fixp->fx_addsy != NULL
4424 && fixp->fx_addsy->sy_tc.subseg != 0
4425 && fixp->fx_addsy->sy_tc.class != XMC_TC
4426 && fixp->fx_addsy->sy_tc.class != XMC_TC0
4427 && S_GET_SEGMENT (fixp->fx_addsy) != bss_section)
4428 {
4429 value = fixp->fx_offset;
4430 fixp->fx_done = 1;
4431 }
4432 #endif
4433
4434 /* Fetch the instruction, insert the fully resolved operand
4435 value, and stuff the instruction back again. */
4436 where = fixp->fx_frag->fr_literal + fixp->fx_where;
4437 if (target_big_endian)
4438 insn = bfd_getb32 ((unsigned char *) where);
4439 else
4440 insn = bfd_getl32 ((unsigned char *) where);
4441 insn = ppc_insert_operand (insn, operand, (offsetT) value,
4442 fixp->fx_file, fixp->fx_line);
4443 if (target_big_endian)
4444 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
4445 else
4446 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
4447
4448 if (fixp->fx_done)
4449 {
4450 /* Nothing else to do here. */
4451 return 1;
4452 }
4453
4454 /* Determine a BFD reloc value based on the operand information.
4455 We are only prepared to turn a few of the operands into
4456 relocs.
4457 FIXME: We need to handle the DS field at the very least.
4458 FIXME: Selecting the reloc type is a bit haphazard; perhaps
4459 there should be a new field in the operand table. */
4460 if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
4461 && operand->bits == 26
4462 && operand->shift == 0)
4463 fixp->fx_r_type = BFD_RELOC_PPC_B26;
4464 else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
4465 && operand->bits == 16
4466 && operand->shift == 0)
4467 fixp->fx_r_type = BFD_RELOC_PPC_B16;
4468 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
4469 && operand->bits == 26
4470 && operand->shift == 0)
4471 fixp->fx_r_type = BFD_RELOC_PPC_BA26;
4472 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
4473 && operand->bits == 16
4474 && operand->shift == 0)
4475 fixp->fx_r_type = BFD_RELOC_PPC_BA16;
4476 else if ((operand->flags & PPC_OPERAND_PARENS) != 0
4477 && operand->bits == 16
4478 && operand->shift == 0
4479 && operand->insert == NULL
4480 && fixp->fx_addsy != NULL
4481 && ppc_is_toc_sym (fixp->fx_addsy))
4482 {
4483 fixp->fx_size = 2;
4484 if (target_big_endian)
4485 fixp->fx_where += 2;
4486 fixp->fx_r_type = BFD_RELOC_PPC_TOC16;
4487 }
4488 else
4489 {
4490 as_bad_where (fixp->fx_file, fixp->fx_line,
4491 "unresolved expression that must be resolved");
4492 fixp->fx_done = 1;
4493 return 1;
4494 }
4495 }
4496 else
4497 {
4498 #ifdef OBJ_ELF
4499 ppc_elf_validate_fix (fixp, seg);
4500 #endif
4501 switch (fixp->fx_r_type)
4502 {
4503 case BFD_RELOC_32:
4504 case BFD_RELOC_CTOR:
4505 if (fixp->fx_pcrel)
4506 fixp->fx_r_type = BFD_RELOC_32_PCREL;
4507 /* fall through */
4508
4509 case BFD_RELOC_RVA:
4510 case BFD_RELOC_32_PCREL:
4511 case BFD_RELOC_32_BASEREL:
4512 case BFD_RELOC_PPC_EMB_NADDR32:
4513 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4514 value, 4);
4515 break;
4516
4517 case BFD_RELOC_LO16:
4518 case BFD_RELOC_HI16:
4519 case BFD_RELOC_HI16_S:
4520 case BFD_RELOC_16:
4521 case BFD_RELOC_GPREL16:
4522 case BFD_RELOC_16_GOT_PCREL:
4523 case BFD_RELOC_16_GOTOFF:
4524 case BFD_RELOC_LO16_GOTOFF:
4525 case BFD_RELOC_HI16_GOTOFF:
4526 case BFD_RELOC_HI16_S_GOTOFF:
4527 case BFD_RELOC_LO16_BASEREL:
4528 case BFD_RELOC_HI16_BASEREL:
4529 case BFD_RELOC_HI16_S_BASEREL:
4530 case BFD_RELOC_PPC_EMB_NADDR16:
4531 case BFD_RELOC_PPC_EMB_NADDR16_LO:
4532 case BFD_RELOC_PPC_EMB_NADDR16_HI:
4533 case BFD_RELOC_PPC_EMB_NADDR16_HA:
4534 case BFD_RELOC_PPC_EMB_SDAI16:
4535 case BFD_RELOC_PPC_EMB_SDA2REL:
4536 case BFD_RELOC_PPC_EMB_SDA2I16:
4537 case BFD_RELOC_PPC_EMB_RELSEC16:
4538 case BFD_RELOC_PPC_EMB_RELST_LO:
4539 case BFD_RELOC_PPC_EMB_RELST_HI:
4540 case BFD_RELOC_PPC_EMB_RELST_HA:
4541 case BFD_RELOC_PPC_EMB_RELSDA:
4542 case BFD_RELOC_PPC_TOC16:
4543 if (fixp->fx_pcrel)
4544 as_bad_where (fixp->fx_file, fixp->fx_line,
4545 "cannot emit PC relative %s relocation%s%s",
4546 bfd_get_reloc_code_name (fixp->fx_r_type),
4547 fixp->fx_addsy != NULL ? " against " : "",
4548 (fixp->fx_addsy != NULL
4549 ? S_GET_NAME (fixp->fx_addsy)
4550 : ""));
4551
4552 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4553 value, 2);
4554 break;
4555
4556 /* Because SDA21 modifies the register field, the size is set to 4
4557 bytes, rather than 2, so offset it here appropriately */
4558 case BFD_RELOC_PPC_EMB_SDA21:
4559 if (fixp->fx_pcrel)
4560 abort ();
4561
4562 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where
4563 + ((target_big_endian) ? 2 : 0),
4564 value, 2);
4565 break;
4566
4567 case BFD_RELOC_8:
4568 if (fixp->fx_pcrel)
4569 abort ();
4570
4571 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4572 value, 1);
4573 break;
4574
4575 default:
4576 fprintf(stderr,
4577 "Gas failure, reloc value %d\n", fixp->fx_r_type);
4578 fflush(stderr);
4579 abort ();
4580 }
4581 }
4582
4583 #ifdef OBJ_ELF
4584 fixp->fx_addnumber = value;
4585 #else
4586 if (fixp->fx_r_type != BFD_RELOC_PPC_TOC16)
4587 fixp->fx_addnumber = 0;
4588 else
4589 {
4590 #ifdef TE_PE
4591 fixp->fx_addnumber = 0;
4592 #else
4593 /* We want to use the offset within the data segment of the
4594 symbol, not the actual VMA of the symbol. */
4595 fixp->fx_addnumber =
4596 - bfd_get_section_vma (stdoutput, S_GET_SEGMENT (fixp->fx_addsy));
4597 #endif
4598 }
4599 #endif
4600
4601 return 1;
4602 }
4603
4604 /* Generate a reloc for a fixup. */
4605
4606 arelent *
4607 tc_gen_reloc (seg, fixp)
4608 asection *seg;
4609 fixS *fixp;
4610 {
4611 arelent *reloc;
4612
4613 reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
4614
4615 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
4616 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
4617 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
4618 if (reloc->howto == (reloc_howto_type *) NULL)
4619 {
4620 as_bad_where (fixp->fx_file, fixp->fx_line,
4621 "reloc %d not supported by object file format", (int)fixp->fx_r_type);
4622 return NULL;
4623 }
4624 reloc->addend = fixp->fx_addnumber;
4625
4626 return reloc;
4627 }
This page took 0.157468 seconds and 4 git commands to generate.