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