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