Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* tc-hppa.c -- Assemble for the PA |
49309057 ILT |
2 | Copyright (C) 1989, 93, 94, 95, 96, 97, 98, 1999 |
3 | Free Software Foundation, Inc. | |
252b5132 RH |
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 | |
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. */ | |
21 | ||
22 | ||
23 | /* HP PA-RISC support was contributed by the Center for Software Science | |
24 | at the University of Utah. */ | |
25 | ||
26 | #include <stdio.h> | |
27 | #include <ctype.h> | |
28 | ||
29 | #include "as.h" | |
30 | #include "subsegs.h" | |
31 | ||
32 | #include "bfd/libhppa.h" | |
33 | #include "bfd/libbfd.h" | |
34 | ||
35 | /* Be careful, this file includes data *declarations*. */ | |
36 | #include "opcode/hppa.h" | |
37 | ||
49863f82 JL |
38 | #if defined (OBJ_ELF) && defined (OBJ_SOM) |
39 | error only one of OBJ_ELF and OBJ_SOM can be defined | |
40 | #endif | |
41 | ||
252b5132 RH |
42 | /* A "convient" place to put object file dependencies which do |
43 | not need to be seen outside of tc-hppa.c. */ | |
44 | #ifdef OBJ_ELF | |
252b5132 | 45 | /* Object file formats specify relocation types. */ |
b388df87 | 46 | typedef elf_hppa_reloc_type reloc_type; |
252b5132 RH |
47 | |
48 | /* Object file formats specify BFD symbol types. */ | |
49 | typedef elf_symbol_type obj_symbol_type; | |
50 | ||
b388df87 | 51 | #ifdef BFD64 |
252b5132 | 52 | /* How to generate a relocation. */ |
b388df87 JL |
53 | #define hppa_gen_reloc_type _bfd_elf64_hppa_gen_reloc_type |
54 | #else | |
55 | #define hppa_gen_reloc_type _bfd_elf32_hppa_gen_reloc_type | |
56 | #endif | |
252b5132 RH |
57 | |
58 | /* ELF objects can have versions, but apparently do not have anywhere | |
59 | to store a copyright string. */ | |
60 | #define obj_version obj_elf_version | |
61 | #define obj_copyright obj_elf_version | |
46031ca9 JL |
62 | |
63 | #define UNWIND_SECTION_NAME ".PARISC.unwind" | |
252b5132 RH |
64 | #endif |
65 | ||
66 | #ifdef OBJ_SOM | |
67 | /* Names of various debugging spaces/subspaces. */ | |
68 | #define GDB_DEBUG_SPACE_NAME "$GDB_DEBUG$" | |
69 | #define GDB_STRINGS_SUBSPACE_NAME "$GDB_STRINGS$" | |
70 | #define GDB_SYMBOLS_SUBSPACE_NAME "$GDB_SYMBOLS$" | |
71 | #define UNWIND_SECTION_NAME "$UNWIND$" | |
72 | ||
73 | /* Object file formats specify relocation types. */ | |
74 | typedef int reloc_type; | |
75 | ||
76 | /* SOM objects can have both a version string and a copyright string. */ | |
77 | #define obj_version obj_som_version | |
78 | #define obj_copyright obj_som_copyright | |
79 | ||
252b5132 RH |
80 | /* How to generate a relocation. */ |
81 | #define hppa_gen_reloc_type hppa_som_gen_reloc_type | |
82 | ||
83 | /* Object file formats specify BFD symbol types. */ | |
84 | typedef som_symbol_type obj_symbol_type; | |
85 | ||
86 | /* This apparently isn't in older versions of hpux reloc.h. */ | |
87 | #ifndef R_DLT_REL | |
88 | #define R_DLT_REL 0x78 | |
89 | #endif | |
90 | #endif | |
91 | ||
92 | #ifndef R_N0SEL | |
93 | #define R_N0SEL 0xd8 | |
94 | #endif | |
95 | ||
96 | #ifndef R_N1SEL | |
97 | #define R_N1SEL 0xd9 | |
98 | #endif | |
99 | ||
100 | /* Various structures and types used internally in tc-hppa.c. */ | |
101 | ||
102 | /* Unwind table and descriptor. FIXME: Sync this with GDB version. */ | |
103 | ||
104 | struct unwind_desc | |
105 | { | |
106 | unsigned int cannot_unwind:1; | |
107 | unsigned int millicode:1; | |
108 | unsigned int millicode_save_rest:1; | |
109 | unsigned int region_desc:2; | |
110 | unsigned int save_sr:2; | |
111 | unsigned int entry_fr:4; | |
112 | unsigned int entry_gr:5; | |
113 | unsigned int args_stored:1; | |
114 | unsigned int call_fr:5; | |
115 | unsigned int call_gr:5; | |
116 | unsigned int save_sp:1; | |
117 | unsigned int save_rp:1; | |
118 | unsigned int save_rp_in_frame:1; | |
119 | unsigned int extn_ptr_defined:1; | |
120 | unsigned int cleanup_defined:1; | |
121 | ||
122 | unsigned int hpe_interrupt_marker:1; | |
123 | unsigned int hpux_interrupt_marker:1; | |
124 | unsigned int reserved:3; | |
125 | unsigned int frame_size:27; | |
126 | }; | |
127 | ||
128 | struct unwind_table | |
129 | { | |
130 | /* Starting and ending offsets of the region described by | |
131 | descriptor. */ | |
132 | unsigned int start_offset; | |
133 | unsigned int end_offset; | |
134 | struct unwind_desc descriptor; | |
135 | }; | |
136 | ||
137 | /* This structure is used by the .callinfo, .enter, .leave pseudo-ops to | |
138 | control the entry and exit code they generate. It is also used in | |
139 | creation of the correct stack unwind descriptors. | |
140 | ||
141 | NOTE: GAS does not support .enter and .leave for the generation of | |
142 | prologues and epilogues. FIXME. | |
143 | ||
144 | The fields in structure roughly correspond to the arguments available on the | |
145 | .callinfo pseudo-op. */ | |
146 | ||
147 | struct call_info | |
148 | { | |
149 | /* The unwind descriptor being built. */ | |
150 | struct unwind_table ci_unwind; | |
151 | ||
152 | /* Name of this function. */ | |
153 | symbolS *start_symbol; | |
154 | ||
155 | /* (temporary) symbol used to mark the end of this function. */ | |
156 | symbolS *end_symbol; | |
157 | ||
158 | /* Next entry in the chain. */ | |
159 | struct call_info *ci_next; | |
160 | }; | |
161 | ||
162 | /* Operand formats for FP instructions. Note not all FP instructions | |
163 | allow all four formats to be used (for example fmpysub only allows | |
164 | SGL and DBL). */ | |
165 | typedef enum | |
166 | { | |
167 | SGL, DBL, ILLEGAL_FMT, QUAD, W, UW, DW, UDW, QW, UQW | |
168 | } | |
169 | fp_operand_format; | |
170 | ||
171 | /* This fully describes the symbol types which may be attached to | |
172 | an EXPORT or IMPORT directive. Only SOM uses this formation | |
173 | (ELF has no need for it). */ | |
174 | typedef enum | |
175 | { | |
176 | SYMBOL_TYPE_UNKNOWN, | |
177 | SYMBOL_TYPE_ABSOLUTE, | |
178 | SYMBOL_TYPE_CODE, | |
179 | SYMBOL_TYPE_DATA, | |
180 | SYMBOL_TYPE_ENTRY, | |
181 | SYMBOL_TYPE_MILLICODE, | |
182 | SYMBOL_TYPE_PLABEL, | |
183 | SYMBOL_TYPE_PRI_PROG, | |
184 | SYMBOL_TYPE_SEC_PROG, | |
185 | } | |
186 | pa_symbol_type; | |
187 | ||
188 | /* This structure contains information needed to assemble | |
189 | individual instructions. */ | |
190 | struct pa_it | |
191 | { | |
192 | /* Holds the opcode after parsing by pa_ip. */ | |
193 | unsigned long opcode; | |
194 | ||
195 | /* Holds an expression associated with the current instruction. */ | |
196 | expressionS exp; | |
197 | ||
198 | /* Does this instruction use PC-relative addressing. */ | |
199 | int pcrel; | |
200 | ||
201 | /* Floating point formats for operand1 and operand2. */ | |
202 | fp_operand_format fpof1; | |
203 | fp_operand_format fpof2; | |
204 | ||
205 | ||
206 | /* Holds the field selector for this instruction | |
207 | (for example L%, LR%, etc). */ | |
208 | long field_selector; | |
209 | ||
210 | /* Holds any argument relocation bits associated with this | |
211 | instruction. (instruction should be some sort of call). */ | |
212 | long arg_reloc; | |
213 | ||
214 | /* The format specification for this instruction. */ | |
215 | int format; | |
216 | ||
217 | /* The relocation (if any) associated with this instruction. */ | |
218 | reloc_type reloc; | |
219 | }; | |
220 | ||
221 | /* PA-89 floating point registers are arranged like this: | |
222 | ||
223 | ||
224 | +--------------+--------------+ | |
225 | | 0 or 16L | 16 or 16R | | |
226 | +--------------+--------------+ | |
227 | | 1 or 17L | 17 or 17R | | |
228 | +--------------+--------------+ | |
229 | | | | | |
230 | ||
231 | . . . | |
232 | . . . | |
233 | . . . | |
234 | ||
235 | | | | | |
236 | +--------------+--------------+ | |
237 | | 14 or 30L | 30 or 30R | | |
238 | +--------------+--------------+ | |
239 | | 15 or 31L | 31 or 31R | | |
240 | +--------------+--------------+ | |
241 | ||
242 | ||
243 | The following is a version of pa_parse_number that | |
244 | handles the L/R notation and returns the correct | |
245 | value to put into the instruction register field. | |
246 | The correct value to put into the instruction is | |
247 | encoded in the structure 'pa_11_fp_reg_struct'. */ | |
248 | ||
249 | struct pa_11_fp_reg_struct | |
250 | { | |
251 | /* The register number. */ | |
252 | char number_part; | |
253 | ||
254 | /* L/R selector. */ | |
255 | char l_r_select; | |
256 | }; | |
257 | ||
258 | /* Additional information needed to build argument relocation stubs. */ | |
259 | struct call_desc | |
260 | { | |
261 | /* The argument relocation specification. */ | |
262 | unsigned int arg_reloc; | |
263 | ||
264 | /* Number of arguments. */ | |
265 | unsigned int arg_count; | |
266 | }; | |
267 | ||
49863f82 | 268 | #ifdef OBJ_SOM |
252b5132 RH |
269 | /* This structure defines an entry in the subspace dictionary |
270 | chain. */ | |
271 | ||
272 | struct subspace_dictionary_chain | |
273 | { | |
274 | /* Nonzero if this space has been defined by the user code. */ | |
275 | unsigned int ssd_defined; | |
276 | ||
277 | /* Name of this subspace. */ | |
278 | char *ssd_name; | |
279 | ||
280 | /* GAS segment and subsegment associated with this subspace. */ | |
281 | asection *ssd_seg; | |
282 | int ssd_subseg; | |
283 | ||
284 | /* Next space in the subspace dictionary chain. */ | |
285 | struct subspace_dictionary_chain *ssd_next; | |
286 | }; | |
287 | ||
288 | typedef struct subspace_dictionary_chain ssd_chain_struct; | |
289 | ||
290 | /* This structure defines an entry in the subspace dictionary | |
291 | chain. */ | |
292 | ||
293 | struct space_dictionary_chain | |
294 | { | |
295 | /* Nonzero if this space has been defined by the user code or | |
296 | as a default space. */ | |
297 | unsigned int sd_defined; | |
298 | ||
299 | /* Nonzero if this spaces has been defined by the user code. */ | |
300 | unsigned int sd_user_defined; | |
301 | ||
302 | /* The space number (or index). */ | |
303 | unsigned int sd_spnum; | |
304 | ||
305 | /* The name of this subspace. */ | |
306 | char *sd_name; | |
307 | ||
308 | /* GAS segment to which this subspace corresponds. */ | |
309 | asection *sd_seg; | |
310 | ||
311 | /* Current subsegment number being used. */ | |
312 | int sd_last_subseg; | |
313 | ||
314 | /* The chain of subspaces contained within this space. */ | |
315 | ssd_chain_struct *sd_subspaces; | |
316 | ||
317 | /* The next entry in the space dictionary chain. */ | |
318 | struct space_dictionary_chain *sd_next; | |
319 | }; | |
320 | ||
321 | typedef struct space_dictionary_chain sd_chain_struct; | |
322 | ||
252b5132 RH |
323 | /* This structure defines attributes of the default subspace |
324 | dictionary entries. */ | |
325 | ||
326 | struct default_subspace_dict | |
327 | { | |
328 | /* Name of the subspace. */ | |
329 | char *name; | |
330 | ||
331 | /* FIXME. Is this still needed? */ | |
332 | char defined; | |
333 | ||
334 | /* Nonzero if this subspace is loadable. */ | |
335 | char loadable; | |
336 | ||
337 | /* Nonzero if this subspace contains only code. */ | |
338 | char code_only; | |
339 | ||
340 | /* Nonzero if this is a common subspace. */ | |
341 | char common; | |
342 | ||
343 | /* Nonzero if this is a common subspace which allows symbols | |
344 | to be multiply defined. */ | |
345 | char dup_common; | |
346 | ||
347 | /* Nonzero if this subspace should be zero filled. */ | |
348 | char zero; | |
349 | ||
350 | /* Sort key for this subspace. */ | |
351 | unsigned char sort; | |
352 | ||
353 | /* Access control bits for this subspace. Can represent RWX access | |
354 | as well as privilege level changes for gateways. */ | |
355 | int access; | |
356 | ||
357 | /* Index of containing space. */ | |
358 | int space_index; | |
359 | ||
360 | /* Alignment (in bytes) of this subspace. */ | |
361 | int alignment; | |
362 | ||
363 | /* Quadrant within space where this subspace should be loaded. */ | |
364 | int quadrant; | |
365 | ||
366 | /* An index into the default spaces array. */ | |
367 | int def_space_index; | |
368 | ||
252b5132 RH |
369 | /* Subsegment associated with this subspace. */ |
370 | subsegT subsegment; | |
371 | }; | |
372 | ||
373 | /* This structure defines attributes of the default space | |
374 | dictionary entries. */ | |
375 | ||
376 | struct default_space_dict | |
377 | { | |
378 | /* Name of the space. */ | |
379 | char *name; | |
380 | ||
381 | /* Space number. It is possible to identify spaces within | |
382 | assembly code numerically! */ | |
383 | int spnum; | |
384 | ||
385 | /* Nonzero if this space is loadable. */ | |
386 | char loadable; | |
387 | ||
388 | /* Nonzero if this space is "defined". FIXME is still needed */ | |
389 | char defined; | |
390 | ||
391 | /* Nonzero if this space can not be shared. */ | |
392 | char private; | |
393 | ||
394 | /* Sort key for this space. */ | |
395 | unsigned char sort; | |
396 | ||
397 | /* Segment associated with this space. */ | |
398 | asection *segment; | |
252b5132 | 399 | }; |
49863f82 JL |
400 | #endif |
401 | ||
402 | /* Structure for previous label tracking. Needed so that alignments, | |
403 | callinfo declarations, etc can be easily attached to a particular | |
404 | label. */ | |
405 | typedef struct label_symbol_struct | |
406 | { | |
407 | struct symbol *lss_label; | |
408 | #ifdef OBJ_SOM | |
409 | sd_chain_struct *lss_space; | |
410 | #endif | |
411 | #ifdef OBJ_ELF | |
412 | segT lss_segment; | |
413 | #endif | |
414 | struct label_symbol_struct *lss_next; | |
415 | } | |
416 | label_symbol_struct; | |
252b5132 RH |
417 | |
418 | /* Extra information needed to perform fixups (relocations) on the PA. */ | |
419 | struct hppa_fix_struct | |
420 | { | |
421 | /* The field selector. */ | |
422 | enum hppa_reloc_field_selector_type_alt fx_r_field; | |
423 | ||
424 | /* Type of fixup. */ | |
425 | int fx_r_type; | |
426 | ||
427 | /* Format of fixup. */ | |
428 | int fx_r_format; | |
429 | ||
430 | /* Argument relocation bits. */ | |
431 | long fx_arg_reloc; | |
432 | ||
433 | /* The segment this fixup appears in. */ | |
434 | segT segment; | |
435 | }; | |
436 | ||
437 | /* Structure to hold information about predefined registers. */ | |
438 | ||
439 | struct pd_reg | |
440 | { | |
441 | char *name; | |
442 | int value; | |
443 | }; | |
444 | ||
445 | /* This structure defines the mapping from a FP condition string | |
446 | to a condition number which can be recorded in an instruction. */ | |
447 | struct fp_cond_map | |
448 | { | |
449 | char *string; | |
450 | int cond; | |
451 | }; | |
452 | ||
453 | /* This structure defines a mapping from a field selector | |
454 | string to a field selector type. */ | |
455 | struct selector_entry | |
456 | { | |
457 | char *prefix; | |
458 | int field_selector; | |
459 | }; | |
460 | ||
461 | /* Prototypes for functions local to tc-hppa.c. */ | |
462 | ||
49863f82 | 463 | #ifdef OBJ_SOM |
252b5132 | 464 | static void pa_check_current_space_and_subspace PARAMS ((void)); |
49863f82 JL |
465 | #endif |
466 | ||
252b5132 RH |
467 | static fp_operand_format pa_parse_fp_format PARAMS ((char **s)); |
468 | static void pa_cons PARAMS ((int)); | |
469 | static void pa_data PARAMS ((int)); | |
470 | static void pa_float_cons PARAMS ((int)); | |
471 | static void pa_fill PARAMS ((int)); | |
472 | static void pa_lcomm PARAMS ((int)); | |
473 | static void pa_lsym PARAMS ((int)); | |
474 | static void pa_stringer PARAMS ((int)); | |
475 | static void pa_text PARAMS ((int)); | |
476 | static void pa_version PARAMS ((int)); | |
477 | static int pa_parse_fp_cmp_cond PARAMS ((char **)); | |
478 | static int get_expression PARAMS ((char *)); | |
479 | static int pa_get_absolute_expression PARAMS ((struct pa_it *, char **)); | |
480 | static int evaluate_absolute PARAMS ((struct pa_it *)); | |
481 | static unsigned int pa_build_arg_reloc PARAMS ((char *)); | |
482 | static unsigned int pa_align_arg_reloc PARAMS ((unsigned int, unsigned int)); | |
483 | static int pa_parse_nullif PARAMS ((char **)); | |
484 | static int pa_parse_nonneg_cmpsub_cmpltr PARAMS ((char **, int)); | |
485 | static int pa_parse_neg_cmpsub_cmpltr PARAMS ((char **, int)); | |
486 | static int pa_parse_neg_add_cmpltr PARAMS ((char **, int)); | |
487 | static int pa_parse_nonneg_add_cmpltr PARAMS ((char **, int)); | |
252b5132 RH |
488 | static void pa_block PARAMS ((int)); |
489 | static void pa_brtab PARAMS ((int)); | |
490 | static void pa_try PARAMS ((int)); | |
491 | static void pa_call PARAMS ((int)); | |
492 | static void pa_call_args PARAMS ((struct call_desc *)); | |
493 | static void pa_callinfo PARAMS ((int)); | |
494 | static void pa_code PARAMS ((int)); | |
495 | static void pa_comm PARAMS ((int)); | |
252b5132 RH |
496 | static void pa_copyright PARAMS ((int)); |
497 | static void pa_end PARAMS ((int)); | |
498 | static void pa_enter PARAMS ((int)); | |
499 | static void pa_entry PARAMS ((int)); | |
500 | static void pa_equ PARAMS ((int)); | |
501 | static void pa_exit PARAMS ((int)); | |
502 | static void pa_export PARAMS ((int)); | |
503 | static void pa_type_args PARAMS ((symbolS *, int)); | |
504 | static void pa_import PARAMS ((int)); | |
505 | static void pa_label PARAMS ((int)); | |
506 | static void pa_leave PARAMS ((int)); | |
507 | static void pa_level PARAMS ((int)); | |
508 | static void pa_origin PARAMS ((int)); | |
509 | static void pa_proc PARAMS ((int)); | |
510 | static void pa_procend PARAMS ((int)); | |
252b5132 RH |
511 | static void pa_param PARAMS ((int)); |
512 | static void pa_undefine_label PARAMS ((void)); | |
513 | static int need_pa11_opcode PARAMS ((struct pa_it *, | |
514 | struct pa_11_fp_reg_struct *)); | |
515 | static int pa_parse_number PARAMS ((char **, struct pa_11_fp_reg_struct *)); | |
516 | static label_symbol_struct *pa_get_label PARAMS ((void)); | |
49863f82 JL |
517 | #ifdef OBJ_SOM |
518 | static void pa_compiler PARAMS ((int)); | |
519 | static void pa_align PARAMS ((int)); | |
520 | static void pa_space PARAMS ((int)); | |
521 | static void pa_spnum PARAMS ((int)); | |
522 | static void pa_subspace PARAMS ((int)); | |
252b5132 RH |
523 | static sd_chain_struct *create_new_space PARAMS ((char *, int, int, |
524 | int, int, int, | |
525 | asection *, int)); | |
526 | static ssd_chain_struct *create_new_subspace PARAMS ((sd_chain_struct *, | |
527 | char *, int, int, | |
528 | int, int, int, | |
529 | int, int, int, int, | |
530 | int, asection *)); | |
531 | static ssd_chain_struct *update_subspace PARAMS ((sd_chain_struct *, | |
532 | char *, int, int, int, | |
533 | int, int, int, int, | |
534 | int, int, int, | |
535 | asection *)); | |
536 | static sd_chain_struct *is_defined_space PARAMS ((char *)); | |
537 | static ssd_chain_struct *is_defined_subspace PARAMS ((char *)); | |
538 | static sd_chain_struct *pa_segment_to_space PARAMS ((asection *)); | |
539 | static ssd_chain_struct *pa_subsegment_to_subspace PARAMS ((asection *, | |
540 | subsegT)); | |
541 | static sd_chain_struct *pa_find_space_by_number PARAMS ((int)); | |
542 | static unsigned int pa_subspace_start PARAMS ((sd_chain_struct *, int)); | |
49863f82 JL |
543 | static sd_chain_struct *pa_parse_space_stmt PARAMS ((char *, int)); |
544 | static int pa_next_subseg PARAMS ((sd_chain_struct *)); | |
545 | static void pa_spaces_begin PARAMS ((void)); | |
546 | #endif | |
252b5132 RH |
547 | static void pa_ip PARAMS ((char *)); |
548 | static void fix_new_hppa PARAMS ((fragS *, int, int, symbolS *, | |
549 | long, expressionS *, int, | |
550 | bfd_reloc_code_real_type, | |
551 | enum hppa_reloc_field_selector_type_alt, | |
552 | int, long, int *)); | |
553 | static int is_end_of_statement PARAMS ((void)); | |
554 | static int reg_name_search PARAMS ((char *)); | |
555 | static int pa_chk_field_selector PARAMS ((char **)); | |
556 | static int is_same_frag PARAMS ((fragS *, fragS *)); | |
557 | static void process_exit PARAMS ((void)); | |
252b5132 | 558 | static int log2 PARAMS ((int)); |
252b5132 | 559 | static unsigned int pa_stringer_aux PARAMS ((char *)); |
252b5132 RH |
560 | |
561 | #ifdef OBJ_ELF | |
562 | static void hppa_elf_mark_end_of_function PARAMS ((void)); | |
563 | static void pa_build_unwind_subspace PARAMS ((struct call_info *)); | |
564 | #endif | |
565 | ||
566 | /* File and gloally scoped variable declarations. */ | |
567 | ||
49863f82 | 568 | #ifdef OBJ_SOM |
252b5132 RH |
569 | /* Root and final entry in the space chain. */ |
570 | static sd_chain_struct *space_dict_root; | |
571 | static sd_chain_struct *space_dict_last; | |
572 | ||
573 | /* The current space and subspace. */ | |
574 | static sd_chain_struct *current_space; | |
575 | static ssd_chain_struct *current_subspace; | |
49863f82 | 576 | #endif |
252b5132 RH |
577 | |
578 | /* Root of the call_info chain. */ | |
579 | static struct call_info *call_info_root; | |
580 | ||
581 | /* The last call_info (for functions) structure | |
582 | seen so it can be associated with fixups and | |
583 | function labels. */ | |
584 | static struct call_info *last_call_info; | |
585 | ||
586 | /* The last call description (for actual calls). */ | |
587 | static struct call_desc last_call_desc; | |
588 | ||
589 | /* handle of the OPCODE hash table */ | |
590 | static struct hash_control *op_hash = NULL; | |
591 | ||
592 | /* This array holds the chars that always start a comment. If the | |
593 | pre-processor is disabled, these aren't very useful. */ | |
594 | const char comment_chars[] = ";"; | |
595 | ||
596 | /* Table of pseudo ops for the PA. FIXME -- how many of these | |
597 | are now redundant with the overall GAS and the object file | |
598 | dependent tables? */ | |
599 | const pseudo_typeS md_pseudo_table[] = | |
600 | { | |
601 | /* align pseudo-ops on the PA specify the actual alignment requested, | |
602 | not the log2 of the requested alignment. */ | |
49863f82 | 603 | #ifdef OBJ_SOM |
252b5132 | 604 | {"align", pa_align, 8}, |
49863f82 JL |
605 | #endif |
606 | #ifdef OBJ_ELF | |
607 | {"align", s_align_bytes, 8}, | |
608 | #endif | |
252b5132 RH |
609 | {"begin_brtab", pa_brtab, 1}, |
610 | {"begin_try", pa_try, 1}, | |
611 | {"block", pa_block, 1}, | |
612 | {"blockz", pa_block, 0}, | |
613 | {"byte", pa_cons, 1}, | |
614 | {"call", pa_call, 0}, | |
615 | {"callinfo", pa_callinfo, 0}, | |
616 | {"code", pa_code, 0}, | |
617 | {"comm", pa_comm, 0}, | |
618 | #ifdef OBJ_SOM | |
619 | {"compiler", pa_compiler, 0}, | |
620 | #endif | |
621 | {"copyright", pa_copyright, 0}, | |
622 | {"data", pa_data, 0}, | |
623 | {"double", pa_float_cons, 'd'}, | |
077db52a | 624 | {"dword", pa_cons, 8}, |
252b5132 RH |
625 | {"end", pa_end, 0}, |
626 | {"end_brtab", pa_brtab, 0}, | |
627 | {"end_try", pa_try, 0}, | |
628 | {"enter", pa_enter, 0}, | |
629 | {"entry", pa_entry, 0}, | |
630 | {"equ", pa_equ, 0}, | |
631 | {"exit", pa_exit, 0}, | |
632 | {"export", pa_export, 0}, | |
633 | {"fill", pa_fill, 0}, | |
634 | {"float", pa_float_cons, 'f'}, | |
635 | {"half", pa_cons, 2}, | |
636 | {"import", pa_import, 0}, | |
637 | {"int", pa_cons, 4}, | |
638 | {"label", pa_label, 0}, | |
639 | {"lcomm", pa_lcomm, 0}, | |
640 | {"leave", pa_leave, 0}, | |
641 | {"level", pa_level, 0}, | |
642 | {"long", pa_cons, 4}, | |
643 | {"lsym", pa_lsym, 0}, | |
49863f82 | 644 | #ifdef OBJ_SOM |
252b5132 | 645 | {"nsubspa", pa_subspace, 1}, |
49863f82 | 646 | #endif |
252b5132 RH |
647 | {"octa", pa_cons, 16}, |
648 | {"org", pa_origin, 0}, | |
649 | {"origin", pa_origin, 0}, | |
650 | {"param", pa_param, 0}, | |
651 | {"proc", pa_proc, 0}, | |
652 | {"procend", pa_procend, 0}, | |
653 | {"quad", pa_cons, 8}, | |
654 | {"reg", pa_equ, 1}, | |
655 | {"short", pa_cons, 2}, | |
656 | {"single", pa_float_cons, 'f'}, | |
49863f82 | 657 | #ifdef OBJ_SOM |
252b5132 RH |
658 | {"space", pa_space, 0}, |
659 | {"spnum", pa_spnum, 0}, | |
49863f82 | 660 | #endif |
252b5132 RH |
661 | {"string", pa_stringer, 0}, |
662 | {"stringz", pa_stringer, 1}, | |
49863f82 | 663 | #ifdef OBJ_SOM |
252b5132 | 664 | {"subspa", pa_subspace, 0}, |
49863f82 | 665 | #endif |
252b5132 RH |
666 | {"text", pa_text, 0}, |
667 | {"version", pa_version, 0}, | |
668 | {"word", pa_cons, 4}, | |
669 | {NULL, 0, 0} | |
670 | }; | |
671 | ||
672 | /* This array holds the chars that only start a comment at the beginning of | |
673 | a line. If the line seems to have the form '# 123 filename' | |
674 | .line and .file directives will appear in the pre-processed output. | |
675 | ||
676 | Note that input_file.c hand checks for '#' at the beginning of the | |
677 | first line of the input file. This is because the compiler outputs | |
678 | #NO_APP at the beginning of its output. | |
679 | ||
680 | Also note that C style comments will always work. */ | |
681 | const char line_comment_chars[] = "#"; | |
682 | ||
683 | /* This array holds the characters which act as line separators. */ | |
684 | const char line_separator_chars[] = "!"; | |
685 | ||
686 | /* Chars that can be used to separate mant from exp in floating point nums. */ | |
687 | const char EXP_CHARS[] = "eE"; | |
688 | ||
689 | /* Chars that mean this number is a floating point constant. | |
690 | As in 0f12.456 or 0d1.2345e12. | |
691 | ||
692 | Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be | |
693 | changed in read.c. Ideally it shouldn't hae to know abou it at | |
694 | all, but nothing is ideal around here. */ | |
695 | const char FLT_CHARS[] = "rRsSfFdDxXpP"; | |
696 | ||
697 | static struct pa_it the_insn; | |
698 | ||
699 | /* Points to the end of an expression just parsed by get_expressoin | |
700 | and friends. FIXME. This shouldn't be handled with a file-global | |
701 | variable. */ | |
702 | static char *expr_end; | |
703 | ||
704 | /* Nonzero if a .callinfo appeared within the current procedure. */ | |
705 | static int callinfo_found; | |
706 | ||
707 | /* Nonzero if the assembler is currently within a .entry/.exit pair. */ | |
708 | static int within_entry_exit; | |
709 | ||
710 | /* Nonzero if the assembler is currently within a procedure definition. */ | |
711 | static int within_procedure; | |
712 | ||
713 | /* Handle on strucutre which keep track of the last symbol | |
714 | seen in each subspace. */ | |
715 | static label_symbol_struct *label_symbols_rootp = NULL; | |
716 | ||
717 | /* Holds the last field selector. */ | |
718 | static int hppa_field_selector; | |
719 | ||
993142d5 | 720 | #ifdef OBJ_SOM |
252b5132 RH |
721 | /* A dummy bfd symbol so that all relocations have symbols of some kind. */ |
722 | static symbolS *dummy_symbol; | |
993142d5 | 723 | #endif |
252b5132 RH |
724 | |
725 | /* Nonzero if errors are to be printed. */ | |
726 | static int print_errors = 1; | |
727 | ||
728 | /* List of registers that are pre-defined: | |
729 | ||
730 | Each general register has one predefined name of the form | |
731 | %r<REGNUM> which has the value <REGNUM>. | |
732 | ||
733 | Space and control registers are handled in a similar manner, | |
734 | but use %sr<REGNUM> and %cr<REGNUM> as their predefined names. | |
735 | ||
736 | Likewise for the floating point registers, but of the form | |
737 | %fr<REGNUM>. Floating point registers have additional predefined | |
738 | names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which | |
739 | again have the value <REGNUM>. | |
740 | ||
741 | Many registers also have synonyms: | |
742 | ||
743 | %r26 - %r23 have %arg0 - %arg3 as synonyms | |
744 | %r28 - %r29 have %ret0 - %ret1 as synonyms | |
745 | %r30 has %sp as a synonym | |
746 | %r27 has %dp as a synonym | |
747 | %r2 has %rp as a synonym | |
748 | ||
749 | Almost every control register has a synonym; they are not listed | |
750 | here for brevity. | |
751 | ||
752 | The table is sorted. Suitable for searching by a binary search. */ | |
753 | ||
754 | static const struct pd_reg pre_defined_registers[] = | |
755 | { | |
756 | {"%arg0", 26}, | |
757 | {"%arg1", 25}, | |
758 | {"%arg2", 24}, | |
759 | {"%arg3", 23}, | |
760 | {"%cr0", 0}, | |
761 | {"%cr10", 10}, | |
762 | {"%cr11", 11}, | |
763 | {"%cr12", 12}, | |
764 | {"%cr13", 13}, | |
765 | {"%cr14", 14}, | |
766 | {"%cr15", 15}, | |
767 | {"%cr16", 16}, | |
768 | {"%cr17", 17}, | |
769 | {"%cr18", 18}, | |
770 | {"%cr19", 19}, | |
771 | {"%cr20", 20}, | |
772 | {"%cr21", 21}, | |
773 | {"%cr22", 22}, | |
774 | {"%cr23", 23}, | |
775 | {"%cr24", 24}, | |
776 | {"%cr25", 25}, | |
777 | {"%cr26", 26}, | |
778 | {"%cr27", 27}, | |
779 | {"%cr28", 28}, | |
780 | {"%cr29", 29}, | |
781 | {"%cr30", 30}, | |
782 | {"%cr31", 31}, | |
783 | {"%cr8", 8}, | |
784 | {"%cr9", 9}, | |
785 | {"%dp", 27}, | |
786 | {"%eiem", 15}, | |
787 | {"%eirr", 23}, | |
788 | {"%fr0", 0}, | |
789 | {"%fr0l", 0}, | |
790 | {"%fr0r", 0}, | |
791 | {"%fr1", 1}, | |
792 | {"%fr10", 10}, | |
793 | {"%fr10l", 10}, | |
794 | {"%fr10r", 10}, | |
795 | {"%fr11", 11}, | |
796 | {"%fr11l", 11}, | |
797 | {"%fr11r", 11}, | |
798 | {"%fr12", 12}, | |
799 | {"%fr12l", 12}, | |
800 | {"%fr12r", 12}, | |
801 | {"%fr13", 13}, | |
802 | {"%fr13l", 13}, | |
803 | {"%fr13r", 13}, | |
804 | {"%fr14", 14}, | |
805 | {"%fr14l", 14}, | |
806 | {"%fr14r", 14}, | |
807 | {"%fr15", 15}, | |
808 | {"%fr15l", 15}, | |
809 | {"%fr15r", 15}, | |
810 | {"%fr16", 16}, | |
811 | {"%fr16l", 16}, | |
812 | {"%fr16r", 16}, | |
813 | {"%fr17", 17}, | |
814 | {"%fr17l", 17}, | |
815 | {"%fr17r", 17}, | |
816 | {"%fr18", 18}, | |
817 | {"%fr18l", 18}, | |
818 | {"%fr18r", 18}, | |
819 | {"%fr19", 19}, | |
820 | {"%fr19l", 19}, | |
821 | {"%fr19r", 19}, | |
822 | {"%fr1l", 1}, | |
823 | {"%fr1r", 1}, | |
824 | {"%fr2", 2}, | |
825 | {"%fr20", 20}, | |
826 | {"%fr20l", 20}, | |
827 | {"%fr20r", 20}, | |
828 | {"%fr21", 21}, | |
829 | {"%fr21l", 21}, | |
830 | {"%fr21r", 21}, | |
831 | {"%fr22", 22}, | |
832 | {"%fr22l", 22}, | |
833 | {"%fr22r", 22}, | |
834 | {"%fr23", 23}, | |
835 | {"%fr23l", 23}, | |
836 | {"%fr23r", 23}, | |
837 | {"%fr24", 24}, | |
838 | {"%fr24l", 24}, | |
839 | {"%fr24r", 24}, | |
840 | {"%fr25", 25}, | |
841 | {"%fr25l", 25}, | |
842 | {"%fr25r", 25}, | |
843 | {"%fr26", 26}, | |
844 | {"%fr26l", 26}, | |
845 | {"%fr26r", 26}, | |
846 | {"%fr27", 27}, | |
847 | {"%fr27l", 27}, | |
848 | {"%fr27r", 27}, | |
849 | {"%fr28", 28}, | |
850 | {"%fr28l", 28}, | |
851 | {"%fr28r", 28}, | |
852 | {"%fr29", 29}, | |
853 | {"%fr29l", 29}, | |
854 | {"%fr29r", 29}, | |
855 | {"%fr2l", 2}, | |
856 | {"%fr2r", 2}, | |
857 | {"%fr3", 3}, | |
858 | {"%fr30", 30}, | |
859 | {"%fr30l", 30}, | |
860 | {"%fr30r", 30}, | |
861 | {"%fr31", 31}, | |
862 | {"%fr31l", 31}, | |
863 | {"%fr31r", 31}, | |
864 | {"%fr3l", 3}, | |
865 | {"%fr3r", 3}, | |
866 | {"%fr4", 4}, | |
867 | {"%fr4l", 4}, | |
868 | {"%fr4r", 4}, | |
869 | {"%fr5", 5}, | |
870 | {"%fr5l", 5}, | |
871 | {"%fr5r", 5}, | |
872 | {"%fr6", 6}, | |
873 | {"%fr6l", 6}, | |
874 | {"%fr6r", 6}, | |
875 | {"%fr7", 7}, | |
876 | {"%fr7l", 7}, | |
877 | {"%fr7r", 7}, | |
878 | {"%fr8", 8}, | |
879 | {"%fr8l", 8}, | |
880 | {"%fr8r", 8}, | |
881 | {"%fr9", 9}, | |
882 | {"%fr9l", 9}, | |
883 | {"%fr9r", 9}, | |
884 | {"%hta", 25}, | |
885 | {"%iir", 19}, | |
886 | {"%ior", 21}, | |
887 | {"%ipsw", 22}, | |
888 | {"%isr", 20}, | |
889 | {"%itmr", 16}, | |
890 | {"%iva", 14}, | |
891 | {"%pcoq", 18}, | |
892 | {"%pcsq", 17}, | |
893 | {"%pidr1", 8}, | |
894 | {"%pidr2", 9}, | |
895 | {"%pidr3", 12}, | |
896 | {"%pidr4", 13}, | |
897 | {"%ppda", 24}, | |
898 | {"%r0", 0}, | |
899 | {"%r1", 1}, | |
900 | {"%r10", 10}, | |
901 | {"%r11", 11}, | |
902 | {"%r12", 12}, | |
903 | {"%r13", 13}, | |
904 | {"%r14", 14}, | |
905 | {"%r15", 15}, | |
906 | {"%r16", 16}, | |
907 | {"%r17", 17}, | |
908 | {"%r18", 18}, | |
909 | {"%r19", 19}, | |
910 | {"%r2", 2}, | |
911 | {"%r20", 20}, | |
912 | {"%r21", 21}, | |
913 | {"%r22", 22}, | |
914 | {"%r23", 23}, | |
915 | {"%r24", 24}, | |
916 | {"%r25", 25}, | |
917 | {"%r26", 26}, | |
918 | {"%r27", 27}, | |
919 | {"%r28", 28}, | |
920 | {"%r29", 29}, | |
921 | {"%r3", 3}, | |
922 | {"%r30", 30}, | |
923 | {"%r31", 31}, | |
924 | {"%r4", 4}, | |
925 | {"%r5", 5}, | |
926 | {"%r6", 6}, | |
927 | {"%r7", 7}, | |
928 | {"%r8", 8}, | |
929 | {"%r9", 9}, | |
930 | {"%rctr", 0}, | |
931 | {"%ret0", 28}, | |
932 | {"%ret1", 29}, | |
933 | {"%rp", 2}, | |
934 | {"%sar", 11}, | |
935 | {"%sp", 30}, | |
936 | {"%sr0", 0}, | |
937 | {"%sr1", 1}, | |
938 | {"%sr2", 2}, | |
939 | {"%sr3", 3}, | |
940 | {"%sr4", 4}, | |
941 | {"%sr5", 5}, | |
942 | {"%sr6", 6}, | |
943 | {"%sr7", 7}, | |
944 | {"%tr0", 24}, | |
945 | {"%tr1", 25}, | |
946 | {"%tr2", 26}, | |
947 | {"%tr3", 27}, | |
948 | {"%tr4", 28}, | |
949 | {"%tr5", 29}, | |
950 | {"%tr6", 30}, | |
951 | {"%tr7", 31} | |
952 | }; | |
953 | ||
954 | /* This table is sorted by order of the length of the string. This is | |
955 | so we check for <> before we check for <. If we had a <> and checked | |
956 | for < first, we would get a false match. */ | |
957 | static const struct fp_cond_map fp_cond_map[] = | |
958 | { | |
959 | {"false?", 0}, | |
960 | {"false", 1}, | |
961 | {"true?", 30}, | |
962 | {"true", 31}, | |
963 | {"!<=>", 3}, | |
964 | {"!?>=", 8}, | |
965 | {"!?<=", 16}, | |
966 | {"!<>", 7}, | |
967 | {"!>=", 11}, | |
968 | {"!?>", 12}, | |
969 | {"?<=", 14}, | |
970 | {"!<=", 19}, | |
971 | {"!?<", 20}, | |
972 | {"?>=", 22}, | |
973 | {"!?=", 24}, | |
974 | {"!=t", 27}, | |
975 | {"<=>", 29}, | |
976 | {"=t", 5}, | |
977 | {"?=", 6}, | |
978 | {"?<", 10}, | |
979 | {"<=", 13}, | |
980 | {"!>", 15}, | |
981 | {"?>", 18}, | |
982 | {">=", 21}, | |
983 | {"!<", 23}, | |
984 | {"<>", 25}, | |
985 | {"!=", 26}, | |
986 | {"!?", 28}, | |
987 | {"?", 2}, | |
988 | {"=", 4}, | |
989 | {"<", 9}, | |
990 | {">", 17} | |
991 | }; | |
992 | ||
993 | static const struct selector_entry selector_table[] = | |
994 | { | |
995 | {"f", e_fsel}, | |
996 | {"l", e_lsel}, | |
997 | {"ld", e_ldsel}, | |
998 | {"lp", e_lpsel}, | |
999 | {"lr", e_lrsel}, | |
1000 | {"ls", e_lssel}, | |
1001 | {"lt", e_ltsel}, | |
39ba5561 | 1002 | {"ltp", e_ltpsel}, |
252b5132 RH |
1003 | {"n", e_nsel}, |
1004 | {"nl", e_nlsel}, | |
1005 | {"nlr", e_nlrsel}, | |
1006 | {"p", e_psel}, | |
1007 | {"r", e_rsel}, | |
1008 | {"rd", e_rdsel}, | |
1009 | {"rp", e_rpsel}, | |
1010 | {"rr", e_rrsel}, | |
1011 | {"rs", e_rssel}, | |
1012 | {"rt", e_rtsel}, | |
39ba5561 | 1013 | {"rtp", e_rtpsel}, |
252b5132 RH |
1014 | {"t", e_tsel}, |
1015 | }; | |
1016 | ||
49863f82 | 1017 | #ifdef OBJ_SOM |
252b5132 RH |
1018 | /* default space and subspace dictionaries */ |
1019 | ||
1020 | #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME | |
1021 | #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME | |
1022 | ||
1023 | /* pre-defined subsegments (subspaces) for the HPPA. */ | |
1024 | #define SUBSEG_CODE 0 | |
1025 | #define SUBSEG_LIT 1 | |
1026 | #define SUBSEG_MILLI 2 | |
1027 | #define SUBSEG_DATA 0 | |
1028 | #define SUBSEG_BSS 2 | |
1029 | #define SUBSEG_UNWIND 3 | |
1030 | #define SUBSEG_GDB_STRINGS 0 | |
1031 | #define SUBSEG_GDB_SYMBOLS 1 | |
1032 | ||
1033 | static struct default_subspace_dict pa_def_subspaces[] = | |
1034 | { | |
49863f82 JL |
1035 | {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, SUBSEG_CODE}, |
1036 | {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, SUBSEG_DATA}, | |
1037 | {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, SUBSEG_LIT}, | |
1038 | {"$MILLICODE$", 1, 1, 0, 0, 0, 0, 8, 0x2c, 0, 8, 0, 0, SUBSEG_MILLI}, | |
1039 | {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, SUBSEG_BSS}, | |
252b5132 RH |
1040 | {NULL, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0} |
1041 | }; | |
1042 | ||
1043 | static struct default_space_dict pa_def_spaces[] = | |
1044 | { | |
49863f82 JL |
1045 | {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL}, |
1046 | {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL}, | |
1047 | {NULL, 0, 0, 0, 0, 0, ASEC_NULL} | |
252b5132 RH |
1048 | }; |
1049 | ||
1050 | /* Misc local definitions used by the assembler. */ | |
1051 | ||
252b5132 RH |
1052 | /* These macros are used to maintain spaces/subspaces. */ |
1053 | #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined | |
1054 | #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined | |
1055 | #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum | |
1056 | #define SPACE_NAME(space_chain) (space_chain)->sd_name | |
1057 | ||
1058 | #define SUBSPACE_DEFINED(ss_chain) (ss_chain)->ssd_defined | |
1059 | #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name | |
49863f82 JL |
1060 | #endif |
1061 | ||
1062 | /* Return nonzero if the string pointed to by S potentially represents | |
1063 | a right or left half of a FP register */ | |
1064 | #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r') | |
1065 | #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l') | |
252b5132 RH |
1066 | |
1067 | /* Insert FIELD into OPCODE starting at bit START. Continue pa_ip | |
1068 | main loop after insertion. */ | |
1069 | ||
1070 | #define INSERT_FIELD_AND_CONTINUE(OPCODE, FIELD, START) \ | |
1071 | { \ | |
1072 | ((OPCODE) |= (FIELD) << (START)); \ | |
1073 | continue; \ | |
1074 | } | |
1075 | ||
1076 | /* Simple range checking for FIELD againt HIGH and LOW bounds. | |
1077 | IGNORE is used to suppress the error message. */ | |
1078 | ||
1079 | #define CHECK_FIELD(FIELD, HIGH, LOW, IGNORE) \ | |
1080 | { \ | |
1081 | if ((FIELD) > (HIGH) || (FIELD) < (LOW)) \ | |
1082 | { \ | |
1083 | if (! IGNORE) \ | |
1084 | as_bad (_("Field out of range [%d..%d] (%d)."), (LOW), (HIGH), \ | |
1085 | (int) (FIELD));\ | |
1086 | break; \ | |
1087 | } \ | |
1088 | } | |
1089 | ||
1090 | #define is_DP_relative(exp) \ | |
1091 | ((exp).X_op == O_subtract \ | |
a0f75b47 | 1092 | && strcmp (S_GET_NAME ((exp).X_op_symbol), "$global$") == 0) |
252b5132 RH |
1093 | |
1094 | #define is_PC_relative(exp) \ | |
1095 | ((exp).X_op == O_subtract \ | |
a0f75b47 | 1096 | && strcmp (S_GET_NAME ((exp).X_op_symbol), "$PIC_pcrel$0") == 0) |
252b5132 RH |
1097 | |
1098 | /* We need some complex handling for stabs (sym1 - sym2). Luckily, we'll | |
1099 | always be able to reduce the expression to a constant, so we don't | |
1100 | need real complex handling yet. */ | |
1101 | #define is_complex(exp) \ | |
1102 | ((exp).X_op != O_constant && (exp).X_op != O_symbol) | |
1103 | ||
1104 | /* Actual functions to implement the PA specific code for the assembler. */ | |
1105 | ||
1106 | /* Called before writing the object file. Make sure entry/exit and | |
1107 | proc/procend pairs match. */ | |
1108 | ||
1109 | void | |
1110 | pa_check_eof () | |
1111 | { | |
1112 | if (within_entry_exit) | |
1113 | as_fatal (_("Missing .exit\n")); | |
1114 | ||
1115 | if (within_procedure) | |
1116 | as_fatal (_("Missing .procend\n")); | |
1117 | } | |
1118 | ||
252b5132 RH |
1119 | /* Returns a pointer to the label_symbol_struct for the current space. |
1120 | or NULL if no label_symbol_struct exists for the current space. */ | |
1121 | ||
1122 | static label_symbol_struct * | |
1123 | pa_get_label () | |
1124 | { | |
1125 | label_symbol_struct *label_chain; | |
252b5132 RH |
1126 | |
1127 | for (label_chain = label_symbols_rootp; | |
1128 | label_chain; | |
1129 | label_chain = label_chain->lss_next) | |
49863f82 JL |
1130 | { |
1131 | #ifdef OBJ_SOM | |
1132 | if (current_space == label_chain->lss_space && label_chain->lss_label) | |
1133 | return label_chain; | |
1134 | #endif | |
1135 | #ifdef OBJ_ELF | |
1136 | if (now_seg == label_chain->lss_segment && label_chain->lss_label) | |
252b5132 | 1137 | return label_chain; |
49863f82 JL |
1138 | #endif |
1139 | } | |
252b5132 RH |
1140 | |
1141 | return NULL; | |
1142 | } | |
1143 | ||
1144 | /* Defines a label for the current space. If one is already defined, | |
1145 | this function will replace it with the new label. */ | |
1146 | ||
1147 | void | |
1148 | pa_define_label (symbol) | |
1149 | symbolS *symbol; | |
1150 | { | |
1151 | label_symbol_struct *label_chain = pa_get_label (); | |
252b5132 RH |
1152 | |
1153 | if (label_chain) | |
1154 | label_chain->lss_label = symbol; | |
1155 | else | |
1156 | { | |
1157 | /* Create a new label entry and add it to the head of the chain. */ | |
1158 | label_chain | |
1159 | = (label_symbol_struct *) xmalloc (sizeof (label_symbol_struct)); | |
1160 | label_chain->lss_label = symbol; | |
49863f82 JL |
1161 | #ifdef OBJ_SOM |
1162 | label_chain->lss_space = current_space; | |
1163 | #endif | |
1164 | #ifdef OBJ_ELF | |
1165 | label_chain->lss_segment = now_seg; | |
1166 | #endif | |
252b5132 RH |
1167 | label_chain->lss_next = NULL; |
1168 | ||
1169 | if (label_symbols_rootp) | |
1170 | label_chain->lss_next = label_symbols_rootp; | |
1171 | ||
1172 | label_symbols_rootp = label_chain; | |
1173 | } | |
1174 | } | |
1175 | ||
1176 | /* Removes a label definition for the current space. | |
1177 | If there is no label_symbol_struct entry, then no action is taken. */ | |
1178 | ||
1179 | static void | |
1180 | pa_undefine_label () | |
1181 | { | |
1182 | label_symbol_struct *label_chain; | |
1183 | label_symbol_struct *prev_label_chain = NULL; | |
252b5132 RH |
1184 | |
1185 | for (label_chain = label_symbols_rootp; | |
1186 | label_chain; | |
1187 | label_chain = label_chain->lss_next) | |
1188 | { | |
49863f82 JL |
1189 | if (1 |
1190 | #ifdef OBJ_SOM | |
1191 | && current_space == label_chain->lss_space && label_chain->lss_label | |
1192 | #endif | |
1193 | #ifdef OBJ_ELF | |
1194 | && now_seg == label_chain->lss_segment && label_chain->lss_label | |
1195 | #endif | |
1196 | ) | |
252b5132 RH |
1197 | { |
1198 | /* Remove the label from the chain and free its memory. */ | |
1199 | if (prev_label_chain) | |
1200 | prev_label_chain->lss_next = label_chain->lss_next; | |
1201 | else | |
1202 | label_symbols_rootp = label_chain->lss_next; | |
1203 | ||
1204 | free (label_chain); | |
1205 | break; | |
1206 | } | |
1207 | prev_label_chain = label_chain; | |
1208 | } | |
1209 | } | |
1210 | ||
1211 | ||
1212 | /* An HPPA-specific version of fix_new. This is required because the HPPA | |
1213 | code needs to keep track of some extra stuff. Each call to fix_new_hppa | |
1214 | results in the creation of an instance of an hppa_fix_struct. An | |
1215 | hppa_fix_struct stores the extra information along with a pointer to the | |
1216 | original fixS. This is attached to the original fixup via the | |
1217 | tc_fix_data field. */ | |
1218 | ||
1219 | static void | |
1220 | fix_new_hppa (frag, where, size, add_symbol, offset, exp, pcrel, | |
1221 | r_type, r_field, r_format, arg_reloc, unwind_bits) | |
1222 | fragS *frag; | |
1223 | int where; | |
1224 | int size; | |
1225 | symbolS *add_symbol; | |
1226 | long offset; | |
1227 | expressionS *exp; | |
1228 | int pcrel; | |
1229 | bfd_reloc_code_real_type r_type; | |
1230 | enum hppa_reloc_field_selector_type_alt r_field; | |
1231 | int r_format; | |
1232 | long arg_reloc; | |
1233 | int* unwind_bits; | |
1234 | { | |
1235 | fixS *new_fix; | |
1236 | ||
1237 | struct hppa_fix_struct *hppa_fix = (struct hppa_fix_struct *) | |
1238 | obstack_alloc (¬es, sizeof (struct hppa_fix_struct)); | |
1239 | ||
1240 | if (exp != NULL) | |
1241 | new_fix = fix_new_exp (frag, where, size, exp, pcrel, r_type); | |
1242 | else | |
1243 | new_fix = fix_new (frag, where, size, add_symbol, offset, pcrel, r_type); | |
1244 | new_fix->tc_fix_data = (void *) hppa_fix; | |
1245 | hppa_fix->fx_r_type = r_type; | |
1246 | hppa_fix->fx_r_field = r_field; | |
1247 | hppa_fix->fx_r_format = r_format; | |
1248 | hppa_fix->fx_arg_reloc = arg_reloc; | |
1249 | hppa_fix->segment = now_seg; | |
1250 | #ifdef OBJ_SOM | |
1251 | if (r_type == R_ENTRY || r_type == R_EXIT) | |
1252 | new_fix->fx_offset = *unwind_bits; | |
1253 | #endif | |
1254 | ||
1255 | /* foo-$global$ is used to access non-automatic storage. $global$ | |
1256 | is really just a marker and has served its purpose, so eliminate | |
1257 | it now so as not to confuse write.c. */ | |
1258 | if (new_fix->fx_subsy | |
1259 | && !strcmp (S_GET_NAME (new_fix->fx_subsy), "$global$")) | |
1260 | new_fix->fx_subsy = NULL; | |
1261 | } | |
1262 | ||
1263 | /* Parse a .byte, .word, .long expression for the HPPA. Called by | |
1264 | cons via the TC_PARSE_CONS_EXPRESSION macro. */ | |
1265 | ||
1266 | void | |
1267 | parse_cons_expression_hppa (exp) | |
1268 | expressionS *exp; | |
1269 | { | |
1270 | hppa_field_selector = pa_chk_field_selector (&input_line_pointer); | |
1271 | expression (exp); | |
1272 | } | |
1273 | ||
1274 | /* This fix_new is called by cons via TC_CONS_FIX_NEW. | |
1275 | hppa_field_selector is set by the parse_cons_expression_hppa. */ | |
1276 | ||
1277 | void | |
1278 | cons_fix_new_hppa (frag, where, size, exp) | |
1279 | fragS *frag; | |
1280 | int where; | |
1281 | int size; | |
1282 | expressionS *exp; | |
1283 | { | |
1284 | unsigned int rel_type; | |
1285 | ||
1286 | /* Get a base relocation type. */ | |
1287 | if (is_DP_relative (*exp)) | |
1288 | rel_type = R_HPPA_GOTOFF; | |
1289 | else if (is_complex (*exp)) | |
1290 | rel_type = R_HPPA_COMPLEX; | |
1291 | else | |
1292 | rel_type = R_HPPA; | |
1293 | ||
1294 | if (hppa_field_selector != e_psel && hppa_field_selector != e_fsel) | |
1295 | as_warn (_("Invalid field selector. Assuming F%%.")); | |
1296 | ||
1297 | fix_new_hppa (frag, where, size, | |
1298 | (symbolS *) NULL, (offsetT) 0, exp, 0, rel_type, | |
077db52a | 1299 | hppa_field_selector, size * 8, 0, NULL); |
252b5132 RH |
1300 | |
1301 | /* Reset field selector to its default state. */ | |
1302 | hppa_field_selector = 0; | |
1303 | } | |
1304 | ||
1305 | /* This function is called once, at assembler startup time. It should | |
1306 | set up all the tables, etc. that the MD part of the assembler will need. */ | |
1307 | ||
1308 | void | |
1309 | md_begin () | |
1310 | { | |
1311 | const char *retval = NULL; | |
1312 | int lose = 0; | |
1313 | unsigned int i = 0; | |
1314 | ||
1315 | last_call_info = NULL; | |
1316 | call_info_root = NULL; | |
1317 | ||
1318 | /* Set the default machine type. */ | |
1319 | if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 10)) | |
1320 | as_warn (_("could not set architecture and machine")); | |
1321 | ||
1322 | /* Folding of text and data segments fails miserably on the PA. | |
1323 | Warn user and disable "-R" option. */ | |
1324 | if (flag_readonly_data_in_text) | |
1325 | { | |
1326 | as_warn (_("-R option not supported on this target.")); | |
1327 | flag_readonly_data_in_text = 0; | |
1328 | } | |
1329 | ||
49863f82 | 1330 | #ifdef OBJ_SOM |
252b5132 | 1331 | pa_spaces_begin (); |
49863f82 | 1332 | #endif |
252b5132 RH |
1333 | |
1334 | op_hash = hash_new (); | |
1335 | ||
1336 | while (i < NUMOPCODES) | |
1337 | { | |
1338 | const char *name = pa_opcodes[i].name; | |
1339 | retval = hash_insert (op_hash, name, (struct pa_opcode *) &pa_opcodes[i]); | |
1340 | if (retval != NULL && *retval != '\0') | |
1341 | { | |
1342 | as_fatal (_("Internal error: can't hash `%s': %s\n"), name, retval); | |
1343 | lose = 1; | |
1344 | } | |
1345 | do | |
1346 | { | |
1347 | if ((pa_opcodes[i].match & pa_opcodes[i].mask) | |
1348 | != pa_opcodes[i].match) | |
1349 | { | |
1350 | fprintf (stderr, _("internal error: losing opcode: `%s' \"%s\"\n"), | |
1351 | pa_opcodes[i].name, pa_opcodes[i].args); | |
1352 | lose = 1; | |
1353 | } | |
1354 | ++i; | |
1355 | } | |
1356 | while (i < NUMOPCODES && !strcmp (pa_opcodes[i].name, name)); | |
1357 | } | |
1358 | ||
1359 | if (lose) | |
1360 | as_fatal (_("Broken assembler. No assembly attempted.")); | |
1361 | ||
49863f82 | 1362 | #ifdef OBJ_SOM |
252b5132 RH |
1363 | /* SOM will change text_section. To make sure we never put |
1364 | anything into the old one switch to the new one now. */ | |
1365 | subseg_set (text_section, 0); | |
49863f82 | 1366 | #endif |
252b5132 | 1367 | |
993142d5 | 1368 | #ifdef OBJ_SOM |
252b5132 RH |
1369 | dummy_symbol = symbol_find_or_make ("L$dummy"); |
1370 | S_SET_SEGMENT (dummy_symbol, text_section); | |
993142d5 ILT |
1371 | /* Force the symbol to be converted to a real symbol. */ |
1372 | (void) symbol_get_bfdsym (dummy_symbol); | |
1373 | #endif | |
252b5132 RH |
1374 | } |
1375 | ||
1376 | /* Assemble a single instruction storing it into a frag. */ | |
1377 | void | |
1378 | md_assemble (str) | |
1379 | char *str; | |
1380 | { | |
1381 | char *to; | |
1382 | ||
1383 | /* The had better be something to assemble. */ | |
1384 | assert (str); | |
1385 | ||
1386 | /* If we are within a procedure definition, make sure we've | |
1387 | defined a label for the procedure; handle case where the | |
1388 | label was defined after the .PROC directive. | |
1389 | ||
1390 | Note there's not need to diddle with the segment or fragment | |
1391 | for the label symbol in this case. We have already switched | |
1392 | into the new $CODE$ subspace at this point. */ | |
1393 | if (within_procedure && last_call_info->start_symbol == NULL) | |
1394 | { | |
1395 | label_symbol_struct *label_symbol = pa_get_label (); | |
1396 | ||
1397 | if (label_symbol) | |
1398 | { | |
1399 | if (label_symbol->lss_label) | |
1400 | { | |
1401 | last_call_info->start_symbol = label_symbol->lss_label; | |
a0f75b47 ILT |
1402 | symbol_get_bfdsym (label_symbol->lss_label)->flags |
1403 | |= BSF_FUNCTION; | |
252b5132 RH |
1404 | #ifdef OBJ_SOM |
1405 | /* Also handle allocation of a fixup to hold the unwind | |
1406 | information when the label appears after the proc/procend. */ | |
1407 | if (within_entry_exit) | |
1408 | { | |
1409 | char *where = frag_more (0); | |
1410 | ||
1411 | fix_new_hppa (frag_now, where - frag_now->fr_literal, 0, | |
1412 | NULL, (offsetT) 0, NULL, | |
1413 | 0, R_HPPA_ENTRY, e_fsel, 0, 0, | |
1414 | (int *)&last_call_info->ci_unwind.descriptor); | |
1415 | } | |
1416 | #endif | |
1417 | } | |
1418 | else | |
1419 | as_bad (_("Missing function name for .PROC (corrupted label chain)")); | |
1420 | } | |
1421 | else | |
1422 | as_bad (_("Missing function name for .PROC")); | |
1423 | } | |
1424 | ||
1425 | /* Assemble the instruction. Results are saved into "the_insn". */ | |
1426 | pa_ip (str); | |
1427 | ||
1428 | /* Get somewhere to put the assembled instrution. */ | |
1429 | to = frag_more (4); | |
1430 | ||
1431 | /* Output the opcode. */ | |
1432 | md_number_to_chars (to, the_insn.opcode, 4); | |
1433 | ||
1434 | /* If necessary output more stuff. */ | |
1435 | if (the_insn.reloc != R_HPPA_NONE) | |
1436 | fix_new_hppa (frag_now, (to - frag_now->fr_literal), 4, NULL, | |
1437 | (offsetT) 0, &the_insn.exp, the_insn.pcrel, | |
1438 | the_insn.reloc, the_insn.field_selector, | |
1439 | the_insn.format, the_insn.arg_reloc, NULL); | |
1440 | } | |
1441 | ||
1442 | /* Do the real work for assembling a single instruction. Store results | |
1443 | into the global "the_insn" variable. */ | |
1444 | ||
1445 | static void | |
1446 | pa_ip (str) | |
1447 | char *str; | |
1448 | { | |
1449 | char *error_message = ""; | |
1450 | char *s, c, *argstart, *name, *save_s; | |
1451 | const char *args; | |
1452 | int match = FALSE; | |
1453 | int comma = 0; | |
1454 | int cmpltr, nullif, flag, cond, num; | |
1455 | unsigned long opcode; | |
1456 | struct pa_opcode *insn; | |
1457 | ||
49863f82 | 1458 | #ifdef OBJ_SOM |
252b5132 RH |
1459 | /* We must have a valid space and subspace. */ |
1460 | pa_check_current_space_and_subspace (); | |
49863f82 | 1461 | #endif |
252b5132 | 1462 | |
b1c5e0ee JL |
1463 | /* Convert everything up to the first whitespace character into lower |
1464 | case. */ | |
1465 | for (s = str; *s != ' ' && *s != '\t' && *s != '\n' && *s != '\0'; s++) | |
1466 | if (isupper (*s)) | |
1467 | *s = tolower (*s); | |
1468 | ||
252b5132 RH |
1469 | /* Skip to something interesting. */ |
1470 | for (s = str; isupper (*s) || islower (*s) || (*s >= '0' && *s <= '3'); ++s) | |
1471 | ; | |
1472 | ||
1473 | switch (*s) | |
1474 | { | |
1475 | ||
1476 | case '\0': | |
1477 | break; | |
1478 | ||
1479 | case ',': | |
1480 | comma = 1; | |
1481 | ||
1482 | /*FALLTHROUGH */ | |
1483 | ||
1484 | case ' ': | |
1485 | *s++ = '\0'; | |
1486 | break; | |
1487 | ||
1488 | default: | |
1489 | as_fatal (_("Unknown opcode: `%s'"), str); | |
1490 | } | |
1491 | ||
1492 | save_s = str; | |
1493 | ||
252b5132 RH |
1494 | /* Look up the opcode in the has table. */ |
1495 | if ((insn = (struct pa_opcode *) hash_find (op_hash, str)) == NULL) | |
1496 | { | |
1497 | as_bad ("Unknown opcode: `%s'", str); | |
1498 | return; | |
1499 | } | |
1500 | ||
1501 | if (comma) | |
1502 | { | |
1503 | *--s = ','; | |
1504 | } | |
1505 | ||
1506 | /* Mark the location where arguments for the instruction start, then | |
1507 | start processing them. */ | |
1508 | argstart = s; | |
1509 | for (;;) | |
1510 | { | |
1511 | /* Do some initialization. */ | |
1512 | opcode = insn->match; | |
1513 | memset (&the_insn, 0, sizeof (the_insn)); | |
1514 | ||
1515 | the_insn.reloc = R_HPPA_NONE; | |
1516 | ||
1517 | /* If this instruction is specific to a particular architecture, | |
1518 | then set a new architecture. */ | |
1519 | /* But do not automatically promote to pa2.0. The automatic promotion | |
1520 | crud is for compatability with HP's old assemblers only. */ | |
1521 | if (insn->arch < 20 | |
1522 | && bfd_get_mach (stdoutput) < insn->arch) | |
1523 | { | |
1524 | if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, insn->arch)) | |
1525 | as_warn (_("could not update architecture and machine")); | |
1526 | } | |
1527 | else if (bfd_get_mach (stdoutput) < insn->arch) | |
1528 | { | |
1529 | match = FALSE; | |
1530 | goto failed; | |
1531 | } | |
1532 | ||
1533 | /* Build the opcode, checking as we go to make | |
1534 | sure that the operands match. */ | |
1535 | for (args = insn->args;; ++args) | |
1536 | { | |
1537 | switch (*args) | |
1538 | { | |
1539 | ||
1540 | /* End of arguments. */ | |
1541 | case '\0': | |
1542 | if (*s == '\0') | |
1543 | match = TRUE; | |
1544 | break; | |
1545 | ||
1546 | case '+': | |
1547 | if (*s == '+') | |
1548 | { | |
1549 | ++s; | |
1550 | continue; | |
1551 | } | |
1552 | if (*s == '-') | |
1553 | continue; | |
1554 | break; | |
1555 | ||
1556 | /* These must match exactly. */ | |
1557 | case '(': | |
1558 | case ')': | |
1559 | case ',': | |
1560 | case ' ': | |
1561 | if (*s++ == *args) | |
1562 | continue; | |
1563 | break; | |
1564 | ||
1565 | /* Handle a 5 bit register or control register field at 10. */ | |
1566 | case 'b': | |
1567 | case '^': | |
1568 | num = pa_parse_number (&s, 0); | |
1569 | CHECK_FIELD (num, 31, 0, 0); | |
1570 | INSERT_FIELD_AND_CONTINUE (opcode, num, 21); | |
1571 | ||
a97685e9 JL |
1572 | /* Handle %sar or %cr11. No bits get set, we just verify that it |
1573 | is there. */ | |
1574 | case '!': | |
1575 | /* Skip whitespace before register. */ | |
1576 | while (*s == ' ' || *s == '\t') | |
1577 | s = s + 1; | |
1578 | ||
1579 | if (!strncasecmp(s, "%sar", 4)) | |
1580 | { | |
1581 | s += 4; | |
1582 | continue; | |
1583 | } | |
1584 | else if (!strncasecmp(s, "%cr11", 5)) | |
1585 | { | |
1586 | s += 5; | |
1587 | continue; | |
1588 | } | |
1589 | break; | |
1590 | ||
252b5132 RH |
1591 | /* Handle a 5 bit register field at 15. */ |
1592 | case 'x': | |
1593 | num = pa_parse_number (&s, 0); | |
1594 | CHECK_FIELD (num, 31, 0, 0); | |
1595 | INSERT_FIELD_AND_CONTINUE (opcode, num, 16); | |
1596 | ||
1597 | /* Handle a 5 bit register field at 31. */ | |
1598 | case 'y': | |
1599 | case 't': | |
1600 | num = pa_parse_number (&s, 0); | |
1601 | CHECK_FIELD (num, 31, 0, 0); | |
1602 | INSERT_FIELD_AND_CONTINUE (opcode, num, 0); | |
1603 | ||
413c94ba JL |
1604 | /* Handle a 5 bit register field at 10 and 15. */ |
1605 | case 'a': | |
1606 | num = pa_parse_number (&s, 0); | |
1607 | CHECK_FIELD (num, 31, 0, 0); | |
1608 | opcode |= num << 16; | |
1609 | INSERT_FIELD_AND_CONTINUE (opcode, num, 21); | |
1610 | ||
252b5132 RH |
1611 | /* Handle a 5 bit field length at 31. */ |
1612 | case 'T': | |
1613 | num = pa_get_absolute_expression (&the_insn, &s); | |
1614 | s = expr_end; | |
1615 | CHECK_FIELD (num, 32, 1, 0); | |
1616 | INSERT_FIELD_AND_CONTINUE (opcode, 32 - num, 0); | |
1617 | ||
1618 | /* Handle a 5 bit immediate at 15. */ | |
1619 | case '5': | |
1620 | num = pa_get_absolute_expression (&the_insn, &s); | |
1621 | s = expr_end; | |
1622 | CHECK_FIELD (num, 15, -16, 0); | |
1623 | low_sign_unext (num, 5, &num); | |
1624 | INSERT_FIELD_AND_CONTINUE (opcode, num, 16); | |
1625 | ||
1626 | /* Handle a 5 bit immediate at 31. */ | |
1627 | case 'V': | |
1628 | num = pa_get_absolute_expression (&the_insn, &s); | |
1629 | s = expr_end; | |
1630 | CHECK_FIELD (num, 15, -16, 0) | |
1631 | low_sign_unext (num, 5, &num); | |
1632 | INSERT_FIELD_AND_CONTINUE (opcode, num, 0); | |
1633 | ||
1634 | /* Handle an unsigned 5 bit immediate at 31. */ | |
1635 | case 'r': | |
1636 | num = pa_get_absolute_expression (&the_insn, &s); | |
1637 | s = expr_end; | |
1638 | CHECK_FIELD (num, 31, 0, 0); | |
1639 | INSERT_FIELD_AND_CONTINUE (opcode, num, 0); | |
1640 | ||
1641 | /* Handle an unsigned 5 bit immediate at 15. */ | |
1642 | case 'R': | |
1643 | num = pa_get_absolute_expression (&the_insn, &s); | |
1644 | s = expr_end; | |
1645 | CHECK_FIELD (num, 31, 0, 0); | |
1646 | INSERT_FIELD_AND_CONTINUE (opcode, num, 16); | |
1647 | ||
1648 | /* Handle a 2 bit space identifier at 17. */ | |
1649 | case 's': | |
1650 | num = pa_parse_number (&s, 0); | |
1651 | CHECK_FIELD (num, 3, 0, 1); | |
1652 | INSERT_FIELD_AND_CONTINUE (opcode, num, 14); | |
1653 | ||
1654 | /* Handle a 3 bit space identifier at 18. */ | |
1655 | case 'S': | |
1656 | num = pa_parse_number (&s, 0); | |
1657 | CHECK_FIELD (num, 7, 0, 1); | |
1658 | dis_assemble_3 (num, &num); | |
1659 | INSERT_FIELD_AND_CONTINUE (opcode, num, 13); | |
1660 | ||
28252e61 | 1661 | /* Handle all completers. */ |
252b5132 | 1662 | case 'c': |
28252e61 JL |
1663 | switch (*++args) |
1664 | { | |
1665 | ||
1666 | /* Handle a completer for an indexing load or store. */ | |
1667 | case 'x': | |
252b5132 | 1668 | { |
28252e61 JL |
1669 | int uu = 0; |
1670 | int m = 0; | |
1671 | int i = 0; | |
1672 | while (*s == ',' && i < 2) | |
252b5132 | 1673 | { |
28252e61 JL |
1674 | s++; |
1675 | if (strncasecmp (s, "sm", 2) == 0) | |
1676 | { | |
1677 | uu = 1; | |
1678 | m = 1; | |
1679 | s++; | |
1680 | i++; | |
1681 | } | |
1682 | else if (strncasecmp (s, "m", 1) == 0) | |
1683 | m = 1; | |
1684 | else if (strncasecmp (s, "s", 1) == 0) | |
1685 | uu = 1; | |
1686 | else | |
1687 | as_bad (_("Invalid Indexed Load Completer.")); | |
252b5132 RH |
1688 | s++; |
1689 | i++; | |
1690 | } | |
28252e61 JL |
1691 | if (i > 2) |
1692 | as_bad (_("Invalid Indexed Load Completer Syntax.")); | |
1693 | opcode |= m << 5; | |
1694 | INSERT_FIELD_AND_CONTINUE (opcode, uu, 13); | |
252b5132 | 1695 | } |
252b5132 | 1696 | |
28252e61 JL |
1697 | /* Handle a short load/store completer. */ |
1698 | case 'm': | |
252b5132 | 1699 | { |
28252e61 JL |
1700 | int a = 0; |
1701 | int m = 0; | |
1702 | if (*s == ',') | |
252b5132 | 1703 | { |
28252e61 JL |
1704 | s++; |
1705 | if (strncasecmp (s, "ma", 2) == 0) | |
1706 | { | |
1707 | a = 0; | |
1708 | m = 1; | |
1709 | } | |
1710 | else if (strncasecmp (s, "mb", 2) == 0) | |
1711 | { | |
1712 | a = 1; | |
1713 | m = 1; | |
1714 | } | |
1715 | else | |
1716 | as_bad (_("Invalid Short Load/Store Completer.")); | |
1717 | s += 2; | |
252b5132 | 1718 | } |
252b5132 | 1719 | |
252b5132 RH |
1720 | opcode |= m << 5; |
1721 | INSERT_FIELD_AND_CONTINUE (opcode, a, 13); | |
1722 | } | |
252b5132 | 1723 | |
28252e61 JL |
1724 | /* Handle a stbys completer. */ |
1725 | case 's': | |
252b5132 | 1726 | { |
28252e61 JL |
1727 | int a = 0; |
1728 | int m = 0; | |
1729 | int i = 0; | |
1730 | while (*s == ',' && i < 2) | |
1731 | { | |
1732 | s++; | |
1733 | if (strncasecmp (s, "m", 1) == 0) | |
1734 | m = 1; | |
1735 | else if (strncasecmp (s, "b", 1) == 0) | |
1736 | a = 0; | |
1737 | else if (strncasecmp (s, "e", 1) == 0) | |
1738 | a = 1; | |
1739 | else | |
1740 | as_bad (_("Invalid Store Bytes Short Completer")); | |
1741 | s++; | |
1742 | i++; | |
1743 | } | |
1744 | if (i > 2) | |
252b5132 | 1745 | as_bad (_("Invalid Store Bytes Short Completer")); |
28252e61 JL |
1746 | opcode |= m << 5; |
1747 | INSERT_FIELD_AND_CONTINUE (opcode, a, 13); | |
252b5132 | 1748 | } |
28252e61 JL |
1749 | |
1750 | /* Handle a system control completer. */ | |
1751 | case 'Z': | |
1752 | if (*s == ',' && (*(s + 1) == 'm' || *(s + 1) == 'M')) | |
1753 | { | |
1754 | flag = 1; | |
1755 | s += 2; | |
1756 | } | |
1757 | else | |
1758 | flag = 0; | |
1759 | ||
1760 | INSERT_FIELD_AND_CONTINUE (opcode, flag, 5); | |
1761 | ||
413c94ba JL |
1762 | /* Handle signed/unsigned at 21. */ |
1763 | case 'S': | |
1764 | { | |
1765 | int sign = 1; | |
1766 | if (strncasecmp (s, ",s", 2) == 0) | |
1767 | { | |
1768 | sign = 1; | |
1769 | s += 2; | |
1770 | } | |
1771 | else if (strncasecmp (s, ",u", 2) == 0) | |
1772 | { | |
1773 | sign = 0; | |
1774 | s += 2; | |
1775 | } | |
1776 | ||
1777 | INSERT_FIELD_AND_CONTINUE (opcode, sign, 10); | |
1778 | } | |
1779 | ||
1780 | /* Handle left/right combination at 17:18. */ | |
1781 | case 'h': | |
1782 | if (*s++ == ',') | |
1783 | { | |
1784 | int lr = 0; | |
1785 | if (*s == 'r') | |
1786 | lr = 2; | |
1787 | else if (*s == 'l') | |
1788 | lr = 0; | |
1789 | else | |
1790 | as_bad(_("Invalid left/right combination completer")); | |
1791 | ||
1792 | s++; | |
1793 | INSERT_FIELD_AND_CONTINUE (opcode, lr, 13); | |
1794 | } | |
1795 | else | |
1796 | as_bad(_("Invalid left/right combination completer")); | |
1797 | break; | |
1798 | ||
1799 | /* Handle saturation at 24:25. */ | |
1800 | case 'H': | |
1801 | { | |
1802 | int sat = 3; | |
1803 | if (strncasecmp (s, ",ss", 3) == 0) | |
1804 | { | |
1805 | sat = 1; | |
1806 | s += 3; | |
1807 | } | |
1808 | else if (strncasecmp (s, ",us", 3) == 0) | |
1809 | { | |
1810 | sat = 0; | |
1811 | s += 3; | |
1812 | } | |
1813 | ||
1814 | INSERT_FIELD_AND_CONTINUE (opcode, sat, 6); | |
1815 | } | |
1816 | ||
1817 | /* Handle permutation completer. */ | |
1818 | case '*': | |
1819 | if (*s++ == ',') | |
1820 | { | |
1821 | int permloc[4] = {13,10,8,6}; | |
1822 | int perm = 0; | |
1823 | int i = 0; | |
1824 | for (; i < 4; i++) | |
1825 | { | |
1826 | switch (*s++) | |
1827 | { | |
1828 | case '0': | |
1829 | perm = 0; | |
1830 | break; | |
1831 | case '1': | |
1832 | perm = 1; | |
1833 | break; | |
1834 | case '2': | |
1835 | perm = 2; | |
1836 | break; | |
1837 | case '3': | |
1838 | perm = 3; | |
1839 | break; | |
1840 | default: | |
1841 | as_bad(_("Invalid permutation completer")); | |
1842 | } | |
1843 | opcode |= perm << permloc[i]; | |
1844 | } | |
1845 | continue; | |
1846 | } | |
1847 | else | |
1848 | as_bad(_("Invalid permutation completer")); | |
1849 | break; | |
1850 | ||
28252e61 JL |
1851 | default: |
1852 | abort (); | |
1853 | } | |
1854 | break; | |
252b5132 | 1855 | |
55a914bc | 1856 | /* Handle all conditions. */ |
252b5132 | 1857 | case '?': |
55a914bc JL |
1858 | { |
1859 | args++; | |
1860 | switch (*args) | |
1861 | { | |
1862 | /* Handle FP compare conditions. */ | |
1863 | case 'f': | |
1864 | cond = pa_parse_fp_cmp_cond (&s); | |
1865 | INSERT_FIELD_AND_CONTINUE (opcode, cond, 0); | |
1866 | ||
1867 | /* Handle an add condition. */ | |
9a913dfb | 1868 | case 'A': |
55a914bc JL |
1869 | case 'a': |
1870 | cmpltr = 0; | |
1871 | flag = 0; | |
1872 | if (*s == ',') | |
1873 | { | |
1874 | s++; | |
9a913dfb JL |
1875 | |
1876 | /* 64 bit conditions. */ | |
1877 | if (*args == 'A') | |
1878 | { | |
1879 | if (*s == '*') | |
1880 | s++; | |
1881 | else | |
1882 | break; | |
1883 | } | |
17d9105c JL |
1884 | else if (*s == '*') |
1885 | break; | |
55a914bc | 1886 | name = s; |
9a913dfb | 1887 | |
55a914bc JL |
1888 | while (*s != ',' && *s != ' ' && *s != '\t') |
1889 | s += 1; | |
1890 | c = *s; | |
1891 | *s = 0x00; | |
1892 | if (strcmp (name, "=") == 0) | |
1893 | cmpltr = 1; | |
1894 | else if (strcmp (name, "<") == 0) | |
1895 | cmpltr = 2; | |
1896 | else if (strcmp (name, "<=") == 0) | |
1897 | cmpltr = 3; | |
1898 | else if (strcasecmp (name, "nuv") == 0) | |
1899 | cmpltr = 4; | |
1900 | else if (strcasecmp (name, "znv") == 0) | |
1901 | cmpltr = 5; | |
1902 | else if (strcasecmp (name, "sv") == 0) | |
1903 | cmpltr = 6; | |
1904 | else if (strcasecmp (name, "od") == 0) | |
1905 | cmpltr = 7; | |
1906 | else if (strcasecmp (name, "tr") == 0) | |
1907 | { | |
1908 | cmpltr = 0; | |
1909 | flag = 1; | |
1910 | } | |
1911 | else if (strcmp (name, "<>") == 0) | |
1912 | { | |
1913 | cmpltr = 1; | |
1914 | flag = 1; | |
1915 | } | |
1916 | else if (strcmp (name, ">=") == 0) | |
1917 | { | |
1918 | cmpltr = 2; | |
1919 | flag = 1; | |
1920 | } | |
1921 | else if (strcmp (name, ">") == 0) | |
1922 | { | |
1923 | cmpltr = 3; | |
1924 | flag = 1; | |
1925 | } | |
1926 | else if (strcasecmp (name, "uv") == 0) | |
1927 | { | |
1928 | cmpltr = 4; | |
1929 | flag = 1; | |
1930 | } | |
1931 | else if (strcasecmp (name, "vnz") == 0) | |
1932 | { | |
1933 | cmpltr = 5; | |
1934 | flag = 1; | |
1935 | } | |
1936 | else if (strcasecmp (name, "nsv") == 0) | |
1937 | { | |
1938 | cmpltr = 6; | |
1939 | flag = 1; | |
1940 | } | |
1941 | else if (strcasecmp (name, "ev") == 0) | |
1942 | { | |
1943 | cmpltr = 7; | |
1944 | flag = 1; | |
1945 | } | |
9a913dfb JL |
1946 | /* ",*" is a valid condition. */ |
1947 | else if (*args == 'a') | |
55a914bc JL |
1948 | as_bad (_("Invalid Add Condition: %s"), name); |
1949 | *s = c; | |
1950 | } | |
1951 | opcode |= cmpltr << 13; | |
1952 | INSERT_FIELD_AND_CONTINUE (opcode, flag, 12); | |
252b5132 | 1953 | |
55a914bc JL |
1954 | /* Handle non-negated add and branch condition. */ |
1955 | case 'd': | |
1956 | cmpltr = pa_parse_nonneg_add_cmpltr (&s, 1); | |
1957 | if (cmpltr < 0) | |
1958 | { | |
1959 | as_bad (_("Invalid Compare/Subtract Condition: %c"), *s); | |
1960 | cmpltr = 0; | |
1961 | } | |
1962 | INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13); | |
1963 | ||
9a913dfb JL |
1964 | /* Handle negated add and branch condition. */ |
1965 | case 'D': | |
1966 | abort (); | |
1967 | ||
1968 | /* Handle wide-mode non-negated add and branch condition. */ | |
1969 | case 'w': | |
1970 | abort (); | |
1971 | ||
1972 | /* Handle wide-mode negated add and branch condition. */ | |
1973 | case 'W': | |
1974 | abort(); | |
1975 | ||
55a914bc JL |
1976 | /* Handle a negated or non-negated add and branch |
1977 | condition. */ | |
1978 | case '@': | |
1979 | save_s = s; | |
1980 | cmpltr = pa_parse_nonneg_add_cmpltr (&s, 1); | |
1981 | if (cmpltr < 0) | |
1982 | { | |
1983 | s = save_s; | |
1984 | cmpltr = pa_parse_neg_add_cmpltr (&s, 1); | |
1985 | if (cmpltr < 0) | |
1986 | { | |
1987 | as_bad (_("Invalid Compare/Subtract Condition")); | |
1988 | cmpltr = 0; | |
1989 | } | |
1990 | else | |
1991 | { | |
1992 | /* Negated condition requires an opcode change. */ | |
1993 | opcode |= 1 << 27; | |
1994 | } | |
1995 | } | |
1996 | INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13); | |
252b5132 | 1997 | |
55a914bc | 1998 | /* Handle branch on bit conditions. */ |
9a913dfb | 1999 | case 'B': |
55a914bc JL |
2000 | case 'b': |
2001 | cmpltr = 0; | |
2002 | if (*s == ',') | |
2003 | { | |
2004 | s++; | |
9a913dfb JL |
2005 | |
2006 | if (*args == 'B') | |
2007 | { | |
2008 | if (*s == '*') | |
2009 | s++; | |
2010 | else | |
2011 | break; | |
2012 | } | |
17d9105c JL |
2013 | else if (*s == '*') |
2014 | break; | |
9a913dfb | 2015 | |
55a914bc JL |
2016 | if (strncmp (s, "<", 1) == 0) |
2017 | { | |
2018 | cmpltr = 0; | |
2019 | s++; | |
2020 | } | |
2021 | else if (strncmp (s, ">=", 2) == 0) | |
2022 | { | |
2023 | cmpltr = 1; | |
2024 | s += 2; | |
2025 | } | |
2026 | else | |
2027 | as_bad (_("Invalid Bit Branch Condition: %c"), *s); | |
2028 | } | |
2029 | INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 15); | |
252b5132 | 2030 | |
55a914bc | 2031 | /* Handle a compare/subtract condition. */ |
9a913dfb | 2032 | case 'S': |
55a914bc JL |
2033 | case 's': |
2034 | cmpltr = 0; | |
2035 | flag = 0; | |
2036 | if (*s == ',') | |
2037 | { | |
2038 | s++; | |
9a913dfb JL |
2039 | |
2040 | /* 64 bit conditions. */ | |
2041 | if (*args == 'S') | |
2042 | { | |
2043 | if (*s == '*') | |
2044 | s++; | |
2045 | else | |
2046 | break; | |
2047 | } | |
17d9105c JL |
2048 | else if (*s == '*') |
2049 | break; | |
55a914bc | 2050 | name = s; |
9a913dfb | 2051 | |
55a914bc JL |
2052 | while (*s != ',' && *s != ' ' && *s != '\t') |
2053 | s += 1; | |
2054 | c = *s; | |
2055 | *s = 0x00; | |
2056 | if (strcmp (name, "=") == 0) | |
2057 | cmpltr = 1; | |
2058 | else if (strcmp (name, "<") == 0) | |
2059 | cmpltr = 2; | |
2060 | else if (strcmp (name, "<=") == 0) | |
2061 | cmpltr = 3; | |
2062 | else if (strcasecmp (name, "<<") == 0) | |
2063 | cmpltr = 4; | |
2064 | else if (strcasecmp (name, "<<=") == 0) | |
2065 | cmpltr = 5; | |
2066 | else if (strcasecmp (name, "sv") == 0) | |
2067 | cmpltr = 6; | |
2068 | else if (strcasecmp (name, "od") == 0) | |
2069 | cmpltr = 7; | |
2070 | else if (strcasecmp (name, "tr") == 0) | |
2071 | { | |
2072 | cmpltr = 0; | |
2073 | flag = 1; | |
2074 | } | |
2075 | else if (strcmp (name, "<>") == 0) | |
2076 | { | |
2077 | cmpltr = 1; | |
2078 | flag = 1; | |
2079 | } | |
2080 | else if (strcmp (name, ">=") == 0) | |
2081 | { | |
2082 | cmpltr = 2; | |
2083 | flag = 1; | |
2084 | } | |
2085 | else if (strcmp (name, ">") == 0) | |
2086 | { | |
2087 | cmpltr = 3; | |
2088 | flag = 1; | |
2089 | } | |
2090 | else if (strcasecmp (name, ">>=") == 0) | |
2091 | { | |
2092 | cmpltr = 4; | |
2093 | flag = 1; | |
2094 | } | |
2095 | else if (strcasecmp (name, ">>") == 0) | |
2096 | { | |
2097 | cmpltr = 5; | |
2098 | flag = 1; | |
2099 | } | |
2100 | else if (strcasecmp (name, "nsv") == 0) | |
2101 | { | |
2102 | cmpltr = 6; | |
2103 | flag = 1; | |
2104 | } | |
2105 | else if (strcasecmp (name, "ev") == 0) | |
2106 | { | |
2107 | cmpltr = 7; | |
2108 | flag = 1; | |
2109 | } | |
9a913dfb JL |
2110 | /* ",*" is a valid condition. */ |
2111 | else if (*args != 'S') | |
55a914bc JL |
2112 | as_bad (_("Invalid Compare/Subtract Condition: %s"), |
2113 | name); | |
2114 | *s = c; | |
2115 | } | |
2116 | opcode |= cmpltr << 13; | |
2117 | INSERT_FIELD_AND_CONTINUE (opcode, flag, 12); | |
252b5132 | 2118 | |
55a914bc JL |
2119 | /* Handle a non-negated compare condition. */ |
2120 | case 't': | |
2121 | cmpltr = pa_parse_nonneg_cmpsub_cmpltr (&s, 1); | |
2122 | if (cmpltr < 0) | |
2123 | { | |
2124 | as_bad (_("Invalid Compare/Subtract Condition: %c"), *s); | |
2125 | cmpltr = 0; | |
2126 | } | |
2127 | INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13); | |
9a913dfb JL |
2128 | |
2129 | /* Handle a negated compare condition. */ | |
2130 | case 'T': | |
2131 | abort (); | |
2132 | ||
2133 | /* Handle a 64 bit non-negated compare condition. */ | |
2134 | case 'r': | |
2135 | abort (); | |
2136 | ||
2137 | /* Handle a 64 bit negated compare condition. */ | |
2138 | case 'R': | |
2139 | abort (); | |
2140 | ||
2141 | /* Handle a 64 bit cmpib condition. */ | |
2142 | case 'Q': | |
2143 | abort (); | |
55a914bc JL |
2144 | |
2145 | /* Handle a negated or non-negated compare/subtract | |
2146 | condition. */ | |
2147 | case 'n': | |
2148 | save_s = s; | |
2149 | cmpltr = pa_parse_nonneg_cmpsub_cmpltr (&s, 1); | |
2150 | if (cmpltr < 0) | |
2151 | { | |
2152 | s = save_s; | |
2153 | cmpltr = pa_parse_neg_cmpsub_cmpltr (&s, 1); | |
2154 | if (cmpltr < 0) | |
2155 | { | |
2156 | as_bad (_("Invalid Compare/Subtract Condition.")); | |
2157 | cmpltr = 0; | |
2158 | } | |
2159 | else | |
2160 | { | |
2161 | /* Negated condition requires an opcode change. */ | |
2162 | opcode |= 1 << 27; | |
2163 | } | |
2164 | } | |
2165 | ||
2166 | INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13); | |
2167 | ||
2168 | /* Handle a logical instruction condition. */ | |
9a913dfb | 2169 | case 'L': |
55a914bc JL |
2170 | case 'l': |
2171 | cmpltr = 0; | |
2172 | flag = 0; | |
2173 | if (*s == ',') | |
2174 | { | |
2175 | s++; | |
9a913dfb JL |
2176 | |
2177 | /* 64 bit conditions. */ | |
2178 | if (*args == 'L') | |
2179 | { | |
2180 | if (*s == '*') | |
2181 | s++; | |
2182 | else | |
2183 | break; | |
2184 | } | |
17d9105c JL |
2185 | else if (*s == '*') |
2186 | break; | |
55a914bc | 2187 | name = s; |
9a913dfb | 2188 | |
55a914bc JL |
2189 | while (*s != ',' && *s != ' ' && *s != '\t') |
2190 | s += 1; | |
2191 | c = *s; | |
2192 | *s = 0x00; | |
2193 | ||
2194 | ||
2195 | if (strcmp (name, "=") == 0) | |
2196 | cmpltr = 1; | |
2197 | else if (strcmp (name, "<") == 0) | |
2198 | cmpltr = 2; | |
2199 | else if (strcmp (name, "<=") == 0) | |
2200 | cmpltr = 3; | |
2201 | else if (strcasecmp (name, "od") == 0) | |
2202 | cmpltr = 7; | |
2203 | else if (strcasecmp (name, "tr") == 0) | |
2204 | { | |
2205 | cmpltr = 0; | |
2206 | flag = 1; | |
2207 | } | |
2208 | else if (strcmp (name, "<>") == 0) | |
2209 | { | |
2210 | cmpltr = 1; | |
2211 | flag = 1; | |
2212 | } | |
2213 | else if (strcmp (name, ">=") == 0) | |
2214 | { | |
2215 | cmpltr = 2; | |
2216 | flag = 1; | |
2217 | } | |
2218 | else if (strcmp (name, ">") == 0) | |
2219 | { | |
2220 | cmpltr = 3; | |
2221 | flag = 1; | |
2222 | } | |
2223 | else if (strcasecmp (name, "ev") == 0) | |
2224 | { | |
2225 | cmpltr = 7; | |
2226 | flag = 1; | |
2227 | } | |
9a913dfb JL |
2228 | /* ",*" is a valid condition. */ |
2229 | else if (*args != 'L') | |
55a914bc JL |
2230 | as_bad (_("Invalid Logical Instruction Condition.")); |
2231 | *s = c; | |
2232 | } | |
2233 | opcode |= cmpltr << 13; | |
2234 | INSERT_FIELD_AND_CONTINUE (opcode, flag, 12); | |
2235 | ||
2236 | /* Handle a shift/extract/deposit condition. */ | |
9a913dfb | 2237 | case 'X': |
55a914bc JL |
2238 | case 'x': |
2239 | case 'y': | |
2240 | cmpltr = 0; | |
2241 | if (*s == ',') | |
2242 | { | |
2243 | save_s = s++; | |
2244 | ||
9a913dfb JL |
2245 | /* 64 bit conditions. */ |
2246 | if (*args == 'X') | |
2247 | { | |
2248 | if (*s == '*') | |
2249 | s++; | |
2250 | else | |
2251 | break; | |
2252 | } | |
17d9105c JL |
2253 | else if (*s == '*') |
2254 | break; | |
55a914bc | 2255 | name = s; |
9a913dfb | 2256 | |
55a914bc JL |
2257 | while (*s != ',' && *s != ' ' && *s != '\t') |
2258 | s += 1; | |
2259 | c = *s; | |
2260 | *s = 0x00; | |
2261 | if (strcmp (name, "=") == 0) | |
2262 | cmpltr = 1; | |
2263 | else if (strcmp (name, "<") == 0) | |
2264 | cmpltr = 2; | |
2265 | else if (strcasecmp (name, "od") == 0) | |
2266 | cmpltr = 3; | |
2267 | else if (strcasecmp (name, "tr") == 0) | |
2268 | cmpltr = 4; | |
2269 | else if (strcmp (name, "<>") == 0) | |
2270 | cmpltr = 5; | |
2271 | else if (strcmp (name, ">=") == 0) | |
2272 | cmpltr = 6; | |
2273 | else if (strcasecmp (name, "ev") == 0) | |
2274 | cmpltr = 7; | |
2275 | /* Handle movb,n. Put things back the way they were. | |
2276 | This includes moving s back to where it started. */ | |
2277 | else if (strcasecmp (name, "n") == 0 && *args == 'y') | |
2278 | { | |
2279 | *s = c; | |
2280 | s = save_s; | |
2281 | continue; | |
2282 | } | |
9a913dfb JL |
2283 | /* ",*" is a valid condition. */ |
2284 | else if (*args != 'X') | |
55a914bc JL |
2285 | as_bad (_("Invalid Shift/Extract/Deposit Condition.")); |
2286 | *s = c; | |
2287 | } | |
2288 | INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13); | |
252b5132 | 2289 | |
55a914bc | 2290 | /* Handle a unit instruction condition. */ |
9a913dfb JL |
2291 | case 'U': |
2292 | case 'u': | |
55a914bc JL |
2293 | cmpltr = 0; |
2294 | flag = 0; | |
2295 | if (*s == ',') | |
2296 | { | |
2297 | s++; | |
2298 | ||
9a913dfb JL |
2299 | /* 64 bit conditions. */ |
2300 | if (*args == 'U') | |
2301 | { | |
2302 | if (*s == '*') | |
2303 | s++; | |
2304 | else | |
2305 | break; | |
2306 | } | |
17d9105c JL |
2307 | else if (*s == '*') |
2308 | break; | |
9a913dfb | 2309 | |
55a914bc JL |
2310 | if (strncasecmp (s, "sbz", 3) == 0) |
2311 | { | |
2312 | cmpltr = 2; | |
2313 | s += 3; | |
2314 | } | |
2315 | else if (strncasecmp (s, "shz", 3) == 0) | |
2316 | { | |
2317 | cmpltr = 3; | |
2318 | s += 3; | |
2319 | } | |
2320 | else if (strncasecmp (s, "sdc", 3) == 0) | |
2321 | { | |
2322 | cmpltr = 4; | |
2323 | s += 3; | |
2324 | } | |
2325 | else if (strncasecmp (s, "sbc", 3) == 0) | |
2326 | { | |
2327 | cmpltr = 6; | |
2328 | s += 3; | |
2329 | } | |
2330 | else if (strncasecmp (s, "shc", 3) == 0) | |
2331 | { | |
2332 | cmpltr = 7; | |
2333 | s += 3; | |
2334 | } | |
2335 | else if (strncasecmp (s, "tr", 2) == 0) | |
2336 | { | |
2337 | cmpltr = 0; | |
2338 | flag = 1; | |
2339 | s += 2; | |
2340 | } | |
2341 | else if (strncasecmp (s, "nbz", 3) == 0) | |
2342 | { | |
2343 | cmpltr = 2; | |
2344 | flag = 1; | |
2345 | s += 3; | |
2346 | } | |
2347 | else if (strncasecmp (s, "nhz", 3) == 0) | |
2348 | { | |
2349 | cmpltr = 3; | |
2350 | flag = 1; | |
2351 | s += 3; | |
2352 | } | |
2353 | else if (strncasecmp (s, "ndc", 3) == 0) | |
2354 | { | |
2355 | cmpltr = 4; | |
2356 | flag = 1; | |
2357 | s += 3; | |
2358 | } | |
2359 | else if (strncasecmp (s, "nbc", 3) == 0) | |
2360 | { | |
2361 | cmpltr = 6; | |
2362 | flag = 1; | |
2363 | s += 3; | |
2364 | } | |
2365 | else if (strncasecmp (s, "nhc", 3) == 0) | |
2366 | { | |
2367 | cmpltr = 7; | |
2368 | flag = 1; | |
2369 | s += 3; | |
2370 | } | |
9a913dfb JL |
2371 | /* ",*" is a valid condition. */ |
2372 | else if (*args != 'U') | |
55a914bc JL |
2373 | as_bad (_("Invalid Unit Instruction Condition.")); |
2374 | } | |
2375 | opcode |= cmpltr << 13; | |
2376 | INSERT_FIELD_AND_CONTINUE (opcode, flag, 12); | |
252b5132 | 2377 | |
55a914bc JL |
2378 | default: |
2379 | abort (); | |
2380 | } | |
0741736b | 2381 | break; |
55a914bc | 2382 | } |
252b5132 | 2383 | |
252b5132 RH |
2384 | /* Handle a nullification completer for branch instructions. */ |
2385 | case 'n': | |
2386 | nullif = pa_parse_nullif (&s); | |
2387 | INSERT_FIELD_AND_CONTINUE (opcode, nullif, 1); | |
2388 | ||
2389 | /* Handle a nullification completer for copr and spop insns. */ | |
2390 | case 'N': | |
2391 | nullif = pa_parse_nullif (&s); | |
2392 | INSERT_FIELD_AND_CONTINUE (opcode, nullif, 5); | |
2393 | ||
2394 | ||
2395 | /* Handle a 11 bit immediate at 31. */ | |
2396 | case 'i': | |
2397 | the_insn.field_selector = pa_chk_field_selector (&s); | |
2398 | get_expression (s); | |
2399 | s = expr_end; | |
2400 | if (the_insn.exp.X_op == O_constant) | |
2401 | { | |
2402 | num = evaluate_absolute (&the_insn); | |
2403 | CHECK_FIELD (num, 1023, -1024, 0); | |
2404 | low_sign_unext (num, 11, &num); | |
2405 | INSERT_FIELD_AND_CONTINUE (opcode, num, 0); | |
2406 | } | |
2407 | else | |
2408 | { | |
2409 | if (is_DP_relative (the_insn.exp)) | |
2410 | the_insn.reloc = R_HPPA_GOTOFF; | |
2411 | else if (is_PC_relative (the_insn.exp)) | |
2412 | the_insn.reloc = R_HPPA_PCREL_CALL; | |
2413 | else | |
2414 | the_insn.reloc = R_HPPA; | |
2415 | the_insn.format = 11; | |
2416 | continue; | |
2417 | } | |
2418 | ||
2419 | ||
2420 | /* Handle a 14 bit immediate at 31. */ | |
2421 | case 'j': | |
2422 | the_insn.field_selector = pa_chk_field_selector (&s); | |
2423 | get_expression (s); | |
2424 | s = expr_end; | |
2425 | if (the_insn.exp.X_op == O_constant) | |
2426 | { | |
2427 | num = evaluate_absolute (&the_insn); | |
2428 | CHECK_FIELD (num, 8191, -8192, 0); | |
2429 | low_sign_unext (num, 14, &num); | |
2430 | INSERT_FIELD_AND_CONTINUE (opcode, num, 0); | |
2431 | } | |
2432 | else | |
2433 | { | |
2434 | if (is_DP_relative (the_insn.exp)) | |
2435 | the_insn.reloc = R_HPPA_GOTOFF; | |
2436 | else if (is_PC_relative (the_insn.exp)) | |
2437 | the_insn.reloc = R_HPPA_PCREL_CALL; | |
2438 | else | |
2439 | the_insn.reloc = R_HPPA; | |
2440 | the_insn.format = 14; | |
2441 | continue; | |
2442 | } | |
2443 | ||
2444 | /* Handle a 21 bit immediate at 31. */ | |
2445 | case 'k': | |
2446 | the_insn.field_selector = pa_chk_field_selector (&s); | |
2447 | get_expression (s); | |
2448 | s = expr_end; | |
2449 | if (the_insn.exp.X_op == O_constant) | |
2450 | { | |
2451 | num = evaluate_absolute (&the_insn); | |
2452 | CHECK_FIELD (num >> 11, 1048575, -1048576, 0); | |
2453 | dis_assemble_21 (num, &num); | |
2454 | INSERT_FIELD_AND_CONTINUE (opcode, num, 0); | |
2455 | } | |
2456 | else | |
2457 | { | |
2458 | if (is_DP_relative (the_insn.exp)) | |
2459 | the_insn.reloc = R_HPPA_GOTOFF; | |
2460 | else if (is_PC_relative (the_insn.exp)) | |
2461 | the_insn.reloc = R_HPPA_PCREL_CALL; | |
2462 | else | |
2463 | the_insn.reloc = R_HPPA; | |
2464 | the_insn.format = 21; | |
2465 | continue; | |
2466 | } | |
2467 | ||
2468 | /* Handle a 12 bit branch displacement. */ | |
2469 | case 'w': | |
2470 | the_insn.field_selector = pa_chk_field_selector (&s); | |
2471 | get_expression (s); | |
2472 | s = expr_end; | |
2473 | the_insn.pcrel = 1; | |
2474 | if (!strcmp (S_GET_NAME (the_insn.exp.X_add_symbol), "L$0\001")) | |
2475 | { | |
2476 | unsigned int w1, w, result; | |
2477 | ||
2478 | num = evaluate_absolute (&the_insn); | |
2479 | if (num % 4) | |
2480 | { | |
2481 | as_bad (_("Branch to unaligned address")); | |
2482 | break; | |
2483 | } | |
2484 | CHECK_FIELD (num, 8199, -8184, 0); | |
2485 | sign_unext ((num - 8) >> 2, 12, &result); | |
2486 | dis_assemble_12 (result, &w1, &w); | |
2487 | INSERT_FIELD_AND_CONTINUE (opcode, ((w1 << 2) | w), 0); | |
2488 | } | |
2489 | else | |
2490 | { | |
2491 | the_insn.reloc = R_HPPA_PCREL_CALL; | |
2492 | the_insn.format = 12; | |
2493 | the_insn.arg_reloc = last_call_desc.arg_reloc; | |
2494 | memset (&last_call_desc, 0, sizeof (struct call_desc)); | |
2495 | s = expr_end; | |
2496 | continue; | |
2497 | } | |
2498 | ||
2499 | /* Handle a 17 bit branch displacement. */ | |
2500 | case 'W': | |
2501 | the_insn.field_selector = pa_chk_field_selector (&s); | |
2502 | get_expression (s); | |
2503 | s = expr_end; | |
2504 | the_insn.pcrel = 1; | |
2505 | if (!the_insn.exp.X_add_symbol | |
2506 | || !strcmp (S_GET_NAME (the_insn.exp.X_add_symbol), | |
2507 | "L$0\001")) | |
2508 | { | |
2509 | unsigned int w2, w1, w, result; | |
2510 | ||
2511 | num = evaluate_absolute (&the_insn); | |
2512 | if (num % 4) | |
2513 | { | |
2514 | as_bad (_("Branch to unaligned address")); | |
2515 | break; | |
2516 | } | |
2517 | CHECK_FIELD (num, 262143, -262144, 0); | |
2518 | ||
2519 | if (the_insn.exp.X_add_symbol) | |
2520 | num -= 8; | |
2521 | ||
2522 | sign_unext (num >> 2, 17, &result); | |
2523 | dis_assemble_17 (result, &w1, &w2, &w); | |
2524 | INSERT_FIELD_AND_CONTINUE (opcode, | |
2525 | ((w2 << 2) | (w1 << 16) | w), 0); | |
2526 | } | |
2527 | else | |
2528 | { | |
2529 | the_insn.reloc = R_HPPA_PCREL_CALL; | |
2530 | the_insn.format = 17; | |
2531 | the_insn.arg_reloc = last_call_desc.arg_reloc; | |
2532 | memset (&last_call_desc, 0, sizeof (struct call_desc)); | |
2533 | continue; | |
2534 | } | |
2535 | ||
2536 | /* Handle an absolute 17 bit branch target. */ | |
2537 | case 'z': | |
2538 | the_insn.field_selector = pa_chk_field_selector (&s); | |
2539 | get_expression (s); | |
2540 | s = expr_end; | |
2541 | the_insn.pcrel = 0; | |
2542 | if (!the_insn.exp.X_add_symbol | |
2543 | || !strcmp (S_GET_NAME (the_insn.exp.X_add_symbol), | |
2544 | "L$0\001")) | |
2545 | { | |
2546 | unsigned int w2, w1, w, result; | |
2547 | ||
2548 | num = evaluate_absolute (&the_insn); | |
2549 | if (num % 4) | |
2550 | { | |
2551 | as_bad (_("Branch to unaligned address")); | |
2552 | break; | |
2553 | } | |
2554 | CHECK_FIELD (num, 262143, -262144, 0); | |
2555 | ||
2556 | if (the_insn.exp.X_add_symbol) | |
2557 | num -= 8; | |
2558 | ||
2559 | sign_unext (num >> 2, 17, &result); | |
2560 | dis_assemble_17 (result, &w1, &w2, &w); | |
2561 | INSERT_FIELD_AND_CONTINUE (opcode, | |
2562 | ((w2 << 2) | (w1 << 16) | w), 0); | |
2563 | } | |
2564 | else | |
2565 | { | |
2566 | the_insn.reloc = R_HPPA_ABS_CALL; | |
2567 | the_insn.format = 17; | |
2568 | the_insn.arg_reloc = last_call_desc.arg_reloc; | |
2569 | memset (&last_call_desc, 0, sizeof (struct call_desc)); | |
2570 | continue; | |
2571 | } | |
2572 | ||
a97685e9 JL |
2573 | /* Handle a 2 bit shift count at 25. */ |
2574 | case '.': | |
2575 | num = pa_get_absolute_expression (&the_insn, &s); | |
2576 | s = expr_end; | |
2577 | CHECK_FIELD (num, 3, 1, 0); | |
2578 | INSERT_FIELD_AND_CONTINUE (opcode, num, 6); | |
2579 | ||
413c94ba JL |
2580 | /* Handle a 4 bit shift count at 25. */ |
2581 | case '*': | |
2582 | num = pa_get_absolute_expression (&the_insn, &s); | |
2583 | s = expr_end; | |
2584 | CHECK_FIELD (num, 15, 0, 0); | |
2585 | INSERT_FIELD_AND_CONTINUE (opcode, num, 6); | |
2586 | ||
252b5132 RH |
2587 | /* Handle a 5 bit shift count at 26. */ |
2588 | case 'p': | |
2589 | num = pa_get_absolute_expression (&the_insn, &s); | |
2590 | s = expr_end; | |
2591 | CHECK_FIELD (num, 31, 0, 0); | |
2592 | INSERT_FIELD_AND_CONTINUE (opcode, 31 - num, 5); | |
2593 | ||
a97685e9 JL |
2594 | /* Handle a 6 bit shift count at 20,22:26. */ |
2595 | case '~': | |
2596 | num = pa_get_absolute_expression (&the_insn, &s); | |
2597 | s = expr_end; | |
2598 | CHECK_FIELD (num, 63, 0, 0); | |
2599 | num = 63 - num; | |
2600 | opcode |= (num & 0x20) << 6; | |
2601 | INSERT_FIELD_AND_CONTINUE (opcode, num & 0x1f, 5); | |
2602 | ||
252b5132 RH |
2603 | /* Handle a 5 bit bit position at 26. */ |
2604 | case 'P': | |
2605 | num = pa_get_absolute_expression (&the_insn, &s); | |
2606 | s = expr_end; | |
2607 | CHECK_FIELD (num, 31, 0, 0); | |
2608 | INSERT_FIELD_AND_CONTINUE (opcode, num, 5); | |
2609 | ||
2610 | /* Handle a 5 bit immediate at 10. */ | |
2611 | case 'Q': | |
2612 | ||
2613 | num = pa_get_absolute_expression (&the_insn, &s); | |
2614 | if (the_insn.exp.X_op != O_constant) | |
2615 | break; | |
2616 | s = expr_end; | |
2617 | CHECK_FIELD (num, 31, 0, 0); | |
2618 | INSERT_FIELD_AND_CONTINUE (opcode, num, 21); | |
2619 | ||
a97685e9 JL |
2620 | /* Handle a 9 bit immediate at 28. */ |
2621 | case '$': | |
2622 | num = pa_get_absolute_expression (&the_insn, &s); | |
2623 | s = expr_end; | |
2624 | CHECK_FIELD (num, 511, 1, 0); | |
2625 | INSERT_FIELD_AND_CONTINUE (opcode, num, 3); | |
2626 | ||
252b5132 RH |
2627 | /* Handle a 13 bit immediate at 18. */ |
2628 | case 'A': | |
2629 | num = pa_get_absolute_expression (&the_insn, &s); | |
2630 | s = expr_end; | |
2631 | CHECK_FIELD (num, 8191, 0, 0); | |
2632 | INSERT_FIELD_AND_CONTINUE (opcode, num, 13); | |
2633 | ||
2634 | /* Handle a 26 bit immediate at 31. */ | |
2635 | case 'D': | |
2636 | num = pa_get_absolute_expression (&the_insn, &s); | |
2637 | s = expr_end; | |
2638 | CHECK_FIELD (num, 671108864, 0, 0); | |
2639 | INSERT_FIELD_AND_CONTINUE (opcode, num, 0); | |
2640 | ||
2641 | /* Handle a 3 bit SFU identifier at 25. */ | |
2642 | case 'f': | |
2643 | if (*s++ != ',') | |
2644 | as_bad (_("Invalid SFU identifier")); | |
2645 | num = pa_get_absolute_expression (&the_insn, &s); | |
2646 | s = expr_end; | |
2647 | CHECK_FIELD (num, 7, 0, 0); | |
2648 | INSERT_FIELD_AND_CONTINUE (opcode, num, 6); | |
2649 | ||
2650 | /* Handle a 20 bit SOP field for spop0. */ | |
2651 | case 'O': | |
2652 | num = pa_get_absolute_expression (&the_insn, &s); | |
2653 | s = expr_end; | |
2654 | CHECK_FIELD (num, 1048575, 0, 0); | |
2655 | num = (num & 0x1f) | ((num & 0x000fffe0) << 6); | |
2656 | INSERT_FIELD_AND_CONTINUE (opcode, num, 0); | |
2657 | ||
2658 | /* Handle a 15bit SOP field for spop1. */ | |
2659 | case 'o': | |
2660 | num = pa_get_absolute_expression (&the_insn, &s); | |
2661 | s = expr_end; | |
2662 | CHECK_FIELD (num, 32767, 0, 0); | |
2663 | INSERT_FIELD_AND_CONTINUE (opcode, num, 11); | |
2664 | ||
2665 | /* Handle a 10bit SOP field for spop3. */ | |
2666 | case '0': | |
2667 | num = pa_get_absolute_expression (&the_insn, &s); | |
2668 | s = expr_end; | |
2669 | CHECK_FIELD (num, 1023, 0, 0); | |
2670 | num = (num & 0x1f) | ((num & 0x000003e0) << 6); | |
2671 | INSERT_FIELD_AND_CONTINUE (opcode, num, 0); | |
2672 | ||
2673 | /* Handle a 15 bit SOP field for spop2. */ | |
2674 | case '1': | |
2675 | num = pa_get_absolute_expression (&the_insn, &s); | |
2676 | s = expr_end; | |
2677 | CHECK_FIELD (num, 32767, 0, 0); | |
2678 | num = (num & 0x1f) | ((num & 0x00007fe0) << 6); | |
2679 | INSERT_FIELD_AND_CONTINUE (opcode, num, 0); | |
2680 | ||
2681 | /* Handle a 3-bit co-processor ID field. */ | |
2682 | case 'u': | |
2683 | if (*s++ != ',') | |
2684 | as_bad (_("Invalid COPR identifier")); | |
2685 | num = pa_get_absolute_expression (&the_insn, &s); | |
2686 | s = expr_end; | |
2687 | CHECK_FIELD (num, 7, 0, 0); | |
2688 | INSERT_FIELD_AND_CONTINUE (opcode, num, 6); | |
2689 | ||
2690 | /* Handle a 22bit SOP field for copr. */ | |
2691 | case '2': | |
2692 | num = pa_get_absolute_expression (&the_insn, &s); | |
2693 | s = expr_end; | |
2694 | CHECK_FIELD (num, 4194303, 0, 0); | |
2695 | num = (num & 0x1f) | ((num & 0x003fffe0) << 4); | |
2696 | INSERT_FIELD_AND_CONTINUE (opcode, num, 0); | |
2697 | ||
2698 | ||
2699 | /* Handle a source FP operand format completer. */ | |
2700 | case 'F': | |
2701 | flag = pa_parse_fp_format (&s); | |
2702 | the_insn.fpof1 = flag; | |
2703 | INSERT_FIELD_AND_CONTINUE (opcode, flag, 11); | |
2704 | ||
2705 | /* Handle a destination FP operand format completer. */ | |
2706 | case 'G': | |
2707 | /* pa_parse_format needs the ',' prefix. */ | |
2708 | s--; | |
2709 | flag = pa_parse_fp_format (&s); | |
2710 | the_insn.fpof2 = flag; | |
2711 | INSERT_FIELD_AND_CONTINUE (opcode, flag, 13); | |
2712 | ||
9ecc05f0 JL |
2713 | /* Handle a source FP operand format completer at 20. */ |
2714 | case 'I': | |
2715 | flag = pa_parse_fp_format (&s); | |
2716 | the_insn.fpof1 = flag; | |
2717 | INSERT_FIELD_AND_CONTINUE (opcode, flag, 11); | |
2718 | ||
252b5132 RH |
2719 | /* Handle L/R register halves like 't'. */ |
2720 | case 'v': | |
2721 | { | |
2722 | struct pa_11_fp_reg_struct result; | |
2723 | ||
2724 | pa_parse_number (&s, &result); | |
2725 | CHECK_FIELD (result.number_part, 31, 0, 0); | |
2726 | opcode |= result.number_part; | |
2727 | ||
2728 | /* 0x30 opcodes are FP arithmetic operation opcodes | |
2729 | and need to be turned into 0x38 opcodes. This | |
2730 | is not necessary for loads/stores. */ | |
2731 | if (need_pa11_opcode (&the_insn, &result) | |
2732 | && ((opcode & 0xfc000000) == 0x30000000)) | |
2733 | opcode |= 1 << 27; | |
2734 | ||
2735 | INSERT_FIELD_AND_CONTINUE (opcode, result.l_r_select & 1, 6); | |
2736 | } | |
2737 | ||
2738 | /* Handle L/R register halves like 'b'. */ | |
2739 | case 'E': | |
2740 | { | |
2741 | struct pa_11_fp_reg_struct result; | |
2742 | ||
2743 | pa_parse_number (&s, &result); | |
2744 | CHECK_FIELD (result.number_part, 31, 0, 0); | |
2745 | opcode |= result.number_part << 21; | |
2746 | if (need_pa11_opcode (&the_insn, &result)) | |
2747 | { | |
2748 | opcode |= (result.l_r_select & 1) << 7; | |
2749 | opcode |= 1 << 27; | |
2750 | } | |
2751 | continue; | |
2752 | } | |
2753 | ||
b53fcc20 JL |
2754 | /* Float operand 1 similar to 'b' but with l/r registers. */ |
2755 | case 'J': | |
2756 | { | |
2757 | struct pa_11_fp_reg_struct result; | |
2758 | ||
2759 | pa_parse_number (&s, &result); | |
2760 | CHECK_FIELD (result.number_part, 31, 0, 0); | |
2761 | opcode |= result.number_part << 21; | |
2762 | opcode |= (result.l_r_select & 1) << 7; | |
2763 | continue; | |
2764 | } | |
2765 | ||
252b5132 RH |
2766 | /* Handle L/R register halves like 'b'. */ |
2767 | case '3': | |
2768 | { | |
2769 | struct pa_11_fp_reg_struct result; | |
2770 | int regnum; | |
2771 | ||
2772 | pa_parse_number (&s, &result); | |
2773 | CHECK_FIELD (result.number_part, 31, 0, 0); | |
2774 | opcode |= (result.number_part & 0x1c) << 11; | |
2775 | opcode |= (result.number_part & 0x3) << 9; | |
2776 | opcode |= (result.l_r_select & 1) << 8; | |
2777 | continue; | |
2778 | } | |
2779 | ||
2780 | /* Handle L/R register halves like 'x'. */ | |
2781 | case 'e': | |
2782 | { | |
2783 | struct pa_11_fp_reg_struct result; | |
2784 | ||
2785 | pa_parse_number (&s, &result); | |
2786 | CHECK_FIELD (result.number_part, 31, 0, 0); | |
2787 | opcode |= (result.number_part & 0x1f) << 16; | |
2788 | if (need_pa11_opcode (&the_insn, &result)) | |
2789 | { | |
2790 | opcode |= (result.l_r_select & 1) << 1; | |
2791 | } | |
2792 | continue; | |
2793 | } | |
2794 | ||
2795 | /* Handle L/R register halves like 'x'. */ | |
2796 | case 'X': | |
2797 | { | |
2798 | struct pa_11_fp_reg_struct result; | |
2799 | ||
2800 | pa_parse_number (&s, &result); | |
2801 | CHECK_FIELD (result.number_part, 31, 0, 0); | |
2802 | opcode |= (result.number_part & 0x1f) << 16; | |
2803 | if (need_pa11_opcode (&the_insn, &result)) | |
2804 | { | |
2805 | opcode |= (result.l_r_select & 1) << 12; | |
2806 | opcode |= 1 << 27; | |
2807 | } | |
2808 | continue; | |
2809 | } | |
2810 | ||
b53fcc20 JL |
2811 | /* Float operand 2, like 'x' but with l/r register halves. */ |
2812 | case 'K': | |
2813 | { | |
2814 | struct pa_11_fp_reg_struct result; | |
2815 | ||
2816 | pa_parse_number (&s, &result); | |
2817 | CHECK_FIELD (result.number_part, 31, 0, 0); | |
2818 | opcode |= (result.number_part & 0x1f) << 16; | |
2819 | opcode |= (result.l_r_select & 1) << 12; | |
2820 | continue; | |
2821 | } | |
2822 | ||
252b5132 RH |
2823 | /* Handle a 5 bit register field at 10. */ |
2824 | case '4': | |
2825 | { | |
2826 | struct pa_11_fp_reg_struct result; | |
2827 | ||
2828 | pa_parse_number (&s, &result); | |
2829 | CHECK_FIELD (result.number_part, 31, 0, 0); | |
2830 | if (the_insn.fpof1 == SGL) | |
2831 | { | |
2832 | if (result.number_part < 16) | |
2833 | { | |
2834 | as_bad (_("Invalid register for single precision fmpyadd or fmpysub")); | |
2835 | break; | |
2836 | } | |
2837 | ||
2838 | result.number_part &= 0xF; | |
2839 | result.number_part |= (result.l_r_select & 1) << 4; | |
2840 | } | |
2841 | INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 21); | |
2842 | } | |
2843 | ||
2844 | /* Handle a 5 bit register field at 15. */ | |
2845 | case '6': | |
2846 | { | |
2847 | struct pa_11_fp_reg_struct result; | |
2848 | ||
2849 | pa_parse_number (&s, &result); | |
2850 | CHECK_FIELD (result.number_part, 31, 0, 0); | |
2851 | if (the_insn.fpof1 == SGL) | |
2852 | { | |
2853 | if (result.number_part < 16) | |
2854 | { | |
2855 | as_bad (_("Invalid register for single precision fmpyadd or fmpysub")); | |
2856 | break; | |
2857 | } | |
2858 | result.number_part &= 0xF; | |
2859 | result.number_part |= (result.l_r_select & 1) << 4; | |
2860 | } | |
2861 | INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 16); | |
2862 | } | |
2863 | ||
2864 | /* Handle a 5 bit register field at 31. */ | |
2865 | case '7': | |
2866 | { | |
2867 | struct pa_11_fp_reg_struct result; | |
2868 | ||
2869 | pa_parse_number (&s, &result); | |
2870 | CHECK_FIELD (result.number_part, 31, 0, 0); | |
2871 | if (the_insn.fpof1 == SGL) | |
2872 | { | |
2873 | if (result.number_part < 16) | |
2874 | { | |
2875 | as_bad (_("Invalid register for single precision fmpyadd or fmpysub")); | |
2876 | break; | |
2877 | } | |
2878 | result.number_part &= 0xF; | |
2879 | result.number_part |= (result.l_r_select & 1) << 4; | |
2880 | } | |
2881 | INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 0); | |
2882 | } | |
2883 | ||
2884 | /* Handle a 5 bit register field at 20. */ | |
2885 | case '8': | |
2886 | { | |
2887 | struct pa_11_fp_reg_struct result; | |
2888 | ||
2889 | pa_parse_number (&s, &result); | |
2890 | CHECK_FIELD (result.number_part, 31, 0, 0); | |
2891 | if (the_insn.fpof1 == SGL) | |
2892 | { | |
2893 | if (result.number_part < 16) | |
2894 | { | |
2895 | as_bad (_("Invalid register for single precision fmpyadd or fmpysub")); | |
2896 | break; | |
2897 | } | |
2898 | result.number_part &= 0xF; | |
2899 | result.number_part |= (result.l_r_select & 1) << 4; | |
2900 | } | |
2901 | INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 11); | |
2902 | } | |
2903 | ||
2904 | /* Handle a 5 bit register field at 25. */ | |
2905 | case '9': | |
2906 | { | |
2907 | struct pa_11_fp_reg_struct result; | |
2908 | ||
2909 | pa_parse_number (&s, &result); | |
2910 | CHECK_FIELD (result.number_part, 31, 0, 0); | |
2911 | if (the_insn.fpof1 == SGL) | |
2912 | { | |
2913 | if (result.number_part < 16) | |
2914 | { | |
2915 | as_bad (_("Invalid register for single precision fmpyadd or fmpysub")); | |
2916 | break; | |
2917 | } | |
2918 | result.number_part &= 0xF; | |
2919 | result.number_part |= (result.l_r_select & 1) << 4; | |
2920 | } | |
2921 | INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 6); | |
2922 | } | |
2923 | ||
2924 | /* Handle a floating point operand format at 26. | |
2925 | Only allows single and double precision. */ | |
2926 | case 'H': | |
2927 | flag = pa_parse_fp_format (&s); | |
2928 | switch (flag) | |
2929 | { | |
2930 | case SGL: | |
2931 | opcode |= 0x20; | |
2932 | case DBL: | |
2933 | the_insn.fpof1 = flag; | |
2934 | continue; | |
2935 | ||
2936 | case QUAD: | |
2937 | case ILLEGAL_FMT: | |
2938 | default: | |
2939 | as_bad (_("Invalid Floating Point Operand Format.")); | |
2940 | } | |
2941 | break; | |
2942 | ||
2943 | default: | |
2944 | abort (); | |
2945 | } | |
2946 | break; | |
2947 | } | |
2948 | ||
2949 | failed: | |
2950 | /* Check if the args matched. */ | |
2951 | if (match == FALSE) | |
2952 | { | |
2953 | if (&insn[1] - pa_opcodes < (int) NUMOPCODES | |
2954 | && !strcmp (insn->name, insn[1].name)) | |
2955 | { | |
2956 | ++insn; | |
2957 | s = argstart; | |
2958 | continue; | |
2959 | } | |
2960 | else | |
2961 | { | |
2962 | as_bad (_("Invalid operands %s"), error_message); | |
2963 | return; | |
2964 | } | |
2965 | } | |
2966 | break; | |
2967 | } | |
2968 | ||
2969 | the_insn.opcode = opcode; | |
2970 | } | |
2971 | ||
2972 | /* Turn a string in input_line_pointer into a floating point constant of type | |
2973 | type, and store the appropriate bytes in *litP. The number of LITTLENUMS | |
2974 | emitted is stored in *sizeP . An error message or NULL is returned. */ | |
2975 | ||
2976 | #define MAX_LITTLENUMS 6 | |
2977 | ||
2978 | char * | |
2979 | md_atof (type, litP, sizeP) | |
2980 | char type; | |
2981 | char *litP; | |
2982 | int *sizeP; | |
2983 | { | |
2984 | int prec; | |
2985 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
2986 | LITTLENUM_TYPE *wordP; | |
2987 | char *t; | |
2988 | ||
2989 | switch (type) | |
2990 | { | |
2991 | ||
2992 | case 'f': | |
2993 | case 'F': | |
2994 | case 's': | |
2995 | case 'S': | |
2996 | prec = 2; | |
2997 | break; | |
2998 | ||
2999 | case 'd': | |
3000 | case 'D': | |
3001 | case 'r': | |
3002 | case 'R': | |
3003 | prec = 4; | |
3004 | break; | |
3005 | ||
3006 | case 'x': | |
3007 | case 'X': | |
3008 | prec = 6; | |
3009 | break; | |
3010 | ||
3011 | case 'p': | |
3012 | case 'P': | |
3013 | prec = 6; | |
3014 | break; | |
3015 | ||
3016 | default: | |
3017 | *sizeP = 0; | |
3018 | return _("Bad call to MD_ATOF()"); | |
3019 | } | |
3020 | t = atof_ieee (input_line_pointer, type, words); | |
3021 | if (t) | |
3022 | input_line_pointer = t; | |
3023 | *sizeP = prec * sizeof (LITTLENUM_TYPE); | |
3024 | for (wordP = words; prec--;) | |
3025 | { | |
3026 | md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE)); | |
3027 | litP += sizeof (LITTLENUM_TYPE); | |
3028 | } | |
3029 | return NULL; | |
3030 | } | |
3031 | ||
3032 | /* Write out big-endian. */ | |
3033 | ||
3034 | void | |
3035 | md_number_to_chars (buf, val, n) | |
3036 | char *buf; | |
3037 | valueT val; | |
3038 | int n; | |
3039 | { | |
3040 | number_to_chars_bigendian (buf, val, n); | |
3041 | } | |
3042 | ||
3043 | /* Translate internal representation of relocation info to BFD target | |
3044 | format. */ | |
3045 | ||
3046 | arelent ** | |
3047 | tc_gen_reloc (section, fixp) | |
3048 | asection *section; | |
3049 | fixS *fixp; | |
3050 | { | |
3051 | arelent *reloc; | |
3052 | struct hppa_fix_struct *hppa_fixp; | |
3053 | bfd_reloc_code_real_type code; | |
3054 | static arelent *no_relocs = NULL; | |
3055 | arelent **relocs; | |
3056 | bfd_reloc_code_real_type **codes; | |
3057 | int n_relocs; | |
3058 | int i; | |
3059 | ||
3060 | hppa_fixp = (struct hppa_fix_struct *) fixp->tc_fix_data; | |
3061 | if (fixp->fx_addsy == 0) | |
3062 | return &no_relocs; | |
3063 | assert (hppa_fixp != 0); | |
3064 | assert (section != 0); | |
3065 | ||
3066 | reloc = (arelent *) xmalloc (sizeof (arelent)); | |
3067 | ||
a0f75b47 ILT |
3068 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
3069 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
252b5132 RH |
3070 | codes = (bfd_reloc_code_real_type **) hppa_gen_reloc_type (stdoutput, |
3071 | fixp->fx_r_type, | |
3072 | hppa_fixp->fx_r_format, | |
3073 | hppa_fixp->fx_r_field, | |
3074 | fixp->fx_subsy != NULL, | |
a0f75b47 | 3075 | symbol_get_bfdsym (fixp->fx_addsy)); |
252b5132 RH |
3076 | |
3077 | if (codes == NULL) | |
3078 | abort (); | |
3079 | ||
3080 | for (n_relocs = 0; codes[n_relocs]; n_relocs++) | |
3081 | ; | |
3082 | ||
3083 | relocs = (arelent **) xmalloc (sizeof (arelent *) * n_relocs + 1); | |
3084 | reloc = (arelent *) xmalloc (sizeof (arelent) * n_relocs); | |
3085 | for (i = 0; i < n_relocs; i++) | |
3086 | relocs[i] = &reloc[i]; | |
3087 | ||
3088 | relocs[n_relocs] = NULL; | |
3089 | ||
3090 | #ifdef OBJ_ELF | |
3091 | switch (fixp->fx_r_type) | |
3092 | { | |
3093 | default: | |
3094 | assert (n_relocs == 1); | |
3095 | ||
3096 | code = *codes[0]; | |
3097 | ||
a0f75b47 ILT |
3098 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
3099 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
252b5132 RH |
3100 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); |
3101 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
3102 | reloc->addend = 0; /* default */ | |
3103 | ||
3104 | assert (reloc->howto && code == reloc->howto->type); | |
3105 | ||
3106 | /* Now, do any processing that is dependent on the relocation type. */ | |
3107 | switch (code) | |
3108 | { | |
3109 | case R_PARISC_DLTREL21L: | |
3110 | case R_PARISC_DLTREL14R: | |
3111 | case R_PARISC_DLTREL14F: | |
3112 | case R_PARISC_PLABEL32: | |
3113 | case R_PARISC_PLABEL21L: | |
3114 | case R_PARISC_PLABEL14R: | |
3115 | /* For plabel relocations, the addend of the | |
3116 | relocation should be either 0 (no static link) or 2 | |
3117 | (static link required). | |
3118 | ||
3119 | FIXME: We always assume no static link! | |
3120 | ||
3121 | We also slam a zero addend into the DLT relative relocs; | |
3122 | it doesn't make a lot of sense to use any addend since | |
3123 | it gets you a different (eg unknown) DLT entry. */ | |
3124 | reloc->addend = 0; | |
3125 | break; | |
3126 | ||
3127 | case R_PARISC_PCREL21L: | |
3128 | case R_PARISC_PCREL17R: | |
3129 | case R_PARISC_PCREL17F: | |
3130 | case R_PARISC_PCREL17C: | |
3131 | case R_PARISC_PCREL14R: | |
3132 | case R_PARISC_PCREL14F: | |
3133 | /* The constant is stored in the instruction. */ | |
3134 | reloc->addend = HPPA_R_ADDEND (hppa_fixp->fx_arg_reloc, 0); | |
3135 | break; | |
3136 | default: | |
3137 | reloc->addend = fixp->fx_offset; | |
3138 | break; | |
3139 | } | |
3140 | break; | |
3141 | } | |
3142 | #else /* OBJ_SOM */ | |
3143 | ||
3144 | /* Walk over reach relocation returned by the BFD backend. */ | |
3145 | for (i = 0; i < n_relocs; i++) | |
3146 | { | |
3147 | code = *codes[i]; | |
3148 | ||
398e8c25 ILT |
3149 | relocs[i]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
3150 | *relocs[i]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
252b5132 RH |
3151 | relocs[i]->howto = bfd_reloc_type_lookup (stdoutput, code); |
3152 | relocs[i]->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
3153 | ||
3154 | switch (code) | |
3155 | { | |
3156 | case R_COMP2: | |
3157 | /* The only time we ever use a R_COMP2 fixup is for the difference | |
3158 | of two symbols. With that in mind we fill in all four | |
3159 | relocs now and break out of the loop. */ | |
3160 | assert (i == 1); | |
993142d5 | 3161 | relocs[0]->sym_ptr_ptr = (asymbol **) &(bfd_abs_symbol); |
252b5132 RH |
3162 | relocs[0]->howto = bfd_reloc_type_lookup (stdoutput, *codes[0]); |
3163 | relocs[0]->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
3164 | relocs[0]->addend = 0; | |
993142d5 ILT |
3165 | relocs[1]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
3166 | *relocs[1]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
252b5132 RH |
3167 | relocs[1]->howto = bfd_reloc_type_lookup (stdoutput, *codes[1]); |
3168 | relocs[1]->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
3169 | relocs[1]->addend = 0; | |
993142d5 ILT |
3170 | relocs[2]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
3171 | *relocs[2]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_subsy); | |
252b5132 RH |
3172 | relocs[2]->howto = bfd_reloc_type_lookup (stdoutput, *codes[2]); |
3173 | relocs[2]->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
3174 | relocs[2]->addend = 0; | |
993142d5 | 3175 | relocs[3]->sym_ptr_ptr = (asymbol **) &(bfd_abs_symbol); |
252b5132 RH |
3176 | relocs[3]->howto = bfd_reloc_type_lookup (stdoutput, *codes[3]); |
3177 | relocs[3]->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
3178 | relocs[3]->addend = 0; | |
993142d5 | 3179 | relocs[4]->sym_ptr_ptr = (asymbol **) &(bfd_abs_symbol); |
252b5132 RH |
3180 | relocs[4]->howto = bfd_reloc_type_lookup (stdoutput, *codes[4]); |
3181 | relocs[4]->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
3182 | relocs[4]->addend = 0; | |
3183 | goto done; | |
3184 | case R_PCREL_CALL: | |
3185 | case R_ABS_CALL: | |
3186 | relocs[i]->addend = HPPA_R_ADDEND (hppa_fixp->fx_arg_reloc, 0); | |
3187 | break; | |
3188 | ||
3189 | case R_DLT_REL: | |
3190 | case R_DATA_PLABEL: | |
3191 | case R_CODE_PLABEL: | |
3192 | /* For plabel relocations, the addend of the | |
3193 | relocation should be either 0 (no static link) or 2 | |
3194 | (static link required). | |
3195 | ||
3196 | FIXME: We always assume no static link! | |
3197 | ||
3198 | We also slam a zero addend into the DLT relative relocs; | |
3199 | it doesn't make a lot of sense to use any addend since | |
3200 | it gets you a different (eg unknown) DLT entry. */ | |
3201 | relocs[i]->addend = 0; | |
3202 | break; | |
3203 | ||
3204 | case R_N_MODE: | |
3205 | case R_S_MODE: | |
3206 | case R_D_MODE: | |
3207 | case R_R_MODE: | |
3208 | case R_FSEL: | |
3209 | case R_LSEL: | |
3210 | case R_RSEL: | |
3211 | case R_BEGIN_BRTAB: | |
3212 | case R_END_BRTAB: | |
3213 | case R_BEGIN_TRY: | |
3214 | case R_N0SEL: | |
3215 | case R_N1SEL: | |
3216 | /* There is no symbol or addend associated with these fixups. */ | |
993142d5 ILT |
3217 | relocs[i]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
3218 | *relocs[i]->sym_ptr_ptr = symbol_get_bfdsym (dummy_symbol); | |
252b5132 RH |
3219 | relocs[i]->addend = 0; |
3220 | break; | |
3221 | ||
3222 | case R_END_TRY: | |
3223 | case R_ENTRY: | |
3224 | case R_EXIT: | |
3225 | /* There is no symbol associated with these fixups. */ | |
993142d5 ILT |
3226 | relocs[i]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
3227 | *relocs[i]->sym_ptr_ptr = symbol_get_bfdsym (dummy_symbol); | |
252b5132 RH |
3228 | relocs[i]->addend = fixp->fx_offset; |
3229 | break; | |
3230 | ||
3231 | default: | |
3232 | relocs[i]->addend = fixp->fx_offset; | |
3233 | } | |
3234 | } | |
3235 | ||
3236 | done: | |
3237 | #endif | |
3238 | ||
3239 | return relocs; | |
3240 | } | |
3241 | ||
3242 | /* Process any machine dependent frag types. */ | |
3243 | ||
3244 | void | |
3245 | md_convert_frag (abfd, sec, fragP) | |
3246 | register bfd *abfd; | |
3247 | register asection *sec; | |
3248 | register fragS *fragP; | |
3249 | { | |
3250 | unsigned int address; | |
3251 | ||
3252 | if (fragP->fr_type == rs_machine_dependent) | |
3253 | { | |
3254 | switch ((int) fragP->fr_subtype) | |
3255 | { | |
3256 | case 0: | |
3257 | fragP->fr_type = rs_fill; | |
3258 | know (fragP->fr_var == 1); | |
3259 | know (fragP->fr_next); | |
3260 | address = fragP->fr_address + fragP->fr_fix; | |
3261 | if (address % fragP->fr_offset) | |
3262 | { | |
3263 | fragP->fr_offset = | |
3264 | fragP->fr_next->fr_address | |
3265 | - fragP->fr_address | |
3266 | - fragP->fr_fix; | |
3267 | } | |
3268 | else | |
3269 | fragP->fr_offset = 0; | |
3270 | break; | |
3271 | } | |
3272 | } | |
3273 | } | |
3274 | ||
3275 | /* Round up a section size to the appropriate boundary. */ | |
3276 | ||
3277 | valueT | |
3278 | md_section_align (segment, size) | |
3279 | asection *segment; | |
3280 | valueT size; | |
3281 | { | |
3282 | int align = bfd_get_section_alignment (stdoutput, segment); | |
3283 | int align2 = (1 << align) - 1; | |
3284 | ||
3285 | return (size + align2) & ~align2; | |
3286 | } | |
3287 | ||
3288 | /* Return the approximate size of a frag before relaxation has occurred. */ | |
3289 | int | |
3290 | md_estimate_size_before_relax (fragP, segment) | |
3291 | register fragS *fragP; | |
3292 | asection *segment; | |
3293 | { | |
3294 | int size; | |
3295 | ||
3296 | size = 0; | |
3297 | ||
3298 | while ((fragP->fr_fix + size) % fragP->fr_offset) | |
3299 | size++; | |
3300 | ||
3301 | return size; | |
3302 | } | |
3303 | \f | |
3304 | CONST char *md_shortopts = ""; | |
3305 | struct option md_longopts[] = { | |
3306 | {NULL, no_argument, NULL, 0} | |
3307 | }; | |
3308 | size_t md_longopts_size = sizeof(md_longopts); | |
3309 | ||
3310 | int | |
3311 | md_parse_option (c, arg) | |
3312 | int c; | |
3313 | char *arg; | |
3314 | { | |
3315 | return 0; | |
3316 | } | |
3317 | ||
3318 | void | |
3319 | md_show_usage (stream) | |
3320 | FILE *stream; | |
3321 | { | |
3322 | } | |
3323 | \f | |
3324 | /* We have no need to default values of symbols. */ | |
3325 | ||
3326 | symbolS * | |
3327 | md_undefined_symbol (name) | |
3328 | char *name; | |
3329 | { | |
3330 | return 0; | |
3331 | } | |
3332 | ||
3333 | /* Apply a fixup to an instruction. */ | |
3334 | ||
3335 | int | |
3336 | md_apply_fix (fixP, valp) | |
3337 | fixS *fixP; | |
3338 | valueT *valp; | |
3339 | { | |
3340 | char *buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
3341 | struct hppa_fix_struct *hppa_fixP; | |
3342 | long new_val, result = 0; | |
3343 | unsigned int w1, w2, w, resulti; | |
3344 | ||
3345 | hppa_fixP = (struct hppa_fix_struct *) fixP->tc_fix_data; | |
3346 | /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can | |
3347 | never be "applied" (they are just markers). Likewise for | |
3348 | R_HPPA_BEGIN_BRTAB and R_HPPA_END_BRTAB. */ | |
3349 | #ifdef OBJ_SOM | |
3350 | if (fixP->fx_r_type == R_HPPA_ENTRY | |
3351 | || fixP->fx_r_type == R_HPPA_EXIT | |
3352 | || fixP->fx_r_type == R_HPPA_BEGIN_BRTAB | |
3353 | || fixP->fx_r_type == R_HPPA_END_BRTAB | |
3354 | || fixP->fx_r_type == R_HPPA_BEGIN_TRY) | |
3355 | return 1; | |
3356 | ||
3357 | /* Disgusting. We must set fx_offset ourselves -- R_HPPA_END_TRY | |
3358 | fixups are considered not adjustable, which in turn causes | |
3359 | adjust_reloc_syms to not set fx_offset. Ugh. */ | |
3360 | if (fixP->fx_r_type == R_HPPA_END_TRY) | |
3361 | { | |
3362 | fixP->fx_offset = *valp; | |
3363 | return 1; | |
3364 | } | |
3365 | #endif | |
3366 | ||
3367 | /* There should have been an HPPA specific fixup associated | |
3368 | with the GAS fixup. */ | |
3369 | if (hppa_fixP) | |
3370 | { | |
3371 | unsigned long buf_wd = bfd_get_32 (stdoutput, buf); | |
3372 | unsigned char fmt = bfd_hppa_insn2fmt (buf_wd); | |
3373 | ||
3374 | /* If there is a symbol associated with this fixup, then it's something | |
3375 | which will need a SOM relocation (except for some PC-relative relocs). | |
3376 | In such cases we should treat the "val" or "addend" as zero since it | |
3377 | will be added in as needed from fx_offset in tc_gen_reloc. */ | |
3378 | if ((fixP->fx_addsy != NULL | |
3379 | || fixP->fx_r_type == R_HPPA_NONE) | |
3380 | #ifdef OBJ_SOM | |
3381 | && fmt != 32 | |
3382 | #endif | |
3383 | ) | |
90700a53 | 3384 | new_val = ((fmt == 12 || fmt == 17 || fmt == 22) ? 8 : 0); |
252b5132 RH |
3385 | #ifdef OBJ_SOM |
3386 | /* These field selectors imply that we do not want an addend. */ | |
3387 | else if (hppa_fixP->fx_r_field == e_psel | |
3388 | || hppa_fixP->fx_r_field == e_rpsel | |
3389 | || hppa_fixP->fx_r_field == e_lpsel | |
3390 | || hppa_fixP->fx_r_field == e_tsel | |
3391 | || hppa_fixP->fx_r_field == e_rtsel | |
3392 | || hppa_fixP->fx_r_field == e_ltsel) | |
90700a53 | 3393 | new_val = ((fmt == 12 || fmt == 17 || fmt == 22) ? 8 : 0); |
252b5132 RH |
3394 | /* This is truely disgusting. The machine independent code blindly |
3395 | adds in the value of the symbol being relocated against. Damn! */ | |
3396 | else if (fmt == 32 | |
3397 | && fixP->fx_addsy != NULL | |
3398 | && S_GET_SEGMENT (fixP->fx_addsy) != bfd_com_section_ptr) | |
3399 | new_val = hppa_field_adjust (*valp - S_GET_VALUE (fixP->fx_addsy), | |
3400 | 0, hppa_fixP->fx_r_field); | |
3401 | #endif | |
3402 | else | |
3403 | new_val = hppa_field_adjust (*valp, 0, hppa_fixP->fx_r_field); | |
3404 | ||
3405 | /* Handle pc-relative exceptions from above. */ | |
3406 | #define arg_reloc_stub_needed(CALLER, CALLEE) \ | |
3407 | ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER))) | |
90700a53 | 3408 | if ((fmt == 12 || fmt == 17 || fmt == 22) |
252b5132 RH |
3409 | && fixP->fx_addsy |
3410 | && fixP->fx_pcrel | |
49863f82 | 3411 | #ifdef OBJ_SOM |
252b5132 | 3412 | && !arg_reloc_stub_needed ((long) ((obj_symbol_type *) |
a0f75b47 ILT |
3413 | symbol_get_bfdsym (fixP->fx_addsy))->tc_data.ap.hppa_arg_reloc, |
3414 | hppa_fixP->fx_arg_reloc) | |
49863f82 | 3415 | #endif |
90700a53 | 3416 | && (((int)(*valp) > -262144 && (int)(*valp) < 262143) && fmt != 22) |
252b5132 RH |
3417 | && S_GET_SEGMENT (fixP->fx_addsy) == hppa_fixP->segment |
3418 | && !(fixP->fx_subsy | |
3419 | && S_GET_SEGMENT (fixP->fx_subsy) != hppa_fixP->segment)) | |
3420 | ||
3421 | new_val = hppa_field_adjust (*valp, 0, hppa_fixP->fx_r_field); | |
3422 | #undef arg_reloc_stub_needed | |
3423 | ||
3424 | switch (fmt) | |
3425 | { | |
3426 | /* Handle all opcodes with the 'j' operand type. */ | |
3427 | case 14: | |
3428 | CHECK_FIELD (new_val, 8191, -8192, 0); | |
3429 | ||
3430 | /* Mask off 14 bits to be changed. */ | |
3431 | bfd_put_32 (stdoutput, | |
3432 | bfd_get_32 (stdoutput, buf) & 0xffffc000, | |
3433 | buf); | |
3434 | low_sign_unext (new_val, 14, &resulti); | |
3435 | result = resulti; | |
3436 | break; | |
3437 | ||
3438 | /* Handle all opcodes with the 'k' operand type. */ | |
3439 | case 21: | |
3440 | CHECK_FIELD (new_val, 2097152, 0, 0); | |
3441 | ||
3442 | /* Mask off 21 bits to be changed. */ | |
3443 | bfd_put_32 (stdoutput, | |
3444 | bfd_get_32 (stdoutput, buf) & 0xffe00000, | |
3445 | buf); | |
3446 | dis_assemble_21 (new_val, &resulti); | |
3447 | result = resulti; | |
3448 | break; | |
3449 | ||
3450 | /* Handle all the opcodes with the 'i' operand type. */ | |
3451 | case 11: | |
3452 | CHECK_FIELD (new_val, 1023, -1023, 0); | |
3453 | ||
3454 | /* Mask off 11 bits to be changed. */ | |
3455 | bfd_put_32 (stdoutput, | |
3456 | bfd_get_32 (stdoutput, buf) & 0xffff800, | |
3457 | buf); | |
3458 | low_sign_unext (new_val, 11, &resulti); | |
3459 | result = resulti; | |
3460 | break; | |
3461 | ||
3462 | /* Handle all the opcodes with the 'w' operand type. */ | |
3463 | case 12: | |
3464 | CHECK_FIELD (new_val, 8199, -8184, 0); | |
3465 | ||
3466 | /* Mask off 11 bits to be changed. */ | |
3467 | sign_unext ((new_val - 8) >> 2, 12, &resulti); | |
3468 | bfd_put_32 (stdoutput, | |
3469 | bfd_get_32 (stdoutput, buf) & 0xffffe002, | |
3470 | buf); | |
3471 | ||
3472 | dis_assemble_12 (resulti, &w1, &w); | |
3473 | result = ((w1 << 2) | w); | |
3474 | break; | |
3475 | ||
3476 | /* Handle some of the opcodes with the 'W' operand type. */ | |
3477 | case 17: | |
3478 | { | |
3479 | int distance = *valp; | |
3480 | ||
3481 | CHECK_FIELD (new_val, 262143, -262144, 0); | |
3482 | ||
3483 | /* If this is an absolute branch (ie no link) with an out of | |
3484 | range target, then we want to complain. */ | |
3485 | if (fixP->fx_r_type == R_HPPA_PCREL_CALL | |
3486 | && (distance > 262143 || distance < -262144) | |
3487 | && (bfd_get_32 (stdoutput, buf) & 0xffe00000) == 0xe8000000) | |
3488 | CHECK_FIELD (distance, 262143, -262144, 0); | |
3489 | ||
3490 | /* Mask off 17 bits to be changed. */ | |
3491 | bfd_put_32 (stdoutput, | |
3492 | bfd_get_32 (stdoutput, buf) & 0xffe0e002, | |
3493 | buf); | |
3494 | sign_unext ((new_val - 8) >> 2, 17, &resulti); | |
3495 | dis_assemble_17 (resulti, &w1, &w2, &w); | |
3496 | result = ((w2 << 2) | (w1 << 16) | w); | |
3497 | break; | |
3498 | } | |
3499 | ||
3500 | case 32: | |
3501 | result = 0; | |
3502 | bfd_put_32 (stdoutput, new_val, buf); | |
3503 | break; | |
3504 | ||
3505 | default: | |
3506 | as_bad (_("Unknown relocation encountered in md_apply_fix.")); | |
3507 | return 0; | |
3508 | } | |
3509 | ||
3510 | /* Insert the relocation. */ | |
3511 | bfd_put_32 (stdoutput, bfd_get_32 (stdoutput, buf) | result, buf); | |
3512 | return 1; | |
3513 | } | |
3514 | else | |
3515 | { | |
3516 | printf (_("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n"), | |
3517 | (unsigned int) fixP, fixP->fx_r_type); | |
3518 | return 0; | |
3519 | } | |
3520 | } | |
3521 | ||
3522 | /* Exactly what point is a PC-relative offset relative TO? | |
3523 | On the PA, they're relative to the address of the offset. */ | |
3524 | ||
3525 | long | |
3526 | md_pcrel_from (fixP) | |
3527 | fixS *fixP; | |
3528 | { | |
3529 | return fixP->fx_where + fixP->fx_frag->fr_address; | |
3530 | } | |
3531 | ||
3532 | /* Return nonzero if the input line pointer is at the end of | |
3533 | a statement. */ | |
3534 | ||
3535 | static int | |
3536 | is_end_of_statement () | |
3537 | { | |
3538 | return ((*input_line_pointer == '\n') | |
3539 | || (*input_line_pointer == ';') | |
3540 | || (*input_line_pointer == '!')); | |
3541 | } | |
3542 | ||
3543 | /* Read a number from S. The number might come in one of many forms, | |
3544 | the most common will be a hex or decimal constant, but it could be | |
3545 | a pre-defined register (Yuk!), or an absolute symbol. | |
3546 | ||
3547 | Return a number or -1 for failure. | |
3548 | ||
3549 | When parsing PA-89 FP register numbers RESULT will be | |
3550 | the address of a structure to return information about | |
3551 | L/R half of FP registers, store results there as appropriate. | |
3552 | ||
3553 | pa_parse_number can not handle negative constants and will fail | |
3554 | horribly if it is passed such a constant. */ | |
3555 | ||
3556 | static int | |
3557 | pa_parse_number (s, result) | |
3558 | char **s; | |
3559 | struct pa_11_fp_reg_struct *result; | |
3560 | { | |
3561 | int num; | |
3562 | char *name; | |
3563 | char c; | |
3564 | symbolS *sym; | |
3565 | int status; | |
3566 | char *p = *s; | |
3567 | ||
3568 | /* Skip whitespace before the number. */ | |
3569 | while (*p == ' ' || *p == '\t') | |
3570 | p = p + 1; | |
3571 | ||
3572 | /* Store info in RESULT if requested by caller. */ | |
3573 | if (result) | |
3574 | { | |
3575 | result->number_part = -1; | |
3576 | result->l_r_select = -1; | |
3577 | } | |
3578 | num = -1; | |
3579 | ||
3580 | if (isdigit (*p)) | |
3581 | { | |
3582 | /* Looks like a number. */ | |
3583 | num = 0; | |
3584 | ||
3585 | if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X')) | |
3586 | { | |
3587 | /* The number is specified in hex. */ | |
3588 | p += 2; | |
3589 | while (isdigit (*p) || ((*p >= 'a') && (*p <= 'f')) | |
3590 | || ((*p >= 'A') && (*p <= 'F'))) | |
3591 | { | |
3592 | if (isdigit (*p)) | |
3593 | num = num * 16 + *p - '0'; | |
3594 | else if (*p >= 'a' && *p <= 'f') | |
3595 | num = num * 16 + *p - 'a' + 10; | |
3596 | else | |
3597 | num = num * 16 + *p - 'A' + 10; | |
3598 | ++p; | |
3599 | } | |
3600 | } | |
3601 | else | |
3602 | { | |
3603 | /* The number is specified in decimal. */ | |
3604 | while (isdigit (*p)) | |
3605 | { | |
3606 | num = num * 10 + *p - '0'; | |
3607 | ++p; | |
3608 | } | |
3609 | } | |
3610 | ||
3611 | /* Store info in RESULT if requested by the caller. */ | |
3612 | if (result) | |
3613 | { | |
3614 | result->number_part = num; | |
3615 | ||
3616 | if (IS_R_SELECT (p)) | |
3617 | { | |
3618 | result->l_r_select = 1; | |
3619 | ++p; | |
3620 | } | |
3621 | else if (IS_L_SELECT (p)) | |
3622 | { | |
3623 | result->l_r_select = 0; | |
3624 | ++p; | |
3625 | } | |
3626 | else | |
3627 | result->l_r_select = 0; | |
3628 | } | |
3629 | } | |
3630 | else if (*p == '%') | |
3631 | { | |
3632 | /* The number might be a predefined register. */ | |
3633 | num = 0; | |
3634 | name = p; | |
3635 | p++; | |
3636 | c = *p; | |
3637 | /* Tege hack: Special case for general registers as the general | |
3638 | code makes a binary search with case translation, and is VERY | |
3639 | slow. */ | |
3640 | if (c == 'r') | |
3641 | { | |
3642 | p++; | |
3643 | if (*p == 'e' && *(p + 1) == 't' | |
3644 | && (*(p + 2) == '0' || *(p + 2) == '1')) | |
3645 | { | |
3646 | p += 2; | |
3647 | num = *p - '0' + 28; | |
3648 | p++; | |
3649 | } | |
3650 | else if (*p == 'p') | |
3651 | { | |
3652 | num = 2; | |
3653 | p++; | |
3654 | } | |
3655 | else if (!isdigit (*p)) | |
3656 | { | |
3657 | if (print_errors) | |
3658 | as_bad (_("Undefined register: '%s'."), name); | |
3659 | num = -1; | |
3660 | } | |
3661 | else | |
3662 | { | |
3663 | do | |
3664 | num = num * 10 + *p++ - '0'; | |
3665 | while (isdigit (*p)); | |
3666 | } | |
3667 | } | |
3668 | else | |
3669 | { | |
3670 | /* Do a normal register search. */ | |
3671 | while (is_part_of_name (c)) | |
3672 | { | |
3673 | p = p + 1; | |
3674 | c = *p; | |
3675 | } | |
3676 | *p = 0; | |
3677 | status = reg_name_search (name); | |
3678 | if (status >= 0) | |
3679 | num = status; | |
3680 | else | |
3681 | { | |
3682 | if (print_errors) | |
3683 | as_bad (_("Undefined register: '%s'."), name); | |
3684 | num = -1; | |
3685 | } | |
3686 | *p = c; | |
3687 | } | |
3688 | ||
3689 | /* Store info in RESULT if requested by caller. */ | |
3690 | if (result) | |
3691 | { | |
3692 | result->number_part = num; | |
3693 | if (IS_R_SELECT (p - 1)) | |
3694 | result->l_r_select = 1; | |
3695 | else if (IS_L_SELECT (p - 1)) | |
3696 | result->l_r_select = 0; | |
3697 | else | |
3698 | result->l_r_select = 0; | |
3699 | } | |
3700 | } | |
3701 | else | |
3702 | { | |
3703 | /* And finally, it could be a symbol in the absolute section which | |
3704 | is effectively a constant. */ | |
3705 | num = 0; | |
3706 | name = p; | |
3707 | c = *p; | |
3708 | while (is_part_of_name (c)) | |
3709 | { | |
3710 | p = p + 1; | |
3711 | c = *p; | |
3712 | } | |
3713 | *p = 0; | |
3714 | if ((sym = symbol_find (name)) != NULL) | |
3715 | { | |
3716 | if (S_GET_SEGMENT (sym) == &bfd_abs_section) | |
3717 | num = S_GET_VALUE (sym); | |
3718 | else | |
3719 | { | |
3720 | if (print_errors) | |
3721 | as_bad (_("Non-absolute symbol: '%s'."), name); | |
3722 | num = -1; | |
3723 | } | |
3724 | } | |
3725 | else | |
3726 | { | |
3727 | /* There is where we'd come for an undefined symbol | |
3728 | or for an empty string. For an empty string we | |
3729 | will return zero. That's a concession made for | |
3730 | compatability with the braindamaged HP assemblers. */ | |
3731 | if (*name == 0) | |
3732 | num = 0; | |
3733 | else | |
3734 | { | |
3735 | if (print_errors) | |
3736 | as_bad (_("Undefined absolute constant: '%s'."), name); | |
3737 | num = -1; | |
3738 | } | |
3739 | } | |
3740 | *p = c; | |
3741 | ||
3742 | /* Store info in RESULT if requested by caller. */ | |
3743 | if (result) | |
3744 | { | |
3745 | result->number_part = num; | |
3746 | if (IS_R_SELECT (p - 1)) | |
3747 | result->l_r_select = 1; | |
3748 | else if (IS_L_SELECT (p - 1)) | |
3749 | result->l_r_select = 0; | |
3750 | else | |
3751 | result->l_r_select = 0; | |
3752 | } | |
3753 | } | |
3754 | ||
3755 | *s = p; | |
3756 | return num; | |
3757 | } | |
3758 | ||
3759 | #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg)) | |
3760 | ||
3761 | /* Given NAME, find the register number associated with that name, return | |
3762 | the integer value associated with the given name or -1 on failure. */ | |
3763 | ||
3764 | static int | |
3765 | reg_name_search (name) | |
3766 | char *name; | |
3767 | { | |
3768 | int middle, low, high; | |
3769 | int cmp; | |
3770 | ||
3771 | low = 0; | |
3772 | high = REG_NAME_CNT - 1; | |
3773 | ||
3774 | do | |
3775 | { | |
3776 | middle = (low + high) / 2; | |
3777 | cmp = strcasecmp (name, pre_defined_registers[middle].name); | |
3778 | if (cmp < 0) | |
3779 | high = middle - 1; | |
3780 | else if (cmp > 0) | |
3781 | low = middle + 1; | |
3782 | else | |
3783 | return pre_defined_registers[middle].value; | |
3784 | } | |
3785 | while (low <= high); | |
3786 | ||
3787 | return -1; | |
3788 | } | |
3789 | ||
3790 | ||
3791 | /* Return nonzero if the given INSN and L/R information will require | |
3792 | a new PA-1.1 opcode. */ | |
3793 | ||
3794 | static int | |
3795 | need_pa11_opcode (insn, result) | |
3796 | struct pa_it *insn; | |
3797 | struct pa_11_fp_reg_struct *result; | |
3798 | { | |
3799 | if (result->l_r_select == 1 && !(insn->fpof1 == DBL && insn->fpof2 == DBL)) | |
3800 | { | |
3801 | /* If this instruction is specific to a particular architecture, | |
3802 | then set a new architecture. */ | |
3803 | if (bfd_get_mach (stdoutput) < pa11) | |
3804 | { | |
3805 | if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, pa11)) | |
3806 | as_warn (_("could not update architecture and machine")); | |
3807 | } | |
3808 | return TRUE; | |
3809 | } | |
3810 | else | |
3811 | return FALSE; | |
3812 | } | |
3813 | ||
3814 | /* Parse a condition for a fcmp instruction. Return the numerical | |
3815 | code associated with the condition. */ | |
3816 | ||
3817 | static int | |
3818 | pa_parse_fp_cmp_cond (s) | |
3819 | char **s; | |
3820 | { | |
3821 | int cond, i; | |
3822 | ||
3823 | cond = 0; | |
3824 | ||
3825 | for (i = 0; i < 32; i++) | |
3826 | { | |
3827 | if (strncasecmp (*s, fp_cond_map[i].string, | |
3828 | strlen (fp_cond_map[i].string)) == 0) | |
3829 | { | |
3830 | cond = fp_cond_map[i].cond; | |
3831 | *s += strlen (fp_cond_map[i].string); | |
3832 | /* If not a complete match, back up the input string and | |
3833 | report an error. */ | |
3834 | if (**s != ' ' && **s != '\t') | |
3835 | { | |
3836 | *s -= strlen (fp_cond_map[i].string); | |
3837 | break; | |
3838 | } | |
3839 | while (**s == ' ' || **s == '\t') | |
3840 | *s = *s + 1; | |
3841 | return cond; | |
3842 | } | |
3843 | } | |
3844 | ||
3845 | as_bad (_("Invalid FP Compare Condition: %s"), *s); | |
3846 | ||
3847 | /* Advance over the bogus completer. */ | |
3848 | while (**s != ',' && **s != ' ' && **s != '\t') | |
3849 | *s += 1; | |
3850 | ||
3851 | return 0; | |
3852 | } | |
3853 | ||
3854 | ||
3855 | /* Parse an FP operand format completer returning the completer | |
3856 | type. */ | |
3857 | ||
3858 | static fp_operand_format | |
3859 | pa_parse_fp_format (s) | |
3860 | char **s; | |
3861 | { | |
3862 | int format; | |
3863 | ||
3864 | format = SGL; | |
3865 | if (**s == ',') | |
3866 | { | |
3867 | *s += 1; | |
3868 | if (strncasecmp (*s, "sgl", 3) == 0) | |
3869 | { | |
3870 | format = SGL; | |
3871 | *s += 4; | |
3872 | } | |
3873 | else if (strncasecmp (*s, "dbl", 3) == 0) | |
3874 | { | |
3875 | format = DBL; | |
3876 | *s += 4; | |
3877 | } | |
3878 | else if (strncasecmp (*s, "quad", 4) == 0) | |
3879 | { | |
3880 | format = QUAD; | |
3881 | *s += 5; | |
3882 | } | |
3883 | else | |
3884 | { | |
3885 | format = ILLEGAL_FMT; | |
3886 | as_bad (_("Invalid FP Operand Format: %3s"), *s); | |
3887 | } | |
3888 | } | |
3889 | ||
3890 | return format; | |
3891 | } | |
3892 | ||
3893 | /* Convert from a selector string into a selector type. */ | |
3894 | ||
3895 | static int | |
3896 | pa_chk_field_selector (str) | |
3897 | char **str; | |
3898 | { | |
3899 | int middle, low, high; | |
3900 | int cmp; | |
3901 | char name[4]; | |
3902 | ||
3903 | /* Read past any whitespace. */ | |
3904 | /* FIXME: should we read past newlines and formfeeds??? */ | |
3905 | while (**str == ' ' || **str == '\t' || **str == '\n' || **str == '\f') | |
3906 | *str = *str + 1; | |
3907 | ||
3908 | if ((*str)[1] == '\'' || (*str)[1] == '%') | |
3909 | name[0] = tolower ((*str)[0]), | |
3910 | name[1] = 0; | |
3911 | else if ((*str)[2] == '\'' || (*str)[2] == '%') | |
3912 | name[0] = tolower ((*str)[0]), | |
3913 | name[1] = tolower ((*str)[1]), | |
3914 | name[2] = 0; | |
252b5132 RH |
3915 | else if ((*str)[3] == '\'' || (*str)[3] == '%') |
3916 | name[0] = tolower ((*str)[0]), | |
3917 | name[1] = tolower ((*str)[1]), | |
3918 | name[2] = tolower ((*str)[2]), | |
3919 | name[3] = 0; | |
252b5132 RH |
3920 | else |
3921 | return e_fsel; | |
3922 | ||
3923 | low = 0; | |
3924 | high = sizeof (selector_table) / sizeof (struct selector_entry) - 1; | |
3925 | ||
3926 | do | |
3927 | { | |
3928 | middle = (low + high) / 2; | |
3929 | cmp = strcmp (name, selector_table[middle].prefix); | |
3930 | if (cmp < 0) | |
3931 | high = middle - 1; | |
3932 | else if (cmp > 0) | |
3933 | low = middle + 1; | |
3934 | else | |
3935 | { | |
3936 | *str += strlen (name) + 1; | |
3937 | #ifndef OBJ_SOM | |
3938 | if (selector_table[middle].field_selector == e_nsel) | |
3939 | return e_fsel; | |
3940 | #endif | |
3941 | return selector_table[middle].field_selector; | |
3942 | } | |
3943 | } | |
3944 | while (low <= high); | |
3945 | ||
3946 | return e_fsel; | |
3947 | } | |
3948 | ||
3949 | /* Mark (via expr_end) the end of an expression (I think). FIXME. */ | |
3950 | ||
3951 | static int | |
3952 | get_expression (str) | |
3953 | char *str; | |
3954 | { | |
3955 | char *save_in; | |
3956 | asection *seg; | |
3957 | ||
3958 | save_in = input_line_pointer; | |
3959 | input_line_pointer = str; | |
3960 | seg = expression (&the_insn.exp); | |
3961 | if (!(seg == absolute_section | |
3962 | || seg == undefined_section | |
3963 | || SEG_NORMAL (seg))) | |
3964 | { | |
3965 | as_warn (_("Bad segment in expression.")); | |
3966 | expr_end = input_line_pointer; | |
3967 | input_line_pointer = save_in; | |
3968 | return 1; | |
3969 | } | |
3970 | expr_end = input_line_pointer; | |
3971 | input_line_pointer = save_in; | |
3972 | return 0; | |
3973 | } | |
3974 | ||
3975 | /* Mark (via expr_end) the end of an absolute expression. FIXME. */ | |
3976 | static int | |
3977 | pa_get_absolute_expression (insn, strp) | |
3978 | struct pa_it *insn; | |
3979 | char **strp; | |
3980 | { | |
3981 | char *save_in; | |
3982 | ||
3983 | insn->field_selector = pa_chk_field_selector (strp); | |
3984 | save_in = input_line_pointer; | |
3985 | input_line_pointer = *strp; | |
3986 | expression (&insn->exp); | |
3987 | /* This is not perfect, but is a huge improvement over doing nothing. | |
3988 | ||
3989 | The PA assembly syntax is ambigious in a variety of ways. Consider | |
3990 | this string "4 %r5" Is that the number 4 followed by the register | |
3991 | r5, or is that 4 MOD 5? | |
3992 | ||
3993 | If we get a modulo expresion When looking for an absolute, we try | |
3994 | again cutting off the input string at the first whitespace character. */ | |
3995 | if (insn->exp.X_op == O_modulus) | |
3996 | { | |
3997 | char *s, c; | |
3998 | int retval; | |
3999 | ||
4000 | input_line_pointer = *strp; | |
4001 | s = *strp; | |
4002 | while (*s != ',' && *s != ' ' && *s != '\t') | |
4003 | s++; | |
4004 | ||
4005 | c = *s; | |
4006 | *s = 0; | |
4007 | ||
4008 | retval = pa_get_absolute_expression (insn, strp); | |
4009 | ||
4010 | input_line_pointer = save_in; | |
4011 | *s = c; | |
4012 | return evaluate_absolute (insn); | |
4013 | } | |
4014 | if (insn->exp.X_op != O_constant) | |
4015 | { | |
4016 | as_bad (_("Bad segment (should be absolute).")); | |
4017 | expr_end = input_line_pointer; | |
4018 | input_line_pointer = save_in; | |
4019 | return 0; | |
4020 | } | |
4021 | expr_end = input_line_pointer; | |
4022 | input_line_pointer = save_in; | |
4023 | return evaluate_absolute (insn); | |
4024 | } | |
4025 | ||
4026 | /* Evaluate an absolute expression EXP which may be modified by | |
4027 | the selector FIELD_SELECTOR. Return the value of the expression. */ | |
4028 | static int | |
4029 | evaluate_absolute (insn) | |
4030 | struct pa_it *insn; | |
4031 | { | |
4032 | int value; | |
4033 | expressionS exp; | |
4034 | int field_selector = insn->field_selector; | |
4035 | ||
4036 | exp = insn->exp; | |
4037 | value = exp.X_add_number; | |
4038 | ||
4039 | switch (field_selector) | |
4040 | { | |
4041 | /* No change. */ | |
4042 | case e_fsel: | |
4043 | break; | |
4044 | ||
4045 | /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */ | |
4046 | case e_lssel: | |
4047 | if (value & 0x00000400) | |
4048 | value += 0x800; | |
4049 | value = (value & 0xfffff800) >> 11; | |
4050 | break; | |
4051 | ||
4052 | /* Sign extend from bit 21. */ | |
4053 | case e_rssel: | |
4054 | if (value & 0x00000400) | |
4055 | value |= 0xfffff800; | |
4056 | else | |
4057 | value &= 0x7ff; | |
4058 | break; | |
4059 | ||
4060 | /* Arithmetic shift right 11 bits. */ | |
4061 | case e_lsel: | |
4062 | value = (value & 0xfffff800) >> 11; | |
4063 | break; | |
4064 | ||
4065 | /* Set bits 0-20 to zero. */ | |
4066 | case e_rsel: | |
4067 | value = value & 0x7ff; | |
4068 | break; | |
4069 | ||
4070 | /* Add 0x800 and arithmetic shift right 11 bits. */ | |
4071 | case e_ldsel: | |
4072 | value += 0x800; | |
4073 | value = (value & 0xfffff800) >> 11; | |
4074 | break; | |
4075 | ||
4076 | /* Set bitgs 0-21 to one. */ | |
4077 | case e_rdsel: | |
4078 | value |= 0xfffff800; | |
4079 | break; | |
4080 | ||
4081 | #define RSEL_ROUND(c) (((c) + 0x1000) & ~0x1fff) | |
4082 | case e_rrsel: | |
4083 | value = (RSEL_ROUND (value) & 0x7ff) + (value - RSEL_ROUND (value)); | |
4084 | break; | |
4085 | ||
4086 | case e_lrsel: | |
4087 | value = (RSEL_ROUND (value) >> 11) & 0x1fffff; | |
4088 | break; | |
4089 | #undef RSEL_ROUND | |
4090 | ||
4091 | default: | |
4092 | BAD_CASE (field_selector); | |
4093 | break; | |
4094 | } | |
4095 | return value; | |
4096 | } | |
4097 | ||
4098 | /* Given an argument location specification return the associated | |
4099 | argument location number. */ | |
4100 | ||
4101 | static unsigned int | |
4102 | pa_build_arg_reloc (type_name) | |
4103 | char *type_name; | |
4104 | { | |
4105 | ||
4106 | if (strncasecmp (type_name, "no", 2) == 0) | |
4107 | return 0; | |
4108 | if (strncasecmp (type_name, "gr", 2) == 0) | |
4109 | return 1; | |
4110 | else if (strncasecmp (type_name, "fr", 2) == 0) | |
4111 | return 2; | |
4112 | else if (strncasecmp (type_name, "fu", 2) == 0) | |
4113 | return 3; | |
4114 | else | |
4115 | as_bad (_("Invalid argument location: %s\n"), type_name); | |
4116 | ||
4117 | return 0; | |
4118 | } | |
4119 | ||
4120 | /* Encode and return an argument relocation specification for | |
4121 | the given register in the location specified by arg_reloc. */ | |
4122 | ||
4123 | static unsigned int | |
4124 | pa_align_arg_reloc (reg, arg_reloc) | |
4125 | unsigned int reg; | |
4126 | unsigned int arg_reloc; | |
4127 | { | |
4128 | unsigned int new_reloc; | |
4129 | ||
4130 | new_reloc = arg_reloc; | |
4131 | switch (reg) | |
4132 | { | |
4133 | case 0: | |
4134 | new_reloc <<= 8; | |
4135 | break; | |
4136 | case 1: | |
4137 | new_reloc <<= 6; | |
4138 | break; | |
4139 | case 2: | |
4140 | new_reloc <<= 4; | |
4141 | break; | |
4142 | case 3: | |
4143 | new_reloc <<= 2; | |
4144 | break; | |
4145 | default: | |
4146 | as_bad (_("Invalid argument description: %d"), reg); | |
4147 | } | |
4148 | ||
4149 | return new_reloc; | |
4150 | } | |
4151 | ||
4152 | /* Parse a PA nullification completer (,n). Return nonzero if the | |
4153 | completer was found; return zero if no completer was found. */ | |
4154 | ||
4155 | static int | |
4156 | pa_parse_nullif (s) | |
4157 | char **s; | |
4158 | { | |
4159 | int nullif; | |
4160 | ||
4161 | nullif = 0; | |
4162 | if (**s == ',') | |
4163 | { | |
4164 | *s = *s + 1; | |
4165 | if (strncasecmp (*s, "n", 1) == 0) | |
4166 | nullif = 1; | |
4167 | else | |
4168 | { | |
4169 | as_bad (_("Invalid Nullification: (%c)"), **s); | |
4170 | nullif = 0; | |
4171 | } | |
4172 | *s = *s + 1; | |
4173 | } | |
4174 | ||
4175 | return nullif; | |
4176 | } | |
4177 | ||
4178 | /* Parse a non-negated compare/subtract completer returning the | |
4179 | number (for encoding in instrutions) of the given completer. | |
4180 | ||
4181 | ISBRANCH specifies whether or not this is parsing a condition | |
4182 | completer for a branch (vs a nullification completer for a | |
4183 | computational instruction. */ | |
4184 | ||
4185 | static int | |
4186 | pa_parse_nonneg_cmpsub_cmpltr (s, isbranch) | |
4187 | char **s; | |
4188 | int isbranch; | |
4189 | { | |
4190 | int cmpltr; | |
4191 | char *name = *s + 1; | |
4192 | char c; | |
4193 | char *save_s = *s; | |
4194 | int nullify = 0; | |
4195 | ||
4196 | cmpltr = 0; | |
4197 | if (**s == ',') | |
4198 | { | |
4199 | *s += 1; | |
4200 | while (**s != ',' && **s != ' ' && **s != '\t') | |
4201 | *s += 1; | |
4202 | c = **s; | |
4203 | **s = 0x00; | |
4204 | ||
4205 | ||
4206 | if (strcmp (name, "=") == 0) | |
4207 | { | |
4208 | cmpltr = 1; | |
4209 | } | |
4210 | else if (strcmp (name, "<") == 0) | |
4211 | { | |
4212 | cmpltr = 2; | |
4213 | } | |
4214 | else if (strcmp (name, "<=") == 0) | |
4215 | { | |
4216 | cmpltr = 3; | |
4217 | } | |
4218 | else if (strcmp (name, "<<") == 0) | |
4219 | { | |
4220 | cmpltr = 4; | |
4221 | } | |
4222 | else if (strcmp (name, "<<=") == 0) | |
4223 | { | |
4224 | cmpltr = 5; | |
4225 | } | |
4226 | else if (strcasecmp (name, "sv") == 0) | |
4227 | { | |
4228 | cmpltr = 6; | |
4229 | } | |
4230 | else if (strcasecmp (name, "od") == 0) | |
4231 | { | |
4232 | cmpltr = 7; | |
4233 | } | |
4234 | /* If we have something like addb,n then there is no condition | |
4235 | completer. */ | |
4236 | else if (strcasecmp (name, "n") == 0 && isbranch) | |
4237 | { | |
4238 | cmpltr = 0; | |
4239 | nullify = 1; | |
4240 | } | |
4241 | else | |
4242 | { | |
4243 | cmpltr = -1; | |
4244 | } | |
4245 | **s = c; | |
4246 | } | |
4247 | ||
4248 | /* Reset pointers if this was really a ,n for a branch instruction. */ | |
4249 | if (nullify) | |
4250 | *s = save_s; | |
4251 | ||
4252 | ||
4253 | return cmpltr; | |
4254 | } | |
4255 | ||
4256 | /* Parse a negated compare/subtract completer returning the | |
4257 | number (for encoding in instrutions) of the given completer. | |
4258 | ||
4259 | ISBRANCH specifies whether or not this is parsing a condition | |
4260 | completer for a branch (vs a nullification completer for a | |
4261 | computational instruction. */ | |
4262 | ||
4263 | static int | |
4264 | pa_parse_neg_cmpsub_cmpltr (s, isbranch) | |
4265 | char **s; | |
4266 | int isbranch; | |
4267 | { | |
4268 | int cmpltr; | |
4269 | char *name = *s + 1; | |
4270 | char c; | |
4271 | char *save_s = *s; | |
4272 | int nullify = 0; | |
4273 | ||
4274 | cmpltr = 0; | |
4275 | if (**s == ',') | |
4276 | { | |
4277 | *s += 1; | |
4278 | while (**s != ',' && **s != ' ' && **s != '\t') | |
4279 | *s += 1; | |
4280 | c = **s; | |
4281 | **s = 0x00; | |
4282 | ||
4283 | ||
4284 | if (strcasecmp (name, "tr") == 0) | |
4285 | { | |
4286 | cmpltr = 0; | |
4287 | } | |
4288 | else if (strcmp (name, "<>") == 0) | |
4289 | { | |
4290 | cmpltr = 1; | |
4291 | } | |
4292 | else if (strcmp (name, ">=") == 0) | |
4293 | { | |
4294 | cmpltr = 2; | |
4295 | } | |
4296 | else if (strcmp (name, ">") == 0) | |
4297 | { | |
4298 | cmpltr = 3; | |
4299 | } | |
4300 | else if (strcmp (name, ">>=") == 0) | |
4301 | { | |
4302 | cmpltr = 4; | |
4303 | } | |
4304 | else if (strcmp (name, ">>") == 0) | |
4305 | { | |
4306 | cmpltr = 5; | |
4307 | } | |
4308 | else if (strcasecmp (name, "nsv") == 0) | |
4309 | { | |
4310 | cmpltr = 6; | |
4311 | } | |
4312 | else if (strcasecmp (name, "ev") == 0) | |
4313 | { | |
4314 | cmpltr = 7; | |
4315 | } | |
4316 | /* If we have something like addb,n then there is no condition | |
4317 | completer. */ | |
4318 | else if (strcasecmp (name, "n") == 0 && isbranch) | |
4319 | { | |
4320 | cmpltr = 0; | |
4321 | nullify = 1; | |
4322 | } | |
4323 | else | |
4324 | { | |
4325 | cmpltr = -1; | |
4326 | } | |
4327 | **s = c; | |
4328 | } | |
4329 | ||
4330 | /* Reset pointers if this was really a ,n for a branch instruction. */ | |
4331 | if (nullify) | |
4332 | *s = save_s; | |
4333 | ||
4334 | ||
4335 | return cmpltr; | |
4336 | } | |
4337 | ||
4338 | ||
4339 | /* Parse a non-negated addition completer returning the number | |
4340 | (for encoding in instrutions) of the given completer. | |
4341 | ||
4342 | ISBRANCH specifies whether or not this is parsing a condition | |
4343 | completer for a branch (vs a nullification completer for a | |
4344 | computational instruction. */ | |
4345 | ||
4346 | static int | |
4347 | pa_parse_nonneg_add_cmpltr (s, isbranch) | |
4348 | char **s; | |
4349 | int isbranch; | |
4350 | { | |
4351 | int cmpltr; | |
4352 | char *name = *s + 1; | |
4353 | char c; | |
4354 | char *save_s = *s; | |
4355 | ||
4356 | cmpltr = 0; | |
4357 | if (**s == ',') | |
4358 | { | |
4359 | *s += 1; | |
4360 | while (**s != ',' && **s != ' ' && **s != '\t') | |
4361 | *s += 1; | |
4362 | c = **s; | |
4363 | **s = 0x00; | |
4364 | if (strcmp (name, "=") == 0) | |
4365 | { | |
4366 | cmpltr = 1; | |
4367 | } | |
4368 | else if (strcmp (name, "<") == 0) | |
4369 | { | |
4370 | cmpltr = 2; | |
4371 | } | |
4372 | else if (strcmp (name, "<=") == 0) | |
4373 | { | |
4374 | cmpltr = 3; | |
4375 | } | |
4376 | else if (strcasecmp (name, "nuv") == 0) | |
4377 | { | |
4378 | cmpltr = 4; | |
4379 | } | |
4380 | else if (strcasecmp (name, "znv") == 0) | |
4381 | { | |
4382 | cmpltr = 5; | |
4383 | } | |
4384 | else if (strcasecmp (name, "sv") == 0) | |
4385 | { | |
4386 | cmpltr = 6; | |
4387 | } | |
4388 | else if (strcasecmp (name, "od") == 0) | |
4389 | { | |
4390 | cmpltr = 7; | |
4391 | } | |
4392 | /* If we have something like addb,n then there is no condition | |
4393 | completer. */ | |
4394 | else if (strcasecmp (name, "n") == 0 && isbranch) | |
4395 | { | |
4396 | cmpltr = 0; | |
4397 | } | |
4398 | else | |
4399 | { | |
4400 | cmpltr = -1; | |
4401 | } | |
4402 | **s = c; | |
4403 | } | |
4404 | ||
4405 | /* Reset pointers if this was really a ,n for a branch instruction. */ | |
4406 | if (cmpltr == 0 && *name == 'n' && isbranch) | |
4407 | *s = save_s; | |
4408 | ||
4409 | return cmpltr; | |
4410 | } | |
4411 | ||
4412 | /* Parse a negated addition completer returning the number | |
4413 | (for encoding in instrutions) of the given completer. | |
4414 | ||
4415 | ISBRANCH specifies whether or not this is parsing a condition | |
4416 | completer for a branch (vs a nullification completer for a | |
4417 | computational instruction). */ | |
4418 | ||
4419 | static int | |
4420 | pa_parse_neg_add_cmpltr (s, isbranch) | |
4421 | char **s; | |
4422 | int isbranch; | |
4423 | { | |
4424 | int cmpltr; | |
4425 | char *name = *s + 1; | |
4426 | char c; | |
4427 | char *save_s = *s; | |
4428 | ||
4429 | cmpltr = 0; | |
4430 | if (**s == ',') | |
4431 | { | |
4432 | *s += 1; | |
4433 | while (**s != ',' && **s != ' ' && **s != '\t') | |
4434 | *s += 1; | |
4435 | c = **s; | |
4436 | **s = 0x00; | |
4437 | if (strcasecmp (name, "tr") == 0) | |
4438 | { | |
4439 | cmpltr = 0; | |
4440 | } | |
4441 | else if (strcmp (name, "<>") == 0) | |
4442 | { | |
4443 | cmpltr = 1; | |
4444 | } | |
4445 | else if (strcmp (name, ">=") == 0) | |
4446 | { | |
4447 | cmpltr = 2; | |
4448 | } | |
4449 | else if (strcmp (name, ">") == 0) | |
4450 | { | |
4451 | cmpltr = 3; | |
4452 | } | |
4453 | else if (strcasecmp (name, "uv") == 0) | |
4454 | { | |
4455 | cmpltr = 4; | |
4456 | } | |
4457 | else if (strcasecmp (name, "vnz") == 0) | |
4458 | { | |
4459 | cmpltr = 5; | |
4460 | } | |
4461 | else if (strcasecmp (name, "nsv") == 0) | |
4462 | { | |
4463 | cmpltr = 6; | |
4464 | } | |
4465 | else if (strcasecmp (name, "ev") == 0) | |
4466 | { | |
4467 | cmpltr = 7; | |
4468 | } | |
4469 | /* If we have something like addb,n then there is no condition | |
4470 | completer. */ | |
4471 | else if (strcasecmp (name, "n") == 0 && isbranch) | |
4472 | { | |
4473 | cmpltr = 0; | |
4474 | } | |
4475 | else | |
4476 | { | |
4477 | cmpltr = -1; | |
4478 | } | |
4479 | **s = c; | |
4480 | } | |
4481 | ||
4482 | /* Reset pointers if this was really a ,n for a branch instruction. */ | |
4483 | if (cmpltr == 0 && *name == 'n' && isbranch) | |
4484 | *s = save_s; | |
4485 | ||
4486 | return cmpltr; | |
4487 | } | |
4488 | ||
49863f82 | 4489 | #ifdef OBJ_SOM |
252b5132 RH |
4490 | /* Handle an alignment directive. Special so that we can update the |
4491 | alignment of the subspace if necessary. */ | |
4492 | static void | |
4493 | pa_align (bytes) | |
4494 | { | |
4495 | /* We must have a valid space and subspace. */ | |
4496 | pa_check_current_space_and_subspace (); | |
4497 | ||
4498 | /* Let the generic gas code do most of the work. */ | |
4499 | s_align_bytes (bytes); | |
4500 | ||
4501 | /* If bytes is a power of 2, then update the current subspace's | |
4502 | alignment if necessary. */ | |
4503 | if (log2 (bytes) != -1) | |
4504 | record_alignment (current_subspace->ssd_seg, log2 (bytes)); | |
4505 | } | |
49863f82 | 4506 | #endif |
252b5132 RH |
4507 | |
4508 | /* Handle a .BLOCK type pseudo-op. */ | |
4509 | ||
4510 | static void | |
4511 | pa_block (z) | |
4512 | int z; | |
4513 | { | |
4514 | char *p; | |
4515 | long int temp_fill; | |
4516 | unsigned int temp_size; | |
4517 | unsigned int i; | |
4518 | ||
49863f82 | 4519 | #ifdef OBJ_SOM |
252b5132 RH |
4520 | /* We must have a valid space and subspace. */ |
4521 | pa_check_current_space_and_subspace (); | |
49863f82 | 4522 | #endif |
252b5132 RH |
4523 | |
4524 | temp_size = get_absolute_expression (); | |
4525 | ||
4526 | /* Always fill with zeros, that's what the HP assembler does. */ | |
4527 | temp_fill = 0; | |
4528 | ||
4529 | p = frag_var (rs_fill, (int) temp_size, (int) temp_size, | |
4530 | (relax_substateT) 0, (symbolS *) 0, (offsetT) 1, NULL); | |
4531 | memset (p, 0, temp_size); | |
4532 | ||
4533 | /* Convert 2 bytes at a time. */ | |
4534 | ||
4535 | for (i = 0; i < temp_size; i += 2) | |
4536 | { | |
4537 | md_number_to_chars (p + i, | |
4538 | (valueT) temp_fill, | |
4539 | (int) ((temp_size - i) > 2 ? 2 : (temp_size - i))); | |
4540 | } | |
4541 | ||
4542 | pa_undefine_label (); | |
4543 | demand_empty_rest_of_line (); | |
4544 | } | |
4545 | ||
4546 | /* Handle a .begin_brtab and .end_brtab pseudo-op. */ | |
4547 | ||
4548 | static void | |
4549 | pa_brtab (begin) | |
4550 | int begin; | |
4551 | { | |
4552 | ||
4553 | #ifdef OBJ_SOM | |
4554 | /* The BRTAB relocations are only availble in SOM (to denote | |
4555 | the beginning and end of branch tables). */ | |
4556 | char *where = frag_more (0); | |
4557 | ||
4558 | fix_new_hppa (frag_now, where - frag_now->fr_literal, 0, | |
4559 | NULL, (offsetT) 0, NULL, | |
4560 | 0, begin ? R_HPPA_BEGIN_BRTAB : R_HPPA_END_BRTAB, | |
4561 | e_fsel, 0, 0, NULL); | |
4562 | #endif | |
4563 | ||
4564 | demand_empty_rest_of_line (); | |
4565 | } | |
4566 | ||
4567 | /* Handle a .begin_try and .end_try pseudo-op. */ | |
4568 | ||
4569 | static void | |
4570 | pa_try (begin) | |
4571 | int begin; | |
4572 | { | |
4573 | #ifdef OBJ_SOM | |
4574 | expressionS exp; | |
4575 | char *where = frag_more (0); | |
4576 | ||
4577 | if (! begin) | |
4578 | expression (&exp); | |
4579 | ||
4580 | /* The TRY relocations are only availble in SOM (to denote | |
4581 | the beginning and end of exception handling regions). */ | |
4582 | ||
4583 | fix_new_hppa (frag_now, where - frag_now->fr_literal, 0, | |
4584 | NULL, (offsetT) 0, begin ? NULL : &exp, | |
4585 | 0, begin ? R_HPPA_BEGIN_TRY : R_HPPA_END_TRY, | |
4586 | e_fsel, 0, 0, NULL); | |
4587 | #endif | |
4588 | ||
4589 | demand_empty_rest_of_line (); | |
4590 | } | |
4591 | ||
4592 | /* Handle a .CALL pseudo-op. This involves storing away information | |
4593 | about where arguments are to be found so the linker can detect | |
4594 | (and correct) argument location mismatches between caller and callee. */ | |
4595 | ||
4596 | static void | |
4597 | pa_call (unused) | |
4598 | int unused; | |
4599 | { | |
49863f82 | 4600 | #ifdef OBJ_SOM |
252b5132 RH |
4601 | /* We must have a valid space and subspace. */ |
4602 | pa_check_current_space_and_subspace (); | |
49863f82 | 4603 | #endif |
252b5132 RH |
4604 | |
4605 | pa_call_args (&last_call_desc); | |
4606 | demand_empty_rest_of_line (); | |
4607 | } | |
4608 | ||
4609 | /* Do the dirty work of building a call descriptor which describes | |
4610 | where the caller placed arguments to a function call. */ | |
4611 | ||
4612 | static void | |
4613 | pa_call_args (call_desc) | |
4614 | struct call_desc *call_desc; | |
4615 | { | |
4616 | char *name, c, *p; | |
4617 | unsigned int temp, arg_reloc; | |
4618 | ||
4619 | while (!is_end_of_statement ()) | |
4620 | { | |
4621 | name = input_line_pointer; | |
4622 | c = get_symbol_end (); | |
4623 | /* Process a source argument. */ | |
4624 | if ((strncasecmp (name, "argw", 4) == 0)) | |
4625 | { | |
4626 | temp = atoi (name + 4); | |
4627 | p = input_line_pointer; | |
4628 | *p = c; | |
4629 | input_line_pointer++; | |
4630 | name = input_line_pointer; | |
4631 | c = get_symbol_end (); | |
4632 | arg_reloc = pa_build_arg_reloc (name); | |
4633 | call_desc->arg_reloc |= pa_align_arg_reloc (temp, arg_reloc); | |
4634 | } | |
4635 | /* Process a return value. */ | |
4636 | else if ((strncasecmp (name, "rtnval", 6) == 0)) | |
4637 | { | |
4638 | p = input_line_pointer; | |
4639 | *p = c; | |
4640 | input_line_pointer++; | |
4641 | name = input_line_pointer; | |
4642 | c = get_symbol_end (); | |
4643 | arg_reloc = pa_build_arg_reloc (name); | |
4644 | call_desc->arg_reloc |= (arg_reloc & 0x3); | |
4645 | } | |
4646 | else | |
4647 | { | |
4648 | as_bad (_("Invalid .CALL argument: %s"), name); | |
4649 | } | |
4650 | p = input_line_pointer; | |
4651 | *p = c; | |
4652 | if (!is_end_of_statement ()) | |
4653 | input_line_pointer++; | |
4654 | } | |
4655 | } | |
4656 | ||
4657 | /* Return TRUE if FRAG1 and FRAG2 are the same. */ | |
4658 | ||
4659 | static int | |
4660 | is_same_frag (frag1, frag2) | |
4661 | fragS *frag1; | |
4662 | fragS *frag2; | |
4663 | { | |
4664 | ||
4665 | if (frag1 == NULL) | |
4666 | return (FALSE); | |
4667 | else if (frag2 == NULL) | |
4668 | return (FALSE); | |
4669 | else if (frag1 == frag2) | |
4670 | return (TRUE); | |
4671 | else if (frag2->fr_type == rs_fill && frag2->fr_fix == 0) | |
4672 | return (is_same_frag (frag1, frag2->fr_next)); | |
4673 | else | |
4674 | return (FALSE); | |
4675 | } | |
4676 | ||
4677 | #ifdef OBJ_ELF | |
4678 | /* Build an entry in the UNWIND subspace from the given function | |
4679 | attributes in CALL_INFO. This is not needed for SOM as using | |
4680 | R_ENTRY and R_EXIT relocations allow the linker to handle building | |
4681 | of the unwind spaces. */ | |
4682 | ||
4683 | static void | |
4684 | pa_build_unwind_subspace (call_info) | |
4685 | struct call_info *call_info; | |
4686 | { | |
4687 | char *unwind; | |
4688 | asection *seg, *save_seg; | |
46031ca9 | 4689 | asymbol *sym; |
252b5132 | 4690 | subsegT subseg, save_subseg; |
46031ca9 | 4691 | int i, reloc; |
252b5132 RH |
4692 | char c, *p; |
4693 | ||
9100134c JL |
4694 | if (bfd_get_arch_info (stdoutput)->bits_per_address == 32) |
4695 | reloc = R_PARISC_DIR32; | |
46031ca9 | 4696 | else |
9100134c | 4697 | reloc = R_PARISC_SEGREL32; |
46031ca9 | 4698 | |
252b5132 RH |
4699 | /* Get into the right seg/subseg. This may involve creating |
4700 | the seg the first time through. Make sure to have the | |
4701 | old seg/subseg so that we can reset things when we are done. */ | |
252b5132 RH |
4702 | seg = bfd_get_section_by_name (stdoutput, UNWIND_SECTION_NAME); |
4703 | if (seg == ASEC_NULL) | |
4704 | { | |
4705 | seg = bfd_make_section_old_way (stdoutput, UNWIND_SECTION_NAME); | |
4706 | bfd_set_section_flags (stdoutput, seg, | |
4707 | SEC_READONLY | SEC_HAS_CONTENTS | |
b100be66 JL |
4708 | | SEC_LOAD | SEC_RELOC | SEC_ALLOC | SEC_DATA); |
4709 | bfd_set_section_alignment (stdoutput, seg, 2); | |
252b5132 RH |
4710 | } |
4711 | ||
4712 | save_seg = now_seg; | |
4713 | save_subseg = now_subseg; | |
46031ca9 | 4714 | subseg_set (seg, 0); |
252b5132 RH |
4715 | |
4716 | ||
4717 | /* Get some space to hold relocation information for the unwind | |
4718 | descriptor. */ | |
4719 | p = frag_more (4); | |
4720 | md_number_to_chars (p, 0, 4); | |
4721 | ||
4722 | /* Relocation info. for start offset of the function. */ | |
4723 | fix_new_hppa (frag_now, p - frag_now->fr_literal, 4, | |
4724 | call_info->start_symbol, (offsetT) 0, | |
46031ca9 JL |
4725 | (expressionS *) NULL, 0, reloc, |
4726 | e_fsel, 32, 0, NULL); | |
252b5132 RH |
4727 | |
4728 | p = frag_more (4); | |
4729 | md_number_to_chars (p, 0, 4); | |
4730 | ||
4731 | /* Relocation info. for end offset of the function. | |
4732 | ||
4733 | Because we allow reductions of 32bit relocations for ELF, this will be | |
4734 | reduced to section_sym + offset which avoids putting the temporary | |
4735 | symbol into the symbol table. It (should) end up giving the same | |
4736 | value as call_info->start_symbol + function size once the linker is | |
4737 | finished with its work. */ | |
4738 | ||
4739 | fix_new_hppa (frag_now, p - frag_now->fr_literal, 4, | |
4740 | call_info->end_symbol, (offsetT) 0, | |
46031ca9 JL |
4741 | (expressionS *) NULL, 0, reloc, |
4742 | e_fsel, 32, 0, NULL); | |
252b5132 RH |
4743 | |
4744 | /* Dump it. */ | |
4745 | unwind = (char *) &call_info->ci_unwind; | |
4746 | for (i = 8; i < sizeof (struct unwind_table); i++) | |
4747 | { | |
4748 | c = *(unwind + i); | |
4749 | { | |
4750 | FRAG_APPEND_1_CHAR (c); | |
4751 | } | |
4752 | } | |
4753 | ||
4754 | /* Return back to the original segment/subsegment. */ | |
4755 | subseg_set (save_seg, save_subseg); | |
4756 | } | |
4757 | #endif | |
4758 | ||
4759 | /* Process a .CALLINFO pseudo-op. This information is used later | |
4760 | to build unwind descriptors and maybe one day to support | |
4761 | .ENTER and .LEAVE. */ | |
4762 | ||
4763 | static void | |
4764 | pa_callinfo (unused) | |
4765 | int unused; | |
4766 | { | |
4767 | char *name, c, *p; | |
4768 | int temp; | |
4769 | ||
49863f82 | 4770 | #ifdef OBJ_SOM |
252b5132 RH |
4771 | /* We must have a valid space and subspace. */ |
4772 | pa_check_current_space_and_subspace (); | |
49863f82 | 4773 | #endif |
252b5132 RH |
4774 | |
4775 | /* .CALLINFO must appear within a procedure definition. */ | |
4776 | if (!within_procedure) | |
4777 | as_bad (_(".callinfo is not within a procedure definition")); | |
4778 | ||
4779 | /* Mark the fact that we found the .CALLINFO for the | |
4780 | current procedure. */ | |
4781 | callinfo_found = TRUE; | |
4782 | ||
4783 | /* Iterate over the .CALLINFO arguments. */ | |
4784 | while (!is_end_of_statement ()) | |
4785 | { | |
4786 | name = input_line_pointer; | |
4787 | c = get_symbol_end (); | |
4788 | /* Frame size specification. */ | |
4789 | if ((strncasecmp (name, "frame", 5) == 0)) | |
4790 | { | |
4791 | p = input_line_pointer; | |
4792 | *p = c; | |
4793 | input_line_pointer++; | |
4794 | temp = get_absolute_expression (); | |
4795 | if ((temp & 0x3) != 0) | |
4796 | { | |
4797 | as_bad (_("FRAME parameter must be a multiple of 8: %d\n"), temp); | |
4798 | temp = 0; | |
4799 | } | |
4800 | ||
4801 | /* callinfo is in bytes and unwind_desc is in 8 byte units. */ | |
4802 | last_call_info->ci_unwind.descriptor.frame_size = temp / 8; | |
4803 | ||
4804 | } | |
4805 | /* Entry register (GR, GR and SR) specifications. */ | |
4806 | else if ((strncasecmp (name, "entry_gr", 8) == 0)) | |
4807 | { | |
4808 | p = input_line_pointer; | |
4809 | *p = c; | |
4810 | input_line_pointer++; | |
4811 | temp = get_absolute_expression (); | |
4812 | /* The HP assembler accepts 19 as the high bound for ENTRY_GR | |
4813 | even though %r19 is caller saved. I think this is a bug in | |
4814 | the HP assembler, and we are not going to emulate it. */ | |
4815 | if (temp < 3 || temp > 18) | |
4816 | as_bad (_("Value for ENTRY_GR must be in the range 3..18\n")); | |
4817 | last_call_info->ci_unwind.descriptor.entry_gr = temp - 2; | |
4818 | } | |
4819 | else if ((strncasecmp (name, "entry_fr", 8) == 0)) | |
4820 | { | |
4821 | p = input_line_pointer; | |
4822 | *p = c; | |
4823 | input_line_pointer++; | |
4824 | temp = get_absolute_expression (); | |
4825 | /* Similarly the HP assembler takes 31 as the high bound even | |
4826 | though %fr21 is the last callee saved floating point register. */ | |
4827 | if (temp < 12 || temp > 21) | |
4828 | as_bad (_("Value for ENTRY_FR must be in the range 12..21\n")); | |
4829 | last_call_info->ci_unwind.descriptor.entry_fr = temp - 11; | |
4830 | } | |
4831 | else if ((strncasecmp (name, "entry_sr", 8) == 0)) | |
4832 | { | |
4833 | p = input_line_pointer; | |
4834 | *p = c; | |
4835 | input_line_pointer++; | |
4836 | temp = get_absolute_expression (); | |
4837 | if (temp != 3) | |
4838 | as_bad (_("Value for ENTRY_SR must be 3\n")); | |
4839 | } | |
4840 | /* Note whether or not this function performs any calls. */ | |
4841 | else if ((strncasecmp (name, "calls", 5) == 0) || | |
4842 | (strncasecmp (name, "caller", 6) == 0)) | |
4843 | { | |
4844 | p = input_line_pointer; | |
4845 | *p = c; | |
4846 | } | |
4847 | else if ((strncasecmp (name, "no_calls", 8) == 0)) | |
4848 | { | |
4849 | p = input_line_pointer; | |
4850 | *p = c; | |
4851 | } | |
4852 | /* Should RP be saved into the stack. */ | |
4853 | else if ((strncasecmp (name, "save_rp", 7) == 0)) | |
4854 | { | |
4855 | p = input_line_pointer; | |
4856 | *p = c; | |
4857 | last_call_info->ci_unwind.descriptor.save_rp = 1; | |
4858 | } | |
4859 | /* Likewise for SP. */ | |
4860 | else if ((strncasecmp (name, "save_sp", 7) == 0)) | |
4861 | { | |
4862 | p = input_line_pointer; | |
4863 | *p = c; | |
4864 | last_call_info->ci_unwind.descriptor.save_sp = 1; | |
4865 | } | |
4866 | /* Is this an unwindable procedure. If so mark it so | |
4867 | in the unwind descriptor. */ | |
4868 | else if ((strncasecmp (name, "no_unwind", 9) == 0)) | |
4869 | { | |
4870 | p = input_line_pointer; | |
4871 | *p = c; | |
4872 | last_call_info->ci_unwind.descriptor.cannot_unwind = 1; | |
4873 | } | |
4874 | /* Is this an interrupt routine. If so mark it in the | |
4875 | unwind descriptor. */ | |
4876 | else if ((strncasecmp (name, "hpux_int", 7) == 0)) | |
4877 | { | |
4878 | p = input_line_pointer; | |
4879 | *p = c; | |
4880 | last_call_info->ci_unwind.descriptor.hpux_interrupt_marker = 1; | |
4881 | } | |
4882 | /* Is this a millicode routine. "millicode" isn't in my | |
4883 | assembler manual, but my copy is old. The HP assembler | |
4884 | accepts it, and there's a place in the unwind descriptor | |
4885 | to drop the information, so we'll accept it too. */ | |
4886 | else if ((strncasecmp (name, "millicode", 9) == 0)) | |
4887 | { | |
4888 | p = input_line_pointer; | |
4889 | *p = c; | |
4890 | last_call_info->ci_unwind.descriptor.millicode = 1; | |
4891 | } | |
4892 | else | |
4893 | { | |
4894 | as_bad (_("Invalid .CALLINFO argument: %s"), name); | |
4895 | *input_line_pointer = c; | |
4896 | } | |
4897 | if (!is_end_of_statement ()) | |
4898 | input_line_pointer++; | |
4899 | } | |
4900 | ||
4901 | demand_empty_rest_of_line (); | |
4902 | } | |
4903 | ||
4904 | /* Switch into the code subspace. */ | |
4905 | ||
4906 | static void | |
4907 | pa_code (unused) | |
4908 | int unused; | |
4909 | { | |
49863f82 | 4910 | #ifdef OBJ_SOM |
252b5132 RH |
4911 | current_space = is_defined_space ("$TEXT$"); |
4912 | current_subspace | |
4913 | = pa_subsegment_to_subspace (current_space->sd_seg, 0); | |
49863f82 | 4914 | #endif |
252b5132 RH |
4915 | s_text (0); |
4916 | pa_undefine_label (); | |
4917 | } | |
4918 | ||
4919 | /* This is different than the standard GAS s_comm(). On HP9000/800 machines, | |
4920 | the .comm pseudo-op has the following symtax: | |
4921 | ||
4922 | <label> .comm <length> | |
4923 | ||
4924 | where <label> is optional and is a symbol whose address will be the start of | |
4925 | a block of memory <length> bytes long. <length> must be an absolute | |
4926 | expression. <length> bytes will be allocated in the current space | |
4927 | and subspace. | |
4928 | ||
4929 | Also note the label may not even be on the same line as the .comm. | |
4930 | ||
4931 | This difference in syntax means the colon function will be called | |
4932 | on the symbol before we arrive in pa_comm. colon will set a number | |
4933 | of attributes of the symbol that need to be fixed here. In particular | |
4934 | the value, section pointer, fragment pointer, flags, etc. What | |
4935 | a pain. | |
4936 | ||
4937 | This also makes error detection all but impossible. */ | |
4938 | ||
4939 | static void | |
4940 | pa_comm (unused) | |
4941 | int unused; | |
4942 | { | |
4943 | unsigned int size; | |
4944 | symbolS *symbol; | |
4945 | label_symbol_struct *label_symbol = pa_get_label (); | |
4946 | ||
4947 | if (label_symbol) | |
4948 | symbol = label_symbol->lss_label; | |
4949 | else | |
4950 | symbol = NULL; | |
4951 | ||
4952 | SKIP_WHITESPACE (); | |
4953 | size = get_absolute_expression (); | |
4954 | ||
4955 | if (symbol) | |
4956 | { | |
4957 | S_SET_VALUE (symbol, size); | |
4958 | S_SET_SEGMENT (symbol, bfd_und_section_ptr); | |
4959 | S_SET_EXTERNAL (symbol); | |
4960 | ||
4961 | /* colon() has already set the frag to the current location in the | |
4962 | current subspace; we need to reset the fragment to the zero address | |
4963 | fragment. We also need to reset the segment pointer. */ | |
a0f75b47 | 4964 | symbol_set_frag (symbol, &zero_address_frag); |
252b5132 RH |
4965 | } |
4966 | demand_empty_rest_of_line (); | |
4967 | } | |
4968 | ||
4969 | /* Process a .END pseudo-op. */ | |
4970 | ||
4971 | static void | |
4972 | pa_end (unused) | |
4973 | int unused; | |
4974 | { | |
4975 | demand_empty_rest_of_line (); | |
4976 | } | |
4977 | ||
4978 | /* Process a .ENTER pseudo-op. This is not supported. */ | |
4979 | static void | |
4980 | pa_enter (unused) | |
4981 | int unused; | |
4982 | { | |
49863f82 | 4983 | #ifdef OBJ_SOM |
252b5132 RH |
4984 | /* We must have a valid space and subspace. */ |
4985 | pa_check_current_space_and_subspace (); | |
49863f82 | 4986 | #endif |
252b5132 RH |
4987 | |
4988 | as_bad (_("The .ENTER pseudo-op is not supported")); | |
4989 | demand_empty_rest_of_line (); | |
4990 | } | |
4991 | ||
4992 | /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the | |
4993 | procesure. */ | |
4994 | static void | |
4995 | pa_entry (unused) | |
4996 | int unused; | |
4997 | { | |
49863f82 | 4998 | #ifdef OBJ_SOM |
252b5132 RH |
4999 | /* We must have a valid space and subspace. */ |
5000 | pa_check_current_space_and_subspace (); | |
49863f82 | 5001 | #endif |
252b5132 RH |
5002 | |
5003 | if (!within_procedure) | |
5004 | as_bad (_("Misplaced .entry. Ignored.")); | |
5005 | else | |
5006 | { | |
5007 | if (!callinfo_found) | |
5008 | as_bad (_("Missing .callinfo.")); | |
5009 | } | |
5010 | demand_empty_rest_of_line (); | |
5011 | within_entry_exit = TRUE; | |
5012 | ||
5013 | #ifdef OBJ_SOM | |
5014 | /* SOM defers building of unwind descriptors until the link phase. | |
5015 | The assembler is responsible for creating an R_ENTRY relocation | |
5016 | to mark the beginning of a region and hold the unwind bits, and | |
5017 | for creating an R_EXIT relocation to mark the end of the region. | |
5018 | ||
5019 | FIXME. ELF should be using the same conventions! The problem | |
5020 | is an unwind requires too much relocation space. Hmmm. Maybe | |
5021 | if we split the unwind bits up between the relocations which | |
5022 | denote the entry and exit points. */ | |
5023 | if (last_call_info->start_symbol != NULL) | |
5024 | { | |
5025 | char *where = frag_more (0); | |
5026 | ||
5027 | fix_new_hppa (frag_now, where - frag_now->fr_literal, 0, | |
5028 | NULL, (offsetT) 0, NULL, | |
5029 | 0, R_HPPA_ENTRY, e_fsel, 0, 0, | |
5030 | (int *) &last_call_info->ci_unwind.descriptor); | |
5031 | } | |
5032 | #endif | |
5033 | } | |
5034 | ||
5035 | /* Handle a .EQU pseudo-op. */ | |
5036 | ||
5037 | static void | |
5038 | pa_equ (reg) | |
5039 | int reg; | |
5040 | { | |
5041 | label_symbol_struct *label_symbol = pa_get_label (); | |
5042 | symbolS *symbol; | |
5043 | ||
5044 | if (label_symbol) | |
5045 | { | |
5046 | symbol = label_symbol->lss_label; | |
5047 | if (reg) | |
5048 | S_SET_VALUE (symbol, pa_parse_number (&input_line_pointer, 0)); | |
5049 | else | |
5050 | S_SET_VALUE (symbol, (unsigned int) get_absolute_expression ()); | |
5051 | S_SET_SEGMENT (symbol, bfd_abs_section_ptr); | |
5052 | } | |
5053 | else | |
5054 | { | |
5055 | if (reg) | |
5056 | as_bad (_(".REG must use a label")); | |
5057 | else | |
5058 | as_bad (_(".EQU must use a label")); | |
5059 | } | |
5060 | ||
5061 | pa_undefine_label (); | |
5062 | demand_empty_rest_of_line (); | |
5063 | } | |
5064 | ||
5065 | /* Helper function. Does processing for the end of a function. This | |
5066 | usually involves creating some relocations or building special | |
5067 | symbols to mark the end of the function. */ | |
5068 | ||
5069 | static void | |
5070 | process_exit () | |
5071 | { | |
5072 | char *where; | |
5073 | ||
5074 | where = frag_more (0); | |
5075 | ||
5076 | #ifdef OBJ_ELF | |
5077 | /* Mark the end of the function, stuff away the location of the frag | |
5078 | for the end of the function, and finally call pa_build_unwind_subspace | |
5079 | to add an entry in the unwind table. */ | |
5080 | hppa_elf_mark_end_of_function (); | |
5081 | pa_build_unwind_subspace (last_call_info); | |
5082 | #else | |
5083 | /* SOM defers building of unwind descriptors until the link phase. | |
5084 | The assembler is responsible for creating an R_ENTRY relocation | |
5085 | to mark the beginning of a region and hold the unwind bits, and | |
5086 | for creating an R_EXIT relocation to mark the end of the region. | |
5087 | ||
5088 | FIXME. ELF should be using the same conventions! The problem | |
5089 | is an unwind requires too much relocation space. Hmmm. Maybe | |
5090 | if we split the unwind bits up between the relocations which | |
5091 | denote the entry and exit points. */ | |
5092 | fix_new_hppa (frag_now, where - frag_now->fr_literal, 0, | |
5093 | NULL, (offsetT) 0, | |
5094 | NULL, 0, R_HPPA_EXIT, e_fsel, 0, 0, | |
5095 | (int *) &last_call_info->ci_unwind.descriptor + 1); | |
5096 | #endif | |
5097 | } | |
5098 | ||
5099 | /* Process a .EXIT pseudo-op. */ | |
5100 | ||
5101 | static void | |
5102 | pa_exit (unused) | |
5103 | int unused; | |
5104 | { | |
49863f82 | 5105 | #ifdef OBJ_SOM |
252b5132 RH |
5106 | /* We must have a valid space and subspace. */ |
5107 | pa_check_current_space_and_subspace (); | |
49863f82 | 5108 | #endif |
252b5132 RH |
5109 | |
5110 | if (!within_procedure) | |
5111 | as_bad (_(".EXIT must appear within a procedure")); | |
5112 | else | |
5113 | { | |
5114 | if (!callinfo_found) | |
5115 | as_bad (_("Missing .callinfo")); | |
5116 | else | |
5117 | { | |
5118 | if (!within_entry_exit) | |
5119 | as_bad (_("No .ENTRY for this .EXIT")); | |
5120 | else | |
5121 | { | |
5122 | within_entry_exit = FALSE; | |
5123 | process_exit (); | |
5124 | } | |
5125 | } | |
5126 | } | |
5127 | demand_empty_rest_of_line (); | |
5128 | } | |
5129 | ||
5130 | /* Process a .EXPORT directive. This makes functions external | |
5131 | and provides information such as argument relocation entries | |
5132 | to callers. */ | |
5133 | ||
5134 | static void | |
5135 | pa_export (unused) | |
5136 | int unused; | |
5137 | { | |
5138 | char *name, c, *p; | |
5139 | symbolS *symbol; | |
5140 | ||
5141 | name = input_line_pointer; | |
5142 | c = get_symbol_end (); | |
5143 | /* Make sure the given symbol exists. */ | |
5144 | if ((symbol = symbol_find_or_make (name)) == NULL) | |
5145 | { | |
5146 | as_bad (_("Cannot define export symbol: %s\n"), name); | |
5147 | p = input_line_pointer; | |
5148 | *p = c; | |
5149 | input_line_pointer++; | |
5150 | } | |
5151 | else | |
5152 | { | |
5153 | /* OK. Set the external bits and process argument relocations. */ | |
5154 | S_SET_EXTERNAL (symbol); | |
5155 | p = input_line_pointer; | |
5156 | *p = c; | |
5157 | if (!is_end_of_statement ()) | |
5158 | { | |
5159 | input_line_pointer++; | |
5160 | pa_type_args (symbol, 1); | |
5161 | } | |
5162 | } | |
5163 | ||
5164 | demand_empty_rest_of_line (); | |
5165 | } | |
5166 | ||
5167 | /* Helper function to process arguments to a .EXPORT pseudo-op. */ | |
5168 | ||
5169 | static void | |
5170 | pa_type_args (symbolP, is_export) | |
5171 | symbolS *symbolP; | |
5172 | int is_export; | |
5173 | { | |
5174 | char *name, c, *p; | |
5175 | unsigned int temp, arg_reloc; | |
5176 | pa_symbol_type type = SYMBOL_TYPE_UNKNOWN; | |
a0f75b47 | 5177 | obj_symbol_type *symbol = (obj_symbol_type *) symbol_get_bfdsym (symbolP); |
252b5132 RH |
5178 | |
5179 | if (strncasecmp (input_line_pointer, "absolute", 8) == 0) | |
5180 | ||
5181 | { | |
5182 | input_line_pointer += 8; | |
a0f75b47 | 5183 | symbol_get_bfdsym (symbolP)->flags &= ~BSF_FUNCTION; |
252b5132 RH |
5184 | S_SET_SEGMENT (symbolP, bfd_abs_section_ptr); |
5185 | type = SYMBOL_TYPE_ABSOLUTE; | |
5186 | } | |
5187 | else if (strncasecmp (input_line_pointer, "code", 4) == 0) | |
5188 | { | |
5189 | input_line_pointer += 4; | |
5190 | /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM, | |
5191 | instead one should be IMPORTing/EXPORTing ENTRY types. | |
5192 | ||
5193 | Complain if one tries to EXPORT a CODE type since that's never | |
5194 | done. Both GCC and HP C still try to IMPORT CODE types, so | |
5195 | silently fix them to be ENTRY types. */ | |
a0f75b47 | 5196 | if (S_IS_FUNCTION (symbolP)) |
252b5132 RH |
5197 | { |
5198 | if (is_export) | |
a0f75b47 ILT |
5199 | as_tsktsk (_("Using ENTRY rather than CODE in export directive for %s"), |
5200 | S_GET_NAME (symbolP)); | |
252b5132 | 5201 | |
a0f75b47 | 5202 | symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION; |
252b5132 RH |
5203 | type = SYMBOL_TYPE_ENTRY; |
5204 | } | |
5205 | else | |
5206 | { | |
a0f75b47 | 5207 | symbol_get_bfdsym (symbolP)->flags &= ~BSF_FUNCTION; |
252b5132 RH |
5208 | type = SYMBOL_TYPE_CODE; |
5209 | } | |
5210 | } | |
5211 | else if (strncasecmp (input_line_pointer, "data", 4) == 0) | |
5212 | { | |
5213 | input_line_pointer += 4; | |
a0f75b47 | 5214 | symbol_get_bfdsym (symbolP)->flags &= ~BSF_FUNCTION; |
252b5132 RH |
5215 | type = SYMBOL_TYPE_DATA; |
5216 | } | |
5217 | else if ((strncasecmp (input_line_pointer, "entry", 5) == 0)) | |
5218 | { | |
5219 | input_line_pointer += 5; | |
a0f75b47 | 5220 | symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION; |
252b5132 RH |
5221 | type = SYMBOL_TYPE_ENTRY; |
5222 | } | |
5223 | else if (strncasecmp (input_line_pointer, "millicode", 9) == 0) | |
5224 | { | |
5225 | input_line_pointer += 9; | |
a0f75b47 | 5226 | symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION; |
252b5132 RH |
5227 | type = SYMBOL_TYPE_MILLICODE; |
5228 | } | |
5229 | else if (strncasecmp (input_line_pointer, "plabel", 6) == 0) | |
5230 | { | |
5231 | input_line_pointer += 6; | |
a0f75b47 | 5232 | symbol_get_bfdsym (symbolP)->flags &= ~BSF_FUNCTION; |
252b5132 RH |
5233 | type = SYMBOL_TYPE_PLABEL; |
5234 | } | |
5235 | else if (strncasecmp (input_line_pointer, "pri_prog", 8) == 0) | |
5236 | { | |
5237 | input_line_pointer += 8; | |
a0f75b47 | 5238 | symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION; |
252b5132 RH |
5239 | type = SYMBOL_TYPE_PRI_PROG; |
5240 | } | |
5241 | else if (strncasecmp (input_line_pointer, "sec_prog", 8) == 0) | |
5242 | { | |
5243 | input_line_pointer += 8; | |
a0f75b47 | 5244 | symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION; |
252b5132 RH |
5245 | type = SYMBOL_TYPE_SEC_PROG; |
5246 | } | |
5247 | ||
5248 | /* SOM requires much more information about symbol types | |
5249 | than BFD understands. This is how we get this information | |
5250 | to the SOM BFD backend. */ | |
5251 | #ifdef obj_set_symbol_type | |
a0f75b47 | 5252 | obj_set_symbol_type (symbol_get_bfdsym (symbolP), (int) type); |
252b5132 RH |
5253 | #endif |
5254 | ||
5255 | /* Now that the type of the exported symbol has been handled, | |
5256 | handle any argument relocation information. */ | |
5257 | while (!is_end_of_statement ()) | |
5258 | { | |
5259 | if (*input_line_pointer == ',') | |
5260 | input_line_pointer++; | |
5261 | name = input_line_pointer; | |
5262 | c = get_symbol_end (); | |
5263 | /* Argument sources. */ | |
5264 | if ((strncasecmp (name, "argw", 4) == 0)) | |
5265 | { | |
5266 | p = input_line_pointer; | |
5267 | *p = c; | |
5268 | input_line_pointer++; | |
5269 | temp = atoi (name + 4); | |
5270 | name = input_line_pointer; | |
5271 | c = get_symbol_end (); | |
5272 | arg_reloc = pa_align_arg_reloc (temp, pa_build_arg_reloc (name)); | |
49863f82 | 5273 | #ifdef OBJ_SOM |
252b5132 | 5274 | symbol->tc_data.ap.hppa_arg_reloc |= arg_reloc; |
49863f82 | 5275 | #endif |
252b5132 RH |
5276 | *input_line_pointer = c; |
5277 | } | |
5278 | /* The return value. */ | |
5279 | else if ((strncasecmp (name, "rtnval", 6)) == 0) | |
5280 | { | |
5281 | p = input_line_pointer; | |
5282 | *p = c; | |
5283 | input_line_pointer++; | |
5284 | name = input_line_pointer; | |
5285 | c = get_symbol_end (); | |
5286 | arg_reloc = pa_build_arg_reloc (name); | |
49863f82 | 5287 | #ifdef OBJ_SOM |
252b5132 | 5288 | symbol->tc_data.ap.hppa_arg_reloc |= arg_reloc; |
49863f82 | 5289 | #endif |
252b5132 RH |
5290 | *input_line_pointer = c; |
5291 | } | |
5292 | /* Privelege level. */ | |
5293 | else if ((strncasecmp (name, "priv_lev", 8)) == 0) | |
5294 | { | |
5295 | p = input_line_pointer; | |
5296 | *p = c; | |
5297 | input_line_pointer++; | |
5298 | temp = atoi (input_line_pointer); | |
49863f82 | 5299 | #ifdef OBJ_SOM |
252b5132 | 5300 | symbol->tc_data.ap.hppa_priv_level = temp; |
49863f82 | 5301 | #endif |
252b5132 RH |
5302 | c = get_symbol_end (); |
5303 | *input_line_pointer = c; | |
5304 | } | |
5305 | else | |
5306 | { | |
5307 | as_bad (_("Undefined .EXPORT/.IMPORT argument (ignored): %s"), name); | |
5308 | p = input_line_pointer; | |
5309 | *p = c; | |
5310 | } | |
5311 | if (!is_end_of_statement ()) | |
5312 | input_line_pointer++; | |
5313 | } | |
5314 | } | |
5315 | ||
5316 | /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given | |
5317 | assembly file must either be defined in the assembly file, or | |
5318 | explicitly IMPORTED from another. */ | |
5319 | ||
5320 | static void | |
5321 | pa_import (unused) | |
5322 | int unused; | |
5323 | { | |
5324 | char *name, c, *p; | |
5325 | symbolS *symbol; | |
5326 | ||
5327 | name = input_line_pointer; | |
5328 | c = get_symbol_end (); | |
5329 | ||
5330 | symbol = symbol_find (name); | |
5331 | /* Ugh. We might be importing a symbol defined earlier in the file, | |
5332 | in which case all the code below will really screw things up | |
5333 | (set the wrong segment, symbol flags & type, etc). */ | |
5334 | if (symbol == NULL || !S_IS_DEFINED (symbol)) | |
5335 | { | |
5336 | symbol = symbol_find_or_make (name); | |
5337 | p = input_line_pointer; | |
5338 | *p = c; | |
5339 | ||
5340 | if (!is_end_of_statement ()) | |
5341 | { | |
5342 | input_line_pointer++; | |
5343 | pa_type_args (symbol, 0); | |
5344 | } | |
5345 | else | |
5346 | { | |
5347 | /* Sigh. To be compatable with the HP assembler and to help | |
5348 | poorly written assembly code, we assign a type based on | |
5349 | the the current segment. Note only BSF_FUNCTION really | |
5350 | matters, we do not need to set the full SYMBOL_TYPE_* info. */ | |
5351 | if (now_seg == text_section) | |
a0f75b47 | 5352 | symbol_get_bfdsym (symbol)->flags |= BSF_FUNCTION; |
252b5132 RH |
5353 | |
5354 | /* If the section is undefined, then the symbol is undefined | |
5355 | Since this is an import, leave the section undefined. */ | |
5356 | S_SET_SEGMENT (symbol, bfd_und_section_ptr); | |
5357 | } | |
5358 | } | |
5359 | else | |
5360 | { | |
5361 | /* The symbol was already defined. Just eat everything up to | |
5362 | the end of the current statement. */ | |
5363 | while (!is_end_of_statement ()) | |
5364 | input_line_pointer++; | |
5365 | } | |
5366 | ||
5367 | demand_empty_rest_of_line (); | |
5368 | } | |
5369 | ||
5370 | /* Handle a .LABEL pseudo-op. */ | |
5371 | ||
5372 | static void | |
5373 | pa_label (unused) | |
5374 | int unused; | |
5375 | { | |
5376 | char *name, c, *p; | |
5377 | ||
5378 | name = input_line_pointer; | |
5379 | c = get_symbol_end (); | |
5380 | ||
5381 | if (strlen (name) > 0) | |
5382 | { | |
5383 | colon (name); | |
5384 | p = input_line_pointer; | |
5385 | *p = c; | |
5386 | } | |
5387 | else | |
5388 | { | |
5389 | as_warn (_("Missing label name on .LABEL")); | |
5390 | } | |
5391 | ||
5392 | if (!is_end_of_statement ()) | |
5393 | { | |
5394 | as_warn (_("extra .LABEL arguments ignored.")); | |
5395 | ignore_rest_of_line (); | |
5396 | } | |
5397 | demand_empty_rest_of_line (); | |
5398 | } | |
5399 | ||
5400 | /* Handle a .LEAVE pseudo-op. This is not supported yet. */ | |
5401 | ||
5402 | static void | |
5403 | pa_leave (unused) | |
5404 | int unused; | |
5405 | { | |
49863f82 | 5406 | #ifdef OBJ_SOM |
252b5132 RH |
5407 | /* We must have a valid space and subspace. */ |
5408 | pa_check_current_space_and_subspace (); | |
49863f82 | 5409 | #endif |
252b5132 RH |
5410 | |
5411 | as_bad (_("The .LEAVE pseudo-op is not supported")); | |
5412 | demand_empty_rest_of_line (); | |
5413 | } | |
5414 | ||
5415 | /* Handle a .LEVEL pseudo-op. */ | |
5416 | ||
5417 | static void | |
5418 | pa_level (unused) | |
5419 | int unused; | |
5420 | { | |
5421 | char *level; | |
5422 | ||
5423 | level = input_line_pointer; | |
5424 | if (strncmp (level, "1.0", 3) == 0) | |
5425 | { | |
5426 | input_line_pointer += 3; | |
5427 | if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 10)) | |
5428 | as_warn (_("could not set architecture and machine")); | |
5429 | } | |
5430 | else if (strncmp (level, "1.1", 3) == 0) | |
5431 | { | |
5432 | input_line_pointer += 3; | |
5433 | if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 11)) | |
5434 | as_warn (_("could not set architecture and machine")); | |
5435 | } | |
46031ca9 JL |
5436 | else if (strncmp (level, "2.0w", 4) == 0) |
5437 | { | |
5438 | input_line_pointer += 4; | |
5439 | if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 25)) | |
5440 | as_warn (_("could not set architecture and machine")); | |
5441 | } | |
252b5132 RH |
5442 | else if (strncmp (level, "2.0", 3) == 0) |
5443 | { | |
5444 | input_line_pointer += 3; | |
5445 | if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 20)) | |
5446 | as_warn (_("could not set architecture and machine")); | |
5447 | } | |
5448 | else | |
5449 | { | |
5450 | as_bad (_("Unrecognized .LEVEL argument\n")); | |
5451 | ignore_rest_of_line (); | |
5452 | } | |
5453 | demand_empty_rest_of_line (); | |
5454 | } | |
5455 | ||
5456 | /* Handle a .ORIGIN pseudo-op. */ | |
5457 | ||
5458 | static void | |
5459 | pa_origin (unused) | |
5460 | int unused; | |
5461 | { | |
49863f82 | 5462 | #ifdef OBJ_SOM |
252b5132 RH |
5463 | /* We must have a valid space and subspace. */ |
5464 | pa_check_current_space_and_subspace (); | |
49863f82 | 5465 | #endif |
252b5132 RH |
5466 | |
5467 | s_org (0); | |
5468 | pa_undefine_label (); | |
5469 | } | |
5470 | ||
5471 | /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it | |
5472 | is for static functions. FIXME. Should share more code with .EXPORT. */ | |
5473 | ||
5474 | static void | |
5475 | pa_param (unused) | |
5476 | int unused; | |
5477 | { | |
5478 | char *name, c, *p; | |
5479 | symbolS *symbol; | |
5480 | ||
5481 | name = input_line_pointer; | |
5482 | c = get_symbol_end (); | |
5483 | ||
5484 | if ((symbol = symbol_find_or_make (name)) == NULL) | |
5485 | { | |
5486 | as_bad (_("Cannot define static symbol: %s\n"), name); | |
5487 | p = input_line_pointer; | |
5488 | *p = c; | |
5489 | input_line_pointer++; | |
5490 | } | |
5491 | else | |
5492 | { | |
5493 | S_CLEAR_EXTERNAL (symbol); | |
5494 | p = input_line_pointer; | |
5495 | *p = c; | |
5496 | if (!is_end_of_statement ()) | |
5497 | { | |
5498 | input_line_pointer++; | |
5499 | pa_type_args (symbol, 0); | |
5500 | } | |
5501 | } | |
5502 | ||
5503 | demand_empty_rest_of_line (); | |
5504 | } | |
5505 | ||
5506 | /* Handle a .PROC pseudo-op. It is used to mark the beginning | |
5507 | of a procedure from a syntatical point of view. */ | |
5508 | ||
5509 | static void | |
5510 | pa_proc (unused) | |
5511 | int unused; | |
5512 | { | |
5513 | struct call_info *call_info; | |
5514 | ||
49863f82 | 5515 | #ifdef OBJ_SOM |
252b5132 RH |
5516 | /* We must have a valid space and subspace. */ |
5517 | pa_check_current_space_and_subspace (); | |
49863f82 | 5518 | #endif |
252b5132 RH |
5519 | |
5520 | if (within_procedure) | |
5521 | as_fatal (_("Nested procedures")); | |
5522 | ||
5523 | /* Reset global variables for new procedure. */ | |
5524 | callinfo_found = FALSE; | |
5525 | within_procedure = TRUE; | |
5526 | ||
5527 | /* Create another call_info structure. */ | |
5528 | call_info = (struct call_info *) xmalloc (sizeof (struct call_info)); | |
5529 | ||
5530 | if (!call_info) | |
5531 | as_fatal (_("Cannot allocate unwind descriptor\n")); | |
5532 | ||
5533 | memset (call_info, 0, sizeof (struct call_info)); | |
5534 | ||
5535 | call_info->ci_next = NULL; | |
5536 | ||
5537 | if (call_info_root == NULL) | |
5538 | { | |
5539 | call_info_root = call_info; | |
5540 | last_call_info = call_info; | |
5541 | } | |
5542 | else | |
5543 | { | |
5544 | last_call_info->ci_next = call_info; | |
5545 | last_call_info = call_info; | |
5546 | } | |
5547 | ||
5548 | /* set up defaults on call_info structure */ | |
5549 | ||
5550 | call_info->ci_unwind.descriptor.cannot_unwind = 0; | |
5551 | call_info->ci_unwind.descriptor.region_desc = 1; | |
5552 | call_info->ci_unwind.descriptor.hpux_interrupt_marker = 0; | |
5553 | ||
5554 | /* If we got a .PROC pseudo-op, we know that the function is defined | |
5555 | locally. Make sure it gets into the symbol table. */ | |
5556 | { | |
5557 | label_symbol_struct *label_symbol = pa_get_label (); | |
5558 | ||
5559 | if (label_symbol) | |
5560 | { | |
5561 | if (label_symbol->lss_label) | |
5562 | { | |
5563 | last_call_info->start_symbol = label_symbol->lss_label; | |
a0f75b47 | 5564 | symbol_get_bfdsym (label_symbol->lss_label)->flags |= BSF_FUNCTION; |
252b5132 RH |
5565 | } |
5566 | else | |
5567 | as_bad (_("Missing function name for .PROC (corrupted label chain)")); | |
5568 | } | |
5569 | else | |
5570 | last_call_info->start_symbol = NULL; | |
5571 | } | |
5572 | ||
5573 | demand_empty_rest_of_line (); | |
5574 | } | |
5575 | ||
5576 | /* Process the syntatical end of a procedure. Make sure all the | |
5577 | appropriate pseudo-ops were found within the procedure. */ | |
5578 | ||
5579 | static void | |
5580 | pa_procend (unused) | |
5581 | int unused; | |
5582 | { | |
5583 | ||
49863f82 | 5584 | #ifdef OBJ_SOM |
252b5132 RH |
5585 | /* We must have a valid space and subspace. */ |
5586 | pa_check_current_space_and_subspace (); | |
49863f82 | 5587 | #endif |
252b5132 RH |
5588 | |
5589 | /* If we are within a procedure definition, make sure we've | |
5590 | defined a label for the procedure; handle case where the | |
5591 | label was defined after the .PROC directive. | |
5592 | ||
5593 | Note there's not need to diddle with the segment or fragment | |
5594 | for the label symbol in this case. We have already switched | |
5595 | into the new $CODE$ subspace at this point. */ | |
5596 | if (within_procedure && last_call_info->start_symbol == NULL) | |
5597 | { | |
5598 | label_symbol_struct *label_symbol = pa_get_label (); | |
5599 | ||
5600 | if (label_symbol) | |
5601 | { | |
5602 | if (label_symbol->lss_label) | |
5603 | { | |
5604 | last_call_info->start_symbol = label_symbol->lss_label; | |
a0f75b47 ILT |
5605 | symbol_get_bfdsym (label_symbol->lss_label)->flags |
5606 | |= BSF_FUNCTION; | |
252b5132 RH |
5607 | #ifdef OBJ_SOM |
5608 | /* Also handle allocation of a fixup to hold the unwind | |
5609 | information when the label appears after the proc/procend. */ | |
5610 | if (within_entry_exit) | |
5611 | { | |
5612 | char *where = frag_more (0); | |
5613 | ||
5614 | fix_new_hppa (frag_now, where - frag_now->fr_literal, 0, | |
5615 | NULL, (offsetT) 0, NULL, | |
5616 | 0, R_HPPA_ENTRY, e_fsel, 0, 0, | |
5617 | (int *) &last_call_info->ci_unwind.descriptor); | |
5618 | } | |
5619 | #endif | |
5620 | } | |
5621 | else | |
5622 | as_bad (_("Missing function name for .PROC (corrupted label chain)")); | |
5623 | } | |
5624 | else | |
5625 | as_bad (_("Missing function name for .PROC")); | |
5626 | } | |
5627 | ||
5628 | if (!within_procedure) | |
5629 | as_bad (_("misplaced .procend")); | |
5630 | ||
5631 | if (!callinfo_found) | |
5632 | as_bad (_("Missing .callinfo for this procedure")); | |
5633 | ||
5634 | if (within_entry_exit) | |
5635 | as_bad (_("Missing .EXIT for a .ENTRY")); | |
5636 | ||
5637 | #ifdef OBJ_ELF | |
5638 | /* ELF needs to mark the end of each function so that it can compute | |
5639 | the size of the function (apparently its needed in the symbol table). */ | |
5640 | hppa_elf_mark_end_of_function (); | |
5641 | #endif | |
5642 | ||
5643 | within_procedure = FALSE; | |
5644 | demand_empty_rest_of_line (); | |
5645 | pa_undefine_label (); | |
5646 | } | |
5647 | ||
49863f82 JL |
5648 | /* If VALUE is an exact power of two between zero and 2^31, then |
5649 | return log2 (VALUE). Else return -1. */ | |
5650 | ||
5651 | static int | |
5652 | log2 (value) | |
5653 | int value; | |
5654 | { | |
5655 | int shift = 0; | |
5656 | ||
5657 | while ((1 << shift) != value && shift < 32) | |
5658 | shift++; | |
5659 | ||
5660 | if (shift >= 32) | |
5661 | return -1; | |
5662 | else | |
5663 | return shift; | |
5664 | } | |
5665 | ||
5666 | ||
5667 | #ifdef OBJ_SOM | |
5668 | /* Check to make sure we have a valid space and subspace. */ | |
5669 | ||
5670 | static void | |
5671 | pa_check_current_space_and_subspace () | |
5672 | { | |
5673 | if (current_space == NULL) | |
5674 | as_fatal (_("Not in a space.\n")); | |
5675 | ||
5676 | if (current_subspace == NULL) | |
5677 | as_fatal (_("Not in a subspace.\n")); | |
5678 | } | |
5679 | ||
252b5132 RH |
5680 | /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero, |
5681 | then create a new space entry to hold the information specified | |
5682 | by the parameters to the .SPACE directive. */ | |
5683 | ||
5684 | static sd_chain_struct * | |
5685 | pa_parse_space_stmt (space_name, create_flag) | |
5686 | char *space_name; | |
5687 | int create_flag; | |
5688 | { | |
5689 | char *name, *ptemp, c; | |
5690 | char loadable, defined, private, sort; | |
5691 | int spnum, temp; | |
5692 | asection *seg = NULL; | |
5693 | sd_chain_struct *space; | |
5694 | ||
5695 | /* load default values */ | |
5696 | spnum = 0; | |
5697 | sort = 0; | |
5698 | loadable = TRUE; | |
5699 | defined = TRUE; | |
5700 | private = FALSE; | |
5701 | if (strcmp (space_name, "$TEXT$") == 0) | |
5702 | { | |
5703 | seg = pa_def_spaces[0].segment; | |
5704 | defined = pa_def_spaces[0].defined; | |
5705 | private = pa_def_spaces[0].private; | |
5706 | sort = pa_def_spaces[0].sort; | |
5707 | spnum = pa_def_spaces[0].spnum; | |
5708 | } | |
5709 | else if (strcmp (space_name, "$PRIVATE$") == 0) | |
5710 | { | |
5711 | seg = pa_def_spaces[1].segment; | |
5712 | defined = pa_def_spaces[1].defined; | |
5713 | private = pa_def_spaces[1].private; | |
5714 | sort = pa_def_spaces[1].sort; | |
5715 | spnum = pa_def_spaces[1].spnum; | |
5716 | } | |
5717 | ||
5718 | if (!is_end_of_statement ()) | |
5719 | { | |
5720 | print_errors = FALSE; | |
5721 | ptemp = input_line_pointer + 1; | |
5722 | /* First see if the space was specified as a number rather than | |
5723 | as a name. According to the PA assembly manual the rest of | |
5724 | the line should be ignored. */ | |
5725 | temp = pa_parse_number (&ptemp, 0); | |
5726 | if (temp >= 0) | |
5727 | { | |
5728 | spnum = temp; | |
5729 | input_line_pointer = ptemp; | |
5730 | } | |
5731 | else | |
5732 | { | |
5733 | while (!is_end_of_statement ()) | |
5734 | { | |
5735 | input_line_pointer++; | |
5736 | name = input_line_pointer; | |
5737 | c = get_symbol_end (); | |
5738 | if ((strncasecmp (name, "spnum", 5) == 0)) | |
5739 | { | |
5740 | *input_line_pointer = c; | |
5741 | input_line_pointer++; | |
5742 | spnum = get_absolute_expression (); | |
5743 | } | |
5744 | else if ((strncasecmp (name, "sort", 4) == 0)) | |
5745 | { | |
5746 | *input_line_pointer = c; | |
5747 | input_line_pointer++; | |
5748 | sort = get_absolute_expression (); | |
5749 | } | |
5750 | else if ((strncasecmp (name, "unloadable", 10) == 0)) | |
5751 | { | |
5752 | *input_line_pointer = c; | |
5753 | loadable = FALSE; | |
5754 | } | |
5755 | else if ((strncasecmp (name, "notdefined", 10) == 0)) | |
5756 | { | |
5757 | *input_line_pointer = c; | |
5758 | defined = FALSE; | |
5759 | } | |
5760 | else if ((strncasecmp (name, "private", 7) == 0)) | |
5761 | { | |
5762 | *input_line_pointer = c; | |
5763 | private = TRUE; | |
5764 | } | |
5765 | else | |
5766 | { | |
5767 | as_bad (_("Invalid .SPACE argument")); | |
5768 | *input_line_pointer = c; | |
5769 | if (!is_end_of_statement ()) | |
5770 | input_line_pointer++; | |
5771 | } | |
5772 | } | |
5773 | } | |
5774 | print_errors = TRUE; | |
5775 | } | |
5776 | ||
5777 | if (create_flag && seg == NULL) | |
5778 | seg = subseg_new (space_name, 0); | |
5779 | ||
5780 | /* If create_flag is nonzero, then create the new space with | |
5781 | the attributes computed above. Else set the values in | |
5782 | an already existing space -- this can only happen for | |
5783 | the first occurence of a built-in space. */ | |
5784 | if (create_flag) | |
5785 | space = create_new_space (space_name, spnum, loadable, defined, | |
5786 | private, sort, seg, 1); | |
5787 | else | |
5788 | { | |
5789 | space = is_defined_space (space_name); | |
5790 | SPACE_SPNUM (space) = spnum; | |
5791 | SPACE_DEFINED (space) = defined & 1; | |
5792 | SPACE_USER_DEFINED (space) = 1; | |
5793 | } | |
5794 | ||
5795 | #ifdef obj_set_section_attributes | |
5796 | obj_set_section_attributes (seg, defined, private, sort, spnum); | |
5797 | #endif | |
5798 | ||
5799 | return space; | |
5800 | } | |
5801 | ||
5802 | /* Handle a .SPACE pseudo-op; this switches the current space to the | |
5803 | given space, creating the new space if necessary. */ | |
5804 | ||
5805 | static void | |
5806 | pa_space (unused) | |
5807 | int unused; | |
5808 | { | |
5809 | char *name, c, *space_name, *save_s; | |
5810 | int temp; | |
5811 | sd_chain_struct *sd_chain; | |
5812 | ||
5813 | if (within_procedure) | |
5814 | { | |
5815 | as_bad (_("Can\'t change spaces within a procedure definition. Ignored")); | |
5816 | ignore_rest_of_line (); | |
5817 | } | |
5818 | else | |
5819 | { | |
5820 | /* Check for some of the predefined spaces. FIXME: most of the code | |
5821 | below is repeated several times, can we extract the common parts | |
5822 | and place them into a subroutine or something similar? */ | |
5823 | /* FIXME Is this (and the next IF stmt) really right? | |
5824 | What if INPUT_LINE_POINTER points to "$TEXT$FOO"? */ | |
5825 | if (strncmp (input_line_pointer, "$TEXT$", 6) == 0) | |
5826 | { | |
5827 | input_line_pointer += 6; | |
5828 | sd_chain = is_defined_space ("$TEXT$"); | |
5829 | if (sd_chain == NULL) | |
5830 | sd_chain = pa_parse_space_stmt ("$TEXT$", 1); | |
5831 | else if (SPACE_USER_DEFINED (sd_chain) == 0) | |
5832 | sd_chain = pa_parse_space_stmt ("$TEXT$", 0); | |
5833 | ||
5834 | current_space = sd_chain; | |
5835 | subseg_set (text_section, sd_chain->sd_last_subseg); | |
5836 | current_subspace | |
5837 | = pa_subsegment_to_subspace (text_section, | |
5838 | sd_chain->sd_last_subseg); | |
5839 | demand_empty_rest_of_line (); | |
5840 | return; | |
5841 | } | |
5842 | if (strncmp (input_line_pointer, "$PRIVATE$", 9) == 0) | |
5843 | { | |
5844 | input_line_pointer += 9; | |
5845 | sd_chain = is_defined_space ("$PRIVATE$"); | |
5846 | if (sd_chain == NULL) | |
5847 | sd_chain = pa_parse_space_stmt ("$PRIVATE$", 1); | |
5848 | else if (SPACE_USER_DEFINED (sd_chain) == 0) | |
5849 | sd_chain = pa_parse_space_stmt ("$PRIVATE$", 0); | |
5850 | ||
5851 | current_space = sd_chain; | |
5852 | subseg_set (data_section, sd_chain->sd_last_subseg); | |
5853 | current_subspace | |
5854 | = pa_subsegment_to_subspace (data_section, | |
5855 | sd_chain->sd_last_subseg); | |
5856 | demand_empty_rest_of_line (); | |
5857 | return; | |
5858 | } | |
5859 | if (!strncasecmp (input_line_pointer, | |
5860 | GDB_DEBUG_SPACE_NAME, | |
5861 | strlen (GDB_DEBUG_SPACE_NAME))) | |
5862 | { | |
5863 | input_line_pointer += strlen (GDB_DEBUG_SPACE_NAME); | |
5864 | sd_chain = is_defined_space (GDB_DEBUG_SPACE_NAME); | |
5865 | if (sd_chain == NULL) | |
5866 | sd_chain = pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME, 1); | |
5867 | else if (SPACE_USER_DEFINED (sd_chain) == 0) | |
5868 | sd_chain = pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME, 0); | |
5869 | ||
5870 | current_space = sd_chain; | |
5871 | ||
5872 | { | |
5873 | asection *gdb_section | |
5874 | = bfd_make_section_old_way (stdoutput, GDB_DEBUG_SPACE_NAME); | |
5875 | ||
5876 | subseg_set (gdb_section, sd_chain->sd_last_subseg); | |
5877 | current_subspace | |
5878 | = pa_subsegment_to_subspace (gdb_section, | |
5879 | sd_chain->sd_last_subseg); | |
5880 | } | |
5881 | demand_empty_rest_of_line (); | |
5882 | return; | |
5883 | } | |
5884 | ||
5885 | /* It could be a space specified by number. */ | |
5886 | print_errors = 0; | |
5887 | save_s = input_line_pointer; | |
5888 | if ((temp = pa_parse_number (&input_line_pointer, 0)) >= 0) | |
5889 | { | |
5890 | if ((sd_chain = pa_find_space_by_number (temp))) | |
5891 | { | |
5892 | current_space = sd_chain; | |
5893 | ||
5894 | subseg_set (sd_chain->sd_seg, sd_chain->sd_last_subseg); | |
5895 | current_subspace | |
5896 | = pa_subsegment_to_subspace (sd_chain->sd_seg, | |
5897 | sd_chain->sd_last_subseg); | |
5898 | demand_empty_rest_of_line (); | |
5899 | return; | |
5900 | } | |
5901 | } | |
5902 | ||
5903 | /* Not a number, attempt to create a new space. */ | |
5904 | print_errors = 1; | |
5905 | input_line_pointer = save_s; | |
5906 | name = input_line_pointer; | |
5907 | c = get_symbol_end (); | |
5908 | space_name = xmalloc (strlen (name) + 1); | |
5909 | strcpy (space_name, name); | |
5910 | *input_line_pointer = c; | |
5911 | ||
5912 | sd_chain = pa_parse_space_stmt (space_name, 1); | |
5913 | current_space = sd_chain; | |
5914 | ||
5915 | subseg_set (sd_chain->sd_seg, sd_chain->sd_last_subseg); | |
5916 | current_subspace = pa_subsegment_to_subspace (sd_chain->sd_seg, | |
5917 | sd_chain->sd_last_subseg); | |
5918 | demand_empty_rest_of_line (); | |
5919 | } | |
5920 | } | |
5921 | ||
5922 | /* Switch to a new space. (I think). FIXME. */ | |
5923 | ||
5924 | static void | |
5925 | pa_spnum (unused) | |
5926 | int unused; | |
5927 | { | |
5928 | char *name; | |
5929 | char c; | |
5930 | char *p; | |
5931 | sd_chain_struct *space; | |
5932 | ||
5933 | name = input_line_pointer; | |
5934 | c = get_symbol_end (); | |
5935 | space = is_defined_space (name); | |
5936 | if (space) | |
5937 | { | |
5938 | p = frag_more (4); | |
5939 | md_number_to_chars (p, SPACE_SPNUM (space), 4); | |
5940 | } | |
5941 | else | |
5942 | as_warn (_("Undefined space: '%s' Assuming space number = 0."), name); | |
5943 | ||
5944 | *input_line_pointer = c; | |
5945 | demand_empty_rest_of_line (); | |
5946 | } | |
5947 | ||
252b5132 RH |
5948 | /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the |
5949 | given subspace, creating the new subspace if necessary. | |
5950 | ||
5951 | FIXME. Should mirror pa_space more closely, in particular how | |
5952 | they're broken up into subroutines. */ | |
5953 | ||
5954 | static void | |
5955 | pa_subspace (create_new) | |
5956 | int create_new; | |
5957 | { | |
49863f82 | 5958 | char *name, *ss_name, c; |
252b5132 RH |
5959 | char loadable, code_only, common, dup_common, zero, sort; |
5960 | int i, access, space_index, alignment, quadrant, applicable, flags; | |
5961 | sd_chain_struct *space; | |
5962 | ssd_chain_struct *ssd; | |
5963 | asection *section; | |
5964 | ||
5965 | if (current_space == NULL) | |
5966 | as_fatal (_("Must be in a space before changing or declaring subspaces.\n")); | |
5967 | ||
5968 | if (within_procedure) | |
5969 | { | |
5970 | as_bad (_("Can\'t change subspaces within a procedure definition. Ignored")); | |
5971 | ignore_rest_of_line (); | |
5972 | } | |
5973 | else | |
5974 | { | |
5975 | name = input_line_pointer; | |
5976 | c = get_symbol_end (); | |
5977 | ss_name = xmalloc (strlen (name) + 1); | |
5978 | strcpy (ss_name, name); | |
5979 | *input_line_pointer = c; | |
5980 | ||
5981 | /* Load default values. */ | |
5982 | sort = 0; | |
5983 | access = 0x7f; | |
5984 | loadable = 1; | |
5985 | common = 0; | |
5986 | dup_common = 0; | |
5987 | code_only = 0; | |
5988 | zero = 0; | |
5989 | space_index = ~0; | |
5990 | alignment = 1; | |
5991 | quadrant = 0; | |
252b5132 RH |
5992 | |
5993 | space = current_space; | |
5994 | if (create_new) | |
5995 | ssd = NULL; | |
5996 | else | |
5997 | ssd = is_defined_subspace (ss_name); | |
5998 | /* Allow user to override the builtin attributes of subspaces. But | |
5999 | only allow the attributes to be changed once! */ | |
6000 | if (ssd && SUBSPACE_DEFINED (ssd)) | |
6001 | { | |
6002 | subseg_set (ssd->ssd_seg, ssd->ssd_subseg); | |
6003 | current_subspace = ssd; | |
6004 | if (!is_end_of_statement ()) | |
6005 | as_warn (_("Parameters of an existing subspace can\'t be modified")); | |
6006 | demand_empty_rest_of_line (); | |
6007 | return; | |
6008 | } | |
6009 | else | |
6010 | { | |
6011 | /* A new subspace. Load default values if it matches one of | |
6012 | the builtin subspaces. */ | |
6013 | i = 0; | |
6014 | while (pa_def_subspaces[i].name) | |
6015 | { | |
6016 | if (strcasecmp (pa_def_subspaces[i].name, ss_name) == 0) | |
6017 | { | |
6018 | loadable = pa_def_subspaces[i].loadable; | |
6019 | common = pa_def_subspaces[i].common; | |
6020 | dup_common = pa_def_subspaces[i].dup_common; | |
6021 | code_only = pa_def_subspaces[i].code_only; | |
6022 | zero = pa_def_subspaces[i].zero; | |
6023 | space_index = pa_def_subspaces[i].space_index; | |
6024 | alignment = pa_def_subspaces[i].alignment; | |
6025 | quadrant = pa_def_subspaces[i].quadrant; | |
6026 | access = pa_def_subspaces[i].access; | |
6027 | sort = pa_def_subspaces[i].sort; | |
252b5132 RH |
6028 | break; |
6029 | } | |
6030 | i++; | |
6031 | } | |
6032 | } | |
6033 | ||
6034 | /* We should be working with a new subspace now. Fill in | |
6035 | any information as specified by the user. */ | |
6036 | if (!is_end_of_statement ()) | |
6037 | { | |
6038 | input_line_pointer++; | |
6039 | while (!is_end_of_statement ()) | |
6040 | { | |
6041 | name = input_line_pointer; | |
6042 | c = get_symbol_end (); | |
6043 | if ((strncasecmp (name, "quad", 4) == 0)) | |
6044 | { | |
6045 | *input_line_pointer = c; | |
6046 | input_line_pointer++; | |
6047 | quadrant = get_absolute_expression (); | |
6048 | } | |
6049 | else if ((strncasecmp (name, "align", 5) == 0)) | |
6050 | { | |
6051 | *input_line_pointer = c; | |
6052 | input_line_pointer++; | |
6053 | alignment = get_absolute_expression (); | |
6054 | if (log2 (alignment) == -1) | |
6055 | { | |
6056 | as_bad (_("Alignment must be a power of 2")); | |
6057 | alignment = 1; | |
6058 | } | |
6059 | } | |
6060 | else if ((strncasecmp (name, "access", 6) == 0)) | |
6061 | { | |
6062 | *input_line_pointer = c; | |
6063 | input_line_pointer++; | |
6064 | access = get_absolute_expression (); | |
6065 | } | |
6066 | else if ((strncasecmp (name, "sort", 4) == 0)) | |
6067 | { | |
6068 | *input_line_pointer = c; | |
6069 | input_line_pointer++; | |
6070 | sort = get_absolute_expression (); | |
6071 | } | |
6072 | else if ((strncasecmp (name, "code_only", 9) == 0)) | |
6073 | { | |
6074 | *input_line_pointer = c; | |
6075 | code_only = 1; | |
6076 | } | |
6077 | else if ((strncasecmp (name, "unloadable", 10) == 0)) | |
6078 | { | |
6079 | *input_line_pointer = c; | |
6080 | loadable = 0; | |
6081 | } | |
6082 | else if ((strncasecmp (name, "common", 6) == 0)) | |
6083 | { | |
6084 | *input_line_pointer = c; | |
6085 | common = 1; | |
6086 | } | |
6087 | else if ((strncasecmp (name, "dup_comm", 8) == 0)) | |
6088 | { | |
6089 | *input_line_pointer = c; | |
6090 | dup_common = 1; | |
6091 | } | |
6092 | else if ((strncasecmp (name, "zero", 4) == 0)) | |
6093 | { | |
6094 | *input_line_pointer = c; | |
6095 | zero = 1; | |
6096 | } | |
6097 | else if ((strncasecmp (name, "first", 5) == 0)) | |
6098 | as_bad (_("FIRST not supported as a .SUBSPACE argument")); | |
6099 | else | |
6100 | as_bad (_("Invalid .SUBSPACE argument")); | |
6101 | if (!is_end_of_statement ()) | |
6102 | input_line_pointer++; | |
6103 | } | |
6104 | } | |
6105 | ||
6106 | /* Compute a reasonable set of BFD flags based on the information | |
6107 | in the .subspace directive. */ | |
6108 | applicable = bfd_applicable_section_flags (stdoutput); | |
6109 | flags = 0; | |
6110 | if (loadable) | |
6111 | flags |= (SEC_ALLOC | SEC_LOAD); | |
6112 | if (code_only) | |
6113 | flags |= SEC_CODE; | |
6114 | if (common || dup_common) | |
6115 | flags |= SEC_IS_COMMON; | |
6116 | ||
6117 | flags |= SEC_RELOC | SEC_HAS_CONTENTS; | |
6118 | ||
6119 | /* This is a zero-filled subspace (eg BSS). */ | |
6120 | if (zero) | |
6121 | flags &= ~(SEC_LOAD | SEC_HAS_CONTENTS); | |
6122 | ||
6123 | applicable &= flags; | |
6124 | ||
6125 | /* If this is an existing subspace, then we want to use the | |
6126 | segment already associated with the subspace. | |
6127 | ||
6128 | FIXME NOW! ELF BFD doesn't appear to be ready to deal with | |
6129 | lots of sections. It might be a problem in the PA ELF | |
6130 | code, I do not know yet. For now avoid creating anything | |
6131 | but the "standard" sections for ELF. */ | |
6132 | if (create_new) | |
6133 | section = subseg_force_new (ss_name, 0); | |
6134 | else if (ssd) | |
6135 | section = ssd->ssd_seg; | |
252b5132 RH |
6136 | else |
6137 | section = subseg_new (ss_name, 0); | |
6138 | ||
6139 | if (zero) | |
6140 | seg_info (section)->bss = 1; | |
6141 | ||
6142 | /* Now set the flags. */ | |
6143 | bfd_set_section_flags (stdoutput, section, applicable); | |
6144 | ||
6145 | /* Record any alignment request for this section. */ | |
6146 | record_alignment (section, log2 (alignment)); | |
6147 | ||
6148 | /* Set the starting offset for this section. */ | |
6149 | bfd_set_section_vma (stdoutput, section, | |
6150 | pa_subspace_start (space, quadrant)); | |
6151 | ||
6152 | /* Now that all the flags are set, update an existing subspace, | |
6153 | or create a new one. */ | |
6154 | if (ssd) | |
6155 | ||
6156 | current_subspace = update_subspace (space, ss_name, loadable, | |
6157 | code_only, common, dup_common, | |
6158 | sort, zero, access, space_index, | |
6159 | alignment, quadrant, | |
6160 | section); | |
6161 | else | |
6162 | current_subspace = create_new_subspace (space, ss_name, loadable, | |
6163 | code_only, common, | |
6164 | dup_common, zero, sort, | |
6165 | access, space_index, | |
6166 | alignment, quadrant, section); | |
6167 | ||
6168 | demand_empty_rest_of_line (); | |
6169 | current_subspace->ssd_seg = section; | |
6170 | subseg_set (current_subspace->ssd_seg, current_subspace->ssd_subseg); | |
6171 | } | |
6172 | SUBSPACE_DEFINED (current_subspace) = 1; | |
6173 | } | |
6174 | ||
6175 | ||
6176 | /* Create default space and subspace dictionaries. */ | |
6177 | ||
6178 | static void | |
6179 | pa_spaces_begin () | |
6180 | { | |
6181 | int i; | |
6182 | ||
6183 | space_dict_root = NULL; | |
6184 | space_dict_last = NULL; | |
6185 | ||
6186 | i = 0; | |
6187 | while (pa_def_spaces[i].name) | |
6188 | { | |
6189 | char *name; | |
6190 | ||
6191 | /* Pick the right name to use for the new section. */ | |
49863f82 | 6192 | name = pa_def_spaces[i].name; |
252b5132 RH |
6193 | |
6194 | pa_def_spaces[i].segment = subseg_new (name, 0); | |
6195 | create_new_space (pa_def_spaces[i].name, pa_def_spaces[i].spnum, | |
6196 | pa_def_spaces[i].loadable, pa_def_spaces[i].defined, | |
6197 | pa_def_spaces[i].private, pa_def_spaces[i].sort, | |
6198 | pa_def_spaces[i].segment, 0); | |
6199 | i++; | |
6200 | } | |
6201 | ||
6202 | i = 0; | |
6203 | while (pa_def_subspaces[i].name) | |
6204 | { | |
6205 | char *name; | |
6206 | int applicable, subsegment; | |
6207 | asection *segment = NULL; | |
6208 | sd_chain_struct *space; | |
6209 | ||
6210 | /* Pick the right name for the new section and pick the right | |
6211 | subsegment number. */ | |
49863f82 JL |
6212 | name = pa_def_subspaces[i].name; |
6213 | subsegment = 0; | |
252b5132 RH |
6214 | |
6215 | /* Create the new section. */ | |
6216 | segment = subseg_new (name, subsegment); | |
6217 | ||
6218 | ||
6219 | /* For SOM we want to replace the standard .text, .data, and .bss | |
6220 | sections with our own. We also want to set BFD flags for | |
6221 | all the built-in subspaces. */ | |
49863f82 | 6222 | if (!strcmp (pa_def_subspaces[i].name, "$CODE$")) |
252b5132 RH |
6223 | { |
6224 | text_section = segment; | |
6225 | applicable = bfd_applicable_section_flags (stdoutput); | |
6226 | bfd_set_section_flags (stdoutput, segment, | |
6227 | applicable & (SEC_ALLOC | SEC_LOAD | |
6228 | | SEC_RELOC | SEC_CODE | |
6229 | | SEC_READONLY | |
6230 | | SEC_HAS_CONTENTS)); | |
6231 | } | |
49863f82 | 6232 | else if (!strcmp (pa_def_subspaces[i].name, "$DATA$")) |
252b5132 RH |
6233 | { |
6234 | data_section = segment; | |
6235 | applicable = bfd_applicable_section_flags (stdoutput); | |
6236 | bfd_set_section_flags (stdoutput, segment, | |
6237 | applicable & (SEC_ALLOC | SEC_LOAD | |
6238 | | SEC_RELOC | |
6239 | | SEC_HAS_CONTENTS)); | |
6240 | ||
6241 | ||
6242 | } | |
49863f82 | 6243 | else if (!strcmp (pa_def_subspaces[i].name, "$BSS$")) |
252b5132 RH |
6244 | { |
6245 | bss_section = segment; | |
6246 | applicable = bfd_applicable_section_flags (stdoutput); | |
6247 | bfd_set_section_flags (stdoutput, segment, | |
6248 | applicable & SEC_ALLOC); | |
6249 | } | |
49863f82 | 6250 | else if (!strcmp (pa_def_subspaces[i].name, "$LIT$")) |
252b5132 RH |
6251 | { |
6252 | applicable = bfd_applicable_section_flags (stdoutput); | |
6253 | bfd_set_section_flags (stdoutput, segment, | |
6254 | applicable & (SEC_ALLOC | SEC_LOAD | |
6255 | | SEC_RELOC | |
6256 | | SEC_READONLY | |
6257 | | SEC_HAS_CONTENTS)); | |
6258 | } | |
49863f82 | 6259 | else if (!strcmp (pa_def_subspaces[i].name, "$MILLICODE$")) |
252b5132 RH |
6260 | { |
6261 | applicable = bfd_applicable_section_flags (stdoutput); | |
6262 | bfd_set_section_flags (stdoutput, segment, | |
6263 | applicable & (SEC_ALLOC | SEC_LOAD | |
6264 | | SEC_RELOC | |
6265 | | SEC_READONLY | |
6266 | | SEC_HAS_CONTENTS)); | |
6267 | } | |
49863f82 | 6268 | else if (!strcmp (pa_def_subspaces[i].name, "$UNWIND$")) |
252b5132 RH |
6269 | { |
6270 | applicable = bfd_applicable_section_flags (stdoutput); | |
6271 | bfd_set_section_flags (stdoutput, segment, | |
6272 | applicable & (SEC_ALLOC | SEC_LOAD | |
6273 | | SEC_RELOC | |
6274 | | SEC_READONLY | |
6275 | | SEC_HAS_CONTENTS)); | |
6276 | } | |
6277 | ||
6278 | /* Find the space associated with this subspace. */ | |
6279 | space = pa_segment_to_space (pa_def_spaces[pa_def_subspaces[i]. | |
6280 | def_space_index].segment); | |
6281 | if (space == NULL) | |
6282 | { | |
6283 | as_fatal (_("Internal error: Unable to find containing space for %s."), | |
6284 | pa_def_subspaces[i].name); | |
6285 | } | |
6286 | ||
6287 | create_new_subspace (space, name, | |
6288 | pa_def_subspaces[i].loadable, | |
6289 | pa_def_subspaces[i].code_only, | |
6290 | pa_def_subspaces[i].common, | |
6291 | pa_def_subspaces[i].dup_common, | |
6292 | pa_def_subspaces[i].zero, | |
6293 | pa_def_subspaces[i].sort, | |
6294 | pa_def_subspaces[i].access, | |
6295 | pa_def_subspaces[i].space_index, | |
6296 | pa_def_subspaces[i].alignment, | |
6297 | pa_def_subspaces[i].quadrant, | |
6298 | segment); | |
6299 | i++; | |
6300 | } | |
6301 | } | |
6302 | ||
6303 | ||
6304 | ||
6305 | /* Create a new space NAME, with the appropriate flags as defined | |
6306 | by the given parameters. */ | |
6307 | ||
6308 | static sd_chain_struct * | |
6309 | create_new_space (name, spnum, loadable, defined, private, | |
6310 | sort, seg, user_defined) | |
6311 | char *name; | |
6312 | int spnum; | |
6313 | int loadable; | |
6314 | int defined; | |
6315 | int private; | |
6316 | int sort; | |
6317 | asection *seg; | |
6318 | int user_defined; | |
6319 | { | |
6320 | sd_chain_struct *chain_entry; | |
6321 | ||
6322 | chain_entry = (sd_chain_struct *) xmalloc (sizeof (sd_chain_struct)); | |
6323 | if (!chain_entry) | |
6324 | as_fatal (_("Out of memory: could not allocate new space chain entry: %s\n"), | |
6325 | name); | |
6326 | ||
6327 | SPACE_NAME (chain_entry) = (char *) xmalloc (strlen (name) + 1); | |
6328 | strcpy (SPACE_NAME (chain_entry), name); | |
6329 | SPACE_DEFINED (chain_entry) = defined; | |
6330 | SPACE_USER_DEFINED (chain_entry) = user_defined; | |
6331 | SPACE_SPNUM (chain_entry) = spnum; | |
6332 | ||
6333 | chain_entry->sd_seg = seg; | |
6334 | chain_entry->sd_last_subseg = -1; | |
6335 | chain_entry->sd_subspaces = NULL; | |
6336 | chain_entry->sd_next = NULL; | |
6337 | ||
6338 | /* Find spot for the new space based on its sort key. */ | |
6339 | if (!space_dict_last) | |
6340 | space_dict_last = chain_entry; | |
6341 | ||
6342 | if (space_dict_root == NULL) | |
6343 | space_dict_root = chain_entry; | |
6344 | else | |
6345 | { | |
6346 | sd_chain_struct *chain_pointer; | |
6347 | sd_chain_struct *prev_chain_pointer; | |
6348 | ||
6349 | chain_pointer = space_dict_root; | |
6350 | prev_chain_pointer = NULL; | |
6351 | ||
6352 | while (chain_pointer) | |
6353 | { | |
6354 | prev_chain_pointer = chain_pointer; | |
6355 | chain_pointer = chain_pointer->sd_next; | |
6356 | } | |
6357 | ||
6358 | /* At this point we've found the correct place to add the new | |
6359 | entry. So add it and update the linked lists as appropriate. */ | |
6360 | if (prev_chain_pointer) | |
6361 | { | |
6362 | chain_entry->sd_next = chain_pointer; | |
6363 | prev_chain_pointer->sd_next = chain_entry; | |
6364 | } | |
6365 | else | |
6366 | { | |
6367 | space_dict_root = chain_entry; | |
6368 | chain_entry->sd_next = chain_pointer; | |
6369 | } | |
6370 | ||
6371 | if (chain_entry->sd_next == NULL) | |
6372 | space_dict_last = chain_entry; | |
6373 | } | |
6374 | ||
6375 | /* This is here to catch predefined spaces which do not get | |
6376 | modified by the user's input. Another call is found at | |
6377 | the bottom of pa_parse_space_stmt to handle cases where | |
6378 | the user modifies a predefined space. */ | |
6379 | #ifdef obj_set_section_attributes | |
6380 | obj_set_section_attributes (seg, defined, private, sort, spnum); | |
6381 | #endif | |
6382 | ||
6383 | return chain_entry; | |
6384 | } | |
6385 | ||
6386 | /* Create a new subspace NAME, with the appropriate flags as defined | |
6387 | by the given parameters. | |
6388 | ||
6389 | Add the new subspace to the subspace dictionary chain in numerical | |
6390 | order as defined by the SORT entries. */ | |
6391 | ||
6392 | static ssd_chain_struct * | |
6393 | create_new_subspace (space, name, loadable, code_only, common, | |
6394 | dup_common, is_zero, sort, access, space_index, | |
6395 | alignment, quadrant, seg) | |
6396 | sd_chain_struct *space; | |
6397 | char *name; | |
6398 | int loadable, code_only, common, dup_common, is_zero; | |
6399 | int sort; | |
6400 | int access; | |
6401 | int space_index; | |
6402 | int alignment; | |
6403 | int quadrant; | |
6404 | asection *seg; | |
6405 | { | |
6406 | ssd_chain_struct *chain_entry; | |
6407 | ||
6408 | chain_entry = (ssd_chain_struct *) xmalloc (sizeof (ssd_chain_struct)); | |
6409 | if (!chain_entry) | |
6410 | as_fatal (_("Out of memory: could not allocate new subspace chain entry: %s\n"), name); | |
6411 | ||
6412 | SUBSPACE_NAME (chain_entry) = (char *) xmalloc (strlen (name) + 1); | |
6413 | strcpy (SUBSPACE_NAME (chain_entry), name); | |
6414 | ||
6415 | /* Initialize subspace_defined. When we hit a .subspace directive | |
6416 | we'll set it to 1 which "locks-in" the subspace attributes. */ | |
6417 | SUBSPACE_DEFINED (chain_entry) = 0; | |
6418 | ||
49863f82 | 6419 | chain_entry->ssd_subseg = 0; |
252b5132 RH |
6420 | chain_entry->ssd_seg = seg; |
6421 | chain_entry->ssd_next = NULL; | |
6422 | ||
6423 | /* Find spot for the new subspace based on its sort key. */ | |
6424 | if (space->sd_subspaces == NULL) | |
6425 | space->sd_subspaces = chain_entry; | |
6426 | else | |
6427 | { | |
6428 | ssd_chain_struct *chain_pointer; | |
6429 | ssd_chain_struct *prev_chain_pointer; | |
6430 | ||
6431 | chain_pointer = space->sd_subspaces; | |
6432 | prev_chain_pointer = NULL; | |
6433 | ||
6434 | while (chain_pointer) | |
6435 | { | |
6436 | prev_chain_pointer = chain_pointer; | |
6437 | chain_pointer = chain_pointer->ssd_next; | |
6438 | } | |
6439 | ||
6440 | /* Now we have somewhere to put the new entry. Insert it and update | |
6441 | the links. */ | |
6442 | if (prev_chain_pointer) | |
6443 | { | |
6444 | chain_entry->ssd_next = chain_pointer; | |
6445 | prev_chain_pointer->ssd_next = chain_entry; | |
6446 | } | |
6447 | else | |
6448 | { | |
6449 | space->sd_subspaces = chain_entry; | |
6450 | chain_entry->ssd_next = chain_pointer; | |
6451 | } | |
6452 | } | |
6453 | ||
6454 | #ifdef obj_set_subsection_attributes | |
6455 | obj_set_subsection_attributes (seg, space->sd_seg, access, | |
6456 | sort, quadrant); | |
6457 | #endif | |
6458 | ||
6459 | return chain_entry; | |
6460 | } | |
6461 | ||
6462 | /* Update the information for the given subspace based upon the | |
6463 | various arguments. Return the modified subspace chain entry. */ | |
6464 | ||
6465 | static ssd_chain_struct * | |
6466 | update_subspace (space, name, loadable, code_only, common, dup_common, sort, | |
6467 | zero, access, space_index, alignment, quadrant, section) | |
6468 | sd_chain_struct *space; | |
6469 | char *name; | |
6470 | int loadable; | |
6471 | int code_only; | |
6472 | int common; | |
6473 | int dup_common; | |
6474 | int zero; | |
6475 | int sort; | |
6476 | int access; | |
6477 | int space_index; | |
6478 | int alignment; | |
6479 | int quadrant; | |
6480 | asection *section; | |
6481 | { | |
6482 | ssd_chain_struct *chain_entry; | |
6483 | ||
6484 | chain_entry = is_defined_subspace (name); | |
6485 | ||
6486 | #ifdef obj_set_subsection_attributes | |
6487 | obj_set_subsection_attributes (section, space->sd_seg, access, | |
6488 | sort, quadrant); | |
6489 | #endif | |
6490 | ||
6491 | return chain_entry; | |
6492 | } | |
6493 | ||
6494 | /* Return the space chain entry for the space with the name NAME or | |
6495 | NULL if no such space exists. */ | |
6496 | ||
6497 | static sd_chain_struct * | |
6498 | is_defined_space (name) | |
6499 | char *name; | |
6500 | { | |
6501 | sd_chain_struct *chain_pointer; | |
6502 | ||
6503 | for (chain_pointer = space_dict_root; | |
6504 | chain_pointer; | |
6505 | chain_pointer = chain_pointer->sd_next) | |
6506 | { | |
6507 | if (strcmp (SPACE_NAME (chain_pointer), name) == 0) | |
6508 | return chain_pointer; | |
6509 | } | |
6510 | ||
6511 | /* No mapping from segment to space was found. Return NULL. */ | |
6512 | return NULL; | |
6513 | } | |
6514 | ||
6515 | /* Find and return the space associated with the given seg. If no mapping | |
6516 | from the given seg to a space is found, then return NULL. | |
6517 | ||
6518 | Unlike subspaces, the number of spaces is not expected to grow much, | |
6519 | so a linear exhaustive search is OK here. */ | |
6520 | ||
6521 | static sd_chain_struct * | |
6522 | pa_segment_to_space (seg) | |
6523 | asection *seg; | |
6524 | { | |
6525 | sd_chain_struct *space_chain; | |
6526 | ||
6527 | /* Walk through each space looking for the correct mapping. */ | |
6528 | for (space_chain = space_dict_root; | |
6529 | space_chain; | |
6530 | space_chain = space_chain->sd_next) | |
6531 | { | |
6532 | if (space_chain->sd_seg == seg) | |
6533 | return space_chain; | |
6534 | } | |
6535 | ||
6536 | /* Mapping was not found. Return NULL. */ | |
6537 | return NULL; | |
6538 | } | |
6539 | ||
6540 | /* Return the space chain entry for the subspace with the name NAME or | |
6541 | NULL if no such subspace exists. | |
6542 | ||
6543 | Uses a linear search through all the spaces and subspaces, this may | |
6544 | not be appropriate if we ever being placing each function in its | |
6545 | own subspace. */ | |
6546 | ||
6547 | static ssd_chain_struct * | |
6548 | is_defined_subspace (name) | |
6549 | char *name; | |
6550 | { | |
6551 | sd_chain_struct *space_chain; | |
6552 | ssd_chain_struct *subspace_chain; | |
6553 | ||
6554 | /* Walk through each space. */ | |
6555 | for (space_chain = space_dict_root; | |
6556 | space_chain; | |
6557 | space_chain = space_chain->sd_next) | |
6558 | { | |
6559 | /* Walk through each subspace looking for a name which matches. */ | |
6560 | for (subspace_chain = space_chain->sd_subspaces; | |
6561 | subspace_chain; | |
6562 | subspace_chain = subspace_chain->ssd_next) | |
6563 | if (strcmp (SUBSPACE_NAME (subspace_chain), name) == 0) | |
6564 | return subspace_chain; | |
6565 | } | |
6566 | ||
6567 | /* Subspace wasn't found. Return NULL. */ | |
6568 | return NULL; | |
6569 | } | |
6570 | ||
6571 | /* Find and return the subspace associated with the given seg. If no | |
6572 | mapping from the given seg to a subspace is found, then return NULL. | |
6573 | ||
6574 | If we ever put each procedure/function within its own subspace | |
6575 | (to make life easier on the compiler and linker), then this will have | |
6576 | to become more efficient. */ | |
6577 | ||
6578 | static ssd_chain_struct * | |
6579 | pa_subsegment_to_subspace (seg, subseg) | |
6580 | asection *seg; | |
6581 | subsegT subseg; | |
6582 | { | |
6583 | sd_chain_struct *space_chain; | |
6584 | ssd_chain_struct *subspace_chain; | |
6585 | ||
6586 | /* Walk through each space. */ | |
6587 | for (space_chain = space_dict_root; | |
6588 | space_chain; | |
6589 | space_chain = space_chain->sd_next) | |
6590 | { | |
6591 | if (space_chain->sd_seg == seg) | |
6592 | { | |
6593 | /* Walk through each subspace within each space looking for | |
6594 | the correct mapping. */ | |
6595 | for (subspace_chain = space_chain->sd_subspaces; | |
6596 | subspace_chain; | |
6597 | subspace_chain = subspace_chain->ssd_next) | |
6598 | if (subspace_chain->ssd_subseg == (int) subseg) | |
6599 | return subspace_chain; | |
6600 | } | |
6601 | } | |
6602 | ||
6603 | /* No mapping from subsegment to subspace found. Return NULL. */ | |
6604 | return NULL; | |
6605 | } | |
6606 | ||
6607 | /* Given a number, try and find a space with the name number. | |
6608 | ||
6609 | Return a pointer to a space dictionary chain entry for the space | |
6610 | that was found or NULL on failure. */ | |
6611 | ||
6612 | static sd_chain_struct * | |
6613 | pa_find_space_by_number (number) | |
6614 | int number; | |
6615 | { | |
6616 | sd_chain_struct *space_chain; | |
6617 | ||
6618 | for (space_chain = space_dict_root; | |
6619 | space_chain; | |
6620 | space_chain = space_chain->sd_next) | |
6621 | { | |
6622 | if (SPACE_SPNUM (space_chain) == (unsigned int) number) | |
6623 | return space_chain; | |
6624 | } | |
6625 | ||
6626 | /* No appropriate space found. Return NULL. */ | |
6627 | return NULL; | |
6628 | } | |
6629 | ||
6630 | /* Return the starting address for the given subspace. If the starting | |
6631 | address is unknown then return zero. */ | |
6632 | ||
6633 | static unsigned int | |
6634 | pa_subspace_start (space, quadrant) | |
6635 | sd_chain_struct *space; | |
6636 | int quadrant; | |
6637 | { | |
252b5132 RH |
6638 | /* FIXME. Assumes everyone puts read/write data at 0x4000000, this |
6639 | is not correct for the PA OSF1 port. */ | |
6640 | if ((strcmp (SPACE_NAME (space), "$PRIVATE$") == 0) && quadrant == 1) | |
6641 | return 0x40000000; | |
6642 | else if (space->sd_seg == data_section && quadrant == 1) | |
6643 | return 0x40000000; | |
6644 | else | |
6645 | return 0; | |
252b5132 RH |
6646 | return 0; |
6647 | } | |
6648 | ||
6649 | /* FIXME. Needs documentation. */ | |
6650 | static int | |
6651 | pa_next_subseg (space) | |
6652 | sd_chain_struct *space; | |
6653 | { | |
6654 | ||
6655 | space->sd_last_subseg++; | |
6656 | return space->sd_last_subseg; | |
6657 | } | |
49863f82 | 6658 | #endif |
252b5132 RH |
6659 | |
6660 | /* Helper function for pa_stringer. Used to find the end of | |
6661 | a string. */ | |
6662 | ||
6663 | static unsigned int | |
6664 | pa_stringer_aux (s) | |
6665 | char *s; | |
6666 | { | |
6667 | unsigned int c = *s & CHAR_MASK; | |
6668 | ||
49863f82 | 6669 | #ifdef OBJ_SOM |
252b5132 RH |
6670 | /* We must have a valid space and subspace. */ |
6671 | pa_check_current_space_and_subspace (); | |
49863f82 | 6672 | #endif |
252b5132 RH |
6673 | |
6674 | switch (c) | |
6675 | { | |
6676 | case '\"': | |
6677 | c = NOT_A_CHAR; | |
6678 | break; | |
6679 | default: | |
6680 | break; | |
6681 | } | |
6682 | return c; | |
6683 | } | |
6684 | ||
6685 | /* Handle a .STRING type pseudo-op. */ | |
6686 | ||
6687 | static void | |
6688 | pa_stringer (append_zero) | |
6689 | int append_zero; | |
6690 | { | |
6691 | char *s, num_buf[4]; | |
6692 | unsigned int c; | |
6693 | int i; | |
6694 | ||
6695 | /* Preprocess the string to handle PA-specific escape sequences. | |
6696 | For example, \xDD where DD is a hexidecimal number should be | |
6697 | changed to \OOO where OOO is an octal number. */ | |
6698 | ||
6699 | /* Skip the opening quote. */ | |
6700 | s = input_line_pointer + 1; | |
6701 | ||
6702 | while (is_a_char (c = pa_stringer_aux (s++))) | |
6703 | { | |
6704 | if (c == '\\') | |
6705 | { | |
6706 | c = *s; | |
6707 | switch (c) | |
6708 | { | |
6709 | /* Handle \x<num>. */ | |
6710 | case 'x': | |
6711 | { | |
6712 | unsigned int number; | |
6713 | int num_digit; | |
6714 | char dg; | |
6715 | char *s_start = s; | |
6716 | ||
6717 | /* Get pas the 'x'. */ | |
6718 | s++; | |
6719 | for (num_digit = 0, number = 0, dg = *s; | |
6720 | num_digit < 2 | |
6721 | && (isdigit (dg) || (dg >= 'a' && dg <= 'f') | |
6722 | || (dg >= 'A' && dg <= 'F')); | |
6723 | num_digit++) | |
6724 | { | |
6725 | if (isdigit (dg)) | |
6726 | number = number * 16 + dg - '0'; | |
6727 | else if (dg >= 'a' && dg <= 'f') | |
6728 | number = number * 16 + dg - 'a' + 10; | |
6729 | else | |
6730 | number = number * 16 + dg - 'A' + 10; | |
6731 | ||
6732 | s++; | |
6733 | dg = *s; | |
6734 | } | |
6735 | if (num_digit > 0) | |
6736 | { | |
6737 | switch (num_digit) | |
6738 | { | |
6739 | case 1: | |
6740 | sprintf (num_buf, "%02o", number); | |
6741 | break; | |
6742 | case 2: | |
6743 | sprintf (num_buf, "%03o", number); | |
6744 | break; | |
6745 | } | |
6746 | for (i = 0; i <= num_digit; i++) | |
6747 | s_start[i] = num_buf[i]; | |
6748 | } | |
6749 | break; | |
6750 | } | |
6751 | /* This might be a "\"", skip over the escaped char. */ | |
6752 | default: | |
6753 | s++; | |
6754 | break; | |
6755 | } | |
6756 | } | |
6757 | } | |
6758 | stringer (append_zero); | |
6759 | pa_undefine_label (); | |
6760 | } | |
6761 | ||
6762 | /* Handle a .VERSION pseudo-op. */ | |
6763 | ||
6764 | static void | |
6765 | pa_version (unused) | |
6766 | int unused; | |
6767 | { | |
6768 | obj_version (0); | |
6769 | pa_undefine_label (); | |
6770 | } | |
6771 | ||
6772 | #ifdef OBJ_SOM | |
6773 | ||
6774 | /* Handle a .COMPILER pseudo-op. */ | |
6775 | ||
6776 | static void | |
6777 | pa_compiler (unused) | |
6778 | int unused; | |
6779 | { | |
6780 | obj_som_compiler (0); | |
6781 | pa_undefine_label (); | |
6782 | } | |
6783 | ||
6784 | #endif | |
6785 | ||
6786 | /* Handle a .COPYRIGHT pseudo-op. */ | |
6787 | ||
6788 | static void | |
6789 | pa_copyright (unused) | |
6790 | int unused; | |
6791 | { | |
6792 | obj_copyright (0); | |
6793 | pa_undefine_label (); | |
6794 | } | |
6795 | ||
6796 | /* Just like a normal cons, but when finished we have to undefine | |
6797 | the latest space label. */ | |
6798 | ||
6799 | static void | |
6800 | pa_cons (nbytes) | |
6801 | int nbytes; | |
6802 | { | |
6803 | cons (nbytes); | |
6804 | pa_undefine_label (); | |
6805 | } | |
6806 | ||
6807 | /* Switch to the data space. As usual delete our label. */ | |
6808 | ||
6809 | static void | |
6810 | pa_data (unused) | |
6811 | int unused; | |
6812 | { | |
49863f82 | 6813 | #ifdef OBJ_SOM |
252b5132 RH |
6814 | current_space = is_defined_space ("$PRIVATE$"); |
6815 | current_subspace | |
6816 | = pa_subsegment_to_subspace (current_space->sd_seg, 0); | |
49863f82 | 6817 | #endif |
252b5132 RH |
6818 | s_data (0); |
6819 | pa_undefine_label (); | |
6820 | } | |
6821 | ||
6822 | /* Like float_cons, but we need to undefine our label. */ | |
6823 | ||
6824 | static void | |
6825 | pa_float_cons (float_type) | |
6826 | int float_type; | |
6827 | { | |
6828 | float_cons (float_type); | |
6829 | pa_undefine_label (); | |
6830 | } | |
6831 | ||
6832 | /* Like s_fill, but delete our label when finished. */ | |
6833 | ||
6834 | static void | |
6835 | pa_fill (unused) | |
6836 | int unused; | |
6837 | { | |
49863f82 | 6838 | #ifdef OBJ_SOM |
252b5132 RH |
6839 | /* We must have a valid space and subspace. */ |
6840 | pa_check_current_space_and_subspace (); | |
49863f82 | 6841 | #endif |
252b5132 RH |
6842 | |
6843 | s_fill (0); | |
6844 | pa_undefine_label (); | |
6845 | } | |
6846 | ||
6847 | /* Like lcomm, but delete our label when finished. */ | |
6848 | ||
6849 | static void | |
6850 | pa_lcomm (needs_align) | |
6851 | int needs_align; | |
6852 | { | |
49863f82 | 6853 | #ifdef OBJ_SOM |
252b5132 RH |
6854 | /* We must have a valid space and subspace. */ |
6855 | pa_check_current_space_and_subspace (); | |
49863f82 | 6856 | #endif |
252b5132 RH |
6857 | |
6858 | s_lcomm (needs_align); | |
6859 | pa_undefine_label (); | |
6860 | } | |
6861 | ||
6862 | /* Like lsym, but delete our label when finished. */ | |
6863 | ||
6864 | static void | |
6865 | pa_lsym (unused) | |
6866 | int unused; | |
6867 | { | |
49863f82 | 6868 | #ifdef OBJ_SOM |
252b5132 RH |
6869 | /* We must have a valid space and subspace. */ |
6870 | pa_check_current_space_and_subspace (); | |
49863f82 | 6871 | #endif |
252b5132 RH |
6872 | |
6873 | s_lsym (0); | |
6874 | pa_undefine_label (); | |
6875 | } | |
6876 | ||
6877 | /* Switch to the text space. Like s_text, but delete our | |
6878 | label when finished. */ | |
6879 | static void | |
6880 | pa_text (unused) | |
6881 | int unused; | |
6882 | { | |
49863f82 | 6883 | #ifdef OBJ_SOM |
252b5132 RH |
6884 | current_space = is_defined_space ("$TEXT$"); |
6885 | current_subspace | |
6886 | = pa_subsegment_to_subspace (current_space->sd_seg, 0); | |
49863f82 | 6887 | #endif |
252b5132 RH |
6888 | |
6889 | s_text (0); | |
6890 | pa_undefine_label (); | |
6891 | } | |
6892 | ||
6893 | /* On the PA relocations which involve function symbols must not be | |
6894 | adjusted. This so that the linker can know when/how to create argument | |
6895 | relocation stubs for indirect calls and calls to static functions. | |
6896 | ||
6897 | "T" field selectors create DLT relative fixups for accessing | |
6898 | globals and statics in PIC code; each DLT relative fixup creates | |
6899 | an entry in the DLT table. The entries contain the address of | |
6900 | the final target (eg accessing "foo" would create a DLT entry | |
6901 | with the address of "foo"). | |
6902 | ||
6903 | Unfortunately, the HP linker doesn't take into account any addend | |
6904 | when generating the DLT; so accessing $LIT$+8 puts the address of | |
6905 | $LIT$ into the DLT rather than the address of $LIT$+8. | |
6906 | ||
6907 | The end result is we can't perform relocation symbol reductions for | |
6908 | any fixup which creates entries in the DLT (eg they use "T" field | |
6909 | selectors). | |
6910 | ||
6911 | Reject reductions involving symbols with external scope; such | |
6912 | reductions make life a living hell for object file editors. | |
6913 | ||
6914 | FIXME. Also reject R_HPPA relocations which are 32bits wide in | |
6915 | the code space. The SOM BFD backend doesn't know how to pull the | |
6916 | right bits out of an instruction. */ | |
6917 | ||
6918 | int | |
6919 | hppa_fix_adjustable (fixp) | |
6920 | fixS *fixp; | |
6921 | { | |
6922 | struct hppa_fix_struct *hppa_fix; | |
6923 | ||
6924 | hppa_fix = (struct hppa_fix_struct *) fixp->tc_fix_data; | |
6925 | ||
6926 | #ifdef OBJ_SOM | |
6927 | /* Reject reductions of symbols in 32bit relocs. */ | |
6928 | if (fixp->fx_r_type == R_HPPA && hppa_fix->fx_r_format == 32) | |
6929 | return 0; | |
6930 | ||
6931 | /* Reject reductions of symbols in sym1-sym2 expressions when | |
6932 | the fixup will occur in a CODE subspace. | |
6933 | ||
6934 | XXX FIXME: Long term we probably want to reject all of these; | |
6935 | for example reducing in the debug section would lose if we ever | |
6936 | supported using the optimizing hp linker. */ | |
6937 | if (fixp->fx_addsy | |
6938 | && fixp->fx_subsy | |
6939 | && (hppa_fix->segment->flags & SEC_CODE)) | |
6940 | { | |
6941 | /* Apparently sy_used_in_reloc never gets set for sub symbols. */ | |
398e8c25 | 6942 | symbol_mark_used_in_reloc (fixp->fx_subsy); |
252b5132 RH |
6943 | return 0; |
6944 | } | |
6945 | ||
6946 | /* We can't adjust any relocs that use LR% and RR% field selectors. | |
6947 | That confuses the HP linker. */ | |
6948 | if (hppa_fix->fx_r_field == e_lrsel | |
6949 | || hppa_fix->fx_r_field == e_rrsel | |
6950 | || hppa_fix->fx_r_field == e_nlrsel) | |
6951 | return 0; | |
6952 | #endif | |
6953 | ||
6954 | /* Reject reductions of symbols in DLT relative relocs, | |
6955 | relocations with plabels. */ | |
6956 | if (hppa_fix->fx_r_field == e_tsel | |
6957 | || hppa_fix->fx_r_field == e_ltsel | |
6958 | || hppa_fix->fx_r_field == e_rtsel | |
6959 | || hppa_fix->fx_r_field == e_psel | |
6960 | || hppa_fix->fx_r_field == e_rpsel | |
6961 | || hppa_fix->fx_r_field == e_lpsel) | |
6962 | return 0; | |
6963 | ||
a0f75b47 | 6964 | if (fixp->fx_addsy && S_IS_EXTERNAL (fixp->fx_addsy)) |
252b5132 RH |
6965 | return 0; |
6966 | ||
6967 | /* Reject absolute calls (jumps). */ | |
6968 | if (hppa_fix->fx_r_type == R_HPPA_ABS_CALL) | |
6969 | return 0; | |
6970 | ||
6971 | /* Reject reductions of function symbols. */ | |
a0f75b47 | 6972 | if (fixp->fx_addsy == 0 || ! S_IS_FUNCTION (fixp->fx_addsy)) |
252b5132 RH |
6973 | return 1; |
6974 | ||
6975 | return 0; | |
6976 | } | |
6977 | ||
6978 | /* Return nonzero if the fixup in FIXP will require a relocation, | |
6979 | even it if appears that the fixup could be completely handled | |
6980 | within GAS. */ | |
6981 | ||
6982 | int | |
6983 | hppa_force_relocation (fixp) | |
6984 | fixS *fixp; | |
6985 | { | |
6986 | struct hppa_fix_struct *hppa_fixp; | |
6987 | int distance; | |
6988 | ||
6989 | hppa_fixp = (struct hppa_fix_struct *) fixp->tc_fix_data; | |
6990 | #ifdef OBJ_SOM | |
6991 | if (fixp->fx_r_type == R_HPPA_ENTRY || fixp->fx_r_type == R_HPPA_EXIT | |
6992 | || fixp->fx_r_type == R_HPPA_BEGIN_BRTAB | |
6993 | || fixp->fx_r_type == R_HPPA_END_BRTAB | |
6994 | || fixp->fx_r_type == R_HPPA_BEGIN_TRY | |
6995 | || fixp->fx_r_type == R_HPPA_END_TRY | |
6996 | || (fixp->fx_addsy != NULL && fixp->fx_subsy != NULL | |
6997 | && (hppa_fixp->segment->flags & SEC_CODE) != 0)) | |
6998 | return 1; | |
6999 | #endif | |
7000 | ||
7001 | #define arg_reloc_stub_needed(CALLER, CALLEE) \ | |
7002 | ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER))) | |
7003 | ||
49863f82 | 7004 | #ifdef OBJ_SOM |
252b5132 RH |
7005 | /* It is necessary to force PC-relative calls/jumps to have a relocation |
7006 | entry if they're going to need either a argument relocation or long | |
7007 | call stub. FIXME. Can't we need the same for absolute calls? */ | |
7008 | if (fixp->fx_pcrel && fixp->fx_addsy | |
7009 | && (arg_reloc_stub_needed ((long) ((obj_symbol_type *) | |
a0f75b47 ILT |
7010 | symbol_get_bfdsym (fixp->fx_addsy))->tc_data.ap.hppa_arg_reloc, |
7011 | hppa_fixp->fx_arg_reloc))) | |
252b5132 | 7012 | return 1; |
49863f82 | 7013 | #endif |
252b5132 RH |
7014 | distance = (fixp->fx_offset + S_GET_VALUE (fixp->fx_addsy) |
7015 | - md_pcrel_from (fixp)); | |
7016 | /* Now check and see if we're going to need a long-branch stub. */ | |
7017 | if (fixp->fx_r_type == R_HPPA_PCREL_CALL | |
7018 | && (distance > 262143 || distance < -262144)) | |
7019 | return 1; | |
7020 | ||
7021 | if (fixp->fx_r_type == R_HPPA_ABS_CALL) | |
7022 | return 1; | |
7023 | #undef arg_reloc_stub_needed | |
7024 | ||
7025 | /* No need (yet) to force another relocations to be emitted. */ | |
7026 | return 0; | |
7027 | } | |
7028 | ||
7029 | /* Now for some ELF specific code. FIXME. */ | |
7030 | #ifdef OBJ_ELF | |
7031 | /* Mark the end of a function so that it's possible to compute | |
7032 | the size of the function in hppa_elf_final_processing. */ | |
7033 | ||
7034 | static void | |
7035 | hppa_elf_mark_end_of_function () | |
7036 | { | |
7037 | /* ELF does not have EXIT relocations. All we do is create a | |
7038 | temporary symbol marking the end of the function. */ | |
7039 | char *name = (char *) | |
7040 | xmalloc (strlen ("L$\001end_") + | |
7041 | strlen (S_GET_NAME (last_call_info->start_symbol)) + 1); | |
7042 | ||
7043 | if (name) | |
7044 | { | |
7045 | symbolS *symbolP; | |
7046 | ||
7047 | strcpy (name, "L$\001end_"); | |
7048 | strcat (name, S_GET_NAME (last_call_info->start_symbol)); | |
7049 | ||
7050 | /* If we have a .exit followed by a .procend, then the | |
7051 | symbol will have already been defined. */ | |
7052 | symbolP = symbol_find (name); | |
7053 | if (symbolP) | |
7054 | { | |
7055 | /* The symbol has already been defined! This can | |
7056 | happen if we have a .exit followed by a .procend. | |
7057 | ||
7058 | This is *not* an error. All we want to do is free | |
7059 | the memory we just allocated for the name and continue. */ | |
7060 | xfree (name); | |
7061 | } | |
7062 | else | |
7063 | { | |
7064 | /* symbol value should be the offset of the | |
7065 | last instruction of the function */ | |
7066 | symbolP = symbol_new (name, now_seg, (valueT) (frag_now_fix () - 4), | |
7067 | frag_now); | |
7068 | ||
7069 | assert (symbolP); | |
a0f75b47 | 7070 | S_CLEAR_EXTERNAL (symbolP); |
252b5132 RH |
7071 | symbol_table_insert (symbolP); |
7072 | } | |
7073 | ||
7074 | if (symbolP) | |
7075 | last_call_info->end_symbol = symbolP; | |
7076 | else | |
7077 | as_bad (_("Symbol '%s' could not be created."), name); | |
7078 | ||
7079 | } | |
7080 | else | |
7081 | as_bad (_("No memory for symbol name.")); | |
7082 | ||
7083 | } | |
7084 | ||
7085 | /* For ELF, this function serves one purpose: to setup the st_size | |
7086 | field of STT_FUNC symbols. To do this, we need to scan the | |
7087 | call_info structure list, determining st_size in by taking the | |
7088 | difference in the address of the beginning/end marker symbols. */ | |
7089 | ||
7090 | void | |
7091 | elf_hppa_final_processing () | |
7092 | { | |
7093 | struct call_info *call_info_pointer; | |
7094 | ||
7095 | for (call_info_pointer = call_info_root; | |
7096 | call_info_pointer; | |
7097 | call_info_pointer = call_info_pointer->ci_next) | |
7098 | { | |
7099 | elf_symbol_type *esym | |
a0f75b47 ILT |
7100 | = ((elf_symbol_type *) |
7101 | symbol_get_bfdsym (call_info_pointer->start_symbol)); | |
252b5132 RH |
7102 | esym->internal_elf_sym.st_size = |
7103 | S_GET_VALUE (call_info_pointer->end_symbol) | |
7104 | - S_GET_VALUE (call_info_pointer->start_symbol) + 4; | |
7105 | } | |
7106 | } | |
7107 | #endif |