OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [binutils-2.20.1/] [gas/] [config/] [tc-ppc.c] - Blame information for rev 205

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 205 julius
/* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2
   Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3
   2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4
   Written by Ian Lance Taylor, Cygnus Support.
5
 
6
   This file is part of GAS, the GNU Assembler.
7
 
8
   GAS is free software; you can redistribute it and/or modify
9
   it under the terms of the GNU General Public License as published by
10
   the Free Software Foundation; either version 3, or (at your option)
11
   any later version.
12
 
13
   GAS is distributed in the hope that it will be useful,
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
   GNU General Public License for more details.
17
 
18
   You should have received a copy of the GNU General Public License
19
   along with GAS; see the file COPYING.  If not, write to the Free
20
   Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21
   02110-1301, USA.  */
22
 
23
#include "as.h"
24
#include "safe-ctype.h"
25
#include "subsegs.h"
26
#include "dw2gencfi.h"
27
#include "opcode/ppc.h"
28
 
29
#ifdef OBJ_ELF
30
#include "elf/ppc.h"
31
#include "dwarf2dbg.h"
32
#endif
33
 
34
#ifdef TE_PE
35
#include "coff/pe.h"
36
#endif
37
 
38
/* This is the assembler for the PowerPC or POWER (RS/6000) chips.  */
39
 
40
/* Tell the main code what the endianness is.  */
41
extern int target_big_endian;
42
 
43
/* Whether or not, we've set target_big_endian.  */
44
static int set_target_endian = 0;
45
 
46
/* Whether to use user friendly register names.  */
47
#ifndef TARGET_REG_NAMES_P
48
#ifdef TE_PE
49
#define TARGET_REG_NAMES_P TRUE
50
#else
51
#define TARGET_REG_NAMES_P FALSE
52
#endif
53
#endif
54
 
55
/* Macros for calculating LO, HI, HA, HIGHER, HIGHERA, HIGHEST,
56
   HIGHESTA.  */
57
 
58
/* #lo(value) denotes the least significant 16 bits of the indicated.  */
59
#define PPC_LO(v) ((v) & 0xffff)
60
 
61
/* #hi(value) denotes bits 16 through 31 of the indicated value.  */
62
#define PPC_HI(v) (((v) >> 16) & 0xffff)
63
 
64
/* #ha(value) denotes the high adjusted value: bits 16 through 31 of
65
  the indicated value, compensating for #lo() being treated as a
66
  signed number.  */
67
#define PPC_HA(v) PPC_HI ((v) + 0x8000)
68
 
69
/* #higher(value) denotes bits 32 through 47 of the indicated value.  */
70
#define PPC_HIGHER(v) (((v) >> 16 >> 16) & 0xffff)
71
 
72
/* #highera(value) denotes bits 32 through 47 of the indicated value,
73
   compensating for #lo() being treated as a signed number.  */
74
#define PPC_HIGHERA(v) PPC_HIGHER ((v) + 0x8000)
75
 
76
/* #highest(value) denotes bits 48 through 63 of the indicated value.  */
77
#define PPC_HIGHEST(v) (((v) >> 24 >> 24) & 0xffff)
78
 
79
/* #highesta(value) denotes bits 48 through 63 of the indicated value,
80
   compensating for #lo being treated as a signed number.  */
81
#define PPC_HIGHESTA(v) PPC_HIGHEST ((v) + 0x8000)
82
 
83
#define SEX16(val) ((((val) & 0xffff) ^ 0x8000) - 0x8000)
84
 
85
static bfd_boolean reg_names_p = TARGET_REG_NAMES_P;
86
 
87
static void ppc_macro (char *, const struct powerpc_macro *);
88
static void ppc_byte (int);
89
 
90
#if defined (OBJ_XCOFF) || defined (OBJ_ELF)
91
static void ppc_tc (int);
92
static void ppc_machine (int);
93
#endif
94
 
95
#ifdef OBJ_XCOFF
96
static void ppc_comm (int);
97
static void ppc_bb (int);
98
static void ppc_bc (int);
99
static void ppc_bf (int);
100
static void ppc_biei (int);
101
static void ppc_bs (int);
102
static void ppc_eb (int);
103
static void ppc_ec (int);
104
static void ppc_ef (int);
105
static void ppc_es (int);
106
static void ppc_csect (int);
107
static void ppc_change_csect (symbolS *, offsetT);
108
static void ppc_function (int);
109
static void ppc_extern (int);
110
static void ppc_lglobl (int);
111
static void ppc_ref (int);
112
static void ppc_section (int);
113
static void ppc_named_section (int);
114
static void ppc_stabx (int);
115
static void ppc_rename (int);
116
static void ppc_toc (int);
117
static void ppc_xcoff_cons (int);
118
static void ppc_vbyte (int);
119
#endif
120
 
121
#ifdef OBJ_ELF
122
static void ppc_elf_cons (int);
123
static void ppc_elf_rdata (int);
124
static void ppc_elf_lcomm (int);
125
#endif
126
 
127
#ifdef TE_PE
128
static void ppc_previous (int);
129
static void ppc_pdata (int);
130
static void ppc_ydata (int);
131
static void ppc_reldata (int);
132
static void ppc_rdata (int);
133
static void ppc_ualong (int);
134
static void ppc_znop (int);
135
static void ppc_pe_comm (int);
136
static void ppc_pe_section (int);
137
static void ppc_pe_function (int);
138
static void ppc_pe_tocd (int);
139
#endif
140
 
141
/* Generic assembler global variables which must be defined by all
142
   targets.  */
143
 
144
#ifdef OBJ_ELF
145
/* This string holds the chars that always start a comment.  If the
146
   pre-processor is disabled, these aren't very useful.  The macro
147
   tc_comment_chars points to this.  We use this, rather than the
148
   usual comment_chars, so that we can switch for Solaris conventions.  */
149
static const char ppc_solaris_comment_chars[] = "#!";
150
static const char ppc_eabi_comment_chars[] = "#";
151
 
152
#ifdef TARGET_SOLARIS_COMMENT
153
const char *ppc_comment_chars = ppc_solaris_comment_chars;
154
#else
155
const char *ppc_comment_chars = ppc_eabi_comment_chars;
156
#endif
157
#else
158
const char comment_chars[] = "#";
159
#endif
160
 
161
/* Characters which start a comment at the beginning of a line.  */
162
const char line_comment_chars[] = "#";
163
 
164
/* Characters which may be used to separate multiple commands on a
165
   single line.  */
166
const char line_separator_chars[] = ";";
167
 
168
/* Characters which are used to indicate an exponent in a floating
169
   point number.  */
170
const char EXP_CHARS[] = "eE";
171
 
172
/* Characters which mean that a number is a floating point constant,
173
   as in 0d1.0.  */
174
const char FLT_CHARS[] = "dD";
175
 
176
/* Anything that can start an operand needs to be mentioned here,
177
   to stop the input scrubber eating whitespace.  */
178
const char ppc_symbol_chars[] = "%[";
179
 
180
/* The dwarf2 data alignment, adjusted for 32 or 64 bit.  */
181
int ppc_cie_data_alignment;
182
 
183
/* The type of processor we are assembling for.  This is one or more
184
   of the PPC_OPCODE flags defined in opcode/ppc.h.  */
185
ppc_cpu_t ppc_cpu = 0;
186
 
187
/* The target specific pseudo-ops which we support.  */
188
 
189
const pseudo_typeS md_pseudo_table[] =
190
{
191
  /* Pseudo-ops which must be overridden.  */
192
  { "byte",     ppc_byte,       0 },
193
 
194
#ifdef OBJ_XCOFF
195
  /* Pseudo-ops specific to the RS/6000 XCOFF format.  Some of these
196
     legitimately belong in the obj-*.c file.  However, XCOFF is based
197
     on COFF, and is only implemented for the RS/6000.  We just use
198
     obj-coff.c, and add what we need here.  */
199
  { "comm",     ppc_comm,       0 },
200
  { "lcomm",    ppc_comm,       1 },
201
  { "bb",       ppc_bb,         0 },
202
  { "bc",       ppc_bc,         0 },
203
  { "bf",       ppc_bf,         0 },
204
  { "bi",       ppc_biei,       0 },
205
  { "bs",       ppc_bs,         0 },
206
  { "csect",    ppc_csect,      0 },
207
  { "data",     ppc_section,    'd' },
208
  { "eb",       ppc_eb,         0 },
209
  { "ec",       ppc_ec,         0 },
210
  { "ef",       ppc_ef,         0 },
211
  { "ei",       ppc_biei,       1 },
212
  { "es",       ppc_es,         0 },
213
  { "extern",   ppc_extern,     0 },
214
  { "function", ppc_function,   0 },
215
  { "lglobl",   ppc_lglobl,     0 },
216
  { "ref",      ppc_ref,        0 },
217
  { "rename",   ppc_rename,     0 },
218
  { "section",  ppc_named_section, 0 },
219
  { "stabx",    ppc_stabx,      0 },
220
  { "text",     ppc_section,    't' },
221
  { "toc",      ppc_toc,        0 },
222
  { "long",     ppc_xcoff_cons, 2 },
223
  { "llong",    ppc_xcoff_cons, 3 },
224
  { "word",     ppc_xcoff_cons, 1 },
225
  { "short",    ppc_xcoff_cons, 1 },
226
  { "vbyte",    ppc_vbyte,      0 },
227
#endif
228
 
229
#ifdef OBJ_ELF
230
  { "llong",    ppc_elf_cons,   8 },
231
  { "quad",     ppc_elf_cons,   8 },
232
  { "long",     ppc_elf_cons,   4 },
233
  { "word",     ppc_elf_cons,   2 },
234
  { "short",    ppc_elf_cons,   2 },
235
  { "rdata",    ppc_elf_rdata,  0 },
236
  { "rodata",   ppc_elf_rdata,  0 },
237
  { "lcomm",    ppc_elf_lcomm,  0 },
238
#endif
239
 
240
#ifdef TE_PE
241
  /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format.  */
242
  { "previous", ppc_previous,   0 },
243
  { "pdata",    ppc_pdata,      0 },
244
  { "ydata",    ppc_ydata,      0 },
245
  { "reldata",  ppc_reldata,    0 },
246
  { "rdata",    ppc_rdata,      0 },
247
  { "ualong",   ppc_ualong,     0 },
248
  { "znop",     ppc_znop,       0 },
249
  { "comm",     ppc_pe_comm,    0 },
250
  { "lcomm",    ppc_pe_comm,    1 },
251
  { "section",  ppc_pe_section, 0 },
252
  { "function", ppc_pe_function,0 },
253
  { "tocd",     ppc_pe_tocd,    0 },
254
#endif
255
 
256
#if defined (OBJ_XCOFF) || defined (OBJ_ELF)
257
  { "tc",       ppc_tc,         0 },
258
  { "machine",  ppc_machine,    0 },
259
#endif
260
 
261
  { NULL,       NULL,           0 }
262
};
263
 
264
 
265
/* Predefined register names if -mregnames (or default for Windows NT).
266
   In general, there are lots of them, in an attempt to be compatible
267
   with a number of other Windows NT assemblers.  */
268
 
269
/* Structure to hold information about predefined registers.  */
270
struct pd_reg
271
  {
272
    char *name;
273
    int value;
274
  };
275
 
276
/* List of registers that are pre-defined:
277
 
278
   Each general register has predefined names of the form:
279
   1. r<reg_num> which has the value <reg_num>.
280
   2. r.<reg_num> which has the value <reg_num>.
281
 
282
   Each floating point register has predefined names of the form:
283
   1. f<reg_num> which has the value <reg_num>.
284
   2. f.<reg_num> which has the value <reg_num>.
285
 
286
   Each vector unit register has predefined names of the form:
287
   1. v<reg_num> which has the value <reg_num>.
288
   2. v.<reg_num> which has the value <reg_num>.
289
 
290
   Each condition register has predefined names of the form:
291
   1. cr<reg_num> which has the value <reg_num>.
292
   2. cr.<reg_num> which has the value <reg_num>.
293
 
294
   There are individual registers as well:
295
   sp or r.sp     has the value 1
296
   rtoc or r.toc  has the value 2
297
   fpscr          has the value 0
298
   xer            has the value 1
299
   lr             has the value 8
300
   ctr            has the value 9
301
   pmr            has the value 0
302
   dar            has the value 19
303
   dsisr          has the value 18
304
   dec            has the value 22
305
   sdr1           has the value 25
306
   srr0           has the value 26
307
   srr1           has the value 27
308
 
309
   The table is sorted. Suitable for searching by a binary search.  */
310
 
