Initial revision
[binutils.git] / gas / config / tc-hppa.c
blob8785de8769dd654a759f4fe96397f18f6d404121
1 /* tc-hppa.c -- Assemble for the PA
2 Copyright (C) 1989, 93, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA. */
22 /* HP PA-RISC support was contributed by the Center for Software Science
23 at the University of Utah. */
25 #include <stdio.h>
26 #include <ctype.h>
28 #include "as.h"
29 #include "subsegs.h"
31 #include "bfd/libhppa.h"
32 #include "bfd/libbfd.h"
34 /* Be careful, this file includes data *declarations*. */
35 #include "opcode/hppa.h"
37 /* A "convient" place to put object file dependencies which do
38 not need to be seen outside of tc-hppa.c. */
39 #ifdef OBJ_ELF
40 /* Names of various debugging spaces/subspaces. */
41 #define GDB_DEBUG_SPACE_NAME ".stab"
42 #define GDB_STRINGS_SUBSPACE_NAME ".stabstr"
43 #define GDB_SYMBOLS_SUBSPACE_NAME ".stab"
44 #define UNWIND_SECTION_NAME ".PARISC.unwind"
45 /* Nonzero if CODE is a fixup code needing further processing. */
47 /* Object file formats specify relocation types. */
48 typedef elf32_hppa_reloc_type reloc_type;
50 /* Object file formats specify BFD symbol types. */
51 typedef elf_symbol_type obj_symbol_type;
53 /* How to generate a relocation. */
54 #define hppa_gen_reloc_type hppa_elf_gen_reloc_type
56 /* ELF objects can have versions, but apparently do not have anywhere
57 to store a copyright string. */
58 #define obj_version obj_elf_version
59 #define obj_copyright obj_elf_version
61 /* Use space aliases. */
62 #define USE_ALIASES 1
63 #endif
65 #ifdef OBJ_SOM
66 /* Names of various debugging spaces/subspaces. */
67 #define GDB_DEBUG_SPACE_NAME "$GDB_DEBUG$"
68 #define GDB_STRINGS_SUBSPACE_NAME "$GDB_STRINGS$"
69 #define GDB_SYMBOLS_SUBSPACE_NAME "$GDB_SYMBOLS$"
70 #define UNWIND_SECTION_NAME "$UNWIND$"
72 /* Object file formats specify relocation types. */
73 typedef int reloc_type;
75 /* SOM objects can have both a version string and a copyright string. */
76 #define obj_version obj_som_version
77 #define obj_copyright obj_som_copyright
79 /* Do not use space aliases. */
80 #define USE_ALIASES 0
82 /* How to generate a relocation. */
83 #define hppa_gen_reloc_type hppa_som_gen_reloc_type
85 /* Object file formats specify BFD symbol types. */
86 typedef som_symbol_type obj_symbol_type;
88 /* This apparently isn't in older versions of hpux reloc.h. */
89 #ifndef R_DLT_REL
90 #define R_DLT_REL 0x78
91 #endif
92 #endif
94 #ifndef R_N0SEL
95 #define R_N0SEL 0xd8
96 #endif
98 #ifndef R_N1SEL
99 #define R_N1SEL 0xd9
100 #endif
102 /* Various structures and types used internally in tc-hppa.c. */
104 /* Unwind table and descriptor. FIXME: Sync this with GDB version. */
106 struct unwind_desc
108 unsigned int cannot_unwind:1;
109 unsigned int millicode:1;
110 unsigned int millicode_save_rest:1;
111 unsigned int region_desc:2;
112 unsigned int save_sr:2;
113 unsigned int entry_fr:4;
114 unsigned int entry_gr:5;
115 unsigned int args_stored:1;
116 unsigned int call_fr:5;
117 unsigned int call_gr:5;
118 unsigned int save_sp:1;
119 unsigned int save_rp:1;
120 unsigned int save_rp_in_frame:1;
121 unsigned int extn_ptr_defined:1;
122 unsigned int cleanup_defined:1;
124 unsigned int hpe_interrupt_marker:1;
125 unsigned int hpux_interrupt_marker:1;
126 unsigned int reserved:3;
127 unsigned int frame_size:27;
130 struct unwind_table
132 /* Starting and ending offsets of the region described by
133 descriptor. */
134 unsigned int start_offset;
135 unsigned int end_offset;
136 struct unwind_desc descriptor;
139 /* This structure is used by the .callinfo, .enter, .leave pseudo-ops to
140 control the entry and exit code they generate. It is also used in
141 creation of the correct stack unwind descriptors.
143 NOTE: GAS does not support .enter and .leave for the generation of
144 prologues and epilogues. FIXME.
146 The fields in structure roughly correspond to the arguments available on the
147 .callinfo pseudo-op. */
149 struct call_info
151 /* The unwind descriptor being built. */
152 struct unwind_table ci_unwind;
154 /* Name of this function. */
155 symbolS *start_symbol;
157 /* (temporary) symbol used to mark the end of this function. */
158 symbolS *end_symbol;
160 /* Next entry in the chain. */
161 struct call_info *ci_next;
164 /* Operand formats for FP instructions. Note not all FP instructions
165 allow all four formats to be used (for example fmpysub only allows
166 SGL and DBL). */
167 typedef enum
169 SGL, DBL, ILLEGAL_FMT, QUAD, W, UW, DW, UDW, QW, UQW
171 fp_operand_format;
173 /* This fully describes the symbol types which may be attached to
174 an EXPORT or IMPORT directive. Only SOM uses this formation
175 (ELF has no need for it). */
176 typedef enum
178 SYMBOL_TYPE_UNKNOWN,
179 SYMBOL_TYPE_ABSOLUTE,
180 SYMBOL_TYPE_CODE,
181 SYMBOL_TYPE_DATA,
182 SYMBOL_TYPE_ENTRY,
183 SYMBOL_TYPE_MILLICODE,
184 SYMBOL_TYPE_PLABEL,
185 SYMBOL_TYPE_PRI_PROG,
186 SYMBOL_TYPE_SEC_PROG,
188 pa_symbol_type;
190 /* This structure contains information needed to assemble
191 individual instructions. */
192 struct pa_it
194 /* Holds the opcode after parsing by pa_ip. */
195 unsigned long opcode;
197 /* Holds an expression associated with the current instruction. */
198 expressionS exp;
200 /* Does this instruction use PC-relative addressing. */
201 int pcrel;
203 /* Floating point formats for operand1 and operand2. */
204 fp_operand_format fpof1;
205 fp_operand_format fpof2;
208 /* Holds the field selector for this instruction
209 (for example L%, LR%, etc). */
210 long field_selector;
212 /* Holds any argument relocation bits associated with this
213 instruction. (instruction should be some sort of call). */
214 long arg_reloc;
216 /* The format specification for this instruction. */
217 int format;
219 /* The relocation (if any) associated with this instruction. */
220 reloc_type reloc;
223 /* PA-89 floating point registers are arranged like this:
226 +--------------+--------------+
227 | 0 or 16L | 16 or 16R |
228 +--------------+--------------+
229 | 1 or 17L | 17 or 17R |
230 +--------------+--------------+
231 | | |
233 . . .
234 . . .
235 . . .
237 | | |
238 +--------------+--------------+
239 | 14 or 30L | 30 or 30R |
240 +--------------+--------------+
241 | 15 or 31L | 31 or 31R |
242 +--------------+--------------+
245 The following is a version of pa_parse_number that
246 handles the L/R notation and returns the correct
247 value to put into the instruction register field.
248 The correct value to put into the instruction is
249 encoded in the structure 'pa_11_fp_reg_struct'. */
251 struct pa_11_fp_reg_struct
253 /* The register number. */
254 char number_part;
256 /* L/R selector. */
257 char l_r_select;
260 /* Additional information needed to build argument relocation stubs. */
261 struct call_desc
263 /* The argument relocation specification. */
264 unsigned int arg_reloc;
266 /* Number of arguments. */
267 unsigned int arg_count;
270 /* This structure defines an entry in the subspace dictionary
271 chain. */
273 struct subspace_dictionary_chain
275 /* Nonzero if this space has been defined by the user code. */
276 unsigned int ssd_defined;
278 /* Name of this subspace. */
279 char *ssd_name;
281 /* GAS segment and subsegment associated with this subspace. */
282 asection *ssd_seg;
283 int ssd_subseg;
285 /* Next space in the subspace dictionary chain. */
286 struct subspace_dictionary_chain *ssd_next;
289 typedef struct subspace_dictionary_chain ssd_chain_struct;
291 /* This structure defines an entry in the subspace dictionary
292 chain. */
294 struct space_dictionary_chain
296 /* Nonzero if this space has been defined by the user code or
297 as a default space. */
298 unsigned int sd_defined;
300 /* Nonzero if this spaces has been defined by the user code. */
301 unsigned int sd_user_defined;
303 /* The space number (or index). */
304 unsigned int sd_spnum;
306 /* The name of this subspace. */
307 char *sd_name;
309 /* GAS segment to which this subspace corresponds. */
310 asection *sd_seg;
312 /* Current subsegment number being used. */
313 int sd_last_subseg;
315 /* The chain of subspaces contained within this space. */
316 ssd_chain_struct *sd_subspaces;
318 /* The next entry in the space dictionary chain. */
319 struct space_dictionary_chain *sd_next;
322 typedef struct space_dictionary_chain sd_chain_struct;
324 /* Structure for previous label tracking. Needed so that alignments,
325 callinfo declarations, etc can be easily attached to a particular
326 label. */
327 typedef struct label_symbol_struct
329 struct symbol *lss_label;
330 sd_chain_struct *lss_space;
331 struct label_symbol_struct *lss_next;
333 label_symbol_struct;
335 /* This structure defines attributes of the default subspace
336 dictionary entries. */
338 struct default_subspace_dict
340 /* Name of the subspace. */
341 char *name;
343 /* FIXME. Is this still needed? */
344 char defined;
346 /* Nonzero if this subspace is loadable. */
347 char loadable;
349 /* Nonzero if this subspace contains only code. */
350 char code_only;
352 /* Nonzero if this is a common subspace. */
353 char common;
355 /* Nonzero if this is a common subspace which allows symbols
356 to be multiply defined. */
357 char dup_common;
359 /* Nonzero if this subspace should be zero filled. */
360 char zero;
362 /* Sort key for this subspace. */
363 unsigned char sort;
365 /* Access control bits for this subspace. Can represent RWX access
366 as well as privilege level changes for gateways. */
367 int access;
369 /* Index of containing space. */
370 int space_index;
372 /* Alignment (in bytes) of this subspace. */
373 int alignment;
375 /* Quadrant within space where this subspace should be loaded. */
376 int quadrant;
378 /* An index into the default spaces array. */
379 int def_space_index;
381 /* An alias for this section (or NULL if no alias exists). */
382 char *alias;
384 /* Subsegment associated with this subspace. */
385 subsegT subsegment;
388 /* This structure defines attributes of the default space
389 dictionary entries. */
391 struct default_space_dict
393 /* Name of the space. */
394 char *name;
396 /* Space number. It is possible to identify spaces within
397 assembly code numerically! */
398 int spnum;
400 /* Nonzero if this space is loadable. */
401 char loadable;
403 /* Nonzero if this space is "defined". FIXME is still needed */
404 char defined;
406 /* Nonzero if this space can not be shared. */
407 char private;
409 /* Sort key for this space. */
410 unsigned char sort;
412 /* Segment associated with this space. */
413 asection *segment;
415 /* An alias for this section (or NULL if no alias exists). */
416 char *alias;
419 /* Extra information needed to perform fixups (relocations) on the PA. */
420 struct hppa_fix_struct
422 /* The field selector. */
423 enum hppa_reloc_field_selector_type_alt fx_r_field;
425 /* Type of fixup. */
426 int fx_r_type;
428 /* Format of fixup. */
429 int fx_r_format;
431 /* Argument relocation bits. */
432 long fx_arg_reloc;
434 /* The segment this fixup appears in. */
435 segT segment;
438 /* Structure to hold information about predefined registers. */
440 struct pd_reg
442 char *name;
443 int value;
446 /* This structure defines the mapping from a FP condition string
447 to a condition number which can be recorded in an instruction. */
448 struct fp_cond_map
450 char *string;
451 int cond;
454 /* This structure defines a mapping from a field selector
455 string to a field selector type. */
456 struct selector_entry
458 char *prefix;
459 int field_selector;
462 /* Prototypes for functions local to tc-hppa.c. */
464 static void pa_check_current_space_and_subspace PARAMS ((void));
465 static fp_operand_format pa_parse_fp_format PARAMS ((char **s));
466 static void pa_cons PARAMS ((int));
467 static void pa_data PARAMS ((int));
468 static void pa_float_cons PARAMS ((int));
469 static void pa_fill PARAMS ((int));
470 static void pa_lcomm PARAMS ((int));
471 static void pa_lsym PARAMS ((int));
472 static void pa_stringer PARAMS ((int));
473 static void pa_text PARAMS ((int));
474 static void pa_version PARAMS ((int));
475 static int pa_parse_fp_cmp_cond PARAMS ((char **));
476 static int get_expression PARAMS ((char *));
477 static int pa_get_absolute_expression PARAMS ((struct pa_it *, char **));
478 static int evaluate_absolute PARAMS ((struct pa_it *));
479 static unsigned int pa_build_arg_reloc PARAMS ((char *));
480 static unsigned int pa_align_arg_reloc PARAMS ((unsigned int, unsigned int));
481 static int pa_parse_nullif PARAMS ((char **));
482 static int pa_parse_nonneg_cmpsub_cmpltr PARAMS ((char **, int));
483 static int pa_parse_neg_cmpsub_cmpltr PARAMS ((char **, int));
484 static int pa_parse_neg_add_cmpltr PARAMS ((char **, int));
485 static int pa_parse_nonneg_add_cmpltr PARAMS ((char **, int));
486 static void pa_align PARAMS ((int));
487 static void pa_block PARAMS ((int));
488 static void pa_brtab PARAMS ((int));
489 static void pa_try PARAMS ((int));
490 static void pa_call PARAMS ((int));
491 static void pa_call_args PARAMS ((struct call_desc *));
492 static void pa_callinfo PARAMS ((int));
493 static void pa_code PARAMS ((int));
494 static void pa_comm PARAMS ((int));
495 #ifdef OBJ_SOM
496 static void pa_compiler PARAMS ((int));
497 #endif
498 static void pa_copyright PARAMS ((int));
499 static void pa_end PARAMS ((int));
500 static void pa_enter PARAMS ((int));
501 static void pa_entry PARAMS ((int));
502 static void pa_equ PARAMS ((int));
503 static void pa_exit PARAMS ((int));
504 static void pa_export PARAMS ((int));
505 static void pa_type_args PARAMS ((symbolS *, int));
506 static void pa_import PARAMS ((int));
507 static void pa_label PARAMS ((int));
508 static void pa_leave PARAMS ((int));
509 static void pa_level PARAMS ((int));
510 static void pa_origin PARAMS ((int));
511 static void pa_proc PARAMS ((int));
512 static void pa_procend PARAMS ((int));
513 static void pa_space PARAMS ((int));
514 static void pa_spnum PARAMS ((int));
515 static void pa_subspace PARAMS ((int));
516 static void pa_param PARAMS ((int));
517 static void pa_undefine_label PARAMS ((void));
518 static int need_pa11_opcode PARAMS ((struct pa_it *,
519 struct pa_11_fp_reg_struct *));
520 static int pa_parse_number PARAMS ((char **, struct pa_11_fp_reg_struct *));
521 static label_symbol_struct *pa_get_label PARAMS ((void));
522 static sd_chain_struct *create_new_space PARAMS ((char *, int, int,
523 int, int, int,
524 asection *, int));
525 static ssd_chain_struct *create_new_subspace PARAMS ((sd_chain_struct *,
526 char *, int, int,
527 int, int, int,
528 int, int, int, int,
529 int, asection *));
530 static ssd_chain_struct *update_subspace PARAMS ((sd_chain_struct *,
531 char *, int, int, int,
532 int, int, int, int,
533 int, int, int,
534 asection *));
535 static sd_chain_struct *is_defined_space PARAMS ((char *));
536 static ssd_chain_struct *is_defined_subspace PARAMS ((char *));
537 static sd_chain_struct *pa_segment_to_space PARAMS ((asection *));
538 static ssd_chain_struct *pa_subsegment_to_subspace PARAMS ((asection *,
539 subsegT));
540 static sd_chain_struct *pa_find_space_by_number PARAMS ((int));
541 static unsigned int pa_subspace_start PARAMS ((sd_chain_struct *, int));
542 static void pa_ip PARAMS ((char *));
543 static void fix_new_hppa PARAMS ((fragS *, int, int, symbolS *,
544 long, expressionS *, int,
545 bfd_reloc_code_real_type,
546 enum hppa_reloc_field_selector_type_alt,
547 int, long, int *));
548 static int is_end_of_statement PARAMS ((void));
549 static int reg_name_search PARAMS ((char *));
550 static int pa_chk_field_selector PARAMS ((char **));
551 static int is_same_frag PARAMS ((fragS *, fragS *));
552 static void process_exit PARAMS ((void));
553 static sd_chain_struct *pa_parse_space_stmt PARAMS ((char *, int));
554 static int log2 PARAMS ((int));
555 static int pa_next_subseg PARAMS ((sd_chain_struct *));
556 static unsigned int pa_stringer_aux PARAMS ((char *));
557 static void pa_spaces_begin PARAMS ((void));
559 #ifdef OBJ_ELF
560 static void hppa_elf_mark_end_of_function PARAMS ((void));
561 static void pa_build_unwind_subspace PARAMS ((struct call_info *));
562 #endif
564 /* File and gloally scoped variable declarations. */
566 /* Root and final entry in the space chain. */
567 static sd_chain_struct *space_dict_root;
568 static sd_chain_struct *space_dict_last;
570 /* The current space and subspace. */
571 static sd_chain_struct *current_space;
572 static ssd_chain_struct *current_subspace;
574 /* Root of the call_info chain. */
575 static struct call_info *call_info_root;
577 /* The last call_info (for functions) structure
578 seen so it can be associated with fixups and
579 function labels. */
580 static struct call_info *last_call_info;
582 /* The last call description (for actual calls). */
583 static struct call_desc last_call_desc;
585 /* handle of the OPCODE hash table */
586 static struct hash_control *op_hash = NULL;
588 /* This array holds the chars that always start a comment. If the
589 pre-processor is disabled, these aren't very useful. */
590 const char comment_chars[] = ";";
592 /* Table of pseudo ops for the PA. FIXME -- how many of these
593 are now redundant with the overall GAS and the object file
594 dependent tables? */
595 const pseudo_typeS md_pseudo_table[] =
597 /* align pseudo-ops on the PA specify the actual alignment requested,
598 not the log2 of the requested alignment. */
599 {"align", pa_align, 8},
600 {"begin_brtab", pa_brtab, 1},
601 {"begin_try", pa_try, 1},
602 {"block", pa_block, 1},
603 {"blockz", pa_block, 0},
604 {"byte", pa_cons, 1},
605 {"call", pa_call, 0},
606 {"callinfo", pa_callinfo, 0},
607 {"code", pa_code, 0},
608 {"comm", pa_comm, 0},
609 #ifdef OBJ_SOM
610 {"compiler", pa_compiler, 0},
611 #endif
612 {"copyright", pa_copyright, 0},
613 {"data", pa_data, 0},
614 {"double", pa_float_cons, 'd'},
615 {"end", pa_end, 0},
616 {"end_brtab", pa_brtab, 0},
617 {"end_try", pa_try, 0},
618 {"enter", pa_enter, 0},
619 {"entry", pa_entry, 0},
620 {"equ", pa_equ, 0},
621 {"exit", pa_exit, 0},
622 {"export", pa_export, 0},
623 {"fill", pa_fill, 0},
624 {"float", pa_float_cons, 'f'},
625 {"half", pa_cons, 2},
626 {"import", pa_import, 0},
627 {"int", pa_cons, 4},
628 {"label", pa_label, 0},
629 {"lcomm", pa_lcomm, 0},
630 {"leave", pa_leave, 0},
631 {"level", pa_level, 0},
632 {"long", pa_cons, 4},
633 {"lsym", pa_lsym, 0},
634 {"nsubspa", pa_subspace, 1},
635 {"octa", pa_cons, 16},
636 {"org", pa_origin, 0},
637 {"origin", pa_origin, 0},
638 {"param", pa_param, 0},
639 {"proc", pa_proc, 0},
640 {"procend", pa_procend, 0},
641 {"quad", pa_cons, 8},
642 {"reg", pa_equ, 1},
643 {"short", pa_cons, 2},
644 {"single", pa_float_cons, 'f'},
645 {"space", pa_space, 0},
646 {"spnum", pa_spnum, 0},
647 {"string", pa_stringer, 0},
648 {"stringz", pa_stringer, 1},
649 {"subspa", pa_subspace, 0},
650 {"text", pa_text, 0},
651 {"version", pa_version, 0},
652 {"word", pa_cons, 4},
653 {NULL, 0, 0}
656 /* This array holds the chars that only start a comment at the beginning of
657 a line. If the line seems to have the form '# 123 filename'
658 .line and .file directives will appear in the pre-processed output.
660 Note that input_file.c hand checks for '#' at the beginning of the
661 first line of the input file. This is because the compiler outputs
662 #NO_APP at the beginning of its output.
664 Also note that C style comments will always work. */
665 const char line_comment_chars[] = "#";
667 /* This array holds the characters which act as line separators. */
668 const char line_separator_chars[] = "!";
670 /* Chars that can be used to separate mant from exp in floating point nums. */
671 const char EXP_CHARS[] = "eE";
673 /* Chars that mean this number is a floating point constant.
674 As in 0f12.456 or 0d1.2345e12.
676 Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
677 changed in read.c. Ideally it shouldn't hae to know abou it at
678 all, but nothing is ideal around here. */
679 const char FLT_CHARS[] = "rRsSfFdDxXpP";
681 static struct pa_it the_insn;
683 /* Points to the end of an expression just parsed by get_expressoin
684 and friends. FIXME. This shouldn't be handled with a file-global
685 variable. */
686 static char *expr_end;
688 /* Nonzero if a .callinfo appeared within the current procedure. */
689 static int callinfo_found;
691 /* Nonzero if the assembler is currently within a .entry/.exit pair. */
692 static int within_entry_exit;
694 /* Nonzero if the assembler is currently within a procedure definition. */
695 static int within_procedure;
697 /* Handle on strucutre which keep track of the last symbol
698 seen in each subspace. */
699 static label_symbol_struct *label_symbols_rootp = NULL;
701 /* Holds the last field selector. */
702 static int hppa_field_selector;
705 /* A dummy bfd symbol so that all relocations have symbols of some kind. */
706 static symbolS *dummy_symbol;
708 /* Nonzero if errors are to be printed. */
709 static int print_errors = 1;
711 /* List of registers that are pre-defined:
713 Each general register has one predefined name of the form
714 %r<REGNUM> which has the value <REGNUM>.
716 Space and control registers are handled in a similar manner,
717 but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
719 Likewise for the floating point registers, but of the form
720 %fr<REGNUM>. Floating point registers have additional predefined
721 names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
722 again have the value <REGNUM>.
724 Many registers also have synonyms:
726 %r26 - %r23 have %arg0 - %arg3 as synonyms
727 %r28 - %r29 have %ret0 - %ret1 as synonyms
728 %r30 has %sp as a synonym
729 %r27 has %dp as a synonym
730 %r2 has %rp as a synonym
732 Almost every control register has a synonym; they are not listed
733 here for brevity.
735 The table is sorted. Suitable for searching by a binary search. */
737 static const struct pd_reg pre_defined_registers[] =
739 {"%arg0", 26},
740 {"%arg1", 25},
741 {"%arg2", 24},
742 {"%arg3", 23},
743 {"%cr0", 0},
744 {"%cr10", 10},
745 {"%cr11", 11},
746 {"%cr12", 12},
747 {"%cr13", 13},
748 {"%cr14", 14},
749 {"%cr15", 15},
750 {"%cr16", 16},
751 {"%cr17", 17},
752 {"%cr18", 18},
753 {"%cr19", 19},
754 {"%cr20", 20},
755 {"%cr21", 21},
756 {"%cr22", 22},
757 {"%cr23", 23},
758 {"%cr24", 24},
759 {"%cr25", 25},
760 {"%cr26", 26},
761 {"%cr27", 27},
762 {"%cr28", 28},
763 {"%cr29", 29},
764 {"%cr30", 30},
765 {"%cr31", 31},
766 {"%cr8", 8},
767 {"%cr9", 9},
768 {"%dp", 27},
769 {"%eiem", 15},
770 {"%eirr", 23},
771 {"%fr0", 0},
772 {"%fr0l", 0},
773 {"%fr0r", 0},
774 {"%fr1", 1},
775 {"%fr10", 10},
776 {"%fr10l", 10},
777 {"%fr10r", 10},
778 {"%fr11", 11},
779 {"%fr11l", 11},
780 {"%fr11r", 11},
781 {"%fr12", 12},
782 {"%fr12l", 12},
783 {"%fr12r", 12},
784 {"%fr13", 13},
785 {"%fr13l", 13},
786 {"%fr13r", 13},
787 {"%fr14", 14},
788 {"%fr14l", 14},
789 {"%fr14r", 14},
790 {"%fr15", 15},
791 {"%fr15l", 15},
792 {"%fr15r", 15},
793 {"%fr16", 16},
794 {"%fr16l", 16},
795 {"%fr16r", 16},
796 {"%fr17", 17},
797 {"%fr17l", 17},
798 {"%fr17r", 17},
799 {"%fr18", 18},
800 {"%fr18l", 18},
801 {"%fr18r", 18},
802 {"%fr19", 19},
803 {"%fr19l", 19},
804 {"%fr19r", 19},
805 {"%fr1l", 1},
806 {"%fr1r", 1},
807 {"%fr2", 2},
808 {"%fr20", 20},
809 {"%fr20l", 20},
810 {"%fr20r", 20},
811 {"%fr21", 21},
812 {"%fr21l", 21},
813 {"%fr21r", 21},
814 {"%fr22", 22},
815 {"%fr22l", 22},
816 {"%fr22r", 22},
817 {"%fr23", 23},
818 {"%fr23l", 23},
819 {"%fr23r", 23},
820 {"%fr24", 24},
821 {"%fr24l", 24},
822 {"%fr24r", 24},
823 {"%fr25", 25},
824 {"%fr25l", 25},
825 {"%fr25r", 25},
826 {"%fr26", 26},
827 {"%fr26l", 26},
828 {"%fr26r", 26},
829 {"%fr27", 27},
830 {"%fr27l", 27},
831 {"%fr27r", 27},
832 {"%fr28", 28},
833 {"%fr28l", 28},
834 {"%fr28r", 28},
835 {"%fr29", 29},
836 {"%fr29l", 29},
837 {"%fr29r", 29},
838 {"%fr2l", 2},
839 {"%fr2r", 2},
840 {"%fr3", 3},
841 {"%fr30", 30},
842 {"%fr30l", 30},
843 {"%fr30r", 30},
844 {"%fr31", 31},
845 {"%fr31l", 31},
846 {"%fr31r", 31},
847 {"%fr3l", 3},
848 {"%fr3r", 3},
849 {"%fr4", 4},
850 {"%fr4l", 4},
851 {"%fr4r", 4},
852 {"%fr5", 5},
853 {"%fr5l", 5},
854 {"%fr5r", 5},
855 {"%fr6", 6},
856 {"%fr6l", 6},
857 {"%fr6r", 6},
858 {"%fr7", 7},
859 {"%fr7l", 7},
860 {"%fr7r", 7},
861 {"%fr8", 8},
862 {"%fr8l", 8},
863 {"%fr8r", 8},
864 {"%fr9", 9},
865 {"%fr9l", 9},
866 {"%fr9r", 9},
867 {"%hta", 25},
868 {"%iir", 19},
869 {"%ior", 21},
870 {"%ipsw", 22},
871 {"%isr", 20},
872 {"%itmr", 16},
873 {"%iva", 14},
874 {"%pcoq", 18},
875 {"%pcsq", 17},
876 {"%pidr1", 8},
877 {"%pidr2", 9},
878 {"%pidr3", 12},
879 {"%pidr4", 13},
880 {"%ppda", 24},
881 {"%r0", 0},
882 {"%r1", 1},
883 {"%r10", 10},
884 {"%r11", 11},
885 {"%r12", 12},
886 {"%r13", 13},
887 {"%r14", 14},
888 {"%r15", 15},
889 {"%r16", 16},
890 {"%r17", 17},
891 {"%r18", 18},
892 {"%r19", 19},
893 {"%r2", 2},
894 {"%r20", 20},
895 {"%r21", 21},
896 {"%r22", 22},
897 {"%r23", 23},
898 {"%r24", 24},
899 {"%r25", 25},
900 {"%r26", 26},
901 {"%r27", 27},
902 {"%r28", 28},
903 {"%r29", 29},
904 {"%r3", 3},
905 {"%r30", 30},
906 {"%r31", 31},
907 {"%r4", 4},
908 {"%r5", 5},
909 {"%r6", 6},
910 {"%r7", 7},
911 {"%r8", 8},
912 {"%r9", 9},
913 {"%rctr", 0},
914 {"%ret0", 28},
915 {"%ret1", 29},
916 {"%rp", 2},
917 {"%sar", 11},
918 {"%sp", 30},
919 {"%sr0", 0},
920 {"%sr1", 1},
921 {"%sr2", 2},
922 {"%sr3", 3},
923 {"%sr4", 4},
924 {"%sr5", 5},
925 {"%sr6", 6},
926 {"%sr7", 7},
927 {"%tr0", 24},
928 {"%tr1", 25},
929 {"%tr2", 26},
930 {"%tr3", 27},
931 {"%tr4", 28},
932 {"%tr5", 29},
933 {"%tr6", 30},
934 {"%tr7", 31}
937 /* This table is sorted by order of the length of the string. This is
938 so we check for <> before we check for <. If we had a <> and checked
939 for < first, we would get a false match. */
940 static const struct fp_cond_map fp_cond_map[] =
942 {"false?", 0},
943 {"false", 1},
944 {"true?", 30},
945 {"true", 31},
946 {"!<=>", 3},
947 {"!?>=", 8},
948 {"!?<=", 16},
949 {"!<>", 7},
950 {"!>=", 11},
951 {"!?>", 12},
952 {"?<=", 14},
953 {"!<=", 19},
954 {"!?<", 20},
955 {"?>=", 22},
956 {"!?=", 24},
957 {"!=t", 27},
958 {"<=>", 29},
959 {"=t", 5},
960 {"?=", 6},
961 {"?<", 10},
962 {"<=", 13},
963 {"!>", 15},
964 {"?>", 18},
965 {">=", 21},
966 {"!<", 23},
967 {"<>", 25},
968 {"!=", 26},
969 {"!?", 28},
970 {"?", 2},
971 {"=", 4},
972 {"<", 9},
973 {">", 17}
976 static const struct selector_entry selector_table[] =
978 {"f", e_fsel},
979 {"l", e_lsel},
980 {"ld", e_ldsel},
981 {"lp", e_lpsel},
982 {"lr", e_lrsel},
983 {"ls", e_lssel},
984 {"lt", e_ltsel},
985 {"n", e_nsel},
986 {"nl", e_nlsel},
987 {"nlr", e_nlrsel},
988 {"p", e_psel},
989 {"r", e_rsel},
990 {"rd", e_rdsel},
991 {"rp", e_rpsel},
992 {"rr", e_rrsel},
993 {"rs", e_rssel},
994 {"rt", e_rtsel},
995 {"t", e_tsel},
998 /* default space and subspace dictionaries */
1000 #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
1001 #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
1003 /* pre-defined subsegments (subspaces) for the HPPA. */
1004 #define SUBSEG_CODE 0
1005 #define SUBSEG_LIT 1
1006 #define SUBSEG_MILLI 2
1007 #define SUBSEG_DATA 0
1008 #define SUBSEG_BSS 2
1009 #define SUBSEG_UNWIND 3
1010 #define SUBSEG_GDB_STRINGS 0
1011 #define SUBSEG_GDB_SYMBOLS 1
1013 static struct default_subspace_dict pa_def_subspaces[] =
1015 {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_CODE},
1016 {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, ".data", SUBSEG_DATA},
1017 {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_LIT},
1018 {"$MILLICODE$", 1, 1, 0, 0, 0, 0, 8, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_MILLI},
1019 {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, ".bss", SUBSEG_BSS},
1020 #ifdef OBJ_ELF
1021 {"$UNWIND$", 1, 1, 0, 0, 0, 0, 64, 0x2c, 0, 4, 0, 0, ".PARISC.unwind", SUBSEG_UNWIND},
1022 #endif
1023 {NULL, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
1026 static struct default_space_dict pa_def_spaces[] =
1028 {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL, ".text"},
1029 {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL, ".data"},
1030 {NULL, 0, 0, 0, 0, 0, ASEC_NULL, NULL}
1033 /* Misc local definitions used by the assembler. */
1035 /* Return nonzero if the string pointed to by S potentially represents
1036 a right or left half of a FP register */
1037 #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
1038 #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
1040 /* These macros are used to maintain spaces/subspaces. */
1041 #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined
1042 #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
1043 #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum
1044 #define SPACE_NAME(space_chain) (space_chain)->sd_name
1046 #define SUBSPACE_DEFINED(ss_chain) (ss_chain)->ssd_defined
1047 #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name
1049 /* Insert FIELD into OPCODE starting at bit START. Continue pa_ip
1050 main loop after insertion. */
1052 #define INSERT_FIELD_AND_CONTINUE(OPCODE, FIELD, START) \
1054 ((OPCODE) |= (FIELD) << (START)); \
1055 continue; \
1058 /* Simple range checking for FIELD againt HIGH and LOW bounds.
1059 IGNORE is used to suppress the error message. */
1061 #define CHECK_FIELD(FIELD, HIGH, LOW, IGNORE) \
1063 if ((FIELD) > (HIGH) || (FIELD) < (LOW)) \
1065 if (! IGNORE) \
1066 as_bad (_("Field out of range [%d..%d] (%d)."), (LOW), (HIGH), \
1067 (int) (FIELD));\
1068 break; \
1072 #define is_DP_relative(exp) \
1073 ((exp).X_op == O_subtract \
1074 && strcmp((exp).X_op_symbol->bsym->name, "$global$") == 0)
1076 #define is_PC_relative(exp) \
1077 ((exp).X_op == O_subtract \
1078 && strcmp((exp).X_op_symbol->bsym->name, "$PIC_pcrel$0") == 0)
1080 /* We need some complex handling for stabs (sym1 - sym2). Luckily, we'll
1081 always be able to reduce the expression to a constant, so we don't
1082 need real complex handling yet. */
1083 #define is_complex(exp) \
1084 ((exp).X_op != O_constant && (exp).X_op != O_symbol)
1086 /* Actual functions to implement the PA specific code for the assembler. */
1088 /* Called before writing the object file. Make sure entry/exit and
1089 proc/procend pairs match. */
1091 void
1092 pa_check_eof ()
1094 if (within_entry_exit)
1095 as_fatal (_("Missing .exit\n"));
1097 if (within_procedure)
1098 as_fatal (_("Missing .procend\n"));
1101 /* Check to make sure we have a valid space and subspace. */
1103 static void
1104 pa_check_current_space_and_subspace ()
1106 if (current_space == NULL)
1107 as_fatal (_("Not in a space.\n"));
1109 if (current_subspace == NULL)
1110 as_fatal (_("Not in a subspace.\n"));
1113 /* Returns a pointer to the label_symbol_struct for the current space.
1114 or NULL if no label_symbol_struct exists for the current space. */
1116 static label_symbol_struct *
1117 pa_get_label ()
1119 label_symbol_struct *label_chain;
1120 sd_chain_struct *space_chain = current_space;
1122 for (label_chain = label_symbols_rootp;
1123 label_chain;
1124 label_chain = label_chain->lss_next)
1125 if (space_chain == label_chain->lss_space && label_chain->lss_label)
1126 return label_chain;
1128 return NULL;
1131 /* Defines a label for the current space. If one is already defined,
1132 this function will replace it with the new label. */
1134 void
1135 pa_define_label (symbol)
1136 symbolS *symbol;
1138 label_symbol_struct *label_chain = pa_get_label ();
1139 sd_chain_struct *space_chain = current_space;
1141 if (label_chain)
1142 label_chain->lss_label = symbol;
1143 else
1145 /* Create a new label entry and add it to the head of the chain. */
1146 label_chain
1147 = (label_symbol_struct *) xmalloc (sizeof (label_symbol_struct));
1148 label_chain->lss_label = symbol;
1149 label_chain->lss_space = space_chain;
1150 label_chain->lss_next = NULL;
1152 if (label_symbols_rootp)
1153 label_chain->lss_next = label_symbols_rootp;
1155 label_symbols_rootp = label_chain;
1159 /* Removes a label definition for the current space.
1160 If there is no label_symbol_struct entry, then no action is taken. */
1162 static void
1163 pa_undefine_label ()
1165 label_symbol_struct *label_chain;
1166 label_symbol_struct *prev_label_chain = NULL;
1167 sd_chain_struct *space_chain = current_space;
1169 for (label_chain = label_symbols_rootp;
1170 label_chain;
1171 label_chain = label_chain->lss_next)
1173 if (space_chain == label_chain->lss_space && label_chain->lss_label)
1175 /* Remove the label from the chain and free its memory. */
1176 if (prev_label_chain)
1177 prev_label_chain->lss_next = label_chain->lss_next;
1178 else
1179 label_symbols_rootp = label_chain->lss_next;
1181 free (label_chain);
1182 break;
1184 prev_label_chain = label_chain;
1189 /* An HPPA-specific version of fix_new. This is required because the HPPA
1190 code needs to keep track of some extra stuff. Each call to fix_new_hppa
1191 results in the creation of an instance of an hppa_fix_struct. An
1192 hppa_fix_struct stores the extra information along with a pointer to the
1193 original fixS. This is attached to the original fixup via the
1194 tc_fix_data field. */
1196 static void
1197 fix_new_hppa (frag, where, size, add_symbol, offset, exp, pcrel,
1198 r_type, r_field, r_format, arg_reloc, unwind_bits)
1199 fragS *frag;
1200 int where;
1201 int size;
1202 symbolS *add_symbol;
1203 long offset;
1204 expressionS *exp;
1205 int pcrel;
1206 bfd_reloc_code_real_type r_type;
1207 enum hppa_reloc_field_selector_type_alt r_field;
1208 int r_format;
1209 long arg_reloc;
1210 int* unwind_bits;
1212 fixS *new_fix;
1214 struct hppa_fix_struct *hppa_fix = (struct hppa_fix_struct *)
1215 obstack_alloc (&notes, sizeof (struct hppa_fix_struct));
1217 if (exp != NULL)
1218 new_fix = fix_new_exp (frag, where, size, exp, pcrel, r_type);
1219 else
1220 new_fix = fix_new (frag, where, size, add_symbol, offset, pcrel, r_type);
1221 new_fix->tc_fix_data = (void *) hppa_fix;
1222 hppa_fix->fx_r_type = r_type;
1223 hppa_fix->fx_r_field = r_field;
1224 hppa_fix->fx_r_format = r_format;
1225 hppa_fix->fx_arg_reloc = arg_reloc;
1226 hppa_fix->segment = now_seg;
1227 #ifdef OBJ_SOM
1228 if (r_type == R_ENTRY || r_type == R_EXIT)
1229 new_fix->fx_offset = *unwind_bits;
1230 #endif
1232 /* foo-$global$ is used to access non-automatic storage. $global$
1233 is really just a marker and has served its purpose, so eliminate
1234 it now so as not to confuse write.c. */
1235 if (new_fix->fx_subsy
1236 && !strcmp (S_GET_NAME (new_fix->fx_subsy), "$global$"))
1237 new_fix->fx_subsy = NULL;
1240 /* Parse a .byte, .word, .long expression for the HPPA. Called by
1241 cons via the TC_PARSE_CONS_EXPRESSION macro. */
1243 void
1244 parse_cons_expression_hppa (exp)
1245 expressionS *exp;
1247 hppa_field_selector = pa_chk_field_selector (&input_line_pointer);
1248 expression (exp);
1251 /* This fix_new is called by cons via TC_CONS_FIX_NEW.
1252 hppa_field_selector is set by the parse_cons_expression_hppa. */
1254 void
1255 cons_fix_new_hppa (frag, where, size, exp)
1256 fragS *frag;
1257 int where;
1258 int size;
1259 expressionS *exp;
1261 unsigned int rel_type;
1263 /* Get a base relocation type. */
1264 if (is_DP_relative (*exp))
1265 rel_type = R_HPPA_GOTOFF;
1266 else if (is_complex (*exp))
1267 rel_type = R_HPPA_COMPLEX;
1268 else
1269 rel_type = R_HPPA;
1271 if (hppa_field_selector != e_psel && hppa_field_selector != e_fsel)
1272 as_warn (_("Invalid field selector. Assuming F%%."));
1274 fix_new_hppa (frag, where, size,
1275 (symbolS *) NULL, (offsetT) 0, exp, 0, rel_type,
1276 hppa_field_selector, 32, 0, NULL);
1278 /* Reset field selector to its default state. */
1279 hppa_field_selector = 0;
1282 /* This function is called once, at assembler startup time. It should
1283 set up all the tables, etc. that the MD part of the assembler will need. */
1285 void
1286 md_begin ()
1288 const char *retval = NULL;
1289 int lose = 0;
1290 unsigned int i = 0;
1292 last_call_info = NULL;
1293 call_info_root = NULL;
1295 /* Set the default machine type. */
1296 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 10))
1297 as_warn (_("could not set architecture and machine"));
1299 /* Folding of text and data segments fails miserably on the PA.
1300 Warn user and disable "-R" option. */
1301 if (flag_readonly_data_in_text)
1303 as_warn (_("-R option not supported on this target."));
1304 flag_readonly_data_in_text = 0;
1307 pa_spaces_begin ();
1309 op_hash = hash_new ();
1311 while (i < NUMOPCODES)
1313 const char *name = pa_opcodes[i].name;
1314 retval = hash_insert (op_hash, name, (struct pa_opcode *) &pa_opcodes[i]);
1315 if (retval != NULL && *retval != '\0')
1317 as_fatal (_("Internal error: can't hash `%s': %s\n"), name, retval);
1318 lose = 1;
1322 if ((pa_opcodes[i].match & pa_opcodes[i].mask)
1323 != pa_opcodes[i].match)
1325 fprintf (stderr, _("internal error: losing opcode: `%s' \"%s\"\n"),
1326 pa_opcodes[i].name, pa_opcodes[i].args);
1327 lose = 1;
1329 ++i;
1331 while (i < NUMOPCODES && !strcmp (pa_opcodes[i].name, name));
1334 if (lose)
1335 as_fatal (_("Broken assembler. No assembly attempted."));
1337 /* SOM will change text_section. To make sure we never put
1338 anything into the old one switch to the new one now. */
1339 subseg_set (text_section, 0);
1341 dummy_symbol = symbol_find_or_make ("L$dummy");
1342 S_SET_SEGMENT (dummy_symbol, text_section);
1345 /* Assemble a single instruction storing it into a frag. */
1346 void
1347 md_assemble (str)
1348 char *str;
1350 char *to;
1352 /* The had better be something to assemble. */
1353 assert (str);
1355 /* If we are within a procedure definition, make sure we've
1356 defined a label for the procedure; handle case where the
1357 label was defined after the .PROC directive.
1359 Note there's not need to diddle with the segment or fragment
1360 for the label symbol in this case. We have already switched
1361 into the new $CODE$ subspace at this point. */
1362 if (within_procedure && last_call_info->start_symbol == NULL)
1364 label_symbol_struct *label_symbol = pa_get_label ();
1366 if (label_symbol)
1368 if (label_symbol->lss_label)
1370 last_call_info->start_symbol = label_symbol->lss_label;
1371 label_symbol->lss_label->bsym->flags |= BSF_FUNCTION;
1372 #ifdef OBJ_SOM
1373 /* Also handle allocation of a fixup to hold the unwind
1374 information when the label appears after the proc/procend. */
1375 if (within_entry_exit)
1377 char *where = frag_more (0);
1379 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
1380 NULL, (offsetT) 0, NULL,
1381 0, R_HPPA_ENTRY, e_fsel, 0, 0,
1382 (int *)&last_call_info->ci_unwind.descriptor);
1384 #endif
1386 else
1387 as_bad (_("Missing function name for .PROC (corrupted label chain)"));
1389 else
1390 as_bad (_("Missing function name for .PROC"));
1393 /* Assemble the instruction. Results are saved into "the_insn". */
1394 pa_ip (str);
1396 /* Get somewhere to put the assembled instrution. */
1397 to = frag_more (4);
1399 /* Output the opcode. */
1400 md_number_to_chars (to, the_insn.opcode, 4);
1402 /* If necessary output more stuff. */
1403 if (the_insn.reloc != R_HPPA_NONE)
1404 fix_new_hppa (frag_now, (to - frag_now->fr_literal), 4, NULL,
1405 (offsetT) 0, &the_insn.exp, the_insn.pcrel,
1406 the_insn.reloc, the_insn.field_selector,
1407 the_insn.format, the_insn.arg_reloc, NULL);
1410 /* Do the real work for assembling a single instruction. Store results
1411 into the global "the_insn" variable. */
1413 static void
1414 pa_ip (str)
1415 char *str;
1417 char *error_message = "";
1418 char *s, c, *argstart, *name, *save_s;
1419 const char *args;
1420 int match = FALSE;
1421 int comma = 0;
1422 int cmpltr, nullif, flag, cond, num;
1423 unsigned long opcode;
1424 struct pa_opcode *insn;
1426 /* We must have a valid space and subspace. */
1427 pa_check_current_space_and_subspace ();
1429 /* Skip to something interesting. */
1430 for (s = str; isupper (*s) || islower (*s) || (*s >= '0' && *s <= '3'); ++s)
1433 switch (*s)
1436 case '\0':
1437 break;
1439 case ',':
1440 comma = 1;
1442 /*FALLTHROUGH */
1444 case ' ':
1445 *s++ = '\0';
1446 break;
1448 default:
1449 as_fatal (_("Unknown opcode: `%s'"), str);
1452 save_s = str;
1454 /* Convert everything into lower case. */
1455 while (*save_s)
1457 if (isupper (*save_s))
1458 *save_s = tolower (*save_s);
1459 save_s++;
1462 /* Look up the opcode in the has table. */
1463 if ((insn = (struct pa_opcode *) hash_find (op_hash, str)) == NULL)
1465 as_bad ("Unknown opcode: `%s'", str);
1466 return;
1469 if (comma)
1471 *--s = ',';
1474 /* Mark the location where arguments for the instruction start, then
1475 start processing them. */
1476 argstart = s;
1477 for (;;)
1479 /* Do some initialization. */
1480 opcode = insn->match;
1481 memset (&the_insn, 0, sizeof (the_insn));
1483 the_insn.reloc = R_HPPA_NONE;
1485 /* If this instruction is specific to a particular architecture,
1486 then set a new architecture. */
1487 /* But do not automatically promote to pa2.0. The automatic promotion
1488 crud is for compatability with HP's old assemblers only. */
1489 if (insn->arch < 20
1490 && bfd_get_mach (stdoutput) < insn->arch)
1492 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, insn->arch))
1493 as_warn (_("could not update architecture and machine"));
1495 else if (bfd_get_mach (stdoutput) < insn->arch)
1497 match = FALSE;
1498 goto failed;
1501 /* Build the opcode, checking as we go to make
1502 sure that the operands match. */
1503 for (args = insn->args;; ++args)
1505 switch (*args)
1508 /* End of arguments. */
1509 case '\0':
1510 if (*s == '\0')
1511 match = TRUE;
1512 break;
1514 case '+':
1515 if (*s == '+')
1517 ++s;
1518 continue;
1520 if (*s == '-')
1521 continue;
1522 break;
1524 /* These must match exactly. */
1525 case '(':
1526 case ')':
1527 case ',':
1528 case ' ':
1529 if (*s++ == *args)
1530 continue;
1531 break;
1533 /* Handle a 5 bit register or control register field at 10. */
1534 case 'b':
1535 case '^':
1536 num = pa_parse_number (&s, 0);
1537 CHECK_FIELD (num, 31, 0, 0);
1538 INSERT_FIELD_AND_CONTINUE (opcode, num, 21);
1540 /* Handle a 5 bit register field at 15. */
1541 case 'x':
1542 num = pa_parse_number (&s, 0);
1543 CHECK_FIELD (num, 31, 0, 0);
1544 INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
1546 /* Handle a 5 bit register field at 31. */
1547 case 'y':
1548 case 't':
1549 num = pa_parse_number (&s, 0);
1550 CHECK_FIELD (num, 31, 0, 0);
1551 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
1553 /* Handle a 5 bit field length at 31. */
1554 case 'T':
1555 num = pa_get_absolute_expression (&the_insn, &s);
1556 s = expr_end;
1557 CHECK_FIELD (num, 32, 1, 0);
1558 INSERT_FIELD_AND_CONTINUE (opcode, 32 - num, 0);
1560 /* Handle a 5 bit immediate at 15. */
1561 case '5':
1562 num = pa_get_absolute_expression (&the_insn, &s);
1563 s = expr_end;
1564 CHECK_FIELD (num, 15, -16, 0);
1565 low_sign_unext (num, 5, &num);
1566 INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
1568 /* Handle a 5 bit immediate at 31. */
1569 case 'V':
1570 num = pa_get_absolute_expression (&the_insn, &s);
1571 s = expr_end;
1572 CHECK_FIELD (num, 15, -16, 0)
1573 low_sign_unext (num, 5, &num);
1574 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
1576 /* Handle an unsigned 5 bit immediate at 31. */
1577 case 'r':
1578 num = pa_get_absolute_expression (&the_insn, &s);
1579 s = expr_end;
1580 CHECK_FIELD (num, 31, 0, 0);
1581 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
1583 /* Handle an unsigned 5 bit immediate at 15. */
1584 case 'R':
1585 num = pa_get_absolute_expression (&the_insn, &s);
1586 s = expr_end;
1587 CHECK_FIELD (num, 31, 0, 0);
1588 INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
1590 /* Handle a 2 bit space identifier at 17. */
1591 case 's':
1592 num = pa_parse_number (&s, 0);
1593 CHECK_FIELD (num, 3, 0, 1);
1594 INSERT_FIELD_AND_CONTINUE (opcode, num, 14);
1596 /* Handle a 3 bit space identifier at 18. */
1597 case 'S':
1598 num = pa_parse_number (&s, 0);
1599 CHECK_FIELD (num, 7, 0, 1);
1600 dis_assemble_3 (num, &num);
1601 INSERT_FIELD_AND_CONTINUE (opcode, num, 13);
1603 /* Handle a completer for an indexing load or store. */
1604 case 'c':
1606 int uu = 0;
1607 int m = 0;
1608 int i = 0;
1609 while (*s == ',' && i < 2)
1611 s++;
1612 if (strncasecmp (s, "sm", 2) == 0)
1614 uu = 1;
1615 m = 1;
1616 s++;
1617 i++;
1619 else if (strncasecmp (s, "m", 1) == 0)
1620 m = 1;
1621 else if (strncasecmp (s, "s", 1) == 0)
1622 uu = 1;
1623 else
1624 as_bad (_("Invalid Indexed Load Completer."));
1625 s++;
1626 i++;
1628 if (i > 2)
1629 as_bad (_("Invalid Indexed Load Completer Syntax."));
1630 opcode |= m << 5;
1631 INSERT_FIELD_AND_CONTINUE (opcode, uu, 13);
1634 /* Handle a short load/store completer. */
1635 case 'C':
1637 int a = 0;
1638 int m = 0;
1639 if (*s == ',')
1641 s++;
1642 if (strncasecmp (s, "ma", 2) == 0)
1644 a = 0;
1645 m = 1;
1647 else if (strncasecmp (s, "mb", 2) == 0)
1649 a = 1;
1650 m = 1;
1652 else
1653 as_bad (_("Invalid Short Load/Store Completer."));
1654 s += 2;
1657 if (*args == 'C')
1659 opcode |= m << 5;
1660 INSERT_FIELD_AND_CONTINUE (opcode, a, 13);
1664 /* Handle a stbys completer. */
1665 case 'Y':
1667 int a = 0;
1668 int m = 0;
1669 int i = 0;
1670 while (*s == ',' && i < 2)
1672 s++;
1673 if (strncasecmp (s, "m", 1) == 0)
1674 m = 1;
1675 else if (strncasecmp (s, "b", 1) == 0)
1676 a = 0;
1677 else if (strncasecmp (s, "e", 1) == 0)
1678 a = 1;
1679 else
1680 as_bad (_("Invalid Store Bytes Short Completer"));
1681 s++;
1682 i++;
1684 if (i > 2)
1685 as_bad (_("Invalid Store Bytes Short Completer"));
1686 opcode |= m << 5;
1687 INSERT_FIELD_AND_CONTINUE (opcode, a, 13);
1690 /* Handle a non-negated compare/stubtract condition. */
1691 case '<':
1692 cmpltr = pa_parse_nonneg_cmpsub_cmpltr (&s, 1);
1693 if (cmpltr < 0)
1695 as_bad (_("Invalid Compare/Subtract Condition: %c"), *s);
1696 cmpltr = 0;
1698 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
1700 /* Handle a negated or non-negated compare/subtract condition. */
1701 case '?':
1702 save_s = s;
1703 cmpltr = pa_parse_nonneg_cmpsub_cmpltr (&s, 1);
1704 if (cmpltr < 0)
1706 s = save_s;
1707 cmpltr = pa_parse_neg_cmpsub_cmpltr (&s, 1);
1708 if (cmpltr < 0)
1710 as_bad (_("Invalid Compare/Subtract Condition."));
1711 cmpltr = 0;
1713 else
1715 /* Negated condition requires an opcode change. */
1716 opcode |= 1 << 27;
1720 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
1722 /* Handle non-negated add condition. */
1723 case '!':
1724 cmpltr = pa_parse_nonneg_add_cmpltr (&s, 1);
1725 if (cmpltr < 0)
1727 as_bad (_("Invalid Compare/Subtract Condition: %c"), *s);
1728 cmpltr = 0;
1730 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
1732 /* Handle a negated or non-negated add condition. */
1733 case '@':
1734 save_s = s;
1735 cmpltr = pa_parse_nonneg_add_cmpltr (&s, 1);
1736 if (cmpltr < 0)
1738 s = save_s;
1739 cmpltr = pa_parse_neg_add_cmpltr (&s, 1);
1740 if (cmpltr < 0)
1742 as_bad (_("Invalid Compare/Subtract Condition"));
1743 cmpltr = 0;
1745 else
1747 /* Negated condition requires an opcode change. */
1748 opcode |= 1 << 27;
1751 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
1753 /* Handle a compare/subtract condition. */
1754 case 'a':
1755 cmpltr = 0;
1756 flag = 0;
1757 if (*s == ',')
1759 s++;
1760 name = s;
1761 while (*s != ',' && *s != ' ' && *s != '\t')
1762 s += 1;
1763 c = *s;
1764 *s = 0x00;
1765 if (strcmp (name, "=") == 0)
1766 cmpltr = 1;
1767 else if (strcmp (name, "<") == 0)
1768 cmpltr = 2;
1769 else if (strcmp (name, "<=") == 0)
1770 cmpltr = 3;
1771 else if (strcasecmp (name, "<<") == 0)
1772 cmpltr = 4;
1773 else if (strcasecmp (name, "<<=") == 0)
1774 cmpltr = 5;
1775 else if (strcasecmp (name, "sv") == 0)
1776 cmpltr = 6;
1777 else if (strcasecmp (name, "od") == 0)
1778 cmpltr = 7;
1779 else if (strcasecmp (name, "tr") == 0)
1781 cmpltr = 0;
1782 flag = 1;
1784 else if (strcmp (name, "<>") == 0)
1786 cmpltr = 1;
1787 flag = 1;
1789 else if (strcmp (name, ">=") == 0)
1791 cmpltr = 2;
1792 flag = 1;
1794 else if (strcmp (name, ">") == 0)
1796 cmpltr = 3;
1797 flag = 1;
1799 else if (strcasecmp (name, ">>=") == 0)
1801 cmpltr = 4;
1802 flag = 1;
1804 else if (strcasecmp (name, ">>") == 0)
1806 cmpltr = 5;
1807 flag = 1;
1809 else if (strcasecmp (name, "nsv") == 0)
1811 cmpltr = 6;
1812 flag = 1;
1814 else if (strcasecmp (name, "ev") == 0)
1816 cmpltr = 7;
1817 flag = 1;
1819 else
1820 as_bad (_("Invalid Add Condition: %s"), name);
1821 *s = c;
1823 opcode |= cmpltr << 13;
1824 INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
1826 /* Handle a non-negated add condition. */
1827 case 'd':
1828 cmpltr = 0;
1829 flag = 0;
1830 if (*s == ',')
1832 s++;
1833 name = s;
1834 while (*s != ',' && *s != ' ' && *s != '\t')
1835 s += 1;
1836 c = *s;
1837 *s = 0x00;
1838 if (strcmp (name, "=") == 0)
1839 cmpltr = 1;
1840 else if (strcmp (name, "<") == 0)
1841 cmpltr = 2;
1842 else if (strcmp (name, "<=") == 0)
1843 cmpltr = 3;
1844 else if (strcasecmp (name, "nuv") == 0)
1845 cmpltr = 4;
1846 else if (strcasecmp (name, "znv") == 0)
1847 cmpltr = 5;
1848 else if (strcasecmp (name, "sv") == 0)
1849 cmpltr = 6;
1850 else if (strcasecmp (name, "od") == 0)
1851 cmpltr = 7;
1852 else if (strcasecmp (name, "tr") == 0)
1854 cmpltr = 0;
1855 flag = 1;
1857 else if (strcmp (name, "<>") == 0)
1859 cmpltr = 1;
1860 flag = 1;
1862 else if (strcmp (name, ">=") == 0)
1864 cmpltr = 2;
1865 flag = 1;
1867 else if (strcmp (name, ">") == 0)
1869 cmpltr = 3;
1870 flag = 1;
1872 else if (strcasecmp (name, "uv") == 0)
1874 cmpltr = 4;
1875 flag = 1;
1877 else if (strcasecmp (name, "vnz") == 0)
1879 cmpltr = 5;
1880 flag = 1;
1882 else if (strcasecmp (name, "nsv") == 0)
1884 cmpltr = 6;
1885 flag = 1;
1887 else if (strcasecmp (name, "ev") == 0)
1889 cmpltr = 7;
1890 flag = 1;
1892 else
1893 as_bad (_("Invalid Add Condition: %s"), name);
1894 *s = c;
1896 opcode |= cmpltr << 13;
1897 INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
1899 /* HANDLE a logical instruction condition. */
1900 case '&':
1901 cmpltr = 0;
1902 flag = 0;
1903 if (*s == ',')
1905 s++;
1906 name = s;
1907 while (*s != ',' && *s != ' ' && *s != '\t')
1908 s += 1;
1909 c = *s;
1910 *s = 0x00;
1913 if (strcmp (name, "=") == 0)
1914 cmpltr = 1;
1915 else if (strcmp (name, "<") == 0)
1916 cmpltr = 2;
1917 else if (strcmp (name, "<=") == 0)
1918 cmpltr = 3;
1919 else if (strcasecmp (name, "od") == 0)
1920 cmpltr = 7;
1921 else if (strcasecmp (name, "tr") == 0)
1923 cmpltr = 0;
1924 flag = 1;
1926 else if (strcmp (name, "<>") == 0)
1928 cmpltr = 1;
1929 flag = 1;
1931 else if (strcmp (name, ">=") == 0)
1933 cmpltr = 2;
1934 flag = 1;
1936 else if (strcmp (name, ">") == 0)
1938 cmpltr = 3;
1939 flag = 1;
1941 else if (strcasecmp (name, "ev") == 0)
1943 cmpltr = 7;
1944 flag = 1;
1946 else
1947 as_bad (_("Invalid Logical Instruction Condition."));
1948 *s = c;
1950 opcode |= cmpltr << 13;
1951 INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
1953 /* Handle a unit instruction condition. */
1954 case 'U':
1955 cmpltr = 0;
1956 flag = 0;
1957 if (*s == ',')
1959 s++;
1962 if (strncasecmp (s, "sbz", 3) == 0)
1964 cmpltr = 2;
1965 s += 3;
1967 else if (strncasecmp (s, "shz", 3) == 0)
1969 cmpltr = 3;
1970 s += 3;
1972 else if (strncasecmp (s, "sdc", 3) == 0)
1974 cmpltr = 4;
1975 s += 3;
1977 else if (strncasecmp (s, "sbc", 3) == 0)
1979 cmpltr = 6;
1980 s += 3;
1982 else if (strncasecmp (s, "shc", 3) == 0)
1984 cmpltr = 7;
1985 s += 3;
1987 else if (strncasecmp (s, "tr", 2) == 0)
1989 cmpltr = 0;
1990 flag = 1;
1991 s += 2;
1993 else if (strncasecmp (s, "nbz", 3) == 0)
1995 cmpltr = 2;
1996 flag = 1;
1997 s += 3;
1999 else if (strncasecmp (s, "nhz", 3) == 0)
2001 cmpltr = 3;
2002 flag = 1;
2003 s += 3;
2005 else if (strncasecmp (s, "ndc", 3) == 0)
2007 cmpltr = 4;
2008 flag = 1;
2009 s += 3;
2011 else if (strncasecmp (s, "nbc", 3) == 0)
2013 cmpltr = 6;
2014 flag = 1;
2015 s += 3;
2017 else if (strncasecmp (s, "nhc", 3) == 0)
2019 cmpltr = 7;
2020 flag = 1;
2021 s += 3;
2023 else
2024 as_bad (_("Invalid Logical Instruction Condition."));
2026 opcode |= cmpltr << 13;
2027 INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
2029 /* Handle a shift/extract/deposit condition. */
2030 case '|':
2031 case '>':
2032 cmpltr = 0;
2033 if (*s == ',')
2035 save_s = s++;
2038 name = s;
2039 while (*s != ',' && *s != ' ' && *s != '\t')
2040 s += 1;
2041 c = *s;
2042 *s = 0x00;
2043 if (strcmp (name, "=") == 0)
2044 cmpltr = 1;
2045 else if (strcmp (name, "<") == 0)
2046 cmpltr = 2;
2047 else if (strcasecmp (name, "od") == 0)
2048 cmpltr = 3;
2049 else if (strcasecmp (name, "tr") == 0)
2050 cmpltr = 4;
2051 else if (strcmp (name, "<>") == 0)
2052 cmpltr = 5;
2053 else if (strcmp (name, ">=") == 0)
2054 cmpltr = 6;
2055 else if (strcasecmp (name, "ev") == 0)
2056 cmpltr = 7;
2057 /* Handle movb,n. Put things back the way they were.
2058 This includes moving s back to where it started. */
2059 else if (strcasecmp (name, "n") == 0 && *args == '|')
2061 *s = c;
2062 s = save_s;
2063 continue;
2065 else
2066 as_bad (_("Invalid Shift/Extract/Deposit Condition."));
2067 *s = c;
2069 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
2071 /* Handle bvb and bb conditions. */
2072 case '~':
2073 cmpltr = 0;
2074 if (*s == ',')
2076 s++;
2077 if (strncmp (s, "<", 1) == 0)
2079 cmpltr = 0;
2080 s++;
2082 else if (strncmp (s, ">=", 2) == 0)
2084 cmpltr = 1;
2085 s += 2;
2087 else
2088 as_bad (_("Invalid Bit Branch Condition: %c"), *s);
2090 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 15);
2092 /* Handle a system control completer. */
2093 case 'Z':
2094 if (*s == ',' && (*(s + 1) == 'm' || *(s + 1) == 'M'))
2096 flag = 1;
2097 s += 2;
2099 else
2100 flag = 0;
2102 INSERT_FIELD_AND_CONTINUE (opcode, flag, 5);
2104 /* Handle a nullification completer for branch instructions. */
2105 case 'n':
2106 nullif = pa_parse_nullif (&s);
2107 INSERT_FIELD_AND_CONTINUE (opcode, nullif, 1);
2109 /* Handle a nullification completer for copr and spop insns. */
2110 case 'N':
2111 nullif = pa_parse_nullif (&s);
2112 INSERT_FIELD_AND_CONTINUE (opcode, nullif, 5);
2115 /* Handle a 11 bit immediate at 31. */
2116 case 'i':
2117 the_insn.field_selector = pa_chk_field_selector (&s);
2118 get_expression (s);
2119 s = expr_end;
2120 if (the_insn.exp.X_op == O_constant)
2122 num = evaluate_absolute (&the_insn);
2123 CHECK_FIELD (num, 1023, -1024, 0);
2124 low_sign_unext (num, 11, &num);
2125 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2127 else
2129 if (is_DP_relative (the_insn.exp))
2130 the_insn.reloc = R_HPPA_GOTOFF;
2131 else if (is_PC_relative (the_insn.exp))
2132 the_insn.reloc = R_HPPA_PCREL_CALL;
2133 else
2134 the_insn.reloc = R_HPPA;
2135 the_insn.format = 11;
2136 continue;
2140 /* Handle a 14 bit immediate at 31. */
2141 case 'j':
2142 the_insn.field_selector = pa_chk_field_selector (&s);
2143 get_expression (s);
2144 s = expr_end;
2145 if (the_insn.exp.X_op == O_constant)
2147 num = evaluate_absolute (&the_insn);
2148 CHECK_FIELD (num, 8191, -8192, 0);
2149 low_sign_unext (num, 14, &num);
2150 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2152 else
2154 if (is_DP_relative (the_insn.exp))
2155 the_insn.reloc = R_HPPA_GOTOFF;
2156 else if (is_PC_relative (the_insn.exp))
2157 the_insn.reloc = R_HPPA_PCREL_CALL;
2158 else
2159 the_insn.reloc = R_HPPA;
2160 the_insn.format = 14;
2161 continue;
2164 /* Handle a 21 bit immediate at 31. */
2165 case 'k':
2166 the_insn.field_selector = pa_chk_field_selector (&s);
2167 get_expression (s);
2168 s = expr_end;
2169 if (the_insn.exp.X_op == O_constant)
2171 num = evaluate_absolute (&the_insn);
2172 CHECK_FIELD (num >> 11, 1048575, -1048576, 0);
2173 dis_assemble_21 (num, &num);
2174 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2176 else
2178 if (is_DP_relative (the_insn.exp))
2179 the_insn.reloc = R_HPPA_GOTOFF;
2180 else if (is_PC_relative (the_insn.exp))
2181 the_insn.reloc = R_HPPA_PCREL_CALL;
2182 else
2183 the_insn.reloc = R_HPPA;
2184 the_insn.format = 21;
2185 continue;
2188 /* Handle a 12 bit branch displacement. */
2189 case 'w':
2190 the_insn.field_selector = pa_chk_field_selector (&s);
2191 get_expression (s);
2192 s = expr_end;
2193 the_insn.pcrel = 1;
2194 if (!strcmp (S_GET_NAME (the_insn.exp.X_add_symbol), "L$0\001"))
2196 unsigned int w1, w, result;
2198 num = evaluate_absolute (&the_insn);
2199 if (num % 4)
2201 as_bad (_("Branch to unaligned address"));
2202 break;
2204 CHECK_FIELD (num, 8199, -8184, 0);
2205 sign_unext ((num - 8) >> 2, 12, &result);
2206 dis_assemble_12 (result, &w1, &w);
2207 INSERT_FIELD_AND_CONTINUE (opcode, ((w1 << 2) | w), 0);
2209 else
2211 the_insn.reloc = R_HPPA_PCREL_CALL;
2212 the_insn.format = 12;
2213 the_insn.arg_reloc = last_call_desc.arg_reloc;
2214 memset (&last_call_desc, 0, sizeof (struct call_desc));
2215 s = expr_end;
2216 continue;
2219 /* Handle a 17 bit branch displacement. */
2220 case 'W':
2221 the_insn.field_selector = pa_chk_field_selector (&s);
2222 get_expression (s);
2223 s = expr_end;
2224 the_insn.pcrel = 1;
2225 if (!the_insn.exp.X_add_symbol
2226 || !strcmp (S_GET_NAME (the_insn.exp.X_add_symbol),
2227 "L$0\001"))
2229 unsigned int w2, w1, w, result;
2231 num = evaluate_absolute (&the_insn);
2232 if (num % 4)
2234 as_bad (_("Branch to unaligned address"));
2235 break;
2237 CHECK_FIELD (num, 262143, -262144, 0);
2239 if (the_insn.exp.X_add_symbol)
2240 num -= 8;
2242 sign_unext (num >> 2, 17, &result);
2243 dis_assemble_17 (result, &w1, &w2, &w);
2244 INSERT_FIELD_AND_CONTINUE (opcode,
2245 ((w2 << 2) | (w1 << 16) | w), 0);
2247 else
2249 the_insn.reloc = R_HPPA_PCREL_CALL;
2250 the_insn.format = 17;
2251 the_insn.arg_reloc = last_call_desc.arg_reloc;
2252 memset (&last_call_desc, 0, sizeof (struct call_desc));
2253 continue;
2256 /* Handle an absolute 17 bit branch target. */
2257 case 'z':
2258 the_insn.field_selector = pa_chk_field_selector (&s);
2259 get_expression (s);
2260 s = expr_end;
2261 the_insn.pcrel = 0;
2262 if (!the_insn.exp.X_add_symbol
2263 || !strcmp (S_GET_NAME (the_insn.exp.X_add_symbol),
2264 "L$0\001"))
2266 unsigned int w2, w1, w, result;
2268 num = evaluate_absolute (&the_insn);
2269 if (num % 4)
2271 as_bad (_("Branch to unaligned address"));
2272 break;
2274 CHECK_FIELD (num, 262143, -262144, 0);
2276 if (the_insn.exp.X_add_symbol)
2277 num -= 8;
2279 sign_unext (num >> 2, 17, &result);
2280 dis_assemble_17 (result, &w1, &w2, &w);
2281 INSERT_FIELD_AND_CONTINUE (opcode,
2282 ((w2 << 2) | (w1 << 16) | w), 0);
2284 else
2286 the_insn.reloc = R_HPPA_ABS_CALL;
2287 the_insn.format = 17;
2288 the_insn.arg_reloc = last_call_desc.arg_reloc;
2289 memset (&last_call_desc, 0, sizeof (struct call_desc));
2290 continue;
2293 /* Handle a 5 bit shift count at 26. */
2294 case 'p':
2295 num = pa_get_absolute_expression (&the_insn, &s);
2296 s = expr_end;
2297 CHECK_FIELD (num, 31, 0, 0);
2298 INSERT_FIELD_AND_CONTINUE (opcode, 31 - num, 5);
2300 /* Handle a 5 bit bit position at 26. */
2301 case 'P':
2302 num = pa_get_absolute_expression (&the_insn, &s);
2303 s = expr_end;
2304 CHECK_FIELD (num, 31, 0, 0);
2305 INSERT_FIELD_AND_CONTINUE (opcode, num, 5);
2307 /* Handle a 5 bit immediate at 10. */
2308 case 'Q':
2310 num = pa_get_absolute_expression (&the_insn, &s);
2311 if (the_insn.exp.X_op != O_constant)
2312 break;
2313 s = expr_end;
2314 CHECK_FIELD (num, 31, 0, 0);
2315 INSERT_FIELD_AND_CONTINUE (opcode, num, 21);
2317 /* Handle a 13 bit immediate at 18. */
2318 case 'A':
2319 num = pa_get_absolute_expression (&the_insn, &s);
2320 s = expr_end;
2321 CHECK_FIELD (num, 8191, 0, 0);
2322 INSERT_FIELD_AND_CONTINUE (opcode, num, 13);
2324 /* Handle a 26 bit immediate at 31. */
2325 case 'D':
2326 num = pa_get_absolute_expression (&the_insn, &s);
2327 s = expr_end;
2328 CHECK_FIELD (num, 671108864, 0, 0);
2329 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2331 /* Handle a 3 bit SFU identifier at 25. */
2332 case 'f':
2333 if (*s++ != ',')
2334 as_bad (_("Invalid SFU identifier"));
2335 num = pa_get_absolute_expression (&the_insn, &s);
2336 s = expr_end;
2337 CHECK_FIELD (num, 7, 0, 0);
2338 INSERT_FIELD_AND_CONTINUE (opcode, num, 6);
2340 /* Handle a 20 bit SOP field for spop0. */
2341 case 'O':
2342 num = pa_get_absolute_expression (&the_insn, &s);
2343 s = expr_end;
2344 CHECK_FIELD (num, 1048575, 0, 0);
2345 num = (num & 0x1f) | ((num & 0x000fffe0) << 6);
2346 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2348 /* Handle a 15bit SOP field for spop1. */
2349 case 'o':
2350 num = pa_get_absolute_expression (&the_insn, &s);
2351 s = expr_end;
2352 CHECK_FIELD (num, 32767, 0, 0);
2353 INSERT_FIELD_AND_CONTINUE (opcode, num, 11);
2355 /* Handle a 10bit SOP field for spop3. */
2356 case '0':
2357 num = pa_get_absolute_expression (&the_insn, &s);
2358 s = expr_end;
2359 CHECK_FIELD (num, 1023, 0, 0);
2360 num = (num & 0x1f) | ((num & 0x000003e0) << 6);
2361 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2363 /* Handle a 15 bit SOP field for spop2. */
2364 case '1':
2365 num = pa_get_absolute_expression (&the_insn, &s);
2366 s = expr_end;
2367 CHECK_FIELD (num, 32767, 0, 0);
2368 num = (num & 0x1f) | ((num & 0x00007fe0) << 6);
2369 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2371 /* Handle a 3-bit co-processor ID field. */
2372 case 'u':
2373 if (*s++ != ',')
2374 as_bad (_("Invalid COPR identifier"));
2375 num = pa_get_absolute_expression (&the_insn, &s);
2376 s = expr_end;
2377 CHECK_FIELD (num, 7, 0, 0);
2378 INSERT_FIELD_AND_CONTINUE (opcode, num, 6);
2380 /* Handle a 22bit SOP field for copr. */
2381 case '2':
2382 num = pa_get_absolute_expression (&the_insn, &s);
2383 s = expr_end;
2384 CHECK_FIELD (num, 4194303, 0, 0);
2385 num = (num & 0x1f) | ((num & 0x003fffe0) << 4);
2386 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2389 /* Handle a source FP operand format completer. */
2390 case 'F':
2391 flag = pa_parse_fp_format (&s);
2392 the_insn.fpof1 = flag;
2393 INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
2395 /* Handle a destination FP operand format completer. */
2396 case 'G':
2397 /* pa_parse_format needs the ',' prefix. */
2398 s--;
2399 flag = pa_parse_fp_format (&s);
2400 the_insn.fpof2 = flag;
2401 INSERT_FIELD_AND_CONTINUE (opcode, flag, 13);
2403 /* Handle FP compare conditions. */
2404 case 'M':
2405 cond = pa_parse_fp_cmp_cond (&s);
2406 INSERT_FIELD_AND_CONTINUE (opcode, cond, 0);
2408 /* Handle L/R register halves like 't'. */
2409 case 'v':
2411 struct pa_11_fp_reg_struct result;
2413 pa_parse_number (&s, &result);
2414 CHECK_FIELD (result.number_part, 31, 0, 0);
2415 opcode |= result.number_part;
2417 /* 0x30 opcodes are FP arithmetic operation opcodes
2418 and need to be turned into 0x38 opcodes. This
2419 is not necessary for loads/stores. */
2420 if (need_pa11_opcode (&the_insn, &result)
2421 && ((opcode & 0xfc000000) == 0x30000000))
2422 opcode |= 1 << 27;
2424 INSERT_FIELD_AND_CONTINUE (opcode, result.l_r_select & 1, 6);
2427 /* Handle L/R register halves like 'b'. */
2428 case 'E':
2430 struct pa_11_fp_reg_struct result;
2432 pa_parse_number (&s, &result);
2433 CHECK_FIELD (result.number_part, 31, 0, 0);
2434 opcode |= result.number_part << 21;
2435 if (need_pa11_opcode (&the_insn, &result))
2437 opcode |= (result.l_r_select & 1) << 7;
2438 opcode |= 1 << 27;
2440 continue;
2443 /* Handle L/R register halves like 'b'. */
2444 case '3':
2446 struct pa_11_fp_reg_struct result;
2447 int regnum;
2449 pa_parse_number (&s, &result);
2450 CHECK_FIELD (result.number_part, 31, 0, 0);
2451 opcode |= (result.number_part & 0x1c) << 11;
2452 opcode |= (result.number_part & 0x3) << 9;
2453 opcode |= (result.l_r_select & 1) << 8;
2454 continue;
2457 /* Handle L/R register halves like 'x'. */
2458 case 'e':
2460 struct pa_11_fp_reg_struct result;
2462 pa_parse_number (&s, &result);
2463 CHECK_FIELD (result.number_part, 31, 0, 0);
2464 opcode |= (result.number_part & 0x1f) << 16;
2465 if (need_pa11_opcode (&the_insn, &result))
2467 opcode |= (result.l_r_select & 1) << 1;
2469 continue;
2472 /* Handle L/R register halves like 'x'. */
2473 case 'X':
2475 struct pa_11_fp_reg_struct result;
2477 pa_parse_number (&s, &result);
2478 CHECK_FIELD (result.number_part, 31, 0, 0);
2479 opcode |= (result.number_part & 0x1f) << 16;
2480 if (need_pa11_opcode (&the_insn, &result))
2482 opcode |= (result.l_r_select & 1) << 12;
2483 opcode |= 1 << 27;
2485 continue;
2488 /* Handle a 5 bit register field at 10. */
2489 case '4':
2491 struct pa_11_fp_reg_struct result;
2493 pa_parse_number (&s, &result);
2494 CHECK_FIELD (result.number_part, 31, 0, 0);
2495 if (the_insn.fpof1 == SGL)
2497 if (result.number_part < 16)
2499 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
2500 break;
2503 result.number_part &= 0xF;
2504 result.number_part |= (result.l_r_select & 1) << 4;
2506 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 21);
2509 /* Handle a 5 bit register field at 15. */
2510 case '6':
2512 struct pa_11_fp_reg_struct result;
2514 pa_parse_number (&s, &result);
2515 CHECK_FIELD (result.number_part, 31, 0, 0);
2516 if (the_insn.fpof1 == SGL)
2518 if (result.number_part < 16)
2520 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
2521 break;
2523 result.number_part &= 0xF;
2524 result.number_part |= (result.l_r_select & 1) << 4;
2526 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 16);
2529 /* Handle a 5 bit register field at 31. */
2530 case '7':
2532 struct pa_11_fp_reg_struct result;
2534 pa_parse_number (&s, &result);
2535 CHECK_FIELD (result.number_part, 31, 0, 0);
2536 if (the_insn.fpof1 == SGL)
2538 if (result.number_part < 16)
2540 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
2541 break;
2543 result.number_part &= 0xF;
2544 result.number_part |= (result.l_r_select & 1) << 4;
2546 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 0);
2549 /* Handle a 5 bit register field at 20. */
2550 case '8':
2552 struct pa_11_fp_reg_struct result;
2554 pa_parse_number (&s, &result);
2555 CHECK_FIELD (result.number_part, 31, 0, 0);
2556 if (the_insn.fpof1 == SGL)
2558 if (result.number_part < 16)
2560 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
2561 break;
2563 result.number_part &= 0xF;
2564 result.number_part |= (result.l_r_select & 1) << 4;
2566 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 11);
2569 /* Handle a 5 bit register field at 25. */
2570 case '9':
2572 struct pa_11_fp_reg_struct result;
2574 pa_parse_number (&s, &result);
2575 CHECK_FIELD (result.number_part, 31, 0, 0);
2576 if (the_insn.fpof1 == SGL)
2578 if (result.number_part < 16)
2580 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
2581 break;
2583 result.number_part &= 0xF;
2584 result.number_part |= (result.l_r_select & 1) << 4;
2586 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 6);
2589 /* Handle a floating point operand format at 26.
2590 Only allows single and double precision. */
2591 case 'H':
2592 flag = pa_parse_fp_format (&s);
2593 switch (flag)
2595 case SGL:
2596 opcode |= 0x20;
2597 case DBL:
2598 the_insn.fpof1 = flag;
2599 continue;
2601 case QUAD:
2602 case ILLEGAL_FMT:
2603 default:
2604 as_bad (_("Invalid Floating Point Operand Format."));
2606 break;
2608 default:
2609 abort ();
2611 break;
2614 failed:
2615 /* Check if the args matched. */
2616 if (match == FALSE)
2618 if (&insn[1] - pa_opcodes < (int) NUMOPCODES
2619 && !strcmp (insn->name, insn[1].name))
2621 ++insn;
2622 s = argstart;
2623 continue;
2625 else
2627 as_bad (_("Invalid operands %s"), error_message);
2628 return;
2631 break;
2634 the_insn.opcode = opcode;
2637 /* Turn a string in input_line_pointer into a floating point constant of type
2638 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2639 emitted is stored in *sizeP . An error message or NULL is returned. */
2641 #define MAX_LITTLENUMS 6
2643 char *
2644 md_atof (type, litP, sizeP)
2645 char type;
2646 char *litP;
2647 int *sizeP;
2649 int prec;
2650 LITTLENUM_TYPE words[MAX_LITTLENUMS];
2651 LITTLENUM_TYPE *wordP;
2652 char *t;
2654 switch (type)
2657 case 'f':
2658 case 'F':
2659 case 's':
2660 case 'S':
2661 prec = 2;
2662 break;
2664 case 'd':
2665 case 'D':
2666 case 'r':
2667 case 'R':
2668 prec = 4;
2669 break;
2671 case 'x':
2672 case 'X':
2673 prec = 6;
2674 break;
2676 case 'p':
2677 case 'P':
2678 prec = 6;
2679 break;
2681 default:
2682 *sizeP = 0;
2683 return _("Bad call to MD_ATOF()");
2685 t = atof_ieee (input_line_pointer, type, words);
2686 if (t)
2687 input_line_pointer = t;
2688 *sizeP = prec * sizeof (LITTLENUM_TYPE);
2689 for (wordP = words; prec--;)
2691 md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE));
2692 litP += sizeof (LITTLENUM_TYPE);
2694 return NULL;
2697 /* Write out big-endian. */
2699 void
2700 md_number_to_chars (buf, val, n)
2701 char *buf;
2702 valueT val;
2703 int n;
2705 number_to_chars_bigendian (buf, val, n);
2708 /* Translate internal representation of relocation info to BFD target
2709 format. */
2711 arelent **
2712 tc_gen_reloc (section, fixp)
2713 asection *section;
2714 fixS *fixp;
2716 arelent *reloc;
2717 struct hppa_fix_struct *hppa_fixp;
2718 bfd_reloc_code_real_type code;
2719 static arelent *no_relocs = NULL;
2720 arelent **relocs;
2721 bfd_reloc_code_real_type **codes;
2722 int n_relocs;
2723 int i;
2725 hppa_fixp = (struct hppa_fix_struct *) fixp->tc_fix_data;
2726 if (fixp->fx_addsy == 0)
2727 return &no_relocs;
2728 assert (hppa_fixp != 0);
2729 assert (section != 0);
2731 reloc = (arelent *) xmalloc (sizeof (arelent));
2733 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
2734 codes = (bfd_reloc_code_real_type **) hppa_gen_reloc_type (stdoutput,
2735 fixp->fx_r_type,
2736 hppa_fixp->fx_r_format,
2737 hppa_fixp->fx_r_field,
2738 fixp->fx_subsy != NULL,
2739 fixp->fx_addsy->bsym);
2741 if (codes == NULL)
2742 abort ();
2744 for (n_relocs = 0; codes[n_relocs]; n_relocs++)
2747 relocs = (arelent **) xmalloc (sizeof (arelent *) * n_relocs + 1);
2748 reloc = (arelent *) xmalloc (sizeof (arelent) * n_relocs);
2749 for (i = 0; i < n_relocs; i++)
2750 relocs[i] = &reloc[i];
2752 relocs[n_relocs] = NULL;
2754 #ifdef OBJ_ELF
2755 switch (fixp->fx_r_type)
2757 default:
2758 assert (n_relocs == 1);
2760 code = *codes[0];
2762 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
2763 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
2764 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2765 reloc->addend = 0; /* default */
2767 assert (reloc->howto && code == reloc->howto->type);
2769 /* Now, do any processing that is dependent on the relocation type. */
2770 switch (code)
2772 case R_PARISC_DLTREL21L:
2773 case R_PARISC_DLTREL14R:
2774 case R_PARISC_DLTREL14F:
2775 case R_PARISC_PLABEL32:
2776 case R_PARISC_PLABEL21L:
2777 case R_PARISC_PLABEL14R:
2778 /* For plabel relocations, the addend of the
2779 relocation should be either 0 (no static link) or 2
2780 (static link required).
2782 FIXME: We always assume no static link!
2784 We also slam a zero addend into the DLT relative relocs;
2785 it doesn't make a lot of sense to use any addend since
2786 it gets you a different (eg unknown) DLT entry. */
2787 reloc->addend = 0;
2788 break;
2790 case R_PARISC_PCREL21L:
2791 case R_PARISC_PCREL17R:
2792 case R_PARISC_PCREL17F:
2793 case R_PARISC_PCREL17C:
2794 case R_PARISC_PCREL14R:
2795 case R_PARISC_PCREL14F:
2796 /* The constant is stored in the instruction. */
2797 reloc->addend = HPPA_R_ADDEND (hppa_fixp->fx_arg_reloc, 0);
2798 break;
2799 default:
2800 reloc->addend = fixp->fx_offset;
2801 break;
2803 break;
2805 #else /* OBJ_SOM */
2807 /* Walk over reach relocation returned by the BFD backend. */
2808 for (i = 0; i < n_relocs; i++)
2810 code = *codes[i];
2812 relocs[i]->sym_ptr_ptr = &fixp->fx_addsy->bsym;
2813 relocs[i]->howto = bfd_reloc_type_lookup (stdoutput, code);
2814 relocs[i]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2816 switch (code)
2818 case R_COMP2:
2819 /* The only time we ever use a R_COMP2 fixup is for the difference
2820 of two symbols. With that in mind we fill in all four
2821 relocs now and break out of the loop. */
2822 assert (i == 1);
2823 relocs[0]->sym_ptr_ptr = (asymbol **) &bfd_abs_symbol;
2824 relocs[0]->howto = bfd_reloc_type_lookup (stdoutput, *codes[0]);
2825 relocs[0]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2826 relocs[0]->addend = 0;
2827 relocs[1]->sym_ptr_ptr = &fixp->fx_addsy->bsym;
2828 relocs[1]->howto = bfd_reloc_type_lookup (stdoutput, *codes[1]);
2829 relocs[1]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2830 relocs[1]->addend = 0;
2831 relocs[2]->sym_ptr_ptr = &fixp->fx_subsy->bsym;
2832 relocs[2]->howto = bfd_reloc_type_lookup (stdoutput, *codes[2]);
2833 relocs[2]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2834 relocs[2]->addend = 0;
2835 relocs[3]->sym_ptr_ptr = (asymbol **) &bfd_abs_symbol;
2836 relocs[3]->howto = bfd_reloc_type_lookup (stdoutput, *codes[3]);
2837 relocs[3]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2838 relocs[3]->addend = 0;
2839 relocs[4]->sym_ptr_ptr = (asymbol **) &bfd_abs_symbol;
2840 relocs[4]->howto = bfd_reloc_type_lookup (stdoutput, *codes[4]);
2841 relocs[4]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2842 relocs[4]->addend = 0;
2843 goto done;
2844 case R_PCREL_CALL:
2845 case R_ABS_CALL:
2846 relocs[i]->addend = HPPA_R_ADDEND (hppa_fixp->fx_arg_reloc, 0);
2847 break;
2849 case R_DLT_REL:
2850 case R_DATA_PLABEL:
2851 case R_CODE_PLABEL:
2852 /* For plabel relocations, the addend of the
2853 relocation should be either 0 (no static link) or 2
2854 (static link required).
2856 FIXME: We always assume no static link!
2858 We also slam a zero addend into the DLT relative relocs;
2859 it doesn't make a lot of sense to use any addend since
2860 it gets you a different (eg unknown) DLT entry. */
2861 relocs[i]->addend = 0;
2862 break;
2864 case R_N_MODE:
2865 case R_S_MODE:
2866 case R_D_MODE:
2867 case R_R_MODE:
2868 case R_FSEL:
2869 case R_LSEL:
2870 case R_RSEL:
2871 case R_BEGIN_BRTAB:
2872 case R_END_BRTAB:
2873 case R_BEGIN_TRY:
2874 case R_N0SEL:
2875 case R_N1SEL:
2876 /* There is no symbol or addend associated with these fixups. */
2877 relocs[i]->sym_ptr_ptr = &dummy_symbol->bsym;
2878 relocs[i]->addend = 0;
2879 break;
2881 case R_END_TRY:
2882 case R_ENTRY:
2883 case R_EXIT:
2884 /* There is no symbol associated with these fixups. */
2885 relocs[i]->sym_ptr_ptr = &dummy_symbol->bsym;
2886 relocs[i]->addend = fixp->fx_offset;
2887 break;
2889 default:
2890 relocs[i]->addend = fixp->fx_offset;
2894 done:
2895 #endif
2897 return relocs;
2900 /* Process any machine dependent frag types. */
2902 void
2903 md_convert_frag (abfd, sec, fragP)
2904 register bfd *abfd;
2905 register asection *sec;
2906 register fragS *fragP;
2908 unsigned int address;
2910 if (fragP->fr_type == rs_machine_dependent)
2912 switch ((int) fragP->fr_subtype)
2914 case 0:
2915 fragP->fr_type = rs_fill;
2916 know (fragP->fr_var == 1);
2917 know (fragP->fr_next);
2918 address = fragP->fr_address + fragP->fr_fix;
2919 if (address % fragP->fr_offset)
2921 fragP->fr_offset =
2922 fragP->fr_next->fr_address
2923 - fragP->fr_address
2924 - fragP->fr_fix;
2926 else
2927 fragP->fr_offset = 0;
2928 break;
2933 /* Round up a section size to the appropriate boundary. */
2935 valueT
2936 md_section_align (segment, size)
2937 asection *segment;
2938 valueT size;
2940 int align = bfd_get_section_alignment (stdoutput, segment);
2941 int align2 = (1 << align) - 1;
2943 return (size + align2) & ~align2;
2946 /* Return the approximate size of a frag before relaxation has occurred. */
2948 md_estimate_size_before_relax (fragP, segment)
2949 register fragS *fragP;
2950 asection *segment;
2952 int size;
2954 size = 0;
2956 while ((fragP->fr_fix + size) % fragP->fr_offset)
2957 size++;
2959 return size;
2962 CONST char *md_shortopts = "";
2963 struct option md_longopts[] = {
2964 {NULL, no_argument, NULL, 0}
2966 size_t md_longopts_size = sizeof(md_longopts);
2969 md_parse_option (c, arg)
2970 int c;
2971 char *arg;
2973 return 0;
2976 void
2977 md_show_usage (stream)
2978 FILE *stream;
2982 /* We have no need to default values of symbols. */
2984 symbolS *
2985 md_undefined_symbol (name)
2986 char *name;
2988 return 0;
2991 /* Apply a fixup to an instruction. */
2994 md_apply_fix (fixP, valp)
2995 fixS *fixP;
2996 valueT *valp;
2998 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
2999 struct hppa_fix_struct *hppa_fixP;
3000 long new_val, result = 0;
3001 unsigned int w1, w2, w, resulti;
3003 hppa_fixP = (struct hppa_fix_struct *) fixP->tc_fix_data;
3004 /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
3005 never be "applied" (they are just markers). Likewise for
3006 R_HPPA_BEGIN_BRTAB and R_HPPA_END_BRTAB. */
3007 #ifdef OBJ_SOM
3008 if (fixP->fx_r_type == R_HPPA_ENTRY
3009 || fixP->fx_r_type == R_HPPA_EXIT
3010 || fixP->fx_r_type == R_HPPA_BEGIN_BRTAB
3011 || fixP->fx_r_type == R_HPPA_END_BRTAB
3012 || fixP->fx_r_type == R_HPPA_BEGIN_TRY)
3013 return 1;
3015 /* Disgusting. We must set fx_offset ourselves -- R_HPPA_END_TRY
3016 fixups are considered not adjustable, which in turn causes
3017 adjust_reloc_syms to not set fx_offset. Ugh. */
3018 if (fixP->fx_r_type == R_HPPA_END_TRY)
3020 fixP->fx_offset = *valp;
3021 return 1;
3023 #endif
3025 /* There should have been an HPPA specific fixup associated
3026 with the GAS fixup. */
3027 if (hppa_fixP)
3029 unsigned long buf_wd = bfd_get_32 (stdoutput, buf);
3030 unsigned char fmt = bfd_hppa_insn2fmt (buf_wd);
3032 /* If there is a symbol associated with this fixup, then it's something
3033 which will need a SOM relocation (except for some PC-relative relocs).
3034 In such cases we should treat the "val" or "addend" as zero since it
3035 will be added in as needed from fx_offset in tc_gen_reloc. */
3036 if ((fixP->fx_addsy != NULL
3037 || fixP->fx_r_type == R_HPPA_NONE)
3038 #ifdef OBJ_SOM
3039 && fmt != 32
3040 #endif
3042 new_val = ((fmt == 12 || fmt == 17) ? 8 : 0);
3043 #ifdef OBJ_SOM
3044 /* These field selectors imply that we do not want an addend. */
3045 else if (hppa_fixP->fx_r_field == e_psel
3046 || hppa_fixP->fx_r_field == e_rpsel
3047 || hppa_fixP->fx_r_field == e_lpsel
3048 || hppa_fixP->fx_r_field == e_tsel
3049 || hppa_fixP->fx_r_field == e_rtsel
3050 || hppa_fixP->fx_r_field == e_ltsel)
3051 new_val = ((fmt == 12 || fmt == 17) ? 8 : 0);
3052 /* This is truely disgusting. The machine independent code blindly
3053 adds in the value of the symbol being relocated against. Damn! */
3054 else if (fmt == 32
3055 && fixP->fx_addsy != NULL
3056 && S_GET_SEGMENT (fixP->fx_addsy) != bfd_com_section_ptr)
3057 new_val = hppa_field_adjust (*valp - S_GET_VALUE (fixP->fx_addsy),
3058 0, hppa_fixP->fx_r_field);
3059 #endif
3060 else
3061 new_val = hppa_field_adjust (*valp, 0, hppa_fixP->fx_r_field);
3063 /* Handle pc-relative exceptions from above. */
3064 #define arg_reloc_stub_needed(CALLER, CALLEE) \
3065 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
3066 if ((fmt == 12 || fmt == 17)
3067 && fixP->fx_addsy
3068 && fixP->fx_pcrel
3069 && !arg_reloc_stub_needed ((long) ((obj_symbol_type *)
3070 fixP->fx_addsy->bsym)->tc_data.ap.hppa_arg_reloc,
3071 hppa_fixP->fx_arg_reloc)
3072 && ((int)(*valp) > -262144 && (int)(*valp) < 262143)
3073 && S_GET_SEGMENT (fixP->fx_addsy) == hppa_fixP->segment
3074 && !(fixP->fx_subsy
3075 && S_GET_SEGMENT (fixP->fx_subsy) != hppa_fixP->segment))
3077 new_val = hppa_field_adjust (*valp, 0, hppa_fixP->fx_r_field);
3078 #undef arg_reloc_stub_needed
3080 switch (fmt)
3082 /* Handle all opcodes with the 'j' operand type. */
3083 case 14:
3084 CHECK_FIELD (new_val, 8191, -8192, 0);
3086 /* Mask off 14 bits to be changed. */
3087 bfd_put_32 (stdoutput,
3088 bfd_get_32 (stdoutput, buf) & 0xffffc000,
3089 buf);
3090 low_sign_unext (new_val, 14, &resulti);
3091 result = resulti;
3092 break;
3094 /* Handle all opcodes with the 'k' operand type. */
3095 case 21:
3096 CHECK_FIELD (new_val, 2097152, 0, 0);
3098 /* Mask off 21 bits to be changed. */
3099 bfd_put_32 (stdoutput,
3100 bfd_get_32 (stdoutput, buf) & 0xffe00000,
3101 buf);
3102 dis_assemble_21 (new_val, &resulti);
3103 result = resulti;
3104 break;
3106 /* Handle all the opcodes with the 'i' operand type. */
3107 case 11:
3108 CHECK_FIELD (new_val, 1023, -1023, 0);
3110 /* Mask off 11 bits to be changed. */
3111 bfd_put_32 (stdoutput,
3112 bfd_get_32 (stdoutput, buf) & 0xffff800,
3113 buf);
3114 low_sign_unext (new_val, 11, &resulti);
3115 result = resulti;
3116 break;
3118 /* Handle all the opcodes with the 'w' operand type. */
3119 case 12:
3120 CHECK_FIELD (new_val, 8199, -8184, 0);
3122 /* Mask off 11 bits to be changed. */
3123 sign_unext ((new_val - 8) >> 2, 12, &resulti);
3124 bfd_put_32 (stdoutput,
3125 bfd_get_32 (stdoutput, buf) & 0xffffe002,
3126 buf);
3128 dis_assemble_12 (resulti, &w1, &w);
3129 result = ((w1 << 2) | w);
3130 break;
3132 /* Handle some of the opcodes with the 'W' operand type. */
3133 case 17:
3135 int distance = *valp;
3137 CHECK_FIELD (new_val, 262143, -262144, 0);
3139 /* If this is an absolute branch (ie no link) with an out of
3140 range target, then we want to complain. */
3141 if (fixP->fx_r_type == R_HPPA_PCREL_CALL
3142 && (distance > 262143 || distance < -262144)
3143 && (bfd_get_32 (stdoutput, buf) & 0xffe00000) == 0xe8000000)
3144 CHECK_FIELD (distance, 262143, -262144, 0);
3146 /* Mask off 17 bits to be changed. */
3147 bfd_put_32 (stdoutput,
3148 bfd_get_32 (stdoutput, buf) & 0xffe0e002,
3149 buf);
3150 sign_unext ((new_val - 8) >> 2, 17, &resulti);
3151 dis_assemble_17 (resulti, &w1, &w2, &w);
3152 result = ((w2 << 2) | (w1 << 16) | w);
3153 break;
3156 case 32:
3157 result = 0;
3158 bfd_put_32 (stdoutput, new_val, buf);
3159 break;
3161 default:
3162 as_bad (_("Unknown relocation encountered in md_apply_fix."));
3163 return 0;
3166 /* Insert the relocation. */
3167 bfd_put_32 (stdoutput, bfd_get_32 (stdoutput, buf) | result, buf);
3168 return 1;
3170 else
3172 printf (_("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n"),
3173 (unsigned int) fixP, fixP->fx_r_type);
3174 return 0;
3178 /* Exactly what point is a PC-relative offset relative TO?
3179 On the PA, they're relative to the address of the offset. */
3181 long
3182 md_pcrel_from (fixP)
3183 fixS *fixP;
3185 return fixP->fx_where + fixP->fx_frag->fr_address;
3188 /* Return nonzero if the input line pointer is at the end of
3189 a statement. */
3191 static int
3192 is_end_of_statement ()
3194 return ((*input_line_pointer == '\n')
3195 || (*input_line_pointer == ';')
3196 || (*input_line_pointer == '!'));
3199 /* Read a number from S. The number might come in one of many forms,
3200 the most common will be a hex or decimal constant, but it could be
3201 a pre-defined register (Yuk!), or an absolute symbol.
3203 Return a number or -1 for failure.
3205 When parsing PA-89 FP register numbers RESULT will be
3206 the address of a structure to return information about
3207 L/R half of FP registers, store results there as appropriate.
3209 pa_parse_number can not handle negative constants and will fail
3210 horribly if it is passed such a constant. */
3212 static int
3213 pa_parse_number (s, result)
3214 char **s;
3215 struct pa_11_fp_reg_struct *result;
3217 int num;
3218 char *name;
3219 char c;
3220 symbolS *sym;
3221 int status;
3222 char *p = *s;
3224 /* Skip whitespace before the number. */
3225 while (*p == ' ' || *p == '\t')
3226 p = p + 1;
3228 /* Store info in RESULT if requested by caller. */
3229 if (result)
3231 result->number_part = -1;
3232 result->l_r_select = -1;
3234 num = -1;
3236 if (isdigit (*p))
3238 /* Looks like a number. */
3239 num = 0;
3241 if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X'))
3243 /* The number is specified in hex. */
3244 p += 2;
3245 while (isdigit (*p) || ((*p >= 'a') && (*p <= 'f'))
3246 || ((*p >= 'A') && (*p <= 'F')))
3248 if (isdigit (*p))
3249 num = num * 16 + *p - '0';
3250 else if (*p >= 'a' && *p <= 'f')
3251 num = num * 16 + *p - 'a' + 10;
3252 else
3253 num = num * 16 + *p - 'A' + 10;
3254 ++p;
3257 else
3259 /* The number is specified in decimal. */
3260 while (isdigit (*p))
3262 num = num * 10 + *p - '0';
3263 ++p;
3267 /* Store info in RESULT if requested by the caller. */
3268 if (result)
3270 result->number_part = num;
3272 if (IS_R_SELECT (p))
3274 result->l_r_select = 1;
3275 ++p;
3277 else if (IS_L_SELECT (p))
3279 result->l_r_select = 0;
3280 ++p;
3282 else
3283 result->l_r_select = 0;
3286 else if (*p == '%')
3288 /* The number might be a predefined register. */
3289 num = 0;
3290 name = p;
3291 p++;
3292 c = *p;
3293 /* Tege hack: Special case for general registers as the general
3294 code makes a binary search with case translation, and is VERY
3295 slow. */
3296 if (c == 'r')
3298 p++;
3299 if (*p == 'e' && *(p + 1) == 't'
3300 && (*(p + 2) == '0' || *(p + 2) == '1'))
3302 p += 2;
3303 num = *p - '0' + 28;
3304 p++;
3306 else if (*p == 'p')
3308 num = 2;
3309 p++;
3311 else if (!isdigit (*p))
3313 if (print_errors)
3314 as_bad (_("Undefined register: '%s'."), name);
3315 num = -1;
3317 else
3320 num = num * 10 + *p++ - '0';
3321 while (isdigit (*p));
3324 else
3326 /* Do a normal register search. */
3327 while (is_part_of_name (c))
3329 p = p + 1;
3330 c = *p;
3332 *p = 0;
3333 status = reg_name_search (name);
3334 if (status >= 0)
3335 num = status;
3336 else
3338 if (print_errors)
3339 as_bad (_("Undefined register: '%s'."), name);
3340 num = -1;
3342 *p = c;
3345 /* Store info in RESULT if requested by caller. */
3346 if (result)
3348 result->number_part = num;
3349 if (IS_R_SELECT (p - 1))
3350 result->l_r_select = 1;
3351 else if (IS_L_SELECT (p - 1))
3352 result->l_r_select = 0;
3353 else
3354 result->l_r_select = 0;
3357 else
3359 /* And finally, it could be a symbol in the absolute section which
3360 is effectively a constant. */
3361 num = 0;
3362 name = p;
3363 c = *p;
3364 while (is_part_of_name (c))
3366 p = p + 1;
3367 c = *p;
3369 *p = 0;
3370 if ((sym = symbol_find (name)) != NULL)
3372 if (S_GET_SEGMENT (sym) == &bfd_abs_section)
3373 num = S_GET_VALUE (sym);
3374 else
3376 if (print_errors)
3377 as_bad (_("Non-absolute symbol: '%s'."), name);
3378 num = -1;
3381 else
3383 /* There is where we'd come for an undefined symbol
3384 or for an empty string. For an empty string we
3385 will return zero. That's a concession made for
3386 compatability with the braindamaged HP assemblers. */
3387 if (*name == 0)
3388 num = 0;
3389 else
3391 if (print_errors)
3392 as_bad (_("Undefined absolute constant: '%s'."), name);
3393 num = -1;
3396 *p = c;
3398 /* Store info in RESULT if requested by caller. */
3399 if (result)
3401 result->number_part = num;
3402 if (IS_R_SELECT (p - 1))
3403 result->l_r_select = 1;
3404 else if (IS_L_SELECT (p - 1))
3405 result->l_r_select = 0;
3406 else
3407 result->l_r_select = 0;
3411 *s = p;
3412 return num;
3415 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
3417 /* Given NAME, find the register number associated with that name, return
3418 the integer value associated with the given name or -1 on failure. */
3420 static int
3421 reg_name_search (name)
3422 char *name;
3424 int middle, low, high;
3425 int cmp;
3427 low = 0;
3428 high = REG_NAME_CNT - 1;
3432 middle = (low + high) / 2;
3433 cmp = strcasecmp (name, pre_defined_registers[middle].name);
3434 if (cmp < 0)
3435 high = middle - 1;
3436 else if (cmp > 0)
3437 low = middle + 1;
3438 else
3439 return pre_defined_registers[middle].value;
3441 while (low <= high);
3443 return -1;
3447 /* Return nonzero if the given INSN and L/R information will require
3448 a new PA-1.1 opcode. */
3450 static int
3451 need_pa11_opcode (insn, result)
3452 struct pa_it *insn;
3453 struct pa_11_fp_reg_struct *result;
3455 if (result->l_r_select == 1 && !(insn->fpof1 == DBL && insn->fpof2 == DBL))
3457 /* If this instruction is specific to a particular architecture,
3458 then set a new architecture. */
3459 if (bfd_get_mach (stdoutput) < pa11)
3461 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, pa11))
3462 as_warn (_("could not update architecture and machine"));
3464 return TRUE;
3466 else
3467 return FALSE;
3470 /* Parse a condition for a fcmp instruction. Return the numerical
3471 code associated with the condition. */
3473 static int
3474 pa_parse_fp_cmp_cond (s)
3475 char **s;
3477 int cond, i;
3479 cond = 0;
3481 for (i = 0; i < 32; i++)
3483 if (strncasecmp (*s, fp_cond_map[i].string,
3484 strlen (fp_cond_map[i].string)) == 0)
3486 cond = fp_cond_map[i].cond;
3487 *s += strlen (fp_cond_map[i].string);
3488 /* If not a complete match, back up the input string and
3489 report an error. */
3490 if (**s != ' ' && **s != '\t')
3492 *s -= strlen (fp_cond_map[i].string);
3493 break;
3495 while (**s == ' ' || **s == '\t')
3496 *s = *s + 1;
3497 return cond;
3501 as_bad (_("Invalid FP Compare Condition: %s"), *s);
3503 /* Advance over the bogus completer. */
3504 while (**s != ',' && **s != ' ' && **s != '\t')
3505 *s += 1;
3507 return 0;
3511 /* Parse an FP operand format completer returning the completer
3512 type. */
3514 static fp_operand_format
3515 pa_parse_fp_format (s)
3516 char **s;
3518 int format;
3520 format = SGL;
3521 if (**s == ',')
3523 *s += 1;
3524 if (strncasecmp (*s, "sgl", 3) == 0)
3526 format = SGL;
3527 *s += 4;
3529 else if (strncasecmp (*s, "dbl", 3) == 0)
3531 format = DBL;
3532 *s += 4;
3534 else if (strncasecmp (*s, "quad", 4) == 0)
3536 format = QUAD;
3537 *s += 5;
3539 else
3541 format = ILLEGAL_FMT;
3542 as_bad (_("Invalid FP Operand Format: %3s"), *s);
3546 return format;
3549 /* Convert from a selector string into a selector type. */
3551 static int
3552 pa_chk_field_selector (str)
3553 char **str;
3555 int middle, low, high;
3556 int cmp;
3557 char name[4];
3559 /* Read past any whitespace. */
3560 /* FIXME: should we read past newlines and formfeeds??? */
3561 while (**str == ' ' || **str == '\t' || **str == '\n' || **str == '\f')
3562 *str = *str + 1;
3564 if ((*str)[1] == '\'' || (*str)[1] == '%')
3565 name[0] = tolower ((*str)[0]),
3566 name[1] = 0;
3567 else if ((*str)[2] == '\'' || (*str)[2] == '%')
3568 name[0] = tolower ((*str)[0]),
3569 name[1] = tolower ((*str)[1]),
3570 name[2] = 0;
3571 #ifdef OBJ_SOM
3572 else if ((*str)[3] == '\'' || (*str)[3] == '%')
3573 name[0] = tolower ((*str)[0]),
3574 name[1] = tolower ((*str)[1]),
3575 name[2] = tolower ((*str)[2]),
3576 name[3] = 0;
3577 #endif
3578 else
3579 return e_fsel;
3581 low = 0;
3582 high = sizeof (selector_table) / sizeof (struct selector_entry) - 1;
3586 middle = (low + high) / 2;
3587 cmp = strcmp (name, selector_table[middle].prefix);
3588 if (cmp < 0)
3589 high = middle - 1;
3590 else if (cmp > 0)
3591 low = middle + 1;
3592 else
3594 *str += strlen (name) + 1;
3595 #ifndef OBJ_SOM
3596 if (selector_table[middle].field_selector == e_nsel)
3597 return e_fsel;
3598 #endif
3599 return selector_table[middle].field_selector;
3602 while (low <= high);
3604 return e_fsel;
3607 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
3609 static int
3610 get_expression (str)
3611 char *str;
3613 char *save_in;
3614 asection *seg;
3616 save_in = input_line_pointer;
3617 input_line_pointer = str;
3618 seg = expression (&the_insn.exp);
3619 if (!(seg == absolute_section
3620 || seg == undefined_section
3621 || SEG_NORMAL (seg)))
3623 as_warn (_("Bad segment in expression."));
3624 expr_end = input_line_pointer;
3625 input_line_pointer = save_in;
3626 return 1;
3628 expr_end = input_line_pointer;
3629 input_line_pointer = save_in;
3630 return 0;
3633 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
3634 static int
3635 pa_get_absolute_expression (insn, strp)
3636 struct pa_it *insn;
3637 char **strp;
3639 char *save_in;
3641 insn->field_selector = pa_chk_field_selector (strp);
3642 save_in = input_line_pointer;
3643 input_line_pointer = *strp;
3644 expression (&insn->exp);
3645 /* This is not perfect, but is a huge improvement over doing nothing.
3647 The PA assembly syntax is ambigious in a variety of ways. Consider
3648 this string "4 %r5" Is that the number 4 followed by the register
3649 r5, or is that 4 MOD 5?
3651 If we get a modulo expresion When looking for an absolute, we try
3652 again cutting off the input string at the first whitespace character. */
3653 if (insn->exp.X_op == O_modulus)
3655 char *s, c;
3656 int retval;
3658 input_line_pointer = *strp;
3659 s = *strp;
3660 while (*s != ',' && *s != ' ' && *s != '\t')
3661 s++;
3663 c = *s;
3664 *s = 0;
3666 retval = pa_get_absolute_expression (insn, strp);
3668 input_line_pointer = save_in;
3669 *s = c;
3670 return evaluate_absolute (insn);
3672 if (insn->exp.X_op != O_constant)
3674 as_bad (_("Bad segment (should be absolute)."));
3675 expr_end = input_line_pointer;
3676 input_line_pointer = save_in;
3677 return 0;
3679 expr_end = input_line_pointer;
3680 input_line_pointer = save_in;
3681 return evaluate_absolute (insn);
3684 /* Evaluate an absolute expression EXP which may be modified by
3685 the selector FIELD_SELECTOR. Return the value of the expression. */
3686 static int
3687 evaluate_absolute (insn)
3688 struct pa_it *insn;
3690 int value;
3691 expressionS exp;
3692 int field_selector = insn->field_selector;
3694 exp = insn->exp;
3695 value = exp.X_add_number;
3697 switch (field_selector)
3699 /* No change. */
3700 case e_fsel:
3701 break;
3703 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
3704 case e_lssel:
3705 if (value & 0x00000400)
3706 value += 0x800;
3707 value = (value & 0xfffff800) >> 11;
3708 break;
3710 /* Sign extend from bit 21. */
3711 case e_rssel:
3712 if (value & 0x00000400)
3713 value |= 0xfffff800;
3714 else
3715 value &= 0x7ff;
3716 break;
3718 /* Arithmetic shift right 11 bits. */
3719 case e_lsel:
3720 value = (value & 0xfffff800) >> 11;
3721 break;
3723 /* Set bits 0-20 to zero. */
3724 case e_rsel:
3725 value = value & 0x7ff;
3726 break;
3728 /* Add 0x800 and arithmetic shift right 11 bits. */
3729 case e_ldsel:
3730 value += 0x800;
3731 value = (value & 0xfffff800) >> 11;
3732 break;
3734 /* Set bitgs 0-21 to one. */
3735 case e_rdsel:
3736 value |= 0xfffff800;
3737 break;
3739 #define RSEL_ROUND(c) (((c) + 0x1000) & ~0x1fff)
3740 case e_rrsel:
3741 value = (RSEL_ROUND (value) & 0x7ff) + (value - RSEL_ROUND (value));
3742 break;
3744 case e_lrsel:
3745 value = (RSEL_ROUND (value) >> 11) & 0x1fffff;
3746 break;
3747 #undef RSEL_ROUND
3749 default:
3750 BAD_CASE (field_selector);
3751 break;
3753 return value;
3756 /* Given an argument location specification return the associated
3757 argument location number. */
3759 static unsigned int
3760 pa_build_arg_reloc (type_name)
3761 char *type_name;
3764 if (strncasecmp (type_name, "no", 2) == 0)
3765 return 0;
3766 if (strncasecmp (type_name, "gr", 2) == 0)
3767 return 1;
3768 else if (strncasecmp (type_name, "fr", 2) == 0)
3769 return 2;
3770 else if (strncasecmp (type_name, "fu", 2) == 0)
3771 return 3;
3772 else
3773 as_bad (_("Invalid argument location: %s\n"), type_name);
3775 return 0;
3778 /* Encode and return an argument relocation specification for
3779 the given register in the location specified by arg_reloc. */
3781 static unsigned int
3782 pa_align_arg_reloc (reg, arg_reloc)
3783 unsigned int reg;
3784 unsigned int arg_reloc;
3786 unsigned int new_reloc;
3788 new_reloc = arg_reloc;
3789 switch (reg)
3791 case 0:
3792 new_reloc <<= 8;
3793 break;
3794 case 1:
3795 new_reloc <<= 6;
3796 break;
3797 case 2:
3798 new_reloc <<= 4;
3799 break;
3800 case 3:
3801 new_reloc <<= 2;
3802 break;
3803 default:
3804 as_bad (_("Invalid argument description: %d"), reg);
3807 return new_reloc;
3810 /* Parse a PA nullification completer (,n). Return nonzero if the
3811 completer was found; return zero if no completer was found. */
3813 static int
3814 pa_parse_nullif (s)
3815 char **s;
3817 int nullif;
3819 nullif = 0;
3820 if (**s == ',')
3822 *s = *s + 1;
3823 if (strncasecmp (*s, "n", 1) == 0)
3824 nullif = 1;
3825 else
3827 as_bad (_("Invalid Nullification: (%c)"), **s);
3828 nullif = 0;
3830 *s = *s + 1;
3833 return nullif;
3836 /* Parse a non-negated compare/subtract completer returning the
3837 number (for encoding in instrutions) of the given completer.
3839 ISBRANCH specifies whether or not this is parsing a condition
3840 completer for a branch (vs a nullification completer for a
3841 computational instruction. */
3843 static int
3844 pa_parse_nonneg_cmpsub_cmpltr (s, isbranch)
3845 char **s;
3846 int isbranch;
3848 int cmpltr;
3849 char *name = *s + 1;
3850 char c;
3851 char *save_s = *s;
3852 int nullify = 0;
3854 cmpltr = 0;
3855 if (**s == ',')
3857 *s += 1;
3858 while (**s != ',' && **s != ' ' && **s != '\t')
3859 *s += 1;
3860 c = **s;
3861 **s = 0x00;
3864 if (strcmp (name, "=") == 0)
3866 cmpltr = 1;
3868 else if (strcmp (name, "<") == 0)
3870 cmpltr = 2;
3872 else if (strcmp (name, "<=") == 0)
3874 cmpltr = 3;
3876 else if (strcmp (name, "<<") == 0)
3878 cmpltr = 4;
3880 else if (strcmp (name, "<<=") == 0)
3882 cmpltr = 5;
3884 else if (strcasecmp (name, "sv") == 0)
3886 cmpltr = 6;
3888 else if (strcasecmp (name, "od") == 0)
3890 cmpltr = 7;
3892 /* If we have something like addb,n then there is no condition
3893 completer. */
3894 else if (strcasecmp (name, "n") == 0 && isbranch)
3896 cmpltr = 0;
3897 nullify = 1;
3899 else
3901 cmpltr = -1;
3903 **s = c;
3906 /* Reset pointers if this was really a ,n for a branch instruction. */
3907 if (nullify)
3908 *s = save_s;
3911 return cmpltr;
3914 /* Parse a negated compare/subtract completer returning the
3915 number (for encoding in instrutions) of the given completer.
3917 ISBRANCH specifies whether or not this is parsing a condition
3918 completer for a branch (vs a nullification completer for a
3919 computational instruction. */
3921 static int
3922 pa_parse_neg_cmpsub_cmpltr (s, isbranch)
3923 char **s;
3924 int isbranch;
3926 int cmpltr;
3927 char *name = *s + 1;
3928 char c;
3929 char *save_s = *s;
3930 int nullify = 0;
3932 cmpltr = 0;
3933 if (**s == ',')
3935 *s += 1;
3936 while (**s != ',' && **s != ' ' && **s != '\t')
3937 *s += 1;
3938 c = **s;
3939 **s = 0x00;
3942 if (strcasecmp (name, "tr") == 0)
3944 cmpltr = 0;
3946 else if (strcmp (name, "<>") == 0)
3948 cmpltr = 1;
3950 else if (strcmp (name, ">=") == 0)
3952 cmpltr = 2;
3954 else if (strcmp (name, ">") == 0)
3956 cmpltr = 3;
3958 else if (strcmp (name, ">>=") == 0)
3960 cmpltr = 4;
3962 else if (strcmp (name, ">>") == 0)
3964 cmpltr = 5;
3966 else if (strcasecmp (name, "nsv") == 0)
3968 cmpltr = 6;
3970 else if (strcasecmp (name, "ev") == 0)
3972 cmpltr = 7;
3974 /* If we have something like addb,n then there is no condition
3975 completer. */
3976 else if (strcasecmp (name, "n") == 0 && isbranch)
3978 cmpltr = 0;
3979 nullify = 1;
3981 else
3983 cmpltr = -1;
3985 **s = c;
3988 /* Reset pointers if this was really a ,n for a branch instruction. */
3989 if (nullify)
3990 *s = save_s;
3993 return cmpltr;
3997 /* Parse a non-negated addition completer returning the number
3998 (for encoding in instrutions) of the given completer.
4000 ISBRANCH specifies whether or not this is parsing a condition
4001 completer for a branch (vs a nullification completer for a
4002 computational instruction. */
4004 static int
4005 pa_parse_nonneg_add_cmpltr (s, isbranch)
4006 char **s;
4007 int isbranch;
4009 int cmpltr;
4010 char *name = *s + 1;
4011 char c;
4012 char *save_s = *s;
4014 cmpltr = 0;
4015 if (**s == ',')
4017 *s += 1;
4018 while (**s != ',' && **s != ' ' && **s != '\t')
4019 *s += 1;
4020 c = **s;
4021 **s = 0x00;
4022 if (strcmp (name, "=") == 0)
4024 cmpltr = 1;
4026 else if (strcmp (name, "<") == 0)
4028 cmpltr = 2;
4030 else if (strcmp (name, "<=") == 0)
4032 cmpltr = 3;
4034 else if (strcasecmp (name, "nuv") == 0)
4036 cmpltr = 4;
4038 else if (strcasecmp (name, "znv") == 0)
4040 cmpltr = 5;
4042 else if (strcasecmp (name, "sv") == 0)
4044 cmpltr = 6;
4046 else if (strcasecmp (name, "od") == 0)
4048 cmpltr = 7;
4050 /* If we have something like addb,n then there is no condition
4051 completer. */
4052 else if (strcasecmp (name, "n") == 0 && isbranch)
4054 cmpltr = 0;
4056 else
4058 cmpltr = -1;
4060 **s = c;
4063 /* Reset pointers if this was really a ,n for a branch instruction. */
4064 if (cmpltr == 0 && *name == 'n' && isbranch)
4065 *s = save_s;
4067 return cmpltr;
4070 /* Parse a negated addition completer returning the number
4071 (for encoding in instrutions) of the given completer.
4073 ISBRANCH specifies whether or not this is parsing a condition
4074 completer for a branch (vs a nullification completer for a
4075 computational instruction). */
4077 static int
4078 pa_parse_neg_add_cmpltr (s, isbranch)
4079 char **s;
4080 int isbranch;
4082 int cmpltr;
4083 char *name = *s + 1;
4084 char c;
4085 char *save_s = *s;
4087 cmpltr = 0;
4088 if (**s == ',')
4090 *s += 1;
4091 while (**s != ',' && **s != ' ' && **s != '\t')
4092 *s += 1;
4093 c = **s;
4094 **s = 0x00;
4095 if (strcasecmp (name, "tr") == 0)
4097 cmpltr = 0;
4099 else if (strcmp (name, "<>") == 0)
4101 cmpltr = 1;
4103 else if (strcmp (name, ">=") == 0)
4105 cmpltr = 2;
4107 else if (strcmp (name, ">") == 0)
4109 cmpltr = 3;
4111 else if (strcasecmp (name, "uv") == 0)
4113 cmpltr = 4;
4115 else if (strcasecmp (name, "vnz") == 0)
4117 cmpltr = 5;
4119 else if (strcasecmp (name, "nsv") == 0)
4121 cmpltr = 6;
4123 else if (strcasecmp (name, "ev") == 0)
4125 cmpltr = 7;
4127 /* If we have something like addb,n then there is no condition
4128 completer. */
4129 else if (strcasecmp (name, "n") == 0 && isbranch)
4131 cmpltr = 0;
4133 else
4135 cmpltr = -1;
4137 **s = c;
4140 /* Reset pointers if this was really a ,n for a branch instruction. */
4141 if (cmpltr == 0 && *name == 'n' && isbranch)
4142 *s = save_s;
4144 return cmpltr;
4147 /* Handle an alignment directive. Special so that we can update the
4148 alignment of the subspace if necessary. */
4149 static void
4150 pa_align (bytes)
4152 /* We must have a valid space and subspace. */
4153 pa_check_current_space_and_subspace ();
4155 /* Let the generic gas code do most of the work. */
4156 s_align_bytes (bytes);
4158 /* If bytes is a power of 2, then update the current subspace's
4159 alignment if necessary. */
4160 if (log2 (bytes) != -1)
4161 record_alignment (current_subspace->ssd_seg, log2 (bytes));
4164 /* Handle a .BLOCK type pseudo-op. */
4166 static void
4167 pa_block (z)
4168 int z;
4170 char *p;
4171 long int temp_fill;
4172 unsigned int temp_size;
4173 unsigned int i;
4175 /* We must have a valid space and subspace. */
4176 pa_check_current_space_and_subspace ();
4178 temp_size = get_absolute_expression ();
4180 /* Always fill with zeros, that's what the HP assembler does. */
4181 temp_fill = 0;
4183 p = frag_var (rs_fill, (int) temp_size, (int) temp_size,
4184 (relax_substateT) 0, (symbolS *) 0, (offsetT) 1, NULL);
4185 memset (p, 0, temp_size);
4187 /* Convert 2 bytes at a time. */
4189 for (i = 0; i < temp_size; i += 2)
4191 md_number_to_chars (p + i,
4192 (valueT) temp_fill,
4193 (int) ((temp_size - i) > 2 ? 2 : (temp_size - i)));
4196 pa_undefine_label ();
4197 demand_empty_rest_of_line ();
4200 /* Handle a .begin_brtab and .end_brtab pseudo-op. */
4202 static void
4203 pa_brtab (begin)
4204 int begin;
4207 #ifdef OBJ_SOM
4208 /* The BRTAB relocations are only availble in SOM (to denote
4209 the beginning and end of branch tables). */
4210 char *where = frag_more (0);
4212 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
4213 NULL, (offsetT) 0, NULL,
4214 0, begin ? R_HPPA_BEGIN_BRTAB : R_HPPA_END_BRTAB,
4215 e_fsel, 0, 0, NULL);
4216 #endif
4218 demand_empty_rest_of_line ();
4221 /* Handle a .begin_try and .end_try pseudo-op. */
4223 static void
4224 pa_try (begin)
4225 int begin;
4227 #ifdef OBJ_SOM
4228 expressionS exp;
4229 char *where = frag_more (0);
4231 if (! begin)
4232 expression (&exp);
4234 /* The TRY relocations are only availble in SOM (to denote
4235 the beginning and end of exception handling regions). */
4237 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
4238 NULL, (offsetT) 0, begin ? NULL : &exp,
4239 0, begin ? R_HPPA_BEGIN_TRY : R_HPPA_END_TRY,
4240 e_fsel, 0, 0, NULL);
4241 #endif
4243 demand_empty_rest_of_line ();
4246 /* Handle a .CALL pseudo-op. This involves storing away information
4247 about where arguments are to be found so the linker can detect
4248 (and correct) argument location mismatches between caller and callee. */
4250 static void
4251 pa_call (unused)
4252 int unused;
4254 /* We must have a valid space and subspace. */
4255 pa_check_current_space_and_subspace ();
4257 pa_call_args (&last_call_desc);
4258 demand_empty_rest_of_line ();
4261 /* Do the dirty work of building a call descriptor which describes
4262 where the caller placed arguments to a function call. */
4264 static void
4265 pa_call_args (call_desc)
4266 struct call_desc *call_desc;
4268 char *name, c, *p;
4269 unsigned int temp, arg_reloc;
4271 while (!is_end_of_statement ())
4273 name = input_line_pointer;
4274 c = get_symbol_end ();
4275 /* Process a source argument. */
4276 if ((strncasecmp (name, "argw", 4) == 0))
4278 temp = atoi (name + 4);
4279 p = input_line_pointer;
4280 *p = c;
4281 input_line_pointer++;
4282 name = input_line_pointer;
4283 c = get_symbol_end ();
4284 arg_reloc = pa_build_arg_reloc (name);
4285 call_desc->arg_reloc |= pa_align_arg_reloc (temp, arg_reloc);
4287 /* Process a return value. */
4288 else if ((strncasecmp (name, "rtnval", 6) == 0))
4290 p = input_line_pointer;
4291 *p = c;
4292 input_line_pointer++;
4293 name = input_line_pointer;
4294 c = get_symbol_end ();
4295 arg_reloc = pa_build_arg_reloc (name);
4296 call_desc->arg_reloc |= (arg_reloc & 0x3);
4298 else
4300 as_bad (_("Invalid .CALL argument: %s"), name);
4302 p = input_line_pointer;
4303 *p = c;
4304 if (!is_end_of_statement ())
4305 input_line_pointer++;
4309 /* Return TRUE if FRAG1 and FRAG2 are the same. */
4311 static int
4312 is_same_frag (frag1, frag2)
4313 fragS *frag1;
4314 fragS *frag2;
4317 if (frag1 == NULL)
4318 return (FALSE);
4319 else if (frag2 == NULL)
4320 return (FALSE);
4321 else if (frag1 == frag2)
4322 return (TRUE);
4323 else if (frag2->fr_type == rs_fill && frag2->fr_fix == 0)
4324 return (is_same_frag (frag1, frag2->fr_next));
4325 else
4326 return (FALSE);
4329 #ifdef OBJ_ELF
4330 /* Build an entry in the UNWIND subspace from the given function
4331 attributes in CALL_INFO. This is not needed for SOM as using
4332 R_ENTRY and R_EXIT relocations allow the linker to handle building
4333 of the unwind spaces. */
4335 static void
4336 pa_build_unwind_subspace (call_info)
4337 struct call_info *call_info;
4339 char *unwind;
4340 asection *seg, *save_seg;
4341 subsegT subseg, save_subseg;
4342 int i;
4343 char c, *p;
4345 /* Get into the right seg/subseg. This may involve creating
4346 the seg the first time through. Make sure to have the
4347 old seg/subseg so that we can reset things when we are done. */
4348 subseg = SUBSEG_UNWIND;
4349 seg = bfd_get_section_by_name (stdoutput, UNWIND_SECTION_NAME);
4350 if (seg == ASEC_NULL)
4352 seg = bfd_make_section_old_way (stdoutput, UNWIND_SECTION_NAME);
4353 bfd_set_section_flags (stdoutput, seg,
4354 SEC_READONLY | SEC_HAS_CONTENTS
4355 | SEC_LOAD | SEC_RELOC);
4358 save_seg = now_seg;
4359 save_subseg = now_subseg;
4360 subseg_set (seg, subseg);
4363 /* Get some space to hold relocation information for the unwind
4364 descriptor. */
4365 p = frag_more (4);
4366 md_number_to_chars (p, 0, 4);
4368 /* Relocation info. for start offset of the function. */
4369 fix_new_hppa (frag_now, p - frag_now->fr_literal, 4,
4370 call_info->start_symbol, (offsetT) 0,
4371 (expressionS *) NULL, 0, R_PARISC_DIR32, e_fsel, 32, 0, NULL);
4373 p = frag_more (4);
4374 md_number_to_chars (p, 0, 4);
4376 /* Relocation info. for end offset of the function.
4378 Because we allow reductions of 32bit relocations for ELF, this will be
4379 reduced to section_sym + offset which avoids putting the temporary
4380 symbol into the symbol table. It (should) end up giving the same
4381 value as call_info->start_symbol + function size once the linker is
4382 finished with its work. */
4384 fix_new_hppa (frag_now, p - frag_now->fr_literal, 4,
4385 call_info->end_symbol, (offsetT) 0,
4386 (expressionS *) NULL, 0, R_PARISC_DIR32, e_fsel, 32, 0, NULL);
4388 /* Dump it. */
4389 unwind = (char *) &call_info->ci_unwind;
4390 for (i = 8; i < sizeof (struct unwind_table); i++)
4392 c = *(unwind + i);
4394 FRAG_APPEND_1_CHAR (c);
4398 /* Return back to the original segment/subsegment. */
4399 subseg_set (save_seg, save_subseg);
4401 #endif
4403 /* Process a .CALLINFO pseudo-op. This information is used later
4404 to build unwind descriptors and maybe one day to support
4405 .ENTER and .LEAVE. */
4407 static void
4408 pa_callinfo (unused)
4409 int unused;
4411 char *name, c, *p;
4412 int temp;
4414 /* We must have a valid space and subspace. */
4415 pa_check_current_space_and_subspace ();
4417 /* .CALLINFO must appear within a procedure definition. */
4418 if (!within_procedure)
4419 as_bad (_(".callinfo is not within a procedure definition"));
4421 /* Mark the fact that we found the .CALLINFO for the
4422 current procedure. */
4423 callinfo_found = TRUE;
4425 /* Iterate over the .CALLINFO arguments. */
4426 while (!is_end_of_statement ())
4428 name = input_line_pointer;
4429 c = get_symbol_end ();
4430 /* Frame size specification. */
4431 if ((strncasecmp (name, "frame", 5) == 0))
4433 p = input_line_pointer;
4434 *p = c;
4435 input_line_pointer++;
4436 temp = get_absolute_expression ();
4437 if ((temp & 0x3) != 0)
4439 as_bad (_("FRAME parameter must be a multiple of 8: %d\n"), temp);
4440 temp = 0;
4443 /* callinfo is in bytes and unwind_desc is in 8 byte units. */
4444 last_call_info->ci_unwind.descriptor.frame_size = temp / 8;
4447 /* Entry register (GR, GR and SR) specifications. */
4448 else if ((strncasecmp (name, "entry_gr", 8) == 0))
4450 p = input_line_pointer;
4451 *p = c;
4452 input_line_pointer++;
4453 temp = get_absolute_expression ();
4454 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
4455 even though %r19 is caller saved. I think this is a bug in
4456 the HP assembler, and we are not going to emulate it. */
4457 if (temp < 3 || temp > 18)
4458 as_bad (_("Value for ENTRY_GR must be in the range 3..18\n"));
4459 last_call_info->ci_unwind.descriptor.entry_gr = temp - 2;
4461 else if ((strncasecmp (name, "entry_fr", 8) == 0))
4463 p = input_line_pointer;
4464 *p = c;
4465 input_line_pointer++;
4466 temp = get_absolute_expression ();
4467 /* Similarly the HP assembler takes 31 as the high bound even
4468 though %fr21 is the last callee saved floating point register. */
4469 if (temp < 12 || temp > 21)
4470 as_bad (_("Value for ENTRY_FR must be in the range 12..21\n"));
4471 last_call_info->ci_unwind.descriptor.entry_fr = temp - 11;
4473 else if ((strncasecmp (name, "entry_sr", 8) == 0))
4475 p = input_line_pointer;
4476 *p = c;
4477 input_line_pointer++;
4478 temp = get_absolute_expression ();
4479 if (temp != 3)
4480 as_bad (_("Value for ENTRY_SR must be 3\n"));
4482 /* Note whether or not this function performs any calls. */
4483 else if ((strncasecmp (name, "calls", 5) == 0) ||
4484 (strncasecmp (name, "caller", 6) == 0))
4486 p = input_line_pointer;
4487 *p = c;
4489 else if ((strncasecmp (name, "no_calls", 8) == 0))
4491 p = input_line_pointer;
4492 *p = c;
4494 /* Should RP be saved into the stack. */
4495 else if ((strncasecmp (name, "save_rp", 7) == 0))
4497 p = input_line_pointer;
4498 *p = c;
4499 last_call_info->ci_unwind.descriptor.save_rp = 1;
4501 /* Likewise for SP. */
4502 else if ((strncasecmp (name, "save_sp", 7) == 0))
4504 p = input_line_pointer;
4505 *p = c;
4506 last_call_info->ci_unwind.descriptor.save_sp = 1;
4508 /* Is this an unwindable procedure. If so mark it so
4509 in the unwind descriptor. */
4510 else if ((strncasecmp (name, "no_unwind", 9) == 0))
4512 p = input_line_pointer;
4513 *p = c;
4514 last_call_info->ci_unwind.descriptor.cannot_unwind = 1;
4516 /* Is this an interrupt routine. If so mark it in the
4517 unwind descriptor. */
4518 else if ((strncasecmp (name, "hpux_int", 7) == 0))
4520 p = input_line_pointer;
4521 *p = c;
4522 last_call_info->ci_unwind.descriptor.hpux_interrupt_marker = 1;
4524 /* Is this a millicode routine. "millicode" isn't in my
4525 assembler manual, but my copy is old. The HP assembler
4526 accepts it, and there's a place in the unwind descriptor
4527 to drop the information, so we'll accept it too. */
4528 else if ((strncasecmp (name, "millicode", 9) == 0))
4530 p = input_line_pointer;
4531 *p = c;
4532 last_call_info->ci_unwind.descriptor.millicode = 1;
4534 else
4536 as_bad (_("Invalid .CALLINFO argument: %s"), name);
4537 *input_line_pointer = c;
4539 if (!is_end_of_statement ())
4540 input_line_pointer++;
4543 demand_empty_rest_of_line ();
4546 /* Switch into the code subspace. */
4548 static void
4549 pa_code (unused)
4550 int unused;
4552 current_space = is_defined_space ("$TEXT$");
4553 current_subspace
4554 = pa_subsegment_to_subspace (current_space->sd_seg, 0);
4555 s_text (0);
4556 pa_undefine_label ();
4559 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
4560 the .comm pseudo-op has the following symtax:
4562 <label> .comm <length>
4564 where <label> is optional and is a symbol whose address will be the start of
4565 a block of memory <length> bytes long. <length> must be an absolute
4566 expression. <length> bytes will be allocated in the current space
4567 and subspace.
4569 Also note the label may not even be on the same line as the .comm.
4571 This difference in syntax means the colon function will be called
4572 on the symbol before we arrive in pa_comm. colon will set a number
4573 of attributes of the symbol that need to be fixed here. In particular
4574 the value, section pointer, fragment pointer, flags, etc. What
4575 a pain.
4577 This also makes error detection all but impossible. */
4579 static void
4580 pa_comm (unused)
4581 int unused;
4583 unsigned int size;
4584 symbolS *symbol;
4585 label_symbol_struct *label_symbol = pa_get_label ();
4587 if (label_symbol)
4588 symbol = label_symbol->lss_label;
4589 else
4590 symbol = NULL;
4592 SKIP_WHITESPACE ();
4593 size = get_absolute_expression ();
4595 if (symbol)
4597 S_SET_VALUE (symbol, size);
4598 S_SET_SEGMENT (symbol, bfd_und_section_ptr);
4599 S_SET_EXTERNAL (symbol);
4601 /* colon() has already set the frag to the current location in the
4602 current subspace; we need to reset the fragment to the zero address
4603 fragment. We also need to reset the segment pointer. */
4604 symbol->sy_frag = &zero_address_frag;
4606 demand_empty_rest_of_line ();
4609 /* Process a .END pseudo-op. */
4611 static void
4612 pa_end (unused)
4613 int unused;
4615 demand_empty_rest_of_line ();
4618 /* Process a .ENTER pseudo-op. This is not supported. */
4619 static void
4620 pa_enter (unused)
4621 int unused;
4623 /* We must have a valid space and subspace. */
4624 pa_check_current_space_and_subspace ();
4626 as_bad (_("The .ENTER pseudo-op is not supported"));
4627 demand_empty_rest_of_line ();
4630 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
4631 procesure. */
4632 static void
4633 pa_entry (unused)
4634 int unused;
4636 /* We must have a valid space and subspace. */
4637 pa_check_current_space_and_subspace ();
4639 if (!within_procedure)
4640 as_bad (_("Misplaced .entry. Ignored."));
4641 else
4643 if (!callinfo_found)
4644 as_bad (_("Missing .callinfo."));
4646 demand_empty_rest_of_line ();
4647 within_entry_exit = TRUE;
4649 #ifdef OBJ_SOM
4650 /* SOM defers building of unwind descriptors until the link phase.
4651 The assembler is responsible for creating an R_ENTRY relocation
4652 to mark the beginning of a region and hold the unwind bits, and
4653 for creating an R_EXIT relocation to mark the end of the region.
4655 FIXME. ELF should be using the same conventions! The problem
4656 is an unwind requires too much relocation space. Hmmm. Maybe
4657 if we split the unwind bits up between the relocations which
4658 denote the entry and exit points. */
4659 if (last_call_info->start_symbol != NULL)
4661 char *where = frag_more (0);
4663 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
4664 NULL, (offsetT) 0, NULL,
4665 0, R_HPPA_ENTRY, e_fsel, 0, 0,
4666 (int *) &last_call_info->ci_unwind.descriptor);
4668 #endif
4671 /* Handle a .EQU pseudo-op. */
4673 static void
4674 pa_equ (reg)
4675 int reg;
4677 label_symbol_struct *label_symbol = pa_get_label ();
4678 symbolS *symbol;
4680 if (label_symbol)
4682 symbol = label_symbol->lss_label;
4683 if (reg)
4684 S_SET_VALUE (symbol, pa_parse_number (&input_line_pointer, 0));
4685 else
4686 S_SET_VALUE (symbol, (unsigned int) get_absolute_expression ());
4687 S_SET_SEGMENT (symbol, bfd_abs_section_ptr);
4689 else
4691 if (reg)
4692 as_bad (_(".REG must use a label"));
4693 else
4694 as_bad (_(".EQU must use a label"));
4697 pa_undefine_label ();
4698 demand_empty_rest_of_line ();
4701 /* Helper function. Does processing for the end of a function. This
4702 usually involves creating some relocations or building special
4703 symbols to mark the end of the function. */
4705 static void
4706 process_exit ()
4708 char *where;
4710 where = frag_more (0);
4712 #ifdef OBJ_ELF
4713 /* Mark the end of the function, stuff away the location of the frag
4714 for the end of the function, and finally call pa_build_unwind_subspace
4715 to add an entry in the unwind table. */
4716 hppa_elf_mark_end_of_function ();
4717 pa_build_unwind_subspace (last_call_info);
4718 #else
4719 /* SOM defers building of unwind descriptors until the link phase.
4720 The assembler is responsible for creating an R_ENTRY relocation
4721 to mark the beginning of a region and hold the unwind bits, and
4722 for creating an R_EXIT relocation to mark the end of the region.
4724 FIXME. ELF should be using the same conventions! The problem
4725 is an unwind requires too much relocation space. Hmmm. Maybe
4726 if we split the unwind bits up between the relocations which
4727 denote the entry and exit points. */
4728 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
4729 NULL, (offsetT) 0,
4730 NULL, 0, R_HPPA_EXIT, e_fsel, 0, 0,
4731 (int *) &last_call_info->ci_unwind.descriptor + 1);
4732 #endif
4735 /* Process a .EXIT pseudo-op. */
4737 static void
4738 pa_exit (unused)
4739 int unused;
4741 /* We must have a valid space and subspace. */
4742 pa_check_current_space_and_subspace ();
4744 if (!within_procedure)
4745 as_bad (_(".EXIT must appear within a procedure"));
4746 else
4748 if (!callinfo_found)
4749 as_bad (_("Missing .callinfo"));
4750 else
4752 if (!within_entry_exit)
4753 as_bad (_("No .ENTRY for this .EXIT"));
4754 else
4756 within_entry_exit = FALSE;
4757 process_exit ();
4761 demand_empty_rest_of_line ();
4764 /* Process a .EXPORT directive. This makes functions external
4765 and provides information such as argument relocation entries
4766 to callers. */
4768 static void
4769 pa_export (unused)
4770 int unused;
4772 char *name, c, *p;
4773 symbolS *symbol;
4775 name = input_line_pointer;
4776 c = get_symbol_end ();
4777 /* Make sure the given symbol exists. */
4778 if ((symbol = symbol_find_or_make (name)) == NULL)
4780 as_bad (_("Cannot define export symbol: %s\n"), name);
4781 p = input_line_pointer;
4782 *p = c;
4783 input_line_pointer++;
4785 else
4787 /* OK. Set the external bits and process argument relocations. */
4788 S_SET_EXTERNAL (symbol);
4789 p = input_line_pointer;
4790 *p = c;
4791 if (!is_end_of_statement ())
4793 input_line_pointer++;
4794 pa_type_args (symbol, 1);
4798 demand_empty_rest_of_line ();
4801 /* Helper function to process arguments to a .EXPORT pseudo-op. */
4803 static void
4804 pa_type_args (symbolP, is_export)
4805 symbolS *symbolP;
4806 int is_export;
4808 char *name, c, *p;
4809 unsigned int temp, arg_reloc;
4810 pa_symbol_type type = SYMBOL_TYPE_UNKNOWN;
4811 obj_symbol_type *symbol = (obj_symbol_type *) symbolP->bsym;
4813 if (strncasecmp (input_line_pointer, "absolute", 8) == 0)
4816 input_line_pointer += 8;
4817 symbolP->bsym->flags &= ~BSF_FUNCTION;
4818 S_SET_SEGMENT (symbolP, bfd_abs_section_ptr);
4819 type = SYMBOL_TYPE_ABSOLUTE;
4821 else if (strncasecmp (input_line_pointer, "code", 4) == 0)
4823 input_line_pointer += 4;
4824 /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM,
4825 instead one should be IMPORTing/EXPORTing ENTRY types.
4827 Complain if one tries to EXPORT a CODE type since that's never
4828 done. Both GCC and HP C still try to IMPORT CODE types, so
4829 silently fix them to be ENTRY types. */
4830 if (symbolP->bsym->flags & BSF_FUNCTION)
4832 if (is_export)
4833 as_tsktsk (_("Using ENTRY rather than CODE in export directive for %s"), symbolP->bsym->name);
4835 symbolP->bsym->flags |= BSF_FUNCTION;
4836 type = SYMBOL_TYPE_ENTRY;
4838 else
4840 symbolP->bsym->flags &= ~BSF_FUNCTION;
4841 type = SYMBOL_TYPE_CODE;
4844 else if (strncasecmp (input_line_pointer, "data", 4) == 0)
4846 input_line_pointer += 4;
4847 symbolP->bsym->flags &= ~BSF_FUNCTION;
4848 type = SYMBOL_TYPE_DATA;
4850 else if ((strncasecmp (input_line_pointer, "entry", 5) == 0))
4852 input_line_pointer += 5;
4853 symbolP->bsym->flags |= BSF_FUNCTION;
4854 type = SYMBOL_TYPE_ENTRY;
4856 else if (strncasecmp (input_line_pointer, "millicode", 9) == 0)
4858 input_line_pointer += 9;
4859 symbolP->bsym->flags |= BSF_FUNCTION;
4860 type = SYMBOL_TYPE_MILLICODE;
4862 else if (strncasecmp (input_line_pointer, "plabel", 6) == 0)
4864 input_line_pointer += 6;
4865 symbolP->bsym->flags &= ~BSF_FUNCTION;
4866 type = SYMBOL_TYPE_PLABEL;
4868 else if (strncasecmp (input_line_pointer, "pri_prog", 8) == 0)
4870 input_line_pointer += 8;
4871 symbolP->bsym->flags |= BSF_FUNCTION;
4872 type = SYMBOL_TYPE_PRI_PROG;
4874 else if (strncasecmp (input_line_pointer, "sec_prog", 8) == 0)
4876 input_line_pointer += 8;
4877 symbolP->bsym->flags |= BSF_FUNCTION;
4878 type = SYMBOL_TYPE_SEC_PROG;
4881 /* SOM requires much more information about symbol types
4882 than BFD understands. This is how we get this information
4883 to the SOM BFD backend. */
4884 #ifdef obj_set_symbol_type
4885 obj_set_symbol_type (symbolP->bsym, (int) type);
4886 #endif
4888 /* Now that the type of the exported symbol has been handled,
4889 handle any argument relocation information. */
4890 while (!is_end_of_statement ())
4892 if (*input_line_pointer == ',')
4893 input_line_pointer++;
4894 name = input_line_pointer;
4895 c = get_symbol_end ();
4896 /* Argument sources. */
4897 if ((strncasecmp (name, "argw", 4) == 0))
4899 p = input_line_pointer;
4900 *p = c;
4901 input_line_pointer++;
4902 temp = atoi (name + 4);
4903 name = input_line_pointer;
4904 c = get_symbol_end ();
4905 arg_reloc = pa_align_arg_reloc (temp, pa_build_arg_reloc (name));
4906 symbol->tc_data.ap.hppa_arg_reloc |= arg_reloc;
4907 *input_line_pointer = c;
4909 /* The return value. */
4910 else if ((strncasecmp (name, "rtnval", 6)) == 0)
4912 p = input_line_pointer;
4913 *p = c;
4914 input_line_pointer++;
4915 name = input_line_pointer;
4916 c = get_symbol_end ();
4917 arg_reloc = pa_build_arg_reloc (name);
4918 symbol->tc_data.ap.hppa_arg_reloc |= arg_reloc;
4919 *input_line_pointer = c;
4921 /* Privelege level. */
4922 else if ((strncasecmp (name, "priv_lev", 8)) == 0)
4924 p = input_line_pointer;
4925 *p = c;
4926 input_line_pointer++;
4927 temp = atoi (input_line_pointer);
4928 symbol->tc_data.ap.hppa_priv_level = temp;
4929 c = get_symbol_end ();
4930 *input_line_pointer = c;
4932 else
4934 as_bad (_("Undefined .EXPORT/.IMPORT argument (ignored): %s"), name);
4935 p = input_line_pointer;
4936 *p = c;
4938 if (!is_end_of_statement ())
4939 input_line_pointer++;
4943 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
4944 assembly file must either be defined in the assembly file, or
4945 explicitly IMPORTED from another. */
4947 static void
4948 pa_import (unused)
4949 int unused;
4951 char *name, c, *p;
4952 symbolS *symbol;
4954 name = input_line_pointer;
4955 c = get_symbol_end ();
4957 symbol = symbol_find (name);
4958 /* Ugh. We might be importing a symbol defined earlier in the file,
4959 in which case all the code below will really screw things up
4960 (set the wrong segment, symbol flags & type, etc). */
4961 if (symbol == NULL || !S_IS_DEFINED (symbol))
4963 symbol = symbol_find_or_make (name);
4964 p = input_line_pointer;
4965 *p = c;
4967 if (!is_end_of_statement ())
4969 input_line_pointer++;
4970 pa_type_args (symbol, 0);
4972 else
4974 /* Sigh. To be compatable with the HP assembler and to help
4975 poorly written assembly code, we assign a type based on
4976 the the current segment. Note only BSF_FUNCTION really
4977 matters, we do not need to set the full SYMBOL_TYPE_* info. */
4978 if (now_seg == text_section)
4979 symbol->bsym->flags |= BSF_FUNCTION;
4981 /* If the section is undefined, then the symbol is undefined
4982 Since this is an import, leave the section undefined. */
4983 S_SET_SEGMENT (symbol, bfd_und_section_ptr);
4986 else
4988 /* The symbol was already defined. Just eat everything up to
4989 the end of the current statement. */
4990 while (!is_end_of_statement ())
4991 input_line_pointer++;
4994 demand_empty_rest_of_line ();
4997 /* Handle a .LABEL pseudo-op. */
4999 static void
5000 pa_label (unused)
5001 int unused;
5003 char *name, c, *p;
5005 name = input_line_pointer;
5006 c = get_symbol_end ();
5008 if (strlen (name) > 0)
5010 colon (name);
5011 p = input_line_pointer;
5012 *p = c;
5014 else
5016 as_warn (_("Missing label name on .LABEL"));
5019 if (!is_end_of_statement ())
5021 as_warn (_("extra .LABEL arguments ignored."));
5022 ignore_rest_of_line ();
5024 demand_empty_rest_of_line ();
5027 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
5029 static void
5030 pa_leave (unused)
5031 int unused;
5033 /* We must have a valid space and subspace. */
5034 pa_check_current_space_and_subspace ();
5036 as_bad (_("The .LEAVE pseudo-op is not supported"));
5037 demand_empty_rest_of_line ();
5040 /* Handle a .LEVEL pseudo-op. */
5042 static void
5043 pa_level (unused)
5044 int unused;
5046 char *level;
5048 level = input_line_pointer;
5049 if (strncmp (level, "1.0", 3) == 0)
5051 input_line_pointer += 3;
5052 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 10))
5053 as_warn (_("could not set architecture and machine"));
5055 else if (strncmp (level, "1.1", 3) == 0)
5057 input_line_pointer += 3;
5058 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 11))
5059 as_warn (_("could not set architecture and machine"));
5061 else if (strncmp (level, "2.0", 3) == 0)
5063 input_line_pointer += 3;
5064 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 20))
5065 as_warn (_("could not set architecture and machine"));
5067 else
5069 as_bad (_("Unrecognized .LEVEL argument\n"));
5070 ignore_rest_of_line ();
5072 demand_empty_rest_of_line ();
5075 /* Handle a .ORIGIN pseudo-op. */
5077 static void
5078 pa_origin (unused)
5079 int unused;
5081 /* We must have a valid space and subspace. */
5082 pa_check_current_space_and_subspace ();
5084 s_org (0);
5085 pa_undefine_label ();
5088 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
5089 is for static functions. FIXME. Should share more code with .EXPORT. */
5091 static void
5092 pa_param (unused)
5093 int unused;
5095 char *name, c, *p;
5096 symbolS *symbol;
5098 name = input_line_pointer;
5099 c = get_symbol_end ();
5101 if ((symbol = symbol_find_or_make (name)) == NULL)
5103 as_bad (_("Cannot define static symbol: %s\n"), name);
5104 p = input_line_pointer;
5105 *p = c;
5106 input_line_pointer++;
5108 else
5110 S_CLEAR_EXTERNAL (symbol);
5111 p = input_line_pointer;
5112 *p = c;
5113 if (!is_end_of_statement ())
5115 input_line_pointer++;
5116 pa_type_args (symbol, 0);
5120 demand_empty_rest_of_line ();
5123 /* Handle a .PROC pseudo-op. It is used to mark the beginning
5124 of a procedure from a syntatical point of view. */
5126 static void
5127 pa_proc (unused)
5128 int unused;
5130 struct call_info *call_info;
5132 /* We must have a valid space and subspace. */
5133 pa_check_current_space_and_subspace ();
5135 if (within_procedure)
5136 as_fatal (_("Nested procedures"));
5138 /* Reset global variables for new procedure. */
5139 callinfo_found = FALSE;
5140 within_procedure = TRUE;
5142 /* Create another call_info structure. */
5143 call_info = (struct call_info *) xmalloc (sizeof (struct call_info));
5145 if (!call_info)
5146 as_fatal (_("Cannot allocate unwind descriptor\n"));
5148 memset (call_info, 0, sizeof (struct call_info));
5150 call_info->ci_next = NULL;
5152 if (call_info_root == NULL)
5154 call_info_root = call_info;
5155 last_call_info = call_info;
5157 else
5159 last_call_info->ci_next = call_info;
5160 last_call_info = call_info;
5163 /* set up defaults on call_info structure */
5165 call_info->ci_unwind.descriptor.cannot_unwind = 0;
5166 call_info->ci_unwind.descriptor.region_desc = 1;
5167 call_info->ci_unwind.descriptor.hpux_interrupt_marker = 0;
5169 /* If we got a .PROC pseudo-op, we know that the function is defined
5170 locally. Make sure it gets into the symbol table. */
5172 label_symbol_struct *label_symbol = pa_get_label ();
5174 if (label_symbol)
5176 if (label_symbol->lss_label)
5178 last_call_info->start_symbol = label_symbol->lss_label;
5179 label_symbol->lss_label->bsym->flags |= BSF_FUNCTION;
5181 else
5182 as_bad (_("Missing function name for .PROC (corrupted label chain)"));
5184 else
5185 last_call_info->start_symbol = NULL;
5188 demand_empty_rest_of_line ();
5191 /* Process the syntatical end of a procedure. Make sure all the
5192 appropriate pseudo-ops were found within the procedure. */
5194 static void
5195 pa_procend (unused)
5196 int unused;
5199 /* We must have a valid space and subspace. */
5200 pa_check_current_space_and_subspace ();
5202 /* If we are within a procedure definition, make sure we've
5203 defined a label for the procedure; handle case where the
5204 label was defined after the .PROC directive.
5206 Note there's not need to diddle with the segment or fragment
5207 for the label symbol in this case. We have already switched
5208 into the new $CODE$ subspace at this point. */
5209 if (within_procedure && last_call_info->start_symbol == NULL)
5211 label_symbol_struct *label_symbol = pa_get_label ();
5213 if (label_symbol)
5215 if (label_symbol->lss_label)
5217 last_call_info->start_symbol = label_symbol->lss_label;
5218 label_symbol->lss_label->bsym->flags |= BSF_FUNCTION;
5219 #ifdef OBJ_SOM
5220 /* Also handle allocation of a fixup to hold the unwind
5221 information when the label appears after the proc/procend. */
5222 if (within_entry_exit)
5224 char *where = frag_more (0);
5226 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
5227 NULL, (offsetT) 0, NULL,
5228 0, R_HPPA_ENTRY, e_fsel, 0, 0,
5229 (int *) &last_call_info->ci_unwind.descriptor);
5231 #endif
5233 else
5234 as_bad (_("Missing function name for .PROC (corrupted label chain)"));
5236 else
5237 as_bad (_("Missing function name for .PROC"));
5240 if (!within_procedure)
5241 as_bad (_("misplaced .procend"));
5243 if (!callinfo_found)
5244 as_bad (_("Missing .callinfo for this procedure"));
5246 if (within_entry_exit)
5247 as_bad (_("Missing .EXIT for a .ENTRY"));
5249 #ifdef OBJ_ELF
5250 /* ELF needs to mark the end of each function so that it can compute
5251 the size of the function (apparently its needed in the symbol table). */
5252 hppa_elf_mark_end_of_function ();
5253 #endif
5255 within_procedure = FALSE;
5256 demand_empty_rest_of_line ();
5257 pa_undefine_label ();
5260 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
5261 then create a new space entry to hold the information specified
5262 by the parameters to the .SPACE directive. */
5264 static sd_chain_struct *
5265 pa_parse_space_stmt (space_name, create_flag)
5266 char *space_name;
5267 int create_flag;
5269 char *name, *ptemp, c;
5270 char loadable, defined, private, sort;
5271 int spnum, temp;
5272 asection *seg = NULL;
5273 sd_chain_struct *space;
5275 /* load default values */
5276 spnum = 0;
5277 sort = 0;
5278 loadable = TRUE;
5279 defined = TRUE;
5280 private = FALSE;
5281 if (strcmp (space_name, "$TEXT$") == 0)
5283 seg = pa_def_spaces[0].segment;
5284 defined = pa_def_spaces[0].defined;
5285 private = pa_def_spaces[0].private;
5286 sort = pa_def_spaces[0].sort;
5287 spnum = pa_def_spaces[0].spnum;
5289 else if (strcmp (space_name, "$PRIVATE$") == 0)
5291 seg = pa_def_spaces[1].segment;
5292 defined = pa_def_spaces[1].defined;
5293 private = pa_def_spaces[1].private;
5294 sort = pa_def_spaces[1].sort;
5295 spnum = pa_def_spaces[1].spnum;
5298 if (!is_end_of_statement ())
5300 print_errors = FALSE;
5301 ptemp = input_line_pointer + 1;
5302 /* First see if the space was specified as a number rather than
5303 as a name. According to the PA assembly manual the rest of
5304 the line should be ignored. */
5305 temp = pa_parse_number (&ptemp, 0);
5306 if (temp >= 0)
5308 spnum = temp;
5309 input_line_pointer = ptemp;
5311 else
5313 while (!is_end_of_statement ())
5315 input_line_pointer++;
5316 name = input_line_pointer;
5317 c = get_symbol_end ();
5318 if ((strncasecmp (name, "spnum", 5) == 0))
5320 *input_line_pointer = c;
5321 input_line_pointer++;
5322 spnum = get_absolute_expression ();
5324 else if ((strncasecmp (name, "sort", 4) == 0))
5326 *input_line_pointer = c;
5327 input_line_pointer++;
5328 sort = get_absolute_expression ();
5330 else if ((strncasecmp (name, "unloadable", 10) == 0))
5332 *input_line_pointer = c;
5333 loadable = FALSE;
5335 else if ((strncasecmp (name, "notdefined", 10) == 0))
5337 *input_line_pointer = c;
5338 defined = FALSE;
5340 else if ((strncasecmp (name, "private", 7) == 0))
5342 *input_line_pointer = c;
5343 private = TRUE;
5345 else
5347 as_bad (_("Invalid .SPACE argument"));
5348 *input_line_pointer = c;
5349 if (!is_end_of_statement ())
5350 input_line_pointer++;
5354 print_errors = TRUE;
5357 if (create_flag && seg == NULL)
5358 seg = subseg_new (space_name, 0);
5360 /* If create_flag is nonzero, then create the new space with
5361 the attributes computed above. Else set the values in
5362 an already existing space -- this can only happen for
5363 the first occurence of a built-in space. */
5364 if (create_flag)
5365 space = create_new_space (space_name, spnum, loadable, defined,
5366 private, sort, seg, 1);
5367 else
5369 space = is_defined_space (space_name);
5370 SPACE_SPNUM (space) = spnum;
5371 SPACE_DEFINED (space) = defined & 1;
5372 SPACE_USER_DEFINED (space) = 1;
5375 #ifdef obj_set_section_attributes
5376 obj_set_section_attributes (seg, defined, private, sort, spnum);
5377 #endif
5379 return space;
5382 /* Handle a .SPACE pseudo-op; this switches the current space to the
5383 given space, creating the new space if necessary. */
5385 static void
5386 pa_space (unused)
5387 int unused;
5389 char *name, c, *space_name, *save_s;
5390 int temp;
5391 sd_chain_struct *sd_chain;
5393 if (within_procedure)
5395 as_bad (_("Can\'t change spaces within a procedure definition. Ignored"));
5396 ignore_rest_of_line ();
5398 else
5400 /* Check for some of the predefined spaces. FIXME: most of the code
5401 below is repeated several times, can we extract the common parts
5402 and place them into a subroutine or something similar? */
5403 /* FIXME Is this (and the next IF stmt) really right?
5404 What if INPUT_LINE_POINTER points to "$TEXT$FOO"? */
5405 if (strncmp (input_line_pointer, "$TEXT$", 6) == 0)
5407 input_line_pointer += 6;
5408 sd_chain = is_defined_space ("$TEXT$");
5409 if (sd_chain == NULL)
5410 sd_chain = pa_parse_space_stmt ("$TEXT$", 1);
5411 else if (SPACE_USER_DEFINED (sd_chain) == 0)
5412 sd_chain = pa_parse_space_stmt ("$TEXT$", 0);
5414 current_space = sd_chain;
5415 subseg_set (text_section, sd_chain->sd_last_subseg);
5416 current_subspace
5417 = pa_subsegment_to_subspace (text_section,
5418 sd_chain->sd_last_subseg);
5419 demand_empty_rest_of_line ();
5420 return;
5422 if (strncmp (input_line_pointer, "$PRIVATE$", 9) == 0)
5424 input_line_pointer += 9;
5425 sd_chain = is_defined_space ("$PRIVATE$");
5426 if (sd_chain == NULL)
5427 sd_chain = pa_parse_space_stmt ("$PRIVATE$", 1);
5428 else if (SPACE_USER_DEFINED (sd_chain) == 0)
5429 sd_chain = pa_parse_space_stmt ("$PRIVATE$", 0);
5431 current_space = sd_chain;
5432 subseg_set (data_section, sd_chain->sd_last_subseg);
5433 current_subspace
5434 = pa_subsegment_to_subspace (data_section,
5435 sd_chain->sd_last_subseg);
5436 demand_empty_rest_of_line ();
5437 return;
5439 if (!strncasecmp (input_line_pointer,
5440 GDB_DEBUG_SPACE_NAME,
5441 strlen (GDB_DEBUG_SPACE_NAME)))
5443 input_line_pointer += strlen (GDB_DEBUG_SPACE_NAME);
5444 sd_chain = is_defined_space (GDB_DEBUG_SPACE_NAME);
5445 if (sd_chain == NULL)
5446 sd_chain = pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME, 1);
5447 else if (SPACE_USER_DEFINED (sd_chain) == 0)
5448 sd_chain = pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME, 0);
5450 current_space = sd_chain;
5453 asection *gdb_section
5454 = bfd_make_section_old_way (stdoutput, GDB_DEBUG_SPACE_NAME);
5456 subseg_set (gdb_section, sd_chain->sd_last_subseg);
5457 current_subspace
5458 = pa_subsegment_to_subspace (gdb_section,
5459 sd_chain->sd_last_subseg);
5461 demand_empty_rest_of_line ();
5462 return;
5465 /* It could be a space specified by number. */
5466 print_errors = 0;
5467 save_s = input_line_pointer;
5468 if ((temp = pa_parse_number (&input_line_pointer, 0)) >= 0)
5470 if ((sd_chain = pa_find_space_by_number (temp)))
5472 current_space = sd_chain;
5474 subseg_set (sd_chain->sd_seg, sd_chain->sd_last_subseg);
5475 current_subspace
5476 = pa_subsegment_to_subspace (sd_chain->sd_seg,
5477 sd_chain->sd_last_subseg);
5478 demand_empty_rest_of_line ();
5479 return;
5483 /* Not a number, attempt to create a new space. */
5484 print_errors = 1;
5485 input_line_pointer = save_s;
5486 name = input_line_pointer;
5487 c = get_symbol_end ();
5488 space_name = xmalloc (strlen (name) + 1);
5489 strcpy (space_name, name);
5490 *input_line_pointer = c;
5492 sd_chain = pa_parse_space_stmt (space_name, 1);
5493 current_space = sd_chain;
5495 subseg_set (sd_chain->sd_seg, sd_chain->sd_last_subseg);
5496 current_subspace = pa_subsegment_to_subspace (sd_chain->sd_seg,
5497 sd_chain->sd_last_subseg);
5498 demand_empty_rest_of_line ();
5502 /* Switch to a new space. (I think). FIXME. */
5504 static void
5505 pa_spnum (unused)
5506 int unused;
5508 char *name;
5509 char c;
5510 char *p;
5511 sd_chain_struct *space;
5513 name = input_line_pointer;
5514 c = get_symbol_end ();
5515 space = is_defined_space (name);
5516 if (space)
5518 p = frag_more (4);
5519 md_number_to_chars (p, SPACE_SPNUM (space), 4);
5521 else
5522 as_warn (_("Undefined space: '%s' Assuming space number = 0."), name);
5524 *input_line_pointer = c;
5525 demand_empty_rest_of_line ();
5528 /* If VALUE is an exact power of two between zero and 2^31, then
5529 return log2 (VALUE). Else return -1. */
5531 static int
5532 log2 (value)
5533 int value;
5535 int shift = 0;
5537 while ((1 << shift) != value && shift < 32)
5538 shift++;
5540 if (shift >= 32)
5541 return -1;
5542 else
5543 return shift;
5546 /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
5547 given subspace, creating the new subspace if necessary.
5549 FIXME. Should mirror pa_space more closely, in particular how
5550 they're broken up into subroutines. */
5552 static void
5553 pa_subspace (create_new)
5554 int create_new;
5556 char *name, *ss_name, *alias, c;
5557 char loadable, code_only, common, dup_common, zero, sort;
5558 int i, access, space_index, alignment, quadrant, applicable, flags;
5559 sd_chain_struct *space;
5560 ssd_chain_struct *ssd;
5561 asection *section;
5563 if (current_space == NULL)
5564 as_fatal (_("Must be in a space before changing or declaring subspaces.\n"));
5566 if (within_procedure)
5568 as_bad (_("Can\'t change subspaces within a procedure definition. Ignored"));
5569 ignore_rest_of_line ();
5571 else
5573 name = input_line_pointer;
5574 c = get_symbol_end ();
5575 ss_name = xmalloc (strlen (name) + 1);
5576 strcpy (ss_name, name);
5577 *input_line_pointer = c;
5579 /* Load default values. */
5580 sort = 0;
5581 access = 0x7f;
5582 loadable = 1;
5583 common = 0;
5584 dup_common = 0;
5585 code_only = 0;
5586 zero = 0;
5587 space_index = ~0;
5588 alignment = 1;
5589 quadrant = 0;
5590 alias = NULL;
5592 space = current_space;
5593 if (create_new)
5594 ssd = NULL;
5595 else
5596 ssd = is_defined_subspace (ss_name);
5597 /* Allow user to override the builtin attributes of subspaces. But
5598 only allow the attributes to be changed once! */
5599 if (ssd && SUBSPACE_DEFINED (ssd))
5601 subseg_set (ssd->ssd_seg, ssd->ssd_subseg);
5602 current_subspace = ssd;
5603 if (!is_end_of_statement ())
5604 as_warn (_("Parameters of an existing subspace can\'t be modified"));
5605 demand_empty_rest_of_line ();
5606 return;
5608 else
5610 /* A new subspace. Load default values if it matches one of
5611 the builtin subspaces. */
5612 i = 0;
5613 while (pa_def_subspaces[i].name)
5615 if (strcasecmp (pa_def_subspaces[i].name, ss_name) == 0)
5617 loadable = pa_def_subspaces[i].loadable;
5618 common = pa_def_subspaces[i].common;
5619 dup_common = pa_def_subspaces[i].dup_common;
5620 code_only = pa_def_subspaces[i].code_only;
5621 zero = pa_def_subspaces[i].zero;
5622 space_index = pa_def_subspaces[i].space_index;
5623 alignment = pa_def_subspaces[i].alignment;
5624 quadrant = pa_def_subspaces[i].quadrant;
5625 access = pa_def_subspaces[i].access;
5626 sort = pa_def_subspaces[i].sort;
5627 if (USE_ALIASES && pa_def_subspaces[i].alias)
5628 alias = pa_def_subspaces[i].alias;
5629 break;
5631 i++;
5635 /* We should be working with a new subspace now. Fill in
5636 any information as specified by the user. */
5637 if (!is_end_of_statement ())
5639 input_line_pointer++;
5640 while (!is_end_of_statement ())
5642 name = input_line_pointer;
5643 c = get_symbol_end ();
5644 if ((strncasecmp (name, "quad", 4) == 0))
5646 *input_line_pointer = c;
5647 input_line_pointer++;
5648 quadrant = get_absolute_expression ();
5650 else if ((strncasecmp (name, "align", 5) == 0))
5652 *input_line_pointer = c;
5653 input_line_pointer++;
5654 alignment = get_absolute_expression ();
5655 if (log2 (alignment) == -1)
5657 as_bad (_("Alignment must be a power of 2"));
5658 alignment = 1;
5661 else if ((strncasecmp (name, "access", 6) == 0))
5663 *input_line_pointer = c;
5664 input_line_pointer++;
5665 access = get_absolute_expression ();
5667 else if ((strncasecmp (name, "sort", 4) == 0))
5669 *input_line_pointer = c;
5670 input_line_pointer++;
5671 sort = get_absolute_expression ();
5673 else if ((strncasecmp (name, "code_only", 9) == 0))
5675 *input_line_pointer = c;
5676 code_only = 1;
5678 else if ((strncasecmp (name, "unloadable", 10) == 0))
5680 *input_line_pointer = c;
5681 loadable = 0;
5683 else if ((strncasecmp (name, "common", 6) == 0))
5685 *input_line_pointer = c;
5686 common = 1;
5688 else if ((strncasecmp (name, "dup_comm", 8) == 0))
5690 *input_line_pointer = c;
5691 dup_common = 1;
5693 else if ((strncasecmp (name, "zero", 4) == 0))
5695 *input_line_pointer = c;
5696 zero = 1;
5698 else if ((strncasecmp (name, "first", 5) == 0))
5699 as_bad (_("FIRST not supported as a .SUBSPACE argument"));
5700 else
5701 as_bad (_("Invalid .SUBSPACE argument"));
5702 if (!is_end_of_statement ())
5703 input_line_pointer++;
5707 /* Compute a reasonable set of BFD flags based on the information
5708 in the .subspace directive. */
5709 applicable = bfd_applicable_section_flags (stdoutput);
5710 flags = 0;
5711 if (loadable)
5712 flags |= (SEC_ALLOC | SEC_LOAD);
5713 if (code_only)
5714 flags |= SEC_CODE;
5715 if (common || dup_common)
5716 flags |= SEC_IS_COMMON;
5718 flags |= SEC_RELOC | SEC_HAS_CONTENTS;
5720 /* This is a zero-filled subspace (eg BSS). */
5721 if (zero)
5722 flags &= ~(SEC_LOAD | SEC_HAS_CONTENTS);
5724 applicable &= flags;
5726 /* If this is an existing subspace, then we want to use the
5727 segment already associated with the subspace.
5729 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
5730 lots of sections. It might be a problem in the PA ELF
5731 code, I do not know yet. For now avoid creating anything
5732 but the "standard" sections for ELF. */
5733 if (create_new)
5734 section = subseg_force_new (ss_name, 0);
5735 else if (ssd)
5736 section = ssd->ssd_seg;
5737 else if (alias)
5738 section = subseg_new (alias, 0);
5739 else if (!alias && USE_ALIASES)
5741 as_warn (_("Ignoring subspace decl due to ELF BFD bugs."));
5742 demand_empty_rest_of_line ();
5743 return;
5745 else
5746 section = subseg_new (ss_name, 0);
5748 if (zero)
5749 seg_info (section)->bss = 1;
5751 /* Now set the flags. */
5752 bfd_set_section_flags (stdoutput, section, applicable);
5754 /* Record any alignment request for this section. */
5755 record_alignment (section, log2 (alignment));
5757 /* Set the starting offset for this section. */
5758 bfd_set_section_vma (stdoutput, section,
5759 pa_subspace_start (space, quadrant));
5761 /* Now that all the flags are set, update an existing subspace,
5762 or create a new one. */
5763 if (ssd)
5765 current_subspace = update_subspace (space, ss_name, loadable,
5766 code_only, common, dup_common,
5767 sort, zero, access, space_index,
5768 alignment, quadrant,
5769 section);
5770 else
5771 current_subspace = create_new_subspace (space, ss_name, loadable,
5772 code_only, common,
5773 dup_common, zero, sort,
5774 access, space_index,
5775 alignment, quadrant, section);
5777 demand_empty_rest_of_line ();
5778 current_subspace->ssd_seg = section;
5779 subseg_set (current_subspace->ssd_seg, current_subspace->ssd_subseg);
5781 SUBSPACE_DEFINED (current_subspace) = 1;
5785 /* Create default space and subspace dictionaries. */
5787 static void
5788 pa_spaces_begin ()
5790 int i;
5792 space_dict_root = NULL;
5793 space_dict_last = NULL;
5795 i = 0;
5796 while (pa_def_spaces[i].name)
5798 char *name;
5800 /* Pick the right name to use for the new section. */
5801 if (pa_def_spaces[i].alias && USE_ALIASES)
5802 name = pa_def_spaces[i].alias;
5803 else
5804 name = pa_def_spaces[i].name;
5806 pa_def_spaces[i].segment = subseg_new (name, 0);
5807 create_new_space (pa_def_spaces[i].name, pa_def_spaces[i].spnum,
5808 pa_def_spaces[i].loadable, pa_def_spaces[i].defined,
5809 pa_def_spaces[i].private, pa_def_spaces[i].sort,
5810 pa_def_spaces[i].segment, 0);
5811 i++;
5814 i = 0;
5815 while (pa_def_subspaces[i].name)
5817 char *name;
5818 int applicable, subsegment;
5819 asection *segment = NULL;
5820 sd_chain_struct *space;
5822 /* Pick the right name for the new section and pick the right
5823 subsegment number. */
5824 if (pa_def_subspaces[i].alias && USE_ALIASES)
5826 name = pa_def_subspaces[i].alias;
5827 subsegment = pa_def_subspaces[i].subsegment;
5829 else
5831 name = pa_def_subspaces[i].name;
5832 subsegment = 0;
5835 /* Create the new section. */
5836 segment = subseg_new (name, subsegment);
5839 /* For SOM we want to replace the standard .text, .data, and .bss
5840 sections with our own. We also want to set BFD flags for
5841 all the built-in subspaces. */
5842 if (!strcmp (pa_def_subspaces[i].name, "$CODE$") && !USE_ALIASES)
5844 text_section = segment;
5845 applicable = bfd_applicable_section_flags (stdoutput);
5846 bfd_set_section_flags (stdoutput, segment,
5847 applicable & (SEC_ALLOC | SEC_LOAD
5848 | SEC_RELOC | SEC_CODE
5849 | SEC_READONLY
5850 | SEC_HAS_CONTENTS));
5852 else if (!strcmp (pa_def_subspaces[i].name, "$DATA$") && !USE_ALIASES)
5854 data_section = segment;
5855 applicable = bfd_applicable_section_flags (stdoutput);
5856 bfd_set_section_flags (stdoutput, segment,
5857 applicable & (SEC_ALLOC | SEC_LOAD
5858 | SEC_RELOC
5859 | SEC_HAS_CONTENTS));
5863 else if (!strcmp (pa_def_subspaces[i].name, "$BSS$") && !USE_ALIASES)
5865 bss_section = segment;
5866 applicable = bfd_applicable_section_flags (stdoutput);
5867 bfd_set_section_flags (stdoutput, segment,
5868 applicable & SEC_ALLOC);
5870 else if (!strcmp (pa_def_subspaces[i].name, "$LIT$") && !USE_ALIASES)
5872 applicable = bfd_applicable_section_flags (stdoutput);
5873 bfd_set_section_flags (stdoutput, segment,
5874 applicable & (SEC_ALLOC | SEC_LOAD
5875 | SEC_RELOC
5876 | SEC_READONLY
5877 | SEC_HAS_CONTENTS));
5879 else if (!strcmp (pa_def_subspaces[i].name, "$MILLICODE$")
5880 && !USE_ALIASES)
5882 applicable = bfd_applicable_section_flags (stdoutput);
5883 bfd_set_section_flags (stdoutput, segment,
5884 applicable & (SEC_ALLOC | SEC_LOAD
5885 | SEC_RELOC
5886 | SEC_READONLY
5887 | SEC_HAS_CONTENTS));
5889 else if (!strcmp (pa_def_subspaces[i].name, "$UNWIND$") && !USE_ALIASES)
5891 applicable = bfd_applicable_section_flags (stdoutput);
5892 bfd_set_section_flags (stdoutput, segment,
5893 applicable & (SEC_ALLOC | SEC_LOAD
5894 | SEC_RELOC
5895 | SEC_READONLY
5896 | SEC_HAS_CONTENTS));
5899 /* Find the space associated with this subspace. */
5900 space = pa_segment_to_space (pa_def_spaces[pa_def_subspaces[i].
5901 def_space_index].segment);
5902 if (space == NULL)
5904 as_fatal (_("Internal error: Unable to find containing space for %s."),
5905 pa_def_subspaces[i].name);
5908 create_new_subspace (space, name,
5909 pa_def_subspaces[i].loadable,
5910 pa_def_subspaces[i].code_only,
5911 pa_def_subspaces[i].common,
5912 pa_def_subspaces[i].dup_common,
5913 pa_def_subspaces[i].zero,
5914 pa_def_subspaces[i].sort,
5915 pa_def_subspaces[i].access,
5916 pa_def_subspaces[i].space_index,
5917 pa_def_subspaces[i].alignment,
5918 pa_def_subspaces[i].quadrant,
5919 segment);
5920 i++;
5926 /* Create a new space NAME, with the appropriate flags as defined
5927 by the given parameters. */
5929 static sd_chain_struct *
5930 create_new_space (name, spnum, loadable, defined, private,
5931 sort, seg, user_defined)
5932 char *name;
5933 int spnum;
5934 int loadable;
5935 int defined;
5936 int private;
5937 int sort;
5938 asection *seg;
5939 int user_defined;
5941 sd_chain_struct *chain_entry;
5943 chain_entry = (sd_chain_struct *) xmalloc (sizeof (sd_chain_struct));
5944 if (!chain_entry)
5945 as_fatal (_("Out of memory: could not allocate new space chain entry: %s\n"),
5946 name);
5948 SPACE_NAME (chain_entry) = (char *) xmalloc (strlen (name) + 1);
5949 strcpy (SPACE_NAME (chain_entry), name);
5950 SPACE_DEFINED (chain_entry) = defined;
5951 SPACE_USER_DEFINED (chain_entry) = user_defined;
5952 SPACE_SPNUM (chain_entry) = spnum;
5954 chain_entry->sd_seg = seg;
5955 chain_entry->sd_last_subseg = -1;
5956 chain_entry->sd_subspaces = NULL;
5957 chain_entry->sd_next = NULL;
5959 /* Find spot for the new space based on its sort key. */
5960 if (!space_dict_last)
5961 space_dict_last = chain_entry;
5963 if (space_dict_root == NULL)
5964 space_dict_root = chain_entry;
5965 else
5967 sd_chain_struct *chain_pointer;
5968 sd_chain_struct *prev_chain_pointer;
5970 chain_pointer = space_dict_root;
5971 prev_chain_pointer = NULL;
5973 while (chain_pointer)
5975 prev_chain_pointer = chain_pointer;
5976 chain_pointer = chain_pointer->sd_next;
5979 /* At this point we've found the correct place to add the new
5980 entry. So add it and update the linked lists as appropriate. */
5981 if (prev_chain_pointer)
5983 chain_entry->sd_next = chain_pointer;
5984 prev_chain_pointer->sd_next = chain_entry;
5986 else
5988 space_dict_root = chain_entry;
5989 chain_entry->sd_next = chain_pointer;
5992 if (chain_entry->sd_next == NULL)
5993 space_dict_last = chain_entry;
5996 /* This is here to catch predefined spaces which do not get
5997 modified by the user's input. Another call is found at
5998 the bottom of pa_parse_space_stmt to handle cases where
5999 the user modifies a predefined space. */
6000 #ifdef obj_set_section_attributes
6001 obj_set_section_attributes (seg, defined, private, sort, spnum);
6002 #endif
6004 return chain_entry;
6007 /* Create a new subspace NAME, with the appropriate flags as defined
6008 by the given parameters.
6010 Add the new subspace to the subspace dictionary chain in numerical
6011 order as defined by the SORT entries. */
6013 static ssd_chain_struct *
6014 create_new_subspace (space, name, loadable, code_only, common,
6015 dup_common, is_zero, sort, access, space_index,
6016 alignment, quadrant, seg)
6017 sd_chain_struct *space;
6018 char *name;
6019 int loadable, code_only, common, dup_common, is_zero;
6020 int sort;
6021 int access;
6022 int space_index;
6023 int alignment;
6024 int quadrant;
6025 asection *seg;
6027 ssd_chain_struct *chain_entry;
6029 chain_entry = (ssd_chain_struct *) xmalloc (sizeof (ssd_chain_struct));
6030 if (!chain_entry)
6031 as_fatal (_("Out of memory: could not allocate new subspace chain entry: %s\n"), name);
6033 SUBSPACE_NAME (chain_entry) = (char *) xmalloc (strlen (name) + 1);
6034 strcpy (SUBSPACE_NAME (chain_entry), name);
6036 /* Initialize subspace_defined. When we hit a .subspace directive
6037 we'll set it to 1 which "locks-in" the subspace attributes. */
6038 SUBSPACE_DEFINED (chain_entry) = 0;
6040 chain_entry->ssd_subseg = USE_ALIASES ? pa_next_subseg (space) : 0;
6041 chain_entry->ssd_seg = seg;
6042 chain_entry->ssd_next = NULL;
6044 /* Find spot for the new subspace based on its sort key. */
6045 if (space->sd_subspaces == NULL)
6046 space->sd_subspaces = chain_entry;
6047 else
6049 ssd_chain_struct *chain_pointer;
6050 ssd_chain_struct *prev_chain_pointer;
6052 chain_pointer = space->sd_subspaces;
6053 prev_chain_pointer = NULL;
6055 while (chain_pointer)
6057 prev_chain_pointer = chain_pointer;
6058 chain_pointer = chain_pointer->ssd_next;
6061 /* Now we have somewhere to put the new entry. Insert it and update
6062 the links. */
6063 if (prev_chain_pointer)
6065 chain_entry->ssd_next = chain_pointer;
6066 prev_chain_pointer->ssd_next = chain_entry;
6068 else
6070 space->sd_subspaces = chain_entry;
6071 chain_entry->ssd_next = chain_pointer;
6075 #ifdef obj_set_subsection_attributes
6076 obj_set_subsection_attributes (seg, space->sd_seg, access,
6077 sort, quadrant);
6078 #endif
6080 return chain_entry;
6083 /* Update the information for the given subspace based upon the
6084 various arguments. Return the modified subspace chain entry. */
6086 static ssd_chain_struct *
6087 update_subspace (space, name, loadable, code_only, common, dup_common, sort,
6088 zero, access, space_index, alignment, quadrant, section)
6089 sd_chain_struct *space;
6090 char *name;
6091 int loadable;
6092 int code_only;
6093 int common;
6094 int dup_common;
6095 int zero;
6096 int sort;
6097 int access;
6098 int space_index;
6099 int alignment;
6100 int quadrant;
6101 asection *section;
6103 ssd_chain_struct *chain_entry;
6105 chain_entry = is_defined_subspace (name);
6107 #ifdef obj_set_subsection_attributes
6108 obj_set_subsection_attributes (section, space->sd_seg, access,
6109 sort, quadrant);
6110 #endif
6112 return chain_entry;
6115 /* Return the space chain entry for the space with the name NAME or
6116 NULL if no such space exists. */
6118 static sd_chain_struct *
6119 is_defined_space (name)
6120 char *name;
6122 sd_chain_struct *chain_pointer;
6124 for (chain_pointer = space_dict_root;
6125 chain_pointer;
6126 chain_pointer = chain_pointer->sd_next)
6128 if (strcmp (SPACE_NAME (chain_pointer), name) == 0)
6129 return chain_pointer;
6132 /* No mapping from segment to space was found. Return NULL. */
6133 return NULL;
6136 /* Find and return the space associated with the given seg. If no mapping
6137 from the given seg to a space is found, then return NULL.
6139 Unlike subspaces, the number of spaces is not expected to grow much,
6140 so a linear exhaustive search is OK here. */
6142 static sd_chain_struct *
6143 pa_segment_to_space (seg)
6144 asection *seg;
6146 sd_chain_struct *space_chain;
6148 /* Walk through each space looking for the correct mapping. */
6149 for (space_chain = space_dict_root;
6150 space_chain;
6151 space_chain = space_chain->sd_next)
6153 if (space_chain->sd_seg == seg)
6154 return space_chain;
6157 /* Mapping was not found. Return NULL. */
6158 return NULL;
6161 /* Return the space chain entry for the subspace with the name NAME or
6162 NULL if no such subspace exists.
6164 Uses a linear search through all the spaces and subspaces, this may
6165 not be appropriate if we ever being placing each function in its
6166 own subspace. */
6168 static ssd_chain_struct *
6169 is_defined_subspace (name)
6170 char *name;
6172 sd_chain_struct *space_chain;
6173 ssd_chain_struct *subspace_chain;
6175 /* Walk through each space. */
6176 for (space_chain = space_dict_root;
6177 space_chain;
6178 space_chain = space_chain->sd_next)
6180 /* Walk through each subspace looking for a name which matches. */
6181 for (subspace_chain = space_chain->sd_subspaces;
6182 subspace_chain;
6183 subspace_chain = subspace_chain->ssd_next)
6184 if (strcmp (SUBSPACE_NAME (subspace_chain), name) == 0)
6185 return subspace_chain;
6188 /* Subspace wasn't found. Return NULL. */
6189 return NULL;
6192 /* Find and return the subspace associated with the given seg. If no
6193 mapping from the given seg to a subspace is found, then return NULL.
6195 If we ever put each procedure/function within its own subspace
6196 (to make life easier on the compiler and linker), then this will have
6197 to become more efficient. */
6199 static ssd_chain_struct *
6200 pa_subsegment_to_subspace (seg, subseg)
6201 asection *seg;
6202 subsegT subseg;
6204 sd_chain_struct *space_chain;
6205 ssd_chain_struct *subspace_chain;
6207 /* Walk through each space. */
6208 for (space_chain = space_dict_root;
6209 space_chain;
6210 space_chain = space_chain->sd_next)
6212 if (space_chain->sd_seg == seg)
6214 /* Walk through each subspace within each space looking for
6215 the correct mapping. */
6216 for (subspace_chain = space_chain->sd_subspaces;
6217 subspace_chain;
6218 subspace_chain = subspace_chain->ssd_next)
6219 if (subspace_chain->ssd_subseg == (int) subseg)
6220 return subspace_chain;
6224 /* No mapping from subsegment to subspace found. Return NULL. */
6225 return NULL;
6228 /* Given a number, try and find a space with the name number.
6230 Return a pointer to a space dictionary chain entry for the space
6231 that was found or NULL on failure. */
6233 static sd_chain_struct *
6234 pa_find_space_by_number (number)
6235 int number;
6237 sd_chain_struct *space_chain;
6239 for (space_chain = space_dict_root;
6240 space_chain;
6241 space_chain = space_chain->sd_next)
6243 if (SPACE_SPNUM (space_chain) == (unsigned int) number)
6244 return space_chain;
6247 /* No appropriate space found. Return NULL. */
6248 return NULL;
6251 /* Return the starting address for the given subspace. If the starting
6252 address is unknown then return zero. */
6254 static unsigned int
6255 pa_subspace_start (space, quadrant)
6256 sd_chain_struct *space;
6257 int quadrant;
6259 #ifdef OBJ_SOM
6260 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
6261 is not correct for the PA OSF1 port. */
6262 if ((strcmp (SPACE_NAME (space), "$PRIVATE$") == 0) && quadrant == 1)
6263 return 0x40000000;
6264 else if (space->sd_seg == data_section && quadrant == 1)
6265 return 0x40000000;
6266 else
6267 return 0;
6268 #endif
6269 return 0;
6272 /* FIXME. Needs documentation. */
6273 static int
6274 pa_next_subseg (space)
6275 sd_chain_struct *space;
6278 space->sd_last_subseg++;
6279 return space->sd_last_subseg;
6282 /* Helper function for pa_stringer. Used to find the end of
6283 a string. */
6285 static unsigned int
6286 pa_stringer_aux (s)
6287 char *s;
6289 unsigned int c = *s & CHAR_MASK;
6291 /* We must have a valid space and subspace. */
6292 pa_check_current_space_and_subspace ();
6294 switch (c)
6296 case '\"':
6297 c = NOT_A_CHAR;
6298 break;
6299 default:
6300 break;
6302 return c;
6305 /* Handle a .STRING type pseudo-op. */
6307 static void
6308 pa_stringer (append_zero)
6309 int append_zero;
6311 char *s, num_buf[4];
6312 unsigned int c;
6313 int i;
6315 /* Preprocess the string to handle PA-specific escape sequences.
6316 For example, \xDD where DD is a hexidecimal number should be
6317 changed to \OOO where OOO is an octal number. */
6319 /* Skip the opening quote. */
6320 s = input_line_pointer + 1;
6322 while (is_a_char (c = pa_stringer_aux (s++)))
6324 if (c == '\\')
6326 c = *s;
6327 switch (c)
6329 /* Handle \x<num>. */
6330 case 'x':
6332 unsigned int number;
6333 int num_digit;
6334 char dg;
6335 char *s_start = s;
6337 /* Get pas the 'x'. */
6338 s++;
6339 for (num_digit = 0, number = 0, dg = *s;
6340 num_digit < 2
6341 && (isdigit (dg) || (dg >= 'a' && dg <= 'f')
6342 || (dg >= 'A' && dg <= 'F'));
6343 num_digit++)
6345 if (isdigit (dg))
6346 number = number * 16 + dg - '0';
6347 else if (dg >= 'a' && dg <= 'f')
6348 number = number * 16 + dg - 'a' + 10;
6349 else
6350 number = number * 16 + dg - 'A' + 10;
6352 s++;
6353 dg = *s;
6355 if (num_digit > 0)
6357 switch (num_digit)
6359 case 1:
6360 sprintf (num_buf, "%02o", number);
6361 break;
6362 case 2:
6363 sprintf (num_buf, "%03o", number);
6364 break;
6366 for (i = 0; i <= num_digit; i++)
6367 s_start[i] = num_buf[i];
6369 break;
6371 /* This might be a "\"", skip over the escaped char. */
6372 default:
6373 s++;
6374 break;
6378 stringer (append_zero);
6379 pa_undefine_label ();
6382 /* Handle a .VERSION pseudo-op. */
6384 static void
6385 pa_version (unused)
6386 int unused;
6388 obj_version (0);
6389 pa_undefine_label ();
6392 #ifdef OBJ_SOM
6394 /* Handle a .COMPILER pseudo-op. */
6396 static void
6397 pa_compiler (unused)
6398 int unused;
6400 obj_som_compiler (0);
6401 pa_undefine_label ();
6404 #endif
6406 /* Handle a .COPYRIGHT pseudo-op. */
6408 static void
6409 pa_copyright (unused)
6410 int unused;
6412 obj_copyright (0);
6413 pa_undefine_label ();
6416 /* Just like a normal cons, but when finished we have to undefine
6417 the latest space label. */
6419 static void
6420 pa_cons (nbytes)
6421 int nbytes;
6423 cons (nbytes);
6424 pa_undefine_label ();
6427 /* Switch to the data space. As usual delete our label. */
6429 static void
6430 pa_data (unused)
6431 int unused;
6433 current_space = is_defined_space ("$PRIVATE$");
6434 current_subspace
6435 = pa_subsegment_to_subspace (current_space->sd_seg, 0);
6436 s_data (0);
6437 pa_undefine_label ();
6440 /* Like float_cons, but we need to undefine our label. */
6442 static void
6443 pa_float_cons (float_type)
6444 int float_type;
6446 float_cons (float_type);
6447 pa_undefine_label ();
6450 /* Like s_fill, but delete our label when finished. */
6452 static void
6453 pa_fill (unused)
6454 int unused;
6456 /* We must have a valid space and subspace. */
6457 pa_check_current_space_and_subspace ();
6459 s_fill (0);
6460 pa_undefine_label ();
6463 /* Like lcomm, but delete our label when finished. */
6465 static void
6466 pa_lcomm (needs_align)
6467 int needs_align;
6469 /* We must have a valid space and subspace. */
6470 pa_check_current_space_and_subspace ();
6472 s_lcomm (needs_align);
6473 pa_undefine_label ();
6476 /* Like lsym, but delete our label when finished. */
6478 static void
6479 pa_lsym (unused)
6480 int unused;
6482 /* We must have a valid space and subspace. */
6483 pa_check_current_space_and_subspace ();
6485 s_lsym (0);
6486 pa_undefine_label ();
6489 /* Switch to the text space. Like s_text, but delete our
6490 label when finished. */
6491 static void
6492 pa_text (unused)
6493 int unused;
6495 current_space = is_defined_space ("$TEXT$");
6496 current_subspace
6497 = pa_subsegment_to_subspace (current_space->sd_seg, 0);
6499 s_text (0);
6500 pa_undefine_label ();
6503 /* On the PA relocations which involve function symbols must not be
6504 adjusted. This so that the linker can know when/how to create argument
6505 relocation stubs for indirect calls and calls to static functions.
6507 "T" field selectors create DLT relative fixups for accessing
6508 globals and statics in PIC code; each DLT relative fixup creates
6509 an entry in the DLT table. The entries contain the address of
6510 the final target (eg accessing "foo" would create a DLT entry
6511 with the address of "foo").
6513 Unfortunately, the HP linker doesn't take into account any addend
6514 when generating the DLT; so accessing $LIT$+8 puts the address of
6515 $LIT$ into the DLT rather than the address of $LIT$+8.
6517 The end result is we can't perform relocation symbol reductions for
6518 any fixup which creates entries in the DLT (eg they use "T" field
6519 selectors).
6521 Reject reductions involving symbols with external scope; such
6522 reductions make life a living hell for object file editors.
6524 FIXME. Also reject R_HPPA relocations which are 32bits wide in
6525 the code space. The SOM BFD backend doesn't know how to pull the
6526 right bits out of an instruction. */
6529 hppa_fix_adjustable (fixp)
6530 fixS *fixp;
6532 struct hppa_fix_struct *hppa_fix;
6534 hppa_fix = (struct hppa_fix_struct *) fixp->tc_fix_data;
6536 #ifdef OBJ_SOM
6537 /* Reject reductions of symbols in 32bit relocs. */
6538 if (fixp->fx_r_type == R_HPPA && hppa_fix->fx_r_format == 32)
6539 return 0;
6541 /* Reject reductions of symbols in sym1-sym2 expressions when
6542 the fixup will occur in a CODE subspace.
6544 XXX FIXME: Long term we probably want to reject all of these;
6545 for example reducing in the debug section would lose if we ever
6546 supported using the optimizing hp linker. */
6547 if (fixp->fx_addsy
6548 && fixp->fx_subsy
6549 && (hppa_fix->segment->flags & SEC_CODE))
6551 /* Apparently sy_used_in_reloc never gets set for sub symbols. */
6552 fixp->fx_subsy->sy_used_in_reloc = 1;
6553 return 0;
6556 /* We can't adjust any relocs that use LR% and RR% field selectors.
6557 That confuses the HP linker. */
6558 if (hppa_fix->fx_r_field == e_lrsel
6559 || hppa_fix->fx_r_field == e_rrsel
6560 || hppa_fix->fx_r_field == e_nlrsel)
6561 return 0;
6562 #endif
6564 /* Reject reductions of symbols in DLT relative relocs,
6565 relocations with plabels. */
6566 if (hppa_fix->fx_r_field == e_tsel
6567 || hppa_fix->fx_r_field == e_ltsel
6568 || hppa_fix->fx_r_field == e_rtsel
6569 || hppa_fix->fx_r_field == e_psel
6570 || hppa_fix->fx_r_field == e_rpsel
6571 || hppa_fix->fx_r_field == e_lpsel)
6572 return 0;
6574 if (fixp->fx_addsy && fixp->fx_addsy->bsym->flags & BSF_GLOBAL)
6575 return 0;
6577 /* Reject absolute calls (jumps). */
6578 if (hppa_fix->fx_r_type == R_HPPA_ABS_CALL)
6579 return 0;
6581 /* Reject reductions of function symbols. */
6582 if (fixp->fx_addsy == 0
6583 || (fixp->fx_addsy->bsym->flags & BSF_FUNCTION) == 0)
6584 return 1;
6586 return 0;
6589 /* Return nonzero if the fixup in FIXP will require a relocation,
6590 even it if appears that the fixup could be completely handled
6591 within GAS. */
6594 hppa_force_relocation (fixp)
6595 fixS *fixp;
6597 struct hppa_fix_struct *hppa_fixp;
6598 int distance;
6600 hppa_fixp = (struct hppa_fix_struct *) fixp->tc_fix_data;
6601 #ifdef OBJ_SOM
6602 if (fixp->fx_r_type == R_HPPA_ENTRY || fixp->fx_r_type == R_HPPA_EXIT
6603 || fixp->fx_r_type == R_HPPA_BEGIN_BRTAB
6604 || fixp->fx_r_type == R_HPPA_END_BRTAB
6605 || fixp->fx_r_type == R_HPPA_BEGIN_TRY
6606 || fixp->fx_r_type == R_HPPA_END_TRY
6607 || (fixp->fx_addsy != NULL && fixp->fx_subsy != NULL
6608 && (hppa_fixp->segment->flags & SEC_CODE) != 0))
6609 return 1;
6610 #endif
6612 #define arg_reloc_stub_needed(CALLER, CALLEE) \
6613 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
6615 /* It is necessary to force PC-relative calls/jumps to have a relocation
6616 entry if they're going to need either a argument relocation or long
6617 call stub. FIXME. Can't we need the same for absolute calls? */
6618 if (fixp->fx_pcrel && fixp->fx_addsy
6619 && (arg_reloc_stub_needed ((long) ((obj_symbol_type *)
6620 fixp->fx_addsy->bsym)->tc_data.ap.hppa_arg_reloc,
6622 hppa_fixp->fx_arg_reloc)))
6623 return 1;
6624 distance = (fixp->fx_offset + S_GET_VALUE (fixp->fx_addsy)
6625 - md_pcrel_from (fixp));
6626 /* Now check and see if we're going to need a long-branch stub. */
6627 if (fixp->fx_r_type == R_HPPA_PCREL_CALL
6628 && (distance > 262143 || distance < -262144))
6629 return 1;
6631 if (fixp->fx_r_type == R_HPPA_ABS_CALL)
6632 return 1;
6633 #undef arg_reloc_stub_needed
6635 /* No need (yet) to force another relocations to be emitted. */
6636 return 0;
6639 /* Now for some ELF specific code. FIXME. */
6640 #ifdef OBJ_ELF
6641 /* Mark the end of a function so that it's possible to compute
6642 the size of the function in hppa_elf_final_processing. */
6644 static void
6645 hppa_elf_mark_end_of_function ()
6647 /* ELF does not have EXIT relocations. All we do is create a
6648 temporary symbol marking the end of the function. */
6649 char *name = (char *)
6650 xmalloc (strlen ("L$\001end_") +
6651 strlen (S_GET_NAME (last_call_info->start_symbol)) + 1);
6653 if (name)
6655 symbolS *symbolP;
6657 strcpy (name, "L$\001end_");
6658 strcat (name, S_GET_NAME (last_call_info->start_symbol));
6660 /* If we have a .exit followed by a .procend, then the
6661 symbol will have already been defined. */
6662 symbolP = symbol_find (name);
6663 if (symbolP)
6665 /* The symbol has already been defined! This can
6666 happen if we have a .exit followed by a .procend.
6668 This is *not* an error. All we want to do is free
6669 the memory we just allocated for the name and continue. */
6670 xfree (name);
6672 else
6674 /* symbol value should be the offset of the
6675 last instruction of the function */
6676 symbolP = symbol_new (name, now_seg, (valueT) (frag_now_fix () - 4),
6677 frag_now);
6679 assert (symbolP);
6680 symbolP->bsym->flags = BSF_LOCAL;
6681 symbol_table_insert (symbolP);
6684 if (symbolP)
6685 last_call_info->end_symbol = symbolP;
6686 else
6687 as_bad (_("Symbol '%s' could not be created."), name);
6690 else
6691 as_bad (_("No memory for symbol name."));
6695 /* For ELF, this function serves one purpose: to setup the st_size
6696 field of STT_FUNC symbols. To do this, we need to scan the
6697 call_info structure list, determining st_size in by taking the
6698 difference in the address of the beginning/end marker symbols. */
6700 void
6701 elf_hppa_final_processing ()
6703 struct call_info *call_info_pointer;
6705 for (call_info_pointer = call_info_root;
6706 call_info_pointer;
6707 call_info_pointer = call_info_pointer->ci_next)
6709 elf_symbol_type *esym
6710 = (elf_symbol_type *) call_info_pointer->start_symbol->bsym;
6711 esym->internal_elf_sym.st_size =
6712 S_GET_VALUE (call_info_pointer->end_symbol)
6713 - S_GET_VALUE (call_info_pointer->start_symbol) + 4;
6716 #endif