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