Add field ``name'' to floatformat.
[binutils.git] / gas / config / tc-hppa.c
blobc57fd61ccff3e7efef2c90b4753d8d079b6a14c2
1 /* tc-hppa.c -- Assemble for the PA
2 Copyright (C) 1989, 93, 94, 95, 96, 97, 98, 1999
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
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.
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.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
23 /* HP PA-RISC support was contributed by the Center for Software Science
24 at the University of Utah. */
26 #include <stdio.h>
27 #include <ctype.h>
29 #include "as.h"
30 #include "subsegs.h"
32 #include "bfd/libhppa.h"
33 #include "bfd/libbfd.h"
35 /* Be careful, this file includes data *declarations*. */
36 #include "opcode/hppa.h"
38 #if defined (OBJ_ELF) && defined (OBJ_SOM)
39 error only one of OBJ_ELF and OBJ_SOM can be defined
40 #endif
42 /* If we are using ELF, then we probably can support dwarf2 debug
43 records. Furthermore, if we are supporting dwarf2 debug records,
44 then we want to use the assembler support for compact line numbers. */
45 #ifdef OBJ_ELF
46 #include "dwarf2dbg.h"
47 struct dwarf2_line_info debug_line;
48 #endif
50 /* A "convient" place to put object file dependencies which do
51 not need to be seen outside of tc-hppa.c. */
52 #ifdef OBJ_ELF
53 /* Object file formats specify relocation types. */
54 typedef elf_hppa_reloc_type reloc_type;
56 /* Object file formats specify BFD symbol types. */
57 typedef elf_symbol_type obj_symbol_type;
59 #ifdef BFD64
60 /* How to generate a relocation. */
61 #define hppa_gen_reloc_type _bfd_elf64_hppa_gen_reloc_type
62 #else
63 #define hppa_gen_reloc_type _bfd_elf32_hppa_gen_reloc_type
64 #endif
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
71 #define UNWIND_SECTION_NAME ".PARISC.unwind"
72 #endif
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$"
81 /* Object file formats specify relocation types. */
82 typedef int reloc_type;
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
88 /* How to generate a relocation. */
89 #define hppa_gen_reloc_type hppa_som_gen_reloc_type
91 /* Object file formats specify BFD symbol types. */
92 typedef som_symbol_type obj_symbol_type;
94 /* This apparently isn't in older versions of hpux reloc.h. */
95 #ifndef R_DLT_REL
96 #define R_DLT_REL 0x78
97 #endif
98 #endif
100 #ifndef R_N0SEL
101 #define R_N0SEL 0xd8
102 #endif
104 #ifndef R_N1SEL
105 #define R_N1SEL 0xd9
106 #endif
108 /* Various structures and types used internally in tc-hppa.c. */
110 /* Unwind table and descriptor. FIXME: Sync this with GDB version. */
112 struct unwind_desc
114 unsigned int cannot_unwind:1;
115 unsigned int millicode:1;
116 unsigned int millicode_save_rest:1;
117 unsigned int region_desc:2;
118 unsigned int save_sr:2;
119 unsigned int entry_fr:4;
120 unsigned int entry_gr:5;
121 unsigned int args_stored:1;
122 unsigned int call_fr:5;
123 unsigned int call_gr:5;
124 unsigned int save_sp:1;
125 unsigned int save_rp:1;
126 unsigned int save_rp_in_frame:1;
127 unsigned int extn_ptr_defined:1;
128 unsigned int cleanup_defined:1;
130 unsigned int hpe_interrupt_marker:1;
131 unsigned int hpux_interrupt_marker:1;
132 unsigned int reserved:3;
133 unsigned int frame_size:27;
136 struct unwind_table
138 /* Starting and ending offsets of the region described by
139 descriptor. */
140 unsigned int start_offset;
141 unsigned int end_offset;
142 struct unwind_desc descriptor;
145 /* This structure is used by the .callinfo, .enter, .leave pseudo-ops to
146 control the entry and exit code they generate. It is also used in
147 creation of the correct stack unwind descriptors.
149 NOTE: GAS does not support .enter and .leave for the generation of
150 prologues and epilogues. FIXME.
152 The fields in structure roughly correspond to the arguments available on the
153 .callinfo pseudo-op. */
155 struct call_info
157 /* The unwind descriptor being built. */
158 struct unwind_table ci_unwind;
160 /* Name of this function. */
161 symbolS *start_symbol;
163 /* (temporary) symbol used to mark the end of this function. */
164 symbolS *end_symbol;
166 /* Next entry in the chain. */
167 struct call_info *ci_next;
170 /* Operand formats for FP instructions. Note not all FP instructions
171 allow all four formats to be used (for example fmpysub only allows
172 SGL and DBL). */
173 typedef enum
175 SGL, DBL, ILLEGAL_FMT, QUAD, W, UW, DW, UDW, QW, UQW
177 fp_operand_format;
179 /* This fully describes the symbol types which may be attached to
180 an EXPORT or IMPORT directive. Only SOM uses this formation
181 (ELF has no need for it). */
182 typedef enum
184 SYMBOL_TYPE_UNKNOWN,
185 SYMBOL_TYPE_ABSOLUTE,
186 SYMBOL_TYPE_CODE,
187 SYMBOL_TYPE_DATA,
188 SYMBOL_TYPE_ENTRY,
189 SYMBOL_TYPE_MILLICODE,
190 SYMBOL_TYPE_PLABEL,
191 SYMBOL_TYPE_PRI_PROG,
192 SYMBOL_TYPE_SEC_PROG,
194 pa_symbol_type;
196 /* This structure contains information needed to assemble
197 individual instructions. */
198 struct pa_it
200 /* Holds the opcode after parsing by pa_ip. */
201 unsigned long opcode;
203 /* Holds an expression associated with the current instruction. */
204 expressionS exp;
206 /* Does this instruction use PC-relative addressing. */
207 int pcrel;
209 /* Floating point formats for operand1 and operand2. */
210 fp_operand_format fpof1;
211 fp_operand_format fpof2;
213 /* Whether or not we saw a truncation request on an fcnv insn. */
214 int trunc;
216 /* Holds the field selector for this instruction
217 (for example L%, LR%, etc). */
218 long field_selector;
220 /* Holds any argument relocation bits associated with this
221 instruction. (instruction should be some sort of call). */
222 long arg_reloc;
224 /* The format specification for this instruction. */
225 int format;
227 /* The relocation (if any) associated with this instruction. */
228 reloc_type reloc;
231 /* PA-89 floating point registers are arranged like this:
234 +--------------+--------------+
235 | 0 or 16L | 16 or 16R |
236 +--------------+--------------+
237 | 1 or 17L | 17 or 17R |
238 +--------------+--------------+
239 | | |
241 . . .
242 . . .
243 . . .
245 | | |
246 +--------------+--------------+
247 | 14 or 30L | 30 or 30R |
248 +--------------+--------------+
249 | 15 or 31L | 31 or 31R |
250 +--------------+--------------+
253 The following is a version of pa_parse_number that
254 handles the L/R notation and returns the correct
255 value to put into the instruction register field.
256 The correct value to put into the instruction is
257 encoded in the structure 'pa_11_fp_reg_struct'. */
259 struct pa_11_fp_reg_struct
261 /* The register number. */
262 char number_part;
264 /* L/R selector. */
265 char l_r_select;
268 /* Additional information needed to build argument relocation stubs. */
269 struct call_desc
271 /* The argument relocation specification. */
272 unsigned int arg_reloc;
274 /* Number of arguments. */
275 unsigned int arg_count;
278 #ifdef OBJ_SOM
279 /* This structure defines an entry in the subspace dictionary
280 chain. */
282 struct subspace_dictionary_chain
284 /* Nonzero if this space has been defined by the user code. */
285 unsigned int ssd_defined;
287 /* Name of this subspace. */
288 char *ssd_name;
290 /* GAS segment and subsegment associated with this subspace. */
291 asection *ssd_seg;
292 int ssd_subseg;
294 /* Next space in the subspace dictionary chain. */
295 struct subspace_dictionary_chain *ssd_next;
298 typedef struct subspace_dictionary_chain ssd_chain_struct;
300 /* This structure defines an entry in the subspace dictionary
301 chain. */
303 struct space_dictionary_chain
305 /* Nonzero if this space has been defined by the user code or
306 as a default space. */
307 unsigned int sd_defined;
309 /* Nonzero if this spaces has been defined by the user code. */
310 unsigned int sd_user_defined;
312 /* The space number (or index). */
313 unsigned int sd_spnum;
315 /* The name of this subspace. */
316 char *sd_name;
318 /* GAS segment to which this subspace corresponds. */
319 asection *sd_seg;
321 /* Current subsegment number being used. */
322 int sd_last_subseg;
324 /* The chain of subspaces contained within this space. */
325 ssd_chain_struct *sd_subspaces;
327 /* The next entry in the space dictionary chain. */
328 struct space_dictionary_chain *sd_next;
331 typedef struct space_dictionary_chain sd_chain_struct;
333 /* This structure defines attributes of the default subspace
334 dictionary entries. */
336 struct default_subspace_dict
338 /* Name of the subspace. */
339 char *name;
341 /* FIXME. Is this still needed? */
342 char defined;
344 /* Nonzero if this subspace is loadable. */
345 char loadable;
347 /* Nonzero if this subspace contains only code. */
348 char code_only;
350 /* Nonzero if this is a common subspace. */
351 char common;
353 /* Nonzero if this is a common subspace which allows symbols
354 to be multiply defined. */
355 char dup_common;
357 /* Nonzero if this subspace should be zero filled. */
358 char zero;
360 /* Sort key for this subspace. */
361 unsigned char sort;
363 /* Access control bits for this subspace. Can represent RWX access
364 as well as privilege level changes for gateways. */
365 int access;
367 /* Index of containing space. */
368 int space_index;
370 /* Alignment (in bytes) of this subspace. */
371 int alignment;
373 /* Quadrant within space where this subspace should be loaded. */
374 int quadrant;
376 /* An index into the default spaces array. */
377 int def_space_index;
379 /* Subsegment associated with this subspace. */
380 subsegT subsegment;
383 /* This structure defines attributes of the default space
384 dictionary entries. */
386 struct default_space_dict
388 /* Name of the space. */
389 char *name;
391 /* Space number. It is possible to identify spaces within
392 assembly code numerically! */
393 int spnum;
395 /* Nonzero if this space is loadable. */
396 char loadable;
398 /* Nonzero if this space is "defined". FIXME is still needed */
399 char defined;
401 /* Nonzero if this space can not be shared. */
402 char private;
404 /* Sort key for this space. */
405 unsigned char sort;
407 /* Segment associated with this space. */
408 asection *segment;
410 #endif
412 /* Structure for previous label tracking. Needed so that alignments,
413 callinfo declarations, etc can be easily attached to a particular
414 label. */
415 typedef struct label_symbol_struct
417 struct symbol *lss_label;
418 #ifdef OBJ_SOM
419 sd_chain_struct *lss_space;
420 #endif
421 #ifdef OBJ_ELF
422 segT lss_segment;
423 #endif
424 struct label_symbol_struct *lss_next;
426 label_symbol_struct;
428 /* Extra information needed to perform fixups (relocations) on the PA. */
429 struct hppa_fix_struct
431 /* The field selector. */
432 enum hppa_reloc_field_selector_type_alt fx_r_field;
434 /* Type of fixup. */
435 int fx_r_type;
437 /* Format of fixup. */
438 int fx_r_format;
440 /* Argument relocation bits. */
441 long fx_arg_reloc;
443 /* The segment this fixup appears in. */
444 segT segment;
447 /* Structure to hold information about predefined registers. */
449 struct pd_reg
451 char *name;
452 int value;
455 /* This structure defines the mapping from a FP condition string
456 to a condition number which can be recorded in an instruction. */
457 struct fp_cond_map
459 char *string;
460 int cond;
463 /* This structure defines a mapping from a field selector
464 string to a field selector type. */
465 struct selector_entry
467 char *prefix;
468 int field_selector;
471 /* Prototypes for functions local to tc-hppa.c. */
473 #ifdef OBJ_SOM
474 static void pa_check_current_space_and_subspace PARAMS ((void));
475 #endif
477 static fp_operand_format pa_parse_fp_format PARAMS ((char **s));
478 static void pa_cons PARAMS ((int));
479 static void pa_data PARAMS ((int));
480 static void pa_float_cons PARAMS ((int));
481 static void pa_fill PARAMS ((int));
482 static void pa_lcomm PARAMS ((int));
483 static void pa_lsym PARAMS ((int));
484 static void pa_stringer PARAMS ((int));
485 static void pa_text PARAMS ((int));
486 static void pa_version PARAMS ((int));
487 static int pa_parse_fp_cmp_cond PARAMS ((char **));
488 static int get_expression PARAMS ((char *));
489 static int pa_get_absolute_expression PARAMS ((struct pa_it *, char **));
490 static int evaluate_absolute PARAMS ((struct pa_it *));
491 static unsigned int pa_build_arg_reloc PARAMS ((char *));
492 static unsigned int pa_align_arg_reloc PARAMS ((unsigned int, unsigned int));
493 static int pa_parse_nullif PARAMS ((char **));
494 static int pa_parse_nonneg_cmpsub_cmpltr PARAMS ((char **, int));
495 static int pa_parse_neg_cmpsub_cmpltr PARAMS ((char **, int));
496 static int pa_parse_neg_add_cmpltr PARAMS ((char **, int));
497 static int pa_parse_nonneg_add_cmpltr PARAMS ((char **, int));
498 static int pa_parse_cmpb_64_cmpltr PARAMS ((char **));
499 static int pa_parse_cmpib_64_cmpltr PARAMS ((char **));
500 static int pa_parse_addb_64_cmpltr PARAMS ((char **));
501 static void pa_block PARAMS ((int));
502 static void pa_brtab PARAMS ((int));
503 static void pa_try PARAMS ((int));
504 static void pa_call PARAMS ((int));
505 static void pa_call_args PARAMS ((struct call_desc *));
506 static void pa_callinfo PARAMS ((int));
507 static void pa_code PARAMS ((int));
508 static void pa_comm PARAMS ((int));
509 static void pa_copyright PARAMS ((int));
510 static void pa_end PARAMS ((int));
511 static void pa_enter PARAMS ((int));
512 static void pa_entry PARAMS ((int));
513 static void pa_equ PARAMS ((int));
514 static void pa_exit PARAMS ((int));
515 static void pa_export PARAMS ((int));
516 static void pa_type_args PARAMS ((symbolS *, int));
517 static void pa_import PARAMS ((int));
518 static void pa_label PARAMS ((int));
519 static void pa_leave PARAMS ((int));
520 static void pa_level PARAMS ((int));
521 static void pa_origin PARAMS ((int));
522 static void pa_proc PARAMS ((int));
523 static void pa_procend PARAMS ((int));
524 static void pa_param PARAMS ((int));
525 static void pa_undefine_label PARAMS ((void));
526 static int need_pa11_opcode PARAMS ((struct pa_it *,
527 struct pa_11_fp_reg_struct *));
528 static int pa_parse_number PARAMS ((char **, struct pa_11_fp_reg_struct *));
529 static label_symbol_struct *pa_get_label PARAMS ((void));
530 #ifdef OBJ_SOM
531 static int log2 PARAMS ((int));
532 static void pa_compiler PARAMS ((int));
533 static void pa_align PARAMS ((int));
534 static void pa_space PARAMS ((int));
535 static void pa_spnum PARAMS ((int));
536 static void pa_subspace PARAMS ((int));
537 static sd_chain_struct *create_new_space PARAMS ((char *, int, int,
538 int, int, int,
539 asection *, int));
540 static ssd_chain_struct *create_new_subspace PARAMS ((sd_chain_struct *,
541 char *, int, int,
542 int, int, int,
543 int, int, int, int,
544 int, asection *));
545 static ssd_chain_struct *update_subspace PARAMS ((sd_chain_struct *,
546 char *, int, int, int,
547 int, int, int, int,
548 int, int, int,
549 asection *));
550 static sd_chain_struct *is_defined_space PARAMS ((char *));
551 static ssd_chain_struct *is_defined_subspace PARAMS ((char *));
552 static sd_chain_struct *pa_segment_to_space PARAMS ((asection *));
553 static ssd_chain_struct *pa_subsegment_to_subspace PARAMS ((asection *,
554 subsegT));
555 static sd_chain_struct *pa_find_space_by_number PARAMS ((int));
556 static unsigned int pa_subspace_start PARAMS ((sd_chain_struct *, int));
557 static sd_chain_struct *pa_parse_space_stmt PARAMS ((char *, int));
558 static int pa_next_subseg PARAMS ((sd_chain_struct *));
559 static void pa_spaces_begin PARAMS ((void));
560 #endif
561 static void pa_ip PARAMS ((char *));
562 static void fix_new_hppa PARAMS ((fragS *, int, int, symbolS *,
563 long, expressionS *, int,
564 bfd_reloc_code_real_type,
565 enum hppa_reloc_field_selector_type_alt,
566 int, long, int *));
567 static int is_end_of_statement PARAMS ((void));
568 static int reg_name_search PARAMS ((char *));
569 static int pa_chk_field_selector PARAMS ((char **));
570 static int is_same_frag PARAMS ((fragS *, fragS *));
571 static void process_exit PARAMS ((void));
572 static unsigned int pa_stringer_aux PARAMS ((char *));
573 static fp_operand_format pa_parse_fp_cnv_format PARAMS ((char **s));
574 static int pa_parse_ftest_gfx_completer PARAMS ((char **));
576 #ifdef OBJ_ELF
577 static void hppa_elf_mark_end_of_function PARAMS ((void));
578 static void pa_build_unwind_subspace PARAMS ((struct call_info *));
579 #endif
581 /* File and gloally scoped variable declarations. */
583 #ifdef OBJ_SOM
584 /* Root and final entry in the space chain. */
585 static sd_chain_struct *space_dict_root;
586 static sd_chain_struct *space_dict_last;
588 /* The current space and subspace. */
589 static sd_chain_struct *current_space;
590 static ssd_chain_struct *current_subspace;
591 #endif
593 /* Root of the call_info chain. */
594 static struct call_info *call_info_root;
596 /* The last call_info (for functions) structure
597 seen so it can be associated with fixups and
598 function labels. */
599 static struct call_info *last_call_info;
601 /* The last call description (for actual calls). */
602 static struct call_desc last_call_desc;
604 /* handle of the OPCODE hash table */
605 static struct hash_control *op_hash = NULL;
607 /* This array holds the chars that always start a comment. If the
608 pre-processor is disabled, these aren't very useful. */
609 const char comment_chars[] = ";";
611 /* Table of pseudo ops for the PA. FIXME -- how many of these
612 are now redundant with the overall GAS and the object file
613 dependent tables? */
614 const pseudo_typeS md_pseudo_table[] =
616 /* align pseudo-ops on the PA specify the actual alignment requested,
617 not the log2 of the requested alignment. */
618 #ifdef OBJ_SOM
619 {"align", pa_align, 8},
620 #endif
621 #ifdef OBJ_ELF
622 {"align", s_align_bytes, 8},
623 #endif
624 {"begin_brtab", pa_brtab, 1},
625 {"begin_try", pa_try, 1},
626 {"block", pa_block, 1},
627 {"blockz", pa_block, 0},
628 {"byte", pa_cons, 1},
629 {"call", pa_call, 0},
630 {"callinfo", pa_callinfo, 0},
631 {"code", pa_code, 0},
632 {"comm", pa_comm, 0},
633 #ifdef OBJ_SOM
634 {"compiler", pa_compiler, 0},
635 #endif
636 {"copyright", pa_copyright, 0},
637 {"data", pa_data, 0},
638 {"double", pa_float_cons, 'd'},
639 {"dword", pa_cons, 8},
640 {"end", pa_end, 0},
641 {"end_brtab", pa_brtab, 0},
642 {"end_try", pa_try, 0},
643 {"enter", pa_enter, 0},
644 {"entry", pa_entry, 0},
645 {"equ", pa_equ, 0},
646 {"exit", pa_exit, 0},
647 {"export", pa_export, 0},
648 #ifdef OBJ_ELF
649 { "file", dwarf2_directive_file, 0 },
650 #endif
651 {"fill", pa_fill, 0},
652 {"float", pa_float_cons, 'f'},
653 {"half", pa_cons, 2},
654 {"import", pa_import, 0},
655 {"int", pa_cons, 4},
656 {"label", pa_label, 0},
657 {"lcomm", pa_lcomm, 0},
658 {"leave", pa_leave, 0},
659 {"level", pa_level, 0},
660 #ifdef OBJ_ELF
661 { "loc", dwarf2_directive_loc, 0 },
662 #endif
663 {"long", pa_cons, 4},
664 {"lsym", pa_lsym, 0},
665 #ifdef OBJ_SOM
666 {"nsubspa", pa_subspace, 1},
667 #endif
668 {"octa", pa_cons, 16},
669 {"org", pa_origin, 0},
670 {"origin", pa_origin, 0},
671 {"param", pa_param, 0},
672 {"proc", pa_proc, 0},
673 {"procend", pa_procend, 0},
674 {"quad", pa_cons, 8},
675 {"reg", pa_equ, 1},
676 {"short", pa_cons, 2},
677 {"single", pa_float_cons, 'f'},
678 #ifdef OBJ_SOM
679 {"space", pa_space, 0},
680 {"spnum", pa_spnum, 0},
681 #endif
682 {"string", pa_stringer, 0},
683 {"stringz", pa_stringer, 1},
684 #ifdef OBJ_SOM
685 {"subspa", pa_subspace, 0},
686 #endif
687 {"text", pa_text, 0},
688 {"version", pa_version, 0},
689 {"word", pa_cons, 4},
690 {NULL, 0, 0}
693 /* This array holds the chars that only start a comment at the beginning of
694 a line. If the line seems to have the form '# 123 filename'
695 .line and .file directives will appear in the pre-processed output.
697 Note that input_file.c hand checks for '#' at the beginning of the
698 first line of the input file. This is because the compiler outputs
699 #NO_APP at the beginning of its output.
701 Also note that C style comments will always work. */
702 const char line_comment_chars[] = "#";
704 /* This array holds the characters which act as line separators. */
705 const char line_separator_chars[] = "!";
707 /* Chars that can be used to separate mant from exp in floating point nums. */
708 const char EXP_CHARS[] = "eE";
710 /* Chars that mean this number is a floating point constant.
711 As in 0f12.456 or 0d1.2345e12.
713 Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
714 changed in read.c. Ideally it shouldn't hae to know abou it at
715 all, but nothing is ideal around here. */
716 const char FLT_CHARS[] = "rRsSfFdDxXpP";
718 static struct pa_it the_insn;
720 /* Points to the end of an expression just parsed by get_expressoin
721 and friends. FIXME. This shouldn't be handled with a file-global
722 variable. */
723 static char *expr_end;
725 /* Nonzero if a .callinfo appeared within the current procedure. */
726 static int callinfo_found;
728 /* Nonzero if the assembler is currently within a .entry/.exit pair. */
729 static int within_entry_exit;
731 /* Nonzero if the assembler is currently within a procedure definition. */
732 static int within_procedure;
734 /* Handle on strucutre which keep track of the last symbol
735 seen in each subspace. */
736 static label_symbol_struct *label_symbols_rootp = NULL;
738 /* Holds the last field selector. */
739 static int hppa_field_selector;
741 /* Nonzero when strict syntax checking is enabled. Zero otherwise.
743 Each opcode in the table has a flag which indicates whether or not
744 strict syntax checking should be enabled for that instruction. */
745 static int strict = 0;
747 #ifdef OBJ_SOM
748 /* A dummy bfd symbol so that all relocations have symbols of some kind. */
749 static symbolS *dummy_symbol;
750 #endif
752 /* Nonzero if errors are to be printed. */
753 static int print_errors = 1;
755 /* List of registers that are pre-defined:
757 Each general register has one predefined name of the form
758 %r<REGNUM> which has the value <REGNUM>.
760 Space and control registers are handled in a similar manner,
761 but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
763 Likewise for the floating point registers, but of the form
764 %fr<REGNUM>. Floating point registers have additional predefined
765 names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
766 again have the value <REGNUM>.
768 Many registers also have synonyms:
770 %r26 - %r23 have %arg0 - %arg3 as synonyms
771 %r28 - %r29 have %ret0 - %ret1 as synonyms
772 %r30 has %sp as a synonym
773 %r27 has %dp as a synonym
774 %r2 has %rp as a synonym
776 Almost every control register has a synonym; they are not listed
777 here for brevity.
779 The table is sorted. Suitable for searching by a binary search. */
781 static const struct pd_reg pre_defined_registers[] =
783 {"%arg0", 26},
784 {"%arg1", 25},
785 {"%arg2", 24},
786 {"%arg3", 23},
787 {"%cr0", 0},
788 {"%cr10", 10},
789 {"%cr11", 11},
790 {"%cr12", 12},
791 {"%cr13", 13},
792 {"%cr14", 14},
793 {"%cr15", 15},
794 {"%cr16", 16},
795 {"%cr17", 17},
796 {"%cr18", 18},
797 {"%cr19", 19},
798 {"%cr20", 20},
799 {"%cr21", 21},
800 {"%cr22", 22},
801 {"%cr23", 23},
802 {"%cr24", 24},
803 {"%cr25", 25},
804 {"%cr26", 26},
805 {"%cr27", 27},
806 {"%cr28", 28},
807 {"%cr29", 29},
808 {"%cr30", 30},
809 {"%cr31", 31},
810 {"%cr8", 8},
811 {"%cr9", 9},
812 {"%dp", 27},
813 {"%eiem", 15},
814 {"%eirr", 23},
815 {"%fr0", 0},
816 {"%fr0l", 0},
817 {"%fr0r", 0},
818 {"%fr1", 1},
819 {"%fr10", 10},
820 {"%fr10l", 10},
821 {"%fr10r", 10},
822 {"%fr11", 11},
823 {"%fr11l", 11},
824 {"%fr11r", 11},
825 {"%fr12", 12},
826 {"%fr12l", 12},
827 {"%fr12r", 12},
828 {"%fr13", 13},
829 {"%fr13l", 13},
830 {"%fr13r", 13},
831 {"%fr14", 14},
832 {"%fr14l", 14},
833 {"%fr14r", 14},
834 {"%fr15", 15},
835 {"%fr15l", 15},
836 {"%fr15r", 15},
837 {"%fr16", 16},
838 {"%fr16l", 16},
839 {"%fr16r", 16},
840 {"%fr17", 17},
841 {"%fr17l", 17},
842 {"%fr17r", 17},
843 {"%fr18", 18},
844 {"%fr18l", 18},
845 {"%fr18r", 18},
846 {"%fr19", 19},
847 {"%fr19l", 19},
848 {"%fr19r", 19},
849 {"%fr1l", 1},
850 {"%fr1r", 1},
851 {"%fr2", 2},
852 {"%fr20", 20},
853 {"%fr20l", 20},
854 {"%fr20r", 20},
855 {"%fr21", 21},
856 {"%fr21l", 21},
857 {"%fr21r", 21},
858 {"%fr22", 22},
859 {"%fr22l", 22},
860 {"%fr22r", 22},
861 {"%fr23", 23},
862 {"%fr23l", 23},
863 {"%fr23r", 23},
864 {"%fr24", 24},
865 {"%fr24l", 24},
866 {"%fr24r", 24},
867 {"%fr25", 25},
868 {"%fr25l", 25},
869 {"%fr25r", 25},
870 {"%fr26", 26},
871 {"%fr26l", 26},
872 {"%fr26r", 26},
873 {"%fr27", 27},
874 {"%fr27l", 27},
875 {"%fr27r", 27},
876 {"%fr28", 28},
877 {"%fr28l", 28},
878 {"%fr28r", 28},
879 {"%fr29", 29},
880 {"%fr29l", 29},
881 {"%fr29r", 29},
882 {"%fr2l", 2},
883 {"%fr2r", 2},
884 {"%fr3", 3},
885 {"%fr30", 30},
886 {"%fr30l", 30},
887 {"%fr30r", 30},
888 {"%fr31", 31},
889 {"%fr31l", 31},
890 {"%fr31r", 31},
891 {"%fr3l", 3},
892 {"%fr3r", 3},
893 {"%fr4", 4},
894 {"%fr4l", 4},
895 {"%fr4r", 4},
896 {"%fr5", 5},
897 {"%fr5l", 5},
898 {"%fr5r", 5},
899 {"%fr6", 6},
900 {"%fr6l", 6},
901 {"%fr6r", 6},
902 {"%fr7", 7},
903 {"%fr7l", 7},
904 {"%fr7r", 7},
905 {"%fr8", 8},
906 {"%fr8l", 8},
907 {"%fr8r", 8},
908 {"%fr9", 9},
909 {"%fr9l", 9},
910 {"%fr9r", 9},
911 {"%hta", 25},
912 {"%iir", 19},
913 {"%ior", 21},
914 {"%ipsw", 22},
915 {"%isr", 20},
916 {"%itmr", 16},
917 {"%iva", 14},
918 {"%pcoq", 18},
919 {"%pcsq", 17},
920 {"%pidr1", 8},
921 {"%pidr2", 9},
922 {"%pidr3", 12},
923 {"%pidr4", 13},
924 {"%ppda", 24},
925 {"%r0", 0},
926 {"%r1", 1},
927 {"%r10", 10},
928 {"%r11", 11},
929 {"%r12", 12},
930 {"%r13", 13},
931 {"%r14", 14},
932 {"%r15", 15},
933 {"%r16", 16},
934 {"%r17", 17},
935 {"%r18", 18},
936 {"%r19", 19},
937 {"%r2", 2},
938 {"%r20", 20},
939 {"%r21", 21},
940 {"%r22", 22},
941 {"%r23", 23},
942 {"%r24", 24},
943 {"%r25", 25},
944 {"%r26", 26},
945 {"%r27", 27},
946 {"%r28", 28},
947 {"%r29", 29},
948 {"%r3", 3},
949 {"%r30", 30},
950 {"%r31", 31},
951 {"%r4", 4},
952 {"%r5", 5},
953 {"%r6", 6},
954 {"%r7", 7},
955 {"%r8", 8},
956 {"%r9", 9},
957 {"%rctr", 0},
958 {"%ret0", 28},
959 {"%ret1", 29},
960 {"%rp", 2},
961 {"%sar", 11},
962 {"%sp", 30},
963 {"%sr0", 0},
964 {"%sr1", 1},
965 {"%sr2", 2},
966 {"%sr3", 3},
967 {"%sr4", 4},
968 {"%sr5", 5},
969 {"%sr6", 6},
970 {"%sr7", 7},
971 {"%tr0", 24},
972 {"%tr1", 25},
973 {"%tr2", 26},
974 {"%tr3", 27},
975 {"%tr4", 28},
976 {"%tr5", 29},
977 {"%tr6", 30},
978 {"%tr7", 31}
981 /* This table is sorted by order of the length of the string. This is
982 so we check for <> before we check for <. If we had a <> and checked
983 for < first, we would get a false match. */
984 static const struct fp_cond_map fp_cond_map[] =
986 {"false?", 0},
987 {"false", 1},
988 {"true?", 30},
989 {"true", 31},
990 {"!<=>", 3},
991 {"!?>=", 8},
992 {"!?<=", 16},
993 {"!<>", 7},
994 {"!>=", 11},
995 {"!?>", 12},
996 {"?<=", 14},
997 {"!<=", 19},
998 {"!?<", 20},
999 {"?>=", 22},
1000 {"!?=", 24},
1001 {"!=t", 27},
1002 {"<=>", 29},
1003 {"=t", 5},
1004 {"?=", 6},
1005 {"?<", 10},
1006 {"<=", 13},
1007 {"!>", 15},
1008 {"?>", 18},
1009 {">=", 21},
1010 {"!<", 23},
1011 {"<>", 25},
1012 {"!=", 26},
1013 {"!?", 28},
1014 {"?", 2},
1015 {"=", 4},
1016 {"<", 9},
1017 {">", 17}
1020 static const struct selector_entry selector_table[] =
1022 {"f", e_fsel},
1023 {"l", e_lsel},
1024 {"ld", e_ldsel},
1025 {"lp", e_lpsel},
1026 {"lr", e_lrsel},
1027 {"ls", e_lssel},
1028 {"lt", e_ltsel},
1029 {"ltp", e_ltpsel},
1030 {"n", e_nsel},
1031 {"nl", e_nlsel},
1032 {"nlr", e_nlrsel},
1033 {"p", e_psel},
1034 {"r", e_rsel},
1035 {"rd", e_rdsel},
1036 {"rp", e_rpsel},
1037 {"rr", e_rrsel},
1038 {"rs", e_rssel},
1039 {"rt", e_rtsel},
1040 {"rtp", e_rtpsel},
1041 {"t", e_tsel},
1044 #ifdef OBJ_SOM
1045 /* default space and subspace dictionaries */
1047 #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
1048 #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
1050 /* pre-defined subsegments (subspaces) for the HPPA. */
1051 #define SUBSEG_CODE 0
1052 #define SUBSEG_LIT 1
1053 #define SUBSEG_MILLI 2
1054 #define SUBSEG_DATA 0
1055 #define SUBSEG_BSS 2
1056 #define SUBSEG_UNWIND 3
1057 #define SUBSEG_GDB_STRINGS 0
1058 #define SUBSEG_GDB_SYMBOLS 1
1060 static struct default_subspace_dict pa_def_subspaces[] =
1062 {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, SUBSEG_CODE},
1063 {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, SUBSEG_DATA},
1064 {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, SUBSEG_LIT},
1065 {"$MILLICODE$", 1, 1, 0, 0, 0, 0, 8, 0x2c, 0, 8, 0, 0, SUBSEG_MILLI},
1066 {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, SUBSEG_BSS},
1067 {NULL, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
1070 static struct default_space_dict pa_def_spaces[] =
1072 {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL},
1073 {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL},
1074 {NULL, 0, 0, 0, 0, 0, ASEC_NULL}
1077 /* Misc local definitions used by the assembler. */
1079 /* These macros are used to maintain spaces/subspaces. */
1080 #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined
1081 #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
1082 #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum
1083 #define SPACE_NAME(space_chain) (space_chain)->sd_name
1085 #define SUBSPACE_DEFINED(ss_chain) (ss_chain)->ssd_defined
1086 #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name
1087 #endif
1089 /* Return nonzero if the string pointed to by S potentially represents
1090 a right or left half of a FP register */
1091 #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
1092 #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
1094 /* Insert FIELD into OPCODE starting at bit START. Continue pa_ip
1095 main loop after insertion. */
1097 #define INSERT_FIELD_AND_CONTINUE(OPCODE, FIELD, START) \
1099 ((OPCODE) |= (FIELD) << (START)); \
1100 continue; \
1103 /* Simple range checking for FIELD againt HIGH and LOW bounds.
1104 IGNORE is used to suppress the error message. */
1106 #define CHECK_FIELD(FIELD, HIGH, LOW, IGNORE) \
1108 if ((FIELD) > (HIGH) || (FIELD) < (LOW)) \
1110 if (! IGNORE) \
1111 as_bad (_("Field out of range [%d..%d] (%d)."), (LOW), (HIGH), \
1112 (int) (FIELD));\
1113 break; \
1117 /* Simple alignment checking for FIELD againt ALIGN (a power of two).
1118 IGNORE is used to suppress the error message. */
1120 #define CHECK_ALIGN(FIELD, ALIGN, IGNORE) \
1122 if ((FIELD) & ((ALIGN) - 1)) \
1124 if (! IGNORE) \
1125 as_bad (_("Field not properly aligned [%d] (%d)."), (ALIGN), \
1126 (int) (FIELD));\
1127 break; \
1131 #define is_DP_relative(exp) \
1132 ((exp).X_op == O_subtract \
1133 && strcmp (S_GET_NAME ((exp).X_op_symbol), "$global$") == 0)
1135 #define is_PC_relative(exp) \
1136 ((exp).X_op == O_subtract \
1137 && strcmp (S_GET_NAME ((exp).X_op_symbol), "$PIC_pcrel$0") == 0)
1139 /* We need some complex handling for stabs (sym1 - sym2). Luckily, we'll
1140 always be able to reduce the expression to a constant, so we don't
1141 need real complex handling yet. */
1142 #define is_complex(exp) \
1143 ((exp).X_op != O_constant && (exp).X_op != O_symbol)
1145 /* Actual functions to implement the PA specific code for the assembler. */
1147 /* Called before writing the object file. Make sure entry/exit and
1148 proc/procend pairs match. */
1150 void
1151 pa_check_eof ()
1153 if (within_entry_exit)
1154 as_fatal (_("Missing .exit\n"));
1156 if (within_procedure)
1157 as_fatal (_("Missing .procend\n"));
1160 /* Returns a pointer to the label_symbol_struct for the current space.
1161 or NULL if no label_symbol_struct exists for the current space. */
1163 static label_symbol_struct *
1164 pa_get_label ()
1166 label_symbol_struct *label_chain;
1168 for (label_chain = label_symbols_rootp;
1169 label_chain;
1170 label_chain = label_chain->lss_next)
1172 #ifdef OBJ_SOM
1173 if (current_space == label_chain->lss_space && label_chain->lss_label)
1174 return label_chain;
1175 #endif
1176 #ifdef OBJ_ELF
1177 if (now_seg == label_chain->lss_segment && label_chain->lss_label)
1178 return label_chain;
1179 #endif
1182 return NULL;
1185 /* Defines a label for the current space. If one is already defined,
1186 this function will replace it with the new label. */
1188 void
1189 pa_define_label (symbol)
1190 symbolS *symbol;
1192 label_symbol_struct *label_chain = pa_get_label ();
1194 if (label_chain)
1195 label_chain->lss_label = symbol;
1196 else
1198 /* Create a new label entry and add it to the head of the chain. */
1199 label_chain
1200 = (label_symbol_struct *) xmalloc (sizeof (label_symbol_struct));
1201 label_chain->lss_label = symbol;
1202 #ifdef OBJ_SOM
1203 label_chain->lss_space = current_space;
1204 #endif
1205 #ifdef OBJ_ELF
1206 label_chain->lss_segment = now_seg;
1207 #endif
1208 label_chain->lss_next = NULL;
1210 if (label_symbols_rootp)
1211 label_chain->lss_next = label_symbols_rootp;
1213 label_symbols_rootp = label_chain;
1217 /* Removes a label definition for the current space.
1218 If there is no label_symbol_struct entry, then no action is taken. */
1220 static void
1221 pa_undefine_label ()
1223 label_symbol_struct *label_chain;
1224 label_symbol_struct *prev_label_chain = NULL;
1226 for (label_chain = label_symbols_rootp;
1227 label_chain;
1228 label_chain = label_chain->lss_next)
1230 if (1
1231 #ifdef OBJ_SOM
1232 && current_space == label_chain->lss_space && label_chain->lss_label
1233 #endif
1234 #ifdef OBJ_ELF
1235 && now_seg == label_chain->lss_segment && label_chain->lss_label
1236 #endif
1239 /* Remove the label from the chain and free its memory. */
1240 if (prev_label_chain)
1241 prev_label_chain->lss_next = label_chain->lss_next;
1242 else
1243 label_symbols_rootp = label_chain->lss_next;
1245 free (label_chain);
1246 break;
1248 prev_label_chain = label_chain;
1253 /* An HPPA-specific version of fix_new. This is required because the HPPA
1254 code needs to keep track of some extra stuff. Each call to fix_new_hppa
1255 results in the creation of an instance of an hppa_fix_struct. An
1256 hppa_fix_struct stores the extra information along with a pointer to the
1257 original fixS. This is attached to the original fixup via the
1258 tc_fix_data field. */
1260 static void
1261 fix_new_hppa (frag, where, size, add_symbol, offset, exp, pcrel,
1262 r_type, r_field, r_format, arg_reloc, unwind_bits)
1263 fragS *frag;
1264 int where;
1265 int size;
1266 symbolS *add_symbol;
1267 long offset;
1268 expressionS *exp;
1269 int pcrel;
1270 bfd_reloc_code_real_type r_type;
1271 enum hppa_reloc_field_selector_type_alt r_field;
1272 int r_format;
1273 long arg_reloc;
1274 int* unwind_bits ATTRIBUTE_UNUSED;
1276 fixS *new_fix;
1278 struct hppa_fix_struct *hppa_fix = (struct hppa_fix_struct *)
1279 obstack_alloc (&notes, sizeof (struct hppa_fix_struct));
1281 if (exp != NULL)
1282 new_fix = fix_new_exp (frag, where, size, exp, pcrel, r_type);
1283 else
1284 new_fix = fix_new (frag, where, size, add_symbol, offset, pcrel, r_type);
1285 new_fix->tc_fix_data = (void *) hppa_fix;
1286 hppa_fix->fx_r_type = r_type;
1287 hppa_fix->fx_r_field = r_field;
1288 hppa_fix->fx_r_format = r_format;
1289 hppa_fix->fx_arg_reloc = arg_reloc;
1290 hppa_fix->segment = now_seg;
1291 #ifdef OBJ_SOM
1292 if (r_type == R_ENTRY || r_type == R_EXIT)
1293 new_fix->fx_offset = *unwind_bits;
1294 #endif
1296 /* foo-$global$ is used to access non-automatic storage. $global$
1297 is really just a marker and has served its purpose, so eliminate
1298 it now so as not to confuse write.c. */
1299 if (new_fix->fx_subsy
1300 && !strcmp (S_GET_NAME (new_fix->fx_subsy), "$global$"))
1301 new_fix->fx_subsy = NULL;
1304 /* Parse a .byte, .word, .long expression for the HPPA. Called by
1305 cons via the TC_PARSE_CONS_EXPRESSION macro. */
1307 void
1308 parse_cons_expression_hppa (exp)
1309 expressionS *exp;
1311 hppa_field_selector = pa_chk_field_selector (&input_line_pointer);
1312 expression (exp);
1315 /* This fix_new is called by cons via TC_CONS_FIX_NEW.
1316 hppa_field_selector is set by the parse_cons_expression_hppa. */
1318 void
1319 cons_fix_new_hppa (frag, where, size, exp)
1320 fragS *frag;
1321 int where;
1322 int size;
1323 expressionS *exp;
1325 unsigned int rel_type;
1327 /* Get a base relocation type. */
1328 if (is_DP_relative (*exp))
1329 rel_type = R_HPPA_GOTOFF;
1330 else if (is_complex (*exp))
1331 rel_type = R_HPPA_COMPLEX;
1332 else
1333 rel_type = R_HPPA;
1335 if (hppa_field_selector != e_psel && hppa_field_selector != e_fsel)
1336 as_warn (_("Invalid field selector. Assuming F%%."));
1338 fix_new_hppa (frag, where, size,
1339 (symbolS *) NULL, (offsetT) 0, exp, 0, rel_type,
1340 hppa_field_selector, size * 8, 0, NULL);
1342 /* Reset field selector to its default state. */
1343 hppa_field_selector = 0;
1346 /* This function is called once, at assembler startup time. It should
1347 set up all the tables, etc. that the MD part of the assembler will need. */
1349 void
1350 md_begin ()
1352 const char *retval = NULL;
1353 int lose = 0;
1354 unsigned int i = 0;
1356 last_call_info = NULL;
1357 call_info_root = NULL;
1359 /* Set the default machine type. */
1360 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 10))
1361 as_warn (_("could not set architecture and machine"));
1363 /* Folding of text and data segments fails miserably on the PA.
1364 Warn user and disable "-R" option. */
1365 if (flag_readonly_data_in_text)
1367 as_warn (_("-R option not supported on this target."));
1368 flag_readonly_data_in_text = 0;
1371 #ifdef OBJ_SOM
1372 pa_spaces_begin ();
1373 #endif
1375 op_hash = hash_new ();
1377 while (i < NUMOPCODES)
1379 const char *name = pa_opcodes[i].name;
1380 retval = hash_insert (op_hash, name, (struct pa_opcode *) &pa_opcodes[i]);
1381 if (retval != NULL && *retval != '\0')
1383 as_fatal (_("Internal error: can't hash `%s': %s\n"), name, retval);
1384 lose = 1;
1388 if ((pa_opcodes[i].match & pa_opcodes[i].mask)
1389 != pa_opcodes[i].match)
1391 fprintf (stderr, _("internal error: losing opcode: `%s' \"%s\"\n"),
1392 pa_opcodes[i].name, pa_opcodes[i].args);
1393 lose = 1;
1395 ++i;
1397 while (i < NUMOPCODES && !strcmp (pa_opcodes[i].name, name));
1400 if (lose)
1401 as_fatal (_("Broken assembler. No assembly attempted."));
1403 #ifdef OBJ_SOM
1404 /* SOM will change text_section. To make sure we never put
1405 anything into the old one switch to the new one now. */
1406 subseg_set (text_section, 0);
1407 #endif
1409 #ifdef OBJ_SOM
1410 dummy_symbol = symbol_find_or_make ("L$dummy");
1411 S_SET_SEGMENT (dummy_symbol, text_section);
1412 /* Force the symbol to be converted to a real symbol. */
1413 (void) symbol_get_bfdsym (dummy_symbol);
1414 #endif
1417 /* Assemble a single instruction storing it into a frag. */
1418 void
1419 md_assemble (str)
1420 char *str;
1422 char *to;
1424 /* The had better be something to assemble. */
1425 assert (str);
1427 /* If we are within a procedure definition, make sure we've
1428 defined a label for the procedure; handle case where the
1429 label was defined after the .PROC directive.
1431 Note there's not need to diddle with the segment or fragment
1432 for the label symbol in this case. We have already switched
1433 into the new $CODE$ subspace at this point. */
1434 if (within_procedure && last_call_info->start_symbol == NULL)
1436 label_symbol_struct *label_symbol = pa_get_label ();
1438 if (label_symbol)
1440 if (label_symbol->lss_label)
1442 last_call_info->start_symbol = label_symbol->lss_label;
1443 symbol_get_bfdsym (label_symbol->lss_label)->flags
1444 |= BSF_FUNCTION;
1445 #ifdef OBJ_SOM
1446 /* Also handle allocation of a fixup to hold the unwind
1447 information when the label appears after the proc/procend. */
1448 if (within_entry_exit)
1450 char *where = frag_more (0);
1452 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
1453 NULL, (offsetT) 0, NULL,
1454 0, R_HPPA_ENTRY, e_fsel, 0, 0,
1455 (int *)&last_call_info->ci_unwind.descriptor);
1457 #endif
1459 else
1460 as_bad (_("Missing function name for .PROC (corrupted label chain)"));
1462 else
1463 as_bad (_("Missing function name for .PROC"));
1466 /* Assemble the instruction. Results are saved into "the_insn". */
1467 pa_ip (str);
1469 /* Get somewhere to put the assembled instrution. */
1470 to = frag_more (4);
1472 /* Output the opcode. */
1473 md_number_to_chars (to, the_insn.opcode, 4);
1475 /* If necessary output more stuff. */
1476 if (the_insn.reloc != R_HPPA_NONE)
1477 fix_new_hppa (frag_now, (to - frag_now->fr_literal), 4, NULL,
1478 (offsetT) 0, &the_insn.exp, the_insn.pcrel,
1479 the_insn.reloc, the_insn.field_selector,
1480 the_insn.format, the_insn.arg_reloc, NULL);
1482 #ifdef OBJ_ELF
1483 if (debug_type == DEBUG_DWARF2)
1485 bfd_vma addr;
1487 /* First update the notion of the current source line. */
1488 dwarf2_where (&debug_line);
1490 /* We want the offset of the start of this instruction within the
1491 the current frag. */
1492 addr = frag_now->fr_address + frag_now_fix () - 4;
1494 /* And record the information. */
1495 dwarf2_gen_line_info (addr, &debug_line);
1497 #endif
1500 /* Do the real work for assembling a single instruction. Store results
1501 into the global "the_insn" variable. */
1503 static void
1504 pa_ip (str)
1505 char *str;
1507 char *error_message = "";
1508 char *s, c, *argstart, *name, *save_s;
1509 const char *args;
1510 int match = FALSE;
1511 int comma = 0;
1512 int cmpltr, nullif, flag, cond, num;
1513 unsigned long opcode;
1514 struct pa_opcode *insn;
1516 #ifdef OBJ_SOM
1517 /* We must have a valid space and subspace. */
1518 pa_check_current_space_and_subspace ();
1519 #endif
1521 /* Convert everything up to the first whitespace character into lower
1522 case. */
1523 for (s = str; *s != ' ' && *s != '\t' && *s != '\n' && *s != '\0'; s++)
1524 if (isupper (*s))
1525 *s = tolower (*s);
1527 /* Skip to something interesting. */
1528 for (s = str; isupper (*s) || islower (*s) || (*s >= '0' && *s <= '3'); ++s)
1531 switch (*s)
1534 case '\0':
1535 break;
1537 case ',':
1538 comma = 1;
1540 /*FALLTHROUGH */
1542 case ' ':
1543 *s++ = '\0';
1544 break;
1546 default:
1547 as_fatal (_("Unknown opcode: `%s'"), str);
1550 save_s = str;
1552 /* Look up the opcode in the has table. */
1553 if ((insn = (struct pa_opcode *) hash_find (op_hash, str)) == NULL)
1555 as_bad ("Unknown opcode: `%s'", str);
1556 return;
1559 if (comma)
1561 *--s = ',';
1564 /* Mark the location where arguments for the instruction start, then
1565 start processing them. */
1566 argstart = s;
1567 for (;;)
1569 /* Do some initialization. */
1570 opcode = insn->match;
1571 strict = (insn->flags & FLAG_STRICT);
1572 memset (&the_insn, 0, sizeof (the_insn));
1574 the_insn.reloc = R_HPPA_NONE;
1576 /* If this instruction is specific to a particular architecture,
1577 then set a new architecture. */
1578 /* But do not automatically promote to pa2.0. The automatic promotion
1579 crud is for compatability with HP's old assemblers only. */
1580 if (insn->arch < 20
1581 && bfd_get_mach (stdoutput) < insn->arch)
1583 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, insn->arch))
1584 as_warn (_("could not update architecture and machine"));
1586 else if (bfd_get_mach (stdoutput) < insn->arch)
1588 match = FALSE;
1589 goto failed;
1592 /* Build the opcode, checking as we go to make
1593 sure that the operands match. */
1594 for (args = insn->args;; ++args)
1596 /* Absorb white space in instruction. */
1597 while (*s == ' ' || *s == '\t')
1598 s++;
1600 switch (*args)
1603 /* End of arguments. */
1604 case '\0':
1605 if (*s == '\0')
1606 match = TRUE;
1607 break;
1609 case '+':
1610 if (*s == '+')
1612 ++s;
1613 continue;
1615 if (*s == '-')
1616 continue;
1617 break;
1619 /* These must match exactly. */
1620 case '(':
1621 case ')':
1622 case ',':
1623 case ' ':
1624 if (*s++ == *args)
1625 continue;
1626 break;
1628 /* Handle a 5 bit register or control register field at 10. */
1629 case 'b':
1630 case '^':
1631 /* This should be more strict. Small steps. */
1632 if (strict && *s != '%')
1633 break;
1634 num = pa_parse_number (&s, 0);
1635 CHECK_FIELD (num, 31, 0, 0);
1636 INSERT_FIELD_AND_CONTINUE (opcode, num, 21);
1638 /* Handle %sar or %cr11. No bits get set, we just verify that it
1639 is there. */
1640 case '!':
1641 /* Skip whitespace before register. */
1642 while (*s == ' ' || *s == '\t')
1643 s = s + 1;
1645 if (!strncasecmp(s, "%sar", 4))
1647 s += 4;
1648 continue;
1650 else if (!strncasecmp(s, "%cr11", 5))
1652 s += 5;
1653 continue;
1655 break;
1657 /* Handle a 5 bit register field at 15. */
1658 case 'x':
1659 /* This should be more strict. Small steps. */
1660 if (strict && *s != '%')
1661 break;
1662 num = pa_parse_number (&s, 0);
1663 CHECK_FIELD (num, 31, 0, 0);
1664 INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
1666 /* Handle a 5 bit register field at 31. */
1667 case 't':
1668 /* This should be more strict. Small steps. */
1669 if (strict && *s != '%')
1670 break;
1671 num = pa_parse_number (&s, 0);
1672 CHECK_FIELD (num, 31, 0, 0);
1673 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
1675 /* Handle a 5 bit register field at 10 and 15. */
1676 case 'a':
1677 /* This should be more strict. Small steps. */
1678 if (strict && *s != '%')
1679 break;
1680 num = pa_parse_number (&s, 0);
1681 CHECK_FIELD (num, 31, 0, 0);
1682 opcode |= num << 16;
1683 INSERT_FIELD_AND_CONTINUE (opcode, num, 21);
1685 /* Handle a 5 bit field length at 31. */
1686 case 'T':
1687 num = pa_get_absolute_expression (&the_insn, &s);
1688 if (strict && the_insn.exp.X_op != O_constant)
1689 break;
1690 s = expr_end;
1691 CHECK_FIELD (num, 32, 1, 0);
1692 INSERT_FIELD_AND_CONTINUE (opcode, 32 - num, 0);
1694 /* Handle a 5 bit immediate at 15. */
1695 case '5':
1696 num = pa_get_absolute_expression (&the_insn, &s);
1697 if (strict && the_insn.exp.X_op != O_constant)
1698 break;
1699 s = expr_end;
1700 /* When in strict mode, we want to just reject this
1701 match instead of giving an out of range error. */
1702 CHECK_FIELD (num, 15, -16, strict);
1703 num = low_sign_unext (num, 5);
1704 INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
1706 /* Handle a 5 bit immediate at 31. */
1707 case 'V':
1708 num = pa_get_absolute_expression (&the_insn, &s);
1709 if (strict && the_insn.exp.X_op != O_constant)
1710 break;
1711 s = expr_end;
1712 /* When in strict mode, we want to just reject this
1713 match instead of giving an out of range error. */
1714 CHECK_FIELD (num, 15, -16, strict)
1715 num = low_sign_unext (num, 5);
1716 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
1718 /* Handle an unsigned 5 bit immediate at 31. */
1719 case 'r':
1720 num = pa_get_absolute_expression (&the_insn, &s);
1721 if (strict && the_insn.exp.X_op != O_constant)
1722 break;
1723 s = expr_end;
1724 CHECK_FIELD (num, 31, 0, 0);
1725 INSERT_FIELD_AND_CONTINUE (opcode, num, strict);
1727 /* Handle an unsigned 5 bit immediate at 15. */
1728 case 'R':
1729 num = pa_get_absolute_expression (&the_insn, &s);
1730 if (strict && the_insn.exp.X_op != O_constant)
1731 break;
1732 s = expr_end;
1733 CHECK_FIELD (num, 31, 0, strict);
1734 INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
1736 /* Handle an unsigned 10 bit immediate at 15. */
1737 case 'U':
1738 num = pa_get_absolute_expression (&the_insn, &s);
1739 if (strict && the_insn.exp.X_op != O_constant)
1740 break;
1741 s = expr_end;
1742 CHECK_FIELD (num, 1023, 0, strict);
1743 INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
1745 /* Handle a 2 bit space identifier at 17. */
1746 case 's':
1747 /* This should be more strict. Small steps. */
1748 if (strict && *s != '%')
1749 break;
1750 num = pa_parse_number (&s, 0);
1751 CHECK_FIELD (num, 3, 0, 1);
1752 INSERT_FIELD_AND_CONTINUE (opcode, num, 14);
1754 /* Handle a 3 bit space identifier at 18. */
1755 case 'S':
1756 /* This should be more strict. Small steps. */
1757 if (strict && *s != '%')
1758 break;
1759 num = pa_parse_number (&s, 0);
1760 CHECK_FIELD (num, 7, 0, 1);
1761 opcode = re_assemble_3 (opcode, num);
1762 continue;
1764 /* Handle all completers. */
1765 case 'c':
1766 switch (*++args)
1769 /* Handle a completer for an indexing load or store. */
1770 case 'x':
1772 int uu = 0;
1773 int m = 0;
1774 int i = 0;
1775 while (*s == ',' && i < 2)
1777 s++;
1778 if (strncasecmp (s, "sm", 2) == 0)
1780 uu = 1;
1781 m = 1;
1782 s++;
1783 i++;
1785 else if (strncasecmp (s, "m", 1) == 0)
1786 m = 1;
1787 else if ((strncasecmp (s, "s ", 2) == 0)
1788 || (strncasecmp (s, "s,", 2) == 0))
1789 uu = 1;
1790 /* When in strict mode this is a match failure. */
1791 else if (strict)
1793 s--;
1794 break;
1796 else
1797 as_bad (_("Invalid Indexed Load Completer."));
1798 s++;
1799 i++;
1801 if (i > 2)
1802 as_bad (_("Invalid Indexed Load Completer Syntax."));
1803 opcode |= m << 5;
1804 INSERT_FIELD_AND_CONTINUE (opcode, uu, 13);
1807 /* Handle a short load/store completer. */
1808 case 'm':
1809 case 'q':
1810 case 'J':
1811 case 'e':
1813 int a = 0;
1814 int m = 0;
1815 if (*s == ',')
1817 int found = 0;
1818 s++;
1819 if (strncasecmp (s, "ma", 2) == 0)
1821 a = 0;
1822 m = 1;
1823 found = 1;
1825 else if (strncasecmp (s, "mb", 2) == 0)
1827 a = 1;
1828 m = 1;
1829 found = 1;
1832 /* When in strict mode, pass through for cache op. */
1833 if (!found && strict)
1834 s--;
1835 else
1837 if (!found)
1838 as_bad (_("Invalid Short Load/Store Completer."));
1839 s += 2;
1842 /* If we did not get a ma/mb completer, then we do not
1843 consider this a positive match for 'ce'. */
1844 else if (*args == 'e')
1845 break;
1847 /* 'J', 'm' and 'q' are the same, except for where they
1848 encode the before/after field. */
1849 if (*args == 'm')
1851 opcode |= m << 5;
1852 INSERT_FIELD_AND_CONTINUE (opcode, a, 13);
1854 else if (*args == 'q')
1856 opcode |= m << 3;
1857 INSERT_FIELD_AND_CONTINUE (opcode, a, 2);
1859 else if (*args == 'J')
1861 /* M bit is explicit in the major opcode. */
1862 INSERT_FIELD_AND_CONTINUE (opcode, a, 2);
1864 else if (*args == 'e')
1866 /* Gross! Hide these values in the immediate field
1867 of the instruction, then pull them out later. */
1868 opcode |= m << 8;
1869 opcode |= a << 9;
1870 continue;
1874 /* Handle a stbys completer. */
1875 case 's':
1877 int a = 0;
1878 int m = 0;
1879 int i = 0;
1880 while (*s == ',' && i < 2)
1882 s++;
1883 if (strncasecmp (s, "m", 1) == 0)
1884 m = 1;
1885 else if ((strncasecmp (s, "b ", 2) == 0)
1886 || (strncasecmp (s, "b,", 2) == 0))
1887 a = 0;
1888 else if (strncasecmp (s, "e", 1) == 0)
1889 a = 1;
1890 /* When in strict mode this is a match failure. */
1891 else if (strict)
1893 s--;
1894 break;
1896 else
1897 as_bad (_("Invalid Store Bytes Short Completer"));
1898 s++;
1899 i++;
1901 if (i > 2)
1902 as_bad (_("Invalid Store Bytes Short Completer"));
1903 opcode |= m << 5;
1904 INSERT_FIELD_AND_CONTINUE (opcode, a, 13);
1907 /* Handle load cache hint completer. */
1908 case 'c':
1909 cmpltr = 0;
1910 if (!strncmp(s, ",sl", 3))
1912 s += 3;
1913 cmpltr = 2;
1915 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 10);
1917 /* Handle store cache hint completer. */
1918 case 'C':
1919 cmpltr = 0;
1920 if (!strncmp(s, ",sl", 3))
1922 s += 3;
1923 cmpltr = 2;
1925 else if (!strncmp(s, ",bc", 3))
1927 s += 3;
1928 cmpltr = 1;
1930 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 10);
1932 /* Handle load and clear cache hint completer. */
1933 case 'd':
1934 cmpltr = 0;
1935 if (!strncmp(s, ",co", 3))
1937 s += 3;
1938 cmpltr = 1;
1940 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 10);
1942 /* Handle load ordering completer. */
1943 case 'o':
1944 if (strncmp(s, ",o", 2) != 0)
1945 break;
1946 s += 2;
1947 continue;
1949 /* Handle a branch gate completer. */
1950 case 'g':
1951 if (strncasecmp (s, ",gate", 5) != 0)
1952 break;
1953 s += 5;
1954 continue;
1956 /* Handle a branch link and push completer. */
1957 case 'p':
1958 if (strncasecmp (s, ",l,push", 7) != 0)
1959 break;
1960 s += 7;
1961 continue;
1963 /* Handle a branch link completer. */
1964 case 'l':
1965 if (strncasecmp (s, ",l", 2) != 0)
1966 break;
1967 s += 2;
1968 continue;
1970 /* Handle a branch pop completer. */
1971 case 'P':
1972 if (strncasecmp (s, ",pop", 4) != 0)
1973 break;
1974 s += 4;
1975 continue;
1977 /* Handle a local processor completer. */
1978 case 'L':
1979 if (strncasecmp (s, ",l", 2) != 0)
1980 break;
1981 s += 2;
1982 continue;
1984 /* Handle a PROBE read/write completer. */
1985 case 'w':
1986 flag = 0;
1987 if (!strncasecmp (s, ",w", 2))
1989 flag = 1;
1990 s += 2;
1992 else if (!strncasecmp (s, ",r", 2))
1994 flag = 0;
1995 s += 2;
1998 INSERT_FIELD_AND_CONTINUE (opcode, flag, 6);
2000 /* Handle MFCTL wide completer. */
2001 case 'W':
2002 if (strncasecmp (s, ",w", 2) != 0)
2003 break;
2004 s += 2;
2005 continue;
2007 /* Handle an RFI restore completer. */
2008 case 'r':
2009 flag = 0;
2010 if (!strncasecmp (s, ",r", 2))
2012 flag = 5;
2013 s += 2;
2016 INSERT_FIELD_AND_CONTINUE (opcode, flag, 5);
2018 /* Handle a system control completer. */
2019 case 'Z':
2020 if (*s == ',' && (*(s + 1) == 'm' || *(s + 1) == 'M'))
2022 flag = 1;
2023 s += 2;
2025 else
2026 flag = 0;
2028 INSERT_FIELD_AND_CONTINUE (opcode, flag, 5);
2030 /* Handle intermediate/final completer for DCOR. */
2031 case 'i':
2032 flag = 0;
2033 if (!strncasecmp (s, ",i", 2))
2035 flag = 1;
2036 s += 2;
2039 INSERT_FIELD_AND_CONTINUE (opcode, flag, 6);
2041 /* Handle zero/sign extension completer. */
2042 case 'z':
2043 flag = 1;
2044 if (!strncasecmp (s, ",z", 2))
2046 flag = 0;
2047 s += 2;
2050 INSERT_FIELD_AND_CONTINUE (opcode, flag, 10);
2052 /* Handle add completer. */
2053 case 'a':
2054 flag = 1;
2055 if (!strncasecmp (s, ",l", 2))
2057 flag = 2;
2058 s += 2;
2060 else if (!strncasecmp (s, ",tsv", 4))
2062 flag = 3;
2063 s += 4;
2066 INSERT_FIELD_AND_CONTINUE (opcode, flag, 10);
2068 /* Handle 64 bit carry for ADD. */
2069 case 'Y':
2070 flag = 0;
2071 if (!strncasecmp (s, ",dc,tsv", 7) ||
2072 !strncasecmp (s, ",tsv,dc", 7))
2074 flag = 1;
2075 s += 7;
2077 else if (!strncasecmp (s, ",dc", 3))
2079 flag = 0;
2080 s += 3;
2082 else
2083 break;
2085 INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
2087 /* Handle 32 bit carry for ADD. */
2088 case 'y':
2089 flag = 0;
2090 if (!strncasecmp (s, ",c,tsv", 6) ||
2091 !strncasecmp (s, ",tsv,c", 6))
2093 flag = 1;
2094 s += 6;
2096 else if (!strncasecmp (s, ",c", 2))
2098 flag = 0;
2099 s += 2;
2101 else
2102 break;
2104 INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
2106 /* Handle trap on signed overflow. */
2107 case 'v':
2108 flag = 0;
2109 if (!strncasecmp (s, ",tsv", 4))
2111 flag = 1;
2112 s += 4;
2115 INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
2117 /* Handle trap on condition and overflow. */
2118 case 't':
2119 flag = 0;
2120 if (!strncasecmp (s, ",tc,tsv", 7) ||
2121 !strncasecmp (s, ",tsv,tc", 7))
2123 flag = 1;
2124 s += 7;
2126 else if (!strncasecmp (s, ",tc", 3))
2128 flag = 0;
2129 s += 3;
2131 else
2132 break;
2134 INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
2136 /* Handle 64 bit borrow for SUB. */
2137 case 'B':
2138 flag = 0;
2139 if (!strncasecmp (s, ",db,tsv", 7) ||
2140 !strncasecmp (s, ",tsv,db", 7))
2142 flag = 1;
2143 s += 7;
2145 else if (!strncasecmp (s, ",db", 3))
2147 flag = 0;
2148 s += 3;
2150 else
2151 break;
2153 INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
2155 /* Handle 32 bit borrow for SUB. */
2156 case 'b':
2157 flag = 0;
2158 if (!strncasecmp (s, ",b,tsv", 6) ||
2159 !strncasecmp (s, ",tsv,b", 6))
2161 flag = 1;
2162 s += 6;
2164 else if (!strncasecmp (s, ",b", 2))
2166 flag = 0;
2167 s += 2;
2169 else
2170 break;
2172 INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
2174 /* Handle trap condition completer for UADDCM. */
2175 case 'T':
2176 flag = 0;
2177 if (!strncasecmp (s, ",tc", 3))
2179 flag = 1;
2180 s += 3;
2183 INSERT_FIELD_AND_CONTINUE (opcode, flag, 6);
2185 /* Handle signed/unsigned at 21. */
2186 case 'S':
2188 int sign = 1;
2189 if (strncasecmp (s, ",s", 2) == 0)
2191 sign = 1;
2192 s += 2;
2194 else if (strncasecmp (s, ",u", 2) == 0)
2196 sign = 0;
2197 s += 2;
2200 INSERT_FIELD_AND_CONTINUE (opcode, sign, 10);
2203 /* Handle left/right combination at 17:18. */
2204 case 'h':
2205 if (*s++ == ',')
2207 int lr = 0;
2208 if (*s == 'r')
2209 lr = 2;
2210 else if (*s == 'l')
2211 lr = 0;
2212 else
2213 as_bad(_("Invalid left/right combination completer"));
2215 s++;
2216 INSERT_FIELD_AND_CONTINUE (opcode, lr, 13);
2218 else
2219 as_bad(_("Invalid left/right combination completer"));
2220 break;
2222 /* Handle saturation at 24:25. */
2223 case 'H':
2225 int sat = 3;
2226 if (strncasecmp (s, ",ss", 3) == 0)
2228 sat = 1;
2229 s += 3;
2231 else if (strncasecmp (s, ",us", 3) == 0)
2233 sat = 0;
2234 s += 3;
2237 INSERT_FIELD_AND_CONTINUE (opcode, sat, 6);
2240 /* Handle permutation completer. */
2241 case '*':
2242 if (*s++ == ',')
2244 int permloc[4];
2245 int perm = 0;
2246 int i = 0;
2247 permloc[0] = 13;
2248 permloc[1] = 10;
2249 permloc[2] = 8;
2250 permloc[3] = 6;
2251 for (; i < 4; i++)
2253 switch (*s++)
2255 case '0':
2256 perm = 0;
2257 break;
2258 case '1':
2259 perm = 1;
2260 break;
2261 case '2':
2262 perm = 2;
2263 break;
2264 case '3':
2265 perm = 3;
2266 break;
2267 default:
2268 as_bad(_("Invalid permutation completer"));
2270 opcode |= perm << permloc[i];
2272 continue;
2274 else
2275 as_bad(_("Invalid permutation completer"));
2276 break;
2278 default:
2279 abort ();
2281 break;
2283 /* Handle all conditions. */
2284 case '?':
2286 args++;
2287 switch (*args)
2289 /* Handle FP compare conditions. */
2290 case 'f':
2291 cond = pa_parse_fp_cmp_cond (&s);
2292 INSERT_FIELD_AND_CONTINUE (opcode, cond, 0);
2294 /* Handle an add condition. */
2295 case 'A':
2296 case 'a':
2297 cmpltr = 0;
2298 flag = 0;
2299 if (*s == ',')
2301 s++;
2303 /* 64 bit conditions. */
2304 if (*args == 'A')
2306 if (*s == '*')
2307 s++;
2308 else
2309 break;
2311 else if (*s == '*')
2312 break;
2313 name = s;
2315 name = s;
2316 while (*s != ',' && *s != ' ' && *s != '\t')
2317 s += 1;
2318 c = *s;
2319 *s = 0x00;
2320 if (strcmp (name, "=") == 0)
2321 cmpltr = 1;
2322 else if (strcmp (name, "<") == 0)
2323 cmpltr = 2;
2324 else if (strcmp (name, "<=") == 0)
2325 cmpltr = 3;
2326 else if (strcasecmp (name, "nuv") == 0)
2327 cmpltr = 4;
2328 else if (strcasecmp (name, "znv") == 0)
2329 cmpltr = 5;
2330 else if (strcasecmp (name, "sv") == 0)
2331 cmpltr = 6;
2332 else if (strcasecmp (name, "od") == 0)
2333 cmpltr = 7;
2334 else if (strcasecmp (name, "tr") == 0)
2336 cmpltr = 0;
2337 flag = 1;
2339 else if (strcmp (name, "<>") == 0)
2341 cmpltr = 1;
2342 flag = 1;
2344 else if (strcmp (name, ">=") == 0)
2346 cmpltr = 2;
2347 flag = 1;
2349 else if (strcmp (name, ">") == 0)
2351 cmpltr = 3;
2352 flag = 1;
2354 else if (strcasecmp (name, "uv") == 0)
2356 cmpltr = 4;
2357 flag = 1;
2359 else if (strcasecmp (name, "vnz") == 0)
2361 cmpltr = 5;
2362 flag = 1;
2364 else if (strcasecmp (name, "nsv") == 0)
2366 cmpltr = 6;
2367 flag = 1;
2369 else if (strcasecmp (name, "ev") == 0)
2371 cmpltr = 7;
2372 flag = 1;
2374 /* ",*" is a valid condition. */
2375 else if (*args == 'a')
2376 as_bad (_("Invalid Add Condition: %s"), name);
2377 *s = c;
2379 opcode |= cmpltr << 13;
2380 INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
2382 /* Handle non-negated add and branch condition. */
2383 case 'd':
2384 cmpltr = pa_parse_nonneg_add_cmpltr (&s, 1);
2385 if (cmpltr < 0)
2387 as_bad (_("Invalid Add and Branch Condition: %c"), *s);
2388 cmpltr = 0;
2390 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
2392 /* Handle 64 bit wide-mode add and branch condition. */
2393 case 'W':
2394 cmpltr = pa_parse_addb_64_cmpltr (&s);
2395 if (cmpltr < 0)
2397 as_bad (_("Invalid Add and Branch Condition: %c"), *s);
2398 cmpltr = 0;
2400 else
2402 /* Negated condition requires an opcode change. */
2403 opcode |= (cmpltr & 8) << 24;
2405 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr & 7, 13);
2407 /* Handle a negated or non-negated add and branch
2408 condition. */
2409 case '@':
2410 save_s = s;
2411 cmpltr = pa_parse_nonneg_add_cmpltr (&s, 1);
2412 if (cmpltr < 0)
2414 s = save_s;
2415 cmpltr = pa_parse_neg_add_cmpltr (&s, 1);
2416 if (cmpltr < 0)
2418 as_bad (_("Invalid Compare/Subtract Condition"));
2419 cmpltr = 0;
2421 else
2423 /* Negated condition requires an opcode change. */
2424 opcode |= 1 << 27;
2427 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
2429 /* Handle branch on bit conditions. */
2430 case 'B':
2431 case 'b':
2432 cmpltr = 0;
2433 if (*s == ',')
2435 s++;
2437 if (*args == 'B')
2439 if (*s == '*')
2440 s++;
2441 else
2442 break;
2444 else if (*s == '*')
2445 break;
2447 if (strncmp (s, "<", 1) == 0)
2449 cmpltr = 0;
2450 s++;
2452 else if (strncmp (s, ">=", 2) == 0)
2454 cmpltr = 1;
2455 s += 2;
2457 else
2458 as_bad (_("Invalid Bit Branch Condition: %c"), *s);
2460 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 15);
2462 /* Handle a compare/subtract condition. */
2463 case 'S':
2464 case 's':
2465 cmpltr = 0;
2466 flag = 0;
2467 if (*s == ',')
2469 s++;
2471 /* 64 bit conditions. */
2472 if (*args == 'S')
2474 if (*s == '*')
2475 s++;
2476 else
2477 break;
2479 else if (*s == '*')
2480 break;
2481 name = s;
2483 name = s;
2484 while (*s != ',' && *s != ' ' && *s != '\t')
2485 s += 1;
2486 c = *s;
2487 *s = 0x00;
2488 if (strcmp (name, "=") == 0)
2489 cmpltr = 1;
2490 else if (strcmp (name, "<") == 0)
2491 cmpltr = 2;
2492 else if (strcmp (name, "<=") == 0)
2493 cmpltr = 3;
2494 else if (strcasecmp (name, "<<") == 0)
2495 cmpltr = 4;
2496 else if (strcasecmp (name, "<<=") == 0)
2497 cmpltr = 5;
2498 else if (strcasecmp (name, "sv") == 0)
2499 cmpltr = 6;
2500 else if (strcasecmp (name, "od") == 0)
2501 cmpltr = 7;
2502 else if (strcasecmp (name, "tr") == 0)
2504 cmpltr = 0;
2505 flag = 1;
2507 else if (strcmp (name, "<>") == 0)
2509 cmpltr = 1;
2510 flag = 1;
2512 else if (strcmp (name, ">=") == 0)
2514 cmpltr = 2;
2515 flag = 1;
2517 else if (strcmp (name, ">") == 0)
2519 cmpltr = 3;
2520 flag = 1;
2522 else if (strcasecmp (name, ">>=") == 0)
2524 cmpltr = 4;
2525 flag = 1;
2527 else if (strcasecmp (name, ">>") == 0)
2529 cmpltr = 5;
2530 flag = 1;
2532 else if (strcasecmp (name, "nsv") == 0)
2534 cmpltr = 6;
2535 flag = 1;
2537 else if (strcasecmp (name, "ev") == 0)
2539 cmpltr = 7;
2540 flag = 1;
2542 /* ",*" is a valid condition. */
2543 else if (*args != 'S')
2544 as_bad (_("Invalid Compare/Subtract Condition: %s"),
2545 name);
2546 *s = c;
2548 opcode |= cmpltr << 13;
2549 INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
2551 /* Handle a non-negated compare condition. */
2552 case 't':
2553 cmpltr = pa_parse_nonneg_cmpsub_cmpltr (&s, 1);
2554 if (cmpltr < 0)
2556 as_bad (_("Invalid Compare/Subtract Condition: %c"), *s);
2557 cmpltr = 0;
2559 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
2561 /* Handle a 32 bit compare and branch condition. */
2562 case 'n':
2563 save_s = s;
2564 cmpltr = pa_parse_nonneg_cmpsub_cmpltr (&s, 1);
2565 if (cmpltr < 0)
2567 s = save_s;
2568 cmpltr = pa_parse_neg_cmpsub_cmpltr (&s, 1);
2569 if (cmpltr < 0)
2571 as_bad (_("Invalid Compare and Branch Condition."));
2572 cmpltr = 0;
2574 else
2576 /* Negated condition requires an opcode change. */
2577 opcode |= 1 << 27;
2581 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
2583 /* Handle a 64 bit compare and branch condition. */
2584 case 'N':
2585 cmpltr = pa_parse_cmpb_64_cmpltr (&s);
2586 if (cmpltr >= 0)
2588 /* Negated condition requires an opcode change. */
2589 opcode |= (cmpltr & 8) << 26;
2591 else
2592 /* Not a 64 bit cond. Give 32 bit a chance. */
2593 break;
2595 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr & 7, 13);
2597 /* Handle a 64 bit cmpib condition. */
2598 case 'Q':
2599 cmpltr = pa_parse_cmpib_64_cmpltr (&s);
2600 if (cmpltr < 0)
2601 /* Not a 64 bit cond. Give 32 bit a chance. */
2602 break;
2604 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
2606 /* Handle a logical instruction condition. */
2607 case 'L':
2608 case 'l':
2609 cmpltr = 0;
2610 flag = 0;
2611 if (*s == ',')
2613 s++;
2615 /* 64 bit conditions. */
2616 if (*args == 'L')
2618 if (*s == '*')
2619 s++;
2620 else
2621 break;
2623 else if (*s == '*')
2624 break;
2625 name = s;
2627 name = s;
2628 while (*s != ',' && *s != ' ' && *s != '\t')
2629 s += 1;
2630 c = *s;
2631 *s = 0x00;
2634 if (strcmp (name, "=") == 0)
2635 cmpltr = 1;
2636 else if (strcmp (name, "<") == 0)
2637 cmpltr = 2;
2638 else if (strcmp (name, "<=") == 0)
2639 cmpltr = 3;
2640 else if (strcasecmp (name, "od") == 0)
2641 cmpltr = 7;
2642 else if (strcasecmp (name, "tr") == 0)
2644 cmpltr = 0;
2645 flag = 1;
2647 else if (strcmp (name, "<>") == 0)
2649 cmpltr = 1;
2650 flag = 1;
2652 else if (strcmp (name, ">=") == 0)
2654 cmpltr = 2;
2655 flag = 1;
2657 else if (strcmp (name, ">") == 0)
2659 cmpltr = 3;
2660 flag = 1;
2662 else if (strcasecmp (name, "ev") == 0)
2664 cmpltr = 7;
2665 flag = 1;
2667 /* ",*" is a valid condition. */
2668 else if (*args != 'L')
2669 as_bad (_("Invalid Logical Instruction Condition."));
2670 *s = c;
2672 opcode |= cmpltr << 13;
2673 INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
2675 /* Handle a shift/extract/deposit condition. */
2676 case 'X':
2677 case 'x':
2678 case 'y':
2679 cmpltr = 0;
2680 if (*s == ',')
2682 save_s = s++;
2684 /* 64 bit conditions. */
2685 if (*args == 'X')
2687 if (*s == '*')
2688 s++;
2689 else
2690 break;
2692 else if (*s == '*')
2693 break;
2694 name = s;
2696 name = s;
2697 while (*s != ',' && *s != ' ' && *s != '\t')
2698 s += 1;
2699 c = *s;
2700 *s = 0x00;
2701 if (strcmp (name, "=") == 0)
2702 cmpltr = 1;
2703 else if (strcmp (name, "<") == 0)
2704 cmpltr = 2;
2705 else if (strcasecmp (name, "od") == 0)
2706 cmpltr = 3;
2707 else if (strcasecmp (name, "tr") == 0)
2708 cmpltr = 4;
2709 else if (strcmp (name, "<>") == 0)
2710 cmpltr = 5;
2711 else if (strcmp (name, ">=") == 0)
2712 cmpltr = 6;
2713 else if (strcasecmp (name, "ev") == 0)
2714 cmpltr = 7;
2715 /* Handle movb,n. Put things back the way they were.
2716 This includes moving s back to where it started. */
2717 else if (strcasecmp (name, "n") == 0 && *args == 'y')
2719 *s = c;
2720 s = save_s;
2721 continue;
2723 /* ",*" is a valid condition. */
2724 else if (*args != 'X')
2725 as_bad (_("Invalid Shift/Extract/Deposit Condition."));
2726 *s = c;
2728 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
2730 /* Handle a unit instruction condition. */
2731 case 'U':
2732 case 'u':
2733 cmpltr = 0;
2734 flag = 0;
2735 if (*s == ',')
2737 s++;
2739 /* 64 bit conditions. */
2740 if (*args == 'U')
2742 if (*s == '*')
2743 s++;
2744 else
2745 break;
2747 else if (*s == '*')
2748 break;
2750 if (strncasecmp (s, "sbz", 3) == 0)
2752 cmpltr = 2;
2753 s += 3;
2755 else if (strncasecmp (s, "shz", 3) == 0)
2757 cmpltr = 3;
2758 s += 3;
2760 else if (strncasecmp (s, "sdc", 3) == 0)
2762 cmpltr = 4;
2763 s += 3;
2765 else if (strncasecmp (s, "sbc", 3) == 0)
2767 cmpltr = 6;
2768 s += 3;
2770 else if (strncasecmp (s, "shc", 3) == 0)
2772 cmpltr = 7;
2773 s += 3;
2775 else if (strncasecmp (s, "tr", 2) == 0)
2777 cmpltr = 0;
2778 flag = 1;
2779 s += 2;
2781 else if (strncasecmp (s, "nbz", 3) == 0)
2783 cmpltr = 2;
2784 flag = 1;
2785 s += 3;
2787 else if (strncasecmp (s, "nhz", 3) == 0)
2789 cmpltr = 3;
2790 flag = 1;
2791 s += 3;
2793 else if (strncasecmp (s, "ndc", 3) == 0)
2795 cmpltr = 4;
2796 flag = 1;
2797 s += 3;
2799 else if (strncasecmp (s, "nbc", 3) == 0)
2801 cmpltr = 6;
2802 flag = 1;
2803 s += 3;
2805 else if (strncasecmp (s, "nhc", 3) == 0)
2807 cmpltr = 7;
2808 flag = 1;
2809 s += 3;
2811 else if (strncasecmp (s, "swz", 3) == 0)
2813 cmpltr = 1;
2814 flag = 0;
2815 s += 3;
2817 else if (strncasecmp (s, "swc", 3) == 0)
2819 cmpltr = 5;
2820 flag = 0;
2821 s += 3;
2823 else if (strncasecmp (s, "nwz", 3) == 0)
2825 cmpltr = 1;
2826 flag = 1;
2827 s += 3;
2829 else if (strncasecmp (s, "nwc", 3) == 0)
2831 cmpltr = 5;
2832 flag = 1;
2833 s += 3;
2835 /* ",*" is a valid condition. */
2836 else if (*args != 'U')
2837 as_bad (_("Invalid Unit Instruction Condition."));
2839 opcode |= cmpltr << 13;
2840 INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
2842 default:
2843 abort ();
2845 break;
2848 /* Handle a nullification completer for branch instructions. */
2849 case 'n':
2850 nullif = pa_parse_nullif (&s);
2851 INSERT_FIELD_AND_CONTINUE (opcode, nullif, 1);
2853 /* Handle a nullification completer for copr and spop insns. */
2854 case 'N':
2855 nullif = pa_parse_nullif (&s);
2856 INSERT_FIELD_AND_CONTINUE (opcode, nullif, 5);
2858 /* Handle ,%r2 completer for new syntax branches. */
2859 case 'L':
2860 if (*s == ',' && strncasecmp (s + 1, "%r2", 3) == 0)
2861 s += 4;
2862 else if (*s == ',' && strncasecmp (s + 1, "%rp", 3) == 0)
2863 s += 4;
2864 else
2865 break;
2866 continue;
2868 /* Handle 3 bit entry into the fp compare array. Valid values
2869 are 0..6 inclusive. */
2870 case 'h':
2871 get_expression (s);
2872 s = expr_end;
2873 if (the_insn.exp.X_op == O_constant)
2875 num = evaluate_absolute (&the_insn);
2876 CHECK_FIELD (num, 6, 0, 0);
2877 num++;
2878 INSERT_FIELD_AND_CONTINUE (opcode, num, 13);
2880 else
2881 break;
2883 /* Handle 3 bit entry into the fp compare array. Valid values
2884 are 0..6 inclusive. */
2885 case 'm':
2886 get_expression (s);
2887 if (the_insn.exp.X_op == O_constant)
2889 s = expr_end;
2890 num = evaluate_absolute (&the_insn);
2891 CHECK_FIELD (num, 6, 0, 0);
2892 num = (num + 1) ^ 1;
2893 INSERT_FIELD_AND_CONTINUE (opcode, num, 13);
2895 else
2896 break;
2898 /* Handle graphics test completers for ftest */
2899 case '=':
2901 num = pa_parse_ftest_gfx_completer (&s);
2902 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2905 /* Handle a 11 bit immediate at 31. */
2906 case 'i':
2907 the_insn.field_selector = pa_chk_field_selector (&s);
2908 get_expression (s);
2909 s = expr_end;
2910 if (the_insn.exp.X_op == O_constant)
2912 num = evaluate_absolute (&the_insn);
2913 CHECK_FIELD (num, 1023, -1024, 0);
2914 num = low_sign_unext (num, 11);
2915 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2917 else
2919 if (is_DP_relative (the_insn.exp))
2920 the_insn.reloc = R_HPPA_GOTOFF;
2921 else if (is_PC_relative (the_insn.exp))
2922 the_insn.reloc = R_HPPA_PCREL_CALL;
2923 else
2924 the_insn.reloc = R_HPPA;
2925 the_insn.format = 11;
2926 continue;
2929 /* Handle a 14 bit immediate at 31. */
2930 case 'J':
2931 the_insn.field_selector = pa_chk_field_selector (&s);
2932 get_expression (s);
2933 s = expr_end;
2934 if (the_insn.exp.X_op == O_constant)
2936 int a, m;
2938 /* XXX the completer stored away tibits of information
2939 for us to extract. We need a cleaner way to do this.
2940 Now that we have lots of letters again, it would be
2941 good to rethink this. */
2942 m = (opcode & (1 << 8)) != 0;
2943 a = (opcode & (1 << 9)) != 0;
2944 opcode &= ~ (3 << 8);
2945 num = evaluate_absolute (&the_insn);
2946 if ((a == 1 && num >= 0) || (a == 0 && num < 0))
2947 break;
2948 CHECK_FIELD (num, 8191, -8192, 0);
2949 num = low_sign_unext (num, 14);
2950 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2952 else
2954 break;
2957 /* Handle a 14 bit immediate at 31. */
2958 case 'K':
2959 the_insn.field_selector = pa_chk_field_selector (&s);
2960 get_expression (s);
2961 s = expr_end;
2962 if (the_insn.exp.X_op == O_constant)
2964 int a, m;
2966 /* XXX the completer stored away tibits of information
2967 for us to extract. We need a cleaner way to do this.
2968 Now that we have lots of letters again, it would be
2969 good to rethink this. */
2970 m = (opcode & (1 << 8)) != 0;
2971 a = (opcode & (1 << 9)) != 0;
2972 opcode &= ~ (3 << 8);
2973 num = evaluate_absolute (&the_insn);
2974 if ((a == 1 && num < 0) || (a == 0 && num > 0))
2975 break;
2976 if (num % 4)
2977 break;
2978 CHECK_FIELD (num, 8191, -8192, 0);
2979 if (num < 0)
2980 opcode |= 1;
2981 num &= 0x1fff;
2982 num >>= 2;
2983 INSERT_FIELD_AND_CONTINUE (opcode, num, 3);
2985 else
2987 break;
2990 /* Handle 14 bit immediated, shifted left three times. */
2991 case '#':
2992 the_insn.field_selector = pa_chk_field_selector (&s);
2993 get_expression (s);
2994 s = expr_end;
2995 if (the_insn.exp.X_op == O_constant)
2997 num = evaluate_absolute (&the_insn);
2998 if (num & 0x7)
2999 break;
3000 CHECK_FIELD (num, 8191, -8192, 0);
3001 if (num < 0)
3002 opcode |= 1;
3003 num &= 0x1fff;
3004 num >>= 3;
3005 INSERT_FIELD_AND_CONTINUE (opcode, num, 4);
3007 else
3009 if (is_DP_relative (the_insn.exp))
3010 the_insn.reloc = R_HPPA_GOTOFF;
3011 else if (is_PC_relative (the_insn.exp))
3012 the_insn.reloc = R_HPPA_PCREL_CALL;
3013 else
3014 the_insn.reloc = R_HPPA;
3015 the_insn.format = 14;
3016 continue;
3018 break;
3020 /* Handle 14 bit immediate, shifted left twice. */
3021 case 'd':
3022 the_insn.field_selector = pa_chk_field_selector (&s);
3023 get_expression (s);
3024 s = expr_end;
3025 if (the_insn.exp.X_op == O_constant)
3027 num = evaluate_absolute (&the_insn);
3028 if (num & 0x3)
3029 break;
3030 CHECK_FIELD (num, 8191, -8192, 0);
3031 if (num < 0)
3032 opcode |= 1;
3033 num &= 0x1fff;
3034 num >>= 2;
3035 INSERT_FIELD_AND_CONTINUE (opcode, num, 3);
3037 else
3039 if (is_DP_relative (the_insn.exp))
3040 the_insn.reloc = R_HPPA_GOTOFF;
3041 else if (is_PC_relative (the_insn.exp))
3042 the_insn.reloc = R_HPPA_PCREL_CALL;
3043 else
3044 the_insn.reloc = R_HPPA;
3045 the_insn.format = 14;
3046 continue;
3049 /* Handle a 14 bit immediate at 31. */
3050 case 'j':
3051 the_insn.field_selector = pa_chk_field_selector (&s);
3052 get_expression (s);
3053 s = expr_end;
3054 if (the_insn.exp.X_op == O_constant)
3056 num = evaluate_absolute (&the_insn);
3057 CHECK_FIELD (num, 8191, -8192, 0);
3058 num = low_sign_unext (num, 14);
3059 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
3061 else
3063 if (is_DP_relative (the_insn.exp))
3064 the_insn.reloc = R_HPPA_GOTOFF;
3065 else if (is_PC_relative (the_insn.exp))
3066 the_insn.reloc = R_HPPA_PCREL_CALL;
3067 else
3068 the_insn.reloc = R_HPPA;
3069 the_insn.format = 14;
3070 continue;
3073 /* Handle a 21 bit immediate at 31. */
3074 case 'k':
3075 the_insn.field_selector = pa_chk_field_selector (&s);
3076 get_expression (s);
3077 s = expr_end;
3078 if (the_insn.exp.X_op == O_constant)
3080 num = evaluate_absolute (&the_insn);
3081 CHECK_FIELD (num >> 11, 1048575, -1048576, 0);
3082 opcode = re_assemble_21 (opcode, num);
3083 continue;
3085 else
3087 if (is_DP_relative (the_insn.exp))
3088 the_insn.reloc = R_HPPA_GOTOFF;
3089 else if (is_PC_relative (the_insn.exp))
3090 the_insn.reloc = R_HPPA_PCREL_CALL;
3091 else
3092 the_insn.reloc = R_HPPA;
3093 the_insn.format = 21;
3094 continue;
3097 /* Handle a 16 bit immediate at 31 (PA 2.0 wide mode only). */
3098 case 'l':
3099 the_insn.field_selector = pa_chk_field_selector (&s);
3100 get_expression (s);
3101 s = expr_end;
3102 if (the_insn.exp.X_op == O_constant)
3104 num = evaluate_absolute (&the_insn);
3105 CHECK_FIELD (num, 32767, -32768, 0);
3106 opcode = re_assemble_16 (opcode, num, 1);
3107 continue;
3109 else
3111 /* ??? Is this valid for wide mode? */
3112 if (is_DP_relative (the_insn.exp))
3113 the_insn.reloc = R_HPPA_GOTOFF;
3114 else if (is_PC_relative (the_insn.exp))
3115 the_insn.reloc = R_HPPA_PCREL_CALL;
3116 else
3117 the_insn.reloc = R_HPPA;
3118 the_insn.format = 14;
3119 continue;
3122 /* Handle a word-aligned 16-bit imm. at 31 (PA2.0 wide). */
3123 case 'y':
3124 the_insn.field_selector = pa_chk_field_selector (&s);
3125 get_expression (s);
3126 s = expr_end;
3127 if (the_insn.exp.X_op == O_constant)
3129 num = evaluate_absolute (&the_insn);
3130 CHECK_FIELD (num, 32767, -32768, 0);
3131 CHECK_ALIGN (num, 4, 0);
3132 opcode = re_assemble_16 (opcode, num, 1);
3133 continue;
3135 else
3137 /* ??? Is this valid for wide mode? */
3138 if (is_DP_relative (the_insn.exp))
3139 the_insn.reloc = R_HPPA_GOTOFF;
3140 else if (is_PC_relative (the_insn.exp))
3141 the_insn.reloc = R_HPPA_PCREL_CALL;
3142 else
3143 the_insn.reloc = R_HPPA;
3144 the_insn.format = 14;
3145 continue;
3148 /* Handle a dword-aligned 16-bit imm. at 31 (PA2.0 wide). */
3149 case '&':
3150 the_insn.field_selector = pa_chk_field_selector (&s);
3151 get_expression (s);
3152 s = expr_end;
3153 if (the_insn.exp.X_op == O_constant)
3155 num = evaluate_absolute (&the_insn);
3156 CHECK_FIELD (num, 32767, -32768, 0);
3157 CHECK_ALIGN (num, 8, 0);
3158 opcode = re_assemble_16 (opcode, num, 1);
3159 continue;
3161 else
3163 /* ??? Is this valid for wide mode? */
3164 if (is_DP_relative (the_insn.exp))
3165 the_insn.reloc = R_HPPA_GOTOFF;
3166 else if (is_PC_relative (the_insn.exp))
3167 the_insn.reloc = R_HPPA_PCREL_CALL;
3168 else
3169 the_insn.reloc = R_HPPA;
3170 the_insn.format = 14;
3171 continue;
3174 /* Handle a 12 bit branch displacement. */
3175 case 'w':
3176 the_insn.field_selector = pa_chk_field_selector (&s);
3177 get_expression (s);
3178 s = expr_end;
3179 the_insn.pcrel = 1;
3180 if (!strcmp (S_GET_NAME (the_insn.exp.X_add_symbol), "L$0\001"))
3182 num = evaluate_absolute (&the_insn);
3183 if (num % 4)
3185 as_bad (_("Branch to unaligned address"));
3186 break;
3188 CHECK_FIELD (num, 8199, -8184, 0);
3190 opcode = re_assemble_12 (opcode, (num - 8) >> 2);
3191 continue;
3193 else
3195 the_insn.reloc = R_HPPA_PCREL_CALL;
3196 the_insn.format = 12;
3197 the_insn.arg_reloc = last_call_desc.arg_reloc;
3198 memset (&last_call_desc, 0, sizeof (struct call_desc));
3199 s = expr_end;
3200 continue;
3203 /* Handle a 17 bit branch displacement. */
3204 case 'W':
3205 the_insn.field_selector = pa_chk_field_selector (&s);
3206 get_expression (s);
3207 s = expr_end;
3208 the_insn.pcrel = 1;
3209 if (!the_insn.exp.X_add_symbol
3210 || !strcmp (S_GET_NAME (the_insn.exp.X_add_symbol),
3211 "L$0\001"))
3213 num = evaluate_absolute (&the_insn);
3214 if (num % 4)
3216 as_bad (_("Branch to unaligned address"));
3217 break;
3219 CHECK_FIELD (num, 262143, -262144, 0);
3221 if (the_insn.exp.X_add_symbol)
3222 num -= 8;
3224 opcode = re_assemble_17 (opcode, num >> 2);
3225 continue;
3227 else
3229 the_insn.reloc = R_HPPA_PCREL_CALL;
3230 the_insn.format = 17;
3231 the_insn.arg_reloc = last_call_desc.arg_reloc;
3232 memset (&last_call_desc, 0, sizeof (struct call_desc));
3233 continue;
3236 /* Handle a 22 bit branch displacement. */
3237 case 'X':
3238 the_insn.field_selector = pa_chk_field_selector (&s);
3239 get_expression (s);
3240 s = expr_end;
3241 the_insn.pcrel = 1;
3242 if (!the_insn.exp.X_add_symbol
3243 || !strcmp (S_GET_NAME (the_insn.exp.X_add_symbol),
3244 "L$0\001"))
3246 num = evaluate_absolute (&the_insn);
3247 if (num % 4)
3249 as_bad (_("Branch to unaligned address"));
3250 break;
3252 CHECK_FIELD (num, 8388607, -8388608, 0);
3254 if (the_insn.exp.X_add_symbol)
3255 num -= 8;
3257 opcode = re_assemble_22 (opcode, num >> 2);
3259 else
3261 the_insn.reloc = R_HPPA_PCREL_CALL;
3262 the_insn.format = 22;
3263 the_insn.arg_reloc = last_call_desc.arg_reloc;
3264 memset (&last_call_desc, 0, sizeof (struct call_desc));
3265 continue;
3268 /* Handle an absolute 17 bit branch target. */
3269 case 'z':
3270 the_insn.field_selector = pa_chk_field_selector (&s);
3271 get_expression (s);
3272 s = expr_end;
3273 the_insn.pcrel = 0;
3274 if (!the_insn.exp.X_add_symbol
3275 || !strcmp (S_GET_NAME (the_insn.exp.X_add_symbol),
3276 "L$0\001"))
3278 num = evaluate_absolute (&the_insn);
3279 if (num % 4)
3281 as_bad (_("Branch to unaligned address"));
3282 break;
3284 CHECK_FIELD (num, 262143, -262144, 0);
3286 if (the_insn.exp.X_add_symbol)
3287 num -= 8;
3289 opcode = re_assemble_17 (opcode, num >> 2);
3290 continue;
3292 else
3294 the_insn.reloc = R_HPPA_ABS_CALL;
3295 the_insn.format = 17;
3296 the_insn.arg_reloc = last_call_desc.arg_reloc;
3297 memset (&last_call_desc, 0, sizeof (struct call_desc));
3298 continue;
3301 /* Handle '%r1' implicit operand of addil instruction. */
3302 case 'Z':
3303 if (*s == ',' && *(s + 1) == '%' && *(s + 3) == '1'
3304 && (*(s + 2) == 'r' || *(s + 2) == 'R'))
3306 s += 4;
3307 continue;
3309 else
3310 break;
3312 /* Handle '%sr0,%r31' implicit operand of be,l instruction. */
3313 case 'Y':
3314 if (strncasecmp (s, "%sr0,%r31", 9) != 0)
3315 break;
3316 s += 9;
3317 continue;
3319 /* Handle immediate value of 0 for ordered load/store instructions. */
3320 case '@':
3321 if (*s != '0')
3322 break;
3323 s++;
3324 continue;
3326 /* Handle a 2 bit shift count at 25. */
3327 case '.':
3328 num = pa_get_absolute_expression (&the_insn, &s);
3329 if (strict && the_insn.exp.X_op != O_constant)
3330 break;
3331 s = expr_end;
3332 CHECK_FIELD (num, 3, 1, strict);
3333 INSERT_FIELD_AND_CONTINUE (opcode, num, 6);
3335 /* Handle a 4 bit shift count at 25. */
3336 case '*':
3337 num = pa_get_absolute_expression (&the_insn, &s);
3338 if (strict && the_insn.exp.X_op != O_constant)
3339 break;
3340 s = expr_end;
3341 CHECK_FIELD (num, 15, 0, strict);
3342 INSERT_FIELD_AND_CONTINUE (opcode, num, 6);
3344 /* Handle a 5 bit shift count at 26. */
3345 case 'p':
3346 num = pa_get_absolute_expression (&the_insn, &s);
3347 if (strict && the_insn.exp.X_op != O_constant)
3348 break;
3349 s = expr_end;
3350 CHECK_FIELD (num, 31, 0, strict);
3351 INSERT_FIELD_AND_CONTINUE (opcode, 31 - num, 5);
3353 /* Handle a 6 bit shift count at 20,22:26. */
3354 case '~':
3355 num = pa_get_absolute_expression (&the_insn, &s);
3356 if (strict && the_insn.exp.X_op != O_constant)
3357 break;
3358 s = expr_end;
3359 CHECK_FIELD (num, 63, 0, strict);
3360 num = 63 - num;
3361 opcode |= (num & 0x20) << 6;
3362 INSERT_FIELD_AND_CONTINUE (opcode, num & 0x1f, 5);
3364 /* Handle a 6 bit field length at 23,27:31. */
3365 case '%':
3366 flag = 0;
3367 num = pa_get_absolute_expression (&the_insn, &s);
3368 if (strict && the_insn.exp.X_op != O_constant)
3369 break;
3370 s = expr_end;
3371 CHECK_FIELD (num, 64, 1, strict);
3372 num--;
3373 opcode |= (num & 0x20) << 3;
3374 num = 31 - (num & 0x1f);
3375 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
3377 /* Handle a 6 bit field length at 19,27:31. */
3378 case '|':
3379 num = pa_get_absolute_expression (&the_insn, &s);
3380 if (strict && the_insn.exp.X_op != O_constant)
3381 break;
3382 s = expr_end;
3383 CHECK_FIELD (num, 64, 1, strict);
3384 num--;
3385 opcode |= (num & 0x20) << 7;
3386 num = 31 - (num & 0x1f);
3387 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
3389 /* Handle a 5 bit bit position at 26. */
3390 case 'P':
3391 num = pa_get_absolute_expression (&the_insn, &s);
3392 if (strict && the_insn.exp.X_op != O_constant)
3393 break;
3394 s = expr_end;
3395 CHECK_FIELD (num, 31, 0, strict);
3396 INSERT_FIELD_AND_CONTINUE (opcode, num, 5);
3398 /* Handle a 6 bit bit position at 20,22:26. */
3399 case 'q':
3400 num = pa_get_absolute_expression (&the_insn, &s);
3401 if (strict && the_insn.exp.X_op != O_constant)
3402 break;
3403 s = expr_end;
3404 CHECK_FIELD (num, 63, 0, strict);
3405 opcode |= (num & 0x20) << 6;
3406 INSERT_FIELD_AND_CONTINUE (opcode, num & 0x1f, 5);
3408 /* Handle a 5 bit immediate at 10 with 'd' as the complement
3409 of the high bit of the immediate. */
3410 case 'B':
3411 num = pa_get_absolute_expression (&the_insn, &s);
3412 if (strict && the_insn.exp.X_op != O_constant)
3413 break;
3414 s = expr_end;
3415 CHECK_FIELD (num, 63, 0, strict);
3416 if (num & 0x20)
3418 else
3419 opcode |= (1 << 13);
3420 INSERT_FIELD_AND_CONTINUE (opcode, num & 0x1f, 21);
3422 /* Handle a 5 bit immediate at 10. */
3423 case 'Q':
3424 num = pa_get_absolute_expression (&the_insn, &s);
3425 if (strict && the_insn.exp.X_op != O_constant)
3426 break;
3427 if (the_insn.exp.X_op != O_constant)
3428 break;
3429 s = expr_end;
3430 CHECK_FIELD (num, 31, 0, strict);
3431 INSERT_FIELD_AND_CONTINUE (opcode, num, 21);
3433 /* Handle a 9 bit immediate at 28. */
3434 case '$':
3435 num = pa_get_absolute_expression (&the_insn, &s);
3436 if (strict && the_insn.exp.X_op != O_constant)
3437 break;
3438 s = expr_end;
3439 CHECK_FIELD (num, 511, 1, strict);
3440 INSERT_FIELD_AND_CONTINUE (opcode, num, 3);
3442 /* Handle a 13 bit immediate at 18. */
3443 case 'A':
3444 num = pa_get_absolute_expression (&the_insn, &s);
3445 if (strict && the_insn.exp.X_op != O_constant)
3446 break;
3447 s = expr_end;
3448 CHECK_FIELD (num, 8191, 0, strict);
3449 INSERT_FIELD_AND_CONTINUE (opcode, num, 13);
3451 /* Handle a 26 bit immediate at 31. */
3452 case 'D':
3453 num = pa_get_absolute_expression (&the_insn, &s);
3454 if (strict && the_insn.exp.X_op != O_constant)
3455 break;
3456 s = expr_end;
3457 CHECK_FIELD (num, 671108864, 0, strict);
3458 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
3460 /* Handle a 3 bit SFU identifier at 25. */
3461 case 'v':
3462 if (*s++ != ',')
3463 as_bad (_("Invalid SFU identifier"));
3464 num = pa_get_absolute_expression (&the_insn, &s);
3465 if (strict && the_insn.exp.X_op != O_constant)
3466 break;
3467 s = expr_end;
3468 CHECK_FIELD (num, 7, 0, strict);
3469 INSERT_FIELD_AND_CONTINUE (opcode, num, 6);
3471 /* Handle a 20 bit SOP field for spop0. */
3472 case 'O':
3473 num = pa_get_absolute_expression (&the_insn, &s);
3474 if (strict && the_insn.exp.X_op != O_constant)
3475 break;
3476 s = expr_end;
3477 CHECK_FIELD (num, 1048575, 0, strict);
3478 num = (num & 0x1f) | ((num & 0x000fffe0) << 6);
3479 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
3481 /* Handle a 15bit SOP field for spop1. */
3482 case 'o':
3483 num = pa_get_absolute_expression (&the_insn, &s);
3484 if (strict && the_insn.exp.X_op != O_constant)
3485 break;
3486 s = expr_end;
3487 CHECK_FIELD (num, 32767, 0, strict);
3488 INSERT_FIELD_AND_CONTINUE (opcode, num, 11);
3490 /* Handle a 10bit SOP field for spop3. */
3491 case '0':
3492 num = pa_get_absolute_expression (&the_insn, &s);
3493 if (strict && the_insn.exp.X_op != O_constant)
3494 break;
3495 s = expr_end;
3496 CHECK_FIELD (num, 1023, 0, strict);
3497 num = (num & 0x1f) | ((num & 0x000003e0) << 6);
3498 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
3500 /* Handle a 15 bit SOP field for spop2. */
3501 case '1':
3502 num = pa_get_absolute_expression (&the_insn, &s);
3503 if (strict && the_insn.exp.X_op != O_constant)
3504 break;
3505 s = expr_end;
3506 CHECK_FIELD (num, 32767, 0, strict);
3507 num = (num & 0x1f) | ((num & 0x00007fe0) << 6);
3508 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
3510 /* Handle a 3-bit co-processor ID field. */
3511 case 'u':
3512 if (*s++ != ',')
3513 as_bad (_("Invalid COPR identifier"));
3514 num = pa_get_absolute_expression (&the_insn, &s);
3515 if (strict && the_insn.exp.X_op != O_constant)
3516 break;
3517 s = expr_end;
3518 CHECK_FIELD (num, 7, 0, strict);
3519 INSERT_FIELD_AND_CONTINUE (opcode, num, 6);
3521 /* Handle a 22bit SOP field for copr. */
3522 case '2':
3523 num = pa_get_absolute_expression (&the_insn, &s);
3524 if (strict && the_insn.exp.X_op != O_constant)
3525 break;
3526 s = expr_end;
3527 CHECK_FIELD (num, 4194303, 0, strict);
3528 num = (num & 0x1f) | ((num & 0x003fffe0) << 4);
3529 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
3531 /* Handle a source FP operand format completer. */
3532 case '{':
3533 if (*s == ',' && *(s+1) == 't')
3535 the_insn.trunc = 1;
3536 s += 2;
3538 else
3539 the_insn.trunc = 0;
3540 flag = pa_parse_fp_cnv_format (&s);
3541 the_insn.fpof1 = flag;
3542 if (flag == W || flag == UW)
3543 flag = SGL;
3544 if (flag == DW || flag == UDW)
3545 flag = DBL;
3546 if (flag == QW || flag == UQW)
3547 flag = QUAD;
3548 INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
3550 /* Handle a destination FP operand format completer. */
3551 case '_':
3552 /* pa_parse_format needs the ',' prefix. */
3553 s--;
3554 flag = pa_parse_fp_cnv_format (&s);
3555 the_insn.fpof2 = flag;
3556 if (flag == W || flag == UW)
3557 flag = SGL;
3558 if (flag == DW || flag == UDW)
3559 flag = DBL;
3560 if (flag == QW || flag == UQW)
3561 flag = QUAD;
3562 opcode |= flag << 13;
3563 if (the_insn.fpof1 == SGL
3564 || the_insn.fpof1 == DBL
3565 || the_insn.fpof1 == QUAD)
3567 if (the_insn.fpof2 == SGL
3568 || the_insn.fpof2 == DBL
3569 || the_insn.fpof2 == QUAD)
3570 flag = 0;
3571 else if (the_insn.fpof2 == W
3572 || the_insn.fpof2 == DW
3573 || the_insn.fpof2 == QW)
3574 flag = 2;
3575 else if (the_insn.fpof2 == UW
3576 || the_insn.fpof2 == UDW
3577 || the_insn.fpof2 == UQW)
3578 flag = 6;
3579 else
3580 abort ();
3582 else if (the_insn.fpof1 == W
3583 || the_insn.fpof1 == DW
3584 || the_insn.fpof1 == QW)
3586 if (the_insn.fpof2 == SGL
3587 || the_insn.fpof2 == DBL
3588 || the_insn.fpof2 == QUAD)
3589 flag = 1;
3590 else
3591 abort ();
3593 else if (the_insn.fpof1 == UW
3594 || the_insn.fpof1 == UDW
3595 || the_insn.fpof1 == UQW)
3597 if (the_insn.fpof2 == SGL
3598 || the_insn.fpof2 == DBL
3599 || the_insn.fpof2 == QUAD)
3600 flag = 5;
3601 else
3602 abort ();
3604 flag |= the_insn.trunc;
3605 INSERT_FIELD_AND_CONTINUE (opcode, flag, 15);
3607 /* Handle a source FP operand format completer. */
3608 case 'F':
3609 flag = pa_parse_fp_format (&s);
3610 the_insn.fpof1 = flag;
3611 INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
3613 /* Handle a destination FP operand format completer. */
3614 case 'G':
3615 /* pa_parse_format needs the ',' prefix. */
3616 s--;
3617 flag = pa_parse_fp_format (&s);
3618 the_insn.fpof2 = flag;
3619 INSERT_FIELD_AND_CONTINUE (opcode, flag, 13);
3621 /* Handle a source FP operand format completer at 20. */
3622 case 'I':
3623 flag = pa_parse_fp_format (&s);
3624 the_insn.fpof1 = flag;
3625 INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
3627 /* Handle a floating point operand format at 26.
3628 Only allows single and double precision. */
3629 case 'H':
3630 flag = pa_parse_fp_format (&s);
3631 switch (flag)
3633 case SGL:
3634 opcode |= 0x20;
3635 case DBL:
3636 the_insn.fpof1 = flag;
3637 continue;
3639 case QUAD:
3640 case ILLEGAL_FMT:
3641 default:
3642 as_bad (_("Invalid Floating Point Operand Format."));
3644 break;
3646 /* Handle all floating point registers. */
3647 case 'f':
3648 switch (*++args)
3650 /* Float target register. */
3651 case 't':
3652 /* This should be more strict. Small steps. */
3653 if (strict && *s != '%')
3654 break;
3655 num = pa_parse_number (&s, 0);
3656 CHECK_FIELD (num, 31, 0, 0);
3657 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
3659 /* Float target register with L/R selection. */
3660 case 'T':
3662 struct pa_11_fp_reg_struct result;
3664 /* This should be more strict. Small steps. */
3665 if (strict && *s != '%')
3666 break;
3667 pa_parse_number (&s, &result);
3668 CHECK_FIELD (result.number_part, 31, 0, 0);
3669 opcode |= result.number_part;
3671 /* 0x30 opcodes are FP arithmetic operation opcodes
3672 and need to be turned into 0x38 opcodes. This
3673 is not necessary for loads/stores. */
3674 if (need_pa11_opcode (&the_insn, &result)
3675 && ((opcode & 0xfc000000) == 0x30000000))
3676 opcode |= 1 << 27;
3678 INSERT_FIELD_AND_CONTINUE (opcode, result.l_r_select & 1, 6);
3681 /* Float operand 1. */
3682 case 'a':
3684 struct pa_11_fp_reg_struct result;
3686 /* This should be more strict. Small steps. */
3687 if (strict && *s != '%')
3688 break;
3689 pa_parse_number (&s, &result);
3690 CHECK_FIELD (result.number_part, 31, 0, 0);
3691 opcode |= result.number_part << 21;
3692 if (need_pa11_opcode (&the_insn, &result))
3694 opcode |= (result.l_r_select & 1) << 7;
3695 opcode |= 1 << 27;
3697 continue;
3700 /* Float operand 1 with L/R selection. */
3701 case 'X':
3702 case 'A':
3704 struct pa_11_fp_reg_struct result;
3706 /* This should be more strict. Small steps. */
3707 if (strict && *s != '%')
3708 break;
3709 pa_parse_number (&s, &result);
3710 CHECK_FIELD (result.number_part, 31, 0, 0);
3711 opcode |= result.number_part << 21;
3712 opcode |= (result.l_r_select & 1) << 7;
3713 continue;
3716 /* Float operand 2. */
3717 case 'b':
3719 struct pa_11_fp_reg_struct result;
3721 /* This should be more strict. Small steps. */
3722 if (strict && *s != '%')
3723 break;
3724 pa_parse_number (&s, &result);
3725 CHECK_FIELD (result.number_part, 31, 0, 0);
3726 opcode |= (result.number_part & 0x1f) << 16;
3727 if (need_pa11_opcode (&the_insn, &result))
3729 opcode |= (result.l_r_select & 1) << 12;
3730 opcode |= 1 << 27;
3732 continue;
3735 /* Float operand 2 with L/R selection. */
3736 case 'B':
3738 struct pa_11_fp_reg_struct result;
3740 /* This should be more strict. Small steps. */
3741 if (strict && *s != '%')
3742 break;
3743 pa_parse_number (&s, &result);
3744 CHECK_FIELD (result.number_part, 31, 0, 0);
3745 opcode |= (result.number_part & 0x1f) << 16;
3746 opcode |= (result.l_r_select & 1) << 12;
3747 continue;
3750 /* Float operand 3 for fmpyfadd, fmpynfadd. */
3751 case 'C':
3753 struct pa_11_fp_reg_struct result;
3755 /* This should be more strict. Small steps. */
3756 if (strict && *s != '%')
3757 break;
3758 pa_parse_number (&s, &result);
3759 CHECK_FIELD (result.number_part, 31, 0, 0);
3760 opcode |= (result.number_part & 0x1c) << 11;
3761 opcode |= (result.number_part & 0x3) << 9;
3762 opcode |= (result.l_r_select & 1) << 8;
3763 continue;
3766 /* Float mult operand 1 for fmpyadd, fmpysub */
3767 case 'i':
3769 struct pa_11_fp_reg_struct result;
3771 /* This should be more strict. Small steps. */
3772 if (strict && *s != '%')
3773 break;
3774 pa_parse_number (&s, &result);
3775 CHECK_FIELD (result.number_part, 31, 0, 0);
3776 if (the_insn.fpof1 == SGL)
3778 if (result.number_part < 16)
3780 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
3781 break;
3784 result.number_part &= 0xF;
3785 result.number_part |= (result.l_r_select & 1) << 4;
3787 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 21);
3790 /* Float mult operand 2 for fmpyadd, fmpysub */
3791 case 'j':
3793 struct pa_11_fp_reg_struct result;
3795 /* This should be more strict. Small steps. */
3796 if (strict && *s != '%')
3797 break;
3798 pa_parse_number (&s, &result);
3799 CHECK_FIELD (result.number_part, 31, 0, 0);
3800 if (the_insn.fpof1 == SGL)
3802 if (result.number_part < 16)
3804 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
3805 break;
3807 result.number_part &= 0xF;
3808 result.number_part |= (result.l_r_select & 1) << 4;
3810 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 16);
3813 /* Float mult target for fmpyadd, fmpysub */
3814 case 'k':
3816 struct pa_11_fp_reg_struct result;
3818 /* This should be more strict. Small steps. */
3819 if (strict && *s != '%')
3820 break;
3821 pa_parse_number (&s, &result);
3822 CHECK_FIELD (result.number_part, 31, 0, 0);
3823 if (the_insn.fpof1 == SGL)
3825 if (result.number_part < 16)
3827 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
3828 break;
3830 result.number_part &= 0xF;
3831 result.number_part |= (result.l_r_select & 1) << 4;
3833 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 0);
3836 /* Float add operand 1 for fmpyadd, fmpysub */
3837 case 'l':
3839 struct pa_11_fp_reg_struct result;
3841 /* This should be more strict. Small steps. */
3842 if (strict && *s != '%')
3843 break;
3844 pa_parse_number (&s, &result);
3845 CHECK_FIELD (result.number_part, 31, 0, 0);
3846 if (the_insn.fpof1 == SGL)
3848 if (result.number_part < 16)
3850 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
3851 break;
3853 result.number_part &= 0xF;
3854 result.number_part |= (result.l_r_select & 1) << 4;
3856 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 6);
3859 /* Float add target for fmpyadd, fmpysub */
3860 case 'm':
3862 struct pa_11_fp_reg_struct result;
3864 /* This should be more strict. Small steps. */
3865 if (strict && *s != '%')
3866 break;
3867 pa_parse_number (&s, &result);
3868 CHECK_FIELD (result.number_part, 31, 0, 0);
3869 if (the_insn.fpof1 == SGL)
3871 if (result.number_part < 16)
3873 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
3874 break;
3876 result.number_part &= 0xF;
3877 result.number_part |= (result.l_r_select & 1) << 4;
3879 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 11);
3882 /* Handle L/R register halves like 'x'. */
3883 case 'E':
3884 case 'e':
3886 struct pa_11_fp_reg_struct result;
3888 if (strict && *s != '%')
3889 break;
3890 pa_parse_number (&s, &result);
3891 CHECK_FIELD (result.number_part, 31, 0, 0);
3892 opcode |= (result.number_part & 0x1f) << 16;
3893 if (need_pa11_opcode (&the_insn, &result))
3895 opcode |= (result.l_r_select & 1) << 1;
3897 continue;
3900 /* Float target register (PA 2.0 wide). */
3901 case 'x':
3902 /* This should be more strict. Small steps. */
3903 if (strict && *s != '%')
3904 break;
3905 num = pa_parse_number (&s, 0);
3906 CHECK_FIELD (num, 31, 0, 0);
3907 INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
3909 default:
3910 abort ();
3912 break;
3914 default:
3915 abort ();
3917 break;
3920 failed:
3921 /* Check if the args matched. */
3922 if (match == FALSE)
3924 if (&insn[1] - pa_opcodes < (int) NUMOPCODES
3925 && !strcmp (insn->name, insn[1].name))
3927 ++insn;
3928 s = argstart;
3929 continue;
3931 else
3933 as_bad (_("Invalid operands %s"), error_message);
3934 return;
3937 break;
3940 the_insn.opcode = opcode;
3943 /* Turn a string in input_line_pointer into a floating point constant of type
3944 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
3945 emitted is stored in *sizeP . An error message or NULL is returned. */
3947 #define MAX_LITTLENUMS 6
3949 char *
3950 md_atof (type, litP, sizeP)
3951 char type;
3952 char *litP;
3953 int *sizeP;
3955 int prec;
3956 LITTLENUM_TYPE words[MAX_LITTLENUMS];
3957 LITTLENUM_TYPE *wordP;
3958 char *t;
3960 switch (type)
3963 case 'f':
3964 case 'F':
3965 case 's':
3966 case 'S':
3967 prec = 2;
3968 break;
3970 case 'd':
3971 case 'D':
3972 case 'r':
3973 case 'R':
3974 prec = 4;
3975 break;
3977 case 'x':
3978 case 'X':
3979 prec = 6;
3980 break;
3982 case 'p':
3983 case 'P':
3984 prec = 6;
3985 break;
3987 default:
3988 *sizeP = 0;
3989 return _("Bad call to MD_ATOF()");
3991 t = atof_ieee (input_line_pointer, type, words);
3992 if (t)
3993 input_line_pointer = t;
3994 *sizeP = prec * sizeof (LITTLENUM_TYPE);
3995 for (wordP = words; prec--;)
3997 md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE));
3998 litP += sizeof (LITTLENUM_TYPE);
4000 return NULL;
4003 /* Write out big-endian. */
4005 void
4006 md_number_to_chars (buf, val, n)
4007 char *buf;
4008 valueT val;
4009 int n;
4011 number_to_chars_bigendian (buf, val, n);
4014 /* Translate internal representation of relocation info to BFD target
4015 format. */
4017 arelent **
4018 tc_gen_reloc (section, fixp)
4019 asection *section;
4020 fixS *fixp;
4022 arelent *reloc;
4023 struct hppa_fix_struct *hppa_fixp;
4024 bfd_reloc_code_real_type code;
4025 static arelent *no_relocs = NULL;
4026 arelent **relocs;
4027 bfd_reloc_code_real_type **codes;
4028 int n_relocs;
4029 int i;
4031 hppa_fixp = (struct hppa_fix_struct *) fixp->tc_fix_data;
4032 if (fixp->fx_addsy == 0)
4033 return &no_relocs;
4034 assert (hppa_fixp != 0);
4035 assert (section != 0);
4037 reloc = (arelent *) xmalloc (sizeof (arelent));
4039 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
4040 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
4041 codes = (bfd_reloc_code_real_type **) hppa_gen_reloc_type (stdoutput,
4042 fixp->fx_r_type,
4043 hppa_fixp->fx_r_format,
4044 hppa_fixp->fx_r_field,
4045 fixp->fx_subsy != NULL,
4046 symbol_get_bfdsym (fixp->fx_addsy));
4048 if (codes == NULL)
4049 abort ();
4051 for (n_relocs = 0; codes[n_relocs]; n_relocs++)
4054 relocs = (arelent **) xmalloc (sizeof (arelent *) * n_relocs + 1);
4055 reloc = (arelent *) xmalloc (sizeof (arelent) * n_relocs);
4056 for (i = 0; i < n_relocs; i++)
4057 relocs[i] = &reloc[i];
4059 relocs[n_relocs] = NULL;
4061 #ifdef OBJ_ELF
4062 switch (fixp->fx_r_type)
4064 default:
4065 assert (n_relocs == 1);
4067 code = *codes[0];
4069 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
4070 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
4071 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
4072 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
4073 reloc->addend = 0; /* default */
4075 assert (reloc->howto && code == reloc->howto->type);
4077 /* Now, do any processing that is dependent on the relocation type. */
4078 switch (code)
4080 case R_PARISC_DLTREL21L:
4081 case R_PARISC_DLTREL14R:
4082 case R_PARISC_DLTREL14F:
4083 case R_PARISC_PLABEL32:
4084 case R_PARISC_PLABEL21L:
4085 case R_PARISC_PLABEL14R:
4086 /* For plabel relocations, the addend of the
4087 relocation should be either 0 (no static link) or 2
4088 (static link required).
4090 FIXME: We always assume no static link!
4092 We also slam a zero addend into the DLT relative relocs;
4093 it doesn't make a lot of sense to use any addend since
4094 it gets you a different (eg unknown) DLT entry. */
4095 reloc->addend = 0;
4096 break;
4098 case R_PARISC_PCREL21L:
4099 case R_PARISC_PCREL17R:
4100 case R_PARISC_PCREL17F:
4101 case R_PARISC_PCREL17C:
4102 case R_PARISC_PCREL14R:
4103 case R_PARISC_PCREL14F:
4104 /* The constant is stored in the instruction. */
4105 reloc->addend = HPPA_R_ADDEND (hppa_fixp->fx_arg_reloc, 0);
4106 break;
4107 default:
4108 reloc->addend = fixp->fx_offset;
4109 break;
4111 break;
4113 #else /* OBJ_SOM */
4115 /* Walk over reach relocation returned by the BFD backend. */
4116 for (i = 0; i < n_relocs; i++)
4118 code = *codes[i];
4120 relocs[i]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
4121 *relocs[i]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
4122 relocs[i]->howto = bfd_reloc_type_lookup (stdoutput, code);
4123 relocs[i]->address = fixp->fx_frag->fr_address + fixp->fx_where;
4125 switch (code)
4127 case R_COMP2:
4128 /* The only time we ever use a R_COMP2 fixup is for the difference
4129 of two symbols. With that in mind we fill in all four
4130 relocs now and break out of the loop. */
4131 assert (i == 1);
4132 relocs[0]->sym_ptr_ptr = (asymbol **) &(bfd_abs_symbol);
4133 relocs[0]->howto = bfd_reloc_type_lookup (stdoutput, *codes[0]);
4134 relocs[0]->address = fixp->fx_frag->fr_address + fixp->fx_where;
4135 relocs[0]->addend = 0;
4136 relocs[1]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
4137 *relocs[1]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
4138 relocs[1]->howto = bfd_reloc_type_lookup (stdoutput, *codes[1]);
4139 relocs[1]->address = fixp->fx_frag->fr_address + fixp->fx_where;
4140 relocs[1]->addend = 0;
4141 relocs[2]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
4142 *relocs[2]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_subsy);
4143 relocs[2]->howto = bfd_reloc_type_lookup (stdoutput, *codes[2]);
4144 relocs[2]->address = fixp->fx_frag->fr_address + fixp->fx_where;
4145 relocs[2]->addend = 0;
4146 relocs[3]->sym_ptr_ptr = (asymbol **) &(bfd_abs_symbol);
4147 relocs[3]->howto = bfd_reloc_type_lookup (stdoutput, *codes[3]);
4148 relocs[3]->address = fixp->fx_frag->fr_address + fixp->fx_where;
4149 relocs[3]->addend = 0;
4150 relocs[4]->sym_ptr_ptr = (asymbol **) &(bfd_abs_symbol);
4151 relocs[4]->howto = bfd_reloc_type_lookup (stdoutput, *codes[4]);
4152 relocs[4]->address = fixp->fx_frag->fr_address + fixp->fx_where;
4153 relocs[4]->addend = 0;
4154 goto done;
4155 case R_PCREL_CALL:
4156 case R_ABS_CALL:
4157 relocs[i]->addend = HPPA_R_ADDEND (hppa_fixp->fx_arg_reloc, 0);
4158 break;
4160 case R_DLT_REL:
4161 case R_DATA_PLABEL:
4162 case R_CODE_PLABEL:
4163 /* For plabel relocations, the addend of the
4164 relocation should be either 0 (no static link) or 2
4165 (static link required).
4167 FIXME: We always assume no static link!
4169 We also slam a zero addend into the DLT relative relocs;
4170 it doesn't make a lot of sense to use any addend since
4171 it gets you a different (eg unknown) DLT entry. */
4172 relocs[i]->addend = 0;
4173 break;
4175 case R_N_MODE:
4176 case R_S_MODE:
4177 case R_D_MODE:
4178 case R_R_MODE:
4179 case R_FSEL:
4180 case R_LSEL:
4181 case R_RSEL:
4182 case R_BEGIN_BRTAB:
4183 case R_END_BRTAB:
4184 case R_BEGIN_TRY:
4185 case R_N0SEL:
4186 case R_N1SEL:
4187 /* There is no symbol or addend associated with these fixups. */
4188 relocs[i]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
4189 *relocs[i]->sym_ptr_ptr = symbol_get_bfdsym (dummy_symbol);
4190 relocs[i]->addend = 0;
4191 break;
4193 case R_END_TRY:
4194 case R_ENTRY:
4195 case R_EXIT:
4196 /* There is no symbol associated with these fixups. */
4197 relocs[i]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
4198 *relocs[i]->sym_ptr_ptr = symbol_get_bfdsym (dummy_symbol);
4199 relocs[i]->addend = fixp->fx_offset;
4200 break;
4202 default:
4203 relocs[i]->addend = fixp->fx_offset;
4207 done:
4208 #endif
4210 return relocs;
4213 /* Process any machine dependent frag types. */
4215 void
4216 md_convert_frag (abfd, sec, fragP)
4217 register bfd *abfd ATTRIBUTE_UNUSED;
4218 register asection *sec ATTRIBUTE_UNUSED;
4219 register fragS *fragP;
4221 unsigned int address;
4223 if (fragP->fr_type == rs_machine_dependent)
4225 switch ((int) fragP->fr_subtype)
4227 case 0:
4228 fragP->fr_type = rs_fill;
4229 know (fragP->fr_var == 1);
4230 know (fragP->fr_next);
4231 address = fragP->fr_address + fragP->fr_fix;
4232 if (address % fragP->fr_offset)
4234 fragP->fr_offset =
4235 fragP->fr_next->fr_address
4236 - fragP->fr_address
4237 - fragP->fr_fix;
4239 else
4240 fragP->fr_offset = 0;
4241 break;
4246 /* Round up a section size to the appropriate boundary. */
4248 valueT
4249 md_section_align (segment, size)
4250 asection *segment;
4251 valueT size;
4253 int align = bfd_get_section_alignment (stdoutput, segment);
4254 int align2 = (1 << align) - 1;
4256 return (size + align2) & ~align2;
4259 /* Return the approximate size of a frag before relaxation has occurred. */
4261 md_estimate_size_before_relax (fragP, segment)
4262 register fragS *fragP;
4263 asection *segment ATTRIBUTE_UNUSED;
4265 int size;
4267 size = 0;
4269 while ((fragP->fr_fix + size) % fragP->fr_offset)
4270 size++;
4272 return size;
4275 CONST char *md_shortopts = "";
4276 struct option md_longopts[] = {
4277 {NULL, no_argument, NULL, 0}
4279 size_t md_longopts_size = sizeof(md_longopts);
4282 md_parse_option (c, arg)
4283 int c ATTRIBUTE_UNUSED;
4284 char *arg ATTRIBUTE_UNUSED;
4286 return 0;
4289 void
4290 md_show_usage (stream)
4291 FILE *stream ATTRIBUTE_UNUSED;
4295 /* We have no need to default values of symbols. */
4297 symbolS *
4298 md_undefined_symbol (name)
4299 char *name ATTRIBUTE_UNUSED;
4301 return 0;
4304 /* Apply a fixup to an instruction. */
4307 md_apply_fix (fixP, valp)
4308 fixS *fixP;
4309 valueT *valp;
4311 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
4312 struct hppa_fix_struct *hppa_fixP;
4313 offsetT new_val;
4314 unsigned int insn, val;
4316 hppa_fixP = (struct hppa_fix_struct *) fixP->tc_fix_data;
4317 /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
4318 never be "applied" (they are just markers). Likewise for
4319 R_HPPA_BEGIN_BRTAB and R_HPPA_END_BRTAB. */
4320 #ifdef OBJ_SOM
4321 if (fixP->fx_r_type == R_HPPA_ENTRY
4322 || fixP->fx_r_type == R_HPPA_EXIT
4323 || fixP->fx_r_type == R_HPPA_BEGIN_BRTAB
4324 || fixP->fx_r_type == R_HPPA_END_BRTAB
4325 || fixP->fx_r_type == R_HPPA_BEGIN_TRY)
4326 return 1;
4328 /* Disgusting. We must set fx_offset ourselves -- R_HPPA_END_TRY
4329 fixups are considered not adjustable, which in turn causes
4330 adjust_reloc_syms to not set fx_offset. Ugh. */
4331 if (fixP->fx_r_type == R_HPPA_END_TRY)
4333 fixP->fx_offset = *valp;
4334 return 1;
4336 #endif
4338 /* There should have been an HPPA specific fixup associated
4339 with the GAS fixup. */
4340 if (hppa_fixP)
4342 unsigned long buf_wd = bfd_get_32 (stdoutput, buf);
4343 int fmt = bfd_hppa_insn2fmt (buf_wd);
4345 /* If there is a symbol associated with this fixup, then it's something
4346 which will need a SOM relocation (except for some PC-relative relocs).
4347 In such cases we should treat the "val" or "addend" as zero since it
4348 will be added in as needed from fx_offset in tc_gen_reloc. */
4349 if ((fixP->fx_addsy != NULL
4350 || fixP->fx_r_type == R_HPPA_NONE)
4351 #ifdef OBJ_SOM
4352 && fmt != 32
4353 #endif
4355 new_val = ((fmt == 12 || fmt == 17 || fmt == 22) ? 8 : 0);
4356 #ifdef OBJ_SOM
4357 /* These field selectors imply that we do not want an addend. */
4358 else if (hppa_fixP->fx_r_field == e_psel
4359 || hppa_fixP->fx_r_field == e_rpsel
4360 || hppa_fixP->fx_r_field == e_lpsel
4361 || hppa_fixP->fx_r_field == e_tsel
4362 || hppa_fixP->fx_r_field == e_rtsel
4363 || hppa_fixP->fx_r_field == e_ltsel)
4364 new_val = ((fmt == 12 || fmt == 17 || fmt == 22) ? 8 : 0);
4365 /* This is truely disgusting. The machine independent code blindly
4366 adds in the value of the symbol being relocated against. Damn! */
4367 else if (fmt == 32
4368 && fixP->fx_addsy != NULL
4369 && S_GET_SEGMENT (fixP->fx_addsy) != bfd_com_section_ptr)
4370 new_val = hppa_field_adjust (*valp - S_GET_VALUE (fixP->fx_addsy),
4371 0, hppa_fixP->fx_r_field);
4372 #endif
4373 else
4374 new_val = hppa_field_adjust (*valp, 0, hppa_fixP->fx_r_field);
4376 /* Handle pc-relative exceptions from above. */
4377 #define arg_reloc_stub_needed(CALLER, CALLEE) \
4378 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
4379 if ((fmt == 12 || fmt == 17 || fmt == 22)
4380 && fixP->fx_addsy
4381 && fixP->fx_pcrel
4382 #ifdef OBJ_SOM
4383 && !arg_reloc_stub_needed ((long) ((obj_symbol_type *)
4384 symbol_get_bfdsym (fixP->fx_addsy))->tc_data.ap.hppa_arg_reloc,
4385 hppa_fixP->fx_arg_reloc)
4386 #endif
4387 && (((int)(*valp) > -262144 && (int)(*valp) < 262143) && fmt != 22)
4388 && S_GET_SEGMENT (fixP->fx_addsy) == hppa_fixP->segment
4389 && !(fixP->fx_subsy
4390 && S_GET_SEGMENT (fixP->fx_subsy) != hppa_fixP->segment))
4392 new_val = hppa_field_adjust (*valp, 0, hppa_fixP->fx_r_field);
4393 #undef arg_reloc_stub_needed
4395 insn = bfd_get_32 (stdoutput, buf);
4396 switch (fmt)
4398 case 10:
4399 CHECK_FIELD (new_val, 8191, -8192, 0);
4400 val = new_val;
4402 insn = (insn & ~ 0x3ff1) | (((val & 0x1ff8) << 1)
4403 | ((val & 0x2000) >> 13));
4404 break;
4405 case -11:
4406 CHECK_FIELD (new_val, 8191, -8192, 0);
4407 val = new_val;
4409 insn = (insn & ~ 0x3ff9) | (((val & 0x1ffc) << 1)
4410 | ((val & 0x2000) >> 13));
4411 break;
4412 /* Handle all opcodes with the 'j' operand type. */
4413 case 14:
4414 CHECK_FIELD (new_val, 8191, -8192, 0);
4415 val = new_val;
4417 insn = ((insn & ~ 0x3fff) | low_sign_unext (val, 14));
4418 break;
4420 /* Handle all opcodes with the 'k' operand type. */
4421 case 21:
4422 CHECK_FIELD (new_val, 1048576, -1048576, 0);
4423 val = new_val;
4425 insn = re_assemble_21 (insn & ~ 0x1fffff, val);
4426 break;
4428 /* Handle all the opcodes with the 'i' operand type. */
4429 case 11:
4430 CHECK_FIELD (new_val, 1023, -1023, 0);
4431 val = new_val;
4433 insn = (insn & ~ 0x7ff) | low_sign_unext (val, 11);
4434 break;
4436 /* Handle all the opcodes with the 'w' operand type. */
4437 case 12:
4438 CHECK_FIELD (new_val, 8199, -8184, 0);
4439 val = new_val;
4441 insn = re_assemble_12 (insn & ~ 0x1ffd, (val - 8) >> 2);
4442 break;
4444 /* Handle some of the opcodes with the 'W' operand type. */
4445 case 17:
4447 offsetT distance = *valp;
4449 /* If this is an absolute branch (ie no link) with an out of
4450 range target, then we want to complain. */
4451 if (fixP->fx_r_type == R_HPPA_PCREL_CALL
4452 && (insn & 0xffe00000) == 0xe8000000)
4453 CHECK_FIELD (distance, 262143, -262144, 0);
4455 CHECK_FIELD (new_val, 262143, -262144, 0);
4456 val = new_val;
4458 insn = re_assemble_17 (insn & ~ 0x1f1ffd, (val - 8) >> 2);
4459 break;
4462 case 22:
4464 offsetT distance = *valp;
4466 /* If this is an absolute branch (ie no link) with an out of
4467 range target, then we want to complain. */
4468 if (fixP->fx_r_type == R_HPPA_PCREL_CALL
4469 && (insn & 0xffe00000) == 0xe8000000)
4470 CHECK_FIELD (distance, 8388607, -8388608, 0);
4472 CHECK_FIELD (new_val, 8388607, -8388608, 0);
4473 val = new_val;
4475 insn = re_assemble_22 (insn & ~ 0x3ff1ffd, (val - 8) >> 2);
4476 break;
4479 case 32:
4480 insn = new_val;
4481 break;
4483 default:
4484 as_bad (_("Unknown relocation encountered in md_apply_fix."));
4485 return 0;
4488 /* Insert the relocation. */
4489 bfd_put_32 (stdoutput, insn, buf);
4490 return 1;
4492 else
4494 printf (_("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n"),
4495 (unsigned int) fixP, fixP->fx_r_type);
4496 return 0;
4500 /* Exactly what point is a PC-relative offset relative TO?
4501 On the PA, they're relative to the address of the offset. */
4503 long
4504 md_pcrel_from (fixP)
4505 fixS *fixP;
4507 return fixP->fx_where + fixP->fx_frag->fr_address;
4510 /* Return nonzero if the input line pointer is at the end of
4511 a statement. */
4513 static int
4514 is_end_of_statement ()
4516 return ((*input_line_pointer == '\n')
4517 || (*input_line_pointer == ';')
4518 || (*input_line_pointer == '!'));
4521 /* Read a number from S. The number might come in one of many forms,
4522 the most common will be a hex or decimal constant, but it could be
4523 a pre-defined register (Yuk!), or an absolute symbol.
4525 Return a number or -1 for failure.
4527 When parsing PA-89 FP register numbers RESULT will be
4528 the address of a structure to return information about
4529 L/R half of FP registers, store results there as appropriate.
4531 pa_parse_number can not handle negative constants and will fail
4532 horribly if it is passed such a constant. */
4534 static int
4535 pa_parse_number (s, result)
4536 char **s;
4537 struct pa_11_fp_reg_struct *result;
4539 int num;
4540 char *name;
4541 char c;
4542 symbolS *sym;
4543 int status;
4544 char *p = *s;
4546 /* Skip whitespace before the number. */
4547 while (*p == ' ' || *p == '\t')
4548 p = p + 1;
4550 /* Store info in RESULT if requested by caller. */
4551 if (result)
4553 result->number_part = -1;
4554 result->l_r_select = -1;
4556 num = -1;
4558 if (isdigit (*p))
4560 /* Looks like a number. */
4561 num = 0;
4563 if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X'))
4565 /* The number is specified in hex. */
4566 p += 2;
4567 while (isdigit (*p) || ((*p >= 'a') && (*p <= 'f'))
4568 || ((*p >= 'A') && (*p <= 'F')))
4570 if (isdigit (*p))
4571 num = num * 16 + *p - '0';
4572 else if (*p >= 'a' && *p <= 'f')
4573 num = num * 16 + *p - 'a' + 10;
4574 else
4575 num = num * 16 + *p - 'A' + 10;
4576 ++p;
4579 else
4581 /* The number is specified in decimal. */
4582 while (isdigit (*p))
4584 num = num * 10 + *p - '0';
4585 ++p;
4589 /* Store info in RESULT if requested by the caller. */
4590 if (result)
4592 result->number_part = num;
4594 if (IS_R_SELECT (p))
4596 result->l_r_select = 1;
4597 ++p;
4599 else if (IS_L_SELECT (p))
4601 result->l_r_select = 0;
4602 ++p;
4604 else
4605 result->l_r_select = 0;
4608 else if (*p == '%')
4610 /* The number might be a predefined register. */
4611 num = 0;
4612 name = p;
4613 p++;
4614 c = *p;
4615 /* Tege hack: Special case for general registers as the general
4616 code makes a binary search with case translation, and is VERY
4617 slow. */
4618 if (c == 'r')
4620 p++;
4621 if (*p == 'e' && *(p + 1) == 't'
4622 && (*(p + 2) == '0' || *(p + 2) == '1'))
4624 p += 2;
4625 num = *p - '0' + 28;
4626 p++;
4628 else if (*p == 'p')
4630 num = 2;
4631 p++;
4633 else if (!isdigit (*p))
4635 if (print_errors)
4636 as_bad (_("Undefined register: '%s'."), name);
4637 num = -1;
4639 else
4642 num = num * 10 + *p++ - '0';
4643 while (isdigit (*p));
4646 else
4648 /* Do a normal register search. */
4649 while (is_part_of_name (c))
4651 p = p + 1;
4652 c = *p;
4654 *p = 0;
4655 status = reg_name_search (name);
4656 if (status >= 0)
4657 num = status;
4658 else
4660 if (print_errors)
4661 as_bad (_("Undefined register: '%s'."), name);
4662 num = -1;
4664 *p = c;
4667 /* Store info in RESULT if requested by caller. */
4668 if (result)
4670 result->number_part = num;
4671 if (IS_R_SELECT (p - 1))
4672 result->l_r_select = 1;
4673 else if (IS_L_SELECT (p - 1))
4674 result->l_r_select = 0;
4675 else
4676 result->l_r_select = 0;
4679 else
4681 /* And finally, it could be a symbol in the absolute section which
4682 is effectively a constant. */
4683 num = 0;
4684 name = p;
4685 c = *p;
4686 while (is_part_of_name (c))
4688 p = p + 1;
4689 c = *p;
4691 *p = 0;
4692 if ((sym = symbol_find (name)) != NULL)
4694 if (S_GET_SEGMENT (sym) == &bfd_abs_section)
4695 num = S_GET_VALUE (sym);
4696 else
4698 if (print_errors)
4699 as_bad (_("Non-absolute symbol: '%s'."), name);
4700 num = -1;
4703 else
4705 /* There is where we'd come for an undefined symbol
4706 or for an empty string. For an empty string we
4707 will return zero. That's a concession made for
4708 compatability with the braindamaged HP assemblers. */
4709 if (*name == 0)
4710 num = 0;
4711 else
4713 if (print_errors)
4714 as_bad (_("Undefined absolute constant: '%s'."), name);
4715 num = -1;
4718 *p = c;
4720 /* Store info in RESULT if requested by caller. */
4721 if (result)
4723 result->number_part = num;
4724 if (IS_R_SELECT (p - 1))
4725 result->l_r_select = 1;
4726 else if (IS_L_SELECT (p - 1))
4727 result->l_r_select = 0;
4728 else
4729 result->l_r_select = 0;
4733 *s = p;
4734 return num;
4737 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
4739 /* Given NAME, find the register number associated with that name, return
4740 the integer value associated with the given name or -1 on failure. */
4742 static int
4743 reg_name_search (name)
4744 char *name;
4746 int middle, low, high;
4747 int cmp;
4749 low = 0;
4750 high = REG_NAME_CNT - 1;
4754 middle = (low + high) / 2;
4755 cmp = strcasecmp (name, pre_defined_registers[middle].name);
4756 if (cmp < 0)
4757 high = middle - 1;
4758 else if (cmp > 0)
4759 low = middle + 1;
4760 else
4761 return pre_defined_registers[middle].value;
4763 while (low <= high);
4765 return -1;
4769 /* Return nonzero if the given INSN and L/R information will require
4770 a new PA-1.1 opcode. */
4772 static int
4773 need_pa11_opcode (insn, result)
4774 struct pa_it *insn;
4775 struct pa_11_fp_reg_struct *result;
4777 if (result->l_r_select == 1 && !(insn->fpof1 == DBL && insn->fpof2 == DBL))
4779 /* If this instruction is specific to a particular architecture,
4780 then set a new architecture. */
4781 if (bfd_get_mach (stdoutput) < pa11)
4783 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, pa11))
4784 as_warn (_("could not update architecture and machine"));
4786 return TRUE;
4788 else
4789 return FALSE;
4792 /* Parse a condition for a fcmp instruction. Return the numerical
4793 code associated with the condition. */
4795 static int
4796 pa_parse_fp_cmp_cond (s)
4797 char **s;
4799 int cond, i;
4801 cond = 0;
4803 for (i = 0; i < 32; i++)
4805 if (strncasecmp (*s, fp_cond_map[i].string,
4806 strlen (fp_cond_map[i].string)) == 0)
4808 cond = fp_cond_map[i].cond;
4809 *s += strlen (fp_cond_map[i].string);
4810 /* If not a complete match, back up the input string and
4811 report an error. */
4812 if (**s != ' ' && **s != '\t')
4814 *s -= strlen (fp_cond_map[i].string);
4815 break;
4817 while (**s == ' ' || **s == '\t')
4818 *s = *s + 1;
4819 return cond;
4823 as_bad (_("Invalid FP Compare Condition: %s"), *s);
4825 /* Advance over the bogus completer. */
4826 while (**s != ',' && **s != ' ' && **s != '\t')
4827 *s += 1;
4829 return 0;
4832 /* Parse a graphics test complete for ftest. */
4834 static int
4835 pa_parse_ftest_gfx_completer (s)
4836 char **s;
4838 int value;
4840 value = 0;
4841 if (strncasecmp (*s, "acc8", 4) == 0)
4843 value = 5;
4844 *s += 4;
4846 else if (strncasecmp (*s, "acc6", 4) == 0)
4848 value = 9;
4849 *s += 4;
4851 else if (strncasecmp (*s, "acc4", 4) == 0)
4853 value = 13;
4854 *s += 4;
4856 else if (strncasecmp (*s, "acc2", 4) == 0)
4858 value = 17;
4859 *s += 4;
4861 else if (strncasecmp (*s, "acc", 3) == 0)
4863 value = 1;
4864 *s += 3;
4866 else if (strncasecmp (*s, "rej8", 4) == 0)
4868 value = 6;
4869 *s += 4;
4871 else if (strncasecmp (*s, "rej", 3) == 0)
4873 value = 2;
4874 *s += 3;
4876 else
4878 value = 0;
4879 as_bad (_("Invalid FTEST completer: %s"), *s);
4882 return value;
4885 /* Parse an FP operand format completer returning the completer
4886 type. */
4888 static fp_operand_format
4889 pa_parse_fp_cnv_format (s)
4890 char **s;
4892 int format;
4894 format = SGL;
4895 if (**s == ',')
4897 *s += 1;
4898 if (strncasecmp (*s, "sgl", 3) == 0)
4900 format = SGL;
4901 *s += 4;
4903 else if (strncasecmp (*s, "dbl", 3) == 0)
4905 format = DBL;
4906 *s += 4;
4908 else if (strncasecmp (*s, "quad", 4) == 0)
4910 format = QUAD;
4911 *s += 5;
4913 else if (strncasecmp (*s, "w", 1) == 0)
4915 format = W;
4916 *s += 2;
4918 else if (strncasecmp (*s, "uw", 2) == 0)
4920 format = UW;
4921 *s += 3;
4923 else if (strncasecmp (*s, "dw", 2) == 0)
4925 format = DW;
4926 *s += 3;
4928 else if (strncasecmp (*s, "udw", 3) == 0)
4930 format = UDW;
4931 *s += 4;
4933 else if (strncasecmp (*s, "qw", 2) == 0)
4935 format = QW;
4936 *s += 3;
4938 else if (strncasecmp (*s, "uqw", 3) == 0)
4940 format = UQW;
4941 *s += 4;
4943 else
4945 format = ILLEGAL_FMT;
4946 as_bad (_("Invalid FP Operand Format: %3s"), *s);
4950 return format;
4953 /* Parse an FP operand format completer returning the completer
4954 type. */
4956 static fp_operand_format
4957 pa_parse_fp_format (s)
4958 char **s;
4960 int format;
4962 format = SGL;
4963 if (**s == ',')
4965 *s += 1;
4966 if (strncasecmp (*s, "sgl", 3) == 0)
4968 format = SGL;
4969 *s += 4;
4971 else if (strncasecmp (*s, "dbl", 3) == 0)
4973 format = DBL;
4974 *s += 4;
4976 else if (strncasecmp (*s, "quad", 4) == 0)
4978 format = QUAD;
4979 *s += 5;
4981 else
4983 format = ILLEGAL_FMT;
4984 as_bad (_("Invalid FP Operand Format: %3s"), *s);
4988 return format;
4991 /* Convert from a selector string into a selector type. */
4993 static int
4994 pa_chk_field_selector (str)
4995 char **str;
4997 int middle, low, high;
4998 int cmp;
4999 char name[4];
5001 /* Read past any whitespace. */
5002 /* FIXME: should we read past newlines and formfeeds??? */
5003 while (**str == ' ' || **str == '\t' || **str == '\n' || **str == '\f')
5004 *str = *str + 1;
5006 if ((*str)[1] == '\'' || (*str)[1] == '%')
5007 name[0] = tolower ((*str)[0]),
5008 name[1] = 0;
5009 else if ((*str)[2] == '\'' || (*str)[2] == '%')
5010 name[0] = tolower ((*str)[0]),
5011 name[1] = tolower ((*str)[1]),
5012 name[2] = 0;
5013 else if ((*str)[3] == '\'' || (*str)[3] == '%')
5014 name[0] = tolower ((*str)[0]),
5015 name[1] = tolower ((*str)[1]),
5016 name[2] = tolower ((*str)[2]),
5017 name[3] = 0;
5018 else
5019 return e_fsel;
5021 low = 0;
5022 high = sizeof (selector_table) / sizeof (struct selector_entry) - 1;
5026 middle = (low + high) / 2;
5027 cmp = strcmp (name, selector_table[middle].prefix);
5028 if (cmp < 0)
5029 high = middle - 1;
5030 else if (cmp > 0)
5031 low = middle + 1;
5032 else
5034 *str += strlen (name) + 1;
5035 #ifndef OBJ_SOM
5036 if (selector_table[middle].field_selector == e_nsel)
5037 return e_fsel;
5038 #endif
5039 return selector_table[middle].field_selector;
5042 while (low <= high);
5044 return e_fsel;
5047 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
5049 static int
5050 get_expression (str)
5051 char *str;
5053 char *save_in;
5054 asection *seg;
5056 save_in = input_line_pointer;
5057 input_line_pointer = str;
5058 seg = expression (&the_insn.exp);
5059 if (!(seg == absolute_section
5060 || seg == undefined_section
5061 || SEG_NORMAL (seg)))
5063 as_warn (_("Bad segment in expression."));
5064 expr_end = input_line_pointer;
5065 input_line_pointer = save_in;
5066 return 1;
5068 expr_end = input_line_pointer;
5069 input_line_pointer = save_in;
5070 return 0;
5073 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
5074 static int
5075 pa_get_absolute_expression (insn, strp)
5076 struct pa_it *insn;
5077 char **strp;
5079 char *save_in;
5081 insn->field_selector = pa_chk_field_selector (strp);
5082 save_in = input_line_pointer;
5083 input_line_pointer = *strp;
5084 expression (&insn->exp);
5085 /* This is not perfect, but is a huge improvement over doing nothing.
5087 The PA assembly syntax is ambigious in a variety of ways. Consider
5088 this string "4 %r5" Is that the number 4 followed by the register
5089 r5, or is that 4 MOD 5?
5091 If we get a modulo expresion When looking for an absolute, we try
5092 again cutting off the input string at the first whitespace character. */
5093 if (insn->exp.X_op == O_modulus)
5095 char *s, c;
5096 int retval;
5098 input_line_pointer = *strp;
5099 s = *strp;
5100 while (*s != ',' && *s != ' ' && *s != '\t')
5101 s++;
5103 c = *s;
5104 *s = 0;
5106 retval = pa_get_absolute_expression (insn, strp);
5108 input_line_pointer = save_in;
5109 *s = c;
5110 return evaluate_absolute (insn);
5112 /* When in strict mode we have a non-match, fix up the pointers
5113 and return to our caller. */
5114 if (insn->exp.X_op != O_constant && strict)
5116 expr_end = input_line_pointer;
5117 input_line_pointer = save_in;
5118 return 0;
5120 if (insn->exp.X_op != O_constant)
5122 as_bad (_("Bad segment (should be absolute)."));
5123 expr_end = input_line_pointer;
5124 input_line_pointer = save_in;
5125 return 0;
5127 expr_end = input_line_pointer;
5128 input_line_pointer = save_in;
5129 return evaluate_absolute (insn);
5132 /* Evaluate an absolute expression EXP which may be modified by
5133 the selector FIELD_SELECTOR. Return the value of the expression. */
5134 static int
5135 evaluate_absolute (insn)
5136 struct pa_it *insn;
5138 offsetT value;
5139 expressionS exp;
5140 int field_selector = insn->field_selector;
5142 exp = insn->exp;
5143 value = exp.X_add_number;
5145 return hppa_field_adjust (0, value, field_selector);
5148 /* Given an argument location specification return the associated
5149 argument location number. */
5151 static unsigned int
5152 pa_build_arg_reloc (type_name)
5153 char *type_name;
5156 if (strncasecmp (type_name, "no", 2) == 0)
5157 return 0;
5158 if (strncasecmp (type_name, "gr", 2) == 0)
5159 return 1;
5160 else if (strncasecmp (type_name, "fr", 2) == 0)
5161 return 2;
5162 else if (strncasecmp (type_name, "fu", 2) == 0)
5163 return 3;
5164 else
5165 as_bad (_("Invalid argument location: %s\n"), type_name);
5167 return 0;
5170 /* Encode and return an argument relocation specification for
5171 the given register in the location specified by arg_reloc. */
5173 static unsigned int
5174 pa_align_arg_reloc (reg, arg_reloc)
5175 unsigned int reg;
5176 unsigned int arg_reloc;
5178 unsigned int new_reloc;
5180 new_reloc = arg_reloc;
5181 switch (reg)
5183 case 0:
5184 new_reloc <<= 8;
5185 break;
5186 case 1:
5187 new_reloc <<= 6;
5188 break;
5189 case 2:
5190 new_reloc <<= 4;
5191 break;
5192 case 3:
5193 new_reloc <<= 2;
5194 break;
5195 default:
5196 as_bad (_("Invalid argument description: %d"), reg);
5199 return new_reloc;
5202 /* Parse a PA nullification completer (,n). Return nonzero if the
5203 completer was found; return zero if no completer was found. */
5205 static int
5206 pa_parse_nullif (s)
5207 char **s;
5209 int nullif;
5211 nullif = 0;
5212 if (**s == ',')
5214 *s = *s + 1;
5215 if (strncasecmp (*s, "n", 1) == 0)
5216 nullif = 1;
5217 else
5219 as_bad (_("Invalid Nullification: (%c)"), **s);
5220 nullif = 0;
5222 *s = *s + 1;
5225 return nullif;
5228 /* Parse a non-negated compare/subtract completer returning the
5229 number (for encoding in instrutions) of the given completer.
5231 ISBRANCH specifies whether or not this is parsing a condition
5232 completer for a branch (vs a nullification completer for a
5233 computational instruction. */
5235 static int
5236 pa_parse_nonneg_cmpsub_cmpltr (s, isbranch)
5237 char **s;
5238 int isbranch;
5240 int cmpltr;
5241 char *name = *s + 1;
5242 char c;
5243 char *save_s = *s;
5244 int nullify = 0;
5246 cmpltr = 0;
5247 if (**s == ',')
5249 *s += 1;
5250 while (**s != ',' && **s != ' ' && **s != '\t')
5251 *s += 1;
5252 c = **s;
5253 **s = 0x00;
5256 if (strcmp (name, "=") == 0)
5258 cmpltr = 1;
5260 else if (strcmp (name, "<") == 0)
5262 cmpltr = 2;
5264 else if (strcmp (name, "<=") == 0)
5266 cmpltr = 3;
5268 else if (strcmp (name, "<<") == 0)
5270 cmpltr = 4;
5272 else if (strcmp (name, "<<=") == 0)
5274 cmpltr = 5;
5276 else if (strcasecmp (name, "sv") == 0)
5278 cmpltr = 6;
5280 else if (strcasecmp (name, "od") == 0)
5282 cmpltr = 7;
5284 /* If we have something like addb,n then there is no condition
5285 completer. */
5286 else if (strcasecmp (name, "n") == 0 && isbranch)
5288 cmpltr = 0;
5289 nullify = 1;
5291 else
5293 cmpltr = -1;
5295 **s = c;
5298 /* Reset pointers if this was really a ,n for a branch instruction. */
5299 if (nullify)
5300 *s = save_s;
5303 return cmpltr;
5306 /* Parse a negated compare/subtract completer returning the
5307 number (for encoding in instrutions) of the given completer.
5309 ISBRANCH specifies whether or not this is parsing a condition
5310 completer for a branch (vs a nullification completer for a
5311 computational instruction. */
5313 static int
5314 pa_parse_neg_cmpsub_cmpltr (s, isbranch)
5315 char **s;
5316 int isbranch;
5318 int cmpltr;
5319 char *name = *s + 1;
5320 char c;
5321 char *save_s = *s;
5322 int nullify = 0;
5324 cmpltr = 0;
5325 if (**s == ',')
5327 *s += 1;
5328 while (**s != ',' && **s != ' ' && **s != '\t')
5329 *s += 1;
5330 c = **s;
5331 **s = 0x00;
5334 if (strcasecmp (name, "tr") == 0)
5336 cmpltr = 0;
5338 else if (strcmp (name, "<>") == 0)
5340 cmpltr = 1;
5342 else if (strcmp (name, ">=") == 0)
5344 cmpltr = 2;
5346 else if (strcmp (name, ">") == 0)
5348 cmpltr = 3;
5350 else if (strcmp (name, ">>=") == 0)
5352 cmpltr = 4;
5354 else if (strcmp (name, ">>") == 0)
5356 cmpltr = 5;
5358 else if (strcasecmp (name, "nsv") == 0)
5360 cmpltr = 6;
5362 else if (strcasecmp (name, "ev") == 0)
5364 cmpltr = 7;
5366 /* If we have something like addb,n then there is no condition
5367 completer. */
5368 else if (strcasecmp (name, "n") == 0 && isbranch)
5370 cmpltr = 0;
5371 nullify = 1;
5373 else
5375 cmpltr = -1;
5377 **s = c;
5380 /* Reset pointers if this was really a ,n for a branch instruction. */
5381 if (nullify)
5382 *s = save_s;
5385 return cmpltr;
5389 /* Parse a 64 bit compare and branch completer returning the number (for
5390 encoding in instrutions) of the given completer.
5392 Nonnegated comparisons are returned as 0-7, negated comparisons are
5393 returned as 8-15. */
5395 static int
5396 pa_parse_cmpb_64_cmpltr (s)
5397 char **s;
5399 int cmpltr;
5400 char *name = *s + 1;
5401 char c;
5403 cmpltr = -1;
5404 if (**s == ',')
5406 *s += 1;
5407 while (**s != ',' && **s != ' ' && **s != '\t')
5408 *s += 1;
5409 c = **s;
5410 **s = 0x00;
5412 if (strcmp (name, "*") == 0)
5414 cmpltr = 0;
5416 else if (strcmp (name, "*=") == 0)
5418 cmpltr = 1;
5420 else if (strcmp (name, "*<") == 0)
5422 cmpltr = 2;
5424 else if (strcmp (name, "*<=") == 0)
5426 cmpltr = 3;
5428 else if (strcmp (name, "*<<") == 0)
5430 cmpltr = 4;
5432 else if (strcmp (name, "*<<=") == 0)
5434 cmpltr = 5;
5436 else if (strcasecmp (name, "*sv") == 0)
5438 cmpltr = 6;
5440 else if (strcasecmp (name, "*od") == 0)
5442 cmpltr = 7;
5444 else if (strcasecmp (name, "*tr") == 0)
5446 cmpltr = 8;
5448 else if (strcmp (name, "*<>") == 0)
5450 cmpltr = 9;
5452 else if (strcmp (name, "*>=") == 0)
5454 cmpltr = 10;
5456 else if (strcmp (name, "*>") == 0)
5458 cmpltr = 11;
5460 else if (strcmp (name, "*>>=") == 0)
5462 cmpltr = 12;
5464 else if (strcmp (name, "*>>") == 0)
5466 cmpltr = 13;
5468 else if (strcasecmp (name, "*nsv") == 0)
5470 cmpltr = 14;
5472 else if (strcasecmp (name, "*ev") == 0)
5474 cmpltr = 15;
5476 else
5478 cmpltr = -1;
5480 **s = c;
5484 return cmpltr;
5487 /* Parse a 64 bit compare immediate and branch completer returning the number
5488 (for encoding in instrutions) of the given completer. */
5490 static int
5491 pa_parse_cmpib_64_cmpltr (s)
5492 char **s;
5494 int cmpltr;
5495 char *name = *s + 1;
5496 char c;
5498 cmpltr = -1;
5499 if (**s == ',')
5501 *s += 1;
5502 while (**s != ',' && **s != ' ' && **s != '\t')
5503 *s += 1;
5504 c = **s;
5505 **s = 0x00;
5507 if (strcmp (name, "*<<") == 0)
5509 cmpltr = 0;
5511 else if (strcmp (name, "*=") == 0)
5513 cmpltr = 1;
5515 else if (strcmp (name, "*<") == 0)
5517 cmpltr = 2;
5519 else if (strcmp (name, "*<=") == 0)
5521 cmpltr = 3;
5523 else if (strcmp (name, "*>>=") == 0)
5525 cmpltr = 4;
5527 else if (strcmp (name, "*<>") == 0)
5529 cmpltr = 5;
5531 else if (strcasecmp (name, "*>=") == 0)
5533 cmpltr = 6;
5535 else if (strcasecmp (name, "*>") == 0)
5537 cmpltr = 7;
5539 else
5541 cmpltr = -1;
5543 **s = c;
5547 return cmpltr;
5550 /* Parse a non-negated addition completer returning the number
5551 (for encoding in instrutions) of the given completer.
5553 ISBRANCH specifies whether or not this is parsing a condition
5554 completer for a branch (vs a nullification completer for a
5555 computational instruction. */
5557 static int
5558 pa_parse_nonneg_add_cmpltr (s, isbranch)
5559 char **s;
5560 int isbranch;
5562 int cmpltr;
5563 char *name = *s + 1;
5564 char c;
5565 char *save_s = *s;
5567 cmpltr = 0;
5568 if (**s == ',')
5570 *s += 1;
5571 while (**s != ',' && **s != ' ' && **s != '\t')
5572 *s += 1;
5573 c = **s;
5574 **s = 0x00;
5575 if (strcmp (name, "=") == 0)
5577 cmpltr = 1;
5579 else if (strcmp (name, "<") == 0)
5581 cmpltr = 2;
5583 else if (strcmp (name, "<=") == 0)
5585 cmpltr = 3;
5587 else if (strcasecmp (name, "nuv") == 0)
5589 cmpltr = 4;
5591 else if (strcasecmp (name, "znv") == 0)
5593 cmpltr = 5;
5595 else if (strcasecmp (name, "sv") == 0)
5597 cmpltr = 6;
5599 else if (strcasecmp (name, "od") == 0)
5601 cmpltr = 7;
5603 /* If we have something like addb,n then there is no condition
5604 completer. */
5605 else if (strcasecmp (name, "n") == 0 && isbranch)
5607 cmpltr = 0;
5609 else
5611 cmpltr = -1;
5613 **s = c;
5616 /* Reset pointers if this was really a ,n for a branch instruction. */
5617 if (cmpltr == 0 && *name == 'n' && isbranch)
5618 *s = save_s;
5620 return cmpltr;
5623 /* Parse a negated addition completer returning the number
5624 (for encoding in instrutions) of the given completer.
5626 ISBRANCH specifies whether or not this is parsing a condition
5627 completer for a branch (vs a nullification completer for a
5628 computational instruction). */
5630 static int
5631 pa_parse_neg_add_cmpltr (s, isbranch)
5632 char **s;
5633 int isbranch;
5635 int cmpltr;
5636 char *name = *s + 1;
5637 char c;
5638 char *save_s = *s;
5640 cmpltr = 0;
5641 if (**s == ',')
5643 *s += 1;
5644 while (**s != ',' && **s != ' ' && **s != '\t')
5645 *s += 1;
5646 c = **s;
5647 **s = 0x00;
5648 if (strcasecmp (name, "tr") == 0)
5650 cmpltr = 0;
5652 else if (strcmp (name, "<>") == 0)
5654 cmpltr = 1;
5656 else if (strcmp (name, ">=") == 0)
5658 cmpltr = 2;
5660 else if (strcmp (name, ">") == 0)
5662 cmpltr = 3;
5664 else if (strcasecmp (name, "uv") == 0)
5666 cmpltr = 4;
5668 else if (strcasecmp (name, "vnz") == 0)
5670 cmpltr = 5;
5672 else if (strcasecmp (name, "nsv") == 0)
5674 cmpltr = 6;
5676 else if (strcasecmp (name, "ev") == 0)
5678 cmpltr = 7;
5680 /* If we have something like addb,n then there is no condition
5681 completer. */
5682 else if (strcasecmp (name, "n") == 0 && isbranch)
5684 cmpltr = 0;
5686 else
5688 cmpltr = -1;
5690 **s = c;
5693 /* Reset pointers if this was really a ,n for a branch instruction. */
5694 if (cmpltr == 0 && *name == 'n' && isbranch)
5695 *s = save_s;
5697 return cmpltr;
5700 /* Parse a 64 bit wide mode add and branch completer returning the number (for
5701 encoding in instrutions) of the given completer. */
5703 static int
5704 pa_parse_addb_64_cmpltr (s)
5705 char **s;
5707 int cmpltr;
5708 char *name = *s + 1;
5709 char c;
5710 char *save_s = *s;
5711 int nullify = 0;
5713 cmpltr = 0;
5714 if (**s == ',')
5716 *s += 1;
5717 while (**s != ',' && **s != ' ' && **s != '\t')
5718 *s += 1;
5719 c = **s;
5720 **s = 0x00;
5721 if (strcmp (name, "=") == 0)
5723 cmpltr = 1;
5725 else if (strcmp (name, "<") == 0)
5727 cmpltr = 2;
5729 else if (strcmp (name, "<=") == 0)
5731 cmpltr = 3;
5733 else if (strcasecmp (name, "nuv") == 0)
5735 cmpltr = 4;
5737 else if (strcasecmp (name, "*=") == 0)
5739 cmpltr = 5;
5741 else if (strcasecmp (name, "*<") == 0)
5743 cmpltr = 6;
5745 else if (strcasecmp (name, "*<=") == 0)
5747 cmpltr = 7;
5749 else if (strcmp (name, "tr") == 0)
5751 cmpltr = 8;
5753 else if (strcmp (name, "<>") == 0)
5755 cmpltr = 9;
5757 else if (strcmp (name, ">=") == 0)
5759 cmpltr = 10;
5761 else if (strcmp (name, ">") == 0)
5763 cmpltr = 11;
5765 else if (strcasecmp (name, "uv") == 0)
5767 cmpltr = 12;
5769 else if (strcasecmp (name, "*<>") == 0)
5771 cmpltr = 13;
5773 else if (strcasecmp (name, "*>=") == 0)
5775 cmpltr = 14;
5777 else if (strcasecmp (name, "*>") == 0)
5779 cmpltr = 15;
5781 /* If we have something like addb,n then there is no condition
5782 completer. */
5783 else if (strcasecmp (name, "n") == 0)
5785 cmpltr = 0;
5786 nullify = 1;
5788 else
5790 cmpltr = -1;
5792 **s = c;
5795 /* Reset pointers if this was really a ,n for a branch instruction. */
5796 if (nullify)
5797 *s = save_s;
5799 return cmpltr;
5802 #ifdef OBJ_SOM
5803 /* Handle an alignment directive. Special so that we can update the
5804 alignment of the subspace if necessary. */
5805 static void
5806 pa_align (bytes)
5808 /* We must have a valid space and subspace. */
5809 pa_check_current_space_and_subspace ();
5811 /* Let the generic gas code do most of the work. */
5812 s_align_bytes (bytes);
5814 /* If bytes is a power of 2, then update the current subspace's
5815 alignment if necessary. */
5816 if (log2 (bytes) != -1)
5817 record_alignment (current_subspace->ssd_seg, log2 (bytes));
5819 #endif
5821 /* Handle a .BLOCK type pseudo-op. */
5823 static void
5824 pa_block (z)
5825 int z ATTRIBUTE_UNUSED;
5827 char *p;
5828 long int temp_fill;
5829 unsigned int temp_size;
5830 unsigned int i;
5832 #ifdef OBJ_SOM
5833 /* We must have a valid space and subspace. */
5834 pa_check_current_space_and_subspace ();
5835 #endif
5837 temp_size = get_absolute_expression ();
5839 /* Always fill with zeros, that's what the HP assembler does. */
5840 temp_fill = 0;
5842 p = frag_var (rs_fill, (int) temp_size, (int) temp_size,
5843 (relax_substateT) 0, (symbolS *) 0, (offsetT) 1, NULL);
5844 memset (p, 0, temp_size);
5846 /* Convert 2 bytes at a time. */
5848 for (i = 0; i < temp_size; i += 2)
5850 md_number_to_chars (p + i,
5851 (valueT) temp_fill,
5852 (int) ((temp_size - i) > 2 ? 2 : (temp_size - i)));
5855 pa_undefine_label ();
5856 demand_empty_rest_of_line ();
5859 /* Handle a .begin_brtab and .end_brtab pseudo-op. */
5861 static void
5862 pa_brtab (begin)
5863 int begin ATTRIBUTE_UNUSED;
5866 #ifdef OBJ_SOM
5867 /* The BRTAB relocations are only availble in SOM (to denote
5868 the beginning and end of branch tables). */
5869 char *where = frag_more (0);
5871 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
5872 NULL, (offsetT) 0, NULL,
5873 0, begin ? R_HPPA_BEGIN_BRTAB : R_HPPA_END_BRTAB,
5874 e_fsel, 0, 0, NULL);
5875 #endif
5877 demand_empty_rest_of_line ();
5880 /* Handle a .begin_try and .end_try pseudo-op. */
5882 static void
5883 pa_try (begin)
5884 int begin ATTRIBUTE_UNUSED;
5886 #ifdef OBJ_SOM
5887 expressionS exp;
5888 char *where = frag_more (0);
5890 if (! begin)
5891 expression (&exp);
5893 /* The TRY relocations are only availble in SOM (to denote
5894 the beginning and end of exception handling regions). */
5896 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
5897 NULL, (offsetT) 0, begin ? NULL : &exp,
5898 0, begin ? R_HPPA_BEGIN_TRY : R_HPPA_END_TRY,
5899 e_fsel, 0, 0, NULL);
5900 #endif
5902 demand_empty_rest_of_line ();
5905 /* Handle a .CALL pseudo-op. This involves storing away information
5906 about where arguments are to be found so the linker can detect
5907 (and correct) argument location mismatches between caller and callee. */
5909 static void
5910 pa_call (unused)
5911 int unused ATTRIBUTE_UNUSED;
5913 #ifdef OBJ_SOM
5914 /* We must have a valid space and subspace. */
5915 pa_check_current_space_and_subspace ();
5916 #endif
5918 pa_call_args (&last_call_desc);
5919 demand_empty_rest_of_line ();
5922 /* Do the dirty work of building a call descriptor which describes
5923 where the caller placed arguments to a function call. */
5925 static void
5926 pa_call_args (call_desc)
5927 struct call_desc *call_desc;
5929 char *name, c, *p;
5930 unsigned int temp, arg_reloc;
5932 while (!is_end_of_statement ())
5934 name = input_line_pointer;
5935 c = get_symbol_end ();
5936 /* Process a source argument. */
5937 if ((strncasecmp (name, "argw", 4) == 0))
5939 temp = atoi (name + 4);
5940 p = input_line_pointer;
5941 *p = c;
5942 input_line_pointer++;
5943 name = input_line_pointer;
5944 c = get_symbol_end ();
5945 arg_reloc = pa_build_arg_reloc (name);
5946 call_desc->arg_reloc |= pa_align_arg_reloc (temp, arg_reloc);
5948 /* Process a return value. */
5949 else if ((strncasecmp (name, "rtnval", 6) == 0))
5951 p = input_line_pointer;
5952 *p = c;
5953 input_line_pointer++;
5954 name = input_line_pointer;
5955 c = get_symbol_end ();
5956 arg_reloc = pa_build_arg_reloc (name);
5957 call_desc->arg_reloc |= (arg_reloc & 0x3);
5959 else
5961 as_bad (_("Invalid .CALL argument: %s"), name);
5963 p = input_line_pointer;
5964 *p = c;
5965 if (!is_end_of_statement ())
5966 input_line_pointer++;
5970 /* Return TRUE if FRAG1 and FRAG2 are the same. */
5972 static int
5973 is_same_frag (frag1, frag2)
5974 fragS *frag1;
5975 fragS *frag2;
5978 if (frag1 == NULL)
5979 return (FALSE);
5980 else if (frag2 == NULL)
5981 return (FALSE);
5982 else if (frag1 == frag2)
5983 return (TRUE);
5984 else if (frag2->fr_type == rs_fill && frag2->fr_fix == 0)
5985 return (is_same_frag (frag1, frag2->fr_next));
5986 else
5987 return (FALSE);
5990 #ifdef OBJ_ELF
5991 /* Build an entry in the UNWIND subspace from the given function
5992 attributes in CALL_INFO. This is not needed for SOM as using
5993 R_ENTRY and R_EXIT relocations allow the linker to handle building
5994 of the unwind spaces. */
5996 static void
5997 pa_build_unwind_subspace (call_info)
5998 struct call_info *call_info;
6000 char *unwind;
6001 asection *seg, *save_seg;
6002 subsegT save_subseg;
6003 unsigned int i;
6004 int reloc;
6005 char c, *p;
6007 if (now_seg != text_section)
6008 return;
6010 if (bfd_get_arch_info (stdoutput)->bits_per_address == 32)
6011 reloc = R_PARISC_DIR32;
6012 else
6013 reloc = R_PARISC_SEGREL32;
6015 save_seg = now_seg;
6016 save_subseg = now_subseg;
6017 /* Get into the right seg/subseg. This may involve creating
6018 the seg the first time through. Make sure to have the
6019 old seg/subseg so that we can reset things when we are done. */
6020 seg = bfd_get_section_by_name (stdoutput, UNWIND_SECTION_NAME);
6021 if (seg == ASEC_NULL)
6023 seg = subseg_new (UNWIND_SECTION_NAME, 0);
6024 bfd_set_section_flags (stdoutput, seg,
6025 SEC_READONLY | SEC_HAS_CONTENTS
6026 | SEC_LOAD | SEC_RELOC | SEC_ALLOC | SEC_DATA);
6027 bfd_set_section_alignment (stdoutput, seg, 2);
6030 subseg_set (seg, 0);
6033 /* Get some space to hold relocation information for the unwind
6034 descriptor. */
6035 p = frag_more (4);
6036 md_number_to_chars (p, 0, 4);
6038 /* Relocation info. for start offset of the function. */
6039 fix_new_hppa (frag_now, p - frag_now->fr_literal, 4,
6040 call_info->start_symbol, (offsetT) 0,
6041 (expressionS *) NULL, 0, reloc,
6042 e_fsel, 32, 0, NULL);
6044 p = frag_more (4);
6045 md_number_to_chars (p, 0, 4);
6047 /* Relocation info. for end offset of the function.
6049 Because we allow reductions of 32bit relocations for ELF, this will be
6050 reduced to section_sym + offset which avoids putting the temporary
6051 symbol into the symbol table. It (should) end up giving the same
6052 value as call_info->start_symbol + function size once the linker is
6053 finished with its work. */
6055 fix_new_hppa (frag_now, p - frag_now->fr_literal, 4,
6056 call_info->end_symbol, (offsetT) 0,
6057 (expressionS *) NULL, 0, reloc,
6058 e_fsel, 32, 0, NULL);
6060 /* Dump it. */
6061 unwind = (char *) &call_info->ci_unwind;
6062 for (i = 8; i < sizeof (struct unwind_table); i++)
6064 c = *(unwind + i);
6066 FRAG_APPEND_1_CHAR (c);
6070 /* Return back to the original segment/subsegment. */
6071 subseg_set (save_seg, save_subseg);
6073 #endif
6075 /* Process a .CALLINFO pseudo-op. This information is used later
6076 to build unwind descriptors and maybe one day to support
6077 .ENTER and .LEAVE. */
6079 static void
6080 pa_callinfo (unused)
6081 int unused ATTRIBUTE_UNUSED;
6083 char *name, c, *p;
6084 int temp;
6086 #ifdef OBJ_SOM
6087 /* We must have a valid space and subspace. */
6088 pa_check_current_space_and_subspace ();
6089 #endif
6091 /* .CALLINFO must appear within a procedure definition. */
6092 if (!within_procedure)
6093 as_bad (_(".callinfo is not within a procedure definition"));
6095 /* Mark the fact that we found the .CALLINFO for the
6096 current procedure. */
6097 callinfo_found = TRUE;
6099 /* Iterate over the .CALLINFO arguments. */
6100 while (!is_end_of_statement ())
6102 name = input_line_pointer;
6103 c = get_symbol_end ();
6104 /* Frame size specification. */
6105 if ((strncasecmp (name, "frame", 5) == 0))
6107 p = input_line_pointer;
6108 *p = c;
6109 input_line_pointer++;
6110 temp = get_absolute_expression ();
6111 if ((temp & 0x3) != 0)
6113 as_bad (_("FRAME parameter must be a multiple of 8: %d\n"), temp);
6114 temp = 0;
6117 /* callinfo is in bytes and unwind_desc is in 8 byte units. */
6118 last_call_info->ci_unwind.descriptor.frame_size = temp / 8;
6121 /* Entry register (GR, GR and SR) specifications. */
6122 else if ((strncasecmp (name, "entry_gr", 8) == 0))
6124 p = input_line_pointer;
6125 *p = c;
6126 input_line_pointer++;
6127 temp = get_absolute_expression ();
6128 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
6129 even though %r19 is caller saved. I think this is a bug in
6130 the HP assembler, and we are not going to emulate it. */
6131 if (temp < 3 || temp > 18)
6132 as_bad (_("Value for ENTRY_GR must be in the range 3..18\n"));
6133 last_call_info->ci_unwind.descriptor.entry_gr = temp - 2;
6135 else if ((strncasecmp (name, "entry_fr", 8) == 0))
6137 p = input_line_pointer;
6138 *p = c;
6139 input_line_pointer++;
6140 temp = get_absolute_expression ();
6141 /* Similarly the HP assembler takes 31 as the high bound even
6142 though %fr21 is the last callee saved floating point register. */
6143 if (temp < 12 || temp > 21)
6144 as_bad (_("Value for ENTRY_FR must be in the range 12..21\n"));
6145 last_call_info->ci_unwind.descriptor.entry_fr = temp - 11;
6147 else if ((strncasecmp (name, "entry_sr", 8) == 0))
6149 p = input_line_pointer;
6150 *p = c;
6151 input_line_pointer++;
6152 temp = get_absolute_expression ();
6153 if (temp != 3)
6154 as_bad (_("Value for ENTRY_SR must be 3\n"));
6156 /* Note whether or not this function performs any calls. */
6157 else if ((strncasecmp (name, "calls", 5) == 0) ||
6158 (strncasecmp (name, "caller", 6) == 0))
6160 p = input_line_pointer;
6161 *p = c;
6163 else if ((strncasecmp (name, "no_calls", 8) == 0))
6165 p = input_line_pointer;
6166 *p = c;
6168 /* Should RP be saved into the stack. */
6169 else if ((strncasecmp (name, "save_rp", 7) == 0))
6171 p = input_line_pointer;
6172 *p = c;
6173 last_call_info->ci_unwind.descriptor.save_rp = 1;
6175 /* Likewise for SP. */
6176 else if ((strncasecmp (name, "save_sp", 7) == 0))
6178 p = input_line_pointer;
6179 *p = c;
6180 last_call_info->ci_unwind.descriptor.save_sp = 1;
6182 /* Is this an unwindable procedure. If so mark it so
6183 in the unwind descriptor. */
6184 else if ((strncasecmp (name, "no_unwind", 9) == 0))
6186 p = input_line_pointer;
6187 *p = c;
6188 last_call_info->ci_unwind.descriptor.cannot_unwind = 1;
6190 /* Is this an interrupt routine. If so mark it in the
6191 unwind descriptor. */
6192 else if ((strncasecmp (name, "hpux_int", 7) == 0))
6194 p = input_line_pointer;
6195 *p = c;
6196 last_call_info->ci_unwind.descriptor.hpux_interrupt_marker = 1;
6198 /* Is this a millicode routine. "millicode" isn't in my
6199 assembler manual, but my copy is old. The HP assembler
6200 accepts it, and there's a place in the unwind descriptor
6201 to drop the information, so we'll accept it too. */
6202 else if ((strncasecmp (name, "millicode", 9) == 0))
6204 p = input_line_pointer;
6205 *p = c;
6206 last_call_info->ci_unwind.descriptor.millicode = 1;
6208 else
6210 as_bad (_("Invalid .CALLINFO argument: %s"), name);
6211 *input_line_pointer = c;
6213 if (!is_end_of_statement ())
6214 input_line_pointer++;
6217 demand_empty_rest_of_line ();
6220 /* Switch into the code subspace. */
6222 static void
6223 pa_code (unused)
6224 int unused ATTRIBUTE_UNUSED;
6226 #ifdef OBJ_SOM
6227 current_space = is_defined_space ("$TEXT$");
6228 current_subspace
6229 = pa_subsegment_to_subspace (current_space->sd_seg, 0);
6230 #endif
6231 s_text (0);
6232 pa_undefine_label ();
6235 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
6236 the .comm pseudo-op has the following symtax:
6238 <label> .comm <length>
6240 where <label> is optional and is a symbol whose address will be the start of
6241 a block of memory <length> bytes long. <length> must be an absolute
6242 expression. <length> bytes will be allocated in the current space
6243 and subspace.
6245 Also note the label may not even be on the same line as the .comm.
6247 This difference in syntax means the colon function will be called
6248 on the symbol before we arrive in pa_comm. colon will set a number
6249 of attributes of the symbol that need to be fixed here. In particular
6250 the value, section pointer, fragment pointer, flags, etc. What
6251 a pain.
6253 This also makes error detection all but impossible. */
6255 static void
6256 pa_comm (unused)
6257 int unused ATTRIBUTE_UNUSED;
6259 unsigned int size;
6260 symbolS *symbol;
6261 label_symbol_struct *label_symbol = pa_get_label ();
6263 if (label_symbol)
6264 symbol = label_symbol->lss_label;
6265 else
6266 symbol = NULL;
6268 SKIP_WHITESPACE ();
6269 size = get_absolute_expression ();
6271 if (symbol)
6273 S_SET_VALUE (symbol, size);
6274 S_SET_SEGMENT (symbol, bfd_und_section_ptr);
6275 S_SET_EXTERNAL (symbol);
6277 /* colon() has already set the frag to the current location in the
6278 current subspace; we need to reset the fragment to the zero address
6279 fragment. We also need to reset the segment pointer. */
6280 symbol_set_frag (symbol, &zero_address_frag);
6282 demand_empty_rest_of_line ();
6285 /* Process a .END pseudo-op. */
6287 static void
6288 pa_end (unused)
6289 int unused ATTRIBUTE_UNUSED;
6291 demand_empty_rest_of_line ();
6294 /* Process a .ENTER pseudo-op. This is not supported. */
6295 static void
6296 pa_enter (unused)
6297 int unused ATTRIBUTE_UNUSED;
6299 #ifdef OBJ_SOM
6300 /* We must have a valid space and subspace. */
6301 pa_check_current_space_and_subspace ();
6302 #endif
6304 as_bad (_("The .ENTER pseudo-op is not supported"));
6305 demand_empty_rest_of_line ();
6308 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
6309 procesure. */
6310 static void
6311 pa_entry (unused)
6312 int unused ATTRIBUTE_UNUSED;
6314 #ifdef OBJ_SOM
6315 /* We must have a valid space and subspace. */
6316 pa_check_current_space_and_subspace ();
6317 #endif
6319 if (!within_procedure)
6320 as_bad (_("Misplaced .entry. Ignored."));
6321 else
6323 if (!callinfo_found)
6324 as_bad (_("Missing .callinfo."));
6326 demand_empty_rest_of_line ();
6327 within_entry_exit = TRUE;
6329 #ifdef OBJ_SOM
6330 /* SOM defers building of unwind descriptors until the link phase.
6331 The assembler is responsible for creating an R_ENTRY relocation
6332 to mark the beginning of a region and hold the unwind bits, and
6333 for creating an R_EXIT relocation to mark the end of the region.
6335 FIXME. ELF should be using the same conventions! The problem
6336 is an unwind requires too much relocation space. Hmmm. Maybe
6337 if we split the unwind bits up between the relocations which
6338 denote the entry and exit points. */
6339 if (last_call_info->start_symbol != NULL)
6341 char *where = frag_more (0);
6343 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
6344 NULL, (offsetT) 0, NULL,
6345 0, R_HPPA_ENTRY, e_fsel, 0, 0,
6346 (int *) &last_call_info->ci_unwind.descriptor);
6348 #endif
6351 /* Handle a .EQU pseudo-op. */
6353 static void
6354 pa_equ (reg)
6355 int reg;
6357 label_symbol_struct *label_symbol = pa_get_label ();
6358 symbolS *symbol;
6360 if (label_symbol)
6362 symbol = label_symbol->lss_label;
6363 if (reg)
6364 S_SET_VALUE (symbol, pa_parse_number (&input_line_pointer, 0));
6365 else
6366 S_SET_VALUE (symbol, (unsigned int) get_absolute_expression ());
6367 S_SET_SEGMENT (symbol, bfd_abs_section_ptr);
6369 else
6371 if (reg)
6372 as_bad (_(".REG must use a label"));
6373 else
6374 as_bad (_(".EQU must use a label"));
6377 pa_undefine_label ();
6378 demand_empty_rest_of_line ();
6381 /* Helper function. Does processing for the end of a function. This
6382 usually involves creating some relocations or building special
6383 symbols to mark the end of the function. */
6385 static void
6386 process_exit ()
6388 char *where;
6390 where = frag_more (0);
6392 #ifdef OBJ_ELF
6393 /* Mark the end of the function, stuff away the location of the frag
6394 for the end of the function, and finally call pa_build_unwind_subspace
6395 to add an entry in the unwind table. */
6396 hppa_elf_mark_end_of_function ();
6397 pa_build_unwind_subspace (last_call_info);
6398 #else
6399 /* SOM defers building of unwind descriptors until the link phase.
6400 The assembler is responsible for creating an R_ENTRY relocation
6401 to mark the beginning of a region and hold the unwind bits, and
6402 for creating an R_EXIT relocation to mark the end of the region.
6404 FIXME. ELF should be using the same conventions! The problem
6405 is an unwind requires too much relocation space. Hmmm. Maybe
6406 if we split the unwind bits up between the relocations which
6407 denote the entry and exit points. */
6408 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
6409 NULL, (offsetT) 0,
6410 NULL, 0, R_HPPA_EXIT, e_fsel, 0, 0,
6411 (int *) &last_call_info->ci_unwind.descriptor + 1);
6412 #endif
6415 /* Process a .EXIT pseudo-op. */
6417 static void
6418 pa_exit (unused)
6419 int unused ATTRIBUTE_UNUSED;
6421 #ifdef OBJ_SOM
6422 /* We must have a valid space and subspace. */
6423 pa_check_current_space_and_subspace ();
6424 #endif
6426 if (!within_procedure)
6427 as_bad (_(".EXIT must appear within a procedure"));
6428 else
6430 if (!callinfo_found)
6431 as_bad (_("Missing .callinfo"));
6432 else
6434 if (!within_entry_exit)
6435 as_bad (_("No .ENTRY for this .EXIT"));
6436 else
6438 within_entry_exit = FALSE;
6439 process_exit ();
6443 demand_empty_rest_of_line ();
6446 /* Process a .EXPORT directive. This makes functions external
6447 and provides information such as argument relocation entries
6448 to callers. */
6450 static void
6451 pa_export (unused)
6452 int unused ATTRIBUTE_UNUSED;
6454 char *name, c, *p;
6455 symbolS *symbol;
6457 name = input_line_pointer;
6458 c = get_symbol_end ();
6459 /* Make sure the given symbol exists. */
6460 if ((symbol = symbol_find_or_make (name)) == NULL)
6462 as_bad (_("Cannot define export symbol: %s\n"), name);
6463 p = input_line_pointer;
6464 *p = c;
6465 input_line_pointer++;
6467 else
6469 /* OK. Set the external bits and process argument relocations. */
6470 S_SET_EXTERNAL (symbol);
6471 p = input_line_pointer;
6472 *p = c;
6473 if (!is_end_of_statement ())
6475 input_line_pointer++;
6476 pa_type_args (symbol, 1);
6480 demand_empty_rest_of_line ();
6483 /* Helper function to process arguments to a .EXPORT pseudo-op. */
6485 static void
6486 pa_type_args (symbolP, is_export)
6487 symbolS *symbolP;
6488 int is_export;
6490 char *name, c, *p;
6491 unsigned int temp, arg_reloc;
6492 pa_symbol_type type = SYMBOL_TYPE_UNKNOWN;
6493 #ifdef OBJ_SOM
6494 obj_symbol_type *symbol = (obj_symbol_type *) symbol_get_bfdsym (symbolP);
6495 #endif
6497 if (strncasecmp (input_line_pointer, "absolute", 8) == 0)
6500 input_line_pointer += 8;
6501 symbol_get_bfdsym (symbolP)->flags &= ~BSF_FUNCTION;
6502 S_SET_SEGMENT (symbolP, bfd_abs_section_ptr);
6503 type = SYMBOL_TYPE_ABSOLUTE;
6505 else if (strncasecmp (input_line_pointer, "code", 4) == 0)
6507 input_line_pointer += 4;
6508 /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM,
6509 instead one should be IMPORTing/EXPORTing ENTRY types.
6511 Complain if one tries to EXPORT a CODE type since that's never
6512 done. Both GCC and HP C still try to IMPORT CODE types, so
6513 silently fix them to be ENTRY types. */
6514 if (S_IS_FUNCTION (symbolP))
6516 if (is_export)
6517 as_tsktsk (_("Using ENTRY rather than CODE in export directive for %s"),
6518 S_GET_NAME (symbolP));
6520 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
6521 type = SYMBOL_TYPE_ENTRY;
6523 else
6525 symbol_get_bfdsym (symbolP)->flags &= ~BSF_FUNCTION;
6526 type = SYMBOL_TYPE_CODE;
6529 else if (strncasecmp (input_line_pointer, "data", 4) == 0)
6531 input_line_pointer += 4;
6532 symbol_get_bfdsym (symbolP)->flags &= ~BSF_FUNCTION;
6533 symbol_get_bfdsym (symbolP)->flags |= BSF_OBJECT;
6534 type = SYMBOL_TYPE_DATA;
6536 else if ((strncasecmp (input_line_pointer, "entry", 5) == 0))
6538 input_line_pointer += 5;
6539 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
6540 type = SYMBOL_TYPE_ENTRY;
6542 else if (strncasecmp (input_line_pointer, "millicode", 9) == 0)
6544 input_line_pointer += 9;
6545 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
6546 type = SYMBOL_TYPE_MILLICODE;
6548 else if (strncasecmp (input_line_pointer, "plabel", 6) == 0)
6550 input_line_pointer += 6;
6551 symbol_get_bfdsym (symbolP)->flags &= ~BSF_FUNCTION;
6552 type = SYMBOL_TYPE_PLABEL;
6554 else if (strncasecmp (input_line_pointer, "pri_prog", 8) == 0)
6556 input_line_pointer += 8;
6557 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
6558 type = SYMBOL_TYPE_PRI_PROG;
6560 else if (strncasecmp (input_line_pointer, "sec_prog", 8) == 0)
6562 input_line_pointer += 8;
6563 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
6564 type = SYMBOL_TYPE_SEC_PROG;
6567 /* SOM requires much more information about symbol types
6568 than BFD understands. This is how we get this information
6569 to the SOM BFD backend. */
6570 #ifdef obj_set_symbol_type
6571 obj_set_symbol_type (symbol_get_bfdsym (symbolP), (int) type);
6572 #endif
6574 /* Now that the type of the exported symbol has been handled,
6575 handle any argument relocation information. */
6576 while (!is_end_of_statement ())
6578 if (*input_line_pointer == ',')
6579 input_line_pointer++;
6580 name = input_line_pointer;
6581 c = get_symbol_end ();
6582 /* Argument sources. */
6583 if ((strncasecmp (name, "argw", 4) == 0))
6585 p = input_line_pointer;
6586 *p = c;
6587 input_line_pointer++;
6588 temp = atoi (name + 4);
6589 name = input_line_pointer;
6590 c = get_symbol_end ();
6591 arg_reloc = pa_align_arg_reloc (temp, pa_build_arg_reloc (name));
6592 #ifdef OBJ_SOM
6593 symbol->tc_data.ap.hppa_arg_reloc |= arg_reloc;
6594 #endif
6595 *input_line_pointer = c;
6597 /* The return value. */
6598 else if ((strncasecmp (name, "rtnval", 6)) == 0)
6600 p = input_line_pointer;
6601 *p = c;
6602 input_line_pointer++;
6603 name = input_line_pointer;
6604 c = get_symbol_end ();
6605 arg_reloc = pa_build_arg_reloc (name);
6606 #ifdef OBJ_SOM
6607 symbol->tc_data.ap.hppa_arg_reloc |= arg_reloc;
6608 #endif
6609 *input_line_pointer = c;
6611 /* Privelege level. */
6612 else if ((strncasecmp (name, "priv_lev", 8)) == 0)
6614 p = input_line_pointer;
6615 *p = c;
6616 input_line_pointer++;
6617 temp = atoi (input_line_pointer);
6618 #ifdef OBJ_SOM
6619 symbol->tc_data.ap.hppa_priv_level = temp;
6620 #endif
6621 c = get_symbol_end ();
6622 *input_line_pointer = c;
6624 else
6626 as_bad (_("Undefined .EXPORT/.IMPORT argument (ignored): %s"), name);
6627 p = input_line_pointer;
6628 *p = c;
6630 if (!is_end_of_statement ())
6631 input_line_pointer++;
6635 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
6636 assembly file must either be defined in the assembly file, or
6637 explicitly IMPORTED from another. */
6639 static void
6640 pa_import (unused)
6641 int unused ATTRIBUTE_UNUSED;
6643 char *name, c, *p;
6644 symbolS *symbol;
6646 name = input_line_pointer;
6647 c = get_symbol_end ();
6649 symbol = symbol_find (name);
6650 /* Ugh. We might be importing a symbol defined earlier in the file,
6651 in which case all the code below will really screw things up
6652 (set the wrong segment, symbol flags & type, etc). */
6653 if (symbol == NULL || !S_IS_DEFINED (symbol))
6655 symbol = symbol_find_or_make (name);
6656 p = input_line_pointer;
6657 *p = c;
6659 if (!is_end_of_statement ())
6661 input_line_pointer++;
6662 pa_type_args (symbol, 0);
6664 else
6666 /* Sigh. To be compatable with the HP assembler and to help
6667 poorly written assembly code, we assign a type based on
6668 the the current segment. Note only BSF_FUNCTION really
6669 matters, we do not need to set the full SYMBOL_TYPE_* info. */
6670 if (now_seg == text_section)
6671 symbol_get_bfdsym (symbol)->flags |= BSF_FUNCTION;
6673 /* If the section is undefined, then the symbol is undefined
6674 Since this is an import, leave the section undefined. */
6675 S_SET_SEGMENT (symbol, bfd_und_section_ptr);
6678 else
6680 /* The symbol was already defined. Just eat everything up to
6681 the end of the current statement. */
6682 while (!is_end_of_statement ())
6683 input_line_pointer++;
6686 demand_empty_rest_of_line ();
6689 /* Handle a .LABEL pseudo-op. */
6691 static void
6692 pa_label (unused)
6693 int unused ATTRIBUTE_UNUSED;
6695 char *name, c, *p;
6697 name = input_line_pointer;
6698 c = get_symbol_end ();
6700 if (strlen (name) > 0)
6702 colon (name);
6703 p = input_line_pointer;
6704 *p = c;
6706 else
6708 as_warn (_("Missing label name on .LABEL"));
6711 if (!is_end_of_statement ())
6713 as_warn (_("extra .LABEL arguments ignored."));
6714 ignore_rest_of_line ();
6716 demand_empty_rest_of_line ();
6719 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
6721 static void
6722 pa_leave (unused)
6723 int unused ATTRIBUTE_UNUSED;
6725 #ifdef OBJ_SOM
6726 /* We must have a valid space and subspace. */
6727 pa_check_current_space_and_subspace ();
6728 #endif
6730 as_bad (_("The .LEAVE pseudo-op is not supported"));
6731 demand_empty_rest_of_line ();
6734 /* Handle a .LEVEL pseudo-op. */
6736 static void
6737 pa_level (unused)
6738 int unused ATTRIBUTE_UNUSED;
6740 char *level;
6742 level = input_line_pointer;
6743 if (strncmp (level, "1.0", 3) == 0)
6745 input_line_pointer += 3;
6746 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 10))
6747 as_warn (_("could not set architecture and machine"));
6749 else if (strncmp (level, "1.1", 3) == 0)
6751 input_line_pointer += 3;
6752 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 11))
6753 as_warn (_("could not set architecture and machine"));
6755 else if (strncmp (level, "2.0w", 4) == 0)
6757 input_line_pointer += 4;
6758 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 25))
6759 as_warn (_("could not set architecture and machine"));
6761 else if (strncmp (level, "2.0", 3) == 0)
6763 input_line_pointer += 3;
6764 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 20))
6765 as_warn (_("could not set architecture and machine"));
6767 else
6769 as_bad (_("Unrecognized .LEVEL argument\n"));
6770 ignore_rest_of_line ();
6772 demand_empty_rest_of_line ();
6775 /* Handle a .ORIGIN pseudo-op. */
6777 static void
6778 pa_origin (unused)
6779 int unused ATTRIBUTE_UNUSED;
6781 #ifdef OBJ_SOM
6782 /* We must have a valid space and subspace. */
6783 pa_check_current_space_and_subspace ();
6784 #endif
6786 s_org (0);
6787 pa_undefine_label ();
6790 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
6791 is for static functions. FIXME. Should share more code with .EXPORT. */
6793 static void
6794 pa_param (unused)
6795 int unused ATTRIBUTE_UNUSED;
6797 char *name, c, *p;
6798 symbolS *symbol;
6800 name = input_line_pointer;
6801 c = get_symbol_end ();
6803 if ((symbol = symbol_find_or_make (name)) == NULL)
6805 as_bad (_("Cannot define static symbol: %s\n"), name);
6806 p = input_line_pointer;
6807 *p = c;
6808 input_line_pointer++;
6810 else
6812 S_CLEAR_EXTERNAL (symbol);
6813 p = input_line_pointer;
6814 *p = c;
6815 if (!is_end_of_statement ())
6817 input_line_pointer++;
6818 pa_type_args (symbol, 0);
6822 demand_empty_rest_of_line ();
6825 /* Handle a .PROC pseudo-op. It is used to mark the beginning
6826 of a procedure from a syntatical point of view. */
6828 static void
6829 pa_proc (unused)
6830 int unused ATTRIBUTE_UNUSED;
6832 struct call_info *call_info;
6834 #ifdef OBJ_SOM
6835 /* We must have a valid space and subspace. */
6836 pa_check_current_space_and_subspace ();
6837 #endif
6839 if (within_procedure)
6840 as_fatal (_("Nested procedures"));
6842 /* Reset global variables for new procedure. */
6843 callinfo_found = FALSE;
6844 within_procedure = TRUE;
6846 /* Create another call_info structure. */
6847 call_info = (struct call_info *) xmalloc (sizeof (struct call_info));
6849 if (!call_info)
6850 as_fatal (_("Cannot allocate unwind descriptor\n"));
6852 memset (call_info, 0, sizeof (struct call_info));
6854 call_info->ci_next = NULL;
6856 if (call_info_root == NULL)
6858 call_info_root = call_info;
6859 last_call_info = call_info;
6861 else
6863 last_call_info->ci_next = call_info;
6864 last_call_info = call_info;
6867 /* set up defaults on call_info structure */
6869 call_info->ci_unwind.descriptor.cannot_unwind = 0;
6870 call_info->ci_unwind.descriptor.region_desc = 1;
6871 call_info->ci_unwind.descriptor.hpux_interrupt_marker = 0;
6873 /* If we got a .PROC pseudo-op, we know that the function is defined
6874 locally. Make sure it gets into the symbol table. */
6876 label_symbol_struct *label_symbol = pa_get_label ();
6878 if (label_symbol)
6880 if (label_symbol->lss_label)
6882 last_call_info->start_symbol = label_symbol->lss_label;
6883 symbol_get_bfdsym (label_symbol->lss_label)->flags |= BSF_FUNCTION;
6885 else
6886 as_bad (_("Missing function name for .PROC (corrupted label chain)"));
6888 else
6889 last_call_info->start_symbol = NULL;
6892 demand_empty_rest_of_line ();
6895 /* Process the syntatical end of a procedure. Make sure all the
6896 appropriate pseudo-ops were found within the procedure. */
6898 static void
6899 pa_procend (unused)
6900 int unused ATTRIBUTE_UNUSED;
6903 #ifdef OBJ_SOM
6904 /* We must have a valid space and subspace. */
6905 pa_check_current_space_and_subspace ();
6906 #endif
6908 /* If we are within a procedure definition, make sure we've
6909 defined a label for the procedure; handle case where the
6910 label was defined after the .PROC directive.
6912 Note there's not need to diddle with the segment or fragment
6913 for the label symbol in this case. We have already switched
6914 into the new $CODE$ subspace at this point. */
6915 if (within_procedure && last_call_info->start_symbol == NULL)
6917 label_symbol_struct *label_symbol = pa_get_label ();
6919 if (label_symbol)
6921 if (label_symbol->lss_label)
6923 last_call_info->start_symbol = label_symbol->lss_label;
6924 symbol_get_bfdsym (label_symbol->lss_label)->flags
6925 |= BSF_FUNCTION;
6926 #ifdef OBJ_SOM
6927 /* Also handle allocation of a fixup to hold the unwind
6928 information when the label appears after the proc/procend. */
6929 if (within_entry_exit)
6931 char *where = frag_more (0);
6933 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
6934 NULL, (offsetT) 0, NULL,
6935 0, R_HPPA_ENTRY, e_fsel, 0, 0,
6936 (int *) &last_call_info->ci_unwind.descriptor);
6938 #endif
6940 else
6941 as_bad (_("Missing function name for .PROC (corrupted label chain)"));
6943 else
6944 as_bad (_("Missing function name for .PROC"));
6947 if (!within_procedure)
6948 as_bad (_("misplaced .procend"));
6950 if (!callinfo_found)
6951 as_bad (_("Missing .callinfo for this procedure"));
6953 if (within_entry_exit)
6954 as_bad (_("Missing .EXIT for a .ENTRY"));
6956 #ifdef OBJ_ELF
6957 /* ELF needs to mark the end of each function so that it can compute
6958 the size of the function (apparently its needed in the symbol table). */
6959 hppa_elf_mark_end_of_function ();
6960 #endif
6962 within_procedure = FALSE;
6963 demand_empty_rest_of_line ();
6964 pa_undefine_label ();
6968 #ifdef OBJ_SOM
6969 /* If VALUE is an exact power of two between zero and 2^31, then
6970 return log2 (VALUE). Else return -1. */
6972 static int
6973 log2 (value)
6974 int value;
6976 int shift = 0;
6978 while ((1 << shift) != value && shift < 32)
6979 shift++;
6981 if (shift >= 32)
6982 return -1;
6983 else
6984 return shift;
6987 /* Check to make sure we have a valid space and subspace. */
6989 static void
6990 pa_check_current_space_and_subspace ()
6992 if (current_space == NULL)
6993 as_fatal (_("Not in a space.\n"));
6995 if (current_subspace == NULL)
6996 as_fatal (_("Not in a subspace.\n"));
6999 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
7000 then create a new space entry to hold the information specified
7001 by the parameters to the .SPACE directive. */
7003 static sd_chain_struct *
7004 pa_parse_space_stmt (space_name, create_flag)
7005 char *space_name;
7006 int create_flag;
7008 char *name, *ptemp, c;
7009 char loadable, defined, private, sort;
7010 int spnum, temp;
7011 asection *seg = NULL;
7012 sd_chain_struct *space;
7014 /* load default values */
7015 spnum = 0;
7016 sort = 0;
7017 loadable = TRUE;
7018 defined = TRUE;
7019 private = FALSE;
7020 if (strcmp (space_name, "$TEXT$") == 0)
7022 seg = pa_def_spaces[0].segment;
7023 defined = pa_def_spaces[0].defined;
7024 private = pa_def_spaces[0].private;
7025 sort = pa_def_spaces[0].sort;
7026 spnum = pa_def_spaces[0].spnum;
7028 else if (strcmp (space_name, "$PRIVATE$") == 0)
7030 seg = pa_def_spaces[1].segment;
7031 defined = pa_def_spaces[1].defined;
7032 private = pa_def_spaces[1].private;
7033 sort = pa_def_spaces[1].sort;
7034 spnum = pa_def_spaces[1].spnum;
7037 if (!is_end_of_statement ())
7039 print_errors = FALSE;
7040 ptemp = input_line_pointer + 1;
7041 /* First see if the space was specified as a number rather than
7042 as a name. According to the PA assembly manual the rest of
7043 the line should be ignored. */
7044 temp = pa_parse_number (&ptemp, 0);
7045 if (temp >= 0)
7047 spnum = temp;
7048 input_line_pointer = ptemp;
7050 else
7052 while (!is_end_of_statement ())
7054 input_line_pointer++;
7055 name = input_line_pointer;
7056 c = get_symbol_end ();
7057 if ((strncasecmp (name, "spnum", 5) == 0))
7059 *input_line_pointer = c;
7060 input_line_pointer++;
7061 spnum = get_absolute_expression ();
7063 else if ((strncasecmp (name, "sort", 4) == 0))
7065 *input_line_pointer = c;
7066 input_line_pointer++;
7067 sort = get_absolute_expression ();
7069 else if ((strncasecmp (name, "unloadable", 10) == 0))
7071 *input_line_pointer = c;
7072 loadable = FALSE;
7074 else if ((strncasecmp (name, "notdefined", 10) == 0))
7076 *input_line_pointer = c;
7077 defined = FALSE;
7079 else if ((strncasecmp (name, "private", 7) == 0))
7081 *input_line_pointer = c;
7082 private = TRUE;
7084 else
7086 as_bad (_("Invalid .SPACE argument"));
7087 *input_line_pointer = c;
7088 if (!is_end_of_statement ())
7089 input_line_pointer++;
7093 print_errors = TRUE;
7096 if (create_flag && seg == NULL)
7097 seg = subseg_new (space_name, 0);
7099 /* If create_flag is nonzero, then create the new space with
7100 the attributes computed above. Else set the values in
7101 an already existing space -- this can only happen for
7102 the first occurence of a built-in space. */
7103 if (create_flag)
7104 space = create_new_space (space_name, spnum, loadable, defined,
7105 private, sort, seg, 1);
7106 else
7108 space = is_defined_space (space_name);
7109 SPACE_SPNUM (space) = spnum;
7110 SPACE_DEFINED (space) = defined & 1;
7111 SPACE_USER_DEFINED (space) = 1;
7114 #ifdef obj_set_section_attributes
7115 obj_set_section_attributes (seg, defined, private, sort, spnum);
7116 #endif
7118 return space;
7121 /* Handle a .SPACE pseudo-op; this switches the current space to the
7122 given space, creating the new space if necessary. */
7124 static void
7125 pa_space (unused)
7126 int unused ATTRIBUTE_UNUSED;
7128 char *name, c, *space_name, *save_s;
7129 int temp;
7130 sd_chain_struct *sd_chain;
7132 if (within_procedure)
7134 as_bad (_("Can\'t change spaces within a procedure definition. Ignored"));
7135 ignore_rest_of_line ();
7137 else
7139 /* Check for some of the predefined spaces. FIXME: most of the code
7140 below is repeated several times, can we extract the common parts
7141 and place them into a subroutine or something similar? */
7142 /* FIXME Is this (and the next IF stmt) really right?
7143 What if INPUT_LINE_POINTER points to "$TEXT$FOO"? */
7144 if (strncmp (input_line_pointer, "$TEXT$", 6) == 0)
7146 input_line_pointer += 6;
7147 sd_chain = is_defined_space ("$TEXT$");
7148 if (sd_chain == NULL)
7149 sd_chain = pa_parse_space_stmt ("$TEXT$", 1);
7150 else if (SPACE_USER_DEFINED (sd_chain) == 0)
7151 sd_chain = pa_parse_space_stmt ("$TEXT$", 0);
7153 current_space = sd_chain;
7154 subseg_set (text_section, sd_chain->sd_last_subseg);
7155 current_subspace
7156 = pa_subsegment_to_subspace (text_section,
7157 sd_chain->sd_last_subseg);
7158 demand_empty_rest_of_line ();
7159 return;
7161 if (strncmp (input_line_pointer, "$PRIVATE$", 9) == 0)
7163 input_line_pointer += 9;
7164 sd_chain = is_defined_space ("$PRIVATE$");
7165 if (sd_chain == NULL)
7166 sd_chain = pa_parse_space_stmt ("$PRIVATE$", 1);
7167 else if (SPACE_USER_DEFINED (sd_chain) == 0)
7168 sd_chain = pa_parse_space_stmt ("$PRIVATE$", 0);
7170 current_space = sd_chain;
7171 subseg_set (data_section, sd_chain->sd_last_subseg);
7172 current_subspace
7173 = pa_subsegment_to_subspace (data_section,
7174 sd_chain->sd_last_subseg);
7175 demand_empty_rest_of_line ();
7176 return;
7178 if (!strncasecmp (input_line_pointer,
7179 GDB_DEBUG_SPACE_NAME,
7180 strlen (GDB_DEBUG_SPACE_NAME)))
7182 input_line_pointer += strlen (GDB_DEBUG_SPACE_NAME);
7183 sd_chain = is_defined_space (GDB_DEBUG_SPACE_NAME);
7184 if (sd_chain == NULL)
7185 sd_chain = pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME, 1);
7186 else if (SPACE_USER_DEFINED (sd_chain) == 0)
7187 sd_chain = pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME, 0);
7189 current_space = sd_chain;
7192 asection *gdb_section
7193 = bfd_make_section_old_way (stdoutput, GDB_DEBUG_SPACE_NAME);
7195 subseg_set (gdb_section, sd_chain->sd_last_subseg);
7196 current_subspace
7197 = pa_subsegment_to_subspace (gdb_section,
7198 sd_chain->sd_last_subseg);
7200 demand_empty_rest_of_line ();
7201 return;
7204 /* It could be a space specified by number. */
7205 print_errors = 0;
7206 save_s = input_line_pointer;
7207 if ((temp = pa_parse_number (&input_line_pointer, 0)) >= 0)
7209 if ((sd_chain = pa_find_space_by_number (temp)))
7211 current_space = sd_chain;
7213 subseg_set (sd_chain->sd_seg, sd_chain->sd_last_subseg);
7214 current_subspace
7215 = pa_subsegment_to_subspace (sd_chain->sd_seg,
7216 sd_chain->sd_last_subseg);
7217 demand_empty_rest_of_line ();
7218 return;
7222 /* Not a number, attempt to create a new space. */
7223 print_errors = 1;
7224 input_line_pointer = save_s;
7225 name = input_line_pointer;
7226 c = get_symbol_end ();
7227 space_name = xmalloc (strlen (name) + 1);
7228 strcpy (space_name, name);
7229 *input_line_pointer = c;
7231 sd_chain = pa_parse_space_stmt (space_name, 1);
7232 current_space = sd_chain;
7234 subseg_set (sd_chain->sd_seg, sd_chain->sd_last_subseg);
7235 current_subspace = pa_subsegment_to_subspace (sd_chain->sd_seg,
7236 sd_chain->sd_last_subseg);
7237 demand_empty_rest_of_line ();
7241 /* Switch to a new space. (I think). FIXME. */
7243 static void
7244 pa_spnum (unused)
7245 int unused ATTRIBUTE_UNUSED;
7247 char *name;
7248 char c;
7249 char *p;
7250 sd_chain_struct *space;
7252 name = input_line_pointer;
7253 c = get_symbol_end ();
7254 space = is_defined_space (name);
7255 if (space)
7257 p = frag_more (4);
7258 md_number_to_chars (p, SPACE_SPNUM (space), 4);
7260 else
7261 as_warn (_("Undefined space: '%s' Assuming space number = 0."), name);
7263 *input_line_pointer = c;
7264 demand_empty_rest_of_line ();
7267 /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
7268 given subspace, creating the new subspace if necessary.
7270 FIXME. Should mirror pa_space more closely, in particular how
7271 they're broken up into subroutines. */
7273 static void
7274 pa_subspace (create_new)
7275 int create_new;
7277 char *name, *ss_name, c;
7278 char loadable, code_only, common, dup_common, zero, sort;
7279 int i, access, space_index, alignment, quadrant, applicable, flags;
7280 sd_chain_struct *space;
7281 ssd_chain_struct *ssd;
7282 asection *section;
7284 if (current_space == NULL)
7285 as_fatal (_("Must be in a space before changing or declaring subspaces.\n"));
7287 if (within_procedure)
7289 as_bad (_("Can\'t change subspaces within a procedure definition. Ignored"));
7290 ignore_rest_of_line ();
7292 else
7294 name = input_line_pointer;
7295 c = get_symbol_end ();
7296 ss_name = xmalloc (strlen (name) + 1);
7297 strcpy (ss_name, name);
7298 *input_line_pointer = c;
7300 /* Load default values. */
7301 sort = 0;
7302 access = 0x7f;
7303 loadable = 1;
7304 common = 0;
7305 dup_common = 0;
7306 code_only = 0;
7307 zero = 0;
7308 space_index = ~0;
7309 alignment = 1;
7310 quadrant = 0;
7312 space = current_space;
7313 if (create_new)
7314 ssd = NULL;
7315 else
7316 ssd = is_defined_subspace (ss_name);
7317 /* Allow user to override the builtin attributes of subspaces. But
7318 only allow the attributes to be changed once! */
7319 if (ssd && SUBSPACE_DEFINED (ssd))
7321 subseg_set (ssd->ssd_seg, ssd->ssd_subseg);
7322 current_subspace = ssd;
7323 if (!is_end_of_statement ())
7324 as_warn (_("Parameters of an existing subspace can\'t be modified"));
7325 demand_empty_rest_of_line ();
7326 return;
7328 else
7330 /* A new subspace. Load default values if it matches one of
7331 the builtin subspaces. */
7332 i = 0;
7333 while (pa_def_subspaces[i].name)
7335 if (strcasecmp (pa_def_subspaces[i].name, ss_name) == 0)
7337 loadable = pa_def_subspaces[i].loadable;
7338 common = pa_def_subspaces[i].common;
7339 dup_common = pa_def_subspaces[i].dup_common;
7340 code_only = pa_def_subspaces[i].code_only;
7341 zero = pa_def_subspaces[i].zero;
7342 space_index = pa_def_subspaces[i].space_index;
7343 alignment = pa_def_subspaces[i].alignment;
7344 quadrant = pa_def_subspaces[i].quadrant;
7345 access = pa_def_subspaces[i].access;
7346 sort = pa_def_subspaces[i].sort;
7347 break;
7349 i++;
7353 /* We should be working with a new subspace now. Fill in
7354 any information as specified by the user. */
7355 if (!is_end_of_statement ())
7357 input_line_pointer++;
7358 while (!is_end_of_statement ())
7360 name = input_line_pointer;
7361 c = get_symbol_end ();
7362 if ((strncasecmp (name, "quad", 4) == 0))
7364 *input_line_pointer = c;
7365 input_line_pointer++;
7366 quadrant = get_absolute_expression ();
7368 else if ((strncasecmp (name, "align", 5) == 0))
7370 *input_line_pointer = c;
7371 input_line_pointer++;
7372 alignment = get_absolute_expression ();
7373 if (log2 (alignment) == -1)
7375 as_bad (_("Alignment must be a power of 2"));
7376 alignment = 1;
7379 else if ((strncasecmp (name, "access", 6) == 0))
7381 *input_line_pointer = c;
7382 input_line_pointer++;
7383 access = get_absolute_expression ();
7385 else if ((strncasecmp (name, "sort", 4) == 0))
7387 *input_line_pointer = c;
7388 input_line_pointer++;
7389 sort = get_absolute_expression ();
7391 else if ((strncasecmp (name, "code_only", 9) == 0))
7393 *input_line_pointer = c;
7394 code_only = 1;
7396 else if ((strncasecmp (name, "unloadable", 10) == 0))
7398 *input_line_pointer = c;
7399 loadable = 0;
7401 else if ((strncasecmp (name, "common", 6) == 0))
7403 *input_line_pointer = c;
7404 common = 1;
7406 else if ((strncasecmp (name, "dup_comm", 8) == 0))
7408 *input_line_pointer = c;
7409 dup_common = 1;
7411 else if ((strncasecmp (name, "zero", 4) == 0))
7413 *input_line_pointer = c;
7414 zero = 1;
7416 else if ((strncasecmp (name, "first", 5) == 0))
7417 as_bad (_("FIRST not supported as a .SUBSPACE argument"));
7418 else
7419 as_bad (_("Invalid .SUBSPACE argument"));
7420 if (!is_end_of_statement ())
7421 input_line_pointer++;
7425 /* Compute a reasonable set of BFD flags based on the information
7426 in the .subspace directive. */
7427 applicable = bfd_applicable_section_flags (stdoutput);
7428 flags = 0;
7429 if (loadable)
7430 flags |= (SEC_ALLOC | SEC_LOAD);
7431 if (code_only)
7432 flags |= SEC_CODE;
7433 if (common || dup_common)
7434 flags |= SEC_IS_COMMON;
7436 flags |= SEC_RELOC | SEC_HAS_CONTENTS;
7438 /* This is a zero-filled subspace (eg BSS). */
7439 if (zero)
7440 flags &= ~(SEC_LOAD | SEC_HAS_CONTENTS);
7442 applicable &= flags;
7444 /* If this is an existing subspace, then we want to use the
7445 segment already associated with the subspace.
7447 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
7448 lots of sections. It might be a problem in the PA ELF
7449 code, I do not know yet. For now avoid creating anything
7450 but the "standard" sections for ELF. */
7451 if (create_new)
7452 section = subseg_force_new (ss_name, 0);
7453 else if (ssd)
7454 section = ssd->ssd_seg;
7455 else
7456 section = subseg_new (ss_name, 0);
7458 if (zero)
7459 seg_info (section)->bss = 1;
7461 /* Now set the flags. */
7462 bfd_set_section_flags (stdoutput, section, applicable);
7464 /* Record any alignment request for this section. */
7465 record_alignment (section, log2 (alignment));
7467 /* Set the starting offset for this section. */
7468 bfd_set_section_vma (stdoutput, section,
7469 pa_subspace_start (space, quadrant));
7471 /* Now that all the flags are set, update an existing subspace,
7472 or create a new one. */
7473 if (ssd)
7475 current_subspace = update_subspace (space, ss_name, loadable,
7476 code_only, common, dup_common,
7477 sort, zero, access, space_index,
7478 alignment, quadrant,
7479 section);
7480 else
7481 current_subspace = create_new_subspace (space, ss_name, loadable,
7482 code_only, common,
7483 dup_common, zero, sort,
7484 access, space_index,
7485 alignment, quadrant, section);
7487 demand_empty_rest_of_line ();
7488 current_subspace->ssd_seg = section;
7489 subseg_set (current_subspace->ssd_seg, current_subspace->ssd_subseg);
7491 SUBSPACE_DEFINED (current_subspace) = 1;
7495 /* Create default space and subspace dictionaries. */
7497 static void
7498 pa_spaces_begin ()
7500 int i;
7502 space_dict_root = NULL;
7503 space_dict_last = NULL;
7505 i = 0;
7506 while (pa_def_spaces[i].name)
7508 char *name;
7510 /* Pick the right name to use for the new section. */
7511 name = pa_def_spaces[i].name;
7513 pa_def_spaces[i].segment = subseg_new (name, 0);
7514 create_new_space (pa_def_spaces[i].name, pa_def_spaces[i].spnum,
7515 pa_def_spaces[i].loadable, pa_def_spaces[i].defined,
7516 pa_def_spaces[i].private, pa_def_spaces[i].sort,
7517 pa_def_spaces[i].segment, 0);
7518 i++;
7521 i = 0;
7522 while (pa_def_subspaces[i].name)
7524 char *name;
7525 int applicable, subsegment;
7526 asection *segment = NULL;
7527 sd_chain_struct *space;
7529 /* Pick the right name for the new section and pick the right
7530 subsegment number. */
7531 name = pa_def_subspaces[i].name;
7532 subsegment = 0;
7534 /* Create the new section. */
7535 segment = subseg_new (name, subsegment);
7538 /* For SOM we want to replace the standard .text, .data, and .bss
7539 sections with our own. We also want to set BFD flags for
7540 all the built-in subspaces. */
7541 if (!strcmp (pa_def_subspaces[i].name, "$CODE$"))
7543 text_section = segment;
7544 applicable = bfd_applicable_section_flags (stdoutput);
7545 bfd_set_section_flags (stdoutput, segment,
7546 applicable & (SEC_ALLOC | SEC_LOAD
7547 | SEC_RELOC | SEC_CODE
7548 | SEC_READONLY
7549 | SEC_HAS_CONTENTS));
7551 else if (!strcmp (pa_def_subspaces[i].name, "$DATA$"))
7553 data_section = segment;
7554 applicable = bfd_applicable_section_flags (stdoutput);
7555 bfd_set_section_flags (stdoutput, segment,
7556 applicable & (SEC_ALLOC | SEC_LOAD
7557 | SEC_RELOC
7558 | SEC_HAS_CONTENTS));
7562 else if (!strcmp (pa_def_subspaces[i].name, "$BSS$"))
7564 bss_section = segment;
7565 applicable = bfd_applicable_section_flags (stdoutput);
7566 bfd_set_section_flags (stdoutput, segment,
7567 applicable & SEC_ALLOC);
7569 else if (!strcmp (pa_def_subspaces[i].name, "$LIT$"))
7571 applicable = bfd_applicable_section_flags (stdoutput);
7572 bfd_set_section_flags (stdoutput, segment,
7573 applicable & (SEC_ALLOC | SEC_LOAD
7574 | SEC_RELOC
7575 | SEC_READONLY
7576 | SEC_HAS_CONTENTS));
7578 else if (!strcmp (pa_def_subspaces[i].name, "$MILLICODE$"))
7580 applicable = bfd_applicable_section_flags (stdoutput);
7581 bfd_set_section_flags (stdoutput, segment,
7582 applicable & (SEC_ALLOC | SEC_LOAD
7583 | SEC_RELOC
7584 | SEC_READONLY
7585 | SEC_HAS_CONTENTS));
7587 else if (!strcmp (pa_def_subspaces[i].name, "$UNWIND$"))
7589 applicable = bfd_applicable_section_flags (stdoutput);
7590 bfd_set_section_flags (stdoutput, segment,
7591 applicable & (SEC_ALLOC | SEC_LOAD
7592 | SEC_RELOC
7593 | SEC_READONLY
7594 | SEC_HAS_CONTENTS));
7597 /* Find the space associated with this subspace. */
7598 space = pa_segment_to_space (pa_def_spaces[pa_def_subspaces[i].
7599 def_space_index].segment);
7600 if (space == NULL)
7602 as_fatal (_("Internal error: Unable to find containing space for %s."),
7603 pa_def_subspaces[i].name);
7606 create_new_subspace (space, name,
7607 pa_def_subspaces[i].loadable,
7608 pa_def_subspaces[i].code_only,
7609 pa_def_subspaces[i].common,
7610 pa_def_subspaces[i].dup_common,
7611 pa_def_subspaces[i].zero,
7612 pa_def_subspaces[i].sort,
7613 pa_def_subspaces[i].access,
7614 pa_def_subspaces[i].space_index,
7615 pa_def_subspaces[i].alignment,
7616 pa_def_subspaces[i].quadrant,
7617 segment);
7618 i++;
7624 /* Create a new space NAME, with the appropriate flags as defined
7625 by the given parameters. */
7627 static sd_chain_struct *
7628 create_new_space (name, spnum, loadable, defined, private,
7629 sort, seg, user_defined)
7630 char *name;
7631 int spnum;
7632 int loadable;
7633 int defined;
7634 int private;
7635 int sort;
7636 asection *seg;
7637 int user_defined;
7639 sd_chain_struct *chain_entry;
7641 chain_entry = (sd_chain_struct *) xmalloc (sizeof (sd_chain_struct));
7642 if (!chain_entry)
7643 as_fatal (_("Out of memory: could not allocate new space chain entry: %s\n"),
7644 name);
7646 SPACE_NAME (chain_entry) = (char *) xmalloc (strlen (name) + 1);
7647 strcpy (SPACE_NAME (chain_entry), name);
7648 SPACE_DEFINED (chain_entry) = defined;
7649 SPACE_USER_DEFINED (chain_entry) = user_defined;
7650 SPACE_SPNUM (chain_entry) = spnum;
7652 chain_entry->sd_seg = seg;
7653 chain_entry->sd_last_subseg = -1;
7654 chain_entry->sd_subspaces = NULL;
7655 chain_entry->sd_next = NULL;
7657 /* Find spot for the new space based on its sort key. */
7658 if (!space_dict_last)
7659 space_dict_last = chain_entry;
7661 if (space_dict_root == NULL)
7662 space_dict_root = chain_entry;
7663 else
7665 sd_chain_struct *chain_pointer;
7666 sd_chain_struct *prev_chain_pointer;
7668 chain_pointer = space_dict_root;
7669 prev_chain_pointer = NULL;
7671 while (chain_pointer)
7673 prev_chain_pointer = chain_pointer;
7674 chain_pointer = chain_pointer->sd_next;
7677 /* At this point we've found the correct place to add the new
7678 entry. So add it and update the linked lists as appropriate. */
7679 if (prev_chain_pointer)
7681 chain_entry->sd_next = chain_pointer;
7682 prev_chain_pointer->sd_next = chain_entry;
7684 else
7686 space_dict_root = chain_entry;
7687 chain_entry->sd_next = chain_pointer;
7690 if (chain_entry->sd_next == NULL)
7691 space_dict_last = chain_entry;
7694 /* This is here to catch predefined spaces which do not get
7695 modified by the user's input. Another call is found at
7696 the bottom of pa_parse_space_stmt to handle cases where
7697 the user modifies a predefined space. */
7698 #ifdef obj_set_section_attributes
7699 obj_set_section_attributes (seg, defined, private, sort, spnum);
7700 #endif
7702 return chain_entry;
7705 /* Create a new subspace NAME, with the appropriate flags as defined
7706 by the given parameters.
7708 Add the new subspace to the subspace dictionary chain in numerical
7709 order as defined by the SORT entries. */
7711 static ssd_chain_struct *
7712 create_new_subspace (space, name, loadable, code_only, common,
7713 dup_common, is_zero, sort, access, space_index,
7714 alignment, quadrant, seg)
7715 sd_chain_struct *space;
7716 char *name;
7717 int loadable, code_only, common, dup_common, is_zero;
7718 int sort;
7719 int access;
7720 int space_index;
7721 int alignment;
7722 int quadrant;
7723 asection *seg;
7725 ssd_chain_struct *chain_entry;
7727 chain_entry = (ssd_chain_struct *) xmalloc (sizeof (ssd_chain_struct));
7728 if (!chain_entry)
7729 as_fatal (_("Out of memory: could not allocate new subspace chain entry: %s\n"), name);
7731 SUBSPACE_NAME (chain_entry) = (char *) xmalloc (strlen (name) + 1);
7732 strcpy (SUBSPACE_NAME (chain_entry), name);
7734 /* Initialize subspace_defined. When we hit a .subspace directive
7735 we'll set it to 1 which "locks-in" the subspace attributes. */
7736 SUBSPACE_DEFINED (chain_entry) = 0;
7738 chain_entry->ssd_subseg = 0;
7739 chain_entry->ssd_seg = seg;
7740 chain_entry->ssd_next = NULL;
7742 /* Find spot for the new subspace based on its sort key. */
7743 if (space->sd_subspaces == NULL)
7744 space->sd_subspaces = chain_entry;
7745 else
7747 ssd_chain_struct *chain_pointer;
7748 ssd_chain_struct *prev_chain_pointer;
7750 chain_pointer = space->sd_subspaces;
7751 prev_chain_pointer = NULL;
7753 while (chain_pointer)
7755 prev_chain_pointer = chain_pointer;
7756 chain_pointer = chain_pointer->ssd_next;
7759 /* Now we have somewhere to put the new entry. Insert it and update
7760 the links. */
7761 if (prev_chain_pointer)
7763 chain_entry->ssd_next = chain_pointer;
7764 prev_chain_pointer->ssd_next = chain_entry;
7766 else
7768 space->sd_subspaces = chain_entry;
7769 chain_entry->ssd_next = chain_pointer;
7773 #ifdef obj_set_subsection_attributes
7774 obj_set_subsection_attributes (seg, space->sd_seg, access,
7775 sort, quadrant);
7776 #endif
7778 return chain_entry;
7781 /* Update the information for the given subspace based upon the
7782 various arguments. Return the modified subspace chain entry. */
7784 static ssd_chain_struct *
7785 update_subspace (space, name, loadable, code_only, common, dup_common, sort,
7786 zero, access, space_index, alignment, quadrant, section)
7787 sd_chain_struct *space;
7788 char *name;
7789 int loadable;
7790 int code_only;
7791 int common;
7792 int dup_common;
7793 int zero;
7794 int sort;
7795 int access;
7796 int space_index;
7797 int alignment;
7798 int quadrant;
7799 asection *section;
7801 ssd_chain_struct *chain_entry;
7803 chain_entry = is_defined_subspace (name);
7805 #ifdef obj_set_subsection_attributes
7806 obj_set_subsection_attributes (section, space->sd_seg, access,
7807 sort, quadrant);
7808 #endif
7810 return chain_entry;
7813 /* Return the space chain entry for the space with the name NAME or
7814 NULL if no such space exists. */
7816 static sd_chain_struct *
7817 is_defined_space (name)
7818 char *name;
7820 sd_chain_struct *chain_pointer;
7822 for (chain_pointer = space_dict_root;
7823 chain_pointer;
7824 chain_pointer = chain_pointer->sd_next)
7826 if (strcmp (SPACE_NAME (chain_pointer), name) == 0)
7827 return chain_pointer;
7830 /* No mapping from segment to space was found. Return NULL. */
7831 return NULL;
7834 /* Find and return the space associated with the given seg. If no mapping
7835 from the given seg to a space is found, then return NULL.
7837 Unlike subspaces, the number of spaces is not expected to grow much,
7838 so a linear exhaustive search is OK here. */
7840 static sd_chain_struct *
7841 pa_segment_to_space (seg)
7842 asection *seg;
7844 sd_chain_struct *space_chain;
7846 /* Walk through each space looking for the correct mapping. */
7847 for (space_chain = space_dict_root;
7848 space_chain;
7849 space_chain = space_chain->sd_next)
7851 if (space_chain->sd_seg == seg)
7852 return space_chain;
7855 /* Mapping was not found. Return NULL. */
7856 return NULL;
7859 /* Return the space chain entry for the subspace with the name NAME or
7860 NULL if no such subspace exists.
7862 Uses a linear search through all the spaces and subspaces, this may
7863 not be appropriate if we ever being placing each function in its
7864 own subspace. */
7866 static ssd_chain_struct *
7867 is_defined_subspace (name)
7868 char *name;
7870 sd_chain_struct *space_chain;
7871 ssd_chain_struct *subspace_chain;
7873 /* Walk through each space. */
7874 for (space_chain = space_dict_root;
7875 space_chain;
7876 space_chain = space_chain->sd_next)
7878 /* Walk through each subspace looking for a name which matches. */
7879 for (subspace_chain = space_chain->sd_subspaces;
7880 subspace_chain;
7881 subspace_chain = subspace_chain->ssd_next)
7882 if (strcmp (SUBSPACE_NAME (subspace_chain), name) == 0)
7883 return subspace_chain;
7886 /* Subspace wasn't found. Return NULL. */
7887 return NULL;
7890 /* Find and return the subspace associated with the given seg. If no
7891 mapping from the given seg to a subspace is found, then return NULL.
7893 If we ever put each procedure/function within its own subspace
7894 (to make life easier on the compiler and linker), then this will have
7895 to become more efficient. */
7897 static ssd_chain_struct *
7898 pa_subsegment_to_subspace (seg, subseg)
7899 asection *seg;
7900 subsegT subseg;
7902 sd_chain_struct *space_chain;
7903 ssd_chain_struct *subspace_chain;
7905 /* Walk through each space. */
7906 for (space_chain = space_dict_root;
7907 space_chain;
7908 space_chain = space_chain->sd_next)
7910 if (space_chain->sd_seg == seg)
7912 /* Walk through each subspace within each space looking for
7913 the correct mapping. */
7914 for (subspace_chain = space_chain->sd_subspaces;
7915 subspace_chain;
7916 subspace_chain = subspace_chain->ssd_next)
7917 if (subspace_chain->ssd_subseg == (int) subseg)
7918 return subspace_chain;
7922 /* No mapping from subsegment to subspace found. Return NULL. */
7923 return NULL;
7926 /* Given a number, try and find a space with the name number.
7928 Return a pointer to a space dictionary chain entry for the space
7929 that was found or NULL on failure. */
7931 static sd_chain_struct *
7932 pa_find_space_by_number (number)
7933 int number;
7935 sd_chain_struct *space_chain;
7937 for (space_chain = space_dict_root;
7938 space_chain;
7939 space_chain = space_chain->sd_next)
7941 if (SPACE_SPNUM (space_chain) == (unsigned int) number)
7942 return space_chain;
7945 /* No appropriate space found. Return NULL. */
7946 return NULL;
7949 /* Return the starting address for the given subspace. If the starting
7950 address is unknown then return zero. */
7952 static unsigned int
7953 pa_subspace_start (space, quadrant)
7954 sd_chain_struct *space;
7955 int quadrant;
7957 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
7958 is not correct for the PA OSF1 port. */
7959 if ((strcmp (SPACE_NAME (space), "$PRIVATE$") == 0) && quadrant == 1)
7960 return 0x40000000;
7961 else if (space->sd_seg == data_section && quadrant == 1)
7962 return 0x40000000;
7963 else
7964 return 0;
7965 return 0;
7968 /* FIXME. Needs documentation. */
7969 static int
7970 pa_next_subseg (space)
7971 sd_chain_struct *space;
7974 space->sd_last_subseg++;
7975 return space->sd_last_subseg;
7977 #endif
7979 /* Helper function for pa_stringer. Used to find the end of
7980 a string. */
7982 static unsigned int
7983 pa_stringer_aux (s)
7984 char *s;
7986 unsigned int c = *s & CHAR_MASK;
7988 #ifdef OBJ_SOM
7989 /* We must have a valid space and subspace. */
7990 pa_check_current_space_and_subspace ();
7991 #endif
7993 switch (c)
7995 case '\"':
7996 c = NOT_A_CHAR;
7997 break;
7998 default:
7999 break;
8001 return c;
8004 /* Handle a .STRING type pseudo-op. */
8006 static void
8007 pa_stringer (append_zero)
8008 int append_zero;
8010 char *s, num_buf[4];
8011 unsigned int c;
8012 int i;
8014 /* Preprocess the string to handle PA-specific escape sequences.
8015 For example, \xDD where DD is a hexidecimal number should be
8016 changed to \OOO where OOO is an octal number. */
8018 /* Skip the opening quote. */
8019 s = input_line_pointer + 1;
8021 while (is_a_char (c = pa_stringer_aux (s++)))
8023 if (c == '\\')
8025 c = *s;
8026 switch (c)
8028 /* Handle \x<num>. */
8029 case 'x':
8031 unsigned int number;
8032 int num_digit;
8033 char dg;
8034 char *s_start = s;
8036 /* Get pas the 'x'. */
8037 s++;
8038 for (num_digit = 0, number = 0, dg = *s;
8039 num_digit < 2
8040 && (isdigit (dg) || (dg >= 'a' && dg <= 'f')
8041 || (dg >= 'A' && dg <= 'F'));
8042 num_digit++)
8044 if (isdigit (dg))
8045 number = number * 16 + dg - '0';
8046 else if (dg >= 'a' && dg <= 'f')
8047 number = number * 16 + dg - 'a' + 10;
8048 else
8049 number = number * 16 + dg - 'A' + 10;
8051 s++;
8052 dg = *s;
8054 if (num_digit > 0)
8056 switch (num_digit)
8058 case 1:
8059 sprintf (num_buf, "%02o", number);
8060 break;
8061 case 2:
8062 sprintf (num_buf, "%03o", number);
8063 break;
8065 for (i = 0; i <= num_digit; i++)
8066 s_start[i] = num_buf[i];
8068 break;
8070 /* This might be a "\"", skip over the escaped char. */
8071 default:
8072 s++;
8073 break;
8077 stringer (append_zero);
8078 pa_undefine_label ();
8081 /* Handle a .VERSION pseudo-op. */
8083 static void
8084 pa_version (unused)
8085 int unused ATTRIBUTE_UNUSED;
8087 obj_version (0);
8088 pa_undefine_label ();
8091 #ifdef OBJ_SOM
8093 /* Handle a .COMPILER pseudo-op. */
8095 static void
8096 pa_compiler (unused)
8097 int unused ATTRIBUTE_UNUSED;
8099 obj_som_compiler (0);
8100 pa_undefine_label ();
8103 #endif
8105 /* Handle a .COPYRIGHT pseudo-op. */
8107 static void
8108 pa_copyright (unused)
8109 int unused ATTRIBUTE_UNUSED;
8111 obj_copyright (0);
8112 pa_undefine_label ();
8115 /* Just like a normal cons, but when finished we have to undefine
8116 the latest space label. */
8118 static void
8119 pa_cons (nbytes)
8120 int nbytes;
8122 cons (nbytes);
8123 pa_undefine_label ();
8126 /* Switch to the data space. As usual delete our label. */
8128 static void
8129 pa_data (unused)
8130 int unused ATTRIBUTE_UNUSED;
8132 #ifdef OBJ_SOM
8133 current_space = is_defined_space ("$PRIVATE$");
8134 current_subspace
8135 = pa_subsegment_to_subspace (current_space->sd_seg, 0);
8136 #endif
8137 s_data (0);
8138 pa_undefine_label ();
8141 /* Like float_cons, but we need to undefine our label. */
8143 static void
8144 pa_float_cons (float_type)
8145 int float_type;
8147 float_cons (float_type);
8148 pa_undefine_label ();
8151 /* Like s_fill, but delete our label when finished. */
8153 static void
8154 pa_fill (unused)
8155 int unused ATTRIBUTE_UNUSED;
8157 #ifdef OBJ_SOM
8158 /* We must have a valid space and subspace. */
8159 pa_check_current_space_and_subspace ();
8160 #endif
8162 s_fill (0);
8163 pa_undefine_label ();
8166 /* Like lcomm, but delete our label when finished. */
8168 static void
8169 pa_lcomm (needs_align)
8170 int needs_align;
8172 #ifdef OBJ_SOM
8173 /* We must have a valid space and subspace. */
8174 pa_check_current_space_and_subspace ();
8175 #endif
8177 s_lcomm (needs_align);
8178 pa_undefine_label ();
8181 /* Like lsym, but delete our label when finished. */
8183 static void
8184 pa_lsym (unused)
8185 int unused ATTRIBUTE_UNUSED;
8187 #ifdef OBJ_SOM
8188 /* We must have a valid space and subspace. */
8189 pa_check_current_space_and_subspace ();
8190 #endif
8192 s_lsym (0);
8193 pa_undefine_label ();
8196 /* Switch to the text space. Like s_text, but delete our
8197 label when finished. */
8198 static void
8199 pa_text (unused)
8200 int unused ATTRIBUTE_UNUSED;
8202 #ifdef OBJ_SOM
8203 current_space = is_defined_space ("$TEXT$");
8204 current_subspace
8205 = pa_subsegment_to_subspace (current_space->sd_seg, 0);
8206 #endif
8208 s_text (0);
8209 pa_undefine_label ();
8212 /* On the PA relocations which involve function symbols must not be
8213 adjusted. This so that the linker can know when/how to create argument
8214 relocation stubs for indirect calls and calls to static functions.
8216 "T" field selectors create DLT relative fixups for accessing
8217 globals and statics in PIC code; each DLT relative fixup creates
8218 an entry in the DLT table. The entries contain the address of
8219 the final target (eg accessing "foo" would create a DLT entry
8220 with the address of "foo").
8222 Unfortunately, the HP linker doesn't take into account any addend
8223 when generating the DLT; so accessing $LIT$+8 puts the address of
8224 $LIT$ into the DLT rather than the address of $LIT$+8.
8226 The end result is we can't perform relocation symbol reductions for
8227 any fixup which creates entries in the DLT (eg they use "T" field
8228 selectors).
8230 Reject reductions involving symbols with external scope; such
8231 reductions make life a living hell for object file editors.
8233 FIXME. Also reject R_HPPA relocations which are 32bits wide in
8234 the code space. The SOM BFD backend doesn't know how to pull the
8235 right bits out of an instruction. */
8238 hppa_fix_adjustable (fixp)
8239 fixS *fixp;
8241 struct hppa_fix_struct *hppa_fix;
8243 hppa_fix = (struct hppa_fix_struct *) fixp->tc_fix_data;
8245 #ifdef OBJ_SOM
8246 /* Reject reductions of symbols in 32bit relocs. */
8247 if (fixp->fx_r_type == R_HPPA && hppa_fix->fx_r_format == 32)
8248 return 0;
8250 /* Reject reductions of symbols in sym1-sym2 expressions when
8251 the fixup will occur in a CODE subspace.
8253 XXX FIXME: Long term we probably want to reject all of these;
8254 for example reducing in the debug section would lose if we ever
8255 supported using the optimizing hp linker. */
8256 if (fixp->fx_addsy
8257 && fixp->fx_subsy
8258 && (hppa_fix->segment->flags & SEC_CODE))
8260 /* Apparently sy_used_in_reloc never gets set for sub symbols. */
8261 symbol_mark_used_in_reloc (fixp->fx_subsy);
8262 return 0;
8265 /* We can't adjust any relocs that use LR% and RR% field selectors.
8266 That confuses the HP linker. */
8267 if (hppa_fix->fx_r_field == e_lrsel
8268 || hppa_fix->fx_r_field == e_rrsel
8269 || hppa_fix->fx_r_field == e_nlrsel)
8270 return 0;
8271 #endif
8273 /* Reject reductions of symbols in DLT relative relocs,
8274 relocations with plabels. */
8275 if (hppa_fix->fx_r_field == e_tsel
8276 || hppa_fix->fx_r_field == e_ltsel
8277 || hppa_fix->fx_r_field == e_rtsel
8278 || hppa_fix->fx_r_field == e_psel
8279 || hppa_fix->fx_r_field == e_rpsel
8280 || hppa_fix->fx_r_field == e_lpsel)
8281 return 0;
8283 if (fixp->fx_addsy && S_IS_EXTERNAL (fixp->fx_addsy))
8284 return 0;
8286 /* Reject absolute calls (jumps). */
8287 if (hppa_fix->fx_r_type == R_HPPA_ABS_CALL)
8288 return 0;
8290 /* Reject reductions of function symbols. */
8291 if (fixp->fx_addsy == 0 || ! S_IS_FUNCTION (fixp->fx_addsy))
8292 return 1;
8294 return 0;
8297 /* Return nonzero if the fixup in FIXP will require a relocation,
8298 even it if appears that the fixup could be completely handled
8299 within GAS. */
8302 hppa_force_relocation (fixp)
8303 fixS *fixp;
8305 struct hppa_fix_struct *hppa_fixp;
8306 int distance;
8308 hppa_fixp = (struct hppa_fix_struct *) fixp->tc_fix_data;
8309 #ifdef OBJ_SOM
8310 if (fixp->fx_r_type == R_HPPA_ENTRY || fixp->fx_r_type == R_HPPA_EXIT
8311 || fixp->fx_r_type == R_HPPA_BEGIN_BRTAB
8312 || fixp->fx_r_type == R_HPPA_END_BRTAB
8313 || fixp->fx_r_type == R_HPPA_BEGIN_TRY
8314 || fixp->fx_r_type == R_HPPA_END_TRY
8315 || (fixp->fx_addsy != NULL && fixp->fx_subsy != NULL
8316 && (hppa_fixp->segment->flags & SEC_CODE) != 0))
8317 return 1;
8318 #endif
8320 #define arg_reloc_stub_needed(CALLER, CALLEE) \
8321 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
8323 #ifdef OBJ_SOM
8324 /* It is necessary to force PC-relative calls/jumps to have a relocation
8325 entry if they're going to need either a argument relocation or long
8326 call stub. FIXME. Can't we need the same for absolute calls? */
8327 if (fixp->fx_pcrel && fixp->fx_addsy
8328 && (arg_reloc_stub_needed ((long) ((obj_symbol_type *)
8329 symbol_get_bfdsym (fixp->fx_addsy))->tc_data.ap.hppa_arg_reloc,
8330 hppa_fixp->fx_arg_reloc)))
8331 return 1;
8332 #endif
8333 distance = (fixp->fx_offset + S_GET_VALUE (fixp->fx_addsy)
8334 - md_pcrel_from (fixp));
8335 /* Now check and see if we're going to need a long-branch stub. */
8336 if (fixp->fx_r_type == R_HPPA_PCREL_CALL
8337 && (distance > 262143 || distance < -262144))
8338 return 1;
8340 if (fixp->fx_r_type == R_HPPA_ABS_CALL)
8341 return 1;
8342 #undef arg_reloc_stub_needed
8344 /* No need (yet) to force another relocations to be emitted. */
8345 return 0;
8348 /* Now for some ELF specific code. FIXME. */
8349 #ifdef OBJ_ELF
8350 /* Mark the end of a function so that it's possible to compute
8351 the size of the function in hppa_elf_final_processing. */
8353 static void
8354 hppa_elf_mark_end_of_function ()
8356 /* ELF does not have EXIT relocations. All we do is create a
8357 temporary symbol marking the end of the function. */
8358 char *name = (char *)
8359 xmalloc (strlen ("L$\001end_") +
8360 strlen (S_GET_NAME (last_call_info->start_symbol)) + 1);
8362 if (name)
8364 symbolS *symbolP;
8366 strcpy (name, "L$\001end_");
8367 strcat (name, S_GET_NAME (last_call_info->start_symbol));
8369 /* If we have a .exit followed by a .procend, then the
8370 symbol will have already been defined. */
8371 symbolP = symbol_find (name);
8372 if (symbolP)
8374 /* The symbol has already been defined! This can
8375 happen if we have a .exit followed by a .procend.
8377 This is *not* an error. All we want to do is free
8378 the memory we just allocated for the name and continue. */
8379 xfree (name);
8381 else
8383 /* symbol value should be the offset of the
8384 last instruction of the function */
8385 symbolP = symbol_new (name, now_seg, (valueT) (frag_now_fix () - 4),
8386 frag_now);
8388 assert (symbolP);
8389 S_CLEAR_EXTERNAL (symbolP);
8390 symbol_table_insert (symbolP);
8393 if (symbolP)
8394 last_call_info->end_symbol = symbolP;
8395 else
8396 as_bad (_("Symbol '%s' could not be created."), name);
8399 else
8400 as_bad (_("No memory for symbol name."));
8404 /* For ELF, this function serves one purpose: to setup the st_size
8405 field of STT_FUNC symbols. To do this, we need to scan the
8406 call_info structure list, determining st_size in by taking the
8407 difference in the address of the beginning/end marker symbols. */
8409 void
8410 elf_hppa_final_processing ()
8412 struct call_info *call_info_pointer;
8414 for (call_info_pointer = call_info_root;
8415 call_info_pointer;
8416 call_info_pointer = call_info_pointer->ci_next)
8418 elf_symbol_type *esym
8419 = ((elf_symbol_type *)
8420 symbol_get_bfdsym (call_info_pointer->start_symbol));
8421 esym->internal_elf_sym.st_size =
8422 S_GET_VALUE (call_info_pointer->end_symbol)
8423 - S_GET_VALUE (call_info_pointer->start_symbol) + 4;
8426 #endif
8428 #ifdef OBJ_ELF
8429 void pa_end_of_source ()
8431 if (debug_type == DEBUG_DWARF2)
8432 dwarf2_finish ();
8434 #endif