1999-06-04 Mark Klein <mklein@dis.com>
[binutils.git] / gas / config / tc-hppa.c
blobf74b1adaa983af8d7f4215c4fd2c3b0ea63aea7e
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;
706 /* A dummy bfd symbol so that all relocations have symbols of some kind. */
707 static symbolS *dummy_symbol;
709 /* Nonzero if errors are to be printed. */
710 static int print_errors = 1;
712 /* List of registers that are pre-defined:
714 Each general register has one predefined name of the form
715 %r<REGNUM> which has the value <REGNUM>.
717 Space and control registers are handled in a similar manner,
718 but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
720 Likewise for the floating point registers, but of the form
721 %fr<REGNUM>. Floating point registers have additional predefined
722 names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
723 again have the value <REGNUM>.
725 Many registers also have synonyms:
727 %r26 - %r23 have %arg0 - %arg3 as synonyms
728 %r28 - %r29 have %ret0 - %ret1 as synonyms
729 %r30 has %sp as a synonym
730 %r27 has %dp as a synonym
731 %r2 has %rp as a synonym
733 Almost every control register has a synonym; they are not listed
734 here for brevity.
736 The table is sorted. Suitable for searching by a binary search. */
738 static const struct pd_reg pre_defined_registers[] =
740 {"%arg0", 26},
741 {"%arg1", 25},
742 {"%arg2", 24},
743 {"%arg3", 23},
744 {"%cr0", 0},
745 {"%cr10", 10},
746 {"%cr11", 11},
747 {"%cr12", 12},
748 {"%cr13", 13},
749 {"%cr14", 14},
750 {"%cr15", 15},
751 {"%cr16", 16},
752 {"%cr17", 17},
753 {"%cr18", 18},
754 {"%cr19", 19},
755 {"%cr20", 20},
756 {"%cr21", 21},
757 {"%cr22", 22},
758 {"%cr23", 23},
759 {"%cr24", 24},
760 {"%cr25", 25},
761 {"%cr26", 26},
762 {"%cr27", 27},
763 {"%cr28", 28},
764 {"%cr29", 29},
765 {"%cr30", 30},
766 {"%cr31", 31},
767 {"%cr8", 8},
768 {"%cr9", 9},
769 {"%dp", 27},
770 {"%eiem", 15},
771 {"%eirr", 23},
772 {"%fr0", 0},
773 {"%fr0l", 0},
774 {"%fr0r", 0},
775 {"%fr1", 1},
776 {"%fr10", 10},
777 {"%fr10l", 10},
778 {"%fr10r", 10},
779 {"%fr11", 11},
780 {"%fr11l", 11},
781 {"%fr11r", 11},
782 {"%fr12", 12},
783 {"%fr12l", 12},
784 {"%fr12r", 12},
785 {"%fr13", 13},
786 {"%fr13l", 13},
787 {"%fr13r", 13},
788 {"%fr14", 14},
789 {"%fr14l", 14},
790 {"%fr14r", 14},
791 {"%fr15", 15},
792 {"%fr15l", 15},
793 {"%fr15r", 15},
794 {"%fr16", 16},
795 {"%fr16l", 16},
796 {"%fr16r", 16},
797 {"%fr17", 17},
798 {"%fr17l", 17},
799 {"%fr17r", 17},
800 {"%fr18", 18},
801 {"%fr18l", 18},
802 {"%fr18r", 18},
803 {"%fr19", 19},
804 {"%fr19l", 19},
805 {"%fr19r", 19},
806 {"%fr1l", 1},
807 {"%fr1r", 1},
808 {"%fr2", 2},
809 {"%fr20", 20},
810 {"%fr20l", 20},
811 {"%fr20r", 20},
812 {"%fr21", 21},
813 {"%fr21l", 21},
814 {"%fr21r", 21},
815 {"%fr22", 22},
816 {"%fr22l", 22},
817 {"%fr22r", 22},
818 {"%fr23", 23},
819 {"%fr23l", 23},
820 {"%fr23r", 23},
821 {"%fr24", 24},
822 {"%fr24l", 24},
823 {"%fr24r", 24},
824 {"%fr25", 25},
825 {"%fr25l", 25},
826 {"%fr25r", 25},
827 {"%fr26", 26},
828 {"%fr26l", 26},
829 {"%fr26r", 26},
830 {"%fr27", 27},
831 {"%fr27l", 27},
832 {"%fr27r", 27},
833 {"%fr28", 28},
834 {"%fr28l", 28},
835 {"%fr28r", 28},
836 {"%fr29", 29},
837 {"%fr29l", 29},
838 {"%fr29r", 29},
839 {"%fr2l", 2},
840 {"%fr2r", 2},
841 {"%fr3", 3},
842 {"%fr30", 30},
843 {"%fr30l", 30},
844 {"%fr30r", 30},
845 {"%fr31", 31},
846 {"%fr31l", 31},
847 {"%fr31r", 31},
848 {"%fr3l", 3},
849 {"%fr3r", 3},
850 {"%fr4", 4},
851 {"%fr4l", 4},
852 {"%fr4r", 4},
853 {"%fr5", 5},
854 {"%fr5l", 5},
855 {"%fr5r", 5},
856 {"%fr6", 6},
857 {"%fr6l", 6},
858 {"%fr6r", 6},
859 {"%fr7", 7},
860 {"%fr7l", 7},
861 {"%fr7r", 7},
862 {"%fr8", 8},
863 {"%fr8l", 8},
864 {"%fr8r", 8},
865 {"%fr9", 9},
866 {"%fr9l", 9},
867 {"%fr9r", 9},
868 {"%hta", 25},
869 {"%iir", 19},
870 {"%ior", 21},
871 {"%ipsw", 22},
872 {"%isr", 20},
873 {"%itmr", 16},
874 {"%iva", 14},
875 {"%pcoq", 18},
876 {"%pcsq", 17},
877 {"%pidr1", 8},
878 {"%pidr2", 9},
879 {"%pidr3", 12},
880 {"%pidr4", 13},
881 {"%ppda", 24},
882 {"%r0", 0},
883 {"%r1", 1},
884 {"%r10", 10},
885 {"%r11", 11},
886 {"%r12", 12},
887 {"%r13", 13},
888 {"%r14", 14},
889 {"%r15", 15},
890 {"%r16", 16},
891 {"%r17", 17},
892 {"%r18", 18},
893 {"%r19", 19},
894 {"%r2", 2},
895 {"%r20", 20},
896 {"%r21", 21},
897 {"%r22", 22},
898 {"%r23", 23},
899 {"%r24", 24},
900 {"%r25", 25},
901 {"%r26", 26},
902 {"%r27", 27},
903 {"%r28", 28},
904 {"%r29", 29},
905 {"%r3", 3},
906 {"%r30", 30},
907 {"%r31", 31},
908 {"%r4", 4},
909 {"%r5", 5},
910 {"%r6", 6},
911 {"%r7", 7},
912 {"%r8", 8},
913 {"%r9", 9},
914 {"%rctr", 0},
915 {"%ret0", 28},
916 {"%ret1", 29},
917 {"%rp", 2},
918 {"%sar", 11},
919 {"%sp", 30},
920 {"%sr0", 0},
921 {"%sr1", 1},
922 {"%sr2", 2},
923 {"%sr3", 3},
924 {"%sr4", 4},
925 {"%sr5", 5},
926 {"%sr6", 6},
927 {"%sr7", 7},
928 {"%tr0", 24},
929 {"%tr1", 25},
930 {"%tr2", 26},
931 {"%tr3", 27},
932 {"%tr4", 28},
933 {"%tr5", 29},
934 {"%tr6", 30},
935 {"%tr7", 31}
938 /* This table is sorted by order of the length of the string. This is
939 so we check for <> before we check for <. If we had a <> and checked
940 for < first, we would get a false match. */
941 static const struct fp_cond_map fp_cond_map[] =
943 {"false?", 0},
944 {"false", 1},
945 {"true?", 30},
946 {"true", 31},
947 {"!<=>", 3},
948 {"!?>=", 8},
949 {"!?<=", 16},
950 {"!<>", 7},
951 {"!>=", 11},
952 {"!?>", 12},
953 {"?<=", 14},
954 {"!<=", 19},
955 {"!?<", 20},
956 {"?>=", 22},
957 {"!?=", 24},
958 {"!=t", 27},
959 {"<=>", 29},
960 {"=t", 5},
961 {"?=", 6},
962 {"?<", 10},
963 {"<=", 13},
964 {"!>", 15},
965 {"?>", 18},
966 {">=", 21},
967 {"!<", 23},
968 {"<>", 25},
969 {"!=", 26},
970 {"!?", 28},
971 {"?", 2},
972 {"=", 4},
973 {"<", 9},
974 {">", 17}
977 static const struct selector_entry selector_table[] =
979 {"f", e_fsel},
980 {"l", e_lsel},
981 {"ld", e_ldsel},
982 {"lp", e_lpsel},
983 {"lr", e_lrsel},
984 {"ls", e_lssel},
985 {"lt", e_ltsel},
986 {"n", e_nsel},
987 {"nl", e_nlsel},
988 {"nlr", e_nlrsel},
989 {"p", e_psel},
990 {"r", e_rsel},
991 {"rd", e_rdsel},
992 {"rp", e_rpsel},
993 {"rr", e_rrsel},
994 {"rs", e_rssel},
995 {"rt", e_rtsel},
996 {"t", e_tsel},
999 /* default space and subspace dictionaries */
1001 #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
1002 #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
1004 /* pre-defined subsegments (subspaces) for the HPPA. */
1005 #define SUBSEG_CODE 0
1006 #define SUBSEG_LIT 1
1007 #define SUBSEG_MILLI 2
1008 #define SUBSEG_DATA 0
1009 #define SUBSEG_BSS 2
1010 #define SUBSEG_UNWIND 3
1011 #define SUBSEG_GDB_STRINGS 0
1012 #define SUBSEG_GDB_SYMBOLS 1
1014 static struct default_subspace_dict pa_def_subspaces[] =
1016 {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_CODE},
1017 {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, ".data", SUBSEG_DATA},
1018 {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_LIT},
1019 {"$MILLICODE$", 1, 1, 0, 0, 0, 0, 8, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_MILLI},
1020 {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, ".bss", SUBSEG_BSS},
1021 #ifdef OBJ_ELF
1022 {"$UNWIND$", 1, 1, 0, 0, 0, 0, 64, 0x2c, 0, 4, 0, 0, ".PARISC.unwind", SUBSEG_UNWIND},
1023 #endif
1024 {NULL, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
1027 static struct default_space_dict pa_def_spaces[] =
1029 {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL, ".text"},
1030 {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL, ".data"},
1031 {NULL, 0, 0, 0, 0, 0, ASEC_NULL, NULL}
1034 /* Misc local definitions used by the assembler. */
1036 /* Return nonzero if the string pointed to by S potentially represents
1037 a right or left half of a FP register */
1038 #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
1039 #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
1041 /* These macros are used to maintain spaces/subspaces. */
1042 #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined
1043 #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
1044 #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum
1045 #define SPACE_NAME(space_chain) (space_chain)->sd_name
1047 #define SUBSPACE_DEFINED(ss_chain) (ss_chain)->ssd_defined
1048 #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name
1050 /* Insert FIELD into OPCODE starting at bit START. Continue pa_ip
1051 main loop after insertion. */
1053 #define INSERT_FIELD_AND_CONTINUE(OPCODE, FIELD, START) \
1055 ((OPCODE) |= (FIELD) << (START)); \
1056 continue; \
1059 /* Simple range checking for FIELD againt HIGH and LOW bounds.
1060 IGNORE is used to suppress the error message. */
1062 #define CHECK_FIELD(FIELD, HIGH, LOW, IGNORE) \
1064 if ((FIELD) > (HIGH) || (FIELD) < (LOW)) \
1066 if (! IGNORE) \
1067 as_bad (_("Field out of range [%d..%d] (%d)."), (LOW), (HIGH), \
1068 (int) (FIELD));\
1069 break; \
1073 #define is_DP_relative(exp) \
1074 ((exp).X_op == O_subtract \
1075 && strcmp (S_GET_NAME ((exp).X_op_symbol), "$global$") == 0)
1077 #define is_PC_relative(exp) \
1078 ((exp).X_op == O_subtract \
1079 && strcmp (S_GET_NAME ((exp).X_op_symbol), "$PIC_pcrel$0") == 0)
1081 /* We need some complex handling for stabs (sym1 - sym2). Luckily, we'll
1082 always be able to reduce the expression to a constant, so we don't
1083 need real complex handling yet. */
1084 #define is_complex(exp) \
1085 ((exp).X_op != O_constant && (exp).X_op != O_symbol)
1087 /* Actual functions to implement the PA specific code for the assembler. */
1089 /* Called before writing the object file. Make sure entry/exit and
1090 proc/procend pairs match. */
1092 void
1093 pa_check_eof ()
1095 if (within_entry_exit)
1096 as_fatal (_("Missing .exit\n"));
1098 if (within_procedure)
1099 as_fatal (_("Missing .procend\n"));
1102 /* Check to make sure we have a valid space and subspace. */
1104 static void
1105 pa_check_current_space_and_subspace ()
1107 if (current_space == NULL)
1108 as_fatal (_("Not in a space.\n"));
1110 if (current_subspace == NULL)
1111 as_fatal (_("Not in a subspace.\n"));
1114 /* Returns a pointer to the label_symbol_struct for the current space.
1115 or NULL if no label_symbol_struct exists for the current space. */
1117 static label_symbol_struct *
1118 pa_get_label ()
1120 label_symbol_struct *label_chain;
1121 sd_chain_struct *space_chain = current_space;
1123 for (label_chain = label_symbols_rootp;
1124 label_chain;
1125 label_chain = label_chain->lss_next)
1126 if (space_chain == label_chain->lss_space && label_chain->lss_label)
1127 return label_chain;
1129 return NULL;
1132 /* Defines a label for the current space. If one is already defined,
1133 this function will replace it with the new label. */
1135 void
1136 pa_define_label (symbol)
1137 symbolS *symbol;
1139 label_symbol_struct *label_chain = pa_get_label ();
1140 sd_chain_struct *space_chain = current_space;
1142 if (label_chain)
1143 label_chain->lss_label = symbol;
1144 else
1146 /* Create a new label entry and add it to the head of the chain. */
1147 label_chain
1148 = (label_symbol_struct *) xmalloc (sizeof (label_symbol_struct));
1149 label_chain->lss_label = symbol;
1150 label_chain->lss_space = space_chain;
1151 label_chain->lss_next = NULL;
1153 if (label_symbols_rootp)
1154 label_chain->lss_next = label_symbols_rootp;
1156 label_symbols_rootp = label_chain;
1160 /* Removes a label definition for the current space.
1161 If there is no label_symbol_struct entry, then no action is taken. */
1163 static void
1164 pa_undefine_label ()
1166 label_symbol_struct *label_chain;
1167 label_symbol_struct *prev_label_chain = NULL;
1168 sd_chain_struct *space_chain = current_space;
1170 for (label_chain = label_symbols_rootp;
1171 label_chain;
1172 label_chain = label_chain->lss_next)
1174 if (space_chain == label_chain->lss_space && label_chain->lss_label)
1176 /* Remove the label from the chain and free its memory. */
1177 if (prev_label_chain)
1178 prev_label_chain->lss_next = label_chain->lss_next;
1179 else
1180 label_symbols_rootp = label_chain->lss_next;
1182 free (label_chain);
1183 break;
1185 prev_label_chain = label_chain;
1190 /* An HPPA-specific version of fix_new. This is required because the HPPA
1191 code needs to keep track of some extra stuff. Each call to fix_new_hppa
1192 results in the creation of an instance of an hppa_fix_struct. An
1193 hppa_fix_struct stores the extra information along with a pointer to the
1194 original fixS. This is attached to the original fixup via the
1195 tc_fix_data field. */
1197 static void
1198 fix_new_hppa (frag, where, size, add_symbol, offset, exp, pcrel,
1199 r_type, r_field, r_format, arg_reloc, unwind_bits)
1200 fragS *frag;
1201 int where;
1202 int size;
1203 symbolS *add_symbol;
1204 long offset;
1205 expressionS *exp;
1206 int pcrel;
1207 bfd_reloc_code_real_type r_type;
1208 enum hppa_reloc_field_selector_type_alt r_field;
1209 int r_format;
1210 long arg_reloc;
1211 int* unwind_bits;
1213 fixS *new_fix;
1215 struct hppa_fix_struct *hppa_fix = (struct hppa_fix_struct *)
1216 obstack_alloc (&notes, sizeof (struct hppa_fix_struct));
1218 if (exp != NULL)
1219 new_fix = fix_new_exp (frag, where, size, exp, pcrel, r_type);
1220 else
1221 new_fix = fix_new (frag, where, size, add_symbol, offset, pcrel, r_type);
1222 new_fix->tc_fix_data = (void *) hppa_fix;
1223 hppa_fix->fx_r_type = r_type;
1224 hppa_fix->fx_r_field = r_field;
1225 hppa_fix->fx_r_format = r_format;
1226 hppa_fix->fx_arg_reloc = arg_reloc;
1227 hppa_fix->segment = now_seg;
1228 #ifdef OBJ_SOM
1229 if (r_type == R_ENTRY || r_type == R_EXIT)
1230 new_fix->fx_offset = *unwind_bits;
1231 #endif
1233 /* foo-$global$ is used to access non-automatic storage. $global$
1234 is really just a marker and has served its purpose, so eliminate
1235 it now so as not to confuse write.c. */
1236 if (new_fix->fx_subsy
1237 && !strcmp (S_GET_NAME (new_fix->fx_subsy), "$global$"))
1238 new_fix->fx_subsy = NULL;
1241 /* Parse a .byte, .word, .long expression for the HPPA. Called by
1242 cons via the TC_PARSE_CONS_EXPRESSION macro. */
1244 void
1245 parse_cons_expression_hppa (exp)
1246 expressionS *exp;
1248 hppa_field_selector = pa_chk_field_selector (&input_line_pointer);
1249 expression (exp);
1252 /* This fix_new is called by cons via TC_CONS_FIX_NEW.
1253 hppa_field_selector is set by the parse_cons_expression_hppa. */
1255 void
1256 cons_fix_new_hppa (frag, where, size, exp)
1257 fragS *frag;
1258 int where;
1259 int size;
1260 expressionS *exp;
1262 unsigned int rel_type;
1264 /* Get a base relocation type. */
1265 if (is_DP_relative (*exp))
1266 rel_type = R_HPPA_GOTOFF;
1267 else if (is_complex (*exp))
1268 rel_type = R_HPPA_COMPLEX;
1269 else
1270 rel_type = R_HPPA;
1272 if (hppa_field_selector != e_psel && hppa_field_selector != e_fsel)
1273 as_warn (_("Invalid field selector. Assuming F%%."));
1275 fix_new_hppa (frag, where, size,
1276 (symbolS *) NULL, (offsetT) 0, exp, 0, rel_type,
1277 hppa_field_selector, 32, 0, NULL);
1279 /* Reset field selector to its default state. */
1280 hppa_field_selector = 0;
1283 /* This function is called once, at assembler startup time. It should
1284 set up all the tables, etc. that the MD part of the assembler will need. */
1286 void
1287 md_begin ()
1289 const char *retval = NULL;
1290 int lose = 0;
1291 unsigned int i = 0;
1293 last_call_info = NULL;
1294 call_info_root = NULL;
1296 /* Set the default machine type. */
1297 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 10))
1298 as_warn (_("could not set architecture and machine"));
1300 /* Folding of text and data segments fails miserably on the PA.
1301 Warn user and disable "-R" option. */
1302 if (flag_readonly_data_in_text)
1304 as_warn (_("-R option not supported on this target."));
1305 flag_readonly_data_in_text = 0;
1308 pa_spaces_begin ();
1310 op_hash = hash_new ();
1312 while (i < NUMOPCODES)
1314 const char *name = pa_opcodes[i].name;
1315 retval = hash_insert (op_hash, name, (struct pa_opcode *) &pa_opcodes[i]);
1316 if (retval != NULL && *retval != '\0')
1318 as_fatal (_("Internal error: can't hash `%s': %s\n"), name, retval);
1319 lose = 1;
1323 if ((pa_opcodes[i].match & pa_opcodes[i].mask)
1324 != pa_opcodes[i].match)
1326 fprintf (stderr, _("internal error: losing opcode: `%s' \"%s\"\n"),
1327 pa_opcodes[i].name, pa_opcodes[i].args);
1328 lose = 1;
1330 ++i;
1332 while (i < NUMOPCODES && !strcmp (pa_opcodes[i].name, name));
1335 if (lose)
1336 as_fatal (_("Broken assembler. No assembly attempted."));
1338 /* SOM will change text_section. To make sure we never put
1339 anything into the old one switch to the new one now. */
1340 subseg_set (text_section, 0);
1342 dummy_symbol = symbol_find_or_make ("L$dummy");
1343 S_SET_SEGMENT (dummy_symbol, text_section);
1346 /* Assemble a single instruction storing it into a frag. */
1347 void
1348 md_assemble (str)
1349 char *str;
1351 char *to;
1353 /* The had better be something to assemble. */
1354 assert (str);
1356 /* If we are within a procedure definition, make sure we've
1357 defined a label for the procedure; handle case where the
1358 label was defined after the .PROC directive.
1360 Note there's not need to diddle with the segment or fragment
1361 for the label symbol in this case. We have already switched
1362 into the new $CODE$ subspace at this point. */
1363 if (within_procedure && last_call_info->start_symbol == NULL)
1365 label_symbol_struct *label_symbol = pa_get_label ();
1367 if (label_symbol)
1369 if (label_symbol->lss_label)
1371 last_call_info->start_symbol = label_symbol->lss_label;
1372 symbol_get_bfdsym (label_symbol->lss_label)->flags
1373 |= BSF_FUNCTION;
1374 #ifdef OBJ_SOM
1375 /* Also handle allocation of a fixup to hold the unwind
1376 information when the label appears after the proc/procend. */
1377 if (within_entry_exit)
1379 char *where = frag_more (0);
1381 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
1382 NULL, (offsetT) 0, NULL,
1383 0, R_HPPA_ENTRY, e_fsel, 0, 0,
1384 (int *)&last_call_info->ci_unwind.descriptor);
1386 #endif
1388 else
1389 as_bad (_("Missing function name for .PROC (corrupted label chain)"));
1391 else
1392 as_bad (_("Missing function name for .PROC"));
1395 /* Assemble the instruction. Results are saved into "the_insn". */
1396 pa_ip (str);
1398 /* Get somewhere to put the assembled instrution. */
1399 to = frag_more (4);
1401 /* Output the opcode. */
1402 md_number_to_chars (to, the_insn.opcode, 4);
1404 /* If necessary output more stuff. */
1405 if (the_insn.reloc != R_HPPA_NONE)
1406 fix_new_hppa (frag_now, (to - frag_now->fr_literal), 4, NULL,
1407 (offsetT) 0, &the_insn.exp, the_insn.pcrel,
1408 the_insn.reloc, the_insn.field_selector,
1409 the_insn.format, the_insn.arg_reloc, NULL);
1412 /* Do the real work for assembling a single instruction. Store results
1413 into the global "the_insn" variable. */
1415 static void
1416 pa_ip (str)
1417 char *str;
1419 char *error_message = "";
1420 char *s, c, *argstart, *name, *save_s;
1421 const char *args;
1422 int match = FALSE;
1423 int comma = 0;
1424 int cmpltr, nullif, flag, cond, num;
1425 unsigned long opcode;
1426 struct pa_opcode *insn;
1428 /* We must have a valid space and subspace. */
1429 pa_check_current_space_and_subspace ();
1431 /* Skip to something interesting. */
1432 for (s = str; isupper (*s) || islower (*s) || (*s >= '0' && *s <= '3'); ++s)
1435 switch (*s)
1438 case '\0':
1439 break;
1441 case ',':
1442 comma = 1;
1444 /*FALLTHROUGH */
1446 case ' ':
1447 *s++ = '\0';
1448 break;
1450 default:
1451 as_fatal (_("Unknown opcode: `%s'"), str);
1454 save_s = str;
1456 /* Convert everything into lower case. */
1457 while (*save_s)
1459 if (isupper (*save_s))
1460 *save_s = tolower (*save_s);
1461 save_s++;
1464 /* Look up the opcode in the has table. */
1465 if ((insn = (struct pa_opcode *) hash_find (op_hash, str)) == NULL)
1467 as_bad ("Unknown opcode: `%s'", str);
1468 return;
1471 if (comma)
1473 *--s = ',';
1476 /* Mark the location where arguments for the instruction start, then
1477 start processing them. */
1478 argstart = s;
1479 for (;;)
1481 /* Do some initialization. */
1482 opcode = insn->match;
1483 memset (&the_insn, 0, sizeof (the_insn));
1485 the_insn.reloc = R_HPPA_NONE;
1487 /* If this instruction is specific to a particular architecture,
1488 then set a new architecture. */
1489 /* But do not automatically promote to pa2.0. The automatic promotion
1490 crud is for compatability with HP's old assemblers only. */
1491 if (insn->arch < 20
1492 && bfd_get_mach (stdoutput) < insn->arch)
1494 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, insn->arch))
1495 as_warn (_("could not update architecture and machine"));
1497 else if (bfd_get_mach (stdoutput) < insn->arch)
1499 match = FALSE;
1500 goto failed;
1503 /* Build the opcode, checking as we go to make
1504 sure that the operands match. */
1505 for (args = insn->args;; ++args)
1507 switch (*args)
1510 /* End of arguments. */
1511 case '\0':
1512 if (*s == '\0')
1513 match = TRUE;
1514 break;
1516 case '+':
1517 if (*s == '+')
1519 ++s;
1520 continue;
1522 if (*s == '-')
1523 continue;
1524 break;
1526 /* These must match exactly. */
1527 case '(':
1528 case ')':
1529 case ',':
1530 case ' ':
1531 if (*s++ == *args)
1532 continue;
1533 break;
1535 /* Handle a 5 bit register or control register field at 10. */
1536 case 'b':
1537 case '^':
1538 num = pa_parse_number (&s, 0);
1539 CHECK_FIELD (num, 31, 0, 0);
1540 INSERT_FIELD_AND_CONTINUE (opcode, num, 21);
1542 /* Handle a 5 bit register field at 15. */
1543 case 'x':
1544 num = pa_parse_number (&s, 0);
1545 CHECK_FIELD (num, 31, 0, 0);
1546 INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
1548 /* Handle a 5 bit register field at 31. */
1549 case 'y':
1550 case 't':
1551 num = pa_parse_number (&s, 0);
1552 CHECK_FIELD (num, 31, 0, 0);
1553 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
1555 /* Handle a 5 bit field length at 31. */
1556 case 'T':
1557 num = pa_get_absolute_expression (&the_insn, &s);
1558 s = expr_end;
1559 CHECK_FIELD (num, 32, 1, 0);
1560 INSERT_FIELD_AND_CONTINUE (opcode, 32 - num, 0);
1562 /* Handle a 5 bit immediate at 15. */
1563 case '5':
1564 num = pa_get_absolute_expression (&the_insn, &s);
1565 s = expr_end;
1566 CHECK_FIELD (num, 15, -16, 0);
1567 low_sign_unext (num, 5, &num);
1568 INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
1570 /* Handle a 5 bit immediate at 31. */
1571 case 'V':
1572 num = pa_get_absolute_expression (&the_insn, &s);
1573 s = expr_end;
1574 CHECK_FIELD (num, 15, -16, 0)
1575 low_sign_unext (num, 5, &num);
1576 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
1578 /* Handle an unsigned 5 bit immediate at 31. */
1579 case 'r':
1580 num = pa_get_absolute_expression (&the_insn, &s);
1581 s = expr_end;
1582 CHECK_FIELD (num, 31, 0, 0);
1583 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
1585 /* Handle an unsigned 5 bit immediate at 15. */
1586 case 'R':
1587 num = pa_get_absolute_expression (&the_insn, &s);
1588 s = expr_end;
1589 CHECK_FIELD (num, 31, 0, 0);
1590 INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
1592 /* Handle a 2 bit space identifier at 17. */
1593 case 's':
1594 num = pa_parse_number (&s, 0);
1595 CHECK_FIELD (num, 3, 0, 1);
1596 INSERT_FIELD_AND_CONTINUE (opcode, num, 14);
1598 /* Handle a 3 bit space identifier at 18. */
1599 case 'S':
1600 num = pa_parse_number (&s, 0);
1601 CHECK_FIELD (num, 7, 0, 1);
1602 dis_assemble_3 (num, &num);
1603 INSERT_FIELD_AND_CONTINUE (opcode, num, 13);
1605 /* Handle a completer for an indexing load or store. */
1606 case 'c':
1608 int uu = 0;
1609 int m = 0;
1610 int i = 0;
1611 while (*s == ',' && i < 2)
1613 s++;
1614 if (strncasecmp (s, "sm", 2) == 0)
1616 uu = 1;
1617 m = 1;
1618 s++;
1619 i++;
1621 else if (strncasecmp (s, "m", 1) == 0)
1622 m = 1;
1623 else if (strncasecmp (s, "s", 1) == 0)
1624 uu = 1;
1625 else
1626 as_bad (_("Invalid Indexed Load Completer."));
1627 s++;
1628 i++;
1630 if (i > 2)
1631 as_bad (_("Invalid Indexed Load Completer Syntax."));
1632 opcode |= m << 5;
1633 INSERT_FIELD_AND_CONTINUE (opcode, uu, 13);
1636 /* Handle a short load/store completer. */
1637 case 'C':
1639 int a = 0;
1640 int m = 0;
1641 if (*s == ',')
1643 s++;
1644 if (strncasecmp (s, "ma", 2) == 0)
1646 a = 0;
1647 m = 1;
1649 else if (strncasecmp (s, "mb", 2) == 0)
1651 a = 1;
1652 m = 1;
1654 else
1655 as_bad (_("Invalid Short Load/Store Completer."));
1656 s += 2;
1659 if (*args == 'C')
1661 opcode |= m << 5;
1662 INSERT_FIELD_AND_CONTINUE (opcode, a, 13);
1666 /* Handle a stbys completer. */
1667 case 'Y':
1669 int a = 0;
1670 int m = 0;
1671 int i = 0;
1672 while (*s == ',' && i < 2)
1674 s++;
1675 if (strncasecmp (s, "m", 1) == 0)
1676 m = 1;
1677 else if (strncasecmp (s, "b", 1) == 0)
1678 a = 0;
1679 else if (strncasecmp (s, "e", 1) == 0)
1680 a = 1;
1681 else
1682 as_bad (_("Invalid Store Bytes Short Completer"));
1683 s++;
1684 i++;
1686 if (i > 2)
1687 as_bad (_("Invalid Store Bytes Short Completer"));
1688 opcode |= m << 5;
1689 INSERT_FIELD_AND_CONTINUE (opcode, a, 13);
1692 /* Handle a non-negated compare/stubtract condition. */
1693 case '<':
1694 cmpltr = pa_parse_nonneg_cmpsub_cmpltr (&s, 1);
1695 if (cmpltr < 0)
1697 as_bad (_("Invalid Compare/Subtract Condition: %c"), *s);
1698 cmpltr = 0;
1700 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
1702 /* Handle a negated or non-negated compare/subtract condition. */
1703 case '?':
1704 save_s = s;
1705 cmpltr = pa_parse_nonneg_cmpsub_cmpltr (&s, 1);
1706 if (cmpltr < 0)
1708 s = save_s;
1709 cmpltr = pa_parse_neg_cmpsub_cmpltr (&s, 1);
1710 if (cmpltr < 0)
1712 as_bad (_("Invalid Compare/Subtract Condition."));
1713 cmpltr = 0;
1715 else
1717 /* Negated condition requires an opcode change. */
1718 opcode |= 1 << 27;
1722 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
1724 /* Handle non-negated add condition. */
1725 case '!':
1726 cmpltr = pa_parse_nonneg_add_cmpltr (&s, 1);
1727 if (cmpltr < 0)
1729 as_bad (_("Invalid Compare/Subtract Condition: %c"), *s);
1730 cmpltr = 0;
1732 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
1734 /* Handle a negated or non-negated add condition. */
1735 case '@':
1736 save_s = s;
1737 cmpltr = pa_parse_nonneg_add_cmpltr (&s, 1);
1738 if (cmpltr < 0)
1740 s = save_s;
1741 cmpltr = pa_parse_neg_add_cmpltr (&s, 1);
1742 if (cmpltr < 0)
1744 as_bad (_("Invalid Compare/Subtract Condition"));
1745 cmpltr = 0;
1747 else
1749 /* Negated condition requires an opcode change. */
1750 opcode |= 1 << 27;
1753 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
1755 /* Handle a compare/subtract condition. */
1756 case 'a':
1757 cmpltr = 0;
1758 flag = 0;
1759 if (*s == ',')
1761 s++;
1762 name = s;
1763 while (*s != ',' && *s != ' ' && *s != '\t')
1764 s += 1;
1765 c = *s;
1766 *s = 0x00;
1767 if (strcmp (name, "=") == 0)
1768 cmpltr = 1;
1769 else if (strcmp (name, "<") == 0)
1770 cmpltr = 2;
1771 else if (strcmp (name, "<=") == 0)
1772 cmpltr = 3;
1773 else if (strcasecmp (name, "<<") == 0)
1774 cmpltr = 4;
1775 else if (strcasecmp (name, "<<=") == 0)
1776 cmpltr = 5;
1777 else if (strcasecmp (name, "sv") == 0)
1778 cmpltr = 6;
1779 else if (strcasecmp (name, "od") == 0)
1780 cmpltr = 7;
1781 else if (strcasecmp (name, "tr") == 0)
1783 cmpltr = 0;
1784 flag = 1;
1786 else if (strcmp (name, "<>") == 0)
1788 cmpltr = 1;
1789 flag = 1;
1791 else if (strcmp (name, ">=") == 0)
1793 cmpltr = 2;
1794 flag = 1;
1796 else if (strcmp (name, ">") == 0)
1798 cmpltr = 3;
1799 flag = 1;
1801 else if (strcasecmp (name, ">>=") == 0)
1803 cmpltr = 4;
1804 flag = 1;
1806 else if (strcasecmp (name, ">>") == 0)
1808 cmpltr = 5;
1809 flag = 1;
1811 else if (strcasecmp (name, "nsv") == 0)
1813 cmpltr = 6;
1814 flag = 1;
1816 else if (strcasecmp (name, "ev") == 0)
1818 cmpltr = 7;
1819 flag = 1;
1821 else
1822 as_bad (_("Invalid Add Condition: %s"), name);
1823 *s = c;
1825 opcode |= cmpltr << 13;
1826 INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
1828 /* Handle a non-negated add condition. */
1829 case 'd':
1830 cmpltr = 0;
1831 flag = 0;
1832 if (*s == ',')
1834 s++;
1835 name = s;
1836 while (*s != ',' && *s != ' ' && *s != '\t')
1837 s += 1;
1838 c = *s;
1839 *s = 0x00;
1840 if (strcmp (name, "=") == 0)
1841 cmpltr = 1;
1842 else if (strcmp (name, "<") == 0)
1843 cmpltr = 2;
1844 else if (strcmp (name, "<=") == 0)
1845 cmpltr = 3;
1846 else if (strcasecmp (name, "nuv") == 0)
1847 cmpltr = 4;
1848 else if (strcasecmp (name, "znv") == 0)
1849 cmpltr = 5;
1850 else if (strcasecmp (name, "sv") == 0)
1851 cmpltr = 6;
1852 else if (strcasecmp (name, "od") == 0)
1853 cmpltr = 7;
1854 else if (strcasecmp (name, "tr") == 0)
1856 cmpltr = 0;
1857 flag = 1;
1859 else if (strcmp (name, "<>") == 0)
1861 cmpltr = 1;
1862 flag = 1;
1864 else if (strcmp (name, ">=") == 0)
1866 cmpltr = 2;
1867 flag = 1;
1869 else if (strcmp (name, ">") == 0)
1871 cmpltr = 3;
1872 flag = 1;
1874 else if (strcasecmp (name, "uv") == 0)
1876 cmpltr = 4;
1877 flag = 1;
1879 else if (strcasecmp (name, "vnz") == 0)
1881 cmpltr = 5;
1882 flag = 1;
1884 else if (strcasecmp (name, "nsv") == 0)
1886 cmpltr = 6;
1887 flag = 1;
1889 else if (strcasecmp (name, "ev") == 0)
1891 cmpltr = 7;
1892 flag = 1;
1894 else
1895 as_bad (_("Invalid Add Condition: %s"), name);
1896 *s = c;
1898 opcode |= cmpltr << 13;
1899 INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
1901 /* HANDLE a logical instruction condition. */
1902 case '&':
1903 cmpltr = 0;
1904 flag = 0;
1905 if (*s == ',')
1907 s++;
1908 name = s;
1909 while (*s != ',' && *s != ' ' && *s != '\t')
1910 s += 1;
1911 c = *s;
1912 *s = 0x00;
1915 if (strcmp (name, "=") == 0)
1916 cmpltr = 1;
1917 else if (strcmp (name, "<") == 0)
1918 cmpltr = 2;
1919 else if (strcmp (name, "<=") == 0)
1920 cmpltr = 3;
1921 else if (strcasecmp (name, "od") == 0)
1922 cmpltr = 7;
1923 else if (strcasecmp (name, "tr") == 0)
1925 cmpltr = 0;
1926 flag = 1;
1928 else if (strcmp (name, "<>") == 0)
1930 cmpltr = 1;
1931 flag = 1;
1933 else if (strcmp (name, ">=") == 0)
1935 cmpltr = 2;
1936 flag = 1;
1938 else if (strcmp (name, ">") == 0)
1940 cmpltr = 3;
1941 flag = 1;
1943 else if (strcasecmp (name, "ev") == 0)
1945 cmpltr = 7;
1946 flag = 1;
1948 else
1949 as_bad (_("Invalid Logical Instruction Condition."));
1950 *s = c;
1952 opcode |= cmpltr << 13;
1953 INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
1955 /* Handle a unit instruction condition. */
1956 case 'U':
1957 cmpltr = 0;
1958 flag = 0;
1959 if (*s == ',')
1961 s++;
1964 if (strncasecmp (s, "sbz", 3) == 0)
1966 cmpltr = 2;
1967 s += 3;
1969 else if (strncasecmp (s, "shz", 3) == 0)
1971 cmpltr = 3;
1972 s += 3;
1974 else if (strncasecmp (s, "sdc", 3) == 0)
1976 cmpltr = 4;
1977 s += 3;
1979 else if (strncasecmp (s, "sbc", 3) == 0)
1981 cmpltr = 6;
1982 s += 3;
1984 else if (strncasecmp (s, "shc", 3) == 0)
1986 cmpltr = 7;
1987 s += 3;
1989 else if (strncasecmp (s, "tr", 2) == 0)
1991 cmpltr = 0;
1992 flag = 1;
1993 s += 2;
1995 else if (strncasecmp (s, "nbz", 3) == 0)
1997 cmpltr = 2;
1998 flag = 1;
1999 s += 3;
2001 else if (strncasecmp (s, "nhz", 3) == 0)
2003 cmpltr = 3;
2004 flag = 1;
2005 s += 3;
2007 else if (strncasecmp (s, "ndc", 3) == 0)
2009 cmpltr = 4;
2010 flag = 1;
2011 s += 3;
2013 else if (strncasecmp (s, "nbc", 3) == 0)
2015 cmpltr = 6;
2016 flag = 1;
2017 s += 3;
2019 else if (strncasecmp (s, "nhc", 3) == 0)
2021 cmpltr = 7;
2022 flag = 1;
2023 s += 3;
2025 else
2026 as_bad (_("Invalid Logical Instruction Condition."));
2028 opcode |= cmpltr << 13;
2029 INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
2031 /* Handle a shift/extract/deposit condition. */
2032 case '|':
2033 case '>':
2034 cmpltr = 0;
2035 if (*s == ',')
2037 save_s = s++;
2040 name = s;
2041 while (*s != ',' && *s != ' ' && *s != '\t')
2042 s += 1;
2043 c = *s;
2044 *s = 0x00;
2045 if (strcmp (name, "=") == 0)
2046 cmpltr = 1;
2047 else if (strcmp (name, "<") == 0)
2048 cmpltr = 2;
2049 else if (strcasecmp (name, "od") == 0)
2050 cmpltr = 3;
2051 else if (strcasecmp (name, "tr") == 0)
2052 cmpltr = 4;
2053 else if (strcmp (name, "<>") == 0)
2054 cmpltr = 5;
2055 else if (strcmp (name, ">=") == 0)
2056 cmpltr = 6;
2057 else if (strcasecmp (name, "ev") == 0)
2058 cmpltr = 7;
2059 /* Handle movb,n. Put things back the way they were.
2060 This includes moving s back to where it started. */
2061 else if (strcasecmp (name, "n") == 0 && *args == '|')
2063 *s = c;
2064 s = save_s;
2065 continue;
2067 else
2068 as_bad (_("Invalid Shift/Extract/Deposit Condition."));
2069 *s = c;
2071 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
2073 /* Handle bvb and bb conditions. */
2074 case '~':
2075 cmpltr = 0;
2076 if (*s == ',')
2078 s++;
2079 if (strncmp (s, "<", 1) == 0)
2081 cmpltr = 0;
2082 s++;
2084 else if (strncmp (s, ">=", 2) == 0)
2086 cmpltr = 1;
2087 s += 2;
2089 else
2090 as_bad (_("Invalid Bit Branch Condition: %c"), *s);
2092 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 15);
2094 /* Handle a system control completer. */
2095 case 'Z':
2096 if (*s == ',' && (*(s + 1) == 'm' || *(s + 1) == 'M'))
2098 flag = 1;
2099 s += 2;
2101 else
2102 flag = 0;
2104 INSERT_FIELD_AND_CONTINUE (opcode, flag, 5);
2106 /* Handle a nullification completer for branch instructions. */
2107 case 'n':
2108 nullif = pa_parse_nullif (&s);
2109 INSERT_FIELD_AND_CONTINUE (opcode, nullif, 1);
2111 /* Handle a nullification completer for copr and spop insns. */
2112 case 'N':
2113 nullif = pa_parse_nullif (&s);
2114 INSERT_FIELD_AND_CONTINUE (opcode, nullif, 5);
2117 /* Handle a 11 bit immediate at 31. */
2118 case 'i':
2119 the_insn.field_selector = pa_chk_field_selector (&s);
2120 get_expression (s);
2121 s = expr_end;
2122 if (the_insn.exp.X_op == O_constant)
2124 num = evaluate_absolute (&the_insn);
2125 CHECK_FIELD (num, 1023, -1024, 0);
2126 low_sign_unext (num, 11, &num);
2127 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2129 else
2131 if (is_DP_relative (the_insn.exp))
2132 the_insn.reloc = R_HPPA_GOTOFF;
2133 else if (is_PC_relative (the_insn.exp))
2134 the_insn.reloc = R_HPPA_PCREL_CALL;
2135 else
2136 the_insn.reloc = R_HPPA;
2137 the_insn.format = 11;
2138 continue;
2142 /* Handle a 14 bit immediate at 31. */
2143 case 'j':
2144 the_insn.field_selector = pa_chk_field_selector (&s);
2145 get_expression (s);
2146 s = expr_end;
2147 if (the_insn.exp.X_op == O_constant)
2149 num = evaluate_absolute (&the_insn);
2150 CHECK_FIELD (num, 8191, -8192, 0);
2151 low_sign_unext (num, 14, &num);
2152 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2154 else
2156 if (is_DP_relative (the_insn.exp))
2157 the_insn.reloc = R_HPPA_GOTOFF;
2158 else if (is_PC_relative (the_insn.exp))
2159 the_insn.reloc = R_HPPA_PCREL_CALL;
2160 else
2161 the_insn.reloc = R_HPPA;
2162 the_insn.format = 14;
2163 continue;
2166 /* Handle a 21 bit immediate at 31. */
2167 case 'k':
2168 the_insn.field_selector = pa_chk_field_selector (&s);
2169 get_expression (s);
2170 s = expr_end;
2171 if (the_insn.exp.X_op == O_constant)
2173 num = evaluate_absolute (&the_insn);
2174 CHECK_FIELD (num >> 11, 1048575, -1048576, 0);
2175 dis_assemble_21 (num, &num);
2176 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2178 else
2180 if (is_DP_relative (the_insn.exp))
2181 the_insn.reloc = R_HPPA_GOTOFF;
2182 else if (is_PC_relative (the_insn.exp))
2183 the_insn.reloc = R_HPPA_PCREL_CALL;
2184 else
2185 the_insn.reloc = R_HPPA;
2186 the_insn.format = 21;
2187 continue;
2190 /* Handle a 12 bit branch displacement. */
2191 case 'w':
2192 the_insn.field_selector = pa_chk_field_selector (&s);
2193 get_expression (s);
2194 s = expr_end;
2195 the_insn.pcrel = 1;
2196 if (!strcmp (S_GET_NAME (the_insn.exp.X_add_symbol), "L$0\001"))
2198 unsigned int w1, w, result;
2200 num = evaluate_absolute (&the_insn);
2201 if (num % 4)
2203 as_bad (_("Branch to unaligned address"));
2204 break;
2206 CHECK_FIELD (num, 8199, -8184, 0);
2207 sign_unext ((num - 8) >> 2, 12, &result);
2208 dis_assemble_12 (result, &w1, &w);
2209 INSERT_FIELD_AND_CONTINUE (opcode, ((w1 << 2) | w), 0);
2211 else
2213 the_insn.reloc = R_HPPA_PCREL_CALL;
2214 the_insn.format = 12;
2215 the_insn.arg_reloc = last_call_desc.arg_reloc;
2216 memset (&last_call_desc, 0, sizeof (struct call_desc));
2217 s = expr_end;
2218 continue;
2221 /* Handle a 17 bit branch displacement. */
2222 case 'W':
2223 the_insn.field_selector = pa_chk_field_selector (&s);
2224 get_expression (s);
2225 s = expr_end;
2226 the_insn.pcrel = 1;
2227 if (!the_insn.exp.X_add_symbol
2228 || !strcmp (S_GET_NAME (the_insn.exp.X_add_symbol),
2229 "L$0\001"))
2231 unsigned int w2, w1, w, result;
2233 num = evaluate_absolute (&the_insn);
2234 if (num % 4)
2236 as_bad (_("Branch to unaligned address"));
2237 break;
2239 CHECK_FIELD (num, 262143, -262144, 0);
2241 if (the_insn.exp.X_add_symbol)
2242 num -= 8;
2244 sign_unext (num >> 2, 17, &result);
2245 dis_assemble_17 (result, &w1, &w2, &w);
2246 INSERT_FIELD_AND_CONTINUE (opcode,
2247 ((w2 << 2) | (w1 << 16) | w), 0);
2249 else
2251 the_insn.reloc = R_HPPA_PCREL_CALL;
2252 the_insn.format = 17;
2253 the_insn.arg_reloc = last_call_desc.arg_reloc;
2254 memset (&last_call_desc, 0, sizeof (struct call_desc));
2255 continue;
2258 /* Handle an absolute 17 bit branch target. */
2259 case 'z':
2260 the_insn.field_selector = pa_chk_field_selector (&s);
2261 get_expression (s);
2262 s = expr_end;
2263 the_insn.pcrel = 0;
2264 if (!the_insn.exp.X_add_symbol
2265 || !strcmp (S_GET_NAME (the_insn.exp.X_add_symbol),
2266 "L$0\001"))
2268 unsigned int w2, w1, w, result;
2270 num = evaluate_absolute (&the_insn);
2271 if (num % 4)
2273 as_bad (_("Branch to unaligned address"));
2274 break;
2276 CHECK_FIELD (num, 262143, -262144, 0);
2278 if (the_insn.exp.X_add_symbol)
2279 num -= 8;
2281 sign_unext (num >> 2, 17, &result);
2282 dis_assemble_17 (result, &w1, &w2, &w);
2283 INSERT_FIELD_AND_CONTINUE (opcode,
2284 ((w2 << 2) | (w1 << 16) | w), 0);
2286 else
2288 the_insn.reloc = R_HPPA_ABS_CALL;
2289 the_insn.format = 17;
2290 the_insn.arg_reloc = last_call_desc.arg_reloc;
2291 memset (&last_call_desc, 0, sizeof (struct call_desc));
2292 continue;
2295 /* Handle a 5 bit shift count at 26. */
2296 case 'p':
2297 num = pa_get_absolute_expression (&the_insn, &s);
2298 s = expr_end;
2299 CHECK_FIELD (num, 31, 0, 0);
2300 INSERT_FIELD_AND_CONTINUE (opcode, 31 - num, 5);
2302 /* Handle a 5 bit bit position at 26. */
2303 case 'P':
2304 num = pa_get_absolute_expression (&the_insn, &s);
2305 s = expr_end;
2306 CHECK_FIELD (num, 31, 0, 0);
2307 INSERT_FIELD_AND_CONTINUE (opcode, num, 5);
2309 /* Handle a 5 bit immediate at 10. */
2310 case 'Q':
2312 num = pa_get_absolute_expression (&the_insn, &s);
2313 if (the_insn.exp.X_op != O_constant)
2314 break;
2315 s = expr_end;
2316 CHECK_FIELD (num, 31, 0, 0);
2317 INSERT_FIELD_AND_CONTINUE (opcode, num, 21);
2319 /* Handle a 13 bit immediate at 18. */
2320 case 'A':
2321 num = pa_get_absolute_expression (&the_insn, &s);
2322 s = expr_end;
2323 CHECK_FIELD (num, 8191, 0, 0);
2324 INSERT_FIELD_AND_CONTINUE (opcode, num, 13);
2326 /* Handle a 26 bit immediate at 31. */
2327 case 'D':
2328 num = pa_get_absolute_expression (&the_insn, &s);
2329 s = expr_end;
2330 CHECK_FIELD (num, 671108864, 0, 0);
2331 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2333 /* Handle a 3 bit SFU identifier at 25. */
2334 case 'f':
2335 if (*s++ != ',')
2336 as_bad (_("Invalid SFU identifier"));
2337 num = pa_get_absolute_expression (&the_insn, &s);
2338 s = expr_end;
2339 CHECK_FIELD (num, 7, 0, 0);
2340 INSERT_FIELD_AND_CONTINUE (opcode, num, 6);
2342 /* Handle a 20 bit SOP field for spop0. */
2343 case 'O':
2344 num = pa_get_absolute_expression (&the_insn, &s);
2345 s = expr_end;
2346 CHECK_FIELD (num, 1048575, 0, 0);
2347 num = (num & 0x1f) | ((num & 0x000fffe0) << 6);
2348 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2350 /* Handle a 15bit SOP field for spop1. */
2351 case 'o':
2352 num = pa_get_absolute_expression (&the_insn, &s);
2353 s = expr_end;
2354 CHECK_FIELD (num, 32767, 0, 0);
2355 INSERT_FIELD_AND_CONTINUE (opcode, num, 11);
2357 /* Handle a 10bit SOP field for spop3. */
2358 case '0':
2359 num = pa_get_absolute_expression (&the_insn, &s);
2360 s = expr_end;
2361 CHECK_FIELD (num, 1023, 0, 0);
2362 num = (num & 0x1f) | ((num & 0x000003e0) << 6);
2363 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2365 /* Handle a 15 bit SOP field for spop2. */
2366 case '1':
2367 num = pa_get_absolute_expression (&the_insn, &s);
2368 s = expr_end;
2369 CHECK_FIELD (num, 32767, 0, 0);
2370 num = (num & 0x1f) | ((num & 0x00007fe0) << 6);
2371 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2373 /* Handle a 3-bit co-processor ID field. */
2374 case 'u':
2375 if (*s++ != ',')
2376 as_bad (_("Invalid COPR identifier"));
2377 num = pa_get_absolute_expression (&the_insn, &s);
2378 s = expr_end;
2379 CHECK_FIELD (num, 7, 0, 0);
2380 INSERT_FIELD_AND_CONTINUE (opcode, num, 6);
2382 /* Handle a 22bit SOP field for copr. */
2383 case '2':
2384 num = pa_get_absolute_expression (&the_insn, &s);
2385 s = expr_end;
2386 CHECK_FIELD (num, 4194303, 0, 0);
2387 num = (num & 0x1f) | ((num & 0x003fffe0) << 4);
2388 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
2391 /* Handle a source FP operand format completer. */
2392 case 'F':
2393 flag = pa_parse_fp_format (&s);
2394 the_insn.fpof1 = flag;
2395 INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
2397 /* Handle a destination FP operand format completer. */
2398 case 'G':
2399 /* pa_parse_format needs the ',' prefix. */
2400 s--;
2401 flag = pa_parse_fp_format (&s);
2402 the_insn.fpof2 = flag;
2403 INSERT_FIELD_AND_CONTINUE (opcode, flag, 13);
2405 /* Handle FP compare conditions. */
2406 case 'M':
2407 cond = pa_parse_fp_cmp_cond (&s);
2408 INSERT_FIELD_AND_CONTINUE (opcode, cond, 0);
2410 /* Handle L/R register halves like 't'. */
2411 case 'v':
2413 struct pa_11_fp_reg_struct result;
2415 pa_parse_number (&s, &result);
2416 CHECK_FIELD (result.number_part, 31, 0, 0);
2417 opcode |= result.number_part;
2419 /* 0x30 opcodes are FP arithmetic operation opcodes
2420 and need to be turned into 0x38 opcodes. This
2421 is not necessary for loads/stores. */
2422 if (need_pa11_opcode (&the_insn, &result)
2423 && ((opcode & 0xfc000000) == 0x30000000))
2424 opcode |= 1 << 27;
2426 INSERT_FIELD_AND_CONTINUE (opcode, result.l_r_select & 1, 6);
2429 /* Handle L/R register halves like 'b'. */
2430 case 'E':
2432 struct pa_11_fp_reg_struct result;
2434 pa_parse_number (&s, &result);
2435 CHECK_FIELD (result.number_part, 31, 0, 0);
2436 opcode |= result.number_part << 21;
2437 if (need_pa11_opcode (&the_insn, &result))
2439 opcode |= (result.l_r_select & 1) << 7;
2440 opcode |= 1 << 27;
2442 continue;
2445 /* Handle L/R register halves like 'b'. */
2446 case '3':
2448 struct pa_11_fp_reg_struct result;
2449 int regnum;
2451 pa_parse_number (&s, &result);
2452 CHECK_FIELD (result.number_part, 31, 0, 0);
2453 opcode |= (result.number_part & 0x1c) << 11;
2454 opcode |= (result.number_part & 0x3) << 9;
2455 opcode |= (result.l_r_select & 1) << 8;
2456 continue;
2459 /* Handle L/R register halves like 'x'. */
2460 case 'e':
2462 struct pa_11_fp_reg_struct result;
2464 pa_parse_number (&s, &result);
2465 CHECK_FIELD (result.number_part, 31, 0, 0);
2466 opcode |= (result.number_part & 0x1f) << 16;
2467 if (need_pa11_opcode (&the_insn, &result))
2469 opcode |= (result.l_r_select & 1) << 1;
2471 continue;
2474 /* Handle L/R register halves like 'x'. */
2475 case 'X':
2477 struct pa_11_fp_reg_struct result;
2479 pa_parse_number (&s, &result);
2480 CHECK_FIELD (result.number_part, 31, 0, 0);
2481 opcode |= (result.number_part & 0x1f) << 16;
2482 if (need_pa11_opcode (&the_insn, &result))
2484 opcode |= (result.l_r_select & 1) << 12;
2485 opcode |= 1 << 27;
2487 continue;
2490 /* Handle a 5 bit register field at 10. */
2491 case '4':
2493 struct pa_11_fp_reg_struct result;
2495 pa_parse_number (&s, &result);
2496 CHECK_FIELD (result.number_part, 31, 0, 0);
2497 if (the_insn.fpof1 == SGL)
2499 if (result.number_part < 16)
2501 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
2502 break;
2505 result.number_part &= 0xF;
2506 result.number_part |= (result.l_r_select & 1) << 4;
2508 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 21);
2511 /* Handle a 5 bit register field at 15. */
2512 case '6':
2514 struct pa_11_fp_reg_struct result;
2516 pa_parse_number (&s, &result);
2517 CHECK_FIELD (result.number_part, 31, 0, 0);
2518 if (the_insn.fpof1 == SGL)
2520 if (result.number_part < 16)
2522 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
2523 break;
2525 result.number_part &= 0xF;
2526 result.number_part |= (result.l_r_select & 1) << 4;
2528 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 16);
2531 /* Handle a 5 bit register field at 31. */
2532 case '7':
2534 struct pa_11_fp_reg_struct result;
2536 pa_parse_number (&s, &result);
2537 CHECK_FIELD (result.number_part, 31, 0, 0);
2538 if (the_insn.fpof1 == SGL)
2540 if (result.number_part < 16)
2542 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
2543 break;
2545 result.number_part &= 0xF;
2546 result.number_part |= (result.l_r_select & 1) << 4;
2548 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 0);
2551 /* Handle a 5 bit register field at 20. */
2552 case '8':
2554 struct pa_11_fp_reg_struct result;
2556 pa_parse_number (&s, &result);
2557 CHECK_FIELD (result.number_part, 31, 0, 0);
2558 if (the_insn.fpof1 == SGL)
2560 if (result.number_part < 16)
2562 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
2563 break;
2565 result.number_part &= 0xF;
2566 result.number_part |= (result.l_r_select & 1) << 4;
2568 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 11);
2571 /* Handle a 5 bit register field at 25. */
2572 case '9':
2574 struct pa_11_fp_reg_struct result;
2576 pa_parse_number (&s, &result);
2577 CHECK_FIELD (result.number_part, 31, 0, 0);
2578 if (the_insn.fpof1 == SGL)
2580 if (result.number_part < 16)
2582 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
2583 break;
2585 result.number_part &= 0xF;
2586 result.number_part |= (result.l_r_select & 1) << 4;
2588 INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 6);
2591 /* Handle a floating point operand format at 26.
2592 Only allows single and double precision. */
2593 case 'H':
2594 flag = pa_parse_fp_format (&s);
2595 switch (flag)
2597 case SGL:
2598 opcode |= 0x20;
2599 case DBL:
2600 the_insn.fpof1 = flag;
2601 continue;
2603 case QUAD:
2604 case ILLEGAL_FMT:
2605 default:
2606 as_bad (_("Invalid Floating Point Operand Format."));
2608 break;
2610 default:
2611 abort ();
2613 break;
2616 failed:
2617 /* Check if the args matched. */
2618 if (match == FALSE)
2620 if (&insn[1] - pa_opcodes < (int) NUMOPCODES
2621 && !strcmp (insn->name, insn[1].name))
2623 ++insn;
2624 s = argstart;
2625 continue;
2627 else
2629 as_bad (_("Invalid operands %s"), error_message);
2630 return;
2633 break;
2636 the_insn.opcode = opcode;
2639 /* Turn a string in input_line_pointer into a floating point constant of type
2640 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2641 emitted is stored in *sizeP . An error message or NULL is returned. */
2643 #define MAX_LITTLENUMS 6
2645 char *
2646 md_atof (type, litP, sizeP)
2647 char type;
2648 char *litP;
2649 int *sizeP;
2651 int prec;
2652 LITTLENUM_TYPE words[MAX_LITTLENUMS];
2653 LITTLENUM_TYPE *wordP;
2654 char *t;
2656 switch (type)
2659 case 'f':
2660 case 'F':
2661 case 's':
2662 case 'S':
2663 prec = 2;
2664 break;
2666 case 'd':
2667 case 'D':
2668 case 'r':
2669 case 'R':
2670 prec = 4;
2671 break;
2673 case 'x':
2674 case 'X':
2675 prec = 6;
2676 break;
2678 case 'p':
2679 case 'P':
2680 prec = 6;
2681 break;
2683 default:
2684 *sizeP = 0;
2685 return _("Bad call to MD_ATOF()");
2687 t = atof_ieee (input_line_pointer, type, words);
2688 if (t)
2689 input_line_pointer = t;
2690 *sizeP = prec * sizeof (LITTLENUM_TYPE);
2691 for (wordP = words; prec--;)
2693 md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE));
2694 litP += sizeof (LITTLENUM_TYPE);
2696 return NULL;
2699 /* Write out big-endian. */
2701 void
2702 md_number_to_chars (buf, val, n)
2703 char *buf;
2704 valueT val;
2705 int n;
2707 number_to_chars_bigendian (buf, val, n);
2710 /* Translate internal representation of relocation info to BFD target
2711 format. */
2713 arelent **
2714 tc_gen_reloc (section, fixp)
2715 asection *section;
2716 fixS *fixp;
2718 arelent *reloc;
2719 struct hppa_fix_struct *hppa_fixp;
2720 bfd_reloc_code_real_type code;
2721 static arelent *no_relocs = NULL;
2722 arelent **relocs;
2723 bfd_reloc_code_real_type **codes;
2724 int n_relocs;
2725 int i;
2727 hppa_fixp = (struct hppa_fix_struct *) fixp->tc_fix_data;
2728 if (fixp->fx_addsy == 0)
2729 return &no_relocs;
2730 assert (hppa_fixp != 0);
2731 assert (section != 0);
2733 reloc = (arelent *) xmalloc (sizeof (arelent));
2735 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2736 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2737 codes = (bfd_reloc_code_real_type **) hppa_gen_reloc_type (stdoutput,
2738 fixp->fx_r_type,
2739 hppa_fixp->fx_r_format,
2740 hppa_fixp->fx_r_field,
2741 fixp->fx_subsy != NULL,
2742 symbol_get_bfdsym (fixp->fx_addsy));
2744 if (codes == NULL)
2745 abort ();
2747 for (n_relocs = 0; codes[n_relocs]; n_relocs++)
2750 relocs = (arelent **) xmalloc (sizeof (arelent *) * n_relocs + 1);
2751 reloc = (arelent *) xmalloc (sizeof (arelent) * n_relocs);
2752 for (i = 0; i < n_relocs; i++)
2753 relocs[i] = &reloc[i];
2755 relocs[n_relocs] = NULL;
2757 #ifdef OBJ_ELF
2758 switch (fixp->fx_r_type)
2760 default:
2761 assert (n_relocs == 1);
2763 code = *codes[0];
2765 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2766 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2767 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
2768 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2769 reloc->addend = 0; /* default */
2771 assert (reloc->howto && code == reloc->howto->type);
2773 /* Now, do any processing that is dependent on the relocation type. */
2774 switch (code)
2776 case R_PARISC_DLTREL21L:
2777 case R_PARISC_DLTREL14R:
2778 case R_PARISC_DLTREL14F:
2779 case R_PARISC_PLABEL32:
2780 case R_PARISC_PLABEL21L:
2781 case R_PARISC_PLABEL14R:
2782 /* For plabel relocations, the addend of the
2783 relocation should be either 0 (no static link) or 2
2784 (static link required).
2786 FIXME: We always assume no static link!
2788 We also slam a zero addend into the DLT relative relocs;
2789 it doesn't make a lot of sense to use any addend since
2790 it gets you a different (eg unknown) DLT entry. */
2791 reloc->addend = 0;
2792 break;
2794 case R_PARISC_PCREL21L:
2795 case R_PARISC_PCREL17R:
2796 case R_PARISC_PCREL17F:
2797 case R_PARISC_PCREL17C:
2798 case R_PARISC_PCREL14R:
2799 case R_PARISC_PCREL14F:
2800 /* The constant is stored in the instruction. */
2801 reloc->addend = HPPA_R_ADDEND (hppa_fixp->fx_arg_reloc, 0);
2802 break;
2803 default:
2804 reloc->addend = fixp->fx_offset;
2805 break;
2807 break;
2809 #else /* OBJ_SOM */
2811 /* Walk over reach relocation returned by the BFD backend. */
2812 for (i = 0; i < n_relocs; i++)
2814 code = *codes[i];
2816 relocs[i]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2817 *relocs[i]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2818 relocs[i]->howto = bfd_reloc_type_lookup (stdoutput, code);
2819 relocs[i]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2821 switch (code)
2823 case R_COMP2:
2824 /* The only time we ever use a R_COMP2 fixup is for the difference
2825 of two symbols. With that in mind we fill in all four
2826 relocs now and break out of the loop. */
2827 assert (i == 1);
2828 relocs[0]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2829 *relocs[0]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2830 relocs[0]->howto = bfd_reloc_type_lookup (stdoutput, *codes[0]);
2831 relocs[0]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2832 relocs[0]->addend = 0;
2833 relocs[1]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2834 *relocs[1]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2835 relocs[1]->howto = bfd_reloc_type_lookup (stdoutput, *codes[1]);
2836 relocs[1]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2837 relocs[1]->addend = 0;
2838 relocs[2]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2839 *relocs[2]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2840 relocs[2]->howto = bfd_reloc_type_lookup (stdoutput, *codes[2]);
2841 relocs[2]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2842 relocs[2]->addend = 0;
2843 relocs[3]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2844 *relocs[3]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2845 relocs[3]->howto = bfd_reloc_type_lookup (stdoutput, *codes[3]);
2846 relocs[3]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2847 relocs[3]->addend = 0;
2848 relocs[4]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2849 *relocs[4]->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2850 relocs[4]->howto = bfd_reloc_type_lookup (stdoutput, *codes[4]);
2851 relocs[4]->address = fixp->fx_frag->fr_address + fixp->fx_where;
2852 relocs[4]->addend = 0;
2853 goto done;
2854 case R_PCREL_CALL:
2855 case R_ABS_CALL:
2856 relocs[i]->addend = HPPA_R_ADDEND (hppa_fixp->fx_arg_reloc, 0);
2857 break;
2859 case R_DLT_REL:
2860 case R_DATA_PLABEL:
2861 case R_CODE_PLABEL:
2862 /* For plabel relocations, the addend of the
2863 relocation should be either 0 (no static link) or 2
2864 (static link required).
2866 FIXME: We always assume no static link!
2868 We also slam a zero addend into the DLT relative relocs;
2869 it doesn't make a lot of sense to use any addend since
2870 it gets you a different (eg unknown) DLT entry. */
2871 relocs[i]->addend = 0;
2872 break;
2874 case R_N_MODE:
2875 case R_S_MODE:
2876 case R_D_MODE:
2877 case R_R_MODE:
2878 case R_FSEL:
2879 case R_LSEL:
2880 case R_RSEL:
2881 case R_BEGIN_BRTAB:
2882 case R_END_BRTAB:
2883 case R_BEGIN_TRY:
2884 case R_N0SEL:
2885 case R_N1SEL:
2886 /* There is no symbol or addend associated with these fixups. */
2887 relocs[i]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2888 *relocs[i]->sym_ptr_ptr = symbol_get_bfdsym (dummy_symbol);
2889 relocs[i]->addend = 0;
2890 break;
2892 case R_END_TRY:
2893 case R_ENTRY:
2894 case R_EXIT:
2895 /* There is no symbol associated with these fixups. */
2896 relocs[i]->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2897 *relocs[i]->sym_ptr_ptr = symbol_get_bfdsym (dummy_symbol);
2898 relocs[i]->addend = fixp->fx_offset;
2899 break;
2901 default:
2902 relocs[i]->addend = fixp->fx_offset;
2906 done:
2907 #endif
2909 return relocs;
2912 /* Process any machine dependent frag types. */
2914 void
2915 md_convert_frag (abfd, sec, fragP)
2916 register bfd *abfd;
2917 register asection *sec;
2918 register fragS *fragP;
2920 unsigned int address;
2922 if (fragP->fr_type == rs_machine_dependent)
2924 switch ((int) fragP->fr_subtype)
2926 case 0:
2927 fragP->fr_type = rs_fill;
2928 know (fragP->fr_var == 1);
2929 know (fragP->fr_next);
2930 address = fragP->fr_address + fragP->fr_fix;
2931 if (address % fragP->fr_offset)
2933 fragP->fr_offset =
2934 fragP->fr_next->fr_address
2935 - fragP->fr_address
2936 - fragP->fr_fix;
2938 else
2939 fragP->fr_offset = 0;
2940 break;
2945 /* Round up a section size to the appropriate boundary. */
2947 valueT
2948 md_section_align (segment, size)
2949 asection *segment;
2950 valueT size;
2952 int align = bfd_get_section_alignment (stdoutput, segment);
2953 int align2 = (1 << align) - 1;
2955 return (size + align2) & ~align2;
2958 /* Return the approximate size of a frag before relaxation has occurred. */
2960 md_estimate_size_before_relax (fragP, segment)
2961 register fragS *fragP;
2962 asection *segment;
2964 int size;
2966 size = 0;
2968 while ((fragP->fr_fix + size) % fragP->fr_offset)
2969 size++;
2971 return size;
2974 CONST char *md_shortopts = "";
2975 struct option md_longopts[] = {
2976 {NULL, no_argument, NULL, 0}
2978 size_t md_longopts_size = sizeof(md_longopts);
2981 md_parse_option (c, arg)
2982 int c;
2983 char *arg;
2985 return 0;
2988 void
2989 md_show_usage (stream)
2990 FILE *stream;
2994 /* We have no need to default values of symbols. */
2996 symbolS *
2997 md_undefined_symbol (name)
2998 char *name;
3000 return 0;
3003 /* Apply a fixup to an instruction. */
3006 md_apply_fix (fixP, valp)
3007 fixS *fixP;
3008 valueT *valp;
3010 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
3011 struct hppa_fix_struct *hppa_fixP;
3012 long new_val, result = 0;
3013 unsigned int w1, w2, w, resulti;
3015 hppa_fixP = (struct hppa_fix_struct *) fixP->tc_fix_data;
3016 /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
3017 never be "applied" (they are just markers). Likewise for
3018 R_HPPA_BEGIN_BRTAB and R_HPPA_END_BRTAB. */
3019 #ifdef OBJ_SOM
3020 if (fixP->fx_r_type == R_HPPA_ENTRY
3021 || fixP->fx_r_type == R_HPPA_EXIT
3022 || fixP->fx_r_type == R_HPPA_BEGIN_BRTAB
3023 || fixP->fx_r_type == R_HPPA_END_BRTAB
3024 || fixP->fx_r_type == R_HPPA_BEGIN_TRY)
3025 return 1;
3027 /* Disgusting. We must set fx_offset ourselves -- R_HPPA_END_TRY
3028 fixups are considered not adjustable, which in turn causes
3029 adjust_reloc_syms to not set fx_offset. Ugh. */
3030 if (fixP->fx_r_type == R_HPPA_END_TRY)
3032 fixP->fx_offset = *valp;
3033 return 1;
3035 #endif
3037 /* There should have been an HPPA specific fixup associated
3038 with the GAS fixup. */
3039 if (hppa_fixP)
3041 unsigned long buf_wd = bfd_get_32 (stdoutput, buf);
3042 unsigned char fmt = bfd_hppa_insn2fmt (buf_wd);
3044 /* If there is a symbol associated with this fixup, then it's something
3045 which will need a SOM relocation (except for some PC-relative relocs).
3046 In such cases we should treat the "val" or "addend" as zero since it
3047 will be added in as needed from fx_offset in tc_gen_reloc. */
3048 if ((fixP->fx_addsy != NULL
3049 || fixP->fx_r_type == R_HPPA_NONE)
3050 #ifdef OBJ_SOM
3051 && fmt != 32
3052 #endif
3054 new_val = ((fmt == 12 || fmt == 17 || fmt == 22) ? 8 : 0);
3055 #ifdef OBJ_SOM
3056 /* These field selectors imply that we do not want an addend. */
3057 else if (hppa_fixP->fx_r_field == e_psel
3058 || hppa_fixP->fx_r_field == e_rpsel
3059 || hppa_fixP->fx_r_field == e_lpsel
3060 || hppa_fixP->fx_r_field == e_tsel
3061 || hppa_fixP->fx_r_field == e_rtsel
3062 || hppa_fixP->fx_r_field == e_ltsel)
3063 new_val = ((fmt == 12 || fmt == 17 || fmt == 22) ? 8 : 0);
3064 /* This is truely disgusting. The machine independent code blindly
3065 adds in the value of the symbol being relocated against. Damn! */
3066 else if (fmt == 32
3067 && fixP->fx_addsy != NULL
3068 && S_GET_SEGMENT (fixP->fx_addsy) != bfd_com_section_ptr)
3069 new_val = hppa_field_adjust (*valp - S_GET_VALUE (fixP->fx_addsy),
3070 0, hppa_fixP->fx_r_field);
3071 #endif
3072 else
3073 new_val = hppa_field_adjust (*valp, 0, hppa_fixP->fx_r_field);
3075 /* Handle pc-relative exceptions from above. */
3076 #define arg_reloc_stub_needed(CALLER, CALLEE) \
3077 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
3078 if ((fmt == 12 || fmt == 17 || fmt == 22)
3079 && fixP->fx_addsy
3080 && fixP->fx_pcrel
3081 && !arg_reloc_stub_needed ((long) ((obj_symbol_type *)
3082 symbol_get_bfdsym (fixP->fx_addsy))->tc_data.ap.hppa_arg_reloc,
3083 hppa_fixP->fx_arg_reloc)
3084 && (((int)(*valp) > -262144 && (int)(*valp) < 262143) && fmt != 22)
3085 && S_GET_SEGMENT (fixP->fx_addsy) == hppa_fixP->segment
3086 && !(fixP->fx_subsy
3087 && S_GET_SEGMENT (fixP->fx_subsy) != hppa_fixP->segment))
3089 new_val = hppa_field_adjust (*valp, 0, hppa_fixP->fx_r_field);
3090 #undef arg_reloc_stub_needed
3092 switch (fmt)
3094 /* Handle all opcodes with the 'j' operand type. */
3095 case 14:
3096 CHECK_FIELD (new_val, 8191, -8192, 0);
3098 /* Mask off 14 bits to be changed. */
3099 bfd_put_32 (stdoutput,
3100 bfd_get_32 (stdoutput, buf) & 0xffffc000,
3101 buf);
3102 low_sign_unext (new_val, 14, &resulti);
3103 result = resulti;
3104 break;
3106 /* Handle all opcodes with the 'k' operand type. */
3107 case 21:
3108 CHECK_FIELD (new_val, 2097152, 0, 0);
3110 /* Mask off 21 bits to be changed. */
3111 bfd_put_32 (stdoutput,
3112 bfd_get_32 (stdoutput, buf) & 0xffe00000,
3113 buf);
3114 dis_assemble_21 (new_val, &resulti);
3115 result = resulti;
3116 break;
3118 /* Handle all the opcodes with the 'i' operand type. */
3119 case 11:
3120 CHECK_FIELD (new_val, 1023, -1023, 0);
3122 /* Mask off 11 bits to be changed. */
3123 bfd_put_32 (stdoutput,
3124 bfd_get_32 (stdoutput, buf) & 0xffff800,
3125 buf);
3126 low_sign_unext (new_val, 11, &resulti);
3127 result = resulti;
3128 break;
3130 /* Handle all the opcodes with the 'w' operand type. */
3131 case 12:
3132 CHECK_FIELD (new_val, 8199, -8184, 0);
3134 /* Mask off 11 bits to be changed. */
3135 sign_unext ((new_val - 8) >> 2, 12, &resulti);
3136 bfd_put_32 (stdoutput,
3137 bfd_get_32 (stdoutput, buf) & 0xffffe002,
3138 buf);
3140 dis_assemble_12 (resulti, &w1, &w);
3141 result = ((w1 << 2) | w);
3142 break;
3144 /* Handle some of the opcodes with the 'W' operand type. */
3145 case 17:
3147 int distance = *valp;
3149 CHECK_FIELD (new_val, 262143, -262144, 0);
3151 /* If this is an absolute branch (ie no link) with an out of
3152 range target, then we want to complain. */
3153 if (fixP->fx_r_type == R_HPPA_PCREL_CALL
3154 && (distance > 262143 || distance < -262144)
3155 && (bfd_get_32 (stdoutput, buf) & 0xffe00000) == 0xe8000000)
3156 CHECK_FIELD (distance, 262143, -262144, 0);
3158 /* Mask off 17 bits to be changed. */
3159 bfd_put_32 (stdoutput,
3160 bfd_get_32 (stdoutput, buf) & 0xffe0e002,
3161 buf);
3162 sign_unext ((new_val - 8) >> 2, 17, &resulti);
3163 dis_assemble_17 (resulti, &w1, &w2, &w);
3164 result = ((w2 << 2) | (w1 << 16) | w);
3165 break;
3168 case 32:
3169 result = 0;
3170 bfd_put_32 (stdoutput, new_val, buf);
3171 break;
3173 default:
3174 as_bad (_("Unknown relocation encountered in md_apply_fix."));
3175 return 0;
3178 /* Insert the relocation. */
3179 bfd_put_32 (stdoutput, bfd_get_32 (stdoutput, buf) | result, buf);
3180 return 1;
3182 else
3184 printf (_("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n"),
3185 (unsigned int) fixP, fixP->fx_r_type);
3186 return 0;
3190 /* Exactly what point is a PC-relative offset relative TO?
3191 On the PA, they're relative to the address of the offset. */
3193 long
3194 md_pcrel_from (fixP)
3195 fixS *fixP;
3197 return fixP->fx_where + fixP->fx_frag->fr_address;
3200 /* Return nonzero if the input line pointer is at the end of
3201 a statement. */
3203 static int
3204 is_end_of_statement ()
3206 return ((*input_line_pointer == '\n')
3207 || (*input_line_pointer == ';')
3208 || (*input_line_pointer == '!'));
3211 /* Read a number from S. The number might come in one of many forms,
3212 the most common will be a hex or decimal constant, but it could be
3213 a pre-defined register (Yuk!), or an absolute symbol.
3215 Return a number or -1 for failure.
3217 When parsing PA-89 FP register numbers RESULT will be
3218 the address of a structure to return information about
3219 L/R half of FP registers, store results there as appropriate.
3221 pa_parse_number can not handle negative constants and will fail
3222 horribly if it is passed such a constant. */
3224 static int
3225 pa_parse_number (s, result)
3226 char **s;
3227 struct pa_11_fp_reg_struct *result;
3229 int num;
3230 char *name;
3231 char c;
3232 symbolS *sym;
3233 int status;
3234 char *p = *s;
3236 /* Skip whitespace before the number. */
3237 while (*p == ' ' || *p == '\t')
3238 p = p + 1;
3240 /* Store info in RESULT if requested by caller. */
3241 if (result)
3243 result->number_part = -1;
3244 result->l_r_select = -1;
3246 num = -1;
3248 if (isdigit (*p))
3250 /* Looks like a number. */
3251 num = 0;
3253 if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X'))
3255 /* The number is specified in hex. */
3256 p += 2;
3257 while (isdigit (*p) || ((*p >= 'a') && (*p <= 'f'))
3258 || ((*p >= 'A') && (*p <= 'F')))
3260 if (isdigit (*p))
3261 num = num * 16 + *p - '0';
3262 else if (*p >= 'a' && *p <= 'f')
3263 num = num * 16 + *p - 'a' + 10;
3264 else
3265 num = num * 16 + *p - 'A' + 10;
3266 ++p;
3269 else
3271 /* The number is specified in decimal. */
3272 while (isdigit (*p))
3274 num = num * 10 + *p - '0';
3275 ++p;
3279 /* Store info in RESULT if requested by the caller. */
3280 if (result)
3282 result->number_part = num;
3284 if (IS_R_SELECT (p))
3286 result->l_r_select = 1;
3287 ++p;
3289 else if (IS_L_SELECT (p))
3291 result->l_r_select = 0;
3292 ++p;
3294 else
3295 result->l_r_select = 0;
3298 else if (*p == '%')
3300 /* The number might be a predefined register. */
3301 num = 0;
3302 name = p;
3303 p++;
3304 c = *p;
3305 /* Tege hack: Special case for general registers as the general
3306 code makes a binary search with case translation, and is VERY
3307 slow. */
3308 if (c == 'r')
3310 p++;
3311 if (*p == 'e' && *(p + 1) == 't'
3312 && (*(p + 2) == '0' || *(p + 2) == '1'))
3314 p += 2;
3315 num = *p - '0' + 28;
3316 p++;
3318 else if (*p == 'p')
3320 num = 2;
3321 p++;
3323 else if (!isdigit (*p))
3325 if (print_errors)
3326 as_bad (_("Undefined register: '%s'."), name);
3327 num = -1;
3329 else
3332 num = num * 10 + *p++ - '0';
3333 while (isdigit (*p));
3336 else
3338 /* Do a normal register search. */
3339 while (is_part_of_name (c))
3341 p = p + 1;
3342 c = *p;
3344 *p = 0;
3345 status = reg_name_search (name);
3346 if (status >= 0)
3347 num = status;
3348 else
3350 if (print_errors)
3351 as_bad (_("Undefined register: '%s'."), name);
3352 num = -1;
3354 *p = c;
3357 /* Store info in RESULT if requested by caller. */
3358 if (result)
3360 result->number_part = num;
3361 if (IS_R_SELECT (p - 1))
3362 result->l_r_select = 1;
3363 else if (IS_L_SELECT (p - 1))
3364 result->l_r_select = 0;
3365 else
3366 result->l_r_select = 0;
3369 else
3371 /* And finally, it could be a symbol in the absolute section which
3372 is effectively a constant. */
3373 num = 0;
3374 name = p;
3375 c = *p;
3376 while (is_part_of_name (c))
3378 p = p + 1;
3379 c = *p;
3381 *p = 0;
3382 if ((sym = symbol_find (name)) != NULL)
3384 if (S_GET_SEGMENT (sym) == &bfd_abs_section)
3385 num = S_GET_VALUE (sym);
3386 else
3388 if (print_errors)
3389 as_bad (_("Non-absolute symbol: '%s'."), name);
3390 num = -1;
3393 else
3395 /* There is where we'd come for an undefined symbol
3396 or for an empty string. For an empty string we
3397 will return zero. That's a concession made for
3398 compatability with the braindamaged HP assemblers. */
3399 if (*name == 0)
3400 num = 0;
3401 else
3403 if (print_errors)
3404 as_bad (_("Undefined absolute constant: '%s'."), name);
3405 num = -1;
3408 *p = c;
3410 /* Store info in RESULT if requested by caller. */
3411 if (result)
3413 result->number_part = num;
3414 if (IS_R_SELECT (p - 1))
3415 result->l_r_select = 1;
3416 else if (IS_L_SELECT (p - 1))
3417 result->l_r_select = 0;
3418 else
3419 result->l_r_select = 0;
3423 *s = p;
3424 return num;
3427 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
3429 /* Given NAME, find the register number associated with that name, return
3430 the integer value associated with the given name or -1 on failure. */
3432 static int
3433 reg_name_search (name)
3434 char *name;
3436 int middle, low, high;
3437 int cmp;
3439 low = 0;
3440 high = REG_NAME_CNT - 1;
3444 middle = (low + high) / 2;
3445 cmp = strcasecmp (name, pre_defined_registers[middle].name);
3446 if (cmp < 0)
3447 high = middle - 1;
3448 else if (cmp > 0)
3449 low = middle + 1;
3450 else
3451 return pre_defined_registers[middle].value;
3453 while (low <= high);
3455 return -1;
3459 /* Return nonzero if the given INSN and L/R information will require
3460 a new PA-1.1 opcode. */
3462 static int
3463 need_pa11_opcode (insn, result)
3464 struct pa_it *insn;
3465 struct pa_11_fp_reg_struct *result;
3467 if (result->l_r_select == 1 && !(insn->fpof1 == DBL && insn->fpof2 == DBL))
3469 /* If this instruction is specific to a particular architecture,
3470 then set a new architecture. */
3471 if (bfd_get_mach (stdoutput) < pa11)
3473 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, pa11))
3474 as_warn (_("could not update architecture and machine"));
3476 return TRUE;
3478 else
3479 return FALSE;
3482 /* Parse a condition for a fcmp instruction. Return the numerical
3483 code associated with the condition. */
3485 static int
3486 pa_parse_fp_cmp_cond (s)
3487 char **s;
3489 int cond, i;
3491 cond = 0;
3493 for (i = 0; i < 32; i++)
3495 if (strncasecmp (*s, fp_cond_map[i].string,
3496 strlen (fp_cond_map[i].string)) == 0)
3498 cond = fp_cond_map[i].cond;
3499 *s += strlen (fp_cond_map[i].string);
3500 /* If not a complete match, back up the input string and
3501 report an error. */
3502 if (**s != ' ' && **s != '\t')
3504 *s -= strlen (fp_cond_map[i].string);
3505 break;
3507 while (**s == ' ' || **s == '\t')
3508 *s = *s + 1;
3509 return cond;
3513 as_bad (_("Invalid FP Compare Condition: %s"), *s);
3515 /* Advance over the bogus completer. */
3516 while (**s != ',' && **s != ' ' && **s != '\t')
3517 *s += 1;
3519 return 0;
3523 /* Parse an FP operand format completer returning the completer
3524 type. */
3526 static fp_operand_format
3527 pa_parse_fp_format (s)
3528 char **s;
3530 int format;
3532 format = SGL;
3533 if (**s == ',')
3535 *s += 1;
3536 if (strncasecmp (*s, "sgl", 3) == 0)
3538 format = SGL;
3539 *s += 4;
3541 else if (strncasecmp (*s, "dbl", 3) == 0)
3543 format = DBL;
3544 *s += 4;
3546 else if (strncasecmp (*s, "quad", 4) == 0)
3548 format = QUAD;
3549 *s += 5;
3551 else
3553 format = ILLEGAL_FMT;
3554 as_bad (_("Invalid FP Operand Format: %3s"), *s);
3558 return format;
3561 /* Convert from a selector string into a selector type. */
3563 static int
3564 pa_chk_field_selector (str)
3565 char **str;
3567 int middle, low, high;
3568 int cmp;
3569 char name[4];
3571 /* Read past any whitespace. */
3572 /* FIXME: should we read past newlines and formfeeds??? */
3573 while (**str == ' ' || **str == '\t' || **str == '\n' || **str == '\f')
3574 *str = *str + 1;
3576 if ((*str)[1] == '\'' || (*str)[1] == '%')
3577 name[0] = tolower ((*str)[0]),
3578 name[1] = 0;
3579 else if ((*str)[2] == '\'' || (*str)[2] == '%')
3580 name[0] = tolower ((*str)[0]),
3581 name[1] = tolower ((*str)[1]),
3582 name[2] = 0;
3583 #ifdef OBJ_SOM
3584 else if ((*str)[3] == '\'' || (*str)[3] == '%')
3585 name[0] = tolower ((*str)[0]),
3586 name[1] = tolower ((*str)[1]),
3587 name[2] = tolower ((*str)[2]),
3588 name[3] = 0;
3589 #endif
3590 else
3591 return e_fsel;
3593 low = 0;
3594 high = sizeof (selector_table) / sizeof (struct selector_entry) - 1;
3598 middle = (low + high) / 2;
3599 cmp = strcmp (name, selector_table[middle].prefix);
3600 if (cmp < 0)
3601 high = middle - 1;
3602 else if (cmp > 0)
3603 low = middle + 1;
3604 else
3606 *str += strlen (name) + 1;
3607 #ifndef OBJ_SOM
3608 if (selector_table[middle].field_selector == e_nsel)
3609 return e_fsel;
3610 #endif
3611 return selector_table[middle].field_selector;
3614 while (low <= high);
3616 return e_fsel;
3619 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
3621 static int
3622 get_expression (str)
3623 char *str;
3625 char *save_in;
3626 asection *seg;
3628 save_in = input_line_pointer;
3629 input_line_pointer = str;
3630 seg = expression (&the_insn.exp);
3631 if (!(seg == absolute_section
3632 || seg == undefined_section
3633 || SEG_NORMAL (seg)))
3635 as_warn (_("Bad segment in expression."));
3636 expr_end = input_line_pointer;
3637 input_line_pointer = save_in;
3638 return 1;
3640 expr_end = input_line_pointer;
3641 input_line_pointer = save_in;
3642 return 0;
3645 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
3646 static int
3647 pa_get_absolute_expression (insn, strp)
3648 struct pa_it *insn;
3649 char **strp;
3651 char *save_in;
3653 insn->field_selector = pa_chk_field_selector (strp);
3654 save_in = input_line_pointer;
3655 input_line_pointer = *strp;
3656 expression (&insn->exp);
3657 /* This is not perfect, but is a huge improvement over doing nothing.
3659 The PA assembly syntax is ambigious in a variety of ways. Consider
3660 this string "4 %r5" Is that the number 4 followed by the register
3661 r5, or is that 4 MOD 5?
3663 If we get a modulo expresion When looking for an absolute, we try
3664 again cutting off the input string at the first whitespace character. */
3665 if (insn->exp.X_op == O_modulus)
3667 char *s, c;
3668 int retval;
3670 input_line_pointer = *strp;
3671 s = *strp;
3672 while (*s != ',' && *s != ' ' && *s != '\t')
3673 s++;
3675 c = *s;
3676 *s = 0;
3678 retval = pa_get_absolute_expression (insn, strp);
3680 input_line_pointer = save_in;
3681 *s = c;
3682 return evaluate_absolute (insn);
3684 if (insn->exp.X_op != O_constant)
3686 as_bad (_("Bad segment (should be absolute)."));
3687 expr_end = input_line_pointer;
3688 input_line_pointer = save_in;
3689 return 0;
3691 expr_end = input_line_pointer;
3692 input_line_pointer = save_in;
3693 return evaluate_absolute (insn);
3696 /* Evaluate an absolute expression EXP which may be modified by
3697 the selector FIELD_SELECTOR. Return the value of the expression. */
3698 static int
3699 evaluate_absolute (insn)
3700 struct pa_it *insn;
3702 int value;
3703 expressionS exp;
3704 int field_selector = insn->field_selector;
3706 exp = insn->exp;
3707 value = exp.X_add_number;
3709 switch (field_selector)
3711 /* No change. */
3712 case e_fsel:
3713 break;
3715 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
3716 case e_lssel:
3717 if (value & 0x00000400)
3718 value += 0x800;
3719 value = (value & 0xfffff800) >> 11;
3720 break;
3722 /* Sign extend from bit 21. */
3723 case e_rssel:
3724 if (value & 0x00000400)
3725 value |= 0xfffff800;
3726 else
3727 value &= 0x7ff;
3728 break;
3730 /* Arithmetic shift right 11 bits. */
3731 case e_lsel:
3732 value = (value & 0xfffff800) >> 11;
3733 break;
3735 /* Set bits 0-20 to zero. */
3736 case e_rsel:
3737 value = value & 0x7ff;
3738 break;
3740 /* Add 0x800 and arithmetic shift right 11 bits. */
3741 case e_ldsel:
3742 value += 0x800;
3743 value = (value & 0xfffff800) >> 11;
3744 break;
3746 /* Set bitgs 0-21 to one. */
3747 case e_rdsel:
3748 value |= 0xfffff800;
3749 break;
3751 #define RSEL_ROUND(c) (((c) + 0x1000) & ~0x1fff)
3752 case e_rrsel:
3753 value = (RSEL_ROUND (value) & 0x7ff) + (value - RSEL_ROUND (value));
3754 break;
3756 case e_lrsel:
3757 value = (RSEL_ROUND (value) >> 11) & 0x1fffff;
3758 break;
3759 #undef RSEL_ROUND
3761 default:
3762 BAD_CASE (field_selector);
3763 break;
3765 return value;
3768 /* Given an argument location specification return the associated
3769 argument location number. */
3771 static unsigned int
3772 pa_build_arg_reloc (type_name)
3773 char *type_name;
3776 if (strncasecmp (type_name, "no", 2) == 0)
3777 return 0;
3778 if (strncasecmp (type_name, "gr", 2) == 0)
3779 return 1;
3780 else if (strncasecmp (type_name, "fr", 2) == 0)
3781 return 2;
3782 else if (strncasecmp (type_name, "fu", 2) == 0)
3783 return 3;
3784 else
3785 as_bad (_("Invalid argument location: %s\n"), type_name);
3787 return 0;
3790 /* Encode and return an argument relocation specification for
3791 the given register in the location specified by arg_reloc. */
3793 static unsigned int
3794 pa_align_arg_reloc (reg, arg_reloc)
3795 unsigned int reg;
3796 unsigned int arg_reloc;
3798 unsigned int new_reloc;
3800 new_reloc = arg_reloc;
3801 switch (reg)
3803 case 0:
3804 new_reloc <<= 8;
3805 break;
3806 case 1:
3807 new_reloc <<= 6;
3808 break;
3809 case 2:
3810 new_reloc <<= 4;
3811 break;
3812 case 3:
3813 new_reloc <<= 2;
3814 break;
3815 default:
3816 as_bad (_("Invalid argument description: %d"), reg);
3819 return new_reloc;
3822 /* Parse a PA nullification completer (,n). Return nonzero if the
3823 completer was found; return zero if no completer was found. */
3825 static int
3826 pa_parse_nullif (s)
3827 char **s;
3829 int nullif;
3831 nullif = 0;
3832 if (**s == ',')
3834 *s = *s + 1;
3835 if (strncasecmp (*s, "n", 1) == 0)
3836 nullif = 1;
3837 else
3839 as_bad (_("Invalid Nullification: (%c)"), **s);
3840 nullif = 0;
3842 *s = *s + 1;
3845 return nullif;
3848 /* Parse a non-negated compare/subtract completer returning the
3849 number (for encoding in instrutions) of the given completer.
3851 ISBRANCH specifies whether or not this is parsing a condition
3852 completer for a branch (vs a nullification completer for a
3853 computational instruction. */
3855 static int
3856 pa_parse_nonneg_cmpsub_cmpltr (s, isbranch)
3857 char **s;
3858 int isbranch;
3860 int cmpltr;
3861 char *name = *s + 1;
3862 char c;
3863 char *save_s = *s;
3864 int nullify = 0;
3866 cmpltr = 0;
3867 if (**s == ',')
3869 *s += 1;
3870 while (**s != ',' && **s != ' ' && **s != '\t')
3871 *s += 1;
3872 c = **s;
3873 **s = 0x00;
3876 if (strcmp (name, "=") == 0)
3878 cmpltr = 1;
3880 else if (strcmp (name, "<") == 0)
3882 cmpltr = 2;
3884 else if (strcmp (name, "<=") == 0)
3886 cmpltr = 3;
3888 else if (strcmp (name, "<<") == 0)
3890 cmpltr = 4;
3892 else if (strcmp (name, "<<=") == 0)
3894 cmpltr = 5;
3896 else if (strcasecmp (name, "sv") == 0)
3898 cmpltr = 6;
3900 else if (strcasecmp (name, "od") == 0)
3902 cmpltr = 7;
3904 /* If we have something like addb,n then there is no condition
3905 completer. */
3906 else if (strcasecmp (name, "n") == 0 && isbranch)
3908 cmpltr = 0;
3909 nullify = 1;
3911 else
3913 cmpltr = -1;
3915 **s = c;
3918 /* Reset pointers if this was really a ,n for a branch instruction. */
3919 if (nullify)
3920 *s = save_s;
3923 return cmpltr;
3926 /* Parse a negated compare/subtract completer returning the
3927 number (for encoding in instrutions) of the given completer.
3929 ISBRANCH specifies whether or not this is parsing a condition
3930 completer for a branch (vs a nullification completer for a
3931 computational instruction. */
3933 static int
3934 pa_parse_neg_cmpsub_cmpltr (s, isbranch)
3935 char **s;
3936 int isbranch;
3938 int cmpltr;
3939 char *name = *s + 1;
3940 char c;
3941 char *save_s = *s;
3942 int nullify = 0;
3944 cmpltr = 0;
3945 if (**s == ',')
3947 *s += 1;
3948 while (**s != ',' && **s != ' ' && **s != '\t')
3949 *s += 1;
3950 c = **s;
3951 **s = 0x00;
3954 if (strcasecmp (name, "tr") == 0)
3956 cmpltr = 0;
3958 else if (strcmp (name, "<>") == 0)
3960 cmpltr = 1;
3962 else if (strcmp (name, ">=") == 0)
3964 cmpltr = 2;
3966 else if (strcmp (name, ">") == 0)
3968 cmpltr = 3;
3970 else if (strcmp (name, ">>=") == 0)
3972 cmpltr = 4;
3974 else if (strcmp (name, ">>") == 0)
3976 cmpltr = 5;
3978 else if (strcasecmp (name, "nsv") == 0)
3980 cmpltr = 6;
3982 else if (strcasecmp (name, "ev") == 0)
3984 cmpltr = 7;
3986 /* If we have something like addb,n then there is no condition
3987 completer. */
3988 else if (strcasecmp (name, "n") == 0 && isbranch)
3990 cmpltr = 0;
3991 nullify = 1;
3993 else
3995 cmpltr = -1;
3997 **s = c;
4000 /* Reset pointers if this was really a ,n for a branch instruction. */
4001 if (nullify)
4002 *s = save_s;
4005 return cmpltr;
4009 /* Parse a non-negated addition completer returning the number
4010 (for encoding in instrutions) of the given completer.
4012 ISBRANCH specifies whether or not this is parsing a condition
4013 completer for a branch (vs a nullification completer for a
4014 computational instruction. */
4016 static int
4017 pa_parse_nonneg_add_cmpltr (s, isbranch)
4018 char **s;
4019 int isbranch;
4021 int cmpltr;
4022 char *name = *s + 1;
4023 char c;
4024 char *save_s = *s;
4026 cmpltr = 0;
4027 if (**s == ',')
4029 *s += 1;
4030 while (**s != ',' && **s != ' ' && **s != '\t')
4031 *s += 1;
4032 c = **s;
4033 **s = 0x00;
4034 if (strcmp (name, "=") == 0)
4036 cmpltr = 1;
4038 else if (strcmp (name, "<") == 0)
4040 cmpltr = 2;
4042 else if (strcmp (name, "<=") == 0)
4044 cmpltr = 3;
4046 else if (strcasecmp (name, "nuv") == 0)
4048 cmpltr = 4;
4050 else if (strcasecmp (name, "znv") == 0)
4052 cmpltr = 5;
4054 else if (strcasecmp (name, "sv") == 0)
4056 cmpltr = 6;
4058 else if (strcasecmp (name, "od") == 0)
4060 cmpltr = 7;
4062 /* If we have something like addb,n then there is no condition
4063 completer. */
4064 else if (strcasecmp (name, "n") == 0 && isbranch)
4066 cmpltr = 0;
4068 else
4070 cmpltr = -1;
4072 **s = c;
4075 /* Reset pointers if this was really a ,n for a branch instruction. */
4076 if (cmpltr == 0 && *name == 'n' && isbranch)
4077 *s = save_s;
4079 return cmpltr;
4082 /* Parse a negated addition completer returning the number
4083 (for encoding in instrutions) of the given completer.
4085 ISBRANCH specifies whether or not this is parsing a condition
4086 completer for a branch (vs a nullification completer for a
4087 computational instruction). */
4089 static int
4090 pa_parse_neg_add_cmpltr (s, isbranch)
4091 char **s;
4092 int isbranch;
4094 int cmpltr;
4095 char *name = *s + 1;
4096 char c;
4097 char *save_s = *s;
4099 cmpltr = 0;
4100 if (**s == ',')
4102 *s += 1;
4103 while (**s != ',' && **s != ' ' && **s != '\t')
4104 *s += 1;
4105 c = **s;
4106 **s = 0x00;
4107 if (strcasecmp (name, "tr") == 0)
4109 cmpltr = 0;
4111 else if (strcmp (name, "<>") == 0)
4113 cmpltr = 1;
4115 else if (strcmp (name, ">=") == 0)
4117 cmpltr = 2;
4119 else if (strcmp (name, ">") == 0)
4121 cmpltr = 3;
4123 else if (strcasecmp (name, "uv") == 0)
4125 cmpltr = 4;
4127 else if (strcasecmp (name, "vnz") == 0)
4129 cmpltr = 5;
4131 else if (strcasecmp (name, "nsv") == 0)
4133 cmpltr = 6;
4135 else if (strcasecmp (name, "ev") == 0)
4137 cmpltr = 7;
4139 /* If we have something like addb,n then there is no condition
4140 completer. */
4141 else if (strcasecmp (name, "n") == 0 && isbranch)
4143 cmpltr = 0;
4145 else
4147 cmpltr = -1;
4149 **s = c;
4152 /* Reset pointers if this was really a ,n for a branch instruction. */
4153 if (cmpltr == 0 && *name == 'n' && isbranch)
4154 *s = save_s;
4156 return cmpltr;
4159 /* Handle an alignment directive. Special so that we can update the
4160 alignment of the subspace if necessary. */
4161 static void
4162 pa_align (bytes)
4164 /* We must have a valid space and subspace. */
4165 pa_check_current_space_and_subspace ();
4167 /* Let the generic gas code do most of the work. */
4168 s_align_bytes (bytes);
4170 /* If bytes is a power of 2, then update the current subspace's
4171 alignment if necessary. */
4172 if (log2 (bytes) != -1)
4173 record_alignment (current_subspace->ssd_seg, log2 (bytes));
4176 /* Handle a .BLOCK type pseudo-op. */
4178 static void
4179 pa_block (z)
4180 int z;
4182 char *p;
4183 long int temp_fill;
4184 unsigned int temp_size;
4185 unsigned int i;
4187 /* We must have a valid space and subspace. */
4188 pa_check_current_space_and_subspace ();
4190 temp_size = get_absolute_expression ();
4192 /* Always fill with zeros, that's what the HP assembler does. */
4193 temp_fill = 0;
4195 p = frag_var (rs_fill, (int) temp_size, (int) temp_size,
4196 (relax_substateT) 0, (symbolS *) 0, (offsetT) 1, NULL);
4197 memset (p, 0, temp_size);
4199 /* Convert 2 bytes at a time. */
4201 for (i = 0; i < temp_size; i += 2)
4203 md_number_to_chars (p + i,
4204 (valueT) temp_fill,
4205 (int) ((temp_size - i) > 2 ? 2 : (temp_size - i)));
4208 pa_undefine_label ();
4209 demand_empty_rest_of_line ();
4212 /* Handle a .begin_brtab and .end_brtab pseudo-op. */
4214 static void
4215 pa_brtab (begin)
4216 int begin;
4219 #ifdef OBJ_SOM
4220 /* The BRTAB relocations are only availble in SOM (to denote
4221 the beginning and end of branch tables). */
4222 char *where = frag_more (0);
4224 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
4225 NULL, (offsetT) 0, NULL,
4226 0, begin ? R_HPPA_BEGIN_BRTAB : R_HPPA_END_BRTAB,
4227 e_fsel, 0, 0, NULL);
4228 #endif
4230 demand_empty_rest_of_line ();
4233 /* Handle a .begin_try and .end_try pseudo-op. */
4235 static void
4236 pa_try (begin)
4237 int begin;
4239 #ifdef OBJ_SOM
4240 expressionS exp;
4241 char *where = frag_more (0);
4243 if (! begin)
4244 expression (&exp);
4246 /* The TRY relocations are only availble in SOM (to denote
4247 the beginning and end of exception handling regions). */
4249 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
4250 NULL, (offsetT) 0, begin ? NULL : &exp,
4251 0, begin ? R_HPPA_BEGIN_TRY : R_HPPA_END_TRY,
4252 e_fsel, 0, 0, NULL);
4253 #endif
4255 demand_empty_rest_of_line ();
4258 /* Handle a .CALL pseudo-op. This involves storing away information
4259 about where arguments are to be found so the linker can detect
4260 (and correct) argument location mismatches between caller and callee. */
4262 static void
4263 pa_call (unused)
4264 int unused;
4266 /* We must have a valid space and subspace. */
4267 pa_check_current_space_and_subspace ();
4269 pa_call_args (&last_call_desc);
4270 demand_empty_rest_of_line ();
4273 /* Do the dirty work of building a call descriptor which describes
4274 where the caller placed arguments to a function call. */
4276 static void
4277 pa_call_args (call_desc)
4278 struct call_desc *call_desc;
4280 char *name, c, *p;
4281 unsigned int temp, arg_reloc;
4283 while (!is_end_of_statement ())
4285 name = input_line_pointer;
4286 c = get_symbol_end ();
4287 /* Process a source argument. */
4288 if ((strncasecmp (name, "argw", 4) == 0))
4290 temp = atoi (name + 4);
4291 p = input_line_pointer;
4292 *p = c;
4293 input_line_pointer++;
4294 name = input_line_pointer;
4295 c = get_symbol_end ();
4296 arg_reloc = pa_build_arg_reloc (name);
4297 call_desc->arg_reloc |= pa_align_arg_reloc (temp, arg_reloc);
4299 /* Process a return value. */
4300 else if ((strncasecmp (name, "rtnval", 6) == 0))
4302 p = input_line_pointer;
4303 *p = c;
4304 input_line_pointer++;
4305 name = input_line_pointer;
4306 c = get_symbol_end ();
4307 arg_reloc = pa_build_arg_reloc (name);
4308 call_desc->arg_reloc |= (arg_reloc & 0x3);
4310 else
4312 as_bad (_("Invalid .CALL argument: %s"), name);
4314 p = input_line_pointer;
4315 *p = c;
4316 if (!is_end_of_statement ())
4317 input_line_pointer++;
4321 /* Return TRUE if FRAG1 and FRAG2 are the same. */
4323 static int
4324 is_same_frag (frag1, frag2)
4325 fragS *frag1;
4326 fragS *frag2;
4329 if (frag1 == NULL)
4330 return (FALSE);
4331 else if (frag2 == NULL)
4332 return (FALSE);
4333 else if (frag1 == frag2)
4334 return (TRUE);
4335 else if (frag2->fr_type == rs_fill && frag2->fr_fix == 0)
4336 return (is_same_frag (frag1, frag2->fr_next));
4337 else
4338 return (FALSE);
4341 #ifdef OBJ_ELF
4342 /* Build an entry in the UNWIND subspace from the given function
4343 attributes in CALL_INFO. This is not needed for SOM as using
4344 R_ENTRY and R_EXIT relocations allow the linker to handle building
4345 of the unwind spaces. */
4347 static void
4348 pa_build_unwind_subspace (call_info)
4349 struct call_info *call_info;
4351 char *unwind;
4352 asection *seg, *save_seg;
4353 subsegT subseg, save_subseg;
4354 int i;
4355 char c, *p;
4357 /* Get into the right seg/subseg. This may involve creating
4358 the seg the first time through. Make sure to have the
4359 old seg/subseg so that we can reset things when we are done. */
4360 subseg = SUBSEG_UNWIND;
4361 seg = bfd_get_section_by_name (stdoutput, UNWIND_SECTION_NAME);
4362 if (seg == ASEC_NULL)
4364 seg = bfd_make_section_old_way (stdoutput, UNWIND_SECTION_NAME);
4365 bfd_set_section_flags (stdoutput, seg,
4366 SEC_READONLY | SEC_HAS_CONTENTS
4367 | SEC_LOAD | SEC_RELOC);
4370 save_seg = now_seg;
4371 save_subseg = now_subseg;
4372 subseg_set (seg, subseg);
4375 /* Get some space to hold relocation information for the unwind
4376 descriptor. */
4377 p = frag_more (4);
4378 md_number_to_chars (p, 0, 4);
4380 /* Relocation info. for start offset of the function. */
4381 fix_new_hppa (frag_now, p - frag_now->fr_literal, 4,
4382 call_info->start_symbol, (offsetT) 0,
4383 (expressionS *) NULL, 0, R_PARISC_DIR32, e_fsel, 32, 0, NULL);
4385 p = frag_more (4);
4386 md_number_to_chars (p, 0, 4);
4388 /* Relocation info. for end offset of the function.
4390 Because we allow reductions of 32bit relocations for ELF, this will be
4391 reduced to section_sym + offset which avoids putting the temporary
4392 symbol into the symbol table. It (should) end up giving the same
4393 value as call_info->start_symbol + function size once the linker is
4394 finished with its work. */
4396 fix_new_hppa (frag_now, p - frag_now->fr_literal, 4,
4397 call_info->end_symbol, (offsetT) 0,
4398 (expressionS *) NULL, 0, R_PARISC_DIR32, e_fsel, 32, 0, NULL);
4400 /* Dump it. */
4401 unwind = (char *) &call_info->ci_unwind;
4402 for (i = 8; i < sizeof (struct unwind_table); i++)
4404 c = *(unwind + i);
4406 FRAG_APPEND_1_CHAR (c);
4410 /* Return back to the original segment/subsegment. */
4411 subseg_set (save_seg, save_subseg);
4413 #endif
4415 /* Process a .CALLINFO pseudo-op. This information is used later
4416 to build unwind descriptors and maybe one day to support
4417 .ENTER and .LEAVE. */
4419 static void
4420 pa_callinfo (unused)
4421 int unused;
4423 char *name, c, *p;
4424 int temp;
4426 /* We must have a valid space and subspace. */
4427 pa_check_current_space_and_subspace ();
4429 /* .CALLINFO must appear within a procedure definition. */
4430 if (!within_procedure)
4431 as_bad (_(".callinfo is not within a procedure definition"));
4433 /* Mark the fact that we found the .CALLINFO for the
4434 current procedure. */
4435 callinfo_found = TRUE;
4437 /* Iterate over the .CALLINFO arguments. */
4438 while (!is_end_of_statement ())
4440 name = input_line_pointer;
4441 c = get_symbol_end ();
4442 /* Frame size specification. */
4443 if ((strncasecmp (name, "frame", 5) == 0))
4445 p = input_line_pointer;
4446 *p = c;
4447 input_line_pointer++;
4448 temp = get_absolute_expression ();
4449 if ((temp & 0x3) != 0)
4451 as_bad (_("FRAME parameter must be a multiple of 8: %d\n"), temp);
4452 temp = 0;
4455 /* callinfo is in bytes and unwind_desc is in 8 byte units. */
4456 last_call_info->ci_unwind.descriptor.frame_size = temp / 8;
4459 /* Entry register (GR, GR and SR) specifications. */
4460 else if ((strncasecmp (name, "entry_gr", 8) == 0))
4462 p = input_line_pointer;
4463 *p = c;
4464 input_line_pointer++;
4465 temp = get_absolute_expression ();
4466 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
4467 even though %r19 is caller saved. I think this is a bug in
4468 the HP assembler, and we are not going to emulate it. */
4469 if (temp < 3 || temp > 18)
4470 as_bad (_("Value for ENTRY_GR must be in the range 3..18\n"));
4471 last_call_info->ci_unwind.descriptor.entry_gr = temp - 2;
4473 else if ((strncasecmp (name, "entry_fr", 8) == 0))
4475 p = input_line_pointer;
4476 *p = c;
4477 input_line_pointer++;
4478 temp = get_absolute_expression ();
4479 /* Similarly the HP assembler takes 31 as the high bound even
4480 though %fr21 is the last callee saved floating point register. */
4481 if (temp < 12 || temp > 21)
4482 as_bad (_("Value for ENTRY_FR must be in the range 12..21\n"));
4483 last_call_info->ci_unwind.descriptor.entry_fr = temp - 11;
4485 else if ((strncasecmp (name, "entry_sr", 8) == 0))
4487 p = input_line_pointer;
4488 *p = c;
4489 input_line_pointer++;
4490 temp = get_absolute_expression ();
4491 if (temp != 3)
4492 as_bad (_("Value for ENTRY_SR must be 3\n"));
4494 /* Note whether or not this function performs any calls. */
4495 else if ((strncasecmp (name, "calls", 5) == 0) ||
4496 (strncasecmp (name, "caller", 6) == 0))
4498 p = input_line_pointer;
4499 *p = c;
4501 else if ((strncasecmp (name, "no_calls", 8) == 0))
4503 p = input_line_pointer;
4504 *p = c;
4506 /* Should RP be saved into the stack. */
4507 else if ((strncasecmp (name, "save_rp", 7) == 0))
4509 p = input_line_pointer;
4510 *p = c;
4511 last_call_info->ci_unwind.descriptor.save_rp = 1;
4513 /* Likewise for SP. */
4514 else if ((strncasecmp (name, "save_sp", 7) == 0))
4516 p = input_line_pointer;
4517 *p = c;
4518 last_call_info->ci_unwind.descriptor.save_sp = 1;
4520 /* Is this an unwindable procedure. If so mark it so
4521 in the unwind descriptor. */
4522 else if ((strncasecmp (name, "no_unwind", 9) == 0))
4524 p = input_line_pointer;
4525 *p = c;
4526 last_call_info->ci_unwind.descriptor.cannot_unwind = 1;
4528 /* Is this an interrupt routine. If so mark it in the
4529 unwind descriptor. */
4530 else if ((strncasecmp (name, "hpux_int", 7) == 0))
4532 p = input_line_pointer;
4533 *p = c;
4534 last_call_info->ci_unwind.descriptor.hpux_interrupt_marker = 1;
4536 /* Is this a millicode routine. "millicode" isn't in my
4537 assembler manual, but my copy is old. The HP assembler
4538 accepts it, and there's a place in the unwind descriptor
4539 to drop the information, so we'll accept it too. */
4540 else if ((strncasecmp (name, "millicode", 9) == 0))
4542 p = input_line_pointer;
4543 *p = c;
4544 last_call_info->ci_unwind.descriptor.millicode = 1;
4546 else
4548 as_bad (_("Invalid .CALLINFO argument: %s"), name);
4549 *input_line_pointer = c;
4551 if (!is_end_of_statement ())
4552 input_line_pointer++;
4555 demand_empty_rest_of_line ();
4558 /* Switch into the code subspace. */
4560 static void
4561 pa_code (unused)
4562 int unused;
4564 current_space = is_defined_space ("$TEXT$");
4565 current_subspace
4566 = pa_subsegment_to_subspace (current_space->sd_seg, 0);
4567 s_text (0);
4568 pa_undefine_label ();
4571 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
4572 the .comm pseudo-op has the following symtax:
4574 <label> .comm <length>
4576 where <label> is optional and is a symbol whose address will be the start of
4577 a block of memory <length> bytes long. <length> must be an absolute
4578 expression. <length> bytes will be allocated in the current space
4579 and subspace.
4581 Also note the label may not even be on the same line as the .comm.
4583 This difference in syntax means the colon function will be called
4584 on the symbol before we arrive in pa_comm. colon will set a number
4585 of attributes of the symbol that need to be fixed here. In particular
4586 the value, section pointer, fragment pointer, flags, etc. What
4587 a pain.
4589 This also makes error detection all but impossible. */
4591 static void
4592 pa_comm (unused)
4593 int unused;
4595 unsigned int size;
4596 symbolS *symbol;
4597 label_symbol_struct *label_symbol = pa_get_label ();
4599 if (label_symbol)
4600 symbol = label_symbol->lss_label;
4601 else
4602 symbol = NULL;
4604 SKIP_WHITESPACE ();
4605 size = get_absolute_expression ();
4607 if (symbol)
4609 S_SET_VALUE (symbol, size);
4610 S_SET_SEGMENT (symbol, bfd_und_section_ptr);
4611 S_SET_EXTERNAL (symbol);
4613 /* colon() has already set the frag to the current location in the
4614 current subspace; we need to reset the fragment to the zero address
4615 fragment. We also need to reset the segment pointer. */
4616 symbol_set_frag (symbol, &zero_address_frag);
4618 demand_empty_rest_of_line ();
4621 /* Process a .END pseudo-op. */
4623 static void
4624 pa_end (unused)
4625 int unused;
4627 demand_empty_rest_of_line ();
4630 /* Process a .ENTER pseudo-op. This is not supported. */
4631 static void
4632 pa_enter (unused)
4633 int unused;
4635 /* We must have a valid space and subspace. */
4636 pa_check_current_space_and_subspace ();
4638 as_bad (_("The .ENTER pseudo-op is not supported"));
4639 demand_empty_rest_of_line ();
4642 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
4643 procesure. */
4644 static void
4645 pa_entry (unused)
4646 int unused;
4648 /* We must have a valid space and subspace. */
4649 pa_check_current_space_and_subspace ();
4651 if (!within_procedure)
4652 as_bad (_("Misplaced .entry. Ignored."));
4653 else
4655 if (!callinfo_found)
4656 as_bad (_("Missing .callinfo."));
4658 demand_empty_rest_of_line ();
4659 within_entry_exit = TRUE;
4661 #ifdef OBJ_SOM
4662 /* SOM defers building of unwind descriptors until the link phase.
4663 The assembler is responsible for creating an R_ENTRY relocation
4664 to mark the beginning of a region and hold the unwind bits, and
4665 for creating an R_EXIT relocation to mark the end of the region.
4667 FIXME. ELF should be using the same conventions! The problem
4668 is an unwind requires too much relocation space. Hmmm. Maybe
4669 if we split the unwind bits up between the relocations which
4670 denote the entry and exit points. */
4671 if (last_call_info->start_symbol != NULL)
4673 char *where = frag_more (0);
4675 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
4676 NULL, (offsetT) 0, NULL,
4677 0, R_HPPA_ENTRY, e_fsel, 0, 0,
4678 (int *) &last_call_info->ci_unwind.descriptor);
4680 #endif
4683 /* Handle a .EQU pseudo-op. */
4685 static void
4686 pa_equ (reg)
4687 int reg;
4689 label_symbol_struct *label_symbol = pa_get_label ();
4690 symbolS *symbol;
4692 if (label_symbol)
4694 symbol = label_symbol->lss_label;
4695 if (reg)
4696 S_SET_VALUE (symbol, pa_parse_number (&input_line_pointer, 0));
4697 else
4698 S_SET_VALUE (symbol, (unsigned int) get_absolute_expression ());
4699 S_SET_SEGMENT (symbol, bfd_abs_section_ptr);
4701 else
4703 if (reg)
4704 as_bad (_(".REG must use a label"));
4705 else
4706 as_bad (_(".EQU must use a label"));
4709 pa_undefine_label ();
4710 demand_empty_rest_of_line ();
4713 /* Helper function. Does processing for the end of a function. This
4714 usually involves creating some relocations or building special
4715 symbols to mark the end of the function. */
4717 static void
4718 process_exit ()
4720 char *where;
4722 where = frag_more (0);
4724 #ifdef OBJ_ELF
4725 /* Mark the end of the function, stuff away the location of the frag
4726 for the end of the function, and finally call pa_build_unwind_subspace
4727 to add an entry in the unwind table. */
4728 hppa_elf_mark_end_of_function ();
4729 pa_build_unwind_subspace (last_call_info);
4730 #else
4731 /* SOM defers building of unwind descriptors until the link phase.
4732 The assembler is responsible for creating an R_ENTRY relocation
4733 to mark the beginning of a region and hold the unwind bits, and
4734 for creating an R_EXIT relocation to mark the end of the region.
4736 FIXME. ELF should be using the same conventions! The problem
4737 is an unwind requires too much relocation space. Hmmm. Maybe
4738 if we split the unwind bits up between the relocations which
4739 denote the entry and exit points. */
4740 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
4741 NULL, (offsetT) 0,
4742 NULL, 0, R_HPPA_EXIT, e_fsel, 0, 0,
4743 (int *) &last_call_info->ci_unwind.descriptor + 1);
4744 #endif
4747 /* Process a .EXIT pseudo-op. */
4749 static void
4750 pa_exit (unused)
4751 int unused;
4753 /* We must have a valid space and subspace. */
4754 pa_check_current_space_and_subspace ();
4756 if (!within_procedure)
4757 as_bad (_(".EXIT must appear within a procedure"));
4758 else
4760 if (!callinfo_found)
4761 as_bad (_("Missing .callinfo"));
4762 else
4764 if (!within_entry_exit)
4765 as_bad (_("No .ENTRY for this .EXIT"));
4766 else
4768 within_entry_exit = FALSE;
4769 process_exit ();
4773 demand_empty_rest_of_line ();
4776 /* Process a .EXPORT directive. This makes functions external
4777 and provides information such as argument relocation entries
4778 to callers. */
4780 static void
4781 pa_export (unused)
4782 int unused;
4784 char *name, c, *p;
4785 symbolS *symbol;
4787 name = input_line_pointer;
4788 c = get_symbol_end ();
4789 /* Make sure the given symbol exists. */
4790 if ((symbol = symbol_find_or_make (name)) == NULL)
4792 as_bad (_("Cannot define export symbol: %s\n"), name);
4793 p = input_line_pointer;
4794 *p = c;
4795 input_line_pointer++;
4797 else
4799 /* OK. Set the external bits and process argument relocations. */
4800 S_SET_EXTERNAL (symbol);
4801 p = input_line_pointer;
4802 *p = c;
4803 if (!is_end_of_statement ())
4805 input_line_pointer++;
4806 pa_type_args (symbol, 1);
4810 demand_empty_rest_of_line ();
4813 /* Helper function to process arguments to a .EXPORT pseudo-op. */
4815 static void
4816 pa_type_args (symbolP, is_export)
4817 symbolS *symbolP;
4818 int is_export;
4820 char *name, c, *p;
4821 unsigned int temp, arg_reloc;
4822 pa_symbol_type type = SYMBOL_TYPE_UNKNOWN;
4823 obj_symbol_type *symbol = (obj_symbol_type *) symbol_get_bfdsym (symbolP);
4825 if (strncasecmp (input_line_pointer, "absolute", 8) == 0)
4828 input_line_pointer += 8;
4829 symbol_get_bfdsym (symbolP)->flags &= ~BSF_FUNCTION;
4830 S_SET_SEGMENT (symbolP, bfd_abs_section_ptr);
4831 type = SYMBOL_TYPE_ABSOLUTE;
4833 else if (strncasecmp (input_line_pointer, "code", 4) == 0)
4835 input_line_pointer += 4;
4836 /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM,
4837 instead one should be IMPORTing/EXPORTing ENTRY types.
4839 Complain if one tries to EXPORT a CODE type since that's never
4840 done. Both GCC and HP C still try to IMPORT CODE types, so
4841 silently fix them to be ENTRY types. */
4842 if (S_IS_FUNCTION (symbolP))
4844 if (is_export)
4845 as_tsktsk (_("Using ENTRY rather than CODE in export directive for %s"),
4846 S_GET_NAME (symbolP));
4848 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
4849 type = SYMBOL_TYPE_ENTRY;
4851 else
4853 symbol_get_bfdsym (symbolP)->flags &= ~BSF_FUNCTION;
4854 type = SYMBOL_TYPE_CODE;
4857 else if (strncasecmp (input_line_pointer, "data", 4) == 0)
4859 input_line_pointer += 4;
4860 symbol_get_bfdsym (symbolP)->flags &= ~BSF_FUNCTION;
4861 type = SYMBOL_TYPE_DATA;
4863 else if ((strncasecmp (input_line_pointer, "entry", 5) == 0))
4865 input_line_pointer += 5;
4866 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
4867 type = SYMBOL_TYPE_ENTRY;
4869 else if (strncasecmp (input_line_pointer, "millicode", 9) == 0)
4871 input_line_pointer += 9;
4872 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
4873 type = SYMBOL_TYPE_MILLICODE;
4875 else if (strncasecmp (input_line_pointer, "plabel", 6) == 0)
4877 input_line_pointer += 6;
4878 symbol_get_bfdsym (symbolP)->flags &= ~BSF_FUNCTION;
4879 type = SYMBOL_TYPE_PLABEL;
4881 else if (strncasecmp (input_line_pointer, "pri_prog", 8) == 0)
4883 input_line_pointer += 8;
4884 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
4885 type = SYMBOL_TYPE_PRI_PROG;
4887 else if (strncasecmp (input_line_pointer, "sec_prog", 8) == 0)
4889 input_line_pointer += 8;
4890 symbol_get_bfdsym (symbolP)->flags |= BSF_FUNCTION;
4891 type = SYMBOL_TYPE_SEC_PROG;
4894 /* SOM requires much more information about symbol types
4895 than BFD understands. This is how we get this information
4896 to the SOM BFD backend. */
4897 #ifdef obj_set_symbol_type
4898 obj_set_symbol_type (symbol_get_bfdsym (symbolP), (int) type);
4899 #endif
4901 /* Now that the type of the exported symbol has been handled,
4902 handle any argument relocation information. */
4903 while (!is_end_of_statement ())
4905 if (*input_line_pointer == ',')
4906 input_line_pointer++;
4907 name = input_line_pointer;
4908 c = get_symbol_end ();
4909 /* Argument sources. */
4910 if ((strncasecmp (name, "argw", 4) == 0))
4912 p = input_line_pointer;
4913 *p = c;
4914 input_line_pointer++;
4915 temp = atoi (name + 4);
4916 name = input_line_pointer;
4917 c = get_symbol_end ();
4918 arg_reloc = pa_align_arg_reloc (temp, pa_build_arg_reloc (name));
4919 symbol->tc_data.ap.hppa_arg_reloc |= arg_reloc;
4920 *input_line_pointer = c;
4922 /* The return value. */
4923 else if ((strncasecmp (name, "rtnval", 6)) == 0)
4925 p = input_line_pointer;
4926 *p = c;
4927 input_line_pointer++;
4928 name = input_line_pointer;
4929 c = get_symbol_end ();
4930 arg_reloc = pa_build_arg_reloc (name);
4931 symbol->tc_data.ap.hppa_arg_reloc |= arg_reloc;
4932 *input_line_pointer = c;
4934 /* Privelege level. */
4935 else if ((strncasecmp (name, "priv_lev", 8)) == 0)
4937 p = input_line_pointer;
4938 *p = c;
4939 input_line_pointer++;
4940 temp = atoi (input_line_pointer);
4941 symbol->tc_data.ap.hppa_priv_level = temp;
4942 c = get_symbol_end ();
4943 *input_line_pointer = c;
4945 else
4947 as_bad (_("Undefined .EXPORT/.IMPORT argument (ignored): %s"), name);
4948 p = input_line_pointer;
4949 *p = c;
4951 if (!is_end_of_statement ())
4952 input_line_pointer++;
4956 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
4957 assembly file must either be defined in the assembly file, or
4958 explicitly IMPORTED from another. */
4960 static void
4961 pa_import (unused)
4962 int unused;
4964 char *name, c, *p;
4965 symbolS *symbol;
4967 name = input_line_pointer;
4968 c = get_symbol_end ();
4970 symbol = symbol_find (name);
4971 /* Ugh. We might be importing a symbol defined earlier in the file,
4972 in which case all the code below will really screw things up
4973 (set the wrong segment, symbol flags & type, etc). */
4974 if (symbol == NULL || !S_IS_DEFINED (symbol))
4976 symbol = symbol_find_or_make (name);
4977 p = input_line_pointer;
4978 *p = c;
4980 if (!is_end_of_statement ())
4982 input_line_pointer++;
4983 pa_type_args (symbol, 0);
4985 else
4987 /* Sigh. To be compatable with the HP assembler and to help
4988 poorly written assembly code, we assign a type based on
4989 the the current segment. Note only BSF_FUNCTION really
4990 matters, we do not need to set the full SYMBOL_TYPE_* info. */
4991 if (now_seg == text_section)
4992 symbol_get_bfdsym (symbol)->flags |= BSF_FUNCTION;
4994 /* If the section is undefined, then the symbol is undefined
4995 Since this is an import, leave the section undefined. */
4996 S_SET_SEGMENT (symbol, bfd_und_section_ptr);
4999 else
5001 /* The symbol was already defined. Just eat everything up to
5002 the end of the current statement. */
5003 while (!is_end_of_statement ())
5004 input_line_pointer++;
5007 demand_empty_rest_of_line ();
5010 /* Handle a .LABEL pseudo-op. */
5012 static void
5013 pa_label (unused)
5014 int unused;
5016 char *name, c, *p;
5018 name = input_line_pointer;
5019 c = get_symbol_end ();
5021 if (strlen (name) > 0)
5023 colon (name);
5024 p = input_line_pointer;
5025 *p = c;
5027 else
5029 as_warn (_("Missing label name on .LABEL"));
5032 if (!is_end_of_statement ())
5034 as_warn (_("extra .LABEL arguments ignored."));
5035 ignore_rest_of_line ();
5037 demand_empty_rest_of_line ();
5040 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
5042 static void
5043 pa_leave (unused)
5044 int unused;
5046 /* We must have a valid space and subspace. */
5047 pa_check_current_space_and_subspace ();
5049 as_bad (_("The .LEAVE pseudo-op is not supported"));
5050 demand_empty_rest_of_line ();
5053 /* Handle a .LEVEL pseudo-op. */
5055 static void
5056 pa_level (unused)
5057 int unused;
5059 char *level;
5061 level = input_line_pointer;
5062 if (strncmp (level, "1.0", 3) == 0)
5064 input_line_pointer += 3;
5065 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 10))
5066 as_warn (_("could not set architecture and machine"));
5068 else if (strncmp (level, "1.1", 3) == 0)
5070 input_line_pointer += 3;
5071 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 11))
5072 as_warn (_("could not set architecture and machine"));
5074 else if (strncmp (level, "2.0", 3) == 0)
5076 input_line_pointer += 3;
5077 if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 20))
5078 as_warn (_("could not set architecture and machine"));
5080 else
5082 as_bad (_("Unrecognized .LEVEL argument\n"));
5083 ignore_rest_of_line ();
5085 demand_empty_rest_of_line ();
5088 /* Handle a .ORIGIN pseudo-op. */
5090 static void
5091 pa_origin (unused)
5092 int unused;
5094 /* We must have a valid space and subspace. */
5095 pa_check_current_space_and_subspace ();
5097 s_org (0);
5098 pa_undefine_label ();
5101 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
5102 is for static functions. FIXME. Should share more code with .EXPORT. */
5104 static void
5105 pa_param (unused)
5106 int unused;
5108 char *name, c, *p;
5109 symbolS *symbol;
5111 name = input_line_pointer;
5112 c = get_symbol_end ();
5114 if ((symbol = symbol_find_or_make (name)) == NULL)
5116 as_bad (_("Cannot define static symbol: %s\n"), name);
5117 p = input_line_pointer;
5118 *p = c;
5119 input_line_pointer++;
5121 else
5123 S_CLEAR_EXTERNAL (symbol);
5124 p = input_line_pointer;
5125 *p = c;
5126 if (!is_end_of_statement ())
5128 input_line_pointer++;
5129 pa_type_args (symbol, 0);
5133 demand_empty_rest_of_line ();
5136 /* Handle a .PROC pseudo-op. It is used to mark the beginning
5137 of a procedure from a syntatical point of view. */
5139 static void
5140 pa_proc (unused)
5141 int unused;
5143 struct call_info *call_info;
5145 /* We must have a valid space and subspace. */
5146 pa_check_current_space_and_subspace ();
5148 if (within_procedure)
5149 as_fatal (_("Nested procedures"));
5151 /* Reset global variables for new procedure. */
5152 callinfo_found = FALSE;
5153 within_procedure = TRUE;
5155 /* Create another call_info structure. */
5156 call_info = (struct call_info *) xmalloc (sizeof (struct call_info));
5158 if (!call_info)
5159 as_fatal (_("Cannot allocate unwind descriptor\n"));
5161 memset (call_info, 0, sizeof (struct call_info));
5163 call_info->ci_next = NULL;
5165 if (call_info_root == NULL)
5167 call_info_root = call_info;
5168 last_call_info = call_info;
5170 else
5172 last_call_info->ci_next = call_info;
5173 last_call_info = call_info;
5176 /* set up defaults on call_info structure */
5178 call_info->ci_unwind.descriptor.cannot_unwind = 0;
5179 call_info->ci_unwind.descriptor.region_desc = 1;
5180 call_info->ci_unwind.descriptor.hpux_interrupt_marker = 0;
5182 /* If we got a .PROC pseudo-op, we know that the function is defined
5183 locally. Make sure it gets into the symbol table. */
5185 label_symbol_struct *label_symbol = pa_get_label ();
5187 if (label_symbol)
5189 if (label_symbol->lss_label)
5191 last_call_info->start_symbol = label_symbol->lss_label;
5192 symbol_get_bfdsym (label_symbol->lss_label)->flags |= BSF_FUNCTION;
5194 else
5195 as_bad (_("Missing function name for .PROC (corrupted label chain)"));
5197 else
5198 last_call_info->start_symbol = NULL;
5201 demand_empty_rest_of_line ();
5204 /* Process the syntatical end of a procedure. Make sure all the
5205 appropriate pseudo-ops were found within the procedure. */
5207 static void
5208 pa_procend (unused)
5209 int unused;
5212 /* We must have a valid space and subspace. */
5213 pa_check_current_space_and_subspace ();
5215 /* If we are within a procedure definition, make sure we've
5216 defined a label for the procedure; handle case where the
5217 label was defined after the .PROC directive.
5219 Note there's not need to diddle with the segment or fragment
5220 for the label symbol in this case. We have already switched
5221 into the new $CODE$ subspace at this point. */
5222 if (within_procedure && last_call_info->start_symbol == NULL)
5224 label_symbol_struct *label_symbol = pa_get_label ();
5226 if (label_symbol)
5228 if (label_symbol->lss_label)
5230 last_call_info->start_symbol = label_symbol->lss_label;
5231 symbol_get_bfdsym (label_symbol->lss_label)->flags
5232 |= BSF_FUNCTION;
5233 #ifdef OBJ_SOM
5234 /* Also handle allocation of a fixup to hold the unwind
5235 information when the label appears after the proc/procend. */
5236 if (within_entry_exit)
5238 char *where = frag_more (0);
5240 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
5241 NULL, (offsetT) 0, NULL,
5242 0, R_HPPA_ENTRY, e_fsel, 0, 0,
5243 (int *) &last_call_info->ci_unwind.descriptor);
5245 #endif
5247 else
5248 as_bad (_("Missing function name for .PROC (corrupted label chain)"));
5250 else
5251 as_bad (_("Missing function name for .PROC"));
5254 if (!within_procedure)
5255 as_bad (_("misplaced .procend"));
5257 if (!callinfo_found)
5258 as_bad (_("Missing .callinfo for this procedure"));
5260 if (within_entry_exit)
5261 as_bad (_("Missing .EXIT for a .ENTRY"));
5263 #ifdef OBJ_ELF
5264 /* ELF needs to mark the end of each function so that it can compute
5265 the size of the function (apparently its needed in the symbol table). */
5266 hppa_elf_mark_end_of_function ();
5267 #endif
5269 within_procedure = FALSE;
5270 demand_empty_rest_of_line ();
5271 pa_undefine_label ();
5274 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
5275 then create a new space entry to hold the information specified
5276 by the parameters to the .SPACE directive. */
5278 static sd_chain_struct *
5279 pa_parse_space_stmt (space_name, create_flag)
5280 char *space_name;
5281 int create_flag;
5283 char *name, *ptemp, c;
5284 char loadable, defined, private, sort;
5285 int spnum, temp;
5286 asection *seg = NULL;
5287 sd_chain_struct *space;
5289 /* load default values */
5290 spnum = 0;
5291 sort = 0;
5292 loadable = TRUE;
5293 defined = TRUE;
5294 private = FALSE;
5295 if (strcmp (space_name, "$TEXT$") == 0)
5297 seg = pa_def_spaces[0].segment;
5298 defined = pa_def_spaces[0].defined;
5299 private = pa_def_spaces[0].private;
5300 sort = pa_def_spaces[0].sort;
5301 spnum = pa_def_spaces[0].spnum;
5303 else if (strcmp (space_name, "$PRIVATE$") == 0)
5305 seg = pa_def_spaces[1].segment;
5306 defined = pa_def_spaces[1].defined;
5307 private = pa_def_spaces[1].private;
5308 sort = pa_def_spaces[1].sort;
5309 spnum = pa_def_spaces[1].spnum;
5312 if (!is_end_of_statement ())
5314 print_errors = FALSE;
5315 ptemp = input_line_pointer + 1;
5316 /* First see if the space was specified as a number rather than
5317 as a name. According to the PA assembly manual the rest of
5318 the line should be ignored. */
5319 temp = pa_parse_number (&ptemp, 0);
5320 if (temp >= 0)
5322 spnum = temp;
5323 input_line_pointer = ptemp;
5325 else
5327 while (!is_end_of_statement ())
5329 input_line_pointer++;
5330 name = input_line_pointer;
5331 c = get_symbol_end ();
5332 if ((strncasecmp (name, "spnum", 5) == 0))
5334 *input_line_pointer = c;
5335 input_line_pointer++;
5336 spnum = get_absolute_expression ();
5338 else if ((strncasecmp (name, "sort", 4) == 0))
5340 *input_line_pointer = c;
5341 input_line_pointer++;
5342 sort = get_absolute_expression ();
5344 else if ((strncasecmp (name, "unloadable", 10) == 0))
5346 *input_line_pointer = c;
5347 loadable = FALSE;
5349 else if ((strncasecmp (name, "notdefined", 10) == 0))
5351 *input_line_pointer = c;
5352 defined = FALSE;
5354 else if ((strncasecmp (name, "private", 7) == 0))
5356 *input_line_pointer = c;
5357 private = TRUE;
5359 else
5361 as_bad (_("Invalid .SPACE argument"));
5362 *input_line_pointer = c;
5363 if (!is_end_of_statement ())
5364 input_line_pointer++;
5368 print_errors = TRUE;
5371 if (create_flag && seg == NULL)
5372 seg = subseg_new (space_name, 0);
5374 /* If create_flag is nonzero, then create the new space with
5375 the attributes computed above. Else set the values in
5376 an already existing space -- this can only happen for
5377 the first occurence of a built-in space. */
5378 if (create_flag)
5379 space = create_new_space (space_name, spnum, loadable, defined,
5380 private, sort, seg, 1);
5381 else
5383 space = is_defined_space (space_name);
5384 SPACE_SPNUM (space) = spnum;
5385 SPACE_DEFINED (space) = defined & 1;
5386 SPACE_USER_DEFINED (space) = 1;
5389 #ifdef obj_set_section_attributes
5390 obj_set_section_attributes (seg, defined, private, sort, spnum);
5391 #endif
5393 return space;
5396 /* Handle a .SPACE pseudo-op; this switches the current space to the
5397 given space, creating the new space if necessary. */
5399 static void
5400 pa_space (unused)
5401 int unused;
5403 char *name, c, *space_name, *save_s;
5404 int temp;
5405 sd_chain_struct *sd_chain;
5407 if (within_procedure)
5409 as_bad (_("Can\'t change spaces within a procedure definition. Ignored"));
5410 ignore_rest_of_line ();
5412 else
5414 /* Check for some of the predefined spaces. FIXME: most of the code
5415 below is repeated several times, can we extract the common parts
5416 and place them into a subroutine or something similar? */
5417 /* FIXME Is this (and the next IF stmt) really right?
5418 What if INPUT_LINE_POINTER points to "$TEXT$FOO"? */
5419 if (strncmp (input_line_pointer, "$TEXT$", 6) == 0)
5421 input_line_pointer += 6;
5422 sd_chain = is_defined_space ("$TEXT$");
5423 if (sd_chain == NULL)
5424 sd_chain = pa_parse_space_stmt ("$TEXT$", 1);
5425 else if (SPACE_USER_DEFINED (sd_chain) == 0)
5426 sd_chain = pa_parse_space_stmt ("$TEXT$", 0);
5428 current_space = sd_chain;
5429 subseg_set (text_section, sd_chain->sd_last_subseg);
5430 current_subspace
5431 = pa_subsegment_to_subspace (text_section,
5432 sd_chain->sd_last_subseg);
5433 demand_empty_rest_of_line ();
5434 return;
5436 if (strncmp (input_line_pointer, "$PRIVATE$", 9) == 0)
5438 input_line_pointer += 9;
5439 sd_chain = is_defined_space ("$PRIVATE$");
5440 if (sd_chain == NULL)
5441 sd_chain = pa_parse_space_stmt ("$PRIVATE$", 1);
5442 else if (SPACE_USER_DEFINED (sd_chain) == 0)
5443 sd_chain = pa_parse_space_stmt ("$PRIVATE$", 0);
5445 current_space = sd_chain;
5446 subseg_set (data_section, sd_chain->sd_last_subseg);
5447 current_subspace
5448 = pa_subsegment_to_subspace (data_section,
5449 sd_chain->sd_last_subseg);
5450 demand_empty_rest_of_line ();
5451 return;
5453 if (!strncasecmp (input_line_pointer,
5454 GDB_DEBUG_SPACE_NAME,
5455 strlen (GDB_DEBUG_SPACE_NAME)))
5457 input_line_pointer += strlen (GDB_DEBUG_SPACE_NAME);
5458 sd_chain = is_defined_space (GDB_DEBUG_SPACE_NAME);
5459 if (sd_chain == NULL)
5460 sd_chain = pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME, 1);
5461 else if (SPACE_USER_DEFINED (sd_chain) == 0)
5462 sd_chain = pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME, 0);
5464 current_space = sd_chain;
5467 asection *gdb_section
5468 = bfd_make_section_old_way (stdoutput, GDB_DEBUG_SPACE_NAME);
5470 subseg_set (gdb_section, sd_chain->sd_last_subseg);
5471 current_subspace
5472 = pa_subsegment_to_subspace (gdb_section,
5473 sd_chain->sd_last_subseg);
5475 demand_empty_rest_of_line ();
5476 return;
5479 /* It could be a space specified by number. */
5480 print_errors = 0;
5481 save_s = input_line_pointer;
5482 if ((temp = pa_parse_number (&input_line_pointer, 0)) >= 0)
5484 if ((sd_chain = pa_find_space_by_number (temp)))
5486 current_space = sd_chain;
5488 subseg_set (sd_chain->sd_seg, sd_chain->sd_last_subseg);
5489 current_subspace
5490 = pa_subsegment_to_subspace (sd_chain->sd_seg,
5491 sd_chain->sd_last_subseg);
5492 demand_empty_rest_of_line ();
5493 return;
5497 /* Not a number, attempt to create a new space. */
5498 print_errors = 1;
5499 input_line_pointer = save_s;
5500 name = input_line_pointer;
5501 c = get_symbol_end ();
5502 space_name = xmalloc (strlen (name) + 1);
5503 strcpy (space_name, name);
5504 *input_line_pointer = c;
5506 sd_chain = pa_parse_space_stmt (space_name, 1);
5507 current_space = sd_chain;
5509 subseg_set (sd_chain->sd_seg, sd_chain->sd_last_subseg);
5510 current_subspace = pa_subsegment_to_subspace (sd_chain->sd_seg,
5511 sd_chain->sd_last_subseg);
5512 demand_empty_rest_of_line ();
5516 /* Switch to a new space. (I think). FIXME. */
5518 static void
5519 pa_spnum (unused)
5520 int unused;
5522 char *name;
5523 char c;
5524 char *p;
5525 sd_chain_struct *space;
5527 name = input_line_pointer;
5528 c = get_symbol_end ();
5529 space = is_defined_space (name);
5530 if (space)
5532 p = frag_more (4);
5533 md_number_to_chars (p, SPACE_SPNUM (space), 4);
5535 else
5536 as_warn (_("Undefined space: '%s' Assuming space number = 0."), name);
5538 *input_line_pointer = c;
5539 demand_empty_rest_of_line ();
5542 /* If VALUE is an exact power of two between zero and 2^31, then
5543 return log2 (VALUE). Else return -1. */
5545 static int
5546 log2 (value)
5547 int value;
5549 int shift = 0;
5551 while ((1 << shift) != value && shift < 32)
5552 shift++;
5554 if (shift >= 32)
5555 return -1;
5556 else
5557 return shift;
5560 /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
5561 given subspace, creating the new subspace if necessary.
5563 FIXME. Should mirror pa_space more closely, in particular how
5564 they're broken up into subroutines. */
5566 static void
5567 pa_subspace (create_new)
5568 int create_new;
5570 char *name, *ss_name, *alias, c;
5571 char loadable, code_only, common, dup_common, zero, sort;
5572 int i, access, space_index, alignment, quadrant, applicable, flags;
5573 sd_chain_struct *space;
5574 ssd_chain_struct *ssd;
5575 asection *section;
5577 if (current_space == NULL)
5578 as_fatal (_("Must be in a space before changing or declaring subspaces.\n"));
5580 if (within_procedure)
5582 as_bad (_("Can\'t change subspaces within a procedure definition. Ignored"));
5583 ignore_rest_of_line ();
5585 else
5587 name = input_line_pointer;
5588 c = get_symbol_end ();
5589 ss_name = xmalloc (strlen (name) + 1);
5590 strcpy (ss_name, name);
5591 *input_line_pointer = c;
5593 /* Load default values. */
5594 sort = 0;
5595 access = 0x7f;
5596 loadable = 1;
5597 common = 0;
5598 dup_common = 0;
5599 code_only = 0;
5600 zero = 0;
5601 space_index = ~0;
5602 alignment = 1;
5603 quadrant = 0;
5604 alias = NULL;
5606 space = current_space;
5607 if (create_new)
5608 ssd = NULL;
5609 else
5610 ssd = is_defined_subspace (ss_name);
5611 /* Allow user to override the builtin attributes of subspaces. But
5612 only allow the attributes to be changed once! */
5613 if (ssd && SUBSPACE_DEFINED (ssd))
5615 subseg_set (ssd->ssd_seg, ssd->ssd_subseg);
5616 current_subspace = ssd;
5617 if (!is_end_of_statement ())
5618 as_warn (_("Parameters of an existing subspace can\'t be modified"));
5619 demand_empty_rest_of_line ();
5620 return;
5622 else
5624 /* A new subspace. Load default values if it matches one of
5625 the builtin subspaces. */
5626 i = 0;
5627 while (pa_def_subspaces[i].name)
5629 if (strcasecmp (pa_def_subspaces[i].name, ss_name) == 0)
5631 loadable = pa_def_subspaces[i].loadable;
5632 common = pa_def_subspaces[i].common;
5633 dup_common = pa_def_subspaces[i].dup_common;
5634 code_only = pa_def_subspaces[i].code_only;
5635 zero = pa_def_subspaces[i].zero;
5636 space_index = pa_def_subspaces[i].space_index;
5637 alignment = pa_def_subspaces[i].alignment;
5638 quadrant = pa_def_subspaces[i].quadrant;
5639 access = pa_def_subspaces[i].access;
5640 sort = pa_def_subspaces[i].sort;
5641 if (USE_ALIASES && pa_def_subspaces[i].alias)
5642 alias = pa_def_subspaces[i].alias;
5643 break;
5645 i++;
5649 /* We should be working with a new subspace now. Fill in
5650 any information as specified by the user. */
5651 if (!is_end_of_statement ())
5653 input_line_pointer++;
5654 while (!is_end_of_statement ())
5656 name = input_line_pointer;
5657 c = get_symbol_end ();
5658 if ((strncasecmp (name, "quad", 4) == 0))
5660 *input_line_pointer = c;
5661 input_line_pointer++;
5662 quadrant = get_absolute_expression ();
5664 else if ((strncasecmp (name, "align", 5) == 0))
5666 *input_line_pointer = c;
5667 input_line_pointer++;
5668 alignment = get_absolute_expression ();
5669 if (log2 (alignment) == -1)
5671 as_bad (_("Alignment must be a power of 2"));
5672 alignment = 1;
5675 else if ((strncasecmp (name, "access", 6) == 0))
5677 *input_line_pointer = c;
5678 input_line_pointer++;
5679 access = get_absolute_expression ();
5681 else if ((strncasecmp (name, "sort", 4) == 0))
5683 *input_line_pointer = c;
5684 input_line_pointer++;
5685 sort = get_absolute_expression ();
5687 else if ((strncasecmp (name, "code_only", 9) == 0))
5689 *input_line_pointer = c;
5690 code_only = 1;
5692 else if ((strncasecmp (name, "unloadable", 10) == 0))
5694 *input_line_pointer = c;
5695 loadable = 0;
5697 else if ((strncasecmp (name, "common", 6) == 0))
5699 *input_line_pointer = c;
5700 common = 1;
5702 else if ((strncasecmp (name, "dup_comm", 8) == 0))
5704 *input_line_pointer = c;
5705 dup_common = 1;
5707 else if ((strncasecmp (name, "zero", 4) == 0))
5709 *input_line_pointer = c;
5710 zero = 1;
5712 else if ((strncasecmp (name, "first", 5) == 0))
5713 as_bad (_("FIRST not supported as a .SUBSPACE argument"));
5714 else
5715 as_bad (_("Invalid .SUBSPACE argument"));
5716 if (!is_end_of_statement ())
5717 input_line_pointer++;
5721 /* Compute a reasonable set of BFD flags based on the information
5722 in the .subspace directive. */
5723 applicable = bfd_applicable_section_flags (stdoutput);
5724 flags = 0;
5725 if (loadable)
5726 flags |= (SEC_ALLOC | SEC_LOAD);
5727 if (code_only)
5728 flags |= SEC_CODE;
5729 if (common || dup_common)
5730 flags |= SEC_IS_COMMON;
5732 flags |= SEC_RELOC | SEC_HAS_CONTENTS;
5734 /* This is a zero-filled subspace (eg BSS). */
5735 if (zero)
5736 flags &= ~(SEC_LOAD | SEC_HAS_CONTENTS);
5738 applicable &= flags;
5740 /* If this is an existing subspace, then we want to use the
5741 segment already associated with the subspace.
5743 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
5744 lots of sections. It might be a problem in the PA ELF
5745 code, I do not know yet. For now avoid creating anything
5746 but the "standard" sections for ELF. */
5747 if (create_new)
5748 section = subseg_force_new (ss_name, 0);
5749 else if (ssd)
5750 section = ssd->ssd_seg;
5751 else if (alias)
5752 section = subseg_new (alias, 0);
5753 else if (!alias && USE_ALIASES)
5755 as_warn (_("Ignoring subspace decl due to ELF BFD bugs."));
5756 demand_empty_rest_of_line ();
5757 return;
5759 else
5760 section = subseg_new (ss_name, 0);
5762 if (zero)
5763 seg_info (section)->bss = 1;
5765 /* Now set the flags. */
5766 bfd_set_section_flags (stdoutput, section, applicable);
5768 /* Record any alignment request for this section. */
5769 record_alignment (section, log2 (alignment));
5771 /* Set the starting offset for this section. */
5772 bfd_set_section_vma (stdoutput, section,
5773 pa_subspace_start (space, quadrant));
5775 /* Now that all the flags are set, update an existing subspace,
5776 or create a new one. */
5777 if (ssd)
5779 current_subspace = update_subspace (space, ss_name, loadable,
5780 code_only, common, dup_common,
5781 sort, zero, access, space_index,
5782 alignment, quadrant,
5783 section);
5784 else
5785 current_subspace = create_new_subspace (space, ss_name, loadable,
5786 code_only, common,
5787 dup_common, zero, sort,
5788 access, space_index,
5789 alignment, quadrant, section);
5791 demand_empty_rest_of_line ();
5792 current_subspace->ssd_seg = section;
5793 subseg_set (current_subspace->ssd_seg, current_subspace->ssd_subseg);
5795 SUBSPACE_DEFINED (current_subspace) = 1;
5799 /* Create default space and subspace dictionaries. */
5801 static void
5802 pa_spaces_begin ()
5804 int i;
5806 space_dict_root = NULL;
5807 space_dict_last = NULL;
5809 i = 0;
5810 while (pa_def_spaces[i].name)
5812 char *name;
5814 /* Pick the right name to use for the new section. */
5815 if (pa_def_spaces[i].alias && USE_ALIASES)
5816 name = pa_def_spaces[i].alias;
5817 else
5818 name = pa_def_spaces[i].name;
5820 pa_def_spaces[i].segment = subseg_new (name, 0);
5821 create_new_space (pa_def_spaces[i].name, pa_def_spaces[i].spnum,
5822 pa_def_spaces[i].loadable, pa_def_spaces[i].defined,
5823 pa_def_spaces[i].private, pa_def_spaces[i].sort,
5824 pa_def_spaces[i].segment, 0);
5825 i++;
5828 i = 0;
5829 while (pa_def_subspaces[i].name)
5831 char *name;
5832 int applicable, subsegment;
5833 asection *segment = NULL;
5834 sd_chain_struct *space;
5836 /* Pick the right name for the new section and pick the right
5837 subsegment number. */
5838 if (pa_def_subspaces[i].alias && USE_ALIASES)
5840 name = pa_def_subspaces[i].alias;
5841 subsegment = pa_def_subspaces[i].subsegment;
5843 else
5845 name = pa_def_subspaces[i].name;
5846 subsegment = 0;
5849 /* Create the new section. */
5850 segment = subseg_new (name, subsegment);
5853 /* For SOM we want to replace the standard .text, .data, and .bss
5854 sections with our own. We also want to set BFD flags for
5855 all the built-in subspaces. */
5856 if (!strcmp (pa_def_subspaces[i].name, "$CODE$") && !USE_ALIASES)
5858 text_section = segment;
5859 applicable = bfd_applicable_section_flags (stdoutput);
5860 bfd_set_section_flags (stdoutput, segment,
5861 applicable & (SEC_ALLOC | SEC_LOAD
5862 | SEC_RELOC | SEC_CODE
5863 | SEC_READONLY
5864 | SEC_HAS_CONTENTS));
5866 else if (!strcmp (pa_def_subspaces[i].name, "$DATA$") && !USE_ALIASES)
5868 data_section = segment;
5869 applicable = bfd_applicable_section_flags (stdoutput);
5870 bfd_set_section_flags (stdoutput, segment,
5871 applicable & (SEC_ALLOC | SEC_LOAD
5872 | SEC_RELOC
5873 | SEC_HAS_CONTENTS));
5877 else if (!strcmp (pa_def_subspaces[i].name, "$BSS$") && !USE_ALIASES)
5879 bss_section = segment;
5880 applicable = bfd_applicable_section_flags (stdoutput);
5881 bfd_set_section_flags (stdoutput, segment,
5882 applicable & SEC_ALLOC);
5884 else if (!strcmp (pa_def_subspaces[i].name, "$LIT$") && !USE_ALIASES)
5886 applicable = bfd_applicable_section_flags (stdoutput);
5887 bfd_set_section_flags (stdoutput, segment,
5888 applicable & (SEC_ALLOC | SEC_LOAD
5889 | SEC_RELOC
5890 | SEC_READONLY
5891 | SEC_HAS_CONTENTS));
5893 else if (!strcmp (pa_def_subspaces[i].name, "$MILLICODE$")
5894 && !USE_ALIASES)
5896 applicable = bfd_applicable_section_flags (stdoutput);
5897 bfd_set_section_flags (stdoutput, segment,
5898 applicable & (SEC_ALLOC | SEC_LOAD
5899 | SEC_RELOC
5900 | SEC_READONLY
5901 | SEC_HAS_CONTENTS));
5903 else if (!strcmp (pa_def_subspaces[i].name, "$UNWIND$") && !USE_ALIASES)
5905 applicable = bfd_applicable_section_flags (stdoutput);
5906 bfd_set_section_flags (stdoutput, segment,
5907 applicable & (SEC_ALLOC | SEC_LOAD
5908 | SEC_RELOC
5909 | SEC_READONLY
5910 | SEC_HAS_CONTENTS));
5913 /* Find the space associated with this subspace. */
5914 space = pa_segment_to_space (pa_def_spaces[pa_def_subspaces[i].
5915 def_space_index].segment);
5916 if (space == NULL)
5918 as_fatal (_("Internal error: Unable to find containing space for %s."),
5919 pa_def_subspaces[i].name);
5922 create_new_subspace (space, name,
5923 pa_def_subspaces[i].loadable,
5924 pa_def_subspaces[i].code_only,
5925 pa_def_subspaces[i].common,
5926 pa_def_subspaces[i].dup_common,
5927 pa_def_subspaces[i].zero,
5928 pa_def_subspaces[i].sort,
5929 pa_def_subspaces[i].access,
5930 pa_def_subspaces[i].space_index,
5931 pa_def_subspaces[i].alignment,
5932 pa_def_subspaces[i].quadrant,
5933 segment);
5934 i++;
5940 /* Create a new space NAME, with the appropriate flags as defined
5941 by the given parameters. */
5943 static sd_chain_struct *
5944 create_new_space (name, spnum, loadable, defined, private,
5945 sort, seg, user_defined)
5946 char *name;
5947 int spnum;
5948 int loadable;
5949 int defined;
5950 int private;
5951 int sort;
5952 asection *seg;
5953 int user_defined;
5955 sd_chain_struct *chain_entry;
5957 chain_entry = (sd_chain_struct *) xmalloc (sizeof (sd_chain_struct));
5958 if (!chain_entry)
5959 as_fatal (_("Out of memory: could not allocate new space chain entry: %s\n"),
5960 name);
5962 SPACE_NAME (chain_entry) = (char *) xmalloc (strlen (name) + 1);
5963 strcpy (SPACE_NAME (chain_entry), name);
5964 SPACE_DEFINED (chain_entry) = defined;
5965 SPACE_USER_DEFINED (chain_entry) = user_defined;
5966 SPACE_SPNUM (chain_entry) = spnum;
5968 chain_entry->sd_seg = seg;
5969 chain_entry->sd_last_subseg = -1;
5970 chain_entry->sd_subspaces = NULL;
5971 chain_entry->sd_next = NULL;
5973 /* Find spot for the new space based on its sort key. */
5974 if (!space_dict_last)
5975 space_dict_last = chain_entry;
5977 if (space_dict_root == NULL)
5978 space_dict_root = chain_entry;
5979 else
5981 sd_chain_struct *chain_pointer;
5982 sd_chain_struct *prev_chain_pointer;
5984 chain_pointer = space_dict_root;
5985 prev_chain_pointer = NULL;
5987 while (chain_pointer)
5989 prev_chain_pointer = chain_pointer;
5990 chain_pointer = chain_pointer->sd_next;
5993 /* At this point we've found the correct place to add the new
5994 entry. So add it and update the linked lists as appropriate. */
5995 if (prev_chain_pointer)
5997 chain_entry->sd_next = chain_pointer;
5998 prev_chain_pointer->sd_next = chain_entry;
6000 else
6002 space_dict_root = chain_entry;
6003 chain_entry->sd_next = chain_pointer;
6006 if (chain_entry->sd_next == NULL)
6007 space_dict_last = chain_entry;
6010 /* This is here to catch predefined spaces which do not get
6011 modified by the user's input. Another call is found at
6012 the bottom of pa_parse_space_stmt to handle cases where
6013 the user modifies a predefined space. */
6014 #ifdef obj_set_section_attributes
6015 obj_set_section_attributes (seg, defined, private, sort, spnum);
6016 #endif
6018 return chain_entry;
6021 /* Create a new subspace NAME, with the appropriate flags as defined
6022 by the given parameters.
6024 Add the new subspace to the subspace dictionary chain in numerical
6025 order as defined by the SORT entries. */
6027 static ssd_chain_struct *
6028 create_new_subspace (space, name, loadable, code_only, common,
6029 dup_common, is_zero, sort, access, space_index,
6030 alignment, quadrant, seg)
6031 sd_chain_struct *space;
6032 char *name;
6033 int loadable, code_only, common, dup_common, is_zero;
6034 int sort;
6035 int access;
6036 int space_index;
6037 int alignment;
6038 int quadrant;
6039 asection *seg;
6041 ssd_chain_struct *chain_entry;
6043 chain_entry = (ssd_chain_struct *) xmalloc (sizeof (ssd_chain_struct));
6044 if (!chain_entry)
6045 as_fatal (_("Out of memory: could not allocate new subspace chain entry: %s\n"), name);
6047 SUBSPACE_NAME (chain_entry) = (char *) xmalloc (strlen (name) + 1);
6048 strcpy (SUBSPACE_NAME (chain_entry), name);
6050 /* Initialize subspace_defined. When we hit a .subspace directive
6051 we'll set it to 1 which "locks-in" the subspace attributes. */
6052 SUBSPACE_DEFINED (chain_entry) = 0;
6054 chain_entry->ssd_subseg = USE_ALIASES ? pa_next_subseg (space) : 0;
6055 chain_entry->ssd_seg = seg;
6056 chain_entry->ssd_next = NULL;
6058 /* Find spot for the new subspace based on its sort key. */
6059 if (space->sd_subspaces == NULL)
6060 space->sd_subspaces = chain_entry;
6061 else
6063 ssd_chain_struct *chain_pointer;
6064 ssd_chain_struct *prev_chain_pointer;
6066 chain_pointer = space->sd_subspaces;
6067 prev_chain_pointer = NULL;
6069 while (chain_pointer)
6071 prev_chain_pointer = chain_pointer;
6072 chain_pointer = chain_pointer->ssd_next;
6075 /* Now we have somewhere to put the new entry. Insert it and update
6076 the links. */
6077 if (prev_chain_pointer)
6079 chain_entry->ssd_next = chain_pointer;
6080 prev_chain_pointer->ssd_next = chain_entry;
6082 else
6084 space->sd_subspaces = chain_entry;
6085 chain_entry->ssd_next = chain_pointer;
6089 #ifdef obj_set_subsection_attributes
6090 obj_set_subsection_attributes (seg, space->sd_seg, access,
6091 sort, quadrant);
6092 #endif
6094 return chain_entry;
6097 /* Update the information for the given subspace based upon the
6098 various arguments. Return the modified subspace chain entry. */
6100 static ssd_chain_struct *
6101 update_subspace (space, name, loadable, code_only, common, dup_common, sort,
6102 zero, access, space_index, alignment, quadrant, section)
6103 sd_chain_struct *space;
6104 char *name;
6105 int loadable;
6106 int code_only;
6107 int common;
6108 int dup_common;
6109 int zero;
6110 int sort;
6111 int access;
6112 int space_index;
6113 int alignment;
6114 int quadrant;
6115 asection *section;
6117 ssd_chain_struct *chain_entry;
6119 chain_entry = is_defined_subspace (name);
6121 #ifdef obj_set_subsection_attributes
6122 obj_set_subsection_attributes (section, space->sd_seg, access,
6123 sort, quadrant);
6124 #endif
6126 return chain_entry;
6129 /* Return the space chain entry for the space with the name NAME or
6130 NULL if no such space exists. */
6132 static sd_chain_struct *
6133 is_defined_space (name)
6134 char *name;
6136 sd_chain_struct *chain_pointer;
6138 for (chain_pointer = space_dict_root;
6139 chain_pointer;
6140 chain_pointer = chain_pointer->sd_next)
6142 if (strcmp (SPACE_NAME (chain_pointer), name) == 0)
6143 return chain_pointer;
6146 /* No mapping from segment to space was found. Return NULL. */
6147 return NULL;
6150 /* Find and return the space associated with the given seg. If no mapping
6151 from the given seg to a space is found, then return NULL.
6153 Unlike subspaces, the number of spaces is not expected to grow much,
6154 so a linear exhaustive search is OK here. */
6156 static sd_chain_struct *
6157 pa_segment_to_space (seg)
6158 asection *seg;
6160 sd_chain_struct *space_chain;
6162 /* Walk through each space looking for the correct mapping. */
6163 for (space_chain = space_dict_root;
6164 space_chain;
6165 space_chain = space_chain->sd_next)
6167 if (space_chain->sd_seg == seg)
6168 return space_chain;
6171 /* Mapping was not found. Return NULL. */
6172 return NULL;
6175 /* Return the space chain entry for the subspace with the name NAME or
6176 NULL if no such subspace exists.
6178 Uses a linear search through all the spaces and subspaces, this may
6179 not be appropriate if we ever being placing each function in its
6180 own subspace. */
6182 static ssd_chain_struct *
6183 is_defined_subspace (name)
6184 char *name;
6186 sd_chain_struct *space_chain;
6187 ssd_chain_struct *subspace_chain;
6189 /* Walk through each space. */
6190 for (space_chain = space_dict_root;
6191 space_chain;
6192 space_chain = space_chain->sd_next)
6194 /* Walk through each subspace looking for a name which matches. */
6195 for (subspace_chain = space_chain->sd_subspaces;
6196 subspace_chain;
6197 subspace_chain = subspace_chain->ssd_next)
6198 if (strcmp (SUBSPACE_NAME (subspace_chain), name) == 0)
6199 return subspace_chain;
6202 /* Subspace wasn't found. Return NULL. */
6203 return NULL;
6206 /* Find and return the subspace associated with the given seg. If no
6207 mapping from the given seg to a subspace is found, then return NULL.
6209 If we ever put each procedure/function within its own subspace
6210 (to make life easier on the compiler and linker), then this will have
6211 to become more efficient. */
6213 static ssd_chain_struct *
6214 pa_subsegment_to_subspace (seg, subseg)
6215 asection *seg;
6216 subsegT subseg;
6218 sd_chain_struct *space_chain;
6219 ssd_chain_struct *subspace_chain;
6221 /* Walk through each space. */
6222 for (space_chain = space_dict_root;
6223 space_chain;
6224 space_chain = space_chain->sd_next)
6226 if (space_chain->sd_seg == seg)
6228 /* Walk through each subspace within each space looking for
6229 the correct mapping. */
6230 for (subspace_chain = space_chain->sd_subspaces;
6231 subspace_chain;
6232 subspace_chain = subspace_chain->ssd_next)
6233 if (subspace_chain->ssd_subseg == (int) subseg)
6234 return subspace_chain;
6238 /* No mapping from subsegment to subspace found. Return NULL. */
6239 return NULL;
6242 /* Given a number, try and find a space with the name number.
6244 Return a pointer to a space dictionary chain entry for the space
6245 that was found or NULL on failure. */
6247 static sd_chain_struct *
6248 pa_find_space_by_number (number)
6249 int number;
6251 sd_chain_struct *space_chain;
6253 for (space_chain = space_dict_root;
6254 space_chain;
6255 space_chain = space_chain->sd_next)
6257 if (SPACE_SPNUM (space_chain) == (unsigned int) number)
6258 return space_chain;
6261 /* No appropriate space found. Return NULL. */
6262 return NULL;
6265 /* Return the starting address for the given subspace. If the starting
6266 address is unknown then return zero. */
6268 static unsigned int
6269 pa_subspace_start (space, quadrant)
6270 sd_chain_struct *space;
6271 int quadrant;
6273 #ifdef OBJ_SOM
6274 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
6275 is not correct for the PA OSF1 port. */
6276 if ((strcmp (SPACE_NAME (space), "$PRIVATE$") == 0) && quadrant == 1)
6277 return 0x40000000;
6278 else if (space->sd_seg == data_section && quadrant == 1)
6279 return 0x40000000;
6280 else
6281 return 0;
6282 #endif
6283 return 0;
6286 /* FIXME. Needs documentation. */
6287 static int
6288 pa_next_subseg (space)
6289 sd_chain_struct *space;
6292 space->sd_last_subseg++;
6293 return space->sd_last_subseg;
6296 /* Helper function for pa_stringer. Used to find the end of
6297 a string. */
6299 static unsigned int
6300 pa_stringer_aux (s)
6301 char *s;
6303 unsigned int c = *s & CHAR_MASK;
6305 /* We must have a valid space and subspace. */
6306 pa_check_current_space_and_subspace ();
6308 switch (c)
6310 case '\"':
6311 c = NOT_A_CHAR;
6312 break;
6313 default:
6314 break;
6316 return c;
6319 /* Handle a .STRING type pseudo-op. */
6321 static void
6322 pa_stringer (append_zero)
6323 int append_zero;
6325 char *s, num_buf[4];
6326 unsigned int c;
6327 int i;
6329 /* Preprocess the string to handle PA-specific escape sequences.
6330 For example, \xDD where DD is a hexidecimal number should be
6331 changed to \OOO where OOO is an octal number. */
6333 /* Skip the opening quote. */
6334 s = input_line_pointer + 1;
6336 while (is_a_char (c = pa_stringer_aux (s++)))
6338 if (c == '\\')
6340 c = *s;
6341 switch (c)
6343 /* Handle \x<num>. */
6344 case 'x':
6346 unsigned int number;
6347 int num_digit;
6348 char dg;
6349 char *s_start = s;
6351 /* Get pas the 'x'. */
6352 s++;
6353 for (num_digit = 0, number = 0, dg = *s;
6354 num_digit < 2
6355 && (isdigit (dg) || (dg >= 'a' && dg <= 'f')
6356 || (dg >= 'A' && dg <= 'F'));
6357 num_digit++)
6359 if (isdigit (dg))
6360 number = number * 16 + dg - '0';
6361 else if (dg >= 'a' && dg <= 'f')
6362 number = number * 16 + dg - 'a' + 10;
6363 else
6364 number = number * 16 + dg - 'A' + 10;
6366 s++;
6367 dg = *s;
6369 if (num_digit > 0)
6371 switch (num_digit)
6373 case 1:
6374 sprintf (num_buf, "%02o", number);
6375 break;
6376 case 2:
6377 sprintf (num_buf, "%03o", number);
6378 break;
6380 for (i = 0; i <= num_digit; i++)
6381 s_start[i] = num_buf[i];
6383 break;
6385 /* This might be a "\"", skip over the escaped char. */
6386 default:
6387 s++;
6388 break;
6392 stringer (append_zero);
6393 pa_undefine_label ();
6396 /* Handle a .VERSION pseudo-op. */
6398 static void
6399 pa_version (unused)
6400 int unused;
6402 obj_version (0);
6403 pa_undefine_label ();
6406 #ifdef OBJ_SOM
6408 /* Handle a .COMPILER pseudo-op. */
6410 static void
6411 pa_compiler (unused)
6412 int unused;
6414 obj_som_compiler (0);
6415 pa_undefine_label ();
6418 #endif
6420 /* Handle a .COPYRIGHT pseudo-op. */
6422 static void
6423 pa_copyright (unused)
6424 int unused;
6426 obj_copyright (0);
6427 pa_undefine_label ();
6430 /* Just like a normal cons, but when finished we have to undefine
6431 the latest space label. */
6433 static void
6434 pa_cons (nbytes)
6435 int nbytes;
6437 cons (nbytes);
6438 pa_undefine_label ();
6441 /* Switch to the data space. As usual delete our label. */
6443 static void
6444 pa_data (unused)
6445 int unused;
6447 current_space = is_defined_space ("$PRIVATE$");
6448 current_subspace
6449 = pa_subsegment_to_subspace (current_space->sd_seg, 0);
6450 s_data (0);
6451 pa_undefine_label ();
6454 /* Like float_cons, but we need to undefine our label. */
6456 static void
6457 pa_float_cons (float_type)
6458 int float_type;
6460 float_cons (float_type);
6461 pa_undefine_label ();
6464 /* Like s_fill, but delete our label when finished. */
6466 static void
6467 pa_fill (unused)
6468 int unused;
6470 /* We must have a valid space and subspace. */
6471 pa_check_current_space_and_subspace ();
6473 s_fill (0);
6474 pa_undefine_label ();
6477 /* Like lcomm, but delete our label when finished. */
6479 static void
6480 pa_lcomm (needs_align)
6481 int needs_align;
6483 /* We must have a valid space and subspace. */
6484 pa_check_current_space_and_subspace ();
6486 s_lcomm (needs_align);
6487 pa_undefine_label ();
6490 /* Like lsym, but delete our label when finished. */
6492 static void
6493 pa_lsym (unused)
6494 int unused;
6496 /* We must have a valid space and subspace. */
6497 pa_check_current_space_and_subspace ();
6499 s_lsym (0);
6500 pa_undefine_label ();
6503 /* Switch to the text space. Like s_text, but delete our
6504 label when finished. */
6505 static void
6506 pa_text (unused)
6507 int unused;
6509 current_space = is_defined_space ("$TEXT$");
6510 current_subspace
6511 = pa_subsegment_to_subspace (current_space->sd_seg, 0);
6513 s_text (0);
6514 pa_undefine_label ();
6517 /* On the PA relocations which involve function symbols must not be
6518 adjusted. This so that the linker can know when/how to create argument
6519 relocation stubs for indirect calls and calls to static functions.
6521 "T" field selectors create DLT relative fixups for accessing
6522 globals and statics in PIC code; each DLT relative fixup creates
6523 an entry in the DLT table. The entries contain the address of
6524 the final target (eg accessing "foo" would create a DLT entry
6525 with the address of "foo").
6527 Unfortunately, the HP linker doesn't take into account any addend
6528 when generating the DLT; so accessing $LIT$+8 puts the address of
6529 $LIT$ into the DLT rather than the address of $LIT$+8.
6531 The end result is we can't perform relocation symbol reductions for
6532 any fixup which creates entries in the DLT (eg they use "T" field
6533 selectors).
6535 Reject reductions involving symbols with external scope; such
6536 reductions make life a living hell for object file editors.
6538 FIXME. Also reject R_HPPA relocations which are 32bits wide in
6539 the code space. The SOM BFD backend doesn't know how to pull the
6540 right bits out of an instruction. */
6543 hppa_fix_adjustable (fixp)
6544 fixS *fixp;
6546 struct hppa_fix_struct *hppa_fix;
6548 hppa_fix = (struct hppa_fix_struct *) fixp->tc_fix_data;
6550 #ifdef OBJ_SOM
6551 /* Reject reductions of symbols in 32bit relocs. */
6552 if (fixp->fx_r_type == R_HPPA && hppa_fix->fx_r_format == 32)
6553 return 0;
6555 /* Reject reductions of symbols in sym1-sym2 expressions when
6556 the fixup will occur in a CODE subspace.
6558 XXX FIXME: Long term we probably want to reject all of these;
6559 for example reducing in the debug section would lose if we ever
6560 supported using the optimizing hp linker. */
6561 if (fixp->fx_addsy
6562 && fixp->fx_subsy
6563 && (hppa_fix->segment->flags & SEC_CODE))
6565 /* Apparently sy_used_in_reloc never gets set for sub symbols. */
6566 symbol_mark_used_in_reloc (fixp->fx_subsy);
6567 return 0;
6570 /* We can't adjust any relocs that use LR% and RR% field selectors.
6571 That confuses the HP linker. */
6572 if (hppa_fix->fx_r_field == e_lrsel
6573 || hppa_fix->fx_r_field == e_rrsel
6574 || hppa_fix->fx_r_field == e_nlrsel)
6575 return 0;
6576 #endif
6578 /* Reject reductions of symbols in DLT relative relocs,
6579 relocations with plabels. */
6580 if (hppa_fix->fx_r_field == e_tsel
6581 || hppa_fix->fx_r_field == e_ltsel
6582 || hppa_fix->fx_r_field == e_rtsel
6583 || hppa_fix->fx_r_field == e_psel
6584 || hppa_fix->fx_r_field == e_rpsel
6585 || hppa_fix->fx_r_field == e_lpsel)
6586 return 0;
6588 if (fixp->fx_addsy && S_IS_EXTERNAL (fixp->fx_addsy))
6589 return 0;
6591 /* Reject absolute calls (jumps). */
6592 if (hppa_fix->fx_r_type == R_HPPA_ABS_CALL)
6593 return 0;
6595 /* Reject reductions of function symbols. */
6596 if (fixp->fx_addsy == 0 || ! S_IS_FUNCTION (fixp->fx_addsy))
6597 return 1;
6599 return 0;
6602 /* Return nonzero if the fixup in FIXP will require a relocation,
6603 even it if appears that the fixup could be completely handled
6604 within GAS. */
6607 hppa_force_relocation (fixp)
6608 fixS *fixp;
6610 struct hppa_fix_struct *hppa_fixp;
6611 int distance;
6613 hppa_fixp = (struct hppa_fix_struct *) fixp->tc_fix_data;
6614 #ifdef OBJ_SOM
6615 if (fixp->fx_r_type == R_HPPA_ENTRY || fixp->fx_r_type == R_HPPA_EXIT
6616 || fixp->fx_r_type == R_HPPA_BEGIN_BRTAB
6617 || fixp->fx_r_type == R_HPPA_END_BRTAB
6618 || fixp->fx_r_type == R_HPPA_BEGIN_TRY
6619 || fixp->fx_r_type == R_HPPA_END_TRY
6620 || (fixp->fx_addsy != NULL && fixp->fx_subsy != NULL
6621 && (hppa_fixp->segment->flags & SEC_CODE) != 0))
6622 return 1;
6623 #endif
6625 #define arg_reloc_stub_needed(CALLER, CALLEE) \
6626 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
6628 /* It is necessary to force PC-relative calls/jumps to have a relocation
6629 entry if they're going to need either a argument relocation or long
6630 call stub. FIXME. Can't we need the same for absolute calls? */
6631 if (fixp->fx_pcrel && fixp->fx_addsy
6632 && (arg_reloc_stub_needed ((long) ((obj_symbol_type *)
6633 symbol_get_bfdsym (fixp->fx_addsy))->tc_data.ap.hppa_arg_reloc,
6634 hppa_fixp->fx_arg_reloc)))
6635 return 1;
6636 distance = (fixp->fx_offset + S_GET_VALUE (fixp->fx_addsy)
6637 - md_pcrel_from (fixp));
6638 /* Now check and see if we're going to need a long-branch stub. */
6639 if (fixp->fx_r_type == R_HPPA_PCREL_CALL
6640 && (distance > 262143 || distance < -262144))
6641 return 1;
6643 if (fixp->fx_r_type == R_HPPA_ABS_CALL)
6644 return 1;
6645 #undef arg_reloc_stub_needed
6647 /* No need (yet) to force another relocations to be emitted. */
6648 return 0;
6651 /* Now for some ELF specific code. FIXME. */
6652 #ifdef OBJ_ELF
6653 /* Mark the end of a function so that it's possible to compute
6654 the size of the function in hppa_elf_final_processing. */
6656 static void
6657 hppa_elf_mark_end_of_function ()
6659 /* ELF does not have EXIT relocations. All we do is create a
6660 temporary symbol marking the end of the function. */
6661 char *name = (char *)
6662 xmalloc (strlen ("L$\001end_") +
6663 strlen (S_GET_NAME (last_call_info->start_symbol)) + 1);
6665 if (name)
6667 symbolS *symbolP;
6669 strcpy (name, "L$\001end_");
6670 strcat (name, S_GET_NAME (last_call_info->start_symbol));
6672 /* If we have a .exit followed by a .procend, then the
6673 symbol will have already been defined. */
6674 symbolP = symbol_find (name);
6675 if (symbolP)
6677 /* The symbol has already been defined! This can
6678 happen if we have a .exit followed by a .procend.
6680 This is *not* an error. All we want to do is free
6681 the memory we just allocated for the name and continue. */
6682 xfree (name);
6684 else
6686 /* symbol value should be the offset of the
6687 last instruction of the function */
6688 symbolP = symbol_new (name, now_seg, (valueT) (frag_now_fix () - 4),
6689 frag_now);
6691 assert (symbolP);
6692 S_CLEAR_EXTERNAL (symbolP);
6693 symbol_table_insert (symbolP);
6696 if (symbolP)
6697 last_call_info->end_symbol = symbolP;
6698 else
6699 as_bad (_("Symbol '%s' could not be created."), name);
6702 else
6703 as_bad (_("No memory for symbol name."));
6707 /* For ELF, this function serves one purpose: to setup the st_size
6708 field of STT_FUNC symbols. To do this, we need to scan the
6709 call_info structure list, determining st_size in by taking the
6710 difference in the address of the beginning/end marker symbols. */
6712 void
6713 elf_hppa_final_processing ()
6715 struct call_info *call_info_pointer;
6717 for (call_info_pointer = call_info_root;
6718 call_info_pointer;
6719 call_info_pointer = call_info_pointer->ci_next)
6721 elf_symbol_type *esym
6722 = ((elf_symbol_type *)
6723 symbol_get_bfdsym (call_info_pointer->start_symbol));
6724 esym->internal_elf_sym.st_size =
6725 S_GET_VALUE (call_info_pointer->end_symbol)
6726 - S_GET_VALUE (call_info_pointer->start_symbol) + 4;
6729 #endif