311
static const struct pd_reg pre_defined_registers[] =
312
{
313
  { "cr.0", 0 },    /* Condition Registers */
314
  { "cr.1", 1 },
315
  { "cr.2", 2 },
316
  { "cr.3", 3 },
317
  { "cr.4", 4 },
318
  { "cr.5", 5 },
319
  { "cr.6", 6 },
320
  { "cr.7", 7 },
321
 
322
  { "cr0", 0 },
323
  { "cr1", 1 },
324
  { "cr2", 2 },
325
  { "cr3", 3 },
326
  { "cr4", 4 },
327
  { "cr5", 5 },
328
  { "cr6", 6 },
329
  { "cr7", 7 },
330
 
331
  { "ctr", 9 },
332
 
333
  { "dar", 19 },    /* Data Access Register */
334
  { "dec", 22 },    /* Decrementer */
335
  { "dsisr", 18 },  /* Data Storage Interrupt Status Register */
336
 
337
  { "f.0", 0 },     /* Floating point registers */
338
  { "f.1", 1 },
339
  { "f.10", 10 },
340
  { "f.11", 11 },
341
  { "f.12", 12 },
342
  { "f.13", 13 },
343
  { "f.14", 14 },
344
  { "f.15", 15 },
345
  { "f.16", 16 },
346
  { "f.17", 17 },
347
  { "f.18", 18 },
348
  { "f.19", 19 },
349
  { "f.2", 2 },
350
  { "f.20", 20 },
351
  { "f.21", 21 },
352
  { "f.22", 22 },
353
  { "f.23", 23 },
354
  { "f.24", 24 },
355
  { "f.25", 25 },
356
  { "f.26", 26 },
357
  { "f.27", 27 },
358
  { "f.28", 28 },
359
  { "f.29", 29 },
360
  { "f.3", 3 },
361
  { "f.30", 30 },
362
  { "f.31", 31 },
363
 
364
  { "f.32", 32 },    /* Extended floating point scalar registers (ISA 2.06).  */
365
  { "f.33", 33 },
366
  { "f.34", 34 },
367
  { "f.35", 35 },
368
  { "f.36", 36 },
369
  { "f.37", 37 },
370
  { "f.38", 38 },
371
  { "f.39", 39 },
372
  { "f.4", 4 },
373
  { "f.40", 40 },
374
  { "f.41", 41 },
375
  { "f.42", 42 },
376
  { "f.43", 43 },
377
  { "f.44", 44 },
378
  { "f.45", 45 },
379
  { "f.46", 46 },
380
  { "f.47", 47 },
381
  { "f.48", 48 },
382
  { "f.49", 49 },
383
  { "f.5", 5 },
384
  { "f.50", 50 },
385
  { "f.51", 51 },
386
  { "f.52", 52 },
387
  { "f.53", 53 },
388
  { "f.54", 54 },
389
  { "f.55", 55 },
390
  { "f.56", 56 },
391
  { "f.57", 57 },
392
  { "f.58", 58 },
393
  { "f.59", 59 },
394
  { "f.6", 6 },
395
  { "f.60", 60 },
396
  { "f.61", 61 },
397
  { "f.62", 62 },
398
  { "f.63", 63 },
399
  { "f.7", 7 },
400
  { "f.8", 8 },
401
  { "f.9", 9 },
402
 
403
  { "f0", 0 },
404
  { "f1", 1 },
405
  { "f10", 10 },
406
  { "f11", 11 },
407
  { "f12", 12 },
408
  { "f13", 13 },
409
  { "f14", 14 },
410
  { "f15", 15 },
411
  { "f16", 16 },
412
  { "f17", 17 },
413
  { "f18", 18 },
414
  { "f19", 19 },
415
  { "f2", 2 },
416
  { "f20", 20 },
417
  { "f21", 21 },
418
  { "f22", 22 },
419
  { "f23", 23 },
420
  { "f24", 24 },
421
  { "f25", 25 },
422
  { "f26", 26 },
423
  { "f27", 27 },
424
  { "f28", 28 },
425
  { "f29", 29 },
426
  { "f3", 3 },
427
  { "f30", 30 },
428
  { "f31", 31 },
429
 
430
  { "f32", 32 },    /* Extended floating point scalar registers (ISA 2.06).  */
431
  { "f33", 33 },
432
  { "f34", 34 },
433
  { "f35", 35 },
434
  { "f36", 36 },
435
  { "f37", 37 },
436
  { "f38", 38 },
437
  { "f39", 39 },
438
  { "f4", 4 },
439
  { "f40", 40 },
440
  { "f41", 41 },
441
  { "f42", 42 },
442
  { "f43", 43 },
443
  { "f44", 44 },
444
  { "f45", 45 },
445
  { "f46", 46 },
446
  { "f47", 47 },
447
  { "f48", 48 },
448
  { "f49", 49 },
449
  { "f5", 5 },
450
  { "f50", 50 },
451
  { "f51", 51 },
452
  { "f52", 52 },
453
  { "f53", 53 },
454
  { "f54", 54 },
455
  { "f55", 55 },
456
  { "f56", 56 },
457
  { "f57", 57 },
458
  { "f58", 58 },
459
  { "f59", 59 },
460
  { "f6", 6 },
461
  { "f60", 60 },
462
  { "f61", 61 },
463
  { "f62", 62 },
464
  { "f63", 63 },
465
  { "f7", 7 },
466
  { "f8", 8 },
467
  { "f9", 9 },
468
 
469
  { "fpscr", 0 },
470
 
471
  /* Quantization registers used with pair single instructions.  */
472
  { "gqr.0", 0 },
473
  { "gqr.1", 1 },
474
  { "gqr.2", 2 },
475
  { "gqr.3", 3 },
476
  { "gqr.4", 4 },
477
  { "gqr.5", 5 },
478
  { "gqr.6", 6 },
479
  { "gqr.7", 7 },
480
  { "gqr0", 0 },
481
  { "gqr1", 1 },
482
  { "gqr2", 2 },
483
  { "gqr3", 3 },
484
  { "gqr4", 4 },
485
  { "gqr5", 5 },
486
  { "gqr6", 6 },
487
  { "gqr7", 7 },
488
 
489
  { "lr", 8 },     /* Link Register */
490
 
491
  { "pmr", 0 },
492
 
493
  { "r.0", 0 },    /* General Purpose Registers */
494
  { "r.1", 1 },
495
  { "r.10", 10 },
496
  { "r.11", 11 },
497
  { "r.12", 12 },
498
  { "r.13", 13 },
499
  { "r.14", 14 },
500
  { "r.15", 15 },
501
  { "r.16", 16 },
502
  { "r.17", 17 },
503
  { "r.18", 18 },
504
  { "r.19", 19 },
505
  { "r.2", 2 },
506
  { "r.20", 20 },
507
  { "r.21", 21 },
508
  { "r.22", 22 },
509
  { "r.23", 23 },
510
  { "r.24", 24 },
511
  { "r.25", 25 },
512
  { "r.26", 26 },
513
  { "r.27", 27 },
514
  { "r.28", 28 },
515
  { "r.29", 29 },
516
  { "r.3", 3 },
517
  { "r.30", 30 },
518
  { "r.31", 31 },
519
  { "r.4", 4 },
520
  { "r.5", 5 },
521
  { "r.6", 6 },
522
  { "r.7", 7 },
523
  { "r.8", 8 },
524
  { "r.9", 9 },
525
 
526
  { "r.sp", 1 },   /* Stack Pointer */
527
 
528
  { "r.toc", 2 },  /* Pointer to the table of contents */
529
 
530
  { "r0", 0 },     /* More general purpose registers */
531
  { "r1", 1 },
532
  { "r10", 10 },
533
  { "r11", 11 },
534
  { "r12", 12 },
535
  { "r13", 13 },
536
  { "r14", 14 },
537
  { "r15", 15 },
538
  { "r16", 16 },
539
  { "r17", 17 },
540
  { "r18", 18 },
541
  { "r19", 19 },
542
  { "r2", 2 },
543
  { "r20", 20 },
544
  { "r21", 21 },
545
  { "r22", 22 },
546
  { "r23", 23 },
547
  { "r24", 24 },
548
  { "r25", 25 },
549
  { "r26", 26 },
550
  { "r27", 27 },
551
  { "r28", 28 },
552
  { "r29", 29 },
553
  { "r3", 3 },
554
  { "r30", 30 },
555
  { "r31", 31 },
556
  { "r4", 4 },
557
  { "r5", 5 },
558
  { "r6", 6 },
559
  { "r7", 7 },
560
  { "r8", 8 },
561
  { "r9", 9 },
562
 
563
  { "rtoc", 2 },  /* Table of contents */
564
 
565
  { "sdr1", 25 }, /* Storage Description Register 1 */
566
 
567
  { "sp", 1 },
568
 
569
  { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
570
  { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
571
 
572
  { "v.0", 0 },     /* Vector (Altivec/VMX) registers */
573
  { "v.1", 1 },
574
  { "v.10", 10 },
575
  { "v.11", 11 },
576
  { "v.12", 12 },
577
  { "v.13", 13 },
578
  { "v.14", 14 },
579
  { "v.15", 15 },
580
  { "v.16", 16 },
581
  { "v.17", 17 },
582
  { "v.18", 18 },
583
  { "v.19", 19 },
584
  { "v.2", 2 },
585
  { "v.20", 20 },
586
  { "v.21", 21 },
587
  { "v.22", 22 },
588
  { "v.23", 23 },
589
  { "v.24", 24 },
590
  { "v.25", 25 },
591
  { "v.26", 26 },
592
  { "v.27", 27 },
593
  { "v.28", 28 },
594
  { "v.29", 29 },
595
  { "v.3", 3 },
596
  { "v.30", 30 },
597
  { "v.31", 31 },
598
  { "v.4", 4 },
599
  { "v.5", 5 },
600
  { "v.6", 6 },
601
  { "v.7", 7 },
602
  { "v.8", 8 },
603
  { "v.9", 9 },
604
 
605
  { "v0", 0 },
606
  { "v1", 1 },
607
  { "v10", 10 },
608
  { "v11", 11 },
609
  { "v12", 12 },
610
  { "v13", 13 },
611
  { "v14", 14 },
612
  { "v15", 15 },
613
  { "v16", 16 },
614
  { "v17", 17 },
615
  { "v18", 18 },
616
  { "v19", 19 },
617
  { "v2", 2 },
618
  { "v20", 20 },
619
  { "v21", 21 },
620
  { "v22", 22 },
621
  { "v23", 23 },
622
  { "v24", 24 },
623
  { "v25", 25 },
624
  { "v26", 26 },
625
  { "v27", 27 },
626
  { "v28", 28 },
627
  { "v29", 29 },
628
  { "v3", 3 },
629
  { "v30", 30 },
630
  { "v31", 31 },
631
  { "v4", 4 },
632
  { "v5", 5 },
633
  { "v6", 6 },
634
  { "v7", 7 },
635
  { "v8", 8 },
636
  { "v9", 9 },
637
 
638
  { "vs.0", 0 },     /* Vector Scalar (VSX) registers (ISA 2.06).  */
639
  { "vs.1", 1 },
640
  { "vs.10", 10 },
641
  { "vs.11", 11 },
642
  { "vs.12", 12 },
643
  { "vs.13", 13 },
644
  { "vs.14", 14 },
645
  { "vs.15", 15 },
646
  { "vs.16", 16 },
647
  { "vs.17", 17 },
648
  { "vs.18", 18 },
649
  { "vs.19", 19 },
650
  { "vs.2", 2 },
651
  { "vs.20", 20 },
652
  { "vs.21", 21 },
653
  { "vs.22", 22 },
654
  { "vs.23", 23 },
655
  { "vs.24", 24 },
656
  { "vs.25", 25 },
657
  { "vs.26", 26 },
658
  { "vs.27", 27 },
659
  { "vs.28", 28 },
660
  { "vs.29", 29 },
661
  { "vs.3", 3 },
662
  { "vs.30", 30 },
663
  { "vs.31", 31 },
664
  { "vs.32", 32 },
665
  { "vs.33", 33 },
666
  { "vs.34", 34 },
667
  { "vs.35", 35 },
668
  { "vs.36", 36 },
669
  { "vs.37", 37 },
670
  { "vs.38", 38 },
671
  { "vs.39", 39 },
672
  { "vs.4", 4 },
673
  { "vs.40", 40 },
674
  { "vs.41", 41 },
675
  { "vs.42", 42 },
676
  { "vs.43", 43 },
677
  { "vs.44", 44 },
678
  { "vs.45", 45 },
679
  { "vs.46", 46 },
680
  { "vs.47", 47 },
681
  { "vs.48", 48 },
682
  { "vs.49", 49 },
683
  { "vs.5", 5 },
684
  { "vs.50", 50 },
685
  { "vs.51", 51 },
686
  { "vs.52", 52 },
687
  { "vs.53", 53 },
688
  { "vs.54", 54 },
689
  { "vs.55", 55 },
690
  { "vs.56", 56 },
691
  { "vs.57", 57 },
692
  { "vs.58", 58 },
693
  { "vs.59", 59 },
694
  { "vs.6", 6 },
695
  { "vs.60", 60 },
696
  { "vs.61", 61 },
697
  { "vs.62", 62 },
698
  { "vs.63", 63 },
699
  { "vs.7", 7 },
700
  { "vs.8", 8 },
701
  { "vs.9", 9 },
702
 
703
  { "vs0", 0 },
704
  { "vs1", 1 },
705
  { "vs10", 10 },
706
  { "vs11", 11 },
707
  { "vs12", 12 },
708
  { "vs13", 13 },
709
  { "vs14", 14 },
710
  { "vs15", 15 },
711
  { "vs16", 16 },
712
  { "vs17", 17 },
713
  { "vs18", 18 },
714
  { "vs19", 19 },
715
  { "vs2", 2 },
716
  { "vs20", 20 },
717
  { "vs21", 21 },
718
  { "vs22", 22 },
719
  { "vs23", 23 },
720
  { "vs24", 24 },
721
  { "vs25", 25 },
722
  { "vs26", 26 },
723
  { "vs27", 27 },
724
  { "vs28", 28 },
725
  { "vs29", 29 },
726
  { "vs3", 3 },
727
  { "vs30", 30 },
728
  { "vs31", 31 },
729
  { "vs32", 32 },
730
  { "vs33", 33 },
731
  { "vs34", 34 },
732
  { "vs35", 35 },
733
  { "vs36", 36 },
734
  { "vs37", 37 },
735
  { "vs38", 38 },
736
  { "vs39", 39 },
737
  { "vs4", 4 },
738
  { "vs40", 40 },
739
  { "vs41", 41 },
740
  { "vs42", 42 },
741
  { "vs43", 43 },
742
  { "vs44", 44 },
743
  { "vs45", 45 },
744
  { "vs46", 46 },
745
  { "vs47", 47 },
746
  { "vs48", 48 },
747
  { "vs49", 49 },
748
  { "vs5", 5 },
749
  { "vs50", 50 },
750
  { "vs51", 51 },
751
  { "vs52", 52 },
752
  { "vs53", 53 },
753
  { "vs54", 54 },
754
  { "vs55", 55 },
755
  { "vs56", 56 },
756
  { "vs57", 57 },
757
  { "vs58", 58 },
758
  { "vs59", 59 },
759
  { "vs6", 6 },
760
  { "vs60", 60 },
761
  { "vs61", 61 },
762
  { "vs62", 62 },
763
  { "vs63", 63 },
764
  { "vs7", 7 },
765
  { "vs8", 8 },
766
  { "vs9", 9 },
767
 
768
  { "xer", 1 },
769
 
770
};
771
 
772
#define REG_NAME_CNT    (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
773
 
774
/* Given NAME, find the register number associated with that name, return
775
   the integer value associated with the given name or -1 on failure.  */
776
 
777
static int
778
reg_name_search (const struct pd_reg *regs, int regcount, const char *name)
779
{
780
  int middle, low, high;
781
  int cmp;
782
 
783
  low = 0;
784
  high = regcount - 1;
785
 
786
  do
787
    {
788
      middle = (low + high) / 2;
789
      cmp = strcasecmp (name, regs[middle].name);
790
      if (cmp < 0)
791
        high = middle - 1;
792
      else if (cmp > 0)
793
        low = middle + 1;
794
      else
795
        return regs[middle].value;
796
    }
797
  while (low <= high);
798
 
799
  return -1;
800
}
801
 
802
/*
803
 * Summary of register_name.
804
 *
805
 * in:  Input_line_pointer points to 1st char of operand.
806
 *
807
 * out: A expressionS.
808
 *      The operand may have been a register: in this case, X_op == O_register,
809
 *      X_add_number is set to the register number, and truth is returned.
810
 *      Input_line_pointer->(next non-blank) char after operand, or is in its
811
 *      original state.
812
 */
813
 
814
static bfd_boolean
815
register_name (expressionS *expressionP)
816
{
817
  int reg_number;
818
  char *name;
819
  char *start;
820
  char c;
821
 
822
  /* Find the spelling of the operand.  */
823
  start = name = input_line_pointer;
824
  if (name[0] == '%' && ISALPHA (name[1]))
825
    name = ++input_line_pointer;
826
 
827
  else if (!reg_names_p || !ISALPHA (name[0]))
828
    return FALSE;
829
 
830
  c = get_symbol_end ();
831
  reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name);
832
 
833
  /* Put back the delimiting char.  */
834
  *input_line_pointer = c;
835
 
836
  /* Look to see if it's in the register table.  */
837
  if (reg_number >= 0)
838
    {
839
      expressionP->X_op = O_register;
840
      expressionP->X_add_number = reg_number;
841
 
842
      /* Make the rest nice.  */
843
      expressionP->X_add_symbol = NULL;
844
      expressionP->X_op_symbol = NULL;
845
      return TRUE;
846
    }
847
 
848
  /* Reset the line as if we had not done anything.  */
849
  input_line_pointer = start;
850
  return FALSE;
851
}
852
 
853
/* This function is called for each symbol seen in an expression.  It
854
   handles the special parsing which PowerPC assemblers are supposed
855
   to use for condition codes.  */
856
 
857
/* Whether to do the special parsing.  */
858
static bfd_boolean cr_operand;
859
 
860
/* Names to recognize in a condition code.  This table is sorted.  */
861
static const struct pd_reg cr_names[] =
862
{
863
  { "cr0", 0 },
864
  { "cr1", 1 },
865
  { "cr2", 2 },
866
  { "cr3", 3 },
867
  { "cr4", 4 },
868
  { "cr5", 5 },
869
  { "cr6", 6 },
870
  { "cr7", 7 },
871
  { "eq", 2 },
872
  { "gt", 1 },
873
  { "lt", 0 },
874
  { "so", 3 },
875
  { "un", 3 }
876
};
877
 
878
/* Parsing function.  This returns non-zero if it recognized an
879
   expression.  */
880
 
881
int
882
ppc_parse_name (const char *name, expressionS *expr)
883
{
884
  int val;
885
 
886
  if (! cr_operand)
887
    return 0;
888
 
889
  if (*name == '%')
890
    ++name;
891
  val = reg_name_search (cr_names, sizeof cr_names / sizeof cr_names[0],
892
                         name);
893
  if (val < 0)
894
    return 0;
895
 
896
  expr->X_op = O_constant;
897
  expr->X_add_number = val;
898
 
899
  return 1;
900
}
901
 
902
/* Local variables.  */
903
 
904
/* Whether to target xcoff64/elf64.  */
905
static unsigned int ppc_obj64 = BFD_DEFAULT_TARGET_SIZE == 64;
906
 
907
/* Opcode hash table.  */
908
static struct hash_control *ppc_hash;
909
 
910
/* Macro hash table.  */
911
static struct hash_control *ppc_macro_hash;
912
 
913
#ifdef OBJ_ELF
914
/* What type of shared library support to use.  */
915
static enum { SHLIB_NONE, SHLIB_PIC, SHLIB_MRELOCATABLE } shlib = SHLIB_NONE;
916
 
917
/* Flags to set in the elf header.  */
918
static flagword ppc_flags = 0;
919
 
920
/* Whether this is Solaris or not.  */
921
#ifdef TARGET_SOLARIS_COMMENT
922
#define SOLARIS_P TRUE
923
#else
924
#define SOLARIS_P FALSE
925
#endif
926
 
927
static bfd_boolean msolaris = SOLARIS_P;
928
#endif
929
 
930
#ifdef OBJ_XCOFF
931
 
932
/* The RS/6000 assembler uses the .csect pseudo-op to generate code
933
   using a bunch of different sections.  These assembler sections,
934
   however, are all encompassed within the .text or .data sections of
935
   the final output file.  We handle this by using different
936
   subsegments within these main segments.  */
937
 
938
/* Next subsegment to allocate within the .text segment.  */
939
static subsegT ppc_text_subsegment = 2;
940
 
941
/* Linked list of csects in the text section.  */
942
static symbolS *ppc_text_csects;
943
 
944
/* Next subsegment to allocate within the .data segment.  */
945
static subsegT ppc_data_subsegment = 2;
946
 
947
/* Linked list of csects in the data section.  */
948
static symbolS *ppc_data_csects;
949
 
950
/* The current csect.  */
951
static symbolS *ppc_current_csect;
952
 
953
/* The RS/6000 assembler uses a TOC which holds addresses of functions
954
   and variables.  Symbols are put in the TOC with the .tc pseudo-op.
955
   A special relocation is used when accessing TOC entries.  We handle
956
   the TOC as a subsegment within the .data segment.  We set it up if
957
   we see a .toc pseudo-op, and save the csect symbol here.  */
958
static symbolS *ppc_toc_csect;
959
 
960
/* The first frag in the TOC subsegment.  */
961
static fragS *ppc_toc_frag;
962
 
963
/* The first frag in the first subsegment after the TOC in the .data
964
   segment.  NULL if there are no subsegments after the TOC.  */
965
static fragS *ppc_after_toc_frag;
966
 
967
/* The current static block.  */
968
static symbolS *ppc_current_block;
969
 
970
/* The COFF debugging section; set by md_begin.  This is not the
971
   .debug section, but is instead the secret BFD section which will
972
   cause BFD to set the section number of a symbol to N_DEBUG.  */
973
static asection *ppc_coff_debug_section;
974
 
975
#endif /* OBJ_XCOFF */
976
 
977
#ifdef TE_PE
978
 
979
/* Various sections that we need for PE coff support.  */
980
static segT ydata_section;
981
static segT pdata_section;
982
static segT reldata_section;
983
static segT rdata_section;
984
static segT tocdata_section;
985
 
986
/* The current section and the previous section. See ppc_previous.  */
987
static segT ppc_previous_section;
988
static segT ppc_current_section;
989
 
990
#endif /* TE_PE */
991
 
992
#ifdef OBJ_ELF
993
symbolS *GOT_symbol;            /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
994
#define PPC_APUINFO_ISEL        0x40
995
#define PPC_APUINFO_PMR         0x41
996
#define PPC_APUINFO_RFMCI       0x42
997
#define PPC_APUINFO_CACHELCK    0x43
998
#define PPC_APUINFO_SPE         0x100
999
#define PPC_APUINFO_EFS         0x101
1000
#define PPC_APUINFO_BRLOCK      0x102
1001
 
1002
/*
1003
 * We keep a list of APUinfo
1004
 */
1005
unsigned long *ppc_apuinfo_list;
1006
unsigned int ppc_apuinfo_num;
1007
unsigned int ppc_apuinfo_num_alloc;
1008
#endif /* OBJ_ELF */
1009
 
1010
#ifdef OBJ_ELF
1011
const char *const md_shortopts = "b:l:usm:K:VQ:";
1012
#else
1013
const char *const md_shortopts = "um:";
1014
#endif
1015
const struct option md_longopts[] = {
1016
  {NULL, no_argument, NULL, 0}
1017
};
1018
const size_t md_longopts_size = sizeof (md_longopts);
1019
 
1020
int
1021
md_parse_option (int c, char *arg)
1022
{
1023
  ppc_cpu_t new_cpu;
1024
 
1025
  switch (c)
1026
    {
1027
    case 'u':
1028
      /* -u means that any undefined symbols should be treated as
1029
         external, which is the default for gas anyhow.  */
1030
      break;
1031
 
1032
#ifdef OBJ_ELF
1033
    case 'l':
1034
      /* Solaris as takes -le (presumably for little endian).  For completeness
1035
         sake, recognize -be also.  */
1036
      if (strcmp (arg, "e") == 0)
1037
        {
1038
          target_big_endian = 0;
1039
          set_target_endian = 1;
1040
        }
1041
      else
1042
        return 0;
1043
 
1044
      break;
1045
 
1046
    case 'b':
1047
      if (strcmp (arg, "e") == 0)
1048
        {
1049
          target_big_endian = 1;
1050
          set_target_endian = 1;
1051
        }
1052
      else
1053
        return 0;
1054
 
1055
      break;
1056
 
1057
    case 'K':
1058
      /* Recognize -K PIC.  */
1059
      if (strcmp (arg, "PIC") == 0 || strcmp (arg, "pic") == 0)
1060
        {
1061
          shlib = SHLIB_PIC;
1062
          ppc_flags |= EF_PPC_RELOCATABLE_LIB;
1063
        }
1064
      else
1065
        return 0;
1066
 
1067
      break;
1068
#endif
1069
 
1070
      /* a64 and a32 determine whether to use XCOFF64 or XCOFF32.  */
1071
    case 'a':
1072
      if (strcmp (arg, "64") == 0)
1073
        {
1074
#ifdef BFD64
1075
          ppc_obj64 = 1;
1076
#else
1077
          as_fatal (_("%s unsupported"), "-a64");
1078
#endif
1079
        }
1080
      else if (strcmp (arg, "32") == 0)
1081
        ppc_obj64 = 0;
1082
      else
1083
        return 0;
1084
      break;
1085
 
1086
    case 'm':
1087
      if ((new_cpu = ppc_parse_cpu (ppc_cpu, arg)) != 0)
1088
        ppc_cpu = new_cpu;
1089
 
1090
      else if (strcmp (arg, "regnames") == 0)
1091
        reg_names_p = TRUE;
1092
 
1093
      else if (strcmp (arg, "no-regnames") == 0)
1094
        reg_names_p = FALSE;
1095
 
1096
#ifdef OBJ_ELF
1097
      /* -mrelocatable/-mrelocatable-lib -- warn about initializations
1098
         that require relocation.  */
1099
      else if (strcmp (arg, "relocatable") == 0)
1100
        {
1101
          shlib = SHLIB_MRELOCATABLE;
1102
          ppc_flags |= EF_PPC_RELOCATABLE;
1103
        }
1104
 
1105
      else if (strcmp (arg, "relocatable-lib") == 0)
1106
        {
1107
          shlib = SHLIB_MRELOCATABLE;
1108
          ppc_flags |= EF_PPC_RELOCATABLE_LIB;
1109
        }
1110
 
1111
      /* -memb, set embedded bit.  */
1112
      else if (strcmp (arg, "emb") == 0)
1113
        ppc_flags |= EF_PPC_EMB;
1114
 
1115
      /* -mlittle/-mbig set the endianess.  */
1116
      else if (strcmp (arg, "little") == 0
1117
               || strcmp (arg, "little-endian") == 0)
1118
        {
1119
          target_big_endian = 0;
1120
          set_target_endian = 1;
1121
        }
1122
 
1123
      else if (strcmp (arg, "big") == 0 || strcmp (arg, "big-endian") == 0)
1124
        {
1125
          target_big_endian = 1;
1126
          set_target_endian = 1;
1127
        }
1128
 
1129
      else if (strcmp (arg, "solaris") == 0)
1130
        {
1131
          msolaris = TRUE;
1132
          ppc_comment_chars = ppc_solaris_comment_chars;
1133
        }
1134
 
1135
      else if (strcmp (arg, "no-solaris") == 0)
1136
        {
1137
          msolaris = FALSE;
1138
          ppc_comment_chars = ppc_eabi_comment_chars;
1139
        }
1140
#endif
1141
      else
1142
        {
1143
          as_bad (_("invalid switch -m%s"), arg);
1144
          return 0;
1145
        }
1146
      break;
1147
 
1148
#ifdef OBJ_ELF
1149
      /* -V: SVR4 argument to print version ID.  */
1150
    case 'V':
1151
      print_version_id ();
1152
      break;
1153
 
1154
      /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
1155
         should be emitted or not.  FIXME: Not implemented.  */
1156
    case 'Q':
1157
      break;
1158
 
1159
      /* Solaris takes -s to specify that .stabs go in a .stabs section,
1160
         rather than .stabs.excl, which is ignored by the linker.
1161
         FIXME: Not implemented.  */
1162
    case 's':
1163
      if (arg)
1164
        return 0;
1165
 
1166
      break;
1167
#endif
1168
 
1169
    default:
1170
      return 0;
1171
    }
1172
 
1173
  return 1;
1174
}
1175
 
1176
void
1177
md_show_usage (FILE *stream)
1178
{
1179
  fprintf (stream, _("\
1180
PowerPC options:\n\
1181
-a32                    generate ELF32/XCOFF32\n\
1182
-a64                    generate ELF64/XCOFF64\n\
1183
-u                      ignored\n\
1184
-mpwrx, -mpwr2          generate code for POWER/2 (RIOS2)\n\
1185
-mpwr                   generate code for POWER (RIOS1)\n\
1186
-m601                   generate code for PowerPC 601\n\
1187
-mppc, -mppc32, -m603, -m604\n\
1188
                        generate code for PowerPC 603/604\n\
1189
-m403                   generate code for PowerPC 403\n\
1190
-m405                   generate code for PowerPC 405\n\
1191
-m440                   generate code for PowerPC 440\n\
1192
-m464                   generate code for PowerPC 464\n\
1193
-m476                   generate code for PowerPC 476\n\
1194
-m7400, -m7410, -m7450, -m7455\n\
1195
                        generate code for PowerPC 7400/7410/7450/7455\n\
1196
-m750cl                 generate code for PowerPC 750cl\n"));
1197
  fprintf (stream, _("\
1198
-mppc64, -m620          generate code for PowerPC 620/625/630\n\
1199
-mppc64bridge           generate code for PowerPC 64, including bridge insns\n\
1200
-mbooke                 generate code for 32-bit PowerPC BookE\n\
1201
-ma2                    generate code for A2 architecture\n\
1202
-mpower4, -mpwr4        generate code for Power4 architecture\n\
1203
-mpower5, -mpwr5, -mpwr5x\n\
1204
                        generate code for Power5 architecture\n\
1205
-mpower6, -mpwr6        generate code for Power6 architecture\n\
1206
-mpower7, -mpwr7        generate code for Power7 architecture\n\
1207
-mcell                  generate code for Cell Broadband Engine architecture\n\
1208
-mcom                   generate code Power/PowerPC common instructions\n\
1209
-many                   generate code for any architecture (PWR/PWRX/PPC)\n"));
1210
  fprintf (stream, _("\
1211
-maltivec               generate code for AltiVec\n\
1212
-mvsx                   generate code for Vector-Scalar (VSX) instructions\n\
1213
-me300                  generate code for PowerPC e300 family\n\
1214
-me500, -me500x2        generate code for Motorola e500 core complex\n\
1215
-me500mc,               generate code for Freescale e500mc core complex\n\
1216
-mspe                   generate code for Motorola SPE instructions\n\
1217
-mregnames              Allow symbolic names for registers\n\
1218
-mno-regnames           Do not allow symbolic names for registers\n"));
1219
#ifdef OBJ_ELF
1220
  fprintf (stream, _("\
1221
-mrelocatable           support for GCC's -mrelocatble option\n\
1222
-mrelocatable-lib       support for GCC's -mrelocatble-lib option\n\
1223
-memb                   set PPC_EMB bit in ELF flags\n\
1224
-mlittle, -mlittle-endian, -l, -le\n\
1225
                        generate code for a little endian machine\n\
1226
-mbig, -mbig-endian, -b, -be\n\
1227
                        generate code for a big endian machine\n\
1228
-msolaris               generate code for Solaris\n\
1229
-mno-solaris            do not generate code for Solaris\n\
1230
-V                      print assembler version number\n\
1231
-Qy, -Qn                ignored\n"));
1232
#endif
1233
}
1234
 
1235
/* Set ppc_cpu if it is not already set.  */
1236
 
1237
static void
1238
ppc_set_cpu (void)
1239
{
1240
  const char *default_os  = TARGET_OS;
1241
  const char *default_cpu = TARGET_CPU;
1242
 
1243
  if ((ppc_cpu & ~PPC_OPCODE_ANY) == 0)
1244
    {
1245
      if (ppc_obj64)
1246
        ppc_cpu |= PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC | PPC_OPCODE_64;
1247
      else if (strncmp (default_os, "aix", 3) == 0
1248
               && default_os[3] >= '4' && default_os[3] <= '9')
1249
        ppc_cpu |= PPC_OPCODE_COMMON | PPC_OPCODE_32;
1250
      else if (strncmp (default_os, "aix3", 4) == 0)
1251
        ppc_cpu |= PPC_OPCODE_POWER | PPC_OPCODE_32;
1252
      else if (strcmp (default_cpu, "rs6000") == 0)
1253
        ppc_cpu |= PPC_OPCODE_POWER | PPC_OPCODE_32;
1254
      else if (strncmp (default_cpu, "powerpc", 7) == 0)
1255
        ppc_cpu |= PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC | PPC_OPCODE_32;
1256
      else
1257
        as_fatal (_("Unknown default cpu = %s, os = %s"),
1258
                  default_cpu, default_os);
1259
    }
1260
}
1261
 
1262
/* Figure out the BFD architecture to use.  This function and ppc_mach
1263
   are called well before md_begin, when the output file is opened.  */
1264
 
1265
enum bfd_architecture
1266
ppc_arch (void)
1267
{
1268
  const char *default_cpu = TARGET_CPU;
1269
  ppc_set_cpu ();
1270
 
1271
  if ((ppc_cpu & PPC_OPCODE_PPC) != 0)
1272
    return bfd_arch_powerpc;
1273
  else if ((ppc_cpu & PPC_OPCODE_POWER) != 0)
1274
    return bfd_arch_rs6000;
1275
  else if ((ppc_cpu & (PPC_OPCODE_COMMON | PPC_OPCODE_ANY)) != 0)
1276
    {
1277
      if (strcmp (default_cpu, "rs6000") == 0)
1278
        return bfd_arch_rs6000;
1279
      else if (strncmp (default_cpu, "powerpc", 7) == 0)
1280
        return bfd_arch_powerpc;
1281
    }
1282
 
1283
  as_fatal (_("Neither Power nor PowerPC opcodes were selected."));
1284
  return bfd_arch_unknown;
1285
}
1286
 
1287
unsigned long
1288
ppc_mach (void)
1289
{
1290
  if (ppc_obj64)
1291
    return bfd_mach_ppc64;
1292
  else if (ppc_arch () == bfd_arch_rs6000)
1293
    return bfd_mach_rs6k;
1294
  else
1295
    return bfd_mach_ppc;
1296
}
1297
 
1298
extern char*
1299
ppc_target_format (void)
1300
{
1301
#ifdef OBJ_COFF
1302
#ifdef TE_PE
1303
  return target_big_endian ? "pe-powerpc" : "pe-powerpcle";
1304
#elif TE_POWERMAC
1305
  return "xcoff-powermac";
1306
#else
1307
#  ifdef TE_AIX5
1308
    return (ppc_obj64 ? "aix5coff64-rs6000" : "aixcoff-rs6000");
1309
#  else
1310
    return (ppc_obj64 ? "aixcoff64-rs6000" : "aixcoff-rs6000");
1311
#  endif
1312
#endif
1313
#endif
1314
#ifdef OBJ_ELF
1315
# ifdef TE_VXWORKS
1316
  return "elf32-powerpc-vxworks";
1317
# else
1318
  return (target_big_endian
1319
          ? (ppc_obj64 ? "elf64-powerpc" : "elf32-powerpc")
1320
          : (ppc_obj64 ? "elf64-powerpcle" : "elf32-powerpcle"));
1321
# endif
1322
#endif
1323
}
1324
 
1325
/* Insert opcodes and macros into hash tables.  Called at startup and
1326
   for .cpu pseudo.  */
1327
 
1328
static void
1329
ppc_setup_opcodes (void)
1330
{
1331
  const struct powerpc_opcode *op;
1332
  const struct powerpc_opcode *op_end;
1333
  const struct powerpc_macro *macro;
1334
  const struct powerpc_macro *macro_end;
1335
  bfd_boolean bad_insn = FALSE;
1336
 
1337
  if (ppc_hash != NULL)
1338
    hash_die (ppc_hash);
1339
  if (ppc_macro_hash != NULL)
1340
    hash_die (ppc_macro_hash);
1341
 
1342
  /* Insert the opcodes into a hash table.  */
1343
  ppc_hash = hash_new ();
1344
 
1345
  if (ENABLE_CHECKING)
1346
    {
1347
      unsigned int i;
1348
 
1349
      /* Check operand masks.  Code here and in the disassembler assumes
1350
         all the 1's in the mask are contiguous.  */
1351
      for (i = 0; i < num_powerpc_operands; ++i)
1352
        {
1353
          unsigned long mask = powerpc_operands[i].bitm;
1354
          unsigned long right_bit;
1355
          unsigned int j;
1356
 
1357
          right_bit = mask & -mask;
1358
          mask += right_bit;
1359
          right_bit = mask & -mask;
1360
          if (mask != right_bit)
1361
            {
1362
              as_bad (_("powerpc_operands[%d].bitm invalid"), i);
1363
              bad_insn = TRUE;
1364
            }
1365
          for (j = i + 1; j < num_powerpc_operands; ++j)
1366
            if (memcmp (&powerpc_operands[i], &powerpc_operands[j],
1367
                        sizeof (powerpc_operands[0])) == 0)
1368
              {
1369
                as_bad (_("powerpc_operands[%d] duplicates powerpc_operands[%d]"),
1370
                        j, i);
1371
                bad_insn = TRUE;
1372
              }
1373
        }
1374
    }
1375
 
1376
  op_end = powerpc_opcodes + powerpc_num_opcodes;
1377
  for (op = powerpc_opcodes; op < op_end; op++)
1378
    {
1379
      if (ENABLE_CHECKING)
1380
        {
1381
          const unsigned char *o;
1382
          unsigned long omask = op->mask;
1383
 
1384
          if (op != powerpc_opcodes)
1385
            {
1386
              /* The major opcodes had better be sorted.  Code in the
1387
                 disassembler assumes the insns are sorted according to
1388
                 major opcode.  */
1389
              if (PPC_OP (op[0].opcode) < PPC_OP (op[-1].opcode))
1390
                {
1391
                  as_bad (_("major opcode is not sorted for %s"),
1392
                          op->name);
1393
                  bad_insn = TRUE;
1394
                }
1395
 
1396
              /* Warn if the table isn't more strictly ordered.
1397
                 Unfortunately it doesn't seem possible to order the
1398
                 table on much more than the major opcode, which makes
1399
                 it difficult to implement a binary search in the
1400
                 disassembler.  The problem is that we have multiple
1401
                 ways to disassemble instructions, and we usually want
1402
                 to choose a more specific form (with more bits set in
1403
                 the opcode) than a more general form.  eg. all of the
1404
                 following are equivalent:
1405
                 bne label      # opcode = 0x40820000, mask = 0xff830003
1406
                 bf  2,label    # opcode = 0x40800000, mask = 0xff800003
1407
                 bc  4,2,label  # opcode = 0x40000000, mask = 0xfc000003
1408
 
1409
                 There are also cases where the table needs to be out
1410
                 of order to disassemble the correct instruction for
1411
                 processor variants.  */
1412
              else if (0)
1413
                {
1414
                  unsigned long t1 = op[0].opcode;
1415
                  unsigned long t2 = op[-1].opcode;
1416
 
1417
                  if (((t1 ^ t2) & 0xfc0007ff) == 0
1418
                      && (t1 & 0xfc0006df) == 0x7c000286)
1419
                    {
1420
                      /* spr field is split.  */
1421
                      t1 = ((t1 & ~0x1ff800)
1422
                            | ((t1 & 0xf800) << 5) | ((t1 & 0x1f0000) >> 5));
1423
                      t2 = ((t2 & ~0x1ff800)
1424
                            | ((t2 & 0xf800) << 5) | ((t2 & 0x1f0000) >> 5));
1425
                    }
1426
                  if (t1 < t2)
1427
                    as_warn (_("%s (%08lx %08lx) after %s (%08lx %08lx)"),
1428
                             op[0].name, op[0].opcode, op[0].mask,
1429
                             op[-1].name, op[-1].opcode, op[-1].mask);
1430
                }
1431
            }
1432
 
1433
          /* The mask had better not trim off opcode bits.  */
1434
          if ((op->opcode & omask) != op->opcode)
1435
            {
1436
              as_bad (_("mask trims opcode bits for %s"),
1437
                      op->name);
1438
              bad_insn = TRUE;
1439
            }
1440
 
1441
          /* The operands must not overlap the opcode or each other.  */
1442
          for (o = op->operands; *o; ++o)
1443
            if (*o >= num_powerpc_operands)
1444
              {
1445
                as_bad (_("operand index error for %s"),
1446
                        op->name);
1447
                bad_insn = TRUE;
1448
              }
1449
            else
1450
              {
1451
                const struct powerpc_operand *operand = &powerpc_operands[*o];
1452
                if (operand->shift >= 0)
1453
                  {
1454
                    unsigned long mask = operand->bitm << operand->shift;
1455
                    if (omask & mask)
1456
                      {
1457
                        as_bad (_("operand %d overlap in %s"),
1458
                                (int) (o - op->operands), op->name);
1459
                        bad_insn = TRUE;
1460
                      }
1461
                    omask |= mask;
1462
                  }
1463
              }
1464
        }
1465
 
1466
      if ((op->flags & ppc_cpu & ~(PPC_OPCODE_32 | PPC_OPCODE_64)) != 0
1467
          && ((op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == 0
1468
              || ((op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64))
1469
                  == (ppc_cpu & (PPC_OPCODE_32 | PPC_OPCODE_64)))
1470
              || (ppc_cpu & PPC_OPCODE_64_BRIDGE) != 0)
1471
          && !(ppc_cpu & op->deprecated))
1472
        {
1473
          const char *retval;
1474
 
1475
          retval = hash_insert (ppc_hash, op->name, (void *) op);
1476
          if (retval != NULL)
1477
            {
1478
              /* Ignore Power duplicates for -m601.  */
1479
              if ((ppc_cpu & PPC_OPCODE_601) != 0
1480
                  && (op->flags & PPC_OPCODE_POWER) != 0)
1481
                continue;
1482
 
1483
              as_bad (_("duplicate instruction %s"),
1484
                      op->name);
1485
              bad_insn = TRUE;
1486
            }
1487
        }
1488
    }
1489
 
1490
  if ((ppc_cpu & PPC_OPCODE_ANY) != 0)
1491
    for (op = powerpc_opcodes; op < op_end; op++)
1492
      hash_insert (ppc_hash, op->name, (void *) op);
1493
 
1494
  /* Insert the macros into a hash table.  */
1495
  ppc_macro_hash = hash_new ();
1496
 
1497
  macro_end = powerpc_macros + powerpc_num_macros;
1498
  for (macro = powerpc_macros; macro < macro_end; macro++)
1499
    {
1500
      if ((macro->flags & ppc_cpu) != 0)
1501
        {
1502
          const char *retval;
1503
 
1504
          retval = hash_insert (ppc_macro_hash, macro->name, (void *) macro);
1505
          if (retval != (const char *) NULL)
1506
            {
1507
              as_bad (_("duplicate macro %s"), macro->name);
1508
              bad_insn = TRUE;
1509
            }
1510
        }
1511
    }
1512
 
1513
  if (bad_insn)
1514
    abort ();
1515
}
1516
 
1517
/* This function is called when the assembler starts up.  It is called
1518
   after the options have been parsed and the output file has been
1519
   opened.  */
1520
 
1521
void
1522
md_begin (void)
1523
{
1524
  ppc_set_cpu ();
1525
 
1526
  ppc_cie_data_alignment = ppc_obj64 ? -8 : -4;
1527
 
1528
#ifdef OBJ_ELF
1529
  /* Set the ELF flags if desired.  */
1530
  if (ppc_flags && !msolaris)
1531
    bfd_set_private_flags (stdoutput, ppc_flags);
1532
#endif
1533
 
1534
  ppc_setup_opcodes ();
1535
 
1536
  /* Tell the main code what the endianness is if it is not overridden
1537
     by the user.  */
1538
  if (!set_target_endian)
1539
    {
1540
      set_target_endian = 1;
1541
      target_big_endian = PPC_BIG_ENDIAN;
1542
    }
1543
 
1544
#ifdef OBJ_XCOFF
1545
  ppc_coff_debug_section = coff_section_from_bfd_index (stdoutput, N_DEBUG);
1546
 
1547
  /* Create dummy symbols to serve as initial csects.  This forces the
1548
     text csects to precede the data csects.  These symbols will not
1549
     be output.  */
1550
  ppc_text_csects = symbol_make ("dummy\001");
1551
  symbol_get_tc (ppc_text_csects)->within = ppc_text_csects;
1552
  ppc_data_csects = symbol_make ("dummy\001");
1553
  symbol_get_tc (ppc_data_csects)->within = ppc_data_csects;
1554
#endif
1555
 
1556
#ifdef TE_PE
1557
 
1558
  ppc_current_section = text_section;
1559
  ppc_previous_section = 0;
1560
 
1561
#endif
1562
}
1563
 
1564
void
1565
ppc_cleanup (void)
1566
{
1567
#ifdef OBJ_ELF
1568
  if (ppc_apuinfo_list == NULL)
1569
    return;
1570
 
1571
  /* Ok, so write the section info out.  We have this layout:
1572
 
1573
  byte  data            what
1574
  ----  ----            ----
1575
 
1576
  4     (n*4)           number of APU's (4 bytes each)
1577
  8     2               note type 2
1578
  12    "APUinfo\0"     name
1579
  20    APU#1           first APU's info
1580
  24    APU#2           second APU's info
1581
  ...   ...
1582
  */
1583
  {
1584
    char *p;
1585
    asection *seg = now_seg;
1586
    subsegT subseg = now_subseg;
1587
    asection *apuinfo_secp = (asection *) NULL;
1588
    unsigned int i;
1589
 
1590
    /* Create the .PPC.EMB.apuinfo section.  */
1591
    apuinfo_secp = subseg_new (".PPC.EMB.apuinfo", 0);
1592
    bfd_set_section_flags (stdoutput,
1593
                           apuinfo_secp,
1594
                           SEC_HAS_CONTENTS | SEC_READONLY);
1595
 
1596
    p = frag_more (4);
1597
    md_number_to_chars (p, (valueT) 8, 4);
1598
 
1599
    p = frag_more (4);
1600
    md_number_to_chars (p, (valueT) ppc_apuinfo_num * 4, 4);
1601
 
1602
    p = frag_more (4);
1603
    md_number_to_chars (p, (valueT) 2, 4);
1604
 
1605
    p = frag_more (8);
1606
    strcpy (p, "APUinfo");
1607
 
1608
    for (i = 0; i < ppc_apuinfo_num; i++)
1609
      {
1610
        p = frag_more (4);
1611
        md_number_to_chars (p, (valueT) ppc_apuinfo_list[i], 4);
1612
      }
1613
 
1614
    frag_align (2, 0, 0);
1615
 
1616
    /* We probably can't restore the current segment, for there likely
1617
       isn't one yet...  */
1618
    if (seg && subseg)
1619
      subseg_set (seg, subseg);
1620
  }
1621
#endif
1622
}
1623
 
1624
/* Insert an operand value into an instruction.  */
1625
 
1626
static unsigned long
1627
ppc_insert_operand (unsigned long insn,
1628
                    const struct powerpc_operand *operand,
1629
                    offsetT val,
1630
                    ppc_cpu_t ppc_cpu,
1631
                    char *file,
1632
                    unsigned int line)
1633
{
1634
  long min, max, right;
1635
 
1636
  max = operand->bitm;
1637
  right = max & -max;
1638
  min = 0;
1639
 
1640
  if ((operand->flags & PPC_OPERAND_SIGNED) != 0)
1641
    {
1642
      if ((operand->flags & PPC_OPERAND_SIGNOPT) == 0)
1643
        max = (max >> 1) & -right;
1644
      min = ~max & -right;
1645
    }
1646
 
1647
  if ((operand->flags & PPC_OPERAND_PLUS1) != 0)
1648
    max++;
1649
 
1650
  if ((operand->flags & PPC_OPERAND_NEGATIVE) != 0)
1651
    {
1652
      long tmp = min;
1653
      min = -max;
1654
      max = -tmp;
1655
    }
1656
 
1657
  if (min <= max)
1658
    {
1659
      /* Some people write constants with the sign extension done by
1660
         hand but only up to 32 bits.  This shouldn't really be valid,
1661
         but, to permit this code to assemble on a 64-bit host, we
1662
         sign extend the 32-bit value to 64 bits if so doing makes the
1663
         value valid.  */
1664
      if (val > max
1665
          && (offsetT) (val - 0x80000000 - 0x80000000) >= min
1666
          && (offsetT) (val - 0x80000000 - 0x80000000) <= max
1667
          && ((val - 0x80000000 - 0x80000000) & (right - 1)) == 0)
1668
        val = val - 0x80000000 - 0x80000000;
1669
 
1670
      /* Similarly, people write expressions like ~(1<<15), and expect
1671
         this to be OK for a 32-bit unsigned value.  */
1672
      else if (val < min
1673
               && (offsetT) (val + 0x80000000 + 0x80000000) >= min
1674
               && (offsetT) (val + 0x80000000 + 0x80000000) <= max
1675
               && ((val + 0x80000000 + 0x80000000) & (right - 1)) == 0)
1676
        val = val + 0x80000000 + 0x80000000;
1677
 
1678
      else if (val < min
1679
               || val > max
1680
               || (val & (right - 1)) != 0)
1681
        as_bad_value_out_of_range (_("operand"), val, min, max, file, line);
1682
    }
1683
 
1684
  if (operand->insert)
1685
    {
1686
      const char *errmsg;
1687
 
1688
      errmsg = NULL;
1689
      insn = (*operand->insert) (insn, (long) val, ppc_cpu, &errmsg);
1690
      if (errmsg != (const char *) NULL)
1691
        as_bad_where (file, line, "%s", errmsg);
1692
    }
1693
  else
1694
    insn |= ((long) val & operand->bitm) << operand->shift;
1695
 
1696
  return insn;
1697
}
1698
 
1699
 
1700
#ifdef OBJ_ELF
1701
/* Parse @got, etc. and return the desired relocation.  */
1702
static bfd_reloc_code_real_type
1703
ppc_elf_suffix (char **str_p, expressionS *exp_p)
1704
{
1705
  struct map_bfd {
1706
    char *string;
1707
    unsigned int length : 8;
1708
    unsigned int valid32 : 1;
1709
    unsigned int valid64 : 1;
1710
    unsigned int reloc;
1711
  };
1712
 
1713
  char ident[20];
1714
  char *str = *str_p;
1715
  char *str2;
1716
  int ch;
1717
  int len;
1718
  const struct map_bfd *ptr;
1719
 
1720
#define MAP(str, reloc)   { str, sizeof (str) - 1, 1, 1, reloc }
1721
#define MAP32(str, reloc) { str, sizeof (str) - 1, 1, 0, reloc }
1722
#define MAP64(str, reloc) { str, sizeof (str) - 1, 0, 1, reloc }
1723
 
1724
  static const struct map_bfd mapping[] = {
1725
    MAP ("l",                   BFD_RELOC_LO16),
1726
    MAP ("h",                   BFD_RELOC_HI16),
1727
    MAP ("ha",                  BFD_RELOC_HI16_S),
1728
    MAP ("brtaken",             BFD_RELOC_PPC_B16_BRTAKEN),
1729
    MAP ("brntaken",            BFD_RELOC_PPC_B16_BRNTAKEN),
1730
    MAP ("got",                 BFD_RELOC_16_GOTOFF),
1731
    MAP ("got@l",               BFD_RELOC_LO16_GOTOFF),
1732
    MAP ("got@h",               BFD_RELOC_HI16_GOTOFF),
1733
    MAP ("got@ha",              BFD_RELOC_HI16_S_GOTOFF),
1734
    MAP ("plt@l",               BFD_RELOC_LO16_PLTOFF),
1735
    MAP ("plt@h",               BFD_RELOC_HI16_PLTOFF),
1736
    MAP ("plt@ha",              BFD_RELOC_HI16_S_PLTOFF),
1737
    MAP ("copy",                BFD_RELOC_PPC_COPY),
1738
    MAP ("globdat",             BFD_RELOC_PPC_GLOB_DAT),
1739
    MAP ("sectoff",             BFD_RELOC_16_BASEREL),
1740
    MAP ("sectoff@l",           BFD_RELOC_LO16_BASEREL),
1741
    MAP ("sectoff@h",           BFD_RELOC_HI16_BASEREL),
1742
    MAP ("sectoff@ha",          BFD_RELOC_HI16_S_BASEREL),
1743
    MAP ("tls",                 BFD_RELOC_PPC_TLS),
1744
    MAP ("dtpmod",              BFD_RELOC_PPC_DTPMOD),
1745
    MAP ("dtprel",              BFD_RELOC_PPC_DTPREL),
1746
    MAP ("dtprel@l",            BFD_RELOC_PPC_DTPREL16_LO),
1747
    MAP ("dtprel@h",            BFD_RELOC_PPC_DTPREL16_HI),
1748
    MAP ("dtprel@ha",           BFD_RELOC_PPC_DTPREL16_HA),
1749
    MAP ("tprel",               BFD_RELOC_PPC_TPREL),
1750
    MAP ("tprel@l",             BFD_RELOC_PPC_TPREL16_LO),
1751
    MAP ("tprel@h",             BFD_RELOC_PPC_TPREL16_HI),
1752
    MAP ("tprel@ha",            BFD_RELOC_PPC_TPREL16_HA),
1753
    MAP ("got@tlsgd",           BFD_RELOC_PPC_GOT_TLSGD16),
1754
    MAP ("got@tlsgd@l",         BFD_RELOC_PPC_GOT_TLSGD16_LO),
1755
    MAP ("got@tlsgd@h",         BFD_RELOC_PPC_GOT_TLSGD16_HI),
1756
    MAP ("got@tlsgd@ha",        BFD_RELOC_PPC_GOT_TLSGD16_HA),
1757
    MAP ("got@tlsld",           BFD_RELOC_PPC_GOT_TLSLD16),
1758
    MAP ("got@tlsld@l",         BFD_RELOC_PPC_GOT_TLSLD16_LO),
1759
    MAP ("got@tlsld@h",         BFD_RELOC_PPC_GOT_TLSLD16_HI),
1760
    MAP ("got@tlsld@ha",        BFD_RELOC_PPC_GOT_TLSLD16_HA),
1761
    MAP ("got@dtprel",          BFD_RELOC_PPC_GOT_DTPREL16),
1762
    MAP ("got@dtprel@l",        BFD_RELOC_PPC_GOT_DTPREL16_LO),
1763
    MAP ("got@dtprel@h",        BFD_RELOC_PPC_GOT_DTPREL16_HI),
1764
    MAP ("got@dtprel@ha",       BFD_RELOC_PPC_GOT_DTPREL16_HA),
1765
    MAP ("got@tprel",           BFD_RELOC_PPC_GOT_TPREL16),
1766
    MAP ("got@tprel@l",         BFD_RELOC_PPC_GOT_TPREL16_LO),
1767
    MAP ("got@tprel@h",         BFD_RELOC_PPC_GOT_TPREL16_HI),
1768
    MAP ("got@tprel@ha",        BFD_RELOC_PPC_GOT_TPREL16_HA),
1769
    MAP32 ("fixup",             BFD_RELOC_CTOR),
1770
    MAP32 ("plt",               BFD_RELOC_24_PLT_PCREL),
1771
    MAP32 ("pltrel24",          BFD_RELOC_24_PLT_PCREL),
1772
    MAP32 ("local24pc",         BFD_RELOC_PPC_LOCAL24PC),
1773
    MAP32 ("local",             BFD_RELOC_PPC_LOCAL24PC),
1774
    MAP32 ("pltrel",            BFD_RELOC_32_PLT_PCREL),
1775
    MAP32 ("sdarel",            BFD_RELOC_GPREL16),
1776
    MAP32 ("naddr",             BFD_RELOC_PPC_EMB_NADDR32),
1777
    MAP32 ("naddr16",           BFD_RELOC_PPC_EMB_NADDR16),
1778
    MAP32 ("naddr@l",           BFD_RELOC_PPC_EMB_NADDR16_LO),
1779
    MAP32 ("naddr@h",           BFD_RELOC_PPC_EMB_NADDR16_HI),
1780
    MAP32 ("naddr@ha",          BFD_RELOC_PPC_EMB_NADDR16_HA),
1781
    MAP32 ("sdai16",            BFD_RELOC_PPC_EMB_SDAI16),
1782
    MAP32 ("sda2rel",           BFD_RELOC_PPC_EMB_SDA2REL),
1783
    MAP32 ("sda2i16",           BFD_RELOC_PPC_EMB_SDA2I16),
1784
    MAP32 ("sda21",             BFD_RELOC_PPC_EMB_SDA21),
1785
    MAP32 ("mrkref",            BFD_RELOC_PPC_EMB_MRKREF),
1786
    MAP32 ("relsect",           BFD_RELOC_PPC_EMB_RELSEC16),
1787
    MAP32 ("relsect@l",         BFD_RELOC_PPC_EMB_RELST_LO),
1788
    MAP32 ("relsect@h",         BFD_RELOC_PPC_EMB_RELST_HI),
1789
    MAP32 ("relsect@ha",        BFD_RELOC_PPC_EMB_RELST_HA),
1790
    MAP32 ("bitfld",            BFD_RELOC_PPC_EMB_BIT_FLD),
1791
    MAP32 ("relsda",            BFD_RELOC_PPC_EMB_RELSDA),
1792
    MAP32 ("xgot",              BFD_RELOC_PPC_TOC16),
1793
    MAP64 ("higher",            BFD_RELOC_PPC64_HIGHER),
1794
    MAP64 ("highera",           BFD_RELOC_PPC64_HIGHER_S),
1795
    MAP64 ("highest",           BFD_RELOC_PPC64_HIGHEST),
1796
    MAP64 ("highesta",          BFD_RELOC_PPC64_HIGHEST_S),
1797
    MAP64 ("tocbase",           BFD_RELOC_PPC64_TOC),
1798
    MAP64 ("toc",               BFD_RELOC_PPC_TOC16),
1799
    MAP64 ("toc@l",             BFD_RELOC_PPC64_TOC16_LO),
1800
    MAP64 ("toc@h",             BFD_RELOC_PPC64_TOC16_HI),
1801
    MAP64 ("toc@ha",            BFD_RELOC_PPC64_TOC16_HA),
1802
    MAP64 ("dtprel@higher",     BFD_RELOC_PPC64_DTPREL16_HIGHER),
1803
    MAP64 ("dtprel@highera",    BFD_RELOC_PPC64_DTPREL16_HIGHERA),
1804
    MAP64 ("dtprel@highest",    BFD_RELOC_PPC64_DTPREL16_HIGHEST),
1805
    MAP64 ("dtprel@highesta",   BFD_RELOC_PPC64_DTPREL16_HIGHESTA),
1806
    MAP64 ("tprel@higher",      BFD_RELOC_PPC64_TPREL16_HIGHER),
1807
    MAP64 ("tprel@highera",     BFD_RELOC_PPC64_TPREL16_HIGHERA),
1808
    MAP64 ("tprel@highest",     BFD_RELOC_PPC64_TPREL16_HIGHEST),
1809
    MAP64 ("tprel@highesta",    BFD_RELOC_PPC64_TPREL16_HIGHESTA),
1810
    { (char *) 0, 0, 0, 0,  BFD_RELOC_UNUSED }
1811
  };
1812
 
1813
  if (*str++ != '@')
1814
    return BFD_RELOC_UNUSED;
1815
 
1816
  for (ch = *str, str2 = ident;
1817
       (str2 < ident + sizeof (ident) - 1
1818
        && (ISALNUM (ch) || ch == '@'));
1819
       ch = *++str)
1820
    {
1821
      *str2++ = TOLOWER (ch);
1822
    }
1823
 
1824
  *str2 = '\0';
1825
  len = str2 - ident;
1826
 
1827
  ch = ident[0];
1828
  for (ptr = &mapping[0]; ptr->length > 0; ptr++)
1829
    if (ch == ptr->string[0]
1830
        && len == ptr->length
1831
        && memcmp (ident, ptr->string, ptr->length) == 0
1832
        && (ppc_obj64 ? ptr->valid64 : ptr->valid32))
1833
      {
1834
        int reloc = ptr->reloc;
1835
 
1836
        if (!ppc_obj64 && exp_p->X_add_number != 0)
1837
          {
1838
            switch (reloc)
1839
              {
1840
              case BFD_RELOC_16_GOTOFF:
1841
              case BFD_RELOC_LO16_GOTOFF:
1842
              case BFD_RELOC_HI16_GOTOFF:
1843
              case BFD_RELOC_HI16_S_GOTOFF:
1844
                as_warn (_("identifier+constant@got means "
1845
                           "identifier@got+constant"));
1846
                break;
1847
 
1848
              case BFD_RELOC_PPC_GOT_TLSGD16:
1849
              case BFD_RELOC_PPC_GOT_TLSGD16_LO:
1850
              case BFD_RELOC_PPC_GOT_TLSGD16_HI:
1851
              case BFD_RELOC_PPC_GOT_TLSGD16_HA:
1852
              case BFD_RELOC_PPC_GOT_TLSLD16:
1853
              case BFD_RELOC_PPC_GOT_TLSLD16_LO:
1854
              case BFD_RELOC_PPC_GOT_TLSLD16_HI:
1855
              case BFD_RELOC_PPC_GOT_TLSLD16_HA:
1856
              case BFD_RELOC_PPC_GOT_DTPREL16:
1857
              case BFD_RELOC_PPC_GOT_DTPREL16_LO:
1858
              case BFD_RELOC_PPC_GOT_DTPREL16_HI:
1859
              case BFD_RELOC_PPC_GOT_DTPREL16_HA:
1860
              case BFD_RELOC_PPC_GOT_TPREL16:
1861
              case BFD_RELOC_PPC_GOT_TPREL16_LO:
1862
              case BFD_RELOC_PPC_GOT_TPREL16_HI:
1863
              case BFD_RELOC_PPC_GOT_TPREL16_HA:
1864
                as_bad (_("symbol+offset not supported for got tls"));
1865
                break;
1866
              }
1867
          }
1868
 
1869
        /* Now check for identifier@suffix+constant.  */
1870
        if (*str == '-' || *str == '+')
1871
          {
1872
            char *orig_line = input_line_pointer;
1873
            expressionS new_exp;
1874
 
1875
            input_line_pointer = str;
1876
            expression (&new_exp);
1877
            if (new_exp.X_op == O_constant)
1878
              {
1879
                exp_p->X_add_number += new_exp.X_add_number;
1880
                str = input_line_pointer;
1881
              }
1882
 
1883
            if (&input_line_pointer != str_p)
1884
              input_line_pointer = orig_line;
1885
          }
1886
        *str_p = str;
1887
 
1888
        if (reloc == (int) BFD_RELOC_PPC64_TOC
1889
            && exp_p->X_op == O_symbol
1890
            && strcmp (S_GET_NAME (exp_p->X_add_symbol), ".TOC.") == 0)
1891
          {
1892
            /* Change the symbol so that the dummy .TOC. symbol can be
1893
               omitted from the object file.  */
1894
            exp_p->X_add_symbol = &abs_symbol;
1895
          }
1896
 
1897
        return (bfd_reloc_code_real_type) reloc;
1898
      }
1899
 
1900
  return BFD_RELOC_UNUSED;
1901
}
1902
 
1903
/* Like normal .long/.short/.word, except support @got, etc.
1904
   Clobbers input_line_pointer, checks end-of-line.  */
1905
static void
1906
ppc_elf_cons (int nbytes /* 1=.byte, 2=.word, 4=.long, 8=.llong */)
1907
{
1908
  expressionS exp;
1909
  bfd_reloc_code_real_type reloc;
1910
 
1911
  if (is_it_end_of_statement ())
1912
    {
1913
      demand_empty_rest_of_line ();
1914
      return;
1915
    }
1916
 
1917
  do
1918
    {
1919
      expression (&exp);
1920
      if (exp.X_op == O_symbol
1921
          && *input_line_pointer == '@'
1922
          && (reloc = ppc_elf_suffix (&input_line_pointer,
1923
                                      &exp)) != BFD_RELOC_UNUSED)
1924
        {
1925
          reloc_howto_type *reloc_howto;
1926
          int size;
1927
 
1928
          reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc);
1929
          size = bfd_get_reloc_size (reloc_howto);
1930
 
1931
          if (size > nbytes)
1932
            {
1933
              as_bad (_("%s relocations do not fit in %d bytes\n"),
1934
                      reloc_howto->name, nbytes);
1935
            }
1936
          else
1937
            {
1938
              char *p;
1939
              int offset;
1940
 
1941
              p = frag_more (nbytes);
1942
              offset = 0;
1943
              if (target_big_endian)
1944
                offset = nbytes - size;
1945
              fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size,
1946
                           &exp, 0, reloc);
1947
            }
1948
        }
1949
      else
1950
        emit_expr (&exp, (unsigned int) nbytes);
1951
    }
1952
  while (*input_line_pointer++ == ',');
1953
 
1954
  /* Put terminator back into stream.  */
1955
  input_line_pointer--;
1956
  demand_empty_rest_of_line ();
1957
}
1958
 
1959
/* Solaris pseduo op to change to the .rodata section.  */
1960
static void
1961
ppc_elf_rdata (int xxx)
1962
{
1963
  char *save_line = input_line_pointer;
1964
  static char section[] = ".rodata\n";
1965
 
1966
  /* Just pretend this is .section .rodata  */
1967
  input_line_pointer = section;
1968
  obj_elf_section (xxx);
1969
 
1970
  input_line_pointer = save_line;
1971
}
1972
 
1973
/* Pseudo op to make file scope bss items.  */
1974
static void
1975
ppc_elf_lcomm (int xxx ATTRIBUTE_UNUSED)
1976
{
1977
  char *name;
1978
  char c;
1979
  char *p;
1980
  offsetT size;
1981
  symbolS *symbolP;
1982
  offsetT align;
1983
  segT old_sec;
1984
  int old_subsec;
1985
  char *pfrag;
1986
  int align2;
1987
 
1988
  name = input_line_pointer;
1989
  c = get_symbol_end ();
1990
 
1991
  /* just after name is now '\0'.  */
1992
  p = input_line_pointer;
1993
  *p = c;
1994
  SKIP_WHITESPACE ();
1995
  if (*input_line_pointer != ',')
1996
    {
1997
      as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1998
      ignore_rest_of_line ();
1999
      return;
2000
    }
2001
 
2002
  input_line_pointer++;         /* skip ',' */
2003
  if ((size = get_absolute_expression ()) < 0)
2004
    {
2005
      as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size);
2006
      ignore_rest_of_line ();
2007
      return;
2008
    }
2009
 
2010
  /* The third argument to .lcomm is the alignment.  */
2011
  if (*input_line_pointer != ',')
2012
    align = 8;
2013
  else
2014
    {
2015
      ++input_line_pointer;
2016
      align = get_absolute_expression ();
2017
      if (align <= 0)
2018
        {
2019
          as_warn (_("ignoring bad alignment"));
2020
          align = 8;
2021
        }
2022
    }
2023
 
2024
  *p = 0;
2025
  symbolP = symbol_find_or_make (name);
2026
  *p = c;
2027
 
2028
  if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
2029
    {
2030
      as_bad (_("Ignoring attempt to re-define symbol `%s'."),
2031
              S_GET_NAME (symbolP));
2032
      ignore_rest_of_line ();
2033
      return;
2034
    }
2035
 
2036
  if (S_GET_VALUE (symbolP) && S_GET_VALUE (symbolP) != (valueT) size)
2037
    {
2038
      as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
2039
              S_GET_NAME (symbolP),
2040
              (long) S_GET_VALUE (symbolP),
2041
              (long) size);
2042
 
2043
      ignore_rest_of_line ();
2044
      return;
2045
    }
2046
 
2047
  /* Allocate_bss.  */
2048
  old_sec = now_seg;
2049
  old_subsec = now_subseg;
2050
  if (align)
2051
    {
2052
      /* Convert to a power of 2 alignment.  */
2053
      for (align2 = 0; (align & 1) == 0; align >>= 1, ++align2);
2054
      if (align != 1)
2055
        {
2056
          as_bad (_("Common alignment not a power of 2"));
2057
          ignore_rest_of_line ();
2058
          return;
2059
        }
2060
    }
2061
  else
2062
    align2 = 0;
2063
 
2064
  record_alignment (bss_section, align2);
2065
  subseg_set (bss_section, 0);
2066
  if (align2)
2067
    frag_align (align2, 0, 0);
2068
  if (S_GET_SEGMENT (symbolP) == bss_section)
2069
    symbol_get_frag (symbolP)->fr_symbol = 0;
2070
  symbol_set_frag (symbolP, frag_now);
2071
  pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
2072
                    (char *) 0);
2073
  *pfrag = 0;
2074
  S_SET_SIZE (symbolP, size);
2075
  S_SET_SEGMENT (symbolP, bss_section);
2076
  subseg_set (old_sec, old_subsec);
2077
  demand_empty_rest_of_line ();
2078
}
2079
 
2080
/* Validate any relocations emitted for -mrelocatable, possibly adding
2081
   fixups for word relocations in writable segments, so we can adjust
2082
   them at runtime.  */
2083
static void
2084
ppc_elf_validate_fix (fixS *fixp, segT seg)
2085
{
2086
  if (fixp->fx_done || fixp->fx_pcrel)
2087
    return;
2088
 
2089
  switch (shlib)
2090
    {
2091
    case SHLIB_NONE:
2092
    case SHLIB_PIC:
2093
      return;
2094
 
2095
    case SHLIB_MRELOCATABLE:
2096
      if (fixp->fx_r_type <= BFD_RELOC_UNUSED
2097
          && fixp->fx_r_type != BFD_RELOC_16_GOTOFF
2098
          && fixp->fx_r_type != BFD_RELOC_HI16_GOTOFF
2099
          && fixp->fx_r_type != BFD_RELOC_LO16_GOTOFF
2100
          && fixp->fx_r_type != BFD_RELOC_HI16_S_GOTOFF
2101
          && fixp->fx_r_type != BFD_RELOC_16_BASEREL
2102
          && fixp->fx_r_type != BFD_RELOC_LO16_BASEREL
2103
          && fixp->fx_r_type != BFD_RELOC_HI16_BASEREL
2104
          && fixp->fx_r_type != BFD_RELOC_HI16_S_BASEREL
2105
          && (seg->flags & SEC_LOAD) != 0
2106
          && strcmp (segment_name (seg), ".got2") != 0
2107
          && strcmp (segment_name (seg), ".dtors") != 0
2108
          && strcmp (segment_name (seg), ".ctors") != 0
2109
          && strcmp (segment_name (seg), ".fixup") != 0
2110
          && strcmp (segment_name (seg), ".gcc_except_table") != 0
2111
          && strcmp (segment_name (seg), ".eh_frame") != 0
2112
          && strcmp (segment_name (seg), ".ex_shared") != 0)
2113
        {
2114
          if ((seg->flags & (SEC_READONLY | SEC_CODE)) != 0
2115
              || fixp->fx_r_type != BFD_RELOC_CTOR)
2116
            {
2117
              as_bad_where (fixp->fx_file, fixp->fx_line,
2118
                            _("Relocation cannot be done when using -mrelocatable"));
2119
            }
2120
        }
2121
      return;
2122
    }
2123
}
2124
 
2125
/* Prevent elf_frob_file_before_adjust removing a weak undefined
2126
   function descriptor sym if the corresponding code sym is used.  */
2127
 
2128
void
2129
ppc_frob_file_before_adjust (void)
2130
{
2131
  symbolS *symp;
2132
  asection *toc;
2133
 
2134
  if (!ppc_obj64)
2135
    return;
2136
 
2137
  for (symp = symbol_rootP; symp; symp = symbol_next (symp))
2138
    {
2139
      const char *name;
2140
      char *dotname;
2141
      symbolS *dotsym;
2142
      size_t len;
2143
 
2144
      name = S_GET_NAME (symp);
2145
      if (name[0] == '.')
2146
        continue;
2147
 
2148
      if (! S_IS_WEAK (symp)
2149
          || S_IS_DEFINED (symp))
2150
        continue;
2151
 
2152
      len = strlen (name) + 1;
2153
      dotname = xmalloc (len + 1);
2154
      dotname[0] = '.';
2155
      memcpy (dotname + 1, name, len);
2156
      dotsym = symbol_find_noref (dotname, 1);
2157
      free (dotname);
2158
      if (dotsym != NULL && (symbol_used_p (dotsym)
2159
                             || symbol_used_in_reloc_p (dotsym)))
2160
        symbol_mark_used (symp);
2161
 
2162
    }
2163
 
2164
  toc = bfd_get_section_by_name (stdoutput, ".toc");
2165
  if (toc != NULL
2166
      && bfd_section_size (stdoutput, toc) > 0x10000)
2167
    as_warn (_("TOC section size exceeds 64k"));
2168
 
2169
  /* Don't emit .TOC. symbol.  */
2170
  symp = symbol_find (".TOC.");
2171
  if (symp != NULL)
2172
    symbol_remove (symp, &symbol_rootP, &symbol_lastP);
2173
}
2174
#endif /* OBJ_ELF */
2175
 
2176
#ifdef TE_PE
2177
 
2178
/*
2179
 * Summary of parse_toc_entry.
2180
 *
2181
 * in:  Input_line_pointer points to the '[' in one of:
2182
 *
2183
 *        [toc] [tocv] [toc32] [toc64]
2184
 *
2185
 *      Anything else is an error of one kind or another.
2186
 *
2187
 * out:
2188
 *   return value: success or failure
2189
 *   toc_kind:     kind of toc reference
2190
 *   input_line_pointer:
2191
 *     success: first char after the ']'
2192
 *     failure: unchanged
2193
 *
2194
 * settings:
2195
 *
2196
 *     [toc]   - rv == success, toc_kind = default_toc
2197
 *     [tocv]  - rv == success, toc_kind = data_in_toc
2198
 *     [toc32] - rv == success, toc_kind = must_be_32
2199
 *     [toc64] - rv == success, toc_kind = must_be_64
2200
 *
2201
 */
2202
 
2203
enum toc_size_qualifier
2204
{
2205
  default_toc, /* The toc cell constructed should be the system default size */
2206
  data_in_toc, /* This is a direct reference to a toc cell                   */
2207
  must_be_32,  /* The toc cell constructed must be 32 bits wide              */
2208
  must_be_64   /* The toc cell constructed must be 64 bits wide              */
2209
};
2210
 
2211
static int
2212
parse_toc_entry (enum toc_size_qualifier *toc_kind)
2213
{
2214
  char *start;
2215
  char *toc_spec;
2216
  char c;
2217
  enum toc_size_qualifier t;
2218
 
2219
  /* Save the input_line_pointer.  */
2220
  start = input_line_pointer;
2221
 
2222
  /* Skip over the '[' , and whitespace.  */
2223
  ++input_line_pointer;
2224
  SKIP_WHITESPACE ();
2225
 
2226
  /* Find the spelling of the operand.  */
2227
  toc_spec = input_line_pointer;
2228
  c = get_symbol_end ();
2229
 
2230
  if (strcmp (toc_spec, "toc") == 0)
2231
    {
2232
      t = default_toc;
2233
    }
2234
  else if (strcmp (toc_spec, "tocv") == 0)
2235
    {
2236
      t = data_in_toc;
2237
    }
2238
  else if (strcmp (toc_spec, "toc32") == 0)
2239
    {
2240
      t = must_be_32;
2241
    }
2242
  else if (strcmp (toc_spec, "toc64") == 0)
2243
    {
2244
      t = must_be_64;
2245
    }
2246
  else
2247
    {
2248
      as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec);
2249
      *input_line_pointer = c;
2250
      input_line_pointer = start;
2251
      return 0;
2252
    }
2253
 
2254
  /* Now find the ']'.  */
2255
  *input_line_pointer = c;
2256
 
2257
  SKIP_WHITESPACE ();        /* leading whitespace could be there.  */
2258
  c = *input_line_pointer++; /* input_line_pointer->past char in c.  */
2259
 
2260
  if (c != ']')
2261
    {
2262
      as_bad (_("syntax error: expected `]', found  `%c'"), c);
2263
      input_line_pointer = start;
2264
      return 0;
2265
    }
2266
 
2267
  *toc_kind = t;
2268
  return 1;
2269
}
2270
#endif
2271
 
2272
 
2273
#ifdef OBJ_ELF
2274
#define APUID(a,v)      ((((a) & 0xffff) << 16) | ((v) & 0xffff))
2275
static void
2276
ppc_apuinfo_section_add (unsigned int apu, unsigned int version)
2277
{
2278
  unsigned int i;
2279
 
2280
  /* Check we don't already exist.  */
2281
  for (i = 0; i < ppc_apuinfo_num; i++)
2282
    if (ppc_apuinfo_list[i] == APUID (apu, version))
2283
      return;
2284
 
2285
  if (ppc_apuinfo_num == ppc_apuinfo_num_alloc)
2286
    {
2287
      if (ppc_apuinfo_num_alloc == 0)
2288
        {
2289
          ppc_apuinfo_num_alloc = 4;
2290
          ppc_apuinfo_list = (unsigned long *)
2291
              xmalloc (sizeof (unsigned long) * ppc_apuinfo_num_alloc);
2292
        }
2293
      else
2294
        {
2295
          ppc_apuinfo_num_alloc += 4;
2296
          ppc_apuinfo_list = (unsigned long *) xrealloc (ppc_apuinfo_list,
2297
              sizeof (unsigned long) * ppc_apuinfo_num_alloc);
2298
        }
2299
    }
2300
  ppc_apuinfo_list[ppc_apuinfo_num++] = APUID (apu, version);
2301
}
2302
#undef APUID
2303
#endif
2304
 
2305
 
2306
/* We need to keep a list of fixups.  We can't simply generate them as
2307
   we go, because that would require us to first create the frag, and
2308
   that would screw up references to ``.''.  */
2309
 
2310
struct ppc_fixup
2311
{
2312
  expressionS exp;
2313
  int opindex;
2314
  bfd_reloc_code_real_type reloc;
2315
};
2316
 
2317
#define MAX_INSN_FIXUPS (5)
2318
 
2319
/* This routine is called for each instruction to be assembled.  */
2320
 
2321
void
2322
md_assemble (char *str)
2323
{
2324
  char *s;
2325
  const struct powerpc_opcode *opcode;
2326
  unsigned long insn;
2327
  const unsigned char *opindex_ptr;
2328
  int skip_optional;
2329
  int need_paren;
2330
  int next_opindex;
2331
  struct ppc_fixup fixups[MAX_INSN_FIXUPS];
2332
  int fc;
2333
  char *f;
2334
  int addr_mod;
2335
  int i;
2336
#ifdef OBJ_ELF
2337
  bfd_reloc_code_real_type reloc;
2338
#endif
2339
 
2340
  /* Get the opcode.  */
2341
  for (s = str; *s != '\0' && ! ISSPACE (*s); s++)
2342
    ;
2343
  if (*s != '\0')
2344
    *s++ = '\0';
2345
 
2346
  /* Look up the opcode in the hash table.  */
2347
  opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, str);
2348
  if (opcode == (const struct powerpc_opcode *) NULL)
2349
    {
2350
      const struct powerpc_macro *macro;
2351
 
2352
      macro = (const struct powerpc_macro *) hash_find (ppc_macro_hash, str);
2353
      if (macro == (const struct powerpc_macro *) NULL)
2354
        as_bad (_("Unrecognized opcode: `%s'"), str);
2355
      else
2356
        ppc_macro (s, macro);
2357
 
2358
      return;
2359
    }
2360
 
2361
  insn = opcode->opcode;
2362
 
2363
  str = s;
2364
  while (ISSPACE (*str))
2365
    ++str;
2366
 
2367
  /* PowerPC operands are just expressions.  The only real issue is
2368
     that a few operand types are optional.  All cases which might use
2369
     an optional operand separate the operands only with commas (in some
2370
     cases parentheses are used, as in ``lwz 1,0(1)'' but such cases never
2371
     have optional operands).  Most instructions with optional operands
2372
     have only one.  Those that have more than one optional operand can
2373
     take either all their operands or none.  So, before we start seriously
2374
     parsing the operands, we check to see if we have optional operands,
2375
     and if we do, we count the number of commas to see which operands
2376
     have been omitted.  */
2377
  skip_optional = 0;
2378
  for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
2379
    {
2380
      const struct powerpc_operand *operand;
2381
 
2382
      operand = &powerpc_operands[*opindex_ptr];
2383
      if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0)
2384
        {
2385
          unsigned int opcount;
2386
          unsigned int num_operands_expected;
2387
          unsigned int i;
2388
 
2389
          /* There is an optional operand.  Count the number of
2390
             commas in the input line.  */
2391
          if (*str == '\0')
2392
            opcount = 0;
2393
          else
2394
            {
2395
              opcount = 1;
2396
              s = str;
2397
              while ((s = strchr (s, ',')) != (char *) NULL)
2398
                {
2399
                  ++opcount;
2400
                  ++s;
2401
                }
2402
            }
2403
 
2404
          /* Compute the number of expected operands.
2405
             Do not count fake operands.  */
2406
          for (num_operands_expected = 0, i = 0; opcode->operands[i]; i ++)
2407
            if ((powerpc_operands [opcode->operands[i]].flags & PPC_OPERAND_FAKE) == 0)
2408
              ++ num_operands_expected;
2409
 
2410
          /* If there are fewer operands in the line then are called
2411
             for by the instruction, we want to skip the optional
2412
             operands.  */
2413
          if (opcount < num_operands_expected)
2414
            skip_optional = 1;
2415
 
2416
          break;
2417
        }
2418
    }
2419
 
2420
  /* Gather the operands.  */
2421
  need_paren = 0;
2422
  next_opindex = 0;
2423
  fc = 0;
2424
  for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
2425
    {
2426
      const struct powerpc_operand *operand;
2427
      const char *errmsg;
2428
      char *hold;
2429
      expressionS ex;
2430
      char endc;
2431
 
2432
      if (next_opindex == 0)
2433
        operand = &powerpc_operands[*opindex_ptr];
2434
      else
2435
        {
2436
          operand = &powerpc_operands[next_opindex];
2437
          next_opindex = 0;
2438
        }
2439
      errmsg = NULL;
2440
 
2441
      /* If this is a fake operand, then we do not expect anything
2442
         from the input.  */
2443
      if ((operand->flags & PPC_OPERAND_FAKE) != 0)
2444
        {
2445
          insn = (*operand->insert) (insn, 0L, ppc_cpu, &errmsg);
2446
          if (errmsg != (const char *) NULL)
2447
            as_bad ("%s", errmsg);
2448
          continue;
2449
        }
2450
 
2451
      /* If this is an optional operand, and we are skipping it, just
2452
         insert a zero.  */
2453
      if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0
2454
          && skip_optional)
2455
        {
2456
          if (operand->insert)
2457
            {
2458
              insn = (*operand->insert) (insn, 0L, ppc_cpu, &errmsg);
2459
              if (errmsg != (const char *) NULL)
2460
                as_bad ("%s", errmsg);
2461
            }
2462
          if ((operand->flags & PPC_OPERAND_NEXT) != 0)
2463
            next_opindex = *opindex_ptr + 1;
2464
          continue;
2465
        }
2466
 
2467
      /* Gather the operand.  */
2468
      hold = input_line_pointer;
2469
      input_line_pointer = str;
2470
 
2471
#ifdef TE_PE
2472
      if (*input_line_pointer == '[')
2473
        {
2474
          /* We are expecting something like the second argument here:
2475
           *
2476
           *    lwz r4,[toc].GS.0.static_int(rtoc)
2477
           *           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2478
           * The argument following the `]' must be a symbol name, and the
2479
           * register must be the toc register: 'rtoc' or '2'
2480
           *
2481
           * The effect is to 0 as the displacement field
2482
           * in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
2483
           * the appropriate variation) reloc against it based on the symbol.
2484
           * The linker will build the toc, and insert the resolved toc offset.
2485
           *
2486
           * Note:
2487
           * o The size of the toc entry is currently assumed to be
2488
           *   32 bits. This should not be assumed to be a hard coded
2489
           *   number.
2490
           * o In an effort to cope with a change from 32 to 64 bits,
2491
           *   there are also toc entries that are specified to be
2492
           *   either 32 or 64 bits:
2493
           *     lwz r4,[toc32].GS.0.static_int(rtoc)
2494
           *     lwz r4,[toc64].GS.0.static_int(rtoc)
2495
           *   These demand toc entries of the specified size, and the
2496
           *   instruction probably requires it.
2497
           */
2498
 
2499
          int valid_toc;
2500
          enum toc_size_qualifier toc_kind;
2501
          bfd_reloc_code_real_type toc_reloc;
2502
 
2503
          /* Go parse off the [tocXX] part.  */
2504
          valid_toc = parse_toc_entry (&toc_kind);
2505
 
2506
          if (!valid_toc)
2507
            {
2508
              /* Note: message has already been issued.
2509
                 FIXME: what sort of recovery should we do?
2510
                 demand_rest_of_line (); return; ?  */
2511
            }
2512
 
2513
          /* Now get the symbol following the ']'.  */
2514
          expression (&ex);
2515
 
2516
          switch (toc_kind)
2517
            {
2518
            case default_toc:
2519
              /* In this case, we may not have seen the symbol yet,
2520
                 since  it is allowed to appear on a .extern or .globl
2521
                 or just be a label in the .data section.  */
2522
              toc_reloc = BFD_RELOC_PPC_TOC16;
2523
              break;
2524
            case data_in_toc:
2525
              /* 1. The symbol must be defined and either in the toc
2526
                 section, or a global.
2527
                 2. The reloc generated must have the TOCDEFN flag set
2528
                 in upper bit mess of the reloc type.
2529
                 FIXME: It's a little confusing what the tocv
2530
                 qualifier can be used for.  At the very least, I've
2531
                 seen three uses, only one of which I'm sure I can
2532
                 explain.  */
2533
              if (ex.X_op == O_symbol)
2534
                {
2535
                  gas_assert (ex.X_add_symbol != NULL);
2536
                  if (symbol_get_bfdsym (ex.X_add_symbol)->section
2537
                      != tocdata_section)
2538
                    {
2539
                      as_bad (_("[tocv] symbol is not a toc symbol"));
2540
                    }
2541
                }
2542
 
2543
              toc_reloc = BFD_RELOC_PPC_TOC16;
2544
              break;
2545
            case must_be_32:
2546
              /* FIXME: these next two specifically specify 32/64 bit
2547
                 toc entries.  We don't support them today.  Is this
2548
                 the right way to say that?  */
2549
              toc_reloc = BFD_RELOC_UNUSED;
2550
              as_bad (_("Unimplemented toc32 expression modifier"));
2551
              break;
2552
            case must_be_64:
2553
              /* FIXME: see above.  */
2554
              toc_reloc = BFD_RELOC_UNUSED;
2555
              as_bad (_("Unimplemented toc64 expression modifier"));
2556
              break;
2557
            default:
2558
              fprintf (stderr,
2559
                       _("Unexpected return value [%d] from parse_toc_entry!\n"),
2560
                       toc_kind);
2561
              abort ();
2562
              break;
2563
            }
2564
 
2565
          /* We need to generate a fixup for this expression.  */
2566
          if (fc >= MAX_INSN_FIXUPS)
2567
            as_fatal (_("too many fixups"));
2568
 
2569
          fixups[fc].reloc = toc_reloc;
2570
          fixups[fc].exp = ex;
2571
          fixups[fc].opindex = *opindex_ptr;
2572
          ++fc;
2573
 
2574
          /* Ok. We've set up the fixup for the instruction. Now make it
2575
             look like the constant 0 was found here.  */
2576
          ex.X_unsigned = 1;
2577
          ex.X_op = O_constant;
2578
          ex.X_add_number = 0;
2579
          ex.X_add_symbol = NULL;
2580
          ex.X_op_symbol = NULL;
2581
        }
2582
 
2583
      else
2584
#endif          /* TE_PE */
2585
        {
2586
          if ((reg_names_p && (operand->flags & PPC_OPERAND_CR) != 0)
2587
              || !register_name (&ex))
2588
            {
2589
              char save_lex = lex_type['%'];
2590
 
2591
              if ((operand->flags & PPC_OPERAND_CR) != 0)
2592
                {
2593
                  cr_operand = TRUE;
2594
                  lex_type['%'] |= LEX_BEGIN_NAME;
2595
                }
2596
              expression (&ex);
2597
              cr_operand = FALSE;
2598
              lex_type['%'] = save_lex;
2599
            }
2600
        }
2601
 
2602
      str = input_line_pointer;
2603
      input_line_pointer = hold;
2604
 
2605
      if (ex.X_op == O_illegal)
2606
        as_bad (_("illegal operand"));
2607
      else if (ex.X_op == O_absent)
2608
        as_bad (_("missing operand"));
2609
      else if (ex.X_op == O_register)
2610
        {
2611
          insn = ppc_insert_operand (insn, operand, ex.X_add_number,
2612
                                     ppc_cpu, (char *) NULL, 0);
2613
        }
2614
      else if (ex.X_op == O_constant)
2615
        {
2616
#ifdef OBJ_ELF
2617
          /* Allow @HA, @L, @H on constants.  */
2618
          char *orig_str = str;
2619
 
2620
          if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
2621
            switch (reloc)
2622
              {
2623
              default:
2624
                str = orig_str;
2625
                break;
2626
 
2627
              case BFD_RELOC_LO16:
2628
                /* X_unsigned is the default, so if the user has done
2629
                   something which cleared it, we always produce a
2630
                   signed value.  */
2631
                if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2632
                  ex.X_add_number &= 0xffff;
2633
                else
2634
                  ex.X_add_number = SEX16 (ex.X_add_number);
2635
                break;
2636
 
2637
              case BFD_RELOC_HI16:
2638
                if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2639
                  ex.X_add_number = PPC_HI (ex.X_add_number);
2640
                else
2641
                  ex.X_add_number = SEX16 (PPC_HI (ex.X_add_number));
2642
                break;
2643
 
2644
              case BFD_RELOC_HI16_S:
2645
                if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2646
                  ex.X_add_number = PPC_HA (ex.X_add_number);
2647
                else
2648
                  ex.X_add_number = SEX16 (PPC_HA (ex.X_add_number));
2649
                break;
2650
 
2651
              case BFD_RELOC_PPC64_HIGHER:
2652
                if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2653
                  ex.X_add_number = PPC_HIGHER (ex.X_add_number);
2654
                else
2655
                  ex.X_add_number = SEX16 (PPC_HIGHER (ex.X_add_number));
2656
                break;
2657
 
2658
              case BFD_RELOC_PPC64_HIGHER_S:
2659
                if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2660
                  ex.X_add_number = PPC_HIGHERA (ex.X_add_number);
2661
                else
2662
                  ex.X_add_number = SEX16 (PPC_HIGHERA (ex.X_add_number));
2663
                break;
2664
 
2665
              case BFD_RELOC_PPC64_HIGHEST:
2666
                if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2667
                  ex.X_add_number = PPC_HIGHEST (ex.X_add_number);
2668
                else
2669
                  ex.X_add_number = SEX16 (PPC_HIGHEST (ex.X_add_number));
2670
                break;
2671
 
2672
              case BFD_RELOC_PPC64_HIGHEST_S:
2673
                if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2674
                  ex.X_add_number = PPC_HIGHESTA (ex.X_add_number);
2675
                else
2676
                  ex.X_add_number = SEX16 (PPC_HIGHESTA (ex.X_add_number));
2677
                break;
2678
              }
2679
#endif /* OBJ_ELF */
2680
          insn = ppc_insert_operand (insn, operand, ex.X_add_number,
2681
                                     ppc_cpu, (char *) NULL, 0);
2682
        }
2683
#ifdef OBJ_ELF
2684
      else
2685
        {
2686
          if (ex.X_op == O_symbol && str[0] == '(')
2687
            {
2688
              const char *sym_name = S_GET_NAME (ex.X_add_symbol);
2689
              if (sym_name[0] == '.')
2690
                ++sym_name;
2691
 
2692
              if (strcasecmp (sym_name, "__tls_get_addr") == 0)
2693
                {
2694
                  expressionS tls_exp;
2695
 
2696
                  hold = input_line_pointer;
2697
                  input_line_pointer = str + 1;
2698
                  expression (&tls_exp);
2699
                  if (tls_exp.X_op == O_symbol)
2700
                    {
2701
                      reloc = BFD_RELOC_UNUSED;
2702
                      if (strncasecmp (input_line_pointer, "@tlsgd)", 7) == 0)
2703
                        {
2704
                          reloc = BFD_RELOC_PPC_TLSGD;
2705
                          input_line_pointer += 7;
2706
                        }
2707
                      else if (strncasecmp (input_line_pointer, "@tlsld)", 7) == 0)
2708
                        {
2709
                          reloc = BFD_RELOC_PPC_TLSLD;
2710
                          input_line_pointer += 7;
2711
                        }
2712
                      if (reloc != BFD_RELOC_UNUSED)
2713
                        {
2714
                          SKIP_WHITESPACE ();
2715
                          str = input_line_pointer;
2716
 
2717
                          if (fc >= MAX_INSN_FIXUPS)
2718
                            as_fatal (_("too many fixups"));
2719
                          fixups[fc].exp = tls_exp;
2720
                          fixups[fc].opindex = *opindex_ptr;
2721
                          fixups[fc].reloc = reloc;
2722
                          ++fc;
2723
                        }
2724
                    }
2725
                  input_line_pointer = hold;
2726
                }
2727
            }
2728
 
2729
          if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
2730
            {
2731
              /* Some TLS tweaks.  */
2732
              switch (reloc)
2733
                {
2734
                default:
2735
                  break;
2736
 
2737
                case BFD_RELOC_PPC_TLS:
2738
                  insn = ppc_insert_operand (insn, operand, ppc_obj64 ? 13 : 2,
2739
                                             ppc_cpu, (char *) NULL, 0);
2740
                  break;
2741
 
2742
                  /* We'll only use the 32 (or 64) bit form of these relocations
2743
                     in constants.  Instructions get the 16 bit form.  */
2744
                case BFD_RELOC_PPC_DTPREL:
2745
                  reloc = BFD_RELOC_PPC_DTPREL16;
2746
                  break;
2747
                case BFD_RELOC_PPC_TPREL:
2748
                  reloc = BFD_RELOC_PPC_TPREL16;
2749
                  break;
2750
                }
2751
 
2752
              /* For the absolute forms of branches, convert the PC
2753
                 relative form back into the absolute.  */
2754
              if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0)
2755
                {
2756
                  switch (reloc)
2757
                    {
2758
                    case BFD_RELOC_PPC_B26:
2759
                      reloc = BFD_RELOC_PPC_BA26;
2760
                      break;
2761
                    case BFD_RELOC_PPC_B16:
2762
                      reloc = BFD_RELOC_PPC_BA16;
2763
                      break;
2764
                    case BFD_RELOC_PPC_B16_BRTAKEN:
2765
                      reloc = BFD_RELOC_PPC_BA16_BRTAKEN;
2766
                      break;
2767
                    case BFD_RELOC_PPC_B16_BRNTAKEN:
2768
                      reloc = BFD_RELOC_PPC_BA16_BRNTAKEN;
2769
                      break;
2770
                    default:
2771
                      break;
2772
                    }
2773
                }
2774
 
2775
              if (ppc_obj64
2776
                  && (operand->flags & (PPC_OPERAND_DS | PPC_OPERAND_DQ)) != 0)
2777
                {
2778
                  switch (reloc)
2779
                    {
2780
                    case BFD_RELOC_16:
2781
                      reloc = BFD_RELOC_PPC64_ADDR16_DS;
2782
                      break;
2783
                    case BFD_RELOC_LO16:
2784
                      reloc = BFD_RELOC_PPC64_ADDR16_LO_DS;
2785
                      break;
2786
                    case BFD_RELOC_16_GOTOFF:
2787
                      reloc = BFD_RELOC_PPC64_GOT16_DS;
2788
                      break;
2789
                    case BFD_RELOC_LO16_GOTOFF:
2790
                      reloc = BFD_RELOC_PPC64_GOT16_LO_DS;
2791
                      break;
2792
                    case BFD_RELOC_LO16_PLTOFF:
2793
                      reloc = BFD_RELOC_PPC64_PLT16_LO_DS;
2794
                      break;
2795
                    case BFD_RELOC_16_BASEREL:
2796
                      reloc = BFD_RELOC_PPC64_SECTOFF_DS;
2797
                      break;
2798
                    case BFD_RELOC_LO16_BASEREL:
2799
                      reloc = BFD_RELOC_PPC64_SECTOFF_LO_DS;
2800
                      break;
2801
                    case BFD_RELOC_PPC_TOC16:
2802
                      reloc = BFD_RELOC_PPC64_TOC16_DS;
2803
                      break;
2804
                    case BFD_RELOC_PPC64_TOC16_LO:
2805
                      reloc = BFD_RELOC_PPC64_TOC16_LO_DS;
2806
                      break;
2807
                    case BFD_RELOC_PPC64_PLTGOT16:
2808
                      reloc = BFD_RELOC_PPC64_PLTGOT16_DS;
2809
                      break;
2810
                    case BFD_RELOC_PPC64_PLTGOT16_LO:
2811
                      reloc = BFD_RELOC_PPC64_PLTGOT16_LO_DS;
2812
                      break;
2813
                    case BFD_RELOC_PPC_DTPREL16:
2814
                      reloc = BFD_RELOC_PPC64_DTPREL16_DS;
2815
                      break;
2816
                    case BFD_RELOC_PPC_DTPREL16_LO:
2817
                      reloc = BFD_RELOC_PPC64_DTPREL16_LO_DS;
2818
                      break;
2819
                    case BFD_RELOC_PPC_TPREL16:
2820
                      reloc = BFD_RELOC_PPC64_TPREL16_DS;
2821
                      break;
2822
                    case BFD_RELOC_PPC_TPREL16_LO:
2823
                      reloc = BFD_RELOC_PPC64_TPREL16_LO_DS;
2824
                      break;
2825
                    case BFD_RELOC_PPC_GOT_DTPREL16:
2826
                    case BFD_RELOC_PPC_GOT_DTPREL16_LO:
2827
                    case BFD_RELOC_PPC_GOT_TPREL16:
2828
                    case BFD_RELOC_PPC_GOT_TPREL16_LO:
2829
                      break;
2830
                    default:
2831
                      as_bad (_("unsupported relocation for DS offset field"));
2832
                      break;
2833
                    }
2834
                }
2835
            }
2836
 
2837
          /* We need to generate a fixup for this expression.  */
2838
          if (fc >= MAX_INSN_FIXUPS)
2839
            as_fatal (_("too many fixups"));
2840
          fixups[fc].exp = ex;
2841
          fixups[fc].opindex = *opindex_ptr;
2842
          fixups[fc].reloc = reloc;
2843
          ++fc;
2844
        }
2845
#else /* OBJ_ELF */
2846
      else
2847
        {
2848
          /* We need to generate a fixup for this expression.  */
2849
          if (fc >= MAX_INSN_FIXUPS)
2850
            as_fatal (_("too many fixups"));
2851
          fixups[fc].exp = ex;
2852
          fixups[fc].opindex = *opindex_ptr;
2853
          fixups[fc].reloc = BFD_RELOC_UNUSED;
2854
          ++fc;
2855
        }
2856
#endif /* OBJ_ELF */
2857
 
2858
      if (need_paren)
2859
        {
2860
          endc = ')';
2861
          need_paren = 0;
2862
          /* If expecting more operands, then we want to see "),".  */
2863
          if (*str == endc && opindex_ptr[1] != 0)
2864
            {
2865
              do
2866
                ++str;
2867
              while (ISSPACE (*str));
2868
              endc = ',';
2869
            }
2870
        }
2871
      else if ((operand->flags & PPC_OPERAND_PARENS) != 0)
2872
        {
2873
          endc = '(';
2874
          need_paren = 1;
2875
        }
2876
      else
2877
        endc = ',';
2878
 
2879
      /* The call to expression should have advanced str past any
2880
         whitespace.  */
2881
      if (*str != endc
2882
          && (endc != ',' || *str != '\0'))
2883
        {
2884
          as_bad (_("syntax error; found `%c' but expected `%c'"), *str, endc);
2885
          break;
2886
        }
2887
 
2888
      if (*str != '\0')
2889
        ++str;
2890
    }
