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