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