2891
 
2892
  while (ISSPACE (*str))
2893
    ++str;
2894
 
2895
  if (*str != '\0')
2896
    as_bad (_("junk at end of line: `%s'"), str);
2897
 
2898
#ifdef OBJ_ELF
2899
  /* Do we need/want a APUinfo section? */
2900
  if ((ppc_cpu & PPC_OPCODE_E500MC) != 0)
2901
    {
2902
      /* These are all version "1".  */
2903
      if (opcode->flags & PPC_OPCODE_SPE)
2904
        ppc_apuinfo_section_add (PPC_APUINFO_SPE, 1);
2905
      if (opcode->flags & PPC_OPCODE_ISEL)
2906
        ppc_apuinfo_section_add (PPC_APUINFO_ISEL, 1);
2907
      if (opcode->flags & PPC_OPCODE_EFS)
2908
        ppc_apuinfo_section_add (PPC_APUINFO_EFS, 1);
2909
      if (opcode->flags & PPC_OPCODE_BRLOCK)
2910
        ppc_apuinfo_section_add (PPC_APUINFO_BRLOCK, 1);
2911
      if (opcode->flags & PPC_OPCODE_PMR)
2912
        ppc_apuinfo_section_add (PPC_APUINFO_PMR, 1);
2913
      if (opcode->flags & PPC_OPCODE_CACHELCK)
2914
        ppc_apuinfo_section_add (PPC_APUINFO_CACHELCK, 1);
2915
      if (opcode->flags & PPC_OPCODE_RFMCI)
2916
        ppc_apuinfo_section_add (PPC_APUINFO_RFMCI, 1);
2917
    }
