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