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