2918
#endif
2919
 
2920
  /* Write out the instruction.  */
2921
  f = frag_more (4);
2922
  addr_mod = frag_now_fix () & 3;
2923
  if (frag_now->has_code && frag_now->insn_addr != addr_mod)
2924
    as_bad (_("instruction address is not a multiple of 4"));
2925
  frag_now->insn_addr = addr_mod;
2926
  frag_now->has_code = 1;
2927
  md_number_to_chars (f, insn, 4);
2928
 
2929
#ifdef OBJ_ELF
2930
  dwarf2_emit_insn (4);
2931
#endif
2932
 
2933
  /* Create any fixups.  At this point we do not use a
2934
     bfd_reloc_code_real_type, but instead just use the
2935
     BFD_RELOC_UNUSED plus the operand index.  This lets us easily
2936
     handle fixups for any operand type, although that is admittedly
2937
     not a very exciting feature.  We pick a BFD reloc type in
2938
     md_apply_fix.  */
2939
  for (i = 0; i < fc; i++)
2940
    {
2941
      if (fixups[i].reloc != BFD_RELOC_UNUSED)
2942
        {
2943
          reloc_howto_type *reloc_howto;
2944
          int size;
2945
          int offset;
2946
          fixS *fixP;
2947
 
2948
          reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
2949
          if (!reloc_howto)
2950
            abort ();
2951
 
2952
          size = bfd_get_reloc_size (reloc_howto);
2953
          offset = target_big_endian ? (4 - size) : 0;
2954
 
2955
          if (size < 1 || size > 4)
2956
            abort ();
2957
 
2958
          fixP = fix_new_exp (frag_now,
2959
                              f - frag_now->fr_literal + offset,
2960
                              size,
2961
                              &fixups[i].exp,
2962
                              reloc_howto->pc_relative,
2963
                              fixups[i].reloc);
2964
 
2965
          /* Turn off complaints that the addend is too large for things like
2966
             foo+100000@ha.  */
2967
          switch (fixups[i].reloc)
2968
            {
2969
            case BFD_RELOC_16_GOTOFF:
2970
            case BFD_RELOC_PPC_TOC16:
2971
            case BFD_RELOC_LO16:
2972
            case BFD_RELOC_HI16:
2973
            case BFD_RELOC_HI16_S:
2974
#ifdef OBJ_ELF
2975
            case BFD_RELOC_PPC64_HIGHER:
2976
            case BFD_RELOC_PPC64_HIGHER_S:
2977
            case BFD_RELOC_PPC64_HIGHEST:
2978
            case BFD_RELOC_PPC64_HIGHEST_S:
2979
#endif
2980
              fixP->fx_no_overflow = 1;
2981
              break;
2982
            default:
2983
              break;
2984
            }
2985
        }
2986
      else
2987
        {
2988
          const struct powerpc_operand *operand;
2989
 
2990
          operand = &powerpc_operands[fixups[i].opindex];
2991
          fix_new_exp (frag_now,
2992
                       f - frag_now->fr_literal,
2993
                       4,
2994
                       &fixups[i].exp,
2995
                       (operand->flags & PPC_OPERAND_RELATIVE) != 0,
2996
                       ((bfd_reloc_code_real_type)
2997
                        (fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
2998
        }
2999
    }
3000
}
3001
 
3002
/* Handle a macro.  Gather all the operands, transform them as
3003
   described by the macro, and call md_assemble recursively.  All the
3004
   operands are separated by commas; we don't accept parentheses
3005
   around operands here.  */
3006
 
3007
static void
3008
ppc_macro (char *str, const struct powerpc_macro *macro)
3009
{
3010
  char *operands[10];
3011
  unsigned int count;
3012
  char *s;
3013
  unsigned int len;
3014
  const char *format;
3015
  unsigned int arg;
3016
  char *send;
3017
  char *complete;
3018
 
3019
  /* Gather the users operands into the operands array.  */
3020
  count = 0;
3021
  s = str;
3022
  while (1)
3023
    {
3024
      if (count >= sizeof operands / sizeof operands[0])
3025
        break;
3026
      operands[count++] = s;
3027
      s = strchr (s, ',');
3028
      if (s == (char *) NULL)
3029
        break;
3030
      *s++ = '\0';
3031
    }
3032
 
3033
  if (count != macro->operands)
3034
    {
3035
      as_bad (_("wrong number of operands"));
3036
      return;
3037
    }
3038
 
3039
  /* Work out how large the string must be (the size is unbounded
3040
     because it includes user input).  */
3041
  len = 0;
3042
  format = macro->format;
3043
  while (*format != '\0')
3044
    {
3045
      if (*format != '%')
3046
        {
3047
          ++len;
3048
          ++format;
3049
        }
3050
      else
3051
        {
3052
          arg = strtol (format + 1, &send, 10);
3053
          know (send != format && arg < count);
3054
          len += strlen (operands[arg]);
3055
          format = send;
3056
        }
3057
    }
3058
 
3059
  /* Put the string together.  */
3060
  complete = s = (char *) alloca (len + 1);
3061
  format = macro->format;
3062
  while (*format != '\0')
3063
    {
3064
      if (*format != '%')
3065
        *s++ = *format++;
3066
      else
3067
        {
3068
          arg = strtol (format + 1, &send, 10);
3069
          strcpy (s, operands[arg]);
3070
          s += strlen (s);
3071
          format = send;
3072
        }
3073
    }
3074
  *s = '\0';
3075
 
3076
  /* Assemble the constructed instruction.  */
3077
  md_assemble (complete);
3078
}
3079
 
3080
#ifdef OBJ_ELF
3081
/* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED.  */
3082
 
3083
bfd_vma
3084
ppc_section_letter (int letter, char **ptr_msg)
3085
{
3086
  if (letter == 'e')
3087
    return SHF_EXCLUDE;
3088
 
3089
  *ptr_msg = _("Bad .section directive: want a,e,w,x,M,S,G,T in string");
3090
  return -1;
3091
}
3092
 
3093
bfd_vma
3094
ppc_section_word (char *str, size_t len)
3095
{
3096
  if (len == 7 && strncmp (str, "exclude", 7) == 0)
3097
    return SHF_EXCLUDE;
3098
 
3099
  return -1;
3100
}
3101
 
3102
int
3103
ppc_section_type (char *str, size_t len)
3104
{
3105
  if (len == 7 && strncmp (str, "ordered", 7) == 0)
3106
    return SHT_ORDERED;
3107
 
3108
  return -1;
3109
}
3110
 
3111
int
3112
ppc_section_flags (flagword flags, bfd_vma attr, int type)
3113
{
3114
  if (type == SHT_ORDERED)
3115
    flags |= SEC_ALLOC | SEC_LOAD | SEC_SORT_ENTRIES;
3116
 
3117
  if (attr & SHF_EXCLUDE)
3118
    flags |= SEC_EXCLUDE;
3119
 
3120
  return flags;
3121
}
3122
#endif /* OBJ_ELF */
3123
 
3124
 
3125
/* Pseudo-op handling.  */
3126
 
3127
/* The .byte pseudo-op.  This is similar to the normal .byte
3128
   pseudo-op, but it can also take a single ASCII string.  */
3129
 
3130
static void
3131
ppc_byte (int ignore ATTRIBUTE_UNUSED)
3132
{
3133
  if (*input_line_pointer != '\"')
3134
    {
3135
      cons (1);
3136
      return;
3137
    }
3138
 
3139
  /* Gather characters.  A real double quote is doubled.  Unusual
3140
     characters are not permitted.  */
3141
  ++input_line_pointer;
3142
  while (1)
3143
    {
3144
      char c;
3145
 
3146
      c = *input_line_pointer++;
3147
 
3148
      if (c == '\"')
3149
        {
3150
          if (*input_line_pointer != '\"')
3151
            break;
3152
          ++input_line_pointer;
3153
        }
3154
 
3155
      FRAG_APPEND_1_CHAR (c);
3156
    }
3157
 
3158
  demand_empty_rest_of_line ();
3159
}
3160
 
3161
#ifdef OBJ_XCOFF
3162
 
3163
/* XCOFF specific pseudo-op handling.  */
3164
 
3165
/* This is set if we are creating a .stabx symbol, since we don't want
3166
   to handle symbol suffixes for such symbols.  */
3167
static bfd_boolean ppc_stab_symbol;
3168
 
3169
/* The .comm and .lcomm pseudo-ops for XCOFF.  XCOFF puts common
3170
   symbols in the .bss segment as though they were local common
3171
   symbols, and uses a different smclas.  The native Aix 4.3.3 assembler
3172
   aligns .comm and .lcomm to 4 bytes.  */
3173
 
3174
static void
3175
ppc_comm (int lcomm)
3176
{
3177
  asection *current_seg = now_seg;
3178
  subsegT current_subseg = now_subseg;
3179
  char *name;
3180
  char endc;
3181
  char *end_name;
3182
  offsetT size;
3183
  offsetT align;
3184
  symbolS *lcomm_sym = NULL;
3185
  symbolS *sym;
3186
  char *pfrag;
3187
 
3188
  name = input_line_pointer;
3189
  endc = get_symbol_end ();
3190
  end_name = input_line_pointer;
3191
  *end_name = endc;
3192
 
3193
  if (*input_line_pointer != ',')
3194
    {
3195
      as_bad (_("missing size"));
3196
      ignore_rest_of_line ();
3197
      return;
3198
    }
3199
  ++input_line_pointer;
3200
 
3201
  size = get_absolute_expression ();
3202
  if (size < 0)
3203
    {
3204
      as_bad (_("negative size"));
3205
      ignore_rest_of_line ();
3206
      return;
3207
    }
3208
 
3209
  if (! lcomm)
3210
    {
3211
      /* The third argument to .comm is the alignment.  */
3212
      if (*input_line_pointer != ',')
3213
        align = 2;
3214
      else
3215
        {
3216
          ++input_line_pointer;
3217
          align = get_absolute_expression ();
3218
          if (align <= 0)
3219
            {
3220
              as_warn (_("ignoring bad alignment"));
3221
              align = 2;
3222
            }
3223
        }
3224
    }
3225
  else
3226
    {
3227
      char *lcomm_name;
3228
      char lcomm_endc;
3229
 
3230
      if (size <= 4)
3231
        align = 2;
3232
      else
3233
        align = 3;
3234
 
3235
      /* The third argument to .lcomm appears to be the real local
3236
         common symbol to create.  References to the symbol named in
3237
         the first argument are turned into references to the third
3238
         argument.  */
3239
      if (*input_line_pointer != ',')
3240
        {
3241
          as_bad (_("missing real symbol name"));
3242
          ignore_rest_of_line ();
3243
          return;
3244
        }
3245
      ++input_line_pointer;
3246
 
3247
      lcomm_name = input_line_pointer;
3248
      lcomm_endc = get_symbol_end ();
3249
 
3250
      lcomm_sym = symbol_find_or_make (lcomm_name);
3251
 
3252
      *input_line_pointer = lcomm_endc;
3253
    }
3254
 
3255
  *end_name = '\0';
3256
  sym = symbol_find_or_make (name);
3257
  *end_name = endc;
3258
 
3259
  if (S_IS_DEFINED (sym)
3260
      || S_GET_VALUE (sym) != 0)
3261
    {
3262
      as_bad (_("attempt to redefine symbol"));
3263
      ignore_rest_of_line ();
3264
      return;
3265
    }
3266
 
3267
  record_alignment (bss_section, align);
3268
 
3269
  if (! lcomm
3270
      || ! S_IS_DEFINED (lcomm_sym))
3271
    {
3272
      symbolS *def_sym;
3273
      offsetT def_size;
3274
 
3275
      if (! lcomm)
3276
        {
3277
          def_sym = sym;
3278
          def_size = size;
3279
          S_SET_EXTERNAL (sym);
3280
        }
3281
      else
3282
        {
3283
          symbol_get_tc (lcomm_sym)->output = 1;
3284
          def_sym = lcomm_sym;
3285
          def_size = 0;
3286
        }
3287
 
3288
      subseg_set (bss_section, 1);
3289
      frag_align (align, 0, 0);
3290
 
3291
      symbol_set_frag (def_sym, frag_now);
3292
      pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, def_sym,
3293
                        def_size, (char *) NULL);
3294
      *pfrag = 0;
3295
      S_SET_SEGMENT (def_sym, bss_section);
3296
      symbol_get_tc (def_sym)->align = align;
3297
    }
3298
  else if (lcomm)
3299
    {
3300
      /* Align the size of lcomm_sym.  */
3301
      symbol_get_frag (lcomm_sym)->fr_offset =
3302
        ((symbol_get_frag (lcomm_sym)->fr_offset + (1 << align) - 1)
3303
         &~ ((1 << align) - 1));
3304
      if (align > symbol_get_tc (lcomm_sym)->align)
3305
        symbol_get_tc (lcomm_sym)->align = align;
3306
    }
3307
 
3308
  if (lcomm)
3309
    {
3310
      /* Make sym an offset from lcomm_sym.  */
3311
      S_SET_SEGMENT (sym, bss_section);
3312
      symbol_set_frag (sym, symbol_get_frag (lcomm_sym));
3313
      S_SET_VALUE (sym, symbol_get_frag (lcomm_sym)->fr_offset);
3314
      symbol_get_frag (lcomm_sym)->fr_offset += size;
3315
    }
3316
 
3317
  subseg_set (current_seg, current_subseg);
3318
 
3319
  demand_empty_rest_of_line ();
3320
}
3321
 
3322
/* The .csect pseudo-op.  This switches us into a different
3323
   subsegment.  The first argument is a symbol whose value is the
3324
   start of the .csect.  In COFF, csect symbols get special aux
3325
   entries defined by the x_csect field of union internal_auxent.  The
3326
   optional second argument is the alignment (the default is 2).  */
3327
 
3328
static void
3329
ppc_csect (int ignore ATTRIBUTE_UNUSED)
3330
{
3331
  char *name;
3332
  char endc;
3333
  symbolS *sym;
3334
  offsetT align;
3335
 
3336
  name = input_line_pointer;
3337
  endc = get_symbol_end ();
3338
 
3339
  sym = symbol_find_or_make (name);
3340
 
3341
  *input_line_pointer = endc;
3342
 
3343
  if (S_GET_NAME (sym)[0] == '\0')
3344
    {
3345
      /* An unnamed csect is assumed to be [PR].  */
3346
      symbol_get_tc (sym)->symbol_class = XMC_PR;
3347
    }
3348
 
3349
  align = 2;
3350
  if (*input_line_pointer == ',')
3351
    {
3352
      ++input_line_pointer;
3353
      align = get_absolute_expression ();
3354
    }
3355
 
3356
  ppc_change_csect (sym, align);
3357
 
3358
  demand_empty_rest_of_line ();
3359
}
3360
 
3361
/* Change to a different csect.  */
3362
 
3363
static void
3364
ppc_change_csect (symbolS *sym, offsetT align)
3365
{
3366
  if (S_IS_DEFINED (sym))
3367
    subseg_set (S_GET_SEGMENT (sym), symbol_get_tc (sym)->subseg);
3368
  else
3369
    {
3370
      symbolS **list_ptr;
3371
      int after_toc;
3372
      int hold_chunksize;
3373
      symbolS *list;
3374
      int is_code;
3375
      segT sec;
3376
 
3377
      /* This is a new csect.  We need to look at the symbol class to
3378
         figure out whether it should go in the text section or the
3379
         data section.  */
3380
      after_toc = 0;
3381
      is_code = 0;
3382
      switch (symbol_get_tc (sym)->symbol_class)
3383
        {
3384
        case XMC_PR:
3385
        case XMC_RO:
3386
        case XMC_DB:
3387
        case XMC_GL:
3388
        case XMC_XO:
3389
        case XMC_SV:
3390
        case XMC_TI:
3391
        case XMC_TB:
3392
          S_SET_SEGMENT (sym, text_section);
3393
          symbol_get_tc (sym)->subseg = ppc_text_subsegment;
3394
          ++ppc_text_subsegment;
3395
          list_ptr = &ppc_text_csects;
3396
          is_code = 1;
3397
          break;
3398
        case XMC_RW:
3399
        case XMC_TC0:
3400
        case XMC_TC:
3401
        case XMC_DS:
3402
        case XMC_UA:
3403
        case XMC_BS:
3404
        case XMC_UC:
3405
          if (ppc_toc_csect != NULL
3406
              && (symbol_get_tc (ppc_toc_csect)->subseg + 1
3407
                  == ppc_data_subsegment))
3408
            after_toc = 1;
3409
          S_SET_SEGMENT (sym, data_section);
3410
          symbol_get_tc (sym)->subseg = ppc_data_subsegment;
3411
          ++ppc_data_subsegment;
3412
          list_ptr = &ppc_data_csects;
3413
          break;
3414
        default:
3415
          abort ();
3416
        }
3417
 
3418
      /* We set the obstack chunk size to a small value before
3419
         changing subsegments, so that we don't use a lot of memory
3420
         space for what may be a small section.  */
3421
      hold_chunksize = chunksize;
3422
      chunksize = 64;
3423
 
3424
      sec = subseg_new (segment_name (S_GET_SEGMENT (sym)),
3425
                        symbol_get_tc (sym)->subseg);
3426
 
3427
      chunksize = hold_chunksize;
3428
 
3429
      if (after_toc)
3430
        ppc_after_toc_frag = frag_now;
3431
 
3432
      record_alignment (sec, align);
3433
      if (is_code)
3434
        frag_align_code (align, 0);
3435
      else
3436
        frag_align (align, 0, 0);
3437
 
3438
      symbol_set_frag (sym, frag_now);
3439
      S_SET_VALUE (sym, (valueT) frag_now_fix ());
3440
 
3441
      symbol_get_tc (sym)->align = align;
3442
      symbol_get_tc (sym)->output = 1;
3443
      symbol_get_tc (sym)->within = sym;
3444
 
3445
      for (list = *list_ptr;
3446
           symbol_get_tc (list)->next != (symbolS *) NULL;
3447
           list = symbol_get_tc (list)->next)
3448
        ;
3449
      symbol_get_tc (list)->next = sym;
3450
 
3451
      symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3452
      symbol_append (sym, symbol_get_tc (list)->within, &symbol_rootP,
3453
                     &symbol_lastP);
3454
    }
3455
 
3456
  ppc_current_csect = sym;
3457
}
3458
 
3459
/* This function handles the .text and .data pseudo-ops.  These
3460
   pseudo-ops aren't really used by XCOFF; we implement them for the
3461
   convenience of people who aren't used to XCOFF.  */
3462
 
3463
static void
3464
ppc_section (int type)
3465
{
3466
  const char *name;
3467
  symbolS *sym;
3468
 
3469
  if (type == 't')
3470
    name = ".text[PR]";
3471
  else if (type == 'd')
3472
    name = ".data[RW]";
3473
  else
3474
    abort ();
3475
 
3476
  sym = symbol_find_or_make (name);
3477
 
3478
  ppc_change_csect (sym, 2);
3479
 
3480
  demand_empty_rest_of_line ();
3481
}
3482
 
3483
/* This function handles the .section pseudo-op.  This is mostly to
3484
   give an error, since XCOFF only supports .text, .data and .bss, but
3485
   we do permit the user to name the text or data section.  */
3486
 
3487
static void
3488
ppc_named_section (int ignore ATTRIBUTE_UNUSED)
3489
{
3490
  char *user_name;
3491
  const char *real_name;
3492
  char c;
3493
  symbolS *sym;
3494
 
3495
  user_name = input_line_pointer;
3496
  c = get_symbol_end ();
3497
 
3498
  if (strcmp (user_name, ".text") == 0)
3499
    real_name = ".text[PR]";
3500
  else if (strcmp (user_name, ".data") == 0)
3501
    real_name = ".data[RW]";
3502
  else
3503
    {
3504
      as_bad (_("The XCOFF file format does not support arbitrary sections"));
3505
      *input_line_pointer = c;
3506
      ignore_rest_of_line ();
3507
      return;
3508
    }
3509
 
3510
  *input_line_pointer = c;
3511
 
3512
  sym = symbol_find_or_make (real_name);
3513
 
3514
  ppc_change_csect (sym, 2);
3515
 
3516
  demand_empty_rest_of_line ();
3517
}
3518
 
3519
/* The .extern pseudo-op.  We create an undefined symbol.  */
3520
 
3521
static void
3522
ppc_extern (int ignore ATTRIBUTE_UNUSED)
3523
{
3524
  char *name;
3525
  char endc;
3526
 
3527
  name = input_line_pointer;
3528
  endc = get_symbol_end ();
3529
 
3530
  (void) symbol_find_or_make (name);
3531
 
3532
  *input_line_pointer = endc;
3533
 
3534
  demand_empty_rest_of_line ();
3535
}
3536
 
3537
/* The .lglobl pseudo-op.  Keep the symbol in the symbol table.  */
3538
 
3539
static void
3540
ppc_lglobl (int ignore ATTRIBUTE_UNUSED)
3541
{
3542
  char *name;
3543
  char endc;
3544
  symbolS *sym;
3545
 
3546
  name = input_line_pointer;
3547
  endc = get_symbol_end ();
3548
 
3549
  sym = symbol_find_or_make (name);
3550
 
3551
  *input_line_pointer = endc;
3552
 
3553
  symbol_get_tc (sym)->output = 1;
3554
 
3555
  demand_empty_rest_of_line ();
3556
}
3557
 
3558
/* The .ref pseudo-op.  It takes a list of symbol names and inserts R_REF
3559
   relocations at the beginning of the current csect.
3560
 
3561
   (In principle, there's no reason why the relocations _have_ to be at
3562
   the beginning.  Anywhere in the csect would do.  However, inserting
3563
   at the beginning is what the native assmebler does, and it helps to
3564
   deal with cases where the .ref statements follow the section contents.)
3565
 
3566
   ??? .refs don't work for empty .csects.  However, the native assembler
3567
   doesn't report an error in this case, and neither yet do we.  */
3568
 
3569
static void
3570
ppc_ref (int ignore ATTRIBUTE_UNUSED)
3571
{
3572
  char *name;
3573
  char c;
3574
 
3575
  if (ppc_current_csect == NULL)
3576
    {
3577
      as_bad (_(".ref outside .csect"));
3578
      ignore_rest_of_line ();
3579
      return;
3580
    }
3581
 
3582
  do
3583
    {
3584
      name = input_line_pointer;
3585
      c = get_symbol_end ();
3586
 
3587
      fix_at_start (symbol_get_frag (ppc_current_csect), 0,
3588
                    symbol_find_or_make (name), 0, FALSE, BFD_RELOC_NONE);
3589
 
3590
      *input_line_pointer = c;
3591
      SKIP_WHITESPACE ();
3592
      c = *input_line_pointer;
3593
      if (c == ',')
3594
        {
3595
          input_line_pointer++;
3596
          SKIP_WHITESPACE ();
3597
          if (is_end_of_line[(unsigned char) *input_line_pointer])
3598
            {
3599
              as_bad (_("missing symbol name"));
3600
              ignore_rest_of_line ();
3601
              return;
3602
            }
3603
        }
3604
    }
3605
  while (c == ',');
3606
 
3607
  demand_empty_rest_of_line ();
3608
}
3609
 
3610
/* The .rename pseudo-op.  The RS/6000 assembler can rename symbols,
3611
   although I don't know why it bothers.  */
3612
 
3613
static void
3614
ppc_rename (int ignore ATTRIBUTE_UNUSED)
3615
{
3616
  char *name;
3617
  char endc;
3618
  symbolS *sym;
3619
  int len;
3620
 
3621
  name = input_line_pointer;
3622
  endc = get_symbol_end ();
3623
 
3624
  sym = symbol_find_or_make (name);
3625
 
3626
  *input_line_pointer = endc;
3627
 
3628
  if (*input_line_pointer != ',')
3629
    {
3630
      as_bad (_("missing rename string"));
3631
      ignore_rest_of_line ();
3632
      return;
3633
    }
3634
  ++input_line_pointer;
3635
 
3636
  symbol_get_tc (sym)->real_name = demand_copy_C_string (&len);
3637
 
3638
  demand_empty_rest_of_line ();
3639
}
3640
 
3641
/* The .stabx pseudo-op.  This is similar to a normal .stabs
3642
   pseudo-op, but slightly different.  A sample is
3643
       .stabx "main:F-1",.main,142,0
3644
   The first argument is the symbol name to create.  The second is the
3645
   value, and the third is the storage class.  The fourth seems to be
3646
   always zero, and I am assuming it is the type.  */
3647
 
3648
static void
3649
ppc_stabx (int ignore ATTRIBUTE_UNUSED)
3650
{
3651
  char *name;
3652
  int len;
3653
  symbolS *sym;
3654
  expressionS exp;
3655
 
3656
  name = demand_copy_C_string (&len);
3657
 
3658
  if (*input_line_pointer != ',')
3659
    {
3660
      as_bad (_("missing value"));
3661
      return;
3662
    }
3663
  ++input_line_pointer;
3664
 
3665
  ppc_stab_symbol = TRUE;
3666
  sym = symbol_make (name);
3667
  ppc_stab_symbol = FALSE;
3668
 
3669
  symbol_get_tc (sym)->real_name = name;
3670
 
3671
  (void) expression (&exp);
3672
 
3673
  switch (exp.X_op)
3674
    {
3675
    case O_illegal:
3676
    case O_absent:
3677
    case O_big:
3678
      as_bad (_("illegal .stabx expression; zero assumed"));
3679
      exp.X_add_number = 0;
3680
      /* Fall through.  */
3681
    case O_constant:
3682
      S_SET_VALUE (sym, (valueT) exp.X_add_number);
3683
      symbol_set_frag (sym, &zero_address_frag);
3684
      break;
3685
 
3686
    case O_symbol:
3687
      if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section)
3688
        symbol_set_value_expression (sym, &exp);
3689
      else
3690
        {
3691
          S_SET_VALUE (sym,
3692
                       exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
3693
          symbol_set_frag (sym, symbol_get_frag (exp.X_add_symbol));
3694
        }
3695
      break;
3696
 
3697
    default:
3698
      /* The value is some complex expression.  This will probably
3699
         fail at some later point, but this is probably the right
3700
         thing to do here.  */
3701
      symbol_set_value_expression (sym, &exp);
3702
      break;
3703
    }
3704
 
3705
  S_SET_SEGMENT (sym, ppc_coff_debug_section);
3706
  symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3707
 
3708
  if (*input_line_pointer != ',')
3709
    {
3710
      as_bad (_("missing class"));
3711
      return;
3712
    }
3713
  ++input_line_pointer;
3714
 
3715
  S_SET_STORAGE_CLASS (sym, get_absolute_expression ());
3716
 
3717
  if (*input_line_pointer != ',')
3718
    {
3719
      as_bad (_("missing type"));
3720
      return;
3721
    }
3722
  ++input_line_pointer;
3723
 
3724
  S_SET_DATA_TYPE (sym, get_absolute_expression ());
3725
 
3726
  symbol_get_tc (sym)->output = 1;
3727
 
3728
  if (S_GET_STORAGE_CLASS (sym) == C_STSYM) {
3729
 
3730
    symbol_get_tc (sym)->within = ppc_current_block;
3731
 
3732
    /* In this case :
3733
 
3734
       .bs name
3735
       .stabx   "z",arrays_,133,0
3736
       .es
3737
 
3738
       .comm arrays_,13768,3
3739
 
3740
       resolve_symbol_value will copy the exp's "within" into sym's when the
3741
       offset is 0.  Since this seems to be corner case problem,
3742
       only do the correction for storage class C_STSYM.  A better solution
3743
       would be to have the tc field updated in ppc_symbol_new_hook.  */
3744
 
3745
    if (exp.X_op == O_symbol)
3746
      {
3747
        symbol_get_tc (exp.X_add_symbol)->within = ppc_current_block;
3748
      }
3749
  }
3750
 
3751
  if (exp.X_op != O_symbol
3752
      || ! S_IS_EXTERNAL (exp.X_add_symbol)
3753
      || S_GET_SEGMENT (exp.X_add_symbol) != bss_section)
3754
    ppc_frob_label (sym);
3755
  else
3756
    {
3757
      symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3758
      symbol_append (sym, exp.X_add_symbol, &symbol_rootP, &symbol_lastP);
3759
      if (symbol_get_tc (ppc_current_csect)->within == exp.X_add_symbol)
3760
        symbol_get_tc (ppc_current_csect)->within = sym;
3761
    }
3762
 
3763
  demand_empty_rest_of_line ();
3764
}
3765
 
3766
/* The .function pseudo-op.  This takes several arguments.  The first
3767
   argument seems to be the external name of the symbol.  The second
3768
   argument seems to be the label for the start of the function.  gcc
3769
   uses the same name for both.  I have no idea what the third and
3770
   fourth arguments are meant to be.  The optional fifth argument is
3771
   an expression for the size of the function.  In COFF this symbol
3772
   gets an aux entry like that used for a csect.  */
3773
 
3774
static void
3775
ppc_function (int ignore ATTRIBUTE_UNUSED)
3776
{
3777
  char *name;
3778
  char endc;
3779
  char *s;
3780
  symbolS *ext_sym;
3781
  symbolS *lab_sym;
3782
 
3783
  name = input_line_pointer;
3784
  endc = get_symbol_end ();
3785
 
3786
  /* Ignore any [PR] suffix.  */
3787
  name = ppc_canonicalize_symbol_name (name);
3788
  s = strchr (name, '[');
3789
  if (s != (char *) NULL
3790
      && strcmp (s + 1, "PR]") == 0)
3791
    *s = '\0';
3792
 
3793
  ext_sym = symbol_find_or_make (name);
3794
 
3795
  *input_line_pointer = endc;
3796
 
3797
  if (*input_line_pointer != ',')
3798
    {
3799
      as_bad (_("missing symbol name"));
3800
      ignore_rest_of_line ();
3801
      return;
3802
    }
3803
  ++input_line_pointer;
3804
 
3805
  name = input_line_pointer;
3806
  endc = get_symbol_end ();
3807
 
3808
  lab_sym = symbol_find_or_make (name);
3809
 
3810
  *input_line_pointer = endc;
3811
 
3812
  if (ext_sym != lab_sym)
3813
    {
3814
      expressionS exp;
3815
 
3816
      exp.X_op = O_symbol;
3817
      exp.X_add_symbol = lab_sym;
3818
      exp.X_op_symbol = NULL;
3819
      exp.X_add_number = 0;
3820
      exp.X_unsigned = 0;
3821
      symbol_set_value_expression (ext_sym, &exp);
3822
    }
3823
 
3824
  if (symbol_get_tc (ext_sym)->symbol_class == -1)
3825
    symbol_get_tc (ext_sym)->symbol_class = XMC_PR;
3826
  symbol_get_tc (ext_sym)->output = 1;
3827
 
3828
  if (*input_line_pointer == ',')
3829
    {
3830
      expressionS ignore;
3831
 
3832
      /* Ignore the third argument.  */
3833
      ++input_line_pointer;
3834
      expression (&ignore);
3835
      if (*input_line_pointer == ',')
3836
        {
3837
          /* Ignore the fourth argument.  */
3838
          ++input_line_pointer;
3839
          expression (&ignore);
3840
          if (*input_line_pointer == ',')
3841
            {
3842
              /* The fifth argument is the function size.  */
3843
              ++input_line_pointer;
3844
              symbol_get_tc (ext_sym)->size = symbol_new ("L0\001",
3845
                                                          absolute_section,
3846
                                                          (valueT) 0,
3847
                                                          &zero_address_frag);
3848
              pseudo_set (symbol_get_tc (ext_sym)->size);
3849
            }
3850
        }
3851
    }
3852
 
3853
  S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
3854
  SF_SET_FUNCTION (ext_sym);
3855
  SF_SET_PROCESS (ext_sym);
3856
  coff_add_linesym (ext_sym);
3857
 
3858
  demand_empty_rest_of_line ();
3859
}
3860
 
3861
/* The .bf pseudo-op.  This is just like a COFF C_FCN symbol named
3862
   ".bf".  If the pseudo op .bi was seen before .bf, patch the .bi sym
3863
   with the correct line number */
3864
 
3865
static symbolS *saved_bi_sym = 0;
3866
 
3867
static void
3868
ppc_bf (int ignore ATTRIBUTE_UNUSED)
3869
{
3870
  symbolS *sym;
3871
 
3872
  sym = symbol_make (".bf");
3873
  S_SET_SEGMENT (sym, text_section);
3874
  symbol_set_frag (sym, frag_now);
3875
  S_SET_VALUE (sym, frag_now_fix ());
3876
  S_SET_STORAGE_CLASS (sym, C_FCN);
3877
 
3878
  coff_line_base = get_absolute_expression ();
3879
 
3880
  S_SET_NUMBER_AUXILIARY (sym, 1);
3881
  SA_SET_SYM_LNNO (sym, coff_line_base);
3882
 
3883
  /* Line number for bi.  */
3884
  if (saved_bi_sym)
3885
    {
3886
      S_SET_VALUE (saved_bi_sym, coff_n_line_nos);
3887
      saved_bi_sym = 0;
3888
    }
3889
 
3890
 
3891
  symbol_get_tc (sym)->output = 1;
3892
 
3893
  ppc_frob_label (sym);
3894
 
3895
  demand_empty_rest_of_line ();
3896
}
3897
 
3898
/* The .ef pseudo-op.  This is just like a COFF C_FCN symbol named
3899
   ".ef", except that the line number is absolute, not relative to the
3900
   most recent ".bf" symbol.  */
3901
 
3902
static void
3903
ppc_ef (int ignore ATTRIBUTE_UNUSED)
3904
{
3905
  symbolS *sym;
3906
 
3907
  sym = symbol_make (".ef");
3908
  S_SET_SEGMENT (sym, text_section);
3909
  symbol_set_frag (sym, frag_now);
3910
  S_SET_VALUE (sym, frag_now_fix ());
3911
  S_SET_STORAGE_CLASS (sym, C_FCN);
3912
  S_SET_NUMBER_AUXILIARY (sym, 1);
3913
  SA_SET_SYM_LNNO (sym, get_absolute_expression ());
3914
  symbol_get_tc (sym)->output = 1;
3915
 
3916
  ppc_frob_label (sym);
3917
 
3918
  demand_empty_rest_of_line ();
3919
}
3920
 
3921
/* The .bi and .ei pseudo-ops.  These take a string argument and
3922
   generates a C_BINCL or C_EINCL symbol, which goes at the start of
3923
   the symbol list.  The value of .bi will be know when the next .bf
3924
   is encountered.  */
3925
 
3926
static void
3927
ppc_biei (int ei)
3928
{
3929
  static symbolS *last_biei;
3930
 
3931
  char *name;
3932
  int len;
3933
  symbolS *sym;
3934
  symbolS *look;
3935
 
3936
  name = demand_copy_C_string (&len);
3937
 
3938
  /* The value of these symbols is actually file offset.  Here we set
3939
     the value to the index into the line number entries.  In
3940
     ppc_frob_symbols we set the fix_line field, which will cause BFD
3941
     to do the right thing.  */
3942
 
3943
  sym = symbol_make (name);
3944
  /* obj-coff.c currently only handles line numbers correctly in the
3945
     .text section.  */
3946
  S_SET_SEGMENT (sym, text_section);
3947
  S_SET_VALUE (sym, coff_n_line_nos);
3948
  symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3949
 
3950
  S_SET_STORAGE_CLASS (sym, ei ? C_EINCL : C_BINCL);
3951
  symbol_get_tc (sym)->output = 1;
3952
 
3953
  /* Save bi.  */
3954
  if (ei)
3955
    saved_bi_sym = 0;
3956
  else
3957
    saved_bi_sym = sym;
3958
 
3959
  for (look = last_biei ? last_biei : symbol_rootP;
3960
       (look != (symbolS *) NULL
3961
        && (S_GET_STORAGE_CLASS (look) == C_FILE
3962
            || S_GET_STORAGE_CLASS (look) == C_BINCL
3963
            || S_GET_STORAGE_CLASS (look) == C_EINCL));
3964
       look = symbol_next (look))
3965
    ;
3966
  if (look != (symbolS *) NULL)
3967
    {
3968
      symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3969
      symbol_insert (sym, look, &symbol_rootP, &symbol_lastP);
3970
      last_biei = sym;
3971
    }
3972
 
3973
  demand_empty_rest_of_line ();
3974
}
3975
 
3976
/* The .bs pseudo-op.  This generates a C_BSTAT symbol named ".bs".
3977
   There is one argument, which is a csect symbol.  The value of the
3978
   .bs symbol is the index of this csect symbol.  */
3979
 
3980
static void
3981
ppc_bs (int ignore ATTRIBUTE_UNUSED)
3982
{
3983
  char *name;
3984
  char endc;
3985
  symbolS *csect;
3986
  symbolS *sym;
3987
 
3988
  if (ppc_current_block != NULL)
3989
    as_bad (_("nested .bs blocks"));
3990
 
3991
  name = input_line_pointer;
3992
  endc = get_symbol_end ();
3993
 
3994
  csect = symbol_find_or_make (name);
3995
 
3996
  *input_line_pointer = endc;
3997
 
3998
  sym = symbol_make (".bs");
3999
  S_SET_SEGMENT (sym, now_seg);
4000
  S_SET_STORAGE_CLASS (sym, C_BSTAT);
4001
  symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
4002
  symbol_get_tc (sym)->output = 1;
4003
 
4004
  symbol_get_tc (sym)->within = csect;
4005
 
4006
  ppc_frob_label (sym);
4007
 
4008
  ppc_current_block = sym;
4009
 
4010
  demand_empty_rest_of_line ();
4011
}
4012
 
4013
/* The .es pseudo-op.  Generate a C_ESTART symbol named .es.  */
4014
 
4015
static void
4016
ppc_es (int ignore ATTRIBUTE_UNUSED)
4017
{
4018
  symbolS *sym;
4019
 
4020
  if (ppc_current_block == NULL)
4021
    as_bad (_(".es without preceding .bs"));
4022
 
4023
  sym = symbol_make (".es");
4024
  S_SET_SEGMENT (sym, now_seg);
4025
  S_SET_STORAGE_CLASS (sym, C_ESTAT);
4026
  symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
4027
  symbol_get_tc (sym)->output = 1;
4028
 
4029
  ppc_frob_label (sym);
4030
 
4031
  ppc_current_block = NULL;
4032
 
4033
  demand_empty_rest_of_line ();
4034
}
4035
 
4036
/* The .bb pseudo-op.  Generate a C_BLOCK symbol named .bb, with a
4037
   line number.  */
4038
 
4039
static void
4040
ppc_bb (int ignore ATTRIBUTE_UNUSED)
4041
{
4042
  symbolS *sym;
4043
 
4044
  sym = symbol_make (".bb");
4045
  S_SET_SEGMENT (sym, text_section);
4046
  symbol_set_frag (sym, frag_now);
4047
  S_SET_VALUE (sym, frag_now_fix ());
4048
  S_SET_STORAGE_CLASS (sym, C_BLOCK);
4049
 
4050
  S_SET_NUMBER_AUXILIARY (sym, 1);
4051
  SA_SET_SYM_LNNO (sym, get_absolute_expression ());
4052
 
4053
  symbol_get_tc (sym)->output = 1;
4054
 
4055
  SF_SET_PROCESS (sym);
4056
 
4057
  ppc_frob_label (sym);
4058
 
4059
  demand_empty_rest_of_line ();
4060
}
4061
 
4062
/* The .eb pseudo-op.  Generate a C_BLOCK symbol named .eb, with a
4063
   line number.  */
4064
 
4065
static void
4066
ppc_eb (int ignore ATTRIBUTE_UNUSED)
4067
{
4068
  symbolS *sym;
4069
 
4070
  sym = symbol_make (".eb");
4071
  S_SET_SEGMENT (sym, text_section);
4072
  symbol_set_frag (sym, frag_now);
4073
  S_SET_VALUE (sym, frag_now_fix ());
4074
  S_SET_STORAGE_CLASS (sym, C_BLOCK);
4075
  S_SET_NUMBER_AUXILIARY (sym, 1);
4076
  SA_SET_SYM_LNNO (sym, get_absolute_expression ());
4077
  symbol_get_tc (sym)->output = 1;
4078
 
4079
  SF_SET_PROCESS (sym);
4080
 
4081
  ppc_frob_label (sym);
4082
 
4083
  demand_empty_rest_of_line ();
4084
}
4085
 
4086
/* The .bc pseudo-op.  This just creates a C_BCOMM symbol with a
4087
   specified name.  */
4088
 
4089
static void
4090
ppc_bc (int ignore ATTRIBUTE_UNUSED)
4091
{
4092
  char *name;
4093
  int len;
4094
  symbolS *sym;
4095
 
4096
  name = demand_copy_C_string (&len);
4097
  sym = symbol_make (name);
4098
  S_SET_SEGMENT (sym, ppc_coff_debug_section);
4099
  symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
4100
  S_SET_STORAGE_CLASS (sym, C_BCOMM);
4101
  S_SET_VALUE (sym, 0);
4102
  symbol_get_tc (sym)->output = 1;
4103
 
4104
  ppc_frob_label (sym);
4105
 
4106
  demand_empty_rest_of_line ();
4107
}
4108
 
4109
/* The .ec pseudo-op.  This just creates a C_ECOMM symbol.  */
4110
 
4111
static void
4112
ppc_ec (int ignore ATTRIBUTE_UNUSED)
4113
{
4114
  symbolS *sym;
4115
 
4116
  sym = symbol_make (".ec");
4117
  S_SET_SEGMENT (sym, ppc_coff_debug_section);
4118
  symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
4119
  S_SET_STORAGE_CLASS (sym, C_ECOMM);
4120
  S_SET_VALUE (sym, 0);
4121
  symbol_get_tc (sym)->output = 1;
4122
 
4123
  ppc_frob_label (sym);
4124
 
4125
  demand_empty_rest_of_line ();
4126
}
4127
 
4128
/* The .toc pseudo-op.  Switch to the .toc subsegment.  */
4129
 
4130
static void
4131
ppc_toc (int ignore ATTRIBUTE_UNUSED)
4132
{
4133
  if (ppc_toc_csect != (symbolS *) NULL)
4134
    subseg_set (data_section, symbol_get_tc (ppc_toc_csect)->subseg);
4135
  else
4136
    {
4137
      subsegT subseg;
4138
      symbolS *sym;
4139
      symbolS *list;
4140
 
4141
      subseg = ppc_data_subsegment;
4142
      ++ppc_data_subsegment;
4143
 
4144
      subseg_new (segment_name (data_section), subseg);
4145
      ppc_toc_frag = frag_now;
4146
 
4147
      sym = symbol_find_or_make ("TOC[TC0]");
4148
      symbol_set_frag (sym, frag_now);
4149
      S_SET_SEGMENT (sym, data_section);
4150
      S_SET_VALUE (sym, (valueT) frag_now_fix ());
4151
      symbol_get_tc (sym)->subseg = subseg;
4152
      symbol_get_tc (sym)->output = 1;
4153
      symbol_get_tc (sym)->within = sym;
4154
 
4155
      ppc_toc_csect = sym;
4156
 
4157
      for (list = ppc_data_csects;
4158
           symbol_get_tc (list)->next != (symbolS *) NULL;
4159
           list = symbol_get_tc (list)->next)
4160
        ;
4161
      symbol_get_tc (list)->next = sym;
4162
 
4163
      symbol_remove (sym, &symbol_rootP, &symbol_lastP);
4164
      symbol_append (sym, symbol_get_tc (list)->within, &symbol_rootP,
4165
                     &symbol_lastP);
4166
    }
4167
 
4168
  ppc_current_csect = ppc_toc_csect;
4169
 
4170
  demand_empty_rest_of_line ();
4171
}
4172
 
4173
/* The AIX assembler automatically aligns the operands of a .long or
4174
   .short pseudo-op, and we want to be compatible.  */
4175
 
4176
static void
4177
ppc_xcoff_cons (int log_size)
4178
{
4179
  frag_align (log_size, 0, 0);
4180
  record_alignment (now_seg, log_size);
4181
  cons (1 << log_size);
4182
}
4183
 
4184
static void
4185
ppc_vbyte (int dummy ATTRIBUTE_UNUSED)
4186
{
4187
  expressionS exp;
4188
  int byte_count;
4189
 
4190
  (void) expression (&exp);
4191
 
4192
  if (exp.X_op != O_constant)
4193
    {
4194
      as_bad (_("non-constant byte count"));
4195
      return;
4196
    }
4197
 
4198
  byte_count = exp.X_add_number;
4199
 
4200
  if (*input_line_pointer != ',')
4201
    {
4202
      as_bad (_("missing value"));
4203
      return;
4204
    }
4205
 
4206
  ++input_line_pointer;
4207
  cons (byte_count);
4208
}
4209
 
4210
#endif /* OBJ_XCOFF */
4211
#if defined (OBJ_XCOFF) || defined (OBJ_ELF)
4212
 
4213
/* The .tc pseudo-op.  This is used when generating either XCOFF or
4214
   ELF.  This takes two or more arguments.
4215
 
4216
   When generating XCOFF output, the first argument is the name to
4217
   give to this location in the toc; this will be a symbol with class
4218
   TC.  The rest of the arguments are N-byte values to actually put at
4219
   this location in the TOC; often there is just one more argument, a
4220
   relocatable symbol reference.  The size of the value to store
4221
   depends on target word size.  A 32-bit target uses 4-byte values, a
4222
   64-bit target uses 8-byte values.
4223
 
4224
   When not generating XCOFF output, the arguments are the same, but
4225
   the first argument is simply ignored.  */
4226
 
4227
static void
4228
ppc_tc (int ignore ATTRIBUTE_UNUSED)
4229
{
4230
#ifdef OBJ_XCOFF
4231
 
4232
  /* Define the TOC symbol name.  */
4233
  {
4234
    char *name;
4235
    char endc;
4236
    symbolS *sym;
4237
 
4238
    if (ppc_toc_csect == (symbolS *) NULL
4239
        || ppc_toc_csect != ppc_current_csect)
4240
      {
4241
        as_bad (_(".tc not in .toc section"));
4242
        ignore_rest_of_line ();
4243
        return;
4244
      }
4245
 
4246
    name = input_line_pointer;
4247
    endc = get_symbol_end ();
4248
 
4249
    sym = symbol_find_or_make (name);
4250
 
4251
    *input_line_pointer = endc;
4252
 
4253
    if (S_IS_DEFINED (sym))
4254
      {
4255
        symbolS *label;
4256
 
4257
        label = symbol_get_tc (ppc_current_csect)->within;
4258
        if (symbol_get_tc (label)->symbol_class != XMC_TC0)
4259
          {
4260
            as_bad (_(".tc with no label"));
4261
            ignore_rest_of_line ();
4262
            return;
4263
          }
4264
 
4265
        S_SET_SEGMENT (label, S_GET_SEGMENT (sym));
4266
        symbol_set_frag (label, symbol_get_frag (sym));
4267
        S_SET_VALUE (label, S_GET_VALUE (sym));
4268
 
4269
        while (! is_end_of_line[(unsigned char) *input_line_pointer])
4270
          ++input_line_pointer;
4271
 
4272
        return;
4273
      }
4274
 
4275
    S_SET_SEGMENT (sym, now_seg);
4276
    symbol_set_frag (sym, frag_now);
4277
    S_SET_VALUE (sym, (valueT) frag_now_fix ());
4278
    symbol_get_tc (sym)->symbol_class = XMC_TC;
4279
    symbol_get_tc (sym)->output = 1;
4280
 
4281
    ppc_frob_label (sym);
4282
  }
4283
 
4284
#endif /* OBJ_XCOFF */
4285
#ifdef OBJ_ELF
4286
  int align;
4287
 
4288
  /* Skip the TOC symbol name.  */
4289
  while (is_part_of_name (*input_line_pointer)
4290
         || *input_line_pointer == ' '
4291
         || *input_line_pointer == '['
4292
         || *input_line_pointer == ']'
4293
         || *input_line_pointer == '{'
4294
         || *input_line_pointer == '}')
4295
    ++input_line_pointer;
4296
 
4297
  /* Align to a four/eight byte boundary.  */
4298
  align = ppc_obj64 ? 3 : 2;
4299
  frag_align (align, 0, 0);
4300
  record_alignment (now_seg, align);
4301
#endif /* OBJ_ELF */
4302
 
4303
  if (*input_line_pointer != ',')
4304
    demand_empty_rest_of_line ();
4305
  else
4306
    {
4307
      ++input_line_pointer;
4308
      cons (ppc_obj64 ? 8 : 4);
4309
    }
4310
}
4311
 
4312
/* Pseudo-op .machine.  */
4313
 
4314
static void
4315
ppc_machine (int ignore ATTRIBUTE_UNUSED)
4316
{
4317
  char *cpu_string;
4318
#define MAX_HISTORY 100
4319
  static ppc_cpu_t *cpu_history;
4320
  static int curr_hist;
4321
 
4322
  SKIP_WHITESPACE ();
4323
 
4324
  if (*input_line_pointer == '"')
4325
    {
4326
      int len;
4327
      cpu_string = demand_copy_C_string (&len);
4328
    }
4329
  else
4330
    {
4331
      char c;
4332
      cpu_string = input_line_pointer;
4333
      c = get_symbol_end ();
4334
      cpu_string = xstrdup (cpu_string);
4335
      *input_line_pointer = c;
4336
    }
4337
 
4338
  if (cpu_string != NULL)
4339
    {
4340
      ppc_cpu_t old_cpu = ppc_cpu;
4341
      ppc_cpu_t new_cpu;
4342
      char *p;
4343
 
4344
      for (p = cpu_string; *p != 0; p++)
4345
        *p = TOLOWER (*p);
4346
 
4347
      if (strcmp (cpu_string, "push") == 0)
4348
        {
4349
          if (cpu_history == NULL)
4350
            cpu_history = xmalloc (MAX_HISTORY * sizeof (*cpu_history));
4351
 
4352
          if (curr_hist >= MAX_HISTORY)
4353
            as_bad (_(".machine stack overflow"));
4354
          else
4355
            cpu_history[curr_hist++] = ppc_cpu;
4356
        }
4357
      else if (strcmp (cpu_string, "pop") == 0)
4358
        {
4359
          if (curr_hist <= 0)
4360
            as_bad (_(".machine stack underflow"));
4361
          else
4362
            ppc_cpu = cpu_history[--curr_hist];
4363
        }
4364
      else if ((new_cpu = ppc_parse_cpu (ppc_cpu, cpu_string)) != 0)
4365
        ppc_cpu = new_cpu;
4366
      else
4367
        as_bad (_("invalid machine `%s'"), cpu_string);
4368
 
4369
      if (ppc_cpu != old_cpu)
4370
        ppc_setup_opcodes ();
4371
    }
4372
 
4373
  demand_empty_rest_of_line ();
4374
}
4375
 
4376
/* See whether a symbol is in the TOC section.  */
4377
 
4378
static int
4379
ppc_is_toc_sym (symbolS *sym)
4380
{
4381
#ifdef OBJ_XCOFF
4382
  return symbol_get_tc (sym)->symbol_class == XMC_TC;
4383
#endif
4384
#ifdef OBJ_ELF
4385
  const char *sname = segment_name (S_GET_SEGMENT (sym));
4386
  if (ppc_obj64)
4387
    return strcmp (sname, ".toc") == 0;
4388
  else
4389
    return strcmp (sname, ".got") == 0;
4390
#endif
4391
}
4392
#endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
4393
 
4394
#ifdef TE_PE
4395
 
4396
/* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format.  */
4397
 
4398
/* Set the current section.  */
4399
static void
4400
ppc_set_current_section (segT new)
4401
{
4402
  ppc_previous_section = ppc_current_section;
4403
  ppc_current_section = new;
4404
}
4405
 
4406
/* pseudo-op: .previous
4407
   behaviour: toggles the current section with the previous section.
4408
   errors:    None
4409
   warnings:  "No previous section"  */
4410
 
4411
static void
4412
ppc_previous (int ignore ATTRIBUTE_UNUSED)
4413
{
4414
  symbolS *tmp;
4415
 
4416
  if (ppc_previous_section == NULL)
4417
    {
4418
      as_warn (_("No previous section to return to. Directive ignored."));
4419
      return;
4420
    }
4421
 
4422
  subseg_set (ppc_previous_section, 0);
4423
 
4424
  ppc_set_current_section (ppc_previous_section);
4425
}
4426
 
4427
/* pseudo-op: .pdata
4428
   behaviour: predefined read only data section
4429
              double word aligned
4430
   errors:    None
4431
   warnings:  None
4432
   initial:   .section .pdata "adr3"
4433
              a - don't know -- maybe a misprint
4434
              d - initialized data
4435
              r - readable
4436
              3 - double word aligned (that would be 4 byte boundary)
4437
 
4438
   commentary:
4439
   Tag index tables (also known as the function table) for exception
4440
   handling, debugging, etc.  */
4441
 
4442
static void
4443
ppc_pdata (int ignore ATTRIBUTE_UNUSED)
4444
{
4445
  if (pdata_section == 0)
4446
    {
4447
      pdata_section = subseg_new (".pdata", 0);
4448
 
4449
      bfd_set_section_flags (stdoutput, pdata_section,
4450
                             (SEC_ALLOC | SEC_LOAD | SEC_RELOC
4451
                              | SEC_READONLY | SEC_DATA ));
4452
 
4453
      bfd_set_section_alignment (stdoutput, pdata_section, 2);
4454
    }
4455
  else
4456
    {
4457
      pdata_section = subseg_new (".pdata", 0);
4458
    }
4459
  ppc_set_current_section (pdata_section);
4460
}
4461
 
4462
/* pseudo-op: .ydata
4463
   behaviour: predefined read only data section
4464
              double word aligned
4465
   errors:    None
4466
   warnings:  None
4467
   initial:   .section .ydata "drw3"
4468
              a - don't know -- maybe a misprint
4469
              d - initialized data
4470
              r - readable
4471
              3 - double word aligned (that would be 4 byte boundary)
4472
   commentary:
4473
   Tag tables (also known as the scope table) for exception handling,
4474
   debugging, etc.  */
4475
 
4476
static void
4477
ppc_ydata (int ignore ATTRIBUTE_UNUSED)
4478
{
4479
  if (ydata_section == 0)
4480
    {
4481
      ydata_section = subseg_new (".ydata", 0);
4482
      bfd_set_section_flags (stdoutput, ydata_section,
4483
                             (SEC_ALLOC | SEC_LOAD | SEC_RELOC
4484
                              | SEC_READONLY | SEC_DATA ));
4485
 
4486
      bfd_set_section_alignment (stdoutput, ydata_section, 3);
4487
    }
4488
  else
4489
    {
4490
      ydata_section = subseg_new (".ydata", 0);
4491
    }
4492
  ppc_set_current_section (ydata_section);
4493
}
4494
 
4495
/* pseudo-op: .reldata
4496
   behaviour: predefined read write data section
4497
              double word aligned (4-byte)
4498
              FIXME: relocation is applied to it
4499
              FIXME: what's the difference between this and .data?
4500
   errors:    None
4501
   warnings:  None
4502
   initial:   .section .reldata "drw3"
4503
              d - initialized data
4504
              r - readable
4505
              w - writeable
4506
              3 - double word aligned (that would be 8 byte boundary)
4507
 
4508
   commentary:
4509
   Like .data, but intended to hold data subject to relocation, such as
4510
   function descriptors, etc.  */
4511
 
4512
static void
4513
ppc_reldata (int ignore ATTRIBUTE_UNUSED)
4514
{
4515
  if (reldata_section == 0)
4516
    {
4517
      reldata_section = subseg_new (".reldata", 0);
4518
 
4519
      bfd_set_section_flags (stdoutput, reldata_section,
4520
                             (SEC_ALLOC | SEC_LOAD | SEC_RELOC
4521
                              | SEC_DATA));
4522
 
4523
      bfd_set_section_alignment (stdoutput, reldata_section, 2);
4524
    }
4525
  else
4526
    {
4527
      reldata_section = subseg_new (".reldata", 0);
4528
    }
4529
  ppc_set_current_section (reldata_section);
4530
}
4531
 
4532
/* pseudo-op: .rdata
4533
   behaviour: predefined read only data section
4534
              double word aligned
4535
   errors:    None
4536
   warnings:  None
4537
   initial:   .section .rdata "dr3"
4538
              d - initialized data
4539
              r - readable
4540
              3 - double word aligned (that would be 4 byte boundary)  */
4541
 
4542
static void
4543
ppc_rdata (int ignore ATTRIBUTE_UNUSED)
4544
{
4545
  if (rdata_section == 0)
4546
    {
4547
      rdata_section = subseg_new (".rdata", 0);
4548
      bfd_set_section_flags (stdoutput, rdata_section,
4549
                             (SEC_ALLOC | SEC_LOAD | SEC_RELOC
4550
                              | SEC_READONLY | SEC_DATA ));
4551
 
4552
      bfd_set_section_alignment (stdoutput, rdata_section, 2);
4553
    }
4554
  else
4555
    {
4556
      rdata_section = subseg_new (".rdata", 0);
4557
    }
4558
  ppc_set_current_section (rdata_section);
4559
}
4560
 
4561
/* pseudo-op: .ualong
4562
   behaviour: much like .int, with the exception that no alignment is
4563
              performed.
4564
              FIXME: test the alignment statement
4565
   errors:    None
4566
   warnings:  None  */
4567
 
4568
static void
4569
ppc_ualong (int ignore ATTRIBUTE_UNUSED)
4570
{
4571
  /* Try for long.  */
4572
  cons (4);
4573
}
4574
 
4575
/* pseudo-op: .znop  <symbol name>
4576
   behaviour: Issue a nop instruction
4577
              Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
4578
              the supplied symbol name.
4579
   errors:    None
4580
   warnings:  Missing symbol name  */
4581
 
4582
static void
4583
ppc_znop (int ignore ATTRIBUTE_UNUSED)
4584
{
4585
  unsigned long insn;
4586
  const struct powerpc_opcode *opcode;
4587
  expressionS ex;
4588
  char *f;
4589
  symbolS *sym;
4590
  char *symbol_name;
4591
  char c;
4592
  char *name;
4593
  unsigned int exp;
4594
  flagword flags;
4595
  asection *sec;
4596
 
4597
  /* Strip out the symbol name.  */
4598
  symbol_name = input_line_pointer;
4599
  c = get_symbol_end ();
4600
 
4601
  name = xmalloc (input_line_pointer - symbol_name + 1);
4602
  strcpy (name, symbol_name);
4603
 
4604
  sym = symbol_find_or_make (name);
4605
 
4606
  *input_line_pointer = c;
4607
 
4608
  SKIP_WHITESPACE ();
4609
 
4610
  /* Look up the opcode in the hash table.  */
4611
  opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, "nop");
4612
 
4613
  /* Stick in the nop.  */
4614
  insn = opcode->opcode;
4615
 
4616
  /* Write out the instruction.  */
4617
  f = frag_more (4);
4618
  md_number_to_chars (f, insn, 4);
4619
  fix_new (frag_now,
4620
           f - frag_now->fr_literal,
4621
           4,
4622
           sym,
4623
           0,
4624
           0,
4625
           BFD_RELOC_16_GOT_PCREL);
4626
 
4627
}
4628
 
