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