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