4629
/* pseudo-op:
4630
   behaviour:
4631
   errors:
4632
   warnings:  */
4633
 
4634
static void
4635
ppc_pe_comm (int lcomm)
4636
{
4637
  char *name;
4638
  char c;
4639
  char *p;
4640
  offsetT temp;
4641
  symbolS *symbolP;
4642
  offsetT align;
4643
 
4644
  name = input_line_pointer;
4645
  c = get_symbol_end ();
4646
 
4647
  /* just after name is now '\0'.  */
4648
  p = input_line_pointer;
4649
  *p = c;
4650
  SKIP_WHITESPACE ();
4651
  if (*input_line_pointer != ',')
4652
    {
4653
      as_bad (_("Expected comma after symbol-name: rest of line ignored."));
4654
      ignore_rest_of_line ();
4655
      return;
4656
    }
4657
 
4658
  input_line_pointer++;         /* skip ',' */
4659
  if ((temp = get_absolute_expression ()) < 0)
4660
    {
4661
      as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp);
4662
      ignore_rest_of_line ();
4663
      return;
4664
    }
4665
 
4666
  if (! lcomm)
4667
    {
4668
      /* The third argument to .comm is the alignment.  */
4669
      if (*input_line_pointer != ',')
4670
        align = 3;
4671
      else
4672
        {
4673
          ++input_line_pointer;
4674
          align = get_absolute_expression ();
4675
          if (align <= 0)
4676
            {
4677
              as_warn (_("ignoring bad alignment"));
4678
              align = 3;
4679
            }
4680
        }
4681
    }
