1999-06-04 Mark Klein <mklein@dis.com>
[binutils.git] / gas / config / tc-hppa.c
blobc2431d9ca45f105bf20f2033ea5a84c70a2bce5f
1 /* tc-hppa.c -- Assemble for the PA
2 Copyright (C) 1989, 93, 94, 95, 96, 97, 98, 1999
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
23 /* HP PA-RISC support was contributed by the Center for Software Science
24 at the University of Utah. */
26 #include <stdio.h>
27 #include <ctype.h>
29 #include "as.h"
30 #include "subsegs.h"
32 #include "bfd/libhppa.h"
33 #include "bfd/libbfd.h"
35 /* Be careful, this file includes data *declarations*. */
36 #include "opcode/hppa.h"
38 /* A "convient" place to put object file dependencies which do
39 not need to be seen outside of tc-hppa.c. */
40 #ifdef OBJ_ELF
41 /* Names of various debugging spaces/subspaces. */
42 #define GDB_DEBUG_SPACE_NAME ".stab"
43 #define GDB_STRINGS_SUBSPACE_NAME ".stabstr"
44 #define GDB_SYMBOLS_SUBSPACE_NAME ".stab"
45 #define UNWIND_SECTION_NAME ".PARISC.unwind"
46 /* Nonzero if CODE is a fixup code needing further processing. */
48 /* Object file formats specify relocation types. */
49 typedef elf32_hppa_reloc_type reloc_type;
51 /* Object file formats specify BFD symbol types. */
52 typedef elf_symbol_type obj_symbol_type;
54 /* How to generate a relocation. */
55 #define hppa_gen_reloc_type hppa_elf_gen_reloc_type
57 /* ELF objects can have versions, but apparently do not have anywhere
58 to store a copyright string. */
59 #define obj_version obj_elf_version
60 #define obj_copyright obj_elf_version
62 /* Use space aliases. */
63 #define USE_ALIASES 1
64 #endif
66 #ifdef OBJ_SOM
67 /* Names of various debugging spaces/subspaces. */
68 #define GDB_DEBUG_SPACE_NAME "$GDB_DEBUG$"
69 #define GDB_STRINGS_SUBSPACE_NAME "$GDB_STRINGS$"
70 #define GDB_SYMBOLS_SUBSPACE_NAME "$GDB_SYMBOLS$"
71 #define UNWIND_SECTION_NAME "$UNWIND$"
73 /* Object file formats specify relocation types. */
74 typedef int reloc_type;
76 /* SOM objects can have both a version string and a copyright string. */
77 #define obj_version obj_som_version
78 #define obj_copyright obj_som_copyright
80 /* Do not use space aliases. */
81 #define USE_ALIASES 0
83 /* How to generate a relocation. */
84 #define hppa_gen_reloc_type hppa_som_gen_reloc_type
86 /* Object file formats specify BFD symbol types. */
87 typedef som_symbol_type obj_symbol_type;
89 /* This apparently isn't in older versions of hpux reloc.h. */
90 #ifndef R_DLT_REL
91 #define R_DLT_REL 0x78
92 #endif
93 #endif
95 #ifndef R_N0SEL
96 #define R_N0SEL 0xd8
97 #endif
99 #ifndef R_N1SEL
100 #define R_N1SEL 0xd9
101 #endif
103 /* Various structures and types used internally in tc-hppa.c. */
105 /* Unwind table and descriptor. FIXME: Sync this with GDB version. */
107 struct unwind_desc
109 unsigned int cannot_unwind:1;
110 unsigned int millicode:1;
111 unsigned int millicode_save_rest:1;
112 unsigned int region_desc:2;
113 unsigned int save_sr:2;
114 unsigned int entry_fr:4;
115 unsigned int entry_gr:5;
116 unsigned int args_stored:1;
117 unsigned int call_fr:5;
118 unsigned int call_gr:5;
119 unsigned int save_sp:1;
120 unsigned int save_rp:1;
121 unsigned int save_rp_in_frame:1;
122 unsigned int extn_ptr_defined:1;
123 unsigned int cleanup_defined:1;
125 unsigned int hpe_interrupt_marker:1;
126 unsigned int hpux_interrupt_marker:1;
127 unsigned int reserved:3;
128 unsigned int frame_size:27;
131 struct unwind_table
133 /* Starting and ending offsets of the region described by
134 descriptor. */
135 unsigned int start_offset;
136 unsigned int end_offset;
137 struct unwind_desc descriptor;
140 /* This structure is used by the .callinfo, .enter, .leave pseudo-ops to
141 control the entry and exit code they generate. It is also used in
142 creation of the correct stack unwind descriptors.
144 NOTE: GAS does not support .enter and .leave for the generation of
145 prologues and epilogues. FIXME.
147 The fields in structure roughly correspond to the arguments available on the
148 .callinfo pseudo-op. */
150 struct call_info
152 /* The unwind descriptor being built. */
153 struct unwind_table ci_unwind;
155 /* Name of this function. */
156 symbolS *start_symbol;
158 /* (temporary) symbol used to mark the end of this function. */
159 symbolS *end_symbol;
161 /* Next entry in the chain. */
162 struct call_info *ci_next;
165 /* Operand formats for FP instructions. Note not all FP instructions
166 allow all four formats to be used (for example fmpysub only allows
167 SGL and DBL). */
168 typedef enum
170 SGL, DBL, ILLEGAL_FMT, QUAD, W, UW, DW, UDW, QW, UQW
172 fp_operand_format;
174 /* This fully describes the symbol types which may be attached to
175 an EXPORT or IMPORT directive. Only SOM uses this formation
176 (ELF has no need for it). */
177 typedef enum
179 SYMBOL_TYPE_UNKNOWN,
180 SYMBOL_TYPE_ABSOLUTE,
181 SYMBOL_TYPE_CODE,
182 SYMBOL_TYPE_DATA,
183 SYMBOL_TYPE_ENTRY,
184 SYMBOL_TYPE_MILLICODE,
185 SYMBOL_TYPE_PLABEL,
186 SYMBOL_TYPE_PRI_PROG,
187 SYMBOL_TYPE_SEC_PROG,
189 pa_symbol_type;
191 /* This structure contains information needed to assemble
192 individual instructions. */
193 struct pa_it
195 /* Holds the opcode after parsing by pa_ip. */
196 unsigned long opcode;
198 /* Holds an expression associated with the current instruction. */
199 expressionS exp;
201 /* Does this instruction use PC-relative addressing. */
202 int pcrel;
204 /* Floating point formats for operand1 and operand2. */
205 fp_operand_format fpof1;
206 fp_operand_format fpof2;
209 /* Holds the field selector for this instruction
210 (for example L%, LR%, etc). */
211 long field_selector;
213 /* Holds any argument relocation bits associated with this
214 instruction. (instruction should be some sort of call). */
215 long arg_reloc;
217 /* The format specification for this instruction. */
218 int format;
220 /* The relocation (if any) associated with this instruction. */
221 reloc_type reloc;
224 /* PA-89 floating point registers are arranged like this:
227 +--------------+--------------+
228 | 0 or 16L | 16 or 16R |
229 +--------------+--------------+
230 | 1 or 17L | 17 or 17R |
231 +--------------+--------------+
232 | | |
234 . . .
235 . . .
236 . . .
238 | | |
239 +--------------+--------------+
240 | 14 or 30L | 30 or 30R |
241 +--------------+--------------+
242 | 15 or 31L | 31 or 31R |
243 +--------------+--------------+
246 The following is a version of pa_parse_number that
247 handles the L/R notation and returns the correct
248 value to put into the instruction register field.
249 The correct value to put into the instruction is
250 encoded in the structure 'pa_11_fp_reg_struct'. */
252 struct pa_11_fp_reg_struct
254 /* The register number. */
255 char number_part;
257 /* L/R selector. */
258 char l_r_select;
261 /* Additional information needed to build argument relocation stubs. */
262 struct call_desc
264 /* The argument relocation specification. */
265 unsigned int arg_reloc;
267 /* Number of arguments. */
268 unsigned int arg_count;
271 /* This structure defines an entry in the subspace dictionary
272 chain. */
274 struct subspace_dictionary_chain
276 /* Nonzero if this space has been defined by the user code. */
277 unsigned int ssd_defined;
279 /* Name of this subspace. */
280 char *ssd_name;
282 /* GAS segment and subsegment associated with this subspace. */
283 asection *ssd_seg;
284 int ssd_subseg;
286 /* Next space in the subspace dictionary chain. */
287 struct subspace_dictionary_chain *ssd_next;
290 typedef struct subspace_dictionary_chain ssd_chain_struct;
292 /* This structure defines an entry in the subspace dictionary
293 chain. */
295 struct space_dictionary_chain
297 /* Nonzero if this space has been defined by the user code or
298 as a default space. */
299 unsigned int sd_defined;
301 /* Nonzero if this spaces has been defined by the user code. */
302 unsigned int sd_user_defined;
304 /* The space number (or index). */
305 unsigned int sd_spnum;
307 /* The name of this subspace. */
308 char *sd_name;
310 /* GAS segment to which this subspace corresponds. */
311 asection *sd_seg;
313 /* Current subsegment number being used. */
314 int sd_last_subseg;
316 /* The chain of subspaces contained within this space. */
317 ssd_chain_struct *sd_subspaces;
319 /* The next entry in the space dictionary chain. */
320 struct space_dictionary_chain *sd_next;
323 typedef struct space_dictionary_chain sd_chain_struct;
325 /* Structure for previous label tracking. Needed so that alignments,
326 callinfo declarations, etc can be easily attached to a particular
327 label. */
328 typedef struct label_symbol_struct
330 symbolS *lss_label;
331 sd_chain_struct *lss_space;
332 struct label_symbol_struct *lss_next;
334 label_symbol_struct;
336 /* This structure defines attributes of the default subspace
337 dictionary entries. */
339 struct default_subspace_dict
341 /* Name of the subspace. */
342 char *name;
344 /* FIXME. Is this still needed? */
345 char defined;
347 /* Nonzero if this subspace is loadable. */
348 char loadable;
350 /* Nonzero if this subspace contains only code. */
351 char code_only;
353 /* Nonzero if this is a common subspace. */
354 char common;
356 /* Nonzero if this is a common subspace which allows symbols
357 to be multiply defined. */
358 char dup_common;
360 /* Nonzero if this subspace should be zero filled. */
361 char zero;
363 /* Sort key for this subspace. */
364 unsigned char sort;
366 /* Access control bits for this subspace. Can represent RWX access
367 as well as privilege level changes for gateways. */
368 int access;
370 /* Index of containing space. */
371 int space_index;
373 /* Alignment (in bytes) of this subspace. */
374 int alignment;
376 /* Quadrant within space where this subspace should be loaded. */
377 int quadrant;
379 /* An index into the default spaces array. */
380 int def_space_index;
382 /* An alias for this section (or NULL if no alias exists). */
383 char *alias;
385 /* Subsegment associated with this subspace. */
386 subsegT subsegment;
389 /* This structure defines attributes of the default space
390 dictionary entries. */
392 struct default_space_dict
394 /* Name of the space. */
395 char *name;
397 /* Space number. It is possible to identify spaces within
398 assembly code numerically! */
399 int spnum;
401 /* Nonzero if this space is loadable. */
402 char loadable;
404 /* Nonzero if this space is "defined". FIXME is still needed */
405 char defined;
407 /* Nonzero if this space can not be shared. */
408 char private;
410 /* Sort key for this space. */
411 unsigned char sort;
413 /* Segment associated with this space. */
414 asection *segment;
416 /* An alias for this section (or NULL if no alias exists). */
417 char *alias;
420 /* Extra information needed to perform fixups (relocations) on the PA. */
421 struct hppa_fix_struct
423 /* The field selector. */
424 enum hppa_reloc_field_selector_type_alt fx_r_field;
426 /* Type of fixup. */
427 int fx_r_type;
429 /* Format of fixup. */
430 int fx_r_format;
432 /* Argument relocation bits. */
433 long fx_arg_reloc;
435 /* The segment this fixup appears in. */
436 segT segment;
439 /* Structure to hold information about predefined registers. */
441 struct pd_reg
443 char *name;
444 int value;
447 /* This structure defines the mapping from a FP condition string
448 to a condition number which can be recorded in an instruction. */
449 struct fp_cond_map
451 char *string;
452 int cond;
455 /* This structure defines a mapping from a field selector
456 string to a field selector type. */
457 struct selector_entry
459 char *prefix;
460 int field_selector;
463 /* Prototypes for functions local to tc-hppa.c. */
465 static void pa_check_current_space_and_subspace PARAMS ((void));
466 static fp_operand_format pa_parse_fp_format PARAMS ((char **s));
467 static void pa_cons PARAMS ((int));
468 static void pa_data PARAMS ((int));
469 static void pa_float_cons PARAMS ((int));
470 static void pa_fill PARAMS ((int));
471 static void pa_lcomm PARAMS ((int));
472 static void pa_lsym PARAMS ((int));
473 static void pa_stringer PARAMS ((int));
474 static void pa_text PARAMS ((int));
475 static void pa_version PARAMS ((int));
476 static int pa_parse_fp_cmp_cond PARAMS ((char **));
477 static int get_expression PARAMS ((char *));
478 static int pa_get_absolute_expression PARAMS ((struct pa_it *, char **));
479 static int evaluate_absolute PARAMS ((struct pa_it *));
480 static unsigned int pa_build_arg_reloc PARAMS ((char *));
481 static unsigned int pa_align_arg_reloc PARAMS ((unsigned int, unsigned int));
482 static int pa_parse_nullif PARAMS ((char **));
483 static int pa_parse_nonneg_cmpsub_cmpltr PARAMS ((char **, int));
484 static int pa_parse_neg_cmpsub_cmpltr PARAMS ((char **, int));
485 static int pa_parse_neg_add_cmpltr PARAMS ((char **, int));
486 static int pa_parse_nonneg_add_cmpltr PARAMS ((char **, int));
487 static void pa_align PARAMS ((int));
488 static void pa_block PARAMS ((int));
489 static void pa_brtab PARAMS ((int));
490 static void pa_try PARAMS ((int));
491 static void pa_call PARAMS ((int));
492 static void pa_call_args PARAMS ((struct call_desc *));
493 static void pa_callinfo PARAMS ((int));
494 static void pa_code PARAMS ((int));
495 static void pa_comm PARAMS ((int));
496 #ifdef OBJ_SOM
497 static void pa_compiler PARAMS ((int));
498 #endif
499 static void pa_copyright PARAMS ((int));
500 static void pa_end PARAMS ((int));
501 static void pa_enter PARAMS ((int));
502 static void pa_entry PARAMS ((int));
503 static void pa_equ PARAMS ((int));
504 static void pa_exit PARAMS ((int));
505 static void pa_export PARAMS ((int));
506 static void pa_type_args PARAMS ((symbolS *, int));
507 static void pa_import PARAMS ((int));
508 static void pa_label PARAMS ((int));
509 static void pa_leave PARAMS ((int));
510 static void pa_level PARAMS ((int));
511 static void pa_origin PARAMS ((int));
512 static void pa_proc PARAMS ((int));
513 static void pa_procend PARAMS ((int));
514 static void pa_space PARAMS ((int));
515 static void pa_spnum PARAMS ((int));
516 static void pa_subspace PARAMS ((int));
517 static void pa_param PARAMS ((int));
518 static void pa_undefine_label PARAMS ((void));
519 static int need_pa11_opcode PARAMS ((struct pa_it *,
520 struct pa_11_fp_reg_struct *));
521 static int pa_parse_number PARAMS ((char **, struct pa_11_fp_reg_struct *));
522 static label_symbol_struct *pa_get_label PARAMS ((void));
523 static sd_chain_struct *create_new_space PARAMS ((char *, int, int,
524 int, int, int,
525 asection *, int));
526 static ssd_chain_struct *create_new_subspace PARAMS ((sd_chain_struct *,
527 char *, int, int,
528 int, int, int,
529 int, int, int, int,
530 int, asection *));
531 static ssd_chain_struct *update_subspace PARAMS ((sd_chain_struct *,
532 char *, int, int, int,
533 int, int, int, int,
534 int, int, int,
535 asection *));
536 static sd_chain_struct *is_defined_space PARAMS ((char *));
537 static ssd_chain_struct *is_defined_subspace PARAMS ((char *));
538 static sd_chain_struct *pa_segment_to_space PARAMS ((asection *));
539 static ssd_chain_struct *pa_subsegment_to_subspace PARAMS ((asection *,
540 subsegT));
541 static sd_chain_struct *pa_find_space_by_number PARAMS ((int));
542 static unsigned int pa_subspace_start PARAMS ((sd_chain_struct *, int));
543 static void pa_ip PARAMS ((char *));
544 static void fix_new_hppa PARAMS ((fragS *, int, int, symbolS *,
545 long, expressionS *, int,
546 bfd_reloc_code_real_type,
547 enum hppa_reloc_field_selector_type_alt,
548 int, long, int *));
549 static int is_end_of_statement PARAMS ((void));
550 static int reg_name_search PARAMS ((char *));
551 static int pa_chk_field_selector PARAMS ((char **));
552 static int is_same_frag PARAMS ((fragS *, fragS *));
553 static void process_exit PARAMS ((void));
554 static sd_chain_struct *pa_parse_space_stmt PARAMS ((char *, int));
555 static int log2 PARAMS ((int));
556 static int pa_next_subseg PARAMS ((sd_chain_struct *));
557 static unsigned int pa_stringer_aux PARAMS ((char *));
558 static void pa_spaces_begin PARAMS ((void));
560 #ifdef OBJ_ELF
561 static void hppa_elf_mark_end_of_function PARAMS ((void));
562 static void pa_build_unwind_subspace PARAMS ((struct call_info *));
563 #endif
565 /* File and gloally scoped variable declarations. */
567 /* Root and final entry in the space chain. */
568 static sd_chain_struct *space_dict_root;
569 static sd_chain_struct *space_dict_last;
571 /* The current space and subspace. */
572 static sd_chain_struct *current_space;
573 static ssd_chain_struct *current_subspace;
575 /* Root of the call_info chain. */
576 static struct call_info *call_info_root;
578 /* The last call_info (for functions) structure
579 seen so it can be associated with fixups and
580 function labels. */
581 static struct call_info *last_call_info;
583 /* The last call description (for actual calls). */
584 static struct call_desc last_call_desc;
586 /* handle of the OPCODE hash table */
587 static struct hash_control *op_hash = NULL;
589 /* This array holds the chars that always start a comment. If the
590 pre-processor is disabled, these aren't very useful. */
591 const char comment_chars[] = ";";
593 /* Table of pseudo ops for the PA. FIXME -- how many of these
594 are now redundant with the overall GAS and the object file
595 dependent tables? */
596 const pseudo_typeS md_pseudo_table[] =
598 /* align pseudo-ops on the PA specify the actual alignment requested,
599 not the log2 of the requested alignment. */
600 {"align", pa_align, 8},
601 {"begin_brtab", pa_brtab, 1},
602 {"begin_try", pa_try, 1},
603 {"block", pa_block, 1},
604 {"blockz", pa_block, 0},
605 {"byte", pa_cons, 1},
606 {"call", pa_call, 0},
607 {"callinfo", pa_callinfo, 0},
608 {"code", pa_code, 0},
609 {"comm", pa_comm, 0},
610 #ifdef OBJ_SOM
611 {"compiler", pa_compiler, 0},
612 #endif
613 {"copyright", pa_copyright, 0},
614 {"data", pa_data, 0},
615 {"double", pa_float_cons, 'd'},
616 {"end", pa_end, 0},
617 {"end_brtab", pa_brtab, 0},
618 {"end_try", pa_try, 0},
619 {"enter", pa_enter, 0},
620 {"entry", pa_entry, 0},
621 {"equ", pa_equ, 0},
622 {"exit", pa_exit, 0},
623 {"export", pa_export, 0},
624 {"fill", pa_fill, 0},
625 {"float", pa_float_cons, 'f'},
626 {"half", pa_cons, 2},
627 {"import", pa_import, 0},
628 {"int", pa_cons, 4},
629 {"label", pa_label, 0},
630 {"lcomm", pa_lcomm, 0},
631 {"leave", pa_leave, 0},
632 {"level", pa_level, 0},
633 {"long", pa_cons, 4},
634 {"lsym", pa_lsym, 0},
635 {"nsubspa", pa_subspace, 1},
636 {"octa", pa_cons, 16},
637 {"org", pa_origin, 0},
638 {"origin", pa_origin, 0},
639 {"param", pa_param, 0},
640 {"proc", pa_proc, 0},
641 {"procend", pa_procend, 0},
642 {"quad", pa_cons, 8},
643 {"reg", pa_equ, 1},
644 {"short", pa_cons, 2},
645 {"single", pa_float_cons, 'f'},
646 {"space", pa_space, 0},
647 {"spnum", pa_spnum, 0},
648 {"string", pa_stringer, 0},
649 {"stringz", pa_stringer, 1},
650 {"subspa", pa_subspace, 0},
651 {"text", pa_text, 0},
652 {"version", pa_version, 0},
653 {"word", pa_cons, 4},
654 {NULL, 0, 0}
657 /* This array holds the chars that only start a comment at the beginning of
658 a line. If the line seems to have the form '# 123 filename'
659 .line and .file directives will appear in the pre-processed output.
661 Note that input_file.c hand checks for '#' at the beginning of the
662 first line of the input file. This is because the compiler outputs
663 #NO_APP at the beginning of its output.
665 Also note that C style comments will always work. */
666 const char line_comment_chars[] = "#";
668 /* This array holds the characters which act as line separators. */
669 const char line_separator_chars[] = "!";
671 /* Chars that can be used to separate mant from exp in floating point nums. */
672 const char EXP_CHARS[] = "eE";
674 /* Chars that mean this number is a floating point constant.
675 As in 0f12.456 or 0d1.2345e12.
677 Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
678 changed in read.c. Ideally it shouldn't hae to know abou it at
679 all, but nothing is ideal around here. */
680 const char FLT_CHARS[] = "rRsSfFdDxXpP";
682 static struct pa_it the_insn;
684 /* Points to the end of an expression just parsed by get_expressoin
685 and friends. FIXME. This shouldn't be handled with a file-global
686 variable. */
687 static char *expr_end;
689 /* Nonzero if a .callinfo appeared within the current procedure. */
690 static int callinfo_found;
692 /* Nonzero if the assembler is currently within a .entry/.exit pair. */
693 static int within_entry_exit;
695 /* Nonzero if the assembler is currently within a procedure definition. */
696 static int within_procedure;
698 /* Handle on strucutre which keep track of the last symbol
699 seen in each subspace. */
700 static label_symbol_struct *label_symbols_rootp = NULL;
702 /* Holds the last field selector. */
703 static int hppa_field_selector;
705 #ifdef OBJ_SOM
706 /* A dummy bfd symbol so that all relocations have symbols of some kind. */
707 static symbolS *dummy_symbol;
708 #endif
710 /* Nonzero if errors are to be printed. */
711 static int print_errors = 1;
713 /* List of registers that are pre-defined:
715 Each general register has one predefined name of the form
716 %r<REGNUM> which has the value <REGNUM>.
718 Space and control registers are handled in a similar manner,
719 but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
721 Likewise for the floating point registers, but of the form
722 %fr<REGNUM>. Floating point registers have additional predefined
723 names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
724 again have the value <REGNUM>.
726 Many registers also have synonyms:
728 %r26 - %r23 have %arg0 - %arg3 as synonyms
729 %r28 - %r29 have %ret0 - %ret1 as synonyms
730 %r30 has %sp as a synonym
731 %r27 has %dp as a synonym
732 %r2 has %rp as a synonym
734 Almost every control register has a synonym; they are not listed
735 here for brevity.
737 The table is sorted. Suitable for searching by a binary search. */
739 static const struct pd_reg pre_defined_registers[] =
741 {"%arg0", 26},
742 {"%arg1", 25},
743 {"%arg2", 24},
744 {"%arg3", 23},
745 {"%cr0", 0},
746 {"%cr10", 10},
747 {"%cr11", 11},
748 {"%cr12", 12},
749 {"%cr13", 13},
750 {"%cr14", 14},
751 {"%cr15", 15},
752 {"%cr16", 16},
753 {"%cr17", 17},
754 {"%cr18", 18},
755 {"%cr19", 19},
756 {"%cr20", 20},
757 {"%cr21", 21},
758 {"%cr22", 22},
759 {"%cr23", 23},
760 {"%cr24", 24},
761 {"%cr25", 25},
762 {"%cr26", 26},
763 {"%cr27", 27},
764 {"%cr28", 28},
765 {"%cr29", 29},
766 {"%cr30", 30},
767 {"%cr31", 31},
768 {"%cr8", 8},
769 {"%cr9", 9},
770 {"%dp", 27},
771 {"%eiem", 15},
772 {"%eirr", 23},
773 {"%fr0", 0},
774 {"%fr0l", 0},
775 {"%fr0r", 0},
776 {"%fr1", 1},
777 {"%fr10", 10},
778 {"%fr10l", 10},
779 {"%fr10r", 10},
780 {"%fr11", 11},
781 {"%fr11l", 11},
782 {"%fr11r", 11},
783 {"%fr12", 12},
784 {"%fr12l", 12},
785 {"%fr12r", 12},
786 {"%fr13", 13},
787 {"%fr13l", 13},
788 {"%fr13r", 13},
789 {"%fr14", 14},
790 {"%fr14l", 14},
791 {"%fr14r", 14},
792 {"%fr15", 15},
793 {"%fr15l", 15},
794 {"%fr15r", 15},
795 {"%fr16", 16},
796 {"%fr16l", 16},
797 {"%fr16r", 16},
798 {"%fr17", 17},
799 {"%fr17l", 17},
800 {"%fr17r", 17},
801 {"%fr18", 18},
802 {"%fr18l", 18},
803 {"%fr18r", 18},
804 {"%fr19", 19},
805 {"%fr19l", 19},
806 {"%fr19r", 19},
807 {"%fr1l", 1},
808 {"%fr1r", 1},
809 {"%fr2", 2},
810 {"%fr20", 20},
811 {"%fr20l", 20},
812 {"%fr20r", 20},
813 {"%fr21", 21},
814 {"%fr21l", 21},
815 {"%fr21r", 21},
816 {"%fr22", 22},
817 {"%fr22l", 22},
818 {"%fr22r", 22},
819 {"%fr23", 23},
820 {"%fr23l", 23},
821 {"%fr23r", 23},
822 {"%fr24", 24},
823 {"%fr24l", 24},
824 {"%fr24r", 24},
825 {"%fr25", 25},
826 {"%fr25l", 25},
827 {"%fr25r", 25},
828 {"%fr26", 26},
829 {"%fr26l", 26},
830 {"%fr26r", 26},
831 {"%fr27", 27},
832 {"%fr27l", 27},
833 {"%fr27r", 27},
834 {"%fr28", 28},
835 {"%fr28l", 28},
836 {"%fr28r", 28},
837 {"%fr29", 29},
838 {"%fr29l", 29},
839 {"%fr29r", 29},
840 {"%fr2l", 2},
841 {"%fr2r", 2},
842 {"%fr3", 3},
843 {"%fr30", 30},
844 {"%fr30l", 30},
845 {"%fr30r", 30},
846 {"%fr31", 31},
847 {"%fr31l", 31},
848 {"%fr31r", 31},
849 {"%fr3l", 3},
850 {"%fr3r", 3},
851 {"%fr4", 4},
852 {"%fr4l", 4},
853 {"%fr4r", 4},
854 {"%fr5", 5},
855 {"%fr5l", 5},
856 {"%fr5r", 5},
857 {"%fr6", 6},
858 {"%fr6l", 6},
859 {"%fr6r", 6},
860 {"%fr7", 7},
861 {"%fr7l", 7},
862 {"%fr7r", 7},
863 {"%fr8", 8},
864 {"%fr8l", 8},
865 {"%fr8r", 8},
866 {"%fr9", 9},
867 {"%fr9l", 9},
868 {"%fr9r", 9},
869 {"%hta", 25},
870 {"%iir", 19},
871 {"%ior", 21},
872 {"%ipsw", 22},
873 {"%isr", 20},
874 {"%itmr", 16},
875 {"%iva", 14},
876 {"%pcoq", 18},
877 {"%pcsq", 17},
878 {"%pidr1", 8},
879 {"%pidr2", 9},
880 {"%pidr3", 12},
881 {"%pidr4", 13},
882 {"%ppda", 24},
883 {"%r0", 0},
884 {"%r1", 1},
885 {"%r10", 10},
886 {"%r11", 11},
887 {"%r12", 12},
888 {"%r13", 13},
889 {"%r14", 14},
890 {"%r15", 15},
891 {"%r16", 16},
892 {"%r17", 17},
893 {"%r18", 18},
894 {"%r19", 19},
895 {"%r2", 2},
896 {"%r20", 20},
897 {"%r21", 21},
898 {"%r22", 22},
899 {"%r23", 23},
900 {"%r24", 24},
901 {"%r25", 25},
902 {"%r26", 26},
903 {"%r27", 27},
904 {"%r28", 28},
905 {"%r29", 29},
906 {"%r3", 3},
907 {"%r30", 30},
908 {"%r31", 31},
909 {"%r4", 4},
910 {"%r5", 5},
911 {"%r6", 6},
912 {"%r7", 7},
913 {"%r8", 8},
914 {"%r9", 9},
915 {"%rctr", 0},
916 {"%ret0", 28},
917 {"%ret1", 29},
918 {"%rp", 2},
919 {"%sar", 11},
920 {"%sp", 30},
921 {"%sr0", 0},
922 {"%sr1", 1},
923 {"%sr2", 2},
924 {"%sr3", 3},
925 {"%sr4", 4},
926 {"%sr5", 5},
927 {"%sr6", 6},
928 {"%sr7", 7},
929 {"%tr0", 24},
930 {"%tr1", 25},
931 {"%tr2", 26},
932 {"%tr3", 27},
933 {"%tr4", 28},
934 {"%tr5", 29},
935 {"%tr6", 30},
936 {"%tr7", 31}
939 /* This table is sorted by order of the length of the string. This is
940 so we check for <> before we check for <. If we had a <> and checked
941 for < first, we would get a false match. */
942 static const struct fp_cond_map fp_cond_map[] =
944 {"false?", 0},
945 {"false", 1},
946 {"true?", 30},
947 {"true", 31},
948 {"!<=>", 3},
949 {"!?>=", 8},
950 {"!?<=", 16},
951 {"!<>", 7},
952 {"!>=", 11},
953 {"!?>", 12},
954 {"?<=", 14},
955 {"!<=", 19},
956 {"!?<", 20},
957 {"?>=", 22},
958 {"!?=", 24},
959 {"!=t", 27},
960 {"<=>", 29},
961 {"=t", 5},
962 {"?=", 6},
963 {"?<", 10},
964 {"<=", 13},
965 {"!>", 15},
966 {"?>", 18},
967 {">=", 21},
968 {"!<", 23},
969 {"<>", 25},
970 {"!=", 26},
971 {"!?", 28},
972 {"?", 2},
973 {"=", 4},
974 {"<", 9},
975 {">", 17}
978 static const struct selector_entry selector_table[] =
980 {"f", e_fsel},
981 {"l", e_lsel},
982 {"ld", e_ldsel},
983 {"lp", e_lpsel},
984 {"lr", e_lrsel},
985 {"ls", e_lssel},
986 {"lt", e_ltsel},
987 {"n", e_nsel},
988 {"nl", e_nlsel},
989 {"nlr", e_nlrsel},
990 {"p", e_psel},
991 {"r", e_rsel},
992 {"rd", e_rdsel},
993 {"rp", e_rpsel},
994 {"rr", e_rrsel},
995 {"rs", e_rssel},
996 {"rt", e_rtsel},
997 {"t", e_tsel},
1000 /* default space and subspace dictionaries */
1002 #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
1003 #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
1005 /* pre-defined subsegments (subspaces) for the HPPA. */
1006 #define SUBSEG_CODE 0
1007 #define SUBSEG_LIT 1
1008 #define SUBSEG_MILLI 2
1009 #define SUBSEG_DATA 0
1010 #define SUBSEG_BSS 2
1011 #define SUBSEG_UNWIND 3
1012 #define SUBSEG_GDB_STRINGS 0
1013 #define SUBSEG_GDB_SYMBOLS 1
1015 static struct default_subspace_dict pa_def_subspaces[] =
1017 {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_CODE},
1018 {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, ".data", SUBSEG_DATA},
1019 {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_LIT},
1020 {"$MILLICODE$", 1, 1, 0, 0, 0, 0, 8, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_MILLI},
1021 {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, ".bss", SUBSEG_BSS},
1022 #ifdef OBJ_ELF
1023 {"$UNWIND$", 1, 1, 0, 0, 0, 0, 64, 0x2c, 0, 4, 0, 0, ".PARISC.unwind", SUBSEG_UNWIND},
1024 #endif
1025 {NULL, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
1028 static struct default_space_dict pa_def_spaces[] =
1030 {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL, ".text"},
1031 {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL, ".data"},
1032 {NULL, 0, 0, 0, 0, 0, ASEC_NULL, NULL}
1035 /* Misc local definitions used by the assembler. */
1037 /* Return nonzero if the string pointed to by S potentially represents
1038 a right or left half of a FP register */
1039 #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
1040 #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
1042 /* These macros are used to maintain spaces/subspaces. */
1043 #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined
1044 #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
1045 #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum
1046 #define SPACE_NAME(space_chain) (space_chain)->sd_name
1048 #define SUBSPACE_DEFINED(ss_chain) (ss_chain)->ssd_defined
1049 #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name
1051 /* Insert FIELD into OPCODE starting at bit START. Continue pa_ip
1052 main loop after insertion. */
1054 #define INSERT_FIELD_AND_CONTINUE(OPCODE, FIELD, START) \
1056 ((OPCODE) |= (FIELD) << (START)); \
1057 continue; \
1060 /* Simple range checking for FIELD againt HIGH and LOW bounds.
1061 IGNORE is used to suppress the error message. */
1063 #define CHECK_FIELD(FIELD, HIGH, LOW, IGNORE) \
1065 if ((FIELD) > (HIGH) || (FIELD) < (LOW)) \
1067 if (! IGNORE) \
1068 as_bad (_("Field out of range [%d..%d] (%d)."), (LOW), (HIGH), \
1069 (int) (FIELD));\
1070 break; \
1074 #define is_DP_relative(exp) \
1075 ((exp).X_op == O_subtract \
1076 && strcmp (S_GET_NAME ((exp).X_op_symbol), "$global$") == 0)
1078 #define is_PC_relative(exp) \
1079 ((exp).X_op == O_subtract \
1080 && strcmp (S_GET_NAME ((exp).X_op_symbol), "$PIC_pcrel$0") == 0)
1082 /* We need some complex handling for stabs (sym1 - sym2). Luckily, we'll
1083 always be able to reduce the expression to a constant, so we don't
1084 need real complex handling yet. */
1085 #define is_complex(exp) \
1086 ((exp).X_op != O_constant && (exp).X_op != O_symbol)
1088 /* Actual functions to implement the PA specific code for the assembler. */
1090 /* Called before writing the object file. Make sure entry/exit and
1091 proc/procend pairs match. */
1093 void
1094 pa_check_eof ()
1096 if (within_entry_exit)
1097 as_fatal (_("Missing .exit\n"));
1099 if (within_procedure)
1100 as_fatal (_("Missing .procend\n"));
1103 /* Check to make sure we have a valid space and subspace. */
1105 static void
1106 pa_check_current_space_and_subspace ()
1108 if (current_space == NULL)
1109 as_fatal (_("Not in a space.\n"));
1111 if (current_subspace == NULL)
1112 as_fatal (_("Not in a subspace.\n"));
1115 /* Returns a pointer to the label_symbol_struct for the current space.
1116 or NULL if no label_symbol_struct exists for the current space. */
1118 static label_symbol_struct *
1119 pa_get_label ()
1121 label_symbol_struct *label_chain;
1122 sd_chain_struct *space_chain = current_space;
1124 for (label_chain = label_symbols_rootp;
1125 label_chain;
1126 label_chain = label_chain->lss_next)
1127 if (space_chain == label_chain->lss_space && label_chain->lss_label)
1128 return label_chain;
1130 return NULL;
1133 /* Defines a label for the current space. If one is already defined,
1134 this function will replace it with the new label. */
1136 void
1137 pa_define_label (symbol)
1138 symbolS *symbol;
1140 label_symbol_struct *label_chain = pa_get_label ();
1141 sd_chain_struct *space_chain = current_space;
1143 if (label_chain)
1144 label_chain->lss_label = symbol;
1145 else
1147 /* Create a new label entry and add it to the head of the chain. */
1148 label_chain
1149 = (label_symbol_struct *) xmalloc (sizeof (label_symbol_struct));
1150 label_chain->lss_label = symbol;
1151 label_chain->lss_space = space_chain;
1152 label_chain->lss_next = NULL;
1154 if (label_symbols_rootp)
1155 label_chain->lss_next = label_symbols_rootp;
1157 label_symbols_rootp = label_chain;
1161 /* Removes a label definition for the current space.
1162 If there is no label_symbol_struct entry, then no action is taken. */
1164 static void
1165 pa_undefine_label ()
1167 label_symbol_struct *label_chain;
1168 label_symbol_struct *prev_label_chain = NULL;
1169 sd_chain_struct *space_chain = current_space;
1171 for (label_chain = label_symbols_rootp;
1172 label_chain;
1173 label_chain = label_chain->lss_next)
1175 if (space_chain == label_chain->lss_space && label_chain->lss_label)
1177 /* Remove the label from the chain and free its memory. */
1178 if (prev_label_chain)
1179 prev_label_chain->lss_next = label_chain->lss_next;
1180 else
1181 label_symbols_rootp = label_chain->lss_next;
1183 free (label_chain);
1184 break;
1186 prev_label_chain = label_chain;
1191 /* An HPPA-specific version of fix_new. This is required because the HPPA
1192 code needs to keep track of some extra stuff. Each call to fix_new_hppa
1193 results in the creation of an instance of an hppa_fix_struct. An
1194 hppa_fix_struct stores the extra information along with a pointer to the
1195 original fixS. This is attached to the original fixup via the
1196 tc_fix_data field. */
1198 static void
1199 fix_new_hppa (frag, where, size, add_symbol, offset, exp, pcrel,
1200 r_type, r_field, r_format, arg_reloc, unwind_bits)
1201 fragS *frag;
1202 int where;
1203 int size;
1204 symbolS *add_symbol;
1205 long offset;
1206 expressionS *exp;
1207 int pcrel;
1208 bfd_reloc_code_real_type r_type;
1209 enum hppa_reloc_field_selector_type_alt r_field;
1210 int r_format;
1211 long arg_reloc;
1212 int* unwind_bits;
1214 fixS *new_fix;
1216 struct hppa_fix_struct *hppa_fix = (struct hppa_fix_struct *)
1217 obstack_alloc (&notes, sizeof (struct hppa_fix_struct));
1219 if (exp != NULL)
1220 new_fix = fix_new_exp (frag, where, size, exp, pcrel, r_type);
1221 else
1222 new_fix = fix_new (frag, where, size, add_symbol, offset, pcrel, r_type);
1223 new_fix->tc_fix_data = (void *) hppa_fix;
1224 hppa_fix->fx_r_type = r_type;
1225 hppa_fix->fx_r_field = r_field;
1226 hppa_fix->fx_r_format = r_format;
1227 hppa_fix->fx_arg_reloc = arg_reloc;
1228 hppa_fix->segment = now_seg;
1229 #ifdef OBJ_SOM
1230 if (r_type == R_ENTRY || r_type == R_EXIT)
1231 new_fix->fx_offset = *unwind_bits;
1232 #endif
1234 /* foo-$global$ is used to access non-automatic storage. $global$
1235 is really just a marker and has served its purpose, so eliminate
1236 it now so as not to confuse write.c. */
1237 if (new_fix->fx_subsy
1238 && !strcmp (S_GET_NAME (new_fix->fx_subsy), "$global$"))
1239 new_fix->fx_subsy = NULL;
1242 /* Parse a .byte, .word, .long expression for the HPPA. Called by
1243 cons via the TC_PARSE_CONS_EXPRESSION macro. */
1245 void
1246 parse_cons_expression_hppa (exp)
1247 expressionS *exp;
1249 hppa_field_selector = pa_chk_field_selector (&input_line_pointer);
1250 expression (exp);
1253 /* This fix_new is called by cons via TC_CONS_FIX_NEW.
1254 hppa_field_selector is set by the parse_cons_expression_hppa. */
1256 void
1257 cons_fix_new_hppa (frag, where, size, exp)
1258 fragS *frag;
1259 int where;
1260 int size;
1261 expressionS *exp;
1263 unsigned int rel_type;
1265 /* Get a base relocation type. */
1266 if (is_DP_relative (*exp))
1267 rel_type = R_HPPA_GOTOFF;
1268 else if (is_complex (*exp))
1269 rel_type = R_HPPA_COMPLEX;
1270 else
1271 rel_type = R_HPPA;
1273 if (hppa_field_selector != e_psel && hppa_field_selector != e_fsel)
1274 as_warn (_("Invalid field selector. Assuming F%%."));
1276 fix_new_hppa (frag, where, size,
1277 (symbolS *) NULL, (offsetT) 0, exp, 0, rel_type,
1278 hppa_field_selector, 32, 0, NULL);
1280 /* Reset field selector to its default state. */
1281 hppa_field_selector = 0;
1284 /* This function is called once, at assembler startup time. It should
1285 set up all the tables, etc. that the MD part of the assembler will need. */
1287 void
1288 md_begin ()
1290 const char *retval = NULL;
1291 int lose = 0;
1292 unsigned int i = 0;
1294 last_call_info = NULL;
1295 call_info_root = NULL;
1297 /* Set the default machine type. */
1298 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 10))
1299 as_warn (_("could not set architecture and machine"));
1301 /* Folding of text and data segments fails miserably on the PA.
1302 Warn user and disable "-R" option. */
1303 if (flag_readonly_data_in_text)
1305 as_warn (_("-R option not supported on this target."));
1306 flag_readonly_data_in_text = 0;
1309 pa_spaces_begin ();
1311 op_hash = hash_new ();
1313 while (i < NUMOPCODES)
1315 const char *name = pa_opcodes[i].name;
1316 retval = hash_insert (op_hash, name, (struct pa_opcode *) &pa_opcodes[i]);
1317 if (retval != NULL && *retval != '\0')
1319 as_fatal (_("Internal error: can't hash `%s': %s\n"), name, retval);
1320 lose = 1;
1324 if ((pa_opcodes[i].match & pa_opcodes[i].mask)
1325 != pa_opcodes[i].match)
1327 fprintf (stderr, _("internal error: losing opcode: `%s' \"%s\"\n"),
1328 pa_opcodes[i].name, pa_opcodes[i].args);
1329 lose = 1;
1331 ++i;
1333 while (i < NUMOPCODES && !strcmp (pa_opcodes[i].name, name));
1336 if (lose)
1337 as_fatal (_("Broken assembler. No assembly attempted."));
1339 /* SOM will change text_section. To make sure we never put
1340 anything into the old one switch to the new one now. */
1341 subseg_set (text_section, 0);
1343 #ifdef OBJ_SOM
1344 dummy_symbol = symbol_find_or_make ("L$dummy");
1345 S_SET_SEGMENT (dummy_symbol, text_section);
1346 /* Force the symbol to be converted to a real symbol. */
1347 (void) symbol_get_bfdsym (dummy_symbol);
1348 #endif
1351 /* Assemble a single instruction storing it into a frag. */
1352 void
1353 md_assemble (str)
1354 char *str;
1356 char *to;
1358 /* The had better be something to assemble. */
1359 assert (str);
1361 /* If we are within a procedure definition, make sure we've
1362 defined a label for the procedure; handle case where the
1363 label was defined after the .PROC directive.
1365 Note there's not need to diddle with the segment or fragment
1366 for the label symbol in this case. We have already switched
1367 into the new $CODE$ subspace at this point. */
1368 if (within_procedure && last_call_info->start_symbol == NULL)
1370 label_symbol_struct *label_symbol = pa_get_label ();
1372 if (label_symbol)
1374 if (label_symbol->lss_label)
1376 last_call_info->start_symbol = label_symbol->lss_label;
1377 symbol_get_bfdsym (label_symbol->lss_label)->flags
1378 |= BSF_FUNCTION;
1379 #ifdef OBJ_SOM
1380 /* Also handle allocation of a fixup to hold the unwind
1381 information when the label appears after the proc/procend. */
1382 if (within_entry_exit)
1384 char *where = frag_more (0);
1386 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
1387 NULL, (offsetT) 0, NULL,
1388 0, R_HPPA_ENTRY, e_fsel, 0, 0,
1389 (int *)&last_call_info->ci_unwind.descriptor);
1391 #endif
1393 else
1394 as_bad (_("Missing function name for .PROC (corrupted label chain)"));
1396 else
1397 as_bad (_("Missing function name for .PROC"));
1400 /* Assemble the instruction. Results are saved into "the_insn". */
1401 pa_ip (str);
1403 /* Get somewhere to put the assembled instrution. */
1404 to = frag_more (4);
1406 /* Output the opcode. */
1407 md_number_to_chars (to, the_insn.opcode, 4);
1409 /* If necessary output more stuff. */
1410 if (the_insn.reloc != R_HPPA_NONE)
1411 fix_new_hppa (frag_now, (to - frag_now->fr_literal), 4, NULL,
1412 (offsetT) 0, &the_insn.exp, the_insn.pcrel,
1413 the_insn.reloc, the_insn.field_selector,
1414 the_insn.format, the_insn.arg_reloc, NULL);
1417 /* Do the real work for assembling a single instruction. Store results
1418 into the global "the_insn" variable. */
1420 static void
1421 pa_ip (str)
1422 char *str;
1424 char *error_message = "";
1425 char *s, c, *argstart, *name, *save_s;
1426 const char *args;
1427 int match = FALSE;
1428 int comma = 0;
1429 int cmpltr, nullif, flag, cond, num;
1430 unsigned long opcode;
1431 struct pa_opcode *insn;
1433 /* We must have a valid space and subspace. */
1434 pa_check_current_space_and_subspace ();
1436 /* Skip to something interesting. */
1437 for (s = str; isupper (*s) || islower (*s) || (*s >= '0' && *s <= '3'); ++s)
1440 switch (*s)
1443 case '\0':
1444 break;
1446 case ',':
1447 comma = 1;
1449 /*FALLTHROUGH */
1451 case ' ':
1452 *s++ = '\0';
1453 break;
1455 default:
1456 as_fatal (_("Unknown opcode: `%s'"), str);
1459 save_s = str;
1461 /* Convert everything into lower case. */
1462 while (*save_s)
1464 if (isupper (*save_s))
1465 *save_s = tolower (*save_s);
1466 save_s++;
1469 /* Look up the opcode in the has table. */
1470 if ((insn = (struct pa_opcode *) hash_find (op_hash, str)) == NULL)
1472 as_bad ("Unknown opcode: `%s'", str);
1473 return;
1476 if (comma)
1478 *--s = ',';
1481 /* Mark the location where arguments for the instruction start, then
1482 start processing them. */
1483 argstart = s;
1484 for (;;)
1486 /* Do some initialization. */
1487 opcode = insn->match;
1488 memset (&the_insn, 0, sizeof (the_insn));
1490 the_insn.reloc = R_HPPA_NONE;
1492 /* If this instruction is specific to a particular architecture,
1493 then set a new architecture. */
1494 /* But do not automatically promote to pa2.0. The automatic promotion
1495 crud is for compatability with HP's old assemblers only. */
1496 if (insn->arch < 20
1497 && bfd_get_mach (stdoutput) < insn->arch)
1499 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, insn->arch))
1500 as_warn (_("could not update architecture and machine"));
1502 else if (bfd_get_mach (stdoutput) < insn->arch)
1504 match = FALSE;
1505 goto failed;
1508 /* Build the opcode, checking as we go to make
1509 sure that the operands match. */
1510 for (args = insn->args;; ++args)
1512 switch (*args)
1515 /* End of arguments. */
1516 case '\0':
1517 if (*s == '\0')
1518 match = TRUE;
1519 break;
1521 case '+':
1522 if (*s == '+')
1524 ++s;
1525 continue;
1527 if (*s == '-')
1528 continue;
1529 break;
1531 /* These must match exactly. */
1532 case '(':
1533 case ')':
1534 case ',':
1535 case ' ':
1536 if (*s++ == *args)
1537 continue;
1538 break;
1540 /* Handle a 5 bit register or control register field at 10. */
1541 case 'b':
1542 case '^':
1543 num = pa_parse_number (&s, 0);
1544 CHECK_FIELD (num, 31, 0, 0);
1545 INSERT_FIELD_AND_CONTINUE (opcode, num, 21);
1547 /* Handle a 5 bit register field at 15. */
1548 case 'x':
1549 num = pa_parse_number (&s, 0);
1550 CHECK_FIELD (num, 31, 0, 0);
1551 INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
1553 /* Handle a 5 bit register field at 31. */
1554 case 'y':
1555 case 't':
1556 num = pa_parse_number (&s, 0);
1557 CHECK_FIELD (num, 31, 0, 0);
1558 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
1560 /* Handle a 5 bit field length at 31. */
1561 case 'T':
1562 num = pa_get_absolute_expression (&the_insn, &s);
1563 s = expr_end;
1564 CHECK_FIELD (num, 32, 1, 0);
1565 INSERT_FIELD_AND_CONTINUE (opcode, 32 - num, 0);
1567 /* Handle a 5 bit immediate at 15. */
1568 case '5':
1569 num = pa_get_absolute_expression (&the_insn, &s);
1570 s = expr_end;
1571 CHECK_FIELD (num, 15, -16, 0);
1572 low_sign_unext (num, 5, &num);
1573 INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
1575 /* Handle a 5 bit immediate at 31. */
1576 case 'V':
1577 num = pa_get_absolute_expression (&the_insn, &s);
1578 s = expr_end;
1579 CHECK_FIELD (num, 15, -16, 0)
1580 low_sign_unext (num, 5, &num);
1581 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
1583 /* Handle an unsigned 5 bit immediate at 31. */
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, 0);
1590 /* Handle an unsigned 5 bit immediate at 15. */
1591 case 'R':
1592 num = pa_get_absolute_expression (&the_insn, &s);
1593 s = expr_end;
1594 CHECK_FIELD (num, 31, 0, 0);
1595 INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
1597 /* Handle a 2 bit space identifier at 17. */
1598 case 's':
1599 num = pa_parse_number (&s, 0);
1600 CHECK_FIELD (num, 3, 0, 1);
1601 INSERT_FIELD_AND_CONTINUE (opcode, num, 14);
1603 /* Handle a 3 bit space identifier at 18. */
1604 case 'S':
1605 num = pa_parse_number (&s, 0);
1606 CHECK_FIELD (num, 7, 0, 1);
1607 dis_assemble_3 (num, &num);
1608 INSERT_FIELD_AND_CONTINUE (opcode, num, 13);
1610 /* Handle a completer for an indexing load or store. */
1611 case 'c':
1613 int uu = 0;
1614 int m = 0;
1615 int i = 0;
1616 while (*s == ',' && i < 2)
1618 s++;
1619 if (strncasecmp (s, "sm", 2) == 0)
1621 uu = 1;
1622 m = 1;
1623 s++;
1624 i++;
1626 else if (strncasecmp (s, "m", 1) == 0)
1627 m = 1;
1628 else if (strncasecmp (s, "s", 1) == 0)
1629 uu = 1;
1630 else
1631 as_bad (_("Invalid Indexed Load Completer."));
1632 s++;
1633 i++;
1635 if (i > 2)
1636 as_bad (_("Invalid Indexed Load Completer Syntax."));
1637 opcode |= m << 5;
1638 INSERT_FIELD_AND_CONTINUE (opcode, uu, 13);
1641 /* Handle a short load/store completer. */
1642 case 'C':
1644 int a = 0;
1645 int m = 0;
1646 if (*s == ',')
1648 s++;
1649 if (strncasecmp (s, "ma", 2) == 0)
1651 a = 0;
1652 m = 1;
1654 else if (strncasecmp (s, "mb", 2) == 0)
1656 a = 1;
1657 m = 1;
1659 else
1660 as_bad (_("Invalid Short Load/Store Completer."));
1661 s += 2;
1664 if (*args == 'C')
1666 opcode |= m << 5;
1667 INSERT_FIELD_AND_CONTINUE (opcode, a, 13);
1671 /* Handle a stbys completer. */
1672 case 'Y':
1674 int a = 0;
1675 int m = 0;
1676 int i = 0;
1677 while (*s == ',' && i < 2)
1679 s++;
1680 if (strncasecmp (s, "m", 1) == 0)
1681 m = 1;
1682 else if (strncasecmp (s, "b", 1) == 0)
1683 a = 0;
1684 else if (strncasecmp (s, "e", 1) == 0)
1685 a = 1;
1686 else
1687 as_bad (_("Invalid Store Bytes Short Completer"));
1688 s++;
1689 i++;
1691 if (i > 2)
1692 as_bad (_("Invalid Store Bytes Short Completer"));
1693 opcode |= m << 5;
1694 INSERT_FIELD_AND_CONTINUE (opcode, a, 13);
1697 /* Handle a non-negated compare/stubtract condition. */
1698 case '<':
1699 cmpltr = pa_parse_nonneg_cmpsub_cmpltr (&s, 1);
1700 if (cmpltr < 0)
1702 as_bad (_("Invalid Compare/Subtract Condition: %c"), *s);
1703 cmpltr = 0;
1705 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
1707 /* Handle a negated or non-negated compare/subtract condition. */
1708 case '?':
1709 save_s = s;
1710 cmpltr = pa_parse_nonneg_cmpsub_cmpltr (&s, 1);
1711 if (cmpltr < 0)
1713 s = save_s;
1714 cmpltr = pa_parse_neg_cmpsub_cmpltr (&s, 1);
1715 if (cmpltr < 0)
1717 as_bad (_("Invalid Compare/Subtract Condition."));
1718 cmpltr = 0;
1720 else
1722 /* Negated condition requires an opcode change. */
1723 opcode |= 1 << 27;
1727 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
1729 /* Handle non-negated add condition. */
1730 case '!':
1731 cmpltr = pa_parse_nonneg_add_cmpltr (&s, 1);
1732 if (cmpltr < 0)
1734 as_bad (_("Invalid Compare/Subtract Condition: %c"), *s);
1735 cmpltr = 0;
1737 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
1739 /* Handle a negated or non-negated add condition. */
1740 case '@':
1741 save_s = s;
1742 cmpltr = pa_parse_nonneg_add_cmpltr (&s, 1);
1743 if (cmpltr < 0)
1745 s = save_s;
1746 cmpltr = pa_parse_neg_add_cmpltr (&s, 1);
1747 if (cmpltr < 0)
1749 as_bad (_("Invalid Compare/Subtract Condition"));
1750 cmpltr = 0;
1752 else
1754 /* Negated condition requires an opcode change. */
1755 opcode |= 1 << 27;
1758 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
1760 /* Handle a compare/subtract condition. */
1761 case 'a':
1762 cmpltr = 0;
1763 flag = 0;
1764 if (*s == ',')
1766 s++;
1767 name = s;
1768 while (*s != ',' && *s != ' ' && *s != '\t')
1769 s += 1;
1770 c = *s;
1771 *s = 0x00;
1772 if (strcmp (name, "=") == 0)
1773 cmpltr = 1;
1774 else if (strcmp (name, "<") == 0)
1775 cmpltr = 2;
1776 else if (strcmp (name, "<=") == 0)
1777 cmpltr = 3;
1778 else if (strcasecmp (name, "<<") == 0)
1779 cmpltr = 4;
1780 else if (strcasecmp (name, "<<=") == 0)
1781 cmpltr = 5;
1782 else if (strcasecmp (name, "sv") == 0)
1783 cmpltr = 6;
1784 else if (strcasecmp (name, "od") == 0)
1785 cmpltr = 7;
1786 else if (strcasecmp (name, "tr") == 0)
1788 cmpltr = 0;
1789 flag = 1;
1791 else if (strcmp (name, "<>") == 0)
1793 cmpltr = 1;
1794 flag = 1;
1796 else if (strcmp (name, ">=") == 0)
1798 cmpltr = 2;
1799 flag = 1;
1801 else if (strcmp (name, ">") == 0)
1803 cmpltr = 3;
1804 flag = 1;
1806 else if (strcasecmp (name, ">>=") == 0)
1808 cmpltr = 4;
1809 flag = 1;
1811 else if (strcasecmp (name, ">>") == 0)
1813 cmpltr = 5;
1814 flag = 1;
1816 else if (strcasecmp (name, "nsv") == 0)
1818 cmpltr = 6;
1819 flag = 1;
1821 else if (strcasecmp (name, "ev") == 0)
1823 cmpltr = 7;
1824 flag = 1;
1826 else
1827 as_bad (_("Invalid Add Condition: %s"), name);
1828 *s = c;
1830 opcode |= cmpltr << 13;
1831 INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
1833 /* Handle a non-negated add condition. */
1834 case 'd':
1835 cmpltr = 0;
1836 flag = 0;
1837 if (*s == ',')
1839 s++;
1840 name = s;
1841 while (*s != ',' && *s != ' ' && *s != '\t')
1842 s += 1;
1843 c = *s;
1844 *s = 0x00;
1845 if (strcmp (name, "=") == 0)
1846 cmpltr = 1;
1847 else if (strcmp (name, "<") == 0)
1848 cmpltr = 2;
1849 else if (strcmp (name, "<=") == 0)
1850 cmpltr = 3;
1851 else if (strcasecmp (name, "nuv") == 0)
1852 cmpltr = 4;
1853 else if (strcasecmp (name, "znv") == 0)
1854 cmpltr = 5;
1855 else if (strcasecmp (name, "sv") == 0)
1856 cmpltr = 6;
1857 else if (strcasecmp (name, "od") == 0)
1858 cmpltr = 7;
1859 else if (strcasecmp (name, "tr") == 0)
1861 cmpltr = 0;
1862 flag = 1;
1864 else if (strcmp (name, "<>") == 0)
1866 cmpltr = 1;
1867 flag = 1;
1869 else if (strcmp (name, ">=") == 0)
1871 cmpltr = 2;
1872 flag = 1;
1874 else if (strcmp (name, ">") == 0)
1876 cmpltr = 3;
1877 flag = 1;
1879 else if (strcasecmp (name, "uv") == 0)
1881 cmpltr = 4;
1882 flag = 1;
1884 else if (strcasecmp (name, "vnz") == 0)
1886 cmpltr = 5;
1887 flag = 1;
1889 else if (strcasecmp (name, "nsv") == 0)
1891 cmpltr = 6;
1892 flag = 1;
1894 else if (strcasecmp (name, "ev") == 0)
1896 cmpltr = 7;
1897 flag = 1;
1899 else
1900 as_bad (_("Invalid Add Condition: %s"), name);
1901 *s = c;
1903 opcode |= cmpltr << 13;
1904 INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
1906 /* HANDLE a logical instruction condition. */
1907 case '&':
1908 cmpltr = 0;
1909 flag = 0;
1910 if (*s == ',')
1912 s++;
1913 name = s;
1914 while (*s != ',' && *s != ' ' && *s != '\t')
1915 s += 1;
1916 c = *s;
1917 *s = 0x00;
1920 if (strcmp (name, "=") == 0)
1921 cmpltr = 1;
1922 else if (strcmp (name, "<") == 0)
1923 cmpltr = 2;
1924 else if (strcmp (name, "<=") == 0)
1925 cmpltr = 3;
1926 else if (strcasecmp (name, "od") == 0)
1927 cmpltr = 7;
1928 else if (strcasecmp (name, "tr") == 0)
1930 cmpltr = 0;
1931 flag = 1;
1933 else if (strcmp (name, "<>") == 0)
1935 cmpltr = 1;
1936 flag = 1;
1938 else if (strcmp (name, ">=") == 0)
1940 cmpltr = 2;
1941 flag = 1;
1943 else if (strcmp (name, ">") == 0)
1945 cmpltr = 3;
1946 flag = 1;
1948 else if (strcasecmp (name, "ev") == 0)
1950 cmpltr = 7;
1951 flag = 1;
1953 else
1954 as_bad (_("Invalid Logical Instruction Condition."));
1955 *s = c;
1957 opcode |= cmpltr << 13;
1958 INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
1960 /* Handle a unit instruction condition. */
1961 case 'U':
1962 cmpltr = 0;
1963 flag = 0;
1964 if (*s == ',')
1966 s++;
1969 if (strncasecmp (s, "sbz", 3) == 0)
1971 cmpltr = 2;
1972 s += 3;
1974 else if (strncasecmp (s, "shz", 3) == 0)
1976 cmpltr = 3;
1977 s += 3;
1979 else if (strncasecmp (s, "sdc", 3) == 0)
1981 cmpltr = 4;
1982 s += 3;
1984 else if (strncasecmp (s, "sbc", 3) == 0)
1986 cmpltr = 6;
1987 s += 3;
1989 else if (strncasecmp (s, "shc", 3) == 0)
1991 cmpltr = 7;
1992 s += 3;
1994 else if (strncasecmp (s, "tr", 2) == 0)
1996 cmpltr = 0;
1997 flag = 1;
1998 s += 2;
2000 else if (strncasecmp (s, "nbz", 3) == 0)
2002 cmpltr = 2;
2003 flag = 1;
2004 s += 3;
2006 else if (strncasecmp (s, "nhz", 3) == 0)
2008 cmpltr = 3;
2009 flag = 1;
2010 s += 3;
2012 else if (strncasecmp (s, "ndc", 3) == 0)
2014 cmpltr = 4;
2015 flag = 1;
2016 s += 3;
2018 else if (strncasecmp (s, "nbc", 3) == 0)
2020 cmpltr = 6;
2021 flag = 1;
2022 s += 3;
2024 else if (strncasecmp (s, "nhc", 3) == 0)
2026 cmpltr = 7;
2027 flag = 1;
2028 s += 3;
2030 else
2031 as_bad (_("Invalid Logical Instruction Condition."));
2033 opcode |= cmpltr << 13;
2034 INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
2036 /* Handle a shift/extract/deposit condition. */
2037 case '|':
2038 case '>':
2039 cmpltr = 0;
2040 if (*s == ',')
2042 save_s = s++;
2045 name = s;
2046 while (*s != ',' && *s != ' ' && *s != '\t')
2047 s += 1;
2048 c = *s;
2049 *s = 0x00;
2050 if (strcmp (name, "=") == 0)
2051 cmpltr = 1;
2052 else if (strcmp (name, "<") == 0)
2053 cmpltr = 2;
2054 else if (strcasecmp (name, "od") == 0)
2055 cmpltr = 3;
2056 else if (strcasecmp (name, "tr") == 0)
2057 cmpltr = 4;
2058 else if (strcmp (name, "<>") == 0)
2059 cmpltr = 5;
2060 else if (strcmp (name, ">=") == 0)
2061 cmpltr = 6;
2062 else if (strcasecmp (name, "ev") == 0)
2063 cmpltr = 7;
2064 /* Handle movb,n. Put things back the way they were.
2065 This includes moving s back to where it started. */
2066 else if (strcasecmp (name, "n") == 0 && *args == '|')
2068 *s = c;
2069 s = save_s;
2070 continue;
2072 else
2073 as_bad (_("Invalid Shift/Extract/Deposit Condition."));
2074 *s = c;
2076 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
2078 /* Handle bvb and bb conditions. */
2079 case '~':
2080 cmpltr = 0;
2081 if (*s == ',')
2083 s++;
2084 if (strncmp (s, "<", 1) == 0)
2086 cmpltr = 0;
2087 s++;
2089 else if (strncmp (s, ">=", 2) == 0)
2091 cmpltr = 1;
2092 s += 2;
2094 else
2095 as_bad (_("Invalid Bit Branch Condition: %c"), *s);
2097 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 15);
2099 /* Handle a system control completer. */
2100 case 'Z':
2101 if (*s == ',' && (*(s + 1) == 'm' || *(s + 1) == 'M'))
2103 flag = 1;
2104 s += 2;
2106 else
2107 flag = 0;
2109 INSERT_FIELD_AND_CONTINUE (opcode, flag, 5);
2111 /* Handle a nullification completer for branch instructions. */
2112 case 'n':
2113 nullif = pa_parse_nullif (&s);
2114 INSERT_FIELD_AND_CONTINUE (opcode, nullif, 1);
2116 /* Handle a nullification completer for copr and spop insns. */
2117 case 'N':
2118 nullif = pa_parse_nullif (&s);
2119 INSERT_FIELD_AND_CONTINUE (opcode, nullif, 5);
2122 /* Handle a 11 bit immediate at 31. */
2123 case 'i':
2124 the_insn.field_selector = pa_chk_field_selector (&s);
2125 get_expression (s);
2126 s = expr_end;
2127 if (the_insn.exp.X_op == O_constant)
2129 num = evaluate_absolute (&the_insn);
2130 CHECK_FIELD (num, 1023, -1024, 0);
2131 low_sign_unext (num, 11, &num);
2132 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2134 else
2136 if (is_DP_relative (the_insn.exp))
2137 the_insn.reloc = R_HPPA_GOTOFF;
2138 else if (is_PC_relative (the_insn.exp))
2139 the_insn.reloc = R_HPPA_PCREL_CALL;
2140 else
2141 the_insn.reloc = R_HPPA;
2142 the_insn.format = 11;
2143 continue;
2147 /* Handle a 14 bit immediate at 31. */
2148 case 'j':
2149 the_insn.field_selector = pa_chk_field_selector (&s);
2150 get_expression (s);
2151 s = expr_end;
2152 if (the_insn.exp.X_op == O_constant)
2154 num = evaluate_absolute (&the_insn);
2155 CHECK_FIELD (num, 8191, -8192, 0);
2156 low_sign_unext (num, 14, &num);
2157 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2159 else
2161 if (is_DP_relative (the_insn.exp))
2162 the_insn.reloc = R_HPPA_GOTOFF;
2163 else if (is_PC_relative (the_insn.exp))
2164 the_insn.reloc = R_HPPA_PCREL_CALL;
2165 else
2166 the_insn.reloc = R_HPPA;
2167 the_insn.format = 14;
2168 continue;
2171 /* Handle a 21 bit immediate at 31. */
2172 case 'k':
2173 the_insn.field_selector = pa_chk_field_selector (&s);
2174 get_expression (s);
2175 s = expr_end;
2176 if (the_insn.exp.X_op == O_constant)
2178 num = evaluate_absolute (&the_insn);
2179 CHECK_FIELD (num >> 11, 1048575, -1048576, 0);
2180 dis_assemble_21 (num, &num);
2181 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2183 else
2185 if (is_DP_relative (the_insn.exp))
2186 the_insn.reloc = R_HPPA_GOTOFF;
2187 else if (is_PC_relative (the_insn.exp))
2188 the_insn.reloc = R_HPPA_PCREL_CALL;
2189 else
2190 the_insn.reloc = R_HPPA;
2191 the_insn.format = 21;
2192 continue;
2195 /* Handle a 12 bit branch displacement. */
2196 case 'w':
2197 the_insn.field_selector = pa_chk_field_selector (&s);
2198 get_expression (s);
2199 s = expr_end;
2200 the_insn.pcrel = 1;
2201 if (!strcmp (S_GET_NAME (the_insn.exp.X_add_symbol), "L$0\001"))
2203 unsigned int w1, w, result;
2205 num = evaluate_absolute (&the_insn);
2206 if (num % 4)
2208 as_bad (_("Branch to unaligned address"));
2209 break;
2211 CHECK_FIELD (num, 8199, -8184, 0);
2212 sign_unext ((num - 8) >> 2, 12, &result);
2213 dis_assemble_12 (result, &w1, &w);
2214 INSERT_FIELD_AND_CONTINUE (opcode, ((w1 << 2) | w), 0);
2216 else
2218 the_insn.reloc = R_HPPA_PCREL_CALL;
2219 the_insn.format = 12;
2220 the_insn.arg_reloc = last_call_desc.arg_reloc;
2221 memset (&last_call_desc, 0, sizeof (struct call_desc));
2222 s = expr_end;
2223 continue;
2226 /* Handle a 17 bit branch displacement. */
2227 case 'W':
2228 the_insn.field_selector = pa_chk_field_selector (&s);
2229 get_expression (s);
2230 s = expr_end;
2231 the_insn.pcrel = 1;
2232 if (!the_insn.exp.X_add_symbol
2233 || !strcmp (S_GET_NAME (the_insn.exp.X_add_symbol),
2234 "L$0\001"))
2236 unsigned int w2, w1, w, result;
2238 num = evaluate_absolute (&the_insn);
2239 if (num % 4)
2241 as_bad (_("Branch to unaligned address"));
2242 break;
2244 CHECK_FIELD (num, 262143, -262144, 0);
2246 if (the_insn.exp.X_add_symbol)
2247 num -= 8;
2249 sign_unext (num >> 2, 17, &result);
2250 dis_assemble_17 (result, &w1, &w2, &w);
2251 INSERT_FIELD_AND_CONTINUE (opcode,
2252 ((w2 << 2) | (w1 << 16) | w), 0);
2254 else
2256 the_insn.reloc = R_HPPA_PCREL_CALL;
2257 the_insn.format = 17;
2258 the_insn.arg_reloc = last_call_desc.arg_reloc;
2259 memset (&last_call_desc, 0, sizeof (struct call_desc));
2260 continue;
2263 /* Handle an absolute 17 bit branch target. */
2264 case 'z':
2265 the_insn.field_selector = pa_chk_field_selector (&s);
2266 get_expression (s);
2267 s = expr_end;
2268 the_insn.pcrel = 0;
2269 if (!the_insn.exp.X_add_symbol
2270 || !strcmp (S_GET_NAME (the_insn.exp.X_add_symbol),
2271 "L$0\001"))
2273 unsigned int w2, w1, w, result;
2275 num = evaluate_absolute (&the_insn);
2276 if (num % 4)
2278 as_bad (_("Branch to unaligned address"));
2279 break;
2281 CHECK_FIELD (num, 262143, -262144, 0);
2283 if (the_insn.exp.X_add_symbol)
2284 num -= 8;
2286 sign_unext (num >> 2, 17, &result);
2287 dis_assemble_17 (result, &w1, &w2, &w);
2288 INSERT_FIELD_AND_CONTINUE (opcode,
2289 ((w2 << 2) | (w1 << 16) | w), 0);
2291 else
2293 the_insn.reloc = R_HPPA_ABS_CALL;
2294 the_insn.format = 17;
2295 the_insn.arg_reloc = last_call_desc.arg_reloc;
2296 memset (&last_call_desc, 0, sizeof (struct call_desc));
2297 continue;
2300 /* Handle a 5 bit shift count 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, 31 - num, 5);
2307 /* Handle a 5 bit bit position at 26. */
2308 case 'P':
2309 num = pa_get_absolute_expression (&the_insn, &s);
2310 s = expr_end;
2311 CHECK_FIELD (num, 31, 0, 0);
2312 INSERT_FIELD_AND_CONTINUE (opcode, num, 5);
2314 /* Handle a 5 bit immediate at 10. */
2315 case 'Q':
2317 num = pa_get_absolute_expression (&the_insn, &s);
2318 if (the_insn.exp.X_op != O_constant)
2319 break;
2320 s = expr_end;
2321 CHECK_FIELD (num, 31, 0, 0);
2322 INSERT_FIELD_AND_CONTINUE (opcode, num, 21);
2324 /* Handle a 13 bit immediate at 18. */
2325 case 'A':
2326 num = pa_get_absolute_expression (&the_insn, &s);
2327 s = expr_end;
2328 CHECK_FIELD (num, 8191, 0, 0);
2329 INSERT_FIELD_AND_CONTINUE (opcode, num, 13);
2331 /* Handle a 26 bit immediate at 31. */
2332 case 'D':
2333 num = pa_get_absolute_expression (&the_insn, &s);
2334 s = expr_end;
2335 CHECK_FIELD (num, 671108864, 0, 0);
2336 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2338 /* Handle a 3 bit SFU identifier at 25. */
2339 case 'f':
2340 if (*s++ != ',')
2341 as_bad (_("Invalid SFU identifier"));
2342 num = pa_get_absolute_expression (&the_insn, &s);
2343 s = expr_end;
2344 CHECK_FIELD (num, 7, 0, 0);
2345 INSERT_FIELD_AND_CONTINUE (opcode, num, 6);
2347 /* Handle a 20 bit SOP field for spop0. */
2348 case 'O':
2349 num = pa_get_absolute_expression (&the_insn, &s);
2350 s = expr_end;
2351 CHECK_FIELD (num, 1048575, 0, 0);
2352 num = (num & 0x1f) | ((num & 0x000fffe0) << 6);
2353 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2355 /* Handle a 15bit SOP field for spop1. */
2356 case 'o':
2357 num = pa_get_absolute_expression (&the_insn, &s);
2358 s = expr_end;
2359 CHECK_FIELD (num, 32767, 0, 0);
2360 INSERT_FIELD_AND_CONTINUE (opcode, num, 11);
2362 /* Handle a 10bit SOP field for spop3. */
2363 case '0':
2364 num = pa_get_absolute_expression (&the_insn, &s);
2365 s = expr_end;
2366 CHECK_FIELD (num, 1023, 0, 0);
2367 num = (num & 0x1f) | ((num & 0x000003e0) << 6);
2368 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2370 /* Handle a 15 bit SOP field for spop2. */
2371 case '1':
2372 num = pa_get_absolute_expression (&the_insn, &s);
2373 s = expr_end;
2374 CHECK_FIELD (num, 32767, 0, 0);
2375 num = (num & 0x1f) | ((num & 0x00007fe0) << 6);
2376 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2378 /* Handle a 3-bit co-processor ID field. */
2379 case 'u':
2380 if (*s++ != ',')
2381 as_bad (_("Invalid COPR identifier"));
2382 num = pa_get_absolute_expression (&the_insn, &s);
2383 s = expr_end;
2384 CHECK_FIELD (num, 7, 0, 0);
2385 INSERT_FIELD_AND_CONTINUE (opcode, num, 6);
2387 /* Handle a 22bit SOP field for copr. */
2388 case '2':
2389 num = pa_get_absolute_expression (&the_insn, &s);
2390 s = expr_end;
2391 CHECK_FIELD (num, 4194303, 0, 0);
2392 num = (num & 0x1f) | ((num & 0x003fffe0) << 4);
2393 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2396 /* Handle a source FP operand format completer. */
2397 case 'F':
2398 flag = pa_parse_fp_format (&s);
2399 the_insn.fpof1 = flag;
2400 INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
2402 /* Handle a destination FP operand format completer. */
2403 case 'G':
2404 /* pa_parse_format needs the ',' prefix. */
2405 s--;
2406 flag = pa_parse_fp_format (&s);
2407 the_insn.fpof2 = flag;
2408 INSERT_FIELD_AND_CONTINUE (opcode, flag, 13);
2410 /* Handle FP compare conditions. */
2411 case 'M':
2412 cond = pa_parse_fp_cmp_cond (&s);
2413 INSERT_FIELD_AND_CONTINUE (opcode, cond, 0);
2415 /* Handle L/R register halves like 't'. */
2416 case 'v':
2418 struct pa_11_fp_reg_struct result;
2420 pa_parse_number (&s, &result);
2421 CHECK_FIELD (result.number_part, 31, 0, 0);
2422 opcode |= result.number_part;
2424 /* 0x30 opcodes are FP arithmetic operation opcodes
2425 and need to be turned into 0x38 opcodes. This
2426 is not necessary for loads/stores. */
2427 if (need_pa11_opcode (&the_insn, &result)
2428 && ((opcode & 0xfc000000) == 0x30000000))
2429 opcode |= 1 << 27;
2431 INSERT_FIELD_AND_CONTINUE (opcode, result.l_r_select & 1, 6);
2434 /* Handle L/R register halves like 'b'. */
2435 case 'E':
2437 struct pa_11_fp_reg_struct result;
2439 pa_parse_number (&s, &result);
2440 CHECK_FIELD (result.number_part, 31, 0, 0);
2441 opcode |= result.number_part << 21;
2442 if (need_pa11_opcode (&the_insn, &result))
2444 opcode |= (result.l_r_select & 1) << 7;
2445 opcode |= 1 << 27;
2447 continue;
2450 /* Handle L/R register halves like 'b'. */
2451 case '3':
2453 struct pa_11_fp_reg_struct result;
2454 int regnum;
2456 pa_parse_number (&s, &result);
2457 CHECK_FIELD (result.number_part, 31, 0, 0);
2458 opcode |= (result.number_part & 0x1c) << 11;
2459 opcode |= (result.number_part & 0x3) << 9;
2460 opcode |= (result.l_r_select & 1) << 8;
2461 continue;
2464 /* Handle L/R register halves like 'x'. */
2465 case 'e':
2467 struct pa_11_fp_reg_struct result;
2469 pa_parse_number (&s, &result);
2470 CHECK_FIELD (result.number_part, 31, 0, 0);
2471 opcode |= (result.number_part & 0x1f) << 16;
2472 if (need_pa11_opcode (&the_insn, &result))
2474 opcode |= (result.l_r_select & 1) << 1;
2476 continue;
2479 /* Handle L/R register halves like 'x'. */
2480 case 'X':
2482 struct pa_11_fp_reg_struct result;
2484 pa_parse_number (&s, &result);
2485 CHECK_FIELD (result.number_part, 31, 0, 0);
2486 opcode |= (result.number_part & 0x1f) << 16;
2487 if (need_pa11_opcode (&the_insn, &result))
2489 opcode |= (result.l_r_select & 1) << 12;
2490 opcode |= 1 << 27;
2492 continue;
2495 /* Handle a 5 bit register field at 10. */
2496 case '4':
2498 struct pa_11_fp_reg_struct result;
2500 pa_parse_number (&s, &result);
2501 CHECK_FIELD (result.number_part, 31, 0, 0);
2502 if (the_insn.fpof1 == SGL)
2504 if (result.number_part < 16)
2506 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
2507 break;
2510 result.number_part &= 0xF;
2511 result.number_part |= (result.l_r_select & 1) << 4;
2513 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 21);
2516 /* Handle a 5 bit register field at 15. */
2517 case '6':
2519 struct pa_11_fp_reg_struct result;
2521 pa_parse_number (&s, &result);
2522 CHECK_FIELD (result.number_part, 31, 0, 0);
2523 if (the_insn.fpof1 == SGL)
2525 if (result.number_part < 16)
2527 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
2528 break;
2530 result.number_part &= 0xF;
2531 result.number_part |= (result.l_r_select & 1) << 4;
2533 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 16);
2536 /* Handle a 5 bit register field at 31. */
2537 case '7':
2539 struct pa_11_fp_reg_struct result;
2541 pa_parse_number (&s, &result);
2542 CHECK_FIELD (result.number_part, 31, 0, 0);
2543 if (the_insn.fpof1 == SGL)
2545 if (result.number_part < 16)
2547 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
2548 break;
2550 result.number_part &= 0xF;
2551 result.number_part |= (result.l_r_select & 1) << 4;
2553 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 0);
2556 /* Handle a 5 bit register field at 20. */
2557 case '8':
2559 struct pa_11_fp_reg_struct result;
2561 pa_parse_number (&s, &result);
2562 CHECK_FIELD (result.number_part, 31, 0, 0);
2563 if (the_insn.fpof1 == SGL)
2565 if (result.number_part < 16)
2567 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
2568 break;
2570 result.number_part &= 0xF;
2571 result.number_part |= (result.l_r_select & 1) << 4;
2573 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 11);
2576 /* Handle a 5 bit register field at 25. */
2577 case '9':
2579 struct pa_11_fp_reg_struct result;
2581 pa_parse_number (&s, &result);
2582 CHECK_FIELD (result.number_part, 31, 0, 0);
2583 if (the_insn.fpof1 == SGL)
2585 if (result.number_part < 16)
2587 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
2588 break;
2590 result.number_part &= 0xF;
2591 result.number_part |= (result.l_r_select & 1) << 4;
2593 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 6);
2596 /* Handle a floating point operand format at 26.
2597 Only allows single and double precision. */
2598 case 'H':
2599 flag = pa_parse_fp_format (&s);
2600 switch (flag)
2602 case SGL:
2603 opcode |= 0x20;
2604 case DBL:
2605 the_insn.fpof1 = flag;
2606 continue;
2608 case QUAD:
2609 case ILLEGAL_FMT:
2610 default:
2611 as_bad (_("Invalid Floating Point Operand Format."));
2613 break;
2615 default:
2616 abort ();
2618 break;
2621 failed:
2622 /* Check if the args matched. */
2623 if (match == FALSE)
2625 if (&insn[1] - pa_opcodes < (int) NUMOPCODES
2626 && !strcmp (insn->name, insn[1].name))
2628 ++insn;
2629 s = argstart;
2630 continue;
2632 else
2634 as_bad (_("Invalid operands %s"), error_message);
2635 return;
2638 break;
2641 the_insn.opcode = opcode;
2644 /* Turn a string in input_line_pointer into a floating point constant of type
2645 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2646 emitted is stored in *sizeP . An error message or NULL is returned. */
2648 #define MAX_LITTLENUMS 6
2650 char *
2651 md_atof (type, litP, sizeP)
2652 char type;
2653 char *litP;
2654 int *sizeP;
2656 int prec;
2657 LITTLENUM_TYPE words[MAX_LITTLENUMS];
2658 LITTLENUM_TYPE *wordP;
2659 char *t;
2661 switch (type)
2664 case 'f':
2665 case 'F':
2666 case 's':
2667 case 'S':
2668 prec = 2;
2669 break;
2671 case 'd':
2672 case 'D':
2673 case 'r':
2674 case 'R':
2675 prec = 4;
2676 break;
2678 case 'x':
2679 case 'X':
2680 prec = 6;
2681 break;
2683 case 'p':
2684 case 'P':
2685 prec = 6;
2686 break;
2688 default:
2689 *sizeP = 0;
2690 return _("Bad call to MD_ATOF()");
2692 t = atof_ieee (input_line_pointer, type, words);
2693 if (t)
2694 input_line_pointer = t;
2695 *sizeP = prec * sizeof (LITTLENUM_TYPE);
2696 for (wordP = words; prec--;)
2698 md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE));
2699 litP += sizeof (LITTLENUM_TYPE);
2701 return NULL;
2704 /* Write out big-endian. */
2706 void
2707 md_number_to_chars (buf, val, n)
2708 char *buf;
2709 valueT val;
2710 int n;
2712 number_to_chars_bigendian (buf, val, n);
2715 /* Translate internal representation of relocation info to BFD target
2716 format. */
2718 arelent **
2719 tc_gen_reloc (section, fixp)
2720 asection *section;
2721 fixS *fixp;
2723 arelent *reloc;
2724 struct hppa_fix_struct *hppa_fixp;
2725 bfd_reloc_code_real_type code;
2726 static arelent *no_relocs = NULL;
2727 arelent **relocs;
2728 bfd_reloc_code_real_type **codes;
2729 int n_relocs;
2730 int i;
2732 hppa_fixp = (struct hppa_fix_struct *) fixp->tc_fix_data;
2733 if (fixp->fx_addsy == 0)
2734 return &no_relocs;
2735 assert (hppa_fixp != 0);
2736 assert (section != 0);
2738 reloc = (arelent *) xmalloc (sizeof (arelent));
2740 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2741 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2742 codes = (bfd_reloc_code_real_type **) hppa_gen_reloc_type (stdoutput,
2743 fixp->fx_r_type,
2744 hppa_fixp->fx_r_format,
2745 hppa_fixp->fx_r_field,
2746 fixp->fx_subsy != NULL,
2747 symbol_get_bfdsym (fixp->fx_addsy));
2749 if (codes == NULL)
2750 abort ();
2752 for (n_relocs = 0; codes[n_relocs]; n_relocs++)
2755 relocs = (arelent **) xmalloc (sizeof (arelent *) * n_relocs + 1);
2756 reloc = (arelent *) xmalloc (sizeof (arelent) * n_relocs);
2757 for (i = 0; i < n_relocs; i++)
2758 relocs[i] = &reloc[i];
2760 relocs[n_relocs] = NULL;
2762 #ifdef OBJ_ELF
2763 switch (fixp->fx_r_type)
2765 default:
2766 assert (n_relocs == 1);
2768 code = *codes[0];
2770 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2771 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2772 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
2773 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2774 reloc->addend = 0; /* default */
2776 assert (reloc->howto && code == reloc->howto->type);
2778 /* Now, do any processing that is dependent on the relocation type. */
2779 switch (code)
2781 case R_PARISC_DLTREL21L:
2782 case R_PARISC_DLTREL14R:
2783 case R_PARISC_DLTREL14F:
2784 case R_PARISC_PLABEL32:
2785 case R_PARISC_PLABEL21L:
2786 case R_PARISC_PLABEL14R:
2787 /* For plabel relocations, the addend of the
2788 relocation should be either 0 (no static link) or 2
2789 (static link required).
2791 FIXME: We always assume no static link!
2793 We also slam a zero addend into the DLT relative relocs;
2794 it doesn't make a lot of sense to use any addend since
2795 it gets you a different (eg unknown) DLT entry. */
2796 reloc->addend = 0;
2797 break;
2799 case R_PARISC_PCREL21L:
2800 case R_PARISC_PCREL17R:
2801 case R_PARISC_PCREL17F:
2802 case R_PARISC_PCREL17C:
2803 case R_PARISC_PCREL14R:
2804 case R_PARISC_PCREL14F:
2805 /* The constant is stored in the instruction. */
2806 reloc->addend = HPPA_R_ADDEND (hppa_fixp->fx_arg_reloc, 0);
2807 break;
2808 default:
2809 reloc->addend = fixp->fx_offset;
2810 break;
2812 break;
2814 #else /* OBJ_SOM */
2816 /* Walk over reach relocation returned by the BFD backend. */
2817 for (i = 0; i < n_relocs; i++)
2819 code = *codes[i];
2821 relocs[i]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2822 *relocs[i]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2823 relocs[i]->howto = bfd_reloc_type_lookup (stdoutput, code);
2824 relocs[i]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2826 switch (code)
2828 case R_COMP2:
2829 /* The only time we ever use a R_COMP2 fixup is for the difference
2830 of two symbols. With that in mind we fill in all four
2831 relocs now and break out of the loop. */
2832 assert (i == 1);
2833 relocs[0]->sym_ptr_ptr = (asymbol **) &(bfd_abs_symbol);
2834 relocs[0]->howto = bfd_reloc_type_lookup (stdoutput, *codes[0]);
2835 relocs[0]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2836 relocs[0]->addend = 0;
2837 relocs[1]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2838 *relocs[1]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2839 relocs[1]->howto = bfd_reloc_type_lookup (stdoutput, *codes[1]);
2840 relocs[1]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2841 relocs[1]->addend = 0;
2842 relocs[2]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2843 *relocs[2]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_subsy);
2844 relocs[2]->howto = bfd_reloc_type_lookup (stdoutput, *codes[2]);
2845 relocs[2]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2846 relocs[2]->addend = 0;
2847 relocs[3]->sym_ptr_ptr = (asymbol **) &(bfd_abs_symbol);
2848 relocs[3]->howto = bfd_reloc_type_lookup (stdoutput, *codes[3]);
2849 relocs[3]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2850 relocs[3]->addend = 0;
2851 relocs[4]->sym_ptr_ptr = (asymbol **) &(bfd_abs_symbol);
2852 relocs[4]->howto = bfd_reloc_type_lookup (stdoutput, *codes[4]);
2853 relocs[4]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2854 relocs[4]->addend = 0;
2855 goto done;
2856 case R_PCREL_CALL:
2857 case R_ABS_CALL:
2858 relocs[i]->addend = HPPA_R_ADDEND (hppa_fixp->fx_arg_reloc, 0);
2859 break;
2861 case R_DLT_REL:
2862 case R_DATA_PLABEL:
2863 case R_CODE_PLABEL:
2864 /* For plabel relocations, the addend of the
2865 relocation should be either 0 (no static link) or 2
2866 (static link required).
2868 FIXME: We always assume no static link!
2870 We also slam a zero addend into the DLT relative relocs;
2871 it doesn't make a lot of sense to use any addend since
2872 it gets you a different (eg unknown) DLT entry. */
2873 relocs[i]->addend = 0;
2874 break;
2876 case R_N_MODE:
2877 case R_S_MODE:
2878 case R_D_MODE:
2879 case R_R_MODE:
2880 case R_FSEL:
2881 case R_LSEL:
2882 case R_RSEL:
2883 case R_BEGIN_BRTAB:
2884 case R_END_BRTAB:
2885 case R_BEGIN_TRY:
2886 case R_N0SEL:
2887 case R_N1SEL:
2888 /* There is no symbol or addend associated with these fixups. */
2889 relocs[i]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2890 *relocs[i]->sym_ptr_ptr = symbol_get_bfdsym (dummy_symbol);
2891 relocs[i]->addend = 0;
2892 break;
2894 case R_END_TRY:
2895 case R_ENTRY:
2896 case R_EXIT:
2897 /* There is no symbol associated with these fixups. */
2898 relocs[i]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2899 *relocs[i]->sym_ptr_ptr = symbol_get_bfdsym (dummy_symbol);
2900 relocs[i]->addend = fixp->fx_offset;
2901 break;
2903 default:
2904 relocs[i]->addend = fixp->fx_offset;
2908 done:
2909 #endif
2911 return relocs;
2914 /* Process any machine dependent frag types. */
2916 void
2917 md_convert_frag (abfd, sec, fragP)
2918 register bfd *abfd;
2919 register asection *sec;
2920 register fragS *fragP;
2922 unsigned int address;
2924 if (fragP->fr_type == rs_machine_dependent)
2926 switch ((int) fragP->fr_subtype)
2928 case 0:
2929 fragP->fr_type = rs_fill;
2930 know (fragP->fr_var == 1);
2931 know (fragP->fr_next);
2932 address = fragP->fr_address + fragP->fr_fix;
2933 if (address % fragP->fr_offset)
2935 fragP->fr_offset =
2936 fragP->fr_next->fr_address
2937 - fragP->fr_address
2938 - fragP->fr_fix;
2940 else
2941 fragP->fr_offset = 0;
2942 break;
2947 /* Round up a section size to the appropriate boundary. */
2949 valueT
2950 md_section_align (segment, size)
2951 asection *segment;
2952 valueT size;
2954 int align = bfd_get_section_alignment (stdoutput, segment);
2955 int align2 = (1 << align) - 1;
2957 return (size + align2) & ~align2;
2960 /* Return the approximate size of a frag before relaxation has occurred. */
2962 md_estimate_size_before_relax (fragP, segment)
2963 register fragS *fragP;
2964 asection *segment;
2966 int size;
2968 size = 0;
2970 while ((fragP->fr_fix + size) % fragP->fr_offset)
2971 size++;
2973 return size;
2976 CONST char *md_shortopts = "";
2977 struct option md_longopts[] = {
2978 {NULL, no_argument, NULL, 0}
2980 size_t md_longopts_size = sizeof(md_longopts);
2983 md_parse_option (c, arg)
2984 int c;
2985 char *arg;
2987 return 0;
2990 void
2991 md_show_usage (stream)
2992 FILE *stream;
2996 /* We have no need to default values of symbols. */
2998 symbolS *
2999 md_undefined_symbol (name)
3000 char *name;
3002 return 0;
3005 /* Apply a fixup to an instruction. */
3008 md_apply_fix (fixP, valp)
3009 fixS *fixP;
3010 valueT *valp;
3012 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
3013 struct hppa_fix_struct *hppa_fixP;
3014 long new_val, result = 0;
3015 unsigned int w1, w2, w, resulti;
3017 hppa_fixP = (struct hppa_fix_struct *) fixP->tc_fix_data;
3018 /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
3019 never be "applied" (they are just markers). Likewise for
3020 R_HPPA_BEGIN_BRTAB and R_HPPA_END_BRTAB. */
3021 #ifdef OBJ_SOM
3022 if (fixP->fx_r_type == R_HPPA_ENTRY
3023 || fixP->fx_r_type == R_HPPA_EXIT
3024 || fixP->fx_r_type == R_HPPA_BEGIN_BRTAB
3025 || fixP->fx_r_type == R_HPPA_END_BRTAB
3026 || fixP->fx_r_type == R_HPPA_BEGIN_TRY)
3027 return 1;
3029 /* Disgusting. We must set fx_offset ourselves -- R_HPPA_END_TRY
3030 fixups are considered not adjustable, which in turn causes
3031 adjust_reloc_syms to not set fx_offset. Ugh. */
3032 if (fixP->fx_r_type == R_HPPA_END_TRY)
3034 fixP->fx_offset = *valp;
3035 return 1;
3037 #endif
3039 /* There should have been an HPPA specific fixup associated
3040 with the GAS fixup. */
3041 if (hppa_fixP)
3043 unsigned long buf_wd = bfd_get_32 (stdoutput, buf);
3044 unsigned char fmt = bfd_hppa_insn2fmt (buf_wd);
3046 /* If there is a symbol associated with this fixup, then it's something
3047 which will need a SOM relocation (except for some PC-relative relocs).
3048 In such cases we should treat the "val" or "addend" as zero since it
3049 will be added in as needed from fx_offset in tc_gen_reloc. */
3050 if ((fixP->fx_addsy != NULL
3051 || fixP->fx_r_type == R_HPPA_NONE)
3052 #ifdef OBJ_SOM
3053 && fmt != 32
3054 #endif
3056 new_val = ((fmt == 12 || fmt == 17 || fmt == 22) ? 8 : 0);
3057 #ifdef OBJ_SOM
3058 /* These field selectors imply that we do not want an addend. */
3059 else if (hppa_fixP->fx_r_field == e_psel
3060 || hppa_fixP->fx_r_field == e_rpsel
3061 || hppa_fixP->fx_r_field == e_lpsel
3062 || hppa_fixP->fx_r_field == e_tsel
3063 || hppa_fixP->fx_r_field == e_rtsel
3064 || hppa_fixP->fx_r_field == e_ltsel)
3065 new_val = ((fmt == 12 || fmt == 17 || fmt == 22) ? 8 : 0);
3066 /* This is truely disgusting. The machine independent code blindly
3067 adds in the value of the symbol being relocated against. Damn! */
3068 else if (fmt == 32
3069 && fixP->fx_addsy != NULL
3070 && S_GET_SEGMENT (fixP->fx_addsy) != bfd_com_section_ptr)
3071 new_val = hppa_field_adjust (*valp - S_GET_VALUE (fixP->fx_addsy),
3072 0, hppa_fixP->fx_r_field);
3073 #endif
3074 else
3075 new_val = hppa_field_adjust (*valp, 0, hppa_fixP->fx_r_field);
3077 /* Handle pc-relative exceptions from above. */
3078 #define arg_reloc_stub_needed(CALLER, CALLEE) \
3079 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
3080 if ((fmt == 12 || fmt == 17 || fmt == 22)
3081 && fixP->fx_addsy
3082 && fixP->fx_pcrel
3083 && !arg_reloc_stub_needed ((long) ((obj_symbol_type *)
3084 symbol_get_bfdsym (fixP->fx_addsy))->tc_data.ap.hppa_arg_reloc,
3085 hppa_fixP->fx_arg_reloc)
3086 && (((int)(*valp) > -262144 && (int)(*valp) < 262143) && fmt != 22)
3087 && S_GET_SEGMENT (fixP->fx_addsy) == hppa_fixP->segment
3088 && !(fixP->fx_subsy
3089 && S_GET_SEGMENT (fixP->fx_subsy) != hppa_fixP->segment))
3091 new_val = hppa_field_adjust (*valp, 0, hppa_fixP->fx_r_field);
3092 #undef arg_reloc_stub_needed
3094 switch (fmt)
3096 /* Handle all opcodes with the 'j' operand type. */
3097 case 14:
3098 CHECK_FIELD (new_val, 8191, -8192, 0);
3100 /* Mask off 14 bits to be changed. */
3101 bfd_put_32 (stdoutput,
3102 bfd_get_32 (stdoutput, buf) & 0xffffc000,
3103 buf);
3104 low_sign_unext (new_val, 14, &resulti);
3105 result = resulti;
3106 break;
3108 /* Handle all opcodes with the 'k' operand type. */
3109 case 21:
3110 CHECK_FIELD (new_val, 2097152, 0, 0);
3112 /* Mask off 21 bits to be changed. */
3113 bfd_put_32 (stdoutput,
3114 bfd_get_32 (stdoutput, buf) & 0xffe00000,
3115 buf);
3116 dis_assemble_21 (new_val, &resulti);
3117 result = resulti;
3118 break;
3120 /* Handle all the opcodes with the 'i' operand type. */
3121 case 11:
3122 CHECK_FIELD (new_val, 1023, -1023, 0);
3124 /* Mask off 11 bits to be changed. */
3125 bfd_put_32 (stdoutput,
3126 bfd_get_32 (stdoutput, buf) & 0xffff800,
3127 buf);
3128 low_sign_unext (new_val, 11, &resulti);
3129 result = resulti;
3130 break;
3132 /* Handle all the opcodes with the 'w' operand type. */
3133 case 12:
3134 CHECK_FIELD (new_val, 8199, -8184, 0);
3136 /* Mask off 11 bits to be changed. */
3137 sign_unext ((new_val - 8) >> 2, 12, &resulti);
3138 bfd_put_32 (stdoutput,
3139 bfd_get_32 (stdoutput, buf) & 0xffffe002,
3140 buf);
3142 dis_assemble_12 (resulti, &w1, &w);
3143 result = ((w1 << 2) | w);
3144 break;
3146 /* Handle some of the opcodes with the 'W' operand type. */
3147 case 17:
3149 int distance = *valp;
3151 CHECK_FIELD (new_val, 262143, -262144, 0);
3153 /* If this is an absolute branch (ie no link) with an out of
3154 range target, then we want to complain. */
3155 if (fixP->fx_r_type == R_HPPA_PCREL_CALL
3156 && (distance > 262143 || distance < -262144)
3157 && (bfd_get_32 (stdoutput, buf) & 0xffe00000) == 0xe8000000)
3158 CHECK_FIELD (distance, 262143, -262144, 0);
3160 /* Mask off 17 bits to be changed. */
3161 bfd_put_32 (stdoutput,
3162 bfd_get_32 (stdoutput, buf) & 0xffe0e002,
3163 buf);
3164 sign_unext ((new_val - 8) >> 2, 17, &resulti);
3165 dis_assemble_17 (resulti, &w1, &w2, &w);
3166 result = ((w2 << 2) | (w1 << 16) | w);
3167 break;
3170 case 32:
3171 result = 0;
3172 bfd_put_32 (stdoutput, new_val, buf);
3173 break;
3175 default:
3176 as_bad (_("Unknown relocation encountered in md_apply_fix."));
3177 return 0;
3180 /* Insert the relocation. */
3181 bfd_put_32 (stdoutput, bfd_get_32 (stdoutput, buf) | result, buf);
3182 return 1;
3184 else
3186 printf (_("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n"),
3187 (unsigned int) fixP, fixP->fx_r_type);
3188 return 0;
3192 /* Exactly what point is a PC-relative offset relative TO?
3193 On the PA, they're relative to the address of the offset. */
3195 long
3196 md_pcrel_from (fixP)
3197 fixS *fixP;
3199 return fixP->fx_where + fixP->fx_frag->fr_address;
3202 /* Return nonzero if the input line pointer is at the end of
3203 a statement. */
3205 static int
3206 is_end_of_statement ()
3208 return ((*input_line_pointer == '\n')
3209 || (*input_line_pointer == ';')
3210 || (*input_line_pointer == '!'));
3213 /* Read a number from S. The number might come in one of many forms,
3214 the most common will be a hex or decimal constant, but it could be
3215 a pre-defined register (Yuk!), or an absolute symbol.
3217 Return a number or -1 for failure.
3219 When parsing PA-89 FP register numbers RESULT will be
3220 the address of a structure to return information about
3221 L/R half of FP registers, store results there as appropriate.
3223 pa_parse_number can not handle negative constants and will fail
3224 horribly if it is passed such a constant. */
3226 static int
3227 pa_parse_number (s, result)
3228 char **s;
3229 struct pa_11_fp_reg_struct *result;
3231 int num;
3232 char *name;
3233 char c;
3234 symbolS *sym;
3235 int status;
3236 char *p = *s;
3238 /* Skip whitespace before the number. */
3239 while (*p == ' ' || *p == '\t')
3240 p = p + 1;
3242 /* Store info in RESULT if requested by caller. */
3243 if (result)
3245 result->number_part = -1;
3246 result->l_r_select = -1;
3248 num = -1;
3250 if (isdigit (*p))
3252 /* Looks like a number. */
3253 num = 0;
3255 if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X'))
3257 /* The number is specified in hex. */
3258 p += 2;
3259 while (isdigit (*p) || ((*p >= 'a') && (*p <= 'f'))
3260 || ((*p >= 'A') && (*p <= 'F')))
3262 if (isdigit (*p))
3263 num = num * 16 + *p - '0';
3264 else if (*p >= 'a' && *p <= 'f')
3265 num = num * 16 + *p - 'a' + 10;
3266 else
3267 num = num * 16 + *p - 'A' + 10;
3268 ++p;
3271 else
3273 /* The number is specified in decimal. */
3274 while (isdigit (*p))
3276 num = num * 10 + *p - '0';
3277 ++p;
3281 /* Store info in RESULT if requested by the caller. */
3282 if (result)
3284 result->number_part = num;
3286 if (IS_R_SELECT (p))
3288 result->l_r_select = 1;
3289 ++p;
3291 else if (IS_L_SELECT (p))
3293 result->l_r_select = 0;
3294 ++p;
3296 else
3297 result->l_r_select = 0;
3300 else if (*p == '%')
3302 /* The number might be a predefined register. */
3303 num = 0;
3304 name = p;
3305 p++;
3306 c = *p;
3307 /* Tege hack: Special case for general registers as the general
3308 code makes a binary search with case translation, and is VERY
3309 slow. */
3310 if (c == 'r')
3312 p++;
3313 if (*p == 'e' && *(p + 1) == 't'
3314 && (*(p + 2) == '0' || *(p + 2) == '1'))
3316 p += 2;
3317 num = *p - '0' + 28;
3318 p++;
3320 else if (*p == 'p')
3322 num = 2;
3323 p++;
3325 else if (!isdigit (*p))
3327 if (print_errors)
3328 as_bad (_("Undefined register: '%s'."), name);
3329 num = -1;
3331 else
3334 num = num * 10 + *p++ - '0';
3335 while (isdigit (*p));
3338 else
3340 /* Do a normal register search. */
3341 while (is_part_of_name (c))
3343 p = p + 1;
3344 c = *p;
3346 *p = 0;
3347 status = reg_name_search (name);
3348 if (status >= 0)
3349 num = status;
3350 else
3352 if (print_errors)
3353 as_bad (_("Undefined register: '%s'."), name);
3354 num = -1;
3356 *p = c;
3359 /* Store info in RESULT if requested by caller. */
3360 if (result)
3362 result->number_part = num;
3363 if (IS_R_SELECT (p - 1))
3364 result->l_r_select = 1;
3365 else if (IS_L_SELECT (p - 1))
3366 result->l_r_select = 0;
3367 else
3368 result->l_r_select = 0;
3371 else
3373 /* And finally, it could be a symbol in the absolute section which
3374 is effectively a constant. */
3375 num = 0;
3376 name = p;
3377 c = *p;
3378 while (is_part_of_name (c))
3380 p = p + 1;
3381 c = *p;
3383 *p = 0;
3384 if ((sym = symbol_find (name)) != NULL)
3386 if (S_GET_SEGMENT (sym) == &bfd_abs_section)
3387 num = S_GET_VALUE (sym);
3388 else
3390 if (print_errors)
3391 as_bad (_("Non-absolute symbol: '%s'."), name);
3392 num = -1;
3395 else
3397 /* There is where we'd come for an undefined symbol
3398 or for an empty string. For an empty string we
3399 will return zero. That's a concession made for
3400 compatability with the braindamaged HP assemblers. */
3401 if (*name == 0)
3402 num = 0;
3403 else
3405 if (print_errors)
3406 as_bad (_("Undefined absolute constant: '%s'."), name);
3407 num = -1;
3410 *p = c;
3412 /* Store info in RESULT if requested by caller. */
3413 if (result)
3415 result->number_part = num;
3416 if (IS_R_SELECT (p - 1))
3417 result->l_r_select = 1;
3418 else if (IS_L_SELECT (p - 1))
3419 result->l_r_select = 0;
3420 else
3421 result->l_r_select = 0;
3425 *s = p;
3426 return num;
3429 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
3431 /* Given NAME, find the register number associated with that name, return
3432 the integer value associated with the given name or -1 on failure. */
3434 static int
3435 reg_name_search (name)
3436 char *name;
3438 int middle, low, high;
3439 int cmp;
3441 low = 0;
3442 high = REG_NAME_CNT - 1;
3446 middle = (low + high) / 2;
3447 cmp = strcasecmp (name, pre_defined_registers[middle].name);
3448 if (cmp < 0)
3449 high = middle - 1;
3450 else if (cmp > 0)
3451 low = middle + 1;
3452 else
3453 return pre_defined_registers[middle].value;
3455 while (low <= high);
3457 return -1;
3461 /* Return nonzero if the given INSN and L/R information will require
3462 a new PA-1.1 opcode. */
3464 static int
3465 need_pa11_opcode (insn, result)
3466 struct pa_it *insn;
3467 struct pa_11_fp_reg_struct *result;
3469 if (result->l_r_select == 1 && !(insn->fpof1 == DBL && insn->fpof2 == DBL))
3471 /* If this instruction is specific to a particular architecture,
3472 then set a new architecture. */
3473 if (bfd_get_mach (stdoutput) < pa11)
3475 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, pa11))
3476 as_warn (_("could not update architecture and machine"));
3478 return TRUE;
3480 else
3481 return FALSE;
3484 /* Parse a condition for a fcmp instruction. Return the numerical
3485 code associated with the condition. */
3487 static int
3488 pa_parse_fp_cmp_cond (s)
3489 char **s;
3491 int cond, i;
3493 cond = 0;
3495 for (i = 0; i < 32; i++)
3497 if (strncasecmp (*s, fp_cond_map[i].string,
3498 strlen (fp_cond_map[i].string)) == 0)
3500 cond = fp_cond_map[i].cond;
3501 *s += strlen (fp_cond_map[i].string);
3502 /* If not a complete match, back up the input string and
3503 report an error. */
3504 if (**s != ' ' && **s != '\t')
3506 *s -= strlen (fp_cond_map[i].string);
3507 break;
3509 while (**s == ' ' || **s == '\t')
3510 *s = *s + 1;
3511 return cond;
3515 as_bad (_("Invalid FP Compare Condition: %s"), *s);
3517 /* Advance over the bogus completer. */
3518 while (**s != ',' && **s != ' ' && **s != '\t')
3519 *s += 1;
3521 return 0;
3525 /* Parse an FP operand format completer returning the completer
3526 type. */
3528 static fp_operand_format
3529 pa_parse_fp_format (s)
3530 char **s;
3532 int format;
3534 format = SGL;
3535 if (**s == ',')
3537 *s += 1;
3538 if (strncasecmp (*s, "sgl", 3) == 0)
3540 format = SGL;
3541 *s += 4;
3543 else if (strncasecmp (*s, "dbl", 3) == 0)
3545 format = DBL;
3546 *s += 4;
3548 else if (strncasecmp (*s, "quad", 4) == 0)
3550 format = QUAD;
3551 *s += 5;
3553 else
3555 format = ILLEGAL_FMT;
3556 as_bad (_("Invalid FP Operand Format: %3s"), *s);
3560 return format;
3563 /* Convert from a selector string into a selector type. */
3565 static int
3566 pa_chk_field_selector (str)
3567 char **str;
3569 int middle, low, high;
3570 int cmp;
3571 char name[4];
3573 /* Read past any whitespace. */
3574 /* FIXME: should we read past newlines and formfeeds??? */
3575 while (**str == ' ' || **str == '\t' || **str == '\n' || **str == '\f')
3576 *str = *str + 1;
3578 if ((*str)[1] == '\'' || (*str)[1] == '%')
3579 name[0] = tolower ((*str)[0]),
3580 name[1] = 0;
3581 else if ((*str)[2] == '\'' || (*str)[2] == '%')
3582 name[0] = tolower ((*str)[0]),
3583 name[1] = tolower ((*str)[1]),
3584 name[2] = 0;
3585 #ifdef OBJ_SOM
3586 else if ((*str)[3] == '\'' || (*str)[3] == '%')
3587 name[0] = tolower ((*str)[0]),
3588 name[1] = tolower ((*str)[1]),
3589 name[2] = tolower ((*str)[2]),
3590 name[3] = 0;
3591 #endif
3592 else
3593 return e_fsel;
3595 low = 0;
3596 high = sizeof (selector_table) / sizeof (struct selector_entry) - 1;
3600 middle = (low + high) / 2;
3601 cmp = strcmp (name, selector_table[middle].prefix);
3602 if (cmp < 0)
3603 high = middle - 1;
3604 else if (cmp > 0)
3605 low = middle + 1;
3606 else
3608 *str += strlen (name) + 1;
3609 #ifndef OBJ_SOM
3610 if (selector_table[middle].field_selector == e_nsel)
3611 return e_fsel;
3612 #endif
3613 return selector_table[middle].field_selector;
3616 while (low <= high);
3618 return e_fsel;
3621 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
3623 static int
3624 get_expression (str)
3625 char *str;
3627 char *save_in;
3628 asection *seg;
3630 save_in = input_line_pointer;
3631 input_line_pointer = str;
3632 seg = expression (&the_insn.exp);
3633 if (!(seg == absolute_section
3634 || seg == undefined_section
3635 || SEG_NORMAL (seg)))
3637 as_warn (_("Bad segment in expression."));
3638 expr_end = input_line_pointer;
3639 input_line_pointer = save_in;
3640 return 1;
3642 expr_end = input_line_pointer;
3643 input_line_pointer = save_in;
3644 return 0;
3647 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
3648 static int
3649 pa_get_absolute_expression (insn, strp)
3650 struct pa_it *insn;
3651 char **strp;
3653 char *save_in;
3655 insn->field_selector = pa_chk_field_selector (strp);
3656 save_in = input_line_pointer;
3657 input_line_pointer = *strp;
3658 expression (&insn->exp);
3659 /* This is not perfect, but is a huge improvement over doing nothing.
3661 The PA assembly syntax is ambigious in a variety of ways. Consider
3662 this string "4 %r5" Is that the number 4 followed by the register
3663 r5, or is that 4 MOD 5?
3665 If we get a modulo expresion When looking for an absolute, we try
3666 again cutting off the input string at the first whitespace character. */
3667 if (insn->exp.X_op == O_modulus)
3669 char *s, c;
3670 int retval;
3672 input_line_pointer = *strp;
3673 s = *strp;
3674 while (*s != ',' && *s != ' ' && *s != '\t')
3675 s++;
3677 c = *s;
3678 *s = 0;
3680 retval = pa_get_absolute_expression (insn, strp);
3682 input_line_pointer = save_in;
3683 *s = c;
3684 return evaluate_absolute (insn);
3686 if (insn->exp.X_op != O_constant)
3688 as_bad (_("Bad segment (should be absolute)."));
3689 expr_end = input_line_pointer;
3690 input_line_pointer = save_in;
3691 return 0;
3693 expr_end = input_line_pointer;
3694 input_line_pointer = save_in;
3695 return evaluate_absolute (insn);
3698 /* Evaluate an absolute expression EXP which may be modified by
3699 the selector FIELD_SELECTOR. Return the value of the expression. */
3700 static int
3701 evaluate_absolute (insn)
3702 struct pa_it *insn;
3704 int value;
3705 expressionS exp;
3706 int field_selector = insn->field_selector;
3708 exp = insn->exp;
3709 value = exp.X_add_number;
3711 switch (field_selector)
3713 /* No change. */
3714 case e_fsel:
3715 break;
3717 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
3718 case e_lssel:
3719 if (value & 0x00000400)
3720 value += 0x800;
3721 value = (value & 0xfffff800) >> 11;
3722 break;
3724 /* Sign extend from bit 21. */
3725 case e_rssel:
3726 if (value & 0x00000400)
3727 value |= 0xfffff800;
3728 else
3729 value &= 0x7ff;
3730 break;
3732 /* Arithmetic shift right 11 bits. */
3733 case e_lsel:
3734 value = (value & 0xfffff800) >> 11;
3735 break;
3737 /* Set bits 0-20 to zero. */
3738 case e_rsel:
3739 value = value & 0x7ff;
3740 break;
3742 /* Add 0x800 and arithmetic shift right 11 bits. */
3743 case e_ldsel:
3744 value += 0x800;
3745 value = (value & 0xfffff800) >> 11;
3746 break;
3748 /* Set bitgs 0-21 to one. */
3749 case e_rdsel:
3750 value |= 0xfffff800;
3751 break;
3753 #define RSEL_ROUND(c) (((c) + 0x1000) & ~0x1fff)
3754 case e_rrsel:
3755 value = (RSEL_ROUND (value) & 0x7ff) + (value - RSEL_ROUND (value));
3756 break;
3758 case e_lrsel:
3759 value = (RSEL_ROUND (value) >> 11) & 0x1fffff;
3760 break;
3761 #undef RSEL_ROUND
3763 default:
3764 BAD_CASE (field_selector);
3765 break;
3767 return value;
3770 /* Given an argument location specification return the associated
3771 argument location number. */
3773 static unsigned int
3774 pa_build_arg_reloc (type_name)
3775 char *type_name;
3778 if (strncasecmp (type_name, "no", 2) == 0)
3779 return 0;
3780 if (strncasecmp (type_name, "gr", 2) == 0)
3781 return 1;
3782 else if (strncasecmp (type_name, "fr", 2) == 0)
3783 return 2;
3784 else if (strncasecmp (type_name, "fu", 2) == 0)
3785 return 3;
3786 else
3787 as_bad (_("Invalid argument location: %s\n"), type_name);
3789 return 0;
3792 /* Encode and return an argument relocation specification for
3793 the given register in the location specified by arg_reloc. */
3795 static unsigned int
3796 pa_align_arg_reloc (reg, arg_reloc)
3797 unsigned int reg;
3798 unsigned int arg_reloc;
3800 unsigned int new_reloc;
3802 new_reloc = arg_reloc;
3803 switch (reg)
3805 case 0:
3806 new_reloc <<= 8;
3807 break;
3808 case 1:
3809 new_reloc <<= 6;
3810 break;
3811 case 2:
3812 new_reloc <<= 4;
3813 break;
3814 case 3:
3815 new_reloc <<= 2;
3816 break;
3817 default:
3818 as_bad (_("Invalid argument description: %d"), reg);
3821 return new_reloc;
3824 /* Parse a PA nullification completer (,n). Return nonzero if the
3825 completer was found; return zero if no completer was found. */
3827 static int
3828 pa_parse_nullif (s)
3829 char **s;
3831 int nullif;
3833 nullif = 0;
3834 if (**s == ',')
3836 *s = *s + 1;
3837 if (strncasecmp (*s, "n", 1) == 0)
3838 nullif = 1;
3839 else
3841 as_bad (_("Invalid Nullification: (%c)"), **s);
3842 nullif = 0;
3844 *s = *s + 1;
3847 return nullif;
3850 /* Parse a non-negated compare/subtract completer returning the
3851 number (for encoding in instrutions) of the given completer.
3853 ISBRANCH specifies whether or not this is parsing a condition
3854 completer for a branch (vs a nullification completer for a
3855 computational instruction. */
3857 static int
3858 pa_parse_nonneg_cmpsub_cmpltr (s, isbranch)
3859 char **s;
3860 int isbranch;
3862 int cmpltr;
3863 char *name = *s + 1;
3864 char c;
3865 char *save_s = *s;
3866 int nullify = 0;
3868 cmpltr = 0;
3869 if (**s == ',')
3871 *s += 1;
3872 while (**s != ',' && **s != ' ' && **s != '\t')
3873 *s += 1;
3874 c = **s;
3875 **s = 0x00;
3878 if (strcmp (name, "=") == 0)
3880 cmpltr = 1;
3882 else if (strcmp (name, "<") == 0)
3884 cmpltr = 2;
3886 else if (strcmp (name, "<=") == 0)
3888 cmpltr = 3;
3890 else if (strcmp (name, "<<") == 0)
3892 cmpltr = 4;
3894 else if (strcmp (name, "<<=") == 0)
3896 cmpltr = 5;
3898 else if (strcasecmp (name, "sv") == 0)
3900 cmpltr = 6;
3902 else if (strcasecmp (name, "od") == 0)
3904 cmpltr = 7;
3906 /* If we have something like addb,n then there is no condition
3907 completer. */
3908 else if (strcasecmp (name, "n") == 0 && isbranch)
3910 cmpltr = 0;
3911 nullify = 1;
3913 else
3915 cmpltr = -1;
3917 **s = c;
3920 /* Reset pointers if this was really a ,n for a branch instruction. */
3921 if (nullify)
3922 *s = save_s;
3925 return cmpltr;
3928 /* Parse a negated compare/subtract completer returning the
3929 number (for encoding in instrutions) of the given completer.
3931 ISBRANCH specifies whether or not this is parsing a condition
3932 completer for a branch (vs a nullification completer for a
3933 computational instruction. */
3935 static int
3936 pa_parse_neg_cmpsub_cmpltr (s, isbranch)
3937 char **s;
3938 int isbranch;
3940 int cmpltr;
3941 char *name = *s + 1;
3942 char c;
3943 char *save_s = *s;
3944 int nullify = 0;
3946 cmpltr = 0;
3947 if (**s == ',')
3949 *s += 1;
3950 while (**s != ',' && **s != ' ' && **s != '\t')
3951 *s += 1;
3952 c = **s;
3953 **s = 0x00;
3956 if (strcasecmp (name, "tr") == 0)
3958 cmpltr = 0;
3960 else if (strcmp (name, "<>") == 0)
3962 cmpltr = 1;
3964 else if (strcmp (name, ">=") == 0)
3966 cmpltr = 2;
3968 else if (strcmp (name, ">") == 0)
3970 cmpltr = 3;
3972 else if (strcmp (name, ">>=") == 0)
3974 cmpltr = 4;
3976 else if (strcmp (name, ">>") == 0)
3978 cmpltr = 5;
3980 else if (strcasecmp (name, "nsv") == 0)
3982 cmpltr = 6;
3984 else if (strcasecmp (name, "ev") == 0)
3986 cmpltr = 7;
3988 /* If we have something like addb,n then there is no condition
3989 completer. */
3990 else if (strcasecmp (name, "n") == 0 && isbranch)
3992 cmpltr = 0;
3993 nullify = 1;
3995 else
3997 cmpltr = -1;
3999 **s = c;
4002 /* Reset pointers if this was really a ,n for a branch instruction. */
4003 if (nullify)
4004 *s = save_s;
4007 return cmpltr;
4011 /* Parse a non-negated addition completer returning the number
4012 (for encoding in instrutions) of the given completer.
4014 ISBRANCH specifies whether or not this is parsing a condition
4015 completer for a branch (vs a nullification completer for a
4016 computational instruction. */
4018 static int
4019 pa_parse_nonneg_add_cmpltr (s, isbranch)
4020 char **s;
4021 int isbranch;
4023 int cmpltr;
4024 char *name = *s + 1;
4025 char c;
4026 char *save_s = *s;
4028 cmpltr = 0;
4029 if (**s == ',')
4031 *s += 1;
4032 while (**s != ',' && **s != ' ' && **s != '\t')
4033 *s += 1;
4034 c = **s;
4035 **s = 0x00;
4036 if (strcmp (name, "=") == 0)
4038 cmpltr = 1;
4040 else if (strcmp (name, "<") == 0)
4042 cmpltr = 2;
4044 else if (strcmp (name, "<=") == 0)
4046 cmpltr = 3;
4048 else if (strcasecmp (name, "nuv") == 0)
4050 cmpltr = 4;
4052 else if (strcasecmp (name, "znv") == 0)
4054 cmpltr = 5;
4056 else if (strcasecmp (name, "sv") == 0)
4058 cmpltr = 6;
4060 else if (strcasecmp (name, "od") == 0)
4062 cmpltr = 7;
4064 /* If we have something like addb,n then there is no condition
4065 completer. */
4066 else if (strcasecmp (name, "n") == 0 && isbranch)
4068 cmpltr = 0;
4070 else
4072 cmpltr = -1;
4074 **s = c;
4077 /* Reset pointers if this was really a ,n for a branch instruction. */
4078 if (cmpltr == 0 && *name == 'n' && isbranch)
4079 *s = save_s;
4081 return cmpltr;
4084 /* Parse a negated addition completer returning the number
4085 (for encoding in instrutions) of the given completer.
4087 ISBRANCH specifies whether or not this is parsing a condition
4088 completer for a branch (vs a nullification completer for a
4089 computational instruction). */
4091 static int
4092 pa_parse_neg_add_cmpltr (s, isbranch)
4093 char **s;
4094 int isbranch;
4096 int cmpltr;
4097 char *name = *s + 1;
4098 char c;
4099 char *save_s = *s;
4101 cmpltr = 0;
4102 if (**s == ',')
4104 *s += 1;
4105 while (**s != ',' && **s != ' ' && **s != '\t')
4106 *s += 1;
4107 c = **s;
4108 **s = 0x00;
4109 if (strcasecmp (name, "tr") == 0)
4111 cmpltr = 0;
4113 else if (strcmp (name, "<>") == 0)
4115 cmpltr = 1;
4117 else if (strcmp (name, ">=") == 0)
4119 cmpltr = 2;
4121 else if (strcmp (name, ">") == 0)
4123 cmpltr = 3;
4125 else if (strcasecmp (name, "uv") == 0)
4127 cmpltr = 4;
4129 else if (strcasecmp (name, "vnz") == 0)
4131 cmpltr = 5;
4133 else if (strcasecmp (name, "nsv") == 0)
4135 cmpltr = 6;
4137 else if (strcasecmp (name, "ev") == 0)
4139 cmpltr = 7;
4141 /* If we have something like addb,n then there is no condition
4142 completer. */
4143 else if (strcasecmp (name, "n") == 0 && isbranch)
4145 cmpltr = 0;
4147 else
4149 cmpltr = -1;
4151 **s = c;
4154 /* Reset pointers if this was really a ,n for a branch instruction. */
4155 if (cmpltr == 0 && *name == 'n' && isbranch)
4156 *s = save_s;
4158 return cmpltr;
4161 /* Handle an alignment directive. Special so that we can update the
4162 alignment of the subspace if necessary. */
4163 static void
4164 pa_align (bytes)
4166 /* We must have a valid space and subspace. */
4167 pa_check_current_space_and_subspace ();
4169 /* Let the generic gas code do most of the work. */
4170 s_align_bytes (bytes);
4172 /* If bytes is a power of 2, then update the current subspace's
4173 alignment if necessary. */
4174 if (log2 (bytes) != -1)
4175 record_alignment (current_subspace->ssd_seg, log2 (bytes));
4178 /* Handle a .BLOCK type pseudo-op. */
4180 static void
4181 pa_block (z)
4182 int z;
4184 char *p;
4185 long int temp_fill;
4186 unsigned int temp_size;
4187 unsigned int i;
4189 /* We must have a valid space and subspace. */
4190 pa_check_current_space_and_subspace ();
4192 temp_size = get_absolute_expression ();
4194 /* Always fill with zeros, that's what the HP assembler does. */
4195 temp_fill = 0;
4197 p = frag_var (rs_fill, (int) temp_size, (int) temp_size,
4198 (relax_substateT) 0, (symbolS *) 0, (offsetT) 1, NULL);
4199 memset (p, 0, temp_size);
4201 /* Convert 2 bytes at a time. */
4203 for (i = 0; i < temp_size; i += 2)
4205 md_number_to_chars (p + i,
4206 (valueT) temp_fill,
4207 (int) ((temp_size - i) > 2 ? 2 : (temp_size - i)));
4210 pa_undefine_label ();
4211 demand_empty_rest_of_line ();
4214 /* Handle a .begin_brtab and .end_brtab pseudo-op. */
4216 static void
4217 pa_brtab (begin)
4218 int begin;
4221 #ifdef OBJ_SOM
4222 /* The BRTAB relocations are only availble in SOM (to denote
4223 the beginning and end of branch tables). */
4224 char *where = frag_more (0);
4226 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
4227 NULL, (offsetT) 0, NULL,
4228 0, begin ? R_HPPA_BEGIN_BRTAB : R_HPPA_END_BRTAB,
4229 e_fsel, 0, 0, NULL);
4230 #endif
4232 demand_empty_rest_of_line ();
4235 /* Handle a .begin_try and .end_try pseudo-op. */
4237 static void
4238 pa_try (begin)
4239 int begin;
4241 #ifdef OBJ_SOM
4242 expressionS exp;
4243 char *where = frag_more (0);
4245 if (! begin)
4246 expression (&exp);
4248 /* The TRY relocations are only availble in SOM (to denote
4249 the beginning and end of exception handling regions). */
4251 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
4252 NULL, (offsetT) 0, begin ? NULL : &exp,
4253 0, begin ? R_HPPA_BEGIN_TRY : R_HPPA_END_TRY,
4254 e_fsel, 0, 0, NULL);
4255 #endif
4257 demand_empty_rest_of_line ();
4260 /* Handle a .CALL pseudo-op. This involves storing away information
4261 about where arguments are to be found so the linker can detect
4262 (and correct) argument location mismatches between caller and callee. */
4264 static void
4265 pa_call (unused)
4266 int unused;
4268 /* We must have a valid space and subspace. */
4269 pa_check_current_space_and_subspace ();
4271 pa_call_args (&last_call_desc);
4272 demand_empty_rest_of_line ();
4275 /* Do the dirty work of building a call descriptor which describes
4276 where the caller placed arguments to a function call. */
4278 static void
4279 pa_call_args (call_desc)
4280 struct call_desc *call_desc;
4282 char *name, c, *p;
4283 unsigned int temp, arg_reloc;
4285 while (!is_end_of_statement ())
4287 name = input_line_pointer;
4288 c = get_symbol_end ();
4289 /* Process a source argument. */
4290 if ((strncasecmp (name, "argw", 4) == 0))
4292 temp = atoi (name + 4);
4293 p = input_line_pointer;
4294 *p = c;
4295 input_line_pointer++;
4296 name = input_line_pointer;
4297 c = get_symbol_end ();
4298 arg_reloc = pa_build_arg_reloc (name);
4299 call_desc->arg_reloc |= pa_align_arg_reloc (temp, arg_reloc);
4301 /* Process a return value. */
4302 else if ((strncasecmp (name, "rtnval", 6) == 0))
4304 p = input_line_pointer;
4305 *p = c;
4306 input_line_pointer++;
4307 name = input_line_pointer;
4308 c = get_symbol_end ();
4309 arg_reloc = pa_build_arg_reloc (name);
4310 call_desc->arg_reloc |= (arg_reloc & 0x3);
4312 else
4314 as_bad (_("Invalid .CALL argument: %s"), name);
4316 p = input_line_pointer;
4317 *p = c;
4318 if (!is_end_of_statement ())
4319 input_line_pointer++;
4323 /* Return TRUE if FRAG1 and FRAG2 are the same. */
4325 static int
4326 is_same_frag (frag1, frag2)
4327 fragS *frag1;
4328 fragS *frag2;
4331 if (frag1 == NULL)
4332 return (FALSE);
4333 else if (frag2 == NULL)
4334 return (FALSE);
4335 else if (frag1 == frag2)
4336 return (TRUE);
4337 else if (frag2->fr_type == rs_fill && frag2->fr_fix == 0)
4338 return (is_same_frag (frag1, frag2->fr_next));
4339 else
4340 return (FALSE);
4343 #ifdef OBJ_ELF
4344 /* Build an entry in the UNWIND subspace from the given function
4345 attributes in CALL_INFO. This is not needed for SOM as using
4346 R_ENTRY and R_EXIT relocations allow the linker to handle building
4347 of the unwind spaces. */
4349 static void
4350 pa_build_unwind_subspace (call_info)
4351 struct call_info *call_info;
4353 char *unwind;
4354 asection *seg, *save_seg;
4355 subsegT subseg, save_subseg;
4356 int i;
4357 char c, *p;
4359 /* Get into the right seg/subseg. This may involve creating
4360 the seg the first time through. Make sure to have the
4361 old seg/subseg so that we can reset things when we are done. */
4362 subseg = SUBSEG_UNWIND;
4363 seg = bfd_get_section_by_name (stdoutput, UNWIND_SECTION_NAME);
4364 if (seg == ASEC_NULL)
4366 seg = bfd_make_section_old_way (stdoutput, UNWIND_SECTION_NAME);
4367 bfd_set_section_flags (stdoutput, seg,
4368 SEC_READONLY | SEC_HAS_CONTENTS
4369 | SEC_LOAD | SEC_RELOC);
4372 save_seg = now_seg;
4373 save_subseg = now_subseg;
4374 subseg_set (seg, subseg);
4377 /* Get some space to hold relocation information for the unwind
4378 descriptor. */
4379 p = frag_more (4);
4380 md_number_to_chars (p, 0, 4);
4382 /* Relocation info. for start offset of the function. */
4383 fix_new_hppa (frag_now, p - frag_now->fr_literal, 4,
4384 call_info->start_symbol, (offsetT) 0,
4385 (expressionS *) NULL, 0, R_PARISC_DIR32, e_fsel, 32, 0, NULL);
4387 p = frag_more (4);
4388 md_number_to_chars (p, 0, 4);
4390 /* Relocation info. for end offset of the function.
4392 Because we allow reductions of 32bit relocations for ELF, this will be
4393 reduced to section_sym + offset which avoids putting the temporary
4394 symbol into the symbol table. It (should) end up giving the same
4395 value as call_info->start_symbol + function size once the linker is
4396 finished with its work. */
4398 fix_new_hppa (frag_now, p - frag_now->fr_literal, 4,
4399 call_info->end_symbol, (offsetT) 0,
4400 (expressionS *) NULL, 0, R_PARISC_DIR32, e_fsel, 32, 0, NULL);
4402 /* Dump it. */
4403 unwind = (char *) &call_info->ci_unwind;
4404 for (i = 8; i < sizeof (struct unwind_table); i++)
4406 c = *(unwind + i);
4408 FRAG_APPEND_1_CHAR (c);
4412 /* Return back to the original segment/subsegment. */
4413 subseg_set (save_seg, save_subseg);
4415 #endif
4417 /* Process a .CALLINFO pseudo-op. This information is used later
4418 to build unwind descriptors and maybe one day to support
4419 .ENTER and .LEAVE. */
4421 static void
4422 pa_callinfo (unused)
4423 int unused;
4425 char *name, c, *p;
4426 int temp;
4428 /* We must have a valid space and subspace. */
4429 pa_check_current_space_and_subspace ();
4431 /* .CALLINFO must appear within a procedure definition. */
4432 if (!within_procedure)
4433 as_bad (_(".callinfo is not within a procedure definition"));
4435 /* Mark the fact that we found the .CALLINFO for the
4436 current procedure. */
4437 callinfo_found = TRUE;
4439 /* Iterate over the .CALLINFO arguments. */
4440 while (!is_end_of_statement ())
4442 name = input_line_pointer;
4443 c = get_symbol_end ();
4444 /* Frame size specification. */
4445 if ((strncasecmp (name, "frame", 5) == 0))
4447 p = input_line_pointer;
4448 *p = c;
4449 input_line_pointer++;
4450 temp = get_absolute_expression ();
4451 if ((temp & 0x3) != 0)
4453 as_bad (_("FRAME parameter must be a multiple of 8: %d\n"), temp);
4454 temp = 0;
4457 /* callinfo is in bytes and unwind_desc is in 8 byte units. */
4458 last_call_info->ci_unwind.descriptor.frame_size = temp / 8;
4461 /* Entry register (GR, GR and SR) specifications. */
4462 else if ((strncasecmp (name, "entry_gr", 8) == 0))
4464 p = input_line_pointer;
4465 *p = c;
4466 input_line_pointer++;
4467 temp = get_absolute_expression ();
4468 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
4469 even though %r19 is caller saved. I think this is a bug in
4470 the HP assembler, and we are not going to emulate it. */
4471 if (temp < 3 || temp > 18)
4472 as_bad (_("Value for ENTRY_GR must be in the range 3..18\n"));
4473 last_call_info->ci_unwind.descriptor.entry_gr = temp - 2;
4475 else if ((strncasecmp (name, "entry_fr", 8) == 0))
4477 p = input_line_pointer;
4478 *p = c;
4479 input_line_pointer++;
4480 temp = get_absolute_expression ();
4481 /* Similarly the HP assembler takes 31 as the high bound even
4482 though %fr21 is the last callee saved floating point register. */
4483 if (temp < 12 || temp > 21)
4484 as_bad (_("Value for ENTRY_FR must be in the range 12..21\n"));
4485 last_call_info->ci_unwind.descriptor.entry_fr = temp - 11;
4487 else if ((strncasecmp (name, "entry_sr", 8) == 0))
4489 p = input_line_pointer;
4490 *p = c;
4491 input_line_pointer++;
4492 temp = get_absolute_expression ();
4493 if (temp != 3)
4494 as_bad (_("Value for ENTRY_SR must be 3\n"));
4496 /* Note whether or not this function performs any calls. */
4497 else if ((strncasecmp (name, "calls", 5) == 0) ||
4498 (strncasecmp (name, "caller", 6) == 0))
4500 p = input_line_pointer;
4501 *p = c;
4503 else if ((strncasecmp (name, "no_calls", 8) == 0))
4505 p = input_line_pointer;
4506 *p = c;
4508 /* Should RP be saved into the stack. */
4509 else if ((strncasecmp (name, "save_rp", 7) == 0))
4511 p = input_line_pointer;
4512 *p = c;
4513 last_call_info->ci_unwind.descriptor.save_rp = 1;
4515 /* Likewise for SP. */
4516 else if ((strncasecmp (name, "save_sp", 7) == 0))
4518 p = input_line_pointer;
4519 *p = c;
4520 last_call_info->ci_unwind.descriptor.save_sp = 1;
4522 /* Is this an unwindable procedure. If so mark it so
4523 in the unwind descriptor. */
4524 else if ((strncasecmp (name, "no_unwind", 9) == 0))
4526 p = input_line_pointer;
4527 *p = c;
4528 last_call_info->ci_unwind.descriptor.cannot_unwind = 1;
4530 /* Is this an interrupt routine. If so mark it in the
4531 unwind descriptor. */
4532 else if ((strncasecmp (name, "hpux_int", 7) == 0))
4534 p = input_line_pointer;
4535 *p = c;
4536 last_call_info->ci_unwind.descriptor.hpux_interrupt_marker = 1;
4538 /* Is this a millicode routine. "millicode" isn't in my
4539 assembler manual, but my copy is old. The HP assembler
4540 accepts it, and there's a place in the unwind descriptor
4541 to drop the information, so we'll accept it too. */
4542 else if ((strncasecmp (name, "millicode", 9) == 0))
4544 p = input_line_pointer;
4545 *p = c;
4546 last_call_info->ci_unwind.descriptor.millicode = 1;
4548 else
4550 as_bad (_("Invalid .CALLINFO argument: %s"), name);
4551 *input_line_pointer = c;
4553 if (!is_end_of_statement ())
4554 input_line_pointer++;
4557 demand_empty_rest_of_line ();
4560 /* Switch into the code subspace. */
4562 static void
4563 pa_code (unused)
4564 int unused;
4566 current_space = is_defined_space ("$TEXT$");
4567 current_subspace
4568 = pa_subsegment_to_subspace (current_space->sd_seg, 0);
4569 s_text (0);
4570 pa_undefine_label ();
4573 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
4574 the .comm pseudo-op has the following symtax:
4576 <label> .comm <length>
4578 where <label> is optional and is a symbol whose address will be the start of
4579 a block of memory <length> bytes long. <length> must be an absolute
4580 expression. <length> bytes will be allocated in the current space
4581 and subspace.
4583 Also note the label may not even be on the same line as the .comm.
4585 This difference in syntax means the colon function will be called
4586 on the symbol before we arrive in pa_comm. colon will set a number
4587 of attributes of the symbol that need to be fixed here. In particular
4588 the value, section pointer, fragment pointer, flags, etc. What
4589 a pain.
4591 This also makes error detection all but impossible. */
4593 static void
4594 pa_comm (unused)
4595 int unused;
4597 unsigned int size;
4598 symbolS *symbol;
4599 label_symbol_struct *label_symbol = pa_get_label ();
4601 if (label_symbol)
4602 symbol = label_symbol->lss_label;
4603 else
4604 symbol = NULL;
4606 SKIP_WHITESPACE ();
4607 size = get_absolute_expression ();
4609 if (symbol)
4611 S_SET_VALUE (symbol, size);
4612 S_SET_SEGMENT (symbol, bfd_und_section_ptr);
4613 S_SET_EXTERNAL (symbol);
4615 /* colon() has already set the frag to the current location in the
4616 current subspace; we need to reset the fragment to the zero address
4617 fragment. We also need to reset the segment pointer. */
4618 symbol_set_frag (symbol, &zero_address_frag);
4620 demand_empty_rest_of_line ();
4623 /* Process a .END pseudo-op. */
4625 static void
4626 pa_end (unused)
4627 int unused;
4629 demand_empty_rest_of_line ();
4632 /* Process a .ENTER pseudo-op. This is not supported. */
4633 static void
4634 pa_enter (unused)
4635 int unused;
4637 /* We must have a valid space and subspace. */
4638 pa_check_current_space_and_subspace ();
4640 as_bad (_("The .ENTER pseudo-op is not supported"));
4641 demand_empty_rest_of_line ();
4644 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
4645 procesure. */
4646 static void
4647 pa_entry (unused)
4648 int unused;
4650 /* We must have a valid space and subspace. */
4651 pa_check_current_space_and_subspace ();
4653 if (!within_procedure)
4654 as_bad (_("Misplaced .entry. Ignored."));
4655 else
4657 if (!callinfo_found)
4658 as_bad (_("Missing .callinfo."));
4660 demand_empty_rest_of_line ();
4661 within_entry_exit = TRUE;
4663 #ifdef OBJ_SOM
4664 /* SOM defers building of unwind descriptors until the link phase.
4665 The assembler is responsible for creating an R_ENTRY relocation
4666 to mark the beginning of a region and hold the unwind bits, and
4667 for creating an R_EXIT relocation to mark the end of the region.
4669 FIXME. ELF should be using the same conventions! The problem
4670 is an unwind requires too much relocation space. Hmmm. Maybe
4671 if we split the unwind bits up between the relocations which
4672 denote the entry and exit points. */
4673 if (last_call_info->start_symbol != NULL)
4675 char *where = frag_more (0);
4677 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
4678 NULL, (offsetT) 0, NULL,
4679 0, R_HPPA_ENTRY, e_fsel, 0, 0,
4680 (int *) &last_call_info->ci_unwind.descriptor);
4682 #endif
4685 /* Handle a .EQU pseudo-op. */
4687 static void
4688 pa_equ (reg)
4689 int reg;
4691 label_symbol_struct *label_symbol = pa_get_label ();
4692 symbolS *symbol;
4694 if (label_symbol)
4696 symbol = label_symbol->lss_label;
4697 if (reg)
4698 S_SET_VALUE (symbol, pa_parse_number (&input_line_pointer, 0));
4699 else
4700 S_SET_VALUE (symbol, (unsigned int) get_absolute_expression ());
4701 S_SET_SEGMENT (symbol, bfd_abs_section_ptr);
4703 else
4705 if (reg)
4706 as_bad (_(".REG must use a label"));
4707 else
4708 as_bad (_(".EQU must use a label"));
4711 pa_undefine_label ();
4712 demand_empty_rest_of_line ();
4715 /* Helper function. Does processing for the end of a function. This
4716 usually involves creating some relocations or building special
4717 symbols to mark the end of the function. */
4719 static void
4720 process_exit ()
4722 char *where;
4724 where = frag_more (0);
4726 #ifdef OBJ_ELF
4727 /* Mark the end of the function, stuff away the location of the frag
4728 for the end of the function, and finally call pa_build_unwind_subspace
4729 to add an entry in the unwind table. */
4730 hppa_elf_mark_end_of_function ();
4731 pa_build_unwind_subspace (last_call_info);
4732 #else
4733 /* SOM defers building of unwind descriptors until the link phase.
4734 The assembler is responsible for creating an R_ENTRY relocation
4735 to mark the beginning of a region and hold the unwind bits, and
4736 for creating an R_EXIT relocation to mark the end of the region.
4738 FIXME. ELF should be using the same conventions! The problem
4739 is an unwind requires too much relocation space. Hmmm. Maybe
4740 if we split the unwind bits up between the relocations which
4741 denote the entry and exit points. */
4742 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
4743 NULL, (offsetT) 0,
4744 NULL, 0, R_HPPA_EXIT, e_fsel, 0, 0,
4745 (int *) &last_call_info->ci_unwind.descriptor + 1);
4746 #endif
4749 /* Process a .EXIT pseudo-op. */
4751 static void
4752 pa_exit (unused)
4753 int unused;
4755 /* We must have a valid space and subspace. */
4756 pa_check_current_space_and_subspace ();
4758 if (!within_procedure)
4759 as_bad (_(".EXIT must appear within a procedure"));
4760 else
4762 if (!callinfo_found)
4763 as_bad (_("Missing .callinfo"));
4764 else
4766 if (!within_entry_exit)
4767 as_bad (_("No .ENTRY for this .EXIT"));
4768 else
4770 within_entry_exit = FALSE;
4771 process_exit ();
4775 demand_empty_rest_of_line ();
4778 /* Process a .EXPORT directive. This makes functions external
4779 and provides information such as argument relocation entries
4780 to callers. */
4782 static void
4783 pa_export (unused)
4784 int unused;
4786 char *name, c, *p;
4787 symbolS *symbol;
4789 name = input_line_pointer;
4790 c = get_symbol_end ();
4791 /* Make sure the given symbol exists. */
4792 if ((symbol = symbol_find_or_make (name)) == NULL)
4794 as_bad (_("Cannot define export symbol: %s\n"), name);
4795 p = input_line_pointer;
4796 *p = c;
4797 input_line_pointer++;
4799 else
4801 /* OK. Set the external bits and process argument relocations. */
4802 S_SET_EXTERNAL (symbol);
4803 p = input_line_pointer;
4804 *p = c;
4805 if (!is_end_of_statement ())
4807 input_line_pointer++;
4808 pa_type_args (symbol, 1);
4812 demand_empty_rest_of_line ();
4815 /* Helper function to process arguments to a .EXPORT pseudo-op. */
4817 static void
4818 pa_type_args (symbolP, is_export)
4819 symbolS *symbolP;
4820 int is_export;
4822 char *name, c, *p;
4823 unsigned int temp, arg_reloc;
4824 pa_symbol_type type = SYMBOL_TYPE_UNKNOWN;
4825 obj_symbol_type *symbol = (obj_symbol_type *) symbol_get_bfdsym (symbolP);
4827 if (strncasecmp (input_line_pointer, "absolute", 8) == 0)
4830 input_line_pointer += 8;
4831 symbol_get_bfdsym (symbolP)->flags &= ~BSF_FUNCTION;
4832 S_SET_SEGMENT (symbolP, bfd_abs_section_ptr);
4833 type = SYMBOL_TYPE_ABSOLUTE;
4835 else if (strncasecmp (input_line_pointer, "code", 4) == 0)
4837 input_line_pointer += 4;
4838 /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM,
4839 instead one should be IMPORTing/EXPORTing ENTRY types.
4841 Complain if one tries to EXPORT a CODE type since that's never
4842 done. Both GCC and HP C still try to IMPORT CODE types, so
4843 silently fix them to be ENTRY types. */
4844 if (S_IS_FUNCTION (symbolP))
4846 if (is_export)
4847 as_tsktsk (_("Using ENTRY rather than CODE in export directive for %s"),
4848 S_GET_NAME (symbolP));
4850 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
4851 type = SYMBOL_TYPE_ENTRY;
4853 else
4855 symbol_get_bfdsym (symbolP)->flags &= ~BSF_FUNCTION;
4856 type = SYMBOL_TYPE_CODE;
4859 else if (strncasecmp (input_line_pointer, "data", 4) == 0)
4861 input_line_pointer += 4;
4862 symbol_get_bfdsym (symbolP)->flags &= ~BSF_FUNCTION;
4863 type = SYMBOL_TYPE_DATA;
4865 else if ((strncasecmp (input_line_pointer, "entry", 5) == 0))
4867 input_line_pointer += 5;
4868 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
4869 type = SYMBOL_TYPE_ENTRY;
4871 else if (strncasecmp (input_line_pointer, "millicode", 9) == 0)
4873 input_line_pointer += 9;
4874 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
4875 type = SYMBOL_TYPE_MILLICODE;
4877 else if (strncasecmp (input_line_pointer, "plabel", 6) == 0)
4879 input_line_pointer += 6;
4880 symbol_get_bfdsym (symbolP)->flags &= ~BSF_FUNCTION;
4881 type = SYMBOL_TYPE_PLABEL;
4883 else if (strncasecmp (input_line_pointer, "pri_prog", 8) == 0)
4885 input_line_pointer += 8;
4886 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
4887 type = SYMBOL_TYPE_PRI_PROG;
4889 else if (strncasecmp (input_line_pointer, "sec_prog", 8) == 0)
4891 input_line_pointer += 8;
4892 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
4893 type = SYMBOL_TYPE_SEC_PROG;
4896 /* SOM requires much more information about symbol types
4897 than BFD understands. This is how we get this information
4898 to the SOM BFD backend. */
4899 #ifdef obj_set_symbol_type
4900 obj_set_symbol_type (symbol_get_bfdsym (symbolP), (int) type);
4901 #endif
4903 /* Now that the type of the exported symbol has been handled,
4904 handle any argument relocation information. */
4905 while (!is_end_of_statement ())
4907 if (*input_line_pointer == ',')
4908 input_line_pointer++;
4909 name = input_line_pointer;
4910 c = get_symbol_end ();
4911 /* Argument sources. */
4912 if ((strncasecmp (name, "argw", 4) == 0))
4914 p = input_line_pointer;
4915 *p = c;
4916 input_line_pointer++;
4917 temp = atoi (name + 4);
4918 name = input_line_pointer;
4919 c = get_symbol_end ();
4920 arg_reloc = pa_align_arg_reloc (temp, pa_build_arg_reloc (name));
4921 symbol->tc_data.ap.hppa_arg_reloc |= arg_reloc;
4922 *input_line_pointer = c;
4924 /* The return value. */
4925 else if ((strncasecmp (name, "rtnval", 6)) == 0)
4927 p = input_line_pointer;
4928 *p = c;
4929 input_line_pointer++;
4930 name = input_line_pointer;
4931 c = get_symbol_end ();
4932 arg_reloc = pa_build_arg_reloc (name);
4933 symbol->tc_data.ap.hppa_arg_reloc |= arg_reloc;
4934 *input_line_pointer = c;
4936 /* Privelege level. */
4937 else if ((strncasecmp (name, "priv_lev", 8)) == 0)
4939 p = input_line_pointer;
4940 *p = c;
4941 input_line_pointer++;
4942 temp = atoi (input_line_pointer);
4943 symbol->tc_data.ap.hppa_priv_level = temp;
4944 c = get_symbol_end ();
4945 *input_line_pointer = c;
4947 else
4949 as_bad (_("Undefined .EXPORT/.IMPORT argument (ignored): %s"), name);
4950 p = input_line_pointer;
4951 *p = c;
4953 if (!is_end_of_statement ())
4954 input_line_pointer++;
4958 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
4959 assembly file must either be defined in the assembly file, or
4960 explicitly IMPORTED from another. */
4962 static void
4963 pa_import (unused)
4964 int unused;
4966 char *name, c, *p;
4967 symbolS *symbol;
4969 name = input_line_pointer;
4970 c = get_symbol_end ();
4972 symbol = symbol_find (name);
4973 /* Ugh. We might be importing a symbol defined earlier in the file,
4974 in which case all the code below will really screw things up
4975 (set the wrong segment, symbol flags & type, etc). */
4976 if (symbol == NULL || !S_IS_DEFINED (symbol))
4978 symbol = symbol_find_or_make (name);
4979 p = input_line_pointer;
4980 *p = c;
4982 if (!is_end_of_statement ())
4984 input_line_pointer++;
4985 pa_type_args (symbol, 0);
4987 else
4989 /* Sigh. To be compatable with the HP assembler and to help
4990 poorly written assembly code, we assign a type based on
4991 the the current segment. Note only BSF_FUNCTION really
4992 matters, we do not need to set the full SYMBOL_TYPE_* info. */
4993 if (now_seg == text_section)
4994 symbol_get_bfdsym (symbol)->flags |= BSF_FUNCTION;
4996 /* If the section is undefined, then the symbol is undefined
4997 Since this is an import, leave the section undefined. */
4998 S_SET_SEGMENT (symbol, bfd_und_section_ptr);
5001 else
5003 /* The symbol was already defined. Just eat everything up to
5004 the end of the current statement. */
5005 while (!is_end_of_statement ())
5006 input_line_pointer++;
5009 demand_empty_rest_of_line ();
5012 /* Handle a .LABEL pseudo-op. */
5014 static void
5015 pa_label (unused)
5016 int unused;
5018 char *name, c, *p;
5020 name = input_line_pointer;
5021 c = get_symbol_end ();
5023 if (strlen (name) > 0)
5025 colon (name);
5026 p = input_line_pointer;
5027 *p = c;
5029 else
5031 as_warn (_("Missing label name on .LABEL"));
5034 if (!is_end_of_statement ())
5036 as_warn (_("extra .LABEL arguments ignored."));
5037 ignore_rest_of_line ();
5039 demand_empty_rest_of_line ();
5042 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
5044 static void
5045 pa_leave (unused)
5046 int unused;
5048 /* We must have a valid space and subspace. */
5049 pa_check_current_space_and_subspace ();
5051 as_bad (_("The .LEAVE pseudo-op is not supported"));
5052 demand_empty_rest_of_line ();
5055 /* Handle a .LEVEL pseudo-op. */
5057 static void
5058 pa_level (unused)
5059 int unused;
5061 char *level;
5063 level = input_line_pointer;
5064 if (strncmp (level, "1.0", 3) == 0)
5066 input_line_pointer += 3;
5067 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 10))
5068 as_warn (_("could not set architecture and machine"));
5070 else if (strncmp (level, "1.1", 3) == 0)
5072 input_line_pointer += 3;
5073 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 11))
5074 as_warn (_("could not set architecture and machine"));
5076 else if (strncmp (level, "2.0", 3) == 0)
5078 input_line_pointer += 3;
5079 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 20))
5080 as_warn (_("could not set architecture and machine"));
5082 else
5084 as_bad (_("Unrecognized .LEVEL argument\n"));
5085 ignore_rest_of_line ();
5087 demand_empty_rest_of_line ();
5090 /* Handle a .ORIGIN pseudo-op. */
5092 static void
5093 pa_origin (unused)
5094 int unused;
5096 /* We must have a valid space and subspace. */
5097 pa_check_current_space_and_subspace ();
5099 s_org (0);
5100 pa_undefine_label ();
5103 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
5104 is for static functions. FIXME. Should share more code with .EXPORT. */
5106 static void
5107 pa_param (unused)
5108 int unused;
5110 char *name, c, *p;
5111 symbolS *symbol;
5113 name = input_line_pointer;
5114 c = get_symbol_end ();
5116 if ((symbol = symbol_find_or_make (name)) == NULL)
5118 as_bad (_("Cannot define static symbol: %s\n"), name);
5119 p = input_line_pointer;
5120 *p = c;
5121 input_line_pointer++;
5123 else
5125 S_CLEAR_EXTERNAL (symbol);
5126 p = input_line_pointer;
5127 *p = c;
5128 if (!is_end_of_statement ())
5130 input_line_pointer++;
5131 pa_type_args (symbol, 0);
5135 demand_empty_rest_of_line ();
5138 /* Handle a .PROC pseudo-op. It is used to mark the beginning
5139 of a procedure from a syntatical point of view. */
5141 static void
5142 pa_proc (unused)
5143 int unused;
5145 struct call_info *call_info;
5147 /* We must have a valid space and subspace. */
5148 pa_check_current_space_and_subspace ();
5150 if (within_procedure)
5151 as_fatal (_("Nested procedures"));
5153 /* Reset global variables for new procedure. */
5154 callinfo_found = FALSE;
5155 within_procedure = TRUE;
5157 /* Create another call_info structure. */
5158 call_info = (struct call_info *) xmalloc (sizeof (struct call_info));
5160 if (!call_info)
5161 as_fatal (_("Cannot allocate unwind descriptor\n"));
5163 memset (call_info, 0, sizeof (struct call_info));
5165 call_info->ci_next = NULL;
5167 if (call_info_root == NULL)
5169 call_info_root = call_info;
5170 last_call_info = call_info;
5172 else
5174 last_call_info->ci_next = call_info;
5175 last_call_info = call_info;
5178 /* set up defaults on call_info structure */
5180 call_info->ci_unwind.descriptor.cannot_unwind = 0;
5181 call_info->ci_unwind.descriptor.region_desc = 1;
5182 call_info->ci_unwind.descriptor.hpux_interrupt_marker = 0;
5184 /* If we got a .PROC pseudo-op, we know that the function is defined
5185 locally. Make sure it gets into the symbol table. */
5187 label_symbol_struct *label_symbol = pa_get_label ();
5189 if (label_symbol)
5191 if (label_symbol->lss_label)
5193 last_call_info->start_symbol = label_symbol->lss_label;
5194 symbol_get_bfdsym (label_symbol->lss_label)->flags |= BSF_FUNCTION;
5196 else
5197 as_bad (_("Missing function name for .PROC (corrupted label chain)"));
5199 else
5200 last_call_info->start_symbol = NULL;
5203 demand_empty_rest_of_line ();
5206 /* Process the syntatical end of a procedure. Make sure all the
5207 appropriate pseudo-ops were found within the procedure. */
5209 static void
5210 pa_procend (unused)
5211 int unused;
5214 /* We must have a valid space and subspace. */
5215 pa_check_current_space_and_subspace ();
5217 /* If we are within a procedure definition, make sure we've
5218 defined a label for the procedure; handle case where the
5219 label was defined after the .PROC directive.
5221 Note there's not need to diddle with the segment or fragment
5222 for the label symbol in this case. We have already switched
5223 into the new $CODE$ subspace at this point. */
5224 if (within_procedure && last_call_info->start_symbol == NULL)
5226 label_symbol_struct *label_symbol = pa_get_label ();
5228 if (label_symbol)
5230 if (label_symbol->lss_label)
5232 last_call_info->start_symbol = label_symbol->lss_label;
5233 symbol_get_bfdsym (label_symbol->lss_label)->flags
5234 |= BSF_FUNCTION;
5235 #ifdef OBJ_SOM
5236 /* Also handle allocation of a fixup to hold the unwind
5237 information when the label appears after the proc/procend. */
5238 if (within_entry_exit)
5240 char *where = frag_more (0);
5242 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
5243 NULL, (offsetT) 0, NULL,
5244 0, R_HPPA_ENTRY, e_fsel, 0, 0,
5245 (int *) &last_call_info->ci_unwind.descriptor);
5247 #endif
5249 else
5250 as_bad (_("Missing function name for .PROC (corrupted label chain)"));
5252 else
5253 as_bad (_("Missing function name for .PROC"));
5256 if (!within_procedure)
5257 as_bad (_("misplaced .procend"));
5259 if (!callinfo_found)
5260 as_bad (_("Missing .callinfo for this procedure"));
5262 if (within_entry_exit)
5263 as_bad (_("Missing .EXIT for a .ENTRY"));
5265 #ifdef OBJ_ELF
5266 /* ELF needs to mark the end of each function so that it can compute
5267 the size of the function (apparently its needed in the symbol table). */
5268 hppa_elf_mark_end_of_function ();
5269 #endif
5271 within_procedure = FALSE;
5272 demand_empty_rest_of_line ();
5273 pa_undefine_label ();
5276 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
5277 then create a new space entry to hold the information specified
5278 by the parameters to the .SPACE directive. */
5280 static sd_chain_struct *
5281 pa_parse_space_stmt (space_name, create_flag)
5282 char *space_name;
5283 int create_flag;
5285 char *name, *ptemp, c;
5286 char loadable, defined, private, sort;
5287 int spnum, temp;
5288 asection *seg = NULL;
5289 sd_chain_struct *space;
5291 /* load default values */
5292 spnum = 0;
5293 sort = 0;
5294 loadable = TRUE;
5295 defined = TRUE;
5296 private = FALSE;
5297 if (strcmp (space_name, "$TEXT$") == 0)
5299 seg = pa_def_spaces[0].segment;
5300 defined = pa_def_spaces[0].defined;
5301 private = pa_def_spaces[0].private;
5302 sort = pa_def_spaces[0].sort;
5303 spnum = pa_def_spaces[0].spnum;
5305 else if (strcmp (space_name, "$PRIVATE$") == 0)
5307 seg = pa_def_spaces[1].segment;
5308 defined = pa_def_spaces[1].defined;
5309 private = pa_def_spaces[1].private;
5310 sort = pa_def_spaces[1].sort;
5311 spnum = pa_def_spaces[1].spnum;
5314 if (!is_end_of_statement ())
5316 print_errors = FALSE;
5317 ptemp = input_line_pointer + 1;
5318 /* First see if the space was specified as a number rather than
5319 as a name. According to the PA assembly manual the rest of
5320 the line should be ignored. */
5321 temp = pa_parse_number (&ptemp, 0);
5322 if (temp >= 0)
5324 spnum = temp;
5325 input_line_pointer = ptemp;
5327 else
5329 while (!is_end_of_statement ())
5331 input_line_pointer++;
5332 name = input_line_pointer;
5333 c = get_symbol_end ();
5334 if ((strncasecmp (name, "spnum", 5) == 0))
5336 *input_line_pointer = c;
5337 input_line_pointer++;
5338 spnum = get_absolute_expression ();
5340 else if ((strncasecmp (name, "sort", 4) == 0))
5342 *input_line_pointer = c;
5343 input_line_pointer++;
5344 sort = get_absolute_expression ();
5346 else if ((strncasecmp (name, "unloadable", 10) == 0))
5348 *input_line_pointer = c;
5349 loadable = FALSE;
5351 else if ((strncasecmp (name, "notdefined", 10) == 0))
5353 *input_line_pointer = c;
5354 defined = FALSE;
5356 else if ((strncasecmp (name, "private", 7) == 0))
5358 *input_line_pointer = c;
5359 private = TRUE;
5361 else
5363 as_bad (_("Invalid .SPACE argument"));
5364 *input_line_pointer = c;
5365 if (!is_end_of_statement ())
5366 input_line_pointer++;
5370 print_errors = TRUE;
5373 if (create_flag && seg == NULL)
5374 seg = subseg_new (space_name, 0);
5376 /* If create_flag is nonzero, then create the new space with
5377 the attributes computed above. Else set the values in
5378 an already existing space -- this can only happen for
5379 the first occurence of a built-in space. */
5380 if (create_flag)
5381 space = create_new_space (space_name, spnum, loadable, defined,
5382 private, sort, seg, 1);
5383 else
5385 space = is_defined_space (space_name);
5386 SPACE_SPNUM (space) = spnum;
5387 SPACE_DEFINED (space) = defined & 1;
5388 SPACE_USER_DEFINED (space) = 1;
5391 #ifdef obj_set_section_attributes
5392 obj_set_section_attributes (seg, defined, private, sort, spnum);
5393 #endif
5395 return space;
5398 /* Handle a .SPACE pseudo-op; this switches the current space to the
5399 given space, creating the new space if necessary. */
5401 static void
5402 pa_space (unused)
5403 int unused;
5405 char *name, c, *space_name, *save_s;
5406 int temp;
5407 sd_chain_struct *sd_chain;
5409 if (within_procedure)
5411 as_bad (_("Can\'t change spaces within a procedure definition. Ignored"));
5412 ignore_rest_of_line ();
5414 else
5416 /* Check for some of the predefined spaces. FIXME: most of the code
5417 below is repeated several times, can we extract the common parts
5418 and place them into a subroutine or something similar? */
5419 /* FIXME Is this (and the next IF stmt) really right?
5420 What if INPUT_LINE_POINTER points to "$TEXT$FOO"? */
5421 if (strncmp (input_line_pointer, "$TEXT$", 6) == 0)
5423 input_line_pointer += 6;
5424 sd_chain = is_defined_space ("$TEXT$");
5425 if (sd_chain == NULL)
5426 sd_chain = pa_parse_space_stmt ("$TEXT$", 1);
5427 else if (SPACE_USER_DEFINED (sd_chain) == 0)
5428 sd_chain = pa_parse_space_stmt ("$TEXT$", 0);
5430 current_space = sd_chain;
5431 subseg_set (text_section, sd_chain->sd_last_subseg);
5432 current_subspace
5433 = pa_subsegment_to_subspace (text_section,
5434 sd_chain->sd_last_subseg);
5435 demand_empty_rest_of_line ();
5436 return;
5438 if (strncmp (input_line_pointer, "$PRIVATE$", 9) == 0)
5440 input_line_pointer += 9;
5441 sd_chain = is_defined_space ("$PRIVATE$");
5442 if (sd_chain == NULL)
5443 sd_chain = pa_parse_space_stmt ("$PRIVATE$", 1);
5444 else if (SPACE_USER_DEFINED (sd_chain) == 0)
5445 sd_chain = pa_parse_space_stmt ("$PRIVATE$", 0);
5447 current_space = sd_chain;
5448 subseg_set (data_section, sd_chain->sd_last_subseg);
5449 current_subspace
5450 = pa_subsegment_to_subspace (data_section,
5451 sd_chain->sd_last_subseg);
5452 demand_empty_rest_of_line ();
5453 return;
5455 if (!strncasecmp (input_line_pointer,
5456 GDB_DEBUG_SPACE_NAME,
5457 strlen (GDB_DEBUG_SPACE_NAME)))
5459 input_line_pointer += strlen (GDB_DEBUG_SPACE_NAME);
5460 sd_chain = is_defined_space (GDB_DEBUG_SPACE_NAME);
5461 if (sd_chain == NULL)
5462 sd_chain = pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME, 1);
5463 else if (SPACE_USER_DEFINED (sd_chain) == 0)
5464 sd_chain = pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME, 0);
5466 current_space = sd_chain;
5469 asection *gdb_section
5470 = bfd_make_section_old_way (stdoutput, GDB_DEBUG_SPACE_NAME);
5472 subseg_set (gdb_section, sd_chain->sd_last_subseg);
5473 current_subspace
5474 = pa_subsegment_to_subspace (gdb_section,
5475 sd_chain->sd_last_subseg);
5477 demand_empty_rest_of_line ();
5478 return;
5481 /* It could be a space specified by number. */
5482 print_errors = 0;
5483 save_s = input_line_pointer;
5484 if ((temp = pa_parse_number (&input_line_pointer, 0)) >= 0)
5486 if ((sd_chain = pa_find_space_by_number (temp)))
5488 current_space = sd_chain;
5490 subseg_set (sd_chain->sd_seg, sd_chain->sd_last_subseg);
5491 current_subspace
5492 = pa_subsegment_to_subspace (sd_chain->sd_seg,
5493 sd_chain->sd_last_subseg);
5494 demand_empty_rest_of_line ();
5495 return;
5499 /* Not a number, attempt to create a new space. */
5500 print_errors = 1;
5501 input_line_pointer = save_s;
5502 name = input_line_pointer;
5503 c = get_symbol_end ();
5504 space_name = xmalloc (strlen (name) + 1);
5505 strcpy (space_name, name);
5506 *input_line_pointer = c;
5508 sd_chain = pa_parse_space_stmt (space_name, 1);
5509 current_space = sd_chain;
5511 subseg_set (sd_chain->sd_seg, sd_chain->sd_last_subseg);
5512 current_subspace = pa_subsegment_to_subspace (sd_chain->sd_seg,
5513 sd_chain->sd_last_subseg);
5514 demand_empty_rest_of_line ();
5518 /* Switch to a new space. (I think). FIXME. */
5520 static void
5521 pa_spnum (unused)
5522 int unused;
5524 char *name;
5525 char c;
5526 char *p;
5527 sd_chain_struct *space;
5529 name = input_line_pointer;
5530 c = get_symbol_end ();
5531 space = is_defined_space (name);
5532 if (space)
5534 p = frag_more (4);
5535 md_number_to_chars (p, SPACE_SPNUM (space), 4);
5537 else
5538 as_warn (_("Undefined space: '%s' Assuming space number = 0."), name);
5540 *input_line_pointer = c;
5541 demand_empty_rest_of_line ();
5544 /* If VALUE is an exact power of two between zero and 2^31, then
5545 return log2 (VALUE). Else return -1. */
5547 static int
5548 log2 (value)
5549 int value;
5551 int shift = 0;
5553 while ((1 << shift) != value && shift < 32)
5554 shift++;
5556 if (shift >= 32)
5557 return -1;
5558 else
5559 return shift;
5562 /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
5563 given subspace, creating the new subspace if necessary.
5565 FIXME. Should mirror pa_space more closely, in particular how
5566 they're broken up into subroutines. */
5568 static void
5569 pa_subspace (create_new)
5570 int create_new;
5572 char *name, *ss_name, *alias, c;
5573 char loadable, code_only, common, dup_common, zero, sort;
5574 int i, access, space_index, alignment, quadrant, applicable, flags;
5575 sd_chain_struct *space;
5576 ssd_chain_struct *ssd;
5577 asection *section;
5579 if (current_space == NULL)
5580 as_fatal (_("Must be in a space before changing or declaring subspaces.\n"));
5582 if (within_procedure)
5584 as_bad (_("Can\'t change subspaces within a procedure definition. Ignored"));
5585 ignore_rest_of_line ();
5587 else
5589 name = input_line_pointer;
5590 c = get_symbol_end ();
5591 ss_name = xmalloc (strlen (name) + 1);
5592 strcpy (ss_name, name);
5593 *input_line_pointer = c;
5595 /* Load default values. */
5596 sort = 0;
5597 access = 0x7f;
5598 loadable = 1;
5599 common = 0;
5600 dup_common = 0;
5601 code_only = 0;
5602 zero = 0;
5603 space_index = ~0;
5604 alignment = 1;
5605 quadrant = 0;
5606 alias = NULL;
5608 space = current_space;
5609 if (create_new)
5610 ssd = NULL;
5611 else
5612 ssd = is_defined_subspace (ss_name);
5613 /* Allow user to override the builtin attributes of subspaces. But
5614 only allow the attributes to be changed once! */
5615 if (ssd && SUBSPACE_DEFINED (ssd))
5617 subseg_set (ssd->ssd_seg, ssd->ssd_subseg);
5618 current_subspace = ssd;
5619 if (!is_end_of_statement ())
5620 as_warn (_("Parameters of an existing subspace can\'t be modified"));
5621 demand_empty_rest_of_line ();
5622 return;
5624 else
5626 /* A new subspace. Load default values if it matches one of
5627 the builtin subspaces. */
5628 i = 0;
5629 while (pa_def_subspaces[i].name)
5631 if (strcasecmp (pa_def_subspaces[i].name, ss_name) == 0)
5633 loadable = pa_def_subspaces[i].loadable;
5634 common = pa_def_subspaces[i].common;
5635 dup_common = pa_def_subspaces[i].dup_common;
5636 code_only = pa_def_subspaces[i].code_only;
5637 zero = pa_def_subspaces[i].zero;
5638 space_index = pa_def_subspaces[i].space_index;
5639 alignment = pa_def_subspaces[i].alignment;
5640 quadrant = pa_def_subspaces[i].quadrant;
5641 access = pa_def_subspaces[i].access;
5642 sort = pa_def_subspaces[i].sort;
5643 if (USE_ALIASES && pa_def_subspaces[i].alias)
5644 alias = pa_def_subspaces[i].alias;
5645 break;
5647 i++;
5651 /* We should be working with a new subspace now. Fill in
5652 any information as specified by the user. */
5653 if (!is_end_of_statement ())
5655 input_line_pointer++;
5656 while (!is_end_of_statement ())
5658 name = input_line_pointer;
5659 c = get_symbol_end ();
5660 if ((strncasecmp (name, "quad", 4) == 0))
5662 *input_line_pointer = c;
5663 input_line_pointer++;
5664 quadrant = get_absolute_expression ();
5666 else if ((strncasecmp (name, "align", 5) == 0))
5668 *input_line_pointer = c;
5669 input_line_pointer++;
5670 alignment = get_absolute_expression ();
5671 if (log2 (alignment) == -1)
5673 as_bad (_("Alignment must be a power of 2"));
5674 alignment = 1;
5677 else if ((strncasecmp (name, "access", 6) == 0))
5679 *input_line_pointer = c;
5680 input_line_pointer++;
5681 access = get_absolute_expression ();
5683 else if ((strncasecmp (name, "sort", 4) == 0))
5685 *input_line_pointer = c;
5686 input_line_pointer++;
5687 sort = get_absolute_expression ();
5689 else if ((strncasecmp (name, "code_only", 9) == 0))
5691 *input_line_pointer = c;
5692 code_only = 1;
5694 else if ((strncasecmp (name, "unloadable", 10) == 0))
5696 *input_line_pointer = c;
5697 loadable = 0;
5699 else if ((strncasecmp (name, "common", 6) == 0))
5701 *input_line_pointer = c;
5702 common = 1;
5704 else if ((strncasecmp (name, "dup_comm", 8) == 0))
5706 *input_line_pointer = c;
5707 dup_common = 1;
5709 else if ((strncasecmp (name, "zero", 4) == 0))
5711 *input_line_pointer = c;
5712 zero = 1;
5714 else if ((strncasecmp (name, "first", 5) == 0))
5715 as_bad (_("FIRST not supported as a .SUBSPACE argument"));
5716 else
5717 as_bad (_("Invalid .SUBSPACE argument"));
5718 if (!is_end_of_statement ())
5719 input_line_pointer++;
5723 /* Compute a reasonable set of BFD flags based on the information
5724 in the .subspace directive. */
5725 applicable = bfd_applicable_section_flags (stdoutput);
5726 flags = 0;
5727 if (loadable)
5728 flags |= (SEC_ALLOC | SEC_LOAD);
5729 if (code_only)
5730 flags |= SEC_CODE;
5731 if (common || dup_common)
5732 flags |= SEC_IS_COMMON;
5734 flags |= SEC_RELOC | SEC_HAS_CONTENTS;
5736 /* This is a zero-filled subspace (eg BSS). */
5737 if (zero)
5738 flags &= ~(SEC_LOAD | SEC_HAS_CONTENTS);
5740 applicable &= flags;
5742 /* If this is an existing subspace, then we want to use the
5743 segment already associated with the subspace.
5745 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
5746 lots of sections. It might be a problem in the PA ELF
5747 code, I do not know yet. For now avoid creating anything
5748 but the "standard" sections for ELF. */
5749 if (create_new)
5750 section = subseg_force_new (ss_name, 0);
5751 else if (ssd)
5752 section = ssd->ssd_seg;
5753 else if (alias)
5754 section = subseg_new (alias, 0);
5755 else if (!alias && USE_ALIASES)
5757 as_warn (_("Ignoring subspace decl due to ELF BFD bugs."));
5758 demand_empty_rest_of_line ();
5759 return;
5761 else
5762 section = subseg_new (ss_name, 0);
5764 if (zero)
5765 seg_info (section)->bss = 1;
5767 /* Now set the flags. */
5768 bfd_set_section_flags (stdoutput, section, applicable);
5770 /* Record any alignment request for this section. */
5771 record_alignment (section, log2 (alignment));
5773 /* Set the starting offset for this section. */
5774 bfd_set_section_vma (stdoutput, section,
5775 pa_subspace_start (space, quadrant));
5777 /* Now that all the flags are set, update an existing subspace,
5778 or create a new one. */
5779 if (ssd)
5781 current_subspace = update_subspace (space, ss_name, loadable,
5782 code_only, common, dup_common,
5783 sort, zero, access, space_index,
5784 alignment, quadrant,
5785 section);
5786 else
5787 current_subspace = create_new_subspace (space, ss_name, loadable,
5788 code_only, common,
5789 dup_common, zero, sort,
5790 access, space_index,
5791 alignment, quadrant, section);
5793 demand_empty_rest_of_line ();
5794 current_subspace->ssd_seg = section;
5795 subseg_set (current_subspace->ssd_seg, current_subspace->ssd_subseg);
5797 SUBSPACE_DEFINED (current_subspace) = 1;
5801 /* Create default space and subspace dictionaries. */
5803 static void
5804 pa_spaces_begin ()
5806 int i;
5808 space_dict_root = NULL;
5809 space_dict_last = NULL;
5811 i = 0;
5812 while (pa_def_spaces[i].name)
5814 char *name;
5816 /* Pick the right name to use for the new section. */
5817 if (pa_def_spaces[i].alias && USE_ALIASES)
5818 name = pa_def_spaces[i].alias;
5819 else
5820 name = pa_def_spaces[i].name;
5822 pa_def_spaces[i].segment = subseg_new (name, 0);
5823 create_new_space (pa_def_spaces[i].name, pa_def_spaces[i].spnum,
5824 pa_def_spaces[i].loadable, pa_def_spaces[i].defined,
5825 pa_def_spaces[i].private, pa_def_spaces[i].sort,
5826 pa_def_spaces[i].segment, 0);
5827 i++;
5830 i = 0;
5831 while (pa_def_subspaces[i].name)
5833 char *name;
5834 int applicable, subsegment;
5835 asection *segment = NULL;
5836 sd_chain_struct *space;
5838 /* Pick the right name for the new section and pick the right
5839 subsegment number. */
5840 if (pa_def_subspaces[i].alias && USE_ALIASES)
5842 name = pa_def_subspaces[i].alias;
5843 subsegment = pa_def_subspaces[i].subsegment;
5845 else
5847 name = pa_def_subspaces[i].name;
5848 subsegment = 0;
5851 /* Create the new section. */
5852 segment = subseg_new (name, subsegment);
5855 /* For SOM we want to replace the standard .text, .data, and .bss
5856 sections with our own. We also want to set BFD flags for
5857 all the built-in subspaces. */
5858 if (!strcmp (pa_def_subspaces[i].name, "$CODE$") && !USE_ALIASES)
5860 text_section = segment;
5861 applicable = bfd_applicable_section_flags (stdoutput);
5862 bfd_set_section_flags (stdoutput, segment,
5863 applicable & (SEC_ALLOC | SEC_LOAD
5864 | SEC_RELOC | SEC_CODE
5865 | SEC_READONLY
5866 | SEC_HAS_CONTENTS));
5868 else if (!strcmp (pa_def_subspaces[i].name, "$DATA$") && !USE_ALIASES)
5870 data_section = segment;
5871 applicable = bfd_applicable_section_flags (stdoutput);
5872 bfd_set_section_flags (stdoutput, segment,
5873 applicable & (SEC_ALLOC | SEC_LOAD
5874 | SEC_RELOC
5875 | SEC_HAS_CONTENTS));
5879 else if (!strcmp (pa_def_subspaces[i].name, "$BSS$") && !USE_ALIASES)
5881 bss_section = segment;
5882 applicable = bfd_applicable_section_flags (stdoutput);
5883 bfd_set_section_flags (stdoutput, segment,
5884 applicable & SEC_ALLOC);
5886 else if (!strcmp (pa_def_subspaces[i].name, "$LIT$") && !USE_ALIASES)
5888 applicable = bfd_applicable_section_flags (stdoutput);
5889 bfd_set_section_flags (stdoutput, segment,
5890 applicable & (SEC_ALLOC | SEC_LOAD
5891 | SEC_RELOC
5892 | SEC_READONLY
5893 | SEC_HAS_CONTENTS));
5895 else if (!strcmp (pa_def_subspaces[i].name, "$MILLICODE$")
5896 && !USE_ALIASES)
5898 applicable = bfd_applicable_section_flags (stdoutput);
5899 bfd_set_section_flags (stdoutput, segment,
5900 applicable & (SEC_ALLOC | SEC_LOAD
5901 | SEC_RELOC
5902 | SEC_READONLY
5903 | SEC_HAS_CONTENTS));
5905 else if (!strcmp (pa_def_subspaces[i].name, "$UNWIND$") && !USE_ALIASES)
5907 applicable = bfd_applicable_section_flags (stdoutput);
5908 bfd_set_section_flags (stdoutput, segment,
5909 applicable & (SEC_ALLOC | SEC_LOAD
5910 | SEC_RELOC
5911 | SEC_READONLY
5912 | SEC_HAS_CONTENTS));
5915 /* Find the space associated with this subspace. */
5916 space = pa_segment_to_space (pa_def_spaces[pa_def_subspaces[i].
5917 def_space_index].segment);
5918 if (space == NULL)
5920 as_fatal (_("Internal error: Unable to find containing space for %s."),
5921 pa_def_subspaces[i].name);
5924 create_new_subspace (space, name,
5925 pa_def_subspaces[i].loadable,
5926 pa_def_subspaces[i].code_only,
5927 pa_def_subspaces[i].common,
5928 pa_def_subspaces[i].dup_common,
5929 pa_def_subspaces[i].zero,
5930 pa_def_subspaces[i].sort,
5931 pa_def_subspaces[i].access,
5932 pa_def_subspaces[i].space_index,
5933 pa_def_subspaces[i].alignment,
5934 pa_def_subspaces[i].quadrant,
5935 segment);
5936 i++;
5942 /* Create a new space NAME, with the appropriate flags as defined
5943 by the given parameters. */
5945 static sd_chain_struct *
5946 create_new_space (name, spnum, loadable, defined, private,
5947 sort, seg, user_defined)
5948 char *name;
5949 int spnum;
5950 int loadable;
5951 int defined;
5952 int private;
5953 int sort;
5954 asection *seg;
5955 int user_defined;
5957 sd_chain_struct *chain_entry;
5959 chain_entry = (sd_chain_struct *) xmalloc (sizeof (sd_chain_struct));
5960 if (!chain_entry)
5961 as_fatal (_("Out of memory: could not allocate new space chain entry: %s\n"),
5962 name);
5964 SPACE_NAME (chain_entry) = (char *) xmalloc (strlen (name) + 1);
5965 strcpy (SPACE_NAME (chain_entry), name);
5966 SPACE_DEFINED (chain_entry) = defined;
5967 SPACE_USER_DEFINED (chain_entry) = user_defined;
5968 SPACE_SPNUM (chain_entry) = spnum;
5970 chain_entry->sd_seg = seg;
5971 chain_entry->sd_last_subseg = -1;
5972 chain_entry->sd_subspaces = NULL;
5973 chain_entry->sd_next = NULL;
5975 /* Find spot for the new space based on its sort key. */
5976 if (!space_dict_last)
5977 space_dict_last = chain_entry;
5979 if (space_dict_root == NULL)
5980 space_dict_root = chain_entry;
5981 else
5983 sd_chain_struct *chain_pointer;
5984 sd_chain_struct *prev_chain_pointer;
5986 chain_pointer = space_dict_root;
5987 prev_chain_pointer = NULL;
5989 while (chain_pointer)
5991 prev_chain_pointer = chain_pointer;
5992 chain_pointer = chain_pointer->sd_next;
5995 /* At this point we've found the correct place to add the new
5996 entry. So add it and update the linked lists as appropriate. */
5997 if (prev_chain_pointer)
5999 chain_entry->sd_next = chain_pointer;
6000 prev_chain_pointer->sd_next = chain_entry;
6002 else
6004 space_dict_root = chain_entry;
6005 chain_entry->sd_next = chain_pointer;
6008 if (chain_entry->sd_next == NULL)
6009 space_dict_last = chain_entry;
6012 /* This is here to catch predefined spaces which do not get
6013 modified by the user's input. Another call is found at
6014 the bottom of pa_parse_space_stmt to handle cases where
6015 the user modifies a predefined space. */
6016 #ifdef obj_set_section_attributes
6017 obj_set_section_attributes (seg, defined, private, sort, spnum);
6018 #endif
6020 return chain_entry;
6023 /* Create a new subspace NAME, with the appropriate flags as defined
6024 by the given parameters.
6026 Add the new subspace to the subspace dictionary chain in numerical
6027 order as defined by the SORT entries. */
6029 static ssd_chain_struct *
6030 create_new_subspace (space, name, loadable, code_only, common,
6031 dup_common, is_zero, sort, access, space_index,
6032 alignment, quadrant, seg)
6033 sd_chain_struct *space;
6034 char *name;
6035 int loadable, code_only, common, dup_common, is_zero;
6036 int sort;
6037 int access;
6038 int space_index;
6039 int alignment;
6040 int quadrant;
6041 asection *seg;
6043 ssd_chain_struct *chain_entry;
6045 chain_entry = (ssd_chain_struct *) xmalloc (sizeof (ssd_chain_struct));
6046 if (!chain_entry)
6047 as_fatal (_("Out of memory: could not allocate new subspace chain entry: %s\n"), name);
6049 SUBSPACE_NAME (chain_entry) = (char *) xmalloc (strlen (name) + 1);
6050 strcpy (SUBSPACE_NAME (chain_entry), name);
6052 /* Initialize subspace_defined. When we hit a .subspace directive
6053 we'll set it to 1 which "locks-in" the subspace attributes. */
6054 SUBSPACE_DEFINED (chain_entry) = 0;
6056 chain_entry->ssd_subseg = USE_ALIASES ? pa_next_subseg (space) : 0;
6057 chain_entry->ssd_seg = seg;
6058 chain_entry->ssd_next = NULL;
6060 /* Find spot for the new subspace based on its sort key. */
6061 if (space->sd_subspaces == NULL)
6062 space->sd_subspaces = chain_entry;
6063 else
6065 ssd_chain_struct *chain_pointer;
6066 ssd_chain_struct *prev_chain_pointer;
6068 chain_pointer = space->sd_subspaces;
6069 prev_chain_pointer = NULL;
6071 while (chain_pointer)
6073 prev_chain_pointer = chain_pointer;
6074 chain_pointer = chain_pointer->ssd_next;
6077 /* Now we have somewhere to put the new entry. Insert it and update
6078 the links. */
6079 if (prev_chain_pointer)
6081 chain_entry->ssd_next = chain_pointer;
6082 prev_chain_pointer->ssd_next = chain_entry;
6084 else
6086 space->sd_subspaces = chain_entry;
6087 chain_entry->ssd_next = chain_pointer;
6091 #ifdef obj_set_subsection_attributes
6092 obj_set_subsection_attributes (seg, space->sd_seg, access,
6093 sort, quadrant);
6094 #endif
6096 return chain_entry;
6099 /* Update the information for the given subspace based upon the
6100 various arguments. Return the modified subspace chain entry. */
6102 static ssd_chain_struct *
6103 update_subspace (space, name, loadable, code_only, common, dup_common, sort,
6104 zero, access, space_index, alignment, quadrant, section)
6105 sd_chain_struct *space;
6106 char *name;
6107 int loadable;
6108 int code_only;
6109 int common;
6110 int dup_common;
6111 int zero;
6112 int sort;
6113 int access;
6114 int space_index;
6115 int alignment;
6116 int quadrant;
6117 asection *section;
6119 ssd_chain_struct *chain_entry;
6121 chain_entry = is_defined_subspace (name);
6123 #ifdef obj_set_subsection_attributes
6124 obj_set_subsection_attributes (section, space->sd_seg, access,
6125 sort, quadrant);
6126 #endif
6128 return chain_entry;
6131 /* Return the space chain entry for the space with the name NAME or
6132 NULL if no such space exists. */
6134 static sd_chain_struct *
6135 is_defined_space (name)
6136 char *name;
6138 sd_chain_struct *chain_pointer;
6140 for (chain_pointer = space_dict_root;
6141 chain_pointer;
6142 chain_pointer = chain_pointer->sd_next)
6144 if (strcmp (SPACE_NAME (chain_pointer), name) == 0)
6145 return chain_pointer;
6148 /* No mapping from segment to space was found. Return NULL. */
6149 return NULL;
6152 /* Find and return the space associated with the given seg. If no mapping
6153 from the given seg to a space is found, then return NULL.
6155 Unlike subspaces, the number of spaces is not expected to grow much,
6156 so a linear exhaustive search is OK here. */
6158 static sd_chain_struct *
6159 pa_segment_to_space (seg)
6160 asection *seg;
6162 sd_chain_struct *space_chain;
6164 /* Walk through each space looking for the correct mapping. */
6165 for (space_chain = space_dict_root;
6166 space_chain;
6167 space_chain = space_chain->sd_next)
6169 if (space_chain->sd_seg == seg)
6170 return space_chain;
6173 /* Mapping was not found. Return NULL. */
6174 return NULL;
6177 /* Return the space chain entry for the subspace with the name NAME or
6178 NULL if no such subspace exists.
6180 Uses a linear search through all the spaces and subspaces, this may
6181 not be appropriate if we ever being placing each function in its
6182 own subspace. */
6184 static ssd_chain_struct *
6185 is_defined_subspace (name)
6186 char *name;
6188 sd_chain_struct *space_chain;
6189 ssd_chain_struct *subspace_chain;
6191 /* Walk through each space. */
6192 for (space_chain = space_dict_root;
6193 space_chain;
6194 space_chain = space_chain->sd_next)
6196 /* Walk through each subspace looking for a name which matches. */
6197 for (subspace_chain = space_chain->sd_subspaces;
6198 subspace_chain;
6199 subspace_chain = subspace_chain->ssd_next)
6200 if (strcmp (SUBSPACE_NAME (subspace_chain), name) == 0)
6201 return subspace_chain;
6204 /* Subspace wasn't found. Return NULL. */
6205 return NULL;
6208 /* Find and return the subspace associated with the given seg. If no
6209 mapping from the given seg to a subspace is found, then return NULL.
6211 If we ever put each procedure/function within its own subspace
6212 (to make life easier on the compiler and linker), then this will have
6213 to become more efficient. */
6215 static ssd_chain_struct *
6216 pa_subsegment_to_subspace (seg, subseg)
6217 asection *seg;
6218 subsegT subseg;
6220 sd_chain_struct *space_chain;
6221 ssd_chain_struct *subspace_chain;
6223 /* Walk through each space. */
6224 for (space_chain = space_dict_root;
6225 space_chain;
6226 space_chain = space_chain->sd_next)
6228 if (space_chain->sd_seg == seg)
6230 /* Walk through each subspace within each space looking for
6231 the correct mapping. */
6232 for (subspace_chain = space_chain->sd_subspaces;
6233 subspace_chain;
6234 subspace_chain = subspace_chain->ssd_next)
6235 if (subspace_chain->ssd_subseg == (int) subseg)
6236 return subspace_chain;
6240 /* No mapping from subsegment to subspace found. Return NULL. */
6241 return NULL;
6244 /* Given a number, try and find a space with the name number.
6246 Return a pointer to a space dictionary chain entry for the space
6247 that was found or NULL on failure. */
6249 static sd_chain_struct *
6250 pa_find_space_by_number (number)
6251 int number;
6253 sd_chain_struct *space_chain;
6255 for (space_chain = space_dict_root;
6256 space_chain;
6257 space_chain = space_chain->sd_next)
6259 if (SPACE_SPNUM (space_chain) == (unsigned int) number)
6260 return space_chain;
6263 /* No appropriate space found. Return NULL. */
6264 return NULL;
6267 /* Return the starting address for the given subspace. If the starting
6268 address is unknown then return zero. */
6270 static unsigned int
6271 pa_subspace_start (space, quadrant)
6272 sd_chain_struct *space;
6273 int quadrant;
6275 #ifdef OBJ_SOM
6276 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
6277 is not correct for the PA OSF1 port. */
6278 if ((strcmp (SPACE_NAME (space), "$PRIVATE$") == 0) && quadrant == 1)
6279 return 0x40000000;
6280 else if (space->sd_seg == data_section && quadrant == 1)
6281 return 0x40000000;
6282 else
6283 return 0;
6284 #endif
6285 return 0;
6288 /* FIXME. Needs documentation. */
6289 static int
6290 pa_next_subseg (space)
6291 sd_chain_struct *space;
6294 space->sd_last_subseg++;
6295 return space->sd_last_subseg;
6298 /* Helper function for pa_stringer. Used to find the end of
6299 a string. */
6301 static unsigned int
6302 pa_stringer_aux (s)
6303 char *s;
6305 unsigned int c = *s & CHAR_MASK;
6307 /* We must have a valid space and subspace. */
6308 pa_check_current_space_and_subspace ();
6310 switch (c)
6312 case '\"':
6313 c = NOT_A_CHAR;
6314 break;
6315 default:
6316 break;
6318 return c;
6321 /* Handle a .STRING type pseudo-op. */
6323 static void
6324 pa_stringer (append_zero)
6325 int append_zero;
6327 char *s, num_buf[4];
6328 unsigned int c;
6329 int i;
6331 /* Preprocess the string to handle PA-specific escape sequences.
6332 For example, \xDD where DD is a hexidecimal number should be
6333 changed to \OOO where OOO is an octal number. */
6335 /* Skip the opening quote. */
6336 s = input_line_pointer + 1;
6338 while (is_a_char (c = pa_stringer_aux (s++)))
6340 if (c == '\\')
6342 c = *s;
6343 switch (c)
6345 /* Handle \x<num>. */
6346 case 'x':
6348 unsigned int number;
6349 int num_digit;
6350 char dg;
6351 char *s_start = s;
6353 /* Get pas the 'x'. */
6354 s++;
6355 for (num_digit = 0, number = 0, dg = *s;
6356 num_digit < 2
6357 && (isdigit (dg) || (dg >= 'a' && dg <= 'f')
6358 || (dg >= 'A' && dg <= 'F'));
6359 num_digit++)
6361 if (isdigit (dg))
6362 number = number * 16 + dg - '0';
6363 else if (dg >= 'a' && dg <= 'f')
6364 number = number * 16 + dg - 'a' + 10;
6365 else
6366 number = number * 16 + dg - 'A' + 10;
6368 s++;
6369 dg = *s;
6371 if (num_digit > 0)
6373 switch (num_digit)
6375 case 1:
6376 sprintf (num_buf, "%02o", number);
6377 break;
6378 case 2:
6379 sprintf (num_buf, "%03o", number);
6380 break;
6382 for (i = 0; i <= num_digit; i++)
6383 s_start[i] = num_buf[i];
6385 break;
6387 /* This might be a "\"", skip over the escaped char. */
6388 default:
6389 s++;
6390 break;
6394 stringer (append_zero);
6395 pa_undefine_label ();
6398 /* Handle a .VERSION pseudo-op. */
6400 static void
6401 pa_version (unused)
6402 int unused;
6404 obj_version (0);
6405 pa_undefine_label ();
6408 #ifdef OBJ_SOM
6410 /* Handle a .COMPILER pseudo-op. */
6412 static void
6413 pa_compiler (unused)
6414 int unused;
6416 obj_som_compiler (0);
6417 pa_undefine_label ();
6420 #endif
6422 /* Handle a .COPYRIGHT pseudo-op. */
6424 static void
6425 pa_copyright (unused)
6426 int unused;
6428 obj_copyright (0);
6429 pa_undefine_label ();
6432 /* Just like a normal cons, but when finished we have to undefine
6433 the latest space label. */
6435 static void
6436 pa_cons (nbytes)
6437 int nbytes;
6439 cons (nbytes);
6440 pa_undefine_label ();
6443 /* Switch to the data space. As usual delete our label. */
6445 static void
6446 pa_data (unused)
6447 int unused;
6449 current_space = is_defined_space ("$PRIVATE$");
6450 current_subspace
6451 = pa_subsegment_to_subspace (current_space->sd_seg, 0);
6452 s_data (0);
6453 pa_undefine_label ();
6456 /* Like float_cons, but we need to undefine our label. */
6458 static void
6459 pa_float_cons (float_type)
6460 int float_type;
6462 float_cons (float_type);
6463 pa_undefine_label ();
6466 /* Like s_fill, but delete our label when finished. */
6468 static void
6469 pa_fill (unused)
6470 int unused;
6472 /* We must have a valid space and subspace. */
6473 pa_check_current_space_and_subspace ();
6475 s_fill (0);
6476 pa_undefine_label ();
6479 /* Like lcomm, but delete our label when finished. */
6481 static void
6482 pa_lcomm (needs_align)
6483 int needs_align;
6485 /* We must have a valid space and subspace. */
6486 pa_check_current_space_and_subspace ();
6488 s_lcomm (needs_align);
6489 pa_undefine_label ();
6492 /* Like lsym, but delete our label when finished. */
6494 static void
6495 pa_lsym (unused)
6496 int unused;
6498 /* We must have a valid space and subspace. */
6499 pa_check_current_space_and_subspace ();
6501 s_lsym (0);
6502 pa_undefine_label ();
6505 /* Switch to the text space. Like s_text, but delete our
6506 label when finished. */
6507 static void
6508 pa_text (unused)
6509 int unused;
6511 current_space = is_defined_space ("$TEXT$");
6512 current_subspace
6513 = pa_subsegment_to_subspace (current_space->sd_seg, 0);
6515 s_text (0);
6516 pa_undefine_label ();
6519 /* On the PA relocations which involve function symbols must not be
6520 adjusted. This so that the linker can know when/how to create argument
6521 relocation stubs for indirect calls and calls to static functions.
6523 "T" field selectors create DLT relative fixups for accessing
6524 globals and statics in PIC code; each DLT relative fixup creates
6525 an entry in the DLT table. The entries contain the address of
6526 the final target (eg accessing "foo" would create a DLT entry
6527 with the address of "foo").
6529 Unfortunately, the HP linker doesn't take into account any addend
6530 when generating the DLT; so accessing $LIT$+8 puts the address of
6531 $LIT$ into the DLT rather than the address of $LIT$+8.
6533 The end result is we can't perform relocation symbol reductions for
6534 any fixup which creates entries in the DLT (eg they use "T" field
6535 selectors).
6537 Reject reductions involving symbols with external scope; such
6538 reductions make life a living hell for object file editors.
6540 FIXME. Also reject R_HPPA relocations which are 32bits wide in
6541 the code space. The SOM BFD backend doesn't know how to pull the
6542 right bits out of an instruction. */
6545 hppa_fix_adjustable (fixp)
6546 fixS *fixp;
6548 struct hppa_fix_struct *hppa_fix;
6550 hppa_fix = (struct hppa_fix_struct *) fixp->tc_fix_data;
6552 #ifdef OBJ_SOM
6553 /* Reject reductions of symbols in 32bit relocs. */
6554 if (fixp->fx_r_type == R_HPPA && hppa_fix->fx_r_format == 32)
6555 return 0;
6557 /* Reject reductions of symbols in sym1-sym2 expressions when
6558 the fixup will occur in a CODE subspace.
6560 XXX FIXME: Long term we probably want to reject all of these;
6561 for example reducing in the debug section would lose if we ever
6562 supported using the optimizing hp linker. */
6563 if (fixp->fx_addsy
6564 && fixp->fx_subsy
6565 && (hppa_fix->segment->flags & SEC_CODE))
6567 /* Apparently sy_used_in_reloc never gets set for sub symbols. */
6568 symbol_mark_used_in_reloc (fixp->fx_subsy);
6569 return 0;
6572 /* We can't adjust any relocs that use LR% and RR% field selectors.
6573 That confuses the HP linker. */
6574 if (hppa_fix->fx_r_field == e_lrsel
6575 || hppa_fix->fx_r_field == e_rrsel
6576 || hppa_fix->fx_r_field == e_nlrsel)
6577 return 0;
6578 #endif
6580 /* Reject reductions of symbols in DLT relative relocs,
6581 relocations with plabels. */
6582 if (hppa_fix->fx_r_field == e_tsel
6583 || hppa_fix->fx_r_field == e_ltsel
6584 || hppa_fix->fx_r_field == e_rtsel
6585 || hppa_fix->fx_r_field == e_psel
6586 || hppa_fix->fx_r_field == e_rpsel
6587 || hppa_fix->fx_r_field == e_lpsel)
6588 return 0;
6590 if (fixp->fx_addsy && S_IS_EXTERNAL (fixp->fx_addsy))
6591 return 0;
6593 /* Reject absolute calls (jumps). */
6594 if (hppa_fix->fx_r_type == R_HPPA_ABS_CALL)
6595 return 0;
6597 /* Reject reductions of function symbols. */
6598 if (fixp->fx_addsy == 0 || ! S_IS_FUNCTION (fixp->fx_addsy))
6599 return 1;
6601 return 0;
6604 /* Return nonzero if the fixup in FIXP will require a relocation,
6605 even it if appears that the fixup could be completely handled
6606 within GAS. */
6609 hppa_force_relocation (fixp)
6610 fixS *fixp;
6612 struct hppa_fix_struct *hppa_fixp;
6613 int distance;
6615 hppa_fixp = (struct hppa_fix_struct *) fixp->tc_fix_data;
6616 #ifdef OBJ_SOM
6617 if (fixp->fx_r_type == R_HPPA_ENTRY || fixp->fx_r_type == R_HPPA_EXIT
6618 || fixp->fx_r_type == R_HPPA_BEGIN_BRTAB
6619 || fixp->fx_r_type == R_HPPA_END_BRTAB
6620 || fixp->fx_r_type == R_HPPA_BEGIN_TRY
6621 || fixp->fx_r_type == R_HPPA_END_TRY
6622 || (fixp->fx_addsy != NULL && fixp->fx_subsy != NULL
6623 && (hppa_fixp->segment->flags & SEC_CODE) != 0))
6624 return 1;
6625 #endif
6627 #define arg_reloc_stub_needed(CALLER, CALLEE) \
6628 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
6630 /* It is necessary to force PC-relative calls/jumps to have a relocation
6631 entry if they're going to need either a argument relocation or long
6632 call stub. FIXME. Can't we need the same for absolute calls? */
6633 if (fixp->fx_pcrel && fixp->fx_addsy
6634 && (arg_reloc_stub_needed ((long) ((obj_symbol_type *)
6635 symbol_get_bfdsym (fixp->fx_addsy))->tc_data.ap.hppa_arg_reloc,
6636 hppa_fixp->fx_arg_reloc)))
6637 return 1;
6638 distance = (fixp->fx_offset + S_GET_VALUE (fixp->fx_addsy)
6639 - md_pcrel_from (fixp));
6640 /* Now check and see if we're going to need a long-branch stub. */
6641 if (fixp->fx_r_type == R_HPPA_PCREL_CALL
6642 && (distance > 262143 || distance < -262144))
6643 return 1;
6645 if (fixp->fx_r_type == R_HPPA_ABS_CALL)
6646 return 1;
6647 #undef arg_reloc_stub_needed
6649 /* No need (yet) to force another relocations to be emitted. */
6650 return 0;
6653 /* Now for some ELF specific code. FIXME. */
6654 #ifdef OBJ_ELF
6655 /* Mark the end of a function so that it's possible to compute
6656 the size of the function in hppa_elf_final_processing. */
6658 static void
6659 hppa_elf_mark_end_of_function ()
6661 /* ELF does not have EXIT relocations. All we do is create a
6662 temporary symbol marking the end of the function. */
6663 char *name = (char *)
6664 xmalloc (strlen ("L$\001end_") +
6665 strlen (S_GET_NAME (last_call_info->start_symbol)) + 1);
6667 if (name)
6669 symbolS *symbolP;
6671 strcpy (name, "L$\001end_");
6672 strcat (name, S_GET_NAME (last_call_info->start_symbol));
6674 /* If we have a .exit followed by a .procend, then the
6675 symbol will have already been defined. */
6676 symbolP = symbol_find (name);
6677 if (symbolP)
6679 /* The symbol has already been defined! This can
6680 happen if we have a .exit followed by a .procend.
6682 This is *not* an error. All we want to do is free
6683 the memory we just allocated for the name and continue. */
6684 xfree (name);
6686 else
6688 /* symbol value should be the offset of the
6689 last instruction of the function */
6690 symbolP = symbol_new (name, now_seg, (valueT) (frag_now_fix () - 4),
6691 frag_now);
6693 assert (symbolP);
6694 S_CLEAR_EXTERNAL (symbolP);
6695 symbol_table_insert (symbolP);
6698 if (symbolP)
6699 last_call_info->end_symbol = symbolP;
6700 else
6701 as_bad (_("Symbol '%s' could not be created."), name);
6704 else
6705 as_bad (_("No memory for symbol name."));
6709 /* For ELF, this function serves one purpose: to setup the st_size
6710 field of STT_FUNC symbols. To do this, we need to scan the
6711 call_info structure list, determining st_size in by taking the
6712 difference in the address of the beginning/end marker symbols. */
6714 void
6715 elf_hppa_final_processing ()
6717 struct call_info *call_info_pointer;
6719 for (call_info_pointer = call_info_root;
6720 call_info_pointer;
6721 call_info_pointer = call_info_pointer->ci_next)
6723 elf_symbol_type *esym
6724 = ((elf_symbol_type *)
6725 symbol_get_bfdsym (call_info_pointer->start_symbol));
6726 esym->internal_elf_sym.st_size =
6727 S_GET_VALUE (call_info_pointer->end_symbol)
6728 - S_GET_VALUE (call_info_pointer->start_symbol) + 4;
6731 #endif