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