4682
 
4683
  *p = 0;
4684
  symbolP = symbol_find_or_make (name);
4685
 
4686
  *p = c;
4687
  if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
4688
    {
4689
      as_bad (_("Ignoring attempt to re-define symbol `%s'."),
4690
              S_GET_NAME (symbolP));
4691
      ignore_rest_of_line ();
4692
      return;
4693
    }
4694
 
4695
  if (S_GET_VALUE (symbolP))
4696
    {
4697
      if (S_GET_VALUE (symbolP) != (valueT) temp)
4698
        as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
4699
                S_GET_NAME (symbolP),
4700
                (long) S_GET_VALUE (symbolP),
4701
                (long) temp);
4702
    }
4703
  else
4704
    {
4705
      S_SET_VALUE (symbolP, (valueT) temp);
4706
      S_SET_EXTERNAL (symbolP);
4707
      S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
4708
    }
4709
 
4710
  demand_empty_rest_of_line ();
4711
}
4712
 
4713
/*
4714
 * implement the .section pseudo op:
4715
 *      .section name {, "flags"}
4716
 *                ^         ^
4717
 *                |         +--- optional flags: 'b' for bss
4718
 *                |                              'i' for info
4719
 *                +-- section name               'l' for lib
4720
 *                                               'n' for noload
4721
 *                                               'o' for over
4722
 *                                               'w' for data
4723
 *                                               'd' (apparently m88k for data)
4724
 *                                               'x' for text
4725
 * But if the argument is not a quoted string, treat it as a
4726
 * subsegment number.
4727
 *
4728
 * FIXME: this is a copy of the section processing from obj-coff.c, with
4729
 * additions/changes for the moto-pas assembler support. There are three
4730
 * categories:
4731
 *
4732
 * FIXME: I just noticed this. This doesn't work at all really. It it
4733
 *        setting bits that bfd probably neither understands or uses. The
4734
 *        correct approach (?) will have to incorporate extra fields attached
4735
 *        to the section to hold the system specific stuff. (krk)
4736
 *
4737
 * Section Contents:
4738
 * 'a' - unknown - referred to in documentation, but no definition supplied
4739
 * 'c' - section has code
4740
 * 'd' - section has initialized data
4741
 * 'u' - section has uninitialized data
4742
 * 'i' - section contains directives (info)
4743
 * 'n' - section can be discarded
4744
 * 'R' - remove section at link time
4745
 *
4746
 * Section Protection:
4747
 * 'r' - section is readable
4748
 * 'w' - section is writeable
4749
 * 'x' - section is executable
4750
 * 's' - section is sharable
4751
 *
4752
 * Section Alignment:
4753
 * '0' - align to byte boundary
4754
 * '1' - align to halfword undary
4755
 * '2' - align to word boundary
4756
 * '3' - align to doubleword boundary
4757
 * '4' - align to quadword boundary
4758
 * '5' - align to 32 byte boundary
4759
 * '6' - align to 64 byte boundary
4760
 *
4761
 */
4762
 
4763
void
4764
ppc_pe_section (int ignore ATTRIBUTE_UNUSED)
4765
{
4766
  /* Strip out the section name.  */
4767
  char *section_name;
4768
  char c;
4769
  char *name;
4770
  unsigned int exp;
4771
  flagword flags;
4772
  segT sec;
4773
  int align;
4774
 
4775
  section_name = input_line_pointer;
4776
  c = get_symbol_end ();
4777
 
4778
  name = xmalloc (input_line_pointer - section_name + 1);
4779
  strcpy (name, section_name);
4780
 
4781
  *input_line_pointer = c;
4782
 
4783
  SKIP_WHITESPACE ();
4784
 
4785
  exp = 0;
4786
  flags = SEC_NO_FLAGS;
4787
 
4788
  if (strcmp (name, ".idata$2") == 0)
4789
    {
4790
      align = 0;
4791
    }
4792
  else if (strcmp (name, ".idata$3") == 0)
4793
    {
4794
      align = 0;
4795
    }
4796
  else if (strcmp (name, ".idata$4") == 0)
4797
    {
4798
      align = 2;
4799
    }
4800
  else if (strcmp (name, ".idata$5") == 0)
4801
    {
4802
      align = 2;
4803
    }
4804
  else if (strcmp (name, ".idata$6") == 0)
4805
    {
4806
      align = 1;
4807
    }
4808
  else
4809
    /* Default alignment to 16 byte boundary.  */
4810
    align = 4;
4811
 
4812
  if (*input_line_pointer == ',')
4813
    {
4814
      ++input_line_pointer;
4815
      SKIP_WHITESPACE ();
4816
      if (*input_line_pointer != '"')
4817
        exp = get_absolute_expression ();
4818
      else
4819
        {
4820
          ++input_line_pointer;
4821
          while (*input_line_pointer != '"'
4822
                 && ! is_end_of_line[(unsigned char) *input_line_pointer])
4823
            {
4824
              switch (*input_line_pointer)
4825
                {
4826
                  /* Section Contents */
4827
                case 'a': /* unknown */
4828
                  as_bad (_("Unsupported section attribute -- 'a'"));
4829
                  break;
4830
                case 'c': /* code section */
4831
                  flags |= SEC_CODE;
4832
                  break;
4833
                case 'd': /* section has initialized data */
4834
                  flags |= SEC_DATA;
4835
                  break;
4836
                case 'u': /* section has uninitialized data */
4837
                  /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
4838
                     in winnt.h */
4839
                  flags |= SEC_ROM;
4840
                  break;
4841
                case 'i': /* section contains directives (info) */
4842
                  /* FIXME: This is IMAGE_SCN_LNK_INFO
4843
                     in winnt.h */
4844
                  flags |= SEC_HAS_CONTENTS;
4845
                  break;
4846
                case 'n': /* section can be discarded */
4847
                  flags &=~ SEC_LOAD;
4848
                  break;
4849
                case 'R': /* Remove section at link time */
4850
                  flags |= SEC_NEVER_LOAD;
4851
                  break;
4852
#if IFLICT_BRAIN_DAMAGE
4853
                  /* Section Protection */
4854
                case 'r': /* section is readable */
4855
                  flags |= IMAGE_SCN_MEM_READ;
4856
                  break;
4857
                case 'w': /* section is writeable */
4858
                  flags |= IMAGE_SCN_MEM_WRITE;
4859
                  break;
4860
                case 'x': /* section is executable */
4861
                  flags |= IMAGE_SCN_MEM_EXECUTE;
4862
                  break;
4863
                case 's': /* section is sharable */
4864
                  flags |= IMAGE_SCN_MEM_SHARED;
4865
                  break;
4866
 
4867
                  /* Section Alignment */
4868
                case '0': /* align to byte boundary */
4869
                  flags |= IMAGE_SCN_ALIGN_1BYTES;
4870
                  align = 0;
4871
                  break;
4872
                case '1':  /* align to halfword boundary */
4873
                  flags |= IMAGE_SCN_ALIGN_2BYTES;
4874
                  align = 1;
4875
                  break;
4876
                case '2':  /* align to word boundary */
4877
                  flags |= IMAGE_SCN_ALIGN_4BYTES;
4878
                  align = 2;
4879
                  break;
4880
                case '3':  /* align to doubleword boundary */
4881
                  flags |= IMAGE_SCN_ALIGN_8BYTES;
4882
                  align = 3;
4883
                  break;
4884
                case '4':  /* align to quadword boundary */
4885
                  flags |= IMAGE_SCN_ALIGN_16BYTES;
4886
                  align = 4;
4887
                  break;
4888
                case '5':  /* align to 32 byte boundary */
4889
                  flags |= IMAGE_SCN_ALIGN_32BYTES;
4890
                  align = 5;
4891
                  break;
4892
                case '6':  /* align to 64 byte boundary */
4893
                  flags |= IMAGE_SCN_ALIGN_64BYTES;
4894
                  align = 6;
4895
                  break;
4896
#endif
4897
                default:
4898
                  as_bad (_("unknown section attribute '%c'"),
4899
                          *input_line_pointer);
4900
                  break;
4901
                }
4902
              ++input_line_pointer;
4903
            }
4904
          if (*input_line_pointer == '"')
4905
            ++input_line_pointer;
4906
        }
4907
    }
4908
 
4909
  sec = subseg_new (name, (subsegT) exp);
4910
 
4911
  ppc_set_current_section (sec);
4912
 
4913
  if (flags != SEC_NO_FLAGS)
4914
    {
4915
      if (! bfd_set_section_flags (stdoutput, sec, flags))
4916
        as_bad (_("error setting flags for \"%s\": %s"),
4917
                bfd_section_name (stdoutput, sec),
4918
                bfd_errmsg (bfd_get_error ()));
4919
    }
4920
 
4921
  bfd_set_section_alignment (stdoutput, sec, align);
4922
}
4923
 
4924
static void
4925
ppc_pe_function (int ignore ATTRIBUTE_UNUSED)
4926
{
4927
  char *name;
4928
  char endc;
4929
  symbolS *ext_sym;
4930
 
4931
  name = input_line_pointer;
4932
  endc = get_symbol_end ();
4933
 
4934
  ext_sym = symbol_find_or_make (name);
4935
 
4936
  *input_line_pointer = endc;
4937
 
4938
  S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
4939
  SF_SET_FUNCTION (ext_sym);
4940
  SF_SET_PROCESS (ext_sym);
4941
  coff_add_linesym (ext_sym);
4942
 
4943
  demand_empty_rest_of_line ();
4944
}
4945
 
4946
static void
4947
ppc_pe_tocd (int ignore ATTRIBUTE_UNUSED)
4948
{
4949
  if (tocdata_section == 0)
4950
    {
4951
      tocdata_section = subseg_new (".tocd", 0);
4952
      /* FIXME: section flags won't work.  */
4953
      bfd_set_section_flags (stdoutput, tocdata_section,
4954
                             (SEC_ALLOC | SEC_LOAD | SEC_RELOC
4955
                              | SEC_READONLY | SEC_DATA));
4956
 
4957
      bfd_set_section_alignment (stdoutput, tocdata_section, 2);
4958
    }
4959
  else
4960
    {
4961
      rdata_section = subseg_new (".tocd", 0);
4962
    }
4963
 
4964
  ppc_set_current_section (tocdata_section);
4965
 
4966
  demand_empty_rest_of_line ();
4967
}
4968
 
4969
/* Don't adjust TOC relocs to use the section symbol.  */
4970
 
4971
int
4972
ppc_pe_fix_adjustable (fixS *fix)
4973
{
4974
  return fix->fx_r_type != BFD_RELOC_PPC_TOC16;
4975
}
4976
 
4977
#endif
4978
 
4979
#ifdef OBJ_XCOFF
4980
 
4981
/* XCOFF specific symbol and file handling.  */
4982
 
4983
/* Canonicalize the symbol name.  We use the to force the suffix, if
4984
   any, to use square brackets, and to be in upper case.  */
4985
 
4986
char *
4987
ppc_canonicalize_symbol_name (char *name)
4988
{
4989
  char *s;
4990
 
4991
  if (ppc_stab_symbol)
4992
    return name;
4993
 
4994
  for (s = name; *s != '\0' && *s != '{' && *s != '['; s++)
4995
    ;
4996
  if (*s != '\0')
4997
    {
4998
      char brac;
4999
 
5000
      if (*s == '[')
5001
        brac = ']';
5002
      else
5003
        {
5004
          *s = '[';
5005
          brac = '}';
5006
        }
5007
 
5008
      for (s++; *s != '\0' && *s != brac; s++)
5009
        *s = TOUPPER (*s);
5010
 
5011
      if (*s == '\0' || s[1] != '\0')
5012
        as_bad (_("bad symbol suffix"));
5013
 
5014
      *s = ']';
5015
    }
5016
 
5017
  return name;
5018
}
5019
 
5020
/* Set the class of a symbol based on the suffix, if any.  This is
5021
   called whenever a new symbol is created.  */
5022
 
5023
void
5024
ppc_symbol_new_hook (symbolS *sym)
5025
{
5026
  struct ppc_tc_sy *tc;
5027
  const char *s;
5028
 
5029
  tc = symbol_get_tc (sym);
5030
  tc->next = NULL;
5031
  tc->output = 0;
5032
  tc->symbol_class = -1;
5033
  tc->real_name = NULL;
5034
  tc->subseg = 0;
5035
  tc->align = 0;
5036
  tc->size = NULL;
5037
  tc->within = NULL;
5038
 
5039
  if (ppc_stab_symbol)
5040
    return;
5041
 
5042
  s = strchr (S_GET_NAME (sym), '[');
5043
  if (s == (const char *) NULL)
5044
    {
5045
      /* There is no suffix.  */
5046
      return;
5047
    }
5048
 
5049
  ++s;
5050
 
5051
  switch (s[0])
5052
    {
5053
    case 'B':
5054
      if (strcmp (s, "BS]") == 0)
5055
        tc->symbol_class = XMC_BS;
5056
      break;
5057
    case 'D':
5058
      if (strcmp (s, "DB]") == 0)
5059
        tc->symbol_class = XMC_DB;
5060
      else if (strcmp (s, "DS]") == 0)
5061
        tc->symbol_class = XMC_DS;
5062
      break;
5063
    case 'G':
5064
      if (strcmp (s, "GL]") == 0)
5065
        tc->symbol_class = XMC_GL;
5066
      break;
5067
    case 'P':
5068
      if (strcmp (s, "PR]") == 0)
5069
        tc->symbol_class = XMC_PR;
5070
      break;
5071
    case 'R':
5072
      if (strcmp (s, "RO]") == 0)
5073
        tc->symbol_class = XMC_RO;
5074
      else if (strcmp (s, "RW]") == 0)
5075
        tc->symbol_class = XMC_RW;
5076
      break;
5077
    case 'S':
5078
      if (strcmp (s, "SV]") == 0)
5079
        tc->symbol_class = XMC_SV;
5080
      break;
5081
    case 'T':
5082
      if (strcmp (s, "TC]") == 0)
5083
        tc->symbol_class = XMC_TC;
5084
      else if (strcmp (s, "TI]") == 0)
5085
        tc->symbol_class = XMC_TI;
5086
      else if (strcmp (s, "TB]") == 0)
5087
        tc->symbol_class = XMC_TB;
5088
      else if (strcmp (s, "TC0]") == 0 || strcmp (s, "T0]") == 0)
5089
        tc->symbol_class = XMC_TC0;
5090
      break;
5091
    case 'U':
5092
      if (strcmp (s, "UA]") == 0)
5093
        tc->symbol_class = XMC_UA;
5094
      else if (strcmp (s, "UC]") == 0)
5095
        tc->symbol_class = XMC_UC;
5096
      break;
5097
    case 'X':
5098
      if (strcmp (s, "XO]") == 0)
5099
        tc->symbol_class = XMC_XO;
5100
      break;
5101
    }
5102
 
5103
  if (tc->symbol_class == -1)
5104
    as_bad (_("Unrecognized symbol suffix"));
5105
}
5106
 
5107
/* Set the class of a label based on where it is defined.  This
5108
   handles symbols without suffixes.  Also, move the symbol so that it
5109
   follows the csect symbol.  */
5110
 
5111
void
5112
ppc_frob_label (symbolS *sym)
5113
{
5114
  if (ppc_current_csect != (symbolS *) NULL)
5115
    {
5116
      if (symbol_get_tc (sym)->symbol_class == -1)
5117
        symbol_get_tc (sym)->symbol_class = symbol_get_tc (ppc_current_csect)->symbol_class;
5118
 
5119
      symbol_remove (sym, &symbol_rootP, &symbol_lastP);
5120
      symbol_append (sym, symbol_get_tc (ppc_current_csect)->within,
5121
                     &symbol_rootP, &symbol_lastP);
5122
      symbol_get_tc (ppc_current_csect)->within = sym;
5123
    }
5124
 
5125
#ifdef OBJ_ELF
5126
  dwarf2_emit_label (sym);
5127
#endif
5128
}
5129
 
5130
/* This variable is set by ppc_frob_symbol if any absolute symbols are
5131
   seen.  It tells ppc_adjust_symtab whether it needs to look through
5132
   the symbols.  */
5133
 
5134
static bfd_boolean ppc_saw_abs;
5135
 
5136
/* Change the name of a symbol just before writing it out.  Set the
5137
   real name if the .rename pseudo-op was used.  Otherwise, remove any
5138
   class suffix.  Return 1 if the symbol should not be included in the
5139
   symbol table.  */
5140
 
5141
int
5142
ppc_frob_symbol (symbolS *sym)
5143
{
5144
  static symbolS *ppc_last_function;
5145
  static symbolS *set_end;
5146
 
5147
  /* Discard symbols that should not be included in the output symbol
5148
     table.  */
5149
  if (! symbol_used_in_reloc_p (sym)
5150
      && ((symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) != 0
5151
          || (! (S_IS_EXTERNAL (sym) || S_IS_WEAK (sym))
5152
              && ! symbol_get_tc (sym)->output
5153
              && S_GET_STORAGE_CLASS (sym) != C_FILE)))
5154
    return 1;
5155
 
5156
  /* This one will disappear anyway.  Don't make a csect sym for it.  */
5157
  if (sym == abs_section_sym)
5158
    return 1;
5159
 
5160
  if (symbol_get_tc (sym)->real_name != (char *) NULL)
5161
    S_SET_NAME (sym, symbol_get_tc (sym)->real_name);
5162
  else
5163
    {
5164
      const char *name;
5165
      const char *s;
5166
 
5167
      name = S_GET_NAME (sym);
5168
      s = strchr (name, '[');
5169
      if (s != (char *) NULL)
5170
        {
5171
          unsigned int len;
5172
          char *snew;
5173
 
5174
          len = s - name;
5175
          snew = xmalloc (len + 1);
5176
          memcpy (snew, name, len);
5177
          snew[len] = '\0';
5178
 
5179
          S_SET_NAME (sym, snew);
5180
        }
5181
    }
5182
 
5183
  if (set_end != (symbolS *) NULL)
5184
    {
5185
      SA_SET_SYM_ENDNDX (set_end, sym);
5186
      set_end = NULL;
5187
    }
5188
 
5189
  if (SF_GET_FUNCTION (sym))
5190
    {
5191
      if (ppc_last_function != (symbolS *) NULL)
5192
        as_bad (_("two .function pseudo-ops with no intervening .ef"));
5193
      ppc_last_function = sym;
5194
      if (symbol_get_tc (sym)->size != (symbolS *) NULL)
5195
        {
5196
          resolve_symbol_value (symbol_get_tc (sym)->size);
5197
          SA_SET_SYM_FSIZE (sym,
5198
                            (long) S_GET_VALUE (symbol_get_tc (sym)->size));
5199
        }
5200
    }
5201
  else if (S_GET_STORAGE_CLASS (sym) == C_FCN
5202
           && strcmp (S_GET_NAME (sym), ".ef") == 0)
5203
    {
5204
      if (ppc_last_function == (symbolS *) NULL)
5205
        as_bad (_(".ef with no preceding .function"));
5206
      else
5207
        {
5208
          set_end = ppc_last_function;
5209
          ppc_last_function = NULL;
5210
 
5211
          /* We don't have a C_EFCN symbol, but we need to force the
5212
             COFF backend to believe that it has seen one.  */
5213
          coff_last_function = NULL;
5214
        }
5215
    }
5216
 
5217
  if (! (S_IS_EXTERNAL (sym) || S_IS_WEAK (sym))
5218
      && (symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) == 0
5219
      && S_GET_STORAGE_CLASS (sym) != C_FILE
5220
      && S_GET_STORAGE_CLASS (sym) != C_FCN
5221
      && S_GET_STORAGE_CLASS (sym) != C_BLOCK
5222
      && S_GET_STORAGE_CLASS (sym) != C_BSTAT
5223
      && S_GET_STORAGE_CLASS (sym) != C_ESTAT
5224
      && S_GET_STORAGE_CLASS (sym) != C_BINCL
5225
      && S_GET_STORAGE_CLASS (sym) != C_EINCL
5226
      && S_GET_SEGMENT (sym) != ppc_coff_debug_section)
5227
    S_SET_STORAGE_CLASS (sym, C_HIDEXT);
5228
 
5229
  if (S_GET_STORAGE_CLASS (sym) == C_EXT
5230
      || S_GET_STORAGE_CLASS (sym) == C_AIX_WEAKEXT
5231
      || S_GET_STORAGE_CLASS (sym) == C_HIDEXT)
5232
    {
5233
      int i;
5234
      union internal_auxent *a;
5235
 
5236
      /* Create a csect aux.  */
5237
      i = S_GET_NUMBER_AUXILIARY (sym);
5238
      S_SET_NUMBER_AUXILIARY (sym, i + 1);
5239
      a = &coffsymbol (symbol_get_bfdsym (sym))->native[i + 1].u.auxent;
5240
      if (symbol_get_tc (sym)->symbol_class == XMC_TC0)
5241
        {
5242
          /* This is the TOC table.  */
5243
          know (strcmp (S_GET_NAME (sym), "TOC") == 0);
5244
          a->x_csect.x_scnlen.l = 0;
5245
          a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
5246
        }
5247
      else if (symbol_get_tc (sym)->subseg != 0)
5248
        {
5249
          /* This is a csect symbol.  x_scnlen is the size of the
5250
             csect.  */
5251
          if (symbol_get_tc (sym)->next == (symbolS *) NULL)
5252
            a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
5253
                                                       S_GET_SEGMENT (sym))
5254
                                     - S_GET_VALUE (sym));
5255
          else
5256
            {
5257
              resolve_symbol_value (symbol_get_tc (sym)->next);
5258
              a->x_csect.x_scnlen.l = (S_GET_VALUE (symbol_get_tc (sym)->next)
5259
                                       - S_GET_VALUE (sym));
5260
            }
5261
          a->x_csect.x_smtyp = (symbol_get_tc (sym)->align << 3) | XTY_SD;
5262
        }
5263
      else if (S_GET_SEGMENT (sym) == bss_section)
5264
        {
5265
          /* This is a common symbol.  */
5266
          a->x_csect.x_scnlen.l = symbol_get_frag (sym)->fr_offset;
5267
          a->x_csect.x_smtyp = (symbol_get_tc (sym)->align << 3) | XTY_CM;
5268
          if (S_IS_EXTERNAL (sym))
5269
            symbol_get_tc (sym)->symbol_class = XMC_RW;
5270
          else
5271
            symbol_get_tc (sym)->symbol_class = XMC_BS;
5272
        }
5273
      else if (S_GET_SEGMENT (sym) == absolute_section)
5274
        {
5275
          /* This is an absolute symbol.  The csect will be created by
5276
             ppc_adjust_symtab.  */
5277
          ppc_saw_abs = TRUE;
5278
          a->x_csect.x_smtyp = XTY_LD;
5279
          if (symbol_get_tc (sym)->symbol_class == -1)
5280
            symbol_get_tc (sym)->symbol_class = XMC_XO;
5281
        }
5282
      else if (! S_IS_DEFINED (sym))
5283
        {
5284
          /* This is an external symbol.  */
5285
          a->x_csect.x_scnlen.l = 0;
5286
          a->x_csect.x_smtyp = XTY_ER;
5287
        }
5288
      else if (symbol_get_tc (sym)->symbol_class == XMC_TC)
5289
        {
5290
          symbolS *next;
5291
 
5292
          /* This is a TOC definition.  x_scnlen is the size of the
5293
             TOC entry.  */
5294
          next = symbol_next (sym);
5295
          while (symbol_get_tc (next)->symbol_class == XMC_TC0)
5296
            next = symbol_next (next);
5297
          if (next == (symbolS *) NULL
5298
              || symbol_get_tc (next)->symbol_class != XMC_TC)
5299
            {
5300
              if (ppc_after_toc_frag == (fragS *) NULL)
5301
                a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
5302
                                                           data_section)
5303
                                         - S_GET_VALUE (sym));
5304
              else
5305
                a->x_csect.x_scnlen.l = (ppc_after_toc_frag->fr_address
5306
                                         - S_GET_VALUE (sym));
5307
            }
5308
          else
5309
            {
5310
              resolve_symbol_value (next);
5311
              a->x_csect.x_scnlen.l = (S_GET_VALUE (next)
5312
                                       - S_GET_VALUE (sym));
5313
            }
5314
          a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
5315
        }
5316
      else
5317
        {
5318
          symbolS *csect;
5319
 
5320
          /* This is a normal symbol definition.  x_scnlen is the
5321
             symbol index of the containing csect.  */
5322
          if (S_GET_SEGMENT (sym) == text_section)
5323
            csect = ppc_text_csects;
5324
          else if (S_GET_SEGMENT (sym) == data_section)
5325
            csect = ppc_data_csects;
5326
          else
5327
            abort ();
5328
 
5329
          /* Skip the initial dummy symbol.  */
5330
          csect = symbol_get_tc (csect)->next;
5331
 
5332
          if (csect == (symbolS *) NULL)
5333
            {
5334
              as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym));
5335
              a->x_csect.x_scnlen.l = 0;
5336
            }
5337
          else
5338
            {
5339
              while (symbol_get_tc (csect)->next != (symbolS *) NULL)
5340
                {
5341
                  resolve_symbol_value (symbol_get_tc (csect)->next);
5342
                  if (S_GET_VALUE (symbol_get_tc (csect)->next)
5343
                      > S_GET_VALUE (sym))
5344
                    break;
5345
                  csect = symbol_get_tc (csect)->next;
5346
                }
5347
 
5348
              a->x_csect.x_scnlen.p =
5349
                coffsymbol (symbol_get_bfdsym (csect))->native;
5350
              coffsymbol (symbol_get_bfdsym (sym))->native[i + 1].fix_scnlen =
5351
                1;
5352
            }
5353
          a->x_csect.x_smtyp = XTY_LD;
5354
        }
5355
 
5356
      a->x_csect.x_parmhash = 0;
5357
      a->x_csect.x_snhash = 0;
5358
      if (symbol_get_tc (sym)->symbol_class == -1)
5359
        a->x_csect.x_smclas = XMC_PR;
5360
      else
5361
        a->x_csect.x_smclas = symbol_get_tc (sym)->symbol_class;
5362
      a->x_csect.x_stab = 0;
5363
      a->x_csect.x_snstab = 0;
5364
 
5365
      /* Don't let the COFF backend resort these symbols.  */
5366
      symbol_get_bfdsym (sym)->flags |= BSF_NOT_AT_END;
5367
    }
5368
  else if (S_GET_STORAGE_CLASS (sym) == C_BSTAT)
5369
    {
5370
      /* We want the value to be the symbol index of the referenced
5371
         csect symbol.  BFD will do that for us if we set the right
5372
         flags.  */
5373
      asymbol *bsym = symbol_get_bfdsym (symbol_get_tc (sym)->within);
5374
      combined_entry_type *c = coffsymbol (bsym)->native;
5375
 
5376
      S_SET_VALUE (sym, (valueT) (size_t) c);
5377
      coffsymbol (symbol_get_bfdsym (sym))->native->fix_value = 1;
5378
    }
5379
  else if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
5380
    {
5381
      symbolS *block;
5382
      symbolS *csect;
5383
 
5384
      /* The value is the offset from the enclosing csect.  */
5385
      block = symbol_get_tc (sym)->within;
5386
      csect = symbol_get_tc (block)->within;
5387
      resolve_symbol_value (csect);
5388
      S_SET_VALUE (sym, S_GET_VALUE (sym) - S_GET_VALUE (csect));
5389
    }
5390
  else if (S_GET_STORAGE_CLASS (sym) == C_BINCL
5391
           || S_GET_STORAGE_CLASS (sym) == C_EINCL)
5392
    {
5393
      /* We want the value to be a file offset into the line numbers.
5394
         BFD will do that for us if we set the right flags.  We have
5395
         already set the value correctly.  */
5396
      coffsymbol (symbol_get_bfdsym (sym))->native->fix_line = 1;
5397
    }
5398
 
5399
  return 0;
5400
}
5401
 
5402
/* Adjust the symbol table.  This creates csect symbols for all
5403
   absolute symbols.  */
5404
 
5405
void
5406
ppc_adjust_symtab (void)
5407
{
5408
  symbolS *sym;
5409
 
5410
  if (! ppc_saw_abs)
5411
    return;
5412
 
5413
  for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
5414
    {
5415
      symbolS *csect;
5416
      int i;
5417
      union internal_auxent *a;
5418
 
5419
      if (S_GET_SEGMENT (sym) != absolute_section)
5420
        continue;
5421
 
5422
      csect = symbol_create (".abs[XO]", absolute_section,
5423
                             S_GET_VALUE (sym), &zero_address_frag);
5424
      symbol_get_bfdsym (csect)->value = S_GET_VALUE (sym);
5425
      S_SET_STORAGE_CLASS (csect, C_HIDEXT);
5426
      i = S_GET_NUMBER_AUXILIARY (csect);
5427
      S_SET_NUMBER_AUXILIARY (csect, i + 1);
5428
      a = &coffsymbol (symbol_get_bfdsym (csect))->native[i + 1].u.auxent;
5429
      a->x_csect.x_scnlen.l = 0;
5430
      a->x_csect.x_smtyp = XTY_SD;
5431
      a->x_csect.x_parmhash = 0;
5432
      a->x_csect.x_snhash = 0;
5433
      a->x_csect.x_smclas = XMC_XO;
5434
      a->x_csect.x_stab = 0;
5435
      a->x_csect.x_snstab = 0;
5436
 
5437
      symbol_insert (csect, sym, &symbol_rootP, &symbol_lastP);
5438
 
5439
      i = S_GET_NUMBER_AUXILIARY (sym);
5440
      a = &coffsymbol (symbol_get_bfdsym (sym))->native[i].u.auxent;
5441
      a->x_csect.x_scnlen.p = coffsymbol (symbol_get_bfdsym (csect))->native;
5442
      coffsymbol (symbol_get_bfdsym (sym))->native[i].fix_scnlen = 1;
5443
    }
5444
 
5445
  ppc_saw_abs = FALSE;
5446
}
5447
 
5448
/* Set the VMA for a section.  This is called on all the sections in
5449
   turn.  */
5450
 
5451
void
5452
ppc_frob_section (asection *sec)
5453
{
5454
  static bfd_vma vma = 0;
5455
 
5456
  vma = md_section_align (sec, vma);
5457
  bfd_set_section_vma (stdoutput, sec, vma);
5458
  vma += bfd_section_size (stdoutput, sec);
5459
}
5460
 
5461
#endif /* OBJ_XCOFF */
5462
 
5463
char *
5464
md_atof (int type, char *litp, int *sizep)
5465
{
5466
  return ieee_md_atof (type, litp, sizep, target_big_endian);
5467
}
5468
 
5469
/* Write a value out to the object file, using the appropriate
5470
   endianness.  */
5471
 
5472
void
5473
md_number_to_chars (char *buf, valueT val, int n)
5474
{
5475
  if (target_big_endian)
5476
    number_to_chars_bigendian (buf, val, n);
5477
  else
5478
    number_to_chars_littleendian (buf, val, n);
5479
}
5480
 
5481
/* Align a section (I don't know why this is machine dependent).  */
5482
 
5483
valueT
5484
md_section_align (asection *seg ATTRIBUTE_UNUSED, valueT addr)
5485
{
5486
#ifdef OBJ_ELF
5487
  return addr;
5488
#else
5489
  int align = bfd_get_section_alignment (stdoutput, seg);
5490
 
5491
  return ((addr + (1 << align) - 1) & (-1 << align));
5492
#endif
5493
}
5494
 
5495
/* We don't have any form of relaxing.  */
5496
 
5497
int
5498
md_estimate_size_before_relax (fragS *fragp ATTRIBUTE_UNUSED,
5499
                               asection *seg ATTRIBUTE_UNUSED)
5500
{
5501
  abort ();
5502
  return 0;
5503
}
5504
 
5505
/* Convert a machine dependent frag.  We never generate these.  */
5506
 
5507
void
5508
md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
5509
                 asection *sec ATTRIBUTE_UNUSED,
5510
                 fragS *fragp ATTRIBUTE_UNUSED)
5511
{
5512
  abort ();
5513
}
5514
 
5515
/* We have no need to default values of symbols.  */
5516
 
5517
symbolS *
5518
md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
5519
{
5520
  return 0;
5521
}
5522
 
5523
/* Functions concerning relocs.  */
5524
 
5525
/* The location from which a PC relative jump should be calculated,
5526
   given a PC relative reloc.  */
5527
 
5528
long
5529
md_pcrel_from_section (fixS *fixp, segT sec ATTRIBUTE_UNUSED)
5530
{
5531
  return fixp->fx_frag->fr_address + fixp->fx_where;
5532
}
5533
 
5534
#ifdef OBJ_XCOFF
5535
 
5536
/* This is called to see whether a fixup should be adjusted to use a
5537
   section symbol.  We take the opportunity to change a fixup against
5538
   a symbol in the TOC subsegment into a reloc against the
5539
   corresponding .tc symbol.  */
5540
 
5541
int
5542
ppc_fix_adjustable (fixS *fix)
5543
{
5544
  valueT val = resolve_symbol_value (fix->fx_addsy);
5545
  segT symseg = S_GET_SEGMENT (fix->fx_addsy);
5546
  TC_SYMFIELD_TYPE *tc;
5547
 
5548
  if (symseg == absolute_section)
5549
    return 0;
5550
 
5551
  if (ppc_toc_csect != (symbolS *) NULL
5552
      && fix->fx_addsy != ppc_toc_csect
5553
      && symseg == data_section
5554
      && val >= ppc_toc_frag->fr_address
5555
      && (ppc_after_toc_frag == (fragS *) NULL
5556
          || val < ppc_after_toc_frag->fr_address))
5557
    {
5558
      symbolS *sy;
5559
 
5560
      for (sy = symbol_next (ppc_toc_csect);
5561
           sy != (symbolS *) NULL;
5562
           sy = symbol_next (sy))
5563
        {
5564
          TC_SYMFIELD_TYPE *sy_tc = symbol_get_tc (sy);
5565
 
5566
          if (sy_tc->symbol_class == XMC_TC0)
5567
            continue;
5568
          if (sy_tc->symbol_class != XMC_TC)
5569
            break;
5570
          if (val == resolve_symbol_value (sy))
5571
            {
5572
              fix->fx_addsy = sy;
5573
              fix->fx_addnumber = val - ppc_toc_frag->fr_address;
5574
              return 0;
5575
            }
5576
        }
5577
 
5578
      as_bad_where (fix->fx_file, fix->fx_line,
5579
                    _("symbol in .toc does not match any .tc"));
5580
    }
5581
 
5582
  /* Possibly adjust the reloc to be against the csect.  */
5583
  tc = symbol_get_tc (fix->fx_addsy);
5584
  if (tc->subseg == 0
5585
      && tc->symbol_class != XMC_TC0
5586
      && tc->symbol_class != XMC_TC
5587
      && symseg != bss_section
5588
      /* Don't adjust if this is a reloc in the toc section.  */
5589
      && (symseg != data_section
5590
          || ppc_toc_csect == NULL
5591
          || val < ppc_toc_frag->fr_address
5592
          || (ppc_after_toc_frag != NULL
5593
              && val >= ppc_after_toc_frag->fr_address)))
5594
    {
5595
      symbolS *csect;
5596
      symbolS *next_csect;
5597
 
5598
      if (symseg == text_section)
5599
        csect = ppc_text_csects;
5600
      else if (symseg == data_section)
5601
        csect = ppc_data_csects;
5602
      else
5603
        abort ();
5604
 
5605
      /* Skip the initial dummy symbol.  */
5606
      csect = symbol_get_tc (csect)->next;
5607
 
5608
      if (csect != (symbolS *) NULL)
5609
        {
5610
          while ((next_csect = symbol_get_tc (csect)->next) != (symbolS *) NULL
5611
                 && (symbol_get_frag (next_csect)->fr_address <= val))
5612
            {
5613
              /* If the csect address equals the symbol value, then we
5614
                 have to look through the full symbol table to see
5615
                 whether this is the csect we want.  Note that we will
5616
                 only get here if the csect has zero length.  */
5617
              if (symbol_get_frag (csect)->fr_address == val
5618
                  && S_GET_VALUE (csect) == val)
5619
                {
5620
                  symbolS *scan;
5621
 
5622
                  for (scan = symbol_next (csect);
5623
                       scan != NULL;
5624
                       scan = symbol_next (scan))
5625
                    {
5626
                      if (symbol_get_tc (scan)->subseg != 0)
5627
                        break;
5628
                      if (scan == fix->fx_addsy)
5629
                        break;
5630
                    }
5631
 
5632
                  /* If we found the symbol before the next csect
5633
                     symbol, then this is the csect we want.  */
5634
                  if (scan == fix->fx_addsy)
5635
                    break;
5636
                }
5637
 
5638
              csect = next_csect;
5639
            }
5640
 
5641
          fix->fx_offset += val - symbol_get_frag (csect)->fr_address;
5642
          fix->fx_addsy = csect;
5643
        }
5644
      return 0;
5645
    }
5646
 
5647
  /* Adjust a reloc against a .lcomm symbol to be against the base
5648
     .lcomm.  */
5649
  if (symseg == bss_section
5650
      && ! S_IS_EXTERNAL (fix->fx_addsy))
5651
    {
5652
      symbolS *sy = symbol_get_frag (fix->fx_addsy)->fr_symbol;
5653
 
5654
      fix->fx_offset += val - resolve_symbol_value (sy);
5655
      fix->fx_addsy = sy;
5656
    }
5657
 
5658
  return 0;
5659
}
5660
 
5661
/* A reloc from one csect to another must be kept.  The assembler
5662
   will, of course, keep relocs between sections, and it will keep
5663
   absolute relocs, but we need to force it to keep PC relative relocs
5664
   between two csects in the same section.  */
5665
 
5666
int
5667
ppc_force_relocation (fixS *fix)
5668
{
5669
  /* At this point fix->fx_addsy should already have been converted to
5670
     a csect symbol.  If the csect does not include the fragment, then
5671
     we need to force the relocation.  */
5672
  if (fix->fx_pcrel
5673
      && fix->fx_addsy != NULL
5674
      && symbol_get_tc (fix->fx_addsy)->subseg != 0
5675
      && ((symbol_get_frag (fix->fx_addsy)->fr_address
5676
           > fix->fx_frag->fr_address)
5677
          || (symbol_get_tc (fix->fx_addsy)->next != NULL
5678
              && (symbol_get_frag (symbol_get_tc (fix->fx_addsy)->next)->fr_address
5679
                  <= fix->fx_frag->fr_address))))
5680
    return 1;
5681
 
5682
  return generic_force_reloc (fix);
5683
}
5684
 
5685
#endif /* OBJ_XCOFF */
5686
 
5687
#ifdef OBJ_ELF
5688
/* If this function returns non-zero, it guarantees that a relocation
5689
   will be emitted for a fixup.  */
5690
 
5691
int
5692
ppc_force_relocation (fixS *fix)
5693
{
5694
  /* Branch prediction relocations must force a relocation, as must
5695
     the vtable description relocs.  */
5696
  switch (fix->fx_r_type)
5697
    {
5698
    case BFD_RELOC_PPC_B16_BRTAKEN:
5699
    case BFD_RELOC_PPC_B16_BRNTAKEN:
5700
    case BFD_RELOC_PPC_BA16_BRTAKEN:
5701
    case BFD_RELOC_PPC_BA16_BRNTAKEN:
5702
    case BFD_RELOC_24_PLT_PCREL:
5703
    case BFD_RELOC_PPC64_TOC:
5704
      return 1;
5705
    default:
5706
      break;
5707
    }
5708
 
5709
  if (fix->fx_r_type >= BFD_RELOC_PPC_TLS
5710
      && fix->fx_r_type <= BFD_RELOC_PPC64_DTPREL16_HIGHESTA)
5711
    return 1;
5712
 
5713
  return generic_force_reloc (fix);
5714
}
5715
 
5716
int
5717
ppc_fix_adjustable (fixS *fix)
5718
{
5719
  return (fix->fx_r_type != BFD_RELOC_16_GOTOFF
5720
          && fix->fx_r_type != BFD_RELOC_LO16_GOTOFF
5721
          && fix->fx_r_type != BFD_RELOC_HI16_GOTOFF
5722
          && fix->fx_r_type != BFD_RELOC_HI16_S_GOTOFF
5723
          && fix->fx_r_type != BFD_RELOC_GPREL16
5724
          && fix->fx_r_type != BFD_RELOC_VTABLE_INHERIT
5725
          && fix->fx_r_type != BFD_RELOC_VTABLE_ENTRY
5726
          && !(fix->fx_r_type >= BFD_RELOC_PPC_TLS
5727
               && fix->fx_r_type <= BFD_RELOC_PPC64_DTPREL16_HIGHESTA));
5728
}
5729
#endif
5730
 
5731
/* Implement HANDLE_ALIGN.  This writes the NOP pattern into an
5732
   rs_align_code frag.  */
5733
 
5734
void
5735
ppc_handle_align (struct frag *fragP)
5736
{
5737
  valueT count = (fragP->fr_next->fr_address
5738
                  - (fragP->fr_address + fragP->fr_fix));
5739
 
5740
  if (count != 0 && (count & 3) == 0)
5741
    {
5742
      char *dest = fragP->fr_literal + fragP->fr_fix;
5743
 
5744
      fragP->fr_var = 4;
5745
      md_number_to_chars (dest, 0x60000000, 4);
5746
 
5747
      if ((ppc_cpu & PPC_OPCODE_POWER6) != 0
5748
          || (ppc_cpu & PPC_OPCODE_POWER7) != 0)
5749
        {
5750
          /* For power6 and power7, we want the last nop to be a group
5751
             terminating one.  Do this by inserting an rs_fill frag immediately
5752
             after this one, with its address set to the last nop location.
5753
             This will automatically reduce the number of nops in the current
5754
             frag by one.  */
5755
          if (count > 4)
5756
            {
5757
              struct frag *group_nop = xmalloc (SIZEOF_STRUCT_FRAG + 4);
5758
 
5759
              memcpy (group_nop, fragP, SIZEOF_STRUCT_FRAG);
5760
              group_nop->fr_address = group_nop->fr_next->fr_address - 4;
5761
              group_nop->fr_fix = 0;
5762
              group_nop->fr_offset = 1;
5763
              group_nop->fr_type = rs_fill;
5764
              fragP->fr_next = group_nop;
5765
              dest = group_nop->fr_literal;
5766
            }
5767
 
5768
          if ((ppc_cpu & PPC_OPCODE_POWER7) != 0)
5769
            /* power7 group terminating nop: "ori 2,2,0".  */
5770
            md_number_to_chars (dest, 0x60420000, 4);
5771
          else
5772
            /* power6 group terminating nop: "ori 1,1,0".  */
5773
            md_number_to_chars (dest, 0x60210000, 4);
5774
        }
5775
    }
5776
}
5777
 
5778
/* Apply a fixup to the object code.  This is called for all the
5779
   fixups we generated by the call to fix_new_exp, above.  In the call
5780
   above we used a reloc code which was the largest legal reloc code
5781
   plus the operand index.  Here we undo that to recover the operand
5782
   index.  At this point all symbol values should be fully resolved,
5783
   and we attempt to completely resolve the reloc.  If we can not do
5784
   that, we determine the correct reloc code and put it back in the
5785
   fixup.  */
5786
 
5787
void
5788
md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
5789
{
5790
  valueT value = * valP;
5791
 
5792
#ifdef OBJ_ELF
5793
  if (fixP->fx_addsy != NULL)
5794
    {
5795
      /* Hack around bfd_install_relocation brain damage.  */
5796
      if (fixP->fx_pcrel)
5797
        value += fixP->fx_frag->fr_address + fixP->fx_where;
5798
    }
5799
  else
5800
    fixP->fx_done = 1;
5801
#else
5802
  /* FIXME FIXME FIXME: The value we are passed in *valP includes
5803
     the symbol values.  If we are doing this relocation the code in
5804
     write.c is going to call bfd_install_relocation, which is also
5805
     going to use the symbol value.  That means that if the reloc is
5806
     fully resolved we want to use *valP since bfd_install_relocation is
5807
     not being used.
5808
     However, if the reloc is not fully resolved we do not want to
5809
     use *valP, and must use fx_offset instead.  If the relocation
5810
     is PC-relative, we then need to re-apply md_pcrel_from_section
5811
     to this new relocation value.  */
5812
  if (fixP->fx_addsy == (symbolS *) NULL)
5813
    fixP->fx_done = 1;
5814
 
5815
  else
5816
    {
5817
      value = fixP->fx_offset;
5818
      if (fixP->fx_pcrel)
5819
        value -= md_pcrel_from_section (fixP, seg);
5820
    }
5821
#endif
5822
 
5823
  if (fixP->fx_subsy != (symbolS *) NULL)
5824
    {
5825
      /* We can't actually support subtracting a symbol.  */
5826
      as_bad_where (fixP->fx_file, fixP->fx_line, _("expression too complex"));
5827
    }
5828
 
5829
  if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED)
5830
    {
5831
      int opindex;
5832
      const struct powerpc_operand *operand;
5833
      char *where;
5834
      unsigned long insn;
5835
 
5836
      opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED;
5837
 
5838
      operand = &powerpc_operands[opindex];
5839
 
5840
#ifdef OBJ_XCOFF
5841
      /* An instruction like `lwz 9,sym(30)' when `sym' is not a TOC symbol
5842
         does not generate a reloc.  It uses the offset of `sym' within its
5843
         csect.  Other usages, such as `.long sym', generate relocs.  This
5844
         is the documented behaviour of non-TOC symbols.  */
5845
      if ((operand->flags & PPC_OPERAND_PARENS) != 0
5846
          && (operand->bitm & 0xfff0) == 0xfff0
5847
          && operand->shift == 0
5848
          && (operand->insert == NULL || ppc_obj64)
5849
          && fixP->fx_addsy != NULL
5850
          && symbol_get_tc (fixP->fx_addsy)->subseg != 0
5851
          && symbol_get_tc (fixP->fx_addsy)->symbol_class != XMC_TC
5852
          && symbol_get_tc (fixP->fx_addsy)->symbol_class != XMC_TC0
5853
          && S_GET_SEGMENT (fixP->fx_addsy) != bss_section)
5854
        {
5855
          value = fixP->fx_offset;
5856
          fixP->fx_done = 1;
5857
        }
5858
#endif
5859
 
5860
      /* Fetch the instruction, insert the fully resolved operand
5861
         value, and stuff the instruction back again.  */
5862
      where = fixP->fx_frag->fr_literal + fixP->fx_where;
5863
      if (target_big_endian)
5864
        insn = bfd_getb32 ((unsigned char *) where);
5865
      else
5866
        insn = bfd_getl32 ((unsigned char *) where);
5867
      insn = ppc_insert_operand (insn, operand, (offsetT) value,
5868
                                 fixP->tc_fix_data.ppc_cpu,
5869
                                 fixP->fx_file, fixP->fx_line);
5870
      if (target_big_endian)
5871
        bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
5872
      else
5873
        bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
5874
 
5875
      if (fixP->fx_done)
5876
        /* Nothing else to do here.  */
5877
        return;
5878
 
5879
      gas_assert (fixP->fx_addsy != NULL);
5880
 
5881
      /* Determine a BFD reloc value based on the operand information.
5882
         We are only prepared to turn a few of the operands into
5883
         relocs.  */
5884
      if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
5885
          && operand->bitm == 0x3fffffc
5886
          && operand->shift == 0)
5887
        fixP->fx_r_type = BFD_RELOC_PPC_B26;
5888
      else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
5889
          && operand->bitm == 0xfffc
5890
          && operand->shift == 0)
5891
        {
5892
          fixP->fx_r_type = BFD_RELOC_PPC_B16;
5893
#ifdef OBJ_XCOFF
5894
          fixP->fx_size = 2;
5895
          if (target_big_endian)
5896
            fixP->fx_where += 2;
5897
#endif
5898
        }
5899
      else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
5900
               && operand->bitm == 0x3fffffc
5901
               && operand->shift == 0)
5902
        fixP->fx_r_type = BFD_RELOC_PPC_BA26;
5903
      else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
5904
               && operand->bitm == 0xfffc
5905
               && operand->shift == 0)
5906
        {
5907
          fixP->fx_r_type = BFD_RELOC_PPC_BA16;
5908
#ifdef OBJ_XCOFF
5909
          fixP->fx_size = 2;
5910
          if (target_big_endian)
5911
            fixP->fx_where += 2;
5912
#endif
5913
        }
5914
#if defined (OBJ_XCOFF) || defined (OBJ_ELF)
5915
      else if ((operand->flags & PPC_OPERAND_PARENS) != 0
5916
               && (operand->bitm & 0xfff0) == 0xfff0
5917
               && operand->shift == 0)
5918
        {
5919
          if (ppc_is_toc_sym (fixP->fx_addsy))
5920
            {
5921
              fixP->fx_r_type = BFD_RELOC_PPC_TOC16;
5922
#ifdef OBJ_ELF
5923
              if (ppc_obj64
5924
                  && (operand->flags & PPC_OPERAND_DS) != 0)
5925
                fixP->fx_r_type = BFD_RELOC_PPC64_TOC16_DS;
5926
#endif
5927
            }
5928
          else
5929
            {
5930
              fixP->fx_r_type = BFD_RELOC_16;
5931
#ifdef OBJ_ELF
5932
              if (ppc_obj64
5933
                  && (operand->flags & PPC_OPERAND_DS) != 0)
5934
                fixP->fx_r_type = BFD_RELOC_PPC64_ADDR16_DS;
5935
#endif
5936
            }
5937
          fixP->fx_size = 2;
5938
          if (target_big_endian)
5939
            fixP->fx_where += 2;
5940
        }
5941
#endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
5942
      else
5943
        {
5944
          char *sfile;
5945
          unsigned int sline;
5946
 
5947
          /* Use expr_symbol_where to see if this is an expression
5948
             symbol.  */
5949
          if (expr_symbol_where (fixP->fx_addsy, &sfile, &sline))
5950
            as_bad_where (fixP->fx_file, fixP->fx_line,
5951
                          _("unresolved expression that must be resolved"));
5952
          else
5953
            as_bad_where (fixP->fx_file, fixP->fx_line,
5954
                          _("unsupported relocation against %s"),
5955
                          S_GET_NAME (fixP->fx_addsy));
5956
          fixP->fx_done = 1;
5957
          return;
5958
        }
5959
    }
5960
  else
5961
    {
5962
#ifdef OBJ_ELF
5963
      ppc_elf_validate_fix (fixP, seg);
5964
#endif
5965
      switch (fixP->fx_r_type)
5966
        {
5967
        case BFD_RELOC_CTOR:
5968
          if (ppc_obj64)
5969
            goto ctor64;
5970
          /* fall through */
5971
 
5972
        case BFD_RELOC_32:
5973
          if (fixP->fx_pcrel)
5974
            fixP->fx_r_type = BFD_RELOC_32_PCREL;
5975
          /* fall through */
5976
 
5977
        case BFD_RELOC_RVA:
5978
        case BFD_RELOC_32_PCREL:
5979
        case BFD_RELOC_PPC_EMB_NADDR32:
5980
          md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5981
                              value, 4);
5982
          break;
5983
 
5984
        case BFD_RELOC_64:
5985
        ctor64:
5986
          if (fixP->fx_pcrel)
5987
            fixP->fx_r_type = BFD_RELOC_64_PCREL;
5988
          /* fall through */
5989
 
5990
        case BFD_RELOC_64_PCREL:
5991
          md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5992
                              value, 8);
5993
          break;
5994
 
5995
        case BFD_RELOC_GPREL16:
5996
        case BFD_RELOC_16_GOT_PCREL:
5997
        case BFD_RELOC_16_GOTOFF:
5998
        case BFD_RELOC_LO16_GOTOFF:
5999
        case BFD_RELOC_HI16_GOTOFF:
6000
        case BFD_RELOC_HI16_S_GOTOFF:
6001
        case BFD_RELOC_16_BASEREL:
6002
        case BFD_RELOC_LO16_BASEREL:
6003
        case BFD_RELOC_HI16_BASEREL:
6004
        case BFD_RELOC_HI16_S_BASEREL:
6005
        case BFD_RELOC_PPC_EMB_NADDR16:
6006
        case BFD_RELOC_PPC_EMB_NADDR16_LO:
6007
        case BFD_RELOC_PPC_EMB_NADDR16_HI:
6008
        case BFD_RELOC_PPC_EMB_NADDR16_HA:
6009
        case BFD_RELOC_PPC_EMB_SDAI16:
6010
        case BFD_RELOC_PPC_EMB_SDA2REL:
6011
        case BFD_RELOC_PPC_EMB_SDA2I16:
6012
        case BFD_RELOC_PPC_EMB_RELSEC16:
6013
        case BFD_RELOC_PPC_EMB_RELST_LO:
6014
        case BFD_RELOC_PPC_EMB_RELST_HI:
6015
        case BFD_RELOC_PPC_EMB_RELST_HA:
6016
        case BFD_RELOC_PPC_EMB_RELSDA:
6017
        case BFD_RELOC_PPC_TOC16:
6018
#ifdef OBJ_ELF
6019
        case BFD_RELOC_PPC64_TOC16_LO:
6020
        case BFD_RELOC_PPC64_TOC16_HI:
6021
        case BFD_RELOC_PPC64_TOC16_HA:
6022
#endif
6023
          if (fixP->fx_pcrel)
6024
            {
6025
              if (fixP->fx_addsy != NULL)
6026
                as_bad_where (fixP->fx_file, fixP->fx_line,
6027
                              _("cannot emit PC relative %s relocation against %s"),
6028
                              bfd_get_reloc_code_name (fixP->fx_r_type),
6029
                              S_GET_NAME (fixP->fx_addsy));
6030
              else
6031
                as_bad_where (fixP->fx_file, fixP->fx_line,
6032
                              _("cannot emit PC relative %s relocation"),
6033
                              bfd_get_reloc_code_name (fixP->fx_r_type));
6034
            }
6035
 
6036
          md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
6037
                              value, 2);
6038
          break;
6039
 
6040
        case BFD_RELOC_16:
6041
          if (fixP->fx_pcrel)
6042
            fixP->fx_r_type = BFD_RELOC_16_PCREL;
6043
          /* fall through */
6044
 
6045
        case BFD_RELOC_16_PCREL:
6046
          md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
6047
                              value, 2);
6048
          break;
6049
 
6050
        case BFD_RELOC_LO16:
6051
          if (fixP->fx_pcrel)
6052
            fixP->fx_r_type = BFD_RELOC_LO16_PCREL;
6053
          /* fall through */
6054
 
6055
        case BFD_RELOC_LO16_PCREL:
6056
          md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
6057
                              value, 2);
6058
          break;
6059
 
6060
          /* This case happens when you write, for example,
6061
             lis %r3,(L1-L2)@ha
6062
             where L1 and L2 are defined later.  */
6063
        case BFD_RELOC_HI16:
6064
          if (fixP->fx_pcrel)
6065
            fixP->fx_r_type = BFD_RELOC_HI16_PCREL;
6066
          /* fall through */
6067
 
6068
        case BFD_RELOC_HI16_PCREL:
6069
          md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
6070
                              PPC_HI (value), 2);
6071
          break;
6072
 
6073
        case BFD_RELOC_HI16_S:
6074
          if (fixP->fx_pcrel)
6075
            fixP->fx_r_type = BFD_RELOC_HI16_S_PCREL;
6076
          /* fall through */
6077
 
6078
        case BFD_RELOC_HI16_S_PCREL:
6079
          md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
6080
                              PPC_HA (value), 2);
6081
          break;
6082
 
6083
#ifdef OBJ_XCOFF
6084
        case BFD_RELOC_NONE:
6085
          break;
6086
#endif
6087
 
6088
#ifdef OBJ_ELF
6089
        case BFD_RELOC_PPC64_HIGHER:
6090
          if (fixP->fx_pcrel)
6091
            abort ();
6092
          md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
6093
                              PPC_HIGHER (value), 2);
6094
          break;
6095
 
6096
        case BFD_RELOC_PPC64_HIGHER_S:
6097
          if (fixP->fx_pcrel)
6098
            abort ();
6099
          md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
6100
                              PPC_HIGHERA (value), 2);
6101
          break;
6102
 
6103
        case BFD_RELOC_PPC64_HIGHEST:
6104
          if (fixP->fx_pcrel)
6105
            abort ();
6106
          md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
6107
                              PPC_HIGHEST (value), 2);
6108
          break;
6109
 
6110
        case BFD_RELOC_PPC64_HIGHEST_S:
6111
          if (fixP->fx_pcrel)
6112
            abort ();
6113
          md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
6114
                              PPC_HIGHESTA (value), 2);
6115
          break;
6116
 
6117
        case BFD_RELOC_PPC64_ADDR16_DS:
6118
        case BFD_RELOC_PPC64_ADDR16_LO_DS:
6119
        case BFD_RELOC_PPC64_GOT16_DS:
6120
        case BFD_RELOC_PPC64_GOT16_LO_DS:
6121
        case BFD_RELOC_PPC64_PLT16_LO_DS:
6122
        case BFD_RELOC_PPC64_SECTOFF_DS:
6123
        case BFD_RELOC_PPC64_SECTOFF_LO_DS:
6124
        case BFD_RELOC_PPC64_TOC16_DS:
6125
        case BFD_RELOC_PPC64_TOC16_LO_DS:
6126
        case BFD_RELOC_PPC64_PLTGOT16_DS:
6127
        case BFD_RELOC_PPC64_PLTGOT16_LO_DS:
6128
          if (fixP->fx_pcrel)
6129
            abort ();
6130
          {
6131
            char *where = fixP->fx_frag->fr_literal + fixP->fx_where;
6132
            unsigned long val, mask;
6133
 
6134
            if (target_big_endian)
6135
              val = bfd_getb32 (where - 2);
6136
            else
6137
              val = bfd_getl32 (where);
6138
            mask = 0xfffc;
6139
            /* lq insns reserve the four lsbs.  */
6140
            if ((ppc_cpu & PPC_OPCODE_POWER4) != 0
6141
                && (val & (0x3f << 26)) == (56u << 26))
6142
              mask = 0xfff0;
6143
            val |= value & mask;
6144
            if (target_big_endian)
6145
              bfd_putb16 ((bfd_vma) val, where);
6146
            else
6147
              bfd_putl16 ((bfd_vma) val, where);
6148
          }
6149
          break;
6150
 
6151
        case BFD_RELOC_PPC_B16_BRTAKEN:
6152
        case BFD_RELOC_PPC_B16_BRNTAKEN:
6153
        case BFD_RELOC_PPC_BA16_BRTAKEN:
6154
        case BFD_RELOC_PPC_BA16_BRNTAKEN:
6155
          break;
6156
 
6157
        case BFD_RELOC_PPC_TLS:
6158
        case BFD_RELOC_PPC_TLSGD:
6159
        case BFD_RELOC_PPC_TLSLD:
6160
          break;
6161
 
6162
        case BFD_RELOC_PPC_DTPMOD:
6163
        case BFD_RELOC_PPC_TPREL16:
6164
        case BFD_RELOC_PPC_TPREL16_LO:
6165
        case BFD_RELOC_PPC_TPREL16_HI:
6166
        case BFD_RELOC_PPC_TPREL16_HA:
6167
        case BFD_RELOC_PPC_TPREL:
6168
        case BFD_RELOC_PPC_DTPREL16:
6169
        case BFD_RELOC_PPC_DTPREL16_LO:
6170
        case BFD_RELOC_PPC_DTPREL16_HI:
6171
        case BFD_RELOC_PPC_DTPREL16_HA:
6172
        case BFD_RELOC_PPC_DTPREL:
6173
        case BFD_RELOC_PPC_GOT_TLSGD16:
6174
        case BFD_RELOC_PPC_GOT_TLSGD16_LO:
6175
        case BFD_RELOC_PPC_GOT_TLSGD16_HI:
6176
        case BFD_RELOC_PPC_GOT_TLSGD16_HA:
6177
        case BFD_RELOC_PPC_GOT_TLSLD16:
6178
        case BFD_RELOC_PPC_GOT_TLSLD16_LO:
6179
        case BFD_RELOC_PPC_GOT_TLSLD16_HI:
6180
        case BFD_RELOC_PPC_GOT_TLSLD16_HA:
6181
        case BFD_RELOC_PPC_GOT_TPREL16:
6182
        case BFD_RELOC_PPC_GOT_TPREL16_LO:
6183
        case BFD_RELOC_PPC_GOT_TPREL16_HI:
6184
        case BFD_RELOC_PPC_GOT_TPREL16_HA:
6185
        case BFD_RELOC_PPC_GOT_DTPREL16:
6186
        case BFD_RELOC_PPC_GOT_DTPREL16_LO:
6187
        case BFD_RELOC_PPC_GOT_DTPREL16_HI:
6188
        case BFD_RELOC_PPC_GOT_DTPREL16_HA:
6189
        case BFD_RELOC_PPC64_TPREL16_DS:
6190
        case BFD_RELOC_PPC64_TPREL16_LO_DS:
6191
        case BFD_RELOC_PPC64_TPREL16_HIGHER:
6192
        case BFD_RELOC_PPC64_TPREL16_HIGHERA:
6193
        case BFD_RELOC_PPC64_TPREL16_HIGHEST:
6194
        case BFD_RELOC_PPC64_TPREL16_HIGHESTA:
6195
        case BFD_RELOC_PPC64_DTPREL16_DS:
6196
        case BFD_RELOC_PPC64_DTPREL16_LO_DS:
6197
        case BFD_RELOC_PPC64_DTPREL16_HIGHER:
6198
        case BFD_RELOC_PPC64_DTPREL16_HIGHERA:
6199
        case BFD_RELOC_PPC64_DTPREL16_HIGHEST:
6200
        case BFD_RELOC_PPC64_DTPREL16_HIGHESTA:
6201
          S_SET_THREAD_LOCAL (fixP->fx_addsy);
6202
          break;
6203
#endif
6204
          /* Because SDA21 modifies the register field, the size is set to 4
6205
             bytes, rather than 2, so offset it here appropriately.  */
6206
        case BFD_RELOC_PPC_EMB_SDA21:
6207
          if (fixP->fx_pcrel)
6208
            abort ();
6209
 
6210
          md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where
6211
                              + ((target_big_endian) ? 2 : 0),
6212
                              value, 2);
6213
          break;
6214
 
6215
        case BFD_RELOC_8:
6216
          if (fixP->fx_pcrel)
6217
            {
6218
              /* This can occur if there is a bug in the input assembler, eg:
6219
                 ".byte <undefined_symbol> - ."  */
6220
              if (fixP->fx_addsy)
6221
                as_bad (_("Unable to handle reference to symbol %s"),
6222
                        S_GET_NAME (fixP->fx_addsy));
6223
              else
6224
                as_bad (_("Unable to resolve expression"));
6225
              fixP->fx_done = 1;
6226
            }
6227
          else
6228
            md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
6229
                                value, 1);
6230
          break;
6231
 
6232
        case BFD_RELOC_24_PLT_PCREL:
6233
        case BFD_RELOC_PPC_LOCAL24PC:
6234
          if (!fixP->fx_pcrel && !fixP->fx_done)
6235
            abort ();
6236
 
6237
          if (fixP->fx_done)
6238
            {
6239
              char *where;
6240
              unsigned long insn;
6241
 
6242
              /* Fetch the instruction, insert the fully resolved operand
6243
                 value, and stuff the instruction back again.  */
6244
              where = fixP->fx_frag->fr_literal + fixP->fx_where;
6245
              if (target_big_endian)
6246
                insn = bfd_getb32 ((unsigned char *) where);
6247
              else
6248
                insn = bfd_getl32 ((unsigned char *) where);
6249
              if ((value & 3) != 0)
6250
                as_bad_where (fixP->fx_file, fixP->fx_line,
6251
                              _("must branch to an address a multiple of 4"));
6252
              if ((offsetT) value < -0x40000000
6253
                  || (offsetT) value >= 0x40000000)
6254
                as_bad_where (fixP->fx_file, fixP->fx_line,
6255
                              _("@local or @plt branch destination is too far away, %ld bytes"),
6256
                              (long) value);
6257
              insn = insn | (value & 0x03fffffc);
6258
              if (target_big_endian)
6259
                bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
6260
              else
6261
                bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
6262
            }
6263
          break;
6264
 
6265
        case BFD_RELOC_VTABLE_INHERIT:
6266
          fixP->fx_done = 0;
6267
          if (fixP->fx_addsy
6268
              && !S_IS_DEFINED (fixP->fx_addsy)
6269
              && !S_IS_WEAK (fixP->fx_addsy))
6270
            S_SET_WEAK (fixP->fx_addsy);
6271
          break;
6272
 
6273
        case BFD_RELOC_VTABLE_ENTRY:
6274
          fixP->fx_done = 0;
6275
          break;
6276
 
6277
#ifdef OBJ_ELF
6278
          /* Generated by reference to `sym@tocbase'.  The sym is
6279
             ignored by the linker.  */
6280
        case BFD_RELOC_PPC64_TOC:
6281
          fixP->fx_done = 0;
6282
          break;
6283
#endif
6284
        default:
6285
          fprintf (stderr,
6286
                   _("Gas failure, reloc value %d\n"), fixP->fx_r_type);
6287
          fflush (stderr);
6288
          abort ();
6289
        }
6290
    }
6291
 
6292
#ifdef OBJ_ELF
6293
  fixP->fx_addnumber = value;
6294
 
6295
  /* PowerPC uses RELA relocs, ie. the reloc addend is stored separately
6296
     from the section contents.  If we are going to be emitting a reloc
6297
     then the section contents are immaterial, so don't warn if they
6298
     happen to overflow.  Leave such warnings to ld.  */
6299
  if (!fixP->fx_done)
6300
    fixP->fx_no_overflow = 1;
6301
#else
6302
  if (fixP->fx_r_type != BFD_RELOC_PPC_TOC16)
6303
    fixP->fx_addnumber = 0;
6304
  else
6305
    {
6306
#ifdef TE_PE
6307
      fixP->fx_addnumber = 0;
6308
#else
6309
      /* We want to use the offset within the toc, not the actual VMA
6310
         of the symbol.  */
6311
      fixP->fx_addnumber =
6312
        - bfd_get_section_vma (stdoutput, S_GET_SEGMENT (fixP->fx_addsy))
6313
        - S_GET_VALUE (ppc_toc_csect);
6314
#endif
6315
    }
6316
#endif
6317
}
6318
 
6319
/* Generate a reloc for a fixup.  */
6320
 
6321
arelent *
6322
tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp)
6323
{
6324
  arelent *reloc;
6325
 
6326
  reloc = (arelent *) xmalloc (sizeof (arelent));
6327
 
6328
  reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
6329
  *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
6330
  reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
6331
  reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
6332
  if (reloc->howto == (reloc_howto_type *) NULL)
6333
    {
6334
      as_bad_where (fixp->fx_file, fixp->fx_line,
6335
                    _("reloc %d not supported by object file format"),
6336
                    (int) fixp->fx_r_type);
6337
      return NULL;
6338
    }
6339
  reloc->addend = fixp->fx_addnumber;
6340
 
6341
  return reloc;
6342
}
6343
 
6344
void
6345
ppc_cfi_frame_initial_instructions (void)
6346
{
6347
  cfi_add_CFA_def_cfa (1, 0);
6348
}
6349
 
6350
int
6351
tc_ppc_regname_to_dw2regnum (char *regname)
6352
{
6353
  unsigned int regnum = -1;
6354
  unsigned int i;
6355
  const char *p;
6356
  char *q;
6357
  static struct { char *name; int dw2regnum; } regnames[] =
6358
    {
6359
      { "sp", 1 }, { "r.sp", 1 }, { "rtoc", 2 }, { "r.toc", 2 },
6360
      { "mq", 64 }, { "lr", 65 }, { "ctr", 66 }, { "ap", 67 },
6361
      { "cr", 70 }, { "xer", 76 }, { "vrsave", 109 }, { "vscr", 110 },
6362
      { "spe_acc", 111 }, { "spefscr", 112 }
6363
    };
6364
 
6365
  for (i = 0; i < ARRAY_SIZE (regnames); ++i)
6366
    if (strcmp (regnames[i].name, regname) == 0)
6367
      return regnames[i].dw2regnum;
6368
 
6369
  if (regname[0] == 'r' || regname[0] == 'f' || regname[0] == 'v')
6370
    {
6371
      p = regname + 1 + (regname[1] == '.');
6372
      regnum = strtoul (p, &q, 10);
6373
      if (p == q || *q || regnum >= 32)
6374
        return -1;
6375
      if (regname[0] == 'f')
6376
        regnum += 32;
6377
      else if (regname[0] == 'v')
6378
        regnum += 77;
6379
    }
6380
  else if (regname[0] == 'c' && regname[1] == 'r')
6381
    {
6382
      p = regname + 2 + (regname[2] == '.');
6383
      if (p[0] < '0' || p[0] > '7' || p[1])
6384
        return -1;
6385
      regnum = p[0] - '0' + 68;
6386
    }
6387
  return regnum;
6388
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.